Merge tag 'staging-5.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 11 Jul 2019 22:36:02 +0000 (15:36 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 11 Jul 2019 22:36:02 +0000 (15:36 -0700)
Pull staging and IIO driver updates from Greg KH:
 "Here is the big Staging and IIO driver update for 5.3-rc1.

  Lots of new IIO drivers are in here, along with loads of tiny staging
  driver cleanups and fixes. Overall we almost break even with the same
  lines added as removed.

  Full details are in the shortlog, they are too large to list here.

  All of these changes have been in linux-next for a while with no
  reported issues"

* tag 'staging-5.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (608 commits)
  staging: kpc2000: simplify comparison to NULL in fileops.c
  staging: kpc2000: simplify comparison to NULL in dma.c
  staging: kpc2000: simplify comparison to NULL in kpc2000_spi.c
  staging: rtl8723bs: hal: remove redundant assignment to packetType
  staging: rtl8723bs: Change return type of hal_btcoex_IsBtDisabled()
  staging: rtl8723bs: Remove rtw_btcoex_DisplayBtCoexInfo()
  staging: rtl8723bs: Remove function rtw_btcoex_GetDBG()
  staging: rtl8723bs: Remove function rtw_btcoex_SetDBG()
  staging: rtl8723bs: Remove rtw_btcoex_IsBTCoexCtrlAMPDUSize()
  staging: rtl8723bs: Remove rtw_btcoex_BtInfoNotify()
  staging: rtl8723bs: Remove rtw_btcoex_ScanNotify()
  staging: rtl8723bs: Remove rtw_btcoex_SetSingleAntPath()
  staging: rtl8723bs: Remove rtw_btcoex_SetPGAntNum()
  staging: rtl8192e: remove redundant initialization of rtstatus
  staging: rtl8723bs: Remove rtw_btcoex_GetRaMask()
  staging: rtl8723bs: Remove rtw_btcoex_SetChipType()
  staging: rtl8723bs: Remove rtw_btcoex_ConnectNotify()
  staging: rtl8723bs: Remove rtw_btcoex_SetBTCoexist()
  staging: rtl8723bs: Remove rtw_btcoex_IsBtDisabled()
  staging: rtl8723bs: Remove rtw_btcoex_IsBtControlLps()
  ...

362 files changed:
Documentation/ABI/testing/sysfs-bus-iio
Documentation/ABI/testing/sysfs-bus-iio-cros-ec
Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371 [new file with mode: 0644]
Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml [new file with mode: 0644]
Documentation/devicetree/bindings/iio/accel/adi,adxl372.yaml [new file with mode: 0644]
Documentation/devicetree/bindings/iio/accel/adxl345.txt [deleted file]
Documentation/devicetree/bindings/iio/accel/adxl372.txt [deleted file]
Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt [deleted file]
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml [new file with mode: 0644]
Documentation/devicetree/bindings/iio/adc/adi,ad7780.txt [deleted file]
Documentation/devicetree/bindings/iio/adc/adi,ad7780.yaml [new file with mode: 0644]
Documentation/devicetree/bindings/iio/adc/mt6577_auxadc.txt
Documentation/devicetree/bindings/iio/adc/st,stm32-adc.txt
Documentation/devicetree/bindings/iio/chemical/sensirion,sps30.txt [deleted file]
Documentation/devicetree/bindings/iio/chemical/sensirion,sps30.yaml [new file with mode: 0644]
Documentation/devicetree/bindings/iio/frequency/adf4371.yaml [new file with mode: 0644]
Documentation/devicetree/bindings/iio/light/isl29018.txt [deleted file]
Documentation/devicetree/bindings/iio/light/isl29018.yaml [new file with mode: 0644]
Documentation/devicetree/bindings/iio/light/tsl2583.txt [deleted file]
Documentation/devicetree/bindings/iio/light/tsl2583.yaml [new file with mode: 0644]
Documentation/devicetree/bindings/iio/light/tsl2772.txt [deleted file]
Documentation/devicetree/bindings/iio/light/tsl2772.yaml [new file with mode: 0644]
Documentation/iio/ep93xx_adc.rst [new file with mode: 0644]
Documentation/iio/ep93xx_adc.txt [deleted file]
Documentation/iio/iio_configfs.rst [new file with mode: 0644]
Documentation/iio/iio_configfs.txt [deleted file]
Documentation/iio/index.rst [new file with mode: 0644]
MAINTAINERS
drivers/counter/ftm-quaddec.c
drivers/iio/Kconfig
drivers/iio/accel/adis16201.c
drivers/iio/accel/adis16209.c
drivers/iio/accel/adxl372.c
drivers/iio/accel/adxl372_spi.c
drivers/iio/accel/kxcjk-1013.c
drivers/iio/accel/kxsd9-spi.c
drivers/iio/accel/sca3000.c
drivers/iio/accel/st_accel_buffer.c
drivers/iio/adc/Kconfig
drivers/iio/adc/ad7124.c
drivers/iio/adc/ad7606.c
drivers/iio/adc/ad7606.h
drivers/iio/adc/ad_sigma_delta.c
drivers/iio/adc/at91-sama5d2_adc.c
drivers/iio/adc/at91_adc.c
drivers/iio/adc/imx7d_adc.c
drivers/iio/adc/meson_saradc.c
drivers/iio/adc/mt6577_auxadc.c
drivers/iio/adc/rcar-gyroadc.c
drivers/iio/adc/stm32-adc-core.c
drivers/iio/adc/stm32-dfsdm-adc.c
drivers/iio/adc/stm32-dfsdm-core.c
drivers/iio/adc/stm32-dfsdm.h
drivers/iio/adc/stmpe-adc.c
drivers/iio/adc/sun4i-gpadc-iio.c
drivers/iio/amplifiers/Kconfig
drivers/iio/amplifiers/ad8366.c
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
drivers/iio/dac/ad5758.c
drivers/iio/dac/ds4424.c
drivers/iio/frequency/Kconfig
drivers/iio/frequency/Makefile
drivers/iio/frequency/ad9523.c
drivers/iio/frequency/adf4371.c [new file with mode: 0644]
drivers/iio/humidity/dht11.c
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
drivers/iio/industrialio-core.c
drivers/iio/light/bh1780.c
drivers/iio/light/stk3310.c
drivers/iio/pressure/Kconfig
drivers/iio/pressure/Makefile
drivers/iio/pressure/dps310.c [new file with mode: 0644]
drivers/iio/temperature/maxim_thermocouple.c
drivers/staging/android/ion/Kconfig
drivers/staging/android/ion/Makefile
drivers/staging/android/ion/ion_carveout_heap.c [deleted file]
drivers/staging/android/ion/ion_chunk_heap.c [deleted file]
drivers/staging/comedi/comedi_buf.c
drivers/staging/comedi/comedi_fops.c
drivers/staging/comedi/drivers/amplc_dio200_common.c
drivers/staging/comedi/drivers/amplc_pci230.c
drivers/staging/comedi/drivers/dt282x.c
drivers/staging/comedi/drivers/mite.c
drivers/staging/comedi/drivers/usbdux.c
drivers/staging/erofs/Makefile
drivers/staging/erofs/compress.h [new file with mode: 0644]
drivers/staging/erofs/data.c
drivers/staging/erofs/decompressor.c [new file with mode: 0644]
drivers/staging/erofs/dir.c
drivers/staging/erofs/erofs_fs.h
drivers/staging/erofs/inode.c
drivers/staging/erofs/internal.h
drivers/staging/erofs/namei.c
drivers/staging/erofs/super.c
drivers/staging/erofs/unzip_pagevec.h
drivers/staging/erofs/unzip_vle.c
drivers/staging/erofs/unzip_vle.h
drivers/staging/erofs/unzip_vle_lz4.c [deleted file]
drivers/staging/erofs/utils.c
drivers/staging/erofs/zmap.c [new file with mode: 0644]
drivers/staging/fieldbus/anybuss/Kconfig
drivers/staging/fieldbus/anybuss/arcx-anybus.c
drivers/staging/fieldbus/dev_core.c
drivers/staging/fsl-dpaa2/Kconfig
drivers/staging/fsl-dpaa2/ethsw/ethsw.c
drivers/staging/gasket/gasket_core.c
drivers/staging/gasket/gasket_ioctl.c
drivers/staging/gasket/gasket_page_table.c
drivers/staging/greybus/tools/loopback_test.c
drivers/staging/iio/accel/adis16203.c
drivers/staging/iio/accel/adis16240.c
drivers/staging/iio/adc/Kconfig
drivers/staging/iio/addac/adt7316-spi.c
drivers/staging/iio/addac/adt7316.c
drivers/staging/iio/cdc/ad7150.c
drivers/staging/iio/cdc/ad7746.c
drivers/staging/iio/frequency/ad9834.c
drivers/staging/iio/resolver/ad2s1210.c
drivers/staging/kpc2000/Kconfig
drivers/staging/kpc2000/Makefile
drivers/staging/kpc2000/TODO
drivers/staging/kpc2000/kpc2000/Makefile
drivers/staging/kpc2000/kpc2000/cell_probe.c
drivers/staging/kpc2000/kpc2000/core.c
drivers/staging/kpc2000/kpc2000/dma_common_defs.h
drivers/staging/kpc2000/kpc2000/fileops.c [deleted file]
drivers/staging/kpc2000/kpc2000/kp2000_module.c [deleted file]
drivers/staging/kpc2000/kpc2000/pcie.h
drivers/staging/kpc2000/kpc2000/uapi.h
drivers/staging/kpc2000/kpc2000_i2c.c [new file with mode: 0644]
drivers/staging/kpc2000/kpc2000_spi.c [new file with mode: 0644]
drivers/staging/kpc2000/kpc_dma/dma.c
drivers/staging/kpc2000/kpc_dma/fileops.c
drivers/staging/kpc2000/kpc_dma/kpc_dma_driver.c
drivers/staging/kpc2000/kpc_dma/kpc_dma_driver.h
drivers/staging/kpc2000/kpc_i2c/Makefile [deleted file]
drivers/staging/kpc2000/kpc_i2c/fileops.c [deleted file]
drivers/staging/kpc2000/kpc_i2c/i2c_driver.c [deleted file]
drivers/staging/kpc2000/kpc_spi/Makefile [deleted file]
drivers/staging/kpc2000/kpc_spi/spi_driver.c [deleted file]
drivers/staging/kpc2000/kpc_spi/spi_parts.h [deleted file]
drivers/staging/ks7010/ks7010_sdio.c
drivers/staging/ks7010/ks_hostif.c
drivers/staging/most/Documentation/ABI/configfs-most.txt
drivers/staging/most/Documentation/driver_usage.txt
drivers/staging/most/Kconfig
drivers/staging/most/configfs.c
drivers/staging/most/net/net.c
drivers/staging/most/video/video.c
drivers/staging/mt7621-dma/mtk-hsdma.c
drivers/staging/mt7621-dts/Kconfig
drivers/staging/mt7621-dts/Makefile
drivers/staging/mt7621-dts/TODO
drivers/staging/mt7621-dts/gbpc1.dts
drivers/staging/mt7621-dts/gbpc2.dts [new file with mode: 0644]
drivers/staging/mt7621-dts/mt7621.dtsi
drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c
drivers/staging/mt7621-pci/mediatek,mt7621-pci.txt
drivers/staging/mt7621-pci/pci-mt7621.c
drivers/staging/netlogic/xlr_net.c
drivers/staging/octeon-usb/octeon-hcd.c
drivers/staging/pi433/pi433_if.c
drivers/staging/pi433/rf69.c
drivers/staging/pi433/rf69_registers.h
drivers/staging/ralink-gdma/ralink-gdma.c
drivers/staging/rtl8188eu/Kconfig
drivers/staging/rtl8188eu/core/rtw_ieee80211.c
drivers/staging/rtl8188eu/core/rtw_mlme.c
drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
drivers/staging/rtl8188eu/core/rtw_recv.c
drivers/staging/rtl8188eu/core/rtw_wlan_util.c
drivers/staging/rtl8188eu/hal/hal_com.c
drivers/staging/rtl8188eu/hal/odm.c
drivers/staging/rtl8188eu/hal/odm_hwconfig.c
drivers/staging/rtl8188eu/hal/usb_halinit.c
drivers/staging/rtl8188eu/include/hal_com.h
drivers/staging/rtl8188eu/include/ieee80211.h
drivers/staging/rtl8188eu/include/odm_precomp.h
drivers/staging/rtl8188eu/include/rtw_eeprom.h
drivers/staging/rtl8188eu/include/rtw_mlme.h
drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
drivers/staging/rtl8188eu/os_dep/mlme_linux.c
drivers/staging/rtl8188eu/os_dep/os_intfs.c
drivers/staging/rtl8188eu/os_dep/rtw_android.c
drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c
drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
drivers/staging/rtl8192e/rtllib_module.c
drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
drivers/staging/rtl8192u/r8192U_core.c
drivers/staging/rtl8192u/r8192U_dm.c
drivers/staging/rtl8192u/r8192U_dm.h
drivers/staging/rtl8712/drv_types.h
drivers/staging/rtl8712/hal_init.c
drivers/staging/rtl8712/ieee80211.c
drivers/staging/rtl8712/mlme_linux.c
drivers/staging/rtl8712/os_intfs.c
drivers/staging/rtl8712/recv_linux.c
drivers/staging/rtl8712/rtl8712_efuse.c
drivers/staging/rtl8712/rtl8712_xmit.c
drivers/staging/rtl8712/rtl871x_cmd.c
drivers/staging/rtl8712/rtl871x_cmd.h
drivers/staging/rtl8712/rtl871x_eeprom.c
drivers/staging/rtl8712/rtl871x_io.c
drivers/staging/rtl8712/rtl871x_ioctl_linux.c
drivers/staging/rtl8712/rtl871x_ioctl_rtl.c
drivers/staging/rtl8712/rtl871x_ioctl_set.c
drivers/staging/rtl8712/rtl871x_mlme.c
drivers/staging/rtl8712/rtl871x_mlme.h
drivers/staging/rtl8712/rtl871x_mp.c
drivers/staging/rtl8712/rtl871x_mp_ioctl.c
drivers/staging/rtl8712/rtl871x_mp_ioctl.h
drivers/staging/rtl8712/rtl871x_recv.c
drivers/staging/rtl8712/rtl871x_security.c
drivers/staging/rtl8712/rtl871x_sta_mgt.c
drivers/staging/rtl8712/rtl871x_xmit.c
drivers/staging/rtl8712/rtl871x_xmit.h
drivers/staging/rtl8712/sta_info.h
drivers/staging/rtl8712/usb_halinit.c
drivers/staging/rtl8712/usb_intf.c
drivers/staging/rtl8712/usb_ops.c
drivers/staging/rtl8712/wifi.h
drivers/staging/rtl8712/xmit_linux.c
drivers/staging/rtl8723bs/Kconfig
drivers/staging/rtl8723bs/TODO
drivers/staging/rtl8723bs/core/rtw_ap.c
drivers/staging/rtl8723bs/core/rtw_btcoex.c
drivers/staging/rtl8723bs/core/rtw_cmd.c
drivers/staging/rtl8723bs/core/rtw_debug.c
drivers/staging/rtl8723bs/core/rtw_eeprom.c
drivers/staging/rtl8723bs/core/rtw_ieee80211.c
drivers/staging/rtl8723bs/core/rtw_ioctl_set.c
drivers/staging/rtl8723bs/core/rtw_mlme.c
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
drivers/staging/rtl8723bs/core/rtw_pwrctrl.c
drivers/staging/rtl8723bs/core/rtw_recv.c
drivers/staging/rtl8723bs/core/rtw_wlan_util.c
drivers/staging/rtl8723bs/core/rtw_xmit.c
drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.c
drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c
drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.c
drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.c
drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c
drivers/staging/rtl8723bs/hal/hal_btcoex.c
drivers/staging/rtl8723bs/hal/hal_com.c
drivers/staging/rtl8723bs/hal/hal_intf.c
drivers/staging/rtl8723bs/hal/hal_phy.c
drivers/staging/rtl8723bs/hal/odm_AntDiv.c [deleted file]
drivers/staging/rtl8723bs/hal/odm_AntDiv.h [deleted file]
drivers/staging/rtl8723bs/hal/odm_DIG.c
drivers/staging/rtl8723bs/hal/odm_HWConfig.c
drivers/staging/rtl8723bs/hal/odm_HWConfig.h
drivers/staging/rtl8723bs/hal/odm_RegConfig8723B.h
drivers/staging/rtl8723bs/hal/odm_precomp.h
drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c
drivers/staging/rtl8723bs/hal/rtl8723b_dm.c
drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c
drivers/staging/rtl8723bs/hal/rtl8723b_rf6052.c
drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c
drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c
drivers/staging/rtl8723bs/hal/sdio_halinit.c
drivers/staging/rtl8723bs/hal/sdio_ops.c
drivers/staging/rtl8723bs/include/drv_types.h
drivers/staging/rtl8723bs/include/hal_btcoex.h
drivers/staging/rtl8723bs/include/hal_com.h
drivers/staging/rtl8723bs/include/hal_intf.h
drivers/staging/rtl8723bs/include/ieee80211.h
drivers/staging/rtl8723bs/include/osdep_intf.h
drivers/staging/rtl8723bs/include/osdep_service.h
drivers/staging/rtl8723bs/include/recv_osdep.h
drivers/staging/rtl8723bs/include/rtw_ap.h
drivers/staging/rtl8723bs/include/rtw_btcoex.h
drivers/staging/rtl8723bs/include/rtw_mlme.h
drivers/staging/rtl8723bs/include/rtw_mlme_ext.h
drivers/staging/rtl8723bs/include/sdio_ops.h
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
drivers/staging/rtl8723bs/os_dep/mlme_linux.c
drivers/staging/rtl8723bs/os_dep/os_intfs.c
drivers/staging/rtl8723bs/os_dep/osdep_service.c
drivers/staging/rtl8723bs/os_dep/recv_linux.c
drivers/staging/rtl8723bs/os_dep/rtw_proc.c
drivers/staging/rtl8723bs/os_dep/sdio_intf.c
drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c
drivers/staging/rtl8723bs/os_dep/xmit_linux.c
drivers/staging/rts5208/TODO
drivers/staging/rts5208/rtsx_chip.c
drivers/staging/rts5208/sd.c
drivers/staging/rts5208/sd.h
drivers/staging/rts5208/xd.c
drivers/staging/speakup/serialio.h
drivers/staging/unisys/Kconfig
drivers/staging/unisys/visornic/visornic_main.c
drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h
drivers/staging/vc04_services/bcm2835-camera/controls.c
drivers/staging/vc04_services/bcm2835-camera/mmal-common.h
drivers/staging/vc04_services/bcm2835-camera/mmal-encodings.h
drivers/staging/vc04_services/bcm2835-camera/mmal-msg-common.h
drivers/staging/vc04_services/bcm2835-camera/mmal-msg-format.h
drivers/staging/vc04_services/bcm2835-camera/mmal-msg-port.h
drivers/staging/vc04_services/bcm2835-camera/mmal-msg.h
drivers/staging/vc04_services/bcm2835-camera/mmal-parameters.h
drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_connected.c
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.c
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_if.h
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.c
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.h
drivers/staging/vt6655/Kconfig
drivers/staging/vt6655/card.c
drivers/staging/vt6655/card.h
drivers/staging/vt6655/test
drivers/staging/vt6656/Kconfig
drivers/staging/vt6656/baseband.c
drivers/staging/vt6656/baseband.h
drivers/staging/vt6656/card.c
drivers/staging/vt6656/firmware.c
drivers/staging/vt6656/int.c
drivers/staging/vt6656/int.h
drivers/staging/vt6656/mac.c
drivers/staging/vt6656/mac.h
drivers/staging/vt6656/main_usb.c
drivers/staging/vt6656/rf.c
drivers/staging/vt6656/rf.h
drivers/staging/vt6656/usbpipe.c
drivers/staging/vt6656/usbpipe.h
drivers/staging/wilc1000/Makefile
drivers/staging/wilc1000/host_interface.c [deleted file]
drivers/staging/wilc1000/host_interface.h [deleted file]
drivers/staging/wilc1000/wilc_hif.c [new file with mode: 0644]
drivers/staging/wilc1000/wilc_hif.h [new file with mode: 0644]
drivers/staging/wilc1000/wilc_mon.c
drivers/staging/wilc1000/wilc_netdev.c
drivers/staging/wilc1000/wilc_sdio.c
drivers/staging/wilc1000/wilc_spi.c
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
drivers/staging/wilc1000/wilc_wfi_cfgoperations.h
drivers/staging/wilc1000/wilc_wfi_netdevice.h
drivers/staging/wilc1000/wilc_wlan.c
drivers/staging/wilc1000/wilc_wlan.h
drivers/staging/wilc1000/wilc_wlan_if.h
drivers/staging/wlan-ng/cfg80211.c
tools/iio/iio_utils.c

index 6aef7dbbde44cf516cc7450141d01bd97aa9267f..680451695422a2a312a7d46349d9b0ff27b3931f 100644 (file)
@@ -61,8 +61,11 @@ What:                /sys/bus/iio/devices/triggerX/sampling_frequency_available
 KernelVersion: 2.6.35
 Contact:       linux-iio@vger.kernel.org
 Description:
-               When the internal sampling clock can only take a small
-               discrete set of values, this file lists those available.
+               When the internal sampling clock can only take a specific set of
+               frequencies, we can specify the available values with:
+               - a small discrete set of values like "0 2 4 6 8"
+               - a range with minimum, step and maximum frequencies like
+                 "[min step max]"
 
 What:          /sys/bus/iio/devices/iio:deviceX/oversampling_ratio
 KernelVersion: 2.6.38
index 0e95c2ca105ca891ebbeab8983b3f0f5461ddaea..6158f831c761f7242b0c0afffcea21b1c570205e 100644 (file)
@@ -18,11 +18,11 @@ Description:
                values are 'base' and 'lid'.
 
 What:          /sys/bus/iio/devices/iio:deviceX/id
-Date:          Septembre 2017
+Date:          September 2017
 KernelVersion: 4.14
 Contact:       linux-iio@vger.kernel.org
 Description:
-               This attribute is exposed by the CrOS EC legacy accelerometer
-               driver and represents the sensor ID as exposed by the EC. This
-               ID is used by the Android sensor service hardware abstraction
-               layer (sensor HAL) through the Android container on ChromeOS.
+               This attribute is exposed by the CrOS EC sensors driver and
+               represents the sensor ID as exposed by the EC. This ID is used
+               by the Android sensor service hardware abstraction layer (sensor
+               HAL) through the Android container on ChromeOS.
diff --git a/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371 b/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
new file mode 100644 (file)
index 0000000..302de64
--- /dev/null
@@ -0,0 +1,44 @@
+What:          /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_frequency
+KernelVersion:
+Contact:       linux-iio@vger.kernel.org
+Description:
+               Stores the PLL frequency in Hz for channel Y.
+               Reading returns the actual frequency in Hz.
+               The ADF4371 has an integrated VCO with fundamendal output
+               frequency ranging from 4000000000 Hz 8000000000 Hz.
+
+               out_altvoltage0_frequency:
+                       A divide by 1, 2, 4, 8, 16, 32 or circuit generates
+                       frequencies from 62500000 Hz to 8000000000 Hz.
+               out_altvoltage1_frequency:
+                       This channel duplicates the channel 0 frequency
+               out_altvoltage2_frequency:
+                       A frequency doubler generates frequencies from
+                       8000000000 Hz to 16000000000 Hz.
+               out_altvoltage3_frequency:
+                       A frequency quadrupler generates frequencies from
+                       16000000000 Hz to 32000000000 Hz.
+
+               Note: writes to one of the channels will affect the frequency of
+               all the other channels, since it involves changing the VCO
+               fundamental output frequency.
+
+What:          /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_name
+KernelVersion:
+Contact:       linux-iio@vger.kernel.org
+Description:
+               Reading returns the datasheet name for channel Y:
+
+               out_altvoltage0_name: RF8x
+               out_altvoltage1_name: RFAUX8x
+               out_altvoltage2_name: RF16x
+               out_altvoltage3_name: RF32x
+
+What:          /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_powerdown
+KernelVersion:
+Contact:       linux-iio@vger.kernel.org
+Description:
+               This attribute allows the user to power down the PLL and it's
+               RFOut buffers.
+               Writing 1 causes the specified channel to power down.
+               Clearing returns to normal operation.
diff --git a/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml b/Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml
new file mode 100644 (file)
index 0000000..7ba167e
--- /dev/null
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/accelerometers/adi,adxl345.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADXL345/ADXL375 3-Axis Digital Accelerometers
+
+maintainers:
+  - Michael Hennerich <michael.hennerich@analog.com>
+
+description: |
+  Analog Devices ADXL345/ADXL375 3-Axis Digital Accelerometers that supports
+  both I2C & SPI interfaces.
+    http://www.analog.com/en/products/mems/accelerometers/adxl345.html
+    http://www.analog.com/en/products/sensors-mems/accelerometers/adxl375.html
+
+properties:
+  compatible:
+    enum:
+      - adi,adxl345
+      - adi,adxl375
+
+  reg:
+    maxItems: 1
+
+  spi-cpha: true
+
+  spi-cpol: true
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    i2c0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        /* Example for a I2C device node */
+        accelerometer@2a {
+            compatible = "adi,adxl345";
+            reg = <0x53>;
+            interrupt-parent = <&gpio0>;
+            interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
+        };
+    };
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    spi0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        /* Example for a SPI device node */
+        accelerometer@0 {
+            compatible = "adi,adxl345";
+            reg = <0>;
+            spi-max-frequency = <5000000>;
+            spi-cpol;
+            spi-cpha;
+            interrupt-parent = <&gpio0>;
+            interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
+        };
+    };
diff --git a/Documentation/devicetree/bindings/iio/accel/adi,adxl372.yaml b/Documentation/devicetree/bindings/iio/accel/adi,adxl372.yaml
new file mode 100644 (file)
index 0000000..a7fafb9
--- /dev/null
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/accelerometers/adi,adxl372.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADXL372 3-Axis, +/-(200g) Digital Accelerometer
+
+maintainers:
+  - Stefan Popa <stefan.popa@analog.com>
+
+description: |
+  Analog Devices ADXL372 3-Axis, +/-(200g) Digital Accelerometer that supports
+  both I2C & SPI interfaces
+    https://www.analog.com/en/products/adxl372.html
+
+properties:
+  compatible:
+    enum:
+      - adi,adxl372
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+examples:
+  - |
+        #include <dt-bindings/gpio/gpio.h>
+        #include <dt-bindings/interrupt-controller/irq.h>
+        i2c0 {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                /* Example for a I2C device node */
+                accelerometer@53 {
+                        compatible = "adi,adxl372";
+                        reg = <0x53>;
+                        interrupt-parent = <&gpio>;
+                        interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
+                };
+        };
+  - |
+        #include <dt-bindings/gpio/gpio.h>
+        #include <dt-bindings/interrupt-controller/irq.h>
+        spi0 {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                accelerometer@0 {
+                        compatible = "adi,adxl372";
+                        reg = <0>;
+                        spi-max-frequency = <1000000>;
+                        interrupt-parent = <&gpio>;
+                        interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
+                };
+        };
diff --git a/Documentation/devicetree/bindings/iio/accel/adxl345.txt b/Documentation/devicetree/bindings/iio/accel/adxl345.txt
deleted file mode 100644 (file)
index f9525f6..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-Analog Devices ADXL345/ADXL375 3-Axis Digital Accelerometers
-
-http://www.analog.com/en/products/mems/accelerometers/adxl345.html
-http://www.analog.com/en/products/sensors-mems/accelerometers/adxl375.html
-
-Required properties:
- - compatible : should be one of
-               "adi,adxl345"
-               "adi,adxl375"
- - reg : the I2C address or SPI chip select number of the sensor
-
-Required properties for SPI bus usage:
- - spi-max-frequency : set maximum clock frequency, must be 5000000
- - spi-cpol and spi-cpha : must be defined for adxl345 to enable SPI mode 3
-
-Optional properties:
- - interrupts: interrupt mapping for IRQ as documented in
-   Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
-
-Example for a I2C device node:
-
-       accelerometer@2a {
-               compatible = "adi,adxl345";
-               reg = <0x53>;
-               interrupt-parent = <&gpio1>;
-               interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
-       };
-
-Example for a SPI device node:
-
-       accelerometer@0 {
-               compatible = "adi,adxl345";
-               reg = <0>;
-               spi-max-frequency = <5000000>;
-               spi-cpol;
-               spi-cpha;
-               interrupt-parent = <&gpio1>;
-               interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
-       };
diff --git a/Documentation/devicetree/bindings/iio/accel/adxl372.txt b/Documentation/devicetree/bindings/iio/accel/adxl372.txt
deleted file mode 100644 (file)
index a289964..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-Analog Devices ADXL372 3-Axis, +/-(200g) Digital Accelerometer
-
-http://www.analog.com/media/en/technical-documentation/data-sheets/adxl372.pdf
-
-Required properties:
- - compatible : should be "adi,adxl372"
- - reg: the I2C address or SPI chip select number for the device
-
-Required properties for SPI bus usage:
- - spi-max-frequency: Max SPI frequency to use
-
-Optional properties:
- - interrupts: interrupt mapping for IRQ as documented in
-   Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
-
-Example for a I2C device node:
-
-       accelerometer@53 {
-               compatible = "adi,adxl372";
-               reg = <0x53>;
-               interrupt-parent = <&gpio>;
-               interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
-       };
-
-Example for a SPI device node:
-
-       accelerometer@0 {
-               compatible = "adi,adxl372";
-               reg = <0>;
-               spi-max-frequency = <1000000>;
-               interrupt-parent = <&gpio>;
-               interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
-       };
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
deleted file mode 100644 (file)
index 416273d..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-Analog Devices AD7124 ADC device driver
-
-Required properties for the AD7124:
-       - compatible: Must be one of "adi,ad7124-4" or "adi,ad7124-8"
-       - reg: SPI chip select number for the device
-       - spi-max-frequency: Max SPI frequency to use
-               see: Documentation/devicetree/bindings/spi/spi-bus.txt
-       - clocks: phandle to the master clock (mclk)
-               see: Documentation/devicetree/bindings/clock/clock-bindings.txt
-       - clock-names: Must be "mclk".
-       - interrupts: IRQ line for the ADC
-               see: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
-
-         Required properties:
-               * #address-cells: Must be 1.
-               * #size-cells: Must be 0.
-
-         Subnode(s) represent the external channels which are connected to the ADC.
-         Each subnode represents one channel and has the following properties:
-               Required properties:
-                       * reg: The channel number. It can have up to 4 channels on ad7124-4
-                         and 8 channels on ad7124-8, numbered from 0 to 15.
-                       * diff-channels: see: Documentation/devicetree/bindings/iio/adc/adc.txt
-
-               Optional properties:
-                       * bipolar: see: Documentation/devicetree/bindings/iio/adc/adc.txt
-                       * adi,reference-select: Select the reference source to use when
-                         converting on the the specific channel. Valid values are:
-                         0: REFIN1(+)/REFIN1(−).
-                         1: REFIN2(+)/REFIN2(−).
-                         3: AVDD
-                         If this field is left empty, internal reference is selected.
-
-Optional properties:
-       - refin1-supply: refin1 supply can be used as reference for conversion.
-       - refin2-supply: refin2 supply can be used as reference for conversion.
-       - avdd-supply: avdd supply can be used as reference for conversion.
-
-Example:
-       adc@0 {
-               compatible = "adi,ad7124-4";
-               reg = <0>;
-               spi-max-frequency = <5000000>;
-               interrupts = <25 2>;
-               interrupt-parent = <&gpio>;
-               refin1-supply = <&adc_vref>;
-               clocks = <&ad7124_mclk>;
-               clock-names = "mclk";
-
-               #address-cells = <1>;
-               #size-cells = <0>;
-
-               channel@0 {
-                       reg = <0>;
-                       diff-channels = <0 1>;
-                       adi,reference-select = <0>;
-               };
-
-               channel@1 {
-                       reg = <1>;
-                       bipolar;
-                       diff-channels = <2 3>;
-                       adi,reference-select = <0>;
-               };
-
-               channel@2 {
-                       reg = <2>;
-                       diff-channels = <4 5>;
-               };
-
-               channel@3 {
-                       reg = <3>;
-                       diff-channels = <6 7>;
-               };
-       };
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml
new file mode 100644 (file)
index 0000000..cf494a0
--- /dev/null
@@ -0,0 +1,155 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright 2019 Analog Devices Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/bindings/iio/adc/adi,ad7124.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD7124 ADC device driver
+
+maintainers:
+  - Stefan Popa <stefan.popa@analog.com>
+
+description: |
+  Bindings for the Analog Devices AD7124 ADC device. Datasheet can be
+  found here:
+    https://www.analog.com/media/en/technical-documentation/data-sheets/AD7124-8.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,ad7124-4
+      - adi,ad7124-8
+
+  reg:
+    description: SPI chip select number for the device
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+    description: phandle to the master clock (mclk)
+
+  clock-names:
+    items:
+      - const: mclk
+
+  interrupts:
+    description: IRQ line for the ADC
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  refin1-supply:
+    description: refin1 supply can be used as reference for conversion.
+    maxItems: 1
+
+  refin2-supply:
+    description: refin2 supply can be used as reference for conversion.
+    maxItems: 1
+
+  avdd-supply:
+    description: avdd supply can be used as reference for conversion.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - interrupts
+
+patternProperties:
+  "^channel@([0-9]|1[0-5])$":
+    type: object
+    description: |
+      Represents the external channels which are connected to the ADC.
+      See Documentation/devicetree/bindings/iio/adc/adc.txt.
+
+    properties:
+      reg:
+        description: |
+          The channel number. It can have up to 8 channels on ad7124-4
+          and 16 channels on ad7124-8, numbered from 0 to 15.
+        items:
+         minimum: 0
+         maximum: 15
+
+      adi,reference-select:
+        description: |
+          Select the reference source to use when converting on
+          the specific channel. Valid values are:
+          0: REFIN1(+)/REFIN1(−).
+          1: REFIN2(+)/REFIN2(−).
+          3: AVDD
+          If this field is left empty, internal reference is selected.
+        allOf:
+          - $ref: /schemas/types.yaml#/definitions/uint32
+          - enum: [0, 1, 3]
+
+      diff-channels:
+        description: see Documentation/devicetree/bindings/iio/adc/adc.txt
+        items:
+          minimum: 0
+          maximum: 15
+
+      bipolar:
+        description: see Documentation/devicetree/bindings/iio/adc/adc.txt
+        type: boolean
+
+      adi,buffered-positive:
+        description: Enable buffered mode for positive input.
+        type: boolean
+
+      adi,buffered-negative:
+        description: Enable buffered mode for negative input.
+        type: boolean
+
+    required:
+      - reg
+      - diff-channels
+
+examples:
+  - |
+    adc@0 {
+      compatible = "adi,ad7124-4";
+      reg = <0>;
+      spi-max-frequency = <5000000>;
+      interrupts = <25 2>;
+      interrupt-parent = <&gpio>;
+      refin1-supply = <&adc_vref>;
+      clocks = <&ad7124_mclk>;
+      clock-names = "mclk";
+
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      channel@0 {
+        reg = <0>;
+        diff-channels = <0 1>;
+        adi,reference-select = <0>;
+        adi,buffered-positive;
+      };
+
+      channel@1 {
+        reg = <1>;
+        bipolar;
+        diff-channels = <2 3>;
+        adi,reference-select = <0>;
+        adi,buffered-positive;
+        adi,buffered-negative;
+      };
+
+      channel@2 {
+        reg = <2>;
+        diff-channels = <4 5>;
+      };
+
+      channel@3 {
+        reg = <3>;
+        diff-channels = <6 7>;
+      };
+    };
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7780.txt b/Documentation/devicetree/bindings/iio/adc/adi,ad7780.txt
deleted file mode 100644 (file)
index 440e525..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-* Analog Devices AD7170/AD7171/AD7780/AD7781
-
-Data sheets:
-
-- AD7170:
-       * https://www.analog.com/media/en/technical-documentation/data-sheets/AD7170.pdf
-- AD7171:
-       * https://www.analog.com/media/en/technical-documentation/data-sheets/AD7171.pdf
-- AD7780:
-       * https://www.analog.com/media/en/technical-documentation/data-sheets/ad7780.pdf
-- AD7781:
-       * https://www.analog.com/media/en/technical-documentation/data-sheets/AD7781.pdf
-
-Required properties:
-
-- compatible: should be one of
-       * "adi,ad7170"
-       * "adi,ad7171"
-       * "adi,ad7780"
-       * "adi,ad7781"
-- reg: spi chip select number for the device
-- vref-supply: the regulator supply for the ADC reference voltage
-
-Optional properties:
-
-- powerdown-gpios:  must be the device tree identifier of the PDRST pin. If
-                   specified, it will be asserted during driver probe. As the
-                   line is active high, it should be marked GPIO_ACTIVE_HIGH.
-- adi,gain-gpios:   must be the device tree identifier of the GAIN pin. Only for
-                   the ad778x chips. If specified, it will be asserted during
-                   driver probe. As the line is active low, it should be marked
-                   GPIO_ACTIVE_LOW.
-- adi,filter-gpios: must be the device tree identifier of the FILTER pin. Only
-                   for the ad778x chips. If specified, it will be asserted
-                   during driver probe. As the line is active low, it should be
-                   marked GPIO_ACTIVE_LOW.
-
-Example:
-
-adc@0 {
-       compatible =  "adi,ad7780";
-       reg =         <0>;
-       vref-supply = <&vdd_supply>
-
-       powerdown-gpios  = <&gpio 12 GPIO_ACTIVE_HIGH>;
-       adi,gain-gpios   = <&gpio  5 GPIO_ACTIVE_LOW>;
-       adi,filter-gpios = <&gpio 15 GPIO_ACTIVE_LOW>;
-};
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7780.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7780.yaml
new file mode 100644 (file)
index 0000000..d110941
--- /dev/null
@@ -0,0 +1,87 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ad7780.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD7170/AD7171/AD7780/AD7781 analog to digital converters
+
+maintainers:
+  - Michael Hennerich <michael.hennerich@analog.com>
+
+description: |
+  The ad7780 is a sigma-delta analog to digital converter. This driver provides
+  reading voltage values and status bits from both the ad778x and ad717x series.
+  Its interface also allows writing on the FILTER and GAIN GPIO pins on the
+  ad778x.
+
+  Specifications on the converters can be found at:
+    AD7170:
+      https://www.analog.com/media/en/technical-documentation/data-sheets/AD7170.pdf
+    AD7171:
+      https://www.analog.com/media/en/technical-documentation/data-sheets/AD7171.pdf
+    AD7780:
+      https://www.analog.com/media/en/technical-documentation/data-sheets/ad7780.pdf
+    AD7781:
+      https://www.analog.com/media/en/technical-documentation/data-sheets/AD7781.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,ad7170
+      - adi,ad7171
+      - adi,ad7780
+      - adi,ad7781
+
+  reg:
+    maxItems: 1
+
+  avdd-supply:
+    description:
+      The regulator supply for the ADC reference voltage.
+    maxItems: 1
+
+  powerdown-gpios:
+    description:
+      Must be the device tree identifier of the PDRST pin. If
+      specified, it will be asserted during driver probe. As the
+      line is active high, it should be marked GPIO_ACTIVE_HIGH.
+    maxItems: 1
+
+  adi,gain-gpios:
+    description:
+      Must be the device tree identifier of the GAIN pin. Only for
+      the ad778x chips. If specified, it will be asserted during
+      driver probe. As the line is active low, it should be marked
+      GPIO_ACTIVE_LOW.
+    maxItems: 1
+
+  adi,filter-gpios:
+    description:
+      Must be the device tree identifier of the FILTER pin. Only
+      for the ad778x chips. If specified, it will be asserted
+      during driver probe. As the line is active low, it should be
+      marked GPIO_ACTIVE_LOW.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    spi0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@0 {
+            compatible = "adi,ad7780";
+            reg = <0>;
+
+            avdd-supply      = <&vdd_supply>;
+            powerdown-gpios  = <&gpio0 12 GPIO_ACTIVE_HIGH>;
+            adi,gain-gpios   = <&gpio1  5 GPIO_ACTIVE_LOW>;
+            adi,filter-gpios = <&gpio2 15 GPIO_ACTIVE_LOW>;
+        };
+    };
index 0df9befdaecca610aafeac98cdae4daf6bb9453a..78c06e05c8e5e146db91672554cf4c9c9707b251 100644 (file)
@@ -13,8 +13,10 @@ Required properties:
   - compatible: Should be one of:
     - "mediatek,mt2701-auxadc": For MT2701 family of SoCs
     - "mediatek,mt2712-auxadc": For MT2712 family of SoCs
+    - "mediatek,mt6765-auxadc": For MT6765 family of SoCs
     - "mediatek,mt7622-auxadc": For MT7622 family of SoCs
     - "mediatek,mt8173-auxadc": For MT8173 family of SoCs
+    - "mediatek,mt8183-auxadc", "mediatek,mt8173-auxadc": For MT8183 family of SoCs
   - reg: Address range of the AUXADC unit.
   - clocks: Should contain a clock specifier for each entry in clock-names
   - clock-names: Should contain "main".
index 8346bcb04ad79efb85230021f1cd66fc3803010a..93a0bd2efc058281e65b29ceb37170a1fa1e0718 100644 (file)
@@ -38,6 +38,7 @@ Required properties:
     It's required on stm32h7.
 - clock-names: Must be "adc" and/or "bus" depending on part used.
 - interrupt-controller: Identifies the controller node as interrupt-parent
+- vdda-supply: Phandle to the vdda input analog voltage.
 - vref-supply: Phandle to the vref input analog reference voltage.
 - #interrupt-cells = <1>;
 - #address-cells = <1>;
diff --git a/Documentation/devicetree/bindings/iio/chemical/sensirion,sps30.txt b/Documentation/devicetree/bindings/iio/chemical/sensirion,sps30.txt
deleted file mode 100644 (file)
index 6eee270..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-* Sensirion SPS30 particulate matter sensor
-
-Required properties:
-- compatible: must be "sensirion,sps30"
-- reg: the I2C address of the sensor
-
-Example:
-
-sps30@69 {
-       compatible = "sensirion,sps30";
-       reg = <0x69>;
-};
diff --git a/Documentation/devicetree/bindings/iio/chemical/sensirion,sps30.yaml b/Documentation/devicetree/bindings/iio/chemical/sensirion,sps30.yaml
new file mode 100644 (file)
index 0000000..50a50a0
--- /dev/null
@@ -0,0 +1,39 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/chemical/sensirion,sps30.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sensirion SPS30 particulate matter sensor
+
+maintainers:
+  - Tomasz Duszynski <tduszyns@gmail.com>
+
+description: |
+  Air pollution sensor capable of measuring mass concentration of dust
+  particles.
+
+properties:
+  compatible:
+    enum:
+      - sensirion,sps30
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      air-pollution-sensor@69 {
+        compatible = "sensirion,sps30";
+        reg = <0x69>;
+      };
+    };
+
+...
diff --git a/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
new file mode 100644 (file)
index 0000000..7ec3ec9
--- /dev/null
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/frequency/adf4371.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADF4371/ADF4372 Wideband Synthesizers
+
+maintainers:
+  - Popa Stefan <stefan.popa@analog.com>
+
+description: |
+  Analog Devices ADF4371/ADF4372 SPI Wideband Synthesizers
+  https://www.analog.com/media/en/technical-documentation/data-sheets/adf4371.pdf
+  https://www.analog.com/media/en/technical-documentation/data-sheets/adf4372.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,adf4371
+      - adi,adf4372
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    description:
+      Definition of the external clock (see clock/clock-bindings.txt)
+    maxItems: 1
+
+  clock-names:
+    description:
+      Must be "clkin"
+    maxItems: 1
+
+  adi,mute-till-lock-en:
+    type: boolean
+    description:
+      If this property is present, then the supply current to RF8P and RF8N
+      output stage will shut down until the ADF4371/ADF4372 achieves lock as
+      measured by the digital lock detect circuitry.
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+
+examples:
+  - |
+    spi0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        frequency@0 {
+                compatible = "adi,adf4371";
+                reg = <0>;
+                spi-max-frequency = <1000000>;
+                clocks = <&adf4371_clkin>;
+                clock-names = "clkin";
+        };
+    };
+...
diff --git a/Documentation/devicetree/bindings/iio/light/isl29018.txt b/Documentation/devicetree/bindings/iio/light/isl29018.txt
deleted file mode 100644 (file)
index b9bbde3..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-* ISL 29018/29023/29035 I2C ALS, Proximity, and Infrared sensor
-
-Required properties:
-
-  - compatible: Should be one of
-               "isil,isl29018"
-               "isil,isl29023"
-               "isil,isl29035"
-  - reg: the I2C address of the device
-
-Optional properties:
-
-  - interrupts: the sole interrupt generated by the device
-
-  Refer to interrupt-controller/interrupts.txt for generic interrupt client
-  node bindings.
-
-  - vcc-supply: phandle to the regulator that provides power to the sensor.
-
-Example:
-
-isl29018@44 {
-       compatible = "isil,isl29018";
-       reg = <0x44>;
-       interrupt-parent = <&gpio>;
-       interrupts = <TEGRA_GPIO(Z, 2) IRQ_TYPE_LEVEL_HIGH>;
-};
diff --git a/Documentation/devicetree/bindings/iio/light/isl29018.yaml b/Documentation/devicetree/bindings/iio/light/isl29018.yaml
new file mode 100644 (file)
index 0000000..cbb00be
--- /dev/null
@@ -0,0 +1,56 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/light/isl29018.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: |
+  Intersil 29018/29023/29035 Ambient Light, Infrared Light, and Proximity Sensor
+
+maintainers:
+  - Brian Masney <masneyb@onstation.org>
+
+description: |
+  Ambient and infrared light sensing with proximity detection over an i2c
+  interface.
+
+  https://www.renesas.com/us/en/www/doc/datasheet/isl29018.pdf
+  https://www.renesas.com/us/en/www/doc/datasheet/isl29023.pdf
+  https://www.renesas.com/us/en/www/doc/datasheet/isl29035.pdf
+
+properties:
+  compatible:
+    enum:
+      - isil,isl29018
+      - isil,isl29023
+      - isil,isl29035
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  vcc-supply:
+    description: Regulator that provides power to the sensor
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c {
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        sensor@44 {
+                compatible = "isil,isl29018";
+                reg = <0x44>;
+                interrupts-extended = <&msmgpio 61 IRQ_TYPE_LEVEL_HIGH>;
+        };
+    };
+...
diff --git a/Documentation/devicetree/bindings/iio/light/tsl2583.txt b/Documentation/devicetree/bindings/iio/light/tsl2583.txt
deleted file mode 100644 (file)
index 059dffa..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-* TAOS TSL 2580/2581/2583 ALS sensor
-
-Required properties:
-
-  - compatible: Should be one of
-               "amstaos,tsl2580"
-               "amstaos,tsl2581"
-               "amstaos,tsl2583"
-  - reg: the I2C address of the device
-
-Optional properties:
-
-  - interrupts: the sole interrupt generated by the device
-
-  Refer to interrupt-controller/interrupts.txt for generic interrupt client
-  node bindings.
-
-  - vcc-supply: phandle to the regulator that provides power to the sensor.
-
-Example:
-
-tsl2581@29 {
-       compatible = "amstaos,tsl2581";
-       reg = <0x29>;
-};
diff --git a/Documentation/devicetree/bindings/iio/light/tsl2583.yaml b/Documentation/devicetree/bindings/iio/light/tsl2583.yaml
new file mode 100644 (file)
index 0000000..e86ef64
--- /dev/null
@@ -0,0 +1,46 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/light/tsl2583.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: AMS/TAOS Ambient Light Sensor (ALS)
+
+maintainers:
+  - Brian Masney <masneyb@onstation.org>
+
+description: |
+  Ambient light sensing with an i2c interface.
+
+properties:
+  compatible:
+    enum:
+      - amstaos,tsl2580
+      - amstaos,tsl2581
+      - amstaos,tsl2583
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  vcc-supply:
+    description: Regulator that provides power to the sensor
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        light-sensor@29 {
+                compatible = "amstaos,tsl2581";
+                reg = <0x29>;
+        };
+    };
+...
diff --git a/Documentation/devicetree/bindings/iio/light/tsl2772.txt b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
deleted file mode 100644 (file)
index 1c5e6f1..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-* AMS/TAOS ALS and proximity sensor
-
-Required properties:
-
-  - compatible: Should be one of
-               "amstaos,tsl2571"
-               "amstaos,tsl2671"
-               "amstaos,tmd2671"
-               "amstaos,tsl2771"
-               "amstaos,tmd2771"
-               "amstaos,tsl2572"
-               "amstaos,tsl2672"
-               "amstaos,tmd2672"
-               "amstaos,tsl2772"
-               "amstaos,tmd2772"
-               "avago,apds9930"
-  - reg: the I2C address of the device
-
-Optional properties:
-
-  - amstaos,proximity-diodes - proximity diodes to enable. <0>, <1>, or <0 1>
-                               are the only valid values.
-  - led-max-microamp - current for the proximity LED. Must be 100000, 50000,
-                       25000, or 13000.
-  - vdd-supply: phandle to the regulator that provides power to the sensor.
-  - vddio-supply: phandle to the regulator that provides power to the bus.
-  - interrupts: the sole interrupt generated by the device
-
-  Refer to interrupt-controller/interrupts.txt for generic interrupt client
-  node bindings.
-
-Example:
-
-tsl2772@39 {
-       compatible = "amstaos,tsl2772";
-       reg = <0x39>;
-       interrupts-extended = <&msmgpio 61 IRQ_TYPE_EDGE_FALLING>;
-       vdd-supply = <&pm8941_l17>;
-       vddio-supply = <&pm8941_lvs1>;
-       amstaos,proximity-diodes = <0>;
-       led-max-microamp = <100000>;
-};
diff --git a/Documentation/devicetree/bindings/iio/light/tsl2772.yaml b/Documentation/devicetree/bindings/iio/light/tsl2772.yaml
new file mode 100644 (file)
index 0000000..ed2c3d5
--- /dev/null
@@ -0,0 +1,83 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/light/tsl2772.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: AMS/TAOS Ambient Light Sensor (ALS) and Proximity Detector
+
+maintainers:
+  - Brian Masney <masneyb@onstation.org>
+
+description: |
+  Ambient light sensing and proximity detection with an i2c interface.
+  https://ams.com/documents/20143/36005/TSL2772_DS000181_2-00.pdf
+
+properties:
+  compatible:
+    enum:
+      - amstaos,tsl2571
+      - amstaos,tsl2671
+      - amstaos,tmd2671
+      - amstaos,tsl2771
+      - amstaos,tmd2771
+      - amstaos,tsl2572
+      - amstaos,tsl2672
+      - amstaos,tmd2672
+      - amstaos,tsl2772
+      - amstaos,tmd2772
+      - avago,apds9930
+
+  reg:
+    maxItems: 1
+
+  amstaos,proximity-diodes:
+    description: Proximity diodes to enable
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32-array
+      - minItems: 1
+        maxItems: 2
+        items:
+          minimum: 0
+          maximum: 1
+
+  interrupts:
+    maxItems: 1
+
+  led-max-microamp:
+    description: Current for the proximity LED
+    enum:
+      - 13000
+      - 25000
+      - 50000
+      - 100000
+
+  vdd-supply:
+    description: Regulator that provides power to the sensor
+
+  vddio-supply:
+    description: Regulator that provides power to the bus
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        sensor@39 {
+                compatible = "amstaos,tsl2772";
+                reg = <0x39>;
+                interrupts-extended = <&msmgpio 61 IRQ_TYPE_EDGE_FALLING>;
+                vdd-supply = <&pm8941_l17>;
+                vddio-supply = <&pm8941_lvs1>;
+                amstaos,proximity-diodes = <0>;
+                led-max-microamp = <100000>;
+        };
+    };
+...
diff --git a/Documentation/iio/ep93xx_adc.rst b/Documentation/iio/ep93xx_adc.rst
new file mode 100644 (file)
index 0000000..4fd8dea
--- /dev/null
@@ -0,0 +1,40 @@
+==============================
+Cirrus Logic EP93xx ADC driver
+==============================
+
+1. Overview
+===========
+
+The driver is intended to work on both low-end (EP9301, EP9302) devices with
+5-channel ADC and high-end (EP9307, EP9312, EP9315) devices with 10-channel
+touchscreen/ADC module.
+
+2. Channel numbering
+====================
+
+Numbering scheme for channels 0..4 is defined in EP9301 and EP9302 datasheets.
+EP9307, EP9312 and EP9312 have 3 channels more (total 8), but the numbering is
+not defined. So the last three are numbered randomly, let's say.
+
+Assuming ep93xx_adc is IIO device0, you'd find the following entries under
+/sys/bus/iio/devices/iio:device0/:
+
+  +-----------------+---------------+
+  | sysfs entry     | ball/pin name |
+  +=================+===============+
+  | in_voltage0_raw | YM            |
+  +-----------------+---------------+
+  | in_voltage1_raw | SXP           |
+  +-----------------+---------------+
+  | in_voltage2_raw | SXM           |
+  +-----------------+---------------+
+  | in_voltage3_raw | SYP           |
+  +-----------------+---------------+
+  | in_voltage4_raw | SYM           |
+  +-----------------+---------------+
+  | in_voltage5_raw | XP            |
+  +-----------------+---------------+
+  | in_voltage6_raw | XM            |
+  +-----------------+---------------+
+  | in_voltage7_raw | YP            |
+  +-----------------+---------------+
diff --git a/Documentation/iio/ep93xx_adc.txt b/Documentation/iio/ep93xx_adc.txt
deleted file mode 100644 (file)
index 23053e7..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-Cirrus Logic EP93xx ADC driver.
-
-1. Overview
-
-The driver is intended to work on both low-end (EP9301, EP9302) devices with
-5-channel ADC and high-end (EP9307, EP9312, EP9315) devices with 10-channel
-touchscreen/ADC module.
-
-2. Channel numbering
-
-Numbering scheme for channels 0..4 is defined in EP9301 and EP9302 datasheets.
-EP9307, EP9312 and EP9312 have 3 channels more (total 8), but the numbering is
-not defined. So the last three are numbered randomly, let's say.
-
-Assuming ep93xx_adc is IIO device0, you'd find the following entries under
-/sys/bus/iio/devices/iio:device0/:
-
-  +-----------------+---------------+
-  | sysfs entry     | ball/pin name |
-  +-----------------+---------------+
-  | in_voltage0_raw | YM            |
-  | in_voltage1_raw | SXP           |
-  | in_voltage2_raw | SXM           |
-  | in_voltage3_raw | SYP           |
-  | in_voltage4_raw | SYM           |
-  | in_voltage5_raw | XP            |
-  | in_voltage6_raw | XM            |
-  | in_voltage7_raw | YP            |
-  +-----------------+---------------+
diff --git a/Documentation/iio/iio_configfs.rst b/Documentation/iio/iio_configfs.rst
new file mode 100644 (file)
index 0000000..ecbfdb3
--- /dev/null
@@ -0,0 +1,101 @@
+===============================
+Industrial IIO configfs support
+===============================
+
+1. Overview
+===========
+
+Configfs is a filesystem-based manager of kernel objects. IIO uses some
+objects that could be easily configured using configfs (e.g.: devices,
+triggers).
+
+See Documentation/filesystems/configfs/configfs.txt for more information
+about how configfs works.
+
+2. Usage
+========
+
+In order to use configfs support in IIO we need to select it at compile
+time via CONFIG_IIO_CONFIGFS config option.
+
+Then, mount the configfs filesystem (usually under /config directory)::
+
+  $ mkdir /config
+  $ mount -t configfs none /config
+
+At this point, all default IIO groups will be created and can be accessed
+under /config/iio. Next chapters will describe available IIO configuration
+objects.
+
+3. Software triggers
+====================
+
+One of the IIO default configfs groups is the "triggers" group. It is
+automagically accessible when the configfs is mounted and can be found
+under /config/iio/triggers.
+
+IIO software triggers implementation offers support for creating multiple
+trigger types. A new trigger type is usually implemented as a separate
+kernel module following the interface in include/linux/iio/sw_trigger.h::
+
+  /*
+   * drivers/iio/trigger/iio-trig-sample.c
+   * sample kernel module implementing a new trigger type
+   */
+  #include <linux/iio/sw_trigger.h>
+
+
+  static struct iio_sw_trigger *iio_trig_sample_probe(const char *name)
+  {
+       /*
+        * This allocates and registers an IIO trigger plus other
+        * trigger type specific initialization.
+        */
+  }
+
+  static int iio_trig_hrtimer_remove(struct iio_sw_trigger *swt)
+  {
+       /*
+        * This undoes the actions in iio_trig_sample_probe
+        */
+  }
+
+  static const struct iio_sw_trigger_ops iio_trig_sample_ops = {
+       .probe          = iio_trig_sample_probe,
+       .remove         = iio_trig_sample_remove,
+  };
+
+  static struct iio_sw_trigger_type iio_trig_sample = {
+       .name = "trig-sample",
+       .owner = THIS_MODULE,
+       .ops = &iio_trig_sample_ops,
+  };
+
+module_iio_sw_trigger_driver(iio_trig_sample);
+
+Each trigger type has its own directory under /config/iio/triggers. Loading
+iio-trig-sample module will create 'trig-sample' trigger type directory
+/config/iio/triggers/trig-sample.
+
+We support the following interrupt sources (trigger types):
+
+       * hrtimer, uses high resolution timers as interrupt source
+
+3.1 Hrtimer triggers creation and destruction
+---------------------------------------------
+
+Loading iio-trig-hrtimer module will register hrtimer trigger types allowing
+users to create hrtimer triggers under /config/iio/triggers/hrtimer.
+
+e.g::
+
+  $ mkdir /config/iio/triggers/hrtimer/instance1
+  $ rmdir /config/iio/triggers/hrtimer/instance1
+
+Each trigger can have one or more attributes specific to the trigger type.
+
+3.2 "hrtimer" trigger types attributes
+--------------------------------------
+
+"hrtimer" trigger type doesn't have any configurable attribute from /config dir.
+It does introduce the sampling_frequency attribute to trigger directory.
diff --git a/Documentation/iio/iio_configfs.txt b/Documentation/iio/iio_configfs.txt
deleted file mode 100644 (file)
index 4e5f101..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-Industrial IIO configfs support
-
-1. Overview
-
-Configfs is a filesystem-based manager of kernel objects. IIO uses some
-objects that could be easily configured using configfs (e.g.: devices,
-triggers).
-
-See Documentation/filesystems/configfs/configfs.txt for more information
-about how configfs works.
-
-2. Usage
-
-In order to use configfs support in IIO we need to select it at compile
-time via CONFIG_IIO_CONFIGFS config option.
-
-Then, mount the configfs filesystem (usually under /config directory):
-
-$ mkdir /config
-$ mount -t configfs none /config
-
-At this point, all default IIO groups will be created and can be accessed
-under /config/iio. Next chapters will describe available IIO configuration
-objects.
-
-3. Software triggers
-
-One of the IIO default configfs groups is the "triggers" group. It is
-automagically accessible when the configfs is mounted and can be found
-under /config/iio/triggers.
-
-IIO software triggers implementation offers support for creating multiple
-trigger types. A new trigger type is usually implemented as a separate
-kernel module following the interface in include/linux/iio/sw_trigger.h:
-
-/*
- * drivers/iio/trigger/iio-trig-sample.c
- * sample kernel module implementing a new trigger type
- */
-#include <linux/iio/sw_trigger.h>
-
-
-static struct iio_sw_trigger *iio_trig_sample_probe(const char *name)
-{
-       /*
-        * This allocates and registers an IIO trigger plus other
-        * trigger type specific initialization.
-        */
-}
-
-static int iio_trig_hrtimer_remove(struct iio_sw_trigger *swt)
-{
-       /*
-        * This undoes the actions in iio_trig_sample_probe
-        */
-}
-
-static const struct iio_sw_trigger_ops iio_trig_sample_ops = {
-       .probe          = iio_trig_sample_probe,
-       .remove         = iio_trig_sample_remove,
-};
-
-static struct iio_sw_trigger_type iio_trig_sample = {
-       .name = "trig-sample",
-       .owner = THIS_MODULE,
-       .ops = &iio_trig_sample_ops,
-};
-
-module_iio_sw_trigger_driver(iio_trig_sample);
-
-Each trigger type has its own directory under /config/iio/triggers. Loading
-iio-trig-sample module will create 'trig-sample' trigger type directory
-/config/iio/triggers/trig-sample.
-
-We support the following interrupt sources (trigger types):
-       * hrtimer, uses high resolution timers as interrupt source
-
-3.1 Hrtimer triggers creation and destruction
-
-Loading iio-trig-hrtimer module will register hrtimer trigger types allowing
-users to create hrtimer triggers under /config/iio/triggers/hrtimer.
-
-e.g:
-
-$ mkdir /config/iio/triggers/hrtimer/instance1
-$ rmdir /config/iio/triggers/hrtimer/instance1
-
-Each trigger can have one or more attributes specific to the trigger type.
-
-3.2 "hrtimer" trigger types attributes
-
-"hrtimer" trigger type doesn't have any configurable attribute from /config dir.
-It does introduce the sampling_frequency attribute to trigger directory.
diff --git a/Documentation/iio/index.rst b/Documentation/iio/index.rst
new file mode 100644 (file)
index 0000000..0593dca
--- /dev/null
@@ -0,0 +1,12 @@
+:orphan:
+
+==============
+Industrial I/O
+==============
+
+.. toctree::
+   :maxdepth: 1
+
+   iio_configfs
+
+   ep93xx_adc
index 9b4a3e7296ca2c6a3b6b883bfb4b9ce3ea422733..30e91044fde86540140a49ae43d1ea5ee0da58a4 100644 (file)
@@ -551,6 +551,7 @@ W:  http://wiki.analog.com/ADXL345
 W:     http://ez.analog.com/community/linux-device-drivers
 S:     Supported
 F:     drivers/input/misc/adxl34x.c
+F:     Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml
 
 ADXL372 THREE-AXIS DIGITAL ACCELEROMETER DRIVER
 M:     Stefan Popa <stefan.popa@analog.com>
@@ -559,7 +560,7 @@ S:  Supported
 F:     drivers/iio/accel/adxl372.c
 F:     drivers/iio/accel/adxl372_spi.c
 F:     drivers/iio/accel/adxl372_i2c.c
-F:     Documentation/devicetree/bindings/iio/accel/adxl372.txt
+F:     Documentation/devicetree/bindings/iio/accel/adi,adxl372.yaml
 
 AF9013 MEDIA DRIVER
 M:     Antti Palosaari <crope@iki.fi>
@@ -916,6 +917,15 @@ S: Supported
 F:     drivers/iio/adc/ad7768-1.c
 F:     Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt
 
+ANALOG DEVICES INC AD7780 DRIVER
+M:     Michael Hennerich <Michael.Hennerich@analog.com>
+M:     Renato Lui Geh <renatogeh@gmail.com>
+L:     linux-iio@vger.kernel.org
+W:     http://ez.analog.com/community/linux-device-drivers
+S:     Supported
+F:     drivers/iio/adc/ad7780.c
+F:     Documentation/devicetree/bindings/iio/adc/adi,ad7780.yaml
+
 ANALOG DEVICES INC AD9389B DRIVER
 M:     Hans Verkuil <hverkuil-cisco@xs4all.nl>
 L:     linux-media@vger.kernel.org
@@ -928,6 +938,13 @@ S: Supported
 F:     drivers/mux/adgs1408.c
 F:     Documentation/devicetree/bindings/mux/adi,adgs1408.txt
 
+ANALOG DEVICES INC ADIS DRIVER LIBRARY
+M:     Alexandru Ardelean <alexandru.ardelean@analog.com>
+S:     Supported
+L:     linux-iio@vger.kernel.org
+F:     include/linux/iio/imu/adis.h
+F:     drivers/iio/imu/adis.c
+
 ANALOG DEVICES INC ADP5061 DRIVER
 M:     Stefan Popa <stefan.popa@analog.com>
 L:     linux-pm@vger.kernel.org
@@ -6258,6 +6275,14 @@ M:       Philip Kelleher <pjk1939@linux.ibm.com>
 S:     Maintained
 F:     drivers/block/rsxx/
 
+FLEXTIMER FTM-QUADDEC DRIVER
+M:     Patrick Havelange <patrick.havelange@essensium.com>
+L:     linux-iio@vger.kernel.org
+S:     Maintained
+F:     Documentation/ABI/testing/sysfs-bus-counter-ftm-quadddec
+F:     Documentation/devicetree/bindings/counter/ftm-quaddec.txt
+F:     drivers/counter/ftm-quaddec.c
+
 FLOPPY DRIVER
 M:     Jiri Kosina <jikos@kernel.org>
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/jikos/floppy.git
@@ -7855,6 +7880,12 @@ W:       http://industrypack.sourceforge.net
 S:     Maintained
 F:     drivers/ipack/
 
+INFINEON DPS310 Driver
+M:     Eddie James <eajames@linux.ibm.com>
+L:     linux-iio@vger.kernel.org
+F:     drivers/iio/pressure/dps310.c
+S:     Maintained
+
 INFINIBAND SUBSYSTEM
 M:     Doug Ledford <dledford@redhat.com>
 M:     Jason Gunthorpe <jgg@mellanox.com>
@@ -14279,6 +14310,12 @@ S:     Maintained
 F:     drivers/misc/phantom.c
 F:     include/uapi/linux/phantom.h
 
+SENSIRION SPS30 AIR POLLUTION SENSOR DRIVER
+M:     Tomasz Duszynski <tduszyns@gmail.com>
+S:     Maintained
+F:     drivers/iio/chemical/sps30.c
+F:     Documentation/devicetree/bindings/iio/chemical/sensirion,sps30.yaml
+
 SERIAL DEVICE BUS
 M:     Rob Herring <robh@kernel.org>
 L:     linux-serial@vger.kernel.org
@@ -15053,6 +15090,17 @@ L:     linux-erofs@lists.ozlabs.org
 S:     Maintained
 F:     drivers/staging/erofs/
 
+STAGING - FIELDBUS SUBSYSTEM
+M:     Sven Van Asbroeck <TheSven73@gmail.com>
+S:     Maintained
+F:     drivers/staging/fieldbus/*
+F:     drivers/staging/fieldbus/Documentation/
+
+STAGING - HMS ANYBUS-S BUS
+M:     Sven Van Asbroeck <TheSven73@gmail.com>
+S:     Maintained
+F:     drivers/staging/fieldbus/anybuss/
+
 STAGING - INDUSTRIAL IO
 M:     Jonathan Cameron <jic23@kernel.org>
 L:     linux-iio@vger.kernel.org
index c83c8875bf8228330b62806d2ffdca9efa2bbcd2..68a9b73934575cae82e4f41664b788b7352ba3a2 100644 (file)
@@ -352,5 +352,5 @@ static struct platform_driver ftm_quaddec_driver = {
 module_platform_driver(ftm_quaddec_driver);
 
 MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Kjeld Flarup <kfa@deif.com");
-MODULE_AUTHOR("Patrick Havelange <patrick.havelange@essensium.com");
+MODULE_AUTHOR("Kjeld Flarup <kfa@deif.com>");
+MODULE_AUTHOR("Patrick Havelange <patrick.havelange@essensium.com>");
index 1d736a4952abb0a1723a4b88968300da0eb00131..5bd51853b15ec519a30e47995fee85908cb33cb6 100644 (file)
@@ -28,7 +28,7 @@ config IIO_CONFIGFS
        help
          This allows configuring various IIO bits through configfs
          (e.g. software triggers). For more info see
-         Documentation/iio/iio_configfs.txt.
+         Documentation/iio/iio_configfs.rst.
 
 config IIO_TRIGGER
        bool "Enable triggered sampling support"
index 0af4b289fc63924919515ea4c68bea9da557e98c..c4810c73b2a22d72bf242ca720fdaf1fffd2d520 100644 (file)
@@ -70,7 +70,7 @@
 #define  ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT                2
 /* Power supply above 3.625 V */
 #define  ADIS16201_DIAG_STAT_POWER_HIGH_BIT            1
-/* Power supply below 3.15 V */
+/* Power supply below 2.975 V */
 #define  ADIS16201_DIAG_STAT_POWER_LOW_BIT             0
 
 /* System Command Register Definition */
@@ -230,7 +230,7 @@ static const char * const adis16201_status_error_msgs[] = {
        [ADIS16201_DIAG_STAT_SPI_FAIL_BIT] = "SPI failure",
        [ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT] = "Flash update failed",
        [ADIS16201_DIAG_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V",
-       [ADIS16201_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 3.15V",
+       [ADIS16201_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 2.975V",
 };
 
 static const struct adis_data adis16201_data = {
index 40be7adfa1f2c7b90a9a1ac0a2b95f88e0ed10ec..98d77af8a2b0f9f95e09bd7b64a0e56cc4467d37 100644 (file)
@@ -72,7 +72,7 @@
 #define  ADIS16209_STAT_FLASH_UPT_FAIL_BIT     2
 /* Power supply above 3.625 V */
 #define  ADIS16209_STAT_POWER_HIGH_BIT         1
-/* Power supply below 3.15 V */
+/* Power supply below 2.975 V */
 #define  ADIS16209_STAT_POWER_LOW_BIT          0
 
 #define ADIS16209_CMD_REG                      0x3E
@@ -240,7 +240,7 @@ static const char * const adis16209_status_error_msgs[] = {
        [ADIS16209_STAT_SPI_FAIL_BIT] = "SPI failure",
        [ADIS16209_STAT_FLASH_UPT_FAIL_BIT] = "Flash update failed",
        [ADIS16209_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V",
-       [ADIS16209_STAT_POWER_LOW_BIT] = "Power supply below 3.15V",
+       [ADIS16209_STAT_POWER_LOW_BIT] = "Power supply below 2.975V",
 };
 
 static const struct adis_data adis16209_data = {
index 3b84cb243a87415dd3bb36338bf4b5e44d0f16e9..055227cb3d43c4bb6f51f2611aa57d5fc9b9936a 100644 (file)
@@ -782,10 +782,14 @@ static int adxl372_buffer_postenable(struct iio_dev *indio_dev)
        unsigned int mask;
        int i, ret;
 
-       ret = adxl372_set_interrupts(st, ADXL372_INT1_MAP_FIFO_FULL_MSK, 0);
+       ret = iio_triggered_buffer_postenable(indio_dev);
        if (ret < 0)
                return ret;
 
+       ret = adxl372_set_interrupts(st, ADXL372_INT1_MAP_FIFO_FULL_MSK, 0);
+       if (ret < 0)
+               goto err;
+
        mask = *indio_dev->active_scan_mask;
 
        for (i = 0; i < ARRAY_SIZE(adxl372_axis_lookup_table); i++) {
@@ -793,8 +797,10 @@ static int adxl372_buffer_postenable(struct iio_dev *indio_dev)
                        break;
        }
 
-       if (i == ARRAY_SIZE(adxl372_axis_lookup_table))
-               return -EINVAL;
+       if (i == ARRAY_SIZE(adxl372_axis_lookup_table)) {
+               ret = -EINVAL;
+               goto err;
+       }
 
        st->fifo_format = adxl372_axis_lookup_table[i].fifo_format;
        st->fifo_set_size = bitmap_weight(indio_dev->active_scan_mask,
@@ -814,26 +820,25 @@ static int adxl372_buffer_postenable(struct iio_dev *indio_dev)
        if (ret < 0) {
                st->fifo_mode = ADXL372_FIFO_BYPASSED;
                adxl372_set_interrupts(st, 0, 0);
-               return ret;
+               goto err;
        }
 
-       return iio_triggered_buffer_postenable(indio_dev);
+       return 0;
+
+err:
+       iio_triggered_buffer_predisable(indio_dev);
+       return ret;
 }
 
 static int adxl372_buffer_predisable(struct iio_dev *indio_dev)
 {
        struct adxl372_state *st = iio_priv(indio_dev);
-       int ret;
-
-       ret = iio_triggered_buffer_predisable(indio_dev);
-       if (ret < 0)
-               return ret;
 
        adxl372_set_interrupts(st, 0, 0);
        st->fifo_mode = ADXL372_FIFO_BYPASSED;
        adxl372_configure_fifo(st);
 
-       return 0;
+       return iio_triggered_buffer_predisable(indio_dev);
 }
 
 static const struct iio_buffer_setup_ops adxl372_buffer_ops = {
index e14e655ef1652ff4ab3de4fc9c267c9ff699985c..3ef7e3a4804efb9ff9b834bc04e332b31591b39b 100644 (file)
@@ -7,6 +7,8 @@
 
 #include <linux/module.h>
 #include <linux/regmap.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/spi/spi.h>
 
 #include "adxl372.h"
@@ -37,9 +39,16 @@ static const struct spi_device_id adxl372_spi_id[] = {
 };
 MODULE_DEVICE_TABLE(spi, adxl372_spi_id);
 
+static const struct of_device_id adxl372_of_match[] = {
+        { .compatible = "adi,adxl372" },
+        { },
+};
+MODULE_DEVICE_TABLE(of, adxl372_of_match);
+
 static struct spi_driver adxl372_spi_driver = {
        .driver = {
                .name = "adxl372_spi",
+               .of_match_table = adxl372_of_match,
        },
        .probe = adxl372_spi_probe,
        .id_table = adxl372_spi_id,
index e589f64eab9d61f054a200a5b5714fe40c04366d..6645771aa349accd7e4ed4bc363a60e17b5a9ae3 100644 (file)
@@ -1487,6 +1487,7 @@ static const struct acpi_device_id kx_acpi_match[] = {
        {"KIOX0009", KXTJ21009},
        {"KIOX000A", KXCJ91008},
        {"KIOX010A", KXCJ91008}, /* KXCJ91008 inside the display of a 2-in-1 */
+       {"KIOX020A", KXCJ91008},
        {"KXTJ1009", KXTJ21009},
        {"KXJ2109",  KXTJ21009},
        {"SMO8500",  KXCJ91008},
index 011aeff19e3ecfb215bc92f8fd965a9492a7c218..7971ec1eeb7eb87cab80a01a17da8fa67142ef00 100644 (file)
@@ -1,6 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0-only
 #include <linux/device.h>
 #include <linux/kernel.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/spi/spi.h>
 #include <linux/module.h>
 #include <linux/slab.h>
@@ -41,10 +43,17 @@ static const struct spi_device_id kxsd9_spi_id[] = {
 };
 MODULE_DEVICE_TABLE(spi, kxsd9_spi_id);
 
+static const struct of_device_id kxsd9_of_match[] = {
+        { .compatible = "kionix,kxsd9" },
+        { },
+};
+MODULE_DEVICE_TABLE(of, kxsd9_of_match);
+
 static struct spi_driver kxsd9_spi_driver = {
        .driver = {
                .name = "kxsd9",
                .pm = &kxsd9_dev_pm_ops,
+               .of_match_table = kxsd9_of_match,
        },
        .probe = kxsd9_spi_probe,
        .remove = kxsd9_spi_remove,
index 274ce2f8bddfcae5a5e9ff3292a8d80c68d400b3..a923f90f6e803e9df51a653895df9615db1ffd63 100644 (file)
@@ -869,8 +869,9 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev,
                                    enum iio_event_info info,
                                    int *val, int *val2)
 {
-       int ret, i;
        struct sca3000_state *st = iio_priv(indio_dev);
+       long ret;
+       int i;
 
        switch (info) {
        case IIO_EV_INFO_VALUE:
@@ -882,11 +883,11 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev,
                        return ret;
                *val = 0;
                if (chan->channel2 == IIO_MOD_Y)
-                       for_each_set_bit(i, (unsigned long *)&ret,
+                       for_each_set_bit(i, &ret,
                                         ARRAY_SIZE(st->info->mot_det_mult_y))
                                *val += st->info->mot_det_mult_y[i];
                else
-                       for_each_set_bit(i, (unsigned long *)&ret,
+                       for_each_set_bit(i, &ret,
                                         ARRAY_SIZE(st->info->mot_det_mult_xz))
                                *val += st->info->mot_det_mult_xz[i];
 
index 54f2ae91f61432ecba85bf0ae57655b474977a9c..0205c0167cdd6b9f33836001be51cfebd3024b0b 100644 (file)
@@ -45,17 +45,19 @@ static int st_accel_buffer_postenable(struct iio_dev *indio_dev)
                goto allocate_memory_error;
        }
 
-       err = st_sensors_set_axis_enable(indio_dev,
-                                       (u8)indio_dev->active_scan_mask[0]);
+       err = iio_triggered_buffer_postenable(indio_dev);
        if (err < 0)
                goto st_accel_buffer_postenable_error;
 
-       err = iio_triggered_buffer_postenable(indio_dev);
+       err = st_sensors_set_axis_enable(indio_dev,
+                                       (u8)indio_dev->active_scan_mask[0]);
        if (err < 0)
-               goto st_accel_buffer_postenable_error;
+               goto st_sensors_set_axis_enable_error;
 
        return err;
 
+st_sensors_set_axis_enable_error:
+       iio_triggered_buffer_predisable(indio_dev);
 st_accel_buffer_postenable_error:
        kfree(adata->buffer_data);
 allocate_memory_error:
@@ -64,20 +66,22 @@ allocate_memory_error:
 
 static int st_accel_buffer_predisable(struct iio_dev *indio_dev)
 {
-       int err;
+       int err, err2;
        struct st_sensor_data *adata = iio_priv(indio_dev);
 
-       err = iio_triggered_buffer_predisable(indio_dev);
-       if (err < 0)
-               goto st_accel_buffer_predisable_error;
-
        err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
        if (err < 0)
                goto st_accel_buffer_predisable_error;
 
        err = st_sensors_set_enable(indio_dev, false);
+       if (err < 0)
+               goto st_accel_buffer_predisable_error;
 
 st_accel_buffer_predisable_error:
+       err2 = iio_triggered_buffer_predisable(indio_dev);
+       if (!err)
+               err = err2;
+
        kfree(adata->buffer_data);
        return err;
 }
index f96a7702b0205048092bace1301f2e2563d2b495..7e3286265a3845346d11b82d7d8c2b3fe72042fe 100644 (file)
@@ -1085,7 +1085,6 @@ config VIPERBOARD_ADC
 
 config XILINX_XADC
        tristate "Xilinx XADC driver"
-       depends on ARCH_ZYNQ || MICROBLAZE || COMPILE_TEST
        depends on HAS_IOMEM
        select IIO_BUFFER
        select IIO_TRIGGERED_BUFFER
index 659ef37d5fe8f3a0642ebeb3316a5aead59da89d..edc6f1cc90b2448d037174113bbb42c048d77ff7 100644 (file)
@@ -61,6 +61,8 @@
 #define AD7124_CONFIG_REF_SEL(x)       FIELD_PREP(AD7124_CONFIG_REF_SEL_MSK, x)
 #define AD7124_CONFIG_PGA_MSK          GENMASK(2, 0)
 #define AD7124_CONFIG_PGA(x)           FIELD_PREP(AD7124_CONFIG_PGA_MSK, x)
+#define AD7124_CONFIG_IN_BUFF_MSK      GENMASK(7, 6)
+#define AD7124_CONFIG_IN_BUFF(x)       FIELD_PREP(AD7124_CONFIG_IN_BUFF_MSK, x)
 
 /* AD7124_FILTER_X */
 #define AD7124_FILTER_FS_MSK           GENMASK(10, 0)
@@ -108,6 +110,8 @@ struct ad7124_chip_info {
 struct ad7124_channel_config {
        enum ad7124_ref_sel refsel;
        bool bipolar;
+       bool buf_positive;
+       bool buf_negative;
        unsigned int ain;
        unsigned int vref_mv;
        unsigned int pga_bits;
@@ -117,7 +121,7 @@ struct ad7124_channel_config {
 struct ad7124_state {
        const struct ad7124_chip_info *chip_info;
        struct ad_sigma_delta sd;
-       struct ad7124_channel_config channel_config[4];
+       struct ad7124_channel_config *channel_config;
        struct regulator *vref[4];
        struct clk *mclk;
        unsigned int adc_control;
@@ -435,6 +439,7 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
        struct ad7124_state *st = iio_priv(indio_dev);
        struct device_node *child;
        struct iio_chan_spec *chan;
+       struct ad7124_channel_config *chan_config;
        unsigned int ain[2], channel = 0, tmp;
        int ret;
 
@@ -449,8 +454,14 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
        if (!chan)
                return -ENOMEM;
 
+       chan_config = devm_kcalloc(indio_dev->dev.parent, st->num_channels,
+                                  sizeof(*chan_config), GFP_KERNEL);
+       if (!chan_config)
+               return -ENOMEM;
+
        indio_dev->channels = chan;
        indio_dev->num_channels = st->num_channels;
+       st->channel_config = chan_config;
 
        for_each_available_child_of_node(np, child) {
                ret = of_property_read_u32(child, "reg", &channel);
@@ -462,13 +473,6 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
                if (ret)
                        goto err;
 
-               if (ain[0] >= st->chip_info->num_inputs ||
-                   ain[1] >= st->chip_info->num_inputs) {
-                       dev_err(indio_dev->dev.parent,
-                               "Input pin number out of range.\n");
-                       ret = -EINVAL;
-                       goto err;
-               }
                st->channel_config[channel].ain = AD7124_CHANNEL_AINP(ain[0]) |
                                                  AD7124_CHANNEL_AINM(ain[1]);
                st->channel_config[channel].bipolar =
@@ -480,6 +484,11 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
                else
                        st->channel_config[channel].refsel = tmp;
 
+               st->channel_config[channel].buf_positive =
+                       of_property_read_bool(child, "adi,buffered-positive");
+               st->channel_config[channel].buf_negative =
+                       of_property_read_bool(child, "adi,buffered-negative");
+
                *chan = ad7124_channel_template;
                chan->address = channel;
                chan->scan_index = channel;
@@ -499,7 +508,7 @@ err:
 static int ad7124_setup(struct ad7124_state *st)
 {
        unsigned int val, fclk, power_mode;
-       int i, ret;
+       int i, ret, tmp;
 
        fclk = clk_get_rate(st->mclk);
        if (!fclk)
@@ -532,8 +541,12 @@ static int ad7124_setup(struct ad7124_state *st)
                if (ret < 0)
                        return ret;
 
+               tmp = (st->channel_config[i].buf_positive << 1)  +
+                       st->channel_config[i].buf_negative;
+
                val = AD7124_CONFIG_BIPOLAR(st->channel_config[i].bipolar) |
-                     AD7124_CONFIG_REF_SEL(st->channel_config[i].refsel);
+                     AD7124_CONFIG_REF_SEL(st->channel_config[i].refsel) |
+                     AD7124_CONFIG_IN_BUFF(tmp);
                ret = ad_sd_write_reg(&st->sd, AD7124_CONFIG(i), 2, val);
                if (ret < 0)
                        return ret;
index 24c70c3cefb4b4c8cdc77cb9c064d240059cd1ca..aba0fd123a51bb714aa767235915639e1b777ee7 100644 (file)
@@ -140,7 +140,7 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
                           int *val2,
                           long m)
 {
-       int ret;
+       int ret, ch = 0;
        struct ad7606_state *st = iio_priv(indio_dev);
 
        switch (m) {
@@ -157,8 +157,10 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
                *val = (short)ret;
                return IIO_VAL_INT;
        case IIO_CHAN_INFO_SCALE:
+               if (st->sw_mode_en)
+                       ch = chan->address;
                *val = 0;
-               *val2 = st->scale_avail[st->range];
+               *val2 = st->scale_avail[st->range[ch]];
                return IIO_VAL_INT_PLUS_MICRO;
        case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
                *val = st->oversampling;
@@ -194,6 +196,32 @@ static ssize_t in_voltage_scale_available_show(struct device *dev,
 
 static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0);
 
+static int ad7606_write_scale_hw(struct iio_dev *indio_dev, int ch, int val)
+{
+       struct ad7606_state *st = iio_priv(indio_dev);
+
+       gpiod_set_value(st->gpio_range, val);
+
+       return 0;
+}
+
+static int ad7606_write_os_hw(struct iio_dev *indio_dev, int val)
+{
+       struct ad7606_state *st = iio_priv(indio_dev);
+       DECLARE_BITMAP(values, 3);
+
+       values[0] = val;
+
+       gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc,
+                             st->gpio_os->info, values);
+
+       /* AD7616 requires a reset to update value */
+       if (st->chip_info->os_req_reset)
+               ad7606_reset(st);
+
+       return 0;
+}
+
 static int ad7606_write_raw(struct iio_dev *indio_dev,
                            struct iio_chan_spec const *chan,
                            int val,
@@ -201,15 +229,20 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
                            long mask)
 {
        struct ad7606_state *st = iio_priv(indio_dev);
-       DECLARE_BITMAP(values, 3);
-       int i;
+       int i, ret, ch = 0;
 
        switch (mask) {
        case IIO_CHAN_INFO_SCALE:
                mutex_lock(&st->lock);
                i = find_closest(val2, st->scale_avail, st->num_scales);
-               gpiod_set_value(st->gpio_range, i);
-               st->range = i;
+               if (st->sw_mode_en)
+                       ch = chan->address;
+               ret = st->write_scale(indio_dev, ch, i);
+               if (ret < 0) {
+                       mutex_unlock(&st->lock);
+                       return ret;
+               }
+               st->range[ch] = i;
                mutex_unlock(&st->lock);
 
                return 0;
@@ -218,17 +251,12 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
                        return -EINVAL;
                i = find_closest(val, st->oversampling_avail,
                                 st->num_os_ratios);
-
-               values[0] = i;
-
                mutex_lock(&st->lock);
-               gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc,
-                                     st->gpio_os->info, values);
-
-               /* AD7616 requires a reset to update value */
-               if (st->chip_info->os_req_reset)
-                       ad7606_reset(st);
-
+               ret = st->write_os(indio_dev, i);
+               if (ret < 0) {
+                       mutex_unlock(&st->lock);
+                       return ret;
+               }
                st->oversampling = st->oversampling_avail[i];
                mutex_unlock(&st->lock);
 
@@ -536,7 +564,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
        st->bops = bops;
        st->base_address = base_address;
        /* tied to logic low, analog input range is +/- 5V */
-       st->range = 0;
+       st->range[0] = 0;
        st->oversampling = 1;
        st->scale_avail = ad7606_scale_avail;
        st->num_scales = ARRAY_SIZE(ad7606_scale_avail);
@@ -589,6 +617,39 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
        if (ret)
                dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
 
+       st->write_scale = ad7606_write_scale_hw;
+       st->write_os = ad7606_write_os_hw;
+
+       if (st->chip_info->sw_mode_config)
+               st->sw_mode_en = device_property_present(st->dev,
+                                                        "adi,sw-mode");
+
+       if (st->sw_mode_en) {
+               /* After reset, in software mode, Â±10 V is set by default */
+               memset32(st->range, 2, ARRAY_SIZE(st->range));
+               indio_dev->info = &ad7606_info_os_and_range;
+
+               /*
+                * In software mode, the range gpio has no longer its function.
+                * Instead, the scale can be configured individually for each
+                * channel from the range registers.
+                */
+               if (st->chip_info->write_scale_sw)
+                       st->write_scale = st->chip_info->write_scale_sw;
+
+               /*
+                * In software mode, the oversampling is no longer configured
+                * with GPIO pins. Instead, the oversampling can be configured
+                * in configuratiion register.
+                */
+               if (st->chip_info->write_os_sw)
+                       st->write_os = st->chip_info->write_os_sw;
+
+               ret = st->chip_info->sw_mode_config(indio_dev);
+               if (ret < 0)
+                       return ret;
+       }
+
        st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
                                          indio_dev->name, indio_dev->id);
        if (!st->trig)
@@ -643,7 +704,7 @@ static int ad7606_resume(struct device *dev)
        struct ad7606_state *st = iio_priv(indio_dev);
 
        if (st->gpio_standby) {
-               gpiod_set_value(st->gpio_range, st->range);
+               gpiod_set_value(st->gpio_range, st->range[0]);
                gpiod_set_value(st->gpio_standby, 1);
                ad7606_reset(st);
        }
index f9ef52131e742b048d9244a4a2a747ff7ddb6f6f..d8a509c2c428c2ebc07b1329ac043b8897bb01e4 100644 (file)
  *                     oversampling ratios.
  * @oversampling_num   number of elements stored in oversampling_avail array
  * @os_req_reset       some devices require a reset to update oversampling
+ * @write_scale_sw     pointer to the function which writes the scale via spi
+                       in software mode
+ * @write_os_sw                pointer to the function which writes the os via spi
+                       in software mode
+ * @sw_mode_config:    pointer to a function which configured the device
+ *                     for software mode
  */
 struct ad7606_chip_info {
        const struct iio_chan_spec      *channels;
@@ -23,6 +29,9 @@ struct ad7606_chip_info {
        const unsigned int              *oversampling_avail;
        unsigned int                    oversampling_num;
        bool                            os_req_reset;
+       int (*write_scale_sw)(struct iio_dev *indio_dev, int ch, int val);
+       int (*write_os_sw)(struct iio_dev *indio_dev, int val);
+       int (*sw_mode_config)(struct iio_dev *indio_dev);
 };
 
 /**
@@ -34,11 +43,14 @@ struct ad7606_chip_info {
  * @range              voltage range selection, selects which scale to apply
  * @oversampling       oversampling selection
  * @base_address       address from where to read data in parallel operation
+ * @sw_mode_en         software mode enabled
  * @scale_avail                pointer to the array which stores the available scales
  * @num_scales         number of elements stored in the scale_avail array
  * @oversampling_avail pointer to the array which stores the available
  *                     oversampling ratios.
  * @num_os_ratios      number of elements stored in oversampling_avail array
+ * @write_scale                pointer to the function which writes the scale
+ * @write_os           pointer to the function which writes the os
  * @lock               protect sensor state from concurrent accesses to GPIOs
  * @gpio_convst        GPIO descriptor for conversion start signal (CONVST)
  * @gpio_reset         GPIO descriptor for device hard-reset
@@ -57,13 +69,16 @@ struct ad7606_state {
        const struct ad7606_chip_info   *chip_info;
        struct regulator                *reg;
        const struct ad7606_bus_ops     *bops;
-       unsigned int                    range;
+       unsigned int                    range[16];
        unsigned int                    oversampling;
        void __iomem                    *base_address;
+       bool                            sw_mode_en;
        const unsigned int              *scale_avail;
        unsigned int                    num_scales;
        const unsigned int              *oversampling_avail;
        unsigned int                    num_os_ratios;
+       int (*write_scale)(struct iio_dev *indio_dev, int ch, int val);
+       int (*write_os)(struct iio_dev *indio_dev, int val);
 
        struct mutex                    lock; /* protect sensor state */
        struct gpio_desc                *gpio_convst;
index 1423221c6e065a415ea28eeb56df69d9a920c1e7..2640b75fb774cae659bcdd718967504f25e3a83d 100644 (file)
@@ -357,7 +357,7 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
        ret = ad_sigma_delta_set_channel(sigma_delta,
                indio_dev->channels[channel].address);
        if (ret)
-               goto err_predisable;
+               return ret;
 
        spi_bus_lock(sigma_delta->spi->master);
        sigma_delta->bus_locked = true;
@@ -374,7 +374,6 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
 
 err_unlock:
        spi_bus_unlock(sigma_delta->spi->master);
-err_predisable:
 
        return ret;
 }
index d384cf0250ffc7700d1dc14b3069ad0bc08d74b4..a2837a0e7cba42e1f5ec87ae0ebd6cac6332da02 100644 (file)
@@ -1578,8 +1578,7 @@ static void at91_adc_hw_init(struct at91_adc_state *st)
 static ssize_t at91_adc_get_fifo_state(struct device *dev,
                                       struct device_attribute *attr, char *buf)
 {
-       struct iio_dev *indio_dev =
-                       platform_get_drvdata(to_platform_device(dev));
+       struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct at91_adc_state *st = iio_priv(indio_dev);
 
        return scnprintf(buf, PAGE_SIZE, "%d\n", !!st->dma_st.dma_chan);
@@ -1588,8 +1587,7 @@ static ssize_t at91_adc_get_fifo_state(struct device *dev,
 static ssize_t at91_adc_get_watermark(struct device *dev,
                                      struct device_attribute *attr, char *buf)
 {
-       struct iio_dev *indio_dev =
-                       platform_get_drvdata(to_platform_device(dev));
+       struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct at91_adc_state *st = iio_priv(indio_dev);
 
        return scnprintf(buf, PAGE_SIZE, "%d\n", st->dma_st.watermark);
@@ -1841,8 +1839,7 @@ static int at91_adc_remove(struct platform_device *pdev)
 
 static __maybe_unused int at91_adc_suspend(struct device *dev)
 {
-       struct iio_dev *indio_dev =
-                       platform_get_drvdata(to_platform_device(dev));
+       struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct at91_adc_state *st = iio_priv(indio_dev);
 
        /*
@@ -1862,8 +1859,7 @@ static __maybe_unused int at91_adc_suspend(struct device *dev)
 
 static __maybe_unused int at91_adc_resume(struct device *dev)
 {
-       struct iio_dev *indio_dev =
-                       platform_get_drvdata(to_platform_device(dev));
+       struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct at91_adc_state *st = iio_priv(indio_dev);
        int ret;
 
index d23709ed9049bf68b9a9f5902dca6f675121b72b..32f1c4a33b2085495bcc1f01909aa76a8fc4a329 100644 (file)
@@ -1359,7 +1359,7 @@ static int at91_adc_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM_SLEEP
 static int at91_adc_suspend(struct device *dev)
 {
-       struct iio_dev *idev = platform_get_drvdata(to_platform_device(dev));
+       struct iio_dev *idev = dev_get_drvdata(dev);
        struct at91_adc_state *st = iio_priv(idev);
 
        pinctrl_pm_select_sleep_state(dev);
@@ -1370,7 +1370,7 @@ static int at91_adc_suspend(struct device *dev)
 
 static int at91_adc_resume(struct device *dev)
 {
-       struct iio_dev *idev = platform_get_drvdata(to_platform_device(dev));
+       struct iio_dev *idev = dev_get_drvdata(dev);
        struct at91_adc_state *st = iio_priv(idev);
 
        clk_prepare_enable(st->clk);
index 4fe97c2a0f4336b8a135b87c01886c2a9e735fd2..26a7bbe4d534df3fb237bbf8597850dd4643966e 100644 (file)
@@ -78,6 +78,7 @@
 #define IMX7D_REG_ADC_INT_STATUS_CHANNEL_CONV_TIME_OUT         0xf0000
 
 #define IMX7D_ADC_TIMEOUT              msecs_to_jiffies(100)
+#define IMX7D_ADC_INPUT_CLK            24000000
 
 enum imx7d_adc_clk_pre_div {
        IMX7D_ADC_ANALOG_CLK_PRE_DIV_4,
@@ -100,8 +101,6 @@ struct imx7d_adc_feature {
        enum imx7d_adc_average_num avg_num;
 
        u32 core_time_unit;     /* impact the sample rate */
-
-       bool average_en;
 };
 
 struct imx7d_adc {
@@ -179,7 +178,6 @@ static void imx7d_adc_feature_config(struct imx7d_adc *info)
        info->adc_feature.clk_pre_div = IMX7D_ADC_ANALOG_CLK_PRE_DIV_4;
        info->adc_feature.avg_num = IMX7D_ADC_AVERAGE_NUM_32;
        info->adc_feature.core_time_unit = 1;
-       info->adc_feature.average_en = true;
 }
 
 static void imx7d_adc_sample_rate_set(struct imx7d_adc *info)
@@ -240,9 +238,8 @@ static void imx7d_adc_channel_set(struct imx7d_adc *info)
 
        /* the channel choose single conversion, and enable average mode */
        cfg1 |= (IMX7D_REG_ADC_CH_CFG1_CHANNEL_EN |
-                IMX7D_REG_ADC_CH_CFG1_CHANNEL_SINGLE);
-       if (info->adc_feature.average_en)
-               cfg1 |= IMX7D_REG_ADC_CH_CFG1_CHANNEL_AVG_EN;
+                IMX7D_REG_ADC_CH_CFG1_CHANNEL_SINGLE |
+                IMX7D_REG_ADC_CH_CFG1_CHANNEL_AVG_EN);
 
        /*
         * physical channel 0 chose logical channel A
@@ -272,13 +269,11 @@ static void imx7d_adc_channel_set(struct imx7d_adc *info)
 
 static u32 imx7d_adc_get_sample_rate(struct imx7d_adc *info)
 {
-       /* input clock is always 24MHz */
-       u32 input_clk = 24000000;
        u32 analogue_core_clk;
        u32 core_time_unit = info->adc_feature.core_time_unit;
        u32 tmp;
 
-       analogue_core_clk = input_clk / info->pre_div_num;
+       analogue_core_clk = IMX7D_ADC_INPUT_CLK / info->pre_div_num;
        tmp = (core_time_unit + 1) * 6;
 
        return analogue_core_clk / tmp;
@@ -493,11 +488,8 @@ static int imx7d_adc_probe(struct platform_device *pdev)
        info->dev = dev;
 
        info->regs = devm_platform_ioremap_resource(pdev, 0);
-       if (IS_ERR(info->regs)) {
-               ret = PTR_ERR(info->regs);
-               dev_err(dev, "Failed to remap adc memory, err = %d\n", ret);
-               return ret;
-       }
+       if (IS_ERR(info->regs))
+               return PTR_ERR(info->regs);
 
        irq = platform_get_irq(pdev, 0);
        if (irq < 0) {
@@ -531,9 +523,7 @@ static int imx7d_adc_probe(struct platform_device *pdev)
        indio_dev->channels = imx7d_adc_iio_channels;
        indio_dev->num_channels = ARRAY_SIZE(imx7d_adc_iio_channels);
 
-       ret = devm_request_irq(dev, irq,
-                              imx7d_adc_isr, 0,
-                              dev_name(dev), info);
+       ret = devm_request_irq(dev, irq, imx7d_adc_isr, 0, dev_name(dev), info);
        if (ret < 0) {
                dev_err(dev, "Failed requesting irq, irq = %d\n", irq);
                return ret;
index 70bbcf253cb641eec53ab0f775070a782e5d7ccc..7b28d045d2719f3e3a710eaa2ffce0e3183d561e 100644 (file)
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Amlogic Meson Successive Approximation Register (SAR) A/D Converter
  *
index d1759c804b2694e98c289f65b1330089f56916bb..7bbb64ca3b3248cbf840e5a9606e0644c5a224bf 100644 (file)
 #define MT6577_AUXADC_POWER_READY_MS          1
 #define MT6577_AUXADC_SAMPLE_READY_US         25
 
+struct mtk_auxadc_compatible {
+       bool sample_data_cali;
+       bool check_global_idle;
+};
+
 struct mt6577_auxadc_device {
        void __iomem *reg_base;
        struct clk *adc_clk;
        struct mutex lock;
+       const struct mtk_auxadc_compatible *dev_comp;
+};
+
+static const struct mtk_auxadc_compatible mt8173_compat = {
+       .sample_data_cali = false,
+       .check_global_idle = true,
+};
+
+static const struct mtk_auxadc_compatible mt6765_compat = {
+       .sample_data_cali = true,
+       .check_global_idle = false,
 };
 
 #define MT6577_AUXADC_CHANNEL(idx) {                               \
@@ -66,6 +82,11 @@ static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = {
        MT6577_AUXADC_CHANNEL(15),
 };
 
+static int mt_auxadc_get_cali_data(int rawdata, bool enable_cali)
+{
+       return rawdata;
+}
+
 static inline void mt6577_auxadc_mod_reg(void __iomem *reg,
                                         u32 or_mask, u32 and_mask)
 {
@@ -112,15 +133,17 @@ static int mt6577_auxadc_read(struct iio_dev *indio_dev,
        /* we must delay here for hardware sample channel data */
        udelay(MT6577_AUXADC_SAMPLE_READY_US);
 
-       /* check MTK_AUXADC_CON2 if auxadc is idle */
-       ret = readl_poll_timeout(adc_dev->reg_base + MT6577_AUXADC_CON2, val,
-                                ((val & MT6577_AUXADC_STA) == 0),
-                                MT6577_AUXADC_SLEEP_US,
-                                MT6577_AUXADC_TIMEOUT_US);
-       if (ret < 0) {
-               dev_err(indio_dev->dev.parent,
-                       "wait for auxadc idle time out\n");
-               goto err_timeout;
+       if (adc_dev->dev_comp->check_global_idle) {
+               /* check MTK_AUXADC_CON2 if auxadc is idle */
+               ret = readl_poll_timeout(adc_dev->reg_base + MT6577_AUXADC_CON2,
+                                        val, ((val & MT6577_AUXADC_STA) == 0),
+                                        MT6577_AUXADC_SLEEP_US,
+                                        MT6577_AUXADC_TIMEOUT_US);
+               if (ret < 0) {
+                       dev_err(indio_dev->dev.parent,
+                               "wait for auxadc idle time out\n");
+                       goto err_timeout;
+               }
        }
 
        /* read channel and make sure ready bit == 1 */
@@ -155,6 +178,8 @@ static int mt6577_auxadc_read_raw(struct iio_dev *indio_dev,
                                  int *val2,
                                  long info)
 {
+       struct mt6577_auxadc_device *adc_dev = iio_priv(indio_dev);
+
        switch (info) {
        case IIO_CHAN_INFO_PROCESSED:
                *val = mt6577_auxadc_read(indio_dev, chan);
@@ -164,6 +189,8 @@ static int mt6577_auxadc_read_raw(struct iio_dev *indio_dev,
                                chan->channel);
                        return *val;
                }
+               if (adc_dev->dev_comp->sample_data_cali)
+                       *val = mt_auxadc_get_cali_data(*val, true);
                return IIO_VAL_INT;
 
        default:
@@ -296,10 +323,11 @@ static SIMPLE_DEV_PM_OPS(mt6577_auxadc_pm_ops,
                         mt6577_auxadc_resume);
 
 static const struct of_device_id mt6577_auxadc_of_match[] = {
-       { .compatible = "mediatek,mt2701-auxadc", },
-       { .compatible = "mediatek,mt2712-auxadc", },
-       { .compatible = "mediatek,mt7622-auxadc", },
-       { .compatible = "mediatek,mt8173-auxadc", },
+       { .compatible = "mediatek,mt2701-auxadc", .data = &mt8173_compat},
+       { .compatible = "mediatek,mt2712-auxadc", .data = &mt8173_compat},
+       { .compatible = "mediatek,mt7622-auxadc", .data = &mt8173_compat},
+       { .compatible = "mediatek,mt8173-auxadc", .data = &mt8173_compat},
+       { .compatible = "mediatek,mt6765-auxadc", .data = &mt6765_compat},
        { }
 };
 MODULE_DEVICE_TABLE(of, mt6577_auxadc_of_match);
index 2c0d0316d149707f96e069b11711fa2988ae9fa8..2d685730f8673e650e1f32d16dc22fe481445438 100644 (file)
@@ -485,10 +485,8 @@ static int rcar_gyroadc_probe(struct platform_device *pdev)
        int ret;
 
        indio_dev = devm_iio_device_alloc(dev, sizeof(*priv));
-       if (!indio_dev) {
-               dev_err(dev, "Failed to allocate IIO device.\n");
+       if (!indio_dev)
                return -ENOMEM;
-       }
 
        priv = iio_priv(indio_dev);
        priv->dev = dev;
index 2327ec18b40cc1f43849d38b8f82b9865bf5f367..1f7ce5186dfcec7541c4b5462f0db7aa3a8ed8d4 100644 (file)
@@ -87,6 +87,7 @@ struct stm32_adc_priv_cfg {
  * @domain:            irq domain reference
  * @aclk:              clock reference for the analog circuitry
  * @bclk:              bus clock common for all ADCs, depends on part used
+ * @vdda:              vdda analog supply reference
  * @vref:              regulator reference
  * @cfg:               compatible configuration data
  * @common:            common data for all ADC instances
@@ -97,6 +98,7 @@ struct stm32_adc_priv {
        struct irq_domain               *domain;
        struct clk                      *aclk;
        struct clk                      *bclk;
+       struct regulator                *vdda;
        struct regulator                *vref;
        const struct stm32_adc_priv_cfg *cfg;
        struct stm32_adc_common         common;
@@ -394,10 +396,16 @@ static int stm32_adc_core_hw_start(struct device *dev)
        struct stm32_adc_priv *priv = to_stm32_adc_priv(common);
        int ret;
 
+       ret = regulator_enable(priv->vdda);
+       if (ret < 0) {
+               dev_err(dev, "vdda enable failed %d\n", ret);
+               return ret;
+       }
+
        ret = regulator_enable(priv->vref);
        if (ret < 0) {
                dev_err(dev, "vref enable failed\n");
-               return ret;
+               goto err_vdda_disable;
        }
 
        if (priv->bclk) {
@@ -425,6 +433,8 @@ err_bclk_disable:
                clk_disable_unprepare(priv->bclk);
 err_regulator_disable:
        regulator_disable(priv->vref);
+err_vdda_disable:
+       regulator_disable(priv->vdda);
 
        return ret;
 }
@@ -441,6 +451,7 @@ static void stm32_adc_core_hw_stop(struct device *dev)
        if (priv->bclk)
                clk_disable_unprepare(priv->bclk);
        regulator_disable(priv->vref);
+       regulator_disable(priv->vdda);
 }
 
 static int stm32_adc_probe(struct platform_device *pdev)
@@ -468,6 +479,14 @@ static int stm32_adc_probe(struct platform_device *pdev)
                return PTR_ERR(priv->common.base);
        priv->common.phys_base = res->start;
 
+       priv->vdda = devm_regulator_get(&pdev->dev, "vdda");
+       if (IS_ERR(priv->vdda)) {
+               ret = PTR_ERR(priv->vdda);
+               if (ret != -EPROBE_DEFER)
+                       dev_err(&pdev->dev, "vdda get failed, %d\n", ret);
+               return ret;
+       }
+
        priv->vref = devm_regulator_get(&pdev->dev, "vref");
        if (IS_ERR(priv->vref)) {
                ret = PTR_ERR(priv->vref);
index 19adc2b23472bb077a5bce8e563c38e19da3dfa8..ee1e0569d0e166b5ba90156a3120a7d699d921e6 100644 (file)
 #define DFSDM_MAX_INT_OVERSAMPLING 256
 #define DFSDM_MAX_FL_OVERSAMPLING 1024
 
-/* Max sample resolutions */
-#define DFSDM_MAX_RES BIT(31)
-#define DFSDM_DATA_RES BIT(23)
+/* Limit filter output resolution to 31 bits. (i.e. sample range is +/-2^30) */
+#define DFSDM_DATA_MAX BIT(30)
+/*
+ * Data are output as two's complement data in a 24 bit field.
+ * Data from filters are in the range +/-2^(n-1)
+ * 2^(n-1) maximum positive value cannot be coded in 2's complement n bits
+ * An extra bit is required to avoid wrap-around of the binary code for 2^(n-1)
+ * So, the resolution of samples from filter is actually limited to 23 bits
+ */
+#define DFSDM_DATA_RES 24
 
 /* Filter configuration */
 #define DFSDM_CR1_CFG_MASK (DFSDM_CR1_RCH_MASK | DFSDM_CR1_RCONT_MASK | \
@@ -181,14 +188,15 @@ static int stm32_dfsdm_get_jextsel(struct iio_dev *indio_dev,
        return -EINVAL;
 }
 
-static int stm32_dfsdm_set_osrs(struct stm32_dfsdm_filter *fl,
-                               unsigned int fast, unsigned int oversamp)
+static int stm32_dfsdm_compute_osrs(struct stm32_dfsdm_filter *fl,
+                                   unsigned int fast, unsigned int oversamp)
 {
        unsigned int i, d, fosr, iosr;
-       u64 res;
-       s64 delta;
+       u64 res, max;
+       int bits, shift;
        unsigned int m = 1;     /* multiplication factor */
        unsigned int p = fl->ford;      /* filter order (ford) */
+       struct stm32_dfsdm_filter_osr *flo = &fl->flo[fast];
 
        pr_debug("%s: Requested oversampling: %d\n",  __func__, oversamp);
        /*
@@ -207,11 +215,8 @@ static int stm32_dfsdm_set_osrs(struct stm32_dfsdm_filter *fl,
 
        /*
         * Look for filter and integrator oversampling ratios which allows
-        * to reach 24 bits data output resolution.
-        * Leave as soon as if exact resolution if reached.
-        * Otherwise the higher resolution below 32 bits is kept.
+        * to maximize data output resolution.
         */
-       fl->res = 0;
        for (fosr = 1; fosr <= DFSDM_MAX_FL_OVERSAMPLING; fosr++) {
                for (iosr = 1; iosr <= DFSDM_MAX_INT_OVERSAMPLING; iosr++) {
                        if (fast)
@@ -236,33 +241,91 @@ static int stm32_dfsdm_set_osrs(struct stm32_dfsdm_filter *fl,
                        res = fosr;
                        for (i = p - 1; i > 0; i--) {
                                res = res * (u64)fosr;
-                               if (res > DFSDM_MAX_RES)
+                               if (res > DFSDM_DATA_MAX)
                                        break;
                        }
-                       if (res > DFSDM_MAX_RES)
+                       if (res > DFSDM_DATA_MAX)
                                continue;
+
                        res = res * (u64)m * (u64)iosr;
-                       if (res > DFSDM_MAX_RES)
+                       if (res > DFSDM_DATA_MAX)
                                continue;
 
-                       delta = res - DFSDM_DATA_RES;
-
-                       if (res >= fl->res) {
-                               fl->res = res;
-                               fl->fosr = fosr;
-                               fl->iosr = iosr;
-                               fl->fast = fast;
-                               pr_debug("%s: fosr = %d, iosr = %d\n",
-                                        __func__, fl->fosr, fl->iosr);
+                       if (res >= flo->res) {
+                               flo->res = res;
+                               flo->fosr = fosr;
+                               flo->iosr = iosr;
+
+                               bits = fls(flo->res);
+                               /* 8 LBSs in data register contain chan info */
+                               max = flo->res << 8;
+
+                               /* if resolution is not a power of two */
+                               if (flo->res > BIT(bits - 1))
+                                       bits++;
+                               else
+                                       max--;
+
+                               shift = DFSDM_DATA_RES - bits;
+                               /*
+                                * Compute right/left shift
+                                * Right shift is performed by hardware
+                                * when transferring samples to data register.
+                                * Left shift is done by software on buffer
+                                */
+                               if (shift > 0) {
+                                       /* Resolution is lower than 24 bits */
+                                       flo->rshift = 0;
+                                       flo->lshift = shift;
+                               } else {
+                                       /*
+                                        * If resolution is 24 bits or more,
+                                        * max positive value may be ambiguous
+                                        * (equal to max negative value as sign
+                                        * bit is dropped).
+                                        * Reduce resolution to 23 bits (rshift)
+                                        * to keep the sign on bit 23 and treat
+                                        * saturation before rescaling on 24
+                                        * bits (lshift).
+                                        */
+                                       flo->rshift = 1 - shift;
+                                       flo->lshift = 1;
+                                       max >>= flo->rshift;
+                               }
+                               flo->max = (s32)max;
+
+                               pr_debug("%s: fast %d, fosr %d, iosr %d, res 0x%llx/%d bits, rshift %d, lshift %d\n",
+                                        __func__, fast, flo->fosr, flo->iosr,
+                                        flo->res, bits, flo->rshift,
+                                        flo->lshift);
                        }
-
-                       if (!delta)
-                               return 0;
                }
        }
 
-       if (!fl->res)
+       if (!flo->res)
+               return -EINVAL;
+
+       return 0;
+}
+
+static int stm32_dfsdm_compute_all_osrs(struct iio_dev *indio_dev,
+                                       unsigned int oversamp)
+{
+       struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
+       struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id];
+       int ret0, ret1;
+
+       memset(&fl->flo[0], 0, sizeof(fl->flo[0]));
+       memset(&fl->flo[1], 0, sizeof(fl->flo[1]));
+
+       ret0 = stm32_dfsdm_compute_osrs(fl, 0, oversamp);
+       ret1 = stm32_dfsdm_compute_osrs(fl, 1, oversamp);
+       if (ret0 < 0 && ret1 < 0) {
+               dev_err(&indio_dev->dev,
+                       "Filter parameters not found: errors %d/%d\n",
+                       ret0, ret1);
                return -EINVAL;
+       }
 
        return 0;
 }
@@ -384,6 +447,50 @@ static int stm32_dfsdm_filter_set_trig(struct stm32_dfsdm_adc *adc,
        return 0;
 }
 
+static int stm32_dfsdm_channels_configure(struct stm32_dfsdm_adc *adc,
+                                         unsigned int fl_id,
+                                         struct iio_trigger *trig)
+{
+       struct iio_dev *indio_dev = iio_priv_to_dev(adc);
+       struct regmap *regmap = adc->dfsdm->regmap;
+       struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[fl_id];
+       struct stm32_dfsdm_filter_osr *flo = &fl->flo[0];
+       const struct iio_chan_spec *chan;
+       unsigned int bit;
+       int ret;
+
+       fl->fast = 0;
+
+       /*
+        * In continuous mode, use fast mode configuration,
+        * if it provides a better resolution.
+        */
+       if (adc->nconv == 1 && !trig &&
+           (indio_dev->currentmode & INDIO_BUFFER_SOFTWARE)) {
+               if (fl->flo[1].res >= fl->flo[0].res) {
+                       fl->fast = 1;
+                       flo = &fl->flo[1];
+               }
+       }
+
+       if (!flo->res)
+               return -EINVAL;
+
+       for_each_set_bit(bit, &adc->smask,
+                        sizeof(adc->smask) * BITS_PER_BYTE) {
+               chan = indio_dev->channels + bit;
+
+               ret = regmap_update_bits(regmap,
+                                        DFSDM_CHCFGR2(chan->channel),
+                                        DFSDM_CHCFGR2_DTRBS_MASK,
+                                        DFSDM_CHCFGR2_DTRBS(flo->rshift));
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
 static int stm32_dfsdm_filter_configure(struct stm32_dfsdm_adc *adc,
                                        unsigned int fl_id,
                                        struct iio_trigger *trig)
@@ -391,6 +498,7 @@ static int stm32_dfsdm_filter_configure(struct stm32_dfsdm_adc *adc,
        struct iio_dev *indio_dev = iio_priv_to_dev(adc);
        struct regmap *regmap = adc->dfsdm->regmap;
        struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[fl_id];
+       struct stm32_dfsdm_filter_osr *flo = &fl->flo[fl->fast];
        u32 cr1;
        const struct iio_chan_spec *chan;
        unsigned int bit, jchg = 0;
@@ -398,13 +506,13 @@ static int stm32_dfsdm_filter_configure(struct stm32_dfsdm_adc *adc,
 
        /* Average integrator oversampling */
        ret = regmap_update_bits(regmap, DFSDM_FCR(fl_id), DFSDM_FCR_IOSR_MASK,
-                                DFSDM_FCR_IOSR(fl->iosr - 1));
+                                DFSDM_FCR_IOSR(flo->iosr - 1));
        if (ret)
                return ret;
 
        /* Filter order and Oversampling */
        ret = regmap_update_bits(regmap, DFSDM_FCR(fl_id), DFSDM_FCR_FOSR_MASK,
-                                DFSDM_FCR_FOSR(fl->fosr - 1));
+                                DFSDM_FCR_FOSR(flo->fosr - 1));
        if (ret)
                return ret;
 
@@ -417,6 +525,12 @@ static int stm32_dfsdm_filter_configure(struct stm32_dfsdm_adc *adc,
        if (ret)
                return ret;
 
+       ret = regmap_update_bits(regmap, DFSDM_CR1(fl_id),
+                                DFSDM_CR1_FAST_MASK,
+                                DFSDM_CR1_FAST(fl->fast));
+       if (ret)
+               return ret;
+
        /*
         * DFSDM modes configuration W.R.T audio/iio type modes
         * ----------------------------------------------------------------
@@ -563,7 +677,6 @@ static int dfsdm_adc_set_samp_freq(struct iio_dev *indio_dev,
                                   unsigned int spi_freq)
 {
        struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
-       struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id];
        unsigned int oversamp;
        int ret;
 
@@ -573,11 +686,10 @@ static int dfsdm_adc_set_samp_freq(struct iio_dev *indio_dev,
                        "Rate not accurate. requested (%u), actual (%u)\n",
                        sample_freq, spi_freq / oversamp);
 
-       ret = stm32_dfsdm_set_osrs(fl, 0, oversamp);
-       if (ret < 0) {
-               dev_err(&indio_dev->dev, "No filter parameters that match!\n");
+       ret = stm32_dfsdm_compute_all_osrs(indio_dev, oversamp);
+       if (ret < 0)
                return ret;
-       }
+
        adc->sample_freq = spi_freq / oversamp;
        adc->oversamp = oversamp;
 
@@ -623,6 +735,10 @@ static int stm32_dfsdm_start_conv(struct stm32_dfsdm_adc *adc,
        struct regmap *regmap = adc->dfsdm->regmap;
        int ret;
 
+       ret = stm32_dfsdm_channels_configure(adc, adc->fl_id, trig);
+       if (ret < 0)
+               return ret;
+
        ret = stm32_dfsdm_start_channel(adc);
        if (ret < 0)
                return ret;
@@ -702,6 +818,30 @@ static unsigned int stm32_dfsdm_adc_dma_residue(struct stm32_dfsdm_adc *adc)
        return 0;
 }
 
+static inline void stm32_dfsdm_process_data(struct stm32_dfsdm_adc *adc,
+                                           s32 *buffer)
+{
+       struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id];
+       struct stm32_dfsdm_filter_osr *flo = &fl->flo[fl->fast];
+       unsigned int i = adc->nconv;
+       s32 *ptr = buffer;
+
+       while (i--) {
+               /* Mask 8 LSB that contains the channel ID */
+               *ptr &= 0xFFFFFF00;
+               /* Convert 2^(n-1) sample to 2^(n-1)-1 to avoid wrap-around */
+               if (*ptr > flo->max)
+                       *ptr -= 1;
+               /*
+                * Samples from filter are retrieved with 23 bits resolution
+                * or less. Shift left to align MSB on 24 bits.
+                */
+               *ptr <<= flo->lshift;
+
+               ptr++;
+       }
+}
+
 static irqreturn_t stm32_dfsdm_adc_trigger_handler(int irq, void *p)
 {
        struct iio_poll_func *pf = p;
@@ -710,7 +850,9 @@ static irqreturn_t stm32_dfsdm_adc_trigger_handler(int irq, void *p)
        int available = stm32_dfsdm_adc_dma_residue(adc);
 
        while (available >= indio_dev->scan_bytes) {
-               u32 *buffer = (u32 *)&adc->rx_buf[adc->bufi];
+               s32 *buffer = (s32 *)&adc->rx_buf[adc->bufi];
+
+               stm32_dfsdm_process_data(adc, buffer);
 
                iio_push_to_buffers_with_timestamp(indio_dev, buffer,
                                                   pf->timestamp);
@@ -751,10 +893,10 @@ static void stm32_dfsdm_dma_buffer_done(void *data)
        old_pos = adc->bufi;
 
        while (available >= indio_dev->scan_bytes) {
-               u32 *buffer = (u32 *)&adc->rx_buf[adc->bufi];
+               s32 *buffer = (s32 *)&adc->rx_buf[adc->bufi];
+
+               stm32_dfsdm_process_data(adc, buffer);
 
-               /* Mask 8 LSB that contains the channel ID */
-               *buffer = (*buffer & 0xFFFFFF00) << 8;
                available -= indio_dev->scan_bytes;
                adc->bufi += indio_dev->scan_bytes;
                if (adc->bufi >= adc->buf_sz) {
@@ -776,6 +918,11 @@ static void stm32_dfsdm_dma_buffer_done(void *data)
 static int stm32_dfsdm_adc_dma_start(struct iio_dev *indio_dev)
 {
        struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
+       /*
+        * The DFSDM supports half-word transfers. However, for 16 bits record,
+        * 4 bytes buswidth is kept, to avoid losing samples LSBs when left
+        * shift is required.
+        */
        struct dma_slave_config config = {
                .src_addr = (dma_addr_t)adc->dfsdm->phys_base,
                .src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
@@ -1068,7 +1215,6 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev,
                                 int val, int val2, long mask)
 {
        struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
-       struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id];
        struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[chan->channel];
        unsigned int spi_freq;
        int ret = -EINVAL;
@@ -1078,7 +1224,7 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev,
                ret = iio_device_claim_direct_mode(indio_dev);
                if (ret)
                        return ret;
-               ret = stm32_dfsdm_set_osrs(fl, 0, val);
+               ret = stm32_dfsdm_compute_all_osrs(indio_dev, val);
                if (!ret)
                        adc->oversamp = val;
                iio_device_release_direct_mode(indio_dev);
@@ -1277,11 +1423,11 @@ static int stm32_dfsdm_adc_chan_init_one(struct iio_dev *indio_dev,
                                        BIT(IIO_CHAN_INFO_SAMP_FREQ);
 
        if (adc->dev_data->type == DFSDM_AUDIO) {
-               ch->scan_type.sign = 's';
                ch->ext_info = dfsdm_adc_audio_ext_info;
        } else {
-               ch->scan_type.sign = 'u';
+               ch->scan_type.shift = 8;
        }
+       ch->scan_type.sign = 's';
        ch->scan_type.realbits = 24;
        ch->scan_type.storagebits = 32;
 
@@ -1327,8 +1473,7 @@ static int stm32_dfsdm_adc_init(struct iio_dev *indio_dev)
        int ret, chan_idx;
 
        adc->oversamp = DFSDM_DEFAULT_OVERSAMPLING;
-       ret = stm32_dfsdm_set_osrs(&adc->dfsdm->fl_list[adc->fl_id], 0,
-                                  adc->oversamp);
+       ret = stm32_dfsdm_compute_all_osrs(indio_dev, adc->oversamp);
        if (ret < 0)
                return ret;
 
@@ -1456,6 +1601,12 @@ static int stm32_dfsdm_adc_probe(struct platform_device *pdev)
         * So IRQ associated to filter instance 0 is dedicated to the Filter 0.
         */
        irq = platform_get_irq(pdev, 0);
+       if (irq < 0) {
+               if (irq != -EPROBE_DEFER)
+                       dev_err(dev, "Failed to get IRQ: %d\n", irq);
+               return irq;
+       }
+
        ret = devm_request_irq(dev, irq, stm32_dfsdm_irq,
                               0, pdev->name, adc);
        if (ret < 0) {
index 0a4d3746d21c34b0cd3a23b1f4fca8653e7168e9..26e2011c5868906e596d942099eea50f0c9a2ef0 100644 (file)
@@ -233,6 +233,8 @@ static int stm32_dfsdm_parse_of(struct platform_device *pdev,
        }
        priv->dfsdm.phys_base = res->start;
        priv->dfsdm.base = devm_ioremap_resource(&pdev->dev, res);
+       if (IS_ERR(priv->dfsdm.base))
+               return PTR_ERR(priv->dfsdm.base);
 
        /*
         * "dfsdm" clock is mandatory for DFSDM peripheral clocking.
@@ -242,8 +244,10 @@ static int stm32_dfsdm_parse_of(struct platform_device *pdev,
         */
        priv->clk = devm_clk_get(&pdev->dev, "dfsdm");
        if (IS_ERR(priv->clk)) {
-               dev_err(&pdev->dev, "No stm32_dfsdm_clk clock found\n");
-               return -EINVAL;
+               ret = PTR_ERR(priv->clk);
+               if (ret != -EPROBE_DEFER)
+                       dev_err(&pdev->dev, "Failed to get clock (%d)\n", ret);
+               return ret;
        }
 
        priv->aclk = devm_clk_get(&pdev->dev, "audio");
index 8708394b07254b42c190675c4beb45f09e3f5794..5dbdae4ed88183961dfe549f3fd0405209238603 100644 (file)
@@ -243,19 +243,33 @@ enum stm32_dfsdm_sinc_order {
 };
 
 /**
- * struct stm32_dfsdm_filter - structure relative to stm32 FDSDM filter
+ * struct stm32_dfsdm_filter_osr - DFSDM filter settings linked to oversampling
  * @iosr: integrator oversampling
  * @fosr: filter oversampling
- * @ford: filter order
+ * @rshift: output sample right shift (hardware shift)
+ * @lshift: output sample left shift (software shift)
  * @res: output sample resolution
+ * @max: output sample maximum positive value
+ */
+struct stm32_dfsdm_filter_osr {
+       unsigned int iosr;
+       unsigned int fosr;
+       unsigned int rshift;
+       unsigned int lshift;
+       u64 res;
+       s32 max;
+};
+
+/**
+ * struct stm32_dfsdm_filter - structure relative to stm32 FDSDM filter
+ * @ford: filter order
+ * @flo: filter oversampling data table indexed by fast mode flag
  * @sync_mode: filter synchronized with filter 0
  * @fast: filter fast mode
  */
 struct stm32_dfsdm_filter {
-       unsigned int iosr;
-       unsigned int fosr;
        enum stm32_dfsdm_sinc_order ford;
-       u64 res;
+       struct stm32_dfsdm_filter_osr flo[2];
        unsigned int sync_mode;
        unsigned int fast;
 };
index 7921f827c6ec4747511d6fb0955112119429c44d..bd72727fc417a7cc76b9b46ffca172e4f7ad6f30 100644 (file)
@@ -65,6 +65,8 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
 
        mutex_lock(&info->lock);
 
+       reinit_completion(&info->completion);
+
        info->channel = (u8)chan->channel;
 
        if (info->channel > STMPE_ADC_LAST_NR) {
@@ -72,23 +74,16 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
                return -EINVAL;
        }
 
-       stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN,
-                       STMPE_ADC_CH(info->channel));
-
        stmpe_reg_write(info->stmpe, STMPE_REG_ADC_CAPT,
                        STMPE_ADC_CH(info->channel));
 
-       *val = info->value;
-
-       ret = wait_for_completion_interruptible_timeout
-               (&info->completion, STMPE_ADC_TIMEOUT);
+       ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
 
        if (ret <= 0) {
+               stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA,
+                               STMPE_ADC_CH(info->channel));
                mutex_unlock(&info->lock);
-               if (ret == 0)
-                       return -ETIMEDOUT;
-               else
-                       return ret;
+               return -ETIMEDOUT;
        }
 
        *val = info->value;
@@ -105,6 +100,8 @@ static int stmpe_read_temp(struct stmpe_adc *info,
 
        mutex_lock(&info->lock);
 
+       reinit_completion(&info->completion);
+
        info->channel = (u8)chan->channel;
 
        if (info->channel != STMPE_TEMP_CHANNEL) {
@@ -115,15 +112,11 @@ static int stmpe_read_temp(struct stmpe_adc *info,
        stmpe_reg_write(info->stmpe, STMPE_REG_TEMP_CTRL,
                        STMPE_START_ONE_TEMP_CONV);
 
-       ret = wait_for_completion_interruptible_timeout
-               (&info->completion, STMPE_ADC_TIMEOUT);
+       ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
 
        if (ret <= 0) {
                mutex_unlock(&info->lock);
-               if (ret == 0)
-                       return -ETIMEDOUT;
-               else
-                       return ret;
+               return -ETIMEDOUT;
        }
 
        /*
@@ -331,6 +324,12 @@ static int stmpe_adc_probe(struct platform_device *pdev)
        if (ret)
                return ret;
 
+       stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN,
+                       ~(norequest_mask & 0xFF));
+
+       stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA,
+                       ~(norequest_mask & 0xFF));
+
        return devm_iio_device_register(&pdev->dev, indio_dev);
 }
 
@@ -353,9 +352,14 @@ static struct platform_driver stmpe_adc_driver = {
                .pm     = &stmpe_adc_pm_ops,
        },
 };
-
 module_platform_driver(stmpe_adc_driver);
 
+static const struct of_device_id stmpe_adc_ids[] = {
+       { .compatible = "st,stmpe-adc", },
+       { },
+};
+MODULE_DEVICE_TABLE(of, stmpe_adc_ids);
+
 MODULE_AUTHOR("Stefan Agner <stefan.agner@toradex.com>");
 MODULE_DESCRIPTION("STMPEXXX ADC driver");
 MODULE_LICENSE("GPL v2");
index a09e7f5dd8f72d51c2f13f371f9c92e1f066e463..f13c6248a662f9bca7110bb6abc5cf84e9191ad4 100644 (file)
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-License-Identifier: GPL-2.0
 /* ADC driver for sunxi platforms' (A10, A13 and A31) GPADC
  *
  * Copyright (c) 2016 Quentin Schulz <quentin.schulz@free-electrons.com>
index 863d73519c0d71f0296116071184e88a001bd75d..da7f126d197b412605baa0adc281780d5f07e408 100644 (file)
@@ -1,4 +1,4 @@
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-2.0
 #
 # Gain Amplifiers, etc.
 #
@@ -7,12 +7,17 @@
 menu "Amplifiers"
 
 config AD8366
-       tristate "Analog Devices AD8366 VGA"
+       tristate "Analog Devices AD8366 and similar Gain Amplifiers"
        depends on SPI
+       depends on GPIOLIB
        select BITREVERSE
        help
-         Say yes here to build support for Analog Devices AD8366
-         SPI Dual-Digital Variable Gain Amplifier (VGA).
+         Say yes here to build support for Analog Devices AD8366 and similar
+         gain amplifiers. This driver supports the following gain amplifiers
+         from Analog Devices:
+           AD8366 Dual-Digital Variable Gain Amplifier (VGA)
+           ADA4961 BiCMOS RF Digital Gain Amplifier (DGA)
+           ADL5240 Digitally controlled variable gain amplifier (VGA)
 
          To compile this driver as a module, choose M here: the
          module will be called ad8366.
index 3d6246f8642933bcf069ceb55827e8a27f0f3f7a..0176d3d8cc9cc40314f1dd326e3e13adade46d74 100644 (file)
@@ -1,8 +1,12 @@
-// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-License-Identifier: GPL-2.0
 /*
- * AD8366 SPI Dual-Digital Variable Gain Amplifier (VGA)
+ * AD8366 and similar Gain Amplifiers
+ * This driver supports the following gain amplifiers:
+ *   AD8366 Dual-Digital Variable Gain Amplifier (VGA)
+ *   ADA4961 BiCMOS RF Digital Gain Amplifier (DGA)
+ *   ADL5240 Digitally controlled variable gain amplifier (VGA)
  *
- * Copyright 2012 Analog Devices Inc.
+ * Copyright 2012-2019 Analog Devices Inc.
  */
 
 #include <linux/device.h>
@@ -11,6 +15,7 @@
 #include <linux/sysfs.h>
 #include <linux/spi/spi.h>
 #include <linux/regulator/consumer.h>
+#include <linux/gpio/consumer.h>
 #include <linux/err.h>
 #include <linux/module.h>
 #include <linux/bitrev.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
 
+enum ad8366_type {
+       ID_AD8366,
+       ID_ADA4961,
+       ID_ADL5240,
+};
+
+struct ad8366_info {
+       int gain_min;
+       int gain_max;
+};
+
 struct ad8366_state {
        struct spi_device       *spi;
        struct regulator        *reg;
+       struct mutex            lock; /* protect sensor state */
+       struct gpio_desc        *reset_gpio;
        unsigned char           ch[2];
+       enum ad8366_type        type;
+       struct ad8366_info      *info;
        /*
         * DMA (thus cache coherency maintenance) requires the
         * transfer buffers to live in their own cache lines.
@@ -29,19 +49,44 @@ struct ad8366_state {
        unsigned char           data[2] ____cacheline_aligned;
 };
 
+static struct ad8366_info ad8366_infos[] = {
+       [ID_AD8366] = {
+               .gain_min = 4500,
+               .gain_max = 20500,
+       },
+       [ID_ADA4961] = {
+               .gain_min = -6000,
+               .gain_max = 15000,
+       },
+       [ID_ADL5240] = {
+               .gain_min = -11500,
+               .gain_max = 20000,
+       },
+};
+
 static int ad8366_write(struct iio_dev *indio_dev,
                        unsigned char ch_a, unsigned char ch_b)
 {
        struct ad8366_state *st = iio_priv(indio_dev);
        int ret;
 
-       ch_a = bitrev8(ch_a & 0x3F);
-       ch_b = bitrev8(ch_b & 0x3F);
+       switch (st->type) {
+       case ID_AD8366:
+               ch_a = bitrev8(ch_a & 0x3F);
+               ch_b = bitrev8(ch_b & 0x3F);
 
-       st->data[0] = ch_b >> 4;
-       st->data[1] = (ch_b << 4) | (ch_a >> 2);
+               st->data[0] = ch_b >> 4;
+               st->data[1] = (ch_b << 4) | (ch_a >> 2);
+               break;
+       case ID_ADA4961:
+               st->data[0] = ch_a & 0x1F;
+               break;
+       case ID_ADL5240:
+               st->data[0] = (ch_a & 0x3F);
+               break;
+       }
 
-       ret = spi_write(st->spi, st->data, ARRAY_SIZE(st->data));
+       ret = spi_write(st->spi, st->data, indio_dev->num_channels);
        if (ret < 0)
                dev_err(&indio_dev->dev, "write failed (%d)", ret);
 
@@ -56,24 +101,35 @@ static int ad8366_read_raw(struct iio_dev *indio_dev,
 {
        struct ad8366_state *st = iio_priv(indio_dev);
        int ret;
-       unsigned code;
+       int code, gain = 0;
 
-       mutex_lock(&indio_dev->mlock);
+       mutex_lock(&st->lock);
        switch (m) {
        case IIO_CHAN_INFO_HARDWAREGAIN:
                code = st->ch[chan->channel];
 
+               switch (st->type) {
+               case ID_AD8366:
+                       gain = code * 253 + 4500;
+                       break;
+               case ID_ADA4961:
+                       gain = 15000 - code * 1000;
+                       break;
+               case ID_ADL5240:
+                       gain = 20000 - 31500 + code * 500;
+                       break;
+               }
+
                /* Values in dB */
-               code = code * 253 + 4500;
-               *val = code / 1000;
-               *val2 = (code % 1000) * 1000;
+               *val = gain / 1000;
+               *val2 = (gain % 1000) * 1000;
 
                ret = IIO_VAL_INT_PLUS_MICRO_DB;
                break;
        default:
                ret = -EINVAL;
        }
-       mutex_unlock(&indio_dev->mlock);
+       mutex_unlock(&st->lock);
 
        return ret;
 };
@@ -85,21 +141,32 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
                            long mask)
 {
        struct ad8366_state *st = iio_priv(indio_dev);
-       unsigned code;
+       struct ad8366_info *inf = st->info;
+       int code = 0, gain;
        int ret;
 
-       if (val < 0 || val2 < 0)
-               return -EINVAL;
-
        /* Values in dB */
-       code = (((u8)val * 1000) + ((u32)val2 / 1000));
+       if (val < 0)
+               gain = (val * 1000) - (val2 / 1000);
+       else
+               gain = (val * 1000) + (val2 / 1000);
 
-       if (code > 20500 || code < 4500)
+       if (gain > inf->gain_max || gain < inf->gain_min)
                return -EINVAL;
 
-       code = (code - 4500) / 253;
+       switch (st->type) {
+       case ID_AD8366:
+               code = (gain - 4500) / 253;
+               break;
+       case ID_ADA4961:
+               code = (15000 - gain) / 1000;
+               break;
+       case ID_ADL5240:
+               code = ((gain - 500 - 20000) / 500) & 0x3F;
+               break;
+       }
 
-       mutex_lock(&indio_dev->mlock);
+       mutex_lock(&st->lock);
        switch (mask) {
        case IIO_CHAN_INFO_HARDWAREGAIN:
                st->ch[chan->channel] = code;
@@ -108,7 +175,7 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
        default:
                ret = -EINVAL;
        }
-       mutex_unlock(&indio_dev->mlock);
+       mutex_unlock(&st->lock);
 
        return ret;
 }
@@ -131,6 +198,10 @@ static const struct iio_chan_spec ad8366_channels[] = {
        AD8366_CHAN(1),
 };
 
+static const struct iio_chan_spec ada4961_channels[] = {
+       AD8366_CHAN(0),
+};
+
 static int ad8366_probe(struct spi_device *spi)
 {
        struct iio_dev *indio_dev;
@@ -151,14 +222,33 @@ static int ad8366_probe(struct spi_device *spi)
        }
 
        spi_set_drvdata(spi, indio_dev);
+       mutex_init(&st->lock);
        st->spi = spi;
+       st->type = spi_get_device_id(spi)->driver_data;
+
+       switch (st->type) {
+       case ID_AD8366:
+               indio_dev->channels = ad8366_channels;
+               indio_dev->num_channels = ARRAY_SIZE(ad8366_channels);
+               break;
+       case ID_ADA4961:
+       case ID_ADL5240:
+               st->reset_gpio = devm_gpiod_get(&spi->dev, "reset",
+                       GPIOD_OUT_HIGH);
+               indio_dev->channels = ada4961_channels;
+               indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
+               break;
+       default:
+               dev_err(&spi->dev, "Invalid device ID\n");
+               ret = -EINVAL;
+               goto error_disable_reg;
+       }
 
+       st->info = &ad8366_infos[st->type];
        indio_dev->dev.parent = &spi->dev;
        indio_dev->name = spi_get_device_id(spi)->name;
        indio_dev->info = &ad8366_info;
        indio_dev->modes = INDIO_DIRECT_MODE;
-       indio_dev->channels = ad8366_channels;
-       indio_dev->num_channels = ARRAY_SIZE(ad8366_channels);
 
        ret = ad8366_write(indio_dev, 0 , 0);
        if (ret < 0)
@@ -192,7 +282,9 @@ static int ad8366_remove(struct spi_device *spi)
 }
 
 static const struct spi_device_id ad8366_id[] = {
-       {"ad8366", 0},
+       {"ad8366",  ID_AD8366},
+       {"ada4961", ID_ADA4961},
+       {"adl5240", ID_ADL5240},
        {}
 };
 MODULE_DEVICE_TABLE(spi, ad8366_id);
@@ -209,5 +301,5 @@ static struct spi_driver ad8366_driver = {
 module_spi_driver(ad8366_driver);
 
 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
-MODULE_DESCRIPTION("Analog Devices AD8366 VGA");
+MODULE_DESCRIPTION("Analog Devices AD8366 and similar Gain Amplifiers");
 MODULE_LICENSE("GPL v2");
index 719a0df5aeeb1b7d812b49349eaf8e2ebd9ca1dd..130362ca421bb2b188abcaf8d80c79c882944224 100644 (file)
@@ -125,6 +125,15 @@ static ssize_t cros_ec_sensors_calibrate(struct iio_dev *indio_dev,
        return ret ? ret : len;
 }
 
+static ssize_t cros_ec_sensors_id(struct iio_dev *indio_dev,
+                                 uintptr_t private,
+                                 const struct iio_chan_spec *chan, char *buf)
+{
+       struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
+
+       return snprintf(buf, PAGE_SIZE, "%d\n", st->param.info.sensor_num);
+}
+
 static ssize_t cros_ec_sensors_loc(struct iio_dev *indio_dev,
                uintptr_t private, const struct iio_chan_spec *chan,
                char *buf)
@@ -140,6 +149,11 @@ const struct iio_chan_spec_ext_info cros_ec_sensors_ext_info[] = {
                .shared = IIO_SHARED_BY_ALL,
                .write = cros_ec_sensors_calibrate
        },
+       {
+               .name = "id",
+               .shared = IIO_SHARED_BY_ALL,
+               .read = cros_ec_sensors_id
+       },
        {
                .name = "location",
                .shared = IIO_SHARED_BY_ALL,
index a513c70faefa1a895fe183aa2ab482be0492da30..475646c82b40e2dd61e5747f2c687c198b52cbcf 100644 (file)
@@ -11,6 +11,8 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/property.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/spi/spi.h>
 #include <linux/gpio/consumer.h>
 
@@ -582,7 +584,7 @@ static ssize_t ad5758_write_powerdown(struct iio_dev *indio_dev,
 {
        struct ad5758_state *st = iio_priv(indio_dev);
        bool pwr_down;
-       unsigned int dc_dc_mode, dac_config_mode, val;
+       unsigned int dac_config_mode, val;
        unsigned long int dac_config_msk;
        int ret;
 
@@ -591,13 +593,10 @@ static ssize_t ad5758_write_powerdown(struct iio_dev *indio_dev,
                return ret;
 
        mutex_lock(&st->lock);
-       if (pwr_down) {
-               dc_dc_mode = AD5758_DCDC_MODE_POWER_OFF;
+       if (pwr_down)
                val = 0;
-       } else {
-               dc_dc_mode = st->dc_dc_mode;
+       else
                val = 1;
-       }
 
        dac_config_mode = AD5758_DAC_CONFIG_OUT_EN_MODE(val) |
                          AD5758_DAC_CONFIG_INT_EN_MODE(val);
@@ -885,9 +884,16 @@ static const struct spi_device_id ad5758_id[] = {
 };
 MODULE_DEVICE_TABLE(spi, ad5758_id);
 
+static const struct of_device_id ad5758_of_match[] = {
+        { .compatible = "adi,ad5758" },
+        { },
+};
+MODULE_DEVICE_TABLE(of, ad5758_of_match);
+
 static struct spi_driver ad5758_driver = {
        .driver = {
                .name = KBUILD_MODNAME,
+               .of_match_table = ad5758_of_match,
        },
        .probe = ad5758_probe,
        .id_table = ad5758_id,
index 030c51363ad8659e36b9bc079c1d5fb1e18bf73e..26d206681472e63db674b5549a563c1f9377ed67 100644 (file)
@@ -233,12 +233,6 @@ static int ds4424_probe(struct i2c_client *client,
        indio_dev->dev.of_node = client->dev.of_node;
        indio_dev->dev.parent = &client->dev;
 
-       if (!client->dev.of_node) {
-               dev_err(&client->dev,
-                               "Not found DT.\n");
-               return -ENODEV;
-       }
-
        data->vcc_reg = devm_regulator_get(&client->dev, "vcc");
        if (IS_ERR(data->vcc_reg)) {
                dev_err(&client->dev,
index c86db8b42380f57a2bad08790444288e52aeb7fa..240b815025127412f70773eb17795899201fe936 100644 (file)
@@ -39,5 +39,15 @@ config ADF4350
          To compile this driver as a module, choose M here: the
          module will be called adf4350.
 
+config ADF4371
+       tristate "Analog Devices ADF4371/ADF4372 Wideband Synthesizers"
+       depends on SPI
+       select REGMAP_SPI
+       help
+         Say yes here to build support for Analog Devices ADF4371 and ADF4372
+         Wideband Synthesizers. The driver provides direct access via sysfs.
+
+         To compile this driver as a module, choose M here: the
+         module will be called adf4371.
 endmenu
 endmenu
index f2e396d40dddf8bafdca80a6668551d20d8d0894..518b1e50caef11cc9f8a8e912e635f236f566c96 100644 (file)
@@ -6,3 +6,4 @@
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_AD9523) += ad9523.o
 obj-$(CONFIG_ADF4350) += adf4350.o
+obj-$(CONFIG_ADF4371) += adf4371.o
index 9691524ce5b037afa5895813bc65bf2c62d03f70..a7322184cbdd0680cea8352efc40ac8311402c50 100644 (file)
@@ -861,9 +861,11 @@ static int ad9523_setup(struct iio_dev *indio_dev)
        if (ret < 0)
                return ret;
 
-       st->vco_freq = (pdata->vcxo_freq * (pdata->pll2_freq_doubler_en ? 2 : 1)
-                       / pdata->pll2_r2_div) * AD9523_PLL2_FB_NDIV(pdata->
-                       pll2_ndiv_a_cnt, pdata->pll2_ndiv_b_cnt);
+       st->vco_freq = div_u64((unsigned long long)pdata->vcxo_freq *
+                              (pdata->pll2_freq_doubler_en ? 2 : 1) *
+                              AD9523_PLL2_FB_NDIV(pdata->pll2_ndiv_a_cnt,
+                                                  pdata->pll2_ndiv_b_cnt),
+                              pdata->pll2_r2_div);
 
        ret = ad9523_write(indio_dev, AD9523_PLL2_VCO_CTRL,
                AD9523_PLL2_VCO_CALIBRATE);
diff --git a/drivers/iio/frequency/adf4371.c b/drivers/iio/frequency/adf4371.c
new file mode 100644 (file)
index 0000000..e48f15c
--- /dev/null
@@ -0,0 +1,632 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Analog Devices ADF4371 SPI Wideband Synthesizer driver
+ *
+ * Copyright 2019 Analog Devices Inc.
+ */
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/gcd.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/sysfs.h>
+#include <linux/spi/spi.h>
+
+#include <linux/iio/iio.h>
+
+/* Registers address macro */
+#define ADF4371_REG(x)                 (x)
+
+/* ADF4371_REG0 */
+#define ADF4371_ADDR_ASC_MSK           BIT(2)
+#define ADF4371_ADDR_ASC(x)            FIELD_PREP(ADF4371_ADDR_ASC_MSK, x)
+#define ADF4371_ADDR_ASC_R_MSK         BIT(5)
+#define ADF4371_ADDR_ASC_R(x)          FIELD_PREP(ADF4371_ADDR_ASC_R_MSK, x)
+#define ADF4371_RESET_CMD              0x81
+
+/* ADF4371_REG17 */
+#define ADF4371_FRAC2WORD_L_MSK                GENMASK(7, 1)
+#define ADF4371_FRAC2WORD_L(x)         FIELD_PREP(ADF4371_FRAC2WORD_L_MSK, x)
+#define ADF4371_FRAC1WORD_MSK          BIT(0)
+#define ADF4371_FRAC1WORD(x)           FIELD_PREP(ADF4371_FRAC1WORD_MSK, x)
+
+/* ADF4371_REG18 */
+#define ADF4371_FRAC2WORD_H_MSK                GENMASK(6, 0)
+#define ADF4371_FRAC2WORD_H(x)         FIELD_PREP(ADF4371_FRAC2WORD_H_MSK, x)
+
+/* ADF4371_REG1A */
+#define ADF4371_MOD2WORD_MSK           GENMASK(5, 0)
+#define ADF4371_MOD2WORD(x)            FIELD_PREP(ADF4371_MOD2WORD_MSK, x)
+
+/* ADF4371_REG24 */
+#define ADF4371_RF_DIV_SEL_MSK         GENMASK(6, 4)
+#define ADF4371_RF_DIV_SEL(x)          FIELD_PREP(ADF4371_RF_DIV_SEL_MSK, x)
+
+/* ADF4371_REG25 */
+#define ADF4371_MUTE_LD_MSK            BIT(7)
+#define ADF4371_MUTE_LD(x)             FIELD_PREP(ADF4371_MUTE_LD_MSK, x)
+
+/* ADF4371_REG32 */
+#define ADF4371_TIMEOUT_MSK            GENMASK(1, 0)
+#define ADF4371_TIMEOUT(x)             FIELD_PREP(ADF4371_TIMEOUT_MSK, x)
+
+/* ADF4371_REG34 */
+#define ADF4371_VCO_ALC_TOUT_MSK       GENMASK(4, 0)
+#define ADF4371_VCO_ALC_TOUT(x)                FIELD_PREP(ADF4371_VCO_ALC_TOUT_MSK, x)
+
+/* Specifications */
+#define ADF4371_MIN_VCO_FREQ           4000000000ULL /* 4000 MHz */
+#define ADF4371_MAX_VCO_FREQ           8000000000ULL /* 8000 MHz */
+#define ADF4371_MAX_OUT_RF8_FREQ       ADF4371_MAX_VCO_FREQ /* Hz */
+#define ADF4371_MIN_OUT_RF8_FREQ       (ADF4371_MIN_VCO_FREQ / 64) /* Hz */
+#define ADF4371_MAX_OUT_RF16_FREQ      (ADF4371_MAX_VCO_FREQ * 2) /* Hz */
+#define ADF4371_MIN_OUT_RF16_FREQ      (ADF4371_MIN_VCO_FREQ * 2) /* Hz */
+#define ADF4371_MAX_OUT_RF32_FREQ      (ADF4371_MAX_VCO_FREQ * 4) /* Hz */
+#define ADF4371_MIN_OUT_RF32_FREQ      (ADF4371_MIN_VCO_FREQ * 4) /* Hz */
+
+#define ADF4371_MAX_FREQ_PFD           250000000UL /* Hz */
+#define ADF4371_MAX_FREQ_REFIN         600000000UL /* Hz */
+
+/* MOD1 is a 24-bit primary modulus with fixed value of 2^25 */
+#define ADF4371_MODULUS1               33554432ULL
+/* MOD2 is the programmable, 14-bit auxiliary fractional modulus */
+#define ADF4371_MAX_MODULUS2           BIT(14)
+
+#define ADF4371_CHECK_RANGE(freq, range) \
+       ((freq > ADF4371_MAX_ ## range) || (freq < ADF4371_MIN_ ## range))
+
+enum {
+       ADF4371_FREQ,
+       ADF4371_POWER_DOWN,
+       ADF4371_CHANNEL_NAME
+};
+
+enum {
+       ADF4371_CH_RF8,
+       ADF4371_CH_RFAUX8,
+       ADF4371_CH_RF16,
+       ADF4371_CH_RF32
+};
+
+enum adf4371_variant {
+       ADF4371,
+       ADF4372
+};
+
+struct adf4371_pwrdown {
+       unsigned int reg;
+       unsigned int bit;
+};
+
+static const char * const adf4371_ch_names[] = {
+       "RF8x", "RFAUX8x", "RF16x", "RF32x"
+};
+
+static const struct adf4371_pwrdown adf4371_pwrdown_ch[4] = {
+       [ADF4371_CH_RF8] = { ADF4371_REG(0x25), 2 },
+       [ADF4371_CH_RFAUX8] = { ADF4371_REG(0x72), 3 },
+       [ADF4371_CH_RF16] = { ADF4371_REG(0x25), 3 },
+       [ADF4371_CH_RF32] = { ADF4371_REG(0x25), 4 },
+};
+
+static const struct reg_sequence adf4371_reg_defaults[] = {
+       { ADF4371_REG(0x0),  0x18 },
+       { ADF4371_REG(0x12), 0x40 },
+       { ADF4371_REG(0x1E), 0x48 },
+       { ADF4371_REG(0x20), 0x14 },
+       { ADF4371_REG(0x22), 0x00 },
+       { ADF4371_REG(0x23), 0x00 },
+       { ADF4371_REG(0x24), 0x80 },
+       { ADF4371_REG(0x25), 0x07 },
+       { ADF4371_REG(0x27), 0xC5 },
+       { ADF4371_REG(0x28), 0x83 },
+       { ADF4371_REG(0x2C), 0x44 },
+       { ADF4371_REG(0x2D), 0x11 },
+       { ADF4371_REG(0x2E), 0x12 },
+       { ADF4371_REG(0x2F), 0x94 },
+       { ADF4371_REG(0x32), 0x04 },
+       { ADF4371_REG(0x35), 0xFA },
+       { ADF4371_REG(0x36), 0x30 },
+       { ADF4371_REG(0x39), 0x07 },
+       { ADF4371_REG(0x3A), 0x55 },
+       { ADF4371_REG(0x3E), 0x0C },
+       { ADF4371_REG(0x3F), 0x80 },
+       { ADF4371_REG(0x40), 0x50 },
+       { ADF4371_REG(0x41), 0x28 },
+       { ADF4371_REG(0x47), 0xC0 },
+       { ADF4371_REG(0x52), 0xF4 },
+       { ADF4371_REG(0x70), 0x03 },
+       { ADF4371_REG(0x71), 0x60 },
+       { ADF4371_REG(0x72), 0x32 },
+};
+
+static const struct regmap_config adf4371_regmap_config = {
+       .reg_bits = 16,
+       .val_bits = 8,
+       .read_flag_mask = BIT(7),
+};
+
+struct adf4371_chip_info {
+       unsigned int num_channels;
+       const struct iio_chan_spec *channels;
+};
+
+struct adf4371_state {
+       struct spi_device *spi;
+       struct regmap *regmap;
+       struct clk *clkin;
+       /*
+        * Lock for accessing device registers. Some operations require
+        * multiple consecutive R/W operations, during which the device
+        * shouldn't be interrupted. The buffers are also shared across
+        * all operations so need to be protected on stand alone reads and
+        * writes.
+        */
+       struct mutex lock;
+       const struct adf4371_chip_info *chip_info;
+       unsigned long clkin_freq;
+       unsigned long fpfd;
+       unsigned int integer;
+       unsigned int fract1;
+       unsigned int fract2;
+       unsigned int mod2;
+       unsigned int rf_div_sel;
+       unsigned int ref_div_factor;
+       u8 buf[10] ____cacheline_aligned;
+};
+
+static unsigned long long adf4371_pll_fract_n_get_rate(struct adf4371_state *st,
+                                                      u32 channel)
+{
+       unsigned long long val, tmp;
+       unsigned int ref_div_sel;
+
+       val = (((u64)st->integer * ADF4371_MODULUS1) + st->fract1) * st->fpfd;
+       tmp = (u64)st->fract2 * st->fpfd;
+       do_div(tmp, st->mod2);
+       val += tmp + ADF4371_MODULUS1 / 2;
+
+       if (channel == ADF4371_CH_RF8 || channel == ADF4371_CH_RFAUX8)
+               ref_div_sel = st->rf_div_sel;
+       else
+               ref_div_sel = 0;
+
+       do_div(val, ADF4371_MODULUS1 * (1 << ref_div_sel));
+
+       if (channel == ADF4371_CH_RF16)
+               val <<= 1;
+       else if (channel == ADF4371_CH_RF32)
+               val <<= 2;
+
+       return val;
+}
+
+static void adf4371_pll_fract_n_compute(unsigned long long vco,
+                                      unsigned long long pfd,
+                                      unsigned int *integer,
+                                      unsigned int *fract1,
+                                      unsigned int *fract2,
+                                      unsigned int *mod2)
+{
+       unsigned long long tmp;
+       u32 gcd_div;
+
+       tmp = do_div(vco, pfd);
+       tmp = tmp * ADF4371_MODULUS1;
+       *fract2 = do_div(tmp, pfd);
+
+       *integer = vco;
+       *fract1 = tmp;
+
+       *mod2 = pfd;
+
+       while (*mod2 > ADF4371_MAX_MODULUS2) {
+               *mod2 >>= 1;
+               *fract2 >>= 1;
+       }
+
+       gcd_div = gcd(*fract2, *mod2);
+       *mod2 /= gcd_div;
+       *fract2 /= gcd_div;
+}
+
+static int adf4371_set_freq(struct adf4371_state *st, unsigned long long freq,
+                           unsigned int channel)
+{
+       u32 cp_bleed;
+       u8 int_mode = 0;
+       int ret;
+
+       switch (channel) {
+       case ADF4371_CH_RF8:
+       case ADF4371_CH_RFAUX8:
+               if (ADF4371_CHECK_RANGE(freq, OUT_RF8_FREQ))
+                       return -EINVAL;
+
+               st->rf_div_sel = 0;
+
+               while (freq < ADF4371_MIN_VCO_FREQ) {
+                       freq <<= 1;
+                       st->rf_div_sel++;
+               }
+               break;
+       case ADF4371_CH_RF16:
+               /* ADF4371 RF16 8000...16000 MHz */
+               if (ADF4371_CHECK_RANGE(freq, OUT_RF16_FREQ))
+                       return -EINVAL;
+
+               freq >>= 1;
+               break;
+       case ADF4371_CH_RF32:
+               /* ADF4371 RF32 16000...32000 MHz */
+               if (ADF4371_CHECK_RANGE(freq, OUT_RF32_FREQ))
+                       return -EINVAL;
+
+               freq >>= 2;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       adf4371_pll_fract_n_compute(freq, st->fpfd, &st->integer, &st->fract1,
+                                   &st->fract2, &st->mod2);
+       st->buf[0] = st->integer >> 8;
+       st->buf[1] = 0x40; /* REG12 default */
+       st->buf[2] = 0x00;
+       st->buf[3] = st->fract2 & 0xFF;
+       st->buf[4] = st->fract2 >> 7;
+       st->buf[5] = st->fract2 >> 15;
+       st->buf[6] = ADF4371_FRAC2WORD_L(st->fract2 & 0x7F) |
+                    ADF4371_FRAC1WORD(st->fract1 >> 23);
+       st->buf[7] = ADF4371_FRAC2WORD_H(st->fract2 >> 7);
+       st->buf[8] = st->mod2 & 0xFF;
+       st->buf[9] = ADF4371_MOD2WORD(st->mod2 >> 8);
+
+       ret = regmap_bulk_write(st->regmap, ADF4371_REG(0x11), st->buf, 10);
+       if (ret < 0)
+               return ret;
+       /*
+        * The R counter allows the input reference frequency to be
+        * divided down to produce the reference clock to the PFD
+        */
+       ret = regmap_write(st->regmap, ADF4371_REG(0x1F), st->ref_div_factor);
+       if (ret < 0)
+               return ret;
+
+       ret = regmap_update_bits(st->regmap, ADF4371_REG(0x24),
+                                ADF4371_RF_DIV_SEL_MSK,
+                                ADF4371_RF_DIV_SEL(st->rf_div_sel));
+       if (ret < 0)
+               return ret;
+
+       cp_bleed = DIV_ROUND_UP(400 * 1750, st->integer * 375);
+       cp_bleed = clamp(cp_bleed, 1U, 255U);
+       ret = regmap_write(st->regmap, ADF4371_REG(0x26), cp_bleed);
+       if (ret < 0)
+               return ret;
+       /*
+        * Set to 1 when in INT mode (when FRAC1 = FRAC2 = 0),
+        * and set to 0 when in FRAC mode.
+        */
+       if (st->fract1 == 0 && st->fract2 == 0)
+               int_mode = 0x01;
+
+       ret = regmap_write(st->regmap, ADF4371_REG(0x2B), int_mode);
+       if (ret < 0)
+               return ret;
+
+       return regmap_write(st->regmap, ADF4371_REG(0x10), st->integer & 0xFF);
+}
+
+static ssize_t adf4371_read(struct iio_dev *indio_dev,
+                           uintptr_t private,
+                           const struct iio_chan_spec *chan,
+                           char *buf)
+{
+       struct adf4371_state *st = iio_priv(indio_dev);
+       unsigned long long val = 0;
+       unsigned int readval, reg, bit;
+       int ret;
+
+       switch ((u32)private) {
+       case ADF4371_FREQ:
+               val = adf4371_pll_fract_n_get_rate(st, chan->channel);
+               ret = regmap_read(st->regmap, ADF4371_REG(0x7C), &readval);
+               if (ret < 0)
+                       break;
+
+               if (readval == 0x00) {
+                       dev_dbg(&st->spi->dev, "PLL un-locked\n");
+                       ret = -EBUSY;
+               }
+               break;
+       case ADF4371_POWER_DOWN:
+               reg = adf4371_pwrdown_ch[chan->channel].reg;
+               bit = adf4371_pwrdown_ch[chan->channel].bit;
+
+               ret = regmap_read(st->regmap, reg, &readval);
+               if (ret < 0)
+                       break;
+
+               val = !(readval & BIT(bit));
+               break;
+       case ADF4371_CHANNEL_NAME:
+               return sprintf(buf, "%s\n", adf4371_ch_names[chan->channel]);
+       default:
+               ret = -EINVAL;
+               val = 0;
+               break;
+       }
+
+       return ret < 0 ? ret : sprintf(buf, "%llu\n", val);
+}
+
+static ssize_t adf4371_write(struct iio_dev *indio_dev,
+                            uintptr_t private,
+                            const struct iio_chan_spec *chan,
+                            const char *buf, size_t len)
+{
+       struct adf4371_state *st = iio_priv(indio_dev);
+       unsigned long long freq;
+       bool power_down;
+       unsigned int bit, readval, reg;
+       int ret;
+
+       mutex_lock(&st->lock);
+       switch ((u32)private) {
+       case ADF4371_FREQ:
+               ret = kstrtoull(buf, 10, &freq);
+               if (ret)
+                       break;
+
+               ret = adf4371_set_freq(st, freq, chan->channel);
+               break;
+       case ADF4371_POWER_DOWN:
+               ret = kstrtobool(buf, &power_down);
+               if (ret)
+                       break;
+
+               reg = adf4371_pwrdown_ch[chan->channel].reg;
+               bit = adf4371_pwrdown_ch[chan->channel].bit;
+               ret = regmap_read(st->regmap, reg, &readval);
+               if (ret < 0)
+                       break;
+
+               readval &= ~BIT(bit);
+               readval |= (!power_down << bit);
+
+               ret = regmap_write(st->regmap, reg, readval);
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
+       mutex_unlock(&st->lock);
+
+       return ret ? ret : len;
+}
+
+#define _ADF4371_EXT_INFO(_name, _ident) { \
+               .name = _name, \
+               .read = adf4371_read, \
+               .write = adf4371_write, \
+               .private = _ident, \
+               .shared = IIO_SEPARATE, \
+}
+
+static const struct iio_chan_spec_ext_info adf4371_ext_info[] = {
+       /*
+        * Ideally we use IIO_CHAN_INFO_FREQUENCY, but there are
+        * values > 2^32 in order to support the entire frequency range
+        * in Hz. Using scale is a bit ugly.
+        */
+       _ADF4371_EXT_INFO("frequency", ADF4371_FREQ),
+       _ADF4371_EXT_INFO("powerdown", ADF4371_POWER_DOWN),
+       _ADF4371_EXT_INFO("name", ADF4371_CHANNEL_NAME),
+       { },
+};
+
+#define ADF4371_CHANNEL(index) { \
+               .type = IIO_ALTVOLTAGE, \
+               .output = 1, \
+               .channel = index, \
+               .ext_info = adf4371_ext_info, \
+               .indexed = 1, \
+       }
+
+static const struct iio_chan_spec adf4371_chan[] = {
+       ADF4371_CHANNEL(ADF4371_CH_RF8),
+       ADF4371_CHANNEL(ADF4371_CH_RFAUX8),
+       ADF4371_CHANNEL(ADF4371_CH_RF16),
+       ADF4371_CHANNEL(ADF4371_CH_RF32),
+};
+
+static const struct adf4371_chip_info adf4371_chip_info[] = {
+       [ADF4371] = {
+               .channels = adf4371_chan,
+               .num_channels = 4,
+       },
+       [ADF4372] = {
+               .channels = adf4371_chan,
+               .num_channels = 3,
+       }
+};
+
+static int adf4371_reg_access(struct iio_dev *indio_dev,
+                             unsigned int reg,
+                             unsigned int writeval,
+                             unsigned int *readval)
+{
+       struct adf4371_state *st = iio_priv(indio_dev);
+
+       if (readval)
+               return regmap_read(st->regmap, reg, readval);
+       else
+               return regmap_write(st->regmap, reg, writeval);
+}
+
+static const struct iio_info adf4371_info = {
+       .debugfs_reg_access = &adf4371_reg_access,
+};
+
+static int adf4371_setup(struct adf4371_state *st)
+{
+       unsigned int synth_timeout = 2, timeout = 1, vco_alc_timeout = 1;
+       unsigned int vco_band_div, tmp;
+       int ret;
+
+       /* Perform a software reset */
+       ret = regmap_write(st->regmap, ADF4371_REG(0x0), ADF4371_RESET_CMD);
+       if (ret < 0)
+               return ret;
+
+       ret = regmap_multi_reg_write(st->regmap, adf4371_reg_defaults,
+                                    ARRAY_SIZE(adf4371_reg_defaults));
+       if (ret < 0)
+               return ret;
+
+       /* Mute to Lock Detect */
+       if (device_property_read_bool(&st->spi->dev, "adi,mute-till-lock-en")) {
+               ret = regmap_update_bits(st->regmap, ADF4371_REG(0x25),
+                                        ADF4371_MUTE_LD_MSK,
+                                        ADF4371_MUTE_LD(1));
+               if (ret < 0)
+                       return ret;
+       }
+
+       /* Set address in ascending order, so the bulk_write() will work */
+       ret = regmap_update_bits(st->regmap, ADF4371_REG(0x0),
+                                ADF4371_ADDR_ASC_MSK | ADF4371_ADDR_ASC_R_MSK,
+                                ADF4371_ADDR_ASC(1) | ADF4371_ADDR_ASC_R(1));
+       if (ret < 0)
+               return ret;
+       /*
+        * Calculate and maximize PFD frequency
+        * fPFD = REFIN Ã— ((1 + D)/(R Ã— (1 + T)))
+        * Where D is the REFIN doubler bit, T is the reference divide by 2,
+        * R is the reference division factor
+        * TODO: it is assumed D and T equal 0.
+        */
+       do {
+               st->ref_div_factor++;
+               st->fpfd = st->clkin_freq / st->ref_div_factor;
+       } while (st->fpfd > ADF4371_MAX_FREQ_PFD);
+
+       /* Calculate Timeouts */
+       vco_band_div = DIV_ROUND_UP(st->fpfd, 2400000U);
+
+       tmp = DIV_ROUND_CLOSEST(st->fpfd, 1000000U);
+       do {
+               timeout++;
+               if (timeout > 1023) {
+                       timeout = 2;
+                       synth_timeout++;
+               }
+       } while (synth_timeout * 1024 + timeout <= 20 * tmp);
+
+       do {
+               vco_alc_timeout++;
+       } while (vco_alc_timeout * 1024 - timeout <= 50 * tmp);
+
+       st->buf[0] = vco_band_div;
+       st->buf[1] = timeout & 0xFF;
+       st->buf[2] = ADF4371_TIMEOUT(timeout >> 8) | 0x04;
+       st->buf[3] = synth_timeout;
+       st->buf[4] = ADF4371_VCO_ALC_TOUT(vco_alc_timeout);
+
+       return regmap_bulk_write(st->regmap, ADF4371_REG(0x30), st->buf, 5);
+}
+
+static void adf4371_clk_disable(void *data)
+{
+       struct adf4371_state *st = data;
+
+       clk_disable_unprepare(st->clkin);
+}
+
+static int adf4371_probe(struct spi_device *spi)
+{
+       const struct spi_device_id *id = spi_get_device_id(spi);
+       struct iio_dev *indio_dev;
+       struct adf4371_state *st;
+       struct regmap *regmap;
+       int ret;
+
+       indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
+       if (!indio_dev)
+               return -ENOMEM;
+
+       regmap = devm_regmap_init_spi(spi, &adf4371_regmap_config);
+       if (IS_ERR(regmap)) {
+               dev_err(&spi->dev, "Error initializing spi regmap: %ld\n",
+                       PTR_ERR(regmap));
+               return PTR_ERR(regmap);
+       }
+
+       st = iio_priv(indio_dev);
+       spi_set_drvdata(spi, indio_dev);
+       st->spi = spi;
+       st->regmap = regmap;
+       mutex_init(&st->lock);
+
+       st->chip_info = &adf4371_chip_info[id->driver_data];
+       indio_dev->dev.parent = &spi->dev;
+       indio_dev->name = id->name;
+       indio_dev->info = &adf4371_info;
+       indio_dev->modes = INDIO_DIRECT_MODE;
+       indio_dev->channels = st->chip_info->channels;
+       indio_dev->num_channels = st->chip_info->num_channels;
+
+       st->clkin = devm_clk_get(&spi->dev, "clkin");
+       if (IS_ERR(st->clkin))
+               return PTR_ERR(st->clkin);
+
+       ret = clk_prepare_enable(st->clkin);
+       if (ret < 0)
+               return ret;
+
+       ret = devm_add_action_or_reset(&spi->dev, adf4371_clk_disable, st);
+       if (ret)
+               return ret;
+
+       st->clkin_freq = clk_get_rate(st->clkin);
+
+       ret = adf4371_setup(st);
+       if (ret < 0) {
+               dev_err(&spi->dev, "ADF4371 setup failed\n");
+               return ret;
+       }
+
+       return devm_iio_device_register(&spi->dev, indio_dev);
+}
+
+static const struct spi_device_id adf4371_id_table[] = {
+       { "adf4371", ADF4371 },
+       { "adf4372", ADF4372 },
+       {}
+};
+MODULE_DEVICE_TABLE(spi, adf4371_id_table);
+
+static const struct of_device_id adf4371_of_match[] = {
+       { .compatible = "adi,adf4371" },
+       { .compatible = "adi,adf4372" },
+       { },
+};
+MODULE_DEVICE_TABLE(of, adf4371_of_match);
+
+static struct spi_driver adf4371_driver = {
+       .driver = {
+               .name = "adf4371",
+               .of_match_table = adf4371_of_match,
+       },
+       .probe = adf4371_probe,
+       .id_table = adf4371_id_table,
+};
+module_spi_driver(adf4371_driver);
+
+MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
+MODULE_DESCRIPTION("Analog Devices ADF4371 SPI PLL");
+MODULE_LICENSE("GPL");
index 4e22b3c3e488e65a3f3d34188d48019e77c5045d..b459600e1a337e70c5ad88e7c07fc7457d5f1ac6 100644 (file)
@@ -22,8 +22,7 @@
 #include <linux/completion.h>
 #include <linux/mutex.h>
 #include <linux/delay.h>
-#include <linux/gpio.h>
-#include <linux/of_gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/timekeeping.h>
 
 #include <linux/iio/iio.h>
@@ -72,7 +71,7 @@
 struct dht11 {
        struct device                   *dev;
 
-       int                             gpio;
+       struct gpio_desc                *gpiod;
        int                             irq;
 
        struct completion               completion;
@@ -179,7 +178,7 @@ static irqreturn_t dht11_handle_irq(int irq, void *data)
        if (dht11->num_edges < DHT11_EDGES_PER_READ && dht11->num_edges >= 0) {
                dht11->edges[dht11->num_edges].ts = ktime_get_boottime_ns();
                dht11->edges[dht11->num_edges++].value =
-                                               gpio_get_value(dht11->gpio);
+                                               gpiod_get_value(dht11->gpiod);
 
                if (dht11->num_edges >= DHT11_EDGES_PER_READ)
                        complete(&dht11->completion);
@@ -217,12 +216,12 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
                reinit_completion(&dht11->completion);
 
                dht11->num_edges = 0;
-               ret = gpio_direction_output(dht11->gpio, 0);
+               ret = gpiod_direction_output(dht11->gpiod, 0);
                if (ret)
                        goto err;
                usleep_range(DHT11_START_TRANSMISSION_MIN,
                             DHT11_START_TRANSMISSION_MAX);
-               ret = gpio_direction_input(dht11->gpio);
+               ret = gpiod_direction_input(dht11->gpiod);
                if (ret)
                        goto err;
 
@@ -294,10 +293,8 @@ MODULE_DEVICE_TABLE(of, dht11_dt_ids);
 static int dht11_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
-       struct device_node *node = dev->of_node;
        struct dht11 *dht11;
        struct iio_dev *iio;
-       int ret;
 
        iio = devm_iio_device_alloc(dev, sizeof(*dht11));
        if (!iio) {
@@ -307,18 +304,13 @@ static int dht11_probe(struct platform_device *pdev)
 
        dht11 = iio_priv(iio);
        dht11->dev = dev;
+       dht11->gpiod = devm_gpiod_get(dev, NULL, GPIOD_IN);
+       if (IS_ERR(dht11->gpiod))
+               return PTR_ERR(dht11->gpiod);
 
-       ret = of_get_gpio(node, 0);
-       if (ret < 0)
-               return ret;
-       dht11->gpio = ret;
-       ret = devm_gpio_request_one(dev, dht11->gpio, GPIOF_IN, pdev->name);
-       if (ret)
-               return ret;
-
-       dht11->irq = gpio_to_irq(dht11->gpio);
+       dht11->irq = gpiod_to_irq(dht11->gpiod);
        if (dht11->irq < 0) {
-               dev_err(dev, "GPIO %d has no interrupt\n", dht11->gpio);
+               dev_err(dev, "GPIO %d has no interrupt\n", desc_to_gpio(dht11->gpiod));
                return -EINVAL;
        }
 
index 5e461f0e759c8ca0b78f87d60e533c7b706d3860..c14bf533b66b39b06c422d0cd4431733c89ba7c9 100644 (file)
@@ -197,7 +197,7 @@ struct st_lsm6dsx_ext_dev_settings {
  * struct st_lsm6dsx_settings - ST IMU sensor settings
  * @wai: Sensor WhoAmI default value.
  * @max_fifo_size: Sensor max fifo length in FIFO words.
- * @id: List of hw id supported by the driver configuration.
+ * @id: List of hw id/device name supported by the driver configuration.
  * @decimator: List of decimator register info (addr + mask).
  * @batch: List of FIFO batching register info (addr + mask).
  * @fifo_ops: Sensor hw FIFO parameters.
@@ -207,7 +207,10 @@ struct st_lsm6dsx_ext_dev_settings {
 struct st_lsm6dsx_settings {
        u8 wai;
        u16 max_fifo_size;
-       enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID];
+       struct {
+               enum st_lsm6dsx_hw_id hw_id;
+               const char *name;
+       } id[ST_LSM6DSX_MAX_ID];
        struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
        struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID];
        struct st_lsm6dsx_fifo_ops fifo_ops;
@@ -303,7 +306,7 @@ struct st_lsm6dsx_hw {
 static const unsigned long st_lsm6dsx_available_scan_masks[] = {0x7, 0x0};
 extern const struct dev_pm_ops st_lsm6dsx_pm_ops;
 
-int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name,
+int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
                     struct regmap *regmap);
 int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
                                 bool enable);
index fd95d924a9965926bb1d2b58abde809bc4ebe957..a6702a74570e206784c250758ccec14563436af3 100644 (file)
@@ -124,7 +124,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
                .wai = 0x69,
                .max_fifo_size = 1365,
                .id = {
-                       [0] = ST_LSM6DS3_ID,
+                       {
+                               .hw_id = ST_LSM6DS3_ID,
+                               .name = ST_LSM6DS3_DEV_NAME,
+                       },
                },
                .decimator = {
                        [ST_LSM6DSX_ID_ACC] = {
@@ -171,7 +174,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
                .wai = 0x69,
                .max_fifo_size = 682,
                .id = {
-                       [0] = ST_LSM6DS3H_ID,
+                       {
+                               .hw_id = ST_LSM6DS3H_ID,
+                               .name = ST_LSM6DS3H_DEV_NAME,
+                       },
                },
                .decimator = {
                        [ST_LSM6DSX_ID_ACC] = {
@@ -218,9 +224,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
                .wai = 0x6a,
                .max_fifo_size = 682,
                .id = {
-                       [0] = ST_LSM6DSL_ID,
-                       [1] = ST_LSM6DSM_ID,
-                       [2] = ST_ISM330DLC_ID,
+                       {
+                               .hw_id = ST_LSM6DSL_ID,
+                               .name = ST_LSM6DSL_DEV_NAME,
+                       }, {
+                               .hw_id = ST_LSM6DSM_ID,
+                               .name = ST_LSM6DSM_DEV_NAME,
+                       }, {
+                               .hw_id = ST_ISM330DLC_ID,
+                               .name = ST_ISM330DLC_DEV_NAME,
+                       },
                },
                .decimator = {
                        [ST_LSM6DSX_ID_ACC] = {
@@ -267,8 +280,13 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
                .wai = 0x6c,
                .max_fifo_size = 512,
                .id = {
-                       [0] = ST_LSM6DSO_ID,
-                       [1] = ST_LSM6DSOX_ID,
+                       {
+                               .hw_id = ST_LSM6DSO_ID,
+                               .name = ST_LSM6DSO_DEV_NAME,
+                       }, {
+                               .hw_id = ST_LSM6DSOX_ID,
+                               .name = ST_LSM6DSOX_DEV_NAME,
+                       },
                },
                .batch = {
                        [ST_LSM6DSX_ID_ACC] = {
@@ -333,7 +351,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
                .wai = 0x6b,
                .max_fifo_size = 512,
                .id = {
-                       [0] = ST_ASM330LHH_ID,
+                       {
+                               .hw_id = ST_ASM330LHH_ID,
+                               .name = ST_ASM330LHH_DEV_NAME,
+                       },
                },
                .batch = {
                        [ST_LSM6DSX_ID_ACC] = {
@@ -372,7 +393,10 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
                .wai = 0x6b,
                .max_fifo_size = 512,
                .id = {
-                       [0] = ST_LSM6DSR_ID,
+                       {
+                               .hw_id = ST_LSM6DSR_ID,
+                               .name = ST_LSM6DSR_DEV_NAME,
+                       },
                },
                .batch = {
                        [ST_LSM6DSX_ID_ACC] = {
@@ -470,13 +494,14 @@ int st_lsm6dsx_set_page(struct st_lsm6dsx_hw *hw, bool enable)
        return err;
 }
 
-static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id)
+static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id,
+                                  const char **name)
 {
        int err, i, j, data;
 
        for (i = 0; i < ARRAY_SIZE(st_lsm6dsx_sensor_settings); i++) {
                for (j = 0; j < ST_LSM6DSX_MAX_ID; j++) {
-                       if (id == st_lsm6dsx_sensor_settings[i].id[j])
+                       if (id == st_lsm6dsx_sensor_settings[i].id[j].hw_id)
                                break;
                }
                if (j < ST_LSM6DSX_MAX_ID)
@@ -499,6 +524,7 @@ static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id)
                return -ENODEV;
        }
 
+       *name = st_lsm6dsx_sensor_settings[i].id[j].name;
        hw->settings = &st_lsm6dsx_sensor_settings[i];
 
        return 0;
@@ -1040,11 +1066,12 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
        return iio_dev;
 }
 
-int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name,
+int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
                     struct regmap *regmap)
 {
        const struct st_lsm6dsx_shub_settings *hub_settings;
        struct st_lsm6dsx_hw *hw;
+       const char *name = NULL;
        int i, err;
 
        hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL);
@@ -1065,7 +1092,7 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name,
        hw->irq = irq;
        hw->regmap = regmap;
 
-       err = st_lsm6dsx_check_whoami(hw, hw_id);
+       err = st_lsm6dsx_check_whoami(hw, hw_id, &name);
        if (err < 0)
                return err;
 
index 966d52a4bf1de8f1eef31e828293a1f8cd55f258..b3211e0ac07bf2ecc272d3d944070386d6c36796 100644 (file)
@@ -35,8 +35,7 @@ static int st_lsm6dsx_i2c_probe(struct i2c_client *client,
                return PTR_ERR(regmap);
        }
 
-       return st_lsm6dsx_probe(&client->dev, client->irq,
-                               hw_id, id->name, regmap);
+       return st_lsm6dsx_probe(&client->dev, client->irq, hw_id, regmap);
 }
 
 static const struct of_device_id st_lsm6dsx_i2c_of_match[] = {
index 24e4e50414e6aa4e3661c951375e2547aa9cbf85..c9d3c4711018f1c7cc4790783d18da3933565517 100644 (file)
@@ -35,8 +35,7 @@ static int st_lsm6dsx_spi_probe(struct spi_device *spi)
                return PTR_ERR(regmap);
        }
 
-       return st_lsm6dsx_probe(&spi->dev, spi->irq,
-                               hw_id, id->name, regmap);
+       return st_lsm6dsx_probe(&spi->dev, spi->irq, hw_id, regmap);
 }
 
 static const struct of_device_id st_lsm6dsx_spi_of_match[] = {
index 401d7ff99853543827ac6b2dce7e763a96c0375b..524a686077ca6d3f3b0765e8cf0c0b96d0bcf6af 100644 (file)
@@ -366,39 +366,25 @@ static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
        debugfs_remove_recursive(indio_dev->debugfs_dentry);
 }
 
-static int iio_device_register_debugfs(struct iio_dev *indio_dev)
+static void iio_device_register_debugfs(struct iio_dev *indio_dev)
 {
-       struct dentry *d;
-
        if (indio_dev->info->debugfs_reg_access == NULL)
-               return 0;
+               return;
 
        if (!iio_debugfs_dentry)
-               return 0;
+               return;
 
        indio_dev->debugfs_dentry =
                debugfs_create_dir(dev_name(&indio_dev->dev),
                                   iio_debugfs_dentry);
-       if (indio_dev->debugfs_dentry == NULL) {
-               dev_warn(indio_dev->dev.parent,
-                        "Failed to create debugfs directory\n");
-               return -EFAULT;
-       }
-
-       d = debugfs_create_file("direct_reg_access", 0644,
-                               indio_dev->debugfs_dentry,
-                               indio_dev, &iio_debugfs_reg_fops);
-       if (!d) {
-               iio_device_unregister_debugfs(indio_dev);
-               return -ENOMEM;
-       }
 
-       return 0;
+       debugfs_create_file("direct_reg_access", 0644,
+                           indio_dev->debugfs_dentry, indio_dev,
+                           &iio_debugfs_reg_fops);
 }
 #else
-static int iio_device_register_debugfs(struct iio_dev *indio_dev)
+static void iio_device_register_debugfs(struct iio_dev *indio_dev)
 {
-       return 0;
 }
 
 static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
@@ -1104,6 +1090,8 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev,
        char *avail_postfix;
 
        for_each_set_bit(i, infomask, sizeof(*infomask) * 8) {
+               if (i >= ARRAY_SIZE(iio_chan_info_postfix))
+                       return -EINVAL;
                avail_postfix = kasprintf(GFP_KERNEL,
                                          "%s_available",
                                          iio_chan_info_postfix[i]);
@@ -1669,12 +1657,7 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
        /* configure elements for the chrdev */
        indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);
 
-       ret = iio_device_register_debugfs(indio_dev);
-       if (ret) {
-               dev_err(indio_dev->dev.parent,
-                       "Failed to register debugfs interfaces\n");
-               return ret;
-       }
+       iio_device_register_debugfs(indio_dev);
 
        ret = iio_buffer_alloc_sysfs_and_mask(indio_dev);
        if (ret) {
index 340d64d0ac59c8b3e70c3d54802714a4bbb321fe..a8361006dcd9bd3a4f1c4f25ae82e6d5716d8c9b 100644 (file)
@@ -146,7 +146,7 @@ static int bh1780_probe(struct i2c_client *client,
 {
        int ret;
        struct bh1780_data *bh1780;
-       struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
+       struct i2c_adapter *adapter = client->adapter;
        struct iio_dev *indio_dev;
 
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
index eff7ac9ae66952fff6ed0e3aed58e1b17c8dddf4..b955183edfe81f2b9470f8c26a9042eb8f3242b4 100644 (file)
@@ -37,6 +37,7 @@
 
 #define STK3310_CHIP_ID_VAL                    0x13
 #define STK3311_CHIP_ID_VAL                    0x1D
+#define STK3335_CHIP_ID_VAL                    0x51
 #define STK3310_PSINT_EN                       0x01
 #define STK3310_PS_MAX_VAL                     0xFFFF
 
@@ -451,7 +452,8 @@ static int stk3310_init(struct iio_dev *indio_dev)
                return ret;
 
        if (chipid != STK3310_CHIP_ID_VAL &&
-           chipid != STK3311_CHIP_ID_VAL) {
+           chipid != STK3311_CHIP_ID_VAL &&
+           chipid != STK3335_CHIP_ID_VAL) {
                dev_err(&client->dev, "invalid chip id: 0x%x\n", chipid);
                return -ENODEV;
        }
@@ -663,6 +665,7 @@ static SIMPLE_DEV_PM_OPS(stk3310_pm_ops, stk3310_suspend, stk3310_resume);
 static const struct i2c_device_id stk3310_i2c_id[] = {
        {"STK3310", 0},
        {"STK3311", 0},
+       {"STK3335", 0},
        {}
 };
 MODULE_DEVICE_TABLE(i2c, stk3310_i2c_id);
@@ -670,6 +673,7 @@ MODULE_DEVICE_TABLE(i2c, stk3310_i2c_id);
 static const struct acpi_device_id stk3310_acpi_id[] = {
        {"STK3310", 0},
        {"STK3311", 0},
+       {"STK3335", 0},
        {}
 };
 
index b191811fd7495602538f6656423512fd88fec149..ba420e4847875d8f448591d6ef9426558f63e781 100644 (file)
@@ -53,6 +53,17 @@ config IIO_CROS_EC_BARO
          To compile this driver as a module, choose M here: the module
          will be called cros_ec_baro.
 
+config DPS310
+       tristate "Infineon DPS310 pressure and temperature sensor"
+       depends on I2C
+       select REGMAP_I2C
+       help
+         Support for the Infineon DPS310 digital barometric pressure sensor.
+         It can be accessed over I2C bus.
+
+         This driver can also be built as a module.  If so, the module will be
+         called dps310.
+
 config HID_SENSOR_PRESS
        depends on HID_SENSOR_HUB
        select IIO_BUFFER
index c2058d7b2f93c540ed03c94f1e5398f5ec50908b..d8f5ace1f25d23c1776fb708b7c1128cb343a66e 100644 (file)
@@ -9,6 +9,7 @@ obj-$(CONFIG_BMP280) += bmp280.o
 bmp280-objs := bmp280-core.o bmp280-regmap.o
 obj-$(CONFIG_BMP280_I2C) += bmp280-i2c.o
 obj-$(CONFIG_BMP280_SPI) += bmp280-spi.o
+obj-$(CONFIG_DPS310) += dps310.o
 obj-$(CONFIG_IIO_CROS_EC_BARO) += cros_ec_baro.o
 obj-$(CONFIG_HID_SENSOR_PRESS)   += hid-sensor-press.o
 obj-$(CONFIG_HP03) += hp03.o
diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
new file mode 100644 (file)
index 0000000..2c1943b
--- /dev/null
@@ -0,0 +1,827 @@
+// SPDX-License-Identifier: GPL-2.0+
+// Copyright IBM Corp 2019
+/*
+ * The DPS310 is a barometric pressure and temperature sensor.
+ * Currently only reading a single temperature is supported by
+ * this driver.
+ *
+ * https://www.infineon.com/dgdl/?fileId=5546d462576f34750157750826c42242
+ *
+ * Temperature calculation:
+ *   c0 * 0.5 + c1 * T_raw / kT Â°C
+ *
+ * TODO:
+ *  - Optionally support the FIFO
+ */
+
+#include <linux/i2c.h>
+#include <linux/limits.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+
+#define DPS310_DEV_NAME                "dps310"
+
+#define DPS310_PRS_B0          0x00
+#define DPS310_PRS_B1          0x01
+#define DPS310_PRS_B2          0x02
+#define DPS310_TMP_B0          0x03
+#define DPS310_TMP_B1          0x04
+#define DPS310_TMP_B2          0x05
+#define DPS310_PRS_CFG         0x06
+#define  DPS310_PRS_RATE_BITS  GENMASK(6, 4)
+#define  DPS310_PRS_PRC_BITS   GENMASK(3, 0)
+#define DPS310_TMP_CFG         0x07
+#define  DPS310_TMP_RATE_BITS  GENMASK(6, 4)
+#define  DPS310_TMP_PRC_BITS   GENMASK(3, 0)
+#define  DPS310_TMP_EXT                BIT(7)
+#define DPS310_MEAS_CFG                0x08
+#define  DPS310_MEAS_CTRL_BITS GENMASK(2, 0)
+#define   DPS310_PRS_EN                BIT(0)
+#define   DPS310_TEMP_EN       BIT(1)
+#define   DPS310_BACKGROUND    BIT(2)
+#define  DPS310_PRS_RDY                BIT(4)
+#define  DPS310_TMP_RDY                BIT(5)
+#define  DPS310_SENSOR_RDY     BIT(6)
+#define  DPS310_COEF_RDY       BIT(7)
+#define DPS310_CFG_REG         0x09
+#define  DPS310_INT_HL         BIT(7)
+#define  DPS310_TMP_SHIFT_EN   BIT(3)
+#define  DPS310_PRS_SHIFT_EN   BIT(4)
+#define  DPS310_FIFO_EN                BIT(5)
+#define  DPS310_SPI_EN         BIT(6)
+#define DPS310_RESET           0x0c
+#define  DPS310_RESET_MAGIC    0x09
+#define DPS310_COEF_BASE       0x10
+
+/* Make sure sleep time is <= 20ms for usleep_range */
+#define DPS310_POLL_SLEEP_US(t)                min(20000, (t) / 8)
+/* Silently handle error in rate value here */
+#define DPS310_POLL_TIMEOUT_US(rc)     ((rc) <= 0 ? 1000000 : 1000000 / (rc))
+
+#define DPS310_PRS_BASE                DPS310_PRS_B0
+#define DPS310_TMP_BASE                DPS310_TMP_B0
+
+/*
+ * These values (defined in the spec) indicate how to scale the raw register
+ * values for each level of precision available.
+ */
+static const int scale_factors[] = {
+        524288,
+       1572864,
+       3670016,
+       7864320,
+        253952,
+        516096,
+       1040384,
+       2088960,
+};
+
+struct dps310_data {
+       struct i2c_client *client;
+       struct regmap *regmap;
+       struct mutex lock;      /* Lock for sequential HW access functions */
+
+       s32 c0, c1;
+       s32 c00, c10, c20, c30, c01, c11, c21;
+       s32 pressure_raw;
+       s32 temp_raw;
+};
+
+static const struct iio_chan_spec dps310_channels[] = {
+       {
+               .type = IIO_TEMP,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) |
+                       BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+                       BIT(IIO_CHAN_INFO_PROCESSED),
+       },
+       {
+               .type = IIO_PRESSURE,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) |
+                       BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+                       BIT(IIO_CHAN_INFO_PROCESSED),
+       },
+};
+
+/* To be called after checking the COEF_RDY bit in MEAS_CFG */
+static int dps310_get_coefs(struct dps310_data *data)
+{
+       int rc;
+       u8 coef[18];
+       u32 c0, c1;
+       u32 c00, c10, c20, c30, c01, c11, c21;
+
+       /* Read all sensor calibration coefficients from the COEF registers. */
+       rc = regmap_bulk_read(data->regmap, DPS310_COEF_BASE, coef,
+                             sizeof(coef));
+       if (rc < 0)
+               return rc;
+
+       /*
+        * Calculate temperature calibration coefficients c0 and c1. The
+        * numbers are 12-bit 2's complement numbers.
+        */
+       c0 = (coef[0] << 4) | (coef[1] >> 4);
+       data->c0 = sign_extend32(c0, 11);
+
+       c1 = ((coef[1] & GENMASK(3, 0)) << 8) | coef[2];
+       data->c1 = sign_extend32(c1, 11);
+
+       /*
+        * Calculate pressure calibration coefficients. c00 and c10 are 20 bit
+        * 2's complement numbers, while the rest are 16 bit 2's complement
+        * numbers.
+        */
+       c00 = (coef[3] << 12) | (coef[4] << 4) | (coef[5] >> 4);
+       data->c00 = sign_extend32(c00, 19);
+
+       c10 = ((coef[5] & GENMASK(3, 0)) << 16) | (coef[6] << 8) | coef[7];
+       data->c10 = sign_extend32(c10, 19);
+
+       c01 = (coef[8] << 8) | coef[9];
+       data->c01 = sign_extend32(c01, 15);
+
+       c11 = (coef[10] << 8) | coef[11];
+       data->c11 = sign_extend32(c11, 15);
+
+       c20 = (coef[12] << 8) | coef[13];
+       data->c20 = sign_extend32(c20, 15);
+
+       c21 = (coef[14] << 8) | coef[15];
+       data->c21 = sign_extend32(c21, 15);
+
+       c30 = (coef[16] << 8) | coef[17];
+       data->c30 = sign_extend32(c30, 15);
+
+       return 0;
+}
+
+static int dps310_get_pres_precision(struct dps310_data *data)
+{
+       int rc;
+       int val;
+
+       rc = regmap_read(data->regmap, DPS310_PRS_CFG, &val);
+       if (rc < 0)
+               return rc;
+
+       return BIT(val & GENMASK(2, 0));
+}
+
+static int dps310_get_temp_precision(struct dps310_data *data)
+{
+       int rc;
+       int val;
+
+       rc = regmap_read(data->regmap, DPS310_TMP_CFG, &val);
+       if (rc < 0)
+               return rc;
+
+       /*
+        * Scale factor is bottom 4 bits of the register, but 1111 is
+        * reserved so just grab bottom three
+        */
+       return BIT(val & GENMASK(2, 0));
+}
+
+/* Called with lock held */
+static int dps310_set_pres_precision(struct dps310_data *data, int val)
+{
+       int rc;
+       u8 shift_en;
+
+       if (val < 0 || val > 128)
+               return -EINVAL;
+
+       shift_en = val >= 16 ? DPS310_PRS_SHIFT_EN : 0;
+       rc = regmap_write_bits(data->regmap, DPS310_CFG_REG,
+                              DPS310_PRS_SHIFT_EN, shift_en);
+       if (rc)
+               return rc;
+
+       return regmap_update_bits(data->regmap, DPS310_PRS_CFG,
+                                 DPS310_PRS_PRC_BITS, ilog2(val));
+}
+
+/* Called with lock held */
+static int dps310_set_temp_precision(struct dps310_data *data, int val)
+{
+       int rc;
+       u8 shift_en;
+
+       if (val < 0 || val > 128)
+               return -EINVAL;
+
+       shift_en = val >= 16 ? DPS310_TMP_SHIFT_EN : 0;
+       rc = regmap_write_bits(data->regmap, DPS310_CFG_REG,
+                              DPS310_TMP_SHIFT_EN, shift_en);
+       if (rc)
+               return rc;
+
+       return regmap_update_bits(data->regmap, DPS310_TMP_CFG,
+                                 DPS310_TMP_PRC_BITS, ilog2(val));
+}
+
+/* Called with lock held */
+static int dps310_set_pres_samp_freq(struct dps310_data *data, int freq)
+{
+       u8 val;
+
+       if (freq < 0 || freq > 128)
+               return -EINVAL;
+
+       val = ilog2(freq) << 4;
+
+       return regmap_update_bits(data->regmap, DPS310_PRS_CFG,
+                                 DPS310_PRS_RATE_BITS, val);
+}
+
+/* Called with lock held */
+static int dps310_set_temp_samp_freq(struct dps310_data *data, int freq)
+{
+       u8 val;
+
+       if (freq < 0 || freq > 128)
+               return -EINVAL;
+
+       val = ilog2(freq) << 4;
+
+       return regmap_update_bits(data->regmap, DPS310_TMP_CFG,
+                                 DPS310_TMP_RATE_BITS, val);
+}
+
+static int dps310_get_pres_samp_freq(struct dps310_data *data)
+{
+       int rc;
+       int val;
+
+       rc = regmap_read(data->regmap, DPS310_PRS_CFG, &val);
+       if (rc < 0)
+               return rc;
+
+       return BIT((val & DPS310_PRS_RATE_BITS) >> 4);
+}
+
+static int dps310_get_temp_samp_freq(struct dps310_data *data)
+{
+       int rc;
+       int val;
+
+       rc = regmap_read(data->regmap, DPS310_TMP_CFG, &val);
+       if (rc < 0)
+               return rc;
+
+       return BIT((val & DPS310_TMP_RATE_BITS) >> 4);
+}
+
+static int dps310_get_pres_k(struct dps310_data *data)
+{
+       int rc = dps310_get_pres_precision(data);
+
+       if (rc < 0)
+               return rc;
+
+       return scale_factors[ilog2(rc)];
+}
+
+static int dps310_get_temp_k(struct dps310_data *data)
+{
+       int rc = dps310_get_temp_precision(data);
+
+       if (rc < 0)
+               return rc;
+
+       return scale_factors[ilog2(rc)];
+}
+
+static int dps310_read_pres_raw(struct dps310_data *data)
+{
+       int rc;
+       int rate;
+       int ready;
+       int timeout;
+       s32 raw;
+       u8 val[3];
+
+       if (mutex_lock_interruptible(&data->lock))
+               return -EINTR;
+
+       rate = dps310_get_pres_samp_freq(data);
+       timeout = DPS310_POLL_TIMEOUT_US(rate);
+
+       /* Poll for sensor readiness; base the timeout upon the sample rate. */
+       rc = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, ready,
+                                     ready & DPS310_PRS_RDY,
+                                     DPS310_POLL_SLEEP_US(timeout), timeout);
+       if (rc)
+               goto done;
+
+       rc = regmap_bulk_read(data->regmap, DPS310_PRS_BASE, val, sizeof(val));
+       if (rc < 0)
+               goto done;
+
+       raw = (val[0] << 16) | (val[1] << 8) | val[2];
+       data->pressure_raw = sign_extend32(raw, 23);
+
+done:
+       mutex_unlock(&data->lock);
+       return rc;
+}
+
+/* Called with lock held */
+static int dps310_read_temp_ready(struct dps310_data *data)
+{
+       int rc;
+       u8 val[3];
+       s32 raw;
+
+       rc = regmap_bulk_read(data->regmap, DPS310_TMP_BASE, val, sizeof(val));
+       if (rc < 0)
+               return rc;
+
+       raw = (val[0] << 16) | (val[1] << 8) | val[2];
+       data->temp_raw = sign_extend32(raw, 23);
+
+       return 0;
+}
+
+static int dps310_read_temp_raw(struct dps310_data *data)
+{
+       int rc;
+       int rate;
+       int ready;
+       int timeout;
+
+       if (mutex_lock_interruptible(&data->lock))
+               return -EINTR;
+
+       rate = dps310_get_temp_samp_freq(data);
+       timeout = DPS310_POLL_TIMEOUT_US(rate);
+
+       /* Poll for sensor readiness; base the timeout upon the sample rate. */
+       rc = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, ready,
+                                     ready & DPS310_TMP_RDY,
+                                     DPS310_POLL_SLEEP_US(timeout), timeout);
+       if (rc < 0)
+               goto done;
+
+       rc = dps310_read_temp_ready(data);
+
+done:
+       mutex_unlock(&data->lock);
+       return rc;
+}
+
+static bool dps310_is_writeable_reg(struct device *dev, unsigned int reg)
+{
+       switch (reg) {
+       case DPS310_PRS_CFG:
+       case DPS310_TMP_CFG:
+       case DPS310_MEAS_CFG:
+       case DPS310_CFG_REG:
+       case DPS310_RESET:
+       /* No documentation available on the registers below */
+       case 0x0e:
+       case 0x0f:
+       case 0x62:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static bool dps310_is_volatile_reg(struct device *dev, unsigned int reg)
+{
+       switch (reg) {
+       case DPS310_PRS_B0:
+       case DPS310_PRS_B1:
+       case DPS310_PRS_B2:
+       case DPS310_TMP_B0:
+       case DPS310_TMP_B1:
+       case DPS310_TMP_B2:
+       case DPS310_MEAS_CFG:
+       case 0x32:      /* No documentation available on this register */
+               return true;
+       default:
+               return false;
+       }
+}
+
+static int dps310_write_raw(struct iio_dev *iio,
+                           struct iio_chan_spec const *chan, int val,
+                           int val2, long mask)
+{
+       int rc;
+       struct dps310_data *data = iio_priv(iio);
+
+       if (mutex_lock_interruptible(&data->lock))
+               return -EINTR;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               switch (chan->type) {
+               case IIO_PRESSURE:
+                       rc = dps310_set_pres_samp_freq(data, val);
+                       break;
+
+               case IIO_TEMP:
+                       rc = dps310_set_temp_samp_freq(data, val);
+                       break;
+
+               default:
+                       rc = -EINVAL;
+                       break;
+               }
+               break;
+
+       case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+               switch (chan->type) {
+               case IIO_PRESSURE:
+                       rc = dps310_set_pres_precision(data, val);
+                       break;
+
+               case IIO_TEMP:
+                       rc = dps310_set_temp_precision(data, val);
+                       break;
+
+               default:
+                       rc = -EINVAL;
+                       break;
+               }
+               break;
+
+       default:
+               rc = -EINVAL;
+               break;
+       }
+
+       mutex_unlock(&data->lock);
+       return rc;
+}
+
+static int dps310_calculate_pressure(struct dps310_data *data)
+{
+       int i;
+       int rc;
+       int t_ready;
+       int kpi = dps310_get_pres_k(data);
+       int kti = dps310_get_temp_k(data);
+       s64 rem = 0ULL;
+       s64 pressure = 0ULL;
+       s64 p;
+       s64 t;
+       s64 denoms[7];
+       s64 nums[7];
+       s64 rems[7];
+       s64 kp;
+       s64 kt;
+
+       if (kpi < 0)
+               return kpi;
+
+       if (kti < 0)
+               return kti;
+
+       kp = (s64)kpi;
+       kt = (s64)kti;
+
+       /* Refresh temp if it's ready, otherwise just use the latest value */
+       if (mutex_trylock(&data->lock)) {
+               rc = regmap_read(data->regmap, DPS310_MEAS_CFG, &t_ready);
+               if (rc >= 0 && t_ready & DPS310_TMP_RDY)
+                       dps310_read_temp_ready(data);
+
+               mutex_unlock(&data->lock);
+       }
+
+       p = (s64)data->pressure_raw;
+       t = (s64)data->temp_raw;
+
+       /* Section 4.9.1 of the DPS310 spec; algebra'd to avoid underflow */
+       nums[0] = (s64)data->c00;
+       denoms[0] = 1LL;
+       nums[1] = p * (s64)data->c10;
+       denoms[1] = kp;
+       nums[2] = p * p * (s64)data->c20;
+       denoms[2] = kp * kp;
+       nums[3] = p * p * p * (s64)data->c30;
+       denoms[3] = kp * kp * kp;
+       nums[4] = t * (s64)data->c01;
+       denoms[4] = kt;
+       nums[5] = t * p * (s64)data->c11;
+       denoms[5] = kp * kt;
+       nums[6] = t * p * p * (s64)data->c21;
+       denoms[6] = kp * kp * kt;
+
+       /* Kernel lacks a div64_s64_rem function; denoms are all positive */
+       for (i = 0; i < 7; ++i) {
+               u64 irem;
+
+               if (nums[i] < 0LL) {
+                       pressure -= div64_u64_rem(-nums[i], denoms[i], &irem);
+                       rems[i] = -irem;
+               } else {
+                       pressure += div64_u64_rem(nums[i], denoms[i], &irem);
+                       rems[i] = (s64)irem;
+               }
+       }
+
+       /* Increase precision and calculate the remainder sum */
+       for (i = 0; i < 7; ++i)
+               rem += div64_s64((s64)rems[i] * 1000000000LL, denoms[i]);
+
+       pressure += div_s64(rem, 1000000000LL);
+       if (pressure < 0LL)
+               return -ERANGE;
+
+       return (int)min_t(s64, pressure, INT_MAX);
+}
+
+static int dps310_read_pressure(struct dps310_data *data, int *val, int *val2,
+                               long mask)
+{
+       int rc;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               rc = dps310_get_pres_samp_freq(data);
+               if (rc < 0)
+                       return rc;
+
+               *val = rc;
+               return IIO_VAL_INT;
+
+       case IIO_CHAN_INFO_PROCESSED:
+               rc = dps310_read_pres_raw(data);
+               if (rc)
+                       return rc;
+
+               rc = dps310_calculate_pressure(data);
+               if (rc < 0)
+                       return rc;
+
+               *val = rc;
+               *val2 = 1000; /* Convert Pa to KPa per IIO ABI */
+               return IIO_VAL_FRACTIONAL;
+
+       case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+               rc = dps310_get_pres_precision(data);
+               if (rc < 0)
+                       return rc;
+
+               *val = rc;
+               return IIO_VAL_INT;
+
+       default:
+               return -EINVAL;
+       }
+}
+
+static int dps310_calculate_temp(struct dps310_data *data)
+{
+       s64 c0;
+       s64 t;
+       int kt = dps310_get_temp_k(data);
+
+       if (kt < 0)
+               return kt;
+
+       /* Obtain inverse-scaled offset */
+       c0 = div_s64((s64)kt * (s64)data->c0, 2);
+
+       /* Add the offset to the unscaled temperature */
+       t = c0 + ((s64)data->temp_raw * (s64)data->c1);
+
+       /* Convert to milliCelsius and scale the temperature */
+       return (int)div_s64(t * 1000LL, kt);
+}
+
+static int dps310_read_temp(struct dps310_data *data, int *val, int *val2,
+                           long mask)
+{
+       int rc;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               rc = dps310_get_temp_samp_freq(data);
+               if (rc < 0)
+                       return rc;
+
+               *val = rc;
+               return IIO_VAL_INT;
+
+       case IIO_CHAN_INFO_PROCESSED:
+               rc = dps310_read_temp_raw(data);
+               if (rc)
+                       return rc;
+
+               rc = dps310_calculate_temp(data);
+               if (rc < 0)
+                       return rc;
+
+               *val = rc;
+               return IIO_VAL_INT;
+
+       case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+               rc = dps310_get_temp_precision(data);
+               if (rc < 0)
+                       return rc;
+
+               *val = rc;
+               return IIO_VAL_INT;
+
+       default:
+               return -EINVAL;
+       }
+}
+
+static int dps310_read_raw(struct iio_dev *iio,
+                          struct iio_chan_spec const *chan,
+                          int *val, int *val2, long mask)
+{
+       struct dps310_data *data = iio_priv(iio);
+
+       switch (chan->type) {
+       case IIO_PRESSURE:
+               return dps310_read_pressure(data, val, val2, mask);
+
+       case IIO_TEMP:
+               return dps310_read_temp(data, val, val2, mask);
+
+       default:
+               return -EINVAL;
+       }
+}
+
+static void dps310_reset(void *action_data)
+{
+       struct dps310_data *data = action_data;
+
+       regmap_write(data->regmap, DPS310_RESET, DPS310_RESET_MAGIC);
+}
+
+static const struct regmap_config dps310_regmap_config = {
+       .reg_bits = 8,
+       .val_bits = 8,
+       .writeable_reg = dps310_is_writeable_reg,
+       .volatile_reg = dps310_is_volatile_reg,
+       .cache_type = REGCACHE_RBTREE,
+       .max_register = 0x62, /* No documentation available on this register */
+};
+
+static const struct iio_info dps310_info = {
+       .read_raw = dps310_read_raw,
+       .write_raw = dps310_write_raw,
+};
+
+/*
+ * Some verions of chip will read temperatures in the ~60C range when
+ * its actually ~20C. This is the manufacturer recommended workaround
+ * to correct the issue. The registers used below are undocumented.
+ */
+static int dps310_temp_workaround(struct dps310_data *data)
+{
+       int rc;
+       int reg;
+
+       rc = regmap_read(data->regmap, 0x32, &reg);
+       if (rc < 0)
+               return rc;
+
+       /*
+        * If bit 1 is set then the device is okay, and the workaround does not
+        * need to be applied
+        */
+       if (reg & BIT(1))
+               return 0;
+
+       rc = regmap_write(data->regmap, 0x0e, 0xA5);
+       if (rc < 0)
+               return rc;
+
+       rc = regmap_write(data->regmap, 0x0f, 0x96);
+       if (rc < 0)
+               return rc;
+
+       rc = regmap_write(data->regmap, 0x62, 0x02);
+       if (rc < 0)
+               return rc;
+
+       rc = regmap_write(data->regmap, 0x0e, 0x00);
+       if (rc < 0)
+               return rc;
+
+       return regmap_write(data->regmap, 0x0f, 0x00);
+}
+
+static int dps310_probe(struct i2c_client *client,
+                       const struct i2c_device_id *id)
+{
+       struct dps310_data *data;
+       struct iio_dev *iio;
+       int rc, ready;
+
+       iio = devm_iio_device_alloc(&client->dev,  sizeof(*data));
+       if (!iio)
+               return -ENOMEM;
+
+       data = iio_priv(iio);
+       data->client = client;
+       mutex_init(&data->lock);
+
+       iio->dev.parent = &client->dev;
+       iio->name = id->name;
+       iio->channels = dps310_channels;
+       iio->num_channels = ARRAY_SIZE(dps310_channels);
+       iio->info = &dps310_info;
+       iio->modes = INDIO_DIRECT_MODE;
+
+       data->regmap = devm_regmap_init_i2c(client, &dps310_regmap_config);
+       if (IS_ERR(data->regmap))
+               return PTR_ERR(data->regmap);
+
+       /* Register to run the device reset when the device is removed */
+       rc = devm_add_action_or_reset(&client->dev, dps310_reset, data);
+       if (rc)
+               return rc;
+
+       /*
+        * Set up pressure sensor in single sample, one measurement per second
+        * mode
+        */
+       rc = regmap_write(data->regmap, DPS310_PRS_CFG, 0);
+
+       /*
+        * Set up external (MEMS) temperature sensor in single sample, one
+        * measurement per second mode
+        */
+       rc = regmap_write(data->regmap, DPS310_TMP_CFG, DPS310_TMP_EXT);
+       if (rc < 0)
+               return rc;
+
+       /* Temp and pressure shifts are disabled when PRC <= 8 */
+       rc = regmap_write_bits(data->regmap, DPS310_CFG_REG,
+                              DPS310_PRS_SHIFT_EN | DPS310_TMP_SHIFT_EN, 0);
+       if (rc < 0)
+               return rc;
+
+       /* MEAS_CFG doesn't update correctly unless first written with 0 */
+       rc = regmap_write_bits(data->regmap, DPS310_MEAS_CFG,
+                              DPS310_MEAS_CTRL_BITS, 0);
+       if (rc < 0)
+               return rc;
+
+       /* Turn on temperature and pressure measurement in the background */
+       rc = regmap_write_bits(data->regmap, DPS310_MEAS_CFG,
+                              DPS310_MEAS_CTRL_BITS, DPS310_PRS_EN |
+                              DPS310_TEMP_EN | DPS310_BACKGROUND);
+       if (rc < 0)
+               return rc;
+
+       /*
+        * Calibration coefficients required for reporting temperature.
+        * They are available 40ms after the device has started
+        */
+       rc = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, ready,
+                                     ready & DPS310_COEF_RDY, 10000, 40000);
+       if (rc < 0)
+               return rc;
+
+       rc = dps310_get_coefs(data);
+       if (rc < 0)
+               return rc;
+
+       rc = dps310_temp_workaround(data);
+       if (rc < 0)
+               return rc;
+
+       rc = devm_iio_device_register(&client->dev, iio);
+       if (rc)
+               return rc;
+
+       i2c_set_clientdata(client, iio);
+
+       return 0;
+}
+
+static const struct i2c_device_id dps310_id[] = {
+       { DPS310_DEV_NAME, 0 },
+       {}
+};
+MODULE_DEVICE_TABLE(i2c, dps310_id);
+
+static struct i2c_driver dps310_driver = {
+       .driver = {
+               .name = DPS310_DEV_NAME,
+       },
+       .probe = dps310_probe,
+       .id_table = dps310_id,
+};
+module_i2c_driver(dps310_driver);
+
+MODULE_AUTHOR("Joel Stanley <joel@jms.id.au>");
+MODULE_DESCRIPTION("Infineon DPS310 pressure and temperature sensor");
+MODULE_LICENSE("GPL v2");
index c31b9633f32d9b8bcac8d05d3822230d7725f5dc..c613a64c017f1e10f67867a4851e423f22a5e64a 100644 (file)
@@ -10,6 +10,8 @@
 #include <linux/init.h>
 #include <linux/mutex.h>
 #include <linux/err.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/spi/spi.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/trigger.h>
@@ -262,9 +264,17 @@ static const struct spi_device_id maxim_thermocouple_id[] = {
 };
 MODULE_DEVICE_TABLE(spi, maxim_thermocouple_id);
 
+static const struct of_device_id maxim_thermocouple_of_match[] = {
+        { .compatible = "maxim,max6675" },
+        { .compatible = "maxim,max31855" },
+        { },
+};
+MODULE_DEVICE_TABLE(of, maxim_thermocouple_of_match);
+
 static struct spi_driver maxim_thermocouple_driver = {
        .driver = {
                .name   = MAXIM_THERMOCOUPLE_DRV_NAME,
+               .of_match_table = maxim_thermocouple_of_match,
        },
        .probe          = maxim_thermocouple_probe,
        .remove         = maxim_thermocouple_remove,
index 178df581a8fc74593589655607dc7aa9ec36cebc..989fe84a9f9d79bf335d294118819e74a8cd92ca 100644 (file)
@@ -18,24 +18,6 @@ config ION_SYSTEM_HEAP
          Choose this option to enable the Ion system heap. The system heap
          is backed by pages from the buddy allocator. If in doubt, say Y.
 
-config ION_CARVEOUT_HEAP
-       bool "Ion carveout heap support"
-       depends on ION
-       help
-         Choose this option to enable carveout heaps with Ion. Carveout heaps
-         are backed by memory reserved from the system. Allocation times are
-         typically faster at the cost of memory not being used. Unless you
-         know your system has these regions, you should say N here.
-
-config ION_CHUNK_HEAP
-       bool "Ion chunk heap support"
-       depends on ION
-       help
-          Choose this option to enable chunk heaps with Ion. This heap is
-         similar in function the carveout heap but memory is broken down
-         into smaller chunk sizes, typically corresponding to a TLB size.
-         Unless you know your system has these regions, you should say N here.
-
 config ION_CMA_HEAP
        bool "Ion CMA heap support"
        depends on ION && DMA_CMA
index 17f3a7569e3de8c2e3d4301506e2f89ce8a733b8..5f4487b1a22440249cddd88fe1295ea2da00afbd 100644 (file)
@@ -1,6 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_ION) += ion.o ion_heap.o
 obj-$(CONFIG_ION_SYSTEM_HEAP) += ion_system_heap.o ion_page_pool.o
-obj-$(CONFIG_ION_CARVEOUT_HEAP) += ion_carveout_heap.o
-obj-$(CONFIG_ION_CHUNK_HEAP) += ion_chunk_heap.o
 obj-$(CONFIG_ION_CMA_HEAP) += ion_cma_heap.o
diff --git a/drivers/staging/android/ion/ion_carveout_heap.c b/drivers/staging/android/ion/ion_carveout_heap.c
deleted file mode 100644 (file)
index bb9d614..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * ION Memory Allocator carveout heap helper
- *
- * Copyright (C) 2011 Google, Inc.
- */
-
-#include <linux/dma-mapping.h>
-#include <linux/err.h>
-#include <linux/genalloc.h>
-#include <linux/io.h>
-#include <linux/mm.h>
-#include <linux/scatterlist.h>
-#include <linux/slab.h>
-
-#include "ion.h"
-
-#define ION_CARVEOUT_ALLOCATE_FAIL     -1
-
-struct ion_carveout_heap {
-       struct ion_heap heap;
-       struct gen_pool *pool;
-};
-
-static phys_addr_t ion_carveout_allocate(struct ion_heap *heap,
-                                        unsigned long size)
-{
-       struct ion_carveout_heap *carveout_heap =
-               container_of(heap, struct ion_carveout_heap, heap);
-       unsigned long offset = gen_pool_alloc(carveout_heap->pool, size);
-
-       if (!offset)
-               return ION_CARVEOUT_ALLOCATE_FAIL;
-
-       return offset;
-}
-
-static void ion_carveout_free(struct ion_heap *heap, phys_addr_t addr,
-                             unsigned long size)
-{
-       struct ion_carveout_heap *carveout_heap =
-               container_of(heap, struct ion_carveout_heap, heap);
-
-       if (addr == ION_CARVEOUT_ALLOCATE_FAIL)
-               return;
-
-       gen_pool_free(carveout_heap->pool, addr, size);
-}
-
-static int ion_carveout_heap_allocate(struct ion_heap *heap,
-                                     struct ion_buffer *buffer,
-                                     unsigned long size,
-                                     unsigned long flags)
-{
-       struct sg_table *table;
-       phys_addr_t paddr;
-       int ret;
-
-       table = kmalloc(sizeof(*table), GFP_KERNEL);
-       if (!table)
-               return -ENOMEM;
-       ret = sg_alloc_table(table, 1, GFP_KERNEL);
-       if (ret)
-               goto err_free;
-
-       paddr = ion_carveout_allocate(heap, size);
-       if (paddr == ION_CARVEOUT_ALLOCATE_FAIL) {
-               ret = -ENOMEM;
-               goto err_free_table;
-       }
-
-       sg_set_page(table->sgl, pfn_to_page(PFN_DOWN(paddr)), size, 0);
-       buffer->sg_table = table;
-
-       return 0;
-
-err_free_table:
-       sg_free_table(table);
-err_free:
-       kfree(table);
-       return ret;
-}
-
-static void ion_carveout_heap_free(struct ion_buffer *buffer)
-{
-       struct ion_heap *heap = buffer->heap;
-       struct sg_table *table = buffer->sg_table;
-       struct page *page = sg_page(table->sgl);
-       phys_addr_t paddr = PFN_PHYS(page_to_pfn(page));
-
-       ion_heap_buffer_zero(buffer);
-
-       ion_carveout_free(heap, paddr, buffer->size);
-       sg_free_table(table);
-       kfree(table);
-}
-
-static struct ion_heap_ops carveout_heap_ops = {
-       .allocate = ion_carveout_heap_allocate,
-       .free = ion_carveout_heap_free,
-       .map_user = ion_heap_map_user,
-       .map_kernel = ion_heap_map_kernel,
-       .unmap_kernel = ion_heap_unmap_kernel,
-};
-
-struct ion_heap *ion_carveout_heap_create(phys_addr_t base, size_t size)
-{
-       struct ion_carveout_heap *carveout_heap;
-       int ret;
-
-       struct page *page;
-
-       page = pfn_to_page(PFN_DOWN(base));
-       ret = ion_heap_pages_zero(page, size, pgprot_writecombine(PAGE_KERNEL));
-       if (ret)
-               return ERR_PTR(ret);
-
-       carveout_heap = kzalloc(sizeof(*carveout_heap), GFP_KERNEL);
-       if (!carveout_heap)
-               return ERR_PTR(-ENOMEM);
-
-       carveout_heap->pool = gen_pool_create(PAGE_SHIFT, -1);
-       if (!carveout_heap->pool) {
-               kfree(carveout_heap);
-               return ERR_PTR(-ENOMEM);
-       }
-       gen_pool_add(carveout_heap->pool, base, size, -1);
-       carveout_heap->heap.ops = &carveout_heap_ops;
-       carveout_heap->heap.type = ION_HEAP_TYPE_CARVEOUT;
-       carveout_heap->heap.flags = ION_HEAP_FLAG_DEFER_FREE;
-
-       return &carveout_heap->heap;
-}
diff --git a/drivers/staging/android/ion/ion_chunk_heap.c b/drivers/staging/android/ion/ion_chunk_heap.c
deleted file mode 100644 (file)
index 3cdde9c..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * ION memory allocator chunk heap helper
- *
- * Copyright (C) 2012 Google, Inc.
- */
-
-#include <linux/dma-mapping.h>
-#include <linux/err.h>
-#include <linux/genalloc.h>
-#include <linux/mm.h>
-#include <linux/scatterlist.h>
-#include <linux/slab.h>
-
-#include "ion.h"
-
-struct ion_chunk_heap {
-       struct ion_heap heap;
-       struct gen_pool *pool;
-       unsigned long chunk_size;
-       unsigned long size;
-       unsigned long allocated;
-};
-
-static int ion_chunk_heap_allocate(struct ion_heap *heap,
-                                  struct ion_buffer *buffer,
-                                  unsigned long size,
-                                  unsigned long flags)
-{
-       struct ion_chunk_heap *chunk_heap =
-               container_of(heap, struct ion_chunk_heap, heap);
-       struct sg_table *table;
-       struct scatterlist *sg;
-       int ret, i;
-       unsigned long num_chunks;
-       unsigned long allocated_size;
-
-       allocated_size = ALIGN(size, chunk_heap->chunk_size);
-       num_chunks = allocated_size / chunk_heap->chunk_size;
-
-       if (allocated_size > chunk_heap->size - chunk_heap->allocated)
-               return -ENOMEM;
-
-       table = kmalloc(sizeof(*table), GFP_KERNEL);
-       if (!table)
-               return -ENOMEM;
-       ret = sg_alloc_table(table, num_chunks, GFP_KERNEL);
-       if (ret) {
-               kfree(table);
-               return ret;
-       }
-
-       sg = table->sgl;
-       for (i = 0; i < num_chunks; i++) {
-               unsigned long paddr = gen_pool_alloc(chunk_heap->pool,
-                                                    chunk_heap->chunk_size);
-               if (!paddr)
-                       goto err;
-               sg_set_page(sg, pfn_to_page(PFN_DOWN(paddr)),
-                           chunk_heap->chunk_size, 0);
-               sg = sg_next(sg);
-       }
-
-       buffer->sg_table = table;
-       chunk_heap->allocated += allocated_size;
-       return 0;
-err:
-       sg = table->sgl;
-       for (i -= 1; i >= 0; i--) {
-               gen_pool_free(chunk_heap->pool, page_to_phys(sg_page(sg)),
-                             sg->length);
-               sg = sg_next(sg);
-       }
-       sg_free_table(table);
-       kfree(table);
-       return -ENOMEM;
-}
-
-static void ion_chunk_heap_free(struct ion_buffer *buffer)
-{
-       struct ion_heap *heap = buffer->heap;
-       struct ion_chunk_heap *chunk_heap =
-               container_of(heap, struct ion_chunk_heap, heap);
-       struct sg_table *table = buffer->sg_table;
-       struct scatterlist *sg;
-       int i;
-       unsigned long allocated_size;
-
-       allocated_size = ALIGN(buffer->size, chunk_heap->chunk_size);
-
-       ion_heap_buffer_zero(buffer);
-
-       for_each_sg(table->sgl, sg, table->nents, i) {
-               gen_pool_free(chunk_heap->pool, page_to_phys(sg_page(sg)),
-                             sg->length);
-       }
-       chunk_heap->allocated -= allocated_size;
-       sg_free_table(table);
-       kfree(table);
-}
-
-static struct ion_heap_ops chunk_heap_ops = {
-       .allocate = ion_chunk_heap_allocate,
-       .free = ion_chunk_heap_free,
-       .map_user = ion_heap_map_user,
-       .map_kernel = ion_heap_map_kernel,
-       .unmap_kernel = ion_heap_unmap_kernel,
-};
-
-struct ion_heap *ion_chunk_heap_create(phys_addr_t base, size_t size, size_t chunk_size)
-{
-       struct ion_chunk_heap *chunk_heap;
-       int ret;
-       struct page *page;
-
-       page = pfn_to_page(PFN_DOWN(base));
-       ret = ion_heap_pages_zero(page, size, pgprot_writecombine(PAGE_KERNEL));
-       if (ret)
-               return ERR_PTR(ret);
-
-       chunk_heap = kzalloc(sizeof(*chunk_heap), GFP_KERNEL);
-       if (!chunk_heap)
-               return ERR_PTR(-ENOMEM);
-
-       chunk_heap->chunk_size = chunk_size;
-       chunk_heap->pool = gen_pool_create(get_order(chunk_heap->chunk_size) +
-                                          PAGE_SHIFT, -1);
-       if (!chunk_heap->pool) {
-               ret = -ENOMEM;
-               goto error_gen_pool_create;
-       }
-       chunk_heap->size = size;
-       chunk_heap->allocated = 0;
-
-       gen_pool_add(chunk_heap->pool, base, size, -1);
-       chunk_heap->heap.ops = &chunk_heap_ops;
-       chunk_heap->heap.type = ION_HEAP_TYPE_CHUNK;
-       chunk_heap->heap.flags = ION_HEAP_FLAG_DEFER_FREE;
-       pr_debug("%s: base %pa size %zu\n", __func__, &base, size);
-
-       return &chunk_heap->heap;
-
-error_gen_pool_create:
-       kfree(chunk_heap);
-       return ERR_PTR(ret);
-}
index d2c8cc72a99dd9d42df5fca44258b8178110c815..3ef3ddabf139444d8b49259c62d2fd45c19a46e8 100644 (file)
@@ -27,18 +27,19 @@ static void comedi_buf_map_kref_release(struct kref *kref)
        unsigned int i;
 
        if (bm->page_list) {
-               for (i = 0; i < bm->n_pages; i++) {
-                       buf = &bm->page_list[i];
-                       clear_bit(PG_reserved,
-                                 &(virt_to_page(buf->virt_addr)->flags));
-                       if (bm->dma_dir != DMA_NONE) {
-#ifdef CONFIG_HAS_DMA
-                               dma_free_coherent(bm->dma_hw_dev,
-                                                 PAGE_SIZE,
-                                                 buf->virt_addr,
-                                                 buf->dma_addr);
-#endif
-                       } else {
+               if (bm->dma_dir != DMA_NONE) {
+                       /*
+                        * DMA buffer was allocated as a single block.
+                        * Address is in page_list[0].
+                        */
+                       buf = &bm->page_list[0];
+                       dma_free_coherent(bm->dma_hw_dev,
+                                         PAGE_SIZE * bm->n_pages,
+                                         buf->virt_addr, buf->dma_addr);
+               } else {
+                       for (i = 0; i < bm->n_pages; i++) {
+                               buf = &bm->page_list[i];
+                               ClearPageReserved(virt_to_page(buf->virt_addr));
                                free_page((unsigned long)buf->virt_addr);
                        }
                }
@@ -57,7 +58,8 @@ static void __comedi_buf_free(struct comedi_device *dev,
        unsigned long flags;
 
        if (async->prealloc_buf) {
-               vunmap(async->prealloc_buf);
+               if (s->async_dma_dir == DMA_NONE)
+                       vunmap(async->prealloc_buf);
                async->prealloc_buf = NULL;
                async->prealloc_bufsz = 0;
        }
@@ -69,6 +71,72 @@ static void __comedi_buf_free(struct comedi_device *dev,
        comedi_buf_map_put(bm);
 }
 
+static struct comedi_buf_map *
+comedi_buf_map_alloc(struct comedi_device *dev, enum dma_data_direction dma_dir,
+                    unsigned int n_pages)
+{
+       struct comedi_buf_map *bm;
+       struct comedi_buf_page *buf;
+       unsigned int i;
+
+       bm = kzalloc(sizeof(*bm), GFP_KERNEL);
+       if (!bm)
+               return NULL;
+
+       kref_init(&bm->refcount);
+       bm->dma_dir = dma_dir;
+       if (bm->dma_dir != DMA_NONE) {
+               /* Need ref to hardware device to free buffer later. */
+               bm->dma_hw_dev = get_device(dev->hw_dev);
+       }
+
+       bm->page_list = vzalloc(sizeof(*buf) * n_pages);
+       if (!bm->page_list)
+               goto err;
+
+       if (bm->dma_dir != DMA_NONE) {
+               void *virt_addr;
+               dma_addr_t dma_addr;
+
+               /*
+                * Currently, the DMA buffer needs to be allocated as a
+                * single block so that it can be mmap()'ed.
+                */
+               virt_addr = dma_alloc_coherent(bm->dma_hw_dev,
+                                              PAGE_SIZE * n_pages, &dma_addr,
+                                              GFP_KERNEL);
+               if (!virt_addr)
+                       goto err;
+
+               for (i = 0; i < n_pages; i++) {
+                       buf = &bm->page_list[i];
+                       buf->virt_addr = virt_addr + (i << PAGE_SHIFT);
+                       buf->dma_addr = dma_addr + (i << PAGE_SHIFT);
+               }
+
+               bm->n_pages = i;
+       } else {
+               for (i = 0; i < n_pages; i++) {
+                       buf = &bm->page_list[i];
+                       buf->virt_addr = (void *)get_zeroed_page(GFP_KERNEL);
+                       if (!buf->virt_addr)
+                               break;
+
+                       SetPageReserved(virt_to_page(buf->virt_addr));
+               }
+
+               bm->n_pages = i;
+               if (i < n_pages)
+                       goto err;
+       }
+
+       return bm;
+
+err:
+       comedi_buf_map_put(bm);
+       return NULL;
+}
+
 static void __comedi_buf_alloc(struct comedi_device *dev,
                               struct comedi_subdevice *s,
                               unsigned int n_pages)
@@ -86,57 +154,37 @@ static void __comedi_buf_alloc(struct comedi_device *dev,
                return;
        }
 
-       bm = kzalloc(sizeof(*async->buf_map), GFP_KERNEL);
+       bm = comedi_buf_map_alloc(dev, s->async_dma_dir, n_pages);
        if (!bm)
                return;
 
-       kref_init(&bm->refcount);
        spin_lock_irqsave(&s->spin_lock, flags);
        async->buf_map = bm;
        spin_unlock_irqrestore(&s->spin_lock, flags);
-       bm->dma_dir = s->async_dma_dir;
-       if (bm->dma_dir != DMA_NONE)
-               /* Need ref to hardware device to free buffer later. */
-               bm->dma_hw_dev = get_device(dev->hw_dev);
 
-       bm->page_list = vzalloc(sizeof(*buf) * n_pages);
-       if (bm->page_list)
+       if (bm->dma_dir != DMA_NONE) {
+               /*
+                * DMA buffer was allocated as a single block.
+                * Address is in page_list[0].
+                */
+               buf = &bm->page_list[0];
+               async->prealloc_buf = buf->virt_addr;
+       } else {
                pages = vmalloc(sizeof(struct page *) * n_pages);
+               if (!pages)
+                       return;
 
-       if (!pages)
-               return;
-
-       for (i = 0; i < n_pages; i++) {
-               buf = &bm->page_list[i];
-               if (bm->dma_dir != DMA_NONE)
-#ifdef CONFIG_HAS_DMA
-                       buf->virt_addr = dma_alloc_coherent(bm->dma_hw_dev,
-                                                           PAGE_SIZE,
-                                                           &buf->dma_addr,
-                                                           GFP_KERNEL |
-                                                           __GFP_COMP);
-#else
-                       break;
-#endif
-               else
-                       buf->virt_addr = (void *)get_zeroed_page(GFP_KERNEL);
-               if (!buf->virt_addr)
-                       break;
-
-               set_bit(PG_reserved, &(virt_to_page(buf->virt_addr)->flags));
-
-               pages[i] = virt_to_page(buf->virt_addr);
-       }
-       spin_lock_irqsave(&s->spin_lock, flags);
-       bm->n_pages = i;
-       spin_unlock_irqrestore(&s->spin_lock, flags);
+               for (i = 0; i < n_pages; i++) {
+                       buf = &bm->page_list[i];
+                       pages[i] = virt_to_page(buf->virt_addr);
+               }
 
-       /* vmap the prealloc_buf if all the pages were allocated */
-       if (i == n_pages)
+               /* vmap the pages to prealloc_buf */
                async->prealloc_buf = vmap(pages, n_pages, VM_MAP,
                                           COMEDI_PAGE_PROTECTION);
 
-       vfree(pages);
+               vfree(pages);
+       }
 }
 
 void comedi_buf_map_get(struct comedi_buf_map *bm)
index f6d1287c7b835421705488219c88c8182e6e4828..08d1bbbebf2d7b59edc87b8dac466421a171b29f 100644 (file)
@@ -2301,11 +2301,12 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
        struct comedi_subdevice *s;
        struct comedi_async *async;
        struct comedi_buf_map *bm = NULL;
+       struct comedi_buf_page *buf;
        unsigned long start = vma->vm_start;
        unsigned long size;
        int n_pages;
        int i;
-       int retval;
+       int retval = 0;
 
        /*
         * 'trylock' avoids circular dependency with current->mm->mmap_sem
@@ -2361,24 +2362,36 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
                retval = -EINVAL;
                goto done;
        }
-       for (i = 0; i < n_pages; ++i) {
-               struct comedi_buf_page *buf = &bm->page_list[i];
+       if (bm->dma_dir != DMA_NONE) {
+               /*
+                * DMA buffer was allocated as a single block.
+                * Address is in page_list[0].
+                */
+               buf = &bm->page_list[0];
+               retval = dma_mmap_coherent(bm->dma_hw_dev, vma, buf->virt_addr,
+                                          buf->dma_addr, n_pages * PAGE_SIZE);
+       } else {
+               for (i = 0; i < n_pages; ++i) {
+                       unsigned long pfn;
+
+                       buf = &bm->page_list[i];
+                       pfn = page_to_pfn(virt_to_page(buf->virt_addr));
+                       retval = remap_pfn_range(vma, start, pfn, PAGE_SIZE,
+                                                PAGE_SHARED);
+                       if (retval)
+                               break;
 
-               if (remap_pfn_range(vma, start,
-                                   page_to_pfn(virt_to_page(buf->virt_addr)),
-                                   PAGE_SIZE, PAGE_SHARED)) {
-                       retval = -EAGAIN;
-                       goto done;
+                       start += PAGE_SIZE;
                }
-               start += PAGE_SIZE;
        }
 
-       vma->vm_ops = &comedi_vm_ops;
-       vma->vm_private_data = bm;
+       if (retval == 0) {
+               vma->vm_ops = &comedi_vm_ops;
+               vma->vm_private_data = bm;
 
-       vma->vm_ops->open(vma);
+               vma->vm_ops->open(vma);
+       }
 
-       retval = 0;
 done:
        up_read(&dev->attach_lock);
        comedi_buf_map_put(bm); /* put reference to buf map - okay if NULL */
index 8697dc02ffb459511d0256ba7a8c1072bd03e271..0b2f04b02ebc2e78f75d0023c284b2dbc6a04532 100644 (file)
@@ -46,18 +46,6 @@ static unsigned char clk_gat_sce(unsigned int which, unsigned int chan,
               ((source & 030) << 3) | (source & 007);
 }
 
-static unsigned char clk_sce(unsigned int which, unsigned int chan,
-                            unsigned int source)
-{
-       return clk_gat_sce(which, chan, source);
-}
-
-static unsigned char gat_sce(unsigned int which, unsigned int chan,
-                            unsigned int source)
-{
-       return clk_gat_sce(which, chan, source);
-}
-
 /*
  * Periods of the internal clock sources in nanoseconds.
  */
@@ -489,7 +477,7 @@ static void dio200_subdev_8254_set_gate_src(struct comedi_device *dev,
        unsigned int offset = dio200_subdev_8254_offset(dev, s);
 
        dio200_write8(dev, DIO200_GAT_SCE(offset >> 3),
-                     gat_sce((offset >> 2) & 1, chan, src));
+                     clk_gat_sce((offset >> 2) & 1, chan, src));
 }
 
 static void dio200_subdev_8254_set_clock_src(struct comedi_device *dev,
@@ -500,7 +488,7 @@ static void dio200_subdev_8254_set_clock_src(struct comedi_device *dev,
        unsigned int offset = dio200_subdev_8254_offset(dev, s);
 
        dio200_write8(dev, DIO200_CLK_SCE(offset >> 3),
-                     clk_sce((offset >> 2) & 1, chan, src));
+                     clk_gat_sce((offset >> 2) & 1, chan, src));
 }
 
 static int dio200_subdev_8254_config(struct comedi_device *dev,
index 65f60c2b702a6cd6adeec6c3e80f1ea2c15e0a55..f7e673121864bdeb5867629b9b49014fe784f458 100644 (file)
@@ -2330,7 +2330,8 @@ static irqreturn_t pci230_interrupt(int irq, void *d)
        devpriv->intr_running = false;
        spin_unlock_irqrestore(&devpriv->isr_spinlock, irqflags);
 
-       comedi_handle_events(dev, s_ao);
+       if (s_ao)
+               comedi_handle_events(dev, s_ao);
        comedi_handle_events(dev, s_ai);
 
        return IRQ_HANDLED;
index 3be927f1d3a92694faf94dc664f3c8bb829ba804..e15e33ed94ae3c81566895633b499a8dfc4a8067 100644 (file)
@@ -557,7 +557,8 @@ static irqreturn_t dt282x_interrupt(int irq, void *d)
        }
 #endif
        comedi_handle_events(dev, s);
-       comedi_handle_events(dev, s_ao);
+       if (s_ao)
+               comedi_handle_events(dev, s_ao);
 
        return IRQ_RETVAL(handled);
 }
index 639ec15869760f5406df8be4f4a6f4f3964dd407..cc9fc263573e11b394a5880eb0b2afafc6a62ea4 100644 (file)
@@ -558,7 +558,14 @@ void mite_prep_dma(struct mite_channel *mite_chan,
 }
 EXPORT_SYMBOL_GPL(mite_prep_dma);
 
-static struct mite_channel *__mite_request_channel(struct mite *mite,
+/**
+ * mite_request_channel_in_range() - Request a MITE dma channel.
+ * @mite: MITE device.
+ * @ring: MITE dma ring.
+ * @min_channel: minimum channel index to use.
+ * @max_channel: maximum channel index to use.
+ */
+struct mite_channel *mite_request_channel_in_range(struct mite *mite,
                                                   struct mite_ring *ring,
                                                   unsigned int min_channel,
                                                   unsigned int max_channel)
@@ -583,21 +590,6 @@ static struct mite_channel *__mite_request_channel(struct mite *mite,
        spin_unlock_irqrestore(&mite->lock, flags);
        return mite_chan;
 }
-
-/**
- * mite_request_channel_in_range() - Request a MITE dma channel.
- * @mite: MITE device.
- * @ring: MITE dma ring.
- * @min_channel: minimum channel index to use.
- * @max_channel: maximum channel index to use.
- */
-struct mite_channel *mite_request_channel_in_range(struct mite *mite,
-                                                  struct mite_ring *ring,
-                                                  unsigned int min_channel,
-                                                  unsigned int max_channel)
-{
-       return __mite_request_channel(mite, ring, min_channel, max_channel);
-}
 EXPORT_SYMBOL_GPL(mite_request_channel_in_range);
 
 /**
@@ -608,7 +600,8 @@ EXPORT_SYMBOL_GPL(mite_request_channel_in_range);
 struct mite_channel *mite_request_channel(struct mite *mite,
                                          struct mite_ring *ring)
 {
-       return __mite_request_channel(mite, ring, 0, mite->num_channels - 1);
+       return mite_request_channel_in_range(mite, ring, 0,
+                                            mite->num_channels - 1);
 }
 EXPORT_SYMBOL_GPL(mite_request_channel);
 
index b8f54b7fb34a775fd5e589d7dcf7d68fe8765ea5..0350f303d5575e4c384ff7f4496afd1ef9339ad4 100644 (file)
@@ -1226,7 +1226,7 @@ static int usbdux_pwm_period(struct comedi_device *dev,
                             unsigned int period)
 {
        struct usbdux_private *devpriv = dev->private;
-       int fx2delay = 255;
+       int fx2delay;
 
        if (period < MIN_PWM_PERIOD)
                return -EAGAIN;
index 38ab344a285efbf7136074df42258c66df9ade70..e704d9e51514c0ea4e1a2eb93534d0e4a01b9348 100644 (file)
@@ -2,12 +2,12 @@
 
 EROFS_VERSION = "1.0pre1"
 
-ccflags-y += -Wall -DEROFS_VERSION=\"$(EROFS_VERSION)\"
+ccflags-y += -DEROFS_VERSION=\"$(EROFS_VERSION)\"
 
 obj-$(CONFIG_EROFS_FS) += erofs.o
 # staging requirement: to be self-contained in its own directory
 ccflags-y += -I $(srctree)/$(src)/include
 erofs-objs := super.o inode.o data.o namei.o dir.o utils.o
 erofs-$(CONFIG_EROFS_FS_XATTR) += xattr.o
-erofs-$(CONFIG_EROFS_FS_ZIP) += unzip_vle.o unzip_vle_lz4.o
+erofs-$(CONFIG_EROFS_FS_ZIP) += unzip_vle.o zmap.o decompressor.o
 
diff --git a/drivers/staging/erofs/compress.h b/drivers/staging/erofs/compress.h
new file mode 100644 (file)
index 0000000..c43aa33
--- /dev/null
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * linux/drivers/staging/erofs/compress.h
+ *
+ * Copyright (C) 2019 HUAWEI, Inc.
+ *             http://www.huawei.com/
+ * Created by Gao Xiang <gaoxiang25@huawei.com>
+ */
+#ifndef __EROFS_FS_COMPRESS_H
+#define __EROFS_FS_COMPRESS_H
+
+#include "internal.h"
+
+enum {
+       Z_EROFS_COMPRESSION_SHIFTED = Z_EROFS_COMPRESSION_MAX,
+       Z_EROFS_COMPRESSION_RUNTIME_MAX
+};
+
+struct z_erofs_decompress_req {
+       struct super_block *sb;
+       struct page **in, **out;
+
+       unsigned short pageofs_out;
+       unsigned int inputsize, outputsize;
+
+       /* indicate the algorithm will be used for decompression */
+       unsigned int alg;
+       bool inplace_io, partial_decoding;
+};
+
+/*
+ * - 0x5A110C8D ('sallocated', Z_EROFS_MAPPING_STAGING) -
+ * used to mark temporary allocated pages from other
+ * file/cached pages and NULL mapping pages.
+ */
+#define Z_EROFS_MAPPING_STAGING         ((void *)0x5A110C8D)
+
+/* check if a page is marked as staging */
+static inline bool z_erofs_page_is_staging(struct page *page)
+{
+       return page->mapping == Z_EROFS_MAPPING_STAGING;
+}
+
+static inline bool z_erofs_put_stagingpage(struct list_head *pagepool,
+                                          struct page *page)
+{
+       if (!z_erofs_page_is_staging(page))
+               return false;
+
+       /* staging pages should not be used by others at the same time */
+       if (page_ref_count(page) > 1)
+               put_page(page);
+       else
+               list_add(&page->lru, pagepool);
+       return true;
+}
+
+int z_erofs_decompress(struct z_erofs_decompress_req *rq,
+                      struct list_head *pagepool);
+
+#endif
+
index 746685f90564e25f94abd165ce34631c259f9f82..cc31c3e5984c90081c428439e6ce7bc76bc1acfd 100644 (file)
@@ -124,7 +124,7 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
        trace_erofs_map_blocks_flatmode_enter(inode, map, flags);
 
        nblocks = DIV_ROUND_UP(inode->i_size, PAGE_SIZE);
-       lastblk = nblocks - is_inode_layout_inline(inode);
+       lastblk = nblocks - is_inode_flat_inline(inode);
 
        if (unlikely(offset >= inode->i_size)) {
                /* leave out-of-bound access unmapped */
@@ -139,7 +139,7 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
        if (offset < blknr_to_addr(lastblk)) {
                map->m_pa = blknr_to_addr(vi->raw_blkaddr) + map->m_la;
                map->m_plen = blknr_to_addr(lastblk) - offset;
-       } else if (is_inode_layout_inline(inode)) {
+       } else if (is_inode_flat_inline(inode)) {
                /* 2 - inode inline B: inode, [xattrs], inline last blk... */
                struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
 
diff --git a/drivers/staging/erofs/decompressor.c b/drivers/staging/erofs/decompressor.c
new file mode 100644 (file)
index 0000000..1fb0abb
--- /dev/null
@@ -0,0 +1,335 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * linux/drivers/staging/erofs/decompressor.c
+ *
+ * Copyright (C) 2019 HUAWEI, Inc.
+ *             http://www.huawei.com/
+ * Created by Gao Xiang <gaoxiang25@huawei.com>
+ */
+#include "compress.h"
+#include <linux/lz4.h>
+
+#ifndef LZ4_DISTANCE_MAX       /* history window size */
+#define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */
+#endif
+
+#define LZ4_MAX_DISTANCE_PAGES (DIV_ROUND_UP(LZ4_DISTANCE_MAX, PAGE_SIZE) + 1)
+#ifndef LZ4_DECOMPRESS_INPLACE_MARGIN
+#define LZ4_DECOMPRESS_INPLACE_MARGIN(srcsize)  (((srcsize) >> 8) + 32)
+#endif
+
+struct z_erofs_decompressor {
+       /*
+        * if destpages have sparsed pages, fill them with bounce pages.
+        * it also check whether destpages indicate continuous physical memory.
+        */
+       int (*prepare_destpages)(struct z_erofs_decompress_req *rq,
+                                struct list_head *pagepool);
+       int (*decompress)(struct z_erofs_decompress_req *rq, u8 *out);
+       char *name;
+};
+
+static int lz4_prepare_destpages(struct z_erofs_decompress_req *rq,
+                                struct list_head *pagepool)
+{
+       const unsigned int nr =
+               PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
+       struct page *availables[LZ4_MAX_DISTANCE_PAGES] = { NULL };
+       unsigned long bounced[DIV_ROUND_UP(LZ4_MAX_DISTANCE_PAGES,
+                                          BITS_PER_LONG)] = { 0 };
+       void *kaddr = NULL;
+       unsigned int i, j, top;
+
+       top = 0;
+       for (i = j = 0; i < nr; ++i, ++j) {
+               struct page *const page = rq->out[i];
+               struct page *victim;
+
+               if (j >= LZ4_MAX_DISTANCE_PAGES)
+                       j = 0;
+
+               /* 'valid' bounced can only be tested after a complete round */
+               if (test_bit(j, bounced)) {
+                       DBG_BUGON(i < LZ4_MAX_DISTANCE_PAGES);
+                       DBG_BUGON(top >= LZ4_MAX_DISTANCE_PAGES);
+                       availables[top++] = rq->out[i - LZ4_MAX_DISTANCE_PAGES];
+               }
+
+               if (page) {
+                       __clear_bit(j, bounced);
+                       if (kaddr) {
+                               if (kaddr + PAGE_SIZE == page_address(page))
+                                       kaddr += PAGE_SIZE;
+                               else
+                                       kaddr = NULL;
+                       } else if (!i) {
+                               kaddr = page_address(page);
+                       }
+                       continue;
+               }
+               kaddr = NULL;
+               __set_bit(j, bounced);
+
+               if (top) {
+                       victim = availables[--top];
+                       get_page(victim);
+               } else {
+                       if (!list_empty(pagepool)) {
+                               victim = lru_to_page(pagepool);
+                               list_del(&victim->lru);
+                               DBG_BUGON(page_ref_count(victim) != 1);
+                       } else {
+                               victim = alloc_pages(GFP_KERNEL, 0);
+                               if (!victim)
+                                       return -ENOMEM;
+                       }
+                       victim->mapping = Z_EROFS_MAPPING_STAGING;
+               }
+               rq->out[i] = victim;
+       }
+       return kaddr ? 1 : 0;
+}
+
+static void *generic_copy_inplace_data(struct z_erofs_decompress_req *rq,
+                                      u8 *src, unsigned int pageofs_in)
+{
+       /*
+        * if in-place decompression is ongoing, those decompressed
+        * pages should be copied in order to avoid being overlapped.
+        */
+       struct page **in = rq->in;
+       u8 *const tmp = erofs_get_pcpubuf(0);
+       u8 *tmpp = tmp;
+       unsigned int inlen = rq->inputsize - pageofs_in;
+       unsigned int count = min_t(uint, inlen, PAGE_SIZE - pageofs_in);
+
+       while (tmpp < tmp + inlen) {
+               if (!src)
+                       src = kmap_atomic(*in);
+               memcpy(tmpp, src + pageofs_in, count);
+               kunmap_atomic(src);
+               src = NULL;
+               tmpp += count;
+               pageofs_in = 0;
+               count = PAGE_SIZE;
+               ++in;
+       }
+       return tmp;
+}
+
+static int lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out)
+{
+       unsigned int inputmargin, inlen;
+       u8 *src;
+       bool copied, support_0padding;
+       int ret;
+
+       if (rq->inputsize > PAGE_SIZE)
+               return -ENOTSUPP;
+
+       src = kmap_atomic(*rq->in);
+       inputmargin = 0;
+       support_0padding = false;
+
+       /* decompression inplace is only safe when 0padding is enabled */
+       if (EROFS_SB(rq->sb)->requirements & EROFS_REQUIREMENT_LZ4_0PADDING) {
+               support_0padding = true;
+
+               while (!src[inputmargin & ~PAGE_MASK])
+                       if (!(++inputmargin & ~PAGE_MASK))
+                               break;
+
+               if (inputmargin >= rq->inputsize) {
+                       kunmap_atomic(src);
+                       return -EIO;
+               }
+       }
+
+       copied = false;
+       inlen = rq->inputsize - inputmargin;
+       if (rq->inplace_io) {
+               const uint oend = (rq->pageofs_out +
+                                  rq->outputsize) & ~PAGE_MASK;
+               const uint nr = PAGE_ALIGN(rq->pageofs_out +
+                                          rq->outputsize) >> PAGE_SHIFT;
+
+               if (rq->partial_decoding || !support_0padding ||
+                   rq->out[nr - 1] != rq->in[0] ||
+                   rq->inputsize - oend <
+                     LZ4_DECOMPRESS_INPLACE_MARGIN(inlen)) {
+                       src = generic_copy_inplace_data(rq, src, inputmargin);
+                       inputmargin = 0;
+                       copied = true;
+               }
+       }
+
+       ret = LZ4_decompress_safe_partial(src + inputmargin, out,
+                                         inlen, rq->outputsize,
+                                         rq->outputsize);
+       if (ret < 0) {
+               errln("%s, failed to decompress, in[%p, %u, %u] out[%p, %u]",
+                     __func__, src + inputmargin, inlen, inputmargin,
+                     out, rq->outputsize);
+               WARN_ON(1);
+               print_hex_dump(KERN_DEBUG, "[ in]: ", DUMP_PREFIX_OFFSET,
+                              16, 1, src + inputmargin, inlen, true);
+               print_hex_dump(KERN_DEBUG, "[out]: ", DUMP_PREFIX_OFFSET,
+                              16, 1, out, rq->outputsize, true);
+               ret = -EIO;
+       }
+
+       if (copied)
+               erofs_put_pcpubuf(src);
+       else
+               kunmap_atomic(src);
+       return ret;
+}
+
+static struct z_erofs_decompressor decompressors[] = {
+       [Z_EROFS_COMPRESSION_SHIFTED] = {
+               .name = "shifted"
+       },
+       [Z_EROFS_COMPRESSION_LZ4] = {
+               .prepare_destpages = lz4_prepare_destpages,
+               .decompress = lz4_decompress,
+               .name = "lz4"
+       },
+};
+
+static void copy_from_pcpubuf(struct page **out, const char *dst,
+                             unsigned short pageofs_out,
+                             unsigned int outputsize)
+{
+       const char *end = dst + outputsize;
+       const unsigned int righthalf = PAGE_SIZE - pageofs_out;
+       const char *cur = dst - pageofs_out;
+
+       while (cur < end) {
+               struct page *const page = *out++;
+
+               if (page) {
+                       char *buf = kmap_atomic(page);
+
+                       if (cur >= dst) {
+                               memcpy(buf, cur, min_t(uint, PAGE_SIZE,
+                                                      end - cur));
+                       } else {
+                               memcpy(buf + pageofs_out, cur + pageofs_out,
+                                      min_t(uint, righthalf, end - cur));
+                       }
+                       kunmap_atomic(buf);
+               }
+               cur += PAGE_SIZE;
+       }
+}
+
+static int decompress_generic(struct z_erofs_decompress_req *rq,
+                             struct list_head *pagepool)
+{
+       const unsigned int nrpages_out =
+               PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
+       const struct z_erofs_decompressor *alg = decompressors + rq->alg;
+       unsigned int dst_maptype;
+       void *dst;
+       int ret;
+
+       if (nrpages_out == 1 && !rq->inplace_io) {
+               DBG_BUGON(!*rq->out);
+               dst = kmap_atomic(*rq->out);
+               dst_maptype = 0;
+               goto dstmap_out;
+       }
+
+       /*
+        * For the case of small output size (especially much less
+        * than PAGE_SIZE), memcpy the decompressed data rather than
+        * compressed data is preferred.
+        */
+       if (rq->outputsize <= PAGE_SIZE * 7 / 8) {
+               dst = erofs_get_pcpubuf(0);
+               if (IS_ERR(dst))
+                       return PTR_ERR(dst);
+
+               rq->inplace_io = false;
+               ret = alg->decompress(rq, dst);
+               if (!ret)
+                       copy_from_pcpubuf(rq->out, dst, rq->pageofs_out,
+                                         rq->outputsize);
+
+               erofs_put_pcpubuf(dst);
+               return ret;
+       }
+
+       ret = alg->prepare_destpages(rq, pagepool);
+       if (ret < 0) {
+               return ret;
+       } else if (ret) {
+               dst = page_address(*rq->out);
+               dst_maptype = 1;
+               goto dstmap_out;
+       }
+
+       dst = erofs_vmap(rq->out, nrpages_out);
+       if (!dst)
+               return -ENOMEM;
+       dst_maptype = 2;
+
+dstmap_out:
+       ret = alg->decompress(rq, dst + rq->pageofs_out);
+
+       if (!dst_maptype)
+               kunmap_atomic(dst);
+       else if (dst_maptype == 2)
+               erofs_vunmap(dst, nrpages_out);
+       return ret;
+}
+
+static int shifted_decompress(const struct z_erofs_decompress_req *rq,
+                             struct list_head *pagepool)
+{
+       const unsigned int nrpages_out =
+               PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
+       const unsigned int righthalf = PAGE_SIZE - rq->pageofs_out;
+       unsigned char *src, *dst;
+
+       if (nrpages_out > 2) {
+               DBG_BUGON(1);
+               return -EIO;
+       }
+
+       if (rq->out[0] == *rq->in) {
+               DBG_BUGON(nrpages_out != 1);
+               return 0;
+       }
+
+       src = kmap_atomic(*rq->in);
+       if (!rq->out[0]) {
+               dst = NULL;
+       } else {
+               dst = kmap_atomic(rq->out[0]);
+               memcpy(dst + rq->pageofs_out, src, righthalf);
+       }
+
+       if (rq->out[1] == *rq->in) {
+               memmove(src, src + righthalf, rq->pageofs_out);
+       } else if (nrpages_out == 2) {
+               if (dst)
+                       kunmap_atomic(dst);
+               DBG_BUGON(!rq->out[1]);
+               dst = kmap_atomic(rq->out[1]);
+               memcpy(dst, src + righthalf, rq->pageofs_out);
+       }
+       if (dst)
+               kunmap_atomic(dst);
+       kunmap_atomic(src);
+       return 0;
+}
+
+int z_erofs_decompress(struct z_erofs_decompress_req *rq,
+                      struct list_head *pagepool)
+{
+       if (rq->alg == Z_EROFS_COMPRESSION_SHIFTED)
+               return shifted_decompress(rq, pagepool);
+       return decompress_generic(rq, pagepool);
+}
+
index 9bbc68729c11052018c26335d6b88498e3491b32..dbf6a151886c437c80fd1365628272c4fe32c8b6 100644 (file)
@@ -42,10 +42,9 @@ static int erofs_fill_dentries(struct dir_context *ctx,
                               void *dentry_blk, unsigned int *ofs,
                               unsigned int nameoff, unsigned int maxsize)
 {
-       struct erofs_dirent *de = dentry_blk;
+       struct erofs_dirent *de = dentry_blk + *ofs;
        const struct erofs_dirent *end = dentry_blk + nameoff;
 
-       de = dentry_blk + *ofs;
        while (de < end) {
                const char *de_name;
                unsigned int de_namelen;
index 8ddb2b3e7d394513ca3acac4a2953390d576a5de..9f61abb7c1cac7b18da7a4e72c74ebc925b2a340 100644 (file)
@@ -21,7 +21,8 @@
  * Any bits that aren't in EROFS_ALL_REQUIREMENTS should be
  * incompatible with this kernel version.
  */
-#define EROFS_ALL_REQUIREMENTS  0
+#define EROFS_REQUIREMENT_LZ4_0PADDING 0x00000001
+#define EROFS_ALL_REQUIREMENTS         EROFS_REQUIREMENT_LZ4_0PADDING
 
 struct erofs_super_block {
 /*  0 */__le32 magic;           /* in the little endian */
@@ -49,19 +50,29 @@ struct erofs_super_block {
  * erofs inode data mapping:
  * 0 - inode plain without inline data A:
  * inode, [xattrs], ... | ... | no-holed data
- * 1 - inode VLE compression B:
+ * 1 - inode VLE compression B (legacy):
  * inode, [xattrs], extents ... | ...
  * 2 - inode plain with inline data C:
  * inode, [xattrs], last_inline_data, ... | ... | no-holed data
- * 3~7 - reserved
+ * 3 - inode compression D:
+ * inode, [xattrs], map_header, extents ... | ...
+ * 4~7 - reserved
  */
 enum {
-       EROFS_INODE_LAYOUT_PLAIN,
-       EROFS_INODE_LAYOUT_COMPRESSION,
-       EROFS_INODE_LAYOUT_INLINE,
+       EROFS_INODE_FLAT_PLAIN,
+       EROFS_INODE_FLAT_COMPRESSION_LEGACY,
+       EROFS_INODE_FLAT_INLINE,
+       EROFS_INODE_FLAT_COMPRESSION,
        EROFS_INODE_LAYOUT_MAX
 };
 
+static bool erofs_inode_is_data_compressed(unsigned int datamode)
+{
+       if (datamode == EROFS_INODE_FLAT_COMPRESSION)
+               return true;
+       return datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY;
+}
+
 /* bit definitions of inode i_advise */
 #define EROFS_I_VERSION_BITS            1
 #define EROFS_I_DATA_MAPPING_BITS       3
@@ -176,11 +187,39 @@ struct erofs_xattr_entry {
        sizeof(struct erofs_xattr_entry) + \
        (entry)->e_name_len + le16_to_cpu((entry)->e_value_size))
 
-/* have to be aligned with 8 bytes on disk */
-struct erofs_extent_header {
-       __le32 eh_checksum;
-       __le32 eh_reserved[3];
-} __packed;
+/* available compression algorithm types */
+enum {
+       Z_EROFS_COMPRESSION_LZ4,
+       Z_EROFS_COMPRESSION_MAX
+};
+
+/*
+ * bit 0 : COMPACTED_2B indexes (0 - off; 1 - on)
+ *  e.g. for 4k logical cluster size,      4B        if compacted 2B is off;
+ *                                  (4B) + 2B + (4B) if compacted 2B is on.
+ */
+#define Z_EROFS_ADVISE_COMPACTED_2B_BIT         0
+
+#define Z_EROFS_ADVISE_COMPACTED_2B     (1 << Z_EROFS_ADVISE_COMPACTED_2B_BIT)
+
+struct z_erofs_map_header {
+       __le32  h_reserved1;
+       __le16  h_advise;
+       /*
+        * bit 0-3 : algorithm type of head 1 (logical cluster type 01);
+        * bit 4-7 : algorithm type of head 2 (logical cluster type 11).
+        */
+       __u8    h_algorithmtype;
+       /*
+        * bit 0-2 : logical cluster bits - 12, e.g. 0 for 4096;
+        * bit 3-4 : (physical - logical) cluster bits of head 1:
+        *       For example, if logical clustersize = 4096, 1 for 8192.
+        * bit 5-7 : (physical - logical) cluster bits of head 2.
+        */
+       __u8    h_clusterbits;
+};
+
+#define Z_EROFS_VLE_LEGACY_HEADER_PADDING       8
 
 /*
  * Z_EROFS Variable-sized Logical Extent cluster type:
@@ -236,8 +275,9 @@ struct z_erofs_vle_decompressed_index {
        } di_u __packed;                /* 8 bytes */
 } __packed;
 
-#define Z_EROFS_VLE_EXTENT_ALIGN(size) round_up(size, \
-       sizeof(struct z_erofs_vle_decompressed_index))
+#define Z_EROFS_VLE_LEGACY_INDEX_ALIGN(size) \
+       (round_up(size, sizeof(struct z_erofs_vle_decompressed_index)) + \
+        sizeof(struct z_erofs_map_header) + Z_EROFS_VLE_LEGACY_HEADER_PADDING)
 
 /* dirent sorts in alphabet order, thus we can do binary search */
 struct erofs_dirent {
@@ -270,7 +310,7 @@ static inline void erofs_check_ondisk_layout_definitions(void)
        BUILD_BUG_ON(sizeof(struct erofs_inode_v2) != 64);
        BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
        BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
-       BUILD_BUG_ON(sizeof(struct erofs_extent_header) != 16);
+       BUILD_BUG_ON(sizeof(struct z_erofs_map_header) != 8);
        BUILD_BUG_ON(sizeof(struct z_erofs_vle_decompressed_index) != 8);
        BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);
 
index c7d3b815a798320292f23d718520beedb68c8e3b..4c3d8bf8d24985d3d5906eab683141102d3f5cc1 100644 (file)
@@ -20,12 +20,13 @@ static int read_inode(struct inode *inode, void *data)
        struct erofs_vnode *vi = EROFS_V(inode);
        struct erofs_inode_v1 *v1 = data;
        const unsigned int advise = le16_to_cpu(v1->i_advise);
+       erofs_blk_t nblks = 0;
 
-       vi->data_mapping_mode = __inode_data_mapping(advise);
+       vi->datamode = __inode_data_mapping(advise);
 
-       if (unlikely(vi->data_mapping_mode >= EROFS_INODE_LAYOUT_MAX)) {
-               errln("unknown data mapping mode %u of nid %llu",
-                     vi->data_mapping_mode, vi->nid);
+       if (unlikely(vi->datamode >= EROFS_INODE_LAYOUT_MAX)) {
+               errln("unsupported data mapping %u of nid %llu",
+                     vi->datamode, vi->nid);
                DBG_BUGON(1);
                return -EIO;
        }
@@ -60,6 +61,10 @@ static int read_inode(struct inode *inode, void *data)
                        le32_to_cpu(v2->i_ctime_nsec);
 
                inode->i_size = le64_to_cpu(v2->i_size);
+
+               /* total blocks for compressed files */
+               if (is_inode_layout_compression(inode))
+                       nblks = le32_to_cpu(v2->i_u.compressed_blocks);
        } else if (__inode_version(advise) == EROFS_INODE_LAYOUT_V1) {
                struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
 
@@ -90,6 +95,8 @@ static int read_inode(struct inode *inode, void *data)
                        sbi->build_time_nsec;
 
                inode->i_size = le32_to_cpu(v1->i_size);
+               if (is_inode_layout_compression(inode))
+                       nblks = le32_to_cpu(v1->i_u.compressed_blocks);
        } else {
                errln("unsupported on-disk inode version %u of nid %llu",
                      __inode_version(advise), vi->nid);
@@ -97,8 +104,11 @@ static int read_inode(struct inode *inode, void *data)
                return -EIO;
        }
 
-       /* measure inode.i_blocks as the generic filesystem */
-       inode->i_blocks = ((inode->i_size - 1) >> 9) + 1;
+       if (!nblks)
+               /* measure inode.i_blocks as generic filesystems */
+               inode->i_blocks = roundup(inode->i_size, EROFS_BLKSIZ) >> 9;
+       else
+               inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK;
        return 0;
 }
 
@@ -117,12 +127,9 @@ static int fill_inline_data(struct inode *inode, void *data,
 {
        struct erofs_vnode *vi = EROFS_V(inode);
        struct erofs_sb_info *sbi = EROFS_I_SB(inode);
-       int mode = vi->data_mapping_mode;
-
-       DBG_BUGON(mode >= EROFS_INODE_LAYOUT_MAX);
 
        /* should be inode inline C */
-       if (mode != EROFS_INODE_LAYOUT_INLINE)
+       if (!is_inode_flat_inline(inode))
                return 0;
 
        /* fast symlink (following ext4) */
@@ -148,7 +155,7 @@ static int fill_inline_data(struct inode *inode, void *data,
                inode->i_link = lnk;
                set_inode_fast_symlink(inode);
        }
-       return -EAGAIN;
+       return 0;
 }
 
 static int fill_inode(struct inode *inode, int isdir)
@@ -197,25 +204,21 @@ static int fill_inode(struct inode *inode, int isdir)
                        S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
                        inode->i_op = &erofs_generic_iops;
                        init_special_inode(inode, inode->i_mode, inode->i_rdev);
+                       goto out_unlock;
                } else {
                        err = -EIO;
                        goto out_unlock;
                }
 
                if (is_inode_layout_compression(inode)) {
-#ifdef CONFIG_EROFS_FS_ZIP
-                       inode->i_mapping->a_ops =
-                               &z_erofs_vle_normalaccess_aops;
-#else
-                       err = -ENOTSUPP;
-#endif
+                       err = z_erofs_fill_inode(inode);
                        goto out_unlock;
                }
 
                inode->i_mapping->a_ops = &erofs_raw_access_aops;
 
                /* fill last page if inline data is available */
-               fill_inline_data(inode, data, ofs);
+               err = fill_inline_data(inode, data, ofs);
        }
 
 out_unlock:
@@ -285,7 +288,24 @@ struct inode *erofs_iget(struct super_block *sb,
        return inode;
 }
 
+int erofs_getattr(const struct path *path, struct kstat *stat,
+                 u32 request_mask, unsigned int query_flags)
+{
+       struct inode *const inode = d_inode(path->dentry);
+
+       if (is_inode_layout_compression(inode))
+               stat->attributes |= STATX_ATTR_COMPRESSED;
+
+       stat->attributes |= STATX_ATTR_IMMUTABLE;
+       stat->attributes_mask |= (STATX_ATTR_COMPRESSED |
+                                 STATX_ATTR_IMMUTABLE);
+
+       generic_fillattr(inode, stat);
+       return 0;
+}
+
 const struct inode_operations erofs_generic_iops = {
+       .getattr = erofs_getattr,
 #ifdef CONFIG_EROFS_FS_XATTR
        .listxattr = erofs_listxattr,
 #endif
@@ -294,6 +314,7 @@ const struct inode_operations erofs_generic_iops = {
 
 const struct inode_operations erofs_symlink_iops = {
        .get_link = page_get_link,
+       .getattr = erofs_getattr,
 #ifdef CONFIG_EROFS_FS_XATTR
        .listxattr = erofs_listxattr,
 #endif
@@ -302,6 +323,7 @@ const struct inode_operations erofs_symlink_iops = {
 
 const struct inode_operations erofs_fast_symlink_iops = {
        .get_link = simple_get_link,
+       .getattr = erofs_getattr,
 #ifdef CONFIG_EROFS_FS_XATTR
        .listxattr = erofs_listxattr,
 #endif
index 382258fc124da1afabd1ba5bd9088a91a0bda216..963cc1b8b8961b0f208a642f91f0f4d9a6f58e65 100644 (file)
@@ -321,6 +321,10 @@ static inline void z_erofs_exit_zip_subsystem(void) {}
 
 /* page count of a compressed cluster */
 #define erofs_clusterpages(sbi)         ((1 << (sbi)->clusterbits) / PAGE_SIZE)
+
+#define EROFS_PCPUBUF_NR_PAGES          Z_EROFS_CLUSTER_MAX_PAGES
+#else
+#define EROFS_PCPUBUF_NR_PAGES          0
 #endif
 
 typedef u64 erofs_off_t;
@@ -339,9 +343,11 @@ static inline erofs_off_t iloc(struct erofs_sb_info *sbi, erofs_nid_t nid)
 
 /* atomic flag definitions */
 #define EROFS_V_EA_INITED_BIT  0
+#define EROFS_V_Z_INITED_BIT   1
 
 /* bitlock definitions (arranged in reverse order) */
 #define EROFS_V_BL_XATTR_BIT   (BITS_PER_LONG - 1)
+#define EROFS_V_BL_Z_BIT       (BITS_PER_LONG - 2)
 
 struct erofs_vnode {
        erofs_nid_t nid;
@@ -349,16 +355,24 @@ struct erofs_vnode {
        /* atomic flags (including bitlocks) */
        unsigned long flags;
 
-       unsigned char data_mapping_mode;
-       /* inline size in bytes */
+       unsigned char datamode;
        unsigned char inode_isize;
        unsigned short xattr_isize;
 
        unsigned xattr_shared_count;
        unsigned *xattr_shared_xattrs;
 
-       erofs_blk_t raw_blkaddr;
-
+       union {
+               erofs_blk_t raw_blkaddr;
+#ifdef CONFIG_EROFS_FS_ZIP
+               struct {
+                       unsigned short z_advise;
+                       unsigned char  z_algorithmtype[2];
+                       unsigned char  z_logical_clusterbits;
+                       unsigned char  z_physical_clusterbits[2];
+               };
+#endif
+       };
        /* the corresponding vfs inode */
        struct inode vfs_inode;
 };
@@ -383,20 +397,14 @@ static inline unsigned long inode_datablocks(struct inode *inode)
        return DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ);
 }
 
-static inline bool is_inode_layout_plain(struct inode *inode)
-{
-       return EROFS_V(inode)->data_mapping_mode == EROFS_INODE_LAYOUT_PLAIN;
-}
-
 static inline bool is_inode_layout_compression(struct inode *inode)
 {
-       return EROFS_V(inode)->data_mapping_mode ==
-                                       EROFS_INODE_LAYOUT_COMPRESSION;
+       return erofs_inode_is_data_compressed(EROFS_V(inode)->datamode);
 }
 
-static inline bool is_inode_layout_inline(struct inode *inode)
+static inline bool is_inode_flat_inline(struct inode *inode)
 {
-       return EROFS_V(inode)->data_mapping_mode == EROFS_INODE_LAYOUT_INLINE;
+       return EROFS_V(inode)->datamode == EROFS_INODE_FLAT_INLINE;
 }
 
 extern const struct super_operations erofs_sops;
@@ -433,6 +441,7 @@ extern const struct address_space_operations z_erofs_vle_normalaccess_aops;
  */
 enum {
        BH_Zipped = BH_PrivateStart,
+       BH_FullMapped,
 };
 
 /* Has a disk mapping */
@@ -441,6 +450,8 @@ enum {
 #define EROFS_MAP_META         (1 << BH_Meta)
 /* The extent has been compressed */
 #define EROFS_MAP_ZIPPED       (1 << BH_Zipped)
+/* The length of extent is full */
+#define EROFS_MAP_FULL_MAPPED  (1 << BH_FullMapped)
 
 struct erofs_map_blocks {
        erofs_off_t m_pa, m_la;
@@ -454,11 +465,14 @@ struct erofs_map_blocks {
 /* Flags used by erofs_map_blocks() */
 #define EROFS_GET_BLOCKS_RAW    0x0001
 
+/* zmap.c */
 #ifdef CONFIG_EROFS_FS_ZIP
+int z_erofs_fill_inode(struct inode *inode);
 int z_erofs_map_blocks_iter(struct inode *inode,
                            struct erofs_map_blocks *map,
                            int flags);
 #else
+static inline int z_erofs_fill_inode(struct inode *inode) { return -ENOTSUPP; }
 static inline int z_erofs_map_blocks_iter(struct inode *inode,
                                          struct erofs_map_blocks *map,
                                          int flags)
@@ -558,6 +572,8 @@ static inline bool is_inode_fast_symlink(struct inode *inode)
 }
 
 struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid, bool dir);
+int erofs_getattr(const struct path *path, struct kstat *stat,
+                 u32 request_mask, unsigned int query_flags);
 
 /* namei.c */
 extern const struct inode_operations erofs_dir_iops;
@@ -599,6 +615,22 @@ static inline void erofs_vunmap(const void *mem, unsigned int count)
 extern struct shrinker erofs_shrinker_info;
 
 struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp);
+
+#if (EROFS_PCPUBUF_NR_PAGES > 0)
+void *erofs_get_pcpubuf(unsigned int pagenr);
+#define erofs_put_pcpubuf(buf) do { \
+       (void)&(buf);   \
+       preempt_enable();       \
+} while (0)
+#else
+static inline void *erofs_get_pcpubuf(unsigned int pagenr)
+{
+       return ERR_PTR(-ENOTSUPP);
+}
+
+#define erofs_put_pcpubuf(buf) do {} while (0)
+#endif
+
 void erofs_register_super(struct super_block *sb);
 void erofs_unregister_super(struct super_block *sb);
 
index d8d9dc9dab437866d9284ff7b405565bf1c6f9cd..fd3ae78d0ba59cec223fc46edeabfcc6a20f1f58 100644 (file)
@@ -247,6 +247,7 @@ static struct dentry *erofs_lookup(struct inode *dir,
 
 const struct inode_operations erofs_dir_iops = {
        .lookup = erofs_lookup,
+       .getattr = erofs_getattr,
 #ifdef CONFIG_EROFS_FS_XATTR
        .listxattr = erofs_listxattr,
 #endif
index cadbcc11702aa7a0eb5f914478e9eed5ad5e9351..54494412eba4189fa64844d5a4ef207e5ac74e51 100644 (file)
@@ -383,7 +383,7 @@ static int erofs_read_super(struct super_block *sb,
                goto err;
        }
 
-       sbi = kzalloc(sizeof(struct erofs_sb_info), GFP_KERNEL);
+       sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
        if (unlikely(!sbi)) {
                err = -ENOMEM;
                goto err;
index f37d8fd147717709ff59692629513113bf0bec59..7af0ba8d84954172d0d8f5e57e96ab171076b304 100644 (file)
@@ -69,10 +69,7 @@ z_erofs_pagevec_ctor_next_page(struct z_erofs_pagevec_ctor *ctor,
                if (tags == Z_EROFS_PAGE_TYPE_EXCLUSIVE)
                        return tagptr_unfold_ptr(t);
        }
-
-       if (unlikely(nr >= ctor->nr))
-               BUG();
-
+       DBG_BUGON(nr >= ctor->nr);
        return NULL;
 }
 
index 9ecaa872bae8de7af47cc7ad0bede41048adabcc..f0dab81ff8167f89d1bd21241abbed335dd810cd 100644 (file)
@@ -11,6 +11,7 @@
  * distribution for more details.
  */
 #include "unzip_vle.h"
+#include "compress.h"
 #include <linux/prefetch.h>
 
 #include <trace/events/erofs.h>
@@ -329,7 +330,7 @@ try_to_claim_workgroup(struct z_erofs_vle_workgroup *grp,
                       z_erofs_vle_owned_workgrp_t *owned_head,
                       bool *hosted)
 {
-       DBG_BUGON(*hosted == true);
+       DBG_BUGON(*hosted);
 
        /* let's claim these following types of workgroup */
 retry:
@@ -468,6 +469,9 @@ z_erofs_vle_work_register(const struct z_erofs_vle_work_finder *f,
                                    Z_EROFS_VLE_WORKGRP_FMT_LZ4 :
                                    Z_EROFS_VLE_WORKGRP_FMT_PLAIN);
 
+       if (map->m_flags & EROFS_MAP_FULL_MAPPED)
+               grp->flags |= Z_EROFS_VLE_WORKGRP_FULL_LENGTH;
+
        /* new workgrps have been claimed as type 1 */
        WRITE_ONCE(grp->next, *f->owned_head);
        /* primary and followed work for all new workgrps */
@@ -552,8 +556,7 @@ repeat:
        if (IS_ERR(work))
                return PTR_ERR(work);
 got_it:
-       z_erofs_pagevec_ctor_init(&builder->vector,
-                                 Z_EROFS_VLE_INLINE_PAGEVECS,
+       z_erofs_pagevec_ctor_init(&builder->vector, Z_EROFS_NR_INLINE_PAGEVECS,
                                  work->pagevec, work->vcnt);
 
        if (builder->role >= Z_EROFS_VLE_WORK_PRIMARY) {
@@ -856,7 +859,7 @@ static inline void z_erofs_vle_read_endio(struct bio *bio)
                DBG_BUGON(PageUptodate(page));
                DBG_BUGON(!page->mapping);
 
-               if (unlikely(!sbi && !z_erofs_is_stagingpage(page))) {
+               if (unlikely(!sbi && !z_erofs_page_is_staging(page))) {
                        sbi = EROFS_SB(page->mapping->host->i_sb);
 
                        if (time_to_inject(sbi, FAULT_READ_IO)) {
@@ -897,12 +900,12 @@ static int z_erofs_vle_unzip(struct super_block *sb,
        unsigned int sparsemem_pages = 0;
        struct page *pages_onstack[Z_EROFS_VLE_VMAP_ONSTACK_PAGES];
        struct page **pages, **compressed_pages, *page;
-       unsigned int i, llen;
+       unsigned int algorithm;
+       unsigned int i, outputsize;
 
        enum z_erofs_page_type page_type;
-       bool overlapped;
+       bool overlapped, partial;
        struct z_erofs_vle_work *work;
-       void *vout;
        int err;
 
        might_sleep();
@@ -936,7 +939,7 @@ repeat:
        for (i = 0; i < nr_pages; ++i)
                pages[i] = NULL;
 
-       z_erofs_pagevec_ctor_init(&ctor, Z_EROFS_VLE_INLINE_PAGEVECS,
+       z_erofs_pagevec_ctor_init(&ctor, Z_EROFS_NR_INLINE_PAGEVECS,
                                  work->pagevec, 0);
 
        for (i = 0; i < work->vcnt; ++i) {
@@ -948,7 +951,7 @@ repeat:
                DBG_BUGON(!page);
                DBG_BUGON(!page->mapping);
 
-               if (z_erofs_gather_if_stagingpage(page_pool, page))
+               if (z_erofs_put_stagingpage(page_pool, page))
                        continue;
 
                if (page_type == Z_EROFS_VLE_PAGE_TYPE_HEAD)
@@ -978,7 +981,7 @@ repeat:
                DBG_BUGON(!page);
                DBG_BUGON(!page->mapping);
 
-               if (!z_erofs_is_stagingpage(page)) {
+               if (!z_erofs_page_is_staging(page)) {
                        if (erofs_page_is_managed(sbi, page)) {
                                if (unlikely(!PageUptodate(page)))
                                        err = -EIO;
@@ -1009,43 +1012,30 @@ repeat:
        if (unlikely(err))
                goto out;
 
-       llen = (nr_pages << PAGE_SHIFT) - work->pageofs;
-
-       if (z_erofs_vle_workgrp_fmt(grp) == Z_EROFS_VLE_WORKGRP_FMT_PLAIN) {
-               err = z_erofs_vle_plain_copy(compressed_pages, clusterpages,
-                                            pages, nr_pages, work->pageofs);
-               goto out;
-       }
-
-       if (llen > grp->llen)
-               llen = grp->llen;
-
-       err = z_erofs_vle_unzip_fast_percpu(compressed_pages, clusterpages,
-                                           pages, llen, work->pageofs);
-       if (err != -ENOTSUPP)
-               goto out;
-
-       if (sparsemem_pages >= nr_pages)
-               goto skip_allocpage;
-
-       for (i = 0; i < nr_pages; ++i) {
-               if (pages[i])
-                       continue;
-
-               pages[i] = __stagingpage_alloc(page_pool, GFP_NOFS);
-       }
-
-skip_allocpage:
-       vout = erofs_vmap(pages, nr_pages);
-       if (!vout) {
-               err = -ENOMEM;
-               goto out;
+       if (nr_pages << PAGE_SHIFT >= work->pageofs + grp->llen) {
+               outputsize = grp->llen;
+               partial = !(grp->flags & Z_EROFS_VLE_WORKGRP_FULL_LENGTH);
+       } else {
+               outputsize = (nr_pages << PAGE_SHIFT) - work->pageofs;
+               partial = true;
        }
 
-       err = z_erofs_vle_unzip_vmap(compressed_pages, clusterpages, vout,
-                                    llen, work->pageofs, overlapped);
-
-       erofs_vunmap(vout, nr_pages);
+       if (z_erofs_vle_workgrp_fmt(grp) == Z_EROFS_VLE_WORKGRP_FMT_PLAIN)
+               algorithm = Z_EROFS_COMPRESSION_SHIFTED;
+       else
+               algorithm = Z_EROFS_COMPRESSION_LZ4;
+
+       err = z_erofs_decompress(&(struct z_erofs_decompress_req) {
+                                       .sb = sb,
+                                       .in = compressed_pages,
+                                       .out = pages,
+                                       .pageofs_out = work->pageofs,
+                                       .inputsize = PAGE_SIZE,
+                                       .outputsize = outputsize,
+                                       .alg = algorithm,
+                                       .inplace_io = overlapped,
+                                       .partial_decoding = partial
+                                }, page_pool);
 
 out:
        /* must handle all compressed pages before endding pages */
@@ -1056,7 +1046,7 @@ out:
                        continue;
 
                /* recycle all individual staging pages */
-               (void)z_erofs_gather_if_stagingpage(page_pool, page);
+               (void)z_erofs_put_stagingpage(page_pool, page);
 
                WRITE_ONCE(compressed_pages[i], NULL);
        }
@@ -1069,7 +1059,7 @@ out:
                DBG_BUGON(!page->mapping);
 
                /* recycle all individual staging pages */
-               if (z_erofs_gather_if_stagingpage(page_pool, page))
+               if (z_erofs_put_stagingpage(page_pool, page))
                        continue;
 
                if (unlikely(err < 0))
@@ -1273,8 +1263,7 @@ jobqueue_init(struct super_block *sb,
                goto out;
        }
 
-       iosb = kvzalloc(sizeof(struct z_erofs_vle_unzip_io_sb),
-                       GFP_KERNEL | __GFP_NOFAIL);
+       iosb = kvzalloc(sizeof(*iosb), GFP_KERNEL | __GFP_NOFAIL);
        DBG_BUGON(!iosb);
 
        /* initialize fields in the allocated descriptor */
@@ -1600,289 +1589,3 @@ const struct address_space_operations z_erofs_vle_normalaccess_aops = {
        .readpages = z_erofs_vle_normalaccess_readpages,
 };
 
-/*
- * Variable-sized Logical Extent (Fixed Physical Cluster) Compression Mode
- * ---
- * VLE compression mode attempts to compress a number of logical data into
- * a physical cluster with a fixed size.
- * VLE compression mode uses "struct z_erofs_vle_decompressed_index".
- */
-#define __vle_cluster_advise(x, bit, bits) \
-       ((le16_to_cpu(x) >> (bit)) & ((1 << (bits)) - 1))
-
-#define __vle_cluster_type(advise) __vle_cluster_advise(advise, \
-       Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT, Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS)
-
-#define vle_cluster_type(di)   \
-       __vle_cluster_type((di)->di_advise)
-
-static int
-vle_decompressed_index_clusterofs(unsigned int *clusterofs,
-                                 unsigned int clustersize,
-                                 struct z_erofs_vle_decompressed_index *di)
-{
-       switch (vle_cluster_type(di)) {
-       case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
-               *clusterofs = clustersize;
-               break;
-       case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN:
-       case Z_EROFS_VLE_CLUSTER_TYPE_HEAD:
-               *clusterofs = le16_to_cpu(di->di_clusterofs);
-               break;
-       default:
-               DBG_BUGON(1);
-               return -EIO;
-       }
-       return 0;
-}
-
-static inline erofs_blk_t
-vle_extent_blkaddr(struct inode *inode, pgoff_t index)
-{
-       struct erofs_sb_info *sbi = EROFS_I_SB(inode);
-       struct erofs_vnode *vi = EROFS_V(inode);
-
-       unsigned int ofs = Z_EROFS_VLE_EXTENT_ALIGN(vi->inode_isize +
-               vi->xattr_isize) + sizeof(struct erofs_extent_header) +
-               index * sizeof(struct z_erofs_vle_decompressed_index);
-
-       return erofs_blknr(iloc(sbi, vi->nid) + ofs);
-}
-
-static inline unsigned int
-vle_extent_blkoff(struct inode *inode, pgoff_t index)
-{
-       struct erofs_sb_info *sbi = EROFS_I_SB(inode);
-       struct erofs_vnode *vi = EROFS_V(inode);
-
-       unsigned int ofs = Z_EROFS_VLE_EXTENT_ALIGN(vi->inode_isize +
-               vi->xattr_isize) + sizeof(struct erofs_extent_header) +
-               index * sizeof(struct z_erofs_vle_decompressed_index);
-
-       return erofs_blkoff(iloc(sbi, vi->nid) + ofs);
-}
-
-struct vle_map_blocks_iter_ctx {
-       struct inode *inode;
-       struct super_block *sb;
-       unsigned int clusterbits;
-
-       struct page **mpage_ret;
-       void **kaddr_ret;
-};
-
-static int
-vle_get_logical_extent_head(const struct vle_map_blocks_iter_ctx *ctx,
-                           unsigned int lcn,   /* logical cluster number */
-                           unsigned long long *ofs,
-                           erofs_blk_t *pblk,
-                           unsigned int *flags)
-{
-       const unsigned int clustersize = 1 << ctx->clusterbits;
-       const erofs_blk_t mblk = vle_extent_blkaddr(ctx->inode, lcn);
-       struct page *mpage = *ctx->mpage_ret;   /* extent metapage */
-
-       struct z_erofs_vle_decompressed_index *di;
-       unsigned int cluster_type, delta0;
-
-       if (mpage->index != mblk) {
-               kunmap_atomic(*ctx->kaddr_ret);
-               unlock_page(mpage);
-               put_page(mpage);
-
-               mpage = erofs_get_meta_page(ctx->sb, mblk, false);
-               if (IS_ERR(mpage)) {
-                       *ctx->mpage_ret = NULL;
-                       return PTR_ERR(mpage);
-               }
-               *ctx->mpage_ret = mpage;
-               *ctx->kaddr_ret = kmap_atomic(mpage);
-       }
-
-       di = *ctx->kaddr_ret + vle_extent_blkoff(ctx->inode, lcn);
-
-       cluster_type = vle_cluster_type(di);
-       switch (cluster_type) {
-       case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
-               delta0 = le16_to_cpu(di->di_u.delta[0]);
-               if (unlikely(!delta0 || delta0 > lcn)) {
-                       errln("invalid NONHEAD dl0 %u at lcn %u of nid %llu",
-                             delta0, lcn, EROFS_V(ctx->inode)->nid);
-                       DBG_BUGON(1);
-                       return -EIO;
-               }
-               return vle_get_logical_extent_head(ctx,
-                       lcn - delta0, ofs, pblk, flags);
-       case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN:
-               *flags ^= EROFS_MAP_ZIPPED;
-               /* fallthrough */
-       case Z_EROFS_VLE_CLUSTER_TYPE_HEAD:
-               /* clustersize should be a power of two */
-               *ofs = ((u64)lcn << ctx->clusterbits) +
-                       (le16_to_cpu(di->di_clusterofs) & (clustersize - 1));
-               *pblk = le32_to_cpu(di->di_u.blkaddr);
-               break;
-       default:
-               errln("unknown cluster type %u at lcn %u of nid %llu",
-                     cluster_type, lcn, EROFS_V(ctx->inode)->nid);
-               DBG_BUGON(1);
-               return -EIO;
-       }
-       return 0;
-}
-
-int z_erofs_map_blocks_iter(struct inode *inode,
-                           struct erofs_map_blocks *map,
-                           int flags)
-{
-       void *kaddr;
-       const struct vle_map_blocks_iter_ctx ctx = {
-               .inode = inode,
-               .sb = inode->i_sb,
-               .clusterbits = EROFS_I_SB(inode)->clusterbits,
-               .mpage_ret = &map->mpage,
-               .kaddr_ret = &kaddr
-       };
-       const unsigned int clustersize = 1 << ctx.clusterbits;
-       /* if both m_(l,p)len are 0, regularize l_lblk, l_lofs, etc... */
-       const bool initial = !map->m_llen;
-
-       /* logicial extent (start, end) offset */
-       unsigned long long ofs, end;
-       unsigned int lcn;
-       u32 ofs_rem;
-
-       /* initialize `pblk' to keep gcc from printing foolish warnings */
-       erofs_blk_t mblk, pblk = 0;
-       struct page *mpage = map->mpage;
-       struct z_erofs_vle_decompressed_index *di;
-       unsigned int cluster_type, logical_cluster_ofs;
-       int err = 0;
-
-       trace_z_erofs_map_blocks_iter_enter(inode, map, flags);
-
-       /* when trying to read beyond EOF, leave it unmapped */
-       if (unlikely(map->m_la >= inode->i_size)) {
-               DBG_BUGON(!initial);
-               map->m_llen = map->m_la + 1 - inode->i_size;
-               map->m_la = inode->i_size;
-               map->m_flags = 0;
-               goto out;
-       }
-
-       debugln("%s, m_la %llu m_llen %llu --- start", __func__,
-               map->m_la, map->m_llen);
-
-       ofs = map->m_la + map->m_llen;
-
-       /* clustersize should be power of two */
-       lcn = ofs >> ctx.clusterbits;
-       ofs_rem = ofs & (clustersize - 1);
-
-       mblk = vle_extent_blkaddr(inode, lcn);
-
-       if (!mpage || mpage->index != mblk) {
-               if (mpage)
-                       put_page(mpage);
-
-               mpage = erofs_get_meta_page(ctx.sb, mblk, false);
-               if (IS_ERR(mpage)) {
-                       err = PTR_ERR(mpage);
-                       goto out;
-               }
-               map->mpage = mpage;
-       } else {
-               lock_page(mpage);
-               DBG_BUGON(!PageUptodate(mpage));
-       }
-
-       kaddr = kmap_atomic(mpage);
-       di = kaddr + vle_extent_blkoff(inode, lcn);
-
-       debugln("%s, lcn %u mblk %u e_blkoff %u", __func__, lcn,
-               mblk, vle_extent_blkoff(inode, lcn));
-
-       err = vle_decompressed_index_clusterofs(&logical_cluster_ofs,
-                                               clustersize, di);
-       if (unlikely(err))
-               goto unmap_out;
-
-       if (!initial) {
-               /* [walking mode] 'map' has been already initialized */
-               map->m_llen += logical_cluster_ofs;
-               goto unmap_out;
-       }
-
-       /* by default, compressed */
-       map->m_flags |= EROFS_MAP_ZIPPED;
-
-       end = ((u64)lcn + 1) * clustersize;
-
-       cluster_type = vle_cluster_type(di);
-
-       switch (cluster_type) {
-       case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN:
-               if (ofs_rem >= logical_cluster_ofs)
-                       map->m_flags ^= EROFS_MAP_ZIPPED;
-               /* fallthrough */
-       case Z_EROFS_VLE_CLUSTER_TYPE_HEAD:
-               if (ofs_rem == logical_cluster_ofs) {
-                       pblk = le32_to_cpu(di->di_u.blkaddr);
-                       goto exact_hitted;
-               }
-
-               if (ofs_rem > logical_cluster_ofs) {
-                       ofs = (u64)lcn * clustersize | logical_cluster_ofs;
-                       pblk = le32_to_cpu(di->di_u.blkaddr);
-                       break;
-               }
-
-               /* logical cluster number should be >= 1 */
-               if (unlikely(!lcn)) {
-                       errln("invalid logical cluster 0 at nid %llu",
-                             EROFS_V(inode)->nid);
-                       err = -EIO;
-                       goto unmap_out;
-               }
-               end = ((u64)lcn-- * clustersize) | logical_cluster_ofs;
-               /* fallthrough */
-       case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
-               /* get the correspoinding first chunk */
-               err = vle_get_logical_extent_head(&ctx, lcn, &ofs,
-                                                 &pblk, &map->m_flags);
-               mpage = map->mpage;
-
-               if (unlikely(err)) {
-                       if (mpage)
-                               goto unmap_out;
-                       goto out;
-               }
-               break;
-       default:
-               errln("unknown cluster type %u at offset %llu of nid %llu",
-                     cluster_type, ofs, EROFS_V(inode)->nid);
-               err = -EIO;
-               goto unmap_out;
-       }
-
-       map->m_la = ofs;
-exact_hitted:
-       map->m_llen = end - ofs;
-       map->m_plen = clustersize;
-       map->m_pa = blknr_to_addr(pblk);
-       map->m_flags |= EROFS_MAP_MAPPED;
-unmap_out:
-       kunmap_atomic(kaddr);
-       unlock_page(mpage);
-out:
-       debugln("%s, m_la %llu m_pa %llu m_llen %llu m_plen %llu m_flags 0%o",
-               __func__, map->m_la, map->m_pa,
-               map->m_llen, map->m_plen, map->m_flags);
-
-       trace_z_erofs_map_blocks_iter_exit(inode, map, flags, err);
-
-       /* aggressively BUG_ON iff CONFIG_EROFS_FS_DEBUG is on */
-       DBG_BUGON(err < 0 && err != -ENOMEM);
-       return err;
-}
-
index 517e5ce8c5e98d3b723ab7762f48980fdf69570a..ab509d75aefd4e5bb65d6bceb5a9c8335fb46e59 100644 (file)
 #include "internal.h"
 #include "unzip_pagevec.h"
 
-/*
- *  - 0x5A110C8D ('sallocated', Z_EROFS_MAPPING_STAGING) -
- * used for temporary allocated pages (via erofs_allocpage),
- * in order to seperate those from NULL mapping (eg. truncated pages)
- */
-#define Z_EROFS_MAPPING_STAGING                ((void *)0x5A110C8D)
-
-#define z_erofs_is_stagingpage(page)   \
-       ((page)->mapping == Z_EROFS_MAPPING_STAGING)
-
-static inline bool z_erofs_gather_if_stagingpage(struct list_head *page_pool,
-                                                struct page *page)
-{
-       if (z_erofs_is_stagingpage(page)) {
-               list_add(&page->lru, page_pool);
-               return true;
-       }
-       return false;
-}
+#define Z_EROFS_NR_INLINE_PAGEVECS      3
 
 /*
  * Structure fields follow one of the following exclusion rules.
@@ -44,8 +26,6 @@ static inline bool z_erofs_gather_if_stagingpage(struct list_head *page_pool,
  *
  */
 
-#define Z_EROFS_VLE_INLINE_PAGEVECS     3
-
 struct z_erofs_vle_work {
        struct mutex lock;
 
@@ -58,7 +38,7 @@ struct z_erofs_vle_work {
 
        union {
                /* L: pagevec */
-               erofs_vtptr_t pagevec[Z_EROFS_VLE_INLINE_PAGEVECS];
+               erofs_vtptr_t pagevec[Z_EROFS_NR_INLINE_PAGEVECS];
                struct rcu_head rcu;
        };
 };
@@ -66,6 +46,7 @@ struct z_erofs_vle_work {
 #define Z_EROFS_VLE_WORKGRP_FMT_PLAIN        0
 #define Z_EROFS_VLE_WORKGRP_FMT_LZ4          1
 #define Z_EROFS_VLE_WORKGRP_FMT_MASK         1
+#define Z_EROFS_VLE_WORKGRP_FULL_LENGTH      2
 
 typedef void *z_erofs_vle_owned_workgrp_t;
 
@@ -147,7 +128,7 @@ static inline unsigned z_erofs_onlinepage_index(struct page *page)
 {
        union z_erofs_onlinepage_converter u;
 
-       BUG_ON(!PagePrivate(page));
+       DBG_BUGON(!PagePrivate(page));
        u.v = &page_private(page);
 
        return atomic_read(u.o) >> Z_EROFS_ONLINEPAGE_INDEX_SHIFT;
@@ -179,7 +160,7 @@ repeat:
                if (!index)
                        return;
 
-               BUG_ON(id != index);
+               DBG_BUGON(id != index);
        }
 
        v = (index << Z_EROFS_ONLINEPAGE_INDEX_SHIFT) |
@@ -193,7 +174,7 @@ static inline void z_erofs_onlinepage_endio(struct page *page)
        union z_erofs_onlinepage_converter u;
        unsigned v;
 
-       BUG_ON(!PagePrivate(page));
+       DBG_BUGON(!PagePrivate(page));
        u.v = &page_private(page);
 
        v = atomic_dec_return(u.o);
@@ -211,18 +192,5 @@ static inline void z_erofs_onlinepage_endio(struct page *page)
        min_t(unsigned int, THREAD_SIZE / 8 / sizeof(struct page *), 96U)
 #define Z_EROFS_VLE_VMAP_GLOBAL_PAGES  2048
 
-/* unzip_vle_lz4.c */
-int z_erofs_vle_plain_copy(struct page **compressed_pages,
-                          unsigned int clusterpages, struct page **pages,
-                          unsigned int nr_pages, unsigned short pageofs);
-int z_erofs_vle_unzip_fast_percpu(struct page **compressed_pages,
-                                 unsigned int clusterpages,
-                                 struct page **pages, unsigned int outlen,
-                                 unsigned short pageofs);
-int z_erofs_vle_unzip_vmap(struct page **compressed_pages,
-                          unsigned int clusterpages,
-                          void *vaddr, unsigned int llen,
-                          unsigned short pageofs, bool overlapped);
-
 #endif
 
diff --git a/drivers/staging/erofs/unzip_vle_lz4.c b/drivers/staging/erofs/unzip_vle_lz4.c
deleted file mode 100644 (file)
index 0daac9b..0000000
+++ /dev/null
@@ -1,229 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * linux/drivers/staging/erofs/unzip_vle_lz4.c
- *
- * Copyright (C) 2018 HUAWEI, Inc.
- *             http://www.huawei.com/
- * Created by Gao Xiang <gaoxiang25@huawei.com>
- *
- * This file is subject to the terms and conditions of the GNU General Public
- * License.  See the file COPYING in the main directory of the Linux
- * distribution for more details.
- */
-#include "unzip_vle.h"
-#include <linux/lz4.h>
-
-static int z_erofs_unzip_lz4(void *in, void *out, size_t inlen, size_t outlen)
-{
-       int ret = LZ4_decompress_safe_partial(in, out, inlen, outlen, outlen);
-
-       if (ret >= 0)
-               return ret;
-
-       /*
-        * LZ4_decompress_safe_partial will return an error code
-        * (< 0) if decompression failed
-        */
-       errln("%s, failed to decompress, in[%p, %zu] outlen[%p, %zu]",
-             __func__, in, inlen, out, outlen);
-       WARN_ON(1);
-       print_hex_dump(KERN_DEBUG, "raw data [in]: ", DUMP_PREFIX_OFFSET,
-                      16, 1, in, inlen, true);
-       print_hex_dump(KERN_DEBUG, "raw data [out]: ", DUMP_PREFIX_OFFSET,
-                      16, 1, out, outlen, true);
-       return -EIO;
-}
-
-#if Z_EROFS_CLUSTER_MAX_PAGES > Z_EROFS_VLE_INLINE_PAGEVECS
-#define EROFS_PERCPU_NR_PAGES   Z_EROFS_CLUSTER_MAX_PAGES
-#else
-#define EROFS_PERCPU_NR_PAGES   Z_EROFS_VLE_INLINE_PAGEVECS
-#endif
-
-static struct {
-       char data[PAGE_SIZE * EROFS_PERCPU_NR_PAGES];
-} erofs_pcpubuf[NR_CPUS];
-
-int z_erofs_vle_plain_copy(struct page **compressed_pages,
-                          unsigned int clusterpages,
-                          struct page **pages,
-                          unsigned int nr_pages,
-                          unsigned short pageofs)
-{
-       unsigned int i, j;
-       void *src = NULL;
-       const unsigned int righthalf = PAGE_SIZE - pageofs;
-       char *percpu_data;
-       bool mirrored[Z_EROFS_CLUSTER_MAX_PAGES] = { 0 };
-
-       preempt_disable();
-       percpu_data = erofs_pcpubuf[smp_processor_id()].data;
-
-       j = 0;
-       for (i = 0; i < nr_pages; j = i++) {
-               struct page *page = pages[i];
-               void *dst;
-
-               if (!page) {
-                       if (src) {
-                               if (!mirrored[j])
-                                       kunmap_atomic(src);
-                               src = NULL;
-                       }
-                       continue;
-               }
-
-               dst = kmap_atomic(page);
-
-               for (; j < clusterpages; ++j) {
-                       if (compressed_pages[j] != page)
-                               continue;
-
-                       DBG_BUGON(mirrored[j]);
-                       memcpy(percpu_data + j * PAGE_SIZE, dst, PAGE_SIZE);
-                       mirrored[j] = true;
-                       break;
-               }
-
-               if (i) {
-                       if (!src)
-                               src = mirrored[i - 1] ?
-                                       percpu_data + (i - 1) * PAGE_SIZE :
-                                       kmap_atomic(compressed_pages[i - 1]);
-
-                       memcpy(dst, src + righthalf, pageofs);
-
-                       if (!mirrored[i - 1])
-                               kunmap_atomic(src);
-
-                       if (unlikely(i >= clusterpages)) {
-                               kunmap_atomic(dst);
-                               break;
-                       }
-               }
-
-               if (!righthalf) {
-                       src = NULL;
-               } else {
-                       src = mirrored[i] ? percpu_data + i * PAGE_SIZE :
-                               kmap_atomic(compressed_pages[i]);
-
-                       memcpy(dst + pageofs, src, righthalf);
-               }
-
-               kunmap_atomic(dst);
-       }
-
-       if (src && !mirrored[j])
-               kunmap_atomic(src);
-
-       preempt_enable();
-       return 0;
-}
-
-int z_erofs_vle_unzip_fast_percpu(struct page **compressed_pages,
-                                 unsigned int clusterpages,
-                                 struct page **pages,
-                                 unsigned int outlen,
-                                 unsigned short pageofs)
-{
-       void *vin, *vout;
-       unsigned int nr_pages, i, j;
-       int ret;
-
-       if (outlen + pageofs > EROFS_PERCPU_NR_PAGES * PAGE_SIZE)
-               return -ENOTSUPP;
-
-       nr_pages = DIV_ROUND_UP(outlen + pageofs, PAGE_SIZE);
-
-       if (clusterpages == 1) {
-               vin = kmap_atomic(compressed_pages[0]);
-       } else {
-               vin = erofs_vmap(compressed_pages, clusterpages);
-               if (!vin)
-                       return -ENOMEM;
-       }
-
-       preempt_disable();
-       vout = erofs_pcpubuf[smp_processor_id()].data;
-
-       ret = z_erofs_unzip_lz4(vin, vout + pageofs,
-                               clusterpages * PAGE_SIZE, outlen);
-
-       if (ret < 0)
-               goto out;
-       ret = 0;
-
-       for (i = 0; i < nr_pages; ++i) {
-               j = min((unsigned int)PAGE_SIZE - pageofs, outlen);
-
-               if (pages[i]) {
-                       if (clusterpages == 1 &&
-                           pages[i] == compressed_pages[0]) {
-                               memcpy(vin + pageofs, vout + pageofs, j);
-                       } else {
-                               void *dst = kmap_atomic(pages[i]);
-
-                               memcpy(dst + pageofs, vout + pageofs, j);
-                               kunmap_atomic(dst);
-                       }
-               }
-               vout += PAGE_SIZE;
-               outlen -= j;
-               pageofs = 0;
-       }
-
-out:
-       preempt_enable();
-
-       if (clusterpages == 1)
-               kunmap_atomic(vin);
-       else
-               erofs_vunmap(vin, clusterpages);
-
-       return ret;
-}
-
-int z_erofs_vle_unzip_vmap(struct page **compressed_pages,
-                          unsigned int clusterpages,
-                          void *vout,
-                          unsigned int llen,
-                          unsigned short pageofs,
-                          bool overlapped)
-{
-       void *vin;
-       unsigned int i;
-       int ret;
-
-       if (overlapped) {
-               preempt_disable();
-               vin = erofs_pcpubuf[smp_processor_id()].data;
-
-               for (i = 0; i < clusterpages; ++i) {
-                       void *t = kmap_atomic(compressed_pages[i]);
-
-                       memcpy(vin + PAGE_SIZE * i, t, PAGE_SIZE);
-                       kunmap_atomic(t);
-               }
-       } else if (clusterpages == 1) {
-               vin = kmap_atomic(compressed_pages[0]);
-       } else {
-               vin = erofs_vmap(compressed_pages, clusterpages);
-       }
-
-       ret = z_erofs_unzip_lz4(vin, vout + pageofs,
-                               clusterpages * PAGE_SIZE, llen);
-       if (ret > 0)
-               ret = 0;
-
-       if (!overlapped) {
-               if (clusterpages == 1)
-                       kunmap_atomic(vin);
-               else
-                       erofs_vunmap(vin, clusterpages);
-       } else {
-               preempt_enable();
-       }
-       return ret;
-}
-
index 3e7d30b6de1d20fa8abaf9120a2547b35f54e007..4bbd3bf34acd9d52f8d58fab595a0ea9e77e0352 100644 (file)
@@ -27,6 +27,18 @@ struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp)
        return page;
 }
 
+#if (EROFS_PCPUBUF_NR_PAGES > 0)
+static struct {
+       u8 data[PAGE_SIZE * EROFS_PCPUBUF_NR_PAGES];
+} ____cacheline_aligned_in_smp erofs_pcpubuf[NR_CPUS];
+
+void *erofs_get_pcpubuf(unsigned int pagenr)
+{
+       preempt_disable();
+       return &erofs_pcpubuf[smp_processor_id()].data[pagenr * PAGE_SIZE];
+}
+#endif
+
 /* global shrink count (for all mounted EROFS instances) */
 static atomic_long_t erofs_global_shrink_cnt;
 
diff --git a/drivers/staging/erofs/zmap.c b/drivers/staging/erofs/zmap.c
new file mode 100644 (file)
index 0000000..9c0bd65
--- /dev/null
@@ -0,0 +1,463 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * linux/drivers/staging/erofs/zmap.c
+ *
+ * Copyright (C) 2018-2019 HUAWEI, Inc.
+ *             http://www.huawei.com/
+ * Created by Gao Xiang <gaoxiang25@huawei.com>
+ */
+#include "internal.h"
+#include <asm/unaligned.h>
+#include <trace/events/erofs.h>
+
+int z_erofs_fill_inode(struct inode *inode)
+{
+       struct erofs_vnode *const vi = EROFS_V(inode);
+       struct super_block *const sb = inode->i_sb;
+
+       if (vi->datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY) {
+               vi->z_advise = 0;
+               vi->z_algorithmtype[0] = 0;
+               vi->z_algorithmtype[1] = 0;
+               vi->z_logical_clusterbits = EROFS_SB(sb)->clusterbits;
+               vi->z_physical_clusterbits[0] = vi->z_logical_clusterbits;
+               vi->z_physical_clusterbits[1] = vi->z_logical_clusterbits;
+               set_bit(EROFS_V_Z_INITED_BIT, &vi->flags);
+       }
+
+       inode->i_mapping->a_ops = &z_erofs_vle_normalaccess_aops;
+       return 0;
+}
+
+static int fill_inode_lazy(struct inode *inode)
+{
+       struct erofs_vnode *const vi = EROFS_V(inode);
+       struct super_block *const sb = inode->i_sb;
+       int err;
+       erofs_off_t pos;
+       struct page *page;
+       void *kaddr;
+       struct z_erofs_map_header *h;
+
+       if (test_bit(EROFS_V_Z_INITED_BIT, &vi->flags))
+               return 0;
+
+       if (wait_on_bit_lock(&vi->flags, EROFS_V_BL_Z_BIT, TASK_KILLABLE))
+               return -ERESTARTSYS;
+
+       err = 0;
+       if (test_bit(EROFS_V_Z_INITED_BIT, &vi->flags))
+               goto out_unlock;
+
+       DBG_BUGON(vi->datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY);
+
+       pos = ALIGN(iloc(EROFS_SB(sb), vi->nid) + vi->inode_isize +
+                   vi->xattr_isize, 8);
+       page = erofs_get_meta_page(sb, erofs_blknr(pos), false);
+       if (IS_ERR(page)) {
+               err = PTR_ERR(page);
+               goto out_unlock;
+       }
+
+       kaddr = kmap_atomic(page);
+
+       h = kaddr + erofs_blkoff(pos);
+       vi->z_advise = le16_to_cpu(h->h_advise);
+       vi->z_algorithmtype[0] = h->h_algorithmtype & 15;
+       vi->z_algorithmtype[1] = h->h_algorithmtype >> 4;
+
+       if (vi->z_algorithmtype[0] >= Z_EROFS_COMPRESSION_MAX) {
+               errln("unknown compression format %u for nid %llu, please upgrade kernel",
+                     vi->z_algorithmtype[0], vi->nid);
+               err = -ENOTSUPP;
+               goto unmap_done;
+       }
+
+       vi->z_logical_clusterbits = LOG_BLOCK_SIZE + (h->h_clusterbits & 7);
+       vi->z_physical_clusterbits[0] = vi->z_logical_clusterbits +
+                                       ((h->h_clusterbits >> 3) & 3);
+
+       if (vi->z_physical_clusterbits[0] != LOG_BLOCK_SIZE) {
+               errln("unsupported physical clusterbits %u for nid %llu, please upgrade kernel",
+                     vi->z_physical_clusterbits[0], vi->nid);
+               err = -ENOTSUPP;
+               goto unmap_done;
+       }
+
+       vi->z_physical_clusterbits[1] = vi->z_logical_clusterbits +
+                                       ((h->h_clusterbits >> 5) & 7);
+unmap_done:
+       kunmap_atomic(kaddr);
+       unlock_page(page);
+       put_page(page);
+
+       set_bit(EROFS_V_Z_INITED_BIT, &vi->flags);
+out_unlock:
+       clear_and_wake_up_bit(EROFS_V_BL_Z_BIT, &vi->flags);
+       return err;
+}
+
+struct z_erofs_maprecorder {
+       struct inode *inode;
+       struct erofs_map_blocks *map;
+       void *kaddr;
+
+       unsigned long lcn;
+       /* compression extent information gathered */
+       u8  type;
+       u16 clusterofs;
+       u16 delta[2];
+       erofs_blk_t pblk;
+};
+
+static int z_erofs_reload_indexes(struct z_erofs_maprecorder *m,
+                                 erofs_blk_t eblk)
+{
+       struct super_block *const sb = m->inode->i_sb;
+       struct erofs_map_blocks *const map = m->map;
+       struct page *mpage = map->mpage;
+
+       if (mpage) {
+               if (mpage->index == eblk) {
+                       if (!m->kaddr)
+                               m->kaddr = kmap_atomic(mpage);
+                       return 0;
+               }
+
+               if (m->kaddr) {
+                       kunmap_atomic(m->kaddr);
+                       m->kaddr = NULL;
+               }
+               put_page(mpage);
+       }
+
+       mpage = erofs_get_meta_page(sb, eblk, false);
+       if (IS_ERR(mpage)) {
+               map->mpage = NULL;
+               return PTR_ERR(mpage);
+       }
+       m->kaddr = kmap_atomic(mpage);
+       unlock_page(mpage);
+       map->mpage = mpage;
+       return 0;
+}
+
+static int vle_legacy_load_cluster_from_disk(struct z_erofs_maprecorder *m,
+                                            unsigned long lcn)
+{
+       struct inode *const inode = m->inode;
+       struct erofs_vnode *const vi = EROFS_V(inode);
+       const erofs_off_t ibase = iloc(EROFS_I_SB(inode), vi->nid);
+       const erofs_off_t pos =
+               Z_EROFS_VLE_LEGACY_INDEX_ALIGN(ibase + vi->inode_isize +
+                                              vi->xattr_isize) +
+               lcn * sizeof(struct z_erofs_vle_decompressed_index);
+       struct z_erofs_vle_decompressed_index *di;
+       unsigned int advise, type;
+       int err;
+
+       err = z_erofs_reload_indexes(m, erofs_blknr(pos));
+       if (err)
+               return err;
+
+       m->lcn = lcn;
+       di = m->kaddr + erofs_blkoff(pos);
+
+       advise = le16_to_cpu(di->di_advise);
+       type = (advise >> Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT) &
+               ((1 << Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) - 1);
+       switch (type) {
+       case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
+               m->clusterofs = 1 << vi->z_logical_clusterbits;
+               m->delta[0] = le16_to_cpu(di->di_u.delta[0]);
+               m->delta[1] = le16_to_cpu(di->di_u.delta[1]);
+               break;
+       case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN:
+       case Z_EROFS_VLE_CLUSTER_TYPE_HEAD:
+               m->clusterofs = le16_to_cpu(di->di_clusterofs);
+               m->pblk = le32_to_cpu(di->di_u.blkaddr);
+               break;
+       default:
+               DBG_BUGON(1);
+               return -EIO;
+       }
+       m->type = type;
+       return 0;
+}
+
+static unsigned int decode_compactedbits(unsigned int lobits,
+                                        unsigned int lomask,
+                                        u8 *in, unsigned int pos, u8 *type)
+{
+       const unsigned int v = get_unaligned_le32(in + pos / 8) >> (pos & 7);
+       const unsigned int lo = v & lomask;
+
+       *type = (v >> lobits) & 3;
+       return lo;
+}
+
+static int unpack_compacted_index(struct z_erofs_maprecorder *m,
+                                 unsigned int amortizedshift,
+                                 unsigned int eofs)
+{
+       struct erofs_vnode *const vi = EROFS_V(m->inode);
+       const unsigned int lclusterbits = vi->z_logical_clusterbits;
+       const unsigned int lomask = (1 << lclusterbits) - 1;
+       unsigned int vcnt, base, lo, encodebits, nblk;
+       int i;
+       u8 *in, type;
+
+       if (1 << amortizedshift == 4)
+               vcnt = 2;
+       else if (1 << amortizedshift == 2 && lclusterbits == 12)
+               vcnt = 16;
+       else
+               return -ENOTSUPP;
+
+       encodebits = ((vcnt << amortizedshift) - sizeof(__le32)) * 8 / vcnt;
+       base = round_down(eofs, vcnt << amortizedshift);
+       in = m->kaddr + base;
+
+       i = (eofs - base) >> amortizedshift;
+
+       lo = decode_compactedbits(lclusterbits, lomask,
+                                 in, encodebits * i, &type);
+       m->type = type;
+       if (type == Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD) {
+               m->clusterofs = 1 << lclusterbits;
+               if (i + 1 != vcnt) {
+                       m->delta[0] = lo;
+                       return 0;
+               }
+               /*
+                * since the last lcluster in the pack is special,
+                * of which lo saves delta[1] rather than delta[0].
+                * Hence, get delta[0] by the previous lcluster indirectly.
+                */
+               lo = decode_compactedbits(lclusterbits, lomask,
+                                         in, encodebits * (i - 1), &type);
+               if (type != Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD)
+                       lo = 0;
+               m->delta[0] = lo + 1;
+               return 0;
+       }
+       m->clusterofs = lo;
+       m->delta[0] = 0;
+       /* figout out blkaddr (pblk) for HEAD lclusters */
+       nblk = 1;
+       while (i > 0) {
+               --i;
+               lo = decode_compactedbits(lclusterbits, lomask,
+                                         in, encodebits * i, &type);
+               if (type == Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD)
+                       i -= lo;
+
+               if (i >= 0)
+                       ++nblk;
+       }
+       in += (vcnt << amortizedshift) - sizeof(__le32);
+       m->pblk = le32_to_cpu(*(__le32 *)in) + nblk;
+       return 0;
+}
+
+static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m,
+                                           unsigned long lcn)
+{
+       struct inode *const inode = m->inode;
+       struct erofs_vnode *const vi = EROFS_V(inode);
+       const unsigned int lclusterbits = vi->z_logical_clusterbits;
+       const erofs_off_t ebase = ALIGN(iloc(EROFS_I_SB(inode), vi->nid) +
+                                       vi->inode_isize + vi->xattr_isize, 8) +
+               sizeof(struct z_erofs_map_header);
+       const unsigned int totalidx = DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ);
+       unsigned int compacted_4b_initial, compacted_2b;
+       unsigned int amortizedshift;
+       erofs_off_t pos;
+       int err;
+
+       if (lclusterbits != 12)
+               return -ENOTSUPP;
+
+       if (lcn >= totalidx)
+               return -EINVAL;
+
+       m->lcn = lcn;
+       /* used to align to 32-byte (compacted_2b) alignment */
+       compacted_4b_initial = (32 - ebase % 32) / 4;
+       if (compacted_4b_initial == 32 / 4)
+               compacted_4b_initial = 0;
+
+       if (vi->z_advise & Z_EROFS_ADVISE_COMPACTED_2B)
+               compacted_2b = rounddown(totalidx - compacted_4b_initial, 16);
+       else
+               compacted_2b = 0;
+
+       pos = ebase;
+       if (lcn < compacted_4b_initial) {
+               amortizedshift = 2;
+               goto out;
+       }
+       pos += compacted_4b_initial * 4;
+       lcn -= compacted_4b_initial;
+
+       if (lcn < compacted_2b) {
+               amortizedshift = 1;
+               goto out;
+       }
+       pos += compacted_2b * 2;
+       lcn -= compacted_2b;
+       amortizedshift = 2;
+out:
+       pos += lcn * (1 << amortizedshift);
+       err = z_erofs_reload_indexes(m, erofs_blknr(pos));
+       if (err)
+               return err;
+       return unpack_compacted_index(m, amortizedshift, erofs_blkoff(pos));
+}
+
+static int vle_load_cluster_from_disk(struct z_erofs_maprecorder *m,
+                                     unsigned int lcn)
+{
+       const unsigned int datamode = EROFS_V(m->inode)->datamode;
+
+       if (datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY)
+               return vle_legacy_load_cluster_from_disk(m, lcn);
+
+       if (datamode == EROFS_INODE_FLAT_COMPRESSION)
+               return compacted_load_cluster_from_disk(m, lcn);
+
+       return -EINVAL;
+}
+
+static int vle_extent_lookback(struct z_erofs_maprecorder *m,
+                              unsigned int lookback_distance)
+{
+       struct erofs_vnode *const vi = EROFS_V(m->inode);
+       struct erofs_map_blocks *const map = m->map;
+       const unsigned int lclusterbits = vi->z_logical_clusterbits;
+       unsigned long lcn = m->lcn;
+       int err;
+
+       if (lcn < lookback_distance) {
+               DBG_BUGON(1);
+               return -EIO;
+       }
+
+       /* load extent head logical cluster if needed */
+       lcn -= lookback_distance;
+       err = vle_load_cluster_from_disk(m, lcn);
+       if (err)
+               return err;
+
+       switch (m->type) {
+       case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
+               return vle_extent_lookback(m, m->delta[0]);
+       case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN:
+               map->m_flags &= ~EROFS_MAP_ZIPPED;
+               /* fallthrough */
+       case Z_EROFS_VLE_CLUSTER_TYPE_HEAD:
+               map->m_la = (lcn << lclusterbits) | m->clusterofs;
+               break;
+       default:
+               errln("unknown type %u at lcn %lu of nid %llu",
+                     m->type, lcn, vi->nid);
+               DBG_BUGON(1);
+               return -EIO;
+       }
+       return 0;
+}
+
+int z_erofs_map_blocks_iter(struct inode *inode,
+                           struct erofs_map_blocks *map,
+                           int flags)
+{
+       struct erofs_vnode *const vi = EROFS_V(inode);
+       struct z_erofs_maprecorder m = {
+               .inode = inode,
+               .map = map,
+       };
+       int err = 0;
+       unsigned int lclusterbits, endoff;
+       unsigned long long ofs, end;
+
+       trace_z_erofs_map_blocks_iter_enter(inode, map, flags);
+
+       /* when trying to read beyond EOF, leave it unmapped */
+       if (unlikely(map->m_la >= inode->i_size)) {
+               map->m_llen = map->m_la + 1 - inode->i_size;
+               map->m_la = inode->i_size;
+               map->m_flags = 0;
+               goto out;
+       }
+
+       err = fill_inode_lazy(inode);
+       if (err)
+               goto out;
+
+       lclusterbits = vi->z_logical_clusterbits;
+       ofs = map->m_la;
+       m.lcn = ofs >> lclusterbits;
+       endoff = ofs & ((1 << lclusterbits) - 1);
+
+       err = vle_load_cluster_from_disk(&m, m.lcn);
+       if (err)
+               goto unmap_out;
+
+       map->m_flags = EROFS_MAP_ZIPPED;        /* by default, compressed */
+       end = (m.lcn + 1ULL) << lclusterbits;
+
+       switch (m.type) {
+       case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN:
+               if (endoff >= m.clusterofs)
+                       map->m_flags &= ~EROFS_MAP_ZIPPED;
+               /* fallthrough */
+       case Z_EROFS_VLE_CLUSTER_TYPE_HEAD:
+               if (endoff >= m.clusterofs) {
+                       map->m_la = (m.lcn << lclusterbits) | m.clusterofs;
+                       break;
+               }
+               /* m.lcn should be >= 1 if endoff < m.clusterofs */
+               if (unlikely(!m.lcn)) {
+                       errln("invalid logical cluster 0 at nid %llu",
+                             vi->nid);
+                       err = -EIO;
+                       goto unmap_out;
+               }
+               end = (m.lcn << lclusterbits) | m.clusterofs;
+               map->m_flags |= EROFS_MAP_FULL_MAPPED;
+               m.delta[0] = 1;
+               /* fallthrough */
+       case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
+               /* get the correspoinding first chunk */
+               err = vle_extent_lookback(&m, m.delta[0]);
+               if (unlikely(err))
+                       goto unmap_out;
+               break;
+       default:
+               errln("unknown type %u at offset %llu of nid %llu",
+                     m.type, ofs, vi->nid);
+               err = -EIO;
+               goto unmap_out;
+       }
+
+       map->m_llen = end - map->m_la;
+       map->m_plen = 1 << lclusterbits;
+       map->m_pa = blknr_to_addr(m.pblk);
+       map->m_flags |= EROFS_MAP_MAPPED;
+
+unmap_out:
+       if (m.kaddr)
+               kunmap_atomic(m.kaddr);
+
+out:
+       debugln("%s, m_la %llu m_pa %llu m_llen %llu m_plen %llu m_flags 0%o",
+               __func__, map->m_la, map->m_pa,
+               map->m_llen, map->m_plen, map->m_flags);
+
+       trace_z_erofs_map_blocks_iter_exit(inode, map, flags, err);
+
+       /* aggressively BUG_ON iff CONFIG_EROFS_FS_DEBUG is on */
+       DBG_BUGON(err < 0 && err != -ENOMEM);
+       return err;
+}
+
index 8bc3d9a877432e30663a869bd90b3bba479bf37f..635a0a7b7dd29b66a010a7d767ea946b6ac865ab 100644 (file)
@@ -14,6 +14,7 @@ if HMS_ANYBUSS_BUS
 config ARCX_ANYBUS_CONTROLLER
        tristate "Arcx Anybus-S Controller"
        depends on OF && GPIOLIB && HAS_IOMEM && REGULATOR
+       select REGMAP_MMIO
        help
          Select this to get support for the Arcx Anybus controller.
          It connects to the SoC via a parallel memory bus, and
index a167fb68e3550ae2035b85aba10731e386e7aae8..2ecffa42e561c22c880d832cade2974b5f9d58ca 100644 (file)
@@ -111,49 +111,31 @@ static void export_reset_1(struct device *dev, bool assert)
  * at a time for now.
  */
 
-static int read_reg_bus(void *context, unsigned int reg,
-                       unsigned int *val)
-{
-       void __iomem *base = context;
-
-       *val = readb(base + reg);
-       return 0;
-}
-
-static int write_reg_bus(void *context, unsigned int reg,
-                        unsigned int val)
-{
-       void __iomem *base = context;
-
-       writeb(val, base + reg);
-       return 0;
-}
+static const struct regmap_config arcx_regmap_cfg = {
+       .reg_bits = 16,
+       .val_bits = 8,
+       .max_register = 0x7ff,
+       .use_single_read = true,
+       .use_single_write = true,
+       /*
+        * single-byte parallel bus accesses are atomic, so don't
+        * require any synchronization.
+        */
+       .disable_locking = true,
+};
 
 static struct regmap *create_parallel_regmap(struct platform_device *pdev,
                                             int idx)
 {
-       struct regmap_config regmap_cfg = {
-               .reg_bits = 11,
-               .val_bits = 8,
-               /*
-                * single-byte parallel bus accesses are atomic, so don't
-                * require any synchronization.
-                */
-               .disable_locking = true,
-               .reg_read = read_reg_bus,
-               .reg_write = write_reg_bus,
-       };
        struct resource *res;
        void __iomem *base;
        struct device *dev = &pdev->dev;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, idx + 1);
-       if (resource_size(res) < (1 << regmap_cfg.reg_bits))
-               return ERR_PTR(-EINVAL);
        base = devm_ioremap_resource(dev, res);
        if (IS_ERR(base))
                return ERR_CAST(base);
-       return devm_regmap_init(dev, NULL, base, &regmap_cfg);
+       return devm_regmap_init_mmio(dev, base, &arcx_regmap_cfg);
 }
 
 static struct anybuss_host *
index 60b85140675ac1d754ec483ae0fe3431c9bae55d..f6f5b92ba9143700e16dbb0056acc021151d9587 100644 (file)
@@ -211,16 +211,16 @@ static ssize_t fieldbus_write(struct file *filp, const char __user *buf,
        return fbdev->write_area(fbdev, buf, size, offset);
 }
 
-static unsigned int fieldbus_poll(struct file *filp, poll_table *wait)
+static __poll_t fieldbus_poll(struct file *filp, poll_table *wait)
 {
        struct fb_open_file *of = filp->private_data;
        struct fieldbus_dev *fbdev = of->fbdev;
-       unsigned int mask = POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM;
+       __poll_t mask = EPOLLIN | EPOLLRDNORM | EPOLLOUT | EPOLLWRNORM;
 
        poll_wait(filp, &fbdev->dc_wq, wait);
        /* data changed ? */
        if (fbdev->dc_event != of->dc_event)
-               mask |= POLLPRI | POLLERR;
+               mask |= EPOLLPRI | EPOLLERR;
        return mask;
 }
 
index 368837cdf281de8c17f93ce6e7c65bf5cbdb8b81..244237bb068a7a77d037c7cea079e0f2c69ba953 100644 (file)
@@ -6,7 +6,7 @@
 config FSL_DPAA2
        bool "Freescale DPAA2 devices"
        depends on FSL_MC_BUS
-       ---help---
+       help
          Build drivers for Freescale DataPath Acceleration
          Architecture (DPAA2) family of SoCs.
 
@@ -14,6 +14,6 @@ config FSL_DPAA2_ETHSW
        tristate "Freescale DPAA2 Ethernet Switch"
        depends on FSL_DPAA2
        depends on NET_SWITCHDEV
-       ---help---
-       Driver for Freescale DPAA2 Ethernet Switch. Select
-       BRIDGE to have support for bridge tools.
+       help
+         Driver for Freescale DPAA2 Ethernet Switch. Select
+         BRIDGE to have support for bridge tools.
index e3c3e427309ab020f082152085a280062d991a04..f73edaf6ce875fedd0197165795c5b3cdf56cb27 100644 (file)
@@ -1086,6 +1086,7 @@ static int port_switchdev_event(struct notifier_block *unused,
                dev_hold(dev);
                break;
        default:
+               kfree(switchdev_work);
                return NOTIFY_DONE;
        }
 
index a445d58fb39998b6f7ee067b91645233bdaa1fda..13179f063a61d8d49245fce10a5e896401db99df 100644 (file)
@@ -702,8 +702,7 @@ static bool gasket_mmap_has_permissions(struct gasket_dev *gasket_dev,
        if ((vma->vm_flags & VM_WRITE) &&
            !gasket_owned_by_current_tgid(&gasket_dev->dev_info)) {
                dev_dbg(gasket_dev->dev,
-                       "Attempting to mmap a region for write without owning "
-                       "device.\n");
+                       "Attempting to mmap a region for write without owning device.\n");
                return false;
        }
 
@@ -1054,8 +1053,7 @@ static int gasket_mmap(struct file *filp, struct vm_area_struct *vma)
        }
        if (bar_index > 0 && is_coherent_region) {
                dev_err(gasket_dev->dev,
-                       "double matching bar and coherent buffers for address "
-                       "0x%lx\n",
+                       "double matching bar and coherent buffers for address 0x%lx\n",
                        raw_offset);
                trace_gasket_mmap_exit(bar_index);
                return -EINVAL;
index 0ca48e688818f345a3e23753f77300ec5a2a8b8a..7ecfba4f2b06bed565df50a128be53ddc1b9d790 100644 (file)
@@ -353,8 +353,7 @@ long gasket_handle_ioctl(struct file *filp, uint cmd, void __user *argp)
                 */
                trace_gasket_ioctl_integer_data(arg);
                dev_dbg(gasket_dev->dev,
-                       "Unknown ioctl cmd=0x%x not caught by "
-                       "gasket_is_supported_ioctl\n",
+                       "Unknown ioctl cmd=0x%x not caught by gasket_is_supported_ioctl\n",
                        cmd);
                retval = -EINVAL;
                break;
index d35c4fb19e280ed78b847ea3c150b1d026eed313..f6d715787da87e4b0a509f2483e7264ed6aa01fb 100644 (file)
@@ -237,8 +237,8 @@ int gasket_page_table_init(struct gasket_page_table **ppg_tbl,
         * hardware register that contains the page table size.
         */
        if (total_entries == ULONG_MAX) {
-               dev_dbg(device, "Error reading page table size. "
-                       "Initializing page table with size 0\n");
+               dev_dbg(device,
+                       "Error reading page table size. Initializing page table with size 0\n");
                total_entries = 0;
        }
 
@@ -491,8 +491,7 @@ static int gasket_perform_mapping(struct gasket_page_table *pg_tbl,
 
                        if (ret <= 0) {
                                dev_err(pg_tbl->device,
-                                       "get user pages failed for addr=0x%lx, "
-                                       "offset=0x%lx [ret=%d]\n",
+                                       "get user pages failed for addr=0x%lx, offset=0x%lx [ret=%d]\n",
                                        page_addr, offset, ret);
                                return ret ? ret : -ENOMEM;
                        }
@@ -779,8 +778,8 @@ static bool gasket_is_extended_dev_addr_bad(struct gasket_page_table *pg_tbl,
 
        if (page_lvl0_idx >= pg_tbl->num_extended_entries) {
                dev_err(pg_tbl->device,
-                       "starting level 0 slot at %lu is too large, max is < "
-                       "%u\n", page_lvl0_idx, pg_tbl->num_extended_entries);
+                       "starting level 0 slot at %lu is too large, max is < %u\n",
+                       page_lvl0_idx, pg_tbl->num_extended_entries);
                return true;
        }
 
@@ -965,8 +964,7 @@ static int gasket_map_extended_pages(struct gasket_page_table *pg_tbl,
        if (ret) {
                dev_addr_end = dev_addr + (num_pages / PAGE_SIZE) - 1;
                dev_err(pg_tbl->device,
-                       "page table slots (%lu,%lu) (@ 0x%lx) to (%lu,%lu) are "
-                       "not available\n",
+                       "page table slots (%lu,%lu) (@ 0x%lx) to (%lu,%lu) are not available\n",
                        gasket_extended_lvl0_page_idx(pg_tbl, dev_addr),
                        dev_addr,
                        gasket_extended_lvl1_page_idx(pg_tbl, dev_addr),
index 2fa88092514d19646ed0e8e80e4444088d89b42a..cebc1d90a1800b1b4a566beefbfc2e29ae5fb74f 100644 (file)
@@ -414,12 +414,6 @@ static int get_results(struct loopback_test *t)
        return 0;
 }
 
-void log_csv_error(int len, int err)
-{
-       fprintf(stderr, "unable to write %d bytes to csv %s\n", len,
-               strerror(err));
-}
-
 int format_output(struct loopback_test *t,
                  struct loopback_results *r,
                  const char *dev_name,
index 70381756a64a804840616e0fd7da720441181ea9..39687139a7d3fc52c4dc9c4da856292c074b4fc3 100644 (file)
 /* Power supply above 3.625 V */
 #define ADIS16203_DIAG_STAT_POWER_HIGH_BIT    1
 
-/* Power supply below 3.15 V */
+/* Power supply below 2.975 V */
 #define ADIS16203_DIAG_STAT_POWER_LOW_BIT     0
 
 /* GLOB_CMD */
@@ -234,7 +234,7 @@ static const char * const adis16203_status_error_msgs[] = {
        [ADIS16203_DIAG_STAT_SPI_FAIL_BIT] = "SPI failure",
        [ADIS16203_DIAG_STAT_FLASH_UPT_BIT] = "Flash update failed",
        [ADIS16203_DIAG_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V",
-       [ADIS16203_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 3.15V",
+       [ADIS16203_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 2.975V",
 };
 
 static const struct adis_data adis16203_data = {
@@ -311,9 +311,17 @@ static int adis16203_remove(struct spi_device *spi)
        return 0;
 }
 
+static const struct of_device_id adis16203_of_match[] = {
+       { .compatible = "adi,adis16203" },
+       { },
+};
+
+MODULE_DEVICE_TABLE(of, adis16203_of_match);
+
 static struct spi_driver adis16203_driver = {
        .driver = {
                .name = "adis16203",
+               .of_match_table = adis16203_of_match,
        },
        .probe = adis16203_probe,
        .remove = adis16203_remove,
index b80e0d248b0f1108b57d6e093b2a455c587cbf18..62f4b3b1b4572661b38d8459fb050bd1871a4b35 100644 (file)
 /* Power supply above 3.625 V */
 #define ADIS16240_DIAG_STAT_POWER_HIGH_BIT     1
 
- /* Power supply below 3.15 V */
+ /* Power supply below 2.225 V */
 #define ADIS16240_DIAG_STAT_POWER_LOW_BIT      0
 
 /* GLOB_CMD */
@@ -435,9 +435,16 @@ static int adis16240_remove(struct spi_device *spi)
        return 0;
 }
 
+static const struct of_device_id adis16240_of_match[] = {
+       { .compatible = "adi,adis16240" },
+       { },
+};
+MODULE_DEVICE_TABLE(of, adis16240_of_match);
+
 static struct spi_driver adis16240_driver = {
        .driver = {
                .name = "adis16240",
+               .of_match_table = adis16240_of_match,
        },
        .probe = adis16240_probe,
        .remove = adis16240_remove,
index 23d9a655a52015df8a4eaab71fb284a554c85a6c..31cd9a12f40fb19ac3964781c720d9a7b7212c0a 100644 (file)
@@ -12,6 +12,9 @@ config AD7816
          Say yes here to build support for Analog Devices AD7816/7/8
          temperature sensors and ADC.
 
+         To compile this driver as a module, choose M here: the
+         module will be called ad7816.
+
 config AD7192
        tristate "Analog Devices AD7190 AD7192 AD7193 AD7195 ADC driver"
        depends on SPI
index 2066241b15b1a81c98e9b3f47869a641e317dad4..af513e003da705581b1e348ecf557c927cfc73f7 100644 (file)
@@ -126,9 +126,22 @@ static const struct spi_device_id adt7316_spi_id[] = {
 
 MODULE_DEVICE_TABLE(spi, adt7316_spi_id);
 
+static const struct of_device_id adt7316_of_spi_match[] = {
+       { .compatible = "adi,adt7316" },
+       { .compatible = "adi,adt7317" },
+       { .compatible = "adi,adt7318" },
+       { .compatible = "adi,adt7516" },
+       { .compatible = "adi,adt7517" },
+       { .compatible = "adi,adt7519" },
+       { }
+};
+
+MODULE_DEVICE_TABLE(of, adt7316_of_spi_match);
+
 static struct spi_driver adt7316_driver = {
        .driver = {
                .name = "adt7316",
+               .of_match_table = adt7316_of_spi_match,
                .pm = ADT7316_PM_OPS,
        },
        .probe = adt7316_spi_probe,
index dc8c25ddb97e7c6b70d064bdb3517c82e9718b38..9cb3d0e42c38cae6e399adb77d104523e381fa77 100644 (file)
@@ -2155,7 +2155,7 @@ int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
                chip->dac_bits = 8;
 
        chip->ldac_pin = devm_gpiod_get_optional(dev, "adi,ldac",
-                                               GPIOD_OUT_LOW);
+                                                GPIOD_OUT_LOW);
        if (IS_ERR(chip->ldac_pin)) {
                ret = PTR_ERR(chip->ldac_pin);
                dev_err(dev, "Failed to request ldac GPIO: %d\n", ret);
index e075244c602ba277dd6441fd956b5d1feb31137a..f4954d85553efa3eb7911408ac400f3b05c51088 100644 (file)
@@ -46,6 +46,9 @@
 #define AD7150_SN0                 22
 #define AD7150_ID                  23
 
+/* AD7150 masks */
+#define AD7150_THRESHTYPE_MSK                  GENMASK(6, 5)
+
 /**
  * struct ad7150_chip_info - instance specific chip data
  * @client: i2c client for this device
@@ -138,7 +141,7 @@ static int ad7150_read_event_config(struct iio_dev *indio_dev,
        if (ret < 0)
                return ret;
 
-       threshtype = (ret >> 5) & 0x03;
+       threshtype = FIELD_GET(AD7150_THRESHTYPE_MSK, ret);
 
        /*check if threshold mode is fixed or adaptive*/
        thrfixed = FIELD_GET(AD7150_CFG_FIX, ret);
@@ -162,7 +165,8 @@ static int ad7150_read_event_config(struct iio_dev *indio_dev,
        return -EINVAL;
 }
 
-/* lock should be held */
+/* state_lock should be held to ensure consistent state*/
+
 static int ad7150_write_event_params(struct iio_dev *indio_dev,
                                     unsigned int chan,
                                     enum iio_event_type type,
@@ -201,16 +205,11 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev,
        ret = i2c_smbus_write_byte_data(chip->client,
                                        ad7150_addresses[chan][4],
                                        sens);
-       if (ret < 0)
+       if (ret)
                return ret;
-
-       ret = i2c_smbus_write_byte_data(chip->client,
+       return i2c_smbus_write_byte_data(chip->client,
                                        ad7150_addresses[chan][5],
                                        timeout);
-       if (ret < 0)
-               return ret;
-
-       return 0;
 }
 
 static int ad7150_write_event_config(struct iio_dev *indio_dev,
@@ -353,8 +352,8 @@ static ssize_t ad7150_show_timeout(struct device *dev,
 
        /* use the event code for consistency reasons */
        int chan = IIO_EVENT_CODE_EXTRACT_CHAN(this_attr->address);
-       int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(this_attr->address)
-                       == IIO_EV_DIR_RISING);
+       int rising = (IIO_EVENT_CODE_EXTRACT_DIR(this_attr->address)
+                     == IIO_EV_DIR_RISING) ? 1 : 0;
 
        switch (IIO_EVENT_CODE_EXTRACT_TYPE(this_attr->address)) {
        case IIO_EV_TYPE_MAG_ADAPTIVE:
@@ -468,30 +467,21 @@ static const struct iio_event_spec ad7150_events[] = {
        },
 };
 
+#define AD7150_CAPACITANCE_CHAN(_chan) {                       \
+               .type = IIO_CAPACITANCE,                        \
+               .indexed = 1,                                   \
+               .channel = _chan,                               \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |  \
+               BIT(IIO_CHAN_INFO_AVERAGE_RAW),                 \
+               .event_spec = ad7150_events,                    \
+               .num_event_specs = ARRAY_SIZE(ad7150_events),   \
+       }
+
 static const struct iio_chan_spec ad7150_channels[] = {
-       {
-               .type = IIO_CAPACITANCE,
-               .indexed = 1,
-               .channel = 0,
-               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
-               BIT(IIO_CHAN_INFO_AVERAGE_RAW),
-               .event_spec = ad7150_events,
-               .num_event_specs = ARRAY_SIZE(ad7150_events),
-       }, {
-               .type = IIO_CAPACITANCE,
-               .indexed = 1,
-               .channel = 1,
-               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
-               BIT(IIO_CHAN_INFO_AVERAGE_RAW),
-               .event_spec = ad7150_events,
-               .num_event_specs = ARRAY_SIZE(ad7150_events),
-       },
+       AD7150_CAPACITANCE_CHAN(0),
+       AD7150_CAPACITANCE_CHAN(1)
 };
 
-/*
- * threshold events
- */
-
 static irqreturn_t ad7150_event_handler(int irq, void *private)
 {
        struct iio_dev *indio_dev = private;
@@ -580,10 +570,6 @@ static const struct iio_info ad7150_info = {
        .write_event_value = &ad7150_write_event_value,
 };
 
-/*
- * device probe and remove
- */
-
 static int ad7150_probe(struct i2c_client *client,
                        const struct i2c_device_id *id)
 {
index 47610d863908b87fdf5662006f8f87ba68c9ada4..21527d84f9408cb737a6157e14d5c09c89f0731a 100644 (file)
@@ -748,9 +748,19 @@ static const struct i2c_device_id ad7746_id[] = {
 
 MODULE_DEVICE_TABLE(i2c, ad7746_id);
 
+static const struct of_device_id ad7746_of_match[] = {
+       { .compatible = "adi,ad7745" },
+       { .compatible = "adi,ad7746" },
+       { .compatible = "adi,ad7747" },
+       { },
+};
+
+MODULE_DEVICE_TABLE(of, ad7746_of_match);
+
 static struct i2c_driver ad7746_driver = {
        .driver = {
                .name = KBUILD_MODNAME,
+               .of_match_table = ad7746_of_match,
        },
        .probe = ad7746_probe,
        .id_table = ad7746_id,
index 6de3cd7363d7f71ccbc80b9cb679dbda38bf71a2..038d6732c3fdbb15ee98c29e04cfef8c7a2091aa 100644 (file)
@@ -521,9 +521,20 @@ static const struct spi_device_id ad9834_id[] = {
 };
 MODULE_DEVICE_TABLE(spi, ad9834_id);
 
+static const struct of_device_id ad9834_of_match[] = {
+       {.compatible = "adi,ad9833"},
+       {.compatible = "adi,ad9834"},
+       {.compatible = "adi,ad9837"},
+       {.compatible = "adi,ad9838"},
+       {}
+};
+
+MODULE_DEVICE_TABLE(of, ad9834_of_match);
+
 static struct spi_driver ad9834_driver = {
        .driver = {
                .name   = "ad9834",
+               .of_match_table = ad9834_of_match
        },
        .probe          = ad9834_probe,
        .remove         = ad9834_remove,
index b6be0bc202f504cbbbdb18bcaaf77622de6d3c80..0c1bd108c38645cc8733549b84b6d3e94b7c513d 100644 (file)
@@ -647,9 +647,6 @@ static int ad2s1210_probe(struct spi_device *spi)
        struct ad2s1210_state *st;
        int ret;
 
-       if (!spi->dev.platform_data)
-               return -EINVAL;
-
        indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
        if (!indio_dev)
                return -ENOMEM;
index 3bb2efd511c4852c95b9ae07f1a705665545ab23..897965359fcbbaf8bef400fede20995791ebf472 100644 (file)
@@ -23,7 +23,7 @@ config KPC2000_CORE
          If unsure, say N.
 
 config KPC2000_SPI
-       tristate "Kaktronics KPC SPI device"
+       tristate "Daktronics KPC SPI device"
        depends on KPC2000 && SPI
        help
          Say Y here if you wish to support the Daktronics KPC PCI
@@ -35,7 +35,7 @@ config KPC2000_SPI
          If unsure, say N.
 
 config KPC2000_I2C
-       tristate "Kaktronics KPC I2C device"
+       tristate "Daktronics KPC I2C device"
        depends on KPC2000 && I2C
        help
          Say Y here if you wish to support the Daktronics KPC PCI
index 1e48e9df132942253c52d8be3b2c6d65c7ab9005..d15ed49807d500dc9df1ed11a846b6ad12f082b6 100644 (file)
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_KPC2000) += kpc2000/
-obj-$(CONFIG_KPC2000_I2C) += kpc_i2c/
-obj-$(CONFIG_KPC2000_SPI) += kpc_spi/
+obj-$(CONFIG_KPC2000_I2C) += kpc2000_i2c.o
+obj-$(CONFIG_KPC2000_SPI) += kpc2000_spi.o
 obj-$(CONFIG_KPC2000_DMA) += kpc_dma/
index 8c7af29fefae595a61744d1e4c9129e0b518fc56..9b5ab37fb3a0f4d90488c4c2d4f6b2a4c875b49d 100644 (file)
@@ -1,8 +1,2 @@
 - the kpc_spi driver doesn't seem to let multiple transactions (to different instances of the core) happen in parallel...
 - The kpc_i2c driver is a hot mess, it should probably be cleaned up a ton.  It functions against current hardware though.
-- pcard->card_num in kp2000_pcie_probe() is a global variable and needs atomic / locking / something better.
-- probe_core_uio() probably needs error handling
-- the loop in kp2000_probe_cores() that uses probe_core_uio() also probably needs error handling
-- would be nice if the AIO fileops in kpc_dma could be made to work
-    - probably want to add a CONFIG_ option to control compilation of the AIO functions
-- if the AIO fileops in kpc_dma start working, next would be making iov_count > 1 work too
index 28ab1e185f9fd1ae54af5e8b9e79eaf77c452de1..c274ad083db6321ae399ae6e301f367c36b33ff8 100644 (file)
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-m := kpc2000.o
-kpc2000-objs += kp2000_module.o  core.o  cell_probe.o  fileops.o
+kpc2000-objs += core.o  cell_probe.o
index e0dba91e7fa8357acc99a184ca5f7b96919349ce..c124a836db27e04c157286a68bc35497131619d8 100644 (file)
@@ -4,7 +4,6 @@
 #include <linux/types.h>
 #include <linux/export.h>
 #include <linux/slab.h>
-#include <asm/io.h>
 #include <linux/io.h>
 #include <linux/io-64-nonatomic-lo-hi.h>
 #include <linux/mfd/core.h>
@@ -25,7 +24,7 @@
  *                                                              D                   C2S DMA Present
  *                                                               DDD                C2S DMA Channel Number    [up to 8 channels]
  *                                                                  II              IRQ Count [0 to 3 IRQs per core]
                                                                     1111111000
*                                                                    1111111000
  *                                                                    IIIIIII       IRQ Base Number [up to 128 IRQs per card]
  *                                                                           ___    Spare
  *
 #define KP_CORE_ID_SPI          5
 
 struct core_table_entry {
-    u16     type;
-    u32     offset;
-    u32     length;
-    bool    s2c_dma_present;
-    u8      s2c_dma_channel_num;
-    bool    c2s_dma_present;
-    u8      c2s_dma_channel_num;
-    u8      irq_count;
-    u8      irq_base_num;
+       u16  type;
+       u32  offset;
+       u32  length;
+       bool s2c_dma_present;
+       u8   s2c_dma_channel_num;
+       bool c2s_dma_present;
+       u8   c2s_dma_channel_num;
+       u8   irq_count;
+       u8   irq_base_num;
 };
 
 static
 void  parse_core_table_entry_v0(struct core_table_entry *cte, const u64 read_val)
 {
-    cte->type                = ((read_val & 0xFFF0000000000000) >> 52);
-    cte->offset              = ((read_val & 0x00000000FFFF0000) >> 16) * 4096;
-    cte->length              = ((read_val & 0x0000FFFF00000000) >> 32) * 8;
-    cte->s2c_dma_present     = ((read_val & 0x0008000000000000) >> 51);
-    cte->s2c_dma_channel_num = ((read_val & 0x0007000000000000) >> 48);
-    cte->c2s_dma_present     = ((read_val & 0x0000000000008000) >> 15);
-    cte->c2s_dma_channel_num = ((read_val & 0x0000000000007000) >> 12);
-    cte->irq_count           = ((read_val & 0x0000000000000C00) >> 10);
-    cte->irq_base_num        = ((read_val & 0x00000000000003F8) >>  3);
+       cte->type                = ((read_val & 0xFFF0000000000000) >> 52);
+       cte->offset              = ((read_val & 0x00000000FFFF0000) >> 16) * 4096;
+       cte->length              = ((read_val & 0x0000FFFF00000000) >> 32) * 8;
+       cte->s2c_dma_present     = ((read_val & 0x0008000000000000) >> 51);
+       cte->s2c_dma_channel_num = ((read_val & 0x0007000000000000) >> 48);
+       cte->c2s_dma_present     = ((read_val & 0x0000000000008000) >> 15);
+       cte->c2s_dma_channel_num = ((read_val & 0x0000000000007000) >> 12);
+       cte->irq_count           = ((read_val & 0x0000000000000C00) >> 10);
+       cte->irq_base_num        = ((read_val & 0x00000000000003F8) >>  3);
 }
 
 static
 void dbg_cte(struct kp2000_device *pcard, struct core_table_entry *cte)
 {
-    dev_dbg(&pcard->pdev->dev, "CTE: type:%3d  offset:%3d (%3d)  length:%3d (%3d)  s2c:%d  c2s:%d  irq_count:%d  base_irq:%d\n",
-        cte->type,
-        cte->offset,
-        cte->offset / 4096,
-        cte->length,
-        cte->length / 8,
-        (cte->s2c_dma_present ? cte->s2c_dma_channel_num : -1),
-        (cte->c2s_dma_present ? cte->c2s_dma_channel_num : -1),
-        cte->irq_count,
-        cte->irq_base_num
-    );
+       dev_dbg(&pcard->pdev->dev, "CTE: type:%3d  offset:%3d (%3d)  length:%3d (%3d)  s2c:%d  c2s:%d  irq_count:%d  base_irq:%d\n",
+               cte->type,
+               cte->offset,
+               cte->offset / 4096,
+               cte->length,
+               cte->length / 8,
+               (cte->s2c_dma_present ? cte->s2c_dma_channel_num : -1),
+               (cte->c2s_dma_present ? cte->c2s_dma_channel_num : -1),
+               cte->irq_count,
+               cte->irq_base_num
+       );
 }
 
 static
 void parse_core_table_entry(struct core_table_entry *cte, const u64 read_val, const u8 entry_rev)
 {
        switch (entry_rev) {
-       case 0: parse_core_table_entry_v0(cte, read_val); break;
-       default: cte->type = 0; break;
+       case 0:
+               parse_core_table_entry_v0(cte, read_val);
+               break;
+       default:
+               cte->type = 0;
+               break;
        }
 }
 
-
-int  probe_core_basic(unsigned int core_num, struct kp2000_device *pcard, char *name, const struct core_table_entry cte)
+static int probe_core_basic(unsigned int core_num, struct kp2000_device *pcard,
+                           char *name, const struct core_table_entry cte)
 {
-    struct mfd_cell  cell = {0};
-    struct resource  resources[2];
-
-    struct kpc_core_device_platdata  core_pdata = {
-        .card_id           = pcard->card_id,
-        .build_version     = pcard->build_version,
-        .hardware_revision = pcard->hardware_revision,
-        .ssid              = pcard->ssid,
-        .ddna              = pcard->ddna,
-    };
-
-    dev_dbg(&pcard->pdev->dev, "Found Basic core: type = %02d  dma = %02x / %02x  offset = 0x%x  length = 0x%x (%d regs)\n", cte.type, KPC_OLD_S2C_DMA_CH_NUM(cte), KPC_OLD_C2S_DMA_CH_NUM(cte), cte.offset, cte.length, cte.length / 8);
-    
-    
-    cell.platform_data = &core_pdata;
-    cell.pdata_size = sizeof(struct kpc_core_device_platdata);
-    cell.name = name;
-    cell.id = core_num;
-    cell.num_resources = 2;
-    
-    memset(&resources, 0, sizeof(resources));
-
-    resources[0].start = cte.offset;
-    resources[0].end   = cte.offset + (cte.length - 1);
-    resources[0].flags = IORESOURCE_MEM;
-    
-    resources[1].start = pcard->pdev->irq;
-    resources[1].end   = pcard->pdev->irq;
-    resources[1].flags = IORESOURCE_IRQ;
-    
-    cell.resources = resources;
-    
-    return mfd_add_devices(
-        PCARD_TO_DEV(pcard),    // parent
-        pcard->card_num * 100,  // id
-        &cell,                  // struct mfd_cell *
-        1,                      // ndevs
-        &pcard->regs_base_resource,
-        0,                      // irq_base
-        NULL                    // struct irq_domain *
-    );
+       struct mfd_cell  cell = { .id = core_num, .name = name };
+       struct resource resources[2];
+
+       struct kpc_core_device_platdata core_pdata = {
+               .card_id           = pcard->card_id,
+               .build_version     = pcard->build_version,
+               .hardware_revision = pcard->hardware_revision,
+               .ssid              = pcard->ssid,
+               .ddna              = pcard->ddna,
+       };
+
+       dev_dbg(&pcard->pdev->dev, "Found Basic core: type = %02d  dma = %02x / %02x  offset = 0x%x  length = 0x%x (%d regs)\n", cte.type, KPC_OLD_S2C_DMA_CH_NUM(cte), KPC_OLD_C2S_DMA_CH_NUM(cte), cte.offset, cte.length, cte.length / 8);
+
+       cell.platform_data = &core_pdata;
+       cell.pdata_size = sizeof(struct kpc_core_device_platdata);
+       cell.num_resources = 2;
+
+       memset(&resources, 0, sizeof(resources));
+
+       resources[0].start = cte.offset;
+       resources[0].end   = cte.offset + (cte.length - 1);
+       resources[0].flags = IORESOURCE_MEM;
+
+       resources[1].start = pcard->pdev->irq;
+       resources[1].end   = pcard->pdev->irq;
+       resources[1].flags = IORESOURCE_IRQ;
+
+       cell.resources = resources;
+
+       return mfd_add_devices(PCARD_TO_DEV(pcard),    // parent
+                              pcard->card_num * 100,  // id
+                              &cell,                  // struct mfd_cell *
+                              1,                      // ndevs
+                              &pcard->regs_base_resource,
+                              0,                      // irq_base
+                              NULL);                  // struct irq_domain *
 }
 
-
 struct kpc_uio_device {
-    struct list_head list;
-    struct kp2000_device *pcard;
-    struct device  *dev;
-    struct uio_info uioinfo;
-    struct core_table_entry cte;
-    u16 core_num;
+       struct list_head list;
+       struct kp2000_device *pcard;
+       struct device  *dev;
+       struct uio_info uioinfo;
+       struct core_table_entry cte;
+       u16 core_num;
 };
 
-static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t offset_show(struct device *dev, struct device_attribute *attr,
+                          char *buf)
+{
+       struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%u\n", kudev->cte.offset);
+}
+static DEVICE_ATTR_RO(offset);
+
+static ssize_t size_show(struct device *dev, struct device_attribute *attr,
+                        char *buf)
+{
+       struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%u\n", kudev->cte.length);
+}
+static DEVICE_ATTR_RO(size);
+
+static ssize_t type_show(struct device *dev, struct device_attribute *attr,
+                        char *buf)
+{
+       struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%u\n", kudev->cte.type);
+}
+static DEVICE_ATTR_RO(type);
+
+static ssize_t s2c_dma_show(struct device *dev, struct device_attribute *attr,
+                           char *buf)
+{
+       struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+       if (!kudev->cte.s2c_dma_present)
+               return sprintf(buf, "%s", "not present\n");
+
+       return sprintf(buf, "%u\n", kudev->cte.s2c_dma_channel_num);
+}
+static DEVICE_ATTR_RO(s2c_dma);
+
+static ssize_t c2s_dma_show(struct device *dev, struct device_attribute *attr,
+                           char *buf)
+{
+       struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+       if (!kudev->cte.c2s_dma_present)
+               return sprintf(buf, "%s", "not present\n");
+
+       return sprintf(buf, "%u\n", kudev->cte.c2s_dma_channel_num);
+}
+static DEVICE_ATTR_RO(c2s_dma);
+
+static ssize_t irq_count_show(struct device *dev, struct device_attribute *attr,
+                             char *buf)
 {
-    struct kpc_uio_device *kudev = dev_get_drvdata(dev);
-    
-    #define ATTR_NAME_CMP(v)  (strcmp(v, attr->attr.name) == 0)
-    if ATTR_NAME_CMP("offset"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.offset);
-    } else if ATTR_NAME_CMP("size"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.length);
-    } else if ATTR_NAME_CMP("type"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.type);
-    }
-    else if ATTR_NAME_CMP("s2c_dma"){
-        if (kudev->cte.s2c_dma_present){
-            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.s2c_dma_channel_num);
-        } else {
-            return scnprintf(buf, PAGE_SIZE, "not present\n");
-        }
-    } else if ATTR_NAME_CMP("c2s_dma"){
-        if (kudev->cte.c2s_dma_present){
-            return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.c2s_dma_channel_num);
-        } else {
-            return scnprintf(buf, PAGE_SIZE, "not present\n");
-        }
-    }
-    else if ATTR_NAME_CMP("irq_count"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_count);
-    } else if ATTR_NAME_CMP("irq_base_num"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->cte.irq_base_num);
-    } else if ATTR_NAME_CMP("core_num"){
-        return scnprintf(buf, PAGE_SIZE, "%u\n", kudev->core_num);
-    } else {
-        return 0;
-    }
-    #undef ATTR_NAME_CMP
+       struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%u\n", kudev->cte.irq_count);
+}
+static DEVICE_ATTR_RO(irq_count);
+
+static ssize_t irq_base_num_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{
+       struct kpc_uio_device *kudev = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%u\n", kudev->cte.irq_base_num);
 }
+static DEVICE_ATTR_RO(irq_base_num);
+
+static ssize_t core_num_show(struct device *dev, struct device_attribute *attr,
+                            char *buf)
+{
+       struct kpc_uio_device *kudev = dev_get_drvdata(dev);
 
+       return sprintf(buf, "%u\n", kudev->core_num);
+}
+static DEVICE_ATTR_RO(core_num);
 
-DEVICE_ATTR(offset,  0444, show_attr, NULL);
-DEVICE_ATTR(size,    0444, show_attr, NULL);
-DEVICE_ATTR(type,    0444, show_attr, NULL);
-DEVICE_ATTR(s2c_dma_ch, 0444, show_attr, NULL);
-DEVICE_ATTR(c2s_dma_ch, 0444, show_attr, NULL);
-DEVICE_ATTR(s2c_dma, 0444, show_attr, NULL);
-DEVICE_ATTR(c2s_dma, 0444, show_attr, NULL);
-DEVICE_ATTR(irq_count, 0444, show_attr, NULL);
-DEVICE_ATTR(irq_base_num, 0444, show_attr, NULL);
-DEVICE_ATTR(core_num, 0444, show_attr, NULL);
-struct attribute * kpc_uio_class_attrs[] = {
+struct attribute *kpc_uio_class_attrs[] = {
        &dev_attr_offset.attr,
        &dev_attr_size.attr,
        &dev_attr_type.attr,
-       &dev_attr_s2c_dma_ch.attr,
-       &dev_attr_c2s_dma_ch.attr,
        &dev_attr_s2c_dma.attr,
        &dev_attr_c2s_dma.attr,
        &dev_attr_irq_count.attr,
@@ -208,264 +233,277 @@ struct attribute * kpc_uio_class_attrs[] = {
        NULL,
 };
 
-
 static
 int  kp2000_check_uio_irq(struct kp2000_device *pcard, u32 irq_num)
 {
-    u64 interrupt_active   =  readq(pcard->sysinfo_regs_base + REG_INTERRUPT_ACTIVE);
-    u64 interrupt_mask_inv = ~readq(pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
-    u64 irq_check_mask = (1 << irq_num);
-    if (interrupt_active & irq_check_mask){ // if it's active (interrupt pending)
-        if (interrupt_mask_inv & irq_check_mask){    // and if it's not masked off
-            return 1;
-        }
-    }
-    return 0;
+       u64 interrupt_active   =  readq(pcard->sysinfo_regs_base + REG_INTERRUPT_ACTIVE);
+       u64 interrupt_mask_inv = ~readq(pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
+       u64 irq_check_mask = BIT_ULL(irq_num);
+
+       if (interrupt_active & irq_check_mask) { // if it's active (interrupt pending)
+               if (interrupt_mask_inv & irq_check_mask) {    // and if it's not masked off
+                       return 1;
+               }
+       }
+       return 0;
 }
 
 static
 irqreturn_t  kuio_handler(int irq, struct uio_info *uioinfo)
 {
-    struct kpc_uio_device *kudev = uioinfo->priv;
-    if (irq != kudev->pcard->pdev->irq)
-        return IRQ_NONE;
-    
-    if (kp2000_check_uio_irq(kudev->pcard, kudev->cte.irq_base_num)){
-        writeq((1 << kudev->cte.irq_base_num), kudev->pcard->sysinfo_regs_base + REG_INTERRUPT_ACTIVE); // Clear the active flag
-        return IRQ_HANDLED;
-    }
-    return IRQ_NONE;
+       struct kpc_uio_device *kudev = uioinfo->priv;
+
+       if (irq != kudev->pcard->pdev->irq)
+               return IRQ_NONE;
+
+       if (kp2000_check_uio_irq(kudev->pcard, kudev->cte.irq_base_num)) {
+               /* Clear the active flag */
+               writeq(BIT_ULL(kudev->cte.irq_base_num),
+                      kudev->pcard->sysinfo_regs_base + REG_INTERRUPT_ACTIVE);
+               return IRQ_HANDLED;
+       }
+       return IRQ_NONE;
 }
 
 static
 int kuio_irqcontrol(struct uio_info *uioinfo, s32 irq_on)
 {
-    struct kpc_uio_device *kudev = uioinfo->priv;
-    struct kp2000_device *pcard = kudev->pcard;
-    u64 mask;
-    
-    lock_card(pcard);
-    mask = readq(pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
-    if (irq_on){
-        mask &= ~(1 << (kudev->cte.irq_base_num));
-    } else {
-        mask |= (1 << (kudev->cte.irq_base_num));
-    }
-    writeq(mask, pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
-    unlock_card(pcard);
-    
-    return 0;
+       struct kpc_uio_device *kudev = uioinfo->priv;
+       struct kp2000_device *pcard = kudev->pcard;
+       u64 mask;
+
+       mutex_lock(&pcard->sem);
+       mask = readq(pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
+       if (irq_on)
+               mask &= ~(BIT_ULL(kudev->cte.irq_base_num));
+       else
+               mask |= BIT_ULL(kudev->cte.irq_base_num);
+       writeq(mask, pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
+       mutex_unlock(&pcard->sem);
+
+       return 0;
 }
 
-int  probe_core_uio(unsigned int core_num, struct kp2000_device *pcard, char *name, const struct core_table_entry cte)
+static int probe_core_uio(unsigned int core_num, struct kp2000_device *pcard,
+                         char *name, const struct core_table_entry cte)
 {
-    struct kpc_uio_device  *kudev;
-    int rv;
-
-    dev_dbg(&pcard->pdev->dev, "Found UIO core:   type = %02d  dma = %02x / %02x  offset = 0x%x  length = 0x%x (%d regs)\n", cte.type, KPC_OLD_S2C_DMA_CH_NUM(cte), KPC_OLD_C2S_DMA_CH_NUM(cte), cte.offset, cte.length, cte.length / 8);
-    
-    kudev = kzalloc(sizeof(struct kpc_uio_device), GFP_KERNEL);
-    if (!kudev){
-        dev_err(&pcard->pdev->dev, "probe_core_uio: failed to kzalloc kpc_uio_device\n");
-        return -ENOMEM;
-    }
-    
-    INIT_LIST_HEAD(&kudev->list);
-    kudev->pcard = pcard;
-    kudev->cte = cte;
-    kudev->core_num = core_num;
-    
-    kudev->uioinfo.priv = kudev;
-    kudev->uioinfo.name = name;
-    kudev->uioinfo.version = "0.0";
-    if (cte.irq_count > 0){
-        kudev->uioinfo.irq_flags = IRQF_SHARED;
-        kudev->uioinfo.irq = pcard->pdev->irq;
-        kudev->uioinfo.handler = kuio_handler;
-        kudev->uioinfo.irqcontrol = kuio_irqcontrol;
-    } else {
-        kudev->uioinfo.irq = 0;
-    }
-
-    kudev->uioinfo.mem[0].name = "uiomap";
-    kudev->uioinfo.mem[0].addr = pci_resource_start(pcard->pdev, REG_BAR) + cte.offset;
-    kudev->uioinfo.mem[0].size = (cte.length + PAGE_SIZE-1) & ~(PAGE_SIZE-1); // Round up to nearest PAGE_SIZE boundary
-    kudev->uioinfo.mem[0].memtype = UIO_MEM_PHYS;
-    
-    kudev->dev = device_create(kpc_uio_class, &pcard->pdev->dev, MKDEV(0,0), kudev, "%s.%d.%d.%d", kudev->uioinfo.name, pcard->card_num, cte.type, kudev->core_num);
-    if (IS_ERR(kudev->dev)) {
-        dev_err(&pcard->pdev->dev, "probe_core_uio device_create failed!\n");
-        return -ENODEV;
-    }
-    dev_set_drvdata(kudev->dev, kudev);
-    
-    rv = uio_register_device(kudev->dev, &kudev->uioinfo);
-    if (rv){
-        dev_err(&pcard->pdev->dev, "probe_core_uio failed uio_register_device: %d\n", rv);
-        return rv;
-    }
-    
-    list_add_tail(&kudev->list, &pcard->uio_devices_list);
-    
-    return 0;
-}
+       struct kpc_uio_device *kudev;
+       int rv;
+
+       dev_dbg(&pcard->pdev->dev, "Found UIO core:   type = %02d  dma = %02x / %02x  offset = 0x%x  length = 0x%x (%d regs)\n", cte.type, KPC_OLD_S2C_DMA_CH_NUM(cte), KPC_OLD_C2S_DMA_CH_NUM(cte), cte.offset, cte.length, cte.length / 8);
+
+       kudev = kzalloc(sizeof(*kudev), GFP_KERNEL);
+       if (!kudev)
+               return -ENOMEM;
+
+       INIT_LIST_HEAD(&kudev->list);
+       kudev->pcard = pcard;
+       kudev->cte = cte;
+       kudev->core_num = core_num;
+
+       kudev->uioinfo.priv = kudev;
+       kudev->uioinfo.name = name;
+       kudev->uioinfo.version = "0.0";
+       if (cte.irq_count > 0) {
+               kudev->uioinfo.irq_flags = IRQF_SHARED;
+               kudev->uioinfo.irq = pcard->pdev->irq;
+               kudev->uioinfo.handler = kuio_handler;
+               kudev->uioinfo.irqcontrol = kuio_irqcontrol;
+       } else {
+               kudev->uioinfo.irq = 0;
+       }
+
+       kudev->uioinfo.mem[0].name = "uiomap";
+       kudev->uioinfo.mem[0].addr = pci_resource_start(pcard->pdev, REG_BAR) + cte.offset;
+       kudev->uioinfo.mem[0].size = (cte.length + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); // Round up to nearest PAGE_SIZE boundary
+       kudev->uioinfo.mem[0].memtype = UIO_MEM_PHYS;
+
+       kudev->dev = device_create(kpc_uio_class, &pcard->pdev->dev, MKDEV(0, 0), kudev, "%s.%d.%d.%d", kudev->uioinfo.name, pcard->card_num, cte.type, kudev->core_num);
+       if (IS_ERR(kudev->dev)) {
+               dev_err(&pcard->pdev->dev, "%s: device_create failed!\n",
+                       __func__);
+               kfree(kudev);
+               return -ENODEV;
+       }
+       dev_set_drvdata(kudev->dev, kudev);
+
+       rv = uio_register_device(kudev->dev, &kudev->uioinfo);
+       if (rv) {
+               dev_err(&pcard->pdev->dev, "%s: failed uio_register_device: %d\n",
+                       __func__, rv);
+               put_device(kudev->dev);
+               kfree(kudev);
+               return rv;
+       }
 
+       list_add_tail(&kudev->list, &pcard->uio_devices_list);
+
+       return 0;
+}
 
 static int  create_dma_engine_core(struct kp2000_device *pcard, size_t engine_regs_offset, int engine_num, int irq_num)
 {
-    struct mfd_cell  cell = {0};
-    struct resource  resources[2];
-
-    dev_dbg(&pcard->pdev->dev, "create_dma_core(pcard = [%p], engine_regs_offset = %zx, engine_num = %d)\n", pcard, engine_regs_offset, engine_num);
-    
-    cell.platform_data = NULL;
-    cell.pdata_size = 0;
-    cell.id = engine_num;
-    cell.name = KP_DRIVER_NAME_DMA_CONTROLLER;
-    cell.num_resources = 2;
-    
-    memset(&resources, 0, sizeof(resources));
-
-    resources[0].start = engine_regs_offset;
-    resources[0].end   = engine_regs_offset + (KPC_DMA_ENGINE_SIZE - 1);
-    resources[0].flags = IORESOURCE_MEM;
-    
-    resources[1].start = irq_num;
-    resources[1].end   = irq_num;
-    resources[1].flags = IORESOURCE_IRQ;
-    
-    cell.resources = resources;
-    
-    return mfd_add_devices(
-        PCARD_TO_DEV(pcard),    // parent
-        pcard->card_num * 100,  // id
-        &cell,                  // struct mfd_cell *
-        1,                      // ndevs
-        &pcard->dma_base_resource,
-        0,                      // irq_base
-        NULL                    // struct irq_domain *
-    );
+       struct mfd_cell  cell = { .id = engine_num };
+       struct resource  resources[2];
+
+       cell.platform_data = NULL;
+       cell.pdata_size = 0;
+       cell.name = KP_DRIVER_NAME_DMA_CONTROLLER;
+       cell.num_resources = 2;
+
+       memset(&resources, 0, sizeof(resources));
+
+       resources[0].start = engine_regs_offset;
+       resources[0].end   = engine_regs_offset + (KPC_DMA_ENGINE_SIZE - 1);
+       resources[0].flags = IORESOURCE_MEM;
+
+       resources[1].start = irq_num;
+       resources[1].end   = irq_num;
+       resources[1].flags = IORESOURCE_IRQ;
+
+       cell.resources = resources;
+
+       return mfd_add_devices(PCARD_TO_DEV(pcard),    // parent
+                              pcard->card_num * 100,  // id
+                              &cell,                  // struct mfd_cell *
+                              1,                      // ndevs
+                              &pcard->dma_base_resource,
+                              0,                      // irq_base
+                              NULL);                  // struct irq_domain *
 }
 
 static int  kp2000_setup_dma_controller(struct kp2000_device *pcard)
 {
-    int err;
-    unsigned int i;
-    u64 capabilities_reg;
-    
-    // S2C Engines
-    for (i = 0 ; i < 32 ; i++){
-        capabilities_reg = readq( pcard->dma_bar_base + KPC_DMA_S2C_BASE_OFFSET + (KPC_DMA_ENGINE_SIZE * i) );
-        if (capabilities_reg & ENGINE_CAP_PRESENT_MASK){
-            err = create_dma_engine_core(pcard, (KPC_DMA_S2C_BASE_OFFSET + (KPC_DMA_ENGINE_SIZE * i)), i,  pcard->pdev->irq);
-            if (err) goto err_out;
-        }
-    }
-    // C2S Engines
-    for (i = 0 ; i < 32 ; i++){
-        capabilities_reg = readq( pcard->dma_bar_base + KPC_DMA_C2S_BASE_OFFSET + (KPC_DMA_ENGINE_SIZE * i) );
-        if (capabilities_reg & ENGINE_CAP_PRESENT_MASK){
-            err = create_dma_engine_core(pcard, (KPC_DMA_C2S_BASE_OFFSET + (KPC_DMA_ENGINE_SIZE * i)), 32+i,  pcard->pdev->irq);
-            if (err) goto err_out;
-        }
-    }
-    
-    return 0;
-    
+       int err;
+       unsigned int i;
+       u64 capabilities_reg;
+
+       // S2C Engines
+       for (i = 0 ; i < 32 ; i++) {
+               capabilities_reg = readq(pcard->dma_bar_base + KPC_DMA_S2C_BASE_OFFSET + (KPC_DMA_ENGINE_SIZE * i));
+               if (capabilities_reg & ENGINE_CAP_PRESENT_MASK) {
+                       err = create_dma_engine_core(pcard, (KPC_DMA_S2C_BASE_OFFSET + (KPC_DMA_ENGINE_SIZE * i)), i,  pcard->pdev->irq);
+                       if (err)
+                               goto err_out;
+               }
+       }
+       // C2S Engines
+       for (i = 0 ; i < 32 ; i++) {
+               capabilities_reg = readq(pcard->dma_bar_base + KPC_DMA_C2S_BASE_OFFSET + (KPC_DMA_ENGINE_SIZE * i));
+               if (capabilities_reg & ENGINE_CAP_PRESENT_MASK) {
+                       err = create_dma_engine_core(pcard, (KPC_DMA_C2S_BASE_OFFSET + (KPC_DMA_ENGINE_SIZE * i)), 32 + i,  pcard->pdev->irq);
+                       if (err)
+                               goto err_out;
+               }
+       }
+
+       return 0;
+
 err_out:
-    dev_err(&pcard->pdev->dev, "kp2000_setup_dma_controller: failed to add a DMA Engine: %d\n", err);
-    return err;
+       dev_err(&pcard->pdev->dev, "%s: failed to add a DMA Engine: %d\n",
+               __func__, err);
+       return err;
 }
 
 int  kp2000_probe_cores(struct kp2000_device *pcard)
 {
-    int err = 0;
-    int i;
-    int current_type_id;
-    u64 read_val;
-    unsigned int highest_core_id = 0;
-    struct core_table_entry cte;
-
-    dev_dbg(&pcard->pdev->dev, "kp2000_probe_cores(pcard = %p / %d)\n", pcard, pcard->card_num);
-    
-    err = kp2000_setup_dma_controller(pcard);
-    if (err) return err;
-    
-    INIT_LIST_HEAD(&pcard->uio_devices_list);
-    
-    // First, iterate the core table looking for the highest CORE_ID
-    for (i = 0 ; i < pcard->core_table_length ; i++){
-        read_val = readq(pcard->sysinfo_regs_base + ((pcard->core_table_offset + i) * 8));
-        parse_core_table_entry(&cte, read_val, pcard->core_table_rev);
-        dbg_cte(pcard, &cte);
-        if (cte.type > highest_core_id){
-            highest_core_id = cte.type;
-        }
-        if (cte.type == KP_CORE_ID_INVALID){
-            dev_info(&pcard->pdev->dev, "Found Invalid core: %016llx\n", read_val);
-        }
-    }
-    // Then, iterate over the possible core types.
-    for (current_type_id = 1 ; current_type_id <= highest_core_id ; current_type_id++){
-        unsigned int core_num = 0;
-        // Foreach core type, iterate the whole table and instantiate subdevices for each core.
-        // Yes, this is O(n*m) but the actual runtime is small enough that it's an acceptable tradeoff.
-        for (i = 0 ; i < pcard->core_table_length ; i++){
-            read_val = readq(pcard->sysinfo_regs_base + ((pcard->core_table_offset + i) * 8));
-            parse_core_table_entry(&cte, read_val, pcard->core_table_rev);
-            
-            if (cte.type == current_type_id){
-                switch (cte.type){
-                    case KP_CORE_ID_I2C:
-                        err = probe_core_basic(core_num, pcard, KP_DRIVER_NAME_I2C, cte);
-                        break;
-                    
-                    case KP_CORE_ID_SPI:
-                        err = probe_core_basic(core_num, pcard, KP_DRIVER_NAME_SPI, cte);
-                        break;
-                    
-                    default:
-                        err = probe_core_uio(core_num, pcard, "kpc_uio", cte);
-                        break;
-                }
-                if (err){
-                    dev_err(&pcard->pdev->dev, "kp2000_probe_cores: failed to add core %d: %d\n", i, err);
-                    return err;
-                }
-                core_num++;
-            }
-        }
-    }
-    
-    // Finally, instantiate a UIO device for the core_table.
-    cte.type                = 0; // CORE_ID_BOARD_INFO
-    cte.offset              = 0; // board info is always at the beginning
-    cte.length              = 512*8;
-    cte.s2c_dma_present     = false;
-    cte.s2c_dma_channel_num = 0;
-    cte.c2s_dma_present     = false;
-    cte.c2s_dma_channel_num = 0;
-    cte.irq_count           = 0;
-    cte.irq_base_num        = 0;
-    err = probe_core_uio(0, pcard, "kpc_uio", cte);
-    if (err){
-        dev_err(&pcard->pdev->dev, "kp2000_probe_cores: failed to add board_info core: %d\n", err);
-        return err;
-    }
-    
-    return 0;
+       int err = 0;
+       int i;
+       int current_type_id;
+       u64 read_val;
+       unsigned int highest_core_id = 0;
+       struct core_table_entry cte;
+
+       err = kp2000_setup_dma_controller(pcard);
+       if (err)
+               return err;
+
+       INIT_LIST_HEAD(&pcard->uio_devices_list);
+
+       // First, iterate the core table looking for the highest CORE_ID
+       for (i = 0 ; i < pcard->core_table_length ; i++) {
+               read_val = readq(pcard->sysinfo_regs_base + ((pcard->core_table_offset + i) * 8));
+               parse_core_table_entry(&cte, read_val, pcard->core_table_rev);
+               dbg_cte(pcard, &cte);
+               if (cte.type > highest_core_id)
+                       highest_core_id = cte.type;
+               if (cte.type == KP_CORE_ID_INVALID)
+                       dev_info(&pcard->pdev->dev, "Found Invalid core: %016llx\n", read_val);
+       }
+       // Then, iterate over the possible core types.
+       for (current_type_id = 1 ; current_type_id <= highest_core_id ; current_type_id++) {
+               unsigned int core_num = 0;
+               // Foreach core type, iterate the whole table and instantiate subdevices for each core.
+               // Yes, this is O(n*m) but the actual runtime is small enough that it's an acceptable tradeoff.
+               for (i = 0 ; i < pcard->core_table_length ; i++) {
+                       read_val = readq(pcard->sysinfo_regs_base + ((pcard->core_table_offset + i) * 8));
+                       parse_core_table_entry(&cte, read_val, pcard->core_table_rev);
+
+                       if (cte.type != current_type_id)
+                               continue;
+
+                       switch (cte.type) {
+                       case KP_CORE_ID_I2C:
+                               err = probe_core_basic(core_num, pcard,
+                                                      KP_DRIVER_NAME_I2C, cte);
+                               break;
+
+                       case KP_CORE_ID_SPI:
+                               err = probe_core_basic(core_num, pcard,
+                                                      KP_DRIVER_NAME_SPI, cte);
+                               break;
+
+                       default:
+                               err = probe_core_uio(core_num, pcard, "kpc_uio", cte);
+                               break;
+                       }
+                       if (err) {
+                               dev_err(&pcard->pdev->dev,
+                                       "%s: failed to add core %d: %d\n",
+                                       __func__, i, err);
+                               goto error;
+                       }
+                       core_num++;
+               }
+       }
+
+       // Finally, instantiate a UIO device for the core_table.
+       cte.type                = 0; // CORE_ID_BOARD_INFO
+       cte.offset              = 0; // board info is always at the beginning
+       cte.length              = 512 * 8;
+       cte.s2c_dma_present     = false;
+       cte.s2c_dma_channel_num = 0;
+       cte.c2s_dma_present     = false;
+       cte.c2s_dma_channel_num = 0;
+       cte.irq_count           = 0;
+       cte.irq_base_num        = 0;
+       err = probe_core_uio(0, pcard, "kpc_uio", cte);
+       if (err) {
+               dev_err(&pcard->pdev->dev, "%s: failed to add board_info core: %d\n",
+                       __func__, err);
+               goto error;
+       }
+
+       return 0;
+
+error:
+       kp2000_remove_cores(pcard);
+       mfd_remove_devices(PCARD_TO_DEV(pcard));
+       return err;
 }
 
 void  kp2000_remove_cores(struct kp2000_device *pcard)
 {
-    struct list_head *ptr;
-    struct list_head *next;
-    list_for_each_safe(ptr, next, &pcard->uio_devices_list){
-        struct kpc_uio_device *kudev = list_entry(ptr, struct kpc_uio_device, list);
-        uio_unregister_device(&kudev->uioinfo);
-        device_unregister(kudev->dev);
-        list_del(&kudev->list);
-        kfree(kudev);
-    }
+       struct list_head *ptr;
+       struct list_head *next;
+
+       list_for_each_safe(ptr, next, &pcard->uio_devices_list) {
+               struct kpc_uio_device *kudev = list_entry(ptr, struct kpc_uio_device, list);
+
+               uio_unregister_device(&kudev->uioinfo);
+               device_unregister(kudev->dev);
+               list_del(&kudev->list);
+               kfree(kudev);
+       }
 }
 
index 40390cdd3c8d6691b07e17b321aa7dd319a0a655..cb05cca687e1bb7736f9c70d5d0c39eb67b4a6d3 100644 (file)
@@ -1,11 +1,17 @@
 // SPDX-License-Identifier: GPL-2.0+
+#include <linux/kernel.h>
+#include <linux/idr.h>
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/pci.h>
 #include <linux/types.h>
 #include <linux/export.h>
 #include <linux/slab.h>
-#include <asm/io.h>
+#include <linux/fs.h>
+#include <linux/errno.h>
+#include <linux/cdev.h>
+#include <linux/rwsem.h>
+#include <linux/uaccess.h>
 #include <linux/io.h>
 #include <linux/mfd/core.h>
 #include <linux/platform_device.h>
 #include <linux/sched.h>
 #include <linux/jiffies.h>
 #include "pcie.h"
+#include "uapi.h"
 
+static DEFINE_IDA(card_num_ida);
 
 /*******************************************************
-  * SysFS Attributes
-  ******************************************************/
-static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
+ * SysFS Attributes
+ ******************************************************/
+
+static ssize_t ssid_show(struct device *dev, struct device_attribute *attr,
+                        char *buf)
 {
-    struct pci_dev *pdev = to_pci_dev(dev);
-    struct kp2000_device *pcard;
-
-    if (!pdev)  return -ENXIO;
-    pcard = pci_get_drvdata(pdev);
-    if (!pcard)  return -ENXIO;
-    
-    if (strcmp("ssid", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);  } else
-    if (strcmp("ddna", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);  } else
-    if (strcmp("card_id", attr->attr.name) == 0){      return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->card_id);  } else
-    if (strcmp("hw_rev", attr->attr.name) == 0){       return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->hardware_revision);  } else
-    if (strcmp("build", attr->attr.name) == 0){        return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_version);  } else
-    if (strcmp("build_date", attr->attr.name) == 0){   return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_datestamp);  } else
-    if (strcmp("build_time", attr->attr.name) == 0){   return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_timestamp);  } else
-    { return -ENXIO; }
+       struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%016llx\n", pcard->ssid);
 }
+static DEVICE_ATTR_RO(ssid);
 
-static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t ddna_show(struct device *dev, struct device_attribute *attr,
+                        char *buf)
 {
-       struct pci_dev *pdev = to_pci_dev(dev);
-       struct kp2000_device *pcard;
-       u64 val;
+       struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-       if (!pdev)
-               return -ENXIO;
+       return sprintf(buf, "%016llx\n", pcard->ddna);
+}
+static DEVICE_ATTR_RO(ddna);
 
-       pcard = pci_get_drvdata(pdev);
-       if (!pcard)
-               return -ENXIO;
+static ssize_t card_id_show(struct device *dev, struct device_attribute *attr,
+                           char *buf)
+{
+       struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%08x\n", pcard->card_id);
+}
+static DEVICE_ATTR_RO(card_id);
+
+static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr,
+                          char *buf)
+{
+       struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%08x\n", pcard->hardware_revision);
+}
+static DEVICE_ATTR_RO(hw_rev);
+
+static ssize_t build_show(struct device *dev, struct device_attribute *attr,
+                         char *buf)
+{
+       struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%08x\n", pcard->build_version);
+}
+static DEVICE_ATTR_RO(build);
+
+static ssize_t build_date_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%08x\n", pcard->build_datestamp);
+}
+static DEVICE_ATTR_RO(build_date);
+
+static ssize_t build_time_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%08x\n", pcard->build_timestamp);
+}
+static DEVICE_ATTR_RO(build_time);
+
+static ssize_t cpld_reg_show(struct device *dev, struct device_attribute *attr,
+                            char *buf)
+{
+       struct kp2000_device *pcard = dev_get_drvdata(dev);
+       u64 val;
 
        val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
-       return scnprintf(buf, PAGE_SIZE, "%016llx\n", val);
+       return sprintf(buf, "%016llx\n", val);
+}
+static DEVICE_ATTR_RO(cpld_reg);
+
+static ssize_t cpld_reconfigure(struct device *dev,
+                               struct device_attribute *attr,
+                               const char *buf, size_t count)
+{
+       struct kp2000_device *pcard = dev_get_drvdata(dev);
+       long wr_val;
+       int rv;
+
+       rv = kstrtol(buf, 0, &wr_val);
+       if (rv < 0)
+               return rv;
+       if (wr_val > 7)
+               return -EINVAL;
+
+       wr_val = wr_val << 8;
+       wr_val |= 0x1; // Set the "Configure Go" bit
+       writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
+       return count;
 }
-static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+static DEVICE_ATTR(cpld_reconfigure, 0220, NULL, cpld_reconfigure);
+
+static ssize_t irq_mask_reg_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
 {
-    struct pci_dev *pdev = to_pci_dev(dev);
-    long wr_val;
-    struct kp2000_device *pcard;
-    int rv;
-
-    if (!pdev)  return -ENXIO;
-    pcard = pci_get_drvdata(pdev);
-    if (!pcard)  return -ENXIO;
-    
-    rv = kstrtol(buf, 0, &wr_val);
-    if (rv < 0)  return rv;
-    if (wr_val > 7)  return -EINVAL;
-    
-    wr_val = wr_val << 8;
-    wr_val |= 0x1; // Set the "Configure Go" bit
-    writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
-    return count;
+       struct kp2000_device *pcard = dev_get_drvdata(dev);
+       u64 val;
+
+       val = readq(pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
+       return sprintf(buf, "%016llx\n", val);
 }
+static DEVICE_ATTR_RO(irq_mask_reg);
 
+static ssize_t irq_active_reg_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       struct kp2000_device *pcard = dev_get_drvdata(dev);
+       u64 val;
 
-DEVICE_ATTR(ssid,       0444, show_attr, NULL);
-DEVICE_ATTR(ddna,       0444, show_attr, NULL);
-DEVICE_ATTR(card_id,    0444, show_attr, NULL);
-DEVICE_ATTR(hw_rev,     0444, show_attr, NULL);
-DEVICE_ATTR(build,      0444, show_attr, NULL);
-DEVICE_ATTR(build_date, 0444, show_attr, NULL);
-DEVICE_ATTR(build_time, 0444, show_attr, NULL);
-DEVICE_ATTR(cpld_reg,   0444, show_cpld_config_reg, NULL);
-DEVICE_ATTR(cpld_reconfigure,   0220, NULL, cpld_reconfigure);
-
-static const struct attribute *  kp_attr_list[] = {
-    &dev_attr_ssid.attr,
-    &dev_attr_ddna.attr,
-    &dev_attr_card_id.attr,
-    &dev_attr_hw_rev.attr,
-    &dev_attr_build.attr,
-    &dev_attr_build_date.attr,
-    &dev_attr_build_time.attr,
-    &dev_attr_cpld_reg.attr,
-    &dev_attr_cpld_reconfigure.attr,
-    NULL,
-};
+       val = readq(pcard->sysinfo_regs_base + REG_INTERRUPT_ACTIVE);
+       return sprintf(buf, "%016llx\n", val);
+}
+static DEVICE_ATTR_RO(irq_active_reg);
 
+static ssize_t pcie_error_count_reg_show(struct device *dev,
+                                        struct device_attribute *attr,
+                                        char *buf)
+{
+       struct kp2000_device *pcard = dev_get_drvdata(dev);
+       u64 val;
+
+       val = readq(pcard->sysinfo_regs_base + REG_PCIE_ERROR_COUNT);
+       return sprintf(buf, "%016llx\n", val);
+}
+static DEVICE_ATTR_RO(pcie_error_count_reg);
+
+static ssize_t core_table_offset_show(struct device *dev,
+                                     struct device_attribute *attr, char *buf)
+{
+       struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%08x\n", pcard->core_table_offset);
+}
+static DEVICE_ATTR_RO(core_table_offset);
+
+static ssize_t core_table_length_show(struct device *dev,
+                                     struct device_attribute *attr, char *buf)
+{
+       struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%08x\n", pcard->core_table_length);
+}
+static DEVICE_ATTR_RO(core_table_length);
+
+static const struct attribute *kp_attr_list[] = {
+       &dev_attr_ssid.attr,
+       &dev_attr_ddna.attr,
+       &dev_attr_card_id.attr,
+       &dev_attr_hw_rev.attr,
+       &dev_attr_build.attr,
+       &dev_attr_build_date.attr,
+       &dev_attr_build_time.attr,
+       &dev_attr_cpld_reg.attr,
+       &dev_attr_cpld_reconfigure.attr,
+       &dev_attr_irq_mask_reg.attr,
+       &dev_attr_irq_active_reg.attr,
+       &dev_attr_pcie_error_count_reg.attr,
+       &dev_attr_core_table_offset.attr,
+       &dev_attr_core_table_length.attr,
+       NULL,
+};
 
 /*******************************************************
 * Functions
 ******************************************************/
+ * Functions
+ ******************************************************/
 
 static void wait_and_read_ssid(struct kp2000_device *pcard)
 {
-    u64 read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
-    unsigned long timeout;
-    
-    if (read_val & 0x8000000000000000){
-        pcard->ssid = read_val;
-        return;
-    }
-    
-    timeout = jiffies + (HZ * 2);
-    do {
-        read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
-        if (read_val & 0x8000000000000000){
-            pcard->ssid = read_val;
-            return;
-        }
-        cpu_relax();
-        //schedule();
-    } while (time_before(jiffies, timeout));
-    
-    dev_notice(&pcard->pdev->dev, "SSID didn't show up!\n");
-    
-    #if 0
-    // Timed out waiting for the SSID to show up, just use the DDNA instead?
-    read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_DDNA);
-    pcard->ssid = read_val;
-    #else
-    // Timed out waiting for the SSID to show up, stick all zeros in the value
-    pcard->ssid = 0;
-    #endif
+       u64 read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
+       unsigned long timeout;
+
+       if (read_val & 0x8000000000000000) {
+               pcard->ssid = read_val;
+               return;
+       }
+
+       timeout = jiffies + (HZ * 2);
+       do {
+               read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
+               if (read_val & 0x8000000000000000) {
+                       pcard->ssid = read_val;
+                       return;
+               }
+               cpu_relax();
+               //schedule();
+       } while (time_before(jiffies, timeout));
+
+       dev_notice(&pcard->pdev->dev, "SSID didn't show up!\n");
+
+       // Timed out waiting for the SSID to show up, stick all zeros in the
+       // value
+       pcard->ssid = 0;
 }
 
 static int  read_system_regs(struct kp2000_device *pcard)
 {
-    u64 read_val;
-    
-    read_val = readq(pcard->sysinfo_regs_base + REG_MAGIC_NUMBER);
-    if (read_val != KP2000_MAGIC_VALUE){
-        dev_err(&pcard->pdev->dev, "Invalid magic!  Got: 0x%016llx  Want: 0x%016lx\n", read_val, KP2000_MAGIC_VALUE);
-        return -EILSEQ;
-    }
-    
-    read_val = readq(pcard->sysinfo_regs_base + REG_CARD_ID_AND_BUILD);
-    pcard->card_id = (read_val & 0xFFFFFFFF00000000) >> 32;
-    pcard->build_version = (read_val & 0x00000000FFFFFFFF) >> 0;
-    
-    read_val = readq(pcard->sysinfo_regs_base + REG_DATE_AND_TIME_STAMPS);
-    pcard->build_datestamp = (read_val & 0xFFFFFFFF00000000) >> 32;
-    pcard->build_timestamp = (read_val & 0x00000000FFFFFFFF) >> 0;
-    
-    read_val = readq(pcard->sysinfo_regs_base + REG_CORE_TABLE_OFFSET);
-    pcard->core_table_length = (read_val & 0xFFFFFFFF00000000) >> 32;
-    pcard->core_table_offset = (read_val & 0x00000000FFFFFFFF) >> 0;
-    
-    wait_and_read_ssid(pcard);
-    
-    read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_HW_ID);
-    pcard->core_table_rev    = (read_val & 0x0000000000000F00) >> 8;
-    pcard->hardware_revision = (read_val & 0x000000000000001F);
-    
-    read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_DDNA);
-    pcard->ddna = read_val;
-    
-    dev_info(&pcard->pdev->dev, "system_regs: %08x %08x %08x %08x  %02x  %d %d  %016llx  %016llx\n",
-        pcard->card_id,
-        pcard->build_version,
-        pcard->build_datestamp,
-        pcard->build_timestamp,
-        pcard->hardware_revision,
-        pcard->core_table_rev,
-        pcard->core_table_length,
-        pcard->ssid,
-        pcard->ddna
-    );
-    
-    if (pcard->core_table_rev > 1){
-        dev_err(&pcard->pdev->dev, "core table entry revision is higher than we can deal with, cannot continue with this card!\n");
-        return 1;
-    }
-    
-    return 0;
+       u64 read_val;
+
+       read_val = readq(pcard->sysinfo_regs_base + REG_MAGIC_NUMBER);
+       if (read_val != KP2000_MAGIC_VALUE) {
+               dev_err(&pcard->pdev->dev,
+                       "Invalid magic!  Got: 0x%016llx  Want: 0x%016llx\n",
+                       read_val, KP2000_MAGIC_VALUE);
+               return -EILSEQ;
+       }
+
+       read_val = readq(pcard->sysinfo_regs_base + REG_CARD_ID_AND_BUILD);
+       pcard->card_id = (read_val & 0xFFFFFFFF00000000) >> 32;
+       pcard->build_version = (read_val & 0x00000000FFFFFFFF) >> 0;
+
+       read_val = readq(pcard->sysinfo_regs_base + REG_DATE_AND_TIME_STAMPS);
+       pcard->build_datestamp = (read_val & 0xFFFFFFFF00000000) >> 32;
+       pcard->build_timestamp = (read_val & 0x00000000FFFFFFFF) >> 0;
+
+       read_val = readq(pcard->sysinfo_regs_base + REG_CORE_TABLE_OFFSET);
+       pcard->core_table_length = (read_val & 0xFFFFFFFF00000000) >> 32;
+       pcard->core_table_offset = (read_val & 0x00000000FFFFFFFF) >> 0;
+
+       wait_and_read_ssid(pcard);
+
+       read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_HW_ID);
+       pcard->core_table_rev    = (read_val & 0x0000000000000F00) >> 8;
+       pcard->hardware_revision = (read_val & 0x000000000000001F);
+
+       read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_DDNA);
+       pcard->ddna = read_val;
+
+       dev_info(&pcard->pdev->dev,
+                "system_regs: %08x %08x %08x %08x  %02x  %d %d  %016llx  %016llx\n",
+                pcard->card_id,
+                pcard->build_version,
+                pcard->build_datestamp,
+                pcard->build_timestamp,
+                pcard->hardware_revision,
+                pcard->core_table_rev,
+                pcard->core_table_length,
+                pcard->ssid,
+                pcard->ddna);
+
+       if (pcard->core_table_rev > 1) {
+               dev_err(&pcard->pdev->dev,
+                       "core table entry revision is higher than we can deal with, cannot continue with this card!\n");
+               return 1;
+       }
+
+       return 0;
 }
 
-irqreturn_t  kp2000_irq_handler(int irq, void *dev_id)
+static irqreturn_t kp2000_irq_handler(int irq, void *dev_id)
 {
-    struct kp2000_device  *pcard = (struct kp2000_device*)dev_id;
-    SetBackEndControl(pcard->dma_common_regs, KPC_DMA_CARD_IRQ_ENABLE | KPC_DMA_CARD_USER_INTERRUPT_MODE | KPC_DMA_CARD_USER_INTERRUPT_ACTIVE);
-    return IRQ_HANDLED;
+       struct kp2000_device *pcard = dev_id;
+
+       writel(KPC_DMA_CARD_IRQ_ENABLE |
+              KPC_DMA_CARD_USER_INTERRUPT_MODE |
+              KPC_DMA_CARD_USER_INTERRUPT_ACTIVE,
+              pcard->dma_common_regs);
+       return IRQ_HANDLED;
 }
 
-int  kp2000_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+static int kp2000_pcie_probe(struct pci_dev *pdev,
+                            const struct pci_device_id *id)
 {
-    int err = 0;
-    struct kp2000_device *pcard;
-    static int card_count = 1;
-    int rv;
-    unsigned long reg_bar_phys_addr;
-    unsigned long reg_bar_phys_len;
-    unsigned long dma_bar_phys_addr;
-    unsigned long dma_bar_phys_len;
-    u16 regval;
-    dev_dbg(&pdev->dev, "kp2000_pcie_probe(pdev = [%p], id = [%p])\n", pdev, id);
-    
-    //{ Step 1: Allocate a struct for the pcard
-    pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);
-    if (NULL == pcard){
-        dev_err(&pdev->dev, "probe: failed to allocate private card data\n");
-        return -ENOMEM;
-    }
-    dev_dbg(&pdev->dev, "probe: allocated struct kp2000_device @ %p\n", pcard);
-    //}
-    
-    //{ Step 2: Initialize trivial pcard elements
-    pcard->card_num = card_count;
-    card_count++;
-    scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num);
-    
-    mutex_init(&pcard->sem);
-    lock_card(pcard);
-    
-    pcard->pdev = pdev;
-    pci_set_drvdata(pdev, pcard);
-    //}
-    
-    //{ Step 3: Enable PCI device
-    err = pci_enable_device(pcard->pdev);
-    if (err){
-        dev_err(&pcard->pdev->dev, "probe: failed to enable PCIE2000 PCIe device (%d)\n", err);
-        goto out3;
-    }
-    //}
-    
-    //{ Step 4: Setup the Register BAR
-    reg_bar_phys_addr = pci_resource_start(pcard->pdev, REG_BAR);
-    reg_bar_phys_len = pci_resource_len(pcard->pdev, REG_BAR);
-    
-    pcard->regs_bar_base = ioremap_nocache(reg_bar_phys_addr, PAGE_SIZE);
-    if (NULL == pcard->regs_bar_base){
-        dev_err(&pcard->pdev->dev, "probe: REG_BAR could not remap memory to virtual space\n");
-        err = -ENODEV;
-        goto out4;
-    }
-    dev_dbg(&pcard->pdev->dev, "probe: REG_BAR virt hardware address start [%p]\n", pcard->regs_bar_base);
-    
-    err = pci_request_region(pcard->pdev, REG_BAR, KP_DRIVER_NAME_KP2000);
-    if (err){
-        iounmap(pcard->regs_bar_base);
-        dev_err(&pcard->pdev->dev, "probe: failed to acquire PCI region (%d)\n", err);
-        err = -ENODEV;
-        goto out4;
-    }
-    
-    pcard->regs_base_resource.start = reg_bar_phys_addr;
-    pcard->regs_base_resource.end   = reg_bar_phys_addr + reg_bar_phys_len - 1;
-    pcard->regs_base_resource.flags = IORESOURCE_MEM;
-    //}
-    
-    //{ Step 5: Setup the DMA BAR
-    dma_bar_phys_addr = pci_resource_start(pcard->pdev, DMA_BAR);
-    dma_bar_phys_len = pci_resource_len(pcard->pdev, DMA_BAR);
-    
-    pcard->dma_bar_base = ioremap_nocache(dma_bar_phys_addr, dma_bar_phys_len);
-    if (NULL == pcard->dma_bar_base){
-        dev_err(&pcard->pdev->dev, "probe: DMA_BAR could not remap memory to virtual space\n");
-        err = -ENODEV;
-        goto out5;
-    }
-    dev_dbg(&pcard->pdev->dev, "probe: DMA_BAR virt hardware address start [%p]\n", pcard->dma_bar_base);
-    
-    pcard->dma_common_regs = pcard->dma_bar_base + KPC_DMA_COMMON_OFFSET;
-    
-    err = pci_request_region(pcard->pdev, DMA_BAR, "kp2000_pcie");
-    if (err){
-        iounmap(pcard->dma_bar_base);
-        dev_err(&pcard->pdev->dev, "probe: failed to acquire PCI region (%d)\n", err);
-        err = -ENODEV;
-        goto out5;
-    }
-    
-    pcard->dma_base_resource.start = dma_bar_phys_addr;
-    pcard->dma_base_resource.end   = dma_bar_phys_addr + dma_bar_phys_len - 1;
-    pcard->dma_base_resource.flags = IORESOURCE_MEM;
-    //}
-    
-    //{ Step 6: System Regs
-    pcard->sysinfo_regs_base = pcard->regs_bar_base;
-    err = read_system_regs(pcard);
-    if (err)
-        goto out6;
-    
-    // Disable all "user" interrupts because they're not used yet.
-    writeq(0xFFFFFFFFFFFFFFFF, pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
-    //}
-    
-    //{ Step 7: Configure PCI thingies
-    // let the card master PCIe
-    pci_set_master(pcard->pdev);
-    // enable IO and mem if not already done
-    pci_read_config_word(pcard->pdev, PCI_COMMAND, &regval);
-    regval |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
-    pci_write_config_word(pcard->pdev, PCI_COMMAND, regval);
-    
-    // Clear relaxed ordering bit
-    pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_RELAX_EN, 0);
-    
-    // Set Max_Payload_Size and Max_Read_Request_Size
-    regval = (0x0) << 5; // Max_Payload_Size = 128 B
-    pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_PAYLOAD, regval);
-    regval = (0x0) << 12; // Max_Read_Request_Size = 128 B
-    pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_READRQ, regval);
-    
-    // Enable error reporting for: Correctable Errors, Non-Fatal Errors, Fatal Errors, Unsupported Requests
-    pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, 0, PCI_EXP_DEVCTL_CERE | PCI_EXP_DEVCTL_NFERE | PCI_EXP_DEVCTL_FERE | PCI_EXP_DEVCTL_URRE);
-    
-    err = dma_set_mask(PCARD_TO_DEV(pcard), DMA_BIT_MASK(64));
-    if (err){
-        dev_err(&pcard->pdev->dev, "CANNOT use DMA mask %0llx\n", DMA_BIT_MASK(64));
-        goto out7;
-    }
-    dev_dbg(&pcard->pdev->dev, "Using DMA mask %0llx\n", dma_get_mask(PCARD_TO_DEV(pcard)));
-    //}
-    
-    //{ Step 8: Configure IRQs
-    err = pci_enable_msi(pcard->pdev);
-    if (err < 0)
-        goto out8a;
-    
-    rv = request_irq(pcard->pdev->irq, kp2000_irq_handler, IRQF_SHARED, pcard->name, pcard);
-    if (rv){
-        dev_err(&pcard->pdev->dev, "kp2000_pcie_probe: failed to request_irq: %d\n", rv);
-        goto out8b;
-    }
-    //}
-    
-    //{ Step 9: Setup sysfs attributes
-    err = sysfs_create_files(&(pdev->dev.kobj), kp_attr_list);
-    if (err){
-        dev_err(&pdev->dev, "Failed to add sysfs files: %d\n", err);
-        goto out9;
-    }
-    //}
-    
-    //{ Step 10: Setup misc device
-    pcard->miscdev.minor = MISC_DYNAMIC_MINOR;
-    pcard->miscdev.fops = &kp2000_fops;
-    pcard->miscdev.parent = &pcard->pdev->dev;
-    pcard->miscdev.name = pcard->name;
-    
-    err = misc_register(&pcard->miscdev);
-    if (err){
-        dev_err(&pcard->pdev->dev, "kp2000_pcie_probe: misc_register failed: %d\n", err);
-        goto out10;
-    }
-    //}
-    
-    //{ Step 11: Probe cores
-    err = kp2000_probe_cores(pcard);
-    if (err)
-        goto out11;
-    //}
-    
-    //{ Step 12: Enable IRQs in HW
-    SetBackEndControl(pcard->dma_common_regs, KPC_DMA_CARD_IRQ_ENABLE | KPC_DMA_CARD_USER_INTERRUPT_MODE);
-    //}
-    
-    dev_dbg(&pcard->pdev->dev, "kp2000_pcie_probe() complete!\n");
-    unlock_card(pcard);
-    return 0;
-
-  out11:
-    misc_deregister(&pcard->miscdev);
-  out10:
-    sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
-  out9:
-    free_irq(pcard->pdev->irq, pcard);
-  out8b:
-    pci_disable_msi(pcard->pdev);
-  out8a:
-  out7:
-  out6:
-    iounmap(pcard->dma_bar_base);
-    pci_release_region(pdev, DMA_BAR);
-    pcard->dma_bar_base = NULL;
-  out5:
-    iounmap(pcard->regs_bar_base);
-    pci_release_region(pdev, REG_BAR);
-    pcard->regs_bar_base = NULL;
-  out4:
-    pci_disable_device(pcard->pdev);
-  out3:
-    unlock_card(pcard);
-    kfree(pcard);
-    return err;
+       int err = 0;
+       struct kp2000_device *pcard;
+       int rv;
+       unsigned long reg_bar_phys_addr;
+       unsigned long reg_bar_phys_len;
+       unsigned long dma_bar_phys_addr;
+       unsigned long dma_bar_phys_len;
+       u16 regval;
+
+       pcard = kzalloc(sizeof(*pcard), GFP_KERNEL);
+       if (!pcard)
+               return -ENOMEM;
+       dev_dbg(&pdev->dev, "probe: allocated struct kp2000_device @ %p\n",
+               pcard);
+
+       err = ida_simple_get(&card_num_ida, 1, INT_MAX, GFP_KERNEL);
+       if (err < 0) {
+               dev_err(&pdev->dev, "probe: failed to get card number (%d)\n",
+                       err);
+               goto err_free_pcard;
+       }
+       pcard->card_num = err;
+       scnprintf(pcard->name, 16, "kpcard%u", pcard->card_num);
+
+       mutex_init(&pcard->sem);
+       mutex_lock(&pcard->sem);
+
+       pcard->pdev = pdev;
+       pci_set_drvdata(pdev, pcard);
+
+       err = pci_enable_device(pcard->pdev);
+       if (err) {
+               dev_err(&pcard->pdev->dev,
+                       "probe: failed to enable PCIE2000 PCIe device (%d)\n",
+                       err);
+               goto err_remove_ida;
+       }
+
+       /* Setup the Register BAR */
+       reg_bar_phys_addr = pci_resource_start(pcard->pdev, REG_BAR);
+       reg_bar_phys_len = pci_resource_len(pcard->pdev, REG_BAR);
+
+       pcard->regs_bar_base = ioremap_nocache(reg_bar_phys_addr, PAGE_SIZE);
+       if (!pcard->regs_bar_base) {
+               dev_err(&pcard->pdev->dev,
+                       "probe: REG_BAR could not remap memory to virtual space\n");
+               err = -ENODEV;
+               goto err_disable_device;
+       }
+       dev_dbg(&pcard->pdev->dev,
+               "probe: REG_BAR virt hardware address start [%p]\n",
+               pcard->regs_bar_base);
+
+       err = pci_request_region(pcard->pdev, REG_BAR, KP_DRIVER_NAME_KP2000);
+       if (err) {
+               dev_err(&pcard->pdev->dev,
+                       "probe: failed to acquire PCI region (%d)\n",
+                       err);
+               err = -ENODEV;
+               goto err_unmap_regs;
+       }
+
+       pcard->regs_base_resource.start = reg_bar_phys_addr;
+       pcard->regs_base_resource.end   = reg_bar_phys_addr +
+                                         reg_bar_phys_len - 1;
+       pcard->regs_base_resource.flags = IORESOURCE_MEM;
+
+       /* Setup the DMA BAR */
+       dma_bar_phys_addr = pci_resource_start(pcard->pdev, DMA_BAR);
+       dma_bar_phys_len = pci_resource_len(pcard->pdev, DMA_BAR);
+
+       pcard->dma_bar_base = ioremap_nocache(dma_bar_phys_addr,
+                                             dma_bar_phys_len);
+       if (!pcard->dma_bar_base) {
+               dev_err(&pcard->pdev->dev,
+                       "probe: DMA_BAR could not remap memory to virtual space\n");
+               err = -ENODEV;
+               goto err_release_regs;
+       }
+       dev_dbg(&pcard->pdev->dev,
+               "probe: DMA_BAR virt hardware address start [%p]\n",
+               pcard->dma_bar_base);
+
+       pcard->dma_common_regs = pcard->dma_bar_base + KPC_DMA_COMMON_OFFSET;
+
+       err = pci_request_region(pcard->pdev, DMA_BAR, "kp2000_pcie");
+       if (err) {
+               dev_err(&pcard->pdev->dev,
+                       "probe: failed to acquire PCI region (%d)\n", err);
+               err = -ENODEV;
+               goto err_unmap_dma;
+       }
+
+       pcard->dma_base_resource.start = dma_bar_phys_addr;
+       pcard->dma_base_resource.end   = dma_bar_phys_addr +
+                                        dma_bar_phys_len - 1;
+       pcard->dma_base_resource.flags = IORESOURCE_MEM;
+
+       /* Read System Regs */
+       pcard->sysinfo_regs_base = pcard->regs_bar_base;
+       err = read_system_regs(pcard);
+       if (err)
+               goto err_release_dma;
+
+       // Disable all "user" interrupts because they're not used yet.
+       writeq(0xFFFFFFFFFFFFFFFF,
+              pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
+
+       // let the card master PCIe
+       pci_set_master(pcard->pdev);
+
+       // enable IO and mem if not already done
+       pci_read_config_word(pcard->pdev, PCI_COMMAND, &regval);
+       regval |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
+       pci_write_config_word(pcard->pdev, PCI_COMMAND, regval);
+
+       // Clear relaxed ordering bit
+       pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL,
+                                          PCI_EXP_DEVCTL_RELAX_EN, 0);
+
+       // Set Max_Payload_Size and Max_Read_Request_Size
+       regval = (0x0) << 5; // Max_Payload_Size = 128 B
+       pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL,
+                                          PCI_EXP_DEVCTL_PAYLOAD, regval);
+       regval = (0x0) << 12; // Max_Read_Request_Size = 128 B
+       pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL,
+                                          PCI_EXP_DEVCTL_READRQ, regval);
+
+       // Enable error reporting for: Correctable Errors, Non-Fatal Errors,
+       // Fatal Errors, Unsupported Requests
+       pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, 0,
+                                          PCI_EXP_DEVCTL_CERE |
+                                          PCI_EXP_DEVCTL_NFERE |
+                                          PCI_EXP_DEVCTL_FERE |
+                                          PCI_EXP_DEVCTL_URRE);
+
+       err = dma_set_mask(PCARD_TO_DEV(pcard), DMA_BIT_MASK(64));
+       if (err) {
+               dev_err(&pcard->pdev->dev,
+                       "CANNOT use DMA mask %0llx\n", DMA_BIT_MASK(64));
+               goto err_release_dma;
+       }
+       dev_dbg(&pcard->pdev->dev,
+               "Using DMA mask %0llx\n", dma_get_mask(PCARD_TO_DEV(pcard)));
+
+       err = pci_enable_msi(pcard->pdev);
+       if (err < 0)
+               goto err_release_dma;
+
+       rv = request_irq(pcard->pdev->irq, kp2000_irq_handler, IRQF_SHARED,
+                        pcard->name, pcard);
+       if (rv) {
+               dev_err(&pcard->pdev->dev,
+                       "%s: failed to request_irq: %d\n", __func__, rv);
+               goto err_disable_msi;
+       }
+
+       err = sysfs_create_files(&pdev->dev.kobj, kp_attr_list);
+       if (err) {
+               dev_err(&pdev->dev, "Failed to add sysfs files: %d\n", err);
+               goto err_free_irq;
+       }
+
+       err = kp2000_probe_cores(pcard);
+       if (err)
+               goto err_remove_sysfs;
+
+       /* Enable IRQs in HW */
+       writel(KPC_DMA_CARD_IRQ_ENABLE | KPC_DMA_CARD_USER_INTERRUPT_MODE,
+              pcard->dma_common_regs);
+
+       mutex_unlock(&pcard->sem);
+       return 0;
+
+err_remove_sysfs:
+       sysfs_remove_files(&pdev->dev.kobj, kp_attr_list);
+err_free_irq:
+       free_irq(pcard->pdev->irq, pcard);
+err_disable_msi:
+       pci_disable_msi(pcard->pdev);
+err_release_dma:
+       pci_release_region(pdev, DMA_BAR);
+err_unmap_dma:
+       iounmap(pcard->dma_bar_base);
+err_release_regs:
+       pci_release_region(pdev, REG_BAR);
+err_unmap_regs:
+       iounmap(pcard->regs_bar_base);
+err_disable_device:
+       pci_disable_device(pcard->pdev);
+err_remove_ida:
+       mutex_unlock(&pcard->sem);
+       ida_simple_remove(&card_num_ida, pcard->card_num);
+err_free_pcard:
+       kfree(pcard);
+       return err;
+}
+
+static void kp2000_pcie_remove(struct pci_dev *pdev)
+{
+       struct kp2000_device *pcard = pci_get_drvdata(pdev);
+
+       if (!pcard)
+               return;
+
+       mutex_lock(&pcard->sem);
+       kp2000_remove_cores(pcard);
+       mfd_remove_devices(PCARD_TO_DEV(pcard));
+       sysfs_remove_files(&pdev->dev.kobj, kp_attr_list);
+       free_irq(pcard->pdev->irq, pcard);
+       pci_disable_msi(pcard->pdev);
+       if (pcard->dma_bar_base) {
+               iounmap(pcard->dma_bar_base);
+               pci_release_region(pdev, DMA_BAR);
+               pcard->dma_bar_base = NULL;
+       }
+       if (pcard->regs_bar_base) {
+               iounmap(pcard->regs_bar_base);
+               pci_release_region(pdev, REG_BAR);
+               pcard->regs_bar_base = NULL;
+       }
+       pci_disable_device(pcard->pdev);
+       pci_set_drvdata(pdev, NULL);
+       mutex_unlock(&pcard->sem);
+       ida_simple_remove(&card_num_ida, pcard->card_num);
+       kfree(pcard);
 }
 
+struct class *kpc_uio_class;
+ATTRIBUTE_GROUPS(kpc_uio_class);
+
+static const struct pci_device_id kp2000_pci_device_ids[] = {
+       { PCI_DEVICE(PCI_VENDOR_ID_DAKTRONICS, PCI_DEVICE_ID_DAKTRONICS) },
+       { PCI_DEVICE(PCI_VENDOR_ID_DAKTRONICS, PCI_DEVICE_ID_DAKTRONICS_KADOKA_P2KR0) },
+       { 0, }
+};
+MODULE_DEVICE_TABLE(pci, kp2000_pci_device_ids);
+
+static struct pci_driver kp2000_driver_inst = {
+       .name =         "kp2000_pcie",
+       .id_table =     kp2000_pci_device_ids,
+       .probe =        kp2000_pcie_probe,
+       .remove =       kp2000_pcie_remove,
+};
 
-void  kp2000_pcie_remove(struct pci_dev *pdev)
+static int __init kp2000_pcie_init(void)
 {
-    struct kp2000_device *pcard = pci_get_drvdata(pdev);
-
-    dev_dbg(&pdev->dev, "kp2000_pcie_remove(pdev=%p)\n", pdev);
-    
-    if (pcard == NULL)  return;
-    
-    lock_card(pcard);
-    kp2000_remove_cores(pcard);
-    mfd_remove_devices(PCARD_TO_DEV(pcard));
-    misc_deregister(&pcard->miscdev);
-    sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
-    free_irq(pcard->pdev->irq, pcard);
-    pci_disable_msi(pcard->pdev);
-    if (pcard->dma_bar_base != NULL){
-        iounmap(pcard->dma_bar_base);
-        pci_release_region(pdev, DMA_BAR);
-        pcard->dma_bar_base = NULL;
-    }
-    if (pcard->regs_bar_base != NULL){
-        iounmap(pcard->regs_bar_base);
-        pci_release_region(pdev, REG_BAR);
-        pcard->regs_bar_base = NULL;
-    }
-    pci_disable_device(pcard->pdev);
-    pci_set_drvdata(pdev, NULL);
-    unlock_card(pcard);
-    kfree(pcard);
+       kpc_uio_class = class_create(THIS_MODULE, "kpc_uio");
+       if (IS_ERR(kpc_uio_class))
+               return PTR_ERR(kpc_uio_class);
+
+       kpc_uio_class->dev_groups = kpc_uio_class_groups;
+       return pci_register_driver(&kp2000_driver_inst);
 }
+module_init(kp2000_pcie_init);
+
+static void __exit kp2000_pcie_exit(void)
+{
+       pci_unregister_driver(&kp2000_driver_inst);
+       class_destroy(kpc_uio_class);
+       ida_destroy(&card_num_ida);
+}
+module_exit(kp2000_pcie_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Lee.Brooke@Daktronics.com, Matt.Sickler@Daktronics.com");
+MODULE_SOFTDEP("pre: uio post: kpc_nwl_dma kpc_i2c kpc_spi");
index f35e636b1fb76d5edeb4d5f328c31da5edb7b46e..21450e3d408f09bf7de6842a383c58c84383ca5e 100644 (file)
 #define KPC_DMA_CARD_S2C_INTERRUPT_STATUS_MASK  0x00FF0000
 #define KPC_DMA_CARD_C2S_INTERRUPT_STATUS_MASK  0xFF000000
 
-static inline  void  SetBackEndControl(void __iomem *regs, u32 value)
-{
-    writel(value, regs + 0);
-}
-static inline  u32  GetBackEndStatus(void __iomem *regs)
-{
-    return readl(regs + 0);
-}
-
-static inline  u32  BackEndControlSetClear(void __iomem *regs, u32 set_bits, u32 clear_bits)
-{
-    u32 start_val = GetBackEndStatus(regs);
-    u32 new_val = start_val;
-    new_val &= ~clear_bits;
-    new_val |= set_bits;
-    SetBackEndControl(regs, new_val);
-    return start_val;
-}
-
 #endif /* KPC_DMA_COMMON_DEFS_H_ */
diff --git a/drivers/staging/kpc2000/kpc2000/fileops.c b/drivers/staging/kpc2000/kpc2000/fileops.c
deleted file mode 100644 (file)
index b3b0b76..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/kernel.h>   /* printk() */
-#include <linux/slab.h>     /* kmalloc() */
-#include <linux/fs.h>       /* everything... */
-#include <linux/errno.h>    /* error codes */
-#include <linux/types.h>    /* size_t */
-#include <linux/cdev.h>
-#include <linux/uaccess.h>    /* copy_*_user */
-#include <linux/rwsem.h>
-#include <linux/idr.h>
-#include <linux/io-64-nonatomic-lo-hi.h>
-#include <linux/device.h>
-#include <linux/sched.h>
-#include "pcie.h"
-#include "uapi.h"
-
-int  kp2000_cdev_open(struct inode *inode, struct file *filp)
-{
-       struct kp2000_device *pcard = container_of(filp->private_data, struct kp2000_device, miscdev);
-
-       dev_dbg(&pcard->pdev->dev, "kp2000_cdev_open(filp = [%p], pcard = [%p])\n", filp, pcard);
-
-       filp->private_data = pcard; /* so other methods can access it */
-
-       return 0;
-}
-
-int  kp2000_cdev_close(struct inode *inode, struct file *filp)
-{
-       struct kp2000_device *pcard = filp->private_data;
-
-       dev_dbg(&pcard->pdev->dev, "kp2000_cdev_close(filp = [%p], pcard = [%p])\n", filp, pcard);
-       return 0;
-}
-
-
-ssize_t  kp2000_cdev_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
-{
-       struct kp2000_device *pcard = filp->private_data;
-       int cnt = 0;
-       int ret;
-#define BUFF_CNT  1024
-       char buff[BUFF_CNT] = {0}; //NOTE: Increase this so it is at least as large as all the scnprintfs.  And don't use unbounded strings. "%s"
-       //NOTE: also, this is a really shitty way to implement the read() call, but it will work for any size 'count'.
-
-       if (WARN(NULL == buf, "kp2000_cdev_read: buf is a NULL pointer!\n"))
-               return -EINVAL;
-
-       cnt += scnprintf(buff+cnt, BUFF_CNT-cnt, "Card ID                 : 0x%08x\n", pcard->card_id);
-       cnt += scnprintf(buff+cnt, BUFF_CNT-cnt, "Build Version           : 0x%08x\n", pcard->build_version);
-       cnt += scnprintf(buff+cnt, BUFF_CNT-cnt, "Build Date              : 0x%08x\n", pcard->build_datestamp);
-       cnt += scnprintf(buff+cnt, BUFF_CNT-cnt, "Build Time              : 0x%08x\n", pcard->build_timestamp);
-       cnt += scnprintf(buff+cnt, BUFF_CNT-cnt, "Core Table Offset       : 0x%08x\n", pcard->core_table_offset);
-       cnt += scnprintf(buff+cnt, BUFF_CNT-cnt, "Core Table Length       : 0x%08x\n", pcard->core_table_length);
-       cnt += scnprintf(buff+cnt, BUFF_CNT-cnt, "Hardware Revision       : 0x%08x\n", pcard->hardware_revision);
-       cnt += scnprintf(buff+cnt, BUFF_CNT-cnt, "SSID                    : 0x%016llx\n", pcard->ssid);
-       cnt += scnprintf(buff+cnt, BUFF_CNT-cnt, "DDNA                    : 0x%016llx\n", pcard->ddna);
-       cnt += scnprintf(buff+cnt, BUFF_CNT-cnt, "IRQ Mask                : 0x%016llx\n", readq(pcard->sysinfo_regs_base + REG_INTERRUPT_MASK));
-       cnt += scnprintf(buff+cnt, BUFF_CNT-cnt, "IRQ Active              : 0x%016llx\n", readq(pcard->sysinfo_regs_base + REG_INTERRUPT_ACTIVE));
-       cnt += scnprintf(buff+cnt, BUFF_CNT-cnt, "CPLD                    : 0x%016llx\n", readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG));
-
-       if (*f_pos >= cnt)
-               return 0;
-
-       if (count > cnt)
-               count = cnt;
-
-       ret = copy_to_user(buf, buff + *f_pos, count);
-       if (ret)
-               return -EFAULT;
-       *f_pos += count;
-       return count;
-}
-
-ssize_t  kp2000_cdev_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos)
-{
-       return -EINVAL;
-}
-
-long  kp2000_cdev_ioctl(struct file *filp, unsigned int ioctl_num, unsigned long ioctl_param)
-{
-       struct kp2000_device *pcard = filp->private_data;
-
-       dev_dbg(&pcard->pdev->dev, "kp2000_cdev_ioctl(filp = [%p], ioctl_num = 0x%08x, ioctl_param = 0x%016lx) pcard = [%p]\n", filp, ioctl_num, ioctl_param, pcard);
-
-       switch (ioctl_num){
-       case KP2000_IOCTL_GET_CPLD_REG:             return readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
-       case KP2000_IOCTL_GET_PCIE_ERROR_REG:       return readq(pcard->sysinfo_regs_base + REG_PCIE_ERROR_COUNT);
-    
-       case KP2000_IOCTL_GET_EVERYTHING: {
-               struct kp2000_regs temp;
-               int ret;
-
-               memset(&temp, 0, sizeof(temp));
-               temp.card_id = pcard->card_id;
-               temp.build_version = pcard->build_version;
-               temp.build_datestamp = pcard->build_datestamp;
-               temp.build_timestamp = pcard->build_timestamp;
-               temp.hw_rev = pcard->hardware_revision;
-               temp.ssid = pcard->ssid;
-               temp.ddna = pcard->ddna;
-               temp.cpld_reg = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
-
-               ret = copy_to_user((void*)ioctl_param, (void*)&temp, sizeof(temp));
-               if (ret)
-                       return -EFAULT;
-
-               return sizeof(temp);
-               }
-
-       default:
-               return -ENOTTY;
-       }
-       return -ENOTTY;
-}
-
-
-struct file_operations  kp2000_fops = {
-       .owner      = THIS_MODULE,
-       .open       = kp2000_cdev_open,
-       .release    = kp2000_cdev_close,
-       .read       = kp2000_cdev_read,
-       //.write      = kp2000_cdev_write,
-       //.poll       = kp2000_cdev_poll,
-       //.fasync     = kp2000_cdev_fasync,
-       .llseek     = noop_llseek,
-       .unlocked_ioctl = kp2000_cdev_ioctl,
-};
-
diff --git a/drivers/staging/kpc2000/kpc2000/kp2000_module.c b/drivers/staging/kpc2000/kpc2000/kp2000_module.c
deleted file mode 100644 (file)
index fa3bd26..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/pci.h>
-#include <linux/types.h>
-#include <linux/export.h>
-#include <linux/slab.h>
-#include <asm/io.h>
-#include <linux/io.h>
-#include <linux/mfd/core.h>
-#include <linux/platform_device.h>
-#include <linux/ioport.h>
-#include "pcie.h"
-
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Lee.Brooke@Daktronics.com, Matt.Sickler@Daktronics.com");
-MODULE_SOFTDEP("pre: uio post: kpc_nwl_dma kpc_i2c kpc_spi");
-
-struct class *kpc_uio_class;
-ATTRIBUTE_GROUPS(kpc_uio_class);
-
-static const struct pci_device_id kp2000_pci_device_ids[] = {
-       { PCI_DEVICE(PCI_VENDOR_ID_DAKTRONICS, PCI_DEVICE_ID_DAKTRONICS) },
-       { PCI_DEVICE(PCI_VENDOR_ID_DAKTRONICS, PCI_DEVICE_ID_DAKTRONICS_KADOKA_P2KR0) },
-       { 0, }
-};
-MODULE_DEVICE_TABLE(pci, kp2000_pci_device_ids);
-
-static struct pci_driver  kp2000_driver_inst = {
-       .name       = "kp2000_pcie",
-       .id_table   = kp2000_pci_device_ids,
-       .probe      = kp2000_pcie_probe,
-       .remove     = kp2000_pcie_remove
-};
-
-
-static int __init  kp2000_pcie_init(void)
-{
-       kpc_uio_class = class_create(THIS_MODULE, "kpc_uio");
-       if (IS_ERR(kpc_uio_class))
-               return PTR_ERR(kpc_uio_class);
-
-       kpc_uio_class->dev_groups = kpc_uio_class_groups;
-       return pci_register_driver(&kp2000_driver_inst);
-}
-module_init(kp2000_pcie_init);
-
-static void __exit  kp2000_pcie_exit(void)
-{
-       pci_unregister_driver(&kp2000_driver_inst);
-       class_destroy(kpc_uio_class);
-}
-module_exit(kp2000_pcie_exit);
index 893aebfd1449179b915caa3c378ce1819a2de722..cb815c30faa41f84c10ef2e6582cf7716b3be62c 100644 (file)
@@ -2,7 +2,6 @@
 #ifndef KP2000_PCIE_H
 #define KP2000_PCIE_H
 #include <linux/types.h>
-#include <linux/miscdevice.h>
 #include <linux/pci.h>
 #include "../kpc.h"
 #include "dma_common_defs.h"
  *      9   <---------------------- IRQ Active Flags ---------------------->
  */
 
-#define REG_WIDTH   8
-#define REG_MAGIC_NUMBER            (0 * REG_WIDTH)
-#define REG_CARD_ID_AND_BUILD       (1 * REG_WIDTH)
-#define REG_DATE_AND_TIME_STAMPS    (2 * REG_WIDTH)
-#define REG_CORE_TABLE_OFFSET       (3 * REG_WIDTH)
-#define REG_FPGA_SSID               (4 * REG_WIDTH)
-#define REG_FPGA_HW_ID              (5 * REG_WIDTH)
-#define REG_FPGA_DDNA               (6 * REG_WIDTH)
-#define REG_CPLD_CONFIG             (7 * REG_WIDTH)
-#define REG_INTERRUPT_MASK          (8 * REG_WIDTH)
-#define REG_INTERRUPT_ACTIVE        (9 * REG_WIDTH)
-#define REG_PCIE_ERROR_COUNT        (10 * REG_WIDTH)
+#define REG_WIDTH                      8
+#define REG_MAGIC_NUMBER               (0 * REG_WIDTH)
+#define REG_CARD_ID_AND_BUILD          (1 * REG_WIDTH)
+#define REG_DATE_AND_TIME_STAMPS       (2 * REG_WIDTH)
+#define REG_CORE_TABLE_OFFSET          (3 * REG_WIDTH)
+#define REG_FPGA_SSID                  (4 * REG_WIDTH)
+#define REG_FPGA_HW_ID                 (5 * REG_WIDTH)
+#define REG_FPGA_DDNA                  (6 * REG_WIDTH)
+#define REG_CPLD_CONFIG                        (7 * REG_WIDTH)
+#define REG_INTERRUPT_MASK             (8 * REG_WIDTH)
+#define REG_INTERRUPT_ACTIVE           (9 * REG_WIDTH)
+#define REG_PCIE_ERROR_COUNT           (10 * REG_WIDTH)
 
-#define KP2000_MAGIC_VALUE      0x196C61482231894D
+#define KP2000_MAGIC_VALUE             0x196C61482231894DULL
 
-#define PCI_VENDOR_ID_DAKTRONICS    0x1c33
-#define PCI_DEVICE_ID_DAKTRONICS    0x6021
+#define PCI_VENDOR_ID_DAKTRONICS       0x1c33
+#define PCI_DEVICE_ID_DAKTRONICS       0x6021
 
-#define DMA_BAR     0
-#define REG_BAR     1
+#define DMA_BAR                                0
+#define REG_BAR                                1
 
 struct kp2000_device {
-    struct pci_dev     *pdev;
-    struct miscdevice   miscdev;
-    char                name[16];
-    
-    unsigned int        card_num;
-    struct mutex        sem;
-    
-    void __iomem       *sysinfo_regs_base;
-    void __iomem       *regs_bar_base;
-    struct resource     regs_base_resource;
-    void __iomem       *dma_bar_base;
-    void __iomem       *dma_common_regs;
-    struct resource     dma_base_resource;
-    
-    // "System Registers"
-    u32                 card_id;
-    u32                 build_version;
-    u32                 build_datestamp;
-    u32                 build_timestamp;
-    u32                 core_table_offset;
-    u32                 core_table_length;
-    u8                  core_table_rev;
-    u8                  hardware_revision;
-    u64                 ssid;
-    u64                 ddna;
-    
-    // IRQ stuff
-    unsigned int        irq;
-    
-    struct list_head    uio_devices_list;
+       struct pci_dev          *pdev;
+       char                    name[16];
+
+       unsigned int            card_num;
+       struct mutex            sem;
+
+       void __iomem            *sysinfo_regs_base;
+       void __iomem            *regs_bar_base;
+       struct resource         regs_base_resource;
+       void __iomem            *dma_bar_base;
+       void __iomem            *dma_common_regs;
+       struct resource         dma_base_resource;
+
+       // "System Registers"
+       u32                     card_id;
+       u32                     build_version;
+       u32                     build_datestamp;
+       u32                     build_timestamp;
+       u32                     core_table_offset;
+       u32                     core_table_length;
+       u8                      core_table_rev;
+       u8                      hardware_revision;
+       u64                     ssid;
+       u64                     ddna;
+
+       // IRQ stuff
+       unsigned int            irq;
+
+       struct list_head        uio_devices_list;
 };
 
 extern struct class *kpc_uio_class;
 extern struct attribute *kpc_uio_class_attrs[];
 
-int   kp2000_pcie_probe(struct pci_dev *dev, const struct pci_device_id *id);
-void  kp2000_pcie_remove(struct pci_dev *pdev);
-int   kp2000_probe_cores(struct kp2000_device *pcard);
-void  kp2000_remove_cores(struct kp2000_device *pcard);
-
-extern struct file_operations  kp2000_fops;
-
+int kp2000_probe_cores(struct kp2000_device *pcard);
+void kp2000_remove_cores(struct kp2000_device *pcard);
 
 // Define this quick little macro because the expression is used frequently
-#define PCARD_TO_DEV(pcard)  (&(pcard->pdev->dev))
-
-static inline void
-lock_card(struct kp2000_device *pcard)
-{
-    BUG_ON(pcard == NULL);
-    mutex_lock(&pcard->sem);
-}
-static inline void
-unlock_card(struct kp2000_device *pcard)
-{
-    BUG_ON(pcard == NULL);
-    mutex_unlock(&pcard->sem);
-}
-
+#define PCARD_TO_DEV(pcard)    (&(pcard->pdev->dev))
 
 #endif /* KP2000_PCIE_H */
index ef8008bcd33d22378ca8b1866c006f7ed6a29343..16f37f002dc625d7205164593c9f9eabc30e52d3 100644 (file)
@@ -5,18 +5,18 @@
 #include <linux/ioctl.h>
 
 struct kp2000_regs {
-    __u32 card_id;
-    __u32 build_version;
-    __u32 build_datestamp;
-    __u32 build_timestamp;
-    __u32 hw_rev;
-    __u64 ssid;
-    __u64 ddna;
-    __u64 cpld_reg;
+       __u32 card_id;
+       __u32 build_version;
+       __u32 build_datestamp;
+       __u32 build_timestamp;
+       __u32 hw_rev;
+       __u64 ssid;
+       __u64 ddna;
+       __u64 cpld_reg;
 };
 
-#define KP2000_IOCTL_GET_CPLD_REG               _IOR('k', 9, __u32)
-#define KP2000_IOCTL_GET_PCIE_ERROR_REG         _IOR('k', 11, __u32)
-#define KP2000_IOCTL_GET_EVERYTHING             _IOR('k', 8, struct kp2000_regs*)
+#define KP2000_IOCTL_GET_CPLD_REG              _IOR('k', 9, __u32)
+#define KP2000_IOCTL_GET_PCIE_ERROR_REG                _IOR('k', 11, __u32)
+#define KP2000_IOCTL_GET_EVERYTHING            _IOR('k', 8, struct kp2000_regs*)
 
 #endif /* KP2000_CDEV_UAPI_H_ */
diff --git a/drivers/staging/kpc2000/kpc2000_i2c.c b/drivers/staging/kpc2000/kpc2000_i2c.c
new file mode 100644 (file)
index 0000000..b108da4
--- /dev/null
@@ -0,0 +1,651 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * KPC2000 i2c driver
+ *
+ * Adapted i2c-i801.c for use with Kadoka hardware.
+ *
+ * Copyright (C) 1998 - 2002
+ *     Frodo Looijaard <frodol@dds.nl>,
+ *     Philip Edelbrock <phil@netroedge.com>,
+ *     Mark D. Studebaker <mdsxyz123@yahoo.com>
+ * Copyright (C) 2007 - 2012
+ *     Jean Delvare <khali@linux-fr.org>
+ * Copyright (C) 2010 Intel Corporation
+ *     David Woodhouse <dwmw2@infradead.org>
+ * Copyright (C) 2014-2018 Daktronics
+ *     Matt Sickler <matt.sickler@daktronics.com>,
+ *     Jordon Hofer <jordon.hofer@daktronics.com>
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/io.h>
+#include <linux/io-64-nonatomic-lo-hi.h>
+#include <linux/export.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/fs.h>
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include "kpc.h"
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Matt.Sickler@Daktronics.com");
+
+struct i2c_device {
+       unsigned long           smba;
+       struct i2c_adapter      adapter;
+       unsigned int            features;
+};
+
+/*****************************
+ *** Part 1 - i2c Handlers ***
+ *****************************/
+
+#define REG_SIZE 8
+
+/* I801 SMBus address offsets */
+#define SMBHSTSTS(p)    ((0  * REG_SIZE) + (p)->smba)
+#define SMBHSTCNT(p)    ((2  * REG_SIZE) + (p)->smba)
+#define SMBHSTCMD(p)    ((3  * REG_SIZE) + (p)->smba)
+#define SMBHSTADD(p)    ((4  * REG_SIZE) + (p)->smba)
+#define SMBHSTDAT0(p)   ((5  * REG_SIZE) + (p)->smba)
+#define SMBHSTDAT1(p)   ((6  * REG_SIZE) + (p)->smba)
+#define SMBBLKDAT(p)    ((7  * REG_SIZE) + (p)->smba)
+#define SMBPEC(p)       ((8  * REG_SIZE) + (p)->smba)   /* ICH3 and later */
+#define SMBAUXSTS(p)    ((12 * REG_SIZE) + (p)->smba)   /* ICH4 and later */
+#define SMBAUXCTL(p)    ((13 * REG_SIZE) + (p)->smba)   /* ICH4 and later */
+
+/* PCI Address Constants */
+#define SMBBAR      4
+#define SMBHSTCFG   0x040
+
+/* Host configuration bits for SMBHSTCFG */
+#define SMBHSTCFG_HST_EN        1
+#define SMBHSTCFG_SMB_SMI_EN    2
+#define SMBHSTCFG_I2C_EN        4
+
+/* Auxiliary control register bits, ICH4+ only */
+#define SMBAUXCTL_CRC       1
+#define SMBAUXCTL_E32B      2
+
+/* kill bit for SMBHSTCNT */
+#define SMBHSTCNT_KILL      2
+
+/* Other settings */
+#define MAX_RETRIES         400
+#define ENABLE_INT9         0       /* set to 0x01 to enable - untested */
+
+/* I801 command constants */
+#define I801_QUICK              0x00
+#define I801_BYTE               0x04
+#define I801_BYTE_DATA          0x08
+#define I801_WORD_DATA          0x0C
+#define I801_PROC_CALL          0x10    /* unimplemented */
+#define I801_BLOCK_DATA         0x14
+#define I801_I2C_BLOCK_DATA     0x18    /* ICH5 and later */
+#define I801_BLOCK_LAST         0x34
+#define I801_I2C_BLOCK_LAST     0x38    /* ICH5 and later */
+#define I801_START              0x40
+#define I801_PEC_EN             0x80    /* ICH3 and later */
+
+/* I801 Hosts Status register bits */
+#define SMBHSTSTS_BYTE_DONE     0x80
+#define SMBHSTSTS_INUSE_STS     0x40
+#define SMBHSTSTS_SMBALERT_STS  0x20
+#define SMBHSTSTS_FAILED        0x10
+#define SMBHSTSTS_BUS_ERR       0x08
+#define SMBHSTSTS_DEV_ERR       0x04
+#define SMBHSTSTS_INTR          0x02
+#define SMBHSTSTS_HOST_BUSY     0x01
+
+#define STATUS_FLAGS        (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_FAILED | SMBHSTSTS_BUS_ERR | SMBHSTSTS_DEV_ERR | SMBHSTSTS_INTR)
+
+/* Older devices have their ID defined in <linux/pci_ids.h> */
+#define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS       0x1c22
+#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS          0x1d22
+/* Patsburg also has three 'Integrated Device Function' SMBus controllers */
+#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0     0x1d70
+#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1     0x1d71
+#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2     0x1d72
+#define PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS      0x1e22
+#define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS          0x2330
+#define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS     0x3b30
+#define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS         0x8c22
+#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS      0x9c22
+
+#define FEATURE_SMBUS_PEC       BIT(0)
+#define FEATURE_BLOCK_BUFFER    BIT(1)
+#define FEATURE_BLOCK_PROC      BIT(2)
+#define FEATURE_I2C_BLOCK_READ  BIT(3)
+/* Not really a feature, but it's convenient to handle it as such */
+#define FEATURE_IDF             BIT(15)
+
+// FIXME!
+#undef inb_p
+#define inb_p(a) readq((void *)a)
+#undef outb_p
+#define outb_p(d, a) writeq(d, (void *)a)
+
+/* Make sure the SMBus host is ready to start transmitting.
+ * Return 0 if it is, -EBUSY if it is not.
+ */
+static int i801_check_pre(struct i2c_device *priv)
+{
+       int status;
+
+       status = inb_p(SMBHSTSTS(priv));
+       if (status & SMBHSTSTS_HOST_BUSY) {
+               dev_err(&priv->adapter.dev, "SMBus is busy, can't use it! (status=%x)\n", status);
+               return -EBUSY;
+       }
+
+       status &= STATUS_FLAGS;
+       if (status) {
+               //dev_dbg(&priv->adapter.dev, "Clearing status flags (%02x)\n", status);
+               outb_p(status, SMBHSTSTS(priv));
+               status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS;
+               if (status) {
+                       dev_err(&priv->adapter.dev, "Failed clearing status flags (%02x)\n", status);
+                       return -EBUSY;
+               }
+       }
+       return 0;
+}
+
+/* Convert the status register to an error code, and clear it. */
+static int i801_check_post(struct i2c_device *priv, int status, int timeout)
+{
+       int result = 0;
+
+       /* If the SMBus is still busy, we give up */
+       if (timeout) {
+               dev_err(&priv->adapter.dev, "Transaction timeout\n");
+               /* try to stop the current command */
+               dev_dbg(&priv->adapter.dev, "Terminating the current operation\n");
+               outb_p(inb_p(SMBHSTCNT(priv)) | SMBHSTCNT_KILL, SMBHSTCNT(priv));
+               usleep_range(1000, 2000);
+               outb_p(inb_p(SMBHSTCNT(priv)) & (~SMBHSTCNT_KILL), SMBHSTCNT(priv));
+
+               /* Check if it worked */
+               status = inb_p(SMBHSTSTS(priv));
+               if ((status & SMBHSTSTS_HOST_BUSY) || !(status & SMBHSTSTS_FAILED))
+                       dev_err(&priv->adapter.dev, "Failed terminating the transaction\n");
+               outb_p(STATUS_FLAGS, SMBHSTSTS(priv));
+               return -ETIMEDOUT;
+       }
+
+       if (status & SMBHSTSTS_FAILED) {
+               result = -EIO;
+               dev_err(&priv->adapter.dev, "Transaction failed\n");
+       }
+       if (status & SMBHSTSTS_DEV_ERR) {
+               result = -ENXIO;
+               dev_dbg(&priv->adapter.dev, "No response\n");
+       }
+       if (status & SMBHSTSTS_BUS_ERR) {
+               result = -EAGAIN;
+               dev_dbg(&priv->adapter.dev, "Lost arbitration\n");
+       }
+
+       if (result) {
+               /* Clear error flags */
+               outb_p(status & STATUS_FLAGS, SMBHSTSTS(priv));
+               status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS;
+               if (status)
+                       dev_warn(&priv->adapter.dev, "Failed clearing status flags at end of transaction (%02x)\n", status);
+       }
+
+       return result;
+}
+
+static int i801_transaction(struct i2c_device *priv, int xact)
+{
+       int status;
+       int result;
+       int timeout = 0;
+
+       result = i801_check_pre(priv);
+       if (result < 0)
+               return result;
+       /* the current contents of SMBHSTCNT can be overwritten, since PEC,
+        * INTREN, SMBSCMD are passed in xact
+        */
+       outb_p(xact | I801_START, SMBHSTCNT(priv));
+
+       /* We will always wait for a fraction of a second! */
+       do {
+               usleep_range(250, 500);
+               status = inb_p(SMBHSTSTS(priv));
+       } while ((status & SMBHSTSTS_HOST_BUSY) && (timeout++ < MAX_RETRIES));
+
+       result = i801_check_post(priv, status, timeout > MAX_RETRIES);
+       if (result < 0)
+               return result;
+
+       outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv));
+       return 0;
+}
+
+/* wait for INTR bit as advised by Intel */
+static void i801_wait_hwpec(struct i2c_device *priv)
+{
+       int timeout = 0;
+       int status;
+
+       do {
+               usleep_range(250, 500);
+               status = inb_p(SMBHSTSTS(priv));
+       } while ((!(status & SMBHSTSTS_INTR)) && (timeout++ < MAX_RETRIES));
+
+       if (timeout > MAX_RETRIES)
+               dev_dbg(&priv->adapter.dev, "PEC Timeout!\n");
+
+       outb_p(status, SMBHSTSTS(priv));
+}
+
+static int i801_block_transaction_by_block(struct i2c_device *priv, union i2c_smbus_data *data, char read_write, int hwpec)
+{
+       int i, len;
+       int status;
+
+       inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
+
+       /* Use 32-byte buffer to process this transaction */
+       if (read_write == I2C_SMBUS_WRITE) {
+               len = data->block[0];
+               outb_p(len, SMBHSTDAT0(priv));
+               for (i = 0; i < len; i++)
+                       outb_p(data->block[i + 1], SMBBLKDAT(priv));
+       }
+
+       status = i801_transaction(priv, I801_BLOCK_DATA | ENABLE_INT9 | I801_PEC_EN * hwpec);
+       if (status)
+               return status;
+
+       if (read_write == I2C_SMBUS_READ) {
+               len = inb_p(SMBHSTDAT0(priv));
+               if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
+                       return -EPROTO;
+
+               data->block[0] = len;
+               for (i = 0; i < len; i++)
+                       data->block[i + 1] = inb_p(SMBBLKDAT(priv));
+       }
+       return 0;
+}
+
+static int i801_block_transaction_byte_by_byte(struct i2c_device *priv, union i2c_smbus_data *data, char read_write, int command, int hwpec)
+{
+       int i, len;
+       int smbcmd;
+       int status;
+       int result;
+       int timeout;
+
+       result = i801_check_pre(priv);
+       if (result < 0)
+               return result;
+
+       len = data->block[0];
+
+       if (read_write == I2C_SMBUS_WRITE) {
+               outb_p(len, SMBHSTDAT0(priv));
+               outb_p(data->block[1], SMBBLKDAT(priv));
+       }
+
+       for (i = 1; i <= len; i++) {
+               if (i == len && read_write == I2C_SMBUS_READ) {
+                       if (command == I2C_SMBUS_I2C_BLOCK_DATA)
+                               smbcmd = I801_I2C_BLOCK_LAST;
+                       else
+                               smbcmd = I801_BLOCK_LAST;
+               } else {
+                       if (command == I2C_SMBUS_I2C_BLOCK_DATA && read_write == I2C_SMBUS_READ)
+                               smbcmd = I801_I2C_BLOCK_DATA;
+                       else
+                               smbcmd = I801_BLOCK_DATA;
+               }
+               outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT(priv));
+
+               if (i == 1)
+                       outb_p(inb(SMBHSTCNT(priv)) | I801_START, SMBHSTCNT(priv));
+               /* We will always wait for a fraction of a second! */
+               timeout = 0;
+               do {
+                       usleep_range(250, 500);
+                       status = inb_p(SMBHSTSTS(priv));
+               } while ((!(status & SMBHSTSTS_BYTE_DONE)) && (timeout++ < MAX_RETRIES));
+
+               result = i801_check_post(priv, status, timeout > MAX_RETRIES);
+               if (result < 0)
+                       return result;
+               if (i == 1 && read_write == I2C_SMBUS_READ && command != I2C_SMBUS_I2C_BLOCK_DATA) {
+                       len = inb_p(SMBHSTDAT0(priv));
+                       if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
+                               dev_err(&priv->adapter.dev, "Illegal SMBus block read size %d\n", len);
+                               /* Recover */
+                               while (inb_p(SMBHSTSTS(priv)) & SMBHSTSTS_HOST_BUSY)
+                                       outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
+                               outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv));
+                               return -EPROTO;
+                       }
+                       data->block[0] = len;
+               }
+
+               /* Retrieve/store value in SMBBLKDAT */
+               if (read_write == I2C_SMBUS_READ)
+                       data->block[i] = inb_p(SMBBLKDAT(priv));
+               if (read_write == I2C_SMBUS_WRITE && i + 1 <= len)
+                       outb_p(data->block[i + 1], SMBBLKDAT(priv));
+               /* signals SMBBLKDAT ready */
+               outb_p(SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR, SMBHSTSTS(priv));
+       }
+
+       return 0;
+}
+
+static int i801_set_block_buffer_mode(struct i2c_device *priv)
+{
+       outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
+       if ((inb_p(SMBAUXCTL(priv)) & SMBAUXCTL_E32B) == 0)
+               return -EIO;
+       return 0;
+}
+
+/* Block transaction function */
+static int i801_block_transaction(struct i2c_device *priv, union i2c_smbus_data *data, char read_write, int command, int hwpec)
+{
+       int result = 0;
+       //unsigned char hostc;
+
+       if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
+               if (read_write == I2C_SMBUS_WRITE) {
+                       /* set I2C_EN bit in configuration register */
+                       //TODO: Figure out the right thing to do here...
+                       //pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc);
+                       //pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc | SMBHSTCFG_I2C_EN);
+               } else if (!(priv->features & FEATURE_I2C_BLOCK_READ)) {
+                       dev_err(&priv->adapter.dev, "I2C block read is unsupported!\n");
+                       return -EOPNOTSUPP;
+               }
+       }
+
+       if (read_write == I2C_SMBUS_WRITE || command == I2C_SMBUS_I2C_BLOCK_DATA) {
+               if (data->block[0] < 1)
+                       data->block[0] = 1;
+               if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
+                       data->block[0] = I2C_SMBUS_BLOCK_MAX;
+       } else {
+               data->block[0] = 32;    /* max for SMBus block reads */
+       }
+
+       /* Experience has shown that the block buffer can only be used for
+        * SMBus (not I2C) block transactions, even though the datasheet
+        * doesn't mention this limitation.
+        */
+       if ((priv->features & FEATURE_BLOCK_BUFFER) && command != I2C_SMBUS_I2C_BLOCK_DATA && i801_set_block_buffer_mode(priv) == 0)
+               result = i801_block_transaction_by_block(priv, data, read_write, hwpec);
+       else
+               result = i801_block_transaction_byte_by_byte(priv, data, read_write, command, hwpec);
+       if (result == 0 && hwpec)
+               i801_wait_hwpec(priv);
+       if (command == I2C_SMBUS_I2C_BLOCK_DATA && read_write == I2C_SMBUS_WRITE) {
+               /* restore saved configuration register value */
+               //TODO: Figure out the right thing to do here...
+               //pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc);
+       }
+       return result;
+}
+
+/* Return negative errno on error. */
+static s32 i801_access(struct i2c_adapter *adap, u16 addr, unsigned short flags, char read_write, u8 command, int size, union i2c_smbus_data *data)
+{
+       int hwpec;
+       int block = 0;
+       int ret, xact = 0;
+       struct i2c_device *priv = i2c_get_adapdata(adap);
+
+       hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK && size != I2C_SMBUS_I2C_BLOCK_DATA;
+
+       switch (size) {
+       case I2C_SMBUS_QUICK:
+               dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_QUICK\n");
+               outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD(priv));
+               xact = I801_QUICK;
+               break;
+       case I2C_SMBUS_BYTE:
+               dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_BYTE\n");
+
+               outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD(priv));
+               if (read_write == I2C_SMBUS_WRITE)
+                       outb_p(command, SMBHSTCMD(priv));
+               xact = I801_BYTE;
+               break;
+       case I2C_SMBUS_BYTE_DATA:
+               dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_BYTE_DATA\n");
+               outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD(priv));
+               outb_p(command, SMBHSTCMD(priv));
+               if (read_write == I2C_SMBUS_WRITE)
+                       outb_p(data->byte, SMBHSTDAT0(priv));
+               xact = I801_BYTE_DATA;
+               break;
+       case I2C_SMBUS_WORD_DATA:
+               dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_WORD_DATA\n");
+               outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD(priv));
+               outb_p(command, SMBHSTCMD(priv));
+               if (read_write == I2C_SMBUS_WRITE) {
+                       outb_p(data->word & 0xff, SMBHSTDAT0(priv));
+                       outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv));
+               }
+               xact = I801_WORD_DATA;
+               break;
+       case I2C_SMBUS_BLOCK_DATA:
+               dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_BLOCK_DATA\n");
+               outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD(priv));
+               outb_p(command, SMBHSTCMD(priv));
+               block = 1;
+               break;
+       case I2C_SMBUS_I2C_BLOCK_DATA:
+               dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_I2C_BLOCK_DATA\n");
+               /* NB: page 240 of ICH5 datasheet shows that the R/#W
+                * bit should be cleared here, even when reading
+                */
+               outb_p((addr & 0x7f) << 1, SMBHSTADD(priv));
+               if (read_write == I2C_SMBUS_READ) {
+                       /* NB: page 240 of ICH5 datasheet also shows
+                        * that DATA1 is the cmd field when reading
+                        */
+                       outb_p(command, SMBHSTDAT1(priv));
+               } else {
+                       outb_p(command, SMBHSTCMD(priv));
+               }
+               block = 1;
+               break;
+       default:
+               dev_dbg(&priv->adapter.dev, "  [acc] Unsupported transaction %d\n", size);
+               return -EOPNOTSUPP;
+       }
+
+       if (hwpec) { /* enable/disable hardware PEC */
+               dev_dbg(&priv->adapter.dev, "  [acc] hwpec: yes\n");
+               outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv));
+       } else {
+               dev_dbg(&priv->adapter.dev, "  [acc] hwpec: no\n");
+               outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC), SMBAUXCTL(priv));
+       }
+
+       if (block) {
+               //ret = 0;
+               dev_dbg(&priv->adapter.dev, "  [acc] block: yes\n");
+               ret = i801_block_transaction(priv, data, read_write, size, hwpec);
+       } else {
+               dev_dbg(&priv->adapter.dev, "  [acc] block: no\n");
+               ret = i801_transaction(priv, xact | ENABLE_INT9);
+       }
+
+       /* Some BIOSes don't like it when PEC is enabled at reboot or resume
+        * time, so we forcibly disable it after every transaction. Turn off
+        * E32B for the same reason.
+        */
+       if (hwpec || block) {
+               dev_dbg(&priv->adapter.dev, "  [acc] hwpec || block\n");
+               outb_p(inb_p(SMBAUXCTL(priv)) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
+       }
+       if (block) {
+               dev_dbg(&priv->adapter.dev, "  [acc] block\n");
+               return ret;
+       }
+       if (ret) {
+               dev_dbg(&priv->adapter.dev, "  [acc] ret %d\n", ret);
+               return ret;
+       }
+       if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK)) {
+               dev_dbg(&priv->adapter.dev, "  [acc] I2C_SMBUS_WRITE || I801_QUICK  -> ret 0\n");
+               return 0;
+       }
+
+       switch (xact & 0x7f) {
+       case I801_BYTE:  /* Result put in SMBHSTDAT0 */
+       case I801_BYTE_DATA:
+               dev_dbg(&priv->adapter.dev, "  [acc] I801_BYTE or I801_BYTE_DATA\n");
+               data->byte = inb_p(SMBHSTDAT0(priv));
+               break;
+       case I801_WORD_DATA:
+               dev_dbg(&priv->adapter.dev, "  [acc] I801_WORD_DATA\n");
+               data->word = inb_p(SMBHSTDAT0(priv)) + (inb_p(SMBHSTDAT1(priv)) << 8);
+               break;
+       }
+       return 0;
+}
+
+static u32 i801_func(struct i2c_adapter *adapter)
+{
+       struct i2c_device *priv = i2c_get_adapdata(adapter);
+
+       /* original settings
+        * u32 f = I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
+        * I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
+        * I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK |
+        * ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) |
+        * ((priv->features & FEATURE_I2C_BLOCK_READ) ?
+        * I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0);
+        */
+
+       // http://lxr.free-electrons.com/source/include/uapi/linux/i2c.h#L85
+
+       u32 f =
+               I2C_FUNC_I2C                     | /* 0x00000001 (I enabled this one) */
+               !I2C_FUNC_10BIT_ADDR             | /* 0x00000002 */
+               !I2C_FUNC_PROTOCOL_MANGLING      | /* 0x00000004 */
+               ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) | /* 0x00000008 */
+               !I2C_FUNC_SMBUS_BLOCK_PROC_CALL  | /* 0x00008000 */
+               I2C_FUNC_SMBUS_QUICK             | /* 0x00010000 */
+               !I2C_FUNC_SMBUS_READ_BYTE        | /* 0x00020000 */
+               !I2C_FUNC_SMBUS_WRITE_BYTE       | /* 0x00040000 */
+               !I2C_FUNC_SMBUS_READ_BYTE_DATA   | /* 0x00080000 */
+               !I2C_FUNC_SMBUS_WRITE_BYTE_DATA  | /* 0x00100000 */
+               !I2C_FUNC_SMBUS_READ_WORD_DATA   | /* 0x00200000 */
+               !I2C_FUNC_SMBUS_WRITE_WORD_DATA  | /* 0x00400000 */
+               !I2C_FUNC_SMBUS_PROC_CALL        | /* 0x00800000 */
+               !I2C_FUNC_SMBUS_READ_BLOCK_DATA  | /* 0x01000000 */
+               !I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | /* 0x02000000 */
+               ((priv->features & FEATURE_I2C_BLOCK_READ) ? I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0) | /* 0x04000000 */
+               I2C_FUNC_SMBUS_WRITE_I2C_BLOCK   | /* 0x08000000 */
+
+               I2C_FUNC_SMBUS_BYTE              | /* _READ_BYTE  _WRITE_BYTE */
+               I2C_FUNC_SMBUS_BYTE_DATA         | /* _READ_BYTE_DATA  _WRITE_BYTE_DATA */
+               I2C_FUNC_SMBUS_WORD_DATA         | /* _READ_WORD_DATA  _WRITE_WORD_DATA */
+               I2C_FUNC_SMBUS_BLOCK_DATA        | /* _READ_BLOCK_DATA  _WRITE_BLOCK_DATA */
+               !I2C_FUNC_SMBUS_I2C_BLOCK        | /* _READ_I2C_BLOCK  _WRITE_I2C_BLOCK */
+               !I2C_FUNC_SMBUS_EMUL;              /* _QUICK  _BYTE  _BYTE_DATA  _WORD_DATA  _PROC_CALL  _WRITE_BLOCK_DATA  _I2C_BLOCK _PEC */
+       return f;
+}
+
+static const struct i2c_algorithm smbus_algorithm = {
+       .smbus_xfer     = i801_access,
+       .functionality  = i801_func,
+};
+
+/********************************
+ *** Part 2 - Driver Handlers ***
+ ********************************/
+static int pi2c_probe(struct platform_device *pldev)
+{
+       int err;
+       struct i2c_device *priv;
+       struct resource *res;
+
+       priv = devm_kzalloc(&pldev->dev, sizeof(*priv), GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;
+
+       i2c_set_adapdata(&priv->adapter, priv);
+       priv->adapter.owner = THIS_MODULE;
+       priv->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
+       priv->adapter.algo = &smbus_algorithm;
+
+       res = platform_get_resource(pldev, IORESOURCE_MEM, 0);
+       if (!res)
+               return -ENXIO;
+
+       priv->smba = (unsigned long)devm_ioremap_nocache(&pldev->dev,
+                                                        res->start,
+                                                        resource_size(res));
+       if (!priv->smba)
+               return -ENOMEM;
+
+       platform_set_drvdata(pldev, priv);
+
+       priv->features |= FEATURE_IDF;
+       priv->features |= FEATURE_I2C_BLOCK_READ;
+       priv->features |= FEATURE_SMBUS_PEC;
+       priv->features |= FEATURE_BLOCK_BUFFER;
+
+       //init_MUTEX(&lddata->sem);
+
+       /* set up the sysfs linkage to our parent device */
+       priv->adapter.dev.parent = &pldev->dev;
+
+       /* Retry up to 3 times on lost arbitration */
+       priv->adapter.retries = 3;
+
+       //snprintf(priv->adapter.name, sizeof(priv->adapter.name), "Fake SMBus I801 adapter at %04lx", priv->smba);
+       snprintf(priv->adapter.name, sizeof(priv->adapter.name), "Fake SMBus I801 adapter");
+
+       err = i2c_add_adapter(&priv->adapter);
+       if (err) {
+               dev_err(&priv->adapter.dev, "Failed to add SMBus adapter\n");
+               return err;
+       }
+
+       return 0;
+}
+
+static int pi2c_remove(struct platform_device *pldev)
+{
+       struct i2c_device *lddev;
+
+       lddev = (struct i2c_device *)platform_get_drvdata(pldev);
+
+       i2c_del_adapter(&lddev->adapter);
+
+       //TODO: Figure out the right thing to do here...
+       //pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
+       //pci_release_region(dev, SMBBAR);
+       //pci_set_drvdata(dev, NULL);
+
+       //cdev_del(&lddev->cdev);
+
+       return 0;
+}
+
+static struct platform_driver i2c_plat_driver_i = {
+       .probe      = pi2c_probe,
+       .remove     = pi2c_remove,
+       .driver     = {
+               .name   = KP_DRIVER_NAME_I2C,
+       },
+};
+
+module_platform_driver(i2c_plat_driver_i);
diff --git a/drivers/staging/kpc2000/kpc2000_spi.c b/drivers/staging/kpc2000/kpc2000_spi.c
new file mode 100644 (file)
index 0000000..35ac1d7
--- /dev/null
@@ -0,0 +1,520 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * KP2000 SPI controller driver
+ *
+ * Copyright (C) 2014-2018 Daktronics
+ * Author: Matt Sickler <matt.sickler@daktronics.com>
+ * Very loosely based on spi-omap2-mcspi.c
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/io-64-nonatomic-lo-hi.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/platform_device.h>
+#include <linux/err.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <linux/pm_runtime.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/gcd.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/flash.h>
+#include <linux/mtd/partitions.h>
+
+#include "kpc.h"
+
+static struct mtd_partition p2kr0_spi0_parts[] = {
+       { .name = "SLOT_0",     .size = 7798784,                .offset = 0,                },
+       { .name = "SLOT_1",     .size = 7798784,                .offset = MTDPART_OFS_NXTBLK},
+       { .name = "SLOT_2",     .size = 7798784,                .offset = MTDPART_OFS_NXTBLK},
+       { .name = "SLOT_3",     .size = 7798784,                .offset = MTDPART_OFS_NXTBLK},
+       { .name = "CS0_EXTRA",  .size = MTDPART_SIZ_FULL,       .offset = MTDPART_OFS_NXTBLK},
+};
+
+static struct mtd_partition p2kr0_spi1_parts[] = {
+       { .name = "SLOT_4",     .size = 7798784,                .offset = 0,                },
+       { .name = "SLOT_5",     .size = 7798784,                .offset = MTDPART_OFS_NXTBLK},
+       { .name = "SLOT_6",     .size = 7798784,                .offset = MTDPART_OFS_NXTBLK},
+       { .name = "SLOT_7",     .size = 7798784,                .offset = MTDPART_OFS_NXTBLK},
+       { .name = "CS1_EXTRA",  .size = MTDPART_SIZ_FULL,       .offset = MTDPART_OFS_NXTBLK},
+};
+
+static struct flash_platform_data p2kr0_spi0_pdata = {
+       .name =         "SPI0",
+       .nr_parts =     ARRAY_SIZE(p2kr0_spi0_parts),
+       .parts =        p2kr0_spi0_parts,
+};
+static struct flash_platform_data p2kr0_spi1_pdata = {
+       .name =         "SPI1",
+       .nr_parts =     ARRAY_SIZE(p2kr0_spi1_parts),
+       .parts =        p2kr0_spi1_parts,
+};
+
+static struct spi_board_info p2kr0_board_info[] = {
+       {
+               .modalias =             "n25q256a11",
+               .bus_num =              1,
+               .chip_select =          0,
+               .mode =                 SPI_MODE_0,
+               .platform_data =        &p2kr0_spi0_pdata
+       },
+       {
+               .modalias =             "n25q256a11",
+               .bus_num =              1,
+               .chip_select =          1,
+               .mode =                 SPI_MODE_0,
+               .platform_data =        &p2kr0_spi1_pdata
+       },
+};
+
+/***************
+ * SPI Defines *
+ ***************/
+#define KP_SPI_REG_CONFIG 0x0 /* 0x00 */
+#define KP_SPI_REG_STATUS 0x1 /* 0x08 */
+#define KP_SPI_REG_FFCTRL 0x2 /* 0x10 */
+#define KP_SPI_REG_TXDATA 0x3 /* 0x18 */
+#define KP_SPI_REG_RXDATA 0x4 /* 0x20 */
+
+#define KP_SPI_CLK           48000000
+#define KP_SPI_MAX_FIFODEPTH 64
+#define KP_SPI_MAX_FIFOWCNT  0xFFFF
+
+#define KP_SPI_REG_CONFIG_TRM_TXRX 0
+#define KP_SPI_REG_CONFIG_TRM_RX   1
+#define KP_SPI_REG_CONFIG_TRM_TX   2
+
+#define KP_SPI_REG_STATUS_RXS   0x01
+#define KP_SPI_REG_STATUS_TXS   0x02
+#define KP_SPI_REG_STATUS_EOT   0x04
+#define KP_SPI_REG_STATUS_TXFFE 0x10
+#define KP_SPI_REG_STATUS_TXFFF 0x20
+#define KP_SPI_REG_STATUS_RXFFE 0x40
+#define KP_SPI_REG_STATUS_RXFFF 0x80
+
+/******************
+ * SPI Structures *
+ ******************/
+struct kp_spi {
+       struct spi_master  *master;
+       u64 __iomem        *base;
+       struct device      *dev;
+};
+
+struct kp_spi_controller_state {
+       void __iomem   *base;
+       s64             conf_cache;
+};
+
+union kp_spi_config {
+       /* use this to access individual elements */
+       struct __packed spi_config_bitfield {
+               unsigned int pha       : 1; /* spim_clk Phase      */
+               unsigned int pol       : 1; /* spim_clk Polarity   */
+               unsigned int epol      : 1; /* spim_csx Polarity   */
+               unsigned int dpe       : 1; /* Transmission Enable */
+               unsigned int wl        : 5; /* Word Length         */
+               unsigned int           : 3;
+               unsigned int trm       : 2; /* TxRx Mode           */
+               unsigned int cs        : 4; /* Chip Select         */
+               unsigned int wcnt      : 7; /* Word Count          */
+               unsigned int ffen      : 1; /* FIFO Enable         */
+               unsigned int spi_en    : 1; /* SPI Enable          */
+               unsigned int           : 5;
+       } bitfield;
+       /* use this to grab the whole register */
+       u32 reg;
+};
+
+union kp_spi_status {
+       struct __packed spi_status_bitfield {
+               unsigned int rx    :  1; /* Rx Status       */
+               unsigned int tx    :  1; /* Tx Status       */
+               unsigned int eo    :  1; /* End of Transfer */
+               unsigned int       :  1;
+               unsigned int txffe :  1; /* Tx FIFO Empty   */
+               unsigned int txfff :  1; /* Tx FIFO Full    */
+               unsigned int rxffe :  1; /* Rx FIFO Empty   */
+               unsigned int rxfff :  1; /* Rx FIFO Full    */
+               unsigned int       : 24;
+       } bitfield;
+       u32 reg;
+};
+
+union kp_spi_ffctrl {
+       struct __packed spi_ffctrl_bitfield {
+               unsigned int ffstart :  1; /* FIFO Start */
+               unsigned int         : 31;
+       } bitfield;
+       u32 reg;
+};
+
+/***************
+ * SPI Helpers *
+ ***************/
+       static inline u64
+kp_spi_read_reg(struct kp_spi_controller_state *cs, int idx)
+{
+       u64 __iomem *addr = cs->base;
+       u64 val;
+
+       addr += idx;
+       if ((idx == KP_SPI_REG_CONFIG) && (cs->conf_cache >= 0))
+               return cs->conf_cache;
+
+       val = readq(addr);
+       return val;
+}
+
+       static inline void
+kp_spi_write_reg(struct kp_spi_controller_state *cs, int idx, u64 val)
+{
+       u64 __iomem *addr = cs->base;
+
+       addr += idx;
+       writeq(val, addr);
+       if (idx == KP_SPI_REG_CONFIG)
+               cs->conf_cache = val;
+}
+
+       static int
+kp_spi_wait_for_reg_bit(struct kp_spi_controller_state *cs, int idx,
+                       unsigned long bit)
+{
+       unsigned long timeout;
+
+       timeout = jiffies + msecs_to_jiffies(1000);
+       while (!(kp_spi_read_reg(cs, idx) & bit)) {
+               if (time_after(jiffies, timeout)) {
+                       if (!(kp_spi_read_reg(cs, idx) & bit))
+                               return -ETIMEDOUT;
+                       else
+                               return 0;
+               }
+               cpu_relax();
+       }
+       return 0;
+}
+
+       static unsigned
+kp_spi_txrx_pio(struct spi_device *spidev, struct spi_transfer *transfer)
+{
+       struct kp_spi_controller_state *cs = spidev->controller_state;
+       unsigned int count = transfer->len;
+       unsigned int c = count;
+
+       int i;
+       int res;
+       u8 *rx       = transfer->rx_buf;
+       const u8 *tx = transfer->tx_buf;
+       int processed = 0;
+
+       if (tx) {
+               for (i = 0 ; i < c ; i++) {
+                       char val = *tx++;
+
+                       res = kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS,
+                                                     KP_SPI_REG_STATUS_TXS);
+                       if (res < 0)
+                               goto out;
+
+                       kp_spi_write_reg(cs, KP_SPI_REG_TXDATA, val);
+                       processed++;
+               }
+       }
+       else if (rx) {
+               for (i = 0 ; i < c ; i++) {
+                       char test = 0;
+
+                       kp_spi_write_reg(cs, KP_SPI_REG_TXDATA, 0x00);
+                       res = kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS,
+                                                     KP_SPI_REG_STATUS_RXS);
+                       if (res < 0)
+                               goto out;
+
+                       test = kp_spi_read_reg(cs, KP_SPI_REG_RXDATA);
+                       *rx++ = test;
+                       processed++;
+               }
+       }
+
+       if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS,
+                                   KP_SPI_REG_STATUS_EOT) < 0) {
+               //TODO: Figure out how to abort transaction??
+               //Ths has never happened in practice though...
+       }
+
+out:
+       return processed;
+}
+
+/*****************
+ * SPI Functions *
+ *****************/
+       static int
+kp_spi_setup(struct spi_device *spidev)
+{
+       union kp_spi_config sc;
+       struct kp_spi *kpspi = spi_master_get_devdata(spidev->master);
+       struct kp_spi_controller_state *cs;
+
+       /* setup controller state */
+       cs = spidev->controller_state;
+       if (!cs) {
+               cs = kzalloc(sizeof(*cs), GFP_KERNEL);
+               if (!cs)
+                       return -ENOMEM;
+               cs->base = kpspi->base;
+               cs->conf_cache = -1;
+               spidev->controller_state = cs;
+       }
+
+       /* set config register */
+       sc.bitfield.wl = spidev->bits_per_word - 1;
+       sc.bitfield.cs = spidev->chip_select;
+       sc.bitfield.spi_en = 0;
+       sc.bitfield.trm = 0;
+       sc.bitfield.ffen = 0;
+       kp_spi_write_reg(spidev->controller_state, KP_SPI_REG_CONFIG, sc.reg);
+       return 0;
+}
+
+       static int
+kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
+{
+       struct kp_spi_controller_state *cs;
+       struct spi_device   *spidev;
+       struct kp_spi       *kpspi;
+       struct spi_transfer *transfer;
+       union kp_spi_config sc;
+       int status = 0;
+
+       spidev = m->spi;
+       kpspi = spi_master_get_devdata(master);
+       m->actual_length = 0;
+       m->status = 0;
+
+       cs = spidev->controller_state;
+
+       /* reject invalid messages and transfers */
+       if (list_empty(&m->transfers))
+               return -EINVAL;
+
+       /* validate input */
+       list_for_each_entry(transfer, &m->transfers, transfer_list) {
+               const void *tx_buf = transfer->tx_buf;
+               void       *rx_buf = transfer->rx_buf;
+               unsigned int len = transfer->len;
+
+               if (transfer->speed_hz > KP_SPI_CLK ||
+                   (len && !(rx_buf || tx_buf))) {
+                       dev_dbg(kpspi->dev, "  transfer: %d Hz, %d %s%s, %d bpw\n",
+                                       transfer->speed_hz,
+                                       len,
+                                       tx_buf ? "tx" : "",
+                                       rx_buf ? "rx" : "",
+                                       transfer->bits_per_word);
+                       dev_dbg(kpspi->dev, "  transfer -EINVAL\n");
+                       return -EINVAL;
+               }
+               if (transfer->speed_hz &&
+                   transfer->speed_hz < (KP_SPI_CLK >> 15)) {
+                       dev_dbg(kpspi->dev, "speed_hz %d below minimum %d Hz\n",
+                                       transfer->speed_hz,
+                                       KP_SPI_CLK >> 15);
+                       dev_dbg(kpspi->dev, "  speed_hz -EINVAL\n");
+                       return -EINVAL;
+               }
+       }
+
+       /* assert chip select to start the sequence*/
+       sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
+       sc.bitfield.spi_en = 1;
+       kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
+
+       /* work */
+       if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS,
+                                   KP_SPI_REG_STATUS_EOT) < 0) {
+               dev_info(kpspi->dev, "EOT timed out\n");
+               goto out;
+       }
+
+       /* do the transfers for this message */
+       list_for_each_entry(transfer, &m->transfers, transfer_list) {
+               if (!transfer->tx_buf && !transfer->rx_buf &&
+                   transfer->len) {
+                       status = -EINVAL;
+                       goto error;
+               }
+
+               /* transfer */
+               if (transfer->len) {
+                       unsigned int word_len = spidev->bits_per_word;
+                       unsigned int count;
+
+                       /* set up the transfer... */
+                       sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
+
+                       /* ...direction */
+                       if (transfer->tx_buf)
+                               sc.bitfield.trm = KP_SPI_REG_CONFIG_TRM_TX;
+                       else if (transfer->rx_buf)
+                               sc.bitfield.trm = KP_SPI_REG_CONFIG_TRM_RX;
+
+                       /* ...word length */
+                       if (transfer->bits_per_word)
+                               word_len = transfer->bits_per_word;
+                       sc.bitfield.wl = word_len - 1;
+
+                       /* ...chip select */
+                       sc.bitfield.cs = spidev->chip_select;
+
+                       /* ...and write the new settings */
+                       kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
+
+                       /* do the transfer */
+                       count = kp_spi_txrx_pio(spidev, transfer);
+                       m->actual_length += count;
+
+                       if (count != transfer->len) {
+                               status = -EIO;
+                               goto error;
+                       }
+               }
+
+               if (transfer->delay_usecs)
+                       udelay(transfer->delay_usecs);
+       }
+
+       /* de-assert chip select to end the sequence */
+       sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
+       sc.bitfield.spi_en = 0;
+       kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
+
+out:
+       /* done work */
+       spi_finalize_current_message(master);
+       return 0;
+
+error:
+       m->status = status;
+       return status;
+}
+
+       static void
+kp_spi_cleanup(struct spi_device *spidev)
+{
+       struct kp_spi_controller_state *cs = spidev->controller_state;
+
+       if (cs)
+               kfree(cs);
+}
+
+/******************
+ * Probe / Remove *
+ ******************/
+       static int
+kp_spi_probe(struct platform_device *pldev)
+{
+       struct kpc_core_device_platdata *drvdata;
+       struct spi_master *master;
+       struct kp_spi *kpspi;
+       struct resource *r;
+       int status = 0;
+       int i;
+
+       drvdata = pldev->dev.platform_data;
+       if (!drvdata) {
+               dev_err(&pldev->dev, "%s: platform_data is NULL\n", __func__);
+               return -ENODEV;
+       }
+
+       master = spi_alloc_master(&pldev->dev, sizeof(struct kp_spi));
+       if (!master) {
+               dev_err(&pldev->dev, "%s: master allocation failed\n",
+                       __func__);
+               return -ENOMEM;
+       }
+
+       /* set up the spi functions */
+       master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
+       master->bits_per_word_mask = (unsigned int)SPI_BPW_RANGE_MASK(4, 32);
+       master->setup = kp_spi_setup;
+       master->transfer_one_message = kp_spi_transfer_one_message;
+       master->cleanup = kp_spi_cleanup;
+
+       platform_set_drvdata(pldev, master);
+
+       kpspi = spi_master_get_devdata(master);
+       kpspi->master = master;
+       kpspi->dev = &pldev->dev;
+
+       master->num_chipselect = 4;
+       if (pldev->id != -1)
+               master->bus_num = pldev->id;
+
+       r = platform_get_resource(pldev, IORESOURCE_MEM, 0);
+       if (!r) {
+               dev_err(&pldev->dev, "%s: Unable to get platform resources\n",
+                       __func__);
+               status = -ENODEV;
+               goto free_master;
+       }
+
+       kpspi->base = devm_ioremap_nocache(&pldev->dev, r->start,
+                                          resource_size(r));
+
+       status = spi_register_master(master);
+       if (status < 0) {
+               dev_err(&pldev->dev, "Unable to register SPI device\n");
+               goto free_master;
+       }
+
+       /* register the slave boards */
+#define NEW_SPI_DEVICE_FROM_BOARD_INFO_TABLE(table) \
+       for (i = 0 ; i < ARRAY_SIZE(table) ; i++) { \
+               spi_new_device(master, &(table[i])); \
+       }
+
+       switch ((drvdata->card_id & 0xFFFF0000) >> 16) {
+       case PCI_DEVICE_ID_DAKTRONICS_KADOKA_P2KR0:
+               NEW_SPI_DEVICE_FROM_BOARD_INFO_TABLE(p2kr0_board_info);
+               break;
+       default:
+               dev_err(&pldev->dev, "Unknown hardware, cant know what partition table to use!\n");
+               goto free_master;
+       }
+
+       return status;
+
+free_master:
+       spi_master_put(master);
+       return status;
+}
+
+       static int
+kp_spi_remove(struct platform_device *pldev)
+{
+       struct spi_master *master = platform_get_drvdata(pldev);
+
+       spi_unregister_master(master);
+       return 0;
+}
+
+static struct platform_driver kp_spi_driver = {
+       .driver = {
+               .name =     KP_DRIVER_NAME_SPI,
+       },
+       .probe =    kp_spi_probe,
+       .remove =   kp_spi_remove,
+};
+
+module_platform_driver(kp_spi_driver);
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:kp_spi");
index 6959bac11388a1b0b1caf32c77074608831af5e0..51a4dd534a0dc2839fae52dc75b6c32d2ad77ed3 100644 (file)
@@ -2,7 +2,7 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/types.h>
-#include <asm/io.h>
+#include <linux/io.h>
 #include <linux/export.h>
 #include <linux/slab.h>
 #include <linux/platform_device.h>
 static
 irqreturn_t  ndd_irq_handler(int irq, void *dev_id)
 {
-       struct kpc_dma_device *ldev = (struct kpc_dma_device*)dev_id;
-       
+       struct kpc_dma_device *ldev = (struct kpc_dma_device *)dev_id;
+
        if ((GetEngineControl(ldev) & ENG_CTL_IRQ_ACTIVE) || (ldev->desc_completed->MyDMAAddr != GetEngineCompletePtr(ldev)))
                schedule_work(&ldev->irq_work);
-       
+
        return IRQ_HANDLED;
 }
 
@@ -27,217 +27,215 @@ void  ndd_irq_worker(struct work_struct *ws)
 {
        struct kpc_dma_descriptor *cur;
        struct kpc_dma_device *eng = container_of(ws, struct kpc_dma_device, irq_work);
+
        lock_engine(eng);
-       
+
        if (GetEngineCompletePtr(eng) == 0)
                goto out;
-       
+
        if (eng->desc_completed->MyDMAAddr == GetEngineCompletePtr(eng))
                goto out;
-       
+
        cur = eng->desc_completed;
        do {
                cur = cur->Next;
                dev_dbg(&eng->pldev->dev, "Handling completed descriptor %p (acd = %p)\n", cur, cur->acd);
                BUG_ON(cur == eng->desc_next); // Ordering failure.
-               
-               if (cur->DescControlFlags & DMA_DESC_CTL_SOP){
+
+               if (cur->DescControlFlags & DMA_DESC_CTL_SOP) {
                        eng->accumulated_bytes = 0;
                        eng->accumulated_flags = 0;
                }
-               
+
                eng->accumulated_bytes += cur->DescByteCount;
                if (cur->DescStatusFlags & DMA_DESC_STS_ERROR)
                        eng->accumulated_flags |= ACD_FLAG_ENG_ACCUM_ERROR;
-               
+
                if (cur->DescStatusFlags & DMA_DESC_STS_SHORT)
                        eng->accumulated_flags |= ACD_FLAG_ENG_ACCUM_SHORT;
-               
-               if (cur->DescControlFlags & DMA_DESC_CTL_EOP){
+
+               if (cur->DescControlFlags & DMA_DESC_CTL_EOP) {
                        if (cur->acd)
                                transfer_complete_cb(cur->acd, eng->accumulated_bytes, eng->accumulated_flags | ACD_FLAG_DONE);
                }
-               
+
                eng->desc_completed = cur;
        } while (cur->MyDMAAddr != GetEngineCompletePtr(eng));
-       
+
  out:
        SetClearEngineControl(eng, ENG_CTL_IRQ_ACTIVE, 0);
-       
+
        unlock_engine(eng);
 }
 
-
 /**********  DMA Engine Init/Teardown  **********/
 void  start_dma_engine(struct kpc_dma_device *eng)
 {
        eng->desc_next       = eng->desc_pool_first;
        eng->desc_completed  = eng->desc_pool_last;
-       
+
        // Setup the engine pointer registers
        SetEngineNextPtr(eng, eng->desc_pool_first);
        SetEngineSWPtr(eng, eng->desc_pool_first);
        ClearEngineCompletePtr(eng);
-       
+
        WriteEngineControl(eng, ENG_CTL_DMA_ENABLE | ENG_CTL_IRQ_ENABLE);
 }
 
 int  setup_dma_engine(struct kpc_dma_device *eng, u32 desc_cnt)
 {
        u32 caps;
-       struct kpc_dma_descriptor * cur;
-       struct kpc_dma_descriptor * next;
+       struct kpc_dma_descriptor *cur;
+       struct kpc_dma_descriptor *next;
        dma_addr_t next_handle;
        dma_addr_t head_handle;
        unsigned int i;
        int rv;
-       dev_dbg(&eng->pldev->dev, "Setting up DMA engine [%p]\n", eng);
-       
+
        caps = GetEngineCapabilities(eng);
-       
-       if (WARN(!(caps & ENG_CAP_PRESENT), "setup_dma_engine() called for DMA Engine at %p which isn't present in hardware!\n", eng))
+
+       if (WARN(!(caps & ENG_CAP_PRESENT), "%s() called for DMA Engine at %p which isn't present in hardware!\n", __func__, eng))
                return -ENXIO;
-       
-       if (caps & ENG_CAP_DIRECTION){
+
+       if (caps & ENG_CAP_DIRECTION) {
                eng->dir = DMA_FROM_DEVICE;
        } else {
                eng->dir = DMA_TO_DEVICE;
        }
-       
+
        eng->desc_pool_cnt = desc_cnt;
        eng->desc_pool = dma_pool_create("KPC DMA Descriptors", &eng->pldev->dev, sizeof(struct kpc_dma_descriptor), DMA_DESC_ALIGNMENT, 4096);
-       
+
        eng->desc_pool_first = dma_pool_alloc(eng->desc_pool, GFP_KERNEL | GFP_DMA, &head_handle);
-       if (!eng->desc_pool_first){
-               dev_err(&eng->pldev->dev, "setup_dma_engine: couldn't allocate desc_pool_first!\n");
+       if (!eng->desc_pool_first) {
+               dev_err(&eng->pldev->dev, "%s: couldn't allocate desc_pool_first!\n", __func__);
                dma_pool_destroy(eng->desc_pool);
                return -ENOMEM;
        }
-       
+
        eng->desc_pool_first->MyDMAAddr = head_handle;
        clear_desc(eng->desc_pool_first);
-       
+
        cur = eng->desc_pool_first;
-       for (i = 1 ; i < eng->desc_pool_cnt ; i++){
+       for (i = 1 ; i < eng->desc_pool_cnt ; i++) {
                next = dma_pool_alloc(eng->desc_pool, GFP_KERNEL | GFP_DMA, &next_handle);
-               if (next == NULL)
+               if (!next)
                        goto done_alloc;
-               
+
                clear_desc(next);
                next->MyDMAAddr = next_handle;
-               
+
                cur->DescNextDescPtr = next_handle;
                cur->Next = next;
                cur = next;
        }
-       
+
  done_alloc:
        // Link the last descriptor back to the first, so it's a circular linked list
        cur->Next = eng->desc_pool_first;
        cur->DescNextDescPtr = eng->desc_pool_first->MyDMAAddr;
-       
+
        eng->desc_pool_last = cur;
        eng->desc_completed = eng->desc_pool_last;
-       
+
        // Setup work queue
        INIT_WORK(&eng->irq_work, ndd_irq_worker);
-       
+
        // Grab IRQ line
        rv = request_irq(eng->irq, ndd_irq_handler, IRQF_SHARED, KP_DRIVER_NAME_DMA_CONTROLLER, eng);
-       if (rv){
-               dev_err(&eng->pldev->dev, "setup_dma_engine: failed to request_irq: %d\n", rv);
+       if (rv) {
+               dev_err(&eng->pldev->dev, "%s: failed to request_irq: %d\n", __func__, rv);
                return rv;
        }
-       
+
        // Turn on the engine!
        start_dma_engine(eng);
        unlock_engine(eng);
-       
+
        return 0;
 }
 
 void  stop_dma_engine(struct kpc_dma_device *eng)
 {
        unsigned long timeout;
-       dev_dbg(&eng->pldev->dev, "Destroying DMA engine [%p]\n", eng);
-       
+
        // Disable the descriptor engine
        WriteEngineControl(eng, 0);
-       
+
        // Wait for descriptor engine to finish current operaion
        timeout = jiffies + (HZ / 2);
-       while (GetEngineControl(eng) & ENG_CTL_DMA_RUNNING){
-               if (time_after(jiffies, timeout)){
+       while (GetEngineControl(eng) & ENG_CTL_DMA_RUNNING) {
+               if (time_after(jiffies, timeout)) {
                        dev_crit(&eng->pldev->dev, "DMA_RUNNING still asserted!\n");
                        break;
                }
        }
-       
+
        // Request a reset
        WriteEngineControl(eng, ENG_CTL_DMA_RESET_REQUEST);
-       
+
        // Wait for reset request to be processed
        timeout = jiffies + (HZ / 2);
-       while (GetEngineControl(eng) & (ENG_CTL_DMA_RUNNING | ENG_CTL_DMA_RESET_REQUEST)){
-               if (time_after(jiffies, timeout)){
+       while (GetEngineControl(eng) & (ENG_CTL_DMA_RUNNING | ENG_CTL_DMA_RESET_REQUEST)) {
+               if (time_after(jiffies, timeout)) {
                        dev_crit(&eng->pldev->dev, "ENG_CTL_DMA_RESET_REQUEST still asserted!\n");
                        break;
                }
        }
-       
+
        // Request a reset
        WriteEngineControl(eng, ENG_CTL_DMA_RESET);
-       
+
        // And wait for reset to complete
        timeout = jiffies + (HZ / 2);
-       while (GetEngineControl(eng) & ENG_CTL_DMA_RESET){
-               if (time_after(jiffies, timeout)){
+       while (GetEngineControl(eng) & ENG_CTL_DMA_RESET) {
+               if (time_after(jiffies, timeout)) {
                        dev_crit(&eng->pldev->dev, "DMA_RESET still asserted!\n");
                        break;
                }
        }
-       
+
        // Clear any persistent bits just to make sure there is no residue from the reset
        SetClearEngineControl(eng, (ENG_CTL_IRQ_ACTIVE | ENG_CTL_DESC_COMPLETE | ENG_CTL_DESC_ALIGN_ERR | ENG_CTL_DESC_FETCH_ERR | ENG_CTL_SW_ABORT_ERR | ENG_CTL_DESC_CHAIN_END | ENG_CTL_DMA_WAITING_PERSIST), 0);
-       
+
        // Reset performance counters
-       
+
        // Completely disable the engine
        WriteEngineControl(eng, 0);
 }
 
 void  destroy_dma_engine(struct kpc_dma_device *eng)
 {
-       struct kpc_dma_descriptor * cur;
+       struct kpc_dma_descriptor *cur;
        dma_addr_t cur_handle;
        unsigned int i;
-       
+
        stop_dma_engine(eng);
-       
+
        cur = eng->desc_pool_first;
        cur_handle = eng->desc_pool_first->MyDMAAddr;
-       
-       for (i = 0 ; i < eng->desc_pool_cnt ; i++){
+
+       for (i = 0 ; i < eng->desc_pool_cnt ; i++) {
                struct kpc_dma_descriptor *next = cur->Next;
                dma_addr_t next_handle = cur->DescNextDescPtr;
+
                dma_pool_free(eng->desc_pool, cur, cur_handle);
                cur_handle = next_handle;
                cur = next;
        }
-       
+
        dma_pool_destroy(eng->desc_pool);
-       
+
        free_irq(eng->irq, eng);
 }
 
-
-
 /**********  Helper Functions  **********/
 int  count_descriptors_available(struct kpc_dma_device *eng)
 {
        u32 count = 0;
        struct kpc_dma_descriptor *cur = eng->desc_next;
-       while (cur != eng->desc_completed){
+
+       while (cur != eng->desc_completed) {
                BUG_ON(cur == NULL);
                count++;
                cur = cur->Next;
@@ -247,7 +245,7 @@ int  count_descriptors_available(struct kpc_dma_device *eng)
 
 void  clear_desc(struct kpc_dma_descriptor *desc)
 {
-       if (desc == NULL)
+       if (!desc)
                return;
        desc->DescByteCount         = 0;
        desc->DescStatusErrorFlags  = 0;
index 616658709bd9aad6e4ceb9fabea66941c9787821..48ca88bc6b0b4166accbc7ab0771d008593175e8 100644 (file)
@@ -9,7 +9,6 @@
 #include <linux/types.h>    /* size_t */
 #include <linux/cdev.h>
 #include <linux/uaccess.h>  /* copy_*_user */
-#include <linux/aio.h>      /* aio stuff */
 #include <linux/highmem.h>
 #include <linux/pagemap.h>
 #include "kpc_dma_driver.h"
@@ -21,20 +20,19 @@ unsigned int  count_pages(unsigned long iov_base, size_t iov_len)
 {
        unsigned long first = (iov_base             & PAGE_MASK) >> PAGE_SHIFT;
        unsigned long last  = ((iov_base+iov_len-1) & PAGE_MASK) >> PAGE_SHIFT;
+
        return last - first + 1;
 }
 
 static inline
 unsigned int  count_parts_for_sge(struct scatterlist *sg)
 {
-       unsigned int sg_length = sg_dma_len(sg);
-       sg_length += (0x80000-1);
-       return (sg_length / 0x80000);
+       return DIV_ROUND_UP(sg_dma_len(sg), 0x80000);
 }
 
 /**********  Transfer Helpers  **********/
-static
-int  kpc_dma_transfer(struct dev_private_data *priv, struct kiocb *kcb, unsigned long iov_base, size_t iov_len)
+static int kpc_dma_transfer(struct dev_private_data *priv,
+                           unsigned long iov_base, size_t iov_len)
 {
        unsigned int i = 0;
        long rv = 0;
@@ -50,75 +48,72 @@ int  kpc_dma_transfer(struct dev_private_data *priv, struct kiocb *kcb, unsigned
        u64 card_addr;
        u64 dma_addr;
        u64 user_ctl;
-       
+
        BUG_ON(priv == NULL);
        ldev = priv->ldev;
        BUG_ON(ldev == NULL);
-       
-       dev_dbg(&priv->ldev->pldev->dev, "kpc_dma_transfer(priv = [%p], kcb = [%p], iov_base = [%p], iov_len = %ld) ldev = [%p]\n", priv, kcb, (void*)iov_base, iov_len, ldev);
-       
-       acd = (struct aio_cb_data *) kzalloc(sizeof(struct aio_cb_data), GFP_KERNEL);
-       if (!acd){
+
+       acd = kzalloc(sizeof(*acd), GFP_KERNEL);
+       if (!acd) {
                dev_err(&priv->ldev->pldev->dev, "Couldn't kmalloc space for for the aio data\n");
                return -ENOMEM;
        }
        memset(acd, 0x66, sizeof(struct aio_cb_data));
-       
+
        acd->priv = priv;
        acd->ldev = priv->ldev;
        acd->cpl = &done;
        acd->flags = 0;
-       acd->kcb = kcb;
        acd->len = iov_len;
        acd->page_count = count_pages(iov_base, iov_len);
-       
+
        // Allocate an array of page pointers
        acd->user_pages = kzalloc(sizeof(struct page *) * acd->page_count, GFP_KERNEL);
-       if (!acd->user_pages){
+       if (!acd->user_pages) {
                dev_err(&priv->ldev->pldev->dev, "Couldn't kmalloc space for for the page pointers\n");
                rv = -ENOMEM;
                goto err_alloc_userpages;
        }
-       
+
        // Lock the user buffer pages in memory, and hold on to the page pointers (for the sglist)
        down_read(&current->mm->mmap_sem);      /*  get memory map semaphore */
        rv = get_user_pages(iov_base, acd->page_count, FOLL_TOUCH | FOLL_WRITE | FOLL_GET, acd->user_pages, NULL);
        up_read(&current->mm->mmap_sem);        /*  release the semaphore */
-       if (rv != acd->page_count){
+       if (rv != acd->page_count) {
                dev_err(&priv->ldev->pldev->dev, "Couldn't get_user_pages (%ld)\n", rv);
                goto err_get_user_pages;
        }
-       
+
        // Allocate and setup the sg_table (scatterlist entries)
        rv = sg_alloc_table_from_pages(&acd->sgt, acd->user_pages, acd->page_count, iov_base & (PAGE_SIZE-1), iov_len, GFP_KERNEL);
-       if (rv){
+       if (rv) {
                dev_err(&priv->ldev->pldev->dev, "Couldn't alloc sg_table (%ld)\n", rv);
                goto err_alloc_sg_table;
        }
-       
+
        // Setup the DMA mapping for all the sg entries
        acd->mapped_entry_count = dma_map_sg(&ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, ldev->dir);
-       if (acd->mapped_entry_count <= 0){
+       if (acd->mapped_entry_count <= 0) {
                dev_err(&priv->ldev->pldev->dev, "Couldn't dma_map_sg (%d)\n", acd->mapped_entry_count);
                goto err_dma_map_sg;
        }
 
        // Calculate how many descriptors are actually needed for this transfer.
-       for_each_sg(acd->sgt.sgl, sg, acd->mapped_entry_count, i){
+       for_each_sg(acd->sgt.sgl, sg, acd->mapped_entry_count, i) {
                desc_needed += count_parts_for_sge(sg);
        }
-       
+
        lock_engine(ldev);
-       
+
        // Figoure out how many descriptors are available and return an error if there aren't enough
        num_descrs_avail = count_descriptors_available(ldev);
        dev_dbg(&priv->ldev->pldev->dev, "    mapped_entry_count = %d    num_descrs_needed = %d    num_descrs_avail = %d\n", acd->mapped_entry_count, desc_needed, num_descrs_avail);
-       if (desc_needed >= ldev->desc_pool_cnt){
+       if (desc_needed >= ldev->desc_pool_cnt) {
                dev_warn(&priv->ldev->pldev->dev, "    mapped_entry_count = %d    num_descrs_needed = %d    num_descrs_avail = %d    TOO MANY to ever complete!\n", acd->mapped_entry_count, desc_needed, num_descrs_avail);
                rv = -EAGAIN;
                goto err_descr_too_many;
        }
-       if (desc_needed > num_descrs_avail){
+       if (desc_needed > num_descrs_avail) {
                dev_warn(&priv->ldev->pldev->dev, "    mapped_entry_count = %d    num_descrs_needed = %d    num_descrs_avail = %d    Too many to complete right now.\n", acd->mapped_entry_count, desc_needed, num_descrs_avail);
                rv = -EMSGSIZE;
                goto err_descr_too_many;
@@ -127,70 +122,67 @@ int  kpc_dma_transfer(struct dev_private_data *priv, struct kiocb *kcb, unsigned
        // Loop through all the sg table entries and fill out a descriptor for each one.
        desc = ldev->desc_next;
        card_addr = acd->priv->card_addr;
-       for_each_sg(acd->sgt.sgl, sg, acd->mapped_entry_count, i){
+       for_each_sg(acd->sgt.sgl, sg, acd->mapped_entry_count, i) {
                pcnt = count_parts_for_sge(sg);
-               for (p = 0 ; p < pcnt ; p++){
+               for (p = 0 ; p < pcnt ; p++) {
                        // Fill out the descriptor
                        BUG_ON(desc == NULL);
                        clear_desc(desc);
-                       if (p != pcnt-1){
+                       if (p != pcnt-1) {
                                desc->DescByteCount = 0x80000;
                        } else {
                                desc->DescByteCount = sg_dma_len(sg) - (p * 0x80000);
                        }
                        desc->DescBufferByteCount = desc->DescByteCount;
-                       
+
                        desc->DescControlFlags |= DMA_DESC_CTL_IRQONERR;
                        if (i == 0 && p == 0)
                                desc->DescControlFlags |= DMA_DESC_CTL_SOP;
                        if (i == acd->mapped_entry_count-1 && p == pcnt-1)
                                desc->DescControlFlags |= DMA_DESC_CTL_EOP | DMA_DESC_CTL_IRQONDONE;
-                       
+
                        desc->DescCardAddrLS = (card_addr & 0xFFFFFFFF);
                        desc->DescCardAddrMS = (card_addr >> 32) & 0xF;
                        card_addr += desc->DescByteCount;
-                       
+
                        dma_addr  = sg_dma_address(sg) + (p * 0x80000);
                        desc->DescSystemAddrLS = (dma_addr & 0x00000000FFFFFFFF) >>  0;
                        desc->DescSystemAddrMS = (dma_addr & 0xFFFFFFFF00000000) >> 32;
-                       
+
                        user_ctl = acd->priv->user_ctl;
-                       if (i == acd->mapped_entry_count-1 && p == pcnt-1){
+                       if (i == acd->mapped_entry_count-1 && p == pcnt-1) {
                                user_ctl = acd->priv->user_ctl_last;
                        }
                        desc->DescUserControlLS = (user_ctl & 0x00000000FFFFFFFF) >>  0;
                        desc->DescUserControlMS = (user_ctl & 0xFFFFFFFF00000000) >> 32;
-                       
+
                        if (i == acd->mapped_entry_count-1 && p == pcnt-1)
                                desc->acd = acd;
-                       
+
                        dev_dbg(&priv->ldev->pldev->dev, "  Filled descriptor %p (acd = %p)\n", desc, desc->acd);
-                       
+
                        ldev->desc_next = desc->Next;
                        desc = desc->Next;
                }
        }
-       
+
        // Send the filled descriptors off to the hardware to process!
        SetEngineSWPtr(ldev, ldev->desc_next);
-       
+
        unlock_engine(ldev);
-       
-       // If this is a synchronous kiocb, we need to put the calling process to sleep until the transfer is complete
-       if (kcb == NULL || is_sync_kiocb(kcb)){
-               rv = wait_for_completion_interruptible(&done);
-               // If the user aborted (rv == -ERESTARTSYS), we're no longer responsible for cleaning up the acd
-               if (rv == -ERESTARTSYS){
-                       acd->cpl = NULL;
-               }
-               if (rv == 0){
-                       rv = acd->len;
-                       kfree(acd);
-               }
-               return rv;
+
+       rv = wait_for_completion_interruptible(&done);
+       /*
+        * If the user aborted (rv == -ERESTARTSYS), we're no longer responsible
+        * for cleaning up the acd
+        */
+       if (rv == -ERESTARTSYS)
+               acd->cpl = NULL;
+       if (rv == 0) {
+               rv = acd->len;
+               kfree(acd);
        }
-       
-       return -EIOCBQUEUED;
+       return rv;
 
  err_descr_too_many:
        unlock_engine(ldev);
@@ -198,58 +190,52 @@ int  kpc_dma_transfer(struct dev_private_data *priv, struct kiocb *kcb, unsigned
        sg_free_table(&acd->sgt);
  err_dma_map_sg:
  err_alloc_sg_table:
-       for (i = 0 ; i < acd->page_count ; i++){
+       for (i = 0 ; i < acd->page_count ; i++) {
                put_page(acd->user_pages[i]);
        }
  err_get_user_pages:
        kfree(acd->user_pages);
  err_alloc_userpages:
        kfree(acd);
-       dev_dbg(&priv->ldev->pldev->dev, "kpc_dma_transfer returning with error %ld\n", rv);
+       dev_dbg(&priv->ldev->pldev->dev, "%s returning with error %ld\n", __func__, rv);
        return rv;
 }
 
 void  transfer_complete_cb(struct aio_cb_data *acd, size_t xfr_count, u32 flags)
 {
        unsigned int i;
-       
+
        BUG_ON(acd == NULL);
        BUG_ON(acd->user_pages == NULL);
        BUG_ON(acd->sgt.sgl == NULL);
        BUG_ON(acd->ldev == NULL);
        BUG_ON(acd->ldev->pldev == NULL);
-       
-       dev_dbg(&acd->ldev->pldev->dev, "transfer_complete_cb(acd = [%p])\n", acd);
-       
-       for (i = 0 ; i < acd->page_count ; i++){
-               if (!PageReserved(acd->user_pages[i])){
+
+       for (i = 0 ; i < acd->page_count ; i++) {
+               if (!PageReserved(acd->user_pages[i])) {
                        set_page_dirty(acd->user_pages[i]);
                }
        }
-       
+
        dma_unmap_sg(&acd->ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, acd->ldev->dir);
-       
-       for (i = 0 ; i < acd->page_count ; i++){
+
+       for (i = 0 ; i < acd->page_count ; i++) {
                put_page(acd->user_pages[i]);
        }
-       
+
        sg_free_table(&acd->sgt);
-       
+
        kfree(acd->user_pages);
-       
+
        acd->flags = flags;
-       
-       if (acd->kcb == NULL || is_sync_kiocb(acd->kcb)){
-               if (acd->cpl){
-                       complete(acd->cpl);
-               } else {
-                       // There's no completion, so we're responsible for cleaning up the acd
-                       kfree(acd);
-               }
+
+       if (acd->cpl) {
+               complete(acd->cpl);
        } else {
-#ifdef CONFIG_KPC_DMA_AIO
-               aio_complete(acd->kcb, acd->len, acd->flags);
-#endif
+               /*
+                * There's no completion, so we're responsible for cleaning up
+                * the acd
+                */
                kfree(acd);
        }
 }
@@ -260,22 +246,22 @@ int  kpc_dma_open(struct inode *inode, struct file *filp)
 {
        struct dev_private_data *priv;
        struct kpc_dma_device *ldev = kpc_dma_lookup_device(iminor(inode));
-       if (ldev == NULL)
+
+       if (!ldev)
                return -ENODEV;
-       
-       if (! atomic_dec_and_test(&ldev->open_count)){
+
+       if (!atomic_dec_and_test(&ldev->open_count)) {
                atomic_inc(&ldev->open_count);
                return -EBUSY; /* already open */
        }
-       
+
        priv = kzalloc(sizeof(struct dev_private_data), GFP_KERNEL);
        if (!priv)
                return -ENOMEM;
-       
+
        priv->ldev = ldev;
        filp->private_data = priv;
-       
-       dev_dbg(&priv->ldev->pldev->dev, "kpc_dma_open(inode = [%p], filp = [%p]) priv = [%p] ldev = [%p]\n", inode, filp, priv, priv->ldev);
+
        return 0;
 }
 
@@ -285,134 +271,81 @@ int  kpc_dma_close(struct inode *inode, struct file *filp)
        struct kpc_dma_descriptor *cur;
        struct dev_private_data *priv = (struct dev_private_data *)filp->private_data;
        struct kpc_dma_device *eng = priv->ldev;
-       dev_dbg(&priv->ldev->pldev->dev, "kpc_dma_close(inode = [%p], filp = [%p]) priv = [%p], ldev = [%p]\n", inode, filp, priv, priv->ldev);
-       
+
        lock_engine(eng);
-       
+
        stop_dma_engine(eng);
-       
+
        cur = eng->desc_completed->Next;
-       while (cur != eng->desc_next){
+       while (cur != eng->desc_next) {
                dev_dbg(&eng->pldev->dev, "Aborting descriptor %p (acd = %p)\n", cur, cur->acd);
-               if (cur->DescControlFlags & DMA_DESC_CTL_EOP){
+               if (cur->DescControlFlags & DMA_DESC_CTL_EOP) {
                        if (cur->acd)
                                transfer_complete_cb(cur->acd, 0, ACD_FLAG_ABORT);
                }
-               
+
                clear_desc(cur);
                eng->desc_completed = cur;
-               
+
                cur = cur->Next;
        }
-       
+
        start_dma_engine(eng);
-       
+
        unlock_engine(eng);
-       
+
        atomic_inc(&priv->ldev->open_count); /* release the device */
        kfree(priv);
        return 0;
 }
 
-#ifdef CONFIG_KPC_DMA_AIO
 static
-int  kpc_dma_aio_cancel(struct kiocb *kcb)
+ssize_t  kpc_dma_read(struct file *filp,       char __user *user_buf, size_t count, loff_t *ppos)
 {
-       struct dev_private_data *priv = (struct dev_private_data *)kcb->ki_filp->private_data;
-       dev_dbg(&priv->ldev->pldev->dev, "kpc_dma_aio_cancel(kcb = [%p]) priv = [%p], ldev = [%p]\n", kcb, priv, priv->ldev);
-       return 0;
-}
+       struct dev_private_data *priv = (struct dev_private_data *)filp->private_data;
 
-static
-ssize_t   kpc_dma_aio_read(struct kiocb *kcb, const struct iovec *iov, unsigned long iov_count, loff_t pos)
-{
-       struct dev_private_data *priv = (struct dev_private_data *)kcb->ki_filp->private_data;
-       dev_dbg(&priv->ldev->pldev->dev, "kpc_dma_aio_read(kcb = [%p], iov = [%p], iov_count = %ld, pos = %lld) priv = [%p], ldev = [%p]\n", kcb, iov, iov_count, pos, priv, priv->ldev);
-       
        if (priv->ldev->dir != DMA_FROM_DEVICE)
                return -EMEDIUMTYPE;
-       
-       if (iov_count != 1){
-               dev_err(&priv->ldev->pldev->dev, "kpc_dma_aio_read() called with iov_count > 1!\n");
-               return -EFAULT;
-       }
-       
-       if (!is_sync_kiocb(kcb))
-               kiocb_set_cancel_fn(kcb, kpc_dma_aio_cancel);
-       return kpc_dma_transfer(priv, kcb, (unsigned long)iov->iov_base, iov->iov_len);
-}
 
-static
-ssize_t  kpc_dma_aio_write(struct kiocb *kcb, const struct iovec *iov, unsigned long iov_count, loff_t pos)
-{
-       struct dev_private_data *priv = (struct dev_private_data *)kcb->ki_filp->private_data;
-       dev_dbg(&priv->ldev->pldev->dev, "kpc_dma_aio_write(kcb = [%p], iov = [%p], iov_count = %ld, pos = %lld) priv = [%p], ldev = [%p]\n", kcb, iov, iov_count, pos, priv, priv->ldev);
-       
-       if (priv->ldev->dir != DMA_TO_DEVICE)
-               return -EMEDIUMTYPE;
-       
-       if (iov_count != 1){
-               dev_err(&priv->ldev->pldev->dev, "kpc_dma_aio_write() called with iov_count > 1!\n");
-               return -EFAULT;
-       }
-       
-       if (!is_sync_kiocb(kcb))
-               kiocb_set_cancel_fn(kcb, kpc_dma_aio_cancel);
-       return kpc_dma_transfer(priv, kcb, (unsigned long)iov->iov_base, iov->iov_len);
-}
-#endif
-
-static
-ssize_t  kpc_dma_read( struct file *filp,       char __user *user_buf, size_t count, loff_t *ppos)
-{
-       struct dev_private_data *priv = (struct dev_private_data *)filp->private_data;
-       dev_dbg(&priv->ldev->pldev->dev, "kpc_dma_read(filp = [%p], user_buf = [%p], count = %zu, ppos = [%p]) priv = [%p], ldev = [%p]\n", filp, user_buf, count, ppos, priv, priv->ldev);
-       
-       if (priv->ldev->dir != DMA_FROM_DEVICE)
-               return -EMEDIUMTYPE;
-       
-       return kpc_dma_transfer(priv, (struct kiocb *)NULL, (unsigned long)user_buf, count);
+       return kpc_dma_transfer(priv, (unsigned long)user_buf, count);
 }
 
 static
 ssize_t  kpc_dma_write(struct file *filp, const char __user *user_buf, size_t count, loff_t *ppos)
 {
        struct dev_private_data *priv = (struct dev_private_data *)filp->private_data;
-       dev_dbg(&priv->ldev->pldev->dev, "kpc_dma_write(filp = [%p], user_buf = [%p], count = %zu, ppos = [%p]) priv = [%p], ldev = [%p]\n", filp, user_buf, count, ppos, priv, priv->ldev);
-       
+
        if (priv->ldev->dir != DMA_TO_DEVICE)
                return -EMEDIUMTYPE;
-       
-       return kpc_dma_transfer(priv, (struct kiocb *)NULL, (unsigned long)user_buf, count);
+
+       return kpc_dma_transfer(priv, (unsigned long)user_buf, count);
 }
 
 static
 long  kpc_dma_ioctl(struct file *filp, unsigned int ioctl_num, unsigned long ioctl_param)
 {
        struct dev_private_data *priv = (struct dev_private_data *)filp->private_data;
-       dev_dbg(&priv->ldev->pldev->dev, "kpc_dma_ioctl(filp = [%p], ioctl_num = 0x%x, ioctl_param = 0x%lx) priv = [%p], ldev = [%p]\n", filp, ioctl_num, ioctl_param, priv, priv->ldev);
-       
-       switch (ioctl_num){
-               case KND_IOCTL_SET_CARD_ADDR:           priv->card_addr  = ioctl_param; return priv->card_addr; 
-               case KND_IOCTL_SET_USER_CTL:            priv->user_ctl   = ioctl_param; return priv->user_ctl; 
-               case KND_IOCTL_SET_USER_CTL_LAST:       priv->user_ctl_last = ioctl_param; return priv->user_ctl_last; 
-               case KND_IOCTL_GET_USER_STS:            return priv->user_sts;
+
+       switch (ioctl_num) {
+       case KND_IOCTL_SET_CARD_ADDR:
+               priv->card_addr  = ioctl_param; return priv->card_addr;
+       case KND_IOCTL_SET_USER_CTL:
+               priv->user_ctl   = ioctl_param; return priv->user_ctl;
+       case KND_IOCTL_SET_USER_CTL_LAST:
+               priv->user_ctl_last = ioctl_param; return priv->user_ctl_last;
+       case KND_IOCTL_GET_USER_STS:
+               return priv->user_sts;
        }
-       
+
        return -ENOTTY;
 }
 
-
-struct file_operations  kpc_dma_fops = {
+const struct file_operations  kpc_dma_fops = {
        .owner      = THIS_MODULE,
        .open           = kpc_dma_open,
        .release        = kpc_dma_close,
        .read           = kpc_dma_read,
        .write          = kpc_dma_write,
-#ifdef CONFIG_KPC_DMA_AIO
-       .aio_read       = kpc_dma_aio_read,
-       .aio_write      = kpc_dma_aio_write,
-#endif
        .unlocked_ioctl = kpc_dma_ioctl,
 };
 
index aeae58d9bc18ec09f05c4e9166116cf277195ddd..a05ae6d40db9d27bf731c4660936ffba5b98488e 100644 (file)
@@ -14,16 +14,16 @@ MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Matt.Sickler@daktronics.com");
 
 #define KPC_DMA_CHAR_MAJOR    UNNAMED_MAJOR
-#define KPC_DMA_NUM_MINORS    1 << MINORBITS
+#define KPC_DMA_NUM_MINORS    BIT(MINORBITS)
 static DEFINE_MUTEX(kpc_dma_mtx);
 static int assigned_major_num;
 static LIST_HEAD(kpc_dma_list);
 
-
 /**********  kpc_dma_list list management  **********/
-struct kpc_dma_device *  kpc_dma_lookup_device(int minor)
+struct kpc_dma_device *kpc_dma_lookup_device(int minor)
 {
        struct kpc_dma_device *c;
+
        mutex_lock(&kpc_dma_mtx);
        list_for_each_entry(c, &kpc_dma_list, list) {
                if (c->pldev->id == minor) {
@@ -31,19 +31,19 @@ struct kpc_dma_device *  kpc_dma_lookup_device(int minor)
                }
        }
        c = NULL; // not-found case
-  out:
+out:
        mutex_unlock(&kpc_dma_mtx);
        return c;
 }
 
-void  kpc_dma_add_device(struct kpc_dma_device * ldev)
+static void kpc_dma_add_device(struct kpc_dma_device *ldev)
 {
        mutex_lock(&kpc_dma_mtx);
        list_add(&ldev->list, &kpc_dma_list);
        mutex_unlock(&kpc_dma_mtx);
 }
 
-void kpc_dma_del_device(struct kpc_dma_device * ldev)
+static void kpc_dma_del_device(struct kpc_dma_device *ldev)
 {
        mutex_lock(&kpc_dma_mtx);
        list_del(&ldev->list);
@@ -55,11 +55,14 @@ static ssize_t  show_engine_regs(struct device *dev, struct device_attribute *at
 {
        struct kpc_dma_device *ldev;
        struct platform_device *pldev = to_platform_device(dev);
-       if (!pldev) return 0;
+
+       if (!pldev)
+               return 0;
        ldev = platform_get_drvdata(pldev);
-       if (!ldev) return 0;
-       
-       return scnprintf(buf, PAGE_SIZE, 
+       if (!ldev)
+               return 0;
+
+       return scnprintf(buf, PAGE_SIZE,
                "EngineControlStatus      = 0x%08x\n"
                "RegNextDescPtr           = 0x%08x\n"
                "RegSWDescPtr             = 0x%08x\n"
@@ -78,15 +81,14 @@ static ssize_t  show_engine_regs(struct device *dev, struct device_attribute *at
                ldev->desc_completed
        );
 }
-DEVICE_ATTR(engine_regs, 0444, show_engine_regs, NULL);
+static DEVICE_ATTR(engine_regs, 0444, show_engine_regs, NULL);
 
-static const struct attribute *  ndd_attr_list[] = {
+static const struct attribute *ndd_attr_list[] = {
        &dev_attr_engine_regs.attr,
        NULL,
 };
 
-struct class *kpc_dma_class;
-
+static struct class *kpc_dma_class;
 
 /**********  Platform Driver Functions  **********/
 static
@@ -95,73 +97,72 @@ int  kpc_dma_probe(struct platform_device *pldev)
        struct resource *r = NULL;
        int rv = 0;
        dev_t dev;
-       
+
        struct kpc_dma_device *ldev = kzalloc(sizeof(struct kpc_dma_device), GFP_KERNEL);
-       if (!ldev){
-               dev_err(&pldev->dev, "kpc_dma_probe: unable to kzalloc space for kpc_dma_device\n");
+
+       if (!ldev) {
+               dev_err(&pldev->dev, "%s: unable to kzalloc space for kpc_dma_device\n", __func__);
                rv = -ENOMEM;
                goto err_rv;
        }
-       
-       dev_dbg(&pldev->dev, "kpc_dma_probe(pldev = [%p]) ldev = [%p]\n", pldev, ldev);
-       
+
        INIT_LIST_HEAD(&ldev->list);
-       
+
        ldev->pldev = pldev;
        platform_set_drvdata(pldev, ldev);
        atomic_set(&ldev->open_count, 1);
-       
+
        mutex_init(&ldev->sem);
        lock_engine(ldev);
-       
+
        // Get Engine regs resource
        r = platform_get_resource(pldev, IORESOURCE_MEM, 0);
-       if (!r){
-               dev_err(&ldev->pldev->dev, "kpc_dma_probe: didn't get the engine regs resource!\n");
+       if (!r) {
+               dev_err(&ldev->pldev->dev, "%s: didn't get the engine regs resource!\n", __func__);
                rv = -ENXIO;
                goto err_kfree;
        }
        ldev->eng_regs = ioremap_nocache(r->start, resource_size(r));
-       if (!ldev->eng_regs){
-               dev_err(&ldev->pldev->dev, "kpc_dma_probe: failed to ioremap engine regs!\n");
+       if (!ldev->eng_regs) {
+               dev_err(&ldev->pldev->dev, "%s: failed to ioremap engine regs!\n", __func__);
                rv = -ENXIO;
                goto err_kfree;
        }
-       
+
        r = platform_get_resource(pldev, IORESOURCE_IRQ, 0);
-       if (!r){
-               dev_err(&ldev->pldev->dev, "kpc_dma_probe: didn't get the IRQ resource!\n");
+       if (!r) {
+               dev_err(&ldev->pldev->dev, "%s: didn't get the IRQ resource!\n", __func__);
                rv = -ENXIO;
                goto err_kfree;
        }
        ldev->irq = r->start;
-       
+
        // Setup miscdev struct
        dev = MKDEV(assigned_major_num, pldev->id);
        ldev->kpc_dma_dev = device_create(kpc_dma_class, &pldev->dev, dev, ldev, "kpc_dma%d", pldev->id);
-       if (IS_ERR(ldev->kpc_dma_dev)){
-               dev_err(&ldev->pldev->dev, "kpc_dma_probe: device_create failed: %d\n", rv);
+       if (IS_ERR(ldev->kpc_dma_dev)) {
+               dev_err(&ldev->pldev->dev, "%s: device_create failed: %d\n", __func__, rv);
                goto err_kfree;
        }
-       
+
        // Setup the DMA engine
        rv = setup_dma_engine(ldev, 30);
-       if (rv){
-               dev_err(&ldev->pldev->dev, "kpc_dma_probe: failed to setup_dma_engine: %d\n", rv);
+       if (rv) {
+               dev_err(&ldev->pldev->dev, "%s: failed to setup_dma_engine: %d\n", __func__, rv);
                goto err_misc_dereg;
        }
-       
+
        // Setup the sysfs files
        rv = sysfs_create_files(&(ldev->pldev->dev.kobj), ndd_attr_list);
-       if (rv){
-               dev_err(&ldev->pldev->dev, "kpc_dma_probe: Failed to add sysfs files: %d\n", rv);
+       if (rv) {
+               dev_err(&ldev->pldev->dev, "%s: Failed to add sysfs files: %d\n", __func__, rv);
                goto err_destroy_eng;
        }
-       
+
        kpc_dma_add_device(ldev);
-       
+
        return 0;
-       
+
  err_destroy_eng:
        destroy_dma_engine(ldev);
  err_misc_dereg:
@@ -176,70 +177,67 @@ static
 int  kpc_dma_remove(struct platform_device *pldev)
 {
        struct kpc_dma_device *ldev = platform_get_drvdata(pldev);
+
        if (!ldev)
                return -ENXIO;
-       
-       dev_dbg(&ldev->pldev->dev, "kpc_dma_remove(pldev = [%p]) ldev = [%p]\n", pldev, ldev);
-       
+
        lock_engine(ldev);
        sysfs_remove_files(&(ldev->pldev->dev.kobj), ndd_attr_list);
        destroy_dma_engine(ldev);
        kpc_dma_del_device(ldev);
        device_destroy(kpc_dma_class, MKDEV(assigned_major_num, ldev->pldev->id));
        kfree(ldev);
-       
+
        return 0;
 }
 
-
 /**********  Driver Functions  **********/
-struct platform_driver kpc_dma_plat_driver_i = {
+static struct platform_driver kpc_dma_plat_driver_i = {
        .probe        = kpc_dma_probe,
        .remove       = kpc_dma_remove,
        .driver = {
                .name   = KP_DRIVER_NAME_DMA_CONTROLLER,
-               .owner  = THIS_MODULE,
        },
 };
 
 static
-int __init  kpc_dma_driver_init(void)
+int __init kpc_dma_driver_init(void)
 {
        int err;
-       
+
        err = __register_chrdev(KPC_DMA_CHAR_MAJOR, 0, KPC_DMA_NUM_MINORS, "kpc_dma", &kpc_dma_fops);
-       if (err < 0){
+       if (err < 0) {
                pr_err("Can't allocate a major number (%d) for kpc_dma (err = %d)\n", KPC_DMA_CHAR_MAJOR, err);
                goto fail_chrdev_register;
        }
        assigned_major_num = err;
-       
+
        kpc_dma_class = class_create(THIS_MODULE, "kpc_dma");
        err = PTR_ERR(kpc_dma_class);
-       if (IS_ERR(kpc_dma_class)){
+       if (IS_ERR(kpc_dma_class)) {
                pr_err("Can't create class kpc_dma (err = %d)\n", err);
                goto fail_class_create;
        }
-       
+
        err = platform_driver_register(&kpc_dma_plat_driver_i);
-       if (err){
+       if (err) {
                pr_err("Can't register platform driver for kpc_dma (err = %d)\n", err);
                goto fail_platdriver_register;
        }
-       
+
        return err;
-       
-  fail_platdriver_register:
+
+fail_platdriver_register:
        class_destroy(kpc_dma_class);
-  fail_class_create:
+fail_class_create:
        __unregister_chrdev(KPC_DMA_CHAR_MAJOR, 0, KPC_DMA_NUM_MINORS, "kpc_dma");
-  fail_chrdev_register:
+fail_chrdev_register:
        return err;
 }
 module_init(kpc_dma_driver_init);
 
 static
-void __exit  kpc_dma_driver_exit(void)
+void __exit kpc_dma_driver_exit(void)
 {
        platform_driver_unregister(&kpc_dma_plat_driver_i);
        class_destroy(kpc_dma_class);
index ef913b7496e6d0d570fa6399f19f8fd62d64b582..4c8cc866b826973ad02d7401ed6147d57455b7b5 100644 (file)
 #include <linux/pci.h>
 #include <linux/interrupt.h>
 #include <linux/workqueue.h>
-#include <linux/aio.h>
 #include <linux/bitops.h>
 #include "../kpc.h"
 
-
 struct kp2000_device;
 struct kpc_dma_device {
        struct list_head            list;
@@ -27,23 +25,23 @@ struct kpc_dma_device {
        struct device              *kpc_dma_dev;
        struct kobject              kobj;
        char                        name[16];
-       
+
        int                         dir; // DMA_FROM_DEVICE || DMA_TO_DEVICE
        struct mutex                sem;
        unsigned int                irq;
        struct work_struct          irq_work;
-       
+
        atomic_t                    open_count;
-       
+
        size_t                      accumulated_bytes;
        u32                         accumulated_flags;
-       
+
        // Descriptor "Pool" housekeeping
        u32                         desc_pool_cnt;
        struct dma_pool            *desc_pool;
        struct kpc_dma_descriptor  *desc_pool_first;
        struct kpc_dma_descriptor  *desc_pool_last;
-       
+
        struct kpc_dma_descriptor  *desc_next;
        struct kpc_dma_descriptor  *desc_completed;
 };
@@ -56,9 +54,9 @@ struct dev_private_data {
        u64                         user_sts;
 };
 
-struct kpc_dma_device *  kpc_dma_lookup_device(int minor);
+struct kpc_dma_device *kpc_dma_lookup_device(int minor);
 
-extern struct file_operations  kpc_dma_fops;
+extern const struct file_operations  kpc_dma_fops;
 
 #define ENG_CAP_PRESENT                 0x00000001
 #define ENG_CAP_DIRECTION               0x00000002
@@ -88,9 +86,8 @@ struct aio_cb_data {
        struct kpc_dma_device      *ldev;
        struct completion  *cpl;
        unsigned char       flags;
-       struct kiocb       *kcb;
        size_t              len;
-       
+
        unsigned int        page_count;
        struct page       **user_pages;
        struct sg_table     sgt;
@@ -119,10 +116,10 @@ struct kpc_dma_descriptor {
                volatile u32  DescSystemAddrLS;
                volatile u32  DescSystemAddrMS;
                volatile u32  DescNextDescPtr;
-               
+
                dma_addr_t    MyDMAAddr;
                struct kpc_dma_descriptor   *Next;
-               
+
                struct aio_cb_data  *acd;
 } __attribute__((packed));
 // DescControlFlags:
@@ -157,35 +154,41 @@ void  WriteEngineControl(struct kpc_dma_device *eng, u32 value)
 {
        writel(value, eng->eng_regs + 1);
 }
+
 static inline
 u32  GetEngineControl(struct kpc_dma_device *eng)
 {
        return readl(eng->eng_regs + 1);
 }
+
 static inline
 void  SetClearEngineControl(struct kpc_dma_device *eng, u32 set_bits, u32 clear_bits)
 {
        u32 val = GetEngineControl(eng);
+
        val |= set_bits;
        val &= ~clear_bits;
        WriteEngineControl(eng, val);
 }
 
 static inline
-void  SetEngineNextPtr(struct kpc_dma_device *eng, struct kpc_dma_descriptor * desc)
+void  SetEngineNextPtr(struct kpc_dma_device *eng, struct kpc_dma_descriptor *desc)
 {
        writel(desc->MyDMAAddr, eng->eng_regs + 2);
 }
+
 static inline
-void  SetEngineSWPtr(struct kpc_dma_device *eng, struct kpc_dma_descriptor * desc)
+void  SetEngineSWPtr(struct kpc_dma_device *eng, struct kpc_dma_descriptor *desc)
 {
        writel(desc->MyDMAAddr, eng->eng_regs + 3);
 }
+
 static inline
 void  ClearEngineCompletePtr(struct kpc_dma_device *eng)
 {
        writel(0, eng->eng_regs + 4);
 }
+
 static inline
 u32  GetEngineCompletePtr(struct kpc_dma_device *eng)
 {
@@ -206,7 +209,6 @@ void  unlock_engine(struct kpc_dma_device *eng)
        mutex_unlock(&eng->sem);
 }
 
-
 /// Shared Functions
 void  start_dma_engine(struct kpc_dma_device *eng);
 int   setup_dma_engine(struct kpc_dma_device *eng, u32 desc_cnt);
diff --git a/drivers/staging/kpc2000/kpc_i2c/Makefile b/drivers/staging/kpc2000/kpc_i2c/Makefile
deleted file mode 100644 (file)
index 73ec07a..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-
-obj-m := kpc2000_i2c.o
-kpc2000_i2c-objs := i2c_driver.o fileops.o
diff --git a/drivers/staging/kpc2000/kpc_i2c/fileops.c b/drivers/staging/kpc2000/kpc_i2c/fileops.c
deleted file mode 100644 (file)
index e749c09..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-#if 0
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/kernel.h>      /* printk() */
-#include <linux/slab.h>                /* kmalloc() */
-#include <linux/fs.h>          /* everything... */
-#include <linux/errno.h>       /* error codes */
-#include <linux/types.h>       /* size_t */
-#include <linux/cdev.h>
-#include <asm/uaccess.h>       /* copy_*_user */
-
-#include "i2c_driver.h"
-
-int i2c_cdev_open(struct inode *inode, struct file *filp)
-{
-  struct i2c_device *lddev;
-  
-  if(NULL == inode) {
-    //printk(KERN_WARNING "<pl_i2c> i2c_cdev_open: inode is a NULL pointer\n");
-    DBG_PRINT(KERN_WARNING, "i2c_cdev_open: inode is a NULL pointer\n");
-    return -EINVAL;
-  }
-  if(NULL == filp) {
-    //printk(KERN_WARNING "<pl_i2c> i2c_cdev_open: filp is a NULL pointer\n");
-    DBG_PRINT(KERN_WARNING, "i2c_cdev_open: filp is a NULL pointer\n");
-    return -EINVAL;
-  }
-  
-  lddev = container_of(inode->i_cdev, struct i2c_device, cdev);
-  //printk(KERN_DEBUG "<pl_i2c> i2c_cdev_open(filp = [%p], lddev = [%p])\n", filp, lddev);
-  DBG_PRINT(KERN_DEBUG, "i2c_cdev_open(filp = [%p], lddev = [%p])\n", filp, lddev);
-  
-  filp->private_data = lddev; /* so other methods can access it */
-  
-  return 0;    /* success */
-}
-
-int i2c_cdev_close(struct inode *inode, struct file *filp)
-{
-  struct i2c_device *lddev;
-  
-  if(NULL == inode) {
-    //printk(KERN_WARNING "<pl_i2c> i2c_cdev_close: inode is a NULL pointer\n");
-    DBG_PRINT(KERN_WARNING, "i2c_cdev_close: inode is a NULL pointer\n");
-    return -EINVAL;
-  }
-  if(NULL == filp) {
-    //printk(KERN_WARNING "<pl_i2c> i2c_cdev_close: filp is a NULL pointer\n");
-    DBG_PRINT(KERN_WARNING, "i2c_cdev_close: filp is a NULL pointer\n");
-    return -EINVAL;
-  }
-  
-  lddev = filp->private_data;
-  //printk(KERN_DEBUG "<pl_i2c> i2c_cdev_close(filp = [%p], lddev = [%p])\n", filp, lddev);
-  DBG_PRINT(KERN_DEBUG, "i2c_cdev_close(filp = [%p], lddev = [%p])\n", filp, lddev);
-  
-  return 0;
-}
-
-ssize_t i2c_cdev_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
-{
-  size_t copy;
-  ssize_t ret = 0;
-  int err = 0;
-  u64 read_val;
-  char tmp_buf[48] = { 0 };
-  struct i2c_device *lddev = filp->private_data;
-
-  if(NULL == filp) {
-    //printk(KERN_WARNING "<pl_i2c> i2c_cdev_read: filp is a NULL pointer\n");
-    DBG_PRINT(KERN_WARNING, "i2c_cdev_read: filp is a NULL pointer\n");
-    return -EINVAL;
-  }
-  if(NULL == buf) {
-    //printk(KERN_WARNING "<pl_i2c> i2c_cdev_read: buf is a NULL pointer\n");
-    DBG_PRINT(KERN_WARNING, "i2c_cdev_read: buf is a NULL pointer\n");
-    return -EINVAL;
-  }
-  if(NULL == f_pos) {
-    //printk(KERN_WARNING "<pl_i2c> i2c_cdev_read: f_pos is a NULL pointer\n");
-    DBG_PRINT(KERN_WARNING, "i2c_cdev_read: f_pos is a NULL pointer\n");
-    return -EINVAL;
-  }
-
-  if(count < sizeof(tmp_buf)) {
-    //printk(KERN_INFO "<pl_i2c> i2c_cdev_read: buffer is too small (count = %d, should be at least %d bytes)\n", (int)count, (int)sizeof(tmp_buf));
-    DBG_PRINT(KERN_INFO, "i2c_cdev_read: buffer is too small (count = %d, should be at least %d bytes)\n", (int)count, (int)sizeof(tmp_buf));
-    return -EINVAL;
-  }
-  if(((*f_pos * 8) + lddev->pldev->resource[0].start) > lddev->pldev->resource[0].end) {
-    //printk(KERN_INFO "<pl_i2c> i2c_cdev_read: bad read addr %016llx\n", (*f_pos * 8) + lddev->pldev->resource[0].start);
-    DBG_PRINT(KERN_INFO, "i2c_cdev_read: bad read addr %016llx\n", (*f_pos * 8) + lddev->pldev->resource[0].start);
-    //printk(KERN_INFO "<pl_i2c> i2c_cdev_read: addr end %016llx\n", lddev->pldev->resource[0].end);
-    DBG_PRINT(KERN_INFO, "i2c_cdev_read: addr end %016llx\n", lddev->pldev->resource[0].end);
-    //printk(KERN_INFO "<pl_i2c> i2c_cdev_read: EOF reached\n");
-    DBG_PRINT(KERN_INFO, "i2c_cdev_read: EOF reached\n");
-    return 0;
-  }
-
-  down_read(&lddev->rw_sem);
-  
-  read_val = *(lddev->regs + *f_pos);
-  copy = clamp_t(size_t, count, 1, sizeof(tmp_buf));
-  copy = scnprintf(tmp_buf, copy, "reg: 0x%x val: 0x%llx\n", (unsigned int)*f_pos, read_val);
-  err = copy_to_user(buf, tmp_buf, copy);
-  if(err) {
-    //printk(KERN_INFO "<pl_i2c> i2c_cdev_read: could not copy to user (err = %d)\n", err);
-    DBG_PRINT(KERN_INFO, "i2c_cdev_read: could not copy to user (err = %d)\n", err);
-    return -EINVAL;
-  }
-
-  ret = (ssize_t)copy;
-  (*f_pos)++;
-  
-  up_read(&lddev->rw_sem);
-  
-  return ret;
-}
-
-ssize_t i2c_cdev_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos)
-{
-  u8 reg;
-  u8 val;
-  char tmp[8] = { 0 };
-  struct i2c_device *lddev = filp->private_data;
-
-  if(NULL == filp) {
-    //printk(KERN_WARNING "<pl_i2c> i2c_cdev_write: filp is a NULL pointer\n");
-    DBG_PRINT(KERN_WARNING, "i2c_cdev_write: filp is a NULL pointer\n");
-    return -EINVAL;
-  }
-  if(NULL == buf) {
-    //printk(KERN_WARNING "<pl_i2c> i2c_cdev_write: buf is a NULL pointer\n");
-    DBG_PRINT(KERN_WARNING, "i2c_cdev_write: buf is a NULL pointer\n");
-    return -EINVAL;
-  }
-  if(NULL == f_pos) {
-    //printk(KERN_WARNING "<pl_i2c> i2c_cdev_write: f_pos is a NULL pointer\n");
-    DBG_PRINT(KERN_WARNING, "i2c_cdev_write: f_pos is a NULL pointer\n");
-    return -EINVAL;
-  }
-
-  //printk(KERN_DEBUG "<pl_i2c> i2c_cdev_write(filp = [%p], lddev = [%p])\n", filp, lddev);
-  DBG_PRINT(KERN_DEBUG, "i2c_cdev_write(filp = [%p], lddev = [%p])\n", filp, lddev);
-
-  down_write(&lddev->rw_sem);
-
-  if(count >= 2) {
-    if(copy_from_user(tmp, buf, 2)) {
-      return -EFAULT;
-    }
-    
-    reg = tmp[0] - '0';
-    val = tmp[1] - '0';
-
-    //printk(KERN_DEBUG "  reg = %d  val = %d\n", reg, val);
-    DBG_PRINT(KERN_DEBUG, "  reg = %d  val = %d\n", reg, val);
-
-    if(reg >= 0 && reg < 16) {
-      //printk(KERN_DEBUG "  Writing 0x%x to %p\n", val, lddev->regs + reg);
-      DBG_PRINT(KERN_DEBUG, "  Writing 0x%x to %p\n", val, lddev->regs + reg);
-      *(lddev->regs + reg) = val;
-    }
-  }
-
-  (*f_pos)++;
-
-  up_write(&lddev->rw_sem);
-
-  return count;
-}
-
-struct file_operations i2c_fops = {
-  .owner               = THIS_MODULE,
-  .open                = i2c_cdev_open,
-  .release     = i2c_cdev_close,
-  .read                = i2c_cdev_read,
-  .write               = i2c_cdev_write,
-};
-#endif
diff --git a/drivers/staging/kpc2000/kpc_i2c/i2c_driver.c b/drivers/staging/kpc2000/kpc_i2c/i2c_driver.c
deleted file mode 100644 (file)
index 0fb068b..0000000
+++ /dev/null
@@ -1,699 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*  Copyright (c) 2014-2018  Daktronics,
-                             Matt Sickler <matt.sickler@daktronics.com>,
-                             Jordon Hofer <jordon.hofer@daktronics.com>
-    Adapted i2c-i801.c for use with Kadoka hardware.
-    Copyright (c) 1998 - 2002  Frodo Looijaard <frodol@dds.nl>,
-    Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker
-    <mdsxyz123@yahoo.com>
-    Copyright (C) 2007 - 2012  Jean Delvare <khali@linux-fr.org>
-    Copyright (C) 2010         Intel Corporation,
-                               David Woodhouse <dwmw2@infradead.org>
-*/
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/types.h>
-#include <asm/io.h>
-#include <linux/io-64-nonatomic-lo-hi.h>
-#include <linux/export.h>
-#include <linux/slab.h>
-#include <linux/platform_device.h>
-#include <linux/fs.h>
-#include <linux/rwsem.h>
-#include <linux/delay.h>
-#include <linux/i2c.h>
-#include "../kpc.h"
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Matt.Sickler@Daktronics.com");
-MODULE_SOFTDEP("pre: i2c-dev");
-
-struct i2c_device {
-    unsigned long           smba;
-    struct i2c_adapter      adapter;
-    struct platform_device *pldev;
-    struct rw_semaphore     rw_sem;
-    unsigned int            features;
-};
-
-/*****************************
- *** Part 1 - i2c Handlers ***
- *****************************/
-
-#define REG_SIZE 8
-
-/* I801 SMBus address offsets */
-#define SMBHSTSTS(p)    ((0  * REG_SIZE) + (p)->smba)
-#define SMBHSTCNT(p)    ((2  * REG_SIZE) + (p)->smba)
-#define SMBHSTCMD(p)    ((3  * REG_SIZE) + (p)->smba)
-#define SMBHSTADD(p)    ((4  * REG_SIZE) + (p)->smba)
-#define SMBHSTDAT0(p)   ((5  * REG_SIZE) + (p)->smba)
-#define SMBHSTDAT1(p)   ((6  * REG_SIZE) + (p)->smba)
-#define SMBBLKDAT(p)    ((7  * REG_SIZE) + (p)->smba)
-#define SMBPEC(p)       ((8  * REG_SIZE) + (p)->smba)   /* ICH3 and later */
-#define SMBAUXSTS(p)    ((12 * REG_SIZE) + (p)->smba)   /* ICH4 and later */
-#define SMBAUXCTL(p)    ((13 * REG_SIZE) + (p)->smba)   /* ICH4 and later */
-
-/* PCI Address Constants */
-#define SMBBAR      4
-#define SMBHSTCFG   0x040
-
-/* Host configuration bits for SMBHSTCFG */
-#define SMBHSTCFG_HST_EN        1
-#define SMBHSTCFG_SMB_SMI_EN    2
-#define SMBHSTCFG_I2C_EN        4
-
-/* Auxiliary control register bits, ICH4+ only */
-#define SMBAUXCTL_CRC       1
-#define SMBAUXCTL_E32B      2
-
-/* kill bit for SMBHSTCNT */
-#define SMBHSTCNT_KILL      2
-
-/* Other settings */
-#define MAX_RETRIES         400
-#define ENABLE_INT9         0       /* set to 0x01 to enable - untested */
-
-/* I801 command constants */
-#define I801_QUICK              0x00
-#define I801_BYTE               0x04
-#define I801_BYTE_DATA          0x08
-#define I801_WORD_DATA          0x0C
-#define I801_PROC_CALL          0x10    /* unimplemented */
-#define I801_BLOCK_DATA         0x14
-#define I801_I2C_BLOCK_DATA     0x18    /* ICH5 and later */
-#define I801_BLOCK_LAST         0x34
-#define I801_I2C_BLOCK_LAST     0x38    /* ICH5 and later */
-#define I801_START              0x40
-#define I801_PEC_EN             0x80    /* ICH3 and later */
-
-/* I801 Hosts Status register bits */
-#define SMBHSTSTS_BYTE_DONE     0x80
-#define SMBHSTSTS_INUSE_STS     0x40
-#define SMBHSTSTS_SMBALERT_STS  0x20
-#define SMBHSTSTS_FAILED        0x10
-#define SMBHSTSTS_BUS_ERR       0x08
-#define SMBHSTSTS_DEV_ERR       0x04
-#define SMBHSTSTS_INTR          0x02
-#define SMBHSTSTS_HOST_BUSY     0x01
-
-#define STATUS_FLAGS        (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_FAILED | SMBHSTSTS_BUS_ERR | SMBHSTSTS_DEV_ERR | SMBHSTSTS_INTR)
-
-/* Older devices have their ID defined in <linux/pci_ids.h> */
-#define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS       0x1c22
-#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS          0x1d22
-/* Patsburg also has three 'Integrated Device Function' SMBus controllers */
-#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0     0x1d70
-#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1     0x1d71
-#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2     0x1d72
-#define PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS      0x1e22
-#define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS          0x2330
-#define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS     0x3b30
-#define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS         0x8c22
-#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS      0x9c22
-
-
-#define FEATURE_SMBUS_PEC       (1 << 0)
-#define FEATURE_BLOCK_BUFFER    (1 << 1)
-#define FEATURE_BLOCK_PROC      (1 << 2)
-#define FEATURE_I2C_BLOCK_READ  (1 << 3)
-/* Not really a feature, but it's convenient to handle it as such */
-#define FEATURE_IDF             (1 << 15)
-
-static unsigned int disable_features;
-module_param(disable_features, uint, S_IRUGO | S_IWUSR);
-MODULE_PARM_DESC(disable_features, "Disable selected driver features");
-
-// FIXME!
-#undef inb_p
-#define inb_p(a) readq((void*)a)
-#undef outb_p
-#define outb_p(d,a) writeq(d,(void*)a)
-
-/* Make sure the SMBus host is ready to start transmitting.
-   Return 0 if it is, -EBUSY if it is not. */
-static int i801_check_pre(struct i2c_device *priv)
-{
-    int status;
-    
-    dev_dbg(&priv->adapter.dev, "i801_check_pre\n");
-    
-    status = inb_p(SMBHSTSTS(priv));
-    if (status & SMBHSTSTS_HOST_BUSY) {
-        dev_err(&priv->adapter.dev, "SMBus is busy, can't use it! (status=%x)\n", status);
-        return -EBUSY;
-    }
-    
-    status &= STATUS_FLAGS;
-    if (status) {
-        //dev_dbg(&priv->adapter.dev, "Clearing status flags (%02x)\n", status);
-        outb_p(status, SMBHSTSTS(priv));
-        status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS;
-        if (status) {
-          dev_err(&priv->adapter.dev, "Failed clearing status flags (%02x)\n", status);
-          return -EBUSY;
-        }
-    }
-    return 0;
-}
-
-/* Convert the status register to an error code, and clear it. */
-static int i801_check_post(struct i2c_device *priv, int status, int timeout)
-{
-    int result = 0;
-    
-    dev_dbg(&priv->adapter.dev, "i801_check_post\n");
-    
-    /* If the SMBus is still busy, we give up */
-    if (timeout) {
-        dev_err(&priv->adapter.dev, "Transaction timeout\n");
-        /* try to stop the current command */
-        dev_dbg(&priv->adapter.dev, "Terminating the current operation\n");
-        outb_p(inb_p(SMBHSTCNT(priv)) | SMBHSTCNT_KILL, SMBHSTCNT(priv));
-        usleep_range(1000, 2000);
-        outb_p(inb_p(SMBHSTCNT(priv)) & (~SMBHSTCNT_KILL), SMBHSTCNT(priv));
-        
-        /* Check if it worked */
-        status = inb_p(SMBHSTSTS(priv));
-        if ((status & SMBHSTSTS_HOST_BUSY) || !(status & SMBHSTSTS_FAILED)) {
-            dev_err(&priv->adapter.dev, "Failed terminating the transaction\n");
-        }
-        outb_p(STATUS_FLAGS, SMBHSTSTS(priv));
-        return -ETIMEDOUT;
-    }
-    
-    if (status & SMBHSTSTS_FAILED) {
-        result = -EIO;
-        dev_err(&priv->adapter.dev, "Transaction failed\n");
-    }
-    if (status & SMBHSTSTS_DEV_ERR) {
-        result = -ENXIO;
-        dev_dbg(&priv->adapter.dev, "No response\n");
-    }
-    if (status & SMBHSTSTS_BUS_ERR) {
-        result = -EAGAIN;
-        dev_dbg(&priv->adapter.dev, "Lost arbitration\n");
-    }
-    
-    if (result) {
-        /* Clear error flags */
-        outb_p(status & STATUS_FLAGS, SMBHSTSTS(priv));
-        status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS;
-        if (status) {
-            dev_warn(&priv->adapter.dev, "Failed clearing status flags at end of transaction (%02x)\n", status);
-        }
-    }
-    
-    return result;
-}
-
-static int i801_transaction(struct i2c_device *priv, int xact)
-{
-    int status;
-    int result;
-    int timeout = 0;
-    
-    dev_dbg(&priv->adapter.dev, "i801_transaction\n");
-    
-    result = i801_check_pre(priv);
-    if (result < 0) {
-        return result;
-    }
-    /* the current contents of SMBHSTCNT can be overwritten, since PEC,
-    * INTREN, SMBSCMD are passed in xact */
-    outb_p(xact | I801_START, SMBHSTCNT(priv));
-    
-    /* We will always wait for a fraction of a second! */
-    do {
-        usleep_range(250, 500);
-        status = inb_p(SMBHSTSTS(priv));
-    } while ((status & SMBHSTSTS_HOST_BUSY) && (timeout++ < MAX_RETRIES));
-    
-    result = i801_check_post(priv, status, timeout > MAX_RETRIES);
-    if (result < 0) {
-        return result;
-    }
-    
-    outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv));
-    return 0;
-}
-
-/* wait for INTR bit as advised by Intel */
-static void i801_wait_hwpec(struct i2c_device *priv)
-{
-    int timeout = 0;
-    int status;
-    
-    dev_dbg(&priv->adapter.dev, "i801_wait_hwpec\n");
-    
-    do {
-        usleep_range(250, 500);
-        status = inb_p(SMBHSTSTS(priv));
-    } while ((!(status & SMBHSTSTS_INTR)) && (timeout++ < MAX_RETRIES));
-    
-    if (timeout > MAX_RETRIES) {
-        dev_dbg(&priv->adapter.dev, "PEC Timeout!\n");
-    }
-    
-    outb_p(status, SMBHSTSTS(priv));
-}
-
-static int i801_block_transaction_by_block(struct i2c_device *priv, union i2c_smbus_data *data, char read_write, int hwpec)
-{
-    int i, len;
-    int status;
-    
-    dev_dbg(&priv->adapter.dev, "i801_block_transaction_by_block\n");
-    
-    inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
-    
-    /* Use 32-byte buffer to process this transaction */
-    if (read_write == I2C_SMBUS_WRITE) {
-        len = data->block[0];
-        outb_p(len, SMBHSTDAT0(priv));
-        for (i = 0; i < len; i++) {
-            outb_p(data->block[i+1], SMBBLKDAT(priv));
-        }
-    }
-    
-    status = i801_transaction(priv, I801_BLOCK_DATA | ENABLE_INT9 | I801_PEC_EN * hwpec);
-    if (status) {
-        return status;
-    }
-
-    if (read_write == I2C_SMBUS_READ) {
-        len = inb_p(SMBHSTDAT0(priv));
-        if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
-            return -EPROTO;
-        }
-        
-        data->block[0] = len;
-        for (i = 0; i < len; i++) {
-            data->block[i + 1] = inb_p(SMBBLKDAT(priv));
-        }
-    }
-    return 0;
-}
-
-static int i801_block_transaction_byte_by_byte(struct i2c_device *priv, union i2c_smbus_data *data, char read_write, int command, int hwpec)
-{
-    int i, len;
-    int smbcmd;
-    int status;
-    int result;
-    int timeout;
-    
-    dev_dbg(&priv->adapter.dev, "i801_block_transaction_byte_by_byte\n");
-    
-    result = i801_check_pre(priv);
-    if (result < 0) {
-        return result;
-    }
-    
-    len = data->block[0];
-    
-    if (read_write == I2C_SMBUS_WRITE) {
-        outb_p(len, SMBHSTDAT0(priv));
-        outb_p(data->block[1], SMBBLKDAT(priv));
-    }
-    
-    for (i = 1; i <= len; i++) {
-        if (i == len && read_write == I2C_SMBUS_READ) {
-            if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
-                smbcmd = I801_I2C_BLOCK_LAST;
-            } else {
-                smbcmd = I801_BLOCK_LAST;
-            }
-        } else {
-            if (command == I2C_SMBUS_I2C_BLOCK_DATA && read_write == I2C_SMBUS_READ) {
-                smbcmd = I801_I2C_BLOCK_DATA;
-            } else {
-                smbcmd = I801_BLOCK_DATA;
-            }
-        }
-        outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT(priv));
-        
-        if (i == 1) {
-            outb_p(inb(SMBHSTCNT(priv)) | I801_START, SMBHSTCNT(priv));
-        }
-        /* We will always wait for a fraction of a second! */
-        timeout = 0;
-        do {
-            usleep_range(250, 500);
-            status = inb_p(SMBHSTSTS(priv));
-        } while ((!(status & SMBHSTSTS_BYTE_DONE)) && (timeout++ < MAX_RETRIES));
-        
-        result = i801_check_post(priv, status, timeout > MAX_RETRIES);
-        if (result < 0) {
-            return result;
-        }
-        if (i == 1 && read_write == I2C_SMBUS_READ && command != I2C_SMBUS_I2C_BLOCK_DATA) {
-            len = inb_p(SMBHSTDAT0(priv));
-            if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
-                dev_err(&priv->adapter.dev, "Illegal SMBus block read size %d\n", len);
-                /* Recover */
-                while (inb_p(SMBHSTSTS(priv)) & SMBHSTSTS_HOST_BUSY) {
-                    outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
-                }
-                outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv));
-                return -EPROTO;
-            }
-            data->block[0] = len;
-        }
-        
-        /* Retrieve/store value in SMBBLKDAT */
-        if (read_write == I2C_SMBUS_READ) {
-            data->block[i] = inb_p(SMBBLKDAT(priv));
-        }
-        if (read_write == I2C_SMBUS_WRITE && i+1 <= len) {
-            outb_p(data->block[i+1], SMBBLKDAT(priv));
-        }
-        /* signals SMBBLKDAT ready */
-        outb_p(SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR, SMBHSTSTS(priv));
-    }
-    
-    return 0;
-}
-
-static int i801_set_block_buffer_mode(struct i2c_device *priv)
-{
-    dev_dbg(&priv->adapter.dev, "i801_set_block_buffer_mode\n");
-    
-    outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
-    if ((inb_p(SMBAUXCTL(priv)) & SMBAUXCTL_E32B) == 0) {
-        return -EIO;
-    }
-    return 0;
-}
-
-/* Block transaction function */
-static int i801_block_transaction(struct i2c_device *priv, union i2c_smbus_data *data, char read_write, int command, int hwpec)
-{
-    int result = 0;
-    //unsigned char hostc;
-    
-    dev_dbg(&priv->adapter.dev, "i801_block_transaction\n");
-    
-    if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
-        if (read_write == I2C_SMBUS_WRITE) {
-            /* set I2C_EN bit in configuration register */
-            //TODO: Figure out the right thing to do here...
-            //pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc);
-            //pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc | SMBHSTCFG_I2C_EN);
-        } else if (!(priv->features & FEATURE_I2C_BLOCK_READ)) {
-            dev_err(&priv->adapter.dev, "I2C block read is unsupported!\n");
-            return -EOPNOTSUPP;
-        }
-    }
-    
-    if (read_write == I2C_SMBUS_WRITE || command == I2C_SMBUS_I2C_BLOCK_DATA) {
-        if (data->block[0] < 1) {
-            data->block[0] = 1;
-        }
-        if (data->block[0] > I2C_SMBUS_BLOCK_MAX) {
-            data->block[0] = I2C_SMBUS_BLOCK_MAX;
-        }
-    } else {
-        data->block[0] = 32;   /* max for SMBus block reads */
-    }
-    
-    /* Experience has shown that the block buffer can only be used for
-        SMBus (not I2C) block transactions, even though the datasheet
-        doesn't mention this limitation. */
-    if ((priv->features & FEATURE_BLOCK_BUFFER) && command != I2C_SMBUS_I2C_BLOCK_DATA && i801_set_block_buffer_mode(priv) == 0) {
-        result = i801_block_transaction_by_block(priv, data, read_write, hwpec);
-    } else {
-        result = i801_block_transaction_byte_by_byte(priv, data, read_write, command, hwpec);
-    }  
-    if (result == 0 && hwpec) {
-        i801_wait_hwpec(priv);
-    }
-    if (command == I2C_SMBUS_I2C_BLOCK_DATA && read_write == I2C_SMBUS_WRITE) {
-        /* restore saved configuration register value */
-        //TODO: Figure out the right thing to do here...
-        //pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc);
-    }
-    return result;
-}
-
-/* Return negative errno on error. */
-static s32 i801_access(struct i2c_adapter *adap, u16 addr, unsigned short flags, char read_write, u8 command, int size, union i2c_smbus_data *data)
-{
-    int hwpec;
-    int block = 0;
-    int ret, xact = 0;
-    struct i2c_device *priv = i2c_get_adapdata(adap);
-    
-    dev_dbg(&priv->adapter.dev, "i801_access (addr=%0d)  flags=%x  read_write=%x  command=%x  size=%x",
-      addr, flags, read_write, command, size );
-    
-    hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK && size != I2C_SMBUS_I2C_BLOCK_DATA;
-    
-    switch (size) {
-        case I2C_SMBUS_QUICK:
-            dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_QUICK\n");
-            outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD(priv));
-            xact = I801_QUICK;
-            break;
-        case I2C_SMBUS_BYTE:
-            dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_BYTE\n");
-            
-            outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD(priv));
-            if (read_write == I2C_SMBUS_WRITE) {
-                outb_p(command, SMBHSTCMD(priv));
-            }
-            xact = I801_BYTE;
-            break;
-        case I2C_SMBUS_BYTE_DATA:
-            dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_BYTE_DATA\n");
-            outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD(priv));
-            outb_p(command, SMBHSTCMD(priv));
-            if (read_write == I2C_SMBUS_WRITE) {
-                outb_p(data->byte, SMBHSTDAT0(priv));
-            }
-            xact = I801_BYTE_DATA;
-            break;
-        case I2C_SMBUS_WORD_DATA:
-            dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_WORD_DATA\n");
-            outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD(priv));
-            outb_p(command, SMBHSTCMD(priv));
-            if (read_write == I2C_SMBUS_WRITE) {
-                outb_p(data->word & 0xff, SMBHSTDAT0(priv));
-                outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv));
-            }
-            xact = I801_WORD_DATA;
-            break;
-        case I2C_SMBUS_BLOCK_DATA:
-            dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_BLOCK_DATA\n");
-            outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD(priv));
-            outb_p(command, SMBHSTCMD(priv));
-            block = 1;
-            break;
-        case I2C_SMBUS_I2C_BLOCK_DATA:
-            dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_I2C_BLOCK_DATA\n");
-            /* NB: page 240 of ICH5 datasheet shows that the R/#W
-             * bit should be cleared here, even when reading */
-            outb_p((addr & 0x7f) << 1, SMBHSTADD(priv));
-            if (read_write == I2C_SMBUS_READ) {
-                /* NB: page 240 of ICH5 datasheet also shows
-                 * that DATA1 is the cmd field when reading */
-                outb_p(command, SMBHSTDAT1(priv));
-            } else {
-                outb_p(command, SMBHSTCMD(priv));
-            }
-            block = 1;
-            break;
-        default:
-            dev_dbg(&priv->adapter.dev, "  [acc] Unsupported transaction %d\n", size);
-            return -EOPNOTSUPP;
-    }
-    
-    if (hwpec) { /* enable/disable hardware PEC */
-        dev_dbg(&priv->adapter.dev, "  [acc] hwpec: yes\n");
-        outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv));
-    } else {
-        dev_dbg(&priv->adapter.dev, "  [acc] hwpec: no\n");
-        outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC), SMBAUXCTL(priv));
-    }
-    
-    if (block) {
-        //ret = 0;
-        dev_dbg(&priv->adapter.dev, "  [acc] block: yes\n");
-        ret = i801_block_transaction(priv, data, read_write, size, hwpec);
-    } else {
-        dev_dbg(&priv->adapter.dev, "  [acc] block: no\n");
-        ret = i801_transaction(priv, xact | ENABLE_INT9);
-    }
-    
-    /* Some BIOSes don't like it when PEC is enabled at reboot or resume
-       time, so we forcibly disable it after every transaction. Turn off
-       E32B for the same reason. */
-    if (hwpec || block) {
-        dev_dbg(&priv->adapter.dev, "  [acc] hwpec || block\n");
-        outb_p(inb_p(SMBAUXCTL(priv)) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
-    }
-    if (block) {
-        dev_dbg(&priv->adapter.dev, "  [acc] block\n");
-        return ret;
-    }
-    if (ret) {
-        dev_dbg(&priv->adapter.dev, "  [acc] ret %d\n", ret);
-        return ret;
-    }
-    if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK)) {
-        dev_dbg(&priv->adapter.dev, "  [acc] I2C_SMBUS_WRITE || I801_QUICK  -> ret 0\n");
-        return 0;
-    }
-    
-    switch (xact & 0x7f) {
-        case I801_BYTE:  /* Result put in SMBHSTDAT0 */
-        case I801_BYTE_DATA:
-            dev_dbg(&priv->adapter.dev, "  [acc] I801_BYTE or I801_BYTE_DATA\n");
-            data->byte = inb_p(SMBHSTDAT0(priv));
-            break;
-        case I801_WORD_DATA:
-            dev_dbg(&priv->adapter.dev, "  [acc] I801_WORD_DATA\n");
-            data->word = inb_p(SMBHSTDAT0(priv)) + (inb_p(SMBHSTDAT1(priv)) << 8);
-            break;
-    }
-    return 0;
-}
-
-
-
-static u32 i801_func(struct i2c_adapter *adapter)
-{
-    struct i2c_device *priv = i2c_get_adapdata(adapter);
-    
-    /* original settings
-    u32 f = I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
-      I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
-      I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK |
-      ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) |
-      ((priv->features & FEATURE_I2C_BLOCK_READ) ?
-       I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0);
-     */
-    
-    // http://lxr.free-electrons.com/source/include/uapi/linux/i2c.h#L85
-    
-    u32 f = 
-        I2C_FUNC_I2C                     | /* 0x00000001 (I enabled this one) */
-        !I2C_FUNC_10BIT_ADDR             | /* 0x00000002 */
-        !I2C_FUNC_PROTOCOL_MANGLING      | /* 0x00000004 */
-        ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) | /* 0x00000008 */
-        !I2C_FUNC_SMBUS_BLOCK_PROC_CALL  | /* 0x00008000 */
-        I2C_FUNC_SMBUS_QUICK             | /* 0x00010000 */
-        !I2C_FUNC_SMBUS_READ_BYTE        | /* 0x00020000 */
-        !I2C_FUNC_SMBUS_WRITE_BYTE       | /* 0x00040000 */
-        !I2C_FUNC_SMBUS_READ_BYTE_DATA   | /* 0x00080000 */
-        !I2C_FUNC_SMBUS_WRITE_BYTE_DATA  | /* 0x00100000 */
-        !I2C_FUNC_SMBUS_READ_WORD_DATA   | /* 0x00200000 */
-        !I2C_FUNC_SMBUS_WRITE_WORD_DATA  | /* 0x00400000 */
-        !I2C_FUNC_SMBUS_PROC_CALL        | /* 0x00800000 */
-        !I2C_FUNC_SMBUS_READ_BLOCK_DATA  | /* 0x01000000 */
-        !I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | /* 0x02000000 */
-        ((priv->features & FEATURE_I2C_BLOCK_READ) ? I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0) | /* 0x04000000 */
-        I2C_FUNC_SMBUS_WRITE_I2C_BLOCK   | /* 0x08000000 */
-        
-        I2C_FUNC_SMBUS_BYTE              | /* _READ_BYTE  _WRITE_BYTE */
-        I2C_FUNC_SMBUS_BYTE_DATA         | /* _READ_BYTE_DATA  _WRITE_BYTE_DATA */
-        I2C_FUNC_SMBUS_WORD_DATA         | /* _READ_WORD_DATA  _WRITE_WORD_DATA */
-        I2C_FUNC_SMBUS_BLOCK_DATA        | /* _READ_BLOCK_DATA  _WRITE_BLOCK_DATA */
-        !I2C_FUNC_SMBUS_I2C_BLOCK        | /* _READ_I2C_BLOCK  _WRITE_I2C_BLOCK */
-        !I2C_FUNC_SMBUS_EMUL;              /* _QUICK  _BYTE  _BYTE_DATA  _WORD_DATA  _PROC_CALL  _WRITE_BLOCK_DATA  _I2C_BLOCK _PEC */
-    return f;
-}
-
-static const struct i2c_algorithm smbus_algorithm = {
-    .smbus_xfer     = i801_access,
-    .functionality  = i801_func,
-};
-
-
-
-/********************************
- *** Part 2 - Driver Handlers ***
- ********************************/
-int pi2c_probe(struct platform_device *pldev)
-{
-    int err;
-    struct i2c_device *priv;
-    struct resource *res;
-    
-    dev_dbg(&pldev->dev, "pi2c_probe(pldev = %p '%s')\n", pldev, pldev->name);
-    
-    priv = kzalloc(sizeof(struct i2c_device), GFP_KERNEL);
-    if (!priv) {
-        return -ENOMEM;
-    }
-    
-    i2c_set_adapdata(&priv->adapter, priv);
-    priv->adapter.owner = THIS_MODULE;
-    priv->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
-    priv->adapter.algo = &smbus_algorithm;
-    
-    res = platform_get_resource(pldev, IORESOURCE_MEM, 0);
-    priv->smba = (unsigned long)ioremap_nocache(res->start, resource_size(res));
-    
-    priv->pldev = pldev;
-    pldev->dev.platform_data = priv;
-    
-    priv->features |= FEATURE_IDF;
-    priv->features |= FEATURE_I2C_BLOCK_READ;
-    priv->features |= FEATURE_SMBUS_PEC;
-    priv->features |= FEATURE_BLOCK_BUFFER;
-    
-    //init_MUTEX(&lddata->sem);
-    init_rwsem(&priv->rw_sem);
-    
-    /* set up the sysfs linkage to our parent device */
-    priv->adapter.dev.parent = &pldev->dev;
-    
-    /* Retry up to 3 times on lost arbitration */
-    priv->adapter.retries = 3;
-    
-    //snprintf(priv->adapter.name, sizeof(priv->adapter.name), "Fake SMBus I801 adapter at %04lx", priv->smba);
-    snprintf(priv->adapter.name, sizeof(priv->adapter.name), "Fake SMBus I801 adapter");
-    
-    err = i2c_add_adapter(&priv->adapter);
-    if (err) {
-        dev_err(&priv->adapter.dev, "Failed to add SMBus adapter\n");
-        return err;
-    }
-    
-    return 0;
-}
-
-int pi2c_remove(struct platform_device *pldev)
-{
-    struct i2c_device *lddev;
-    dev_dbg(&pldev->dev, "pi2c_remove(pldev = %p '%s')\n", pldev, pldev->name);
-    
-    lddev = (struct i2c_device *)pldev->dev.platform_data;
-    
-    i2c_del_adapter(&lddev->adapter);
-    
-    //TODO: Figure out the right thing to do here...
-    //pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
-    //pci_release_region(dev, SMBBAR);
-    //pci_set_drvdata(dev, NULL);
-    
-    //cdev_del(&lddev->cdev);
-    if(lddev != 0) {
-        kfree(lddev);
-        pldev->dev.platform_data = 0;
-    }
-    
-    return 0;
-}
-
-struct platform_driver i2c_plat_driver_i = {
-    .probe      = pi2c_probe,
-    .remove     = pi2c_remove,
-    .driver     = {
-        .name   = KP_DRIVER_NAME_I2C,
-        .owner  = THIS_MODULE,
-    },
-};
-
-module_platform_driver(i2c_plat_driver_i);
diff --git a/drivers/staging/kpc2000/kpc_spi/Makefile b/drivers/staging/kpc2000/kpc_spi/Makefile
deleted file mode 100644 (file)
index 3018d20..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-
-obj-m += kpc2000_spi.o
-kpc2000_spi-objs := spi_driver.o
diff --git a/drivers/staging/kpc2000/kpc_spi/spi_driver.c b/drivers/staging/kpc2000/kpc_spi/spi_driver.c
deleted file mode 100644 (file)
index 86df165..0000000
+++ /dev/null
@@ -1,507 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * KP2000 SPI controller driver
- *
- * Copyright (C) 2014-2018 Daktronics
- * Author: Matt Sickler <matt.sickler@daktronics.com>
- * Very loosely based on spi-omap2-mcspi.c
- */
-
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/interrupt.h>
-#include <linux/io-64-nonatomic-lo-hi.h>
-#include <linux/module.h>
-#include <linux/device.h>
-#include <linux/delay.h>
-#include <linux/platform_device.h>
-#include <linux/err.h>
-#include <linux/clk.h>
-#include <linux/io.h>
-#include <linux/slab.h>
-#include <linux/pm_runtime.h>
-#include <linux/of.h>
-#include <linux/of_device.h>
-#include <linux/gcd.h>
-#include <linux/spi/spi.h>
-#include <linux/spi/flash.h>
-#include <linux/mtd/partitions.h>
-
-#include "../kpc.h"
-#include "spi_parts.h"
-
-
-/***************
- * SPI Defines *
- ***************/
-#define KP_SPI_REG_CONFIG 0x0 /* 0x00 */
-#define KP_SPI_REG_STATUS 0x1 /* 0x08 */
-#define KP_SPI_REG_FFCTRL 0x2 /* 0x10 */
-#define KP_SPI_REG_TXDATA 0x3 /* 0x18 */
-#define KP_SPI_REG_RXDATA 0x4 /* 0x20 */
-
-#define KP_SPI_CLK           48000000
-#define KP_SPI_MAX_FIFODEPTH 64
-#define KP_SPI_MAX_FIFOWCNT  0xFFFF
-
-#define KP_SPI_REG_CONFIG_TRM_TXRX 0
-#define KP_SPI_REG_CONFIG_TRM_RX   1
-#define KP_SPI_REG_CONFIG_TRM_TX   2
-
-#define KP_SPI_REG_STATUS_RXS   0x01
-#define KP_SPI_REG_STATUS_TXS   0x02
-#define KP_SPI_REG_STATUS_EOT   0x04
-#define KP_SPI_REG_STATUS_TXFFE 0x10
-#define KP_SPI_REG_STATUS_TXFFF 0x20
-#define KP_SPI_REG_STATUS_RXFFE 0x40
-#define KP_SPI_REG_STATUS_RXFFF 0x80
-
-
-
-/******************
- * SPI Structures *
- ******************/
-struct kp_spi {
-       struct spi_master  *master;
-       u64 __iomem        *base;
-       unsigned long       phys;
-       struct device      *dev;
-       int                 fifo_depth;
-       unsigned int        pin_dir:1;
-};
-
-
-struct kp_spi_controller_state {
-    void __iomem   *base;
-    unsigned long   phys;
-    unsigned char   chip_select;
-    int             word_len;
-    s64             conf_cache;
-};
-
-
-union kp_spi_config {
-    /* use this to access individual elements */
-    struct __attribute__((packed)) spi_config_bitfield {
-        unsigned int pha       : 1; /* spim_clk Phase      */
-        unsigned int pol       : 1; /* spim_clk Polarity   */
-        unsigned int epol      : 1; /* spim_csx Polarity   */
-        unsigned int dpe       : 1; /* Transmission Enable */
-        unsigned int wl        : 5; /* Word Length         */
-        unsigned int           : 3;
-        unsigned int trm       : 2; /* TxRx Mode           */
-        unsigned int cs        : 4; /* Chip Select         */
-        unsigned int wcnt      : 7; /* Word Count          */
-        unsigned int ffen      : 1; /* FIFO Enable         */
-        unsigned int spi_en    : 1; /* SPI Enable          */
-        unsigned int           : 5;
-    } bitfield;
-    /* use this to grab the whole register */
-    u32 reg;
-};
-
-
-
-union kp_spi_status {
-    struct __attribute__((packed)) spi_status_bitfield {
-        unsigned int rx    :  1; /* Rx Status       */
-        unsigned int tx    :  1; /* Tx Status       */
-        unsigned int eo    :  1; /* End of Transfer */
-        unsigned int       :  1;
-        unsigned int txffe :  1; /* Tx FIFO Empty   */
-        unsigned int txfff :  1; /* Tx FIFO Full    */
-        unsigned int rxffe :  1; /* Rx FIFO Empty   */
-        unsigned int rxfff :  1; /* Rx FIFO Full    */
-        unsigned int       : 24;
-    } bitfield;
-    u32 reg;
-};
-
-
-
-union kp_spi_ffctrl {
-    struct __attribute__((packed)) spi_ffctrl_bitfield {
-        unsigned int ffstart :  1; /* FIFO Start */
-        unsigned int         : 31;
-    } bitfield;
-    u32 reg;
-};
-
-
-
-/***************
- * SPI Helpers *
- ***************/
-static inline int
-kp_spi_bytes_per_word(int word_len)
-{
-    if (word_len <= 8){
-        return 1;
-    }
-    else if (word_len <= 16) {
-        return 2;
-    }
-    else { /* word_len <= 32 */
-        return 4;
-    }
-}
-
-static inline u64
-kp_spi_read_reg(struct kp_spi_controller_state *cs, int idx)
-{
-    u64 __iomem *addr = cs->base;
-    u64 val;
-
-    addr += idx;
-    if ((idx == KP_SPI_REG_CONFIG) && (cs->conf_cache >= 0)){
-        return cs->conf_cache;
-    }
-    val = readq((void*)addr);
-    return val;
-}
-
-static inline void
-kp_spi_write_reg(struct kp_spi_controller_state *cs, int idx, u64 val)
-{
-    u64 __iomem *addr = cs->base;
-    addr += idx;
-    writeq(val, (void*)addr);
-    if (idx == KP_SPI_REG_CONFIG)
-        cs->conf_cache = val;
-}
-
-static int
-kp_spi_wait_for_reg_bit(struct kp_spi_controller_state *cs, int idx, unsigned long bit)
-{
-    unsigned long timeout;
-    timeout = jiffies + msecs_to_jiffies(1000);
-    while (!(kp_spi_read_reg(cs, idx) & bit)) {
-        if (time_after(jiffies, timeout)) {
-            if (!(kp_spi_read_reg(cs, idx) & bit)) {
-                return -ETIMEDOUT;
-            } else {
-                return 0;
-            }
-        }
-        cpu_relax();
-    }
-    return 0;
-}
-
-static unsigned
-kp_spi_txrx_pio(struct spi_device *spidev, struct spi_transfer *transfer)
-{
-    struct kp_spi_controller_state *cs = spidev->controller_state;
-    unsigned int count = transfer->len;
-    unsigned int c = count;
-    
-    int i;
-    u8 *rx       = transfer->rx_buf;
-    const u8 *tx = transfer->tx_buf;
-    int processed = 0;
-    
-    if (tx) {
-        for (i = 0 ; i < c ; i++) {
-            char val = *tx++;
-            
-            if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_TXS) < 0) {
-                goto out;
-            }
-            
-            kp_spi_write_reg(cs, KP_SPI_REG_TXDATA, val);
-            processed++;
-        }
-    }
-    else if(rx) {
-        for (i = 0 ; i < c ; i++) {
-            char test=0;
-            
-            kp_spi_write_reg(cs, KP_SPI_REG_TXDATA, 0x00);
-            
-            if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_RXS) < 0) {
-                goto out;
-            }
-            
-            test = kp_spi_read_reg(cs, KP_SPI_REG_RXDATA);
-            *rx++ = test;
-            processed++;
-        }
-    }
-    
-    if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_EOT) < 0) {
-        //TODO: Figure out how to abort transaction??  This has never happened in practice though...
-    }
-    
- out:
-    return processed;
-}
-
-/*****************
- * SPI Functions *
- *****************/
-static int
-kp_spi_setup(struct spi_device *spidev)
-{
-    union kp_spi_config sc;
-    struct kp_spi *kpspi = spi_master_get_devdata(spidev->master);
-    struct kp_spi_controller_state *cs;
-    
-    /* setup controller state */
-    cs = spidev->controller_state;
-    if (!cs) {
-        cs = kzalloc(sizeof(*cs), GFP_KERNEL);
-        if(!cs) {
-            return -ENOMEM;
-        }
-        cs->base = kpspi->base;
-        cs->phys = kpspi->phys;
-        cs->chip_select = spidev->chip_select;
-        cs->word_len = spidev->bits_per_word;
-        cs->conf_cache = -1;
-        spidev->controller_state = cs;
-    }
-    
-    /* set config register */
-    sc.bitfield.wl = spidev->bits_per_word - 1;
-    sc.bitfield.cs = spidev->chip_select;
-    sc.bitfield.spi_en = 0;
-    sc.bitfield.trm = 0;
-    sc.bitfield.ffen = 0;
-    kp_spi_write_reg(spidev->controller_state, KP_SPI_REG_CONFIG, sc.reg);
-    return 0;
-}
-
-static int
-kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
-{
-    struct kp_spi_controller_state *cs;
-    struct spi_device   *spidev;
-    struct kp_spi       *kpspi;
-    struct spi_transfer *transfer;
-    union kp_spi_config sc;
-    int status = 0;
-    
-    spidev = m->spi;
-    kpspi = spi_master_get_devdata(master);
-    m->actual_length = 0;
-    m->status = 0;
-    
-    cs = spidev->controller_state;
-    
-    /* reject invalid messages and transfers */
-    if (list_empty(&m->transfers)) {
-        return -EINVAL;
-    }
-    
-    /* validate input */
-    list_for_each_entry(transfer, &m->transfers, transfer_list) {
-        const void *tx_buf = transfer->tx_buf;
-        void       *rx_buf = transfer->rx_buf;
-        unsigned    len = transfer->len;
-        
-        if (transfer->speed_hz > KP_SPI_CLK || (len && !(rx_buf || tx_buf))) {
-            dev_dbg(kpspi->dev, "  transfer: %d Hz, %d %s%s, %d bpw\n",
-                    transfer->speed_hz,
-                    len,
-                    tx_buf ? "tx" : "",
-                    rx_buf ? "rx" : "",
-                    transfer->bits_per_word);
-            dev_dbg(kpspi->dev, "  transfer -EINVAL\n");
-            return -EINVAL;
-        }
-        if (transfer->speed_hz && (transfer->speed_hz < (KP_SPI_CLK >> 15))) {
-            dev_dbg(kpspi->dev, "speed_hz %d below minimum %d Hz\n",
-                    transfer->speed_hz,
-                    KP_SPI_CLK >> 15);
-            dev_dbg(kpspi->dev, "  speed_hz -EINVAL\n");
-            return -EINVAL;
-        }
-    }
-    
-    /* assert chip select to start the sequence*/
-    sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
-    sc.bitfield.spi_en = 1;
-    kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
-    
-    /* work */
-    if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_EOT) < 0) {
-        dev_info(kpspi->dev, "EOT timed out\n");
-        goto out;
-    }
-    
-    /* do the transfers for this message */
-    list_for_each_entry(transfer, &m->transfers, transfer_list) {
-        if (transfer->tx_buf == NULL && transfer->rx_buf == NULL && transfer->len) {
-            status = -EINVAL;
-            break;
-        }
-        
-        /* transfer */
-        if (transfer->len) {
-            unsigned int word_len = spidev->bits_per_word;
-            unsigned count;
-            
-            /* set up the transfer... */
-            sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
-            
-            /* ...direction */
-            if (transfer->tx_buf) {
-                sc.bitfield.trm = KP_SPI_REG_CONFIG_TRM_TX;
-            }
-            else if (transfer->rx_buf) {
-                sc.bitfield.trm = KP_SPI_REG_CONFIG_TRM_RX;
-            }
-            
-            /* ...word length */
-            if (transfer->bits_per_word) {
-                word_len = transfer->bits_per_word;
-            }
-            cs->word_len = word_len;
-            sc.bitfield.wl = word_len-1;
-            
-            /* ...chip select */
-            sc.bitfield.cs = spidev->chip_select;
-            
-            /* ...and write the new settings */
-            kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
-            
-            /* do the transfer */
-            count = kp_spi_txrx_pio(spidev, transfer);
-            m->actual_length += count;
-            
-            if (count != transfer->len) {
-                status = -EIO;
-                break;
-            }
-        }
-        
-        if (transfer->delay_usecs) {
-            udelay(transfer->delay_usecs);
-        }
-    }
-    
-    /* de-assert chip select to end the sequence */
-    sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
-    sc.bitfield.spi_en = 0;
-    kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
-    
- out:
-    /* done work */
-    spi_finalize_current_message(master);
-    return 0;
-}
-
-static void
-kp_spi_cleanup(struct spi_device *spidev)
-{
-    struct kp_spi_controller_state *cs = spidev->controller_state;
-    if (cs) {
-        kfree(cs);
-    }
-}
-
-
-
-/******************
- * Probe / Remove *
- ******************/
-static int
-kp_spi_probe(struct platform_device *pldev)
-{
-    struct kpc_core_device_platdata *drvdata;
-    struct spi_master *master;
-    struct kp_spi *kpspi;
-    struct resource *r;
-    int status = 0;
-    int i;
-
-    drvdata = pldev->dev.platform_data;
-    if (!drvdata){
-        dev_err(&pldev->dev, "kp_spi_probe: platform_data is NULL!\n");
-        return -ENODEV;
-    }
-    
-    master = spi_alloc_master(&pldev->dev, sizeof(struct kp_spi));
-    if (master == NULL) {
-        dev_err(&pldev->dev, "kp_spi_probe: master allocation failed\n");
-        return -ENOMEM;
-    }
-    
-    /* set up the spi functions */
-    master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
-    master->bits_per_word_mask = (unsigned int)SPI_BPW_RANGE_MASK(4, 32);
-    master->setup = kp_spi_setup;
-    master->transfer_one_message = kp_spi_transfer_one_message;
-    master->cleanup = kp_spi_cleanup;
-    
-    platform_set_drvdata(pldev, master);
-    
-    kpspi = spi_master_get_devdata(master);
-    kpspi->master = master;
-    kpspi->dev = &pldev->dev;
-    
-    master->num_chipselect = 4;
-    if (pldev->id != -1) {
-        master->bus_num = pldev->id;
-    }
-    kpspi->pin_dir = 0;
-    
-    r = platform_get_resource(pldev, IORESOURCE_MEM, 0);
-    if (r == NULL) {
-        dev_err(&pldev->dev, "kp_spi_probe: Unable to get platform resources\n");
-        status = -ENODEV;
-        goto free_master;
-    }
-    
-    kpspi->phys = (unsigned long)ioremap_nocache(r->start, resource_size(r));
-    kpspi->base = (u64 __iomem *)kpspi->phys;
-    
-    status = spi_register_master(master);
-    if (status < 0) {
-        dev_err(&pldev->dev, "Unable to register SPI device\n");
-        goto free_master;
-    }
-    
-    /* register the slave boards */
-    #define NEW_SPI_DEVICE_FROM_BOARD_INFO_TABLE(table) \
-        for (i = 0 ; i < ARRAY_SIZE(table) ; i++) { \
-            spi_new_device(master, &(table[i])); \
-        }
-    
-    switch ((drvdata->card_id & 0xFFFF0000) >> 16){
-        case PCI_DEVICE_ID_DAKTRONICS_KADOKA_P2KR0:
-            NEW_SPI_DEVICE_FROM_BOARD_INFO_TABLE(p2kr0_board_info);
-            break;
-        default:
-            dev_err(&pldev->dev, "Unknown hardware, cant know what partition table to use!\n");
-            goto free_master;
-            break;
-    }
-    
-    return status;
-
- free_master:
-    spi_master_put(master);
-    return status;
-}
-
-static int
-kp_spi_remove(struct platform_device *pldev)
-{
-    struct spi_master * master = platform_get_drvdata(pldev);
-    spi_unregister_master(master);
-    return 0;
-}
-
-
-static struct platform_driver kp_spi_driver = {
-    .driver = {
-        .name =     KP_DRIVER_NAME_SPI,
-    },
-    .probe =    kp_spi_probe,
-    .remove =   kp_spi_remove,
-};
-
-module_platform_driver(kp_spi_driver);
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("platform:kp_spi");
diff --git a/drivers/staging/kpc2000/kpc_spi/spi_parts.h b/drivers/staging/kpc2000/kpc_spi/spi_parts.h
deleted file mode 100644 (file)
index 33e62ac..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-#ifndef __KPC_SPI_SPI_PARTS_H__
-#define __KPC_SPI_SPI_PARTS_H__
-
-static struct mtd_partition p2kr0_spi0_parts[] = {
-    { .name = "SLOT_0",    .size = 7798784,          .offset = 0,                 },
-    { .name = "SLOT_1",    .size = 7798784,          .offset = MTDPART_OFS_NXTBLK },
-    { .name = "SLOT_2",    .size = 7798784,          .offset = MTDPART_OFS_NXTBLK },
-    { .name = "SLOT_3",    .size = 7798784,          .offset = MTDPART_OFS_NXTBLK },
-    { .name = "CS0_EXTRA", .size = MTDPART_SIZ_FULL, .offset = MTDPART_OFS_NXTBLK }
-};
-static struct mtd_partition p2kr0_spi1_parts[] = {
-    { .name = "SLOT_4",    .size   = 7798784,          .offset = 0,                 },
-    { .name = "SLOT_5",    .size   = 7798784,          .offset = MTDPART_OFS_NXTBLK },
-    { .name = "SLOT_6",    .size   = 7798784,          .offset = MTDPART_OFS_NXTBLK },
-    { .name = "SLOT_7",    .size   = 7798784,          .offset = MTDPART_OFS_NXTBLK },
-    { .name = "CS1_EXTRA", .size   = MTDPART_SIZ_FULL, .offset = MTDPART_OFS_NXTBLK }
-};
-
-static struct flash_platform_data p2kr0_spi0_pdata = {
-    .name = "SPI0",
-    .nr_parts = ARRAY_SIZE(p2kr0_spi0_parts),
-    .parts = p2kr0_spi0_parts,
-};
-static struct flash_platform_data p2kr0_spi1_pdata = {
-    .name = "SPI1",
-    .nr_parts = ARRAY_SIZE(p2kr0_spi1_parts),
-    .parts = p2kr0_spi1_parts,
-};
-
-static struct spi_board_info p2kr0_board_info[] = {
-    {
-        .modalias = "n25q256a11",
-        .bus_num = 1,
-        .chip_select = 0,
-        .mode = SPI_MODE_0,
-        .platform_data = &p2kr0_spi0_pdata
-    },
-    {
-        .modalias = "n25q256a11",
-        .bus_num = 1,
-        .chip_select = 1,
-        .mode = SPI_MODE_0,
-        .platform_data = &p2kr0_spi1_pdata
-    },
-};
-
-#endif
index 74551eb717fc7b6efb11756df57c559c0ccfa5b6..4b379542ecd500b5d2f41a5f9a583b45f0a6163f 100644 (file)
@@ -380,7 +380,7 @@ int ks_wlan_hw_tx(struct ks_wlan_private *priv, void *p, unsigned long size,
                                           struct sk_buff *skb),
                  struct sk_buff *skb)
 {
-       int result = 0;
+       int result;
        struct hostif_hdr *hdr;
 
        hdr = (struct hostif_hdr *)p;
index e089366ed02a08fc8b44dda64247d80c91cb33ab..2666f9e30c155006a5d68b749dbe7d53c7b69997 100644 (file)
@@ -1067,7 +1067,6 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb)
        unsigned int length = 0;
        struct hostif_data_request *pp;
        unsigned char *p;
-       int result = 0;
        unsigned short eth_proto;
        struct ether_hdr *eth_hdr;
        unsigned short keyinfo = 0;
@@ -1209,8 +1208,8 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb)
        pp->header.event = cpu_to_le16(HIF_DATA_REQ);
 
        /* tx request */
-       result = ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp) + skb_len),
-                              send_packet_complete, skb);
+       ret = ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp) + skb_len),
+                           send_packet_complete, skb);
 
        /* MIC FAILURE REPORT check */
        if (eth_proto == ETH_P_PAE &&
@@ -1225,7 +1224,7 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb)
                        priv->wpa.mic_failure.stop = 1;
        }
 
-       return result;
+       return ret;
 
 err_kfree:
        kfree(pp);
index 25b3e18c4d9121813ed4666033359e0bffc16c88..2bf811449b0b0dd02199d451989ddb63cfa906dd 100644 (file)
@@ -31,13 +31,13 @@ Description:
                                or output
 
                dbr_size        configure DBR data buffer size (this is used
-                               for MediaLB communiction only)
+                               for MediaLB communication only)
 
                packets_per_xact
                                configure the number of packets that will be
                                collected from the network before being
                                transmitted via USB (this is used for USB
-                               communiction only)
+                               communication only)
 
                device          name of the device the link is to be attached to
 
@@ -75,13 +75,13 @@ Description:
                                or output
 
                dbr_size        configure DBR data buffer size (this is used
-                               for MediaLB communiction only)
+                               for MediaLB communication only)
 
                packets_per_xact
                                configure the number of packets that will be
                                collected from the network before being
                                transmitted via USB (this is used for USB
-                               communiction only)
+                               communication only)
 
                device          name of the device the link is to be attached to
 
@@ -119,13 +119,13 @@ Description:
                                or output
 
                dbr_size        configure DBR data buffer size (this is used
-                               for MediaLB communiction only)
+                               for MediaLB communication only)
 
                packets_per_xact
                                configure the number of packets that will be
                                collected from the network before being
                                transmitted via USB (this is used for USB
-                               communiction only)
+                               communication only)
 
                device          name of the device the link is to be attached to
 
@@ -173,13 +173,13 @@ Description:
                                or output
 
                dbr_size        configure DBR data buffer size (this is used
-                               for MediaLB communiction only)
+                               for MediaLB communication only)
 
                packets_per_xact
                                configure the number of packets that will be
                                collected from the network before being
                                transmitted via USB (this is used for USB
-                               communiction only)
+                               communication only)
 
                device          name of the device the link is to be attached to
 
index 56d79195bb3c2c51deda21622dbc4816b7da1030..2fa8dea1da4d2a83e1302f292a0ddf073d2e220d 100644 (file)
@@ -42,7 +42,7 @@ the attached network interface controller hardware. Hence, a given module
 of this layer is designed to handle exactly one of the peripheral
 interfaces (e.g. USB, MediaLB, I2C) the hardware provides.
 
-A module of the application layer is referred to as a core comoponent,
+A module of the application layer is referred to as a core component,
 which kind of extends the core by providing connectivity to the user space.
 Applications, then, can access a MOST network via character devices, an
 ALSA soundcard, a Network adapter or a V4L2 capture device.
@@ -119,7 +119,7 @@ following components are available
 
 The driver is to be configured via configfs. Each loaded component kernel
 object (see section 1.3) registers a subsystem with configfs, which is used to
-configure and establish communiction pathways (links) to attached devices on
+configure and establish communication pathways (links) to attached devices on
 the bus. To do so, the user has to descend into the component's configuration
 directory and create a new directory (child config itmes). The name of this
 directory will be used as a reference for the link and it will contain the
@@ -137,12 +137,12 @@ following attributes:
        - direction
          configure whether this link will be an input or output
        - dbr_size
-         configure DBR data buffer size (this is used for MediaLB communiction
+         configure DBR data buffer size (this is used for MediaLB communication
          only)
        - packets_per_xact
          configure the number of packets that will be collected from the
          network before being transmitted via USB (this is used for USB
-         communiction only)
+         communication only)
        - device
          name of the device the link is to be attached to
        - channel
index db32ea7d1743639f8f98cada873ed28b13d69abe..8948d52464091b0925a3ce41fef719e09a6c5d8a 100644 (file)
@@ -3,7 +3,7 @@ menuconfig MOST
         tristate "MOST support"
        depends on HAS_DMA && CONFIGFS_FS
         default n
-        ---help---
+        help
          Say Y here if you want to enable MOST support.
          This driver needs at least one additional component to enable the
          desired access from userspace (e.g. character devices) and one that
index 1d8bf29e0ffb49218950b976acdc71d42dee8b7c..025495657b68a805b1a333446f8b6d6ba78bdae6 100644 (file)
@@ -35,56 +35,42 @@ static struct list_head mdev_link_list;
 
 static int set_cfg_buffer_size(struct mdev_link *link)
 {
-       if (!link->buffer_size)
-               return -ENODATA;
        return most_set_cfg_buffer_size(link->device, link->channel,
                                        link->buffer_size);
 }
 
 static int set_cfg_subbuffer_size(struct mdev_link *link)
 {
-       if (!link->subbuffer_size)
-               return -ENODATA;
        return most_set_cfg_subbuffer_size(link->device, link->channel,
                                           link->subbuffer_size);
 }
 
 static int set_cfg_dbr_size(struct mdev_link *link)
 {
-       if (!link->dbr_size)
-               return -ENODATA;
        return most_set_cfg_dbr_size(link->device, link->channel,
                                     link->dbr_size);
 }
 
 static int set_cfg_num_buffers(struct mdev_link *link)
 {
-       if (!link->num_buffers)
-               return -ENODATA;
        return most_set_cfg_num_buffers(link->device, link->channel,
                                        link->num_buffers);
 }
 
 static int set_cfg_packets_xact(struct mdev_link *link)
 {
-       if (!link->packets_per_xact)
-               return -ENODATA;
        return most_set_cfg_packets_xact(link->device, link->channel,
                                         link->packets_per_xact);
 }
 
 static int set_cfg_direction(struct mdev_link *link)
 {
-       if (!strlen(link->direction))
-               return -ENODATA;
        return most_set_cfg_direction(link->device, link->channel,
                                      link->direction);
 }
 
 static int set_cfg_datatype(struct mdev_link *link)
 {
-       if (!strlen(link->datatype))
-               return -ENODATA;
        return most_set_cfg_datatype(link->device, link->channel,
                                     link->datatype);
 }
index c8a64e20902736e2c9b78d6cd8132f9308432ece..aababdf2be12c8d803171b917bc5e76a9d8fb5a2 100644 (file)
@@ -507,13 +507,24 @@ static struct core_component comp = {
 
 static int __init most_net_init(void)
 {
+       int err;
+
        spin_lock_init(&list_lock);
        mutex_init(&probe_disc_mt);
-       return most_register_component(&comp);
+       err = most_register_component(&comp);
+       if (err)
+               return err;
+       err = most_register_configfs_subsys(&comp);
+       if (err) {
+               most_deregister_component(&comp);
+               return err;
+       }
+       return 0;
 }
 
 static void __exit most_net_exit(void)
 {
+       most_deregister_configfs_subsys(&comp);
        most_deregister_component(&comp);
 }
 
index adca250062e1beb29d8ad48bce0a038b2b58994a..6f6e98ab0550073132edd745d1313552c844c309 100644 (file)
@@ -250,11 +250,6 @@ static int vidioc_querycap(struct file *file, void *priv,
        strlcpy(cap->card, "MOST", sizeof(cap->card));
        snprintf(cap->bus_info, sizeof(cap->bus_info),
                 "%s", mdev->iface->description);
-
-       cap->capabilities =
-               V4L2_CAP_READWRITE |
-               V4L2_CAP_TUNER |
-               V4L2_CAP_VIDEO_CAPTURE;
        return 0;
 }
 
@@ -366,6 +361,7 @@ static const struct video_device comp_videodev_template = {
        .release = video_device_release,
        .ioctl_ops = &video_ioctl_ops,
        .tvnorms = V4L2_STD_UNKNOWN,
+       .device_caps = V4L2_CAP_READWRITE | V4L2_CAP_VIDEO_CAPTURE,
 };
 
 /**************************************************************************/
@@ -540,8 +536,18 @@ static struct core_component comp = {
 
 static int __init comp_init(void)
 {
+       int err;
+
        spin_lock_init(&list_lock);
-       return most_register_component(&comp);
+       err = most_register_component(&comp);
+       if (err)
+               return err;
+       err = most_register_configfs_subsys(&comp);
+       if (err) {
+               most_deregister_component(&comp);
+               return err;
+       }
+       return 0;
 }
 
 static void __exit comp_exit(void)
@@ -566,6 +572,7 @@ static void __exit comp_exit(void)
        }
        spin_unlock_irq(&list_lock);
 
+       most_deregister_configfs_subsys(&comp);
        most_deregister_component(&comp);
        BUG_ON(!list_empty(&video_devices));
 }
index 0fbb9932d6bbd3c9516d6d89ed00704dce24fd7c..60db06768c8ab9c4bcc78ffb53deb7a406d64557 100644 (file)
@@ -468,7 +468,7 @@ static struct dma_async_tx_descriptor *mtk_hsdma_prep_dma_memcpy(
        if (len <= 0)
                return NULL;
 
-       desc = kzalloc(sizeof(struct mtk_hsdma_desc), GFP_ATOMIC);
+       desc = kzalloc(sizeof(*desc), GFP_ATOMIC);
        if (!desc) {
                dev_err(c->device->dev, "alloc memcpy decs error\n");
                return NULL;
@@ -664,9 +664,8 @@ static int mtk_hsdma_probe(struct platform_device *pdev)
                return -EINVAL;
 
        hsdma = devm_kzalloc(&pdev->dev, sizeof(*hsdma), GFP_KERNEL);
-       if (!hsdma) {
+       if (!hsdma)
                return -EINVAL;
-       }
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        base = devm_ioremap_resource(&pdev->dev, res);
index 3ea08ab9d0d3f14e1da8f0ed6801b744c5088d16..6932ab7acadf3f518b398c5abaeda3bf2301a392 100644 (file)
@@ -1,6 +1,11 @@
 # SPDX-License-Identifier: GPL-2.0
 config DTB_GNUBEE1
-       bool "GnuBee1 NAS"
+       bool "GnuBee1 2.5inch NAS"
+       depends on SOC_MT7621 && DTB_RT_NONE
+       select BUILTIN_DTB
+
+config DTB_GNUBEE2
+       bool "GnuBee2 3.5inch NAS"
        depends on SOC_MT7621 && DTB_RT_NONE
        select BUILTIN_DTB
 
index aeec48a4edc7c25f39258578e2f1848a24f286b5..b4ab99fed932b1f3c7a3975f49b2b6d3e4f2b3aa 100644 (file)
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 dtb-$(CONFIG_DTB_GNUBEE1)      += gbpc1.dtb
+dtb-$(CONFIG_DTB_GNUBEE2)      += gbpc2.dtb
 
 obj-y                          += $(patsubst %.dtb, %.dtb.o, $(dtb-y))
index 15803132c1ea798a28b2e39bb4f848d9f2d113d2..1b758e5c84e00d486d0a8ab213764e0d82fac47f 100644 (file)
@@ -2,4 +2,4 @@
 - ensure all usage matches code
 - ensure all features used are documented
 
-Cc: NeilBrown <neil@brown.name>
\ No newline at end of file
+Cc: NeilBrown <neil@brown.name>
index 250c15ace2a71147be4e6f14e522b6a3e898745e..1fb560ff059c83ff3a130c3b50bd20c0c67620d2 100644 (file)
 
 &pinctrl {
        state_default: pinctrl0 {
-               gpio {
+               default_gpio: gpio {
                        groups = "wdt", "rgmii2", "uart3";
                        function = "gpio";
                };
diff --git a/drivers/staging/mt7621-dts/gbpc2.dts b/drivers/staging/mt7621-dts/gbpc2.dts
new file mode 100644 (file)
index 0000000..52760e7
--- /dev/null
@@ -0,0 +1,21 @@
+/dts-v1/;
+
+#include "gbpc1.dts"
+
+/ {
+       compatible = "gnubee,gb-pc2", "mediatek,mt7621-soc";
+       model = "GB-PC2";
+};
+
+&default_gpio {
+       groups = "wdt", "uart3";
+       function = "gpio";
+};
+
+&gmac1 {
+       status = "ok";
+};
+
+&phy_external {
+       status = "ok";
+};
index 280ec33c854049a16646255eb5aeb810aa84e2d1..a4c08110094b3b1345d2323f58d90a38bb99a820 100644 (file)
@@ -1,4 +1,5 @@
 #include <dt-bindings/interrupt-controller/mips-gic.h>
+#include <dt-bindings/gpio/gpio.h>
 
 / {
        #address-cells = <1>;
                clock-frequency = <220000000>;
        };
 
+       mmc_clock: mmc_clock@0 {
+               #clock-cells = <0>;
+               compatible = "fixed-clock";
+               clock-frequency = <48000000>;
+       };
+
+       mmc_fixed_3v3: fixedregulator@0 {
+               compatible = "regulator-fixed";
+               regulator-name = "mmc_power";
+               regulator-min-microvolt = <3300000>;
+               regulator-max-microvolt = <3300000>;
+               enable-active-high;
+               regulator-always-on;
+         };
+
+         mmc_fixed_1v8_io: fixedregulator@1 {
+               compatible = "regulator-fixed";
+               regulator-name = "mmc_io";
+               regulator-min-microvolt = <1800000>;
+               regulator-max-microvolt = <1800000>;
+               enable-active-high;
+               regulator-always-on;
+       };
+
        palmbus: palmbus@1E000000 {
                compatible = "palmbus";
                reg = <0x1E000000 0x100000>;
        sdhci: sdhci@1E130000 {
                status = "disabled";
 
-               compatible = "ralink,mt7620-sdhci";
+               compatible = "mediatek,mt7620-mmc";
                reg = <0x1E130000 0x4000>;
 
+               bus-width = <4>;
+               max-frequency = <48000000>;
+               cap-sd-highspeed;
+               cap-mmc-highspeed;
+               vmmc-supply = <&mmc_fixed_3v3>;
+               vqmmc-supply = <&mmc_fixed_1v8_io>;
+               disable-wp;
+
+               pinctrl-names = "default", "state_uhs";
+               pinctrl-0 = <&sdhci_pins>;
+               pinctrl-1 = <&sdhci_pins>;
+
+               clocks = <&mmc_clock &mmc_clock>;
+               clock-names = "source", "hclk";
+
                interrupt-parent = <&gic>;
                interrupts = <GIC_SHARED 20 IRQ_TYPE_LEVEL_HIGH>;
        };
                        compatible = "mediatek,eth-mac";
                        reg = <1>;
                        status = "off";
-                       phy-mode = "rgmii";
-                       phy-handle = <&phy5>;
+                       phy-mode = "rgmii-rxid";
+                       phy-handle = <&phy_external>;
                };
                mdio-bus {
                        #address-cells = <1>;
                        #size-cells = <0>;
 
-                       phy5: ethernet-phy@5 {
+                       phy_external: ethernet-phy@5 {
+                               status = "off";
                                reg = <5>;
-                               phy-mode = "rgmii";
+                               phy-mode = "rgmii-rxid";
+
+                               pinctrl-names = "default";
+                               pinctrl-0 = <&rgmii2_pins>;
                        };
 
                        switch0: switch0@0 {
                #address-cells = <3>;
                #size-cells = <2>;
 
+               perst-gpio = <&gpio 19 GPIO_ACTIVE_HIGH>;
                pinctrl-names = "default";
                pinctrl-0 = <&pcie_pins>;
 
index 2576f179e30afe274c78d1ea458a7f1145ae1f99..d2a07f145143af1a2abe96cedc4fd0754122885f 100644 (file)
 #include <mt7621.h>
 #include <ralink_regs.h>
 
-#define RALINK_CLKCFG1                         0x30
-
-#define PCIE_PORT_CLK_EN(x)                    BIT(24 + (x))
-
 #define RG_PE1_PIPE_REG                                0x02c
 #define RG_PE1_PIPE_RST                                BIT(12)
 #define RG_PE1_PIPE_CMD_FRC                    BIT(4)
@@ -286,10 +282,6 @@ static int mt7621_pci_phy_power_off(struct phy *phy)
 
 static int mt7621_pci_phy_exit(struct phy *phy)
 {
-       struct mt7621_pci_phy_instance *instance = phy_get_drvdata(phy);
-
-       rt_sysc_m32(PCIE_PORT_CLK_EN(instance->index), 0, RALINK_CLKCFG1);
-
        return 0;
 }
 
index 5a6ee4103cd58f43f89943fa0f1922b1d39ad825..604ec813bd45f432b2a2959e11f819dfd11e73eb 100644 (file)
@@ -6,6 +6,7 @@ Required properties:
 - reg: Base addresses and lengths of the PCIe subsys and root ports.
 - bus-range: Range of bus numbers associated with this controller.
 - #address-cells: Address representation for root ports (must be 3)
+- perst-gpio: PCIe reset signal line.
 - pinctrl-names : The pin control state names.
 - pinctrl-0: The "default" pinctrl state.
 - #size-cells: Size representation for root ports (must be 2)
@@ -48,6 +49,7 @@ Example for MT7621:
                #address-cells = <3>;
                #size-cells = <2>;
 
+               perst-gpio = <&gpio 19 GPIO_ACTIVE_HIGH>;
                pinctrl-names = "default";
                pinctrl-0 = <&pcie_pins>;
 
index 03d919a945521345bd0270bc4ce3dbd702913864..89fa813142abe219a502b87203f0291c5ffddcac 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <linux/bitops.h>
 #include <linux/delay.h>
+#include <linux/gpio/consumer.h>
 #include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/of.h>
 
 /* sysctl */
 #define MT7621_CHIP_REV_ID             0x0c
+#define MT7621_GPIO_MODE               0x60
 #define CHIP_REV_MT7621_E2             0x0101
 
 /* MediaTek specific configuration registers */
 #define PCIE_FTS_NUM                   0x70c
 #define PCIE_FTS_NUM_MASK              GENMASK(15, 8)
-#define PCIE_FTS_NUM_L0(x)             ((x) & 0xff << 8)
+#define PCIE_FTS_NUM_L0(x)             (((x) & 0xff) << 8)
 
 /* rt_sysc_membase relative registers */
+#define RALINK_CLKCFG1                 0x30
 #define RALINK_PCIE_CLK_GEN            0x7c
 #define RALINK_PCIE_CLK_GEN1           0x80
 
@@ -81,7 +84,6 @@
 #define PCIE_BAR_ENABLE                        BIT(0)
 #define PCIE_PORT_INT_EN(x)            BIT(20 + (x))
 #define PCIE_PORT_CLK_EN(x)            BIT(24 + (x))
-#define PCIE_PORT_PERST(x)             BIT(1 + (x))
 #define PCIE_PORT_LINKUP               BIT(0)
 
 #define PCIE_CLK_GEN_EN                        BIT(31)
@@ -89,6 +91,9 @@
 #define PCIE_CLK_GEN1_DIS              GENMASK(30, 24)
 #define PCIE_CLK_GEN1_EN               (BIT(27) | BIT(25))
 #define MEMORY_BASE                    0x0
+#define PERST_MODE_MASK                        GENMASK(11, 10)
+#define PERST_MODE_GPIO                        BIT(10)
+#define PERST_DELAY_US                 1000
 
 /**
  * struct mt7621_pcie_port - PCIe port information
@@ -119,6 +124,7 @@ struct mt7621_pcie_port {
  * @offset: IO / Memory offset
  * @dev: Pointer to PCIe device
  * @ports: pointer to PCIe port information
+ * @perst: gpio reset
  * @rst: pointer to pcie reset
  */
 struct mt7621_pcie {
@@ -132,6 +138,7 @@ struct mt7621_pcie {
                resource_size_t io;
        } offset;
        struct list_head ports;
+       struct gpio_desc *perst;
        struct reset_control *rst;
 };
 
@@ -198,6 +205,28 @@ static void write_config(struct mt7621_pcie *pcie, unsigned int dev,
        pcie_write(pcie, val, RALINK_PCI_CONFIG_DATA);
 }
 
+static inline void mt7621_perst_gpio_pcie_assert(struct mt7621_pcie *pcie)
+{
+       gpiod_set_value(pcie->perst, 0);
+       mdelay(PERST_DELAY_US);
+}
+
+static inline void mt7621_perst_gpio_pcie_deassert(struct mt7621_pcie *pcie)
+{
+       gpiod_set_value(pcie->perst, 1);
+       mdelay(PERST_DELAY_US);
+}
+
+static inline bool mt7621_pcie_port_is_linkup(struct mt7621_pcie_port *port)
+{
+       return (pcie_port_read(port, RALINK_PCI_STATUS) & PCIE_PORT_LINKUP) != 0;
+}
+
+static inline void mt7621_pcie_port_clk_disable(struct mt7621_pcie_port *port)
+{
+       rt_sysc_m32(PCIE_PORT_CLK_EN(port->slot), 0, RALINK_CLKCFG1);
+}
+
 static inline void mt7621_control_assert(struct mt7621_pcie_port *port)
 {
        u32 chip_rev_id = rt_sysc_r32(MT7621_CHIP_REV_ID);
@@ -344,6 +373,12 @@ static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie)
        struct resource regs;
        int err;
 
+       pcie->perst = devm_gpiod_get(dev, "perst", GPIOD_OUT_HIGH);
+       if (IS_ERR(pcie->perst)) {
+               dev_err(dev, "failed to get gpio perst\n");
+               return PTR_ERR(pcie->perst);
+       }
+
        err = of_address_to_resource(node, 0, &regs);
        if (err) {
                dev_err(dev, "missing \"reg\" property\n");
@@ -384,7 +419,6 @@ static int mt7621_pcie_init_port(struct mt7621_pcie_port *port)
        struct mt7621_pcie *pcie = port->pcie;
        struct device *dev = pcie->dev;
        u32 slot = port->slot;
-       u32 val = 0;
        int err;
 
        /*
@@ -393,47 +427,35 @@ static int mt7621_pcie_init_port(struct mt7621_pcie_port *port)
         */
        mt7621_reset_port(port);
 
-       val = read_config(pcie, slot, PCIE_FTS_NUM);
-       dev_info(dev, "Port %d N_FTS = %x\n", (unsigned int)val, slot);
-
        err = phy_init(port->phy);
        if (err) {
                dev_err(dev, "failed to initialize port%d phy\n", slot);
-               goto err_phy_init;
+               return err;
        }
 
        err = phy_power_on(port->phy);
        if (err) {
                dev_err(dev, "failed to power on port%d phy\n", slot);
-               goto err_phy_on;
-       }
-
-       if ((pcie_port_read(port, RALINK_PCI_STATUS) & PCIE_PORT_LINKUP) == 0) {
-               dev_err(dev, "pcie%d no card, disable it (RST & CLK)\n", slot);
-               mt7621_control_assert(port);
-               port->enabled = false;
-               err = -ENODEV;
-               goto err_no_link_up;
+               phy_exit(port->phy);
+               return err;
        }
 
        port->enabled = true;
 
        return 0;
-
-err_no_link_up:
-       phy_power_off(port->phy);
-err_phy_on:
-       phy_exit(port->phy);
-err_phy_init:
-       return err;
 }
 
 static void mt7621_pcie_init_ports(struct mt7621_pcie *pcie)
 {
        struct device *dev = pcie->dev;
        struct mt7621_pcie_port *port, *tmp;
+       u32 val = 0;
        int err;
 
+       rt_sysc_m32(PERST_MODE_MASK, PERST_MODE_GPIO, MT7621_GPIO_MODE);
+
+       mt7621_perst_gpio_pcie_assert(pcie);
+
        list_for_each_entry_safe(port, tmp, &pcie->ports, list) {
                u32 slot = port->slot;
 
@@ -441,10 +463,30 @@ static void mt7621_pcie_init_ports(struct mt7621_pcie *pcie)
                if (err) {
                        dev_err(dev, "Initiating port %d failed\n", slot);
                        list_del(&port->list);
+               } else {
+                       val = read_config(pcie, slot, PCIE_FTS_NUM);
+                       dev_info(dev, "Port %d N_FTS = %x\n", slot,
+                                (unsigned int)val);
                }
        }
 
        reset_control_assert(pcie->rst);
+
+       mt7621_perst_gpio_pcie_deassert(pcie);
+
+       list_for_each_entry(port, &pcie->ports, list) {
+               u32 slot = port->slot;
+
+               if (!mt7621_pcie_port_is_linkup(port)) {
+                       dev_err(dev, "pcie%d no card, disable it (RST & CLK)\n",
+                               slot);
+                       phy_power_off(port->phy);
+                       mt7621_control_assert(port);
+                       mt7621_pcie_port_clk_disable(port);
+                       port->enabled = false;
+               }
+       }
+
        rt_sysc_m32(0x30, 2 << 4, SYSC_REG_SYSTEM_CONFIG1);
        rt_sysc_m32(PCIE_CLK_GEN_EN, PCIE_CLK_GEN_DIS, RALINK_PCIE_CLK_GEN);
        rt_sysc_m32(PCIE_CLK_GEN1_DIS, PCIE_CLK_GEN1_EN, RALINK_PCIE_CLK_GEN1);
@@ -453,30 +495,12 @@ static void mt7621_pcie_init_ports(struct mt7621_pcie *pcie)
        reset_control_deassert(pcie->rst);
 }
 
-static int mt7621_pcie_enable_port(struct mt7621_pcie_port *port)
+static void mt7621_pcie_enable_port(struct mt7621_pcie_port *port)
 {
        struct mt7621_pcie *pcie = port->pcie;
        u32 slot = port->slot;
        u32 offset = MT7621_PCIE_OFFSET + (slot * MT7621_NEXT_PORT);
        u32 val;
-       int err;
-
-       /* assert port PERST_N */
-       val = pcie_read(pcie, RALINK_PCI_PCICFG_ADDR);
-       val |= PCIE_PORT_PERST(slot);
-       pcie_write(pcie, val, RALINK_PCI_PCICFG_ADDR);
-
-       /* de-assert port PERST_N */
-       val = pcie_read(pcie, RALINK_PCI_PCICFG_ADDR);
-       val &= ~PCIE_PORT_PERST(slot);
-       pcie_write(pcie, val, RALINK_PCI_PCICFG_ADDR);
-
-       /* 100ms timeout value should be enough for Gen1 training */
-       err = readl_poll_timeout(port->base + RALINK_PCI_STATUS,
-                                val, !!(val & PCIE_PORT_LINKUP),
-                                20, 100 * USEC_PER_MSEC);
-       if (err)
-               return -ETIMEDOUT;
 
        /* enable pcie interrupt */
        val = pcie_read(pcie, RALINK_PCI_PCIMSK_ADDR);
@@ -492,8 +516,6 @@ static int mt7621_pcie_enable_port(struct mt7621_pcie_port *port)
        /* configure class code and revision ID */
        pcie_write(pcie, PCIE_CLASS_CODE | PCIE_REVISION_ID,
                   offset + RALINK_PCI_CLASS);
-
-       return 0;
 }
 
 static void mt7621_pcie_enable_ports(struct mt7621_pcie *pcie)
@@ -506,12 +528,8 @@ static void mt7621_pcie_enable_ports(struct mt7621_pcie *pcie)
 
        list_for_each_entry(port, &pcie->ports, list) {
                if (port->enabled) {
-                       if (mt7621_pcie_enable_port(port)) {
-                               dev_err(dev, "de-assert port %d PERST_N\n",
-                                       port->slot);
-                               continue;
-                       }
-                       dev_info(dev, "PCIE%d enabled\n", slot);
+                       mt7621_pcie_enable_port(port);
+                       dev_info(dev, "PCIE%d enabled\n", num_slots_enabled);
                        num_slots_enabled++;
                }
        }
@@ -709,4 +727,4 @@ static int __init mt7621_pci_init(void)
        return platform_driver_register(&mt7621_pci_driver);
 }
 
-arch_initcall(mt7621_pci_init);
+module_init(mt7621_pci_init);
index 07a06c532dee244aa2836d39c719e9307390ee45..05079f7be841a8d30c848c752b33e8e30735d806 100644 (file)
@@ -385,7 +385,7 @@ static void *xlr_config_spill(struct xlr_net_priv *priv, int reg_start_0,
 
        base = priv->base_addr;
        spill_size = size;
-       spill = kmalloc(spill_size + SMP_CACHE_BYTES, GFP_ATOMIC);
+       spill = kmalloc(spill_size + SMP_CACHE_BYTES, GFP_KERNEL);
        if (!spill)
                return ZERO_SIZE_PTR;
 
index aeec16314e0d75ed3b0c765249dc768a5d6ccd31..cd2b777073c42bfbd7cd63df3013426e0d32750c 100644 (file)
@@ -521,8 +521,7 @@ static void octeon_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
  */
 static inline u32 cvmx_usb_read_csr32(struct octeon_hcd *usb, u64 address)
 {
-       u32 result = cvmx_read64_uint32(address ^ 4);
-       return result;
+       return cvmx_read64_uint32(address ^ 4);
 }
 
 /**
index c889f0bdf4244682e39e930eed8eadc1c603eef8..40c6f4e7632f951c363a6833030232b8cef20743 100644 (file)
@@ -871,7 +871,6 @@ abort:
 static long
 pi433_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
-       int                     retval = 0;
        struct pi433_instance   *instance;
        struct pi433_device     *device;
        struct pi433_tx_cfg     tx_cfg;
@@ -923,10 +922,10 @@ pi433_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
                mutex_unlock(&device->rx_lock);
                break;
        default:
-               retval = -EINVAL;
+               return -EINVAL;
        }
 
-       return retval;
+       return 0;
 }
 
 #ifdef CONFIG_COMPAT
index 4cd16257f0aab57c496b74832cbecbcf537db395..7d86bb8be24535a99763b6bd50de1d3c7d67d5eb 100644 (file)
@@ -722,10 +722,10 @@ int rf69_set_packet_format(struct spi_device *spi,
        switch (packet_format) {
        case packet_length_var:
                return rf69_set_bit(spi, REG_PACKETCONFIG1,
-                                   MASK_PACKETCONFIG1_PAKET_FORMAT_VARIABLE);
+                                   MASK_PACKETCONFIG1_PACKET_FORMAT_VARIABLE);
        case packet_length_fix:
                return rf69_clear_bit(spi, REG_PACKETCONFIG1,
-                                     MASK_PACKETCONFIG1_PAKET_FORMAT_VARIABLE);
+                                     MASK_PACKETCONFIG1_PACKET_FORMAT_VARIABLE);
        default:
                dev_dbg(&spi->dev, "set: illegal input param");
                return -EINVAL;
index f925a83c324701d3854a546d2083c29f683029d7..be5497cdace0b0c61782bd8718ab0c1fe17e6e32 100644 (file)
 #define  MASK_SYNC_CONFIG_SYNC_TOLERANCE       0x07
 
 /* RegPacketConfig1 */
-#define  MASK_PACKETCONFIG1_PAKET_FORMAT_VARIABLE      0x80
+#define  MASK_PACKETCONFIG1_PACKET_FORMAT_VARIABLE     0x80
 #define  MASK_PACKETCONFIG1_DCFREE                     0x60
 #define  MASK_PACKETCONFIG1_CRC_ON                     0x10 /* default */
 #define  MASK_PACKETCONFIG1_CRCAUTOCLEAR_OFF           0x08
index de3e357b26404d2bd2f678e707664e4df2fd3856..5854551d0a52c617b058adf70ce672e5dc2bec97 100644 (file)
@@ -814,9 +814,8 @@ static int gdma_dma_probe(struct platform_device *pdev)
        dma_dev = devm_kzalloc(&pdev->dev,
                               struct_size(dma_dev, chan, data->chancnt),
                               GFP_KERNEL);
-       if (!dma_dev) {
+       if (!dma_dev)
                return -EINVAL;
-       }
        dma_dev->data = data;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
index 4f7ef287a0f24362e7880967fc8782c1535aedd2..970d5abd6336389a15b646ddf13ffc594e4f2372 100644 (file)
@@ -8,7 +8,7 @@ config R8188EU
        select LIB80211
        select LIB80211_CRYPT_WEP
        select LIB80211_CRYPT_CCMP
-       ---help---
+       help
        This option adds the Realtek RTL8188EU USB device such as TP-Link TL-WN725N.
        If built as a module, it will be called r8188eu.
 
@@ -17,7 +17,7 @@ if R8188EU
 config 88EU_AP_MODE
        bool "Realtek RTL8188EU AP mode"
        default y
-       ---help---
+       help
        This option enables Access Point mode. Unless you know that your system
        will never be used as an AP, or the target system has limited memory,
        "Y" should be selected.
index 797ffa6e64d5a31893cf8d98f1f090d406c9a63e..28b3cdd10397f4cc03ac9b2d6c18a6e7e70c1b67 100644 (file)
@@ -482,7 +482,7 @@ int rtw_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher, int *pairwi
        return ret;
 }
 
-int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len)
+void rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len)
 {
        u8 authmode, sec_idx, i;
        u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
@@ -539,8 +539,6 @@ int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie,
                        }
                }
        }
-
-       return *rsn_len + *wpa_len;
 }
 
 u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen)
index 9a4aad5ec36555500023e3727e7878c8fa3deb84..d2f7a88e992e79c5b1f257e482d7ed060b86e6e6 100644 (file)
@@ -159,7 +159,8 @@ static void _rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *
        spin_unlock_bh(&free_queue->lock);
 }
 
-void _rtw_free_network_nolock(struct   mlme_priv *pmlmepriv, struct wlan_network *pnetwork)
+static void rtw_free_network_nolock(struct mlme_priv *pmlmepriv,
+                                   struct wlan_network *pnetwork)
 {
        struct __queue *free_queue = &pmlmepriv->free_bss_pool;
 
@@ -276,12 +277,6 @@ static struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv)
        return _rtw_alloc_network(pmlmepriv);
 }
 
-static void rtw_free_network_nolock(struct mlme_priv *pmlmepriv,
-                                   struct wlan_network *pnetwork)
-{
-       _rtw_free_network_nolock(pmlmepriv, pnetwork);
-}
-
 int rtw_is_same_ibss(struct adapter *adapter, struct wlan_network *pnetwork)
 {
        int ret = true;
@@ -1330,11 +1325,10 @@ void _rtw_join_timeout_handler (struct timer_list *t)
                                        continue;
                                }
                                break;
-                       } else {
-                               DBG_88E("%s We've try roaming but fail\n", __func__);
-                               rtw_indicate_disconnect(adapter);
-                               break;
                        }
+                       DBG_88E("%s We've try roaming but fail\n", __func__);
+                       rtw_indicate_disconnect(adapter);
+                       break;
                }
        } else {
                rtw_indicate_disconnect(adapter);
@@ -2058,17 +2052,16 @@ void _rtw_roaming(struct adapter *padapter, struct wlan_network *tgt_network)
                        do_join_r = rtw_do_join(padapter);
                        if (do_join_r == _SUCCESS) {
                                break;
-                       } else {
-                               DBG_88E("roaming do_join return %d\n", do_join_r);
-                               pmlmepriv->to_roaming--;
+                       }
+                       DBG_88E("roaming do_join return %d\n", do_join_r);
+                       pmlmepriv->to_roaming--;
 
-                               if (pmlmepriv->to_roaming > 0) {
-                                       continue;
-                               } else {
-                                       DBG_88E("%s(%d) -to roaming fail, indicate_disconnect\n", __func__, __LINE__);
-                                       rtw_indicate_disconnect(padapter);
-                                       break;
-                               }
+                       if (pmlmepriv->to_roaming > 0) {
+                               continue;
+                       } else {
+                               DBG_88E("%s(%d) -to roaming fail, indicate_disconnect\n", __func__, __LINE__);
+                               rtw_indicate_disconnect(padapter);
+                               break;
                        }
                }
        }
index 8f28aefbe6f97047e043cc32c3b1e97434b84af6..6f3c03201f649633e6d43487fac633bc5aae63c9 100644 (file)
@@ -5322,7 +5322,7 @@ u8 set_tx_beacon_cmd(struct adapter *padapter)
        struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
        struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
        struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
-       u8 res = _SUCCESS;
+       u8 res;
        int len_diff = 0;
 
        ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
index 087f6c9a58261c2a2363685a26026d392fce3577..9caf7041ad60e2e82c1a18b376126f9641b62e92 100644 (file)
@@ -450,7 +450,7 @@ static struct recv_frame *portctrl(struct adapter *adapter,
                memcpy(&be_tmp, ptr, 2);
                ether_type = ntohs(be_tmp);
 
-               if ((psta != NULL) && (psta->ieee8021x_blocked)) {
+               if (psta && (psta->ieee8021x_blocked)) {
                        /* blocked */
                        /* only accept EAPOL frame */
                        RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########%s:psta->ieee8021x_blocked==1\n", __func__));
@@ -700,7 +700,7 @@ static int sta2sta_data_frame(struct adapter *adapter,
        else
                *psta = rtw_get_stainfo(pstapriv, sta_addr); /*  get ap_info */
 
-       if (*psta == NULL) {
+       if (!*psta) {
                RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under %s ; drop pkt\n", __func__));
                ret = _FAIL;
                goto exit;
@@ -764,7 +764,7 @@ static int ap2sta_data_frame(
                else
                        *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /*  get ap_info */
 
-               if (*psta == NULL) {
+               if (!*psta) {
                        RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("ap2sta: can't get psta under STATION_MODE ; drop pkt\n"));
                        ret = _FAIL;
                        goto exit;
@@ -786,7 +786,7 @@ static int ap2sta_data_frame(
        } else {
                if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && !mcast) {
                        *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /*  get sta_info */
-                       if (*psta == NULL) {
+                       if (!*psta) {
                                DBG_88E("issue_deauth to the ap =%pM for the reason(7)\n", (pattrib->bssid));
 
                                issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
@@ -820,7 +820,7 @@ static int sta2ap_data_frame(struct adapter *adapter,
                }
 
                *psta = rtw_get_stainfo(pstapriv, pattrib->src);
-               if (*psta == NULL) {
+               if (!*psta) {
                        RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under AP_MODE; drop pkt\n"));
                        DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib->src));
 
@@ -883,7 +883,7 @@ static int validate_recv_ctrl_frame(struct adapter *padapter,
                aid = GetAid(pframe);
                psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
 
-               if ((psta == NULL) || (psta->aid != aid))
+               if ((!psta) || (psta->aid != aid))
                        return _FAIL;
 
                /* for rx pkt statistics */
@@ -1479,7 +1479,7 @@ struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
                }
        }
 
-       if ((prtnframe != NULL) && (prtnframe->attrib.privacy)) {
+       if (prtnframe && (prtnframe->attrib.privacy)) {
                /* after defrag we must check tkip mic code */
                if (recvframe_chkmic(padapter,  prtnframe) == _FAIL) {
                        RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic(padapter,  prtnframe)==_FAIL\n"));
index f404370d6631b104978796884fb8f71fa3fa8020..7bfc5b7c27574872cff6a4bb05d4826167bcf354 100644 (file)
@@ -27,9 +27,6 @@ static const u8 EPIGRAM_OUI[] = {0x00, 0x90, 0x4c};
 
 u8 REALTEK_96B_IE[] = {0x00, 0xe0, 0x4c, 0x02, 0x01, 0x20};
 
-#define R2T_PHY_DELAY  (0)
-
-/* define WAIT_FOR_BCN_TO_M    (3000) */
 #define WAIT_FOR_BCN_TO_MIN    (6000)
 #define WAIT_FOR_BCN_TO_MAX    (20000)
 
@@ -349,16 +346,6 @@ void set_channel_bwmode(struct adapter *padapter, unsigned char channel, unsigne
        SetBWMode(padapter, bwmode, channel_offset);
 }
 
-int get_bsstype(unsigned short capability)
-{
-       if (capability & BIT(0))
-               return WIFI_FW_AP_STATE;
-       else if (capability & BIT(1))
-               return WIFI_FW_ADHOC_STATE;
-       else
-               return 0;
-}
-
 u16 get_beacon_interval(struct wlan_bssid_ex *bss)
 {
        __le16 val;
@@ -1041,7 +1028,6 @@ void update_beacon_info(struct adapter *padapter, u8 *pframe, uint pkt_len, stru
 
                switch (pIE->ElementID) {
                case _HT_EXTRA_INFO_IE_:        /* HT info */
-                       /* HT_info_handler(padapter, pIE); */
                        bwmode_update_check(padapter, pIE);
                        break;
                case _ERPINFO_IE_:
@@ -1088,36 +1074,6 @@ unsigned int is_ap_in_tkip(struct adapter *padapter)
        }
 }
 
-unsigned int is_ap_in_wep(struct adapter *padapter)
-{
-       u32 i;
-       struct ndis_802_11_var_ie *pIE;
-       struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
-       struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
-       struct wlan_bssid_ex *cur_network = &pmlmeinfo->network;
-
-       if (rtw_get_capability((struct wlan_bssid_ex *)cur_network) & WLAN_CAPABILITY_PRIVACY) {
-               for (i = sizeof(struct ndis_802_11_fixed_ie); i < pmlmeinfo->network.ie_length;) {
-                       pIE = (struct ndis_802_11_var_ie *)(pmlmeinfo->network.ies + i);
-
-                       switch (pIE->ElementID) {
-                       case _VENDOR_SPECIFIC_IE_:
-                               if (!memcmp(pIE->data, RTW_WPA_OUI, 4))
-                                       return false;
-                               break;
-                       case _RSN_IE_2_:
-                               return false;
-                       default:
-                               break;
-                       }
-                       i += (pIE->Length + 2);
-               }
-               return true;
-       } else {
-               return false;
-       }
-}
-
 static int wifirate2_ratetbl_inx(unsigned char rate)
 {
        rate = rate & 0x7f;
@@ -1346,8 +1302,6 @@ void update_IOT_info(struct adapter *padapter)
                               false);
                break;
        case HT_IOT_PEER_REALTEK:
-               /* rtw_write16(padapter, 0x4cc, 0xffff); */
-               /* rtw_write16(padapter, 0x546, 0x01c0); */
                /* disable high power */
                Switch_DM_Func(padapter, (u32)(~DYNAMIC_BB_DYNAMIC_TXPWR),
                               false);
index ff481fbd074cb7b5873f08c044a320ac3e674caa..95f1b1431373f9c711b88de92f1d573f15bbd078 100644 (file)
@@ -283,9 +283,3 @@ bool hal_mapping_out_pipe(struct adapter *adapter, u8 numoutpipe)
        }
        return result;
 }
-
-void hal_init_macaddr(struct adapter *adapter)
-{
-       rtw_hal_set_hwreg(adapter, HW_VAR_MAC_ADDR,
-                         adapter->eeprompriv.mac_addr);
-}
index 74f7c9c81bf63ed686261f3f86be98bccdfb151c..4e2f6cb55a7529fcf8bcd1de5a64574a840c55c8 100644 (file)
@@ -942,11 +942,6 @@ void odm_RSSIMonitorCheckCE(struct odm_dm_struct *pDM_Odm)
 /* 3============================================================ */
 
 void odm_TXPowerTrackingInit(struct odm_dm_struct *pDM_Odm)
-{
-       odm_TXPowerTrackingThermalMeterInit(pDM_Odm);
-}
-
-void odm_TXPowerTrackingThermalMeterInit(struct odm_dm_struct *pDM_Odm)
 {
        pDM_Odm->RFCalibrateInfo.bTXPowerTracking = true;
        pDM_Odm->RFCalibrateInfo.TXPowercount = 0;
@@ -962,11 +957,6 @@ void ODM_TXPowerTrackingCheck(struct odm_dm_struct *pDM_Odm)
        /*  2011/09/29 MH In HW integration first stage, we provide 4 different handle to operate */
        /*  at the same time. In the stage2/3, we need to prive universal interface and merge all */
        /*  HW dynamic mechanism. */
-       odm_TXPowerTrackingCheckCE(pDM_Odm);
-}
-
-void odm_TXPowerTrackingCheckCE(struct odm_dm_struct *pDM_Odm)
-{
        struct adapter *Adapter = pDM_Odm->Adapter;
 
        if (!(pDM_Odm->SupportAbility & ODM_RF_TX_PWR_TRACK))
index 149b0009ad66cb0ed5bcb05865dee82a3311d91b..d5a9ac51e9071f0b5a4ea3ac11aee9c8609ebbfe 100644 (file)
@@ -387,10 +387,9 @@ static void odm_Process_RSSIForDM(struct odm_dm_struct *dm_odm,
 }
 
 /*  Endianness before calling this API */
-static void ODM_PhyStatusQuery_92CSeries(struct odm_dm_struct *dm_odm,
-                                        struct odm_phy_status_info *pPhyInfo,
-                                        u8 *pPhyStatus,
-                                        struct odm_per_pkt_info *pPktinfo)
+void ODM_PhyStatusQuery(struct odm_dm_struct *dm_odm,
+                       struct odm_phy_status_info *pPhyInfo,
+                       u8 *pPhyStatus, struct odm_per_pkt_info *pPktinfo)
 {
        odm_RxPhyStatus92CSeries_Parsing(dm_odm, pPhyInfo, pPhyStatus,
                                         pPktinfo);
@@ -398,12 +397,4 @@ static void ODM_PhyStatusQuery_92CSeries(struct odm_dm_struct *dm_odm,
                ;/*  Select the packets to do RSSI checking for antenna switching. */
        else
                odm_Process_RSSIForDM(dm_odm, pPhyInfo, pPktinfo);
-
-}
-
-void ODM_PhyStatusQuery(struct odm_dm_struct *dm_odm,
-                       struct odm_phy_status_info *pPhyInfo,
-                       u8 *pPhyStatus, struct odm_per_pkt_info *pPktinfo)
-{
-       ODM_PhyStatusQuery_92CSeries(dm_odm, pPhyInfo, pPhyStatus, pPktinfo);
 }
index 70c02c49b1770f20452f721ed22db48fb264c95f..ac555205075286ccfb326850805fe1d5f1876341 100644 (file)
@@ -469,10 +469,7 @@ static void usb_AggSettingTxUpdate(struct adapter *Adapter)
  *
  *---------------------------------------------------------------------------
  */
-static void
-usb_AggSettingRxUpdate(
-               struct adapter *Adapter
-       )
+static void usb_AggSettingRxUpdate(struct adapter *Adapter)
 {
        struct hal_data_8188e *haldata = Adapter->HalData;
        u8 valueDMA;
@@ -749,7 +746,8 @@ u32 rtl8188eu_hal_init(struct adapter *Adapter)
        _InitDriverInfoSize(Adapter, DRVINFO_SZ);
 
        _InitInterrupt(Adapter);
-       hal_init_macaddr(Adapter);/* set mac_address */
+       rtw_hal_set_hwreg(Adapter, HW_VAR_MAC_ADDR,
+                         Adapter->eeprompriv.mac_addr);
        _InitNetworkType(Adapter);/* set msr */
        _InitWMACSetting(Adapter);
        _InitAdaptiveCtrl(Adapter);
@@ -1044,10 +1042,7 @@ static void Hal_EfuseParseMACAddr_8188EU(struct adapter *adapt, u8 *hwinfo, bool
                 eeprom->mac_addr));
 }
 
-static void
-readAdapterInfo_8188EU(
-               struct adapter *adapt
-       )
+static void readAdapterInfo_8188EU(struct adapter *adapt)
 {
        struct eeprom_priv *eeprom = GET_EEPROM_EFUSE_PRIV(adapt);
 
@@ -1067,9 +1062,7 @@ readAdapterInfo_8188EU(
        Hal_ReadThermalMeter_88E(adapt, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
 }
 
-static void _ReadPROMContent(
-       struct adapter *Adapter
-       )
+static void _ReadPROMContent(struct adapter *Adapter)
 {
        struct eeprom_priv *eeprom = GET_EEPROM_EFUSE_PRIV(Adapter);
        u8 eeValue;
@@ -1782,11 +1775,8 @@ void rtw_hal_get_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
 /*     Description: */
 /*             Query setting of specified variable. */
 /*  */
-u8 rtw_hal_get_def_var(
-               struct adapter *Adapter,
-               enum hal_def_variable eVariable,
-               void *pValue
-       )
+u8 rtw_hal_get_def_var(struct adapter *Adapter, enum hal_def_variable eVariable,
+                      void *pValue)
 {
        struct hal_data_8188e *haldata = Adapter->HalData;
        u8 bResult = _SUCCESS;
index 2f7bdade40a5996b58066af59740a27f05b4580b..93cbbe7ba1fd645a447999d07a9accf93d8b5d58 100644 (file)
@@ -148,5 +148,4 @@ void hal_set_brate_cfg(u8 *brates, u16 *rate_cfg);
 
 bool hal_mapping_out_pipe(struct adapter *adapter, u8 numoutpipe);
 
-void hal_init_macaddr(struct adapter *adapter);
 #endif /* __HAL_COMMON_H__ */
index c60b833ca110a163f62043754be120bd94a227cf..d569fe5ed8e6b65d9e5c7f2ad7669a5ec7ada5b2 100644 (file)
 #include "wifi.h"
 #include <linux/wireless.h>
 
-#define MGMT_QUEUE_NUM 5
-
-#define ETH_ALEN       6
-#define ETH_TYPE_LEN           2
-#define PAYLOAD_TYPE_LEN       1
-
 #ifdef CONFIG_88EU_AP_MODE
 
 #define RTL_IOCTL_HOSTAPD (SIOCIWFIRSTPRIV + 28)
@@ -749,8 +743,8 @@ int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
 int rtw_parse_wpa2_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
                      int *pairwise_cipher, int *is_8021x);
 
-int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len,
-                  u8 *wpa_ie, u16 *wpa_len);
+void rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len,
+                   u8 *wpa_ie, u16 *wpa_len);
 
 u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen);
 u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen);
index df096c37f5ebfa25b0e6da0ed41e5cc2d06267d7..5254d875f96bcaab9a13e9ce766b190389238c47 100644 (file)
@@ -59,9 +59,7 @@ void odm_RefreshRateAdaptiveMaskCE(struct odm_dm_struct *pDM_Odm);
 void odm_RefreshRateAdaptiveMaskAPADSL(struct odm_dm_struct *pDM_Odm);
 void odm_DynamicTxPowerNIC(struct odm_dm_struct *pDM_Odm);
 void odm_RSSIMonitorCheckCE(struct odm_dm_struct *pDM_Odm);
-void odm_TXPowerTrackingThermalMeterInit(struct odm_dm_struct *pDM_Odm);
 void odm_EdcaTurboCheckCE(struct odm_dm_struct *pDM_Odm);
-void odm_TXPowerTrackingCheckCE(struct odm_dm_struct *pDM_Odm);
 void odm_SwAntDivChkAntSwitchCallback(void *FunctionContext);
 void odm_InitHybridAntDiv(struct odm_dm_struct *pDM_Odm);
 void odm_HwAntDiv(struct odm_dm_struct *pDM_Odm);
index db25eb580c98d11266193356752c01cd0b6cd87f..10525493129bb3126b4981eedbf5a7948faa4397 100644 (file)
@@ -111,10 +111,4 @@ struct eeprom_priv {
        u8              efuse_eeprom_data[HWSET_MAX_SIZE_512];
 };
 
-void eeprom_write16(struct adapter *padapter, u16 reg, u16 data);
-u16 eeprom_read16(struct adapter *padapter, u16 reg);
-void read_eeprom_content(struct adapter *padapter);
-void eeprom_read_sz(struct adapter *adapt, u16 reg, u8 *data, u32 sz);
-void read_eeprom_content_by_attrib(struct adapter *padapter);
-
 #endif  /* __RTL871X_EEPROM_H__ */
index bfef66525944ddc5b1ab06ca79821ce48e65d7ea..9abb7c32019210f35db722dc57f5c70507e6780b 100644 (file)
@@ -335,9 +335,6 @@ void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv);
 
 struct wlan_network *_rtw_alloc_network(struct mlme_priv *pmlmepriv);
 
-void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv,
-                             struct wlan_network *pnetwork);
-
 int rtw_if_up(struct adapter *padapter);
 
 u8 *rtw_get_capability_from_ie(u8 *ie);
index 1fb2349bd0a0ffebbf7c089a23d9d334f8498acf..327f7d1bc20ca5b1ebd9395c0c304d944cb59b6f 100644 (file)
@@ -485,7 +485,6 @@ void flush_all_cam_entry(struct adapter *padapter);
 void update_network(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src,
                    struct adapter *adapter, bool update_ie);
 
-int get_bsstype(unsigned short capability);
 u16 get_beacon_interval(struct wlan_bssid_ex *bss);
 
 int is_client_associated_to_ap(struct adapter *padapter);
@@ -526,7 +525,6 @@ void set_sta_rate(struct adapter *padapter, struct sta_info *psta);
 unsigned char get_highest_rate_idx(u32 mask);
 int support_short_GI(struct adapter *padapter, struct ieee80211_ht_cap *caps);
 unsigned int is_ap_in_tkip(struct adapter *padapter);
-unsigned int is_ap_in_wep(struct adapter *padapter);
 
 void report_join_res(struct adapter *padapter, int res);
 void report_survey_event(struct adapter *padapter,
index eaa4adb32a0de299ae5055d7b44929001cdcbdbb..ec5835d1aa8ce0be9bf3b22c45aa0b095993dd9f 100644 (file)
@@ -1686,7 +1686,7 @@ static int rtw_wx_get_enc(struct net_device *dev,
                            struct iw_request_info *info,
                            union iwreq_data *wrqu, char *keybuf)
 {
-       uint key, ret = 0;
+       uint key;
        struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
        struct iw_point *erq = &(wrqu->encoding);
        struct  mlme_priv       *pmlmepriv = &(padapter->mlmepriv);
@@ -1744,7 +1744,7 @@ static int rtw_wx_get_enc(struct net_device *dev,
                break;
        }
 
-       return ret;
+       return 0;
 }
 
 static int rtw_wx_get_power(struct net_device *dev,
@@ -2508,7 +2508,6 @@ static int rtw_add_sta(struct net_device *dev, struct ieee_param *param)
 
 static int rtw_del_sta(struct net_device *dev, struct ieee_param *param)
 {
-       int ret = 0;
        struct sta_info *psta = NULL;
        struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
        struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
@@ -2538,7 +2537,7 @@ static int rtw_del_sta(struct net_device *dev, struct ieee_param *param)
                DBG_88E("rtw_del_sta(), sta has already been removed or never been added\n");
        }
 
-       return ret;
+       return 0;
 }
 
 static int rtw_ioctl_get_sta_data(struct net_device *dev, struct ieee_param *param, int len)
@@ -2636,7 +2635,6 @@ static int rtw_get_sta_wpaie(struct net_device *dev, struct ieee_param *param)
 
 static int rtw_set_wps_beacon(struct net_device *dev, struct ieee_param *param, int len)
 {
-       int ret = 0;
        unsigned char wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
        struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
        struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
@@ -2668,12 +2666,11 @@ static int rtw_set_wps_beacon(struct net_device *dev, struct ieee_param *param,
                pmlmeext->bstart_bss = true;
        }
 
-       return ret;
+       return 0;
 }
 
 static int rtw_set_wps_probe_resp(struct net_device *dev, struct ieee_param *param, int len)
 {
-       int ret = 0;
        struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
        struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
        int ie_len;
@@ -2698,12 +2695,11 @@ static int rtw_set_wps_probe_resp(struct net_device *dev, struct ieee_param *par
                memcpy(pmlmepriv->wps_probe_resp_ie, param->u.bcn_ie.buf, ie_len);
        }
 
-       return ret;
+       return 0;
 }
 
 static int rtw_set_wps_assoc_resp(struct net_device *dev, struct ieee_param *param, int len)
 {
-       int ret = 0;
        struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
        struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
        int ie_len;
@@ -2729,12 +2725,11 @@ static int rtw_set_wps_assoc_resp(struct net_device *dev, struct ieee_param *par
                memcpy(pmlmepriv->wps_assoc_resp_ie, param->u.bcn_ie.buf, ie_len);
        }
 
-       return ret;
+       return 0;
 }
 
 static int rtw_set_hidden_ssid(struct net_device *dev, struct ieee_param *param, int len)
 {
-       int ret = 0;
        struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
        struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
        struct mlme_ext_priv    *pmlmeext = &(padapter->mlmeextpriv);
@@ -2754,7 +2749,7 @@ static int rtw_set_hidden_ssid(struct net_device *dev, struct ieee_param *param,
                value = 0;
        DBG_88E("%s value(%u)\n", __func__, value);
        pmlmeinfo->hidden_ssid_mode = value;
-       return ret;
+       return 0;
 }
 
 static int rtw_ioctl_acl_remove_sta(struct net_device *dev, struct ieee_param *param, int len)
@@ -2787,7 +2782,6 @@ static int rtw_ioctl_acl_add_sta(struct net_device *dev, struct ieee_param *para
 
 static int rtw_ioctl_set_macaddr_acl(struct net_device *dev, struct ieee_param *param, int len)
 {
-       int ret = 0;
        struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
        struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
 
@@ -2796,7 +2790,7 @@ static int rtw_ioctl_set_macaddr_acl(struct net_device *dev, struct ieee_param *
 
        rtw_set_macaddr_acl(padapter, param->u.mlme.command);
 
-       return ret;
+       return 0;
 }
 
 static int rtw_hostapd_ioctl(struct net_device *dev, struct iw_point *p)
index 9db11b16cb93a880acb1f604a94a160f54f3bc3f..e660bd4d91ef35994259a84edd1632eeb8ee1119 100644 (file)
@@ -93,11 +93,11 @@ void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie)
        union iwreq_data wrqu;
 
        RT_TRACE(_module_mlme_osdep_c_, _drv_info_,
-                ("+rtw_report_sec_ie, authmode=%d\n", authmode));
+                ("+%s, authmode=%d\n", __func__, authmode));
        buff = NULL;
        if (authmode == _WPA_IE_ID_) {
                RT_TRACE(_module_mlme_osdep_c_, _drv_info_,
-                        ("rtw_report_sec_ie, authmode=%d\n", authmode));
+                        ("%s, authmode=%d\n", __func__, authmode));
                buff = rtw_malloc(IW_CUSTOM_MAX);
                if (!buff)
                        return;
@@ -149,7 +149,7 @@ void rtw_indicate_sta_assoc_event(struct adapter *padapter, struct sta_info *pst
 
        memcpy(wrqu.addr.sa_data, psta->hwaddr, ETH_ALEN);
 
-       DBG_88E("+rtw_indicate_sta_assoc_event\n");
+       DBG_88E("+%s\n", __func__);
 
        wireless_send_event(padapter->pnetdev, IWEVREGISTERED, &wrqu, NULL);
 }
@@ -172,7 +172,7 @@ void rtw_indicate_sta_disassoc_event(struct adapter *padapter, struct sta_info *
 
        memcpy(wrqu.addr.sa_data, psta->hwaddr, ETH_ALEN);
 
-       DBG_88E("+rtw_indicate_sta_disassoc_event\n");
+       DBG_88E("+%s\n", __func__);
 
        wireless_send_event(padapter->pnetdev, IWEVEXPIRED, &wrqu, NULL);
 }
index 2c088af44c8ba8d98f146a848c81a59076d99461..8907bf6bb7ffec2b89e2e34a7cae676eab42634c 100644 (file)
@@ -19,6 +19,7 @@ MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Realtek Wireless Lan Driver");
 MODULE_AUTHOR("Realtek Semiconductor Corp.");
 MODULE_VERSION(DRIVERVERSION);
+MODULE_FIRMWARE("rtlwifi/rtl8188eufw.bin");
 
 #define RTW_NOTCH_FILTER 0 /* 0:Disable, 1:Enable, */
 
index 7a090615dcbce992d3679947830e673d9e479236..daf6db354982df4b15e11bb43a201e147544eeb7 100644 (file)
@@ -67,7 +67,7 @@ int rtw_android_cmdstr_to_num(char *cmdstr)
        int cmd_num;
 
        for (cmd_num = 0; cmd_num < ANDROID_WIFI_CMD_MAX; cmd_num++)
-               if (0 == strncasecmp(cmdstr, android_wifi_cmd_str[cmd_num],
+               if (!strncasecmp(cmdstr, android_wifi_cmd_str[cmd_num],
                                  strlen(android_wifi_cmd_str[cmd_num])))
                        break;
        return cmd_num;
index 5215a0b5fd454fbed47b79f35ddfdf4558194036..7d78f16efc1d2f677c563a976131e8303a0f3adb 100644 (file)
@@ -1427,7 +1427,7 @@ static bool _rtl92e_set_rf_power_state(struct net_device *dev,
                                 "_rtl92e_set_rf_power_state() eRfOn!\n");
                        if ((priv->rtllib->eRFPowerState == eRfOff) &&
                             RT_IN_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC)) {
-                               bool rtstatus = true;
+                               bool rtstatus;
                                u32 InitilizeCount = 3;
 
                                do {
index 55d857926bbaf51b3bce5daa26a18654f4adeee2..1b7e3fda7905f476bad29bd12cd5e9cb0ecf4651 100644 (file)
@@ -334,7 +334,7 @@ static void _rtl92e_dm_check_rate_adaptive(struct net_device *dev)
 
        if (!priv->up) {
                RT_TRACE(COMP_RATE,
-                        "<---- _rtl92e_dm_check_rate_adaptive(): driver is going to unload\n");
+                        "<---- %s: driver is going to unload\n", __func__);
                return;
        }
 
@@ -1178,7 +1178,7 @@ void rtl92e_dm_restore_state(struct net_device *dev)
 
        if (!priv->up) {
                RT_TRACE(COMP_RATE,
-                        "<---- rtl92e_dm_restore_state(): driver is going to unload\n");
+                        "<---- %s: driver is going to unload\n", __func__);
                return;
        }
 
index bb13b1de27974f787ab43c415dcfa20846c7c1d0..64d9feee1f392d33fb575336289570e565caa300 100644 (file)
@@ -83,7 +83,6 @@ struct net_device *alloc_rtllib(int sizeof_priv)
                return NULL;
        }
        ieee = (struct rtllib_device *)netdev_priv_rsl(dev);
-       memset(ieee, 0, sizeof(struct rtllib_device) + sizeof_priv);
        ieee->dev = dev;
 
        err = rtllib_networks_allocate(ieee);
index d7975aa335b24c406142a69a19186b6e83410b1d..4a6c3f6744317a770a1bdfe61478c651bd9cb50a 100644 (file)
@@ -109,7 +109,6 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
        }
 
        ieee = netdev_priv(dev);
-       memset(ieee, 0, sizeof(struct ieee80211_device) + sizeof_priv);
        ieee->dev = dev;
 
        err = ieee80211_networks_allocate(ieee);
@@ -155,7 +154,7 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
        ieee80211_softmac_init(ieee);
 
        ieee->pHTInfo = kzalloc(sizeof(RT_HIGH_THROUGHPUT), GFP_KERNEL);
-       if (ieee->pHTInfo == NULL) {
+       if (!ieee->pHTInfo) {
                IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc memory for HTInfo\n");
 
                /* By this point in code ieee80211_networks_allocate() has been
index 0e762e5596753c59fac9cb922ef32e652d12581f..0a3e478fccd6e30728b4482e0a9455f28b415daf 100644 (file)
@@ -67,7 +67,7 @@ ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq,
 
        for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
                entry = &ieee->frag_cache[tid][i];
-               if (entry->skb != NULL &&
+               if (entry->skb &&
                    time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
                        IEEE80211_DEBUG_FRAG(
                                "expiring fragment cache entry "
@@ -77,7 +77,7 @@ ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq,
                        entry->skb = NULL;
                }
 
-               if (entry->skb != NULL && entry->seq == seq &&
+               if (entry->skb && entry->seq == seq &&
                    (entry->last_frag + 1 == frag || frag == -1) &&
                    memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
                    memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
@@ -102,7 +102,7 @@ ieee80211_frag_cache_get(struct ieee80211_device *ieee,
        struct rtl_80211_hdr_4addrqos *hdr_4addrqos;
        u8 tid;
 
-       if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
+       if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) {
          hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)hdr;
          tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
          tid = UP2AC(tid);
@@ -133,7 +133,7 @@ ieee80211_frag_cache_get(struct ieee80211_device *ieee,
                if (ieee->frag_next_idx[tid] >= IEEE80211_FRAG_CACHE_LEN)
                        ieee->frag_next_idx[tid] = 0;
 
-               if (entry->skb != NULL)
+               if (entry->skb)
                        dev_kfree_skb_any(entry->skb);
 
                entry->first_frag_time = jiffies;
@@ -169,7 +169,7 @@ static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
        struct rtl_80211_hdr_4addrqos *hdr_4addrqos;
        u8 tid;
 
-       if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
+       if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) {
          hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)hdr;
          tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
          tid = UP2AC(tid);
@@ -426,7 +426,7 @@ static int is_duplicate_packet(struct ieee80211_device *ieee,
 
 
        //TO2DS and QoS
-       if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS)&&IEEE80211_QOS_HAS_SEQ(fc)) {
+       if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) {
          hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)header;
          tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
          tid = UP2AC(tid);
@@ -557,7 +557,7 @@ void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_
                        //stats->rx_packets++;
                        //stats->rx_bytes += sub_skb->len;
 
-               /* Indicat the packets to upper layer */
+               /* Indicate the packets to upper layer */
                        if (sub_skb) {
                                sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
                                memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
@@ -773,7 +773,7 @@ static u8 parse_subframe(struct sk_buff *skb,
        /* just for debug purpose */
        SeqNum = WLAN_GET_SEQ_SEQ(le16_to_cpu(hdr->seq_ctl));
 
-       if ((IEEE80211_QOS_HAS_SEQ(fc))&&\
+       if ((IEEE80211_QOS_HAS_SEQ(fc)) && \
                        (((frameqos *)(skb->data + IEEE80211_3ADDR_LEN))->field.reserved)) {
                bIsAggregateFrame = true;
        }
@@ -1092,7 +1092,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
             ieee->iw_mode == IW_MODE_REPEAT) &&
            !from_assoc_ap) {
                switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
-                                            wds != NULL)) {
+                                            wds)) {
                case AP_RX_CONTINUE_NOT_AUTHORIZED:
                case AP_RX_CONTINUE:
                        break;
@@ -1109,7 +1109,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
        if (stype != IEEE80211_STYPE_DATA &&
            stype != IEEE80211_STYPE_DATA_CFACK &&
            stype != IEEE80211_STYPE_DATA_CFPOLL &&
-           stype != IEEE80211_STYPE_DATA_CFACKPOLL&&
+           stype != IEEE80211_STYPE_DATA_CFACKPOLL &&
            stype != IEEE80211_STYPE_QOS_DATA//add by David,2006.8.4
            ) {
                if (stype != IEEE80211_STYPE_NULLFUNC)
@@ -1311,7 +1311,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
                                        stats->multicast++;
                                }
 
-                               /* Indicat the packets to upper layer */
+                               /* Indicate the packets to upper layer */
                                sub_skb->protocol = eth_type_trans(sub_skb, dev);
                                memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
                                sub_skb->dev = dev;
@@ -1388,7 +1388,7 @@ static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
        int ret = 0;
        u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
 
-       if ((info_element == NULL) || (element_param == NULL))
+       if (!info_element || !element_param)
                return -1;
 
        if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
@@ -2508,7 +2508,7 @@ static inline void ieee80211_process_probe_response(
        list_for_each_entry(target, &ieee->network_list, list) {
                if (is_same_network(target, network, ieee))
                        break;
-               if ((oldest == NULL) ||
+               if (!oldest ||
                    (target->last_scanned < oldest->last_scanned))
                        oldest = target;
        }
@@ -2565,7 +2565,7 @@ static inline void ieee80211_process_probe_response(
                //      printk("====>2 network->ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network->ssid, network->flags, target->ssid, target->flags);
                if(((network->flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \
                    && (((network->ssid_len > 0) && (strncmp(target->ssid, network->ssid, network->ssid_len)))\
-                   ||((ieee->current_network.ssid_len == network->ssid_len)&&(strncmp(ieee->current_network.ssid, network->ssid, network->ssid_len) == 0)&&(ieee->state == IEEE80211_NOLINK))))
+                   ||((ieee->current_network.ssid_len == network->ssid_len) && (strncmp(ieee->current_network.ssid, network->ssid, network->ssid_len) == 0) && (ieee->state == IEEE80211_NOLINK))))
                        renew = 1;
                //YJ,add,080819,for hidden ap,end
 
@@ -2575,11 +2575,10 @@ static inline void ieee80211_process_probe_response(
        }
 
        spin_unlock_irqrestore(&ieee->lock, flags);
-       if (is_beacon(beacon->header.frame_ctl)&&is_same_network(&ieee->current_network, network, ieee)&&\
+       if (is_beacon(beacon->header.frame_ctl) && is_same_network(&ieee->current_network, network, ieee) && \
                (ieee->state == IEEE80211_LINKED)) {
-               if (ieee->handle_beacon != NULL) {
+               if (ieee->handle_beacon)
                        ieee->handle_beacon(ieee->dev,beacon,&ieee->current_network);
-               }
        }
 
 out:
index 944c8894f9ffb7734fcb315251054e7fe6ab7107..e0da0900a4f74fda48340755db75affeb21d3150 100644 (file)
@@ -1796,7 +1796,7 @@ static void ieee80211_process_action(struct ieee80211_device *ieee,
        u8 *act = ieee80211_get_payload(header);
        u8 tmp = 0;
 //     IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len);
-       if (act == NULL) {
+       if (!act) {
                IEEE80211_DEBUG(IEEE80211_DL_ERR, "error to get payload of action frame\n");
                return;
        }
@@ -1929,7 +1929,7 @@ ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb,
                                                memcpy(ieee->pHTInfo->PeerHTCapBuf, network->bssht.bdHTCapBuf, network->bssht.bdHTCapLen);
                                                memcpy(ieee->pHTInfo->PeerHTInfoBuf, network->bssht.bdHTInfoBuf, network->bssht.bdHTInfoLen);
                                        }
-                                       if (ieee->handle_assoc_response != NULL)
+                                       if (ieee->handle_assoc_response)
                                                ieee->handle_assoc_response(ieee->dev, (struct ieee80211_assoc_response_frame *)header, network);
                                }
                                ieee80211_associate_complete(ieee);
@@ -2659,14 +2659,13 @@ static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee,
 {
        u8 *buf;
 
-       if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
-           (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
+       if (param->u.wpa_ie.len > MAX_WPA_IE_LEN)
                return -EINVAL;
 
        if (param->u.wpa_ie.len) {
                buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len,
                              GFP_KERNEL);
-               if (buf == NULL)
+               if (!buf)
                        return -ENOMEM;
 
                kfree(ieee->wpa_ie);
@@ -2856,7 +2855,7 @@ static int ieee80211_wpa_set_encryption(struct ieee80211_device *ieee,
                goto done;
        }
 
-       if (*crypt == NULL || (*crypt)->ops != ops) {
+       if (!*crypt || (*crypt)->ops != ops) {
                struct ieee80211_crypt_data *new_crypt;
 
                ieee80211_crypt_delayed_deinit(ieee, crypt);
@@ -2871,7 +2870,7 @@ static int ieee80211_wpa_set_encryption(struct ieee80211_device *ieee,
                        new_crypt->priv =
                                new_crypt->ops->init(param->u.crypt.idx);
 
-               if (new_crypt->priv == NULL) {
+               if (!new_crypt->priv) {
                        kfree(new_crypt);
                        param->u.crypt.err = IEEE_CRYPT_ERR_CRYPT_INIT_FAILED;
                        ret = -EINVAL;
index aab1586fe0dddfd08f32662838271614d0b859e5..4a8d16a45fc5d28788171f8ea2f30fc098c98980 100644 (file)
@@ -244,9 +244,9 @@ int ieee80211_wx_set_rts(struct ieee80211_device *ieee,
                             struct iw_request_info *info,
                             union iwreq_data *wrqu, char *extra)
 {
-       if (wrqu->rts.disabled || !wrqu->rts.fixed)
+       if (wrqu->rts.disabled || !wrqu->rts.fixed) {
                ieee->rts = DEFAULT_RTS_THRESHOLD;
-       else {
+       else {
                if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
                                wrqu->rts.value > MAX_RTS_THRESHOLD)
                        return -EINVAL;
index 8e1ec4409b4f92ecce1b5e7d5ea9ed963c4e40b3..fc6eb97801e1c0c63091d7666c54ec03b7c372cf 100644 (file)
@@ -169,8 +169,7 @@ int ieee80211_encrypt_fragment(
        struct ieee80211_crypt_data *crypt = ieee->crypt[ieee->tx_keyidx];
        int res;
 
-       if (!(crypt && crypt->ops))
-       {
+       if (!(crypt && crypt->ops)) {
                printk("=========>%s(), crypt is null\n", __func__);
                return -1;
        }
@@ -309,32 +308,25 @@ static void ieee80211_tx_query_agg_cap(struct ieee80211_device *ieee,
        if (!Adapter->HalFunc.GetNmodeSupportBySecCfgHandler(Adapter))
                return;
 #endif
-       if (!ieee->GetNmodeSupportBySecCfg(ieee->dev))
-       {
+       if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) {
                return;
        }
-       if (pHTInfo->bCurrentAMPDUEnable)
-       {
-               if (!GetTs(ieee, (struct ts_common_info **)(&pTxTs), hdr->addr1, skb->priority, TX_DIR, true))
-               {
+       if (pHTInfo->bCurrentAMPDUEnable) {
+               if (!GetTs(ieee, (struct ts_common_info **)(&pTxTs), hdr->addr1, skb->priority, TX_DIR, true)) {
                        printk("===>can't get TS\n");
                        return;
                }
-               if (!pTxTs->tx_admitted_ba_record.valid)
-               {
+               if (!pTxTs->tx_admitted_ba_record.valid) {
                        TsStartAddBaProcess(ieee, pTxTs);
                        goto FORCED_AGG_SETTING;
-               }
-               else if (!pTxTs->using_ba)
-               {
+               } else if (!pTxTs->using_ba) {
                        if (SN_LESS(pTxTs->tx_admitted_ba_record.start_seq_ctrl.field.seq_num, (pTxTs->tx_cur_seq + 1) % 4096))
                                pTxTs->using_ba = true;
                        else
                                goto FORCED_AGG_SETTING;
                }
 
-               if (ieee->iw_mode == IW_MODE_INFRA)
-               {
+               if (ieee->iw_mode == IW_MODE_INFRA) {
                        tcb_desc->bAMPDUEnable = true;
                        tcb_desc->ampdu_factor = pHTInfo->CurrentAMPDUFactor;
                        tcb_desc->ampdu_density = pHTInfo->CurrentMPDUDensity;
@@ -366,12 +358,9 @@ static void ieee80211_qurey_ShortPreambleMode(struct ieee80211_device *ieee,
                                              struct cb_desc *tcb_desc)
 {
        tcb_desc->bUseShortPreamble = false;
-       if (tcb_desc->data_rate == 2)
-       {//// 1M can only use Long Preamble. 11B spec
+       if (tcb_desc->data_rate == 2) {//// 1M can only use Long Preamble. 11B spec
                return;
-       }
-       else if (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
-       {
+       } else if (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_PREAMBLE) {
                tcb_desc->bUseShortPreamble = true;
        }
        return;
@@ -386,8 +375,7 @@ ieee80211_query_HTCapShortGI(struct ieee80211_device *ieee, struct cb_desc *tcb_
        if (!pHTInfo->bCurrentHTSupport||!pHTInfo->bEnableHT)
                return;
 
-       if (pHTInfo->bForcedShortGI)
-       {
+       if (pHTInfo->bForcedShortGI) {
                tcb_desc->bUseShortGI = true;
                return;
        }
@@ -535,27 +523,25 @@ static void ieee80211_txrate_selectmode(struct ieee80211_device *ieee,
                                        struct cb_desc *tcb_desc)
 {
 #ifdef TO_DO_LIST
-       if(!IsDataFrame(pFrame))
-       {
+       if (!IsDataFrame(pFrame)) {
                pTcb->bTxDisableRateFallBack = true;
                pTcb->bTxUseDriverAssingedRate = true;
                pTcb->RATRIndex = 7;
                return;
        }
 
-       if(pMgntInfo->ForcedDataRate!= 0)
-       {
+       if (pMgntInfo->ForcedDataRate!= 0) {
                pTcb->bTxDisableRateFallBack = true;
                pTcb->bTxUseDriverAssingedRate = true;
                return;
        }
 #endif
-       if(ieee->bTxDisableRateFallBack)
+       if (ieee->bTxDisableRateFallBack)
                tcb_desc->bTxDisableRateFallBack = true;
 
-       if(ieee->bTxUseDriverAssingedRate)
+       if (ieee->bTxUseDriverAssingedRate)
                tcb_desc->bTxUseDriverAssingedRate = true;
-       if(!tcb_desc->bTxDisableRateFallBack || !tcb_desc->bTxUseDriverAssingedRate)
+       if (!tcb_desc->bTxDisableRateFallBack || !tcb_desc->bTxUseDriverAssingedRate)
        {
                if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC)
                        tcb_desc->RATRIndex = 0;
@@ -614,7 +600,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
        }
 
 
-       if(likely(ieee->raw_tx == 0)){
+       if (likely(ieee->raw_tx == 0)) {
                if (unlikely(skb->len < SNAP_SIZE + sizeof(u16))) {
                        printk(KERN_WARNING "%s: skb too small (%d).\n",
                        ieee->dev->name, skb->len);
@@ -690,15 +676,13 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
                if (is_multicast_ether_addr(header.addr1)) {
                        frag_size = MAX_FRAG_THRESHOLD;
                        qos_ctl |= QOS_CTL_NOTCONTAIN_ACK;
-               }
-               else {
+               } else {
                        frag_size = ieee->fts;//default:392
                        qos_ctl = 0;
                }
 
                //if (ieee->current_network.QoS_Enable)
-               if(qos_actived)
-               {
+               if (qos_actived) {
                        hdr_len = IEEE80211_3ADDR_LEN + 2;
 
                        skb->priority = ieee80211_classify(skb, &ieee->current_network);
@@ -746,12 +730,10 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
                txb->payload_size = __cpu_to_le16(bytes);
 
                //if (ieee->current_network.QoS_Enable)
-               if(qos_actived)
-               {
+               if (qos_actived)
                        txb->queue_index = UP2AC(skb->priority);
-               } else {
+               else
                        txb->queue_index = WME_AC_BK;
-               }
 
 
 
index dead134f6de075c8fb80a392a35365cd30e2851a..be08cd1d37a79d2b608f3ea1cef2b584c37dc092 100644 (file)
@@ -243,8 +243,7 @@ int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
 
        list_for_each_entry(network, &ieee->network_list, list) {
                i++;
-               if((stop-ev)<200)
-               {
+               if((stop-ev)<200) {
                        err = -E2BIG;
                        break;
                }
@@ -312,7 +311,7 @@ int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
                /* Check all the keys to see if any are still configured,
                 * and if no key index was provided, de-init them all */
                for (i = 0; i < WEP_KEYS; i++) {
-                       if (ieee->crypt[i] != NULL) {
+                       if (ieee->crypt[i]) {
                                if (key_provided)
                                        break;
                                ieee80211_crypt_delayed_deinit(
@@ -334,14 +333,14 @@ int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
        sec.enabled = 1;
        sec.flags |= SEC_ENABLED;
 
-       if (*crypt != NULL && (*crypt)->ops != NULL &&
+       if (*crypt && (*crypt)->ops &&
            strcmp((*crypt)->ops->name, "WEP") != 0) {
                /* changing to use WEP; deinit previously used algorithm
                 * on this key */
                ieee80211_crypt_delayed_deinit(ieee, crypt);
        }
 
-       if (*crypt == NULL) {
+       if (!*crypt) {
                struct ieee80211_crypt_data *new_crypt;
 
                /* take WEP into use */
@@ -469,7 +468,7 @@ int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
        crypt = ieee->crypt[key];
        erq->flags = key + 1;
 
-       if (crypt == NULL || crypt->ops == NULL) {
+       if (!crypt || !crypt->ops) {
                erq->length = 0;
                erq->flags |= IW_ENCODE_DISABLED;
                return 0;
@@ -538,7 +537,7 @@ int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
 
                for (i = 0; i < WEP_KEYS; i++)
 
-                       if (ieee->crypt[i] != NULL)
+                       if (ieee->crypt[i])
 
                                break;
 
@@ -583,7 +582,7 @@ int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
                goto done;
        }
 
-       if (*crypt == NULL || (*crypt)->ops != ops) {
+       if (!*crypt || (*crypt)->ops != ops) {
                struct ieee80211_crypt_data *new_crypt;
 
                ieee80211_crypt_delayed_deinit(ieee, crypt);
@@ -596,7 +595,7 @@ int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
                new_crypt->ops = ops;
                if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
                        new_crypt->priv = new_crypt->ops->init(idx);
-               if (new_crypt->priv == NULL) {
+               if (!new_crypt->priv) {
                        kfree(new_crypt);
                        ret = -EINVAL;
                        goto done;
@@ -684,7 +683,7 @@ int ieee80211_wx_get_encode_ext(struct ieee80211_device *ieee,
        encoding->flags = idx + 1;
        memset(ext, 0, sizeof(*ext));
 
-       if (crypt == NULL || crypt->ops == NULL ) {
+       if (!crypt || !crypt->ops) {
                ext->alg = IW_ENCODE_ALG_NONE;
                ext->key_len = 0;
                encoding->flags |= IW_ENCODE_DISABLED;
@@ -761,8 +760,7 @@ int ieee80211_wx_set_auth(struct ieee80211_device *ieee,
                } else if (data->value & IW_AUTH_ALG_LEAP) {
                        ieee->open_wep = 1;
                        ieee->auth_mode = 2;
-               }
-               else
+               } else
                        return -EINVAL;
                break;
 
@@ -787,28 +785,24 @@ int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len)
 {
        u8 *buf;
 
-       if (len>MAX_WPA_IE_LEN || (len && ie == NULL))
-       {
+       if (len>MAX_WPA_IE_LEN || (len && !ie)) {
        //      printk("return error out, len:%d\n", len);
        return -EINVAL;
        }
 
 
-       if (len)
-       {
-               if (len != ie[1]+2)
-               {
+       if (len) {
+               if (len != ie[1]+2) {
                        printk("len:%zu, ie:%d\n", len, ie[1]);
                        return -EINVAL;
                }
                buf = kmemdup(ie, len, GFP_KERNEL);
-               if (buf == NULL)
+               if (!buf)
                        return -ENOMEM;
                kfree(ieee->wpa_ie);
                ieee->wpa_ie = buf;
                ieee->wpa_ie_len = len;
-       }
-       else{
+       } else {
                kfree(ieee->wpa_ie);
                ieee->wpa_ie = NULL;
                ieee->wpa_ie_len = 0;
index 7cac668bfb0bca24b3c5a9e6489c21b82a893df5..59d179ae7ad2ae058f0f1e1fafe804598b4c4bed 100644 (file)
@@ -51,7 +51,7 @@ static void RxPktPendingTimeout(struct timer_list *t)
                                if (SN_EQUAL(pReorderEntry->SeqNum, pRxTs->rx_indicate_seq))
                                        pRxTs->rx_indicate_seq = (pRxTs->rx_indicate_seq + 1) % 4096;
 
-                               IEEE80211_DEBUG(IEEE80211_DL_REORDER, "RxPktPendingTimeout(): IndicateSeq: %d\n", pReorderEntry->SeqNum);
+                               IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s: IndicateSeq: %d\n", __func__, pReorderEntry->SeqNum);
                                ieee->stats_IndicateArray[index] = pReorderEntry->prxb;
                                index++;
 
@@ -97,7 +97,7 @@ static void TsAddBaProcess(struct timer_list *t)
        struct ieee80211_device *ieee = container_of(pTxTs, struct ieee80211_device, TxTsRecord[num]);
 
        TsInitAddBA(ieee, pTxTs, BA_POLICY_IMMEDIATE, false);
-       IEEE80211_DEBUG(IEEE80211_DL_BA, "TsAddBaProcess(): ADDBA Req is started!! \n");
+       IEEE80211_DEBUG(IEEE80211_DL_BA, "%s: ADDBA Req is started!! \n", __func__);
 }
 
 
@@ -456,7 +456,7 @@ void RemovePeerTS(struct ieee80211_device *ieee, u8 *Addr)
 {
        struct ts_common_info   *pTS, *pTmpTS;
 
-       printk("===========>RemovePeerTS,%pM\n", Addr);
+       printk("===========>%s,%pM\n", __func__, Addr);
        list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, list) {
                if (memcmp(pTS->addr, Addr, 6) == 0) {
                        RemoveTsEntry(ieee, pTS, TX_DIR);
@@ -525,11 +525,11 @@ void TsStartAddBaProcess(struct ieee80211_device *ieee, struct tx_ts_record *pTx
        if (!pTxTS->add_ba_req_in_progress) {
                pTxTS->add_ba_req_in_progress = true;
                if (pTxTS->add_ba_req_delayed)  {
-                       IEEE80211_DEBUG(IEEE80211_DL_BA, "TsStartAddBaProcess(): Delayed Start ADDBA after 60 sec!!\n");
+                       IEEE80211_DEBUG(IEEE80211_DL_BA, "%s: Delayed Start ADDBA after 60 sec!!\n", __func__);
                        mod_timer(&pTxTS->ts_add_ba_timer,
                                  jiffies + msecs_to_jiffies(TS_ADDBA_DELAY));
                } else {
-                       IEEE80211_DEBUG(IEEE80211_DL_BA, "TsStartAddBaProcess(): Immediately Start ADDBA now!!\n");
+                       IEEE80211_DEBUG(IEEE80211_DL_BA, "%s: Immediately Start ADDBA now!!\n", __func__);
                        mod_timer(&pTxTS->ts_add_ba_timer, jiffies+10); //set 10 ticks
                }
        } else {
index 4065a4710142f63bb149d6162ea11dd60397789e..fe1f279ca368b7370b2fc9f659113e78b9ad9037 100644 (file)
@@ -713,7 +713,7 @@ static u32 get_rxpacket_shiftbytes_819xusb(struct ieee80211_rx_stats *pstats)
                + pstats->RxBufShift);
 }
 
-static int rtl8192_rx_initiate(struct net_device *dev)
+void rtl8192_rx_enable(struct net_device *dev)
 {
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct urb *entry;
@@ -763,8 +763,6 @@ static int rtl8192_rx_initiate(struct net_device *dev)
                skb_queue_tail(&priv->rx_queue, skb);
                usb_submit_urb(entry, GFP_KERNEL);
        }
-
-       return 0;
 }
 
 void rtl8192_set_rxconf(struct net_device *dev)
@@ -810,12 +808,6 @@ void rtl8192_set_rxconf(struct net_device *dev)
        write_nic_dword(dev, RCR, rxconf);
 }
 
-/* wait to be removed */
-void rtl8192_rx_enable(struct net_device *dev)
-{
-       rtl8192_rx_initiate(dev);
-}
-
 void rtl8192_rtx_disable(struct net_device *dev)
 {
        u8 cmd;
index 2ba01041406bd33210a45d8c0654e149cd052ea7..ade14ef0573097e5a3041f11f1c63893ebd3c1ce 100644 (file)
@@ -99,8 +99,7 @@ static        void    dm_dynamic_txpower(struct net_device *dev);
 static void dm_send_rssi_tofw(struct net_device *dev);
 static void    dm_ctstoself(struct net_device *dev);
 /*---------------------------Define function prototype------------------------*/
-/*
- * ================================================================================
+/* ================================================================================
  *     HW Dynamic mechanism interface.
  * ================================================================================
  *
@@ -178,8 +177,7 @@ void dm_CheckRxAggregation(struct net_device *dev)
 
                        ulValue = (pHTInfo->UsbRxFwAggrEn<<24) | (pHTInfo->UsbRxFwAggrPageNum<<16) |
                                (pHTInfo->UsbRxFwAggrPacketNum<<8) | (pHTInfo->UsbRxFwAggrTimeout);
-                       /*
-                        * If usb rx firmware aggregation is enabled,
+                       /* If usb rx firmware aggregation is enabled,
                         * when anyone of three threshold conditions above is reached,
                         * firmware will send aggregated packet to driver.
                         */
@@ -219,8 +217,7 @@ void hal_dm_watchdog(struct net_device *dev)
 #endif
 }      /* HalDmWatchDog */
 
-/*
- * Decide Rate Adaptive Set according to distance (signal strength)
+/* Decide Rate Adaptive Set according to distance (signal strength)
  *     01/11/2008      MHC             Modify input arguments and RATR table level.
  *     01/16/2008      MHC             RF_Type is assigned in ReadAdapterInfo(). We must call
  *                                             the function after making sure RF_Type.
@@ -246,8 +243,7 @@ void init_rate_adaptive(struct net_device *dev)
        pra->ping_rssi_thresh_for_ra = 15;
 
        if (priv->rf_type == RF_2T4R) {
-               /*
-                * 07/10/08 MH Modify for RA smooth scheme.
+               /* 07/10/08 MH Modify for RA smooth scheme.
                 * 2008/01/11 MH Modify 2T RATR table for different RSSI. 080515 porting by amy from windows code.
                 */
                pra->upper_rssi_threshold_ratr          =       0x8f0f0000;
@@ -336,9 +332,10 @@ static void dm_check_rate_adaptive(struct net_device *dev)
                                ((bshort_gi_enabled) ? BIT(31) : 0);
 
                /* 2007/10/08 MH We support RA smooth scheme now. When it is the first
-                  time to link with AP. We will not change upper/lower threshold. If
-                  STA stay in high or low level, we must change two different threshold
-                  to prevent jumping frequently. */
+                * time to link with AP. We will not change upper/lower threshold. If
+                * STA stay in high or low level, we must change two different threshold
+                * to prevent jumping frequently.
+                */
                if (pra->ratr_state == DM_RATR_STA_HIGH) {
                        HighRSSIThreshForRA     = pra->high2low_rssi_thresh_for_ra;
                        LowRSSIThreshForRA      = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) ?
@@ -387,8 +384,7 @@ static void dm_check_rate_adaptive(struct net_device *dev)
                        }
                }
 
-               /*
-                * 2008.04.01
+               /* 2008.04.01
                 * For RTL819X, if pairwisekey = wep/tkip, we support only MCS0~7.
                 */
                if (priv->ieee80211->GetHalfNmodeSupportByAPsHandler(dev))
@@ -683,8 +679,7 @@ static void dm_TXPowerTrackingCallback_ThermalMeter(struct net_device *dev)
                return;
        }
 
-       /*
-        * ==========================
+       /* ==========================
         * this is only for test, should be masked
         * ==========================
         */
@@ -850,8 +845,7 @@ static void dm_InitializeTXPowerTracking_TSSI(struct net_device *dev)
        priv->txbbgain_table[36].txbb_iq_amplifygain =               -24;
        priv->txbbgain_table[36].txbbgain_value = 0x10000040;
 
-       /*
-        * ccktxbb_valuearray[0] is 0xA22 [1] is 0xA24 ...[7] is 0xA29
+       /* ccktxbb_valuearray[0] is 0xA22 [1] is 0xA24 ...[7] is 0xA29
         * This Table is for CH1~CH13
         */
        priv->cck_txbbgain_table[0].ccktxbb_valuearray[0] = 0x36;
@@ -1061,8 +1055,7 @@ static void dm_InitializeTXPowerTracking_TSSI(struct net_device *dev)
        priv->cck_txbbgain_table[22].ccktxbb_valuearray[6] = 0x03;
        priv->cck_txbbgain_table[22].ccktxbb_valuearray[7] = 0x01;
 
-       /*
-        * ccktxbb_valuearray[0] is 0xA22 [1] is 0xA24 ...[7] is 0xA29
+       /* ccktxbb_valuearray[0] is 0xA22 [1] is 0xA24 ...[7] is 0xA29
         * This Table is for CH14
         */
        priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[0] = 0x36;
@@ -1282,8 +1275,7 @@ static void dm_InitializeTXPowerTracking_ThermalMeter(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
 
-       /*
-        * Tx Power tracking by Thermal Meter requires Firmware R/W 3-wire. This mechanism
+       /* Tx Power tracking by Thermal Meter requires Firmware R/W 3-wire. This mechanism
         * can be enabled only when Firmware R/W 3-wire is enabled. Otherwise, frequent r/w
         * 3-wire by driver causes RF to go into a wrong state.
         */
@@ -1330,8 +1322,7 @@ static void dm_CheckTXPowerTracking_ThermalMeter(struct net_device *dev)
        }
 
        if (!TM_Trigger) {
-               /*
-                * Attention!! You have to write all 12bits of data to RF, or it may cause RF to crash
+               /* Attention!! You have to write all 12bits of data to RF, or it may cause RF to crash
                 * actually write reg0x02 bit1=0, then bit1=1.
                 * DbgPrint("Trigger ThermalMeter, write RF reg0x2 = 0x4d to 0x4f\n");
                 */
@@ -1563,18 +1554,6 @@ static void dm_bb_initialgain_restore(struct net_device *dev)
 
 }      /* dm_BBInitialGainRestore */
 
-void dm_backup_dynamic_mechanism_state(struct net_device *dev)
-{
-       struct r8192_priv *priv = ieee80211_priv(dev);
-
-       /* Fsync to avoid reset */
-       priv->bswitch_fsync  = false;
-       priv->bfsync_processing = false;
-       /* Backup BB InitialGain */
-       dm_bb_initialgain_backup(dev);
-
-}      /* DM_BackupDynamicMechanismState */
-
 static void dm_bb_initialgain_backup(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
@@ -1748,10 +1727,12 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
        pHalData->UndecoratedSmoothedPWDB, DM_DigTable.RssiLowThresh,
        DM_DigTable.RssiHighThresh, DM_DigTable.Dig_State);*/
        /* 1. When RSSI decrease, We have to judge if it is smaller than a threshold
-                 and then execute the step below. */
+        * and then execute the step below.
+        */
        if (priv->undecorated_smoothed_pwdb <= dm_digtable.rssi_low_thresh) {
                /* 2008/02/05 MH When we execute silent reset, the DIG PHY parameters
-                  will be reset to init value. We must prevent the condition. */
+                * will be reset to init value. We must prevent the condition.
+                */
                if (dm_digtable.dig_state == DM_STA_DIG_OFF &&
                    (priv->reset_count == reset_cnt)) {
                        return;
@@ -1773,8 +1754,7 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
 
                /*  1.3 Lower PD_TH for OFDM. */
                if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) {
-                       /*
-                        * 2008/01/11 MH 40MHZ 90/92 register are not the same.
+                       /* 2008/01/11 MH 40MHZ 90/92 register are not the same.
                         * 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
                         */
                        write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x00);
@@ -1797,7 +1777,8 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
        }
 
        /* 2. When RSSI increase, We have to judge if it is larger than a threshold
-                 and then execute the step below.  */
+        * and then execute the step below.
+        */
        if (priv->undecorated_smoothed_pwdb >= dm_digtable.rssi_high_thresh) {
                u8 reset_flag = 0;
 
@@ -1814,8 +1795,7 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
                dm_digtable.dig_state = DM_STA_DIG_ON;
                /*DbgPrint("DIG ON\n\r");*/
 
-               /*
-                * 2.1 Set initial gain.
+               /* 2.1 Set initial gain.
                 * 2008/02/26 MH SD3-Jerry suggest to prevent dirty environment.
                 */
                if (reset_flag == 1) {
@@ -1832,8 +1812,7 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
 
                /* 2.2 Higher PD_TH for OFDM. */
                if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) {
-                       /*
-                        * 2008/01/11 MH 40MHZ 90/92 register are not the same.
+                       /* 2008/01/11 MH 40MHZ 90/92 register are not the same.
                         * 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
                         */
                        write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x20);
@@ -1850,8 +1829,7 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
                /* 2.3 Higher CS ratio for CCK. */
                write_nic_byte(dev, 0xa0a, 0xcd);
 
-               /*
-                * 2.4 Lower EDCCA.
+               /* 2.4 Lower EDCCA.
                 * 2008/01/11 MH 90/92 series are the same.
                 */
                /*PlatformEFIOWrite4Byte(pAdapter, rOFDM0_ECCAThreshold, 0x346);*/
@@ -1892,8 +1870,7 @@ static void dm_ctrl_initgain_byrssi_highpwr(
                (priv->undecorated_smoothed_pwdb < dm_digtable.rssi_high_power_highthresh))
                return;
 
-       /*
-        * 3. When RSSI >75% or <70%, it is a high power issue. We have to judge if
+       /* 3. When RSSI >75% or <70%, it is a high power issue. We have to judge if
         *    it is larger than a threshold and then execute the step below.
         *
         * 2008/02/05 MH SD3-Jerry Modify PD_TH for high power issue.
@@ -2042,8 +2019,7 @@ static void dm_pd_th(
                        if (dm_digtable.curpd_thstate == DIG_PD_AT_LOW_POWER) {
                                /*  Lower PD_TH for OFDM. */
                                if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) {
-                                       /*
-                                        * 2008/01/11 MH 40MHZ 90/92 register are not the same.
+                                       /* 2008/01/11 MH 40MHZ 90/92 register are not the same.
                                         * 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
                                         */
                                        write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x00);
@@ -2055,8 +2031,7 @@ static void dm_pd_th(
                        } else if (dm_digtable.curpd_thstate == DIG_PD_AT_NORMAL_POWER) {
                                /* Higher PD_TH for OFDM. */
                                if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) {
-                                       /*
-                                        * 2008/01/11 MH 40MHZ 90/92 register are not the same.
+                                       /* 2008/01/11 MH 40MHZ 90/92 register are not the same.
                                         * 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
                                         */
                                        write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x20);
@@ -2155,8 +2130,7 @@ static void dm_check_edca_turbo(
        unsigned long                           curTxOkCnt = 0;
        unsigned long                           curRxOkCnt = 0;
 
-       /*
-        * Do not be Turbo if it's under WiFi config and Qos Enabled, because the EDCA parameters
+       /* Do not be Turbo if it's under WiFi config and Qos Enabled, because the EDCA parameters
         * should follow the settings from QAP. By Bruce, 2007-12-07.
         */
        if (priv->ieee80211->state != IEEE80211_LINKED)
@@ -2188,8 +2162,7 @@ static void dm_check_edca_turbo(
 
                priv->bcurrent_turbo_EDCA = true;
        } else {
-               /*
-                * Turn Off EDCA turbo here.
+               /* Turn Off EDCA turbo here.
                 * Restore original EDCA according to the declaration of AP.
                 */
                if (priv->bcurrent_turbo_EDCA) {
@@ -2219,8 +2192,7 @@ static void dm_check_edca_turbo(
                        write_nic_dword(dev, EDCAPARA_BE, u4bAcParam);
 
 
-                       /*
-                        * Check ACM bit.
+                       /* Check ACM bit.
                         * If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13.
                         */
                        {
@@ -2272,11 +2244,10 @@ static void dm_ctstoself(struct net_device *dev)
                pHTInfo->IOTAction &= ~HT_IOT_ACT_FORCED_CTS2SELF;
                return;
        }
-       /*
-       1. Uplink
-       2. Linksys350/Linksys300N
-       3. <50 disable, >55 enable
-       */
+       /* 1. Uplink
+        * 2. Linksys350/Linksys300N
+        * 3. <50 disable, >55 enable
+        */
 
        if (pHTInfo->IOTPeer == HT_IOT_PEER_BROADCOM) {
                curTxOkCnt = priv->stats.txbytesunicast - lastTxOkCnt;
@@ -2319,8 +2290,7 @@ static    void    dm_check_pbc_gpio(struct net_device *dev)
                return;
 
        if (tmp1byte & BIT(6) || tmp1byte & BIT(0)) {
-               /*
-                * Here we only set bPbcPressed to TRUE
+               /* Here we only set bPbcPressed to TRUE
                 * After trigger PBC, the variable will be set to FALSE
                 */
                RT_TRACE(COMP_IO, "CheckPbcGPIO - PBC is pressed\n");
@@ -2354,7 +2324,8 @@ void dm_rf_pathcheck_workitemcallback(struct work_struct *work)
        u8 rfpath = 0, i;
 
        /* 2008/01/30 MH After discussing with SD3 Jerry, 0xc04/0xd04 register will
-          always be the same. We only read 0xc04 now. */
+        * always be the same. We only read 0xc04 now.
+        */
        read_nic_byte(dev, 0xc04, &rfpath);
 
        /* Check Bit 0-3, it means if RF A-D is enabled. */
@@ -2529,8 +2500,7 @@ static void dm_rxpath_sel_byrssi(struct net_device *dev)
                }
        }
 
-       /*
-        * Set CCK Rx path
+       /* Set CCK Rx path
         * reg0xA07[3:2]=cck default rx path, reg0xa07[1:0]=cck optional rx path.
         */
        update_cck_rx_path = 0;
@@ -3049,8 +3019,7 @@ static void dm_send_rssi_tofw(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
 
-       /*
-        * If we test chariot, we should stop the TX command ?
+       /* If we test chariot, we should stop the TX command ?
         * Because 92E will always silent reset when we send tx command. We use register
         * 0x1e0(byte) to notify driver.
         */
index 0de0332906bd3feb39164084ca08915a3fafc08b..0b2a1c688597caa55d400ee011ca0f692594a5e4 100644 (file)
@@ -161,7 +161,6 @@ void hal_dm_watchdog(struct net_device *dev);
 void init_rate_adaptive(struct net_device *dev);
 void dm_txpower_trackingcallback(struct work_struct *work);
 void dm_restore_dynamic_mechanism_state(struct net_device *dev);
-void dm_backup_dynamic_mechanism_state(struct net_device *dev);
 void dm_force_tx_fw_info(struct net_device *dev,
                         u32 force_type, u32 force_value);
 void dm_init_edca_turbo(struct net_device *dev);
index 9ae86631fa8b87f3e72fc00d787c4e2681985b7d..0c4325073c638c7a9594c781cbeb3e3485051cdd 100644 (file)
@@ -148,14 +148,9 @@ struct _adapter {
        bool    driver_stopped;
        bool    surprise_removed;
        bool    suspended;
-       u32     IsrContent;
-       u32     ImrContent;
-       u8      EepromAddressSize;
+       u8      eeprom_address_size;
        u8      hw_init_completed;
-       struct task_struct *cmdThread;
-       pid_t evtThread;
-       struct task_struct *xmitThread;
-       pid_t recvThread;
+       struct task_struct *cmd_thread;
        uint (*dvobj_init)(struct _adapter *adapter);
        void (*dvobj_deinit)(struct _adapter *adapter);
        struct net_device *pnetdev;
@@ -163,9 +158,9 @@ struct _adapter {
        struct net_device_stats stats;
        struct iw_statistics iwstats;
        int pid; /*process id from UI*/
-       struct work_struct wkFilterRxFF0;
+       struct work_struct wk_filter_rx_ff0;
        u8 blnEnableRxFF0Filter;
-       spinlock_t lockRxFF0Filter;
+       spinlock_t lock_rx_ff0_filter;
        const struct firmware *fw;
        struct usb_interface *pusb_intf;
        struct mutex mutex_start;
index 401f0e442bcf472643912dcb84dbb99e0661eb5e..40145c0338e458290891f9e36c35cf2622805a2c 100644 (file)
 
 static void rtl871x_load_fw_cb(const struct firmware *firmware, void *context)
 {
-       struct _adapter *padapter = context;
+       struct _adapter *adapter = context;
 
-       complete(&padapter->rtl8712_fw_ready);
+       complete(&adapter->rtl8712_fw_ready);
        if (!firmware) {
-               struct usb_device *udev = padapter->dvobjpriv.pusbdev;
-               struct usb_interface *pusb_intf = padapter->pusb_intf;
+               struct usb_device *udev = adapter->dvobjpriv.pusbdev;
+               struct usb_interface *usb_intf = adapter->pusb_intf;
 
                dev_err(&udev->dev, "r8712u: Firmware request failed\n");
                usb_put_dev(udev);
-               usb_set_intfdata(pusb_intf, NULL);
+               usb_set_intfdata(usb_intf, NULL);
                return;
        }
-       padapter->fw = firmware;
+       adapter->fw = firmware;
        /* firmware available - start netdev */
-       register_netdev(padapter->pnetdev);
+       register_netdev(adapter->pnetdev);
 }
 
 static const char firmware_file[] = "rtlwifi/rtl8712u.bin";
@@ -65,47 +65,47 @@ int rtl871x_load_fw(struct _adapter *padapter)
 }
 MODULE_FIRMWARE("rtlwifi/rtl8712u.bin");
 
-static u32 rtl871x_open_fw(struct _adapter *padapter, const u8 **ppmappedfw)
+static u32 rtl871x_open_fw(struct _adapter *adapter, const u8 **mappedfw)
 {
-       const struct firmware **praw = &padapter->fw;
+       const struct firmware **raw = &adapter->fw;
 
-       if (padapter->fw->size > 200000) {
-               dev_err(&padapter->pnetdev->dev, "r8172u: Badfw->size of %d\n",
-                       (int)padapter->fw->size);
+       if (adapter->fw->size > 200000) {
+               dev_err(&adapter->pnetdev->dev, "r8172u: Badfw->size of %d\n",
+                       (int)adapter->fw->size);
                return 0;
        }
-       *ppmappedfw = (*praw)->data;
-       return (*praw)->size;
+       *mappedfw = (*raw)->data;
+       return (*raw)->size;
 }
 
-static void fill_fwpriv(struct _adapter *padapter, struct fw_priv *pfwpriv)
+static void fill_fwpriv(struct _adapter *adapter, struct fw_priv *fwpriv)
 {
-       struct dvobj_priv *pdvobj = &padapter->dvobjpriv;
-       struct registry_priv *pregpriv = &padapter->registrypriv;
+       struct dvobj_priv *dvobj = &adapter->dvobjpriv;
+       struct registry_priv *regpriv = &adapter->registrypriv;
 
-       memset(pfwpriv, 0, sizeof(struct fw_priv));
+       memset(fwpriv, 0, sizeof(struct fw_priv));
        /* todo: check if needs endian conversion */
-       pfwpriv->hci_sel =  RTL8712_HCI_TYPE_72USB;
-       pfwpriv->usb_ep_num = (u8)pdvobj->nr_endpoint;
-       pfwpriv->bw_40MHz_en = pregpriv->cbw40_enable;
-       switch (pregpriv->rf_config) {
+       fwpriv->hci_sel =  RTL8712_HCI_TYPE_72USB;
+       fwpriv->usb_ep_num = (u8)dvobj->nr_endpoint;
+       fwpriv->bw_40MHz_en = regpriv->cbw40_enable;
+       switch (regpriv->rf_config) {
        case RTL8712_RF_1T1R:
-               pfwpriv->rf_config = RTL8712_RFC_1T1R;
+               fwpriv->rf_config = RTL8712_RFC_1T1R;
                break;
        case RTL8712_RF_2T2R:
-               pfwpriv->rf_config = RTL8712_RFC_2T2R;
+               fwpriv->rf_config = RTL8712_RFC_2T2R;
                break;
        case RTL8712_RF_1T2R:
        default:
-               pfwpriv->rf_config = RTL8712_RFC_1T2R;
+               fwpriv->rf_config = RTL8712_RFC_1T2R;
        }
-       pfwpriv->mp_mode = (pregpriv->mp_mode == 1) ? 1 : 0;
+       fwpriv->mp_mode = (regpriv->mp_mode == 1) ? 1 : 0;
        /* 0:off 1:on 2:auto */
-       pfwpriv->vcs_type = pregpriv->vrtl_carrier_sense;
-       pfwpriv->vcs_mode = pregpriv->vcs_type; /* 1:RTS/CTS 2:CTS to self */
+       fwpriv->vcs_type = regpriv->vrtl_carrier_sense;
+       fwpriv->vcs_mode = regpriv->vcs_type; /* 1:RTS/CTS 2:CTS to self */
        /* default enable turbo_mode */
-       pfwpriv->turbo_mode = ((pregpriv->wifi_test == 1) ? 0 : 1);
-       pfwpriv->low_power_mode = pregpriv->low_power;
+       fwpriv->turbo_mode = ((regpriv->wifi_test == 1) ? 0 : 1);
+       fwpriv->low_power_mode = regpriv->low_power;
 }
 
 static void update_fwhdr(struct fw_hdr *pfwhdr, const u8 *pmappedfw)
@@ -141,7 +141,7 @@ static u8 chk_fwhdr(struct fw_hdr *pfwhdr, u32 ulfilelength)
        return _SUCCESS;
 }
 
-static u8 rtl8712_dl_fw(struct _adapter *padapter)
+static u8 rtl8712_dl_fw(struct _adapter *adapter)
 {
        sint i;
        u8 tmp8, tmp8_a;
@@ -150,56 +150,56 @@ static u8 rtl8712_dl_fw(struct _adapter *padapter)
        uint dump_imem_sz, imem_sz, dump_emem_sz, emem_sz; /* max = 49152; */
        struct fw_hdr fwhdr;
        u32 ulfilelength;       /* FW file size */
-       const u8 *pmappedfw = NULL;
-       u8 *ptmpchar = NULL, *ppayload, *ptr;
-       struct tx_desc *ptx_desc;
+       const u8 *mappedfw = NULL;
+       u8 *tmpchar = NULL, *payload, *ptr;
+       struct tx_desc *txdesc;
        u32 txdscp_sz = sizeof(struct tx_desc);
        u8 ret = _FAIL;
 
-       ulfilelength = rtl871x_open_fw(padapter, &pmappedfw);
-       if (pmappedfw && (ulfilelength > 0)) {
-               update_fwhdr(&fwhdr, pmappedfw);
+       ulfilelength = rtl871x_open_fw(adapter, &mappedfw);
+       if (mappedfw && (ulfilelength > 0)) {
+               update_fwhdr(&fwhdr, mappedfw);
                if (chk_fwhdr(&fwhdr, ulfilelength) == _FAIL)
                        return ret;
-               fill_fwpriv(padapter, &fwhdr.fwpriv);
+               fill_fwpriv(adapter, &fwhdr.fwpriv);
                /* firmware check ok */
                maxlen = (fwhdr.img_IMEM_size > fwhdr.img_SRAM_size) ?
                          fwhdr.img_IMEM_size : fwhdr.img_SRAM_size;
                maxlen += txdscp_sz;
-               ptmpchar = kmalloc(maxlen + FWBUFF_ALIGN_SZ, GFP_KERNEL);
-               if (!ptmpchar)
+               tmpchar = kmalloc(maxlen + FWBUFF_ALIGN_SZ, GFP_KERNEL);
+               if (!tmpchar)
                        return ret;
 
-               ptx_desc = (struct tx_desc *)(ptmpchar + FWBUFF_ALIGN_SZ -
-                           ((addr_t)(ptmpchar) & (FWBUFF_ALIGN_SZ - 1)));
-               ppayload = (u8 *)(ptx_desc) + txdscp_sz;
-               ptr = (u8 *)pmappedfw + FIELD_OFFSET(struct fw_hdr, fwpriv) +
+               txdesc = (struct tx_desc *)(tmpchar + FWBUFF_ALIGN_SZ -
+                           ((addr_t)(tmpchar) & (FWBUFF_ALIGN_SZ - 1)));
+               payload = (u8 *)(txdesc) + txdscp_sz;
+               ptr = (u8 *)mappedfw + FIELD_OFFSET(struct fw_hdr, fwpriv) +
                      fwhdr.fw_priv_sz;
                /* Download FirmWare */
                /* 1. determine IMEM code size and Load IMEM Code Section */
                imem_sz = fwhdr.img_IMEM_size;
                do {
-                       memset(ptx_desc, 0, TXDESC_SIZE);
+                       memset(txdesc, 0, TXDESC_SIZE);
                        if (imem_sz >  MAX_DUMP_FWSZ/*49152*/) {
                                dump_imem_sz = MAX_DUMP_FWSZ;
                        } else {
                                dump_imem_sz = imem_sz;
-                               ptx_desc->txdw0 |= cpu_to_le32(BIT(28));
+                               txdesc->txdw0 |= cpu_to_le32(BIT(28));
                        }
-                       ptx_desc->txdw0 |= cpu_to_le32(dump_imem_sz &
+                       txdesc->txdw0 |= cpu_to_le32(dump_imem_sz &
                                                       0x0000ffff);
-                       memcpy(ppayload, ptr, dump_imem_sz);
-                       r8712_write_mem(padapter, RTL8712_DMA_VOQ,
+                       memcpy(payload, ptr, dump_imem_sz);
+                       r8712_write_mem(adapter, RTL8712_DMA_VOQ,
                                        dump_imem_sz + TXDESC_SIZE,
-                                       (u8 *)ptx_desc);
+                                       (u8 *)txdesc);
                        ptr += dump_imem_sz;
                        imem_sz -= dump_imem_sz;
                } while (imem_sz > 0);
                i = 10;
-               tmp16 = r8712_read16(padapter, TCR);
+               tmp16 = r8712_read16(adapter, TCR);
                while (((tmp16 & _IMEM_CODE_DONE) == 0) && (i > 0)) {
                        usleep_range(10, 1000);
-                       tmp16 = r8712_read16(padapter, TCR);
+                       tmp16 = r8712_read16(adapter, TCR);
                        i--;
                }
                if (i == 0 || (tmp16 & _IMEM_CHK_RPT) == 0)
@@ -208,94 +208,94 @@ static u8 rtl8712_dl_fw(struct _adapter *padapter)
                /* 2.Download EMEM code size and Load EMEM Code Section */
                emem_sz = fwhdr.img_SRAM_size;
                do {
-                       memset(ptx_desc, 0, TXDESC_SIZE);
+                       memset(txdesc, 0, TXDESC_SIZE);
                        if (emem_sz >  MAX_DUMP_FWSZ) { /* max=48k */
                                dump_emem_sz = MAX_DUMP_FWSZ;
                        } else {
                                dump_emem_sz = emem_sz;
-                               ptx_desc->txdw0 |= cpu_to_le32(BIT(28));
+                               txdesc->txdw0 |= cpu_to_le32(BIT(28));
                        }
-                       ptx_desc->txdw0 |= cpu_to_le32(dump_emem_sz &
+                       txdesc->txdw0 |= cpu_to_le32(dump_emem_sz &
                                                       0x0000ffff);
-                       memcpy(ppayload, ptr, dump_emem_sz);
-                       r8712_write_mem(padapter, RTL8712_DMA_VOQ,
+                       memcpy(payload, ptr, dump_emem_sz);
+                       r8712_write_mem(adapter, RTL8712_DMA_VOQ,
                                        dump_emem_sz + TXDESC_SIZE,
-                                       (u8 *)ptx_desc);
+                                       (u8 *)txdesc);
                        ptr += dump_emem_sz;
                        emem_sz -= dump_emem_sz;
                } while (emem_sz > 0);
                i = 5;
-               tmp16 = r8712_read16(padapter, TCR);
+               tmp16 = r8712_read16(adapter, TCR);
                while (((tmp16 & _EMEM_CODE_DONE) == 0) && (i > 0)) {
                        usleep_range(10, 1000);
-                       tmp16 = r8712_read16(padapter, TCR);
+                       tmp16 = r8712_read16(adapter, TCR);
                        i--;
                }
                if (i == 0 || (tmp16 & _EMEM_CHK_RPT) == 0)
                        goto exit_fail;
 
                /* 3.Enable CPU */
-               tmp8 = r8712_read8(padapter, SYS_CLKR);
-               r8712_write8(padapter, SYS_CLKR, tmp8 | BIT(2));
-               tmp8_a = r8712_read8(padapter, SYS_CLKR);
+               tmp8 = r8712_read8(adapter, SYS_CLKR);
+               r8712_write8(adapter, SYS_CLKR, tmp8 | BIT(2));
+               tmp8_a = r8712_read8(adapter, SYS_CLKR);
                if (tmp8_a != (tmp8 | BIT(2)))
                        goto exit_fail;
 
-               tmp8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
-               r8712_write8(padapter, SYS_FUNC_EN + 1, tmp8 | BIT(2));
-               tmp8_a = r8712_read8(padapter, SYS_FUNC_EN + 1);
+               tmp8 = r8712_read8(adapter, SYS_FUNC_EN + 1);
+               r8712_write8(adapter, SYS_FUNC_EN + 1, tmp8 | BIT(2));
+               tmp8_a = r8712_read8(adapter, SYS_FUNC_EN + 1);
                if (tmp8_a != (tmp8 | BIT(2)))
                        goto exit_fail;
 
-               r8712_read32(padapter, TCR);
+               r8712_read32(adapter, TCR);
 
                /* 4.polling IMEM Ready */
                i = 100;
-               tmp16 = r8712_read16(padapter, TCR);
+               tmp16 = r8712_read16(adapter, TCR);
                while (((tmp16 & _IMEM_RDY) == 0) && (i > 0)) {
                        msleep(20);
-                       tmp16 = r8712_read16(padapter, TCR);
+                       tmp16 = r8712_read16(adapter, TCR);
                        i--;
                }
                if (i == 0) {
-                       r8712_write16(padapter, 0x10250348, 0xc000);
-                       r8712_write16(padapter, 0x10250348, 0xc001);
-                       r8712_write16(padapter, 0x10250348, 0x2000);
-                       r8712_write16(padapter, 0x10250348, 0x2001);
-                       r8712_write16(padapter, 0x10250348, 0x2002);
-                       r8712_write16(padapter, 0x10250348, 0x2003);
+                       r8712_write16(adapter, 0x10250348, 0xc000);
+                       r8712_write16(adapter, 0x10250348, 0xc001);
+                       r8712_write16(adapter, 0x10250348, 0x2000);
+                       r8712_write16(adapter, 0x10250348, 0x2001);
+                       r8712_write16(adapter, 0x10250348, 0x2002);
+                       r8712_write16(adapter, 0x10250348, 0x2003);
                        goto exit_fail;
                }
                /* 5.Download DMEM code size and Load EMEM Code Section */
-               memset(ptx_desc, 0, TXDESC_SIZE);
-               ptx_desc->txdw0 |= cpu_to_le32(fwhdr.fw_priv_sz & 0x0000ffff);
-               ptx_desc->txdw0 |= cpu_to_le32(BIT(28));
-               memcpy(ppayload, &fwhdr.fwpriv, fwhdr.fw_priv_sz);
-               r8712_write_mem(padapter, RTL8712_DMA_VOQ,
-                               fwhdr.fw_priv_sz + TXDESC_SIZE, (u8 *)ptx_desc);
+               memset(txdesc, 0, TXDESC_SIZE);
+               txdesc->txdw0 |= cpu_to_le32(fwhdr.fw_priv_sz & 0x0000ffff);
+               txdesc->txdw0 |= cpu_to_le32(BIT(28));
+               memcpy(payload, &fwhdr.fwpriv, fwhdr.fw_priv_sz);
+               r8712_write_mem(adapter, RTL8712_DMA_VOQ,
+                               fwhdr.fw_priv_sz + TXDESC_SIZE, (u8 *)txdesc);
 
                /* polling dmem code done */
                i = 100;
-               tmp16 = r8712_read16(padapter, TCR);
+               tmp16 = r8712_read16(adapter, TCR);
                while (((tmp16 & _DMEM_CODE_DONE) == 0) && (i > 0)) {
                        msleep(20);
-                       tmp16 = r8712_read16(padapter, TCR);
+                       tmp16 = r8712_read16(adapter, TCR);
                        i--;
                }
                if (i == 0)
                        goto exit_fail;
 
-               tmp8 = r8712_read8(padapter, 0x1025000A);
+               tmp8 = r8712_read8(adapter, 0x1025000A);
                if (tmp8 & BIT(4)) /* When boot from EEPROM,
                                    * & FW need more time to read EEPROM
                                    */
                        i = 60;
                else                    /* boot from EFUSE */
                        i = 30;
-               tmp16 = r8712_read16(padapter, TCR);
+               tmp16 = r8712_read16(adapter, TCR);
                while (((tmp16 & _FWRDY) == 0) && (i > 0)) {
                        msleep(100);
-                       tmp16 = r8712_read16(padapter, TCR);
+                       tmp16 = r8712_read16(adapter, TCR);
                        i--;
                }
                if (i == 0)
@@ -306,7 +306,7 @@ static u8 rtl8712_dl_fw(struct _adapter *padapter)
        ret = _SUCCESS;
 
 exit_fail:
-       kfree(ptmpchar);
+       kfree(tmpchar);
        return ret;
 }
 
index 4cca7390c8ef9a7afd940b0e976c906a45c5ac2a..b4a099169c7c8d1ac4cee68533aa2637cc5e649f 100644 (file)
@@ -156,13 +156,13 @@ static uint r8712_get_rateset_len(u8 *rateset)
        return i;
 }
 
-int r8712_generate_ie(struct registry_priv *pregistrypriv)
+int r8712_generate_ie(struct registry_priv *registrypriv)
 {
        int rate_len;
        uint sz = 0;
-       struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network;
-       u8 *ie = pdev_network->IEs;
-       u16 beaconPeriod = (u16)pdev_network->Configuration.BeaconPeriod;
+       struct wlan_bssid_ex *dev_network = &registrypriv->dev_network;
+       u8 *ie = dev_network->IEs;
+       u16 beaconPeriod = (u16)dev_network->Configuration.BeaconPeriod;
 
        /*timestamp will be inserted by hardware*/
        sz += 8;
@@ -174,65 +174,65 @@ int r8712_generate_ie(struct registry_priv *pregistrypriv)
        /*capability info*/
        *(u16 *)ie = 0;
        *(__le16 *)ie |= cpu_to_le16(cap_IBSS);
-       if (pregistrypriv->preamble == PREAMBLE_SHORT)
+       if (registrypriv->preamble == PREAMBLE_SHORT)
                *(__le16 *)ie |= cpu_to_le16(cap_ShortPremble);
-       if (pdev_network->Privacy)
+       if (dev_network->Privacy)
                *(__le16 *)ie |= cpu_to_le16(cap_Privacy);
        sz += 2;
        ie += 2;
        /*SSID*/
-       ie = r8712_set_ie(ie, _SSID_IE_, pdev_network->Ssid.SsidLength,
-                         pdev_network->Ssid.Ssid, &sz);
+       ie = r8712_set_ie(ie, _SSID_IE_, dev_network->Ssid.SsidLength,
+                         dev_network->Ssid.Ssid, &sz);
        /*supported rates*/
-       set_supported_rate(pdev_network->rates, pregistrypriv->wireless_mode);
-       rate_len = r8712_get_rateset_len(pdev_network->rates);
+       set_supported_rate(dev_network->rates, registrypriv->wireless_mode);
+       rate_len = r8712_get_rateset_len(dev_network->rates);
        if (rate_len > 8) {
                ie = r8712_set_ie(ie, _SUPPORTEDRATES_IE_, 8,
-                                 pdev_network->rates, &sz);
+                                 dev_network->rates, &sz);
                ie = r8712_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8),
-                                 (pdev_network->rates + 8), &sz);
+                                 (dev_network->rates + 8), &sz);
        } else {
                ie = r8712_set_ie(ie, _SUPPORTEDRATES_IE_,
-                                 rate_len, pdev_network->rates, &sz);
+                                 rate_len, dev_network->rates, &sz);
        }
        /*DS parameter set*/
        ie = r8712_set_ie(ie, _DSSET_IE_, 1,
-                         (u8 *)&pdev_network->Configuration.DSConfig, &sz);
+                         (u8 *)&dev_network->Configuration.DSConfig, &sz);
        /*IBSS Parameter Set*/
        ie = r8712_set_ie(ie, _IBSS_PARA_IE_, 2,
-                         (u8 *)&pdev_network->Configuration.ATIMWindow, &sz);
+                         (u8 *)&dev_network->Configuration.ATIMWindow, &sz);
        return sz;
 }
 
-unsigned char *r8712_get_wpa_ie(unsigned char *pie, uint *wpa_ie_len, int limit)
+unsigned char *r8712_get_wpa_ie(unsigned char *ie, uint *wpa_ie_len, int limit)
 {
        u32 len;
        u16 val16;
        unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01};
-       u8 *pbuf = pie;
+       u8 *buf = ie;
 
        while (1) {
-               pbuf = r8712_get_ie(pbuf, _WPA_IE_ID_, &len, limit);
-               if (pbuf) {
+               buf = r8712_get_ie(buf, _WPA_IE_ID_, &len, limit);
+               if (buf) {
                        /*check if oui matches...*/
-                       if (memcmp((pbuf + 2), wpa_oui_type,
+                       if (memcmp((buf + 2), wpa_oui_type,
                                   sizeof(wpa_oui_type)))
                                goto check_next_ie;
                        /*check version...*/
-                       memcpy((u8 *)&val16, (pbuf + 6), sizeof(val16));
+                       memcpy((u8 *)&val16, (buf + 6), sizeof(val16));
                        le16_to_cpus(&val16);
                        if (val16 != 0x0001)
                                goto check_next_ie;
-                       *wpa_ie_len = *(pbuf + 1);
-                       return pbuf;
+                       *wpa_ie_len = *(buf + 1);
+                       return buf;
                }
                *wpa_ie_len = 0;
                return NULL;
 check_next_ie:
-               limit = limit - (pbuf - pie) - 2 - len;
+               limit = limit - (buf - ie) - 2 - len;
                if (limit <= 0)
                        break;
-               pbuf += (2 + len);
+               buf += (2 + len);
        }
        *wpa_ie_len = 0;
        return NULL;
@@ -283,12 +283,12 @@ int r8712_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
 
        if (wpa_ie_len <= 0) {
                /* No WPA IE - fail silently */
-               return _FAIL;
+               return -EINVAL;
        }
        if ((*wpa_ie != _WPA_IE_ID_) ||
            (*(wpa_ie + 1) != (u8)(wpa_ie_len - 2)) ||
            (memcmp(wpa_ie + 2, (void *)WPA_OUI_TYPE, WPA_SELECTOR_LEN)))
-               return _FAIL;
+               return -EINVAL;
        pos = wpa_ie;
        pos += 8;
        left = wpa_ie_len - 8;
@@ -298,7 +298,7 @@ int r8712_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
                pos += WPA_SELECTOR_LEN;
                left -= WPA_SELECTOR_LEN;
        } else if (left > 0) {
-               return _FAIL;
+               return -EINVAL;
        }
        /*pairwise_cipher*/
        if (left >= 2) {
@@ -306,16 +306,16 @@ int r8712_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
                pos += 2;
                left -= 2;
                if (count == 0 || left < count * WPA_SELECTOR_LEN)
-                       return _FAIL;
+                       return -EINVAL;
                for (i = 0; i < count; i++) {
                        *pairwise_cipher |= r8712_get_wpa_cipher_suite(pos);
                        pos += WPA_SELECTOR_LEN;
                        left -= WPA_SELECTOR_LEN;
                }
        } else if (left == 1) {
-               return _FAIL;
+               return -EINVAL;
        }
-       return _SUCCESS;
+       return 0;
 }
 
 int r8712_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher,
@@ -327,11 +327,11 @@ int r8712_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher,
 
        if (rsn_ie_len <= 0) {
                /* No RSN IE - fail silently */
-               return _FAIL;
+               return -EINVAL;
        }
        if ((*rsn_ie != _WPA2_IE_ID_) ||
            (*(rsn_ie + 1) != (u8)(rsn_ie_len - 2)))
-               return _FAIL;
+               return -EINVAL;
        pos = rsn_ie;
        pos += 4;
        left = rsn_ie_len - 4;
@@ -341,7 +341,7 @@ int r8712_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher,
                pos += RSN_SELECTOR_LEN;
                left -= RSN_SELECTOR_LEN;
        } else if (left > 0) {
-               return _FAIL;
+               return -EINVAL;
        }
        /*pairwise_cipher*/
        if (left >= 2) {
@@ -349,16 +349,16 @@ int r8712_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher,
                pos += 2;
                left -= 2;
                if (count == 0 || left < count * RSN_SELECTOR_LEN)
-                       return _FAIL;
+                       return -EINVAL;
                for (i = 0; i < count; i++) {
                        *pairwise_cipher |= r8712_get_wpa2_cipher_suite(pos);
                        pos += RSN_SELECTOR_LEN;
                        left -= RSN_SELECTOR_LEN;
                }
        } else if (left == 1) {
-               return _FAIL;
+               return -EINVAL;
        }
-       return _SUCCESS;
+       return 0;
 }
 
 int r8712_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len,
index 4d473f008aa48f7c3f5d2735402a5edc257dbf61..b9f5104f3bf75a0fc0f132886fdc418eb379757e 100644 (file)
@@ -60,22 +60,22 @@ static void wdg_timeout_handler (struct timer_list *t)
        struct _adapter *adapter =
                from_timer(adapter, t, mlmepriv.wdg_timer);
 
-       _r8712_wdg_timeout_handler(adapter);
+       r8712_wdg_wk_cmd(adapter);
 
        mod_timer(&adapter->mlmepriv.wdg_timer,
                  jiffies + msecs_to_jiffies(2000));
 }
 
-void r8712_init_mlme_timer(struct _adapter *padapter)
+void r8712_init_mlme_timer(struct _adapter *adapter)
 {
-       struct  mlme_priv *pmlmepriv = &padapter->mlmepriv;
+       struct  mlme_priv *mlmepriv = &adapter->mlmepriv;
 
-       timer_setup(&pmlmepriv->assoc_timer, join_timeout_handler, 0);
-       timer_setup(&pmlmepriv->sitesurveyctrl.sitesurvey_ctrl_timer,
+       timer_setup(&mlmepriv->assoc_timer, join_timeout_handler, 0);
+       timer_setup(&mlmepriv->sitesurveyctrl.sitesurvey_ctrl_timer,
                    sitesurvey_ctrl_handler, 0);
-       timer_setup(&pmlmepriv->scan_to_timer, _scan_timeout_handler, 0);
-       timer_setup(&pmlmepriv->dhcp_timer, dhcp_timeout_handler, 0);
-       timer_setup(&pmlmepriv->wdg_timer, wdg_timeout_handler, 0);
+       timer_setup(&mlmepriv->scan_to_timer, _scan_timeout_handler, 0);
+       timer_setup(&mlmepriv->dhcp_timer, dhcp_timeout_handler, 0);
+       timer_setup(&mlmepriv->wdg_timer, wdg_timeout_handler, 0);
 }
 
 void r8712_os_indicate_connect(struct _adapter *adapter)
@@ -119,16 +119,16 @@ void r8712_os_indicate_disconnect(struct _adapter *adapter)
                adapter->securitypriv.btkip_countermeasure =
                                         backupTKIPCountermeasure;
        } else { /*reset values in securitypriv*/
-               struct security_priv *psec_priv = &adapter->securitypriv;
-
-               psec_priv->AuthAlgrthm = 0; /*open system*/
-               psec_priv->PrivacyAlgrthm = _NO_PRIVACY_;
-               psec_priv->PrivacyKeyIndex = 0;
-               psec_priv->XGrpPrivacy = _NO_PRIVACY_;
-               psec_priv->XGrpKeyid = 1;
-               psec_priv->ndisauthtype = Ndis802_11AuthModeOpen;
-               psec_priv->ndisencryptstatus = Ndis802_11WEPDisabled;
-               psec_priv->wps_phase = false;
+               struct security_priv *sec_priv = &adapter->securitypriv;
+
+               sec_priv->AuthAlgrthm = 0; /*open system*/
+               sec_priv->PrivacyAlgrthm = _NO_PRIVACY_;
+               sec_priv->PrivacyKeyIndex = 0;
+               sec_priv->XGrpPrivacy = _NO_PRIVACY_;
+               sec_priv->XGrpKeyid = 1;
+               sec_priv->ndisauthtype = Ndis802_11AuthModeOpen;
+               sec_priv->ndisencryptstatus = Ndis802_11WEPDisabled;
+               sec_priv->wps_phase = false;
        }
 }
 
index c962696c9822f5e143a78468ba4ddb8e0a6e8876..b554cf8bd679a430ba1932751a8e95a3b76b8a26 100644 (file)
@@ -221,9 +221,9 @@ struct net_device *r8712_init_netdev(void)
 
 static u32 start_drv_threads(struct _adapter *padapter)
 {
-       padapter->cmdThread = kthread_run(r8712_cmd_thread, padapter, "%s",
+       padapter->cmd_thread = kthread_run(r8712_cmd_thread, padapter, "%s",
                                          padapter->pnetdev->name);
-       if (IS_ERR(padapter->cmdThread))
+       if (IS_ERR(padapter->cmd_thread))
                return _FAIL;
        return _SUCCESS;
 }
@@ -235,7 +235,7 @@ void r8712_stop_drv_threads(struct _adapter *padapter)
 
        /*Below is to terminate r8712_cmd_thread & event_thread...*/
        complete(&padapter->cmdpriv.cmd_queue_comp);
-       if (padapter->cmdThread)
+       if (padapter->cmd_thread)
                wait_for_completion_interruptible(completion);
        padapter->cmdpriv.cmd_seq = 1;
 }
@@ -297,10 +297,10 @@ static u8 init_default_value(struct _adapter *padapter)
 
 u8 r8712_init_drv_sw(struct _adapter *padapter)
 {
-       if ((r8712_init_cmd_priv(&padapter->cmdpriv)) == _FAIL)
+       if (r8712_init_cmd_priv(&padapter->cmdpriv))
                return _FAIL;
        padapter->cmdpriv.padapter = padapter;
-       if ((r8712_init_evt_priv(&padapter->evtpriv)) == _FAIL)
+       if (r8712_init_evt_priv(&padapter->evtpriv))
                return _FAIL;
        if (r8712_init_mlme_priv(padapter) == _FAIL)
                return _FAIL;
@@ -310,7 +310,8 @@ u8 r8712_init_drv_sw(struct _adapter *padapter)
               sizeof(struct security_priv));
        timer_setup(&padapter->securitypriv.tkip_timer,
                    r8712_use_tkipkey_handler, 0);
-       _r8712_init_sta_priv(&padapter->stapriv);
+       if (_r8712_init_sta_priv(&padapter->stapriv))
+               return _FAIL;
        padapter->stapriv.padapter = padapter;
        r8712_init_bcmc_stainfo(padapter);
        r8712_init_pwrctrl_priv(padapter);
index 4e20cbafa9fbeb49bacc73ae0db68201731c6ecb..84c4c8580f9a3314cfa83880c7b535f23274127f 100644 (file)
@@ -72,11 +72,11 @@ int r8712_os_recvbuf_resource_free(struct _adapter *padapter,
        return _SUCCESS;
 }
 
-void r8712_handle_tkip_mic_err(struct _adapter *padapter, u8 bgroup)
+void r8712_handle_tkip_mic_err(struct _adapter *adapter, u8 bgroup)
 {
        union iwreq_data wrqu;
        struct iw_michaelmicfailure ev;
-       struct mlme_priv *pmlmepriv  = &padapter->mlmepriv;
+       struct mlme_priv *mlmepriv  = &adapter->mlmepriv;
 
        memset(&ev, 0x00, sizeof(ev));
        if (bgroup)
@@ -84,54 +84,54 @@ void r8712_handle_tkip_mic_err(struct _adapter *padapter, u8 bgroup)
        else
                ev.flags |= IW_MICFAILURE_PAIRWISE;
        ev.src_addr.sa_family = ARPHRD_ETHER;
-       ether_addr_copy(ev.src_addr.sa_data, &pmlmepriv->assoc_bssid[0]);
+       ether_addr_copy(ev.src_addr.sa_data, &mlmepriv->assoc_bssid[0]);
        memset(&wrqu, 0x00, sizeof(wrqu));
        wrqu.data.length = sizeof(ev);
-       wireless_send_event(padapter->pnetdev, IWEVMICHAELMICFAILURE, &wrqu,
+       wireless_send_event(adapter->pnetdev, IWEVMICHAELMICFAILURE, &wrqu,
                            (char *)&ev);
 }
 
-void r8712_recv_indicatepkt(struct _adapter *padapter,
-                           union recv_frame *precv_frame)
+void r8712_recv_indicatepkt(struct _adapter *adapter,
+                           union recv_frame *recvframe)
 {
-       struct recv_priv *precvpriv;
-       struct  __queue *pfree_recv_queue;
+       struct recv_priv *recvpriv;
+       struct  __queue *free_recv_queue;
        _pkt *skb;
-       struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
+       struct rx_pkt_attrib *attrib = &recvframe->u.hdr.attrib;
 
-       precvpriv = &padapter->recvpriv;
-       pfree_recv_queue = &precvpriv->free_recv_queue;
-       skb = precv_frame->u.hdr.pkt;
+       recvpriv = &adapter->recvpriv;
+       free_recv_queue = &recvpriv->free_recv_queue;
+       skb = recvframe->u.hdr.pkt;
        if (!skb)
                goto _recv_indicatepkt_drop;
-       skb->data = precv_frame->u.hdr.rx_data;
-       skb->len = precv_frame->u.hdr.len;
+       skb->data = recvframe->u.hdr.rx_data;
+       skb->len = recvframe->u.hdr.len;
        skb_set_tail_pointer(skb, skb->len);
-       if ((pattrib->tcpchk_valid == 1) && (pattrib->tcp_chkrpt == 1))
+       if ((attrib->tcpchk_valid == 1) && (attrib->tcp_chkrpt == 1))
                skb->ip_summed = CHECKSUM_UNNECESSARY;
        else
                skb->ip_summed = CHECKSUM_NONE;
-       skb->dev = padapter->pnetdev;
-       skb->protocol = eth_type_trans(skb, padapter->pnetdev);
+       skb->dev = adapter->pnetdev;
+       skb->protocol = eth_type_trans(skb, adapter->pnetdev);
        netif_rx(skb);
-       precv_frame->u.hdr.pkt = NULL; /* pointers to NULL before
+       recvframe->u.hdr.pkt = NULL; /* pointers to NULL before
                                        * r8712_free_recvframe()
                                        */
-       r8712_free_recvframe(precv_frame, pfree_recv_queue);
+       r8712_free_recvframe(recvframe, free_recv_queue);
        return;
 _recv_indicatepkt_drop:
         /*enqueue back to free_recv_queue*/
-       if (precv_frame)
-               r8712_free_recvframe(precv_frame, pfree_recv_queue);
-       precvpriv->rx_drop++;
+       if (recvframe)
+               r8712_free_recvframe(recvframe, free_recv_queue);
+       recvpriv->rx_drop++;
 }
 
 static void _r8712_reordering_ctrl_timeout_handler (struct timer_list *t)
 {
-       struct recv_reorder_ctrl *preorder_ctrl =
-                        from_timer(preorder_ctrl, t, reordering_ctrl_timer);
+       struct recv_reorder_ctrl *reorder_ctrl =
+                        from_timer(reorder_ctrl, t, reordering_ctrl_timer);
 
-       r8712_reordering_ctrl_timeout_handler(preorder_ctrl);
+       r8712_reordering_ctrl_timeout_handler(reorder_ctrl);
 }
 
 void r8712_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl)
index 00babd011a62d4fa3492e67f956d4c6f52fb05ff..4f3b54a7c3beb5a89c7d5b9e7debcdeb01245ad5 100644 (file)
@@ -23,7 +23,7 @@
 /* reserve 3 bytes for HW stop read */
 static int efuse_available_max_size = EFUSE_MAX_SIZE - 3 /*0x1FD*/;
 
-static void efuse_reg_ctrl(struct _adapter *padapter, u8 bPowerOn)
+static void efuse_reg_ctrl(struct _adapter *adapter, u8 bPowerOn)
 {
        u8 tmpu8 = 0;
 
@@ -31,53 +31,53 @@ static void efuse_reg_ctrl(struct _adapter *padapter, u8 bPowerOn)
                /* -----------------e-fuse pwr & clk reg ctrl ---------------
                 * Enable LDOE25 Macro Block
                 */
-               tmpu8 = r8712_read8(padapter, EFUSE_TEST + 3);
+               tmpu8 = r8712_read8(adapter, EFUSE_TEST + 3);
                tmpu8 |= 0x80;
-               r8712_write8(padapter, EFUSE_TEST + 3, tmpu8);
+               r8712_write8(adapter, EFUSE_TEST + 3, tmpu8);
                msleep(20); /* for some platform , need some delay time */
                /* Change Efuse Clock for write action to 40MHZ */
-               r8712_write8(padapter, EFUSE_CLK_CTRL, 0x03);
+               r8712_write8(adapter, EFUSE_CLK_CTRL, 0x03);
                msleep(20); /* for some platform , need some delay time */
        } else {
                /* -----------------e-fuse pwr & clk reg ctrl -----------------
                 * Disable LDOE25 Macro Block
                 */
-               tmpu8 = r8712_read8(padapter, EFUSE_TEST + 3);
+               tmpu8 = r8712_read8(adapter, EFUSE_TEST + 3);
                tmpu8 &= 0x7F;
-               r8712_write8(padapter, EFUSE_TEST + 3, tmpu8);
+               r8712_write8(adapter, EFUSE_TEST + 3, tmpu8);
                /* Change Efuse Clock for write action to 500K */
-               r8712_write8(padapter, EFUSE_CLK_CTRL, 0x02);
+               r8712_write8(adapter, EFUSE_CLK_CTRL, 0x02);
        }
 }
 
 /*
  * Before write E-Fuse, this function must be called.
  */
-u8 r8712_efuse_reg_init(struct _adapter *padapter)
+u8 r8712_efuse_reg_init(struct _adapter *adapter)
 {
        return true;
 }
 
-void r8712_efuse_reg_uninit(struct _adapter *padapter)
+void r8712_efuse_reg_uninit(struct _adapter *adapter)
 {
-       efuse_reg_ctrl(padapter, false);
+       efuse_reg_ctrl(adapter, false);
 }
 
-static u8 efuse_one_byte_read(struct _adapter *padapter, u16 addr, u8 *data)
+static u8 efuse_one_byte_read(struct _adapter *adapter, u16 addr, u8 *data)
 {
        u8 tmpidx = 0, bResult;
 
        /* -----------------e-fuse reg ctrl --------------------------------- */
-       r8712_write8(padapter, EFUSE_CTRL + 1, (u8)(addr & 0xFF)); /* address */
-       r8712_write8(padapter, EFUSE_CTRL + 2, ((u8)((addr >> 8) & 0x03)) |
-              (r8712_read8(padapter, EFUSE_CTRL + 2) & 0xFC));
-       r8712_write8(padapter, EFUSE_CTRL + 3, 0x72); /* read cmd */
+       r8712_write8(adapter, EFUSE_CTRL + 1, (u8)(addr & 0xFF)); /* address */
+       r8712_write8(adapter, EFUSE_CTRL + 2, ((u8)((addr >> 8) & 0x03)) |
+              (r8712_read8(adapter, EFUSE_CTRL + 2) & 0xFC));
+       r8712_write8(adapter, EFUSE_CTRL + 3, 0x72); /* read cmd */
        /* wait for complete */
-       while (!(0x80 & r8712_read8(padapter, EFUSE_CTRL + 3)) &&
+       while (!(0x80 & r8712_read8(adapter, EFUSE_CTRL + 3)) &&
               (tmpidx < 100))
                tmpidx++;
        if (tmpidx < 100) {
-               *data = r8712_read8(padapter, EFUSE_CTRL);
+               *data = r8712_read8(adapter, EFUSE_CTRL);
                bResult = true;
        } else {
                *data = 0xff;
@@ -86,18 +86,18 @@ static u8 efuse_one_byte_read(struct _adapter *padapter, u16 addr, u8 *data)
        return bResult;
 }
 
-static u8 efuse_one_byte_write(struct _adapter *padapter, u16 addr, u8 data)
+static u8 efuse_one_byte_write(struct _adapter *adapter, u16 addr, u8 data)
 {
        u8 tmpidx = 0, bResult;
 
        /* -----------------e-fuse reg ctrl -------------------------------- */
-       r8712_write8(padapter, EFUSE_CTRL + 1, (u8)(addr & 0xFF)); /* address */
-       r8712_write8(padapter, EFUSE_CTRL + 2, ((u8)((addr >> 8) & 0x03)) |
-              (r8712_read8(padapter, EFUSE_CTRL + 2) & 0xFC));
-       r8712_write8(padapter, EFUSE_CTRL, data); /* data */
-       r8712_write8(padapter, EFUSE_CTRL + 3, 0xF2); /* write cmd */
+       r8712_write8(adapter, EFUSE_CTRL + 1, (u8)(addr & 0xFF)); /* address */
+       r8712_write8(adapter, EFUSE_CTRL + 2, ((u8)((addr >> 8) & 0x03)) |
+              (r8712_read8(adapter, EFUSE_CTRL + 2) & 0xFC));
+       r8712_write8(adapter, EFUSE_CTRL, data); /* data */
+       r8712_write8(adapter, EFUSE_CTRL + 3, 0xF2); /* write cmd */
        /* wait for complete */
-       while ((0x80 &  r8712_read8(padapter, EFUSE_CTRL + 3)) &&
+       while ((0x80 &  r8712_read8(adapter, EFUSE_CTRL + 3)) &&
               (tmpidx < 100))
                tmpidx++;
        if (tmpidx < 100)
@@ -107,32 +107,32 @@ static u8 efuse_one_byte_write(struct _adapter *padapter, u16 addr, u8 data)
        return bResult;
 }
 
-static u8 efuse_one_byte_rw(struct _adapter *padapter, u8 bRead, u16 addr,
+static u8 efuse_one_byte_rw(struct _adapter *adapter, u8 bRead, u16 addr,
                            u8 *data)
 {
        u8 tmpidx = 0, tmpv8 = 0, bResult;
 
        /* -----------------e-fuse reg ctrl --------------------------------- */
-       r8712_write8(padapter, EFUSE_CTRL + 1, (u8)(addr & 0xFF)); /* address */
+       r8712_write8(adapter, EFUSE_CTRL + 1, (u8)(addr & 0xFF)); /* address */
        tmpv8 = ((u8)((addr >> 8) & 0x03)) |
-                (r8712_read8(padapter, EFUSE_CTRL + 2) & 0xFC);
-       r8712_write8(padapter, EFUSE_CTRL + 2, tmpv8);
+                (r8712_read8(adapter, EFUSE_CTRL + 2) & 0xFC);
+       r8712_write8(adapter, EFUSE_CTRL + 2, tmpv8);
        if (bRead) {
-               r8712_write8(padapter, EFUSE_CTRL + 3,  0x72); /* read cmd */
-               while (!(0x80 & r8712_read8(padapter, EFUSE_CTRL + 3)) &&
+               r8712_write8(adapter, EFUSE_CTRL + 3,  0x72); /* read cmd */
+               while (!(0x80 & r8712_read8(adapter, EFUSE_CTRL + 3)) &&
                       (tmpidx < 100))
                        tmpidx++;
                if (tmpidx < 100) {
-                       *data = r8712_read8(padapter, EFUSE_CTRL);
+                       *data = r8712_read8(adapter, EFUSE_CTRL);
                        bResult = true;
                } else {
                        *data = 0;
                        bResult = false;
                }
        } else {
-               r8712_write8(padapter, EFUSE_CTRL, *data); /* data */
-               r8712_write8(padapter, EFUSE_CTRL + 3, 0xF2); /* write cmd */
-               while ((0x80 & r8712_read8(padapter, EFUSE_CTRL + 3)) &&
+               r8712_write8(adapter, EFUSE_CTRL, *data); /* data */
+               r8712_write8(adapter, EFUSE_CTRL + 3, 0xF2); /* write cmd */
+               while ((0x80 & r8712_read8(adapter, EFUSE_CTRL + 3)) &&
                       (tmpidx < 100))
                        tmpidx++;
                if (tmpidx < 100)
@@ -143,12 +143,12 @@ static u8 efuse_one_byte_rw(struct _adapter *padapter, u8 bRead, u16 addr,
        return bResult;
 }
 
-static u8 efuse_is_empty(struct _adapter *padapter, u8 *empty)
+static u8 efuse_is_empty(struct _adapter *adapter, u8 *empty)
 {
        u8 value, ret = true;
 
        /* read one byte to check if E-Fuse is empty */
-       if (efuse_one_byte_rw(padapter, true, 0, &value)) {
+       if (efuse_one_byte_rw(adapter, true, 0, &value)) {
                if (value == 0xFF)
                        *empty = true;
                else
@@ -159,7 +159,7 @@ static u8 efuse_is_empty(struct _adapter *padapter, u8 *empty)
        return ret;
 }
 
-void r8712_efuse_change_max_size(struct _adapter *padapter)
+void r8712_efuse_change_max_size(struct _adapter *adapter)
 {
        u16 pre_pg_data_saddr = 0x1FB;
        u16 i;
@@ -167,7 +167,7 @@ void r8712_efuse_change_max_size(struct _adapter *padapter)
        u8 pre_pg_data[5];
 
        for (i = 0; i < pre_pg_data_size; i++)
-               efuse_one_byte_read(padapter, pre_pg_data_saddr + i,
+               efuse_one_byte_read(adapter, pre_pg_data_saddr + i,
                                    &pre_pg_data[i]);
        if ((pre_pg_data[0] == 0x03) && (pre_pg_data[1] == 0x00) &&
            (pre_pg_data[2] == 0x00) && (pre_pg_data[3] == 0x00) &&
@@ -175,7 +175,7 @@ void r8712_efuse_change_max_size(struct _adapter *padapter)
                efuse_available_max_size -= pre_pg_data_size;
 }
 
-int r8712_efuse_get_max_size(struct _adapter *padapter)
+int r8712_efuse_get_max_size(struct _adapter *adapter)
 {
        return  efuse_available_max_size;
 }
@@ -206,14 +206,14 @@ static void pgpacket_copy_data(const u8 word_en, const u8 *sourdata,
        }
 }
 
-u16 r8712_efuse_get_current_size(struct _adapter *padapter)
+u16 r8712_efuse_get_current_size(struct _adapter *adapter)
 {
        int bContinual = true;
        u16 efuse_addr = 0;
        u8 hworden = 0;
        u8 efuse_data, word_cnts = 0;
 
-       while (bContinual && efuse_one_byte_read(padapter, efuse_addr,
+       while (bContinual && efuse_one_byte_read(adapter, efuse_addr,
               &efuse_data) && (efuse_addr < efuse_available_max_size)) {
                if (efuse_data != 0xFF) {
                        hworden =  efuse_data & 0x0F;
@@ -227,7 +227,7 @@ u16 r8712_efuse_get_current_size(struct _adapter *padapter)
        return efuse_addr;
 }
 
-u8 r8712_efuse_pg_packet_read(struct _adapter *padapter, u8 offset, u8 *data)
+u8 r8712_efuse_pg_packet_read(struct _adapter *adapter, u8 offset, u8 *data)
 {
        u8 hoffset = 0, hworden = 0, word_cnts = 0;
        u16 efuse_addr = 0;
@@ -242,7 +242,7 @@ u8 r8712_efuse_pg_packet_read(struct _adapter *padapter, u8 offset, u8 *data)
                return false;
        memset(data, 0xFF, sizeof(u8) * PGPKT_DATA_SIZE);
        while (efuse_addr < efuse_available_max_size) {
-               if (efuse_one_byte_read(padapter, efuse_addr, &efuse_data)) {
+               if (efuse_one_byte_read(adapter, efuse_addr, &efuse_data)) {
                        if (efuse_data == 0xFF)
                                break;
                        hoffset = (efuse_data >> 4) & 0x0F;
@@ -252,7 +252,7 @@ u8 r8712_efuse_pg_packet_read(struct _adapter *padapter, u8 offset, u8 *data)
                                memset(tmpdata, 0xFF, PGPKT_DATA_SIZE);
                                for (tmpidx = 0; tmpidx < word_cnts * 2;
                                     tmpidx++) {
-                                       if (efuse_one_byte_read(padapter,
+                                       if (efuse_one_byte_read(adapter,
                                            efuse_addr + 1 + tmpidx,
                                            &efuse_data)) {
                                                tmpdata[tmpidx] = efuse_data;
@@ -271,7 +271,7 @@ u8 r8712_efuse_pg_packet_read(struct _adapter *padapter, u8 offset, u8 *data)
        return ret;
 }
 
-static u8 fix_header(struct _adapter *padapter, u8 header, u16 header_addr)
+static u8 fix_header(struct _adapter *adapter, u8 header, u16 header_addr)
 {
        struct PGPKT_STRUCT pkt;
        u8 offset, word_en, value;
@@ -287,7 +287,7 @@ static u8 fix_header(struct _adapter *padapter, u8 header, u16 header_addr)
        /* retrieve original data */
        addr = 0;
        while (addr < header_addr) {
-               if (!efuse_one_byte_read(padapter, addr++, &value)) {
+               if (!efuse_one_byte_read(adapter, addr++, &value)) {
                        ret = false;
                        break;
                }
@@ -301,13 +301,13 @@ static u8 fix_header(struct _adapter *padapter, u8 header, u16 header_addr)
                        if (BIT(i) & word_en) {
                                if (BIT(i) & pkt.word_en) {
                                        if (efuse_one_byte_read(
-                                                       padapter, addr,
+                                                       adapter, addr,
                                                        &value))
                                                pkt.data[i * 2] = value;
                                        else
                                                return false;
                                        if (efuse_one_byte_read(
-                                                       padapter,
+                                                       adapter,
                                                        addr + 1,
                                                        &value))
                                                pkt.data[i * 2 + 1] =
@@ -325,24 +325,24 @@ static u8 fix_header(struct _adapter *padapter, u8 header, u16 header_addr)
        /* fill original data */
        for (i = 0; i < PGPKG_MAX_WORDS; i++) {
                if (BIT(i) & pkt.word_en) {
-                       efuse_one_byte_write(padapter, addr, pkt.data[i * 2]);
-                       efuse_one_byte_write(padapter, addr + 1,
+                       efuse_one_byte_write(adapter, addr, pkt.data[i * 2]);
+                       efuse_one_byte_write(adapter, addr + 1,
                                             pkt.data[i * 2 + 1]);
                        /* additional check */
-                       if (!efuse_one_byte_read(padapter, addr, &value)) {
+                       if (!efuse_one_byte_read(adapter, addr, &value)) {
                                ret = false;
                        } else if (pkt.data[i * 2] != value) {
                                ret = false;
                                if (value == 0xFF) /* write again */
-                                       efuse_one_byte_write(padapter, addr,
+                                       efuse_one_byte_write(adapter, addr,
                                                             pkt.data[i * 2]);
                        }
-                       if (!efuse_one_byte_read(padapter, addr + 1, &value)) {
+                       if (!efuse_one_byte_read(adapter, addr + 1, &value)) {
                                ret = false;
                        } else if (pkt.data[i * 2 + 1] != value) {
                                ret = false;
                                if (value == 0xFF) /* write again */
-                                       efuse_one_byte_write(padapter, addr + 1,
+                                       efuse_one_byte_write(adapter, addr + 1,
                                                             pkt.data[i * 2 +
                                                                      1]);
                        }
@@ -352,7 +352,7 @@ static u8 fix_header(struct _adapter *padapter, u8 header, u16 header_addr)
        return ret;
 }
 
-u8 r8712_efuse_pg_packet_write(struct _adapter *padapter, const u8 offset,
+u8 r8712_efuse_pg_packet_write(struct _adapter *adapter, const u8 offset,
                               const u8 word_en, const u8 *data)
 {
        u8 pg_header = 0;
@@ -363,7 +363,7 @@ u8 r8712_efuse_pg_packet_write(struct _adapter *padapter, const u8 offset,
        u8 bResult = true;
 
        /* check if E-Fuse Clock Enable and E-Fuse Clock is 40M */
-       efuse_data = r8712_read8(padapter, EFUSE_CLK_CTRL);
+       efuse_data = r8712_read8(adapter, EFUSE_CLK_CTRL);
        if (efuse_data != 0x03)
                return false;
        pg_header = MAKE_EFUSE_HEADER(offset, word_en);
@@ -371,15 +371,15 @@ u8 r8712_efuse_pg_packet_write(struct _adapter *padapter, const u8 offset,
        repeat_times = 0;
        efuse_addr = 0;
        while (efuse_addr < efuse_available_max_size) {
-               curr_size = r8712_efuse_get_current_size(padapter);
+               curr_size = r8712_efuse_get_current_size(adapter);
                if ((curr_size + 1 + target_word_cnts * 2) >
                     efuse_available_max_size)
                        return false; /*target_word_cnts + pg header(1 byte)*/
                efuse_addr = curr_size; /* current size is also the last addr*/
-               efuse_one_byte_write(padapter, efuse_addr, pg_header); /*hdr*/
+               efuse_one_byte_write(adapter, efuse_addr, pg_header); /*hdr*/
                sub_repeat = 0;
                /* check if what we read is what we write */
-               while (!efuse_one_byte_read(padapter, efuse_addr,
+               while (!efuse_one_byte_read(adapter, efuse_addr,
                                            &efuse_data)) {
                        if (++sub_repeat > _REPEAT_THRESHOLD_) {
                                bResult = false; /* continue to blind write */
@@ -394,10 +394,10 @@ u8 r8712_efuse_pg_packet_write(struct _adapter *padapter, const u8 offset,
                        /* go to next address */
                        efuse_addr++;
                        for (i = 0; i < target_word_cnts * 2; i++) {
-                               efuse_one_byte_write(padapter,
+                               efuse_one_byte_write(adapter,
                                                     efuse_addr + i,
                                                     *(data + i));
-                               if (!efuse_one_byte_read(padapter,
+                               if (!efuse_one_byte_read(adapter,
                                                         efuse_addr + i,
                                                         &efuse_data))
                                        bResult = false;
@@ -411,7 +411,7 @@ u8 r8712_efuse_pg_packet_write(struct _adapter *padapter, const u8 offset,
                if (efuse_data == 0xFF)
                        return bResult; /* nothing damaged. */
                /* call rescue procedure */
-               if (!fix_header(padapter, efuse_data, efuse_addr))
+               if (!fix_header(adapter, efuse_data, efuse_addr))
                        return false; /* rescue fail */
 
                if (++repeat_times > _REPEAT_THRESHOLD_) /* fail */
@@ -421,7 +421,7 @@ u8 r8712_efuse_pg_packet_write(struct _adapter *padapter, const u8 offset,
        return bResult;
 }
 
-u8 r8712_efuse_access(struct _adapter *padapter, u8 bRead, u16 start_addr,
+u8 r8712_efuse_access(struct _adapter *adapter, u8 bRead, u16 start_addr,
                      u16 cnts, u8 *data)
 {
        int i;
@@ -432,7 +432,7 @@ u8 r8712_efuse_access(struct _adapter *padapter, u8 bRead, u16 start_addr,
        if (!bRead && ((start_addr + cnts) >
           efuse_available_max_size))
                return false;
-       if (!bRead && !r8712_efuse_reg_init(padapter))
+       if (!bRead && !r8712_efuse_reg_init(adapter))
                return false;
        /* -----------------e-fuse one byte read / write ---------------------*/
        for (i = 0; i < cnts; i++) {
@@ -440,17 +440,17 @@ u8 r8712_efuse_access(struct _adapter *padapter, u8 bRead, u16 start_addr,
                        res = false;
                        break;
                }
-               res = efuse_one_byte_rw(padapter, bRead, start_addr + i,
+               res = efuse_one_byte_rw(adapter, bRead, start_addr + i,
                                        data + i);
                if (!bRead && !res)
                        break;
        }
        if (!bRead)
-               r8712_efuse_reg_uninit(padapter);
+               r8712_efuse_reg_uninit(adapter);
        return res;
 }
 
-u8 r8712_efuse_map_read(struct _adapter *padapter, u16 addr, u16 cnts, u8 *data)
+u8 r8712_efuse_map_read(struct _adapter *adapter, u16 addr, u16 cnts, u8 *data)
 {
        u8 offset, ret = true;
        u8 pktdata[PGPKT_DATA_SIZE];
@@ -458,13 +458,13 @@ u8 r8712_efuse_map_read(struct _adapter *padapter, u16 addr, u16 cnts, u8 *data)
 
        if ((addr + cnts) > EFUSE_MAP_MAX_SIZE)
                return false;
-       if (efuse_is_empty(padapter, &offset) && offset) {
+       if (efuse_is_empty(adapter, &offset) && offset) {
                for (i = 0; i < cnts; i++)
                        data[i] = 0xFF;
                return ret;
        }
        offset = (addr >> 3) & 0xF;
-       ret = r8712_efuse_pg_packet_read(padapter, offset, pktdata);
+       ret = r8712_efuse_pg_packet_read(adapter, offset, pktdata);
        i = addr & 0x7; /* pktdata index */
        idx = 0;        /* data index */
 
@@ -475,14 +475,14 @@ u8 r8712_efuse_map_read(struct _adapter *padapter, u16 addr, u16 cnts, u8 *data)
                                return ret;
                }
                offset++;
-               if (!r8712_efuse_pg_packet_read(padapter, offset, pktdata))
+               if (!r8712_efuse_pg_packet_read(adapter, offset, pktdata))
                        ret = false;
                i = 0;
        } while (1);
        return ret;
 }
 
-u8 r8712_efuse_map_write(struct _adapter *padapter, u16 addr, u16 cnts,
+u8 r8712_efuse_map_write(struct _adapter *adapter, u16 addr, u16 cnts,
                         u8 *data)
 {
        u8 offset, word_en, empty;
@@ -492,10 +492,10 @@ u8 r8712_efuse_map_write(struct _adapter *padapter, u16 addr, u16 cnts,
        if ((addr + cnts) > EFUSE_MAP_MAX_SIZE)
                return false;
        /* check if E-Fuse Clock Enable and E-Fuse Clock is 40M */
-       empty = r8712_read8(padapter, EFUSE_CLK_CTRL);
+       empty = r8712_read8(adapter, EFUSE_CLK_CTRL);
        if (empty != 0x03)
                return false;
-       if (efuse_is_empty(padapter, &empty)) {
+       if (efuse_is_empty(adapter, &empty)) {
                if (empty)
                        memset(pktdata, 0xFF, PGPKT_DATA_SIZE);
        } else {
@@ -503,7 +503,7 @@ u8 r8712_efuse_map_write(struct _adapter *padapter, u16 addr, u16 cnts,
        }
        offset = (addr >> 3) & 0xF;
        if (!empty)
-               if (!r8712_efuse_pg_packet_read(padapter, offset, pktdata))
+               if (!r8712_efuse_pg_packet_read(adapter, offset, pktdata))
                        return false;
        word_en = 0xF;
        memset(newdata, 0xFF, PGPKT_DATA_SIZE);
@@ -546,14 +546,14 @@ u8 r8712_efuse_map_write(struct _adapter *padapter, u16 addr, u16 cnts,
                }
 
                if (word_en != 0xF)
-                       if (!r8712_efuse_pg_packet_write(padapter, offset,
+                       if (!r8712_efuse_pg_packet_write(adapter, offset,
                                                         word_en, newdata))
                                return false;
                if (idx == cnts)
                        break;
                offset++;
                if (!empty)
-                       if (!r8712_efuse_pg_packet_read(padapter, offset,
+                       if (!r8712_efuse_pg_packet_read(adapter, offset,
                                                        pktdata))
                                return false;
                i = 0;
index 7574a4b569a4ddb943c97db33548d59854150eb3..307b0e2929761fd932b428012c8034b179eeaaf1 100644 (file)
@@ -419,7 +419,7 @@ static void update_txdesc(struct xmit_frame *pxmitframe, uint *pmem, int sz)
        struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 #endif
        u8 blnSetTxDescOffset;
-       sint bmcst = IS_MCAST(pattrib->ra);
+       bool bmcst = is_multicast_ether_addr(pattrib->ra);
        struct ht_priv *phtpriv = &pmlmepriv->htpriv;
        struct tx_desc txdesc_mp;
 
index 05a78ac24987c6d74e5171c1c7fe57b8c032dd49..26b618008fcfe731e77bb2b0e8ced6eb4346991e 100644 (file)
@@ -43,7 +43,7 @@
  * No irqsave is necessary.
  */
 
-static sint _init_cmd_priv(struct cmd_priv *pcmdpriv)
+int r8712_init_cmd_priv(struct cmd_priv *pcmdpriv)
 {
        init_completion(&pcmdpriv->cmd_queue_comp);
        init_completion(&pcmdpriv->terminate_cmdthread_comp);
@@ -55,7 +55,7 @@ static sint _init_cmd_priv(struct cmd_priv *pcmdpriv)
        pcmdpriv->cmd_allocated_buf = kmalloc(MAX_CMDSZ + CMDBUFF_ALIGN_SZ,
                                              GFP_ATOMIC);
        if (!pcmdpriv->cmd_allocated_buf)
-               return _FAIL;
+               return -ENOMEM;
        pcmdpriv->cmd_buf = pcmdpriv->cmd_allocated_buf  +  CMDBUFF_ALIGN_SZ -
                            ((addr_t)(pcmdpriv->cmd_allocated_buf) &
                            (CMDBUFF_ALIGN_SZ - 1));
@@ -63,36 +63,36 @@ static sint _init_cmd_priv(struct cmd_priv *pcmdpriv)
        if (!pcmdpriv->rsp_allocated_buf) {
                kfree(pcmdpriv->cmd_allocated_buf);
                pcmdpriv->cmd_allocated_buf = NULL;
-               return _FAIL;
+               return -ENOMEM;
        }
        pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf  +  4 -
                            ((addr_t)(pcmdpriv->rsp_allocated_buf) & 3);
        pcmdpriv->cmd_issued_cnt = 0;
        pcmdpriv->cmd_done_cnt = 0;
        pcmdpriv->rsp_cnt = 0;
-       return _SUCCESS;
+       return 0;
 }
 
-static sint _init_evt_priv(struct evt_priv *pevtpriv)
+int r8712_init_evt_priv(struct evt_priv *pevtpriv)
 {
        /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
        pevtpriv->event_seq = 0;
        pevtpriv->evt_allocated_buf = kmalloc(MAX_EVTSZ + 4, GFP_ATOMIC);
 
        if (!pevtpriv->evt_allocated_buf)
-               return _FAIL;
+               return -ENOMEM;
        pevtpriv->evt_buf = pevtpriv->evt_allocated_buf  +  4 -
                            ((addr_t)(pevtpriv->evt_allocated_buf) & 3);
        pevtpriv->evt_done_cnt = 0;
-       return _SUCCESS;
+       return 0;
 }
 
-static void _free_evt_priv(struct evt_priv *pevtpriv)
+void r8712_free_evt_priv(struct evt_priv *pevtpriv)
 {
        kfree(pevtpriv->evt_allocated_buf);
 }
 
-static void _free_cmd_priv(struct cmd_priv *pcmdpriv)
+void r8712_free_cmd_priv(struct cmd_priv *pcmdpriv)
 {
        if (pcmdpriv) {
                kfree(pcmdpriv->cmd_allocated_buf);
@@ -103,26 +103,30 @@ static void _free_cmd_priv(struct cmd_priv *pcmdpriv)
 /*
  * Calling Context:
  *
- * _enqueue_cmd can only be called between kernel thread,
+ * r8712_enqueue_cmd can only be called between kernel thread,
  * since only spin_lock is used.
  *
  * ISR/Call-Back functions can't call this sub-function.
  *
  */
 
-static sint _enqueue_cmd(struct  __queue *queue, struct cmd_obj *obj)
+void r8712_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *obj)
 {
+       struct __queue *queue;
        unsigned long irqL;
 
+       if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag)
+               return;
        if (!obj)
-               return _SUCCESS;
+               return;
+       queue = &pcmdpriv->cmd_queue;
        spin_lock_irqsave(&queue->lock, irqL);
        list_add_tail(&obj->list, &queue->queue);
        spin_unlock_irqrestore(&queue->lock, irqL);
-       return _SUCCESS;
+       complete(&pcmdpriv->cmd_queue_comp);
 }
 
-static struct cmd_obj *_dequeue_cmd(struct  __queue *queue)
+struct cmd_obj *r8712_dequeue_cmd(struct  __queue *queue)
 {
        unsigned long irqL;
        struct cmd_obj *obj;
@@ -136,57 +140,20 @@ static struct cmd_obj *_dequeue_cmd(struct  __queue *queue)
        return obj;
 }
 
-u32 r8712_init_cmd_priv(struct cmd_priv *pcmdpriv)
-{
-       return _init_cmd_priv(pcmdpriv);
-}
-
-u32 r8712_init_evt_priv(struct evt_priv *pevtpriv)
-{
-       return _init_evt_priv(pevtpriv);
-}
-
-void r8712_free_evt_priv(struct evt_priv *pevtpriv)
-{
-       _free_evt_priv(pevtpriv);
-}
-
-void r8712_free_cmd_priv(struct cmd_priv *pcmdpriv)
-{
-       _free_cmd_priv(pcmdpriv);
-}
-
-u32 r8712_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *obj)
-{
-       int res;
-
-       if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag)
-               return _FAIL;
-       res = _enqueue_cmd(&pcmdpriv->cmd_queue, obj);
-       complete(&pcmdpriv->cmd_queue_comp);
-       return res;
-}
-
-u32 r8712_enqueue_cmd_ex(struct cmd_priv *pcmdpriv, struct cmd_obj *obj)
+void r8712_enqueue_cmd_ex(struct cmd_priv *pcmdpriv, struct cmd_obj *obj)
 {
        unsigned long irqL;
        struct  __queue *queue;
 
        if (!obj)
-               return _SUCCESS;
+               return;
        if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag)
-               return _FAIL;
+               return;
        queue = &pcmdpriv->cmd_queue;
        spin_lock_irqsave(&queue->lock, irqL);
        list_add_tail(&obj->list, &queue->queue);
        spin_unlock_irqrestore(&queue->lock, irqL);
        complete(&pcmdpriv->cmd_queue_comp);
-       return _SUCCESS;
-}
-
-struct cmd_obj *r8712_dequeue_cmd(struct  __queue *queue)
-{
-       return _dequeue_cmd(queue);
 }
 
 void r8712_free_cmd_obj(struct cmd_obj *pcmd)
@@ -242,7 +209,7 @@ u8 r8712_sitesurvey_cmd(struct _adapter *padapter,
        return _SUCCESS;
 }
 
-u8 r8712_setdatarate_cmd(struct _adapter *padapter, u8 *rateset)
+int r8712_setdatarate_cmd(struct _adapter *padapter, u8 *rateset)
 {
        struct cmd_obj          *ph2c;
        struct setdatarate_parm *pbsetdataratepara;
@@ -250,21 +217,21 @@ u8 r8712_setdatarate_cmd(struct _adapter *padapter, u8 *rateset)
 
        ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
        if (!ph2c)
-               return _FAIL;
+               return -ENOMEM;
        pbsetdataratepara = kmalloc(sizeof(*pbsetdataratepara), GFP_ATOMIC);
        if (!pbsetdataratepara) {
                kfree(ph2c);
-               return _FAIL;
+               return -ENOMEM;
        }
        init_h2fwcmd_w_parm_no_rsp(ph2c, pbsetdataratepara,
                                   GEN_CMD_CODE(_SetDataRate));
        pbsetdataratepara->mac_id = 5;
        memcpy(pbsetdataratepara->datarates, rateset, NumRates);
        r8712_enqueue_cmd(pcmdpriv, ph2c);
-       return _SUCCESS;
+       return 0;
 }
 
-u8 r8712_set_chplan_cmd(struct _adapter *padapter, int chplan)
+void r8712_set_chplan_cmd(struct _adapter *padapter, int chplan)
 {
        struct cmd_obj *ph2c;
        struct SetChannelPlan_param *psetchplanpara;
@@ -272,81 +239,19 @@ u8 r8712_set_chplan_cmd(struct _adapter *padapter, int chplan)
 
        ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
        if (!ph2c)
-               return _FAIL;
+               return;
        psetchplanpara = kmalloc(sizeof(*psetchplanpara), GFP_ATOMIC);
        if (!psetchplanpara) {
                kfree(ph2c);
-               return _FAIL;
+               return;
        }
        init_h2fwcmd_w_parm_no_rsp(ph2c, psetchplanpara,
                                GEN_CMD_CODE(_SetChannelPlan));
        psetchplanpara->ChannelPlan = chplan;
        r8712_enqueue_cmd(pcmdpriv, ph2c);
-       return _SUCCESS;
-}
-
-u8 r8712_setbasicrate_cmd(struct _adapter *padapter, u8 *rateset)
-{
-       struct cmd_obj *ph2c;
-       struct setbasicrate_parm *pssetbasicratepara;
-       struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
-
-       ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
-       if (!ph2c)
-               return _FAIL;
-       pssetbasicratepara = kmalloc(sizeof(*pssetbasicratepara), GFP_ATOMIC);
-       if (!pssetbasicratepara) {
-               kfree(ph2c);
-               return _FAIL;
-       }
-       init_h2fwcmd_w_parm_no_rsp(ph2c, pssetbasicratepara,
-               _SetBasicRate_CMD_);
-       memcpy(pssetbasicratepara->basicrates, rateset, NumRates);
-       r8712_enqueue_cmd(pcmdpriv, ph2c);
-       return _SUCCESS;
-}
-
-u8 r8712_setfwdig_cmd(struct _adapter *padapter, u8 type)
-{
-       struct cmd_obj *ph2c;
-       struct writePTM_parm *pwriteptmparm;
-       struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
-
-       ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
-       if (!ph2c)
-               return _FAIL;
-       pwriteptmparm = kmalloc(sizeof(*pwriteptmparm), GFP_ATOMIC);
-       if (!pwriteptmparm) {
-               kfree(ph2c);
-               return _FAIL;
-       }
-       init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteptmparm, GEN_CMD_CODE(_SetDIG));
-       pwriteptmparm->type = type;
-       r8712_enqueue_cmd(pcmdpriv, ph2c);
-       return _SUCCESS;
-}
-
-u8 r8712_setfwra_cmd(struct _adapter *padapter, u8 type)
-{
-       struct cmd_obj *ph2c;
-       struct writePTM_parm *pwriteptmparm;
-       struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
-
-       ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
-       if (!ph2c)
-               return _FAIL;
-       pwriteptmparm = kmalloc(sizeof(*pwriteptmparm), GFP_ATOMIC);
-       if (!pwriteptmparm) {
-               kfree(ph2c);
-               return _FAIL;
-       }
-       init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteptmparm, GEN_CMD_CODE(_SetRA));
-       pwriteptmparm->type = type;
-       r8712_enqueue_cmd(pcmdpriv, ph2c);
-       return _SUCCESS;
 }
 
-u8 r8712_setrfreg_cmd(struct _adapter  *padapter, u8 offset, u32 val)
+int r8712_setrfreg_cmd(struct _adapter  *padapter, u8 offset, u32 val)
 {
        struct cmd_obj *ph2c;
        struct writeRF_parm *pwriterfparm;
@@ -354,20 +259,20 @@ u8 r8712_setrfreg_cmd(struct _adapter  *padapter, u8 offset, u32 val)
 
        ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
        if (!ph2c)
-               return _FAIL;
+               return -ENOMEM;
        pwriterfparm = kmalloc(sizeof(*pwriterfparm), GFP_ATOMIC);
        if (!pwriterfparm) {
                kfree(ph2c);
-               return _FAIL;
+               return -ENOMEM;
        }
        init_h2fwcmd_w_parm_no_rsp(ph2c, pwriterfparm, GEN_CMD_CODE(_SetRFReg));
        pwriterfparm->offset = offset;
        pwriterfparm->value = val;
        r8712_enqueue_cmd(pcmdpriv, ph2c);
-       return _SUCCESS;
+       return 0;
 }
 
-u8 r8712_getrfreg_cmd(struct _adapter *padapter, u8 offset, u8 *pval)
+int r8712_getrfreg_cmd(struct _adapter *padapter, u8 offset, u8 *pval)
 {
        struct cmd_obj *ph2c;
        struct readRF_parm *prdrfparm;
@@ -375,11 +280,11 @@ u8 r8712_getrfreg_cmd(struct _adapter *padapter, u8 offset, u8 *pval)
 
        ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
        if (!ph2c)
-               return _FAIL;
+               return -ENOMEM;
        prdrfparm = kmalloc(sizeof(*prdrfparm), GFP_ATOMIC);
        if (!prdrfparm) {
                kfree(ph2c);
-               return _FAIL;
+               return -ENOMEM;
        }
        INIT_LIST_HEAD(&ph2c->list);
        ph2c->cmdcode = GEN_CMD_CODE(_GetRFReg);
@@ -389,7 +294,7 @@ u8 r8712_getrfreg_cmd(struct _adapter *padapter, u8 offset, u8 *pval)
        ph2c->rspsz = sizeof(struct readRF_rsp);
        prdrfparm->offset = offset;
        r8712_enqueue_cmd(pcmdpriv, ph2c);
-       return _SUCCESS;
+       return 0;
 }
 
 void r8712_getbbrfreg_cmdrsp_callback(struct _adapter *padapter,
@@ -409,7 +314,7 @@ void r8712_readtssi_cmdrsp_callback(struct _adapter *padapter,
        padapter->mppriv.workparam.bcompleted = true;
 }
 
-u8 r8712_createbss_cmd(struct _adapter *padapter)
+int r8712_createbss_cmd(struct _adapter *padapter)
 {
        struct cmd_obj *pcmd;
        struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
@@ -419,7 +324,7 @@ u8 r8712_createbss_cmd(struct _adapter *padapter)
        padapter->ledpriv.LedControlHandler(padapter, LED_CTL_START_TO_LINK);
        pcmd = kmalloc(sizeof(*pcmd), GFP_ATOMIC);
        if (!pcmd)
-               return _FAIL;
+               return -ENOMEM;
        INIT_LIST_HEAD(&pcmd->list);
        pcmd->cmdcode = _CreateBss_CMD_;
        pcmd->parmbuf = (unsigned char *)pdev_network;
@@ -431,10 +336,10 @@ u8 r8712_createbss_cmd(struct _adapter *padapter)
        pdev_network->IELength = pdev_network->IELength;
        pdev_network->Ssid.SsidLength = pdev_network->Ssid.SsidLength;
        r8712_enqueue_cmd(pcmdpriv, pcmd);
-       return _SUCCESS;
+       return 0;
 }
 
-u8 r8712_joinbss_cmd(struct _adapter  *padapter, struct wlan_network *pnetwork)
+int r8712_joinbss_cmd(struct _adapter  *padapter, struct wlan_network *pnetwork)
 {
        struct wlan_bssid_ex *psecnetwork;
        struct cmd_obj          *pcmd;
@@ -449,7 +354,7 @@ u8 r8712_joinbss_cmd(struct _adapter  *padapter, struct wlan_network *pnetwork)
        padapter->ledpriv.LedControlHandler(padapter, LED_CTL_START_TO_LINK);
        pcmd = kmalloc(sizeof(*pcmd), GFP_ATOMIC);
        if (!pcmd)
-               return _FAIL;
+               return -ENOMEM;
 
        /* for hidden ap to set fw_state here */
        if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_ADHOC_STATE) !=
@@ -468,10 +373,6 @@ u8 r8712_joinbss_cmd(struct _adapter  *padapter, struct wlan_network *pnetwork)
                }
        }
        psecnetwork = &psecuritypriv->sec_bss;
-       if (!psecnetwork) {
-               kfree(pcmd);
-               return _FAIL;
-       }
        memcpy(psecnetwork, &pnetwork->network, sizeof(*psecnetwork));
        psecuritypriv->authenticator_ie[0] = (unsigned char)
                                             psecnetwork->IELength;
@@ -570,10 +471,10 @@ u8 r8712_joinbss_cmd(struct _adapter  *padapter, struct wlan_network *pnetwork)
        pcmd->rsp = NULL;
        pcmd->rspsz = 0;
        r8712_enqueue_cmd(pcmdpriv, pcmd);
-       return _SUCCESS;
+       return 0;
 }
 
-u8 r8712_disassoc_cmd(struct _adapter *padapter) /* for sta_mode */
+void r8712_disassoc_cmd(struct _adapter *padapter) /* for sta_mode */
 {
        struct cmd_obj *pdisconnect_cmd;
        struct disconnect_parm *pdisconnect;
@@ -581,19 +482,18 @@ u8 r8712_disassoc_cmd(struct _adapter *padapter) /* for sta_mode */
 
        pdisconnect_cmd = kmalloc(sizeof(*pdisconnect_cmd), GFP_ATOMIC);
        if (!pdisconnect_cmd)
-               return _FAIL;
+               return;
        pdisconnect = kmalloc(sizeof(*pdisconnect), GFP_ATOMIC);
        if (!pdisconnect) {
                kfree(pdisconnect_cmd);
-               return _FAIL;
+               return;
        }
        init_h2fwcmd_w_parm_no_rsp(pdisconnect_cmd, pdisconnect,
                                   _DisConnect_CMD_);
        r8712_enqueue_cmd(pcmdpriv, pdisconnect_cmd);
-       return _SUCCESS;
 }
 
-u8 r8712_setopmode_cmd(struct _adapter *padapter,
+void r8712_setopmode_cmd(struct _adapter *padapter,
                 enum NDIS_802_11_NETWORK_INFRASTRUCTURE networktype)
 {
        struct cmd_obj *ph2c;
@@ -603,19 +503,18 @@ u8 r8712_setopmode_cmd(struct _adapter *padapter,
 
        ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
        if (!ph2c)
-               return _FAIL;
+               return;
        psetop = kmalloc(sizeof(*psetop), GFP_ATOMIC);
        if (!psetop) {
                kfree(ph2c);
-               return _FAIL;
+               return;
        }
        init_h2fwcmd_w_parm_no_rsp(ph2c, psetop, _SetOpMode_CMD_);
        psetop->mode = (u8)networktype;
        r8712_enqueue_cmd(pcmdpriv, ph2c);
-       return _SUCCESS;
 }
 
-u8 r8712_setstakey_cmd(struct _adapter *padapter, u8 *psta, u8 unicast_key)
+void r8712_setstakey_cmd(struct _adapter *padapter, u8 *psta, u8 unicast_key)
 {
        struct cmd_obj *ph2c;
        struct set_stakey_parm *psetstakey_para;
@@ -627,17 +526,17 @@ u8 r8712_setstakey_cmd(struct _adapter *padapter, u8 *psta, u8 unicast_key)
 
        ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
        if (!ph2c)
-               return _FAIL;
+               return;
        psetstakey_para = kmalloc(sizeof(*psetstakey_para), GFP_ATOMIC);
        if (!psetstakey_para) {
                kfree(ph2c);
-               return _FAIL;
+               return;
        }
        psetstakey_rsp = kmalloc(sizeof(*psetstakey_rsp), GFP_ATOMIC);
        if (!psetstakey_rsp) {
                kfree(ph2c);
                kfree(psetstakey_para);
-               return _FAIL;
+               return;
        }
        init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
        ph2c->rsp = (u8 *) psetstakey_rsp;
@@ -656,53 +555,9 @@ u8 r8712_setstakey_cmd(struct _adapter *padapter, u8 *psta, u8 unicast_key)
                        &psecuritypriv->XGrpKey[
                        psecuritypriv->XGrpKeyid - 1]. skey, 16);
        r8712_enqueue_cmd(pcmdpriv, ph2c);
-       return _SUCCESS;
-}
-
-u8 r8712_setrfintfs_cmd(struct _adapter *padapter, u8 mode)
-{
-       struct cmd_obj *ph2c;
-       struct setrfintfs_parm *psetrfintfsparm;
-       struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
-
-       ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
-       if (!ph2c)
-               return _FAIL;
-       psetrfintfsparm = kmalloc(sizeof(*psetrfintfsparm), GFP_ATOMIC);
-       if (!psetrfintfsparm) {
-               kfree(ph2c);
-               return _FAIL;
-       }
-       init_h2fwcmd_w_parm_no_rsp(ph2c, psetrfintfsparm,
-                                  GEN_CMD_CODE(_SetRFIntFs));
-       psetrfintfsparm->rfintfs = mode;
-       r8712_enqueue_cmd(pcmdpriv, ph2c);
-       return _SUCCESS;
-}
-
-u8 r8712_setrttbl_cmd(struct _adapter *padapter,
-                     struct setratable_parm *prate_table)
-{
-       struct cmd_obj *ph2c;
-       struct setratable_parm *psetrttblparm;
-       struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
-
-       ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
-       if (!ph2c)
-               return _FAIL;
-       psetrttblparm = kmalloc(sizeof(*psetrttblparm), GFP_ATOMIC);
-       if (!psetrttblparm) {
-               kfree(ph2c);
-               return _FAIL;
-       }
-       init_h2fwcmd_w_parm_no_rsp(ph2c, psetrttblparm,
-                                  GEN_CMD_CODE(_SetRaTable));
-       memcpy(psetrttblparm, prate_table, sizeof(struct setratable_parm));
-       r8712_enqueue_cmd(pcmdpriv, ph2c);
-       return _SUCCESS;
 }
 
-u8 r8712_setMacAddr_cmd(struct _adapter *padapter, u8 *mac_addr)
+void r8712_setMacAddr_cmd(struct _adapter *padapter, u8 *mac_addr)
 {
        struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
        struct cmd_obj *ph2c;
@@ -710,49 +565,19 @@ u8 r8712_setMacAddr_cmd(struct _adapter *padapter, u8 *mac_addr)
 
        ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
        if (!ph2c)
-               return _FAIL;
+               return;
        psetMacAddr_para = kmalloc(sizeof(*psetMacAddr_para), GFP_ATOMIC);
        if (!psetMacAddr_para) {
                kfree(ph2c);
-               return _FAIL;
+               return;
        }
        init_h2fwcmd_w_parm_no_rsp(ph2c, psetMacAddr_para,
                                   _SetMacAddress_CMD_);
        ether_addr_copy(psetMacAddr_para->MacAddr, mac_addr);
        r8712_enqueue_cmd(pcmdpriv, ph2c);
-       return _SUCCESS;
-}
-
-u8 r8712_setassocsta_cmd(struct _adapter *padapter, u8 *mac_addr)
-{
-       struct cmd_priv                 *pcmdpriv = &padapter->cmdpriv;
-       struct cmd_obj                  *ph2c;
-       struct set_assocsta_parm        *psetassocsta_para;
-       struct set_assocsta_rsp         *psetassocsta_rsp = NULL;
-
-       ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
-       if (!ph2c)
-               return _FAIL;
-       psetassocsta_para = kmalloc(sizeof(*psetassocsta_para), GFP_ATOMIC);
-       if (!psetassocsta_para) {
-               kfree(ph2c);
-               return _FAIL;
-       }
-       psetassocsta_rsp = kmalloc(sizeof(*psetassocsta_rsp), GFP_ATOMIC);
-       if (!psetassocsta_rsp) {
-               kfree(ph2c);
-               kfree(psetassocsta_para);
-               return _FAIL;
-       }
-       init_h2fwcmd_w_parm_no_rsp(ph2c, psetassocsta_para, _SetAssocSta_CMD_);
-       ph2c->rsp = (u8 *) psetassocsta_rsp;
-       ph2c->rspsz = sizeof(struct set_assocsta_rsp);
-       ether_addr_copy(psetassocsta_para->addr, mac_addr);
-       r8712_enqueue_cmd(pcmdpriv, ph2c);
-       return _SUCCESS;
 }
 
-u8 r8712_addbareq_cmd(struct _adapter *padapter, u8 tid)
+void r8712_addbareq_cmd(struct _adapter *padapter, u8 tid)
 {
        struct cmd_priv         *pcmdpriv = &padapter->cmdpriv;
        struct cmd_obj          *ph2c;
@@ -760,20 +585,19 @@ u8 r8712_addbareq_cmd(struct _adapter *padapter, u8 tid)
 
        ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
        if (!ph2c)
-               return _FAIL;
+               return;
        paddbareq_parm = kmalloc(sizeof(*paddbareq_parm), GFP_ATOMIC);
        if (!paddbareq_parm) {
                kfree(ph2c);
-               return _FAIL;
+               return;
        }
        paddbareq_parm->tid = tid;
        init_h2fwcmd_w_parm_no_rsp(ph2c, paddbareq_parm,
                                   GEN_CMD_CODE(_AddBAReq));
        r8712_enqueue_cmd_ex(pcmdpriv, ph2c);
-       return _SUCCESS;
 }
 
-u8 r8712_wdg_wk_cmd(struct _adapter *padapter)
+void r8712_wdg_wk_cmd(struct _adapter *padapter)
 {
        struct cmd_obj *ph2c;
        struct drvint_cmd_parm  *pdrvintcmd_param;
@@ -781,18 +605,17 @@ u8 r8712_wdg_wk_cmd(struct _adapter *padapter)
 
        ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
        if (!ph2c)
-               return _FAIL;
+               return;
        pdrvintcmd_param = kmalloc(sizeof(*pdrvintcmd_param), GFP_ATOMIC);
        if (!pdrvintcmd_param) {
                kfree(ph2c);
-               return _FAIL;
+               return;
        }
        pdrvintcmd_param->i_cid = WDG_WK_CID;
        pdrvintcmd_param->sz = 0;
        pdrvintcmd_param->pbuf = NULL;
        init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvintcmd_param, _DRV_INT_CMD_);
        r8712_enqueue_cmd_ex(pcmdpriv, ph2c);
-       return _SUCCESS;
 }
 
 void r8712_survey_cmd_callback(struct _adapter *padapter, struct cmd_obj *pcmd)
@@ -949,7 +772,7 @@ void r8712_setassocsta_cmdrsp_callback(struct _adapter *padapter,
        r8712_free_cmd_obj(pcmd);
 }
 
-u8 r8712_disconnectCtrlEx_cmd(struct _adapter *adapter, u32 enableDrvCtrl,
+void r8712_disconnectCtrlEx_cmd(struct _adapter *adapter, u32 enableDrvCtrl,
                        u32 tryPktCnt, u32 tryPktInterval, u32 firstStageTO)
 {
        struct cmd_obj *ph2c;
@@ -958,11 +781,11 @@ u8 r8712_disconnectCtrlEx_cmd(struct _adapter *adapter, u32 enableDrvCtrl,
 
        ph2c = kmalloc(sizeof(*ph2c), GFP_ATOMIC);
        if (!ph2c)
-               return _FAIL;
+               return;
        param = kzalloc(sizeof(*param), GFP_ATOMIC);
        if (!param) {
                kfree(ph2c);
-               return _FAIL;
+               return;
        }
 
        param->EnableDrvCtrl = (unsigned char)enableDrvCtrl;
@@ -973,5 +796,4 @@ u8 r8712_disconnectCtrlEx_cmd(struct _adapter *adapter, u32 enableDrvCtrl,
        init_h2fwcmd_w_parm_no_rsp(ph2c, param,
                                GEN_CMD_CODE(_DisconnectCtrlEx));
        r8712_enqueue_cmd(pcmdpriv, ph2c);
-       return _SUCCESS;
 }
index 262984c58efb9c6aa19dcc5b9688c9dea763d8be..98d7fbfce1a57de3ab1ec1ac92d62e8006def74f 100644 (file)
@@ -79,14 +79,14 @@ do {\
        pcmd->rspsz = 0;\
 } while (0)
 
-u32 r8712_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *obj);
-u32 r8712_enqueue_cmd_ex(struct cmd_priv *pcmdpriv, struct cmd_obj *obj);
+void r8712_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *obj);
+void r8712_enqueue_cmd_ex(struct cmd_priv *pcmdpriv, struct cmd_obj *obj);
 struct cmd_obj *r8712_dequeue_cmd(struct  __queue *queue);
 void r8712_free_cmd_obj(struct cmd_obj *pcmd);
 int r8712_cmd_thread(void *context);
-u32 r8712_init_cmd_priv(struct cmd_priv *pcmdpriv);
+int r8712_init_cmd_priv(struct cmd_priv *pcmdpriv);
 void r8712_free_cmd_priv(struct cmd_priv *pcmdpriv);
-u32 r8712_init_evt_priv(struct evt_priv *pevtpriv);
+int r8712_init_evt_priv(struct evt_priv *pevtpriv);
 void r8712_free_evt_priv(struct evt_priv *pevtpriv);
 
 enum rtl871x_drvint_cid {
@@ -708,29 +708,22 @@ struct DisconnectCtrlEx_param {
 #define H2C_CMD_OVERFLOW               0x06
 #define H2C_RESERVED                   0x07
 
-u8 r8712_setMacAddr_cmd(struct _adapter *padapter, u8 *mac_addr);
-u8 r8712_setassocsta_cmd(struct _adapter *padapter, u8 *mac_addr);
+void r8712_setMacAddr_cmd(struct _adapter *padapter, u8 *mac_addr);
 u8 r8712_sitesurvey_cmd(struct _adapter *padapter,
                        struct ndis_802_11_ssid *pssid);
-u8 r8712_createbss_cmd(struct _adapter *padapter);
-u8 r8712_setstakey_cmd(struct _adapter *padapter, u8 *psta, u8 unicast_key);
-u8 r8712_joinbss_cmd(struct _adapter *padapter,
-                    struct wlan_network *pnetwork);
-u8 r8712_disassoc_cmd(struct _adapter *padapter);
-u8 r8712_setopmode_cmd(struct _adapter *padapter,
+int r8712_createbss_cmd(struct _adapter *padapter);
+void r8712_setstakey_cmd(struct _adapter *padapter, u8 *psta, u8 unicast_key);
+int r8712_joinbss_cmd(struct _adapter *padapter,
+                     struct wlan_network *pnetwork);
+void r8712_disassoc_cmd(struct _adapter *padapter);
+void r8712_setopmode_cmd(struct _adapter *padapter,
                 enum NDIS_802_11_NETWORK_INFRASTRUCTURE networktype);
-u8 r8712_setdatarate_cmd(struct _adapter *padapter, u8 *rateset);
-u8 r8712_set_chplan_cmd(struct _adapter  *padapter, int chplan);
-u8 r8712_setbasicrate_cmd(struct _adapter *padapter, u8 *rateset);
-u8 r8712_getrfreg_cmd(struct _adapter *padapter, u8 offset, u8 *pval);
-u8 r8712_setrfintfs_cmd(struct _adapter *padapter, u8 mode);
-u8 r8712_setrfreg_cmd(struct _adapter  *padapter, u8 offset, u32 val);
-u8 r8712_setrttbl_cmd(struct _adapter  *padapter,
-                     struct setratable_parm *prate_table);
-u8 r8712_setfwdig_cmd(struct _adapter *padapter, u8 type);
-u8 r8712_setfwra_cmd(struct _adapter *padapter, u8 type);
-u8 r8712_addbareq_cmd(struct _adapter *padapter, u8 tid);
-u8 r8712_wdg_wk_cmd(struct _adapter *padapter);
+int r8712_setdatarate_cmd(struct _adapter *padapter, u8 *rateset);
+void r8712_set_chplan_cmd(struct _adapter  *padapter, int chplan);
+int r8712_getrfreg_cmd(struct _adapter *padapter, u8 offset, u8 *pval);
+int r8712_setrfreg_cmd(struct _adapter  *padapter, u8 offset, u32 val);
+void r8712_addbareq_cmd(struct _adapter *padapter, u8 tid);
+void r8712_wdg_wk_cmd(struct _adapter *padapter);
 void r8712_survey_cmd_callback(struct _adapter  *padapter,
                               struct cmd_obj *pcmd);
 void r8712_disassoc_cmd_callback(struct _adapter  *padapter,
@@ -747,7 +740,7 @@ void r8712_setstaKey_cmdrsp_callback(struct _adapter  *padapter,
                                     struct cmd_obj *pcmd);
 void r8712_setassocsta_cmdrsp_callback(struct _adapter  *padapter,
                                       struct cmd_obj *pcmd);
-u8 r8712_disconnectCtrlEx_cmd(struct _adapter *adapter, u32 enableDrvCtrl,
+void r8712_disconnectCtrlEx_cmd(struct _adapter *adapter, u32 enableDrvCtrl,
                        u32 tryPktCnt, u32 tryPktInterval, u32 firstStageTO);
 
 struct _cmd_callback {
index 0027d8eb22fa720b133c427e9c493d08b8da13ba..221bf92e1b1c3f3a2f00faf4be9b24d6708c380b 100644 (file)
@@ -150,7 +150,7 @@ void r8712_eeprom_write16(struct _adapter *padapter, u16 reg, u16 data)
        x |= _EEM1 | _EECS;
        r8712_write8(padapter, EE_9346CR, x);
        shift_out_bits(padapter, EEPROM_EWEN_OPCODE, 5);
-       if (padapter->EepromAddressSize == 8)   /*CF+ and SDIO*/
+       if (padapter->eeprom_address_size == 8) /*CF+ and SDIO*/
                shift_out_bits(padapter, 0, 6);
        else    /* USB */
                shift_out_bits(padapter, 0, 4);
@@ -165,7 +165,7 @@ void r8712_eeprom_write16(struct _adapter *padapter, u16 reg, u16 data)
         */
        shift_out_bits(padapter, EEPROM_WRITE_OPCODE, 3);
        /* select which word in the EEPROM that we are writing to. */
-       shift_out_bits(padapter, reg, padapter->EepromAddressSize);
+       shift_out_bits(padapter, reg, padapter->eeprom_address_size);
        /* write the data to the selected EEPROM word. */
        shift_out_bits(padapter, data, 16);
        if (wait_eeprom_cmd_done(padapter)) {
@@ -207,7 +207,7 @@ u16 r8712_eeprom_read16(struct _adapter *padapter, u16 reg) /*ReadEEprom*/
         * The opcode is 3bits in length, reg is 6 bits long
         */
        shift_out_bits(padapter, EEPROM_READ_OPCODE, 3);
-       shift_out_bits(padapter, reg, padapter->EepromAddressSize);
+       shift_out_bits(padapter, reg, padapter->eeprom_address_size);
        /* Now read the data (16 bits) in from the selected EEPROM word */
        data = shift_in_bits(padapter);
        eeprom_clean(padapter);
index 17dafeffd6f4f136e4f710ebc931f58f9606e790..87024d6a465e675e1cbf518f97d451cfe6978087 100644 (file)
@@ -107,13 +107,11 @@ uint r8712_alloc_io_queue(struct _adapter *adapter)
        INIT_LIST_HEAD(&pio_queue->processing);
        INIT_LIST_HEAD(&pio_queue->pending);
        spin_lock_init(&pio_queue->lock);
-       pio_queue->pallocated_free_ioreqs_buf = kmalloc(NUM_IOREQ *
+       pio_queue->pallocated_free_ioreqs_buf = kzalloc(NUM_IOREQ *
                                                (sizeof(struct io_req)) + 4,
                                                GFP_ATOMIC);
        if ((pio_queue->pallocated_free_ioreqs_buf) == NULL)
                goto alloc_io_queue_fail;
-       memset(pio_queue->pallocated_free_ioreqs_buf, 0,
-                       (NUM_IOREQ * (sizeof(struct io_req)) + 4));
        pio_queue->free_ioreqs_buf = pio_queue->pallocated_free_ioreqs_buf + 4
                        - ((addr_t)(pio_queue->pallocated_free_ioreqs_buf)
                        & 3);
index a7230c0c7b23e3b19d1c7ed5cff194fc8fa2fd5f..b08b9a191a3416971e19f9d45e7fb7bbb5f32582 100644 (file)
@@ -124,10 +124,91 @@ static inline void handle_group_key(struct ieee_param *param,
        }
 }
 
-static noinline_for_stack char *translate_scan(struct _adapter *padapter,
-                                  struct iw_request_info *info,
-                                  struct wlan_network *pnetwork,
-                                  char *start, char *stop)
+static noinline_for_stack char *translate_scan_wpa(struct iw_request_info *info,
+                                                  struct wlan_network *pnetwork,
+                                                  struct iw_event *iwe,
+                                                  char *start, char *stop)
+{
+       /* parsing WPA/WPA2 IE */
+       u8 buf[MAX_WPA_IE_LEN];
+       u8 wpa_ie[255], rsn_ie[255];
+       u16 wpa_len = 0, rsn_len = 0;
+       int n, i;
+
+       r8712_get_sec_ie(pnetwork->network.IEs,
+                        pnetwork->network.IELength, rsn_ie, &rsn_len,
+                        wpa_ie, &wpa_len);
+       if (wpa_len > 0) {
+               memset(buf, 0, MAX_WPA_IE_LEN);
+               n = sprintf(buf, "wpa_ie=");
+               for (i = 0; i < wpa_len; i++) {
+                       n += snprintf(buf + n, MAX_WPA_IE_LEN - n,
+                                               "%02x", wpa_ie[i]);
+                       if (n >= MAX_WPA_IE_LEN)
+                               break;
+               }
+               memset(iwe, 0, sizeof(*iwe));
+               iwe->cmd = IWEVCUSTOM;
+               iwe->u.data.length = (u16)strlen(buf);
+               start = iwe_stream_add_point(info, start, stop,
+                       iwe, buf);
+               memset(iwe, 0, sizeof(*iwe));
+               iwe->cmd = IWEVGENIE;
+               iwe->u.data.length = (u16)wpa_len;
+               start = iwe_stream_add_point(info, start, stop,
+                       iwe, wpa_ie);
+       }
+       if (rsn_len > 0) {
+               memset(buf, 0, MAX_WPA_IE_LEN);
+               n = sprintf(buf, "rsn_ie=");
+               for (i = 0; i < rsn_len; i++) {
+                       n += snprintf(buf + n, MAX_WPA_IE_LEN - n,
+                                               "%02x", rsn_ie[i]);
+                       if (n >= MAX_WPA_IE_LEN)
+                               break;
+               }
+               memset(iwe, 0, sizeof(*iwe));
+               iwe->cmd = IWEVCUSTOM;
+               iwe->u.data.length = strlen(buf);
+               start = iwe_stream_add_point(info, start, stop,
+                       iwe, buf);
+               memset(iwe, 0, sizeof(*iwe));
+               iwe->cmd = IWEVGENIE;
+               iwe->u.data.length = rsn_len;
+               start = iwe_stream_add_point(info, start, stop, iwe,
+                       rsn_ie);
+       }
+
+       return start;
+}
+
+static noinline_for_stack char *translate_scan_wps(struct iw_request_info *info,
+                                                  struct wlan_network *pnetwork,
+                                                  struct iw_event *iwe,
+                                                  char *start, char *stop)
+{
+       /* parsing WPS IE */
+       u8 wps_ie[512];
+       uint wps_ielen;
+
+       if (r8712_get_wps_ie(pnetwork->network.IEs,
+           pnetwork->network.IELength,
+           wps_ie, &wps_ielen)) {
+               if (wps_ielen > 2) {
+                       iwe->cmd = IWEVGENIE;
+                       iwe->u.data.length = (u16)wps_ielen;
+                       start = iwe_stream_add_point(info, start, stop,
+                               iwe, wps_ie);
+               }
+       }
+
+       return start;
+}
+
+static char *translate_scan(struct _adapter *padapter,
+                           struct iw_request_info *info,
+                           struct wlan_network *pnetwork,
+                           char *start, char *stop)
 {
        struct iw_event iwe;
        struct ieee80211_ht_cap *pht_capie;
@@ -240,73 +321,11 @@ static noinline_for_stack char *translate_scan(struct _adapter *padapter,
        /* Check if we added any event */
        if ((current_val - start) > iwe_stream_lcp_len(info))
                start = current_val;
-       /* parsing WPA/WPA2 IE */
-       {
-               u8 buf[MAX_WPA_IE_LEN];
-               u8 wpa_ie[255], rsn_ie[255];
-               u16 wpa_len = 0, rsn_len = 0;
-               int n;
-
-               r8712_get_sec_ie(pnetwork->network.IEs,
-                                pnetwork->network.IELength, rsn_ie, &rsn_len,
-                                wpa_ie, &wpa_len);
-               if (wpa_len > 0) {
-                       memset(buf, 0, MAX_WPA_IE_LEN);
-                       n = sprintf(buf, "wpa_ie=");
-                       for (i = 0; i < wpa_len; i++) {
-                               n += snprintf(buf + n, MAX_WPA_IE_LEN - n,
-                                                       "%02x", wpa_ie[i]);
-                               if (n >= MAX_WPA_IE_LEN)
-                                       break;
-                       }
-                       memset(&iwe, 0, sizeof(iwe));
-                       iwe.cmd = IWEVCUSTOM;
-                       iwe.u.data.length = (u16)strlen(buf);
-                       start = iwe_stream_add_point(info, start, stop,
-                               &iwe, buf);
-                       memset(&iwe, 0, sizeof(iwe));
-                       iwe.cmd = IWEVGENIE;
-                       iwe.u.data.length = (u16)wpa_len;
-                       start = iwe_stream_add_point(info, start, stop,
-                               &iwe, wpa_ie);
-               }
-               if (rsn_len > 0) {
-                       memset(buf, 0, MAX_WPA_IE_LEN);
-                       n = sprintf(buf, "rsn_ie=");
-                       for (i = 0; i < rsn_len; i++) {
-                               n += snprintf(buf + n, MAX_WPA_IE_LEN - n,
-                                                       "%02x", rsn_ie[i]);
-                               if (n >= MAX_WPA_IE_LEN)
-                                       break;
-                       }
-                       memset(&iwe, 0, sizeof(iwe));
-                       iwe.cmd = IWEVCUSTOM;
-                       iwe.u.data.length = strlen(buf);
-                       start = iwe_stream_add_point(info, start, stop,
-                               &iwe, buf);
-                       memset(&iwe, 0, sizeof(iwe));
-                       iwe.cmd = IWEVGENIE;
-                       iwe.u.data.length = rsn_len;
-                       start = iwe_stream_add_point(info, start, stop, &iwe,
-                               rsn_ie);
-               }
-       }
 
-       { /* parsing WPS IE */
-               u8 wps_ie[512];
-               uint wps_ielen;
+       start = translate_scan_wpa(info, pnetwork, &iwe, start, stop);
+
+       start = translate_scan_wps(info, pnetwork, &iwe, start, stop);
 
-               if (r8712_get_wps_ie(pnetwork->network.IEs,
-                   pnetwork->network.IELength,
-                   wps_ie, &wps_ielen)) {
-                       if (wps_ielen > 2) {
-                               iwe.cmd = IWEVGENIE;
-                               iwe.u.data.length = (u16)wps_ielen;
-                               start = iwe_stream_add_point(info, start, stop,
-                                       &iwe, wps_ie);
-                       }
-               }
-       }
        /* Add quality statistics */
        iwe.cmd = IWEVQUAL;
        rssi = r8712_signal_scale_mapping(pnetwork->network.Rssi);
@@ -478,13 +497,13 @@ static int r871x_set_wpa_ie(struct _adapter *padapter, char *pie,
                        goto exit;
                }
                if (r8712_parse_wpa_ie(buf, ielen, &group_cipher,
-                   &pairwise_cipher) == _SUCCESS) {
+                   &pairwise_cipher) == 0) {
                        padapter->securitypriv.AuthAlgrthm = 2;
                        padapter->securitypriv.ndisauthtype =
                                  Ndis802_11AuthModeWPAPSK;
                }
                if (r8712_parse_wpa2_ie(buf, ielen, &group_cipher,
-                   &pairwise_cipher) == _SUCCESS) {
+                   &pairwise_cipher) == 0) {
                        padapter->securitypriv.AuthAlgrthm = 2;
                        padapter->securitypriv.ndisauthtype =
                                  Ndis802_11AuthModeWPA2PSK;
@@ -1309,7 +1328,7 @@ static int r8711_wx_set_rate(struct net_device *dev,
        u32 ratevalue = 0;
        u8 datarates[NumRates];
        u8 mpdatarate[NumRates] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff};
-       int i, ret = 0;
+       int i;
 
        if (target_rate == -1) {
                ratevalue = 11;
@@ -1367,9 +1386,7 @@ set_rate:
                        datarates[i] = 0xff;
                }
        }
-       if (r8712_setdatarate_cmd(padapter, datarates) != _SUCCESS)
-               ret = -ENOMEM;
-       return ret;
+       return r8712_setdatarate_cmd(padapter, datarates);
 }
 
 static int r8711_wx_get_rate(struct net_device *dev,
@@ -1577,7 +1594,7 @@ static int r8711_wx_get_enc(struct net_device *dev,
                                struct iw_request_info *info,
                                union iwreq_data *wrqu, char *keybuf)
 {
-       uint key, ret = 0;
+       uint key;
        struct _adapter *padapter = netdev_priv(dev);
        struct iw_point *erq = &(wrqu->encoding);
        struct  mlme_priv       *pmlmepriv = &(padapter->mlmepriv);
@@ -1633,7 +1650,7 @@ static int r8711_wx_get_enc(struct net_device *dev,
                erq->flags |= IW_ENCODE_DISABLED;
                break;
        }
-       return ret;
+       return 0;
 }
 
 static int r8711_wx_get_power(struct net_device *dev,
index 2dc20da21679c3250e6e1f1f46ff978ec2208ade..b78101afc93d3a86b8983718906a8a991858361a 100644 (file)
@@ -429,7 +429,7 @@ uint oid_rt_pro_rf_write_registry_hdl(struct oid_par_priv*
                return RNDIS_STATUS_NOT_ACCEPTED;
        if (poid_par_priv->information_buf_len ==
           (sizeof(unsigned long) * 3)) {
-               if (!r8712_setrfreg_cmd(Adapter,
+               if (r8712_setrfreg_cmd(Adapter,
                        *(unsigned char *)poid_par_priv->information_buf,
                        (unsigned long)(*((unsigned long *)
                                        poid_par_priv->information_buf + 2))))
@@ -467,7 +467,7 @@ uint oid_rt_pro_rf_read_registry_hdl(struct oid_par_priv *poid_par_priv)
                 * RegDataWidth = *((unsigned long *)InformationBuffer+1);
                 * RegDataValue =  *((unsigned long *)InformationBuffer+2);
                 */
-                       if (!r8712_getrfreg_cmd(Adapter,
+                       if (r8712_getrfreg_cmd(Adapter,
                            *(unsigned char *)poid_par_priv->information_buf,
                            (unsigned char *)&Adapter->mppriv.workparam.io_value
                            ))
index 2622d5e3bff9b2d5852369705002b097f9c8d7cb..f3c0a9348f56a367696197e3bdf936b2ea330d99 100644 (file)
@@ -66,7 +66,7 @@ static u8 do_join(struct _adapter *padapter)
        }
 
        ret = r8712_select_and_join_from_scan(pmlmepriv);
-       if (ret == _SUCCESS) {
+       if (!ret) {
                mod_timer(&pmlmepriv->assoc_timer,
                          jiffies + msecs_to_jiffies(MAX_JOIN_TIMEOUT));
        } else {
@@ -84,7 +84,7 @@ static u8 do_join(struct _adapter *padapter)
                               sizeof(struct ndis_802_11_ssid));
                        r8712_update_registrypriv_dev_network(padapter);
                        r8712_generate_random_ibss(pibss);
-                       if (r8712_createbss_cmd(padapter) != _SUCCESS)
+                       if (r8712_createbss_cmd(padapter))
                                return false;
                        pmlmepriv->to_join = false;
                } else {
index 7c7267d0fc9e3da3dca053f9a5ecad75107994e4..0cc879a4d43fa19446a33fa428afe728e5a6ad06 100644 (file)
@@ -29,7 +29,7 @@
 
 static void update_ht_cap(struct _adapter *padapter, u8 *pie, uint ie_len);
 
-static sint _init_mlme_priv(struct _adapter *padapter)
+int r8712_init_mlme_priv(struct _adapter *padapter)
 {
        sint    i;
        u8      *pbuf;
@@ -129,8 +129,8 @@ static void free_network_nolock(struct mlme_priv *pmlmepriv,
  * Shall be called under atomic context...
  * to avoid possible racing condition...
  */
-static struct wlan_network *_r8712_find_network(struct  __queue *scanned_queue,
-                                        u8 *addr)
+static struct wlan_network *r8712_find_network(struct  __queue *scanned_queue,
+                                              u8 *addr)
 {
        unsigned long irqL;
        struct list_head *phead, *plist;
@@ -151,7 +151,7 @@ static struct wlan_network *_r8712_find_network(struct  __queue *scanned_queue,
        return pnetwork;
 }
 
-static void _free_network_queue(struct _adapter *padapter)
+void r8712_free_network_queue(struct _adapter *padapter)
 {
        unsigned long irqL;
        struct list_head *phead, *plist;
@@ -205,11 +205,6 @@ u8 *r8712_get_capability_from_ie(u8 *ie)
        return ie + 8 + 2;
 }
 
-int r8712_init_mlme_priv(struct _adapter *padapter)
-{
-       return _init_mlme_priv(padapter);
-}
-
 void r8712_free_mlme_priv(struct mlme_priv *pmlmepriv)
 {
        kfree(pmlmepriv->free_bss_buf);
@@ -220,25 +215,6 @@ static struct      wlan_network *alloc_network(struct mlme_priv *pmlmepriv)
        return _r8712_alloc_network(pmlmepriv);
 }
 
-void r8712_free_network_queue(struct _adapter *dev)
-{
-       _free_network_queue(dev);
-}
-
-/*
- * return the wlan_network with the matching addr
- * Shall be called under atomic context...
- * to avoid possible racing condition...
- */
-static struct wlan_network *r8712_find_network(struct  __queue *scanned_queue,
-                                              u8 *addr)
-{
-       struct wlan_network *pnetwork = _r8712_find_network(scanned_queue,
-                                                           addr);
-
-       return pnetwork;
-}
-
 int r8712_is_same_ibss(struct _adapter *adapter, struct wlan_network *pnetwork)
 {
        int ret = true;
@@ -558,8 +534,7 @@ void r8712_surveydone_event_callback(struct _adapter *adapter, u8 *pbuf)
                        if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
                                set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
 
-                               if (r8712_select_and_join_from_scan(pmlmepriv)
-                                   == _SUCCESS) {
+                               if (!r8712_select_and_join_from_scan(pmlmepriv)) {
                                        mod_timer(&pmlmepriv->assoc_timer, jiffies +
                                                  msecs_to_jiffies(MAX_JOIN_TIMEOUT));
                                } else {
@@ -584,8 +559,7 @@ void r8712_surveydone_event_callback(struct _adapter *adapter, u8 *pbuf)
                } else {
                        pmlmepriv->to_join = false;
                        set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
-                       if (r8712_select_and_join_from_scan(pmlmepriv) ==
-                           _SUCCESS)
+                       if (!r8712_select_and_join_from_scan(pmlmepriv))
                                mod_timer(&pmlmepriv->assoc_timer, jiffies +
                                          msecs_to_jiffies(MAX_JOIN_TIMEOUT));
                        else
@@ -1091,11 +1065,6 @@ void _r8712_dhcp_timeout_handler (struct _adapter *adapter)
                            adapter->registrypriv.smart_ps);
 }
 
-void _r8712_wdg_timeout_handler(struct _adapter *adapter)
-{
-       r8712_wdg_wk_cmd(adapter);
-}
-
 int r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv)
 {
        struct list_head *phead;
@@ -1116,7 +1085,7 @@ int r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv)
                                pnetwork = pnetwork_max_rssi;
                                goto ask_for_joinbss;
                        }
-                       return _FAIL;
+                       return -EINVAL;
                }
                pnetwork = container_of(pmlmepriv->pscanned,
                                        struct wlan_network, list);
index 8a54181f481693dae7f098de588f1deb4cb88ee0..a160107e98010ec351fa0319e539f49404d2f52f 100644 (file)
@@ -172,7 +172,7 @@ void r8712_wpspbc_event_callback(struct _adapter *adapter, u8 *pbuf);
 void r8712_free_network_queue(struct _adapter *adapter);
 int r8712_init_mlme_priv(struct _adapter *adapter);
 void r8712_free_mlme_priv(struct mlme_priv *pmlmepriv);
-sint r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv);
+int r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv);
 sint r8712_set_key(struct _adapter *adapter,
                   struct security_priv *psecuritypriv, sint keyid);
 sint r8712_set_auth(struct _adapter *adapter,
@@ -195,7 +195,6 @@ void _r8712_sitesurvey_ctrl_handler(struct _adapter *adapter);
 void _r8712_join_timeout_handler(struct _adapter *adapter);
 void r8712_scan_timeout_handler(struct _adapter *adapter);
 void _r8712_dhcp_timeout_handler(struct _adapter *adapter);
-void _r8712_wdg_timeout_handler(struct _adapter *adapter);
 struct wlan_network *_r8712_alloc_network(struct mlme_priv *pmlmepriv);
 sint r8712_if_up(struct _adapter *padapter);
 void r8712_joinbss_reset(struct _adapter *padapter);
index ba379506da3fd1e6cbc7c312979d440348e947c7..edd3da05fc062fed5f83754677cc629221025d10 100644 (file)
@@ -709,20 +709,18 @@ static u32 GetPhyRxPktCounts(struct _adapter *pAdapter, u32 selbit)
 
 u32 r8712_GetPhyRxPktReceived(struct _adapter *pAdapter)
 {
-       u32 OFDM_cnt = 0, CCK_cnt = 0, HT_cnt = 0;
+       u32 OFDM_cnt = GetPhyRxPktCounts(pAdapter, OFDM_MPDU_OK_BIT);
+       u32 CCK_cnt  = GetPhyRxPktCounts(pAdapter, CCK_MPDU_OK_BIT);
+       u32 HT_cnt   = GetPhyRxPktCounts(pAdapter, HT_MPDU_OK_BIT);
 
-       OFDM_cnt = GetPhyRxPktCounts(pAdapter, OFDM_MPDU_OK_BIT);
-       CCK_cnt = GetPhyRxPktCounts(pAdapter, CCK_MPDU_OK_BIT);
-       HT_cnt = GetPhyRxPktCounts(pAdapter, HT_MPDU_OK_BIT);
        return OFDM_cnt + CCK_cnt + HT_cnt;
 }
 
 u32 r8712_GetPhyRxPktCRC32Error(struct _adapter *pAdapter)
 {
-       u32 OFDM_cnt = 0, CCK_cnt = 0, HT_cnt = 0;
+       u32 OFDM_cnt = GetPhyRxPktCounts(pAdapter, OFDM_MPDU_FAIL_BIT);
+       u32 CCK_cnt  = GetPhyRxPktCounts(pAdapter, CCK_MPDU_FAIL_BIT);
+       u32 HT_cnt   = GetPhyRxPktCounts(pAdapter, HT_MPDU_FAIL_BIT);
 
-       OFDM_cnt = GetPhyRxPktCounts(pAdapter, OFDM_MPDU_FAIL_BIT);
-       CCK_cnt = GetPhyRxPktCounts(pAdapter, CCK_MPDU_FAIL_BIT);
-       HT_cnt = GetPhyRxPktCounts(pAdapter, HT_MPDU_FAIL_BIT);
        return OFDM_cnt + CCK_cnt + HT_cnt;
 }
index 588346da1412fc02c284a0a6b8ca871890bb292b..aa8f8500cbb261feb5a11af4f474c64db2253a2c 100644 (file)
@@ -153,7 +153,7 @@ static int mp_start_test(struct _adapter *padapter)
        struct sta_info *psta;
        unsigned long length;
        unsigned long irqL;
-       int res = _SUCCESS;
+       int res = 0;
 
        /* 3 1. initialize a new struct wlan_bssid_ex */
        memcpy(bssid.MacAddress, pmppriv->network_macaddr, ETH_ALEN);
@@ -187,7 +187,7 @@ static int mp_start_test(struct _adapter *padapter)
                r8712_free_stainfo(padapter, psta);
        psta = r8712_alloc_stainfo(&padapter->stapriv, bssid.MacAddress);
        if (psta == NULL) {
-               res = _FAIL;
+               res = -ENOMEM;
                goto end_of_mp_start_test;
        }
        /* 3 3. join pseudo AdHoc */
@@ -231,22 +231,6 @@ end_of_mp_stop_test:
        return _SUCCESS;
 }
 
-int mp_start_joinbss(struct _adapter *padapter, struct ndis_802_11_ssid *pssid)
-{
-       struct mp_priv *pmppriv = &padapter->mppriv;
-       struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
-       unsigned char res = _SUCCESS;
-
-       if (!check_fwstate(pmlmepriv, WIFI_MP_STATE))
-               return _FAIL;
-       if (!check_fwstate(pmlmepriv, _FW_LINKED))
-               return _FAIL;
-       _clr_fwstate_(pmlmepriv, _FW_LINKED);
-       res = r8712_setassocsta_cmd(padapter, pmppriv->network_macaddr);
-       set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
-       return res;
-}
-
 uint oid_rt_pro_set_data_rate_hdl(struct oid_par_priv
                                         *poid_par_priv)
 {
@@ -278,7 +262,7 @@ uint oid_rt_pro_start_test_hdl(struct oid_par_priv *poid_par_priv)
                return  RNDIS_STATUS_NOT_ACCEPTED;
        mode = *((u32 *)poid_par_priv->information_buf);
        Adapter->mppriv.mode = mode;/* 1 for loopback*/
-       if (mp_start_test(Adapter) == _FAIL)
+       if (mp_start_test(Adapter))
                status = RNDIS_STATUS_NOT_ACCEPTED;
        r8712_write8(Adapter, MSR, 1); /* Link in ad hoc network, 0x1025004C */
        r8712_write8(Adapter, RCR, 0); /* RCR : disable all pkt, 0x10250048 */
@@ -661,11 +645,6 @@ uint oid_rt_pro_write_register_hdl(struct oid_par_priv *poid_par_priv)
                        status = RNDIS_STATUS_NOT_ACCEPTED;
                        break;
                }
-
-               if ((status == RNDIS_STATUS_SUCCESS) &&
-                   (RegRWStruct->offset == HIMR) &&
-                   (RegRWStruct->width == 4))
-                       Adapter->ImrContent = RegRWStruct->value;
        }
        return status;
 }
index 44cd911f2aa139da58c190dafaf2d87a2bc7afbe..64e2ae436625b762dec8e6e2db166574da18bba0 100644 (file)
@@ -71,8 +71,6 @@ struct DR_VARIABLE_STRUCT {
        u32 variable;
 };
 
-int mp_start_joinbss(struct _adapter *padapter, struct ndis_802_11_ssid *pssid);
-
 /* oid_rtl_seg_87_11_00 */
 uint oid_rt_pro_read_register_hdl(struct oid_par_priv *poid_par_priv);
 uint oid_rt_pro_write_register_hdl(struct oid_par_priv *poid_par_priv);
index 28f736913292ed0f1c391aedefe2ed7e314260dc..5298fe603437de8b0c866cdee6e0cee1934fc595 100644 (file)
@@ -151,7 +151,7 @@ sint r8712_recvframe_chkmic(struct _adapter *adapter,
        if (prxattrib->encrypt == _TKIP_) {
                /* calculate mic code */
                if (stainfo != NULL) {
-                       if (IS_MCAST(prxattrib->ra)) {
+                       if (is_multicast_ether_addr(prxattrib->ra)) {
                                iv = precvframe->u.hdr.rx_data +
                                     prxattrib->hdrlen;
                                idx = iv[3];
@@ -180,12 +180,12 @@ sint r8712_recvframe_chkmic(struct _adapter *adapter,
                        if (bmic_err) {
                                if (prxattrib->bdecrypted)
                                        r8712_handle_tkip_mic_err(adapter,
-                                               (u8)IS_MCAST(prxattrib->ra));
+                                               (u8)is_multicast_ether_addr(prxattrib->ra));
                                res = _FAIL;
                        } else {
                                /* mic checked ok */
                                if (!psecuritypriv->bcheck_grpkey &&
-                                   IS_MCAST(prxattrib->ra))
+                                   is_multicast_ether_addr(prxattrib->ra))
                                        psecuritypriv->bcheck_grpkey = true;
                        }
                        recvframe_pull_tail(precvframe, 8);
@@ -305,7 +305,7 @@ static sint sta2sta_data_frame(struct _adapter *adapter,
        u8 *mybssid  = get_bssid(pmlmepriv);
        u8 *myhwaddr = myid(&adapter->eeprompriv);
        u8 *sta_addr = NULL;
-       sint bmcast = IS_MCAST(pattrib->dst);
+       bool bmcast = is_multicast_ether_addr(pattrib->dst);
 
        if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
            check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
@@ -331,7 +331,7 @@ static sint sta2sta_data_frame(struct _adapter *adapter,
                        /* For AP mode, if DA == MCAST, then BSSID should
                         * be also MCAST
                         */
-                       if (!IS_MCAST(pattrib->bssid))
+                       if (!is_multicast_ether_addr(pattrib->bssid))
                                return _FAIL;
                } else { /* not mc-frame */
                        /* For AP mode, if DA is non-MCAST, then it must be
@@ -373,7 +373,7 @@ static sint ap2sta_data_frame(struct _adapter *adapter,
        struct  mlme_priv *pmlmepriv = &adapter->mlmepriv;
        u8 *mybssid  = get_bssid(pmlmepriv);
        u8 *myhwaddr = myid(&adapter->eeprompriv);
-       sint bmcast = IS_MCAST(pattrib->dst);
+       bool bmcast = is_multicast_ether_addr(pattrib->dst);
 
        if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) &&
            check_fwstate(pmlmepriv, _FW_LINKED)) {
@@ -532,7 +532,7 @@ static sint validate_recv_data_frame(struct _adapter *adapter,
 
        if (pattrib->privacy) {
                GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt,
-                              IS_MCAST(pattrib->ra));
+                              is_multicast_ether_addr(pattrib->ra));
                SET_ICE_IV_LEN(pattrib->iv_len, pattrib->icv_len,
                               pattrib->encrypt);
        } else {
index f82645011d02038a7f6405b8b517a2a4e7e187f6..693008bba83ea5661f60e91a7e26105a9825c7af 100644 (file)
@@ -665,7 +665,7 @@ u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe)
                        length = ((union recv_frame *)precvframe)->
                                 u.hdr.len - prxattrib->hdrlen -
                                 prxattrib->iv_len;
-                       if (IS_MCAST(prxattrib->ra)) {
+                       if (is_multicast_ether_addr(prxattrib->ra)) {
                                idx = iv[3];
                                prwskey = &psecuritypriv->XGrpKey[
                                         ((idx >> 6) & 0x3) - 1].skey[0];
@@ -1368,7 +1368,7 @@ u32 r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe)
                stainfo = r8712_get_stainfo(&padapter->stapriv,
                                            &prxattrib->ta[0]);
                if (stainfo != NULL) {
-                       if (IS_MCAST(prxattrib->ra)) {
+                       if (is_multicast_ether_addr(prxattrib->ra)) {
                                iv = pframe + prxattrib->hdrlen;
                                idx = iv[3];
                                prwskey = &psecuritypriv->XGrpKey[
index 7c30b9e68e702c82210a3ee922155b147d6f1f48..653812c5d5a83b300870c411f08c401ae6f59684 100644 (file)
@@ -34,7 +34,7 @@ static void _init_stainfo(struct sta_info *psta)
        INIT_LIST_HEAD(&psta->auth_list);
 }
 
-u32 _r8712_init_sta_priv(struct        sta_priv *pstapriv)
+int _r8712_init_sta_priv(struct        sta_priv *pstapriv)
 {
        struct sta_info *psta;
        s32 i;
@@ -42,7 +42,7 @@ u32 _r8712_init_sta_priv(struct       sta_priv *pstapriv)
        pstapriv->pallocated_stainfo_buf = kmalloc(sizeof(struct sta_info) *
                                                   NUM_STA + 4, GFP_ATOMIC);
        if (!pstapriv->pallocated_stainfo_buf)
-               return _FAIL;
+               return -ENOMEM;
        pstapriv->pstainfo_buf = pstapriv->pallocated_stainfo_buf + 4 -
                ((addr_t)(pstapriv->pallocated_stainfo_buf) & 3);
        _init_queue(&pstapriv->free_sta_queue);
@@ -59,7 +59,7 @@ u32 _r8712_init_sta_priv(struct       sta_priv *pstapriv)
        }
        INIT_LIST_HEAD(&pstapriv->asoc_list);
        INIT_LIST_HEAD(&pstapriv->auth_list);
-       return _SUCCESS;
+       return 0;
 }
 
 /* this function is used to free the memory of lock || sema for all stainfos */
@@ -77,14 +77,13 @@ static void mfree_all_stainfo(struct sta_priv *pstapriv)
        spin_unlock_irqrestore(&pstapriv->sta_hash_lock, irqL);
 }
 
-u32 _r8712_free_sta_priv(struct sta_priv *pstapriv)
+void _r8712_free_sta_priv(struct sta_priv *pstapriv)
 {
        if (pstapriv) {
                /* be done before free sta_hash_lock */
                mfree_all_stainfo(pstapriv);
                kfree(pstapriv->pallocated_stainfo_buf);
        }
-       return _SUCCESS;
 }
 
 struct sta_info *r8712_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
index f6fe8ea129611f46811258464873bd29f8a7c5f9..0a26d71e5340267686178f6aeaa224ee897a34ba 100644 (file)
@@ -133,13 +133,14 @@ sint _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv,
                pxmitbuf->pbuf = pxmitbuf->pallocated_buf + XMITBUF_ALIGN_SZ -
                                 ((addr_t) (pxmitbuf->pallocated_buf) &
                                 (XMITBUF_ALIGN_SZ - 1));
-               r8712_xmit_resource_alloc(padapter, pxmitbuf);
+               if (r8712_xmit_resource_alloc(padapter, pxmitbuf))
+                       return _FAIL;
                list_add_tail(&pxmitbuf->list,
                                 &(pxmitpriv->free_xmitbuf_queue.queue));
                pxmitbuf++;
        }
        pxmitpriv->free_xmitbuf_cnt = NR_XMITBUFF;
-       INIT_WORK(&padapter->wkFilterRxFF0, r8712_SetFilter);
+       INIT_WORK(&padapter->wk_filter_rx_ff0, r8712_SetFilter);
        alloc_hwxmits(padapter);
        init_hwxmits(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);
        tasklet_init(&pxmitpriv->xmit_tasklet,
@@ -181,7 +182,7 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
 
        struct tx_cmd txdesc;
 
-       sint bmcast;
+       bool bmcast;
        struct sta_priv         *pstapriv = &padapter->stapriv;
        struct security_priv    *psecuritypriv = &padapter->securitypriv;
        struct mlme_priv        *pmlmepriv = &padapter->mlmepriv;
@@ -257,7 +258,7 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
                        }
                }
        }
-       bmcast = IS_MCAST(pattrib->ra);
+       bmcast = is_multicast_ether_addr(pattrib->ra);
        /* get sta_info*/
        if (bmcast) {
                psta = r8712_get_bcmc_stainfo(padapter);
@@ -353,7 +354,7 @@ static sint xmitframe_addmic(struct _adapter *padapter,
        struct  security_priv *psecuritypriv = &padapter->securitypriv;
        struct  xmit_priv *pxmitpriv = &padapter->xmitpriv;
        u8 priority[4] = {0x0, 0x0, 0x0, 0x0};
-       sint bmcst = IS_MCAST(pattrib->ra);
+       bool bmcst = is_multicast_ether_addr(pattrib->ra);
 
        if (pattrib->psta)
                stainfo = pattrib->psta;
@@ -523,7 +524,7 @@ static sint make_wlanhdr(struct _adapter *padapter, u8 *hdr,
                /* Update Seq Num will be handled by f/w */
                {
                        struct sta_info *psta;
-                       sint bmcst = IS_MCAST(pattrib->ra);
+                       bool bmcst = is_multicast_ether_addr(pattrib->ra);
 
                        if (pattrib->psta) {
                                psta = pattrib->psta;
@@ -594,7 +595,7 @@ sint r8712_xmitframe_coalesce(struct _adapter *padapter, _pkt *pkt,
        struct xmit_priv        *pxmitpriv = &padapter->xmitpriv;
        struct pkt_attrib       *pattrib = &pxmitframe->attrib;
        u8 *pbuf_start;
-       sint bmcst = IS_MCAST(pattrib->ra);
+       bool bmcst = is_multicast_ether_addr(pattrib->ra);
 
        if (pattrib->psta == NULL)
                return _FAIL;
@@ -903,7 +904,7 @@ sint r8712_xmit_classifier(struct _adapter *padapter,
        struct pkt_attrib *pattrib = &pxmitframe->attrib;
        struct sta_priv *pstapriv = &padapter->stapriv;
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
-       sint bmcst = IS_MCAST(pattrib->ra);
+       bool bmcst = is_multicast_ether_addr(pattrib->ra);
 
        if (pattrib->psta) {
                psta = pattrib->psta;
index 3bea2e374f137a1fec88a98b6f887b1d62144f39..4199cb586fb1db6ff5a4c1cbb041e7de67d2d95d 100644 (file)
@@ -148,8 +148,8 @@ struct xmit_frame {
        _pkt *pkt;
        int frame_tag;
        struct _adapter *padapter;
-        u8 *buf_addr;
-        struct xmit_buf *pxmitbuf;
+       u8 *buf_addr;
+       struct xmit_buf *pxmitbuf;
        u8 *mem_addr;
        u16 sz[8];
        struct urb *pxmit_urb[8];
index 45dbed10295f0ccb0a339bce2e003a6642808e85..d042d900f30c46c8ab62af06db8d9d12660754ad 100644 (file)
@@ -119,8 +119,8 @@ static inline u32 wifi_mac_hash(u8 *mac)
        return x;
 }
 
-u32 _r8712_init_sta_priv(struct sta_priv *pstapriv);
-u32 _r8712_free_sta_priv(struct sta_priv *pstapriv);
+int _r8712_init_sta_priv(struct sta_priv *pstapriv);
+void _r8712_free_sta_priv(struct sta_priv *pstapriv);
 struct sta_info *r8712_alloc_stainfo(struct sta_priv *pstapriv,
                                     u8 *hwaddr);
 void r8712_free_stainfo(struct _adapter *padapter, struct sta_info *psta);
index 02e73c2412d4f000257b0357a6406b43a16847a8..6cc4a704c3a014b29ec107e893eaa03b19af56fb 100644 (file)
 #include "usb_ops.h"
 #include "usb_osintf.h"
 
-u8 r8712_usb_hal_bus_init(struct _adapter *padapter)
+u8 r8712_usb_hal_bus_init(struct _adapter *adapter)
 {
        u8 val8 = 0;
        u8 ret = _SUCCESS;
        int PollingCnt = 20;
-       struct registry_priv *pregistrypriv = &padapter->registrypriv;
+       struct registry_priv *registrypriv = &adapter->registrypriv;
 
-       if (pregistrypriv->chip_version == RTL8712_FPGA) {
+       if (registrypriv->chip_version == RTL8712_FPGA) {
                val8 = 0x01;
                /* switch to 80M clock */
-               r8712_write8(padapter, SYS_CLKR, val8);
-               val8 = r8712_read8(padapter, SPS1_CTRL);
+               r8712_write8(adapter, SYS_CLKR, val8);
+               val8 = r8712_read8(adapter, SPS1_CTRL);
                val8 = val8 | 0x01;
                /* enable VSPS12 LDO Macro block */
-               r8712_write8(padapter, SPS1_CTRL, val8);
-               val8 = r8712_read8(padapter, AFE_MISC);
+               r8712_write8(adapter, SPS1_CTRL, val8);
+               val8 = r8712_read8(adapter, AFE_MISC);
                val8 = val8 | 0x01;
                /* Enable AFE Macro Block's Bandgap */
-               r8712_write8(padapter, AFE_MISC, val8);
-               val8 = r8712_read8(padapter, LDOA15_CTRL);
+               r8712_write8(adapter, AFE_MISC, val8);
+               val8 = r8712_read8(adapter, LDOA15_CTRL);
                val8 = val8 | 0x01;
                /* enable LDOA15 block */
-               r8712_write8(padapter, LDOA15_CTRL, val8);
-               val8 = r8712_read8(padapter, SPS1_CTRL);
+               r8712_write8(adapter, LDOA15_CTRL, val8);
+               val8 = r8712_read8(adapter, SPS1_CTRL);
                val8 = val8 | 0x02;
                /* Enable VSPS12_SW Macro Block */
-               r8712_write8(padapter, SPS1_CTRL, val8);
-               val8 = r8712_read8(padapter, AFE_MISC);
+               r8712_write8(adapter, SPS1_CTRL, val8);
+               val8 = r8712_read8(adapter, AFE_MISC);
                val8 = val8 | 0x02;
                /* Enable AFE Macro Block's Mbias */
-               r8712_write8(padapter, AFE_MISC, val8);
-               val8 = r8712_read8(padapter, SYS_ISO_CTRL + 1);
+               r8712_write8(adapter, AFE_MISC, val8);
+               val8 = r8712_read8(adapter, SYS_ISO_CTRL + 1);
                val8 = val8 | 0x08;
                /* isolate PCIe Analog 1.2V to PCIe 3.3V and PCIE Digital */
-               r8712_write8(padapter, SYS_ISO_CTRL + 1, val8);
-               val8 = r8712_read8(padapter, SYS_ISO_CTRL + 1);
+               r8712_write8(adapter, SYS_ISO_CTRL + 1, val8);
+               val8 = r8712_read8(adapter, SYS_ISO_CTRL + 1);
                val8 = val8 & 0xEF;
                /* attatch AFE PLL to MACTOP/BB/PCIe Digital */
-               r8712_write8(padapter, SYS_ISO_CTRL + 1, val8);
-               val8 = r8712_read8(padapter, AFE_XTAL_CTRL + 1);
+               r8712_write8(adapter, SYS_ISO_CTRL + 1, val8);
+               val8 = r8712_read8(adapter, AFE_XTAL_CTRL + 1);
                val8 = val8 & 0xFB;
                /* enable AFE clock */
-               r8712_write8(padapter, AFE_XTAL_CTRL + 1, val8);
-               val8 = r8712_read8(padapter, AFE_PLL_CTRL);
+               r8712_write8(adapter, AFE_XTAL_CTRL + 1, val8);
+               val8 = r8712_read8(adapter, AFE_PLL_CTRL);
                val8 = val8 | 0x01;
                /* Enable AFE PLL Macro Block */
-               r8712_write8(padapter, AFE_PLL_CTRL, val8);
+               r8712_write8(adapter, AFE_PLL_CTRL, val8);
                val8 = 0xEE;
                /* release isolation AFE PLL & MD */
-               r8712_write8(padapter, SYS_ISO_CTRL, val8);
-               val8 = r8712_read8(padapter, SYS_CLKR + 1);
+               r8712_write8(adapter, SYS_ISO_CTRL, val8);
+               val8 = r8712_read8(adapter, SYS_CLKR + 1);
                val8 = val8 | 0x08;
                /* enable MAC clock */
-               r8712_write8(padapter, SYS_CLKR + 1, val8);
-               val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
+               r8712_write8(adapter, SYS_CLKR + 1, val8);
+               val8 = r8712_read8(adapter, SYS_FUNC_EN + 1);
                val8 = val8 | 0x08;
                /* enable Core digital and enable IOREG R/W */
-               r8712_write8(padapter, SYS_FUNC_EN + 1, val8);
+               r8712_write8(adapter, SYS_FUNC_EN + 1, val8);
                val8 = val8 | 0x80;
                /* enable REG_EN */
-               r8712_write8(padapter, SYS_FUNC_EN + 1, val8);
-               val8 = r8712_read8(padapter, SYS_CLKR + 1);
+               r8712_write8(adapter, SYS_FUNC_EN + 1, val8);
+               val8 = r8712_read8(adapter, SYS_CLKR + 1);
                val8 = (val8 | 0x80) & 0xBF;
                /* switch the control path */
-               r8712_write8(padapter, SYS_CLKR + 1, val8);
+               r8712_write8(adapter, SYS_CLKR + 1, val8);
                val8 = 0xFC;
-               r8712_write8(padapter, CR, val8);
+               r8712_write8(adapter, CR, val8);
                val8 = 0x37;
-               r8712_write8(padapter, CR + 1, val8);
+               r8712_write8(adapter, CR + 1, val8);
                /* reduce EndPoint & init it */
-               r8712_write8(padapter, 0x102500ab, r8712_read8(padapter,
+               r8712_write8(adapter, 0x102500ab, r8712_read8(adapter,
                             0x102500ab) | BIT(6) | BIT(7));
                /* consideration of power consumption - init */
-               r8712_write8(padapter, 0x10250008, r8712_read8(padapter,
+               r8712_write8(adapter, 0x10250008, r8712_read8(adapter,
                             0x10250008) & 0xfffffffb);
-       } else if (pregistrypriv->chip_version == RTL8712_1stCUT) {
+       } else if (registrypriv->chip_version == RTL8712_1stCUT) {
                /* Initialization for power on sequence, */
-               r8712_write8(padapter, SPS0_CTRL + 1, 0x53);
-               r8712_write8(padapter, SPS0_CTRL, 0x57);
+               r8712_write8(adapter, SPS0_CTRL + 1, 0x53);
+               r8712_write8(adapter, SPS0_CTRL, 0x57);
                /* Enable AFE Macro Block's Bandgap and Enable AFE Macro
                 * Block's Mbias
                 */
-               val8 = r8712_read8(padapter, AFE_MISC);
-               r8712_write8(padapter, AFE_MISC, (val8 | AFE_MISC_BGEN |
+               val8 = r8712_read8(adapter, AFE_MISC);
+               r8712_write8(adapter, AFE_MISC, (val8 | AFE_MISC_BGEN |
                             AFE_MISC_MBEN));
                /* Enable LDOA15 block */
-               val8 = r8712_read8(padapter, LDOA15_CTRL);
-               r8712_write8(padapter, LDOA15_CTRL, (val8 | LDA15_EN));
-               val8 = r8712_read8(padapter, SPS1_CTRL);
-               r8712_write8(padapter, SPS1_CTRL, (val8 | SPS1_LDEN));
+               val8 = r8712_read8(adapter, LDOA15_CTRL);
+               r8712_write8(adapter, LDOA15_CTRL, (val8 | LDA15_EN));
+               val8 = r8712_read8(adapter, SPS1_CTRL);
+               r8712_write8(adapter, SPS1_CTRL, (val8 | SPS1_LDEN));
                msleep(20);
                /* Enable Switch Regulator Block */
-               val8 = r8712_read8(padapter, SPS1_CTRL);
-               r8712_write8(padapter, SPS1_CTRL, (val8 | SPS1_SWEN));
-               r8712_write32(padapter, SPS1_CTRL, 0x00a7b267);
-               val8 = r8712_read8(padapter, SYS_ISO_CTRL + 1);
-               r8712_write8(padapter, SYS_ISO_CTRL + 1, (val8 | 0x08));
+               val8 = r8712_read8(adapter, SPS1_CTRL);
+               r8712_write8(adapter, SPS1_CTRL, (val8 | SPS1_SWEN));
+               r8712_write32(adapter, SPS1_CTRL, 0x00a7b267);
+               val8 = r8712_read8(adapter, SYS_ISO_CTRL + 1);
+               r8712_write8(adapter, SYS_ISO_CTRL + 1, (val8 | 0x08));
                /* Engineer Packet CP test Enable */
-               val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
-               r8712_write8(padapter, SYS_FUNC_EN + 1, (val8 | 0x20));
-               val8 = r8712_read8(padapter, SYS_ISO_CTRL + 1);
-               r8712_write8(padapter, SYS_ISO_CTRL + 1, (val8 & 0x6F));
+               val8 = r8712_read8(adapter, SYS_FUNC_EN + 1);
+               r8712_write8(adapter, SYS_FUNC_EN + 1, (val8 | 0x20));
+               val8 = r8712_read8(adapter, SYS_ISO_CTRL + 1);
+               r8712_write8(adapter, SYS_ISO_CTRL + 1, (val8 & 0x6F));
                /* Enable AFE clock */
-               val8 = r8712_read8(padapter, AFE_XTAL_CTRL + 1);
-               r8712_write8(padapter, AFE_XTAL_CTRL + 1, (val8 & 0xfb));
+               val8 = r8712_read8(adapter, AFE_XTAL_CTRL + 1);
+               r8712_write8(adapter, AFE_XTAL_CTRL + 1, (val8 & 0xfb));
                /* Enable AFE PLL Macro Block */
-               val8 = r8712_read8(padapter, AFE_PLL_CTRL);
-               r8712_write8(padapter, AFE_PLL_CTRL, (val8 | 0x11));
+               val8 = r8712_read8(adapter, AFE_PLL_CTRL);
+               r8712_write8(adapter, AFE_PLL_CTRL, (val8 | 0x11));
                /* Attach AFE PLL to MACTOP/BB/PCIe Digital */
-               val8 = r8712_read8(padapter, SYS_ISO_CTRL);
-               r8712_write8(padapter, SYS_ISO_CTRL, (val8 & 0xEE));
+               val8 = r8712_read8(adapter, SYS_ISO_CTRL);
+               r8712_write8(adapter, SYS_ISO_CTRL, (val8 & 0xEE));
                /* Switch to 40M clock */
-               val8 = r8712_read8(padapter, SYS_CLKR);
-               r8712_write8(padapter, SYS_CLKR, val8 & (~SYS_CLKSEL));
+               val8 = r8712_read8(adapter, SYS_CLKR);
+               r8712_write8(adapter, SYS_CLKR, val8 & (~SYS_CLKSEL));
                /* SSC Disable */
-               val8 = r8712_read8(padapter, SYS_CLKR);
+               val8 = r8712_read8(adapter, SYS_CLKR);
                /* Enable MAC clock */
-               val8 = r8712_read8(padapter, SYS_CLKR + 1);
-               r8712_write8(padapter, SYS_CLKR + 1, (val8 | 0x18));
+               val8 = r8712_read8(adapter, SYS_CLKR + 1);
+               r8712_write8(adapter, SYS_CLKR + 1, (val8 | 0x18));
                /* Revised POS, */
-               r8712_write8(padapter, PMC_FSM, 0x02);
+               r8712_write8(adapter, PMC_FSM, 0x02);
                /* Enable Core digital and enable IOREG R/W */
-               val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
-               r8712_write8(padapter, SYS_FUNC_EN + 1, (val8 | 0x08));
+               val8 = r8712_read8(adapter, SYS_FUNC_EN + 1);
+               r8712_write8(adapter, SYS_FUNC_EN + 1, (val8 | 0x08));
                /* Enable REG_EN */
-               val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
-               r8712_write8(padapter, SYS_FUNC_EN + 1, (val8 | 0x80));
+               val8 = r8712_read8(adapter, SYS_FUNC_EN + 1);
+               r8712_write8(adapter, SYS_FUNC_EN + 1, (val8 | 0x80));
                /* Switch the control path to FW */
-               val8 = r8712_read8(padapter, SYS_CLKR + 1);
-               r8712_write8(padapter, SYS_CLKR + 1, (val8 | 0x80) & 0xBF);
-               r8712_write8(padapter, CR, 0xFC);
-               r8712_write8(padapter, CR + 1, 0x37);
+               val8 = r8712_read8(adapter, SYS_CLKR + 1);
+               r8712_write8(adapter, SYS_CLKR + 1, (val8 | 0x80) & 0xBF);
+               r8712_write8(adapter, CR, 0xFC);
+               r8712_write8(adapter, CR + 1, 0x37);
                /* Fix the RX FIFO issue(usb error), */
-               val8 = r8712_read8(padapter, 0x1025FE5c);
-               r8712_write8(padapter, 0x1025FE5c, (val8 | BIT(7)));
-               val8 = r8712_read8(padapter, 0x102500ab);
-               r8712_write8(padapter, 0x102500ab, (val8 | BIT(6) | BIT(7)));
+               val8 = r8712_read8(adapter, 0x1025FE5c);
+               r8712_write8(adapter, 0x1025FE5c, (val8 | BIT(7)));
+               val8 = r8712_read8(adapter, 0x102500ab);
+               r8712_write8(adapter, 0x102500ab, (val8 | BIT(6) | BIT(7)));
                /* For power save, used this in the bit file after 970621 */
-               val8 = r8712_read8(padapter, SYS_CLKR);
-               r8712_write8(padapter, SYS_CLKR, val8 & (~CPU_CLKSEL));
-       } else if (pregistrypriv->chip_version == RTL8712_2ndCUT ||
-                 pregistrypriv->chip_version == RTL8712_3rdCUT) {
+               val8 = r8712_read8(adapter, SYS_CLKR);
+               r8712_write8(adapter, SYS_CLKR, val8 & (~CPU_CLKSEL));
+       } else if (registrypriv->chip_version == RTL8712_2ndCUT ||
+                  registrypriv->chip_version == RTL8712_3rdCUT) {
                /* Initialization for power on sequence,
                 * E-Fuse leakage prevention sequence
                 */
-               r8712_write8(padapter, 0x37, 0xb0);
+               r8712_write8(adapter, 0x37, 0xb0);
                msleep(20);
-               r8712_write8(padapter, 0x37, 0x30);
+               r8712_write8(adapter, 0x37, 0x30);
                /* Set control path switch to HW control and reset Digital Core,
                 * CPU Core and MAC I/O to solve FW download fail when system
                 * from resume sate.
                 */
-               val8 = r8712_read8(padapter, SYS_CLKR + 1);
+               val8 = r8712_read8(adapter, SYS_CLKR + 1);
                if (val8 & 0x80) {
                        val8 &= 0x3f;
-                       r8712_write8(padapter, SYS_CLKR + 1, val8);
+                       r8712_write8(adapter, SYS_CLKR + 1, val8);
                }
-               val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
+               val8 = r8712_read8(adapter, SYS_FUNC_EN + 1);
                val8 &= 0x73;
-               r8712_write8(padapter, SYS_FUNC_EN + 1, val8);
+               r8712_write8(adapter, SYS_FUNC_EN + 1, val8);
                msleep(20);
                /* Revised POS, */
                /* Enable AFE Macro Block's Bandgap and Enable AFE Macro
                 * Block's Mbias
                 */
-               r8712_write8(padapter, SPS0_CTRL + 1, 0x53);
-               r8712_write8(padapter, SPS0_CTRL, 0x57);
-               val8 = r8712_read8(padapter, AFE_MISC);
+               r8712_write8(adapter, SPS0_CTRL + 1, 0x53);
+               r8712_write8(adapter, SPS0_CTRL, 0x57);
+               val8 = r8712_read8(adapter, AFE_MISC);
                /*Bandgap*/
-               r8712_write8(padapter, AFE_MISC, (val8 | AFE_MISC_BGEN));
-               r8712_write8(padapter, AFE_MISC, (val8 | AFE_MISC_BGEN |
+               r8712_write8(adapter, AFE_MISC, (val8 | AFE_MISC_BGEN));
+               r8712_write8(adapter, AFE_MISC, (val8 | AFE_MISC_BGEN |
                             AFE_MISC_MBEN | AFE_MISC_I32_EN));
                /* Enable PLL Power (LDOA15V) */
-               val8 = r8712_read8(padapter, LDOA15_CTRL);
-               r8712_write8(padapter, LDOA15_CTRL, (val8 | LDA15_EN));
+               val8 = r8712_read8(adapter, LDOA15_CTRL);
+               r8712_write8(adapter, LDOA15_CTRL, (val8 | LDA15_EN));
                /* Enable LDOV12D block */
-               val8 = r8712_read8(padapter, LDOV12D_CTRL);
-               r8712_write8(padapter, LDOV12D_CTRL, (val8 | LDV12_EN));
-               val8 = r8712_read8(padapter, SYS_ISO_CTRL + 1);
-               r8712_write8(padapter, SYS_ISO_CTRL + 1, (val8 | 0x08));
+               val8 = r8712_read8(adapter, LDOV12D_CTRL);
+               r8712_write8(adapter, LDOV12D_CTRL, (val8 | LDV12_EN));
+               val8 = r8712_read8(adapter, SYS_ISO_CTRL + 1);
+               r8712_write8(adapter, SYS_ISO_CTRL + 1, (val8 | 0x08));
                /* Engineer Packet CP test Enable */
-               val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
-               r8712_write8(padapter, SYS_FUNC_EN + 1, (val8 | 0x20));
+               val8 = r8712_read8(adapter, SYS_FUNC_EN + 1);
+               r8712_write8(adapter, SYS_FUNC_EN + 1, (val8 | 0x20));
                /* Support 64k IMEM */
-               val8 = r8712_read8(padapter, SYS_ISO_CTRL + 1);
-               r8712_write8(padapter, SYS_ISO_CTRL + 1, (val8 & 0x68));
+               val8 = r8712_read8(adapter, SYS_ISO_CTRL + 1);
+               r8712_write8(adapter, SYS_ISO_CTRL + 1, (val8 & 0x68));
                /* Enable AFE clock */
-               val8 = r8712_read8(padapter, AFE_XTAL_CTRL + 1);
-               r8712_write8(padapter, AFE_XTAL_CTRL + 1, (val8 & 0xfb));
+               val8 = r8712_read8(adapter, AFE_XTAL_CTRL + 1);
+               r8712_write8(adapter, AFE_XTAL_CTRL + 1, (val8 & 0xfb));
                /* Enable AFE PLL Macro Block */
-               val8 = r8712_read8(padapter, AFE_PLL_CTRL);
-               r8712_write8(padapter, AFE_PLL_CTRL, (val8 | 0x11));
+               val8 = r8712_read8(adapter, AFE_PLL_CTRL);
+               r8712_write8(adapter, AFE_PLL_CTRL, (val8 | 0x11));
                /* Some sample will download fw failure. The clock will be
                 * stable with 500 us delay after reset the PLL
                 * TODO: When usleep is added to kernel, change next 3
                 * udelay(500) to usleep(500)
                 */
                udelay(500);
-               r8712_write8(padapter, AFE_PLL_CTRL, (val8 | 0x51));
+               r8712_write8(adapter, AFE_PLL_CTRL, (val8 | 0x51));
                udelay(500);
-               r8712_write8(padapter, AFE_PLL_CTRL, (val8 | 0x11));
+               r8712_write8(adapter, AFE_PLL_CTRL, (val8 | 0x11));
                udelay(500);
                /* Attach AFE PLL to MACTOP/BB/PCIe Digital */
-               val8 = r8712_read8(padapter, SYS_ISO_CTRL);
-               r8712_write8(padapter, SYS_ISO_CTRL, (val8 & 0xEE));
+               val8 = r8712_read8(adapter, SYS_ISO_CTRL);
+               r8712_write8(adapter, SYS_ISO_CTRL, (val8 & 0xEE));
                /* Switch to 40M clock */
-               r8712_write8(padapter, SYS_CLKR, 0x00);
+               r8712_write8(adapter, SYS_CLKR, 0x00);
                /* CPU Clock and 80M Clock SSC Disable to overcome FW download
                 * fail timing issue.
                 */
-               val8 = r8712_read8(padapter, SYS_CLKR);
-               r8712_write8(padapter, SYS_CLKR, (val8 | 0xa0));
+               val8 = r8712_read8(adapter, SYS_CLKR);
+               r8712_write8(adapter, SYS_CLKR, (val8 | 0xa0));
                /* Enable MAC clock */
-               val8 = r8712_read8(padapter, SYS_CLKR + 1);
-               r8712_write8(padapter, SYS_CLKR + 1, (val8 | 0x18));
+               val8 = r8712_read8(adapter, SYS_CLKR + 1);
+               r8712_write8(adapter, SYS_CLKR + 1, (val8 | 0x18));
                /* Revised POS, */
-               r8712_write8(padapter, PMC_FSM, 0x02);
+               r8712_write8(adapter, PMC_FSM, 0x02);
                /* Enable Core digital and enable IOREG R/W */
-               val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
-               r8712_write8(padapter, SYS_FUNC_EN + 1, (val8 | 0x08));
+               val8 = r8712_read8(adapter, SYS_FUNC_EN + 1);
+               r8712_write8(adapter, SYS_FUNC_EN + 1, (val8 | 0x08));
                /* Enable REG_EN */
-               val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
-               r8712_write8(padapter, SYS_FUNC_EN + 1, (val8 | 0x80));
+               val8 = r8712_read8(adapter, SYS_FUNC_EN + 1);
+               r8712_write8(adapter, SYS_FUNC_EN + 1, (val8 | 0x80));
                /* Switch the control path to FW */
-               val8 = r8712_read8(padapter, SYS_CLKR + 1);
-               r8712_write8(padapter, SYS_CLKR + 1, (val8 | 0x80) & 0xBF);
-               r8712_write8(padapter, CR, 0xFC);
-               r8712_write8(padapter, CR + 1, 0x37);
+               val8 = r8712_read8(adapter, SYS_CLKR + 1);
+               r8712_write8(adapter, SYS_CLKR + 1, (val8 | 0x80) & 0xBF);
+               r8712_write8(adapter, CR, 0xFC);
+               r8712_write8(adapter, CR + 1, 0x37);
                /* Fix the RX FIFO issue(usb error), 970410 */
-               val8 = r8712_read8(padapter, 0x1025FE5c);
-               r8712_write8(padapter, 0x1025FE5c, (val8 | BIT(7)));
+               val8 = r8712_read8(adapter, 0x1025FE5c);
+               r8712_write8(adapter, 0x1025FE5c, (val8 | BIT(7)));
                /* For power save, used this in the bit file after 970621 */
-               val8 = r8712_read8(padapter, SYS_CLKR);
-               r8712_write8(padapter, SYS_CLKR, val8 & (~CPU_CLKSEL));
+               val8 = r8712_read8(adapter, SYS_CLKR);
+               r8712_write8(adapter, SYS_CLKR, val8 & (~CPU_CLKSEL));
                /* Revised for 8051 ROM code wrong operation. */
-               r8712_write8(padapter, 0x1025fe1c, 0x80);
+               r8712_write8(adapter, 0x1025fe1c, 0x80);
                /* To make sure that TxDMA can ready to download FW.
                 * We should reset TxDMA if IMEM RPT was not ready.
                 */
                do {
-                       val8 = r8712_read8(padapter, TCR);
+                       val8 = r8712_read8(adapter, TCR);
                        if ((val8 & _TXDMA_INIT_VALUE) == _TXDMA_INIT_VALUE)
                                break;
                        udelay(5); /* PlatformStallExecution(5); */
                } while (PollingCnt--); /* Delay 1ms */
 
                if (PollingCnt <= 0) {
-                       val8 = r8712_read8(padapter, CR);
-                       r8712_write8(padapter, CR, val8 & (~_TXDMA_EN));
+                       val8 = r8712_read8(adapter, CR);
+                       r8712_write8(adapter, CR, val8 & (~_TXDMA_EN));
                        udelay(2); /* PlatformStallExecution(2); */
                        /* Reset TxDMA */
-                       r8712_write8(padapter, CR, val8 | _TXDMA_EN);
+                       r8712_write8(adapter, CR, val8 | _TXDMA_EN);
                }
        } else {
                ret = _FAIL;
@@ -280,28 +280,28 @@ u8 r8712_usb_hal_bus_init(struct _adapter *padapter)
        return ret;
 }
 
-unsigned int r8712_usb_inirp_init(struct _adapter *padapter)
+unsigned int r8712_usb_inirp_init(struct _adapter *adapter)
 {
        u8 i;
-       struct recv_buf *precvbuf;
-       struct intf_hdl *pintfhdl = &padapter->pio_queue->intf;
-       struct recv_priv *precvpriv = &(padapter->recvpriv);
+       struct recv_buf *recvbuf;
+       struct intf_hdl *intfhdl = &adapter->pio_queue->intf;
+       struct recv_priv *recvpriv = &(adapter->recvpriv);
 
-       precvpriv->ff_hwaddr = RTL8712_DMA_RX0FF; /* mapping rx fifo address */
+       recvpriv->ff_hwaddr = RTL8712_DMA_RX0FF; /* mapping rx fifo address */
        /* issue Rx irp to receive data */
-       precvbuf = (struct recv_buf *)precvpriv->precv_buf;
+       recvbuf = (struct recv_buf *)recvpriv->precv_buf;
        for (i = 0; i < NR_RECVBUFF; i++) {
-               if (r8712_usb_read_port(pintfhdl, precvpriv->ff_hwaddr, 0,
-                  (unsigned char *)precvbuf) == false)
+               if (r8712_usb_read_port(intfhdl, recvpriv->ff_hwaddr, 0,
+                                       (unsigned char *)recvbuf) == false)
                        return _FAIL;
-               precvbuf++;
-               precvpriv->free_recv_buf_queue_cnt--;
+               recvbuf++;
+               recvpriv->free_recv_buf_queue_cnt--;
        }
        return _SUCCESS;
 }
 
-unsigned int r8712_usb_inirp_deinit(struct _adapter *padapter)
+unsigned int r8712_usb_inirp_deinit(struct _adapter *adapter)
 {
-       r8712_usb_read_port_cancel(padapter);
+       r8712_usb_read_port_cancel(adapter);
        return _SUCCESS;
 }
index 7478bbd3de78c6b6e47b6de852ee613520594b73..d0daae0b8299c56b09ee6a5513e8f463c24493d8 100644 (file)
@@ -246,7 +246,7 @@ static uint r8712_usb_dvobj_init(struct _adapter *padapter)
        struct usb_device *pusbd = pdvobjpriv->pusbdev;
 
        pdvobjpriv->padapter = padapter;
-       padapter->EepromAddressSize = 6;
+       padapter->eeprom_address_size = 6;
        phost_iface = &pintf->altsetting[0];
        piface_desc = &phost_iface->desc;
        pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;
@@ -571,7 +571,7 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf,
        /* step 6. Load the firmware asynchronously */
        if (rtl871x_load_fw(padapter))
                goto error;
-       spin_lock_init(&padapter->lockRxFF0Filter);
+       spin_lock_init(&padapter->lock_rx_ff0_filter);
        mutex_init(&padapter->mutex_start);
        return 0;
 error:
index eef52d5c730a4ce7fc733b7e8b83a940e702195d..e64845e6adf3dbf2424595de689d63c22f00262f 100644 (file)
@@ -22,7 +22,7 @@
 #include "usb_ops.h"
 #include "recv_osdep.h"
 
-static u8 usb_read8(struct intf_hdl *pintfhdl, u32 addr)
+static u8 usb_read8(struct intf_hdl *intfhdl, u32 addr)
 {
        u8 request;
        u8 requesttype;
@@ -30,19 +30,19 @@ static u8 usb_read8(struct intf_hdl *pintfhdl, u32 addr)
        u16 index;
        u16 len;
        __le32 data;
-       struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
+       struct intf_priv *intfpriv = intfhdl->pintfpriv;
 
        request = 0x05;
        requesttype = 0x01; /* read_in */
        index = 0;
        wvalue = (u16)(addr & 0x0000ffff);
        len = 1;
-       r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
-                         requesttype);
+       r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
+                               requesttype);
        return (u8)(le32_to_cpu(data) & 0x0ff);
 }
 
-static u16 usb_read16(struct intf_hdl *pintfhdl, u32 addr)
+static u16 usb_read16(struct intf_hdl *intfhdl, u32 addr)
 {
        u8 request;
        u8 requesttype;
@@ -50,19 +50,19 @@ static u16 usb_read16(struct intf_hdl *pintfhdl, u32 addr)
        u16 index;
        u16 len;
        __le32 data;
-       struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
+       struct intf_priv *intfpriv = intfhdl->pintfpriv;
 
        request = 0x05;
        requesttype = 0x01; /* read_in */
        index = 0;
        wvalue = (u16)(addr & 0x0000ffff);
        len = 2;
-       r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
-                         requesttype);
+       r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
+                               requesttype);
        return (u16)(le32_to_cpu(data) & 0xffff);
 }
 
-static u32 usb_read32(struct intf_hdl *pintfhdl, u32 addr)
+static u32 usb_read32(struct intf_hdl *intfhdl, u32 addr)
 {
        u8 request;
        u8 requesttype;
@@ -70,19 +70,19 @@ static u32 usb_read32(struct intf_hdl *pintfhdl, u32 addr)
        u16 index;
        u16 len;
        __le32 data;
-       struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
+       struct intf_priv *intfpriv = intfhdl->pintfpriv;
 
        request = 0x05;
        requesttype = 0x01; /* read_in */
        index = 0;
        wvalue = (u16)(addr & 0x0000ffff);
        len = 4;
-       r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
-                         requesttype);
+       r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
+                               requesttype);
        return le32_to_cpu(data);
 }
 
-static void usb_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val)
+static void usb_write8(struct intf_hdl *intfhdl, u32 addr, u8 val)
 {
        u8 request;
        u8 requesttype;
@@ -90,7 +90,7 @@ static void usb_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val)
        u16 index;
        u16 len;
        __le32 data;
-       struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
+       struct intf_priv *intfpriv = intfhdl->pintfpriv;
 
        request = 0x05;
        requesttype = 0x00; /* write_out */
@@ -98,11 +98,11 @@ static void usb_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val)
        wvalue = (u16)(addr & 0x0000ffff);
        len = 1;
        data = cpu_to_le32((u32)val & 0x000000ff);
-       r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
-                         requesttype);
+       r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
+                               requesttype);
 }
 
-static void usb_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val)
+static void usb_write16(struct intf_hdl *intfhdl, u32 addr, u16 val)
 {
        u8 request;
        u8 requesttype;
@@ -110,7 +110,7 @@ static void usb_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val)
        u16 index;
        u16 len;
        __le32 data;
-       struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
+       struct intf_priv *intfpriv = intfhdl->pintfpriv;
 
        request = 0x05;
        requesttype = 0x00; /* write_out */
@@ -118,11 +118,11 @@ static void usb_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val)
        wvalue = (u16)(addr & 0x0000ffff);
        len = 2;
        data = cpu_to_le32((u32)val & 0x0000ffff);
-       r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
-                         requesttype);
+       r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
+                               requesttype);
 }
 
-static void usb_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val)
+static void usb_write32(struct intf_hdl *intfhdl, u32 addr, u32 val)
 {
        u8 request;
        u8 requesttype;
@@ -130,7 +130,7 @@ static void usb_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val)
        u16 index;
        u16 len;
        __le32 data;
-       struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
+       struct intf_priv *intfpriv = intfhdl->pintfpriv;
 
        request = 0x05;
        requesttype = 0x00; /* write_out */
@@ -138,13 +138,13 @@ static void usb_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val)
        wvalue = (u16)(addr & 0x0000ffff);
        len = 4;
        data = cpu_to_le32(val);
-       r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
-                         requesttype);
+       r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
+                               requesttype);
 }
 
-void r8712_usb_set_intf_option(u32 *poption)
+void r8712_usb_set_intf_option(u32 *option)
 {
-       *poption = ((*poption) | _INTF_ASYNC_);
+       *option = ((*option) | _INTF_ASYNC_);
 }
 
 static void usb_intf_hdl_init(u8 *priv)
@@ -163,24 +163,24 @@ static void usb_intf_hdl_close(u8 *priv)
 {
 }
 
-void r8712_usb_set_intf_funs(struct intf_hdl *pintf_hdl)
+void r8712_usb_set_intf_funs(struct intf_hdl *intfhdl)
 {
-       pintf_hdl->intf_hdl_init = usb_intf_hdl_init;
-       pintf_hdl->intf_hdl_unload = usb_intf_hdl_unload;
-       pintf_hdl->intf_hdl_open = usb_intf_hdl_open;
-       pintf_hdl->intf_hdl_close = usb_intf_hdl_close;
+       intfhdl->intf_hdl_init = usb_intf_hdl_init;
+       intfhdl->intf_hdl_unload = usb_intf_hdl_unload;
+       intfhdl->intf_hdl_open = usb_intf_hdl_open;
+       intfhdl->intf_hdl_close = usb_intf_hdl_close;
 }
 
-void r8712_usb_set_intf_ops(struct _io_ops     *pops)
+void r8712_usb_set_intf_ops(struct _io_ops *ops)
 {
-       memset((u8 *)pops, 0, sizeof(struct _io_ops));
-       pops->_read8 = usb_read8;
-       pops->_read16 = usb_read16;
-       pops->_read32 = usb_read32;
-       pops->_read_port = r8712_usb_read_port;
-       pops->_write8 = usb_write8;
-       pops->_write16 = usb_write16;
-       pops->_write32 = usb_write32;
-       pops->_write_mem = r8712_usb_write_mem;
-       pops->_write_port = r8712_usb_write_port;
+       memset((u8 *)ops, 0, sizeof(struct _io_ops));
+       ops->_read8 = usb_read8;
+       ops->_read16 = usb_read16;
+       ops->_read32 = usb_read32;
+       ops->_read_port = r8712_usb_read_port;
+       ops->_write8 = usb_write8;
+       ops->_write16 = usb_write16;
+       ops->_write32 = usb_write32;
+       ops->_write_mem = r8712_usb_write_mem;
+       ops->_write_port = r8712_usb_write_port;
 }
index 77346debea0377d9a83a9810e5df9d2bb3ec1990..1a5b966a167ecc4fc5fef302dacb7476a1a594dd 100644 (file)
@@ -278,17 +278,6 @@ static inline unsigned char get_tofr_ds(unsigned char *pframe)
 
 #define GetAddr4Ptr(pbuf)      ((unsigned char *)((addr_t)(pbuf) + 24))
 
-
-
-static inline int IS_MCAST(unsigned char *da)
-{
-       if ((*da) & 0x01)
-               return true;
-       else
-               return false;
-}
-
-
 static inline unsigned char *get_da(unsigned char *pframe)
 {
        unsigned char   *da;
index 8bcb0775411fbaed92730e7a2fbe5e927b1fba0d..01d713d027b0b695ae030d3ae3693994b6b965c1 100644 (file)
@@ -93,22 +93,22 @@ void r8712_set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
 
 void r8712_SetFilter(struct work_struct *work)
 {
-       struct _adapter *padapter = container_of(work, struct _adapter,
-                                               wkFilterRxFF0);
+       struct _adapter *adapter = container_of(work, struct _adapter,
+                                               wk_filter_rx_ff0);
        u8  oldvalue = 0x00, newvalue = 0x00;
        unsigned long irqL;
 
-       oldvalue = r8712_read8(padapter, 0x117);
+       oldvalue = r8712_read8(adapter, 0x117);
        newvalue = oldvalue & 0xfe;
-       r8712_write8(padapter, 0x117, newvalue);
+       r8712_write8(adapter, 0x117, newvalue);
 
-       spin_lock_irqsave(&padapter->lockRxFF0Filter, irqL);
-       padapter->blnEnableRxFF0Filter = 1;
-       spin_unlock_irqrestore(&padapter->lockRxFF0Filter, irqL);
+       spin_lock_irqsave(&adapter->lock_rx_ff0_filter, irqL);
+       adapter->blnEnableRxFF0Filter = 1;
+       spin_unlock_irqrestore(&adapter->lock_rx_ff0_filter, irqL);
        do {
                msleep(100);
-       } while (padapter->blnEnableRxFF0Filter == 1);
-       r8712_write8(padapter, 0x117, oldvalue);
+       } while (adapter->blnEnableRxFF0Filter == 1);
+       r8712_write8(adapter, 0x117, oldvalue);
 }
 
 int r8712_xmit_resource_alloc(struct _adapter *padapter,
@@ -120,11 +120,11 @@ int r8712_xmit_resource_alloc(struct _adapter *padapter,
                pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
                if (!pxmitbuf->pxmit_urb[i]) {
                        netdev_err(padapter->pnetdev, "pxmitbuf->pxmit_urb[i] == NULL\n");
-                       return _FAIL;
+                       return -ENOMEM;
                }
                kmemleak_not_leak(pxmitbuf->pxmit_urb[i]);
        }
-       return _SUCCESS;
+       return 0;
 }
 
 void r8712_xmit_resource_free(struct _adapter *padapter,
@@ -147,36 +147,36 @@ void r8712_xmit_complete(struct _adapter *padapter, struct xmit_frame *pxframe)
        pxframe->pkt = NULL;
 }
 
-int r8712_xmit_entry(_pkt *pkt, struct  net_device *pnetdev)
+int r8712_xmit_entry(_pkt *pkt, struct  net_device *netdev)
 {
-       struct xmit_frame *pxmitframe = NULL;
-       struct _adapter *padapter = netdev_priv(pnetdev);
-       struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
+       struct xmit_frame *xmitframe = NULL;
+       struct _adapter *adapter = netdev_priv(netdev);
+       struct xmit_priv *xmitpriv = &(adapter->xmitpriv);
 
-       if (!r8712_if_up(padapter))
+       if (!r8712_if_up(adapter))
                goto _xmit_entry_drop;
 
-       pxmitframe = r8712_alloc_xmitframe(pxmitpriv);
-       if (!pxmitframe)
+       xmitframe = r8712_alloc_xmitframe(xmitpriv);
+       if (!xmitframe)
                goto _xmit_entry_drop;
 
-       if ((!r8712_update_attrib(padapter, pkt, &pxmitframe->attrib)))
+       if ((!r8712_update_attrib(adapter, pkt, &xmitframe->attrib)))
                goto _xmit_entry_drop;
 
-       padapter->ledpriv.LedControlHandler(padapter, LED_CTL_TX);
-       pxmitframe->pkt = pkt;
-       if (r8712_pre_xmit(padapter, pxmitframe)) {
+       adapter->ledpriv.LedControlHandler(adapter, LED_CTL_TX);
+       xmitframe->pkt = pkt;
+       if (r8712_pre_xmit(adapter, xmitframe)) {
                /*dump xmitframe directly or drop xframe*/
                dev_kfree_skb_any(pkt);
-               pxmitframe->pkt = NULL;
+               xmitframe->pkt = NULL;
        }
-       pxmitpriv->tx_pkts++;
-       pxmitpriv->tx_bytes += pxmitframe->attrib.last_txcmdsz;
+       xmitpriv->tx_pkts++;
+       xmitpriv->tx_bytes += xmitframe->attrib.last_txcmdsz;
        return 0;
 _xmit_entry_drop:
-       if (pxmitframe)
-               r8712_free_xmitframe(pxmitpriv, pxmitframe);
-       pxmitpriv->tx_drop++;
+       if (xmitframe)
+               r8712_free_xmitframe(xmitpriv, xmitframe);
+       xmitpriv->tx_drop++;
        dev_kfree_skb_any(pkt);
        return 0;
 }
index 744091d46f4c936514f2792a4b0ba9f8679f6377..a88467334dacc6b60527e82a1ba4bbc872ff32a4 100644 (file)
@@ -5,7 +5,7 @@ config RTL8723BS
        depends on m
        select WIRELESS_EXT
        select WEXT_PRIV
-       ---help---
+       help
        This option enables support for RTL8723BS SDIO drivers, such as
        the wifi found on the 1st gen Intel Compute Stick, the CHIP
        and many other Intel Atom and ARM based devices.
index 58e02f944b6dc0db5efcacd5caa3823d876bcc28..45065fd3fd5d5a08e4b18835346e814c9db64531 100644 (file)
@@ -12,5 +12,4 @@ TODO:
 - switch to use MAC80211
 
 Please send any patches to Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
-Bastien Nocera <hadess@hadess.net>, Hans de Goede <hdegoede@redhat.com>
-and Larry Finger <Larry.Finger@lwfinger.net>.
+Hans de Goede <hdegoede@redhat.com> and Larry Finger <Larry.Finger@lwfinger.net>.
index bc023067245752be2065b81ee740d5de2a286530..7bd5c61b055c9e2528e99f6ad04629777abbe8cb 100644 (file)
@@ -443,7 +443,7 @@ void add_RATid(struct adapter *padapter, struct sta_info *psta, u8 rssi_level)
        }
 
        psta->wireless_mode = sta_band;
-       psta->raid = rtw_hal_networktype_to_raid(padapter, psta);
+       psta->raid = networktype_to_raid_ex(padapter, psta);
 
        if (psta->aid < NUM_STA) {
                u8 arg[4] = {0};
@@ -512,7 +512,7 @@ void update_bmc_sta(struct adapter *padapter)
                rtw_hal_update_sta_rate_mask(padapter, psta);
                tx_ra_bitmap = psta->ra_mask;
 
-               psta->raid = rtw_hal_networktype_to_raid(padapter, psta);
+               psta->raid = networktype_to_raid_ex(padapter, psta);
 
                /* ap mode */
                rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, true);
@@ -1394,10 +1394,9 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr)
        return ret;
 }
 
-int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr)
+void rtw_acl_remove_sta(struct adapter *padapter, u8 *addr)
 {
        struct list_head        *plist, *phead;
-       int ret = 0;
        struct rtw_wlan_acl_node *paclnode;
        struct sta_priv *pstapriv = &padapter->stapriv;
        struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
@@ -1438,7 +1437,6 @@ int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr)
 
        DBG_871X("%s, acl_num =%d\n", __func__, pacl_list->num);
 
-       return ret;
 }
 
 u8 rtw_ap_set_pairwise_key(struct adapter *padapter, struct sta_info *psta)
@@ -1504,8 +1502,6 @@ static int rtw_ap_set_key(
                goto exit;
        }
 
-       memset(psetkeyparm, 0, sizeof(struct setkey_parm));
-
        psetkeyparm->keyid = (u8)keyid;
        if (is_wep_enc(alg))
                padapter->securitypriv.key_mask |= BIT(psetkeyparm->keyid);
@@ -1914,7 +1910,7 @@ static int rtw_ht_operation_update(struct adapter *padapter)
 
 void associated_clients_update(struct adapter *padapter, u8 updated)
 {
-       /* update associcated stations cap. */
+       /* update associated stations cap. */
        if (updated) {
                struct list_head        *phead, *plist;
                struct sta_info *psta = NULL;
@@ -2072,7 +2068,7 @@ void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta)
                update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, true);
        }
 
-       /* update associcated stations cap. */
+       /* update associated stations cap. */
        associated_clients_update(padapter,  beacon_updated);
 
        DBG_871X("%s, updated =%d\n", __func__, beacon_updated);
@@ -2136,7 +2132,7 @@ u8 bss_cap_update_on_sta_leave(struct adapter *padapter, struct sta_info *psta)
                update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, true);
        }
 
-       /* update associcated stations cap. */
+       /* update associated stations cap. */
        /* associated_clients_update(padapter,  beacon_updated); //move it to avoid deadlock */
 
        DBG_871X("%s, updated =%d\n", __func__, beacon_updated);
@@ -2156,7 +2152,7 @@ u8 ap_free_sta(
        if (!psta)
                return beacon_updated;
 
-       if (active == true) {
+       if (active) {
                /* tear down Rx AMPDU */
                send_delba(padapter, 0, psta->hwaddr);/*  recipient */
 
@@ -2189,10 +2185,9 @@ u8 ap_free_sta(
        return beacon_updated;
 }
 
-int rtw_sta_flush(struct adapter *padapter)
+void rtw_sta_flush(struct adapter *padapter)
 {
        struct list_head        *phead, *plist;
-       int ret = 0;
        struct sta_info *psta = NULL;
        struct sta_priv *pstapriv = &padapter->stapriv;
        struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
@@ -2202,7 +2197,7 @@ int rtw_sta_flush(struct adapter *padapter)
        DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
 
        if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
-               return ret;
+               return;
 
        spin_lock_bh(&pstapriv->asoc_list_lock);
        phead = &pstapriv->asoc_list;
@@ -2226,8 +2221,6 @@ int rtw_sta_flush(struct adapter *padapter)
        issue_deauth(padapter, bc_addr, WLAN_REASON_DEAUTH_LEAVING);
 
        associated_clients_update(padapter, true);
-
-       return ret;
 }
 
 /* called > TSR LEVEL for USB or SDIO Interface*/
index 35310e8e0806008e836f86a44558b306bd371a9f..44219b7b61235d2bf881f5c3204321c628979709 100644 (file)
@@ -9,42 +9,6 @@
 #include <rtw_btcoex.h>
 #include <hal_btcoex.h>
 
-
-void rtw_btcoex_Initialize(struct adapter *padapter)
-{
-       hal_btcoex_Initialize(padapter);
-}
-
-void rtw_btcoex_PowerOnSetting(struct adapter *padapter)
-{
-       hal_btcoex_PowerOnSetting(padapter);
-}
-
-void rtw_btcoex_HAL_Initialize(struct adapter *padapter, u8 bWifiOnly)
-{
-       hal_btcoex_InitHwConfig(padapter, bWifiOnly);
-}
-
-void rtw_btcoex_IpsNotify(struct adapter *padapter, u8 type)
-{
-       hal_btcoex_IpsNotify(padapter, type);
-}
-
-void rtw_btcoex_LpsNotify(struct adapter *padapter, u8 type)
-{
-       hal_btcoex_LpsNotify(padapter, type);
-}
-
-void rtw_btcoex_ScanNotify(struct adapter *padapter, u8 type)
-{
-       hal_btcoex_ScanNotify(padapter, type);
-}
-
-void rtw_btcoex_ConnectNotify(struct adapter *padapter, u8 action)
-{
-       hal_btcoex_ConnectNotify(padapter, action);
-}
-
 void rtw_btcoex_MediaStatusNotify(struct adapter *padapter, u8 mediaStatus)
 {
        if ((mediaStatus == RT_MEDIA_CONNECT)
@@ -55,26 +19,6 @@ void rtw_btcoex_MediaStatusNotify(struct adapter *padapter, u8 mediaStatus)
        hal_btcoex_MediaStatusNotify(padapter, mediaStatus);
 }
 
-void rtw_btcoex_SpecialPacketNotify(struct adapter *padapter, u8 pktType)
-{
-       hal_btcoex_SpecialPacketNotify(padapter, pktType);
-}
-
-void rtw_btcoex_IQKNotify(struct adapter *padapter, u8 state)
-{
-       hal_btcoex_IQKNotify(padapter, state);
-}
-
-void rtw_btcoex_BtInfoNotify(struct adapter *padapter, u8 length, u8 *tmpBuf)
-{
-       hal_btcoex_BtInfoNotify(padapter, length, tmpBuf);
-}
-
-void rtw_btcoex_SuspendNotify(struct adapter *padapter, u8 state)
-{
-       hal_btcoex_SuspendNotify(padapter, state);
-}
-
 void rtw_btcoex_HaltNotify(struct adapter *padapter)
 {
        if (!padapter->bup) {
@@ -94,95 +38,6 @@ void rtw_btcoex_HaltNotify(struct adapter *padapter)
        hal_btcoex_HaltNotify(padapter);
 }
 
-u8 rtw_btcoex_IsBtDisabled(struct adapter *padapter)
-{
-       return hal_btcoex_IsBtDisabled(padapter);
-}
-
-void rtw_btcoex_Handler(struct adapter *padapter)
-{
-       hal_btcoex_Hanlder(padapter);
-}
-
-s32 rtw_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *padapter)
-{
-       s32 coexctrl;
-
-       coexctrl = hal_btcoex_IsBTCoexCtrlAMPDUSize(padapter);
-
-       return coexctrl;
-}
-
-void rtw_btcoex_SetManualControl(struct adapter *padapter, u8 manual)
-{
-       hal_btcoex_SetManualControl(padapter, manual);
-}
-
-u8 rtw_btcoex_IsBtControlLps(struct adapter *padapter)
-{
-       return hal_btcoex_IsBtControlLps(padapter);
-}
-
-u8 rtw_btcoex_IsLpsOn(struct adapter *padapter)
-{
-       return hal_btcoex_IsLpsOn(padapter);
-}
-
-u8 rtw_btcoex_RpwmVal(struct adapter *padapter)
-{
-       return hal_btcoex_RpwmVal(padapter);
-}
-
-u8 rtw_btcoex_LpsVal(struct adapter *padapter)
-{
-       return hal_btcoex_LpsVal(padapter);
-}
-
-void rtw_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist)
-{
-       hal_btcoex_SetBTCoexist(padapter, bBtExist);
-}
-
-void rtw_btcoex_SetChipType(struct adapter *padapter, u8 chipType)
-{
-       hal_btcoex_SetChipType(padapter, chipType);
-}
-
-void rtw_btcoex_SetPGAntNum(struct adapter *padapter, u8 antNum)
-{
-       hal_btcoex_SetPgAntNum(padapter, antNum);
-}
-
-void rtw_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath)
-{
-       hal_btcoex_SetSingleAntPath(padapter, singleAntPath);
-}
-
-u32 rtw_btcoex_GetRaMask(struct adapter *padapter)
-{
-       return hal_btcoex_GetRaMask(padapter);
-}
-
-void rtw_btcoex_RecordPwrMode(struct adapter *padapter, u8 *pCmdBuf, u8 cmdLen)
-{
-       hal_btcoex_RecordPwrMode(padapter, pCmdBuf, cmdLen);
-}
-
-void rtw_btcoex_DisplayBtCoexInfo(struct adapter *padapter, u8 *pbuf, u32 bufsize)
-{
-       hal_btcoex_DisplayBtCoexInfo(padapter, pbuf, bufsize);
-}
-
-void rtw_btcoex_SetDBG(struct adapter *padapter, u32 *pDbgModule)
-{
-       hal_btcoex_SetDBG(padapter, pDbgModule);
-}
-
-u32 rtw_btcoex_GetDBG(struct adapter *padapter, u8 *pStrBuf, u32 bufSize)
-{
-       return hal_btcoex_GetDBG(padapter, pStrBuf, bufSize);
-}
-
 /*  ================================================== */
 /*  Below Functions are called by BT-Coex */
 /*  ================================================== */
@@ -212,7 +67,7 @@ void rtw_btcoex_LPS_Enter(struct adapter *padapter)
        pwrpriv = adapter_to_pwrctl(padapter);
 
        pwrpriv->bpower_saving = true;
-       lpsVal = rtw_btcoex_LpsVal(padapter);
+       lpsVal = hal_btcoex_LpsVal(padapter);
        rtw_set_ps_mode(padapter, PS_MODE_MIN, 0, lpsVal, "BTCOEX");
 }
 
index ecaa769f12e68363d718f20ecce7437c5f1a92dc..addc55706a3ca903f2d56afde2cbaf9ea201e5e9 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <drv_types.h>
 #include <rtw_debug.h>
+#include <hal_btcoex.h>
 #include <linux/jiffies.h>
 
 static struct _cmd_callback rtw_cmd_callback[] = {
@@ -1439,7 +1440,7 @@ static void dynamic_chk_wk_hdl(struct adapter *padapter)
        /*  */
        /*  BT-Coexist */
        /*  */
-       rtw_btcoex_Handler(padapter);
+       hal_btcoex_Handler(padapter);
 
 
        /* always call rtw_ps_processor() at last one. */
@@ -1462,7 +1463,7 @@ void lps_ctrl_wk_hdl(struct adapter *padapter, u8 lps_ctrl_type)
        switch (lps_ctrl_type) {
        case LPS_CTRL_SCAN:
                /* DBG_871X("LPS_CTRL_SCAN\n"); */
-               rtw_btcoex_ScanNotify(padapter, true);
+               hal_btcoex_ScanNotify(padapter, true);
 
                if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
                        /*  connect */
@@ -1491,7 +1492,7 @@ void lps_ctrl_wk_hdl(struct adapter *padapter, u8 lps_ctrl_type)
        case LPS_CTRL_SPECIAL_PACKET:
                /* DBG_871X("LPS_CTRL_SPECIAL_PACKET\n"); */
                pwrpriv->DelayLPSLastTimeStamp = jiffies;
-               rtw_btcoex_SpecialPacketNotify(padapter, PACKET_DHCP);
+               hal_btcoex_SpecialPacketNotify(padapter, PACKET_DHCP);
                LPS_Leave(padapter, "LPS_CTRL_SPECIAL_PACKET");
                break;
        case LPS_CTRL_LEAVE:
@@ -1594,7 +1595,7 @@ static void rtw_lps_change_dtim_hdl(struct adapter *padapter, u8 dtim)
        if (dtim <= 0 || dtim > 16)
                return;
 
-       if (rtw_btcoex_IsBtControlLps(padapter) == true)
+       if (hal_btcoex_IsBtControlLps(padapter) == true)
                return;
 
        mutex_lock(&pwrpriv->lock);
@@ -1660,22 +1661,6 @@ exit:
 
 }
 
-static void power_saving_wk_hdl(struct adapter *padapter)
-{
-        rtw_ps_processor(padapter);
-}
-
-/* add for CONFIG_IEEE80211W, none 11w can use it */
-static void reset_securitypriv_hdl(struct adapter *padapter)
-{
-        rtw_reset_securitypriv(padapter);
-}
-
-static void free_assoc_resources_hdl(struct adapter *padapter)
-{
-        rtw_free_assoc_resources(padapter, 1);
-}
-
 u8 rtw_ps_cmd(struct adapter *padapter)
 {
        struct cmd_obj          *ppscmd;
@@ -1738,7 +1723,7 @@ static void rtw_chk_hi_queue_hdl(struct adapter *padapter)
                        pstapriv->tim_bitmap &= ~BIT(0);
                        pstapriv->sta_dz_bitmap &= ~BIT(0);
 
-                       if (update_tim == true)
+                       if (update_tim)
                                update_beacon(padapter, _TIM_IE_, NULL, true);
                } else {/* re check again */
                        rtw_chk_hi_queue_cmd(padapter);
@@ -1844,7 +1829,7 @@ static void rtw_btinfo_hdl(struct adapter *adapter, u8 *buf, u16 buf_len)
                buf[1] = 0;
        else if (cmd_idx == BTINFO_BT_AUTO_RPT)
                buf[1] = 2;
-       rtw_btcoex_BtInfoNotify(adapter, len+1, &buf[1]);
+       hal_btcoex_BtInfoNotify(adapter, len+1, &buf[1]);
 }
 
 u8 rtw_c2h_packet_wk_cmd(struct adapter *padapter, u8 *pbuf, u16 length)
@@ -1934,7 +1919,7 @@ static void c2h_wk_callback(_workitem *work)
                        c2h_evt = rtw_malloc(16);
                        if (c2h_evt != NULL) {
                                /* This C2H event is not read, read & clear now */
-                               if (rtw_hal_c2h_evt_read(adapter, c2h_evt) != _SUCCESS) {
+                               if (c2h_evt_read_88xx(adapter, c2h_evt) != _SUCCESS) {
                                        kfree(c2h_evt);
                                        continue;
                                }
@@ -1977,7 +1962,7 @@ u8 rtw_drvextra_cmd_hdl(struct adapter *padapter, unsigned char *pbuf)
                dynamic_chk_wk_hdl(padapter);
                break;
        case POWER_SAVING_CTRL_WK_CID:
-               power_saving_wk_hdl(padapter);
+               rtw_ps_processor(padapter);
                break;
        case LPS_CTRL_WK_CID:
                lps_ctrl_wk_hdl(padapter, (u8)pdrvextra_cmd->type);
@@ -1993,10 +1978,10 @@ u8 rtw_drvextra_cmd_hdl(struct adapter *padapter, unsigned char *pbuf)
                break;
        /* add for CONFIG_IEEE80211W, none 11w can use it */
        case RESET_SECURITYPRIV:
-               reset_securitypriv_hdl(padapter);
+               rtw_reset_securitypriv(padapter);
                break;
        case FREE_ASSOC_RESOURCES:
-               free_assoc_resources_hdl(padapter);
+               rtw_free_assoc_resources(padapter, 1);
                break;
        case C2H_WK_CID:
                rtw_hal_set_hwreg_with_buf(padapter, HW_VAR_C2H_HANDLE, pdrvextra_cmd->pbuf, pdrvextra_cmd->size);
index 9f8446ccf771363ecdb74078e8d6955a62f61faa..695a85999270946751b3650906efff3d9c053a11 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <drv_types.h>
 #include <rtw_debug.h>
+#include <hal_btcoex.h>
 
 u32 GlobalDebugLevel = _drv_err_;
 
@@ -1350,7 +1351,7 @@ int proc_get_btcoex_dbg(struct seq_file *m, void *v)
        char buf[512] = {0};
        padapter = (struct adapter *)rtw_netdev_priv(dev);
 
-       rtw_btcoex_GetDBG(padapter, buf, 512);
+       hal_btcoex_GetDBG(padapter, buf, 512);
 
        DBG_871X_SEL(m, "%s", buf);
 
@@ -1410,7 +1411,7 @@ ssize_t proc_set_btcoex_dbg(struct file *file, const char __user *buffer, size_t
 
        DBG_871X(FUNC_ADPT_FMT ": input 0x%08X 0x%08X\n",
                FUNC_ADPT_ARG(padapter), module[0], module[1]);
-       rtw_btcoex_SetDBG(padapter, module);
+       hal_btcoex_SetDBG(padapter, module);
 
        return count;
 }
@@ -1428,7 +1429,7 @@ int proc_get_btcoex_info(struct seq_file *m, void *v)
        if (!pbuf)
                return -ENOMEM;
 
-       rtw_btcoex_DisplayBtCoexInfo(padapter, pbuf, bufsize);
+       hal_btcoex_DisplayBtCoexInfo(padapter, pbuf, bufsize);
 
        DBG_871X_SEL(m, "%s\n", pbuf);
 
index 5eea02cfce1f6cfe4328a7b140ee9f97ad3cd7e3..3cbd65dee741b1adfe31fd728e78a49c0f12c62b 100644 (file)
@@ -118,25 +118,6 @@ _func_enter_;
 _func_exit_;
 }
 
-u16 wait_eeprom_cmd_done(_adapter *padapter)
-{
-       u8 x;
-       u16 i, res = false;
-_func_enter_;
-       standby(padapter);
-       for (i = 0; i < 200; i++) {
-               x = rtw_read8(padapter, EE_9346CR);
-               if (x & _EEDO) {
-                       res = true;
-                       goto exit;
-                       }
-               udelay(CLOCK_RATE);
-       }
-exit:
-_func_exit_;
-       return res;
-}
-
 void eeprom_clean(_adapter *padapter)
 {
        u16 x;
@@ -166,68 +147,6 @@ out:
 _func_exit_;
 }
 
-void eeprom_write16(_adapter *padapter, u16 reg, u16 data)
-{
-       u8 x;
-
-_func_enter_;
-
-       x = rtw_read8(padapter, EE_9346CR);
-
-       x &= ~(_EEDI | _EEDO | _EESK | _EEM0);
-       x |= _EEM1 | _EECS;
-       rtw_write8(padapter, EE_9346CR, x);
-
-       shift_out_bits(padapter, EEPROM_EWEN_OPCODE, 5);
-
-       if (padapter->EepromAddressSize == 8)   /*CF+ and SDIO*/
-               shift_out_bits(padapter, 0, 6);
-       else                                                                    /*USB*/
-               shift_out_bits(padapter, 0, 4);
-
-       standby(padapter);
-
-/* Commented out by rcnjko, 2004.0
-*       Erase this particular word.  Write the erase opcode and register
-*       number in that order. The opcode is 3bits in length; reg is 6 bits long.
-*      shift_out_bits(Adapter, EEPROM_ERASE_OPCODE, 3);
-*      shift_out_bits(Adapter, reg, Adapter->EepromAddressSize);
-*
-*      if (wait_eeprom_cmd_done(Adapter ) == false)
-*      {
-*              return;
-*      }
-*/
-
-       standby(padapter);
-
-       /* write the new word to the EEPROM*/
-
-       /* send the write opcode the EEPORM*/
-       shift_out_bits(padapter, EEPROM_WRITE_OPCODE, 3);
-
-       /* select which word in the EEPROM that we are writing to.*/
-       shift_out_bits(padapter, reg, padapter->EepromAddressSize);
-
-       /* write the data to the selected EEPROM word.*/
-       shift_out_bits(padapter, data, 16);
-
-       if (wait_eeprom_cmd_done(padapter) == false) {
-
-               goto exit;
-       }
-
-       standby(padapter);
-
-       shift_out_bits(padapter, EEPROM_EWDS_OPCODE, 5);
-       shift_out_bits(padapter, reg, 4);
-
-       eeprom_clean(padapter);
-exit:
-_func_exit_;
-       return;
-}
-
 u16 eeprom_read16(_adapter *padapter, u16 reg) /*ReadEEprom*/
 {
 
@@ -268,53 +187,6 @@ _func_exit_;
 
 }
 
-
-
-
-/*From even offset*/
-void eeprom_read_sz(_adapter *padapter, u16 reg, u8 *data, u32 sz)
-{
-
-       u16 x, data16;
-       u32 i;
-_func_enter_;
-       if (padapter->bSurpriseRemoved == true) {
-               RT_TRACE(_module_rtl871x_eeprom_c_, _drv_err_, ("padapter->bSurpriseRemoved==true"));
-               goto out;
-       }
-       /* select EEPROM, reset bits, set _EECS*/
-       x = rtw_read8(padapter, EE_9346CR);
-
-       if (padapter->bSurpriseRemoved == true) {
-               RT_TRACE(_module_rtl871x_eeprom_c_, _drv_err_, ("padapter->bSurpriseRemoved==true"));
-               goto out;
-       }
-
-       x &= ~(_EEDI | _EEDO | _EESK | _EEM0);
-       x |= _EEM1 | _EECS;
-       rtw_write8(padapter, EE_9346CR, (unsigned char)x);
-
-       /* write the read opcode and register number in that order*/
-       /* The opcode is 3bits in length, reg is 6 bits long*/
-       shift_out_bits(padapter, EEPROM_READ_OPCODE, 3);
-       shift_out_bits(padapter, reg, padapter->EepromAddressSize);
-
-
-       for (i = 0; i < sz; i += 2) {
-               data16 = shift_in_bits(padapter);
-               data[i] = data16 & 0xff;
-               data[i+1] = data16 >> 8;
-       }
-
-       eeprom_clean(padapter);
-out:
-_func_exit_;
-
-
-
-}
-
-
 /*addr_off : address offset of the entry in eeprom (not the tuple number of eeprom (reg); that is addr_off !=reg)*/
 u8 eeprom_read(_adapter *padapter, u32 addr_off, u8 sz, u8 *rbuf)
 {
@@ -348,14 +220,3 @@ _func_enter_;
 _func_exit_;
        return true;
 }
-
-
-
-void read_eeprom_content(_adapter *padapter)
-{
-
-_func_enter_;
-
-
-_func_exit_;
-}
index aaf27438cd815c45a50f11525db3634bf0c4579e..6018d877a8a6c20f5cd526c4d6c85fd7787bd966 100644 (file)
@@ -654,7 +654,7 @@ int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len)
 }
 /* endif */
 
-int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len)
+void rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len)
 {
        u8 authmode, sec_idx, i;
        u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
@@ -705,8 +705,6 @@ int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie,
                        }
                }
        }
-
-       return *rsn_len + *wpa_len;
 }
 
 u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen)
index bd75bca1ac6eee4f3d57cdfbe69b8d7e4f7da5e8..8eb0ff57925f3d8ecc9e45f3e796f7f3140474a6 100644 (file)
@@ -357,7 +357,7 @@ u8 rtw_set_802_11_connect(struct adapter *padapter, u8 *bssid, struct ndis_802_1
        if (!bssid || rtw_validate_bssid(bssid) == false)
                bssid_valid = false;
 
-       if (ssid_valid == false && bssid_valid == false) {
+       if (!ssid_valid && !bssid_valid) {
                DBG_871X(FUNC_ADPT_FMT" ssid:%p, ssid_valid:%d, bssid:%p, bssid_valid:%d\n",
                        FUNC_ADPT_ARG(padapter), ssid, ssid_valid, bssid, bssid_valid);
                status = _FAIL;
index 5f78f1eaa7aabdab60bc7ddadb8099e226eb7571..34adf5789c982b9c3de6ef39f72a84f426dd6524 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/etherdevice.h>
 #include <drv_types.h>
 #include <rtw_debug.h>
+#include <hal_btcoex.h>
 #include <linux/jiffies.h>
 
 extern u8 rtw_do_join(struct adapter *padapter);
@@ -275,7 +276,7 @@ exit:
        return pnetwork;
 }
 
-void _rtw_free_network_queue(struct adapter *padapter, u8 isfreeall)
+void rtw_free_network_queue(struct adapter *padapter, u8 isfreeall)
 {
        struct list_head *phead, *plist;
        struct wlan_network *pnetwork;
@@ -375,12 +376,6 @@ void rtw_free_network_nolock(struct adapter *padapter, struct wlan_network *pnet
        rtw_cfg80211_unlink_bss(padapter, pnetwork);
 }
 
-
-void rtw_free_network_queue(struct adapter *dev, u8 isfreeall)
-{
-       _rtw_free_network_queue(dev, isfreeall);
-}
-
 /*
        return the wlan_network with the matching addr
 
@@ -1192,7 +1187,7 @@ static struct sta_info *rtw_joinbss_update_stainfo(struct adapter *padapter, str
                rtw_hal_update_sta_rate_mask(padapter, psta);
 
                psta->wireless_mode = pmlmeext->cur_wireless_mode;
-               psta->raid = rtw_hal_networktype_to_raid(padapter, psta);
+               psta->raid = networktype_to_raid_ex(padapter, psta);
 
 
                /* sta mode */
@@ -1672,7 +1667,7 @@ void rtw_stadel_event_callback(struct adapter *adapter, u8 *pbuf)
                        roam_target = pmlmepriv->roam_network;
                }
 
-               if (roam == true) {
+               if (roam) {
                        if (rtw_to_roam(adapter) > 0)
                                rtw_dec_to_roam(adapter); /* this stadel_event is caused by roaming, decrease to_roam */
                        else if (rtw_to_roam(adapter) == 0)
@@ -1894,10 +1889,10 @@ void rtw_dynamic_check_timer_handler(struct adapter *adapter)
                return;
 
        if (is_primary_adapter(adapter))
-               DBG_871X("IsBtDisabled =%d, IsBtControlLps =%d\n", rtw_btcoex_IsBtDisabled(adapter), rtw_btcoex_IsBtControlLps(adapter));
+               DBG_871X("IsBtDisabled =%d, IsBtControlLps =%d\n", hal_btcoex_IsBtDisabled(adapter), hal_btcoex_IsBtControlLps(adapter));
 
        if ((adapter_to_pwrctl(adapter)->bFwCurrentInPSMode == true)
-               && (rtw_btcoex_IsBtControlLps(adapter) == false)
+               && (hal_btcoex_IsBtControlLps(adapter) == false)
                ) {
                u8 bEnterPS;
 
@@ -1936,11 +1931,6 @@ inline void rtw_clear_scan_deny(struct adapter *adapter)
        DBG_871X(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(adapter));
 }
 
-void rtw_set_scan_deny_timer_hdl(struct adapter *adapter)
-{
-       rtw_clear_scan_deny(adapter);
-}
-
 void rtw_set_scan_deny(struct adapter *adapter, u32 ms)
 {
        struct mlme_priv *mlmepriv = &adapter->mlmepriv;
@@ -2229,7 +2219,6 @@ sint rtw_set_auth(struct adapter *adapter, struct security_priv *psecuritypriv)
                goto exit;
        }
 
-       memset(psetauthparm, 0, sizeof(struct setauth_parm));
        psetauthparm->mode = (unsigned char)psecuritypriv->dot11AuthAlgrthm;
 
        pcmd->cmdcode = _SetAuth_CMD_;
@@ -2262,7 +2251,6 @@ sint rtw_set_key(struct adapter *adapter, struct security_priv *psecuritypriv, s
                res = _FAIL;
                goto exit;
        }
-       memset(psetkeyparm, 0, sizeof(struct setkey_parm));
 
        if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) {
                psetkeyparm->algorithm = (unsigned char)psecuritypriv->dot118021XGrpPrivacy;
index d110d4514771a85ca94a64badde1506122086f89..4285844420cb8af97392821435ddc0ac8975b42e 100644 (file)
@@ -9,9 +9,9 @@
 #include <drv_types.h>
 #include <rtw_debug.h>
 #include <rtw_wifi_regd.h>
+#include <hal_btcoex.h>
 #include <linux/kernel.h>
 
-
 static struct mlme_handler mlme_sta_tbl[] = {
        {WIFI_ASSOCREQ,         "OnAssocReq",   &OnAssocReq},
        {WIFI_ASSOCRSP,         "OnAssocRsp",   &OnAssocRsp},
@@ -51,7 +51,6 @@ static struct action_handler OnAction_tbl[] = {
        {RTW_WLAN_CATEGORY_P2P, "ACTION_P2P", &DoReserved},
 };
 
-
 static u8 null_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
 
 /**************************************************
@@ -279,7 +278,7 @@ void init_mlme_default_rate_set(struct adapter *padapter)
 static void init_mlme_ext_priv_value(struct adapter *padapter)
 {
        struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
-       struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+       struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
 
        atomic_set(&pmlmeext->event_seq, 0);
        pmlmeext->mgnt_seq = 0;/* reset to zero when disconnect at client mode */
@@ -372,9 +371,8 @@ static void init_channel_list(struct adapter *padapter, RT_CHANNEL_INFO *channel
                struct p2p_reg_class *reg = NULL;
 
                for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
-                       if (!has_channel(channel_set, chanset_size, ch)) {
+                       if (!has_channel(channel_set, chanset_size, ch))
                                continue;
-                       }
 
                        if ((0 == padapter->registrypriv.ht_enable) && (8 == o->inc))
                                continue;
@@ -383,7 +381,7 @@ static void init_channel_list(struct adapter *padapter, RT_CHANNEL_INFO *channel
                                ((BW40MINUS == o->bw) || (BW40PLUS == o->bw)))
                                continue;
 
-                       if (reg == NULL) {
+                       if (!reg) {
                                reg = &channel_list->reg_class[cla];
                                cla++;
                                reg->reg_class = o->op_class;
@@ -466,8 +464,8 @@ int init_mlme_ext_priv(struct adapter *padapter)
        int     res = _SUCCESS;
        struct registry_priv *pregistrypriv = &padapter->registrypriv;
        struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
-       struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
-       struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
+       struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
+       struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
 
        pmlmeext->padapter = padapter;
 
@@ -611,8 +609,8 @@ unsigned int OnProbeReq(struct adapter *padapter, union recv_frame *precv_frame)
        unsigned char *p;
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
        struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
-       struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
-       struct wlan_bssid_ex    *cur = &(pmlmeinfo->network);
+       struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
+       struct wlan_bssid_ex    *cur = &pmlmeinfo->network;
        u8 *pframe = precv_frame->u.hdr.rx_data;
        uint len = precv_frame->u.hdr.len;
        u8 is_valid_p2p_probereq = false;
@@ -661,7 +659,7 @@ unsigned int OnProbeReq(struct adapter *padapter, union recv_frame *precv_frame)
                        /*  allocate a new one */
                        DBG_871X("going to alloc stainfo for rc ="MAC_FMT"\n",  MAC_ARG(get_sa(pframe)));
                        psta = rtw_alloc_stainfo(pstapriv, get_sa(pframe));
-                       if (psta == NULL) {
+                       if (!psta) {
                                /* TODO: */
                                DBG_871X(" Exceed the upper limit of supported clients...\n");
                                return _SUCCESS;
@@ -1219,7 +1217,7 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
        }
 
        pstat = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
-       if (pstat == NULL) {
+       if (!pstat) {
                status = _RSON_CLS2_;
                goto asoc_class2_error;
        }
@@ -1261,7 +1259,6 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
                goto OnAssocReqFail;
        }
 
-
        /*  now we should check all the fields... */
        /*  checking SSID */
        p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len,
@@ -1280,7 +1277,7 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
                        status = _STATS_FAILURE_;
        }
 
-       if (_STATS_SUCCESSFUL_ != status)
+       if (status != _STATS_SUCCESSFUL_)
                goto OnAssocReqFail;
 
        /*  check if the supported rate is ok */
@@ -1376,11 +1373,11 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
                wpa_ie_len = 0;
        }
 
-       if (_STATS_SUCCESSFUL_ != status)
+       if (status != _STATS_SUCCESSFUL_)
                goto OnAssocReqFail;
 
        pstat->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
-       if (wpa_ie == NULL) {
+       if (!wpa_ie) {
                if (elems.wps_ie) {
                        DBG_871X("STA included WPS IE in "
                                   "(Re)Association Request - assume WPS is "
@@ -1946,16 +1943,15 @@ unsigned int OnAction_back(struct adapter *padapter, union recv_frame *precv_fra
        addr = GetAddr2Ptr(pframe);
        psta = rtw_get_stainfo(pstapriv, addr);
 
-       if (psta == NULL)
+       if (!psta)
                return _SUCCESS;
 
        frame_body = (unsigned char *)(pframe + sizeof(struct ieee80211_hdr_3addr));
 
        category = frame_body[0];
        if (category == RTW_WLAN_CATEGORY_BACK) {/*  representing Block Ack */
-               if (!pmlmeinfo->HT_enable) {
+               if (!pmlmeinfo->HT_enable)
                        return _SUCCESS;
-               }
 
                action = frame_body[1];
                DBG_871X("%s, action =%d\n", __func__, action);
@@ -2400,9 +2396,8 @@ s32 dump_mgntframe_and_wait_ack(struct adapter *padapter, struct xmit_frame *pmg
                pxmitpriv->ack_tx = true;
                pxmitpriv->seq_no = seq_no++;
                pmgntframe->ack_report = 1;
-               if (rtw_hal_mgnt_xmit(padapter, pmgntframe) == _SUCCESS) {
+               if (rtw_hal_mgnt_xmit(padapter, pmgntframe) == _SUCCESS)
                        ret = rtw_ack_tx_wait(pxmitpriv, timeout_ms);
-               }
 
                pxmitpriv->ack_tx = false;
                mutex_unlock(&pxmitpriv->ack_tx_mutex);
@@ -2465,7 +2460,7 @@ void issue_beacon(struct adapter *padapter, int timeout_ms)
        /* DBG_871X("%s\n", __func__); */
 
        pmgntframe = alloc_mgtxmitframe(pxmitpriv);
-       if (pmgntframe == NULL) {
+       if (!pmgntframe) {
                DBG_871X("%s, alloc mgnt frame fail\n", __func__);
                return;
        }
@@ -2846,7 +2841,7 @@ static int _issue_probereq(struct adapter *padapter,
        RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_, ("+issue_probereq\n"));
 
        pmgntframe = alloc_mgtxmitframe(pxmitpriv);
-       if (pmgntframe == NULL)
+       if (!pmgntframe)
                goto exit;
 
        /* update attribute */
@@ -3219,7 +3214,6 @@ void issue_asocrsp(struct adapter *padapter, unsigned short status, struct sta_i
 
        }
 
-
        if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK) {
                pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 6, REALTEK_96B_IE, &(pattrib->pktlen));
        }
@@ -3264,7 +3258,6 @@ void issue_assocreq(struct adapter *padapter)
        pattrib = &pmgntframe->attrib;
        update_mgntframe_attrib(padapter, pattrib);
 
-
        memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
 
        pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
@@ -3914,7 +3907,7 @@ void issue_action_BA(struct adapter *padapter, unsigned char *raddr, unsigned ch
        DBG_871X("%s, category =%d, action =%d, status =%d\n", __func__, category, action, status);
 
        pmgntframe = alloc_mgtxmitframe(pxmitpriv);
-       if (pmgntframe == NULL)
+       if (!pmgntframe)
                return;
 
        /* update attribute */
@@ -3952,7 +3945,7 @@ void issue_action_BA(struct adapter *padapter, unsigned char *raddr, unsigned ch
                        } while (pmlmeinfo->dialogToken == 0);
                        pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->dialogToken), &(pattrib->pktlen));
 
-                       if (rtw_btcoex_IsBTCoexCtrlAMPDUSize(padapter)) {
+                       if (hal_btcoex_IsBTCoexCtrlAMPDUSize(padapter)) {
                                /*  A-MSDU NOT Supported */
                                BA_para_set = 0;
                                /*  immediate Block Ack */
@@ -4008,7 +4001,7 @@ void issue_action_BA(struct adapter *padapter, unsigned char *raddr, unsigned ch
                        else
                                BA_para_set = ((le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f) | 0x1000); /* 64 buffer size */
 
-                       if (rtw_btcoex_IsBTCoexCtrlAMPDUSize(padapter) &&
+                       if (hal_btcoex_IsBTCoexCtrlAMPDUSize(padapter) &&
                            padapter->driver_rx_ampdu_factor == 0xFF) {
                                /*  max buffer size is 8 MSDU */
                                BA_para_set &= ~RTW_IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK;
@@ -5038,12 +5031,12 @@ void report_survey_event(struct adapter *padapter, union recv_frame *precv_frame
        pcmdpriv = &padapter->cmdpriv;
 
        pcmd_obj = rtw_zmalloc(sizeof(struct cmd_obj));
-       if (pcmd_obj == NULL)
+       if (!pcmd_obj)
                return;
 
        cmdsz = (sizeof(struct survey_event) + sizeof(struct C2HEvent_Header));
        pevtcmd = rtw_zmalloc(cmdsz);
-       if (pevtcmd == NULL) {
+       if (!pevtcmd) {
                kfree(pcmd_obj);
                return;
        }
@@ -5091,12 +5084,12 @@ void report_surveydone_event(struct adapter *padapter)
        struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 
        pcmd_obj = rtw_zmalloc(sizeof(struct cmd_obj));
-       if (pcmd_obj == NULL)
+       if (!pcmd_obj)
                return;
 
        cmdsz = (sizeof(struct surveydone_event) + sizeof(struct C2HEvent_Header));
        pevtcmd = rtw_zmalloc(cmdsz);
-       if (pevtcmd == NULL) {
+       if (!pevtcmd) {
                kfree(pcmd_obj);
                return;
        }
@@ -5138,12 +5131,12 @@ void report_join_res(struct adapter *padapter, int res)
        struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 
        pcmd_obj = rtw_zmalloc(sizeof(struct cmd_obj));
-       if (pcmd_obj == NULL)
+       if (!pcmd_obj)
                return;
 
        cmdsz = (sizeof(struct joinbss_event) + sizeof(struct C2HEvent_Header));
        pevtcmd = rtw_zmalloc(cmdsz);
-       if (pevtcmd == NULL) {
+       if (!pevtcmd) {
                kfree(pcmd_obj);
                return;
        }
@@ -5189,12 +5182,12 @@ void report_wmm_edca_update(struct adapter *padapter)
        struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 
        pcmd_obj = rtw_zmalloc(sizeof(struct cmd_obj));
-       if (pcmd_obj == NULL)
+       if (!pcmd_obj)
                return;
 
        cmdsz = (sizeof(struct wmm_event) + sizeof(struct C2HEvent_Header));
        pevtcmd = rtw_zmalloc(cmdsz);
-       if (pevtcmd == NULL) {
+       if (!pevtcmd) {
                kfree(pcmd_obj);
                return;
        }
@@ -5571,7 +5564,7 @@ void mlmeext_sta_add_event_callback(struct adapter *padapter, struct sta_info *p
 
        /*  ToDo: HT for Ad-hoc */
        psta->wireless_mode = rtw_check_network_type(psta->bssrateset, psta->bssratelen, pmlmeext->cur_channel);
-       psta->raid = rtw_hal_networktype_to_raid(padapter, psta);
+       psta->raid = networktype_to_raid_ex(padapter, psta);
 
        /* rate radaptive */
        Update_RA_Entry(padapter, psta);
@@ -6044,7 +6037,7 @@ u8 setopmode_hdl(struct adapter *padapter, u8 *pbuf)
        }
 
        rtw_hal_set_hwreg(padapter, HW_VAR_SET_OPMODE, (u8 *)(&type));
-       /* Set_NETYPE0_MSR(padapter, type); */
+       /* Set_MSR(padapter, type); */
 
 
 #ifdef CONFIG_AUTO_AP_MODE
@@ -6436,9 +6429,8 @@ u8 setauth_hdl(struct adapter *padapter, unsigned char *pbuf)
        struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
        struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
 
-       if (pparm->mode < 4) {
+       if (pparm->mode < 4)
                pmlmeinfo->auth_algo = pparm->mode;
-       }
 
        return  H2C_SUCCESS;
 }
@@ -6772,7 +6764,7 @@ int rtw_chk_start_clnt_join(struct adapter *padapter, u8 *ch, u8 *bw, u8 *offset
                *offset = cur_ch_offset;
        }
 
-       return connect_allow == true ? _SUCCESS : _FAIL;
+       return connect_allow ? _SUCCESS : _FAIL;
 }
 
 /* Find union about ch, bw, ch_offset of all linked/linking interfaces */
@@ -6780,10 +6772,6 @@ int rtw_get_ch_setting_union(struct adapter *adapter, u8 *ch, u8 *bw, u8 *offset
 {
        struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
        struct adapter *iface;
-       struct mlme_ext_priv *mlmeext;
-       u8 ch_ret = 0;
-       u8 bw_ret = CHANNEL_WIDTH_20;
-       u8 offset_ret = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
 
        if (ch)
                *ch = 0;
@@ -6793,15 +6781,10 @@ int rtw_get_ch_setting_union(struct adapter *adapter, u8 *ch, u8 *bw, u8 *offset
                *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
 
        iface = dvobj->padapters;
-       mlmeext = &iface->mlmeextpriv;
 
        if (!check_fwstate(&iface->mlmepriv, _FW_LINKED|_FW_UNDER_LINKING))
                return 0;
 
-       ch_ret = mlmeext->cur_channel;
-       bw_ret = mlmeext->cur_bwmode;
-       offset_ret = mlmeext->cur_ch_offset;
-
        return 1;
 }
 
index 5c468c5057b15b40d20c13f8c2c16e6693b68bbf..ae7fb7046c93de6595ed98c7965b6ac81470756a 100644 (file)
@@ -43,7 +43,7 @@ void ips_enter(struct adapter *padapter)
        struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
 
 
-       rtw_btcoex_IpsNotify(padapter, pwrpriv->ips_mode_req);
+       hal_btcoex_IpsNotify(padapter, pwrpriv->ips_mode_req);
 
        mutex_lock(&pwrpriv->lock);
        _ips_enter(padapter);
@@ -90,7 +90,7 @@ int ips_leave(struct adapter *padapter)
        mutex_unlock(&pwrpriv->lock);
 
        if (_SUCCESS == ret)
-               rtw_btcoex_IpsNotify(padapter, IPS_NONE);
+               hal_btcoex_IpsNotify(padapter, IPS_NONE);
 
        return ret;
 }
@@ -178,7 +178,7 @@ void rtw_ps_processor(struct adapter *padapter)
        if (pwrpriv->ips_mode_req == IPS_NONE)
                goto exit;
 
-       if (rtw_pwr_unassociated_idle(padapter) == false)
+       if (!rtw_pwr_unassociated_idle(padapter))
                goto exit;
 
        if ((pwrpriv->rf_pwrstate == rf_on) && ((pwrpriv->pwr_state_check_cnts%4) == 0)) {
@@ -221,7 +221,7 @@ void traffic_check_for_leave_lps(struct adapter *padapter, u8 tx, u32 tx_packets
                        if (xmit_cnt > 8) {
                                if ((adapter_to_pwrctl(padapter)->bLeisurePs)
                                        && (adapter_to_pwrctl(padapter)->pwr_mode != PS_MODE_ACTIVE)
-                                       && (rtw_btcoex_IsBtControlLps(padapter) == false)
+                                       && (hal_btcoex_IsBtControlLps(padapter) == false)
                                        ) {
                                        DBG_871X("leave lps via Tx = %d\n", xmit_cnt);
                                        bLeaveLPS = true;
@@ -236,7 +236,7 @@ void traffic_check_for_leave_lps(struct adapter *padapter, u8 tx, u32 tx_packets
                if (pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod > 4/*2*/) {
                        if ((adapter_to_pwrctl(padapter)->bLeisurePs)
                                && (adapter_to_pwrctl(padapter)->pwr_mode != PS_MODE_ACTIVE)
-                               && (rtw_btcoex_IsBtControlLps(padapter) == false)
+                               && (hal_btcoex_IsBtControlLps(padapter) == false)
                                ) {
                                DBG_871X("leave lps via Rx = %d\n", pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod);
                                bLeaveLPS = true;
@@ -418,10 +418,10 @@ void rtw_set_ps_mode(struct adapter *padapter, u8 ps_mode, u8 smart_ps, u8 bcn_a
        /* if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) */
        if (ps_mode == PS_MODE_ACTIVE) {
                if (1
-                       && (((rtw_btcoex_IsBtControlLps(padapter) == false)
+                       && (((hal_btcoex_IsBtControlLps(padapter) == false)
                                        )
-                               || ((rtw_btcoex_IsBtControlLps(padapter) == true)
-                                       && (rtw_btcoex_IsLpsOn(padapter) == false))
+                               || ((hal_btcoex_IsBtControlLps(padapter) == true)
+                                       && (hal_btcoex_IsLpsOn(padapter) == false))
                                )
                        ) {
                        DBG_871X(FUNC_ADPT_FMT" Leave 802.11 power save - %s\n",
@@ -457,19 +457,19 @@ void rtw_set_ps_mode(struct adapter *padapter, u8 ps_mode, u8 smart_ps, u8 bcn_a
                        rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&ps_mode));
                        pwrpriv->bFwCurrentInPSMode = false;
 
-                       rtw_btcoex_LpsNotify(padapter, ps_mode);
+                       hal_btcoex_LpsNotify(padapter, ps_mode);
                }
        } else {
                if ((PS_RDY_CHECK(padapter) && check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE))
-                       || ((rtw_btcoex_IsBtControlLps(padapter) == true)
-                               && (rtw_btcoex_IsLpsOn(padapter) == true))
+                       || ((hal_btcoex_IsBtControlLps(padapter) == true)
+                               && (hal_btcoex_IsLpsOn(padapter) == true))
                        ) {
                        u8 pslv;
 
                        DBG_871X(FUNC_ADPT_FMT" Enter 802.11 power save - %s\n",
                                FUNC_ADPT_ARG(padapter), msg);
 
-                       rtw_btcoex_LpsNotify(padapter, ps_mode);
+                       hal_btcoex_LpsNotify(padapter, ps_mode);
 
                        pwrpriv->bFwCurrentInPSMode = true;
                        pwrpriv->pwr_mode = ps_mode;
@@ -481,11 +481,11 @@ void rtw_set_ps_mode(struct adapter *padapter, u8 ps_mode, u8 smart_ps, u8 bcn_a
                        if (pwrpriv->alives == 0)
                                pslv = PS_STATE_S0;
 
-                       if ((rtw_btcoex_IsBtDisabled(padapter) == false)
-                               && (rtw_btcoex_IsBtControlLps(padapter) == true)) {
+                       if ((hal_btcoex_IsBtDisabled(padapter) == false)
+                               && (hal_btcoex_IsBtControlLps(padapter) == true)) {
                                u8 val8;
 
-                               val8 = rtw_btcoex_LpsVal(padapter);
+                               val8 = hal_btcoex_LpsVal(padapter);
                                if (val8 & BIT(4))
                                        pslv = PS_STATE_S2;
                        }
@@ -544,7 +544,7 @@ void LPS_Enter(struct adapter *padapter, const char *msg)
        int n_assoc_iface = 0;
        char buf[32] = {0};
 
-       if (rtw_btcoex_IsBtControlLps(padapter) == true)
+       if (hal_btcoex_IsBtControlLps(padapter) == true)
                return;
 
        /* Skip lps enter request if number of assocated adapters is not 1 */
@@ -589,7 +589,7 @@ void LPS_Leave(struct adapter *padapter, const char *msg)
 
 /*     DBG_871X("+LeisurePSLeave\n"); */
 
-       if (rtw_btcoex_IsBtControlLps(padapter) == true)
+       if (hal_btcoex_IsBtControlLps(padapter) == true)
                return;
 
        if (pwrpriv->bLeisurePs) {
@@ -910,11 +910,11 @@ void rtw_unregister_task_alive(struct adapter *padapter, u32 task)
        pwrctrl = adapter_to_pwrctl(padapter);
        pslv = PS_STATE_S0;
 
-       if ((rtw_btcoex_IsBtDisabled(padapter) == false)
-               && (rtw_btcoex_IsBtControlLps(padapter) == true)) {
+       if ((hal_btcoex_IsBtDisabled(padapter) == false)
+               && (hal_btcoex_IsBtControlLps(padapter) == true)) {
                u8 val8;
 
-               val8 = rtw_btcoex_LpsVal(padapter);
+               val8 = hal_btcoex_LpsVal(padapter);
                if (val8 & BIT(4))
                        pslv = PS_STATE_S2;
        }
@@ -1051,11 +1051,11 @@ void rtw_unregister_tx_alive(struct adapter *padapter)
        pwrctrl = adapter_to_pwrctl(padapter);
        pslv = PS_STATE_S0;
 
-       if ((rtw_btcoex_IsBtDisabled(padapter) == false)
-               && (rtw_btcoex_IsBtControlLps(padapter) == true)) {
+       if ((hal_btcoex_IsBtDisabled(padapter) == false)
+               && (hal_btcoex_IsBtControlLps(padapter) == true)) {
                u8 val8;
 
-               val8 = rtw_btcoex_LpsVal(padapter);
+               val8 = hal_btcoex_LpsVal(padapter);
                if (val8 & BIT(4))
                        pslv = PS_STATE_S2;
        }
@@ -1093,11 +1093,11 @@ void rtw_unregister_cmd_alive(struct adapter *padapter)
        pwrctrl = adapter_to_pwrctl(padapter);
        pslv = PS_STATE_S0;
 
-       if ((rtw_btcoex_IsBtDisabled(padapter) == false)
-               && (rtw_btcoex_IsBtControlLps(padapter) == true)) {
+       if ((hal_btcoex_IsBtDisabled(padapter) == false)
+               && (hal_btcoex_IsBtControlLps(padapter) == true)) {
                u8 val8;
 
-               val8 = rtw_btcoex_LpsVal(padapter);
+               val8 = hal_btcoex_LpsVal(padapter);
                if (val8 & BIT(4))
                        pslv = PS_STATE_S2;
        }
index b543e9768e886c47bfc421e7906daf9aee565adc..687ff3c6f09f2885653e523d80e5d5fd5af30703 100644 (file)
@@ -50,7 +50,7 @@ sint _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter)
 
        precvpriv->pallocated_frame_buf = vzalloc(NR_RECVFRAME * sizeof(union recv_frame) + RXFRAME_ALIGN_SZ);
 
-       if (precvpriv->pallocated_frame_buf == NULL) {
+       if (!precvpriv->pallocated_frame_buf) {
                res = _FAIL;
                goto exit;
        }
@@ -67,7 +67,7 @@ sint _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter)
 
                list_add_tail(&(precvframe->u.list), &(precvpriv->free_recv_queue.queue));
 
-               res = rtw_os_recv_resource_alloc(padapter, precvframe);
+               rtw_os_recv_resource_alloc(padapter, precvframe);
 
                precvframe->u.hdr.len = 0;
 
@@ -122,7 +122,7 @@ union recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue)
 
                list_del_init(&precvframe->u.hdr.list);
                padapter = precvframe->u.hdr.adapter;
-               if (padapter != NULL) {
+               if (padapter) {
                        precvpriv = &padapter->recvpriv;
                        if (pfree_recv_queue == &precvpriv->free_recv_queue)
                                precvpriv->free_recvframe_cnt--;
@@ -160,7 +160,7 @@ int rtw_free_recvframe(union recv_frame *precvframe, struct __queue *pfree_recv_
 
        list_add_tail(&(precvframe->u.hdr.list), get_list_head(pfree_recv_queue));
 
-       if (padapter != NULL) {
+       if (padapter) {
                if (pfree_recv_queue == &precvpriv->free_recv_queue)
                                precvpriv->free_recvframe_cnt++;
        }
@@ -183,7 +183,7 @@ sint _rtw_enqueue_recvframe(union recv_frame *precvframe, struct __queue *queue)
 
        list_add_tail(&(precvframe->u.hdr.list), get_list_head(queue));
 
-       if (padapter != NULL)
+       if (padapter)
                if (queue == &precvpriv->free_recv_queue)
                        precvpriv->free_recvframe_cnt++;
 
@@ -334,7 +334,7 @@ sint recvframe_chkmic(struct adapter *adapter,  union recv_frame *precvframe)
                        prxattrib->ra[0], prxattrib->ra[1], prxattrib->ra[2], prxattrib->ra[3], prxattrib->ra[4], prxattrib->ra[5]));
 
                /* calculate mic code */
-               if (stainfo != NULL) {
+               if (stainfo) {
                        if (IS_MCAST(prxattrib->ra)) {
                                /* mickey =&psecuritypriv->dot118021XGrprxmickey.skey[0]; */
                                /* iv = precvframe->u.hdr.rx_data+prxattrib->hdrlen; */
@@ -570,7 +570,7 @@ union recv_frame *portctrl(struct adapter *adapter, union recv_frame *precv_fram
        RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:adapter->securitypriv.dot11AuthAlgrthm =%d\n", adapter->securitypriv.dot11AuthAlgrthm));
 
        if (auth_alg == 2) {
-               if ((psta != NULL) && (psta->ieee8021x_blocked)) {
+               if ((psta) && (psta->ieee8021x_blocked)) {
                        __be16 be_tmp;
 
                        /* blocked */
@@ -859,7 +859,7 @@ sint sta2sta_data_frame(
        else
                *psta = rtw_get_stainfo(pstapriv, sta_addr); /*  get ap_info */
 
-       if (*psta == NULL) {
+       if (!*psta) {
                RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under sta2sta_data_frame ; drop pkt\n"));
                ret = _FAIL;
                goto exit;
@@ -942,7 +942,7 @@ sint ap2sta_data_frame(
                else
                        *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /*  get ap_info */
 
-               if (*psta == NULL) {
+               if (!*psta) {
                        RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("ap2sta: can't get psta under STATION_MODE ; drop pkt\n"));
                        #ifdef DBG_RX_DROP_FRAME
                        DBG_871X("DBG_RX_DROP_FRAME %s can't get psta under STATION_MODE ; drop pkt\n", __func__);
@@ -974,7 +974,7 @@ sint ap2sta_data_frame(
 
 
                *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /*  get sta_info */
-               if (*psta == NULL) {
+               if (!*psta) {
                        RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under MP_MODE ; drop pkt\n"));
                        #ifdef DBG_RX_DROP_FRAME
                        DBG_871X("DBG_RX_DROP_FRAME %s can't get psta under WIFI_MP_STATE ; drop pkt\n", __func__);
@@ -991,7 +991,7 @@ sint ap2sta_data_frame(
        } else {
                if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && (!bmcast)) {
                        *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /*  get sta_info */
-                       if (*psta == NULL) {
+                       if (!*psta) {
 
                                /* for AP multicast issue , modify by yiwei */
                                static unsigned long send_issue_deauth_time;
@@ -1042,7 +1042,7 @@ sint sta2ap_data_frame(
                }
 
                *psta = rtw_get_stainfo(pstapriv, pattrib->src);
-               if (*psta == NULL) {
+               if (!*psta) {
                        RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under AP_MODE; drop pkt\n"));
                        DBG_871X("issue_deauth to sta =" MAC_FMT " for the reason(7)\n", MAC_ARG(pattrib->src));
 
@@ -1099,7 +1099,7 @@ sint validate_recv_ctrl_frame(struct adapter *padapter, union recv_frame *precv_
                return _FAIL;
 
        psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
-       if (psta == NULL)
+       if (!psta)
                return _FAIL;
 
        /* for rx pkt statistics */
@@ -1226,7 +1226,7 @@ sint validate_recv_mgnt_frame(struct adapter *padapter, union recv_frame *precv_
        RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("+validate_recv_mgnt_frame\n"));
 
        precv_frame = recvframe_chk_defrag(padapter, precv_frame);
-       if (precv_frame == NULL) {
+       if (!precv_frame) {
                RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("%s: fragment packet\n", __func__));
                return _SUCCESS;
        }
@@ -1274,7 +1274,7 @@ sint validate_recv_data_frame(struct adapter *adapter, union recv_frame *precv_f
        psa = get_sa(ptr);
        pbssid = get_hdr_bssid(ptr);
 
-       if (pbssid == NULL) {
+       if (!pbssid) {
                #ifdef DBG_RX_DROP_FRAME
                DBG_871X("DBG_RX_DROP_FRAME %s pbssid == NULL\n", __func__);
                #endif
@@ -1329,7 +1329,7 @@ sint validate_recv_data_frame(struct adapter *adapter, union recv_frame *precv_f
        }
 
 
-       if (psta == NULL) {
+       if (!psta) {
                RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" after to_fr_ds_chk; psta == NULL\n"));
                #ifdef DBG_RX_DROP_FRAME
                DBG_871X("DBG_RX_DROP_FRAME %s psta == NULL\n", __func__);
@@ -1426,7 +1426,7 @@ static sint validate_80211w_mgmt(struct adapter *adapter, union recv_frame *prec
                        /* actual management data frame body */
                        data_len = pattrib->pkt_len - pattrib->hdrlen - pattrib->iv_len - pattrib->icv_len;
                        mgmt_DATA = rtw_zmalloc(data_len);
-                       if (mgmt_DATA == NULL) {
+                       if (!mgmt_DATA) {
                                DBG_871X("%s mgmt allocate fail  !!!!!!!!!\n", __func__);
                                goto validate_80211w_fail;
                        }
@@ -1615,7 +1615,6 @@ sint wlanhdr_to_ethhdr(union recv_frame *precvframe)
        u8 *psnap_type;
        struct ieee80211_snap_hdr       *psnap;
        __be16 be_tmp;
-       sint ret = _SUCCESS;
        struct adapter                  *adapter = precvframe->u.hdr.adapter;
        struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
        u8 *ptr = get_recvframe_data(precvframe) ; /*  point to frame_ctrl field */
@@ -1702,7 +1701,7 @@ sint wlanhdr_to_ethhdr(union recv_frame *precvframe)
                memcpy(ptr+12, &be_tmp, 2);
        }
 
-       return ret;
+       return _SUCCESS;
 }
 
 /* perform defrag */
@@ -1812,7 +1811,7 @@ union recv_frame *recvframe_chk_defrag(struct adapter *padapter, union recv_fram
 
        psta_addr = pfhdr->attrib.ta;
        psta = rtw_get_stainfo(pstapriv, psta_addr);
-       if (psta == NULL) {
+       if (!psta) {
                u8 type = GetFrameType(pfhdr->rx_data);
                if (type != WIFI_DATA_TYPE) {
                        psta = rtw_get_bcmc_stainfo(padapter);
@@ -1828,7 +1827,7 @@ union recv_frame *recvframe_chk_defrag(struct adapter *padapter, union recv_fram
        if (ismfrag == 1) {
                /* 0~(n-1) fragment frame */
                /* enqueue to defraf_g */
-               if (pdefrag_q != NULL) {
+               if (pdefrag_q) {
                        if (fragnum == 0)
                                /* the first fragment */
                                if (!list_empty(&pdefrag_q->queue))
@@ -1859,7 +1858,7 @@ union recv_frame *recvframe_chk_defrag(struct adapter *padapter, union recv_fram
        if ((ismfrag == 0) && (fragnum != 0)) {
                /* the last fragment frame */
                /* enqueue the last fragment */
-               if (pdefrag_q != NULL) {
+               if (pdefrag_q) {
                        /* spin_lock(&pdefrag_q->lock); */
                        phead = get_list_head(pdefrag_q);
                        list_add_tail(&pfhdr->list, phead);
@@ -1880,7 +1879,7 @@ union recv_frame *recvframe_chk_defrag(struct adapter *padapter, union recv_fram
        }
 
 
-       if ((prtnframe != NULL) && (prtnframe->u.hdr.attrib.privacy)) {
+       if ((prtnframe) && (prtnframe->u.hdr.attrib.privacy)) {
                /* after defrag we must check tkip mic code */
                if (recvframe_chkmic(padapter,  prtnframe) == _FAIL) {
                        RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic(padapter,  prtnframe) == _FAIL\n"));
@@ -1900,7 +1899,6 @@ static int amsdu_to_msdu(struct adapter *padapter, union recv_frame *prframe)
        _pkt *sub_pkt, *subframes[MAX_SUBFRAME_COUNT];
        struct recv_priv *precvpriv = &padapter->recvpriv;
        struct __queue *pfree_recv_queue = &(precvpriv->free_recv_queue);
-       int     ret = _SUCCESS;
 
        nr_subframes = 0;
 
@@ -1924,7 +1922,7 @@ static int amsdu_to_msdu(struct adapter *padapter, union recv_frame *prframe)
                }
 
                sub_pkt = rtw_os_alloc_msdu_pkt(prframe, nSubframe_Length, pdata);
-               if (sub_pkt == NULL) {
+               if (!sub_pkt) {
                        DBG_871X("%s(): allocate sub packet fail !!!\n", __func__);
                        break;
                }
@@ -1969,7 +1967,7 @@ static int amsdu_to_msdu(struct adapter *padapter, union recv_frame *prframe)
        prframe->u.hdr.len = 0;
        rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */
 
-       return ret;
+       return  _SUCCESS;
 }
 
 int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num);
@@ -2453,7 +2451,7 @@ static int recv_func_posthandle(struct adapter *padapter, union recv_frame *prfr
        DBG_COUNTER(padapter->rx_logs.core_rx_post);
 
        prframe = decryptor(padapter, prframe);
-       if (prframe == NULL) {
+       if (!prframe) {
                RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("decryptor: drop pkt\n"));
                #ifdef DBG_RX_DROP_FRAME
                DBG_871X("DBG_RX_DROP_FRAME %s decryptor: drop pkt\n", __func__);
@@ -2464,7 +2462,7 @@ static int recv_func_posthandle(struct adapter *padapter, union recv_frame *prfr
        }
 
        prframe = recvframe_chk_defrag(padapter, prframe);
-       if (prframe == NULL)    {
+       if (!prframe)   {
                RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chk_defrag: drop pkt\n"));
                #ifdef DBG_RX_DROP_FRAME
                DBG_871X("DBG_RX_DROP_FRAME %s recvframe_chk_defrag: drop pkt\n", __func__);
@@ -2474,7 +2472,7 @@ static int recv_func_posthandle(struct adapter *padapter, union recv_frame *prfr
        }
 
        prframe = portctrl(padapter, prframe);
-       if (prframe == NULL) {
+       if (!prframe) {
                RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("portctrl: drop pkt\n"));
                #ifdef DBG_RX_DROP_FRAME
                DBG_871X("DBG_RX_DROP_FRAME %s portctrl: drop pkt\n", __func__);
index fdbf967812f9b2b73cccd7a1452768adbee47e64..76c50377f0feb32acabd128ab7c5e7b6e77501cf 100644 (file)
@@ -302,14 +302,9 @@ void Switch_DM_Func(struct adapter *padapter, u32 mode, u8 enable)
                rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_CLR, (u8 *)(&mode));
 }
 
-static void Set_NETYPE0_MSR(struct adapter *padapter, u8 type)
-{
-       rtw_hal_set_hwreg(padapter, HW_VAR_MEDIA_STATUS, (u8 *)(&type));
-}
-
 void Set_MSR(struct adapter *padapter, u8 type)
 {
-       Set_NETYPE0_MSR(padapter, type);
+       rtw_hal_set_hwreg(padapter, HW_VAR_MEDIA_STATUS, (u8 *)(&type));
 }
 
 inline u8 rtw_get_oper_ch(struct adapter *adapter)
@@ -745,7 +740,7 @@ s16 rtw_camid_alloc(struct adapter *adapter, struct sta_info *sta, u8 kid)
                i = _rtw_camid_search(adapter, addr, kid);
                if (i >= 0) {
                        /* Fix issue that pairwise and group key have same key id. Pairwise key first, group key can overwirte group only(ex: rekey) */
-                       if (sta || _rtw_camid_is_gk(adapter, i) == true)
+                       if (sta || _rtw_camid_is_gk(adapter, i))
                                cam_id = i;
                        else
                                DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT" group key id:%u the same key id as pairwise key\n"
@@ -1620,16 +1615,10 @@ void Update_RA_Entry(struct adapter *padapter, struct sta_info *psta)
        rtw_hal_update_ra_mask(psta, 0);
 }
 
-void enable_rate_adaptive(struct adapter *padapter, struct sta_info *psta);
-void enable_rate_adaptive(struct adapter *padapter, struct sta_info *psta)
-{
-       Update_RA_Entry(padapter, psta);
-}
-
 void set_sta_rate(struct adapter *padapter, struct sta_info *psta)
 {
        /* rate adaptive */
-       enable_rate_adaptive(padapter, psta);
+       Update_RA_Entry(padapter, psta);
 }
 
 unsigned char check_assoc_AP(u8 *pframe, uint len)
@@ -1943,7 +1932,7 @@ void adaptive_early_32k(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len)
 
        /* delay = (timestamp mod 1024*100)/1000 (unit: ms) */
        /* delay_ms = do_div(tsf, (pmlmeinfo->bcn_interval*1024))/1000; */
-       delay_ms = rtw_modular64(tsf, (pmlmeinfo->bcn_interval*1024));
+       delay_ms = do_div(tsf, (pmlmeinfo->bcn_interval*1024));
        delay_ms = delay_ms/1000;
 
        if (delay_ms >= 8)
index 2bb679e54dc78f474d1c0fc6f130d325be21964f..b5dcb78fb4f48c88c8d92593cabd3d3d3e4953ab 100644 (file)
@@ -76,7 +76,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
 
        pxmitpriv->pallocated_frame_buf = vzalloc(NR_XMITFRAME * sizeof(struct xmit_frame) + 4);
 
-       if (pxmitpriv->pallocated_frame_buf  == NULL) {
+       if (!pxmitpriv->pallocated_frame_buf) {
                pxmitpriv->pxmit_frame_buf = NULL;
                RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xmit_frame fail!\n"));
                res = _FAIL;
@@ -115,7 +115,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
 
        pxmitpriv->pallocated_xmitbuf = vzalloc(NR_XMITBUFF * sizeof(struct xmit_buf) + 4);
 
-       if (pxmitpriv->pallocated_xmitbuf  == NULL) {
+       if (!pxmitpriv->pallocated_xmitbuf) {
                RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xmit_buf fail!\n"));
                res = _FAIL;
                goto exit;
@@ -166,7 +166,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
 
        pxmitpriv->xframe_ext_alloc_addr = vzalloc(NR_XMIT_EXTBUFF * sizeof(struct xmit_frame) + 4);
 
-       if (pxmitpriv->xframe_ext_alloc_addr  == NULL) {
+       if (!pxmitpriv->xframe_ext_alloc_addr) {
                pxmitpriv->xframe_ext = NULL;
                RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xframe_ext fail!\n"));
                res = _FAIL;
@@ -199,7 +199,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
 
        pxmitpriv->pallocated_xmit_extbuf = vzalloc(NR_XMIT_EXTBUFF * sizeof(struct xmit_buf) + 4);
 
-       if (pxmitpriv->pallocated_xmit_extbuf  == NULL) {
+       if (!pxmitpriv->pallocated_xmit_extbuf) {
                RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xmit_extbuf fail!\n"));
                res = _FAIL;
                goto exit;
@@ -288,7 +288,7 @@ void _rtw_free_xmit_priv(struct xmit_priv *pxmitpriv)
 
        rtw_hal_free_xmit_priv(padapter);
 
-       if (pxmitpriv->pxmit_frame_buf == NULL)
+       if (!pxmitpriv->pxmit_frame_buf)
                return;
 
        for (i = 0; i < NR_XMITFRAME; i++) {
@@ -335,7 +335,7 @@ void _rtw_free_xmit_priv(struct xmit_priv *pxmitpriv)
 
        for (i = 0; i < CMDBUF_MAX; i++) {
                pxmitbuf = &pxmitpriv->pcmd_xmitbuf[i];
-               if (pxmitbuf != NULL)
+               if (pxmitbuf)
                        rtw_os_xmit_resource_free(padapter, pxmitbuf, MAX_CMDBUF_SZ+XMITBUF_ALIGN_SZ, true);
        }
 
@@ -625,13 +625,11 @@ exit:
 
 u8 qos_acm(u8 acm_mask, u8 priority)
 {
-       u8 change_priority = priority;
-
        switch (priority) {
        case 0:
        case 3:
                if (acm_mask & BIT(1))
-                       change_priority = 1;
+                       priority = 1;
                break;
        case 1:
        case 2:
@@ -639,19 +637,19 @@ u8 qos_acm(u8 acm_mask, u8 priority)
        case 4:
        case 5:
                if (acm_mask & BIT(2))
-                       change_priority = 0;
+                       priority = 0;
                break;
        case 6:
        case 7:
                if (acm_mask & BIT(3))
-                       change_priority = 5;
+                       priority = 5;
                break;
        default:
                DBG_871X("qos_acm(): invalid pattrib->priority: %d!!!\n", priority);
                break;
        }
 
-       return change_priority;
+       return priority;
 }
 
 static void set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
@@ -774,7 +772,7 @@ static s32 update_attrib(struct adapter *padapter, _pkt *pkt, struct pkt_attrib
                psta = rtw_get_bcmc_stainfo(padapter);
        } else {
                psta = rtw_get_stainfo(pstapriv, pattrib->ra);
-               if (psta == NULL)       { /*  if we cannot get psta => drop the pkt */
+               if (!psta)      { /*  if we cannot get psta => drop the pkt */
                        DBG_COUNTER(padapter->tx_logs.core_tx_upd_attrib_err_ucast_sta);
                        RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("\nupdate_attrib => get sta_info fail, ra:" MAC_FMT"\n", MAC_ARG(pattrib->ra)));
                        #ifdef DBG_TX_DROP_FRAME
@@ -789,7 +787,7 @@ static s32 update_attrib(struct adapter *padapter, _pkt *pkt, struct pkt_attrib
                }
        }
 
-       if (psta == NULL) {
+       if (!psta) {
                /*  if we cannot get psta => drop the pkt */
                DBG_COUNTER(padapter->tx_logs.core_tx_upd_attrib_err_sta);
                RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("\nupdate_attrib => get sta_info fail, ra:" MAC_FMT "\n", MAC_ARG(pattrib->ra)));
@@ -1098,7 +1096,7 @@ s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr
                                return _FAIL;
                        }
 
-                       if (psta == NULL) {
+                       if (!psta) {
                                DBG_871X("%s, psta ==NUL\n", __func__);
                                return _FAIL;
                        }
@@ -1241,7 +1239,7 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, _pkt *pkt, struct xmit_fram
                return _FAIL;
        }
 */
-       if (pxmitframe->buf_addr == NULL) {
+       if (!pxmitframe->buf_addr) {
                DBG_8192C("==> %s buf_addr == NULL\n", __func__);
                return _FAIL;
        }
@@ -1376,7 +1374,7 @@ s32 rtw_mgmt_xmitframe_coalesce(struct adapter *padapter, _pkt *pkt, struct xmit
        tmp_buf = BIP_AAD = rtw_zmalloc(ori_len);
        subtype = GetFrameSubType(pframe); /* bit(7)~bit(2) */
 
-       if (BIP_AAD == NULL)
+       if (!BIP_AAD)
                return _FAIL;
 
        spin_lock_bh(&padapter->security_key_mutex);
@@ -1442,13 +1440,13 @@ s32 rtw_mgmt_xmitframe_coalesce(struct adapter *padapter, _pkt *pkt, struct xmit
                        else
                                psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
 
-                       if (psta == NULL) {
+                       if (!psta) {
 
                                DBG_871X("%s, psta ==NUL\n", __func__);
                                goto xmitframe_coalesce_fail;
                        }
 
-                       if (!(psta->state & _FW_LINKED) || pxmitframe->buf_addr == NULL) {
+                       if (!(psta->state & _FW_LINKED) || !pxmitframe->buf_addr) {
                                DBG_871X("%s, not _FW_LINKED or addr null\n", __func__);
                                goto xmitframe_coalesce_fail;
                        }
@@ -1570,7 +1568,7 @@ void rtw_update_protection(struct adapter *padapter, u8 *ie, uint ie_len)
        case AUTO_VCS:
        default:
                perp = rtw_get_ie(ie, _ERPINFO_IE_, &erp_len, ie_len);
-               if (perp == NULL)
+               if (!perp)
                        pxmitpriv->vcs = NONE_VCS;
                else {
                        protection = (*(perp + 2)) & BIT(1);
@@ -1622,7 +1620,7 @@ static struct xmit_buf *__rtw_alloc_cmd_xmitbuf(struct xmit_priv *pxmitpriv,
        struct xmit_buf *pxmitbuf =  NULL;
 
        pxmitbuf = &pxmitpriv->pcmd_xmitbuf[buf_type];
-       if (pxmitbuf !=  NULL) {
+       if (pxmitbuf) {
                pxmitbuf->priv_data = NULL;
 
                pxmitbuf->len = 0;
@@ -1647,13 +1645,13 @@ struct xmit_frame *__rtw_alloc_cmdxmitframe(struct xmit_priv *pxmitpriv,
        struct xmit_buf         *pxmitbuf;
 
        pcmdframe = rtw_alloc_xmitframe(pxmitpriv);
-       if (pcmdframe == NULL) {
+       if (!pcmdframe) {
                DBG_871X("%s, alloc xmitframe fail\n", __func__);
                return NULL;
        }
 
        pxmitbuf = __rtw_alloc_cmd_xmitbuf(pxmitpriv, buf_type);
-       if (pxmitbuf == NULL) {
+       if (!pxmitbuf) {
                DBG_871X("%s, alloc xmitbuf fail\n", __func__);
                rtw_free_xmitframe(pxmitpriv, pcmdframe);
                return NULL;
@@ -1693,7 +1691,7 @@ struct xmit_buf *rtw_alloc_xmitbuf_ext(struct xmit_priv *pxmitpriv)
                list_del_init(&(pxmitbuf->list));
        }
 
-       if (pxmitbuf !=  NULL) {
+       if (pxmitbuf) {
                pxmitpriv->free_xmit_extbuf_cnt--;
                #ifdef DBG_XMIT_BUF_EXT
                DBG_871X("DBG_XMIT_BUF_EXT ALLOC no =%d,  free_xmit_extbuf_cnt =%d\n", pxmitbuf->no, pxmitpriv->free_xmit_extbuf_cnt);
@@ -1723,7 +1721,7 @@ s32 rtw_free_xmitbuf_ext(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
        _irqL irqL;
        struct __queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue;
 
-       if (pxmitbuf == NULL)
+       if (!pxmitbuf)
                return _FAIL;
 
        spin_lock_irqsave(&pfree_queue->lock, irqL);
@@ -1765,7 +1763,7 @@ struct xmit_buf *rtw_alloc_xmitbuf(struct xmit_priv *pxmitpriv)
                list_del_init(&(pxmitbuf->list));
        }
 
-       if (pxmitbuf !=  NULL) {
+       if (pxmitbuf) {
                pxmitpriv->free_xmitbuf_cnt--;
                #ifdef DBG_XMIT_BUF
                DBG_871X("DBG_XMIT_BUF ALLOC no =%d,  free_xmitbuf_cnt =%d\n", pxmitbuf->no, pxmitpriv->free_xmitbuf_cnt);
@@ -1801,7 +1799,7 @@ s32 rtw_free_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
 
        /* DBG_871X("+rtw_free_xmitbuf\n"); */
 
-       if (pxmitbuf == NULL)
+       if (!pxmitbuf)
                return _FAIL;
 
        if (pxmitbuf->sctx) {
@@ -1831,7 +1829,7 @@ s32 rtw_free_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
 
 static void rtw_init_xmitframe(struct xmit_frame *pxframe)
 {
-       if (pxframe !=  NULL) { /* default value setting */
+       if (pxframe) { /* default value setting */
                pxframe->buf_addr = NULL;
                pxframe->pxmitbuf = NULL;
 
@@ -1927,7 +1925,7 @@ struct xmit_frame *rtw_alloc_xmitframe_once(struct xmit_priv *pxmitpriv)
 
        alloc_addr = rtw_zmalloc(sizeof(struct xmit_frame) + 4);
 
-       if (alloc_addr == NULL)
+       if (!alloc_addr)
                goto exit;
 
        pxframe = (struct xmit_frame *)N_BYTE_ALIGMENT((SIZE_PTR)(alloc_addr), 4);
@@ -1955,7 +1953,7 @@ s32 rtw_free_xmitframe(struct xmit_priv *pxmitpriv, struct xmit_frame *pxmitfram
        struct adapter *padapter = pxmitpriv->adapter;
        _pkt *pndis_pkt = NULL;
 
-       if (pxmitframe == NULL) {
+       if (!pxmitframe) {
                RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("======rtw_free_xmitframe():pxmitframe == NULL!!!!!!!!!!\n"));
                goto exit;
        }
@@ -2109,7 +2107,7 @@ s32 rtw_xmit_classifier(struct adapter *padapter, struct xmit_frame *pxmitframe)
                return _FAIL;
        }
 
-       if (psta == NULL) {
+       if (!psta) {
                DBG_COUNTER(padapter->tx_logs.core_tx_enqueue_class_err_nosta);
                res = _FAIL;
                DBG_8192C("rtw_xmit_classifier: psta == NULL\n");
@@ -2310,7 +2308,7 @@ s32 rtw_xmit(struct adapter *padapter, _pkt **ppkt)
                drop_cnt = 0;
        }
 
-       if (pxmitframe == NULL) {
+       if (!pxmitframe) {
                drop_cnt++;
                RT_TRACE(_module_xmit_osdep_c_, _drv_err_, ("rtw_xmit: no more pxmitframe\n"));
                DBG_COUNTER(padapter->tx_logs.core_tx_err_pxmitframe);
@@ -2409,7 +2407,7 @@ sint xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_fr
                return false;
        }
 
-       if (psta == NULL) {
+       if (!psta) {
                DBG_COUNTER(padapter->tx_logs.core_tx_ap_enqueue_warn_nosta);
                DBG_871X("%s, psta ==NUL\n", __func__);
                return false;
@@ -2426,7 +2424,7 @@ sint xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_fr
                /* DBG_871X("directly xmit pspoll_triggered packet\n"); */
 
                /* pattrib->triggered = 0; */
-               if (bmcst && xmitframe_hiq_filter(pxmitframe) == true)
+               if (bmcst && xmitframe_hiq_filter(pxmitframe))
                        pattrib->qsel = 0x11;/* HIQ */
 
                return ret;
@@ -2455,7 +2453,7 @@ sint xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_fr
 
                        /* DBG_871X("enqueue, sq_len =%d, tim =%x\n", psta->sleepq_len, pstapriv->tim_bitmap); */
 
-                       if (update_tim == true) {
+                       if (update_tim) {
                                update_beacon(padapter, _TIM_IE_, NULL, true);
                        } else {
                                chk_bmc_sleepq_cmd(padapter);
@@ -2521,7 +2519,7 @@ sint xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_fr
 
                                /* DBG_871X("enqueue, sq_len =%d, tim =%x\n", psta->sleepq_len, pstapriv->tim_bitmap); */
 
-                               if (update_tim == true)
+                               if (update_tim)
                                        /* DBG_871X("sleepq_len == 1, update BCNTIM\n"); */
                                        /* upate BCN for TIM IE */
                                        update_beacon(padapter, _TIM_IE_, NULL, true);
index eb6e07ef5dad06c167eac44e544bc21bb529e1e2..8e4caeeb4070fc756e2d94904c6eb64f096fcb2f 100644 (file)
@@ -1421,7 +1421,7 @@ static void halbtc8723b1ant_PsTdma(
 
 
        if (bTurnOn) {
-               if (pBtLinkInfo->bSlaveRole == true)
+               if (pBtLinkInfo->bSlaveRole)
                        psTdmaByte4Val = psTdmaByte4Val | 0x1;  /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
 
 
@@ -2337,9 +2337,9 @@ static void halbtc8723b1ant_ActionWifiConnected(PBTC_COEXIST pBtCoexist)
                                        );
                        }
                } else if (
-                       (pCoexSta->bPanExist == false) &&
-                       (pCoexSta->bA2dpExist == false) &&
-                       (pCoexSta->bHidExist == false)
+                       (!pCoexSta->bPanExist) &&
+                       (!pCoexSta->bA2dpExist) &&
+                       (!pCoexSta->bHidExist)
                )
                        halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
                else
index cb62fc0a0f9c5a40fc807425379c8517cb6c45c5..02da0a883594b8b3e9ec14ab70e2acd658d64ed1 100644 (file)
@@ -7,6 +7,13 @@
 
 #include "Mp_Precomp.h"
 
+/* defines */
+#define HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(val)                            \
+do {                                                                         \
+       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, val);           \
+       pCoexDm->psTdmaDuAdjType = val;                                       \
+} while (0)
+
 /*  Global variables, these are static variables */
 static COEX_DM_8723B_2ANT GLCoexDm8723b2Ant;
 static PCOEX_DM_8723B_2ANT pCoexDm = &GLCoexDm8723b2Ant;
@@ -1599,63 +1606,43 @@ static void halbtc8723b2ant_TdmaDurationAdjust(
                {
                        if (bScoHid) {
                                if (bTxPause) {
-                                       if (maxInterval == 1) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13);
-                                               pCoexDm->psTdmaDuAdjType = 13;
-                                       } else if (maxInterval == 2) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
-                                               pCoexDm->psTdmaDuAdjType = 14;
-                                       } else if (maxInterval == 3) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                               pCoexDm->psTdmaDuAdjType = 15;
-                                       } else {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                               pCoexDm->psTdmaDuAdjType = 15;
-                                       }
+                                       if (maxInterval == 1)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(13);
+                                       else if (maxInterval == 2)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
+                                       else if (maxInterval == 3)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
+                                       else
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
                                } else {
-                                       if (maxInterval == 1) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
-                                               pCoexDm->psTdmaDuAdjType = 9;
-                                       } else if (maxInterval == 2) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
-                                               pCoexDm->psTdmaDuAdjType = 10;
-                                       } else if (maxInterval == 3) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                               pCoexDm->psTdmaDuAdjType = 11;
-                                       } else {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                               pCoexDm->psTdmaDuAdjType = 11;
-                                       }
+                                       if (maxInterval == 1)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(9);
+                                       else if (maxInterval == 2)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
+                                       else if (maxInterval == 3)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
+                                       else
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
                                }
                        } else {
                                if (bTxPause) {
-                                       if (maxInterval == 1) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
-                                               pCoexDm->psTdmaDuAdjType = 5;
-                                       } else if (maxInterval == 2) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
-                                               pCoexDm->psTdmaDuAdjType = 6;
-                                       } else if (maxInterval == 3) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                               pCoexDm->psTdmaDuAdjType = 7;
-                                       } else {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                               pCoexDm->psTdmaDuAdjType = 7;
-                                       }
+                                       if (maxInterval == 1)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(5);
+                                       else if (maxInterval == 2)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
+                                       else if (maxInterval == 3)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
+                                       else
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
                                } else {
-                                       if (maxInterval == 1) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1);
-                                               pCoexDm->psTdmaDuAdjType = 1;
-                                       } else if (maxInterval == 2) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
-                                               pCoexDm->psTdmaDuAdjType = 2;
-                                       } else if (maxInterval == 3) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                               pCoexDm->psTdmaDuAdjType = 3;
-                                       } else {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                               pCoexDm->psTdmaDuAdjType = 3;
-                                       }
+                                       if (maxInterval == 1)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(1);
+                                       else if (maxInterval == 2)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
+                                       else if (maxInterval == 3)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
+                                       else
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
                                }
                        }
                }
@@ -1741,442 +1728,295 @@ static void halbtc8723b2ant_TdmaDurationAdjust(
                        if (bTxPause) {
                                BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));
 
-                               if (pCoexDm->curPsTdma == 71) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
-                                       pCoexDm->psTdmaDuAdjType = 5;
-                               } else if (pCoexDm->curPsTdma == 1) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
-                                       pCoexDm->psTdmaDuAdjType = 5;
-                               } else if (pCoexDm->curPsTdma == 2) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
-                                       pCoexDm->psTdmaDuAdjType = 6;
-                               } else if (pCoexDm->curPsTdma == 3) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                       pCoexDm->psTdmaDuAdjType = 7;
-                               } else if (pCoexDm->curPsTdma == 4) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
-                                       pCoexDm->psTdmaDuAdjType = 8;
-                               }
-
-                               if (pCoexDm->curPsTdma == 9) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13);
-                                       pCoexDm->psTdmaDuAdjType = 13;
-                               } else if (pCoexDm->curPsTdma == 10) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
-                                       pCoexDm->psTdmaDuAdjType = 14;
-                               } else if (pCoexDm->curPsTdma == 11) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                       pCoexDm->psTdmaDuAdjType = 15;
-                               } else if (pCoexDm->curPsTdma == 12) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
-                                       pCoexDm->psTdmaDuAdjType = 16;
-                               }
+                               if (pCoexDm->curPsTdma == 71)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(5);
+                               else if (pCoexDm->curPsTdma == 1)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(5);
+                               else if (pCoexDm->curPsTdma == 2)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
+                               else if (pCoexDm->curPsTdma == 3)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
+                               else if (pCoexDm->curPsTdma == 4)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8);
+
+                               if (pCoexDm->curPsTdma == 9)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(13);
+                               else if (pCoexDm->curPsTdma == 10)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
+                               else if (pCoexDm->curPsTdma == 11)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
+                               else if (pCoexDm->curPsTdma == 12)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16);
 
                                if (result == -1) {
-                                       if (pCoexDm->curPsTdma == 5) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
-                                               pCoexDm->psTdmaDuAdjType = 6;
-                                       } else if (pCoexDm->curPsTdma == 6) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                               pCoexDm->psTdmaDuAdjType = 7;
-                                       } else if (pCoexDm->curPsTdma == 7) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
-                                               pCoexDm->psTdmaDuAdjType = 8;
-                                       } else if (pCoexDm->curPsTdma == 13) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
-                                               pCoexDm->psTdmaDuAdjType = 14;
-                                       } else if (pCoexDm->curPsTdma == 14) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                               pCoexDm->psTdmaDuAdjType = 15;
-                                       } else if (pCoexDm->curPsTdma == 15) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
-                                               pCoexDm->psTdmaDuAdjType = 16;
-                                       }
+                                       if (pCoexDm->curPsTdma == 5)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
+                                       else if (pCoexDm->curPsTdma == 6)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
+                                       else if (pCoexDm->curPsTdma == 7)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8);
+                                       else if (pCoexDm->curPsTdma == 13)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
+                                       else if (pCoexDm->curPsTdma == 14)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
+                                       else if (pCoexDm->curPsTdma == 15)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16);
                                } else if (result == 1) {
-                                       if (pCoexDm->curPsTdma == 8) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                               pCoexDm->psTdmaDuAdjType = 7;
-                                       } else if (pCoexDm->curPsTdma == 7) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
-                                               pCoexDm->psTdmaDuAdjType = 6;
-                                       } else if (pCoexDm->curPsTdma == 6) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
-                                               pCoexDm->psTdmaDuAdjType = 5;
-                                       } else if (pCoexDm->curPsTdma == 16) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                               pCoexDm->psTdmaDuAdjType = 15;
-                                       } else if (pCoexDm->curPsTdma == 15) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
-                                               pCoexDm->psTdmaDuAdjType = 14;
-                                       } else if (pCoexDm->curPsTdma == 14) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13);
-                                               pCoexDm->psTdmaDuAdjType = 13;
-                                       }
+                                       if (pCoexDm->curPsTdma == 8)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
+                                       else if (pCoexDm->curPsTdma == 7)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
+                                       else if (pCoexDm->curPsTdma == 6)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(5);
+                                       else if (pCoexDm->curPsTdma == 16)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
+                                       else if (pCoexDm->curPsTdma == 15)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
+                                       else if (pCoexDm->curPsTdma == 14)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(13);
                                }
                        } else {
                                BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));
-                               if (pCoexDm->curPsTdma == 5) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 71);
-                                       pCoexDm->psTdmaDuAdjType = 71;
-                               } else if (pCoexDm->curPsTdma == 6) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
-                                       pCoexDm->psTdmaDuAdjType = 2;
-                               } else if (pCoexDm->curPsTdma == 7) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                       pCoexDm->psTdmaDuAdjType = 3;
-                               } else if (pCoexDm->curPsTdma == 8) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
-                                       pCoexDm->psTdmaDuAdjType = 4;
-                               }
-
-                               if (pCoexDm->curPsTdma == 13) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
-                                       pCoexDm->psTdmaDuAdjType = 9;
-                               } else if (pCoexDm->curPsTdma == 14) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
-                                       pCoexDm->psTdmaDuAdjType = 10;
-                               } else if (pCoexDm->curPsTdma == 15) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                       pCoexDm->psTdmaDuAdjType = 11;
-                               } else if (pCoexDm->curPsTdma == 16) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
-                                       pCoexDm->psTdmaDuAdjType = 12;
-                               }
+                               if (pCoexDm->curPsTdma == 5)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(71);
+                               else if (pCoexDm->curPsTdma == 6)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
+                               else if (pCoexDm->curPsTdma == 7)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
+                               else if (pCoexDm->curPsTdma == 8)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4);
+
+                               if (pCoexDm->curPsTdma == 13)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(9);
+                               else if (pCoexDm->curPsTdma == 14)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
+                               else if (pCoexDm->curPsTdma == 15)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
+                               else if (pCoexDm->curPsTdma == 16)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12);
 
                                if (result == -1) {
-                                       if (pCoexDm->curPsTdma == 71) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1);
-                                               pCoexDm->psTdmaDuAdjType = 1;
-                                       } else if (pCoexDm->curPsTdma == 1) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
-                                               pCoexDm->psTdmaDuAdjType = 2;
-                                       } else if (pCoexDm->curPsTdma == 2) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                               pCoexDm->psTdmaDuAdjType = 3;
-                                       } else if (pCoexDm->curPsTdma == 3) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
-                                               pCoexDm->psTdmaDuAdjType = 4;
-                                       } else if (pCoexDm->curPsTdma == 9) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
-                                               pCoexDm->psTdmaDuAdjType = 10;
-                                       } else if (pCoexDm->curPsTdma == 10) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                               pCoexDm->psTdmaDuAdjType = 11;
-                                       } else if (pCoexDm->curPsTdma == 11) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
-                                               pCoexDm->psTdmaDuAdjType = 12;
-                                       }
+                                       if (pCoexDm->curPsTdma == 71)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(1);
+                                       else if (pCoexDm->curPsTdma == 1)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
+                                       else if (pCoexDm->curPsTdma == 2)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
+                                       else if (pCoexDm->curPsTdma == 3)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4);
+                                       else if (pCoexDm->curPsTdma == 9)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
+                                       else if (pCoexDm->curPsTdma == 10)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
+                                       else if (pCoexDm->curPsTdma == 11)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12);
                                } else if (result == 1) {
-                                       if (pCoexDm->curPsTdma == 4) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                               pCoexDm->psTdmaDuAdjType = 3;
-                                       } else if (pCoexDm->curPsTdma == 3) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
-                                               pCoexDm->psTdmaDuAdjType = 2;
-                                       } else if (pCoexDm->curPsTdma == 2) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1);
-                                               pCoexDm->psTdmaDuAdjType = 1;
-                                       } else if (pCoexDm->curPsTdma == 1) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 71);
-                                               pCoexDm->psTdmaDuAdjType = 71;
-                                       } else if (pCoexDm->curPsTdma == 12) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                               pCoexDm->psTdmaDuAdjType = 11;
-                                       } else if (pCoexDm->curPsTdma == 11) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
-                                               pCoexDm->psTdmaDuAdjType = 10;
-                                       } else if (pCoexDm->curPsTdma == 10) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
-                                               pCoexDm->psTdmaDuAdjType = 9;
-                                       }
+                                       if (pCoexDm->curPsTdma == 4)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
+                                       else if (pCoexDm->curPsTdma == 3)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
+                                       else if (pCoexDm->curPsTdma == 2)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(1);
+                                       else if (pCoexDm->curPsTdma == 1)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(71);
+                                       else if (pCoexDm->curPsTdma == 12)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
+                                       else if (pCoexDm->curPsTdma == 11)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
+                                       else if (pCoexDm->curPsTdma == 10)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(9);
                                }
                        }
                } else if (maxInterval == 2) {
                        if (bTxPause) {
                                BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));
-                               if (pCoexDm->curPsTdma == 1) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
-                                       pCoexDm->psTdmaDuAdjType = 6;
-                               } else if (pCoexDm->curPsTdma == 2) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
-                                       pCoexDm->psTdmaDuAdjType = 6;
-                               } else if (pCoexDm->curPsTdma == 3) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                       pCoexDm->psTdmaDuAdjType = 7;
-                               } else if (pCoexDm->curPsTdma == 4) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
-                                       pCoexDm->psTdmaDuAdjType = 8;
-                               }
-
-                               if (pCoexDm->curPsTdma == 9) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
-                                       pCoexDm->psTdmaDuAdjType = 14;
-                               } else if (pCoexDm->curPsTdma == 10) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
-                                       pCoexDm->psTdmaDuAdjType = 14;
-                               } else if (pCoexDm->curPsTdma == 11) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                       pCoexDm->psTdmaDuAdjType = 15;
-                               } else if (pCoexDm->curPsTdma == 12) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
-                                       pCoexDm->psTdmaDuAdjType = 16;
-                               }
+                               if (pCoexDm->curPsTdma == 1)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
+                               else if (pCoexDm->curPsTdma == 2)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
+                               else if (pCoexDm->curPsTdma == 3)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
+                               else if (pCoexDm->curPsTdma == 4)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8);
+
+                               if (pCoexDm->curPsTdma == 9)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
+                               else if (pCoexDm->curPsTdma == 10)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
+                               else if (pCoexDm->curPsTdma == 11)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
+                               else if (pCoexDm->curPsTdma == 12)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16);
 
                                if (result == -1) {
-                                       if (pCoexDm->curPsTdma == 5) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
-                                               pCoexDm->psTdmaDuAdjType = 6;
-                                       } else if (pCoexDm->curPsTdma == 6) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                               pCoexDm->psTdmaDuAdjType = 7;
-                                       } else if (pCoexDm->curPsTdma == 7) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
-                                               pCoexDm->psTdmaDuAdjType = 8;
-                                       } else if (pCoexDm->curPsTdma == 13) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
-                                               pCoexDm->psTdmaDuAdjType = 14;
-                                       } else if (pCoexDm->curPsTdma == 14) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                               pCoexDm->psTdmaDuAdjType = 15;
-                                       } else if (pCoexDm->curPsTdma == 15) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
-                                               pCoexDm->psTdmaDuAdjType = 16;
-                                       }
+                                       if (pCoexDm->curPsTdma == 5)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
+                                       else if (pCoexDm->curPsTdma == 6)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
+                                       else if (pCoexDm->curPsTdma == 7)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8);
+                                       else if (pCoexDm->curPsTdma == 13)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
+                                       else if (pCoexDm->curPsTdma == 14)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
+                                       else if (pCoexDm->curPsTdma == 15)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16);
                                } else if (result == 1) {
-                                       if (pCoexDm->curPsTdma == 8) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                               pCoexDm->psTdmaDuAdjType = 7;
-                                       } else if (pCoexDm->curPsTdma == 7) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
-                                               pCoexDm->psTdmaDuAdjType = 6;
-                                       } else if (pCoexDm->curPsTdma == 6) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
-                                               pCoexDm->psTdmaDuAdjType = 6;
-                                       } else if (pCoexDm->curPsTdma == 16) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                               pCoexDm->psTdmaDuAdjType = 15;
-                                       } else if (pCoexDm->curPsTdma == 15) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
-                                               pCoexDm->psTdmaDuAdjType = 14;
-                                       } else if (pCoexDm->curPsTdma == 14) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
-                                               pCoexDm->psTdmaDuAdjType = 14;
-                                       }
+                                       if (pCoexDm->curPsTdma == 8)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
+                                       else if (pCoexDm->curPsTdma == 7)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
+                                       else if (pCoexDm->curPsTdma == 6)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
+                                       else if (pCoexDm->curPsTdma == 16)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
+                                       else if (pCoexDm->curPsTdma == 15)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
+                                       else if (pCoexDm->curPsTdma == 14)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
                                }
                        } else {
                                BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));
-                               if (pCoexDm->curPsTdma == 5) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
-                                       pCoexDm->psTdmaDuAdjType = 2;
-                               } else if (pCoexDm->curPsTdma == 6) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
-                                       pCoexDm->psTdmaDuAdjType = 2;
-                               } else if (pCoexDm->curPsTdma == 7) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                       pCoexDm->psTdmaDuAdjType = 3;
-                               } else if (pCoexDm->curPsTdma == 8) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
-                                       pCoexDm->psTdmaDuAdjType = 4;
-                               }
-
-                               if (pCoexDm->curPsTdma == 13) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
-                                       pCoexDm->psTdmaDuAdjType = 10;
-                               } else if (pCoexDm->curPsTdma == 14) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
-                                       pCoexDm->psTdmaDuAdjType = 10;
-                               } else if (pCoexDm->curPsTdma == 15) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                       pCoexDm->psTdmaDuAdjType = 11;
-                               } else if (pCoexDm->curPsTdma == 16) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
-                                       pCoexDm->psTdmaDuAdjType = 12;
-                               }
+                               if (pCoexDm->curPsTdma == 5)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
+                               else if (pCoexDm->curPsTdma == 6)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
+                               else if (pCoexDm->curPsTdma == 7)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
+                               else if (pCoexDm->curPsTdma == 8)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4);
+
+                               if (pCoexDm->curPsTdma == 13)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
+                               else if (pCoexDm->curPsTdma == 14)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
+                               else if (pCoexDm->curPsTdma == 15)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
+                               else if (pCoexDm->curPsTdma == 16)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12);
 
                                if (result == -1) {
-                                       if (pCoexDm->curPsTdma == 1) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
-                                               pCoexDm->psTdmaDuAdjType = 2;
-                                       } else if (pCoexDm->curPsTdma == 2) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                               pCoexDm->psTdmaDuAdjType = 3;
-                                       } else if (pCoexDm->curPsTdma == 3) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
-                                               pCoexDm->psTdmaDuAdjType = 4;
-                                       } else if (pCoexDm->curPsTdma == 9) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
-                                               pCoexDm->psTdmaDuAdjType = 10;
-                                       } else if (pCoexDm->curPsTdma == 10) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                               pCoexDm->psTdmaDuAdjType = 11;
-                                       } else if (pCoexDm->curPsTdma == 11) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
-                                               pCoexDm->psTdmaDuAdjType = 12;
-                                       }
+                                       if (pCoexDm->curPsTdma == 1)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
+                                       else if (pCoexDm->curPsTdma == 2)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
+                                       else if (pCoexDm->curPsTdma == 3)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4);
+                                       else if (pCoexDm->curPsTdma == 9)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
+                                       else if (pCoexDm->curPsTdma == 10)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
+                                       else if (pCoexDm->curPsTdma == 11)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12);
                                } else if (result == 1) {
-                                       if (pCoexDm->curPsTdma == 4) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                               pCoexDm->psTdmaDuAdjType = 3;
-                                       } else if (pCoexDm->curPsTdma == 3) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
-                                               pCoexDm->psTdmaDuAdjType = 2;
-                                       } else if (pCoexDm->curPsTdma == 2) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
-                                               pCoexDm->psTdmaDuAdjType = 2;
-                                       } else if (pCoexDm->curPsTdma == 12) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                               pCoexDm->psTdmaDuAdjType = 11;
-                                       } else if (pCoexDm->curPsTdma == 11) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
-                                               pCoexDm->psTdmaDuAdjType = 10;
-                                       } else if (pCoexDm->curPsTdma == 10) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 10);
-                                               pCoexDm->psTdmaDuAdjType = 10;
-                                       }
+                                       if (pCoexDm->curPsTdma == 4)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
+                                       else if (pCoexDm->curPsTdma == 3)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
+                                       else if (pCoexDm->curPsTdma == 2)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
+                                       else if (pCoexDm->curPsTdma == 12)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
+                                       else if (pCoexDm->curPsTdma == 11)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
+                                       else if (pCoexDm->curPsTdma == 10)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
                                }
                        }
                } else if (maxInterval == 3) {
                        if (bTxPause) {
                                BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));
-                               if (pCoexDm->curPsTdma == 1) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                       pCoexDm->psTdmaDuAdjType = 7;
-                               } else if (pCoexDm->curPsTdma == 2) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                       pCoexDm->psTdmaDuAdjType = 7;
-                               } else if (pCoexDm->curPsTdma == 3) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                       pCoexDm->psTdmaDuAdjType = 7;
-                               } else if (pCoexDm->curPsTdma == 4) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
-                                       pCoexDm->psTdmaDuAdjType = 8;
-                               }
-
-                               if (pCoexDm->curPsTdma == 9) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                       pCoexDm->psTdmaDuAdjType = 15;
-                               } else if (pCoexDm->curPsTdma == 10) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                       pCoexDm->psTdmaDuAdjType = 15;
-                               } else if (pCoexDm->curPsTdma == 11) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                       pCoexDm->psTdmaDuAdjType = 15;
-                               } else if (pCoexDm->curPsTdma == 12) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
-                                       pCoexDm->psTdmaDuAdjType = 16;
-                               }
+                               if (pCoexDm->curPsTdma == 1)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
+                               else if (pCoexDm->curPsTdma == 2)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
+                               else if (pCoexDm->curPsTdma == 3)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
+                               else if (pCoexDm->curPsTdma == 4)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8);
+
+                               if (pCoexDm->curPsTdma == 9)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
+                               else if (pCoexDm->curPsTdma == 10)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
+                               else if (pCoexDm->curPsTdma == 11)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
+                               else if (pCoexDm->curPsTdma == 12)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16);
 
                                if (result == -1) {
-                                       if (pCoexDm->curPsTdma == 5) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                               pCoexDm->psTdmaDuAdjType = 7;
-                                       } else if (pCoexDm->curPsTdma == 6) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                               pCoexDm->psTdmaDuAdjType = 7;
-                                       } else if (pCoexDm->curPsTdma == 7) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 8);
-                                               pCoexDm->psTdmaDuAdjType = 8;
-                                       } else if (pCoexDm->curPsTdma == 13) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                               pCoexDm->psTdmaDuAdjType = 15;
-                                       } else if (pCoexDm->curPsTdma == 14) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                               pCoexDm->psTdmaDuAdjType = 15;
-                                       } else if (pCoexDm->curPsTdma == 15) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 16);
-                                               pCoexDm->psTdmaDuAdjType = 16;
-                                       }
+                                       if (pCoexDm->curPsTdma == 5)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
+                                       else if (pCoexDm->curPsTdma == 6)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
+                                       else if (pCoexDm->curPsTdma == 7)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8);
+                                       else if (pCoexDm->curPsTdma == 13)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
+                                       else if (pCoexDm->curPsTdma == 14)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
+                                       else if (pCoexDm->curPsTdma == 15)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16);
                                } else if (result == 1) {
-                                       if (pCoexDm->curPsTdma == 8) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                               pCoexDm->psTdmaDuAdjType = 7;
-                                       } else if (pCoexDm->curPsTdma == 7) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                               pCoexDm->psTdmaDuAdjType = 7;
-                                       } else if (pCoexDm->curPsTdma == 6) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 7);
-                                               pCoexDm->psTdmaDuAdjType = 7;
-                                       } else if (pCoexDm->curPsTdma == 16) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                               pCoexDm->psTdmaDuAdjType = 15;
-                                       } else if (pCoexDm->curPsTdma == 15) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                               pCoexDm->psTdmaDuAdjType = 15;
-                                       } else if (pCoexDm->curPsTdma == 14) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 15);
-                                               pCoexDm->psTdmaDuAdjType = 15;
-                                       }
+                                       if (pCoexDm->curPsTdma == 8)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
+                                       else if (pCoexDm->curPsTdma == 7)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
+                                       else if (pCoexDm->curPsTdma == 6)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
+                                       else if (pCoexDm->curPsTdma == 16)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
+                                       else if (pCoexDm->curPsTdma == 15)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
+                                       else if (pCoexDm->curPsTdma == 14)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
                                }
                        } else {
                                BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));
-                               if (pCoexDm->curPsTdma == 5) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                       pCoexDm->psTdmaDuAdjType = 3;
-                               } else if (pCoexDm->curPsTdma == 6) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                       pCoexDm->psTdmaDuAdjType = 3;
-                               } else if (pCoexDm->curPsTdma == 7) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                       pCoexDm->psTdmaDuAdjType = 3;
-                               } else if (pCoexDm->curPsTdma == 8) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
-                                       pCoexDm->psTdmaDuAdjType = 4;
-                               }
-
-                               if (pCoexDm->curPsTdma == 13) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                       pCoexDm->psTdmaDuAdjType = 11;
-                               } else if (pCoexDm->curPsTdma == 14) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                       pCoexDm->psTdmaDuAdjType = 11;
-                               } else if (pCoexDm->curPsTdma == 15) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                       pCoexDm->psTdmaDuAdjType = 11;
-                               } else if (pCoexDm->curPsTdma == 16) {
-                                       halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
-                                       pCoexDm->psTdmaDuAdjType = 12;
-                               }
+                               if (pCoexDm->curPsTdma == 5)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
+                               else if (pCoexDm->curPsTdma == 6)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
+                               else if (pCoexDm->curPsTdma == 7)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
+                               else if (pCoexDm->curPsTdma == 8)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4);
+
+                               if (pCoexDm->curPsTdma == 13)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
+                               else if (pCoexDm->curPsTdma == 14)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
+                               else if (pCoexDm->curPsTdma == 15)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
+                               else if (pCoexDm->curPsTdma == 16)
+                                       HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12);
 
                                if (result == -1) {
-                                       if (pCoexDm->curPsTdma == 1) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                               pCoexDm->psTdmaDuAdjType = 3;
-                                       } else if (pCoexDm->curPsTdma == 2) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                               pCoexDm->psTdmaDuAdjType = 3;
-                                       } else if (pCoexDm->curPsTdma == 3) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 4);
-                                               pCoexDm->psTdmaDuAdjType = 4;
-                                       } else if (pCoexDm->curPsTdma == 9) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                               pCoexDm->psTdmaDuAdjType = 11;
-                                       } else if (pCoexDm->curPsTdma == 10) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                               pCoexDm->psTdmaDuAdjType = 11;
-                                       } else if (pCoexDm->curPsTdma == 11) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 12);
-                                               pCoexDm->psTdmaDuAdjType = 12;
-                                       }
+                                       if (pCoexDm->curPsTdma == 1)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
+                                       else if (pCoexDm->curPsTdma == 2)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
+                                       else if (pCoexDm->curPsTdma == 3)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4);
+                                       else if (pCoexDm->curPsTdma == 9)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
+                                       else if (pCoexDm->curPsTdma == 10)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
+                                       else if (pCoexDm->curPsTdma == 11)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12);
                                } else if (result == 1) {
-                                       if (pCoexDm->curPsTdma == 4) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                               pCoexDm->psTdmaDuAdjType = 3;
-                                       } else if (pCoexDm->curPsTdma == 3) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                               pCoexDm->psTdmaDuAdjType = 3;
-                                       } else if (pCoexDm->curPsTdma == 2) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
-                                               pCoexDm->psTdmaDuAdjType = 3;
-                                       } else if (pCoexDm->curPsTdma == 12) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                               pCoexDm->psTdmaDuAdjType = 11;
-                                       } else if (pCoexDm->curPsTdma == 11) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                               pCoexDm->psTdmaDuAdjType = 11;
-                                       } else if (pCoexDm->curPsTdma == 10) {
-                                               halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
-                                               pCoexDm->psTdmaDuAdjType = 11;
-                                       }
+                                       if (pCoexDm->curPsTdma == 4)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
+                                       else if (pCoexDm->curPsTdma == 3)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
+                                       else if (pCoexDm->curPsTdma == 2)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
+                                       else if (pCoexDm->curPsTdma == 12)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
+                                       else if (pCoexDm->curPsTdma == 11)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
+                                       else if (pCoexDm->curPsTdma == 10)
+                                               HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
                                }
                        }
                }
index bae59e5153487f5c7fb91252fd4b2a433b69630c..19856e806b1f174a58707d15235cf423fd3d66b9 100644 (file)
@@ -299,7 +299,7 @@ void ODM_ReadAndConfig_MP_8723B_AGC_TAB(PDM_ODM_T pDM_Odm)
                                READ_NEXT_PAIR(v1, v2, i);
                        }
 
-                       if (bMatched == false) {
+                       if (!bMatched) {
                                /*  Condition isn't matched.
                                *   Discard the following (offset, data) pairs.
                                */
@@ -568,7 +568,7 @@ void ODM_ReadAndConfig_MP_8723B_PHY_REG(PDM_ODM_T pDM_Odm)
                                READ_NEXT_PAIR(v1, v2, i);
                        }
 
-                       if (bMatched == false) {
+                       if (!bMatched) {
                                /*  Condition isn't matched.
                                *   Discard the following (offset, data) pairs.
                                */
index 3c8e26aba406ecef7ac63667c87b82861209e2e0..b80c5b11796bb8f9e8e8a80f871b29db22c0ce5a 100644 (file)
@@ -270,7 +270,7 @@ void ODM_ReadAndConfig_MP_8723B_MAC_REG(PDM_ODM_T pDM_Odm)
                                READ_NEXT_PAIR(v1, v2, i);
                        }
 
-                       if (bMatched == false) {
+                       if (!bMatched) {
                                /*  Condition isn't matched. Discard the following (offset, data) pairs. */
                                while (v1 < 0x40000000 && i < ArrayLen-2)
                                        READ_NEXT_PAIR(v1, v2, i);
index ba42b4d2a9c4ed0089d7776c0283dba0ef72b86b..426f68b8f0d2b1374d222b0244a6bc7c5d87d5a7 100644 (file)
@@ -301,7 +301,7 @@ void ODM_ReadAndConfig_MP_8723B_RadioA(PDM_ODM_T pDM_Odm)
                                READ_NEXT_PAIR(v1, v2, i);
                        }
 
-                       if (bMatched == false) {
+                       if (!bMatched) {
                                /*  Condition isn't matched.
                                *   Discard the following (offset, data) pairs.
                                */
index 53d3bdf21a6f30334dc08ef47116108b0d8fb7f2..3239d37087c8b1ca4ab30347d08d44662b328532 100644 (file)
@@ -1292,7 +1292,7 @@ static void _PHY_SaveADDARegisters8723B(
        struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
        PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
 
-       if (ODM_CheckPowerStatus(padapter) == false)
+       if (!ODM_CheckPowerStatus(padapter))
                return;
 
        ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Save ADDA parameters.\n"));
@@ -1363,7 +1363,7 @@ static void _PHY_PathADDAOn8723B(
        ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("ADDA ON.\n"));
 
        pathOn = 0x01c00014;
-       if (false == is2T) {
+       if (!is2T) {
                pathOn = 0x01c00014;
                PHY_SetBBReg(pDM_Odm->Adapter, ADDAReg[0], bMaskDWord, 0x01c00014);
        } else {
@@ -1811,7 +1811,7 @@ void PHY_IQCalibrate_8723B(
        u32             StartTime;
        s32                     ProgressingTime;
 
-       if (ODM_CheckPowerStatus(padapter) == false)
+       if (!ODM_CheckPowerStatus(padapter))
                return;
 
        if (!(pDM_Odm->SupportAbility & ODM_RF_CALIBRATION))
index 6caddd7834a189f795c7924efb61cc8e524aa8e3..5257287b4f4dcc0aec9bdb1a4fa2aef60a9a6191 100644 (file)
@@ -112,9 +112,9 @@ void DBG_BT_INFO(u8 *dbgmsg)
 /*  */
 static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)
 {
-       if (!pBtCoexist->bBinded || !pBtCoexist->Adapter){
+       if (!pBtCoexist->bBinded || !pBtCoexist->Adapter)
                return false;
-       }
+
        return true;
 }
 
@@ -195,7 +195,6 @@ static void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
 static void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
 {
        struct adapter *padapter;
-       struct hal_com_data *pHalData;
        s32 ready;
        unsigned long stime;
        unsigned long utime;
@@ -203,7 +202,6 @@ static void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
 
 
        padapter = pBtCoexist->Adapter;
-       pHalData = GET_HAL_DATA(padapter);
        ready = _FAIL;
 #ifdef LPS_RPWM_WAIT_MS
        timeout = LPS_RPWM_WAIT_MS;
@@ -256,13 +254,11 @@ static void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
        padapter = pBtCoexist->Adapter;
        bNeedToAct = false;
 
-       if (pBtCoexist->btInfo.bRejectAggPkt)
+       if (pBtCoexist->btInfo.bRejectAggPkt) {
                rtw_btcoex_RejectApAggregatedPacket(padapter, true);
-       else {
-
+       } else {
                if (pBtCoexist->btInfo.bPreBtCtrlAggBufSize !=
-                       pBtCoexist->btInfo.bBtCtrlAggBufSize){
-
+                       pBtCoexist->btInfo.bBtCtrlAggBufSize) {
                        bNeedToAct = true;
                        pBtCoexist->btInfo.bPreBtCtrlAggBufSize = pBtCoexist->btInfo.bBtCtrlAggBufSize;
                }
@@ -292,7 +288,7 @@ static u8 halbtcoutsrc_IsWifiBusy(struct adapter *padapter)
        if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
                if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
                        return true;
-               if (true == pmlmepriv->LinkDetectInfo.bBusyTraffic)
+               if (pmlmepriv->LinkDetectInfo.bBusyTraffic)
                        return true;
        }
 
@@ -312,12 +308,12 @@ static u32 _halbtcoutsrc_GetWifiLinkStatus(struct adapter *padapter)
 
        if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
                if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
-                       if (true == bp2p)
+                       if (bp2p)
                                portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
                        else
                                portConnectedStatus |= WIFI_AP_CONNECTED;
                } else {
-                       if (true == bp2p)
+                       if (bp2p)
                                portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
                        else
                                portConnectedStatus |= WIFI_STA_CONNECTED;
@@ -362,15 +358,9 @@ static u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
 
 static s32 halbtcoutsrc_GetWifiRssi(struct adapter *padapter)
 {
-       struct hal_com_data *pHalData;
-       s32 UndecoratedSmoothedPWDB = 0;
+       struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
 
-
-       pHalData = GET_HAL_DATA(padapter);
-
-       UndecoratedSmoothedPWDB = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
-
-       return UndecoratedSmoothedPWDB;
+       return pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
 }
 
 static u8 halbtcoutsrc_GetWifiScanAPNum(struct adapter *padapter)
@@ -380,7 +370,7 @@ static u8 halbtcoutsrc_GetWifiScanAPNum(struct adapter *padapter)
 
        pmlmeext = &padapter->mlmeextpriv;
 
-       if (GLBtcWiFiInScanState == false) {
+       if (!GLBtcWiFiInScanState) {
                if (pmlmeext->sitesurvey_res.bss_cnt > 0xFF)
                        scan_AP_num = 0xFF;
                else
@@ -566,18 +556,14 @@ static u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
 {
        PBTC_COEXIST pBtCoexist;
        struct adapter *padapter;
-       struct hal_com_data *pHalData;
        u8 *pu8;
-       u8 *pU1Tmp;
        u32 *pU4Tmp;
        u8 ret;
 
 
        pBtCoexist = (PBTC_COEXIST)pBtcContext;
        padapter = pBtCoexist->Adapter;
-       pHalData = GET_HAL_DATA(padapter);
        pu8 = pInBuf;
-       pU1Tmp = pInBuf;
        pU4Tmp = pInBuf;
        ret = true;
 
@@ -620,11 +606,11 @@ static u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
 
        /*  set some u8 type variables. */
        case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
-               pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pU1Tmp;
+               pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pu8;
                break;
 
        case BTC_SET_U1_AGG_BUF_SIZE:
-               pBtCoexist->btInfo.aggBufSize = *pU1Tmp;
+               pBtCoexist->btInfo.aggBufSize = *pu8;
                break;
 
        /*  the following are some action which will be triggered */
@@ -639,15 +625,15 @@ static u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
        /* 1Ant =========== */
        /*  set some u8 type variables. */
        case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
-               pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pU1Tmp;
+               pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pu8;
                break;
 
        case BTC_SET_U1_LPS_VAL:
-               pBtCoexist->btInfo.lpsVal = *pU1Tmp;
+               pBtCoexist->btInfo.lpsVal = *pu8;
                break;
 
        case BTC_SET_U1_RPWM_VAL:
-               pBtCoexist->btInfo.rpwmVal = *pU1Tmp;
+               pBtCoexist->btInfo.rpwmVal = *pu8;
                break;
 
        /*  the following are some action which will be triggered */
@@ -822,11 +808,10 @@ static void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 D
        PBTC_COEXIST            pBtCoexist = (PBTC_COEXIST)pBtcContext;
        struct adapter *Adapter = pBtCoexist->Adapter;
 
-       if (BTC_INTF_SDIO == pBtCoexist->chipInterface) {
+       if (BTC_INTF_SDIO == pBtCoexist->chipInterface)
                rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
-       } else {
+       else
                rtw_write8(Adapter, RegAddr, Data);
-       }
 }
 
 static void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
@@ -1202,14 +1187,13 @@ void EXhalbtcoutsrc_SpecialPacketNotify(PBTC_COEXIST pBtCoexist, u8 pktType)
        if (pBtCoexist->bManualControl)
                return;
 
-       if (PACKET_DHCP == pktType)
+       if (PACKET_DHCP == pktType) {
                packetType = BTC_PACKET_DHCP;
-       else if (PACKET_EAPOL == pktType)
+       } else if (PACKET_EAPOL == pktType) {
                packetType = BTC_PACKET_EAPOL;
-       else if (PACKET_ARP == pktType)
+       } else if (PACKET_ARP == pktType) {
                packetType = BTC_PACKET_ARP;
-       else {
-               packetType = BTC_PACKET_UNKNOWN;
+       } else {
                return;
        }
 
@@ -1362,7 +1346,7 @@ u8 hal_btcoex_IsBtExist(struct adapter *padapter)
        return pHalData->bt_coexist.bBtExist;
 }
 
-u8 hal_btcoex_IsBtDisabled(struct adapter *padapter)
+bool hal_btcoex_IsBtDisabled(struct adapter *padapter)
 {
        if (!hal_btcoex_IsBtExist(padapter))
                return true;
@@ -1457,7 +1441,7 @@ void hal_btcoex_IQKNotify(struct adapter *padapter, u8 state)
 
 void hal_btcoex_BtInfoNotify(struct adapter *padapter, u8 length, u8 *tmpBuf)
 {
-       if (GLBtcWiFiInIQKState == true)
+       if (GLBtcWiFiInIQKState)
                return;
 
        EXhalbtcoutsrc_BtInfoNotify(&GLBtCoexist, tmpBuf, length);
@@ -1478,7 +1462,7 @@ void hal_btcoex_HaltNotify(struct adapter *padapter)
        EXhalbtcoutsrc_HaltNotify(&GLBtCoexist);
 }
 
-void hal_btcoex_Hanlder(struct adapter *padapter)
+void hal_btcoex_Handler(struct adapter *padapter)
 {
        EXhalbtcoutsrc_Periodical(&GLBtCoexist);
 }
index e5f1153527b9492b05a2a2b7a9e5a81c5c84b89b..638b12ae6ee975abf6da727e28bce2635cd18a3a 100644 (file)
@@ -125,7 +125,7 @@ u8 hal_com_config_channel_plan(
        if (0xFF == hw_channel_plan)
                AutoLoadFail = true;
 
-       if (false == AutoLoadFail) {
+       if (!AutoLoadFail) {
                u8 hw_chnlPlan;
 
                hw_chnlPlan = hw_channel_plan & (~EEPROM_CHANNEL_PLAN_BY_HW_MASK);
@@ -963,12 +963,6 @@ exit:
        return ret;
 }
 
-
-u8  rtw_hal_networktype_to_raid(struct adapter *adapter, struct sta_info *psta)
-{
-       return networktype_to_raid_ex(adapter, psta);
-}
-
 u8 rtw_get_mgntframe_raid(struct adapter *adapter, unsigned char network_type)
 {
 
index 4a4d17b44ba63a5f87c222374bfaa82949fe3421..acb25978a46c39053beede1553e7752b9cacb953 100644 (file)
@@ -400,11 +400,6 @@ bool rtw_hal_c2h_valid(struct adapter *adapter, u8 *buf)
        return c2h_evt_valid((struct c2h_evt_hdr_88xx *)buf);
 }
 
-s32 rtw_hal_c2h_evt_read(struct adapter *adapter, u8 *buf)
-{
-       return c2h_evt_read_88xx(adapter, buf);
-}
-
 s32 rtw_hal_c2h_handler(struct adapter *adapter, u8 *c2h_evt)
 {
        s32 ret = _FAIL;
index ebaefcaf5f2ae603ab0e986780cd84289fe8d588..24a9d8f783f019056a31cc7412c691976eb13b91 100644 (file)
@@ -8,30 +8,6 @@
 
 #include <drv_types.h>
 
-/**
-* Function:    PHY_CalculateBitShift
-*
-* OverView:    Get shifted position of the BitMask
-*
-* Input:
-*              u32     BitMask,
-*
-* Output:      none
-* Return:              u32     Return the shift bit bit position of the mask
-*/
-u32 PHY_CalculateBitShift(u32 BitMask)
-{
-       u32 i;
-
-       for (i = 0; i <= 31; i++) {
-               if (((BitMask>>i) &  0x1) == 1)
-                       break;
-       }
-
-       return i;
-}
-
-
 /*  */
 /*  ==> RF shadow Operation API Code Section!!! */
 /*  */
@@ -179,38 +155,3 @@ void PHY_RFShadowCompareFlagSetAll(IN PADAPTER Adapter)
        }
 
 }      /* PHY_RFShadowCompareFlagSetAll */
-
-
-void PHY_RFShadowRecorverFlagSetAll(IN PADAPTER Adapter)
-{
-       u8 eRFPath = 0;
-       u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
-
-       for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
-               for (Offset = 0; Offset < maxReg; Offset++) {
-                       /*  2008/11/20 MH For S3S4 test, we only check reg 26/27 now!!!! */
-                       if (Offset != 0x26 && Offset != 0x27)
-                               PHY_RFShadowRecorverFlagSet(Adapter, eRFPath, Offset, false);
-                       else
-                               PHY_RFShadowRecorverFlagSet(Adapter, eRFPath, Offset, true);
-               }
-       }
-
-}      /* PHY_RFShadowCompareFlagSetAll */
-
-void PHY_RFShadowRefresh(IN PADAPTER Adapter)
-{
-       u8 eRFPath = 0;
-       u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
-
-       for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
-               for (Offset = 0; Offset < maxReg; Offset++) {
-                       RF_Shadow[eRFPath][Offset].Value = 0;
-                       RF_Shadow[eRFPath][Offset].Compare = false;
-                       RF_Shadow[eRFPath][Offset].Recorver  = false;
-                       RF_Shadow[eRFPath][Offset].ErrorOrNot = false;
-                       RF_Shadow[eRFPath][Offset].Driver_Write = false;
-               }
-       }
-
-}      /* PHY_RFShadowRead */
diff --git a/drivers/staging/rtl8723bs/hal/odm_AntDiv.c b/drivers/staging/rtl8723bs/hal/odm_AntDiv.c
deleted file mode 100644 (file)
index d5415ee..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/******************************************************************************
- *
- * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
- *
- ******************************************************************************/
-
-//============================================================
-// include files
-//============================================================
-
-#include "odm_precomp.h"
-
-//======================================================
-// when antenna test utility is on or some testing
-// need to disable antenna diversity
-// call this function to disable all ODM related mechanisms
-// which will switch antenna.
-//======================================================
-void ODM_StopAntennaSwitchDm(PDM_ODM_T pDM_Odm)
-{
-       // disable ODM antenna diversity
-       pDM_Odm->SupportAbility &= ~ODM_BB_ANT_DIV;
-       ODM_RT_TRACE(
-               pDM_Odm,
-               ODM_COMP_ANT_DIV,
-               ODM_DBG_LOUD,
-               ("STOP Antenna Diversity\n")
-       );
-}
-
-void ODM_SetAntConfig(PDM_ODM_T pDM_Odm, u8 antSetting)// 0=A, 1=B, 2=C, ....
-{
-       if (antSetting == 0) // ant A
-               PHY_SetBBReg(pDM_Odm->Adapter, 0x948, bMaskDWord, 0x00000000);
-       else if (antSetting == 1)
-               PHY_SetBBReg(pDM_Odm->Adapter, 0x948, bMaskDWord, 0x00000280);
-}
-
-//======================================================
-
-
-void ODM_SwAntDivRestAfterLink(PDM_ODM_T pDM_Odm)
-{
-       pSWAT_T pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
-       pFAT_T pDM_FatTable = &pDM_Odm->DM_FatTable;
-       u32 i;
-
-       pDM_Odm->RSSI_test = false;
-       pDM_SWAT_Table->try_flag = 0xff;
-       pDM_SWAT_Table->RSSI_Trying = 0;
-       pDM_SWAT_Table->Double_chk_flag = 0;
-
-       pDM_FatTable->RxIdleAnt = MAIN_ANT;
-
-       for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) {
-               pDM_FatTable->MainAnt_Sum[i] = 0;
-               pDM_FatTable->AuxAnt_Sum[i] = 0;
-               pDM_FatTable->MainAnt_Cnt[i] = 0;
-               pDM_FatTable->AuxAnt_Cnt[i] = 0;
-       }
-}
diff --git a/drivers/staging/rtl8723bs/hal/odm_AntDiv.h b/drivers/staging/rtl8723bs/hal/odm_AntDiv.h
deleted file mode 100644 (file)
index c9496d5..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/******************************************************************************
- *
- * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
- *
- ******************************************************************************/
-
-#ifndef        __ODMANTDIV_H__
-#define    __ODMANTDIV_H__
-
-
-
-#define ANT1_2G 0 /*  = ANT2_5G */
-#define ANT2_2G 1 /*  = ANT1_5G */
-
-/* Antenna Diversty Control Type */
-#define        ODM_AUTO_ANT    0
-#define        ODM_FIX_MAIN_ANT        1
-#define        ODM_FIX_AUX_ANT 2
-
-#define        TX_BY_REG       0
-
-#define ANTDIV_ON 1
-#define ANTDIV_OFF 0
-
-#define INIT_ANTDIV_TIMMER 0
-#define CANCEL_ANTDIV_TIMMER 1
-#define RELEASE_ANTDIV_TIMMER 2
-
-#endif /* ifndef       __ODMANTDIV_H__ */
index 4fa6cd315cf7dd9ade675a0e624550eb8c2811a8..70d98c58ca97520a41a9853f35e5282824a92240 100644 (file)
@@ -496,13 +496,8 @@ void odm_DIGInit(void *pDM_VOID)
        /* To Initi BT30 IGI */
        pDM_DigTable->BT30_CurIGI = 0x32;
 
-       if (pDM_Odm->BoardType & (ODM_BOARD_EXT_PA|ODM_BOARD_EXT_LNA)) {
-               pDM_DigTable->rx_gain_range_max = DM_DIG_MAX_NIC;
-               pDM_DigTable->rx_gain_range_min = DM_DIG_MIN_NIC;
-       } else {
-               pDM_DigTable->rx_gain_range_max = DM_DIG_MAX_NIC;
-               pDM_DigTable->rx_gain_range_min = DM_DIG_MIN_NIC;
-       }
+       pDM_DigTable->rx_gain_range_max = DM_DIG_MAX_NIC;
+       pDM_DigTable->rx_gain_range_min = DM_DIG_MIN_NIC;
 
 }
 
@@ -525,7 +520,7 @@ void odm_DIG(void *pDM_VOID)
        bool bDFSBand = false;
        bool bPerformance = true, bFirstTpTarget = false, bFirstCoverage = false;
 
-       if (odm_DigAbort(pDM_Odm) == true)
+       if (odm_DigAbort(pDM_Odm))
                return;
 
        ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG() ===========================>\n\n"));
index d802a1fde58fd13c60e282643d2b825fed9c7bc7..49fa814068b80ca9f290ef816b9797d73b8cb1bb 100644 (file)
@@ -23,7 +23,7 @@ static u8 odm_QueryRxPwrPercentage(s8 AntPower)
 
 }
 
-static s32 odm_SignalScaleMapping_92CSeries(PDM_ODM_T pDM_Odm, s32 CurrSig)
+s32 odm_SignalScaleMapping(PDM_ODM_T pDM_Odm, s32 CurrSig)
 {
        s32 RetSig = 0;
 
@@ -49,11 +49,6 @@ static s32 odm_SignalScaleMapping_92CSeries(PDM_ODM_T pDM_Odm, s32 CurrSig)
        return RetSig;
 }
 
-s32 odm_SignalScaleMapping(PDM_ODM_T pDM_Odm, s32 CurrSig)
-{
-       return odm_SignalScaleMapping_92CSeries(pDM_Odm, CurrSig);
-}
-
 static u8 odm_EVMdbToPercentage(s8 Value)
 {
        /*  */
@@ -496,32 +491,3 @@ HAL_STATUS ODM_ConfigBBWithHeaderFile(
        return HAL_STATUS_SUCCESS;
 }
 
-HAL_STATUS ODM_ConfigMACWithHeaderFile(PDM_ODM_T pDM_Odm)
-{
-       u8 result = HAL_STATUS_SUCCESS;
-
-       ODM_RT_TRACE(
-               pDM_Odm,
-               ODM_COMP_INIT,
-               ODM_DBG_LOUD,
-               (
-                       "===>ODM_ConfigMACWithHeaderFile (%s)\n",
-                       (pDM_Odm->bIsMPChip) ? "MPChip" : "TestChip"
-               )
-       );
-       ODM_RT_TRACE(
-               pDM_Odm,
-               ODM_COMP_INIT,
-               ODM_DBG_LOUD,
-               (
-                       "pDM_Odm->SupportPlatform: 0x%X, pDM_Odm->SupportInterface: 0x%X, pDM_Odm->BoardType: 0x%X\n",
-                       pDM_Odm->SupportPlatform,
-                       pDM_Odm->SupportInterface,
-                       pDM_Odm->BoardType
-               )
-       );
-
-       READ_AND_CONFIG(8723B, _MAC_REG);
-
-       return result;
-}
index d3af1caaa73cf1da2d0f138efdcce5a6f25d810a..945366bc37ce051d274ee4d26b780a5604c3361d 100644 (file)
@@ -140,8 +140,6 @@ HAL_STATUS ODM_ConfigBBWithHeaderFile(
        PDM_ODM_T pDM_Odm, ODM_BB_Config_Type ConfigType
 );
 
-HAL_STATUS ODM_ConfigMACWithHeaderFile(PDM_ODM_T pDM_Odm);
-
 HAL_STATUS ODM_ConfigFWWithHeaderFile(
        PDM_ODM_T pDM_Odm,
        ODM_FW_Config_Type ConfigType,
index 12dfc58a6da0011d747d538daa8c62ffe57bfc97..07b585950cf96f561bfc8e7b7f2ae80683240b4b 100644 (file)
@@ -7,51 +7,46 @@
 #ifndef __INC_ODM_REGCONFIG_H_8723B
 #define __INC_ODM_REGCONFIG_H_8723B
 
-void odm_ConfigRFReg_8723B(
-       PDM_ODM_T pDM_Odm,
-       u32 Addr,
-       u32 Data,
-       ODM_RF_RADIO_PATH_E RF_PATH,
-       u32 RegAddr
+void odm_ConfigRFReg_8723B(PDM_ODM_T pDM_Odm,
+                          u32 Addr,
+                          u32 Data,
+                          ODM_RF_RADIO_PATH_E RF_PATH,
+                          u32 RegAddr
 );
 
 void odm_ConfigRF_RadioA_8723B(PDM_ODM_T pDM_Odm, u32 Addr, u32 Data);
 
 void odm_ConfigMAC_8723B(PDM_ODM_T pDM_Odm, u32 Addr, u8 Data);
 
-void odm_ConfigBB_AGC_8723B(
-       PDM_ODM_T pDM_Odm,
-       u32 Addr,
-       u32 Bitmask,
-       u32 Data
+void odm_ConfigBB_AGC_8723B(PDM_ODM_T pDM_Odm,
+                           u32 Addr,
+                           u32 Bitmask,
+                           u32 Data
 );
 
-void odm_ConfigBB_PHY_REG_PG_8723B(
-       PDM_ODM_T pDM_Odm,
-       u32 Band,
-       u32 RfPath,
-       u32 TxNum,
-       u32 Addr,
-       u32 Bitmask,
-       u32 Data
+void odm_ConfigBB_PHY_REG_PG_8723B(PDM_ODM_T pDM_Odm,
+                                  u32 Band,
+                                  u32 RfPath,
+                                  u32 TxNum,
+                                  u32 Addr,
+                                  u32 Bitmask,
+                                  u32 Data
 );
 
-void odm_ConfigBB_PHY_8723B(
-       PDM_ODM_T pDM_Odm,
-       u32 Addr,
-       u32 Bitmask,
-       u32 Data
+void odm_ConfigBB_PHY_8723B(PDM_ODM_T pDM_Odm,
+                           u32 Addr,
+                           u32 Bitmask,
+                           u32 Data
 );
 
-void odm_ConfigBB_TXPWR_LMT_8723B(
-       PDM_ODM_T pDM_Odm,
-       u8 *Regulation,
-       u8 *Band,
-       u8 *Bandwidth,
-       u8 *RateSection,
-       u8 *RfPath,
-       u8 *Channel,
-       u8 *PowerLimit
+void odm_ConfigBB_TXPWR_LMT_8723B(PDM_ODM_T pDM_Odm,
+                                 u8 *Regulation,
+                                 u8 *Band,
+                                 u8 *Bandwidth,
+                                 u8 *RateSection,
+                                 u8 *RfPath,
+                                 u8 *Channel,
+                                 u8 *PowerLimit
 );
 
 #endif
index b5b0c0ed02fc46d4b7e28944e891c5ddc47c569b..d48d681472d58a863f1329ad86d16b8b65b95709 100644 (file)
@@ -29,7 +29,6 @@
 #include "odm_HWConfig.h"
 #include "odm_debug.h"
 #include "odm_RegDefine11N.h"
-#include "odm_AntDiv.h"
 #include "odm_EdcaTurboCheck.h"
 #include "odm_DIG.h"
 #include "odm_PathDiv.h"
index fe3891106a6d631e2f68449eef234d8760e0939c..080e974914b65b7188b1b9ffb6f9546ca4e55f4d 100644 (file)
@@ -73,7 +73,7 @@ s32 FillH2CCmd8723B(struct adapter *padapter, u8 ElementID, u32 CmdLen, u8 *pCmd
                goto exit;
        }
 
-       if (padapter->bSurpriseRemoved == true)
+       if (padapter->bSurpriseRemoved)
                goto exit;
 
        /* pay attention to if  race condition happened in  H2C cmd setting. */
@@ -297,7 +297,7 @@ static void ConstructNullFunctionData(
 
        SetSeqNum(pwlanhdr, 0);
 
-       if (bQoS == true) {
+       if (bQoS) {
                struct ieee80211_qos_hdr *pwlanqoshdr;
 
                SetFrameSubType(pframe, WIFI_QOS_DATA_NULL);
@@ -436,7 +436,7 @@ static void ConstructARPResponse(
                DBG_871X("%s(): Add MIC\n", __func__);
 
                psta = rtw_get_stainfo(&padapter->stapriv, get_my_bssid(&(pmlmeinfo->network)));
-               if (psta != NULL) {
+               if (psta) {
                        if (!memcmp(&psta->dot11tkiptxmickey.skey[0], null_key, 16)) {
                                DBG_871X("%s(): STA dot11tkiptxmickey == 0\n", __func__);
                        }
@@ -674,10 +674,6 @@ static void ConstructProbeReq(struct adapter *padapter, u8 *pframe, u32 *pLength
        u32 pktlen;
        unsigned char *mac;
        unsigned char bssrate[NumRates];
-       struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
-       struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
-       struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
-       struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
        int bssrate_len = 0;
        u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 
@@ -757,7 +753,7 @@ static void ConstructProbeRsp(struct adapter *padapter, u8 *pframe, u32 *pLength
                        cur_network->IELength-_FIXED_IE_LENGTH_, NULL, &wps_ielen);
 
        /* inerset & update wps_probe_resp_ie */
-       if ((pmlmepriv->wps_probe_resp_ie != NULL) && pwps_ie && (wps_ielen > 0)) {
+       if (pmlmepriv->wps_probe_resp_ie && pwps_ie && (wps_ielen > 0)) {
                uint wps_offset, remainder_ielen;
                u8 *premainder_ie;
 
@@ -995,7 +991,7 @@ void rtl8723b_set_FwMacIdConfig_cmd(struct adapter *padapter, u8 mac_id, u8 raid
        FillH2CCmd8723B(padapter, H2C_8723B_MACID_CFG, H2C_MACID_CFG_LEN, u1H2CMacIdConfigParm);
 }
 
-static void rtl8723b_set_FwRssiSetting_cmd(struct adapter *padapter, u8 *param)
+void rtl8723b_set_rssi_cmd(struct adapter *padapter, u8 *param)
 {
        u8 u1H2CRssiSettingParm[H2C_RSSI_SETTING_LEN] = {0};
        u8 mac_id = *param;
@@ -1048,9 +1044,9 @@ void rtl8723b_set_FwPwrMode_cmd(struct adapter *padapter, u8 psmode)
        }
 
        if (psmode > 0) {
-               if (rtw_btcoex_IsBtControlLps(padapter) == true) {
-                       PowerState = rtw_btcoex_RpwmVal(padapter);
-                       byte5 = rtw_btcoex_LpsVal(padapter);
+               if (hal_btcoex_IsBtControlLps(padapter) == true) {
+                       PowerState = hal_btcoex_RpwmVal(padapter);
+                       byte5 = hal_btcoex_LpsVal(padapter);
 
                        if ((rlbm == 2) && (byte5 & BIT(4))) {
                                /*  Keep awake interval to 1 to prevent from */
@@ -1075,7 +1071,7 @@ void rtl8723b_set_FwPwrMode_cmd(struct adapter *padapter, u8 psmode)
        SET_8723B_H2CCMD_PWRMODE_PARM_PWR_STATE(u1H2CPwrModeParm, PowerState);
        SET_8723B_H2CCMD_PWRMODE_PARM_BYTE5(u1H2CPwrModeParm, byte5);
        if (psmode != PS_MODE_ACTIVE) {
-               if (pmlmeext->adaptive_tsf_done == false && pmlmeext->bcn_cnt > 0) {
+               if (!pmlmeext->adaptive_tsf_done && pmlmeext->bcn_cnt > 0) {
                        u8 ratio_20_delay, ratio_80_delay;
 
                        /* byte 6 for adaptive_early_32k */
@@ -1137,7 +1133,7 @@ void rtl8723b_set_FwPwrMode_cmd(struct adapter *padapter, u8 psmode)
 
        }
 
-       rtw_btcoex_RecordPwrMode(padapter, u1H2CPwrModeParm, H2C_PWRMODE_LEN);
+       hal_btcoex_RecordPwrMode(padapter, u1H2CPwrModeParm, H2C_PWRMODE_LEN);
 
        RT_PRINT_DATA(_module_hal_init_c_, _drv_always_, "u1H2CPwrModeParm:", u1H2CPwrModeParm, H2C_PWRMODE_LEN);
 
@@ -1256,7 +1252,7 @@ static void rtl8723b_set_FwRemoteWakeCtrl_Cmd(struct adapter *padapter, u8 benab
        FillH2CCmd8723B(padapter, H2C_8723B_REMOTE_WAKE_CTRL,
                H2C_REMOTE_WAKE_CTRL_LEN, u1H2CRemoteWakeCtrlParm);
 #ifdef CONFIG_PNO_SUPPORT
-       if (ppwrpriv->wowlan_pno_enable && ppwrpriv->pno_in_resume == false) {
+       if (ppwrpriv->wowlan_pno_enable && !ppwrpriv->pno_in_resume) {
                res = rtw_read8(padapter, REG_PNO_STATUS);
                DBG_871X("cmd: 0x81 REG_PNO_STATUS: 0x%02x\n", res);
                while (!(res&BIT(7)) && count < 25) {
@@ -1288,8 +1284,6 @@ static void rtl8723b_set_FwAOACGlobalInfo_Cmd(struct adapter *padapter,  u8 grou
 static void rtl8723b_set_FwScanOffloadInfo_cmd(struct adapter *padapter, PRSVDPAGE_LOC rsvdpageloc, u8 enable)
 {
        u8 u1H2CScanOffloadInfoParm[H2C_SCAN_OFFLOAD_CTRL_LEN] = {0};
-       u8 res = 0, count = 0;
-       struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
 
        DBG_871X("%s: loc_probe_packet:%d, loc_scan_info: %d loc_ssid_info:%d\n",
                __func__, rsvdpageloc->LocProbePacket, rsvdpageloc->LocScanInfo, rsvdpageloc->LocSSIDInfo);
@@ -1322,7 +1316,7 @@ static void rtl8723b_set_FwWoWlanRelated_cmd(struct adapter *padapter, u8 enable
 
                if (!(ppwrpriv->wowlan_pno_enable)) {
                        psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(pmlmepriv));
-                       if (psta != NULL)
+                       if (psta)
                                rtl8723b_set_FwMediaStatusRpt_cmd(padapter, RT_MEDIA_CONNECT, psta->mac_id);
                } else
                        DBG_871X("%s(): Disconnected, no FwMediaStatusRpt CONNECT\n", __func__);
@@ -1440,7 +1434,6 @@ static void rtl8723b_set_FwRsvdPagePkt(
        struct adapter *padapter, bool bDLFinished
 )
 {
-       struct hal_com_data *pHalData;
        struct xmit_frame *pcmdframe;
        struct pkt_attrib *pattrib;
        struct xmit_priv *pxmitpriv;
@@ -1470,7 +1463,6 @@ static void rtl8723b_set_FwRsvdPagePkt(
 
        /* DBG_871X("%s---->\n", __func__); */
 
-       pHalData = GET_HAL_DATA(padapter);
        pxmitpriv = &padapter->xmitpriv;
        pmlmeext = &padapter->mlmeextpriv;
        pmlmeinfo = &pmlmeext->mlmext_info;
@@ -1677,7 +1669,7 @@ static void rtl8723b_set_FwRsvdPagePkt(
 #endif /* CONFIG_WOWLAN */
        {
 #ifdef CONFIG_PNO_SUPPORT
-               if (pwrctl->pno_in_resume == false && pwrctl->pno_inited == true) {
+               if (!pwrctl->pno_in_resume && pwrctl->pno_inited) {
                        /* Probe Request */
                        RsvdPageLoc.LocProbePacket = TotalPageNum;
                        ConstructProbeReq(
@@ -2036,11 +2028,6 @@ void rtl8723b_download_rsvd_page(struct adapter *padapter, u8 mstatus)
        }
 }
 
-void rtl8723b_set_rssi_cmd(struct adapter *padapter, u8 *param)
-{
-       rtl8723b_set_FwRssiSetting_cmd(padapter, param);
-}
-
 void rtl8723b_set_FwJoinBssRpt_cmd(struct adapter *padapter, u8 mstatus)
 {
        if (mstatus == 1)
@@ -2125,7 +2112,7 @@ static void ConstructBtNullFunctionData(
        SetDuration(pwlanhdr, 0);
        SetSeqNum(pwlanhdr, 0);
 
-       if (bQoS == true) {
+       if (bQoS) {
                struct ieee80211_qos_hdr *pwlanqoshdr;
 
                SetFrameSubType(pframe, WIFI_QOS_DATA_NULL);
@@ -2313,7 +2300,7 @@ void rtl8723b_download_BTCoex_AP_mode_rsvd_page(struct adapter *padapter)
                } while (!bcn_valid && (poll%10) != 0 && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
        } while (!bcn_valid && (DLBcnCount <= 100) && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
 
-       if (true == bcn_valid) {
+       if (bcn_valid) {
                struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
                pwrctl->fw_psmode_iface_id = padapter->iface_id;
                DBG_8192C(ADPT_FMT": DL RSVD page success! DLBcnCount:%d, poll:%d\n",
index 65781477cac9ebcf6ed3f8ba0b88a0d1209fec62..c514cb735afd339ca26866a817367f8d1285fd72 100644 (file)
@@ -173,7 +173,7 @@ void rtl8723b_HalDmWatchDog(struct adapter *Adapter)
        if (hw_init_completed == true) {
                u8 bLinked = false;
                u8 bsta_state = false;
-               u8 bBtDisabled = true;
+               bool bBtDisabled = true;
 
                if (rtw_linked_check(Adapter)) {
                        bLinked = true;
@@ -186,7 +186,7 @@ void rtl8723b_HalDmWatchDog(struct adapter *Adapter)
 
                /* ODM_CmnInfoUpdate(&pHalData->odmpriv , ODM_CMNINFO_RSSI_MIN, pdmpriv->MinUndecoratedPWDBForDM); */
 
-               bBtDisabled = rtw_btcoex_IsBtDisabled(Adapter);
+               bBtDisabled = hal_btcoex_IsBtDisabled(Adapter);
 
                ODM_CmnInfoUpdate(&pHalData->odmpriv, ODM_CMNINFO_BT_ENABLED, ((bBtDisabled == true)?false:true));
 
index caa8e2f394481d605bd24af98331e66c8c56335c..faeaf24fa8333d704c5836956b9293389ee0c4d1 100644 (file)
@@ -217,7 +217,7 @@ void _8051Reset8723(struct adapter *padapter)
        DBG_8192C("%s: Finish\n", __func__);
 }
 
-u8 g_fwdl_chksum_fail = 0;
+u8 g_fwdl_chksum_fail;
 
 static s32 polling_fwdl_chksum(
        struct adapter *adapter, u32 min_cnt, u32 timeout_ms
@@ -262,7 +262,7 @@ exit:
        return ret;
 }
 
-u8 g_fwdl_wintint_rdy_fail = 0;
+u8 g_fwdl_wintint_rdy_fail;
 
 static s32 _FWFreeToGo(struct adapter *adapter, u32 min_cnt, u32 timeout_ms)
 {
@@ -742,7 +742,7 @@ static void Hal_BT_EfusePowerSwitch(
 )
 {
        u8 tempval;
-       if (PwrState == true) {
+       if (PwrState) {
                /*  enable BT power cut */
                /*  0x6A[14] = 1 */
                tempval = rtw_read8(padapter, 0x6B);
@@ -783,7 +783,7 @@ static void Hal_EfusePowerSwitch(
        u16 tmpV16;
 
 
-       if (PwrState == true) {
+       if (PwrState) {
                /*  To avoid cannot access efuse regsiters after disable/enable several times during DTM test. */
                /*  Suggested by SD1 IsaacHsu. 2013.07.08, added by tynli. */
                tempval = rtw_read8(padapter, SDIO_LOCAL_BASE|SDIO_REG_HSUS_CTRL);
@@ -833,7 +833,7 @@ static void Hal_EfusePowerSwitch(
                        rtw_write16(padapter, REG_SYS_CLKR, tmpV16);
                }
 
-               if (bWrite == true) {
+               if (bWrite) {
                        /*  Enable LDO 2.5V before read/write action */
                        tempval = rtw_read8(padapter, EFUSE_TEST+3);
                        tempval &= 0x0F;
@@ -845,7 +845,7 @@ static void Hal_EfusePowerSwitch(
        } else {
                rtw_write8(padapter, REG_EFUSE_ACCESS, EFUSE_ACCESS_OFF);
 
-               if (bWrite == true) {
+               if (bWrite) {
                        /*  Disable LDO 2.5V after read/write action */
                        tempval = rtw_read8(padapter, EFUSE_TEST+3);
                        rtw_write8(padapter, EFUSE_TEST+3, (tempval & 0x7F));
@@ -1023,7 +1023,7 @@ static void hal_ReadEFuse_BT(
        }
 
        efuseTbl = rtw_malloc(EFUSE_BT_MAP_LEN);
-       if (efuseTbl == NULL) {
+       if (!efuseTbl) {
                DBG_8192C("%s: efuseTbl malloc fail!\n", __func__);
                return;
        }
@@ -2139,7 +2139,7 @@ static void UpdateHalRAMask8723B(struct adapter *padapter, u32 mac_id, u8 rssi_l
                return;
 
        psta = pmlmeinfo->FW_sta_info[mac_id].psta;
-       if (psta == NULL)
+       if (!psta)
                return;
 
        shortGIrate = query_ra_short_GI(psta);
@@ -2153,7 +2153,7 @@ static void UpdateHalRAMask8723B(struct adapter *padapter, u32 mac_id, u8 rssi_l
 
        mask &= rate_bitmap;
 
-       rate_bitmap = rtw_btcoex_GetRaMask(padapter);
+       rate_bitmap = hal_btcoex_GetRaMask(padapter);
        mask &= ~rate_bitmap;
 
 #ifdef CONFIG_CMCC_TEST
@@ -2166,7 +2166,7 @@ static void UpdateHalRAMask8723B(struct adapter *padapter, u32 mac_id, u8 rssi_l
        }
 #endif
 
-       if (pHalData->fw_ractrl == true) {
+       if (pHalData->fw_ractrl) {
                rtl8723b_set_FwMacIdConfig_cmd(padapter, mac_id, psta->raid, psta->bw_mode, shortGIrate, mask);
        }
 
@@ -2428,7 +2428,7 @@ void Hal_InitPGData(struct adapter *padapter, u8 *PROMContent)
 {
        struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
 
-       if (false == pEEPROM->bautoload_fail_flag) { /*  autoload OK. */
+       if (!pEEPROM->bautoload_fail_flag) { /*  autoload OK. */
                if (!pEEPROM->EepromOrEfuse) {
                        /*  Read EFUSE real map to shadow. */
                        EFUSE_ShadowMapUpdate(padapter, EFUSE_WIFI, false);
@@ -2436,7 +2436,7 @@ void Hal_InitPGData(struct adapter *padapter, u8 *PROMContent)
                }
        } else {/* autoload fail */
                RT_TRACE(_module_hci_hal_init_c_, _drv_notice_, ("AutoLoad Fail reported from CR9346!!\n"));
-               if (false == pEEPROM->EepromOrEfuse)
+               if (!pEEPROM->EepromOrEfuse)
                        EFUSE_ShadowMapUpdate(padapter, EFUSE_WIFI, false);
                memcpy((void *)PROMContent, (void *)pEEPROM->efuse_eeprom_data, HWSET_MAX_SIZE_8723B);
        }
@@ -2694,11 +2694,11 @@ void Hal_EfuseParseBTCoexistInfo_8723B(
                }
        }
 
-       rtw_btcoex_SetBTCoexist(padapter, pHalData->EEPROMBluetoothCoexist);
-       rtw_btcoex_SetChipType(padapter, pHalData->EEPROMBluetoothType);
-       rtw_btcoex_SetPGAntNum(padapter, pHalData->EEPROMBluetoothAntNum == Ant_x2 ? 2 : 1);
+       hal_btcoex_SetBTCoexist(padapter, pHalData->EEPROMBluetoothCoexist);
+       hal_btcoex_SetChipType(padapter, pHalData->EEPROMBluetoothType);
+       hal_btcoex_SetPgAntNum(padapter, pHalData->EEPROMBluetoothAntNum == Ant_x2 ? 2 : 1);
        if (pHalData->EEPROMBluetoothAntNum == Ant_x1)
-               rtw_btcoex_SetSingleAntPath(padapter, pHalData->ant_path);
+               hal_btcoex_SetSingleAntPath(padapter, pHalData->ant_path);
 
        DBG_8192C(
                "%s: %s BT-coex, ant_num =%d\n",
@@ -2842,12 +2842,12 @@ void Hal_EfuseParseThermalMeter_8723B(
        /*  */
        /*  ThermalMeter from EEPROM */
        /*  */
-       if (false == AutoLoadFail)
+       if (!AutoLoadFail)
                pHalData->EEPROMThermalMeter = PROMContent[EEPROM_THERMAL_METER_8723B];
        else
                pHalData->EEPROMThermalMeter = EEPROM_Default_ThermalMeter_8723B;
 
-       if ((pHalData->EEPROMThermalMeter == 0xff) || (true == AutoLoadFail)) {
+       if ((pHalData->EEPROMThermalMeter == 0xff) || AutoLoadFail) {
                pHalData->bAPKThermalMeterIgnore = true;
                pHalData->EEPROMThermalMeter = EEPROM_Default_ThermalMeter_8723B;
        }
@@ -3094,12 +3094,12 @@ static void rtl8723b_fill_default_txdesc(
                        (pattrib->dhcp_pkt != 1) &&
                        (drv_userate != 1)
 #ifdef CONFIG_AUTO_AP_MODE
-                       && (pattrib->pctrl != true)
+                       && (!pattrib->pctrl)
 #endif
                ) {
                        /*  Non EAP & ARP & DHCP type data packet */
 
-                       if (pattrib->ampdu_en == true) {
+                       if (pattrib->ampdu_en) {
                                ptxdesc->agg_en = 1; /*  AGG EN */
                                ptxdesc->max_agg_num = 0x1f;
                                ptxdesc->ampdu_density = pattrib->ampdu_spacing;
@@ -3110,7 +3110,7 @@ static void rtl8723b_fill_default_txdesc(
 
                        ptxdesc->data_ratefb_lmt = 0x1F;
 
-                       if (pHalData->fw_ractrl == false) {
+                       if (!pHalData->fw_ractrl) {
                                ptxdesc->userate = 1;
 
                                if (pHalData->dmpriv.INIDATA_RATE[pattrib->mac_id] & BIT(7))
@@ -3162,7 +3162,7 @@ static void rtl8723b_fill_default_txdesc(
                ptxdesc->mbssid = pattrib->mbssid & 0xF;
 
                ptxdesc->rty_lmt_en = 1; /*  retry limit enable */
-               if (pattrib->retry_ctrl == true) {
+               if (pattrib->retry_ctrl) {
                        ptxdesc->data_rt_lmt = 6;
                } else {
                        ptxdesc->data_rt_lmt = 12;
@@ -3265,14 +3265,14 @@ void rtl8723b_fill_fake_txdesc(
        SET_TX_DESC_QUEUE_SEL_8723B(pDesc, QSLT_MGNT); /*  Fixed queue of Mgnt queue */
 
        /*  Set NAVUSEHDR to prevent Ps-poll AId filed to be changed to error vlaue by Hw. */
-       if (true == IsPsPoll) {
+       if (IsPsPoll) {
                SET_TX_DESC_NAV_USE_HDR_8723B(pDesc, 1);
        } else {
                SET_TX_DESC_HWSEQ_EN_8723B(pDesc, 1); /*  Hw set sequence number */
                SET_TX_DESC_HWSEQ_SEL_8723B(pDesc, 0);
        }
 
-       if (true == IsBTQosNull) {
+       if (IsBTQosNull) {
                SET_TX_DESC_BT_INT_8723B(pDesc, 1);
        }
 
@@ -3284,7 +3284,7 @@ void rtl8723b_fill_fake_txdesc(
        /*  */
        /*  Encrypt the data frame if under security mode excepct null data. Suggested by CCW. */
        /*  */
-       if (true == bDataFrame) {
+       if (bDataFrame) {
                u32 EncAlg;
 
                EncAlg = padapter->securitypriv.dot11PrivacyAlgrthm;
@@ -3463,7 +3463,7 @@ static void hw_var_set_correct_tsf(struct adapter *padapter, u8 variable, u8 *va
        pmlmeext = &padapter->mlmeextpriv;
        pmlmeinfo = &pmlmeext->mlmext_info;
 
-       tsf = pmlmeext->TSFValue-rtw_modular64(pmlmeext->TSFValue, (pmlmeinfo->bcn_interval*1024))-1024; /* us */
+       tsf = pmlmeext->TSFValue-do_div(pmlmeext->TSFValue, (pmlmeinfo->bcn_interval*1024))-1024; /* us */
 
        if (
                ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) ||
@@ -3579,14 +3579,12 @@ static void hw_var_set_mlme_join(struct adapter *padapter, u8 variable, u8 *val)
        u32 val32;
        u8 RetryLimit;
        u8 type;
-       struct hal_com_data *pHalData;
        struct mlme_priv *pmlmepriv;
        struct eeprom_priv *pEEPROM;
 
 
        RetryLimit = 0x30;
        type = *(u8 *)val;
-       pHalData = GET_HAL_DATA(padapter);
        pmlmepriv = &padapter->mlmepriv;
        pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
 
@@ -3695,7 +3693,7 @@ s32 c2h_handler_8723b(struct adapter *padapter, u8 *buf)
                break;
 
        case C2H_8723B_BT_INFO:
-               rtw_btcoex_BtInfoNotify(padapter, pC2hEvent->plen, pC2hEvent->payload);
+               hal_btcoex_BtInfoNotify(padapter, pC2hEvent->plen, pC2hEvent->payload);
                break;
 
        default:
@@ -3744,7 +3742,7 @@ static void process_c2h_event(struct adapter *padapter, PC2H_EVT_HDR pC2hEvent,
                break;
 
        case C2H_8723B_BT_INFO:
-               rtw_btcoex_BtInfoNotify(padapter, pC2hEvent->CmdLen, c2hBuf);
+               hal_btcoex_BtInfoNotify(padapter, pC2hEvent->CmdLen, c2hBuf);
                break;
 
        default:
@@ -3759,7 +3757,7 @@ void C2HPacketHandler_8723B(struct adapter *padapter, u8 *pbuffer, u16 length)
 #ifdef CONFIG_WOWLAN
        struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
 
-       if (pwrpriv->wowlan_mode == true) {
+       if (pwrpriv->wowlan_mode) {
                DBG_871X("%s(): return because wowolan_mode ==true! CMDID =%d\n", __func__, pbuffer[0]);
                return;
        }
@@ -3878,7 +3876,7 @@ void SetHwReg8723B(struct adapter *padapter, u8 variable, u8 *val)
        case HW_VAR_MLME_SITESURVEY:
                hw_var_set_mlme_sitesurvey(padapter, variable,  val);
 
-               rtw_btcoex_ScanNotify(padapter, *val?true:false);
+               hal_btcoex_ScanNotify(padapter, *val?true:false);
                break;
 
        case HW_VAR_MLME_JOIN:
@@ -3887,11 +3885,11 @@ void SetHwReg8723B(struct adapter *padapter, u8 variable, u8 *val)
                switch (*val) {
                case 0:
                        /*  prepare to join */
-                       rtw_btcoex_ConnectNotify(padapter, true);
+                       hal_btcoex_ConnectNotify(padapter, true);
                        break;
                case 1:
                        /*  joinbss_event callback when join res < 0 */
-                       rtw_btcoex_ConnectNotify(padapter, false);
+                       hal_btcoex_ConnectNotify(padapter, false);
                        break;
                case 2:
                        /*  sta add event callback */
@@ -4119,7 +4117,7 @@ void SetHwReg8723B(struct adapter *padapter, u8 variable, u8 *val)
                        /*  keep sn */
                        padapter->xmitpriv.nqos_ssn = rtw_read16(padapter, REG_NQOS_SEQ);
 
-                       if (pwrpriv->bkeepfwalive != true) {
+                       if (!pwrpriv->bkeepfwalive) {
                                /* RX DMA stop */
                                val32 = rtw_read32(padapter, REG_RXPKT_NUM);
                                val32 |= RW_RELEASE_EN;
@@ -4274,7 +4272,7 @@ void GetHwReg8723B(struct adapter *padapter, u8 variable, u8 *val)
                        u32 valRCR;
 
                        if (
-                               (padapter->bSurpriseRemoved == true) ||
+                               padapter->bSurpriseRemoved  ||
                                (adapter_to_pwrctl(padapter)->rf_pwrstate == rf_off)
                        ) {
                                /*  If it is in HW/SW Radio OFF or IPS state, we do not check Fw LPS Leave, */
@@ -4345,11 +4343,8 @@ void GetHwReg8723B(struct adapter *padapter, u8 variable, u8 *val)
  */
 u8 SetHalDefVar8723B(struct adapter *padapter, enum HAL_DEF_VARIABLE variable, void *pval)
 {
-       struct hal_com_data *pHalData;
        u8 bResult;
 
-
-       pHalData = GET_HAL_DATA(padapter);
        bResult = _SUCCESS;
 
        switch (variable) {
@@ -4367,11 +4362,8 @@ u8 SetHalDefVar8723B(struct adapter *padapter, enum HAL_DEF_VARIABLE variable, v
  */
 u8 GetHalDefVar8723B(struct adapter *padapter, enum HAL_DEF_VARIABLE variable, void *pval)
 {
-       struct hal_com_data *pHalData;
        u8 bResult;
 
-
-       pHalData = GET_HAL_DATA(padapter);
        bResult = _SUCCESS;
 
        switch (variable) {
index 4f2ad54af398b9584898e3be3142e8b1982a74d2..d26bdfd11266b606d262a801803a0aabd457d47d 100644 (file)
@@ -375,7 +375,7 @@ s32 PHY_MACConfig8723B(struct adapter *Adapter)
        /*  */
        rtStatus = phy_ConfigMACWithParaFile(Adapter, pszMACRegFile);
        if (rtStatus == _FAIL) {
-               ODM_ConfigMACWithHeaderFile(&pHalData->odmpriv);
+               ODM_ReadAndConfig_MP_8723B_MAC_REG(&pHalData->odmpriv);
                rtStatus = _SUCCESS;
        }
 
index aa45a8421ebeeb202087552c0de79132d0359c44..d0ffe0af5339cb37e0349359b8805ab6bd3187b9 100644 (file)
@@ -114,12 +114,12 @@ static int phy_RF6052_Config_ParaFile(struct adapter *Adapter)
                        break;
                case RF_PATH_B:
                case RF_PATH_D:
-                       u4RegValue = PHY_QueryBBReg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV<<16);
+                       u4RegValue = PHY_QueryBBReg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV << 16);
                        break;
                }
 
                /*----Set RF_ENV enable----*/
-               PHY_SetBBReg(Adapter, pPhyReg->rfintfe, bRFSI_RFENV<<16, 0x1);
+               PHY_SetBBReg(Adapter, pPhyReg->rfintfe, bRFSI_RFENV << 16, 0x1);
                udelay(1);/* PlatformStallExecution(1); */
 
                /*----Set RF_ENV output high----*/
@@ -163,7 +163,7 @@ static int phy_RF6052_Config_ParaFile(struct adapter *Adapter)
                        break;
                case RF_PATH_B:
                case RF_PATH_D:
-                       PHY_SetBBReg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV<<16, u4RegValue);
+                       PHY_SetBBReg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV << 16, u4RegValue);
                        break;
                }
 
@@ -194,7 +194,6 @@ phy_RF6052_Config_ParaFile_Fail:
 int PHY_RF6052_Config8723B(struct adapter *Adapter)
 {
        struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
-       int rtStatus = _SUCCESS;
 
        /*  */
        /*  Initialize general global value */
@@ -208,8 +207,7 @@ int PHY_RF6052_Config8723B(struct adapter *Adapter)
        /*  */
        /*  Config BB and RF */
        /*  */
-       rtStatus = phy_RF6052_Config_ParaFile(Adapter);
-       return rtStatus;
+       return phy_RF6052_Config_ParaFile(Adapter);
 
 }
 
index b269de52e535d3ee9cd4ca7c5f5fe56a3e2f17a9..e23b39ab16c50eafbef213e94eaab916573cb9ff 100644 (file)
 #include <rtw_debug.h>
 #include <rtl8723b_hal.h>
 
-static s32 initrecvbuf(struct recv_buf *precvbuf, struct adapter *padapter)
+static void initrecvbuf(struct recv_buf *precvbuf, struct adapter *padapter)
 {
        INIT_LIST_HEAD(&precvbuf->list);
        spin_lock_init(&precvbuf->recvbuf_lock);
 
        precvbuf->adapter = padapter;
-
-       return _SUCCESS;
 }
 
 static void update_recvframe_attrib(struct adapter *padapter,
@@ -177,7 +175,7 @@ static void rtl8723bs_c2h_packet_handler(struct adapter *padapter,
 
        res = rtw_c2h_packet_wk_cmd(padapter, tmp, length);
 
-       if (res == false)
+       if (!res)
                kfree(tmp);
 
        /* DBG_871X("-%s res(%d)\n", __func__, res); */
@@ -435,9 +433,7 @@ s32 rtl8723bs_init_recv_priv(struct adapter *padapter)
        /*  init each recv buffer */
        precvbuf = (struct recv_buf *)precvpriv->precv_buf;
        for (i = 0; i < NR_RECVBUFF; i++) {
-               res = initrecvbuf(precvbuf, padapter);
-               if (res == _FAIL)
-                       break;
+               initrecvbuf(precvbuf, padapter);
 
                if (!precvbuf->pskb) {
                        SIZE_PTR tmpaddr = 0;
index 7b06aab04ee63f8649b002ba0dfff0efc59cf143..b44e902ed338cef7cd523bdde3b89e7341aec980 100644 (file)
@@ -17,8 +17,8 @@ static u8 rtw_sdio_wait_enough_TxOQT_space(struct adapter *padapter, u8 agg_num)
 
        while (pHalData->SdioTxOQTFreeSpace < agg_num) {
                if (
-                       (padapter->bSurpriseRemoved == true) ||
-                       (padapter->bDriverStopped == true)
+                       (padapter->bSurpriseRemoved) ||
+                       (padapter->bDriverStopped)
                ) {
                        DBG_871X("%s: bSurpriseRemoved or bDriverStopped (wait TxOQT)\n", __func__);
                        return false;
@@ -58,7 +58,7 @@ static s32 rtl8723_dequeue_writeport(struct adapter *padapter)
 
        ret = ret || check_fwstate(pmlmepriv, _FW_UNDER_SURVEY);
 
-       if (ret == true)
+       if (ret)
                pxmitbuf = dequeue_pending_xmitbuf_under_survey(pxmitpriv);
        else
                pxmitbuf = dequeue_pending_xmitbuf(pxmitpriv);
@@ -85,7 +85,7 @@ static s32 rtl8723_dequeue_writeport(struct adapter *padapter)
 
 query_free_page:
        /*  check if hardware tx fifo page is enough */
-       if (false == rtw_hal_sdio_query_tx_freepage(pri_padapter, PageIdx, pxmitbuf->pg_num)) {
+       if (!rtw_hal_sdio_query_tx_freepage(pri_padapter, PageIdx, pxmitbuf->pg_num)) {
                if (!bUpdatePageNum) {
                        /*  Total number of page is NOT available, so update current FIFO status */
                        HalQueryTxBufferStatus8723BSdio(padapter);
@@ -99,8 +99,8 @@ query_free_page:
        }
 
        if (
-               (padapter->bSurpriseRemoved == true) ||
-               (padapter->bDriverStopped == true)
+               (padapter->bSurpriseRemoved) ||
+               (padapter->bDriverStopped)
        ) {
                RT_TRACE(
                        _module_hal_xmit_c_,
@@ -153,7 +153,7 @@ s32 rtl8723bs_xmit_buf_handler(struct adapter *padapter)
                return _FAIL;
        }
 
-       ret = (padapter->bDriverStopped == true) || (padapter->bSurpriseRemoved == true);
+       ret = (padapter->bDriverStopped) || (padapter->bSurpriseRemoved);
        if (ret) {
                RT_TRACE(
                        _module_hal_xmit_c_,
@@ -170,7 +170,7 @@ s32 rtl8723bs_xmit_buf_handler(struct adapter *padapter)
 
        queue_pending = check_pending_xmitbuf(pxmitpriv);
 
-       if (queue_pending == false)
+       if (!queue_pending)
                return _SUCCESS;
 
        ret = rtw_register_tx_alive(padapter);
@@ -202,7 +202,7 @@ static s32 xmit_xmitframes(struct adapter *padapter, struct xmit_priv *pxmitpriv
        s32 err, ret;
        u32 k = 0;
        struct hw_xmit *hwxmits, *phwxmit;
-       u8 no_res, idx, hwentry;
+       u8 idx, hwentry;
        struct tx_servq *ptxservq;
        struct list_head *sta_plist, *sta_phead, *frame_plist, *frame_phead;
        struct xmit_frame *pxmitframe;
@@ -213,7 +213,6 @@ static s32 xmit_xmitframes(struct adapter *padapter, struct xmit_priv *pxmitpriv
        int inx[4];
 
        err = 0;
-       no_res = false;
        hwxmits = pxmitpriv->hwxmits;
        hwentry = pxmitpriv->hwxmit_entry;
        ptxservq = NULL;
@@ -236,8 +235,8 @@ static s32 xmit_xmitframes(struct adapter *padapter, struct xmit_priv *pxmitpriv
                phwxmit = hwxmits + inx[idx];
 
                if (
-                       (check_pending_xmitbuf(pxmitpriv) == true) &&
-                       (padapter->mlmepriv.LinkDetectInfo.bHigherBusyTxTraffic == true)
+                       (check_pending_xmitbuf(pxmitpriv)) &&
+                       (padapter->mlmepriv.LinkDetectInfo.bHigherBusyTxTraffic)
                ) {
                        if ((phwxmit->accnt > 0) && (phwxmit->accnt < 5)) {
                                err = -2;
@@ -285,7 +284,7 @@ static s32 xmit_xmitframes(struct adapter *padapter, struct xmit_priv *pxmitpriv
                                txlen = txdesc_size + rtw_wlan_pkt_size(pxmitframe);
                                if(     !pxmitbuf ||
                                        ((_RND(pxmitbuf->len, 8) + txlen) > max_xmit_len) ||
-                                       (k >= (rtw_hal_sdio_max_txoqt_free_space(padapter)-1))
+                                       (k >= (rtw_hal_sdio_max_txoqt_free_space(padapter) - 1))
                                ) {
                                        if (pxmitbuf) {
                                                /* pxmitbuf->priv_data will be NULL, and will crash here */
@@ -356,8 +355,8 @@ static s32 xmit_xmitframes(struct adapter *padapter, struct xmit_priv *pxmitpriv
                                        rtw_count_tx_stats(padapter, pxmitframe, pxmitframe->attrib.last_txcmdsz);
 
                                        txlen = txdesc_size + pxmitframe->attrib.last_txcmdsz;
-                                       pxmitframe->pg_num = (txlen + 127)/128;
-                                       pxmitbuf->pg_num += (txlen + 127)/128;
+                                       pxmitframe->pg_num = (txlen + 127) / 128;
+                                       pxmitbuf->pg_num += (txlen + 127) / 128;
                                    /* if (k != 1) */
                                        /*      ((struct xmit_frame*)pxmitbuf->priv_data)->pg_num += pxmitframe->pg_num; */
                                        pxmitbuf->ptail += _RND(txlen, 8); /*  round to 8 bytes alignment */
@@ -426,8 +425,8 @@ static s32 rtl8723bs_xmit_handler(struct adapter *padapter)
 
 next:
        if (
-               (padapter->bDriverStopped == true) ||
-               (padapter->bSurpriseRemoved == true)
+               (padapter->bDriverStopped) ||
+               (padapter->bSurpriseRemoved)
        ) {
                RT_TRACE(
                        _module_hal_xmit_c_,
@@ -523,7 +522,7 @@ s32 rtl8723bs_mgnt_xmit(
        rtl8723b_update_txdesc(pmgntframe, pmgntframe->buf_addr);
 
        pxmitbuf->len = txdesc_size + pattrib->last_txcmdsz;
-       pxmitbuf->pg_num = (pxmitbuf->len + 127)/128; /*  128 is tx page size */
+       pxmitbuf->pg_num = (pxmitbuf->len + 127) / 128; /*  128 is tx page size */
        pxmitbuf->ptail = pmgntframe->buf_addr + pxmitbuf->len;
        pxmitbuf->ff_hwaddr = rtw_get_ff_hwaddr(pmgntframe);
 
@@ -570,7 +569,7 @@ s32 rtl8723bs_hal_xmit(
                (pxmitframe->attrib.ether_type != 0x888e) &&
                (pxmitframe->attrib.dhcp_pkt != 1)
        ) {
-               if (padapter->mlmepriv.LinkDetectInfo.bBusyTraffic == true)
+               if (padapter->mlmepriv.LinkDetectInfo.bBusyTraffic)
                        rtw_issue_addbareq_cmd(padapter, pxmitframe);
        }
 
@@ -637,7 +636,6 @@ s32 rtl8723bs_init_xmit_priv(struct adapter *padapter)
 
 void rtl8723bs_free_xmit_priv(struct adapter *padapter)
 {
-       struct hal_com_data *phal;
        struct xmit_priv *pxmitpriv;
        struct xmit_buf *pxmitbuf;
        struct __queue *pqueue;
@@ -645,7 +643,6 @@ void rtl8723bs_free_xmit_priv(struct adapter *padapter)
        struct list_head tmplist;
 
 
-       phal = GET_HAL_DATA(padapter);
        pxmitpriv = &padapter->xmitpriv;
        pqueue = &pxmitpriv->pending_xmitbuf_queue;
        phead = get_list_head(pqueue);
index 3c65a9c02bbdc912f9066ef26b4fadd13446dba5..0f5dd4629e6f180b6d948e9f2df57de513c060ba 100644 (file)
@@ -26,7 +26,7 @@ static u8 CardEnable(struct adapter *padapter)
 
 
        rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
-       if (bMacPwrCtrlOn == false) {
+       if (!bMacPwrCtrlOn) {
                /*  RSV_CTRL 0x1C[7:0] = 0x00 */
                /*  unlock ISO/CLK/Power control register */
                rtw_write8(padapter, REG_RSV_CTRL, 0x0);
@@ -112,22 +112,22 @@ u8 _InitPowerOn_8723BS(struct adapter *padapter)
        /*  all of these MUST be configured before power on */
 #ifdef CONFIG_EXT_CLK
        /*  Use external crystal(XTAL) */
-       value8 = rtw_read8(padapter, REG_PAD_CTRL1_8723B+2);
+       value8 = rtw_read8(padapter, REG_PAD_CTRL1_8723B + 2);
        value8 |=  BIT(7);
-       rtw_write8(padapter, REG_PAD_CTRL1_8723B+2, value8);
+       rtw_write8(padapter, REG_PAD_CTRL1_8723B + 2, value8);
 
        /*  CLK_REQ High active or Low Active */
        /*  Request GPIO polarity: */
        /*  0: low active */
        /*  1: high active */
-       value8 = rtw_read8(padapter, REG_MULTI_FUNC_CTRL+1);
+       value8 = rtw_read8(padapter, REG_MULTI_FUNC_CTRL + 1);
        value8 |= BIT(5);
-       rtw_write8(padapter, REG_MULTI_FUNC_CTRL+1, value8);
+       rtw_write8(padapter, REG_MULTI_FUNC_CTRL + 1, value8);
 #endif /*  CONFIG_EXT_CLK */
 
        /*  only cmd52 can be used before power on(card enable) */
        ret = CardEnable(padapter);
-       if (ret == false) {
+       if (!ret) {
                RT_TRACE(
                        _module_hci_hal_init_c_,
                        _drv_emerg_,
@@ -137,12 +137,12 @@ u8 _InitPowerOn_8723BS(struct adapter *padapter)
        }
 
        /*  Radio-Off Pin Trigger */
-       value8 = rtw_read8(padapter, REG_GPIO_INTM+1);
+       value8 = rtw_read8(padapter, REG_GPIO_INTM + 1);
        value8 |= BIT(1); /*  Enable falling edge triggering interrupt */
-       rtw_write8(padapter, REG_GPIO_INTM+1, value8);
-       value8 = rtw_read8(padapter, REG_GPIO_IO_SEL_2+1);
+       rtw_write8(padapter, REG_GPIO_INTM + 1, value8);
+       value8 = rtw_read8(padapter, REG_GPIO_IO_SEL_2 + 1);
        value8 |= BIT(1);
-       rtw_write8(padapter, REG_GPIO_IO_SEL_2+1, value8);
+       rtw_write8(padapter, REG_GPIO_IO_SEL_2 + 1, value8);
 
        /*  Enable power down and GPIO interrupt */
        value16 = rtw_read16(padapter, REG_APS_FSMCO);
@@ -168,7 +168,7 @@ u8 _InitPowerOn_8723BS(struct adapter *padapter)
        );
        rtw_write16(padapter, REG_CR, value16);
 
-       rtw_btcoex_PowerOnSetting(padapter);
+       hal_btcoex_PowerOnSetting(padapter);
 
        /*  external switch to S1 */
        /*  0x38[11] = 0x1 */
@@ -203,13 +203,13 @@ static void _init_available_page_threshold(struct adapter *padapter, u8 numHQ, u
        u16 HQ_threshold, NQ_threshold, LQ_threshold;
 
        HQ_threshold = (numPubQ + numHQ + 1) >> 1;
-       HQ_threshold |= (HQ_threshold<<8);
+       HQ_threshold |= (HQ_threshold << 8);
 
        NQ_threshold = (numPubQ + numNQ + 1) >> 1;
-       NQ_threshold |= (NQ_threshold<<8);
+       NQ_threshold |= (NQ_threshold << 8);
 
        LQ_threshold = (numPubQ + numLQ + 1) >> 1;
-       LQ_threshold |= (LQ_threshold<<8);
+       LQ_threshold |= (LQ_threshold << 8);
 
        rtw_write16(padapter, 0x218, HQ_threshold);
        rtw_write16(padapter, 0x21A, NQ_threshold);
@@ -271,7 +271,7 @@ static void _InitTxBufferBoundary(struct adapter *padapter)
        rtw_write8(padapter, REG_TXPKTBUF_MGQ_BDNY_8723B, txpktbuf_bndy);
        rtw_write8(padapter, REG_TXPKTBUF_WMAC_LBK_BF_HD_8723B, txpktbuf_bndy);
        rtw_write8(padapter, REG_TRXFF_BNDY, txpktbuf_bndy);
-       rtw_write8(padapter, REG_TDECTRL+1, txpktbuf_bndy);
+       rtw_write8(padapter, REG_TDECTRL + 1, txpktbuf_bndy);
 }
 
 static void _InitNormalChipRegPriority(
@@ -397,7 +397,7 @@ static void _InitNormalChipThreeOutEpPriority(struct adapter *padapter)
        _InitNormalChipRegPriority(padapter, beQ, bkQ, viQ, voQ, mgtQ, hiQ);
 }
 
-static void _InitNormalChipQueuePriority(struct adapter *Adapter)
+static void _InitQueuePriority(struct adapter *Adapter)
 {
        struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
 
@@ -419,11 +419,6 @@ static void _InitNormalChipQueuePriority(struct adapter *Adapter)
 
 }
 
-static void _InitQueuePriority(struct adapter *padapter)
-{
-       _InitNormalChipQueuePriority(padapter);
-}
-
 static void _InitPageBoundary(struct adapter *padapter)
 {
        /*  RX Page Boundary */
@@ -569,7 +564,7 @@ static void HalRxAggr8723BSdio(struct adapter *padapter)
                valueDMAPageCount = 0x06;
        }
 
-       rtw_write8(padapter, REG_RXDMA_AGG_PG_TH+1, valueDMATimeout);
+       rtw_write8(padapter, REG_RXDMA_AGG_PG_TH + 1, valueDMATimeout);
        rtw_write8(padapter, REG_RXDMA_AGG_PG_TH, valueDMAPageCount);
 }
 
@@ -588,8 +583,8 @@ static void sdio_AggSettingRxUpdate(struct adapter *padapter)
        rtw_write8(padapter, REG_TRXDMA_CTRL, valueDMA);
 
        valueRxAggCtrl |= RXDMA_AGG_MODE_EN;
-       valueRxAggCtrl |= ((aggBurstNum<<2) & 0x0C);
-       valueRxAggCtrl |= ((aggBurstSize<<4) & 0x30);
+       valueRxAggCtrl |= ((aggBurstNum << 2) & 0x0C);
+       valueRxAggCtrl |= ((aggBurstSize << 4) & 0x30);
        rtw_write8(padapter, REG_RXDMA_MODE_CTRL_8723B, valueRxAggCtrl);/* RxAggLowThresh = 4*1K */
 }
 
@@ -611,12 +606,9 @@ static void _initSdioAggregationSetting(struct adapter *padapter)
 
 static void _InitOperationMode(struct adapter *padapter)
 {
-       struct hal_com_data *pHalData;
        struct mlme_ext_priv *pmlmeext;
        u8 regBwOpMode = 0;
-       u32 regRATR = 0, regRRSR = 0;
 
-       pHalData = GET_HAL_DATA(padapter);
        pmlmeext = &padapter->mlmeextpriv;
 
        /* 1 This part need to modified according to the rate set we filtered!! */
@@ -626,34 +618,24 @@ static void _InitOperationMode(struct adapter *padapter)
        switch (pmlmeext->cur_wireless_mode) {
        case WIRELESS_MODE_B:
                regBwOpMode = BW_OPMODE_20MHZ;
-               regRATR = RATE_ALL_CCK;
-               regRRSR = RATE_ALL_CCK;
                break;
        case WIRELESS_MODE_A:
 /*                     RT_ASSERT(false, ("Error wireless a mode\n")); */
                break;
        case WIRELESS_MODE_G:
                regBwOpMode = BW_OPMODE_20MHZ;
-               regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
-               regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
                break;
        case WIRELESS_MODE_AUTO:
                regBwOpMode = BW_OPMODE_20MHZ;
-               regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
-               regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
                break;
        case WIRELESS_MODE_N_24G:
                /*  It support CCK rate by default. */
                /*  CCK rate will be filtered out only when associated AP does not support it. */
                regBwOpMode = BW_OPMODE_20MHZ;
-               regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
-               regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
                break;
        case WIRELESS_MODE_N_5G:
 /*                     RT_ASSERT(false, ("Error wireless mode")); */
                regBwOpMode = BW_OPMODE_5G;
-               regRATR = RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
-               regRRSR = RATE_ALL_OFDM_AG;
                break;
 
        default: /* for MacOSX compiler warning. */
@@ -754,11 +736,11 @@ static u32 rtl8723bs_hal_init(struct adapter *padapter)
                rtw_hal_get_hwreg(padapter, HW_VAR_CPWM, &cpwm_orig);
 
                /* ser rpwm */
-               val8 = rtw_read8(padapter, SDIO_LOCAL_BASE|SDIO_REG_HRPWM1);
+               val8 = rtw_read8(padapter, SDIO_LOCAL_BASE | SDIO_REG_HRPWM1);
                val8 &= 0x80;
                val8 += 0x80;
                val8 |= BIT(6);
-               rtw_write8(padapter, SDIO_LOCAL_BASE|SDIO_REG_HRPWM1, val8);
+               rtw_write8(padapter, SDIO_LOCAL_BASE | SDIO_REG_HRPWM1, val8);
                DBG_871X("%s: write rpwm =%02x\n", __func__, val8);
                adapter_to_pwrctl(padapter)->tog = (val8 + 0x80) & 0x80;
 
@@ -782,13 +764,13 @@ static u32 rtl8723bs_hal_init(struct adapter *padapter)
 
                rtw_hal_set_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
 
-               rtw_btcoex_HAL_Initialize(padapter, false);
+               hal_btcoex_InitHwConfig(padapter, false);
 
                return _SUCCESS;
        }
 
 #ifdef CONFIG_WOWLAN
-       if (rtw_read8(padapter, REG_MCUFWDL)&BIT7) {
+       if (rtw_read8(padapter, REG_MCUFWDL) & BIT7) {
                u8 reg_val = 0;
                DBG_871X("+Reset Entry+\n");
                rtw_write8(padapter, REG_MCUFWDL, 0x00);
@@ -802,12 +784,12 @@ static u32 rtl8723bs_hal_init(struct adapter *padapter)
                /* reset TRX path */
                rtw_write16(padapter, REG_CR, 0);
                /* reset MAC, Digital Core */
-               reg_val = rtw_read8(padapter, REG_SYS_FUNC_EN+1);
+               reg_val = rtw_read8(padapter, REG_SYS_FUNC_EN + 1);
                reg_val &= ~(BIT(4) | BIT(7));
-               rtw_write8(padapter, REG_SYS_FUNC_EN+1, reg_val);
-               reg_val = rtw_read8(padapter, REG_SYS_FUNC_EN+1);
+               rtw_write8(padapter, REG_SYS_FUNC_EN + 1, reg_val);
+               reg_val = rtw_read8(padapter, REG_SYS_FUNC_EN + 1);
                reg_val |= BIT(4) | BIT(7);
-               rtw_write8(padapter, REG_SYS_FUNC_EN+1, reg_val);
+               rtw_write8(padapter, REG_SYS_FUNC_EN + 1, reg_val);
                DBG_871X("-Reset Entry-\n");
        }
 #endif /* CONFIG_WOWLAN */
@@ -838,7 +820,7 @@ static u32 rtl8723bs_hal_init(struct adapter *padapter)
 
 /*     SIC_Init(padapter); */
 
-       if (pwrctrlpriv->reg_rfoff == true)
+       if (pwrctrlpriv->reg_rfoff)
                pwrctrlpriv->rf_pwrstate = rf_off;
 
        /*  2010/08/09 MH We need to check if we need to turnon or off RF after detecting */
@@ -955,7 +937,7 @@ static u32 rtl8723bs_hal_init(struct adapter *padapter)
        /*  Configure SDIO TxRx Control to enable Rx DMA timer masking. */
        /*  2010.02.24. */
        /*  */
-       rtw_write32(padapter, SDIO_LOCAL_BASE|SDIO_REG_TX_CTRL, 0);
+       rtw_write32(padapter, SDIO_LOCAL_BASE | SDIO_REG_TX_CTRL, 0);
 
        _RfPowerSave(padapter);
 
@@ -979,7 +961,7 @@ static u32 rtl8723bs_hal_init(struct adapter *padapter)
        rtw_hal_set_hwreg(padapter, HW_VAR_NAV_UPPER, (u8 *)&NavUpper);
 
        /* ack for xmit mgmt frames. */
-       rtw_write32(padapter, REG_FWHW_TXQ_CTRL, rtw_read32(padapter, REG_FWHW_TXQ_CTRL)|BIT(12));
+       rtw_write32(padapter, REG_FWHW_TXQ_CTRL, rtw_read32(padapter, REG_FWHW_TXQ_CTRL) | BIT(12));
 
 /*     pHalData->PreRpwmVal = SdioLocalCmd52Read1Byte(padapter, SDIO_REG_HRPWM1) & 0x80; */
 
@@ -1009,14 +991,14 @@ static u32 rtl8723bs_hal_init(struct adapter *padapter)
                                msleep(50);
                        } while (jiffies_to_msecs(jiffies - start_time) <= 400);
 
-                       rtw_btcoex_IQKNotify(padapter, true);
+                       hal_btcoex_IQKNotify(padapter, true);
 
                        restore_iqk_rst = pwrpriv->bips_processing;
                        b2Ant = pHalData->EEPROMBluetoothAntNum == Ant_x2;
                        PHY_IQCalibrate_8723B(padapter, false, restore_iqk_rst, b2Ant, pHalData->ant_path);
                        pHalData->odmpriv.RFCalibrateInfo.bIQKInitialized = true;
 
-                       rtw_btcoex_IQKNotify(padapter, false);
+                       hal_btcoex_IQKNotify(padapter, false);
 
                        /* Inform WiFi FW that it is the finish of IQK */
                        h2cCmdBuf = 0;
@@ -1027,7 +1009,7 @@ static u32 rtl8723bs_hal_init(struct adapter *padapter)
        }
 
        /*  Init BT hw config. */
-       rtw_btcoex_HAL_Initialize(padapter, false);
+       hal_btcoex_InitHwConfig(padapter, false);
 
        RT_TRACE(_module_hci_hal_init_c_, _drv_info_, ("-%s\n", __func__));
 
@@ -1059,19 +1041,19 @@ static void CardDisableRTL8723BSdio(struct adapter *padapter)
                rtl8723b_FirmwareSelfReset(padapter);
 
        /*  Reset MCU 0x2[10]= 0. Suggested by Filen. 2011.01.26. by tynli. */
-       u1bTmp = rtw_read8(padapter, REG_SYS_FUNC_EN+1);
+       u1bTmp = rtw_read8(padapter, REG_SYS_FUNC_EN + 1);
        u1bTmp &= ~BIT(2);      /*  0x2[10], FEN_CPUEN */
-       rtw_write8(padapter, REG_SYS_FUNC_EN+1, u1bTmp);
+       rtw_write8(padapter, REG_SYS_FUNC_EN + 1, u1bTmp);
 
        /*  MCUFWDL 0x80[1:0]= 0 */
        /*  reset MCU ready status */
        rtw_write8(padapter, REG_MCUFWDL, 0);
 
        /*  Reset MCU IO Wrapper, added by Roger, 2011.08.30 */
-       u1bTmp = rtw_read8(padapter, REG_RSV_CTRL+1);
+       u1bTmp = rtw_read8(padapter, REG_RSV_CTRL + 1);
        u1bTmp &= ~BIT(0);
-       rtw_write8(padapter, REG_RSV_CTRL+1, u1bTmp);
-       u1bTmp = rtw_read8(padapter, REG_RSV_CTRL+1);
+       rtw_write8(padapter, REG_RSV_CTRL + 1, u1bTmp);
+       u1bTmp = rtw_read8(padapter, REG_RSV_CTRL + 1);
        u1bTmp |= BIT(0);
        rtw_write8(padapter, REG_RSV_CTRL+1, u1bTmp);
 
@@ -1081,7 +1063,7 @@ static void CardDisableRTL8723BSdio(struct adapter *padapter)
        ret = false;
        rtw_hal_set_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
        ret = HalPwrSeqCmdParsing(padapter, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK, rtl8723B_card_disable_flow);
-       if (ret == false) {
+       if (!ret) {
                DBG_8192C(KERN_ERR "%s: run CARD DISABLE flow fail!\n", __func__);
        }
 }
@@ -1091,9 +1073,9 @@ static u32 rtl8723bs_hal_deinit(struct adapter *padapter)
        struct dvobj_priv *psdpriv = padapter->dvobj;
        struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
 
-       if (padapter->hw_init_completed == true) {
-               if (adapter_to_pwrctl(padapter)->bips_processing == true) {
-                       if (padapter->netif_up == true) {
+       if (padapter->hw_init_completed) {
+               if (adapter_to_pwrctl(padapter)->bips_processing) {
+                       if (padapter->netif_up) {
                                int cnt = 0;
                                u8 val8 = 0;
 
@@ -1110,10 +1092,10 @@ static u32 rtl8723bs_hal_deinit(struct adapter *padapter)
                                /* H2C done, enter 32k */
                                if (val8 == 0) {
                                        /* ser rpwm to enter 32k */
-                                       val8 = rtw_read8(padapter, SDIO_LOCAL_BASE|SDIO_REG_HRPWM1);
+                                       val8 = rtw_read8(padapter, SDIO_LOCAL_BASE | SDIO_REG_HRPWM1);
                                        val8 += 0x80;
                                        val8 |= BIT(0);
-                                       rtw_write8(padapter, SDIO_LOCAL_BASE|SDIO_REG_HRPWM1, val8);
+                                       rtw_write8(padapter, SDIO_LOCAL_BASE | SDIO_REG_HRPWM1, val8);
                                        DBG_871X("%s: write rpwm =%02x\n", __func__, val8);
                                        adapter_to_pwrctl(padapter)->tog = (val8 + 0x80) & 0x80;
                                        cnt = val8 = 0;
@@ -1205,7 +1187,7 @@ static void rtl8723bs_interface_configure(struct adapter *padapter)
 
        switch (pHalData->OutEpNumber) {
        case 3:
-               pHalData->OutEpQueueSel = TX_SELE_HQ | TX_SELE_LQ|TX_SELE_NQ;
+               pHalData->OutEpQueueSel = TX_SELE_HQ | TX_SELE_LQ | TX_SELE_NQ;
                break;
        case 2:
                pHalData->OutEpQueueSel = TX_SELE_HQ | TX_SELE_NQ;
@@ -1292,7 +1274,7 @@ static void Hal_EfuseParseBoardType_8723BS(
        if (!AutoLoadFail) {
                pHalData->BoardType = (hwinfo[EEPROM_RF_BOARD_OPTION_8723B] & 0xE0) >> 5;
                if (pHalData->BoardType == 0xFF)
-                       pHalData->BoardType = (EEPROM_DEFAULT_BOARD_OPTION&0xE0)>>5;
+                       pHalData->BoardType = (EEPROM_DEFAULT_BOARD_OPTION & 0xE0) >> 5;
        } else
                pHalData->BoardType = 0;
        RT_TRACE(_module_hci_hal_init_c_, _drv_info_, ("Board Type: 0x%2x\n", pHalData->BoardType));
@@ -1387,7 +1369,7 @@ static s32 _ReadAdapterInfo8723BS(struct adapter *padapter)
        RT_TRACE(_module_hci_hal_init_c_, _drv_info_, ("+_ReadAdapterInfo8723BS\n"));
 
        /*  before access eFuse, make sure card enable has been called */
-       if (padapter->hw_init_completed == false)
+       if (!padapter->hw_init_completed)
                _InitPowerOn_8723BS(padapter);
 
 
@@ -1404,7 +1386,7 @@ static s32 _ReadAdapterInfo8723BS(struct adapter *padapter)
        _ReadPROMContent(padapter);
        _InitOtherVariable(padapter);
 
-       if (padapter->hw_init_completed == false) {
+       if (!padapter->hw_init_completed) {
                rtw_write8(padapter, 0x67, 0x00); /*  for BT, Switch Ant control to BT */
                CardDisableRTL8723BSdio(padapter);/* for the power consumption issue,  wifi ko module is loaded during booting, but wifi GUI is off */
        }
@@ -1429,7 +1411,6 @@ static void ReadAdapterInfo8723BS(struct adapter *padapter)
  */
 static void SetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val)
 {
-       struct hal_com_data *pHalData;
        u8 val8;
 
 #if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN)
@@ -1449,8 +1430,6 @@ static void SetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val)
 #endif
 #endif
 
-       pHalData = GET_HAL_DATA(padapter);
-
        switch (variable) {
        case HW_VAR_SET_RPWM:
                /*  rpwm value only use BIT0(clock bit) , BIT6(Ack bit), and BIT7(Toggle bit) */
@@ -1460,7 +1439,7 @@ static void SetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val)
                {
                        val8 = *val;
                        val8 &= 0xC1;
-                       rtw_write8(padapter, SDIO_LOCAL_BASE|SDIO_REG_HRPWM1, val8);
+                       rtw_write8(padapter, SDIO_LOCAL_BASE | SDIO_REG_HRPWM1, val8);
                }
                break;
        case HW_VAR_SET_REQ_FW_PS:
@@ -1496,9 +1475,9 @@ static void SetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val)
 
                        /*  2. RX DMA stop */
                        DBG_871X_LEVEL(_drv_always_, "Pause DMA\n");
-                       rtw_write32(padapter, REG_RXPKT_NUM, (rtw_read32(padapter, REG_RXPKT_NUM)|RW_RELEASE_EN));
+                       rtw_write32(padapter, REG_RXPKT_NUM, (rtw_read32(padapter, REG_RXPKT_NUM) | RW_RELEASE_EN));
                        do {
-                               if ((rtw_read32(padapter, REG_RXPKT_NUM)&RXDMA_IDLE)) {
+                               if ((rtw_read32(padapter, REG_RXPKT_NUM) & RXDMA_IDLE)) {
                                        DBG_871X_LEVEL(_drv_always_, "RX_DMA_IDLE is true\n");
                                        break;
                                } else {
@@ -1530,7 +1509,7 @@ static void SetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val)
                        sdio_local_read(padapter, SDIO_REG_HIMR, 4, (u8 *)&tmp);
                        DBG_871X("DisableInterruptButCpwm28723BSdio(): Read SDIO_REG_HIMR: 0x%08x\n", tmp);
 
-                       himr = cpu_to_le32(SDIO_HIMR_DISABLED)|SDIO_HIMR_CPWM2_MSK;
+                       himr = cpu_to_le32(SDIO_HIMR_DISABLED) | SDIO_HIMR_CPWM2_MSK;
                        sdio_local_write(padapter, SDIO_REG_HIMR, 4, (u8 *)&himr);
 
                        sdio_local_read(padapter, SDIO_REG_HIMR, 4, (u8 *)&tmp);
@@ -1545,7 +1524,7 @@ static void SetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val)
                                DBG_871X_LEVEL(_drv_always_, "Check EnableWoWlan CMD is ready\n");
                                mstatus = rtw_read8(padapter, REG_WOW_CTRL);
                                trycnt = 10;
-                               while (!(mstatus&BIT1) && trycnt > 1) {
+                               while (!(mstatus & BIT1) && trycnt > 1) {
                                        mstatus = rtw_read8(padapter, REG_WOW_CTRL);
                                        DBG_871X("Loop index: %d :0x%02x\n", trycnt, mstatus);
                                        trycnt--;
@@ -1558,7 +1537,7 @@ static void SetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val)
                        DBG_871X_LEVEL(_drv_always_, "WOWLAN_DISABLE\n");
 
                        psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(pmlmepriv));
-                       if (psta != NULL)
+                       if (psta)
                                rtl8723b_set_FwMediaStatusRpt_cmd(padapter, RT_MEDIA_DISCONNECT, psta->mac_id);
                        else
                                DBG_871X("psta is null\n");
@@ -1603,7 +1582,7 @@ static void SetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val)
                                DBG_871X_LEVEL(_drv_always_, "Check DisableWoWlan CMD is ready\n");
                                mstatus = rtw_read8(padapter, REG_WOW_CTRL);
                                trycnt = 50;
-                               while (mstatus&BIT1 && trycnt > 1) {
+                               while (mstatus & BIT1 && trycnt > 1) {
                                        mstatus = rtw_read8(padapter, REG_WOW_CTRL);
                                        DBG_871X_LEVEL(_drv_always_, "Loop index: %d :0x%02x\n", trycnt, mstatus);
                                        trycnt--;
@@ -1613,9 +1592,9 @@ static void SetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val)
                                if (mstatus & BIT1) {
                                        DBG_871X_LEVEL(_drv_always_, "Disable WOW mode fail!!\n");
                                        DBG_871X("Set 0x690 = 0x00\n");
-                                       rtw_write8(padapter, REG_WOW_CTRL, (rtw_read8(padapter, REG_WOW_CTRL)&0xf0));
+                                       rtw_write8(padapter, REG_WOW_CTRL, (rtw_read8(padapter, REG_WOW_CTRL) & 0xf0));
                                        DBG_871X_LEVEL(_drv_always_, "Release RXDMA\n");
-                                       rtw_write32(padapter, REG_RXPKT_NUM, (rtw_read32(padapter, REG_RXPKT_NUM)&(~RW_RELEASE_EN)));
+                                       rtw_write32(padapter, REG_RXPKT_NUM, (rtw_read32(padapter, REG_RXPKT_NUM) & (~RW_RELEASE_EN)));
                                }
 
                                /*  3.1 read fw iv */
@@ -1673,7 +1652,7 @@ static void SetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val)
                                (pwrctl->wowlan_wake_reason != Rx_DeAuth)
                        ) {
                                rtl8723b_set_FwJoinBssRpt_cmd(padapter, RT_MEDIA_CONNECT);
-                               if (psta != NULL)
+                               if (psta)
                                        rtl8723b_set_FwMediaStatusRpt_cmd(padapter, RT_MEDIA_CONNECT, psta->mac_id);
                        }
 #ifdef CONFIG_PNO_SUPPORT
@@ -1706,9 +1685,9 @@ static void SetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val)
                        /*  2. RX DMA stop */
                        DBG_871X_LEVEL(_drv_always_, "Pause DMA\n");
                        rtw_write32(padapter, REG_RXPKT_NUM,
-                               (rtw_read32(padapter, REG_RXPKT_NUM)|RW_RELEASE_EN));
+                               (rtw_read32(padapter, REG_RXPKT_NUM) | RW_RELEASE_EN));
                        do {
-                               if ((rtw_read32(padapter, REG_RXPKT_NUM)&RXDMA_IDLE)) {
+                               if ((rtw_read32(padapter, REG_RXPKT_NUM) & RXDMA_IDLE)) {
                                        DBG_871X_LEVEL(_drv_always_, "RX_DMA_IDLE is true\n");
                                        break;
                                } else {
@@ -1742,7 +1721,7 @@ static void SetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val)
                        sdio_local_read(padapter, SDIO_REG_HIMR, 4, (u8 *)&tmp);
                        DBG_871X("DisableInterruptButCpwm28723BSdio(): Read SDIO_REG_HIMR: 0x%08x\n", tmp);
 
-                       himr = cpu_to_le32(SDIO_HIMR_DISABLED)|SDIO_HIMR_CPWM2_MSK;
+                       himr = cpu_to_le32(SDIO_HIMR_DISABLED) | SDIO_HIMR_CPWM2_MSK;
                        sdio_local_write(padapter, SDIO_REG_HIMR, 4, (u8 *)&himr);
 
                        sdio_local_read(padapter, SDIO_REG_HIMR, 4, (u8 *)&tmp);
@@ -1808,7 +1787,7 @@ static void GetHwReg8723BS(struct adapter *padapter, u8 variable, u8 *val)
 {
        switch (variable) {
        case HW_VAR_CPWM:
-               *val = rtw_read8(padapter, SDIO_LOCAL_BASE|SDIO_REG_HCPWM1_8723B);
+               *val = rtw_read8(padapter, SDIO_LOCAL_BASE | SDIO_REG_HCPWM1_8723B);
                break;
 
        case HW_VAR_FW_PS_STATE:
index a60162046e5a1ec699367929880bedbf6a7239d3..301d327d062449dfd650a6198bcee77e3f69dd67 100644 (file)
@@ -214,7 +214,7 @@ static u32 sdio_read32(struct intf_hdl *intfhdl, u32 addr)
 
                ftaddr &= ~(u16)0x3;
                sd_read(intfhdl, ftaddr, 8, tmpbuf);
-               memcpy(&le_tmp, tmpbuf+shift, 4);
+               memcpy(&le_tmp, tmpbuf + shift, 4);
                val = le32_to_cpu(le_tmp);
 
                kfree(tmpbuf);
@@ -261,7 +261,7 @@ static s32 sdio_readN(struct intf_hdl *intfhdl, u32 addr, u32 cnt, u8 *buf)
 
                err = sd_read(intfhdl, ftaddr, n, tmpbuf);
                if (!err)
-                       memcpy(buf, tmpbuf+shift, cnt);
+                       memcpy(buf, tmpbuf + shift, cnt);
                kfree(tmpbuf);
        }
        return err;
@@ -366,7 +366,7 @@ static s32 sdio_writeN(struct intf_hdl *intfhdl, u32 addr, u32 cnt, u8 *buf)
                        kfree(tmpbuf);
                        return err;
                }
-               memcpy(tmpbuf+shift, buf, cnt);
+               memcpy(tmpbuf + shift, buf, cnt);
                err = sd_write(intfhdl, ftaddr, n, tmpbuf);
                kfree(tmpbuf);
        }
@@ -727,8 +727,8 @@ static s32 ReadInterrupt8723BSdio(struct adapter *adapter, u32 *phisr)
        hisr = 0;
        while (hisr_len != 0) {
                hisr_len--;
-               val8 = SdioLocalCmd52Read1Byte(adapter, SDIO_REG_HISR+hisr_len);
-               hisr |= (val8 << (8*hisr_len));
+               val8 = SdioLocalCmd52Read1Byte(adapter, SDIO_REG_HISR + hisr_len);
+               hisr |= (val8 << (8 * hisr_len));
        }
 
        *phisr = hisr;
@@ -795,38 +795,6 @@ void InitSysInterrupt8723BSdio(struct adapter *adapter)
                                                        0);
 }
 
-#ifdef CONFIG_WOWLAN
-/*  */
-/*     Description: */
-/*             Clear corresponding SDIO Host ISR interrupt service. */
-/*  */
-/*     Assumption: */
-/*             Using SDIO Local register ONLY for configuration. */
-/*  */
-/*     Created by Roger, 2011.02.11. */
-/*  */
-void clearinterrupt8723bsdio(struct adapter *adapter)
-{
-       struct hal_com_data *haldata;
-       u8 *clear;
-
-       if (adapter->bSurpriseRemoved)
-               return;
-
-       haldata = GET_HAL_DATA(adapter);
-       clear = rtw_zmalloc(4);
-
-       /*  Clear corresponding HISR Content if needed */
-       *(__le32 *)clear = cpu_to_le32(haldata->sdio_hisr & MASK_SDIO_HISR_CLEAR);
-       if (*(__le32 *)clear) {
-               /*  Perform write one clear operation */
-               sdio_local_write(padapter, SDIO_REG_HISR, 4, clear);
-       }
-
-       kfree(clear);
-}
-#endif
-
 /*  */
 /*     Description: */
 /*             Enalbe SDIO Host Interrupt Mask configuration on SDIO local domain. */
@@ -952,7 +920,7 @@ static struct recv_buf *sd_recv_rxfifo(struct adapter *adapter, u32 size)
                        recvbuf->pskb->dev = adapter->pnetdev;
 
                        tmpaddr = (SIZE_PTR)recvbuf->pskb->data;
-                       alignment = tmpaddr & (RECVBUFF_ALIGN_SZ-1);
+                       alignment = tmpaddr & (RECVBUFF_ALIGN_SZ - 1);
                        skb_reserve(recvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment));
                }
 
@@ -1045,21 +1013,19 @@ void sd_int_dpc(struct adapter *adapter)
                }
        }
 
-       if (hal->sdio_hisr & SDIO_HISR_TXBCNOK) {
+       if (hal->sdio_hisr & SDIO_HISR_TXBCNOK)
                DBG_8192C("%s: SDIO_HISR_TXBCNOK\n", __func__);
-       }
 
-       if (hal->sdio_hisr & SDIO_HISR_TXBCNERR) {
+       if (hal->sdio_hisr & SDIO_HISR_TXBCNERR)
                DBG_8192C("%s: SDIO_HISR_TXBCNERR\n", __func__);
-       }
 #ifndef CONFIG_C2H_PACKET_EN
        if (hal->sdio_hisr & SDIO_HISR_C2HCMD) {
                struct c2h_evt_hdr_88xx *c2h_evt;
 
                DBG_8192C("%s: C2H Command\n", __func__);
                c2h_evt = rtw_zmalloc(16);
-               if (c2h_evt != NULL) {
-                       if (rtw_hal_c2h_evt_read(adapter, (u8 *)c2h_evt) == _SUCCESS) {
+               if (c2h_evt) {
+                       if (c2h_evt_read_88xx(adapter, (u8 *)c2h_evt) == _SUCCESS) {
                                if (c2h_id_filter_ccx_8723b((u8 *)c2h_evt)) {
                                        /* Handle CCX report here */
                                        rtw_hal_c2h_handler(adapter, (u8 *)c2h_evt);
@@ -1077,13 +1043,12 @@ void sd_int_dpc(struct adapter *adapter)
        }
 #endif
 
-       if (hal->sdio_hisr & SDIO_HISR_RXFOVW) {
+       if (hal->sdio_hisr & SDIO_HISR_RXFOVW)
                DBG_8192C("%s: Rx Overflow\n", __func__);
-       }
 
-       if (hal->sdio_hisr & SDIO_HISR_RXERR) {
+       if (hal->sdio_hisr & SDIO_HISR_RXERR)
                DBG_8192C("%s: Rx Error\n", __func__);
-       }
+
 
        if (hal->sdio_hisr & SDIO_HISR_RX_REQUEST) {
                struct recv_buf *recvbuf;
@@ -1143,9 +1108,8 @@ void sd_int_hdl(struct adapter *adapter)
 
                /*  clear HISR */
                v32 = hal->sdio_hisr & MASK_SDIO_HISR_CLEAR;
-               if (v32) {
+               if (v32)
                        SdioLocalCmd52Write4Byte(adapter, SDIO_REG_HISR, v32);
-               }
 
                sd_int_dpc(adapter);
        } else {
@@ -1194,12 +1158,11 @@ u8 HalQueryTxBufferStatus8723BSdio(struct adapter *adapter)
 /*     Description: */
 /*             Query SDIO Local register to get the current number of TX OQT Free Space. */
 /*  */
-u8 HalQueryTxOQTBufferStatus8723BSdio(struct adapter *adapter)
+void HalQueryTxOQTBufferStatus8723BSdio(struct adapter *adapter)
 {
        struct hal_com_data *haldata = GET_HAL_DATA(adapter);
 
        haldata->SdioTxOQTFreeSpace = SdioLocalCmd52Read1Byte(adapter, SDIO_REG_OQT_FREE_PG);
-       return true;
 }
 
 #if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN)
@@ -1207,7 +1170,6 @@ u8 RecvOnePkt(struct adapter *adapter, u32 size)
 {
        struct recv_buf *recvbuf;
        struct dvobj_priv *sddev;
-       struct sdio_data *psdio;
        struct sdio_func *func;
 
        u8 res = false;
index 0fd84c93e72ba0904c156cce93a0abd5cb0ddedd..96346ce064aa04c6baa1e4032f2f87c5a6f5b450 100644 (file)
@@ -673,7 +673,7 @@ int rtw_config_gpio(struct net_device *netdev, int gpio_num, bool isOutput);
 #endif
 
 #ifdef CONFIG_WOWLAN
-int rtw_suspend_wow(struct adapter *padapter);
+void rtw_suspend_wow(struct adapter *padapter);
 int rtw_resume_process_wow(struct adapter *padapter);
 #endif
 
index 4066b0a1450cd02009f67bab38840dd7335a2a62..6f7514be998f18fdcaba7b5b8b54ecfbf28e6a48 100644 (file)
@@ -23,7 +23,7 @@ void DBG_BT_INFO(u8 *dbgmsg);
 
 void hal_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist);
 u8 hal_btcoex_IsBtExist(struct adapter *padapter);
-u8 hal_btcoex_IsBtDisabled(struct adapter *);
+bool hal_btcoex_IsBtDisabled(struct adapter *);
 void hal_btcoex_SetChipType(struct adapter *padapter, u8 chipType);
 void hal_btcoex_SetPgAntNum(struct adapter *padapter, u8 antNum);
 void hal_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath);
@@ -43,7 +43,7 @@ void hal_btcoex_BtInfoNotify(struct adapter *padapter, u8 length, u8 *tmpBuf);
 void hal_btcoex_SuspendNotify(struct adapter *padapter, u8 state);
 void hal_btcoex_HaltNotify(struct adapter *padapter);
 
-void hal_btcoex_Hanlder(struct adapter *padapter);
+void hal_btcoex_Handler(struct adapter *padapter);
 
 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *padapter);
 void hal_btcoex_SetManualControl(struct adapter *padapter, u8 bmanual);
index d1c5b31930437fa65580b2e6a262dca335d20220..f5c3ce5da70c1e1ee5fbb5a2eadad86dd47c0a68 100644 (file)
@@ -232,7 +232,6 @@ void rtw_init_hal_com_default_value(struct adapter * Adapter);
 void c2h_evt_clear(struct adapter *adapter);
 s32 c2h_evt_read_88xx(struct adapter *adapter, u8 *buf);
 
-u8  rtw_hal_networktype_to_raid(struct adapter *adapter, struct sta_info *psta);
 u8 rtw_get_mgntframe_raid(struct adapter *adapter, unsigned char network_type);
 void rtw_hal_update_sta_rate_mask(struct adapter *padapter, struct sta_info *psta);
 
index 19ceb4aa753ea6a2c51c2ca69411b7044bef60c2..3a0c3d079d507c9ba22a7f2480013dde0f00f98e 100644 (file)
@@ -388,7 +388,6 @@ void rtw_hal_notch_filter(struct adapter * adapter, bool enable);
 void rtw_hal_reset_security_engine(struct adapter * adapter);
 
 bool rtw_hal_c2h_valid(struct adapter *adapter, u8 *buf);
-s32 rtw_hal_c2h_evt_read(struct adapter *adapter, u8 *buf);
 s32 rtw_hal_c2h_handler(struct adapter *adapter, u8 *c2h_evt);
 c2h_id_filter rtw_hal_c2h_id_filter_ccx(struct adapter *adapter);
 
index 74c028fbe8f7d29202881876fb41812cf32fd158..2110552b8e594f8f6c6a07ee5162589235bfd8b8 100644 (file)
@@ -1138,7 +1138,7 @@ int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len);
 int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x);
 int rtw_parse_wpa2_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x);
 
-int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len);
+void rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len);
 
 u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen);
 u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen);
index 0ea91a111da389cf92fe8a82ea75609b1b76243f..40313d17a242d7e43fdc3264f778f13ef3791bcc 100644 (file)
@@ -46,7 +46,7 @@ void devobj_deinit(struct dvobj_priv *pdvobj);
 
 u8 rtw_init_drv_sw(struct adapter *padapter);
 u8 rtw_free_drv_sw(struct adapter *padapter);
-u8 rtw_reset_drv_sw(struct adapter *padapter);
+void rtw_reset_drv_sw(struct adapter *padapter);
 void rtw_dev_unload(struct adapter *padapter);
 
 u32 rtw_start_drv_threads(struct adapter *padapter);
index 76d61958504689daca57a3f422e3c33163421ae9..d2616af95ffa8568353d72c160724b2fad8dd3b4 100644 (file)
@@ -178,8 +178,6 @@ extern int rtw_retrive_from_file(char *path, u8 *buf, u32 sz);
 extern void rtw_free_netdev(struct net_device * netdev);
 
 
-extern u64 rtw_modular64(u64 x, u64 y);
-
 /* Macros for handling unaligned memory accesses */
 
 #define RTW_GET_BE16(a) ((u16) (((a)[0] << 8) | (a)[1]))
index 6fea0e9482710cf417b5aa00833168ad79109c37..1056f615d0f9b2561768bf76c746f5e1cd1d7287 100644 (file)
@@ -22,14 +22,14 @@ int rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter);
 void rtw_free_recv_priv (struct recv_priv *precvpriv);
 
 
-int rtw_os_recv_resource_alloc(struct adapter *padapter, union recv_frame *precvframe);
+void rtw_os_recv_resource_alloc(struct adapter *padapter, union recv_frame *precvframe);
 void rtw_os_recv_resource_free(struct recv_priv *precvpriv);
 
 
 void rtw_os_free_recvframe(union recv_frame *precvframe);
 
 
-int rtw_os_recvbuf_resource_free(struct adapter *padapter, struct recv_buf *precvbuf);
+void rtw_os_recvbuf_resource_free(struct adapter *padapter, struct recv_buf *precvbuf);
 
 _pkt *rtw_os_alloc_msdu_pkt(union recv_frame *prframe, u16 nSubframe_Length, u8 *pdata);
 void rtw_os_recv_indicate_pkt(struct adapter *padapter, _pkt *pkt, struct rx_pkt_attrib *pattrib);
index fd56c9db16a96fc0eddeeadf7137992e876d82a3..4a1ed9eff83a66b4c48e2244140ee7cc91c3a17e 100644 (file)
@@ -19,7 +19,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf,  int len);
 void rtw_ap_restore_network(struct adapter *padapter);
 void rtw_set_macaddr_acl(struct adapter *padapter, int mode);
 int rtw_acl_add_sta(struct adapter *padapter, u8 *addr);
-int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr);
+void rtw_acl_remove_sta(struct adapter *padapter, u8 *addr);
 
 u8 rtw_ap_set_pairwise_key(struct adapter *padapter, struct sta_info *psta);
 int rtw_ap_set_group_key(struct adapter *padapter, u8 *key, u8 alg, int keyid);
@@ -31,7 +31,7 @@ u8 bss_cap_update_on_sta_leave(struct adapter *padapter, struct sta_info *psta);
 void sta_info_update(struct adapter *padapter, struct sta_info *psta);
 void ap_sta_info_defer_update(struct adapter *padapter, struct sta_info *psta);
 u8 ap_free_sta(struct adapter *padapter, struct sta_info *psta, bool active, u16 reason);
-int rtw_sta_flush(struct adapter *padapter);
+void rtw_sta_flush(struct adapter *padapter);
 void start_ap_mode(struct adapter *padapter);
 void stop_ap_mode(struct adapter *padapter);
 
index 53f49c6b2fcd8098fa5696a8e1605e95a543c8fb..19764c80b8ba8bf4b4d3ae32e4d56d34c0db3a7d 100644 (file)
 #define        PACKET_ARP                              2
 #define        PACKET_EAPOL                    3
 
-void rtw_btcoex_Initialize(struct adapter *);
-void rtw_btcoex_PowerOnSetting(struct adapter *padapter);
-void rtw_btcoex_HAL_Initialize(struct adapter *padapter, u8 bWifiOnly);
-void rtw_btcoex_IpsNotify(struct adapter *, u8 type);
-void rtw_btcoex_LpsNotify(struct adapter *, u8 type);
-void rtw_btcoex_ScanNotify(struct adapter *, u8 type);
-void rtw_btcoex_ConnectNotify(struct adapter *, u8 action);
 void rtw_btcoex_MediaStatusNotify(struct adapter *, u8 mediaStatus);
-void rtw_btcoex_SpecialPacketNotify(struct adapter *, u8 pktType);
-void rtw_btcoex_IQKNotify(struct adapter *padapter, u8 state);
-void rtw_btcoex_BtInfoNotify(struct adapter *, u8 length, u8 *tmpBuf);
-void rtw_btcoex_SuspendNotify(struct adapter *, u8 state);
 void rtw_btcoex_HaltNotify(struct adapter *);
-u8 rtw_btcoex_IsBtDisabled(struct adapter *);
-void rtw_btcoex_Handler(struct adapter *);
-s32 rtw_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *);
-void rtw_btcoex_SetManualControl(struct adapter *, u8 bmanual);
-u8 rtw_btcoex_IsBtControlLps(struct adapter *);
-u8 rtw_btcoex_IsLpsOn(struct adapter *);
-u8 rtw_btcoex_RpwmVal(struct adapter *);
-u8 rtw_btcoex_LpsVal(struct adapter *);
-void rtw_btcoex_SetBTCoexist(struct adapter *, u8 bBtExist);
-void rtw_btcoex_SetChipType(struct adapter *, u8 chipType);
-void rtw_btcoex_SetPGAntNum(struct adapter *, u8 antNum);
-void rtw_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath);
-u32 rtw_btcoex_GetRaMask(struct adapter *);
-void rtw_btcoex_RecordPwrMode(struct adapter *, u8 *pCmdBuf, u8 cmdLen);
-void rtw_btcoex_DisplayBtCoexInfo(struct adapter *, u8 *pbuf, u32 bufsize);
-void rtw_btcoex_SetDBG(struct adapter *, u32 *pDbgModule);
-u32 rtw_btcoex_GetDBG(struct adapter *, u8 *pStrBuf, u32 bufSize);
 
 /*  ================================================== */
 /*  Below Functions are called by BT-Coex */
index 2693b554f4146c83814c677f443c35fb5b5932c8..d3c07d1c36e923bc97ae1a1ff411d3efc8380c82 100644 (file)
@@ -589,7 +589,6 @@ extern void rtw_scan_timeout_handler(struct timer_list *t);
 extern void rtw_dynamic_check_timer_handler(struct adapter *adapter);
 bool rtw_is_scan_deny(struct adapter *adapter);
 void rtw_clear_scan_deny(struct adapter *adapter);
-void rtw_set_scan_deny_timer_hdl(struct adapter *adapter);
 void rtw_set_scan_deny(struct adapter *adapter, u32 ms);
 
 void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv);
@@ -607,8 +606,6 @@ extern void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv, struct wlan_ne
 
 extern struct wlan_network* _rtw_find_network(struct __queue *scanned_queue, u8 *addr);
 
-extern void _rtw_free_network_queue(struct adapter *padapter, u8 isfreeall);
-
 extern sint rtw_if_up(struct adapter *padapter);
 
 sint rtw_linked_check(struct adapter *padapter);
index f6eabad4bbe036fcaa8979f4f10f647302312964..733bb9425448ff6efc21497ed01b824b4d54cc2d 100644 (file)
@@ -544,7 +544,7 @@ extern struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv);
 
 /* void fill_fwpriv(struct adapter *padapter, struct fw_priv *pfwpriv); */
 
-unsigned char networktype_to_raid_ex(struct adapter *adapter, struct sta_info *psta);
+u8 networktype_to_raid_ex(struct adapter *adapter, struct sta_info *psta);
 
 void get_rate_set(struct adapter *padapter, unsigned char *pbssrate, int *bssrate_len);
 void set_mcs_rate_by_mask(u8 *mcs_set, u32 mask);
index 0f117ff1fbbe16b9a6f82a86c3be8bbdb72ff1b2..6b0446be6d19c902bb8e33d0fd2a94c23b2bc3a1 100644 (file)
@@ -33,7 +33,7 @@ extern void InitSysInterrupt8723BSdio(struct adapter *padapter);
 extern void EnableInterrupt8723BSdio(struct adapter *padapter);
 extern void DisableInterrupt8723BSdio(struct adapter *padapter);
 extern u8 HalQueryTxBufferStatus8723BSdio(struct adapter *padapter);
-extern u8 HalQueryTxOQTBufferStatus8723BSdio(struct adapter *padapter);
+extern void HalQueryTxOQTBufferStatus8723BSdio(struct adapter *padapter);
 #if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN)
 extern void ClearInterrupt8723BSdio(struct adapter *padapter);
 #endif /* CONFIG_WOWLAN */
index db553f2e4c0b835386330ec9773c219085b82c2f..9bc6856326518aaa3cac2f514166145a7ea1213e 100644 (file)
@@ -1650,7 +1650,7 @@ static int cfg80211_rtw_scan(struct wiphy *wiphy
        }
 
 check_need_indicate_scan_done:
-       if (true == need_indicate_scan_done)
+       if (need_indicate_scan_done)
        {
                rtw_cfg80211_surveydone_event_callback(padapter);
                rtw_cfg80211_indicate_scan_done(padapter, false);
@@ -2439,23 +2439,7 @@ void rtw_cfg80211_indicate_sta_disassoc(struct adapter *padapter, unsigned char
        cfg80211_del_sta(ndev, da, GFP_ATOMIC);
 }
 
-static int rtw_cfg80211_monitor_if_open(struct net_device *ndev)
-{
-       int ret = 0;
-
-       DBG_8192C("%s\n", __func__);
-
-       return ret;
-}
-
-static int rtw_cfg80211_monitor_if_close(struct net_device *ndev)
-{
-       int ret = 0;
-
-       DBG_8192C("%s\n", __func__);
 
-       return ret;
-}
 
 static netdev_tx_t rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_device *ndev)
 {
@@ -2604,20 +2588,10 @@ fail:
 
 }
 
-static int rtw_cfg80211_monitor_if_set_mac_address(struct net_device *ndev, void *addr)
-{
-       int ret = 0;
 
-       DBG_8192C("%s\n", __func__);
-
-       return ret;
-}
 
 static const struct net_device_ops rtw_cfg80211_monitor_if_ops = {
-       .ndo_open = rtw_cfg80211_monitor_if_open,
-       .ndo_stop = rtw_cfg80211_monitor_if_close,
-       .ndo_start_xmit = rtw_cfg80211_monitor_if_xmit_entry,
-       .ndo_set_mac_address = rtw_cfg80211_monitor_if_set_mac_address,
+       .ndo_start_xmit = rtw_cfg80211_monitor_if_xmit_entry,
 };
 
 static int rtw_cfg80211_add_monitor_if (struct adapter *padapter, char *name, struct net_device **ndev)
@@ -2896,9 +2870,9 @@ static int cfg80211_rtw_del_station(struct wiphy *wiphy, struct net_device *ndev
 
                flush_all_cam_entry(padapter);  /* clear CAM */
 
-               ret = rtw_sta_flush(padapter);
+               rtw_sta_flush(padapter);
 
-               return ret;
+               return 0;
        }
 
 
index e3d35695287578d93390a8e082b6121cdf6a9d09..99e6b1028f71409d380fbbb545ae5fc37d9be25f 100644 (file)
@@ -10,6 +10,7 @@
 #include <drv_types.h>
 #include <rtw_debug.h>
 #include <rtw_mp.h>
+#include <hal_btcoex.h>
 #include <linux/jiffies.h>
 #include <linux/kernel.h>
 
@@ -55,7 +56,7 @@ void rtw_indicate_wx_assoc_event(struct adapter *padapter)
        struct  mlme_priv *pmlmepriv = &padapter->mlmepriv;
        struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
        struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
-       struct wlan_bssid_ex            *pnetwork = (struct wlan_bssid_ex*)(&(pmlmeinfo->network));
+       struct wlan_bssid_ex            *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
 
        memset(&wrqu, 0, sizeof(union iwreq_data));
 
@@ -235,8 +236,7 @@ static char *translate_scan(struct adapter *padapter,
                u8 wpa_ie[255], rsn_ie[255];
                u16 wpa_len = 0, rsn_len = 0;
                u8 *p;
-               sint out_len = 0;
-               out_len =rtw_get_sec_ie(pnetwork->network.IEs , pnetwork->network.IELength, rsn_ie,&rsn_len, wpa_ie,&wpa_len);
+               rtw_get_sec_ie(pnetwork->network.IEs, pnetwork->network.IELength, rsn_ie, &rsn_len, wpa_ie, &wpa_len);
                RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_get_scan: ssid =%s\n", pnetwork->network.Ssid.Ssid));
                RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_get_scan: wpa_len =%d rsn_len =%d\n", wpa_len, rsn_len));
 
@@ -478,14 +478,12 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
                if (wep_key_len > 0) {
                        wep_key_len = wep_key_len <= 5 ? 5 : 13;
                        wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, KeyMaterial);
-                       pwep = rtw_malloc(wep_total_len);
+                       pwep = kzalloc(wep_total_len, GFP_KERNEL);
                        if (pwep == NULL) {
                                RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, (" wpa_set_encryption: pwep allocate fail !!!\n"));
                                goto exit;
                        }
 
-                       memset(pwep, 0, wep_total_len);
-
                        pwep->KeyLength = wep_key_len;
                        pwep->Length = wep_total_len;
 
@@ -617,7 +615,7 @@ exit:
 
 static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ielen)
 {
-       u8 *buf = NULL, *pos = NULL;
+       u8 *buf = NULL;
        int group_cipher = 0, pairwise_cipher = 0;
        int ret = 0;
        u8 null_addr[]= {0, 0, 0, 0, 0, 0};
@@ -647,7 +645,6 @@ static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ie
                                DBG_871X("0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", buf[i], buf[i+1], buf[i+2], buf[i+3], buf[i+4], buf[i+5], buf[i+6], buf[i+7]);
                }
 
-               pos = buf;
                if (ielen < RSN_HEADER_LEN) {
                        RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, ("Ie len too short %d\n", ielen));
                        ret  = -1;
@@ -946,7 +943,7 @@ static int rtw_wx_set_pmkid(struct net_device *dev,
        u8          j, blInserted = false;
        int         intReturn = false;
        struct security_priv *psecuritypriv = &padapter->securitypriv;
-        struct iw_pmksa*  pPMK = (struct iw_pmksa*)extra;
+        struct iw_pmksa*  pPMK = (struct iw_pmksa *)extra;
         u8     strZeroMacAddress[ ETH_ALEN ] = { 0x00 };
         u8     strIssueBssid[ ETH_ALEN ] = { 0x00 };
 
@@ -1183,7 +1180,7 @@ static int rtw_wx_set_wap(struct net_device *dev,
                                spin_unlock_bh(&queue->lock);
                                goto exit;
                        }
-                               break;
+                       break;
                }
 
        }
@@ -1671,45 +1668,45 @@ static int rtw_wx_set_rate(struct net_device *dev,
        target_rate = target_rate/100000;
 
        switch (target_rate) {
-               case 10:
-                       ratevalue = 0;
-                       break;
-               case 20:
-                       ratevalue = 1;
-                       break;
-               case 55:
-                       ratevalue = 2;
-                       break;
-               case 60:
-                       ratevalue = 3;
-                       break;
-               case 90:
-                       ratevalue = 4;
-                       break;
-               case 110:
-                       ratevalue = 5;
-                       break;
-               case 120:
-                       ratevalue = 6;
-                       break;
-               case 180:
-                       ratevalue = 7;
-                       break;
-               case 240:
-                       ratevalue = 8;
-                       break;
-               case 360:
-                       ratevalue = 9;
-                       break;
-               case 480:
-                       ratevalue = 10;
-                       break;
-               case 540:
-                       ratevalue = 11;
-                       break;
-               default:
-                       ratevalue = 11;
-                       break;
+       case 10:
+               ratevalue = 0;
+               break;
+       case 20:
+               ratevalue = 1;
+               break;
+       case 55:
+               ratevalue = 2;
+               break;
+       case 60:
+               ratevalue = 3;
+               break;
+       case 90:
+               ratevalue = 4;
+               break;
+       case 110:
+               ratevalue = 5;
+               break;
+       case 120:
+               ratevalue = 6;
+               break;
+       case 180:
+               ratevalue = 7;
+               break;
+       case 240:
+               ratevalue = 8;
+               break;
+       case 360:
+               ratevalue = 9;
+               break;
+       case 480:
+               ratevalue = 10;
+               break;
+       case 540:
+               ratevalue = 11;
+               break;
+       default:
+               ratevalue = 11;
+               break;
        }
 
 set_rate:
@@ -2054,7 +2051,7 @@ static int rtw_wx_set_auth(struct net_device *dev,
                           union iwreq_data *wrqu, char *extra)
 {
        struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
-       struct iw_param *param = (struct iw_param*)&(wrqu->param);
+       struct iw_param *param = (struct iw_param *)&(wrqu->param);
        int ret = 0;
 
        switch (param->flags & IW_AUTH_INDEX) {
@@ -2144,12 +2141,10 @@ static int rtw_wx_set_enc_ext(struct net_device *dev,
        int ret = 0;
 
        param_len = sizeof(struct ieee_param) + pext->key_len;
-       param = rtw_malloc(param_len);
+       param = kzalloc(param_len, GFP_KERNEL);
        if (param == NULL)
                return -1;
 
-       memset(param, 0, param_len);
-
        param->cmd = IEEE_CMD_SET_ENCRYPTION;
        memset(param->sta_addr, 0xff, ETH_ALEN);
 
@@ -2267,22 +2262,22 @@ static int rtw_wx_read32(struct net_device *dev,
        sscanf(ptmp, "%d,%x", &bytes, &addr);
 
        switch (bytes) {
-               case 1:
-                       data32 = rtw_read8(padapter, addr);
-                       sprintf(extra, "0x%02X", data32);
-                       break;
-               case 2:
-                       data32 = rtw_read16(padapter, addr);
-                       sprintf(extra, "0x%04X", data32);
-                       break;
-               case 4:
-                       data32 = rtw_read32(padapter, addr);
-                       sprintf(extra, "0x%08X", data32);
-                       break;
-               default:
-                       DBG_871X(KERN_INFO "%s: usage> read [bytes],[address(hex)]\n", __func__);
-                       ret = -EINVAL;
-                       goto exit;
+       case 1:
+               data32 = rtw_read8(padapter, addr);
+               sprintf(extra, "0x%02X", data32);
+               break;
+       case 2:
+               data32 = rtw_read16(padapter, addr);
+               sprintf(extra, "0x%04X", data32);
+               break;
+       case 4:
+               data32 = rtw_read32(padapter, addr);
+               sprintf(extra, "0x%08X", data32);
+               break;
+       default:
+               DBG_871X(KERN_INFO "%s: usage> read [bytes],[address(hex)]\n", __func__);
+               ret = -EINVAL;
+               goto exit;
        }
        DBG_871X(KERN_INFO "%s: addr = 0x%08X data =%s\n", __func__, addr, extra);
 
@@ -2309,21 +2304,21 @@ static int rtw_wx_write32(struct net_device *dev,
        sscanf(extra, "%d,%x,%x", &bytes, &addr, &data32);
 
        switch (bytes) {
-               case 1:
-                       rtw_write8(padapter, addr, (u8)data32);
-                       DBG_871X(KERN_INFO "%s: addr = 0x%08X data = 0x%02X\n", __func__, addr, (u8)data32);
-                       break;
-               case 2:
-                       rtw_write16(padapter, addr, (u16)data32);
-                       DBG_871X(KERN_INFO "%s: addr = 0x%08X data = 0x%04X\n", __func__, addr, (u16)data32);
-                       break;
-               case 4:
-                       rtw_write32(padapter, addr, data32);
-                       DBG_871X(KERN_INFO "%s: addr = 0x%08X data = 0x%08X\n", __func__, addr, data32);
-                       break;
-               default:
-                       DBG_871X(KERN_INFO "%s: usage> write [bytes],[address(hex)],[data(hex)]\n", __func__);
-                       return -EINVAL;
+       case 1:
+               rtw_write8(padapter, addr, (u8)data32);
+               DBG_871X(KERN_INFO "%s: addr = 0x%08X data = 0x%02X\n", __func__, addr, (u8)data32);
+               break;
+       case 2:
+               rtw_write16(padapter, addr, (u16)data32);
+               DBG_871X(KERN_INFO "%s: addr = 0x%08X data = 0x%04X\n", __func__, addr, (u16)data32);
+               break;
+       case 4:
+               rtw_write32(padapter, addr, data32);
+               DBG_871X(KERN_INFO "%s: addr = 0x%08X data = 0x%08X\n", __func__, addr, data32);
+               break;
+       default:
+               DBG_871X(KERN_INFO "%s: usage> write [bytes],[address(hex)],[data(hex)]\n", __func__);
+               return -EINVAL;
        }
 
        return 0;
@@ -2337,8 +2332,8 @@ static int rtw_wx_read_rf(struct net_device *dev,
        u32 path, addr, data32;
 
 
-       path = *(u32*)extra;
-       addr = *((u32*)extra + 1);
+       path = *(u32 *)extra;
+       addr = *((u32 *)extra + 1);
        data32 = rtw_hal_read_rfreg(padapter, path, addr, 0xFFFFF);
        /*
         * IMPORTANT!!
@@ -2358,9 +2353,9 @@ static int rtw_wx_write_rf(struct net_device *dev,
        u32 path, addr, data32;
 
 
-       path = *(u32*)extra;
-       addr = *((u32*)extra + 1);
-       data32 = *((u32*)extra + 2);
+       path = *(u32 *)extra;
+       addr = *((u32 *)extra + 1);
+       data32 = *((u32 *)extra + 2);
 /*     DBG_871X("%s: path =%d addr = 0x%02x data = 0x%05x\n", __func__, path, addr, data32); */
        rtw_hal_write_rfreg(padapter, path, addr, 0xFFFFF, data32);
 
@@ -2584,7 +2579,7 @@ static int rtw_wps_start(struct net_device *dev,
                goto exit;
        }
 
-       uintRet = copy_from_user((void*)&u32wps_start, pdata->pointer, 4);
+       uintRet = copy_from_user((void *)&u32wps_start, pdata->pointer, 4);
        if (u32wps_start == 0)
                u32wps_start = *extra;
 
@@ -2601,9 +2596,7 @@ static int rtw_p2p_set(struct net_device *dev,
                                union iwreq_data *wrqu, char *extra)
 {
 
-       int ret = 0;
-
-       return ret;
+       return 0;
 
 }
 
@@ -2612,9 +2605,7 @@ static int rtw_p2p_get(struct net_device *dev,
                                union iwreq_data *wrqu, char *extra)
 {
 
-       int ret = 0;
-
-       return ret;
+       return 0;
 
 }
 
@@ -2623,9 +2614,7 @@ static int rtw_p2p_get2(struct net_device *dev,
                                                union iwreq_data *wrqu, char *extra)
 {
 
-       int ret = 0;
-
-       return ret;
+       return 0;
 
 }
 
@@ -2682,7 +2671,6 @@ static int rtw_dbg_port(struct net_device *dev,
                                struct iw_request_info *info,
                                union iwreq_data *wrqu, char *extra)
 {
-       int ret = 0;
        u8 major_cmd, minor_cmd;
        u16 arg;
        u32 extra_arg, *pdata, val32;
@@ -2695,7 +2683,7 @@ static int rtw_dbg_port(struct net_device *dev,
        struct sta_priv *pstapriv = &padapter->stapriv;
 
 
-       pdata = (u32*)&wrqu->data;
+       pdata = (u32 *)&wrqu->data;
 
        val32 = *pdata;
        arg = (u16)(val32&0x0000ffff);
@@ -3097,7 +3085,7 @@ static int rtw_dbg_port(struct net_device *dev,
 
                                                        DBG_871X("enable driver ctrl ampdu density = %d\n", extra_arg);
 
-                                                       if ((extra_arg & 0x07) > 0x07)
+                                                       if (extra_arg > 0x07)
                                                                padapter->driver_ampdu_spacing = 0xFF;
                                                        else
                                                                padapter->driver_ampdu_spacing = extra_arg;
@@ -3263,7 +3251,7 @@ static int rtw_dbg_port(struct net_device *dev,
        }
 
 
-       return ret;
+       return 0;
 
 }
 
@@ -3366,23 +3354,23 @@ static int wpa_mlme(struct net_device *dev, u32 command, u32 reason)
        struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
 
        switch (command) {
-               case IEEE_MLME_STA_DEAUTH:
+       case IEEE_MLME_STA_DEAUTH:
 
-                       if (!rtw_set_802_11_disassociate(padapter))
-                               ret = -1;
+               if (!rtw_set_802_11_disassociate(padapter))
+                       ret = -1;
 
-                       break;
+               break;
 
-               case IEEE_MLME_STA_DISASSOC:
+       case IEEE_MLME_STA_DISASSOC:
 
-                       if (!rtw_set_802_11_disassociate(padapter))
-                               ret = -1;
+               if (!rtw_set_802_11_disassociate(padapter))
+                       ret = -1;
 
-                       break;
+               break;
 
-               default:
-                       ret = -EOPNOTSUPP;
-                       break;
+       default:
+               ret = -EOPNOTSUPP;
+               break;
        }
 
        return ret;
@@ -3421,7 +3409,7 @@ static int wpa_supplicant_ioctl(struct net_device *dev, struct iw_point *p)
 
        case IEEE_CMD_SET_WPA_IE:
                /* ret = wpa_set_wpa_ie(dev, param, p->length); */
-               ret =  rtw_set_wpa_ie((struct adapter *)rtw_netdev_priv(dev), (char*)param->u.wpa_ie.data, (u16)param->u.wpa_ie.len);
+               ret =  rtw_set_wpa_ie((struct adapter *)rtw_netdev_priv(dev), (char *)param->u.wpa_ie.data, (u16)param->u.wpa_ie.len);
                break;
 
        case IEEE_CMD_SET_ENCRYPTION:
@@ -3522,14 +3510,12 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
                if (wep_key_len > 0) {
                        wep_key_len = wep_key_len <= 5 ? 5 : 13;
                        wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, KeyMaterial);
-                       pwep = rtw_malloc(wep_total_len);
+                       pwep = kzalloc(wep_total_len, GFP_KERNEL);
                        if (pwep == NULL) {
                                DBG_871X(" r871x_set_encryption: pwep allocate fail !!!\n");
                                goto exit;
                        }
 
-                       memset(pwep, 0, wep_total_len);
-
                        pwep->KeyLength = wep_key_len;
                        pwep->Length = wep_total_len;
 
@@ -3754,7 +3740,7 @@ static int rtw_set_beacon(struct net_device *dev, struct ieee_param *param, int
 
 }
 
-static int rtw_hostapd_sta_flush(struct net_device *dev)
+static void rtw_hostapd_sta_flush(struct net_device *dev)
 {
        /* _irqL irqL; */
        /* struct list_head     *phead, *plist; */
@@ -3766,8 +3752,7 @@ static int rtw_hostapd_sta_flush(struct net_device *dev)
 
        flush_all_cam_entry(padapter);  /* clear CAM */
 
-       return rtw_sta_flush(padapter);
-
+       rtw_sta_flush(padapter);
 }
 
 static int rtw_add_sta(struct net_device *dev, struct ieee_param *param)
@@ -3826,7 +3811,7 @@ static int rtw_add_sta(struct net_device *dev, struct ieee_param *param)
                if (WLAN_STA_HT&flags) {
                        psta->htpriv.ht_option = true;
                        psta->qos_option = 1;
-                       memcpy((void*)&psta->htpriv.ht_cap, (void*)&param->u.add_sta.ht_cap, sizeof(struct rtw_ieee80211_ht_cap));
+                       memcpy((void *)&psta->htpriv.ht_cap, (void *)&param->u.add_sta.ht_cap, sizeof(struct rtw_ieee80211_ht_cap));
                } else {
                        psta->htpriv.ht_option = false;
                }
@@ -4176,7 +4161,8 @@ static int rtw_ioctl_acl_remove_sta(struct net_device *dev, struct ieee_param *p
                return -EINVAL;
        }
 
-       return rtw_acl_remove_sta(padapter, param->sta_addr);
+       rtw_acl_remove_sta(padapter, param->sta_addr);
+       return 0;
 
 }
 
@@ -4252,94 +4238,94 @@ static int rtw_hostapd_ioctl(struct net_device *dev, struct iw_point *p)
        /* DBG_871X("%s, cmd =%d\n", __func__, param->cmd); */
 
        switch (param->cmd) {
-               case RTL871X_HOSTAPD_FLUSH:
+       case RTL871X_HOSTAPD_FLUSH:
 
-                       ret = rtw_hostapd_sta_flush(dev);
+               rtw_hostapd_sta_flush(dev);
 
-                       break;
+               break;
 
-               case RTL871X_HOSTAPD_ADD_STA:
+       case RTL871X_HOSTAPD_ADD_STA:
 
-                       ret = rtw_add_sta(dev, param);
+               ret = rtw_add_sta(dev, param);
 
-                       break;
+               break;
 
-               case RTL871X_HOSTAPD_REMOVE_STA:
+       case RTL871X_HOSTAPD_REMOVE_STA:
 
-                       ret = rtw_del_sta(dev, param);
+               ret = rtw_del_sta(dev, param);
 
-                       break;
+               break;
 
-               case RTL871X_HOSTAPD_SET_BEACON:
+       case RTL871X_HOSTAPD_SET_BEACON:
 
-                       ret = rtw_set_beacon(dev, param, p->length);
+               ret = rtw_set_beacon(dev, param, p->length);
 
-                       break;
+               break;
 
-               case RTL871X_SET_ENCRYPTION:
+       case RTL871X_SET_ENCRYPTION:
 
-                       ret = rtw_set_encryption(dev, param, p->length);
+               ret = rtw_set_encryption(dev, param, p->length);
 
-                       break;
+               break;
 
-               case RTL871X_HOSTAPD_GET_WPAIE_STA:
+       case RTL871X_HOSTAPD_GET_WPAIE_STA:
 
-                       ret = rtw_get_sta_wpaie(dev, param);
+               ret = rtw_get_sta_wpaie(dev, param);
 
-                       break;
+               break;
 
-               case RTL871X_HOSTAPD_SET_WPS_BEACON:
+       case RTL871X_HOSTAPD_SET_WPS_BEACON:
 
-                       ret = rtw_set_wps_beacon(dev, param, p->length);
+               ret = rtw_set_wps_beacon(dev, param, p->length);
 
-                       break;
+               break;
 
-               case RTL871X_HOSTAPD_SET_WPS_PROBE_RESP:
+       case RTL871X_HOSTAPD_SET_WPS_PROBE_RESP:
 
-                       ret = rtw_set_wps_probe_resp(dev, param, p->length);
+               ret = rtw_set_wps_probe_resp(dev, param, p->length);
 
-                       break;
+               break;
 
-               case RTL871X_HOSTAPD_SET_WPS_ASSOC_RESP:
+       case RTL871X_HOSTAPD_SET_WPS_ASSOC_RESP:
 
-                       ret = rtw_set_wps_assoc_resp(dev, param, p->length);
+               ret = rtw_set_wps_assoc_resp(dev, param, p->length);
 
-                       break;
+               break;
 
-               case RTL871X_HOSTAPD_SET_HIDDEN_SSID:
+       case RTL871X_HOSTAPD_SET_HIDDEN_SSID:
 
-                       ret = rtw_set_hidden_ssid(dev, param, p->length);
+               ret = rtw_set_hidden_ssid(dev, param, p->length);
 
-                       break;
+               break;
 
-               case RTL871X_HOSTAPD_GET_INFO_STA:
+       case RTL871X_HOSTAPD_GET_INFO_STA:
 
-                       ret = rtw_ioctl_get_sta_data(dev, param, p->length);
+               ret = rtw_ioctl_get_sta_data(dev, param, p->length);
 
-                       break;
+               break;
 
-               case RTL871X_HOSTAPD_SET_MACADDR_ACL:
+       case RTL871X_HOSTAPD_SET_MACADDR_ACL:
 
-                       ret = rtw_ioctl_set_macaddr_acl(dev, param, p->length);
+               ret = rtw_ioctl_set_macaddr_acl(dev, param, p->length);
 
-                       break;
+               break;
 
-               case RTL871X_HOSTAPD_ACL_ADD_STA:
+       case RTL871X_HOSTAPD_ACL_ADD_STA:
 
-                       ret = rtw_ioctl_acl_add_sta(dev, param, p->length);
+               ret = rtw_ioctl_acl_add_sta(dev, param, p->length);
 
-                       break;
+               break;
 
-               case RTL871X_HOSTAPD_ACL_REMOVE_STA:
+       case RTL871X_HOSTAPD_ACL_REMOVE_STA:
 
-                       ret = rtw_ioctl_acl_remove_sta(dev, param, p->length);
+               ret = rtw_ioctl_acl_remove_sta(dev, param, p->length);
 
-                       break;
+               break;
 
-               default:
-                       DBG_871X("Unknown hostapd request: %d\n", param->cmd);
-                       ret = -EOPNOTSUPP;
-                       break;
+       default:
+               DBG_871X("Unknown hostapd request: %d\n", param->cmd);
+               ret = -EOPNOTSUPP;
+               break;
 
        }
 
@@ -4370,7 +4356,7 @@ static int rtw_wx_set_priv(struct net_device *dev,
        char *ext;
 
        struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
-       struct iw_point *dwrq = (struct iw_point*)awrq;
+       struct iw_point *dwrq = (struct iw_point *)awrq;
 
        /* RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_notice_, ("+rtw_wx_set_priv\n")); */
        if (dwrq->length == 0)
@@ -4542,7 +4528,7 @@ static int rtw_test(
        }
        DBG_871X("%s: string =\"%s\"\n", __func__, pbuf);
 
-       ptmp = (char*)pbuf;
+       ptmp = (char *)pbuf;
        pch = strsep(&ptmp, delim);
        if ((pch == NULL) || (strlen(pch) == 0)) {
                kfree(pbuf);
@@ -4551,10 +4537,10 @@ static int rtw_test(
        }
 
        if (strcmp(pch, "bton") == 0)
-               rtw_btcoex_SetManualControl(padapter, false);
+               hal_btcoex_SetManualControl(padapter, false);
 
        if (strcmp(pch, "btoff") == 0)
-               rtw_btcoex_SetManualControl(padapter, true);
+               hal_btcoex_SetManualControl(padapter, true);
 
        if (strcmp(pch, "h2c") == 0) {
                u8 param[8];
@@ -5015,62 +5001,62 @@ static int rtw_ioctl_wext_private(struct net_device *dev, union iwreq_data *wrq_
                u8 *str;
 
                switch (priv_args[k].set_args & IW_PRIV_TYPE_MASK) {
-                       case IW_PRIV_TYPE_BYTE:
-                               /* Fetch args */
-                               count = 0;
-                               do {
-                                       str = strsep(&ptr, delim);
-                                       if (NULL == str) break;
-                                       sscanf(str, "%i", &temp);
-                                       buffer[count++] = (u8)temp;
-                               } while (1);
-                               buffer_len = count;
-
-                               /* Number of args to fetch */
-                               wdata.data.length = count;
-                               if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
-                                       wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
+               case IW_PRIV_TYPE_BYTE:
+                       /* Fetch args */
+                       count = 0;
+                       do {
+                               str = strsep(&ptr, delim);
+                               if (NULL == str) break;
+                               sscanf(str, "%i", &temp);
+                               buffer[count++] = (u8)temp;
+                       } while (1);
+                       buffer_len = count;
+
+                       /* Number of args to fetch */
+                       wdata.data.length = count;
+                       if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
+                               wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
 
-                               break;
+                       break;
 
-                       case IW_PRIV_TYPE_INT:
-                               /* Fetch args */
-                               count = 0;
-                               do {
-                                       str = strsep(&ptr, delim);
-                                       if (NULL == str) break;
-                                       sscanf(str, "%i", &temp);
-                                       ((s32*)buffer)[count++] = (s32)temp;
-                               } while (1);
-                               buffer_len = count * sizeof(s32);
-
-                               /* Number of args to fetch */
-                               wdata.data.length = count;
-                               if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
-                                       wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
+               case IW_PRIV_TYPE_INT:
+                       /* Fetch args */
+                       count = 0;
+                       do {
+                               str = strsep(&ptr, delim);
+                               if (NULL == str) break;
+                               sscanf(str, "%i", &temp);
+                               ((s32 *)buffer)[count++] = (s32)temp;
+                       } while (1);
+                       buffer_len = count * sizeof(s32);
+
+                       /* Number of args to fetch */
+                       wdata.data.length = count;
+                       if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
+                               wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
 
-                               break;
+                       break;
 
-                       case IW_PRIV_TYPE_CHAR:
-                               if (len > 0) {
-                                       /* Size of the string to fetch */
-                                       wdata.data.length = len;
-                                       if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
-                                               wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
+               case IW_PRIV_TYPE_CHAR:
+                       if (len > 0) {
+                               /* Size of the string to fetch */
+                               wdata.data.length = len;
+                               if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
+                                       wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
 
-                                       /* Fetch string */
-                                       memcpy(buffer, ptr, wdata.data.length);
-                               } else {
-                                       wdata.data.length = 1;
-                                       buffer[0] = '\0';
-                               }
-                               buffer_len = wdata.data.length;
-                               break;
+                               /* Fetch string */
+                               memcpy(buffer, ptr, wdata.data.length);
+                       } else {
+                               wdata.data.length = 1;
+                               buffer[0] = '\0';
+                       }
+                       buffer_len = wdata.data.length;
+                       break;
 
-                       default:
-                               DBG_8192C("%s: Not yet implemented...\n", __func__);
-                               err = -1;
-                               goto exit;
+               default:
+                       DBG_8192C("%s: Not yet implemented...\n", __func__);
+                       err = -1;
+                       goto exit;
                }
 
                if ((priv_args[k].set_args & IW_PRIV_SIZE_FIXED) &&
@@ -5162,43 +5148,43 @@ static int rtw_ioctl_wext_private(struct net_device *dev, union iwreq_data *wrq_
                }
 
                switch (priv_args[k].get_args & IW_PRIV_TYPE_MASK) {
-                       case IW_PRIV_TYPE_BYTE:
-                               /* Display args */
-                               for (j = 0; j < n; j++) {
-                                       sprintf(str, "%d  ", extra[j]);
-                                       len = strlen(str);
-                                       output_len = strlen(output);
-                                       if ((output_len + len + 1) > 4096) {
-                                               err = -E2BIG;
-                                               goto exit;
-                                       }
-                                       memcpy(output+output_len, str, len);
+               case IW_PRIV_TYPE_BYTE:
+                       /* Display args */
+                       for (j = 0; j < n; j++) {
+                               sprintf(str, "%d  ", extra[j]);
+                               len = strlen(str);
+                               output_len = strlen(output);
+                               if ((output_len + len + 1) > 4096) {
+                                       err = -E2BIG;
+                                       goto exit;
                                }
-                               break;
+                               memcpy(output+output_len, str, len);
+                       }
+                       break;
 
-                       case IW_PRIV_TYPE_INT:
-                               /* Display args */
-                               for (j = 0; j < n; j++) {
-                                       sprintf(str, "%d  ", ((__s32*)extra)[j]);
-                                       len = strlen(str);
-                                       output_len = strlen(output);
-                                       if ((output_len + len + 1) > 4096) {
-                                               err = -E2BIG;
-                                               goto exit;
-                                       }
-                                       memcpy(output+output_len, str, len);
+               case IW_PRIV_TYPE_INT:
+                       /* Display args */
+                       for (j = 0; j < n; j++) {
+                               sprintf(str, "%d  ", ((__s32 *)extra)[j]);
+                               len = strlen(str);
+                               output_len = strlen(output);
+                               if ((output_len + len + 1) > 4096) {
+                                       err = -E2BIG;
+                                       goto exit;
                                }
-                               break;
+                               memcpy(output+output_len, str, len);
+                       }
+                       break;
 
-                       case IW_PRIV_TYPE_CHAR:
-                               /* Display args */
-                               memcpy(output, extra, n);
-                               break;
+               case IW_PRIV_TYPE_CHAR:
+                       /* Display args */
+                       memcpy(output, extra, n);
+                       break;
 
-                       default:
-                               DBG_8192C("%s: Not yet implemented...\n", __func__);
-                               err = -1;
-                               goto exit;
+               default:
+                       DBG_8192C("%s: Not yet implemented...\n", __func__);
+                       err = -1;
+                       goto exit;
                }
 
                output_len = strlen(output) + 1;
@@ -5225,18 +5211,18 @@ int rtw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        int ret = 0;
 
        switch (cmd) {
-               case RTL_IOCTL_WPA_SUPPLICANT:
-                       ret = wpa_supplicant_ioctl(dev, &wrq->u.data);
-                       break;
-               case RTL_IOCTL_HOSTAPD:
-                       ret = rtw_hostapd_ioctl(dev, &wrq->u.data);
-                       break;
-               case SIOCDEVPRIVATE:
-                       ret = rtw_ioctl_wext_private(dev, &wrq->u);
-                       break;
-               default:
-                       ret = -EOPNOTSUPP;
-                       break;
+       case RTL_IOCTL_WPA_SUPPLICANT:
+               ret = wpa_supplicant_ioctl(dev, &wrq->u.data);
+               break;
+       case RTL_IOCTL_HOSTAPD:
+               ret = rtw_hostapd_ioctl(dev, &wrq->u.data);
+               break;
+       case SIOCDEVPRIVATE:
+               ret = rtw_ioctl_wext_private(dev, &wrq->u);
+               break;
+       default:
+               ret = -EOPNOTSUPP;
+               break;
        }
 
        return ret;
index da4bd5292b0a5ae75031d2a68019667bfec9874a..52a5b3156b28b23c59a6fd938a200cfb87f5cc4a 100644 (file)
@@ -26,7 +26,7 @@ static void _rtw_set_scan_deny_timer_hdl(struct timer_list *t)
        struct adapter *adapter =
                from_timer(adapter, t, mlmepriv.set_scan_deny_timer);
 
-       rtw_set_scan_deny_timer_hdl(adapter);
+       rtw_clear_scan_deny(adapter);
 }
 
 void rtw_init_mlme_timer(struct adapter *padapter)
@@ -46,11 +46,9 @@ void rtw_os_indicate_connect(struct adapter *adapter)
        struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
 
        if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) ||
-               (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true))
-       {
+               (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true)) {
                rtw_cfg80211_ibss_indicate_connect(adapter);
-       }
-       else
+       } else
                rtw_cfg80211_indicate_connect(adapter);
 
        rtw_indicate_wx_assoc_event(adapter);
@@ -77,8 +75,8 @@ void rtw_reset_securitypriv(struct adapter *adapter)
 
        spin_lock_bh(&adapter->security_key_mutex);
 
-       if (adapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)/* 802.1x */
-       {
+       if (adapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) {
+               /* 802.1x */
                /*  Added by Albert 2009/02/18 */
                /*  We have to backup the PMK information for WiFi PMK Caching test item. */
                /*  */
@@ -105,9 +103,8 @@ void rtw_reset_securitypriv(struct adapter *adapter)
                adapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
                adapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
 
-       }
-       else /* reset values in securitypriv */
-       {
+       } else {
+               /* reset values in securitypriv */
                /* if (adapter->mlmepriv.fw_state & WIFI_STATION_STATE) */
                /*  */
                struct security_priv *psec_priv = &adapter->securitypriv;
@@ -150,8 +147,7 @@ void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie)
        RT_TRACE(_module_mlme_osdep_c_, _drv_info_, ("+rtw_report_sec_ie, authmode =%d\n", authmode));
 
        buff = NULL;
-       if (authmode == _WPA_IE_ID_)
-       {
+       if (authmode == _WPA_IE_ID_) {
                RT_TRACE(_module_mlme_osdep_c_, _drv_info_, ("rtw_report_sec_ie, authmode =%d\n", authmode));
 
                buff = rtw_zmalloc(IW_CUSTOM_MAX);
index 8a9d838af24e825640a98cbfe12bd5c105b1d38e..544e799d0a03c3bd9addf366900664d0aca72696 100644 (file)
@@ -223,9 +223,8 @@ int _netdev_open(struct net_device *pnetdev);
 int netdev_open (struct net_device *pnetdev);
 static int netdev_close (struct net_device *pnetdev);
 
-static uint loadparam(struct adapter *padapter, _nic_hdl pnetdev)
+static void loadparam(struct adapter *padapter, _nic_hdl pnetdev)
 {
-       uint status = _SUCCESS;
        struct registry_priv  *registry_par = &padapter->registrypriv;
 
        registry_par->chip_version = (u8)rtw_chip_version;
@@ -330,7 +329,6 @@ static uint loadparam(struct adapter *padapter, _nic_hdl pnetdev)
        registry_par->qos_opt_enable = (u8)rtw_qos_opt_enable;
 
        registry_par->hiq_filter = (u8)rtw_hiq_filter;
-       return status;
 }
 
 static int rtw_net_set_mac_address(struct net_device *pnetdev, void *p)
@@ -601,9 +599,8 @@ void rtw_stop_drv_threads (struct adapter *padapter)
        rtw_hal_stop_thread(padapter);
 }
 
-static u8 rtw_init_default_value(struct adapter *padapter)
+static void rtw_init_default_value(struct adapter *padapter)
 {
-       u8 ret  = _SUCCESS;
        struct registry_priv *pregistrypriv = &padapter->registrypriv;
        struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
@@ -665,7 +662,6 @@ static u8 rtw_init_default_value(struct adapter *padapter)
        padapter->driver_ampdu_spacing = 0xFF;
        padapter->driver_rx_ampdu_factor =  0xFF;
 
-       return ret;
 }
 
 struct dvobj_priv *devobj_init(void)
@@ -707,9 +703,8 @@ void devobj_deinit(struct dvobj_priv *pdvobj)
        kfree(pdvobj);
 }
 
-u8 rtw_reset_drv_sw(struct adapter *padapter)
+void rtw_reset_drv_sw(struct adapter *padapter)
 {
-       u8 ret8 = _SUCCESS;
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
        struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
 
@@ -739,7 +734,6 @@ u8 rtw_reset_drv_sw(struct adapter *padapter)
 
        rtw_set_signal_stat_timer(&padapter->recvpriv);
 
-       return ret8;
 }
 
 
@@ -749,7 +743,7 @@ u8 rtw_init_drv_sw(struct adapter *padapter)
 
        RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_init_drv_sw\n"));
 
-       ret8 = rtw_init_default_value(padapter);
+       rtw_init_default_value(padapter);
 
        rtw_init_hal_com_default_value(padapter);
 
@@ -1214,7 +1208,7 @@ void rtw_dev_unload(struct adapter *padapter)
                }
 
                if (padapter->bSurpriseRemoved == false) {
-                       rtw_btcoex_IpsNotify(padapter, pwrctl->ips_mode_req);
+                       hal_btcoex_IpsNotify(padapter, pwrctl->ips_mode_req);
 #ifdef CONFIG_WOWLAN
                        if (pwrctl->bSupportRemoteWakeup == true &&
                                pwrctl->wowlan_mode == true) {
@@ -1289,14 +1283,13 @@ static int rtw_suspend_free_assoc_resource(struct adapter *padapter)
 }
 
 #ifdef CONFIG_WOWLAN
-int rtw_suspend_wow(struct adapter *padapter)
+void rtw_suspend_wow(struct adapter *padapter)
 {
        u8 ch, bw, offset;
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
        struct net_device *pnetdev = padapter->pnetdev;
        struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
        struct wowlan_ioctl_param poidparam;
-       int ret = _SUCCESS;
 
        DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
 
@@ -1364,7 +1357,6 @@ int rtw_suspend_wow(struct adapter *padapter)
                DBG_871X_LEVEL(_drv_always_, "%s: ### ERROR ### wowlan_mode =%d\n", __func__, pwrpriv->wowlan_mode);
        }
        DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
-       return ret;
 }
 #endif /* ifdef CONFIG_WOWLAN */
 
@@ -1422,10 +1414,9 @@ int rtw_suspend_ap_wow(struct adapter *padapter)
 #endif /* ifdef CONFIG_AP_WOWLAN */
 
 
-static int rtw_suspend_normal(struct adapter *padapter)
+static void rtw_suspend_normal(struct adapter *padapter)
 {
        struct net_device *pnetdev = padapter->pnetdev;
-       int ret = _SUCCESS;
 
        DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
        if (pnetdev) {
@@ -1447,7 +1438,6 @@ static int rtw_suspend_normal(struct adapter *padapter)
                padapter->intf_deinit(adapter_to_dvobj(padapter));
 
        DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
-       return ret;
 }
 
 int rtw_suspend_common(struct adapter *padapter)
@@ -1485,10 +1475,10 @@ int rtw_suspend_common(struct adapter *padapter)
 
        /*  wait for the latest FW to remove this condition. */
        if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
-               rtw_btcoex_SuspendNotify(padapter, 0);
+               hal_btcoex_SuspendNotify(padapter, 0);
                DBG_871X("WIFI_AP_STATE\n");
        } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) {
-               rtw_btcoex_SuspendNotify(padapter, 1);
+               hal_btcoex_SuspendNotify(padapter, 1);
                DBG_871X("STATION\n");
        }
 
@@ -1839,7 +1829,7 @@ int rtw_resume_common(struct adapter *padapter)
                rtw_resume_process_normal(padapter);
        }
 
-       rtw_btcoex_SuspendNotify(padapter, 0);
+       hal_btcoex_SuspendNotify(padapter, 0);
 
        if (pwrpriv) {
                pwrpriv->bInSuspend = false;
index a5a5a5c8226a51d94558d4b634290dc331a68306..62fdd24ba42760c3252ece6dfadb3feb7bb58714 100644 (file)
@@ -77,13 +77,13 @@ static int openFile(struct file **fpp, char *path, int flag, int mode)
 {
        struct file *fp;
 
-       fp =filp_open(path, flag, mode);
+       fp = filp_open(path, flag, mode);
        if (IS_ERR(fp)) {
                *fpp = NULL;
                return PTR_ERR(fp);
        }
        else {
-               *fpp =fp;
+               *fpp = fp;
                return 0;
        }
 }
@@ -106,10 +106,10 @@ static int readFile(struct file *fp, char *buf, int len)
        if (!fp->f_op || !fp->f_op->read)
                return -EPERM;
 
-       while (sum<len) {
+       while (sum < len) {
                rlen = kernel_read(fp, buf + sum, len - sum, &fp->f_pos);
-               if (rlen>0)
-                       sum+=rlen;
+               if (rlen > 0)
+                       sum += rlen;
                else if (0 != rlen)
                        return rlen;
                else
@@ -131,7 +131,7 @@ static int isFileReadable(char *path)
        int ret = 0;
        char buf;
 
-       fp =filp_open(path, O_RDONLY, 0);
+       fp = filp_open(path, O_RDONLY, 0);
        if (IS_ERR(fp))
                return PTR_ERR(fp);
 
@@ -151,7 +151,7 @@ static int isFileReadable(char *path)
 */
 static int retriveFromFile(char *path, u8 *buf, u32 sz)
 {
-       int ret =-1;
+       int ret = -1;
        struct file *fp;
 
        if (path && buf) {
@@ -160,7 +160,7 @@ static int retriveFromFile(char *path, u8 *buf, u32 sz)
                if (ret == 0) {
                        DBG_871X("%s openFile path:%s fp =%p\n", __func__, path , fp);
 
-                       ret =readFile(fp, buf, sz);
+                       ret = readFile(fp, buf, sz);
                        closeFile(fp);
 
                        DBG_871X("%s readFile, ret:%d\n", __func__, ret);
@@ -197,8 +197,8 @@ int rtw_is_file_readable(char *path)
 */
 int rtw_retrive_from_file(char *path, u8 *buf, u32 sz)
 {
-       int ret =retriveFromFile(path, buf, sz);
-       return ret>= 0?ret:0;
+       int ret = retriveFromFile(path, buf, sz);
+       return ret >= 0 ? ret : 0;
 }
 
 struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv, void *old_priv)
@@ -211,8 +211,8 @@ struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv, void *old_p
                goto RETURN;
 
        pnpi = netdev_priv(pnetdev);
-       pnpi->priv =old_priv;
-       pnpi->sizeof_priv =sizeof_priv;
+       pnpi->priv = old_priv;
+       pnpi->sizeof_priv = sizeof_priv;
 
 RETURN:
        return pnetdev;
@@ -236,7 +236,7 @@ struct net_device *rtw_alloc_etherdev(int sizeof_priv)
                goto RETURN;
        }
 
-       pnpi->sizeof_priv =sizeof_priv;
+       pnpi->sizeof_priv = sizeof_priv;
 RETURN:
        return pnetdev;
 }
@@ -284,7 +284,7 @@ int rtw_change_ifname(struct adapter *padapter, const char *ifname)
        else
                unregister_netdevice(cur_pnetdev);
 
-       rereg_priv->old_pnetdev =cur_pnetdev;
+       rereg_priv->old_pnetdev = cur_pnetdev;
 
        pnetdev = rtw_init_netdev(padapter);
        if (!pnetdev)  {
@@ -316,11 +316,6 @@ error:
 
 }
 
-u64 rtw_modular64(u64 x, u64 y)
-{
-       return do_div(x, y);
-}
-
 void rtw_buf_free(u8 **buf, u32 *buf_len)
 {
        u32 ori_len;
@@ -379,7 +374,7 @@ keep_ori:
  */
 inline bool rtw_cbuf_full(struct rtw_cbuf *cbuf)
 {
-       return (cbuf->write == cbuf->read-1)? true : false;
+       return (cbuf->write == cbuf->read - 1) ? true : false;
 }
 
 /**
@@ -390,7 +385,7 @@ inline bool rtw_cbuf_full(struct rtw_cbuf *cbuf)
  */
 inline bool rtw_cbuf_empty(struct rtw_cbuf *cbuf)
 {
-       return (cbuf->write == cbuf->read)? true : false;
+       return (cbuf->write == cbuf->read) ? true : false;
 }
 
 /**
@@ -408,7 +403,7 @@ bool rtw_cbuf_push(struct rtw_cbuf *cbuf, void *buf)
 
        DBG_871X("%s on %u\n", __func__, cbuf->write);
        cbuf->bufs[cbuf->write] = buf;
-       cbuf->write = (cbuf->write+1)%cbuf->size;
+       cbuf->write = (cbuf->write + 1) % cbuf->size;
 
        return _SUCCESS;
 }
@@ -428,7 +423,7 @@ void *rtw_cbuf_pop(struct rtw_cbuf *cbuf)
 
         DBG_871X("%s on %u\n", __func__, cbuf->read);
        buf = cbuf->bufs[cbuf->read];
-       cbuf->read = (cbuf->read+1)%cbuf->size;
+       cbuf->read = (cbuf->read + 1) % cbuf->size;
 
        return buf;
 }
index 67ec336264e5cbde636b6bdec37cc833c39d9430..643caccc3069c5d56c5d636268140455725231e7 100644 (file)
@@ -12,8 +12,7 @@
 
 void rtw_os_free_recvframe(union recv_frame *precvframe)
 {
-       if (precvframe->u.hdr.pkt)
-       {
+       if (precvframe->u.hdr.pkt) {
                dev_kfree_skb_any(precvframe->u.hdr.pkt);/* free skb by driver */
 
                precvframe->u.hdr.pkt = NULL;
@@ -21,13 +20,9 @@ void rtw_os_free_recvframe(union recv_frame *precvframe)
 }
 
 /* alloc os related resource in union recv_frame */
-int rtw_os_recv_resource_alloc(struct adapter *padapter, union recv_frame *precvframe)
+void rtw_os_recv_resource_alloc(struct adapter *padapter, union recv_frame *precvframe)
 {
-       int     res = _SUCCESS;
-
        precvframe->u.hdr.pkt_newalloc = precvframe->u.hdr.pkt = NULL;
-
-       return res;
 }
 
 /* free os related resource in union recv_frame */
@@ -38,10 +33,8 @@ void rtw_os_recv_resource_free(struct recv_priv *precvpriv)
 
        precvframe = (union recv_frame*) precvpriv->precv_frame_buf;
 
-       for (i = 0; i < NR_RECVFRAME; i++)
-       {
-               if (precvframe->u.hdr.pkt)
-               {
+       for (i = 0; i < NR_RECVFRAME; i++) {
+               if (precvframe->u.hdr.pkt) {
                        dev_kfree_skb_any(precvframe->u.hdr.pkt);/* free skb by driver */
                        precvframe->u.hdr.pkt = NULL;
                }
@@ -50,16 +43,11 @@ void rtw_os_recv_resource_free(struct recv_priv *precvpriv)
 }
 
 /* free os related resource in struct recv_buf */
-int rtw_os_recvbuf_resource_free(struct adapter *padapter, struct recv_buf *precvbuf)
+void rtw_os_recvbuf_resource_free(struct adapter *padapter, struct recv_buf *precvbuf)
 {
-       int ret = _SUCCESS;
-
-       if (precvbuf->pskb)
-       {
+       if (precvbuf->pskb) {
                dev_kfree_skb_any(precvbuf->pskb);
        }
-       return ret;
-
 }
 
 _pkt *rtw_os_alloc_msdu_pkt(union recv_frame *prframe, u16 nSubframe_Length, u8 *pdata)
@@ -71,22 +59,16 @@ _pkt *rtw_os_alloc_msdu_pkt(union recv_frame *prframe, u16 nSubframe_Length, u8
        pattrib = &prframe->u.hdr.attrib;
 
        sub_skb = rtw_skb_alloc(nSubframe_Length + 12);
-       if (sub_skb)
-       {
+       if (sub_skb) {
                skb_reserve(sub_skb, 12);
                skb_put_data(sub_skb, (pdata + ETH_HLEN), nSubframe_Length);
-       }
-       else
-       {
+       } else {
                sub_skb = rtw_skb_clone(prframe->u.hdr.pkt);
-               if (sub_skb)
-               {
+               if (sub_skb) {
                        sub_skb->data = pdata + ETH_HLEN;
                        sub_skb->len = nSubframe_Length;
                        skb_set_tail_pointer(sub_skb, nSubframe_Length);
-               }
-               else
-               {
+               } else {
                        DBG_871X("%s(): rtw_skb_clone() Fail!!!\n", __func__);
                        return NULL;
                }
@@ -121,8 +103,7 @@ void rtw_os_recv_indicate_pkt(struct adapter *padapter, _pkt *pkt, struct rx_pkt
 
        /* Indicat the packets to upper layer */
        if (pkt) {
-               if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
-               {
+               if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
                        _pkt *pskb2 = NULL;
                        struct sta_info *psta = NULL;
                        struct sta_priv *pstapriv = &padapter->stapriv;
@@ -130,20 +111,17 @@ void rtw_os_recv_indicate_pkt(struct adapter *padapter, _pkt *pkt, struct rx_pkt
 
                        /* DBG_871X("bmcast =%d\n", bmcast); */
 
-                       if (memcmp(pattrib->dst, myid(&padapter->eeprompriv), ETH_ALEN))
-                       {
+                       if (memcmp(pattrib->dst, myid(&padapter->eeprompriv), ETH_ALEN)) {
                                /* DBG_871X("not ap psta =%p, addr =%pM\n", psta, pattrib->dst); */
 
-                               if (bmcast)
-                               {
+                               if (bmcast) {
                                        psta = rtw_get_bcmc_stainfo(padapter);
                                        pskb2 = rtw_skb_clone(pkt);
                                } else {
                                        psta = rtw_get_stainfo(pstapriv, pattrib->dst);
                                }
 
-                               if (psta)
-                               {
+                               if (psta) {
                                        struct net_device *pnetdev = (struct net_device*)padapter->pnetdev;
 
                                        /* DBG_871X("directly forwarding to the rtw_xmit_entry\n"); */
@@ -162,9 +140,8 @@ void rtw_os_recv_indicate_pkt(struct adapter *padapter, _pkt *pkt, struct rx_pkt
                                                return;
                                        }
                                }
-                       }
-                       else/*  to APself */
-                       {
+                       } else {
+                               /*  to APself */
                                /* DBG_871X("to APSelf\n"); */
                                DBG_COUNTER(padapter->rx_logs.os_indicate_ap_self);
                        }
@@ -200,32 +177,23 @@ void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup)
        struct security_priv *psecuritypriv = &padapter->securitypriv;
        unsigned long cur_time = 0;
 
-       if (psecuritypriv->last_mic_err_time == 0)
-       {
+       if (psecuritypriv->last_mic_err_time == 0) {
                psecuritypriv->last_mic_err_time = jiffies;
-       }
-       else
-       {
+       } else {
                cur_time = jiffies;
 
-               if (cur_time - psecuritypriv->last_mic_err_time < 60*HZ)
-               {
+               if (cur_time - psecuritypriv->last_mic_err_time < 60*HZ) {
                        psecuritypriv->btkip_countermeasure = true;
                        psecuritypriv->last_mic_err_time = 0;
                        psecuritypriv->btkip_countermeasure_time = cur_time;
-               }
-               else
-               {
+               } else {
                        psecuritypriv->last_mic_err_time = jiffies;
                }
        }
 
-       if (bgroup)
-       {
+       if (bgroup) {
                key_type |= NL80211_KEYTYPE_GROUP;
-       }
-       else
-       {
+       } else {
                key_type |= NL80211_KEYTYPE_PAIRWISE;
        }
 
@@ -233,13 +201,10 @@ void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup)
                NULL, GFP_ATOMIC);
 
        memset(&ev, 0x00, sizeof(ev));
-       if (bgroup)
-       {
-           ev.flags |= IW_MICFAILURE_GROUP;
-       }
-       else
-       {
-           ev.flags |= IW_MICFAILURE_PAIRWISE;
+       if (bgroup) {
+               ev.flags |= IW_MICFAILURE_GROUP;
+       } else {
+               ev.flags |= IW_MICFAILURE_PAIRWISE;
        }
 
        ev.src_addr.sa_family = ARPHRD_ETHER;
@@ -258,8 +223,7 @@ static void rtw_os_ksocket_send(struct adapter *padapter, union recv_frame *prec
 
        DBG_871X("eth rx: got eth_type = 0x%x\n", pattrib->eth_type);
 
-       if (psta && psta->isrc && psta->pid>0)
-       {
+       if (psta && psta->isrc && psta->pid>0) {
                u16 rx_pid;
 
                rx_pid = *(u16*)(skb->data+ETH_HLEN);
@@ -267,8 +231,7 @@ static void rtw_os_ksocket_send(struct adapter *padapter, union recv_frame *prec
                DBG_871X("eth rx(pid = 0x%x): sta("MAC_FMT") pid = 0x%x\n",
                        rx_pid, MAC_ARG(psta->hwaddr), psta->pid);
 
-               if (rx_pid == psta->pid)
-               {
+               if (rx_pid == psta->pid) {
                        int i;
                        u16 len = *(u16*)(skb->data+ETH_HLEN+2);
                        /* u16 ctrl_type = *(u16*)(skb->data+ETH_HLEN+4); */
@@ -301,8 +264,7 @@ int rtw_recv_indicatepkt(struct adapter *padapter, union recv_frame *precv_frame
        pfree_recv_queue = &(precvpriv->free_recv_queue);
 
        skb = precv_frame->u.hdr.pkt;
-       if (skb == NULL)
-       {
+       if (skb == NULL) {
                RT_TRACE(_module_recv_osdep_c_, _drv_err_, ("rtw_recv_indicatepkt():skb == NULL something wrong!!!!\n"));
                goto _recv_indicatepkt_drop;
        }
@@ -320,8 +282,7 @@ int rtw_recv_indicatepkt(struct adapter *padapter, union recv_frame *precv_frame
        RT_TRACE(_module_recv_osdep_c_, _drv_info_, ("\n skb->head =%p skb->data =%p skb->tail =%p skb->end =%p skb->len =%d\n", skb->head, skb->data, skb_tail_pointer(skb), skb_end_pointer(skb), skb->len));
 
 #ifdef CONFIG_AUTO_AP_MODE
-       if (0x8899 == pattrib->eth_type)
-       {
+       if (0x8899 == pattrib->eth_type) {
                rtw_os_ksocket_send(padapter, precv_frame);
 
                /* goto _recv_indicatepkt_drop; */
@@ -336,7 +297,7 @@ int rtw_recv_indicatepkt(struct adapter *padapter, union recv_frame *precv_frame
 
        RT_TRACE(_module_recv_osdep_c_, _drv_info_, ("\n rtw_recv_indicatepkt :after rtw_os_recv_indicate_pkt!!!!\n"));
 
-        return _SUCCESS;
+       return _SUCCESS;
 
 _recv_indicatepkt_drop:
 
index d8e7ad1ed84266db421d87c4406bef7798f9cbfb..5f950fda48ea3d08711ba5a906892ffe6de37eaf 100644 (file)
@@ -63,8 +63,7 @@ static ssize_t proc_set_log_level(struct file *file, const char __user *buffer,
 
        if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
                sscanf(tmp, "%d ", &log_level);
-               if (log_level >= _drv_always_ && log_level <= _drv_debug_)
-               {
+               if (log_level >= _drv_always_ && log_level <= _drv_debug_) {
                        GlobalDebugLevel = log_level;
                        printk("%d\n", GlobalDebugLevel);
                }
@@ -122,14 +121,14 @@ int rtw_drv_proc_init(void)
        ssize_t i;
        struct proc_dir_entry *entry = NULL;
 
-       if (rtw_proc != NULL) {
+       if (rtw_proc) {
                rtw_warn_on(1);
                goto exit;
        }
 
        rtw_proc = rtw_proc_create_dir(RTW_PROC_NAME, get_proc_net, NULL);
 
-       if (rtw_proc == NULL) {
+       if (!rtw_proc) {
                rtw_warn_on(1);
                goto exit;
        }
@@ -152,7 +151,7 @@ void rtw_drv_proc_deinit(void)
 {
        int i;
 
-       if (rtw_proc == NULL)
+       if (!rtw_proc)
                return;
 
        for (i = 0; i < drv_proc_hdls_num; i++)
@@ -224,8 +223,7 @@ static ssize_t proc_set_linked_info_dump(struct file *file, const char __user *b
                return -EFAULT;
 
        if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
-               if (padapter)
-               {
+               if (padapter) {
                        /* padapter->bLinkInfoDump = mode; */
                        /* DBG_871X("linked_info_dump =%s\n", (padapter->bLinkInfoDump)?"enable":"disable"); */
                         linked_info_dump(padapter, mode);
@@ -637,18 +635,18 @@ static struct proc_dir_entry *rtw_odm_proc_init(struct net_device *dev)
        struct adapter  *adapter = rtw_netdev_priv(dev);
        ssize_t i;
 
-       if (adapter->dir_dev == NULL) {
+       if (!adapter->dir_dev) {
                rtw_warn_on(1);
                goto exit;
        }
 
-       if (adapter->dir_odm != NULL) {
+       if (adapter->dir_odm) {
                rtw_warn_on(1);
                goto exit;
        }
 
        dir_odm = rtw_proc_create_dir("odm", adapter->dir_dev, dev);
-       if (dir_odm == NULL) {
+       if (!dir_odm) {
                rtw_warn_on(1);
                goto exit;
        }
@@ -674,7 +672,7 @@ static void rtw_odm_proc_deinit(struct adapter      *adapter)
 
        dir_odm = adapter->dir_odm;
 
-       if (dir_odm == NULL) {
+       if (!dir_odm) {
                rtw_warn_on(1);
                return;
        }
@@ -695,18 +693,18 @@ struct proc_dir_entry *rtw_adapter_proc_init(struct net_device *dev)
        struct adapter *adapter = rtw_netdev_priv(dev);
        ssize_t i;
 
-       if (drv_proc == NULL) {
+       if (!drv_proc) {
                rtw_warn_on(1);
                goto exit;
        }
 
-       if (adapter->dir_dev != NULL) {
+       if (adapter->dir_dev) {
                rtw_warn_on(1);
                goto exit;
        }
 
        dir_dev = rtw_proc_create_dir(dev->name, drv_proc, dev);
-       if (dir_dev == NULL) {
+       if (!dir_dev) {
                rtw_warn_on(1);
                goto exit;
        }
@@ -736,7 +734,7 @@ void rtw_adapter_proc_deinit(struct net_device *dev)
 
        dir_dev = adapter->dir_dev;
 
-       if (dir_dev == NULL) {
+       if (!dir_dev) {
                rtw_warn_on(1);
                return;
        }
@@ -760,7 +758,7 @@ void rtw_adapter_proc_replace(struct net_device *dev)
 
        dir_dev = adapter->dir_dev;
 
-       if (dir_dev == NULL) {
+       if (!dir_dev) {
                rtw_warn_on(1);
                return;
        }
index 052482554f74ba3014befb8e5ba5f4857ea6ca8d..540a7eed621dcc67c8c753233d036d5271af89c6 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <drv_types.h>
 #include <rtw_debug.h>
+#include <hal_btcoex.h>
 #include <linux/jiffies.h>
 
 #ifndef dev_to_sdio_func
@@ -84,13 +85,10 @@ static int sdio_alloc_irq(struct dvobj_priv *dvobj)
        sdio_claim_host(func);
 
        err = sdio_claim_irq(func, &sd_sync_int_hdl);
-       if (err)
-       {
+       if (err) {
                dvobj->drv_dbg.dbg_sdio_alloc_irq_error_cnt++;
                printk(KERN_CRIT "%s: sdio_claim_irq FAIL(%d)!\n", __func__, err);
-       }
-       else
-       {
+       } else {
                dvobj->drv_dbg.dbg_sdio_alloc_irq_cnt++;
                dvobj->irq_alloc = 1;
        }
@@ -102,28 +100,26 @@ static int sdio_alloc_irq(struct dvobj_priv *dvobj)
 
 static void sdio_free_irq(struct dvobj_priv *dvobj)
 {
-    struct sdio_data *psdio_data;
-    struct sdio_func *func;
-    int err;
-
-    if (dvobj->irq_alloc) {
-        psdio_data = &dvobj->intf_data;
-        func = psdio_data->func;
-
-        if (func) {
-            sdio_claim_host(func);
-            err = sdio_release_irq(func);
-            if (err)
-            {
+       struct sdio_data *psdio_data;
+       struct sdio_func *func;
+       int err;
+
+       if (dvobj->irq_alloc) {
+               psdio_data = &dvobj->intf_data;
+               func = psdio_data->func;
+
+               if (func) {
+                       sdio_claim_host(func);
+                       err = sdio_release_irq(func);
+                       if (err) {
                                dvobj->drv_dbg.dbg_sdio_free_irq_error_cnt++;
                                DBG_871X_LEVEL(_drv_err_,"%s: sdio_release_irq FAIL(%d)!\n", __func__, err);
-            }
-            else
-               dvobj->drv_dbg.dbg_sdio_free_irq_cnt++;
-            sdio_release_host(func);
-        }
-        dvobj->irq_alloc = 0;
-    }
+                       } else
+                               dvobj->drv_dbg.dbg_sdio_free_irq_cnt++;
+                       sdio_release_host(func);
+               }
+               dvobj->irq_alloc = 0;
+       }
 }
 
 #ifdef CONFIG_GPIO_WAKEUP
@@ -224,20 +220,17 @@ static void sdio_deinit(struct dvobj_priv *dvobj)
        if (func) {
                sdio_claim_host(func);
                err = sdio_disable_func(func);
-               if (err)
-               {
+               if (err) {
                        dvobj->drv_dbg.dbg_sdio_deinit_error_cnt++;
                        DBG_8192C(KERN_ERR "%s: sdio_disable_func(%d)\n", __func__, err);
                }
 
                if (dvobj->irq_alloc) {
                        err = sdio_release_irq(func);
-                       if (err)
-                       {
+                       if (err) {
                                dvobj->drv_dbg.dbg_sdio_free_irq_error_cnt++;
                                DBG_8192C(KERN_ERR "%s: sdio_release_irq(%d)\n", __func__, err);
-                       }
-                       else
+                       } else
                                dvobj->drv_dbg.dbg_sdio_free_irq_cnt++;
                }
 
@@ -368,8 +361,7 @@ static struct adapter *rtw_sdio_if1_init(struct dvobj_priv *dvobj, const struct
        padapter->intf_alloc_irq = &sdio_alloc_irq;
        padapter->intf_free_irq = &sdio_free_irq;
 
-       if (rtw_init_io_priv(padapter, sdio_set_intf_ops) == _FAIL)
-       {
+       if (rtw_init_io_priv(padapter, sdio_set_intf_ops) == _FAIL) {
                RT_TRACE(_module_hci_intfs_c_, _drv_err_,
                        ("rtw_drv_init: Can't init io_priv\n"));
                goto free_hal_data;
@@ -379,7 +371,7 @@ static struct adapter *rtw_sdio_if1_init(struct dvobj_priv *dvobj, const struct
 
        rtw_hal_chip_configure(padapter);
 
-       rtw_btcoex_Initialize(padapter);
+       hal_btcoex_Initialize(padapter);
 
        /* 3 6. read efuse/eeprom data */
        rtw_hal_read_chip_info(padapter);
@@ -489,9 +481,8 @@ static int rtw_drv_init(
 
        /* dev_alloc_name && register_netdev */
        status = rtw_drv_register_netdev(if1);
-       if (status != _SUCCESS) {
+       if (status != _SUCCESS)
                goto free_if2;
-       }
 
        if (sdio_alloc_irq(dvobj) != _SUCCESS)
                goto free_if2;
@@ -569,14 +560,12 @@ static int rtw_sdio_suspend(struct device *dev)
        struct adapter *padapter = psdpriv->if1;
        struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
 
-       if (padapter->bDriverStopped == true)
-       {
+       if (padapter->bDriverStopped == true) {
                DBG_871X("%s bDriverStopped = %d\n", __func__, padapter->bDriverStopped);
                return 0;
        }
 
-       if (pwrpriv->bInSuspend == true)
-       {
+       if (pwrpriv->bInSuspend == true) {
                DBG_871X("%s bInSuspend = %d\n", __func__, pwrpriv->bInSuspend);
                pdbgpriv->dbg_suspend_error_cnt++;
                return 0;
@@ -591,8 +580,7 @@ static int rtw_resume_process(struct adapter *padapter)
        struct dvobj_priv *psdpriv = padapter->dvobj;
        struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
 
-       if (pwrpriv->bInSuspend == false)
-       {
+       if (pwrpriv->bInSuspend == false) {
                pdbgpriv->dbg_resume_error_cnt++;
                DBG_871X("%s bInSuspend = %d\n", __func__, pwrpriv->bInSuspend);
                return -1;
@@ -635,8 +623,7 @@ static int __init rtw_drv_entry(void)
        rtw_drv_proc_init();
 
        ret = sdio_register_driver(&sdio_drvpriv.r871xs_drv);
-       if (ret != 0)
-       {
+       if (ret != 0) {
                sdio_drvpriv.drv_registered = false;
                rtw_drv_proc_deinit();
                rtw_ndev_notifier_unregister();
index 1787534487b4b473f4b97b8d1a410cf8a2d2b7b7..50b89340465b07940e0d2bc511d2db69b671a029 100644 (file)
@@ -257,15 +257,13 @@ u32 sd_read32(struct intf_hdl *pintfhdl, u32 addr, s32 *err)
        if (claim_needed)
                sdio_release_host(func);
 
-       if (err && *err)
-       {
+       if (err && *err) {
                int i;
 
                DBG_871X(KERN_ERR "%s: (%d) addr = 0x%05x, val = 0x%x\n", __func__, *err, addr, v);
 
                *err = 0;
-               for (i = 0; i < SD_IO_TRY_CNT; i++)
-               {
+               for (i = 0; i < SD_IO_TRY_CNT; i++) {
                        if (claim_needed) sdio_claim_host(func);
                        v = sdio_readl(func, addr, err);
                        if (claim_needed) sdio_release_host(func);
@@ -350,15 +348,13 @@ void sd_write32(struct intf_hdl *pintfhdl, u32 addr, u32 v, s32 *err)
        if (claim_needed)
                sdio_release_host(func);
 
-       if (err && *err)
-       {
+       if (err && *err) {
                int i;
 
                DBG_871X(KERN_ERR "%s: (%d) addr = 0x%05x val = 0x%08x\n", __func__, *err, addr, v);
 
                *err = 0;
-               for (i = 0; i < SD_IO_TRY_CNT; i++)
-               {
+               for (i = 0; i < SD_IO_TRY_CNT; i++) {
                        if (claim_needed) sdio_claim_host(func);
                        sdio_writel(func, v, addr, err);
                        if (claim_needed) sdio_release_host(func);
@@ -420,13 +416,11 @@ s32 _sd_read(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, void *pdata)
 
        func = psdio->func;
 
-       if (unlikely((cnt == 1) || (cnt == 2)))
-       {
+       if (unlikely((cnt == 1) || (cnt == 2))) {
                int i;
                u8 *pbuf = pdata;
 
-               for (i = 0; i < cnt; i++)
-               {
+               for (i = 0; i < cnt; i++) {
                        *(pbuf+i) = sdio_readb(func, addr+i, &err);
 
                        if (err) {
@@ -523,13 +517,11 @@ s32 _sd_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, void *pdata)
        func = psdio->func;
 /*     size = sdio_align_size(func, cnt); */
 
-       if (unlikely((cnt == 1) || (cnt == 2)))
-       {
+       if (unlikely((cnt == 1) || (cnt == 2))) {
                int i;
                u8 *pbuf = pdata;
 
-               for (i = 0; i < cnt; i++)
-               {
+               for (i = 0; i < cnt; i++) {
                        sdio_writeb(func, *(pbuf+i), addr+i, &err);
                        if (err) {
                                DBG_871X(KERN_ERR "%s: FAIL!(%d) addr = 0x%05x val = 0x%02x\n", __func__, err, addr, *(pbuf+i));
index 4e4e565d991c765a0c234cd685699ab90fb78658..4e81bc13e57ddd735d75cc3cf5bf5ddf46b0332b 100644 (file)
@@ -32,7 +32,7 @@ uint _rtw_pktfile_read (struct pkt_file *pfile, u8 *rmem, uint rlen)
        len = (rlen > len) ? len : rlen;
 
        if (rmem)
-               skb_copy_bits(pfile->pkt, pfile->buf_len-pfile->pkt_len, rmem, len);
+               skb_copy_bits(pfile->pkt, pfile->buf_len - pfile->pkt_len, rmem, len);
 
        pfile->cur_addr += len;
        pfile->pkt_len -= len;
@@ -50,7 +50,7 @@ int rtw_os_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *pxmitb
 {
        if (alloc_sz > 0) {
                pxmitbuf->pallocated_buf = rtw_zmalloc(alloc_sz);
-               if (pxmitbuf->pallocated_buf == NULL)
+               if (!pxmitbuf->pallocated_buf)
                        return _FAIL;
 
                pxmitbuf->pbuf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitbuf->pallocated_buf), XMITBUF_ALIGN_SZ);
@@ -65,7 +65,7 @@ void rtw_os_xmit_resource_free(struct adapter *padapter, struct xmit_buf *pxmitb
                kfree(pxmitbuf->pallocated_buf);
 }
 
-#define WMM_XMIT_THRESHOLD     (NR_XMITFRAME*2/5)
+#define WMM_XMIT_THRESHOLD     (NR_XMITFRAME * 2 / 5)
 
 void rtw_os_pkt_complete(struct adapter *padapter, _pkt *pkt)
 {
@@ -229,9 +229,9 @@ int _rtw_xmit_entry(_pkt *pkt, _nic_hdl pnetdev)
                        #endif
                        )
                && padapter->registrypriv.wifi_spec == 0) {
-               if (pxmitpriv->free_xmitframe_cnt > (NR_XMITFRAME/4)) {
+               if (pxmitpriv->free_xmitframe_cnt > (NR_XMITFRAME / 4)) {
                        res = rtw_mlcst2unicst(padapter, pkt);
-                       if (res == true)
+                       if (res)
                                goto exit;
                } else {
                        /* DBG_871X("Stop M2U(%d, %d)! ", pxmitpriv->free_xmitframe_cnt, pxmitpriv->free_xmitbuf_cnt); */
index 57bcf5834c0c9333a6929428cc42ab9938fea768..9cec0d8dd0b6cad6d8890d9bae1357629a25f6b2 100644 (file)
@@ -4,4 +4,4 @@ TODO:
 - We will use the stack in drivers/mmc to implement
   rts5208/5288 in the future
 
-Micky Ching <micky_ching@realsil.com.cn>
\ No newline at end of file
+Micky Ching <micky_ching@realsil.com.cn>
index 76c35f3c0208c8826ab7f2944320baa80dc4fc94..17c4131f5f62240c70fed4979fd021184e9d2b57 100644 (file)
@@ -598,38 +598,38 @@ nextcard:
        return STATUS_SUCCESS;
 }
 
-static inline int check_sd_speed_prior(u32 sd_speed_prior)
+static inline int valid_sd_speed_prior(u32 sd_speed_prior)
 {
-       bool fake_para = false;
+       bool valid_para = true;
        int i;
 
        for (i = 0; i < 4; i++) {
                u8 tmp = (u8)(sd_speed_prior >> (i * 8));
 
                if ((tmp < 0x01) || (tmp > 0x04)) {
-                       fake_para = true;
+                       valid_para = false;
                        break;
                }
        }
 
-       return !fake_para;
+       return valid_para;
 }
 
-static inline int check_sd_current_prior(u32 sd_current_prior)
+static inline int valid_sd_current_prior(u32 sd_current_prior)
 {
-       bool fake_para = false;
+       bool valid_para = true;
        int i;
 
        for (i = 0; i < 4; i++) {
                u8 tmp = (u8)(sd_current_prior >> (i * 8));
 
                if (tmp > 0x03) {
-                       fake_para = true;
+                       valid_para = false;
                        break;
                }
        }
 
-       return !fake_para;
+       return valid_para;
 }
 
 static int rts5208_init(struct rtsx_chip *chip)
@@ -796,13 +796,13 @@ int rtsx_init_chip(struct rtsx_chip *chip)
                chip->rw_fail_cnt[i] = 0;
        }
 
-       if (!check_sd_speed_prior(chip->sd_speed_prior))
+       if (!valid_sd_speed_prior(chip->sd_speed_prior))
                chip->sd_speed_prior = 0x01040203;
 
        dev_dbg(rtsx_dev(chip), "sd_speed_prior = 0x%08x\n",
                chip->sd_speed_prior);
 
-       if (!check_sd_current_prior(chip->sd_current_prior))
+       if (!valid_sd_current_prior(chip->sd_current_prior))
                chip->sd_current_prior = 0x00010203;
 
        dev_dbg(rtsx_dev(chip), "sd_current_prior = 0x%08x\n",
index c256a2398651c007303082286304a3158cf3b002..a0604534430127a35ec334f37828e890376a6624 100644 (file)
@@ -3580,11 +3580,6 @@ RW_FAIL:
 }
 
 #ifdef SUPPORT_CPRM
-int soft_reset_sd_card(struct rtsx_chip *chip)
-{
-       return reset_sd(chip);
-}
-
 int ext_sd_send_cmd_get_rsp(struct rtsx_chip *chip, u8 cmd_idx, u32 arg,
                            u8 rsp_type, u8 *rsp, int rsp_len,
                            bool special_check)
@@ -4512,20 +4507,19 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
                        sd_lock_state, sd_card->sd_lock_status);
                if (sd_lock_state ^ (sd_card->sd_lock_status & SD_LOCKED)) {
                        sd_card->sd_lock_notify = 1;
-                       if (sd_lock_state) {
-                               if (sd_card->sd_lock_status & SD_LOCK_1BIT_MODE) {
-                                       sd_card->sd_lock_status |= (
-                                               SD_UNLOCK_POW_ON | SD_SDR_RST);
-                                       if (CHK_SD(sd_card)) {
-                                               retval = reset_sd(chip);
-                                               if (retval != STATUS_SUCCESS) {
-                                                       sd_card->sd_lock_status &= ~(SD_UNLOCK_POW_ON | SD_SDR_RST);
-                                                       goto sd_execute_write_cmd_failed;
-                                               }
+                       if (sd_lock_state &&
+                           (sd_card->sd_lock_status & SD_LOCK_1BIT_MODE)) {
+                               sd_card->sd_lock_status |= (
+                                       SD_UNLOCK_POW_ON | SD_SDR_RST);
+                               if (CHK_SD(sd_card)) {
+                                       retval = reset_sd(chip);
+                                       if (retval != STATUS_SUCCESS) {
+                                               sd_card->sd_lock_status &= ~(SD_UNLOCK_POW_ON | SD_SDR_RST);
+                                               goto sd_execute_write_cmd_failed;
                                        }
-
-                                       sd_card->sd_lock_status &= ~(SD_UNLOCK_POW_ON | SD_SDR_RST);
                                }
+
+                               sd_card->sd_lock_status &= ~(SD_UNLOCK_POW_ON | SD_SDR_RST);
                        }
                }
        }
@@ -4639,7 +4633,7 @@ int sd_hw_rst(struct scsi_cmnd *srb, struct rtsx_chip *chip)
                break;
 
        case 1:
-               retval = soft_reset_sd_card(chip);
+               retval = reset_sd(chip);
                if (retval != STATUS_SUCCESS) {
                        set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
                        sd_card->pre_cmd_err = 1;
index e124526360b23abf0e3843ea830bc158d0acb764..dc9e8cad7a743a170a6b7a3527062cd54389a4b7 100644 (file)
@@ -273,7 +273,6 @@ void sd_cleanup_work(struct rtsx_chip *chip);
 int sd_power_off_card3v3(struct rtsx_chip *chip);
 int release_sd_card(struct rtsx_chip *chip);
 #ifdef SUPPORT_CPRM
-int soft_reset_sd_card(struct rtsx_chip *chip);
 int ext_sd_send_cmd_get_rsp(struct rtsx_chip *chip, u8 cmd_idx,
                            u32 arg, u8 rsp_type, u8 *rsp, int rsp_len,
                            bool special_check);
index c5ee04ecd1c9a1fc61322c2485002b0aec71a1a7..f3dc96a4c59dd0d5c1eb04ea71f3a4a0a1e036c4 100644 (file)
@@ -1155,10 +1155,10 @@ static int xd_copy_page(struct rtsx_chip *chip, u32 old_blk, u32 new_blk,
                                        return STATUS_FAIL;
                                }
 
-                               if (((reg & (XD_ECC1_ERROR | XD_ECC1_UNCORRECTABLE)) ==
-                                               (XD_ECC1_ERROR | XD_ECC1_UNCORRECTABLE)) ||
-                                       ((reg & (XD_ECC2_ERROR | XD_ECC2_UNCORRECTABLE)) ==
-                                               (XD_ECC2_ERROR | XD_ECC2_UNCORRECTABLE))) {
+                               if (((reg & XD_ECC1_ERROR) &&
+                                    (reg & XD_ECC1_UNCORRECTABLE)) ||
+                                   ((reg & XD_ECC2_ERROR) &&
+                                    (reg & XD_ECC2_UNCORRECTABLE))) {
                                        rtsx_write_register(chip,
                                                            XD_PAGE_STATUS,
                                                            0xFF,
index aa691e4a6916165afc8766e88e38e2cecb2ea3c8..6f8f86f161bb00bf0c0ceaf04b97442a10bdf5cb 100644 (file)
@@ -4,9 +4,6 @@
 
 #include <linux/serial.h>      /* for rs_table, serial constants */
 #include <linux/serial_reg.h>  /* for more serial constants */
-#ifndef __sparc__
-#include <linux/serial.h>
-#endif
 #include <linux/serial_core.h>
 
 #include "spk_priv.h"
index dc5e1bddc0852a171577af19b5466f47580245c3..43fe1ce538e1f21d4f56e5d15e696f56bebd92e9 100644 (file)
@@ -4,8 +4,8 @@
 #
 menuconfig UNISYSSPAR
        bool "Unisys SPAR driver support"
-       ---help---
-       Support for the Unisys SPAR drivers
+       help
+         Support for the Unisys SPAR drivers
 
 if UNISYSSPAR
 
index 1c1a470d2e50f03201b442174ba3af205abe4763..9d4f1dab0968dd04d5ed75daf42f240dfe00c71c 100644 (file)
@@ -1861,12 +1861,12 @@ static int visornic_probe(struct visor_device *dev)
        skb_queue_head_init(&devdata->xmitbufhead);
 
        /* create a cmdrsp we can use to post and unpost rcv buffers */
-       devdata->cmdrsp_rcv = kmalloc(SIZEOF_CMDRSP, GFP_ATOMIC);
+       devdata->cmdrsp_rcv = kmalloc(SIZEOF_CMDRSP, GFP_KERNEL);
        if (!devdata->cmdrsp_rcv) {
                err = -ENOMEM;
                goto cleanup_rcvbuf;
        }
-       devdata->xmit_cmdrsp = kmalloc(SIZEOF_CMDRSP, GFP_ATOMIC);
+       devdata->xmit_cmdrsp = kmalloc(SIZEOF_CMDRSP, GFP_KERNEL);
        if (!devdata->xmit_cmdrsp) {
                err = -ENOMEM;
                goto cleanup_cmdrsp_rcv;
index 49d0470f9a7e511135da7415ee095103a441ab3e..ea54cc27e645c26848b5a5bfbf1423dd76796333 100644 (file)
@@ -4,10 +4,11 @@
  *
  * Copyright Â© 2013 Raspberry Pi (Trading) Ltd.
  *
- * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
- *          Dave Stevenson <dsteve@broadcom.com>
- *          Simon Mellor <simellor@broadcom.com>
- *          Luke Diamand <luked@broadcom.com>
+ * Authors: Vincent Sanders @ Collabora
+ *          Dave Stevenson @ Broadcom
+ *             (now dave.stevenson@raspberrypi.org)
+ *          Simon Mellor @ Broadcom
+ *          Luke Diamand @ Broadcom
  */
 
 #include <linux/errno.h>
@@ -79,7 +80,7 @@ static struct mmal_fmt formats[] = {
                .flags = 0,
                .mmal = MMAL_ENCODING_I420,
                .depth = 12,
-               .mmal_component = MMAL_COMPONENT_CAMERA,
+               .mmal_component = COMP_CAMERA,
                .ybbp = 1,
                .remove_padding = 1,
        }, {
@@ -88,7 +89,7 @@ static struct mmal_fmt formats[] = {
                .flags = 0,
                .mmal = MMAL_ENCODING_YUYV,
                .depth = 16,
-               .mmal_component = MMAL_COMPONENT_CAMERA,
+               .mmal_component = COMP_CAMERA,
                .ybbp = 2,
                .remove_padding = 0,
        }, {
@@ -97,7 +98,7 @@ static struct mmal_fmt formats[] = {
                .flags = 0,
                .mmal = MMAL_ENCODING_RGB24,
                .depth = 24,
-               .mmal_component = MMAL_COMPONENT_CAMERA,
+               .mmal_component = COMP_CAMERA,
                .ybbp = 3,
                .remove_padding = 0,
        }, {
@@ -106,7 +107,7 @@ static struct mmal_fmt formats[] = {
                .flags = V4L2_FMT_FLAG_COMPRESSED,
                .mmal = MMAL_ENCODING_JPEG,
                .depth = 8,
-               .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
+               .mmal_component = COMP_IMAGE_ENCODE,
                .ybbp = 0,
                .remove_padding = 0,
        }, {
@@ -115,7 +116,7 @@ static struct mmal_fmt formats[] = {
                .flags = V4L2_FMT_FLAG_COMPRESSED,
                .mmal = MMAL_ENCODING_H264,
                .depth = 8,
-               .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
+               .mmal_component = COMP_VIDEO_ENCODE,
                .ybbp = 0,
                .remove_padding = 0,
        }, {
@@ -124,7 +125,7 @@ static struct mmal_fmt formats[] = {
                .flags = V4L2_FMT_FLAG_COMPRESSED,
                .mmal = MMAL_ENCODING_MJPEG,
                .depth = 8,
-               .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
+               .mmal_component = COMP_VIDEO_ENCODE,
                .ybbp = 0,
                .remove_padding = 0,
        }, {
@@ -133,7 +134,7 @@ static struct mmal_fmt formats[] = {
                .flags = 0,
                .mmal = MMAL_ENCODING_YVYU,
                .depth = 16,
-               .mmal_component = MMAL_COMPONENT_CAMERA,
+               .mmal_component = COMP_CAMERA,
                .ybbp = 2,
                .remove_padding = 0,
        }, {
@@ -142,7 +143,7 @@ static struct mmal_fmt formats[] = {
                .flags = 0,
                .mmal = MMAL_ENCODING_VYUY,
                .depth = 16,
-               .mmal_component = MMAL_COMPONENT_CAMERA,
+               .mmal_component = COMP_CAMERA,
                .ybbp = 2,
                .remove_padding = 0,
        }, {
@@ -151,7 +152,7 @@ static struct mmal_fmt formats[] = {
                .flags = 0,
                .mmal = MMAL_ENCODING_UYVY,
                .depth = 16,
-               .mmal_component = MMAL_COMPONENT_CAMERA,
+               .mmal_component = COMP_CAMERA,
                .ybbp = 2,
                .remove_padding = 0,
        }, {
@@ -160,7 +161,7 @@ static struct mmal_fmt formats[] = {
                .flags = 0,
                .mmal = MMAL_ENCODING_NV12,
                .depth = 12,
-               .mmal_component = MMAL_COMPONENT_CAMERA,
+               .mmal_component = COMP_CAMERA,
                .ybbp = 1,
                .remove_padding = 1,
        }, {
@@ -169,7 +170,7 @@ static struct mmal_fmt formats[] = {
                .flags = 0,
                .mmal = MMAL_ENCODING_BGR24,
                .depth = 24,
-               .mmal_component = MMAL_COMPONENT_CAMERA,
+               .mmal_component = COMP_CAMERA,
                .ybbp = 3,
                .remove_padding = 0,
        }, {
@@ -178,7 +179,7 @@ static struct mmal_fmt formats[] = {
                .flags = 0,
                .mmal = MMAL_ENCODING_YV12,
                .depth = 12,
-               .mmal_component = MMAL_COMPONENT_CAMERA,
+               .mmal_component = COMP_CAMERA,
                .ybbp = 1,
                .remove_padding = 1,
        }, {
@@ -187,7 +188,7 @@ static struct mmal_fmt formats[] = {
                .flags = 0,
                .mmal = MMAL_ENCODING_NV21,
                .depth = 12,
-               .mmal_component = MMAL_COMPONENT_CAMERA,
+               .mmal_component = COMP_CAMERA,
                .ybbp = 1,
                .remove_padding = 1,
        }, {
@@ -196,7 +197,7 @@ static struct mmal_fmt formats[] = {
                .flags = 0,
                .mmal = MMAL_ENCODING_BGRA,
                .depth = 32,
-               .mmal_component = MMAL_COMPONENT_CAMERA,
+               .mmal_component = COMP_CAMERA,
                .ybbp = 4,
                .remove_padding = 0,
        },
@@ -235,6 +236,22 @@ static int queue_setup(struct vb2_queue *vq,
                return -EINVAL;
        }
 
+       /* Handle CREATE_BUFS situation - *nplanes != 0 */
+       if (*nplanes) {
+               if (*nplanes != 1 ||
+                   sizes[0] < dev->capture.port->current_buffer.size) {
+                       v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+                                "%s: dev:%p Invalid buffer request from CREATE_BUFS, size %u < %u, nplanes %u != 1\n",
+                                __func__, dev, sizes[0],
+                                dev->capture.port->current_buffer.size,
+                                *nplanes);
+                       return -EINVAL;
+               } else {
+                       return 0;
+               }
+       }
+
+       /* Handle REQBUFS situation */
        size = dev->capture.port->current_buffer.size;
        if (size == 0) {
                v4l2_err(&dev->v4l2_dev,
@@ -312,7 +329,7 @@ static void buffer_cleanup(struct vb2_buffer *vb)
 static inline bool is_capturing(struct bm2835_mmal_dev *dev)
 {
        return dev->capture.camera_port ==
-           &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
+           &dev->component[COMP_CAMERA]->output[CAM_PORT_CAPTURE];
 }
 
 static void buffer_cb(struct vchiq_mmal_instance *instance,
@@ -327,25 +344,24 @@ static void buffer_cb(struct vchiq_mmal_instance *instance,
                 "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
                 __func__, status, buf, length, mmal_flags, pts);
 
-       if (status != 0) {
+       if (status) {
                /* error in transfer */
                if (buf) {
                        /* there was a buffer with the error so return it */
                        vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
                }
                return;
-       } else if (length == 0) {
+       }
+
+       if (length == 0) {
                /* stream ended */
-               if (buf) {
-                       /* this should only ever happen if the port is
-                        * disabled and there are buffers still queued
+               if (dev->capture.frame_count) {
+                       /* empty buffer whilst capturing - expected to be an
+                        * EOS, so grab another frame
                         */
-                       vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
-                       pr_debug("Empty buffer");
-               } else if (dev->capture.frame_count) {
-                       /* grab another frame */
                        if (is_capturing(dev)) {
-                               pr_debug("Grab another frame");
+                               v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+                                        "Grab another frame");
                                vchiq_mmal_port_parameter_set(
                                        instance,
                                        dev->capture.camera_port,
@@ -353,48 +369,60 @@ static void buffer_cb(struct vchiq_mmal_instance *instance,
                                        &dev->capture.frame_count,
                                        sizeof(dev->capture.frame_count));
                        }
+                       if (vchiq_mmal_submit_buffer(instance, port, buf))
+                               v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+                                        "Failed to return EOS buffer");
                } else {
-                       /* signal frame completion */
+                       /* stopping streaming.
+                        * return buffer, and signal frame completion
+                        */
+                       vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
                        complete(&dev->capture.frame_cmplt);
                }
+               return;
+       }
+
+       if (!dev->capture.frame_count) {
+               /* signal frame completion */
+               vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
+               complete(&dev->capture.frame_cmplt);
+               return;
+       }
+
+       if (dev->capture.vc_start_timestamp != -1 && pts) {
+               ktime_t timestamp;
+               s64 runtime_us = pts -
+                   dev->capture.vc_start_timestamp;
+               timestamp = ktime_add_us(dev->capture.kernel_start_ts,
+                                        runtime_us);
+               v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+                        "Convert start time %llu and %llu with offset %llu to %llu\n",
+                        ktime_to_ns(dev->capture.kernel_start_ts),
+                        dev->capture.vc_start_timestamp, pts,
+                        ktime_to_ns(timestamp));
+               buf->vb.vb2_buf.timestamp = ktime_to_ns(timestamp);
        } else {
-               if (dev->capture.frame_count) {
-                       if (dev->capture.vc_start_timestamp != -1 &&
-                           pts != 0) {
-                               ktime_t timestamp;
-                               s64 runtime_us = pts -
-                                   dev->capture.vc_start_timestamp;
-                               timestamp = ktime_add_us(dev->capture.kernel_start_ts,
-                                                        runtime_us);
-                               v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
-                                        "Convert start time %llu and %llu with offset %llu to %llu\n",
-                                        ktime_to_ns(dev->capture.kernel_start_ts),
-                                        dev->capture.vc_start_timestamp, pts,
-                                        ktime_to_ns(timestamp));
-                               buf->vb.vb2_buf.timestamp = ktime_to_ns(timestamp);
-                       } else {
-                               buf->vb.vb2_buf.timestamp = ktime_get_ns();
-                       }
+               buf->vb.vb2_buf.timestamp = ktime_get_ns();
+       }
+       buf->vb.sequence = dev->capture.sequence++;
+       buf->vb.field = V4L2_FIELD_NONE;
 
-                       vb2_set_plane_payload(&buf->vb.vb2_buf, 0, length);
-                       vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
+       vb2_set_plane_payload(&buf->vb.vb2_buf, 0, length);
+       if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_KEYFRAME)
+               buf->vb.flags |= V4L2_BUF_FLAG_KEYFRAME;
 
-                       if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
-                           is_capturing(dev)) {
-                               v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
-                                        "Grab another frame as buffer has EOS");
-                               vchiq_mmal_port_parameter_set(
-                                       instance,
-                                       dev->capture.camera_port,
-                                       MMAL_PARAMETER_CAPTURE,
-                                       &dev->capture.frame_count,
-                                       sizeof(dev->capture.frame_count));
-                       }
-               } else {
-                       /* signal frame completion */
-                       vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
-                       complete(&dev->capture.frame_cmplt);
-               }
+       vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
+
+       if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
+           is_capturing(dev)) {
+               v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+                        "Grab another frame as buffer has EOS");
+               vchiq_mmal_port_parameter_set(
+                       instance,
+                       dev->capture.camera_port,
+                       MMAL_PARAMETER_CAPTURE,
+                       &dev->capture.frame_count,
+                       sizeof(dev->capture.frame_count));
        }
 }
 
@@ -405,7 +433,7 @@ static int enable_camera(struct bm2835_mmal_dev *dev)
        if (!dev->camera_use_count) {
                ret = vchiq_mmal_port_parameter_set(
                        dev->instance,
-                       &dev->component[MMAL_COMPONENT_CAMERA]->control,
+                       &dev->component[COMP_CAMERA]->control,
                        MMAL_PARAMETER_CAMERA_NUM, &dev->camera_num,
                        sizeof(dev->camera_num));
                if (ret < 0) {
@@ -416,7 +444,7 @@ static int enable_camera(struct bm2835_mmal_dev *dev)
 
                ret = vchiq_mmal_component_enable(
                                dev->instance,
-                               dev->component[MMAL_COMPONENT_CAMERA]);
+                               dev->component[COMP_CAMERA]);
                if (ret < 0) {
                        v4l2_err(&dev->v4l2_dev,
                                 "Failed enabling camera, ret %d\n", ret);
@@ -448,7 +476,7 @@ static int disable_camera(struct bm2835_mmal_dev *dev)
                ret =
                    vchiq_mmal_component_disable(
                                dev->instance,
-                               dev->component[MMAL_COMPONENT_CAMERA]);
+                               dev->component[COMP_CAMERA]);
                if (ret < 0) {
                        v4l2_err(&dev->v4l2_dev,
                                 "Failed disabling camera, ret %d\n", ret);
@@ -456,7 +484,7 @@ static int disable_camera(struct bm2835_mmal_dev *dev)
                }
                vchiq_mmal_port_parameter_set(
                        dev->instance,
-                       &dev->component[MMAL_COMPONENT_CAMERA]->control,
+                       &dev->component[COMP_CAMERA]->control,
                        MMAL_PARAMETER_CAMERA_NUM, &i,
                        sizeof(i));
        }
@@ -505,10 +533,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
        /* enable frame capture */
        dev->capture.frame_count = 1;
 
+       /* reset sequence number */
+       dev->capture.sequence = 0;
+
        /* if the preview is not already running, wait for a few frames for AGC
         * to settle down.
         */
-       if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
+       if (!dev->component[COMP_PREVIEW]->enabled)
                msleep(300);
 
        /* enable the connection from camera to encoder (if applicable) */
@@ -536,10 +567,11 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
 
                /* Flag to indicate just to rely on kernel timestamps */
                dev->capture.vc_start_timestamp = -1;
-       } else
+       } else {
                v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
                         "Start time %lld size %d\n",
                         dev->capture.vc_start_timestamp, parameter_size);
+       }
 
        dev->capture.kernel_start_ts = ktime_get();
 
@@ -549,8 +581,8 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
            vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
        if (ret) {
                v4l2_err(&dev->v4l2_dev,
-                       "Failed to enable capture port - error %d. Disabling camera port again\n",
-                       ret);
+                        "Failed to enable capture port - error %d. Disabling camera port again\n",
+                        ret);
 
                vchiq_mmal_port_disable(dev->instance,
                                        dev->capture.camera_port);
@@ -576,6 +608,7 @@ static void stop_streaming(struct vb2_queue *vq)
        int ret;
        unsigned long timeout;
        struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
+       struct vchiq_mmal_port *port = dev->capture.port;
 
        v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
                 __func__, dev);
@@ -599,12 +632,6 @@ static void stop_streaming(struct vb2_queue *vq)
                                      &dev->capture.frame_count,
                                      sizeof(dev->capture.frame_count));
 
-       /* wait for last frame to complete */
-       timeout = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
-       if (timeout == 0)
-               v4l2_err(&dev->v4l2_dev,
-                        "timed out waiting for frame completion\n");
-
        v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
                 "disabling connection\n");
 
@@ -619,6 +646,21 @@ static void stop_streaming(struct vb2_queue *vq)
                         ret);
        }
 
+       /* wait for all buffers to be returned */
+       while (atomic_read(&port->buffers_with_vpu)) {
+               v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+                        "%s: Waiting for buffers to be returned - %d outstanding\n",
+                        __func__, atomic_read(&port->buffers_with_vpu));
+               timeout = wait_for_completion_timeout(&dev->capture.frame_cmplt,
+                                                     HZ);
+               if (timeout == 0) {
+                       v4l2_err(&dev->v4l2_dev, "%s: Timeout waiting for buffers to be returned - %d outstanding\n",
+                                __func__,
+                                atomic_read(&port->buffers_with_vpu));
+                       break;
+               }
+       }
+
        if (disable_camera(dev) < 0)
                v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
 }
@@ -730,9 +772,9 @@ static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
        vidioc_try_fmt_vid_overlay(file, priv, f);
 
        dev->overlay = f->fmt.win;
-       if (dev->component[MMAL_COMPONENT_PREVIEW]->enabled) {
+       if (dev->component[COMP_PREVIEW]->enabled) {
                set_overlay_params(dev,
-                                  &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
+                                  &dev->component[COMP_PREVIEW]->input[0]);
        }
 
        return 0;
@@ -745,12 +787,12 @@ static int vidioc_overlay(struct file *file, void *f, unsigned int on)
        struct vchiq_mmal_port *src;
        struct vchiq_mmal_port *dst;
 
-       if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
-           (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
+       if ((on && dev->component[COMP_PREVIEW]->enabled) ||
+           (!on && !dev->component[COMP_PREVIEW]->enabled))
                return 0;       /* already in requested state */
 
        src =
-           &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_PREVIEW];
+           &dev->component[COMP_CAMERA]->output[CAM_PORT_PREVIEW];
 
        if (!on) {
                /* disconnect preview ports and disable component */
@@ -762,39 +804,39 @@ static int vidioc_overlay(struct file *file, void *f, unsigned int on)
                if (ret >= 0)
                        ret = vchiq_mmal_component_disable(
                                        dev->instance,
-                                       dev->component[MMAL_COMPONENT_PREVIEW]);
+                                       dev->component[COMP_PREVIEW]);
 
                disable_camera(dev);
                return ret;
        }
 
        /* set preview port format and connect it to output */
-       dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
+       dst = &dev->component[COMP_PREVIEW]->input[0];
 
        ret = vchiq_mmal_port_set_format(dev->instance, src);
        if (ret < 0)
-               goto error;
+               return ret;
 
        ret = set_overlay_params(dev, dst);
        if (ret < 0)
-               goto error;
+               return ret;
 
        if (enable_camera(dev) < 0)
-               goto error;
+               return -EINVAL;
 
        ret = vchiq_mmal_component_enable(
                        dev->instance,
-                       dev->component[MMAL_COMPONENT_PREVIEW]);
+                       dev->component[COMP_PREVIEW]);
        if (ret < 0)
-               goto error;
+               return ret;
 
        v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
                 src, dst);
        ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
-       if (!ret)
-               ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
-error:
-       return ret;
+       if (ret)
+               return ret;
+
+       return vchiq_mmal_port_enable(dev->instance, src, NULL);
 }
 
 static int vidioc_g_fbuf(struct file *file, void *fh,
@@ -805,7 +847,7 @@ static int vidioc_g_fbuf(struct file *file, void *fh,
         */
        struct bm2835_mmal_dev *dev = video_drvdata(file);
        struct vchiq_mmal_port *preview_port =
-                   &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_PREVIEW];
+               &dev->component[COMP_CAMERA]->output[CAM_PORT_PREVIEW];
 
        a->capability = V4L2_FBUF_CAP_EXTERNOVERLAY |
                        V4L2_FBUF_CAP_GLOBAL_ALPHA;
@@ -826,7 +868,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
                             struct v4l2_input *inp)
 {
        /* only a single camera input */
-       if (inp->index != 0)
+       if (inp->index)
                return -EINVAL;
 
        inp->type = V4L2_INPUT_TYPE_CAMERA;
@@ -842,7 +884,7 @@ static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
 
 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
 {
-       if (i != 0)
+       if (i)
                return -EINVAL;
 
        return 0;
@@ -935,14 +977,27 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
                              1, 0);
        f->fmt.pix.bytesperline = f->fmt.pix.width * mfmt->ybbp;
        if (!mfmt->remove_padding) {
-               int align_mask = ((32 * mfmt->depth) >> 3) - 1;
-               /* GPU isn't removing padding, so stride is aligned to 32 */
-               f->fmt.pix.bytesperline =
-                       (f->fmt.pix.bytesperline + align_mask) & ~align_mask;
+               if (mfmt->depth == 24) {
+                       /*
+                        * 24bpp is a pain as we can't use simple masking.
+                        * Min stride is width aligned to 16, times 24bpp.
+                        */
+                       f->fmt.pix.bytesperline =
+                               ((f->fmt.pix.width + 15) & ~15) * 3;
+               } else {
+                       /*
+                        * GPU isn't removing padding, so stride is aligned to
+                        * 32
+                        */
+                       int align_mask = ((32 * mfmt->depth) >> 3) - 1;
+
+                       f->fmt.pix.bytesperline =
+                               (f->fmt.pix.bytesperline + align_mask) &
+                                                       ~align_mask;
+               }
                v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
-                        "Not removing padding, so bytes/line = %d, "
-                        "(align_mask %d)\n",
-                        f->fmt.pix.bytesperline, align_mask);
+                        "Not removing padding, so bytes/line = %d\n",
+                        f->fmt.pix.bytesperline);
        }
 
        /* Image buffer has to be padded to allow for alignment, even though
@@ -1003,27 +1058,28 @@ static int mmal_setup_components(struct bm2835_mmal_dev *dev,
        }
        /* format dependent port setup */
        switch (mfmt->mmal_component) {
-       case MMAL_COMPONENT_CAMERA:
+       case COMP_CAMERA:
                /* Make a further decision on port based on resolution */
                if (f->fmt.pix.width <= max_video_width &&
                    f->fmt.pix.height <= max_video_height)
-                       camera_port = port =
-                           &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_VIDEO];
+                       camera_port =
+                           &dev->component[COMP_CAMERA]->output[CAM_PORT_VIDEO];
                else
-                       camera_port = port =
-                           &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
+                       camera_port =
+                           &dev->component[COMP_CAMERA]->output[CAM_PORT_CAPTURE];
+               port = camera_port;
                break;
-       case MMAL_COMPONENT_IMAGE_ENCODE:
-               encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
-               port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
+       case COMP_IMAGE_ENCODE:
+               encode_component = dev->component[COMP_IMAGE_ENCODE];
+               port = &dev->component[COMP_IMAGE_ENCODE]->output[0];
                camera_port =
-                   &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
+                   &dev->component[COMP_CAMERA]->output[CAM_PORT_CAPTURE];
                break;
-       case MMAL_COMPONENT_VIDEO_ENCODE:
-               encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
-               port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
+       case COMP_VIDEO_ENCODE:
+               encode_component = dev->component[COMP_VIDEO_ENCODE];
+               port = &dev->component[COMP_VIDEO_ENCODE]->output[0];
                camera_port =
-                   &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_VIDEO];
+                   &dev->component[COMP_CAMERA]->output[CAM_PORT_VIDEO];
                break;
        default:
                break;
@@ -1063,13 +1119,13 @@ static int mmal_setup_components(struct bm2835_mmal_dev *dev,
 
        ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
 
-       if (!ret &&
-           camera_port ==
-           &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_VIDEO]) {
+       if (!ret
+           && camera_port ==
+           &dev->component[COMP_CAMERA]->output[CAM_PORT_VIDEO]) {
                bool overlay_enabled =
-                   !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
+                   !!dev->component[COMP_PREVIEW]->enabled;
                struct vchiq_mmal_port *preview_port =
-                   &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_PREVIEW];
+                   &dev->component[COMP_CAMERA]->output[CAM_PORT_PREVIEW];
                /* Preview and encode ports need to match on resolution */
                if (overlay_enabled) {
                        /* Need to disable the overlay before we can update
@@ -1100,7 +1156,7 @@ static int mmal_setup_components(struct bm2835_mmal_dev *dev,
                        ret = vchiq_mmal_port_connect_tunnel(
                                dev->instance,
                                preview_port,
-                               &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
+                               &dev->component[COMP_PREVIEW]->input[0]);
                        if (!ret)
                                ret = vchiq_mmal_port_enable(dev->instance,
                                                             preview_port,
@@ -1154,11 +1210,11 @@ static int mmal_setup_components(struct bm2835_mmal_dev *dev,
                                port->format.encoding_variant = 0;
                                /* Set any encoding specific parameters */
                                switch (mfmt->mmal_component) {
-                               case MMAL_COMPONENT_VIDEO_ENCODE:
+                               case COMP_VIDEO_ENCODE:
                                        port->format.bitrate =
                                            dev->capture.encode_bitrate;
                                        break;
-                               case MMAL_COMPONENT_IMAGE_ENCODE:
+                               case COMP_IMAGE_ENCODE:
                                        /* Could set EXIF parameters here */
                                        break;
                                default:
@@ -1202,9 +1258,8 @@ static int mmal_setup_components(struct bm2835_mmal_dev *dev,
                                                 port->current_buffer.size);
                                        port->current_buffer.size =
                                            (f->fmt.pix.sizeimage <
-                                            (100 << 10))
-                                           ? (100 << 10)
-                                           : f->fmt.pix.sizeimage;
+                                            (100 << 10)) ?
+                                           (100 << 10) : f->fmt.pix.sizeimage;
                                }
                                v4l2_dbg(1, bcm2835_v4l2_debug,
                                         &dev->v4l2_dev,
@@ -1277,7 +1332,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        }
 
        ret = mmal_setup_components(dev, f);
-       if (ret != 0) {
+       if (ret) {
                v4l2_err(&dev->v4l2_dev,
                         "%s: failed to setup mmal components: %d\n",
                         __func__, ret);
@@ -1288,7 +1343,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
 }
 
 static int vidioc_enum_framesizes(struct file *file, void *fh,
-                          struct v4l2_frmsizeenum *fsize)
+                                 struct v4l2_frmsizeenum *fsize)
 {
        struct bm2835_mmal_dev *dev = video_drvdata(file);
        static const struct v4l2_frmsize_stepwise sizes = {
@@ -1529,14 +1584,14 @@ static int mmal_init(struct bm2835_mmal_dev *dev)
 
        /* get the camera component ready */
        ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
-                                       &dev->component[MMAL_COMPONENT_CAMERA]);
+                                       &dev->component[COMP_CAMERA]);
        if (ret < 0)
                goto unreg_mmal;
 
-       camera = dev->component[MMAL_COMPONENT_CAMERA];
-       if (camera->outputs < MMAL_CAMERA_PORT_COUNT) {
+       camera = dev->component[COMP_CAMERA];
+       if (camera->outputs < CAM_PORT_COUNT) {
                v4l2_err(&dev->v4l2_dev, "%s: too few camera outputs %d needed %d\n",
-                        __func__, camera->outputs, MMAL_CAMERA_PORT_COUNT);
+                        __func__, camera->outputs, CAM_PORT_COUNT);
                ret = -EINVAL;
                goto unreg_camera;
        }
@@ -1558,7 +1613,7 @@ static int mmal_init(struct bm2835_mmal_dev *dev)
        dev->rgb_bgr_swapped = true;
        param_size = sizeof(supported_encodings);
        ret = vchiq_mmal_port_parameter_get(dev->instance,
-                                           &camera->output[MMAL_CAMERA_PORT_CAPTURE],
+                                           &camera->output[CAM_PORT_CAPTURE],
                                            MMAL_PARAMETER_SUPPORTED_ENCODINGS,
                                            &supported_encodings,
                                            &param_size);
@@ -1579,7 +1634,7 @@ static int mmal_init(struct bm2835_mmal_dev *dev)
                        }
                }
        }
-       format = &camera->output[MMAL_CAMERA_PORT_PREVIEW].format;
+       format = &camera->output[CAM_PORT_PREVIEW].format;
 
        format->encoding = MMAL_ENCODING_OPAQUE;
        format->encoding_variant = MMAL_ENCODING_I420;
@@ -1593,7 +1648,7 @@ static int mmal_init(struct bm2835_mmal_dev *dev)
        format->es->video.frame_rate.num = 0; /* Rely on fps_range */
        format->es->video.frame_rate.den = 1;
 
-       format = &camera->output[MMAL_CAMERA_PORT_VIDEO].format;
+       format = &camera->output[CAM_PORT_VIDEO].format;
 
        format->encoding = MMAL_ENCODING_OPAQUE;
        format->encoding_variant = MMAL_ENCODING_I420;
@@ -1607,7 +1662,7 @@ static int mmal_init(struct bm2835_mmal_dev *dev)
        format->es->video.frame_rate.num = 0; /* Rely on fps_range */
        format->es->video.frame_rate.den = 1;
 
-       format = &camera->output[MMAL_CAMERA_PORT_CAPTURE].format;
+       format = &camera->output[CAM_PORT_CAPTURE].format;
 
        format->encoding = MMAL_ENCODING_OPAQUE;
 
@@ -1631,49 +1686,49 @@ static int mmal_init(struct bm2835_mmal_dev *dev)
        /* get the preview component ready */
        ret = vchiq_mmal_component_init(
                        dev->instance, "ril.video_render",
-                       &dev->component[MMAL_COMPONENT_PREVIEW]);
+                       &dev->component[COMP_PREVIEW]);
        if (ret < 0)
                goto unreg_camera;
 
-       if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
+       if (dev->component[COMP_PREVIEW]->inputs < 1) {
                ret = -EINVAL;
                v4l2_err(&dev->v4l2_dev, "%s: too few input ports %d needed %d\n",
-                        __func__, dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
+                        __func__, dev->component[COMP_PREVIEW]->inputs, 1);
                goto unreg_preview;
        }
 
        /* get the image encoder component ready */
        ret = vchiq_mmal_component_init(
                dev->instance, "ril.image_encode",
-               &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
+               &dev->component[COMP_IMAGE_ENCODE]);
        if (ret < 0)
                goto unreg_preview;
 
-       if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
+       if (dev->component[COMP_IMAGE_ENCODE]->inputs < 1) {
                ret = -EINVAL;
                v4l2_err(&dev->v4l2_dev, "%s: too few input ports %d needed %d\n",
-                        __func__, dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
+                        __func__, dev->component[COMP_IMAGE_ENCODE]->inputs,
                         1);
                goto unreg_image_encoder;
        }
 
        /* get the video encoder component ready */
        ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
-                                       &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
+                                       &dev->component[COMP_VIDEO_ENCODE]);
        if (ret < 0)
                goto unreg_image_encoder;
 
-       if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
+       if (dev->component[COMP_VIDEO_ENCODE]->inputs < 1) {
                ret = -EINVAL;
                v4l2_err(&dev->v4l2_dev, "%s: too few input ports %d needed %d\n",
-                        __func__, dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
+                        __func__, dev->component[COMP_VIDEO_ENCODE]->inputs,
                         1);
                goto unreg_vid_encoder;
        }
 
        {
                struct vchiq_mmal_port *encoder_port =
-                       &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
+                       &dev->component[COMP_VIDEO_ENCODE]->output[0];
                encoder_port->format.encoding = MMAL_ENCODING_H264;
                ret = vchiq_mmal_port_set_format(dev->instance,
                                                 encoder_port);
@@ -1684,12 +1739,12 @@ static int mmal_init(struct bm2835_mmal_dev *dev)
 
                vchiq_mmal_port_parameter_set(
                        dev->instance,
-                       &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
+                       &dev->component[COMP_VIDEO_ENCODE]->control,
                        MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
                        &enable, sizeof(enable));
 
                vchiq_mmal_port_parameter_set(dev->instance,
-                                             &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
+                                             &dev->component[COMP_VIDEO_ENCODE]->control,
                                              MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
                                              &enable,
                                              sizeof(enable));
@@ -1707,23 +1762,23 @@ unreg_vid_encoder:
        pr_err("Cleanup: Destroy video encoder\n");
        vchiq_mmal_component_finalise(
                dev->instance,
-               dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
+               dev->component[COMP_VIDEO_ENCODE]);
 
 unreg_image_encoder:
        pr_err("Cleanup: Destroy image encoder\n");
        vchiq_mmal_component_finalise(
                dev->instance,
-               dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
+               dev->component[COMP_IMAGE_ENCODE]);
 
 unreg_preview:
        pr_err("Cleanup: Destroy video render\n");
        vchiq_mmal_component_finalise(dev->instance,
-                                     dev->component[MMAL_COMPONENT_PREVIEW]);
+                                     dev->component[COMP_PREVIEW]);
 
 unreg_camera:
        pr_err("Cleanup: Destroy camera\n");
        vchiq_mmal_component_finalise(dev->instance,
-                                     dev->component[MMAL_COMPONENT_CAMERA]);
+                                     dev->component[COMP_CAMERA]);
 
 unreg_mmal:
        vchiq_mmal_finalise(dev->instance);
@@ -1779,19 +1834,19 @@ static void bcm2835_cleanup_instance(struct bm2835_mmal_dev *dev)
                                             dev->capture.encode_component);
        }
        vchiq_mmal_component_disable(dev->instance,
-                                    dev->component[MMAL_COMPONENT_CAMERA]);
+                                    dev->component[COMP_CAMERA]);
 
        vchiq_mmal_component_finalise(dev->instance,
-                                     dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
+                                     dev->component[COMP_VIDEO_ENCODE]);
 
        vchiq_mmal_component_finalise(dev->instance,
-                                     dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
+                                     dev->component[COMP_IMAGE_ENCODE]);
 
        vchiq_mmal_component_finalise(dev->instance,
-                                     dev->component[MMAL_COMPONENT_PREVIEW]);
+                                     dev->component[COMP_PREVIEW]);
 
        vchiq_mmal_component_finalise(dev->instance,
-                                     dev->component[MMAL_COMPONENT_CAMERA]);
+                                     dev->component[COMP_CAMERA]);
 
        v4l2_ctrl_handler_free(&dev->ctrl_handler);
 
index 2b5679eb5b4a7eb0e51067562b16b749dae52ba5..b5fce38de038c97d715f5d01db040ebed8fe385f 100644 (file)
@@ -4,10 +4,11 @@
  *
  * Copyright Â© 2013 Raspberry Pi (Trading) Ltd.
  *
- * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
- *          Dave Stevenson <dsteve@broadcom.com>
- *          Simon Mellor <simellor@broadcom.com>
- *          Luke Diamand <luked@broadcom.com>
+ * Authors: Vincent Sanders @ Collabora
+ *          Dave Stevenson @ Broadcom
+ *             (now dave.stevenson@raspberrypi.org)
+ *          Simon Mellor @ Broadcom
+ *          Luke Diamand @ Broadcom
  *
  * core driver device
  */
 #define V4L2_CTRL_COUNT 29 /* number of v4l controls */
 
 enum {
-       MMAL_COMPONENT_CAMERA = 0,
-       MMAL_COMPONENT_PREVIEW,
-       MMAL_COMPONENT_IMAGE_ENCODE,
-       MMAL_COMPONENT_VIDEO_ENCODE,
-       MMAL_COMPONENT_COUNT
+       COMP_CAMERA = 0,
+       COMP_PREVIEW,
+       COMP_IMAGE_ENCODE,
+       COMP_VIDEO_ENCODE,
+       COMP_COUNT
 };
 
 enum {
-       MMAL_CAMERA_PORT_PREVIEW = 0,
-       MMAL_CAMERA_PORT_VIDEO,
-       MMAL_CAMERA_PORT_CAPTURE,
-       MMAL_CAMERA_PORT_COUNT
+       CAM_PORT_PREVIEW = 0,
+       CAM_PORT_VIDEO,
+       CAM_PORT_CAPTURE,
+       CAM_PORT_COUNT
 };
 
 #define PREVIEW_LAYER      2
@@ -60,7 +61,7 @@ struct bm2835_mmal_dev {
 
        /* allocated mmal instance and components */
        struct vchiq_mmal_instance   *instance;
-       struct vchiq_mmal_component  *component[MMAL_COMPONENT_COUNT];
+       struct vchiq_mmal_component  *component[COMP_COUNT];
        int camera_use_count;
 
        struct v4l2_window overlay;
@@ -90,6 +91,8 @@ struct bm2835_mmal_dev {
                s64         vc_start_timestamp;
                /* Kernel start timestamp for streaming */
                ktime_t kernel_start_ts;
+               /* Sequence number of last buffer */
+               u32             sequence;
 
                struct vchiq_mmal_port  *port; /* port being used for capture */
                /* camera port being used for capture */
@@ -127,6 +130,7 @@ int set_framerate_params(struct bm2835_mmal_dev *dev);
                (pix_fmt)->pixelformat, (pix_fmt)->bytesperline,        \
                (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
 }
+
 #define v4l2_dump_win_format(level, debug, dev, win_fmt, desc) \
 {      \
        v4l2_dbg(level, debug, dev,     \
index dade79738a2947c6948b0ed89946780c83d6fa84..89786c264867922704aa09ccc0cb51c368964269 100644 (file)
@@ -4,10 +4,11 @@
  *
  * Copyright Â© 2013 Raspberry Pi (Trading) Ltd.
  *
- * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
- *          Dave Stevenson <dsteve@broadcom.com>
- *          Simon Mellor <simellor@broadcom.com>
- *          Luke Diamand <luked@broadcom.com>
+ * Authors: Vincent Sanders @ Collabora
+ *          Dave Stevenson @ Broadcom
+ *             (now dave.stevenson@raspberrypi.org)
+ *          Simon Mellor @ Broadcom
+ *          Luke Diamand @ Broadcom
  */
 
 #include <linux/errno.h>
@@ -52,21 +53,9 @@ static const s64 ev_bias_qmenu[] = {
 static const s64 iso_qmenu[] = {
        0, 100000, 200000, 400000, 800000,
 };
-static const uint32_t iso_values[] = {
-       0, 100, 200, 400, 800,
-};
 
-static const s64 mains_freq_qmenu[] = {
-       V4L2_CID_POWER_LINE_FREQUENCY_DISABLED,
-       V4L2_CID_POWER_LINE_FREQUENCY_50HZ,
-       V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
-       V4L2_CID_POWER_LINE_FREQUENCY_AUTO
-};
-
-/* Supported video encode modes */
-static const s64 bitrate_mode_qmenu[] = {
-       (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
-       (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
+static const u32 iso_values[] = {
+       0, 100, 200, 400, 800,
 };
 
 enum bm2835_mmal_ctrl_type {
@@ -89,10 +78,10 @@ struct bm2835_mmal_v4l2_ctrl {
        /* control minimum value or
         * mask for MMAL_CONTROL_TYPE_STD_MENU
         */
-       s32 min;
-       s32 max; /* maximum value of control */
-       s32 def;  /* default value of control */
-       s32 step; /* step size of the control */
+       s64 min;
+       s64 max; /* maximum value of control */
+       s64 def;  /* default value of control */
+       u64 step; /* step size of the control */
        const s64 *imenu; /* integer menu array */
        u32 mmal_id; /* mmal parameter id */
        bm2835_mmal_v4l2_ctrl_cb *setter;
@@ -175,7 +164,7 @@ static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
        struct mmal_parameter_rational rational_value;
        struct vchiq_mmal_port *control;
 
-       control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
+       control = &dev->component[COMP_CAMERA]->control;
 
        rational_value.num = ctrl->val;
        rational_value.den = 100;
@@ -193,7 +182,7 @@ static int ctrl_set_value(struct bm2835_mmal_dev *dev,
        u32 u32_value;
        struct vchiq_mmal_port *control;
 
-       control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
+       control = &dev->component[COMP_CAMERA]->control;
 
        u32_value = ctrl->val;
 
@@ -218,7 +207,7 @@ static int ctrl_set_iso(struct bm2835_mmal_dev *dev,
                dev->manual_iso_enabled =
                                (ctrl->val == V4L2_ISO_SENSITIVITY_MANUAL);
 
-       control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
+       control = &dev->component[COMP_CAMERA]->control;
 
        if (dev->manual_iso_enabled)
                u32_value = dev->iso;
@@ -237,7 +226,7 @@ static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
        s32 s32_value;
        struct vchiq_mmal_port *control;
 
-       control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
+       control = &dev->component[COMP_CAMERA]->control;
 
        s32_value = (ctrl->val - 12) * 2;       /* Convert from index to 1/6ths */
 
@@ -254,7 +243,7 @@ static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
        u32 u32_value;
        struct vchiq_mmal_component *camera;
 
-       camera = dev->component[MMAL_COMPONENT_CAMERA];
+       camera = dev->component[COMP_CAMERA];
 
        u32_value = ((ctrl->val % 360) / 90) * 90;
 
@@ -288,7 +277,7 @@ static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
        else
                dev->vflip = ctrl->val;
 
-       camera = dev->component[MMAL_COMPONENT_CAMERA];
+       camera = dev->component[COMP_CAMERA];
 
        if (dev->hflip && dev->vflip)
                u32_value = MMAL_PARAM_MIRROR_BOTH;
@@ -325,7 +314,7 @@ static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
        struct vchiq_mmal_port *control;
        int ret = 0;
 
-       control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
+       control = &dev->component[COMP_CAMERA]->control;
 
        if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
                /* V4L2 is in 100usec increments.
@@ -400,13 +389,14 @@ static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
                struct vchiq_mmal_port *control;
                u32 u32_value = dev->metering_mode;
 
-               control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
+               control = &dev->component[COMP_CAMERA]->control;
 
                return vchiq_mmal_port_parameter_set(dev->instance, control,
                                             mmal_ctrl->mmal_id,
                                             &u32_value, sizeof(u32_value));
-       } else
+       } else {
                return 0;
+       }
 }
 
 static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
@@ -416,7 +406,7 @@ static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
        u32 u32_value;
        struct vchiq_mmal_port *control;
 
-       control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
+       control = &dev->component[COMP_CAMERA]->control;
 
        switch (ctrl->val) {
        case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
@@ -445,7 +435,7 @@ static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
        u32 u32_value;
        struct vchiq_mmal_port *control;
 
-       control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
+       control = &dev->component[COMP_CAMERA]->control;
 
        switch (ctrl->val) {
        case V4L2_WHITE_BALANCE_MANUAL:
@@ -501,7 +491,7 @@ static int ctrl_set_awb_gains(struct bm2835_mmal_dev *dev,
        struct vchiq_mmal_port *control;
        struct mmal_parameter_awbgains gains;
 
-       control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
+       control = &dev->component[COMP_CAMERA]->control;
 
        if (ctrl->id == V4L2_CID_RED_BALANCE)
                dev->red_gain = ctrl->val;
@@ -549,7 +539,7 @@ static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
                                        v4l2_to_mmal_effects_values[i].v;
                        }
 
-                       control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
+                       control = &dev->component[COMP_CAMERA]->control;
 
                        ret = vchiq_mmal_port_parameter_set(
                                        dev->instance, control,
@@ -579,13 +569,13 @@ static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
                          struct v4l2_ctrl *ctrl,
                          const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
 {
-       int ret = -EINVAL;
+       int ret;
        struct vchiq_mmal_port *control;
 
-       control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
+       control = &dev->component[COMP_CAMERA]->control;
 
-       dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
-       dev->colourfx.enable = ctrl->val & 0xff;
+       dev->colourfx.u = (ctrl->val & 0xff00) >> 8;
+       dev->colourfx.v = ctrl->val & 0xff;
 
        ret = vchiq_mmal_port_parameter_set(dev->instance, control,
                                            MMAL_PARAMETER_COLOUR_EFFECT,
@@ -603,15 +593,28 @@ static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
                            struct v4l2_ctrl *ctrl,
                            const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
 {
+       int ret;
        struct vchiq_mmal_port *encoder_out;
 
        dev->capture.encode_bitrate = ctrl->val;
 
-       encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
+       encoder_out = &dev->component[COMP_VIDEO_ENCODE]->output[0];
 
-       return vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
-                                            mmal_ctrl->mmal_id, &ctrl->val,
-                                            sizeof(ctrl->val));
+       ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
+                                           mmal_ctrl->mmal_id, &ctrl->val,
+                                           sizeof(ctrl->val));
+
+       v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+                "%s: After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
+                __func__, mmal_ctrl, ctrl->id, ctrl->val, ret,
+                (ret == 0 ? 0 : -EINVAL));
+
+       /*
+        * Older firmware versions (pre July 2019) have a bug in handling
+        * MMAL_PARAMETER_VIDEO_BIT_RATE that result in the call
+        * returning -MMAL_MSG_STATUS_EINVAL. So ignore errors from this call.
+        */
+       return 0;
 }
 
 static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
@@ -621,7 +624,7 @@ static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
        u32 bitrate_mode;
        struct vchiq_mmal_port *encoder_out;
 
-       encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
+       encoder_out = &dev->component[COMP_VIDEO_ENCODE]->output[0];
 
        dev->capture.encode_bitrate_mode = ctrl->val;
        switch (ctrl->val) {
@@ -648,7 +651,7 @@ static int ctrl_set_image_encode_output(struct bm2835_mmal_dev *dev,
        u32 u32_value;
        struct vchiq_mmal_port *jpeg_out;
 
-       jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
+       jpeg_out = &dev->component[COMP_IMAGE_ENCODE]->output[0];
 
        u32_value = ctrl->val;
 
@@ -664,7 +667,7 @@ static int ctrl_set_video_encode_param_output(struct bm2835_mmal_dev *dev,
        u32 u32_value;
        struct vchiq_mmal_port *vid_enc_ctl;
 
-       vid_enc_ctl = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
+       vid_enc_ctl = &dev->component[COMP_VIDEO_ENCODE]->output[0];
 
        u32_value = ctrl->val;
 
@@ -777,7 +780,7 @@ static int ctrl_set_video_encode_profile_level(struct bm2835_mmal_dev *dev,
                }
 
                ret = vchiq_mmal_port_parameter_set(dev->instance,
-                                                   &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0],
+                                                   &dev->component[COMP_VIDEO_ENCODE]->output[0],
                        mmal_ctrl->mmal_id,
                        &param, sizeof(param));
        }
@@ -795,7 +798,7 @@ static int ctrl_set_scene_mode(struct bm2835_mmal_dev *dev,
        v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
                 "scene mode selected %d, was %d\n", ctrl->val,
                 dev->scene_mode);
-       control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
+       control = &dev->component[COMP_CAMERA]->control;
 
        if (ctrl->val == dev->scene_mode)
                return 0;
@@ -956,8 +959,8 @@ static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
        },
        {
                V4L2_CID_ISO_SENSITIVITY_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
-               0, 1, V4L2_ISO_SENSITIVITY_AUTO, 1, NULL,
-               MMAL_PARAMETER_ISO,
+               0, V4L2_ISO_SENSITIVITY_AUTO, V4L2_ISO_SENSITIVITY_AUTO, 1,
+               NULL, MMAL_PARAMETER_ISO,
                ctrl_set_iso,
                false
        },
@@ -968,22 +971,13 @@ static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
                ctrl_set_value,
                false
        },
-/*     {
- *             0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
- *     },
- */
        {
                V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
-               ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
-               MMAL_PARAMETER_EXPOSURE_MODE,
+               ~0x03, V4L2_EXPOSURE_APERTURE_PRIORITY, V4L2_EXPOSURE_AUTO, 0,
+               NULL, MMAL_PARAMETER_EXPOSURE_MODE,
                ctrl_set_exposure,
                false
        },
-/* todo this needs mixing in with set exposure
- *     {
- *             V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
- *     },
- */
        {
                V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
                /* Units of 100usecs */
@@ -1011,7 +1005,8 @@ static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
        {
                V4L2_CID_EXPOSURE_METERING,
                MMAL_CONTROL_TYPE_STD_MENU,
-               ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
+               ~0x7, V4L2_EXPOSURE_METERING_SPOT,
+               V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
                MMAL_PARAMETER_EXP_METERING_MODE,
                ctrl_set_metering_mode,
                false
@@ -1019,7 +1014,8 @@ static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
        {
                V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
                MMAL_CONTROL_TYPE_STD_MENU,
-               ~0x3ff, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
+               ~0x3ff, V4L2_WHITE_BALANCE_SHADE, V4L2_WHITE_BALANCE_AUTO, 0,
+               NULL,
                MMAL_PARAMETER_AWB_MODE,
                ctrl_set_awb_mode,
                false
@@ -1040,7 +1036,7 @@ static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
        },
        {
                V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
-               0, 15, V4L2_COLORFX_NONE, 0, NULL,
+               0, V4L2_COLORFX_SET_CBCR, V4L2_COLORFX_NONE, 0, NULL,
                MMAL_PARAMETER_IMAGE_EFFECT,
                ctrl_set_image_effect,
                false
@@ -1075,8 +1071,8 @@ static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
        },
        {
                V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
-               0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
-               0, 0, bitrate_mode_qmenu,
+               0, V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
+               0, 0, NULL,
                MMAL_PARAMETER_RATECONTROL,
                ctrl_set_bitrate_mode,
                false
@@ -1098,8 +1094,8 @@ static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
        },
        {
                V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
-               0, ARRAY_SIZE(mains_freq_qmenu) - 1,
-               1, 1, mains_freq_qmenu,
+               0, V4L2_CID_POWER_LINE_FREQUENCY_AUTO,
+               1, 1, NULL,
                MMAL_PARAMETER_FLICKER_AVOID,
                ctrl_set_flicker_avoidance,
                false
@@ -1110,15 +1106,15 @@ static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
                0, 1, NULL,
                MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
                ctrl_set_video_encode_param_output,
-               true    /* Errors ignored as requires latest firmware to work */
+               false
        },
        {
                V4L2_CID_MPEG_VIDEO_H264_PROFILE,
                MMAL_CONTROL_TYPE_STD_MENU,
-               ~((1<<V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
-                       (1<<V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
-                       (1<<V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
-                       (1<<V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
+               ~(BIT(V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
+                 BIT(V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
+                 BIT(V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
+                 BIT(V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
                V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
                V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, 1, NULL,
                MMAL_PARAMETER_PROFILE,
@@ -1127,18 +1123,18 @@ static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
        },
        {
                V4L2_CID_MPEG_VIDEO_H264_LEVEL, MMAL_CONTROL_TYPE_STD_MENU,
-               ~((1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_0) |
-                       (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1B) |
-                       (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_1) |
-                       (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_2) |
-                       (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_3) |
-                       (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
-                       (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_1) |
-                       (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_2) |
-                       (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
-                       (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
-                       (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
-                       (1<<V4L2_MPEG_VIDEO_H264_LEVEL_4_0)),
+               ~(BIT(V4L2_MPEG_VIDEO_H264_LEVEL_1_0) |
+                 BIT(V4L2_MPEG_VIDEO_H264_LEVEL_1B) |
+                 BIT(V4L2_MPEG_VIDEO_H264_LEVEL_1_1) |
+                 BIT(V4L2_MPEG_VIDEO_H264_LEVEL_1_2) |
+                 BIT(V4L2_MPEG_VIDEO_H264_LEVEL_1_3) |
+                 BIT(V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
+                 BIT(V4L2_MPEG_VIDEO_H264_LEVEL_2_1) |
+                 BIT(V4L2_MPEG_VIDEO_H264_LEVEL_2_2) |
+                 BIT(V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
+                 BIT(V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
+                 BIT(V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
+                 BIT(V4L2_MPEG_VIDEO_H264_LEVEL_4_0)),
                V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
                V4L2_MPEG_VIDEO_H264_LEVEL_4_0, 1, NULL,
                MMAL_PARAMETER_PROFILE,
@@ -1147,7 +1143,7 @@ static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
        },
        {
                V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
-               -1,     /* Min is computed at runtime */
+               -1,     /* Min (mask) is computed at runtime */
                V4L2_SCENE_MODE_TEXT,
                V4L2_SCENE_MODE_NONE, 1, NULL,
                MMAL_PARAMETER_PROFILE,
@@ -1213,18 +1209,15 @@ int set_framerate_params(struct bm2835_mmal_dev *dev)
                 fps_range.fps_high.den);
 
        ret = vchiq_mmal_port_parameter_set(dev->instance,
-                                           &dev->component[MMAL_COMPONENT_CAMERA]->
-                                           output[MMAL_CAMERA_PORT_PREVIEW],
+                                           &dev->component[COMP_CAMERA]->output[CAM_PORT_PREVIEW],
                                            MMAL_PARAMETER_FPS_RANGE,
                                            &fps_range, sizeof(fps_range));
        ret += vchiq_mmal_port_parameter_set(dev->instance,
-                                            &dev->component[MMAL_COMPONENT_CAMERA]->
-                                            output[MMAL_CAMERA_PORT_VIDEO],
+                                            &dev->component[COMP_CAMERA]->output[CAM_PORT_VIDEO],
                                             MMAL_PARAMETER_FPS_RANGE,
                                             &fps_range, sizeof(fps_range));
        ret += vchiq_mmal_port_parameter_set(dev->instance,
-                                            &dev->component[MMAL_COMPONENT_CAMERA]->
-                                            output[MMAL_CAMERA_PORT_CAPTURE],
+                                            &dev->component[COMP_CAMERA]->output[CAM_PORT_CAPTURE],
                                             MMAL_PARAMETER_FPS_RANGE,
                                             &fps_range, sizeof(fps_range));
        if (ret)
@@ -1247,14 +1240,17 @@ int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
 
                switch (ctrl->type) {
                case MMAL_CONTROL_TYPE_STD:
-                       dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
-                               &bm2835_mmal_ctrl_ops, ctrl->id,
-                               ctrl->min, ctrl->max, ctrl->step, ctrl->def);
+                       dev->ctrls[c] =
+                               v4l2_ctrl_new_std(hdl,
+                                                 &bm2835_mmal_ctrl_ops,
+                                                 ctrl->id, ctrl->min,
+                                                 ctrl->max, ctrl->step,
+                                                 ctrl->def);
                        break;
 
                case MMAL_CONTROL_TYPE_STD_MENU:
                {
-                       int mask = ctrl->min;
+                       u64 mask = ctrl->min;
 
                        if (ctrl->id == V4L2_CID_SCENE_MODE) {
                                /* Special handling to work out the mask
@@ -1264,25 +1260,29 @@ int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
                                 */
                                int i;
 
-                               mask = 1 << V4L2_SCENE_MODE_NONE;
+                               mask = BIT(V4L2_SCENE_MODE_NONE);
                                for (i = 0;
                                     i < ARRAY_SIZE(scene_configs);
                                     i++) {
-                                       mask |= 1 << scene_configs[i].v4l2_scene;
+                                       mask |= BIT(scene_configs[i].v4l2_scene);
                                }
                                mask = ~mask;
                        }
 
-                       dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
-                       &bm2835_mmal_ctrl_ops, ctrl->id,
-                       ctrl->max, mask, ctrl->def);
+                       dev->ctrls[c] =
+                               v4l2_ctrl_new_std_menu(hdl,
+                                                      &bm2835_mmal_ctrl_ops,
+                                                      ctrl->id, ctrl->max,
+                                                      mask, ctrl->def);
                        break;
                }
 
                case MMAL_CONTROL_TYPE_INT_MENU:
-                       dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
-                               &bm2835_mmal_ctrl_ops, ctrl->id,
-                               ctrl->max, ctrl->def, ctrl->imenu);
+                       dev->ctrls[c] =
+                               v4l2_ctrl_new_int_menu(hdl,
+                                                      &bm2835_mmal_ctrl_ops,
+                                                      ctrl->id, ctrl->max,
+                                                      ctrl->def, ctrl->imenu);
                        break;
 
                case MMAL_CONTROL_TYPE_CLUSTER:
index a20bf274a4fdffdb443348baee76f03a63b90f60..6f56c517d850e332c64b32bbce513173c5e55168 100644 (file)
@@ -4,14 +4,17 @@
  *
  * Copyright Â© 2013 Raspberry Pi (Trading) Ltd.
  *
- * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
- *          Dave Stevenson <dsteve@broadcom.com>
- *          Simon Mellor <simellor@broadcom.com>
- *          Luke Diamand <luked@broadcom.com>
+ * Authors: Vincent Sanders @ Collabora
+ *          Dave Stevenson @ Broadcom
+ *             (now dave.stevenson@raspberrypi.org)
+ *          Simon Mellor @ Broadcom
+ *          Luke Diamand @ Broadcom
  *
  * MMAL structures
  *
  */
+#ifndef MMAL_COMMON_H
+#define MMAL_COMMON_H
 
 #define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
 #define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
@@ -55,3 +58,4 @@ struct mmal_colourfx {
        u32 u;
        u32 v;
 };
+#endif
index 129203597f917953901cfb23452c511fbb946c5c..2be9941a1f30e0136872c5d108e80f1bf3f60dbe 100644 (file)
@@ -4,10 +4,11 @@
  *
  * Copyright Â© 2013 Raspberry Pi (Trading) Ltd.
  *
- * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
- *          Dave Stevenson <dsteve@broadcom.com>
- *          Simon Mellor <simellor@broadcom.com>
- *          Luke Diamand <luked@broadcom.com>
+ * Authors: Vincent Sanders @ Collabora
+ *          Dave Stevenson @ Broadcom
+ *             (now dave.stevenson@raspberrypi.org)
+ *          Simon Mellor @ Broadcom
+ *          Luke Diamand @ Broadcom
  */
 #ifndef MMAL_ENCODINGS_H
 #define MMAL_ENCODINGS_H
index ec8455639d497f39db2ec6ea7f2f659ad7e79c7b..342c9b670f7ef5d7771899751dbe7222eab33305 100644 (file)
@@ -4,10 +4,11 @@
  *
  * Copyright Â© 2013 Raspberry Pi (Trading) Ltd.
  *
- * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
- *          Dave Stevenson <dsteve@broadcom.com>
- *          Simon Mellor <simellor@broadcom.com>
- *          Luke Diamand <luked@broadcom.com>
+ * Authors: Vincent Sanders @ Collabora
+ *          Dave Stevenson @ Broadcom
+ *             (now dave.stevenson@raspberrypi.org)
+ *          Simon Mellor @ Broadcom
+ *          Luke Diamand @ Broadcom
  */
 
 #ifndef MMAL_MSG_COMMON_H
index c9d6fbe25fe4869f79649b0cf391a1e1dc60a23e..a118efd21d98aa5f233636fed267b59f80255749 100644 (file)
@@ -4,10 +4,11 @@
  *
  * Copyright Â© 2013 Raspberry Pi (Trading) Ltd.
  *
- * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
- *          Dave Stevenson <dsteve@broadcom.com>
- *          Simon Mellor <simellor@broadcom.com>
- *          Luke Diamand <luked@broadcom.com>
+ * Authors: Vincent Sanders @ Collabora
+ *          Dave Stevenson @ Broadcom
+ *             (now dave.stevenson@raspberrypi.org)
+ *          Simon Mellor @ Broadcom
+ *          Luke Diamand @ Broadcom
  */
 
 #ifndef MMAL_MSG_FORMAT_H
 /* MMAL_ES_FORMAT_T */
 
 struct mmal_audio_format {
-       u32 channels;           /**< Number of audio channels */
-       u32 sample_rate;        /**< Sample rate */
+       u32 channels;           /* Number of audio channels */
+       u32 sample_rate;        /* Sample rate */
 
-       u32 bits_per_sample;    /**< Bits per sample */
-       u32 block_align;        /**< Size of a block of data */
+       u32 bits_per_sample;    /* Bits per sample */
+       u32 block_align;        /* Size of a block of data */
 };
 
 struct mmal_video_format {
-       u32 width;        /**< Width of frame in pixels */
-       u32 height;       /**< Height of frame in rows of pixels */
-       struct mmal_rect crop;         /**< Visible region of the frame */
-       struct mmal_rational frame_rate;   /**< Frame rate */
-       struct mmal_rational par;          /**< Pixel aspect ratio */
-
-       /* FourCC specifying the color space of the video stream. See the
-        * \ref MmalColorSpace "pre-defined color spaces" for some examples.
+       u32 width;              /* Width of frame in pixels */
+       u32 height;             /* Height of frame in rows of pixels */
+       struct mmal_rect crop;  /* Visible region of the frame */
+       struct mmal_rational frame_rate;        /* Frame rate */
+       struct mmal_rational par;               /* Pixel aspect ratio */
+
+       /*
+        * FourCC specifying the color space of the video stream. See the
+        * MmalColorSpace "pre-defined color spaces" for some examples.
         */
        u32 color_space;
 };
@@ -49,48 +51,56 @@ union mmal_es_specific_format {
        struct mmal_subpicture_format subpicture;
 };
 
-/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
+/* Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
 struct mmal_es_format_local {
-       u32 type;      /* enum mmal_es_type */
-
-       u32 encoding;  /* FourCC specifying encoding of the elementary stream.*/
-       u32 encoding_variant; /* FourCC specifying the specific
-                              * encoding variant of the elementary
-                              * stream.
-                              */
-
-       union mmal_es_specific_format *es;  /* Type specific
-                                            * information for the
-                                            * elementary stream
-                                            */
-
-       u32 bitrate;        /**< Bitrate in bits per second */
-       u32 flags; /**< Flags describing properties of the elementary stream. */
-
-       u32 extradata_size;       /**< Size of the codec specific data */
-       u8  *extradata;           /**< Codec specific data */
+       u32 type;       /* enum mmal_es_type */
+
+       u32 encoding;   /* FourCC specifying encoding of the elementary
+                        * stream.
+                        */
+       u32 encoding_variant;   /* FourCC specifying the specific
+                                * encoding variant of the elementary
+                                * stream.
+                                */
+
+       union mmal_es_specific_format *es;      /* Type specific
+                                                * information for the
+                                                * elementary stream
+                                                */
+
+       u32 bitrate;    /* Bitrate in bits per second */
+       u32 flags;      /* Flags describing properties of the elementary
+                        * stream.
+                        */
+
+       u32 extradata_size;     /* Size of the codec specific data */
+       u8  *extradata;         /* Codec specific data */
 };
 
-/** Remote definition of an elementary stream format (MMAL_ES_FORMAT_T) */
+/* Remote definition of an elementary stream format (MMAL_ES_FORMAT_T) */
 struct mmal_es_format {
-       u32 type;      /* enum mmal_es_type */
+       u32 type;       /* enum mmal_es_type */
 
-       u32 encoding;  /* FourCC specifying encoding of the elementary stream.*/
-       u32 encoding_variant; /* FourCC specifying the specific
-                              * encoding variant of the elementary
-                              * stream.
-                              */
+       u32 encoding;   /* FourCC specifying encoding of the elementary
+                        * stream.
+                        */
+       u32 encoding_variant;   /* FourCC specifying the specific
+                                * encoding variant of the elementary
+                                * stream.
+                                */
 
-       u32 es; /* Type specific
+       u32 es; /* Type specific
                 * information for the
                 * elementary stream
                 */
 
-       u32 bitrate;        /**< Bitrate in bits per second */
-       u32 flags; /**< Flags describing properties of the elementary stream. */
+       u32 bitrate;    /* Bitrate in bits per second */
+       u32 flags;      /* Flags describing properties of the elementary
+                        * stream.
+                        */
 
-       u32 extradata_size;       /**< Size of the codec specific data */
-       u32 extradata;           /**< Codec specific data */
+       u32 extradata_size;     /* Size of the codec specific data */
+       u32 extradata;          /* Codec specific data */
 };
 
 #endif /* MMAL_MSG_FORMAT_H */
index 3b3ed79cadd95aef1e0570418b05c83b690917f1..3fa3f2a578f069ca674dd4353b0827c09a6d8d90 100644 (file)
@@ -4,36 +4,40 @@
  *
  * Copyright Â© 2013 Raspberry Pi (Trading) Ltd.
  *
- * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
- *          Dave Stevenson <dsteve@broadcom.com>
- *          Simon Mellor <simellor@broadcom.com>
- *          Luke Diamand <luked@broadcom.com>
+ * Authors: Vincent Sanders @ Collabora
+ *          Dave Stevenson @ Broadcom
+ *             (now dave.stevenson@raspberrypi.org)
+ *          Simon Mellor @ Broadcom
+ *          Luke Diamand @ Broadcom
  */
 
 /* MMAL_PORT_TYPE_T */
 enum mmal_port_type {
-       MMAL_PORT_TYPE_UNKNOWN = 0,  /**< Unknown port type */
-       MMAL_PORT_TYPE_CONTROL,      /**< Control port */
-       MMAL_PORT_TYPE_INPUT,        /**< Input port */
-       MMAL_PORT_TYPE_OUTPUT,       /**< Output port */
-       MMAL_PORT_TYPE_CLOCK,        /**< Clock port */
+       MMAL_PORT_TYPE_UNKNOWN = 0,     /* Unknown port type */
+       MMAL_PORT_TYPE_CONTROL,         /* Control port */
+       MMAL_PORT_TYPE_INPUT,           /* Input port */
+       MMAL_PORT_TYPE_OUTPUT,          /* Output port */
+       MMAL_PORT_TYPE_CLOCK,           /* Clock port */
 };
 
-/** The port is pass-through and doesn't need buffer headers allocated */
+/* The port is pass-through and doesn't need buffer headers allocated */
 #define MMAL_PORT_CAPABILITY_PASSTHROUGH                       0x01
-/** The port wants to allocate the buffer payloads.
+/*
+ *The port wants to allocate the buffer payloads.
  * This signals a preference that payload allocation should be done
  * on this port for efficiency reasons.
  */
 #define MMAL_PORT_CAPABILITY_ALLOCATION                        0x02
-/** The port supports format change events.
+/*
+ * The port supports format change events.
  * This applies to input ports and is used to let the client know
  * whether the port supports being reconfigured via a format
  * change event (i.e. without having to disable the port).
  */
 #define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE      0x04
 
-/* mmal port structure (MMAL_PORT_T)
+/*
+ * mmal port structure (MMAL_PORT_T)
  *
  * most elements are informational only, the pointer values for
  * interogation messages are generally provided as additional
@@ -41,50 +45,50 @@ enum mmal_port_type {
  * buffer_num, buffer_size and userdata parameters are writable.
  */
 struct mmal_port {
-       u32 priv; /* Private member used by the framework */
-       u32 name; /* Port name. Used for debugging purposes (RO) */
-
-       u32 type;      /* Type of the port (RO) enum mmal_port_type */
-       u16 index;     /* Index of the port in its type list (RO) */
-       u16 index_all; /* Index of the port in the list of all ports (RO) */
-
-       u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
-       u32 format; /* Format of the elementary stream */
-
-       u32 buffer_num_min; /* Minimum number of buffers the port
-                            *   requires (RO).  This is set by the
-                            *   component.
-                            */
-
-       u32 buffer_size_min; /* Minimum size of buffers the port
-                             * requires (RO).  This is set by the
-                             * component.
-                             */
-
-       u32 buffer_alignment_min; /* Minimum alignment requirement for
-                                  * the buffers (RO).  A value of
-                                  * zero means no special alignment
-                                  * requirements.  This is set by the
-                                  * component.
-                                  */
-
-       u32 buffer_num_recommended;  /* Number of buffers the port
-                                     * recommends for optimal
-                                     * performance (RO).  A value of
-                                     * zero means no special
-                                     * recommendation.  This is set
-                                     * by the component.
-                                     */
-
-       u32 buffer_size_recommended; /* Size of buffers the port
-                                     * recommends for optimal
-                                     * performance (RO).  A value of
-                                     * zero means no special
-                                     * recommendation.  This is set
-                                     * by the component.
-                                     */
-
-       u32 buffer_num; /* Actual number of buffers the port will use.
+       u32 priv;       /* Private member used by the framework */
+       u32 name;       /* Port name. Used for debugging purposes (RO) */
+
+       u32 type;       /* Type of the port (RO) enum mmal_port_type */
+       u16 index;      /* Index of the port in its type list (RO) */
+       u16 index_all;  /* Index of the port in the list of all ports (RO) */
+
+       u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
+       u32 format;     /* Format of the elementary stream */
+
+       u32 buffer_num_min;     /* Minimum number of buffers the port
+                                *   requires (RO).  This is set by the
+                                *   component.
+                                */
+
+       u32 buffer_size_min;    /* Minimum size of buffers the port
+                                * requires (RO).  This is set by the
+                                * component.
+                                */
+
+       u32 buffer_alignment_min;/* Minimum alignment requirement for
+                                 * the buffers (RO).  A value of
+                                 * zero means no special alignment
+                                 * requirements.  This is set by the
+                                 * component.
+                                 */
+
+       u32 buffer_num_recommended;     /* Number of buffers the port
+                                        * recommends for optimal
+                                        * performance (RO).  A value of
+                                        * zero means no special
+                                        * recommendation.  This is set
+                                        * by the component.
+                                        */
+
+       u32 buffer_size_recommended;    /* Size of buffers the port
+                                        * recommends for optimal
+                                        * performance (RO).  A value of
+                                        * zero means no special
+                                        * recommendation.  This is set
+                                        * by the component.
+                                        */
+
+       u32 buffer_num; /* Actual number of buffers the port will use.
                         * This is set by the client.
                         */
 
@@ -93,14 +97,13 @@ struct mmal_port {
                          * the client.
                          */
 
-       u32 component; /* Component this port belongs to (Read Only) */
-
-       u32 userdata; /* Field reserved for use by the client */
+       u32 component;  /* Component this port belongs to (Read Only) */
 
-       u32 capabilities; /* Flags describing the capabilities of a
-                          * port (RO).  Bitwise combination of \ref
-                          * portcapabilities "Port capabilities"
-                          * values.
-                          */
+       u32 userdata;   /* Field reserved for use by the client */
 
+       u32 capabilities;       /* Flags describing the capabilities of a
+                                * port (RO).  Bitwise combination of \ref
+                                * portcapabilities "Port capabilities"
+                                * values.
+                                */
 };
index d1c57edbe2b890891f63078efc014fb635fafc3f..43cc59316f90a0344f1b4bf2b5074aaf36cf7a37 100644 (file)
@@ -4,13 +4,15 @@
  *
  * Copyright Â© 2013 Raspberry Pi (Trading) Ltd.
  *
- * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
- *          Dave Stevenson <dsteve@broadcom.com>
- *          Simon Mellor <simellor@broadcom.com>
- *          Luke Diamand <luked@broadcom.com>
+ * Authors: Vincent Sanders @ Collabora
+ *          Dave Stevenson @ Broadcom
+ *             (now dave.stevenson@raspberrypi.org)
+ *          Simon Mellor @ Broadcom
+ *          Luke Diamand @ Broadcom
  */
 
-/* all the data structures which serialise the MMAL protocol. note
+/*
+ * all the data structures which serialise the MMAL protocol. note
  * these are directly mapped onto the recived message data.
  *
  * BEWARE: They seem to *assume* pointers are u32 and that there is no
@@ -21,6 +23,8 @@
  * implementation uses fixed size types and not the enums (though the
  * comments have the actual enum type
  */
+#ifndef MMAL_MSG_H
+#define MMAL_MSG_H
 
 #define VC_MMAL_VER 15
 #define VC_MMAL_MIN_VER 10
@@ -40,51 +44,51 @@ enum mmal_msg_type {
        MMAL_MSG_TYPE_SERVICE_CLOSED,
        MMAL_MSG_TYPE_GET_VERSION,
        MMAL_MSG_TYPE_COMPONENT_CREATE,
-       MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
+       MMAL_MSG_TYPE_COMPONENT_DESTROY,        /* 5 */
        MMAL_MSG_TYPE_COMPONENT_ENABLE,
        MMAL_MSG_TYPE_COMPONENT_DISABLE,
        MMAL_MSG_TYPE_PORT_INFO_GET,
        MMAL_MSG_TYPE_PORT_INFO_SET,
-       MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
+       MMAL_MSG_TYPE_PORT_ACTION,              /* 10 */
        MMAL_MSG_TYPE_BUFFER_FROM_HOST,
        MMAL_MSG_TYPE_BUFFER_TO_HOST,
        MMAL_MSG_TYPE_GET_STATS,
        MMAL_MSG_TYPE_PORT_PARAMETER_SET,
-       MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
+       MMAL_MSG_TYPE_PORT_PARAMETER_GET,       /* 15 */
        MMAL_MSG_TYPE_EVENT_TO_HOST,
        MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
        MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
        MMAL_MSG_TYPE_CONSUME_MEM,
-       MMAL_MSG_TYPE_LMK, /* 20 */
+       MMAL_MSG_TYPE_LMK,                      /* 20 */
        MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
        MMAL_MSG_TYPE_DRM_GET_LHS32,
        MMAL_MSG_TYPE_DRM_GET_TIME,
        MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
-       MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
+       MMAL_MSG_TYPE_PORT_FLUSH,               /* 25 */
        MMAL_MSG_TYPE_HOST_LOG,
        MMAL_MSG_TYPE_MSG_LAST
 };
 
 /* port action request messages differ depending on the action type */
 enum mmal_msg_port_action_type {
-       MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0,      /* Unknown action */
-       MMAL_MSG_PORT_ACTION_TYPE_ENABLE,           /* Enable a port */
-       MMAL_MSG_PORT_ACTION_TYPE_DISABLE,          /* Disable a port */
-       MMAL_MSG_PORT_ACTION_TYPE_FLUSH,            /* Flush a port */
-       MMAL_MSG_PORT_ACTION_TYPE_CONNECT,          /* Connect ports */
-       MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,       /* Disconnect ports */
+       MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0,  /* Unknown action */
+       MMAL_MSG_PORT_ACTION_TYPE_ENABLE,       /* Enable a port */
+       MMAL_MSG_PORT_ACTION_TYPE_DISABLE,      /* Disable a port */
+       MMAL_MSG_PORT_ACTION_TYPE_FLUSH,        /* Flush a port */
+       MMAL_MSG_PORT_ACTION_TYPE_CONNECT,      /* Connect ports */
+       MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,   /* Disconnect ports */
        MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
 };
 
 struct mmal_msg_header {
        u32 magic;
-       u32 type; /** enum mmal_msg_type */
+       u32 type;       /* enum mmal_msg_type */
 
        /* Opaque handle to the control service */
        u32 control_service;
 
-       u32 context; /** a u32 per message context */
-       u32 status; /** The status of the vchiq operation */
+       u32 context;    /* a u32 per message context */
+       u32 status;     /* The status of the vchiq operation */
        u32 padding;
 };
 
@@ -98,9 +102,9 @@ struct mmal_msg_version {
 
 /* request to VC to create component */
 struct mmal_msg_component_create {
-       u32 client_component; /* component context */
+       u32 client_component;   /* component context */
        char name[128];
-       u32 pid;                /* For debug */
+       u32 pid;                /* For debug */
 };
 
 /* reply from VC to component creation request */
@@ -120,7 +124,7 @@ struct mmal_msg_component_destroy {
 };
 
 struct mmal_msg_component_destroy_reply {
-       u32 status; /** The component destruction status */
+       u32 status; /* The component destruction status */
 };
 
 /* request and reply to VC to enable a component */
@@ -129,7 +133,7 @@ struct mmal_msg_component_enable {
 };
 
 struct mmal_msg_component_enable_reply {
-       u32 status; /** The component enable status */
+       u32 status; /* The component enable status */
 };
 
 /* request and reply to VC to disable a component */
@@ -138,7 +142,7 @@ struct mmal_msg_component_disable {
 };
 
 struct mmal_msg_component_disable_reply {
-       u32 status; /** The component disable status */
+       u32 status; /* The component disable status */
 };
 
 /* request to VC to get port information */
@@ -150,12 +154,12 @@ struct mmal_msg_port_info_get {
 
 /* reply from VC to get port info request */
 struct mmal_msg_port_info_get_reply {
-       u32 status; /** enum mmal_msg_status */
-       u32 component_handle;  /* component handle port is associated with */
-       u32 port_type;         /* enum mmal_msg_port_type */
-       u32 port_index;        /* port indexed in query */
-       s32 found;             /* unused */
-       u32 port_handle;               /**< Handle to use for this port */
+       u32 status;             /* enum mmal_msg_status */
+       u32 component_handle;   /* component handle port is associated with */
+       u32 port_type;          /* enum mmal_msg_port_type */
+       u32 port_index;         /* port indexed in query */
+       s32 found;              /* unused */
+       u32 port_handle;        /* Handle to use for this port */
        struct mmal_port port;
        struct mmal_es_format format; /* elementary stream format */
        union mmal_es_specific_format es; /* es type specific data */
@@ -165,8 +169,8 @@ struct mmal_msg_port_info_get_reply {
 /* request to VC to set port information */
 struct mmal_msg_port_info_set {
        u32 component_handle;
-       u32 port_type;         /* enum mmal_msg_port_type */
-       u32 port_index;           /* port indexed in query */
+       u32 port_type;          /* enum mmal_msg_port_type */
+       u32 port_index;         /* port indexed in query */
        struct mmal_port port;
        struct mmal_es_format format;
        union mmal_es_specific_format es;
@@ -176,11 +180,11 @@ struct mmal_msg_port_info_set {
 /* reply from VC to port info set request */
 struct mmal_msg_port_info_set_reply {
        u32 status;
-       u32 component_handle;  /* component handle port is associated with */
-       u32 port_type;         /* enum mmal_msg_port_type */
-       u32 index;             /* port indexed in query */
-       s32 found;             /* unused */
-       u32 port_handle;               /**< Handle to use for this port */
+       u32 component_handle;   /* component handle port is associated with */
+       u32 port_type;          /* enum mmal_msg_port_type */
+       u32 index;              /* port indexed in query */
+       s32 found;              /* unused */
+       u32 port_handle;        /* Handle to use for this port */
        struct mmal_port port;
        struct mmal_es_format format;
        union mmal_es_specific_format es;
@@ -191,7 +195,7 @@ struct mmal_msg_port_info_set_reply {
 struct mmal_msg_port_action_port {
        u32 component_handle;
        u32 port_handle;
-       u32 action; /* enum mmal_msg_port_action_type */
+       u32 action;             /* enum mmal_msg_port_action_type */
        struct mmal_port port;
 };
 
@@ -199,50 +203,54 @@ struct mmal_msg_port_action_port {
 struct mmal_msg_port_action_handle {
        u32 component_handle;
        u32 port_handle;
-       u32 action; /* enum mmal_msg_port_action_type */
+       u32 action;             /* enum mmal_msg_port_action_type */
        u32 connect_component_handle;
        u32 connect_port_handle;
 };
 
 struct mmal_msg_port_action_reply {
-       u32 status; /** The port action operation status */
+       u32 status;     /* The port action operation status */
 };
 
 /* MMAL buffer transfer */
 
-/** Size of space reserved in a buffer message for short messages. */
+/* Size of space reserved in a buffer message for short messages. */
 #define MMAL_VC_SHORT_DATA 128
 
-/** Signals that the current payload is the end of the stream of data */
+/* Signals that the current payload is the end of the stream of data */
 #define MMAL_BUFFER_HEADER_FLAG_EOS                    BIT(0)
-/** Signals that the start of the current payload starts a frame */
+/* Signals that the start of the current payload starts a frame */
 #define MMAL_BUFFER_HEADER_FLAG_FRAME_START            BIT(1)
-/** Signals that the end of the current payload ends a frame */
+/* Signals that the end of the current payload ends a frame */
 #define MMAL_BUFFER_HEADER_FLAG_FRAME_END              BIT(2)
-/** Signals that the current payload contains only complete frames (>1) */
+/* Signals that the current payload contains only complete frames (>1) */
 #define MMAL_BUFFER_HEADER_FLAG_FRAME                  \
-       (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
-/** Signals that the current payload is a keyframe (i.e. self decodable) */
+       (MMAL_BUFFER_HEADER_FLAG_FRAME_START | \
+        MMAL_BUFFER_HEADER_FLAG_FRAME_END)
+/* Signals that the current payload is a keyframe (i.e. self decodable) */
 #define MMAL_BUFFER_HEADER_FLAG_KEYFRAME               BIT(3)
-/** Signals a discontinuity in the stream of data (e.g. after a seek).
+/*
+ * Signals a discontinuity in the stream of data (e.g. after a seek).
  * Can be used for instance by a decoder to reset its state
  */
 #define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY          BIT(4)
-/** Signals a buffer containing some kind of config data for the component
+/*
+ * Signals a buffer containing some kind of config data for the component
  * (e.g. codec config data)
  */
 #define MMAL_BUFFER_HEADER_FLAG_CONFIG                 BIT(5)
-/** Signals an encrypted payload */
+/* Signals an encrypted payload */
 #define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED              BIT(6)
-/** Signals a buffer containing side information */
+/* Signals a buffer containing side information */
 #define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO          BIT(7)
-/** Signals a buffer which is the snapshot/postview image from a stills
+/*
+ * Signals a buffer which is the snapshot/postview image from a stills
  * capture
  */
 #define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT              BIT(8)
-/** Signals a buffer which contains data known to be corrupted */
+/* Signals a buffer which contains data known to be corrupted */
 #define MMAL_BUFFER_HEADER_FLAG_CORRUPTED              BIT(9)
-/** Signals that a buffer failed to be transmitted */
+/* Signals that a buffer failed to be transmitted */
 #define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED    BIT(10)
 
 struct mmal_driver_buffer {
@@ -254,8 +262,8 @@ struct mmal_driver_buffer {
 
 /* buffer header */
 struct mmal_buffer_header {
-       u32 next; /* next header */
-       u32 priv; /* framework private data */
+       u32 next;       /* next header */
+       u32 priv;       /* framework private data */
        u32 cmd;
        u32 data;
        u32 alloc_size;
@@ -280,7 +288,8 @@ struct mmal_buffer_header_type_specific {
 };
 
 struct mmal_msg_buffer_from_host {
-       /* The front 32 bytes of the buffer header are copied
+       /*
+        *The front 32 bytes of the buffer header are copied
         * back to us in the reply to allow for context. This
         * area is used to store two mmal_driver_buffer structures to
         * allow for multiple concurrent service users.
@@ -295,7 +304,7 @@ struct mmal_msg_buffer_from_host {
        s32 is_zero_copy;
        s32 has_reference;
 
-       /** allows short data to be xfered in control message */
+       /* allows short data to be xfered in control message */
        u32 payload_in_message;
        u8 short_data[MMAL_VC_SHORT_DATA];
 };
@@ -305,11 +314,11 @@ struct mmal_msg_buffer_from_host {
 #define MMAL_WORKER_PORT_PARAMETER_SPACE      96
 
 struct mmal_msg_port_parameter_set {
-       u32 component_handle; /* component */
-       u32 port_handle;      /* port */
-       u32 id;     /* Parameter ID  */
-       u32 size;      /* Parameter size */
-       uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
+       u32 component_handle;   /* component */
+       u32 port_handle;        /* port */
+       u32 id;                 /* Parameter ID  */
+       u32 size;               /* Parameter size */
+       u32 value[MMAL_WORKER_PORT_PARAMETER_SPACE];
 };
 
 struct mmal_msg_port_parameter_set_reply {
@@ -321,24 +330,24 @@ struct mmal_msg_port_parameter_set_reply {
 /* port parameter getting */
 
 struct mmal_msg_port_parameter_get {
-       u32 component_handle; /* component */
-       u32 port_handle;      /* port */
-       u32 id;     /* Parameter ID  */
-       u32 size;      /* Parameter size */
+       u32 component_handle;   /* component */
+       u32 port_handle;        /* port */
+       u32 id;                 /* Parameter ID  */
+       u32 size;               /* Parameter size */
 };
 
 struct mmal_msg_port_parameter_get_reply {
-       u32 status;           /* Status of mmal_port_parameter_get call */
-       u32 id;     /* Parameter ID  */
-       u32 size;      /* Parameter size */
-       uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
+       u32 status;             /* Status of mmal_port_parameter_get call */
+       u32 id;                 /* Parameter ID  */
+       u32 size;               /* Parameter size */
+       u32 value[MMAL_WORKER_PORT_PARAMETER_SPACE];
 };
 
 /* event messages */
 #define MMAL_WORKER_EVENT_SPACE 256
 
 struct mmal_msg_event_to_host {
-       u32 client_component; /* component context */
+       u32 client_component;   /* component context */
 
        u32 port_type;
        u32 port_num;
@@ -394,3 +403,4 @@ struct mmal_msg {
                u8 payload[MMAL_MSG_MAX_PAYLOAD];
        } u;
 };
+#endif
index 184024dfb8b71f08beda279d4f9297e0f875dfa6..80a99128f5f3e97429e90dd3acebc439b59b605a 100644 (file)
@@ -4,10 +4,11 @@
  *
  * Copyright Â© 2013 Raspberry Pi (Trading) Ltd.
  *
- * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
- *          Dave Stevenson <dsteve@broadcom.com>
- *          Simon Mellor <simellor@broadcom.com>
- *          Luke Diamand <luked@broadcom.com>
+ * Authors: Vincent Sanders @ Collabora
+ *          Dave Stevenson @ Broadcom
+ *             (now dave.stevenson@raspberrypi.org)
+ *          Simon Mellor @ Broadcom
+ *          Luke Diamand @ Broadcom
  */
 
 /* common parameters */
  * @{
  */
 
-#ifndef __MMAL_PARAMETERS_H
-#define __MMAL_PARAMETERS_H
+#ifndef MMAL_PARAMETERS_H
+#define MMAL_PARAMETERS_H
 
 /** Common parameter ID group, used with many types of component. */
-#define MMAL_PARAMETER_GROUP_COMMON            (0<<16)
+#define MMAL_PARAMETER_GROUP_COMMON            (0 << 16)
 /** Camera-specific parameter ID group. */
-#define MMAL_PARAMETER_GROUP_CAMERA            (1<<16)
+#define MMAL_PARAMETER_GROUP_CAMERA            (1 << 16)
 /** Video-specific parameter ID group. */
-#define MMAL_PARAMETER_GROUP_VIDEO             (2<<16)
+#define MMAL_PARAMETER_GROUP_VIDEO             (2 << 16)
 /** Audio-specific parameter ID group. */
-#define MMAL_PARAMETER_GROUP_AUDIO             (3<<16)
+#define MMAL_PARAMETER_GROUP_AUDIO             (3 << 16)
 /** Clock-specific parameter ID group. */
-#define MMAL_PARAMETER_GROUP_CLOCK             (4<<16)
+#define MMAL_PARAMETER_GROUP_CLOCK             (4 << 16)
 /** Miracast-specific parameter ID group. */
-#define MMAL_PARAMETER_GROUP_MIRACAST       (5<<16)
+#define MMAL_PARAMETER_GROUP_MIRACAST       (5 << 16)
 
 /* Common parameters */
 enum mmal_parameter_common_type {
-       MMAL_PARAMETER_UNUSED  /**< Never a valid parameter ID */
-               = MMAL_PARAMETER_GROUP_COMMON,
-       MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
-       MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
-
-       /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
+               /**< Never a valid parameter ID */
+       MMAL_PARAMETER_UNUSED = MMAL_PARAMETER_GROUP_COMMON,
+
+               /**< MMAL_PARAMETER_ENCODING_T */
+       MMAL_PARAMETER_SUPPORTED_ENCODINGS,
+               /**< MMAL_PARAMETER_URI_T */
+       MMAL_PARAMETER_URI,
+               /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
        MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
-
-       /** MMAL_PARAMETER_BOOLEAN_T */
+               /** MMAL_PARAMETER_BOOLEAN_T */
        MMAL_PARAMETER_ZERO_COPY,
-
-       /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
+               /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
        MMAL_PARAMETER_BUFFER_REQUIREMENTS,
-
-       MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
-       MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
-       MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
-       MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
-       MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
-       MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
-       MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
-       MMAL_PARAMETER_SYSTEM_TIME, /**< MMAL_PARAMETER_UINT64_T */
-       MMAL_PARAMETER_NO_IMAGE_PADDING  /**< MMAL_PARAMETER_BOOLEAN_T */
+               /**< MMAL_PARAMETER_STATISTICS_T */
+       MMAL_PARAMETER_STATISTICS,
+               /**< MMAL_PARAMETER_CORE_STATISTICS_T */
+       MMAL_PARAMETER_CORE_STATISTICS,
+               /**< MMAL_PARAMETER_MEM_USAGE_T */
+       MMAL_PARAMETER_MEM_USAGE,
+               /**< MMAL_PARAMETER_UINT32_T */
+       MMAL_PARAMETER_BUFFER_FLAG_FILTER,
+               /**< MMAL_PARAMETER_SEEK_T */
+       MMAL_PARAMETER_SEEK,
+               /**< MMAL_PARAMETER_BOOLEAN_T */
+       MMAL_PARAMETER_POWERMON_ENABLE,
+               /**< MMAL_PARAMETER_LOGGING_T */
+       MMAL_PARAMETER_LOGGING,
+               /**< MMAL_PARAMETER_UINT64_T */
+       MMAL_PARAMETER_SYSTEM_TIME,
+               /**< MMAL_PARAMETER_BOOLEAN_T */
+       MMAL_PARAMETER_NO_IMAGE_PADDING,
 };
 
 /* camera parameters */
 
 enum mmal_parameter_camera_type {
        /* 0 */
-       /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
-       MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
-               = MMAL_PARAMETER_GROUP_CAMERA,
-       MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
-       MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
-       MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
-       MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
-       MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
-       MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
-       MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
-       MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
-       MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
-       MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
-       MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
-       MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
-       MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
-       MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
-       MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
+               /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
+       MMAL_PARAMETER_THUMBNAIL_CONFIGURATION =
+               MMAL_PARAMETER_GROUP_CAMERA,
+               /**< Unused? */
+       MMAL_PARAMETER_CAPTURE_QUALITY,
+               /**< @ref MMAL_PARAMETER_INT32_T */
+       MMAL_PARAMETER_ROTATION,
+               /**< @ref MMAL_PARAMETER_BOOLEAN_T */
+       MMAL_PARAMETER_EXIF_DISABLE,
+               /**< @ref MMAL_PARAMETER_EXIF_T */
+       MMAL_PARAMETER_EXIF,
+               /**< @ref MMAL_PARAM_AWBMODE_T */
+       MMAL_PARAMETER_AWB_MODE,
+               /**< @ref MMAL_PARAMETER_IMAGEFX_T */
+       MMAL_PARAMETER_IMAGE_EFFECT,
+               /**< @ref MMAL_PARAMETER_COLOURFX_T */
+       MMAL_PARAMETER_COLOUR_EFFECT,
+               /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
+       MMAL_PARAMETER_FLICKER_AVOID,
+               /**< @ref MMAL_PARAMETER_FLASH_T */
+       MMAL_PARAMETER_FLASH,
+               /**< @ref MMAL_PARAMETER_REDEYE_T */
+       MMAL_PARAMETER_REDEYE,
+               /**< @ref MMAL_PARAMETER_FOCUS_T */
+       MMAL_PARAMETER_FOCUS,
+               /**< Unused? */
+       MMAL_PARAMETER_FOCAL_LENGTHS,
+               /**< @ref MMAL_PARAMETER_INT32_T */
+       MMAL_PARAMETER_EXPOSURE_COMP,
+               /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
+       MMAL_PARAMETER_ZOOM,
+               /**< @ref MMAL_PARAMETER_MIRROR_T */
+       MMAL_PARAMETER_MIRROR,
 
        /* 0x10 */
-       MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
-       MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
-       MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
-       MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
-       MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
-       MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
-       MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
-       MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
-       MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
-       MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
-       MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
-       MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
-       MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
-       MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
-       MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
-       MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
+               /**< @ref MMAL_PARAMETER_UINT32_T */
+       MMAL_PARAMETER_CAMERA_NUM,
+               /**< @ref MMAL_PARAMETER_BOOLEAN_T */
+       MMAL_PARAMETER_CAPTURE,
+               /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
+       MMAL_PARAMETER_EXPOSURE_MODE,
+               /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
+       MMAL_PARAMETER_EXP_METERING_MODE,
+               /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
+       MMAL_PARAMETER_FOCUS_STATUS,
+               /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
+       MMAL_PARAMETER_CAMERA_CONFIG,
+               /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
+       MMAL_PARAMETER_CAPTURE_STATUS,
+               /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
+       MMAL_PARAMETER_FACE_TRACK,
+               /**< @ref MMAL_PARAMETER_BOOLEAN_T */
+       MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS,
+               /**< @ref MMAL_PARAMETER_UINT32_T */
+       MMAL_PARAMETER_JPEG_Q_FACTOR,
+               /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
+       MMAL_PARAMETER_FRAME_RATE,
+               /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
+       MMAL_PARAMETER_USE_STC,
+               /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
+       MMAL_PARAMETER_CAMERA_INFO,
+               /**< @ref MMAL_PARAMETER_BOOLEAN_T */
+       MMAL_PARAMETER_VIDEO_STABILISATION,
+               /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
+       MMAL_PARAMETER_FACE_TRACK_RESULTS,
+               /**< @ref MMAL_PARAMETER_BOOLEAN_T */
+       MMAL_PARAMETER_ENABLE_RAW_CAPTURE,
 
        /* 0x20 */
-       MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
-       MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
-       MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
-       MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
-       MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
-       MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
-       MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
-       MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
-       MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
-       MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
-       MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
-       MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
-       MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
-       MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
-       MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
-       MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
+               /**< @ref MMAL_PARAMETER_URI_T */
+       MMAL_PARAMETER_DPF_FILE,
+               /**< @ref MMAL_PARAMETER_BOOLEAN_T */
+       MMAL_PARAMETER_ENABLE_DPF_FILE,
+               /**< @ref MMAL_PARAMETER_BOOLEAN_T */
+       MMAL_PARAMETER_DPF_FAIL_IS_FATAL,
+               /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
+       MMAL_PARAMETER_CAPTURE_MODE,
+               /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
+       MMAL_PARAMETER_FOCUS_REGIONS,
+               /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
+       MMAL_PARAMETER_INPUT_CROP,
+               /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
+       MMAL_PARAMETER_SENSOR_INFORMATION,
+               /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
+       MMAL_PARAMETER_FLASH_SELECT,
+               /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
+       MMAL_PARAMETER_FIELD_OF_VIEW,
+               /**< @ref MMAL_PARAMETER_BOOLEAN_T */
+       MMAL_PARAMETER_HIGH_DYNAMIC_RANGE,
+               /**< @ref MMAL_PARAMETER_DRC_T */
+       MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION,
+               /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
+       MMAL_PARAMETER_ALGORITHM_CONTROL,
+               /**< @ref MMAL_PARAMETER_RATIONAL_T */
+       MMAL_PARAMETER_SHARPNESS,
+               /**< @ref MMAL_PARAMETER_RATIONAL_T */
+       MMAL_PARAMETER_CONTRAST,
+               /**< @ref MMAL_PARAMETER_RATIONAL_T */
+       MMAL_PARAMETER_BRIGHTNESS,
+               /**< @ref MMAL_PARAMETER_RATIONAL_T */
+       MMAL_PARAMETER_SATURATION,
 
        /* 0x30 */
-       MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
-       MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
-
-       /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
+               /**< @ref MMAL_PARAMETER_UINT32_T */
+       MMAL_PARAMETER_ISO,
+               /**< @ref MMAL_PARAMETER_BOOLEAN_T */
+       MMAL_PARAMETER_ANTISHAKE,
+               /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
        MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
-
-       /** @ref MMAL_PARAMETER_BOOLEAN_T */
+               /** @ref MMAL_PARAMETER_BOOLEAN_T */
        MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
-
-       /** @ref MMAL_PARAMETER_UINT32_T */
+               /** @ref MMAL_PARAMETER_UINT32_T */
        MMAL_PARAMETER_CAMERA_MIN_ISO,
-
-       /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
+               /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
        MMAL_PARAMETER_CAMERA_USE_CASE,
-
-       /**< @ref MMAL_PARAMETER_BOOLEAN_T */
+               /**< @ref MMAL_PARAMETER_BOOLEAN_T */
        MMAL_PARAMETER_CAPTURE_STATS_PASS,
-
-       /** @ref MMAL_PARAMETER_UINT32_T */
+               /** @ref MMAL_PARAMETER_UINT32_T */
        MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
-
-       /** @ref MMAL_PARAMETER_BOOLEAN_T */
+               /** @ref MMAL_PARAMETER_BOOLEAN_T */
        MMAL_PARAMETER_ENABLE_REGISTER_FILE,
-
-       /** @ref MMAL_PARAMETER_BOOLEAN_T */
+               /** @ref MMAL_PARAMETER_BOOLEAN_T */
        MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
-
-       /** @ref MMAL_PARAMETER_CONFIGFILE_T */
+               /** @ref MMAL_PARAMETER_CONFIGFILE_T */
        MMAL_PARAMETER_CONFIGFILE_REGISTERS,
-
-       /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
+               /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
        MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
-       MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
-       MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
-       MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
-       MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
+               /**< @ref MMAL_PARAMETER_BOOLEAN_T */
+       MMAL_PARAMETER_JPEG_ATTACH_LOG,
+               /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
+       MMAL_PARAMETER_ZERO_SHUTTER_LAG,
+               /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
+       MMAL_PARAMETER_FPS_RANGE,
+               /**< @ref MMAL_PARAMETER_INT32_T */
+       MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP,
 
        /* 0x40 */
-       MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
-       MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
-       MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
-       MMAL_PARAMETER_SHUTTER_SPEED,             /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
-       MMAL_PARAMETER_CUSTOM_AWB_GAINS,          /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */
+               /**< @ref MMAL_PARAMETER_BOOLEAN_T */
+       MMAL_PARAMETER_SW_SHARPEN_DISABLE,
+               /**< @ref MMAL_PARAMETER_BOOLEAN_T */
+       MMAL_PARAMETER_FLASH_REQUIRED,
+               /**< @ref MMAL_PARAMETER_BOOLEAN_T */
+       MMAL_PARAMETER_SW_SATURATION_DISABLE,
+               /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
+       MMAL_PARAMETER_SHUTTER_SPEED,
+               /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */
+       MMAL_PARAMETER_CUSTOM_AWB_GAINS,
 };
 
 struct mmal_parameter_rational {
@@ -410,7 +467,8 @@ enum mmal_parameter_video_type {
        MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
 
        /** @ref MMAL_PARAMETER_UINT32_T.
-        * Setting the value to zero resets to the default (one slice per frame).
+        * Setting the value to zero resets to the default (one slice per
+        * frame).
         */
        MMAL_PARAMETER_MB_ROWS_PER_SLICE,
 
index 16af735af5c359defe7001e90afcd08a95e32c8c..1c180ead4a20b58416f765ad811d425d2c32e94d 100644 (file)
@@ -4,10 +4,11 @@
  *
  * Copyright Â© 2013 Raspberry Pi (Trading) Ltd.
  *
- * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
- *          Dave Stevenson <dsteve@broadcom.com>
- *          Simon Mellor <simellor@broadcom.com>
- *          Luke Diamand <luked@broadcom.com>
+ * Authors: Vincent Sanders @ Collabora
+ *          Dave Stevenson @ Broadcom
+ *             (now dave.stevenson@raspberrypi.org)
+ *          Simon Mellor @ Broadcom
+ *          Luke Diamand @ Broadcom
  *
  * V4L2 driver MMAL vchiq interface code
  */
@@ -117,8 +118,10 @@ struct mmal_msg_context {
 
        union {
                struct {
-                       /* work struct for defered callback - must come first */
+                       /* work struct for buffer_cb callback */
                        struct work_struct work;
+                       /* work struct for deferred callback */
+                       struct work_struct buffer_to_host_work;
                        /* mmal instance */
                        struct vchiq_mmal_instance *instance;
                        /* mmal port */
@@ -161,11 +164,15 @@ struct vchiq_mmal_instance {
        void *bulk_scratch;
 
        struct idr context_map;
-       spinlock_t context_map_lock;
+       /* protect accesses to context_map */
+       struct mutex context_map_lock;
 
        /* component to use next */
        int component_idx;
        struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
+
+       /* ordered workqueue to process all bulk operations */
+       struct workqueue_struct *bulk_wq;
 };
 
 static struct mmal_msg_context *
@@ -184,10 +191,10 @@ get_msg_context(struct vchiq_mmal_instance *instance)
         * that when we service the VCHI reply, we can look up what
         * message is being replied to.
         */
-       spin_lock(&instance->context_map_lock);
+       mutex_lock(&instance->context_map_lock);
        handle = idr_alloc(&instance->context_map, msg_context,
                           0, 0, GFP_KERNEL);
-       spin_unlock(&instance->context_map_lock);
+       mutex_unlock(&instance->context_map_lock);
 
        if (handle < 0) {
                kfree(msg_context);
@@ -211,9 +218,9 @@ release_msg_context(struct mmal_msg_context *msg_context)
 {
        struct vchiq_mmal_instance *instance = msg_context->instance;
 
-       spin_lock(&instance->context_map_lock);
+       mutex_lock(&instance->context_map_lock);
        idr_remove(&instance->context_map, msg_context->handle);
-       spin_unlock(&instance->context_map_lock);
+       mutex_unlock(&instance->context_map_lock);
        kfree(msg_context);
 }
 
@@ -239,6 +246,8 @@ static void buffer_work_cb(struct work_struct *work)
        struct mmal_msg_context *msg_context =
                container_of(work, struct mmal_msg_context, u.bulk.work);
 
+       atomic_dec(&msg_context->u.bulk.port->buffers_with_vpu);
+
        msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
                                            msg_context->u.bulk.port,
                                            msg_context->u.bulk.status,
@@ -247,7 +256,44 @@ static void buffer_work_cb(struct work_struct *work)
                                            msg_context->u.bulk.mmal_flags,
                                            msg_context->u.bulk.dts,
                                            msg_context->u.bulk.pts);
+}
+
+/* workqueue scheduled callback to handle receiving buffers
+ *
+ * VCHI will allow up to 4 bulk receives to be scheduled before blocking.
+ * If we block in the service_callback context then we can't process the
+ * VCHI_CALLBACK_BULK_RECEIVED message that would otherwise allow the blocked
+ * vchi_bulk_queue_receive() call to complete.
+ */
+static void buffer_to_host_work_cb(struct work_struct *work)
+{
+       struct mmal_msg_context *msg_context =
+               container_of(work, struct mmal_msg_context,
+                            u.bulk.buffer_to_host_work);
+       struct vchiq_mmal_instance *instance = msg_context->instance;
+       unsigned long len = msg_context->u.bulk.buffer_used;
+       int ret;
 
+       if (!len)
+               /* Dummy receive to ensure the buffers remain in order */
+               len = 8;
+       /* queue the bulk submission */
+       vchi_service_use(instance->handle);
+       ret = vchi_bulk_queue_receive(instance->handle,
+                                     msg_context->u.bulk.buffer->buffer,
+                                     /* Actual receive needs to be a multiple
+                                      * of 4 bytes
+                                      */
+                                     (len + 3) & ~3,
+                                     VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
+                                     VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
+                                     msg_context);
+
+       vchi_service_release(instance->handle);
+
+       if (ret != 0)
+               pr_err("%s: ctx: %p, vchi_bulk_queue_receive failed %d\n",
+                      __func__, msg_context, ret);
 }
 
 /* enqueue a bulk receive for a given message context */
@@ -256,7 +302,6 @@ static int bulk_receive(struct vchiq_mmal_instance *instance,
                        struct mmal_msg_context *msg_context)
 {
        unsigned long rd_len;
-       int ret;
 
        rd_len = msg->u.buffer_from_host.buffer_header.length;
 
@@ -287,50 +332,13 @@ static int bulk_receive(struct vchiq_mmal_instance *instance,
 
        /* store length */
        msg_context->u.bulk.buffer_used = rd_len;
-       msg_context->u.bulk.mmal_flags =
-           msg->u.buffer_from_host.buffer_header.flags;
        msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
        msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
 
-       /* queue the bulk submission */
-       vchi_service_use(instance->handle);
-       ret = vchi_bulk_queue_receive(instance->handle,
-                                     msg_context->u.bulk.buffer->buffer,
-                                     /* Actual receive needs to be a multiple
-                                      * of 4 bytes
-                                      */
-                                     (rd_len + 3) & ~3,
-                                     VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
-                                     VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
-                                     msg_context);
-
-       vchi_service_release(instance->handle);
-
-       return ret;
-}
-
-/* enque a dummy bulk receive for a given message context */
-static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
-                             struct mmal_msg_context *msg_context)
-{
-       int ret;
-
-       /* zero length indicates this was a dummy transfer */
-       msg_context->u.bulk.buffer_used = 0;
-
-       /* queue the bulk submission */
-       vchi_service_use(instance->handle);
-
-       ret = vchi_bulk_queue_receive(instance->handle,
-                                     instance->bulk_scratch,
-                                     8,
-                                     VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
-                                     VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
-                                     msg_context);
+       queue_work(msg_context->instance->bulk_wq,
+                  &msg_context->u.bulk.buffer_to_host_work);
 
-       vchi_service_release(instance->handle);
-
-       return ret;
+       return 0;
 }
 
 /* data in message, memcpy from packet into output buffer */
@@ -378,6 +386,10 @@ buffer_from_host(struct vchiq_mmal_instance *instance,
 
        /* initialise work structure ready to schedule callback */
        INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
+       INIT_WORK(&msg_context->u.bulk.buffer_to_host_work,
+                 buffer_to_host_work_cb);
+
+       atomic_inc(&port->buffers_with_vpu);
 
        /* prep the buffer from host message */
        memset(&m, 0xbc, sizeof(m));    /* just to make debug clearer */
@@ -447,6 +459,9 @@ static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
                return;
        }
 
+       msg_context->u.bulk.mmal_flags =
+                               msg->u.buffer_from_host.buffer_header.flags;
+
        if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
                /* message reception had an error */
                pr_warn("error %d in reply\n", msg->h.status);
@@ -458,7 +473,7 @@ static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
                if (msg->u.buffer_from_host.buffer_header.flags &
                    MMAL_BUFFER_HEADER_FLAG_EOS) {
                        msg_context->u.bulk.status =
-                           dummy_bulk_receive(instance, msg_context);
+                           bulk_receive(instance, msg, msg_context);
                        if (msg_context->u.bulk.status == 0)
                                return; /* successful bulk submission, bulk
                                         * completion will trigger callback
@@ -635,7 +650,7 @@ static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
        if (payload_len >
            (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
                pr_err("payload length %d exceeds max:%d\n", payload_len,
-                     (int)(MMAL_MSG_MAX_SIZE -
+                      (int)(MMAL_MSG_MAX_SIZE -
                            sizeof(struct mmal_msg_header)));
                return -EINVAL;
        }
@@ -838,9 +853,9 @@ static int port_info_get(struct vchiq_mmal_instance *instance,
                goto release_msg;
 
        if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
-               port->enabled = false;
+               port->enabled = 0;
        else
-               port->enabled = true;
+               port->enabled = 1;
 
        /* copy the values out of the message */
        port->handle = rmsg->u.port_info_get_reply.port_handle;
@@ -1252,9 +1267,10 @@ static int port_parameter_get(struct vchiq_mmal_instance *instance,
                memcpy(value, &rmsg->u.port_parameter_get_reply.value,
                       *value_size);
                *value_size = rmsg->u.port_parameter_get_reply.size;
-       } else
+       } else {
                memcpy(value, &rmsg->u.port_parameter_get_reply.value,
                       rmsg->u.port_parameter_get_reply.size);
+       }
 
        pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
                 ret, port->component->handle, port->handle, parameter_id);
@@ -1276,7 +1292,7 @@ static int port_disable(struct vchiq_mmal_instance *instance,
        if (!port->enabled)
                return 0;
 
-       port->enabled = false;
+       port->enabled = 0;
 
        ret = port_action_port(instance, port,
                               MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
@@ -1323,22 +1339,12 @@ static int port_enable(struct vchiq_mmal_instance *instance,
        if (port->enabled)
                return 0;
 
-       /* ensure there are enough buffers queued to cover the buffer headers */
-       if (port->buffer_cb) {
-               hdr_count = 0;
-               list_for_each(buf_head, &port->buffers) {
-                       hdr_count++;
-               }
-               if (hdr_count < port->current_buffer.num)
-                       return -ENOSPC;
-       }
-
        ret = port_action_port(instance, port,
                               MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
        if (ret)
                goto done;
 
-       port->enabled = true;
+       port->enabled = 1;
 
        if (port->buffer_cb) {
                /* send buffer headers to videocore */
@@ -1505,7 +1511,7 @@ int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
                        pr_err("failed disconnecting src port\n");
                        goto release_unlock;
                }
-               src->connected->enabled = false;
+               src->connected->enabled = 0;
                src->connected = NULL;
        }
 
@@ -1752,7 +1758,7 @@ int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
 
        ret = disable_component(instance, component);
        if (ret == 0)
-               component->enabled = false;
+               component->enabled = 0;
 
        mutex_unlock(&instance->vchiq_mutex);
 
@@ -1792,6 +1798,9 @@ int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
 
        mutex_unlock(&instance->vchiq_mutex);
 
+       flush_workqueue(instance->bulk_wq);
+       destroy_workqueue(instance->bulk_wq);
+
        vfree(instance->bulk_scratch);
 
        idr_destroy(&instance->context_map);
@@ -1849,11 +1858,16 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
 
        instance->bulk_scratch = vmalloc(PAGE_SIZE);
 
-       spin_lock_init(&instance->context_map_lock);
+       mutex_init(&instance->context_map_lock);
        idr_init_base(&instance->context_map, 1);
 
        params.callback_param = instance;
 
+       instance->bulk_wq = alloc_ordered_workqueue("mmal-vchiq",
+                                                   WQ_MEM_RECLAIM);
+       if (!instance->bulk_wq)
+               goto err_free;
+
        status = vchi_service_open(vchi_instance, &params, &instance->handle);
        if (status) {
                pr_err("Failed to open VCHI service connection (status=%d)\n",
@@ -1868,8 +1882,9 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
        return 0;
 
 err_close_services:
-
        vchi_service_close(instance->handle);
+       destroy_workqueue(instance->bulk_wq);
+err_free:
        vfree(instance->bulk_scratch);
        kfree(instance);
        return -ENODEV;
index 22b839ecd5f02471f3cb2918436529d05d595064..f738e7f99e96e927f9764d1577a52511f74a4aa3 100644 (file)
@@ -4,10 +4,11 @@
  *
  * Copyright Â© 2013 Raspberry Pi (Trading) Ltd.
  *
- * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
- *          Dave Stevenson <dsteve@broadcom.com>
- *          Simon Mellor <simellor@broadcom.com>
- *          Luke Diamand <luked@broadcom.com>
+ * Authors: Vincent Sanders @ Collabora
+ *          Dave Stevenson @ Broadcom
+ *             (now dave.stevenson@raspberrypi.org)
+ *          Simon Mellor @ Broadcom
+ *          Luke Diamand @ Broadcom
  *
  * MMAL interface to VCHIQ message passing
  */
@@ -47,7 +48,7 @@ typedef void (*vchiq_mmal_buffer_cb)(
                unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
 
 struct vchiq_mmal_port {
-       bool enabled;
+       u32 enabled:1;
        u32 handle;
        u32 type; /* port type, cached to use on port info set */
        u32 index; /* port index, cached to use on port info set */
@@ -71,6 +72,9 @@ struct vchiq_mmal_port {
        struct list_head buffers;
        /* lock to serialise adding and removing buffers from list */
        spinlock_t slock;
+
+       /* Count of buffers the VPU has yet to return */
+       atomic_t buffers_with_vpu;
        /* callback on buffer completion */
        vchiq_mmal_buffer_cb buffer_cb;
        /* callback context */
@@ -78,7 +82,7 @@ struct vchiq_mmal_port {
 };
 
 struct vchiq_mmal_component {
-       bool enabled;
+       u32 enabled:1;
        u32 handle;  /* VideoCore handle for component */
        u32 inputs;  /* Number of input ports */
        u32 outputs; /* Number of output ports */
@@ -127,7 +131,7 @@ int vchiq_mmal_port_enable(
  * disable a port will dequeue any pending buffers
  */
 int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
-                          struct vchiq_mmal_port *port);
+                           struct vchiq_mmal_port *port);
 
 int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
                                  struct vchiq_mmal_port *port,
@@ -145,8 +149,8 @@ int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
                               struct vchiq_mmal_port *port);
 
 int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
-                           struct vchiq_mmal_port *src,
-                           struct vchiq_mmal_port *dst);
+                                  struct vchiq_mmal_port *src,
+                                  struct vchiq_mmal_port *dst);
 
 int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
                       u32 *major_out,
index c557c9953724783d5ff61cc51f146639336cd6e8..61c69f353cdb043107b8d64d60a2beb88d78fed9 100644 (file)
@@ -523,7 +523,7 @@ create_pagelist(char __user *buf, size_t count, unsigned short type)
                (g_cache_line_size - 1)))) {
                char *fragments;
 
-               if (down_killable(&g_free_fragments_sema)) {
+               if (down_interruptible(&g_free_fragments_sema)) {
                        cleanup_pagelistinfo(pagelistinfo);
                        return NULL;
                }
index ab7d6a0ce94cacfc92a8b28f3f2bbb5e33718aa4..cc4383d1ec3eabe033037d517d4dbb3e9ed26b2a 100644 (file)
@@ -238,7 +238,7 @@ VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance)
        vchiq_log_trace(vchiq_core_log_level,
                "%s(%p) called", __func__, instance);
 
-       if (mutex_lock_killable(&state->mutex) != 0)
+       if (mutex_lock_killable(&state->mutex))
                return VCHIQ_RETRY;
 
        /* Remove all services */
@@ -280,7 +280,7 @@ VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance)
        vchiq_log_trace(vchiq_core_log_level,
                "%s(%p) called", __func__, instance);
 
-       if (mutex_lock_killable(&state->mutex) != 0) {
+       if (mutex_lock_killable(&state->mutex)) {
                vchiq_log_trace(vchiq_core_log_level,
                        "%s: call to mutex_lock failed", __func__);
                status = VCHIQ_RETRY;
@@ -532,7 +532,8 @@ add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
                vchiq_log_trace(vchiq_arm_log_level,
                        "%s - completion queue full", __func__);
                DEBUG_COUNT(COMPLETION_QUEUE_FULL_COUNT);
-               if (wait_for_completion_killable(&instance->remove_event)) {
+               if (wait_for_completion_interruptible(
+                                       &instance->remove_event)) {
                        vchiq_log_info(vchiq_arm_log_level,
                                "service_callback interrupted");
                        return VCHIQ_RETRY;
@@ -643,9 +644,8 @@ service_callback(VCHIQ_REASON_T reason, struct vchiq_header *header,
                        }
 
                        DEBUG_TRACE(SERVICE_CALLBACK_LINE);
-                       if (wait_for_completion_killable(
-                                               &user_service->remove_event)
-                               != 0) {
+                       if (wait_for_completion_interruptible(
+                                               &user_service->remove_event)) {
                                vchiq_log_info(vchiq_arm_log_level,
                                        "%s interrupted", __func__);
                                DEBUG_TRACE(SERVICE_CALLBACK_LINE);
@@ -849,7 +849,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                        break;
                }
                rc = mutex_lock_killable(&instance->state->mutex);
-               if (rc != 0) {
+               if (rc) {
                        vchiq_log_error(vchiq_arm_log_level,
                                "vchiq: connect: could not lock mutex for "
                                "state %d: %d",
@@ -873,9 +873,8 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                void *userdata;
                int srvstate;
 
-               if (copy_from_user
-                        (&args, (const void __user *)arg,
-                         sizeof(args)) != 0) {
+               if (copy_from_user(&args, (const void __user *)arg,
+                                  sizeof(args))) {
                        ret = -EFAULT;
                        break;
                }
@@ -939,7 +938,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                                &(((struct vchiq_create_service __user *)
                                        arg)->handle),
                                (const void *)&service->handle,
-                               sizeof(service->handle)) != 0) {
+                               sizeof(service->handle))) {
                                ret = -EFAULT;
                                vchiq_remove_service(service->handle);
                        }
@@ -978,7 +977,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                   has been closed until the client library calls the
                   CLOSE_DELIVERED ioctl, signalling close_event. */
                if (user_service->close_pending &&
-                       wait_for_completion_killable(
+                       wait_for_completion_interruptible(
                                &user_service->close_event))
                        status = VCHIQ_RETRY;
                break;
@@ -1014,9 +1013,8 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        case VCHIQ_IOC_QUEUE_MESSAGE: {
                struct vchiq_queue_message args;
 
-               if (copy_from_user
-                        (&args, (const void __user *)arg,
-                         sizeof(args)) != 0) {
+               if (copy_from_user(&args, (const void __user *)arg,
+                                  sizeof(args))) {
                        ret = -EFAULT;
                        break;
                }
@@ -1048,9 +1046,8 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                        (cmd == VCHIQ_IOC_QUEUE_BULK_TRANSMIT) ?
                        VCHIQ_BULK_TRANSMIT : VCHIQ_BULK_RECEIVE;
 
-               if (copy_from_user
-                       (&args, (const void __user *)arg,
-                       sizeof(args)) != 0) {
+               if (copy_from_user(&args, (const void __user *)arg,
+                                  sizeof(args))) {
                        ret = -EFAULT;
                        break;
                }
@@ -1124,7 +1121,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                                &(((struct vchiq_queue_bulk_transfer __user *)
                                        arg)->mode),
                                (const void *)&mode_waiting,
-                               sizeof(mode_waiting)) != 0)
+                               sizeof(mode_waiting)))
                                ret = -EFAULT;
                }
        } break;
@@ -1139,7 +1136,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                }
 
                if (copy_from_user(&args, (const void __user *)arg,
-                       sizeof(args)) != 0) {
+                       sizeof(args))) {
                        ret = -EFAULT;
                        break;
                }
@@ -1154,10 +1151,10 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
                        DEBUG_TRACE(AWAIT_COMPLETION_LINE);
                        mutex_unlock(&instance->completion_mutex);
-                       rc = wait_for_completion_killable(
+                       rc = wait_for_completion_interruptible(
                                                &instance->insert_event);
                        mutex_lock(&instance->completion_mutex);
-                       if (rc != 0) {
+                       if (rc) {
                                DEBUG_TRACE(AWAIT_COMPLETION_LINE);
                                vchiq_log_info(vchiq_arm_log_level,
                                        "AWAIT_COMPLETION interrupted");
@@ -1223,7 +1220,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                                        if (copy_from_user(&msgbuf,
                                                (const void __user *)
                                                &args.msgbufs[msgbufcount],
-                                               sizeof(msgbuf)) != 0) {
+                                               sizeof(msgbuf))) {
                                                if (ret == 0)
                                                        ret = -EFAULT;
                                                break;
@@ -1231,7 +1228,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
                                        /* Copy the message to user space */
                                        if (copy_to_user(msgbuf, header,
-                                               msglen) != 0) {
+                                               msglen)) {
                                                if (ret == 0)
                                                        ret = -EFAULT;
                                                break;
@@ -1256,8 +1253,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                                        (size_t)args.buf + ret *
                                        sizeof(struct vchiq_completion_data)),
                                        completion,
-                                       sizeof(struct vchiq_completion_data))
-                                                                       != 0) {
+                                       sizeof(struct vchiq_completion_data))) {
                                                if (ret == 0)
                                                        ret = -EFAULT;
                                        break;
@@ -1277,13 +1273,13 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                                        &((struct vchiq_await_completion *)arg)
                                                ->msgbufcount,
                                        &msgbufcount,
-                                       sizeof(msgbufcount)) != 0) {
+                                       sizeof(msgbufcount))) {
                                        ret = -EFAULT;
                                }
                        }
                }
 
-               if (ret != 0)
+               if (ret)
                        complete(&instance->remove_event);
                mutex_unlock(&instance->completion_mutex);
                DEBUG_TRACE(AWAIT_COMPLETION_LINE);
@@ -1295,9 +1291,8 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                struct vchiq_header *header;
 
                DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
-               if (copy_from_user
-                        (&args, (const void __user *)arg,
-                         sizeof(args)) != 0) {
+               if (copy_from_user(&args, (const void __user *)arg,
+                                  sizeof(args))) {
                        ret = -EFAULT;
                        break;
                }
@@ -1324,7 +1319,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                        do {
                                spin_unlock(&msg_queue_spinlock);
                                DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
-                               if (wait_for_completion_killable(
+                               if (wait_for_completion_interruptible(
                                        &user_service->insert_event)) {
                                        vchiq_log_info(vchiq_arm_log_level,
                                                "DEQUEUE_MESSAGE interrupted");
@@ -1383,7 +1378,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                struct vchiq_config config;
 
                if (copy_from_user(&args, (const void __user *)arg,
-                       sizeof(args)) != 0) {
+                                  sizeof(args))) {
                        ret = -EFAULT;
                        break;
                }
@@ -1402,9 +1397,8 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        case VCHIQ_IOC_SET_SERVICE_OPTION: {
                struct vchiq_set_service_option args;
 
-               if (copy_from_user(
-                       &args, (const void __user *)arg,
-                       sizeof(args)) != 0) {
+               if (copy_from_user(&args, (const void __user *)arg,
+                                  sizeof(args))) {
                        ret = -EFAULT;
                        break;
                }
@@ -2328,8 +2322,7 @@ vchiq_keepalive_thread_func(void *v)
        while (1) {
                long rc = 0, uc = 0;
 
-               if (wait_for_completion_killable(&arm_state->ka_evt)
-                               != 0) {
+               if (wait_for_completion_interruptible(&arm_state->ka_evt)) {
                        vchiq_log_error(vchiq_susp_log_level,
                                "%s interrupted", __func__);
                        flush_signals(current);
@@ -2561,72 +2554,6 @@ need_resume(struct vchiq_state *state)
                        vchiq_videocore_wanted(state);
 }
 
-static int
-block_resume(struct vchiq_arm_state *arm_state)
-{
-       int status = VCHIQ_SUCCESS;
-       const unsigned long timeout_val =
-                               msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS);
-       int resume_count = 0;
-
-       /* Allow any threads which were blocked by the last force suspend to
-        * complete if they haven't already.  Only give this one shot; if
-        * blocked_count is incremented after blocked_blocker is completed
-        * (which only happens when blocked_count hits 0) then those threads
-        * will have to wait until next time around */
-       if (arm_state->blocked_count) {
-               reinit_completion(&arm_state->blocked_blocker);
-               write_unlock_bh(&arm_state->susp_res_lock);
-               vchiq_log_info(vchiq_susp_log_level, "%s wait for previously "
-                       "blocked clients", __func__);
-               if (wait_for_completion_killable_timeout(
-                               &arm_state->blocked_blocker, timeout_val)
-                                       <= 0) {
-                       vchiq_log_error(vchiq_susp_log_level, "%s wait for "
-                               "previously blocked clients failed", __func__);
-                       status = VCHIQ_ERROR;
-                       write_lock_bh(&arm_state->susp_res_lock);
-                       goto out;
-               }
-               vchiq_log_info(vchiq_susp_log_level, "%s previously blocked "
-                       "clients resumed", __func__);
-               write_lock_bh(&arm_state->susp_res_lock);
-       }
-
-       /* We need to wait for resume to complete if it's in process */
-       while (arm_state->vc_resume_state != VC_RESUME_RESUMED &&
-                       arm_state->vc_resume_state > VC_RESUME_IDLE) {
-               if (resume_count > 1) {
-                       status = VCHIQ_ERROR;
-                       vchiq_log_error(vchiq_susp_log_level, "%s waited too "
-                               "many times for resume", __func__);
-                       goto out;
-               }
-               write_unlock_bh(&arm_state->susp_res_lock);
-               vchiq_log_info(vchiq_susp_log_level, "%s wait for resume",
-                       __func__);
-               if (wait_for_completion_killable_timeout(
-                               &arm_state->vc_resume_complete, timeout_val)
-                                       <= 0) {
-                       vchiq_log_error(vchiq_susp_log_level, "%s wait for "
-                               "resume failed (%s)", __func__,
-                               resume_state_names[arm_state->vc_resume_state +
-                                                       VC_RESUME_NUM_OFFSET]);
-                       status = VCHIQ_ERROR;
-                       write_lock_bh(&arm_state->susp_res_lock);
-                       goto out;
-               }
-               vchiq_log_info(vchiq_susp_log_level, "%s resumed", __func__);
-               write_lock_bh(&arm_state->susp_res_lock);
-               resume_count++;
-       }
-       reinit_completion(&arm_state->resume_blocker);
-       arm_state->resume_blocked = 1;
-
-out:
-       return status;
-}
-
 static inline void
 unblock_resume(struct vchiq_arm_state *arm_state)
 {
@@ -2712,162 +2639,6 @@ out:
        return;
 }
 
-static void
-output_timeout_error(struct vchiq_state *state)
-{
-       struct vchiq_arm_state *arm_state = vchiq_platform_get_arm_state(state);
-       char err[50] = "";
-       int vc_use_count = arm_state->videocore_use_count;
-       int active_services = state->unused_service;
-       int i;
-
-       if (!arm_state->videocore_use_count) {
-               snprintf(err, sizeof(err), " Videocore usecount is 0");
-               goto output_msg;
-       }
-       for (i = 0; i < active_services; i++) {
-               struct vchiq_service *service_ptr = state->services[i];
-
-               if (service_ptr && service_ptr->service_use_count &&
-                       (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE)) {
-                       snprintf(err, sizeof(err), " %c%c%c%c(%d) service has "
-                               "use count %d%s", VCHIQ_FOURCC_AS_4CHARS(
-                                       service_ptr->base.fourcc),
-                                service_ptr->client_id,
-                                service_ptr->service_use_count,
-                                service_ptr->service_use_count ==
-                                        vc_use_count ? "" : " (+ more)");
-                       break;
-               }
-       }
-
-output_msg:
-       vchiq_log_error(vchiq_susp_log_level,
-               "timed out waiting for vc suspend (%d).%s",
-                arm_state->autosuspend_override, err);
-
-}
-
-/* Try to get videocore into suspended state, regardless of autosuspend state.
-** We don't actually force suspend, since videocore may get into a bad state
-** if we force suspend at a bad time.  Instead, we wait for autosuspend to
-** determine a good point to suspend.  If this doesn't happen within 100ms we
-** report failure.
-**
-** Returns VCHIQ_SUCCESS if videocore suspended successfully, VCHIQ_RETRY if
-** videocore failed to suspend in time or VCHIQ_ERROR if interrupted.
-*/
-VCHIQ_STATUS_T
-vchiq_arm_force_suspend(struct vchiq_state *state)
-{
-       struct vchiq_arm_state *arm_state = vchiq_platform_get_arm_state(state);
-       VCHIQ_STATUS_T status = VCHIQ_ERROR;
-       long rc = 0;
-       int repeat = -1;
-
-       if (!arm_state)
-               goto out;
-
-       vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
-
-       write_lock_bh(&arm_state->susp_res_lock);
-
-       status = block_resume(arm_state);
-       if (status != VCHIQ_SUCCESS)
-               goto unlock;
-       if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
-               /* Already suspended - just block resume and exit */
-               vchiq_log_info(vchiq_susp_log_level, "%s already suspended",
-                       __func__);
-               status = VCHIQ_SUCCESS;
-               goto unlock;
-       } else if (arm_state->vc_suspend_state <= VC_SUSPEND_IDLE) {
-               /* initiate suspend immediately in the case that we're waiting
-                * for the timeout */
-               stop_suspend_timer(arm_state);
-               if (!vchiq_videocore_wanted(state)) {
-                       vchiq_log_info(vchiq_susp_log_level, "%s videocore "
-                               "idle, initiating suspend", __func__);
-                       status = vchiq_arm_vcsuspend(state);
-               } else if (arm_state->autosuspend_override <
-                                               FORCE_SUSPEND_FAIL_MAX) {
-                       vchiq_log_info(vchiq_susp_log_level, "%s letting "
-                               "videocore go idle", __func__);
-                       status = VCHIQ_SUCCESS;
-               } else {
-                       vchiq_log_warning(vchiq_susp_log_level, "%s failed too "
-                               "many times - attempting suspend", __func__);
-                       status = vchiq_arm_vcsuspend(state);
-               }
-       } else {
-               vchiq_log_info(vchiq_susp_log_level, "%s videocore suspend "
-                       "in progress - wait for completion", __func__);
-               status = VCHIQ_SUCCESS;
-       }
-
-       /* Wait for suspend to happen due to system idle (not forced..) */
-       if (status != VCHIQ_SUCCESS)
-               goto unblock_resume;
-
-       do {
-               write_unlock_bh(&arm_state->susp_res_lock);
-
-               rc = wait_for_completion_killable_timeout(
-                               &arm_state->vc_suspend_complete,
-                               msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS));
-
-               write_lock_bh(&arm_state->susp_res_lock);
-               if (rc < 0) {
-                       vchiq_log_warning(vchiq_susp_log_level, "%s "
-                               "interrupted waiting for suspend", __func__);
-                       status = VCHIQ_ERROR;
-                       goto unblock_resume;
-               } else if (rc == 0) {
-                       if (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) {
-                               /* Repeat timeout once if in progress */
-                               if (repeat < 0) {
-                                       repeat = 1;
-                                       continue;
-                               }
-                       }
-                       arm_state->autosuspend_override++;
-                       output_timeout_error(state);
-
-                       status = VCHIQ_RETRY;
-                       goto unblock_resume;
-               }
-       } while (0 < (repeat--));
-
-       /* Check and report state in case we need to abort ARM suspend */
-       if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED) {
-               status = VCHIQ_RETRY;
-               vchiq_log_error(vchiq_susp_log_level,
-                       "%s videocore suspend failed (state %s)", __func__,
-                       suspend_state_names[arm_state->vc_suspend_state +
-                                               VC_SUSPEND_NUM_OFFSET]);
-               /* Reset the state only if it's still in an error state.
-                * Something could have already initiated another suspend. */
-               if (arm_state->vc_suspend_state < VC_SUSPEND_IDLE)
-                       set_suspend_state(arm_state, VC_SUSPEND_IDLE);
-
-               goto unblock_resume;
-       }
-
-       /* successfully suspended - unlock and exit */
-       goto unlock;
-
-unblock_resume:
-       /* all error states need to unblock resume before exit */
-       unblock_resume(arm_state);
-
-unlock:
-       write_unlock_bh(&arm_state->susp_res_lock);
-
-out:
-       vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
-       return status;
-}
-
 void
 vchiq_check_suspend(struct vchiq_state *state)
 {
@@ -2890,49 +2661,6 @@ out:
        vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
 }
 
-int
-vchiq_arm_allow_resume(struct vchiq_state *state)
-{
-       struct vchiq_arm_state *arm_state = vchiq_platform_get_arm_state(state);
-       int resume = 0;
-       int ret = -1;
-
-       if (!arm_state)
-               goto out;
-
-       vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
-
-       write_lock_bh(&arm_state->susp_res_lock);
-       unblock_resume(arm_state);
-       resume = vchiq_check_resume(state);
-       write_unlock_bh(&arm_state->susp_res_lock);
-
-       if (resume) {
-               if (wait_for_completion_killable(
-                       &arm_state->vc_resume_complete) < 0) {
-                       vchiq_log_error(vchiq_susp_log_level,
-                               "%s interrupted", __func__);
-                       /* failed, cannot accurately derive suspend
-                        * state, so exit early. */
-                       goto out;
-               }
-       }
-
-       read_lock_bh(&arm_state->susp_res_lock);
-       if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
-               vchiq_log_info(vchiq_susp_log_level,
-                               "%s: Videocore remains suspended", __func__);
-       } else {
-               vchiq_log_info(vchiq_susp_log_level,
-                               "%s: Videocore resumed", __func__);
-               ret = 0;
-       }
-       read_unlock_bh(&arm_state->susp_res_lock);
-out:
-       vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
-       return ret;
-}
-
 /* This function should be called with the write lock held */
 int
 vchiq_check_resume(struct vchiq_state *state)
@@ -3010,7 +2738,7 @@ vchiq_use_internal(struct vchiq_state *state, struct vchiq_service *service,
                        vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
                                "blocked - waiting...", __func__, entity);
                        if (wait_for_completion_killable(
-                                       &arm_state->resume_blocker) != 0) {
+                                       &arm_state->resume_blocker)) {
                                vchiq_log_error(vchiq_susp_log_level, "%s %s "
                                        "wait for resume blocker interrupted",
                                        __func__, entity);
@@ -3059,7 +2787,7 @@ vchiq_use_internal(struct vchiq_state *state, struct vchiq_service *service,
                vchiq_log_info(vchiq_susp_log_level, "%s %s wait for resume",
                        __func__, entity);
                if (wait_for_completion_killable(
-                               &arm_state->vc_resume_complete) != 0) {
+                               &arm_state->vc_resume_complete)) {
                        vchiq_log_error(vchiq_susp_log_level, "%s %s wait for "
                                "resume interrupted", __func__, entity);
                        ret = VCHIQ_ERROR;
@@ -3242,20 +2970,6 @@ static void suspend_timer_callback(struct timer_list *t)
        vchiq_check_suspend(state);
 }
 
-VCHIQ_STATUS_T
-vchiq_use_service_no_resume(VCHIQ_SERVICE_HANDLE_T handle)
-{
-       VCHIQ_STATUS_T ret = VCHIQ_ERROR;
-       struct vchiq_service *service = find_service_by_handle(handle);
-
-       if (service) {
-               ret = vchiq_use_internal(service->state, service,
-                               USE_TYPE_SERVICE_NO_RESUME);
-               unlock_service(service);
-       }
-       return ret;
-}
-
 VCHIQ_STATUS_T
 vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle)
 {
@@ -3504,13 +3218,13 @@ static int vchiq_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, drvdata);
 
        err = vchiq_platform_init(pdev, &g_state);
-       if (err != 0)
+       if (err)
                goto failed_platform_init;
 
        cdev_init(&vchiq_cdev, &vchiq_fops);
        vchiq_cdev.owner = THIS_MODULE;
        err = cdev_add(&vchiq_cdev, vchiq_devid, 1);
-       if (err != 0) {
+       if (err) {
                vchiq_log_error(vchiq_arm_log_level,
                        "Unable to register device");
                goto failed_platform_init;
index c1d5a9d17071ba63fa1ab48d522ae35b84fc7736..b424323e9613449fe3ed7187b35f647aaed38f94 100644 (file)
@@ -112,12 +112,6 @@ vchiq_get_state(void);
 extern VCHIQ_STATUS_T
 vchiq_arm_vcsuspend(struct vchiq_state *state);
 
-extern VCHIQ_STATUS_T
-vchiq_arm_force_suspend(struct vchiq_state *state);
-
-extern int
-vchiq_arm_allow_resume(struct vchiq_state *state);
-
 extern VCHIQ_STATUS_T
 vchiq_arm_vcresume(struct vchiq_state *state);
 
index e87e6619695ee690e818cc3e397a91f68ce71721..1640906e3929f96e4546ff01349b04caefaeba05 100644 (file)
@@ -41,7 +41,7 @@ void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback)
 {
        connected_init();
 
-       if (mutex_lock_killable(&g_connected_mutex) != 0)
+       if (mutex_lock_killable(&g_connected_mutex))
                return;
 
        if (g_connected)
@@ -76,7 +76,7 @@ void vchiq_call_connected_callbacks(void)
 
        connected_init();
 
-       if (mutex_lock_killable(&g_connected_mutex) != 0)
+       if (mutex_lock_killable(&g_connected_mutex))
                return;
 
        for (i = 0; i <  g_num_deferred_callbacks; i++)
index 0c387b6473a5e5e8b9a916c24e729258c028cd05..183f5cf887e0e2faee00790a83b5ae1cf5cb387e 100644 (file)
@@ -395,13 +395,21 @@ remote_event_create(wait_queue_head_t *wq, struct remote_event *event)
        init_waitqueue_head(wq);
 }
 
+/*
+ * All the event waiting routines in VCHIQ used a custom semaphore
+ * implementation that filtered most signals. This achieved a behaviour similar
+ * to the "killable" family of functions. While cleaning up this code all the
+ * routines where switched to the "interruptible" family of functions, as the
+ * former was deemed unjustified and the use "killable" set all VCHIQ's
+ * threads in D state.
+ */
 static inline int
 remote_event_wait(wait_queue_head_t *wq, struct remote_event *event)
 {
        if (!event->fired) {
                event->armed = 1;
                dsb(sy);
-               if (wait_event_killable(*wq, event->fired)) {
+               if (wait_event_interruptible(*wq, event->fired)) {
                        event->armed = 0;
                        return 0;
                }
@@ -560,7 +568,7 @@ reserve_space(struct vchiq_state *state, size_t space, int is_blocking)
                        remote_event_signal(&state->remote->trigger);
 
                        if (!is_blocking ||
-                               (wait_for_completion_killable(
+                               (wait_for_completion_interruptible(
                                &state->slot_available_event)))
                                return NULL; /* No space available */
                }
@@ -792,7 +800,7 @@ queue_message(struct vchiq_state *state, struct vchiq_service *service,
        WARN_ON(!(stride <= VCHIQ_SLOT_SIZE));
 
        if (!(flags & QMFLAGS_NO_MUTEX_LOCK) &&
-               (mutex_lock_killable(&state->slot_mutex) != 0))
+           mutex_lock_killable(&state->slot_mutex))
                return VCHIQ_RETRY;
 
        if (type == VCHIQ_MSG_DATA) {
@@ -804,8 +812,8 @@ queue_message(struct vchiq_state *state, struct vchiq_service *service,
                        return VCHIQ_ERROR;
                }
 
-               WARN_ON((flags & (QMFLAGS_NO_MUTEX_LOCK |
-                                 QMFLAGS_NO_MUTEX_UNLOCK)) != 0);
+               WARN_ON(flags & (QMFLAGS_NO_MUTEX_LOCK |
+                                QMFLAGS_NO_MUTEX_UNLOCK));
 
                if (service->closing) {
                        /* The service has been closed */
@@ -830,7 +838,7 @@ queue_message(struct vchiq_state *state, struct vchiq_service *service,
                        spin_unlock(&quota_spinlock);
                        mutex_unlock(&state->slot_mutex);
 
-                       if (wait_for_completion_killable(
+                       if (wait_for_completion_interruptible(
                                                &state->data_quota_event))
                                return VCHIQ_RETRY;
 
@@ -861,12 +869,12 @@ queue_message(struct vchiq_state *state, struct vchiq_service *service,
                                service_quota->slot_use_count);
                        VCHIQ_SERVICE_STATS_INC(service, quota_stalls);
                        mutex_unlock(&state->slot_mutex);
-                       if (wait_for_completion_killable(
+                       if (wait_for_completion_interruptible(
                                                &service_quota->quota_event))
                                return VCHIQ_RETRY;
                        if (service->closing)
                                return VCHIQ_ERROR;
-                       if (mutex_lock_killable(&state->slot_mutex) != 0)
+                       if (mutex_lock_killable(&state->slot_mutex))
                                return VCHIQ_RETRY;
                        if (service->srvstate != VCHIQ_SRVSTATE_OPEN) {
                                /* The service has been closed */
@@ -904,8 +912,8 @@ queue_message(struct vchiq_state *state, struct vchiq_service *service,
                        header, size, VCHIQ_MSG_SRCPORT(msgid),
                        VCHIQ_MSG_DSTPORT(msgid));
 
-               WARN_ON((flags & (QMFLAGS_NO_MUTEX_LOCK |
-                                 QMFLAGS_NO_MUTEX_UNLOCK)) != 0);
+               WARN_ON(flags & (QMFLAGS_NO_MUTEX_LOCK |
+                                QMFLAGS_NO_MUTEX_UNLOCK));
 
                callback_result =
                        copy_message_data(copy_callback, context,
@@ -1032,8 +1040,8 @@ queue_message_sync(struct vchiq_state *state, struct vchiq_service *service,
 
        local = state->local;
 
-       if ((VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_RESUME) &&
-               (mutex_lock_killable(&state->sync_mutex) != 0))
+       if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_RESUME &&
+           mutex_lock_killable(&state->sync_mutex))
                return VCHIQ_RETRY;
 
        remote_event_wait(&state->sync_release_event, &local->sync_release);
@@ -2428,7 +2436,7 @@ vchiq_open_service_internal(struct vchiq_service *service, int client_id)
                               QMFLAGS_IS_BLOCKING);
        if (status == VCHIQ_SUCCESS) {
                /* Wait for the ACK/NAK */
-               if (wait_for_completion_killable(&service->remove_event)) {
+               if (wait_for_completion_interruptible(&service->remove_event)) {
                        status = VCHIQ_RETRY;
                        vchiq_release_service_internal(service);
                } else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) &&
@@ -2514,7 +2522,7 @@ do_abort_bulks(struct vchiq_service *service)
        VCHIQ_STATUS_T status;
 
        /* Abort any outstanding bulk transfers */
-       if (mutex_lock_killable(&service->bulk_mutex) != 0)
+       if (mutex_lock_killable(&service->bulk_mutex))
                return 0;
        abort_outstanding_bulks(service, &service->bulk_tx);
        abort_outstanding_bulks(service, &service->bulk_rx);
@@ -2795,7 +2803,7 @@ vchiq_connect_internal(struct vchiq_state *state, VCHIQ_INSTANCE_T instance)
        }
 
        if (state->conn_state == VCHIQ_CONNSTATE_CONNECTING) {
-               if (wait_for_completion_killable(&state->connect))
+               if (wait_for_completion_interruptible(&state->connect))
                        return VCHIQ_RETRY;
 
                vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
@@ -2822,45 +2830,6 @@ vchiq_shutdown_internal(struct vchiq_state *state, VCHIQ_INSTANCE_T instance)
        return VCHIQ_SUCCESS;
 }
 
-VCHIQ_STATUS_T
-vchiq_pause_internal(struct vchiq_state *state)
-{
-       VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
-
-       switch (state->conn_state) {
-       case VCHIQ_CONNSTATE_CONNECTED:
-               /* Request a pause */
-               vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSING);
-               request_poll(state, NULL, 0);
-               break;
-       default:
-               vchiq_log_error(vchiq_core_log_level,
-                       "%s in state %s\n",
-                       __func__, conn_state_names[state->conn_state]);
-               status = VCHIQ_ERROR;
-               VCHIQ_STATS_INC(state, error_count);
-               break;
-       }
-
-       return status;
-}
-
-VCHIQ_STATUS_T
-vchiq_resume_internal(struct vchiq_state *state)
-{
-       VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
-
-       if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
-               vchiq_set_conn_state(state, VCHIQ_CONNSTATE_RESUMING);
-               request_poll(state, NULL, 0);
-       } else {
-               status = VCHIQ_ERROR;
-               VCHIQ_STATS_INC(state, error_count);
-       }
-
-       return status;
-}
-
 VCHIQ_STATUS_T
 vchiq_close_service(VCHIQ_SERVICE_HANDLE_T handle)
 {
@@ -2894,7 +2863,7 @@ vchiq_close_service(VCHIQ_SERVICE_HANDLE_T handle)
        }
 
        while (1) {
-               if (wait_for_completion_killable(&service->remove_event)) {
+               if (wait_for_completion_interruptible(&service->remove_event)) {
                        status = VCHIQ_RETRY;
                        break;
                }
@@ -2955,7 +2924,7 @@ vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T handle)
                request_poll(service->state, service, VCHIQ_POLL_REMOVE);
        }
        while (1) {
-               if (wait_for_completion_killable(&service->remove_event)) {
+               if (wait_for_completion_interruptible(&service->remove_event)) {
                        status = VCHIQ_RETRY;
                        break;
                }
@@ -3029,7 +2998,7 @@ VCHIQ_STATUS_T vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
        queue = (dir == VCHIQ_BULK_TRANSMIT) ?
                &service->bulk_tx : &service->bulk_rx;
 
-       if (mutex_lock_killable(&service->bulk_mutex) != 0) {
+       if (mutex_lock_killable(&service->bulk_mutex)) {
                status = VCHIQ_RETRY;
                goto error_exit;
        }
@@ -3038,13 +3007,12 @@ VCHIQ_STATUS_T vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
                VCHIQ_SERVICE_STATS_INC(service, bulk_stalls);
                do {
                        mutex_unlock(&service->bulk_mutex);
-                       if (wait_for_completion_killable(
+                       if (wait_for_completion_interruptible(
                                                &service->bulk_remove_event)) {
                                status = VCHIQ_RETRY;
                                goto error_exit;
                        }
-                       if (mutex_lock_killable(&service->bulk_mutex)
-                               != 0) {
+                       if (mutex_lock_killable(&service->bulk_mutex)) {
                                status = VCHIQ_RETRY;
                                goto error_exit;
                        }
@@ -3072,7 +3040,7 @@ VCHIQ_STATUS_T vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
 
        /* The slot mutex must be held when the service is being closed, so
           claim it here to ensure that isn't happening */
-       if (mutex_lock_killable(&state->slot_mutex) != 0) {
+       if (mutex_lock_killable(&state->slot_mutex)) {
                status = VCHIQ_RETRY;
                goto cancel_bulk_error_exit;
        }
@@ -3093,9 +3061,8 @@ VCHIQ_STATUS_T vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
                               QMFLAGS_IS_BLOCKING |
                               QMFLAGS_NO_MUTEX_LOCK |
                               QMFLAGS_NO_MUTEX_UNLOCK);
-       if (status != VCHIQ_SUCCESS) {
+       if (status != VCHIQ_SUCCESS)
                goto unlock_both_error_exit;
-       }
 
        queue->local_insert++;
 
@@ -3115,7 +3082,7 @@ waiting:
 
        if (bulk_waiter) {
                bulk_waiter->bulk = bulk;
-               if (wait_for_completion_killable(&bulk_waiter->event))
+               if (wait_for_completion_interruptible(&bulk_waiter->event))
                        status = VCHIQ_RETRY;
                else if (bulk_waiter->actual == VCHIQ_BULK_ACTUAL_ABORTED)
                        status = VCHIQ_ERROR;
@@ -3571,17 +3538,6 @@ VCHIQ_STATUS_T vchiq_send_remote_use(struct vchiq_state *state)
        return status;
 }
 
-VCHIQ_STATUS_T vchiq_send_remote_release(struct vchiq_state *state)
-{
-       VCHIQ_STATUS_T status = VCHIQ_RETRY;
-
-       if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
-               status = queue_message(state, NULL,
-                       VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_RELEASE, 0, 0),
-                       NULL, NULL, 0, 0);
-       return status;
-}
-
 VCHIQ_STATUS_T vchiq_send_remote_use_active(struct vchiq_state *state)
 {
        VCHIQ_STATUS_T status = VCHIQ_RETRY;
index aee2d362e88d2e4506cfecb4ff78ff5094e738d0..63f71b2a492fe913cc01abf09af523ea9f6cc32d 100644 (file)
@@ -518,12 +518,6 @@ vchiq_free_service_internal(struct vchiq_service *service);
 extern VCHIQ_STATUS_T
 vchiq_shutdown_internal(struct vchiq_state *state, VCHIQ_INSTANCE_T instance);
 
-extern VCHIQ_STATUS_T
-vchiq_pause_internal(struct vchiq_state *state);
-
-extern VCHIQ_STATUS_T
-vchiq_resume_internal(struct vchiq_state *state);
-
 extern void
 remote_event_pollall(struct vchiq_state *state);
 
@@ -645,9 +639,6 @@ vchiq_on_remote_use_active(struct vchiq_state *state);
 extern VCHIQ_STATUS_T
 vchiq_send_remote_use(struct vchiq_state *state);
 
-extern VCHIQ_STATUS_T
-vchiq_send_remote_release(struct vchiq_state *state);
-
 extern VCHIQ_STATUS_T
 vchiq_send_remote_use_active(struct vchiq_state *state);
 
index 2bb9120883fd9b4788a6d253b41d1fd4f6aee6f1..f217b78d95a0457e5a4cc089cb1869e2651e0d0f 100644 (file)
@@ -86,7 +86,7 @@ static ssize_t debugfs_log_write(struct file *file,
        if (count >= DEBUGFS_WRITE_BUF_SIZE)
                count = DEBUGFS_WRITE_BUF_SIZE;
 
-       if (copy_from_user(kbuf, buffer, count) != 0)
+       if (copy_from_user(kbuf, buffer, count))
                return -EFAULT;
        kbuf[count - 1] = 0;
 
@@ -151,7 +151,7 @@ static ssize_t debugfs_trace_write(struct file *file,
        VCHIQ_INSTANCE_T instance = f->private;
        char firstchar;
 
-       if (copy_from_user(&firstchar, buffer, 1) != 0)
+       if (copy_from_user(&firstchar, buffer, 1))
                return -EFAULT;
 
        switch (firstchar) {
index 5445f201e284a8d2a14d60adcc3ab1f9287829af..c23bd105c40f4b363f30038b1bd8ed10c830ee5e 100644 (file)
@@ -107,8 +107,6 @@ extern VCHIQ_STATUS_T vchiq_open_service(VCHIQ_INSTANCE_T instance,
 extern VCHIQ_STATUS_T vchiq_close_service(VCHIQ_SERVICE_HANDLE_T service);
 extern VCHIQ_STATUS_T vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T service);
 extern VCHIQ_STATUS_T vchiq_use_service(VCHIQ_SERVICE_HANDLE_T service);
-extern VCHIQ_STATUS_T vchiq_use_service_no_resume(
-       VCHIQ_SERVICE_HANDLE_T service);
 extern VCHIQ_STATUS_T vchiq_release_service(VCHIQ_SERVICE_HANDLE_T service);
 extern VCHIQ_STATUS_T
 vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T handle,
index 13910d205fce2bda7fa05d6287c2053fe35824fd..17a4f2c8d8b1af3b8779d06f5f9e6ed5bff9764e 100644 (file)
@@ -639,10 +639,8 @@ int32_t vchi_service_close(const VCHI_SERVICE_HANDLE_T handle)
 
        if (service) {
                VCHIQ_STATUS_T status = vchiq_close_service(service->handle);
-               if (status == VCHIQ_SUCCESS) {
+               if (status == VCHIQ_SUCCESS)
                        service_free(service);
-                       service = NULL;
-               }
 
                ret = vchiq_status_to_vchi(status);
        }
index 6c519d8e48cbc88616ea3c82aa1a0ad91f0700a1..5e6d3035dc05864339262b2f005366328c28d48d 100644 (file)
@@ -39,18 +39,13 @@ int vchiu_queue_is_empty(struct vchiu_queue *queue)
        return queue->read == queue->write;
 }
 
-int vchiu_queue_is_full(struct vchiu_queue *queue)
-{
-       return queue->write == queue->read + queue->size;
-}
-
 void vchiu_queue_push(struct vchiu_queue *queue, struct vchiq_header *header)
 {
        if (!queue->initialized)
                return;
 
        while (queue->write == queue->read + queue->size) {
-               if (wait_for_completion_killable(&queue->pop))
+               if (wait_for_completion_interruptible(&queue->pop))
                        flush_signals(current);
        }
 
@@ -63,7 +58,7 @@ void vchiu_queue_push(struct vchiu_queue *queue, struct vchiq_header *header)
 struct vchiq_header *vchiu_queue_peek(struct vchiu_queue *queue)
 {
        while (queue->write == queue->read) {
-               if (wait_for_completion_killable(&queue->push))
+               if (wait_for_completion_interruptible(&queue->push))
                        flush_signals(current);
        }
 
@@ -77,7 +72,7 @@ struct vchiq_header *vchiu_queue_pop(struct vchiu_queue *queue)
        struct vchiq_header *header;
 
        while (queue->write == queue->read) {
-               if (wait_for_completion_killable(&queue->push))
+               if (wait_for_completion_interruptible(&queue->push))
                        flush_signals(current);
        }
 
index ee14594681718bf4cdc26cddf49377de1129cca6..f03a4250de0d264baae152ad64ef4553718cccd4 100644 (file)
@@ -40,7 +40,6 @@ extern int  vchiu_queue_init(struct vchiu_queue *queue, int size);
 extern void vchiu_queue_delete(struct vchiu_queue *queue);
 
 extern int vchiu_queue_is_empty(struct vchiu_queue *queue);
-extern int vchiu_queue_is_full(struct vchiu_queue *queue);
 
 extern void vchiu_queue_push(struct vchiu_queue *queue,
                             struct vchiq_header *header);
index e4b224fedf5b9724d10540eb9ef20060599b866b..d1cd5de46dcf2855b60722ed93f036280b38e9ed 100644 (file)
@@ -2,6 +2,5 @@
 config VT6655
    tristate "VIA Technologies VT6655 support"
    depends on PCI && MAC80211 && m
-   ---help---
-   This is a vendor-written driver for VIA VT6655.
-
+   help
+     This is a vendor-written driver for VIA VT6655.
index 6ecbe925026d6132744eade5184da2bd39a49939..eba4ee0750dc61bcaed74abbbb7a791c5245b0b6 100644 (file)
@@ -409,14 +409,11 @@ bool CARDbSetBeaconPeriod(struct vnt_private *priv,
  *  Out:
  *      none
  *
- * Return Value: true if success; otherwise false
  */
-bool CARDbRadioPowerOff(struct vnt_private *priv)
+void CARDbRadioPowerOff(struct vnt_private *priv)
 {
-       bool bResult = true;
-
        if (priv->bRadioOff)
-               return true;
+               return;
 
        switch (priv->byRFType) {
        case RF_RFMD2959:
@@ -444,7 +441,6 @@ bool CARDbRadioPowerOff(struct vnt_private *priv)
        pr_debug("chester power off\n");
        MACvRegBitsOn(priv->PortOffset, MAC_REG_GPIOCTL0,
                      LED_ACTSET);  /* LED issue */
-       return bResult;
 }
 
 /*
index f422fb3c78bd72a881c4d0d4b1da06a9f535cda5..887c1692e05b47cef7b83e571388be6ba3b1890f 100644 (file)
@@ -57,7 +57,7 @@ u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2);
 unsigned char CARDbyGetPktType(struct vnt_private *priv);
 void CARDvSafeResetTx(struct vnt_private *priv);
 void CARDvSafeResetRx(struct vnt_private *priv);
-bool CARDbRadioPowerOff(struct vnt_private *priv);
+void CARDbRadioPowerOff(struct vnt_private *priv);
 bool CARDbRadioPowerOn(struct vnt_private *priv);
 bool CARDbSetPhyParameter(struct vnt_private *priv, u8 bb_type);
 bool CARDbUpdateTSF(struct vnt_private *priv, unsigned char byRxRate,
index 039f7d71c537857cef07ba31acd8f1e29026409c..ba6dec774478e9d57321d07983ad1884bb29078e 100644 (file)
@@ -6,4 +6,4 @@ KSP :=  /lib/modules/$(shell uname -r)/build \
 #      /usr/src/linux-$(shell uname -r | sed 's/\([0-9]*\.[0-9]*\)\..*/\1/') \
 #      /usr/src/linux   /home/plice
 test_dir = $(shell [ -e $(dir)/include/linux ] && echo $(dir))
-KSP := $(foreach dir, $(KSP), $(test_dir))
\ No newline at end of file
+KSP := $(foreach dir, $(KSP), $(test_dir))
index 51e295265ba625da7d41a592454075d2898a4b63..f52a3f1d9a2ee294cb5a511b788bbf58d6117ca9 100644 (file)
@@ -3,6 +3,5 @@ config VT6656
        tristate "VIA Technologies VT6656 support"
        depends on MAC80211 && USB && WLAN && m
        select FW_LOADER
-       ---help---
-       This is a vendor-written driver for VIA VT6656.
-
+       help
+         This is a vendor-written driver for VIA VT6656.
index b29ba237fa2953f968864dc6376f3d5519160bec..8d19ae71e7cc9124f666f1807e8752e379a222b3 100644 (file)
@@ -329,7 +329,7 @@ void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length,
  * Return Value: none
  *
  */
-void vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode)
+int vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode)
 {
        switch (antenna_mode) {
        case ANT_TXA:
@@ -344,8 +344,8 @@ void vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode)
                break;
        }
 
-       vnt_control_out(priv, MESSAGE_TYPE_SET_ANTMD,
-                       (u16)antenna_mode, 0, 0, NULL);
+       return vnt_control_out(priv, MESSAGE_TYPE_SET_ANTMD,
+                              (u16)antenna_mode, 0, 0, NULL);
 }
 
 /*
@@ -364,7 +364,7 @@ void vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode)
 
 int vnt_vt3184_init(struct vnt_private *priv)
 {
-       int status;
+       int ret = 0;
        u16 length;
        u8 *addr;
        u8 *agc;
@@ -372,11 +372,10 @@ int vnt_vt3184_init(struct vnt_private *priv)
        u8 array[256];
        u8 data;
 
-       status = vnt_control_in(priv, MESSAGE_TYPE_READ, 0,
-                               MESSAGE_REQUEST_EEPROM, EEP_MAX_CONTEXT_SIZE,
-                                               priv->eeprom);
-       if (status != STATUS_SUCCESS)
-               return false;
+       ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0, MESSAGE_REQUEST_EEPROM,
+                            EEP_MAX_CONTEXT_SIZE, priv->eeprom);
+       if (ret)
+               goto end;
 
        priv->rf_type = priv->eeprom[EEP_OFS_RFTYPE];
 
@@ -423,8 +422,10 @@ int vnt_vt3184_init(struct vnt_private *priv)
                priv->bb_vga[3] = 0x0;
 
                /* Fix VT3226 DFC system timing issue */
-               vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
-                                   SOFTPWRCTL_RFLEOPT);
+               ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
+                                         SOFTPWRCTL_RFLEOPT);
+               if (ret)
+                       goto end;
        } else if (priv->rf_type == RF_VT3342A0) {
                priv->bb_rx_conf = vnt_vt3184_vt3226d0[10];
                length = sizeof(vnt_vt3184_vt3226d0);
@@ -438,48 +439,74 @@ int vnt_vt3184_init(struct vnt_private *priv)
                priv->bb_vga[3] = 0x0;
 
                /* Fix VT3226 DFC system timing issue */
-               vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
-                                   SOFTPWRCTL_RFLEOPT);
+               ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
+                                         SOFTPWRCTL_RFLEOPT);
+               if (ret)
+                       goto end;
        } else {
-               return true;
+               goto end;
        }
 
        memcpy(array, addr, length);
 
-       vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
-                       MESSAGE_REQUEST_BBREG, length, array);
+       ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
+                             MESSAGE_REQUEST_BBREG, length, array);
+       if (ret)
+               goto end;
 
        memcpy(array, agc, length_agc);
 
-       vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
-                       MESSAGE_REQUEST_BBAGC, length_agc, array);
+       ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
+                             MESSAGE_REQUEST_BBAGC, length_agc, array);
+       if (ret)
+               goto end;
 
        if ((priv->rf_type == RF_VT3226) ||
            (priv->rf_type == RF_VT3342A0)) {
-               vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
-                                  MAC_REG_ITRTMSET, 0x23);
-               vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01);
+               ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
+                                        MAC_REG_ITRTMSET, 0x23);
+               if (ret)
+                       goto end;
+
+               ret = vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01);
+               if (ret)
+                       goto end;
        } else if (priv->rf_type == RF_VT3226D0) {
-               vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
-                                  MAC_REG_ITRTMSET, 0x11);
-               vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01);
+               ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
+                                        MAC_REG_ITRTMSET, 0x11);
+               if (ret)
+                       goto end;
+
+               ret = vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01);
+               if (ret)
+                       goto end;
        }
 
-       vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x04, 0x7f);
-       vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);
+       ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x04, 0x7f);
+       if (ret)
+               goto end;
 
-       vnt_rf_table_download(priv);
+       ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);
+       if (ret)
+               goto end;
+
+       ret = vnt_rf_table_download(priv);
+       if (ret)
+               goto end;
 
        /* Fix for TX USB resets from vendors driver */
-       vnt_control_in(priv, MESSAGE_TYPE_READ, USB_REG4,
-                      MESSAGE_REQUEST_MEM, sizeof(data), &data);
+       ret = vnt_control_in(priv, MESSAGE_TYPE_READ, USB_REG4,
+                            MESSAGE_REQUEST_MEM, sizeof(data), &data);
+       if (ret)
+               goto end;
 
        data |= 0x2;
 
-       vnt_control_out(priv, MESSAGE_TYPE_WRITE, USB_REG4,
-                       MESSAGE_REQUEST_MEM, sizeof(data), &data);
+       ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, USB_REG4,
+                             MESSAGE_REQUEST_MEM, sizeof(data), &data);
 
-       return true;
+end:
+       return ret;
 }
 
 /*
@@ -494,8 +521,9 @@ int vnt_vt3184_init(struct vnt_private *priv)
  * Return Value: none
  *
  */
-void vnt_set_short_slot_time(struct vnt_private *priv)
+int vnt_set_short_slot_time(struct vnt_private *priv)
 {
+       int ret = 0;
        u8 bb_vga = 0;
 
        if (priv->short_slot_time)
@@ -503,12 +531,18 @@ void vnt_set_short_slot_time(struct vnt_private *priv)
        else
                priv->bb_rx_conf |= 0x20;
 
-       vnt_control_in_u8(priv, MESSAGE_REQUEST_BBREG, 0xe7, &bb_vga);
+       ret = vnt_control_in_u8(priv, MESSAGE_REQUEST_BBREG, 0xe7, &bb_vga);
+       if (ret)
+               goto end;
 
        if (bb_vga == priv->bb_vga[0])
                priv->bb_rx_conf |= 0x20;
 
-       vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, priv->bb_rx_conf);
+       ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a,
+                                priv->bb_rx_conf);
+
+end:
+       return ret;
 }
 
 void vnt_set_vga_gain_offset(struct vnt_private *priv, u8 data)
@@ -536,16 +570,30 @@ void vnt_set_vga_gain_offset(struct vnt_private *priv, u8 data)
  * Return Value: none
  *
  */
-void vnt_set_deep_sleep(struct vnt_private *priv)
+int vnt_set_deep_sleep(struct vnt_private *priv)
 {
-       vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x17);/* CR12 */
-       vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0xB9);/* CR13 */
+       int ret = 0;
+
+       /* CR12 */
+       ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x17);
+       if (ret)
+               return ret;
+
+       /* CR13 */
+       return vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0xB9);
 }
 
-void vnt_exit_deep_sleep(struct vnt_private *priv)
+int vnt_exit_deep_sleep(struct vnt_private *priv)
 {
-       vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x00);/* CR12 */
-       vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);/* CR13 */
+       int ret = 0;
+
+       /* CR12 */
+       ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x00);
+       if (ret)
+               return ret;
+
+       /* CR13 */
+       return vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);
 }
 
 void vnt_update_pre_ed_threshold(struct vnt_private *priv, int scanning)
index c3b8bbdb3ea1c3654414adb8a6fd28d213c042b5..dc42aa6ae1d937533b69af7c73ca23edb6d5cff5 100644 (file)
@@ -79,12 +79,12 @@ unsigned int vnt_get_frame_time(u8 preamble_type, u8 pkt_type,
 void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length,
                       u16 tx_rate, u8 pkt_type, struct vnt_phy_field *phy);
 
-void vnt_set_short_slot_time(struct vnt_private *priv);
+int vnt_set_short_slot_time(struct vnt_private *priv);
 void vnt_set_vga_gain_offset(struct vnt_private *priv, u8 data);
-void vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode);
+int vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode);
 int vnt_vt3184_init(struct vnt_private *priv);
-void vnt_set_deep_sleep(struct vnt_private *priv);
-void vnt_exit_deep_sleep(struct vnt_private *priv);
+int vnt_set_deep_sleep(struct vnt_private *priv);
+int vnt_exit_deep_sleep(struct vnt_private *priv);
 void vnt_update_pre_ed_threshold(struct vnt_private *priv, int scanning);
 
 #endif /* __BASEBAND_H__ */
index 501f482b41c49087ec6753cb67d945a47d3ce1ba..56cd77fd9ea021d9849b0e4ed5a1abc26bc9c7a6 100644 (file)
@@ -166,7 +166,7 @@ static void vnt_calculate_ofdm_rate(u16 rate, u8 bb_type,
                        *tx_rate = 0x8b;
                        *rsv_time = 30;
                }
-                       break;
+               break;
        case RATE_9M:
                if (bb_type == BB_TYPE_11A) {
                        *tx_rate = 0x9f;
@@ -674,7 +674,7 @@ void vnt_update_next_tbtt(struct vnt_private *priv, u64 tsf,
  */
 int vnt_radio_power_off(struct vnt_private *priv)
 {
-       int ret = true;
+       int ret = 0;
 
        switch (priv->rf_type) {
        case RF_AL2230:
@@ -683,17 +683,25 @@ int vnt_radio_power_off(struct vnt_private *priv)
        case RF_VT3226:
        case RF_VT3226D0:
        case RF_VT3342A0:
-               vnt_mac_reg_bits_off(priv, MAC_REG_SOFTPWRCTL,
-                                    (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
+               ret = vnt_mac_reg_bits_off(priv, MAC_REG_SOFTPWRCTL,
+                                       (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
                break;
        }
 
-       vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
+       if (ret)
+               goto end;
+
+       ret = vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
+       if (ret)
+               goto end;
 
-       vnt_set_deep_sleep(priv);
+       ret = vnt_set_deep_sleep(priv);
+       if (ret)
+               goto end;
 
-       vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD);
+       ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD);
 
+end:
        return ret;
 }
 
index 38521c338917b628541e23af8ea4913ca1712eaf..60a00af250bffa233a56f7602f913eb52f0da579 100644 (file)
@@ -30,98 +30,87 @@ int vnt_download_firmware(struct vnt_private *priv)
 {
        struct device *dev = &priv->usb->dev;
        const struct firmware *fw;
-       int status;
        void *buffer = NULL;
-       bool result = false;
        u16 length;
-       int ii, rc;
+       int ii;
+       int ret = 0;
 
        dev_dbg(dev, "---->Download firmware\n");
 
-       rc = request_firmware(&fw, FIRMWARE_NAME, dev);
-       if (rc) {
+       ret = request_firmware(&fw, FIRMWARE_NAME, dev);
+       if (ret) {
                dev_err(dev, "firmware file %s request failed (%d)\n",
-                       FIRMWARE_NAME, rc);
-                       goto out;
+                       FIRMWARE_NAME, ret);
+               goto end;
        }
 
        buffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
-       if (!buffer)
+       if (!buffer) {
+               ret = -ENOMEM;
                goto free_fw;
+       }
 
        for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
                length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
                memcpy(buffer, fw->data + ii, length);
 
-               status = vnt_control_out(priv,
-                                        0,
-                                        0x1200 + ii,
-                                        0x0000,
-                                        length,
-                                        buffer);
+               ret = vnt_control_out(priv, 0, 0x1200 + ii, 0x0000, length,
+                                     buffer);
+               if (ret)
+                       goto free_buffer;
 
                dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
-
-               if (status != STATUS_SUCCESS)
-                       goto free_fw;
        }
 
-       result = true;
+free_buffer:
+       kfree(buffer);
 free_fw:
        release_firmware(fw);
-
-out:
-       kfree(buffer);
-
-       return result;
+end:
+       return ret;
 }
 MODULE_FIRMWARE(FIRMWARE_NAME);
 
 int vnt_firmware_branch_to_sram(struct vnt_private *priv)
 {
-       int status;
-
        dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
 
-       status = vnt_control_out(priv,
-                                1,
-                                0x1200,
-                                0x0000,
-                                0,
-                                NULL);
-       return status == STATUS_SUCCESS;
+       return vnt_control_out(priv, 1, 0x1200, 0x0000, 0, NULL);
 }
 
 int vnt_check_firmware_version(struct vnt_private *priv)
 {
-       int status;
-
-       status = vnt_control_in(priv,
-                               MESSAGE_TYPE_READ,
-                               0,
-                               MESSAGE_REQUEST_VERSION,
-                               2,
-                               (u8 *)&priv->firmware_version);
+       int ret = 0;
+
+       ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0,
+                            MESSAGE_REQUEST_VERSION, 2,
+                            (u8 *)&priv->firmware_version);
+       if (ret) {
+               dev_dbg(&priv->usb->dev,
+                       "Could not get firmware version: %d.\n", ret);
+               goto end;
+       }
 
        dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
                priv->firmware_version);
 
-       if (status != STATUS_SUCCESS) {
-               dev_dbg(&priv->usb->dev, "Firmware Invalid.\n");
-               return false;
-       }
        if (priv->firmware_version == 0xFFFF) {
                dev_dbg(&priv->usb->dev, "In Loader.\n");
-               return false;
+               ret = -EINVAL;
+               goto end;
        }
 
-       dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
-               priv->firmware_version);
-
        if (priv->firmware_version < FIRMWARE_VERSION) {
                /* branch to loader for download new firmware */
-               vnt_firmware_branch_to_sram(priv);
-               return false;
+               ret = vnt_firmware_branch_to_sram(priv);
+               if (ret) {
+                       dev_dbg(&priv->usb->dev,
+                               "Could not branch to SRAM: %d.\n", ret);
+               } else {
+                       ret = -EINVAL;
+               }
        }
-       return true;
+
+end:
+       return ret;
 }
index 504424b19fcf9981ceb1a1ff28348ba8e2624c22..f40947955675f098a59b8c25684eb8b74c31e8b1 100644 (file)
@@ -39,18 +39,20 @@ static const u8 fallback_rate1[5][5] = {
        {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
 };
 
-void vnt_int_start_interrupt(struct vnt_private *priv)
+int vnt_int_start_interrupt(struct vnt_private *priv)
 {
+       int ret = 0;
        unsigned long flags;
-       int status;
 
        dev_dbg(&priv->usb->dev, "---->Interrupt Polling Thread\n");
 
        spin_lock_irqsave(&priv->lock, flags);
 
-       status = vnt_start_interrupt_urb(priv);
+       ret = vnt_start_interrupt_urb(priv);
 
        spin_unlock_irqrestore(&priv->lock, flags);
+
+       return ret;
 }
 
 static int vnt_int_report_rate(struct vnt_private *priv, u8 pkt_no, u8 tsr)
index 987c454e99e91c86d4af2236744b5dc9433d8bfc..8a6d60569ceb55b668ecc82b5920ef667eb4b626 100644 (file)
@@ -41,7 +41,7 @@ struct vnt_interrupt_data {
        u8 sw[2];
 } __packed;
 
-void vnt_int_start_interrupt(struct vnt_private *priv);
+int vnt_int_start_interrupt(struct vnt_private *priv);
 void vnt_int_process_data(struct vnt_private *priv);
 
 #endif /* __INT_H__ */
index 0b543854ea972bd6302692484f3b5efb85f60ea8..5cacf6e60e90b4a011f087e60b15cfb19eccf18f 100644 (file)
@@ -129,27 +129,26 @@ void vnt_mac_set_keyentry(struct vnt_private *priv, u16 key_ctl, u32 entry_idx,
                        (u8 *)&set_key);
 }
 
-void vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits)
+int vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits)
 {
        u8 data[2];
 
        data[0] = 0;
        data[1] = bits;
 
-       vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK,
-                       reg_ofs, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data),
-                       data);
+       return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, reg_ofs,
+                              MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
 }
 
-void vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits)
+int vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits)
 {
        u8 data[2];
 
        data[0] = bits;
        data[1] = bits;
 
-       vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, reg_ofs,
-                       MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
+       return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, reg_ofs,
+                              MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
 }
 
 void vnt_mac_write_word(struct vnt_private *priv, u8 reg_ofs, u16 word)
@@ -224,13 +223,13 @@ void vnt_mac_set_beacon_interval(struct vnt_private *priv, u16 interval)
                        MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
 }
 
-void vnt_mac_set_led(struct vnt_private *priv, u8 state, u8 led)
+int vnt_mac_set_led(struct vnt_private *priv, u8 state, u8 led)
 {
        u8 data[2];
 
        data[0] = led;
        data[1] = state;
 
-       vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_PAPEDELAY,
-                       MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
+       return vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_PAPEDELAY,
+                              MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
 }
index 3fd87f95c52420afb6aecfae366a9120b0d58df3..0a42308b81e9cc63af3de1754a9142caaef54270 100644 (file)
@@ -360,8 +360,8 @@ void vnt_mac_set_bb_type(struct vnt_private *priv, u8 type);
 void vnt_mac_disable_keyentry(struct vnt_private *priv, u8 entry_idx);
 void vnt_mac_set_keyentry(struct vnt_private *priv, u16 key_ctl, u32 entry_idx,
                          u32 key_idx, u8 *addr, u8 *key);
-void vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits);
-void vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits);
+int vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits);
+int vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits);
 void vnt_mac_write_word(struct vnt_private *priv, u8 reg_ofs, u16 word);
 void vnt_mac_set_bssid_addr(struct vnt_private *priv, u8 *addr);
 void vnt_mac_enable_protect_mode(struct vnt_private *priv);
@@ -369,6 +369,6 @@ void vnt_mac_disable_protect_mode(struct vnt_private *priv);
 void vnt_mac_enable_barker_preamble_mode(struct vnt_private *priv);
 void vnt_mac_disable_barker_preamble_mode(struct vnt_private *priv);
 void vnt_mac_set_beacon_interval(struct vnt_private *priv, u16 interval);
-void vnt_mac_set_led(struct vnt_private *privpriv, u8 state, u8 led);
+int vnt_mac_set_led(struct vnt_private *privpriv, u8 state, u8 led);
 
 #endif /* __MAC_H__ */
index ccafcc2c87ac980da5f70e52cfa89ad41a0cdf45..856ba97aec4ffaed85744cd22dce4b41544a2876 100644 (file)
@@ -109,33 +109,38 @@ static void vnt_set_options(struct vnt_private *priv)
  */
 static int vnt_init_registers(struct vnt_private *priv)
 {
+       int ret = 0;
        struct vnt_cmd_card_init *init_cmd = &priv->init_command;
        struct vnt_rsp_card_init *init_rsp = &priv->init_response;
        u8 antenna;
        int ii;
-       int status = STATUS_SUCCESS;
        u8 tmp;
        u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0;
 
        dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n",
                DEVICE_INIT_COLD, priv->packet_type);
 
-       if (!vnt_check_firmware_version(priv)) {
-               if (vnt_download_firmware(priv) == true) {
-                       if (vnt_firmware_branch_to_sram(priv) == false) {
-                               dev_dbg(&priv->usb->dev,
-                                       " vnt_firmware_branch_to_sram fail\n");
-                               return false;
-                       }
-               } else {
-                       dev_dbg(&priv->usb->dev, "FIRMWAREbDownload fail\n");
-                       return false;
+       ret = vnt_check_firmware_version(priv);
+       if (ret) {
+               ret = vnt_download_firmware(priv);
+               if (ret) {
+                       dev_dbg(&priv->usb->dev,
+                               "Could not download firmware: %d.\n", ret);
+                       goto end;
+               }
+
+               ret = vnt_firmware_branch_to_sram(priv);
+               if (ret) {
+                       dev_dbg(&priv->usb->dev,
+                               "Could not branch to SRAM: %d.\n", ret);
+                       goto end;
                }
        }
 
-       if (!vnt_vt3184_init(priv)) {
+       ret = vnt_vt3184_init(priv);
+       if (ret) {
                dev_dbg(&priv->usb->dev, "vnt_vt3184_init fail\n");
-               return false;
+               goto end;
        }
 
        init_cmd->init_class = DEVICE_INIT_COLD;
@@ -146,28 +151,27 @@ static int vnt_init_registers(struct vnt_private *priv)
        init_cmd->long_retry_limit = priv->long_retry_limit;
 
        /* issue card_init command to device */
-       status = vnt_control_out(priv, MESSAGE_TYPE_CARDINIT, 0, 0,
-                                sizeof(struct vnt_cmd_card_init),
-                                (u8 *)init_cmd);
-       if (status != STATUS_SUCCESS) {
+       ret = vnt_control_out(priv, MESSAGE_TYPE_CARDINIT, 0, 0,
+                             sizeof(struct vnt_cmd_card_init),
+                             (u8 *)init_cmd);
+       if (ret) {
                dev_dbg(&priv->usb->dev, "Issue Card init fail\n");
-               return false;
+               goto end;
        }
 
-       status = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0,
-                               sizeof(struct vnt_rsp_card_init),
-                               (u8 *)init_rsp);
-       if (status != STATUS_SUCCESS) {
-               dev_dbg(&priv->usb->dev,
-                       "Cardinit request in status fail!\n");
-               return false;
+       ret = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0,
+                            sizeof(struct vnt_rsp_card_init),
+                            (u8 *)init_rsp);
+       if (ret) {
+               dev_dbg(&priv->usb->dev, "Cardinit request in status fail!\n");
+               goto end;
        }
 
        /* local ID for AES functions */
-       status = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_LOCALID,
-                               MESSAGE_REQUEST_MACREG, 1, &priv->local_id);
-       if (status != STATUS_SUCCESS)
-               return false;
+       ret = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_LOCALID,
+                            MESSAGE_REQUEST_MACREG, 1, &priv->local_id);
+       if (ret)
+               goto end;
 
        /* do MACbSoftwareReset in MACvInitialize */
 
@@ -253,7 +257,9 @@ static int vnt_init_registers(struct vnt_private *priv)
        }
 
        /* Set initial antenna mode */
-       vnt_set_antenna_mode(priv, priv->rx_antenna_mode);
+       ret = vnt_set_antenna_mode(priv, priv->rx_antenna_mode);
+       if (ret)
+               goto end;
 
        /* get Auto Fall Back type */
        priv->auto_fb_ctrl = AUTO_FB_0;
@@ -275,33 +281,41 @@ static int vnt_init_registers(struct vnt_private *priv)
                                /* CR255, enable TX/RX IQ and
                                 * DC compensation mode
                                 */
-                               vnt_control_out_u8(priv,
-                                                  MESSAGE_REQUEST_BBREG,
-                                                  0xff,
-                                                  0x03);
+                               ret = vnt_control_out_u8(priv,
+                                                        MESSAGE_REQUEST_BBREG,
+                                                        0xff, 0x03);
+                               if (ret)
+                                       goto end;
+
                                /* CR251, TX I/Q Imbalance Calibration */
-                               vnt_control_out_u8(priv,
-                                                  MESSAGE_REQUEST_BBREG,
-                                                  0xfb,
-                                                  calib_tx_iq);
+                               ret = vnt_control_out_u8(priv,
+                                                        MESSAGE_REQUEST_BBREG,
+                                                        0xfb, calib_tx_iq);
+                               if (ret)
+                                       goto end;
+
                                /* CR252, TX DC-Offset Calibration */
-                               vnt_control_out_u8(priv,
-                                                  MESSAGE_REQUEST_BBREG,
-                                                  0xfC,
-                                                  calib_tx_dc);
+                               ret = vnt_control_out_u8(priv,
+                                                        MESSAGE_REQUEST_BBREG,
+                                                        0xfC, calib_tx_dc);
+                               if (ret)
+                                       goto end;
+
                                /* CR253, RX I/Q Imbalance Calibration */
-                               vnt_control_out_u8(priv,
-                                                  MESSAGE_REQUEST_BBREG,
-                                                  0xfd,
-                                                  calib_rx_iq);
+                               ret = vnt_control_out_u8(priv,
+                                                        MESSAGE_REQUEST_BBREG,
+                                                        0xfd, calib_rx_iq);
+                               if (ret)
+                                       goto end;
                        } else {
                                /* CR255, turn off
                                 * BB Calibration compensation
                                 */
-                               vnt_control_out_u8(priv,
-                                                  MESSAGE_REQUEST_BBREG,
-                                                  0xff,
-                                                  0x0);
+                               ret = vnt_control_out_u8(priv,
+                                                        MESSAGE_REQUEST_BBREG,
+                                                        0xff, 0x0);
+                               if (ret)
+                                       goto end;
                        }
                }
        }
@@ -323,37 +337,52 @@ static int vnt_init_registers(struct vnt_private *priv)
        else
                priv->short_slot_time = false;
 
-       vnt_set_short_slot_time(priv);
+       ret = vnt_set_short_slot_time(priv);
+       if (ret)
+               goto end;
 
        priv->radio_ctl = priv->eeprom[EEP_OFS_RADIOCTL];
 
        if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) {
-               status = vnt_control_in(priv, MESSAGE_TYPE_READ,
-                                       MAC_REG_GPIOCTL1,
-                                       MESSAGE_REQUEST_MACREG, 1, &tmp);
-
-               if (status != STATUS_SUCCESS)
-                       return false;
+               ret = vnt_control_in(priv, MESSAGE_TYPE_READ,
+                                    MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG,
+                                    1, &tmp);
+               if (ret)
+                       goto end;
+
+               if ((tmp & GPIO3_DATA) == 0) {
+                       ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1,
+                                                 GPIO3_INTMD);
+               } else {
+                       ret = vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1,
+                                                  GPIO3_INTMD);
+               }
 
-               if ((tmp & GPIO3_DATA) == 0)
-                       vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1,
-                                           GPIO3_INTMD);
-               else
-                       vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1,
-                                            GPIO3_INTMD);
+               if (ret)
+                       goto end;
        }
 
-       vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38);
 
-       vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
+       ret = vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38);
+       if (ret)
+               goto end;
+
+       ret = vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
+       if (ret)
+               goto end;
 
-       vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, 0x01);
+       ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, 0x01);
+       if (ret)
+               goto end;
 
-       vnt_radio_power_on(priv);
+       ret = vnt_radio_power_on(priv);
+       if (ret)
+               goto end;
 
        dev_dbg(&priv->usb->dev, "<----INIbInitAdapter Exit\n");
 
-       return true;
+end:
+       return ret;
 }
 
 static void vnt_free_tx_bufs(struct vnt_private *priv)
@@ -363,6 +392,9 @@ static void vnt_free_tx_bufs(struct vnt_private *priv)
 
        for (ii = 0; ii < priv->num_tx_context; ii++) {
                tx_context = priv->tx_context[ii];
+               if (!tx_context)
+                       continue;
+
                /* deallocate URBs */
                if (tx_context->urb) {
                        usb_kill_urb(tx_context->urb);
@@ -402,16 +434,19 @@ static void vnt_free_int_bufs(struct vnt_private *priv)
        kfree(priv->int_buf.data_buf);
 }
 
-static bool vnt_alloc_bufs(struct vnt_private *priv)
+static int vnt_alloc_bufs(struct vnt_private *priv)
 {
+       int ret = 0;
        struct vnt_usb_send_context *tx_context;
        struct vnt_rcb *rcb;
        int ii;
 
        for (ii = 0; ii < priv->num_tx_context; ii++) {
                tx_context = kmalloc(sizeof(*tx_context), GFP_KERNEL);
-               if (!tx_context)
+               if (!tx_context) {
+                       ret = -ENOMEM;
                        goto free_tx;
+               }
 
                priv->tx_context[ii] = tx_context;
                tx_context->priv = priv;
@@ -419,16 +454,20 @@ static bool vnt_alloc_bufs(struct vnt_private *priv)
 
                /* allocate URBs */
                tx_context->urb = usb_alloc_urb(0, GFP_KERNEL);
-               if (!tx_context->urb)
+               if (!tx_context->urb) {
+                       ret = -ENOMEM;
                        goto free_tx;
+               }
 
                tx_context->in_use = false;
        }
 
        for (ii = 0; ii < priv->num_rcb; ii++) {
                priv->rcb[ii] = kzalloc(sizeof(*priv->rcb[ii]), GFP_KERNEL);
-               if (!priv->rcb[ii])
+               if (!priv->rcb[ii]) {
+                       ret = -ENOMEM;
                        goto free_rx_tx;
+               }
 
                rcb = priv->rcb[ii];
 
@@ -436,39 +475,46 @@ static bool vnt_alloc_bufs(struct vnt_private *priv)
 
                /* allocate URBs */
                rcb->urb = usb_alloc_urb(0, GFP_KERNEL);
-               if (!rcb->urb)
+               if (!rcb->urb) {
+                       ret = -ENOMEM;
                        goto free_rx_tx;
+               }
 
                rcb->skb = dev_alloc_skb(priv->rx_buf_sz);
-               if (!rcb->skb)
+               if (!rcb->skb) {
+                       ret = -ENOMEM;
                        goto free_rx_tx;
+               }
 
                rcb->in_use = false;
 
                /* submit rx urb */
-               if (vnt_submit_rx_urb(priv, rcb))
+               ret = vnt_submit_rx_urb(priv, rcb);
+               if (ret)
                        goto free_rx_tx;
        }
 
        priv->interrupt_urb = usb_alloc_urb(0, GFP_KERNEL);
-       if (!priv->interrupt_urb)
+       if (!priv->interrupt_urb) {
+               ret = -ENOMEM;
                goto free_rx_tx;
+       }
 
        priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
        if (!priv->int_buf.data_buf) {
-               usb_free_urb(priv->interrupt_urb);
-               goto free_rx_tx;
+               ret = -ENOMEM;
+               goto free_rx_tx_urb;
        }
 
-       return true;
+       return 0;
 
+free_rx_tx_urb:
+       usb_free_urb(priv->interrupt_urb);
 free_rx_tx:
        vnt_free_rx_bufs(priv);
-
 free_tx:
        vnt_free_tx_bufs(priv);
-
-       return false;
+       return ret;
 }
 
 static void vnt_tx_80211(struct ieee80211_hw *hw,
@@ -483,28 +529,34 @@ static void vnt_tx_80211(struct ieee80211_hw *hw,
 
 static int vnt_start(struct ieee80211_hw *hw)
 {
+       int ret = 0;
        struct vnt_private *priv = hw->priv;
 
        priv->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
 
-       if (!vnt_alloc_bufs(priv)) {
+       ret = vnt_alloc_bufs(priv);
+       if (ret) {
                dev_dbg(&priv->usb->dev, "vnt_alloc_bufs fail...\n");
-               return -ENOMEM;
+               goto err;
        }
 
        clear_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags);
 
-       if (vnt_init_registers(priv) == false) {
+       ret = vnt_init_registers(priv);
+       if (ret) {
                dev_dbg(&priv->usb->dev, " init register fail\n");
                goto free_all;
        }
 
-       if (vnt_key_init_table(priv))
+       ret = vnt_key_init_table(priv);
+       if (ret)
                goto free_all;
 
        priv->int_interval = 1;  /* bInterval is set to 1 */
 
-       vnt_int_start_interrupt(priv);
+       ret = vnt_int_start_interrupt(priv);
+       if (ret)
+               goto free_all;
 
        ieee80211_wake_queues(hw);
 
@@ -517,8 +569,8 @@ free_all:
 
        usb_kill_urb(priv->interrupt_urb);
        usb_free_urb(priv->interrupt_urb);
-
-       return -ENOMEM;
+err:
+       return ret;
 }
 
 static void vnt_stop(struct ieee80211_hw *hw)
index 18f75dcc65d2129957cb958f7dd29d554425aae6..43237b7e1dbe1f5f6ae66b564d810556d9d9bc75 100644 (file)
@@ -811,8 +811,9 @@ void vnt_rf_rssi_to_dbm(struct vnt_private *priv, u8 rssi, long *dbm)
        *dbm = -1 * (a + b * 2);
 }
 
-void vnt_rf_table_download(struct vnt_private *priv)
+int vnt_rf_table_download(struct vnt_private *priv)
 {
+       int ret = 0;
        u16 length1 = 0, length2 = 0, length3 = 0;
        u8 *addr1 = NULL, *addr2 = NULL, *addr3 = NULL;
        u16 length, value;
@@ -865,8 +866,10 @@ void vnt_rf_table_download(struct vnt_private *priv)
        /* Init Table */
        memcpy(array, addr1, length1);
 
-       vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
-                       MESSAGE_REQUEST_RF_INIT, length1, array);
+       ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
+                             MESSAGE_REQUEST_RF_INIT, length1, array);
+       if (ret)
+               goto end;
 
        /* Channel Table 0 */
        value = 0;
@@ -878,8 +881,10 @@ void vnt_rf_table_download(struct vnt_private *priv)
 
                memcpy(array, addr2, length);
 
-               vnt_control_out(priv, MESSAGE_TYPE_WRITE,
-                               value, MESSAGE_REQUEST_RF_CH0, length, array);
+               ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, value,
+                                     MESSAGE_REQUEST_RF_CH0, length, array);
+               if (ret)
+                       goto end;
 
                length2 -= length;
                value += length;
@@ -896,8 +901,10 @@ void vnt_rf_table_download(struct vnt_private *priv)
 
                memcpy(array, addr3, length);
 
-               vnt_control_out(priv, MESSAGE_TYPE_WRITE,
-                               value, MESSAGE_REQUEST_RF_CH1, length, array);
+               ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, value,
+                                     MESSAGE_REQUEST_RF_CH1, length, array);
+               if (ret)
+                       goto end;
 
                length3 -= length;
                value += length;
@@ -913,8 +920,10 @@ void vnt_rf_table_download(struct vnt_private *priv)
                memcpy(array, addr1, length1);
 
                /* Init Table 2 */
-               vnt_control_out(priv, MESSAGE_TYPE_WRITE,
-                               0, MESSAGE_REQUEST_RF_INIT2, length1, array);
+               ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
+                                     MESSAGE_REQUEST_RF_INIT2, length1, array);
+               if (ret)
+                       goto end;
 
                /* Channel Table 0 */
                value = 0;
@@ -926,13 +935,18 @@ void vnt_rf_table_download(struct vnt_private *priv)
 
                        memcpy(array, addr2, length);
 
-                       vnt_control_out(priv, MESSAGE_TYPE_WRITE,
-                                       value, MESSAGE_REQUEST_RF_CH2,
-                                       length, array);
+                       ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, value,
+                                             MESSAGE_REQUEST_RF_CH2, length,
+                                             array);
+                       if (ret)
+                               goto end;
 
                        length2 -= length;
                        value += length;
                        addr2 += length;
                }
        }
+
+end:
+       return ret;
 }
index 6103117d6df56e0033c96972e2756c8a4d0ad8b0..7494546d71b8eb5048ce7c1aa1527e27d4a49732 100644 (file)
@@ -44,6 +44,6 @@ int vnt_rf_write_embedded(struct vnt_private *priv, u32 data);
 int vnt_rf_setpower(struct vnt_private *priv, u32 rate, u32 channel);
 int vnt_rf_set_txpower(struct vnt_private *priv, u8 power, u32 rate);
 void vnt_rf_rssi_to_dbm(struct vnt_private *priv, u8 rssi, long *dbm);
-void vnt_rf_table_download(struct vnt_private *priv);
+int vnt_rf_table_download(struct vnt_private *priv);
 
 #endif /* __RF_H__ */
index 5bbc56f8779ee392bea9b9859275bf8bccccfe82..ff351a7a08767de193f5e6b98f2194baf974929b 100644 (file)
 int vnt_control_out(struct vnt_private *priv, u8 request, u16 value,
                    u16 index, u16 length, u8 *buffer)
 {
-       int status = 0;
+       int ret = 0;
        u8 *usb_buffer;
 
-       if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
-               return STATUS_FAILURE;
+       if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags)) {
+               ret = -EINVAL;
+               goto end;
+       }
 
        mutex_lock(&priv->usb_lock);
 
        usb_buffer = kmemdup(buffer, length, GFP_KERNEL);
        if (!usb_buffer) {
-               mutex_unlock(&priv->usb_lock);
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto end_unlock;
        }
 
-       status = usb_control_msg(priv->usb,
-                                usb_sndctrlpipe(priv->usb, 0),
-                                request, 0x40, value,
-                                index, usb_buffer, length, USB_CTL_WAIT);
+       ret = usb_control_msg(priv->usb,
+                             usb_sndctrlpipe(priv->usb, 0),
+                             request, 0x40, value,
+                             index, usb_buffer, length, USB_CTL_WAIT);
 
        kfree(usb_buffer);
 
-       mutex_unlock(&priv->usb_lock);
+       if (ret >= 0 && ret < (int)length)
+               ret = -EIO;
 
-       if (status < (int)length)
-               return STATUS_FAILURE;
-
-       return STATUS_SUCCESS;
+end_unlock:
+       mutex_unlock(&priv->usb_lock);
+end:
+       return ret;
 }
 
-void vnt_control_out_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 data)
+int vnt_control_out_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 data)
 {
-       vnt_control_out(priv, MESSAGE_TYPE_WRITE,
-                       reg_off, reg, sizeof(u8), &data);
+       return vnt_control_out(priv, MESSAGE_TYPE_WRITE,
+                              reg_off, reg, sizeof(u8), &data);
 }
 
 int vnt_control_in(struct vnt_private *priv, u8 request, u16 value,
                   u16 index, u16 length, u8 *buffer)
 {
-       int status;
+       int ret = 0;
        u8 *usb_buffer;
 
-       if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
-               return STATUS_FAILURE;
+       if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags)) {
+               ret = -EINVAL;
+               goto end;
+       }
 
        mutex_lock(&priv->usb_lock);
 
        usb_buffer = kmalloc(length, GFP_KERNEL);
        if (!usb_buffer) {
-               mutex_unlock(&priv->usb_lock);
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto end_unlock;
        }
 
-       status = usb_control_msg(priv->usb,
-                                usb_rcvctrlpipe(priv->usb, 0),
-                                request, 0xc0, value,
-                                index, usb_buffer, length, USB_CTL_WAIT);
+       ret = usb_control_msg(priv->usb,
+                             usb_rcvctrlpipe(priv->usb, 0),
+                             request, 0xc0, value,
+                             index, usb_buffer, length, USB_CTL_WAIT);
 
-       if (status == length)
+       if (ret == length)
                memcpy(buffer, usb_buffer, length);
 
        kfree(usb_buffer);
 
-       mutex_unlock(&priv->usb_lock);
+       if (ret >= 0 && ret < (int)length)
+               ret = -EIO;
 
-       if (status < (int)length)
-               return STATUS_FAILURE;
-
-       return STATUS_SUCCESS;
+end_unlock:
+       mutex_unlock(&priv->usb_lock);
+end:
+       return ret;
 }
 
-void vnt_control_in_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 *data)
+int vnt_control_in_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 *data)
 {
-       vnt_control_in(priv, MESSAGE_TYPE_READ,
-                      reg_off, reg, sizeof(u8), data);
+       return vnt_control_in(priv, MESSAGE_TYPE_READ,
+                             reg_off, reg, sizeof(u8), data);
 }
 
 static void vnt_start_interrupt_urb_complete(struct urb *urb)
@@ -147,10 +153,12 @@ static void vnt_start_interrupt_urb_complete(struct urb *urb)
 
 int vnt_start_interrupt_urb(struct vnt_private *priv)
 {
-       int status = STATUS_FAILURE;
+       int ret = 0;
 
-       if (priv->int_buf.in_use)
-               return STATUS_FAILURE;
+       if (priv->int_buf.in_use) {
+               ret = -EBUSY;
+               goto err;
+       }
 
        priv->int_buf.in_use = true;
 
@@ -163,13 +171,18 @@ int vnt_start_interrupt_urb(struct vnt_private *priv)
                         priv,
                         priv->int_interval);
 
-       status = usb_submit_urb(priv->interrupt_urb, GFP_ATOMIC);
-       if (status) {
-               dev_dbg(&priv->usb->dev, "Submit int URB failed %d\n", status);
-               priv->int_buf.in_use = false;
+       ret = usb_submit_urb(priv->interrupt_urb, GFP_ATOMIC);
+       if (ret) {
+               dev_dbg(&priv->usb->dev, "Submit int URB failed %d\n", ret);
+               goto err_submit;
        }
 
-       return status;
+       return 0;
+
+err_submit:
+       priv->int_buf.in_use = false;
+err:
+       return ret;
 }
 
 static void vnt_submit_rx_urb_complete(struct urb *urb)
@@ -215,12 +228,13 @@ static void vnt_submit_rx_urb_complete(struct urb *urb)
 
 int vnt_submit_rx_urb(struct vnt_private *priv, struct vnt_rcb *rcb)
 {
-       int status = 0;
+       int ret = 0;
        struct urb *urb = rcb->urb;
 
        if (!rcb->skb) {
                dev_dbg(&priv->usb->dev, "rcb->skb is null\n");
-               return status;
+               ret = -EINVAL;
+               goto end;
        }
 
        usb_fill_bulk_urb(urb,
@@ -231,15 +245,16 @@ int vnt_submit_rx_urb(struct vnt_private *priv, struct vnt_rcb *rcb)
                          vnt_submit_rx_urb_complete,
                          rcb);
 
-       status = usb_submit_urb(urb, GFP_ATOMIC);
-       if (status) {
-               dev_dbg(&priv->usb->dev, "Submit Rx URB failed %d\n", status);
-               return STATUS_FAILURE;
+       ret = usb_submit_urb(urb, GFP_ATOMIC);
+       if (ret) {
+               dev_dbg(&priv->usb->dev, "Submit Rx URB failed %d\n", ret);
+               goto end;
        }
 
        rcb->in_use = true;
 
-       return status;
+end:
+       return ret;
 }
 
 static void vnt_tx_context_complete(struct urb *urb)
index 2910ca54886e74930f78f0c6d565d701e5dda85c..95147ec7b96ae8e63af958a7453f231e6a084825 100644 (file)
@@ -23,8 +23,8 @@ int vnt_control_out(struct vnt_private *priv, u8 request, u16 value,
 int vnt_control_in(struct vnt_private *priv, u8 request, u16 value,
                   u16 index, u16 length,  u8 *buffer);
 
-void vnt_control_out_u8(struct vnt_private *priv, u8 reg, u8 ref_off, u8 data);
-void vnt_control_in_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 *data);
+int vnt_control_out_u8(struct vnt_private *priv, u8 reg, u8 ref_off, u8 data);
+int vnt_control_in_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 *data);
 
 int vnt_start_interrupt_urb(struct vnt_private *priv);
 int vnt_submit_rx_urb(struct vnt_private *priv, struct vnt_rcb *rcb);
index 2ad3feed9725ea4d68d14250b2fc5a20f9fc2be0..a5a8e806b98ed988df64b67e4c030e7371d5a9e7 100644 (file)
@@ -5,7 +5,7 @@ ccflags-y += -DFIRMWARE_1002=\"atmel/wilc1002_firmware.bin\" \
                -DFIRMWARE_1003=\"atmel/wilc1003_firmware.bin\"
 
 wilc1000-objs := wilc_wfi_cfgoperations.o wilc_netdev.o wilc_mon.o \
-                       host_interface.o wilc_wlan_cfg.o wilc_wlan.o
+                       wilc_hif.o wilc_wlan_cfg.o wilc_wlan.o
 
 obj-$(CONFIG_WILC1000_SDIO) += wilc1000-sdio.o
 wilc1000-sdio-objs += wilc_sdio.o
diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
deleted file mode 100644 (file)
index ed15bd1..0000000
+++ /dev/null
@@ -1,2137 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
- * All rights reserved.
- */
-
-#include "wilc_wfi_netdevice.h"
-
-#define WILC_HIF_SCAN_TIMEOUT_MS                4000
-#define WILC_HIF_CONNECT_TIMEOUT_MS             9500
-
-#define WILC_FALSE_FRMWR_CHANNEL               100
-#define WILC_MAX_RATES_SUPPORTED               12
-
-struct wilc_rcvd_mac_info {
-       u8 status;
-};
-
-struct wilc_set_multicast {
-       u32 enabled;
-       u32 cnt;
-       u8 *mc_list;
-};
-
-struct wilc_del_all_sta {
-       u8 assoc_sta;
-       u8 mac[WILC_MAX_NUM_STA][ETH_ALEN];
-};
-
-struct wilc_op_mode {
-       __le32 mode;
-};
-
-struct wilc_reg_frame {
-       bool reg;
-       u8 reg_id;
-       __le16 frame_type;
-} __packed;
-
-struct wilc_drv_handler {
-       __le32 handler;
-       u8 mode;
-} __packed;
-
-struct wilc_wep_key {
-       u8 index;
-       u8 key_len;
-       u8 key[0];
-} __packed;
-
-struct wilc_sta_wpa_ptk {
-       u8 mac_addr[ETH_ALEN];
-       u8 key_len;
-       u8 key[0];
-} __packed;
-
-struct wilc_ap_wpa_ptk {
-       u8 mac_addr[ETH_ALEN];
-       u8 index;
-       u8 key_len;
-       u8 key[0];
-} __packed;
-
-struct wilc_gtk_key {
-       u8 mac_addr[ETH_ALEN];
-       u8 rsc[8];
-       u8 index;
-       u8 key_len;
-       u8 key[0];
-} __packed;
-
-union wilc_message_body {
-       struct wilc_rcvd_net_info net_info;
-       struct wilc_rcvd_mac_info mac_info;
-       struct wilc_set_multicast mc_info;
-       struct wilc_remain_ch remain_on_ch;
-       char *data;
-};
-
-struct host_if_msg {
-       union wilc_message_body body;
-       struct wilc_vif *vif;
-       struct work_struct work;
-       void (*fn)(struct work_struct *ws);
-       struct completion work_comp;
-       bool is_sync;
-};
-
-struct wilc_noa_opp_enable {
-       u8 ct_window;
-       u8 cnt;
-       __le32 duration;
-       __le32 interval;
-       __le32 start_time;
-} __packed;
-
-struct wilc_noa_opp_disable {
-       u8 cnt;
-       __le32 duration;
-       __le32 interval;
-       __le32 start_time;
-} __packed;
-
-struct wilc_join_bss_param {
-       char ssid[IEEE80211_MAX_SSID_LEN];
-       u8 ssid_terminator;
-       u8 bss_type;
-       u8 ch;
-       __le16 cap_info;
-       u8 sa[ETH_ALEN];
-       u8 bssid[ETH_ALEN];
-       __le16 beacon_period;
-       u8 dtim_period;
-       u8 supp_rates[WILC_MAX_RATES_SUPPORTED + 1];
-       u8 wmm_cap;
-       u8 uapsd_cap;
-       u8 ht_capable;
-       u8 rsn_found;
-       u8 rsn_grp_policy;
-       u8 mode_802_11i;
-       u8 p_suites[3];
-       u8 akm_suites[3];
-       u8 rsn_cap[2];
-       u8 noa_enabled;
-       __le32 tsf_lo;
-       u8 idx;
-       u8 opp_enabled;
-       union {
-               struct wilc_noa_opp_disable opp_dis;
-               struct wilc_noa_opp_enable opp_en;
-       };
-} __packed;
-
-/* 'msg' should be free by the caller for syc */
-static struct host_if_msg*
-wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *),
-               bool is_sync)
-{
-       struct host_if_msg *msg;
-
-       if (!work_fun)
-               return ERR_PTR(-EINVAL);
-
-       msg = kzalloc(sizeof(*msg), GFP_ATOMIC);
-       if (!msg)
-               return ERR_PTR(-ENOMEM);
-       msg->fn = work_fun;
-       msg->vif = vif;
-       msg->is_sync = is_sync;
-       if (is_sync)
-               init_completion(&msg->work_comp);
-
-       return msg;
-}
-
-static int wilc_enqueue_work(struct host_if_msg *msg)
-{
-       INIT_WORK(&msg->work, msg->fn);
-
-       if (!msg->vif || !msg->vif->wilc || !msg->vif->wilc->hif_workqueue)
-               return -EINVAL;
-
-       if (!queue_work(msg->vif->wilc->hif_workqueue, &msg->work))
-               return -EINVAL;
-
-       return 0;
-}
-
-/* The idx starts from 0 to (NUM_CONCURRENT_IFC - 1), but 0 index used as
- * special purpose in wilc device, so we add 1 to the index to starts from 1.
- * As a result, the returned index will be 1 to NUM_CONCURRENT_IFC.
- */
-int wilc_get_vif_idx(struct wilc_vif *vif)
-{
-       return vif->idx + 1;
-}
-
-/* We need to minus 1 from idx which is from wilc device to get real index
- * of wilc->vif[], because we add 1 when pass to wilc device in the function
- * wilc_get_vif_idx.
- * As a result, the index should be between 0 and (NUM_CONCURRENT_IFC - 1).
- */
-static struct wilc_vif *wilc_get_vif_from_idx(struct wilc *wilc, int idx)
-{
-       int index = idx - 1;
-
-       if (index < 0 || index >= WILC_NUM_CONCURRENT_IFC)
-               return NULL;
-
-       return wilc->vif[index];
-}
-
-static int handle_scan_done(struct wilc_vif *vif, enum scan_event evt)
-{
-       int result = 0;
-       u8 abort_running_scan;
-       struct wid wid;
-       struct host_if_drv *hif_drv = vif->hif_drv;
-       struct wilc_user_scan_req *scan_req;
-
-       if (evt == SCAN_EVENT_ABORTED) {
-               abort_running_scan = 1;
-               wid.id = WID_ABORT_RUNNING_SCAN;
-               wid.type = WID_CHAR;
-               wid.val = (s8 *)&abort_running_scan;
-               wid.size = sizeof(char);
-
-               result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                             wilc_get_vif_idx(vif));
-
-               if (result) {
-                       netdev_err(vif->ndev, "Failed to set abort running\n");
-                       result = -EFAULT;
-               }
-       }
-
-       if (!hif_drv) {
-               netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
-               return result;
-       }
-
-       scan_req = &hif_drv->usr_scan_req;
-       if (scan_req->scan_result) {
-               scan_req->scan_result(evt, NULL, scan_req->arg);
-               scan_req->scan_result = NULL;
-       }
-
-       return result;
-}
-
-int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
-             u8 *ch_freq_list, u8 ch_list_len,
-             void (*scan_result_fn)(enum scan_event,
-                                    struct wilc_rcvd_net_info *, void *),
-             void *user_arg, struct cfg80211_scan_request *request)
-{
-       int result = 0;
-       struct wid wid_list[5];
-       u32 index = 0;
-       u32 i;
-       u8 *buffer;
-       u8 valuesize = 0;
-       u8 *search_ssid_vals = NULL;
-       struct host_if_drv *hif_drv = vif->hif_drv;
-
-       if (hif_drv->hif_state >= HOST_IF_SCANNING &&
-           hif_drv->hif_state < HOST_IF_CONNECTED) {
-               netdev_err(vif->ndev, "Already scan\n");
-               result = -EBUSY;
-               goto error;
-       }
-
-       if (vif->obtaining_ip || vif->connecting) {
-               netdev_err(vif->ndev, "Don't do obss scan\n");
-               result = -EBUSY;
-               goto error;
-       }
-
-       hif_drv->usr_scan_req.ch_cnt = 0;
-
-       if (request->n_ssids) {
-               for (i = 0; i < request->n_ssids; i++)
-                       valuesize += ((request->ssids[i].ssid_len) + 1);
-               search_ssid_vals = kmalloc(valuesize + 1, GFP_KERNEL);
-               if (search_ssid_vals) {
-                       wid_list[index].id = WID_SSID_PROBE_REQ;
-                       wid_list[index].type = WID_STR;
-                       wid_list[index].val = search_ssid_vals;
-                       buffer = wid_list[index].val;
-
-                       *buffer++ = request->n_ssids;
-
-                       for (i = 0; i < request->n_ssids; i++) {
-                               *buffer++ = request->ssids[i].ssid_len;
-                               memcpy(buffer, request->ssids[i].ssid,
-                                      request->ssids[i].ssid_len);
-                               buffer += request->ssids[i].ssid_len;
-                       }
-                       wid_list[index].size = (s32)(valuesize + 1);
-                       index++;
-               }
-       }
-
-       wid_list[index].id = WID_INFO_ELEMENT_PROBE;
-       wid_list[index].type = WID_BIN_DATA;
-       wid_list[index].val = (s8 *)request->ie;
-       wid_list[index].size = request->ie_len;
-       index++;
-
-       wid_list[index].id = WID_SCAN_TYPE;
-       wid_list[index].type = WID_CHAR;
-       wid_list[index].size = sizeof(char);
-       wid_list[index].val = (s8 *)&scan_type;
-       index++;
-
-       wid_list[index].id = WID_SCAN_CHANNEL_LIST;
-       wid_list[index].type = WID_BIN_DATA;
-
-       if (ch_freq_list && ch_list_len > 0) {
-               for (i = 0; i < ch_list_len; i++) {
-                       if (ch_freq_list[i] > 0)
-                               ch_freq_list[i] -= 1;
-               }
-       }
-
-       wid_list[index].val = ch_freq_list;
-       wid_list[index].size = ch_list_len;
-       index++;
-
-       wid_list[index].id = WID_START_SCAN_REQ;
-       wid_list[index].type = WID_CHAR;
-       wid_list[index].size = sizeof(char);
-       wid_list[index].val = (s8 *)&scan_source;
-       index++;
-
-       hif_drv->usr_scan_req.scan_result = scan_result_fn;
-       hif_drv->usr_scan_req.arg = user_arg;
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
-                                     index,
-                                     wilc_get_vif_idx(vif));
-       if (result) {
-               netdev_err(vif->ndev, "Failed to send scan parameters\n");
-               goto error;
-       }
-
-       hif_drv->scan_timer_vif = vif;
-       mod_timer(&hif_drv->scan_timer,
-                 jiffies + msecs_to_jiffies(WILC_HIF_SCAN_TIMEOUT_MS));
-
-error:
-
-       kfree(search_ssid_vals);
-
-       return result;
-}
-
-static int wilc_send_connect_wid(struct wilc_vif *vif)
-{
-       int result = 0;
-       struct wid wid_list[4];
-       u32 wid_cnt = 0;
-       struct host_if_drv *hif_drv = vif->hif_drv;
-       struct wilc_conn_info *conn_attr = &hif_drv->conn_info;
-       struct wilc_join_bss_param *bss_param = conn_attr->param;
-
-       wid_list[wid_cnt].id = WID_INFO_ELEMENT_ASSOCIATE;
-       wid_list[wid_cnt].type = WID_BIN_DATA;
-       wid_list[wid_cnt].val = conn_attr->req_ies;
-       wid_list[wid_cnt].size = conn_attr->req_ies_len;
-       wid_cnt++;
-
-       wid_list[wid_cnt].id = WID_11I_MODE;
-       wid_list[wid_cnt].type = WID_CHAR;
-       wid_list[wid_cnt].size = sizeof(char);
-       wid_list[wid_cnt].val = (s8 *)&conn_attr->security;
-       wid_cnt++;
-
-       wid_list[wid_cnt].id = WID_AUTH_TYPE;
-       wid_list[wid_cnt].type = WID_CHAR;
-       wid_list[wid_cnt].size = sizeof(char);
-       wid_list[wid_cnt].val = (s8 *)&conn_attr->auth_type;
-       wid_cnt++;
-
-       wid_list[wid_cnt].id = WID_JOIN_REQ_EXTENDED;
-       wid_list[wid_cnt].type = WID_STR;
-       wid_list[wid_cnt].size = sizeof(*bss_param);
-       wid_list[wid_cnt].val = (u8 *)bss_param;
-       wid_cnt++;
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
-                                     wid_cnt,
-                                     wilc_get_vif_idx(vif));
-       if (result) {
-               netdev_err(vif->ndev, "failed to send config packet\n");
-               goto error;
-       } else {
-               hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
-       }
-
-       return 0;
-
-error:
-
-       kfree(conn_attr->req_ies);
-       conn_attr->req_ies = NULL;
-
-       return result;
-}
-
-static void handle_connect_timeout(struct work_struct *work)
-{
-       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
-       struct wilc_vif *vif = msg->vif;
-       int result;
-       struct wid wid;
-       u16 dummy_reason_code = 0;
-       struct host_if_drv *hif_drv = vif->hif_drv;
-
-       if (!hif_drv) {
-               netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
-               goto out;
-       }
-
-       hif_drv->hif_state = HOST_IF_IDLE;
-
-       if (hif_drv->conn_info.conn_result) {
-               hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
-                                              WILC_MAC_STATUS_DISCONNECTED,
-                                              hif_drv->conn_info.arg);
-
-       } else {
-               netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
-       }
-
-       wid.id = WID_DISCONNECT;
-       wid.type = WID_CHAR;
-       wid.val = (s8 *)&dummy_reason_code;
-       wid.size = sizeof(char);
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev, "Failed to send disconnect\n");
-
-       hif_drv->conn_info.req_ies_len = 0;
-       kfree(hif_drv->conn_info.req_ies);
-       hif_drv->conn_info.req_ies = NULL;
-
-out:
-       kfree(msg);
-}
-
-void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
-                               struct cfg80211_crypto_settings *crypto)
-{
-       struct wilc_join_bss_param *param;
-       struct ieee80211_p2p_noa_attr noa_attr;
-       u8 rates_len = 0;
-       const u8 *tim_elm, *ssid_elm, *rates_ie, *supp_rates_ie;
-       const u8 *ht_ie, *wpa_ie, *wmm_ie, *rsn_ie;
-       int ret;
-       const struct cfg80211_bss_ies *ies = rcu_dereference(bss->ies);
-
-       param = kzalloc(sizeof(*param), GFP_KERNEL);
-       if (!param)
-               return NULL;
-
-       param->beacon_period = cpu_to_le16(bss->beacon_interval);
-       param->cap_info = cpu_to_le16(bss->capability);
-       param->bss_type = WILC_FW_BSS_TYPE_INFRA;
-       param->ch = ieee80211_frequency_to_channel(bss->channel->center_freq);
-       ether_addr_copy(param->bssid, bss->bssid);
-
-       ssid_elm = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
-       if (ssid_elm) {
-               if (ssid_elm[1] <= IEEE80211_MAX_SSID_LEN)
-                       memcpy(param->ssid, ssid_elm + 2, ssid_elm[1]);
-       }
-
-       tim_elm = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
-       if (tim_elm && tim_elm[1] >= 2)
-               param->dtim_period = tim_elm[3];
-
-       memset(param->p_suites, 0xFF, 3);
-       memset(param->akm_suites, 0xFF, 3);
-
-       rates_ie = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies->data, ies->len);
-       if (rates_ie) {
-               rates_len = rates_ie[1];
-               param->supp_rates[0] = rates_len;
-               memcpy(&param->supp_rates[1], rates_ie + 2, rates_len);
-       }
-
-       supp_rates_ie = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies->data,
-                                        ies->len);
-       if (supp_rates_ie) {
-               if (supp_rates_ie[1] > (WILC_MAX_RATES_SUPPORTED - rates_len))
-                       param->supp_rates[0] = WILC_MAX_RATES_SUPPORTED;
-               else
-                       param->supp_rates[0] += supp_rates_ie[1];
-
-               memcpy(&param->supp_rates[rates_len + 1], supp_rates_ie + 2,
-                      (param->supp_rates[0] - rates_len));
-       }
-
-       ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies->data, ies->len);
-       if (ht_ie)
-               param->ht_capable = true;
-
-       ret = cfg80211_get_p2p_attr(ies->data, ies->len,
-                                   IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
-                                   (u8 *)&noa_attr, sizeof(noa_attr));
-       if (ret > 0) {
-               param->tsf_lo = cpu_to_le32(ies->tsf);
-               param->noa_enabled = 1;
-               param->idx = noa_attr.index;
-               if (noa_attr.oppps_ctwindow & IEEE80211_P2P_OPPPS_ENABLE_BIT) {
-                       param->opp_enabled = 1;
-                       param->opp_en.ct_window = noa_attr.oppps_ctwindow;
-                       param->opp_en.cnt = noa_attr.desc[0].count;
-                       param->opp_en.duration = noa_attr.desc[0].duration;
-                       param->opp_en.interval = noa_attr.desc[0].interval;
-                       param->opp_en.start_time = noa_attr.desc[0].start_time;
-               } else {
-                       param->opp_enabled = 0;
-                       param->opp_dis.cnt = noa_attr.desc[0].count;
-                       param->opp_dis.duration = noa_attr.desc[0].duration;
-                       param->opp_dis.interval = noa_attr.desc[0].interval;
-                       param->opp_dis.start_time = noa_attr.desc[0].start_time;
-               }
-       }
-       wmm_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
-                                        WLAN_OUI_TYPE_MICROSOFT_WMM,
-                                        ies->data, ies->len);
-       if (wmm_ie) {
-               struct ieee80211_wmm_param_ie *ie;
-
-               ie = (struct ieee80211_wmm_param_ie *)wmm_ie;
-               if ((ie->oui_subtype == 0 || ie->oui_subtype == 1) &&
-                   ie->version == 1) {
-                       param->wmm_cap = true;
-                       if (ie->qos_info & BIT(7))
-                               param->uapsd_cap = true;
-               }
-       }
-
-       wpa_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
-                                        WLAN_OUI_TYPE_MICROSOFT_WPA,
-                                        ies->data, ies->len);
-       if (wpa_ie) {
-               param->mode_802_11i = 1;
-               param->rsn_found = true;
-       }
-
-       rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, ies->data, ies->len);
-       if (rsn_ie) {
-               int offset = 8;
-
-               param->mode_802_11i = 2;
-               param->rsn_found = true;
-               //extract RSN capabilities
-               offset += (rsn_ie[offset] * 4) + 2;
-               offset += (rsn_ie[offset] * 4) + 2;
-               memcpy(param->rsn_cap, &rsn_ie[offset], 2);
-       }
-
-       if (param->rsn_found) {
-               int i;
-
-               param->rsn_grp_policy = crypto->cipher_group & 0xFF;
-               for (i = 0; i < crypto->n_ciphers_pairwise && i < 3; i++)
-                       param->p_suites[i] = crypto->ciphers_pairwise[i] & 0xFF;
-
-               for (i = 0; i < crypto->n_akm_suites && i < 3; i++)
-                       param->akm_suites[i] = crypto->akm_suites[i] & 0xFF;
-       }
-
-       return (void *)param;
-}
-
-static void handle_rcvd_ntwrk_info(struct work_struct *work)
-{
-       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
-       struct wilc_rcvd_net_info *rcvd_info = &msg->body.net_info;
-       struct wilc_user_scan_req *scan_req = &msg->vif->hif_drv->usr_scan_req;
-       const u8 *ch_elm;
-       u8 *ies;
-       int ies_len;
-       size_t offset;
-
-       if (ieee80211_is_probe_resp(rcvd_info->mgmt->frame_control))
-               offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
-       else if (ieee80211_is_beacon(rcvd_info->mgmt->frame_control))
-               offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
-       else
-               goto done;
-
-       ies = rcvd_info->mgmt->u.beacon.variable;
-       ies_len = rcvd_info->frame_len - offset;
-       if (ies_len <= 0)
-               goto done;
-
-       ch_elm = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ies, ies_len);
-       if (ch_elm && ch_elm[1] > 0)
-               rcvd_info->ch = ch_elm[2];
-
-       if (scan_req->scan_result)
-               scan_req->scan_result(SCAN_EVENT_NETWORK_FOUND, rcvd_info,
-                                     scan_req->arg);
-
-done:
-       kfree(rcvd_info->mgmt);
-       kfree(msg);
-}
-
-static void host_int_get_assoc_res_info(struct wilc_vif *vif,
-                                       u8 *assoc_resp_info,
-                                       u32 max_assoc_resp_info_len,
-                                       u32 *rcvd_assoc_resp_info_len)
-{
-       int result;
-       struct wid wid;
-
-       wid.id = WID_ASSOC_RES_INFO;
-       wid.type = WID_STR;
-       wid.val = assoc_resp_info;
-       wid.size = max_assoc_resp_info_len;
-
-       result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result) {
-               *rcvd_assoc_resp_info_len = 0;
-               netdev_err(vif->ndev, "Failed to send association response\n");
-               return;
-       }
-
-       *rcvd_assoc_resp_info_len = wid.size;
-}
-
-static s32 wilc_parse_assoc_resp_info(u8 *buffer, u32 buffer_len,
-                                     struct wilc_conn_info *ret_conn_info)
-{
-       u8 *ies;
-       u16 ies_len;
-       struct assoc_resp *res = (struct assoc_resp *)buffer;
-
-       ret_conn_info->status = le16_to_cpu(res->status_code);
-       if (ret_conn_info->status == WLAN_STATUS_SUCCESS) {
-               ies = &buffer[sizeof(*res)];
-               ies_len = buffer_len - sizeof(*res);
-
-               ret_conn_info->resp_ies = kmemdup(ies, ies_len, GFP_KERNEL);
-               if (!ret_conn_info->resp_ies)
-                       return -ENOMEM;
-
-               ret_conn_info->resp_ies_len = ies_len;
-       }
-
-       return 0;
-}
-
-static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
-                                                 u8 mac_status)
-{
-       struct host_if_drv *hif_drv = vif->hif_drv;
-       struct wilc_conn_info *conn_info = &hif_drv->conn_info;
-
-       if (mac_status == WILC_MAC_STATUS_CONNECTED) {
-               u32 assoc_resp_info_len;
-
-               memset(hif_drv->assoc_resp, 0, WILC_MAX_ASSOC_RESP_FRAME_SIZE);
-
-               host_int_get_assoc_res_info(vif, hif_drv->assoc_resp,
-                                           WILC_MAX_ASSOC_RESP_FRAME_SIZE,
-                                           &assoc_resp_info_len);
-
-               if (assoc_resp_info_len != 0) {
-                       s32 err = 0;
-
-                       err = wilc_parse_assoc_resp_info(hif_drv->assoc_resp,
-                                                        assoc_resp_info_len,
-                                                        conn_info);
-                       if (err)
-                               netdev_err(vif->ndev,
-                                          "wilc_parse_assoc_resp_info() returned error %d\n",
-                                          err);
-               }
-       }
-
-       del_timer(&hif_drv->connect_timer);
-       conn_info->conn_result(CONN_DISCONN_EVENT_CONN_RESP, mac_status,
-                              hif_drv->conn_info.arg);
-
-       if (mac_status == WILC_MAC_STATUS_CONNECTED &&
-           conn_info->status == WLAN_STATUS_SUCCESS) {
-               ether_addr_copy(hif_drv->assoc_bssid, conn_info->bssid);
-               wilc_set_power_mgmt(vif, 0, 0);
-
-               hif_drv->hif_state = HOST_IF_CONNECTED;
-
-               vif->obtaining_ip = true;
-               mod_timer(&vif->during_ip_timer,
-                         jiffies + msecs_to_jiffies(10000));
-       } else {
-               hif_drv->hif_state = HOST_IF_IDLE;
-       }
-
-       kfree(conn_info->resp_ies);
-       conn_info->resp_ies = NULL;
-       conn_info->resp_ies_len = 0;
-
-       kfree(conn_info->req_ies);
-       conn_info->req_ies = NULL;
-       conn_info->req_ies_len = 0;
-}
-
-static inline void host_int_handle_disconnect(struct wilc_vif *vif)
-{
-       struct host_if_drv *hif_drv = vif->hif_drv;
-
-       if (hif_drv->usr_scan_req.scan_result) {
-               del_timer(&hif_drv->scan_timer);
-               handle_scan_done(vif, SCAN_EVENT_ABORTED);
-       }
-
-       if (hif_drv->conn_info.conn_result) {
-               vif->obtaining_ip = false;
-               wilc_set_power_mgmt(vif, 0, 0);
-
-               hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
-                                              0, hif_drv->conn_info.arg);
-       } else {
-               netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
-       }
-
-       eth_zero_addr(hif_drv->assoc_bssid);
-
-       hif_drv->conn_info.req_ies_len = 0;
-       kfree(hif_drv->conn_info.req_ies);
-       hif_drv->conn_info.req_ies = NULL;
-       hif_drv->hif_state = HOST_IF_IDLE;
-}
-
-static void handle_rcvd_gnrl_async_info(struct work_struct *work)
-{
-       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
-       struct wilc_vif *vif = msg->vif;
-       struct wilc_rcvd_mac_info *mac_info = &msg->body.mac_info;
-       struct host_if_drv *hif_drv = vif->hif_drv;
-
-       if (!hif_drv) {
-               netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
-               goto free_msg;
-       }
-
-       if (!hif_drv->conn_info.conn_result) {
-               netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
-               goto free_msg;
-       }
-
-       if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
-               host_int_parse_assoc_resp_info(vif, mac_info->status);
-       } else if (mac_info->status == WILC_MAC_STATUS_DISCONNECTED) {
-               if (hif_drv->hif_state == HOST_IF_CONNECTED) {
-                       host_int_handle_disconnect(vif);
-               } else if (hif_drv->usr_scan_req.scan_result) {
-                       del_timer(&hif_drv->scan_timer);
-                       handle_scan_done(vif, SCAN_EVENT_ABORTED);
-               }
-       }
-
-free_msg:
-       kfree(msg);
-}
-
-int wilc_disconnect(struct wilc_vif *vif)
-{
-       struct wid wid;
-       struct host_if_drv *hif_drv = vif->hif_drv;
-       struct wilc_user_scan_req *scan_req;
-       struct wilc_conn_info *conn_info;
-       int result;
-       u16 dummy_reason_code = 0;
-
-       wid.id = WID_DISCONNECT;
-       wid.type = WID_CHAR;
-       wid.val = (s8 *)&dummy_reason_code;
-       wid.size = sizeof(char);
-
-       vif->obtaining_ip = false;
-       wilc_set_power_mgmt(vif, 0, 0);
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result) {
-               netdev_err(vif->ndev, "Failed to send disconnect\n");
-               return result;
-       }
-
-       scan_req = &hif_drv->usr_scan_req;
-       conn_info = &hif_drv->conn_info;
-
-       if (scan_req->scan_result) {
-               del_timer(&hif_drv->scan_timer);
-               scan_req->scan_result(SCAN_EVENT_ABORTED, NULL, scan_req->arg);
-               scan_req->scan_result = NULL;
-       }
-
-       if (conn_info->conn_result) {
-               if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
-                       del_timer(&hif_drv->connect_timer);
-
-               conn_info->conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, 0,
-                                      conn_info->arg);
-       } else {
-               netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
-       }
-
-       hif_drv->hif_state = HOST_IF_IDLE;
-
-       eth_zero_addr(hif_drv->assoc_bssid);
-
-       conn_info->req_ies_len = 0;
-       kfree(conn_info->req_ies);
-       conn_info->req_ies = NULL;
-
-       return 0;
-}
-
-void wilc_resolve_disconnect_aberration(struct wilc_vif *vif)
-{
-       if (!vif->hif_drv)
-               return;
-       if (vif->hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP ||
-           vif->hif_drv->hif_state == HOST_IF_CONNECTING)
-               wilc_disconnect(vif);
-}
-
-int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
-{
-       struct wid wid_list[5];
-       u32 wid_cnt = 0, result;
-
-       wid_list[wid_cnt].id = WID_LINKSPEED;
-       wid_list[wid_cnt].type = WID_CHAR;
-       wid_list[wid_cnt].size = sizeof(char);
-       wid_list[wid_cnt].val = (s8 *)&stats->link_speed;
-       wid_cnt++;
-
-       wid_list[wid_cnt].id = WID_RSSI;
-       wid_list[wid_cnt].type = WID_CHAR;
-       wid_list[wid_cnt].size = sizeof(char);
-       wid_list[wid_cnt].val = (s8 *)&stats->rssi;
-       wid_cnt++;
-
-       wid_list[wid_cnt].id = WID_SUCCESS_FRAME_COUNT;
-       wid_list[wid_cnt].type = WID_INT;
-       wid_list[wid_cnt].size = sizeof(u32);
-       wid_list[wid_cnt].val = (s8 *)&stats->tx_cnt;
-       wid_cnt++;
-
-       wid_list[wid_cnt].id = WID_RECEIVED_FRAGMENT_COUNT;
-       wid_list[wid_cnt].type = WID_INT;
-       wid_list[wid_cnt].size = sizeof(u32);
-       wid_list[wid_cnt].val = (s8 *)&stats->rx_cnt;
-       wid_cnt++;
-
-       wid_list[wid_cnt].id = WID_FAILED_COUNT;
-       wid_list[wid_cnt].type = WID_INT;
-       wid_list[wid_cnt].size = sizeof(u32);
-       wid_list[wid_cnt].val = (s8 *)&stats->tx_fail_cnt;
-       wid_cnt++;
-
-       result = wilc_send_config_pkt(vif, WILC_GET_CFG, wid_list,
-                                     wid_cnt,
-                                     wilc_get_vif_idx(vif));
-
-       if (result) {
-               netdev_err(vif->ndev, "Failed to send scan parameters\n");
-               return result;
-       }
-
-       if (stats->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
-           stats->link_speed != DEFAULT_LINK_SPEED)
-               wilc_enable_tcp_ack_filter(vif, true);
-       else if (stats->link_speed != DEFAULT_LINK_SPEED)
-               wilc_enable_tcp_ack_filter(vif, false);
-
-       return result;
-}
-
-static void handle_get_statistics(struct work_struct *work)
-{
-       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
-       struct wilc_vif *vif = msg->vif;
-       struct rf_info *stats = (struct rf_info *)msg->body.data;
-
-       wilc_get_statistics(vif, stats);
-
-       kfree(msg);
-}
-
-static void wilc_hif_pack_sta_param(u8 *cur_byte, const u8 *mac,
-                                   struct station_parameters *params)
-{
-       ether_addr_copy(cur_byte, mac);
-       cur_byte += ETH_ALEN;
-
-       put_unaligned_le16(params->aid, cur_byte);
-       cur_byte += 2;
-
-       *cur_byte++ = params->supported_rates_len;
-       if (params->supported_rates_len > 0)
-               memcpy(cur_byte, params->supported_rates,
-                      params->supported_rates_len);
-       cur_byte += params->supported_rates_len;
-
-       if (params->ht_capa) {
-               *cur_byte++ = true;
-               memcpy(cur_byte, &params->ht_capa,
-                      sizeof(struct ieee80211_ht_cap));
-       } else {
-               *cur_byte++ = false;
-       }
-       cur_byte += sizeof(struct ieee80211_ht_cap);
-
-       put_unaligned_le16(params->sta_flags_mask, cur_byte);
-       cur_byte += 2;
-       put_unaligned_le16(params->sta_flags_set, cur_byte);
-}
-
-static int handle_remain_on_chan(struct wilc_vif *vif,
-                                struct wilc_remain_ch *hif_remain_ch)
-{
-       int result;
-       u8 remain_on_chan_flag;
-       struct wid wid;
-       struct host_if_drv *hif_drv = vif->hif_drv;
-
-       if (hif_drv->usr_scan_req.scan_result)
-               return -EBUSY;
-
-       if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
-               return -EBUSY;
-
-       if (vif->obtaining_ip || vif->connecting)
-               return -EBUSY;
-
-       remain_on_chan_flag = true;
-       wid.id = WID_REMAIN_ON_CHAN;
-       wid.type = WID_STR;
-       wid.size = 2;
-       wid.val = kmalloc(wid.size, GFP_KERNEL);
-       if (!wid.val)
-               return -ENOMEM;
-
-       wid.val[0] = remain_on_chan_flag;
-       wid.val[1] = (s8)hif_remain_ch->ch;
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       kfree(wid.val);
-       if (result)
-               return -EBUSY;
-
-       hif_drv->remain_on_ch.arg = hif_remain_ch->arg;
-       hif_drv->remain_on_ch.expired = hif_remain_ch->expired;
-       hif_drv->remain_on_ch.ch = hif_remain_ch->ch;
-       hif_drv->remain_on_ch.cookie = hif_remain_ch->cookie;
-       hif_drv->remain_on_ch_timer_vif = vif;
-
-       return 0;
-}
-
-static void handle_listen_state_expired(struct work_struct *work)
-{
-       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
-       struct wilc_vif *vif = msg->vif;
-       struct wilc_remain_ch *hif_remain_ch = &msg->body.remain_on_ch;
-       u8 remain_on_chan_flag;
-       struct wid wid;
-       int result;
-       struct host_if_drv *hif_drv = vif->hif_drv;
-       struct wilc_priv *priv = wdev_priv(vif->ndev->ieee80211_ptr);
-
-       if (priv->p2p_listen_state) {
-               remain_on_chan_flag = false;
-               wid.id = WID_REMAIN_ON_CHAN;
-               wid.type = WID_STR;
-               wid.size = 2;
-               wid.val = kmalloc(wid.size, GFP_KERNEL);
-
-               if (!wid.val)
-                       goto free_msg;
-
-               wid.val[0] = remain_on_chan_flag;
-               wid.val[1] = WILC_FALSE_FRMWR_CHANNEL;
-
-               result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                             wilc_get_vif_idx(vif));
-               kfree(wid.val);
-               if (result != 0) {
-                       netdev_err(vif->ndev, "Failed to set remain channel\n");
-                       goto free_msg;
-               }
-
-               if (hif_drv->remain_on_ch.expired) {
-                       hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg,
-                                                     hif_remain_ch->cookie);
-               }
-       } else {
-               netdev_dbg(vif->ndev, "Not in listen state\n");
-       }
-
-free_msg:
-       kfree(msg);
-}
-
-static void listen_timer_cb(struct timer_list *t)
-{
-       struct host_if_drv *hif_drv = from_timer(hif_drv, t,
-                                                     remain_on_ch_timer);
-       struct wilc_vif *vif = hif_drv->remain_on_ch_timer_vif;
-       int result;
-       struct host_if_msg *msg;
-
-       del_timer(&vif->hif_drv->remain_on_ch_timer);
-
-       msg = wilc_alloc_work(vif, handle_listen_state_expired, false);
-       if (IS_ERR(msg))
-               return;
-
-       msg->body.remain_on_ch.cookie = vif->hif_drv->remain_on_ch.cookie;
-
-       result = wilc_enqueue_work(msg);
-       if (result) {
-               netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
-               kfree(msg);
-       }
-}
-
-static void handle_set_mcast_filter(struct work_struct *work)
-{
-       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
-       struct wilc_vif *vif = msg->vif;
-       struct wilc_set_multicast *set_mc = &msg->body.mc_info;
-       int result;
-       struct wid wid;
-       u8 *cur_byte;
-
-       wid.id = WID_SETUP_MULTICAST_FILTER;
-       wid.type = WID_BIN;
-       wid.size = sizeof(struct wilc_set_multicast) + (set_mc->cnt * ETH_ALEN);
-       wid.val = kmalloc(wid.size, GFP_KERNEL);
-       if (!wid.val)
-               goto error;
-
-       cur_byte = wid.val;
-       put_unaligned_le32(set_mc->enabled, cur_byte);
-       cur_byte += 4;
-
-       put_unaligned_le32(set_mc->cnt, cur_byte);
-       cur_byte += 4;
-
-       if (set_mc->cnt > 0 && set_mc->mc_list)
-               memcpy(cur_byte, set_mc->mc_list, set_mc->cnt * ETH_ALEN);
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev, "Failed to send setup multicast\n");
-
-error:
-       kfree(set_mc->mc_list);
-       kfree(wid.val);
-       kfree(msg);
-}
-
-static void handle_scan_timer(struct work_struct *work)
-{
-       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
-
-       handle_scan_done(msg->vif, SCAN_EVENT_ABORTED);
-       kfree(msg);
-}
-
-static void handle_scan_complete(struct work_struct *work)
-{
-       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
-       struct wilc *wilc = msg->vif->wilc;
-
-       del_timer(&msg->vif->hif_drv->scan_timer);
-
-       if (!wilc_wlan_get_num_conn_ifcs(wilc))
-               wilc_chip_sleep_manually(wilc);
-
-       handle_scan_done(msg->vif, SCAN_EVENT_DONE);
-
-       kfree(msg);
-}
-
-static void timer_scan_cb(struct timer_list *t)
-{
-       struct host_if_drv *hif_drv = from_timer(hif_drv, t, scan_timer);
-       struct wilc_vif *vif = hif_drv->scan_timer_vif;
-       struct host_if_msg *msg;
-       int result;
-
-       msg = wilc_alloc_work(vif, handle_scan_timer, false);
-       if (IS_ERR(msg))
-               return;
-
-       result = wilc_enqueue_work(msg);
-       if (result)
-               kfree(msg);
-}
-
-static void timer_connect_cb(struct timer_list *t)
-{
-       struct host_if_drv *hif_drv = from_timer(hif_drv, t,
-                                                     connect_timer);
-       struct wilc_vif *vif = hif_drv->connect_timer_vif;
-       struct host_if_msg *msg;
-       int result;
-
-       msg = wilc_alloc_work(vif, handle_connect_timeout, false);
-       if (IS_ERR(msg))
-               return;
-
-       result = wilc_enqueue_work(msg);
-       if (result)
-               kfree(msg);
-}
-
-int wilc_remove_wep_key(struct wilc_vif *vif, u8 index)
-{
-       struct wid wid;
-       int result;
-
-       wid.id = WID_REMOVE_WEP_KEY;
-       wid.type = WID_STR;
-       wid.size = sizeof(char);
-       wid.val = &index;
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev,
-                          "Failed to send remove wep key config packet\n");
-       return result;
-}
-
-int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index)
-{
-       struct wid wid;
-       int result;
-
-       wid.id = WID_KEY_ID;
-       wid.type = WID_CHAR;
-       wid.size = sizeof(char);
-       wid.val = &index;
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev,
-                          "Failed to send wep default key config packet\n");
-
-       return result;
-}
-
-int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
-                            u8 index)
-{
-       struct wid wid;
-       int result;
-       struct wilc_wep_key *wep_key;
-
-       wid.id = WID_ADD_WEP_KEY;
-       wid.type = WID_STR;
-       wid.size = sizeof(*wep_key) + len;
-       wep_key = kzalloc(wid.size, GFP_KERNEL);
-       if (!wep_key)
-               return -ENOMEM;
-
-       wid.val = (u8 *)wep_key;
-
-       wep_key->index = index;
-       wep_key->key_len = len;
-       memcpy(wep_key->key, key, len);
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev,
-                          "Failed to add wep key config packet\n");
-
-       kfree(wep_key);
-       return result;
-}
-
-int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
-                           u8 index, u8 mode, enum authtype auth_type)
-{
-       struct wid wid_list[3];
-       int result;
-       struct wilc_wep_key *wep_key;
-
-       wid_list[0].id = WID_11I_MODE;
-       wid_list[0].type = WID_CHAR;
-       wid_list[0].size = sizeof(char);
-       wid_list[0].val = &mode;
-
-       wid_list[1].id = WID_AUTH_TYPE;
-       wid_list[1].type = WID_CHAR;
-       wid_list[1].size = sizeof(char);
-       wid_list[1].val = (s8 *)&auth_type;
-
-       wid_list[2].id = WID_WEP_KEY_VALUE;
-       wid_list[2].type = WID_STR;
-       wid_list[2].size = sizeof(*wep_key) + len;
-       wep_key = kzalloc(wid_list[2].size, GFP_KERNEL);
-       if (!wep_key)
-               return -ENOMEM;
-
-       wid_list[2].val = (u8 *)wep_key;
-
-       wep_key->index = index;
-       wep_key->key_len = len;
-       memcpy(wep_key->key, key, len);
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
-                                     ARRAY_SIZE(wid_list),
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev,
-                          "Failed to add wep ap key config packet\n");
-
-       kfree(wep_key);
-       return result;
-}
-
-int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
-                const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic,
-                u8 mode, u8 cipher_mode, u8 index)
-{
-       int result = 0;
-       u8 t_key_len  = ptk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
-
-       if (mode == WILC_AP_MODE) {
-               struct wid wid_list[2];
-               struct wilc_ap_wpa_ptk *key_buf;
-
-               wid_list[0].id = WID_11I_MODE;
-               wid_list[0].type = WID_CHAR;
-               wid_list[0].size = sizeof(char);
-               wid_list[0].val = (s8 *)&cipher_mode;
-
-               key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
-               if (!key_buf)
-                       return -ENOMEM;
-
-               ether_addr_copy(key_buf->mac_addr, mac_addr);
-               key_buf->index = index;
-               key_buf->key_len = t_key_len;
-               memcpy(&key_buf->key[0], ptk, ptk_key_len);
-
-               if (rx_mic)
-                       memcpy(&key_buf->key[ptk_key_len], rx_mic,
-                              WILC_RX_MIC_KEY_LEN);
-
-               if (tx_mic)
-                       memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
-                              tx_mic, WILC_TX_MIC_KEY_LEN);
-
-               wid_list[1].id = WID_ADD_PTK;
-               wid_list[1].type = WID_STR;
-               wid_list[1].size = sizeof(*key_buf) + t_key_len;
-               wid_list[1].val = (u8 *)key_buf;
-               result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
-                                             ARRAY_SIZE(wid_list),
-                                             wilc_get_vif_idx(vif));
-               kfree(key_buf);
-       } else if (mode == WILC_STATION_MODE) {
-               struct wid wid;
-               struct wilc_sta_wpa_ptk *key_buf;
-
-               key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
-               if (!key_buf)
-                       return -ENOMEM;
-
-               ether_addr_copy(key_buf->mac_addr, mac_addr);
-               key_buf->key_len = t_key_len;
-               memcpy(&key_buf->key[0], ptk, ptk_key_len);
-
-               if (rx_mic)
-                       memcpy(&key_buf->key[ptk_key_len], rx_mic,
-                              WILC_RX_MIC_KEY_LEN);
-
-               if (tx_mic)
-                       memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
-                              tx_mic, WILC_TX_MIC_KEY_LEN);
-
-               wid.id = WID_ADD_PTK;
-               wid.type = WID_STR;
-               wid.size = sizeof(*key_buf) + t_key_len;
-               wid.val = (s8 *)key_buf;
-               result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                             wilc_get_vif_idx(vif));
-               kfree(key_buf);
-       }
-
-       return result;
-}
-
-int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
-                   u8 index, u32 key_rsc_len, const u8 *key_rsc,
-                   const u8 *rx_mic, const u8 *tx_mic, u8 mode,
-                   u8 cipher_mode)
-{
-       int result = 0;
-       struct wilc_gtk_key *gtk_key;
-       int t_key_len = gtk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
-
-       gtk_key = kzalloc(sizeof(*gtk_key) + t_key_len, GFP_KERNEL);
-       if (!gtk_key)
-               return -ENOMEM;
-
-       /* fill bssid value only in station mode */
-       if (mode == WILC_STATION_MODE &&
-           vif->hif_drv->hif_state == HOST_IF_CONNECTED)
-               memcpy(gtk_key->mac_addr, vif->hif_drv->assoc_bssid, ETH_ALEN);
-
-       if (key_rsc)
-               memcpy(gtk_key->rsc, key_rsc, 8);
-       gtk_key->index = index;
-       gtk_key->key_len = t_key_len;
-       memcpy(&gtk_key->key[0], rx_gtk, gtk_key_len);
-
-       if (rx_mic)
-               memcpy(&gtk_key->key[gtk_key_len], rx_mic, WILC_RX_MIC_KEY_LEN);
-
-       if (tx_mic)
-               memcpy(&gtk_key->key[gtk_key_len + WILC_RX_MIC_KEY_LEN],
-                      tx_mic, WILC_TX_MIC_KEY_LEN);
-
-       if (mode == WILC_AP_MODE) {
-               struct wid wid_list[2];
-
-               wid_list[0].id = WID_11I_MODE;
-               wid_list[0].type = WID_CHAR;
-               wid_list[0].size = sizeof(char);
-               wid_list[0].val = (s8 *)&cipher_mode;
-
-               wid_list[1].id = WID_ADD_RX_GTK;
-               wid_list[1].type = WID_STR;
-               wid_list[1].size = sizeof(*gtk_key) + t_key_len;
-               wid_list[1].val = (u8 *)gtk_key;
-
-               result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
-                                             ARRAY_SIZE(wid_list),
-                                             wilc_get_vif_idx(vif));
-       } else if (mode == WILC_STATION_MODE) {
-               struct wid wid;
-
-               wid.id = WID_ADD_RX_GTK;
-               wid.type = WID_STR;
-               wid.size = sizeof(*gtk_key) + t_key_len;
-               wid.val = (u8 *)gtk_key;
-               result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                             wilc_get_vif_idx(vif));
-       }
-
-       kfree(gtk_key);
-       return result;
-}
-
-int wilc_set_pmkid_info(struct wilc_vif *vif, struct wilc_pmkid_attr *pmkid)
-{
-       struct wid wid;
-
-       wid.id = WID_PMKID_INFO;
-       wid.type = WID_STR;
-       wid.size = (pmkid->numpmkid * sizeof(struct wilc_pmkid)) + 1;
-       wid.val = (u8 *)pmkid;
-
-       return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                   wilc_get_vif_idx(vif));
-}
-
-int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)
-{
-       int result;
-       struct wid wid;
-
-       wid.id = WID_MAC_ADDR;
-       wid.type = WID_STR;
-       wid.size = ETH_ALEN;
-       wid.val = mac_addr;
-
-       result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev, "Failed to get mac address\n");
-
-       return result;
-}
-
-int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ies,
-                     size_t ies_len)
-{
-       int result;
-       struct host_if_drv *hif_drv = vif->hif_drv;
-       struct wilc_conn_info *conn_info = &hif_drv->conn_info;
-
-       if (bssid)
-               ether_addr_copy(conn_info->bssid, bssid);
-
-       if (ies) {
-               conn_info->req_ies_len = ies_len;
-               conn_info->req_ies = kmemdup(ies, ies_len, GFP_KERNEL);
-               if (!conn_info->req_ies)
-                       return -ENOMEM;
-       }
-
-       result = wilc_send_connect_wid(vif);
-       if (result)
-               goto free_ies;
-
-       hif_drv->connect_timer_vif = vif;
-       mod_timer(&hif_drv->connect_timer,
-                 jiffies + msecs_to_jiffies(WILC_HIF_CONNECT_TIMEOUT_MS));
-
-       return 0;
-
-free_ies:
-       kfree(conn_info->req_ies);
-
-       return result;
-}
-
-int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
-{
-       struct wid wid;
-       int result;
-
-       wid.id = WID_CURRENT_CHANNEL;
-       wid.type = WID_CHAR;
-       wid.size = sizeof(char);
-       wid.val = &channel;
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev, "Failed to set channel\n");
-
-       return result;
-}
-
-int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
-                            u8 ifc_id)
-{
-       struct wid wid;
-       struct host_if_drv *hif_drv = vif->hif_drv;
-       int result;
-       struct wilc_drv_handler drv;
-
-       if (!hif_drv)
-               return -EFAULT;
-
-       wid.id = WID_SET_DRV_HANDLER;
-       wid.type = WID_STR;
-       wid.size = sizeof(drv);
-       wid.val = (u8 *)&drv;
-
-       drv.handler = cpu_to_le32(index);
-       drv.mode = (ifc_id | (mode << 1));
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     hif_drv->driver_handler_id);
-       if (result)
-               netdev_err(vif->ndev, "Failed to set driver handler\n");
-
-       return result;
-}
-
-int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode)
-{
-       struct wid wid;
-       struct wilc_op_mode op_mode;
-       int result;
-
-       wid.id = WID_SET_OPERATION_MODE;
-       wid.type = WID_INT;
-       wid.size = sizeof(op_mode);
-       wid.val = (u8 *)&op_mode;
-
-       op_mode.mode = cpu_to_le32(mode);
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev, "Failed to set operation mode\n");
-
-       return result;
-}
-
-s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac, u32 *out_val)
-{
-       struct wid wid;
-       s32 result;
-
-       wid.id = WID_SET_STA_MAC_INACTIVE_TIME;
-       wid.type = WID_STR;
-       wid.size = ETH_ALEN;
-       wid.val = kzalloc(wid.size, GFP_KERNEL);
-       if (!wid.val)
-               return -ENOMEM;
-
-       ether_addr_copy(wid.val, mac);
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       kfree(wid.val);
-       if (result) {
-               netdev_err(vif->ndev, "Failed to set inactive mac\n");
-               return result;
-       }
-
-       wid.id = WID_GET_INACTIVE_TIME;
-       wid.type = WID_INT;
-       wid.val = (s8 *)out_val;
-       wid.size = sizeof(u32);
-       result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev, "Failed to get inactive time\n");
-
-       return result;
-}
-
-int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
-{
-       struct wid wid;
-       int result;
-
-       if (!rssi_level) {
-               netdev_err(vif->ndev, "%s: RSSI level is NULL\n", __func__);
-               return -EFAULT;
-       }
-
-       wid.id = WID_RSSI;
-       wid.type = WID_CHAR;
-       wid.size = sizeof(char);
-       wid.val = rssi_level;
-       result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev, "Failed to get RSSI value\n");
-
-       return result;
-}
-
-static int wilc_get_stats_async(struct wilc_vif *vif, struct rf_info *stats)
-{
-       int result;
-       struct host_if_msg *msg;
-
-       msg = wilc_alloc_work(vif, handle_get_statistics, false);
-       if (IS_ERR(msg))
-               return PTR_ERR(msg);
-
-       msg->body.data = (char *)stats;
-
-       result = wilc_enqueue_work(msg);
-       if (result) {
-               netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
-               kfree(msg);
-               return result;
-       }
-
-       return result;
-}
-
-int wilc_hif_set_cfg(struct wilc_vif *vif, struct cfg_param_attr *param)
-{
-       struct wid wid_list[4];
-       int i = 0;
-
-       if (param->flag & WILC_CFG_PARAM_RETRY_SHORT) {
-               wid_list[i].id = WID_SHORT_RETRY_LIMIT;
-               wid_list[i].val = (s8 *)&param->short_retry_limit;
-               wid_list[i].type = WID_SHORT;
-               wid_list[i].size = sizeof(u16);
-               i++;
-       }
-       if (param->flag & WILC_CFG_PARAM_RETRY_LONG) {
-               wid_list[i].id = WID_LONG_RETRY_LIMIT;
-               wid_list[i].val = (s8 *)&param->long_retry_limit;
-               wid_list[i].type = WID_SHORT;
-               wid_list[i].size = sizeof(u16);
-               i++;
-       }
-       if (param->flag & WILC_CFG_PARAM_FRAG_THRESHOLD) {
-               wid_list[i].id = WID_FRAG_THRESHOLD;
-               wid_list[i].val = (s8 *)&param->frag_threshold;
-               wid_list[i].type = WID_SHORT;
-               wid_list[i].size = sizeof(u16);
-               i++;
-       }
-       if (param->flag & WILC_CFG_PARAM_RTS_THRESHOLD) {
-               wid_list[i].id = WID_RTS_THRESHOLD;
-               wid_list[i].val = (s8 *)&param->rts_threshold;
-               wid_list[i].type = WID_SHORT;
-               wid_list[i].size = sizeof(u16);
-               i++;
-       }
-
-       return wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
-                                   i, wilc_get_vif_idx(vif));
-}
-
-static void get_periodic_rssi(struct timer_list *t)
-{
-       struct wilc_vif *vif = from_timer(vif, t, periodic_rssi);
-
-       if (!vif->hif_drv) {
-               netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
-               return;
-       }
-
-       if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
-               wilc_get_stats_async(vif, &vif->periodic_stat);
-
-       mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
-}
-
-int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
-{
-       struct host_if_drv *hif_drv;
-       struct wilc_vif *vif = netdev_priv(dev);
-       struct wilc *wilc = vif->wilc;
-       int i;
-
-       hif_drv  = kzalloc(sizeof(*hif_drv), GFP_KERNEL);
-       if (!hif_drv)
-               return -ENOMEM;
-
-       *hif_drv_handler = hif_drv;
-       for (i = 0; i < wilc->vif_num; i++)
-               if (dev == wilc->vif[i]->ndev) {
-                       wilc->vif[i]->hif_drv = hif_drv;
-                       hif_drv->driver_handler_id = i + 1;
-                       break;
-               }
-
-       vif->obtaining_ip = false;
-
-       if (wilc->clients_count == 0)
-               mutex_init(&wilc->deinit_lock);
-
-       timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0);
-       mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
-
-       timer_setup(&hif_drv->scan_timer, timer_scan_cb, 0);
-       timer_setup(&hif_drv->connect_timer, timer_connect_cb, 0);
-       timer_setup(&hif_drv->remain_on_ch_timer, listen_timer_cb, 0);
-
-       hif_drv->hif_state = HOST_IF_IDLE;
-
-       hif_drv->p2p_timeout = 0;
-
-       wilc->clients_count++;
-
-       return 0;
-}
-
-int wilc_deinit(struct wilc_vif *vif)
-{
-       int result = 0;
-       struct host_if_drv *hif_drv = vif->hif_drv;
-
-       if (!hif_drv) {
-               netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
-               return -EFAULT;
-       }
-
-       mutex_lock(&vif->wilc->deinit_lock);
-
-       del_timer_sync(&hif_drv->scan_timer);
-       del_timer_sync(&hif_drv->connect_timer);
-       del_timer_sync(&vif->periodic_rssi);
-       del_timer_sync(&hif_drv->remain_on_ch_timer);
-
-       wilc_set_wfi_drv_handler(vif, 0, 0, 0);
-
-       if (hif_drv->usr_scan_req.scan_result) {
-               hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL,
-                                                 hif_drv->usr_scan_req.arg);
-               hif_drv->usr_scan_req.scan_result = NULL;
-       }
-
-       hif_drv->hif_state = HOST_IF_IDLE;
-
-       kfree(hif_drv);
-       vif->hif_drv = NULL;
-       vif->wilc->clients_count--;
-       mutex_unlock(&vif->wilc->deinit_lock);
-       return result;
-}
-
-void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
-{
-       int result;
-       struct host_if_msg *msg;
-       int id;
-       struct host_if_drv *hif_drv;
-       struct wilc_vif *vif;
-
-       id = get_unaligned_le32(&buffer[length - 4]);
-       vif = wilc_get_vif_from_idx(wilc, id);
-       if (!vif)
-               return;
-       hif_drv = vif->hif_drv;
-
-       if (!hif_drv) {
-               netdev_err(vif->ndev, "driver not init[%p]\n", hif_drv);
-               return;
-       }
-
-       msg = wilc_alloc_work(vif, handle_rcvd_ntwrk_info, false);
-       if (IS_ERR(msg))
-               return;
-
-       msg->body.net_info.frame_len = get_unaligned_le16(&buffer[6]) - 1;
-       msg->body.net_info.rssi = buffer[8];
-       msg->body.net_info.mgmt = kmemdup(&buffer[9],
-                                         msg->body.net_info.frame_len,
-                                         GFP_KERNEL);
-       if (!msg->body.net_info.mgmt) {
-               kfree(msg);
-               return;
-       }
-
-       result = wilc_enqueue_work(msg);
-       if (result) {
-               netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
-               kfree(msg->body.net_info.mgmt);
-               kfree(msg);
-       }
-}
-
-void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
-{
-       int result;
-       struct host_if_msg *msg;
-       int id;
-       struct host_if_drv *hif_drv;
-       struct wilc_vif *vif;
-
-       mutex_lock(&wilc->deinit_lock);
-
-       id = get_unaligned_le32(&buffer[length - 4]);
-       vif = wilc_get_vif_from_idx(wilc, id);
-       if (!vif) {
-               mutex_unlock(&wilc->deinit_lock);
-               return;
-       }
-
-       hif_drv = vif->hif_drv;
-
-       if (!hif_drv) {
-               mutex_unlock(&wilc->deinit_lock);
-               return;
-       }
-
-       if (!hif_drv->conn_info.conn_result) {
-               netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
-               mutex_unlock(&wilc->deinit_lock);
-               return;
-       }
-
-       msg = wilc_alloc_work(vif, handle_rcvd_gnrl_async_info, false);
-       if (IS_ERR(msg)) {
-               mutex_unlock(&wilc->deinit_lock);
-               return;
-       }
-
-       msg->body.mac_info.status = buffer[7];
-       result = wilc_enqueue_work(msg);
-       if (result) {
-               netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
-               kfree(msg);
-       }
-
-       mutex_unlock(&wilc->deinit_lock);
-}
-
-void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
-{
-       int result;
-       int id;
-       struct host_if_drv *hif_drv;
-       struct wilc_vif *vif;
-
-       id = get_unaligned_le32(&buffer[length - 4]);
-       vif = wilc_get_vif_from_idx(wilc, id);
-       if (!vif)
-               return;
-       hif_drv = vif->hif_drv;
-
-       if (!hif_drv)
-               return;
-
-       if (hif_drv->usr_scan_req.scan_result) {
-               struct host_if_msg *msg;
-
-               msg = wilc_alloc_work(vif, handle_scan_complete, false);
-               if (IS_ERR(msg))
-                       return;
-
-               result = wilc_enqueue_work(msg);
-               if (result) {
-                       netdev_err(vif->ndev, "%s: enqueue work failed\n",
-                                  __func__);
-                       kfree(msg);
-               }
-       }
-}
-
-int wilc_remain_on_channel(struct wilc_vif *vif, u64 cookie,
-                          u32 duration, u16 chan,
-                          void (*expired)(void *, u64),
-                          void *user_arg)
-{
-       struct wilc_remain_ch roc;
-       int result;
-
-       roc.ch = chan;
-       roc.expired = expired;
-       roc.arg = user_arg;
-       roc.duration = duration;
-       roc.cookie = cookie;
-       result = handle_remain_on_chan(vif, &roc);
-       if (result)
-               netdev_err(vif->ndev, "%s: failed to set remain on channel\n",
-                          __func__);
-
-       return result;
-}
-
-int wilc_listen_state_expired(struct wilc_vif *vif, u64 cookie)
-{
-       int result;
-       struct host_if_msg *msg;
-       struct host_if_drv *hif_drv = vif->hif_drv;
-
-       if (!hif_drv) {
-               netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
-               return -EFAULT;
-       }
-
-       del_timer(&hif_drv->remain_on_ch_timer);
-
-       msg = wilc_alloc_work(vif, handle_listen_state_expired, false);
-       if (IS_ERR(msg))
-               return PTR_ERR(msg);
-
-       msg->body.remain_on_ch.cookie = cookie;
-
-       result = wilc_enqueue_work(msg);
-       if (result) {
-               netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
-               kfree(msg);
-       }
-
-       return result;
-}
-
-void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
-{
-       struct wid wid;
-       int result;
-       struct wilc_reg_frame reg_frame;
-
-       wid.id = WID_REGISTER_FRAME;
-       wid.type = WID_STR;
-       wid.size = sizeof(reg_frame);
-       wid.val = (u8 *)&reg_frame;
-
-       memset(&reg_frame, 0x0, sizeof(reg_frame));
-       reg_frame.reg = reg;
-
-       switch (frame_type) {
-       case IEEE80211_STYPE_ACTION:
-               reg_frame.reg_id = WILC_FW_ACTION_FRM_IDX;
-               break;
-
-       case IEEE80211_STYPE_PROBE_REQ:
-               reg_frame.reg_id = WILC_FW_PROBE_REQ_IDX;
-               break;
-
-       default:
-               break;
-       }
-       reg_frame.frame_type = cpu_to_le16(frame_type);
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev, "Failed to frame register\n");
-}
-
-int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
-                   struct cfg80211_beacon_data *params)
-{
-       struct wid wid;
-       int result;
-       u8 *cur_byte;
-
-       wid.id = WID_ADD_BEACON;
-       wid.type = WID_BIN;
-       wid.size = params->head_len + params->tail_len + 16;
-       wid.val = kzalloc(wid.size, GFP_KERNEL);
-       if (!wid.val)
-               return -ENOMEM;
-
-       cur_byte = wid.val;
-       put_unaligned_le32(interval, cur_byte);
-       cur_byte += 4;
-       put_unaligned_le32(dtim_period, cur_byte);
-       cur_byte += 4;
-       put_unaligned_le32(params->head_len, cur_byte);
-       cur_byte += 4;
-
-       if (params->head_len > 0)
-               memcpy(cur_byte, params->head, params->head_len);
-       cur_byte += params->head_len;
-
-       put_unaligned_le32(params->tail_len, cur_byte);
-       cur_byte += 4;
-
-       if (params->tail_len > 0)
-               memcpy(cur_byte, params->tail, params->tail_len);
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev, "Failed to send add beacon\n");
-
-       kfree(wid.val);
-
-       return result;
-}
-
-int wilc_del_beacon(struct wilc_vif *vif)
-{
-       int result;
-       struct wid wid;
-       u8 del_beacon = 0;
-
-       wid.id = WID_DEL_BEACON;
-       wid.type = WID_CHAR;
-       wid.size = sizeof(char);
-       wid.val = &del_beacon;
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev, "Failed to send delete beacon\n");
-
-       return result;
-}
-
-int wilc_add_station(struct wilc_vif *vif, const u8 *mac,
-                    struct station_parameters *params)
-{
-       struct wid wid;
-       int result;
-       u8 *cur_byte;
-
-       wid.id = WID_ADD_STA;
-       wid.type = WID_BIN;
-       wid.size = WILC_ADD_STA_LENGTH + params->supported_rates_len;
-       wid.val = kmalloc(wid.size, GFP_KERNEL);
-       if (!wid.val)
-               return -ENOMEM;
-
-       cur_byte = wid.val;
-       wilc_hif_pack_sta_param(cur_byte, mac, params);
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result != 0)
-               netdev_err(vif->ndev, "Failed to send add station\n");
-
-       kfree(wid.val);
-
-       return result;
-}
-
-int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)
-{
-       struct wid wid;
-       int result;
-
-       wid.id = WID_REMOVE_STA;
-       wid.type = WID_BIN;
-       wid.size = ETH_ALEN;
-       wid.val = kzalloc(wid.size, GFP_KERNEL);
-       if (!wid.val)
-               return -ENOMEM;
-
-       if (!mac_addr)
-               eth_broadcast_addr(wid.val);
-       else
-               ether_addr_copy(wid.val, mac_addr);
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev, "Failed to del station\n");
-
-       kfree(wid.val);
-
-       return result;
-}
-
-int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
-{
-       struct wid wid;
-       int result;
-       int i;
-       u8 assoc_sta = 0;
-       struct wilc_del_all_sta del_sta;
-
-       memset(&del_sta, 0x0, sizeof(del_sta));
-       for (i = 0; i < WILC_MAX_NUM_STA; i++) {
-               if (!is_zero_ether_addr(mac_addr[i])) {
-                       assoc_sta++;
-                       ether_addr_copy(del_sta.mac[i], mac_addr[i]);
-               }
-       }
-
-       if (!assoc_sta)
-               return 0;
-
-       del_sta.assoc_sta = assoc_sta;
-
-       wid.id = WID_DEL_ALL_STA;
-       wid.type = WID_STR;
-       wid.size = (assoc_sta * ETH_ALEN) + 1;
-       wid.val = (u8 *)&del_sta;
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev, "Failed to send delete all station\n");
-
-       return result;
-}
-
-int wilc_edit_station(struct wilc_vif *vif, const u8 *mac,
-                     struct station_parameters *params)
-{
-       struct wid wid;
-       int result;
-       u8 *cur_byte;
-
-       wid.id = WID_EDIT_STA;
-       wid.type = WID_BIN;
-       wid.size = WILC_ADD_STA_LENGTH + params->supported_rates_len;
-       wid.val = kmalloc(wid.size, GFP_KERNEL);
-       if (!wid.val)
-               return -ENOMEM;
-
-       cur_byte = wid.val;
-       wilc_hif_pack_sta_param(cur_byte, mac, params);
-
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev, "Failed to send edit station\n");
-
-       kfree(wid.val);
-       return result;
-}
-
-int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
-{
-       struct wid wid;
-       int result;
-       s8 power_mode;
-
-       if (wilc_wlan_get_num_conn_ifcs(vif->wilc) == 2 && enabled)
-               return 0;
-
-       if (enabled)
-               power_mode = WILC_FW_MIN_FAST_PS;
-       else
-               power_mode = WILC_FW_NO_POWERSAVE;
-
-       wid.id = WID_POWER_MANAGEMENT;
-       wid.val = &power_mode;
-       wid.size = sizeof(char);
-       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                     wilc_get_vif_idx(vif));
-       if (result)
-               netdev_err(vif->ndev, "Failed to send power management\n");
-
-       return result;
-}
-
-int wilc_setup_multicast_filter(struct wilc_vif *vif, u32 enabled, u32 count,
-                               u8 *mc_list)
-{
-       int result;
-       struct host_if_msg *msg;
-
-       msg = wilc_alloc_work(vif, handle_set_mcast_filter, false);
-       if (IS_ERR(msg))
-               return PTR_ERR(msg);
-
-       msg->body.mc_info.enabled = enabled;
-       msg->body.mc_info.cnt = count;
-       msg->body.mc_info.mc_list = mc_list;
-
-       result = wilc_enqueue_work(msg);
-       if (result) {
-               netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
-               kfree(msg);
-       }
-       return result;
-}
-
-int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
-{
-       struct wid wid;
-
-       wid.id = WID_TX_POWER;
-       wid.type = WID_CHAR;
-       wid.val = &tx_power;
-       wid.size = sizeof(char);
-
-       return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
-                                  wilc_get_vif_idx(vif));
-}
-
-int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)
-{
-       struct wid wid;
-
-       wid.id = WID_TX_POWER;
-       wid.type = WID_CHAR;
-       wid.val = tx_power;
-       wid.size = sizeof(char);
-
-       return wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1,
-                                   wilc_get_vif_idx(vif));
-}
diff --git a/drivers/staging/wilc1000/host_interface.h b/drivers/staging/wilc1000/host_interface.h
deleted file mode 100644 (file)
index a907c6d..0000000
+++ /dev/null
@@ -1,237 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries
- * All rights reserved.
- */
-
-#ifndef HOST_INT_H
-#define HOST_INT_H
-#include <linux/ieee80211.h>
-#include "wilc_wlan_if.h"
-
-enum {
-       WILC_IDLE_MODE = 0x0,
-       WILC_AP_MODE = 0x1,
-       WILC_STATION_MODE = 0x2,
-       WILC_GO_MODE = 0x3,
-       WILC_CLIENT_MODE = 0x4
-};
-
-#define WILC_MAX_NUM_STA                       9
-#define WILC_MAX_NUM_SCANNED_CH                        14
-#define WILC_MAX_NUM_PROBED_SSID               10
-
-#define WILC_TX_MIC_KEY_LEN                    8
-#define WILC_RX_MIC_KEY_LEN                    8
-
-#define WILC_MAX_NUM_PMKIDS                    16
-#define WILC_ADD_STA_LENGTH                    40
-#define WILC_NUM_CONCURRENT_IFC                        2
-
-enum {
-       WILC_SET_CFG = 0,
-       WILC_GET_CFG
-};
-
-#define WILC_MAX_ASSOC_RESP_FRAME_SIZE   256
-
-struct assoc_resp {
-       __le16 capab_info;
-       __le16 status_code;
-       __le16 aid;
-} __packed;
-
-struct rf_info {
-       u8 link_speed;
-       s8 rssi;
-       u32 tx_cnt;
-       u32 rx_cnt;
-       u32 tx_fail_cnt;
-};
-
-enum host_if_state {
-       HOST_IF_IDLE                    = 0,
-       HOST_IF_SCANNING                = 1,
-       HOST_IF_CONNECTING              = 2,
-       HOST_IF_WAITING_CONN_RESP       = 3,
-       HOST_IF_CONNECTED               = 4,
-       HOST_IF_P2P_LISTEN              = 5,
-       HOST_IF_FORCE_32BIT             = 0xFFFFFFFF
-};
-
-struct wilc_pmkid {
-       u8 bssid[ETH_ALEN];
-       u8 pmkid[WLAN_PMKID_LEN];
-} __packed;
-
-struct wilc_pmkid_attr {
-       u8 numpmkid;
-       struct wilc_pmkid pmkidlist[WILC_MAX_NUM_PMKIDS];
-} __packed;
-
-struct cfg_param_attr {
-       u32 flag;
-       u16 short_retry_limit;
-       u16 long_retry_limit;
-       u16 frag_threshold;
-       u16 rts_threshold;
-};
-
-enum cfg_param {
-       WILC_CFG_PARAM_RETRY_SHORT = BIT(0),
-       WILC_CFG_PARAM_RETRY_LONG = BIT(1),
-       WILC_CFG_PARAM_FRAG_THRESHOLD = BIT(2),
-       WILC_CFG_PARAM_RTS_THRESHOLD = BIT(3)
-};
-
-enum scan_event {
-       SCAN_EVENT_NETWORK_FOUND        = 0,
-       SCAN_EVENT_DONE                 = 1,
-       SCAN_EVENT_ABORTED              = 2,
-       SCAN_EVENT_FORCE_32BIT          = 0xFFFFFFFF
-};
-
-enum conn_event {
-       CONN_DISCONN_EVENT_CONN_RESP            = 0,
-       CONN_DISCONN_EVENT_DISCONN_NOTIF        = 1,
-       CONN_DISCONN_EVENT_FORCE_32BIT          = 0xFFFFFFFF
-};
-
-enum {
-       WILC_HIF_SDIO = 0,
-       WILC_HIF_SPI = BIT(0)
-};
-
-enum {
-       WILC_MAC_STATUS_INIT = -1,
-       WILC_MAC_STATUS_DISCONNECTED = 0,
-       WILC_MAC_STATUS_CONNECTED = 1
-};
-
-struct wilc_rcvd_net_info {
-       s8 rssi;
-       u8 ch;
-       u16 frame_len;
-       struct ieee80211_mgmt *mgmt;
-};
-
-
-struct wilc_user_scan_req {
-       void (*scan_result)(enum scan_event evt,
-                           struct wilc_rcvd_net_info *info, void *priv);
-       void *arg;
-       u32 ch_cnt;
-};
-
-struct wilc_conn_info {
-       u8 bssid[ETH_ALEN];
-       u8 security;
-       enum authtype auth_type;
-       u8 ch;
-       u8 *req_ies;
-       size_t req_ies_len;
-       u8 *resp_ies;
-       u16 resp_ies_len;
-       u16 status;
-       void (*conn_result)(enum conn_event evt, u8 status, void *priv_data);
-       void *arg;
-       void *param;
-};
-
-struct wilc_remain_ch {
-       u16 ch;
-       u32 duration;
-       void (*expired)(void *priv, u64 cookie);
-       void *arg;
-       u32 cookie;
-};
-
-struct wilc;
-struct host_if_drv {
-       struct wilc_user_scan_req usr_scan_req;
-       struct wilc_conn_info conn_info;
-       struct wilc_remain_ch remain_on_ch;
-       u64 p2p_timeout;
-
-       enum host_if_state hif_state;
-
-       u8 assoc_bssid[ETH_ALEN];
-
-       struct timer_list scan_timer;
-       struct wilc_vif *scan_timer_vif;
-
-       struct timer_list connect_timer;
-       struct wilc_vif *connect_timer_vif;
-
-       struct timer_list remain_on_ch_timer;
-       struct wilc_vif *remain_on_ch_timer_vif;
-
-       bool ifc_up;
-       int driver_handler_id;
-       u8 assoc_resp[WILC_MAX_ASSOC_RESP_FRAME_SIZE];
-};
-
-struct wilc_vif;
-int wilc_remove_wep_key(struct wilc_vif *vif, u8 index);
-int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index);
-int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
-                            u8 index);
-int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
-                           u8 index, u8 mode, enum authtype auth_type);
-int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
-                const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic,
-                u8 mode, u8 cipher_mode, u8 index);
-s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac,
-                          u32 *out_val);
-int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
-                   u8 index, u32 key_rsc_len, const u8 *key_rsc,
-                   const u8 *rx_mic, const u8 *tx_mic, u8 mode,
-                   u8 cipher_mode);
-int wilc_set_pmkid_info(struct wilc_vif *vif, struct wilc_pmkid_attr *pmkid);
-int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr);
-int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ies,
-                     size_t ies_len);
-int wilc_disconnect(struct wilc_vif *vif);
-int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel);
-int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level);
-int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
-             u8 *ch_freq_list, u8 ch_list_len,
-             void (*scan_result_fn)(enum scan_event,
-                                    struct wilc_rcvd_net_info *, void *),
-             void *user_arg, struct cfg80211_scan_request *request);
-int wilc_hif_set_cfg(struct wilc_vif *vif,
-                    struct cfg_param_attr *cfg_param);
-int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler);
-int wilc_deinit(struct wilc_vif *vif);
-int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
-                   struct cfg80211_beacon_data *params);
-int wilc_del_beacon(struct wilc_vif *vif);
-int wilc_add_station(struct wilc_vif *vif, const u8 *mac,
-                    struct station_parameters *params);
-int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN]);
-int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr);
-int wilc_edit_station(struct wilc_vif *vif, const u8 *mac,
-                     struct station_parameters *params);
-int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout);
-int wilc_setup_multicast_filter(struct wilc_vif *vif, u32 enabled, u32 count,
-                               u8 *mc_list);
-int wilc_remain_on_channel(struct wilc_vif *vif, u64 cookie,
-                          u32 duration, u16 chan,
-                          void (*expired)(void *, u64),
-                          void *user_arg);
-int wilc_listen_state_expired(struct wilc_vif *vif, u64 cookie);
-void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg);
-int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
-                            u8 ifc_id);
-int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode);
-int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats);
-void wilc_resolve_disconnect_aberration(struct wilc_vif *vif);
-int wilc_get_vif_idx(struct wilc_vif *vif);
-int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power);
-int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power);
-void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length);
-void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length);
-void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length);
-void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
-                               struct cfg80211_crypto_settings *crypto);
-#endif
diff --git a/drivers/staging/wilc1000/wilc_hif.c b/drivers/staging/wilc1000/wilc_hif.c
new file mode 100644 (file)
index 0000000..9345cab
--- /dev/null
@@ -0,0 +1,2089 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
+ * All rights reserved.
+ */
+
+#include "wilc_wfi_netdevice.h"
+
+#define WILC_HIF_SCAN_TIMEOUT_MS                5000
+#define WILC_HIF_CONNECT_TIMEOUT_MS             9500
+
+#define WILC_FALSE_FRMWR_CHANNEL               100
+#define WILC_MAX_RATES_SUPPORTED               12
+
+struct wilc_rcvd_mac_info {
+       u8 status;
+};
+
+struct wilc_set_multicast {
+       u32 enabled;
+       u32 cnt;
+       u8 *mc_list;
+};
+
+struct wilc_del_all_sta {
+       u8 assoc_sta;
+       u8 mac[WILC_MAX_NUM_STA][ETH_ALEN];
+};
+
+struct wilc_op_mode {
+       __le32 mode;
+};
+
+struct wilc_reg_frame {
+       bool reg;
+       u8 reg_id;
+       __le16 frame_type;
+} __packed;
+
+struct wilc_drv_handler {
+       __le32 handler;
+       u8 mode;
+} __packed;
+
+struct wilc_wep_key {
+       u8 index;
+       u8 key_len;
+       u8 key[0];
+} __packed;
+
+struct wilc_sta_wpa_ptk {
+       u8 mac_addr[ETH_ALEN];
+       u8 key_len;
+       u8 key[0];
+} __packed;
+
+struct wilc_ap_wpa_ptk {
+       u8 mac_addr[ETH_ALEN];
+       u8 index;
+       u8 key_len;
+       u8 key[0];
+} __packed;
+
+struct wilc_gtk_key {
+       u8 mac_addr[ETH_ALEN];
+       u8 rsc[8];
+       u8 index;
+       u8 key_len;
+       u8 key[0];
+} __packed;
+
+union wilc_message_body {
+       struct wilc_rcvd_net_info net_info;
+       struct wilc_rcvd_mac_info mac_info;
+       struct wilc_set_multicast mc_info;
+       struct wilc_remain_ch remain_on_ch;
+       char *data;
+};
+
+struct host_if_msg {
+       union wilc_message_body body;
+       struct wilc_vif *vif;
+       struct work_struct work;
+       void (*fn)(struct work_struct *ws);
+       struct completion work_comp;
+       bool is_sync;
+};
+
+struct wilc_noa_opp_enable {
+       u8 ct_window;
+       u8 cnt;
+       __le32 duration;
+       __le32 interval;
+       __le32 start_time;
+} __packed;
+
+struct wilc_noa_opp_disable {
+       u8 cnt;
+       __le32 duration;
+       __le32 interval;
+       __le32 start_time;
+} __packed;
+
+struct wilc_join_bss_param {
+       char ssid[IEEE80211_MAX_SSID_LEN];
+       u8 ssid_terminator;
+       u8 bss_type;
+       u8 ch;
+       __le16 cap_info;
+       u8 sa[ETH_ALEN];
+       u8 bssid[ETH_ALEN];
+       __le16 beacon_period;
+       u8 dtim_period;
+       u8 supp_rates[WILC_MAX_RATES_SUPPORTED + 1];
+       u8 wmm_cap;
+       u8 uapsd_cap;
+       u8 ht_capable;
+       u8 rsn_found;
+       u8 rsn_grp_policy;
+       u8 mode_802_11i;
+       u8 p_suites[3];
+       u8 akm_suites[3];
+       u8 rsn_cap[2];
+       u8 noa_enabled;
+       __le32 tsf_lo;
+       u8 idx;
+       u8 opp_enabled;
+       union {
+               struct wilc_noa_opp_disable opp_dis;
+               struct wilc_noa_opp_enable opp_en;
+       };
+} __packed;
+
+/* 'msg' should be free by the caller for syc */
+static struct host_if_msg*
+wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *),
+               bool is_sync)
+{
+       struct host_if_msg *msg;
+
+       if (!work_fun)
+               return ERR_PTR(-EINVAL);
+
+       msg = kzalloc(sizeof(*msg), GFP_ATOMIC);
+       if (!msg)
+               return ERR_PTR(-ENOMEM);
+       msg->fn = work_fun;
+       msg->vif = vif;
+       msg->is_sync = is_sync;
+       if (is_sync)
+               init_completion(&msg->work_comp);
+
+       return msg;
+}
+
+static int wilc_enqueue_work(struct host_if_msg *msg)
+{
+       INIT_WORK(&msg->work, msg->fn);
+
+       if (!msg->vif || !msg->vif->wilc || !msg->vif->wilc->hif_workqueue)
+               return -EINVAL;
+
+       if (!queue_work(msg->vif->wilc->hif_workqueue, &msg->work))
+               return -EINVAL;
+
+       return 0;
+}
+
+/* The idx starts from 0 to (NUM_CONCURRENT_IFC - 1), but 0 index used as
+ * special purpose in wilc device, so we add 1 to the index to starts from 1.
+ * As a result, the returned index will be 1 to NUM_CONCURRENT_IFC.
+ */
+int wilc_get_vif_idx(struct wilc_vif *vif)
+{
+       return vif->idx + 1;
+}
+
+/* We need to minus 1 from idx which is from wilc device to get real index
+ * of wilc->vif[], because we add 1 when pass to wilc device in the function
+ * wilc_get_vif_idx.
+ * As a result, the index should be between 0 and (NUM_CONCURRENT_IFC - 1).
+ */
+static struct wilc_vif *wilc_get_vif_from_idx(struct wilc *wilc, int idx)
+{
+       int index = idx - 1;
+
+       if (index < 0 || index >= WILC_NUM_CONCURRENT_IFC)
+               return NULL;
+
+       return wilc->vif[index];
+}
+
+static int handle_scan_done(struct wilc_vif *vif, enum scan_event evt)
+{
+       int result = 0;
+       u8 abort_running_scan;
+       struct wid wid;
+       struct host_if_drv *hif_drv = vif->hif_drv;
+       struct wilc_user_scan_req *scan_req;
+
+       if (evt == SCAN_EVENT_ABORTED) {
+               abort_running_scan = 1;
+               wid.id = WID_ABORT_RUNNING_SCAN;
+               wid.type = WID_CHAR;
+               wid.val = (s8 *)&abort_running_scan;
+               wid.size = sizeof(char);
+
+               result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+               if (result) {
+                       netdev_err(vif->ndev, "Failed to set abort running\n");
+                       result = -EFAULT;
+               }
+       }
+
+       if (!hif_drv) {
+               netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
+               return result;
+       }
+
+       scan_req = &hif_drv->usr_scan_req;
+       if (scan_req->scan_result) {
+               scan_req->scan_result(evt, NULL, scan_req->arg);
+               scan_req->scan_result = NULL;
+       }
+
+       return result;
+}
+
+int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
+             u8 *ch_freq_list, u8 ch_list_len,
+             void (*scan_result_fn)(enum scan_event,
+                                    struct wilc_rcvd_net_info *, void *),
+             void *user_arg, struct cfg80211_scan_request *request)
+{
+       int result = 0;
+       struct wid wid_list[5];
+       u32 index = 0;
+       u32 i, scan_timeout;
+       u8 *buffer;
+       u8 valuesize = 0;
+       u8 *search_ssid_vals = NULL;
+       struct host_if_drv *hif_drv = vif->hif_drv;
+
+       if (hif_drv->hif_state >= HOST_IF_SCANNING &&
+           hif_drv->hif_state < HOST_IF_CONNECTED) {
+               netdev_err(vif->ndev, "Already scan\n");
+               result = -EBUSY;
+               goto error;
+       }
+
+       if (vif->obtaining_ip || vif->connecting) {
+               netdev_err(vif->ndev, "Don't do obss scan\n");
+               result = -EBUSY;
+               goto error;
+       }
+
+       hif_drv->usr_scan_req.ch_cnt = 0;
+
+       if (request->n_ssids) {
+               for (i = 0; i < request->n_ssids; i++)
+                       valuesize += ((request->ssids[i].ssid_len) + 1);
+               search_ssid_vals = kmalloc(valuesize + 1, GFP_KERNEL);
+               if (search_ssid_vals) {
+                       wid_list[index].id = WID_SSID_PROBE_REQ;
+                       wid_list[index].type = WID_STR;
+                       wid_list[index].val = search_ssid_vals;
+                       buffer = wid_list[index].val;
+
+                       *buffer++ = request->n_ssids;
+
+                       for (i = 0; i < request->n_ssids; i++) {
+                               *buffer++ = request->ssids[i].ssid_len;
+                               memcpy(buffer, request->ssids[i].ssid,
+                                      request->ssids[i].ssid_len);
+                               buffer += request->ssids[i].ssid_len;
+                       }
+                       wid_list[index].size = (s32)(valuesize + 1);
+                       index++;
+               }
+       }
+
+       wid_list[index].id = WID_INFO_ELEMENT_PROBE;
+       wid_list[index].type = WID_BIN_DATA;
+       wid_list[index].val = (s8 *)request->ie;
+       wid_list[index].size = request->ie_len;
+       index++;
+
+       wid_list[index].id = WID_SCAN_TYPE;
+       wid_list[index].type = WID_CHAR;
+       wid_list[index].size = sizeof(char);
+       wid_list[index].val = (s8 *)&scan_type;
+       index++;
+
+       if (scan_type == WILC_FW_PASSIVE_SCAN && request->duration) {
+               wid_list[index].id = WID_PASSIVE_SCAN_TIME;
+               wid_list[index].type = WID_SHORT;
+               wid_list[index].size = sizeof(u16);
+               wid_list[index].val = (s8 *)&request->duration;
+               index++;
+
+               scan_timeout = (request->duration * ch_list_len) + 500;
+       } else {
+               scan_timeout = WILC_HIF_SCAN_TIMEOUT_MS;
+       }
+
+       wid_list[index].id = WID_SCAN_CHANNEL_LIST;
+       wid_list[index].type = WID_BIN_DATA;
+
+       if (ch_freq_list && ch_list_len > 0) {
+               for (i = 0; i < ch_list_len; i++) {
+                       if (ch_freq_list[i] > 0)
+                               ch_freq_list[i] -= 1;
+               }
+       }
+
+       wid_list[index].val = ch_freq_list;
+       wid_list[index].size = ch_list_len;
+       index++;
+
+       wid_list[index].id = WID_START_SCAN_REQ;
+       wid_list[index].type = WID_CHAR;
+       wid_list[index].size = sizeof(char);
+       wid_list[index].val = (s8 *)&scan_source;
+       index++;
+
+       hif_drv->usr_scan_req.scan_result = scan_result_fn;
+       hif_drv->usr_scan_req.arg = user_arg;
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, index);
+       if (result) {
+               netdev_err(vif->ndev, "Failed to send scan parameters\n");
+               goto error;
+       }
+
+       hif_drv->scan_timer_vif = vif;
+       mod_timer(&hif_drv->scan_timer,
+                 jiffies + msecs_to_jiffies(scan_timeout));
+
+error:
+
+       kfree(search_ssid_vals);
+
+       return result;
+}
+
+static int wilc_send_connect_wid(struct wilc_vif *vif)
+{
+       int result = 0;
+       struct wid wid_list[4];
+       u32 wid_cnt = 0;
+       struct host_if_drv *hif_drv = vif->hif_drv;
+       struct wilc_conn_info *conn_attr = &hif_drv->conn_info;
+       struct wilc_join_bss_param *bss_param = conn_attr->param;
+
+       wid_list[wid_cnt].id = WID_INFO_ELEMENT_ASSOCIATE;
+       wid_list[wid_cnt].type = WID_BIN_DATA;
+       wid_list[wid_cnt].val = conn_attr->req_ies;
+       wid_list[wid_cnt].size = conn_attr->req_ies_len;
+       wid_cnt++;
+
+       wid_list[wid_cnt].id = WID_11I_MODE;
+       wid_list[wid_cnt].type = WID_CHAR;
+       wid_list[wid_cnt].size = sizeof(char);
+       wid_list[wid_cnt].val = (s8 *)&conn_attr->security;
+       wid_cnt++;
+
+       wid_list[wid_cnt].id = WID_AUTH_TYPE;
+       wid_list[wid_cnt].type = WID_CHAR;
+       wid_list[wid_cnt].size = sizeof(char);
+       wid_list[wid_cnt].val = (s8 *)&conn_attr->auth_type;
+       wid_cnt++;
+
+       wid_list[wid_cnt].id = WID_JOIN_REQ_EXTENDED;
+       wid_list[wid_cnt].type = WID_STR;
+       wid_list[wid_cnt].size = sizeof(*bss_param);
+       wid_list[wid_cnt].val = (u8 *)bss_param;
+       wid_cnt++;
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, wid_cnt);
+       if (result) {
+               netdev_err(vif->ndev, "failed to send config packet\n");
+               goto error;
+       } else {
+               hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
+       }
+
+       return 0;
+
+error:
+
+       kfree(conn_attr->req_ies);
+       conn_attr->req_ies = NULL;
+
+       return result;
+}
+
+static void handle_connect_timeout(struct work_struct *work)
+{
+       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+       struct wilc_vif *vif = msg->vif;
+       int result;
+       struct wid wid;
+       u16 dummy_reason_code = 0;
+       struct host_if_drv *hif_drv = vif->hif_drv;
+
+       if (!hif_drv) {
+               netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
+               goto out;
+       }
+
+       hif_drv->hif_state = HOST_IF_IDLE;
+
+       if (hif_drv->conn_info.conn_result) {
+               hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
+                                              WILC_MAC_STATUS_DISCONNECTED,
+                                              hif_drv->conn_info.arg);
+
+       } else {
+               netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
+       }
+
+       wid.id = WID_DISCONNECT;
+       wid.type = WID_CHAR;
+       wid.val = (s8 *)&dummy_reason_code;
+       wid.size = sizeof(char);
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev, "Failed to send disconnect\n");
+
+       hif_drv->conn_info.req_ies_len = 0;
+       kfree(hif_drv->conn_info.req_ies);
+       hif_drv->conn_info.req_ies = NULL;
+
+out:
+       kfree(msg);
+}
+
+void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
+                               struct cfg80211_crypto_settings *crypto)
+{
+       struct wilc_join_bss_param *param;
+       struct ieee80211_p2p_noa_attr noa_attr;
+       u8 rates_len = 0;
+       const u8 *tim_elm, *ssid_elm, *rates_ie, *supp_rates_ie;
+       const u8 *ht_ie, *wpa_ie, *wmm_ie, *rsn_ie;
+       int ret;
+       const struct cfg80211_bss_ies *ies = rcu_dereference(bss->ies);
+
+       param = kzalloc(sizeof(*param), GFP_KERNEL);
+       if (!param)
+               return NULL;
+
+       param->beacon_period = cpu_to_le16(bss->beacon_interval);
+       param->cap_info = cpu_to_le16(bss->capability);
+       param->bss_type = WILC_FW_BSS_TYPE_INFRA;
+       param->ch = ieee80211_frequency_to_channel(bss->channel->center_freq);
+       ether_addr_copy(param->bssid, bss->bssid);
+
+       ssid_elm = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
+       if (ssid_elm) {
+               if (ssid_elm[1] <= IEEE80211_MAX_SSID_LEN)
+                       memcpy(param->ssid, ssid_elm + 2, ssid_elm[1]);
+       }
+
+       tim_elm = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
+       if (tim_elm && tim_elm[1] >= 2)
+               param->dtim_period = tim_elm[3];
+
+       memset(param->p_suites, 0xFF, 3);
+       memset(param->akm_suites, 0xFF, 3);
+
+       rates_ie = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies->data, ies->len);
+       if (rates_ie) {
+               rates_len = rates_ie[1];
+               param->supp_rates[0] = rates_len;
+               memcpy(&param->supp_rates[1], rates_ie + 2, rates_len);
+       }
+
+       supp_rates_ie = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies->data,
+                                        ies->len);
+       if (supp_rates_ie) {
+               if (supp_rates_ie[1] > (WILC_MAX_RATES_SUPPORTED - rates_len))
+                       param->supp_rates[0] = WILC_MAX_RATES_SUPPORTED;
+               else
+                       param->supp_rates[0] += supp_rates_ie[1];
+
+               memcpy(&param->supp_rates[rates_len + 1], supp_rates_ie + 2,
+                      (param->supp_rates[0] - rates_len));
+       }
+
+       ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies->data, ies->len);
+       if (ht_ie)
+               param->ht_capable = true;
+
+       ret = cfg80211_get_p2p_attr(ies->data, ies->len,
+                                   IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
+                                   (u8 *)&noa_attr, sizeof(noa_attr));
+       if (ret > 0) {
+               param->tsf_lo = cpu_to_le32(ies->tsf);
+               param->noa_enabled = 1;
+               param->idx = noa_attr.index;
+               if (noa_attr.oppps_ctwindow & IEEE80211_P2P_OPPPS_ENABLE_BIT) {
+                       param->opp_enabled = 1;
+                       param->opp_en.ct_window = noa_attr.oppps_ctwindow;
+                       param->opp_en.cnt = noa_attr.desc[0].count;
+                       param->opp_en.duration = noa_attr.desc[0].duration;
+                       param->opp_en.interval = noa_attr.desc[0].interval;
+                       param->opp_en.start_time = noa_attr.desc[0].start_time;
+               } else {
+                       param->opp_enabled = 0;
+                       param->opp_dis.cnt = noa_attr.desc[0].count;
+                       param->opp_dis.duration = noa_attr.desc[0].duration;
+                       param->opp_dis.interval = noa_attr.desc[0].interval;
+                       param->opp_dis.start_time = noa_attr.desc[0].start_time;
+               }
+       }
+       wmm_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
+                                        WLAN_OUI_TYPE_MICROSOFT_WMM,
+                                        ies->data, ies->len);
+       if (wmm_ie) {
+               struct ieee80211_wmm_param_ie *ie;
+
+               ie = (struct ieee80211_wmm_param_ie *)wmm_ie;
+               if ((ie->oui_subtype == 0 || ie->oui_subtype == 1) &&
+                   ie->version == 1) {
+                       param->wmm_cap = true;
+                       if (ie->qos_info & BIT(7))
+                               param->uapsd_cap = true;
+               }
+       }
+
+       wpa_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
+                                        WLAN_OUI_TYPE_MICROSOFT_WPA,
+                                        ies->data, ies->len);
+       if (wpa_ie) {
+               param->mode_802_11i = 1;
+               param->rsn_found = true;
+       }
+
+       rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, ies->data, ies->len);
+       if (rsn_ie) {
+               int offset = 8;
+
+               param->mode_802_11i = 2;
+               param->rsn_found = true;
+               //extract RSN capabilities
+               offset += (rsn_ie[offset] * 4) + 2;
+               offset += (rsn_ie[offset] * 4) + 2;
+               memcpy(param->rsn_cap, &rsn_ie[offset], 2);
+       }
+
+       if (param->rsn_found) {
+               int i;
+
+               param->rsn_grp_policy = crypto->cipher_group & 0xFF;
+               for (i = 0; i < crypto->n_ciphers_pairwise && i < 3; i++)
+                       param->p_suites[i] = crypto->ciphers_pairwise[i] & 0xFF;
+
+               for (i = 0; i < crypto->n_akm_suites && i < 3; i++)
+                       param->akm_suites[i] = crypto->akm_suites[i] & 0xFF;
+       }
+
+       return (void *)param;
+}
+
+static void handle_rcvd_ntwrk_info(struct work_struct *work)
+{
+       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+       struct wilc_rcvd_net_info *rcvd_info = &msg->body.net_info;
+       struct wilc_user_scan_req *scan_req = &msg->vif->hif_drv->usr_scan_req;
+       const u8 *ch_elm;
+       u8 *ies;
+       int ies_len;
+       size_t offset;
+
+       if (ieee80211_is_probe_resp(rcvd_info->mgmt->frame_control))
+               offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
+       else if (ieee80211_is_beacon(rcvd_info->mgmt->frame_control))
+               offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
+       else
+               goto done;
+
+       ies = rcvd_info->mgmt->u.beacon.variable;
+       ies_len = rcvd_info->frame_len - offset;
+       if (ies_len <= 0)
+               goto done;
+
+       ch_elm = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ies, ies_len);
+       if (ch_elm && ch_elm[1] > 0)
+               rcvd_info->ch = ch_elm[2];
+
+       if (scan_req->scan_result)
+               scan_req->scan_result(SCAN_EVENT_NETWORK_FOUND, rcvd_info,
+                                     scan_req->arg);
+
+done:
+       kfree(rcvd_info->mgmt);
+       kfree(msg);
+}
+
+static void host_int_get_assoc_res_info(struct wilc_vif *vif,
+                                       u8 *assoc_resp_info,
+                                       u32 max_assoc_resp_info_len,
+                                       u32 *rcvd_assoc_resp_info_len)
+{
+       int result;
+       struct wid wid;
+
+       wid.id = WID_ASSOC_RES_INFO;
+       wid.type = WID_STR;
+       wid.val = assoc_resp_info;
+       wid.size = max_assoc_resp_info_len;
+
+       result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
+       if (result) {
+               *rcvd_assoc_resp_info_len = 0;
+               netdev_err(vif->ndev, "Failed to send association response\n");
+               return;
+       }
+
+       *rcvd_assoc_resp_info_len = wid.size;
+}
+
+static s32 wilc_parse_assoc_resp_info(u8 *buffer, u32 buffer_len,
+                                     struct wilc_conn_info *ret_conn_info)
+{
+       u8 *ies;
+       u16 ies_len;
+       struct assoc_resp *res = (struct assoc_resp *)buffer;
+
+       ret_conn_info->status = le16_to_cpu(res->status_code);
+       if (ret_conn_info->status == WLAN_STATUS_SUCCESS) {
+               ies = &buffer[sizeof(*res)];
+               ies_len = buffer_len - sizeof(*res);
+
+               ret_conn_info->resp_ies = kmemdup(ies, ies_len, GFP_KERNEL);
+               if (!ret_conn_info->resp_ies)
+                       return -ENOMEM;
+
+               ret_conn_info->resp_ies_len = ies_len;
+       }
+
+       return 0;
+}
+
+static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
+                                                 u8 mac_status)
+{
+       struct host_if_drv *hif_drv = vif->hif_drv;
+       struct wilc_conn_info *conn_info = &hif_drv->conn_info;
+
+       if (mac_status == WILC_MAC_STATUS_CONNECTED) {
+               u32 assoc_resp_info_len;
+
+               memset(hif_drv->assoc_resp, 0, WILC_MAX_ASSOC_RESP_FRAME_SIZE);
+
+               host_int_get_assoc_res_info(vif, hif_drv->assoc_resp,
+                                           WILC_MAX_ASSOC_RESP_FRAME_SIZE,
+                                           &assoc_resp_info_len);
+
+               if (assoc_resp_info_len != 0) {
+                       s32 err = 0;
+
+                       err = wilc_parse_assoc_resp_info(hif_drv->assoc_resp,
+                                                        assoc_resp_info_len,
+                                                        conn_info);
+                       if (err)
+                               netdev_err(vif->ndev,
+                                          "wilc_parse_assoc_resp_info() returned error %d\n",
+                                          err);
+               }
+       }
+
+       del_timer(&hif_drv->connect_timer);
+       conn_info->conn_result(CONN_DISCONN_EVENT_CONN_RESP, mac_status,
+                              hif_drv->conn_info.arg);
+
+       if (mac_status == WILC_MAC_STATUS_CONNECTED &&
+           conn_info->status == WLAN_STATUS_SUCCESS) {
+               ether_addr_copy(hif_drv->assoc_bssid, conn_info->bssid);
+               wilc_set_power_mgmt(vif, 0, 0);
+
+               hif_drv->hif_state = HOST_IF_CONNECTED;
+
+               vif->obtaining_ip = true;
+               mod_timer(&vif->during_ip_timer,
+                         jiffies + msecs_to_jiffies(10000));
+       } else {
+               hif_drv->hif_state = HOST_IF_IDLE;
+       }
+
+       kfree(conn_info->resp_ies);
+       conn_info->resp_ies = NULL;
+       conn_info->resp_ies_len = 0;
+
+       kfree(conn_info->req_ies);
+       conn_info->req_ies = NULL;
+       conn_info->req_ies_len = 0;
+}
+
+static inline void host_int_handle_disconnect(struct wilc_vif *vif)
+{
+       struct host_if_drv *hif_drv = vif->hif_drv;
+
+       if (hif_drv->usr_scan_req.scan_result) {
+               del_timer(&hif_drv->scan_timer);
+               handle_scan_done(vif, SCAN_EVENT_ABORTED);
+       }
+
+       if (hif_drv->conn_info.conn_result) {
+               vif->obtaining_ip = false;
+               wilc_set_power_mgmt(vif, 0, 0);
+
+               hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
+                                              0, hif_drv->conn_info.arg);
+       } else {
+               netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
+       }
+
+       eth_zero_addr(hif_drv->assoc_bssid);
+
+       hif_drv->conn_info.req_ies_len = 0;
+       kfree(hif_drv->conn_info.req_ies);
+       hif_drv->conn_info.req_ies = NULL;
+       hif_drv->hif_state = HOST_IF_IDLE;
+}
+
+static void handle_rcvd_gnrl_async_info(struct work_struct *work)
+{
+       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+       struct wilc_vif *vif = msg->vif;
+       struct wilc_rcvd_mac_info *mac_info = &msg->body.mac_info;
+       struct host_if_drv *hif_drv = vif->hif_drv;
+
+       if (!hif_drv) {
+               netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
+               goto free_msg;
+       }
+
+       if (!hif_drv->conn_info.conn_result) {
+               netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
+               goto free_msg;
+       }
+
+       if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
+               host_int_parse_assoc_resp_info(vif, mac_info->status);
+       } else if (mac_info->status == WILC_MAC_STATUS_DISCONNECTED) {
+               if (hif_drv->hif_state == HOST_IF_CONNECTED) {
+                       host_int_handle_disconnect(vif);
+               } else if (hif_drv->usr_scan_req.scan_result) {
+                       del_timer(&hif_drv->scan_timer);
+                       handle_scan_done(vif, SCAN_EVENT_ABORTED);
+               }
+       }
+
+free_msg:
+       kfree(msg);
+}
+
+int wilc_disconnect(struct wilc_vif *vif)
+{
+       struct wid wid;
+       struct host_if_drv *hif_drv = vif->hif_drv;
+       struct wilc_user_scan_req *scan_req;
+       struct wilc_conn_info *conn_info;
+       int result;
+       u16 dummy_reason_code = 0;
+
+       wid.id = WID_DISCONNECT;
+       wid.type = WID_CHAR;
+       wid.val = (s8 *)&dummy_reason_code;
+       wid.size = sizeof(char);
+
+       vif->obtaining_ip = false;
+       wilc_set_power_mgmt(vif, 0, 0);
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result) {
+               netdev_err(vif->ndev, "Failed to send disconnect\n");
+               return result;
+       }
+
+       scan_req = &hif_drv->usr_scan_req;
+       conn_info = &hif_drv->conn_info;
+
+       if (scan_req->scan_result) {
+               del_timer(&hif_drv->scan_timer);
+               scan_req->scan_result(SCAN_EVENT_ABORTED, NULL, scan_req->arg);
+               scan_req->scan_result = NULL;
+       }
+
+       if (conn_info->conn_result) {
+               if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
+                       del_timer(&hif_drv->connect_timer);
+
+               conn_info->conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, 0,
+                                      conn_info->arg);
+       } else {
+               netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
+       }
+
+       hif_drv->hif_state = HOST_IF_IDLE;
+
+       eth_zero_addr(hif_drv->assoc_bssid);
+
+       conn_info->req_ies_len = 0;
+       kfree(conn_info->req_ies);
+       conn_info->req_ies = NULL;
+
+       return 0;
+}
+
+void wilc_resolve_disconnect_aberration(struct wilc_vif *vif)
+{
+       if (!vif->hif_drv)
+               return;
+       if (vif->hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP ||
+           vif->hif_drv->hif_state == HOST_IF_CONNECTING)
+               wilc_disconnect(vif);
+}
+
+int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
+{
+       struct wid wid_list[5];
+       u32 wid_cnt = 0, result;
+
+       wid_list[wid_cnt].id = WID_LINKSPEED;
+       wid_list[wid_cnt].type = WID_CHAR;
+       wid_list[wid_cnt].size = sizeof(char);
+       wid_list[wid_cnt].val = (s8 *)&stats->link_speed;
+       wid_cnt++;
+
+       wid_list[wid_cnt].id = WID_RSSI;
+       wid_list[wid_cnt].type = WID_CHAR;
+       wid_list[wid_cnt].size = sizeof(char);
+       wid_list[wid_cnt].val = (s8 *)&stats->rssi;
+       wid_cnt++;
+
+       wid_list[wid_cnt].id = WID_SUCCESS_FRAME_COUNT;
+       wid_list[wid_cnt].type = WID_INT;
+       wid_list[wid_cnt].size = sizeof(u32);
+       wid_list[wid_cnt].val = (s8 *)&stats->tx_cnt;
+       wid_cnt++;
+
+       wid_list[wid_cnt].id = WID_RECEIVED_FRAGMENT_COUNT;
+       wid_list[wid_cnt].type = WID_INT;
+       wid_list[wid_cnt].size = sizeof(u32);
+       wid_list[wid_cnt].val = (s8 *)&stats->rx_cnt;
+       wid_cnt++;
+
+       wid_list[wid_cnt].id = WID_FAILED_COUNT;
+       wid_list[wid_cnt].type = WID_INT;
+       wid_list[wid_cnt].size = sizeof(u32);
+       wid_list[wid_cnt].val = (s8 *)&stats->tx_fail_cnt;
+       wid_cnt++;
+
+       result = wilc_send_config_pkt(vif, WILC_GET_CFG, wid_list, wid_cnt);
+       if (result) {
+               netdev_err(vif->ndev, "Failed to send scan parameters\n");
+               return result;
+       }
+
+       if (stats->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
+           stats->link_speed != DEFAULT_LINK_SPEED)
+               wilc_enable_tcp_ack_filter(vif, true);
+       else if (stats->link_speed != DEFAULT_LINK_SPEED)
+               wilc_enable_tcp_ack_filter(vif, false);
+
+       return result;
+}
+
+static void handle_get_statistics(struct work_struct *work)
+{
+       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+       struct wilc_vif *vif = msg->vif;
+       struct rf_info *stats = (struct rf_info *)msg->body.data;
+
+       wilc_get_statistics(vif, stats);
+
+       kfree(msg);
+}
+
+static void wilc_hif_pack_sta_param(u8 *cur_byte, const u8 *mac,
+                                   struct station_parameters *params)
+{
+       ether_addr_copy(cur_byte, mac);
+       cur_byte += ETH_ALEN;
+
+       put_unaligned_le16(params->aid, cur_byte);
+       cur_byte += 2;
+
+       *cur_byte++ = params->supported_rates_len;
+       if (params->supported_rates_len > 0)
+               memcpy(cur_byte, params->supported_rates,
+                      params->supported_rates_len);
+       cur_byte += params->supported_rates_len;
+
+       if (params->ht_capa) {
+               *cur_byte++ = true;
+               memcpy(cur_byte, &params->ht_capa,
+                      sizeof(struct ieee80211_ht_cap));
+       } else {
+               *cur_byte++ = false;
+       }
+       cur_byte += sizeof(struct ieee80211_ht_cap);
+
+       put_unaligned_le16(params->sta_flags_mask, cur_byte);
+       cur_byte += 2;
+       put_unaligned_le16(params->sta_flags_set, cur_byte);
+}
+
+static int handle_remain_on_chan(struct wilc_vif *vif,
+                                struct wilc_remain_ch *hif_remain_ch)
+{
+       int result;
+       u8 remain_on_chan_flag;
+       struct wid wid;
+       struct host_if_drv *hif_drv = vif->hif_drv;
+
+       if (hif_drv->usr_scan_req.scan_result)
+               return -EBUSY;
+
+       if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
+               return -EBUSY;
+
+       if (vif->obtaining_ip || vif->connecting)
+               return -EBUSY;
+
+       remain_on_chan_flag = true;
+       wid.id = WID_REMAIN_ON_CHAN;
+       wid.type = WID_STR;
+       wid.size = 2;
+       wid.val = kmalloc(wid.size, GFP_KERNEL);
+       if (!wid.val)
+               return -ENOMEM;
+
+       wid.val[0] = remain_on_chan_flag;
+       wid.val[1] = (s8)hif_remain_ch->ch;
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       kfree(wid.val);
+       if (result)
+               return -EBUSY;
+
+       hif_drv->remain_on_ch.arg = hif_remain_ch->arg;
+       hif_drv->remain_on_ch.expired = hif_remain_ch->expired;
+       hif_drv->remain_on_ch.ch = hif_remain_ch->ch;
+       hif_drv->remain_on_ch.cookie = hif_remain_ch->cookie;
+       hif_drv->remain_on_ch_timer_vif = vif;
+
+       return 0;
+}
+
+static int wilc_handle_roc_expired(struct wilc_vif *vif, u64 cookie)
+{
+       u8 remain_on_chan_flag;
+       struct wid wid;
+       int result;
+       struct host_if_drv *hif_drv = vif->hif_drv;
+       struct wilc_priv *priv = wdev_priv(vif->ndev->ieee80211_ptr);
+
+       if (priv->p2p_listen_state) {
+               remain_on_chan_flag = false;
+               wid.id = WID_REMAIN_ON_CHAN;
+               wid.type = WID_STR;
+               wid.size = 2;
+
+               wid.val = kmalloc(wid.size, GFP_KERNEL);
+               if (!wid.val)
+                       return -ENOMEM;
+
+               wid.val[0] = remain_on_chan_flag;
+               wid.val[1] = WILC_FALSE_FRMWR_CHANNEL;
+
+               result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+               kfree(wid.val);
+               if (result != 0) {
+                       netdev_err(vif->ndev, "Failed to set remain channel\n");
+                       return -EINVAL;
+               }
+
+               if (hif_drv->remain_on_ch.expired) {
+                       hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg,
+                                                     cookie);
+               }
+       } else {
+               netdev_dbg(vif->ndev, "Not in listen state\n");
+       }
+
+       return 0;
+}
+
+static void wilc_handle_listen_state_expired(struct work_struct *work)
+{
+       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+
+       wilc_handle_roc_expired(msg->vif, msg->body.remain_on_ch.cookie);
+       kfree(msg);
+}
+
+static void listen_timer_cb(struct timer_list *t)
+{
+       struct host_if_drv *hif_drv = from_timer(hif_drv, t,
+                                                     remain_on_ch_timer);
+       struct wilc_vif *vif = hif_drv->remain_on_ch_timer_vif;
+       int result;
+       struct host_if_msg *msg;
+
+       del_timer(&vif->hif_drv->remain_on_ch_timer);
+
+       msg = wilc_alloc_work(vif, wilc_handle_listen_state_expired, false);
+       if (IS_ERR(msg))
+               return;
+
+       msg->body.remain_on_ch.cookie = vif->hif_drv->remain_on_ch.cookie;
+
+       result = wilc_enqueue_work(msg);
+       if (result) {
+               netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
+               kfree(msg);
+       }
+}
+
+static void handle_set_mcast_filter(struct work_struct *work)
+{
+       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+       struct wilc_vif *vif = msg->vif;
+       struct wilc_set_multicast *set_mc = &msg->body.mc_info;
+       int result;
+       struct wid wid;
+       u8 *cur_byte;
+
+       wid.id = WID_SETUP_MULTICAST_FILTER;
+       wid.type = WID_BIN;
+       wid.size = sizeof(struct wilc_set_multicast) + (set_mc->cnt * ETH_ALEN);
+       wid.val = kmalloc(wid.size, GFP_KERNEL);
+       if (!wid.val)
+               goto error;
+
+       cur_byte = wid.val;
+       put_unaligned_le32(set_mc->enabled, cur_byte);
+       cur_byte += 4;
+
+       put_unaligned_le32(set_mc->cnt, cur_byte);
+       cur_byte += 4;
+
+       if (set_mc->cnt > 0 && set_mc->mc_list)
+               memcpy(cur_byte, set_mc->mc_list, set_mc->cnt * ETH_ALEN);
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev, "Failed to send setup multicast\n");
+
+error:
+       kfree(set_mc->mc_list);
+       kfree(wid.val);
+       kfree(msg);
+}
+
+static void handle_scan_timer(struct work_struct *work)
+{
+       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+
+       handle_scan_done(msg->vif, SCAN_EVENT_ABORTED);
+       kfree(msg);
+}
+
+static void handle_scan_complete(struct work_struct *work)
+{
+       struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
+       struct wilc *wilc = msg->vif->wilc;
+
+       del_timer(&msg->vif->hif_drv->scan_timer);
+
+       if (!wilc_wlan_get_num_conn_ifcs(wilc))
+               wilc_chip_sleep_manually(wilc);
+
+       handle_scan_done(msg->vif, SCAN_EVENT_DONE);
+
+       kfree(msg);
+}
+
+static void timer_scan_cb(struct timer_list *t)
+{
+       struct host_if_drv *hif_drv = from_timer(hif_drv, t, scan_timer);
+       struct wilc_vif *vif = hif_drv->scan_timer_vif;
+       struct host_if_msg *msg;
+       int result;
+
+       msg = wilc_alloc_work(vif, handle_scan_timer, false);
+       if (IS_ERR(msg))
+               return;
+
+       result = wilc_enqueue_work(msg);
+       if (result)
+               kfree(msg);
+}
+
+static void timer_connect_cb(struct timer_list *t)
+{
+       struct host_if_drv *hif_drv = from_timer(hif_drv, t,
+                                                     connect_timer);
+       struct wilc_vif *vif = hif_drv->connect_timer_vif;
+       struct host_if_msg *msg;
+       int result;
+
+       msg = wilc_alloc_work(vif, handle_connect_timeout, false);
+       if (IS_ERR(msg))
+               return;
+
+       result = wilc_enqueue_work(msg);
+       if (result)
+               kfree(msg);
+}
+
+int wilc_remove_wep_key(struct wilc_vif *vif, u8 index)
+{
+       struct wid wid;
+       int result;
+
+       wid.id = WID_REMOVE_WEP_KEY;
+       wid.type = WID_STR;
+       wid.size = sizeof(char);
+       wid.val = &index;
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev,
+                          "Failed to send remove wep key config packet\n");
+       return result;
+}
+
+int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index)
+{
+       struct wid wid;
+       int result;
+
+       wid.id = WID_KEY_ID;
+       wid.type = WID_CHAR;
+       wid.size = sizeof(char);
+       wid.val = &index;
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev,
+                          "Failed to send wep default key config packet\n");
+
+       return result;
+}
+
+int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
+                            u8 index)
+{
+       struct wid wid;
+       int result;
+       struct wilc_wep_key *wep_key;
+
+       wid.id = WID_ADD_WEP_KEY;
+       wid.type = WID_STR;
+       wid.size = sizeof(*wep_key) + len;
+       wep_key = kzalloc(wid.size, GFP_KERNEL);
+       if (!wep_key)
+               return -ENOMEM;
+
+       wid.val = (u8 *)wep_key;
+
+       wep_key->index = index;
+       wep_key->key_len = len;
+       memcpy(wep_key->key, key, len);
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev,
+                          "Failed to add wep key config packet\n");
+
+       kfree(wep_key);
+       return result;
+}
+
+int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
+                           u8 index, u8 mode, enum authtype auth_type)
+{
+       struct wid wid_list[3];
+       int result;
+       struct wilc_wep_key *wep_key;
+
+       wid_list[0].id = WID_11I_MODE;
+       wid_list[0].type = WID_CHAR;
+       wid_list[0].size = sizeof(char);
+       wid_list[0].val = &mode;
+
+       wid_list[1].id = WID_AUTH_TYPE;
+       wid_list[1].type = WID_CHAR;
+       wid_list[1].size = sizeof(char);
+       wid_list[1].val = (s8 *)&auth_type;
+
+       wid_list[2].id = WID_WEP_KEY_VALUE;
+       wid_list[2].type = WID_STR;
+       wid_list[2].size = sizeof(*wep_key) + len;
+       wep_key = kzalloc(wid_list[2].size, GFP_KERNEL);
+       if (!wep_key)
+               return -ENOMEM;
+
+       wid_list[2].val = (u8 *)wep_key;
+
+       wep_key->index = index;
+       wep_key->key_len = len;
+       memcpy(wep_key->key, key, len);
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
+                                     ARRAY_SIZE(wid_list));
+       if (result)
+               netdev_err(vif->ndev,
+                          "Failed to add wep ap key config packet\n");
+
+       kfree(wep_key);
+       return result;
+}
+
+int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
+                const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic,
+                u8 mode, u8 cipher_mode, u8 index)
+{
+       int result = 0;
+       u8 t_key_len  = ptk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
+
+       if (mode == WILC_AP_MODE) {
+               struct wid wid_list[2];
+               struct wilc_ap_wpa_ptk *key_buf;
+
+               wid_list[0].id = WID_11I_MODE;
+               wid_list[0].type = WID_CHAR;
+               wid_list[0].size = sizeof(char);
+               wid_list[0].val = (s8 *)&cipher_mode;
+
+               key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
+               if (!key_buf)
+                       return -ENOMEM;
+
+               ether_addr_copy(key_buf->mac_addr, mac_addr);
+               key_buf->index = index;
+               key_buf->key_len = t_key_len;
+               memcpy(&key_buf->key[0], ptk, ptk_key_len);
+
+               if (rx_mic)
+                       memcpy(&key_buf->key[ptk_key_len], rx_mic,
+                              WILC_RX_MIC_KEY_LEN);
+
+               if (tx_mic)
+                       memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
+                              tx_mic, WILC_TX_MIC_KEY_LEN);
+
+               wid_list[1].id = WID_ADD_PTK;
+               wid_list[1].type = WID_STR;
+               wid_list[1].size = sizeof(*key_buf) + t_key_len;
+               wid_list[1].val = (u8 *)key_buf;
+               result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
+                                             ARRAY_SIZE(wid_list));
+               kfree(key_buf);
+       } else if (mode == WILC_STATION_MODE) {
+               struct wid wid;
+               struct wilc_sta_wpa_ptk *key_buf;
+
+               key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
+               if (!key_buf)
+                       return -ENOMEM;
+
+               ether_addr_copy(key_buf->mac_addr, mac_addr);
+               key_buf->key_len = t_key_len;
+               memcpy(&key_buf->key[0], ptk, ptk_key_len);
+
+               if (rx_mic)
+                       memcpy(&key_buf->key[ptk_key_len], rx_mic,
+                              WILC_RX_MIC_KEY_LEN);
+
+               if (tx_mic)
+                       memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
+                              tx_mic, WILC_TX_MIC_KEY_LEN);
+
+               wid.id = WID_ADD_PTK;
+               wid.type = WID_STR;
+               wid.size = sizeof(*key_buf) + t_key_len;
+               wid.val = (s8 *)key_buf;
+               result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+               kfree(key_buf);
+       }
+
+       return result;
+}
+
+int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
+                   u8 index, u32 key_rsc_len, const u8 *key_rsc,
+                   const u8 *rx_mic, const u8 *tx_mic, u8 mode,
+                   u8 cipher_mode)
+{
+       int result = 0;
+       struct wilc_gtk_key *gtk_key;
+       int t_key_len = gtk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
+
+       gtk_key = kzalloc(sizeof(*gtk_key) + t_key_len, GFP_KERNEL);
+       if (!gtk_key)
+               return -ENOMEM;
+
+       /* fill bssid value only in station mode */
+       if (mode == WILC_STATION_MODE &&
+           vif->hif_drv->hif_state == HOST_IF_CONNECTED)
+               memcpy(gtk_key->mac_addr, vif->hif_drv->assoc_bssid, ETH_ALEN);
+
+       if (key_rsc)
+               memcpy(gtk_key->rsc, key_rsc, 8);
+       gtk_key->index = index;
+       gtk_key->key_len = t_key_len;
+       memcpy(&gtk_key->key[0], rx_gtk, gtk_key_len);
+
+       if (rx_mic)
+               memcpy(&gtk_key->key[gtk_key_len], rx_mic, WILC_RX_MIC_KEY_LEN);
+
+       if (tx_mic)
+               memcpy(&gtk_key->key[gtk_key_len + WILC_RX_MIC_KEY_LEN],
+                      tx_mic, WILC_TX_MIC_KEY_LEN);
+
+       if (mode == WILC_AP_MODE) {
+               struct wid wid_list[2];
+
+               wid_list[0].id = WID_11I_MODE;
+               wid_list[0].type = WID_CHAR;
+               wid_list[0].size = sizeof(char);
+               wid_list[0].val = (s8 *)&cipher_mode;
+
+               wid_list[1].id = WID_ADD_RX_GTK;
+               wid_list[1].type = WID_STR;
+               wid_list[1].size = sizeof(*gtk_key) + t_key_len;
+               wid_list[1].val = (u8 *)gtk_key;
+
+               result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
+                                             ARRAY_SIZE(wid_list));
+       } else if (mode == WILC_STATION_MODE) {
+               struct wid wid;
+
+               wid.id = WID_ADD_RX_GTK;
+               wid.type = WID_STR;
+               wid.size = sizeof(*gtk_key) + t_key_len;
+               wid.val = (u8 *)gtk_key;
+               result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       }
+
+       kfree(gtk_key);
+       return result;
+}
+
+int wilc_set_pmkid_info(struct wilc_vif *vif, struct wilc_pmkid_attr *pmkid)
+{
+       struct wid wid;
+
+       wid.id = WID_PMKID_INFO;
+       wid.type = WID_STR;
+       wid.size = (pmkid->numpmkid * sizeof(struct wilc_pmkid)) + 1;
+       wid.val = (u8 *)pmkid;
+
+       return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+}
+
+int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)
+{
+       int result;
+       struct wid wid;
+
+       wid.id = WID_MAC_ADDR;
+       wid.type = WID_STR;
+       wid.size = ETH_ALEN;
+       wid.val = mac_addr;
+
+       result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev, "Failed to get mac address\n");
+
+       return result;
+}
+
+int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ies,
+                     size_t ies_len)
+{
+       int result;
+       struct host_if_drv *hif_drv = vif->hif_drv;
+       struct wilc_conn_info *conn_info = &hif_drv->conn_info;
+
+       if (bssid)
+               ether_addr_copy(conn_info->bssid, bssid);
+
+       if (ies) {
+               conn_info->req_ies_len = ies_len;
+               conn_info->req_ies = kmemdup(ies, ies_len, GFP_KERNEL);
+               if (!conn_info->req_ies)
+                       return -ENOMEM;
+       }
+
+       result = wilc_send_connect_wid(vif);
+       if (result)
+               goto free_ies;
+
+       hif_drv->connect_timer_vif = vif;
+       mod_timer(&hif_drv->connect_timer,
+                 jiffies + msecs_to_jiffies(WILC_HIF_CONNECT_TIMEOUT_MS));
+
+       return 0;
+
+free_ies:
+       kfree(conn_info->req_ies);
+
+       return result;
+}
+
+int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
+{
+       struct wid wid;
+       int result;
+
+       wid.id = WID_CURRENT_CHANNEL;
+       wid.type = WID_CHAR;
+       wid.size = sizeof(char);
+       wid.val = &channel;
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev, "Failed to set channel\n");
+
+       return result;
+}
+
+int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
+                            u8 ifc_id)
+{
+       struct wid wid;
+       struct host_if_drv *hif_drv = vif->hif_drv;
+       int result;
+       struct wilc_drv_handler drv;
+
+       if (!hif_drv)
+               return -EFAULT;
+
+       wid.id = WID_SET_DRV_HANDLER;
+       wid.type = WID_STR;
+       wid.size = sizeof(drv);
+       wid.val = (u8 *)&drv;
+
+       drv.handler = cpu_to_le32(index);
+       drv.mode = (ifc_id | (mode << 1));
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev, "Failed to set driver handler\n");
+
+       return result;
+}
+
+int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode)
+{
+       struct wid wid;
+       struct wilc_op_mode op_mode;
+       int result;
+
+       wid.id = WID_SET_OPERATION_MODE;
+       wid.type = WID_INT;
+       wid.size = sizeof(op_mode);
+       wid.val = (u8 *)&op_mode;
+
+       op_mode.mode = cpu_to_le32(mode);
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev, "Failed to set operation mode\n");
+
+       return result;
+}
+
+s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac, u32 *out_val)
+{
+       struct wid wid;
+       s32 result;
+
+       wid.id = WID_SET_STA_MAC_INACTIVE_TIME;
+       wid.type = WID_STR;
+       wid.size = ETH_ALEN;
+       wid.val = kzalloc(wid.size, GFP_KERNEL);
+       if (!wid.val)
+               return -ENOMEM;
+
+       ether_addr_copy(wid.val, mac);
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       kfree(wid.val);
+       if (result) {
+               netdev_err(vif->ndev, "Failed to set inactive mac\n");
+               return result;
+       }
+
+       wid.id = WID_GET_INACTIVE_TIME;
+       wid.type = WID_INT;
+       wid.val = (s8 *)out_val;
+       wid.size = sizeof(u32);
+       result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev, "Failed to get inactive time\n");
+
+       return result;
+}
+
+int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
+{
+       struct wid wid;
+       int result;
+
+       if (!rssi_level) {
+               netdev_err(vif->ndev, "%s: RSSI level is NULL\n", __func__);
+               return -EFAULT;
+       }
+
+       wid.id = WID_RSSI;
+       wid.type = WID_CHAR;
+       wid.size = sizeof(char);
+       wid.val = rssi_level;
+       result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev, "Failed to get RSSI value\n");
+
+       return result;
+}
+
+static int wilc_get_stats_async(struct wilc_vif *vif, struct rf_info *stats)
+{
+       int result;
+       struct host_if_msg *msg;
+
+       msg = wilc_alloc_work(vif, handle_get_statistics, false);
+       if (IS_ERR(msg))
+               return PTR_ERR(msg);
+
+       msg->body.data = (char *)stats;
+
+       result = wilc_enqueue_work(msg);
+       if (result) {
+               netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
+               kfree(msg);
+               return result;
+       }
+
+       return result;
+}
+
+int wilc_hif_set_cfg(struct wilc_vif *vif, struct cfg_param_attr *param)
+{
+       struct wid wid_list[4];
+       int i = 0;
+
+       if (param->flag & WILC_CFG_PARAM_RETRY_SHORT) {
+               wid_list[i].id = WID_SHORT_RETRY_LIMIT;
+               wid_list[i].val = (s8 *)&param->short_retry_limit;
+               wid_list[i].type = WID_SHORT;
+               wid_list[i].size = sizeof(u16);
+               i++;
+       }
+       if (param->flag & WILC_CFG_PARAM_RETRY_LONG) {
+               wid_list[i].id = WID_LONG_RETRY_LIMIT;
+               wid_list[i].val = (s8 *)&param->long_retry_limit;
+               wid_list[i].type = WID_SHORT;
+               wid_list[i].size = sizeof(u16);
+               i++;
+       }
+       if (param->flag & WILC_CFG_PARAM_FRAG_THRESHOLD) {
+               wid_list[i].id = WID_FRAG_THRESHOLD;
+               wid_list[i].val = (s8 *)&param->frag_threshold;
+               wid_list[i].type = WID_SHORT;
+               wid_list[i].size = sizeof(u16);
+               i++;
+       }
+       if (param->flag & WILC_CFG_PARAM_RTS_THRESHOLD) {
+               wid_list[i].id = WID_RTS_THRESHOLD;
+               wid_list[i].val = (s8 *)&param->rts_threshold;
+               wid_list[i].type = WID_SHORT;
+               wid_list[i].size = sizeof(u16);
+               i++;
+       }
+
+       return wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, i);
+}
+
+static void get_periodic_rssi(struct timer_list *t)
+{
+       struct wilc_vif *vif = from_timer(vif, t, periodic_rssi);
+
+       if (!vif->hif_drv) {
+               netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
+               return;
+       }
+
+       if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
+               wilc_get_stats_async(vif, &vif->periodic_stat);
+
+       mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
+}
+
+int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
+{
+       struct host_if_drv *hif_drv;
+       struct wilc_vif *vif = netdev_priv(dev);
+       struct wilc *wilc = vif->wilc;
+
+       hif_drv  = kzalloc(sizeof(*hif_drv), GFP_KERNEL);
+       if (!hif_drv)
+               return -ENOMEM;
+
+       *hif_drv_handler = hif_drv;
+
+       vif->hif_drv = hif_drv;
+       vif->obtaining_ip = false;
+
+       if (wilc->clients_count == 0)
+               mutex_init(&wilc->deinit_lock);
+
+       timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0);
+       mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
+
+       timer_setup(&hif_drv->scan_timer, timer_scan_cb, 0);
+       timer_setup(&hif_drv->connect_timer, timer_connect_cb, 0);
+       timer_setup(&hif_drv->remain_on_ch_timer, listen_timer_cb, 0);
+
+       hif_drv->hif_state = HOST_IF_IDLE;
+
+       hif_drv->p2p_timeout = 0;
+
+       wilc->clients_count++;
+
+       return 0;
+}
+
+int wilc_deinit(struct wilc_vif *vif)
+{
+       int result = 0;
+       struct host_if_drv *hif_drv = vif->hif_drv;
+
+       if (!hif_drv) {
+               netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
+               return -EFAULT;
+       }
+
+       mutex_lock(&vif->wilc->deinit_lock);
+
+       del_timer_sync(&hif_drv->scan_timer);
+       del_timer_sync(&hif_drv->connect_timer);
+       del_timer_sync(&vif->periodic_rssi);
+       del_timer_sync(&hif_drv->remain_on_ch_timer);
+
+       wilc_set_wfi_drv_handler(vif, 0, 0, 0);
+
+       if (hif_drv->usr_scan_req.scan_result) {
+               hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL,
+                                                 hif_drv->usr_scan_req.arg);
+               hif_drv->usr_scan_req.scan_result = NULL;
+       }
+
+       hif_drv->hif_state = HOST_IF_IDLE;
+
+       kfree(hif_drv);
+       vif->hif_drv = NULL;
+       vif->wilc->clients_count--;
+       mutex_unlock(&vif->wilc->deinit_lock);
+       return result;
+}
+
+void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
+{
+       int result;
+       struct host_if_msg *msg;
+       int id;
+       struct host_if_drv *hif_drv;
+       struct wilc_vif *vif;
+
+       id = get_unaligned_le32(&buffer[length - 4]);
+       vif = wilc_get_vif_from_idx(wilc, id);
+       if (!vif)
+               return;
+       hif_drv = vif->hif_drv;
+
+       if (!hif_drv) {
+               netdev_err(vif->ndev, "driver not init[%p]\n", hif_drv);
+               return;
+       }
+
+       msg = wilc_alloc_work(vif, handle_rcvd_ntwrk_info, false);
+       if (IS_ERR(msg))
+               return;
+
+       msg->body.net_info.frame_len = get_unaligned_le16(&buffer[6]) - 1;
+       msg->body.net_info.rssi = buffer[8];
+       msg->body.net_info.mgmt = kmemdup(&buffer[9],
+                                         msg->body.net_info.frame_len,
+                                         GFP_KERNEL);
+       if (!msg->body.net_info.mgmt) {
+               kfree(msg);
+               return;
+       }
+
+       result = wilc_enqueue_work(msg);
+       if (result) {
+               netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
+               kfree(msg->body.net_info.mgmt);
+               kfree(msg);
+       }
+}
+
+void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
+{
+       int result;
+       struct host_if_msg *msg;
+       int id;
+       struct host_if_drv *hif_drv;
+       struct wilc_vif *vif;
+
+       mutex_lock(&wilc->deinit_lock);
+
+       id = get_unaligned_le32(&buffer[length - 4]);
+       vif = wilc_get_vif_from_idx(wilc, id);
+       if (!vif) {
+               mutex_unlock(&wilc->deinit_lock);
+               return;
+       }
+
+       hif_drv = vif->hif_drv;
+
+       if (!hif_drv) {
+               mutex_unlock(&wilc->deinit_lock);
+               return;
+       }
+
+       if (!hif_drv->conn_info.conn_result) {
+               netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
+               mutex_unlock(&wilc->deinit_lock);
+               return;
+       }
+
+       msg = wilc_alloc_work(vif, handle_rcvd_gnrl_async_info, false);
+       if (IS_ERR(msg)) {
+               mutex_unlock(&wilc->deinit_lock);
+               return;
+       }
+
+       msg->body.mac_info.status = buffer[7];
+       result = wilc_enqueue_work(msg);
+       if (result) {
+               netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
+               kfree(msg);
+       }
+
+       mutex_unlock(&wilc->deinit_lock);
+}
+
+void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
+{
+       int result;
+       int id;
+       struct host_if_drv *hif_drv;
+       struct wilc_vif *vif;
+
+       id = get_unaligned_le32(&buffer[length - 4]);
+       vif = wilc_get_vif_from_idx(wilc, id);
+       if (!vif)
+               return;
+       hif_drv = vif->hif_drv;
+
+       if (!hif_drv)
+               return;
+
+       if (hif_drv->usr_scan_req.scan_result) {
+               struct host_if_msg *msg;
+
+               msg = wilc_alloc_work(vif, handle_scan_complete, false);
+               if (IS_ERR(msg))
+                       return;
+
+               result = wilc_enqueue_work(msg);
+               if (result) {
+                       netdev_err(vif->ndev, "%s: enqueue work failed\n",
+                                  __func__);
+                       kfree(msg);
+               }
+       }
+}
+
+int wilc_remain_on_channel(struct wilc_vif *vif, u64 cookie,
+                          u32 duration, u16 chan,
+                          void (*expired)(void *, u64),
+                          void *user_arg)
+{
+       struct wilc_remain_ch roc;
+       int result;
+
+       roc.ch = chan;
+       roc.expired = expired;
+       roc.arg = user_arg;
+       roc.duration = duration;
+       roc.cookie = cookie;
+       result = handle_remain_on_chan(vif, &roc);
+       if (result)
+               netdev_err(vif->ndev, "%s: failed to set remain on channel\n",
+                          __func__);
+
+       return result;
+}
+
+int wilc_listen_state_expired(struct wilc_vif *vif, u64 cookie)
+{
+       if (!vif->hif_drv) {
+               netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
+               return -EFAULT;
+       }
+
+       del_timer(&vif->hif_drv->remain_on_ch_timer);
+
+       return wilc_handle_roc_expired(vif, cookie);
+}
+
+void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
+{
+       struct wid wid;
+       int result;
+       struct wilc_reg_frame reg_frame;
+
+       wid.id = WID_REGISTER_FRAME;
+       wid.type = WID_STR;
+       wid.size = sizeof(reg_frame);
+       wid.val = (u8 *)&reg_frame;
+
+       memset(&reg_frame, 0x0, sizeof(reg_frame));
+       reg_frame.reg = reg;
+
+       switch (frame_type) {
+       case IEEE80211_STYPE_ACTION:
+               reg_frame.reg_id = WILC_FW_ACTION_FRM_IDX;
+               break;
+
+       case IEEE80211_STYPE_PROBE_REQ:
+               reg_frame.reg_id = WILC_FW_PROBE_REQ_IDX;
+               break;
+
+       default:
+               break;
+       }
+       reg_frame.frame_type = cpu_to_le16(frame_type);
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev, "Failed to frame register\n");
+}
+
+int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
+                   struct cfg80211_beacon_data *params)
+{
+       struct wid wid;
+       int result;
+       u8 *cur_byte;
+
+       wid.id = WID_ADD_BEACON;
+       wid.type = WID_BIN;
+       wid.size = params->head_len + params->tail_len + 16;
+       wid.val = kzalloc(wid.size, GFP_KERNEL);
+       if (!wid.val)
+               return -ENOMEM;
+
+       cur_byte = wid.val;
+       put_unaligned_le32(interval, cur_byte);
+       cur_byte += 4;
+       put_unaligned_le32(dtim_period, cur_byte);
+       cur_byte += 4;
+       put_unaligned_le32(params->head_len, cur_byte);
+       cur_byte += 4;
+
+       if (params->head_len > 0)
+               memcpy(cur_byte, params->head, params->head_len);
+       cur_byte += params->head_len;
+
+       put_unaligned_le32(params->tail_len, cur_byte);
+       cur_byte += 4;
+
+       if (params->tail_len > 0)
+               memcpy(cur_byte, params->tail, params->tail_len);
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev, "Failed to send add beacon\n");
+
+       kfree(wid.val);
+
+       return result;
+}
+
+int wilc_del_beacon(struct wilc_vif *vif)
+{
+       int result;
+       struct wid wid;
+       u8 del_beacon = 0;
+
+       wid.id = WID_DEL_BEACON;
+       wid.type = WID_CHAR;
+       wid.size = sizeof(char);
+       wid.val = &del_beacon;
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev, "Failed to send delete beacon\n");
+
+       return result;
+}
+
+int wilc_add_station(struct wilc_vif *vif, const u8 *mac,
+                    struct station_parameters *params)
+{
+       struct wid wid;
+       int result;
+       u8 *cur_byte;
+
+       wid.id = WID_ADD_STA;
+       wid.type = WID_BIN;
+       wid.size = WILC_ADD_STA_LENGTH + params->supported_rates_len;
+       wid.val = kmalloc(wid.size, GFP_KERNEL);
+       if (!wid.val)
+               return -ENOMEM;
+
+       cur_byte = wid.val;
+       wilc_hif_pack_sta_param(cur_byte, mac, params);
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result != 0)
+               netdev_err(vif->ndev, "Failed to send add station\n");
+
+       kfree(wid.val);
+
+       return result;
+}
+
+int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)
+{
+       struct wid wid;
+       int result;
+
+       wid.id = WID_REMOVE_STA;
+       wid.type = WID_BIN;
+       wid.size = ETH_ALEN;
+       wid.val = kzalloc(wid.size, GFP_KERNEL);
+       if (!wid.val)
+               return -ENOMEM;
+
+       if (!mac_addr)
+               eth_broadcast_addr(wid.val);
+       else
+               ether_addr_copy(wid.val, mac_addr);
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev, "Failed to del station\n");
+
+       kfree(wid.val);
+
+       return result;
+}
+
+int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
+{
+       struct wid wid;
+       int result;
+       int i;
+       u8 assoc_sta = 0;
+       struct wilc_del_all_sta del_sta;
+
+       memset(&del_sta, 0x0, sizeof(del_sta));
+       for (i = 0; i < WILC_MAX_NUM_STA; i++) {
+               if (!is_zero_ether_addr(mac_addr[i])) {
+                       assoc_sta++;
+                       ether_addr_copy(del_sta.mac[i], mac_addr[i]);
+               }
+       }
+
+       if (!assoc_sta)
+               return 0;
+
+       del_sta.assoc_sta = assoc_sta;
+
+       wid.id = WID_DEL_ALL_STA;
+       wid.type = WID_STR;
+       wid.size = (assoc_sta * ETH_ALEN) + 1;
+       wid.val = (u8 *)&del_sta;
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev, "Failed to send delete all station\n");
+
+       return result;
+}
+
+int wilc_edit_station(struct wilc_vif *vif, const u8 *mac,
+                     struct station_parameters *params)
+{
+       struct wid wid;
+       int result;
+       u8 *cur_byte;
+
+       wid.id = WID_EDIT_STA;
+       wid.type = WID_BIN;
+       wid.size = WILC_ADD_STA_LENGTH + params->supported_rates_len;
+       wid.val = kmalloc(wid.size, GFP_KERNEL);
+       if (!wid.val)
+               return -ENOMEM;
+
+       cur_byte = wid.val;
+       wilc_hif_pack_sta_param(cur_byte, mac, params);
+
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev, "Failed to send edit station\n");
+
+       kfree(wid.val);
+       return result;
+}
+
+int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
+{
+       struct wid wid;
+       int result;
+       s8 power_mode;
+
+       if (wilc_wlan_get_num_conn_ifcs(vif->wilc) == 2 && enabled)
+               return 0;
+
+       if (enabled)
+               power_mode = WILC_FW_MIN_FAST_PS;
+       else
+               power_mode = WILC_FW_NO_POWERSAVE;
+
+       wid.id = WID_POWER_MANAGEMENT;
+       wid.val = &power_mode;
+       wid.size = sizeof(char);
+       result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+       if (result)
+               netdev_err(vif->ndev, "Failed to send power management\n");
+
+       return result;
+}
+
+int wilc_setup_multicast_filter(struct wilc_vif *vif, u32 enabled, u32 count,
+                               u8 *mc_list)
+{
+       int result;
+       struct host_if_msg *msg;
+
+       msg = wilc_alloc_work(vif, handle_set_mcast_filter, false);
+       if (IS_ERR(msg))
+               return PTR_ERR(msg);
+
+       msg->body.mc_info.enabled = enabled;
+       msg->body.mc_info.cnt = count;
+       msg->body.mc_info.mc_list = mc_list;
+
+       result = wilc_enqueue_work(msg);
+       if (result) {
+               netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
+               kfree(msg);
+       }
+       return result;
+}
+
+int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
+{
+       struct wid wid;
+
+       wid.id = WID_TX_POWER;
+       wid.type = WID_CHAR;
+       wid.val = &tx_power;
+       wid.size = sizeof(char);
+
+       return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+}
+
+int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)
+{
+       struct wid wid;
+
+       wid.id = WID_TX_POWER;
+       wid.type = WID_CHAR;
+       wid.val = tx_power;
+       wid.size = sizeof(char);
+
+       return wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
+}
diff --git a/drivers/staging/wilc1000/wilc_hif.h b/drivers/staging/wilc1000/wilc_hif.h
new file mode 100644 (file)
index 0000000..be1d249
--- /dev/null
@@ -0,0 +1,235 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries
+ * All rights reserved.
+ */
+
+#ifndef HOST_INT_H
+#define HOST_INT_H
+#include <linux/ieee80211.h>
+#include "wilc_wlan_if.h"
+
+enum {
+       WILC_IDLE_MODE = 0x0,
+       WILC_AP_MODE = 0x1,
+       WILC_STATION_MODE = 0x2,
+       WILC_GO_MODE = 0x3,
+       WILC_CLIENT_MODE = 0x4
+};
+
+#define WILC_MAX_NUM_STA                       9
+#define WILC_MAX_NUM_SCANNED_CH                        14
+#define WILC_MAX_NUM_PROBED_SSID               10
+
+#define WILC_TX_MIC_KEY_LEN                    8
+#define WILC_RX_MIC_KEY_LEN                    8
+
+#define WILC_MAX_NUM_PMKIDS                    16
+#define WILC_ADD_STA_LENGTH                    40
+#define WILC_NUM_CONCURRENT_IFC                        2
+
+enum {
+       WILC_SET_CFG = 0,
+       WILC_GET_CFG
+};
+
+#define WILC_MAX_ASSOC_RESP_FRAME_SIZE   256
+
+struct assoc_resp {
+       __le16 capab_info;
+       __le16 status_code;
+       __le16 aid;
+} __packed;
+
+struct rf_info {
+       u8 link_speed;
+       s8 rssi;
+       u32 tx_cnt;
+       u32 rx_cnt;
+       u32 tx_fail_cnt;
+};
+
+enum host_if_state {
+       HOST_IF_IDLE                    = 0,
+       HOST_IF_SCANNING                = 1,
+       HOST_IF_CONNECTING              = 2,
+       HOST_IF_WAITING_CONN_RESP       = 3,
+       HOST_IF_CONNECTED               = 4,
+       HOST_IF_P2P_LISTEN              = 5,
+       HOST_IF_FORCE_32BIT             = 0xFFFFFFFF
+};
+
+struct wilc_pmkid {
+       u8 bssid[ETH_ALEN];
+       u8 pmkid[WLAN_PMKID_LEN];
+} __packed;
+
+struct wilc_pmkid_attr {
+       u8 numpmkid;
+       struct wilc_pmkid pmkidlist[WILC_MAX_NUM_PMKIDS];
+} __packed;
+
+struct cfg_param_attr {
+       u32 flag;
+       u16 short_retry_limit;
+       u16 long_retry_limit;
+       u16 frag_threshold;
+       u16 rts_threshold;
+};
+
+enum cfg_param {
+       WILC_CFG_PARAM_RETRY_SHORT = BIT(0),
+       WILC_CFG_PARAM_RETRY_LONG = BIT(1),
+       WILC_CFG_PARAM_FRAG_THRESHOLD = BIT(2),
+       WILC_CFG_PARAM_RTS_THRESHOLD = BIT(3)
+};
+
+enum scan_event {
+       SCAN_EVENT_NETWORK_FOUND        = 0,
+       SCAN_EVENT_DONE                 = 1,
+       SCAN_EVENT_ABORTED              = 2,
+       SCAN_EVENT_FORCE_32BIT          = 0xFFFFFFFF
+};
+
+enum conn_event {
+       CONN_DISCONN_EVENT_CONN_RESP            = 0,
+       CONN_DISCONN_EVENT_DISCONN_NOTIF        = 1,
+       CONN_DISCONN_EVENT_FORCE_32BIT          = 0xFFFFFFFF
+};
+
+enum {
+       WILC_HIF_SDIO = 0,
+       WILC_HIF_SPI = BIT(0)
+};
+
+enum {
+       WILC_MAC_STATUS_INIT = -1,
+       WILC_MAC_STATUS_DISCONNECTED = 0,
+       WILC_MAC_STATUS_CONNECTED = 1
+};
+
+struct wilc_rcvd_net_info {
+       s8 rssi;
+       u8 ch;
+       u16 frame_len;
+       struct ieee80211_mgmt *mgmt;
+};
+
+struct wilc_user_scan_req {
+       void (*scan_result)(enum scan_event evt,
+                           struct wilc_rcvd_net_info *info, void *priv);
+       void *arg;
+       u32 ch_cnt;
+};
+
+struct wilc_conn_info {
+       u8 bssid[ETH_ALEN];
+       u8 security;
+       enum authtype auth_type;
+       u8 ch;
+       u8 *req_ies;
+       size_t req_ies_len;
+       u8 *resp_ies;
+       u16 resp_ies_len;
+       u16 status;
+       void (*conn_result)(enum conn_event evt, u8 status, void *priv_data);
+       void *arg;
+       void *param;
+};
+
+struct wilc_remain_ch {
+       u16 ch;
+       u32 duration;
+       void (*expired)(void *priv, u64 cookie);
+       void *arg;
+       u32 cookie;
+};
+
+struct wilc;
+struct host_if_drv {
+       struct wilc_user_scan_req usr_scan_req;
+       struct wilc_conn_info conn_info;
+       struct wilc_remain_ch remain_on_ch;
+       u64 p2p_timeout;
+
+       enum host_if_state hif_state;
+
+       u8 assoc_bssid[ETH_ALEN];
+
+       struct timer_list scan_timer;
+       struct wilc_vif *scan_timer_vif;
+
+       struct timer_list connect_timer;
+       struct wilc_vif *connect_timer_vif;
+
+       struct timer_list remain_on_ch_timer;
+       struct wilc_vif *remain_on_ch_timer_vif;
+
+       bool ifc_up;
+       u8 assoc_resp[WILC_MAX_ASSOC_RESP_FRAME_SIZE];
+};
+
+struct wilc_vif;
+int wilc_remove_wep_key(struct wilc_vif *vif, u8 index);
+int wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index);
+int wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
+                            u8 index);
+int wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
+                           u8 index, u8 mode, enum authtype auth_type);
+int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
+                const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic,
+                u8 mode, u8 cipher_mode, u8 index);
+s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac,
+                          u32 *out_val);
+int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
+                   u8 index, u32 key_rsc_len, const u8 *key_rsc,
+                   const u8 *rx_mic, const u8 *tx_mic, u8 mode,
+                   u8 cipher_mode);
+int wilc_set_pmkid_info(struct wilc_vif *vif, struct wilc_pmkid_attr *pmkid);
+int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr);
+int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ies,
+                     size_t ies_len);
+int wilc_disconnect(struct wilc_vif *vif);
+int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel);
+int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level);
+int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
+             u8 *ch_freq_list, u8 ch_list_len,
+             void (*scan_result_fn)(enum scan_event,
+                                    struct wilc_rcvd_net_info *, void *),
+             void *user_arg, struct cfg80211_scan_request *request);
+int wilc_hif_set_cfg(struct wilc_vif *vif,
+                    struct cfg_param_attr *cfg_param);
+int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler);
+int wilc_deinit(struct wilc_vif *vif);
+int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
+                   struct cfg80211_beacon_data *params);
+int wilc_del_beacon(struct wilc_vif *vif);
+int wilc_add_station(struct wilc_vif *vif, const u8 *mac,
+                    struct station_parameters *params);
+int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN]);
+int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr);
+int wilc_edit_station(struct wilc_vif *vif, const u8 *mac,
+                     struct station_parameters *params);
+int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout);
+int wilc_setup_multicast_filter(struct wilc_vif *vif, u32 enabled, u32 count,
+                               u8 *mc_list);
+int wilc_remain_on_channel(struct wilc_vif *vif, u64 cookie,
+                          u32 duration, u16 chan,
+                          void (*expired)(void *, u64),
+                          void *user_arg);
+int wilc_listen_state_expired(struct wilc_vif *vif, u64 cookie);
+void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg);
+int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
+                            u8 ifc_id);
+int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode);
+int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats);
+void wilc_resolve_disconnect_aberration(struct wilc_vif *vif);
+int wilc_get_vif_idx(struct wilc_vif *vif);
+int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power);
+int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power);
+void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length);
+void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length);
+void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length);
+void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
+                               struct cfg80211_crypto_settings *crypto);
+#endif
index 9fe19a3e1dd48947f8156ec89a0cd6dd253741c3..7d7933d40924f379b8c28f5c62b7cb995c5926ee 100644 (file)
@@ -233,6 +233,7 @@ struct net_device *wilc_wfi_init_mon_interface(struct wilc *wl,
        strncpy(wl->monitor_dev->name, name, IFNAMSIZ);
        wl->monitor_dev->name[IFNAMSIZ - 1] = 0;
        wl->monitor_dev->netdev_ops = &wilc_wfi_netdev_ops;
+       wl->monitor_dev->needs_free_netdev = true;
 
        if (register_netdevice(wl->monitor_dev)) {
                netdev_err(real_dev, "register_netdevice failed\n");
@@ -247,12 +248,14 @@ struct net_device *wilc_wfi_init_mon_interface(struct wilc *wl,
        return wl->monitor_dev;
 }
 
-void wilc_wfi_deinit_mon_interface(struct wilc *wl)
+void wilc_wfi_deinit_mon_interface(struct wilc *wl, bool rtnl_locked)
 {
        if (!wl->monitor_dev)
                return;
 
-       unregister_netdev(wl->monitor_dev);
-       free_netdev(wl->monitor_dev);
+       if (rtnl_locked)
+               unregister_netdevice(wl->monitor_dev);
+       else
+               unregister_netdev(wl->monitor_dev);
        wl->monitor_dev = NULL;
 }
index ba78c08a17f120ea4872e9a913ce79c6110193f4..565e2b5d06164c1f648b0d482484336149998142 100644 (file)
@@ -97,22 +97,29 @@ static struct net_device *get_if_handler(struct wilc *wilc, u8 *mac_header)
 {
        u8 *bssid, *bssid1;
        int i = 0;
+       struct net_device *ndev = NULL;
 
        bssid = mac_header + 10;
        bssid1 = mac_header + 4;
 
+       mutex_lock(&wilc->vif_mutex);
        for (i = 0; i < wilc->vif_num; i++) {
                if (wilc->vif[i]->mode == WILC_STATION_MODE)
                        if (ether_addr_equal_unaligned(bssid,
-                                                      wilc->vif[i]->bssid))
-                               return wilc->vif[i]->ndev;
+                                                      wilc->vif[i]->bssid)) {
+                               ndev = wilc->vif[i]->ndev;
+                               goto out;
+                       }
                if (wilc->vif[i]->mode == WILC_AP_MODE)
                        if (ether_addr_equal_unaligned(bssid1,
-                                                      wilc->vif[i]->bssid))
-                               return wilc->vif[i]->ndev;
+                                                      wilc->vif[i]->bssid)) {
+                               ndev = wilc->vif[i]->ndev;
+                               goto out;
+                       }
        }
-
-       return NULL;
+out:
+       mutex_unlock(&wilc->vif_mutex);
+       return ndev;
 }
 
 void wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode)
@@ -143,9 +150,7 @@ static int wilc_txq_task(void *vp)
 {
        int ret;
        u32 txq_count;
-       struct net_device *dev = vp;
-       struct wilc_vif *vif = netdev_priv(dev);
-       struct wilc *wl = vif->wilc;
+       struct wilc *wl = vp;
 
        complete(&wl->txq_thread_started);
        while (1) {
@@ -159,14 +164,18 @@ static int wilc_txq_task(void *vp)
                        break;
                }
                do {
-                       ret = wilc_wlan_handle_txq(dev, &txq_count);
+                       ret = wilc_wlan_handle_txq(wl, &txq_count);
                        if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD) {
-                               if (wl->vif[0]->mac_opened &&
-                                   netif_queue_stopped(wl->vif[0]->ndev))
-                                       netif_wake_queue(wl->vif[0]->ndev);
-                               if (wl->vif[1]->mac_opened &&
-                                   netif_queue_stopped(wl->vif[1]->ndev))
-                                       netif_wake_queue(wl->vif[1]->ndev);
+                               int i;
+                               struct wilc_vif *ifc;
+
+                               mutex_lock(&wl->vif_mutex);
+                               for (i = 0; i < wl->vif_num; i++) {
+                                       ifc = wl->vif[i];
+                                       if (ifc->mac_opened && ifc->ndev)
+                                               netif_wake_queue(ifc->ndev);
+                               }
+                               mutex_unlock(&wl->vif_mutex);
                        }
                } while (ret == -ENOBUFS && !wl->close);
        }
@@ -245,14 +254,13 @@ static int wilc1000_firmware_download(struct net_device *dev)
 
 static int wilc_init_fw_config(struct net_device *dev, struct wilc_vif *vif)
 {
-       struct wilc_priv *priv;
+       struct wilc_priv *priv = &vif->priv;
        struct host_if_drv *hif_drv;
        u8 b;
        u16 hw;
        u32 w;
 
        netdev_dbg(dev, "Start configuring Firmware\n");
-       priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
        hif_drv = (struct host_if_drv *)priv->hif_drv;
        netdev_dbg(dev, "Host = %p\n", hif_drv);
 
@@ -424,6 +432,7 @@ static void wlan_deinit_locks(struct net_device *dev)
        mutex_destroy(&wilc->rxq_cs);
        mutex_destroy(&wilc->cfg_cmd_lock);
        mutex_destroy(&wilc->txq_add_to_head_cs);
+       mutex_destroy(&wilc->vif_mutex);
 }
 
 static void wlan_deinitialize_threads(struct net_device *dev)
@@ -477,31 +486,12 @@ static void wilc_wlan_deinitialize(struct net_device *dev)
        }
 }
 
-static void wlan_init_locks(struct net_device *dev)
-{
-       struct wilc_vif *vif = netdev_priv(dev);
-       struct wilc *wl = vif->wilc;
-
-       mutex_init(&wl->hif_cs);
-       mutex_init(&wl->rxq_cs);
-       mutex_init(&wl->cfg_cmd_lock);
-
-       spin_lock_init(&wl->txq_spinlock);
-       mutex_init(&wl->txq_add_to_head_cs);
-
-       init_completion(&wl->txq_event);
-
-       init_completion(&wl->cfg_event);
-       init_completion(&wl->sync_event);
-       init_completion(&wl->txq_thread_started);
-}
-
 static int wlan_initialize_threads(struct net_device *dev)
 {
        struct wilc_vif *vif = netdev_priv(dev);
        struct wilc *wilc = vif->wilc;
 
-       wilc->txq_thread = kthread_run(wilc_txq_task, (void *)dev,
+       wilc->txq_thread = kthread_run(wilc_txq_task, (void *)wilc,
                                       "K_TXQ_TASK");
        if (IS_ERR(wilc->txq_thread)) {
                netdev_err(dev, "couldn't create TXQ thread\n");
@@ -513,6 +503,12 @@ static int wlan_initialize_threads(struct net_device *dev)
        return 0;
 }
 
+static int dev_state_ev_handler(struct notifier_block *this,
+                               unsigned long event, void *ptr);
+static struct notifier_block g_dev_notifier = {
+       .notifier_call = dev_state_ev_handler
+};
+
 static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif)
 {
        int ret = 0;
@@ -522,23 +518,19 @@ static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif)
                wl->mac_status = WILC_MAC_STATUS_INIT;
                wl->close = 0;
 
-               wlan_init_locks(dev);
-
                ret = wilc_wlan_init(dev);
+               if (ret < 0)
+                       return -EIO;
+
+               ret = wlan_initialize_threads(dev);
                if (ret < 0) {
                        ret = -EIO;
-                       goto fail_locks;
+                       goto fail_wilc_wlan;
                }
 
                if (wl->gpio_irq && init_irq(dev)) {
                        ret = -EIO;
-                       goto fail_locks;
-               }
-
-               ret = wlan_initialize_threads(dev);
-               if (ret < 0) {
-                       ret = -EIO;
-                       goto fail_wilc_wlan;
+                       goto fail_threads;
                }
 
                if (!wl->dev_irq_num &&
@@ -582,7 +574,7 @@ static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif)
                        ret = -EIO;
                        goto fail_fw_start;
                }
-
+               register_inetaddr_notifier(&g_dev_notifier);
                wl->initialized = true;
                return 0;
 
@@ -596,12 +588,10 @@ fail_irq_enable:
 fail_irq_init:
                if (wl->dev_irq_num)
                        deinit_irq(dev);
-
+fail_threads:
                wlan_deinitialize_threads(dev);
 fail_wilc_wlan:
                wilc_wlan_cleanup(dev);
-fail_locks:
-               wlan_deinit_locks(dev);
                netdev_err(dev, "WLAN initialization FAILED\n");
        } else {
                netdev_dbg(dev, "wilc1000 already initialized\n");
@@ -624,7 +614,6 @@ static int wilc_mac_open(struct net_device *ndev)
        struct wilc_priv *priv = wdev_priv(vif->ndev->ieee80211_ptr);
        unsigned char mac_add[ETH_ALEN] = {0};
        int ret = 0;
-       int i = 0;
 
        if (!wl || !wl->dev) {
                netdev_err(ndev, "device not ready\n");
@@ -643,19 +632,13 @@ static int wilc_mac_open(struct net_device *ndev)
                return ret;
        }
 
-       for (i = 0; i < wl->vif_num; i++) {
-               if (ndev == wl->vif[i]->ndev) {
-                       wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif),
-                                                vif->iftype, vif->ifc_id);
-                       wilc_set_operation_mode(vif, vif->iftype);
-                       break;
-               }
-       }
+       wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif), vif->iftype,
+                                vif->idx);
+       wilc_set_operation_mode(vif, vif->iftype);
 
        wilc_get_mac_address(vif, mac_add);
        netdev_dbg(ndev, "Mac address: %pM\n", mac_add);
-       memcpy(wl->vif[i]->src_addr, mac_add, ETH_ALEN);
-       memcpy(ndev->dev_addr, wl->vif[i]->src_addr, ETH_ALEN);
+       ether_addr_copy(ndev->dev_addr, mac_add);
 
        if (!is_valid_ether_addr(ndev->dev_addr)) {
                netdev_err(ndev, "Wrong MAC address\n");
@@ -758,16 +741,19 @@ netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *ndev)
 
        vif->netstats.tx_packets++;
        vif->netstats.tx_bytes += tx_data->size;
-       tx_data->bssid = wilc->vif[vif->idx]->bssid;
        queue_count = wilc_wlan_txq_add_net_pkt(ndev, (void *)tx_data,
                                                tx_data->buff, tx_data->size,
                                                wilc_tx_complete);
 
        if (queue_count > FLOW_CONTROL_UPPER_THRESHOLD) {
-               if (wilc->vif[0]->mac_opened)
-                       netif_stop_queue(wilc->vif[0]->ndev);
-               if (wilc->vif[1]->mac_opened)
-                       netif_stop_queue(wilc->vif[1]->ndev);
+               int i;
+
+               mutex_lock(&wilc->vif_mutex);
+               for (i = 0; i < wilc->vif_num; i++) {
+                       if (wilc->vif[i]->mac_opened)
+                               netif_stop_queue(wilc->vif[i]->ndev);
+               }
+               mutex_unlock(&wilc->vif_mutex);
        }
 
        return 0;
@@ -794,6 +780,7 @@ static int wilc_mac_close(struct net_device *ndev)
        if (wl->open_ifcs == 0) {
                netdev_dbg(ndev, "Deinitializing wilc1000\n");
                wl->close = 1;
+               unregister_inetaddr_notifier(&g_dev_notifier);
                wilc_wlan_deinitialize(ndev);
        }
 
@@ -848,18 +835,23 @@ void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size)
        int i = 0;
        struct wilc_vif *vif;
 
+       mutex_lock(&wilc->vif_mutex);
        for (i = 0; i < wilc->vif_num; i++) {
+               u16 type = le16_to_cpup((__le16 *)buff);
+
                vif = netdev_priv(wilc->vif[i]->ndev);
+               if ((type == vif->frame_reg[0].type && vif->frame_reg[0].reg) ||
+                   (type == vif->frame_reg[1].type && vif->frame_reg[1].reg)) {
+                       wilc_wfi_p2p_rx(vif, buff, size);
+                       break;
+               }
+
                if (vif->monitor_flag) {
                        wilc_wfi_monitor_rx(wilc->monitor_dev, buff, size);
-                       return;
+                       break;
                }
        }
-
-       vif = netdev_priv(wilc->vif[1]->ndev);
-       if ((buff[0] == vif->frame_reg[0].type && vif->frame_reg[0].reg) ||
-           (buff[0] == vif->frame_reg[1].type && vif->frame_reg[1].reg))
-               wilc_wfi_p2p_rx(wilc->vif[1]->ndev, buff, size);
+       mutex_unlock(&wilc->vif_mutex);
 }
 
 static const struct net_device_ops wilc_netdev_ops = {
@@ -890,14 +882,10 @@ static int dev_state_ev_handler(struct notifier_block *this,
        if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
                return NOTIFY_DONE;
 
-       priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
-       if (!priv)
-               return NOTIFY_DONE;
+       vif = netdev_priv(dev);
+       priv = &vif->priv;
 
        hif_drv = (struct host_if_drv *)priv->hif_drv;
-       vif = netdev_priv(dev);
-       if (!vif || !hif_drv)
-               return NOTIFY_DONE;
 
        switch (event) {
        case NETDEV_UP:
@@ -932,10 +920,6 @@ static int dev_state_ev_handler(struct notifier_block *this,
        return NOTIFY_DONE;
 }
 
-static struct notifier_block g_dev_notifier = {
-       .notifier_call = dev_state_ev_handler
-};
-
 void wilc_netdev_cleanup(struct wilc *wilc)
 {
        int i;
@@ -943,137 +927,71 @@ void wilc_netdev_cleanup(struct wilc *wilc)
        if (!wilc)
                return;
 
-       if (wilc->vif[0]->ndev || wilc->vif[1]->ndev)
-               unregister_inetaddr_notifier(&g_dev_notifier);
-
        if (wilc->firmware) {
                release_firmware(wilc->firmware);
                wilc->firmware = NULL;
        }
 
-       for (i = 0; i < WILC_NUM_CONCURRENT_IFC; i++) {
-               if (wilc->vif[i] && wilc->vif[i]->ndev) {
+       for (i = 0; i < wilc->vif_num; i++) {
+               if (wilc->vif[i] && wilc->vif[i]->ndev)
                        unregister_netdev(wilc->vif[i]->ndev);
-                       wilc_free_wiphy(wilc->vif[i]->ndev);
-                       free_netdev(wilc->vif[i]->ndev);
-               }
        }
 
-       wilc_wfi_deinit_mon_interface(wilc);
+       wilc_wfi_deinit_mon_interface(wilc, false);
        flush_workqueue(wilc->hif_workqueue);
        destroy_workqueue(wilc->hif_workqueue);
        wilc_wlan_cfg_deinit(wilc);
        kfree(wilc->bus_data);
-       kfree(wilc);
+       wiphy_unregister(wilc->wiphy);
+       wiphy_free(wilc->wiphy);
 }
 EXPORT_SYMBOL_GPL(wilc_netdev_cleanup);
 
-int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
-                    const struct wilc_hif_func *ops)
+struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
+                                     int vif_type, enum nl80211_iftype type,
+                                     bool rtnl_locked)
 {
-       int i, ret;
-       struct wilc_vif *vif;
        struct net_device *ndev;
-       struct wilc *wl;
-
-       wl = kzalloc(sizeof(*wl), GFP_KERNEL);
-       if (!wl)
-               return -ENOMEM;
-
-       ret = wilc_wlan_cfg_init(wl);
-       if (ret)
-               goto free_wl;
-
-       *wilc = wl;
-       wl->io_type = io_type;
-       wl->hif_func = ops;
-       wl->enable_ps = true;
-       wl->chip_ps_state = WILC_CHIP_WAKEDUP;
-       INIT_LIST_HEAD(&wl->txq_head.list);
-       INIT_LIST_HEAD(&wl->rxq_head.list);
-
-       wl->hif_workqueue = create_singlethread_workqueue("WILC_wq");
-       if (!wl->hif_workqueue) {
-               ret = -ENOMEM;
-               goto free_cfg;
-       }
-
-       register_inetaddr_notifier(&g_dev_notifier);
-
-       for (i = 0; i < WILC_NUM_CONCURRENT_IFC; i++) {
-               struct wireless_dev *wdev;
+       struct wilc_vif *vif;
+       int ret;
 
-               ndev = alloc_etherdev(sizeof(struct wilc_vif));
-               if (!ndev) {
-                       ret = -ENOMEM;
-                       goto free_ndev;
-               }
+       ndev = alloc_etherdev(sizeof(*vif));
+       if (!ndev)
+               return ERR_PTR(-ENOMEM);
 
-               vif = netdev_priv(ndev);
-               memset(vif, 0, sizeof(struct wilc_vif));
+       vif = netdev_priv(ndev);
+       ndev->ieee80211_ptr = &vif->priv.wdev;
+       strcpy(ndev->name, name);
+       vif->wilc = wl;
+       vif->ndev = ndev;
+       ndev->ml_priv = vif;
 
-               if (i == 0) {
-                       strcpy(ndev->name, "wlan%d");
-                       vif->ifc_id = 1;
-               } else {
-                       strcpy(ndev->name, "p2p%d");
-                       vif->ifc_id = 0;
-               }
-               vif->wilc = *wilc;
-               vif->ndev = ndev;
-               wl->vif[i] = vif;
-               wl->vif_num = i + 1;
-               vif->idx = i;
-
-               ndev->netdev_ops = &wilc_netdev_ops;
-
-               wdev = wilc_create_wiphy(ndev, dev);
-               if (!wdev) {
-                       netdev_err(ndev, "Can't register WILC Wiphy\n");
-                       ret = -ENOMEM;
-                       goto free_ndev;
-               }
+       ndev->netdev_ops = &wilc_netdev_ops;
 
-               SET_NETDEV_DEV(ndev, dev);
+       SET_NETDEV_DEV(ndev, wiphy_dev(wl->wiphy));
 
-               vif->ndev->ieee80211_ptr = wdev;
-               vif->ndev->ml_priv = vif;
-               wdev->netdev = vif->ndev;
-               vif->netstats.rx_packets = 0;
-               vif->netstats.tx_packets = 0;
-               vif->netstats.rx_bytes = 0;
-               vif->netstats.tx_bytes = 0;
+       vif->priv.wdev.wiphy = wl->wiphy;
+       vif->priv.wdev.netdev = ndev;
+       vif->priv.wdev.iftype = type;
+       vif->priv.dev = ndev;
 
+       if (rtnl_locked)
+               ret = register_netdevice(ndev);
+       else
                ret = register_netdev(ndev);
-               if (ret)
-                       goto free_ndev;
 
-               vif->iftype = WILC_STATION_MODE;
-               vif->mac_opened = 0;
+       if (ret) {
+               free_netdev(ndev);
+               return ERR_PTR(-EFAULT);
        }
 
-       return 0;
-
-free_ndev:
-       for (; i >= 0; i--) {
-               if (wl->vif[i]) {
-                       if (wl->vif[i]->iftype == WILC_STATION_MODE)
-                               unregister_netdev(wl->vif[i]->ndev);
-
-                       if (wl->vif[i]->ndev) {
-                               wilc_free_wiphy(wl->vif[i]->ndev);
-                               free_netdev(wl->vif[i]->ndev);
-                       }
-               }
-       }
-       unregister_inetaddr_notifier(&g_dev_notifier);
-       destroy_workqueue(wl->hif_workqueue);
-free_cfg:
-       wilc_wlan_cfg_deinit(wl);
-free_wl:
-       kfree(wl);
-       return ret;
+       ndev->needs_free_netdev = true;
+       vif->iftype = vif_type;
+       vif->wilc->vif[wl->vif_num] = vif;
+       vif->idx = wl->vif_num;
+       wl->vif_num += 1;
+       vif->mac_opened = 0;
+       return vif;
 }
-EXPORT_SYMBOL_GPL(wilc_netdev_init);
 
 MODULE_LICENSE("GPL");
index b789c57d7e80ccf62bd9cc7dffb6d717c57f307d..4c1c81fed11ffb6d79b2cbe19fe0c68fb95f975f 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/mmc/host.h>
 
 #include "wilc_wfi_netdevice.h"
+#include "wilc_wfi_cfgoperations.h"
 
 #define SDIO_MODALIAS "wilc1000_sdio"
 
@@ -139,11 +140,9 @@ static int wilc_sdio_probe(struct sdio_func *func,
                }
        }
 
-       dev_dbg(&func->dev, "Initializing netdev\n");
-       ret = wilc_netdev_init(&wilc, &func->dev, WILC_HIF_SDIO,
-                              &wilc_hif_sdio);
+       ret = wilc_cfg80211_init(&wilc, &func->dev, WILC_HIF_SDIO,
+                                &wilc_hif_sdio);
        if (ret) {
-               dev_err(&func->dev, "Couldn't initialize netdev\n");
                kfree(sdio_priv);
                return ret;
        }
index d8910bf9cb753f0280a148cc88ec317dc7e69ceb..3c1ae9e9f9aa1a2bcc4688ac007801ccab699faa 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/spi/spi.h>
 
 #include "wilc_wfi_netdevice.h"
+#include "wilc_wfi_cfgoperations.h"
 
 struct wilc_spi {
        int crc_off;
@@ -120,7 +121,7 @@ static int wilc_bus_probe(struct spi_device *spi)
                        dev_err(&spi->dev, "failed to get the irq gpio\n");
        }
 
-       ret = wilc_netdev_init(&wilc, NULL, WILC_HIF_SPI, &wilc_hif_spi);
+       ret = wilc_cfg80211_init(&wilc, &spi->dev, WILC_HIF_SPI, &wilc_hif_spi);
        if (ret) {
                kfree(spi_priv);
                return ret;
index f6825727bf7741501c32798ba8bb9e706bc5767a..d72fdd333050cd45042237942f794a41f9d7ffa9 100644 (file)
@@ -183,47 +183,67 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt, u8 mac_status,
                eth_zero_addr(priv->associated_bss);
                wilc_wlan_set_bssid(priv->dev, NULL, WILC_STATION_MODE);
 
-               if (vif->iftype != WILC_CLIENT_MODE)
+               if (vif->iftype != WILC_CLIENT_MODE) {
                        wl->sta_ch = WILC_INVALID_CHANNEL;
-
-               if (wfi_drv->ifc_up && dev == wl->vif[1]->ndev)
-                       reason = 3;
-               else if (!wfi_drv->ifc_up && dev == wl->vif[1]->ndev)
-                       reason = 1;
+               } else {
+                       if (wfi_drv->ifc_up)
+                               reason = 3;
+                       else
+                               reason = 1;
+               }
 
                cfg80211_disconnected(dev, reason, NULL, 0, false, GFP_KERNEL);
        }
 }
 
+static struct wilc_vif *wilc_get_wl_to_vif(struct wilc *wl)
+{
+       int i;
+
+       for (i = 0; i < wl->vif_num; i++)
+               if (wl->vif[i])
+                       return wl->vif[i];
+
+       return ERR_PTR(-EINVAL);
+}
+
 static int set_channel(struct wiphy *wiphy,
                       struct cfg80211_chan_def *chandef)
 {
-       u32 channelnum = 0;
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
-       int result = 0;
+       struct wilc *wl = wiphy_priv(wiphy);
+       struct wilc_vif *vif;
+       u32 channelnum;
+       int result;
+
+       mutex_lock(&wl->vif_mutex);
+       vif = wilc_get_wl_to_vif(wl);
+       if (IS_ERR(vif)) {
+               mutex_unlock(&wl->vif_mutex);
+               return PTR_ERR(vif);
+       }
 
        channelnum = ieee80211_frequency_to_channel(chandef->chan->center_freq);
 
-       vif->wilc->op_ch = channelnum;
+       wl->op_ch = channelnum;
        result = wilc_set_mac_chnl_num(vif, channelnum);
+       if (result)
+               netdev_err(vif->ndev, "Error in setting channel\n");
 
-       if (result != 0)
-               netdev_err(priv->dev, "Error in setting channel\n");
-
+       mutex_unlock(&wl->vif_mutex);
        return result;
 }
 
 static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc_vif *vif = netdev_priv(request->wdev->netdev);
+       struct wilc_priv *priv = &vif->priv;
        u32 i;
        int ret = 0;
        u8 scan_ch_list[WILC_MAX_NUM_SCANNED_CH];
+       u8 scan_type;
 
        if (request->n_channels > WILC_MAX_NUM_SCANNED_CH) {
-               netdev_err(priv->dev, "Requested scanned channels over\n");
+               netdev_err(vif->ndev, "Requested scanned channels over\n");
                return -EINVAL;
        }
 
@@ -235,9 +255,14 @@ static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
                scan_ch_list[i] = ieee80211_frequency_to_channel(freq);
        }
 
-       ret = wilc_scan(vif, WILC_FW_USER_SCAN, WILC_FW_ACTIVE_SCAN,
-                       scan_ch_list, request->n_channels, cfg_scan_result,
-                       (void *)priv, request);
+       if (request->n_ssids)
+               scan_type = WILC_FW_ACTIVE_SCAN;
+       else
+               scan_type = WILC_FW_PASSIVE_SCAN;
+
+       ret = wilc_scan(vif, WILC_FW_USER_SCAN, scan_type, scan_ch_list,
+                       request->n_channels, cfg_scan_result, (void *)priv,
+                       request);
 
        if (ret) {
                priv->scan_req = NULL;
@@ -250,8 +275,8 @@ static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
 static int connect(struct wiphy *wiphy, struct net_device *dev,
                   struct cfg80211_connect_params *sme)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc_vif *vif = netdev_priv(dev);
+       struct wilc_priv *priv = &vif->priv;
        struct host_if_drv *wfi_drv = priv->hif_drv;
        int ret;
        u32 i;
@@ -404,8 +429,8 @@ out_error:
 static int disconnect(struct wiphy *wiphy, struct net_device *dev,
                      u16 reason_code)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc_vif *vif = netdev_priv(dev);
+       struct wilc_priv *priv = &vif->priv;
        struct wilc *wilc = vif->wilc;
        int ret;
 
@@ -495,17 +520,17 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
 
 {
        int ret = 0, keylen = params->key_len;
-       struct wilc_priv *priv = wiphy_priv(wiphy);
        const u8 *rx_mic = NULL;
        const u8 *tx_mic = NULL;
        u8 mode = WILC_FW_SEC_NO;
        u8 op_mode;
        struct wilc_vif *vif = netdev_priv(netdev);
+       struct wilc_priv *priv = &vif->priv;
 
        switch (params->cipher) {
        case WLAN_CIPHER_SUITE_WEP40:
        case WLAN_CIPHER_SUITE_WEP104:
-               if (priv->wdev->iftype == NL80211_IFTYPE_AP) {
+               if (priv->wdev.iftype == NL80211_IFTYPE_AP) {
                        wilc_wfi_cfg_copy_wep_info(priv, key_index, params);
 
                        if (params->cipher == WLAN_CIPHER_SUITE_WEP40)
@@ -532,8 +557,8 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
 
        case WLAN_CIPHER_SUITE_TKIP:
        case WLAN_CIPHER_SUITE_CCMP:
-               if (priv->wdev->iftype == NL80211_IFTYPE_AP ||
-                   priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) {
+               if (priv->wdev.iftype == NL80211_IFTYPE_AP ||
+                   priv->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
                        struct wilc_wfi_key *key;
 
                        ret = wilc_wfi_cfg_allocate_wpa_entry(priv, key_index);
@@ -605,9 +630,9 @@ static int del_key(struct wiphy *wiphy, struct net_device *netdev,
                   bool pairwise,
                   const u8 *mac_addr)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
+       struct wilc *wl = wiphy_priv(wiphy);
        struct wilc_vif *vif = netdev_priv(netdev);
-       struct wilc *wl = vif->wilc;
+       struct wilc_priv *priv = &vif->priv;
 
        if (netdev == wl->vif[0]->ndev) {
                if (priv->wilc_gtk[key_index]) {
@@ -644,7 +669,8 @@ static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
                   bool pairwise, const u8 *mac_addr, void *cookie,
                   void (*callback)(void *cookie, struct key_params *))
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
+       struct wilc_vif *vif = netdev_priv(netdev);
+       struct wilc_priv *priv = &vif->priv;
        struct  key_params key_params;
 
        if (!pairwise) {
@@ -669,8 +695,7 @@ static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
 static int set_default_key(struct wiphy *wiphy, struct net_device *netdev,
                           u8 key_index, bool unicast, bool multicast)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc_vif *vif = netdev_priv(netdev);
 
        wilc_set_wep_default_keyid(vif, key_index);
 
@@ -680,8 +705,8 @@ static int set_default_key(struct wiphy *wiphy, struct net_device *netdev,
 static int get_station(struct wiphy *wiphy, struct net_device *dev,
                       const u8 *mac, struct station_info *sinfo)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
        struct wilc_vif *vif = netdev_priv(dev);
+       struct wilc_priv *priv = &vif->priv;
        u32 i = 0;
        u32 associatedsta = ~0;
        u32 inactive_time = 0;
@@ -737,13 +762,35 @@ static int change_bss(struct wiphy *wiphy, struct net_device *dev,
        return 0;
 }
 
+struct wilc_vif *wilc_get_interface(struct wilc *wl)
+{
+       int i;
+       struct wilc_vif *vif = NULL;
+
+       mutex_lock(&wl->vif_mutex);
+       for (i = 0; i < wl->vif_num; i++) {
+               if (wl->vif[i]) {
+                       vif = wl->vif[i];
+                       break;
+               }
+       }
+       mutex_unlock(&wl->vif_mutex);
+       return vif;
+}
+
 static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
 {
        int ret;
        struct cfg_param_attr cfg_param_val;
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc *wl = wiphy_priv(wiphy);
+       struct wilc_vif *vif;
+       struct wilc_priv *priv;
+
+       vif = wilc_get_interface(wl);
+       if (!vif)
+               return -EINVAL;
 
+       priv = &vif->priv;
        cfg_param_val.flag = 0;
 
        if (changed & WIPHY_PARAM_RETRY_SHORT) {
@@ -798,8 +845,8 @@ static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
 static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
                     struct cfg80211_pmksa *pmksa)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc_vif *vif = netdev_priv(netdev);
+       struct wilc_priv *priv = &vif->priv;
        u32 i;
        int ret = 0;
        u8 flag = 0;
@@ -834,7 +881,8 @@ static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
 {
        u32 i;
        int ret = 0;
-       struct wilc_priv *priv = wiphy_priv(wiphy);
+       struct wilc_vif *vif = netdev_priv(netdev);
+       struct wilc_priv *priv = &vif->priv;
 
        for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
                if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
@@ -864,9 +912,9 @@ static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
 
 static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
+       struct wilc_vif *vif = netdev_priv(netdev);
 
-       memset(&priv->pmkid_list, 0, sizeof(struct wilc_pmkid_attr));
+       memset(&vif->priv.pmkid_list, 0, sizeof(struct wilc_pmkid_attr));
 
        return 0;
 }
@@ -981,12 +1029,11 @@ static void wilc_wfi_cfg_parse_rx_vendor_spec(struct wilc_priv *priv, u8 *buff,
        }
 }
 
-void wilc_wfi_p2p_rx(struct net_device *dev, u8 *buff, u32 size)
+void wilc_wfi_p2p_rx(struct wilc_vif *vif, u8 *buff, u32 size)
 {
-       struct wilc_priv *priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
-       struct host_if_drv *wfi_drv = priv->hif_drv;
-       struct wilc_vif *vif = netdev_priv(dev);
        struct wilc *wl = vif->wilc;
+       struct wilc_priv *priv = &vif->priv;
+       struct host_if_drv *wfi_drv = priv->hif_drv;
        u32 header, pkt_offset;
        s32 freq;
        __le16 fc;
@@ -1002,8 +1049,8 @@ void wilc_wfi_p2p_rx(struct net_device *dev, u8 *buff, u32 size)
                    pkt_offset & IS_MGMT_STATUS_SUCCES)
                        ack = true;
 
-               cfg80211_mgmt_tx_status(priv->wdev, priv->tx_cookie, buff, size,
-                                       ack, GFP_KERNEL);
+               cfg80211_mgmt_tx_status(&priv->wdev, priv->tx_cookie, buff,
+                                       size, ack, GFP_KERNEL);
                return;
        }
 
@@ -1011,13 +1058,13 @@ void wilc_wfi_p2p_rx(struct net_device *dev, u8 *buff, u32 size)
 
        fc = ((struct ieee80211_hdr *)buff)->frame_control;
        if (!ieee80211_is_action(fc)) {
-               cfg80211_rx_mgmt(priv->wdev, freq, 0, buff, size, 0);
+               cfg80211_rx_mgmt(&priv->wdev, freq, 0, buff, size, 0);
                return;
        }
 
        if (priv->cfg_scanning &&
            time_after_eq(jiffies, (unsigned long)wfi_drv->p2p_timeout)) {
-               netdev_dbg(dev, "Receiving action wrong ch\n");
+               netdev_dbg(vif->ndev, "Receiving action wrong ch\n");
                return;
        }
        if (buff[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
@@ -1040,14 +1087,14 @@ void wilc_wfi_p2p_rx(struct net_device *dev, u8 *buff, u32 size)
                        break;
 
                default:
-                       netdev_dbg(dev,
+                       netdev_dbg(vif->ndev,
                                   "%s: Not handled action frame type:%x\n",
                                   __func__, buff[ACTION_SUBTYPE_ID]);
                        break;
                }
        }
 
-       cfg80211_rx_mgmt(priv->wdev, freq, 0, buff, size, 0);
+       cfg80211_rx_mgmt(&priv->wdev, freq, 0, buff, size, 0);
 }
 
 static void wilc_wfi_mgmt_tx_complete(void *priv, int status)
@@ -1060,7 +1107,8 @@ static void wilc_wfi_mgmt_tx_complete(void *priv, int status)
 
 static void wilc_wfi_remain_on_channel_expired(void *data, u64 cookie)
 {
-       struct wilc_priv *priv = data;
+       struct wilc_vif *vif = data;
+       struct wilc_priv *priv = &vif->priv;
        struct wilc_wfi_p2p_listen_params *params = &priv->remain_on_ch_params;
 
        if (cookie != params->listen_cookie)
@@ -1068,7 +1116,7 @@ static void wilc_wfi_remain_on_channel_expired(void *data, u64 cookie)
 
        priv->p2p_listen_state = false;
 
-       cfg80211_remain_on_channel_expired(priv->wdev, params->listen_cookie,
+       cfg80211_remain_on_channel_expired(&priv->wdev, params->listen_cookie,
                                           params->listen_ch, GFP_KERNEL);
 }
 
@@ -1078,8 +1126,8 @@ static int remain_on_channel(struct wiphy *wiphy,
                             unsigned int duration, u64 *cookie)
 {
        int ret = 0;
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc_vif *vif = netdev_priv(wdev->netdev);
+       struct wilc_priv *priv = &vif->priv;
        u64 id;
 
        if (wdev->iftype == NL80211_IFTYPE_AP) {
@@ -1093,7 +1141,7 @@ static int remain_on_channel(struct wiphy *wiphy,
 
        ret = wilc_remain_on_channel(vif, id, duration, chan->hw_value,
                                     wilc_wfi_remain_on_channel_expired,
-                                    (void *)priv);
+                                    (void *)vif);
        if (ret)
                return ret;
 
@@ -1116,8 +1164,8 @@ static int cancel_remain_on_channel(struct wiphy *wiphy,
                                    struct wireless_dev *wdev,
                                    u64 cookie)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc_vif *vif = netdev_priv(wdev->netdev);
+       struct wilc_priv *priv = &vif->priv;
 
        if (cookie != priv->remain_on_ch_params.listen_cookie)
                return -ENOENT;
@@ -1187,9 +1235,9 @@ static int mgmt_tx(struct wiphy *wiphy,
        size_t len = params->len;
        const struct ieee80211_mgmt *mgmt;
        struct wilc_p2p_mgmt_data *mgmt_tx;
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct host_if_drv *wfi_drv = priv->hif_drv;
        struct wilc_vif *vif = netdev_priv(wdev->netdev);
+       struct wilc_priv *priv = &vif->priv;
+       struct host_if_drv *wfi_drv = priv->hif_drv;
        u32 buf_len = len + sizeof(p2p_vendor_spec) +
                        sizeof(priv->p2p.local_random);
        int ret = 0;
@@ -1273,7 +1321,8 @@ static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
                               struct wireless_dev *wdev,
                               u64 cookie)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
+       struct wilc_vif *vif = netdev_priv(wdev->netdev);
+       struct wilc_priv *priv = &vif->priv;
        struct host_if_drv *wfi_drv = priv->hif_drv;
 
        wfi_drv->p2p_timeout = jiffies;
@@ -1283,7 +1332,7 @@ static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
 
                params = &priv->remain_on_ch_params;
 
-               cfg80211_remain_on_channel_expired(priv->wdev,
+               cfg80211_remain_on_channel_expired(wdev,
                                                   params->listen_cookie,
                                                   params->listen_ch,
                                                   GFP_KERNEL);
@@ -1295,9 +1344,8 @@ static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
 void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
                              u16 frame_type, bool reg)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->wdev->netdev);
-       struct wilc *wl = vif->wilc;
+       struct wilc *wl = wiphy_priv(wiphy);
+       struct wilc_vif *vif = netdev_priv(wdev->netdev);
 
        if (!frame_type)
                return;
@@ -1331,8 +1379,7 @@ static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev,
 static int dump_station(struct wiphy *wiphy, struct net_device *dev,
                        int idx, u8 *mac, struct station_info *sinfo)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc_vif *vif = netdev_priv(dev);
        int ret;
 
        if (idx != 0)
@@ -1344,15 +1391,15 @@ static int dump_station(struct wiphy *wiphy, struct net_device *dev,
        if (ret)
                return ret;
 
-       memcpy(mac, priv->associated_bss, ETH_ALEN);
+       memcpy(mac, vif->priv.associated_bss, ETH_ALEN);
        return 0;
 }
 
 static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
                          bool enabled, int timeout)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc_vif *vif = netdev_priv(dev);
+       struct wilc_priv *priv = &vif->priv;
 
        if (!priv->hif_drv)
                return -EIO;
@@ -1367,9 +1414,9 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
                               enum nl80211_iftype type,
                               struct vif_params *params)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
+       struct wilc *wl = wiphy_priv(wiphy);
        struct wilc_vif *vif = netdev_priv(dev);
-       struct wilc *wl = vif->wilc;
+       struct wilc_priv *priv = &vif->priv;
 
        priv->p2p.local_random = 0x01;
        priv->p2p.recv_random = 0x00;
@@ -1381,8 +1428,10 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
        case NL80211_IFTYPE_STATION:
                vif->connecting = false;
                dev->ieee80211_ptr->iftype = type;
-               priv->wdev->iftype = type;
+               priv->wdev.iftype = type;
                vif->monitor_flag = 0;
+               if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE)
+                       wilc_wfi_deinit_mon_interface(wl, true);
                vif->iftype = WILC_STATION_MODE;
                wilc_set_operation_mode(vif, WILC_STATION_MODE);
 
@@ -1396,7 +1445,7 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
        case NL80211_IFTYPE_P2P_CLIENT:
                vif->connecting = false;
                dev->ieee80211_ptr->iftype = type;
-               priv->wdev->iftype = type;
+               priv->wdev.iftype = type;
                vif->monitor_flag = 0;
                vif->iftype = WILC_CLIENT_MODE;
                wilc_set_operation_mode(vif, WILC_STATION_MODE);
@@ -1408,12 +1457,12 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
        case NL80211_IFTYPE_AP:
                wl->enable_ps = false;
                dev->ieee80211_ptr->iftype = type;
-               priv->wdev->iftype = type;
+               priv->wdev.iftype = type;
                vif->iftype = WILC_AP_MODE;
 
                if (wl->initialized) {
                        wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif),
-                                                0, vif->ifc_id);
+                                                0, vif->idx);
                        wilc_set_operation_mode(vif, WILC_AP_MODE);
                        wilc_set_power_mgmt(vif, 0, 0);
                }
@@ -1425,7 +1474,7 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
                          jiffies + msecs_to_jiffies(WILC_IP_TIMEOUT_MS));
                wilc_set_operation_mode(vif, WILC_AP_MODE);
                dev->ieee80211_ptr->iftype = type;
-               priv->wdev->iftype = type;
+               priv->wdev.iftype = type;
                vif->iftype = WILC_GO_MODE;
 
                wl->enable_ps = false;
@@ -1444,14 +1493,13 @@ static int start_ap(struct wiphy *wiphy, struct net_device *dev,
                    struct cfg80211_ap_settings *settings)
 {
        struct wilc_vif *vif = netdev_priv(dev);
-       struct wilc *wl = vif->wilc;
        int ret;
 
        ret = set_channel(wiphy, &settings->chandef);
        if (ret != 0)
                netdev_err(dev, "Error in setting channel\n");
 
-       wilc_wlan_set_bssid(dev, wl->vif[vif->idx]->src_addr, WILC_AP_MODE);
+       wilc_wlan_set_bssid(dev, dev->dev_addr, WILC_AP_MODE);
        wilc_set_power_mgmt(vif, 0, 0);
 
        return wilc_add_beacon(vif, settings->beacon_interval,
@@ -1461,8 +1509,7 @@ static int start_ap(struct wiphy *wiphy, struct net_device *dev,
 static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
                         struct cfg80211_beacon_data *beacon)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc_vif *vif = netdev_priv(dev);
 
        return wilc_add_beacon(vif, 0, 0, beacon);
 }
@@ -1470,8 +1517,7 @@ static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
 static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
 {
        int ret;
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc_vif *vif = netdev_priv(dev);
 
        wilc_wlan_set_bssid(dev, NULL, WILC_AP_MODE);
 
@@ -1487,8 +1533,8 @@ static int add_station(struct wiphy *wiphy, struct net_device *dev,
                       const u8 *mac, struct station_parameters *params)
 {
        int ret = 0;
-       struct wilc_priv *priv = wiphy_priv(wiphy);
        struct wilc_vif *vif = netdev_priv(dev);
+       struct wilc_priv *priv = &vif->priv;
 
        if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE) {
                memcpy(priv->assoc_stainfo.sta_associated_bss[params->aid], mac,
@@ -1507,8 +1553,8 @@ static int del_station(struct wiphy *wiphy, struct net_device *dev,
 {
        const u8 *mac = params->mac;
        int ret = 0;
-       struct wilc_priv *priv = wiphy_priv(wiphy);
        struct wilc_vif *vif = netdev_priv(dev);
+       struct wilc_priv *priv = &vif->priv;
        struct sta_info *info;
 
        if (!(vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE))
@@ -1539,60 +1585,157 @@ static int change_station(struct wiphy *wiphy, struct net_device *dev,
        return ret;
 }
 
+static int wilc_get_vif_from_type(struct wilc *wl, int type)
+{
+       int i;
+
+       mutex_lock(&wl->vif_mutex);
+       for (i = 0; i < wl->vif_num; i++) {
+               if (wl->vif[i]->iftype == type) {
+                       mutex_unlock(&wl->vif_mutex);
+                       return i;
+               }
+       }
+       mutex_unlock(&wl->vif_mutex);
+
+       return -EINVAL;
+}
+
 static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
                                             const char *name,
                                             unsigned char name_assign_type,
                                             enum nl80211_iftype type,
                                             struct vif_params *params)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->wdev->netdev);
-       struct net_device *new_ifc;
+       struct wilc *wl = wiphy_priv(wiphy);
+       struct wilc_vif *vif;
+       struct wireless_dev *wdev;
+       int iftype;
+       int ret;
 
        if (type == NL80211_IFTYPE_MONITOR) {
-               new_ifc = wilc_wfi_init_mon_interface(vif->wilc, name,
-                                                     vif->ndev);
-               if (new_ifc) {
-                       vif = netdev_priv(priv->wdev->netdev);
-                       vif->monitor_flag = 1;
+               struct net_device *ndev;
+               int ap_index = wilc_get_vif_from_type(wl, WILC_AP_MODE);
+
+               if (ap_index < 0) {
+                       ap_index = wilc_get_vif_from_type(wl, WILC_GO_MODE);
+                       if (ap_index < 0)
+                               goto validate_interface;
                }
+
+               vif  = wl->vif[ap_index];
+               if (vif->monitor_flag)
+                       goto validate_interface;
+
+               ndev = wilc_wfi_init_mon_interface(wl, name, vif->ndev);
+               if (ndev)
+                       vif->monitor_flag = 1;
+               else
+                       return ERR_PTR(-EINVAL);
+
+               wdev = &vif->priv.wdev;
+               return wdev;
+       }
+
+validate_interface:
+       mutex_lock(&wl->vif_mutex);
+       if (wl->vif_num == WILC_NUM_CONCURRENT_IFC) {
+               pr_err("Reached maximum number of interface\n");
+               ret = -EINVAL;
+               goto out_err;
        }
-       return priv->wdev;
+
+       switch (type) {
+       case NL80211_IFTYPE_STATION:
+               iftype = WILC_STATION_MODE;
+               break;
+       case NL80211_IFTYPE_AP:
+               iftype = WILC_AP_MODE;
+               break;
+       default:
+               ret = -EOPNOTSUPP;
+               goto out_err;
+       }
+
+       vif = wilc_netdev_ifc_init(wl, name, iftype, type, true);
+       if (IS_ERR(vif)) {
+               ret = PTR_ERR(vif);
+               goto out_err;
+       }
+
+       mutex_unlock(&wl->vif_mutex);
+
+       return &vif->priv.wdev;
+
+out_err:
+       mutex_unlock(&wl->vif_mutex);
+       return ERR_PTR(ret);
 }
 
 static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
 {
+       struct wilc *wl = wiphy_priv(wiphy);
+       struct wilc_vif *vif;
+       int i;
+
+       if (wdev->iftype == NL80211_IFTYPE_AP ||
+           wdev->iftype == NL80211_IFTYPE_P2P_GO)
+               wilc_wfi_deinit_mon_interface(wl, true);
+       vif = netdev_priv(wdev->netdev);
+       cfg80211_stop_iface(wiphy, wdev, GFP_KERNEL);
+       unregister_netdevice(vif->ndev);
+       vif->monitor_flag = 0;
+
+       mutex_lock(&wl->vif_mutex);
+       wilc_set_wfi_drv_handler(vif, 0, 0, 0);
+       for (i = vif->idx; i < wl->vif_num ; i++) {
+               if ((i + 1) >= wl->vif_num) {
+                       wl->vif[i] = NULL;
+               } else {
+                       vif = wl->vif[i + 1];
+                       vif->idx = i;
+                       wl->vif[i] = vif;
+                       wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif),
+                                                vif->iftype, vif->idx);
+               }
+       }
+       wl->vif_num--;
+       mutex_unlock(&wl->vif_mutex);
+
        return 0;
 }
 
 static int wilc_suspend(struct wiphy *wiphy, struct cfg80211_wowlan *wow)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc *wl = wiphy_priv(wiphy);
 
-       if (!wow && wilc_wlan_get_num_conn_ifcs(vif->wilc))
-               vif->wilc->suspend_event = true;
+       if (!wow && wilc_wlan_get_num_conn_ifcs(wl))
+               wl->suspend_event = true;
        else
-               vif->wilc->suspend_event = false;
+               wl->suspend_event = false;
 
        return 0;
 }
 
 static int wilc_resume(struct wiphy *wiphy)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
-
-       netdev_info(vif->ndev, "cfg resume\n");
        return 0;
 }
 
 static void wilc_set_wakeup(struct wiphy *wiphy, bool enabled)
 {
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc *wl = wiphy_priv(wiphy);
+       struct wilc_vif *vif;
+
+       mutex_lock(&wl->vif_mutex);
+       vif = wilc_get_wl_to_vif(wl);
+       if (IS_ERR(vif)) {
+               mutex_unlock(&wl->vif_mutex);
+               return;
+       }
 
        netdev_info(vif->ndev, "cfg set wake up = %d\n", enabled);
+       mutex_unlock(&wl->vif_mutex);
 }
 
 static int set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
@@ -1600,8 +1743,7 @@ static int set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
 {
        int ret;
        s32 tx_power = MBM_TO_DBM(mbm);
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc_vif *vif = netdev_priv(wdev->netdev);
 
        if (tx_power < 0)
                tx_power = 0;
@@ -1618,8 +1760,7 @@ static int get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
                        int *dbm)
 {
        int ret;
-       struct wilc_priv *priv = wiphy_priv(wiphy);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc_vif *vif = netdev_priv(wdev->netdev);
        struct wilc *wl = vif->wilc;
 
        /* If firmware is not started, return. */
@@ -1676,98 +1817,137 @@ static const struct cfg80211_ops wilc_cfg80211_ops = {
 
 };
 
-static struct wireless_dev *wilc_wfi_cfg_alloc(void)
+static void wlan_init_locks(struct wilc *wl)
 {
-       struct wireless_dev *wdev;
+       mutex_init(&wl->hif_cs);
+       mutex_init(&wl->rxq_cs);
+       mutex_init(&wl->cfg_cmd_lock);
+       mutex_init(&wl->vif_mutex);
+
+       spin_lock_init(&wl->txq_spinlock);
+       mutex_init(&wl->txq_add_to_head_cs);
+
+       init_completion(&wl->txq_event);
+       init_completion(&wl->cfg_event);
+       init_completion(&wl->sync_event);
+       init_completion(&wl->txq_thread_started);
+}
 
-       wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
-       if (!wdev)
-               goto out;
+int wilc_cfg80211_init(struct wilc **wilc, struct device *dev, int io_type,
+                      const struct wilc_hif_func *ops)
+{
+       struct wilc *wl;
+       struct wilc_vif *vif;
+       int ret;
 
-       wdev->wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(struct wilc_priv));
-       if (!wdev->wiphy)
-               goto free_mem;
+       wl = wilc_create_wiphy(dev);
+       if (!wl)
+               return -EINVAL;
 
-       return wdev;
+       ret = wilc_wlan_cfg_init(wl);
+       if (ret)
+               goto free_wl;
+
+       *wilc = wl;
+       wl->io_type = io_type;
+       wl->hif_func = ops;
+       wl->enable_ps = false;
+       wl->chip_ps_state = WILC_CHIP_WAKEDUP;
+       INIT_LIST_HEAD(&wl->txq_head.list);
+       INIT_LIST_HEAD(&wl->rxq_head.list);
+
+       wl->hif_workqueue = create_singlethread_workqueue("WILC_wq");
+       if (!wl->hif_workqueue) {
+               ret = -ENOMEM;
+               goto free_cfg;
+       }
+       vif = wilc_netdev_ifc_init(wl, "wlan%d", WILC_STATION_MODE,
+                                  NL80211_IFTYPE_STATION, false);
+       if (IS_ERR(vif)) {
+               ret = PTR_ERR(vif);
+               goto free_hq;
+       }
 
-free_mem:
-       kfree(wdev);
-out:
-       return NULL;
+       wlan_init_locks(wl);
+
+       return 0;
+
+free_hq:
+       destroy_workqueue(wl->hif_workqueue);
+
+free_cfg:
+       wilc_wlan_cfg_deinit(wl);
+
+free_wl:
+       wiphy_unregister(wl->wiphy);
+       wiphy_free(wl->wiphy);
+       return ret;
 }
+EXPORT_SYMBOL_GPL(wilc_cfg80211_init);
 
-struct wireless_dev *wilc_create_wiphy(struct net_device *net,
-                                      struct device *dev)
+struct wilc *wilc_create_wiphy(struct device *dev)
 {
-       struct wilc_priv *priv;
-       struct wireless_dev *wdev;
+       struct wiphy *wiphy;
+       struct wilc *wl;
        int ret;
 
-       wdev = wilc_wfi_cfg_alloc();
-       if (!wdev) {
-               netdev_err(net, "wiphy new allocate failed\n");
+       wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(*wl));
+       if (!wiphy)
                return NULL;
-       }
 
-       priv = wdev_priv(wdev);
-       priv->wdev = wdev;
+       wl = wiphy_priv(wiphy);
 
-       memcpy(priv->bitrates, wilc_bitrates, sizeof(wilc_bitrates));
-       memcpy(priv->channels, wilc_2ghz_channels, sizeof(wilc_2ghz_channels));
-       priv->band.bitrates = priv->bitrates;
-       priv->band.n_bitrates = ARRAY_SIZE(priv->bitrates);
-       priv->band.channels = priv->channels;
-       priv->band.n_channels = ARRAY_SIZE(wilc_2ghz_channels);
+       memcpy(wl->bitrates, wilc_bitrates, sizeof(wilc_bitrates));
+       memcpy(wl->channels, wilc_2ghz_channels, sizeof(wilc_2ghz_channels));
+       wl->band.bitrates = wl->bitrates;
+       wl->band.n_bitrates = ARRAY_SIZE(wl->bitrates);
+       wl->band.channels = wl->channels;
+       wl->band.n_channels = ARRAY_SIZE(wilc_2ghz_channels);
 
-       priv->band.ht_cap.ht_supported = 1;
-       priv->band.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
-       priv->band.ht_cap.mcs.rx_mask[0] = 0xff;
-       priv->band.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
-       priv->band.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
+       wl->band.ht_cap.ht_supported = 1;
+       wl->band.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
+       wl->band.ht_cap.mcs.rx_mask[0] = 0xff;
+       wl->band.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
+       wl->band.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
 
-       wdev->wiphy->bands[NL80211_BAND_2GHZ] = &priv->band;
+       wiphy->bands[NL80211_BAND_2GHZ] = &wl->band;
 
-       wdev->wiphy->max_scan_ssids = WILC_MAX_NUM_PROBED_SSID;
+       wiphy->max_scan_ssids = WILC_MAX_NUM_PROBED_SSID;
 #ifdef CONFIG_PM
-       wdev->wiphy->wowlan = &wowlan_support;
+       wiphy->wowlan = &wowlan_support;
 #endif
-       wdev->wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
-       wdev->wiphy->max_scan_ie_len = 1000;
-       wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
-       memcpy(priv->cipher_suites, wilc_cipher_suites,
+       wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
+       wiphy->max_scan_ie_len = 1000;
+       wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
+       memcpy(wl->cipher_suites, wilc_cipher_suites,
               sizeof(wilc_cipher_suites));
-       wdev->wiphy->cipher_suites = priv->cipher_suites;
-       wdev->wiphy->n_cipher_suites = ARRAY_SIZE(wilc_cipher_suites);
-       wdev->wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
-
-       wdev->wiphy->max_remain_on_channel_duration = 500;
-       wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
-                                       BIT(NL80211_IFTYPE_AP) |
-                                       BIT(NL80211_IFTYPE_MONITOR) |
-                                       BIT(NL80211_IFTYPE_P2P_GO) |
-                                       BIT(NL80211_IFTYPE_P2P_CLIENT);
-       wdev->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
-       wdev->iftype = NL80211_IFTYPE_STATION;
-
-       set_wiphy_dev(wdev->wiphy, dev);
-
-       ret = wiphy_register(wdev->wiphy);
+       wiphy->cipher_suites = wl->cipher_suites;
+       wiphy->n_cipher_suites = ARRAY_SIZE(wilc_cipher_suites);
+       wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
+
+       wiphy->max_remain_on_channel_duration = 500;
+       wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
+                               BIT(NL80211_IFTYPE_AP) |
+                               BIT(NL80211_IFTYPE_MONITOR) |
+                               BIT(NL80211_IFTYPE_P2P_GO) |
+                               BIT(NL80211_IFTYPE_P2P_CLIENT);
+       wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
+
+       set_wiphy_dev(wiphy, dev);
+       wl->wiphy = wiphy;
+       ret = wiphy_register(wiphy);
        if (ret) {
-               netdev_err(net, "Cannot register wiphy device\n");
-               wiphy_free(wdev->wiphy);
-               kfree(wdev);
+               wiphy_free(wiphy);
                return NULL;
        }
-
-       priv->dev = net;
-       return wdev;
+       return wl;
 }
 
 int wilc_init_host_int(struct net_device *net)
 {
        int ret;
-       struct wilc_priv *priv = wdev_priv(net->ieee80211_ptr);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc_vif *vif = netdev_priv(net);
+       struct wilc_priv *priv = &vif->priv;
 
        timer_setup(&vif->during_ip_timer, clear_during_ip, 0);
 
@@ -1784,8 +1964,8 @@ int wilc_init_host_int(struct net_device *net)
 void wilc_deinit_host_int(struct net_device *net)
 {
        int ret;
-       struct wilc_priv *priv = wdev_priv(net->ieee80211_ptr);
-       struct wilc_vif *vif = netdev_priv(priv->dev);
+       struct wilc_vif *vif = netdev_priv(net);
+       struct wilc_priv *priv = &vif->priv;
 
        priv->p2p_listen_state = false;
 
@@ -1798,19 +1978,3 @@ void wilc_deinit_host_int(struct net_device *net)
                netdev_err(net, "Error while deinitializing host interface\n");
 }
 
-void wilc_free_wiphy(struct net_device *net)
-{
-       if (!net)
-               return;
-
-       if (!net->ieee80211_ptr)
-               return;
-
-       if (!net->ieee80211_ptr->wiphy)
-               return;
-
-       wiphy_unregister(net->ieee80211_ptr->wiphy);
-
-       wiphy_free(net->ieee80211_ptr->wiphy);
-       kfree(net->ieee80211_ptr);
-}
index 31dfa1f141f11b53b3b5b9828eb6bff5ff15b276..234faaabdb8208be823dd0fe80f66daa7e1e2cab 100644 (file)
@@ -8,17 +8,20 @@
 #define NM_WFI_CFGOPERATIONS
 #include "wilc_wfi_netdevice.h"
 
-struct wireless_dev *wilc_create_wiphy(struct net_device *net,
-                                      struct device *dev);
-void wilc_free_wiphy(struct net_device *net);
+struct wiphy *wilc_cfg_alloc(void);
+int wilc_cfg80211_init(struct wilc **wilc, struct device *dev, int io_type,
+                      const struct wilc_hif_func *ops);
+struct wilc *wilc_create_wiphy(struct device *dev);
 void wilc_deinit_host_int(struct net_device *net);
 int wilc_init_host_int(struct net_device *net);
 void wilc_wfi_monitor_rx(struct net_device *mon_dev, u8 *buff, u32 size);
-void wilc_wfi_deinit_mon_interface(struct wilc *wl);
+struct wilc_vif *wilc_netdev_interface(struct wilc *wl, const char *name,
+                                      enum nl80211_iftype type);
+void wilc_wfi_deinit_mon_interface(struct wilc *wl, bool rtnl_locked);
 struct net_device *wilc_wfi_init_mon_interface(struct wilc *wl,
                                               const char *name,
                                               struct net_device *real_dev);
 void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
                              u16 frame_type, bool reg);
-
+struct wilc_vif *wilc_get_interface(struct wilc *wl);
 #endif
index df00762487c057e47bc43f8b85198e447a2461ae..1e74a08e7cf1fd2d2d77b11bf99d10661467bdcd 100644 (file)
@@ -14,7 +14,7 @@
 #include <linux/if_arp.h>
 #include <linux/gpio/consumer.h>
 
-#include "host_interface.h"
+#include "wilc_hif.h"
 #include "wilc_wlan.h"
 #include "wilc_wlan_cfg.h"
 
@@ -129,7 +129,7 @@ static struct ieee80211_rate wilc_bitrates[] = {
 };
 
 struct wilc_priv {
-       struct wireless_dev *wdev;
+       struct wireless_dev wdev;
        struct cfg80211_scan_request *scan_req;
 
        struct wilc_wfi_p2p_listen_params remain_on_ch_params;
@@ -156,10 +156,6 @@ struct wilc_priv {
        int scanned_cnt;
        struct wilc_p2p_var p2p;
 
-       struct ieee80211_channel channels[ARRAY_SIZE(wilc_2ghz_channels)];
-       struct ieee80211_rate bitrates[ARRAY_SIZE(wilc_bitrates)];
-       struct ieee80211_supported_band band;
-       u32 cipher_suites[ARRAY_SIZE(wilc_cipher_suites)];
        u64 inc_roc_cookie;
 };
 
@@ -202,21 +198,21 @@ struct wilc_vif {
        struct frame_reg frame_reg[NUM_REG_FRAME];
        struct net_device_stats netstats;
        struct wilc *wilc;
-       u8 src_addr[ETH_ALEN];
        u8 bssid[ETH_ALEN];
        struct host_if_drv *hif_drv;
        struct net_device *ndev;
        u8 mode;
-       u8 ifc_id;
        struct timer_list during_ip_timer;
        bool obtaining_ip;
        struct timer_list periodic_rssi;
        struct rf_info periodic_stat;
        struct tcp_ack_filter ack_filter;
        bool connecting;
+       struct wilc_priv priv;
 };
 
 struct wilc {
+       struct wiphy *wiphy;
        const struct wilc_hif_func *hif_func;
        int io_type;
        s8 mac_status;
@@ -226,6 +222,8 @@ struct wilc {
        int close;
        u8 vif_num;
        struct wilc_vif *vif[WILC_NUM_CONCURRENT_IFC];
+       /*protect vif list*/
+       struct mutex vif_mutex;
        u8 open_ifcs;
        /*protect head of transmit queue*/
        struct mutex txq_add_to_head_cs;
@@ -275,6 +273,10 @@ struct wilc {
        struct mutex deinit_lock;
        u8 sta_ch;
        u8 op_ch;
+       struct ieee80211_channel channels[ARRAY_SIZE(wilc_2ghz_channels)];
+       struct ieee80211_rate bitrates[ARRAY_SIZE(wilc_bitrates)];
+       struct ieee80211_supported_band band;
+       u32 cipher_suites[ARRAY_SIZE(wilc_cipher_suites)];
 };
 
 struct wilc_wfi_mon_priv {
@@ -284,9 +286,9 @@ struct wilc_wfi_mon_priv {
 void wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset);
 void wilc_mac_indicate(struct wilc *wilc);
 void wilc_netdev_cleanup(struct wilc *wilc);
-int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
-                    const struct wilc_hif_func *ops);
 void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size);
 void wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode);
-
+struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
+                                     int vif_type, enum nl80211_iftype type,
+                                     bool rtnl_locked);
 #endif
index 95eaf8fdf4f23b17778abcd2a2d8c1ca291986ef..d46876edcfeb2a8c83e4017b98fa1c8a9f3a3c3a 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <linux/if_ether.h>
 #include <linux/ip.h>
-#include "wilc_wfi_netdevice.h"
+#include "wilc_wfi_cfgoperations.h"
 #include "wilc_wlan_cfg.h"
 
 static inline bool is_wilc1000(u32 id)
@@ -267,6 +267,7 @@ static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, u8 *buffer,
        tqe->tx_complete_func = NULL;
        tqe->priv = NULL;
        tqe->ack_idx = NOT_TCP_ACK;
+       tqe->vif = vif;
 
        wilc_wlan_txq_add_to_head(vif, tqe);
 
@@ -295,6 +296,7 @@ int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
        tqe->buffer_size = buffer_size;
        tqe->tx_complete_func = tx_complete_fn;
        tqe->priv = priv;
+       tqe->vif = vif;
 
        tqe->ack_idx = NOT_TCP_ACK;
        if (vif->ack_filter.enabled)
@@ -326,6 +328,7 @@ int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
        tqe->tx_complete_func = tx_complete_fn;
        tqe->priv = priv;
        tqe->ack_idx = NOT_TCP_ACK;
+       tqe->vif = vif;
        wilc_wlan_txq_add_to_tail(dev, tqe);
        return 1;
 }
@@ -482,7 +485,7 @@ void host_sleep_notify(struct wilc *wilc)
 }
 EXPORT_SYMBOL_GPL(host_sleep_notify);
 
-int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count)
+int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count)
 {
        int i, entries = 0;
        u32 sum;
@@ -494,17 +497,20 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count)
        int counter;
        int timeout;
        u32 vmm_table[WILC_VMM_TBL_SIZE];
-       struct wilc_vif *vif = netdev_priv(dev);
-       struct wilc *wilc = vif->wilc;
        const struct wilc_hif_func *func;
        u8 *txb = wilc->tx_buffer;
+       struct net_device *dev;
+       struct wilc_vif *vif;
 
        if (wilc->quit)
                goto out;
 
        mutex_lock(&wilc->txq_add_to_head_cs);
-       wilc_wlan_txq_filter_dup_tcp_ack(dev);
        tqe = wilc_wlan_txq_get_first(wilc);
+       if (!tqe)
+               goto out;
+       dev = tqe->vif->ndev;
+       wilc_wlan_txq_filter_dup_tcp_ack(dev);
        i = 0;
        sum = 0;
        do {
@@ -629,6 +635,7 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count)
                if (!tqe)
                        break;
 
+               vif = tqe->vif;
                if (vmm_table[i] == 0)
                        break;
 
@@ -648,8 +655,7 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count)
                if (tqe->type == WILC_CFG_PKT) {
                        buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
                } else if (tqe->type == WILC_NET_PKT) {
-                       bssid = ((struct tx_complete_data *)(tqe->priv))->bssid;
-
+                       bssid = tqe->vif->bssid;
                        buffer_offset = ETH_ETHERNET_HDR_OFFSET;
                        memcpy(&txb[offset + 8], bssid, 6);
                } else {
@@ -709,9 +715,6 @@ static void wilc_wlan_handle_rx_buff(struct wilc *wilc, u8 *buffer, int size)
                        break;
 
                if (pkt_offset & IS_MANAGMEMENT) {
-                       pkt_offset &= ~(IS_MANAGMEMENT |
-                                       IS_MANAGMEMENT_CALLBACK |
-                                       IS_MGMT_STATUS_SUCCES);
                        buff_ptr += HOST_HDR_OFFSET;
                        wilc_wfi_mgmt_rx(wilc, buff_ptr, pkt_len);
                } else {
@@ -1199,10 +1202,11 @@ int wilc_wlan_cfg_get_val(struct wilc *wl, u16 wid, u8 *buffer, u32 buffer_size)
 }
 
 int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
-                        u32 count, u32 drv)
+                        u32 count)
 {
        int i;
        int ret = 0;
+       u32 drv = wilc_get_vif_idx(vif);
 
        if (mode == WILC_GET_CFG) {
                for (i = 0; i < count; i++) {
index 1a27f62589a282f6ff7ff1c624349c99821a3f0a..d2eef7b4c3b7c32af0508cd4b23f7eb724490045 100644 (file)
@@ -216,6 +216,7 @@ struct txq_entry_t {
        int buffer_size;
        void *priv;
        int status;
+       struct wilc_vif *vif;
        void (*tx_complete_func)(void *priv, int status);
 };
 
@@ -253,7 +254,6 @@ struct wilc_hif_func {
 struct tx_complete_data {
        int size;
        void *buff;
-       u8 *bssid;
        struct sk_buff *skb;
 };
 
@@ -284,7 +284,7 @@ int wilc_wlan_stop(struct wilc *wilc);
 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
                              u32 buffer_size,
                              void (*tx_complete_fn)(void *, int));
-int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count);
+int wilc_wlan_handle_txq(struct wilc *wl, u32 *txq_count);
 void wilc_handle_isr(struct wilc *wilc);
 void wilc_wlan_cleanup(struct net_device *dev);
 int wilc_wlan_cfg_set(struct wilc_vif *vif, int start, u16 wid, u8 *buffer,
@@ -301,13 +301,13 @@ void wilc_enable_tcp_ack_filter(struct wilc_vif *vif, bool value);
 int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc);
 netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *dev);
 
-void wilc_wfi_p2p_rx(struct net_device *dev, u8 *buff, u32 size);
+void wilc_wfi_p2p_rx(struct wilc_vif *vif, u8 *buff, u32 size);
 void host_wakeup_notify(struct wilc *wilc);
 void host_sleep_notify(struct wilc *wilc);
 void chip_allow_sleep(struct wilc *wilc);
 void chip_wakeup(struct wilc *wilc);
 int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
-                        u32 count, u32 drv);
+                        u32 count);
 int wilc_wlan_init(struct net_device *dev);
 u32 wilc_get_chipid(struct wilc *wilc, bool update);
 #endif
index b15de36e32e04e410c6138ef7ec4eb11d9d8c40c..b89d0e0f04cc2d4ef6de8dcec8794c2a159056b3 100644 (file)
@@ -684,7 +684,7 @@ enum {
        WID_LONG_RETRY_LIMIT            = 0x1003,
        WID_BEACON_INTERVAL             = 0x1006,
        WID_MEMORY_ACCESS_16BIT         = 0x1008,
-
+       WID_PASSIVE_SCAN_TIME           = 0x100D,
        WID_JOIN_START_TIMEOUT          = 0x100F,
        WID_ASOC_TIMEOUT                = 0x1011,
        WID_11I_PROTOCOL_TIMEOUT        = 0x1012,
index 8a862f718d5c0e36055b3b481bbf75112cc07c43..eee1998c4b189179b6de81f2fa98717bb5395176 100644 (file)
@@ -231,17 +231,9 @@ static int prism2_set_default_key(struct wiphy *wiphy, struct net_device *dev,
 {
        struct wlandevice *wlandev = dev->ml_priv;
 
-       int err = 0;
-       int result = 0;
-
-       result = prism2_domibset_uint32(wlandev,
-               DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID,
-               key_index);
-
-       if (result)
-               err = -EFAULT;
-
-       return err;
+       return  prism2_domibset_uint32(wlandev,
+                                      DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID,
+                                      key_index);
 }
 
 static int prism2_get_station(struct wiphy *wiphy, struct net_device *dev,
index a22b6e8fad46eecb68f2a61455895f0279a5efab..7399eb7f13786f9d2e45d4fb9eef5e6123285ca4 100644 (file)
@@ -156,9 +156,9 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
                        *be = (endianchar == 'b');
                        *bytes = padint / 8;
                        if (*bits_used == 64)
-                               *mask = ~0;
+                               *mask = ~(0ULL);
                        else
-                               *mask = (1ULL << *bits_used) - 1;
+                               *mask = (1ULL << *bits_used) - 1ULL;
 
                        *is_signed = (signchar == 's');
                        if (fclose(sysfsfp)) {