summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-09-18 14:05:34 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-09-18 14:05:34 -0400
commite6874fc29410fabfdbc8c12b467f41a16cbcfd2b (patch)
treebb869a9b481a6c05bf334a0a4db0b1397ce4ca90
parente444d51b14c4795074f485c79debd234931f0e49 (diff)
parent3fb73eddba106ad2a265a5c5c29d14b0ed6aaee1 (diff)
Merge tag 'staging-5.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging and IIO driver updates from Greg KH: "Here is the big staging/iio driver update for 5.4-rc1. Lots of churn here, with a few driver/filesystems moving out of staging finally: - erofs moved out of staging - greybus core code moved out of staging Along with that, a new filesytem has been added: - extfat to provide support for those devices requiring that filesystem (i.e. transfer devices to/from windows systems or printers) Other than that, there a number of new IIO drivers, and lots and lots and lots of staging driver cleanups and minor fixes as people continue to dig into those for easy changes. All of these have been in linux-next for a while with no reported issues" * tag 'staging-5.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (453 commits) Staging: gasket: Use temporaries to reduce line length. Staging: octeon: Avoid several usecases of strcpy staging: vhciq_core: replace snprintf with scnprintf staging: wilc1000: avoid twice IRQ handler execution for each single interrupt staging: wilc1000: remove unused interrupt status handling code staging: fbtft: make several arrays static const, makes object smaller staging: rtl8188eu: make two arrays static const, makes object smaller staging: rtl8723bs: core: Remove Macro "IS_MAC_ADDRESS_BROADCAST" dt-bindings: anybus-controller: move to staging/ tree staging: emxx_udc: remove local TRUE/FALSE definition staging: wilc1000: look for rtc_clk clock staging: dt-bindings: wilc1000: add optional rtc_clk property staging: nvec: make use of devm_platform_ioremap_resource staging: exfat: drop unused function parameter Staging: exfat: Avoid use of strcpy staging: exfat: use integer constants staging: exfat: cleanup spacing for casts staging: exfat: cleanup spacing for operators staging: rtl8723bs: hal: remove redundant variable n staging: pi433: Fix typo in documentation ...
-rw-r--r--Documentation/ABI/testing/sysfs-bus-iio-dfsdm-adc-stm322
-rw-r--r--Documentation/ABI/testing/sysfs-bus-iio-timer-stm3223
-rw-r--r--Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml121
-rw-r--r--Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt66
-rw-r--r--Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml138
-rw-r--r--Documentation/devicetree/bindings/iio/adc/st,stm32-adc.txt6
-rw-r--r--Documentation/devicetree/bindings/iio/chemical/plantower,pms7003.txt26
-rw-r--r--Documentation/devicetree/bindings/iio/chemical/plantower,pms7003.yaml51
-rw-r--r--Documentation/devicetree/bindings/iio/imu/adi,adis16460.yaml53
-rw-r--r--Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt3
-rw-r--r--Documentation/devicetree/bindings/iio/light/noa1305.yaml44
-rw-r--r--Documentation/devicetree/bindings/iio/light/renesas,isl29501.txt (renamed from Documentation/devicetree/bindings/iio/light/isl29501.txt)0
-rw-r--r--Documentation/devicetree/bindings/iio/light/stk33xx.yaml49
-rw-r--r--Documentation/devicetree/bindings/iio/mount-matrix.txt203
-rw-r--r--Documentation/devicetree/bindings/iio/potentiometer/max5432.yaml44
-rw-r--r--Documentation/devicetree/bindings/vendor-prefixes.yaml2
-rw-r--r--Documentation/filesystems/erofs.txt (renamed from drivers/staging/erofs/Documentation/filesystems/erofs.txt)19
-rw-r--r--MAINTAINERS39
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/Makefile1
-rw-r--r--drivers/counter/ftm-quaddec.c30
-rw-r--r--drivers/greybus/Kconfig32
-rw-r--r--drivers/greybus/Makefile26
-rw-r--r--drivers/greybus/arpc.h63
-rw-r--r--drivers/greybus/bundle.c (renamed from drivers/staging/greybus/bundle.c)2
-rw-r--r--drivers/greybus/connection.c (renamed from drivers/staging/greybus/connection.c)2
-rw-r--r--drivers/greybus/control.c (renamed from drivers/staging/greybus/control.c)2
-rw-r--r--drivers/greybus/core.c (renamed from drivers/staging/greybus/core.c)2
-rw-r--r--drivers/greybus/debugfs.c (renamed from drivers/staging/greybus/debugfs.c)3
-rw-r--r--drivers/greybus/es2.c (renamed from drivers/staging/greybus/es2.c)3
-rw-r--r--drivers/greybus/greybus_trace.h (renamed from drivers/staging/greybus/greybus_trace.h)2
-rw-r--r--drivers/greybus/hd.c (renamed from drivers/staging/greybus/hd.c)12
-rw-r--r--drivers/greybus/interface.c (renamed from drivers/staging/greybus/interface.c)2
-rw-r--r--drivers/greybus/manifest.c (renamed from drivers/staging/greybus/manifest.c)41
-rw-r--r--drivers/greybus/module.c (renamed from drivers/staging/greybus/module.c)2
-rw-r--r--drivers/greybus/operation.c (renamed from drivers/staging/greybus/operation.c)2
-rw-r--r--drivers/greybus/svc.c (renamed from drivers/staging/greybus/svc.c)3
-rw-r--r--drivers/greybus/svc_watchdog.c (renamed from drivers/staging/greybus/svc_watchdog.c)2
-rw-r--r--drivers/iio/accel/Kconfig4
-rw-r--r--drivers/iio/accel/cros_ec_accel_legacy.c352
-rw-r--r--drivers/iio/accel/kxcjk-1013.c4
-rw-r--r--drivers/iio/accel/mxc4005.c40
-rw-r--r--drivers/iio/accel/sca3000.c2
-rw-r--r--drivers/iio/accel/st_accel.h1
-rw-r--r--drivers/iio/accel/st_accel_buffer.c44
-rw-r--r--drivers/iio/accel/st_accel_core.c32
-rw-r--r--drivers/iio/accel/st_accel_i2c.c23
-rw-r--r--drivers/iio/accel/st_accel_spi.c20
-rw-r--r--drivers/iio/adc/ad7606.c100
-rw-r--r--drivers/iio/adc/ad7606.h61
-rw-r--r--drivers/iio/adc/ad7606_par.c4
-rw-r--r--drivers/iio/adc/ad7606_spi.c282
-rw-r--r--drivers/iio/adc/at91_adc.c4
-rw-r--r--drivers/iio/adc/axp288_adc.c4
-rw-r--r--drivers/iio/adc/bcm_iproc_adc.c7
-rw-r--r--drivers/iio/adc/da9150-gpadc.c4
-rw-r--r--drivers/iio/adc/envelope-detector.c5
-rw-r--r--drivers/iio/adc/exynos_adc.c4
-rw-r--r--drivers/iio/adc/fsl-imx25-gcq.c1
-rw-r--r--drivers/iio/adc/hi8435.c34
-rw-r--r--drivers/iio/adc/imx7d_adc.c4
-rw-r--r--drivers/iio/adc/lpc32xx_adc.c4
-rw-r--r--drivers/iio/adc/max1027.c38
-rw-r--r--drivers/iio/adc/npcm_adc.c1
-rw-r--r--drivers/iio/adc/rockchip_saradc.c4
-rw-r--r--drivers/iio/adc/sc27xx_adc.c122
-rw-r--r--drivers/iio/adc/spear_adc.c1
-rw-r--r--drivers/iio/adc/stm32-adc-core.c194
-rw-r--r--drivers/iio/adc/stm32-adc.c4
-rw-r--r--drivers/iio/adc/stm32-dfsdm-adc.c5
-rw-r--r--drivers/iio/adc/sun4i-gpadc-iio.c4
-rw-r--r--drivers/iio/adc/twl6030-gpadc.c4
-rw-r--r--drivers/iio/adc/vf610_adc.c4
-rw-r--r--drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c54
-rw-r--r--drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c153
-rw-r--r--drivers/iio/common/hid-sensors/hid-sensor-attributes.c69
-rw-r--r--drivers/iio/common/st_sensors/Kconfig2
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_buffer.c10
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_core.c118
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_i2c.c82
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_spi.c148
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_trigger.c31
-rw-r--r--drivers/iio/dac/ad5380.c2
-rw-r--r--drivers/iio/gyro/st_gyro.h1
-rw-r--r--drivers/iio/gyro/st_gyro_buffer.c48
-rw-r--r--drivers/iio/gyro/st_gyro_core.c32
-rw-r--r--drivers/iio/gyro/st_gyro_i2c.c22
-rw-r--r--drivers/iio/gyro/st_gyro_spi.c20
-rw-r--r--drivers/iio/humidity/am2315.c24
-rw-r--r--drivers/iio/humidity/hdc100x.c19
-rw-r--r--drivers/iio/imu/Kconfig12
-rw-r--r--drivers/iio/imu/Makefile1
-rw-r--r--drivers/iio/imu/adis.c12
-rw-r--r--drivers/iio/imu/adis16460.c489
-rw-r--r--drivers/iio/imu/inv_mpu6050/Kconfig10
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_core.c3
-rw-r--r--drivers/iio/imu/st_lsm6dsx/Kconfig11
-rw-r--r--drivers/iio/imu/st_lsm6dsx/Makefile1
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h29
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c36
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c622
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c15
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c57
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c15
-rw-r--r--drivers/iio/light/Kconfig11
-rw-r--r--drivers/iio/light/Makefile1
-rw-r--r--drivers/iio/light/apds9960.c2
-rw-r--r--drivers/iio/light/cm3323.c33
-rw-r--r--drivers/iio/light/cm36651.c12
-rw-r--r--drivers/iio/light/cros_ec_light_prox.c51
-rw-r--r--drivers/iio/light/noa1305.c313
-rw-r--r--drivers/iio/light/si1145.c42
-rw-r--r--drivers/iio/light/stk3310.c9
-rw-r--r--drivers/iio/light/tsl2772.c124
-rw-r--r--drivers/iio/light/veml6070.c6
-rw-r--r--drivers/iio/magnetometer/mmc35240.c4
-rw-r--r--drivers/iio/magnetometer/st_magn.h1
-rw-r--r--drivers/iio/magnetometer/st_magn_buffer.c31
-rw-r--r--drivers/iio/magnetometer/st_magn_core.c32
-rw-r--r--drivers/iio/magnetometer/st_magn_i2c.c22
-rw-r--r--drivers/iio/magnetometer/st_magn_spi.c20
-rw-r--r--drivers/iio/potentiometer/Kconfig11
-rw-r--r--drivers/iio/potentiometer/Makefile1
-rw-r--r--drivers/iio/potentiometer/max5432.c135
-rw-r--r--drivers/iio/pressure/cros_ec_baro.c19
-rw-r--r--drivers/iio/pressure/hp03.c6
-rw-r--r--drivers/iio/pressure/st_pressure.h1
-rw-r--r--drivers/iio/pressure/st_pressure_buffer.c39
-rw-r--r--drivers/iio/pressure/st_pressure_core.c32
-rw-r--r--drivers/iio/pressure/st_pressure_i2c.c31
-rw-r--r--drivers/iio/pressure/st_pressure_spi.c22
-rw-r--r--drivers/iio/proximity/Kconfig2
-rw-r--r--drivers/iio/temperature/maxim_thermocouple.c25
-rw-r--r--drivers/iio/trigger/stm32-timer-trigger.c84
-rw-r--r--drivers/staging/Kconfig4
-rw-r--r--drivers/staging/Makefile2
-rw-r--r--drivers/staging/android/TODO2
-rw-r--r--drivers/staging/android/ion/ion.c36
-rw-r--r--drivers/staging/android/ion/ion.h10
-rw-r--r--drivers/staging/comedi/drivers/daqboard2000.c7
-rw-r--r--drivers/staging/comedi/drivers/ni_mio_common.c2
-rw-r--r--drivers/staging/comedi/drivers/usbduxsigma.c2
-rw-r--r--drivers/staging/emxx_udc/emxx_udc.c80
-rw-r--r--drivers/staging/emxx_udc/emxx_udc.h5
-rw-r--r--drivers/staging/erofs/Kconfig151
-rw-r--r--drivers/staging/erofs/Makefile13
-rw-r--r--drivers/staging/erofs/TODO46
-rw-r--r--drivers/staging/erofs/inode.c332
-rw-r--r--drivers/staging/erofs/super.c701
-rw-r--r--drivers/staging/erofs/unzip_vle.c1591
-rw-r--r--drivers/staging/exfat/Kconfig49
-rw-r--r--drivers/staging/exfat/Makefile10
-rw-r--r--drivers/staging/exfat/TODO12
-rw-r--r--drivers/staging/exfat/exfat.h971
-rw-r--r--drivers/staging/exfat/exfat_blkdev.c136
-rw-r--r--drivers/staging/exfat/exfat_cache.c724
-rw-r--r--drivers/staging/exfat/exfat_core.c3701
-rw-r--r--drivers/staging/exfat/exfat_nls.c404
-rw-r--r--drivers/staging/exfat/exfat_super.c4049
-rw-r--r--drivers/staging/exfat/exfat_upcase.c740
-rw-r--r--drivers/staging/fbtft/fb_hx8340bn.c2
-rw-r--r--drivers/staging/fbtft/fb_hx8347d.c2
-rw-r--r--drivers/staging/fbtft/fb_ili9163.c2
-rw-r--r--drivers/staging/fbtft/fb_ili9320.c2
-rw-r--r--drivers/staging/fbtft/fb_ili9325.c2
-rw-r--r--drivers/staging/fbtft/fb_pcd8544.c4
-rw-r--r--drivers/staging/fbtft/fb_s6d1121.c2
-rw-r--r--drivers/staging/fbtft/fb_ssd1289.c2
-rw-r--r--drivers/staging/fieldbus/Documentation/devicetree/bindings/fieldbus/arcx,anybus-controller.txt (renamed from Documentation/devicetree/bindings/fieldbus/arcx,anybus-controller.txt)0
-rw-r--r--drivers/staging/fsl-dpaa2/ethsw/TODO1
-rw-r--r--drivers/staging/fsl-dpaa2/ethsw/dpsw-cmd.h15
-rw-r--r--drivers/staging/fsl-dpaa2/ethsw/dpsw.c51
-rw-r--r--drivers/staging/fsl-dpaa2/ethsw/dpsw.h56
-rw-r--r--drivers/staging/fsl-dpaa2/ethsw/ethsw-ethtool.c44
-rw-r--r--drivers/staging/fsl-dpaa2/ethsw/ethsw.c309
-rw-r--r--drivers/staging/fsl-dpaa2/ethsw/ethsw.h4
-rw-r--r--drivers/staging/gasket/apex_driver.c22
-rw-r--r--drivers/staging/gasket/gasket_ioctl.c12
-rw-r--r--drivers/staging/goldfish/goldfish_audio.c4
-rw-r--r--drivers/staging/greybus/Documentation/firmware/authenticate.c46
-rw-r--r--drivers/staging/greybus/Documentation/firmware/firmware.c46
-rw-r--r--drivers/staging/greybus/Kconfig27
-rw-r--r--drivers/staging/greybus/Makefile22
-rw-r--r--drivers/staging/greybus/arche-platform.c2
-rw-r--r--drivers/staging/greybus/arpc.h109
-rw-r--r--drivers/staging/greybus/audio_apbridgea.c3
-rw-r--r--drivers/staging/greybus/audio_apbridgea.h26
-rw-r--r--drivers/staging/greybus/audio_codec.h4
-rw-r--r--drivers/staging/greybus/audio_gb.c4
-rw-r--r--drivers/staging/greybus/audio_manager.c2
-rw-r--r--drivers/staging/greybus/authentication.c3
-rw-r--r--drivers/staging/greybus/bootrom.c2
-rw-r--r--drivers/staging/greybus/camera.c2
-rw-r--r--drivers/staging/greybus/firmware.h4
-rw-r--r--drivers/staging/greybus/fw-core.c2
-rw-r--r--drivers/staging/greybus/fw-download.c2
-rw-r--r--drivers/staging/greybus/fw-management.c2
-rw-r--r--drivers/staging/greybus/gb-camera.h2
-rw-r--r--drivers/staging/greybus/gbphy.c2
-rw-r--r--drivers/staging/greybus/gbphy.h2
-rw-r--r--drivers/staging/greybus/gpio.c2
-rw-r--r--drivers/staging/greybus/greybus_authentication.h48
-rw-r--r--drivers/staging/greybus/greybus_firmware.h48
-rw-r--r--drivers/staging/greybus/hid.c3
-rw-r--r--drivers/staging/greybus/i2c.c24
-rw-r--r--drivers/staging/greybus/light.c16
-rw-r--r--drivers/staging/greybus/log.c9
-rw-r--r--drivers/staging/greybus/loopback.c9
-rw-r--r--drivers/staging/greybus/power_supply.c3
-rw-r--r--drivers/staging/greybus/pwm.c2
-rw-r--r--drivers/staging/greybus/raw.c3
-rw-r--r--drivers/staging/greybus/sdio.c2
-rw-r--r--drivers/staging/greybus/spi.c2
-rw-r--r--drivers/staging/greybus/spilib.c2
-rw-r--r--drivers/staging/greybus/spilib.h2
-rw-r--r--drivers/staging/greybus/tools/loopback_test.c2
-rw-r--r--drivers/staging/greybus/uart.c2
-rw-r--r--drivers/staging/greybus/usb.c2
-rw-r--r--drivers/staging/greybus/vibrator.c3
-rw-r--r--drivers/staging/iio/accel/adis16240.c5
-rw-r--r--drivers/staging/iio/adc/ad7192.c175
-rw-r--r--drivers/staging/iio/adc/ad7192.h37
-rw-r--r--drivers/staging/iio/resolver/ad2s1210.c12
-rw-r--r--drivers/staging/isdn/hysdn/hysdn_net.c2
-rw-r--r--drivers/staging/isdn/hysdn/hysdn_procconf.c2
-rw-r--r--drivers/staging/kpc2000/kpc2000/cell_probe.c18
-rw-r--r--drivers/staging/kpc2000/kpc2000/core.c18
-rw-r--r--drivers/staging/kpc2000/kpc2000_i2c.c4
-rw-r--r--drivers/staging/kpc2000/kpc2000_spi.c3
-rw-r--r--drivers/staging/kpc2000/kpc_dma/fileops.c8
-rw-r--r--drivers/staging/media/allegro-dvt/allegro-core.c4
-rw-r--r--drivers/staging/media/hantro/hantro_drv.c4
-rw-r--r--drivers/staging/media/imx/imx7-media-csi.c4
-rw-r--r--drivers/staging/media/imx/imx7-mipi-csis.c4
-rw-r--r--drivers/staging/media/meson/vdec/esparser.c4
-rw-r--r--drivers/staging/media/omap4iss/iss.c1
-rw-r--r--drivers/staging/media/sunxi/cedrus/cedrus_hw.c5
-rw-r--r--drivers/staging/most/cdev/cdev.c4
-rw-r--r--drivers/staging/most/core.c4
-rw-r--r--drivers/staging/most/dim2/dim2.c21
-rw-r--r--drivers/staging/most/dim2/hal.c99
-rw-r--r--drivers/staging/most/dim2/hal.h4
-rw-r--r--drivers/staging/most/net/net.c3
-rw-r--r--drivers/staging/most/sound/sound.c5
-rw-r--r--drivers/staging/most/video/video.c3
-rw-r--r--drivers/staging/mt7621-dma/mtk-hsdma.c4
-rw-r--r--drivers/staging/mt7621-pci/pci-mt7621.c12
-rw-r--r--drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c5
-rw-r--r--drivers/staging/nvec/nvec.c8
-rw-r--r--drivers/staging/octeon/ethernet.c16
-rw-r--r--drivers/staging/olpc_dcon/TODO4
-rw-r--r--drivers/staging/pi433/Documentation/pi433.txt2
-rw-r--r--drivers/staging/ralink-gdma/ralink-gdma.c4
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_cmd.c2
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_efuse.c141
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_ieee80211.c4
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_mlme.c11
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_mlme_ext.c2
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_recv.c14
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_security.c41
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_wlan_util.c19
-rw-r--r--drivers/staging/rtl8188eu/hal/bb_cfg.c2
-rw-r--r--drivers/staging/rtl8188eu/hal/rf_cfg.c14
-rw-r--r--drivers/staging/rtl8188eu/hal/usb_halinit.c143
-rw-r--r--drivers/staging/rtl8188eu/include/hal8188e_phy_reg.h881
-rw-r--r--drivers/staging/rtl8188eu/include/hal_intf.h2
-rw-r--r--drivers/staging/rtl8188eu/include/mlme_osdep.h1
-rw-r--r--drivers/staging/rtl8188eu/include/osdep_service.h2
-rw-r--r--drivers/staging/rtl8188eu/include/rtw_mlme.h2
-rw-r--r--drivers/staging/rtl8188eu/include/rtw_mlme_ext.h1
-rw-r--r--drivers/staging/rtl8188eu/os_dep/mlme_linux.c5
-rw-r--r--drivers/staging/rtl8188eu/os_dep/osdep_service.c5
-rw-r--r--drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c3
-rw-r--r--drivers/staging/rtl8192e/Kconfig1
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_dm.c12
-rw-r--r--drivers/staging/rtl8192e/rtllib.h5
-rw-r--r--drivers/staging/rtl8192e/rtllib_crypt_ccmp.c206
-rw-r--r--drivers/staging/rtl8192e/rtllib_rx.c2
-rw-r--r--drivers/staging/rtl8192e/rtllib_softmac.c24
-rw-r--r--drivers/staging/rtl8192u/Kconfig2
-rw-r--r--drivers/staging/rtl8192u/ieee80211/dot11d.c10
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211.h42
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.c2
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c204
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c22
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c4
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c635
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c1
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c14
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c142
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c43
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c12
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h17
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c4
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c18
-rw-r--r--drivers/staging/rtl8192u/r8180_93cx6.c11
-rw-r--r--drivers/staging/rtl8192u/r8190_rtl8256.c42
-rw-r--r--drivers/staging/rtl8192u/r8192U_core.c112
-rw-r--r--drivers/staging/rtl8192u/r8192U_dm.c2
-rw-r--r--drivers/staging/rtl8192u/r819xU_firmware.c2
-rw-r--r--drivers/staging/rtl8192u/r819xU_phy.c59
-rw-r--r--drivers/staging/rtl8712/os_intfs.c35
-rw-r--r--drivers/staging/rtl8712/recv_linux.c18
-rw-r--r--drivers/staging/rtl8712/recv_osdep.h16
-rw-r--r--drivers/staging/rtl8712/rtl8712_cmd.c14
-rw-r--r--drivers/staging/rtl8712/rtl8712_recv.c54
-rw-r--r--drivers/staging/rtl8712/rtl8712_recv.h2
-rw-r--r--drivers/staging/rtl8712/rtl8712_xmit.c46
-rw-r--r--drivers/staging/rtl8712/rtl8712_xmit.h8
-rw-r--r--drivers/staging/rtl8712/rtl871x_io.h7
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_linux.c5
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_set.c16
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_set.h4
-rw-r--r--drivers/staging/rtl8712/rtl871x_mlme.c34
-rw-r--r--drivers/staging/rtl8712/rtl871x_mlme.h8
-rw-r--r--drivers/staging/rtl8712/rtl871x_mp.c9
-rw-r--r--drivers/staging/rtl8712/rtl871x_pwrctrl.c10
-rw-r--r--drivers/staging/rtl8712/rtl871x_pwrctrl.h2
-rw-r--r--drivers/staging/rtl8712/rtl871x_recv.c22
-rw-r--r--drivers/staging/rtl8712/rtl871x_recv.h2
-rw-r--r--drivers/staging/rtl8712/rtl871x_rf.h3
-rw-r--r--drivers/staging/rtl8712/rtl871x_security.c29
-rw-r--r--drivers/staging/rtl8712/rtl871x_security.h4
-rw-r--r--drivers/staging/rtl8712/rtl871x_xmit.c65
-rw-r--r--drivers/staging/rtl8712/rtl871x_xmit.h20
-rw-r--r--drivers/staging/rtl8712/usb_intf.c2
-rw-r--r--drivers/staging/rtl8712/usb_osintf.h4
-rw-r--r--drivers/staging/rtl8712/wifi.h8
-rw-r--r--drivers/staging/rtl8712/xmit_linux.c2
-rw-r--r--drivers/staging/rtl8723bs/Makefile1
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_ap.c113
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_cmd.c11
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_debug.c1307
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_io.c2
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_ioctl_set.c7
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_mlme_ext.c15
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_pwrctrl.c121
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_security.c3
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_wlan_util.c7
-rw-r--r--drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c6
-rw-r--r--drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h1
-rw-r--r--drivers/staging/rtl8723bs/hal/hal_btcoex.c44
-rw-r--r--drivers/staging/rtl8723bs/hal/hal_com.c5
-rw-r--r--drivers/staging/rtl8723bs/hal/hal_com_phycfg.c18
-rw-r--r--drivers/staging/rtl8723bs/hal/hal_intf.c2
-rw-r--r--drivers/staging/rtl8723bs/hal/hal_phy.c157
-rw-r--r--drivers/staging/rtl8723bs/hal/odm.c19
-rw-r--r--drivers/staging/rtl8723bs/hal/odm.h4
-rw-r--r--drivers/staging/rtl8723bs/hal/odm_CfoTracking.c5
-rw-r--r--drivers/staging/rtl8723bs/hal/odm_HWConfig.c7
-rw-r--r--drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c15
-rw-r--r--drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c8
-rw-r--r--drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c7
-rw-r--r--drivers/staging/rtl8723bs/include/autoconf.h4
-rw-r--r--drivers/staging/rtl8723bs/include/drv_types.h8
-rw-r--r--drivers/staging/rtl8723bs/include/hal_btcoex.h8
-rw-r--r--drivers/staging/rtl8723bs/include/hal_com_phycfg.h17
-rw-r--r--drivers/staging/rtl8723bs/include/hal_intf.h2
-rw-r--r--drivers/staging/rtl8723bs/include/hal_phy_cfg.h4
-rw-r--r--drivers/staging/rtl8723bs/include/osdep_intf.h2
-rw-r--r--drivers/staging/rtl8723bs/include/osdep_service.h10
-rw-r--r--drivers/staging/rtl8723bs/include/osdep_service_linux.h14
-rw-r--r--drivers/staging/rtl8723bs/include/rtw_debug.h77
-rw-r--r--drivers/staging/rtl8723bs/include/rtw_mlme.h20
-rw-r--r--drivers/staging/rtl8723bs/include/rtw_mlme_ext.h3
-rw-r--r--drivers/staging/rtl8723bs/include/rtw_recv.h16
-rw-r--r--drivers/staging/rtl8723bs/include/sta_info.h2
-rw-r--r--drivers/staging/rtl8723bs/include/wifi.h14
-rw-r--r--drivers/staging/rtl8723bs/include/wlan_bssdef.h2
-rw-r--r--drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c10
-rw-r--r--drivers/staging/rtl8723bs/os_dep/ioctl_linux.c7
-rw-r--r--drivers/staging/rtl8723bs/os_dep/os_intfs.c21
-rw-r--r--drivers/staging/rtl8723bs/os_dep/osdep_service.c4
-rw-r--r--drivers/staging/rtl8723bs/os_dep/rtw_proc.c779
-rw-r--r--drivers/staging/rtl8723bs/os_dep/rtw_proc.h37
-rw-r--r--drivers/staging/rtl8723bs/os_dep/sdio_intf.c5
-rw-r--r--drivers/staging/rtl8723bs/os_dep/wifi_regd.c5
-rw-r--r--drivers/staging/rts5208/ms.c2
-rw-r--r--drivers/staging/rts5208/rtsx_transport.c12
-rw-r--r--drivers/staging/rts5208/sd.c28
-rw-r--r--drivers/staging/sm750fb/ddk750.h3
-rw-r--r--drivers/staging/sm750fb/ddk750_swi2c.c3
-rw-r--r--drivers/staging/sm750fb/ddk750_swi2c.h3
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h2
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c4
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c5
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c38
-rw-r--r--drivers/staging/vt6656/rxtx.c10
-rw-r--r--drivers/staging/vt6656/usbpipe.c2
-rw-r--r--drivers/staging/wilc1000/microchip,wilc1000,sdio.txt8
-rw-r--r--drivers/staging/wilc1000/microchip,wilc1000,spi.txt8
-rw-r--r--drivers/staging/wilc1000/wilc_hif.c70
-rw-r--r--drivers/staging/wilc1000/wilc_hif.h6
-rw-r--r--drivers/staging/wilc1000/wilc_mon.c3
-rw-r--r--drivers/staging/wilc1000/wilc_netdev.c78
-rw-r--r--drivers/staging/wilc1000/wilc_sdio.c18
-rw-r--r--drivers/staging/wilc1000/wilc_wfi_cfgoperations.c63
-rw-r--r--drivers/staging/wilc1000/wilc_wfi_netdevice.h3
-rw-r--r--drivers/staging/wilc1000/wilc_wlan.c135
-rw-r--r--drivers/staging/wilc1000/wilc_wlan.h19
-rw-r--r--drivers/staging/wilc1000/wilc_wlan_cfg.c78
-rw-r--r--drivers/staging/wilc1000/wilc_wlan_cfg.h4
-rw-r--r--drivers/staging/wilc1000/wilc_wlan_if.h3
-rw-r--r--drivers/staging/wlan-ng/hfa384x_usb.c210
-rw-r--r--drivers/staging/wlan-ng/prism2mib.c44
-rw-r--r--drivers/staging/wlan-ng/prism2sta.c2
-rw-r--r--fs/Kconfig1
-rw-r--r--fs/Makefile1
-rw-r--r--fs/erofs/Kconfig91
-rw-r--r--fs/erofs/Makefile11
-rw-r--r--fs/erofs/compress.h (renamed from drivers/staging/erofs/compress.h)4
-rw-r--r--fs/erofs/data.c (renamed from drivers/staging/erofs/data.c)178
-rw-r--r--fs/erofs/decompressor.c (renamed from drivers/staging/erofs/decompressor.c)65
-rw-r--r--fs/erofs/dir.c (renamed from drivers/staging/erofs/dir.c)71
-rw-r--r--fs/erofs/erofs_fs.h (renamed from drivers/staging/erofs/erofs_fs.h)216
-rw-r--r--fs/erofs/inode.c337
-rw-r--r--fs/erofs/internal.h (renamed from drivers/staging/erofs/internal.h)425
-rw-r--r--fs/erofs/namei.c (renamed from drivers/staging/erofs/namei.c)48
-rw-r--r--fs/erofs/super.c615
-rw-r--r--fs/erofs/tagptr.h (renamed from drivers/staging/erofs/include/linux/tagptr.h)12
-rw-r--r--fs/erofs/utils.c (renamed from drivers/staging/erofs/utils.c)126
-rw-r--r--fs/erofs/xattr.c (renamed from drivers/staging/erofs/xattr.c)76
-rw-r--r--fs/erofs/xattr.h (renamed from drivers/staging/erofs/xattr.h)49
-rw-r--r--fs/erofs/zdata.c1431
-rw-r--r--fs/erofs/zdata.h (renamed from drivers/staging/erofs/unzip_vle.h)129
-rw-r--r--fs/erofs/zmap.c (renamed from drivers/staging/erofs/zmap.c)106
-rw-r--r--fs/erofs/zpvec.h (renamed from drivers/staging/erofs/unzip_pagevec.h)58
-rw-r--r--include/linux/greybus.h (renamed from drivers/staging/greybus/greybus.h)26
-rw-r--r--include/linux/greybus/bundle.h (renamed from drivers/staging/greybus/bundle.h)3
-rw-r--r--include/linux/greybus/connection.h (renamed from drivers/staging/greybus/connection.h)3
-rw-r--r--include/linux/greybus/control.h (renamed from drivers/staging/greybus/control.h)3
-rw-r--r--include/linux/greybus/greybus_id.h (renamed from drivers/staging/greybus/greybus_id.h)0
-rw-r--r--include/linux/greybus/greybus_manifest.h (renamed from drivers/staging/greybus/greybus_manifest.h)5
-rw-r--r--include/linux/greybus/greybus_protocols.h (renamed from drivers/staging/greybus/greybus_protocols.h)50
-rw-r--r--include/linux/greybus/hd.h (renamed from drivers/staging/greybus/hd.h)5
-rw-r--r--include/linux/greybus/interface.h (renamed from drivers/staging/greybus/interface.h)5
-rw-r--r--include/linux/greybus/manifest.h (renamed from drivers/staging/greybus/manifest.h)4
-rw-r--r--include/linux/greybus/module.h (renamed from drivers/staging/greybus/module.h)5
-rw-r--r--include/linux/greybus/operation.h (renamed from drivers/staging/greybus/operation.h)7
-rw-r--r--include/linux/greybus/svc.h (renamed from drivers/staging/greybus/svc.h)7
-rw-r--r--include/linux/iio/common/cros_ec_sensors_core.h28
-rw-r--r--include/linux/iio/common/st_sensors.h66
-rw-r--r--include/linux/iio/common/st_sensors_i2c.h4
-rw-r--r--include/linux/iio/common/st_sensors_spi.h4
-rw-r--r--include/linux/iio/imu/adis.h2
-rw-r--r--include/trace/events/erofs.h (renamed from drivers/staging/erofs/include/trace/events/erofs.h)19
-rw-r--r--include/uapi/linux/magic.h1
-rw-r--r--tools/iio/.gitignore4
448 files changed, 20318 insertions, 12333 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-iio-dfsdm-adc-stm32 b/Documentation/ABI/testing/sysfs-bus-iio-dfsdm-adc-stm32
index da9822309f07..0e66ae9b0071 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio-dfsdm-adc-stm32
+++ b/Documentation/ABI/testing/sysfs-bus-iio-dfsdm-adc-stm32
@@ -13,4 +13,4 @@ Description:
13 error on writing 13 error on writing
14 If DFSDM input is SPI Slave: 14 If DFSDM input is SPI Slave:
15 Reading returns value previously set. 15 Reading returns value previously set.
16 Writing value before starting conversions. \ No newline at end of file 16 Writing value before starting conversions.
diff --git a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
index 161c147d3c40..b7259234ad70 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
+++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
@@ -91,29 +91,6 @@ Description:
91 When counting down the counter start from preset value 91 When counting down the counter start from preset value
92 and fire event when reach 0. 92 and fire event when reach 0.
93 93
94What: /sys/bus/iio/devices/iio:deviceX/in_count_quadrature_mode_available
95KernelVersion: 4.12
96Contact: benjamin.gaignard@st.com
97Description:
98 Reading returns the list possible quadrature modes.
99
100What: /sys/bus/iio/devices/iio:deviceX/in_count0_quadrature_mode
101KernelVersion: 4.12
102Contact: benjamin.gaignard@st.com
103Description:
104 Configure the device counter quadrature modes:
105 channel_A:
106 Encoder A input servers as the count input and B as
107 the UP/DOWN direction control input.
108
109 channel_B:
110 Encoder B input serves as the count input and A as
111 the UP/DOWN direction control input.
112
113 quadrature:
114 Encoder A and B inputs are mixed to get direction
115 and count with a scale of 0.25.
116
117What: /sys/bus/iio/devices/iio:deviceX/in_count_enable_mode_available 94What: /sys/bus/iio/devices/iio:deviceX/in_count_enable_mode_available
118KernelVersion: 4.12 95KernelVersion: 4.12
119Contact: benjamin.gaignard@st.com 96Contact: benjamin.gaignard@st.com
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
new file mode 100644
index 000000000000..676ec42e1438
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
@@ -0,0 +1,121 @@
1# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2# Copyright 2019 Analog Devices Inc.
3%YAML 1.2
4---
5$id: http://devicetree.org/schemas/bindings/iio/adc/adi,ad7192.yaml#
6$schema: http://devicetree.org/meta-schemas/core.yaml#
7
8title: Analog Devices AD7192 ADC device driver
9
10maintainers:
11 - Michael Hennerich <michael.hennerich@analog.com>
12
13description: |
14 Bindings for the Analog Devices AD7192 ADC device. Datasheet can be
15 found here:
16 https://www.analog.com/media/en/technical-documentation/data-sheets/AD7192.pdf
17
18properties:
19 compatible:
20 enum:
21 - adi,ad7190
22 - adi,ad7192
23 - adi,ad7193
24 - adi,ad7195
25
26 reg:
27 maxItems: 1
28
29 spi-cpol: true
30
31 spi-cpha: true
32
33 clocks:
34 maxItems: 1
35 description: phandle to the master clock (mclk)
36
37 clock-names:
38 items:
39 - const: mclk
40
41 interrupts:
42 maxItems: 1
43
44 dvdd-supply:
45 description: DVdd voltage supply
46 items:
47 - const: dvdd
48
49 avdd-supply:
50 description: AVdd voltage supply
51 items:
52 - const: avdd
53
54 adi,rejection-60-Hz-enable:
55 description: |
56 This bit enables a notch at 60 Hz when the first notch of the sinc
57 filter is at 50 Hz. When REJ60 is set, a filter notch is placed at
58 60 Hz when the sinc filter first notch is at 50 Hz. This allows
59 simultaneous 50 Hz/ 60 Hz rejection.
60 type: boolean
61
62 adi,refin2-pins-enable:
63 description: |
64 External reference applied between the P1/REFIN2(+) and P0/REFIN2(−) pins.
65 type: boolean
66
67 adi,buffer-enable:
68 description: |
69 Enables the buffer on the analog inputs. If cleared, the analog inputs
70 are unbuffered, lowering the power consumption of the device. If this
71 bit is set, the analog inputs are buffered, allowing the user to place
72 source impedances on the front end without contributing gain errors to
73 the system.
74 type: boolean
75
76 adi,burnout-currents-enable:
77 description: |
78 When this bit is set to 1, the 500 nA current sources in the signal
79 path are enabled. When BURN = 0, the burnout currents are disabled.
80 The burnout currents can be enabled only when the buffer is active
81 and when chop is disabled.
82 type: boolean
83
84 bipolar:
85 description: see Documentation/devicetree/bindings/iio/adc/adc.txt
86 type: boolean
87
88required:
89 - compatible
90 - reg
91 - clocks
92 - clock-names
93 - interrupts
94 - dvdd-supply
95 - avdd-supply
96 - spi-cpol
97 - spi-cpha
98
99examples:
100 - |
101 spi0 {
102 adc@0 {
103 compatible = "adi,ad7192";
104 reg = <0>;
105 spi-max-frequency = <1000000>;
106 spi-cpol;
107 spi-cpha;
108 clocks = <&ad7192_mclk>;
109 clock-names = "mclk";
110 #interrupt-cells = <2>;
111 interrupts = <25 0x2>;
112 interrupt-parent = <&gpio>;
113 dvdd-supply = <&dvdd>;
114 avdd-supply = <&avdd>;
115
116 adi,refin2-pins-enable;
117 adi,rejection-60-Hz-enable;
118 adi,buffer-enable;
119 adi,burnout-currents-enable;
120 };
121 };
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
deleted file mode 100644
index d8652460198e..000000000000
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
+++ /dev/null
@@ -1,66 +0,0 @@
1Analog Devices AD7606 Simultaneous Sampling ADC
2
3Required properties for the AD7606:
4
5- compatible: Must be one of
6 * "adi,ad7605-4"
7 * "adi,ad7606-8"
8 * "adi,ad7606-6"
9 * "adi,ad7606-4"
10 * "adi,ad7616"
11- reg: SPI chip select number for the device
12- spi-max-frequency: Max SPI frequency to use
13 see: Documentation/devicetree/bindings/spi/spi-bus.txt
14- spi-cpha: See Documentation/devicetree/bindings/spi/spi-bus.txt
15- avcc-supply: phandle to the Avcc power supply
16- interrupts: IRQ line for the ADC
17 see: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
18- adi,conversion-start-gpios: must be the device tree identifier of the CONVST pin.
19 This logic input is used to initiate conversions on the analog
20 input channels. As the line is active high, it should be marked
21 GPIO_ACTIVE_HIGH.
22
23Optional properties:
24
25- reset-gpios: must be the device tree identifier of the RESET pin. If specified,
26 it will be asserted during driver probe. As the line is active high,
27 it should be marked GPIO_ACTIVE_HIGH.
28- standby-gpios: must be the device tree identifier of the STBY pin. This pin is used
29 to place the AD7606 into one of two power-down modes, Standby mode or
30 Shutdown mode. As the line is active low, it should be marked
31 GPIO_ACTIVE_LOW.
32- adi,first-data-gpios: must be the device tree identifier of the FRSTDATA pin.
33 The FRSTDATA output indicates when the first channel, V1, is
34 being read back on either the parallel, byte or serial interface.
35 As the line is active high, it should be marked GPIO_ACTIVE_HIGH.
36- adi,range-gpios: must be the device tree identifier of the RANGE pin. The polarity on
37 this pin determines the input range of the analog input channels. If
38 this pin is tied to a logic high, the analog input range is ±10V for
39 all channels. If this pin is tied to a logic low, the analog input range
40 is ±5V for all channels. As the line is active high, it should be marked
41 GPIO_ACTIVE_HIGH.
42- adi,oversampling-ratio-gpios: must be the device tree identifier of the over-sampling
43 mode pins. As the line is active high, it should be marked
44 GPIO_ACTIVE_HIGH.
45
46Example:
47
48 adc@0 {
49 compatible = "adi,ad7606-8";
50 reg = <0>;
51 spi-max-frequency = <1000000>;
52 spi-cpol;
53
54 avcc-supply = <&adc_vref>;
55
56 interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
57 interrupt-parent = <&gpio>;
58
59 adi,conversion-start-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
60 reset-gpios = <&gpio 27 GPIO_ACTIVE_HIGH>;
61 adi,first-data-gpios = <&gpio 22 GPIO_ACTIVE_HIGH>;
62 adi,oversampling-ratio-gpios = <&gpio 18 GPIO_ACTIVE_HIGH
63 &gpio 23 GPIO_ACTIVE_HIGH
64 &gpio 26 GPIO_ACTIVE_HIGH>;
65 standby-gpios = <&gpio 24 GPIO_ACTIVE_LOW>;
66 };
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
new file mode 100644
index 000000000000..cc544fdc38be
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
@@ -0,0 +1,138 @@
1# SPDX-License-Identifier: GPL-2.0
2%YAML 1.2
3---
4$id: http://devicetree.org/schemas/iio/adc/adi,ad7606.yaml#
5$schema: http://devicetree.org/meta-schemas/core.yaml#
6
7title: Analog Devices AD7606 Simultaneous Sampling ADC
8
9maintainers:
10 - Beniamin Bia <beniamin.bia@analog.com>
11 - Stefan Popa <stefan.popa@analog.com>
12
13description: |
14 Analog Devices AD7606 Simultaneous Sampling ADC
15 https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606_7606-6_7606-4.pdf
16 https://www.analog.com/media/en/technical-documentation/data-sheets/AD7606B.pdf
17 https://www.analog.com/media/en/technical-documentation/data-sheets/AD7616.pdf
18
19properties:
20 compatible:
21 enum:
22 - adi,ad7605-4
23 - adi,ad7606-8
24 - adi,ad7606-6
25 - adi,ad7606-4
26 - adi,ad7606b
27 - adi,ad7616
28
29 reg:
30 maxItems: 1
31
32 spi-cpha: true
33
34 avcc-supply:
35 description:
36 Phandle to the Avcc power supply
37 maxItems: 1
38
39 interrupts:
40 maxItems: 1
41
42 adi,conversion-start-gpios:
43 description:
44 Must be the device tree identifier of the CONVST pin.
45 This logic input is used to initiate conversions on the analog
46 input channels. As the line is active high, it should be marked
47 GPIO_ACTIVE_HIGH.
48 maxItems: 1
49
50 reset-gpios:
51 description:
52 Must be the device tree identifier of the RESET pin. If specified,
53 it will be asserted during driver probe. As the line is active high,
54 it should be marked GPIO_ACTIVE_HIGH.
55 maxItems: 1
56
57 standby-gpios:
58 description:
59 Must be the device tree identifier of the STBY pin. This pin is used
60 to place the AD7606 into one of two power-down modes, Standby mode or
61 Shutdown mode. As the line is active low, it should be marked
62 GPIO_ACTIVE_LOW.
63 maxItems: 1
64
65 adi,first-data-gpios:
66 description:
67 Must be the device tree identifier of the FRSTDATA pin.
68 The FRSTDATA output indicates when the first channel, V1, is
69 being read back on either the parallel, byte or serial interface.
70 As the line is active high, it should be marked GPIO_ACTIVE_HIGH.
71 maxItems: 1
72
73 adi,range-gpios:
74 description:
75 Must be the device tree identifier of the RANGE pin. The polarity on
76 this pin determines the input range of the analog input channels. If
77 this pin is tied to a logic high, the analog input range is ±10V for
78 all channels. If this pin is tied to a logic low, the analog input range
79 is ±5V for all channels. As the line is active high, it should be marked
80 GPIO_ACTIVE_HIGH.
81 maxItems: 1
82
83 adi,oversampling-ratio-gpios:
84 description:
85 Must be the device tree identifier of the over-sampling
86 mode pins. As the line is active high, it should be marked
87 GPIO_ACTIVE_HIGH.
88 maxItems: 1
89
90 adi,sw-mode:
91 description:
92 Software mode of operation, so far available only for ad7616 and ad7606b.
93 It is enabled when all three oversampling mode pins are connected to
94 high level. The device is configured by the corresponding registers. If the
95 adi,oversampling-ratio-gpios property is defined, then the driver will set the
96 oversampling gpios to high. Otherwise, it is assumed that the pins are hardwired
97 to VDD.
98 type: boolean
99
100required:
101 - compatible
102 - reg
103 - spi-cpha
104 - avcc-supply
105 - interrupts
106 - adi,conversion-start-gpios
107
108examples:
109 - |
110 #include <dt-bindings/gpio/gpio.h>
111 #include <dt-bindings/interrupt-controller/irq.h>
112 spi0 {
113 #address-cells = <1>;
114 #size-cells = <0>;
115
116 adc@0 {
117 compatible = "adi,ad7606-8";
118 reg = <0>;
119 spi-max-frequency = <1000000>;
120 spi-cpol;
121 spi-cpha;
122
123 avcc-supply = <&adc_vref>;
124
125 interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
126 interrupt-parent = <&gpio>;
127
128 adi,conversion-start-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
129 reset-gpios = <&gpio 27 GPIO_ACTIVE_HIGH>;
130 adi,first-data-gpios = <&gpio 22 GPIO_ACTIVE_HIGH>;
131 adi,oversampling-ratio-gpios = <&gpio 18 GPIO_ACTIVE_HIGH
132 &gpio 23 GPIO_ACTIVE_HIGH
133 &gpio 26 GPIO_ACTIVE_HIGH>;
134 standby-gpios = <&gpio 24 GPIO_ACTIVE_LOW>;
135 adi,sw-mode;
136 };
137 };
138...
diff --git a/Documentation/devicetree/bindings/iio/adc/st,stm32-adc.txt b/Documentation/devicetree/bindings/iio/adc/st,stm32-adc.txt
index 93a0bd2efc05..4c0da8c74bb2 100644
--- a/Documentation/devicetree/bindings/iio/adc/st,stm32-adc.txt
+++ b/Documentation/devicetree/bindings/iio/adc/st,stm32-adc.txt
@@ -47,6 +47,12 @@ Required properties:
47Optional properties: 47Optional properties:
48- A pinctrl state named "default" for each ADC channel may be defined to set 48- A pinctrl state named "default" for each ADC channel may be defined to set
49 inX ADC pins in mode of operation for analog input on external pin. 49 inX ADC pins in mode of operation for analog input on external pin.
50- booster-supply: Phandle to the embedded booster regulator that can be used
51 to supply ADC analog input switches on stm32h7 and stm32mp1.
52- vdd-supply: Phandle to the vdd input voltage. It can be used to supply ADC
53 analog input switches on stm32mp1.
54- st,syscfg: Phandle to system configuration controller. It can be used to
55 control the analog circuitry on stm32mp1.
50 56
51Contents of a stm32 adc child node: 57Contents of a stm32 adc child node:
52----------------------------------- 58-----------------------------------
diff --git a/Documentation/devicetree/bindings/iio/chemical/plantower,pms7003.txt b/Documentation/devicetree/bindings/iio/chemical/plantower,pms7003.txt
deleted file mode 100644
index c52ea2126eaa..000000000000
--- a/Documentation/devicetree/bindings/iio/chemical/plantower,pms7003.txt
+++ /dev/null
@@ -1,26 +0,0 @@
1* Plantower PMS7003 particulate matter sensor
2
3Required properties:
4- compatible: must one of:
5 "plantower,pms1003"
6 "plantower,pms3003"
7 "plantower,pms5003"
8 "plantower,pms6003"
9 "plantower,pms7003"
10 "plantower,pmsa003"
11- vcc-supply: phandle to the regulator that provides power to the sensor
12
13Optional properties:
14- plantower,set-gpios: phandle to the GPIO connected to the SET line
15- reset-gpios: phandle to the GPIO connected to the RESET line
16
17Refer to serial/slave-device.txt for generic serial attached device bindings.
18
19Example:
20
21&uart0 {
22 air-pollution-sensor {
23 compatible = "plantower,pms7003";
24 vcc-supply = <&reg_vcc5v0>;
25 };
26};
diff --git a/Documentation/devicetree/bindings/iio/chemical/plantower,pms7003.yaml b/Documentation/devicetree/bindings/iio/chemical/plantower,pms7003.yaml
new file mode 100644
index 000000000000..a551d3101f93
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/chemical/plantower,pms7003.yaml
@@ -0,0 +1,51 @@
1# SPDX-License-Identifier: GPL-2.0
2%YAML 1.2
3---
4$id: http://devicetree.org/schemas/iio/chemical/plantower,pms7003.yaml#
5$schema: http://devicetree.org/meta-schemas/core.yaml#
6
7title: Plantower PMS7003 air pollution sensor
8
9maintainers:
10 - Tomasz Duszynski <tduszyns@gmail.com>
11
12description: |
13 Air pollution sensor capable of measuring mass concentration of dust
14 particles.
15
16properties:
17 compatible:
18 enum:
19 - plantower,pms1003
20 - plantower,pms3003
21 - plantower,pms5003
22 - plantower,pms6003
23 - plantower,pms7003
24 - plantower,pmsa003
25
26 vcc-supply:
27 description: regulator that provides power to the sensor
28 maxItems: 1
29
30 plantower,set-gpios:
31 description: GPIO connected to the SET line
32 maxItems: 1
33
34 reset-gpios:
35 description: GPIO connected to the RESET line
36 maxItems: 1
37
38required:
39 - compatible
40 - vcc-supply
41
42examples:
43 - |
44 serial {
45 air-pollution-sensor {
46 compatible = "plantower,pms7003";
47 vcc-supply = <&reg_vcc5v0>;
48 };
49 };
50
51...
diff --git a/Documentation/devicetree/bindings/iio/imu/adi,adis16460.yaml b/Documentation/devicetree/bindings/iio/imu/adi,adis16460.yaml
new file mode 100644
index 000000000000..0c53009ba7d6
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/imu/adi,adis16460.yaml
@@ -0,0 +1,53 @@
1# SPDX-License-Identifier: GPL-2.0
2%YAML 1.2
3---
4$id: http://devicetree.org/schemas/iio/imu/adi,adis16460.yaml#
5$schema: http://devicetree.org/meta-schemas/core.yaml#
6
7title: Analog Devices ADIS16460 and similar IMUs
8
9maintainers:
10 - Dragos Bogdan <dragos.bogdan@analog.com>
11
12description: |
13 Analog Devices ADIS16460 and similar IMUs
14 https://www.analog.com/media/en/technical-documentation/data-sheets/ADIS16460.pdf
15
16properties:
17 compatible:
18 enum:
19 - adi,adis16460
20
21 reg:
22 maxItems: 1
23
24 spi-cpha: true
25
26 spi-cpol: true
27
28 interrupts:
29 maxItems: 1
30
31required:
32 - compatible
33 - reg
34 - interrupts
35
36examples:
37 - |
38 #include <dt-bindings/gpio/gpio.h>
39 #include <dt-bindings/interrupt-controller/irq.h>
40 spi0 {
41 #address-cells = <1>;
42 #size-cells = <0>;
43
44 imu@0 {
45 compatible = "adi,adis16460";
46 reg = <0>;
47 spi-max-frequency = <5000000>;
48 spi-cpol;
49 spi-cpha;
50 interrupt-parent = <&gpio0>;
51 interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
52 };
53 };
diff --git a/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt b/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
index efec9ece034a..6d0c050d89fe 100644
--- a/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
+++ b/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
@@ -11,6 +11,9 @@ Required properties:
11 "st,asm330lhh" 11 "st,asm330lhh"
12 "st,lsm6dsox" 12 "st,lsm6dsox"
13 "st,lsm6dsr" 13 "st,lsm6dsr"
14 "st,lsm6ds3tr-c"
15 "st,ism330dhcx"
16 "st,lsm9ds1-imu"
14- reg: i2c address of the sensor / spi cs line 17- reg: i2c address of the sensor / spi cs line
15 18
16Optional properties: 19Optional properties:
diff --git a/Documentation/devicetree/bindings/iio/light/noa1305.yaml b/Documentation/devicetree/bindings/iio/light/noa1305.yaml
new file mode 100644
index 000000000000..17e7f140b69b
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/light/noa1305.yaml
@@ -0,0 +1,44 @@
1# SPDX-License-Identifier: GPL-2.0
2%YAML 1.2
3---
4$id: http://devicetree.org/schemas/iio/light/noa1305.yaml#
5$schema: http://devicetree.org/meta-schemas/core.yaml#
6
7title: ON Semiconductor NOA1305 Ambient Light Sensor
8
9maintainers:
10 - Martyn Welch <martyn.welch@collabora.com>
11
12description: |
13 Ambient sensing with an i2c interface.
14
15 https://www.onsemi.com/pub/Collateral/NOA1305-D.PDF
16
17properties:
18 compatible:
19 enum:
20 - onnn,noa1305
21
22 reg:
23 maxItems: 1
24
25 vin-supply:
26 description: Regulator that provides power to the sensor
27
28required:
29 - compatible
30 - reg
31
32examples:
33 - |
34 i2c {
35
36 #address-cells = <1>;
37 #size-cells = <0>;
38
39 light@39 {
40 compatible = "onnn,noa1305";
41 reg = <0x39>;
42 };
43 };
44...
diff --git a/Documentation/devicetree/bindings/iio/light/isl29501.txt b/Documentation/devicetree/bindings/iio/light/renesas,isl29501.txt
index 46957997fee3..46957997fee3 100644
--- a/Documentation/devicetree/bindings/iio/light/isl29501.txt
+++ b/Documentation/devicetree/bindings/iio/light/renesas,isl29501.txt
diff --git a/Documentation/devicetree/bindings/iio/light/stk33xx.yaml b/Documentation/devicetree/bindings/iio/light/stk33xx.yaml
new file mode 100644
index 000000000000..aae8a6d627c9
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/light/stk33xx.yaml
@@ -0,0 +1,49 @@
1# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2%YAML 1.2
3---
4$id: http://devicetree.org/schemas/iio/light/stk33xx.yaml#
5$schema: http://devicetree.org/meta-schemas/core.yaml#
6
7title: |
8 Sensortek STK33xx I2C Ambient Light and Proximity sensor
9
10maintainers:
11 - Jonathan Cameron <jic23@kernel.org>
12
13description: |
14 Ambient light and proximity sensor over an i2c interface.
15
16properties:
17 compatible:
18 enum:
19 - sensortek,stk3310
20 - sensortek,stk3311
21 - sensortek,stk3335
22
23 reg:
24 maxItems: 1
25
26 interrupts:
27 maxItems: 1
28
29required:
30 - compatible
31 - reg
32
33examples:
34 - |
35 #include <dt-bindings/interrupt-controller/irq.h>
36
37 i2c {
38
39 #address-cells = <1>;
40 #size-cells = <0>;
41
42 stk3310@48 {
43 compatible = "sensortek,stk3310";
44 reg = <0x48>;
45 interrupt-parent = <&gpio1>;
46 interrupts = <5 IRQ_TYPE_LEVEL_LOW>;
47 };
48 };
49...
diff --git a/Documentation/devicetree/bindings/iio/mount-matrix.txt b/Documentation/devicetree/bindings/iio/mount-matrix.txt
new file mode 100644
index 000000000000..c3344ab509a3
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/mount-matrix.txt
@@ -0,0 +1,203 @@
1For discussion. Unclear are:
2* is the definition of +/- values practical or counterintuitive?
3* are the definitions unambiguous and easy to follow?
4* are the examples correct?
5* should we have HOWTO engineer a correct matrix for a new device (without comparing to a different one)?
6
7====
8
9
10Mounting matrix
11
12The mounting matrix is a device tree property used to orient any device
13that produce three-dimensional data in relation to the world where it is
14deployed.
15
16The purpose of the mounting matrix is to translate the sensor frame of
17reference into the device frame of reference using a translation matrix as
18defined in linear algebra.
19
20The typical usecase is that where a component has an internal representation
21of the (x,y,z) triplets, such as different registers to read these coordinates,
22and thus implying that the component should be mounted in a certain orientation
23relative to some specific device frame of reference.
24
25For example a device with some kind of screen, where the user is supposed to
26interact with the environment using an accelerometer, gyroscope or magnetometer
27mounted on the same chassis as this screen, will likely take the screen as
28reference to (x,y,z) orientation, with (x,y) corresponding to these axes on the
29screen and (z) being depth, the axis perpendicular to the screen.
30
31For a screen you probably want (x) coordinates to go from negative on the left
32to positive on the right, (y) from negative on the bottom to positive on top
33and (z) depth to be negative under the screen and positive in front of it,
34toward the face of the user.
35
36A sensor can be mounted in any angle along the axes relative to the frame of
37reference. This means that the sensor may be flipped upside-down, left-right,
38or tilted at any angle relative to the frame of reference.
39
40Another frame of reference is how the device with its sensor relates to the
41external world, the environment where the device is deployed. Usually the data
42from the sensor is used to figure out how the device is oriented with respect
43to this world. When using the mounting matrix, the sensor and device orientation
44becomes identical and we can focus on the data as it relates to the surrounding
45world.
46
47Device-to-world examples for some three-dimensional sensor types:
48
49- Accelerometers have their world frame of reference toward the center of
50 gravity, usually to the core of the planet. A reading of the (x,y,z) values
51 from the sensor will give a projection of the gravity vector through the
52 device relative to the center of the planet, i.e. relative to its surface at
53 this point. Up and down in the world relative to the device frame of
54 reference can thus be determined. and users would likely expect a value of
55 9.81 m/s^2 upwards along the (z) axis, i.e. out of the screen when the device
56 is held with its screen flat on the planets surface and 0 on the other axes,
57 as the gravity vector is projected 1:1 onto the sensors (z)-axis.
58
59 If you tilt the device, the g vector virtually coming out of the display
60 is projected onto the (x,y) plane of the display panel.
61
62 Example:
63
64 ^ z: +g ^ z: > 0
65 ! /!
66 ! x=y=0 / ! x: > 0
67 +--------+ +--------+
68 ! ! ! !
69 +--------+ +--------+
70 ! /
71 ! /
72 v v
73 center of center of
74 gravity gravity
75
76
77 If the device is tilted to the left, you get a positive x value. If you point
78 its top towards surface, you get a negative y axis.
79
80 (---------)
81 ! ! y: -g
82 ! ! ^
83 ! ! !
84 ! !
85 ! ! x: +g <- z: +g -> x: -g
86 ! 1 2 3 !
87 ! 4 5 6 ! !
88 ! 7 8 9 ! v
89 ! * 0 # ! y: +g
90 (---------)
91
92
93- Magnetometers (compasses) have their world frame of reference relative to the
94 geomagnetic field. The system orientation vis-a-vis the world is defined with
95 respect to the local earth geomagnetic reference frame where (y) is in the
96 ground plane and positive towards magnetic North, (x) is in the ground plane,
97 perpendicular to the North axis and positive towards the East and (z) is
98 perpendicular to the ground plane and positive upwards.
99
100
101 ^^^ North: y > 0
102
103 (---------)
104 ! !
105 ! !
106 ! !
107 ! ! >
108 ! ! > North: x > 0
109 ! 1 2 3 ! >
110 ! 4 5 6 !
111 ! 7 8 9 !
112 ! * 0 # !
113 (---------)
114
115 Since the geomagnetic field is not uniform this definition fails if we come
116 closer to the poles.
117
118 Sensors and driver can not and should not take care of this because there
119 are complex calculations and empirical data to be taken care of. We leave
120 this up to user space.
121
122 The definition we take:
123
124 If the device is placed at the equator and the top is pointing north, the
125 display is readable by a person standing upright on the earth surface, this
126 defines a positive y value.
127
128
129- Gyroscopes detects the movement relative the device itself. The angular
130 velocity is defined as orthogonal to the plane of rotation, so if you put the
131 device on a flat surface and spin it around the z axis (such as rotating a
132 device with a screen lying flat on a table), you should get a negative value
133 along the (z) axis if rotated clockwise, and a positive value if rotated
134 counter-clockwise according to the right-hand rule.
135
136
137 (---------) y > 0
138 ! ! v---\
139 ! !
140 ! !
141 ! ! <--\
142 ! ! ! z > 0
143 ! 1 2 3 ! --/
144 ! 4 5 6 !
145 ! 7 8 9 !
146 ! * 0 # !
147 (---------)
148
149
150So unless the sensor is ideally mounted, we need a means to indicate the
151relative orientation of any given sensor of this type with respect to the
152frame of reference.
153
154To achieve this, use the device tree property "mount-matrix" for the sensor.
155
156This supplies a 3x3 rotation matrix in the strict linear algebraic sense,
157to orient the senor axes relative to a desired point of reference. This means
158the resulting values from the sensor, after scaling to proper units, should be
159multiplied by this matrix to give the proper vectors values in three-dimensional
160space, relative to the device or world point of reference.
161
162For more information, consult:
163https://en.wikipedia.org/wiki/Rotation_matrix
164
165The mounting matrix has the layout:
166
167 (mxx, myx, mzx)
168 (mxy, myy, mzy)
169 (mxz, myz, mzz)
170
171Values are intended to be multiplied as:
172
173 x' = mxx * x + myx * y + mzx * z
174 y' = mxy * x + myy * y + mzy * z
175 z' = mxz * x + myz * y + mzz * z
176
177It is represented as an array of strings containing the real values for
178producing the transformation matrix.
179
180Examples:
181
182Identity matrix (nothing happens to the coordinates, which means the device was
183mechanically mounted in an ideal way and we need no transformation):
184
185mount-matrix = "1", "0", "0",
186 "0", "1", "0",
187 "0", "0", "1";
188
189The sensor is mounted 30 degrees (Pi/6 radians) tilted along the X axis, so we
190compensate by performing a -30 degrees rotation around the X axis:
191
192mount-matrix = "1", "0", "0",
193 "0", "0.866", "0.5",
194 "0", "-0.5", "0.866";
195
196The sensor is flipped 180 degrees (Pi radians) around the Z axis, i.e. mounted
197upside-down:
198
199mount-matrix = "0.998", "0.054", "0",
200 "-0.054", "0.998", "0",
201 "0", "0", "1";
202
203???: this does not match "180 degrees" - factors indicate ca. 3 degrees compensation
diff --git a/Documentation/devicetree/bindings/iio/potentiometer/max5432.yaml b/Documentation/devicetree/bindings/iio/potentiometer/max5432.yaml
new file mode 100644
index 000000000000..5082f919df2a
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/potentiometer/max5432.yaml
@@ -0,0 +1,44 @@
1# SPDX-License-Identifier: GPL-2.0
2%YAML 1.2
3---
4$id: http://devicetree.org/schemas/iio/potentiometer/max5432.yaml#
5$schema: http://devicetree.org/meta-schemas/core.yaml#
6
7title: Maxim Integrated MAX5432-MAX5435 Digital Potentiometers
8
9maintainers:
10 - Martin Kaiser <martin@kaiser.cx>
11
12description: |
13 Maxim Integrated MAX5432-MAX5435 Digital Potentiometers connected via I2C
14
15 Datasheet:
16 https://datasheets.maximintegrated.com/en/ds/MAX5432-MAX5435.pdf
17
18properties:
19 compatible:
20 enum:
21 - maxim,max5432
22 - maxim,max5433
23 - maxim,max5434
24 - maxim,max5435
25
26 reg:
27 maxItems: 1
28
29required:
30 - compatible
31 - reg
32
33additionalProperties: false
34
35examples:
36 - |
37 i2c {
38 #address-cells = <1>;
39 #size-cells = <0>;
40 max5434@28 {
41 compatible = "maxim,max5434";
42 reg = <0x28>;
43 };
44 };
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml
index de4240e0aa82..329b668dac0a 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
@@ -827,6 +827,8 @@ patternProperties:
827 description: Semtech Corporation 827 description: Semtech Corporation
828 "^sensirion,.*": 828 "^sensirion,.*":
829 description: Sensirion AG 829 description: Sensirion AG
830 "^sensortek,.*":
831 description: Sensortek Technology Corporation
830 "^sff,.*": 832 "^sff,.*":
831 description: Small Form Factor Committee 833 description: Small Form Factor Committee
832 "^sgd,.*": 834 "^sgd,.*":
diff --git a/drivers/staging/erofs/Documentation/filesystems/erofs.txt b/Documentation/filesystems/erofs.txt
index 74cf84ac48a3..b0c085326e2e 100644
--- a/drivers/staging/erofs/Documentation/filesystems/erofs.txt
+++ b/Documentation/filesystems/erofs.txt
@@ -49,22 +49,23 @@ Bugs and patches are welcome, please kindly help us and send to the following
49linux-erofs mailing list: 49linux-erofs mailing list:
50>> linux-erofs mailing list <linux-erofs@lists.ozlabs.org> 50>> linux-erofs mailing list <linux-erofs@lists.ozlabs.org>
51 51
52Note that EROFS is still working in progress as a Linux staging driver,
53Cc the staging mailing list as well is highly recommended:
54>> Linux Driver Project Developer List <devel@driverdev.osuosl.org>
55
56Mount options 52Mount options
57============= 53=============
58 54
59fault_injection=%d Enable fault injection in all supported types with
60 specified injection rate. Supported injection type:
61 Type_Name Type_Value
62 FAULT_KMALLOC 0x000000001
63 FAULT_READ_IO 0x000000002
64(no)user_xattr Setup Extended User Attributes. Note: xattr is enabled 55(no)user_xattr Setup Extended User Attributes. Note: xattr is enabled
65 by default if CONFIG_EROFS_FS_XATTR is selected. 56 by default if CONFIG_EROFS_FS_XATTR is selected.
66(no)acl Setup POSIX Access Control List. Note: acl is enabled 57(no)acl Setup POSIX Access Control List. Note: acl is enabled
67 by default if CONFIG_EROFS_FS_POSIX_ACL is selected. 58 by default if CONFIG_EROFS_FS_POSIX_ACL is selected.
59cache_strategy=%s Select a strategy for cached decompression from now on:
60 disabled: In-place I/O decompression only;
61 readahead: Cache the last incomplete compressed physical
62 cluster for further reading. It still does
63 in-place I/O decompression for the rest
64 compressed physical clusters;
65 readaround: Cache the both ends of incomplete compressed
66 physical clusters for further reading.
67 It still does in-place I/O decompression
68 for the rest compressed physical clusters.
68 69
69On-disk details 70On-disk details
70=============== 71===============
diff --git a/MAINTAINERS b/MAINTAINERS
index 0e01ab35df04..0262f99df61d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -902,11 +902,12 @@ F: Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml
902 902
903ANALOG DEVICES INC AD7606 DRIVER 903ANALOG DEVICES INC AD7606 DRIVER
904M: Stefan Popa <stefan.popa@analog.com> 904M: Stefan Popa <stefan.popa@analog.com>
905M: Beniamin Bia <beniamin.bia@analog.com>
905L: linux-iio@vger.kernel.org 906L: linux-iio@vger.kernel.org
906W: http://ez.analog.com/community/linux-device-drivers 907W: http://ez.analog.com/community/linux-device-drivers
907S: Supported 908S: Supported
908F: drivers/iio/adc/ad7606.c 909F: drivers/iio/adc/ad7606.c
909F: Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt 910F: Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
910 911
911ANALOG DEVICES INC AD7768-1 DRIVER 912ANALOG DEVICES INC AD7768-1 DRIVER
912M: Stefan Popa <stefan.popa@analog.com> 913M: Stefan Popa <stefan.popa@analog.com>
@@ -944,6 +945,14 @@ L: linux-iio@vger.kernel.org
944F: include/linux/iio/imu/adis.h 945F: include/linux/iio/imu/adis.h
945F: drivers/iio/imu/adis.c 946F: drivers/iio/imu/adis.c
946 947
948ANALOG DEVICES INC ADIS16460 DRIVER
949M: Dragos Bogdan <dragos.bogdan@analog.com>
950S: Supported
951L: linux-iio@vger.kernel.org
952W: http://ez.analog.com/community/linux-device-drivers
953F: drivers/iio/imu/adis16460.c
954F: Documentation/devicetree/bindings/iio/imu/adi,adis16460.yaml
955
947ANALOG DEVICES INC ADP5061 DRIVER 956ANALOG DEVICES INC ADP5061 DRIVER
948M: Stefan Popa <stefan.popa@analog.com> 957M: Stefan Popa <stefan.popa@analog.com>
949L: linux-pm@vger.kernel.org 958L: linux-pm@vger.kernel.org
@@ -6050,6 +6059,13 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/kristoffer/linux-hpc.git
6050F: drivers/video/fbdev/s1d13xxxfb.c 6059F: drivers/video/fbdev/s1d13xxxfb.c
6051F: include/video/s1d13xxxfb.h 6060F: include/video/s1d13xxxfb.h
6052 6061
6062EROFS FILE SYSTEM
6063M: Gao Xiang <gaoxiang25@huawei.com>
6064M: Chao Yu <yuchao0@huawei.com>
6065L: linux-erofs@lists.ozlabs.org
6066S: Maintained
6067F: fs/erofs/
6068
6053ERRSEQ ERROR TRACKING INFRASTRUCTURE 6069ERRSEQ ERROR TRACKING INFRASTRUCTURE
6054M: Jeff Layton <jlayton@kernel.org> 6070M: Jeff Layton <jlayton@kernel.org>
6055S: Maintained 6071S: Maintained
@@ -6094,6 +6110,11 @@ F: include/trace/events/mdio.h
6094F: include/uapi/linux/mdio.h 6110F: include/uapi/linux/mdio.h
6095F: include/uapi/linux/mii.h 6111F: include/uapi/linux/mii.h
6096 6112
6113EXFAT FILE SYSTEM
6114M: Valdis Kletnieks <valdis.kletnieks@vt.edu>
6115S: Maintained
6116F: drivers/staging/exfat/
6117
6097EXT2 FILE SYSTEM 6118EXT2 FILE SYSTEM
6098M: Jan Kara <jack@suse.com> 6119M: Jan Kara <jack@suse.com>
6099L: linux-ext4@vger.kernel.org 6120L: linux-ext4@vger.kernel.org
@@ -7001,6 +7022,9 @@ M: Alex Elder <elder@kernel.org>
7001M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 7022M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
7002S: Maintained 7023S: Maintained
7003F: drivers/staging/greybus/ 7024F: drivers/staging/greybus/
7025F: drivers/greybus/
7026F: include/linux/greybus.h
7027F: include/linux/greybus/
7004L: greybus-dev@lists.linaro.org (moderated for non-subscribers) 7028L: greybus-dev@lists.linaro.org (moderated for non-subscribers)
7005 7029
7006GREYBUS UART PROTOCOLS DRIVERS 7030GREYBUS UART PROTOCOLS DRIVERS
@@ -12803,6 +12827,12 @@ F: drivers/i2c/busses/i2c-puv3.c
12803F: drivers/video/fbdev/fb-puv3.c 12827F: drivers/video/fbdev/fb-puv3.c
12804F: drivers/rtc/rtc-puv3.c 12828F: drivers/rtc/rtc-puv3.c
12805 12829
12830PLANTOWER PMS7003 AIR POLLUTION SENSOR DRIVER
12831M: Tomasz Duszynski <tduszyns@gmail.com>
12832S: Maintained
12833F: drivers/iio/chemical/pms7003.c
12834F: Documentation/devicetree/bindings/iio/chemical/plantower,pms7003.yaml
12835
12806PMBUS HARDWARE MONITORING DRIVERS 12836PMBUS HARDWARE MONITORING DRIVERS
12807M: Guenter Roeck <linux@roeck-us.net> 12837M: Guenter Roeck <linux@roeck-us.net>
12808L: linux-hwmon@vger.kernel.org 12838L: linux-hwmon@vger.kernel.org
@@ -15240,13 +15270,6 @@ M: H Hartley Sweeten <hsweeten@visionengravers.com>
15240S: Odd Fixes 15270S: Odd Fixes
15241F: drivers/staging/comedi/ 15271F: drivers/staging/comedi/
15242 15272
15243STAGING - EROFS FILE SYSTEM
15244M: Gao Xiang <gaoxiang25@huawei.com>
15245M: Chao Yu <yuchao0@huawei.com>
15246L: linux-erofs@lists.ozlabs.org
15247S: Maintained
15248F: drivers/staging/erofs/
15249
15250STAGING - FIELDBUS SUBSYSTEM 15273STAGING - FIELDBUS SUBSYSTEM
15251M: Sven Van Asbroeck <TheSven73@gmail.com> 15274M: Sven Van Asbroeck <TheSven73@gmail.com>
15252S: Maintained 15275S: Maintained
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 13f09bf64a0f..8befa53f43be 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -142,6 +142,8 @@ source "drivers/hv/Kconfig"
142 142
143source "drivers/xen/Kconfig" 143source "drivers/xen/Kconfig"
144 144
145source "drivers/greybus/Kconfig"
146
145source "drivers/staging/Kconfig" 147source "drivers/staging/Kconfig"
146 148
147source "drivers/platform/Kconfig" 149source "drivers/platform/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index ad66dc2325d7..aaef17cc6512 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -146,6 +146,7 @@ obj-$(CONFIG_BCMA) += bcma/
146obj-$(CONFIG_VHOST_RING) += vhost/ 146obj-$(CONFIG_VHOST_RING) += vhost/
147obj-$(CONFIG_VHOST) += vhost/ 147obj-$(CONFIG_VHOST) += vhost/
148obj-$(CONFIG_VLYNQ) += vlynq/ 148obj-$(CONFIG_VLYNQ) += vlynq/
149obj-$(CONFIG_GREYBUS) += greybus/
149obj-$(CONFIG_STAGING) += staging/ 150obj-$(CONFIG_STAGING) += staging/
150obj-y += platform/ 151obj-y += platform/
151 152
diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
index 68a9b7393457..4046aa9f9234 100644
--- a/drivers/counter/ftm-quaddec.c
+++ b/drivers/counter/ftm-quaddec.c
@@ -100,16 +100,18 @@ static void ftm_quaddec_init(struct ftm_quaddec *ftm)
100 ftm_set_write_protection(ftm); 100 ftm_set_write_protection(ftm);
101} 101}
102 102
103static void ftm_quaddec_disable(struct ftm_quaddec *ftm) 103static void ftm_quaddec_disable(void *ftm)
104{ 104{
105 ftm_clear_write_protection(ftm); 105 struct ftm_quaddec *ftm_qua = ftm;
106 ftm_write(ftm, FTM_MODE, 0); 106
107 ftm_write(ftm, FTM_QDCTRL, 0); 107 ftm_clear_write_protection(ftm_qua);
108 ftm_write(ftm_qua, FTM_MODE, 0);
109 ftm_write(ftm_qua, FTM_QDCTRL, 0);
108 /* 110 /*
109 * This is enough to disable the counter. No clock has been 111 * This is enough to disable the counter. No clock has been
110 * selected by writing to FTM_SC in init() 112 * selected by writing to FTM_SC in init()
111 */ 113 */
112 ftm_set_write_protection(ftm); 114 ftm_set_write_protection(ftm_qua);
113} 115}
114 116
115static int ftm_quaddec_get_prescaler(struct counter_device *counter, 117static int ftm_quaddec_get_prescaler(struct counter_device *counter,
@@ -317,20 +319,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
317 319
318 ftm_quaddec_init(ftm); 320 ftm_quaddec_init(ftm);
319 321
320 ret = counter_register(&ftm->counter); 322 ret = devm_add_action_or_reset(&pdev->dev, ftm_quaddec_disable, ftm);
321 if (ret) 323 if (ret)
322 ftm_quaddec_disable(ftm); 324 return ret;
323
324 return ret;
325}
326 325
327static int ftm_quaddec_remove(struct platform_device *pdev) 326 ret = devm_counter_register(&pdev->dev, &ftm->counter);
328{ 327 if (ret)
329 struct ftm_quaddec *ftm = platform_get_drvdata(pdev); 328 return ret;
330
331 counter_unregister(&ftm->counter);
332
333 ftm_quaddec_disable(ftm);
334 329
335 return 0; 330 return 0;
336} 331}
@@ -346,7 +341,6 @@ static struct platform_driver ftm_quaddec_driver = {
346 .of_match_table = ftm_quaddec_match, 341 .of_match_table = ftm_quaddec_match,
347 }, 342 },
348 .probe = ftm_quaddec_probe, 343 .probe = ftm_quaddec_probe,
349 .remove = ftm_quaddec_remove,
350}; 344};
351 345
352module_platform_driver(ftm_quaddec_driver); 346module_platform_driver(ftm_quaddec_driver);
diff --git a/drivers/greybus/Kconfig b/drivers/greybus/Kconfig
new file mode 100644
index 000000000000..b84fcaf8b105
--- /dev/null
+++ b/drivers/greybus/Kconfig
@@ -0,0 +1,32 @@
1# SPDX-License-Identifier: GPL-2.0
2menuconfig GREYBUS
3 tristate "Greybus support"
4 depends on SYSFS
5 ---help---
6 This option enables the Greybus driver core. Greybus is an
7 hardware protocol that was designed to provide Unipro with a
8 sane application layer. It was originally designed for the
9 ARA project, a module phone system, but has shown up in other
10 phones, and can be tunneled over other busses in order to
11 control hardware devices.
12
13 Say Y here to enable support for these types of drivers.
14
15 To compile this code as a module, chose M here: the module
16 will be called greybus.ko
17
18if GREYBUS
19
20config GREYBUS_ES2
21 tristate "Greybus ES3 USB host controller"
22 depends on USB
23 ---help---
24 Select this option if you have a Toshiba ES3 USB device that
25 acts as a Greybus "host controller". This device is a bridge
26 from a USB device to a Unipro network.
27
28 To compile this code as a module, chose M here: the module
29 will be called gb-es2.ko
30
31endif # GREYBUS
32
diff --git a/drivers/greybus/Makefile b/drivers/greybus/Makefile
new file mode 100644
index 000000000000..9bccdd229aa2
--- /dev/null
+++ b/drivers/greybus/Makefile
@@ -0,0 +1,26 @@
1# SPDX-License-Identifier: GPL-2.0
2# Greybus core
3greybus-y := core.o \
4 debugfs.o \
5 hd.o \
6 manifest.o \
7 module.o \
8 interface.o \
9 bundle.o \
10 connection.o \
11 control.o \
12 svc.o \
13 svc_watchdog.o \
14 operation.o
15
16obj-$(CONFIG_GREYBUS) += greybus.o
17
18# needed for trace events
19ccflags-y += -I$(src)
20
21# Greybus Host controller drivers
22gb-es2-y := es2.o
23
24obj-$(CONFIG_GREYBUS_ES2) += gb-es2.o
25
26
diff --git a/drivers/greybus/arpc.h b/drivers/greybus/arpc.h
new file mode 100644
index 000000000000..c8b83c5cfa79
--- /dev/null
+++ b/drivers/greybus/arpc.h
@@ -0,0 +1,63 @@
1/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2/*
3 * Copyright(c) 2016 Google Inc. All rights reserved.
4 * Copyright(c) 2016 Linaro Ltd. All rights reserved.
5 */
6
7#ifndef __ARPC_H
8#define __ARPC_H
9
10/* APBridgeA RPC (ARPC) */
11
12enum arpc_result {
13 ARPC_SUCCESS = 0x00,
14 ARPC_NO_MEMORY = 0x01,
15 ARPC_INVALID = 0x02,
16 ARPC_TIMEOUT = 0x03,
17 ARPC_UNKNOWN_ERROR = 0xff,
18};
19
20struct arpc_request_message {
21 __le16 id; /* RPC unique id */
22 __le16 size; /* Size in bytes of header + payload */
23 __u8 type; /* RPC type */
24 __u8 data[0]; /* ARPC data */
25} __packed;
26
27struct arpc_response_message {
28 __le16 id; /* RPC unique id */
29 __u8 result; /* Result of RPC */
30} __packed;
31
32/* ARPC requests */
33#define ARPC_TYPE_CPORT_CONNECTED 0x01
34#define ARPC_TYPE_CPORT_QUIESCE 0x02
35#define ARPC_TYPE_CPORT_CLEAR 0x03
36#define ARPC_TYPE_CPORT_FLUSH 0x04
37#define ARPC_TYPE_CPORT_SHUTDOWN 0x05
38
39struct arpc_cport_connected_req {
40 __le16 cport_id;
41} __packed;
42
43struct arpc_cport_quiesce_req {
44 __le16 cport_id;
45 __le16 peer_space;
46 __le16 timeout;
47} __packed;
48
49struct arpc_cport_clear_req {
50 __le16 cport_id;
51} __packed;
52
53struct arpc_cport_flush_req {
54 __le16 cport_id;
55} __packed;
56
57struct arpc_cport_shutdown_req {
58 __le16 cport_id;
59 __le16 timeout;
60 __u8 phase;
61} __packed;
62
63#endif /* __ARPC_H */
diff --git a/drivers/staging/greybus/bundle.c b/drivers/greybus/bundle.c
index 3f702db9e098..84660729538b 100644
--- a/drivers/staging/greybus/bundle.c
+++ b/drivers/greybus/bundle.c
@@ -6,7 +6,7 @@
6 * Copyright 2014-2015 Linaro Ltd. 6 * Copyright 2014-2015 Linaro Ltd.
7 */ 7 */
8 8
9#include "greybus.h" 9#include <linux/greybus.h>
10#include "greybus_trace.h" 10#include "greybus_trace.h"
11 11
12static ssize_t bundle_class_show(struct device *dev, 12static ssize_t bundle_class_show(struct device *dev,
diff --git a/drivers/staging/greybus/connection.c b/drivers/greybus/connection.c
index eda964208cce..fc8f57f97ce6 100644
--- a/drivers/staging/greybus/connection.c
+++ b/drivers/greybus/connection.c
@@ -7,8 +7,8 @@
7 */ 7 */
8 8
9#include <linux/workqueue.h> 9#include <linux/workqueue.h>
10#include <linux/greybus.h>
10 11
11#include "greybus.h"
12#include "greybus_trace.h" 12#include "greybus_trace.h"
13 13
14#define GB_CONNECTION_CPORT_QUIESCE_TIMEOUT 1000 14#define GB_CONNECTION_CPORT_QUIESCE_TIMEOUT 1000
diff --git a/drivers/staging/greybus/control.c b/drivers/greybus/control.c
index a9e8b6036cac..359a25841973 100644
--- a/drivers/staging/greybus/control.c
+++ b/drivers/greybus/control.c
@@ -9,7 +9,7 @@
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include "greybus.h" 12#include <linux/greybus.h>
13 13
14/* Highest control-protocol version supported */ 14/* Highest control-protocol version supported */
15#define GB_CONTROL_VERSION_MAJOR 0 15#define GB_CONTROL_VERSION_MAJOR 0
diff --git a/drivers/staging/greybus/core.c b/drivers/greybus/core.c
index d6b0d49130c0..e546c6431877 100644
--- a/drivers/staging/greybus/core.c
+++ b/drivers/greybus/core.c
@@ -9,7 +9,7 @@
9#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 9#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 10
11#define CREATE_TRACE_POINTS 11#define CREATE_TRACE_POINTS
12#include "greybus.h" 12#include <linux/greybus.h>
13#include "greybus_trace.h" 13#include "greybus_trace.h"
14 14
15#define GB_BUNDLE_AUTOSUSPEND_MS 3000 15#define GB_BUNDLE_AUTOSUSPEND_MS 3000
diff --git a/drivers/staging/greybus/debugfs.c b/drivers/greybus/debugfs.c
index 56e20c30feb5..e102d7badb9d 100644
--- a/drivers/staging/greybus/debugfs.c
+++ b/drivers/greybus/debugfs.c
@@ -7,8 +7,7 @@
7 */ 7 */
8 8
9#include <linux/debugfs.h> 9#include <linux/debugfs.h>
10 10#include <linux/greybus.h>
11#include "greybus.h"
12 11
13static struct dentry *gb_debug_root; 12static struct dentry *gb_debug_root;
14 13
diff --git a/drivers/staging/greybus/es2.c b/drivers/greybus/es2.c
index be6af18cec31..366716f11b1a 100644
--- a/drivers/staging/greybus/es2.c
+++ b/drivers/greybus/es2.c
@@ -11,12 +11,11 @@
11#include <linux/kfifo.h> 11#include <linux/kfifo.h>
12#include <linux/debugfs.h> 12#include <linux/debugfs.h>
13#include <linux/list.h> 13#include <linux/list.h>
14#include <linux/greybus.h>
14#include <asm/unaligned.h> 15#include <asm/unaligned.h>
15 16
16#include "arpc.h" 17#include "arpc.h"
17#include "greybus.h"
18#include "greybus_trace.h" 18#include "greybus_trace.h"
19#include "connection.h"
20 19
21 20
22/* Default timeout for USB vendor requests. */ 21/* Default timeout for USB vendor requests. */
diff --git a/drivers/staging/greybus/greybus_trace.h b/drivers/greybus/greybus_trace.h
index 7b5e2c6b1f6b..1bc9f1275c65 100644
--- a/drivers/staging/greybus/greybus_trace.h
+++ b/drivers/greybus/greybus_trace.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Greybus driver and device API 3 * Greybus driver and device API
4 * 4 *
diff --git a/drivers/staging/greybus/hd.c b/drivers/greybus/hd.c
index 969f86697673..72b21bf2d7d3 100644
--- a/drivers/staging/greybus/hd.c
+++ b/drivers/greybus/hd.c
@@ -8,8 +8,8 @@
8 8
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/slab.h> 10#include <linux/slab.h>
11#include <linux/greybus.h>
11 12
12#include "greybus.h"
13#include "greybus_trace.h" 13#include "greybus_trace.h"
14 14
15EXPORT_TRACEPOINT_SYMBOL_GPL(gb_hd_create); 15EXPORT_TRACEPOINT_SYMBOL_GPL(gb_hd_create);
@@ -31,7 +31,7 @@ int gb_hd_output(struct gb_host_device *hd, void *req, u16 size, u8 cmd,
31EXPORT_SYMBOL_GPL(gb_hd_output); 31EXPORT_SYMBOL_GPL(gb_hd_output);
32 32
33static ssize_t bus_id_show(struct device *dev, 33static ssize_t bus_id_show(struct device *dev,
34 struct device_attribute *attr, char *buf) 34 struct device_attribute *attr, char *buf)
35{ 35{
36 struct gb_host_device *hd = to_gb_host_device(dev); 36 struct gb_host_device *hd = to_gb_host_device(dev);
37 37
@@ -70,7 +70,7 @@ EXPORT_SYMBOL_GPL(gb_hd_cport_release_reserved);
70 70
71/* Locking: Caller guarantees serialisation */ 71/* Locking: Caller guarantees serialisation */
72int gb_hd_cport_allocate(struct gb_host_device *hd, int cport_id, 72int gb_hd_cport_allocate(struct gb_host_device *hd, int cport_id,
73 unsigned long flags) 73 unsigned long flags)
74{ 74{
75 struct ida *id_map = &hd->cport_id_map; 75 struct ida *id_map = &hd->cport_id_map;
76 int ida_start, ida_end; 76 int ida_start, ida_end;
@@ -122,9 +122,9 @@ struct device_type greybus_hd_type = {
122}; 122};
123 123
124struct gb_host_device *gb_hd_create(struct gb_hd_driver *driver, 124struct gb_host_device *gb_hd_create(struct gb_hd_driver *driver,
125 struct device *parent, 125 struct device *parent,
126 size_t buffer_size_max, 126 size_t buffer_size_max,
127 size_t num_cports) 127 size_t num_cports)
128{ 128{
129 struct gb_host_device *hd; 129 struct gb_host_device *hd;
130 int ret; 130 int ret;
diff --git a/drivers/staging/greybus/interface.c b/drivers/greybus/interface.c
index d7b5b89a2f40..67dbe6fda9a1 100644
--- a/drivers/staging/greybus/interface.c
+++ b/drivers/greybus/interface.c
@@ -7,8 +7,8 @@
7 */ 7 */
8 8
9#include <linux/delay.h> 9#include <linux/delay.h>
10#include <linux/greybus.h>
10 11
11#include "greybus.h"
12#include "greybus_trace.h" 12#include "greybus_trace.h"
13 13
14#define GB_INTERFACE_MODE_SWITCH_TIMEOUT 2000 14#define GB_INTERFACE_MODE_SWITCH_TIMEOUT 2000
diff --git a/drivers/staging/greybus/manifest.c b/drivers/greybus/manifest.c
index 08db49264f2b..dd7040697bde 100644
--- a/drivers/staging/greybus/manifest.c
+++ b/drivers/greybus/manifest.c
@@ -6,7 +6,7 @@
6 * Copyright 2014-2015 Linaro Ltd. 6 * Copyright 2014-2015 Linaro Ltd.
7 */ 7 */
8 8
9#include "greybus.h" 9#include <linux/greybus.h>
10 10
11static const char *get_descriptor_type_string(u8 type) 11static const char *get_descriptor_type_string(u8 type)
12{ 12{
@@ -104,15 +104,15 @@ static int identify_descriptor(struct gb_interface *intf,
104 size_t expected_size; 104 size_t expected_size;
105 105
106 if (size < sizeof(*desc_header)) { 106 if (size < sizeof(*desc_header)) {
107 dev_err(&intf->dev, "manifest too small (%zu < %zu)\n", 107 dev_err(&intf->dev, "manifest too small (%zu < %zu)\n", size,
108 size, sizeof(*desc_header)); 108 sizeof(*desc_header));
109 return -EINVAL; /* Must at least have header */ 109 return -EINVAL; /* Must at least have header */
110 } 110 }
111 111
112 desc_size = le16_to_cpu(desc_header->size); 112 desc_size = le16_to_cpu(desc_header->size);
113 if (desc_size > size) { 113 if (desc_size > size) {
114 dev_err(&intf->dev, "descriptor too big (%zu > %zu)\n", 114 dev_err(&intf->dev, "descriptor too big (%zu > %zu)\n",
115 desc_size, size); 115 desc_size, size);
116 return -EINVAL; 116 return -EINVAL;
117 } 117 }
118 118
@@ -139,22 +139,22 @@ static int identify_descriptor(struct gb_interface *intf,
139 case GREYBUS_TYPE_INVALID: 139 case GREYBUS_TYPE_INVALID:
140 default: 140 default:
141 dev_err(&intf->dev, "invalid descriptor type (%u)\n", 141 dev_err(&intf->dev, "invalid descriptor type (%u)\n",
142 desc_header->type); 142 desc_header->type);
143 return -EINVAL; 143 return -EINVAL;
144 } 144 }
145 145
146 if (desc_size < expected_size) { 146 if (desc_size < expected_size) {
147 dev_err(&intf->dev, "%s descriptor too small (%zu < %zu)\n", 147 dev_err(&intf->dev, "%s descriptor too small (%zu < %zu)\n",
148 get_descriptor_type_string(desc_header->type), 148 get_descriptor_type_string(desc_header->type),
149 desc_size, expected_size); 149 desc_size, expected_size);
150 return -EINVAL; 150 return -EINVAL;
151 } 151 }
152 152
153 /* Descriptor bigger than what we expect */ 153 /* Descriptor bigger than what we expect */
154 if (desc_size > expected_size) { 154 if (desc_size > expected_size) {
155 dev_warn(&intf->dev, "%s descriptor size mismatch (want %zu got %zu)\n", 155 dev_warn(&intf->dev, "%s descriptor size mismatch (want %zu got %zu)\n",
156 get_descriptor_type_string(desc_header->type), 156 get_descriptor_type_string(desc_header->type),
157 expected_size, desc_size); 157 expected_size, desc_size);
158 } 158 }
159 159
160 descriptor = kzalloc(sizeof(*descriptor), GFP_KERNEL); 160 descriptor = kzalloc(sizeof(*descriptor), GFP_KERNEL);
@@ -208,7 +208,7 @@ static char *gb_string_get(struct gb_interface *intf, u8 string_id)
208 208
209 /* Allocate an extra byte so we can guarantee it's NUL-terminated */ 209 /* Allocate an extra byte so we can guarantee it's NUL-terminated */
210 string = kmemdup(&desc_string->string, desc_string->length + 1, 210 string = kmemdup(&desc_string->string, desc_string->length + 1,
211 GFP_KERNEL); 211 GFP_KERNEL);
212 if (!string) 212 if (!string)
213 return ERR_PTR(-ENOMEM); 213 return ERR_PTR(-ENOMEM);
214 string[desc_string->length] = '\0'; 214 string[desc_string->length] = '\0';
@@ -264,8 +264,7 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
264 desc_cport = tmp->data; 264 desc_cport = tmp->data;
265 if (cport_id == le16_to_cpu(desc_cport->id)) { 265 if (cport_id == le16_to_cpu(desc_cport->id)) {
266 dev_err(&bundle->dev, 266 dev_err(&bundle->dev,
267 "duplicate CPort %u found\n", 267 "duplicate CPort %u found\n", cport_id);
268 cport_id);
269 goto exit; 268 goto exit;
270 } 269 }
271 } 270 }
@@ -277,7 +276,7 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
277 return 0; 276 return 0;
278 277
279 bundle->cport_desc = kcalloc(count, sizeof(*bundle->cport_desc), 278 bundle->cport_desc = kcalloc(count, sizeof(*bundle->cport_desc),
280 GFP_KERNEL); 279 GFP_KERNEL);
281 if (!bundle->cport_desc) 280 if (!bundle->cport_desc)
282 goto exit; 281 goto exit;
283 282
@@ -287,7 +286,7 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
287 list_for_each_entry_safe(desc, next, &list, links) { 286 list_for_each_entry_safe(desc, next, &list, links) {
288 desc_cport = desc->data; 287 desc_cport = desc->data;
289 memcpy(&bundle->cport_desc[i++], desc_cport, 288 memcpy(&bundle->cport_desc[i++], desc_cport,
290 sizeof(*desc_cport)); 289 sizeof(*desc_cport));
291 290
292 /* Release the cport descriptor */ 291 /* Release the cport descriptor */
293 release_manifest_descriptor(desc); 292 release_manifest_descriptor(desc);
@@ -333,9 +332,9 @@ static u32 gb_manifest_parse_bundles(struct gb_interface *intf)
333 /* Ignore any legacy control bundles */ 332 /* Ignore any legacy control bundles */
334 if (bundle_id == GB_CONTROL_BUNDLE_ID) { 333 if (bundle_id == GB_CONTROL_BUNDLE_ID) {
335 dev_dbg(&intf->dev, "%s - ignoring control bundle\n", 334 dev_dbg(&intf->dev, "%s - ignoring control bundle\n",
336 __func__); 335 __func__);
337 release_cport_descriptors(&intf->manifest_descs, 336 release_cport_descriptors(&intf->manifest_descs,
338 bundle_id); 337 bundle_id);
339 continue; 338 continue;
340 } 339 }
341 340
@@ -468,7 +467,7 @@ bool gb_manifest_parse(struct gb_interface *intf, void *data, size_t size)
468 /* we have to have at _least_ the manifest header */ 467 /* we have to have at _least_ the manifest header */
469 if (size < sizeof(*header)) { 468 if (size < sizeof(*header)) {
470 dev_err(&intf->dev, "short manifest (%zu < %zu)\n", 469 dev_err(&intf->dev, "short manifest (%zu < %zu)\n",
471 size, sizeof(*header)); 470 size, sizeof(*header));
472 return false; 471 return false;
473 } 472 }
474 473
@@ -478,15 +477,15 @@ bool gb_manifest_parse(struct gb_interface *intf, void *data, size_t size)
478 manifest_size = le16_to_cpu(header->size); 477 manifest_size = le16_to_cpu(header->size);
479 if (manifest_size != size) { 478 if (manifest_size != size) {
480 dev_err(&intf->dev, "manifest size mismatch (%zu != %u)\n", 479 dev_err(&intf->dev, "manifest size mismatch (%zu != %u)\n",
481 size, manifest_size); 480 size, manifest_size);
482 return false; 481 return false;
483 } 482 }
484 483
485 /* Validate major/minor number */ 484 /* Validate major/minor number */
486 if (header->version_major > GREYBUS_VERSION_MAJOR) { 485 if (header->version_major > GREYBUS_VERSION_MAJOR) {
487 dev_err(&intf->dev, "manifest version too new (%u.%u > %u.%u)\n", 486 dev_err(&intf->dev, "manifest version too new (%u.%u > %u.%u)\n",
488 header->version_major, header->version_minor, 487 header->version_major, header->version_minor,
489 GREYBUS_VERSION_MAJOR, GREYBUS_VERSION_MINOR); 488 GREYBUS_VERSION_MAJOR, GREYBUS_VERSION_MINOR);
490 return false; 489 return false;
491 } 490 }
492 491
@@ -513,7 +512,7 @@ bool gb_manifest_parse(struct gb_interface *intf, void *data, size_t size)
513 } 512 }
514 if (found != 1) { 513 if (found != 1) {
515 dev_err(&intf->dev, "manifest must have 1 interface descriptor (%u found)\n", 514 dev_err(&intf->dev, "manifest must have 1 interface descriptor (%u found)\n",
516 found); 515 found);
517 result = false; 516 result = false;
518 goto out; 517 goto out;
519 } 518 }
diff --git a/drivers/staging/greybus/module.c b/drivers/greybus/module.c
index b251a53d0e8e..36f77f9e1d74 100644
--- a/drivers/staging/greybus/module.c
+++ b/drivers/greybus/module.c
@@ -6,7 +6,7 @@
6 * Copyright 2016 Linaro Ltd. 6 * Copyright 2016 Linaro Ltd.
7 */ 7 */
8 8
9#include "greybus.h" 9#include <linux/greybus.h>
10#include "greybus_trace.h" 10#include "greybus_trace.h"
11 11
12static ssize_t eject_store(struct device *dev, 12static ssize_t eject_store(struct device *dev,
diff --git a/drivers/staging/greybus/operation.c b/drivers/greybus/operation.c
index fe268f7b63ed..8459e9bc0749 100644
--- a/drivers/staging/greybus/operation.c
+++ b/drivers/greybus/operation.c
@@ -12,8 +12,8 @@
12#include <linux/sched.h> 12#include <linux/sched.h>
13#include <linux/wait.h> 13#include <linux/wait.h>
14#include <linux/workqueue.h> 14#include <linux/workqueue.h>
15#include <linux/greybus.h>
15 16
16#include "greybus.h"
17#include "greybus_trace.h" 17#include "greybus_trace.h"
18 18
19static struct kmem_cache *gb_operation_cache; 19static struct kmem_cache *gb_operation_cache;
diff --git a/drivers/staging/greybus/svc.c b/drivers/greybus/svc.c
index 05bc45287b87..ce7740ef449b 100644
--- a/drivers/staging/greybus/svc.c
+++ b/drivers/greybus/svc.c
@@ -8,8 +8,7 @@
8 8
9#include <linux/debugfs.h> 9#include <linux/debugfs.h>
10#include <linux/workqueue.h> 10#include <linux/workqueue.h>
11 11#include <linux/greybus.h>
12#include "greybus.h"
13 12
14#define SVC_INTF_EJECT_TIMEOUT 9000 13#define SVC_INTF_EJECT_TIMEOUT 9000
15#define SVC_INTF_ACTIVATE_TIMEOUT 6000 14#define SVC_INTF_ACTIVATE_TIMEOUT 6000
diff --git a/drivers/staging/greybus/svc_watchdog.c b/drivers/greybus/svc_watchdog.c
index 7868ad8211c5..b6b1682c19c4 100644
--- a/drivers/staging/greybus/svc_watchdog.c
+++ b/drivers/greybus/svc_watchdog.c
@@ -8,7 +8,7 @@
8#include <linux/delay.h> 8#include <linux/delay.h>
9#include <linux/suspend.h> 9#include <linux/suspend.h>
10#include <linux/workqueue.h> 10#include <linux/workqueue.h>
11#include "greybus.h" 11#include <linux/greybus.h>
12 12
13#define SVC_WATCHDOG_PERIOD (2 * HZ) 13#define SVC_WATCHDOG_PERIOD (2 * HZ)
14 14
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index 9b9656ce37e6..d4ef35aeb579 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -202,9 +202,7 @@ config HID_SENSOR_ACCEL_3D
202 202
203config IIO_CROS_EC_ACCEL_LEGACY 203config IIO_CROS_EC_ACCEL_LEGACY
204 tristate "ChromeOS EC Legacy Accelerometer Sensor" 204 tristate "ChromeOS EC Legacy Accelerometer Sensor"
205 select IIO_BUFFER 205 depends on IIO_CROS_EC_SENSORS_CORE
206 select IIO_TRIGGERED_BUFFER
207 select CROS_EC_LPC_REGISTER_DEVICE
208 help 206 help
209 Say yes here to get support for accelerometers on Chromebook using 207 Say yes here to get support for accelerometers on Chromebook using
210 legacy EC firmware. 208 legacy EC firmware.
diff --git a/drivers/iio/accel/cros_ec_accel_legacy.c b/drivers/iio/accel/cros_ec_accel_legacy.c
index ad19d9c716f4..39002cb5605d 100644
--- a/drivers/iio/accel/cros_ec_accel_legacy.c
+++ b/drivers/iio/accel/cros_ec_accel_legacy.c
@@ -5,13 +5,14 @@
5 * Copyright 2017 Google, Inc 5 * Copyright 2017 Google, Inc
6 * 6 *
7 * This driver uses the memory mapper cros-ec interface to communicate 7 * This driver uses the memory mapper cros-ec interface to communicate
8 * with the Chrome OS EC about accelerometer data. 8 * with the Chrome OS EC about accelerometer data or older commands.
9 * Accelerometer access is presented through iio sysfs. 9 * Accelerometer access is presented through iio sysfs.
10 */ 10 */
11 11
12#include <linux/delay.h> 12#include <linux/delay.h>
13#include <linux/device.h> 13#include <linux/device.h>
14#include <linux/iio/buffer.h> 14#include <linux/iio/buffer.h>
15#include <linux/iio/common/cros_ec_sensors_core.h>
15#include <linux/iio/iio.h> 16#include <linux/iio/iio.h>
16#include <linux/iio/kfifo_buf.h> 17#include <linux/iio/kfifo_buf.h>
17#include <linux/iio/trigger_consumer.h> 18#include <linux/iio/trigger_consumer.h>
@@ -25,160 +26,41 @@
25 26
26#define DRV_NAME "cros-ec-accel-legacy" 27#define DRV_NAME "cros-ec-accel-legacy"
27 28
29#define CROS_EC_SENSOR_LEGACY_NUM 2
28/* 30/*
29 * Sensor scale hard coded at 10 bits per g, computed as: 31 * Sensor scale hard coded at 10 bits per g, computed as:
30 * g / (2^10 - 1) = 0.009586168; with g = 9.80665 m.s^-2 32 * g / (2^10 - 1) = 0.009586168; with g = 9.80665 m.s^-2
31 */ 33 */
32#define ACCEL_LEGACY_NSCALE 9586168 34#define ACCEL_LEGACY_NSCALE 9586168
33 35
34/* Indices for EC sensor values. */ 36static int cros_ec_accel_legacy_read_cmd(struct iio_dev *indio_dev,
35enum { 37 unsigned long scan_mask, s16 *data)
36 X,
37 Y,
38 Z,
39 MAX_AXIS,
40};
41
42/* State data for cros_ec_accel_legacy iio driver. */
43struct cros_ec_accel_legacy_state {
44 struct cros_ec_device *ec;
45
46 /*
47 * Array holding data from a single capture. 2 bytes per channel
48 * for the 3 channels plus the timestamp which is always last and
49 * 8-bytes aligned.
50 */
51 s16 capture_data[8];
52 s8 sign[MAX_AXIS];
53 u8 sensor_num;
54};
55
56static int ec_cmd_read_u8(struct cros_ec_device *ec, unsigned int offset,
57 u8 *dest)
58{
59 return ec->cmd_readmem(ec, offset, 1, dest);
60}
61
62static int ec_cmd_read_u16(struct cros_ec_device *ec, unsigned int offset,
63 u16 *dest)
64{
65 __le16 tmp;
66 int ret = ec->cmd_readmem(ec, offset, 2, &tmp);
67
68 *dest = le16_to_cpu(tmp);
69
70 return ret;
71}
72
73/**
74 * read_ec_until_not_busy() - Read from EC status byte until it reads not busy.
75 * @st: Pointer to state information for device.
76 *
77 * This function reads EC status until its busy bit gets cleared. It does not
78 * wait indefinitely and returns -EIO if the EC status is still busy after a
79 * few hundreds milliseconds.
80 *
81 * Return: 8-bit status if ok, -EIO on error
82 */
83static int read_ec_until_not_busy(struct cros_ec_accel_legacy_state *st)
84{
85 struct cros_ec_device *ec = st->ec;
86 u8 status;
87 int attempts = 0;
88
89 ec_cmd_read_u8(ec, EC_MEMMAP_ACC_STATUS, &status);
90 while (status & EC_MEMMAP_ACC_STATUS_BUSY_BIT) {
91 /* Give up after enough attempts, return error. */
92 if (attempts++ >= 50)
93 return -EIO;
94
95 /* Small delay every so often. */
96 if (attempts % 5 == 0)
97 msleep(25);
98
99 ec_cmd_read_u8(ec, EC_MEMMAP_ACC_STATUS, &status);
100 }
101
102 return status;
103}
104
105/**
106 * read_ec_accel_data_unsafe() - Read acceleration data from EC shared memory.
107 * @st: Pointer to state information for device.
108 * @scan_mask: Bitmap of the sensor indices to scan.
109 * @data: Location to store data.
110 *
111 * This is the unsafe function for reading the EC data. It does not guarantee
112 * that the EC will not modify the data as it is being read in.
113 */
114static void read_ec_accel_data_unsafe(struct cros_ec_accel_legacy_state *st,
115 unsigned long scan_mask, s16 *data)
116{
117 int i = 0;
118 int num_enabled = bitmap_weight(&scan_mask, MAX_AXIS);
119
120 /* Read all sensors enabled in scan_mask. Each value is 2 bytes. */
121 while (num_enabled--) {
122 i = find_next_bit(&scan_mask, MAX_AXIS, i);
123 ec_cmd_read_u16(st->ec,
124 EC_MEMMAP_ACC_DATA +
125 sizeof(s16) *
126 (1 + i + st->sensor_num * MAX_AXIS),
127 data);
128 *data *= st->sign[i];
129 i++;
130 data++;
131 }
132}
133
134/**
135 * read_ec_accel_data() - Read acceleration data from EC shared memory.
136 * @st: Pointer to state information for device.
137 * @scan_mask: Bitmap of the sensor indices to scan.
138 * @data: Location to store data.
139 *
140 * This is the safe function for reading the EC data. It guarantees that
141 * the data sampled was not modified by the EC while being read.
142 *
143 * Return: 0 if ok, -ve on error
144 */
145static int read_ec_accel_data(struct cros_ec_accel_legacy_state *st,
146 unsigned long scan_mask, s16 *data)
147{ 38{
148 u8 samp_id = 0xff; 39 struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
149 u8 status = 0;
150 int ret; 40 int ret;
151 int attempts = 0; 41 unsigned int i;
42 u8 sensor_num;
152 43
153 /* 44 /*
154 * Continually read all data from EC until the status byte after 45 * Read all sensor data through a command.
155 * all reads reflects that the EC is not busy and the sample id 46 * Save sensor_num, it is assumed to stay.
156 * matches the sample id from before all reads. This guarantees
157 * that data read in was not modified by the EC while reading.
158 */ 47 */
159 while ((status & (EC_MEMMAP_ACC_STATUS_BUSY_BIT | 48 sensor_num = st->param.info.sensor_num;
160 EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK)) != samp_id) { 49 st->param.cmd = MOTIONSENSE_CMD_DUMP;
161 /* If we have tried to read too many times, return error. */ 50 st->param.dump.max_sensor_count = CROS_EC_SENSOR_LEGACY_NUM;
162 if (attempts++ >= 5) 51 ret = cros_ec_motion_send_host_cmd(st,
163 return -EIO; 52 sizeof(st->resp->dump) + CROS_EC_SENSOR_LEGACY_NUM *
164 53 sizeof(struct ec_response_motion_sensor_data));
165 /* Read status byte until EC is not busy. */ 54 st->param.info.sensor_num = sensor_num;
166 ret = read_ec_until_not_busy(st); 55 if (ret != 0) {
167 if (ret < 0) 56 dev_warn(&indio_dev->dev, "Unable to read sensor data\n");
168 return ret; 57 return ret;
169 status = ret; 58 }
170
171 /*
172 * Store the current sample id so that we can compare to the
173 * sample id after reading the data.
174 */
175 samp_id = status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
176
177 /* Read all EC data, format it, and store it into data. */
178 read_ec_accel_data_unsafe(st, scan_mask, data);
179 59
180 /* Read status byte. */ 60 for_each_set_bit(i, &scan_mask, indio_dev->masklength) {
181 ec_cmd_read_u8(st->ec, EC_MEMMAP_ACC_STATUS, &status); 61 *data = st->resp->dump.sensor[sensor_num].data[i] *
62 st->sign[i];
63 data++;
182 } 64 }
183 65
184 return 0; 66 return 0;
@@ -188,28 +70,40 @@ static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev,
188 struct iio_chan_spec const *chan, 70 struct iio_chan_spec const *chan,
189 int *val, int *val2, long mask) 71 int *val, int *val2, long mask)
190{ 72{
191 struct cros_ec_accel_legacy_state *st = iio_priv(indio_dev); 73 struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
192 s16 data = 0; 74 s16 data = 0;
193 int ret = IIO_VAL_INT; 75 int ret;
76 int idx = chan->scan_index;
77
78 mutex_lock(&st->cmd_lock);
194 79
195 switch (mask) { 80 switch (mask) {
196 case IIO_CHAN_INFO_RAW: 81 case IIO_CHAN_INFO_RAW:
197 ret = read_ec_accel_data(st, (1 << chan->scan_index), &data); 82 ret = st->read_ec_sensors_data(indio_dev, 1 << idx, &data);
198 if (ret) 83 if (ret < 0)
199 return ret; 84 break;
85 ret = IIO_VAL_INT;
200 *val = data; 86 *val = data;
201 return IIO_VAL_INT; 87 break;
202 case IIO_CHAN_INFO_SCALE: 88 case IIO_CHAN_INFO_SCALE:
89 WARN_ON(st->type != MOTIONSENSE_TYPE_ACCEL);
203 *val = 0; 90 *val = 0;
204 *val2 = ACCEL_LEGACY_NSCALE; 91 *val2 = ACCEL_LEGACY_NSCALE;
205 return IIO_VAL_INT_PLUS_NANO; 92 ret = IIO_VAL_INT_PLUS_NANO;
93 break;
206 case IIO_CHAN_INFO_CALIBBIAS: 94 case IIO_CHAN_INFO_CALIBBIAS:
207 /* Calibration not supported. */ 95 /* Calibration not supported. */
208 *val = 0; 96 *val = 0;
209 return IIO_VAL_INT; 97 ret = IIO_VAL_INT;
98 break;
210 default: 99 default:
211 return -EINVAL; 100 ret = cros_ec_sensors_core_read(st, chan, val, val2,
101 mask);
102 break;
212 } 103 }
104 mutex_unlock(&st->cmd_lock);
105
106 return ret;
213} 107}
214 108
215static int cros_ec_accel_legacy_write(struct iio_dev *indio_dev, 109static int cros_ec_accel_legacy_write(struct iio_dev *indio_dev,
@@ -231,86 +125,14 @@ static const struct iio_info cros_ec_accel_legacy_info = {
231 .write_raw = &cros_ec_accel_legacy_write, 125 .write_raw = &cros_ec_accel_legacy_write,
232}; 126};
233 127
234/** 128/*
235 * cros_ec_accel_legacy_capture() - The trigger handler function 129 * Present the channel using HTML5 standard:
236 * @irq: The interrupt number. 130 * need to invert X and Y and invert some lid axis.
237 * @p: Private data - always a pointer to the poll func.
238 *
239 * On a trigger event occurring, if the pollfunc is attached then this
240 * handler is called as a threaded interrupt (and hence may sleep). It
241 * is responsible for grabbing data from the device and pushing it into
242 * the associated buffer.
243 *
244 * Return: IRQ_HANDLED
245 */ 131 */
246static irqreturn_t cros_ec_accel_legacy_capture(int irq, void *p) 132#define CROS_EC_ACCEL_ROTATE_AXIS(_axis) \
247{ 133 ((_axis) == CROS_EC_SENSOR_Z ? CROS_EC_SENSOR_Z : \
248 struct iio_poll_func *pf = p; 134 ((_axis) == CROS_EC_SENSOR_X ? CROS_EC_SENSOR_Y : \
249 struct iio_dev *indio_dev = pf->indio_dev; 135 CROS_EC_SENSOR_X))
250 struct cros_ec_accel_legacy_state *st = iio_priv(indio_dev);
251
252 /* Clear capture data. */
253 memset(st->capture_data, 0, sizeof(st->capture_data));
254
255 /*
256 * Read data based on which channels are enabled in scan mask. Note
257 * that on a capture we are always reading the calibrated data.
258 */
259 read_ec_accel_data(st, *indio_dev->active_scan_mask, st->capture_data);
260
261 iio_push_to_buffers_with_timestamp(indio_dev, (void *)st->capture_data,
262 iio_get_time_ns(indio_dev));
263
264 /*
265 * Tell the core we are done with this trigger and ready for the
266 * next one.
267 */
268 iio_trigger_notify_done(indio_dev->trig);
269
270 return IRQ_HANDLED;
271}
272
273static char *cros_ec_accel_legacy_loc_strings[] = {
274 [MOTIONSENSE_LOC_BASE] = "base",
275 [MOTIONSENSE_LOC_LID] = "lid",
276 [MOTIONSENSE_LOC_MAX] = "unknown",
277};
278
279static ssize_t cros_ec_accel_legacy_loc(struct iio_dev *indio_dev,
280 uintptr_t private,
281 const struct iio_chan_spec *chan,
282 char *buf)
283{
284 struct cros_ec_accel_legacy_state *st = iio_priv(indio_dev);
285
286 return sprintf(buf, "%s\n",
287 cros_ec_accel_legacy_loc_strings[st->sensor_num +
288 MOTIONSENSE_LOC_BASE]);
289}
290
291static ssize_t cros_ec_accel_legacy_id(struct iio_dev *indio_dev,
292 uintptr_t private,
293 const struct iio_chan_spec *chan,
294 char *buf)
295{
296 struct cros_ec_accel_legacy_state *st = iio_priv(indio_dev);
297
298 return sprintf(buf, "%d\n", st->sensor_num);
299}
300
301static const struct iio_chan_spec_ext_info cros_ec_accel_legacy_ext_info[] = {
302 {
303 .name = "id",
304 .shared = IIO_SHARED_BY_ALL,
305 .read = cros_ec_accel_legacy_id,
306 },
307 {
308 .name = "location",
309 .shared = IIO_SHARED_BY_ALL,
310 .read = cros_ec_accel_legacy_loc,
311 },
312 { }
313};
314 136
315#define CROS_EC_ACCEL_LEGACY_CHAN(_axis) \ 137#define CROS_EC_ACCEL_LEGACY_CHAN(_axis) \
316 { \ 138 { \
@@ -321,28 +143,28 @@ static const struct iio_chan_spec_ext_info cros_ec_accel_legacy_ext_info[] = {
321 BIT(IIO_CHAN_INFO_RAW) | \ 143 BIT(IIO_CHAN_INFO_RAW) | \
322 BIT(IIO_CHAN_INFO_CALIBBIAS), \ 144 BIT(IIO_CHAN_INFO_CALIBBIAS), \
323 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE), \ 145 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE), \
324 .ext_info = cros_ec_accel_legacy_ext_info, \ 146 .ext_info = cros_ec_sensors_ext_info, \
325 .scan_type = { \ 147 .scan_type = { \
326 .sign = 's', \ 148 .sign = 's', \
327 .realbits = 16, \ 149 .realbits = CROS_EC_SENSOR_BITS, \
328 .storagebits = 16, \ 150 .storagebits = CROS_EC_SENSOR_BITS, \
329 }, \ 151 }, \
152 .scan_index = CROS_EC_ACCEL_ROTATE_AXIS(_axis), \
330 } \ 153 } \
331 154
332static struct iio_chan_spec ec_accel_channels[] = { 155static const struct iio_chan_spec cros_ec_accel_legacy_channels[] = {
333 CROS_EC_ACCEL_LEGACY_CHAN(X), 156 CROS_EC_ACCEL_LEGACY_CHAN(CROS_EC_SENSOR_X),
334 CROS_EC_ACCEL_LEGACY_CHAN(Y), 157 CROS_EC_ACCEL_LEGACY_CHAN(CROS_EC_SENSOR_Y),
335 CROS_EC_ACCEL_LEGACY_CHAN(Z), 158 CROS_EC_ACCEL_LEGACY_CHAN(CROS_EC_SENSOR_Z),
336 IIO_CHAN_SOFT_TIMESTAMP(MAX_AXIS) 159 IIO_CHAN_SOFT_TIMESTAMP(CROS_EC_SENSOR_MAX_AXIS)
337}; 160};
338 161
339static int cros_ec_accel_legacy_probe(struct platform_device *pdev) 162static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
340{ 163{
341 struct device *dev = &pdev->dev; 164 struct device *dev = &pdev->dev;
342 struct cros_ec_dev *ec = dev_get_drvdata(dev->parent); 165 struct cros_ec_dev *ec = dev_get_drvdata(dev->parent);
343 struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
344 struct iio_dev *indio_dev; 166 struct iio_dev *indio_dev;
345 struct cros_ec_accel_legacy_state *state; 167 struct cros_ec_sensors_core_state *state;
346 int ret; 168 int ret;
347 169
348 if (!ec || !ec->ec_dev) { 170 if (!ec || !ec->ec_dev) {
@@ -350,46 +172,32 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
350 return -EINVAL; 172 return -EINVAL;
351 } 173 }
352 174
353 if (!ec->ec_dev->cmd_readmem) {
354 dev_warn(&pdev->dev, "EC does not support direct reads.\n");
355 return -EINVAL;
356 }
357
358 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*state)); 175 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*state));
359 if (!indio_dev) 176 if (!indio_dev)
360 return -ENOMEM; 177 return -ENOMEM;
361 178
362 platform_set_drvdata(pdev, indio_dev); 179 ret = cros_ec_sensors_core_init(pdev, indio_dev, true);
363 state = iio_priv(indio_dev); 180 if (ret)
364 state->ec = ec->ec_dev; 181 return ret;
365 state->sensor_num = sensor_platform->sensor_num;
366
367 indio_dev->dev.parent = dev;
368 indio_dev->name = pdev->name;
369 indio_dev->channels = ec_accel_channels;
370 /*
371 * Present the channel using HTML5 standard:
372 * need to invert X and Y and invert some lid axis.
373 */
374 ec_accel_channels[X].scan_index = Y;
375 ec_accel_channels[Y].scan_index = X;
376 ec_accel_channels[Z].scan_index = Z;
377 182
378 state->sign[Y] = 1; 183 indio_dev->info = &cros_ec_accel_legacy_info;
184 state = iio_priv(indio_dev);
379 185
380 if (state->sensor_num == MOTIONSENSE_LOC_LID) 186 if (state->ec->cmd_readmem != NULL)
381 state->sign[X] = state->sign[Z] = -1; 187 state->read_ec_sensors_data = cros_ec_sensors_read_lpc;
382 else 188 else
383 state->sign[X] = state->sign[Z] = 1; 189 state->read_ec_sensors_data = cros_ec_accel_legacy_read_cmd;
384 190
385 indio_dev->num_channels = ARRAY_SIZE(ec_accel_channels); 191 indio_dev->channels = cros_ec_accel_legacy_channels;
386 indio_dev->dev.parent = &pdev->dev; 192 indio_dev->num_channels = ARRAY_SIZE(cros_ec_accel_legacy_channels);
387 indio_dev->info = &cros_ec_accel_legacy_info; 193 /* The lid sensor needs to be presented inverted. */
388 indio_dev->modes = INDIO_DIRECT_MODE; 194 if (state->loc == MOTIONSENSE_LOC_LID) {
195 state->sign[CROS_EC_SENSOR_X] = -1;
196 state->sign[CROS_EC_SENSOR_Z] = -1;
197 }
389 198
390 ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, 199 ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
391 cros_ec_accel_legacy_capture, 200 cros_ec_sensors_capture, NULL);
392 NULL);
393 if (ret) 201 if (ret)
394 return ret; 202 return ret;
395 203
diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
index 6645771aa349..fee535d6e45b 100644
--- a/drivers/iio/accel/kxcjk-1013.c
+++ b/drivers/iio/accel/kxcjk-1013.c
@@ -1486,8 +1486,8 @@ static const struct acpi_device_id kx_acpi_match[] = {
1486 {"KIOX0008", KXCJ91008}, 1486 {"KIOX0008", KXCJ91008},
1487 {"KIOX0009", KXTJ21009}, 1487 {"KIOX0009", KXTJ21009},
1488 {"KIOX000A", KXCJ91008}, 1488 {"KIOX000A", KXCJ91008},
1489 {"KIOX010A", KXCJ91008}, /* KXCJ91008 inside the display of a 2-in-1 */ 1489 {"KIOX010A", KXCJ91008}, /* KXCJ91008 in the display of a yoga 2-in-1 */
1490 {"KIOX020A", KXCJ91008}, 1490 {"KIOX020A", KXCJ91008}, /* KXCJ91008 in the base of a yoga 2-in-1 */
1491 {"KXTJ1009", KXTJ21009}, 1491 {"KXTJ1009", KXTJ21009},
1492 {"KXJ2109", KXTJ21009}, 1492 {"KXJ2109", KXTJ21009},
1493 {"SMO8500", KXCJ91008}, 1493 {"SMO8500", KXCJ91008},
diff --git a/drivers/iio/accel/mxc4005.c b/drivers/iio/accel/mxc4005.c
index 637e6e676061..3d5bea651923 100644
--- a/drivers/iio/accel/mxc4005.c
+++ b/drivers/iio/accel/mxc4005.c
@@ -424,7 +424,7 @@ static int mxc4005_probe(struct i2c_client *client,
424 indio_dev->modes = INDIO_DIRECT_MODE; 424 indio_dev->modes = INDIO_DIRECT_MODE;
425 indio_dev->info = &mxc4005_info; 425 indio_dev->info = &mxc4005_info;
426 426
427 ret = iio_triggered_buffer_setup(indio_dev, 427 ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev,
428 iio_pollfunc_store_time, 428 iio_pollfunc_store_time,
429 mxc4005_trigger_handler, 429 mxc4005_trigger_handler,
430 NULL); 430 NULL);
@@ -452,7 +452,7 @@ static int mxc4005_probe(struct i2c_client *client,
452 if (ret) { 452 if (ret) {
453 dev_err(&client->dev, 453 dev_err(&client->dev,
454 "failed to init threaded irq\n"); 454 "failed to init threaded irq\n");
455 goto err_buffer_cleanup; 455 return ret;
456 } 456 }
457 457
458 data->dready_trig->dev.parent = &client->dev; 458 data->dready_trig->dev.parent = &client->dev;
@@ -460,43 +460,16 @@ static int mxc4005_probe(struct i2c_client *client,
460 iio_trigger_set_drvdata(data->dready_trig, indio_dev); 460 iio_trigger_set_drvdata(data->dready_trig, indio_dev);
461 indio_dev->trig = data->dready_trig; 461 indio_dev->trig = data->dready_trig;
462 iio_trigger_get(indio_dev->trig); 462 iio_trigger_get(indio_dev->trig);
463 ret = iio_trigger_register(data->dready_trig); 463 ret = devm_iio_trigger_register(&client->dev,
464 data->dready_trig);
464 if (ret) { 465 if (ret) {
465 dev_err(&client->dev, 466 dev_err(&client->dev,
466 "failed to register trigger\n"); 467 "failed to register trigger\n");
467 goto err_trigger_unregister; 468 return ret;
468 } 469 }
469 } 470 }
470 471
471 ret = iio_device_register(indio_dev); 472 return devm_iio_device_register(&client->dev, indio_dev);
472 if (ret < 0) {
473 dev_err(&client->dev,
474 "unable to register iio device %d\n", ret);
475 goto err_buffer_cleanup;
476 }
477
478 return 0;
479
480err_trigger_unregister:
481 iio_trigger_unregister(data->dready_trig);
482err_buffer_cleanup:
483 iio_triggered_buffer_cleanup(indio_dev);
484
485 return ret;
486}
487
488static int mxc4005_remove(struct i2c_client *client)
489{
490 struct iio_dev *indio_dev = i2c_get_clientdata(client);
491 struct mxc4005_data *data = iio_priv(indio_dev);
492
493 iio_device_unregister(indio_dev);
494
495 iio_triggered_buffer_cleanup(indio_dev);
496 if (data->dready_trig)
497 iio_trigger_unregister(data->dready_trig);
498
499 return 0;
500} 473}
501 474
502static const struct acpi_device_id mxc4005_acpi_match[] = { 475static const struct acpi_device_id mxc4005_acpi_match[] = {
@@ -517,7 +490,6 @@ static struct i2c_driver mxc4005_driver = {
517 .acpi_match_table = ACPI_PTR(mxc4005_acpi_match), 490 .acpi_match_table = ACPI_PTR(mxc4005_acpi_match),
518 }, 491 },
519 .probe = mxc4005_probe, 492 .probe = mxc4005_probe,
520 .remove = mxc4005_remove,
521 .id_table = mxc4005_id, 493 .id_table = mxc4005_id,
522}; 494};
523 495
diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
index a923f90f6e80..66d768d971e1 100644
--- a/drivers/iio/accel/sca3000.c
+++ b/drivers/iio/accel/sca3000.c
@@ -111,7 +111,7 @@
111/* Currently unsupported */ 111/* Currently unsupported */
112#define SCA3000_MD_CTRL_AND_Y BIT(3) 112#define SCA3000_MD_CTRL_AND_Y BIT(3)
113#define SCA3000_MD_CTRL_AND_X BIT(4) 113#define SCA3000_MD_CTRL_AND_X BIT(4)
114#define SAC3000_MD_CTRL_AND_Z BIT(5) 114#define SCA3000_MD_CTRL_AND_Z BIT(5)
115 115
116/* 116/*
117 * Some control registers of complex access methods requiring this register to 117 * Some control registers of complex access methods requiring this register to
diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h
index 979ab9679b99..af09943f38c9 100644
--- a/drivers/iio/accel/st_accel.h
+++ b/drivers/iio/accel/st_accel.h
@@ -68,6 +68,7 @@ static const struct st_sensors_platform_data default_accel_pdata = {
68 .drdy_int_pin = 1, 68 .drdy_int_pin = 1,
69}; 69};
70 70
71const struct st_sensor_settings *st_accel_get_settings(const char *name);
71int st_accel_common_probe(struct iio_dev *indio_dev); 72int st_accel_common_probe(struct iio_dev *indio_dev);
72void st_accel_common_remove(struct iio_dev *indio_dev); 73void st_accel_common_remove(struct iio_dev *indio_dev);
73 74
diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c
index 0205c0167cdd..9f2b40474b8e 100644
--- a/drivers/iio/accel/st_accel_buffer.c
+++ b/drivers/iio/accel/st_accel_buffer.c
@@ -29,65 +29,51 @@ int st_accel_trig_set_state(struct iio_trigger *trig, bool state)
29 return st_sensors_set_dataready_irq(indio_dev, state); 29 return st_sensors_set_dataready_irq(indio_dev, state);
30} 30}
31 31
32static int st_accel_buffer_preenable(struct iio_dev *indio_dev)
33{
34 return st_sensors_set_enable(indio_dev, true);
35}
36
37static int st_accel_buffer_postenable(struct iio_dev *indio_dev) 32static int st_accel_buffer_postenable(struct iio_dev *indio_dev)
38{ 33{
39 int err; 34 int err;
40 struct st_sensor_data *adata = iio_priv(indio_dev);
41
42 adata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
43 if (adata->buffer_data == NULL) {
44 err = -ENOMEM;
45 goto allocate_memory_error;
46 }
47 35
48 err = iio_triggered_buffer_postenable(indio_dev); 36 err = iio_triggered_buffer_postenable(indio_dev);
49 if (err < 0) 37 if (err < 0)
50 goto st_accel_buffer_postenable_error; 38 return err;
51 39
52 err = st_sensors_set_axis_enable(indio_dev, 40 err = st_sensors_set_axis_enable(indio_dev,
53 (u8)indio_dev->active_scan_mask[0]); 41 (u8)indio_dev->active_scan_mask[0]);
54 if (err < 0) 42 if (err < 0)
55 goto st_sensors_set_axis_enable_error; 43 goto st_accel_buffer_predisable;
56 44
57 return err; 45 err = st_sensors_set_enable(indio_dev, true);
46 if (err < 0)
47 goto st_accel_buffer_enable_all_axis;
58 48
59st_sensors_set_axis_enable_error: 49 return 0;
50
51st_accel_buffer_enable_all_axis:
52 st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
53st_accel_buffer_predisable:
60 iio_triggered_buffer_predisable(indio_dev); 54 iio_triggered_buffer_predisable(indio_dev);
61st_accel_buffer_postenable_error:
62 kfree(adata->buffer_data);
63allocate_memory_error:
64 return err; 55 return err;
65} 56}
66 57
67static int st_accel_buffer_predisable(struct iio_dev *indio_dev) 58static int st_accel_buffer_predisable(struct iio_dev *indio_dev)
68{ 59{
69 int err, err2; 60 int err, err2;
70 struct st_sensor_data *adata = iio_priv(indio_dev);
71
72 err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
73 if (err < 0)
74 goto st_accel_buffer_predisable_error;
75 61
76 err = st_sensors_set_enable(indio_dev, false); 62 err = st_sensors_set_enable(indio_dev, false);
77 if (err < 0) 63 if (err < 0)
78 goto st_accel_buffer_predisable_error; 64 goto st_accel_buffer_predisable;
65
66 err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
79 67
80st_accel_buffer_predisable_error: 68st_accel_buffer_predisable:
81 err2 = iio_triggered_buffer_predisable(indio_dev); 69 err2 = iio_triggered_buffer_predisable(indio_dev);
82 if (!err) 70 if (!err)
83 err = err2; 71 err = err2;
84 72
85 kfree(adata->buffer_data);
86 return err; 73 return err;
87} 74}
88 75
89static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = { 76static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = {
90 .preenable = &st_accel_buffer_preenable,
91 .postenable = &st_accel_buffer_postenable, 77 .postenable = &st_accel_buffer_postenable,
92 .predisable = &st_accel_buffer_predisable, 78 .predisable = &st_accel_buffer_predisable,
93}; 79};
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index e02b79931979..2e37f8a6d8cf 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -13,7 +13,6 @@
13#include <linux/acpi.h> 13#include <linux/acpi.h>
14#include <linux/errno.h> 14#include <linux/errno.h>
15#include <linux/types.h> 15#include <linux/types.h>
16#include <linux/mutex.h>
17#include <linux/interrupt.h> 16#include <linux/interrupt.h>
18#include <linux/i2c.h> 17#include <linux/i2c.h>
19#include <linux/gpio.h> 18#include <linux/gpio.h>
@@ -1147,32 +1146,45 @@ out:
1147#endif 1146#endif
1148} 1147}
1149 1148
1149/*
1150 * st_accel_get_settings() - get sensor settings from device name
1151 * @name: device name buffer reference.
1152 *
1153 * Return: valid reference on success, NULL otherwise.
1154 */
1155const struct st_sensor_settings *st_accel_get_settings(const char *name)
1156{
1157 int index = st_sensors_get_settings_index(name,
1158 st_accel_sensors_settings,
1159 ARRAY_SIZE(st_accel_sensors_settings));
1160 if (index < 0)
1161 return NULL;
1162
1163 return &st_accel_sensors_settings[index];
1164}
1165EXPORT_SYMBOL(st_accel_get_settings);
1166
1150int st_accel_common_probe(struct iio_dev *indio_dev) 1167int st_accel_common_probe(struct iio_dev *indio_dev)
1151{ 1168{
1152 struct st_sensor_data *adata = iio_priv(indio_dev); 1169 struct st_sensor_data *adata = iio_priv(indio_dev);
1153 struct st_sensors_platform_data *pdata = 1170 struct st_sensors_platform_data *pdata =
1154 (struct st_sensors_platform_data *)adata->dev->platform_data; 1171 (struct st_sensors_platform_data *)adata->dev->platform_data;
1155 int irq = adata->get_irq_data_ready(indio_dev);
1156 struct iio_chan_spec *channels; 1172 struct iio_chan_spec *channels;
1157 size_t channels_size; 1173 size_t channels_size;
1158 int err; 1174 int err;
1159 1175
1160 indio_dev->modes = INDIO_DIRECT_MODE; 1176 indio_dev->modes = INDIO_DIRECT_MODE;
1161 indio_dev->info = &accel_info; 1177 indio_dev->info = &accel_info;
1162 mutex_init(&adata->tb.buf_lock);
1163 1178
1164 err = st_sensors_power_enable(indio_dev); 1179 err = st_sensors_power_enable(indio_dev);
1165 if (err) 1180 if (err)
1166 return err; 1181 return err;
1167 1182
1168 err = st_sensors_check_device_support(indio_dev, 1183 err = st_sensors_verify_id(indio_dev);
1169 ARRAY_SIZE(st_accel_sensors_settings),
1170 st_accel_sensors_settings);
1171 if (err < 0) 1184 if (err < 0)
1172 goto st_accel_power_off; 1185 goto st_accel_power_off;
1173 1186
1174 adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS; 1187 adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS;
1175 adata->multiread_bit = adata->sensor_settings->multi_read_bit;
1176 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; 1188 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
1177 1189
1178 channels_size = indio_dev->num_channels * sizeof(struct iio_chan_spec); 1190 channels_size = indio_dev->num_channels * sizeof(struct iio_chan_spec);
@@ -1204,7 +1216,7 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
1204 if (err < 0) 1216 if (err < 0)
1205 goto st_accel_power_off; 1217 goto st_accel_power_off;
1206 1218
1207 if (irq > 0) { 1219 if (adata->irq > 0) {
1208 err = st_sensors_allocate_trigger(indio_dev, 1220 err = st_sensors_allocate_trigger(indio_dev,
1209 ST_ACCEL_TRIGGER_OPS); 1221 ST_ACCEL_TRIGGER_OPS);
1210 if (err < 0) 1222 if (err < 0)
@@ -1221,7 +1233,7 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
1221 return 0; 1233 return 0;
1222 1234
1223st_accel_device_register_error: 1235st_accel_device_register_error:
1224 if (irq > 0) 1236 if (adata->irq > 0)
1225 st_sensors_deallocate_trigger(indio_dev); 1237 st_sensors_deallocate_trigger(indio_dev);
1226st_accel_probe_trigger_error: 1238st_accel_probe_trigger_error:
1227 st_accel_deallocate_ring(indio_dev); 1239 st_accel_deallocate_ring(indio_dev);
@@ -1239,7 +1251,7 @@ void st_accel_common_remove(struct iio_dev *indio_dev)
1239 st_sensors_power_disable(indio_dev); 1251 st_sensors_power_disable(indio_dev);
1240 1252
1241 iio_device_unregister(indio_dev); 1253 iio_device_unregister(indio_dev);
1242 if (adata->get_irq_data_ready(indio_dev) > 0) 1254 if (adata->irq > 0)
1243 st_sensors_deallocate_trigger(indio_dev); 1255 st_sensors_deallocate_trigger(indio_dev);
1244 1256
1245 st_accel_deallocate_ring(indio_dev); 1257 st_accel_deallocate_ring(indio_dev);
diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
index c3c8f2e73c2a..50fa0fc32baa 100644
--- a/drivers/iio/accel/st_accel_i2c.c
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -150,22 +150,33 @@ MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
150 150
151static int st_accel_i2c_probe(struct i2c_client *client) 151static int st_accel_i2c_probe(struct i2c_client *client)
152{ 152{
153 struct iio_dev *indio_dev; 153 const struct st_sensor_settings *settings;
154 struct st_sensor_data *adata; 154 struct st_sensor_data *adata;
155 struct iio_dev *indio_dev;
155 const char *match; 156 const char *match;
156 int ret; 157 int ret;
157 158
159 match = device_get_match_data(&client->dev);
160 if (match)
161 strlcpy(client->name, match, sizeof(client->name));
162
163 settings = st_accel_get_settings(client->name);
164 if (!settings) {
165 dev_err(&client->dev, "device name %s not recognized.\n",
166 client->name);
167 return -ENODEV;
168 }
169
158 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata)); 170 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata));
159 if (!indio_dev) 171 if (!indio_dev)
160 return -ENOMEM; 172 return -ENOMEM;
161 173
162 adata = iio_priv(indio_dev); 174 adata = iio_priv(indio_dev);
175 adata->sensor_settings = (struct st_sensor_settings *)settings;
163 176
164 match = device_get_match_data(&client->dev); 177 ret = st_sensors_i2c_configure(indio_dev, client);
165 if (match) 178 if (ret < 0)
166 strlcpy(client->name, match, sizeof(client->name)); 179 return ret;
167
168 st_sensors_i2c_configure(indio_dev, client, adata);
169 180
170 ret = st_accel_common_probe(indio_dev); 181 ret = st_accel_common_probe(indio_dev);
171 if (ret < 0) 182 if (ret < 0)
diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c
index 474742e35d92..8af7027d5598 100644
--- a/drivers/iio/accel/st_accel_spi.c
+++ b/drivers/iio/accel/st_accel_spi.c
@@ -102,19 +102,31 @@ MODULE_DEVICE_TABLE(of, st_accel_of_match);
102 102
103static int st_accel_spi_probe(struct spi_device *spi) 103static int st_accel_spi_probe(struct spi_device *spi)
104{ 104{
105 struct iio_dev *indio_dev; 105 const struct st_sensor_settings *settings;
106 struct st_sensor_data *adata; 106 struct st_sensor_data *adata;
107 struct iio_dev *indio_dev;
107 int err; 108 int err;
108 109
110 st_sensors_of_name_probe(&spi->dev, st_accel_of_match,
111 spi->modalias, sizeof(spi->modalias));
112
113 settings = st_accel_get_settings(spi->modalias);
114 if (!settings) {
115 dev_err(&spi->dev, "device name %s not recognized.\n",
116 spi->modalias);
117 return -ENODEV;
118 }
119
109 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adata)); 120 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adata));
110 if (!indio_dev) 121 if (!indio_dev)
111 return -ENOMEM; 122 return -ENOMEM;
112 123
113 adata = iio_priv(indio_dev); 124 adata = iio_priv(indio_dev);
125 adata->sensor_settings = (struct st_sensor_settings *)settings;
114 126
115 st_sensors_of_name_probe(&spi->dev, st_accel_of_match, 127 err = st_sensors_spi_configure(indio_dev, spi);
116 spi->modalias, sizeof(spi->modalias)); 128 if (err < 0)
117 st_sensors_spi_configure(indio_dev, spi, adata); 129 return err;
118 130
119 err = st_accel_common_probe(indio_dev); 131 err = st_accel_common_probe(indio_dev);
120 if (err < 0) 132 if (err < 0)
diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
index aba0fd123a51..f5ba94c03a8d 100644
--- a/drivers/iio/adc/ad7606.c
+++ b/drivers/iio/adc/ad7606.c
@@ -35,6 +35,11 @@ static const unsigned int ad7606_scale_avail[2] = {
35 152588, 305176 35 152588, 305176
36}; 36};
37 37
38
39static const unsigned int ad7616_sw_scale_avail[3] = {
40 76293, 152588, 305176
41};
42
38static const unsigned int ad7606_oversampling_avail[7] = { 43static const unsigned int ad7606_oversampling_avail[7] = {
39 1, 2, 4, 8, 16, 32, 64, 44 1, 2, 4, 8, 16, 32, 64,
40}; 45};
@@ -55,6 +60,29 @@ static int ad7606_reset(struct ad7606_state *st)
55 return -ENODEV; 60 return -ENODEV;
56} 61}
57 62
63static int ad7606_reg_access(struct iio_dev *indio_dev,
64 unsigned int reg,
65 unsigned int writeval,
66 unsigned int *readval)
67{
68 struct ad7606_state *st = iio_priv(indio_dev);
69 int ret;
70
71 mutex_lock(&st->lock);
72 if (readval) {
73 ret = st->bops->reg_read(st, reg);
74 if (ret < 0)
75 goto err_unlock;
76 *readval = ret;
77 ret = 0;
78 } else {
79 ret = st->bops->reg_write(st, reg, writeval);
80 }
81err_unlock:
82 mutex_unlock(&st->lock);
83 return ret;
84}
85
58static int ad7606_read_samples(struct ad7606_state *st) 86static int ad7606_read_samples(struct ad7606_state *st)
59{ 87{
60 unsigned int num = st->chip_info->num_channels; 88 unsigned int num = st->chip_info->num_channels;
@@ -308,29 +336,6 @@ static const struct attribute_group ad7606_attribute_group_range = {
308 .attrs = ad7606_attributes_range, 336 .attrs = ad7606_attributes_range,
309}; 337};
310 338
311#define AD760X_CHANNEL(num, mask) { \
312 .type = IIO_VOLTAGE, \
313 .indexed = 1, \
314 .channel = num, \
315 .address = num, \
316 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
317 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
318 .info_mask_shared_by_all = mask, \
319 .scan_index = num, \
320 .scan_type = { \
321 .sign = 's', \
322 .realbits = 16, \
323 .storagebits = 16, \
324 .endianness = IIO_CPU, \
325 }, \
326}
327
328#define AD7605_CHANNEL(num) \
329 AD760X_CHANNEL(num, 0)
330
331#define AD7606_CHANNEL(num) \
332 AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO))
333
334static const struct iio_chan_spec ad7605_channels[] = { 339static const struct iio_chan_spec ad7605_channels[] = {
335 IIO_CHAN_SOFT_TIMESTAMP(4), 340 IIO_CHAN_SOFT_TIMESTAMP(4),
336 AD7605_CHANNEL(0), 341 AD7605_CHANNEL(0),
@@ -405,12 +410,19 @@ static const struct ad7606_chip_info ad7606_chip_info_tbl[] = {
405 .oversampling_avail = ad7606_oversampling_avail, 410 .oversampling_avail = ad7606_oversampling_avail,
406 .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail), 411 .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
407 }, 412 },
413 [ID_AD7606B] = {
414 .channels = ad7606_channels,
415 .num_channels = 9,
416 .oversampling_avail = ad7606_oversampling_avail,
417 .oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
418 },
408 [ID_AD7616] = { 419 [ID_AD7616] = {
409 .channels = ad7616_channels, 420 .channels = ad7616_channels,
410 .num_channels = 17, 421 .num_channels = 17,
411 .oversampling_avail = ad7616_oversampling_avail, 422 .oversampling_avail = ad7616_oversampling_avail,
412 .oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail), 423 .oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail),
413 .os_req_reset = true, 424 .os_req_reset = true,
425 .init_delay_ms = 15,
414 }, 426 },
415}; 427};
416 428
@@ -519,6 +531,14 @@ static const struct iio_info ad7606_info_os_and_range = {
519 .validate_trigger = &ad7606_validate_trigger, 531 .validate_trigger = &ad7606_validate_trigger,
520}; 532};
521 533
534static const struct iio_info ad7606_info_os_range_and_debug = {
535 .read_raw = &ad7606_read_raw,
536 .write_raw = &ad7606_write_raw,
537 .debugfs_reg_access = &ad7606_reg_access,
538 .attrs = &ad7606_attribute_group_os_and_range,
539 .validate_trigger = &ad7606_validate_trigger,
540};
541
522static const struct iio_info ad7606_info_os = { 542static const struct iio_info ad7606_info_os = {
523 .read_raw = &ad7606_read_raw, 543 .read_raw = &ad7606_read_raw,
524 .write_raw = &ad7606_write_raw, 544 .write_raw = &ad7606_write_raw,
@@ -617,35 +637,29 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
617 if (ret) 637 if (ret)
618 dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n"); 638 dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
619 639
640 /* AD7616 requires al least 15ms to reconfigure after a reset */
641 if (st->chip_info->init_delay_ms) {
642 if (msleep_interruptible(st->chip_info->init_delay_ms))
643 return -ERESTARTSYS;
644 }
645
620 st->write_scale = ad7606_write_scale_hw; 646 st->write_scale = ad7606_write_scale_hw;
621 st->write_os = ad7606_write_os_hw; 647 st->write_os = ad7606_write_os_hw;
622 648
623 if (st->chip_info->sw_mode_config) 649 if (st->bops->sw_mode_config)
624 st->sw_mode_en = device_property_present(st->dev, 650 st->sw_mode_en = device_property_present(st->dev,
625 "adi,sw-mode"); 651 "adi,sw-mode");
626 652
627 if (st->sw_mode_en) { 653 if (st->sw_mode_en) {
654 /* Scale of 0.076293 is only available in sw mode */
655 st->scale_avail = ad7616_sw_scale_avail;
656 st->num_scales = ARRAY_SIZE(ad7616_sw_scale_avail);
657
628 /* After reset, in software mode, ±10 V is set by default */ 658 /* After reset, in software mode, ±10 V is set by default */
629 memset32(st->range, 2, ARRAY_SIZE(st->range)); 659 memset32(st->range, 2, ARRAY_SIZE(st->range));
630 indio_dev->info = &ad7606_info_os_and_range; 660 indio_dev->info = &ad7606_info_os_range_and_debug;
631 661
632 /* 662 ret = st->bops->sw_mode_config(indio_dev);
633 * In software mode, the range gpio has no longer its function.
634 * Instead, the scale can be configured individually for each
635 * channel from the range registers.
636 */
637 if (st->chip_info->write_scale_sw)
638 st->write_scale = st->chip_info->write_scale_sw;
639
640 /*
641 * In software mode, the oversampling is no longer configured
642 * with GPIO pins. Instead, the oversampling can be configured
643 * in configuratiion register.
644 */
645 if (st->chip_info->write_os_sw)
646 st->write_os = st->chip_info->write_os_sw;
647
648 ret = st->chip_info->sw_mode_config(indio_dev);
649 if (ret < 0) 663 if (ret < 0)
650 return ret; 664 return ret;
651 } 665 }
diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
index d8a509c2c428..9350ef1f63b5 100644
--- a/drivers/iio/adc/ad7606.h
+++ b/drivers/iio/adc/ad7606.h
@@ -8,6 +8,36 @@
8#ifndef IIO_ADC_AD7606_H_ 8#ifndef IIO_ADC_AD7606_H_
9#define IIO_ADC_AD7606_H_ 9#define IIO_ADC_AD7606_H_
10 10
11#define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all) { \
12 .type = IIO_VOLTAGE, \
13 .indexed = 1, \
14 .channel = num, \
15 .address = num, \
16 .info_mask_separate = mask_sep, \
17 .info_mask_shared_by_type = mask_type, \
18 .info_mask_shared_by_all = mask_all, \
19 .scan_index = num, \
20 .scan_type = { \
21 .sign = 's', \
22 .realbits = 16, \
23 .storagebits = 16, \
24 .endianness = IIO_CPU, \
25 }, \
26}
27
28#define AD7605_CHANNEL(num) \
29 AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \
30 BIT(IIO_CHAN_INFO_SCALE), 0)
31
32#define AD7606_CHANNEL(num) \
33 AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \
34 BIT(IIO_CHAN_INFO_SCALE), \
35 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO))
36
37#define AD7616_CHANNEL(num) \
38 AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),\
39 0, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO))
40
11/** 41/**
12 * struct ad7606_chip_info - chip specific information 42 * struct ad7606_chip_info - chip specific information
13 * @channels: channel specification 43 * @channels: channel specification
@@ -16,12 +46,8 @@
16 * oversampling ratios. 46 * oversampling ratios.
17 * @oversampling_num number of elements stored in oversampling_avail array 47 * @oversampling_num number of elements stored in oversampling_avail array
18 * @os_req_reset some devices require a reset to update oversampling 48 * @os_req_reset some devices require a reset to update oversampling
19 * @write_scale_sw pointer to the function which writes the scale via spi 49 * @init_delay_ms required delay in miliseconds for initialization
20 in software mode 50 * after a restart
21 * @write_os_sw pointer to the function which writes the os via spi
22 in software mode
23 * @sw_mode_config: pointer to a function which configured the device
24 * for software mode
25 */ 51 */
26struct ad7606_chip_info { 52struct ad7606_chip_info {
27 const struct iio_chan_spec *channels; 53 const struct iio_chan_spec *channels;
@@ -29,9 +55,7 @@ struct ad7606_chip_info {
29 const unsigned int *oversampling_avail; 55 const unsigned int *oversampling_avail;
30 unsigned int oversampling_num; 56 unsigned int oversampling_num;
31 bool os_req_reset; 57 bool os_req_reset;
32 int (*write_scale_sw)(struct iio_dev *indio_dev, int ch, int val); 58 unsigned long init_delay_ms;
33 int (*write_os_sw)(struct iio_dev *indio_dev, int val);
34 int (*sw_mode_config)(struct iio_dev *indio_dev);
35}; 59};
36 60
37/** 61/**
@@ -63,6 +87,7 @@ struct ad7606_chip_info {
63 * @complete completion to indicate end of conversion 87 * @complete completion to indicate end of conversion
64 * @trig The IIO trigger associated with the device. 88 * @trig The IIO trigger associated with the device.
65 * @data buffer for reading data from the device 89 * @data buffer for reading data from the device
90 * @d16 be16 buffer for reading data from the device
66 */ 91 */
67struct ad7606_state { 92struct ad7606_state {
68 struct device *dev; 93 struct device *dev;
@@ -96,15 +121,32 @@ struct ad7606_state {
96 * 16 * 16-bit samples + 64-bit timestamp 121 * 16 * 16-bit samples + 64-bit timestamp
97 */ 122 */
98 unsigned short data[20] ____cacheline_aligned; 123 unsigned short data[20] ____cacheline_aligned;
124 __be16 d16[2];
99}; 125};
100 126
101/** 127/**
102 * struct ad7606_bus_ops - driver bus operations 128 * struct ad7606_bus_ops - driver bus operations
103 * @read_block function pointer for reading blocks of data 129 * @read_block function pointer for reading blocks of data
130 * @sw_mode_config: pointer to a function which configured the device
131 * for software mode
132 * @reg_read function pointer for reading spi register
133 * @reg_write function pointer for writing spi register
134 * @write_mask function pointer for write spi register with mask
135 * @rd_wr_cmd pointer to the function which calculates the spi address
104 */ 136 */
105struct ad7606_bus_ops { 137struct ad7606_bus_ops {
106 /* more methods added in future? */ 138 /* more methods added in future? */
107 int (*read_block)(struct device *dev, int num, void *data); 139 int (*read_block)(struct device *dev, int num, void *data);
140 int (*sw_mode_config)(struct iio_dev *indio_dev);
141 int (*reg_read)(struct ad7606_state *st, unsigned int addr);
142 int (*reg_write)(struct ad7606_state *st,
143 unsigned int addr,
144 unsigned int val);
145 int (*write_mask)(struct ad7606_state *st,
146 unsigned int addr,
147 unsigned long mask,
148 unsigned int val);
149 u16 (*rd_wr_cmd)(int addr, char isWriteOp);
108}; 150};
109 151
110int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, 152int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
@@ -116,6 +158,7 @@ enum ad7606_supported_device_ids {
116 ID_AD7606_8, 158 ID_AD7606_8,
117 ID_AD7606_6, 159 ID_AD7606_6,
118 ID_AD7606_4, 160 ID_AD7606_4,
161 ID_AD7606B,
119 ID_AD7616, 162 ID_AD7616,
120}; 163};
121 164
diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c
index 1b08028facde..f732b3ac7878 100644
--- a/drivers/iio/adc/ad7606_par.c
+++ b/drivers/iio/adc/ad7606_par.c
@@ -53,10 +53,8 @@ static int ad7606_par_probe(struct platform_device *pdev)
53 int irq; 53 int irq;
54 54
55 irq = platform_get_irq(pdev, 0); 55 irq = platform_get_irq(pdev, 0);
56 if (irq < 0) { 56 if (irq < 0)
57 dev_err(&pdev->dev, "no irq: %d\n", irq);
58 return irq; 57 return irq;
59 }
60 58
61 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 59 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
62 addr = devm_ioremap_resource(&pdev->dev, res); 60 addr = devm_ioremap_resource(&pdev->dev, res);
diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c
index b7faef69a58f..29945ad07dca 100644
--- a/drivers/iio/adc/ad7606_spi.c
+++ b/drivers/iio/adc/ad7606_spi.c
@@ -15,6 +15,91 @@
15 15
16#define MAX_SPI_FREQ_HZ 23500000 /* VDRIVE above 4.75 V */ 16#define MAX_SPI_FREQ_HZ 23500000 /* VDRIVE above 4.75 V */
17 17
18#define AD7616_CONFIGURATION_REGISTER 0x02
19#define AD7616_OS_MASK GENMASK(4, 2)
20#define AD7616_BURST_MODE BIT(6)
21#define AD7616_SEQEN_MODE BIT(5)
22#define AD7616_RANGE_CH_A_ADDR_OFF 0x04
23#define AD7616_RANGE_CH_B_ADDR_OFF 0x06
24/*
25 * Range of channels from a group are stored in 2 registers.
26 * 0, 1, 2, 3 in a register followed by 4, 5, 6, 7 in second register.
27 * For channels from second group(8-15) the order is the same, only with
28 * an offset of 2 for register address.
29 */
30#define AD7616_RANGE_CH_ADDR(ch) ((ch) >> 2)
31/* The range of the channel is stored in 2 bits */
32#define AD7616_RANGE_CH_MSK(ch) (0b11 << (((ch) & 0b11) * 2))
33#define AD7616_RANGE_CH_MODE(ch, mode) ((mode) << ((((ch) & 0b11)) * 2))
34
35#define AD7606_CONFIGURATION_REGISTER 0x02
36#define AD7606_SINGLE_DOUT 0x00
37
38/*
39 * Range for AD7606B channels are stored in registers starting with address 0x3.
40 * Each register stores range for 2 channels(4 bits per channel).
41 */
42#define AD7606_RANGE_CH_MSK(ch) (GENMASK(3, 0) << (4 * ((ch) & 0x1)))
43#define AD7606_RANGE_CH_MODE(ch, mode) \
44 ((GENMASK(3, 0) & mode) << (4 * ((ch) & 0x1)))
45#define AD7606_RANGE_CH_ADDR(ch) (0x03 + ((ch) >> 1))
46#define AD7606_OS_MODE 0x08
47
48static const struct iio_chan_spec ad7616_sw_channels[] = {
49 IIO_CHAN_SOFT_TIMESTAMP(16),
50 AD7616_CHANNEL(0),
51 AD7616_CHANNEL(1),
52 AD7616_CHANNEL(2),
53 AD7616_CHANNEL(3),
54 AD7616_CHANNEL(4),
55 AD7616_CHANNEL(5),
56 AD7616_CHANNEL(6),
57 AD7616_CHANNEL(7),
58 AD7616_CHANNEL(8),
59 AD7616_CHANNEL(9),
60 AD7616_CHANNEL(10),
61 AD7616_CHANNEL(11),
62 AD7616_CHANNEL(12),
63 AD7616_CHANNEL(13),
64 AD7616_CHANNEL(14),
65 AD7616_CHANNEL(15),
66};
67
68static const struct iio_chan_spec ad7606b_sw_channels[] = {
69 IIO_CHAN_SOFT_TIMESTAMP(8),
70 AD7616_CHANNEL(0),
71 AD7616_CHANNEL(1),
72 AD7616_CHANNEL(2),
73 AD7616_CHANNEL(3),
74 AD7616_CHANNEL(4),
75 AD7616_CHANNEL(5),
76 AD7616_CHANNEL(6),
77 AD7616_CHANNEL(7),
78};
79
80static const unsigned int ad7606B_oversampling_avail[9] = {
81 1, 2, 4, 8, 16, 32, 64, 128, 256
82};
83
84static u16 ad7616_spi_rd_wr_cmd(int addr, char isWriteOp)
85{
86 /*
87 * The address of register consist of one w/r bit
88 * 6 bits of address followed by one reserved bit.
89 */
90 return ((addr & 0x7F) << 1) | ((isWriteOp & 0x1) << 7);
91}
92
93static u16 ad7606B_spi_rd_wr_cmd(int addr, char is_write_op)
94{
95 /*
96 * The address of register consists of one bit which
97 * specifies a read command placed in bit 6, followed by
98 * 6 bits of address.
99 */
100 return (addr & 0x3F) | (((~is_write_op) & 0x1) << 6);
101}
102
18static int ad7606_spi_read_block(struct device *dev, 103static int ad7606_spi_read_block(struct device *dev,
19 int count, void *buf) 104 int count, void *buf)
20{ 105{
@@ -35,17 +120,210 @@ static int ad7606_spi_read_block(struct device *dev,
35 return 0; 120 return 0;
36} 121}
37 122
123static int ad7606_spi_reg_read(struct ad7606_state *st, unsigned int addr)
124{
125 struct spi_device *spi = to_spi_device(st->dev);
126 struct spi_transfer t[] = {
127 {
128 .tx_buf = &st->d16[0],
129 .len = 2,
130 .cs_change = 0,
131 }, {
132 .rx_buf = &st->d16[1],
133 .len = 2,
134 },
135 };
136 int ret;
137
138 st->d16[0] = cpu_to_be16(st->bops->rd_wr_cmd(addr, 0) << 8);
139
140 ret = spi_sync_transfer(spi, t, ARRAY_SIZE(t));
141 if (ret < 0)
142 return ret;
143
144 return be16_to_cpu(st->d16[1]);
145}
146
147static int ad7606_spi_reg_write(struct ad7606_state *st,
148 unsigned int addr,
149 unsigned int val)
150{
151 struct spi_device *spi = to_spi_device(st->dev);
152
153 st->d16[0] = cpu_to_be16((st->bops->rd_wr_cmd(addr, 1) << 8) |
154 (val & 0x1FF));
155
156 return spi_write(spi, &st->d16[0], sizeof(st->d16[0]));
157}
158
159static int ad7606_spi_write_mask(struct ad7606_state *st,
160 unsigned int addr,
161 unsigned long mask,
162 unsigned int val)
163{
164 int readval;
165
166 readval = st->bops->reg_read(st, addr);
167 if (readval < 0)
168 return readval;
169
170 readval &= ~mask;
171 readval |= val;
172
173 return st->bops->reg_write(st, addr, readval);
174}
175
176static int ad7616_write_scale_sw(struct iio_dev *indio_dev, int ch, int val)
177{
178 struct ad7606_state *st = iio_priv(indio_dev);
179 unsigned int ch_addr, mode, ch_index;
180
181
182 /*
183 * Ad7616 has 16 channels divided in group A and group B.
184 * The range of channels from A are stored in registers with address 4
185 * while channels from B are stored in register with address 6.
186 * The last bit from channels determines if it is from group A or B
187 * because the order of channels in iio is 0A, 0B, 1A, 1B...
188 */
189 ch_index = ch >> 1;
190
191 ch_addr = AD7616_RANGE_CH_ADDR(ch_index);
192
193 if ((ch & 0x1) == 0) /* channel A */
194 ch_addr += AD7616_RANGE_CH_A_ADDR_OFF;
195 else /* channel B */
196 ch_addr += AD7616_RANGE_CH_B_ADDR_OFF;
197
198 /* 0b01 for 2.5v, 0b10 for 5v and 0b11 for 10v */
199 mode = AD7616_RANGE_CH_MODE(ch_index, ((val + 1) & 0b11));
200 return st->bops->write_mask(st, ch_addr, AD7616_RANGE_CH_MSK(ch_index),
201 mode);
202}
203
204static int ad7616_write_os_sw(struct iio_dev *indio_dev, int val)
205{
206 struct ad7606_state *st = iio_priv(indio_dev);
207
208 return st->bops->write_mask(st, AD7616_CONFIGURATION_REGISTER,
209 AD7616_OS_MASK, val << 2);
210}
211
212static int ad7606_write_scale_sw(struct iio_dev *indio_dev, int ch, int val)
213{
214 struct ad7606_state *st = iio_priv(indio_dev);
215
216 return ad7606_spi_write_mask(st,
217 AD7606_RANGE_CH_ADDR(ch),
218 AD7606_RANGE_CH_MSK(ch),
219 AD7606_RANGE_CH_MODE(ch, val));
220}
221
222static int ad7606_write_os_sw(struct iio_dev *indio_dev, int val)
223{
224 struct ad7606_state *st = iio_priv(indio_dev);
225
226 return ad7606_spi_reg_write(st, AD7606_OS_MODE, val);
227}
228
229static int ad7616_sw_mode_config(struct iio_dev *indio_dev)
230{
231 struct ad7606_state *st = iio_priv(indio_dev);
232
233 /*
234 * Scale can be configured individually for each channel
235 * in software mode.
236 */
237 indio_dev->channels = ad7616_sw_channels;
238
239 st->write_scale = ad7616_write_scale_sw;
240 st->write_os = &ad7616_write_os_sw;
241
242 /* Activate Burst mode and SEQEN MODE */
243 return st->bops->write_mask(st,
244 AD7616_CONFIGURATION_REGISTER,
245 AD7616_BURST_MODE | AD7616_SEQEN_MODE,
246 AD7616_BURST_MODE | AD7616_SEQEN_MODE);
247}
248
249static int ad7606B_sw_mode_config(struct iio_dev *indio_dev)
250{
251 struct ad7606_state *st = iio_priv(indio_dev);
252 unsigned long os[3] = {1};
253
254 /*
255 * Software mode is enabled when all three oversampling
256 * pins are set to high. If oversampling gpios are defined
257 * in the device tree, then they need to be set to high,
258 * otherwise, they must be hardwired to VDD
259 */
260 if (st->gpio_os) {
261 gpiod_set_array_value(ARRAY_SIZE(os),
262 st->gpio_os->desc, st->gpio_os->info, os);
263 }
264 /* OS of 128 and 256 are available only in software mode */
265 st->oversampling_avail = ad7606B_oversampling_avail;
266 st->num_os_ratios = ARRAY_SIZE(ad7606B_oversampling_avail);
267
268 st->write_scale = ad7606_write_scale_sw;
269 st->write_os = &ad7606_write_os_sw;
270
271 /* Configure device spi to output on a single channel */
272 st->bops->reg_write(st,
273 AD7606_CONFIGURATION_REGISTER,
274 AD7606_SINGLE_DOUT);
275
276 /*
277 * Scale can be configured individually for each channel
278 * in software mode.
279 */
280 indio_dev->channels = ad7606b_sw_channels;
281
282 return 0;
283}
284
38static const struct ad7606_bus_ops ad7606_spi_bops = { 285static const struct ad7606_bus_ops ad7606_spi_bops = {
39 .read_block = ad7606_spi_read_block, 286 .read_block = ad7606_spi_read_block,
40}; 287};
41 288
289static const struct ad7606_bus_ops ad7616_spi_bops = {
290 .read_block = ad7606_spi_read_block,
291 .reg_read = ad7606_spi_reg_read,
292 .reg_write = ad7606_spi_reg_write,
293 .write_mask = ad7606_spi_write_mask,
294 .rd_wr_cmd = ad7616_spi_rd_wr_cmd,
295 .sw_mode_config = ad7616_sw_mode_config,
296};
297
298static const struct ad7606_bus_ops ad7606B_spi_bops = {
299 .read_block = ad7606_spi_read_block,
300 .reg_read = ad7606_spi_reg_read,
301 .reg_write = ad7606_spi_reg_write,
302 .write_mask = ad7606_spi_write_mask,
303 .rd_wr_cmd = ad7606B_spi_rd_wr_cmd,
304 .sw_mode_config = ad7606B_sw_mode_config,
305};
306
42static int ad7606_spi_probe(struct spi_device *spi) 307static int ad7606_spi_probe(struct spi_device *spi)
43{ 308{
44 const struct spi_device_id *id = spi_get_device_id(spi); 309 const struct spi_device_id *id = spi_get_device_id(spi);
310 const struct ad7606_bus_ops *bops;
311
312 switch (id->driver_data) {
313 case ID_AD7616:
314 bops = &ad7616_spi_bops;
315 break;
316 case ID_AD7606B:
317 bops = &ad7606B_spi_bops;
318 break;
319 default:
320 bops = &ad7606_spi_bops;
321 break;
322 }
45 323
46 return ad7606_probe(&spi->dev, spi->irq, NULL, 324 return ad7606_probe(&spi->dev, spi->irq, NULL,
47 id->name, id->driver_data, 325 id->name, id->driver_data,
48 &ad7606_spi_bops); 326 bops);
49} 327}
50 328
51static const struct spi_device_id ad7606_id_table[] = { 329static const struct spi_device_id ad7606_id_table[] = {
@@ -53,6 +331,7 @@ static const struct spi_device_id ad7606_id_table[] = {
53 { "ad7606-4", ID_AD7606_4 }, 331 { "ad7606-4", ID_AD7606_4 },
54 { "ad7606-6", ID_AD7606_6 }, 332 { "ad7606-6", ID_AD7606_6 },
55 { "ad7606-8", ID_AD7606_8 }, 333 { "ad7606-8", ID_AD7606_8 },
334 { "ad7606b", ID_AD7606B },
56 { "ad7616", ID_AD7616 }, 335 { "ad7616", ID_AD7616 },
57 {} 336 {}
58}; 337};
@@ -63,6 +342,7 @@ static const struct of_device_id ad7606_of_match[] = {
63 { .compatible = "adi,ad7606-4" }, 342 { .compatible = "adi,ad7606-4" },
64 { .compatible = "adi,ad7606-6" }, 343 { .compatible = "adi,ad7606-6" },
65 { .compatible = "adi,ad7606-8" }, 344 { .compatible = "adi,ad7606-8" },
345 { .compatible = "adi,ad7606b" },
66 { .compatible = "adi,ad7616" }, 346 { .compatible = "adi,ad7616" },
67 { }, 347 { },
68}; 348};
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 32f1c4a33b20..abe99856c823 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -1179,10 +1179,8 @@ static int at91_adc_probe(struct platform_device *pdev)
1179 idev->info = &at91_adc_info; 1179 idev->info = &at91_adc_info;
1180 1180
1181 st->irq = platform_get_irq(pdev, 0); 1181 st->irq = platform_get_irq(pdev, 0);
1182 if (st->irq < 0) { 1182 if (st->irq < 0)
1183 dev_err(&pdev->dev, "No IRQ ID is designated\n");
1184 return -ENODEV; 1183 return -ENODEV;
1185 }
1186 1184
1187 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1185 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1188 1186
diff --git a/drivers/iio/adc/axp288_adc.c b/drivers/iio/adc/axp288_adc.c
index 31d51bcc5f2c..adc9cf7a075d 100644
--- a/drivers/iio/adc/axp288_adc.c
+++ b/drivers/iio/adc/axp288_adc.c
@@ -225,10 +225,8 @@ static int axp288_adc_probe(struct platform_device *pdev)
225 225
226 info = iio_priv(indio_dev); 226 info = iio_priv(indio_dev);
227 info->irq = platform_get_irq(pdev, 0); 227 info->irq = platform_get_irq(pdev, 0);
228 if (info->irq < 0) { 228 if (info->irq < 0)
229 dev_err(&pdev->dev, "no irq resource?\n");
230 return info->irq; 229 return info->irq;
231 }
232 platform_set_drvdata(pdev, indio_dev); 230 platform_set_drvdata(pdev, indio_dev);
233 info->regmap = axp20x->regmap; 231 info->regmap = axp20x->regmap;
234 /* 232 /*
diff --git a/drivers/iio/adc/bcm_iproc_adc.c b/drivers/iio/adc/bcm_iproc_adc.c
index c46c0aa15376..646ebdc0a8b4 100644
--- a/drivers/iio/adc/bcm_iproc_adc.c
+++ b/drivers/iio/adc/bcm_iproc_adc.c
@@ -540,11 +540,8 @@ static int iproc_adc_probe(struct platform_device *pdev)
540 } 540 }
541 541
542 adc_priv->irqno = platform_get_irq(pdev, 0); 542 adc_priv->irqno = platform_get_irq(pdev, 0);
543 if (adc_priv->irqno <= 0) { 543 if (adc_priv->irqno <= 0)
544 dev_err(&pdev->dev, "platform_get_irq failed\n"); 544 return -ENODEV;
545 ret = -ENODEV;
546 return ret;
547 }
548 545
549 ret = regmap_update_bits(adc_priv->regmap, IPROC_REGCTL2, 546 ret = regmap_update_bits(adc_priv->regmap, IPROC_REGCTL2,
550 IPROC_ADC_AUXIN_SCAN_ENA, 0); 547 IPROC_ADC_AUXIN_SCAN_ENA, 0);
diff --git a/drivers/iio/adc/da9150-gpadc.c b/drivers/iio/adc/da9150-gpadc.c
index 354433996101..ae8bcc32f63d 100644
--- a/drivers/iio/adc/da9150-gpadc.c
+++ b/drivers/iio/adc/da9150-gpadc.c
@@ -337,10 +337,8 @@ static int da9150_gpadc_probe(struct platform_device *pdev)
337 init_completion(&gpadc->complete); 337 init_completion(&gpadc->complete);
338 338
339 irq = platform_get_irq_byname(pdev, "GPADC"); 339 irq = platform_get_irq_byname(pdev, "GPADC");
340 if (irq < 0) { 340 if (irq < 0)
341 dev_err(dev, "Failed to get IRQ: %d\n", irq);
342 return irq; 341 return irq;
343 }
344 342
345 ret = devm_request_threaded_irq(dev, irq, NULL, da9150_gpadc_irq, 343 ret = devm_request_threaded_irq(dev, irq, NULL, da9150_gpadc_irq,
346 IRQF_ONESHOT, "GPADC", gpadc); 344 IRQF_ONESHOT, "GPADC", gpadc);
diff --git a/drivers/iio/adc/envelope-detector.c b/drivers/iio/adc/envelope-detector.c
index 2f2b563c1162..28f3d6758eb5 100644
--- a/drivers/iio/adc/envelope-detector.c
+++ b/drivers/iio/adc/envelope-detector.c
@@ -357,11 +357,8 @@ static int envelope_detector_probe(struct platform_device *pdev)
357 } 357 }
358 358
359 env->comp_irq = platform_get_irq_byname(pdev, "comp"); 359 env->comp_irq = platform_get_irq_byname(pdev, "comp");
360 if (env->comp_irq < 0) { 360 if (env->comp_irq < 0)
361 if (env->comp_irq != -EPROBE_DEFER)
362 dev_err(dev, "failed to get compare interrupt\n");
363 return env->comp_irq; 361 return env->comp_irq;
364 }
365 362
366 ret = devm_request_irq(dev, env->comp_irq, envelope_detector_comp_isr, 363 ret = devm_request_irq(dev, env->comp_irq, envelope_detector_comp_isr,
367 0, "envelope-detector", env); 364 0, "envelope-detector", env);
diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index d4c3ece21679..42a3ced11fbd 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -805,10 +805,8 @@ static int exynos_adc_probe(struct platform_device *pdev)
805 } 805 }
806 806
807 irq = platform_get_irq(pdev, 0); 807 irq = platform_get_irq(pdev, 0);
808 if (irq < 0) { 808 if (irq < 0)
809 dev_err(&pdev->dev, "no irq resource?\n");
810 return irq; 809 return irq;
811 }
812 info->irq = irq; 810 info->irq = irq;
813 811
814 irq = platform_get_irq(pdev, 1); 812 irq = platform_get_irq(pdev, 1);
diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c
index df19ecae52f7..fa71489195c6 100644
--- a/drivers/iio/adc/fsl-imx25-gcq.c
+++ b/drivers/iio/adc/fsl-imx25-gcq.c
@@ -340,7 +340,6 @@ static int mx25_gcq_probe(struct platform_device *pdev)
340 340
341 priv->irq = platform_get_irq(pdev, 0); 341 priv->irq = platform_get_irq(pdev, 0);
342 if (priv->irq <= 0) { 342 if (priv->irq <= 0) {
343 dev_err(dev, "Failed to get IRQ\n");
344 ret = priv->irq; 343 ret = priv->irq;
345 if (!ret) 344 if (!ret)
346 ret = -ENXIO; 345 ret = -ENXIO;
diff --git a/drivers/iio/adc/hi8435.c b/drivers/iio/adc/hi8435.c
index 35951c47004e..8da45bf36d36 100644
--- a/drivers/iio/adc/hi8435.c
+++ b/drivers/iio/adc/hi8435.c
@@ -456,6 +456,11 @@ err_read:
456 return IRQ_HANDLED; 456 return IRQ_HANDLED;
457} 457}
458 458
459static void hi8435_triggered_event_cleanup(void *data)
460{
461 iio_triggered_event_cleanup(data);
462}
463
459static int hi8435_probe(struct spi_device *spi) 464static int hi8435_probe(struct spi_device *spi)
460{ 465{
461 struct iio_dev *idev; 466 struct iio_dev *idev;
@@ -477,7 +482,7 @@ static int hi8435_probe(struct spi_device *spi)
477 hi8435_writeb(priv, HI8435_CTRL_REG, 0); 482 hi8435_writeb(priv, HI8435_CTRL_REG, 0);
478 } else { 483 } else {
479 udelay(5); 484 udelay(5);
480 gpiod_set_value(reset_gpio, 1); 485 gpiod_set_value_cansleep(reset_gpio, 1);
481 } 486 }
482 487
483 spi_set_drvdata(spi, idev); 488 spi_set_drvdata(spi, idev);
@@ -513,27 +518,13 @@ static int hi8435_probe(struct spi_device *spi)
513 if (ret) 518 if (ret)
514 return ret; 519 return ret;
515 520
516 ret = iio_device_register(idev); 521 ret = devm_add_action_or_reset(&spi->dev,
517 if (ret < 0) { 522 hi8435_triggered_event_cleanup,
518 dev_err(&spi->dev, "unable to register device\n"); 523 idev);
519 goto unregister_triggered_event; 524 if (ret)
520 } 525 return ret;
521
522 return 0;
523
524unregister_triggered_event:
525 iio_triggered_event_cleanup(idev);
526 return ret;
527}
528
529static int hi8435_remove(struct spi_device *spi)
530{
531 struct iio_dev *idev = spi_get_drvdata(spi);
532
533 iio_device_unregister(idev);
534 iio_triggered_event_cleanup(idev);
535 526
536 return 0; 527 return devm_iio_device_register(&spi->dev, idev);
537} 528}
538 529
539static const struct of_device_id hi8435_dt_ids[] = { 530static const struct of_device_id hi8435_dt_ids[] = {
@@ -554,7 +545,6 @@ static struct spi_driver hi8435_driver = {
554 .of_match_table = of_match_ptr(hi8435_dt_ids), 545 .of_match_table = of_match_ptr(hi8435_dt_ids),
555 }, 546 },
556 .probe = hi8435_probe, 547 .probe = hi8435_probe,
557 .remove = hi8435_remove,
558 .id_table = hi8435_id, 548 .id_table = hi8435_id,
559}; 549};
560module_spi_driver(hi8435_driver); 550module_spi_driver(hi8435_driver);
diff --git a/drivers/iio/adc/imx7d_adc.c b/drivers/iio/adc/imx7d_adc.c
index 26a7bbe4d534..2a2fbf788e95 100644
--- a/drivers/iio/adc/imx7d_adc.c
+++ b/drivers/iio/adc/imx7d_adc.c
@@ -492,10 +492,8 @@ static int imx7d_adc_probe(struct platform_device *pdev)
492 return PTR_ERR(info->regs); 492 return PTR_ERR(info->regs);
493 493
494 irq = platform_get_irq(pdev, 0); 494 irq = platform_get_irq(pdev, 0);
495 if (irq < 0) { 495 if (irq < 0)
496 dev_err(dev, "No irq resource?\n");
497 return irq; 496 return irq;
498 }
499 497
500 info->clk = devm_clk_get(dev, "adc"); 498 info->clk = devm_clk_get(dev, "adc");
501 if (IS_ERR(info->clk)) { 499 if (IS_ERR(info->clk)) {
diff --git a/drivers/iio/adc/lpc32xx_adc.c b/drivers/iio/adc/lpc32xx_adc.c
index a6ee1c3a9064..b896f7ff4572 100644
--- a/drivers/iio/adc/lpc32xx_adc.c
+++ b/drivers/iio/adc/lpc32xx_adc.c
@@ -172,10 +172,8 @@ static int lpc32xx_adc_probe(struct platform_device *pdev)
172 } 172 }
173 173
174 irq = platform_get_irq(pdev, 0); 174 irq = platform_get_irq(pdev, 0);
175 if (irq <= 0) { 175 if (irq <= 0)
176 dev_err(&pdev->dev, "failed getting interrupt resource\n");
177 return -ENXIO; 176 return -ENXIO;
178 }
179 177
180 retval = devm_request_irq(&pdev->dev, irq, lpc32xx_adc_isr, 0, 178 retval = devm_request_irq(&pdev->dev, irq, lpc32xx_adc_isr, 0,
181 LPC32XXAD_NAME, st); 179 LPC32XXAD_NAME, st);
diff --git a/drivers/iio/adc/max1027.c b/drivers/iio/adc/max1027.c
index da84adfdb819..214883458582 100644
--- a/drivers/iio/adc/max1027.c
+++ b/drivers/iio/adc/max1027.c
@@ -427,8 +427,9 @@ static int max1027_probe(struct spi_device *spi)
427 return -ENOMEM; 427 return -ENOMEM;
428 } 428 }
429 429
430 ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, 430 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev,
431 &max1027_trigger_handler, NULL); 431 &iio_pollfunc_store_time,
432 &max1027_trigger_handler, NULL);
432 if (ret < 0) { 433 if (ret < 0) {
433 dev_err(&indio_dev->dev, "Failed to setup buffer\n"); 434 dev_err(&indio_dev->dev, "Failed to setup buffer\n");
434 return ret; 435 return ret;
@@ -439,7 +440,7 @@ static int max1027_probe(struct spi_device *spi)
439 if (st->trig == NULL) { 440 if (st->trig == NULL) {
440 ret = -ENOMEM; 441 ret = -ENOMEM;
441 dev_err(&indio_dev->dev, "Failed to allocate iio trigger\n"); 442 dev_err(&indio_dev->dev, "Failed to allocate iio trigger\n");
442 goto fail_trigger_alloc; 443 return ret;
443 } 444 }
444 445
445 st->trig->ops = &max1027_trigger_ops; 446 st->trig->ops = &max1027_trigger_ops;
@@ -454,7 +455,7 @@ static int max1027_probe(struct spi_device *spi)
454 spi->dev.driver->name, st->trig); 455 spi->dev.driver->name, st->trig);
455 if (ret < 0) { 456 if (ret < 0) {
456 dev_err(&indio_dev->dev, "Failed to allocate IRQ.\n"); 457 dev_err(&indio_dev->dev, "Failed to allocate IRQ.\n");
457 goto fail_dev_register; 458 return ret;
458 } 459 }
459 460
460 /* Disable averaging */ 461 /* Disable averaging */
@@ -462,34 +463,10 @@ static int max1027_probe(struct spi_device *spi)
462 ret = spi_write(st->spi, &st->reg, 1); 463 ret = spi_write(st->spi, &st->reg, 1);
463 if (ret < 0) { 464 if (ret < 0) {
464 dev_err(&indio_dev->dev, "Failed to configure averaging register\n"); 465 dev_err(&indio_dev->dev, "Failed to configure averaging register\n");
465 goto fail_dev_register; 466 return ret;
466 }
467
468 ret = iio_device_register(indio_dev);
469 if (ret < 0) {
470 dev_err(&indio_dev->dev, "Failed to register iio device\n");
471 goto fail_dev_register;
472 } 467 }
473 468
474 return 0; 469 return devm_iio_device_register(&spi->dev, indio_dev);
475
476fail_dev_register:
477fail_trigger_alloc:
478 iio_triggered_buffer_cleanup(indio_dev);
479
480 return ret;
481}
482
483static int max1027_remove(struct spi_device *spi)
484{
485 struct iio_dev *indio_dev = spi_get_drvdata(spi);
486
487 pr_debug("%s: remove(spi = 0x%p)\n", __func__, spi);
488
489 iio_device_unregister(indio_dev);
490 iio_triggered_buffer_cleanup(indio_dev);
491
492 return 0;
493} 470}
494 471
495static struct spi_driver max1027_driver = { 472static struct spi_driver max1027_driver = {
@@ -498,7 +475,6 @@ static struct spi_driver max1027_driver = {
498 .of_match_table = of_match_ptr(max1027_adc_dt_ids), 475 .of_match_table = of_match_ptr(max1027_adc_dt_ids),
499 }, 476 },
500 .probe = max1027_probe, 477 .probe = max1027_probe,
501 .remove = max1027_remove,
502 .id_table = max1027_id, 478 .id_table = max1027_id,
503}; 479};
504module_spi_driver(max1027_driver); 480module_spi_driver(max1027_driver);
diff --git a/drivers/iio/adc/npcm_adc.c b/drivers/iio/adc/npcm_adc.c
index 193b3b81de4d..910f3585fa54 100644
--- a/drivers/iio/adc/npcm_adc.c
+++ b/drivers/iio/adc/npcm_adc.c
@@ -225,7 +225,6 @@ static int npcm_adc_probe(struct platform_device *pdev)
225 225
226 irq = platform_get_irq(pdev, 0); 226 irq = platform_get_irq(pdev, 0);
227 if (irq <= 0) { 227 if (irq <= 0) {
228 dev_err(dev, "failed getting interrupt resource\n");
229 ret = -EINVAL; 228 ret = -EINVAL;
230 goto err_disable_clk; 229 goto err_disable_clk;
231 } 230 }
diff --git a/drivers/iio/adc/rockchip_saradc.c b/drivers/iio/adc/rockchip_saradc.c
index dd8299831e09..582ba047c4a6 100644
--- a/drivers/iio/adc/rockchip_saradc.c
+++ b/drivers/iio/adc/rockchip_saradc.c
@@ -244,10 +244,8 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
244 init_completion(&info->completion); 244 init_completion(&info->completion);
245 245
246 irq = platform_get_irq(pdev, 0); 246 irq = platform_get_irq(pdev, 0);
247 if (irq < 0) { 247 if (irq < 0)
248 dev_err(&pdev->dev, "no irq resource?\n");
249 return irq; 248 return irq;
250 }
251 249
252 ret = devm_request_irq(&pdev->dev, irq, rockchip_saradc_isr, 250 ret = devm_request_irq(&pdev->dev, irq, rockchip_saradc_isr,
253 0, dev_name(&pdev->dev), info); 251 0, dev_name(&pdev->dev), info);
diff --git a/drivers/iio/adc/sc27xx_adc.c b/drivers/iio/adc/sc27xx_adc.c
index f7f7a18904b4..a6c046575ec3 100644
--- a/drivers/iio/adc/sc27xx_adc.c
+++ b/drivers/iio/adc/sc27xx_adc.c
@@ -3,7 +3,6 @@
3 3
4#include <linux/hwspinlock.h> 4#include <linux/hwspinlock.h>
5#include <linux/iio/iio.h> 5#include <linux/iio/iio.h>
6#include <linux/interrupt.h>
7#include <linux/module.h> 6#include <linux/module.h>
8#include <linux/nvmem-consumer.h> 7#include <linux/nvmem-consumer.h>
9#include <linux/of.h> 8#include <linux/of.h>
@@ -46,14 +45,18 @@
46/* Bits definitions for SC27XX_ADC_INT_CLR registers */ 45/* Bits definitions for SC27XX_ADC_INT_CLR registers */
47#define SC27XX_ADC_IRQ_CLR BIT(0) 46#define SC27XX_ADC_IRQ_CLR BIT(0)
48 47
48/* Bits definitions for SC27XX_ADC_INT_RAW registers */
49#define SC27XX_ADC_IRQ_RAW BIT(0)
50
49/* Mask definition for SC27XX_ADC_DATA register */ 51/* Mask definition for SC27XX_ADC_DATA register */
50#define SC27XX_ADC_DATA_MASK GENMASK(11, 0) 52#define SC27XX_ADC_DATA_MASK GENMASK(11, 0)
51 53
52/* Timeout (ms) for the trylock of hardware spinlocks */ 54/* Timeout (ms) for the trylock of hardware spinlocks */
53#define SC27XX_ADC_HWLOCK_TIMEOUT 5000 55#define SC27XX_ADC_HWLOCK_TIMEOUT 5000
54 56
55/* Timeout (ms) for ADC data conversion according to ADC datasheet */ 57/* Timeout (us) for ADC data conversion according to ADC datasheet */
56#define SC27XX_ADC_RDY_TIMEOUT 100 58#define SC27XX_ADC_RDY_TIMEOUT 1000000
59#define SC27XX_ADC_POLL_RAW_STATUS 500
57 60
58/* Maximum ADC channel number */ 61/* Maximum ADC channel number */
59#define SC27XX_ADC_CHANNEL_MAX 32 62#define SC27XX_ADC_CHANNEL_MAX 32
@@ -72,10 +75,8 @@ struct sc27xx_adc_data {
72 * subsystems which will access the unique ADC controller. 75 * subsystems which will access the unique ADC controller.
73 */ 76 */
74 struct hwspinlock *hwlock; 77 struct hwspinlock *hwlock;
75 struct completion completion;
76 int channel_scale[SC27XX_ADC_CHANNEL_MAX]; 78 int channel_scale[SC27XX_ADC_CHANNEL_MAX];
77 u32 base; 79 u32 base;
78 int value;
79 int irq; 80 int irq;
80}; 81};
81 82
@@ -188,9 +189,7 @@ static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel,
188 int scale, int *val) 189 int scale, int *val)
189{ 190{
190 int ret; 191 int ret;
191 u32 tmp; 192 u32 tmp, value, status;
192
193 reinit_completion(&data->completion);
194 193
195 ret = hwspin_lock_timeout_raw(data->hwlock, SC27XX_ADC_HWLOCK_TIMEOUT); 194 ret = hwspin_lock_timeout_raw(data->hwlock, SC27XX_ADC_HWLOCK_TIMEOUT);
196 if (ret) { 195 if (ret) {
@@ -203,6 +202,11 @@ static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel,
203 if (ret) 202 if (ret)
204 goto unlock_adc; 203 goto unlock_adc;
205 204
205 ret = regmap_update_bits(data->regmap, data->base + SC27XX_ADC_INT_CLR,
206 SC27XX_ADC_IRQ_CLR, SC27XX_ADC_IRQ_CLR);
207 if (ret)
208 goto disable_adc;
209
206 /* Configure the channel id and scale */ 210 /* Configure the channel id and scale */
207 tmp = (scale << SC27XX_ADC_SCALE_SHIFT) & SC27XX_ADC_SCALE_MASK; 211 tmp = (scale << SC27XX_ADC_SCALE_SHIFT) & SC27XX_ADC_SCALE_MASK;
208 tmp |= channel & SC27XX_ADC_CHN_ID_MASK; 212 tmp |= channel & SC27XX_ADC_CHN_ID_MASK;
@@ -226,15 +230,22 @@ static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel,
226 if (ret) 230 if (ret)
227 goto disable_adc; 231 goto disable_adc;
228 232
229 ret = wait_for_completion_timeout(&data->completion, 233 ret = regmap_read_poll_timeout(data->regmap,
230 msecs_to_jiffies(SC27XX_ADC_RDY_TIMEOUT)); 234 data->base + SC27XX_ADC_INT_RAW,
231 if (!ret) { 235 status, (status & SC27XX_ADC_IRQ_RAW),
232 dev_err(data->dev, "read ADC data timeout\n"); 236 SC27XX_ADC_POLL_RAW_STATUS,
233 ret = -ETIMEDOUT; 237 SC27XX_ADC_RDY_TIMEOUT);
234 } else { 238 if (ret) {
235 ret = 0; 239 dev_err(data->dev, "read adc timeout, status = 0x%x\n", status);
240 goto disable_adc;
236 } 241 }
237 242
243 ret = regmap_read(data->regmap, data->base + SC27XX_ADC_DATA, &value);
244 if (ret)
245 goto disable_adc;
246
247 value &= SC27XX_ADC_DATA_MASK;
248
238disable_adc: 249disable_adc:
239 regmap_update_bits(data->regmap, data->base + SC27XX_ADC_CTL, 250 regmap_update_bits(data->regmap, data->base + SC27XX_ADC_CTL,
240 SC27XX_ADC_EN, 0); 251 SC27XX_ADC_EN, 0);
@@ -242,32 +253,11 @@ unlock_adc:
242 hwspin_unlock_raw(data->hwlock); 253 hwspin_unlock_raw(data->hwlock);
243 254
244 if (!ret) 255 if (!ret)
245 *val = data->value; 256 *val = value;
246 257
247 return ret; 258 return ret;
248} 259}
249 260
250static irqreturn_t sc27xx_adc_isr(int irq, void *dev_id)
251{
252 struct sc27xx_adc_data *data = dev_id;
253 int ret;
254
255 ret = regmap_update_bits(data->regmap, data->base + SC27XX_ADC_INT_CLR,
256 SC27XX_ADC_IRQ_CLR, SC27XX_ADC_IRQ_CLR);
257 if (ret)
258 return IRQ_RETVAL(ret);
259
260 ret = regmap_read(data->regmap, data->base + SC27XX_ADC_DATA,
261 &data->value);
262 if (ret)
263 return IRQ_RETVAL(ret);
264
265 data->value &= SC27XX_ADC_DATA_MASK;
266 complete(&data->completion);
267
268 return IRQ_HANDLED;
269}
270
271static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data, 261static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data,
272 int channel, int scale, 262 int channel, int scale,
273 u32 *div_numerator, u32 *div_denominator) 263 u32 *div_numerator, u32 *div_denominator)
@@ -454,11 +444,6 @@ static int sc27xx_adc_enable(struct sc27xx_adc_data *data)
454 if (ret) 444 if (ret)
455 goto disable_adc; 445 goto disable_adc;
456 446
457 ret = regmap_update_bits(data->regmap, data->base + SC27XX_ADC_INT_EN,
458 SC27XX_ADC_IRQ_EN, SC27XX_ADC_IRQ_EN);
459 if (ret)
460 goto disable_clk;
461
462 /* ADC channel scales' calibration from nvmem device */ 447 /* ADC channel scales' calibration from nvmem device */
463 ret = sc27xx_adc_scale_calibration(data, true); 448 ret = sc27xx_adc_scale_calibration(data, true);
464 if (ret) 449 if (ret)
@@ -484,9 +469,6 @@ static void sc27xx_adc_disable(void *_data)
484{ 469{
485 struct sc27xx_adc_data *data = _data; 470 struct sc27xx_adc_data *data = _data;
486 471
487 regmap_update_bits(data->regmap, data->base + SC27XX_ADC_INT_EN,
488 SC27XX_ADC_IRQ_EN, 0);
489
490 /* Disable ADC work clock and controller clock */ 472 /* Disable ADC work clock and controller clock */
491 regmap_update_bits(data->regmap, SC27XX_ARM_CLK_EN, 473 regmap_update_bits(data->regmap, SC27XX_ARM_CLK_EN,
492 SC27XX_CLK_ADC_EN | SC27XX_CLK_ADC_CLK_EN, 0); 474 SC27XX_CLK_ADC_EN | SC27XX_CLK_ADC_CLK_EN, 0);
@@ -504,88 +486,76 @@ static void sc27xx_adc_free_hwlock(void *_data)
504 486
505static int sc27xx_adc_probe(struct platform_device *pdev) 487static int sc27xx_adc_probe(struct platform_device *pdev)
506{ 488{
507 struct device_node *np = pdev->dev.of_node; 489 struct device *dev = &pdev->dev;
490 struct device_node *np = dev->of_node;
508 struct sc27xx_adc_data *sc27xx_data; 491 struct sc27xx_adc_data *sc27xx_data;
509 struct iio_dev *indio_dev; 492 struct iio_dev *indio_dev;
510 int ret; 493 int ret;
511 494
512 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*sc27xx_data)); 495 indio_dev = devm_iio_device_alloc(dev, sizeof(*sc27xx_data));
513 if (!indio_dev) 496 if (!indio_dev)
514 return -ENOMEM; 497 return -ENOMEM;
515 498
516 sc27xx_data = iio_priv(indio_dev); 499 sc27xx_data = iio_priv(indio_dev);
517 500
518 sc27xx_data->regmap = dev_get_regmap(pdev->dev.parent, NULL); 501 sc27xx_data->regmap = dev_get_regmap(dev->parent, NULL);
519 if (!sc27xx_data->regmap) { 502 if (!sc27xx_data->regmap) {
520 dev_err(&pdev->dev, "failed to get ADC regmap\n"); 503 dev_err(dev, "failed to get ADC regmap\n");
521 return -ENODEV; 504 return -ENODEV;
522 } 505 }
523 506
524 ret = of_property_read_u32(np, "reg", &sc27xx_data->base); 507 ret = of_property_read_u32(np, "reg", &sc27xx_data->base);
525 if (ret) { 508 if (ret) {
526 dev_err(&pdev->dev, "failed to get ADC base address\n"); 509 dev_err(dev, "failed to get ADC base address\n");
527 return ret; 510 return ret;
528 } 511 }
529 512
530 sc27xx_data->irq = platform_get_irq(pdev, 0); 513 sc27xx_data->irq = platform_get_irq(pdev, 0);
531 if (sc27xx_data->irq < 0) { 514 if (sc27xx_data->irq < 0)
532 dev_err(&pdev->dev, "failed to get ADC irq number\n");
533 return sc27xx_data->irq; 515 return sc27xx_data->irq;
534 }
535 516
536 ret = of_hwspin_lock_get_id(np, 0); 517 ret = of_hwspin_lock_get_id(np, 0);
537 if (ret < 0) { 518 if (ret < 0) {
538 dev_err(&pdev->dev, "failed to get hwspinlock id\n"); 519 dev_err(dev, "failed to get hwspinlock id\n");
539 return ret; 520 return ret;
540 } 521 }
541 522
542 sc27xx_data->hwlock = hwspin_lock_request_specific(ret); 523 sc27xx_data->hwlock = hwspin_lock_request_specific(ret);
543 if (!sc27xx_data->hwlock) { 524 if (!sc27xx_data->hwlock) {
544 dev_err(&pdev->dev, "failed to request hwspinlock\n"); 525 dev_err(dev, "failed to request hwspinlock\n");
545 return -ENXIO; 526 return -ENXIO;
546 } 527 }
547 528
548 ret = devm_add_action(&pdev->dev, sc27xx_adc_free_hwlock, 529 ret = devm_add_action_or_reset(dev, sc27xx_adc_free_hwlock,
549 sc27xx_data->hwlock); 530 sc27xx_data->hwlock);
550 if (ret) { 531 if (ret) {
551 sc27xx_adc_free_hwlock(sc27xx_data->hwlock); 532 dev_err(dev, "failed to add hwspinlock action\n");
552 dev_err(&pdev->dev, "failed to add hwspinlock action\n");
553 return ret; 533 return ret;
554 } 534 }
555 535
556 init_completion(&sc27xx_data->completion); 536 sc27xx_data->dev = dev;
557 sc27xx_data->dev = &pdev->dev;
558 537
559 ret = sc27xx_adc_enable(sc27xx_data); 538 ret = sc27xx_adc_enable(sc27xx_data);
560 if (ret) { 539 if (ret) {
561 dev_err(&pdev->dev, "failed to enable ADC module\n"); 540 dev_err(dev, "failed to enable ADC module\n");
562 return ret;
563 }
564
565 ret = devm_add_action(&pdev->dev, sc27xx_adc_disable, sc27xx_data);
566 if (ret) {
567 sc27xx_adc_disable(sc27xx_data);
568 dev_err(&pdev->dev, "failed to add ADC disable action\n");
569 return ret; 541 return ret;
570 } 542 }
571 543
572 ret = devm_request_threaded_irq(&pdev->dev, sc27xx_data->irq, NULL, 544 ret = devm_add_action_or_reset(dev, sc27xx_adc_disable, sc27xx_data);
573 sc27xx_adc_isr, IRQF_ONESHOT,
574 pdev->name, sc27xx_data);
575 if (ret) { 545 if (ret) {
576 dev_err(&pdev->dev, "failed to request ADC irq\n"); 546 dev_err(dev, "failed to add ADC disable action\n");
577 return ret; 547 return ret;
578 } 548 }
579 549
580 indio_dev->dev.parent = &pdev->dev; 550 indio_dev->dev.parent = dev;
581 indio_dev->name = dev_name(&pdev->dev); 551 indio_dev->name = dev_name(dev);
582 indio_dev->modes = INDIO_DIRECT_MODE; 552 indio_dev->modes = INDIO_DIRECT_MODE;
583 indio_dev->info = &sc27xx_info; 553 indio_dev->info = &sc27xx_info;
584 indio_dev->channels = sc27xx_channels; 554 indio_dev->channels = sc27xx_channels;
585 indio_dev->num_channels = ARRAY_SIZE(sc27xx_channels); 555 indio_dev->num_channels = ARRAY_SIZE(sc27xx_channels);
586 ret = devm_iio_device_register(&pdev->dev, indio_dev); 556 ret = devm_iio_device_register(dev, indio_dev);
587 if (ret) 557 if (ret)
588 dev_err(&pdev->dev, "could not register iio (ADC)"); 558 dev_err(dev, "could not register iio (ADC)");
589 559
590 return ret; 560 return ret;
591} 561}
diff --git a/drivers/iio/adc/spear_adc.c b/drivers/iio/adc/spear_adc.c
index a33d0a4cc088..592b97c464da 100644
--- a/drivers/iio/adc/spear_adc.c
+++ b/drivers/iio/adc/spear_adc.c
@@ -301,7 +301,6 @@ static int spear_adc_probe(struct platform_device *pdev)
301 301
302 irq = platform_get_irq(pdev, 0); 302 irq = platform_get_irq(pdev, 0);
303 if (irq <= 0) { 303 if (irq <= 0) {
304 dev_err(dev, "failed getting interrupt resource\n");
305 ret = -EINVAL; 304 ret = -EINVAL;
306 goto errout2; 305 goto errout2;
307 } 306 }
diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c
index 1f7ce5186dfc..9b85fefc0a96 100644
--- a/drivers/iio/adc/stm32-adc-core.c
+++ b/drivers/iio/adc/stm32-adc-core.c
@@ -14,9 +14,11 @@
14#include <linux/irqchip/chained_irq.h> 14#include <linux/irqchip/chained_irq.h>
15#include <linux/irqdesc.h> 15#include <linux/irqdesc.h>
16#include <linux/irqdomain.h> 16#include <linux/irqdomain.h>
17#include <linux/mfd/syscon.h>
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/of_device.h> 19#include <linux/of_device.h>
19#include <linux/pm_runtime.h> 20#include <linux/pm_runtime.h>
21#include <linux/regmap.h>
20#include <linux/regulator/consumer.h> 22#include <linux/regulator/consumer.h>
21#include <linux/slab.h> 23#include <linux/slab.h>
22 24
@@ -51,6 +53,17 @@
51 53
52#define STM32_ADC_CORE_SLEEP_DELAY_MS 2000 54#define STM32_ADC_CORE_SLEEP_DELAY_MS 2000
53 55
56/* SYSCFG registers */
57#define STM32MP1_SYSCFG_PMCSETR 0x04
58#define STM32MP1_SYSCFG_PMCCLRR 0x44
59
60/* SYSCFG bit fields */
61#define STM32MP1_SYSCFG_ANASWVDD_MASK BIT(9)
62
63/* SYSCFG capability flags */
64#define HAS_VBOOSTER BIT(0)
65#define HAS_ANASWVDD BIT(1)
66
54/** 67/**
55 * stm32_adc_common_regs - stm32 common registers, compatible dependent data 68 * stm32_adc_common_regs - stm32 common registers, compatible dependent data
56 * @csr: common status register offset 69 * @csr: common status register offset
@@ -74,11 +87,13 @@ struct stm32_adc_priv;
74 * @regs: common registers for all instances 87 * @regs: common registers for all instances
75 * @clk_sel: clock selection routine 88 * @clk_sel: clock selection routine
76 * @max_clk_rate_hz: maximum analog clock rate (Hz, from datasheet) 89 * @max_clk_rate_hz: maximum analog clock rate (Hz, from datasheet)
90 * @has_syscfg: SYSCFG capability flags
77 */ 91 */
78struct stm32_adc_priv_cfg { 92struct stm32_adc_priv_cfg {
79 const struct stm32_adc_common_regs *regs; 93 const struct stm32_adc_common_regs *regs;
80 int (*clk_sel)(struct platform_device *, struct stm32_adc_priv *); 94 int (*clk_sel)(struct platform_device *, struct stm32_adc_priv *);
81 u32 max_clk_rate_hz; 95 u32 max_clk_rate_hz;
96 unsigned int has_syscfg;
82}; 97};
83 98
84/** 99/**
@@ -87,22 +102,32 @@ struct stm32_adc_priv_cfg {
87 * @domain: irq domain reference 102 * @domain: irq domain reference
88 * @aclk: clock reference for the analog circuitry 103 * @aclk: clock reference for the analog circuitry
89 * @bclk: bus clock common for all ADCs, depends on part used 104 * @bclk: bus clock common for all ADCs, depends on part used
105 * @booster: booster supply reference
106 * @vdd: vdd supply reference
90 * @vdda: vdda analog supply reference 107 * @vdda: vdda analog supply reference
91 * @vref: regulator reference 108 * @vref: regulator reference
109 * @vdd_uv: vdd supply voltage (microvolts)
110 * @vdda_uv: vdda supply voltage (microvolts)
92 * @cfg: compatible configuration data 111 * @cfg: compatible configuration data
93 * @common: common data for all ADC instances 112 * @common: common data for all ADC instances
94 * @ccr_bak: backup CCR in low power mode 113 * @ccr_bak: backup CCR in low power mode
114 * @syscfg: reference to syscon, system control registers
95 */ 115 */
96struct stm32_adc_priv { 116struct stm32_adc_priv {
97 int irq[STM32_ADC_MAX_ADCS]; 117 int irq[STM32_ADC_MAX_ADCS];
98 struct irq_domain *domain; 118 struct irq_domain *domain;
99 struct clk *aclk; 119 struct clk *aclk;
100 struct clk *bclk; 120 struct clk *bclk;
121 struct regulator *booster;
122 struct regulator *vdd;
101 struct regulator *vdda; 123 struct regulator *vdda;
102 struct regulator *vref; 124 struct regulator *vref;
125 int vdd_uv;
126 int vdda_uv;
103 const struct stm32_adc_priv_cfg *cfg; 127 const struct stm32_adc_priv_cfg *cfg;
104 struct stm32_adc_common common; 128 struct stm32_adc_common common;
105 u32 ccr_bak; 129 u32 ccr_bak;
130 struct regmap *syscfg;
106}; 131};
107 132
108static struct stm32_adc_priv *to_stm32_adc_priv(struct stm32_adc_common *com) 133static struct stm32_adc_priv *to_stm32_adc_priv(struct stm32_adc_common *com)
@@ -349,7 +374,6 @@ static int stm32_adc_irq_probe(struct platform_device *pdev,
349 */ 374 */
350 if (i && priv->irq[i] == -ENXIO) 375 if (i && priv->irq[i] == -ENXIO)
351 continue; 376 continue;
352 dev_err(&pdev->dev, "failed to get irq\n");
353 377
354 return priv->irq[i]; 378 return priv->irq[i];
355 } 379 }
@@ -390,6 +414,82 @@ static void stm32_adc_irq_remove(struct platform_device *pdev,
390 } 414 }
391} 415}
392 416
417static int stm32_adc_core_switches_supply_en(struct stm32_adc_priv *priv,
418 struct device *dev)
419{
420 int ret;
421
422 /*
423 * On STM32H7 and STM32MP1, the ADC inputs are multiplexed with analog
424 * switches (via PCSEL) which have reduced performances when their
425 * supply is below 2.7V (vdda by default):
426 * - Voltage booster can be used, to get full ADC performances
427 * (increases power consumption).
428 * - Vdd can be used to supply them, if above 2.7V (STM32MP1 only).
429 *
430 * Recommended settings for ANASWVDD and EN_BOOSTER:
431 * - vdda < 2.7V but vdd > 2.7V: ANASWVDD = 1, EN_BOOSTER = 0 (stm32mp1)
432 * - vdda < 2.7V and vdd < 2.7V: ANASWVDD = 0, EN_BOOSTER = 1
433 * - vdda >= 2.7V: ANASWVDD = 0, EN_BOOSTER = 0 (default)
434 */
435 if (priv->vdda_uv < 2700000) {
436 if (priv->syscfg && priv->vdd_uv > 2700000) {
437 ret = regulator_enable(priv->vdd);
438 if (ret < 0) {
439 dev_err(dev, "vdd enable failed %d\n", ret);
440 return ret;
441 }
442
443 ret = regmap_write(priv->syscfg,
444 STM32MP1_SYSCFG_PMCSETR,
445 STM32MP1_SYSCFG_ANASWVDD_MASK);
446 if (ret < 0) {
447 regulator_disable(priv->vdd);
448 dev_err(dev, "vdd select failed, %d\n", ret);
449 return ret;
450 }
451 dev_dbg(dev, "analog switches supplied by vdd\n");
452
453 return 0;
454 }
455
456 if (priv->booster) {
457 /*
458 * This is optional, as this is a trade-off between
459 * analog performance and power consumption.
460 */
461 ret = regulator_enable(priv->booster);
462 if (ret < 0) {
463 dev_err(dev, "booster enable failed %d\n", ret);
464 return ret;
465 }
466 dev_dbg(dev, "analog switches supplied by booster\n");
467
468 return 0;
469 }
470 }
471
472 /* Fallback using vdda (default), nothing to do */
473 dev_dbg(dev, "analog switches supplied by vdda (%d uV)\n",
474 priv->vdda_uv);
475
476 return 0;
477}
478
479static void stm32_adc_core_switches_supply_dis(struct stm32_adc_priv *priv)
480{
481 if (priv->vdda_uv < 2700000) {
482 if (priv->syscfg && priv->vdd_uv > 2700000) {
483 regmap_write(priv->syscfg, STM32MP1_SYSCFG_PMCCLRR,
484 STM32MP1_SYSCFG_ANASWVDD_MASK);
485 regulator_disable(priv->vdd);
486 return;
487 }
488 if (priv->booster)
489 regulator_disable(priv->booster);
490 }
491}
492
393static int stm32_adc_core_hw_start(struct device *dev) 493static int stm32_adc_core_hw_start(struct device *dev)
394{ 494{
395 struct stm32_adc_common *common = dev_get_drvdata(dev); 495 struct stm32_adc_common *common = dev_get_drvdata(dev);
@@ -402,10 +502,21 @@ static int stm32_adc_core_hw_start(struct device *dev)
402 return ret; 502 return ret;
403 } 503 }
404 504
505 ret = regulator_get_voltage(priv->vdda);
506 if (ret < 0) {
507 dev_err(dev, "vdda get voltage failed, %d\n", ret);
508 goto err_vdda_disable;
509 }
510 priv->vdda_uv = ret;
511
512 ret = stm32_adc_core_switches_supply_en(priv, dev);
513 if (ret < 0)
514 goto err_vdda_disable;
515
405 ret = regulator_enable(priv->vref); 516 ret = regulator_enable(priv->vref);
406 if (ret < 0) { 517 if (ret < 0) {
407 dev_err(dev, "vref enable failed\n"); 518 dev_err(dev, "vref enable failed\n");
408 goto err_vdda_disable; 519 goto err_switches_dis;
409 } 520 }
410 521
411 if (priv->bclk) { 522 if (priv->bclk) {
@@ -433,6 +544,8 @@ err_bclk_disable:
433 clk_disable_unprepare(priv->bclk); 544 clk_disable_unprepare(priv->bclk);
434err_regulator_disable: 545err_regulator_disable:
435 regulator_disable(priv->vref); 546 regulator_disable(priv->vref);
547err_switches_dis:
548 stm32_adc_core_switches_supply_dis(priv);
436err_vdda_disable: 549err_vdda_disable:
437 regulator_disable(priv->vdda); 550 regulator_disable(priv->vdda);
438 551
@@ -451,9 +564,80 @@ static void stm32_adc_core_hw_stop(struct device *dev)
451 if (priv->bclk) 564 if (priv->bclk)
452 clk_disable_unprepare(priv->bclk); 565 clk_disable_unprepare(priv->bclk);
453 regulator_disable(priv->vref); 566 regulator_disable(priv->vref);
567 stm32_adc_core_switches_supply_dis(priv);
454 regulator_disable(priv->vdda); 568 regulator_disable(priv->vdda);
455} 569}
456 570
571static int stm32_adc_core_switches_probe(struct device *dev,
572 struct stm32_adc_priv *priv)
573{
574 struct device_node *np = dev->of_node;
575 int ret;
576
577 /* Analog switches supply can be controlled by syscfg (optional) */
578 priv->syscfg = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
579 if (IS_ERR(priv->syscfg)) {
580 ret = PTR_ERR(priv->syscfg);
581 if (ret != -ENODEV) {
582 if (ret != -EPROBE_DEFER)
583 dev_err(dev, "Can't probe syscfg: %d\n", ret);
584 return ret;
585 }
586 priv->syscfg = NULL;
587 }
588
589 /* Booster can be used to supply analog switches (optional) */
590 if (priv->cfg->has_syscfg & HAS_VBOOSTER &&
591 of_property_read_bool(np, "booster-supply")) {
592 priv->booster = devm_regulator_get_optional(dev, "booster");
593 if (IS_ERR(priv->booster)) {
594 ret = PTR_ERR(priv->booster);
595 if (ret != -ENODEV) {
596 if (ret != -EPROBE_DEFER)
597 dev_err(dev, "can't get booster %d\n",
598 ret);
599 return ret;
600 }
601 priv->booster = NULL;
602 }
603 }
604
605 /* Vdd can be used to supply analog switches (optional) */
606 if (priv->cfg->has_syscfg & HAS_ANASWVDD &&
607 of_property_read_bool(np, "vdd-supply")) {
608 priv->vdd = devm_regulator_get_optional(dev, "vdd");
609 if (IS_ERR(priv->vdd)) {
610 ret = PTR_ERR(priv->vdd);
611 if (ret != -ENODEV) {
612 if (ret != -EPROBE_DEFER)
613 dev_err(dev, "can't get vdd %d\n", ret);
614 return ret;
615 }
616 priv->vdd = NULL;
617 }
618 }
619
620 if (priv->vdd) {
621 ret = regulator_enable(priv->vdd);
622 if (ret < 0) {
623 dev_err(dev, "vdd enable failed %d\n", ret);
624 return ret;
625 }
626
627 ret = regulator_get_voltage(priv->vdd);
628 if (ret < 0) {
629 dev_err(dev, "vdd get voltage failed %d\n", ret);
630 regulator_disable(priv->vdd);
631 return ret;
632 }
633 priv->vdd_uv = ret;
634
635 regulator_disable(priv->vdd);
636 }
637
638 return 0;
639}
640
457static int stm32_adc_probe(struct platform_device *pdev) 641static int stm32_adc_probe(struct platform_device *pdev)
458{ 642{
459 struct stm32_adc_priv *priv; 643 struct stm32_adc_priv *priv;
@@ -514,6 +698,10 @@ static int stm32_adc_probe(struct platform_device *pdev)
514 priv->bclk = NULL; 698 priv->bclk = NULL;
515 } 699 }
516 700
701 ret = stm32_adc_core_switches_probe(dev, priv);
702 if (ret)
703 return ret;
704
517 pm_runtime_get_noresume(dev); 705 pm_runtime_get_noresume(dev);
518 pm_runtime_set_active(dev); 706 pm_runtime_set_active(dev);
519 pm_runtime_set_autosuspend_delay(dev, STM32_ADC_CORE_SLEEP_DELAY_MS); 707 pm_runtime_set_autosuspend_delay(dev, STM32_ADC_CORE_SLEEP_DELAY_MS);
@@ -611,12 +799,14 @@ static const struct stm32_adc_priv_cfg stm32h7_adc_priv_cfg = {
611 .regs = &stm32h7_adc_common_regs, 799 .regs = &stm32h7_adc_common_regs,
612 .clk_sel = stm32h7_adc_clk_sel, 800 .clk_sel = stm32h7_adc_clk_sel,
613 .max_clk_rate_hz = 36000000, 801 .max_clk_rate_hz = 36000000,
802 .has_syscfg = HAS_VBOOSTER,
614}; 803};
615 804
616static const struct stm32_adc_priv_cfg stm32mp1_adc_priv_cfg = { 805static const struct stm32_adc_priv_cfg stm32mp1_adc_priv_cfg = {
617 .regs = &stm32h7_adc_common_regs, 806 .regs = &stm32h7_adc_common_regs,
618 .clk_sel = stm32h7_adc_clk_sel, 807 .clk_sel = stm32h7_adc_clk_sel,
619 .max_clk_rate_hz = 40000000, 808 .max_clk_rate_hz = 40000000,
809 .has_syscfg = HAS_VBOOSTER | HAS_ANASWVDD,
620}; 810};
621 811
622static const struct of_device_id stm32_adc_of_match[] = { 812static const struct of_device_id stm32_adc_of_match[] = {
diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index 205e1699f954..6a7dd08b1e0b 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -1919,10 +1919,8 @@ static int stm32_adc_probe(struct platform_device *pdev)
1919 } 1919 }
1920 1920
1921 adc->irq = platform_get_irq(pdev, 0); 1921 adc->irq = platform_get_irq(pdev, 0);
1922 if (adc->irq < 0) { 1922 if (adc->irq < 0)
1923 dev_err(&pdev->dev, "failed to get irq\n");
1924 return adc->irq; 1923 return adc->irq;
1925 }
1926 1924
1927 ret = devm_request_irq(&pdev->dev, adc->irq, stm32_adc_isr, 1925 ret = devm_request_irq(&pdev->dev, adc->irq, stm32_adc_isr,
1928 0, pdev->name, adc); 1926 0, pdev->name, adc);
diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c
index ee1e0569d0e1..e493242c266e 100644
--- a/drivers/iio/adc/stm32-dfsdm-adc.c
+++ b/drivers/iio/adc/stm32-dfsdm-adc.c
@@ -1601,11 +1601,8 @@ static int stm32_dfsdm_adc_probe(struct platform_device *pdev)
1601 * So IRQ associated to filter instance 0 is dedicated to the Filter 0. 1601 * So IRQ associated to filter instance 0 is dedicated to the Filter 0.
1602 */ 1602 */
1603 irq = platform_get_irq(pdev, 0); 1603 irq = platform_get_irq(pdev, 0);
1604 if (irq < 0) { 1604 if (irq < 0)
1605 if (irq != -EPROBE_DEFER)
1606 dev_err(dev, "Failed to get IRQ: %d\n", irq);
1607 return irq; 1605 return irq;
1608 }
1609 1606
1610 ret = devm_request_irq(dev, irq, stm32_dfsdm_irq, 1607 ret = devm_request_irq(dev, irq, stm32_dfsdm_irq,
1611 0, pdev->name, adc); 1608 0, pdev->name, adc);
diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c
index f13c6248a662..176e1cb4abb1 100644
--- a/drivers/iio/adc/sun4i-gpadc-iio.c
+++ b/drivers/iio/adc/sun4i-gpadc-iio.c
@@ -460,10 +460,8 @@ static int sun4i_irq_init(struct platform_device *pdev, const char *name,
460 atomic_set(atomic, 1); 460 atomic_set(atomic, 1);
461 461
462 ret = platform_get_irq_byname(pdev, name); 462 ret = platform_get_irq_byname(pdev, name);
463 if (ret < 0) { 463 if (ret < 0)
464 dev_err(&pdev->dev, "no %s interrupt registered\n", name);
465 return ret; 464 return ret;
466 }
467 465
468 ret = regmap_irq_get_virq(mfd_dev->regmap_irqc, ret); 466 ret = regmap_irq_get_virq(mfd_dev->regmap_irqc, ret);
469 if (ret < 0) { 467 if (ret < 0) {
diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
index 2fa6ec83bb13..f24148bd15de 100644
--- a/drivers/iio/adc/twl6030-gpadc.c
+++ b/drivers/iio/adc/twl6030-gpadc.c
@@ -905,10 +905,8 @@ static int twl6030_gpadc_probe(struct platform_device *pdev)
905 } 905 }
906 906
907 irq = platform_get_irq(pdev, 0); 907 irq = platform_get_irq(pdev, 0);
908 if (irq < 0) { 908 if (irq < 0)
909 dev_err(&pdev->dev, "failed to get irq\n");
910 return irq; 909 return irq;
911 }
912 910
913 ret = devm_request_threaded_irq(dev, irq, NULL, 911 ret = devm_request_threaded_irq(dev, irq, NULL,
914 twl6030_gpadc_irq_handler, 912 twl6030_gpadc_irq_handler,
diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c
index 41d3621c4787..98b30475bbc6 100644
--- a/drivers/iio/adc/vf610_adc.c
+++ b/drivers/iio/adc/vf610_adc.c
@@ -821,10 +821,8 @@ static int vf610_adc_probe(struct platform_device *pdev)
821 return PTR_ERR(info->regs); 821 return PTR_ERR(info->regs);
822 822
823 irq = platform_get_irq(pdev, 0); 823 irq = platform_get_irq(pdev, 0);
824 if (irq < 0) { 824 if (irq < 0)
825 dev_err(&pdev->dev, "no irq resource?\n");
826 return irq; 825 return irq;
827 }
828 826
829 ret = devm_request_irq(info->dev, irq, 827 ret = devm_request_irq(info->dev, irq,
830 vf610_adc_isr, 0, 828 vf610_adc_isr, 0,
diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
index 17af4e0fd5f8..6a4919cd83c3 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
@@ -63,10 +63,35 @@ static int cros_ec_sensors_read(struct iio_dev *indio_dev,
63 63
64 /* Save values */ 64 /* Save values */
65 for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++) 65 for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
66 st->core.calib[i] = 66 st->core.calib[i].offset =
67 st->core.resp->sensor_offset.offset[i]; 67 st->core.resp->sensor_offset.offset[i];
68 ret = IIO_VAL_INT; 68 ret = IIO_VAL_INT;
69 *val = st->core.calib[idx]; 69 *val = st->core.calib[idx].offset;
70 break;
71 case IIO_CHAN_INFO_CALIBSCALE:
72 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_SCALE;
73 st->core.param.sensor_offset.flags = 0;
74
75 ret = cros_ec_motion_send_host_cmd(&st->core, 0);
76 if (ret == -EPROTO) {
77 /* Reading calibscale is not supported on older EC. */
78 *val = 1;
79 *val2 = 0;
80 ret = IIO_VAL_INT_PLUS_MICRO;
81 break;
82 } else if (ret) {
83 break;
84 }
85
86 /* Save values */
87 for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
88 st->core.calib[i].scale =
89 st->core.resp->sensor_scale.scale[i];
90
91 *val = st->core.calib[idx].scale >> 15;
92 *val2 = ((st->core.calib[idx].scale & 0x7FFF) * 1000000LL) /
93 MOTION_SENSE_DEFAULT_SCALE;
94 ret = IIO_VAL_INT_PLUS_MICRO;
70 break; 95 break;
71 case IIO_CHAN_INFO_SCALE: 96 case IIO_CHAN_INFO_SCALE:
72 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE; 97 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE;
@@ -134,7 +159,7 @@ static int cros_ec_sensors_write(struct iio_dev *indio_dev,
134 159
135 switch (mask) { 160 switch (mask) {
136 case IIO_CHAN_INFO_CALIBBIAS: 161 case IIO_CHAN_INFO_CALIBBIAS:
137 st->core.calib[idx] = val; 162 st->core.calib[idx].offset = val;
138 163
139 /* Send to EC for each axis, even if not complete */ 164 /* Send to EC for each axis, even if not complete */
140 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET; 165 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET;
@@ -142,12 +167,27 @@ static int cros_ec_sensors_write(struct iio_dev *indio_dev,
142 MOTION_SENSE_SET_OFFSET; 167 MOTION_SENSE_SET_OFFSET;
143 for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++) 168 for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
144 st->core.param.sensor_offset.offset[i] = 169 st->core.param.sensor_offset.offset[i] =
145 st->core.calib[i]; 170 st->core.calib[i].offset;
146 st->core.param.sensor_offset.temp = 171 st->core.param.sensor_offset.temp =
147 EC_MOTION_SENSE_INVALID_CALIB_TEMP; 172 EC_MOTION_SENSE_INVALID_CALIB_TEMP;
148 173
149 ret = cros_ec_motion_send_host_cmd(&st->core, 0); 174 ret = cros_ec_motion_send_host_cmd(&st->core, 0);
150 break; 175 break;
176 case IIO_CHAN_INFO_CALIBSCALE:
177 st->core.calib[idx].scale = val;
178 /* Send to EC for each axis, even if not complete */
179
180 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_SCALE;
181 st->core.param.sensor_offset.flags =
182 MOTION_SENSE_SET_OFFSET;
183 for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
184 st->core.param.sensor_scale.scale[i] =
185 st->core.calib[i].scale;
186 st->core.param.sensor_scale.temp =
187 EC_MOTION_SENSE_INVALID_CALIB_TEMP;
188
189 ret = cros_ec_motion_send_host_cmd(&st->core, 0);
190 break;
151 case IIO_CHAN_INFO_SCALE: 191 case IIO_CHAN_INFO_SCALE:
152 if (st->core.type == MOTIONSENSE_TYPE_MAG) { 192 if (st->core.type == MOTIONSENSE_TYPE_MAG) {
153 ret = -EINVAL; 193 ret = -EINVAL;
@@ -175,6 +215,7 @@ static int cros_ec_sensors_write(struct iio_dev *indio_dev,
175static const struct iio_info ec_sensors_info = { 215static const struct iio_info ec_sensors_info = {
176 .read_raw = &cros_ec_sensors_read, 216 .read_raw = &cros_ec_sensors_read,
177 .write_raw = &cros_ec_sensors_write, 217 .write_raw = &cros_ec_sensors_write,
218 .read_avail = &cros_ec_sensors_core_read_avail,
178}; 219};
179 220
180static int cros_ec_sensors_probe(struct platform_device *pdev) 221static int cros_ec_sensors_probe(struct platform_device *pdev)
@@ -206,11 +247,14 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)
206 /* Common part */ 247 /* Common part */
207 channel->info_mask_separate = 248 channel->info_mask_separate =
208 BIT(IIO_CHAN_INFO_RAW) | 249 BIT(IIO_CHAN_INFO_RAW) |
209 BIT(IIO_CHAN_INFO_CALIBBIAS); 250 BIT(IIO_CHAN_INFO_CALIBBIAS) |
251 BIT(IIO_CHAN_INFO_CALIBSCALE);
210 channel->info_mask_shared_by_all = 252 channel->info_mask_shared_by_all =
211 BIT(IIO_CHAN_INFO_SCALE) | 253 BIT(IIO_CHAN_INFO_SCALE) |
212 BIT(IIO_CHAN_INFO_FREQUENCY) | 254 BIT(IIO_CHAN_INFO_FREQUENCY) |
213 BIT(IIO_CHAN_INFO_SAMP_FREQ); 255 BIT(IIO_CHAN_INFO_SAMP_FREQ);
256 channel->info_mask_shared_by_all_available =
257 BIT(IIO_CHAN_INFO_SAMP_FREQ);
214 channel->scan_type.realbits = CROS_EC_SENSOR_BITS; 258 channel->scan_type.realbits = CROS_EC_SENSOR_BITS;
215 channel->scan_type.storagebits = CROS_EC_SENSOR_BITS; 259 channel->scan_type.storagebits = CROS_EC_SENSOR_BITS;
216 channel->scan_index = i; 260 channel->scan_index = i;
diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index 130362ca421b..d44ae126f457 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -25,6 +25,62 @@ static char *cros_ec_loc[] = {
25 [MOTIONSENSE_LOC_MAX] = "unknown", 25 [MOTIONSENSE_LOC_MAX] = "unknown",
26}; 26};
27 27
28static int cros_ec_get_host_cmd_version_mask(struct cros_ec_device *ec_dev,
29 u16 cmd_offset, u16 cmd, u32 *mask)
30{
31 int ret;
32 struct {
33 struct cros_ec_command msg;
34 union {
35 struct ec_params_get_cmd_versions params;
36 struct ec_response_get_cmd_versions resp;
37 };
38 } __packed buf = {
39 .msg = {
40 .command = EC_CMD_GET_CMD_VERSIONS + cmd_offset,
41 .insize = sizeof(struct ec_response_get_cmd_versions),
42 .outsize = sizeof(struct ec_params_get_cmd_versions)
43 },
44 .params = {.cmd = cmd}
45 };
46
47 ret = cros_ec_cmd_xfer_status(ec_dev, &buf.msg);
48 if (ret >= 0)
49 *mask = buf.resp.version_mask;
50 return ret;
51}
52
53static void get_default_min_max_freq(enum motionsensor_type type,
54 u32 *min_freq,
55 u32 *max_freq)
56{
57 switch (type) {
58 case MOTIONSENSE_TYPE_ACCEL:
59 case MOTIONSENSE_TYPE_GYRO:
60 *min_freq = 12500;
61 *max_freq = 100000;
62 break;
63 case MOTIONSENSE_TYPE_MAG:
64 *min_freq = 5000;
65 *max_freq = 25000;
66 break;
67 case MOTIONSENSE_TYPE_PROX:
68 case MOTIONSENSE_TYPE_LIGHT:
69 *min_freq = 100;
70 *max_freq = 50000;
71 break;
72 case MOTIONSENSE_TYPE_BARO:
73 *min_freq = 250;
74 *max_freq = 20000;
75 break;
76 case MOTIONSENSE_TYPE_ACTIVITY:
77 default:
78 *min_freq = 0;
79 *max_freq = 0;
80 break;
81 }
82}
83
28int cros_ec_sensors_core_init(struct platform_device *pdev, 84int cros_ec_sensors_core_init(struct platform_device *pdev,
29 struct iio_dev *indio_dev, 85 struct iio_dev *indio_dev,
30 bool physical_device) 86 bool physical_device)
@@ -33,6 +89,8 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
33 struct cros_ec_sensors_core_state *state = iio_priv(indio_dev); 89 struct cros_ec_sensors_core_state *state = iio_priv(indio_dev);
34 struct cros_ec_dev *ec = dev_get_drvdata(pdev->dev.parent); 90 struct cros_ec_dev *ec = dev_get_drvdata(pdev->dev.parent);
35 struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev); 91 struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
92 u32 ver_mask;
93 int ret, i;
36 94
37 platform_set_drvdata(pdev, indio_dev); 95 platform_set_drvdata(pdev, indio_dev);
38 96
@@ -47,8 +105,15 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
47 105
48 mutex_init(&state->cmd_lock); 106 mutex_init(&state->cmd_lock);
49 107
108 ret = cros_ec_get_host_cmd_version_mask(state->ec,
109 ec->cmd_offset,
110 EC_CMD_MOTION_SENSE_CMD,
111 &ver_mask);
112 if (ret < 0)
113 return ret;
114
50 /* Set up the host command structure. */ 115 /* Set up the host command structure. */
51 state->msg->version = 2; 116 state->msg->version = fls(ver_mask) - 1;
52 state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset; 117 state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
53 state->msg->outsize = sizeof(struct ec_params_motion_sense); 118 state->msg->outsize = sizeof(struct ec_params_motion_sense);
54 119
@@ -60,12 +125,32 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
60 125
61 state->param.cmd = MOTIONSENSE_CMD_INFO; 126 state->param.cmd = MOTIONSENSE_CMD_INFO;
62 state->param.info.sensor_num = sensor_platform->sensor_num; 127 state->param.info.sensor_num = sensor_platform->sensor_num;
63 if (cros_ec_motion_send_host_cmd(state, 0)) { 128 ret = cros_ec_motion_send_host_cmd(state, 0);
129 if (ret) {
64 dev_warn(dev, "Can not access sensor info\n"); 130 dev_warn(dev, "Can not access sensor info\n");
65 return -EIO; 131 return ret;
66 } 132 }
67 state->type = state->resp->info.type; 133 state->type = state->resp->info.type;
68 state->loc = state->resp->info.location; 134 state->loc = state->resp->info.location;
135
136 /* Set sign vector, only used for backward compatibility. */
137 memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
138
139 for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
140 state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE;
141
142 /* 0 is a correct value used to stop the device */
143 state->frequencies[0] = 0;
144 if (state->msg->version < 3) {
145 get_default_min_max_freq(state->resp->info.type,
146 &state->frequencies[1],
147 &state->frequencies[2]);
148 } else {
149 state->frequencies[1] =
150 state->resp->info_3.min_frequency;
151 state->frequencies[2] =
152 state->resp->info_3.max_frequency;
153 }
69 } 154 }
70 155
71 return 0; 156 return 0;
@@ -86,7 +171,7 @@ int cros_ec_motion_send_host_cmd(struct cros_ec_sensors_core_state *state,
86 171
87 ret = cros_ec_cmd_xfer_status(state->ec, state->msg); 172 ret = cros_ec_cmd_xfer_status(state->ec, state->msg);
88 if (ret < 0) 173 if (ret < 0)
89 return -EIO; 174 return ret;
90 175
91 if (ret && 176 if (ret &&
92 state->resp != (struct ec_response_motion_sense *)state->msg->data) 177 state->resp != (struct ec_response_motion_sense *)state->msg->data)
@@ -118,7 +203,7 @@ static ssize_t cros_ec_sensors_calibrate(struct iio_dev *indio_dev,
118 } else { 203 } else {
119 /* Save values */ 204 /* Save values */
120 for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++) 205 for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
121 st->calib[i] = st->resp->perform_calib.offset[i]; 206 st->calib[i].offset = st->resp->perform_calib.offset[i];
122 } 207 }
123 mutex_unlock(&st->cmd_lock); 208 mutex_unlock(&st->cmd_lock);
124 209
@@ -268,6 +353,7 @@ static int cros_ec_sensors_read_data_unsafe(struct iio_dev *indio_dev,
268 if (ret < 0) 353 if (ret < 0)
269 return ret; 354 return ret;
270 355
356 *data *= st->sign[i];
271 data++; 357 data++;
272 } 358 }
273 359
@@ -396,7 +482,7 @@ int cros_ec_sensors_core_read(struct cros_ec_sensors_core_state *st,
396 struct iio_chan_spec const *chan, 482 struct iio_chan_spec const *chan,
397 int *val, int *val2, long mask) 483 int *val, int *val2, long mask)
398{ 484{
399 int ret = IIO_VAL_INT; 485 int ret;
400 486
401 switch (mask) { 487 switch (mask) {
402 case IIO_CHAN_INFO_SAMP_FREQ: 488 case IIO_CHAN_INFO_SAMP_FREQ:
@@ -404,22 +490,27 @@ int cros_ec_sensors_core_read(struct cros_ec_sensors_core_state *st,
404 st->param.ec_rate.data = 490 st->param.ec_rate.data =
405 EC_MOTION_SENSE_NO_VALUE; 491 EC_MOTION_SENSE_NO_VALUE;
406 492
407 if (cros_ec_motion_send_host_cmd(st, 0)) 493 ret = cros_ec_motion_send_host_cmd(st, 0);
408 ret = -EIO; 494 if (ret)
409 else 495 break;
410 *val = st->resp->ec_rate.ret; 496
497 *val = st->resp->ec_rate.ret;
498 ret = IIO_VAL_INT;
411 break; 499 break;
412 case IIO_CHAN_INFO_FREQUENCY: 500 case IIO_CHAN_INFO_FREQUENCY:
413 st->param.cmd = MOTIONSENSE_CMD_SENSOR_ODR; 501 st->param.cmd = MOTIONSENSE_CMD_SENSOR_ODR;
414 st->param.sensor_odr.data = 502 st->param.sensor_odr.data =
415 EC_MOTION_SENSE_NO_VALUE; 503 EC_MOTION_SENSE_NO_VALUE;
416 504
417 if (cros_ec_motion_send_host_cmd(st, 0)) 505 ret = cros_ec_motion_send_host_cmd(st, 0);
418 ret = -EIO; 506 if (ret)
419 else 507 break;
420 *val = st->resp->sensor_odr.ret; 508
509 *val = st->resp->sensor_odr.ret;
510 ret = IIO_VAL_INT;
421 break; 511 break;
422 default: 512 default:
513 ret = -EINVAL;
423 break; 514 break;
424 } 515 }
425 516
@@ -427,11 +518,32 @@ int cros_ec_sensors_core_read(struct cros_ec_sensors_core_state *st,
427} 518}
428EXPORT_SYMBOL_GPL(cros_ec_sensors_core_read); 519EXPORT_SYMBOL_GPL(cros_ec_sensors_core_read);
429 520
521int cros_ec_sensors_core_read_avail(struct iio_dev *indio_dev,
522 struct iio_chan_spec const *chan,
523 const int **vals,
524 int *type,
525 int *length,
526 long mask)
527{
528 struct cros_ec_sensors_core_state *state = iio_priv(indio_dev);
529
530 switch (mask) {
531 case IIO_CHAN_INFO_SAMP_FREQ:
532 *length = ARRAY_SIZE(state->frequencies);
533 *vals = (const int *)&state->frequencies;
534 *type = IIO_VAL_INT;
535 return IIO_AVAIL_LIST;
536 }
537
538 return -EINVAL;
539}
540EXPORT_SYMBOL_GPL(cros_ec_sensors_core_read_avail);
541
430int cros_ec_sensors_core_write(struct cros_ec_sensors_core_state *st, 542int cros_ec_sensors_core_write(struct cros_ec_sensors_core_state *st,
431 struct iio_chan_spec const *chan, 543 struct iio_chan_spec const *chan,
432 int val, int val2, long mask) 544 int val, int val2, long mask)
433{ 545{
434 int ret = 0; 546 int ret;
435 547
436 switch (mask) { 548 switch (mask) {
437 case IIO_CHAN_INFO_FREQUENCY: 549 case IIO_CHAN_INFO_FREQUENCY:
@@ -441,17 +553,16 @@ int cros_ec_sensors_core_write(struct cros_ec_sensors_core_state *st,
441 /* Always roundup, so caller gets at least what it asks for. */ 553 /* Always roundup, so caller gets at least what it asks for. */
442 st->param.sensor_odr.roundup = 1; 554 st->param.sensor_odr.roundup = 1;
443 555
444 if (cros_ec_motion_send_host_cmd(st, 0)) 556 ret = cros_ec_motion_send_host_cmd(st, 0);
445 ret = -EIO;
446 break; 557 break;
447 case IIO_CHAN_INFO_SAMP_FREQ: 558 case IIO_CHAN_INFO_SAMP_FREQ:
448 st->param.cmd = MOTIONSENSE_CMD_EC_RATE; 559 st->param.cmd = MOTIONSENSE_CMD_EC_RATE;
449 st->param.ec_rate.data = val; 560 st->param.ec_rate.data = val;
450 561
451 if (cros_ec_motion_send_host_cmd(st, 0)) 562 ret = cros_ec_motion_send_host_cmd(st, 0);
452 ret = -EIO; 563 if (ret)
453 else 564 break;
454 st->curr_sampl_freq = val; 565 st->curr_sampl_freq = val;
455 break; 566 break;
456 default: 567 default:
457 ret = -EINVAL; 568 ret = -EINVAL;
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index a8a3fe428d8d..442ff787f7af 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -8,11 +8,16 @@
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/interrupt.h> 9#include <linux/interrupt.h>
10#include <linux/irq.h> 10#include <linux/irq.h>
11#include <linux/kernel.h>
11#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/time.h>
14
12#include <linux/hid-sensor-hub.h> 15#include <linux/hid-sensor-hub.h>
13#include <linux/iio/iio.h> 16#include <linux/iio/iio.h>
14#include <linux/iio/sysfs.h> 17#include <linux/iio/sysfs.h>
15 18
19#define HZ_PER_MHZ 1000000L
20
16static struct { 21static struct {
17 u32 usage_id; 22 u32 usage_id;
18 int unit; /* 0 for default others from HID sensor spec */ 23 int unit; /* 0 for default others from HID sensor spec */
@@ -68,16 +73,6 @@ static struct {
68 {HID_USAGE_SENSOR_HUMIDITY, 0, 1000, 0}, 73 {HID_USAGE_SENSOR_HUMIDITY, 0, 1000, 0},
69}; 74};
70 75
71static int pow_10(unsigned power)
72{
73 int i;
74 int ret = 1;
75 for (i = 0; i < power; ++i)
76 ret = ret * 10;
77
78 return ret;
79}
80
81static void simple_div(int dividend, int divisor, int *whole, 76static void simple_div(int dividend, int divisor, int *whole,
82 int *micro_frac) 77 int *micro_frac)
83{ 78{
@@ -96,14 +91,16 @@ static void simple_div(int dividend, int divisor, int *whole,
96 rem *= 10; 91 rem *= 10;
97 exp++; 92 exp++;
98 } 93 }
99 *micro_frac = (rem / divisor) * pow_10(6-exp); 94 *micro_frac = (rem / divisor) * int_pow(10, 6 - exp);
100 } 95 }
101} 96}
102 97
103static void split_micro_fraction(unsigned int no, int exp, int *val1, int *val2) 98static void split_micro_fraction(unsigned int no, int exp, int *val1, int *val2)
104{ 99{
105 *val1 = no/pow_10(exp); 100 int divisor = int_pow(10, exp);
106 *val2 = no%pow_10(exp) * pow_10(6-exp); 101
102 *val1 = no / divisor;
103 *val2 = no % divisor * int_pow(10, 6 - exp);
107} 104}
108 105
109/* 106/*
@@ -125,7 +122,7 @@ static void convert_from_vtf_format(u32 value, int size, int exp,
125 } 122 }
126 exp = hid_sensor_convert_exponent(exp); 123 exp = hid_sensor_convert_exponent(exp);
127 if (exp >= 0) { 124 if (exp >= 0) {
128 *val1 = sign * value * pow_10(exp); 125 *val1 = sign * value * int_pow(10, exp);
129 *val2 = 0; 126 *val2 = 0;
130 } else { 127 } else {
131 split_micro_fraction(value, -exp, val1, val2); 128 split_micro_fraction(value, -exp, val1, val2);
@@ -138,6 +135,7 @@ static void convert_from_vtf_format(u32 value, int size, int exp,
138 135
139static u32 convert_to_vtf_format(int size, int exp, int val1, int val2) 136static u32 convert_to_vtf_format(int size, int exp, int val1, int val2)
140{ 137{
138 int divisor;
141 u32 value; 139 u32 value;
142 int sign = 1; 140 int sign = 1;
143 141
@@ -145,10 +143,13 @@ static u32 convert_to_vtf_format(int size, int exp, int val1, int val2)
145 sign = -1; 143 sign = -1;
146 exp = hid_sensor_convert_exponent(exp); 144 exp = hid_sensor_convert_exponent(exp);
147 if (exp < 0) { 145 if (exp < 0) {
148 value = abs(val1) * pow_10(-exp); 146 divisor = int_pow(10, 6 + exp);
149 value += abs(val2) / pow_10(6+exp); 147 value = abs(val1) * int_pow(10, -exp);
150 } else 148 value += abs(val2) / divisor;
151 value = abs(val1) / pow_10(exp); 149 } else {
150 divisor = int_pow(10, exp);
151 value = abs(val1) / divisor;
152 }
152 if (sign < 0) 153 if (sign < 0)
153 value = ((1LL << (size * 8)) - value); 154 value = ((1LL << (size * 8)) - value);
154 155
@@ -211,12 +212,12 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
211 if (val1 < 0 || val2 < 0) 212 if (val1 < 0 || val2 < 0)
212 return -EINVAL; 213 return -EINVAL;
213 214
214 value = val1 * pow_10(6) + val2; 215 value = val1 * HZ_PER_MHZ + val2;
215 if (value) { 216 if (value) {
216 if (st->poll.units == HID_USAGE_SENSOR_UNITS_MILLISECOND) 217 if (st->poll.units == HID_USAGE_SENSOR_UNITS_MILLISECOND)
217 value = pow_10(9)/value; 218 value = NSEC_PER_SEC / value;
218 else if (st->poll.units == HID_USAGE_SENSOR_UNITS_SECOND) 219 else if (st->poll.units == HID_USAGE_SENSOR_UNITS_SECOND)
219 value = pow_10(6)/value; 220 value = USEC_PER_SEC / value;
220 else 221 else
221 value = 0; 222 value = 0;
222 } 223 }
@@ -305,40 +306,44 @@ EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
305static void adjust_exponent_nano(int *val0, int *val1, int scale0, 306static void adjust_exponent_nano(int *val0, int *val1, int scale0,
306 int scale1, int exp) 307 int scale1, int exp)
307{ 308{
309 int divisor;
308 int i; 310 int i;
309 int x; 311 int x;
310 int res; 312 int res;
311 int rem; 313 int rem;
312 314
313 if (exp > 0) { 315 if (exp > 0) {
314 *val0 = scale0 * pow_10(exp); 316 *val0 = scale0 * int_pow(10, exp);
315 res = 0; 317 res = 0;
316 if (exp > 9) { 318 if (exp > 9) {
317 *val1 = 0; 319 *val1 = 0;
318 return; 320 return;
319 } 321 }
320 for (i = 0; i < exp; ++i) { 322 for (i = 0; i < exp; ++i) {
321 x = scale1 / pow_10(8 - i); 323 divisor = int_pow(10, 8 - i);
322 res += (pow_10(exp - 1 - i) * x); 324 x = scale1 / divisor;
323 scale1 = scale1 % pow_10(8 - i); 325 res += int_pow(10, exp - 1 - i) * x;
326 scale1 = scale1 % divisor;
324 } 327 }
325 *val0 += res; 328 *val0 += res;
326 *val1 = scale1 * pow_10(exp); 329 *val1 = scale1 * int_pow(10, exp);
327 } else if (exp < 0) { 330 } else if (exp < 0) {
328 exp = abs(exp); 331 exp = abs(exp);
329 if (exp > 9) { 332 if (exp > 9) {
330 *val0 = *val1 = 0; 333 *val0 = *val1 = 0;
331 return; 334 return;
332 } 335 }
333 *val0 = scale0 / pow_10(exp); 336 divisor = int_pow(10, exp);
334 rem = scale0 % pow_10(exp); 337 *val0 = scale0 / divisor;
338 rem = scale0 % divisor;
335 res = 0; 339 res = 0;
336 for (i = 0; i < (9 - exp); ++i) { 340 for (i = 0; i < (9 - exp); ++i) {
337 x = scale1 / pow_10(8 - i); 341 divisor = int_pow(10, 8 - i);
338 res += (pow_10(8 - exp - i) * x); 342 x = scale1 / divisor;
339 scale1 = scale1 % pow_10(8 - i); 343 res += int_pow(10, 8 - exp - i) * x;
344 scale1 = scale1 % divisor;
340 } 345 }
341 *val1 = rem * pow_10(9 - exp) + res; 346 *val1 = rem * int_pow(10, 9 - exp) + res;
342 } else { 347 } else {
343 *val0 = scale0; 348 *val0 = scale0;
344 *val1 = scale1; 349 *val1 = scale1;
diff --git a/drivers/iio/common/st_sensors/Kconfig b/drivers/iio/common/st_sensors/Kconfig
index 91b98e152d75..9364ec7a811f 100644
--- a/drivers/iio/common/st_sensors/Kconfig
+++ b/drivers/iio/common/st_sensors/Kconfig
@@ -5,9 +5,11 @@
5 5
6config IIO_ST_SENSORS_I2C 6config IIO_ST_SENSORS_I2C
7 tristate 7 tristate
8 select REGMAP_I2C
8 9
9config IIO_ST_SENSORS_SPI 10config IIO_ST_SENSORS_SPI
10 tristate 11 tristate
12 select REGMAP_SPI
11 13
12config IIO_ST_SENSORS_CORE 14config IIO_ST_SENSORS_CORE
13 tristate 15 tristate
diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c
index 4a68669dc555..eee30130ae23 100644
--- a/drivers/iio/common/st_sensors/st_sensors_buffer.c
+++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c
@@ -17,15 +17,16 @@
17#include <linux/iio/trigger_consumer.h> 17#include <linux/iio/trigger_consumer.h>
18#include <linux/iio/triggered_buffer.h> 18#include <linux/iio/triggered_buffer.h>
19#include <linux/irqreturn.h> 19#include <linux/irqreturn.h>
20#include <linux/regmap.h>
20 21
21#include <linux/iio/common/st_sensors.h> 22#include <linux/iio/common/st_sensors.h>
22 23
23 24
24static int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) 25static int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf)
25{ 26{
26 int i;
27 struct st_sensor_data *sdata = iio_priv(indio_dev); 27 struct st_sensor_data *sdata = iio_priv(indio_dev);
28 unsigned int num_data_channels = sdata->num_data_channels; 28 unsigned int num_data_channels = sdata->num_data_channels;
29 int i;
29 30
30 for_each_set_bit(i, indio_dev->active_scan_mask, num_data_channels) { 31 for_each_set_bit(i, indio_dev->active_scan_mask, num_data_channels) {
31 const struct iio_chan_spec *channel = &indio_dev->channels[i]; 32 const struct iio_chan_spec *channel = &indio_dev->channels[i];
@@ -36,11 +37,8 @@ static int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf)
36 channel->scan_type.storagebits >> 3; 37 channel->scan_type.storagebits >> 3;
37 38
38 buf = PTR_ALIGN(buf, storage_bytes); 39 buf = PTR_ALIGN(buf, storage_bytes);
39 if (sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev, 40 if (regmap_bulk_read(sdata->regmap, channel->address,
40 channel->address, 41 buf, bytes_to_read) < 0)
41 bytes_to_read, buf,
42 sdata->multiread_bit) <
43 bytes_to_read)
44 return -EIO; 42 return -EIO;
45 43
46 /* Advance the buffer pointer */ 44 /* Advance the buffer pointer */
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index 8b22dc241482..4a3064fb6cd9 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -15,6 +15,7 @@
15#include <linux/regulator/consumer.h> 15#include <linux/regulator/consumer.h>
16#include <linux/of.h> 16#include <linux/of.h>
17#include <linux/of_device.h> 17#include <linux/of_device.h>
18#include <linux/regmap.h>
18#include <asm/unaligned.h> 19#include <asm/unaligned.h>
19#include <linux/iio/common/st_sensors.h> 20#include <linux/iio/common/st_sensors.h>
20 21
@@ -28,19 +29,10 @@ static inline u32 st_sensors_get_unaligned_le24(const u8 *p)
28int st_sensors_write_data_with_mask(struct iio_dev *indio_dev, 29int st_sensors_write_data_with_mask(struct iio_dev *indio_dev,
29 u8 reg_addr, u8 mask, u8 data) 30 u8 reg_addr, u8 mask, u8 data)
30{ 31{
31 int err;
32 u8 new_data;
33 struct st_sensor_data *sdata = iio_priv(indio_dev); 32 struct st_sensor_data *sdata = iio_priv(indio_dev);
34 33
35 err = sdata->tf->read_byte(&sdata->tb, sdata->dev, reg_addr, &new_data); 34 return regmap_update_bits(sdata->regmap,
36 if (err < 0) 35 reg_addr, mask, data << __ffs(mask));
37 goto st_sensors_write_data_with_mask_error;
38
39 new_data = ((new_data & (~mask)) | ((data << __ffs(mask)) & mask));
40 err = sdata->tf->write_byte(&sdata->tb, sdata->dev, reg_addr, new_data);
41
42st_sensors_write_data_with_mask_error:
43 return err;
44} 36}
45 37
46int st_sensors_debugfs_reg_access(struct iio_dev *indio_dev, 38int st_sensors_debugfs_reg_access(struct iio_dev *indio_dev,
@@ -48,19 +40,15 @@ int st_sensors_debugfs_reg_access(struct iio_dev *indio_dev,
48 unsigned *readval) 40 unsigned *readval)
49{ 41{
50 struct st_sensor_data *sdata = iio_priv(indio_dev); 42 struct st_sensor_data *sdata = iio_priv(indio_dev);
51 u8 readdata;
52 int err; 43 int err;
53 44
54 if (!readval) 45 if (!readval)
55 return sdata->tf->write_byte(&sdata->tb, sdata->dev, 46 return regmap_write(sdata->regmap, reg, writeval);
56 (u8)reg, (u8)writeval);
57 47
58 err = sdata->tf->read_byte(&sdata->tb, sdata->dev, (u8)reg, &readdata); 48 err = regmap_read(sdata->regmap, reg, readval);
59 if (err < 0) 49 if (err < 0)
60 return err; 50 return err;
61 51
62 *readval = (unsigned)readdata;
63
64 return 0; 52 return 0;
65} 53}
66EXPORT_SYMBOL(st_sensors_debugfs_reg_access); 54EXPORT_SYMBOL(st_sensors_debugfs_reg_access);
@@ -545,7 +533,7 @@ st_sensors_match_scale_error:
545EXPORT_SYMBOL(st_sensors_set_fullscale_by_gain); 533EXPORT_SYMBOL(st_sensors_set_fullscale_by_gain);
546 534
547static int st_sensors_read_axis_data(struct iio_dev *indio_dev, 535static int st_sensors_read_axis_data(struct iio_dev *indio_dev,
548 struct iio_chan_spec const *ch, int *data) 536 struct iio_chan_spec const *ch, int *data)
549{ 537{
550 int err; 538 int err;
551 u8 *outdata; 539 u8 *outdata;
@@ -554,13 +542,12 @@ static int st_sensors_read_axis_data(struct iio_dev *indio_dev,
554 542
555 byte_for_channel = DIV_ROUND_UP(ch->scan_type.realbits + 543 byte_for_channel = DIV_ROUND_UP(ch->scan_type.realbits +
556 ch->scan_type.shift, 8); 544 ch->scan_type.shift, 8);
557 outdata = kmalloc(byte_for_channel, GFP_KERNEL); 545 outdata = kmalloc(byte_for_channel, GFP_DMA | GFP_KERNEL);
558 if (!outdata) 546 if (!outdata)
559 return -ENOMEM; 547 return -ENOMEM;
560 548
561 err = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev, 549 err = regmap_bulk_read(sdata->regmap, ch->address,
562 ch->address, byte_for_channel, 550 outdata, byte_for_channel);
563 outdata, sdata->multiread_bit);
564 if (err < 0) 551 if (err < 0)
565 goto st_sensors_free_memory; 552 goto st_sensors_free_memory;
566 553
@@ -608,69 +595,55 @@ out:
608} 595}
609EXPORT_SYMBOL(st_sensors_read_info_raw); 596EXPORT_SYMBOL(st_sensors_read_info_raw);
610 597
611static int st_sensors_init_interface_mode(struct iio_dev *indio_dev, 598/*
612 const struct st_sensor_settings *sensor_settings) 599 * st_sensors_get_settings_index() - get index of the sensor settings for a
600 * specific device from list of settings
601 * @name: device name buffer reference.
602 * @list: sensor settings list.
603 * @list_length: length of sensor settings list.
604 *
605 * Return: non negative number on success (valid index),
606 * negative error code otherwise.
607 */
608int st_sensors_get_settings_index(const char *name,
609 const struct st_sensor_settings *list,
610 const int list_length)
613{ 611{
614 struct st_sensor_data *sdata = iio_priv(indio_dev); 612 int i, n;
615 struct device_node *np = sdata->dev->of_node;
616 struct st_sensors_platform_data *pdata;
617 613
618 pdata = (struct st_sensors_platform_data *)sdata->dev->platform_data; 614 for (i = 0; i < list_length; i++) {
619 if (((np && of_property_read_bool(np, "spi-3wire")) || 615 for (n = 0; n < ST_SENSORS_MAX_4WAI; n++) {
620 (pdata && pdata->spi_3wire)) && sensor_settings->sim.addr) { 616 if (strcmp(name, list[i].sensors_supported[n]) == 0)
621 int err; 617 return i;
622
623 err = sdata->tf->write_byte(&sdata->tb, sdata->dev,
624 sensor_settings->sim.addr,
625 sensor_settings->sim.value);
626 if (err < 0) {
627 dev_err(&indio_dev->dev,
628 "failed to init interface mode\n");
629 return err;
630 } 618 }
631 } 619 }
632 620
633 return 0; 621 return -ENODEV;
634} 622}
623EXPORT_SYMBOL(st_sensors_get_settings_index);
635 624
636int st_sensors_check_device_support(struct iio_dev *indio_dev, 625/*
637 int num_sensors_list, 626 * st_sensors_verify_id() - verify sensor ID (WhoAmI) is matching with the
638 const struct st_sensor_settings *sensor_settings) 627 * expected value
628 * @indio_dev: IIO device reference.
629 *
630 * Return: 0 on success (valid sensor ID), else a negative error code.
631 */
632int st_sensors_verify_id(struct iio_dev *indio_dev)
639{ 633{
640 int i, n, err = 0;
641 u8 wai;
642 struct st_sensor_data *sdata = iio_priv(indio_dev); 634 struct st_sensor_data *sdata = iio_priv(indio_dev);
635 int wai, err;
643 636
644 for (i = 0; i < num_sensors_list; i++) { 637 if (sdata->sensor_settings->wai_addr) {
645 for (n = 0; n < ST_SENSORS_MAX_4WAI; n++) { 638 err = regmap_read(sdata->regmap,
646 if (strcmp(indio_dev->name, 639 sdata->sensor_settings->wai_addr, &wai);
647 sensor_settings[i].sensors_supported[n]) == 0) {
648 break;
649 }
650 }
651 if (n < ST_SENSORS_MAX_4WAI)
652 break;
653 }
654 if (i == num_sensors_list) {
655 dev_err(&indio_dev->dev, "device name %s not recognized.\n",
656 indio_dev->name);
657 return -ENODEV;
658 }
659
660 err = st_sensors_init_interface_mode(indio_dev, &sensor_settings[i]);
661 if (err < 0)
662 return err;
663
664 if (sensor_settings[i].wai_addr) {
665 err = sdata->tf->read_byte(&sdata->tb, sdata->dev,
666 sensor_settings[i].wai_addr, &wai);
667 if (err < 0) { 640 if (err < 0) {
668 dev_err(&indio_dev->dev, 641 dev_err(&indio_dev->dev,
669 "failed to read Who-Am-I register.\n"); 642 "failed to read Who-Am-I register.\n");
670 return err; 643 return err;
671 } 644 }
672 645
673 if (sensor_settings[i].wai != wai) { 646 if (sdata->sensor_settings->wai != wai) {
674 dev_err(&indio_dev->dev, 647 dev_err(&indio_dev->dev,
675 "%s: WhoAmI mismatch (0x%x).\n", 648 "%s: WhoAmI mismatch (0x%x).\n",
676 indio_dev->name, wai); 649 indio_dev->name, wai);
@@ -678,12 +651,9 @@ int st_sensors_check_device_support(struct iio_dev *indio_dev,
678 } 651 }
679 } 652 }
680 653
681 sdata->sensor_settings = 654 return 0;
682 (struct st_sensor_settings *)&sensor_settings[i];
683
684 return i;
685} 655}
686EXPORT_SYMBOL(st_sensors_check_device_support); 656EXPORT_SYMBOL(st_sensors_verify_id);
687 657
688ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev, 658ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
689 struct device_attribute *attr, char *buf) 659 struct device_attribute *attr, char *buf)
diff --git a/drivers/iio/common/st_sensors/st_sensors_i2c.c b/drivers/iio/common/st_sensors/st_sensors_i2c.c
index b1c9812407e7..aa89d54a7c59 100644
--- a/drivers/iio/common/st_sensors/st_sensors_i2c.c
+++ b/drivers/iio/common/st_sensors/st_sensors_i2c.c
@@ -13,68 +13,58 @@
13#include <linux/iio/iio.h> 13#include <linux/iio/iio.h>
14#include <linux/of_device.h> 14#include <linux/of_device.h>
15#include <linux/acpi.h> 15#include <linux/acpi.h>
16#include <linux/regmap.h>
16 17
17#include <linux/iio/common/st_sensors_i2c.h> 18#include <linux/iio/common/st_sensors_i2c.h>
18 19
19 20
20#define ST_SENSORS_I2C_MULTIREAD 0x80 21#define ST_SENSORS_I2C_MULTIREAD 0x80
21 22
22static unsigned int st_sensors_i2c_get_irq(struct iio_dev *indio_dev) 23static const struct regmap_config st_sensors_i2c_regmap_config = {
23{ 24 .reg_bits = 8,
24 struct st_sensor_data *sdata = iio_priv(indio_dev); 25 .val_bits = 8,
25 26};
26 return to_i2c_client(sdata->dev)->irq;
27}
28
29static int st_sensors_i2c_read_byte(struct st_sensor_transfer_buffer *tb,
30 struct device *dev, u8 reg_addr, u8 *res_byte)
31{
32 int err;
33
34 err = i2c_smbus_read_byte_data(to_i2c_client(dev), reg_addr);
35 if (err < 0)
36 goto st_accel_i2c_read_byte_error;
37
38 *res_byte = err & 0xff;
39
40st_accel_i2c_read_byte_error:
41 return err < 0 ? err : 0;
42}
43
44static int st_sensors_i2c_read_multiple_byte(
45 struct st_sensor_transfer_buffer *tb, struct device *dev,
46 u8 reg_addr, int len, u8 *data, bool multiread_bit)
47{
48 if (multiread_bit)
49 reg_addr |= ST_SENSORS_I2C_MULTIREAD;
50
51 return i2c_smbus_read_i2c_block_data_or_emulated(to_i2c_client(dev),
52 reg_addr, len, data);
53}
54
55static int st_sensors_i2c_write_byte(struct st_sensor_transfer_buffer *tb,
56 struct device *dev, u8 reg_addr, u8 data)
57{
58 return i2c_smbus_write_byte_data(to_i2c_client(dev), reg_addr, data);
59}
60 27
61static const struct st_sensor_transfer_function st_sensors_tf_i2c = { 28static const struct regmap_config st_sensors_i2c_regmap_multiread_bit_config = {
62 .read_byte = st_sensors_i2c_read_byte, 29 .reg_bits = 8,
63 .write_byte = st_sensors_i2c_write_byte, 30 .val_bits = 8,
64 .read_multiple_byte = st_sensors_i2c_read_multiple_byte, 31 .read_flag_mask = ST_SENSORS_I2C_MULTIREAD,
65}; 32};
66 33
67void st_sensors_i2c_configure(struct iio_dev *indio_dev, 34/*
68 struct i2c_client *client, struct st_sensor_data *sdata) 35 * st_sensors_i2c_configure() - configure I2C interface
36 * @indio_dev: IIO device reference.
37 * @client: i2c client reference.
38 *
39 * Return: 0 on success, else a negative error code.
40 */
41int st_sensors_i2c_configure(struct iio_dev *indio_dev,
42 struct i2c_client *client)
69{ 43{
44 struct st_sensor_data *sdata = iio_priv(indio_dev);
45 const struct regmap_config *config;
46
47 if (sdata->sensor_settings->multi_read_bit)
48 config = &st_sensors_i2c_regmap_multiread_bit_config;
49 else
50 config = &st_sensors_i2c_regmap_config;
51
52 sdata->regmap = devm_regmap_init_i2c(client, config);
53 if (IS_ERR(sdata->regmap)) {
54 dev_err(&client->dev, "Failed to register i2c regmap (%d)\n",
55 (int)PTR_ERR(sdata->regmap));
56 return PTR_ERR(sdata->regmap);
57 }
58
70 i2c_set_clientdata(client, indio_dev); 59 i2c_set_clientdata(client, indio_dev);
71 60
72 indio_dev->dev.parent = &client->dev; 61 indio_dev->dev.parent = &client->dev;
73 indio_dev->name = client->name; 62 indio_dev->name = client->name;
74 63
75 sdata->dev = &client->dev; 64 sdata->dev = &client->dev;
76 sdata->tf = &st_sensors_tf_i2c; 65 sdata->irq = client->irq;
77 sdata->get_irq_data_ready = st_sensors_i2c_get_irq; 66
67 return 0;
78} 68}
79EXPORT_SYMBOL(st_sensors_i2c_configure); 69EXPORT_SYMBOL(st_sensors_i2c_configure);
80 70
diff --git a/drivers/iio/common/st_sensors/st_sensors_spi.c b/drivers/iio/common/st_sensors/st_sensors_spi.c
index 2213843f02cb..2262f81b07c2 100644
--- a/drivers/iio/common/st_sensors/st_sensors_spi.c
+++ b/drivers/iio/common/st_sensors/st_sensors_spi.c
@@ -11,108 +11,108 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/iio/iio.h> 13#include <linux/iio/iio.h>
14#include <linux/regmap.h>
14 15
15#include <linux/iio/common/st_sensors_spi.h> 16#include <linux/iio/common/st_sensors_spi.h>
16 17#include "st_sensors_core.h"
17 18
18#define ST_SENSORS_SPI_MULTIREAD 0xc0 19#define ST_SENSORS_SPI_MULTIREAD 0xc0
19#define ST_SENSORS_SPI_READ 0x80
20 20
21static unsigned int st_sensors_spi_get_irq(struct iio_dev *indio_dev) 21static const struct regmap_config st_sensors_spi_regmap_config = {
22{ 22 .reg_bits = 8,
23 struct st_sensor_data *sdata = iio_priv(indio_dev); 23 .val_bits = 8,
24};
24 25
25 return to_spi_device(sdata->dev)->irq; 26static const struct regmap_config st_sensors_spi_regmap_multiread_bit_config = {
26} 27 .reg_bits = 8,
28 .val_bits = 8,
29 .read_flag_mask = ST_SENSORS_SPI_MULTIREAD,
30};
27 31
28static int st_sensors_spi_read(struct st_sensor_transfer_buffer *tb, 32/*
29 struct device *dev, u8 reg_addr, int len, u8 *data, bool multiread_bit) 33 * st_sensors_is_spi_3_wire() - check if SPI 3-wire mode has been selected
34 * @spi: spi device reference.
35 *
36 * Return: true if SPI 3-wire mode is selected, false otherwise.
37 */
38static bool st_sensors_is_spi_3_wire(struct spi_device *spi)
30{ 39{
31 int err; 40 struct device_node *np = spi->dev.of_node;
32 41 struct st_sensors_platform_data *pdata;
33 struct spi_transfer xfers[] = {
34 {
35 .tx_buf = tb->tx_buf,
36 .bits_per_word = 8,
37 .len = 1,
38 },
39 {
40 .rx_buf = tb->rx_buf,
41 .bits_per_word = 8,
42 .len = len,
43 }
44 };
45
46 mutex_lock(&tb->buf_lock);
47 if ((multiread_bit) && (len > 1))
48 tb->tx_buf[0] = reg_addr | ST_SENSORS_SPI_MULTIREAD;
49 else
50 tb->tx_buf[0] = reg_addr | ST_SENSORS_SPI_READ;
51 42
52 err = spi_sync_transfer(to_spi_device(dev), xfers, ARRAY_SIZE(xfers)); 43 pdata = (struct st_sensors_platform_data *)spi->dev.platform_data;
53 if (err) 44 if ((np && of_property_read_bool(np, "spi-3wire")) ||
54 goto acc_spi_read_error; 45 (pdata && pdata->spi_3wire)) {
46 return true;
47 }
55 48
56 memcpy(data, tb->rx_buf, len); 49 return false;
57 mutex_unlock(&tb->buf_lock);
58 return len;
59
60acc_spi_read_error:
61 mutex_unlock(&tb->buf_lock);
62 return err;
63} 50}
64 51
65static int st_sensors_spi_read_byte(struct st_sensor_transfer_buffer *tb, 52/*
66 struct device *dev, u8 reg_addr, u8 *res_byte) 53 * st_sensors_configure_spi_3_wire() - configure SPI 3-wire if needed
54 * @spi: spi device reference.
55 * @settings: sensor specific settings reference.
56 *
57 * Return: 0 on success, else a negative error code.
58 */
59static int st_sensors_configure_spi_3_wire(struct spi_device *spi,
60 struct st_sensor_settings *settings)
67{ 61{
68 return st_sensors_spi_read(tb, dev, reg_addr, 1, res_byte, false); 62 if (settings->sim.addr) {
69} 63 u8 buffer[] = {
64 settings->sim.addr,
65 settings->sim.value
66 };
70 67
71static int st_sensors_spi_read_multiple_byte( 68 return spi_write(spi, buffer, 2);
72 struct st_sensor_transfer_buffer *tb, struct device *dev, 69 }
73 u8 reg_addr, int len, u8 *data, bool multiread_bit) 70
74{ 71 return 0;
75 return st_sensors_spi_read(tb, dev, reg_addr, len, data, multiread_bit);
76} 72}
77 73
78static int st_sensors_spi_write_byte(struct st_sensor_transfer_buffer *tb, 74/*
79 struct device *dev, u8 reg_addr, u8 data) 75 * st_sensors_spi_configure() - configure SPI interface
76 * @indio_dev: IIO device reference.
77 * @spi: spi device reference.
78 *
79 * Return: 0 on success, else a negative error code.
80 */
81int st_sensors_spi_configure(struct iio_dev *indio_dev,
82 struct spi_device *spi)
80{ 83{
84 struct st_sensor_data *sdata = iio_priv(indio_dev);
85 const struct regmap_config *config;
81 int err; 86 int err;
82 87
83 struct spi_transfer xfers = { 88 if (st_sensors_is_spi_3_wire(spi)) {
84 .tx_buf = tb->tx_buf, 89 err = st_sensors_configure_spi_3_wire(spi,
85 .bits_per_word = 8, 90 sdata->sensor_settings);
86 .len = 2, 91 if (err < 0)
87 }; 92 return err;
93 }
88 94
89 mutex_lock(&tb->buf_lock); 95 if (sdata->sensor_settings->multi_read_bit)
90 tb->tx_buf[0] = reg_addr; 96 config = &st_sensors_spi_regmap_multiread_bit_config;
91 tb->tx_buf[1] = data; 97 else
92 98 config = &st_sensors_spi_regmap_config;
93 err = spi_sync_transfer(to_spi_device(dev), &xfers, 1);
94 mutex_unlock(&tb->buf_lock);
95 99
96 return err; 100 sdata->regmap = devm_regmap_init_spi(spi, config);
97} 101 if (IS_ERR(sdata->regmap)) {
102 dev_err(&spi->dev, "Failed to register spi regmap (%d)\n",
103 (int)PTR_ERR(sdata->regmap));
104 return PTR_ERR(sdata->regmap);
105 }
98 106
99static const struct st_sensor_transfer_function st_sensors_tf_spi = {
100 .read_byte = st_sensors_spi_read_byte,
101 .write_byte = st_sensors_spi_write_byte,
102 .read_multiple_byte = st_sensors_spi_read_multiple_byte,
103};
104
105void st_sensors_spi_configure(struct iio_dev *indio_dev,
106 struct spi_device *spi, struct st_sensor_data *sdata)
107{
108 spi_set_drvdata(spi, indio_dev); 107 spi_set_drvdata(spi, indio_dev);
109 108
110 indio_dev->dev.parent = &spi->dev; 109 indio_dev->dev.parent = &spi->dev;
111 indio_dev->name = spi->modalias; 110 indio_dev->name = spi->modalias;
112 111
113 sdata->dev = &spi->dev; 112 sdata->dev = &spi->dev;
114 sdata->tf = &st_sensors_tf_spi; 113 sdata->irq = spi->irq;
115 sdata->get_irq_data_ready = st_sensors_spi_get_irq; 114
115 return 0;
116} 116}
117EXPORT_SYMBOL(st_sensors_spi_configure); 117EXPORT_SYMBOL(st_sensors_spi_configure);
118 118
diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c b/drivers/iio/common/st_sensors/st_sensors_trigger.c
index 630c8cb35e8b..4a2efa00f7f2 100644
--- a/drivers/iio/common/st_sensors/st_sensors_trigger.c
+++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c
@@ -13,6 +13,7 @@
13#include <linux/iio/iio.h> 13#include <linux/iio/iio.h>
14#include <linux/iio/trigger.h> 14#include <linux/iio/trigger.h>
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16#include <linux/regmap.h>
16#include <linux/iio/common/st_sensors.h> 17#include <linux/iio/common/st_sensors.h>
17#include "st_sensors_core.h" 18#include "st_sensors_core.h"
18 19
@@ -26,8 +27,7 @@
26static int st_sensors_new_samples_available(struct iio_dev *indio_dev, 27static int st_sensors_new_samples_available(struct iio_dev *indio_dev,
27 struct st_sensor_data *sdata) 28 struct st_sensor_data *sdata)
28{ 29{
29 u8 status; 30 int ret, status;
30 int ret;
31 31
32 /* How would I know if I can't check it? */ 32 /* How would I know if I can't check it? */
33 if (!sdata->sensor_settings->drdy_irq.stat_drdy.addr) 33 if (!sdata->sensor_settings->drdy_irq.stat_drdy.addr)
@@ -37,9 +37,9 @@ static int st_sensors_new_samples_available(struct iio_dev *indio_dev,
37 if (!indio_dev->active_scan_mask) 37 if (!indio_dev->active_scan_mask)
38 return 0; 38 return 0;
39 39
40 ret = sdata->tf->read_byte(&sdata->tb, sdata->dev, 40 ret = regmap_read(sdata->regmap,
41 sdata->sensor_settings->drdy_irq.stat_drdy.addr, 41 sdata->sensor_settings->drdy_irq.stat_drdy.addr,
42 &status); 42 &status);
43 if (ret < 0) { 43 if (ret < 0) {
44 dev_err(sdata->dev, 44 dev_err(sdata->dev,
45 "error checking samples available\n"); 45 "error checking samples available\n");
@@ -121,9 +121,9 @@ static irqreturn_t st_sensors_irq_thread(int irq, void *p)
121int st_sensors_allocate_trigger(struct iio_dev *indio_dev, 121int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
122 const struct iio_trigger_ops *trigger_ops) 122 const struct iio_trigger_ops *trigger_ops)
123{ 123{
124 int err, irq;
125 struct st_sensor_data *sdata = iio_priv(indio_dev); 124 struct st_sensor_data *sdata = iio_priv(indio_dev);
126 unsigned long irq_trig; 125 unsigned long irq_trig;
126 int err;
127 127
128 sdata->trig = iio_trigger_alloc("%s-trigger", indio_dev->name); 128 sdata->trig = iio_trigger_alloc("%s-trigger", indio_dev->name);
129 if (sdata->trig == NULL) { 129 if (sdata->trig == NULL) {
@@ -135,8 +135,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
135 sdata->trig->ops = trigger_ops; 135 sdata->trig->ops = trigger_ops;
136 sdata->trig->dev.parent = sdata->dev; 136 sdata->trig->dev.parent = sdata->dev;
137 137
138 irq = sdata->get_irq_data_ready(indio_dev); 138 irq_trig = irqd_get_trigger_type(irq_get_irq_data(sdata->irq));
139 irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq));
140 /* 139 /*
141 * If the IRQ is triggered on falling edge, we need to mark the 140 * If the IRQ is triggered on falling edge, we need to mark the
142 * interrupt as active low, if the hardware supports this. 141 * interrupt as active low, if the hardware supports this.
@@ -206,12 +205,12 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
206 sdata->sensor_settings->drdy_irq.stat_drdy.addr) 205 sdata->sensor_settings->drdy_irq.stat_drdy.addr)
207 irq_trig |= IRQF_SHARED; 206 irq_trig |= IRQF_SHARED;
208 207
209 err = request_threaded_irq(sdata->get_irq_data_ready(indio_dev), 208 err = request_threaded_irq(sdata->irq,
210 st_sensors_irq_handler, 209 st_sensors_irq_handler,
211 st_sensors_irq_thread, 210 st_sensors_irq_thread,
212 irq_trig, 211 irq_trig,
213 sdata->trig->name, 212 sdata->trig->name,
214 sdata->trig); 213 sdata->trig);
215 if (err) { 214 if (err) {
216 dev_err(&indio_dev->dev, "failed to request trigger IRQ.\n"); 215 dev_err(&indio_dev->dev, "failed to request trigger IRQ.\n");
217 goto iio_trigger_free; 216 goto iio_trigger_free;
@@ -227,7 +226,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
227 return 0; 226 return 0;
228 227
229iio_trigger_register_error: 228iio_trigger_register_error:
230 free_irq(sdata->get_irq_data_ready(indio_dev), sdata->trig); 229 free_irq(sdata->irq, sdata->trig);
231iio_trigger_free: 230iio_trigger_free:
232 iio_trigger_free(sdata->trig); 231 iio_trigger_free(sdata->trig);
233 return err; 232 return err;
@@ -239,7 +238,7 @@ void st_sensors_deallocate_trigger(struct iio_dev *indio_dev)
239 struct st_sensor_data *sdata = iio_priv(indio_dev); 238 struct st_sensor_data *sdata = iio_priv(indio_dev);
240 239
241 iio_trigger_unregister(sdata->trig); 240 iio_trigger_unregister(sdata->trig);
242 free_irq(sdata->get_irq_data_ready(indio_dev), sdata->trig); 241 free_irq(sdata->irq, sdata->trig);
243 iio_trigger_free(sdata->trig); 242 iio_trigger_free(sdata->trig);
244} 243}
245EXPORT_SYMBOL(st_sensors_deallocate_trigger); 244EXPORT_SYMBOL(st_sensors_deallocate_trigger);
diff --git a/drivers/iio/dac/ad5380.c b/drivers/iio/dac/ad5380.c
index 4335214800d2..2ebe08326048 100644
--- a/drivers/iio/dac/ad5380.c
+++ b/drivers/iio/dac/ad5380.c
@@ -220,7 +220,7 @@ static int ad5380_read_raw(struct iio_dev *indio_dev,
220 if (ret) 220 if (ret)
221 return ret; 221 return ret;
222 *val >>= chan->scan_type.shift; 222 *val >>= chan->scan_type.shift;
223 val -= (1 << chan->scan_type.realbits) / 2; 223 *val -= (1 << chan->scan_type.realbits) / 2;
224 return IIO_VAL_INT; 224 return IIO_VAL_INT;
225 case IIO_CHAN_INFO_SCALE: 225 case IIO_CHAN_INFO_SCALE:
226 *val = 2 * st->vref; 226 *val = 2 * st->vref;
diff --git a/drivers/iio/gyro/st_gyro.h b/drivers/iio/gyro/st_gyro.h
index 460d190be4a4..592f6b34e987 100644
--- a/drivers/iio/gyro/st_gyro.h
+++ b/drivers/iio/gyro/st_gyro.h
@@ -32,6 +32,7 @@ static const struct st_sensors_platform_data gyro_pdata = {
32 .drdy_int_pin = 2, 32 .drdy_int_pin = 2,
33}; 33};
34 34
35const struct st_sensor_settings *st_gyro_get_settings(const char *name);
35int st_gyro_common_probe(struct iio_dev *indio_dev); 36int st_gyro_common_probe(struct iio_dev *indio_dev);
36void st_gyro_common_remove(struct iio_dev *indio_dev); 37void st_gyro_common_remove(struct iio_dev *indio_dev);
37 38
diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c
index 6e362f735e92..7465ad62391c 100644
--- a/drivers/iio/gyro/st_gyro_buffer.c
+++ b/drivers/iio/gyro/st_gyro_buffer.c
@@ -29,61 +29,51 @@ int st_gyro_trig_set_state(struct iio_trigger *trig, bool state)
29 return st_sensors_set_dataready_irq(indio_dev, state); 29 return st_sensors_set_dataready_irq(indio_dev, state);
30} 30}
31 31
32static int st_gyro_buffer_preenable(struct iio_dev *indio_dev)
33{
34 return st_sensors_set_enable(indio_dev, true);
35}
36
37static int st_gyro_buffer_postenable(struct iio_dev *indio_dev) 32static int st_gyro_buffer_postenable(struct iio_dev *indio_dev)
38{ 33{
39 int err; 34 int err;
40 struct st_sensor_data *gdata = iio_priv(indio_dev);
41 35
42 gdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); 36 err = iio_triggered_buffer_postenable(indio_dev);
43 if (gdata->buffer_data == NULL) { 37 if (err < 0)
44 err = -ENOMEM; 38 return err;
45 goto allocate_memory_error;
46 }
47 39
48 err = st_sensors_set_axis_enable(indio_dev, 40 err = st_sensors_set_axis_enable(indio_dev,
49 (u8)indio_dev->active_scan_mask[0]); 41 (u8)indio_dev->active_scan_mask[0]);
50 if (err < 0) 42 if (err < 0)
51 goto st_gyro_buffer_postenable_error; 43 goto st_gyro_buffer_predisable;
52 44
53 err = iio_triggered_buffer_postenable(indio_dev); 45 err = st_sensors_set_enable(indio_dev, true);
54 if (err < 0) 46 if (err < 0)
55 goto st_gyro_buffer_postenable_error; 47 goto st_gyro_buffer_enable_all_axis;
56 48
57 return err; 49 return 0;
58 50
59st_gyro_buffer_postenable_error: 51st_gyro_buffer_enable_all_axis:
60 kfree(gdata->buffer_data); 52 st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
61allocate_memory_error: 53st_gyro_buffer_predisable:
54 iio_triggered_buffer_predisable(indio_dev);
62 return err; 55 return err;
63} 56}
64 57
65static int st_gyro_buffer_predisable(struct iio_dev *indio_dev) 58static int st_gyro_buffer_predisable(struct iio_dev *indio_dev)
66{ 59{
67 int err; 60 int err, err2;
68 struct st_sensor_data *gdata = iio_priv(indio_dev);
69 61
70 err = iio_triggered_buffer_predisable(indio_dev); 62 err = st_sensors_set_enable(indio_dev, false);
71 if (err < 0) 63 if (err < 0)
72 goto st_gyro_buffer_predisable_error; 64 goto st_gyro_buffer_predisable;
73 65
74 err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS); 66 err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
75 if (err < 0)
76 goto st_gyro_buffer_predisable_error;
77 67
78 err = st_sensors_set_enable(indio_dev, false); 68st_gyro_buffer_predisable:
69 err2 = iio_triggered_buffer_predisable(indio_dev);
70 if (!err)
71 err = err2;
79 72
80st_gyro_buffer_predisable_error:
81 kfree(gdata->buffer_data);
82 return err; 73 return err;
83} 74}
84 75
85static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = { 76static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = {
86 .preenable = &st_gyro_buffer_preenable,
87 .postenable = &st_gyro_buffer_postenable, 77 .postenable = &st_gyro_buffer_postenable,
88 .predisable = &st_gyro_buffer_predisable, 78 .predisable = &st_gyro_buffer_predisable,
89}; 79};
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index e995dc77e30e..c0acbb5d2ffb 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -12,7 +12,6 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/errno.h> 13#include <linux/errno.h>
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/mutex.h>
16#include <linux/interrupt.h> 15#include <linux/interrupt.h>
17#include <linux/i2c.h> 16#include <linux/i2c.h>
18#include <linux/gpio.h> 17#include <linux/gpio.h>
@@ -368,28 +367,41 @@ static const struct iio_trigger_ops st_gyro_trigger_ops = {
368#define ST_GYRO_TRIGGER_OPS NULL 367#define ST_GYRO_TRIGGER_OPS NULL
369#endif 368#endif
370 369
370/*
371 * st_gyro_get_settings() - get sensor settings from device name
372 * @name: device name buffer reference.
373 *
374 * Return: valid reference on success, NULL otherwise.
375 */
376const struct st_sensor_settings *st_gyro_get_settings(const char *name)
377{
378 int index = st_sensors_get_settings_index(name,
379 st_gyro_sensors_settings,
380 ARRAY_SIZE(st_gyro_sensors_settings));
381 if (index < 0)
382 return NULL;
383
384 return &st_gyro_sensors_settings[index];
385}
386EXPORT_SYMBOL(st_gyro_get_settings);
387
371int st_gyro_common_probe(struct iio_dev *indio_dev) 388int st_gyro_common_probe(struct iio_dev *indio_dev)
372{ 389{
373 struct st_sensor_data *gdata = iio_priv(indio_dev); 390 struct st_sensor_data *gdata = iio_priv(indio_dev);
374 int irq = gdata->get_irq_data_ready(indio_dev);
375 int err; 391 int err;
376 392
377 indio_dev->modes = INDIO_DIRECT_MODE; 393 indio_dev->modes = INDIO_DIRECT_MODE;
378 indio_dev->info = &gyro_info; 394 indio_dev->info = &gyro_info;
379 mutex_init(&gdata->tb.buf_lock);
380 395
381 err = st_sensors_power_enable(indio_dev); 396 err = st_sensors_power_enable(indio_dev);
382 if (err) 397 if (err)
383 return err; 398 return err;
384 399
385 err = st_sensors_check_device_support(indio_dev, 400 err = st_sensors_verify_id(indio_dev);
386 ARRAY_SIZE(st_gyro_sensors_settings),
387 st_gyro_sensors_settings);
388 if (err < 0) 401 if (err < 0)
389 goto st_gyro_power_off; 402 goto st_gyro_power_off;
390 403
391 gdata->num_data_channels = ST_GYRO_NUMBER_DATA_CHANNELS; 404 gdata->num_data_channels = ST_GYRO_NUMBER_DATA_CHANNELS;
392 gdata->multiread_bit = gdata->sensor_settings->multi_read_bit;
393 indio_dev->channels = gdata->sensor_settings->ch; 405 indio_dev->channels = gdata->sensor_settings->ch;
394 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; 406 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
395 407
@@ -406,7 +418,7 @@ int st_gyro_common_probe(struct iio_dev *indio_dev)
406 if (err < 0) 418 if (err < 0)
407 goto st_gyro_power_off; 419 goto st_gyro_power_off;
408 420
409 if (irq > 0) { 421 if (gdata->irq > 0) {
410 err = st_sensors_allocate_trigger(indio_dev, 422 err = st_sensors_allocate_trigger(indio_dev,
411 ST_GYRO_TRIGGER_OPS); 423 ST_GYRO_TRIGGER_OPS);
412 if (err < 0) 424 if (err < 0)
@@ -423,7 +435,7 @@ int st_gyro_common_probe(struct iio_dev *indio_dev)
423 return 0; 435 return 0;
424 436
425st_gyro_device_register_error: 437st_gyro_device_register_error:
426 if (irq > 0) 438 if (gdata->irq > 0)
427 st_sensors_deallocate_trigger(indio_dev); 439 st_sensors_deallocate_trigger(indio_dev);
428st_gyro_probe_trigger_error: 440st_gyro_probe_trigger_error:
429 st_gyro_deallocate_ring(indio_dev); 441 st_gyro_deallocate_ring(indio_dev);
@@ -441,7 +453,7 @@ void st_gyro_common_remove(struct iio_dev *indio_dev)
441 st_sensors_power_disable(indio_dev); 453 st_sensors_power_disable(indio_dev);
442 454
443 iio_device_unregister(indio_dev); 455 iio_device_unregister(indio_dev);
444 if (gdata->get_irq_data_ready(indio_dev) > 0) 456 if (gdata->irq > 0)
445 st_sensors_deallocate_trigger(indio_dev); 457 st_sensors_deallocate_trigger(indio_dev);
446 458
447 st_gyro_deallocate_ring(indio_dev); 459 st_gyro_deallocate_ring(indio_dev);
diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c
index f2a8683db7d9..05a1a0874bd5 100644
--- a/drivers/iio/gyro/st_gyro_i2c.c
+++ b/drivers/iio/gyro/st_gyro_i2c.c
@@ -63,21 +63,33 @@ MODULE_DEVICE_TABLE(of, st_gyro_of_match);
63#endif 63#endif
64 64
65static int st_gyro_i2c_probe(struct i2c_client *client, 65static int st_gyro_i2c_probe(struct i2c_client *client,
66 const struct i2c_device_id *id) 66 const struct i2c_device_id *id)
67{ 67{
68 struct iio_dev *indio_dev; 68 const struct st_sensor_settings *settings;
69 struct st_sensor_data *gdata; 69 struct st_sensor_data *gdata;
70 struct iio_dev *indio_dev;
70 int err; 71 int err;
71 72
73 st_sensors_of_name_probe(&client->dev, st_gyro_of_match,
74 client->name, sizeof(client->name));
75
76 settings = st_gyro_get_settings(client->name);
77 if (!settings) {
78 dev_err(&client->dev, "device name %s not recognized.\n",
79 client->name);
80 return -ENODEV;
81 }
82
72 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*gdata)); 83 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*gdata));
73 if (!indio_dev) 84 if (!indio_dev)
74 return -ENOMEM; 85 return -ENOMEM;
75 86
76 gdata = iio_priv(indio_dev); 87 gdata = iio_priv(indio_dev);
77 st_sensors_of_name_probe(&client->dev, st_gyro_of_match, 88 gdata->sensor_settings = (struct st_sensor_settings *)settings;
78 client->name, sizeof(client->name));
79 89
80 st_sensors_i2c_configure(indio_dev, client, gdata); 90 err = st_sensors_i2c_configure(indio_dev, client);
91 if (err < 0)
92 return err;
81 93
82 err = st_gyro_common_probe(indio_dev); 94 err = st_gyro_common_probe(indio_dev);
83 if (err < 0) 95 if (err < 0)
diff --git a/drivers/iio/gyro/st_gyro_spi.c b/drivers/iio/gyro/st_gyro_spi.c
index 93c48248bea6..b5c624251231 100644
--- a/drivers/iio/gyro/st_gyro_spi.c
+++ b/drivers/iio/gyro/st_gyro_spi.c
@@ -69,19 +69,31 @@ MODULE_DEVICE_TABLE(of, st_gyro_of_match);
69 69
70static int st_gyro_spi_probe(struct spi_device *spi) 70static int st_gyro_spi_probe(struct spi_device *spi)
71{ 71{
72 struct iio_dev *indio_dev; 72 const struct st_sensor_settings *settings;
73 struct st_sensor_data *gdata; 73 struct st_sensor_data *gdata;
74 struct iio_dev *indio_dev;
74 int err; 75 int err;
75 76
77 st_sensors_of_name_probe(&spi->dev, st_gyro_of_match,
78 spi->modalias, sizeof(spi->modalias));
79
80 settings = st_gyro_get_settings(spi->modalias);
81 if (!settings) {
82 dev_err(&spi->dev, "device name %s not recognized.\n",
83 spi->modalias);
84 return -ENODEV;
85 }
86
76 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*gdata)); 87 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*gdata));
77 if (!indio_dev) 88 if (!indio_dev)
78 return -ENOMEM; 89 return -ENOMEM;
79 90
80 gdata = iio_priv(indio_dev); 91 gdata = iio_priv(indio_dev);
92 gdata->sensor_settings = (struct st_sensor_settings *)settings;
81 93
82 st_sensors_of_name_probe(&spi->dev, st_gyro_of_match, 94 err = st_sensors_spi_configure(indio_dev, spi);
83 spi->modalias, sizeof(spi->modalias)); 95 if (err < 0)
84 st_sensors_spi_configure(indio_dev, spi, gdata); 96 return err;
85 97
86 err = st_gyro_common_probe(indio_dev); 98 err = st_gyro_common_probe(indio_dev);
87 if (err < 0) 99 if (err < 0)
diff --git a/drivers/iio/humidity/am2315.c b/drivers/iio/humidity/am2315.c
index f18da7859229..3bac98e731d9 100644
--- a/drivers/iio/humidity/am2315.c
+++ b/drivers/iio/humidity/am2315.c
@@ -240,32 +240,15 @@ static int am2315_probe(struct i2c_client *client,
240 indio_dev->channels = am2315_channels; 240 indio_dev->channels = am2315_channels;
241 indio_dev->num_channels = ARRAY_SIZE(am2315_channels); 241 indio_dev->num_channels = ARRAY_SIZE(am2315_channels);
242 242
243 ret = iio_triggered_buffer_setup(indio_dev, iio_pollfunc_store_time, 243 ret = devm_iio_triggered_buffer_setup(&client->dev,
244 indio_dev, iio_pollfunc_store_time,
244 am2315_trigger_handler, NULL); 245 am2315_trigger_handler, NULL);
245 if (ret < 0) { 246 if (ret < 0) {
246 dev_err(&client->dev, "iio triggered buffer setup failed\n"); 247 dev_err(&client->dev, "iio triggered buffer setup failed\n");
247 return ret; 248 return ret;
248 } 249 }
249 250
250 ret = iio_device_register(indio_dev); 251 return devm_iio_device_register(&client->dev, indio_dev);
251 if (ret < 0)
252 goto err_buffer_cleanup;
253
254 return 0;
255
256err_buffer_cleanup:
257 iio_triggered_buffer_cleanup(indio_dev);
258 return ret;
259}
260
261static int am2315_remove(struct i2c_client *client)
262{
263 struct iio_dev *indio_dev = i2c_get_clientdata(client);
264
265 iio_device_unregister(indio_dev);
266 iio_triggered_buffer_cleanup(indio_dev);
267
268 return 0;
269} 252}
270 253
271static const struct i2c_device_id am2315_i2c_id[] = { 254static const struct i2c_device_id am2315_i2c_id[] = {
@@ -287,7 +270,6 @@ static struct i2c_driver am2315_driver = {
287 .acpi_match_table = ACPI_PTR(am2315_acpi_id), 270 .acpi_match_table = ACPI_PTR(am2315_acpi_id),
288 }, 271 },
289 .probe = am2315_probe, 272 .probe = am2315_probe,
290 .remove = am2315_remove,
291 .id_table = am2315_i2c_id, 273 .id_table = am2315_i2c_id,
292}; 274};
293 275
diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c
index 066e05f92081..bfe1cdb16846 100644
--- a/drivers/iio/humidity/hdc100x.c
+++ b/drivers/iio/humidity/hdc100x.c
@@ -385,28 +385,16 @@ static int hdc100x_probe(struct i2c_client *client,
385 hdc100x_set_it_time(data, 1, hdc100x_int_time[1][0]); 385 hdc100x_set_it_time(data, 1, hdc100x_int_time[1][0]);
386 hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE, 0); 386 hdc100x_update_config(data, HDC100X_REG_CONFIG_ACQ_MODE, 0);
387 387
388 ret = iio_triggered_buffer_setup(indio_dev, NULL, 388 ret = devm_iio_triggered_buffer_setup(&client->dev,
389 indio_dev, NULL,
389 hdc100x_trigger_handler, 390 hdc100x_trigger_handler,
390 &hdc_buffer_setup_ops); 391 &hdc_buffer_setup_ops);
391 if (ret < 0) { 392 if (ret < 0) {
392 dev_err(&client->dev, "iio triggered buffer setup failed\n"); 393 dev_err(&client->dev, "iio triggered buffer setup failed\n");
393 return ret; 394 return ret;
394 } 395 }
395 ret = iio_device_register(indio_dev);
396 if (ret < 0)
397 iio_triggered_buffer_cleanup(indio_dev);
398 396
399 return ret; 397 return devm_iio_device_register(&client->dev, indio_dev);
400}
401
402static int hdc100x_remove(struct i2c_client *client)
403{
404 struct iio_dev *indio_dev = i2c_get_clientdata(client);
405
406 iio_device_unregister(indio_dev);
407 iio_triggered_buffer_cleanup(indio_dev);
408
409 return 0;
410} 398}
411 399
412static const struct i2c_device_id hdc100x_id[] = { 400static const struct i2c_device_id hdc100x_id[] = {
@@ -436,7 +424,6 @@ static struct i2c_driver hdc100x_driver = {
436 .of_match_table = of_match_ptr(hdc100x_dt_ids), 424 .of_match_table = of_match_ptr(hdc100x_dt_ids),
437 }, 425 },
438 .probe = hdc100x_probe, 426 .probe = hdc100x_probe,
439 .remove = hdc100x_remove,
440 .id_table = hdc100x_id, 427 .id_table = hdc100x_id,
441}; 428};
442module_i2c_driver(hdc100x_driver); 429module_i2c_driver(hdc100x_driver);
diff --git a/drivers/iio/imu/Kconfig b/drivers/iio/imu/Kconfig
index 4957e6df447e..f3c7282321a8 100644
--- a/drivers/iio/imu/Kconfig
+++ b/drivers/iio/imu/Kconfig
@@ -17,6 +17,18 @@ config ADIS16400
17 adis16365, adis16400 and adis16405 triaxial inertial sensors 17 adis16365, adis16400 and adis16405 triaxial inertial sensors
18 (adis16400 series also have magnetometers). 18 (adis16400 series also have magnetometers).
19 19
20config ADIS16460
21 tristate "Analog Devices ADIS16460 and similar IMU driver"
22 depends on SPI
23 select IIO_ADIS_LIB
24 select IIO_ADIS_LIB_BUFFER if IIO_BUFFER
25 help
26 Say yes here to build support for Analog Devices ADIS16460 inertial
27 sensor.
28
29 To compile this driver as a module, choose M here: the module will be
30 called adis16460.
31
20config ADIS16480 32config ADIS16480
21 tristate "Analog Devices ADIS16480 and similar IMU driver" 33 tristate "Analog Devices ADIS16480 and similar IMU driver"
22 depends on SPI 34 depends on SPI
diff --git a/drivers/iio/imu/Makefile b/drivers/iio/imu/Makefile
index 9e452fce1aaf..4a6958865504 100644
--- a/drivers/iio/imu/Makefile
+++ b/drivers/iio/imu/Makefile
@@ -5,6 +5,7 @@
5 5
6# When adding new entries keep the list in alphabetical order 6# When adding new entries keep the list in alphabetical order
7obj-$(CONFIG_ADIS16400) += adis16400.o 7obj-$(CONFIG_ADIS16400) += adis16400.o
8obj-$(CONFIG_ADIS16460) += adis16460.o
8obj-$(CONFIG_ADIS16480) += adis16480.o 9obj-$(CONFIG_ADIS16480) += adis16480.o
9 10
10adis_lib-y += adis.o 11adis_lib-y += adis.o
diff --git a/drivers/iio/imu/adis.c b/drivers/iio/imu/adis.c
index 30281e91dbf9..1631c255deab 100644
--- a/drivers/iio/imu/adis.c
+++ b/drivers/iio/imu/adis.c
@@ -39,18 +39,24 @@ int adis_write_reg(struct adis *adis, unsigned int reg,
39 .len = 2, 39 .len = 2,
40 .cs_change = 1, 40 .cs_change = 1,
41 .delay_usecs = adis->data->write_delay, 41 .delay_usecs = adis->data->write_delay,
42 .cs_change_delay = adis->data->cs_change_delay,
43 .cs_change_delay_unit = SPI_DELAY_UNIT_USECS,
42 }, { 44 }, {
43 .tx_buf = adis->tx + 2, 45 .tx_buf = adis->tx + 2,
44 .bits_per_word = 8, 46 .bits_per_word = 8,
45 .len = 2, 47 .len = 2,
46 .cs_change = 1, 48 .cs_change = 1,
47 .delay_usecs = adis->data->write_delay, 49 .delay_usecs = adis->data->write_delay,
50 .cs_change_delay = adis->data->cs_change_delay,
51 .cs_change_delay_unit = SPI_DELAY_UNIT_USECS,
48 }, { 52 }, {
49 .tx_buf = adis->tx + 4, 53 .tx_buf = adis->tx + 4,
50 .bits_per_word = 8, 54 .bits_per_word = 8,
51 .len = 2, 55 .len = 2,
52 .cs_change = 1, 56 .cs_change = 1,
53 .delay_usecs = adis->data->write_delay, 57 .delay_usecs = adis->data->write_delay,
58 .cs_change_delay = adis->data->cs_change_delay,
59 .cs_change_delay_unit = SPI_DELAY_UNIT_USECS,
54 }, { 60 }, {
55 .tx_buf = adis->tx + 6, 61 .tx_buf = adis->tx + 6,
56 .bits_per_word = 8, 62 .bits_per_word = 8,
@@ -133,12 +139,16 @@ int adis_read_reg(struct adis *adis, unsigned int reg,
133 .len = 2, 139 .len = 2,
134 .cs_change = 1, 140 .cs_change = 1,
135 .delay_usecs = adis->data->write_delay, 141 .delay_usecs = adis->data->write_delay,
142 .cs_change_delay = adis->data->cs_change_delay,
143 .cs_change_delay_unit = SPI_DELAY_UNIT_USECS,
136 }, { 144 }, {
137 .tx_buf = adis->tx + 2, 145 .tx_buf = adis->tx + 2,
138 .bits_per_word = 8, 146 .bits_per_word = 8,
139 .len = 2, 147 .len = 2,
140 .cs_change = 1, 148 .cs_change = 1,
141 .delay_usecs = adis->data->read_delay, 149 .delay_usecs = adis->data->read_delay,
150 .cs_change_delay = adis->data->cs_change_delay,
151 .cs_change_delay_unit = SPI_DELAY_UNIT_USECS,
142 }, { 152 }, {
143 .tx_buf = adis->tx + 4, 153 .tx_buf = adis->tx + 4,
144 .rx_buf = adis->rx, 154 .rx_buf = adis->rx,
@@ -146,6 +156,8 @@ int adis_read_reg(struct adis *adis, unsigned int reg,
146 .len = 2, 156 .len = 2,
147 .cs_change = 1, 157 .cs_change = 1,
148 .delay_usecs = adis->data->read_delay, 158 .delay_usecs = adis->data->read_delay,
159 .cs_change_delay = adis->data->cs_change_delay,
160 .cs_change_delay_unit = SPI_DELAY_UNIT_USECS,
149 }, { 161 }, {
150 .rx_buf = adis->rx + 2, 162 .rx_buf = adis->rx + 2,
151 .bits_per_word = 8, 163 .bits_per_word = 8,
diff --git a/drivers/iio/imu/adis16460.c b/drivers/iio/imu/adis16460.c
new file mode 100644
index 000000000000..6aed9e84abbf
--- /dev/null
+++ b/drivers/iio/imu/adis16460.c
@@ -0,0 +1,489 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * ADIS16460 IMU driver
4 *
5 * Copyright 2019 Analog Devices Inc.
6 */
7
8#include <linux/delay.h>
9#include <linux/module.h>
10#include <linux/spi/spi.h>
11
12#include <linux/iio/iio.h>
13#include <linux/iio/imu/adis.h>
14
15#include <linux/debugfs.h>
16
17#define ADIS16460_REG_FLASH_CNT 0x00
18#define ADIS16460_REG_DIAG_STAT 0x02
19#define ADIS16460_REG_X_GYRO_LOW 0x04
20#define ADIS16460_REG_X_GYRO_OUT 0x06
21#define ADIS16460_REG_Y_GYRO_LOW 0x08
22#define ADIS16460_REG_Y_GYRO_OUT 0x0A
23#define ADIS16460_REG_Z_GYRO_LOW 0x0C
24#define ADIS16460_REG_Z_GYRO_OUT 0x0E
25#define ADIS16460_REG_X_ACCL_LOW 0x10
26#define ADIS16460_REG_X_ACCL_OUT 0x12
27#define ADIS16460_REG_Y_ACCL_LOW 0x14
28#define ADIS16460_REG_Y_ACCL_OUT 0x16
29#define ADIS16460_REG_Z_ACCL_LOW 0x18
30#define ADIS16460_REG_Z_ACCL_OUT 0x1A
31#define ADIS16460_REG_SMPL_CNTR 0x1C
32#define ADIS16460_REG_TEMP_OUT 0x1E
33#define ADIS16460_REG_X_DELT_ANG 0x24
34#define ADIS16460_REG_Y_DELT_ANG 0x26
35#define ADIS16460_REG_Z_DELT_ANG 0x28
36#define ADIS16460_REG_X_DELT_VEL 0x2A
37#define ADIS16460_REG_Y_DELT_VEL 0x2C
38#define ADIS16460_REG_Z_DELT_VEL 0x2E
39#define ADIS16460_REG_MSC_CTRL 0x32
40#define ADIS16460_REG_SYNC_SCAL 0x34
41#define ADIS16460_REG_DEC_RATE 0x36
42#define ADIS16460_REG_FLTR_CTRL 0x38
43#define ADIS16460_REG_GLOB_CMD 0x3E
44#define ADIS16460_REG_X_GYRO_OFF 0x40
45#define ADIS16460_REG_Y_GYRO_OFF 0x42
46#define ADIS16460_REG_Z_GYRO_OFF 0x44
47#define ADIS16460_REG_X_ACCL_OFF 0x46
48#define ADIS16460_REG_Y_ACCL_OFF 0x48
49#define ADIS16460_REG_Z_ACCL_OFF 0x4A
50#define ADIS16460_REG_LOT_ID1 0x52
51#define ADIS16460_REG_LOT_ID2 0x54
52#define ADIS16460_REG_PROD_ID 0x56
53#define ADIS16460_REG_SERIAL_NUM 0x58
54#define ADIS16460_REG_CAL_SGNTR 0x60
55#define ADIS16460_REG_CAL_CRC 0x62
56#define ADIS16460_REG_CODE_SGNTR 0x64
57#define ADIS16460_REG_CODE_CRC 0x66
58
59struct adis16460_chip_info {
60 unsigned int num_channels;
61 const struct iio_chan_spec *channels;
62 unsigned int gyro_max_val;
63 unsigned int gyro_max_scale;
64 unsigned int accel_max_val;
65 unsigned int accel_max_scale;
66};
67
68struct adis16460 {
69 const struct adis16460_chip_info *chip_info;
70 struct adis adis;
71};
72
73#ifdef CONFIG_DEBUG_FS
74
75static int adis16460_show_serial_number(void *arg, u64 *val)
76{
77 struct adis16460 *adis16460 = arg;
78 u16 serial;
79 int ret;
80
81 ret = adis_read_reg_16(&adis16460->adis, ADIS16460_REG_SERIAL_NUM,
82 &serial);
83 if (ret < 0)
84 return ret;
85
86 *val = serial;
87
88 return 0;
89}
90DEFINE_SIMPLE_ATTRIBUTE(adis16460_serial_number_fops,
91 adis16460_show_serial_number, NULL, "0x%.4llx\n");
92
93static int adis16460_show_product_id(void *arg, u64 *val)
94{
95 struct adis16460 *adis16460 = arg;
96 u16 prod_id;
97 int ret;
98
99 ret = adis_read_reg_16(&adis16460->adis, ADIS16460_REG_PROD_ID,
100 &prod_id);
101 if (ret < 0)
102 return ret;
103
104 *val = prod_id;
105
106 return 0;
107}
108DEFINE_SIMPLE_ATTRIBUTE(adis16460_product_id_fops,
109 adis16460_show_product_id, NULL, "%llu\n");
110
111static int adis16460_show_flash_count(void *arg, u64 *val)
112{
113 struct adis16460 *adis16460 = arg;
114 u32 flash_count;
115 int ret;
116
117 ret = adis_read_reg_32(&adis16460->adis, ADIS16460_REG_FLASH_CNT,
118 &flash_count);
119 if (ret < 0)
120 return ret;
121
122 *val = flash_count;
123
124 return 0;
125}
126DEFINE_SIMPLE_ATTRIBUTE(adis16460_flash_count_fops,
127 adis16460_show_flash_count, NULL, "%lld\n");
128
129static int adis16460_debugfs_init(struct iio_dev *indio_dev)
130{
131 struct adis16460 *adis16460 = iio_priv(indio_dev);
132
133 debugfs_create_file("serial_number", 0400, indio_dev->debugfs_dentry,
134 adis16460, &adis16460_serial_number_fops);
135 debugfs_create_file("product_id", 0400, indio_dev->debugfs_dentry,
136 adis16460, &adis16460_product_id_fops);
137 debugfs_create_file("flash_count", 0400, indio_dev->debugfs_dentry,
138 adis16460, &adis16460_flash_count_fops);
139
140 return 0;
141}
142
143#else
144
145static int adis16460_debugfs_init(struct iio_dev *indio_dev)
146{
147 return 0;
148}
149
150#endif
151
152static int adis16460_set_freq(struct iio_dev *indio_dev, int val, int val2)
153{
154 struct adis16460 *st = iio_priv(indio_dev);
155 int t;
156
157 t = val * 1000 + val2 / 1000;
158 if (t <= 0)
159 return -EINVAL;
160
161 t = 2048000 / t;
162 if (t > 2048)
163 t = 2048;
164
165 if (t != 0)
166 t--;
167
168 return adis_write_reg_16(&st->adis, ADIS16460_REG_DEC_RATE, t);
169}
170
171static int adis16460_get_freq(struct iio_dev *indio_dev, int *val, int *val2)
172{
173 struct adis16460 *st = iio_priv(indio_dev);
174 uint16_t t;
175 int ret;
176 unsigned int freq;
177
178 ret = adis_read_reg_16(&st->adis, ADIS16460_REG_DEC_RATE, &t);
179 if (ret < 0)
180 return ret;
181
182 freq = 2048000 / (t + 1);
183 *val = freq / 1000;
184 *val2 = (freq % 1000) * 1000;
185
186 return IIO_VAL_INT_PLUS_MICRO;
187}
188
189static int adis16460_read_raw(struct iio_dev *indio_dev,
190 const struct iio_chan_spec *chan, int *val, int *val2, long info)
191{
192 struct adis16460 *st = iio_priv(indio_dev);
193
194 switch (info) {
195 case IIO_CHAN_INFO_RAW:
196 return adis_single_conversion(indio_dev, chan, 0, val);
197 case IIO_CHAN_INFO_SCALE:
198 switch (chan->type) {
199 case IIO_ANGL_VEL:
200 *val = st->chip_info->gyro_max_scale;
201 *val2 = st->chip_info->gyro_max_val;
202 return IIO_VAL_FRACTIONAL;
203 case IIO_ACCEL:
204 *val = st->chip_info->accel_max_scale;
205 *val2 = st->chip_info->accel_max_val;
206 return IIO_VAL_FRACTIONAL;
207 case IIO_TEMP:
208 *val = 50; /* 50 milli degrees Celsius/LSB */
209 return IIO_VAL_INT;
210 default:
211 return -EINVAL;
212 }
213 case IIO_CHAN_INFO_OFFSET:
214 *val = 500; /* 25 degrees Celsius = 0x0000 */
215 return IIO_VAL_INT;
216 case IIO_CHAN_INFO_SAMP_FREQ:
217 return adis16460_get_freq(indio_dev, val, val2);
218 default:
219 return -EINVAL;
220 }
221}
222
223static int adis16460_write_raw(struct iio_dev *indio_dev,
224 const struct iio_chan_spec *chan, int val, int val2, long info)
225{
226 switch (info) {
227 case IIO_CHAN_INFO_SAMP_FREQ:
228 return adis16460_set_freq(indio_dev, val, val2);
229 default:
230 return -EINVAL;
231 }
232}
233
234enum {
235 ADIS16460_SCAN_GYRO_X,
236 ADIS16460_SCAN_GYRO_Y,
237 ADIS16460_SCAN_GYRO_Z,
238 ADIS16460_SCAN_ACCEL_X,
239 ADIS16460_SCAN_ACCEL_Y,
240 ADIS16460_SCAN_ACCEL_Z,
241 ADIS16460_SCAN_TEMP,
242};
243
244#define ADIS16460_MOD_CHANNEL(_type, _mod, _address, _si, _bits) \
245 { \
246 .type = (_type), \
247 .modified = 1, \
248 .channel2 = (_mod), \
249 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
250 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
251 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
252 .address = (_address), \
253 .scan_index = (_si), \
254 .scan_type = { \
255 .sign = 's', \
256 .realbits = (_bits), \
257 .storagebits = (_bits), \
258 .endianness = IIO_BE, \
259 }, \
260 }
261
262#define ADIS16460_GYRO_CHANNEL(_mod) \
263 ADIS16460_MOD_CHANNEL(IIO_ANGL_VEL, IIO_MOD_ ## _mod, \
264 ADIS16460_REG_ ## _mod ## _GYRO_LOW, ADIS16460_SCAN_GYRO_ ## _mod, \
265 32)
266
267#define ADIS16460_ACCEL_CHANNEL(_mod) \
268 ADIS16460_MOD_CHANNEL(IIO_ACCEL, IIO_MOD_ ## _mod, \
269 ADIS16460_REG_ ## _mod ## _ACCL_LOW, ADIS16460_SCAN_ACCEL_ ## _mod, \
270 32)
271
272#define ADIS16460_TEMP_CHANNEL() { \
273 .type = IIO_TEMP, \
274 .indexed = 1, \
275 .channel = 0, \
276 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
277 BIT(IIO_CHAN_INFO_SCALE) | \
278 BIT(IIO_CHAN_INFO_OFFSET), \
279 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
280 .address = ADIS16460_REG_TEMP_OUT, \
281 .scan_index = ADIS16460_SCAN_TEMP, \
282 .scan_type = { \
283 .sign = 's', \
284 .realbits = 16, \
285 .storagebits = 16, \
286 .endianness = IIO_BE, \
287 }, \
288 }
289
290static const struct iio_chan_spec adis16460_channels[] = {
291 ADIS16460_GYRO_CHANNEL(X),
292 ADIS16460_GYRO_CHANNEL(Y),
293 ADIS16460_GYRO_CHANNEL(Z),
294 ADIS16460_ACCEL_CHANNEL(X),
295 ADIS16460_ACCEL_CHANNEL(Y),
296 ADIS16460_ACCEL_CHANNEL(Z),
297 ADIS16460_TEMP_CHANNEL(),
298 IIO_CHAN_SOFT_TIMESTAMP(7)
299};
300
301static const struct adis16460_chip_info adis16460_chip_info = {
302 .channels = adis16460_channels,
303 .num_channels = ARRAY_SIZE(adis16460_channels),
304 /*
305 * storing the value in rad/degree and the scale in degree
306 * gives us the result in rad and better precession than
307 * storing the scale directly in rad.
308 */
309 .gyro_max_val = IIO_RAD_TO_DEGREE(200 << 16),
310 .gyro_max_scale = 1,
311 .accel_max_val = IIO_M_S_2_TO_G(20000 << 16),
312 .accel_max_scale = 5,
313};
314
315static const struct iio_info adis16460_info = {
316 .read_raw = &adis16460_read_raw,
317 .write_raw = &adis16460_write_raw,
318 .update_scan_mode = adis_update_scan_mode,
319 .debugfs_reg_access = adis_debugfs_reg_access,
320};
321
322static int adis16460_enable_irq(struct adis *adis, bool enable)
323{
324 /*
325 * There is no way to gate the data-ready signal internally inside the
326 * ADIS16460 :(
327 */
328 if (enable)
329 enable_irq(adis->spi->irq);
330 else
331 disable_irq(adis->spi->irq);
332
333 return 0;
334}
335
336static int adis16460_initial_setup(struct iio_dev *indio_dev)
337{
338 struct adis16460 *st = iio_priv(indio_dev);
339 uint16_t prod_id;
340 unsigned int device_id;
341 int ret;
342
343 adis_reset(&st->adis);
344 msleep(222);
345
346 ret = adis_write_reg_16(&st->adis, ADIS16460_REG_GLOB_CMD, BIT(1));
347 if (ret)
348 return ret;
349 msleep(75);
350
351 ret = adis_check_status(&st->adis);
352 if (ret)
353 return ret;
354
355 ret = adis_read_reg_16(&st->adis, ADIS16460_REG_PROD_ID, &prod_id);
356 if (ret)
357 return ret;
358
359 ret = sscanf(indio_dev->name, "adis%u\n", &device_id);
360 if (ret != 1)
361 return -EINVAL;
362
363 if (prod_id != device_id)
364 dev_warn(&indio_dev->dev, "Device ID(%u) and product ID(%u) do not match.",
365 device_id, prod_id);
366
367 return 0;
368}
369
370#define ADIS16460_DIAG_STAT_IN_CLK_OOS 7
371#define ADIS16460_DIAG_STAT_FLASH_MEM 6
372#define ADIS16460_DIAG_STAT_SELF_TEST 5
373#define ADIS16460_DIAG_STAT_OVERRANGE 4
374#define ADIS16460_DIAG_STAT_SPI_COMM 3
375#define ADIS16460_DIAG_STAT_FLASH_UPT 2
376
377static const char * const adis16460_status_error_msgs[] = {
378 [ADIS16460_DIAG_STAT_IN_CLK_OOS] = "Input clock out of sync",
379 [ADIS16460_DIAG_STAT_FLASH_MEM] = "Flash memory failure",
380 [ADIS16460_DIAG_STAT_SELF_TEST] = "Self test diagnostic failure",
381 [ADIS16460_DIAG_STAT_OVERRANGE] = "Sensor overrange",
382 [ADIS16460_DIAG_STAT_SPI_COMM] = "SPI communication failure",
383 [ADIS16460_DIAG_STAT_FLASH_UPT] = "Flash update failure",
384};
385
386static const struct adis_data adis16460_data = {
387 .diag_stat_reg = ADIS16460_REG_DIAG_STAT,
388 .glob_cmd_reg = ADIS16460_REG_GLOB_CMD,
389 .has_paging = false,
390 .read_delay = 5,
391 .write_delay = 5,
392 .cs_change_delay = 16,
393 .status_error_msgs = adis16460_status_error_msgs,
394 .status_error_mask = BIT(ADIS16460_DIAG_STAT_IN_CLK_OOS) |
395 BIT(ADIS16460_DIAG_STAT_FLASH_MEM) |
396 BIT(ADIS16460_DIAG_STAT_SELF_TEST) |
397 BIT(ADIS16460_DIAG_STAT_OVERRANGE) |
398 BIT(ADIS16460_DIAG_STAT_SPI_COMM) |
399 BIT(ADIS16460_DIAG_STAT_FLASH_UPT),
400 .enable_irq = adis16460_enable_irq,
401};
402
403static int adis16460_probe(struct spi_device *spi)
404{
405 struct iio_dev *indio_dev;
406 struct adis16460 *st;
407 int ret;
408
409 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
410 if (indio_dev == NULL)
411 return -ENOMEM;
412
413 spi_set_drvdata(spi, indio_dev);
414
415 st = iio_priv(indio_dev);
416
417 st->chip_info = &adis16460_chip_info;
418 indio_dev->dev.parent = &spi->dev;
419 indio_dev->name = spi_get_device_id(spi)->name;
420 indio_dev->channels = st->chip_info->channels;
421 indio_dev->num_channels = st->chip_info->num_channels;
422 indio_dev->info = &adis16460_info;
423 indio_dev->modes = INDIO_DIRECT_MODE;
424
425 ret = adis_init(&st->adis, indio_dev, spi, &adis16460_data);
426 if (ret)
427 return ret;
428
429 ret = adis_setup_buffer_and_trigger(&st->adis, indio_dev, NULL);
430 if (ret)
431 return ret;
432
433 adis16460_enable_irq(&st->adis, 0);
434
435 ret = adis16460_initial_setup(indio_dev);
436 if (ret)
437 goto error_cleanup_buffer;
438
439 ret = iio_device_register(indio_dev);
440 if (ret)
441 goto error_cleanup_buffer;
442
443 adis16460_debugfs_init(indio_dev);
444
445 return 0;
446
447error_cleanup_buffer:
448 adis_cleanup_buffer_and_trigger(&st->adis, indio_dev);
449 return ret;
450}
451
452static int adis16460_remove(struct spi_device *spi)
453{
454 struct iio_dev *indio_dev = spi_get_drvdata(spi);
455 struct adis16460 *st = iio_priv(indio_dev);
456
457 iio_device_unregister(indio_dev);
458
459 adis_cleanup_buffer_and_trigger(&st->adis, indio_dev);
460
461 return 0;
462}
463
464static const struct spi_device_id adis16460_ids[] = {
465 { "adis16460", 0 },
466 {}
467};
468MODULE_DEVICE_TABLE(spi, adis16460_ids);
469
470static const struct of_device_id adis16460_of_match[] = {
471 { .compatible = "adi,adis16460" },
472 {}
473};
474MODULE_DEVICE_TABLE(of, adis16460_of_match);
475
476static struct spi_driver adis16460_driver = {
477 .driver = {
478 .name = "adis16460",
479 .of_match_table = adis16460_of_match,
480 },
481 .id_table = adis16460_ids,
482 .probe = adis16460_probe,
483 .remove = adis16460_remove,
484};
485module_spi_driver(adis16460_driver);
486
487MODULE_AUTHOR("Dragos Bogdan <dragos.bogdan@analog.com>");
488MODULE_DESCRIPTION("Analog Devices ADIS16460 IMU driver");
489MODULE_LICENSE("GPL");
diff --git a/drivers/iio/imu/inv_mpu6050/Kconfig b/drivers/iio/imu/inv_mpu6050/Kconfig
index 395f3bd7de0a..e4c4c12236a7 100644
--- a/drivers/iio/imu/inv_mpu6050/Kconfig
+++ b/drivers/iio/imu/inv_mpu6050/Kconfig
@@ -14,8 +14,9 @@ config INV_MPU6050_I2C
14 select INV_MPU6050_IIO 14 select INV_MPU6050_IIO
15 select REGMAP_I2C 15 select REGMAP_I2C
16 help 16 help
17 This driver supports the Invensense MPU6050/6500/9150 and 17 This driver supports the Invensense MPU6000/6050/6500/6515,
18 ICM20608/20602 motion tracking devices over I2C. 18 MPU9150/9250/9255 and ICM20608/20602 motion tracking devices
19 over I2C.
19 This driver can be built as a module. The module will be called 20 This driver can be built as a module. The module will be called
20 inv-mpu6050-i2c. 21 inv-mpu6050-i2c.
21 22
@@ -25,7 +26,8 @@ config INV_MPU6050_SPI
25 select INV_MPU6050_IIO 26 select INV_MPU6050_IIO
26 select REGMAP_SPI 27 select REGMAP_SPI
27 help 28 help
28 This driver supports the Invensense MPU6050/6500/9150 and 29 This driver supports the Invensense MPU6000/6050/6500/6515,
29 ICM20608/20602 motion tracking devices over SPI. 30 MPU9150/9250/9255 and ICM20608/20602 motion tracking devices
31 over SPI.
30 This driver can be built as a module. The module will be called 32 This driver can be built as a module. The module will be called
31 inv-mpu6050-spi. 33 inv-mpu6050-spi.
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 8a704cd5bddb..b17f060b52fc 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -1137,10 +1137,9 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
1137 if (result) 1137 if (result)
1138 return result; 1138 return result;
1139 1139
1140 result = devm_add_action(dev, inv_mpu_core_disable_regulator_action, 1140 result = devm_add_action_or_reset(dev, inv_mpu_core_disable_regulator_action,
1141 st); 1141 st);
1142 if (result) { 1142 if (result) {
1143 inv_mpu_core_disable_regulator_action(st);
1144 dev_err(dev, "Failed to setup regulator cleanup action %d\n", 1143 dev_err(dev, "Failed to setup regulator cleanup action %d\n",
1145 result); 1144 result);
1146 return result; 1145 return result;
diff --git a/drivers/iio/imu/st_lsm6dsx/Kconfig b/drivers/iio/imu/st_lsm6dsx/Kconfig
index 002a423eae52..77aa0e77212d 100644
--- a/drivers/iio/imu/st_lsm6dsx/Kconfig
+++ b/drivers/iio/imu/st_lsm6dsx/Kconfig
@@ -2,15 +2,17 @@
2 2
3config IIO_ST_LSM6DSX 3config IIO_ST_LSM6DSX
4 tristate "ST_LSM6DSx driver for STM 6-axis IMU MEMS sensors" 4 tristate "ST_LSM6DSx driver for STM 6-axis IMU MEMS sensors"
5 depends on (I2C || SPI) 5 depends on (I2C || SPI || I3C)
6 select IIO_BUFFER 6 select IIO_BUFFER
7 select IIO_KFIFO_BUF 7 select IIO_KFIFO_BUF
8 select IIO_ST_LSM6DSX_I2C if (I2C) 8 select IIO_ST_LSM6DSX_I2C if (I2C)
9 select IIO_ST_LSM6DSX_SPI if (SPI_MASTER) 9 select IIO_ST_LSM6DSX_SPI if (SPI_MASTER)
10 select IIO_ST_LSM6DSX_I3C if (I3C)
10 help 11 help
11 Say yes here to build support for STMicroelectronics LSM6DSx imu 12 Say yes here to build support for STMicroelectronics LSM6DSx imu
12 sensor. Supported devices: lsm6ds3, lsm6ds3h, lsm6dsl, lsm6dsm, 13 sensor. Supported devices: lsm6ds3, lsm6ds3h, lsm6dsl, lsm6dsm,
13 ism330dlc, lsm6dso, lsm6dsox, asm330lhh, lsm6dsr 14 ism330dlc, lsm6dso, lsm6dsox, asm330lhh, lsm6dsr, lsm6ds3tr-c,
15 ism330dhcx and the accelerometer/gyroscope of lsm9ds1.
14 16
15 To compile this driver as a module, choose M here: the module 17 To compile this driver as a module, choose M here: the module
16 will be called st_lsm6dsx. 18 will be called st_lsm6dsx.
@@ -24,3 +26,8 @@ config IIO_ST_LSM6DSX_SPI
24 tristate 26 tristate
25 depends on IIO_ST_LSM6DSX 27 depends on IIO_ST_LSM6DSX
26 select REGMAP_SPI 28 select REGMAP_SPI
29
30config IIO_ST_LSM6DSX_I3C
31 tristate
32 depends on IIO_ST_LSM6DSX
33 select REGMAP_I3C
diff --git a/drivers/iio/imu/st_lsm6dsx/Makefile b/drivers/iio/imu/st_lsm6dsx/Makefile
index 28cc67399d94..57cbcd67d64f 100644
--- a/drivers/iio/imu/st_lsm6dsx/Makefile
+++ b/drivers/iio/imu/st_lsm6dsx/Makefile
@@ -5,3 +5,4 @@ st_lsm6dsx-y := st_lsm6dsx_core.o st_lsm6dsx_buffer.o \
5obj-$(CONFIG_IIO_ST_LSM6DSX) += st_lsm6dsx.o 5obj-$(CONFIG_IIO_ST_LSM6DSX) += st_lsm6dsx.o
6obj-$(CONFIG_IIO_ST_LSM6DSX_I2C) += st_lsm6dsx_i2c.o 6obj-$(CONFIG_IIO_ST_LSM6DSX_I2C) += st_lsm6dsx_i2c.o
7obj-$(CONFIG_IIO_ST_LSM6DSX_SPI) += st_lsm6dsx_spi.o 7obj-$(CONFIG_IIO_ST_LSM6DSX_SPI) += st_lsm6dsx_spi.o
8obj-$(CONFIG_IIO_ST_LSM6DSX_I3C) += st_lsm6dsx_i3c.o
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index c14bf533b66b..80e42c7dbcbe 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -22,6 +22,9 @@
22#define ST_ASM330LHH_DEV_NAME "asm330lhh" 22#define ST_ASM330LHH_DEV_NAME "asm330lhh"
23#define ST_LSM6DSOX_DEV_NAME "lsm6dsox" 23#define ST_LSM6DSOX_DEV_NAME "lsm6dsox"
24#define ST_LSM6DSR_DEV_NAME "lsm6dsr" 24#define ST_LSM6DSR_DEV_NAME "lsm6dsr"
25#define ST_LSM6DS3TRC_DEV_NAME "lsm6ds3tr-c"
26#define ST_ISM330DHCX_DEV_NAME "ism330dhcx"
27#define ST_LSM9DS1_DEV_NAME "lsm9ds1-imu"
25 28
26enum st_lsm6dsx_hw_id { 29enum st_lsm6dsx_hw_id {
27 ST_LSM6DS3_ID, 30 ST_LSM6DS3_ID,
@@ -33,6 +36,9 @@ enum st_lsm6dsx_hw_id {
33 ST_ASM330LHH_ID, 36 ST_ASM330LHH_ID,
34 ST_LSM6DSOX_ID, 37 ST_LSM6DSOX_ID,
35 ST_LSM6DSR_ID, 38 ST_LSM6DSR_ID,
39 ST_LSM6DS3TRC_ID,
40 ST_ISM330DHCX_ID,
41 ST_LSM9DS1_ID,
36 ST_LSM6DSX_MAX_ID, 42 ST_LSM6DSX_MAX_ID,
37}; 43};
38 44
@@ -54,8 +60,8 @@ enum st_lsm6dsx_hw_id {
54 .address = addr, \ 60 .address = addr, \
55 .modified = 1, \ 61 .modified = 1, \
56 .channel2 = mod, \ 62 .channel2 = mod, \
57 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 63 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
58 BIT(IIO_CHAN_INFO_SCALE), \ 64 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
59 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 65 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
60 .scan_index = scan_idx, \ 66 .scan_index = scan_idx, \
61 .scan_type = { \ 67 .scan_type = { \
@@ -71,6 +77,7 @@ struct st_lsm6dsx_reg {
71 u8 mask; 77 u8 mask;
72}; 78};
73 79
80struct st_lsm6dsx_sensor;
74struct st_lsm6dsx_hw; 81struct st_lsm6dsx_hw;
75 82
76struct st_lsm6dsx_odr { 83struct st_lsm6dsx_odr {
@@ -97,12 +104,14 @@ struct st_lsm6dsx_fs_table_entry {
97 104
98/** 105/**
99 * struct st_lsm6dsx_fifo_ops - ST IMU FIFO settings 106 * struct st_lsm6dsx_fifo_ops - ST IMU FIFO settings
107 * @update_fifo: Update FIFO configuration callback.
100 * @read_fifo: Read FIFO callback. 108 * @read_fifo: Read FIFO callback.
101 * @fifo_th: FIFO threshold register info (addr + mask). 109 * @fifo_th: FIFO threshold register info (addr + mask).
102 * @fifo_diff: FIFO diff status register info (addr + mask). 110 * @fifo_diff: FIFO diff status register info (addr + mask).
103 * @th_wl: FIFO threshold word length. 111 * @th_wl: FIFO threshold word length.
104 */ 112 */
105struct st_lsm6dsx_fifo_ops { 113struct st_lsm6dsx_fifo_ops {
114 int (*update_fifo)(struct st_lsm6dsx_sensor *sensor, bool enable);
106 int (*read_fifo)(struct st_lsm6dsx_hw *hw); 115 int (*read_fifo)(struct st_lsm6dsx_hw *hw);
107 struct { 116 struct {
108 u8 addr; 117 u8 addr;
@@ -196,8 +205,14 @@ struct st_lsm6dsx_ext_dev_settings {
196/** 205/**
197 * struct st_lsm6dsx_settings - ST IMU sensor settings 206 * struct st_lsm6dsx_settings - ST IMU sensor settings
198 * @wai: Sensor WhoAmI default value. 207 * @wai: Sensor WhoAmI default value.
208 * @int1_addr: Control Register address for INT1
209 * @int2_addr: Control Register address for INT2
210 * @reset_addr: register address for reset/reboot
199 * @max_fifo_size: Sensor max fifo length in FIFO words. 211 * @max_fifo_size: Sensor max fifo length in FIFO words.
200 * @id: List of hw id/device name supported by the driver configuration. 212 * @id: List of hw id/device name supported by the driver configuration.
213 * @channels: IIO channels supported by the device.
214 * @odr_table: Hw sensors odr table (Hz + val).
215 * @fs_table: Hw sensors gain table (gain + val).
201 * @decimator: List of decimator register info (addr + mask). 216 * @decimator: List of decimator register info (addr + mask).
202 * @batch: List of FIFO batching register info (addr + mask). 217 * @batch: List of FIFO batching register info (addr + mask).
203 * @fifo_ops: Sensor hw FIFO parameters. 218 * @fifo_ops: Sensor hw FIFO parameters.
@@ -206,11 +221,20 @@ struct st_lsm6dsx_ext_dev_settings {
206 */ 221 */
207struct st_lsm6dsx_settings { 222struct st_lsm6dsx_settings {
208 u8 wai; 223 u8 wai;
224 u8 int1_addr;
225 u8 int2_addr;
226 u8 reset_addr;
209 u16 max_fifo_size; 227 u16 max_fifo_size;
210 struct { 228 struct {
211 enum st_lsm6dsx_hw_id hw_id; 229 enum st_lsm6dsx_hw_id hw_id;
212 const char *name; 230 const char *name;
213 } id[ST_LSM6DSX_MAX_ID]; 231 } id[ST_LSM6DSX_MAX_ID];
232 struct {
233 const struct iio_chan_spec *chan;
234 int len;
235 } channels[2];
236 struct st_lsm6dsx_odr_table_entry odr_table[2];
237 struct st_lsm6dsx_fs_table_entry fs_table[2];
214 struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID]; 238 struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
215 struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID]; 239 struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID];
216 struct st_lsm6dsx_fifo_ops fifo_ops; 240 struct st_lsm6dsx_fifo_ops fifo_ops;
@@ -314,6 +338,7 @@ int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw);
314int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val); 338int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val);
315int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, 339int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor,
316 u16 watermark); 340 u16 watermark);
341int st_lsm6dsx_update_fifo(struct st_lsm6dsx_sensor *sensor, bool enable);
317int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw); 342int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw);
318int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw, 343int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
319 enum st_lsm6dsx_fifo_mode fifo_mode); 344 enum st_lsm6dsx_fifo_mode fifo_mode);
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
index e4d8a79d557d..b0f3da1976e4 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
@@ -2,10 +2,10 @@
2/* 2/*
3 * STMicroelectronics st_lsm6dsx FIFO buffer library driver 3 * STMicroelectronics st_lsm6dsx FIFO buffer library driver
4 * 4 *
5 * LSM6DS3/LSM6DS3H/LSM6DSL/LSM6DSM/ISM330DLC: The FIFO buffer can be 5 * LSM6DS3/LSM6DS3H/LSM6DSL/LSM6DSM/ISM330DLC/LSM6DS3TR-C:
6 * configured to store data from gyroscope and accelerometer. Samples are 6 * The FIFO buffer can be configured to store data from gyroscope and
7 * queued without any tag according to a specific pattern based on 7 * accelerometer. Samples are queued without any tag according to a
8 * 'FIFO data sets' (6 bytes each): 8 * specific pattern based on 'FIFO data sets' (6 bytes each):
9 * - 1st data set is reserved for gyroscope data 9 * - 1st data set is reserved for gyroscope data
10 * - 2nd data set is reserved for accelerometer data 10 * - 2nd data set is reserved for accelerometer data
11 * The FIFO pattern changes depending on the ODRs and decimation factors 11 * The FIFO pattern changes depending on the ODRs and decimation factors
@@ -14,9 +14,10 @@
14 * (e.g. Gx, Gy, Gz, Ax, Ay, Az), then data are repeated depending on the 14 * (e.g. Gx, Gy, Gz, Ax, Ay, Az), then data are repeated depending on the
15 * value of the decimation factor and ODR set for each FIFO data set. 15 * value of the decimation factor and ODR set for each FIFO data set.
16 * 16 *
17 * LSM6DSO/LSM6DSOX/ASM330LHH/LSM6DSR: The FIFO buffer can be configured to 17 * LSM6DSO/LSM6DSOX/ASM330LHH/LSM6DSR/ISM330DHCX: The FIFO buffer can be
18 * store data from gyroscope and accelerometer. Each sample is queued with 18 * configured to store data from gyroscope and accelerometer. Each sample
19 * a tag (1B) indicating data source (gyroscope, accelerometer, hw timer). 19 * is queued with a tag (1B) indicating data source (gyroscope, accelerometer,
20 * hw timer).
20 * 21 *
21 * FIFO supported modes: 22 * FIFO supported modes:
22 * - BYPASS: FIFO disabled 23 * - BYPASS: FIFO disabled
@@ -601,9 +602,8 @@ int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw)
601 return err; 602 return err;
602} 603}
603 604
604static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable) 605int st_lsm6dsx_update_fifo(struct st_lsm6dsx_sensor *sensor, bool enable)
605{ 606{
606 struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
607 struct st_lsm6dsx_hw *hw = sensor->hw; 607 struct st_lsm6dsx_hw *hw = sensor->hw;
608 int err; 608 int err;
609 609
@@ -670,17 +670,29 @@ static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
670 count = hw->settings->fifo_ops.read_fifo(hw); 670 count = hw->settings->fifo_ops.read_fifo(hw);
671 mutex_unlock(&hw->fifo_lock); 671 mutex_unlock(&hw->fifo_lock);
672 672
673 return !count ? IRQ_NONE : IRQ_HANDLED; 673 return count ? IRQ_HANDLED : IRQ_NONE;
674} 674}
675 675
676static int st_lsm6dsx_buffer_preenable(struct iio_dev *iio_dev) 676static int st_lsm6dsx_buffer_preenable(struct iio_dev *iio_dev)
677{ 677{
678 return st_lsm6dsx_update_fifo(iio_dev, true); 678 struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
679 struct st_lsm6dsx_hw *hw = sensor->hw;
680
681 if (!hw->settings->fifo_ops.update_fifo)
682 return -ENOTSUPP;
683
684 return hw->settings->fifo_ops.update_fifo(sensor, true);
679} 685}
680 686
681static int st_lsm6dsx_buffer_postdisable(struct iio_dev *iio_dev) 687static int st_lsm6dsx_buffer_postdisable(struct iio_dev *iio_dev)
682{ 688{
683 return st_lsm6dsx_update_fifo(iio_dev, false); 689 struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
690 struct st_lsm6dsx_hw *hw = sensor->hw;
691
692 if (!hw->settings->fifo_ops.update_fifo)
693 return -ENOTSUPP;
694
695 return hw->settings->fifo_ops.update_fifo(sensor, false);
684} 696}
685 697
686static const struct iio_buffer_setup_ops st_lsm6dsx_buffer_ops = { 698static const struct iio_buffer_setup_ops st_lsm6dsx_buffer_ops = {
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index a6702a74570e..2d3495560136 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -10,6 +10,8 @@
10 * +-125/+-245/+-500/+-1000/+-2000 dps 10 * +-125/+-245/+-500/+-1000/+-2000 dps
11 * LSM6DSx series has an integrated First-In-First-Out (FIFO) buffer 11 * LSM6DSx series has an integrated First-In-First-Out (FIFO) buffer
12 * allowing dynamic batching of sensor data. 12 * allowing dynamic batching of sensor data.
13 * LSM9DSx series is similar but includes an additional magnetometer, handled
14 * by a different driver.
13 * 15 *
14 * Supported sensors: 16 * Supported sensors:
15 * - LSM6DS3: 17 * - LSM6DS3:
@@ -18,18 +20,25 @@
18 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 20 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000
19 * - FIFO size: 8KB 21 * - FIFO size: 8KB
20 * 22 *
21 * - LSM6DS3H/LSM6DSL/LSM6DSM/ISM330DLC: 23 * - LSM6DS3H/LSM6DSL/LSM6DSM/ISM330DLC/LSM6DS3TR-C:
22 * - Accelerometer/Gyroscope supported ODR [Hz]: 13, 26, 52, 104, 208, 416 24 * - Accelerometer/Gyroscope supported ODR [Hz]: 13, 26, 52, 104, 208, 416
23 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16 25 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16
24 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 26 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000
25 * - FIFO size: 4KB 27 * - FIFO size: 4KB
26 * 28 *
27 * - LSM6DSO/LSM6DSOX/ASM330LHH/LSM6DSR 29 * - LSM6DSO/LSM6DSOX/ASM330LHH/LSM6DSR/ISM330DHCX:
28 * - Accelerometer/Gyroscope supported ODR [Hz]: 13, 26, 52, 104, 208, 416 30 * - Accelerometer/Gyroscope supported ODR [Hz]: 13, 26, 52, 104, 208, 416
29 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16 31 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16
30 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 32 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000
31 * - FIFO size: 3KB 33 * - FIFO size: 3KB
32 * 34 *
35 * - LSM9DS1:
36 * - Accelerometer supported ODR [Hz]: 10, 50, 119, 238, 476, 952
37 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16
38 * - Gyroscope supported ODR [Hz]: 15, 60, 119, 238, 476, 952
39 * - Gyroscope supported full-scale [dps]: +-245/+-500/+-2000
40 * - FIFO size: 32
41 *
33 * Copyright 2016 STMicroelectronics Inc. 42 * Copyright 2016 STMicroelectronics Inc.
34 * 43 *
35 * Lorenzo Bianconi <lorenzo.bianconi@st.com> 44 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
@@ -49,79 +58,110 @@
49 58
50#include "st_lsm6dsx.h" 59#include "st_lsm6dsx.h"
51 60
52#define ST_LSM6DSX_REG_INT1_ADDR 0x0d
53#define ST_LSM6DSX_REG_INT2_ADDR 0x0e
54#define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK BIT(3) 61#define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK BIT(3)
55#define ST_LSM6DSX_REG_WHOAMI_ADDR 0x0f 62#define ST_LSM6DSX_REG_WHOAMI_ADDR 0x0f
56#define ST_LSM6DSX_REG_RESET_ADDR 0x12
57#define ST_LSM6DSX_REG_RESET_MASK BIT(0) 63#define ST_LSM6DSX_REG_RESET_MASK BIT(0)
58#define ST_LSM6DSX_REG_BOOT_MASK BIT(7) 64#define ST_LSM6DSX_REG_BOOT_MASK BIT(7)
59#define ST_LSM6DSX_REG_BDU_ADDR 0x12 65#define ST_LSM6DSX_REG_BDU_ADDR 0x12
60#define ST_LSM6DSX_REG_BDU_MASK BIT(6) 66#define ST_LSM6DSX_REG_BDU_MASK BIT(6)
61#define ST_LSM6DSX_REG_INT2_ON_INT1_ADDR 0x13 67
62#define ST_LSM6DSX_REG_INT2_ON_INT1_MASK BIT(5) 68static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = {
63 69 ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x28, IIO_MOD_X, 0),
64#define ST_LSM6DSX_REG_ACC_OUT_X_L_ADDR 0x28 70 ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x2a, IIO_MOD_Y, 1),
65#define ST_LSM6DSX_REG_ACC_OUT_Y_L_ADDR 0x2a 71 ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x2c, IIO_MOD_Z, 2),
66#define ST_LSM6DSX_REG_ACC_OUT_Z_L_ADDR 0x2c 72 IIO_CHAN_SOFT_TIMESTAMP(3),
67
68#define ST_LSM6DSX_REG_GYRO_OUT_X_L_ADDR 0x22
69#define ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR 0x24
70#define ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR 0x26
71
72static const struct st_lsm6dsx_odr_table_entry st_lsm6dsx_odr_table[] = {
73 [ST_LSM6DSX_ID_ACC] = {
74 .reg = {
75 .addr = 0x10,
76 .mask = GENMASK(7, 4),
77 },
78 .odr_avl[0] = { 13, 0x01 },
79 .odr_avl[1] = { 26, 0x02 },
80 .odr_avl[2] = { 52, 0x03 },
81 .odr_avl[3] = { 104, 0x04 },
82 .odr_avl[4] = { 208, 0x05 },
83 .odr_avl[5] = { 416, 0x06 },
84 },
85 [ST_LSM6DSX_ID_GYRO] = {
86 .reg = {
87 .addr = 0x11,
88 .mask = GENMASK(7, 4),
89 },
90 .odr_avl[0] = { 13, 0x01 },
91 .odr_avl[1] = { 26, 0x02 },
92 .odr_avl[2] = { 52, 0x03 },
93 .odr_avl[3] = { 104, 0x04 },
94 .odr_avl[4] = { 208, 0x05 },
95 .odr_avl[5] = { 416, 0x06 },
96 }
97}; 73};
98 74
99static const struct st_lsm6dsx_fs_table_entry st_lsm6dsx_fs_table[] = { 75static const struct iio_chan_spec st_lsm6dsx_gyro_channels[] = {
100 [ST_LSM6DSX_ID_ACC] = { 76 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x22, IIO_MOD_X, 0),
101 .reg = { 77 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x24, IIO_MOD_Y, 1),
102 .addr = 0x10, 78 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x26, IIO_MOD_Z, 2),
103 .mask = GENMASK(3, 2), 79 IIO_CHAN_SOFT_TIMESTAMP(3),
104 }, 80};
105 .fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 }, 81
106 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 }, 82static const struct iio_chan_spec st_lsm6ds0_gyro_channels[] = {
107 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 }, 83 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x18, IIO_MOD_X, 0),
108 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 }, 84 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x1a, IIO_MOD_Y, 1),
109 }, 85 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, 0x1c, IIO_MOD_Z, 2),
110 [ST_LSM6DSX_ID_GYRO] = { 86 IIO_CHAN_SOFT_TIMESTAMP(3),
111 .reg = {
112 .addr = 0x11,
113 .mask = GENMASK(3, 2),
114 },
115 .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 },
116 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
117 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
118 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
119 }
120}; 87};
121 88
122static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { 89static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
123 { 90 {
91 .wai = 0x68,
92 .int1_addr = 0x0c,
93 .int2_addr = 0x0d,
94 .reset_addr = 0x22,
95 .max_fifo_size = 32,
96 .id = {
97 {
98 .hw_id = ST_LSM9DS1_ID,
99 .name = ST_LSM9DS1_DEV_NAME,
100 },
101 },
102 .channels = {
103 [ST_LSM6DSX_ID_ACC] = {
104 .chan = st_lsm6dsx_acc_channels,
105 .len = ARRAY_SIZE(st_lsm6dsx_acc_channels),
106 },
107 [ST_LSM6DSX_ID_GYRO] = {
108 .chan = st_lsm6ds0_gyro_channels,
109 .len = ARRAY_SIZE(st_lsm6ds0_gyro_channels),
110 },
111 },
112 .odr_table = {
113 [ST_LSM6DSX_ID_ACC] = {
114 .reg = {
115 .addr = 0x20,
116 .mask = GENMASK(7, 5),
117 },
118 .odr_avl[0] = { 10, 0x01 },
119 .odr_avl[1] = { 50, 0x02 },
120 .odr_avl[2] = { 119, 0x03 },
121 .odr_avl[3] = { 238, 0x04 },
122 .odr_avl[4] = { 476, 0x05 },
123 .odr_avl[5] = { 952, 0x06 },
124 },
125 [ST_LSM6DSX_ID_GYRO] = {
126 .reg = {
127 .addr = 0x10,
128 .mask = GENMASK(7, 5),
129 },
130 .odr_avl[0] = { 15, 0x01 },
131 .odr_avl[1] = { 60, 0x02 },
132 .odr_avl[2] = { 119, 0x03 },
133 .odr_avl[3] = { 238, 0x04 },
134 .odr_avl[4] = { 476, 0x05 },
135 .odr_avl[5] = { 952, 0x06 },
136 },
137 },
138 .fs_table = {
139 [ST_LSM6DSX_ID_ACC] = {
140 .reg = {
141 .addr = 0x20,
142 .mask = GENMASK(4, 3),
143 },
144 .fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 },
145 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
146 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
147 .fs_avl[3] = { IIO_G_TO_M_S_2(732), 0x1 },
148 },
149 [ST_LSM6DSX_ID_GYRO] = {
150 .reg = {
151 .addr = 0x10,
152 .mask = GENMASK(4, 3),
153 },
154 .fs_avl[0] = { IIO_DEGREE_TO_RAD(245), 0x0 },
155 .fs_avl[1] = { IIO_DEGREE_TO_RAD(500), 0x1 },
156 .fs_avl[2] = { IIO_DEGREE_TO_RAD(2000), 0x3 },
157 },
158 },
159 },
160 {
124 .wai = 0x69, 161 .wai = 0x69,
162 .int1_addr = 0x0d,
163 .int2_addr = 0x0e,
164 .reset_addr = 0x12,
125 .max_fifo_size = 1365, 165 .max_fifo_size = 1365,
126 .id = { 166 .id = {
127 { 167 {
@@ -129,6 +169,64 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
129 .name = ST_LSM6DS3_DEV_NAME, 169 .name = ST_LSM6DS3_DEV_NAME,
130 }, 170 },
131 }, 171 },
172 .channels = {
173 [ST_LSM6DSX_ID_ACC] = {
174 .chan = st_lsm6dsx_acc_channels,
175 .len = ARRAY_SIZE(st_lsm6dsx_acc_channels),
176 },
177 [ST_LSM6DSX_ID_GYRO] = {
178 .chan = st_lsm6dsx_gyro_channels,
179 .len = ARRAY_SIZE(st_lsm6dsx_gyro_channels),
180 },
181 },
182 .odr_table = {
183 [ST_LSM6DSX_ID_ACC] = {
184 .reg = {
185 .addr = 0x10,
186 .mask = GENMASK(7, 4),
187 },
188 .odr_avl[0] = { 13, 0x01 },
189 .odr_avl[1] = { 26, 0x02 },
190 .odr_avl[2] = { 52, 0x03 },
191 .odr_avl[3] = { 104, 0x04 },
192 .odr_avl[4] = { 208, 0x05 },
193 .odr_avl[5] = { 416, 0x06 },
194 },
195 [ST_LSM6DSX_ID_GYRO] = {
196 .reg = {
197 .addr = 0x11,
198 .mask = GENMASK(7, 4),
199 },
200 .odr_avl[0] = { 13, 0x01 },
201 .odr_avl[1] = { 26, 0x02 },
202 .odr_avl[2] = { 52, 0x03 },
203 .odr_avl[3] = { 104, 0x04 },
204 .odr_avl[4] = { 208, 0x05 },
205 .odr_avl[5] = { 416, 0x06 },
206 },
207 },
208 .fs_table = {
209 [ST_LSM6DSX_ID_ACC] = {
210 .reg = {
211 .addr = 0x10,
212 .mask = GENMASK(3, 2),
213 },
214 .fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 },
215 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
216 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
217 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
218 },
219 [ST_LSM6DSX_ID_GYRO] = {
220 .reg = {
221 .addr = 0x11,
222 .mask = GENMASK(3, 2),
223 },
224 .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 },
225 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
226 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
227 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
228 },
229 },
132 .decimator = { 230 .decimator = {
133 [ST_LSM6DSX_ID_ACC] = { 231 [ST_LSM6DSX_ID_ACC] = {
134 .addr = 0x08, 232 .addr = 0x08,
@@ -140,6 +238,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
140 }, 238 },
141 }, 239 },
142 .fifo_ops = { 240 .fifo_ops = {
241 .update_fifo = st_lsm6dsx_update_fifo,
143 .read_fifo = st_lsm6dsx_read_fifo, 242 .read_fifo = st_lsm6dsx_read_fifo,
144 .fifo_th = { 243 .fifo_th = {
145 .addr = 0x06, 244 .addr = 0x06,
@@ -172,6 +271,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
172 }, 271 },
173 { 272 {
174 .wai = 0x69, 273 .wai = 0x69,
274 .int1_addr = 0x0d,
275 .int2_addr = 0x0e,
276 .reset_addr = 0x12,
175 .max_fifo_size = 682, 277 .max_fifo_size = 682,
176 .id = { 278 .id = {
177 { 279 {
@@ -179,6 +281,64 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
179 .name = ST_LSM6DS3H_DEV_NAME, 281 .name = ST_LSM6DS3H_DEV_NAME,
180 }, 282 },
181 }, 283 },
284 .channels = {
285 [ST_LSM6DSX_ID_ACC] = {
286 .chan = st_lsm6dsx_acc_channels,
287 .len = ARRAY_SIZE(st_lsm6dsx_acc_channels),
288 },
289 [ST_LSM6DSX_ID_GYRO] = {
290 .chan = st_lsm6dsx_gyro_channels,
291 .len = ARRAY_SIZE(st_lsm6dsx_gyro_channels),
292 },
293 },
294 .odr_table = {
295 [ST_LSM6DSX_ID_ACC] = {
296 .reg = {
297 .addr = 0x10,
298 .mask = GENMASK(7, 4),
299 },
300 .odr_avl[0] = { 13, 0x01 },
301 .odr_avl[1] = { 26, 0x02 },
302 .odr_avl[2] = { 52, 0x03 },
303 .odr_avl[3] = { 104, 0x04 },
304 .odr_avl[4] = { 208, 0x05 },
305 .odr_avl[5] = { 416, 0x06 },
306 },
307 [ST_LSM6DSX_ID_GYRO] = {
308 .reg = {
309 .addr = 0x11,
310 .mask = GENMASK(7, 4),
311 },
312 .odr_avl[0] = { 13, 0x01 },
313 .odr_avl[1] = { 26, 0x02 },
314 .odr_avl[2] = { 52, 0x03 },
315 .odr_avl[3] = { 104, 0x04 },
316 .odr_avl[4] = { 208, 0x05 },
317 .odr_avl[5] = { 416, 0x06 },
318 },
319 },
320 .fs_table = {
321 [ST_LSM6DSX_ID_ACC] = {
322 .reg = {
323 .addr = 0x10,
324 .mask = GENMASK(3, 2),
325 },
326 .fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 },
327 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
328 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
329 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
330 },
331 [ST_LSM6DSX_ID_GYRO] = {
332 .reg = {
333 .addr = 0x11,
334 .mask = GENMASK(3, 2),
335 },
336 .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 },
337 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
338 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
339 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
340 },
341 },
182 .decimator = { 342 .decimator = {
183 [ST_LSM6DSX_ID_ACC] = { 343 [ST_LSM6DSX_ID_ACC] = {
184 .addr = 0x08, 344 .addr = 0x08,
@@ -190,6 +350,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
190 }, 350 },
191 }, 351 },
192 .fifo_ops = { 352 .fifo_ops = {
353 .update_fifo = st_lsm6dsx_update_fifo,
193 .read_fifo = st_lsm6dsx_read_fifo, 354 .read_fifo = st_lsm6dsx_read_fifo,
194 .fifo_th = { 355 .fifo_th = {
195 .addr = 0x06, 356 .addr = 0x06,
@@ -222,6 +383,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
222 }, 383 },
223 { 384 {
224 .wai = 0x6a, 385 .wai = 0x6a,
386 .int1_addr = 0x0d,
387 .int2_addr = 0x0e,
388 .reset_addr = 0x12,
225 .max_fifo_size = 682, 389 .max_fifo_size = 682,
226 .id = { 390 .id = {
227 { 391 {
@@ -233,6 +397,67 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
233 }, { 397 }, {
234 .hw_id = ST_ISM330DLC_ID, 398 .hw_id = ST_ISM330DLC_ID,
235 .name = ST_ISM330DLC_DEV_NAME, 399 .name = ST_ISM330DLC_DEV_NAME,
400 }, {
401 .hw_id = ST_LSM6DS3TRC_ID,
402 .name = ST_LSM6DS3TRC_DEV_NAME,
403 },
404 },
405 .channels = {
406 [ST_LSM6DSX_ID_ACC] = {
407 .chan = st_lsm6dsx_acc_channels,
408 .len = ARRAY_SIZE(st_lsm6dsx_acc_channels),
409 },
410 [ST_LSM6DSX_ID_GYRO] = {
411 .chan = st_lsm6dsx_gyro_channels,
412 .len = ARRAY_SIZE(st_lsm6dsx_gyro_channels),
413 },
414 },
415 .odr_table = {
416 [ST_LSM6DSX_ID_ACC] = {
417 .reg = {
418 .addr = 0x10,
419 .mask = GENMASK(7, 4),
420 },
421 .odr_avl[0] = { 13, 0x01 },
422 .odr_avl[1] = { 26, 0x02 },
423 .odr_avl[2] = { 52, 0x03 },
424 .odr_avl[3] = { 104, 0x04 },
425 .odr_avl[4] = { 208, 0x05 },
426 .odr_avl[5] = { 416, 0x06 },
427 },
428 [ST_LSM6DSX_ID_GYRO] = {
429 .reg = {
430 .addr = 0x11,
431 .mask = GENMASK(7, 4),
432 },
433 .odr_avl[0] = { 13, 0x01 },
434 .odr_avl[1] = { 26, 0x02 },
435 .odr_avl[2] = { 52, 0x03 },
436 .odr_avl[3] = { 104, 0x04 },
437 .odr_avl[4] = { 208, 0x05 },
438 .odr_avl[5] = { 416, 0x06 },
439 },
440 },
441 .fs_table = {
442 [ST_LSM6DSX_ID_ACC] = {
443 .reg = {
444 .addr = 0x10,
445 .mask = GENMASK(3, 2),
446 },
447 .fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 },
448 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
449 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
450 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
451 },
452 [ST_LSM6DSX_ID_GYRO] = {
453 .reg = {
454 .addr = 0x11,
455 .mask = GENMASK(3, 2),
456 },
457 .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 },
458 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
459 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
460 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
236 }, 461 },
237 }, 462 },
238 .decimator = { 463 .decimator = {
@@ -246,6 +471,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
246 }, 471 },
247 }, 472 },
248 .fifo_ops = { 473 .fifo_ops = {
474 .update_fifo = st_lsm6dsx_update_fifo,
249 .read_fifo = st_lsm6dsx_read_fifo, 475 .read_fifo = st_lsm6dsx_read_fifo,
250 .fifo_th = { 476 .fifo_th = {
251 .addr = 0x06, 477 .addr = 0x06,
@@ -278,6 +504,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
278 }, 504 },
279 { 505 {
280 .wai = 0x6c, 506 .wai = 0x6c,
507 .int1_addr = 0x0d,
508 .int2_addr = 0x0e,
509 .reset_addr = 0x12,
281 .max_fifo_size = 512, 510 .max_fifo_size = 512,
282 .id = { 511 .id = {
283 { 512 {
@@ -288,6 +517,64 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
288 .name = ST_LSM6DSOX_DEV_NAME, 517 .name = ST_LSM6DSOX_DEV_NAME,
289 }, 518 },
290 }, 519 },
520 .channels = {
521 [ST_LSM6DSX_ID_ACC] = {
522 .chan = st_lsm6dsx_acc_channels,
523 .len = ARRAY_SIZE(st_lsm6dsx_acc_channels),
524 },
525 [ST_LSM6DSX_ID_GYRO] = {
526 .chan = st_lsm6dsx_gyro_channels,
527 .len = ARRAY_SIZE(st_lsm6dsx_gyro_channels),
528 },
529 },
530 .odr_table = {
531 [ST_LSM6DSX_ID_ACC] = {
532 .reg = {
533 .addr = 0x10,
534 .mask = GENMASK(7, 4),
535 },
536 .odr_avl[0] = { 13, 0x01 },
537 .odr_avl[1] = { 26, 0x02 },
538 .odr_avl[2] = { 52, 0x03 },
539 .odr_avl[3] = { 104, 0x04 },
540 .odr_avl[4] = { 208, 0x05 },
541 .odr_avl[5] = { 416, 0x06 },
542 },
543 [ST_LSM6DSX_ID_GYRO] = {
544 .reg = {
545 .addr = 0x11,
546 .mask = GENMASK(7, 4),
547 },
548 .odr_avl[0] = { 13, 0x01 },
549 .odr_avl[1] = { 26, 0x02 },
550 .odr_avl[2] = { 52, 0x03 },
551 .odr_avl[3] = { 104, 0x04 },
552 .odr_avl[4] = { 208, 0x05 },
553 .odr_avl[5] = { 416, 0x06 },
554 },
555 },
556 .fs_table = {
557 [ST_LSM6DSX_ID_ACC] = {
558 .reg = {
559 .addr = 0x10,
560 .mask = GENMASK(3, 2),
561 },
562 .fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 },
563 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
564 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
565 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
566 },
567 [ST_LSM6DSX_ID_GYRO] = {
568 .reg = {
569 .addr = 0x11,
570 .mask = GENMASK(3, 2),
571 },
572 .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 },
573 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
574 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
575 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
576 },
577 },
291 .batch = { 578 .batch = {
292 [ST_LSM6DSX_ID_ACC] = { 579 [ST_LSM6DSX_ID_ACC] = {
293 .addr = 0x09, 580 .addr = 0x09,
@@ -299,6 +586,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
299 }, 586 },
300 }, 587 },
301 .fifo_ops = { 588 .fifo_ops = {
589 .update_fifo = st_lsm6dsx_update_fifo,
302 .read_fifo = st_lsm6dsx_read_tagged_fifo, 590 .read_fifo = st_lsm6dsx_read_tagged_fifo,
303 .fifo_th = { 591 .fifo_th = {
304 .addr = 0x07, 592 .addr = 0x07,
@@ -306,7 +594,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
306 }, 594 },
307 .fifo_diff = { 595 .fifo_diff = {
308 .addr = 0x3a, 596 .addr = 0x3a,
309 .mask = GENMASK(8, 0), 597 .mask = GENMASK(9, 0),
310 }, 598 },
311 .th_wl = 1, 599 .th_wl = 1,
312 }, 600 },
@@ -349,6 +637,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
349 }, 637 },
350 { 638 {
351 .wai = 0x6b, 639 .wai = 0x6b,
640 .int1_addr = 0x0d,
641 .int2_addr = 0x0e,
642 .reset_addr = 0x12,
352 .max_fifo_size = 512, 643 .max_fifo_size = 512,
353 .id = { 644 .id = {
354 { 645 {
@@ -356,6 +647,64 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
356 .name = ST_ASM330LHH_DEV_NAME, 647 .name = ST_ASM330LHH_DEV_NAME,
357 }, 648 },
358 }, 649 },
650 .channels = {
651 [ST_LSM6DSX_ID_ACC] = {
652 .chan = st_lsm6dsx_acc_channels,
653 .len = ARRAY_SIZE(st_lsm6dsx_acc_channels),
654 },
655 [ST_LSM6DSX_ID_GYRO] = {
656 .chan = st_lsm6dsx_gyro_channels,
657 .len = ARRAY_SIZE(st_lsm6dsx_gyro_channels),
658 },
659 },
660 .odr_table = {
661 [ST_LSM6DSX_ID_ACC] = {
662 .reg = {
663 .addr = 0x10,
664 .mask = GENMASK(7, 4),
665 },
666 .odr_avl[0] = { 13, 0x01 },
667 .odr_avl[1] = { 26, 0x02 },
668 .odr_avl[2] = { 52, 0x03 },
669 .odr_avl[3] = { 104, 0x04 },
670 .odr_avl[4] = { 208, 0x05 },
671 .odr_avl[5] = { 416, 0x06 },
672 },
673 [ST_LSM6DSX_ID_GYRO] = {
674 .reg = {
675 .addr = 0x11,
676 .mask = GENMASK(7, 4),
677 },
678 .odr_avl[0] = { 13, 0x01 },
679 .odr_avl[1] = { 26, 0x02 },
680 .odr_avl[2] = { 52, 0x03 },
681 .odr_avl[3] = { 104, 0x04 },
682 .odr_avl[4] = { 208, 0x05 },
683 .odr_avl[5] = { 416, 0x06 },
684 },
685 },
686 .fs_table = {
687 [ST_LSM6DSX_ID_ACC] = {
688 .reg = {
689 .addr = 0x10,
690 .mask = GENMASK(3, 2),
691 },
692 .fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 },
693 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
694 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
695 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
696 },
697 [ST_LSM6DSX_ID_GYRO] = {
698 .reg = {
699 .addr = 0x11,
700 .mask = GENMASK(3, 2),
701 },
702 .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 },
703 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
704 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
705 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
706 },
707 },
359 .batch = { 708 .batch = {
360 [ST_LSM6DSX_ID_ACC] = { 709 [ST_LSM6DSX_ID_ACC] = {
361 .addr = 0x09, 710 .addr = 0x09,
@@ -367,6 +716,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
367 }, 716 },
368 }, 717 },
369 .fifo_ops = { 718 .fifo_ops = {
719 .update_fifo = st_lsm6dsx_update_fifo,
370 .read_fifo = st_lsm6dsx_read_tagged_fifo, 720 .read_fifo = st_lsm6dsx_read_tagged_fifo,
371 .fifo_th = { 721 .fifo_th = {
372 .addr = 0x07, 722 .addr = 0x07,
@@ -374,7 +724,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
374 }, 724 },
375 .fifo_diff = { 725 .fifo_diff = {
376 .addr = 0x3a, 726 .addr = 0x3a,
377 .mask = GENMASK(8, 0), 727 .mask = GENMASK(9, 0),
378 }, 728 },
379 .th_wl = 1, 729 .th_wl = 1,
380 }, 730 },
@@ -391,11 +741,75 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
391 }, 741 },
392 { 742 {
393 .wai = 0x6b, 743 .wai = 0x6b,
744 .int1_addr = 0x0d,
745 .int2_addr = 0x0e,
746 .reset_addr = 0x12,
394 .max_fifo_size = 512, 747 .max_fifo_size = 512,
395 .id = { 748 .id = {
396 { 749 {
397 .hw_id = ST_LSM6DSR_ID, 750 .hw_id = ST_LSM6DSR_ID,
398 .name = ST_LSM6DSR_DEV_NAME, 751 .name = ST_LSM6DSR_DEV_NAME,
752 }, {
753 .hw_id = ST_ISM330DHCX_ID,
754 .name = ST_ISM330DHCX_DEV_NAME,
755 },
756 },
757 .channels = {
758 [ST_LSM6DSX_ID_ACC] = {
759 .chan = st_lsm6dsx_acc_channels,
760 .len = ARRAY_SIZE(st_lsm6dsx_acc_channels),
761 },
762 [ST_LSM6DSX_ID_GYRO] = {
763 .chan = st_lsm6dsx_gyro_channels,
764 .len = ARRAY_SIZE(st_lsm6dsx_gyro_channels),
765 },
766 },
767 .odr_table = {
768 [ST_LSM6DSX_ID_ACC] = {
769 .reg = {
770 .addr = 0x10,
771 .mask = GENMASK(7, 4),
772 },
773 .odr_avl[0] = { 13, 0x01 },
774 .odr_avl[1] = { 26, 0x02 },
775 .odr_avl[2] = { 52, 0x03 },
776 .odr_avl[3] = { 104, 0x04 },
777 .odr_avl[4] = { 208, 0x05 },
778 .odr_avl[5] = { 416, 0x06 },
779 },
780 [ST_LSM6DSX_ID_GYRO] = {
781 .reg = {
782 .addr = 0x11,
783 .mask = GENMASK(7, 4),
784 },
785 .odr_avl[0] = { 13, 0x01 },
786 .odr_avl[1] = { 26, 0x02 },
787 .odr_avl[2] = { 52, 0x03 },
788 .odr_avl[3] = { 104, 0x04 },
789 .odr_avl[4] = { 208, 0x05 },
790 .odr_avl[5] = { 416, 0x06 },
791 },
792 },
793 .fs_table = {
794 [ST_LSM6DSX_ID_ACC] = {
795 .reg = {
796 .addr = 0x10,
797 .mask = GENMASK(3, 2),
798 },
799 .fs_avl[0] = { IIO_G_TO_M_S_2(61), 0x0 },
800 .fs_avl[1] = { IIO_G_TO_M_S_2(122), 0x2 },
801 .fs_avl[2] = { IIO_G_TO_M_S_2(244), 0x3 },
802 .fs_avl[3] = { IIO_G_TO_M_S_2(488), 0x1 },
803 },
804 [ST_LSM6DSX_ID_GYRO] = {
805 .reg = {
806 .addr = 0x11,
807 .mask = GENMASK(3, 2),
808 },
809 .fs_avl[0] = { IIO_DEGREE_TO_RAD(8750), 0x0 },
810 .fs_avl[1] = { IIO_DEGREE_TO_RAD(17500), 0x1 },
811 .fs_avl[2] = { IIO_DEGREE_TO_RAD(35000), 0x2 },
812 .fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
399 }, 813 },
400 }, 814 },
401 .batch = { 815 .batch = {
@@ -409,6 +823,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
409 }, 823 },
410 }, 824 },
411 .fifo_ops = { 825 .fifo_ops = {
826 .update_fifo = st_lsm6dsx_update_fifo,
412 .read_fifo = st_lsm6dsx_read_tagged_fifo, 827 .read_fifo = st_lsm6dsx_read_tagged_fifo,
413 .fifo_th = { 828 .fifo_th = {
414 .addr = 0x07, 829 .addr = 0x07,
@@ -416,7 +831,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
416 }, 831 },
417 .fifo_diff = { 832 .fifo_diff = {
418 .addr = 0x3a, 833 .addr = 0x3a,
419 .mask = GENMASK(8, 0), 834 .mask = GENMASK(9, 0),
420 }, 835 },
421 .th_wl = 1, 836 .th_wl = 1,
422 }, 837 },
@@ -459,26 +874,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
459 }, 874 },
460}; 875};
461 876
462static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = {
463 ST_LSM6DSX_CHANNEL(IIO_ACCEL, ST_LSM6DSX_REG_ACC_OUT_X_L_ADDR,
464 IIO_MOD_X, 0),
465 ST_LSM6DSX_CHANNEL(IIO_ACCEL, ST_LSM6DSX_REG_ACC_OUT_Y_L_ADDR,
466 IIO_MOD_Y, 1),
467 ST_LSM6DSX_CHANNEL(IIO_ACCEL, ST_LSM6DSX_REG_ACC_OUT_Z_L_ADDR,
468 IIO_MOD_Z, 2),
469 IIO_CHAN_SOFT_TIMESTAMP(3),
470};
471
472static const struct iio_chan_spec st_lsm6dsx_gyro_channels[] = {
473 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, ST_LSM6DSX_REG_GYRO_OUT_X_L_ADDR,
474 IIO_MOD_X, 0),
475 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR,
476 IIO_MOD_Y, 1),
477 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR,
478 IIO_MOD_Z, 2),
479 IIO_CHAN_SOFT_TIMESTAMP(3),
480};
481
482int st_lsm6dsx_set_page(struct st_lsm6dsx_hw *hw, bool enable) 877int st_lsm6dsx_set_page(struct st_lsm6dsx_hw *hw, bool enable)
483{ 878{
484 const struct st_lsm6dsx_shub_settings *hub_settings; 879 const struct st_lsm6dsx_shub_settings *hub_settings;
@@ -533,23 +928,22 @@ static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id,
533static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor, 928static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
534 u32 gain) 929 u32 gain)
535{ 930{
536 struct st_lsm6dsx_hw *hw = sensor->hw; 931 const struct st_lsm6dsx_fs_table_entry *fs_table;
537 const struct st_lsm6dsx_reg *reg;
538 unsigned int data; 932 unsigned int data;
539 int i, err; 933 int i, err;
540 u8 val;
541 934
935 fs_table = &sensor->hw->settings->fs_table[sensor->id];
542 for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++) 936 for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++)
543 if (st_lsm6dsx_fs_table[sensor->id].fs_avl[i].gain == gain) 937 if (fs_table->fs_avl[i].gain == gain)
544 break; 938 break;
545 939
546 if (i == ST_LSM6DSX_FS_LIST_SIZE) 940 if (i == ST_LSM6DSX_FS_LIST_SIZE)
547 return -EINVAL; 941 return -EINVAL;
548 942
549 val = st_lsm6dsx_fs_table[sensor->id].fs_avl[i].val; 943 data = ST_LSM6DSX_SHIFT_VAL(fs_table->fs_avl[i].val,
550 reg = &st_lsm6dsx_fs_table[sensor->id].reg; 944 fs_table->reg.mask);
551 data = ST_LSM6DSX_SHIFT_VAL(val, reg->mask); 945 err = st_lsm6dsx_update_bits_locked(sensor->hw, fs_table->reg.addr,
552 err = st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data); 946 fs_table->reg.mask, data);
553 if (err < 0) 947 if (err < 0)
554 return err; 948 return err;
555 949
@@ -560,20 +954,22 @@ static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
560 954
561int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u16 odr, u8 *val) 955int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u16 odr, u8 *val)
562{ 956{
957 const struct st_lsm6dsx_odr_table_entry *odr_table;
563 int i; 958 int i;
564 959
960 odr_table = &sensor->hw->settings->odr_table[sensor->id];
565 for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++) 961 for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
566 /* 962 /*
567 * ext devices can run at different odr respect to 963 * ext devices can run at different odr respect to
568 * accel sensor 964 * accel sensor
569 */ 965 */
570 if (st_lsm6dsx_odr_table[sensor->id].odr_avl[i].hz >= odr) 966 if (odr_table->odr_avl[i].hz >= odr)
571 break; 967 break;
572 968
573 if (i == ST_LSM6DSX_ODR_LIST_SIZE) 969 if (i == ST_LSM6DSX_ODR_LIST_SIZE)
574 return -EINVAL; 970 return -EINVAL;
575 971
576 *val = st_lsm6dsx_odr_table[sensor->id].odr_avl[i].val; 972 *val = odr_table->odr_avl[i].val;
577 973
578 return 0; 974 return 0;
579} 975}
@@ -638,7 +1034,7 @@ static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 req_odr)
638 return err; 1034 return err;
639 } 1035 }
640 1036
641 reg = &st_lsm6dsx_odr_table[ref_sensor->id].reg; 1037 reg = &hw->settings->odr_table[ref_sensor->id].reg;
642 data = ST_LSM6DSX_SHIFT_VAL(val, reg->mask); 1038 data = ST_LSM6DSX_SHIFT_VAL(val, reg->mask);
643 return st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data); 1039 return st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data);
644} 1040}
@@ -783,11 +1179,12 @@ st_lsm6dsx_sysfs_sampling_frequency_avail(struct device *dev,
783{ 1179{
784 struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev)); 1180 struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev));
785 enum st_lsm6dsx_sensor_id id = sensor->id; 1181 enum st_lsm6dsx_sensor_id id = sensor->id;
1182 struct st_lsm6dsx_hw *hw = sensor->hw;
786 int i, len = 0; 1183 int i, len = 0;
787 1184
788 for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++) 1185 for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
789 len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", 1186 len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
790 st_lsm6dsx_odr_table[id].odr_avl[i].hz); 1187 hw->settings->odr_table[id].odr_avl[i].hz);
791 buf[len - 1] = '\n'; 1188 buf[len - 1] = '\n';
792 1189
793 return len; 1190 return len;
@@ -798,12 +1195,19 @@ static ssize_t st_lsm6dsx_sysfs_scale_avail(struct device *dev,
798 char *buf) 1195 char *buf)
799{ 1196{
800 struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev)); 1197 struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev));
1198 const struct st_lsm6dsx_fs_table_entry *fs_table;
801 enum st_lsm6dsx_sensor_id id = sensor->id; 1199 enum st_lsm6dsx_sensor_id id = sensor->id;
1200 struct st_lsm6dsx_hw *hw = sensor->hw;
802 int i, len = 0; 1201 int i, len = 0;
803 1202
804 for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++) 1203 fs_table = &hw->settings->fs_table[id];
1204 for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++) {
1205 if (!fs_table->fs_avl[i].gain)
1206 break;
1207
805 len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ", 1208 len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
806 st_lsm6dsx_fs_table[id].fs_avl[i].gain); 1209 fs_table->fs_avl[i].gain);
1210 }
807 buf[len - 1] = '\n'; 1211 buf[len - 1] = '\n';
808 1212
809 return len; 1213 return len;
@@ -873,10 +1277,10 @@ static int st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, u8 *drdy_reg)
873 1277
874 switch (drdy_pin) { 1278 switch (drdy_pin) {
875 case 1: 1279 case 1:
876 *drdy_reg = ST_LSM6DSX_REG_INT1_ADDR; 1280 *drdy_reg = hw->settings->int1_addr;
877 break; 1281 break;
878 case 2: 1282 case 2:
879 *drdy_reg = ST_LSM6DSX_REG_INT2_ADDR; 1283 *drdy_reg = hw->settings->int2_addr;
880 break; 1284 break;
881 default: 1285 default:
882 dev_err(hw->dev, "unsupported data ready pin\n"); 1286 dev_err(hw->dev, "unsupported data ready pin\n");
@@ -976,7 +1380,7 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
976 int err; 1380 int err;
977 1381
978 /* device sw reset */ 1382 /* device sw reset */
979 err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_RESET_ADDR, 1383 err = regmap_update_bits(hw->regmap, hw->settings->reset_addr,
980 ST_LSM6DSX_REG_RESET_MASK, 1384 ST_LSM6DSX_REG_RESET_MASK,
981 FIELD_PREP(ST_LSM6DSX_REG_RESET_MASK, 1)); 1385 FIELD_PREP(ST_LSM6DSX_REG_RESET_MASK, 1));
982 if (err < 0) 1386 if (err < 0)
@@ -985,7 +1389,7 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
985 msleep(50); 1389 msleep(50);
986 1390
987 /* reload trimming parameter */ 1391 /* reload trimming parameter */
988 err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_RESET_ADDR, 1392 err = regmap_update_bits(hw->regmap, hw->settings->reset_addr,
989 ST_LSM6DSX_REG_BOOT_MASK, 1393 ST_LSM6DSX_REG_BOOT_MASK,
990 FIELD_PREP(ST_LSM6DSX_REG_BOOT_MASK, 1)); 1394 FIELD_PREP(ST_LSM6DSX_REG_BOOT_MASK, 1));
991 if (err < 0) 1395 if (err < 0)
@@ -1033,28 +1437,24 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
1033 iio_dev->modes = INDIO_DIRECT_MODE; 1437 iio_dev->modes = INDIO_DIRECT_MODE;
1034 iio_dev->dev.parent = hw->dev; 1438 iio_dev->dev.parent = hw->dev;
1035 iio_dev->available_scan_masks = st_lsm6dsx_available_scan_masks; 1439 iio_dev->available_scan_masks = st_lsm6dsx_available_scan_masks;
1440 iio_dev->channels = hw->settings->channels[id].chan;
1441 iio_dev->num_channels = hw->settings->channels[id].len;
1036 1442
1037 sensor = iio_priv(iio_dev); 1443 sensor = iio_priv(iio_dev);
1038 sensor->id = id; 1444 sensor->id = id;
1039 sensor->hw = hw; 1445 sensor->hw = hw;
1040 sensor->odr = st_lsm6dsx_odr_table[id].odr_avl[0].hz; 1446 sensor->odr = hw->settings->odr_table[id].odr_avl[0].hz;
1041 sensor->gain = st_lsm6dsx_fs_table[id].fs_avl[0].gain; 1447 sensor->gain = hw->settings->fs_table[id].fs_avl[0].gain;
1042 sensor->watermark = 1; 1448 sensor->watermark = 1;
1043 1449
1044 switch (id) { 1450 switch (id) {
1045 case ST_LSM6DSX_ID_ACC: 1451 case ST_LSM6DSX_ID_ACC:
1046 iio_dev->channels = st_lsm6dsx_acc_channels;
1047 iio_dev->num_channels = ARRAY_SIZE(st_lsm6dsx_acc_channels);
1048 iio_dev->info = &st_lsm6dsx_acc_info; 1452 iio_dev->info = &st_lsm6dsx_acc_info;
1049
1050 scnprintf(sensor->name, sizeof(sensor->name), "%s_accel", 1453 scnprintf(sensor->name, sizeof(sensor->name), "%s_accel",
1051 name); 1454 name);
1052 break; 1455 break;
1053 case ST_LSM6DSX_ID_GYRO: 1456 case ST_LSM6DSX_ID_GYRO:
1054 iio_dev->channels = st_lsm6dsx_gyro_channels;
1055 iio_dev->num_channels = ARRAY_SIZE(st_lsm6dsx_gyro_channels);
1056 iio_dev->info = &st_lsm6dsx_gyro_info; 1457 iio_dev->info = &st_lsm6dsx_gyro_info;
1057
1058 scnprintf(sensor->name, sizeof(sensor->name), "%s_gyro", 1458 scnprintf(sensor->name, sizeof(sensor->name), "%s_gyro",
1059 name); 1459 name);
1060 break; 1460 break;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
index b3211e0ac07b..f52511059545 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
@@ -75,6 +75,18 @@ static const struct of_device_id st_lsm6dsx_i2c_of_match[] = {
75 .compatible = "st,lsm6dsr", 75 .compatible = "st,lsm6dsr",
76 .data = (void *)ST_LSM6DSR_ID, 76 .data = (void *)ST_LSM6DSR_ID,
77 }, 77 },
78 {
79 .compatible = "st,lsm6ds3tr-c",
80 .data = (void *)ST_LSM6DS3TRC_ID,
81 },
82 {
83 .compatible = "st,ism330dhcx",
84 .data = (void *)ST_ISM330DHCX_ID,
85 },
86 {
87 .compatible = "st,lsm9ds1-imu",
88 .data = (void *)ST_LSM9DS1_ID,
89 },
78 {}, 90 {},
79}; 91};
80MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match); 92MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match);
@@ -89,6 +101,9 @@ static const struct i2c_device_id st_lsm6dsx_i2c_id_table[] = {
89 { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID }, 101 { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID },
90 { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID }, 102 { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID },
91 { ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID }, 103 { ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID },
104 { ST_LSM6DS3TRC_DEV_NAME, ST_LSM6DS3TRC_ID },
105 { ST_ISM330DHCX_DEV_NAME, ST_ISM330DHCX_ID },
106 { ST_LSM9DS1_DEV_NAME, ST_LSM9DS1_ID },
92 {}, 107 {},
93}; 108};
94MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table); 109MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table);
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c
new file mode 100644
index 000000000000..57e633121bdc
--- /dev/null
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c
@@ -0,0 +1,57 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2018 Synopsys, Inc. and/or its affiliates.
4 *
5 * Author: Vitor Soares <vitor.soares@synopsys.com>
6 */
7
8#include <linux/kernel.h>
9#include <linux/module.h>
10#include <linux/i3c/device.h>
11#include <linux/i3c/master.h>
12#include <linux/slab.h>
13#include <linux/of.h>
14#include <linux/regmap.h>
15
16#include "st_lsm6dsx.h"
17
18static const struct i3c_device_id st_lsm6dsx_i3c_ids[] = {
19 I3C_DEVICE(0x0104, 0x006C, (void *)ST_LSM6DSO_ID),
20 I3C_DEVICE(0x0104, 0x006B, (void *)ST_LSM6DSR_ID),
21 { /* sentinel */ },
22};
23MODULE_DEVICE_TABLE(i3c, st_lsm6dsx_i3c_ids);
24
25static int st_lsm6dsx_i3c_probe(struct i3c_device *i3cdev)
26{
27 struct regmap_config st_lsm6dsx_i3c_regmap_config = {
28 .reg_bits = 8,
29 .val_bits = 8,
30 };
31 const struct i3c_device_id *id = i3c_device_match_id(i3cdev,
32 st_lsm6dsx_i3c_ids);
33 struct regmap *regmap;
34
35 regmap = devm_regmap_init_i3c(i3cdev, &st_lsm6dsx_i3c_regmap_config);
36 if (IS_ERR(regmap)) {
37 dev_err(&i3cdev->dev, "Failed to register i3c regmap %d\n",
38 (int)PTR_ERR(regmap));
39 return PTR_ERR(regmap);
40 }
41
42 return st_lsm6dsx_probe(&i3cdev->dev, 0, (uintptr_t)id->data, regmap);
43}
44
45static struct i3c_driver st_lsm6dsx_driver = {
46 .driver = {
47 .name = "st_lsm6dsx_i3c",
48 .pm = &st_lsm6dsx_pm_ops,
49 },
50 .probe = st_lsm6dsx_i3c_probe,
51 .id_table = st_lsm6dsx_i3c_ids,
52};
53module_i3c_driver(st_lsm6dsx_driver);
54
55MODULE_AUTHOR("Vitor Soares <vitor.soares@synopsys.com>");
56MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx i3c driver");
57MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
index c9d3c4711018..344b28dddebb 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
@@ -75,6 +75,18 @@ static const struct of_device_id st_lsm6dsx_spi_of_match[] = {
75 .compatible = "st,lsm6dsr", 75 .compatible = "st,lsm6dsr",
76 .data = (void *)ST_LSM6DSR_ID, 76 .data = (void *)ST_LSM6DSR_ID,
77 }, 77 },
78 {
79 .compatible = "st,lsm6ds3tr-c",
80 .data = (void *)ST_LSM6DS3TRC_ID,
81 },
82 {
83 .compatible = "st,ism330dhcx",
84 .data = (void *)ST_ISM330DHCX_ID,
85 },
86 {
87 .compatible = "st,lsm9ds1-imu",
88 .data = (void *)ST_LSM9DS1_ID,
89 },
78 {}, 90 {},
79}; 91};
80MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match); 92MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match);
@@ -89,6 +101,9 @@ static const struct spi_device_id st_lsm6dsx_spi_id_table[] = {
89 { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID }, 101 { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID },
90 { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID }, 102 { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID },
91 { ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID }, 103 { ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID },
104 { ST_LSM6DS3TRC_DEV_NAME, ST_LSM6DS3TRC_ID },
105 { ST_ISM330DHCX_DEV_NAME, ST_ISM330DHCX_ID },
106 { ST_LSM9DS1_DEV_NAME, ST_LSM9DS1_ID },
92 {}, 107 {},
93}; 108};
94MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table); 109MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table);
diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index e3fd00b595d0..08d7e1ef2186 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -303,6 +303,7 @@ config MAX44000
303config MAX44009 303config MAX44009
304 tristate "MAX44009 Ambient Light Sensor" 304 tristate "MAX44009 Ambient Light Sensor"
305 depends on I2C 305 depends on I2C
306 select REGMAP_I2C
306 help 307 help
307 Say Y here if you want to build support for Maxim Integrated's 308 Say Y here if you want to build support for Maxim Integrated's
308 MAX44009 ambient light sensor device. 309 MAX44009 ambient light sensor device.
@@ -310,6 +311,16 @@ config MAX44009
310 To compile this driver as a module, choose M here: 311 To compile this driver as a module, choose M here:
311 the module will be called max44009. 312 the module will be called max44009.
312 313
314config NOA1305
315 tristate "ON Semiconductor NOA1305 ambient light sensor"
316 depends on I2C
317 help
318 Say Y here if you want to build support for the ON Semiconductor
319 NOA1305 ambient light sensor.
320
321 To compile this driver as a module, choose M here:
322 The module will be called noa1305.
323
313config OPT3001 324config OPT3001
314 tristate "Texas Instruments OPT3001 Light Sensor" 325 tristate "Texas Instruments OPT3001 Light Sensor"
315 depends on I2C 326 depends on I2C
diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
index e40794fbb435..00d1f9b98f39 100644
--- a/drivers/iio/light/Makefile
+++ b/drivers/iio/light/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_LTR501) += ltr501.o
29obj-$(CONFIG_LV0104CS) += lv0104cs.o 29obj-$(CONFIG_LV0104CS) += lv0104cs.o
30obj-$(CONFIG_MAX44000) += max44000.o 30obj-$(CONFIG_MAX44000) += max44000.o
31obj-$(CONFIG_MAX44009) += max44009.o 31obj-$(CONFIG_MAX44009) += max44009.o
32obj-$(CONFIG_NOA1305) += noa1305.o
32obj-$(CONFIG_OPT3001) += opt3001.o 33obj-$(CONFIG_OPT3001) += opt3001.o
33obj-$(CONFIG_PA12203001) += pa12203001.o 34obj-$(CONFIG_PA12203001) += pa12203001.o
34obj-$(CONFIG_RPR0521) += rpr0521.o 35obj-$(CONFIG_RPR0521) += rpr0521.o
diff --git a/drivers/iio/light/apds9960.c b/drivers/iio/light/apds9960.c
index b09b8b60bd83..c5dfb9a6b5a1 100644
--- a/drivers/iio/light/apds9960.c
+++ b/drivers/iio/light/apds9960.c
@@ -1135,5 +1135,5 @@ static struct i2c_driver apds9960_driver = {
1135module_i2c_driver(apds9960_driver); 1135module_i2c_driver(apds9960_driver);
1136 1136
1137MODULE_AUTHOR("Matt Ranostay <matt.ranostay@konsulko.com>"); 1137MODULE_AUTHOR("Matt Ranostay <matt.ranostay@konsulko.com>");
1138MODULE_DESCRIPTION("ADPS9960 Gesture/RGB/ALS/Proximity sensor"); 1138MODULE_DESCRIPTION("APDS9960 Gesture/RGB/ALS/Proximity sensor");
1139MODULE_LICENSE("GPL"); 1139MODULE_LICENSE("GPL");
diff --git a/drivers/iio/light/cm3323.c b/drivers/iio/light/cm3323.c
index 50f3438c2b49..0443861ba1ec 100644
--- a/drivers/iio/light/cm3323.c
+++ b/drivers/iio/light/cm3323.c
@@ -101,15 +101,16 @@ static int cm3323_init(struct iio_dev *indio_dev)
101 return 0; 101 return 0;
102} 102}
103 103
104static void cm3323_disable(struct iio_dev *indio_dev) 104static void cm3323_disable(void *data)
105{ 105{
106 int ret; 106 int ret;
107 struct cm3323_data *data = iio_priv(indio_dev); 107 struct iio_dev *indio_dev = data;
108 struct cm3323_data *cm_data = iio_priv(indio_dev);
108 109
109 ret = i2c_smbus_write_word_data(data->client, CM3323_CMD_CONF, 110 ret = i2c_smbus_write_word_data(cm_data->client, CM3323_CMD_CONF,
110 CM3323_CONF_SD_BIT); 111 CM3323_CONF_SD_BIT);
111 if (ret < 0) 112 if (ret < 0)
112 dev_err(&data->client->dev, "Error writing reg_conf\n"); 113 dev_err(&cm_data->client->dev, "Error writing reg_conf\n");
113} 114}
114 115
115static int cm3323_set_it_bits(struct cm3323_data *data, int val, int val2) 116static int cm3323_set_it_bits(struct cm3323_data *data, int val, int val2)
@@ -243,26 +244,11 @@ static int cm3323_probe(struct i2c_client *client,
243 return ret; 244 return ret;
244 } 245 }
245 246
246 ret = iio_device_register(indio_dev); 247 ret = devm_add_action_or_reset(&client->dev, cm3323_disable, indio_dev);
247 if (ret < 0) { 248 if (ret < 0)
248 dev_err(&client->dev, "failed to register iio dev\n"); 249 return ret;
249 goto err_init;
250 }
251
252 return 0;
253err_init:
254 cm3323_disable(indio_dev);
255 return ret;
256}
257
258static int cm3323_remove(struct i2c_client *client)
259{
260 struct iio_dev *indio_dev = i2c_get_clientdata(client);
261
262 iio_device_unregister(indio_dev);
263 cm3323_disable(indio_dev);
264 250
265 return 0; 251 return devm_iio_device_register(&client->dev, indio_dev);
266} 252}
267 253
268static const struct i2c_device_id cm3323_id[] = { 254static const struct i2c_device_id cm3323_id[] = {
@@ -276,7 +262,6 @@ static struct i2c_driver cm3323_driver = {
276 .name = CM3323_DRV_NAME, 262 .name = CM3323_DRV_NAME,
277 }, 263 },
278 .probe = cm3323_probe, 264 .probe = cm3323_probe,
279 .remove = cm3323_remove,
280 .id_table = cm3323_id, 265 .id_table = cm3323_id,
281}; 266};
282 267
diff --git a/drivers/iio/light/cm36651.c b/drivers/iio/light/cm36651.c
index 7702c2bcbcfa..1019d625adb1 100644
--- a/drivers/iio/light/cm36651.c
+++ b/drivers/iio/light/cm36651.c
@@ -646,18 +646,18 @@ static int cm36651_probe(struct i2c_client *client,
646 i2c_set_clientdata(client, indio_dev); 646 i2c_set_clientdata(client, indio_dev);
647 647
648 cm36651->client = client; 648 cm36651->client = client;
649 cm36651->ps_client = i2c_new_dummy(client->adapter, 649 cm36651->ps_client = i2c_new_dummy_device(client->adapter,
650 CM36651_I2C_ADDR_PS); 650 CM36651_I2C_ADDR_PS);
651 if (!cm36651->ps_client) { 651 if (IS_ERR(cm36651->ps_client)) {
652 dev_err(&client->dev, "%s: new i2c device failed\n", __func__); 652 dev_err(&client->dev, "%s: new i2c device failed\n", __func__);
653 ret = -ENODEV; 653 ret = PTR_ERR(cm36651->ps_client);
654 goto error_disable_reg; 654 goto error_disable_reg;
655 } 655 }
656 656
657 cm36651->ara_client = i2c_new_dummy(client->adapter, CM36651_ARA); 657 cm36651->ara_client = i2c_new_dummy_device(client->adapter, CM36651_ARA);
658 if (!cm36651->ara_client) { 658 if (IS_ERR(cm36651->ara_client)) {
659 dev_err(&client->dev, "%s: new i2c device failed\n", __func__); 659 dev_err(&client->dev, "%s: new i2c device failed\n", __func__);
660 ret = -ENODEV; 660 ret = PTR_ERR(cm36651->ara_client);
661 goto error_i2c_unregister_ps; 661 goto error_i2c_unregister_ps;
662 } 662 }
663 663
diff --git a/drivers/iio/light/cros_ec_light_prox.c b/drivers/iio/light/cros_ec_light_prox.c
index 308ee6ff2e22..44313a009928 100644
--- a/drivers/iio/light/cros_ec_light_prox.c
+++ b/drivers/iio/light/cros_ec_light_prox.c
@@ -42,7 +42,7 @@ static int cros_ec_light_prox_read(struct iio_dev *indio_dev,
42 struct cros_ec_light_prox_state *st = iio_priv(indio_dev); 42 struct cros_ec_light_prox_state *st = iio_priv(indio_dev);
43 u16 data = 0; 43 u16 data = 0;
44 s64 val64; 44 s64 val64;
45 int ret = IIO_VAL_INT; 45 int ret;
46 int idx = chan->scan_index; 46 int idx = chan->scan_index;
47 47
48 mutex_lock(&st->core.cmd_lock); 48 mutex_lock(&st->core.cmd_lock);
@@ -50,23 +50,22 @@ static int cros_ec_light_prox_read(struct iio_dev *indio_dev,
50 switch (mask) { 50 switch (mask) {
51 case IIO_CHAN_INFO_RAW: 51 case IIO_CHAN_INFO_RAW:
52 if (chan->type == IIO_PROXIMITY) { 52 if (chan->type == IIO_PROXIMITY) {
53 if (cros_ec_sensors_read_cmd(indio_dev, 1 << idx, 53 ret = cros_ec_sensors_read_cmd(indio_dev, 1 << idx,
54 (s16 *)&data) < 0) { 54 (s16 *)&data);
55 ret = -EIO; 55 if (ret)
56 break; 56 break;
57 }
58 *val = data; 57 *val = data;
58 ret = IIO_VAL_INT;
59 } else { 59 } else {
60 ret = -EINVAL; 60 ret = -EINVAL;
61 } 61 }
62 break; 62 break;
63 case IIO_CHAN_INFO_PROCESSED: 63 case IIO_CHAN_INFO_PROCESSED:
64 if (chan->type == IIO_LIGHT) { 64 if (chan->type == IIO_LIGHT) {
65 if (cros_ec_sensors_read_cmd(indio_dev, 1 << idx, 65 ret = cros_ec_sensors_read_cmd(indio_dev, 1 << idx,
66 (s16 *)&data) < 0) { 66 (s16 *)&data);
67 ret = -EIO; 67 if (ret)
68 break; 68 break;
69 }
70 /* 69 /*
71 * The data coming from the light sensor is 70 * The data coming from the light sensor is
72 * pre-processed and represents the ambient light 71 * pre-processed and represents the ambient light
@@ -82,15 +81,16 @@ static int cros_ec_light_prox_read(struct iio_dev *indio_dev,
82 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET; 81 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET;
83 st->core.param.sensor_offset.flags = 0; 82 st->core.param.sensor_offset.flags = 0;
84 83
85 if (cros_ec_motion_send_host_cmd(&st->core, 0)) { 84 ret = cros_ec_motion_send_host_cmd(&st->core, 0);
86 ret = -EIO; 85 if (ret)
87 break; 86 break;
88 }
89 87
90 /* Save values */ 88 /* Save values */
91 st->core.calib[0] = st->core.resp->sensor_offset.offset[0]; 89 st->core.calib[0].offset =
90 st->core.resp->sensor_offset.offset[0];
92 91
93 *val = st->core.calib[idx]; 92 *val = st->core.calib[idx].offset;
93 ret = IIO_VAL_INT;
94 break; 94 break;
95 case IIO_CHAN_INFO_CALIBSCALE: 95 case IIO_CHAN_INFO_CALIBSCALE:
96 /* 96 /*
@@ -101,10 +101,9 @@ static int cros_ec_light_prox_read(struct iio_dev *indio_dev,
101 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE; 101 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE;
102 st->core.param.sensor_range.data = EC_MOTION_SENSE_NO_VALUE; 102 st->core.param.sensor_range.data = EC_MOTION_SENSE_NO_VALUE;
103 103
104 if (cros_ec_motion_send_host_cmd(&st->core, 0)) { 104 ret = cros_ec_motion_send_host_cmd(&st->core, 0);
105 ret = -EIO; 105 if (ret)
106 break; 106 break;
107 }
108 107
109 val64 = st->core.resp->sensor_range.ret; 108 val64 = st->core.resp->sensor_range.ret;
110 *val = val64 >> 16; 109 *val = val64 >> 16;
@@ -127,28 +126,27 @@ static int cros_ec_light_prox_write(struct iio_dev *indio_dev,
127 int val, int val2, long mask) 126 int val, int val2, long mask)
128{ 127{
129 struct cros_ec_light_prox_state *st = iio_priv(indio_dev); 128 struct cros_ec_light_prox_state *st = iio_priv(indio_dev);
130 int ret = 0; 129 int ret;
131 int idx = chan->scan_index; 130 int idx = chan->scan_index;
132 131
133 mutex_lock(&st->core.cmd_lock); 132 mutex_lock(&st->core.cmd_lock);
134 133
135 switch (mask) { 134 switch (mask) {
136 case IIO_CHAN_INFO_CALIBBIAS: 135 case IIO_CHAN_INFO_CALIBBIAS:
137 st->core.calib[idx] = val; 136 st->core.calib[idx].offset = val;
138 /* Send to EC for each axis, even if not complete */ 137 /* Send to EC for each axis, even if not complete */
139 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET; 138 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET;
140 st->core.param.sensor_offset.flags = MOTION_SENSE_SET_OFFSET; 139 st->core.param.sensor_offset.flags = MOTION_SENSE_SET_OFFSET;
141 st->core.param.sensor_offset.offset[0] = st->core.calib[0]; 140 st->core.param.sensor_offset.offset[0] =
141 st->core.calib[0].offset;
142 st->core.param.sensor_offset.temp = 142 st->core.param.sensor_offset.temp =
143 EC_MOTION_SENSE_INVALID_CALIB_TEMP; 143 EC_MOTION_SENSE_INVALID_CALIB_TEMP;
144 if (cros_ec_motion_send_host_cmd(&st->core, 0)) 144 ret = cros_ec_motion_send_host_cmd(&st->core, 0);
145 ret = -EIO;
146 break; 145 break;
147 case IIO_CHAN_INFO_CALIBSCALE: 146 case IIO_CHAN_INFO_CALIBSCALE:
148 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE; 147 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE;
149 st->core.param.sensor_range.data = (val << 16) | (val2 / 100); 148 st->core.param.sensor_range.data = (val << 16) | (val2 / 100);
150 if (cros_ec_motion_send_host_cmd(&st->core, 0)) 149 ret = cros_ec_motion_send_host_cmd(&st->core, 0);
151 ret = -EIO;
152 break; 150 break;
153 default: 151 default:
154 ret = cros_ec_sensors_core_write(&st->core, chan, val, val2, 152 ret = cros_ec_sensors_core_write(&st->core, chan, val, val2,
@@ -164,6 +162,7 @@ static int cros_ec_light_prox_write(struct iio_dev *indio_dev,
164static const struct iio_info cros_ec_light_prox_info = { 162static const struct iio_info cros_ec_light_prox_info = {
165 .read_raw = &cros_ec_light_prox_read, 163 .read_raw = &cros_ec_light_prox_read,
166 .write_raw = &cros_ec_light_prox_write, 164 .write_raw = &cros_ec_light_prox_write,
165 .read_avail = &cros_ec_sensors_core_read_avail,
167}; 166};
168 167
169static int cros_ec_light_prox_probe(struct platform_device *pdev) 168static int cros_ec_light_prox_probe(struct platform_device *pdev)
@@ -198,6 +197,8 @@ static int cros_ec_light_prox_probe(struct platform_device *pdev)
198 channel->info_mask_shared_by_all = 197 channel->info_mask_shared_by_all =
199 BIT(IIO_CHAN_INFO_SAMP_FREQ) | 198 BIT(IIO_CHAN_INFO_SAMP_FREQ) |
200 BIT(IIO_CHAN_INFO_FREQUENCY); 199 BIT(IIO_CHAN_INFO_FREQUENCY);
200 channel->info_mask_shared_by_all_available =
201 BIT(IIO_CHAN_INFO_SAMP_FREQ);
201 channel->scan_type.realbits = CROS_EC_SENSOR_BITS; 202 channel->scan_type.realbits = CROS_EC_SENSOR_BITS;
202 channel->scan_type.storagebits = CROS_EC_SENSOR_BITS; 203 channel->scan_type.storagebits = CROS_EC_SENSOR_BITS;
203 channel->scan_type.shift = 0; 204 channel->scan_type.shift = 0;
@@ -205,8 +206,6 @@ static int cros_ec_light_prox_probe(struct platform_device *pdev)
205 channel->ext_info = cros_ec_sensors_ext_info; 206 channel->ext_info = cros_ec_sensors_ext_info;
206 channel->scan_type.sign = 'u'; 207 channel->scan_type.sign = 'u';
207 208
208 state->core.calib[0] = 0;
209
210 /* Sensor specific */ 209 /* Sensor specific */
211 switch (state->core.type) { 210 switch (state->core.type) {
212 case MOTIONSENSE_TYPE_LIGHT: 211 case MOTIONSENSE_TYPE_LIGHT:
diff --git a/drivers/iio/light/noa1305.c b/drivers/iio/light/noa1305.c
new file mode 100644
index 000000000000..5ebfbc52f541
--- /dev/null
+++ b/drivers/iio/light/noa1305.c
@@ -0,0 +1,313 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Support for ON Semiconductor NOA1305 ambient light sensor
4 *
5 * Copyright (C) 2016 Emcraft Systems
6 * Copyright (C) 2019 Collabora Ltd.
7 */
8
9#include <linux/delay.h>
10#include <linux/err.h>
11#include <linux/i2c.h>
12#include <linux/iio/iio.h>
13#include <linux/iio/sysfs.h>
14#include <linux/module.h>
15#include <linux/regmap.h>
16#include <linux/regulator/consumer.h>
17
18#define NOA1305_REG_POWER_CONTROL 0x0
19#define NOA1305_POWER_CONTROL_DOWN 0x00
20#define NOA1305_POWER_CONTROL_ON 0x08
21#define NOA1305_REG_RESET 0x1
22#define NOA1305_RESET_RESET 0x10
23#define NOA1305_REG_INTEGRATION_TIME 0x2
24#define NOA1305_INTEGR_TIME_800MS 0x00
25#define NOA1305_INTEGR_TIME_400MS 0x01
26#define NOA1305_INTEGR_TIME_200MS 0x02
27#define NOA1305_INTEGR_TIME_100MS 0x03
28#define NOA1305_INTEGR_TIME_50MS 0x04
29#define NOA1305_INTEGR_TIME_25MS 0x05
30#define NOA1305_INTEGR_TIME_12_5MS 0x06
31#define NOA1305_INTEGR_TIME_6_25MS 0x07
32#define NOA1305_REG_INT_SELECT 0x3
33#define NOA1305_INT_SEL_ACTIVE_HIGH 0x01
34#define NOA1305_INT_SEL_ACTIVE_LOW 0x02
35#define NOA1305_INT_SEL_INACTIVE 0x03
36#define NOA1305_REG_INT_THRESH_LSB 0x4
37#define NOA1305_REG_INT_THRESH_MSB 0x5
38#define NOA1305_REG_ALS_DATA_LSB 0x6
39#define NOA1305_REG_ALS_DATA_MSB 0x7
40#define NOA1305_REG_DEVICE_ID_LSB 0x8
41#define NOA1305_REG_DEVICE_ID_MSB 0x9
42
43#define NOA1305_DEVICE_ID 0x0519
44#define NOA1305_DRIVER_NAME "noa1305"
45
46struct noa1305_priv {
47 struct i2c_client *client;
48 struct regmap *regmap;
49 struct regulator *vin_reg;
50};
51
52static int noa1305_measure(struct noa1305_priv *priv)
53{
54 __le16 data;
55 int ret;
56
57 ret = regmap_bulk_read(priv->regmap, NOA1305_REG_ALS_DATA_LSB, &data,
58 2);
59 if (ret < 0)
60 return ret;
61
62 return le16_to_cpu(data);
63}
64
65static int noa1305_scale(struct noa1305_priv *priv, int *val, int *val2)
66{
67 int data;
68 int ret;
69
70 ret = regmap_read(priv->regmap, NOA1305_REG_INTEGRATION_TIME, &data);
71 if (ret < 0)
72 return ret;
73
74 /*
75 * Lux = count / (<Integration Constant> * <Integration Time>)
76 *
77 * Integration Constant = 7.7
78 * Integration Time in Seconds
79 */
80 switch (data) {
81 case NOA1305_INTEGR_TIME_800MS:
82 *val = 100;
83 *val2 = 77 * 8;
84 break;
85 case NOA1305_INTEGR_TIME_400MS:
86 *val = 100;
87 *val2 = 77 * 4;
88 break;
89 case NOA1305_INTEGR_TIME_200MS:
90 *val = 100;
91 *val2 = 77 * 2;
92 break;
93 case NOA1305_INTEGR_TIME_100MS:
94 *val = 100;
95 *val2 = 77;
96 break;
97 case NOA1305_INTEGR_TIME_50MS:
98 *val = 1000;
99 *val2 = 77 * 5;
100 break;
101 case NOA1305_INTEGR_TIME_25MS:
102 *val = 10000;
103 *val2 = 77 * 25;
104 break;
105 case NOA1305_INTEGR_TIME_12_5MS:
106 *val = 100000;
107 *val2 = 77 * 125;
108 break;
109 case NOA1305_INTEGR_TIME_6_25MS:
110 *val = 1000000;
111 *val2 = 77 * 625;
112 break;
113 default:
114 return -EINVAL;
115 }
116
117 return IIO_VAL_FRACTIONAL;
118}
119
120static const struct iio_chan_spec noa1305_channels[] = {
121 {
122 .type = IIO_LIGHT,
123 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
124 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
125 }
126};
127
128static int noa1305_read_raw(struct iio_dev *indio_dev,
129 struct iio_chan_spec const *chan,
130 int *val, int *val2, long mask)
131{
132 int ret = -EINVAL;
133 struct noa1305_priv *priv = iio_priv(indio_dev);
134
135 switch (mask) {
136 case IIO_CHAN_INFO_RAW:
137 switch (chan->type) {
138 case IIO_LIGHT:
139 ret = noa1305_measure(priv);
140 if (ret < 0)
141 return ret;
142 *val = ret;
143 return IIO_VAL_INT;
144 default:
145 break;
146 }
147 break;
148 case IIO_CHAN_INFO_SCALE:
149 switch (chan->type) {
150 case IIO_LIGHT:
151 return noa1305_scale(priv, val, val2);
152 default:
153 break;
154 }
155 break;
156 default:
157 break;
158 }
159
160 return ret;
161}
162
163static const struct iio_info noa1305_info = {
164 .read_raw = noa1305_read_raw,
165};
166
167static bool noa1305_writable_reg(struct device *dev, unsigned int reg)
168{
169 switch (reg) {
170 case NOA1305_REG_POWER_CONTROL:
171 case NOA1305_REG_RESET:
172 case NOA1305_REG_INTEGRATION_TIME:
173 case NOA1305_REG_INT_SELECT:
174 case NOA1305_REG_INT_THRESH_LSB:
175 case NOA1305_REG_INT_THRESH_MSB:
176 return true;
177 default:
178 return false;
179 }
180}
181
182static const struct regmap_config noa1305_regmap_config = {
183 .name = NOA1305_DRIVER_NAME,
184 .reg_bits = 8,
185 .val_bits = 8,
186 .max_register = NOA1305_REG_DEVICE_ID_MSB,
187 .writeable_reg = noa1305_writable_reg,
188};
189
190static void noa1305_reg_remove(void *data)
191{
192 struct noa1305_priv *priv = data;
193
194 regulator_disable(priv->vin_reg);
195}
196
197static int noa1305_probe(struct i2c_client *client,
198 const struct i2c_device_id *id)
199{
200 struct noa1305_priv *priv;
201 struct iio_dev *indio_dev;
202 struct regmap *regmap;
203 __le16 data;
204 unsigned int dev_id;
205 int ret;
206
207 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*priv));
208 if (!indio_dev)
209 return -ENOMEM;
210
211 regmap = devm_regmap_init_i2c(client, &noa1305_regmap_config);
212 if (IS_ERR(regmap)) {
213 dev_err(&client->dev, "Regmap initialization failed.\n");
214 return PTR_ERR(regmap);
215 }
216
217 priv = iio_priv(indio_dev);
218
219 priv->vin_reg = devm_regulator_get(&client->dev, "vin");
220 if (IS_ERR(priv->vin_reg)) {
221 dev_err(&client->dev, "get regulator vin failed\n");
222 return PTR_ERR(priv->vin_reg);
223 }
224
225 ret = regulator_enable(priv->vin_reg);
226 if (ret) {
227 dev_err(&client->dev, "enable regulator vin failed\n");
228 return ret;
229 }
230
231 ret = devm_add_action_or_reset(&client->dev, noa1305_reg_remove, priv);
232 if (ret) {
233 dev_err(&client->dev, "addition of devm action failed\n");
234 return ret;
235 }
236
237 i2c_set_clientdata(client, indio_dev);
238 priv->client = client;
239 priv->regmap = regmap;
240
241 ret = regmap_bulk_read(regmap, NOA1305_REG_DEVICE_ID_LSB, &data, 2);
242 if (ret < 0) {
243 dev_err(&client->dev, "ID reading failed: %d\n", ret);
244 return ret;
245 }
246
247 dev_id = le16_to_cpu(data);
248 if (dev_id != NOA1305_DEVICE_ID) {
249 dev_err(&client->dev, "Unknown device ID: 0x%x\n", dev_id);
250 return -ENODEV;
251 }
252
253 ret = regmap_write(regmap, NOA1305_REG_POWER_CONTROL,
254 NOA1305_POWER_CONTROL_ON);
255 if (ret < 0) {
256 dev_err(&client->dev, "Enabling power control failed\n");
257 return ret;
258 }
259
260 ret = regmap_write(regmap, NOA1305_REG_RESET, NOA1305_RESET_RESET);
261 if (ret < 0) {
262 dev_err(&client->dev, "Device reset failed\n");
263 return ret;
264 }
265
266 ret = regmap_write(regmap, NOA1305_REG_INTEGRATION_TIME,
267 NOA1305_INTEGR_TIME_800MS);
268 if (ret < 0) {
269 dev_err(&client->dev, "Setting integration time failed\n");
270 return ret;
271 }
272
273 indio_dev->dev.parent = &client->dev;
274 indio_dev->info = &noa1305_info;
275 indio_dev->channels = noa1305_channels;
276 indio_dev->num_channels = ARRAY_SIZE(noa1305_channels);
277 indio_dev->name = NOA1305_DRIVER_NAME;
278 indio_dev->modes = INDIO_DIRECT_MODE;
279
280 ret = devm_iio_device_register(&client->dev, indio_dev);
281 if (ret)
282 dev_err(&client->dev, "registering device failed\n");
283
284 return ret;
285}
286
287static const struct of_device_id noa1305_of_match[] = {
288 { .compatible = "onnn,noa1305" },
289 { }
290};
291MODULE_DEVICE_TABLE(of, noa1305_of_match);
292
293static const struct i2c_device_id noa1305_ids[] = {
294 { "noa1305", 0 },
295 { }
296};
297MODULE_DEVICE_TABLE(i2c, noa1305_ids);
298
299static struct i2c_driver noa1305_driver = {
300 .driver = {
301 .name = NOA1305_DRIVER_NAME,
302 .of_match_table = noa1305_of_match,
303 },
304 .probe = noa1305_probe,
305 .id_table = noa1305_ids,
306};
307
308module_i2c_driver(noa1305_driver);
309
310MODULE_AUTHOR("Sergei Miroshnichenko <sergeimir@emcraft.com>");
311MODULE_AUTHOR("Martyn Welch <martyn.welch@collabora.com");
312MODULE_DESCRIPTION("ON Semiconductor NOA1305 ambient light sensor");
313MODULE_LICENSE("GPL");
diff --git a/drivers/iio/light/si1145.c b/drivers/iio/light/si1145.c
index 6579d2418814..982bba0c54e7 100644
--- a/drivers/iio/light/si1145.c
+++ b/drivers/iio/light/si1145.c
@@ -1261,7 +1261,7 @@ static int si1145_probe_trigger(struct iio_dev *indio_dev)
1261 return ret; 1261 return ret;
1262 } 1262 }
1263 1263
1264 ret = iio_trigger_register(trig); 1264 ret = devm_iio_trigger_register(&client->dev, trig);
1265 if (ret) 1265 if (ret)
1266 return ret; 1266 return ret;
1267 1267
@@ -1271,16 +1271,6 @@ static int si1145_probe_trigger(struct iio_dev *indio_dev)
1271 return 0; 1271 return 0;
1272} 1272}
1273 1273
1274static void si1145_remove_trigger(struct iio_dev *indio_dev)
1275{
1276 struct si1145_data *data = iio_priv(indio_dev);
1277
1278 if (data->trig) {
1279 iio_trigger_unregister(data->trig);
1280 data->trig = NULL;
1281 }
1282}
1283
1284static int si1145_probe(struct i2c_client *client, 1274static int si1145_probe(struct i2c_client *client,
1285 const struct i2c_device_id *id) 1275 const struct i2c_device_id *id)
1286{ 1276{
@@ -1332,7 +1322,8 @@ static int si1145_probe(struct i2c_client *client,
1332 if (ret < 0) 1322 if (ret < 0)
1333 return ret; 1323 return ret;
1334 1324
1335 ret = iio_triggered_buffer_setup(indio_dev, NULL, 1325 ret = devm_iio_triggered_buffer_setup(&client->dev,
1326 indio_dev, NULL,
1336 si1145_trigger_handler, &si1145_buffer_setup_ops); 1327 si1145_trigger_handler, &si1145_buffer_setup_ops);
1337 if (ret < 0) 1328 if (ret < 0)
1338 return ret; 1329 return ret;
@@ -1340,23 +1331,12 @@ static int si1145_probe(struct i2c_client *client,
1340 if (client->irq) { 1331 if (client->irq) {
1341 ret = si1145_probe_trigger(indio_dev); 1332 ret = si1145_probe_trigger(indio_dev);
1342 if (ret < 0) 1333 if (ret < 0)
1343 goto error_free_buffer; 1334 return ret;
1344 } else { 1335 } else {
1345 dev_info(&client->dev, "no irq, using polling\n"); 1336 dev_info(&client->dev, "no irq, using polling\n");
1346 } 1337 }
1347 1338
1348 ret = iio_device_register(indio_dev); 1339 return devm_iio_device_register(&client->dev, indio_dev);
1349 if (ret < 0)
1350 goto error_free_trigger;
1351
1352 return 0;
1353
1354error_free_trigger:
1355 si1145_remove_trigger(indio_dev);
1356error_free_buffer:
1357 iio_triggered_buffer_cleanup(indio_dev);
1358
1359 return ret;
1360} 1340}
1361 1341
1362static const struct i2c_device_id si1145_ids[] = { 1342static const struct i2c_device_id si1145_ids[] = {
@@ -1371,23 +1351,11 @@ static const struct i2c_device_id si1145_ids[] = {
1371}; 1351};
1372MODULE_DEVICE_TABLE(i2c, si1145_ids); 1352MODULE_DEVICE_TABLE(i2c, si1145_ids);
1373 1353
1374static int si1145_remove(struct i2c_client *client)
1375{
1376 struct iio_dev *indio_dev = i2c_get_clientdata(client);
1377
1378 iio_device_unregister(indio_dev);
1379 si1145_remove_trigger(indio_dev);
1380 iio_triggered_buffer_cleanup(indio_dev);
1381
1382 return 0;
1383}
1384
1385static struct i2c_driver si1145_driver = { 1354static struct i2c_driver si1145_driver = {
1386 .driver = { 1355 .driver = {
1387 .name = "si1145", 1356 .name = "si1145",
1388 }, 1357 },
1389 .probe = si1145_probe, 1358 .probe = si1145_probe,
1390 .remove = si1145_remove,
1391 .id_table = si1145_ids, 1359 .id_table = si1145_ids,
1392}; 1360};
1393 1361
diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c
index b955183edfe8..185c24a75ae6 100644
--- a/drivers/iio/light/stk3310.c
+++ b/drivers/iio/light/stk3310.c
@@ -679,9 +679,18 @@ static const struct acpi_device_id stk3310_acpi_id[] = {
679 679
680MODULE_DEVICE_TABLE(acpi, stk3310_acpi_id); 680MODULE_DEVICE_TABLE(acpi, stk3310_acpi_id);
681 681
682static const struct of_device_id stk3310_of_match[] = {
683 { .compatible = "sensortek,stk3310", },
684 { .compatible = "sensortek,stk3311", },
685 { .compatible = "sensortek,stk3335", },
686 {}
687};
688MODULE_DEVICE_TABLE(of, stk3310_of_match);
689
682static struct i2c_driver stk3310_driver = { 690static struct i2c_driver stk3310_driver = {
683 .driver = { 691 .driver = {
684 .name = "stk3310", 692 .name = "stk3310",
693 .of_match_table = stk3310_of_match,
685 .pm = STK3310_PM_OPS, 694 .pm = STK3310_PM_OPS,
686 .acpi_match_table = ACPI_PTR(stk3310_acpi_id), 695 .acpi_match_table = ACPI_PTR(stk3310_acpi_id),
687 }, 696 },
diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c
index 83cece921843..be37fcbd4654 100644
--- a/drivers/iio/light/tsl2772.c
+++ b/drivers/iio/light/tsl2772.c
@@ -134,6 +134,12 @@ enum {
134 TSL2772_CHIP_SUSPENDED = 2 134 TSL2772_CHIP_SUSPENDED = 2
135}; 135};
136 136
137enum {
138 TSL2772_SUPPLY_VDD = 0,
139 TSL2772_SUPPLY_VDDIO = 1,
140 TSL2772_NUM_SUPPLIES = 2
141};
142
137/* Per-device data */ 143/* Per-device data */
138struct tsl2772_als_info { 144struct tsl2772_als_info {
139 u16 als_ch0; 145 u16 als_ch0;
@@ -161,8 +167,7 @@ struct tsl2772_chip {
161 struct mutex prox_mutex; 167 struct mutex prox_mutex;
162 struct mutex als_mutex; 168 struct mutex als_mutex;
163 struct i2c_client *client; 169 struct i2c_client *client;
164 struct regulator *vdd_supply; 170 struct regulator_bulk_data supplies[TSL2772_NUM_SUPPLIES];
165 struct regulator *vddio_supply;
166 u16 prox_data; 171 u16 prox_data;
167 struct tsl2772_als_info als_cur_info; 172 struct tsl2772_als_info als_cur_info;
168 struct tsl2772_settings settings; 173 struct tsl2772_settings settings;
@@ -697,46 +702,7 @@ static void tsl2772_disable_regulators_action(void *_data)
697{ 702{
698 struct tsl2772_chip *chip = _data; 703 struct tsl2772_chip *chip = _data;
699 704
700 regulator_disable(chip->vdd_supply); 705 regulator_bulk_disable(ARRAY_SIZE(chip->supplies), chip->supplies);
701 regulator_disable(chip->vddio_supply);
702}
703
704static int tsl2772_enable_regulator(struct tsl2772_chip *chip,
705 struct regulator *regulator)
706{
707 int ret;
708
709 ret = regulator_enable(regulator);
710 if (ret < 0) {
711 dev_err(&chip->client->dev, "Failed to enable regulator: %d\n",
712 ret);
713 return ret;
714 }
715
716 return 0;
717}
718
719static struct regulator *tsl2772_get_regulator(struct tsl2772_chip *chip,
720 char *name)
721{
722 struct regulator *regulator;
723 int ret;
724
725 regulator = devm_regulator_get(&chip->client->dev, name);
726 if (IS_ERR(regulator)) {
727 if (PTR_ERR(regulator) != -EPROBE_DEFER)
728 dev_err(&chip->client->dev,
729 "Failed to get %s regulator %d\n",
730 name, (int)PTR_ERR(regulator));
731
732 return regulator;
733 }
734
735 ret = tsl2772_enable_regulator(chip, regulator);
736 if (ret < 0)
737 return ERR_PTR(ret);
738
739 return regulator;
740} 706}
741 707
742static int tsl2772_chip_on(struct iio_dev *indio_dev) 708static int tsl2772_chip_on(struct iio_dev *indio_dev)
@@ -860,6 +826,13 @@ static int tsl2772_chip_off(struct iio_dev *indio_dev)
860 return tsl2772_write_control_reg(chip, 0x00); 826 return tsl2772_write_control_reg(chip, 0x00);
861} 827}
862 828
829static void tsl2772_chip_off_action(void *data)
830{
831 struct iio_dev *indio_dev = data;
832
833 tsl2772_chip_off(indio_dev);
834}
835
863/** 836/**
864 * tsl2772_invoke_change - power cycle the device to implement the user 837 * tsl2772_invoke_change - power cycle the device to implement the user
865 * parameters 838 * parameters
@@ -1797,20 +1770,32 @@ static int tsl2772_probe(struct i2c_client *clientp,
1797 chip->client = clientp; 1770 chip->client = clientp;
1798 i2c_set_clientdata(clientp, indio_dev); 1771 i2c_set_clientdata(clientp, indio_dev);
1799 1772
1800 chip->vddio_supply = tsl2772_get_regulator(chip, "vddio"); 1773 chip->supplies[TSL2772_SUPPLY_VDD].supply = "vdd";
1801 if (IS_ERR(chip->vddio_supply)) 1774 chip->supplies[TSL2772_SUPPLY_VDDIO].supply = "vddio";
1802 return PTR_ERR(chip->vddio_supply); 1775
1776 ret = devm_regulator_bulk_get(&clientp->dev,
1777 ARRAY_SIZE(chip->supplies),
1778 chip->supplies);
1779 if (ret < 0) {
1780 if (ret != -EPROBE_DEFER)
1781 dev_err(&clientp->dev,
1782 "Failed to get regulators: %d\n",
1783 ret);
1784
1785 return ret;
1786 }
1803 1787
1804 chip->vdd_supply = tsl2772_get_regulator(chip, "vdd"); 1788 ret = regulator_bulk_enable(ARRAY_SIZE(chip->supplies), chip->supplies);
1805 if (IS_ERR(chip->vdd_supply)) { 1789 if (ret < 0) {
1806 regulator_disable(chip->vddio_supply); 1790 dev_err(&clientp->dev, "Failed to enable regulators: %d\n",
1807 return PTR_ERR(chip->vdd_supply); 1791 ret);
1792 return ret;
1808 } 1793 }
1809 1794
1810 ret = devm_add_action(&clientp->dev, tsl2772_disable_regulators_action, 1795 ret = devm_add_action_or_reset(&clientp->dev,
1811 chip); 1796 tsl2772_disable_regulators_action,
1797 chip);
1812 if (ret < 0) { 1798 if (ret < 0) {
1813 tsl2772_disable_regulators_action(chip);
1814 dev_err(&clientp->dev, "Failed to setup regulator cleanup action %d\n", 1799 dev_err(&clientp->dev, "Failed to setup regulator cleanup action %d\n",
1815 ret); 1800 ret);
1816 return ret; 1801 return ret;
@@ -1877,15 +1862,13 @@ static int tsl2772_probe(struct i2c_client *clientp,
1877 if (ret < 0) 1862 if (ret < 0)
1878 return ret; 1863 return ret;
1879 1864
1880 ret = iio_device_register(indio_dev); 1865 ret = devm_add_action_or_reset(&clientp->dev,
1881 if (ret) { 1866 tsl2772_chip_off_action,
1882 tsl2772_chip_off(indio_dev); 1867 indio_dev);
1883 dev_err(&clientp->dev, 1868 if (ret < 0)
1884 "%s: iio registration failed\n", __func__);
1885 return ret; 1869 return ret;
1886 }
1887 1870
1888 return 0; 1871 return devm_iio_device_register(&clientp->dev, indio_dev);
1889} 1872}
1890 1873
1891static int tsl2772_suspend(struct device *dev) 1874static int tsl2772_suspend(struct device *dev)
@@ -1895,8 +1878,7 @@ static int tsl2772_suspend(struct device *dev)
1895 int ret; 1878 int ret;
1896 1879
1897 ret = tsl2772_chip_off(indio_dev); 1880 ret = tsl2772_chip_off(indio_dev);
1898 regulator_disable(chip->vdd_supply); 1881 regulator_bulk_disable(ARRAY_SIZE(chip->supplies), chip->supplies);
1899 regulator_disable(chip->vddio_supply);
1900 1882
1901 return ret; 1883 return ret;
1902} 1884}
@@ -1907,32 +1889,15 @@ static int tsl2772_resume(struct device *dev)
1907 struct tsl2772_chip *chip = iio_priv(indio_dev); 1889 struct tsl2772_chip *chip = iio_priv(indio_dev);
1908 int ret; 1890 int ret;
1909 1891
1910 ret = tsl2772_enable_regulator(chip, chip->vddio_supply); 1892 ret = regulator_bulk_enable(ARRAY_SIZE(chip->supplies), chip->supplies);
1911 if (ret < 0) 1893 if (ret < 0)
1912 return ret; 1894 return ret;
1913 1895
1914 ret = tsl2772_enable_regulator(chip, chip->vdd_supply);
1915 if (ret < 0) {
1916 regulator_disable(chip->vddio_supply);
1917 return ret;
1918 }
1919
1920 usleep_range(TSL2772_BOOT_MIN_SLEEP_TIME, TSL2772_BOOT_MAX_SLEEP_TIME); 1896 usleep_range(TSL2772_BOOT_MIN_SLEEP_TIME, TSL2772_BOOT_MAX_SLEEP_TIME);
1921 1897
1922 return tsl2772_chip_on(indio_dev); 1898 return tsl2772_chip_on(indio_dev);
1923} 1899}
1924 1900
1925static int tsl2772_remove(struct i2c_client *client)
1926{
1927 struct iio_dev *indio_dev = i2c_get_clientdata(client);
1928
1929 tsl2772_chip_off(indio_dev);
1930
1931 iio_device_unregister(indio_dev);
1932
1933 return 0;
1934}
1935
1936static const struct i2c_device_id tsl2772_idtable[] = { 1901static const struct i2c_device_id tsl2772_idtable[] = {
1937 { "tsl2571", tsl2571 }, 1902 { "tsl2571", tsl2571 },
1938 { "tsl2671", tsl2671 }, 1903 { "tsl2671", tsl2671 },
@@ -1979,7 +1944,6 @@ static struct i2c_driver tsl2772_driver = {
1979 }, 1944 },
1980 .id_table = tsl2772_idtable, 1945 .id_table = tsl2772_idtable,
1981 .probe = tsl2772_probe, 1946 .probe = tsl2772_probe,
1982 .remove = tsl2772_remove,
1983}; 1947};
1984 1948
1985module_i2c_driver(tsl2772_driver); 1949module_i2c_driver(tsl2772_driver);
diff --git a/drivers/iio/light/veml6070.c b/drivers/iio/light/veml6070.c
index a3138e1b5803..0be553ad5989 100644
--- a/drivers/iio/light/veml6070.c
+++ b/drivers/iio/light/veml6070.c
@@ -158,10 +158,10 @@ static int veml6070_probe(struct i2c_client *client,
158 indio_dev->name = VEML6070_DRV_NAME; 158 indio_dev->name = VEML6070_DRV_NAME;
159 indio_dev->modes = INDIO_DIRECT_MODE; 159 indio_dev->modes = INDIO_DIRECT_MODE;
160 160
161 data->client2 = i2c_new_dummy(client->adapter, VEML6070_ADDR_DATA_LSB); 161 data->client2 = i2c_new_dummy_device(client->adapter, VEML6070_ADDR_DATA_LSB);
162 if (!data->client2) { 162 if (IS_ERR(data->client2)) {
163 dev_err(&client->dev, "i2c device for second chip address failed\n"); 163 dev_err(&client->dev, "i2c device for second chip address failed\n");
164 return -ENODEV; 164 return PTR_ERR(data->client2);
165 } 165 }
166 166
167 data->config = VEML6070_IT_10 | VEML6070_COMMAND_RSRVD | 167 data->config = VEML6070_IT_10 | VEML6070_COMMAND_RSRVD |
diff --git a/drivers/iio/magnetometer/mmc35240.c b/drivers/iio/magnetometer/mmc35240.c
index 7de10281ad9e..425cdd07b4e5 100644
--- a/drivers/iio/magnetometer/mmc35240.c
+++ b/drivers/iio/magnetometer/mmc35240.c
@@ -53,7 +53,7 @@
53#define MMC35240_CTRL1_BW_SHIFT 0 53#define MMC35240_CTRL1_BW_SHIFT 0
54 54
55#define MMC35240_WAIT_CHARGE_PUMP 50000 /* us */ 55#define MMC35240_WAIT_CHARGE_PUMP 50000 /* us */
56#define MMC53240_WAIT_SET_RESET 1000 /* us */ 56#define MMC35240_WAIT_SET_RESET 1000 /* us */
57 57
58/* 58/*
59 * Memsic OTP process code piece is put here for reference: 59 * Memsic OTP process code piece is put here for reference:
@@ -225,7 +225,7 @@ static int mmc35240_init(struct mmc35240_data *data)
225 ret = mmc35240_hw_set(data, true); 225 ret = mmc35240_hw_set(data, true);
226 if (ret < 0) 226 if (ret < 0)
227 return ret; 227 return ret;
228 usleep_range(MMC53240_WAIT_SET_RESET, MMC53240_WAIT_SET_RESET + 1); 228 usleep_range(MMC35240_WAIT_SET_RESET, MMC35240_WAIT_SET_RESET + 1);
229 229
230 ret = mmc35240_hw_set(data, false); 230 ret = mmc35240_hw_set(data, false);
231 if (ret < 0) 231 if (ret < 0)
diff --git a/drivers/iio/magnetometer/st_magn.h b/drivers/iio/magnetometer/st_magn.h
index d69ef9b2a731..204b285725c8 100644
--- a/drivers/iio/magnetometer/st_magn.h
+++ b/drivers/iio/magnetometer/st_magn.h
@@ -22,6 +22,7 @@
22#define LIS2MDL_MAGN_DEV_NAME "lis2mdl" 22#define LIS2MDL_MAGN_DEV_NAME "lis2mdl"
23#define LSM9DS1_MAGN_DEV_NAME "lsm9ds1_magn" 23#define LSM9DS1_MAGN_DEV_NAME "lsm9ds1_magn"
24 24
25const struct st_sensor_settings *st_magn_get_settings(const char *name);
25int st_magn_common_probe(struct iio_dev *indio_dev); 26int st_magn_common_probe(struct iio_dev *indio_dev);
26void st_magn_common_remove(struct iio_dev *indio_dev); 27void st_magn_common_remove(struct iio_dev *indio_dev);
27 28
diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c
index 11d7806655bc..bb425c167a96 100644
--- a/drivers/iio/magnetometer/st_magn_buffer.c
+++ b/drivers/iio/magnetometer/st_magn_buffer.c
@@ -32,39 +32,32 @@ int st_magn_trig_set_state(struct iio_trigger *trig, bool state)
32static int st_magn_buffer_postenable(struct iio_dev *indio_dev) 32static int st_magn_buffer_postenable(struct iio_dev *indio_dev)
33{ 33{
34 int err; 34 int err;
35 struct st_sensor_data *mdata = iio_priv(indio_dev);
36
37 mdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
38 if (mdata->buffer_data == NULL) {
39 err = -ENOMEM;
40 goto allocate_memory_error;
41 }
42 35
43 err = iio_triggered_buffer_postenable(indio_dev); 36 err = iio_triggered_buffer_postenable(indio_dev);
44 if (err < 0) 37 if (err < 0)
45 goto st_magn_buffer_postenable_error; 38 return err;
39
40 err = st_sensors_set_enable(indio_dev, true);
41 if (err < 0)
42 goto st_magn_buffer_predisable;
46 43
47 return st_sensors_set_enable(indio_dev, true); 44 return 0;
48 45
49st_magn_buffer_postenable_error: 46st_magn_buffer_predisable:
50 kfree(mdata->buffer_data); 47 iio_triggered_buffer_predisable(indio_dev);
51allocate_memory_error:
52 return err; 48 return err;
53} 49}
54 50
55static int st_magn_buffer_predisable(struct iio_dev *indio_dev) 51static int st_magn_buffer_predisable(struct iio_dev *indio_dev)
56{ 52{
57 int err; 53 int err, err2;
58 struct st_sensor_data *mdata = iio_priv(indio_dev);
59 54
60 err = st_sensors_set_enable(indio_dev, false); 55 err = st_sensors_set_enable(indio_dev, false);
61 if (err < 0)
62 goto st_magn_buffer_predisable_error;
63 56
64 err = iio_triggered_buffer_predisable(indio_dev); 57 err2 = iio_triggered_buffer_predisable(indio_dev);
58 if (!err)
59 err = err2;
65 60
66st_magn_buffer_predisable_error:
67 kfree(mdata->buffer_data);
68 return err; 61 return err;
69} 62}
70 63
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index 2f7a1dbcdeb3..a3a268ee2896 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -12,7 +12,6 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/errno.h> 13#include <linux/errno.h>
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/mutex.h>
16#include <linux/interrupt.h> 15#include <linux/interrupt.h>
17#include <linux/i2c.h> 16#include <linux/i2c.h>
18#include <linux/gpio.h> 17#include <linux/gpio.h>
@@ -470,28 +469,41 @@ static const struct iio_trigger_ops st_magn_trigger_ops = {
470#define ST_MAGN_TRIGGER_OPS NULL 469#define ST_MAGN_TRIGGER_OPS NULL
471#endif 470#endif
472 471
472/*
473 * st_magn_get_settings() - get sensor settings from device name
474 * @name: device name buffer reference.
475 *
476 * Return: valid reference on success, NULL otherwise.
477 */
478const struct st_sensor_settings *st_magn_get_settings(const char *name)
479{
480 int index = st_sensors_get_settings_index(name,
481 st_magn_sensors_settings,
482 ARRAY_SIZE(st_magn_sensors_settings));
483 if (index < 0)
484 return NULL;
485
486 return &st_magn_sensors_settings[index];
487}
488EXPORT_SYMBOL(st_magn_get_settings);
489
473int st_magn_common_probe(struct iio_dev *indio_dev) 490int st_magn_common_probe(struct iio_dev *indio_dev)
474{ 491{
475 struct st_sensor_data *mdata = iio_priv(indio_dev); 492 struct st_sensor_data *mdata = iio_priv(indio_dev);
476 int irq = mdata->get_irq_data_ready(indio_dev);
477 int err; 493 int err;
478 494
479 indio_dev->modes = INDIO_DIRECT_MODE; 495 indio_dev->modes = INDIO_DIRECT_MODE;
480 indio_dev->info = &magn_info; 496 indio_dev->info = &magn_info;
481 mutex_init(&mdata->tb.buf_lock);
482 497
483 err = st_sensors_power_enable(indio_dev); 498 err = st_sensors_power_enable(indio_dev);
484 if (err) 499 if (err)
485 return err; 500 return err;
486 501
487 err = st_sensors_check_device_support(indio_dev, 502 err = st_sensors_verify_id(indio_dev);
488 ARRAY_SIZE(st_magn_sensors_settings),
489 st_magn_sensors_settings);
490 if (err < 0) 503 if (err < 0)
491 goto st_magn_power_off; 504 goto st_magn_power_off;
492 505
493 mdata->num_data_channels = ST_MAGN_NUMBER_DATA_CHANNELS; 506 mdata->num_data_channels = ST_MAGN_NUMBER_DATA_CHANNELS;
494 mdata->multiread_bit = mdata->sensor_settings->multi_read_bit;
495 indio_dev->channels = mdata->sensor_settings->ch; 507 indio_dev->channels = mdata->sensor_settings->ch;
496 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; 508 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
497 509
@@ -507,7 +519,7 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
507 if (err < 0) 519 if (err < 0)
508 goto st_magn_power_off; 520 goto st_magn_power_off;
509 521
510 if (irq > 0) { 522 if (mdata->irq > 0) {
511 err = st_sensors_allocate_trigger(indio_dev, 523 err = st_sensors_allocate_trigger(indio_dev,
512 ST_MAGN_TRIGGER_OPS); 524 ST_MAGN_TRIGGER_OPS);
513 if (err < 0) 525 if (err < 0)
@@ -524,7 +536,7 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
524 return 0; 536 return 0;
525 537
526st_magn_device_register_error: 538st_magn_device_register_error:
527 if (irq > 0) 539 if (mdata->irq > 0)
528 st_sensors_deallocate_trigger(indio_dev); 540 st_sensors_deallocate_trigger(indio_dev);
529st_magn_probe_trigger_error: 541st_magn_probe_trigger_error:
530 st_magn_deallocate_ring(indio_dev); 542 st_magn_deallocate_ring(indio_dev);
@@ -542,7 +554,7 @@ void st_magn_common_remove(struct iio_dev *indio_dev)
542 st_sensors_power_disable(indio_dev); 554 st_sensors_power_disable(indio_dev);
543 555
544 iio_device_unregister(indio_dev); 556 iio_device_unregister(indio_dev);
545 if (mdata->get_irq_data_ready(indio_dev) > 0) 557 if (mdata->irq > 0)
546 st_sensors_deallocate_trigger(indio_dev); 558 st_sensors_deallocate_trigger(indio_dev);
547 559
548 st_magn_deallocate_ring(indio_dev); 560 st_magn_deallocate_ring(indio_dev);
diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c
index 4d014fd1aeb0..fdba480a12be 100644
--- a/drivers/iio/magnetometer/st_magn_i2c.c
+++ b/drivers/iio/magnetometer/st_magn_i2c.c
@@ -55,21 +55,33 @@ MODULE_DEVICE_TABLE(of, st_magn_of_match);
55#endif 55#endif
56 56
57static int st_magn_i2c_probe(struct i2c_client *client, 57static int st_magn_i2c_probe(struct i2c_client *client,
58 const struct i2c_device_id *id) 58 const struct i2c_device_id *id)
59{ 59{
60 struct iio_dev *indio_dev; 60 const struct st_sensor_settings *settings;
61 struct st_sensor_data *mdata; 61 struct st_sensor_data *mdata;
62 struct iio_dev *indio_dev;
62 int err; 63 int err;
63 64
65 st_sensors_of_name_probe(&client->dev, st_magn_of_match,
66 client->name, sizeof(client->name));
67
68 settings = st_magn_get_settings(client->name);
69 if (!settings) {
70 dev_err(&client->dev, "device name %s not recognized.\n",
71 client->name);
72 return -ENODEV;
73 }
74
64 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*mdata)); 75 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*mdata));
65 if (!indio_dev) 76 if (!indio_dev)
66 return -ENOMEM; 77 return -ENOMEM;
67 78
68 mdata = iio_priv(indio_dev); 79 mdata = iio_priv(indio_dev);
69 st_sensors_of_name_probe(&client->dev, st_magn_of_match, 80 mdata->sensor_settings = (struct st_sensor_settings *)settings;
70 client->name, sizeof(client->name));
71 81
72 st_sensors_i2c_configure(indio_dev, client, mdata); 82 err = st_sensors_i2c_configure(indio_dev, client);
83 if (err < 0)
84 return err;
73 85
74 err = st_magn_common_probe(indio_dev); 86 err = st_magn_common_probe(indio_dev);
75 if (err < 0) 87 if (err < 0)
diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c
index 0d47070611b1..fbf909bde841 100644
--- a/drivers/iio/magnetometer/st_magn_spi.c
+++ b/drivers/iio/magnetometer/st_magn_spi.c
@@ -51,19 +51,31 @@ MODULE_DEVICE_TABLE(of, st_magn_of_match);
51 51
52static int st_magn_spi_probe(struct spi_device *spi) 52static int st_magn_spi_probe(struct spi_device *spi)
53{ 53{
54 struct iio_dev *indio_dev; 54 const struct st_sensor_settings *settings;
55 struct st_sensor_data *mdata; 55 struct st_sensor_data *mdata;
56 struct iio_dev *indio_dev;
56 int err; 57 int err;
57 58
59 st_sensors_of_name_probe(&spi->dev, st_magn_of_match,
60 spi->modalias, sizeof(spi->modalias));
61
62 settings = st_magn_get_settings(spi->modalias);
63 if (!settings) {
64 dev_err(&spi->dev, "device name %s not recognized.\n",
65 spi->modalias);
66 return -ENODEV;
67 }
68
58 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*mdata)); 69 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*mdata));
59 if (!indio_dev) 70 if (!indio_dev)
60 return -ENOMEM; 71 return -ENOMEM;
61 72
62 mdata = iio_priv(indio_dev); 73 mdata = iio_priv(indio_dev);
74 mdata->sensor_settings = (struct st_sensor_settings *)settings;
63 75
64 st_sensors_of_name_probe(&spi->dev, st_magn_of_match, 76 err = st_sensors_spi_configure(indio_dev, spi);
65 spi->modalias, sizeof(spi->modalias)); 77 if (err < 0)
66 st_sensors_spi_configure(indio_dev, spi, mdata); 78 return err;
67 79
68 err = st_magn_common_probe(indio_dev); 80 err = st_magn_common_probe(indio_dev);
69 if (err < 0) 81 if (err < 0)
diff --git a/drivers/iio/potentiometer/Kconfig b/drivers/iio/potentiometer/Kconfig
index ebc7c72a5e36..4cac0173db8b 100644
--- a/drivers/iio/potentiometer/Kconfig
+++ b/drivers/iio/potentiometer/Kconfig
@@ -26,6 +26,17 @@ config DS1803
26 To compile this driver as a module, choose M here: the 26 To compile this driver as a module, choose M here: the
27 module will be called ds1803. 27 module will be called ds1803.
28 28
29config MAX5432
30 tristate "Maxim MAX5432-MAX5435 Digital Potentiometer driver"
31 depends on I2C
32 help
33 Say yes here to build support for the Maxim
34 MAX5432, MAX5433, MAX5434 and MAX5435 digital
35 potentiometer chips.
36
37 To compile this driver as a module, choose M here: the
38 module will be called max5432.
39
29config MAX5481 40config MAX5481
30 tristate "Maxim MAX5481-MAX5484 Digital Potentiometer driver" 41 tristate "Maxim MAX5481-MAX5484 Digital Potentiometer driver"
31 depends on SPI 42 depends on SPI
diff --git a/drivers/iio/potentiometer/Makefile b/drivers/iio/potentiometer/Makefile
index 8ff55138cf12..091adf3cdd0b 100644
--- a/drivers/iio/potentiometer/Makefile
+++ b/drivers/iio/potentiometer/Makefile
@@ -6,6 +6,7 @@
6# When adding new entries keep the list in alphabetical order 6# When adding new entries keep the list in alphabetical order
7obj-$(CONFIG_AD5272) += ad5272.o 7obj-$(CONFIG_AD5272) += ad5272.o
8obj-$(CONFIG_DS1803) += ds1803.o 8obj-$(CONFIG_DS1803) += ds1803.o
9obj-$(CONFIG_MAX5432) += max5432.o
9obj-$(CONFIG_MAX5481) += max5481.o 10obj-$(CONFIG_MAX5481) += max5481.o
10obj-$(CONFIG_MAX5487) += max5487.o 11obj-$(CONFIG_MAX5487) += max5487.o
11obj-$(CONFIG_MCP4018) += mcp4018.o 12obj-$(CONFIG_MCP4018) += mcp4018.o
diff --git a/drivers/iio/potentiometer/max5432.c b/drivers/iio/potentiometer/max5432.c
new file mode 100644
index 000000000000..641b1821fdf6
--- /dev/null
+++ b/drivers/iio/potentiometer/max5432.c
@@ -0,0 +1,135 @@
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Maxim Integrated MAX5432-MAX5435 digital potentiometer driver
4 * Copyright (C) 2019 Martin Kaiser <martin@kaiser.cx>
5 *
6 * Datasheet:
7 * https://datasheets.maximintegrated.com/en/ds/MAX5432-MAX5435.pdf
8 */
9
10#include <linux/i2c.h>
11#include <linux/iio/iio.h>
12#include <linux/limits.h>
13#include <linux/module.h>
14#include <linux/of.h>
15#include <linux/of_device.h>
16
17/* All chip variants have 32 wiper positions. */
18#define MAX5432_MAX_POS 31
19
20#define MAX5432_OHM_50K (50 * 1000)
21#define MAX5432_OHM_100K (100 * 1000)
22
23/* Update the volatile (currently active) setting. */
24#define MAX5432_CMD_VREG 0x11
25
26struct max5432_data {
27 struct i2c_client *client;
28 unsigned long ohm;
29};
30
31static const struct iio_chan_spec max5432_channels[] = {
32 {
33 .type = IIO_RESISTANCE,
34 .indexed = 1,
35 .output = 1,
36 .channel = 0,
37 .address = MAX5432_CMD_VREG,
38 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
39 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
40 }
41};
42
43static int max5432_read_raw(struct iio_dev *indio_dev,
44 struct iio_chan_spec const *chan,
45 int *val, int *val2, long mask)
46{
47 struct max5432_data *data = iio_priv(indio_dev);
48
49 if (mask != IIO_CHAN_INFO_SCALE)
50 return -EINVAL;
51
52 if (unlikely(data->ohm > INT_MAX))
53 return -ERANGE;
54
55 *val = data->ohm;
56 *val2 = MAX5432_MAX_POS;
57
58 return IIO_VAL_FRACTIONAL;
59}
60
61static int max5432_write_raw(struct iio_dev *indio_dev,
62 struct iio_chan_spec const *chan,
63 int val, int val2, long mask)
64{
65 struct max5432_data *data = iio_priv(indio_dev);
66 u8 data_byte;
67
68 if (mask != IIO_CHAN_INFO_RAW)
69 return -EINVAL;
70
71 if (val < 0 || val > MAX5432_MAX_POS)
72 return -EINVAL;
73
74 if (val2 != 0)
75 return -EINVAL;
76
77 /* Wiper position is in bits D7-D3. (D2-D0 are don't care bits.) */
78 data_byte = val << 3;
79 return i2c_smbus_write_byte_data(data->client, chan->address,
80 data_byte);
81}
82
83static const struct iio_info max5432_info = {
84 .read_raw = max5432_read_raw,
85 .write_raw = max5432_write_raw,
86};
87
88static int max5432_probe(struct i2c_client *client,
89 const struct i2c_device_id *id)
90{
91 struct device *dev = &client->dev;
92 struct iio_dev *indio_dev;
93 struct max5432_data *data;
94
95 indio_dev = devm_iio_device_alloc(dev, sizeof(struct max5432_data));
96 if (!indio_dev)
97 return -ENOMEM;
98
99 i2c_set_clientdata(client, indio_dev);
100
101 data = iio_priv(indio_dev);
102 data->client = client;
103 data->ohm = (unsigned long)of_device_get_match_data(dev);
104
105 indio_dev->dev.parent = dev;
106 indio_dev->info = &max5432_info;
107 indio_dev->channels = max5432_channels;
108 indio_dev->num_channels = ARRAY_SIZE(max5432_channels);
109 indio_dev->name = client->name;
110
111 return devm_iio_device_register(dev, indio_dev);
112}
113
114static const struct of_device_id max5432_dt_ids[] = {
115 { .compatible = "maxim,max5432", .data = (void *)MAX5432_OHM_50K },
116 { .compatible = "maxim,max5433", .data = (void *)MAX5432_OHM_100K },
117 { .compatible = "maxim,max5434", .data = (void *)MAX5432_OHM_50K },
118 { .compatible = "maxim,max5435", .data = (void *)MAX5432_OHM_100K },
119 { /* sentinel */ }
120};
121MODULE_DEVICE_TABLE(of, max5432_dt_ids);
122
123static struct i2c_driver max5432_driver = {
124 .driver = {
125 .name = "max5432",
126 .of_match_table = of_match_ptr(max5432_dt_ids),
127 },
128 .probe = max5432_probe,
129};
130
131module_i2c_driver(max5432_driver);
132
133MODULE_AUTHOR("Martin Kaiser <martin@kaiser.cx>");
134MODULE_DESCRIPTION("max5432-max5435 digital potentiometers");
135MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/pressure/cros_ec_baro.c b/drivers/iio/pressure/cros_ec_baro.c
index 034ce98d6e97..70148624db64 100644
--- a/drivers/iio/pressure/cros_ec_baro.c
+++ b/drivers/iio/pressure/cros_ec_baro.c
@@ -39,26 +39,29 @@ static int cros_ec_baro_read(struct iio_dev *indio_dev,
39{ 39{
40 struct cros_ec_baro_state *st = iio_priv(indio_dev); 40 struct cros_ec_baro_state *st = iio_priv(indio_dev);
41 u16 data = 0; 41 u16 data = 0;
42 int ret = IIO_VAL_INT; 42 int ret;
43 int idx = chan->scan_index; 43 int idx = chan->scan_index;
44 44
45 mutex_lock(&st->core.cmd_lock); 45 mutex_lock(&st->core.cmd_lock);
46 46
47 switch (mask) { 47 switch (mask) {
48 case IIO_CHAN_INFO_RAW: 48 case IIO_CHAN_INFO_RAW:
49 if (cros_ec_sensors_read_cmd(indio_dev, 1 << idx, 49 ret = cros_ec_sensors_read_cmd(indio_dev, 1 << idx,
50 (s16 *)&data) < 0) 50 (s16 *)&data);
51 ret = -EIO; 51 if (ret)
52 break;
53
52 *val = data; 54 *val = data;
55 ret = IIO_VAL_INT;
53 break; 56 break;
54 case IIO_CHAN_INFO_SCALE: 57 case IIO_CHAN_INFO_SCALE:
55 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE; 58 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE;
56 st->core.param.sensor_range.data = EC_MOTION_SENSE_NO_VALUE; 59 st->core.param.sensor_range.data = EC_MOTION_SENSE_NO_VALUE;
57 60
58 if (cros_ec_motion_send_host_cmd(&st->core, 0)) { 61 ret = cros_ec_motion_send_host_cmd(&st->core, 0);
59 ret = -EIO; 62 if (ret)
60 break; 63 break;
61 } 64
62 *val = st->core.resp->sensor_range.ret; 65 *val = st->core.resp->sensor_range.ret;
63 66
64 /* scale * in_pressure_raw --> kPa */ 67 /* scale * in_pressure_raw --> kPa */
@@ -152,8 +155,6 @@ static int cros_ec_baro_probe(struct platform_device *pdev)
152 channel->ext_info = cros_ec_sensors_ext_info; 155 channel->ext_info = cros_ec_sensors_ext_info;
153 channel->scan_type.sign = 'u'; 156 channel->scan_type.sign = 'u';
154 157
155 state->core.calib[0] = 0;
156
157 /* Sensor specific */ 158 /* Sensor specific */
158 switch (state->core.type) { 159 switch (state->core.type) {
159 case MOTIONSENSE_TYPE_BARO: 160 case MOTIONSENSE_TYPE_BARO:
diff --git a/drivers/iio/pressure/hp03.c b/drivers/iio/pressure/hp03.c
index f00102577fd5..026ba15ef68f 100644
--- a/drivers/iio/pressure/hp03.c
+++ b/drivers/iio/pressure/hp03.c
@@ -243,10 +243,10 @@ static int hp03_probe(struct i2c_client *client,
243 * which has it's dedicated I2C address and contains 243 * which has it's dedicated I2C address and contains
244 * the calibration constants for the sensor. 244 * the calibration constants for the sensor.
245 */ 245 */
246 priv->eeprom_client = i2c_new_dummy(client->adapter, HP03_EEPROM_ADDR); 246 priv->eeprom_client = i2c_new_dummy_device(client->adapter, HP03_EEPROM_ADDR);
247 if (!priv->eeprom_client) { 247 if (IS_ERR(priv->eeprom_client)) {
248 dev_err(dev, "New EEPROM I2C device failed\n"); 248 dev_err(dev, "New EEPROM I2C device failed\n");
249 return -ENODEV; 249 return PTR_ERR(priv->eeprom_client);
250 } 250 }
251 251
252 priv->eeprom_regmap = regmap_init_i2c(priv->eeprom_client, 252 priv->eeprom_regmap = regmap_init_i2c(priv->eeprom_client,
diff --git a/drivers/iio/pressure/st_pressure.h b/drivers/iio/pressure/st_pressure.h
index 6a720cfb5686..c2e47a6c3118 100644
--- a/drivers/iio/pressure/st_pressure.h
+++ b/drivers/iio/pressure/st_pressure.h
@@ -41,6 +41,7 @@ static const struct st_sensors_platform_data default_press_pdata = {
41 .drdy_int_pin = 1, 41 .drdy_int_pin = 1,
42}; 42};
43 43
44const struct st_sensor_settings *st_press_get_settings(const char *name);
44int st_press_common_probe(struct iio_dev *indio_dev); 45int st_press_common_probe(struct iio_dev *indio_dev);
45void st_press_common_remove(struct iio_dev *indio_dev); 46void st_press_common_remove(struct iio_dev *indio_dev);
46 47
diff --git a/drivers/iio/pressure/st_pressure_buffer.c b/drivers/iio/pressure/st_pressure_buffer.c
index 4566e08a64a1..418dbf9e6e1e 100644
--- a/drivers/iio/pressure/st_pressure_buffer.c
+++ b/drivers/iio/pressure/st_pressure_buffer.c
@@ -29,52 +29,39 @@ int st_press_trig_set_state(struct iio_trigger *trig, bool state)
29 return st_sensors_set_dataready_irq(indio_dev, state); 29 return st_sensors_set_dataready_irq(indio_dev, state);
30} 30}
31 31
32static int st_press_buffer_preenable(struct iio_dev *indio_dev)
33{
34 return st_sensors_set_enable(indio_dev, true);
35}
36
37static int st_press_buffer_postenable(struct iio_dev *indio_dev) 32static int st_press_buffer_postenable(struct iio_dev *indio_dev)
38{ 33{
39 int err; 34 int err;
40 struct st_sensor_data *press_data = iio_priv(indio_dev);
41
42 press_data->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
43 if (press_data->buffer_data == NULL) {
44 err = -ENOMEM;
45 goto allocate_memory_error;
46 }
47 35
48 err = iio_triggered_buffer_postenable(indio_dev); 36 err = iio_triggered_buffer_postenable(indio_dev);
49 if (err < 0) 37 if (err < 0)
50 goto st_press_buffer_postenable_error; 38 return err;
51 39
52 return err; 40 err = st_sensors_set_enable(indio_dev, true);
41 if (err < 0)
42 goto st_press_buffer_predisable;
53 43
54st_press_buffer_postenable_error: 44 return 0;
55 kfree(press_data->buffer_data); 45
56allocate_memory_error: 46st_press_buffer_predisable:
47 iio_triggered_buffer_predisable(indio_dev);
57 return err; 48 return err;
58} 49}
59 50
60static int st_press_buffer_predisable(struct iio_dev *indio_dev) 51static int st_press_buffer_predisable(struct iio_dev *indio_dev)
61{ 52{
62 int err; 53 int err, err2;
63 struct st_sensor_data *press_data = iio_priv(indio_dev);
64
65 err = iio_triggered_buffer_predisable(indio_dev);
66 if (err < 0)
67 goto st_press_buffer_predisable_error;
68 54
69 err = st_sensors_set_enable(indio_dev, false); 55 err = st_sensors_set_enable(indio_dev, false);
70 56
71st_press_buffer_predisable_error: 57 err2 = iio_triggered_buffer_predisable(indio_dev);
72 kfree(press_data->buffer_data); 58 if (!err)
59 err = err2;
60
73 return err; 61 return err;
74} 62}
75 63
76static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = { 64static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = {
77 .preenable = &st_press_buffer_preenable,
78 .postenable = &st_press_buffer_postenable, 65 .postenable = &st_press_buffer_postenable,
79 .predisable = &st_press_buffer_predisable, 66 .predisable = &st_press_buffer_predisable,
80}; 67};
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index b960e76f7dfd..ca6863b32a5f 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -12,7 +12,6 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/errno.h> 13#include <linux/errno.h>
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/mutex.h>
16#include <linux/interrupt.h> 15#include <linux/interrupt.h>
17#include <linux/i2c.h> 16#include <linux/i2c.h>
18#include <linux/gpio.h> 17#include <linux/gpio.h>
@@ -664,25 +663,39 @@ static const struct iio_trigger_ops st_press_trigger_ops = {
664#define ST_PRESS_TRIGGER_OPS NULL 663#define ST_PRESS_TRIGGER_OPS NULL
665#endif 664#endif
666 665
666/*
667 * st_press_get_settings() - get sensor settings from device name
668 * @name: device name buffer reference.
669 *
670 * Return: valid reference on success, NULL otherwise.
671 */
672const struct st_sensor_settings *st_press_get_settings(const char *name)
673{
674 int index = st_sensors_get_settings_index(name,
675 st_press_sensors_settings,
676 ARRAY_SIZE(st_press_sensors_settings));
677 if (index < 0)
678 return NULL;
679
680 return &st_press_sensors_settings[index];
681}
682EXPORT_SYMBOL(st_press_get_settings);
683
667int st_press_common_probe(struct iio_dev *indio_dev) 684int st_press_common_probe(struct iio_dev *indio_dev)
668{ 685{
669 struct st_sensor_data *press_data = iio_priv(indio_dev); 686 struct st_sensor_data *press_data = iio_priv(indio_dev);
670 struct st_sensors_platform_data *pdata = 687 struct st_sensors_platform_data *pdata =
671 (struct st_sensors_platform_data *)press_data->dev->platform_data; 688 (struct st_sensors_platform_data *)press_data->dev->platform_data;
672 int irq = press_data->get_irq_data_ready(indio_dev);
673 int err; 689 int err;
674 690
675 indio_dev->modes = INDIO_DIRECT_MODE; 691 indio_dev->modes = INDIO_DIRECT_MODE;
676 indio_dev->info = &press_info; 692 indio_dev->info = &press_info;
677 mutex_init(&press_data->tb.buf_lock);
678 693
679 err = st_sensors_power_enable(indio_dev); 694 err = st_sensors_power_enable(indio_dev);
680 if (err) 695 if (err)
681 return err; 696 return err;
682 697
683 err = st_sensors_check_device_support(indio_dev, 698 err = st_sensors_verify_id(indio_dev);
684 ARRAY_SIZE(st_press_sensors_settings),
685 st_press_sensors_settings);
686 if (err < 0) 699 if (err < 0)
687 goto st_press_power_off; 700 goto st_press_power_off;
688 701
@@ -693,7 +706,6 @@ int st_press_common_probe(struct iio_dev *indio_dev)
693 * element. 706 * element.
694 */ 707 */
695 press_data->num_data_channels = press_data->sensor_settings->num_ch - 1; 708 press_data->num_data_channels = press_data->sensor_settings->num_ch - 1;
696 press_data->multiread_bit = press_data->sensor_settings->multi_read_bit;
697 indio_dev->channels = press_data->sensor_settings->ch; 709 indio_dev->channels = press_data->sensor_settings->ch;
698 indio_dev->num_channels = press_data->sensor_settings->num_ch; 710 indio_dev->num_channels = press_data->sensor_settings->num_ch;
699 711
@@ -716,7 +728,7 @@ int st_press_common_probe(struct iio_dev *indio_dev)
716 if (err < 0) 728 if (err < 0)
717 goto st_press_power_off; 729 goto st_press_power_off;
718 730
719 if (irq > 0) { 731 if (press_data->irq > 0) {
720 err = st_sensors_allocate_trigger(indio_dev, 732 err = st_sensors_allocate_trigger(indio_dev,
721 ST_PRESS_TRIGGER_OPS); 733 ST_PRESS_TRIGGER_OPS);
722 if (err < 0) 734 if (err < 0)
@@ -733,7 +745,7 @@ int st_press_common_probe(struct iio_dev *indio_dev)
733 return err; 745 return err;
734 746
735st_press_device_register_error: 747st_press_device_register_error:
736 if (irq > 0) 748 if (press_data->irq > 0)
737 st_sensors_deallocate_trigger(indio_dev); 749 st_sensors_deallocate_trigger(indio_dev);
738st_press_probe_trigger_error: 750st_press_probe_trigger_error:
739 st_press_deallocate_ring(indio_dev); 751 st_press_deallocate_ring(indio_dev);
@@ -751,7 +763,7 @@ void st_press_common_remove(struct iio_dev *indio_dev)
751 st_sensors_power_disable(indio_dev); 763 st_sensors_power_disable(indio_dev);
752 764
753 iio_device_unregister(indio_dev); 765 iio_device_unregister(indio_dev);
754 if (press_data->get_irq_data_ready(indio_dev) > 0) 766 if (press_data->irq > 0)
755 st_sensors_deallocate_trigger(indio_dev); 767 st_sensors_deallocate_trigger(indio_dev);
756 768
757 st_press_deallocate_ring(indio_dev); 769 st_press_deallocate_ring(indio_dev);
diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c
index b7d9ba706abc..71d2ed6b4948 100644
--- a/drivers/iio/pressure/st_pressure_i2c.c
+++ b/drivers/iio/pressure/st_pressure_i2c.c
@@ -78,18 +78,13 @@ static const struct i2c_device_id st_press_id_table[] = {
78MODULE_DEVICE_TABLE(i2c, st_press_id_table); 78MODULE_DEVICE_TABLE(i2c, st_press_id_table);
79 79
80static int st_press_i2c_probe(struct i2c_client *client, 80static int st_press_i2c_probe(struct i2c_client *client,
81 const struct i2c_device_id *id) 81 const struct i2c_device_id *id)
82{ 82{
83 struct iio_dev *indio_dev; 83 const struct st_sensor_settings *settings;
84 struct st_sensor_data *press_data; 84 struct st_sensor_data *press_data;
85 struct iio_dev *indio_dev;
85 int ret; 86 int ret;
86 87
87 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
88 if (!indio_dev)
89 return -ENOMEM;
90
91 press_data = iio_priv(indio_dev);
92
93 if (client->dev.of_node) { 88 if (client->dev.of_node) {
94 st_sensors_of_name_probe(&client->dev, st_press_of_match, 89 st_sensors_of_name_probe(&client->dev, st_press_of_match,
95 client->name, sizeof(client->name)); 90 client->name, sizeof(client->name));
@@ -99,11 +94,27 @@ static int st_press_i2c_probe(struct i2c_client *client,
99 return -ENODEV; 94 return -ENODEV;
100 95
101 strlcpy(client->name, st_press_id_table[ret].name, 96 strlcpy(client->name, st_press_id_table[ret].name,
102 sizeof(client->name)); 97 sizeof(client->name));
103 } else if (!id) 98 } else if (!id)
104 return -ENODEV; 99 return -ENODEV;
105 100
106 st_sensors_i2c_configure(indio_dev, client, press_data); 101 settings = st_press_get_settings(client->name);
102 if (!settings) {
103 dev_err(&client->dev, "device name %s not recognized.\n",
104 client->name);
105 return -ENODEV;
106 }
107
108 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
109 if (!indio_dev)
110 return -ENOMEM;
111
112 press_data = iio_priv(indio_dev);
113 press_data->sensor_settings = (struct st_sensor_settings *)settings;
114
115 ret = st_sensors_i2c_configure(indio_dev, client);
116 if (ret < 0)
117 return ret;
107 118
108 ret = st_press_common_probe(indio_dev); 119 ret = st_press_common_probe(indio_dev);
109 if (ret < 0) 120 if (ret < 0)
diff --git a/drivers/iio/pressure/st_pressure_spi.c b/drivers/iio/pressure/st_pressure_spi.c
index ef61401c41d3..7c8b70221e70 100644
--- a/drivers/iio/pressure/st_pressure_spi.c
+++ b/drivers/iio/pressure/st_pressure_spi.c
@@ -61,19 +61,31 @@ MODULE_DEVICE_TABLE(of, st_press_of_match);
61 61
62static int st_press_spi_probe(struct spi_device *spi) 62static int st_press_spi_probe(struct spi_device *spi)
63{ 63{
64 struct iio_dev *indio_dev; 64 const struct st_sensor_settings *settings;
65 struct st_sensor_data *press_data; 65 struct st_sensor_data *press_data;
66 struct iio_dev *indio_dev;
66 int err; 67 int err;
67 68
69 st_sensors_of_name_probe(&spi->dev, st_press_of_match,
70 spi->modalias, sizeof(spi->modalias));
71
72 settings = st_press_get_settings(spi->modalias);
73 if (!settings) {
74 dev_err(&spi->dev, "device name %s not recognized.\n",
75 spi->modalias);
76 return -ENODEV;
77 }
78
68 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*press_data)); 79 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*press_data));
69 if (indio_dev == NULL) 80 if (!indio_dev)
70 return -ENOMEM; 81 return -ENOMEM;
71 82
72 press_data = iio_priv(indio_dev); 83 press_data = iio_priv(indio_dev);
84 press_data->sensor_settings = (struct st_sensor_settings *)settings;
73 85
74 st_sensors_of_name_probe(&spi->dev, st_press_of_match, 86 err = st_sensors_spi_configure(indio_dev, spi);
75 spi->modalias, sizeof(spi->modalias)); 87 if (err < 0)
76 st_sensors_spi_configure(indio_dev, spi, press_data); 88 return err;
77 89
78 err = st_press_common_probe(indio_dev); 90 err = st_press_common_probe(indio_dev);
79 if (err < 0) 91 if (err < 0)
diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig
index 6b5cce6f1a7b..d53601447da4 100644
--- a/drivers/iio/proximity/Kconfig
+++ b/drivers/iio/proximity/Kconfig
@@ -62,7 +62,7 @@ config RFD77402
62 tristate "RFD77402 ToF sensor" 62 tristate "RFD77402 ToF sensor"
63 depends on I2C 63 depends on I2C
64 help 64 help
65 Say Y to build a driver for the RFD77420 Time-of-Flight (distance) 65 Say Y to build a driver for the RFD77402 Time-of-Flight (distance)
66 sensor module with I2C interface. 66 sensor module with I2C interface.
67 67
68 To compile this driver as a module, choose M here: the 68 To compile this driver as a module, choose M here: the
diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
index c613a64c017f..2ab68282d0b6 100644
--- a/drivers/iio/temperature/maxim_thermocouple.c
+++ b/drivers/iio/temperature/maxim_thermocouple.c
@@ -230,31 +230,13 @@ static int maxim_thermocouple_probe(struct spi_device *spi)
230 data->spi = spi; 230 data->spi = spi;
231 data->chip = chip; 231 data->chip = chip;
232 232
233 ret = iio_triggered_buffer_setup(indio_dev, NULL, 233 ret = devm_iio_triggered_buffer_setup(&spi->dev,
234 indio_dev, NULL,
234 maxim_thermocouple_trigger_handler, NULL); 235 maxim_thermocouple_trigger_handler, NULL);
235 if (ret) 236 if (ret)
236 return ret; 237 return ret;
237 238
238 ret = iio_device_register(indio_dev); 239 return devm_iio_device_register(&spi->dev, indio_dev);
239 if (ret)
240 goto error_unreg_buffer;
241
242 return 0;
243
244error_unreg_buffer:
245 iio_triggered_buffer_cleanup(indio_dev);
246
247 return ret;
248}
249
250static int maxim_thermocouple_remove(struct spi_device *spi)
251{
252 struct iio_dev *indio_dev = spi_get_drvdata(spi);
253
254 iio_device_unregister(indio_dev);
255 iio_triggered_buffer_cleanup(indio_dev);
256
257 return 0;
258} 240}
259 241
260static const struct spi_device_id maxim_thermocouple_id[] = { 242static const struct spi_device_id maxim_thermocouple_id[] = {
@@ -277,7 +259,6 @@ static struct spi_driver maxim_thermocouple_driver = {
277 .of_match_table = maxim_thermocouple_of_match, 259 .of_match_table = maxim_thermocouple_of_match,
278 }, 260 },
279 .probe = maxim_thermocouple_probe, 261 .probe = maxim_thermocouple_probe,
280 .remove = maxim_thermocouple_remove,
281 .id_table = maxim_thermocouple_id, 262 .id_table = maxim_thermocouple_id,
282}; 263};
283module_spi_driver(maxim_thermocouple_driver); 264module_spi_driver(maxim_thermocouple_driver);
diff --git a/drivers/iio/trigger/stm32-timer-trigger.c b/drivers/iio/trigger/stm32-timer-trigger.c
index ccf1ce653b25..a5dfe65cd9b9 100644
--- a/drivers/iio/trigger/stm32-timer-trigger.c
+++ b/drivers/iio/trigger/stm32-timer-trigger.c
@@ -608,86 +608,6 @@ static const struct iio_enum stm32_enable_mode_enum = {
608 .get = stm32_get_enable_mode 608 .get = stm32_get_enable_mode
609}; 609};
610 610
611static const char *const stm32_quadrature_modes[] = {
612 "channel_A",
613 "channel_B",
614 "quadrature",
615};
616
617static int stm32_set_quadrature_mode(struct iio_dev *indio_dev,
618 const struct iio_chan_spec *chan,
619 unsigned int mode)
620{
621 struct stm32_timer_trigger *priv = iio_priv(indio_dev);
622
623 regmap_update_bits(priv->regmap, TIM_SMCR, TIM_SMCR_SMS, mode + 1);
624
625 return 0;
626}
627
628static int stm32_get_quadrature_mode(struct iio_dev *indio_dev,
629 const struct iio_chan_spec *chan)
630{
631 struct stm32_timer_trigger *priv = iio_priv(indio_dev);
632 u32 smcr;
633 int mode;
634
635 regmap_read(priv->regmap, TIM_SMCR, &smcr);
636 mode = (smcr & TIM_SMCR_SMS) - 1;
637 if ((mode < 0) || (mode > ARRAY_SIZE(stm32_quadrature_modes)))
638 return -EINVAL;
639
640 return mode;
641}
642
643static const struct iio_enum stm32_quadrature_mode_enum = {
644 .items = stm32_quadrature_modes,
645 .num_items = ARRAY_SIZE(stm32_quadrature_modes),
646 .set = stm32_set_quadrature_mode,
647 .get = stm32_get_quadrature_mode
648};
649
650static const char *const stm32_count_direction_states[] = {
651 "up",
652 "down"
653};
654
655static int stm32_set_count_direction(struct iio_dev *indio_dev,
656 const struct iio_chan_spec *chan,
657 unsigned int dir)
658{
659 struct stm32_timer_trigger *priv = iio_priv(indio_dev);
660 u32 val;
661 int mode;
662
663 /* In encoder mode, direction is RO (given by TI1/TI2 signals) */
664 regmap_read(priv->regmap, TIM_SMCR, &val);
665 mode = (val & TIM_SMCR_SMS) - 1;
666 if ((mode >= 0) || (mode < ARRAY_SIZE(stm32_quadrature_modes)))
667 return -EBUSY;
668
669 return regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_DIR,
670 dir ? TIM_CR1_DIR : 0);
671}
672
673static int stm32_get_count_direction(struct iio_dev *indio_dev,
674 const struct iio_chan_spec *chan)
675{
676 struct stm32_timer_trigger *priv = iio_priv(indio_dev);
677 u32 cr1;
678
679 regmap_read(priv->regmap, TIM_CR1, &cr1);
680
681 return ((cr1 & TIM_CR1_DIR) ? 1 : 0);
682}
683
684static const struct iio_enum stm32_count_direction_enum = {
685 .items = stm32_count_direction_states,
686 .num_items = ARRAY_SIZE(stm32_count_direction_states),
687 .set = stm32_set_count_direction,
688 .get = stm32_get_count_direction
689};
690
691static ssize_t stm32_count_get_preset(struct iio_dev *indio_dev, 611static ssize_t stm32_count_get_preset(struct iio_dev *indio_dev,
692 uintptr_t private, 612 uintptr_t private,
693 const struct iio_chan_spec *chan, 613 const struct iio_chan_spec *chan,
@@ -728,10 +648,6 @@ static const struct iio_chan_spec_ext_info stm32_trigger_count_info[] = {
728 .read = stm32_count_get_preset, 648 .read = stm32_count_get_preset,
729 .write = stm32_count_set_preset 649 .write = stm32_count_set_preset
730 }, 650 },
731 IIO_ENUM("count_direction", IIO_SEPARATE, &stm32_count_direction_enum),
732 IIO_ENUM_AVAILABLE("count_direction", &stm32_count_direction_enum),
733 IIO_ENUM("quadrature_mode", IIO_SEPARATE, &stm32_quadrature_mode_enum),
734 IIO_ENUM_AVAILABLE("quadrature_mode", &stm32_quadrature_mode_enum),
735 IIO_ENUM("enable_mode", IIO_SEPARATE, &stm32_enable_mode_enum), 651 IIO_ENUM("enable_mode", IIO_SEPARATE, &stm32_enable_mode_enum),
736 IIO_ENUM_AVAILABLE("enable_mode", &stm32_enable_mode_enum), 652 IIO_ENUM_AVAILABLE("enable_mode", &stm32_enable_mode_enum),
737 IIO_ENUM("trigger_mode", IIO_SEPARATE, &stm32_trigger_mode_enum), 653 IIO_ENUM("trigger_mode", IIO_SEPARATE, &stm32_trigger_mode_enum),
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index cf419d9c942d..b9c7f0dc653b 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -112,8 +112,6 @@ source "drivers/staging/gasket/Kconfig"
112 112
113source "drivers/staging/axis-fifo/Kconfig" 113source "drivers/staging/axis-fifo/Kconfig"
114 114
115source "drivers/staging/erofs/Kconfig"
116
117source "drivers/staging/fieldbus/Kconfig" 115source "drivers/staging/fieldbus/Kconfig"
118 116
119source "drivers/staging/kpc2000/Kconfig" 117source "drivers/staging/kpc2000/Kconfig"
@@ -123,4 +121,6 @@ source "drivers/staging/isdn/Kconfig"
123source "drivers/staging/wusbcore/Kconfig" 121source "drivers/staging/wusbcore/Kconfig"
124source "drivers/staging/uwb/Kconfig" 122source "drivers/staging/uwb/Kconfig"
125 123
124source "drivers/staging/exfat/Kconfig"
125
126endif # STAGING 126endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 38179bc842a8..4b5962006c4b 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -46,9 +46,9 @@ obj-$(CONFIG_DMA_RALINK) += ralink-gdma/
46obj-$(CONFIG_SOC_MT7621) += mt7621-dts/ 46obj-$(CONFIG_SOC_MT7621) += mt7621-dts/
47obj-$(CONFIG_STAGING_GASKET_FRAMEWORK) += gasket/ 47obj-$(CONFIG_STAGING_GASKET_FRAMEWORK) += gasket/
48obj-$(CONFIG_XIL_AXIS_FIFO) += axis-fifo/ 48obj-$(CONFIG_XIL_AXIS_FIFO) += axis-fifo/
49obj-$(CONFIG_EROFS_FS) += erofs/
50obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/ 49obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/
51obj-$(CONFIG_KPC2000) += kpc2000/ 50obj-$(CONFIG_KPC2000) += kpc2000/
52obj-$(CONFIG_ISDN_CAPI) += isdn/ 51obj-$(CONFIG_ISDN_CAPI) += isdn/
53obj-$(CONFIG_UWB) += uwb/ 52obj-$(CONFIG_UWB) += uwb/
54obj-$(CONFIG_USB_WUSB) += wusbcore/ 53obj-$(CONFIG_USB_WUSB) += wusbcore/
54obj-$(CONFIG_EXFAT_FS) += exfat/
diff --git a/drivers/staging/android/TODO b/drivers/staging/android/TODO
index fbf015cc6d62..767dd98fd92d 100644
--- a/drivers/staging/android/TODO
+++ b/drivers/staging/android/TODO
@@ -6,8 +6,6 @@ TODO:
6 6
7 7
8ion/ 8ion/
9 - Add dt-bindings for remaining heaps (chunk and carveout heaps). This would
10 involve putting appropriate bindings in a memory node for Ion to find.
11 - Split /dev/ion up into multiple nodes (e.g. /dev/ion/heap0) 9 - Split /dev/ion up into multiple nodes (e.g. /dev/ion/heap0)
12 - Better test framework (integration with VGEM was suggested) 10 - Better test framework (integration with VGEM was suggested)
13 11
diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
index 92c2914239e3..e6b1ca141b93 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -30,32 +30,6 @@ static struct ion_device *internal_dev;
30static int heap_id; 30static int heap_id;
31 31
32/* this function should only be called while dev->lock is held */ 32/* this function should only be called while dev->lock is held */
33static void ion_buffer_add(struct ion_device *dev,
34 struct ion_buffer *buffer)
35{
36 struct rb_node **p = &dev->buffers.rb_node;
37 struct rb_node *parent = NULL;
38 struct ion_buffer *entry;
39
40 while (*p) {
41 parent = *p;
42 entry = rb_entry(parent, struct ion_buffer, node);
43
44 if (buffer < entry) {
45 p = &(*p)->rb_left;
46 } else if (buffer > entry) {
47 p = &(*p)->rb_right;
48 } else {
49 pr_err("%s: buffer already found.", __func__);
50 BUG();
51 }
52 }
53
54 rb_link_node(&buffer->node, parent, p);
55 rb_insert_color(&buffer->node, &dev->buffers);
56}
57
58/* this function should only be called while dev->lock is held */
59static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, 33static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
60 struct ion_device *dev, 34 struct ion_device *dev,
61 unsigned long len, 35 unsigned long len,
@@ -100,9 +74,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
100 74
101 INIT_LIST_HEAD(&buffer->attachments); 75 INIT_LIST_HEAD(&buffer->attachments);
102 mutex_init(&buffer->lock); 76 mutex_init(&buffer->lock);
103 mutex_lock(&dev->buffer_lock);
104 ion_buffer_add(dev, buffer);
105 mutex_unlock(&dev->buffer_lock);
106 return buffer; 77 return buffer;
107 78
108err1: 79err1:
@@ -131,11 +102,6 @@ void ion_buffer_destroy(struct ion_buffer *buffer)
131static void _ion_buffer_destroy(struct ion_buffer *buffer) 102static void _ion_buffer_destroy(struct ion_buffer *buffer)
132{ 103{
133 struct ion_heap *heap = buffer->heap; 104 struct ion_heap *heap = buffer->heap;
134 struct ion_device *dev = buffer->dev;
135
136 mutex_lock(&dev->buffer_lock);
137 rb_erase(&buffer->node, &dev->buffers);
138 mutex_unlock(&dev->buffer_lock);
139 105
140 if (heap->flags & ION_HEAP_FLAG_DEFER_FREE) 106 if (heap->flags & ION_HEAP_FLAG_DEFER_FREE)
141 ion_heap_freelist_add(heap, buffer); 107 ion_heap_freelist_add(heap, buffer);
@@ -694,8 +660,6 @@ static int ion_device_create(void)
694 } 660 }
695 661
696 idev->debug_root = debugfs_create_dir("ion", NULL); 662 idev->debug_root = debugfs_create_dir("ion", NULL);
697 idev->buffers = RB_ROOT;
698 mutex_init(&idev->buffer_lock);
699 init_rwsem(&idev->lock); 663 init_rwsem(&idev->lock);
700 plist_head_init(&idev->heaps); 664 plist_head_init(&idev->heaps);
701 internal_dev = idev; 665 internal_dev = idev;
diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h
index e291299fd35f..74914a266e25 100644
--- a/drivers/staging/android/ion/ion.h
+++ b/drivers/staging/android/ion/ion.h
@@ -23,7 +23,6 @@
23 23
24/** 24/**
25 * struct ion_buffer - metadata for a particular buffer 25 * struct ion_buffer - metadata for a particular buffer
26 * @node: node in the ion_device buffers tree
27 * @list: element in list of deferred freeable buffers 26 * @list: element in list of deferred freeable buffers
28 * @dev: back pointer to the ion_device 27 * @dev: back pointer to the ion_device
29 * @heap: back pointer to the heap the buffer came from 28 * @heap: back pointer to the heap the buffer came from
@@ -39,10 +38,7 @@
39 * @attachments: list of devices attached to this buffer 38 * @attachments: list of devices attached to this buffer
40 */ 39 */
41struct ion_buffer { 40struct ion_buffer {
42 union { 41 struct list_head list;
43 struct rb_node node;
44 struct list_head list;
45 };
46 struct ion_device *dev; 42 struct ion_device *dev;
47 struct ion_heap *heap; 43 struct ion_heap *heap;
48 unsigned long flags; 44 unsigned long flags;
@@ -61,14 +57,10 @@ void ion_buffer_destroy(struct ion_buffer *buffer);
61/** 57/**
62 * struct ion_device - the metadata of the ion device node 58 * struct ion_device - the metadata of the ion device node
63 * @dev: the actual misc device 59 * @dev: the actual misc device
64 * @buffers: an rb tree of all the existing buffers
65 * @buffer_lock: lock protecting the tree of buffers
66 * @lock: rwsem protecting the tree of heaps and clients 60 * @lock: rwsem protecting the tree of heaps and clients
67 */ 61 */
68struct ion_device { 62struct ion_device {
69 struct miscdevice dev; 63 struct miscdevice dev;
70 struct rb_root buffers;
71 struct mutex buffer_lock;
72 struct rw_semaphore lock; 64 struct rw_semaphore lock;
73 struct plist_head heaps; 65 struct plist_head heaps;
74 struct dentry *debug_root; 66 struct dentry *debug_root;
diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c
index aabcda3f9fc8..28603dfadce2 100644
--- a/drivers/staging/comedi/drivers/daqboard2000.c
+++ b/drivers/staging/comedi/drivers/daqboard2000.c
@@ -665,11 +665,6 @@ static void db2k_initialize_adc(struct comedi_device *dev)
665 db2k_initialize_tmrs(dev); 665 db2k_initialize_tmrs(dev);
666} 666}
667 667
668static void db2k_initialize_dac(struct comedi_device *dev)
669{
670 db2k_dac_disarm(dev);
671}
672
673static int db2k_8255_cb(struct comedi_device *dev, int dir, int port, int data, 668static int db2k_8255_cb(struct comedi_device *dev, int dir, int port, int data,
674 unsigned long iobase) 669 unsigned long iobase)
675{ 670{
@@ -719,7 +714,7 @@ static int db2k_auto_attach(struct comedi_device *dev, unsigned long context)
719 return result; 714 return result;
720 715
721 db2k_initialize_adc(dev); 716 db2k_initialize_adc(dev);
722 db2k_initialize_dac(dev); 717 db2k_dac_disarm(dev);
723 718
724 s = &dev->subdevices[0]; 719 s = &dev->subdevices[0];
725 /* ai subdevice */ 720 /* ai subdevice */
diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c
index c175227009f1..f98e3ae27bff 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -596,7 +596,7 @@ static int ni_request_ao_mite_channel(struct comedi_device *dev)
596 if (!mite_chan) { 596 if (!mite_chan) {
597 spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); 597 spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags);
598 dev_err(dev->class_dev, 598 dev_err(dev->class_dev,
599 "failed to reserve mite dma channel for analog outut\n"); 599 "failed to reserve mite dma channel for analog output\n");
600 return -EBUSY; 600 return -EBUSY;
601 } 601 }
602 mite_chan->dir = COMEDI_OUTPUT; 602 mite_chan->dir = COMEDI_OUTPUT;
diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c b/drivers/staging/comedi/drivers/usbduxsigma.c
index 3cc40d2544be..54d7605e909f 100644
--- a/drivers/staging/comedi/drivers/usbduxsigma.c
+++ b/drivers/staging/comedi/drivers/usbduxsigma.c
@@ -1074,7 +1074,7 @@ static int usbduxsigma_pwm_period(struct comedi_device *dev,
1074 unsigned int period) 1074 unsigned int period)
1075{ 1075{
1076 struct usbduxsigma_private *devpriv = dev->private; 1076 struct usbduxsigma_private *devpriv = dev->private;
1077 int fx2delay = 255; 1077 int fx2delay;
1078 1078
1079 if (period < MIN_PWM_PERIOD) 1079 if (period < MIN_PWM_PERIOD)
1080 return -EAGAIN; 1080 return -EAGAIN;
diff --git a/drivers/staging/emxx_udc/emxx_udc.c b/drivers/staging/emxx_udc/emxx_udc.c
index 4f3c2c13a225..147481bf680c 100644
--- a/drivers/staging/emxx_udc/emxx_udc.c
+++ b/drivers/staging/emxx_udc/emxx_udc.c
@@ -165,7 +165,7 @@ static void _nbu2ss_create_ep0_packet(struct nbu2ss_udc *udc,
165 udc->ep0_req.req.buf = p_buf; 165 udc->ep0_req.req.buf = p_buf;
166 udc->ep0_req.req.length = length; 166 udc->ep0_req.req.length = length;
167 udc->ep0_req.req.dma = 0; 167 udc->ep0_req.req.dma = 0;
168 udc->ep0_req.req.zero = TRUE; 168 udc->ep0_req.req.zero = true;
169 udc->ep0_req.req.complete = _nbu2ss_ep0_complete; 169 udc->ep0_req.req.complete = _nbu2ss_ep0_complete;
170 udc->ep0_req.req.status = -EINPROGRESS; 170 udc->ep0_req.req.status = -EINPROGRESS;
171 udc->ep0_req.req.context = udc; 171 udc->ep0_req.req.context = udc;
@@ -668,7 +668,7 @@ static int _nbu2ss_ep0_in_transfer(struct nbu2ss_udc *udc,
668 if ((req->req.actual % EP0_PACKETSIZE) == 0) { 668 if ((req->req.actual % EP0_PACKETSIZE) == 0) {
669 if (req->zero) { 669 if (req->zero) {
670 req->zero = false; 670 req->zero = false;
671 EP0_send_NULL(udc, FALSE); 671 EP0_send_NULL(udc, false);
672 return 1; 672 return 1;
673 } 673 }
674 } 674 }
@@ -695,7 +695,7 @@ static int _nbu2ss_ep0_in_transfer(struct nbu2ss_udc *udc,
695 i_remain_size -= result; 695 i_remain_size -= result;
696 696
697 if (i_remain_size == 0) { 697 if (i_remain_size == 0) {
698 EP0_send_NULL(udc, FALSE); 698 EP0_send_NULL(udc, false);
699 return result; 699 return result;
700 } 700 }
701 701
@@ -754,7 +754,7 @@ static int _nbu2ss_ep0_out_transfer(struct nbu2ss_udc *udc,
754 if ((req->req.actual % EP0_PACKETSIZE) == 0) { 754 if ((req->req.actual % EP0_PACKETSIZE) == 0) {
755 if (req->zero) { 755 if (req->zero) {
756 req->zero = false; 756 req->zero = false;
757 EP0_receive_NULL(udc, FALSE); 757 EP0_receive_NULL(udc, false);
758 return 1; 758 return 1;
759 } 759 }
760 } 760 }
@@ -799,7 +799,7 @@ static int _nbu2ss_out_dma(struct nbu2ss_udc *udc, struct nbu2ss_req *req,
799 if (req->dma_flag) 799 if (req->dma_flag)
800 return 1; /* DMA is forwarded */ 800 return 1; /* DMA is forwarded */
801 801
802 req->dma_flag = TRUE; 802 req->dma_flag = true;
803 p_buffer = req->req.dma; 803 p_buffer = req->req.dma;
804 p_buffer += req->req.actual; 804 p_buffer += req->req.actual;
805 805
@@ -997,7 +997,7 @@ static int _nbu2ss_in_dma(struct nbu2ss_udc *udc, struct nbu2ss_ep *ep,
997 if (req->req.actual == 0) 997 if (req->req.actual == 0)
998 _nbu2ss_dma_map_single(udc, ep, req, USB_DIR_IN); 998 _nbu2ss_dma_map_single(udc, ep, req, USB_DIR_IN);
999#endif 999#endif
1000 req->dma_flag = TRUE; 1000 req->dma_flag = true;
1001 1001
1002 /* MAX Packet Size */ 1002 /* MAX Packet Size */
1003 mpkt = _nbu2ss_readl(&preg->EP_REGS[num].EP_PCKT_ADRS) & EPN_MPKT; 1003 mpkt = _nbu2ss_readl(&preg->EP_REGS[num].EP_PCKT_ADRS) & EPN_MPKT;
@@ -1166,7 +1166,7 @@ static int _nbu2ss_start_transfer(struct nbu2ss_udc *udc,
1166{ 1166{
1167 int nret = -EINVAL; 1167 int nret = -EINVAL;
1168 1168
1169 req->dma_flag = FALSE; 1169 req->dma_flag = false;
1170 req->div_len = 0; 1170 req->div_len = 0;
1171 1171
1172 if (req->req.length == 0) { 1172 if (req->req.length == 0) {
@@ -1190,7 +1190,7 @@ static int _nbu2ss_start_transfer(struct nbu2ss_udc *udc,
1190 break; 1190 break;
1191 1191
1192 case EP0_IN_STATUS_PHASE: 1192 case EP0_IN_STATUS_PHASE:
1193 nret = EP0_send_NULL(udc, TRUE); 1193 nret = EP0_send_NULL(udc, true);
1194 break; 1194 break;
1195 1195
1196 default: 1196 default:
@@ -1216,7 +1216,7 @@ static int _nbu2ss_start_transfer(struct nbu2ss_udc *udc,
1216static void _nbu2ss_restert_transfer(struct nbu2ss_ep *ep) 1216static void _nbu2ss_restert_transfer(struct nbu2ss_ep *ep)
1217{ 1217{
1218 u32 length; 1218 u32 length;
1219 bool bflag = FALSE; 1219 bool bflag = false;
1220 struct nbu2ss_req *req; 1220 struct nbu2ss_req *req;
1221 1221
1222 req = list_first_entry_or_null(&ep->queue, struct nbu2ss_req, queue); 1222 req = list_first_entry_or_null(&ep->queue, struct nbu2ss_req, queue);
@@ -1229,7 +1229,7 @@ static void _nbu2ss_restert_transfer(struct nbu2ss_ep *ep)
1229 1229
1230 length &= EPN_LDATA; 1230 length &= EPN_LDATA;
1231 if (length < ep->ep.maxpacket) 1231 if (length < ep->ep.maxpacket)
1232 bflag = TRUE; 1232 bflag = true;
1233 } 1233 }
1234 1234
1235 _nbu2ss_start_transfer(ep->udc, ep, req, bflag); 1235 _nbu2ss_start_transfer(ep->udc, ep, req, bflag);
@@ -1280,7 +1280,7 @@ static void _nbu2ss_set_endpoint_stall(struct nbu2ss_udc *udc,
1280 1280
1281 if (bstall) { 1281 if (bstall) {
1282 /* Set STALL */ 1282 /* Set STALL */
1283 ep->halted = TRUE; 1283 ep->halted = true;
1284 1284
1285 if (ep_adrs & USB_DIR_IN) 1285 if (ep_adrs & USB_DIR_IN)
1286 data = EPN_BCLR | EPN_ISTL; 1286 data = EPN_BCLR | EPN_ISTL;
@@ -1290,7 +1290,7 @@ static void _nbu2ss_set_endpoint_stall(struct nbu2ss_udc *udc,
1290 _nbu2ss_bitset(&preg->EP_REGS[num].EP_CONTROL, data); 1290 _nbu2ss_bitset(&preg->EP_REGS[num].EP_CONTROL, data);
1291 } else { 1291 } else {
1292 /* Clear STALL */ 1292 /* Clear STALL */
1293 ep->stalled = FALSE; 1293 ep->stalled = false;
1294 if (ep_adrs & USB_DIR_IN) { 1294 if (ep_adrs & USB_DIR_IN) {
1295 _nbu2ss_bitclr(&preg->EP_REGS[num].EP_CONTROL 1295 _nbu2ss_bitclr(&preg->EP_REGS[num].EP_CONTROL
1296 , EPN_ISTL); 1296 , EPN_ISTL);
@@ -1305,9 +1305,9 @@ static void _nbu2ss_set_endpoint_stall(struct nbu2ss_udc *udc,
1305 , data); 1305 , data);
1306 } 1306 }
1307 1307
1308 ep->stalled = FALSE; 1308 ep->stalled = false;
1309 if (ep->halted) { 1309 if (ep->halted) {
1310 ep->halted = FALSE; 1310 ep->halted = false;
1311 _nbu2ss_restert_transfer(ep); 1311 _nbu2ss_restert_transfer(ep);
1312 } 1312 }
1313 } 1313 }
@@ -1533,13 +1533,13 @@ static int std_req_get_status(struct nbu2ss_udc *udc)
1533/*-------------------------------------------------------------------------*/ 1533/*-------------------------------------------------------------------------*/
1534static int std_req_clear_feature(struct nbu2ss_udc *udc) 1534static int std_req_clear_feature(struct nbu2ss_udc *udc)
1535{ 1535{
1536 return _nbu2ss_req_feature(udc, FALSE); 1536 return _nbu2ss_req_feature(udc, false);
1537} 1537}
1538 1538
1539/*-------------------------------------------------------------------------*/ 1539/*-------------------------------------------------------------------------*/
1540static int std_req_set_feature(struct nbu2ss_udc *udc) 1540static int std_req_set_feature(struct nbu2ss_udc *udc)
1541{ 1541{
1542 return _nbu2ss_req_feature(udc, TRUE); 1542 return _nbu2ss_req_feature(udc, true);
1543} 1543}
1544 1544
1545/*-------------------------------------------------------------------------*/ 1545/*-------------------------------------------------------------------------*/
@@ -1601,7 +1601,7 @@ static inline void _nbu2ss_read_request_data(struct nbu2ss_udc *udc, u32 *pdata)
1601/*-------------------------------------------------------------------------*/ 1601/*-------------------------------------------------------------------------*/
1602static inline int _nbu2ss_decode_request(struct nbu2ss_udc *udc) 1602static inline int _nbu2ss_decode_request(struct nbu2ss_udc *udc)
1603{ 1603{
1604 bool bcall_back = TRUE; 1604 bool bcall_back = true;
1605 int nret = -EINVAL; 1605 int nret = -EINVAL;
1606 struct usb_ctrlrequest *p_ctrl; 1606 struct usb_ctrlrequest *p_ctrl;
1607 1607
@@ -1623,22 +1623,22 @@ static inline int _nbu2ss_decode_request(struct nbu2ss_udc *udc)
1623 switch (p_ctrl->bRequest) { 1623 switch (p_ctrl->bRequest) {
1624 case USB_REQ_GET_STATUS: 1624 case USB_REQ_GET_STATUS:
1625 nret = std_req_get_status(udc); 1625 nret = std_req_get_status(udc);
1626 bcall_back = FALSE; 1626 bcall_back = false;
1627 break; 1627 break;
1628 1628
1629 case USB_REQ_CLEAR_FEATURE: 1629 case USB_REQ_CLEAR_FEATURE:
1630 nret = std_req_clear_feature(udc); 1630 nret = std_req_clear_feature(udc);
1631 bcall_back = FALSE; 1631 bcall_back = false;
1632 break; 1632 break;
1633 1633
1634 case USB_REQ_SET_FEATURE: 1634 case USB_REQ_SET_FEATURE:
1635 nret = std_req_set_feature(udc); 1635 nret = std_req_set_feature(udc);
1636 bcall_back = FALSE; 1636 bcall_back = false;
1637 break; 1637 break;
1638 1638
1639 case USB_REQ_SET_ADDRESS: 1639 case USB_REQ_SET_ADDRESS:
1640 nret = std_req_set_address(udc); 1640 nret = std_req_set_address(udc);
1641 bcall_back = FALSE; 1641 bcall_back = false;
1642 break; 1642 break;
1643 1643
1644 case USB_REQ_SET_CONFIGURATION: 1644 case USB_REQ_SET_CONFIGURATION:
@@ -1655,7 +1655,7 @@ static inline int _nbu2ss_decode_request(struct nbu2ss_udc *udc)
1655 if (nret >= 0) { 1655 if (nret >= 0) {
1656 /*--------------------------------------*/ 1656 /*--------------------------------------*/
1657 /* Status Stage */ 1657 /* Status Stage */
1658 nret = EP0_send_NULL(udc, TRUE); 1658 nret = EP0_send_NULL(udc, true);
1659 } 1659 }
1660 } 1660 }
1661 1661
@@ -1688,7 +1688,7 @@ static inline int _nbu2ss_ep0_in_data_stage(struct nbu2ss_udc *udc)
1688 nret = _nbu2ss_ep0_in_transfer(udc, req); 1688 nret = _nbu2ss_ep0_in_transfer(udc, req);
1689 if (nret == 0) { 1689 if (nret == 0) {
1690 udc->ep0state = EP0_OUT_STATUS_PAHSE; 1690 udc->ep0state = EP0_OUT_STATUS_PAHSE;
1691 EP0_receive_NULL(udc, TRUE); 1691 EP0_receive_NULL(udc, true);
1692 } 1692 }
1693 1693
1694 return 0; 1694 return 0;
@@ -1708,7 +1708,7 @@ static inline int _nbu2ss_ep0_out_data_stage(struct nbu2ss_udc *udc)
1708 nret = _nbu2ss_ep0_out_transfer(udc, req); 1708 nret = _nbu2ss_ep0_out_transfer(udc, req);
1709 if (nret == 0) { 1709 if (nret == 0) {
1710 udc->ep0state = EP0_IN_STATUS_PHASE; 1710 udc->ep0state = EP0_IN_STATUS_PHASE;
1711 EP0_send_NULL(udc, TRUE); 1711 EP0_send_NULL(udc, true);
1712 1712
1713 } else if (nret < 0) { 1713 } else if (nret < 0) {
1714 _nbu2ss_bitset(&udc->p_regs->EP0_CONTROL, EP0_BCLR); 1714 _nbu2ss_bitset(&udc->p_regs->EP0_CONTROL, EP0_BCLR);
@@ -1817,7 +1817,7 @@ static inline void _nbu2ss_ep0_int(struct nbu2ss_udc *udc)
1817 1817
1818 if (nret < 0) { 1818 if (nret < 0) {
1819 /* Send Stall */ 1819 /* Send Stall */
1820 _nbu2ss_set_endpoint_stall(udc, 0, TRUE); 1820 _nbu2ss_set_endpoint_stall(udc, 0, true);
1821 } 1821 }
1822} 1822}
1823 1823
@@ -1925,7 +1925,7 @@ static inline void _nbu2ss_epn_in_dma_int(struct nbu2ss_udc *udc,
1925 1925
1926 preq->actual += req->div_len; 1926 preq->actual += req->div_len;
1927 req->div_len = 0; 1927 req->div_len = 0;
1928 req->dma_flag = FALSE; 1928 req->dma_flag = false;
1929 1929
1930#ifdef USE_DMA 1930#ifdef USE_DMA
1931 _nbu2ss_dma_unmap_single(udc, ep, req, USB_DIR_IN); 1931 _nbu2ss_dma_unmap_single(udc, ep, req, USB_DIR_IN);
@@ -1961,7 +1961,7 @@ static inline void _nbu2ss_epn_out_dma_int(struct nbu2ss_udc *udc,
1961 if (req->req.actual == req->req.length) { 1961 if (req->req.actual == req->req.length) {
1962 if ((req->req.length % ep->ep.maxpacket) && !req->zero) { 1962 if ((req->req.length % ep->ep.maxpacket) && !req->zero) {
1963 req->div_len = 0; 1963 req->div_len = 0;
1964 req->dma_flag = FALSE; 1964 req->dma_flag = false;
1965 _nbu2ss_ep_done(ep, req, 0); 1965 _nbu2ss_ep_done(ep, req, 0);
1966 return; 1966 return;
1967 } 1967 }
@@ -1990,7 +1990,7 @@ static inline void _nbu2ss_epn_out_dma_int(struct nbu2ss_udc *udc,
1990 if ((req->req.actual % ep->ep.maxpacket) > 0) { 1990 if ((req->req.actual % ep->ep.maxpacket) > 0) {
1991 if (req->req.actual == req->div_len) { 1991 if (req->req.actual == req->div_len) {
1992 req->div_len = 0; 1992 req->div_len = 0;
1993 req->dma_flag = FALSE; 1993 req->dma_flag = false;
1994 _nbu2ss_ep_done(ep, req, 0); 1994 _nbu2ss_ep_done(ep, req, 0);
1995 return; 1995 return;
1996 } 1996 }
@@ -1998,7 +1998,7 @@ static inline void _nbu2ss_epn_out_dma_int(struct nbu2ss_udc *udc,
1998 1998
1999 req->req.actual += req->div_len; 1999 req->req.actual += req->div_len;
2000 req->div_len = 0; 2000 req->div_len = 0;
2001 req->dma_flag = FALSE; 2001 req->dma_flag = false;
2002 2002
2003 _nbu2ss_epn_out_int(udc, ep, req); 2003 _nbu2ss_epn_out_int(udc, ep, req);
2004} 2004}
@@ -2187,7 +2187,7 @@ static int _nbu2ss_enable_controller(struct nbu2ss_udc *udc)
2187 /* USB Interrupt Enable */ 2187 /* USB Interrupt Enable */
2188 _nbu2ss_bitset(&udc->p_regs->USB_INT_ENA, USB_INT_EN_BIT); 2188 _nbu2ss_bitset(&udc->p_regs->USB_INT_ENA, USB_INT_EN_BIT);
2189 2189
2190 udc->udc_enabled = TRUE; 2190 udc->udc_enabled = true;
2191 2191
2192 return 0; 2192 return 0;
2193} 2193}
@@ -2203,7 +2203,7 @@ static void _nbu2ss_reset_controller(struct nbu2ss_udc *udc)
2203static void _nbu2ss_disable_controller(struct nbu2ss_udc *udc) 2203static void _nbu2ss_disable_controller(struct nbu2ss_udc *udc)
2204{ 2204{
2205 if (udc->udc_enabled) { 2205 if (udc->udc_enabled) {
2206 udc->udc_enabled = FALSE; 2206 udc->udc_enabled = false;
2207 _nbu2ss_reset_controller(udc); 2207 _nbu2ss_reset_controller(udc);
2208 _nbu2ss_bitset(&udc->p_regs->EPCTR, (DIRPD | EPC_RST)); 2208 _nbu2ss_bitset(&udc->p_regs->EPCTR, (DIRPD | EPC_RST));
2209 } 2209 }
@@ -2456,8 +2456,8 @@ static int nbu2ss_ep_enable(struct usb_ep *_ep,
2456 ep->direct = desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK; 2456 ep->direct = desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK;
2457 ep->ep_type = ep_type; 2457 ep->ep_type = ep_type;
2458 ep->wedged = 0; 2458 ep->wedged = 0;
2459 ep->halted = FALSE; 2459 ep->halted = false;
2460 ep->stalled = FALSE; 2460 ep->stalled = false;
2461 2461
2462 ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize); 2462 ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize);
2463 2463
@@ -2588,9 +2588,9 @@ static int nbu2ss_ep_queue(struct usb_ep *_ep,
2588 2588
2589#ifdef USE_DMA 2589#ifdef USE_DMA
2590 if ((uintptr_t)req->req.buf & 0x3) 2590 if ((uintptr_t)req->req.buf & 0x3)
2591 req->unaligned = TRUE; 2591 req->unaligned = true;
2592 else 2592 else
2593 req->unaligned = FALSE; 2593 req->unaligned = false;
2594 2594
2595 if (req->unaligned) { 2595 if (req->unaligned) {
2596 if (!ep->virt_buf) 2596 if (!ep->virt_buf)
@@ -2616,7 +2616,7 @@ static int nbu2ss_ep_queue(struct usb_ep *_ep,
2616 list_add_tail(&req->queue, &ep->queue); 2616 list_add_tail(&req->queue, &ep->queue);
2617 2617
2618 if (bflag && !ep->stalled) { 2618 if (bflag && !ep->stalled) {
2619 result = _nbu2ss_start_transfer(udc, ep, req, FALSE); 2619 result = _nbu2ss_start_transfer(udc, ep, req, false);
2620 if (result < 0) { 2620 if (result < 0) {
2621 dev_err(udc->dev, " *** %s, result = %d\n", __func__, 2621 dev_err(udc->dev, " *** %s, result = %d\n", __func__,
2622 result); 2622 result);
@@ -2704,12 +2704,12 @@ static int nbu2ss_ep_set_halt(struct usb_ep *_ep, int value)
2704 ep_adrs = ep->epnum | ep->direct; 2704 ep_adrs = ep->epnum | ep->direct;
2705 if (value == 0) { 2705 if (value == 0) {
2706 _nbu2ss_set_endpoint_stall(udc, ep_adrs, value); 2706 _nbu2ss_set_endpoint_stall(udc, ep_adrs, value);
2707 ep->stalled = FALSE; 2707 ep->stalled = false;
2708 } else { 2708 } else {
2709 if (list_empty(&ep->queue)) 2709 if (list_empty(&ep->queue))
2710 _nbu2ss_epn_set_stall(udc, ep); 2710 _nbu2ss_epn_set_stall(udc, ep);
2711 else 2711 else
2712 ep->stalled = TRUE; 2712 ep->stalled = true;
2713 } 2713 }
2714 2714
2715 if (value == 0) 2715 if (value == 0)
@@ -3094,10 +3094,8 @@ static int nbu2ss_drv_probe(struct platform_device *pdev)
3094 return PTR_ERR(mmio_base); 3094 return PTR_ERR(mmio_base);
3095 3095
3096 irq = platform_get_irq(pdev, 0); 3096 irq = platform_get_irq(pdev, 0);
3097 if (irq < 0) { 3097 if (irq < 0)
3098 dev_err(&pdev->dev, "failed to get IRQ\n");
3099 return irq; 3098 return irq;
3100 }
3101 status = devm_request_irq(&pdev->dev, irq, _nbu2ss_udc_irq, 3099 status = devm_request_irq(&pdev->dev, irq, _nbu2ss_udc_irq,
3102 0, driver_name, udc); 3100 0, driver_name, udc);
3103 3101
diff --git a/drivers/staging/emxx_udc/emxx_udc.h b/drivers/staging/emxx_udc/emxx_udc.h
index b8c3dee5626c..9c2671cb32f7 100644
--- a/drivers/staging/emxx_udc/emxx_udc.h
+++ b/drivers/staging/emxx_udc/emxx_udc.h
@@ -19,11 +19,6 @@
19#define USE_DMA 1 19#define USE_DMA 1
20#define USE_SUSPEND_WAIT 1 20#define USE_SUSPEND_WAIT 1
21 21
22#ifndef TRUE
23#define TRUE 1
24#define FALSE 0
25#endif
26
27/*------------ Board dependence(Resource) */ 22/*------------ Board dependence(Resource) */
28#define VBUS_VALUE GPIO_VBUS 23#define VBUS_VALUE GPIO_VBUS
29 24
diff --git a/drivers/staging/erofs/Kconfig b/drivers/staging/erofs/Kconfig
deleted file mode 100644
index d04b798a8efb..000000000000
--- a/drivers/staging/erofs/Kconfig
+++ /dev/null
@@ -1,151 +0,0 @@
1# SPDX-License-Identifier: GPL-2.0
2
3config EROFS_FS
4 tristate "EROFS filesystem support"
5 depends on BLOCK
6 help
7 EROFS(Enhanced Read-Only File System) is a lightweight
8 read-only file system with modern designs (eg. page-sized
9 blocks, inline xattrs/data, etc.) for scenarios which need
10 high-performance read-only requirements, eg. firmwares in
11 mobile phone or LIVECDs.
12
13 It also provides VLE compression support, focusing on
14 random read improvements, keeping relatively lower
15 compression ratios, which is useful for high-performance
16 devices with limited memory and ROM space.
17
18 If unsure, say N.
19
20config EROFS_FS_DEBUG
21 bool "EROFS debugging feature"
22 depends on EROFS_FS
23 help
24 Print EROFS debugging messages and enable more BUG_ONs
25 which check the filesystem consistency aggressively.
26
27 For daily use, say N.
28
29config EROFS_FS_XATTR
30 bool "EROFS extended attributes"
31 depends on EROFS_FS
32 default y
33 help
34 Extended attributes are name:value pairs associated with inodes by
35 the kernel or by users (see the attr(5) manual page, or visit
36 <http://acl.bestbits.at/> for details).
37
38 If unsure, say N.
39
40config EROFS_FS_POSIX_ACL
41 bool "EROFS Access Control Lists"
42 depends on EROFS_FS_XATTR
43 select FS_POSIX_ACL
44 default y
45 help
46 Posix Access Control Lists (ACLs) support permissions for users and
47 groups beyond the owner/group/world scheme.
48
49 To learn more about Access Control Lists, visit the POSIX ACLs for
50 Linux website <http://acl.bestbits.at/>.
51
52 If you don't know what Access Control Lists are, say N.
53
54config EROFS_FS_SECURITY
55 bool "EROFS Security Labels"
56 depends on EROFS_FS_XATTR
57 help
58 Security labels provide an access control facility to support Linux
59 Security Models (LSMs) accepted by AppArmor, SELinux, Smack and TOMOYO
60 Linux. This option enables an extended attribute handler for file
61 security labels in the erofs filesystem, so that it requires enabling
62 the extended attribute support in advance.
63
64 If you are not using a security module, say N.
65
66config EROFS_FS_USE_VM_MAP_RAM
67 bool "EROFS VM_MAP_RAM Support"
68 depends on EROFS_FS
69 help
70 use vm_map_ram/vm_unmap_ram instead of vmap/vunmap.
71
72 If you don't know what these are, say N.
73
74config EROFS_FAULT_INJECTION
75 bool "EROFS fault injection facility"
76 depends on EROFS_FS
77 help
78 Test EROFS to inject faults such as ENOMEM, EIO, and so on.
79 If unsure, say N.
80
81config EROFS_FS_IO_MAX_RETRIES
82 int "EROFS IO Maximum Retries"
83 depends on EROFS_FS
84 default "5"
85 help
86 Maximum retry count of IO Errors.
87
88 If unsure, leave the default value (5 retries, 6 IOs at most).
89
90config EROFS_FS_ZIP
91 bool "EROFS Data Compresssion Support"
92 depends on EROFS_FS
93 select LZ4_DECOMPRESS
94 help
95 Currently we support LZ4 VLE Compression only.
96 Play at your own risk.
97
98 If you don't want to use compression feature, say N.
99
100config EROFS_FS_CLUSTER_PAGE_LIMIT
101 int "EROFS Cluster Pages Hard Limit"
102 depends on EROFS_FS_ZIP
103 range 1 256
104 default "1"
105 help
106 Indicates VLE compressed pages hard limit of a
107 compressed cluster.
108
109 For example, if files of a image are compressed
110 into 8k-unit, the hard limit should not be less
111 than 2. Otherwise, the image cannot be mounted
112 correctly on this kernel.
113
114choice
115 prompt "EROFS VLE Data Decompression mode"
116 depends on EROFS_FS_ZIP
117 default EROFS_FS_ZIP_CACHE_BIPOLAR
118 help
119 EROFS supports three options for VLE decompression.
120 "In-place Decompression Only" consumes the minimum memory
121 with lowest random read.
122
123 "Bipolar Cached Decompression" consumes the maximum memory
124 with highest random read.
125
126 If unsure, select "Bipolar Cached Decompression"
127
128config EROFS_FS_ZIP_NO_CACHE
129 bool "In-place Decompression Only"
130 help
131 Read compressed data into page cache and do in-place
132 decompression directly.
133
134config EROFS_FS_ZIP_CACHE_UNIPOLAR
135 bool "Unipolar Cached Decompression"
136 help
137 For each request, it caches the last compressed page
138 for further reading.
139 It still decompresses in place for the rest compressed pages.
140
141config EROFS_FS_ZIP_CACHE_BIPOLAR
142 bool "Bipolar Cached Decompression"
143 help
144 For each request, it caches the both end compressed pages
145 for further reading.
146 It still decompresses in place for the rest compressed pages.
147
148 Recommended for performance priority.
149
150endchoice
151
diff --git a/drivers/staging/erofs/Makefile b/drivers/staging/erofs/Makefile
deleted file mode 100644
index e704d9e51514..000000000000
--- a/drivers/staging/erofs/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
1# SPDX-License-Identifier: GPL-2.0
2
3EROFS_VERSION = "1.0pre1"
4
5ccflags-y += -DEROFS_VERSION=\"$(EROFS_VERSION)\"
6
7obj-$(CONFIG_EROFS_FS) += erofs.o
8# staging requirement: to be self-contained in its own directory
9ccflags-y += -I $(srctree)/$(src)/include
10erofs-objs := super.o inode.o data.o namei.o dir.o utils.o
11erofs-$(CONFIG_EROFS_FS_XATTR) += xattr.o
12erofs-$(CONFIG_EROFS_FS_ZIP) += unzip_vle.o zmap.o decompressor.o
13
diff --git a/drivers/staging/erofs/TODO b/drivers/staging/erofs/TODO
deleted file mode 100644
index a8608b2f72bd..000000000000
--- a/drivers/staging/erofs/TODO
+++ /dev/null
@@ -1,46 +0,0 @@
1
2EROFS is still working in progress, thus it is not suitable
3for all productive uses. play at your own risk :)
4
5TODO List:
6 - add the missing error handling code
7 (mainly existed in xattr and decompression submodules);
8
9 - finalize erofs ondisk format design (which means that
10 minor on-disk revisions could happen later);
11
12 - documentation and detailed technical analysis;
13
14 - general code review and clean up
15 (including confusing variable names and code snippets);
16
17 - support larger compressed clustersizes for selection
18 (currently erofs only works as expected with the page-sized
19 compressed cluster configuration, usually 4KB);
20
21 - support more lossless data compression algorithms
22 in addition to LZ4 algorithms in VLE approach;
23
24 - data deduplication and other useful features.
25
26The following git tree provides the file system user-space
27tools under development (ex, formatting tool mkfs.erofs):
28>> git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git
29
30The open-source development of erofs-utils is at the early stage.
31Contact the original author Li Guifu <bluce.liguifu@huawei.com> and
32the co-maintainer Fang Wei <fangwei1@huawei.com> for the latest news
33and more details.
34
35Code, suggestions, etc, are welcome. Please feel free to
36ask and send patches,
37
38To:
39 linux-erofs mailing list <linux-erofs@lists.ozlabs.org>
40 Gao Xiang <gaoxiang25@huawei.com>
41 Chao Yu <yuchao0@huawei.com>
42
43Cc: (for linux-kernel upstream patches)
44 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
45 linux-staging mailing list <devel@driverdev.osuosl.org>
46
diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
deleted file mode 100644
index 4c3d8bf8d249..000000000000
--- a/drivers/staging/erofs/inode.c
+++ /dev/null
@@ -1,332 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/drivers/staging/erofs/inode.c
4 *
5 * Copyright (C) 2017-2018 HUAWEI, Inc.
6 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of the Linux
11 * distribution for more details.
12 */
13#include "xattr.h"
14
15#include <trace/events/erofs.h>
16
17/* no locking */
18static int read_inode(struct inode *inode, void *data)
19{
20 struct erofs_vnode *vi = EROFS_V(inode);
21 struct erofs_inode_v1 *v1 = data;
22 const unsigned int advise = le16_to_cpu(v1->i_advise);
23 erofs_blk_t nblks = 0;
24
25 vi->datamode = __inode_data_mapping(advise);
26
27 if (unlikely(vi->datamode >= EROFS_INODE_LAYOUT_MAX)) {
28 errln("unsupported data mapping %u of nid %llu",
29 vi->datamode, vi->nid);
30 DBG_BUGON(1);
31 return -EIO;
32 }
33
34 if (__inode_version(advise) == EROFS_INODE_LAYOUT_V2) {
35 struct erofs_inode_v2 *v2 = data;
36
37 vi->inode_isize = sizeof(struct erofs_inode_v2);
38 vi->xattr_isize = ondisk_xattr_ibody_size(v2->i_xattr_icount);
39
40 inode->i_mode = le16_to_cpu(v2->i_mode);
41 if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
42 S_ISLNK(inode->i_mode)) {
43 vi->raw_blkaddr = le32_to_cpu(v2->i_u.raw_blkaddr);
44 } else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
45 inode->i_rdev =
46 new_decode_dev(le32_to_cpu(v2->i_u.rdev));
47 } else if (S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
48 inode->i_rdev = 0;
49 } else {
50 return -EIO;
51 }
52
53 i_uid_write(inode, le32_to_cpu(v2->i_uid));
54 i_gid_write(inode, le32_to_cpu(v2->i_gid));
55 set_nlink(inode, le32_to_cpu(v2->i_nlink));
56
57 /* ns timestamp */
58 inode->i_mtime.tv_sec = inode->i_ctime.tv_sec =
59 le64_to_cpu(v2->i_ctime);
60 inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec =
61 le32_to_cpu(v2->i_ctime_nsec);
62
63 inode->i_size = le64_to_cpu(v2->i_size);
64
65 /* total blocks for compressed files */
66 if (is_inode_layout_compression(inode))
67 nblks = le32_to_cpu(v2->i_u.compressed_blocks);
68 } else if (__inode_version(advise) == EROFS_INODE_LAYOUT_V1) {
69 struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
70
71 vi->inode_isize = sizeof(struct erofs_inode_v1);
72 vi->xattr_isize = ondisk_xattr_ibody_size(v1->i_xattr_icount);
73
74 inode->i_mode = le16_to_cpu(v1->i_mode);
75 if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
76 S_ISLNK(inode->i_mode)) {
77 vi->raw_blkaddr = le32_to_cpu(v1->i_u.raw_blkaddr);
78 } else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
79 inode->i_rdev =
80 new_decode_dev(le32_to_cpu(v1->i_u.rdev));
81 } else if (S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
82 inode->i_rdev = 0;
83 } else {
84 return -EIO;
85 }
86
87 i_uid_write(inode, le16_to_cpu(v1->i_uid));
88 i_gid_write(inode, le16_to_cpu(v1->i_gid));
89 set_nlink(inode, le16_to_cpu(v1->i_nlink));
90
91 /* use build time to derive all file time */
92 inode->i_mtime.tv_sec = inode->i_ctime.tv_sec =
93 sbi->build_time;
94 inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec =
95 sbi->build_time_nsec;
96
97 inode->i_size = le32_to_cpu(v1->i_size);
98 if (is_inode_layout_compression(inode))
99 nblks = le32_to_cpu(v1->i_u.compressed_blocks);
100 } else {
101 errln("unsupported on-disk inode version %u of nid %llu",
102 __inode_version(advise), vi->nid);
103 DBG_BUGON(1);
104 return -EIO;
105 }
106
107 if (!nblks)
108 /* measure inode.i_blocks as generic filesystems */
109 inode->i_blocks = roundup(inode->i_size, EROFS_BLKSIZ) >> 9;
110 else
111 inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK;
112 return 0;
113}
114
115/*
116 * try_lock can be required since locking order is:
117 * file data(fs_inode)
118 * meta(bd_inode)
119 * but the majority of the callers is "iget",
120 * in that case we are pretty sure no deadlock since
121 * no data operations exist. However I tend to
122 * try_lock since it takes no much overhead and
123 * will success immediately.
124 */
125static int fill_inline_data(struct inode *inode, void *data,
126 unsigned int m_pofs)
127{
128 struct erofs_vnode *vi = EROFS_V(inode);
129 struct erofs_sb_info *sbi = EROFS_I_SB(inode);
130
131 /* should be inode inline C */
132 if (!is_inode_flat_inline(inode))
133 return 0;
134
135 /* fast symlink (following ext4) */
136 if (S_ISLNK(inode->i_mode) && inode->i_size < PAGE_SIZE) {
137 char *lnk = erofs_kmalloc(sbi, inode->i_size + 1, GFP_KERNEL);
138
139 if (unlikely(!lnk))
140 return -ENOMEM;
141
142 m_pofs += vi->inode_isize + vi->xattr_isize;
143
144 /* inline symlink data shouldn't across page boundary as well */
145 if (unlikely(m_pofs + inode->i_size > PAGE_SIZE)) {
146 DBG_BUGON(1);
147 kfree(lnk);
148 return -EIO;
149 }
150
151 /* get in-page inline data */
152 memcpy(lnk, data + m_pofs, inode->i_size);
153 lnk[inode->i_size] = '\0';
154
155 inode->i_link = lnk;
156 set_inode_fast_symlink(inode);
157 }
158 return 0;
159}
160
161static int fill_inode(struct inode *inode, int isdir)
162{
163 struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
164 struct erofs_vnode *vi = EROFS_V(inode);
165 struct page *page;
166 void *data;
167 int err;
168 erofs_blk_t blkaddr;
169 unsigned int ofs;
170
171 trace_erofs_fill_inode(inode, isdir);
172
173 blkaddr = erofs_blknr(iloc(sbi, vi->nid));
174 ofs = erofs_blkoff(iloc(sbi, vi->nid));
175
176 debugln("%s, reading inode nid %llu at %u of blkaddr %u",
177 __func__, vi->nid, ofs, blkaddr);
178
179 page = erofs_get_meta_page(inode->i_sb, blkaddr, isdir);
180
181 if (IS_ERR(page)) {
182 errln("failed to get inode (nid: %llu) page, err %ld",
183 vi->nid, PTR_ERR(page));
184 return PTR_ERR(page);
185 }
186
187 DBG_BUGON(!PageUptodate(page));
188 data = page_address(page);
189
190 err = read_inode(inode, data + ofs);
191 if (!err) {
192 /* setup the new inode */
193 if (S_ISREG(inode->i_mode)) {
194 inode->i_op = &erofs_generic_iops;
195 inode->i_fop = &generic_ro_fops;
196 } else if (S_ISDIR(inode->i_mode)) {
197 inode->i_op = &erofs_dir_iops;
198 inode->i_fop = &erofs_dir_fops;
199 } else if (S_ISLNK(inode->i_mode)) {
200 /* by default, page_get_link is used for symlink */
201 inode->i_op = &erofs_symlink_iops;
202 inode_nohighmem(inode);
203 } else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
204 S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
205 inode->i_op = &erofs_generic_iops;
206 init_special_inode(inode, inode->i_mode, inode->i_rdev);
207 goto out_unlock;
208 } else {
209 err = -EIO;
210 goto out_unlock;
211 }
212
213 if (is_inode_layout_compression(inode)) {
214 err = z_erofs_fill_inode(inode);
215 goto out_unlock;
216 }
217
218 inode->i_mapping->a_ops = &erofs_raw_access_aops;
219
220 /* fill last page if inline data is available */
221 err = fill_inline_data(inode, data, ofs);
222 }
223
224out_unlock:
225 unlock_page(page);
226 put_page(page);
227 return err;
228}
229
230/*
231 * erofs nid is 64bits, but i_ino is 'unsigned long', therefore
232 * we should do more for 32-bit platform to find the right inode.
233 */
234#if BITS_PER_LONG == 32
235static int erofs_ilookup_test_actor(struct inode *inode, void *opaque)
236{
237 const erofs_nid_t nid = *(erofs_nid_t *)opaque;
238
239 return EROFS_V(inode)->nid == nid;
240}
241
242static int erofs_iget_set_actor(struct inode *inode, void *opaque)
243{
244 const erofs_nid_t nid = *(erofs_nid_t *)opaque;
245
246 inode->i_ino = erofs_inode_hash(nid);
247 return 0;
248}
249#endif
250
251static inline struct inode *erofs_iget_locked(struct super_block *sb,
252 erofs_nid_t nid)
253{
254 const unsigned long hashval = erofs_inode_hash(nid);
255
256#if BITS_PER_LONG >= 64
257 /* it is safe to use iget_locked for >= 64-bit platform */
258 return iget_locked(sb, hashval);
259#else
260 return iget5_locked(sb, hashval, erofs_ilookup_test_actor,
261 erofs_iget_set_actor, &nid);
262#endif
263}
264
265struct inode *erofs_iget(struct super_block *sb,
266 erofs_nid_t nid,
267 bool isdir)
268{
269 struct inode *inode = erofs_iget_locked(sb, nid);
270
271 if (unlikely(!inode))
272 return ERR_PTR(-ENOMEM);
273
274 if (inode->i_state & I_NEW) {
275 int err;
276 struct erofs_vnode *vi = EROFS_V(inode);
277
278 vi->nid = nid;
279
280 err = fill_inode(inode, isdir);
281 if (likely(!err))
282 unlock_new_inode(inode);
283 else {
284 iget_failed(inode);
285 inode = ERR_PTR(err);
286 }
287 }
288 return inode;
289}
290
291int erofs_getattr(const struct path *path, struct kstat *stat,
292 u32 request_mask, unsigned int query_flags)
293{
294 struct inode *const inode = d_inode(path->dentry);
295
296 if (is_inode_layout_compression(inode))
297 stat->attributes |= STATX_ATTR_COMPRESSED;
298
299 stat->attributes |= STATX_ATTR_IMMUTABLE;
300 stat->attributes_mask |= (STATX_ATTR_COMPRESSED |
301 STATX_ATTR_IMMUTABLE);
302
303 generic_fillattr(inode, stat);
304 return 0;
305}
306
307const struct inode_operations erofs_generic_iops = {
308 .getattr = erofs_getattr,
309#ifdef CONFIG_EROFS_FS_XATTR
310 .listxattr = erofs_listxattr,
311#endif
312 .get_acl = erofs_get_acl,
313};
314
315const struct inode_operations erofs_symlink_iops = {
316 .get_link = page_get_link,
317 .getattr = erofs_getattr,
318#ifdef CONFIG_EROFS_FS_XATTR
319 .listxattr = erofs_listxattr,
320#endif
321 .get_acl = erofs_get_acl,
322};
323
324const struct inode_operations erofs_fast_symlink_iops = {
325 .get_link = simple_get_link,
326 .getattr = erofs_getattr,
327#ifdef CONFIG_EROFS_FS_XATTR
328 .listxattr = erofs_listxattr,
329#endif
330 .get_acl = erofs_get_acl,
331};
332
diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
deleted file mode 100644
index 54494412eba4..000000000000
--- a/drivers/staging/erofs/super.c
+++ /dev/null
@@ -1,701 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/drivers/staging/erofs/super.c
4 *
5 * Copyright (C) 2017-2018 HUAWEI, Inc.
6 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of the Linux
11 * distribution for more details.
12 */
13#include <linux/module.h>
14#include <linux/buffer_head.h>
15#include <linux/statfs.h>
16#include <linux/parser.h>
17#include <linux/seq_file.h>
18#include "internal.h"
19#include "xattr.h"
20
21#define CREATE_TRACE_POINTS
22#include <trace/events/erofs.h>
23
24static struct kmem_cache *erofs_inode_cachep __read_mostly;
25
26static void init_once(void *ptr)
27{
28 struct erofs_vnode *vi = ptr;
29
30 inode_init_once(&vi->vfs_inode);
31}
32
33static int __init erofs_init_inode_cache(void)
34{
35 erofs_inode_cachep = kmem_cache_create("erofs_inode",
36 sizeof(struct erofs_vnode), 0,
37 SLAB_RECLAIM_ACCOUNT,
38 init_once);
39
40 return erofs_inode_cachep ? 0 : -ENOMEM;
41}
42
43static void erofs_exit_inode_cache(void)
44{
45 kmem_cache_destroy(erofs_inode_cachep);
46}
47
48static struct inode *alloc_inode(struct super_block *sb)
49{
50 struct erofs_vnode *vi =
51 kmem_cache_alloc(erofs_inode_cachep, GFP_KERNEL);
52
53 if (!vi)
54 return NULL;
55
56 /* zero out everything except vfs_inode */
57 memset(vi, 0, offsetof(struct erofs_vnode, vfs_inode));
58 return &vi->vfs_inode;
59}
60
61static void free_inode(struct inode *inode)
62{
63 struct erofs_vnode *vi = EROFS_V(inode);
64
65 /* be careful RCU symlink path (see ext4_inode_info->i_data)! */
66 if (is_inode_fast_symlink(inode))
67 kfree(inode->i_link);
68
69 kfree(vi->xattr_shared_xattrs);
70
71 kmem_cache_free(erofs_inode_cachep, vi);
72}
73
74static bool check_layout_compatibility(struct super_block *sb,
75 struct erofs_super_block *layout)
76{
77 const unsigned int requirements = le32_to_cpu(layout->requirements);
78
79 EROFS_SB(sb)->requirements = requirements;
80
81 /* check if current kernel meets all mandatory requirements */
82 if (requirements & (~EROFS_ALL_REQUIREMENTS)) {
83 errln("unidentified requirements %x, please upgrade kernel version",
84 requirements & ~EROFS_ALL_REQUIREMENTS);
85 return false;
86 }
87 return true;
88}
89
90static int superblock_read(struct super_block *sb)
91{
92 struct erofs_sb_info *sbi;
93 struct buffer_head *bh;
94 struct erofs_super_block *layout;
95 unsigned int blkszbits;
96 int ret;
97
98 bh = sb_bread(sb, 0);
99
100 if (!bh) {
101 errln("cannot read erofs superblock");
102 return -EIO;
103 }
104
105 sbi = EROFS_SB(sb);
106 layout = (struct erofs_super_block *)((u8 *)bh->b_data
107 + EROFS_SUPER_OFFSET);
108
109 ret = -EINVAL;
110 if (le32_to_cpu(layout->magic) != EROFS_SUPER_MAGIC_V1) {
111 errln("cannot find valid erofs superblock");
112 goto out;
113 }
114
115 blkszbits = layout->blkszbits;
116 /* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */
117 if (unlikely(blkszbits != LOG_BLOCK_SIZE)) {
118 errln("blksize %u isn't supported on this platform",
119 1 << blkszbits);
120 goto out;
121 }
122
123 if (!check_layout_compatibility(sb, layout))
124 goto out;
125
126 sbi->blocks = le32_to_cpu(layout->blocks);
127 sbi->meta_blkaddr = le32_to_cpu(layout->meta_blkaddr);
128#ifdef CONFIG_EROFS_FS_XATTR
129 sbi->xattr_blkaddr = le32_to_cpu(layout->xattr_blkaddr);
130#endif
131 sbi->islotbits = ffs(sizeof(struct erofs_inode_v1)) - 1;
132#ifdef CONFIG_EROFS_FS_ZIP
133 /* TODO: clusterbits should be related to inode */
134 sbi->clusterbits = blkszbits;
135
136 if (1 << (sbi->clusterbits - PAGE_SHIFT) > Z_EROFS_CLUSTER_MAX_PAGES)
137 errln("clusterbits %u is not supported on this kernel",
138 sbi->clusterbits);
139#endif
140
141 sbi->root_nid = le16_to_cpu(layout->root_nid);
142 sbi->inos = le64_to_cpu(layout->inos);
143
144 sbi->build_time = le64_to_cpu(layout->build_time);
145 sbi->build_time_nsec = le32_to_cpu(layout->build_time_nsec);
146
147 memcpy(&sb->s_uuid, layout->uuid, sizeof(layout->uuid));
148 memcpy(sbi->volume_name, layout->volume_name,
149 sizeof(layout->volume_name));
150
151 ret = 0;
152out:
153 brelse(bh);
154 return ret;
155}
156
157#ifdef CONFIG_EROFS_FAULT_INJECTION
158const char *erofs_fault_name[FAULT_MAX] = {
159 [FAULT_KMALLOC] = "kmalloc",
160 [FAULT_READ_IO] = "read IO error",
161};
162
163static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
164 unsigned int rate)
165{
166 struct erofs_fault_info *ffi = &sbi->fault_info;
167
168 if (rate) {
169 atomic_set(&ffi->inject_ops, 0);
170 ffi->inject_rate = rate;
171 ffi->inject_type = (1 << FAULT_MAX) - 1;
172 } else {
173 memset(ffi, 0, sizeof(struct erofs_fault_info));
174 }
175
176 set_opt(sbi, FAULT_INJECTION);
177}
178
179static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
180 substring_t *args)
181{
182 int rate = 0;
183
184 if (args->from && match_int(args, &rate))
185 return -EINVAL;
186
187 __erofs_build_fault_attr(sbi, rate);
188 return 0;
189}
190
191static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi)
192{
193 return sbi->fault_info.inject_rate;
194}
195#else
196static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
197 unsigned int rate)
198{
199}
200
201static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
202 substring_t *args)
203{
204 infoln("fault_injection options not supported");
205 return 0;
206}
207
208static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi)
209{
210 return 0;
211}
212#endif
213
214static void default_options(struct erofs_sb_info *sbi)
215{
216 /* set up some FS parameters */
217#ifdef CONFIG_EROFS_FS_ZIP
218 sbi->max_sync_decompress_pages = DEFAULT_MAX_SYNC_DECOMPRESS_PAGES;
219#endif
220
221#ifdef CONFIG_EROFS_FS_XATTR
222 set_opt(sbi, XATTR_USER);
223#endif
224
225#ifdef CONFIG_EROFS_FS_POSIX_ACL
226 set_opt(sbi, POSIX_ACL);
227#endif
228}
229
230enum {
231 Opt_user_xattr,
232 Opt_nouser_xattr,
233 Opt_acl,
234 Opt_noacl,
235 Opt_fault_injection,
236 Opt_err
237};
238
239static match_table_t erofs_tokens = {
240 {Opt_user_xattr, "user_xattr"},
241 {Opt_nouser_xattr, "nouser_xattr"},
242 {Opt_acl, "acl"},
243 {Opt_noacl, "noacl"},
244 {Opt_fault_injection, "fault_injection=%u"},
245 {Opt_err, NULL}
246};
247
248static int parse_options(struct super_block *sb, char *options)
249{
250 substring_t args[MAX_OPT_ARGS];
251 char *p;
252 int err;
253
254 if (!options)
255 return 0;
256
257 while ((p = strsep(&options, ","))) {
258 int token;
259
260 if (!*p)
261 continue;
262
263 args[0].to = args[0].from = NULL;
264 token = match_token(p, erofs_tokens, args);
265
266 switch (token) {
267#ifdef CONFIG_EROFS_FS_XATTR
268 case Opt_user_xattr:
269 set_opt(EROFS_SB(sb), XATTR_USER);
270 break;
271 case Opt_nouser_xattr:
272 clear_opt(EROFS_SB(sb), XATTR_USER);
273 break;
274#else
275 case Opt_user_xattr:
276 infoln("user_xattr options not supported");
277 break;
278 case Opt_nouser_xattr:
279 infoln("nouser_xattr options not supported");
280 break;
281#endif
282#ifdef CONFIG_EROFS_FS_POSIX_ACL
283 case Opt_acl:
284 set_opt(EROFS_SB(sb), POSIX_ACL);
285 break;
286 case Opt_noacl:
287 clear_opt(EROFS_SB(sb), POSIX_ACL);
288 break;
289#else
290 case Opt_acl:
291 infoln("acl options not supported");
292 break;
293 case Opt_noacl:
294 infoln("noacl options not supported");
295 break;
296#endif
297 case Opt_fault_injection:
298 err = erofs_build_fault_attr(EROFS_SB(sb), args);
299 if (err)
300 return err;
301 break;
302
303 default:
304 errln("Unrecognized mount option \"%s\" "
305 "or missing value", p);
306 return -EINVAL;
307 }
308 }
309 return 0;
310}
311
312#ifdef EROFS_FS_HAS_MANAGED_CACHE
313
314static const struct address_space_operations managed_cache_aops;
315
316static int managed_cache_releasepage(struct page *page, gfp_t gfp_mask)
317{
318 int ret = 1; /* 0 - busy */
319 struct address_space *const mapping = page->mapping;
320
321 DBG_BUGON(!PageLocked(page));
322 DBG_BUGON(mapping->a_ops != &managed_cache_aops);
323
324 if (PagePrivate(page))
325 ret = erofs_try_to_free_cached_page(mapping, page);
326
327 return ret;
328}
329
330static void managed_cache_invalidatepage(struct page *page,
331 unsigned int offset,
332 unsigned int length)
333{
334 const unsigned int stop = length + offset;
335
336 DBG_BUGON(!PageLocked(page));
337
338 /* Check for potential overflow in debug mode */
339 DBG_BUGON(stop > PAGE_SIZE || stop < length);
340
341 if (offset == 0 && stop == PAGE_SIZE)
342 while (!managed_cache_releasepage(page, GFP_NOFS))
343 cond_resched();
344}
345
346static const struct address_space_operations managed_cache_aops = {
347 .releasepage = managed_cache_releasepage,
348 .invalidatepage = managed_cache_invalidatepage,
349};
350
351static struct inode *erofs_init_managed_cache(struct super_block *sb)
352{
353 struct inode *inode = new_inode(sb);
354
355 if (unlikely(!inode))
356 return ERR_PTR(-ENOMEM);
357
358 set_nlink(inode, 1);
359 inode->i_size = OFFSET_MAX;
360
361 inode->i_mapping->a_ops = &managed_cache_aops;
362 mapping_set_gfp_mask(inode->i_mapping,
363 GFP_NOFS | __GFP_HIGHMEM |
364 __GFP_MOVABLE | __GFP_NOFAIL);
365 return inode;
366}
367
368#endif
369
370static int erofs_read_super(struct super_block *sb,
371 const char *dev_name,
372 void *data, int silent)
373{
374 struct inode *inode;
375 struct erofs_sb_info *sbi;
376 int err = -EINVAL;
377
378 infoln("read_super, device -> %s", dev_name);
379 infoln("options -> %s", (char *)data);
380
381 if (unlikely(!sb_set_blocksize(sb, EROFS_BLKSIZ))) {
382 errln("failed to set erofs blksize");
383 goto err;
384 }
385
386 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
387 if (unlikely(!sbi)) {
388 err = -ENOMEM;
389 goto err;
390 }
391 sb->s_fs_info = sbi;
392
393 err = superblock_read(sb);
394 if (err)
395 goto err_sbread;
396
397 sb->s_magic = EROFS_SUPER_MAGIC;
398 sb->s_flags |= SB_RDONLY | SB_NOATIME;
399 sb->s_maxbytes = MAX_LFS_FILESIZE;
400 sb->s_time_gran = 1;
401
402 sb->s_op = &erofs_sops;
403
404#ifdef CONFIG_EROFS_FS_XATTR
405 sb->s_xattr = erofs_xattr_handlers;
406#endif
407
408 /* set erofs default mount options */
409 default_options(sbi);
410
411 err = parse_options(sb, data);
412 if (err)
413 goto err_parseopt;
414
415 if (!silent)
416 infoln("root inode @ nid %llu", ROOT_NID(sbi));
417
418 if (test_opt(sbi, POSIX_ACL))
419 sb->s_flags |= SB_POSIXACL;
420 else
421 sb->s_flags &= ~SB_POSIXACL;
422
423#ifdef CONFIG_EROFS_FS_ZIP
424 INIT_RADIX_TREE(&sbi->workstn_tree, GFP_ATOMIC);
425#endif
426
427#ifdef EROFS_FS_HAS_MANAGED_CACHE
428 sbi->managed_cache = erofs_init_managed_cache(sb);
429 if (IS_ERR(sbi->managed_cache)) {
430 err = PTR_ERR(sbi->managed_cache);
431 goto err_init_managed_cache;
432 }
433#endif
434
435 /* get the root inode */
436 inode = erofs_iget(sb, ROOT_NID(sbi), true);
437 if (IS_ERR(inode)) {
438 err = PTR_ERR(inode);
439 goto err_iget;
440 }
441
442 if (!S_ISDIR(inode->i_mode)) {
443 errln("rootino(nid %llu) is not a directory(i_mode %o)",
444 ROOT_NID(sbi), inode->i_mode);
445 err = -EINVAL;
446 iput(inode);
447 goto err_iget;
448 }
449
450 sb->s_root = d_make_root(inode);
451 if (!sb->s_root) {
452 err = -ENOMEM;
453 goto err_iget;
454 }
455
456 /* save the device name to sbi */
457 sbi->dev_name = __getname();
458 if (!sbi->dev_name) {
459 err = -ENOMEM;
460 goto err_devname;
461 }
462
463 snprintf(sbi->dev_name, PATH_MAX, "%s", dev_name);
464 sbi->dev_name[PATH_MAX - 1] = '\0';
465
466 erofs_register_super(sb);
467
468 if (!silent)
469 infoln("mounted on %s with opts: %s.", dev_name,
470 (char *)data);
471 return 0;
472 /*
473 * please add a label for each exit point and use
474 * the following name convention, thus new features
475 * can be integrated easily without renaming labels.
476 */
477err_devname:
478 dput(sb->s_root);
479 sb->s_root = NULL;
480err_iget:
481#ifdef EROFS_FS_HAS_MANAGED_CACHE
482 iput(sbi->managed_cache);
483err_init_managed_cache:
484#endif
485err_parseopt:
486err_sbread:
487 sb->s_fs_info = NULL;
488 kfree(sbi);
489err:
490 return err;
491}
492
493/*
494 * could be triggered after deactivate_locked_super()
495 * is called, thus including umount and failed to initialize.
496 */
497static void erofs_put_super(struct super_block *sb)
498{
499 struct erofs_sb_info *sbi = EROFS_SB(sb);
500
501 /* for cases which are failed in "read_super" */
502 if (!sbi)
503 return;
504
505 WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC);
506
507 infoln("unmounted for %s", sbi->dev_name);
508 __putname(sbi->dev_name);
509
510#ifdef EROFS_FS_HAS_MANAGED_CACHE
511 iput(sbi->managed_cache);
512#endif
513
514 mutex_lock(&sbi->umount_mutex);
515
516#ifdef CONFIG_EROFS_FS_ZIP
517 /* clean up the compression space of this sb */
518 erofs_shrink_workstation(EROFS_SB(sb), ~0UL, true);
519#endif
520
521 erofs_unregister_super(sb);
522 mutex_unlock(&sbi->umount_mutex);
523
524 kfree(sbi);
525 sb->s_fs_info = NULL;
526}
527
528
529struct erofs_mount_private {
530 const char *dev_name;
531 char *options;
532};
533
534/* support mount_bdev() with options */
535static int erofs_fill_super(struct super_block *sb,
536 void *_priv, int silent)
537{
538 struct erofs_mount_private *priv = _priv;
539
540 return erofs_read_super(sb, priv->dev_name,
541 priv->options, silent);
542}
543
544static struct dentry *erofs_mount(
545 struct file_system_type *fs_type, int flags,
546 const char *dev_name, void *data)
547{
548 struct erofs_mount_private priv = {
549 .dev_name = dev_name,
550 .options = data
551 };
552
553 return mount_bdev(fs_type, flags, dev_name,
554 &priv, erofs_fill_super);
555}
556
557static void erofs_kill_sb(struct super_block *sb)
558{
559 kill_block_super(sb);
560}
561
562static struct file_system_type erofs_fs_type = {
563 .owner = THIS_MODULE,
564 .name = "erofs",
565 .mount = erofs_mount,
566 .kill_sb = erofs_kill_sb,
567 .fs_flags = FS_REQUIRES_DEV,
568};
569MODULE_ALIAS_FS("erofs");
570
571static int __init erofs_module_init(void)
572{
573 int err;
574
575 erofs_check_ondisk_layout_definitions();
576 infoln("initializing erofs " EROFS_VERSION);
577
578 err = erofs_init_inode_cache();
579 if (err)
580 goto icache_err;
581
582 err = register_shrinker(&erofs_shrinker_info);
583 if (err)
584 goto shrinker_err;
585
586 err = z_erofs_init_zip_subsystem();
587 if (err)
588 goto zip_err;
589
590 err = register_filesystem(&erofs_fs_type);
591 if (err)
592 goto fs_err;
593
594 infoln("successfully to initialize erofs");
595 return 0;
596
597fs_err:
598 z_erofs_exit_zip_subsystem();
599zip_err:
600 unregister_shrinker(&erofs_shrinker_info);
601shrinker_err:
602 erofs_exit_inode_cache();
603icache_err:
604 return err;
605}
606
607static void __exit erofs_module_exit(void)
608{
609 unregister_filesystem(&erofs_fs_type);
610 z_erofs_exit_zip_subsystem();
611 unregister_shrinker(&erofs_shrinker_info);
612 erofs_exit_inode_cache();
613 infoln("successfully finalize erofs");
614}
615
616/* get filesystem statistics */
617static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf)
618{
619 struct super_block *sb = dentry->d_sb;
620 struct erofs_sb_info *sbi = EROFS_SB(sb);
621 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
622
623 buf->f_type = sb->s_magic;
624 buf->f_bsize = EROFS_BLKSIZ;
625 buf->f_blocks = sbi->blocks;
626 buf->f_bfree = buf->f_bavail = 0;
627
628 buf->f_files = ULLONG_MAX;
629 buf->f_ffree = ULLONG_MAX - sbi->inos;
630
631 buf->f_namelen = EROFS_NAME_LEN;
632
633 buf->f_fsid.val[0] = (u32)id;
634 buf->f_fsid.val[1] = (u32)(id >> 32);
635 return 0;
636}
637
638static int erofs_show_options(struct seq_file *seq, struct dentry *root)
639{
640 struct erofs_sb_info *sbi __maybe_unused = EROFS_SB(root->d_sb);
641
642#ifdef CONFIG_EROFS_FS_XATTR
643 if (test_opt(sbi, XATTR_USER))
644 seq_puts(seq, ",user_xattr");
645 else
646 seq_puts(seq, ",nouser_xattr");
647#endif
648#ifdef CONFIG_EROFS_FS_POSIX_ACL
649 if (test_opt(sbi, POSIX_ACL))
650 seq_puts(seq, ",acl");
651 else
652 seq_puts(seq, ",noacl");
653#endif
654 if (test_opt(sbi, FAULT_INJECTION))
655 seq_printf(seq, ",fault_injection=%u",
656 erofs_get_fault_rate(sbi));
657 return 0;
658}
659
660static int erofs_remount(struct super_block *sb, int *flags, char *data)
661{
662 struct erofs_sb_info *sbi = EROFS_SB(sb);
663 unsigned int org_mnt_opt = sbi->mount_opt;
664 unsigned int org_inject_rate = erofs_get_fault_rate(sbi);
665 int err;
666
667 DBG_BUGON(!sb_rdonly(sb));
668 err = parse_options(sb, data);
669 if (err)
670 goto out;
671
672 if (test_opt(sbi, POSIX_ACL))
673 sb->s_flags |= SB_POSIXACL;
674 else
675 sb->s_flags &= ~SB_POSIXACL;
676
677 *flags |= SB_RDONLY;
678 return 0;
679out:
680 __erofs_build_fault_attr(sbi, org_inject_rate);
681 sbi->mount_opt = org_mnt_opt;
682
683 return err;
684}
685
686const struct super_operations erofs_sops = {
687 .put_super = erofs_put_super,
688 .alloc_inode = alloc_inode,
689 .free_inode = free_inode,
690 .statfs = erofs_statfs,
691 .show_options = erofs_show_options,
692 .remount_fs = erofs_remount,
693};
694
695module_init(erofs_module_init);
696module_exit(erofs_module_exit);
697
698MODULE_DESCRIPTION("Enhanced ROM File System");
699MODULE_AUTHOR("Gao Xiang, Yu Chao, Miao Xie, CONSUMER BG, HUAWEI Inc.");
700MODULE_LICENSE("GPL");
701
diff --git a/drivers/staging/erofs/unzip_vle.c b/drivers/staging/erofs/unzip_vle.c
deleted file mode 100644
index f0dab81ff816..000000000000
--- a/drivers/staging/erofs/unzip_vle.c
+++ /dev/null
@@ -1,1591 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/drivers/staging/erofs/unzip_vle.c
4 *
5 * Copyright (C) 2018 HUAWEI, Inc.
6 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of the Linux
11 * distribution for more details.
12 */
13#include "unzip_vle.h"
14#include "compress.h"
15#include <linux/prefetch.h>
16
17#include <trace/events/erofs.h>
18
19/*
20 * a compressed_pages[] placeholder in order to avoid
21 * being filled with file pages for in-place decompression.
22 */
23#define PAGE_UNALLOCATED ((void *)0x5F0E4B1D)
24
25/* how to allocate cached pages for a workgroup */
26enum z_erofs_cache_alloctype {
27 DONTALLOC, /* don't allocate any cached pages */
28 DELAYEDALLOC, /* delayed allocation (at the time of submitting io) */
29};
30
31/*
32 * tagged pointer with 1-bit tag for all compressed pages
33 * tag 0 - the page is just found with an extra page reference
34 */
35typedef tagptr1_t compressed_page_t;
36
37#define tag_compressed_page_justfound(page) \
38 tagptr_fold(compressed_page_t, page, 1)
39
40static struct workqueue_struct *z_erofs_workqueue __read_mostly;
41static struct kmem_cache *z_erofs_workgroup_cachep __read_mostly;
42
43void z_erofs_exit_zip_subsystem(void)
44{
45 destroy_workqueue(z_erofs_workqueue);
46 kmem_cache_destroy(z_erofs_workgroup_cachep);
47}
48
49static inline int init_unzip_workqueue(void)
50{
51 const unsigned int onlinecpus = num_possible_cpus();
52
53 /*
54 * we don't need too many threads, limiting threads
55 * could improve scheduling performance.
56 */
57 z_erofs_workqueue =
58 alloc_workqueue("erofs_unzipd",
59 WQ_UNBOUND | WQ_HIGHPRI | WQ_CPU_INTENSIVE,
60 onlinecpus + onlinecpus / 4);
61
62 return z_erofs_workqueue ? 0 : -ENOMEM;
63}
64
65static void init_once(void *ptr)
66{
67 struct z_erofs_vle_workgroup *grp = ptr;
68 struct z_erofs_vle_work *const work =
69 z_erofs_vle_grab_primary_work(grp);
70 unsigned int i;
71
72 mutex_init(&work->lock);
73 work->nr_pages = 0;
74 work->vcnt = 0;
75 for (i = 0; i < Z_EROFS_CLUSTER_MAX_PAGES; ++i)
76 grp->compressed_pages[i] = NULL;
77}
78
79static void init_always(struct z_erofs_vle_workgroup *grp)
80{
81 struct z_erofs_vle_work *const work =
82 z_erofs_vle_grab_primary_work(grp);
83
84 atomic_set(&grp->obj.refcount, 1);
85 grp->flags = 0;
86
87 DBG_BUGON(work->nr_pages);
88 DBG_BUGON(work->vcnt);
89}
90
91int __init z_erofs_init_zip_subsystem(void)
92{
93 z_erofs_workgroup_cachep =
94 kmem_cache_create("erofs_compress",
95 Z_EROFS_WORKGROUP_SIZE, 0,
96 SLAB_RECLAIM_ACCOUNT, init_once);
97
98 if (z_erofs_workgroup_cachep) {
99 if (!init_unzip_workqueue())
100 return 0;
101
102 kmem_cache_destroy(z_erofs_workgroup_cachep);
103 }
104 return -ENOMEM;
105}
106
107enum z_erofs_vle_work_role {
108 Z_EROFS_VLE_WORK_SECONDARY,
109 Z_EROFS_VLE_WORK_PRIMARY,
110 /*
111 * The current work was the tail of an exist chain, and the previous
112 * processed chained works are all decided to be hooked up to it.
113 * A new chain should be created for the remaining unprocessed works,
114 * therefore different from Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED,
115 * the next work cannot reuse the whole page in the following scenario:
116 * ________________________________________________________________
117 * | tail (partial) page | head (partial) page |
118 * | (belongs to the next work) | (belongs to the current work) |
119 * |_______PRIMARY_FOLLOWED_______|________PRIMARY_HOOKED___________|
120 */
121 Z_EROFS_VLE_WORK_PRIMARY_HOOKED,
122 /*
123 * The current work has been linked with the processed chained works,
124 * and could be also linked with the potential remaining works, which
125 * means if the processing page is the tail partial page of the work,
126 * the current work can safely use the whole page (since the next work
127 * is under control) for in-place decompression, as illustrated below:
128 * ________________________________________________________________
129 * | tail (partial) page | head (partial) page |
130 * | (of the current work) | (of the previous work) |
131 * | PRIMARY_FOLLOWED or | |
132 * |_____PRIMARY_HOOKED____|____________PRIMARY_FOLLOWED____________|
133 *
134 * [ (*) the above page can be used for the current work itself. ]
135 */
136 Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED,
137 Z_EROFS_VLE_WORK_MAX
138};
139
140struct z_erofs_vle_work_builder {
141 enum z_erofs_vle_work_role role;
142 /*
143 * 'hosted = false' means that the current workgroup doesn't belong to
144 * the owned chained workgroups. In the other words, it is none of our
145 * business to submit this workgroup.
146 */
147 bool hosted;
148
149 struct z_erofs_vle_workgroup *grp;
150 struct z_erofs_vle_work *work;
151 struct z_erofs_pagevec_ctor vector;
152
153 /* pages used for reading the compressed data */
154 struct page **compressed_pages;
155 unsigned int compressed_deficit;
156};
157
158#define VLE_WORK_BUILDER_INIT() \
159 { .work = NULL, .role = Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED }
160
161#ifdef EROFS_FS_HAS_MANAGED_CACHE
162static void preload_compressed_pages(struct z_erofs_vle_work_builder *bl,
163 struct address_space *mc,
164 pgoff_t index,
165 unsigned int clusterpages,
166 enum z_erofs_cache_alloctype type,
167 struct list_head *pagepool,
168 gfp_t gfp)
169{
170 struct page **const pages = bl->compressed_pages;
171 const unsigned int remaining = bl->compressed_deficit;
172 bool standalone = true;
173 unsigned int i, j = 0;
174
175 if (bl->role < Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED)
176 return;
177
178 gfp = mapping_gfp_constraint(mc, gfp) & ~__GFP_RECLAIM;
179
180 index += clusterpages - remaining;
181
182 for (i = 0; i < remaining; ++i) {
183 struct page *page;
184 compressed_page_t t;
185
186 /* the compressed page was loaded before */
187 if (READ_ONCE(pages[i]))
188 continue;
189
190 page = find_get_page(mc, index + i);
191
192 if (page) {
193 t = tag_compressed_page_justfound(page);
194 } else if (type == DELAYEDALLOC) {
195 t = tagptr_init(compressed_page_t, PAGE_UNALLOCATED);
196 } else { /* DONTALLOC */
197 if (standalone)
198 j = i;
199 standalone = false;
200 continue;
201 }
202
203 if (!cmpxchg_relaxed(&pages[i], NULL, tagptr_cast_ptr(t)))
204 continue;
205
206 if (page)
207 put_page(page);
208 }
209 bl->compressed_pages += j;
210 bl->compressed_deficit = remaining - j;
211
212 if (standalone)
213 bl->role = Z_EROFS_VLE_WORK_PRIMARY;
214}
215
216/* called by erofs_shrinker to get rid of all compressed_pages */
217int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
218 struct erofs_workgroup *egrp)
219{
220 struct z_erofs_vle_workgroup *const grp =
221 container_of(egrp, struct z_erofs_vle_workgroup, obj);
222 struct address_space *const mapping = MNGD_MAPPING(sbi);
223 const int clusterpages = erofs_clusterpages(sbi);
224 int i;
225
226 /*
227 * refcount of workgroup is now freezed as 1,
228 * therefore no need to worry about available decompression users.
229 */
230 for (i = 0; i < clusterpages; ++i) {
231 struct page *page = grp->compressed_pages[i];
232
233 if (!page || page->mapping != mapping)
234 continue;
235
236 /* block other users from reclaiming or migrating the page */
237 if (!trylock_page(page))
238 return -EBUSY;
239
240 /* barrier is implied in the following 'unlock_page' */
241 WRITE_ONCE(grp->compressed_pages[i], NULL);
242
243 set_page_private(page, 0);
244 ClearPagePrivate(page);
245
246 unlock_page(page);
247 put_page(page);
248 }
249 return 0;
250}
251
252int erofs_try_to_free_cached_page(struct address_space *mapping,
253 struct page *page)
254{
255 struct erofs_sb_info *const sbi = EROFS_SB(mapping->host->i_sb);
256 const unsigned int clusterpages = erofs_clusterpages(sbi);
257 struct z_erofs_vle_workgroup *const grp = (void *)page_private(page);
258 int ret = 0; /* 0 - busy */
259
260 if (erofs_workgroup_try_to_freeze(&grp->obj, 1)) {
261 unsigned int i;
262
263 for (i = 0; i < clusterpages; ++i) {
264 if (grp->compressed_pages[i] == page) {
265 WRITE_ONCE(grp->compressed_pages[i], NULL);
266 ret = 1;
267 break;
268 }
269 }
270 erofs_workgroup_unfreeze(&grp->obj, 1);
271
272 if (ret) {
273 ClearPagePrivate(page);
274 put_page(page);
275 }
276 }
277 return ret;
278}
279#else
280static void preload_compressed_pages(struct z_erofs_vle_work_builder *bl,
281 struct address_space *mc,
282 pgoff_t index,
283 unsigned int clusterpages,
284 enum z_erofs_cache_alloctype type,
285 struct list_head *pagepool,
286 gfp_t gfp)
287{
288 /* nowhere to load compressed pages from */
289}
290#endif
291
292/* page_type must be Z_EROFS_PAGE_TYPE_EXCLUSIVE */
293static inline bool try_to_reuse_as_compressed_page(
294 struct z_erofs_vle_work_builder *b,
295 struct page *page)
296{
297 while (b->compressed_deficit) {
298 --b->compressed_deficit;
299 if (!cmpxchg(b->compressed_pages++, NULL, page))
300 return true;
301 }
302
303 return false;
304}
305
306/* callers must be with work->lock held */
307static int z_erofs_vle_work_add_page(
308 struct z_erofs_vle_work_builder *builder,
309 struct page *page,
310 enum z_erofs_page_type type)
311{
312 int ret;
313 bool occupied;
314
315 /* give priority for the compressed data storage */
316 if (builder->role >= Z_EROFS_VLE_WORK_PRIMARY &&
317 type == Z_EROFS_PAGE_TYPE_EXCLUSIVE &&
318 try_to_reuse_as_compressed_page(builder, page))
319 return 0;
320
321 ret = z_erofs_pagevec_ctor_enqueue(&builder->vector,
322 page, type, &occupied);
323 builder->work->vcnt += (unsigned int)ret;
324
325 return ret ? 0 : -EAGAIN;
326}
327
328static enum z_erofs_vle_work_role
329try_to_claim_workgroup(struct z_erofs_vle_workgroup *grp,
330 z_erofs_vle_owned_workgrp_t *owned_head,
331 bool *hosted)
332{
333 DBG_BUGON(*hosted);
334
335 /* let's claim these following types of workgroup */
336retry:
337 if (grp->next == Z_EROFS_VLE_WORKGRP_NIL) {
338 /* type 1, nil workgroup */
339 if (cmpxchg(&grp->next, Z_EROFS_VLE_WORKGRP_NIL,
340 *owned_head) != Z_EROFS_VLE_WORKGRP_NIL)
341 goto retry;
342
343 *owned_head = &grp->next;
344 *hosted = true;
345 /* lucky, I am the followee :) */
346 return Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED;
347
348 } else if (grp->next == Z_EROFS_VLE_WORKGRP_TAIL) {
349 /*
350 * type 2, link to the end of a existing open chain,
351 * be careful that its submission itself is governed
352 * by the original owned chain.
353 */
354 if (cmpxchg(&grp->next, Z_EROFS_VLE_WORKGRP_TAIL,
355 *owned_head) != Z_EROFS_VLE_WORKGRP_TAIL)
356 goto retry;
357 *owned_head = Z_EROFS_VLE_WORKGRP_TAIL;
358 return Z_EROFS_VLE_WORK_PRIMARY_HOOKED;
359 }
360
361 return Z_EROFS_VLE_WORK_PRIMARY; /* :( better luck next time */
362}
363
364struct z_erofs_vle_work_finder {
365 struct super_block *sb;
366 pgoff_t idx;
367 unsigned int pageofs;
368
369 struct z_erofs_vle_workgroup **grp_ret;
370 enum z_erofs_vle_work_role *role;
371 z_erofs_vle_owned_workgrp_t *owned_head;
372 bool *hosted;
373};
374
375static struct z_erofs_vle_work *
376z_erofs_vle_work_lookup(const struct z_erofs_vle_work_finder *f)
377{
378 bool tag, primary;
379 struct erofs_workgroup *egrp;
380 struct z_erofs_vle_workgroup *grp;
381 struct z_erofs_vle_work *work;
382
383 egrp = erofs_find_workgroup(f->sb, f->idx, &tag);
384 if (!egrp) {
385 *f->grp_ret = NULL;
386 return NULL;
387 }
388
389 grp = container_of(egrp, struct z_erofs_vle_workgroup, obj);
390 *f->grp_ret = grp;
391
392 work = z_erofs_vle_grab_work(grp, f->pageofs);
393 /* if multiref is disabled, `primary' is always true */
394 primary = true;
395
396 DBG_BUGON(work->pageofs != f->pageofs);
397
398 /*
399 * lock must be taken first to avoid grp->next == NIL between
400 * claiming workgroup and adding pages:
401 * grp->next != NIL
402 * grp->next = NIL
403 * mutex_unlock_all
404 * mutex_lock(&work->lock)
405 * add all pages to pagevec
406 *
407 * [correct locking case 1]:
408 * mutex_lock(grp->work[a])
409 * ...
410 * mutex_lock(grp->work[b]) mutex_lock(grp->work[c])
411 * ... *role = SECONDARY
412 * add all pages to pagevec
413 * ...
414 * mutex_unlock(grp->work[c])
415 * mutex_lock(grp->work[c])
416 * ...
417 * grp->next = NIL
418 * mutex_unlock_all
419 *
420 * [correct locking case 2]:
421 * mutex_lock(grp->work[b])
422 * ...
423 * mutex_lock(grp->work[a])
424 * ...
425 * mutex_lock(grp->work[c])
426 * ...
427 * grp->next = NIL
428 * mutex_unlock_all
429 * mutex_lock(grp->work[a])
430 * *role = PRIMARY_OWNER
431 * add all pages to pagevec
432 * ...
433 */
434 mutex_lock(&work->lock);
435
436 *f->hosted = false;
437 if (!primary)
438 *f->role = Z_EROFS_VLE_WORK_SECONDARY;
439 else /* claim the workgroup if possible */
440 *f->role = try_to_claim_workgroup(grp, f->owned_head,
441 f->hosted);
442 return work;
443}
444
445static struct z_erofs_vle_work *
446z_erofs_vle_work_register(const struct z_erofs_vle_work_finder *f,
447 struct erofs_map_blocks *map)
448{
449 bool gnew = false;
450 struct z_erofs_vle_workgroup *grp = *f->grp_ret;
451 struct z_erofs_vle_work *work;
452
453 /* if multiref is disabled, grp should never be nullptr */
454 if (unlikely(grp)) {
455 DBG_BUGON(1);
456 return ERR_PTR(-EINVAL);
457 }
458
459 /* no available workgroup, let's allocate one */
460 grp = kmem_cache_alloc(z_erofs_workgroup_cachep, GFP_NOFS);
461 if (unlikely(!grp))
462 return ERR_PTR(-ENOMEM);
463
464 init_always(grp);
465 grp->obj.index = f->idx;
466 grp->llen = map->m_llen;
467
468 z_erofs_vle_set_workgrp_fmt(grp, (map->m_flags & EROFS_MAP_ZIPPED) ?
469 Z_EROFS_VLE_WORKGRP_FMT_LZ4 :
470 Z_EROFS_VLE_WORKGRP_FMT_PLAIN);
471
472 if (map->m_flags & EROFS_MAP_FULL_MAPPED)
473 grp->flags |= Z_EROFS_VLE_WORKGRP_FULL_LENGTH;
474
475 /* new workgrps have been claimed as type 1 */
476 WRITE_ONCE(grp->next, *f->owned_head);
477 /* primary and followed work for all new workgrps */
478 *f->role = Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED;
479 /* it should be submitted by ourselves */
480 *f->hosted = true;
481
482 gnew = true;
483 work = z_erofs_vle_grab_primary_work(grp);
484 work->pageofs = f->pageofs;
485
486 /*
487 * lock all primary followed works before visible to others
488 * and mutex_trylock *never* fails for a new workgroup.
489 */
490 mutex_trylock(&work->lock);
491
492 if (gnew) {
493 int err = erofs_register_workgroup(f->sb, &grp->obj, 0);
494
495 if (err) {
496 mutex_unlock(&work->lock);
497 kmem_cache_free(z_erofs_workgroup_cachep, grp);
498 return ERR_PTR(-EAGAIN);
499 }
500 }
501
502 *f->owned_head = &grp->next;
503 *f->grp_ret = grp;
504 return work;
505}
506
507#define builder_is_hooked(builder) \
508 ((builder)->role >= Z_EROFS_VLE_WORK_PRIMARY_HOOKED)
509
510#define builder_is_followed(builder) \
511 ((builder)->role >= Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED)
512
513static int z_erofs_vle_work_iter_begin(struct z_erofs_vle_work_builder *builder,
514 struct super_block *sb,
515 struct erofs_map_blocks *map,
516 z_erofs_vle_owned_workgrp_t *owned_head)
517{
518 const unsigned int clusterpages = erofs_clusterpages(EROFS_SB(sb));
519 struct z_erofs_vle_workgroup *grp;
520 const struct z_erofs_vle_work_finder finder = {
521 .sb = sb,
522 .idx = erofs_blknr(map->m_pa),
523 .pageofs = map->m_la & ~PAGE_MASK,
524 .grp_ret = &grp,
525 .role = &builder->role,
526 .owned_head = owned_head,
527 .hosted = &builder->hosted
528 };
529 struct z_erofs_vle_work *work;
530
531 DBG_BUGON(builder->work);
532
533 /* must be Z_EROFS_WORK_TAIL or the next chained work */
534 DBG_BUGON(*owned_head == Z_EROFS_VLE_WORKGRP_NIL);
535 DBG_BUGON(*owned_head == Z_EROFS_VLE_WORKGRP_TAIL_CLOSED);
536
537 DBG_BUGON(erofs_blkoff(map->m_pa));
538
539repeat:
540 work = z_erofs_vle_work_lookup(&finder);
541 if (work) {
542 unsigned int orig_llen;
543
544 /* increase workgroup `llen' if needed */
545 while ((orig_llen = READ_ONCE(grp->llen)) < map->m_llen &&
546 orig_llen != cmpxchg_relaxed(&grp->llen,
547 orig_llen, map->m_llen))
548 cpu_relax();
549 goto got_it;
550 }
551
552 work = z_erofs_vle_work_register(&finder, map);
553 if (unlikely(work == ERR_PTR(-EAGAIN)))
554 goto repeat;
555
556 if (IS_ERR(work))
557 return PTR_ERR(work);
558got_it:
559 z_erofs_pagevec_ctor_init(&builder->vector, Z_EROFS_NR_INLINE_PAGEVECS,
560 work->pagevec, work->vcnt);
561
562 if (builder->role >= Z_EROFS_VLE_WORK_PRIMARY) {
563 /* enable possibly in-place decompression */
564 builder->compressed_pages = grp->compressed_pages;
565 builder->compressed_deficit = clusterpages;
566 } else {
567 builder->compressed_pages = NULL;
568 builder->compressed_deficit = 0;
569 }
570
571 builder->grp = grp;
572 builder->work = work;
573 return 0;
574}
575
576/*
577 * keep in mind that no referenced workgroups will be freed
578 * only after a RCU grace period, so rcu_read_lock() could
579 * prevent a workgroup from being freed.
580 */
581static void z_erofs_rcu_callback(struct rcu_head *head)
582{
583 struct z_erofs_vle_work *work = container_of(head,
584 struct z_erofs_vle_work, rcu);
585 struct z_erofs_vle_workgroup *grp =
586 z_erofs_vle_work_workgroup(work, true);
587
588 kmem_cache_free(z_erofs_workgroup_cachep, grp);
589}
590
591void erofs_workgroup_free_rcu(struct erofs_workgroup *grp)
592{
593 struct z_erofs_vle_workgroup *const vgrp = container_of(grp,
594 struct z_erofs_vle_workgroup, obj);
595 struct z_erofs_vle_work *const work = &vgrp->work;
596
597 call_rcu(&work->rcu, z_erofs_rcu_callback);
598}
599
600static void
601__z_erofs_vle_work_release(struct z_erofs_vle_workgroup *grp,
602 struct z_erofs_vle_work *work __maybe_unused)
603{
604 erofs_workgroup_put(&grp->obj);
605}
606
607static void z_erofs_vle_work_release(struct z_erofs_vle_work *work)
608{
609 struct z_erofs_vle_workgroup *grp =
610 z_erofs_vle_work_workgroup(work, true);
611
612 __z_erofs_vle_work_release(grp, work);
613}
614
615static inline bool
616z_erofs_vle_work_iter_end(struct z_erofs_vle_work_builder *builder)
617{
618 struct z_erofs_vle_work *work = builder->work;
619
620 if (!work)
621 return false;
622
623 z_erofs_pagevec_ctor_exit(&builder->vector, false);
624 mutex_unlock(&work->lock);
625
626 /*
627 * if all pending pages are added, don't hold work reference
628 * any longer if the current work isn't hosted by ourselves.
629 */
630 if (!builder->hosted)
631 __z_erofs_vle_work_release(builder->grp, work);
632
633 builder->work = NULL;
634 builder->grp = NULL;
635 return true;
636}
637
638static inline struct page *__stagingpage_alloc(struct list_head *pagepool,
639 gfp_t gfp)
640{
641 struct page *page = erofs_allocpage(pagepool, gfp);
642
643 if (unlikely(!page))
644 return NULL;
645
646 page->mapping = Z_EROFS_MAPPING_STAGING;
647 return page;
648}
649
650struct z_erofs_vle_frontend {
651 struct inode *const inode;
652
653 struct z_erofs_vle_work_builder builder;
654 struct erofs_map_blocks map;
655
656 z_erofs_vle_owned_workgrp_t owned_head;
657
658 /* used for applying cache strategy on the fly */
659 bool backmost;
660 erofs_off_t headoffset;
661};
662
663#define VLE_FRONTEND_INIT(__i) { \
664 .inode = __i, \
665 .map = { \
666 .m_llen = 0, \
667 .m_plen = 0, \
668 .mpage = NULL \
669 }, \
670 .builder = VLE_WORK_BUILDER_INIT(), \
671 .owned_head = Z_EROFS_VLE_WORKGRP_TAIL, \
672 .backmost = true, }
673
674#ifdef EROFS_FS_HAS_MANAGED_CACHE
675static inline bool
676should_alloc_managed_pages(struct z_erofs_vle_frontend *fe, erofs_off_t la)
677{
678 if (fe->backmost)
679 return true;
680
681 if (EROFS_FS_ZIP_CACHE_LVL >= 2)
682 return la < fe->headoffset;
683
684 return false;
685}
686#else
687static inline bool
688should_alloc_managed_pages(struct z_erofs_vle_frontend *fe, erofs_off_t la)
689{
690 return false;
691}
692#endif
693
694static int z_erofs_do_read_page(struct z_erofs_vle_frontend *fe,
695 struct page *page,
696 struct list_head *page_pool)
697{
698 struct super_block *const sb = fe->inode->i_sb;
699 struct erofs_sb_info *const sbi __maybe_unused = EROFS_SB(sb);
700 struct erofs_map_blocks *const map = &fe->map;
701 struct z_erofs_vle_work_builder *const builder = &fe->builder;
702 const loff_t offset = page_offset(page);
703
704 bool tight = builder_is_hooked(builder);
705 struct z_erofs_vle_work *work = builder->work;
706
707 enum z_erofs_cache_alloctype cache_strategy;
708 enum z_erofs_page_type page_type;
709 unsigned int cur, end, spiltted, index;
710 int err = 0;
711
712 /* register locked file pages as online pages in pack */
713 z_erofs_onlinepage_init(page);
714
715 spiltted = 0;
716 end = PAGE_SIZE;
717repeat:
718 cur = end - 1;
719
720 /* lucky, within the range of the current map_blocks */
721 if (offset + cur >= map->m_la &&
722 offset + cur < map->m_la + map->m_llen) {
723 /* didn't get a valid unzip work previously (very rare) */
724 if (!builder->work)
725 goto restart_now;
726 goto hitted;
727 }
728
729 /* go ahead the next map_blocks */
730 debugln("%s: [out-of-range] pos %llu", __func__, offset + cur);
731
732 if (z_erofs_vle_work_iter_end(builder))
733 fe->backmost = false;
734
735 map->m_la = offset + cur;
736 map->m_llen = 0;
737 err = z_erofs_map_blocks_iter(fe->inode, map, 0);
738 if (unlikely(err))
739 goto err_out;
740
741restart_now:
742 if (unlikely(!(map->m_flags & EROFS_MAP_MAPPED)))
743 goto hitted;
744
745 DBG_BUGON(map->m_plen != 1 << sbi->clusterbits);
746 DBG_BUGON(erofs_blkoff(map->m_pa));
747
748 err = z_erofs_vle_work_iter_begin(builder, sb, map, &fe->owned_head);
749 if (unlikely(err))
750 goto err_out;
751
752 /* preload all compressed pages (maybe downgrade role if necessary) */
753 if (should_alloc_managed_pages(fe, map->m_la))
754 cache_strategy = DELAYEDALLOC;
755 else
756 cache_strategy = DONTALLOC;
757
758 preload_compressed_pages(builder, MNGD_MAPPING(sbi),
759 map->m_pa / PAGE_SIZE,
760 map->m_plen / PAGE_SIZE,
761 cache_strategy, page_pool, GFP_KERNEL);
762
763 tight &= builder_is_hooked(builder);
764 work = builder->work;
765hitted:
766 cur = end - min_t(unsigned int, offset + end - map->m_la, end);
767 if (unlikely(!(map->m_flags & EROFS_MAP_MAPPED))) {
768 zero_user_segment(page, cur, end);
769 goto next_part;
770 }
771
772 /* let's derive page type */
773 page_type = cur ? Z_EROFS_VLE_PAGE_TYPE_HEAD :
774 (!spiltted ? Z_EROFS_PAGE_TYPE_EXCLUSIVE :
775 (tight ? Z_EROFS_PAGE_TYPE_EXCLUSIVE :
776 Z_EROFS_VLE_PAGE_TYPE_TAIL_SHARED));
777
778 if (cur)
779 tight &= builder_is_followed(builder);
780
781retry:
782 err = z_erofs_vle_work_add_page(builder, page, page_type);
783 /* should allocate an additional staging page for pagevec */
784 if (err == -EAGAIN) {
785 struct page *const newpage =
786 __stagingpage_alloc(page_pool, GFP_NOFS);
787
788 err = z_erofs_vle_work_add_page(builder, newpage,
789 Z_EROFS_PAGE_TYPE_EXCLUSIVE);
790 if (likely(!err))
791 goto retry;
792 }
793
794 if (unlikely(err))
795 goto err_out;
796
797 index = page->index - map->m_la / PAGE_SIZE;
798
799 /* FIXME! avoid the last relundant fixup & endio */
800 z_erofs_onlinepage_fixup(page, index, true);
801
802 /* bump up the number of spiltted parts of a page */
803 ++spiltted;
804 /* also update nr_pages */
805 work->nr_pages = max_t(pgoff_t, work->nr_pages, index + 1);
806next_part:
807 /* can be used for verification */
808 map->m_llen = offset + cur - map->m_la;
809
810 end = cur;
811 if (end > 0)
812 goto repeat;
813
814out:
815 /* FIXME! avoid the last relundant fixup & endio */
816 z_erofs_onlinepage_endio(page);
817
818 debugln("%s, finish page: %pK spiltted: %u map->m_llen %llu",
819 __func__, page, spiltted, map->m_llen);
820 return err;
821
822 /* if some error occurred while processing this page */
823err_out:
824 SetPageError(page);
825 goto out;
826}
827
828static void z_erofs_vle_unzip_kickoff(void *ptr, int bios)
829{
830 tagptr1_t t = tagptr_init(tagptr1_t, ptr);
831 struct z_erofs_vle_unzip_io *io = tagptr_unfold_ptr(t);
832 bool background = tagptr_unfold_tags(t);
833
834 if (!background) {
835 unsigned long flags;
836
837 spin_lock_irqsave(&io->u.wait.lock, flags);
838 if (!atomic_add_return(bios, &io->pending_bios))
839 wake_up_locked(&io->u.wait);
840 spin_unlock_irqrestore(&io->u.wait.lock, flags);
841 return;
842 }
843
844 if (!atomic_add_return(bios, &io->pending_bios))
845 queue_work(z_erofs_workqueue, &io->u.work);
846}
847
848static inline void z_erofs_vle_read_endio(struct bio *bio)
849{
850 struct erofs_sb_info *sbi = NULL;
851 blk_status_t err = bio->bi_status;
852 struct bio_vec *bvec;
853 struct bvec_iter_all iter_all;
854
855 bio_for_each_segment_all(bvec, bio, iter_all) {
856 struct page *page = bvec->bv_page;
857 bool cachemngd = false;
858
859 DBG_BUGON(PageUptodate(page));
860 DBG_BUGON(!page->mapping);
861
862 if (unlikely(!sbi && !z_erofs_page_is_staging(page))) {
863 sbi = EROFS_SB(page->mapping->host->i_sb);
864
865 if (time_to_inject(sbi, FAULT_READ_IO)) {
866 erofs_show_injection_info(FAULT_READ_IO);
867 err = BLK_STS_IOERR;
868 }
869 }
870
871 /* sbi should already be gotten if the page is managed */
872 if (sbi)
873 cachemngd = erofs_page_is_managed(sbi, page);
874
875 if (unlikely(err))
876 SetPageError(page);
877 else if (cachemngd)
878 SetPageUptodate(page);
879
880 if (cachemngd)
881 unlock_page(page);
882 }
883
884 z_erofs_vle_unzip_kickoff(bio->bi_private, -1);
885 bio_put(bio);
886}
887
888static struct page *z_pagemap_global[Z_EROFS_VLE_VMAP_GLOBAL_PAGES];
889static DEFINE_MUTEX(z_pagemap_global_lock);
890
891static int z_erofs_vle_unzip(struct super_block *sb,
892 struct z_erofs_vle_workgroup *grp,
893 struct list_head *page_pool)
894{
895 struct erofs_sb_info *const sbi = EROFS_SB(sb);
896 const unsigned int clusterpages = erofs_clusterpages(sbi);
897
898 struct z_erofs_pagevec_ctor ctor;
899 unsigned int nr_pages;
900 unsigned int sparsemem_pages = 0;
901 struct page *pages_onstack[Z_EROFS_VLE_VMAP_ONSTACK_PAGES];
902 struct page **pages, **compressed_pages, *page;
903 unsigned int algorithm;
904 unsigned int i, outputsize;
905
906 enum z_erofs_page_type page_type;
907 bool overlapped, partial;
908 struct z_erofs_vle_work *work;
909 int err;
910
911 might_sleep();
912 work = z_erofs_vle_grab_primary_work(grp);
913 DBG_BUGON(!READ_ONCE(work->nr_pages));
914
915 mutex_lock(&work->lock);
916 nr_pages = work->nr_pages;
917
918 if (likely(nr_pages <= Z_EROFS_VLE_VMAP_ONSTACK_PAGES))
919 pages = pages_onstack;
920 else if (nr_pages <= Z_EROFS_VLE_VMAP_GLOBAL_PAGES &&
921 mutex_trylock(&z_pagemap_global_lock))
922 pages = z_pagemap_global;
923 else {
924repeat:
925 pages = kvmalloc_array(nr_pages, sizeof(struct page *),
926 GFP_KERNEL);
927
928 /* fallback to global pagemap for the lowmem scenario */
929 if (unlikely(!pages)) {
930 if (nr_pages > Z_EROFS_VLE_VMAP_GLOBAL_PAGES)
931 goto repeat;
932 else {
933 mutex_lock(&z_pagemap_global_lock);
934 pages = z_pagemap_global;
935 }
936 }
937 }
938
939 for (i = 0; i < nr_pages; ++i)
940 pages[i] = NULL;
941
942 z_erofs_pagevec_ctor_init(&ctor, Z_EROFS_NR_INLINE_PAGEVECS,
943 work->pagevec, 0);
944
945 for (i = 0; i < work->vcnt; ++i) {
946 unsigned int pagenr;
947
948 page = z_erofs_pagevec_ctor_dequeue(&ctor, &page_type);
949
950 /* all pages in pagevec ought to be valid */
951 DBG_BUGON(!page);
952 DBG_BUGON(!page->mapping);
953
954 if (z_erofs_put_stagingpage(page_pool, page))
955 continue;
956
957 if (page_type == Z_EROFS_VLE_PAGE_TYPE_HEAD)
958 pagenr = 0;
959 else
960 pagenr = z_erofs_onlinepage_index(page);
961
962 DBG_BUGON(pagenr >= nr_pages);
963 DBG_BUGON(pages[pagenr]);
964
965 pages[pagenr] = page;
966 }
967 sparsemem_pages = i;
968
969 z_erofs_pagevec_ctor_exit(&ctor, true);
970
971 overlapped = false;
972 compressed_pages = grp->compressed_pages;
973
974 err = 0;
975 for (i = 0; i < clusterpages; ++i) {
976 unsigned int pagenr;
977
978 page = compressed_pages[i];
979
980 /* all compressed pages ought to be valid */
981 DBG_BUGON(!page);
982 DBG_BUGON(!page->mapping);
983
984 if (!z_erofs_page_is_staging(page)) {
985 if (erofs_page_is_managed(sbi, page)) {
986 if (unlikely(!PageUptodate(page)))
987 err = -EIO;
988 continue;
989 }
990
991 /*
992 * only if non-head page can be selected
993 * for inplace decompression
994 */
995 pagenr = z_erofs_onlinepage_index(page);
996
997 DBG_BUGON(pagenr >= nr_pages);
998 DBG_BUGON(pages[pagenr]);
999 ++sparsemem_pages;
1000 pages[pagenr] = page;
1001
1002 overlapped = true;
1003 }
1004
1005 /* PG_error needs checking for inplaced and staging pages */
1006 if (unlikely(PageError(page))) {
1007 DBG_BUGON(PageUptodate(page));
1008 err = -EIO;
1009 }
1010 }
1011
1012 if (unlikely(err))
1013 goto out;
1014
1015 if (nr_pages << PAGE_SHIFT >= work->pageofs + grp->llen) {
1016 outputsize = grp->llen;
1017 partial = !(grp->flags & Z_EROFS_VLE_WORKGRP_FULL_LENGTH);
1018 } else {
1019 outputsize = (nr_pages << PAGE_SHIFT) - work->pageofs;
1020 partial = true;
1021 }
1022
1023 if (z_erofs_vle_workgrp_fmt(grp) == Z_EROFS_VLE_WORKGRP_FMT_PLAIN)
1024 algorithm = Z_EROFS_COMPRESSION_SHIFTED;
1025 else
1026 algorithm = Z_EROFS_COMPRESSION_LZ4;
1027
1028 err = z_erofs_decompress(&(struct z_erofs_decompress_req) {
1029 .sb = sb,
1030 .in = compressed_pages,
1031 .out = pages,
1032 .pageofs_out = work->pageofs,
1033 .inputsize = PAGE_SIZE,
1034 .outputsize = outputsize,
1035 .alg = algorithm,
1036 .inplace_io = overlapped,
1037 .partial_decoding = partial
1038 }, page_pool);
1039
1040out:
1041 /* must handle all compressed pages before endding pages */
1042 for (i = 0; i < clusterpages; ++i) {
1043 page = compressed_pages[i];
1044
1045 if (erofs_page_is_managed(sbi, page))
1046 continue;
1047
1048 /* recycle all individual staging pages */
1049 (void)z_erofs_put_stagingpage(page_pool, page);
1050
1051 WRITE_ONCE(compressed_pages[i], NULL);
1052 }
1053
1054 for (i = 0; i < nr_pages; ++i) {
1055 page = pages[i];
1056 if (!page)
1057 continue;
1058
1059 DBG_BUGON(!page->mapping);
1060
1061 /* recycle all individual staging pages */
1062 if (z_erofs_put_stagingpage(page_pool, page))
1063 continue;
1064
1065 if (unlikely(err < 0))
1066 SetPageError(page);
1067
1068 z_erofs_onlinepage_endio(page);
1069 }
1070
1071 if (pages == z_pagemap_global)
1072 mutex_unlock(&z_pagemap_global_lock);
1073 else if (unlikely(pages != pages_onstack))
1074 kvfree(pages);
1075
1076 work->nr_pages = 0;
1077 work->vcnt = 0;
1078
1079 /* all work locks MUST be taken before the following line */
1080
1081 WRITE_ONCE(grp->next, Z_EROFS_VLE_WORKGRP_NIL);
1082
1083 /* all work locks SHOULD be released right now */
1084 mutex_unlock(&work->lock);
1085
1086 z_erofs_vle_work_release(work);
1087 return err;
1088}
1089
1090static void z_erofs_vle_unzip_all(struct super_block *sb,
1091 struct z_erofs_vle_unzip_io *io,
1092 struct list_head *page_pool)
1093{
1094 z_erofs_vle_owned_workgrp_t owned = io->head;
1095
1096 while (owned != Z_EROFS_VLE_WORKGRP_TAIL_CLOSED) {
1097 struct z_erofs_vle_workgroup *grp;
1098
1099 /* no possible that 'owned' equals Z_EROFS_WORK_TPTR_TAIL */
1100 DBG_BUGON(owned == Z_EROFS_VLE_WORKGRP_TAIL);
1101
1102 /* no possible that 'owned' equals NULL */
1103 DBG_BUGON(owned == Z_EROFS_VLE_WORKGRP_NIL);
1104
1105 grp = container_of(owned, struct z_erofs_vle_workgroup, next);
1106 owned = READ_ONCE(grp->next);
1107
1108 z_erofs_vle_unzip(sb, grp, page_pool);
1109 }
1110}
1111
1112static void z_erofs_vle_unzip_wq(struct work_struct *work)
1113{
1114 struct z_erofs_vle_unzip_io_sb *iosb = container_of(work,
1115 struct z_erofs_vle_unzip_io_sb, io.u.work);
1116 LIST_HEAD(page_pool);
1117
1118 DBG_BUGON(iosb->io.head == Z_EROFS_VLE_WORKGRP_TAIL_CLOSED);
1119 z_erofs_vle_unzip_all(iosb->sb, &iosb->io, &page_pool);
1120
1121 put_pages_list(&page_pool);
1122 kvfree(iosb);
1123}
1124
1125static struct page *
1126pickup_page_for_submission(struct z_erofs_vle_workgroup *grp,
1127 unsigned int nr,
1128 struct list_head *pagepool,
1129 struct address_space *mc,
1130 gfp_t gfp)
1131{
1132 /* determined at compile time to avoid too many #ifdefs */
1133 const bool nocache = __builtin_constant_p(mc) ? !mc : false;
1134 const pgoff_t index = grp->obj.index;
1135 bool tocache = false;
1136
1137 struct address_space *mapping;
1138 struct page *oldpage, *page;
1139
1140 compressed_page_t t;
1141 int justfound;
1142
1143repeat:
1144 page = READ_ONCE(grp->compressed_pages[nr]);
1145 oldpage = page;
1146
1147 if (!page)
1148 goto out_allocpage;
1149
1150 /*
1151 * the cached page has not been allocated and
1152 * an placeholder is out there, prepare it now.
1153 */
1154 if (!nocache && page == PAGE_UNALLOCATED) {
1155 tocache = true;
1156 goto out_allocpage;
1157 }
1158
1159 /* process the target tagged pointer */
1160 t = tagptr_init(compressed_page_t, page);
1161 justfound = tagptr_unfold_tags(t);
1162 page = tagptr_unfold_ptr(t);
1163
1164 mapping = READ_ONCE(page->mapping);
1165
1166 /*
1167 * if managed cache is disabled, it's no way to
1168 * get such a cached-like page.
1169 */
1170 if (nocache) {
1171 /* if managed cache is disabled, it is impossible `justfound' */
1172 DBG_BUGON(justfound);
1173
1174 /* and it should be locked, not uptodate, and not truncated */
1175 DBG_BUGON(!PageLocked(page));
1176 DBG_BUGON(PageUptodate(page));
1177 DBG_BUGON(!mapping);
1178 goto out;
1179 }
1180
1181 /*
1182 * unmanaged (file) pages are all locked solidly,
1183 * therefore it is impossible for `mapping' to be NULL.
1184 */
1185 if (mapping && mapping != mc)
1186 /* ought to be unmanaged pages */
1187 goto out;
1188
1189 lock_page(page);
1190
1191 /* only true if page reclaim goes wrong, should never happen */
1192 DBG_BUGON(justfound && PagePrivate(page));
1193
1194 /* the page is still in manage cache */
1195 if (page->mapping == mc) {
1196 WRITE_ONCE(grp->compressed_pages[nr], page);
1197
1198 ClearPageError(page);
1199 if (!PagePrivate(page)) {
1200 /*
1201 * impossible to be !PagePrivate(page) for
1202 * the current restriction as well if
1203 * the page is already in compressed_pages[].
1204 */
1205 DBG_BUGON(!justfound);
1206
1207 justfound = 0;
1208 set_page_private(page, (unsigned long)grp);
1209 SetPagePrivate(page);
1210 }
1211
1212 /* no need to submit io if it is already up-to-date */
1213 if (PageUptodate(page)) {
1214 unlock_page(page);
1215 page = NULL;
1216 }
1217 goto out;
1218 }
1219
1220 /*
1221 * the managed page has been truncated, it's unsafe to
1222 * reuse this one, let's allocate a new cache-managed page.
1223 */
1224 DBG_BUGON(page->mapping);
1225 DBG_BUGON(!justfound);
1226
1227 tocache = true;
1228 unlock_page(page);
1229 put_page(page);
1230out_allocpage:
1231 page = __stagingpage_alloc(pagepool, gfp);
1232 if (oldpage != cmpxchg(&grp->compressed_pages[nr], oldpage, page)) {
1233 list_add(&page->lru, pagepool);
1234 cpu_relax();
1235 goto repeat;
1236 }
1237 if (nocache || !tocache)
1238 goto out;
1239 if (add_to_page_cache_lru(page, mc, index + nr, gfp)) {
1240 page->mapping = Z_EROFS_MAPPING_STAGING;
1241 goto out;
1242 }
1243
1244 set_page_private(page, (unsigned long)grp);
1245 SetPagePrivate(page);
1246out: /* the only exit (for tracing and debugging) */
1247 return page;
1248}
1249
1250static struct z_erofs_vle_unzip_io *
1251jobqueue_init(struct super_block *sb,
1252 struct z_erofs_vle_unzip_io *io,
1253 bool foreground)
1254{
1255 struct z_erofs_vle_unzip_io_sb *iosb;
1256
1257 if (foreground) {
1258 /* waitqueue available for foreground io */
1259 DBG_BUGON(!io);
1260
1261 init_waitqueue_head(&io->u.wait);
1262 atomic_set(&io->pending_bios, 0);
1263 goto out;
1264 }
1265
1266 iosb = kvzalloc(sizeof(*iosb), GFP_KERNEL | __GFP_NOFAIL);
1267 DBG_BUGON(!iosb);
1268
1269 /* initialize fields in the allocated descriptor */
1270 io = &iosb->io;
1271 iosb->sb = sb;
1272 INIT_WORK(&io->u.work, z_erofs_vle_unzip_wq);
1273out:
1274 io->head = Z_EROFS_VLE_WORKGRP_TAIL_CLOSED;
1275 return io;
1276}
1277
1278/* define workgroup jobqueue types */
1279enum {
1280#ifdef EROFS_FS_HAS_MANAGED_CACHE
1281 JQ_BYPASS,
1282#endif
1283 JQ_SUBMIT,
1284 NR_JOBQUEUES,
1285};
1286
1287static void *jobqueueset_init(struct super_block *sb,
1288 z_erofs_vle_owned_workgrp_t qtail[],
1289 struct z_erofs_vle_unzip_io *q[],
1290 struct z_erofs_vle_unzip_io *fgq,
1291 bool forcefg)
1292{
1293#ifdef EROFS_FS_HAS_MANAGED_CACHE
1294 /*
1295 * if managed cache is enabled, bypass jobqueue is needed,
1296 * no need to read from device for all workgroups in this queue.
1297 */
1298 q[JQ_BYPASS] = jobqueue_init(sb, fgq + JQ_BYPASS, true);
1299 qtail[JQ_BYPASS] = &q[JQ_BYPASS]->head;
1300#endif
1301
1302 q[JQ_SUBMIT] = jobqueue_init(sb, fgq + JQ_SUBMIT, forcefg);
1303 qtail[JQ_SUBMIT] = &q[JQ_SUBMIT]->head;
1304
1305 return tagptr_cast_ptr(tagptr_fold(tagptr1_t, q[JQ_SUBMIT], !forcefg));
1306}
1307
1308#ifdef EROFS_FS_HAS_MANAGED_CACHE
1309static void move_to_bypass_jobqueue(struct z_erofs_vle_workgroup *grp,
1310 z_erofs_vle_owned_workgrp_t qtail[],
1311 z_erofs_vle_owned_workgrp_t owned_head)
1312{
1313 z_erofs_vle_owned_workgrp_t *const submit_qtail = qtail[JQ_SUBMIT];
1314 z_erofs_vle_owned_workgrp_t *const bypass_qtail = qtail[JQ_BYPASS];
1315
1316 DBG_BUGON(owned_head == Z_EROFS_VLE_WORKGRP_TAIL_CLOSED);
1317 if (owned_head == Z_EROFS_VLE_WORKGRP_TAIL)
1318 owned_head = Z_EROFS_VLE_WORKGRP_TAIL_CLOSED;
1319
1320 WRITE_ONCE(grp->next, Z_EROFS_VLE_WORKGRP_TAIL_CLOSED);
1321
1322 WRITE_ONCE(*submit_qtail, owned_head);
1323 WRITE_ONCE(*bypass_qtail, &grp->next);
1324
1325 qtail[JQ_BYPASS] = &grp->next;
1326}
1327
1328static bool postsubmit_is_all_bypassed(struct z_erofs_vle_unzip_io *q[],
1329 unsigned int nr_bios,
1330 bool force_fg)
1331{
1332 /*
1333 * although background is preferred, no one is pending for submission.
1334 * don't issue workqueue for decompression but drop it directly instead.
1335 */
1336 if (force_fg || nr_bios)
1337 return false;
1338
1339 kvfree(container_of(q[JQ_SUBMIT],
1340 struct z_erofs_vle_unzip_io_sb,
1341 io));
1342 return true;
1343}
1344#else
1345static void move_to_bypass_jobqueue(struct z_erofs_vle_workgroup *grp,
1346 z_erofs_vle_owned_workgrp_t qtail[],
1347 z_erofs_vle_owned_workgrp_t owned_head)
1348{
1349 /* impossible to bypass submission for managed cache disabled */
1350 DBG_BUGON(1);
1351}
1352
1353static bool postsubmit_is_all_bypassed(struct z_erofs_vle_unzip_io *q[],
1354 unsigned int nr_bios,
1355 bool force_fg)
1356{
1357 /* bios should be >0 if managed cache is disabled */
1358 DBG_BUGON(!nr_bios);
1359 return false;
1360}
1361#endif
1362
1363static bool z_erofs_vle_submit_all(struct super_block *sb,
1364 z_erofs_vle_owned_workgrp_t owned_head,
1365 struct list_head *pagepool,
1366 struct z_erofs_vle_unzip_io *fgq,
1367 bool force_fg)
1368{
1369 struct erofs_sb_info *const sbi = EROFS_SB(sb);
1370 const unsigned int clusterpages = erofs_clusterpages(sbi);
1371 const gfp_t gfp = GFP_NOFS;
1372
1373 z_erofs_vle_owned_workgrp_t qtail[NR_JOBQUEUES];
1374 struct z_erofs_vle_unzip_io *q[NR_JOBQUEUES];
1375 struct bio *bio;
1376 void *bi_private;
1377 /* since bio will be NULL, no need to initialize last_index */
1378 pgoff_t uninitialized_var(last_index);
1379 bool force_submit = false;
1380 unsigned int nr_bios;
1381
1382 if (unlikely(owned_head == Z_EROFS_VLE_WORKGRP_TAIL))
1383 return false;
1384
1385 force_submit = false;
1386 bio = NULL;
1387 nr_bios = 0;
1388 bi_private = jobqueueset_init(sb, qtail, q, fgq, force_fg);
1389
1390 /* by default, all need io submission */
1391 q[JQ_SUBMIT]->head = owned_head;
1392
1393 do {
1394 struct z_erofs_vle_workgroup *grp;
1395 pgoff_t first_index;
1396 struct page *page;
1397 unsigned int i = 0, bypass = 0;
1398 int err;
1399
1400 /* no possible 'owned_head' equals the following */
1401 DBG_BUGON(owned_head == Z_EROFS_VLE_WORKGRP_TAIL_CLOSED);
1402 DBG_BUGON(owned_head == Z_EROFS_VLE_WORKGRP_NIL);
1403
1404 grp = container_of(owned_head,
1405 struct z_erofs_vle_workgroup, next);
1406
1407 /* close the main owned chain at first */
1408 owned_head = cmpxchg(&grp->next, Z_EROFS_VLE_WORKGRP_TAIL,
1409 Z_EROFS_VLE_WORKGRP_TAIL_CLOSED);
1410
1411 first_index = grp->obj.index;
1412 force_submit |= (first_index != last_index + 1);
1413
1414repeat:
1415 page = pickup_page_for_submission(grp, i, pagepool,
1416 MNGD_MAPPING(sbi), gfp);
1417 if (!page) {
1418 force_submit = true;
1419 ++bypass;
1420 goto skippage;
1421 }
1422
1423 if (bio && force_submit) {
1424submit_bio_retry:
1425 __submit_bio(bio, REQ_OP_READ, 0);
1426 bio = NULL;
1427 }
1428
1429 if (!bio) {
1430 bio = erofs_grab_bio(sb, first_index + i,
1431 BIO_MAX_PAGES, bi_private,
1432 z_erofs_vle_read_endio, true);
1433 ++nr_bios;
1434 }
1435
1436 err = bio_add_page(bio, page, PAGE_SIZE, 0);
1437 if (err < PAGE_SIZE)
1438 goto submit_bio_retry;
1439
1440 force_submit = false;
1441 last_index = first_index + i;
1442skippage:
1443 if (++i < clusterpages)
1444 goto repeat;
1445
1446 if (bypass < clusterpages)
1447 qtail[JQ_SUBMIT] = &grp->next;
1448 else
1449 move_to_bypass_jobqueue(grp, qtail, owned_head);
1450 } while (owned_head != Z_EROFS_VLE_WORKGRP_TAIL);
1451
1452 if (bio)
1453 __submit_bio(bio, REQ_OP_READ, 0);
1454
1455 if (postsubmit_is_all_bypassed(q, nr_bios, force_fg))
1456 return true;
1457
1458 z_erofs_vle_unzip_kickoff(bi_private, nr_bios);
1459 return true;
1460}
1461
1462static void z_erofs_submit_and_unzip(struct z_erofs_vle_frontend *f,
1463 struct list_head *pagepool,
1464 bool force_fg)
1465{
1466 struct super_block *sb = f->inode->i_sb;
1467 struct z_erofs_vle_unzip_io io[NR_JOBQUEUES];
1468
1469 if (!z_erofs_vle_submit_all(sb, f->owned_head, pagepool, io, force_fg))
1470 return;
1471
1472#ifdef EROFS_FS_HAS_MANAGED_CACHE
1473 z_erofs_vle_unzip_all(sb, &io[JQ_BYPASS], pagepool);
1474#endif
1475 if (!force_fg)
1476 return;
1477
1478 /* wait until all bios are completed */
1479 wait_event(io[JQ_SUBMIT].u.wait,
1480 !atomic_read(&io[JQ_SUBMIT].pending_bios));
1481
1482 /* let's synchronous decompression */
1483 z_erofs_vle_unzip_all(sb, &io[JQ_SUBMIT], pagepool);
1484}
1485
1486static int z_erofs_vle_normalaccess_readpage(struct file *file,
1487 struct page *page)
1488{
1489 struct inode *const inode = page->mapping->host;
1490 struct z_erofs_vle_frontend f = VLE_FRONTEND_INIT(inode);
1491 int err;
1492 LIST_HEAD(pagepool);
1493
1494 trace_erofs_readpage(page, false);
1495
1496 f.headoffset = (erofs_off_t)page->index << PAGE_SHIFT;
1497
1498 err = z_erofs_do_read_page(&f, page, &pagepool);
1499 (void)z_erofs_vle_work_iter_end(&f.builder);
1500
1501 if (err) {
1502 errln("%s, failed to read, err [%d]", __func__, err);
1503 goto out;
1504 }
1505
1506 z_erofs_submit_and_unzip(&f, &pagepool, true);
1507out:
1508 if (f.map.mpage)
1509 put_page(f.map.mpage);
1510
1511 /* clean up the remaining free pages */
1512 put_pages_list(&pagepool);
1513 return 0;
1514}
1515
1516static int z_erofs_vle_normalaccess_readpages(struct file *filp,
1517 struct address_space *mapping,
1518 struct list_head *pages,
1519 unsigned int nr_pages)
1520{
1521 struct inode *const inode = mapping->host;
1522 struct erofs_sb_info *const sbi = EROFS_I_SB(inode);
1523
1524 bool sync = __should_decompress_synchronously(sbi, nr_pages);
1525 struct z_erofs_vle_frontend f = VLE_FRONTEND_INIT(inode);
1526 gfp_t gfp = mapping_gfp_constraint(mapping, GFP_KERNEL);
1527 struct page *head = NULL;
1528 LIST_HEAD(pagepool);
1529
1530 trace_erofs_readpages(mapping->host, lru_to_page(pages),
1531 nr_pages, false);
1532
1533 f.headoffset = (erofs_off_t)lru_to_page(pages)->index << PAGE_SHIFT;
1534
1535 for (; nr_pages; --nr_pages) {
1536 struct page *page = lru_to_page(pages);
1537
1538 prefetchw(&page->flags);
1539 list_del(&page->lru);
1540
1541 /*
1542 * A pure asynchronous readahead is indicated if
1543 * a PG_readahead marked page is hitted at first.
1544 * Let's also do asynchronous decompression for this case.
1545 */
1546 sync &= !(PageReadahead(page) && !head);
1547
1548 if (add_to_page_cache_lru(page, mapping, page->index, gfp)) {
1549 list_add(&page->lru, &pagepool);
1550 continue;
1551 }
1552
1553 set_page_private(page, (unsigned long)head);
1554 head = page;
1555 }
1556
1557 while (head) {
1558 struct page *page = head;
1559 int err;
1560
1561 /* traversal in reverse order */
1562 head = (void *)page_private(page);
1563
1564 err = z_erofs_do_read_page(&f, page, &pagepool);
1565 if (err) {
1566 struct erofs_vnode *vi = EROFS_V(inode);
1567
1568 errln("%s, readahead error at page %lu of nid %llu",
1569 __func__, page->index, vi->nid);
1570 }
1571
1572 put_page(page);
1573 }
1574
1575 (void)z_erofs_vle_work_iter_end(&f.builder);
1576
1577 z_erofs_submit_and_unzip(&f, &pagepool, sync);
1578
1579 if (f.map.mpage)
1580 put_page(f.map.mpage);
1581
1582 /* clean up the remaining free pages */
1583 put_pages_list(&pagepool);
1584 return 0;
1585}
1586
1587const struct address_space_operations z_erofs_vle_normalaccess_aops = {
1588 .readpage = z_erofs_vle_normalaccess_readpage,
1589 .readpages = z_erofs_vle_normalaccess_readpages,
1590};
1591
diff --git a/drivers/staging/exfat/Kconfig b/drivers/staging/exfat/Kconfig
new file mode 100644
index 000000000000..290dbfc7ace1
--- /dev/null
+++ b/drivers/staging/exfat/Kconfig
@@ -0,0 +1,49 @@
1config EXFAT_FS
2 tristate "exFAT fs support"
3 depends on BLOCK
4 select NLS
5 help
6 This adds support for the exFAT file system.
7
8config EXFAT_DONT_MOUNT_VFAT
9 bool "Prohibit mounting of fat/vfat filesysems by exFAT"
10 depends on EXFAT_FS
11 default y
12 help
13 By default, the exFAT driver will only mount exFAT filesystems, and refuse
14 to mount fat/vfat filesystems. Set this to 'n' to allow the exFAT driver
15 to mount these filesystems.
16
17config EXFAT_DISCARD
18 bool "enable discard support"
19 depends on EXFAT_FS
20 default y
21
22config EXFAT_DELAYED_SYNC
23 bool "enable delayed sync"
24 depends on EXFAT_FS
25 default n
26
27config EXFAT_KERNEL_DEBUG
28 bool "enable kernel debug features via ioctl"
29 depends on EXFAT_FS
30 default n
31
32config EXFAT_DEBUG_MSG
33 bool "print debug messages"
34 depends on EXFAT_FS
35 default n
36
37config EXFAT_DEFAULT_CODEPAGE
38 int "Default codepage for exFAT"
39 default 437
40 depends on EXFAT_FS
41 help
42 This option should be set to the codepage of your exFAT filesystems.
43
44config EXFAT_DEFAULT_IOCHARSET
45 string "Default iocharset for exFAT"
46 default "utf8"
47 depends on EXFAT_FS
48 help
49 Set this to the default input/output character set you'd like exFAT to use.
diff --git a/drivers/staging/exfat/Makefile b/drivers/staging/exfat/Makefile
new file mode 100644
index 000000000000..84944dfbae28
--- /dev/null
+++ b/drivers/staging/exfat/Makefile
@@ -0,0 +1,10 @@
1# SPDX-License-Identifier: GPL-2.0
2
3obj-$(CONFIG_EXFAT_FS) += exfat.o
4
5exfat-y := exfat_core.o \
6 exfat_super.o \
7 exfat_blkdev.o \
8 exfat_cache.o \
9 exfat_nls.o \
10 exfat_upcase.o
diff --git a/drivers/staging/exfat/TODO b/drivers/staging/exfat/TODO
new file mode 100644
index 000000000000..a3eb282f9efc
--- /dev/null
+++ b/drivers/staging/exfat/TODO
@@ -0,0 +1,12 @@
1exfat_core.c - ffsReadFile - the goto err_out seem to leak a brelse().
2same for ffsWriteFile.
3
4exfat_core.c - fs_sync(sb,0) all over the place looks fishy as hell.
5There's only one place that calls it with a non-zero argument.
6
7ffsTruncateFile - if (old_size <= new_size) {
8That doesn't look right. How did it ever work? Are they relying on lazy
9block allocation when actual writes happen? If nothing else, it never
10does the 'fid->size = new_size' and do the inode update....
11
12ffsSetAttr() is just dangling in the breeze, not wired up at all...
diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
new file mode 100644
index 000000000000..6c12f2d79f4d
--- /dev/null
+++ b/drivers/staging/exfat/exfat.h
@@ -0,0 +1,971 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */
5
6#ifndef _EXFAT_H
7#define _EXFAT_H
8
9#include <linux/types.h>
10#include <linux/buffer_head.h>
11
12#ifdef CONFIG_EXFAT_KERNEL_DEBUG
13 /* For Debugging Purpose */
14 /* IOCTL code 'f' used by
15 * - file systems typically #0~0x1F
16 * - embedded terminal devices #128~
17 * - exts for debugging purpose #99
18 * number 100 and 101 is available now but has possible conflicts
19 */
20#define EXFAT_IOC_GET_DEBUGFLAGS _IOR('f', 100, long)
21#define EXFAT_IOC_SET_DEBUGFLAGS _IOW('f', 101, long)
22
23#define EXFAT_DEBUGFLAGS_INVALID_UMOUNT 0x01
24#define EXFAT_DEBUGFLAGS_ERROR_RW 0x02
25#endif /* CONFIG_EXFAT_KERNEL_DEBUG */
26
27#ifdef CONFIG_EXFAT_DEBUG_MSG
28#define DEBUG 1
29#else
30#undef DEBUG
31#endif
32
33#define DENTRY_SIZE 32 /* dir entry size */
34#define DENTRY_SIZE_BITS 5
35
36/* PBR entries */
37#define PBR_SIGNATURE 0xAA55
38#define EXT_SIGNATURE 0xAA550000
39#define VOL_LABEL "NO NAME " /* size should be 11 */
40#define OEM_NAME "MSWIN4.1" /* size should be 8 */
41#define STR_FAT12 "FAT12 " /* size should be 8 */
42#define STR_FAT16 "FAT16 " /* size should be 8 */
43#define STR_FAT32 "FAT32 " /* size should be 8 */
44#define STR_EXFAT "EXFAT " /* size should be 8 */
45#define VOL_CLEAN 0x0000
46#define VOL_DIRTY 0x0002
47
48/* max number of clusters */
49#define FAT12_THRESHOLD 4087 /* 2^12 - 1 + 2 (clu 0 & 1) */
50#define FAT16_THRESHOLD 65527 /* 2^16 - 1 + 2 */
51#define FAT32_THRESHOLD 268435457 /* 2^28 - 1 + 2 */
52#define EXFAT_THRESHOLD 268435457 /* 2^28 - 1 + 2 */
53
54/* file types */
55#define TYPE_UNUSED 0x0000
56#define TYPE_DELETED 0x0001
57#define TYPE_INVALID 0x0002
58#define TYPE_CRITICAL_PRI 0x0100
59#define TYPE_BITMAP 0x0101
60#define TYPE_UPCASE 0x0102
61#define TYPE_VOLUME 0x0103
62#define TYPE_DIR 0x0104
63#define TYPE_FILE 0x011F
64#define TYPE_SYMLINK 0x015F
65#define TYPE_CRITICAL_SEC 0x0200
66#define TYPE_STREAM 0x0201
67#define TYPE_EXTEND 0x0202
68#define TYPE_ACL 0x0203
69#define TYPE_BENIGN_PRI 0x0400
70#define TYPE_GUID 0x0401
71#define TYPE_PADDING 0x0402
72#define TYPE_ACLTAB 0x0403
73#define TYPE_BENIGN_SEC 0x0800
74#define TYPE_ALL 0x0FFF
75
76/* time modes */
77#define TM_CREATE 0
78#define TM_MODIFY 1
79#define TM_ACCESS 2
80
81/* checksum types */
82#define CS_DIR_ENTRY 0
83#define CS_PBR_SECTOR 1
84#define CS_DEFAULT 2
85
86#define CLUSTER_16(x) ((u16)(x))
87#define CLUSTER_32(x) ((u32)(x))
88
89#define START_SECTOR(x) \
90 ((((sector_t)((x) - 2)) << p_fs->sectors_per_clu_bits) + \
91 p_fs->data_start_sector)
92
93#define IS_LAST_SECTOR_IN_CLUSTER(sec) \
94 ((((sec) - p_fs->data_start_sector + 1) & \
95 ((1 << p_fs->sectors_per_clu_bits) - 1)) == 0)
96
97#define GET_CLUSTER_FROM_SECTOR(sec) \
98 ((u32)((((sec) - p_fs->data_start_sector) >> \
99 p_fs->sectors_per_clu_bits) + 2))
100
101#define GET16(p_src) \
102 (((u16)(p_src)[0]) | (((u16)(p_src)[1]) << 8))
103#define GET32(p_src) \
104 (((u32)(p_src)[0]) | (((u32)(p_src)[1]) << 8) | \
105 (((u32)(p_src)[2]) << 16) | (((u32)(p_src)[3]) << 24))
106#define GET64(p_src) \
107 (((u64)(p_src)[0]) | (((u64)(p_src)[1]) << 8) | \
108 (((u64)(p_src)[2]) << 16) | (((u64)(p_src)[3]) << 24) | \
109 (((u64)(p_src)[4]) << 32) | (((u64)(p_src)[5]) << 40) | \
110 (((u64)(p_src)[6]) << 48) | (((u64)(p_src)[7]) << 56))
111
112#define SET16(p_dst, src) \
113 do { \
114 (p_dst)[0] = (u8)(src); \
115 (p_dst)[1] = (u8)(((u16)(src)) >> 8); \
116 } while (0)
117#define SET32(p_dst, src) \
118 do { \
119 (p_dst)[0] = (u8)(src); \
120 (p_dst)[1] = (u8)(((u32)(src)) >> 8); \
121 (p_dst)[2] = (u8)(((u32)(src)) >> 16); \
122 (p_dst)[3] = (u8)(((u32)(src)) >> 24); \
123 } while (0)
124#define SET64(p_dst, src) \
125 do { \
126 (p_dst)[0] = (u8)(src); \
127 (p_dst)[1] = (u8)(((u64)(src)) >> 8); \
128 (p_dst)[2] = (u8)(((u64)(src)) >> 16); \
129 (p_dst)[3] = (u8)(((u64)(src)) >> 24); \
130 (p_dst)[4] = (u8)(((u64)(src)) >> 32); \
131 (p_dst)[5] = (u8)(((u64)(src)) >> 40); \
132 (p_dst)[6] = (u8)(((u64)(src)) >> 48); \
133 (p_dst)[7] = (u8)(((u64)(src)) >> 56); \
134 } while (0)
135
136#ifdef __LITTLE_ENDIAN
137#define GET16_A(p_src) (*((u16 *)(p_src)))
138#define GET32_A(p_src) (*((u32 *)(p_src)))
139#define GET64_A(p_src) (*((u64 *)(p_src)))
140#define SET16_A(p_dst, src) (*((u16 *)(p_dst)) = (u16)(src))
141#define SET32_A(p_dst, src) (*((u32 *)(p_dst)) = (u32)(src))
142#define SET64_A(p_dst, src) (*((u64 *)(p_dst)) = (u64)(src))
143#else /* BIG_ENDIAN */
144#define GET16_A(p_src) GET16(p_src)
145#define GET32_A(p_src) GET32(p_src)
146#define GET64_A(p_src) GET64(p_src)
147#define SET16_A(p_dst, src) SET16(p_dst, src)
148#define SET32_A(p_dst, src) SET32(p_dst, src)
149#define SET64_A(p_dst, src) SET64(p_dst, src)
150#endif
151
152/* cache size (in number of sectors) */
153/* (should be an exponential value of 2) */
154#define FAT_CACHE_SIZE 128
155#define FAT_CACHE_HASH_SIZE 64
156#define BUF_CACHE_SIZE 256
157#define BUF_CACHE_HASH_SIZE 64
158
159/* Upcase table macro */
160#define HIGH_INDEX_BIT (8)
161#define HIGH_INDEX_MASK (0xFF00)
162#define LOW_INDEX_BIT (16 - HIGH_INDEX_BIT)
163#define UTBL_ROW_COUNT BIT(LOW_INDEX_BIT)
164#define UTBL_COL_COUNT BIT(HIGH_INDEX_BIT)
165
166static inline u16 get_col_index(u16 i)
167{
168 return i >> LOW_INDEX_BIT;
169}
170
171static inline u16 get_row_index(u16 i)
172{
173 return i & ~HIGH_INDEX_MASK;
174}
175
176#define EXFAT_SUPER_MAGIC (0x2011BAB0L)
177#define EXFAT_ROOT_INO 1
178
179/* FAT types */
180#define FAT12 0x01 /* FAT12 */
181#define FAT16 0x0E /* Win95 FAT16 (LBA) */
182#define FAT32 0x0C /* Win95 FAT32 (LBA) */
183#define EXFAT 0x07 /* exFAT */
184
185/* file name lengths */
186#define MAX_CHARSET_SIZE 3 /* max size of multi-byte character */
187#define MAX_PATH_DEPTH 15 /* max depth of path name */
188#define MAX_NAME_LENGTH 256 /* max len of filename including NULL */
189#define MAX_PATH_LENGTH 260 /* max len of pathname including NULL */
190#define DOS_NAME_LENGTH 11 /* DOS filename length excluding NULL */
191#define DOS_PATH_LENGTH 80 /* DOS pathname length excluding NULL */
192
193/* file attributes */
194#define ATTR_NORMAL 0x0000
195#define ATTR_READONLY 0x0001
196#define ATTR_HIDDEN 0x0002
197#define ATTR_SYSTEM 0x0004
198#define ATTR_VOLUME 0x0008
199#define ATTR_SUBDIR 0x0010
200#define ATTR_ARCHIVE 0x0020
201#define ATTR_SYMLINK 0x0040
202#define ATTR_EXTEND 0x000F
203#define ATTR_RWMASK 0x007E
204
205/* file creation modes */
206#define FM_REGULAR 0x00
207#define FM_SYMLINK 0x40
208
209/* return values */
210#define FFS_SUCCESS 0
211#define FFS_MEDIAERR 1
212#define FFS_FORMATERR 2
213#define FFS_MOUNTED 3
214#define FFS_NOTMOUNTED 4
215#define FFS_ALIGNMENTERR 5
216#define FFS_SEMAPHOREERR 6
217#define FFS_INVALIDPATH 7
218#define FFS_INVALIDFID 8
219#define FFS_NOTFOUND 9
220#define FFS_FILEEXIST 10
221#define FFS_PERMISSIONERR 11
222#define FFS_NOTOPENED 12
223#define FFS_MAXOPENED 13
224#define FFS_FULL 14
225#define FFS_EOF 15
226#define FFS_DIRBUSY 16
227#define FFS_MEMORYERR 17
228#define FFS_NAMETOOLONG 18
229#define FFS_ERROR 19
230
231#define NUM_UPCASE 2918
232
233#define DOS_CUR_DIR_NAME ". "
234#define DOS_PAR_DIR_NAME ".. "
235
236#ifdef __LITTLE_ENDIAN
237#define UNI_CUR_DIR_NAME ".\0"
238#define UNI_PAR_DIR_NAME ".\0.\0"
239#else
240#define UNI_CUR_DIR_NAME "\0."
241#define UNI_PAR_DIR_NAME "\0.\0."
242#endif
243
244struct date_time_t {
245 u16 Year;
246 u16 Month;
247 u16 Day;
248 u16 Hour;
249 u16 Minute;
250 u16 Second;
251 u16 MilliSecond;
252};
253
254struct part_info_t {
255 u32 Offset; /* start sector number of the partition */
256 u32 Size; /* in sectors */
257};
258
259struct dev_info_t {
260 u32 SecSize; /* sector size in bytes */
261 u32 DevSize; /* block device size in sectors */
262};
263
264struct vol_info_t {
265 u32 FatType;
266 u32 ClusterSize;
267 u32 NumClusters;
268 u32 FreeClusters;
269 u32 UsedClusters;
270};
271
272/* directory structure */
273struct chain_t {
274 u32 dir;
275 s32 size;
276 u8 flags;
277};
278
279struct file_id_t {
280 struct chain_t dir;
281 s32 entry;
282 u32 type;
283 u32 attr;
284 u32 start_clu;
285 u64 size;
286 u8 flags;
287 s64 rwoffset;
288 s32 hint_last_off;
289 u32 hint_last_clu;
290};
291
292struct dir_entry_t {
293 char Name[MAX_NAME_LENGTH * MAX_CHARSET_SIZE];
294
295 /* used only for FAT12/16/32, not used for exFAT */
296 char ShortName[DOS_NAME_LENGTH + 2];
297
298 u32 Attr;
299 u64 Size;
300 u32 NumSubdirs;
301 struct date_time_t CreateTimestamp;
302 struct date_time_t ModifyTimestamp;
303 struct date_time_t AccessTimestamp;
304};
305
306struct timestamp_t {
307 u16 sec; /* 0 ~ 59 */
308 u16 min; /* 0 ~ 59 */
309 u16 hour; /* 0 ~ 23 */
310 u16 day; /* 1 ~ 31 */
311 u16 mon; /* 1 ~ 12 */
312 u16 year; /* 0 ~ 127 (since 1980) */
313};
314
315/* MS_DOS FAT partition boot record (512 bytes) */
316struct pbr_sector_t {
317 u8 jmp_boot[3];
318 u8 oem_name[8];
319 u8 bpb[109];
320 u8 boot_code[390];
321 u8 signature[2];
322};
323
324/* MS-DOS FAT12/16 BIOS parameter block (51 bytes) */
325struct bpb16_t {
326 u8 sector_size[2];
327 u8 sectors_per_clu;
328 u8 num_reserved[2];
329 u8 num_fats;
330 u8 num_root_entries[2];
331 u8 num_sectors[2];
332 u8 media_type;
333 u8 num_fat_sectors[2];
334 u8 sectors_in_track[2];
335 u8 num_heads[2];
336 u8 num_hid_sectors[4];
337 u8 num_huge_sectors[4];
338
339 u8 phy_drv_no;
340 u8 reserved;
341 u8 ext_signature;
342 u8 vol_serial[4];
343 u8 vol_label[11];
344 u8 vol_type[8];
345};
346
347/* MS-DOS FAT32 BIOS parameter block (79 bytes) */
348struct bpb32_t {
349 u8 sector_size[2];
350 u8 sectors_per_clu;
351 u8 num_reserved[2];
352 u8 num_fats;
353 u8 num_root_entries[2];
354 u8 num_sectors[2];
355 u8 media_type;
356 u8 num_fat_sectors[2];
357 u8 sectors_in_track[2];
358 u8 num_heads[2];
359 u8 num_hid_sectors[4];
360 u8 num_huge_sectors[4];
361 u8 num_fat32_sectors[4];
362 u8 ext_flags[2];
363 u8 fs_version[2];
364 u8 root_cluster[4];
365 u8 fsinfo_sector[2];
366 u8 backup_sector[2];
367 u8 reserved[12];
368
369 u8 phy_drv_no;
370 u8 ext_reserved;
371 u8 ext_signature;
372 u8 vol_serial[4];
373 u8 vol_label[11];
374 u8 vol_type[8];
375};
376
377/* MS-DOS EXFAT BIOS parameter block (109 bytes) */
378struct bpbex_t {
379 u8 reserved1[53];
380 u8 vol_offset[8];
381 u8 vol_length[8];
382 u8 fat_offset[4];
383 u8 fat_length[4];
384 u8 clu_offset[4];
385 u8 clu_count[4];
386 u8 root_cluster[4];
387 u8 vol_serial[4];
388 u8 fs_version[2];
389 u8 vol_flags[2];
390 u8 sector_size_bits;
391 u8 sectors_per_clu_bits;
392 u8 num_fats;
393 u8 phy_drv_no;
394 u8 perc_in_use;
395 u8 reserved2[7];
396};
397
398/* MS-DOS FAT file system information sector (512 bytes) */
399struct fsi_sector_t {
400 u8 signature1[4];
401 u8 reserved1[480];
402 u8 signature2[4];
403 u8 free_cluster[4];
404 u8 next_cluster[4];
405 u8 reserved2[14];
406 u8 signature3[2];
407};
408
409/* MS-DOS FAT directory entry (32 bytes) */
410struct dentry_t {
411 u8 dummy[32];
412};
413
414struct dos_dentry_t {
415 u8 name[DOS_NAME_LENGTH];
416 u8 attr;
417 u8 lcase;
418 u8 create_time_ms;
419 u8 create_time[2];
420 u8 create_date[2];
421 u8 access_date[2];
422 u8 start_clu_hi[2];
423 u8 modify_time[2];
424 u8 modify_date[2];
425 u8 start_clu_lo[2];
426 u8 size[4];
427};
428
429/* MS-DOS FAT extended directory entry (32 bytes) */
430struct ext_dentry_t {
431 u8 order;
432 u8 unicode_0_4[10];
433 u8 attr;
434 u8 sysid;
435 u8 checksum;
436 u8 unicode_5_10[12];
437 u8 start_clu[2];
438 u8 unicode_11_12[4];
439};
440
441/* MS-DOS EXFAT file directory entry (32 bytes) */
442struct file_dentry_t {
443 u8 type;
444 u8 num_ext;
445 u8 checksum[2];
446 u8 attr[2];
447 u8 reserved1[2];
448 u8 create_time[2];
449 u8 create_date[2];
450 u8 modify_time[2];
451 u8 modify_date[2];
452 u8 access_time[2];
453 u8 access_date[2];
454 u8 create_time_ms;
455 u8 modify_time_ms;
456 u8 access_time_ms;
457 u8 reserved2[9];
458};
459
460/* MS-DOS EXFAT stream extension directory entry (32 bytes) */
461struct strm_dentry_t {
462 u8 type;
463 u8 flags;
464 u8 reserved1;
465 u8 name_len;
466 u8 name_hash[2];
467 u8 reserved2[2];
468 u8 valid_size[8];
469 u8 reserved3[4];
470 u8 start_clu[4];
471 u8 size[8];
472};
473
474/* MS-DOS EXFAT file name directory entry (32 bytes) */
475struct name_dentry_t {
476 u8 type;
477 u8 flags;
478 u8 unicode_0_14[30];
479};
480
481/* MS-DOS EXFAT allocation bitmap directory entry (32 bytes) */
482struct bmap_dentry_t {
483 u8 type;
484 u8 flags;
485 u8 reserved[18];
486 u8 start_clu[4];
487 u8 size[8];
488};
489
490/* MS-DOS EXFAT up-case table directory entry (32 bytes) */
491struct case_dentry_t {
492 u8 type;
493 u8 reserved1[3];
494 u8 checksum[4];
495 u8 reserved2[12];
496 u8 start_clu[4];
497 u8 size[8];
498};
499
500/* MS-DOS EXFAT volume label directory entry (32 bytes) */
501struct volm_dentry_t {
502 u8 type;
503 u8 label_len;
504 u8 unicode_0_10[22];
505 u8 reserved[8];
506};
507
508/* unused entry hint information */
509struct uentry_t {
510 u32 dir;
511 s32 entry;
512 struct chain_t clu;
513};
514
515/* DOS name structure */
516struct dos_name_t {
517 u8 name[DOS_NAME_LENGTH];
518 u8 name_case;
519};
520
521/* unicode name structure */
522struct uni_name_t {
523 u16 name[MAX_NAME_LENGTH];
524 u16 name_hash;
525 u8 name_len;
526};
527
528struct buf_cache_t {
529 struct buf_cache_t *next;
530 struct buf_cache_t *prev;
531 struct buf_cache_t *hash_next;
532 struct buf_cache_t *hash_prev;
533 s32 drv;
534 sector_t sec;
535 u32 flag;
536 struct buffer_head *buf_bh;
537};
538
539struct fs_func {
540 s32 (*alloc_cluster)(struct super_block *sb, s32 num_alloc,
541 struct chain_t *p_chain);
542 void (*free_cluster)(struct super_block *sb, struct chain_t *p_chain,
543 s32 do_relse);
544 s32 (*count_used_clusters)(struct super_block *sb);
545
546 s32 (*init_dir_entry)(struct super_block *sb, struct chain_t *p_dir,
547 s32 entry, u32 type, u32 start_clu, u64 size);
548 s32 (*init_ext_entry)(struct super_block *sb, struct chain_t *p_dir,
549 s32 entry, s32 num_entries,
550 struct uni_name_t *p_uniname,
551 struct dos_name_t *p_dosname);
552 s32 (*find_dir_entry)(struct super_block *sb, struct chain_t *p_dir,
553 struct uni_name_t *p_uniname, s32 num_entries,
554 struct dos_name_t *p_dosname, u32 type);
555 void (*delete_dir_entry)(struct super_block *sb,
556 struct chain_t *p_dir, s32 entry,
557 s32 offset, s32 num_entries);
558 void (*get_uni_name_from_ext_entry)(struct super_block *sb,
559 struct chain_t *p_dir, s32 entry,
560 u16 *uniname);
561 s32 (*count_ext_entries)(struct super_block *sb,
562 struct chain_t *p_dir, s32 entry,
563 struct dentry_t *p_entry);
564 s32 (*calc_num_entries)(struct uni_name_t *p_uniname);
565
566 u32 (*get_entry_type)(struct dentry_t *p_entry);
567 void (*set_entry_type)(struct dentry_t *p_entry, u32 type);
568 u32 (*get_entry_attr)(struct dentry_t *p_entry);
569 void (*set_entry_attr)(struct dentry_t *p_entry, u32 attr);
570 u8 (*get_entry_flag)(struct dentry_t *p_entry);
571 void (*set_entry_flag)(struct dentry_t *p_entry, u8 flag);
572 u32 (*get_entry_clu0)(struct dentry_t *p_entry);
573 void (*set_entry_clu0)(struct dentry_t *p_entry, u32 clu0);
574 u64 (*get_entry_size)(struct dentry_t *p_entry);
575 void (*set_entry_size)(struct dentry_t *p_entry, u64 size);
576 void (*get_entry_time)(struct dentry_t *p_entry,
577 struct timestamp_t *tp, u8 mode);
578 void (*set_entry_time)(struct dentry_t *p_entry,
579 struct timestamp_t *tp, u8 mode);
580};
581
582struct fs_info_t {
583 u32 drv; /* drive ID */
584 u32 vol_type; /* volume FAT type */
585 u32 vol_id; /* volume serial number */
586
587 u64 num_sectors; /* num of sectors in volume */
588 u32 num_clusters; /* num of clusters in volume */
589 u32 cluster_size; /* cluster size in bytes */
590 u32 cluster_size_bits;
591 u32 sectors_per_clu; /* cluster size in sectors */
592 u32 sectors_per_clu_bits;
593
594 u32 PBR_sector; /* PBR sector */
595 u32 FAT1_start_sector; /* FAT1 start sector */
596 u32 FAT2_start_sector; /* FAT2 start sector */
597 u32 root_start_sector; /* root dir start sector */
598 u32 data_start_sector; /* data area start sector */
599 u32 num_FAT_sectors; /* num of FAT sectors */
600
601 u32 root_dir; /* root dir cluster */
602 u32 dentries_in_root; /* num of dentries in root dir */
603 u32 dentries_per_clu; /* num of dentries per cluster */
604
605 u32 vol_flag; /* volume dirty flag */
606 struct buffer_head *pbr_bh; /* PBR sector */
607
608 u32 map_clu; /* allocation bitmap start cluster */
609 u32 map_sectors; /* num of allocation bitmap sectors */
610 struct buffer_head **vol_amap; /* allocation bitmap */
611
612 u16 **vol_utbl; /* upcase table */
613
614 u32 clu_srch_ptr; /* cluster search pointer */
615 u32 used_clusters; /* number of used clusters */
616 struct uentry_t hint_uentry; /* unused entry hint information */
617
618 u32 dev_ejected; /* block device operation error flag */
619
620 struct fs_func *fs_func;
621 struct semaphore v_sem;
622
623 /* FAT cache */
624 struct buf_cache_t FAT_cache_array[FAT_CACHE_SIZE];
625 struct buf_cache_t FAT_cache_lru_list;
626 struct buf_cache_t FAT_cache_hash_list[FAT_CACHE_HASH_SIZE];
627
628 /* buf cache */
629 struct buf_cache_t buf_cache_array[BUF_CACHE_SIZE];
630 struct buf_cache_t buf_cache_lru_list;
631 struct buf_cache_t buf_cache_hash_list[BUF_CACHE_HASH_SIZE];
632};
633
634#define ES_2_ENTRIES 2
635#define ES_3_ENTRIES 3
636#define ES_ALL_ENTRIES 0
637
638struct entry_set_cache_t {
639 /* sector number that contains file_entry */
640 sector_t sector;
641
642 /* byte offset in the sector */
643 s32 offset;
644
645 /*
646 * flag in stream entry.
647 * 01 for cluster chain,
648 * 03 for contig. clusteres.
649 */
650 s32 alloc_flag;
651
652 u32 num_entries;
653
654 /* __buf should be the last member */
655 void *__buf;
656};
657
658#define EXFAT_ERRORS_CONT 1 /* ignore error and continue */
659#define EXFAT_ERRORS_PANIC 2 /* panic on error */
660#define EXFAT_ERRORS_RO 3 /* remount r/o on error */
661
662/* ioctl command */
663#define EXFAT_IOCTL_GET_VOLUME_ID _IOR('r', 0x12, __u32)
664
665struct exfat_mount_options {
666 kuid_t fs_uid;
667 kgid_t fs_gid;
668 unsigned short fs_fmask;
669 unsigned short fs_dmask;
670
671 /* permission for setting the [am]time */
672 unsigned short allow_utime;
673
674 /* codepage for shortname conversions */
675 unsigned short codepage;
676
677 /* charset for filename input/display */
678 char *iocharset;
679
680 unsigned char casesensitive;
681
682 /* on error: continue, panic, remount-ro */
683 unsigned char errors;
684#ifdef CONFIG_EXFAT_DISCARD
685 /* flag on if -o dicard specified and device support discard() */
686 unsigned char discard;
687#endif /* CONFIG_EXFAT_DISCARD */
688};
689
690#define EXFAT_HASH_BITS 8
691#define EXFAT_HASH_SIZE BIT(EXFAT_HASH_BITS)
692
693/*
694 * EXFAT file system in-core superblock data
695 */
696struct bd_info_t {
697 s32 sector_size; /* in bytes */
698 s32 sector_size_bits;
699 s32 sector_size_mask;
700
701 /* total number of sectors in this block device */
702 s32 num_sectors;
703
704 /* opened or not */
705 bool opened;
706};
707
708struct exfat_sb_info {
709 struct fs_info_t fs_info;
710 struct bd_info_t bd_info;
711
712 struct exfat_mount_options options;
713
714 int s_dirt;
715 struct mutex s_lock;
716 struct nls_table *nls_disk; /* Codepage used on disk */
717 struct nls_table *nls_io; /* Charset used for input and display */
718
719 struct inode *fat_inode;
720
721 spinlock_t inode_hash_lock;
722 struct hlist_head inode_hashtable[EXFAT_HASH_SIZE];
723#ifdef CONFIG_EXFAT_KERNEL_DEBUG
724 long debug_flags;
725#endif /* CONFIG_EXFAT_KERNEL_DEBUG */
726};
727
728/*
729 * EXFAT file system inode data in memory
730 */
731struct exfat_inode_info {
732 struct file_id_t fid;
733 char *target;
734 /* NOTE: mmu_private is 64bits, so must hold ->i_mutex to access */
735 loff_t mmu_private; /* physically allocated size */
736 loff_t i_pos; /* on-disk position of directory entry or 0 */
737 struct hlist_node i_hash_fat; /* hash by i_location */
738 struct rw_semaphore truncate_lock;
739 struct inode vfs_inode;
740 struct rw_semaphore i_alloc_sem; /* protect bmap against truncate */
741};
742
743#define EXFAT_SB(sb) ((struct exfat_sb_info *)((sb)->s_fs_info))
744
745static inline struct exfat_inode_info *EXFAT_I(struct inode *inode)
746{
747 return container_of(inode, struct exfat_inode_info, vfs_inode);
748}
749
750/* NLS management function */
751u16 nls_upper(struct super_block *sb, u16 a);
752int nls_dosname_cmp(struct super_block *sb, u8 *a, u8 *b);
753int nls_uniname_cmp(struct super_block *sb, u16 *a, u16 *b);
754void nls_uniname_to_dosname(struct super_block *sb,
755 struct dos_name_t *p_dosname,
756 struct uni_name_t *p_uniname, bool *p_lossy);
757void nls_dosname_to_uniname(struct super_block *sb,
758 struct uni_name_t *p_uniname,
759 struct dos_name_t *p_dosname);
760void nls_uniname_to_cstring(struct super_block *sb, u8 *p_cstring,
761 struct uni_name_t *p_uniname);
762void nls_cstring_to_uniname(struct super_block *sb,
763 struct uni_name_t *p_uniname, u8 *p_cstring,
764 bool *p_lossy);
765
766/* buffer cache management */
767void buf_init(struct super_block *sb);
768void buf_shutdown(struct super_block *sb);
769int FAT_read(struct super_block *sb, u32 loc, u32 *content);
770s32 FAT_write(struct super_block *sb, u32 loc, u32 content);
771u8 *FAT_getblk(struct super_block *sb, sector_t sec);
772void FAT_modify(struct super_block *sb, sector_t sec);
773void FAT_release_all(struct super_block *sb);
774void FAT_sync(struct super_block *sb);
775u8 *buf_getblk(struct super_block *sb, sector_t sec);
776void buf_modify(struct super_block *sb, sector_t sec);
777void buf_lock(struct super_block *sb, sector_t sec);
778void buf_unlock(struct super_block *sb, sector_t sec);
779void buf_release(struct super_block *sb, sector_t sec);
780void buf_release_all(struct super_block *sb);
781void buf_sync(struct super_block *sb);
782
783/* fs management functions */
784void fs_set_vol_flags(struct super_block *sb, u32 new_flag);
785void fs_error(struct super_block *sb);
786
787/* cluster management functions */
788s32 clear_cluster(struct super_block *sb, u32 clu);
789s32 fat_alloc_cluster(struct super_block *sb, s32 num_alloc,
790 struct chain_t *p_chain);
791s32 exfat_alloc_cluster(struct super_block *sb, s32 num_alloc,
792 struct chain_t *p_chain);
793void fat_free_cluster(struct super_block *sb, struct chain_t *p_chain,
794 s32 do_relse);
795void exfat_free_cluster(struct super_block *sb, struct chain_t *p_chain,
796 s32 do_relse);
797u32 find_last_cluster(struct super_block *sb, struct chain_t *p_chain);
798s32 count_num_clusters(struct super_block *sb, struct chain_t *dir);
799s32 fat_count_used_clusters(struct super_block *sb);
800s32 exfat_count_used_clusters(struct super_block *sb);
801void exfat_chain_cont_cluster(struct super_block *sb, u32 chain, s32 len);
802
803/* allocation bitmap management functions */
804s32 load_alloc_bitmap(struct super_block *sb);
805void free_alloc_bitmap(struct super_block *sb);
806s32 set_alloc_bitmap(struct super_block *sb, u32 clu);
807s32 clr_alloc_bitmap(struct super_block *sb, u32 clu);
808u32 test_alloc_bitmap(struct super_block *sb, u32 clu);
809void sync_alloc_bitmap(struct super_block *sb);
810
811/* upcase table management functions */
812s32 load_upcase_table(struct super_block *sb);
813void free_upcase_table(struct super_block *sb);
814
815/* dir entry management functions */
816u32 fat_get_entry_type(struct dentry_t *p_entry);
817u32 exfat_get_entry_type(struct dentry_t *p_entry);
818void fat_set_entry_type(struct dentry_t *p_entry, u32 type);
819void exfat_set_entry_type(struct dentry_t *p_entry, u32 type);
820u32 fat_get_entry_attr(struct dentry_t *p_entry);
821u32 exfat_get_entry_attr(struct dentry_t *p_entry);
822void fat_set_entry_attr(struct dentry_t *p_entry, u32 attr);
823void exfat_set_entry_attr(struct dentry_t *p_entry, u32 attr);
824u8 fat_get_entry_flag(struct dentry_t *p_entry);
825u8 exfat_get_entry_flag(struct dentry_t *p_entry);
826void fat_set_entry_flag(struct dentry_t *p_entry, u8 flag);
827void exfat_set_entry_flag(struct dentry_t *p_entry, u8 flag);
828u32 fat_get_entry_clu0(struct dentry_t *p_entry);
829u32 exfat_get_entry_clu0(struct dentry_t *p_entry);
830void fat_set_entry_clu0(struct dentry_t *p_entry, u32 start_clu);
831void exfat_set_entry_clu0(struct dentry_t *p_entry, u32 start_clu);
832u64 fat_get_entry_size(struct dentry_t *p_entry);
833u64 exfat_get_entry_size(struct dentry_t *p_entry);
834void fat_set_entry_size(struct dentry_t *p_entry, u64 size);
835void exfat_set_entry_size(struct dentry_t *p_entry, u64 size);
836struct timestamp_t *tm_current(struct timestamp_t *tm);
837void fat_get_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
838 u8 mode);
839void exfat_get_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
840 u8 mode);
841void fat_set_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
842 u8 mode);
843void exfat_set_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
844 u8 mode);
845s32 fat_init_dir_entry(struct super_block *sb, struct chain_t *p_dir, s32 entry,
846 u32 type, u32 start_clu, u64 size);
847s32 exfat_init_dir_entry(struct super_block *sb, struct chain_t *p_dir,
848 s32 entry, u32 type, u32 start_clu, u64 size);
849s32 fat_init_ext_dir_entry(struct super_block *sb, struct chain_t *p_dir,
850 s32 entry, s32 num_entries,
851 struct uni_name_t *p_uniname,
852 struct dos_name_t *p_dosname);
853s32 exfat_init_ext_dir_entry(struct super_block *sb, struct chain_t *p_dir,
854 s32 entry, s32 num_entries,
855 struct uni_name_t *p_uniname,
856 struct dos_name_t *p_dosname);
857void init_dos_entry(struct dos_dentry_t *ep, u32 type, u32 start_clu);
858void init_ext_entry(struct ext_dentry_t *ep, s32 order, u8 chksum,
859 u16 *uniname);
860void init_file_entry(struct file_dentry_t *ep, u32 type);
861void init_strm_entry(struct strm_dentry_t *ep, u8 flags, u32 start_clu,
862 u64 size);
863void init_name_entry(struct name_dentry_t *ep, u16 *uniname);
864void fat_delete_dir_entry(struct super_block *sb, struct chain_t *p_dir,
865 s32 entry, s32 order, s32 num_entries);
866void exfat_delete_dir_entry(struct super_block *sb, struct chain_t *p_dir,
867 s32 entry, s32 order, s32 num_entries);
868
869s32 find_location(struct super_block *sb, struct chain_t *p_dir, s32 entry,
870 sector_t *sector, s32 *offset);
871struct dentry_t *get_entry_with_sector(struct super_block *sb, sector_t sector,
872 s32 offset);
873struct dentry_t *get_entry_in_dir(struct super_block *sb, struct chain_t *p_dir,
874 s32 entry, sector_t *sector);
875struct entry_set_cache_t *get_entry_set_in_dir(struct super_block *sb,
876 struct chain_t *p_dir, s32 entry,
877 u32 type,
878 struct dentry_t **file_ep);
879void release_entry_set(struct entry_set_cache_t *es);
880s32 write_whole_entry_set(struct super_block *sb, struct entry_set_cache_t *es);
881s32 write_partial_entries_in_entry_set(struct super_block *sb,
882 struct entry_set_cache_t *es,
883 struct dentry_t *ep, u32 count);
884s32 search_deleted_or_unused_entry(struct super_block *sb,
885 struct chain_t *p_dir, s32 num_entries);
886s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir,
887 s32 num_entries);
888s32 fat_find_dir_entry(struct super_block *sb, struct chain_t *p_dir,
889 struct uni_name_t *p_uniname, s32 num_entries,
890 struct dos_name_t *p_dosname, u32 type);
891s32 exfat_find_dir_entry(struct super_block *sb, struct chain_t *p_dir,
892 struct uni_name_t *p_uniname, s32 num_entries,
893 struct dos_name_t *p_dosname, u32 type);
894s32 fat_count_ext_entries(struct super_block *sb, struct chain_t *p_dir,
895 s32 entry, struct dentry_t *p_entry);
896s32 exfat_count_ext_entries(struct super_block *sb, struct chain_t *p_dir,
897 s32 entry, struct dentry_t *p_entry);
898s32 count_dos_name_entries(struct super_block *sb, struct chain_t *p_dir,
899 u32 type);
900void update_dir_checksum(struct super_block *sb, struct chain_t *p_dir,
901 s32 entry);
902void update_dir_checksum_with_entry_set(struct super_block *sb,
903 struct entry_set_cache_t *es);
904bool is_dir_empty(struct super_block *sb, struct chain_t *p_dir);
905
906/* name conversion functions */
907s32 get_num_entries_and_dos_name(struct super_block *sb, struct chain_t *p_dir,
908 struct uni_name_t *p_uniname, s32 *entries,
909 struct dos_name_t *p_dosname);
910void get_uni_name_from_dos_entry(struct super_block *sb,
911 struct dos_dentry_t *ep,
912 struct uni_name_t *p_uniname, u8 mode);
913void fat_get_uni_name_from_ext_entry(struct super_block *sb,
914 struct chain_t *p_dir, s32 entry,
915 u16 *uniname);
916void exfat_get_uni_name_from_ext_entry(struct super_block *sb,
917 struct chain_t *p_dir, s32 entry,
918 u16 *uniname);
919s32 extract_uni_name_from_ext_entry(struct ext_dentry_t *ep,
920 u16 *uniname, s32 order);
921s32 extract_uni_name_from_name_entry(struct name_dentry_t *ep,
922 u16 *uniname, s32 order);
923s32 fat_generate_dos_name(struct super_block *sb, struct chain_t *p_dir,
924 struct dos_name_t *p_dosname);
925void fat_attach_count_to_dos_name(u8 *dosname, s32 count);
926s32 fat_calc_num_entries(struct uni_name_t *p_uniname);
927s32 exfat_calc_num_entries(struct uni_name_t *p_uniname);
928u8 calc_checksum_1byte(void *data, s32 len, u8 chksum);
929u16 calc_checksum_2byte(void *data, s32 len, u16 chksum, s32 type);
930u32 calc_checksum_4byte(void *data, s32 len, u32 chksum, s32 type);
931
932/* name resolution functions */
933s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir,
934 struct uni_name_t *p_uniname);
935s32 resolve_name(u8 *name, u8 **arg);
936
937/* file operation functions */
938s32 fat16_mount(struct super_block *sb, struct pbr_sector_t *p_pbr);
939s32 fat32_mount(struct super_block *sb, struct pbr_sector_t *p_pbr);
940s32 exfat_mount(struct super_block *sb, struct pbr_sector_t *p_pbr);
941s32 create_dir(struct inode *inode, struct chain_t *p_dir,
942 struct uni_name_t *p_uniname, struct file_id_t *fid);
943s32 create_file(struct inode *inode, struct chain_t *p_dir,
944 struct uni_name_t *p_uniname, u8 mode, struct file_id_t *fid);
945void remove_file(struct inode *inode, struct chain_t *p_dir, s32 entry);
946s32 rename_file(struct inode *inode, struct chain_t *p_dir, s32 old_entry,
947 struct uni_name_t *p_uniname, struct file_id_t *fid);
948s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry,
949 struct chain_t *p_newdir, struct uni_name_t *p_uniname,
950 struct file_id_t *fid);
951
952/* sector read/write functions */
953int sector_read(struct super_block *sb, sector_t sec,
954 struct buffer_head **bh, bool read);
955int sector_write(struct super_block *sb, sector_t sec,
956 struct buffer_head *bh, bool sync);
957int multi_sector_read(struct super_block *sb, sector_t sec,
958 struct buffer_head **bh, s32 num_secs, bool read);
959int multi_sector_write(struct super_block *sb, sector_t sec,
960 struct buffer_head *bh, s32 num_secs, bool sync);
961
962void bdev_open(struct super_block *sb);
963void bdev_close(struct super_block *sb);
964int bdev_read(struct super_block *sb, sector_t secno,
965 struct buffer_head **bh, u32 num_secs, bool read);
966int bdev_write(struct super_block *sb, sector_t secno,
967 struct buffer_head *bh, u32 num_secs, bool sync);
968int bdev_sync(struct super_block *sb);
969
970extern const u8 uni_upcase[];
971#endif /* _EXFAT_H */
diff --git a/drivers/staging/exfat/exfat_blkdev.c b/drivers/staging/exfat/exfat_blkdev.c
new file mode 100644
index 000000000000..f086c75e7076
--- /dev/null
+++ b/drivers/staging/exfat/exfat_blkdev.c
@@ -0,0 +1,136 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */
5
6#include <linux/blkdev.h>
7#include <linux/buffer_head.h>
8#include <linux/fs.h>
9#include "exfat.h"
10
11void bdev_open(struct super_block *sb)
12{
13 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
14
15 if (p_bd->opened)
16 return;
17
18 p_bd->sector_size = bdev_logical_block_size(sb->s_bdev);
19 p_bd->sector_size_bits = ilog2(p_bd->sector_size);
20 p_bd->sector_size_mask = p_bd->sector_size - 1;
21 p_bd->num_sectors = i_size_read(sb->s_bdev->bd_inode) >>
22 p_bd->sector_size_bits;
23 p_bd->opened = true;
24}
25
26void bdev_close(struct super_block *sb)
27{
28 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
29
30 p_bd->opened = false;
31}
32
33int bdev_read(struct super_block *sb, sector_t secno, struct buffer_head **bh,
34 u32 num_secs, bool read)
35{
36 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
37 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
38#ifdef CONFIG_EXFAT_KERNEL_DEBUG
39 struct exfat_sb_info *sbi = EXFAT_SB(sb);
40 long flags = sbi->debug_flags;
41
42 if (flags & EXFAT_DEBUGFLAGS_ERROR_RW)
43 return FFS_MEDIAERR;
44#endif /* CONFIG_EXFAT_KERNEL_DEBUG */
45
46 if (!p_bd->opened)
47 return FFS_MEDIAERR;
48
49 if (*bh)
50 __brelse(*bh);
51
52 if (read)
53 *bh = __bread(sb->s_bdev, secno,
54 num_secs << p_bd->sector_size_bits);
55 else
56 *bh = __getblk(sb->s_bdev, secno,
57 num_secs << p_bd->sector_size_bits);
58
59 if (*bh)
60 return 0;
61
62 WARN(!p_fs->dev_ejected,
63 "[EXFAT] No bh, device seems wrong or to be ejected.\n");
64
65 return FFS_MEDIAERR;
66}
67
68int bdev_write(struct super_block *sb, sector_t secno, struct buffer_head *bh,
69 u32 num_secs, bool sync)
70{
71 s32 count;
72 struct buffer_head *bh2;
73 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
74 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
75#ifdef CONFIG_EXFAT_KERNEL_DEBUG
76 struct exfat_sb_info *sbi = EXFAT_SB(sb);
77 long flags = sbi->debug_flags;
78
79 if (flags & EXFAT_DEBUGFLAGS_ERROR_RW)
80 return FFS_MEDIAERR;
81#endif /* CONFIG_EXFAT_KERNEL_DEBUG */
82
83 if (!p_bd->opened)
84 return FFS_MEDIAERR;
85
86 if (secno == bh->b_blocknr) {
87 lock_buffer(bh);
88 set_buffer_uptodate(bh);
89 mark_buffer_dirty(bh);
90 unlock_buffer(bh);
91 if (sync && (sync_dirty_buffer(bh) != 0))
92 return FFS_MEDIAERR;
93 } else {
94 count = num_secs << p_bd->sector_size_bits;
95
96 bh2 = __getblk(sb->s_bdev, secno, count);
97 if (!bh2)
98 goto no_bh;
99
100 lock_buffer(bh2);
101 memcpy(bh2->b_data, bh->b_data, count);
102 set_buffer_uptodate(bh2);
103 mark_buffer_dirty(bh2);
104 unlock_buffer(bh2);
105 if (sync && (sync_dirty_buffer(bh2) != 0)) {
106 __brelse(bh2);
107 goto no_bh;
108 }
109 __brelse(bh2);
110 }
111
112 return 0;
113
114no_bh:
115 WARN(!p_fs->dev_ejected,
116 "[EXFAT] No bh, device seems wrong or to be ejected.\n");
117
118 return FFS_MEDIAERR;
119}
120
121int bdev_sync(struct super_block *sb)
122{
123 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
124#ifdef CONFIG_EXFAT_KERNEL_DEBUG
125 struct exfat_sb_info *sbi = EXFAT_SB(sb);
126 long flags = sbi->debug_flags;
127
128 if (flags & EXFAT_DEBUGFLAGS_ERROR_RW)
129 return FFS_MEDIAERR;
130#endif /* CONFIG_EXFAT_KERNEL_DEBUG */
131
132 if (!p_bd->opened)
133 return FFS_MEDIAERR;
134
135 return sync_blockdev(sb->s_bdev);
136}
diff --git a/drivers/staging/exfat/exfat_cache.c b/drivers/staging/exfat/exfat_cache.c
new file mode 100644
index 000000000000..1565ce65d39f
--- /dev/null
+++ b/drivers/staging/exfat/exfat_cache.c
@@ -0,0 +1,724 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */
5
6#include <linux/buffer_head.h>
7#include <linux/fs.h>
8#include <linux/mutex.h>
9#include "exfat.h"
10
11#define LOCKBIT 0x01
12#define DIRTYBIT 0x02
13
14/* Local variables */
15static DEFINE_SEMAPHORE(f_sem);
16static DEFINE_SEMAPHORE(b_sem);
17
18static struct buf_cache_t *FAT_cache_find(struct super_block *sb, sector_t sec)
19{
20 s32 off;
21 struct buf_cache_t *bp, *hp;
22 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
23
24 off = (sec +
25 (sec >> p_fs->sectors_per_clu_bits)) & (FAT_CACHE_HASH_SIZE - 1);
26
27 hp = &p_fs->FAT_cache_hash_list[off];
28 for (bp = hp->hash_next; bp != hp; bp = bp->hash_next) {
29 if ((bp->drv == p_fs->drv) && (bp->sec == sec)) {
30 WARN(!bp->buf_bh,
31 "[EXFAT] FAT_cache has no bh. It will make system panic.\n");
32
33 touch_buffer(bp->buf_bh);
34 return bp;
35 }
36 }
37 return NULL;
38}
39
40static void push_to_mru(struct buf_cache_t *bp, struct buf_cache_t *list)
41{
42 bp->next = list->next;
43 bp->prev = list;
44 list->next->prev = bp;
45 list->next = bp;
46}
47
48static void push_to_lru(struct buf_cache_t *bp, struct buf_cache_t *list)
49{
50 bp->prev = list->prev;
51 bp->next = list;
52 list->prev->next = bp;
53 list->prev = bp;
54}
55
56static void move_to_mru(struct buf_cache_t *bp, struct buf_cache_t *list)
57{
58 bp->prev->next = bp->next;
59 bp->next->prev = bp->prev;
60 push_to_mru(bp, list);
61}
62
63static void move_to_lru(struct buf_cache_t *bp, struct buf_cache_t *list)
64{
65 bp->prev->next = bp->next;
66 bp->next->prev = bp->prev;
67 push_to_lru(bp, list);
68}
69
70static struct buf_cache_t *FAT_cache_get(struct super_block *sb, sector_t sec)
71{
72 struct buf_cache_t *bp;
73 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
74
75 bp = p_fs->FAT_cache_lru_list.prev;
76
77 move_to_mru(bp, &p_fs->FAT_cache_lru_list);
78 return bp;
79}
80
81static void FAT_cache_insert_hash(struct super_block *sb,
82 struct buf_cache_t *bp)
83{
84 s32 off;
85 struct buf_cache_t *hp;
86 struct fs_info_t *p_fs;
87
88 p_fs = &(EXFAT_SB(sb)->fs_info);
89 off = (bp->sec +
90 (bp->sec >> p_fs->sectors_per_clu_bits)) &
91 (FAT_CACHE_HASH_SIZE - 1);
92
93 hp = &p_fs->FAT_cache_hash_list[off];
94 bp->hash_next = hp->hash_next;
95 bp->hash_prev = hp;
96 hp->hash_next->hash_prev = bp;
97 hp->hash_next = bp;
98}
99
100static void FAT_cache_remove_hash(struct buf_cache_t *bp)
101{
102 (bp->hash_prev)->hash_next = bp->hash_next;
103 (bp->hash_next)->hash_prev = bp->hash_prev;
104}
105
106static void buf_cache_insert_hash(struct super_block *sb,
107 struct buf_cache_t *bp)
108{
109 s32 off;
110 struct buf_cache_t *hp;
111 struct fs_info_t *p_fs;
112
113 p_fs = &(EXFAT_SB(sb)->fs_info);
114 off = (bp->sec +
115 (bp->sec >> p_fs->sectors_per_clu_bits)) &
116 (BUF_CACHE_HASH_SIZE - 1);
117
118 hp = &p_fs->buf_cache_hash_list[off];
119 bp->hash_next = hp->hash_next;
120 bp->hash_prev = hp;
121 hp->hash_next->hash_prev = bp;
122 hp->hash_next = bp;
123}
124
125static void buf_cache_remove_hash(struct buf_cache_t *bp)
126{
127 (bp->hash_prev)->hash_next = bp->hash_next;
128 (bp->hash_next)->hash_prev = bp->hash_prev;
129}
130
131void buf_init(struct super_block *sb)
132{
133 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
134
135 int i;
136
137 /* LRU list */
138 p_fs->FAT_cache_lru_list.next = &p_fs->FAT_cache_lru_list;
139 p_fs->FAT_cache_lru_list.prev = &p_fs->FAT_cache_lru_list;
140
141 for (i = 0; i < FAT_CACHE_SIZE; i++) {
142 p_fs->FAT_cache_array[i].drv = -1;
143 p_fs->FAT_cache_array[i].sec = ~0;
144 p_fs->FAT_cache_array[i].flag = 0;
145 p_fs->FAT_cache_array[i].buf_bh = NULL;
146 p_fs->FAT_cache_array[i].prev = NULL;
147 p_fs->FAT_cache_array[i].next = NULL;
148 push_to_mru(&p_fs->FAT_cache_array[i],
149 &p_fs->FAT_cache_lru_list);
150 }
151
152 p_fs->buf_cache_lru_list.next = &p_fs->buf_cache_lru_list;
153 p_fs->buf_cache_lru_list.prev = &p_fs->buf_cache_lru_list;
154
155 for (i = 0; i < BUF_CACHE_SIZE; i++) {
156 p_fs->buf_cache_array[i].drv = -1;
157 p_fs->buf_cache_array[i].sec = ~0;
158 p_fs->buf_cache_array[i].flag = 0;
159 p_fs->buf_cache_array[i].buf_bh = NULL;
160 p_fs->buf_cache_array[i].prev = NULL;
161 p_fs->buf_cache_array[i].next = NULL;
162 push_to_mru(&p_fs->buf_cache_array[i],
163 &p_fs->buf_cache_lru_list);
164 }
165
166 /* HASH list */
167 for (i = 0; i < FAT_CACHE_HASH_SIZE; i++) {
168 p_fs->FAT_cache_hash_list[i].drv = -1;
169 p_fs->FAT_cache_hash_list[i].sec = ~0;
170 p_fs->FAT_cache_hash_list[i].hash_next =
171 &p_fs->FAT_cache_hash_list[i];
172 p_fs->FAT_cache_hash_list[i].hash_prev =
173 &p_fs->FAT_cache_hash_list[i];
174 }
175
176 for (i = 0; i < FAT_CACHE_SIZE; i++)
177 FAT_cache_insert_hash(sb, &p_fs->FAT_cache_array[i]);
178
179 for (i = 0; i < BUF_CACHE_HASH_SIZE; i++) {
180 p_fs->buf_cache_hash_list[i].drv = -1;
181 p_fs->buf_cache_hash_list[i].sec = ~0;
182 p_fs->buf_cache_hash_list[i].hash_next =
183 &p_fs->buf_cache_hash_list[i];
184 p_fs->buf_cache_hash_list[i].hash_prev =
185 &p_fs->buf_cache_hash_list[i];
186 }
187
188 for (i = 0; i < BUF_CACHE_SIZE; i++)
189 buf_cache_insert_hash(sb, &p_fs->buf_cache_array[i]);
190}
191
192void buf_shutdown(struct super_block *sb)
193{
194}
195
196static int __FAT_read(struct super_block *sb, u32 loc, u32 *content)
197{
198 s32 off;
199 u32 _content;
200 sector_t sec;
201 u8 *fat_sector, *fat_entry;
202 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
203 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
204
205 if (p_fs->vol_type == FAT12) {
206 sec = p_fs->FAT1_start_sector +
207 ((loc + (loc >> 1)) >> p_bd->sector_size_bits);
208 off = (loc + (loc >> 1)) & p_bd->sector_size_mask;
209
210 if (off == (p_bd->sector_size - 1)) {
211 fat_sector = FAT_getblk(sb, sec);
212 if (!fat_sector)
213 return -1;
214
215 _content = (u32)fat_sector[off];
216
217 fat_sector = FAT_getblk(sb, ++sec);
218 if (!fat_sector)
219 return -1;
220
221 _content |= (u32)fat_sector[0] << 8;
222 } else {
223 fat_sector = FAT_getblk(sb, sec);
224 if (!fat_sector)
225 return -1;
226
227 fat_entry = &fat_sector[off];
228 _content = GET16(fat_entry);
229 }
230
231 if (loc & 1)
232 _content >>= 4;
233
234 _content &= 0x00000FFF;
235
236 if (_content >= CLUSTER_16(0x0FF8)) {
237 *content = CLUSTER_32(~0);
238 return 0;
239 }
240 *content = CLUSTER_32(_content);
241 return 0;
242 } else if (p_fs->vol_type == FAT16) {
243 sec = p_fs->FAT1_start_sector +
244 (loc >> (p_bd->sector_size_bits - 1));
245 off = (loc << 1) & p_bd->sector_size_mask;
246
247 fat_sector = FAT_getblk(sb, sec);
248 if (!fat_sector)
249 return -1;
250
251 fat_entry = &fat_sector[off];
252
253 _content = GET16_A(fat_entry);
254
255 _content &= 0x0000FFFF;
256
257 if (_content >= CLUSTER_16(0xFFF8)) {
258 *content = CLUSTER_32(~0);
259 return 0;
260 }
261 *content = CLUSTER_32(_content);
262 return 0;
263 } else if (p_fs->vol_type == FAT32) {
264 sec = p_fs->FAT1_start_sector +
265 (loc >> (p_bd->sector_size_bits - 2));
266 off = (loc << 2) & p_bd->sector_size_mask;
267
268 fat_sector = FAT_getblk(sb, sec);
269 if (!fat_sector)
270 return -1;
271
272 fat_entry = &fat_sector[off];
273
274 _content = GET32_A(fat_entry);
275
276 _content &= 0x0FFFFFFF;
277
278 if (_content >= CLUSTER_32(0x0FFFFFF8)) {
279 *content = CLUSTER_32(~0);
280 return 0;
281 }
282 *content = CLUSTER_32(_content);
283 return 0;
284 } else if (p_fs->vol_type == EXFAT) {
285 sec = p_fs->FAT1_start_sector +
286 (loc >> (p_bd->sector_size_bits - 2));
287 off = (loc << 2) & p_bd->sector_size_mask;
288
289 fat_sector = FAT_getblk(sb, sec);
290 if (!fat_sector)
291 return -1;
292
293 fat_entry = &fat_sector[off];
294 _content = GET32_A(fat_entry);
295
296 if (_content >= CLUSTER_32(0xFFFFFFF8)) {
297 *content = CLUSTER_32(~0);
298 return 0;
299 }
300 *content = CLUSTER_32(_content);
301 return 0;
302 }
303
304 /* Unknown volume type, throw in the towel and go home */
305 *content = CLUSTER_32(~0);
306 return 0;
307}
308
309/* in : sb, loc
310 * out: content
311 * returns 0 on success
312 * -1 on error
313 */
314int FAT_read(struct super_block *sb, u32 loc, u32 *content)
315{
316 s32 ret;
317
318 down(&f_sem);
319 ret = __FAT_read(sb, loc, content);
320 up(&f_sem);
321
322 return ret;
323}
324
325static s32 __FAT_write(struct super_block *sb, u32 loc, u32 content)
326{
327 s32 off;
328 sector_t sec;
329 u8 *fat_sector, *fat_entry;
330 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
331 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
332
333 if (p_fs->vol_type == FAT12) {
334 content &= 0x00000FFF;
335
336 sec = p_fs->FAT1_start_sector +
337 ((loc + (loc >> 1)) >> p_bd->sector_size_bits);
338 off = (loc + (loc >> 1)) & p_bd->sector_size_mask;
339
340 fat_sector = FAT_getblk(sb, sec);
341 if (!fat_sector)
342 return -1;
343
344 if (loc & 1) { /* odd */
345 content <<= 4;
346
347 if (off == (p_bd->sector_size - 1)) {
348 fat_sector[off] = (u8)(content |
349 (fat_sector[off] &
350 0x0F));
351 FAT_modify(sb, sec);
352
353 fat_sector = FAT_getblk(sb, ++sec);
354 if (!fat_sector)
355 return -1;
356
357 fat_sector[0] = (u8)(content >> 8);
358 } else {
359 fat_entry = &fat_sector[off];
360 content |= GET16(fat_entry) & 0x000F;
361
362 SET16(fat_entry, content);
363 }
364 } else { /* even */
365 fat_sector[off] = (u8)(content);
366
367 if (off == (p_bd->sector_size - 1)) {
368 fat_sector[off] = (u8)(content);
369 FAT_modify(sb, sec);
370
371 fat_sector = FAT_getblk(sb, ++sec);
372 if (!fat_sector)
373 return -1;
374 fat_sector[0] = (u8)((fat_sector[0] & 0xF0) |
375 (content >> 8));
376 } else {
377 fat_entry = &fat_sector[off];
378 content |= GET16(fat_entry) & 0xF000;
379
380 SET16(fat_entry, content);
381 }
382 }
383 }
384
385 else if (p_fs->vol_type == FAT16) {
386 content &= 0x0000FFFF;
387
388 sec = p_fs->FAT1_start_sector + (loc >>
389 (p_bd->sector_size_bits - 1));
390 off = (loc << 1) & p_bd->sector_size_mask;
391
392 fat_sector = FAT_getblk(sb, sec);
393 if (!fat_sector)
394 return -1;
395
396 fat_entry = &fat_sector[off];
397
398 SET16_A(fat_entry, content);
399 } else if (p_fs->vol_type == FAT32) {
400 content &= 0x0FFFFFFF;
401
402 sec = p_fs->FAT1_start_sector + (loc >>
403 (p_bd->sector_size_bits - 2));
404 off = (loc << 2) & p_bd->sector_size_mask;
405
406 fat_sector = FAT_getblk(sb, sec);
407 if (!fat_sector)
408 return -1;
409
410 fat_entry = &fat_sector[off];
411
412 content |= GET32_A(fat_entry) & 0xF0000000;
413
414 SET32_A(fat_entry, content);
415 } else { /* p_fs->vol_type == EXFAT */
416 sec = p_fs->FAT1_start_sector + (loc >>
417 (p_bd->sector_size_bits - 2));
418 off = (loc << 2) & p_bd->sector_size_mask;
419
420 fat_sector = FAT_getblk(sb, sec);
421 if (!fat_sector)
422 return -1;
423
424 fat_entry = &fat_sector[off];
425
426 SET32_A(fat_entry, content);
427 }
428
429 FAT_modify(sb, sec);
430 return 0;
431}
432
433int FAT_write(struct super_block *sb, u32 loc, u32 content)
434{
435 s32 ret;
436
437 down(&f_sem);
438 ret = __FAT_write(sb, loc, content);
439 up(&f_sem);
440
441 return ret;
442}
443
444u8 *FAT_getblk(struct super_block *sb, sector_t sec)
445{
446 struct buf_cache_t *bp;
447 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
448
449 bp = FAT_cache_find(sb, sec);
450 if (bp) {
451 move_to_mru(bp, &p_fs->FAT_cache_lru_list);
452 return bp->buf_bh->b_data;
453 }
454
455 bp = FAT_cache_get(sb, sec);
456
457 FAT_cache_remove_hash(bp);
458
459 bp->drv = p_fs->drv;
460 bp->sec = sec;
461 bp->flag = 0;
462
463 FAT_cache_insert_hash(sb, bp);
464
465 if (sector_read(sb, sec, &bp->buf_bh, 1) != FFS_SUCCESS) {
466 FAT_cache_remove_hash(bp);
467 bp->drv = -1;
468 bp->sec = ~0;
469 bp->flag = 0;
470 bp->buf_bh = NULL;
471
472 move_to_lru(bp, &p_fs->FAT_cache_lru_list);
473 return NULL;
474 }
475
476 return bp->buf_bh->b_data;
477}
478
479void FAT_modify(struct super_block *sb, sector_t sec)
480{
481 struct buf_cache_t *bp;
482
483 bp = FAT_cache_find(sb, sec);
484 if (bp)
485 sector_write(sb, sec, bp->buf_bh, 0);
486}
487
488void FAT_release_all(struct super_block *sb)
489{
490 struct buf_cache_t *bp;
491 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
492
493 down(&f_sem);
494
495 bp = p_fs->FAT_cache_lru_list.next;
496 while (bp != &p_fs->FAT_cache_lru_list) {
497 if (bp->drv == p_fs->drv) {
498 bp->drv = -1;
499 bp->sec = ~0;
500 bp->flag = 0;
501
502 if (bp->buf_bh) {
503 __brelse(bp->buf_bh);
504 bp->buf_bh = NULL;
505 }
506 }
507 bp = bp->next;
508 }
509
510 up(&f_sem);
511}
512
513void FAT_sync(struct super_block *sb)
514{
515 struct buf_cache_t *bp;
516 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
517
518 down(&f_sem);
519
520 bp = p_fs->FAT_cache_lru_list.next;
521 while (bp != &p_fs->FAT_cache_lru_list) {
522 if ((bp->drv == p_fs->drv) && (bp->flag & DIRTYBIT)) {
523 sync_dirty_buffer(bp->buf_bh);
524 bp->flag &= ~(DIRTYBIT);
525 }
526 bp = bp->next;
527 }
528
529 up(&f_sem);
530}
531
532static struct buf_cache_t *buf_cache_find(struct super_block *sb, sector_t sec)
533{
534 s32 off;
535 struct buf_cache_t *bp, *hp;
536 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
537
538 off = (sec + (sec >> p_fs->sectors_per_clu_bits)) &
539 (BUF_CACHE_HASH_SIZE - 1);
540
541 hp = &p_fs->buf_cache_hash_list[off];
542 for (bp = hp->hash_next; bp != hp; bp = bp->hash_next) {
543 if ((bp->drv == p_fs->drv) && (bp->sec == sec)) {
544 touch_buffer(bp->buf_bh);
545 return bp;
546 }
547 }
548 return NULL;
549}
550
551static struct buf_cache_t *buf_cache_get(struct super_block *sb, sector_t sec)
552{
553 struct buf_cache_t *bp;
554 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
555
556 bp = p_fs->buf_cache_lru_list.prev;
557 while (bp->flag & LOCKBIT)
558 bp = bp->prev;
559
560 move_to_mru(bp, &p_fs->buf_cache_lru_list);
561 return bp;
562}
563
564static u8 *__buf_getblk(struct super_block *sb, sector_t sec)
565{
566 struct buf_cache_t *bp;
567 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
568
569 bp = buf_cache_find(sb, sec);
570 if (bp) {
571 move_to_mru(bp, &p_fs->buf_cache_lru_list);
572 return bp->buf_bh->b_data;
573 }
574
575 bp = buf_cache_get(sb, sec);
576
577 buf_cache_remove_hash(bp);
578
579 bp->drv = p_fs->drv;
580 bp->sec = sec;
581 bp->flag = 0;
582
583 buf_cache_insert_hash(sb, bp);
584
585 if (sector_read(sb, sec, &bp->buf_bh, 1) != FFS_SUCCESS) {
586 buf_cache_remove_hash(bp);
587 bp->drv = -1;
588 bp->sec = ~0;
589 bp->flag = 0;
590 bp->buf_bh = NULL;
591
592 move_to_lru(bp, &p_fs->buf_cache_lru_list);
593 return NULL;
594 }
595
596 return bp->buf_bh->b_data;
597}
598
599u8 *buf_getblk(struct super_block *sb, sector_t sec)
600{
601 u8 *buf;
602
603 down(&b_sem);
604 buf = __buf_getblk(sb, sec);
605 up(&b_sem);
606
607 return buf;
608}
609
610void buf_modify(struct super_block *sb, sector_t sec)
611{
612 struct buf_cache_t *bp;
613
614 down(&b_sem);
615
616 bp = buf_cache_find(sb, sec);
617 if (likely(bp))
618 sector_write(sb, sec, bp->buf_bh, 0);
619
620 WARN(!bp, "[EXFAT] failed to find buffer_cache(sector:%llu).\n",
621 (unsigned long long)sec);
622
623 up(&b_sem);
624}
625
626void buf_lock(struct super_block *sb, sector_t sec)
627{
628 struct buf_cache_t *bp;
629
630 down(&b_sem);
631
632 bp = buf_cache_find(sb, sec);
633 if (likely(bp))
634 bp->flag |= LOCKBIT;
635
636 WARN(!bp, "[EXFAT] failed to find buffer_cache(sector:%llu).\n",
637 (unsigned long long)sec);
638
639 up(&b_sem);
640}
641
642void buf_unlock(struct super_block *sb, sector_t sec)
643{
644 struct buf_cache_t *bp;
645
646 down(&b_sem);
647
648 bp = buf_cache_find(sb, sec);
649 if (likely(bp))
650 bp->flag &= ~(LOCKBIT);
651
652 WARN(!bp, "[EXFAT] failed to find buffer_cache(sector:%llu).\n",
653 (unsigned long long)sec);
654
655 up(&b_sem);
656}
657
658void buf_release(struct super_block *sb, sector_t sec)
659{
660 struct buf_cache_t *bp;
661 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
662
663 down(&b_sem);
664
665 bp = buf_cache_find(sb, sec);
666 if (likely(bp)) {
667 bp->drv = -1;
668 bp->sec = ~0;
669 bp->flag = 0;
670
671 if (bp->buf_bh) {
672 __brelse(bp->buf_bh);
673 bp->buf_bh = NULL;
674 }
675
676 move_to_lru(bp, &p_fs->buf_cache_lru_list);
677 }
678
679 up(&b_sem);
680}
681
682void buf_release_all(struct super_block *sb)
683{
684 struct buf_cache_t *bp;
685 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
686
687 down(&b_sem);
688
689 bp = p_fs->buf_cache_lru_list.next;
690 while (bp != &p_fs->buf_cache_lru_list) {
691 if (bp->drv == p_fs->drv) {
692 bp->drv = -1;
693 bp->sec = ~0;
694 bp->flag = 0;
695
696 if (bp->buf_bh) {
697 __brelse(bp->buf_bh);
698 bp->buf_bh = NULL;
699 }
700 }
701 bp = bp->next;
702 }
703
704 up(&b_sem);
705}
706
707void buf_sync(struct super_block *sb)
708{
709 struct buf_cache_t *bp;
710 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
711
712 down(&b_sem);
713
714 bp = p_fs->buf_cache_lru_list.next;
715 while (bp != &p_fs->buf_cache_lru_list) {
716 if ((bp->drv == p_fs->drv) && (bp->flag & DIRTYBIT)) {
717 sync_dirty_buffer(bp->buf_bh);
718 bp->flag &= ~(DIRTYBIT);
719 }
720 bp = bp->next;
721 }
722
723 up(&b_sem);
724}
diff --git a/drivers/staging/exfat/exfat_core.c b/drivers/staging/exfat/exfat_core.c
new file mode 100644
index 000000000000..b3e9cf725cf5
--- /dev/null
+++ b/drivers/staging/exfat/exfat_core.c
@@ -0,0 +1,3701 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */
5
6#include <linux/types.h>
7#include <linux/buffer_head.h>
8#include <linux/fs.h>
9#include <linux/mutex.h>
10#include <linux/blkdev.h>
11#include <linux/slab.h>
12#include "exfat.h"
13
14static void __set_sb_dirty(struct super_block *sb)
15{
16 struct exfat_sb_info *sbi = EXFAT_SB(sb);
17
18 sbi->s_dirt = 1;
19}
20
21static u8 name_buf[MAX_PATH_LENGTH * MAX_CHARSET_SIZE];
22
23static char *reserved_names[] = {
24 "AUX ", "CON ", "NUL ", "PRN ",
25 "COM1 ", "COM2 ", "COM3 ", "COM4 ",
26 "COM5 ", "COM6 ", "COM7 ", "COM8 ", "COM9 ",
27 "LPT1 ", "LPT2 ", "LPT3 ", "LPT4 ",
28 "LPT5 ", "LPT6 ", "LPT7 ", "LPT8 ", "LPT9 ",
29 NULL
30};
31
32static u8 free_bit[] = {
33 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, /* 0 ~ 19 */
34 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, /* 20 ~ 39 */
35 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, /* 40 ~ 59 */
36 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, /* 60 ~ 79 */
37 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, /* 80 ~ 99 */
38 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, /* 100 ~ 119 */
39 0, 1, 0, 2, 0, 1, 0, 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, /* 120 ~ 139 */
40 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, /* 140 ~ 159 */
41 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, /* 160 ~ 179 */
42 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, /* 180 ~ 199 */
43 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, /* 200 ~ 219 */
44 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, /* 220 ~ 239 */
45 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 /* 240 ~ 254 */
46};
47
48static u8 used_bit[] = {
49 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, /* 0 ~ 19 */
50 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, /* 20 ~ 39 */
51 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, /* 40 ~ 59 */
52 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 60 ~ 79 */
53 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, /* 80 ~ 99 */
54 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, /* 100 ~ 119 */
55 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, /* 120 ~ 139 */
56 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 140 ~ 159 */
57 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, /* 160 ~ 179 */
58 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, /* 180 ~ 199 */
59 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, /* 200 ~ 219 */
60 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 220 ~ 239 */
61 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 /* 240 ~ 255 */
62};
63
64#define BITMAP_LOC(v) ((v) >> 3)
65#define BITMAP_SHIFT(v) ((v) & 0x07)
66
67static inline s32 exfat_bitmap_test(u8 *bitmap, int i)
68{
69 u8 data;
70
71 data = bitmap[BITMAP_LOC(i)];
72 if ((data >> BITMAP_SHIFT(i)) & 0x01)
73 return 1;
74 return 0;
75}
76
77static inline void exfat_bitmap_set(u8 *bitmap, int i)
78{
79 bitmap[BITMAP_LOC(i)] |= (0x01 << BITMAP_SHIFT(i));
80}
81
82static inline void exfat_bitmap_clear(u8 *bitmap, int i)
83{
84 bitmap[BITMAP_LOC(i)] &= ~(0x01 << BITMAP_SHIFT(i));
85}
86
87/*
88 * File System Management Functions
89 */
90
91void fs_set_vol_flags(struct super_block *sb, u32 new_flag)
92{
93 struct pbr_sector_t *p_pbr;
94 struct bpbex_t *p_bpb;
95 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
96
97 if (p_fs->vol_flag == new_flag)
98 return;
99
100 p_fs->vol_flag = new_flag;
101
102 if (p_fs->vol_type == EXFAT) {
103 if (!p_fs->pbr_bh) {
104 if (sector_read(sb, p_fs->PBR_sector,
105 &p_fs->pbr_bh, 1) != FFS_SUCCESS)
106 return;
107 }
108
109 p_pbr = (struct pbr_sector_t *)p_fs->pbr_bh->b_data;
110 p_bpb = (struct bpbex_t *)p_pbr->bpb;
111 SET16(p_bpb->vol_flags, (u16)new_flag);
112
113 /* XXX duyoung
114 * what can we do here? (cuz fs_set_vol_flags() is void)
115 */
116 if ((new_flag == VOL_DIRTY) && (!buffer_dirty(p_fs->pbr_bh)))
117 sector_write(sb, p_fs->PBR_sector, p_fs->pbr_bh, 1);
118 else
119 sector_write(sb, p_fs->PBR_sector, p_fs->pbr_bh, 0);
120 }
121}
122
123void fs_error(struct super_block *sb)
124{
125 struct exfat_mount_options *opts = &EXFAT_SB(sb)->options;
126
127 if (opts->errors == EXFAT_ERRORS_PANIC) {
128 panic("[EXFAT] Filesystem panic from previous error\n");
129 } else if ((opts->errors == EXFAT_ERRORS_RO) && !sb_rdonly(sb)) {
130 sb->s_flags |= SB_RDONLY;
131 pr_err("[EXFAT] Filesystem has been set read-only\n");
132 }
133}
134
135/*
136 * Cluster Management Functions
137 */
138
139s32 clear_cluster(struct super_block *sb, u32 clu)
140{
141 sector_t s, n;
142 s32 ret = FFS_SUCCESS;
143 struct buffer_head *tmp_bh = NULL;
144 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
145 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
146
147 if (clu == CLUSTER_32(0)) { /* FAT16 root_dir */
148 s = p_fs->root_start_sector;
149 n = p_fs->data_start_sector;
150 } else {
151 s = START_SECTOR(clu);
152 n = s + p_fs->sectors_per_clu;
153 }
154
155 for (; s < n; s++) {
156 ret = sector_read(sb, s, &tmp_bh, 0);
157 if (ret != FFS_SUCCESS)
158 return ret;
159
160 memset((char *)tmp_bh->b_data, 0x0, p_bd->sector_size);
161 ret = sector_write(sb, s, tmp_bh, 0);
162 if (ret != FFS_SUCCESS)
163 break;
164 }
165
166 brelse(tmp_bh);
167 return ret;
168}
169
170s32 fat_alloc_cluster(struct super_block *sb, s32 num_alloc,
171 struct chain_t *p_chain)
172{
173 int i, num_clusters = 0;
174 u32 new_clu, last_clu = CLUSTER_32(~0), read_clu;
175 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
176
177 new_clu = p_chain->dir;
178 if (new_clu == CLUSTER_32(~0))
179 new_clu = p_fs->clu_srch_ptr;
180 else if (new_clu >= p_fs->num_clusters)
181 new_clu = 2;
182
183 __set_sb_dirty(sb);
184
185 p_chain->dir = CLUSTER_32(~0);
186
187 for (i = 2; i < p_fs->num_clusters; i++) {
188 if (FAT_read(sb, new_clu, &read_clu) != 0)
189 return -1;
190
191 if (read_clu == CLUSTER_32(0)) {
192 if (FAT_write(sb, new_clu, CLUSTER_32(~0)) < 0)
193 return -1;
194 num_clusters++;
195
196 if (p_chain->dir == CLUSTER_32(~0)) {
197 p_chain->dir = new_clu;
198 } else {
199 if (FAT_write(sb, last_clu, new_clu) < 0)
200 return -1;
201 }
202
203 last_clu = new_clu;
204
205 if ((--num_alloc) == 0) {
206 p_fs->clu_srch_ptr = new_clu;
207 if (p_fs->used_clusters != UINT_MAX)
208 p_fs->used_clusters += num_clusters;
209
210 return num_clusters;
211 }
212 }
213 if ((++new_clu) >= p_fs->num_clusters)
214 new_clu = 2;
215 }
216
217 p_fs->clu_srch_ptr = new_clu;
218 if (p_fs->used_clusters != UINT_MAX)
219 p_fs->used_clusters += num_clusters;
220
221 return num_clusters;
222}
223
224s32 exfat_alloc_cluster(struct super_block *sb, s32 num_alloc,
225 struct chain_t *p_chain)
226{
227 s32 num_clusters = 0;
228 u32 hint_clu, new_clu, last_clu = CLUSTER_32(~0);
229 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
230
231 hint_clu = p_chain->dir;
232 if (hint_clu == CLUSTER_32(~0)) {
233 hint_clu = test_alloc_bitmap(sb, p_fs->clu_srch_ptr - 2);
234 if (hint_clu == CLUSTER_32(~0))
235 return 0;
236 } else if (hint_clu >= p_fs->num_clusters) {
237 hint_clu = 2;
238 p_chain->flags = 0x01;
239 }
240
241 __set_sb_dirty(sb);
242
243 p_chain->dir = CLUSTER_32(~0);
244
245 while ((new_clu = test_alloc_bitmap(sb, hint_clu - 2)) != CLUSTER_32(~0)) {
246 if (new_clu != hint_clu) {
247 if (p_chain->flags == 0x03) {
248 exfat_chain_cont_cluster(sb, p_chain->dir,
249 num_clusters);
250 p_chain->flags = 0x01;
251 }
252 }
253
254 if (set_alloc_bitmap(sb, new_clu - 2) != FFS_SUCCESS)
255 return -1;
256
257 num_clusters++;
258
259 if (p_chain->flags == 0x01) {
260 if (FAT_write(sb, new_clu, CLUSTER_32(~0)) < 0)
261 return -1;
262 }
263
264 if (p_chain->dir == CLUSTER_32(~0)) {
265 p_chain->dir = new_clu;
266 } else {
267 if (p_chain->flags == 0x01) {
268 if (FAT_write(sb, last_clu, new_clu) < 0)
269 return -1;
270 }
271 }
272 last_clu = new_clu;
273
274 if ((--num_alloc) == 0) {
275 p_fs->clu_srch_ptr = hint_clu;
276 if (p_fs->used_clusters != UINT_MAX)
277 p_fs->used_clusters += num_clusters;
278
279 p_chain->size += num_clusters;
280 return num_clusters;
281 }
282
283 hint_clu = new_clu + 1;
284 if (hint_clu >= p_fs->num_clusters) {
285 hint_clu = 2;
286
287 if (p_chain->flags == 0x03) {
288 exfat_chain_cont_cluster(sb, p_chain->dir,
289 num_clusters);
290 p_chain->flags = 0x01;
291 }
292 }
293 }
294
295 p_fs->clu_srch_ptr = hint_clu;
296 if (p_fs->used_clusters != UINT_MAX)
297 p_fs->used_clusters += num_clusters;
298
299 p_chain->size += num_clusters;
300 return num_clusters;
301}
302
303void fat_free_cluster(struct super_block *sb, struct chain_t *p_chain,
304 s32 do_relse)
305{
306 s32 num_clusters = 0;
307 u32 clu, prev;
308 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
309 int i;
310 sector_t sector;
311
312 if ((p_chain->dir == CLUSTER_32(0)) || (p_chain->dir == CLUSTER_32(~0)))
313 return;
314 __set_sb_dirty(sb);
315 clu = p_chain->dir;
316
317 if (p_chain->size <= 0)
318 return;
319
320 do {
321 if (p_fs->dev_ejected)
322 break;
323
324 if (do_relse) {
325 sector = START_SECTOR(clu);
326 for (i = 0; i < p_fs->sectors_per_clu; i++)
327 buf_release(sb, sector + i);
328 }
329
330 prev = clu;
331 if (FAT_read(sb, clu, &clu) == -1)
332 break;
333
334 if (FAT_write(sb, prev, CLUSTER_32(0)) < 0)
335 break;
336 num_clusters++;
337
338 } while (clu != CLUSTER_32(~0));
339
340 if (p_fs->used_clusters != UINT_MAX)
341 p_fs->used_clusters -= num_clusters;
342}
343
344void exfat_free_cluster(struct super_block *sb, struct chain_t *p_chain,
345 s32 do_relse)
346{
347 s32 num_clusters = 0;
348 u32 clu;
349 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
350 int i;
351 sector_t sector;
352
353 if ((p_chain->dir == CLUSTER_32(0)) || (p_chain->dir == CLUSTER_32(~0)))
354 return;
355
356 if (p_chain->size <= 0) {
357 pr_err("[EXFAT] free_cluster : skip free-req clu:%u, because of zero-size truncation\n",
358 p_chain->dir);
359 return;
360 }
361
362 __set_sb_dirty(sb);
363 clu = p_chain->dir;
364
365 if (p_chain->flags == 0x03) {
366 do {
367 if (do_relse) {
368 sector = START_SECTOR(clu);
369 for (i = 0; i < p_fs->sectors_per_clu; i++)
370 buf_release(sb, sector + i);
371 }
372
373 if (clr_alloc_bitmap(sb, clu - 2) != FFS_SUCCESS)
374 break;
375 clu++;
376
377 num_clusters++;
378 } while (num_clusters < p_chain->size);
379 } else {
380 do {
381 if (p_fs->dev_ejected)
382 break;
383
384 if (do_relse) {
385 sector = START_SECTOR(clu);
386 for (i = 0; i < p_fs->sectors_per_clu; i++)
387 buf_release(sb, sector + i);
388 }
389
390 if (clr_alloc_bitmap(sb, clu - 2) != FFS_SUCCESS)
391 break;
392
393 if (FAT_read(sb, clu, &clu) == -1)
394 break;
395 num_clusters++;
396 } while ((clu != CLUSTER_32(0)) && (clu != CLUSTER_32(~0)));
397 }
398
399 if (p_fs->used_clusters != UINT_MAX)
400 p_fs->used_clusters -= num_clusters;
401}
402
403u32 find_last_cluster(struct super_block *sb, struct chain_t *p_chain)
404{
405 u32 clu, next;
406 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
407
408 clu = p_chain->dir;
409
410 if (p_chain->flags == 0x03) {
411 clu += p_chain->size - 1;
412 } else {
413 while ((FAT_read(sb, clu, &next) == 0) &&
414 (next != CLUSTER_32(~0))) {
415 if (p_fs->dev_ejected)
416 break;
417 clu = next;
418 }
419 }
420
421 return clu;
422}
423
424s32 count_num_clusters(struct super_block *sb, struct chain_t *p_chain)
425{
426 int i, count = 0;
427 u32 clu;
428 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
429
430 if ((p_chain->dir == CLUSTER_32(0)) || (p_chain->dir == CLUSTER_32(~0)))
431 return 0;
432
433 clu = p_chain->dir;
434
435 if (p_chain->flags == 0x03) {
436 count = p_chain->size;
437 } else {
438 for (i = 2; i < p_fs->num_clusters; i++) {
439 count++;
440 if (FAT_read(sb, clu, &clu) != 0)
441 return 0;
442 if (clu == CLUSTER_32(~0))
443 break;
444 }
445 }
446
447 return count;
448}
449
450s32 fat_count_used_clusters(struct super_block *sb)
451{
452 int i, count = 0;
453 u32 clu;
454 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
455
456 for (i = 2; i < p_fs->num_clusters; i++) {
457 if (FAT_read(sb, i, &clu) != 0)
458 break;
459 if (clu != CLUSTER_32(0))
460 count++;
461 }
462
463 return count;
464}
465
466s32 exfat_count_used_clusters(struct super_block *sb)
467{
468 int i, map_i, map_b, count = 0;
469 u8 k;
470 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
471 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
472
473 map_i = map_b = 0;
474
475 for (i = 2; i < p_fs->num_clusters; i += 8) {
476 k = *(((u8 *)p_fs->vol_amap[map_i]->b_data) + map_b);
477 count += used_bit[k];
478
479 if ((++map_b) >= p_bd->sector_size) {
480 map_i++;
481 map_b = 0;
482 }
483 }
484
485 return count;
486}
487
488void exfat_chain_cont_cluster(struct super_block *sb, u32 chain, s32 len)
489{
490 if (len == 0)
491 return;
492
493 while (len > 1) {
494 if (FAT_write(sb, chain, chain + 1) < 0)
495 break;
496 chain++;
497 len--;
498 }
499 FAT_write(sb, chain, CLUSTER_32(~0));
500}
501
502/*
503 * Allocation Bitmap Management Functions
504 */
505
506s32 load_alloc_bitmap(struct super_block *sb)
507{
508 int i, j, ret;
509 u32 map_size;
510 u32 type;
511 sector_t sector;
512 struct chain_t clu;
513 struct bmap_dentry_t *ep;
514 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
515 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
516
517 clu.dir = p_fs->root_dir;
518 clu.flags = 0x01;
519
520 while (clu.dir != CLUSTER_32(~0)) {
521 if (p_fs->dev_ejected)
522 break;
523
524 for (i = 0; i < p_fs->dentries_per_clu; i++) {
525 ep = (struct bmap_dentry_t *)get_entry_in_dir(sb, &clu,
526 i, NULL);
527 if (!ep)
528 return FFS_MEDIAERR;
529
530 type = p_fs->fs_func->get_entry_type((struct dentry_t *)ep);
531
532 if (type == TYPE_UNUSED)
533 break;
534 if (type != TYPE_BITMAP)
535 continue;
536
537 if (ep->flags == 0x0) {
538 p_fs->map_clu = GET32_A(ep->start_clu);
539 map_size = (u32)GET64_A(ep->size);
540
541 p_fs->map_sectors = ((map_size - 1) >> p_bd->sector_size_bits) + 1;
542
543 p_fs->vol_amap = kmalloc_array(p_fs->map_sectors,
544 sizeof(struct buffer_head *),
545 GFP_KERNEL);
546 if (!p_fs->vol_amap)
547 return FFS_MEMORYERR;
548
549 sector = START_SECTOR(p_fs->map_clu);
550
551 for (j = 0; j < p_fs->map_sectors; j++) {
552 p_fs->vol_amap[j] = NULL;
553 ret = sector_read(sb, sector + j, &(p_fs->vol_amap[j]), 1);
554 if (ret != FFS_SUCCESS) {
555 /* release all buffers and free vol_amap */
556 i = 0;
557 while (i < j)
558 brelse(p_fs->vol_amap[i++]);
559
560 kfree(p_fs->vol_amap);
561 p_fs->vol_amap = NULL;
562 return ret;
563 }
564 }
565
566 p_fs->pbr_bh = NULL;
567 return FFS_SUCCESS;
568 }
569 }
570
571 if (FAT_read(sb, clu.dir, &clu.dir) != 0)
572 return FFS_MEDIAERR;
573 }
574
575 return FFS_FORMATERR;
576}
577
578void free_alloc_bitmap(struct super_block *sb)
579{
580 int i;
581 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
582
583 brelse(p_fs->pbr_bh);
584
585 for (i = 0; i < p_fs->map_sectors; i++)
586 __brelse(p_fs->vol_amap[i]);
587
588 kfree(p_fs->vol_amap);
589 p_fs->vol_amap = NULL;
590}
591
592s32 set_alloc_bitmap(struct super_block *sb, u32 clu)
593{
594 int i, b;
595 sector_t sector;
596 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
597 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
598
599 i = clu >> (p_bd->sector_size_bits + 3);
600 b = clu & ((p_bd->sector_size << 3) - 1);
601
602 sector = START_SECTOR(p_fs->map_clu) + i;
603
604 exfat_bitmap_set((u8 *)p_fs->vol_amap[i]->b_data, b);
605
606 return sector_write(sb, sector, p_fs->vol_amap[i], 0);
607}
608
609s32 clr_alloc_bitmap(struct super_block *sb, u32 clu)
610{
611 int i, b;
612 sector_t sector;
613#ifdef CONFIG_EXFAT_DISCARD
614 struct exfat_sb_info *sbi = EXFAT_SB(sb);
615 struct exfat_mount_options *opts = &sbi->options;
616 int ret;
617#endif /* CONFIG_EXFAT_DISCARD */
618 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
619 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
620
621 i = clu >> (p_bd->sector_size_bits + 3);
622 b = clu & ((p_bd->sector_size << 3) - 1);
623
624 sector = START_SECTOR(p_fs->map_clu) + i;
625
626 exfat_bitmap_clear((u8 *)p_fs->vol_amap[i]->b_data, b);
627
628 return sector_write(sb, sector, p_fs->vol_amap[i], 0);
629
630#ifdef CONFIG_EXFAT_DISCARD
631 if (opts->discard) {
632 ret = sb_issue_discard(sb, START_SECTOR(clu),
633 (1 << p_fs->sectors_per_clu_bits),
634 GFP_NOFS, 0);
635 if (ret == -EOPNOTSUPP) {
636 pr_warn("discard not supported by device, disabling");
637 opts->discard = 0;
638 }
639 }
640#endif /* CONFIG_EXFAT_DISCARD */
641}
642
643u32 test_alloc_bitmap(struct super_block *sb, u32 clu)
644{
645 int i, map_i, map_b;
646 u32 clu_base, clu_free;
647 u8 k, clu_mask;
648 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
649 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
650
651 clu_base = (clu & ~(0x7)) + 2;
652 clu_mask = (1 << (clu - clu_base + 2)) - 1;
653
654 map_i = clu >> (p_bd->sector_size_bits + 3);
655 map_b = (clu >> 3) & p_bd->sector_size_mask;
656
657 for (i = 2; i < p_fs->num_clusters; i += 8) {
658 k = *(((u8 *)p_fs->vol_amap[map_i]->b_data) + map_b);
659 if (clu_mask > 0) {
660 k |= clu_mask;
661 clu_mask = 0;
662 }
663 if (k < 0xFF) {
664 clu_free = clu_base + free_bit[k];
665 if (clu_free < p_fs->num_clusters)
666 return clu_free;
667 }
668 clu_base += 8;
669
670 if (((++map_b) >= p_bd->sector_size) ||
671 (clu_base >= p_fs->num_clusters)) {
672 if ((++map_i) >= p_fs->map_sectors) {
673 clu_base = 2;
674 map_i = 0;
675 }
676 map_b = 0;
677 }
678 }
679
680 return CLUSTER_32(~0);
681}
682
683void sync_alloc_bitmap(struct super_block *sb)
684{
685 int i;
686 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
687
688 if (!p_fs->vol_amap)
689 return;
690
691 for (i = 0; i < p_fs->map_sectors; i++)
692 sync_dirty_buffer(p_fs->vol_amap[i]);
693}
694
695/*
696 * Upcase table Management Functions
697 */
698static s32 __load_upcase_table(struct super_block *sb, sector_t sector,
699 u32 num_sectors, u32 utbl_checksum)
700{
701 int i, ret = FFS_ERROR;
702 u32 j;
703 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
704 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
705 struct buffer_head *tmp_bh = NULL;
706 sector_t end_sector = num_sectors + sector;
707
708 bool skip = false;
709 u32 index = 0;
710 u16 uni = 0;
711 u16 **upcase_table;
712
713 u32 checksum = 0;
714
715 upcase_table = p_fs->vol_utbl = kmalloc(UTBL_COL_COUNT * sizeof(u16 *),
716 GFP_KERNEL);
717 if (!upcase_table)
718 return FFS_MEMORYERR;
719 memset(upcase_table, 0, UTBL_COL_COUNT * sizeof(u16 *));
720
721 while (sector < end_sector) {
722 ret = sector_read(sb, sector, &tmp_bh, 1);
723 if (ret != FFS_SUCCESS) {
724 pr_debug("sector read (0x%llX)fail\n",
725 (unsigned long long)sector);
726 goto error;
727 }
728 sector++;
729
730 for (i = 0; i < p_bd->sector_size && index <= 0xFFFF; i += 2) {
731 uni = GET16(((u8 *)tmp_bh->b_data) + i);
732
733 checksum = ((checksum & 1) ? 0x80000000 : 0) +
734 (checksum >> 1) + *(((u8 *)tmp_bh->b_data) +
735 i);
736 checksum = ((checksum & 1) ? 0x80000000 : 0) +
737 (checksum >> 1) + *(((u8 *)tmp_bh->b_data) +
738 (i + 1));
739
740 if (skip) {
741 pr_debug("skip from 0x%X ", index);
742 index += uni;
743 pr_debug("to 0x%X (amount of 0x%X)\n",
744 index, uni);
745 skip = false;
746 } else if (uni == index) {
747 index++;
748 } else if (uni == 0xFFFF) {
749 skip = true;
750 } else { /* uni != index , uni != 0xFFFF */
751 u16 col_index = get_col_index(index);
752
753 if (!upcase_table[col_index]) {
754 pr_debug("alloc = 0x%X\n", col_index);
755 upcase_table[col_index] = kmalloc_array(UTBL_ROW_COUNT,
756 sizeof(u16), GFP_KERNEL);
757 if (!upcase_table[col_index]) {
758 ret = FFS_MEMORYERR;
759 goto error;
760 }
761
762 for (j = 0; j < UTBL_ROW_COUNT; j++)
763 upcase_table[col_index][j] = (col_index << LOW_INDEX_BIT) | j;
764 }
765
766 upcase_table[col_index][get_row_index(index)] = uni;
767 index++;
768 }
769 }
770 }
771 if (index >= 0xFFFF && utbl_checksum == checksum) {
772 if (tmp_bh)
773 brelse(tmp_bh);
774 return FFS_SUCCESS;
775 }
776 ret = FFS_ERROR;
777error:
778 if (tmp_bh)
779 brelse(tmp_bh);
780 free_upcase_table(sb);
781 return ret;
782}
783
784static s32 __load_default_upcase_table(struct super_block *sb)
785{
786 int i, ret = FFS_ERROR;
787 u32 j;
788 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
789
790 bool skip = false;
791 u32 index = 0;
792 u16 uni = 0;
793 u16 **upcase_table;
794
795 upcase_table = p_fs->vol_utbl = kmalloc(UTBL_COL_COUNT * sizeof(u16 *),
796 GFP_KERNEL);
797 if (!upcase_table)
798 return FFS_MEMORYERR;
799 memset(upcase_table, 0, UTBL_COL_COUNT * sizeof(u16 *));
800
801 for (i = 0; index <= 0xFFFF && i < NUM_UPCASE * 2; i += 2) {
802 uni = GET16(uni_upcase + i);
803 if (skip) {
804 pr_debug("skip from 0x%X ", index);
805 index += uni;
806 pr_debug("to 0x%X (amount of 0x%X)\n", index, uni);
807 skip = false;
808 } else if (uni == index) {
809 index++;
810 } else if (uni == 0xFFFF) {
811 skip = true;
812 } else { /* uni != index , uni != 0xFFFF */
813 u16 col_index = get_col_index(index);
814
815 if (!upcase_table[col_index]) {
816 pr_debug("alloc = 0x%X\n", col_index);
817 upcase_table[col_index] = kmalloc_array(UTBL_ROW_COUNT,
818 sizeof(u16),
819 GFP_KERNEL);
820 if (!upcase_table[col_index]) {
821 ret = FFS_MEMORYERR;
822 goto error;
823 }
824
825 for (j = 0; j < UTBL_ROW_COUNT; j++)
826 upcase_table[col_index][j] = (col_index << LOW_INDEX_BIT) | j;
827 }
828
829 upcase_table[col_index][get_row_index(index)] = uni;
830 index++;
831 }
832 }
833
834 if (index >= 0xFFFF)
835 return FFS_SUCCESS;
836
837error:
838 /* FATAL error: default upcase table has error */
839 free_upcase_table(sb);
840 return ret;
841}
842
843s32 load_upcase_table(struct super_block *sb)
844{
845 int i;
846 u32 tbl_clu, tbl_size;
847 sector_t sector;
848 u32 type, num_sectors;
849 struct chain_t clu;
850 struct case_dentry_t *ep;
851 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
852 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
853
854 clu.dir = p_fs->root_dir;
855 clu.flags = 0x01;
856
857 if (p_fs->dev_ejected)
858 return FFS_MEDIAERR;
859
860 while (clu.dir != CLUSTER_32(~0)) {
861 for (i = 0; i < p_fs->dentries_per_clu; i++) {
862 ep = (struct case_dentry_t *)get_entry_in_dir(sb, &clu,
863 i, NULL);
864 if (!ep)
865 return FFS_MEDIAERR;
866
867 type = p_fs->fs_func->get_entry_type((struct dentry_t *)ep);
868
869 if (type == TYPE_UNUSED)
870 break;
871 if (type != TYPE_UPCASE)
872 continue;
873
874 tbl_clu = GET32_A(ep->start_clu);
875 tbl_size = (u32)GET64_A(ep->size);
876
877 sector = START_SECTOR(tbl_clu);
878 num_sectors = ((tbl_size - 1) >> p_bd->sector_size_bits) + 1;
879 if (__load_upcase_table(sb, sector, num_sectors,
880 GET32_A(ep->checksum)) != FFS_SUCCESS)
881 break;
882 return FFS_SUCCESS;
883 }
884 if (FAT_read(sb, clu.dir, &clu.dir) != 0)
885 return FFS_MEDIAERR;
886 }
887 /* load default upcase table */
888 return __load_default_upcase_table(sb);
889}
890
891void free_upcase_table(struct super_block *sb)
892{
893 u32 i;
894 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
895 u16 **upcase_table;
896
897 upcase_table = p_fs->vol_utbl;
898 for (i = 0; i < UTBL_COL_COUNT; i++)
899 kfree(upcase_table[i]);
900
901 kfree(p_fs->vol_utbl);
902 p_fs->vol_utbl = NULL;
903}
904
905/*
906 * Directory Entry Management Functions
907 */
908
909u32 fat_get_entry_type(struct dentry_t *p_entry)
910{
911 struct dos_dentry_t *ep = (struct dos_dentry_t *)p_entry;
912
913 if (*(ep->name) == 0x0)
914 return TYPE_UNUSED;
915
916 else if (*(ep->name) == 0xE5)
917 return TYPE_DELETED;
918
919 else if (ep->attr == ATTR_EXTEND)
920 return TYPE_EXTEND;
921
922 else if ((ep->attr & (ATTR_SUBDIR | ATTR_VOLUME)) == ATTR_VOLUME)
923 return TYPE_VOLUME;
924
925 else if ((ep->attr & (ATTR_SUBDIR | ATTR_VOLUME)) == ATTR_SUBDIR)
926 return TYPE_DIR;
927
928 return TYPE_FILE;
929}
930
931u32 exfat_get_entry_type(struct dentry_t *p_entry)
932{
933 struct file_dentry_t *ep = (struct file_dentry_t *)p_entry;
934
935 if (ep->type == 0x0) {
936 return TYPE_UNUSED;
937 } else if (ep->type < 0x80) {
938 return TYPE_DELETED;
939 } else if (ep->type == 0x80) {
940 return TYPE_INVALID;
941 } else if (ep->type < 0xA0) {
942 if (ep->type == 0x81) {
943 return TYPE_BITMAP;
944 } else if (ep->type == 0x82) {
945 return TYPE_UPCASE;
946 } else if (ep->type == 0x83) {
947 return TYPE_VOLUME;
948 } else if (ep->type == 0x85) {
949 if (GET16_A(ep->attr) & ATTR_SUBDIR)
950 return TYPE_DIR;
951 else
952 return TYPE_FILE;
953 }
954 return TYPE_CRITICAL_PRI;
955 } else if (ep->type < 0xC0) {
956 if (ep->type == 0xA0)
957 return TYPE_GUID;
958 else if (ep->type == 0xA1)
959 return TYPE_PADDING;
960 else if (ep->type == 0xA2)
961 return TYPE_ACLTAB;
962 return TYPE_BENIGN_PRI;
963 } else if (ep->type < 0xE0) {
964 if (ep->type == 0xC0)
965 return TYPE_STREAM;
966 else if (ep->type == 0xC1)
967 return TYPE_EXTEND;
968 else if (ep->type == 0xC2)
969 return TYPE_ACL;
970 return TYPE_CRITICAL_SEC;
971 }
972
973 return TYPE_BENIGN_SEC;
974}
975
976void fat_set_entry_type(struct dentry_t *p_entry, u32 type)
977{
978 struct dos_dentry_t *ep = (struct dos_dentry_t *)p_entry;
979
980 if (type == TYPE_UNUSED)
981 *(ep->name) = 0x0;
982
983 else if (type == TYPE_DELETED)
984 *(ep->name) = 0xE5;
985
986 else if (type == TYPE_EXTEND)
987 ep->attr = ATTR_EXTEND;
988
989 else if (type == TYPE_DIR)
990 ep->attr = ATTR_SUBDIR;
991
992 else if (type == TYPE_FILE)
993 ep->attr = ATTR_ARCHIVE;
994
995 else if (type == TYPE_SYMLINK)
996 ep->attr = ATTR_ARCHIVE | ATTR_SYMLINK;
997}
998
999void exfat_set_entry_type(struct dentry_t *p_entry, u32 type)
1000{
1001 struct file_dentry_t *ep = (struct file_dentry_t *)p_entry;
1002
1003 if (type == TYPE_UNUSED) {
1004 ep->type = 0x0;
1005 } else if (type == TYPE_DELETED) {
1006 ep->type &= ~0x80;
1007 } else if (type == TYPE_STREAM) {
1008 ep->type = 0xC0;
1009 } else if (type == TYPE_EXTEND) {
1010 ep->type = 0xC1;
1011 } else if (type == TYPE_BITMAP) {
1012 ep->type = 0x81;
1013 } else if (type == TYPE_UPCASE) {
1014 ep->type = 0x82;
1015 } else if (type == TYPE_VOLUME) {
1016 ep->type = 0x83;
1017 } else if (type == TYPE_DIR) {
1018 ep->type = 0x85;
1019 SET16_A(ep->attr, ATTR_SUBDIR);
1020 } else if (type == TYPE_FILE) {
1021 ep->type = 0x85;
1022 SET16_A(ep->attr, ATTR_ARCHIVE);
1023 } else if (type == TYPE_SYMLINK) {
1024 ep->type = 0x85;
1025 SET16_A(ep->attr, ATTR_ARCHIVE | ATTR_SYMLINK);
1026 }
1027}
1028
1029u32 fat_get_entry_attr(struct dentry_t *p_entry)
1030{
1031 struct dos_dentry_t *ep = (struct dos_dentry_t *)p_entry;
1032
1033 return (u32)ep->attr;
1034}
1035
1036u32 exfat_get_entry_attr(struct dentry_t *p_entry)
1037{
1038 struct file_dentry_t *ep = (struct file_dentry_t *)p_entry;
1039
1040 return (u32)GET16_A(ep->attr);
1041}
1042
1043void fat_set_entry_attr(struct dentry_t *p_entry, u32 attr)
1044{
1045 struct dos_dentry_t *ep = (struct dos_dentry_t *)p_entry;
1046
1047 ep->attr = (u8)attr;
1048}
1049
1050void exfat_set_entry_attr(struct dentry_t *p_entry, u32 attr)
1051{
1052 struct file_dentry_t *ep = (struct file_dentry_t *)p_entry;
1053
1054 SET16_A(ep->attr, (u16)attr);
1055}
1056
1057u8 fat_get_entry_flag(struct dentry_t *p_entry)
1058{
1059 return 0x01;
1060}
1061
1062u8 exfat_get_entry_flag(struct dentry_t *p_entry)
1063{
1064 struct strm_dentry_t *ep = (struct strm_dentry_t *)p_entry;
1065
1066 return ep->flags;
1067}
1068
1069void fat_set_entry_flag(struct dentry_t *p_entry, u8 flags)
1070{
1071}
1072
1073void exfat_set_entry_flag(struct dentry_t *p_entry, u8 flags)
1074{
1075 struct strm_dentry_t *ep = (struct strm_dentry_t *)p_entry;
1076
1077 ep->flags = flags;
1078}
1079
1080u32 fat_get_entry_clu0(struct dentry_t *p_entry)
1081{
1082 struct dos_dentry_t *ep = (struct dos_dentry_t *)p_entry;
1083
1084 return ((u32)GET16_A(ep->start_clu_hi) << 16) |
1085 GET16_A(ep->start_clu_lo);
1086}
1087
1088u32 exfat_get_entry_clu0(struct dentry_t *p_entry)
1089{
1090 struct strm_dentry_t *ep = (struct strm_dentry_t *)p_entry;
1091
1092 return GET32_A(ep->start_clu);
1093}
1094
1095void fat_set_entry_clu0(struct dentry_t *p_entry, u32 start_clu)
1096{
1097 struct dos_dentry_t *ep = (struct dos_dentry_t *)p_entry;
1098
1099 SET16_A(ep->start_clu_lo, CLUSTER_16(start_clu));
1100 SET16_A(ep->start_clu_hi, CLUSTER_16(start_clu >> 16));
1101}
1102
1103void exfat_set_entry_clu0(struct dentry_t *p_entry, u32 start_clu)
1104{
1105 struct strm_dentry_t *ep = (struct strm_dentry_t *)p_entry;
1106
1107 SET32_A(ep->start_clu, start_clu);
1108}
1109
1110u64 fat_get_entry_size(struct dentry_t *p_entry)
1111{
1112 struct dos_dentry_t *ep = (struct dos_dentry_t *)p_entry;
1113
1114 return (u64)GET32_A(ep->size);
1115}
1116
1117u64 exfat_get_entry_size(struct dentry_t *p_entry)
1118{
1119 struct strm_dentry_t *ep = (struct strm_dentry_t *)p_entry;
1120
1121 return GET64_A(ep->valid_size);
1122}
1123
1124void fat_set_entry_size(struct dentry_t *p_entry, u64 size)
1125{
1126 struct dos_dentry_t *ep = (struct dos_dentry_t *)p_entry;
1127
1128 SET32_A(ep->size, (u32)size);
1129}
1130
1131void exfat_set_entry_size(struct dentry_t *p_entry, u64 size)
1132{
1133 struct strm_dentry_t *ep = (struct strm_dentry_t *)p_entry;
1134
1135 SET64_A(ep->valid_size, size);
1136 SET64_A(ep->size, size);
1137}
1138
1139void fat_get_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
1140 u8 mode)
1141{
1142 u16 t = 0x00, d = 0x21;
1143 struct dos_dentry_t *ep = (struct dos_dentry_t *)p_entry;
1144
1145 switch (mode) {
1146 case TM_CREATE:
1147 t = GET16_A(ep->create_time);
1148 d = GET16_A(ep->create_date);
1149 break;
1150 case TM_MODIFY:
1151 t = GET16_A(ep->modify_time);
1152 d = GET16_A(ep->modify_date);
1153 break;
1154 }
1155
1156 tp->sec = (t & 0x001F) << 1;
1157 tp->min = (t >> 5) & 0x003F;
1158 tp->hour = (t >> 11);
1159 tp->day = (d & 0x001F);
1160 tp->mon = (d >> 5) & 0x000F;
1161 tp->year = (d >> 9);
1162}
1163
1164void exfat_get_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
1165 u8 mode)
1166{
1167 u16 t = 0x00, d = 0x21;
1168 struct file_dentry_t *ep = (struct file_dentry_t *)p_entry;
1169
1170 switch (mode) {
1171 case TM_CREATE:
1172 t = GET16_A(ep->create_time);
1173 d = GET16_A(ep->create_date);
1174 break;
1175 case TM_MODIFY:
1176 t = GET16_A(ep->modify_time);
1177 d = GET16_A(ep->modify_date);
1178 break;
1179 case TM_ACCESS:
1180 t = GET16_A(ep->access_time);
1181 d = GET16_A(ep->access_date);
1182 break;
1183 }
1184
1185 tp->sec = (t & 0x001F) << 1;
1186 tp->min = (t >> 5) & 0x003F;
1187 tp->hour = (t >> 11);
1188 tp->day = (d & 0x001F);
1189 tp->mon = (d >> 5) & 0x000F;
1190 tp->year = (d >> 9);
1191}
1192
1193void fat_set_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
1194 u8 mode)
1195{
1196 u16 t, d;
1197 struct dos_dentry_t *ep = (struct dos_dentry_t *)p_entry;
1198
1199 t = (tp->hour << 11) | (tp->min << 5) | (tp->sec >> 1);
1200 d = (tp->year << 9) | (tp->mon << 5) | tp->day;
1201
1202 switch (mode) {
1203 case TM_CREATE:
1204 SET16_A(ep->create_time, t);
1205 SET16_A(ep->create_date, d);
1206 break;
1207 case TM_MODIFY:
1208 SET16_A(ep->modify_time, t);
1209 SET16_A(ep->modify_date, d);
1210 break;
1211 }
1212}
1213
1214void exfat_set_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
1215 u8 mode)
1216{
1217 u16 t, d;
1218 struct file_dentry_t *ep = (struct file_dentry_t *)p_entry;
1219
1220 t = (tp->hour << 11) | (tp->min << 5) | (tp->sec >> 1);
1221 d = (tp->year << 9) | (tp->mon << 5) | tp->day;
1222
1223 switch (mode) {
1224 case TM_CREATE:
1225 SET16_A(ep->create_time, t);
1226 SET16_A(ep->create_date, d);
1227 break;
1228 case TM_MODIFY:
1229 SET16_A(ep->modify_time, t);
1230 SET16_A(ep->modify_date, d);
1231 break;
1232 case TM_ACCESS:
1233 SET16_A(ep->access_time, t);
1234 SET16_A(ep->access_date, d);
1235 break;
1236 }
1237}
1238
1239s32 fat_init_dir_entry(struct super_block *sb, struct chain_t *p_dir, s32 entry,
1240 u32 type, u32 start_clu, u64 size)
1241{
1242 sector_t sector;
1243 struct dos_dentry_t *dos_ep;
1244
1245 dos_ep = (struct dos_dentry_t *)get_entry_in_dir(sb, p_dir, entry,
1246 &sector);
1247 if (!dos_ep)
1248 return FFS_MEDIAERR;
1249
1250 init_dos_entry(dos_ep, type, start_clu);
1251 buf_modify(sb, sector);
1252
1253 return FFS_SUCCESS;
1254}
1255
1256s32 exfat_init_dir_entry(struct super_block *sb, struct chain_t *p_dir,
1257 s32 entry, u32 type, u32 start_clu, u64 size)
1258{
1259 sector_t sector;
1260 u8 flags;
1261 struct file_dentry_t *file_ep;
1262 struct strm_dentry_t *strm_ep;
1263
1264 flags = (type == TYPE_FILE) ? 0x01 : 0x03;
1265
1266 /* we cannot use get_entry_set_in_dir here because file ep is not initialized yet */
1267 file_ep = (struct file_dentry_t *)get_entry_in_dir(sb, p_dir, entry,
1268 &sector);
1269 if (!file_ep)
1270 return FFS_MEDIAERR;
1271
1272 strm_ep = (struct strm_dentry_t *)get_entry_in_dir(sb, p_dir, entry + 1,
1273 &sector);
1274 if (!strm_ep)
1275 return FFS_MEDIAERR;
1276
1277 init_file_entry(file_ep, type);
1278 buf_modify(sb, sector);
1279
1280 init_strm_entry(strm_ep, flags, start_clu, size);
1281 buf_modify(sb, sector);
1282
1283 return FFS_SUCCESS;
1284}
1285
1286static s32 fat_init_ext_entry(struct super_block *sb, struct chain_t *p_dir,
1287 s32 entry, s32 num_entries,
1288 struct uni_name_t *p_uniname,
1289 struct dos_name_t *p_dosname)
1290{
1291 int i;
1292 sector_t sector;
1293 u8 chksum;
1294 u16 *uniname = p_uniname->name;
1295 struct dos_dentry_t *dos_ep;
1296 struct ext_dentry_t *ext_ep;
1297
1298 dos_ep = (struct dos_dentry_t *)get_entry_in_dir(sb, p_dir, entry,
1299 &sector);
1300 if (!dos_ep)
1301 return FFS_MEDIAERR;
1302
1303 dos_ep->lcase = p_dosname->name_case;
1304 memcpy(dos_ep->name, p_dosname->name, DOS_NAME_LENGTH);
1305 buf_modify(sb, sector);
1306
1307 if ((--num_entries) > 0) {
1308 chksum = calc_checksum_1byte((void *)dos_ep->name,
1309 DOS_NAME_LENGTH, 0);
1310
1311 for (i = 1; i < num_entries; i++) {
1312 ext_ep = (struct ext_dentry_t *)get_entry_in_dir(sb,
1313 p_dir,
1314 entry - i,
1315 &sector);
1316 if (!ext_ep)
1317 return FFS_MEDIAERR;
1318
1319 init_ext_entry(ext_ep, i, chksum, uniname);
1320 buf_modify(sb, sector);
1321 uniname += 13;
1322 }
1323
1324 ext_ep = (struct ext_dentry_t *)get_entry_in_dir(sb, p_dir,
1325 entry - i,
1326 &sector);
1327 if (!ext_ep)
1328 return FFS_MEDIAERR;
1329
1330 init_ext_entry(ext_ep, i + 0x40, chksum, uniname);
1331 buf_modify(sb, sector);
1332 }
1333
1334 return FFS_SUCCESS;
1335}
1336
1337static s32 exfat_init_ext_entry(struct super_block *sb, struct chain_t *p_dir,
1338 s32 entry, s32 num_entries,
1339 struct uni_name_t *p_uniname,
1340 struct dos_name_t *p_dosname)
1341{
1342 int i;
1343 sector_t sector;
1344 u16 *uniname = p_uniname->name;
1345 struct file_dentry_t *file_ep;
1346 struct strm_dentry_t *strm_ep;
1347 struct name_dentry_t *name_ep;
1348
1349 file_ep = (struct file_dentry_t *)get_entry_in_dir(sb, p_dir, entry,
1350 &sector);
1351 if (!file_ep)
1352 return FFS_MEDIAERR;
1353
1354 file_ep->num_ext = (u8)(num_entries - 1);
1355 buf_modify(sb, sector);
1356
1357 strm_ep = (struct strm_dentry_t *)get_entry_in_dir(sb, p_dir, entry + 1,
1358 &sector);
1359 if (!strm_ep)
1360 return FFS_MEDIAERR;
1361
1362 strm_ep->name_len = p_uniname->name_len;
1363 SET16_A(strm_ep->name_hash, p_uniname->name_hash);
1364 buf_modify(sb, sector);
1365
1366 for (i = 2; i < num_entries; i++) {
1367 name_ep = (struct name_dentry_t *)get_entry_in_dir(sb, p_dir,
1368 entry + i,
1369 &sector);
1370 if (!name_ep)
1371 return FFS_MEDIAERR;
1372
1373 init_name_entry(name_ep, uniname);
1374 buf_modify(sb, sector);
1375 uniname += 15;
1376 }
1377
1378 update_dir_checksum(sb, p_dir, entry);
1379
1380 return FFS_SUCCESS;
1381}
1382
1383void init_dos_entry(struct dos_dentry_t *ep, u32 type, u32 start_clu)
1384{
1385 struct timestamp_t tm, *tp;
1386
1387 fat_set_entry_type((struct dentry_t *)ep, type);
1388 SET16_A(ep->start_clu_lo, CLUSTER_16(start_clu));
1389 SET16_A(ep->start_clu_hi, CLUSTER_16(start_clu >> 16));
1390 SET32_A(ep->size, 0);
1391
1392 tp = tm_current(&tm);
1393 fat_set_entry_time((struct dentry_t *)ep, tp, TM_CREATE);
1394 fat_set_entry_time((struct dentry_t *)ep, tp, TM_MODIFY);
1395 SET16_A(ep->access_date, 0);
1396 ep->create_time_ms = 0;
1397}
1398
1399void init_ext_entry(struct ext_dentry_t *ep, s32 order, u8 chksum, u16 *uniname)
1400{
1401 int i;
1402 bool end = false;
1403
1404 fat_set_entry_type((struct dentry_t *)ep, TYPE_EXTEND);
1405 ep->order = (u8)order;
1406 ep->sysid = 0;
1407 ep->checksum = chksum;
1408 SET16_A(ep->start_clu, 0);
1409
1410 for (i = 0; i < 10; i += 2) {
1411 if (!end) {
1412 SET16(ep->unicode_0_4 + i, *uniname);
1413 if (*uniname == 0x0)
1414 end = true;
1415 else
1416 uniname++;
1417 } else {
1418 SET16(ep->unicode_0_4 + i, 0xFFFF);
1419 }
1420 }
1421
1422 for (i = 0; i < 12; i += 2) {
1423 if (!end) {
1424 SET16_A(ep->unicode_5_10 + i, *uniname);
1425 if (*uniname == 0x0)
1426 end = true;
1427 else
1428 uniname++;
1429 } else {
1430 SET16_A(ep->unicode_5_10 + i, 0xFFFF);
1431 }
1432 }
1433
1434 for (i = 0; i < 4; i += 2) {
1435 if (!end) {
1436 SET16_A(ep->unicode_11_12 + i, *uniname);
1437 if (*uniname == 0x0)
1438 end = true;
1439 else
1440 uniname++;
1441 } else {
1442 SET16_A(ep->unicode_11_12 + i, 0xFFFF);
1443 }
1444 }
1445}
1446
1447void init_file_entry(struct file_dentry_t *ep, u32 type)
1448{
1449 struct timestamp_t tm, *tp;
1450
1451 exfat_set_entry_type((struct dentry_t *)ep, type);
1452
1453 tp = tm_current(&tm);
1454 exfat_set_entry_time((struct dentry_t *)ep, tp, TM_CREATE);
1455 exfat_set_entry_time((struct dentry_t *)ep, tp, TM_MODIFY);
1456 exfat_set_entry_time((struct dentry_t *)ep, tp, TM_ACCESS);
1457 ep->create_time_ms = 0;
1458 ep->modify_time_ms = 0;
1459 ep->access_time_ms = 0;
1460}
1461
1462void init_strm_entry(struct strm_dentry_t *ep, u8 flags, u32 start_clu, u64 size)
1463{
1464 exfat_set_entry_type((struct dentry_t *)ep, TYPE_STREAM);
1465 ep->flags = flags;
1466 SET32_A(ep->start_clu, start_clu);
1467 SET64_A(ep->valid_size, size);
1468 SET64_A(ep->size, size);
1469}
1470
1471void init_name_entry(struct name_dentry_t *ep, u16 *uniname)
1472{
1473 int i;
1474
1475 exfat_set_entry_type((struct dentry_t *)ep, TYPE_EXTEND);
1476 ep->flags = 0x0;
1477
1478 for (i = 0; i < 30; i++, i++) {
1479 SET16_A(ep->unicode_0_14 + i, *uniname);
1480 if (*uniname == 0x0)
1481 break;
1482 uniname++;
1483 }
1484}
1485
1486void fat_delete_dir_entry(struct super_block *sb, struct chain_t *p_dir,
1487 s32 entry, s32 order, s32 num_entries)
1488{
1489 int i;
1490 sector_t sector;
1491 struct dentry_t *ep;
1492 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1493
1494 for (i = num_entries - 1; i >= order; i--) {
1495 ep = get_entry_in_dir(sb, p_dir, entry - i, &sector);
1496 if (!ep)
1497 return;
1498
1499 p_fs->fs_func->set_entry_type(ep, TYPE_DELETED);
1500 buf_modify(sb, sector);
1501 }
1502}
1503
1504void exfat_delete_dir_entry(struct super_block *sb, struct chain_t *p_dir,
1505 s32 entry, s32 order, s32 num_entries)
1506{
1507 int i;
1508 sector_t sector;
1509 struct dentry_t *ep;
1510 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1511
1512 for (i = order; i < num_entries; i++) {
1513 ep = get_entry_in_dir(sb, p_dir, entry + i, &sector);
1514 if (!ep)
1515 return;
1516
1517 p_fs->fs_func->set_entry_type(ep, TYPE_DELETED);
1518 buf_modify(sb, sector);
1519 }
1520}
1521
1522void update_dir_checksum(struct super_block *sb, struct chain_t *p_dir,
1523 s32 entry)
1524{
1525 int i, num_entries;
1526 sector_t sector;
1527 u16 chksum;
1528 struct file_dentry_t *file_ep;
1529 struct dentry_t *ep;
1530
1531 file_ep = (struct file_dentry_t *)get_entry_in_dir(sb, p_dir, entry,
1532 &sector);
1533 if (!file_ep)
1534 return;
1535
1536 buf_lock(sb, sector);
1537
1538 num_entries = (s32)file_ep->num_ext + 1;
1539 chksum = calc_checksum_2byte((void *)file_ep, DENTRY_SIZE, 0,
1540 CS_DIR_ENTRY);
1541
1542 for (i = 1; i < num_entries; i++) {
1543 ep = get_entry_in_dir(sb, p_dir, entry + i, NULL);
1544 if (!ep) {
1545 buf_unlock(sb, sector);
1546 return;
1547 }
1548
1549 chksum = calc_checksum_2byte((void *)ep, DENTRY_SIZE, chksum,
1550 CS_DEFAULT);
1551 }
1552
1553 SET16_A(file_ep->checksum, chksum);
1554 buf_modify(sb, sector);
1555 buf_unlock(sb, sector);
1556}
1557
1558void update_dir_checksum_with_entry_set(struct super_block *sb,
1559 struct entry_set_cache_t *es)
1560{
1561 struct dentry_t *ep;
1562 u16 chksum = 0;
1563 s32 chksum_type = CS_DIR_ENTRY, i;
1564
1565 ep = (struct dentry_t *)&(es->__buf);
1566 for (i = 0; i < es->num_entries; i++) {
1567 pr_debug("%s ep %p\n", __func__, ep);
1568 chksum = calc_checksum_2byte((void *)ep, DENTRY_SIZE, chksum,
1569 chksum_type);
1570 ep++;
1571 chksum_type = CS_DEFAULT;
1572 }
1573
1574 ep = (struct dentry_t *)&(es->__buf);
1575 SET16_A(((struct file_dentry_t *)ep)->checksum, chksum);
1576 write_whole_entry_set(sb, es);
1577}
1578
1579static s32 _walk_fat_chain(struct super_block *sb, struct chain_t *p_dir,
1580 s32 byte_offset, u32 *clu)
1581{
1582 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1583 s32 clu_offset;
1584 u32 cur_clu;
1585
1586 clu_offset = byte_offset >> p_fs->cluster_size_bits;
1587 cur_clu = p_dir->dir;
1588
1589 if (p_dir->flags == 0x03) {
1590 cur_clu += clu_offset;
1591 } else {
1592 while (clu_offset > 0) {
1593 if (FAT_read(sb, cur_clu, &cur_clu) == -1)
1594 return FFS_MEDIAERR;
1595 clu_offset--;
1596 }
1597 }
1598
1599 if (clu)
1600 *clu = cur_clu;
1601 return FFS_SUCCESS;
1602}
1603
1604s32 find_location(struct super_block *sb, struct chain_t *p_dir, s32 entry,
1605 sector_t *sector, s32 *offset)
1606{
1607 s32 off, ret;
1608 u32 clu = 0;
1609 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1610 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
1611
1612 off = entry << DENTRY_SIZE_BITS;
1613
1614 if (p_dir->dir == CLUSTER_32(0)) { /* FAT16 root_dir */
1615 *offset = off & p_bd->sector_size_mask;
1616 *sector = off >> p_bd->sector_size_bits;
1617 *sector += p_fs->root_start_sector;
1618 } else {
1619 ret = _walk_fat_chain(sb, p_dir, off, &clu);
1620 if (ret != FFS_SUCCESS)
1621 return ret;
1622
1623 /* byte offset in cluster */
1624 off &= p_fs->cluster_size - 1;
1625
1626 /* byte offset in sector */
1627 *offset = off & p_bd->sector_size_mask;
1628
1629 /* sector offset in cluster */
1630 *sector = off >> p_bd->sector_size_bits;
1631 *sector += START_SECTOR(clu);
1632 }
1633 return FFS_SUCCESS;
1634}
1635
1636struct dentry_t *get_entry_with_sector(struct super_block *sb, sector_t sector,
1637 s32 offset)
1638{
1639 u8 *buf;
1640
1641 buf = buf_getblk(sb, sector);
1642
1643 if (!buf)
1644 return NULL;
1645
1646 return (struct dentry_t *)(buf + offset);
1647}
1648
1649struct dentry_t *get_entry_in_dir(struct super_block *sb, struct chain_t *p_dir,
1650 s32 entry, sector_t *sector)
1651{
1652 s32 off;
1653 sector_t sec;
1654 u8 *buf;
1655
1656 if (find_location(sb, p_dir, entry, &sec, &off) != FFS_SUCCESS)
1657 return NULL;
1658
1659 buf = buf_getblk(sb, sec);
1660
1661 if (!buf)
1662 return NULL;
1663
1664 if (sector)
1665 *sector = sec;
1666 return (struct dentry_t *)(buf + off);
1667}
1668
1669/* returns a set of dentries for a file or dir.
1670 * Note that this is a copy (dump) of dentries so that user should call write_entry_set()
1671 * to apply changes made in this entry set to the real device.
1672 * in:
1673 * sb+p_dir+entry: indicates a file/dir
1674 * type: specifies how many dentries should be included.
1675 * out:
1676 * file_ep: will point the first dentry(= file dentry) on success
1677 * return:
1678 * pointer of entry set on success,
1679 * NULL on failure.
1680 */
1681
1682#define ES_MODE_STARTED 0
1683#define ES_MODE_GET_FILE_ENTRY 1
1684#define ES_MODE_GET_STRM_ENTRY 2
1685#define ES_MODE_GET_NAME_ENTRY 3
1686#define ES_MODE_GET_CRITICAL_SEC_ENTRY 4
1687struct entry_set_cache_t *get_entry_set_in_dir(struct super_block *sb,
1688 struct chain_t *p_dir, s32 entry,
1689 u32 type,
1690 struct dentry_t **file_ep)
1691{
1692 s32 off, ret, byte_offset;
1693 u32 clu = 0;
1694 sector_t sec;
1695 u32 entry_type;
1696 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1697 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
1698 struct entry_set_cache_t *es = NULL;
1699 struct dentry_t *ep, *pos;
1700 u8 *buf;
1701 u8 num_entries;
1702 s32 mode = ES_MODE_STARTED;
1703 size_t bufsize;
1704
1705 pr_debug("%s entered p_dir dir %u flags %x size %d\n",
1706 __func__, p_dir->dir, p_dir->flags, p_dir->size);
1707
1708 byte_offset = entry << DENTRY_SIZE_BITS;
1709 ret = _walk_fat_chain(sb, p_dir, byte_offset, &clu);
1710 if (ret != FFS_SUCCESS)
1711 return NULL;
1712
1713 /* byte offset in cluster */
1714 byte_offset &= p_fs->cluster_size - 1;
1715
1716 /* byte offset in sector */
1717 off = byte_offset & p_bd->sector_size_mask;
1718
1719 /* sector offset in cluster */
1720 sec = byte_offset >> p_bd->sector_size_bits;
1721 sec += START_SECTOR(clu);
1722
1723 buf = buf_getblk(sb, sec);
1724 if (!buf)
1725 goto err_out;
1726
1727 ep = (struct dentry_t *)(buf + off);
1728 entry_type = p_fs->fs_func->get_entry_type(ep);
1729
1730 if ((entry_type != TYPE_FILE)
1731 && (entry_type != TYPE_DIR))
1732 goto err_out;
1733
1734 if (type == ES_ALL_ENTRIES)
1735 num_entries = ((struct file_dentry_t *)ep)->num_ext + 1;
1736 else
1737 num_entries = type;
1738
1739 bufsize = offsetof(struct entry_set_cache_t, __buf) + (num_entries) *
1740 sizeof(struct dentry_t);
1741 pr_debug("%s: trying to kmalloc %zx bytes for %d entries\n", __func__,
1742 bufsize, num_entries);
1743 es = kmalloc(bufsize, GFP_KERNEL);
1744 if (!es)
1745 goto err_out;
1746
1747 es->num_entries = num_entries;
1748 es->sector = sec;
1749 es->offset = off;
1750 es->alloc_flag = p_dir->flags;
1751
1752 pos = (struct dentry_t *)&es->__buf;
1753
1754 while (num_entries) {
1755 /*
1756 * instead of copying whole sector, we will check every entry.
1757 * this will provide minimum stablity and consistency.
1758 */
1759 entry_type = p_fs->fs_func->get_entry_type(ep);
1760
1761 if ((entry_type == TYPE_UNUSED) || (entry_type == TYPE_DELETED))
1762 goto err_out;
1763
1764 switch (mode) {
1765 case ES_MODE_STARTED:
1766 if ((entry_type == TYPE_FILE) || (entry_type == TYPE_DIR))
1767 mode = ES_MODE_GET_FILE_ENTRY;
1768 else
1769 goto err_out;
1770 break;
1771 case ES_MODE_GET_FILE_ENTRY:
1772 if (entry_type == TYPE_STREAM)
1773 mode = ES_MODE_GET_STRM_ENTRY;
1774 else
1775 goto err_out;
1776 break;
1777 case ES_MODE_GET_STRM_ENTRY:
1778 if (entry_type == TYPE_EXTEND)
1779 mode = ES_MODE_GET_NAME_ENTRY;
1780 else
1781 goto err_out;
1782 break;
1783 case ES_MODE_GET_NAME_ENTRY:
1784 if (entry_type == TYPE_EXTEND)
1785 break;
1786 else if (entry_type == TYPE_STREAM)
1787 goto err_out;
1788 else if (entry_type & TYPE_CRITICAL_SEC)
1789 mode = ES_MODE_GET_CRITICAL_SEC_ENTRY;
1790 else
1791 goto err_out;
1792 break;
1793 case ES_MODE_GET_CRITICAL_SEC_ENTRY:
1794 if ((entry_type == TYPE_EXTEND) ||
1795 (entry_type == TYPE_STREAM))
1796 goto err_out;
1797 else if ((entry_type & TYPE_CRITICAL_SEC) !=
1798 TYPE_CRITICAL_SEC)
1799 goto err_out;
1800 break;
1801 }
1802
1803 memcpy(pos, ep, sizeof(struct dentry_t));
1804
1805 if (--num_entries == 0)
1806 break;
1807
1808 if (((off + DENTRY_SIZE) & p_bd->sector_size_mask) <
1809 (off & p_bd->sector_size_mask)) {
1810 /* get the next sector */
1811 if (IS_LAST_SECTOR_IN_CLUSTER(sec)) {
1812 if (es->alloc_flag == 0x03) {
1813 clu++;
1814 } else {
1815 if (FAT_read(sb, clu, &clu) == -1)
1816 goto err_out;
1817 }
1818 sec = START_SECTOR(clu);
1819 } else {
1820 sec++;
1821 }
1822 buf = buf_getblk(sb, sec);
1823 if (!buf)
1824 goto err_out;
1825 off = 0;
1826 ep = (struct dentry_t *)(buf);
1827 } else {
1828 ep++;
1829 off += DENTRY_SIZE;
1830 }
1831 pos++;
1832 }
1833
1834 if (file_ep)
1835 *file_ep = (struct dentry_t *)&(es->__buf);
1836
1837 pr_debug("%s exiting es %p sec %llu offset %d flags %d, num_entries %u buf ptr %p\n",
1838 __func__, es, (unsigned long long)es->sector, es->offset,
1839 es->alloc_flag, es->num_entries, &es->__buf);
1840 return es;
1841err_out:
1842 pr_debug("%s exited NULL (es %p)\n", __func__, es);
1843 kfree(es);
1844 return NULL;
1845}
1846
1847void release_entry_set(struct entry_set_cache_t *es)
1848{
1849 pr_debug("%s es=%p\n", __func__, es);
1850 kfree(es);
1851}
1852
1853static s32 __write_partial_entries_in_entry_set(struct super_block *sb,
1854 struct entry_set_cache_t *es,
1855 sector_t sec, s32 off, u32 count)
1856{
1857 s32 num_entries, buf_off = (off - es->offset);
1858 u32 remaining_byte_in_sector, copy_entries;
1859 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1860 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
1861 u32 clu;
1862 u8 *buf, *esbuf = (u8 *)&(es->__buf);
1863
1864 pr_debug("%s entered es %p sec %llu off %d count %d\n",
1865 __func__, es, (unsigned long long)sec, off, count);
1866 num_entries = count;
1867
1868 while (num_entries) {
1869 /* white per sector base */
1870 remaining_byte_in_sector = (1 << p_bd->sector_size_bits) - off;
1871 copy_entries = min_t(s32,
1872 remaining_byte_in_sector >> DENTRY_SIZE_BITS,
1873 num_entries);
1874 buf = buf_getblk(sb, sec);
1875 if (!buf)
1876 goto err_out;
1877 pr_debug("es->buf %p buf_off %u\n", esbuf, buf_off);
1878 pr_debug("copying %d entries from %p to sector %llu\n",
1879 copy_entries, (esbuf + buf_off),
1880 (unsigned long long)sec);
1881 memcpy(buf + off, esbuf + buf_off,
1882 copy_entries << DENTRY_SIZE_BITS);
1883 buf_modify(sb, sec);
1884 num_entries -= copy_entries;
1885
1886 if (num_entries) {
1887 /* get next sector */
1888 if (IS_LAST_SECTOR_IN_CLUSTER(sec)) {
1889 clu = GET_CLUSTER_FROM_SECTOR(sec);
1890 if (es->alloc_flag == 0x03) {
1891 clu++;
1892 } else {
1893 if (FAT_read(sb, clu, &clu) == -1)
1894 goto err_out;
1895 }
1896 sec = START_SECTOR(clu);
1897 } else {
1898 sec++;
1899 }
1900 off = 0;
1901 buf_off += copy_entries << DENTRY_SIZE_BITS;
1902 }
1903 }
1904
1905 pr_debug("%s exited successfully\n", __func__);
1906 return FFS_SUCCESS;
1907err_out:
1908 pr_debug("%s failed\n", __func__);
1909 return FFS_ERROR;
1910}
1911
1912/* write back all entries in entry set */
1913s32 write_whole_entry_set(struct super_block *sb, struct entry_set_cache_t *es)
1914{
1915 return __write_partial_entries_in_entry_set(sb, es, es->sector,
1916 es->offset,
1917 es->num_entries);
1918}
1919
1920/* write back some entries in entry set */
1921s32 write_partial_entries_in_entry_set(struct super_block *sb,
1922 struct entry_set_cache_t *es, struct dentry_t *ep, u32 count)
1923{
1924 s32 ret, byte_offset, off;
1925 u32 clu = 0;
1926 sector_t sec;
1927 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1928 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
1929 struct chain_t dir;
1930
1931 /* vaidity check */
1932 if (ep + count > ((struct dentry_t *)&(es->__buf)) + es->num_entries)
1933 return FFS_ERROR;
1934
1935 dir.dir = GET_CLUSTER_FROM_SECTOR(es->sector);
1936 dir.flags = es->alloc_flag;
1937 dir.size = 0xffffffff; /* XXX */
1938
1939 byte_offset = (es->sector - START_SECTOR(dir.dir)) <<
1940 p_bd->sector_size_bits;
1941 byte_offset += ((void **)ep - &(es->__buf)) + es->offset;
1942
1943 ret = _walk_fat_chain(sb, &dir, byte_offset, &clu);
1944 if (ret != FFS_SUCCESS)
1945 return ret;
1946
1947 /* byte offset in cluster */
1948 byte_offset &= p_fs->cluster_size - 1;
1949
1950 /* byte offset in sector */
1951 off = byte_offset & p_bd->sector_size_mask;
1952
1953 /* sector offset in cluster */
1954 sec = byte_offset >> p_bd->sector_size_bits;
1955 sec += START_SECTOR(clu);
1956 return __write_partial_entries_in_entry_set(sb, es, sec, off, count);
1957}
1958
1959/* search EMPTY CONTINUOUS "num_entries" entries */
1960s32 search_deleted_or_unused_entry(struct super_block *sb,
1961 struct chain_t *p_dir, s32 num_entries)
1962{
1963 int i, dentry, num_empty = 0;
1964 s32 dentries_per_clu;
1965 u32 type;
1966 struct chain_t clu;
1967 struct dentry_t *ep;
1968 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1969
1970 if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */
1971 dentries_per_clu = p_fs->dentries_in_root;
1972 else
1973 dentries_per_clu = p_fs->dentries_per_clu;
1974
1975 if (p_fs->hint_uentry.dir == p_dir->dir) {
1976 if (p_fs->hint_uentry.entry == -1)
1977 return -1;
1978
1979 clu.dir = p_fs->hint_uentry.clu.dir;
1980 clu.size = p_fs->hint_uentry.clu.size;
1981 clu.flags = p_fs->hint_uentry.clu.flags;
1982
1983 dentry = p_fs->hint_uentry.entry;
1984 } else {
1985 p_fs->hint_uentry.entry = -1;
1986
1987 clu.dir = p_dir->dir;
1988 clu.size = p_dir->size;
1989 clu.flags = p_dir->flags;
1990
1991 dentry = 0;
1992 }
1993
1994 while (clu.dir != CLUSTER_32(~0)) {
1995 if (p_fs->dev_ejected)
1996 break;
1997
1998 if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */
1999 i = dentry % dentries_per_clu;
2000 else
2001 i = dentry & (dentries_per_clu - 1);
2002
2003 for (; i < dentries_per_clu; i++, dentry++) {
2004 ep = get_entry_in_dir(sb, &clu, i, NULL);
2005 if (!ep)
2006 return -1;
2007
2008 type = p_fs->fs_func->get_entry_type(ep);
2009
2010 if (type == TYPE_UNUSED) {
2011 num_empty++;
2012 if (p_fs->hint_uentry.entry == -1) {
2013 p_fs->hint_uentry.dir = p_dir->dir;
2014 p_fs->hint_uentry.entry = dentry;
2015
2016 p_fs->hint_uentry.clu.dir = clu.dir;
2017 p_fs->hint_uentry.clu.size = clu.size;
2018 p_fs->hint_uentry.clu.flags = clu.flags;
2019 }
2020 } else if (type == TYPE_DELETED) {
2021 num_empty++;
2022 } else {
2023 num_empty = 0;
2024 }
2025
2026 if (num_empty >= num_entries) {
2027 p_fs->hint_uentry.dir = CLUSTER_32(~0);
2028 p_fs->hint_uentry.entry = -1;
2029
2030 if (p_fs->vol_type == EXFAT)
2031 return dentry - (num_entries - 1);
2032 else
2033 return dentry;
2034 }
2035 }
2036
2037 if (p_dir->dir == CLUSTER_32(0))
2038 break; /* FAT16 root_dir */
2039
2040 if (clu.flags == 0x03) {
2041 if ((--clu.size) > 0)
2042 clu.dir++;
2043 else
2044 clu.dir = CLUSTER_32(~0);
2045 } else {
2046 if (FAT_read(sb, clu.dir, &clu.dir) != 0)
2047 return -1;
2048 }
2049 }
2050
2051 return -1;
2052}
2053
2054s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir, s32 num_entries)
2055{
2056 s32 ret, dentry;
2057 u32 last_clu;
2058 sector_t sector;
2059 u64 size = 0;
2060 struct chain_t clu;
2061 struct dentry_t *ep = NULL;
2062 struct super_block *sb = inode->i_sb;
2063 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
2064 struct file_id_t *fid = &(EXFAT_I(inode)->fid);
2065
2066 if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */
2067 return search_deleted_or_unused_entry(sb, p_dir, num_entries);
2068
2069 while ((dentry = search_deleted_or_unused_entry(sb, p_dir, num_entries)) < 0) {
2070 if (p_fs->dev_ejected)
2071 break;
2072
2073 if (p_fs->vol_type == EXFAT) {
2074 if (p_dir->dir != p_fs->root_dir)
2075 size = i_size_read(inode);
2076 }
2077
2078 last_clu = find_last_cluster(sb, p_dir);
2079 clu.dir = last_clu + 1;
2080 clu.size = 0;
2081 clu.flags = p_dir->flags;
2082
2083 /* (1) allocate a cluster */
2084 ret = p_fs->fs_func->alloc_cluster(sb, 1, &clu);
2085 if (ret < 1)
2086 return -1;
2087
2088 if (clear_cluster(sb, clu.dir) != FFS_SUCCESS)
2089 return -1;
2090
2091 /* (2) append to the FAT chain */
2092 if (clu.flags != p_dir->flags) {
2093 exfat_chain_cont_cluster(sb, p_dir->dir, p_dir->size);
2094 p_dir->flags = 0x01;
2095 p_fs->hint_uentry.clu.flags = 0x01;
2096 }
2097 if (clu.flags == 0x01)
2098 if (FAT_write(sb, last_clu, clu.dir) < 0)
2099 return -1;
2100
2101 if (p_fs->hint_uentry.entry == -1) {
2102 p_fs->hint_uentry.dir = p_dir->dir;
2103 p_fs->hint_uentry.entry = p_dir->size << (p_fs->cluster_size_bits - DENTRY_SIZE_BITS);
2104
2105 p_fs->hint_uentry.clu.dir = clu.dir;
2106 p_fs->hint_uentry.clu.size = 0;
2107 p_fs->hint_uentry.clu.flags = clu.flags;
2108 }
2109 p_fs->hint_uentry.clu.size++;
2110 p_dir->size++;
2111
2112 /* (3) update the directory entry */
2113 if (p_fs->vol_type == EXFAT) {
2114 if (p_dir->dir != p_fs->root_dir) {
2115 size += p_fs->cluster_size;
2116
2117 ep = get_entry_in_dir(sb, &fid->dir,
2118 fid->entry + 1, &sector);
2119 if (!ep)
2120 return -1;
2121 p_fs->fs_func->set_entry_size(ep, size);
2122 p_fs->fs_func->set_entry_flag(ep, p_dir->flags);
2123 buf_modify(sb, sector);
2124
2125 update_dir_checksum(sb, &(fid->dir),
2126 fid->entry);
2127 }
2128 }
2129
2130 i_size_write(inode, i_size_read(inode) + p_fs->cluster_size);
2131 EXFAT_I(inode)->mmu_private += p_fs->cluster_size;
2132 EXFAT_I(inode)->fid.size += p_fs->cluster_size;
2133 EXFAT_I(inode)->fid.flags = p_dir->flags;
2134 inode->i_blocks += 1 << (p_fs->cluster_size_bits - 9);
2135 }
2136
2137 return dentry;
2138}
2139
2140/* return values of fat_find_dir_entry()
2141 * >= 0 : return dir entiry position with the name in dir
2142 * -1 : (root dir, ".") it is the root dir itself
2143 * -2 : entry with the name does not exist
2144 */
2145s32 fat_find_dir_entry(struct super_block *sb, struct chain_t *p_dir,
2146 struct uni_name_t *p_uniname, s32 num_entries,
2147 struct dos_name_t *p_dosname, u32 type)
2148{
2149 int i, dentry = 0, len;
2150 s32 order = 0;
2151 bool is_feasible_entry = true, has_ext_entry = false;
2152 s32 dentries_per_clu;
2153 u32 entry_type;
2154 u16 entry_uniname[14], *uniname = NULL, unichar;
2155 struct chain_t clu;
2156 struct dentry_t *ep;
2157 struct dos_dentry_t *dos_ep;
2158 struct ext_dentry_t *ext_ep;
2159 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
2160
2161 if (p_dir->dir == p_fs->root_dir) {
2162 if ((!nls_uniname_cmp(sb, p_uniname->name,
2163 (u16 *)UNI_CUR_DIR_NAME)) ||
2164 (!nls_uniname_cmp(sb, p_uniname->name,
2165 (u16 *)UNI_PAR_DIR_NAME)))
2166 return -1; // special case, root directory itself
2167 }
2168
2169 if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */
2170 dentries_per_clu = p_fs->dentries_in_root;
2171 else
2172 dentries_per_clu = p_fs->dentries_per_clu;
2173
2174 clu.dir = p_dir->dir;
2175 clu.flags = p_dir->flags;
2176
2177 while (clu.dir != CLUSTER_32(~0)) {
2178 if (p_fs->dev_ejected)
2179 break;
2180
2181 for (i = 0; i < dentries_per_clu; i++, dentry++) {
2182 ep = get_entry_in_dir(sb, &clu, i, NULL);
2183 if (!ep)
2184 return -2;
2185
2186 entry_type = p_fs->fs_func->get_entry_type(ep);
2187
2188 if ((entry_type == TYPE_FILE) || (entry_type == TYPE_DIR)) {
2189 if ((type == TYPE_ALL) || (type == entry_type)) {
2190 if (is_feasible_entry && has_ext_entry)
2191 return dentry;
2192
2193 dos_ep = (struct dos_dentry_t *)ep;
2194 if (!nls_dosname_cmp(sb, p_dosname->name, dos_ep->name))
2195 return dentry;
2196 }
2197 is_feasible_entry = true;
2198 has_ext_entry = false;
2199 } else if (entry_type == TYPE_EXTEND) {
2200 if (is_feasible_entry) {
2201 ext_ep = (struct ext_dentry_t *)ep;
2202 if (ext_ep->order > 0x40) {
2203 order = (s32)(ext_ep->order - 0x40);
2204 uniname = p_uniname->name + 13 * (order - 1);
2205 } else {
2206 order = (s32)ext_ep->order;
2207 uniname -= 13;
2208 }
2209
2210 len = extract_uni_name_from_ext_entry(ext_ep, entry_uniname, order);
2211
2212 unichar = *(uniname + len);
2213 *(uniname + len) = 0x0;
2214
2215 if (nls_uniname_cmp(sb, uniname, entry_uniname))
2216 is_feasible_entry = false;
2217
2218 *(uniname + len) = unichar;
2219 }
2220 has_ext_entry = true;
2221 } else if (entry_type == TYPE_UNUSED) {
2222 return -2;
2223 }
2224 is_feasible_entry = true;
2225 has_ext_entry = false;
2226 }
2227
2228 if (p_dir->dir == CLUSTER_32(0))
2229 break; /* FAT16 root_dir */
2230
2231 if (FAT_read(sb, clu.dir, &clu.dir) != 0)
2232 return -2;
2233 }
2234
2235 return -2;
2236}
2237
2238/* return values of exfat_find_dir_entry()
2239 * >= 0 : return dir entiry position with the name in dir
2240 * -1 : (root dir, ".") it is the root dir itself
2241 * -2 : entry with the name does not exist
2242 */
2243s32 exfat_find_dir_entry(struct super_block *sb, struct chain_t *p_dir,
2244 struct uni_name_t *p_uniname, s32 num_entries,
2245 struct dos_name_t *p_dosname, u32 type)
2246{
2247 int i = 0, dentry = 0, num_ext_entries = 0, len, step;
2248 s32 order = 0;
2249 bool is_feasible_entry = false;
2250 s32 dentries_per_clu, num_empty = 0;
2251 u32 entry_type;
2252 u16 entry_uniname[16], *uniname = NULL, unichar;
2253 struct chain_t clu;
2254 struct dentry_t *ep;
2255 struct file_dentry_t *file_ep;
2256 struct strm_dentry_t *strm_ep;
2257 struct name_dentry_t *name_ep;
2258 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
2259
2260 if (p_dir->dir == p_fs->root_dir) {
2261 if ((!nls_uniname_cmp(sb, p_uniname->name,
2262 (u16 *)UNI_CUR_DIR_NAME)) ||
2263 (!nls_uniname_cmp(sb, p_uniname->name,
2264 (u16 *)UNI_PAR_DIR_NAME)))
2265 return -1; // special case, root directory itself
2266 }
2267
2268 if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */
2269 dentries_per_clu = p_fs->dentries_in_root;
2270 else
2271 dentries_per_clu = p_fs->dentries_per_clu;
2272
2273 clu.dir = p_dir->dir;
2274 clu.size = p_dir->size;
2275 clu.flags = p_dir->flags;
2276
2277 p_fs->hint_uentry.dir = p_dir->dir;
2278 p_fs->hint_uentry.entry = -1;
2279
2280 while (clu.dir != CLUSTER_32(~0)) {
2281 if (p_fs->dev_ejected)
2282 break;
2283
2284 while (i < dentries_per_clu) {
2285 ep = get_entry_in_dir(sb, &clu, i, NULL);
2286 if (!ep)
2287 return -2;
2288
2289 entry_type = p_fs->fs_func->get_entry_type(ep);
2290 step = 1;
2291
2292 if ((entry_type == TYPE_UNUSED) || (entry_type == TYPE_DELETED)) {
2293 is_feasible_entry = false;
2294
2295 if (p_fs->hint_uentry.entry == -1) {
2296 num_empty++;
2297
2298 if (num_empty == 1) {
2299 p_fs->hint_uentry.clu.dir = clu.dir;
2300 p_fs->hint_uentry.clu.size = clu.size;
2301 p_fs->hint_uentry.clu.flags = clu.flags;
2302 }
2303 if ((num_empty >= num_entries) || (entry_type == TYPE_UNUSED))
2304 p_fs->hint_uentry.entry = dentry - (num_empty - 1);
2305 }
2306
2307 if (entry_type == TYPE_UNUSED)
2308 return -2;
2309 } else {
2310 num_empty = 0;
2311
2312 if ((entry_type == TYPE_FILE) || (entry_type == TYPE_DIR)) {
2313 file_ep = (struct file_dentry_t *)ep;
2314 if ((type == TYPE_ALL) || (type == entry_type)) {
2315 num_ext_entries = file_ep->num_ext;
2316 is_feasible_entry = true;
2317 } else {
2318 is_feasible_entry = false;
2319 step = file_ep->num_ext + 1;
2320 }
2321 } else if (entry_type == TYPE_STREAM) {
2322 if (is_feasible_entry) {
2323 strm_ep = (struct strm_dentry_t *)ep;
2324 if (p_uniname->name_hash == GET16_A(strm_ep->name_hash) &&
2325 p_uniname->name_len == strm_ep->name_len) {
2326 order = 1;
2327 } else {
2328 is_feasible_entry = false;
2329 step = num_ext_entries;
2330 }
2331 }
2332 } else if (entry_type == TYPE_EXTEND) {
2333 if (is_feasible_entry) {
2334 name_ep = (struct name_dentry_t *)ep;
2335
2336 if ((++order) == 2)
2337 uniname = p_uniname->name;
2338 else
2339 uniname += 15;
2340
2341 len = extract_uni_name_from_name_entry(name_ep,
2342 entry_uniname, order);
2343
2344 unichar = *(uniname + len);
2345 *(uniname + len) = 0x0;
2346
2347 if (nls_uniname_cmp(sb, uniname, entry_uniname)) {
2348 is_feasible_entry = false;
2349 step = num_ext_entries - order + 1;
2350 } else if (order == num_ext_entries) {
2351 p_fs->hint_uentry.dir = CLUSTER_32(~0);
2352 p_fs->hint_uentry.entry = -1;
2353 return dentry - (num_ext_entries);
2354 }
2355
2356 *(uniname + len) = unichar;
2357 }
2358 } else {
2359 is_feasible_entry = false;
2360 }
2361 }
2362
2363 i += step;
2364 dentry += step;
2365 }
2366
2367 i -= dentries_per_clu;
2368
2369 if (p_dir->dir == CLUSTER_32(0))
2370 break; /* FAT16 root_dir */
2371
2372 if (clu.flags == 0x03) {
2373 if ((--clu.size) > 0)
2374 clu.dir++;
2375 else
2376 clu.dir = CLUSTER_32(~0);
2377 } else {
2378 if (FAT_read(sb, clu.dir, &clu.dir) != 0)
2379 return -2;
2380 }
2381 }
2382
2383 return -2;
2384}
2385
2386s32 fat_count_ext_entries(struct super_block *sb, struct chain_t *p_dir,
2387 s32 entry, struct dentry_t *p_entry)
2388{
2389 s32 count = 0;
2390 u8 chksum;
2391 struct dos_dentry_t *dos_ep = (struct dos_dentry_t *)p_entry;
2392 struct ext_dentry_t *ext_ep;
2393 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
2394
2395 chksum = calc_checksum_1byte((void *)dos_ep->name, DOS_NAME_LENGTH, 0);
2396
2397 for (entry--; entry >= 0; entry--) {
2398 ext_ep = (struct ext_dentry_t *)get_entry_in_dir(sb, p_dir,
2399 entry, NULL);
2400 if (!ext_ep)
2401 return -1;
2402
2403 if ((p_fs->fs_func->get_entry_type((struct dentry_t *)ext_ep) ==
2404 TYPE_EXTEND) && (ext_ep->checksum == chksum)) {
2405 count++;
2406 if (ext_ep->order > 0x40)
2407 return count;
2408 } else {
2409 return count;
2410 }
2411 }
2412
2413 return count;
2414}
2415
2416s32 exfat_count_ext_entries(struct super_block *sb, struct chain_t *p_dir,
2417 s32 entry, struct dentry_t *p_entry)
2418{
2419 int i, count = 0;
2420 u32 type;
2421 struct file_dentry_t *file_ep = (struct file_dentry_t *)p_entry;
2422 struct dentry_t *ext_ep;
2423 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
2424
2425 for (i = 0, entry++; i < file_ep->num_ext; i++, entry++) {
2426 ext_ep = get_entry_in_dir(sb, p_dir, entry, NULL);
2427 if (!ext_ep)
2428 return -1;
2429
2430 type = p_fs->fs_func->get_entry_type(ext_ep);
2431 if ((type == TYPE_EXTEND) || (type == TYPE_STREAM))
2432 count++;
2433 else
2434 return count;
2435 }
2436
2437 return count;
2438}
2439
2440s32 count_dos_name_entries(struct super_block *sb, struct chain_t *p_dir,
2441 u32 type)
2442{
2443 int i, count = 0;
2444 s32 dentries_per_clu;
2445 u32 entry_type;
2446 struct chain_t clu;
2447 struct dentry_t *ep;
2448 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
2449
2450 if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */
2451 dentries_per_clu = p_fs->dentries_in_root;
2452 else
2453 dentries_per_clu = p_fs->dentries_per_clu;
2454
2455 clu.dir = p_dir->dir;
2456 clu.size = p_dir->size;
2457 clu.flags = p_dir->flags;
2458
2459 while (clu.dir != CLUSTER_32(~0)) {
2460 if (p_fs->dev_ejected)
2461 break;
2462
2463 for (i = 0; i < dentries_per_clu; i++) {
2464 ep = get_entry_in_dir(sb, &clu, i, NULL);
2465 if (!ep)
2466 return -1;
2467
2468 entry_type = p_fs->fs_func->get_entry_type(ep);
2469
2470 if (entry_type == TYPE_UNUSED)
2471 return count;
2472 if (!(type & TYPE_CRITICAL_PRI) &&
2473 !(type & TYPE_BENIGN_PRI))
2474 continue;
2475
2476 if ((type == TYPE_ALL) || (type == entry_type))
2477 count++;
2478 }
2479
2480 if (p_dir->dir == CLUSTER_32(0))
2481 break; /* FAT16 root_dir */
2482
2483 if (clu.flags == 0x03) {
2484 if ((--clu.size) > 0)
2485 clu.dir++;
2486 else
2487 clu.dir = CLUSTER_32(~0);
2488 } else {
2489 if (FAT_read(sb, clu.dir, &clu.dir) != 0)
2490 return -1;
2491 }
2492 }
2493
2494 return count;
2495}
2496
2497bool is_dir_empty(struct super_block *sb, struct chain_t *p_dir)
2498{
2499 int i, count = 0;
2500 s32 dentries_per_clu;
2501 u32 type;
2502 struct chain_t clu;
2503 struct dentry_t *ep;
2504 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
2505
2506 if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */
2507 dentries_per_clu = p_fs->dentries_in_root;
2508 else
2509 dentries_per_clu = p_fs->dentries_per_clu;
2510
2511 clu.dir = p_dir->dir;
2512 clu.size = p_dir->size;
2513 clu.flags = p_dir->flags;
2514
2515 while (clu.dir != CLUSTER_32(~0)) {
2516 if (p_fs->dev_ejected)
2517 break;
2518
2519 for (i = 0; i < dentries_per_clu; i++) {
2520 ep = get_entry_in_dir(sb, &clu, i, NULL);
2521 if (!ep)
2522 break;
2523
2524 type = p_fs->fs_func->get_entry_type(ep);
2525
2526 if (type == TYPE_UNUSED)
2527 return true;
2528 if ((type != TYPE_FILE) && (type != TYPE_DIR))
2529 continue;
2530
2531 if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */
2532 return false;
2533
2534 if (p_fs->vol_type == EXFAT)
2535 return false;
2536 if ((p_dir->dir == p_fs->root_dir) || ((++count) > 2))
2537 return false;
2538 }
2539
2540 if (p_dir->dir == CLUSTER_32(0))
2541 break; /* FAT16 root_dir */
2542
2543 if (clu.flags == 0x03) {
2544 if ((--clu.size) > 0)
2545 clu.dir++;
2546 else
2547 clu.dir = CLUSTER_32(~0);
2548 }
2549 if (FAT_read(sb, clu.dir, &clu.dir) != 0)
2550 break;
2551 }
2552
2553 return true;
2554}
2555
2556/*
2557 * Name Conversion Functions
2558 */
2559
2560/* input : dir, uni_name
2561 * output : num_of_entry, dos_name(format : aaaaaa~1.bbb)
2562 */
2563s32 get_num_entries_and_dos_name(struct super_block *sb, struct chain_t *p_dir,
2564 struct uni_name_t *p_uniname, s32 *entries,
2565 struct dos_name_t *p_dosname)
2566{
2567 s32 ret, num_entries;
2568 bool lossy = false;
2569 char **r;
2570 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
2571
2572 num_entries = p_fs->fs_func->calc_num_entries(p_uniname);
2573 if (num_entries == 0)
2574 return FFS_INVALIDPATH;
2575
2576 if (p_fs->vol_type != EXFAT) {
2577 nls_uniname_to_dosname(sb, p_dosname, p_uniname, &lossy);
2578
2579 if (lossy) {
2580 ret = fat_generate_dos_name(sb, p_dir, p_dosname);
2581 if (ret)
2582 return ret;
2583 } else {
2584 for (r = reserved_names; *r; r++) {
2585 if (!strncmp((void *)p_dosname->name, *r, 8))
2586 return FFS_INVALIDPATH;
2587 }
2588
2589 if (p_dosname->name_case != 0xFF)
2590 num_entries = 1;
2591 }
2592
2593 if (num_entries > 1)
2594 p_dosname->name_case = 0x0;
2595 }
2596
2597 *entries = num_entries;
2598
2599 return FFS_SUCCESS;
2600}
2601
2602void get_uni_name_from_dos_entry(struct super_block *sb,
2603 struct dos_dentry_t *ep,
2604 struct uni_name_t *p_uniname, u8 mode)
2605{
2606 struct dos_name_t dos_name;
2607
2608 if (mode == 0x0)
2609 dos_name.name_case = 0x0;
2610 else
2611 dos_name.name_case = ep->lcase;
2612
2613 memcpy(dos_name.name, ep->name, DOS_NAME_LENGTH);
2614 nls_dosname_to_uniname(sb, p_uniname, &dos_name);
2615}
2616
2617void fat_get_uni_name_from_ext_entry(struct super_block *sb,
2618 struct chain_t *p_dir, s32 entry,
2619 u16 *uniname)
2620{
2621 int i;
2622 struct ext_dentry_t *ep;
2623 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
2624
2625 for (entry--, i = 1; entry >= 0; entry--, i++) {
2626 ep = (struct ext_dentry_t *)get_entry_in_dir(sb, p_dir, entry,
2627 NULL);
2628 if (!ep)
2629 return;
2630
2631 if (p_fs->fs_func->get_entry_type((struct dentry_t *)ep) ==
2632 TYPE_EXTEND) {
2633 extract_uni_name_from_ext_entry(ep, uniname, i);
2634 if (ep->order > 0x40)
2635 return;
2636 } else {
2637 return;
2638 }
2639
2640 uniname += 13;
2641 }
2642}
2643
2644void exfat_get_uni_name_from_ext_entry(struct super_block *sb,
2645 struct chain_t *p_dir, s32 entry,
2646 u16 *uniname)
2647{
2648 int i;
2649 struct dentry_t *ep;
2650 struct entry_set_cache_t *es;
2651 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
2652
2653 es = get_entry_set_in_dir(sb, p_dir, entry, ES_ALL_ENTRIES, &ep);
2654 if (!es || es->num_entries < 3) {
2655 if (es)
2656 release_entry_set(es);
2657 return;
2658 }
2659
2660 ep += 2;
2661
2662 /*
2663 * First entry : file entry
2664 * Second entry : stream-extension entry
2665 * Third entry : first file-name entry
2666 * So, the index of first file-name dentry should start from 2.
2667 */
2668 for (i = 2; i < es->num_entries; i++, ep++) {
2669 if (p_fs->fs_func->get_entry_type(ep) == TYPE_EXTEND)
2670 extract_uni_name_from_name_entry((struct name_dentry_t *)
2671 ep, uniname, i);
2672 else
2673 goto out;
2674 uniname += 15;
2675 }
2676
2677out:
2678 release_entry_set(es);
2679}
2680
2681s32 extract_uni_name_from_ext_entry(struct ext_dentry_t *ep, u16 *uniname,
2682 s32 order)
2683{
2684 int i, len = 0;
2685
2686 for (i = 0; i < 10; i += 2) {
2687 *uniname = GET16(ep->unicode_0_4 + i);
2688 if (*uniname == 0x0)
2689 return len;
2690 uniname++;
2691 len++;
2692 }
2693
2694 if (order < 20) {
2695 for (i = 0; i < 12; i += 2) {
2696 *uniname = GET16_A(ep->unicode_5_10 + i);
2697 if (*uniname == 0x0)
2698 return len;
2699 uniname++;
2700 len++;
2701 }
2702 } else {
2703 for (i = 0; i < 8; i += 2) {
2704 *uniname = GET16_A(ep->unicode_5_10 + i);
2705 if (*uniname == 0x0)
2706 return len;
2707 uniname++;
2708 len++;
2709 }
2710 *uniname = 0x0; /* uniname[MAX_NAME_LENGTH-1] */
2711 return len;
2712 }
2713
2714 for (i = 0; i < 4; i += 2) {
2715 *uniname = GET16_A(ep->unicode_11_12 + i);
2716 if (*uniname == 0x0)
2717 return len;
2718 uniname++;
2719 len++;
2720 }
2721
2722 *uniname = 0x0;
2723 return len;
2724}
2725
2726s32 extract_uni_name_from_name_entry(struct name_dentry_t *ep, u16 *uniname,
2727 s32 order)
2728{
2729 int i, len = 0;
2730
2731 for (i = 0; i < 30; i += 2) {
2732 *uniname = GET16_A(ep->unicode_0_14 + i);
2733 if (*uniname == 0x0)
2734 return len;
2735 uniname++;
2736 len++;
2737 }
2738
2739 *uniname = 0x0;
2740 return len;
2741}
2742
2743s32 fat_generate_dos_name(struct super_block *sb, struct chain_t *p_dir,
2744 struct dos_name_t *p_dosname)
2745{
2746 int i, j, count = 0;
2747 bool count_begin = false;
2748 s32 dentries_per_clu;
2749 u32 type;
2750 u8 bmap[128/* 1 ~ 1023 */];
2751 struct chain_t clu;
2752 struct dos_dentry_t *ep;
2753 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
2754
2755 memset(bmap, 0, sizeof(bmap));
2756 exfat_bitmap_set(bmap, 0);
2757
2758 if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */
2759 dentries_per_clu = p_fs->dentries_in_root;
2760 else
2761 dentries_per_clu = p_fs->dentries_per_clu;
2762
2763 clu.dir = p_dir->dir;
2764 clu.flags = p_dir->flags;
2765
2766 while (clu.dir != CLUSTER_32(~0)) {
2767 if (p_fs->dev_ejected)
2768 break;
2769
2770 for (i = 0; i < dentries_per_clu; i++) {
2771 ep = (struct dos_dentry_t *)get_entry_in_dir(sb, &clu,
2772 i, NULL);
2773 if (!ep)
2774 return FFS_MEDIAERR;
2775
2776 type = p_fs->fs_func->get_entry_type((struct dentry_t *)
2777 ep);
2778
2779 if (type == TYPE_UNUSED)
2780 break;
2781 if ((type != TYPE_FILE) && (type != TYPE_DIR))
2782 continue;
2783
2784 count = 0;
2785 count_begin = false;
2786
2787 for (j = 0; j < 8; j++) {
2788 if (ep->name[j] == ' ')
2789 break;
2790
2791 if (ep->name[j] == '~') {
2792 count_begin = true;
2793 } else if (count_begin) {
2794 if ((ep->name[j] >= '0') &&
2795 (ep->name[j] <= '9')) {
2796 count = count * 10 +
2797 (ep->name[j] - '0');
2798 } else {
2799 count = 0;
2800 count_begin = false;
2801 }
2802 }
2803 }
2804
2805 if ((count > 0) && (count < 1024))
2806 exfat_bitmap_set(bmap, count);
2807 }
2808
2809 if (p_dir->dir == CLUSTER_32(0))
2810 break; /* FAT16 root_dir */
2811
2812 if (FAT_read(sb, clu.dir, &clu.dir) != 0)
2813 return FFS_MEDIAERR;
2814 }
2815
2816 count = 0;
2817 for (i = 0; i < 128; i++) {
2818 if (bmap[i] != 0xFF) {
2819 for (j = 0; j < 8; j++) {
2820 if (exfat_bitmap_test(&bmap[i], j) == 0) {
2821 count = (i << 3) + j;
2822 break;
2823 }
2824 }
2825 if (count != 0)
2826 break;
2827 }
2828 }
2829
2830 if ((count == 0) || (count >= 1024))
2831 return FFS_FILEEXIST;
2832 fat_attach_count_to_dos_name(p_dosname->name, count);
2833
2834 /* Now dos_name has DOS~????.EXT */
2835 return FFS_SUCCESS;
2836}
2837
2838void fat_attach_count_to_dos_name(u8 *dosname, s32 count)
2839{
2840 int i, j, length;
2841 char str_count[6];
2842
2843 snprintf(str_count, sizeof(str_count), "~%d", count);
2844 length = strlen(str_count);
2845
2846 i = 0;
2847 j = 0;
2848 while (j <= (8 - length)) {
2849 i = j;
2850 if (dosname[j] == ' ')
2851 break;
2852 if (dosname[j] & 0x80)
2853 j += 2;
2854 else
2855 j++;
2856 }
2857
2858 for (j = 0; j < length; i++, j++)
2859 dosname[i] = (u8)str_count[j];
2860
2861 if (i == 7)
2862 dosname[7] = ' ';
2863}
2864
2865s32 fat_calc_num_entries(struct uni_name_t *p_uniname)
2866{
2867 s32 len;
2868
2869 len = p_uniname->name_len;
2870 if (len == 0)
2871 return 0;
2872
2873 /* 1 dos name entry + extended entries */
2874 return (len - 1) / 13 + 2;
2875}
2876
2877s32 exfat_calc_num_entries(struct uni_name_t *p_uniname)
2878{
2879 s32 len;
2880
2881 len = p_uniname->name_len;
2882 if (len == 0)
2883 return 0;
2884
2885 /* 1 file entry + 1 stream entry + name entries */
2886 return (len - 1) / 15 + 3;
2887}
2888
2889u8 calc_checksum_1byte(void *data, s32 len, u8 chksum)
2890{
2891 int i;
2892 u8 *c = (u8 *)data;
2893
2894 for (i = 0; i < len; i++, c++)
2895 chksum = (((chksum & 1) << 7) | ((chksum & 0xFE) >> 1)) + *c;
2896
2897 return chksum;
2898}
2899
2900u16 calc_checksum_2byte(void *data, s32 len, u16 chksum, s32 type)
2901{
2902 int i;
2903 u8 *c = (u8 *)data;
2904
2905 switch (type) {
2906 case CS_DIR_ENTRY:
2907 for (i = 0; i < len; i++, c++) {
2908 if ((i == 2) || (i == 3))
2909 continue;
2910 chksum = (((chksum & 1) << 15) |
2911 ((chksum & 0xFFFE) >> 1)) + (u16)*c;
2912 }
2913 break;
2914 default
2915 :
2916 for (i = 0; i < len; i++, c++)
2917 chksum = (((chksum & 1) << 15) |
2918 ((chksum & 0xFFFE) >> 1)) + (u16)*c;
2919 }
2920
2921 return chksum;
2922}
2923
2924u32 calc_checksum_4byte(void *data, s32 len, u32 chksum, s32 type)
2925{
2926 int i;
2927 u8 *c = (u8 *)data;
2928
2929 switch (type) {
2930 case CS_PBR_SECTOR:
2931 for (i = 0; i < len; i++, c++) {
2932 if ((i == 106) || (i == 107) || (i == 112))
2933 continue;
2934 chksum = (((chksum & 1) << 31) |
2935 ((chksum & 0xFFFFFFFE) >> 1)) + (u32)*c;
2936 }
2937 break;
2938 default
2939 :
2940 for (i = 0; i < len; i++, c++)
2941 chksum = (((chksum & 1) << 31) |
2942 ((chksum & 0xFFFFFFFE) >> 1)) + (u32)*c;
2943 }
2944
2945 return chksum;
2946}
2947
2948/*
2949 * Name Resolution Functions
2950 */
2951
2952/* return values of resolve_path()
2953 * > 0 : return the length of the path
2954 * < 0 : return error
2955 */
2956s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir,
2957 struct uni_name_t *p_uniname)
2958{
2959 bool lossy = false;
2960 struct super_block *sb = inode->i_sb;
2961 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
2962 struct file_id_t *fid = &(EXFAT_I(inode)->fid);
2963
2964 if (strscpy(name_buf, path, sizeof(name_buf)) < 0)
2965 return FFS_INVALIDPATH;
2966
2967 nls_cstring_to_uniname(sb, p_uniname, name_buf, &lossy);
2968 if (lossy)
2969 return FFS_INVALIDPATH;
2970
2971 fid->size = i_size_read(inode);
2972
2973 p_dir->dir = fid->start_clu;
2974 p_dir->size = (s32)(fid->size >> p_fs->cluster_size_bits);
2975 p_dir->flags = fid->flags;
2976
2977 return FFS_SUCCESS;
2978}
2979
2980/*
2981 * File Operation Functions
2982 */
2983static struct fs_func fat_fs_func = {
2984 .alloc_cluster = fat_alloc_cluster,
2985 .free_cluster = fat_free_cluster,
2986 .count_used_clusters = fat_count_used_clusters,
2987
2988 .init_dir_entry = fat_init_dir_entry,
2989 .init_ext_entry = fat_init_ext_entry,
2990 .find_dir_entry = fat_find_dir_entry,
2991 .delete_dir_entry = fat_delete_dir_entry,
2992 .get_uni_name_from_ext_entry = fat_get_uni_name_from_ext_entry,
2993 .count_ext_entries = fat_count_ext_entries,
2994 .calc_num_entries = fat_calc_num_entries,
2995
2996 .get_entry_type = fat_get_entry_type,
2997 .set_entry_type = fat_set_entry_type,
2998 .get_entry_attr = fat_get_entry_attr,
2999 .set_entry_attr = fat_set_entry_attr,
3000 .get_entry_flag = fat_get_entry_flag,
3001 .set_entry_flag = fat_set_entry_flag,
3002 .get_entry_clu0 = fat_get_entry_clu0,
3003 .set_entry_clu0 = fat_set_entry_clu0,
3004 .get_entry_size = fat_get_entry_size,
3005 .set_entry_size = fat_set_entry_size,
3006 .get_entry_time = fat_get_entry_time,
3007 .set_entry_time = fat_set_entry_time,
3008};
3009
3010s32 fat16_mount(struct super_block *sb, struct pbr_sector_t *p_pbr)
3011{
3012 s32 num_reserved, num_root_sectors;
3013 struct bpb16_t *p_bpb = (struct bpb16_t *)p_pbr->bpb;
3014 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
3015 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
3016
3017 if (p_bpb->num_fats == 0)
3018 return FFS_FORMATERR;
3019
3020 num_root_sectors = GET16(p_bpb->num_root_entries) << DENTRY_SIZE_BITS;
3021 num_root_sectors = ((num_root_sectors - 1) >>
3022 p_bd->sector_size_bits) + 1;
3023
3024 p_fs->sectors_per_clu = p_bpb->sectors_per_clu;
3025 p_fs->sectors_per_clu_bits = ilog2(p_bpb->sectors_per_clu);
3026 p_fs->cluster_size_bits = p_fs->sectors_per_clu_bits +
3027 p_bd->sector_size_bits;
3028 p_fs->cluster_size = 1 << p_fs->cluster_size_bits;
3029
3030 p_fs->num_FAT_sectors = GET16(p_bpb->num_fat_sectors);
3031
3032 p_fs->FAT1_start_sector = p_fs->PBR_sector + GET16(p_bpb->num_reserved);
3033 if (p_bpb->num_fats == 1)
3034 p_fs->FAT2_start_sector = p_fs->FAT1_start_sector;
3035 else
3036 p_fs->FAT2_start_sector = p_fs->FAT1_start_sector +
3037 p_fs->num_FAT_sectors;
3038
3039 p_fs->root_start_sector = p_fs->FAT2_start_sector +
3040 p_fs->num_FAT_sectors;
3041 p_fs->data_start_sector = p_fs->root_start_sector + num_root_sectors;
3042
3043 p_fs->num_sectors = GET16(p_bpb->num_sectors);
3044 if (p_fs->num_sectors == 0)
3045 p_fs->num_sectors = GET32(p_bpb->num_huge_sectors);
3046
3047 num_reserved = p_fs->data_start_sector - p_fs->PBR_sector;
3048 p_fs->num_clusters = ((p_fs->num_sectors - num_reserved) >>
3049 p_fs->sectors_per_clu_bits) + 2;
3050 /* because the cluster index starts with 2 */
3051
3052 if (p_fs->num_clusters < FAT12_THRESHOLD)
3053 p_fs->vol_type = FAT12;
3054 else
3055 p_fs->vol_type = FAT16;
3056 p_fs->vol_id = GET32(p_bpb->vol_serial);
3057
3058 p_fs->root_dir = 0;
3059 p_fs->dentries_in_root = GET16(p_bpb->num_root_entries);
3060 p_fs->dentries_per_clu = 1 << (p_fs->cluster_size_bits -
3061 DENTRY_SIZE_BITS);
3062
3063 p_fs->vol_flag = VOL_CLEAN;
3064 p_fs->clu_srch_ptr = 2;
3065 p_fs->used_clusters = UINT_MAX;
3066
3067 p_fs->fs_func = &fat_fs_func;
3068
3069 return FFS_SUCCESS;
3070}
3071
3072s32 fat32_mount(struct super_block *sb, struct pbr_sector_t *p_pbr)
3073{
3074 s32 num_reserved;
3075 struct bpb32_t *p_bpb = (struct bpb32_t *)p_pbr->bpb;
3076 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
3077 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
3078
3079 if (p_bpb->num_fats == 0)
3080 return FFS_FORMATERR;
3081
3082 p_fs->sectors_per_clu = p_bpb->sectors_per_clu;
3083 p_fs->sectors_per_clu_bits = ilog2(p_bpb->sectors_per_clu);
3084 p_fs->cluster_size_bits = p_fs->sectors_per_clu_bits +
3085 p_bd->sector_size_bits;
3086 p_fs->cluster_size = 1 << p_fs->cluster_size_bits;
3087
3088 p_fs->num_FAT_sectors = GET32(p_bpb->num_fat32_sectors);
3089
3090 p_fs->FAT1_start_sector = p_fs->PBR_sector + GET16(p_bpb->num_reserved);
3091 if (p_bpb->num_fats == 1)
3092 p_fs->FAT2_start_sector = p_fs->FAT1_start_sector;
3093 else
3094 p_fs->FAT2_start_sector = p_fs->FAT1_start_sector +
3095 p_fs->num_FAT_sectors;
3096
3097 p_fs->root_start_sector = p_fs->FAT2_start_sector +
3098 p_fs->num_FAT_sectors;
3099 p_fs->data_start_sector = p_fs->root_start_sector;
3100
3101 p_fs->num_sectors = GET32(p_bpb->num_huge_sectors);
3102 num_reserved = p_fs->data_start_sector - p_fs->PBR_sector;
3103
3104 p_fs->num_clusters = ((p_fs->num_sectors - num_reserved) >>
3105 p_fs->sectors_per_clu_bits) + 2;
3106 /* because the cluster index starts with 2 */
3107
3108 p_fs->vol_type = FAT32;
3109 p_fs->vol_id = GET32(p_bpb->vol_serial);
3110
3111 p_fs->root_dir = GET32(p_bpb->root_cluster);
3112 p_fs->dentries_in_root = 0;
3113 p_fs->dentries_per_clu = 1 << (p_fs->cluster_size_bits -
3114 DENTRY_SIZE_BITS);
3115
3116 p_fs->vol_flag = VOL_CLEAN;
3117 p_fs->clu_srch_ptr = 2;
3118 p_fs->used_clusters = UINT_MAX;
3119
3120 p_fs->fs_func = &fat_fs_func;
3121
3122 return FFS_SUCCESS;
3123}
3124
3125static struct fs_func exfat_fs_func = {
3126 .alloc_cluster = exfat_alloc_cluster,
3127 .free_cluster = exfat_free_cluster,
3128 .count_used_clusters = exfat_count_used_clusters,
3129
3130 .init_dir_entry = exfat_init_dir_entry,
3131 .init_ext_entry = exfat_init_ext_entry,
3132 .find_dir_entry = exfat_find_dir_entry,
3133 .delete_dir_entry = exfat_delete_dir_entry,
3134 .get_uni_name_from_ext_entry = exfat_get_uni_name_from_ext_entry,
3135 .count_ext_entries = exfat_count_ext_entries,
3136 .calc_num_entries = exfat_calc_num_entries,
3137
3138 .get_entry_type = exfat_get_entry_type,
3139 .set_entry_type = exfat_set_entry_type,
3140 .get_entry_attr = exfat_get_entry_attr,
3141 .set_entry_attr = exfat_set_entry_attr,
3142 .get_entry_flag = exfat_get_entry_flag,
3143 .set_entry_flag = exfat_set_entry_flag,
3144 .get_entry_clu0 = exfat_get_entry_clu0,
3145 .set_entry_clu0 = exfat_set_entry_clu0,
3146 .get_entry_size = exfat_get_entry_size,
3147 .set_entry_size = exfat_set_entry_size,
3148 .get_entry_time = exfat_get_entry_time,
3149 .set_entry_time = exfat_set_entry_time,
3150};
3151
3152s32 exfat_mount(struct super_block *sb, struct pbr_sector_t *p_pbr)
3153{
3154 struct bpbex_t *p_bpb = (struct bpbex_t *)p_pbr->bpb;
3155 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
3156 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
3157
3158 if (p_bpb->num_fats == 0)
3159 return FFS_FORMATERR;
3160
3161 p_fs->sectors_per_clu = 1 << p_bpb->sectors_per_clu_bits;
3162 p_fs->sectors_per_clu_bits = p_bpb->sectors_per_clu_bits;
3163 p_fs->cluster_size_bits = p_fs->sectors_per_clu_bits +
3164 p_bd->sector_size_bits;
3165 p_fs->cluster_size = 1 << p_fs->cluster_size_bits;
3166
3167 p_fs->num_FAT_sectors = GET32(p_bpb->fat_length);
3168
3169 p_fs->FAT1_start_sector = p_fs->PBR_sector + GET32(p_bpb->fat_offset);
3170 if (p_bpb->num_fats == 1)
3171 p_fs->FAT2_start_sector = p_fs->FAT1_start_sector;
3172 else
3173 p_fs->FAT2_start_sector = p_fs->FAT1_start_sector +
3174 p_fs->num_FAT_sectors;
3175
3176 p_fs->root_start_sector = p_fs->PBR_sector + GET32(p_bpb->clu_offset);
3177 p_fs->data_start_sector = p_fs->root_start_sector;
3178
3179 p_fs->num_sectors = GET64(p_bpb->vol_length);
3180 p_fs->num_clusters = GET32(p_bpb->clu_count) + 2;
3181 /* because the cluster index starts with 2 */
3182
3183 p_fs->vol_type = EXFAT;
3184 p_fs->vol_id = GET32(p_bpb->vol_serial);
3185
3186 p_fs->root_dir = GET32(p_bpb->root_cluster);
3187 p_fs->dentries_in_root = 0;
3188 p_fs->dentries_per_clu = 1 << (p_fs->cluster_size_bits -
3189 DENTRY_SIZE_BITS);
3190
3191 p_fs->vol_flag = (u32)GET16(p_bpb->vol_flags);
3192 p_fs->clu_srch_ptr = 2;
3193 p_fs->used_clusters = UINT_MAX;
3194
3195 p_fs->fs_func = &exfat_fs_func;
3196
3197 return FFS_SUCCESS;
3198}
3199
3200s32 create_dir(struct inode *inode, struct chain_t *p_dir,
3201 struct uni_name_t *p_uniname, struct file_id_t *fid)
3202{
3203 s32 ret, dentry, num_entries;
3204 u64 size;
3205 struct chain_t clu;
3206 struct dos_name_t dos_name, dot_name;
3207 struct super_block *sb = inode->i_sb;
3208 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
3209 struct fs_func *fs_func = p_fs->fs_func;
3210
3211 ret = get_num_entries_and_dos_name(sb, p_dir, p_uniname, &num_entries,
3212 &dos_name);
3213 if (ret)
3214 return ret;
3215
3216 /* find_empty_entry must be called before alloc_cluster */
3217 dentry = find_empty_entry(inode, p_dir, num_entries);
3218 if (dentry < 0)
3219 return FFS_FULL;
3220
3221 clu.dir = CLUSTER_32(~0);
3222 clu.size = 0;
3223 clu.flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01;
3224
3225 /* (1) allocate a cluster */
3226 ret = fs_func->alloc_cluster(sb, 1, &clu);
3227 if (ret < 0)
3228 return FFS_MEDIAERR;
3229 else if (ret == 0)
3230 return FFS_FULL;
3231
3232 ret = clear_cluster(sb, clu.dir);
3233 if (ret != FFS_SUCCESS)
3234 return ret;
3235
3236 if (p_fs->vol_type == EXFAT) {
3237 size = p_fs->cluster_size;
3238 } else {
3239 size = 0;
3240
3241 /* initialize the . and .. entry
3242 * Information for . points to itself
3243 * Information for .. points to parent dir
3244 */
3245
3246 dot_name.name_case = 0x0;
3247 memcpy(dot_name.name, DOS_CUR_DIR_NAME, DOS_NAME_LENGTH);
3248
3249 ret = fs_func->init_dir_entry(sb, &clu, 0, TYPE_DIR, clu.dir,
3250 0);
3251 if (ret != FFS_SUCCESS)
3252 return ret;
3253
3254 ret = fs_func->init_ext_entry(sb, &clu, 0, 1, NULL, &dot_name);
3255 if (ret != FFS_SUCCESS)
3256 return ret;
3257
3258 memcpy(dot_name.name, DOS_PAR_DIR_NAME, DOS_NAME_LENGTH);
3259
3260 if (p_dir->dir == p_fs->root_dir)
3261 ret = fs_func->init_dir_entry(sb, &clu, 1, TYPE_DIR,
3262 CLUSTER_32(0), 0);
3263 else
3264 ret = fs_func->init_dir_entry(sb, &clu, 1, TYPE_DIR,
3265 p_dir->dir, 0);
3266
3267 if (ret != FFS_SUCCESS)
3268 return ret;
3269
3270 ret = p_fs->fs_func->init_ext_entry(sb, &clu, 1, 1, NULL,
3271 &dot_name);
3272 if (ret != FFS_SUCCESS)
3273 return ret;
3274 }
3275
3276 /* (2) update the directory entry */
3277 /* make sub-dir entry in parent directory */
3278 ret = fs_func->init_dir_entry(sb, p_dir, dentry, TYPE_DIR, clu.dir,
3279 size);
3280 if (ret != FFS_SUCCESS)
3281 return ret;
3282
3283 ret = fs_func->init_ext_entry(sb, p_dir, dentry, num_entries, p_uniname,
3284 &dos_name);
3285 if (ret != FFS_SUCCESS)
3286 return ret;
3287
3288 fid->dir.dir = p_dir->dir;
3289 fid->dir.size = p_dir->size;
3290 fid->dir.flags = p_dir->flags;
3291 fid->entry = dentry;
3292
3293 fid->attr = ATTR_SUBDIR;
3294 fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01;
3295 fid->size = size;
3296 fid->start_clu = clu.dir;
3297
3298 fid->type = TYPE_DIR;
3299 fid->rwoffset = 0;
3300 fid->hint_last_off = -1;
3301
3302 return FFS_SUCCESS;
3303}
3304
3305s32 create_file(struct inode *inode, struct chain_t *p_dir,
3306 struct uni_name_t *p_uniname, u8 mode, struct file_id_t *fid)
3307{
3308 s32 ret, dentry, num_entries;
3309 struct dos_name_t dos_name;
3310 struct super_block *sb = inode->i_sb;
3311 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
3312 struct fs_func *fs_func = p_fs->fs_func;
3313
3314 ret = get_num_entries_and_dos_name(sb, p_dir, p_uniname, &num_entries,
3315 &dos_name);
3316 if (ret)
3317 return ret;
3318
3319 /* find_empty_entry must be called before alloc_cluster() */
3320 dentry = find_empty_entry(inode, p_dir, num_entries);
3321 if (dentry < 0)
3322 return FFS_FULL;
3323
3324 /* (1) update the directory entry */
3325 /* fill the dos name directory entry information of the created file.
3326 * the first cluster is not determined yet. (0)
3327 */
3328 ret = fs_func->init_dir_entry(sb, p_dir, dentry, TYPE_FILE | mode,
3329 CLUSTER_32(0), 0);
3330 if (ret != FFS_SUCCESS)
3331 return ret;
3332
3333 ret = fs_func->init_ext_entry(sb, p_dir, dentry, num_entries, p_uniname,
3334 &dos_name);
3335 if (ret != FFS_SUCCESS)
3336 return ret;
3337
3338 fid->dir.dir = p_dir->dir;
3339 fid->dir.size = p_dir->size;
3340 fid->dir.flags = p_dir->flags;
3341 fid->entry = dentry;
3342
3343 fid->attr = ATTR_ARCHIVE | mode;
3344 fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01;
3345 fid->size = 0;
3346 fid->start_clu = CLUSTER_32(~0);
3347
3348 fid->type = TYPE_FILE;
3349 fid->rwoffset = 0;
3350 fid->hint_last_off = -1;
3351
3352 return FFS_SUCCESS;
3353}
3354
3355void remove_file(struct inode *inode, struct chain_t *p_dir, s32 entry)
3356{
3357 s32 num_entries;
3358 sector_t sector;
3359 struct dentry_t *ep;
3360 struct super_block *sb = inode->i_sb;
3361 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
3362 struct fs_func *fs_func = p_fs->fs_func;
3363
3364 ep = get_entry_in_dir(sb, p_dir, entry, &sector);
3365 if (!ep)
3366 return;
3367
3368 buf_lock(sb, sector);
3369
3370 /* buf_lock() before call count_ext_entries() */
3371 num_entries = fs_func->count_ext_entries(sb, p_dir, entry, ep);
3372 if (num_entries < 0) {
3373 buf_unlock(sb, sector);
3374 return;
3375 }
3376 num_entries++;
3377
3378 buf_unlock(sb, sector);
3379
3380 /* (1) update the directory entry */
3381 fs_func->delete_dir_entry(sb, p_dir, entry, 0, num_entries);
3382}
3383
3384s32 rename_file(struct inode *inode, struct chain_t *p_dir, s32 oldentry,
3385 struct uni_name_t *p_uniname, struct file_id_t *fid)
3386{
3387 s32 ret, newentry = -1, num_old_entries, num_new_entries;
3388 sector_t sector_old, sector_new;
3389 struct dos_name_t dos_name;
3390 struct dentry_t *epold, *epnew;
3391 struct super_block *sb = inode->i_sb;
3392 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
3393 struct fs_func *fs_func = p_fs->fs_func;
3394
3395 epold = get_entry_in_dir(sb, p_dir, oldentry, &sector_old);
3396 if (!epold)
3397 return FFS_MEDIAERR;
3398
3399 buf_lock(sb, sector_old);
3400
3401 /* buf_lock() before call count_ext_entries() */
3402 num_old_entries = fs_func->count_ext_entries(sb, p_dir, oldentry,
3403 epold);
3404 if (num_old_entries < 0) {
3405 buf_unlock(sb, sector_old);
3406 return FFS_MEDIAERR;
3407 }
3408 num_old_entries++;
3409
3410 ret = get_num_entries_and_dos_name(sb, p_dir, p_uniname,
3411 &num_new_entries, &dos_name);
3412 if (ret) {
3413 buf_unlock(sb, sector_old);
3414 return ret;
3415 }
3416
3417 if (num_old_entries < num_new_entries) {
3418 newentry = find_empty_entry(inode, p_dir, num_new_entries);
3419 if (newentry < 0) {
3420 buf_unlock(sb, sector_old);
3421 return FFS_FULL;
3422 }
3423
3424 epnew = get_entry_in_dir(sb, p_dir, newentry, &sector_new);
3425 if (!epnew) {
3426 buf_unlock(sb, sector_old);
3427 return FFS_MEDIAERR;
3428 }
3429
3430 memcpy((void *)epnew, (void *)epold, DENTRY_SIZE);
3431 if (fs_func->get_entry_type(epnew) == TYPE_FILE) {
3432 fs_func->set_entry_attr(epnew,
3433 fs_func->get_entry_attr(epnew) |
3434 ATTR_ARCHIVE);
3435 fid->attr |= ATTR_ARCHIVE;
3436 }
3437 buf_modify(sb, sector_new);
3438 buf_unlock(sb, sector_old);
3439
3440 if (p_fs->vol_type == EXFAT) {
3441 epold = get_entry_in_dir(sb, p_dir, oldentry + 1,
3442 &sector_old);
3443 buf_lock(sb, sector_old);
3444 epnew = get_entry_in_dir(sb, p_dir, newentry + 1,
3445 &sector_new);
3446
3447 if (!epold || !epnew) {
3448 buf_unlock(sb, sector_old);
3449 return FFS_MEDIAERR;
3450 }
3451
3452 memcpy((void *)epnew, (void *)epold, DENTRY_SIZE);
3453 buf_modify(sb, sector_new);
3454 buf_unlock(sb, sector_old);
3455 }
3456
3457 ret = fs_func->init_ext_entry(sb, p_dir, newentry,
3458 num_new_entries, p_uniname,
3459 &dos_name);
3460 if (ret != FFS_SUCCESS)
3461 return ret;
3462
3463 fs_func->delete_dir_entry(sb, p_dir, oldentry, 0,
3464 num_old_entries);
3465 fid->entry = newentry;
3466 } else {
3467 if (fs_func->get_entry_type(epold) == TYPE_FILE) {
3468 fs_func->set_entry_attr(epold,
3469 fs_func->get_entry_attr(epold) |
3470 ATTR_ARCHIVE);
3471 fid->attr |= ATTR_ARCHIVE;
3472 }
3473 buf_modify(sb, sector_old);
3474 buf_unlock(sb, sector_old);
3475
3476 ret = fs_func->init_ext_entry(sb, p_dir, oldentry,
3477 num_new_entries, p_uniname,
3478 &dos_name);
3479 if (ret != FFS_SUCCESS)
3480 return ret;
3481
3482 fs_func->delete_dir_entry(sb, p_dir, oldentry, num_new_entries,
3483 num_old_entries);
3484 }
3485
3486 return FFS_SUCCESS;
3487}
3488
3489s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry,
3490 struct chain_t *p_newdir, struct uni_name_t *p_uniname,
3491 struct file_id_t *fid)
3492{
3493 s32 ret, newentry, num_new_entries, num_old_entries;
3494 sector_t sector_mov, sector_new;
3495 struct chain_t clu;
3496 struct dos_name_t dos_name;
3497 struct dentry_t *epmov, *epnew;
3498 struct super_block *sb = inode->i_sb;
3499 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
3500 struct fs_func *fs_func = p_fs->fs_func;
3501
3502 epmov = get_entry_in_dir(sb, p_olddir, oldentry, &sector_mov);
3503 if (!epmov)
3504 return FFS_MEDIAERR;
3505
3506 /* check if the source and target directory is the same */
3507 if (fs_func->get_entry_type(epmov) == TYPE_DIR &&
3508 fs_func->get_entry_clu0(epmov) == p_newdir->dir)
3509 return FFS_INVALIDPATH;
3510
3511 buf_lock(sb, sector_mov);
3512
3513 /* buf_lock() before call count_ext_entries() */
3514 num_old_entries = fs_func->count_ext_entries(sb, p_olddir, oldentry,
3515 epmov);
3516 if (num_old_entries < 0) {
3517 buf_unlock(sb, sector_mov);
3518 return FFS_MEDIAERR;
3519 }
3520 num_old_entries++;
3521
3522 ret = get_num_entries_and_dos_name(sb, p_newdir, p_uniname,
3523 &num_new_entries, &dos_name);
3524 if (ret) {
3525 buf_unlock(sb, sector_mov);
3526 return ret;
3527 }
3528
3529 newentry = find_empty_entry(inode, p_newdir, num_new_entries);
3530 if (newentry < 0) {
3531 buf_unlock(sb, sector_mov);
3532 return FFS_FULL;
3533 }
3534
3535 epnew = get_entry_in_dir(sb, p_newdir, newentry, &sector_new);
3536 if (!epnew) {
3537 buf_unlock(sb, sector_mov);
3538 return FFS_MEDIAERR;
3539 }
3540
3541 memcpy((void *)epnew, (void *)epmov, DENTRY_SIZE);
3542 if (fs_func->get_entry_type(epnew) == TYPE_FILE) {
3543 fs_func->set_entry_attr(epnew, fs_func->get_entry_attr(epnew) |
3544 ATTR_ARCHIVE);
3545 fid->attr |= ATTR_ARCHIVE;
3546 }
3547 buf_modify(sb, sector_new);
3548 buf_unlock(sb, sector_mov);
3549
3550 if (p_fs->vol_type == EXFAT) {
3551 epmov = get_entry_in_dir(sb, p_olddir, oldentry + 1,
3552 &sector_mov);
3553 buf_lock(sb, sector_mov);
3554 epnew = get_entry_in_dir(sb, p_newdir, newentry + 1,
3555 &sector_new);
3556 if (!epmov || !epnew) {
3557 buf_unlock(sb, sector_mov);
3558 return FFS_MEDIAERR;
3559 }
3560
3561 memcpy((void *)epnew, (void *)epmov, DENTRY_SIZE);
3562 buf_modify(sb, sector_new);
3563 buf_unlock(sb, sector_mov);
3564 } else if (fs_func->get_entry_type(epnew) == TYPE_DIR) {
3565 /* change ".." pointer to new parent dir */
3566 clu.dir = fs_func->get_entry_clu0(epnew);
3567 clu.flags = 0x01;
3568
3569 epnew = get_entry_in_dir(sb, &clu, 1, &sector_new);
3570 if (!epnew)
3571 return FFS_MEDIAERR;
3572
3573 if (p_newdir->dir == p_fs->root_dir)
3574 fs_func->set_entry_clu0(epnew, CLUSTER_32(0));
3575 else
3576 fs_func->set_entry_clu0(epnew, p_newdir->dir);
3577 buf_modify(sb, sector_new);
3578 }
3579
3580 ret = fs_func->init_ext_entry(sb, p_newdir, newentry, num_new_entries,
3581 p_uniname, &dos_name);
3582 if (ret != FFS_SUCCESS)
3583 return ret;
3584
3585 fs_func->delete_dir_entry(sb, p_olddir, oldentry, 0, num_old_entries);
3586
3587 fid->dir.dir = p_newdir->dir;
3588 fid->dir.size = p_newdir->size;
3589 fid->dir.flags = p_newdir->flags;
3590
3591 fid->entry = newentry;
3592
3593 return FFS_SUCCESS;
3594}
3595
3596/*
3597 * Sector Read/Write Functions
3598 */
3599
3600int sector_read(struct super_block *sb, sector_t sec, struct buffer_head **bh,
3601 bool read)
3602{
3603 s32 ret = FFS_MEDIAERR;
3604 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
3605
3606 if ((sec >= (p_fs->PBR_sector + p_fs->num_sectors)) &&
3607 (p_fs->num_sectors > 0)) {
3608 pr_err("[EXFAT] %s: out of range error! (sec = %llu)\n",
3609 __func__, (unsigned long long)sec);
3610 fs_error(sb);
3611 return ret;
3612 }
3613
3614 if (!p_fs->dev_ejected) {
3615 ret = bdev_read(sb, sec, bh, 1, read);
3616 if (ret != FFS_SUCCESS)
3617 p_fs->dev_ejected = 1;
3618 }
3619
3620 return ret;
3621}
3622
3623int sector_write(struct super_block *sb, sector_t sec, struct buffer_head *bh,
3624 bool sync)
3625{
3626 s32 ret = FFS_MEDIAERR;
3627 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
3628
3629 if (sec >= (p_fs->PBR_sector + p_fs->num_sectors) &&
3630 (p_fs->num_sectors > 0)) {
3631 pr_err("[EXFAT] %s: out of range error! (sec = %llu)\n",
3632 __func__, (unsigned long long)sec);
3633 fs_error(sb);
3634 return ret;
3635 }
3636
3637 if (!bh) {
3638 pr_err("[EXFAT] %s: bh is NULL!\n", __func__);
3639 fs_error(sb);
3640 return ret;
3641 }
3642
3643 if (!p_fs->dev_ejected) {
3644 ret = bdev_write(sb, sec, bh, 1, sync);
3645 if (ret != FFS_SUCCESS)
3646 p_fs->dev_ejected = 1;
3647 }
3648
3649 return ret;
3650}
3651
3652int multi_sector_read(struct super_block *sb, sector_t sec,
3653 struct buffer_head **bh, s32 num_secs, bool read)
3654{
3655 s32 ret = FFS_MEDIAERR;
3656 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
3657
3658 if (((sec + num_secs) > (p_fs->PBR_sector + p_fs->num_sectors)) &&
3659 (p_fs->num_sectors > 0)) {
3660 pr_err("[EXFAT] %s: out of range error! (sec = %llu, num_secs = %d)\n",
3661 __func__, (unsigned long long)sec, num_secs);
3662 fs_error(sb);
3663 return ret;
3664 }
3665
3666 if (!p_fs->dev_ejected) {
3667 ret = bdev_read(sb, sec, bh, num_secs, read);
3668 if (ret != FFS_SUCCESS)
3669 p_fs->dev_ejected = 1;
3670 }
3671
3672 return ret;
3673}
3674
3675int multi_sector_write(struct super_block *sb, sector_t sec,
3676 struct buffer_head *bh, s32 num_secs, bool sync)
3677{
3678 s32 ret = FFS_MEDIAERR;
3679 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
3680
3681 if ((sec + num_secs) > (p_fs->PBR_sector + p_fs->num_sectors) &&
3682 (p_fs->num_sectors > 0)) {
3683 pr_err("[EXFAT] %s: out of range error! (sec = %llu, num_secs = %d)\n",
3684 __func__, (unsigned long long)sec, num_secs);
3685 fs_error(sb);
3686 return ret;
3687 }
3688 if (!bh) {
3689 pr_err("[EXFAT] %s: bh is NULL!\n", __func__);
3690 fs_error(sb);
3691 return ret;
3692 }
3693
3694 if (!p_fs->dev_ejected) {
3695 ret = bdev_write(sb, sec, bh, num_secs, sync);
3696 if (ret != FFS_SUCCESS)
3697 p_fs->dev_ejected = 1;
3698 }
3699
3700 return ret;
3701}
diff --git a/drivers/staging/exfat/exfat_nls.c b/drivers/staging/exfat/exfat_nls.c
new file mode 100644
index 000000000000..03cb8290b5d2
--- /dev/null
+++ b/drivers/staging/exfat/exfat_nls.c
@@ -0,0 +1,404 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */
5
6#include <linux/string.h>
7#include <linux/nls.h>
8#include "exfat.h"
9
10static u16 bad_dos_chars[] = {
11 /* + , ; = [ ] */
12 0x002B, 0x002C, 0x003B, 0x003D, 0x005B, 0x005D,
13 0xFF0B, 0xFF0C, 0xFF1B, 0xFF1D, 0xFF3B, 0xFF3D,
14 0
15};
16
17static u16 bad_uni_chars[] = {
18 /* " * / : < > ? \ | */
19 0x0022, 0x002A, 0x002F, 0x003A,
20 0x003C, 0x003E, 0x003F, 0x005C, 0x007C,
21 0
22};
23
24static int convert_ch_to_uni(struct nls_table *nls, u16 *uni, u8 *ch,
25 bool *lossy)
26{
27 int len;
28
29 *uni = 0x0;
30
31 if (ch[0] < 0x80) {
32 *uni = (u16)ch[0];
33 return 1;
34 }
35
36 len = nls->char2uni(ch, NLS_MAX_CHARSET_SIZE, uni);
37 if (len < 0) {
38 /* conversion failed */
39 pr_info("%s: fail to use nls\n", __func__);
40 if (lossy)
41 *lossy = true;
42 *uni = (u16)'_';
43 if (!strcmp(nls->charset, "utf8"))
44 return 1;
45 else
46 return 2;
47 }
48
49 return len;
50}
51
52static int convert_uni_to_ch(struct nls_table *nls, u8 *ch, u16 uni,
53 bool *lossy)
54{
55 int len;
56
57 ch[0] = 0x0;
58
59 if (uni < 0x0080) {
60 ch[0] = (u8)uni;
61 return 1;
62 }
63
64 len = nls->uni2char(uni, ch, NLS_MAX_CHARSET_SIZE);
65 if (len < 0) {
66 /* conversion failed */
67 pr_info("%s: fail to use nls\n", __func__);
68 if (lossy)
69 *lossy = true;
70 ch[0] = '_';
71 return 1;
72 }
73
74 return len;
75}
76
77u16 nls_upper(struct super_block *sb, u16 a)
78{
79 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
80
81 if (EXFAT_SB(sb)->options.casesensitive)
82 return a;
83 if (p_fs->vol_utbl && p_fs->vol_utbl[get_col_index(a)])
84 return p_fs->vol_utbl[get_col_index(a)][get_row_index(a)];
85 else
86 return a;
87}
88
89static u16 *nls_wstrchr(u16 *str, u16 wchar)
90{
91 while (*str) {
92 if (*(str++) == wchar)
93 return str;
94 }
95
96 return NULL;
97}
98
99int nls_dosname_cmp(struct super_block *sb, u8 *a, u8 *b)
100{
101 return strncmp(a, b, DOS_NAME_LENGTH);
102}
103
104int nls_uniname_cmp(struct super_block *sb, u16 *a, u16 *b)
105{
106 int i;
107
108 for (i = 0; i < MAX_NAME_LENGTH; i++, a++, b++) {
109 if (nls_upper(sb, *a) != nls_upper(sb, *b))
110 return 1;
111 if (*a == 0x0)
112 return 0;
113 }
114 return 0;
115}
116
117void nls_uniname_to_dosname(struct super_block *sb,
118 struct dos_name_t *p_dosname,
119 struct uni_name_t *p_uniname, bool *p_lossy)
120{
121 int i, j, len;
122 bool lossy = false;
123 u8 buf[MAX_CHARSET_SIZE];
124 u8 lower = 0, upper = 0;
125 u8 *dosname = p_dosname->name;
126 u16 *uniname = p_uniname->name;
127 u16 *p, *last_period;
128 struct nls_table *nls = EXFAT_SB(sb)->nls_disk;
129
130 for (i = 0; i < DOS_NAME_LENGTH; i++)
131 *(dosname + i) = ' ';
132
133 if (!nls_uniname_cmp(sb, uniname, (u16 *)UNI_CUR_DIR_NAME)) {
134 *(dosname) = '.';
135 p_dosname->name_case = 0x0;
136 if (p_lossy)
137 *p_lossy = false;
138 return;
139 }
140
141 if (!nls_uniname_cmp(sb, uniname, (u16 *)UNI_PAR_DIR_NAME)) {
142 *(dosname) = '.';
143 *(dosname + 1) = '.';
144 p_dosname->name_case = 0x0;
145 if (p_lossy)
146 *p_lossy = false;
147 return;
148 }
149
150 /* search for the last embedded period */
151 last_period = NULL;
152 for (p = uniname; *p; p++) {
153 if (*p == (u16)'.')
154 last_period = p;
155 }
156
157 i = 0;
158 while (i < DOS_NAME_LENGTH) {
159 if (i == 8) {
160 if (!last_period)
161 break;
162
163 if (uniname <= last_period) {
164 if (uniname < last_period)
165 lossy = true;
166 uniname = last_period + 1;
167 }
168 }
169
170 if (*uniname == (u16)'\0') {
171 break;
172 } else if (*uniname == (u16)' ') {
173 lossy = true;
174 } else if (*uniname == (u16)'.') {
175 if (uniname < last_period)
176 lossy = true;
177 else
178 i = 8;
179 } else if (nls_wstrchr(bad_dos_chars, *uniname)) {
180 lossy = true;
181 *(dosname + i) = '_';
182 i++;
183 } else {
184 len = convert_uni_to_ch(nls, buf, *uniname, &lossy);
185
186 if (len > 1) {
187 if ((i >= 8) && ((i + len) > DOS_NAME_LENGTH))
188 break;
189
190 if ((i < 8) && ((i + len) > 8)) {
191 i = 8;
192 continue;
193 }
194
195 lower = 0xFF;
196
197 for (j = 0; j < len; j++, i++)
198 *(dosname + i) = *(buf + j);
199 } else { /* len == 1 */
200 if ((*buf >= 'a') && (*buf <= 'z')) {
201 *(dosname + i) = *buf - ('a' - 'A');
202
203 if (i < 8)
204 lower |= 0x08;
205 else
206 lower |= 0x10;
207 } else if ((*buf >= 'A') && (*buf <= 'Z')) {
208 *(dosname + i) = *buf;
209
210 if (i < 8)
211 upper |= 0x08;
212 else
213 upper |= 0x10;
214 } else {
215 *(dosname + i) = *buf;
216 }
217 i++;
218 }
219 }
220
221 uniname++;
222 }
223
224 if (*dosname == 0xE5)
225 *dosname = 0x05;
226
227 if (*uniname != 0x0)
228 lossy = true;
229
230 if (upper & lower)
231 p_dosname->name_case = 0xFF;
232 else
233 p_dosname->name_case = lower;
234
235 if (p_lossy)
236 *p_lossy = lossy;
237}
238
239void nls_dosname_to_uniname(struct super_block *sb,
240 struct uni_name_t *p_uniname,
241 struct dos_name_t *p_dosname)
242{
243 int i = 0, j, n = 0;
244 u8 buf[DOS_NAME_LENGTH + 2];
245 u8 *dosname = p_dosname->name;
246 u16 *uniname = p_uniname->name;
247 struct nls_table *nls = EXFAT_SB(sb)->nls_disk;
248
249 if (*dosname == 0x05) {
250 *buf = 0xE5;
251 i++;
252 n++;
253 }
254
255 for (; i < 8; i++, n++) {
256 if (*(dosname + i) == ' ')
257 break;
258
259 if ((*(dosname + i) >= 'A') && (*(dosname + i) <= 'Z') &&
260 (p_dosname->name_case & 0x08))
261 *(buf + n) = *(dosname + i) + ('a' - 'A');
262 else
263 *(buf + n) = *(dosname + i);
264 }
265 if (*(dosname + 8) != ' ') {
266 *(buf + n) = '.';
267 n++;
268 }
269
270 for (i = 8; i < DOS_NAME_LENGTH; i++, n++) {
271 if (*(dosname + i) == ' ')
272 break;
273
274 if ((*(dosname + i) >= 'A') && (*(dosname + i) <= 'Z') &&
275 (p_dosname->name_case & 0x10))
276 *(buf + n) = *(dosname + i) + ('a' - 'A');
277 else
278 *(buf + n) = *(dosname + i);
279 }
280 *(buf + n) = '\0';
281
282 i = 0;
283 j = 0;
284 while (j < (MAX_NAME_LENGTH - 1)) {
285 if (*(buf + i) == '\0')
286 break;
287
288 i += convert_ch_to_uni(nls, uniname, (buf + i), NULL);
289
290 uniname++;
291 j++;
292 }
293
294 *uniname = (u16)'\0';
295}
296
297void nls_uniname_to_cstring(struct super_block *sb, u8 *p_cstring,
298 struct uni_name_t *p_uniname)
299{
300 int i, j, len;
301 u8 buf[MAX_CHARSET_SIZE];
302 u16 *uniname = p_uniname->name;
303 struct nls_table *nls = EXFAT_SB(sb)->nls_io;
304
305 if (!nls) {
306 len = utf16s_to_utf8s(uniname, MAX_NAME_LENGTH,
307 UTF16_HOST_ENDIAN, p_cstring,
308 MAX_NAME_LENGTH);
309 p_cstring[len] = 0;
310 return;
311 }
312
313 i = 0;
314 while (i < (MAX_NAME_LENGTH - 1)) {
315 if (*uniname == (u16)'\0')
316 break;
317
318 len = convert_uni_to_ch(nls, buf, *uniname, NULL);
319
320 if (len > 1) {
321 for (j = 0; j < len; j++)
322 *p_cstring++ = (char)*(buf + j);
323 } else { /* len == 1 */
324 *p_cstring++ = (char)*buf;
325 }
326
327 uniname++;
328 i++;
329 }
330
331 *p_cstring = '\0';
332}
333
334void nls_cstring_to_uniname(struct super_block *sb,
335 struct uni_name_t *p_uniname, u8 *p_cstring,
336 bool *p_lossy)
337{
338 int i, j;
339 bool lossy = false;
340 u8 *end_of_name;
341 u8 upname[MAX_NAME_LENGTH * 2];
342 u16 *uniname = p_uniname->name;
343 struct nls_table *nls = EXFAT_SB(sb)->nls_io;
344
345 /* strip all trailing spaces */
346 end_of_name = p_cstring + strlen(p_cstring);
347
348 while (*(--end_of_name) == ' ') {
349 if (end_of_name < p_cstring)
350 break;
351 }
352 *(++end_of_name) = '\0';
353
354 if (strcmp(p_cstring, ".") && strcmp(p_cstring, "..")) {
355 /* strip all trailing periods */
356 while (*(--end_of_name) == '.') {
357 if (end_of_name < p_cstring)
358 break;
359 }
360 *(++end_of_name) = '\0';
361 }
362
363 if (*p_cstring == '\0')
364 lossy = true;
365
366 if (!nls) {
367 i = utf8s_to_utf16s(p_cstring, MAX_NAME_LENGTH,
368 UTF16_HOST_ENDIAN, uniname,
369 MAX_NAME_LENGTH);
370 for (j = 0; j < i; j++)
371 SET16_A(upname + j * 2, nls_upper(sb, uniname[j]));
372 uniname[i] = '\0';
373 } else {
374 i = 0;
375 j = 0;
376 while (j < (MAX_NAME_LENGTH - 1)) {
377 if (*(p_cstring + i) == '\0')
378 break;
379
380 i += convert_ch_to_uni(nls, uniname,
381 (u8 *)(p_cstring + i), &lossy);
382
383 if ((*uniname < 0x0020) ||
384 nls_wstrchr(bad_uni_chars, *uniname))
385 lossy = true;
386
387 SET16_A(upname + j * 2, nls_upper(sb, *uniname));
388
389 uniname++;
390 j++;
391 }
392
393 if (*(p_cstring + i) != '\0')
394 lossy = true;
395 *uniname = (u16)'\0';
396 }
397
398 p_uniname->name_len = j;
399 p_uniname->name_hash = calc_checksum_2byte(upname, j << 1, 0,
400 CS_DEFAULT);
401
402 if (p_lossy)
403 *p_lossy = lossy;
404}
diff --git a/drivers/staging/exfat/exfat_super.c b/drivers/staging/exfat/exfat_super.c
new file mode 100644
index 000000000000..5f6caee819a6
--- /dev/null
+++ b/drivers/staging/exfat/exfat_super.c
@@ -0,0 +1,4049 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */
5
6#include <linux/module.h>
7#include <linux/init.h>
8#include <linux/time.h>
9#include <linux/slab.h>
10#include <linux/seq_file.h>
11#include <linux/pagemap.h>
12#include <linux/mpage.h>
13#include <linux/buffer_head.h>
14#include <linux/exportfs.h>
15#include <linux/mount.h>
16#include <linux/vfs.h>
17#include <linux/aio.h>
18#include <linux/iversion.h>
19#include <linux/parser.h>
20#include <linux/uio.h>
21#include <linux/writeback.h>
22#include <linux/log2.h>
23#include <linux/hash.h>
24#include <linux/backing-dev.h>
25#include <linux/sched.h>
26#include <linux/fs_struct.h>
27#include <linux/namei.h>
28
29#include <linux/string.h>
30#include <linux/nls.h>
31#include <linux/mutex.h>
32#include <linux/swap.h>
33
34#define EXFAT_VERSION "1.3.0"
35
36#include "exfat.h"
37
38static struct kmem_cache *exfat_inode_cachep;
39
40static int exfat_default_codepage = CONFIG_EXFAT_DEFAULT_CODEPAGE;
41static char exfat_default_iocharset[] = CONFIG_EXFAT_DEFAULT_IOCHARSET;
42
43#define INC_IVERSION(x) (inode_inc_iversion(x))
44#define GET_IVERSION(x) (inode_peek_iversion_raw(x))
45#define SET_IVERSION(x, y) (inode_set_iversion(x, y))
46
47static struct inode *exfat_iget(struct super_block *sb, loff_t i_pos);
48static int exfat_sync_inode(struct inode *inode);
49static struct inode *exfat_build_inode(struct super_block *sb,
50 struct file_id_t *fid, loff_t i_pos);
51static int exfat_write_inode(struct inode *inode,
52 struct writeback_control *wbc);
53static void exfat_write_super(struct super_block *sb);
54
55#define UNIX_SECS_1980 315532800L
56#define UNIX_SECS_2108 4354819200L
57
58/* Convert a FAT time/date pair to a UNIX date (seconds since 1 1 70). */
59static void exfat_time_fat2unix(struct timespec64 *ts, struct date_time_t *tp)
60{
61 ts->tv_sec = mktime64(tp->Year + 1980, tp->Month + 1, tp->Day,
62 tp->Hour, tp->Minute, tp->Second);
63
64 ts->tv_nsec = tp->MilliSecond * NSEC_PER_MSEC;
65}
66
67/* Convert linear UNIX date to a FAT time/date pair. */
68static void exfat_time_unix2fat(struct timespec64 *ts, struct date_time_t *tp)
69{
70 time64_t second = ts->tv_sec;
71 struct tm tm;
72
73 time64_to_tm(second, 0, &tm);
74
75 if (second < UNIX_SECS_1980) {
76 tp->MilliSecond = 0;
77 tp->Second = 0;
78 tp->Minute = 0;
79 tp->Hour = 0;
80 tp->Day = 1;
81 tp->Month = 1;
82 tp->Year = 0;
83 return;
84 }
85
86 if (second >= UNIX_SECS_2108) {
87 tp->MilliSecond = 999;
88 tp->Second = 59;
89 tp->Minute = 59;
90 tp->Hour = 23;
91 tp->Day = 31;
92 tp->Month = 12;
93 tp->Year = 127;
94 return;
95 }
96
97 tp->MilliSecond = ts->tv_nsec / NSEC_PER_MSEC;
98 tp->Second = tm.tm_sec;
99 tp->Minute = tm.tm_min;
100 tp->Hour = tm.tm_hour;
101 tp->Day = tm.tm_mday;
102 tp->Month = tm.tm_mon + 1;
103 tp->Year = tm.tm_year + 1900 - 1980;
104}
105
106struct timestamp_t *tm_current(struct timestamp_t *tp)
107{
108 time64_t second = ktime_get_real_seconds();
109 struct tm tm;
110
111 time64_to_tm(second, 0, &tm);
112
113 if (second < UNIX_SECS_1980) {
114 tp->sec = 0;
115 tp->min = 0;
116 tp->hour = 0;
117 tp->day = 1;
118 tp->mon = 1;
119 tp->year = 0;
120 return tp;
121 }
122
123 if (second >= UNIX_SECS_2108) {
124 tp->sec = 59;
125 tp->min = 59;
126 tp->hour = 23;
127 tp->day = 31;
128 tp->mon = 12;
129 tp->year = 127;
130 return tp;
131 }
132
133 tp->sec = tm.tm_sec;
134 tp->min = tm.tm_min;
135 tp->hour = tm.tm_hour;
136 tp->day = tm.tm_mday;
137 tp->mon = tm.tm_mon + 1;
138 tp->year = tm.tm_year + 1900 - 1980;
139
140 return tp;
141}
142
143static void __lock_super(struct super_block *sb)
144{
145 struct exfat_sb_info *sbi = EXFAT_SB(sb);
146
147 mutex_lock(&sbi->s_lock);
148}
149
150static void __unlock_super(struct super_block *sb)
151{
152 struct exfat_sb_info *sbi = EXFAT_SB(sb);
153
154 mutex_unlock(&sbi->s_lock);
155}
156
157static int __is_sb_dirty(struct super_block *sb)
158{
159 struct exfat_sb_info *sbi = EXFAT_SB(sb);
160
161 return sbi->s_dirt;
162}
163
164static void __set_sb_clean(struct super_block *sb)
165{
166 struct exfat_sb_info *sbi = EXFAT_SB(sb);
167
168 sbi->s_dirt = 0;
169}
170
171static int __exfat_revalidate(struct dentry *dentry)
172{
173 return 0;
174}
175
176static int exfat_revalidate(struct dentry *dentry, unsigned int flags)
177{
178 if (flags & LOOKUP_RCU)
179 return -ECHILD;
180
181 if (dentry->d_inode)
182 return 1;
183 return __exfat_revalidate(dentry);
184}
185
186static int exfat_revalidate_ci(struct dentry *dentry, unsigned int flags)
187{
188 if (flags & LOOKUP_RCU)
189 return -ECHILD;
190
191 if (dentry->d_inode)
192 return 1;
193
194 if (!flags)
195 return 0;
196
197 if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET))
198 return 0;
199
200 return __exfat_revalidate(dentry);
201}
202
203static unsigned int __exfat_striptail_len(unsigned int len, const char *name)
204{
205 while (len && name[len - 1] == '.')
206 len--;
207 return len;
208}
209
210static unsigned int exfat_striptail_len(const struct qstr *qstr)
211{
212 return __exfat_striptail_len(qstr->len, qstr->name);
213}
214
215static int exfat_d_hash(const struct dentry *dentry, struct qstr *qstr)
216{
217 qstr->hash = full_name_hash(dentry, qstr->name,
218 exfat_striptail_len(qstr));
219 return 0;
220}
221
222static int exfat_d_hashi(const struct dentry *dentry, struct qstr *qstr)
223{
224 struct super_block *sb = dentry->d_sb;
225 const unsigned char *name;
226 unsigned int len;
227 unsigned long hash;
228
229 name = qstr->name;
230 len = exfat_striptail_len(qstr);
231
232 hash = init_name_hash(dentry);
233 while (len--)
234 hash = partial_name_hash(nls_upper(sb, *name++), hash);
235 qstr->hash = end_name_hash(hash);
236
237 return 0;
238}
239
240static int exfat_cmpi(const struct dentry *dentry, unsigned int len,
241 const char *str, const struct qstr *name)
242{
243 struct nls_table *t = EXFAT_SB(dentry->d_sb)->nls_io;
244 unsigned int alen, blen;
245
246 alen = exfat_striptail_len(name);
247 blen = __exfat_striptail_len(len, str);
248 if (alen == blen) {
249 if (!t) {
250 if (strncasecmp(name->name, str, alen) == 0)
251 return 0;
252 } else {
253 if (nls_strnicmp(t, name->name, str, alen) == 0)
254 return 0;
255 }
256 }
257 return 1;
258}
259
260static int exfat_cmp(const struct dentry *dentry, unsigned int len,
261 const char *str, const struct qstr *name)
262{
263 unsigned int alen, blen;
264
265 alen = exfat_striptail_len(name);
266 blen = __exfat_striptail_len(len, str);
267 if (alen == blen) {
268 if (strncmp(name->name, str, alen) == 0)
269 return 0;
270 }
271 return 1;
272}
273
274static const struct dentry_operations exfat_ci_dentry_ops = {
275 .d_revalidate = exfat_revalidate_ci,
276 .d_hash = exfat_d_hashi,
277 .d_compare = exfat_cmpi,
278};
279
280static const struct dentry_operations exfat_dentry_ops = {
281 .d_revalidate = exfat_revalidate,
282 .d_hash = exfat_d_hash,
283 .d_compare = exfat_cmp,
284};
285
286static DEFINE_SEMAPHORE(z_sem);
287
288static inline void fs_sync(struct super_block *sb, bool do_sync)
289{
290 if (do_sync)
291 bdev_sync(sb);
292}
293
294/*
295 * If ->i_mode can't hold S_IWUGO (i.e. ATTR_RO), we use ->i_attrs to
296 * save ATTR_RO instead of ->i_mode.
297 *
298 * If it's directory and !sbi->options.rodir, ATTR_RO isn't read-only
299 * bit, it's just used as flag for app.
300 */
301static inline int exfat_mode_can_hold_ro(struct inode *inode)
302{
303 struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb);
304
305 if (S_ISDIR(inode->i_mode))
306 return 0;
307
308 if ((~sbi->options.fs_fmask) & 0222)
309 return 1;
310 return 0;
311}
312
313/* Convert attribute bits and a mask to the UNIX mode. */
314static inline mode_t exfat_make_mode(struct exfat_sb_info *sbi, u32 attr,
315 mode_t mode)
316{
317 if ((attr & ATTR_READONLY) && !(attr & ATTR_SUBDIR))
318 mode &= ~0222;
319
320 if (attr & ATTR_SUBDIR)
321 return (mode & ~sbi->options.fs_dmask) | S_IFDIR;
322 else if (attr & ATTR_SYMLINK)
323 return (mode & ~sbi->options.fs_dmask) | S_IFLNK;
324 else
325 return (mode & ~sbi->options.fs_fmask) | S_IFREG;
326}
327
328/* Return the FAT attribute byte for this inode */
329static inline u32 exfat_make_attr(struct inode *inode)
330{
331 if (exfat_mode_can_hold_ro(inode) && !(inode->i_mode & 0222))
332 return (EXFAT_I(inode)->fid.attr) | ATTR_READONLY;
333 else
334 return EXFAT_I(inode)->fid.attr;
335}
336
337static inline void exfat_save_attr(struct inode *inode, u32 attr)
338{
339 if (exfat_mode_can_hold_ro(inode))
340 EXFAT_I(inode)->fid.attr = attr & ATTR_RWMASK;
341 else
342 EXFAT_I(inode)->fid.attr = attr & (ATTR_RWMASK | ATTR_READONLY);
343}
344
345static int ffsMountVol(struct super_block *sb)
346{
347 int i, ret;
348 struct pbr_sector_t *p_pbr;
349 struct buffer_head *tmp_bh = NULL;
350 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
351 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
352
353 pr_info("[EXFAT] trying to mount...\n");
354
355 down(&z_sem);
356
357 buf_init(sb);
358
359 sema_init(&p_fs->v_sem, 1);
360 p_fs->dev_ejected = 0;
361
362 /* open the block device */
363 bdev_open(sb);
364
365 if (p_bd->sector_size < sb->s_blocksize) {
366 ret = FFS_MEDIAERR;
367 goto out;
368 }
369 if (p_bd->sector_size > sb->s_blocksize)
370 sb_set_blocksize(sb, p_bd->sector_size);
371
372 /* read Sector 0 */
373 if (sector_read(sb, 0, &tmp_bh, 1) != FFS_SUCCESS) {
374 ret = FFS_MEDIAERR;
375 goto out;
376 }
377
378 p_fs->PBR_sector = 0;
379
380 p_pbr = (struct pbr_sector_t *)tmp_bh->b_data;
381
382 /* check the validity of PBR */
383 if (GET16_A(p_pbr->signature) != PBR_SIGNATURE) {
384 brelse(tmp_bh);
385 bdev_close(sb);
386 ret = FFS_FORMATERR;
387 goto out;
388 }
389
390 /* fill fs_struct */
391 for (i = 0; i < 53; i++)
392 if (p_pbr->bpb[i])
393 break;
394
395 if (i < 53) {
396#ifdef CONFIG_EXFAT_DONT_MOUNT_VFAT
397 ret = -EINVAL;
398 printk(KERN_INFO "EXFAT: Attempted to mount VFAT filesystem\n");
399 goto out;
400#else
401 if (GET16(p_pbr->bpb + 11)) /* num_fat_sectors */
402 ret = fat16_mount(sb, p_pbr);
403 else
404 ret = fat32_mount(sb, p_pbr);
405#endif
406 } else {
407 ret = exfat_mount(sb, p_pbr);
408 }
409
410 brelse(tmp_bh);
411
412 if (ret) {
413 bdev_close(sb);
414 goto out;
415 }
416
417 if (p_fs->vol_type == EXFAT) {
418 ret = load_alloc_bitmap(sb);
419 if (ret) {
420 bdev_close(sb);
421 goto out;
422 }
423 ret = load_upcase_table(sb);
424 if (ret) {
425 free_alloc_bitmap(sb);
426 bdev_close(sb);
427 goto out;
428 }
429 }
430
431 if (p_fs->dev_ejected) {
432 if (p_fs->vol_type == EXFAT) {
433 free_upcase_table(sb);
434 free_alloc_bitmap(sb);
435 }
436 bdev_close(sb);
437 ret = FFS_MEDIAERR;
438 goto out;
439 }
440
441 pr_info("[EXFAT] mounted successfully\n");
442
443out:
444 up(&z_sem);
445
446 return ret;
447}
448
449static int ffsUmountVol(struct super_block *sb)
450{
451 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
452 int err = FFS_SUCCESS;
453
454 pr_info("[EXFAT] trying to unmount...\n");
455
456 down(&z_sem);
457
458 /* acquire the lock for file system critical section */
459 down(&p_fs->v_sem);
460
461 fs_sync(sb, false);
462 fs_set_vol_flags(sb, VOL_CLEAN);
463
464 if (p_fs->vol_type == EXFAT) {
465 free_upcase_table(sb);
466 free_alloc_bitmap(sb);
467 }
468
469 FAT_release_all(sb);
470 buf_release_all(sb);
471
472 /* close the block device */
473 bdev_close(sb);
474
475 if (p_fs->dev_ejected) {
476 pr_info("[EXFAT] unmounted with media errors. Device is already ejected.\n");
477 err = FFS_MEDIAERR;
478 }
479
480 buf_shutdown(sb);
481
482 /* release the lock for file system critical section */
483 up(&p_fs->v_sem);
484 up(&z_sem);
485
486 pr_info("[EXFAT] unmounted successfully\n");
487
488 return err;
489}
490
491static int ffsGetVolInfo(struct super_block *sb, struct vol_info_t *info)
492{
493 int err = FFS_SUCCESS;
494 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
495
496 /* check the validity of pointer parameters */
497 if (!info)
498 return FFS_ERROR;
499
500 /* acquire the lock for file system critical section */
501 down(&p_fs->v_sem);
502
503 if (p_fs->used_clusters == UINT_MAX)
504 p_fs->used_clusters = p_fs->fs_func->count_used_clusters(sb);
505
506 info->FatType = p_fs->vol_type;
507 info->ClusterSize = p_fs->cluster_size;
508 info->NumClusters = p_fs->num_clusters - 2; /* clu 0 & 1 */
509 info->UsedClusters = p_fs->used_clusters;
510 info->FreeClusters = info->NumClusters - info->UsedClusters;
511
512 if (p_fs->dev_ejected)
513 err = FFS_MEDIAERR;
514
515 /* release the lock for file system critical section */
516 up(&p_fs->v_sem);
517
518 return err;
519}
520
521static int ffsSyncVol(struct super_block *sb, bool do_sync)
522{
523 int err = FFS_SUCCESS;
524 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
525
526 /* acquire the lock for file system critical section */
527 down(&p_fs->v_sem);
528
529 /* synchronize the file system */
530 fs_sync(sb, do_sync);
531 fs_set_vol_flags(sb, VOL_CLEAN);
532
533 if (p_fs->dev_ejected)
534 err = FFS_MEDIAERR;
535
536 /* release the lock for file system critical section */
537 up(&p_fs->v_sem);
538
539 return err;
540}
541
542/*----------------------------------------------------------------------*/
543/* File Operation Functions */
544/*----------------------------------------------------------------------*/
545
546static int ffsLookupFile(struct inode *inode, char *path, struct file_id_t *fid)
547{
548 int ret, dentry, num_entries;
549 struct chain_t dir;
550 struct uni_name_t uni_name;
551 struct dos_name_t dos_name;
552 struct dentry_t *ep, *ep2;
553 struct entry_set_cache_t *es = NULL;
554 struct super_block *sb = inode->i_sb;
555 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
556
557 pr_debug("%s entered\n", __func__);
558
559 /* check the validity of pointer parameters */
560 if (!fid || !path || (*path == '\0'))
561 return FFS_ERROR;
562
563 /* acquire the lock for file system critical section */
564 down(&p_fs->v_sem);
565
566 /* check the validity of directory name in the given pathname */
567 ret = resolve_path(inode, path, &dir, &uni_name);
568 if (ret)
569 goto out;
570
571 ret = get_num_entries_and_dos_name(sb, &dir, &uni_name, &num_entries,
572 &dos_name);
573 if (ret)
574 goto out;
575
576 /* search the file name for directories */
577 dentry = p_fs->fs_func->find_dir_entry(sb, &dir, &uni_name, num_entries,
578 &dos_name, TYPE_ALL);
579 if (dentry < -1) {
580 ret = FFS_NOTFOUND;
581 goto out;
582 }
583
584 fid->dir.dir = dir.dir;
585 fid->dir.size = dir.size;
586 fid->dir.flags = dir.flags;
587 fid->entry = dentry;
588
589 if (dentry == -1) {
590 fid->type = TYPE_DIR;
591 fid->rwoffset = 0;
592 fid->hint_last_off = -1;
593
594 fid->attr = ATTR_SUBDIR;
595 fid->flags = 0x01;
596 fid->size = 0;
597 fid->start_clu = p_fs->root_dir;
598 } else {
599 if (p_fs->vol_type == EXFAT) {
600 es = get_entry_set_in_dir(sb, &dir, dentry,
601 ES_2_ENTRIES, &ep);
602 if (!es) {
603 ret = FFS_MEDIAERR;
604 goto out;
605 }
606 ep2 = ep + 1;
607 } else {
608 ep = get_entry_in_dir(sb, &dir, dentry, NULL);
609 if (!ep) {
610 ret = FFS_MEDIAERR;
611 goto out;
612 }
613 ep2 = ep;
614 }
615
616 fid->type = p_fs->fs_func->get_entry_type(ep);
617 fid->rwoffset = 0;
618 fid->hint_last_off = -1;
619 fid->attr = p_fs->fs_func->get_entry_attr(ep);
620
621 fid->size = p_fs->fs_func->get_entry_size(ep2);
622 if ((fid->type == TYPE_FILE) && (fid->size == 0)) {
623 fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01;
624 fid->start_clu = CLUSTER_32(~0);
625 } else {
626 fid->flags = p_fs->fs_func->get_entry_flag(ep2);
627 fid->start_clu = p_fs->fs_func->get_entry_clu0(ep2);
628 }
629
630 if (p_fs->vol_type == EXFAT)
631 release_entry_set(es);
632 }
633
634 if (p_fs->dev_ejected)
635 ret = FFS_MEDIAERR;
636out:
637 /* release the lock for file system critical section */
638 up(&p_fs->v_sem);
639
640 return ret;
641}
642
643static int ffsCreateFile(struct inode *inode, char *path, u8 mode,
644 struct file_id_t *fid)
645{
646 struct chain_t dir;
647 struct uni_name_t uni_name;
648 struct super_block *sb = inode->i_sb;
649 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
650 int ret;
651
652 /* check the validity of pointer parameters */
653 if (!fid || !path || (*path == '\0'))
654 return FFS_ERROR;
655
656 /* acquire the lock for file system critical section */
657 down(&p_fs->v_sem);
658
659 /* check the validity of directory name in the given pathname */
660 ret = resolve_path(inode, path, &dir, &uni_name);
661 if (ret)
662 goto out;
663
664 fs_set_vol_flags(sb, VOL_DIRTY);
665
666 /* create a new file */
667 ret = create_file(inode, &dir, &uni_name, mode, fid);
668
669#ifdef CONFIG_EXFAT_DELAYED_SYNC
670 fs_sync(sb, false);
671 fs_set_vol_flags(sb, VOL_CLEAN);
672#endif
673
674 if (p_fs->dev_ejected)
675 ret = FFS_MEDIAERR;
676
677out:
678 /* release the lock for file system critical section */
679 up(&p_fs->v_sem);
680
681 return ret;
682}
683
684static int ffsReadFile(struct inode *inode, struct file_id_t *fid, void *buffer,
685 u64 count, u64 *rcount)
686{
687 s32 offset, sec_offset, clu_offset;
688 u32 clu;
689 int ret = 0;
690 sector_t LogSector;
691 u64 oneblkread, read_bytes;
692 struct buffer_head *tmp_bh = NULL;
693 struct super_block *sb = inode->i_sb;
694 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
695 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
696
697 /* check the validity of the given file id */
698 if (!fid)
699 return FFS_INVALIDFID;
700
701 /* check the validity of pointer parameters */
702 if (!buffer)
703 return FFS_ERROR;
704
705 /* acquire the lock for file system critical section */
706 down(&p_fs->v_sem);
707
708 /* check if the given file ID is opened */
709 if (fid->type != TYPE_FILE) {
710 ret = FFS_PERMISSIONERR;
711 goto out;
712 }
713
714 if (fid->rwoffset > fid->size)
715 fid->rwoffset = fid->size;
716
717 if (count > (fid->size - fid->rwoffset))
718 count = fid->size - fid->rwoffset;
719
720 if (count == 0) {
721 if (rcount)
722 *rcount = 0;
723 ret = FFS_EOF;
724 goto out;
725 }
726
727 read_bytes = 0;
728
729 while (count > 0) {
730 clu_offset = (s32)(fid->rwoffset >> p_fs->cluster_size_bits);
731 clu = fid->start_clu;
732
733 if (fid->flags == 0x03) {
734 clu += clu_offset;
735 } else {
736 /* hint information */
737 if ((clu_offset > 0) && (fid->hint_last_off > 0) &&
738 (clu_offset >= fid->hint_last_off)) {
739 clu_offset -= fid->hint_last_off;
740 clu = fid->hint_last_clu;
741 }
742
743 while (clu_offset > 0) {
744 /* clu = FAT_read(sb, clu); */
745 if (FAT_read(sb, clu, &clu) == -1)
746 return FFS_MEDIAERR;
747
748 clu_offset--;
749 }
750 }
751
752 /* hint information */
753 fid->hint_last_off = (s32)(fid->rwoffset >>
754 p_fs->cluster_size_bits);
755 fid->hint_last_clu = clu;
756
757 /* byte offset in cluster */
758 offset = (s32)(fid->rwoffset & (p_fs->cluster_size - 1));
759
760 /* sector offset in cluster */
761 sec_offset = offset >> p_bd->sector_size_bits;
762
763 /* byte offset in sector */
764 offset &= p_bd->sector_size_mask;
765
766 LogSector = START_SECTOR(clu) + sec_offset;
767
768 oneblkread = (u64)(p_bd->sector_size - offset);
769 if (oneblkread > count)
770 oneblkread = count;
771
772 if ((offset == 0) && (oneblkread == p_bd->sector_size)) {
773 if (sector_read(sb, LogSector, &tmp_bh, 1) !=
774 FFS_SUCCESS)
775 goto err_out;
776 memcpy((char *)buffer + read_bytes,
777 (char *)tmp_bh->b_data, (s32)oneblkread);
778 } else {
779 if (sector_read(sb, LogSector, &tmp_bh, 1) !=
780 FFS_SUCCESS)
781 goto err_out;
782 memcpy((char *)buffer + read_bytes,
783 (char *)tmp_bh->b_data + offset,
784 (s32)oneblkread);
785 }
786 count -= oneblkread;
787 read_bytes += oneblkread;
788 fid->rwoffset += oneblkread;
789 }
790 brelse(tmp_bh);
791
792/* How did this ever work and not leak a brlse()?? */
793err_out:
794 /* set the size of read bytes */
795 if (rcount)
796 *rcount = read_bytes;
797
798 if (p_fs->dev_ejected)
799 ret = FFS_MEDIAERR;
800
801out:
802 /* release the lock for file system critical section */
803 up(&p_fs->v_sem);
804
805 return ret;
806}
807
808static int ffsWriteFile(struct inode *inode, struct file_id_t *fid,
809 void *buffer, u64 count, u64 *wcount)
810{
811 bool modified = false;
812 s32 offset, sec_offset, clu_offset;
813 s32 num_clusters, num_alloc, num_alloced = (s32)~0;
814 int ret = 0;
815 u32 clu, last_clu;
816 sector_t LogSector, sector = 0;
817 u64 oneblkwrite, write_bytes;
818 struct chain_t new_clu;
819 struct timestamp_t tm;
820 struct dentry_t *ep, *ep2;
821 struct entry_set_cache_t *es = NULL;
822 struct buffer_head *tmp_bh = NULL;
823 struct super_block *sb = inode->i_sb;
824 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
825 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
826
827 /* check the validity of the given file id */
828 if (!fid)
829 return FFS_INVALIDFID;
830
831 /* check the validity of pointer parameters */
832 if (!buffer)
833 return FFS_ERROR;
834
835 /* acquire the lock for file system critical section */
836 down(&p_fs->v_sem);
837
838 /* check if the given file ID is opened */
839 if (fid->type != TYPE_FILE) {
840 ret = FFS_PERMISSIONERR;
841 goto out;
842 }
843
844 if (fid->rwoffset > fid->size)
845 fid->rwoffset = fid->size;
846
847 if (count == 0) {
848 if (wcount)
849 *wcount = 0;
850 ret = FFS_SUCCESS;
851 goto out;
852 }
853
854 fs_set_vol_flags(sb, VOL_DIRTY);
855
856 if (fid->size == 0)
857 num_clusters = 0;
858 else
859 num_clusters = (s32)((fid->size - 1) >>
860 p_fs->cluster_size_bits) + 1;
861
862 write_bytes = 0;
863
864 while (count > 0) {
865 clu_offset = (s32)(fid->rwoffset >> p_fs->cluster_size_bits);
866 clu = last_clu = fid->start_clu;
867
868 if (fid->flags == 0x03) {
869 if ((clu_offset > 0) && (clu != CLUSTER_32(~0))) {
870 last_clu += clu_offset - 1;
871
872 if (clu_offset == num_clusters)
873 clu = CLUSTER_32(~0);
874 else
875 clu += clu_offset;
876 }
877 } else {
878 /* hint information */
879 if ((clu_offset > 0) && (fid->hint_last_off > 0) &&
880 (clu_offset >= fid->hint_last_off)) {
881 clu_offset -= fid->hint_last_off;
882 clu = fid->hint_last_clu;
883 }
884
885 while ((clu_offset > 0) && (clu != CLUSTER_32(~0))) {
886 last_clu = clu;
887 /* clu = FAT_read(sb, clu); */
888 if (FAT_read(sb, clu, &clu) == -1) {
889 ret = FFS_MEDIAERR;
890 goto out;
891 }
892 clu_offset--;
893 }
894 }
895
896 if (clu == CLUSTER_32(~0)) {
897 num_alloc = (s32)((count - 1) >>
898 p_fs->cluster_size_bits) + 1;
899 new_clu.dir = (last_clu == CLUSTER_32(~0)) ?
900 CLUSTER_32(~0) : last_clu + 1;
901 new_clu.size = 0;
902 new_clu.flags = fid->flags;
903
904 /* (1) allocate a chain of clusters */
905 num_alloced = p_fs->fs_func->alloc_cluster(sb,
906 num_alloc,
907 &new_clu);
908 if (num_alloced == 0)
909 break;
910 if (num_alloced < 0) {
911 ret = FFS_MEDIAERR;
912 goto out;
913 }
914
915 /* (2) append to the FAT chain */
916 if (last_clu == CLUSTER_32(~0)) {
917 if (new_clu.flags == 0x01)
918 fid->flags = 0x01;
919 fid->start_clu = new_clu.dir;
920 modified = true;
921 } else {
922 if (new_clu.flags != fid->flags) {
923 exfat_chain_cont_cluster(sb,
924 fid->start_clu,
925 num_clusters);
926 fid->flags = 0x01;
927 modified = true;
928 }
929 if (new_clu.flags == 0x01)
930 FAT_write(sb, last_clu, new_clu.dir);
931 }
932
933 num_clusters += num_alloced;
934 clu = new_clu.dir;
935 }
936
937 /* hint information */
938 fid->hint_last_off = (s32)(fid->rwoffset >>
939 p_fs->cluster_size_bits);
940 fid->hint_last_clu = clu;
941
942 /* byte offset in cluster */
943 offset = (s32)(fid->rwoffset & (p_fs->cluster_size - 1));
944
945 /* sector offset in cluster */
946 sec_offset = offset >> p_bd->sector_size_bits;
947
948 /* byte offset in sector */
949 offset &= p_bd->sector_size_mask;
950
951 LogSector = START_SECTOR(clu) + sec_offset;
952
953 oneblkwrite = (u64)(p_bd->sector_size - offset);
954 if (oneblkwrite > count)
955 oneblkwrite = count;
956
957 if ((offset == 0) && (oneblkwrite == p_bd->sector_size)) {
958 if (sector_read(sb, LogSector, &tmp_bh, 0) !=
959 FFS_SUCCESS)
960 goto err_out;
961 memcpy((char *)tmp_bh->b_data,
962 (char *)buffer + write_bytes, (s32)oneblkwrite);
963 if (sector_write(sb, LogSector, tmp_bh, 0) !=
964 FFS_SUCCESS) {
965 brelse(tmp_bh);
966 goto err_out;
967 }
968 } else {
969 if ((offset > 0) ||
970 ((fid->rwoffset + oneblkwrite) < fid->size)) {
971 if (sector_read(sb, LogSector, &tmp_bh, 1) !=
972 FFS_SUCCESS)
973 goto err_out;
974 } else {
975 if (sector_read(sb, LogSector, &tmp_bh, 0) !=
976 FFS_SUCCESS)
977 goto err_out;
978 }
979
980 memcpy((char *)tmp_bh->b_data + offset,
981 (char *)buffer + write_bytes, (s32)oneblkwrite);
982 if (sector_write(sb, LogSector, tmp_bh, 0) !=
983 FFS_SUCCESS) {
984 brelse(tmp_bh);
985 goto err_out;
986 }
987 }
988
989 count -= oneblkwrite;
990 write_bytes += oneblkwrite;
991 fid->rwoffset += oneblkwrite;
992
993 fid->attr |= ATTR_ARCHIVE;
994
995 if (fid->size < fid->rwoffset) {
996 fid->size = fid->rwoffset;
997 modified = true;
998 }
999 }
1000
1001 brelse(tmp_bh);
1002
1003 /* (3) update the direcoty entry */
1004 if (p_fs->vol_type == EXFAT) {
1005 es = get_entry_set_in_dir(sb, &(fid->dir), fid->entry,
1006 ES_ALL_ENTRIES, &ep);
1007 if (!es)
1008 goto err_out;
1009 ep2 = ep + 1;
1010 } else {
1011 ep = get_entry_in_dir(sb, &(fid->dir), fid->entry, &sector);
1012 if (!ep)
1013 goto err_out;
1014 ep2 = ep;
1015 }
1016
1017 p_fs->fs_func->set_entry_time(ep, tm_current(&tm), TM_MODIFY);
1018 p_fs->fs_func->set_entry_attr(ep, fid->attr);
1019
1020 if (p_fs->vol_type != EXFAT)
1021 buf_modify(sb, sector);
1022
1023 if (modified) {
1024 if (p_fs->fs_func->get_entry_flag(ep2) != fid->flags)
1025 p_fs->fs_func->set_entry_flag(ep2, fid->flags);
1026
1027 if (p_fs->fs_func->get_entry_size(ep2) != fid->size)
1028 p_fs->fs_func->set_entry_size(ep2, fid->size);
1029
1030 if (p_fs->fs_func->get_entry_clu0(ep2) != fid->start_clu)
1031 p_fs->fs_func->set_entry_clu0(ep2, fid->start_clu);
1032
1033 if (p_fs->vol_type != EXFAT)
1034 buf_modify(sb, sector);
1035 }
1036
1037 if (p_fs->vol_type == EXFAT) {
1038 update_dir_checksum_with_entry_set(sb, es);
1039 release_entry_set(es);
1040 }
1041
1042#ifdef CONFIG_EXFAT_DELAYED_SYNC
1043 fs_sync(sb, false);
1044 fs_set_vol_flags(sb, VOL_CLEAN);
1045#endif
1046
1047err_out:
1048 /* set the size of written bytes */
1049 if (wcount)
1050 *wcount = write_bytes;
1051
1052 if (num_alloced == 0)
1053 ret = FFS_FULL;
1054
1055 else if (p_fs->dev_ejected)
1056 ret = FFS_MEDIAERR;
1057
1058out:
1059 /* release the lock for file system critical section */
1060 up(&p_fs->v_sem);
1061
1062 return ret;
1063}
1064
1065static int ffsTruncateFile(struct inode *inode, u64 old_size, u64 new_size)
1066{
1067 s32 num_clusters;
1068 u32 last_clu = CLUSTER_32(0);
1069 int ret = 0;
1070 sector_t sector = 0;
1071 struct chain_t clu;
1072 struct timestamp_t tm;
1073 struct dentry_t *ep, *ep2;
1074 struct super_block *sb = inode->i_sb;
1075 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1076 struct file_id_t *fid = &(EXFAT_I(inode)->fid);
1077 struct entry_set_cache_t *es = NULL;
1078
1079 pr_debug("%s entered (inode %p size %llu)\n", __func__, inode,
1080 new_size);
1081
1082 /* acquire the lock for file system critical section */
1083 down(&p_fs->v_sem);
1084
1085 /* check if the given file ID is opened */
1086 if (fid->type != TYPE_FILE) {
1087 ret = FFS_PERMISSIONERR;
1088 goto out;
1089 }
1090
1091 if (fid->size != old_size) {
1092 pr_err("[EXFAT] truncate : can't skip it because of size-mismatch(old:%lld->fid:%lld).\n",
1093 old_size, fid->size);
1094 }
1095
1096 if (old_size <= new_size) {
1097 ret = FFS_SUCCESS;
1098 goto out;
1099 }
1100
1101 fs_set_vol_flags(sb, VOL_DIRTY);
1102
1103 clu.dir = fid->start_clu;
1104 clu.size = (s32)((old_size - 1) >> p_fs->cluster_size_bits) + 1;
1105 clu.flags = fid->flags;
1106
1107 if (new_size > 0) {
1108 num_clusters = (s32)((new_size - 1) >>
1109 p_fs->cluster_size_bits) + 1;
1110
1111 if (clu.flags == 0x03) {
1112 clu.dir += num_clusters;
1113 } else {
1114 while (num_clusters > 0) {
1115 last_clu = clu.dir;
1116 if (FAT_read(sb, clu.dir, &clu.dir) == -1) {
1117 ret = FFS_MEDIAERR;
1118 goto out;
1119 }
1120 num_clusters--;
1121 }
1122 }
1123
1124 clu.size -= num_clusters;
1125 }
1126
1127 fid->size = new_size;
1128 fid->attr |= ATTR_ARCHIVE;
1129 if (new_size == 0) {
1130 fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01;
1131 fid->start_clu = CLUSTER_32(~0);
1132 }
1133
1134 /* (1) update the directory entry */
1135 if (p_fs->vol_type == EXFAT) {
1136 es = get_entry_set_in_dir(sb, &fid->dir, fid->entry,
1137 ES_ALL_ENTRIES, &ep);
1138 if (!es) {
1139 ret = FFS_MEDIAERR;
1140 goto out;
1141 }
1142 ep2 = ep + 1;
1143 } else {
1144 ep = get_entry_in_dir(sb, &(fid->dir), fid->entry, &sector);
1145 if (!ep) {
1146 ret = FFS_MEDIAERR;
1147 goto out;
1148 }
1149 ep2 = ep;
1150 }
1151
1152 p_fs->fs_func->set_entry_time(ep, tm_current(&tm), TM_MODIFY);
1153 p_fs->fs_func->set_entry_attr(ep, fid->attr);
1154
1155 p_fs->fs_func->set_entry_size(ep2, new_size);
1156 if (new_size == 0) {
1157 p_fs->fs_func->set_entry_flag(ep2, 0x01);
1158 p_fs->fs_func->set_entry_clu0(ep2, CLUSTER_32(0));
1159 }
1160
1161 if (p_fs->vol_type != EXFAT) {
1162 buf_modify(sb, sector);
1163 } else {
1164 update_dir_checksum_with_entry_set(sb, es);
1165 release_entry_set(es);
1166 }
1167
1168 /* (2) cut off from the FAT chain */
1169 if (last_clu != CLUSTER_32(0)) {
1170 if (fid->flags == 0x01)
1171 FAT_write(sb, last_clu, CLUSTER_32(~0));
1172 }
1173
1174 /* (3) free the clusters */
1175 p_fs->fs_func->free_cluster(sb, &clu, 0);
1176
1177 /* hint information */
1178 fid->hint_last_off = -1;
1179 if (fid->rwoffset > fid->size)
1180 fid->rwoffset = fid->size;
1181
1182#ifdef CONFIG_EXFAT_DELAYED_SYNC
1183 fs_sync(sb, false);
1184 fs_set_vol_flags(sb, VOL_CLEAN);
1185#endif
1186
1187 if (p_fs->dev_ejected)
1188 ret = FFS_MEDIAERR;
1189
1190out:
1191 pr_debug("%s exited (%d)\n", __func__, ret);
1192 /* release the lock for file system critical section */
1193 up(&p_fs->v_sem);
1194
1195 return ret;
1196}
1197
1198static void update_parent_info(struct file_id_t *fid,
1199 struct inode *parent_inode)
1200{
1201 struct fs_info_t *p_fs = &(EXFAT_SB(parent_inode->i_sb)->fs_info);
1202 struct file_id_t *parent_fid = &(EXFAT_I(parent_inode)->fid);
1203
1204 if (unlikely((parent_fid->flags != fid->dir.flags) ||
1205 (parent_fid->size !=
1206 (fid->dir.size << p_fs->cluster_size_bits)) ||
1207 (parent_fid->start_clu != fid->dir.dir))) {
1208 fid->dir.dir = parent_fid->start_clu;
1209 fid->dir.flags = parent_fid->flags;
1210 fid->dir.size = ((parent_fid->size + (p_fs->cluster_size - 1))
1211 >> p_fs->cluster_size_bits);
1212 }
1213}
1214
1215static int ffsMoveFile(struct inode *old_parent_inode, struct file_id_t *fid,
1216 struct inode *new_parent_inode, struct dentry *new_dentry)
1217{
1218 s32 ret;
1219 s32 dentry;
1220 struct chain_t olddir, newdir;
1221 struct chain_t *p_dir = NULL;
1222 struct uni_name_t uni_name;
1223 struct dentry_t *ep;
1224 struct super_block *sb = old_parent_inode->i_sb;
1225 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1226 u8 *new_path = (u8 *)new_dentry->d_name.name;
1227 struct inode *new_inode = new_dentry->d_inode;
1228 int num_entries;
1229 struct file_id_t *new_fid = NULL;
1230 s32 new_entry = 0;
1231
1232 /* check the validity of the given file id */
1233 if (!fid)
1234 return FFS_INVALIDFID;
1235
1236 /* check the validity of pointer parameters */
1237 if (!new_path || (*new_path == '\0'))
1238 return FFS_ERROR;
1239
1240 /* acquire the lock for file system critical section */
1241 down(&p_fs->v_sem);
1242
1243 update_parent_info(fid, old_parent_inode);
1244
1245 olddir.dir = fid->dir.dir;
1246 olddir.size = fid->dir.size;
1247 olddir.flags = fid->dir.flags;
1248
1249 dentry = fid->entry;
1250
1251 /* check if the old file is "." or ".." */
1252 if (p_fs->vol_type != EXFAT) {
1253 if ((olddir.dir != p_fs->root_dir) && (dentry < 2)) {
1254 ret = FFS_PERMISSIONERR;
1255 goto out2;
1256 }
1257 }
1258
1259 ep = get_entry_in_dir(sb, &olddir, dentry, NULL);
1260 if (!ep) {
1261 ret = FFS_MEDIAERR;
1262 goto out2;
1263 }
1264
1265 if (p_fs->fs_func->get_entry_attr(ep) & ATTR_READONLY) {
1266 ret = FFS_PERMISSIONERR;
1267 goto out2;
1268 }
1269
1270 /* check whether new dir is existing directory and empty */
1271 if (new_inode) {
1272 u32 entry_type;
1273
1274 ret = FFS_MEDIAERR;
1275 new_fid = &EXFAT_I(new_inode)->fid;
1276
1277 update_parent_info(new_fid, new_parent_inode);
1278
1279 p_dir = &(new_fid->dir);
1280 new_entry = new_fid->entry;
1281 ep = get_entry_in_dir(sb, p_dir, new_entry, NULL);
1282 if (!ep)
1283 goto out;
1284
1285 entry_type = p_fs->fs_func->get_entry_type(ep);
1286
1287 if (entry_type == TYPE_DIR) {
1288 struct chain_t new_clu;
1289
1290 new_clu.dir = new_fid->start_clu;
1291 new_clu.size = (s32)((new_fid->size - 1) >>
1292 p_fs->cluster_size_bits) + 1;
1293 new_clu.flags = new_fid->flags;
1294
1295 if (!is_dir_empty(sb, &new_clu)) {
1296 ret = FFS_FILEEXIST;
1297 goto out;
1298 }
1299 }
1300 }
1301
1302 /* check the validity of directory name in the given new pathname */
1303 ret = resolve_path(new_parent_inode, new_path, &newdir, &uni_name);
1304 if (ret)
1305 goto out2;
1306
1307 fs_set_vol_flags(sb, VOL_DIRTY);
1308
1309 if (olddir.dir == newdir.dir)
1310 ret = rename_file(new_parent_inode, &olddir, dentry, &uni_name,
1311 fid);
1312 else
1313 ret = move_file(new_parent_inode, &olddir, dentry, &newdir,
1314 &uni_name, fid);
1315
1316 if ((ret == FFS_SUCCESS) && new_inode) {
1317 /* delete entries of new_dir */
1318 ep = get_entry_in_dir(sb, p_dir, new_entry, NULL);
1319 if (!ep)
1320 goto out;
1321
1322 num_entries = p_fs->fs_func->count_ext_entries(sb, p_dir,
1323 new_entry, ep);
1324 if (num_entries < 0)
1325 goto out;
1326 p_fs->fs_func->delete_dir_entry(sb, p_dir, new_entry, 0,
1327 num_entries + 1);
1328 }
1329out:
1330#ifdef CONFIG_EXFAT_DELAYED_SYNC
1331 fs_sync(sb, false);
1332 fs_set_vol_flags(sb, VOL_CLEAN);
1333#endif
1334
1335 if (p_fs->dev_ejected)
1336 ret = FFS_MEDIAERR;
1337out2:
1338 /* release the lock for file system critical section */
1339 up(&p_fs->v_sem);
1340
1341 return ret;
1342}
1343
1344static int ffsRemoveFile(struct inode *inode, struct file_id_t *fid)
1345{
1346 s32 dentry;
1347 int ret = FFS_SUCCESS;
1348 struct chain_t dir, clu_to_free;
1349 struct dentry_t *ep;
1350 struct super_block *sb = inode->i_sb;
1351 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1352
1353 /* check the validity of the given file id */
1354 if (!fid)
1355 return FFS_INVALIDFID;
1356
1357 /* acquire the lock for file system critical section */
1358 down(&p_fs->v_sem);
1359
1360 dir.dir = fid->dir.dir;
1361 dir.size = fid->dir.size;
1362 dir.flags = fid->dir.flags;
1363
1364 dentry = fid->entry;
1365
1366 ep = get_entry_in_dir(sb, &dir, dentry, NULL);
1367 if (!ep) {
1368 ret = FFS_MEDIAERR;
1369 goto out;
1370 }
1371
1372 if (p_fs->fs_func->get_entry_attr(ep) & ATTR_READONLY) {
1373 ret = FFS_PERMISSIONERR;
1374 goto out;
1375 }
1376 fs_set_vol_flags(sb, VOL_DIRTY);
1377
1378 /* (1) update the directory entry */
1379 remove_file(inode, &dir, dentry);
1380
1381 clu_to_free.dir = fid->start_clu;
1382 clu_to_free.size = (s32)((fid->size - 1) >> p_fs->cluster_size_bits) + 1;
1383 clu_to_free.flags = fid->flags;
1384
1385 /* (2) free the clusters */
1386 p_fs->fs_func->free_cluster(sb, &clu_to_free, 0);
1387
1388 fid->size = 0;
1389 fid->start_clu = CLUSTER_32(~0);
1390 fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01;
1391
1392#ifdef CONFIG_EXFAT_DELAYED_SYNC
1393 fs_sync(sb, false);
1394 fs_set_vol_flags(sb, VOL_CLEAN);
1395#endif
1396
1397 if (p_fs->dev_ejected)
1398 ret = FFS_MEDIAERR;
1399out:
1400 /* release the lock for file system critical section */
1401 up(&p_fs->v_sem);
1402
1403 return ret;
1404}
1405
1406#if 0
1407/* Not currently wired up */
1408static int ffsSetAttr(struct inode *inode, u32 attr)
1409{
1410 u32 type;
1411 int ret = FFS_SUCCESS;
1412 sector_t sector = 0;
1413 struct dentry_t *ep;
1414 struct super_block *sb = inode->i_sb;
1415 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1416 struct file_id_t *fid = &(EXFAT_I(inode)->fid);
1417 u8 is_dir = (fid->type == TYPE_DIR) ? 1 : 0;
1418 struct entry_set_cache_t *es = NULL;
1419
1420 if (fid->attr == attr) {
1421 if (p_fs->dev_ejected)
1422 return FFS_MEDIAERR;
1423 return FFS_SUCCESS;
1424 }
1425
1426 if (is_dir) {
1427 if ((fid->dir.dir == p_fs->root_dir) &&
1428 (fid->entry == -1)) {
1429 if (p_fs->dev_ejected)
1430 return FFS_MEDIAERR;
1431 return FFS_SUCCESS;
1432 }
1433 }
1434
1435 /* acquire the lock for file system critical section */
1436 down(&p_fs->v_sem);
1437
1438 /* get the directory entry of given file */
1439 if (p_fs->vol_type == EXFAT) {
1440 es = get_entry_set_in_dir(sb, &(fid->dir), fid->entry,
1441 ES_ALL_ENTRIES, &ep);
1442 if (!es) {
1443 ret = FFS_MEDIAERR;
1444 goto out;
1445 }
1446 } else {
1447 ep = get_entry_in_dir(sb, &(fid->dir), fid->entry, &sector);
1448 if (!ep) {
1449 ret = FFS_MEDIAERR;
1450 goto out;
1451 }
1452 }
1453
1454 type = p_fs->fs_func->get_entry_type(ep);
1455
1456 if (((type == TYPE_FILE) && (attr & ATTR_SUBDIR)) ||
1457 ((type == TYPE_DIR) && (!(attr & ATTR_SUBDIR)))) {
1458 if (p_fs->dev_ejected)
1459 ret = FFS_MEDIAERR;
1460 else
1461 ret = FFS_ERROR;
1462
1463 if (p_fs->vol_type == EXFAT)
1464 release_entry_set(es);
1465 goto out;
1466 }
1467
1468 fs_set_vol_flags(sb, VOL_DIRTY);
1469
1470 /* set the file attribute */
1471 fid->attr = attr;
1472 p_fs->fs_func->set_entry_attr(ep, attr);
1473
1474 if (p_fs->vol_type != EXFAT) {
1475 buf_modify(sb, sector);
1476 } else {
1477 update_dir_checksum_with_entry_set(sb, es);
1478 release_entry_set(es);
1479 }
1480
1481#ifdef CONFIG_EXFAT_DELAYED_SYNC
1482 fs_sync(sb, false);
1483 fs_set_vol_flags(sb, VOL_CLEAN);
1484#endif
1485
1486 if (p_fs->dev_ejected)
1487 ret = FFS_MEDIAERR;
1488out:
1489 /* release the lock for file system critical section */
1490 up(&p_fs->v_sem);
1491
1492 return ret;
1493}
1494#endif
1495
1496static int ffsReadStat(struct inode *inode, struct dir_entry_t *info)
1497{
1498 sector_t sector = 0;
1499 s32 count;
1500 int ret = FFS_SUCCESS;
1501 struct chain_t dir;
1502 struct uni_name_t uni_name;
1503 struct timestamp_t tm;
1504 struct dentry_t *ep, *ep2;
1505 struct super_block *sb = inode->i_sb;
1506 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1507 struct file_id_t *fid = &(EXFAT_I(inode)->fid);
1508 struct entry_set_cache_t *es = NULL;
1509 u8 is_dir = (fid->type == TYPE_DIR) ? 1 : 0;
1510
1511 pr_debug("%s entered\n", __func__);
1512
1513 /* acquire the lock for file system critical section */
1514 down(&p_fs->v_sem);
1515
1516 if (is_dir) {
1517 if ((fid->dir.dir == p_fs->root_dir) &&
1518 (fid->entry == -1)) {
1519 info->Attr = ATTR_SUBDIR;
1520 memset((char *)&info->CreateTimestamp, 0,
1521 sizeof(struct date_time_t));
1522 memset((char *)&info->ModifyTimestamp, 0,
1523 sizeof(struct date_time_t));
1524 memset((char *)&info->AccessTimestamp, 0,
1525 sizeof(struct date_time_t));
1526 strcpy(info->ShortName, ".");
1527 strcpy(info->Name, ".");
1528
1529 dir.dir = p_fs->root_dir;
1530 dir.flags = 0x01;
1531
1532 if (p_fs->root_dir == CLUSTER_32(0)) {
1533 /* FAT16 root_dir */
1534 info->Size = p_fs->dentries_in_root <<
1535 DENTRY_SIZE_BITS;
1536 } else {
1537 info->Size = count_num_clusters(sb, &dir) <<
1538 p_fs->cluster_size_bits;
1539 }
1540
1541 count = count_dos_name_entries(sb, &dir, TYPE_DIR);
1542 if (count < 0) {
1543 ret = FFS_MEDIAERR;
1544 goto out;
1545 }
1546 info->NumSubdirs = count;
1547
1548 if (p_fs->dev_ejected)
1549 ret = FFS_MEDIAERR;
1550 goto out;
1551 }
1552 }
1553
1554 /* get the directory entry of given file or directory */
1555 if (p_fs->vol_type == EXFAT) {
1556 es = get_entry_set_in_dir(sb, &(fid->dir), fid->entry,
1557 ES_2_ENTRIES, &ep);
1558 if (!es) {
1559 ret = FFS_MEDIAERR;
1560 goto out;
1561 }
1562 ep2 = ep + 1;
1563 } else {
1564 ep = get_entry_in_dir(sb, &(fid->dir), fid->entry, &sector);
1565 if (!ep) {
1566 ret = FFS_MEDIAERR;
1567 goto out;
1568 }
1569 ep2 = ep;
1570 buf_lock(sb, sector);
1571 }
1572
1573 /* set FILE_INFO structure using the acquired struct dentry_t */
1574 info->Attr = p_fs->fs_func->get_entry_attr(ep);
1575
1576 p_fs->fs_func->get_entry_time(ep, &tm, TM_CREATE);
1577 info->CreateTimestamp.Year = tm.year;
1578 info->CreateTimestamp.Month = tm.mon;
1579 info->CreateTimestamp.Day = tm.day;
1580 info->CreateTimestamp.Hour = tm.hour;
1581 info->CreateTimestamp.Minute = tm.min;
1582 info->CreateTimestamp.Second = tm.sec;
1583 info->CreateTimestamp.MilliSecond = 0;
1584
1585 p_fs->fs_func->get_entry_time(ep, &tm, TM_MODIFY);
1586 info->ModifyTimestamp.Year = tm.year;
1587 info->ModifyTimestamp.Month = tm.mon;
1588 info->ModifyTimestamp.Day = tm.day;
1589 info->ModifyTimestamp.Hour = tm.hour;
1590 info->ModifyTimestamp.Minute = tm.min;
1591 info->ModifyTimestamp.Second = tm.sec;
1592 info->ModifyTimestamp.MilliSecond = 0;
1593
1594 memset((char *)&info->AccessTimestamp, 0, sizeof(struct date_time_t));
1595
1596 *(uni_name.name) = 0x0;
1597 /* XXX this is very bad for exfat cuz name is already included in es.
1598 * API should be revised
1599 */
1600 p_fs->fs_func->get_uni_name_from_ext_entry(sb, &(fid->dir), fid->entry,
1601 uni_name.name);
1602 if (*uni_name.name == 0x0 && p_fs->vol_type != EXFAT)
1603 get_uni_name_from_dos_entry(sb, (struct dos_dentry_t *)ep,
1604 &uni_name, 0x1);
1605 nls_uniname_to_cstring(sb, info->Name, &uni_name);
1606
1607 if (p_fs->vol_type == EXFAT) {
1608 info->NumSubdirs = 2;
1609 } else {
1610 buf_unlock(sb, sector);
1611 get_uni_name_from_dos_entry(sb, (struct dos_dentry_t *)ep,
1612 &uni_name, 0x0);
1613 nls_uniname_to_cstring(sb, info->ShortName, &uni_name);
1614 info->NumSubdirs = 0;
1615 }
1616
1617 info->Size = p_fs->fs_func->get_entry_size(ep2);
1618
1619 if (p_fs->vol_type == EXFAT)
1620 release_entry_set(es);
1621
1622 if (is_dir) {
1623 dir.dir = fid->start_clu;
1624 dir.flags = 0x01;
1625
1626 if (info->Size == 0)
1627 info->Size = (u64)count_num_clusters(sb, &dir) <<
1628 p_fs->cluster_size_bits;
1629
1630 count = count_dos_name_entries(sb, &dir, TYPE_DIR);
1631 if (count < 0) {
1632 ret = FFS_MEDIAERR;
1633 goto out;
1634 }
1635 info->NumSubdirs += count;
1636 }
1637
1638 if (p_fs->dev_ejected)
1639 ret = FFS_MEDIAERR;
1640
1641out:
1642 /* release the lock for file system critical section */
1643 up(&p_fs->v_sem);
1644
1645 pr_debug("%s exited successfully\n", __func__);
1646 return ret;
1647}
1648
1649static int ffsWriteStat(struct inode *inode, struct dir_entry_t *info)
1650{
1651 sector_t sector = 0;
1652 int ret = FFS_SUCCESS;
1653 struct timestamp_t tm;
1654 struct dentry_t *ep, *ep2;
1655 struct entry_set_cache_t *es = NULL;
1656 struct super_block *sb = inode->i_sb;
1657 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1658 struct file_id_t *fid = &(EXFAT_I(inode)->fid);
1659 u8 is_dir = (fid->type == TYPE_DIR) ? 1 : 0;
1660
1661 pr_debug("%s entered (inode %p info %p\n", __func__, inode, info);
1662
1663 /* acquire the lock for file system critical section */
1664 down(&p_fs->v_sem);
1665
1666 if (is_dir) {
1667 if ((fid->dir.dir == p_fs->root_dir) &&
1668 (fid->entry == -1)) {
1669 if (p_fs->dev_ejected)
1670 ret = FFS_MEDIAERR;
1671 ret = FFS_SUCCESS;
1672 goto out;
1673 }
1674 }
1675
1676 fs_set_vol_flags(sb, VOL_DIRTY);
1677
1678 /* get the directory entry of given file or directory */
1679 if (p_fs->vol_type == EXFAT) {
1680 es = get_entry_set_in_dir(sb, &(fid->dir), fid->entry,
1681 ES_ALL_ENTRIES, &ep);
1682 if (!es) {
1683 ret = FFS_MEDIAERR;
1684 goto out;
1685 }
1686 ep2 = ep + 1;
1687 } else {
1688 /* for other than exfat */
1689 ep = get_entry_in_dir(sb, &(fid->dir), fid->entry, &sector);
1690 if (!ep) {
1691 ret = FFS_MEDIAERR;
1692 goto out;
1693 }
1694 ep2 = ep;
1695 }
1696
1697 p_fs->fs_func->set_entry_attr(ep, info->Attr);
1698
1699 /* set FILE_INFO structure using the acquired struct dentry_t */
1700 tm.sec = info->CreateTimestamp.Second;
1701 tm.min = info->CreateTimestamp.Minute;
1702 tm.hour = info->CreateTimestamp.Hour;
1703 tm.day = info->CreateTimestamp.Day;
1704 tm.mon = info->CreateTimestamp.Month;
1705 tm.year = info->CreateTimestamp.Year;
1706 p_fs->fs_func->set_entry_time(ep, &tm, TM_CREATE);
1707
1708 tm.sec = info->ModifyTimestamp.Second;
1709 tm.min = info->ModifyTimestamp.Minute;
1710 tm.hour = info->ModifyTimestamp.Hour;
1711 tm.day = info->ModifyTimestamp.Day;
1712 tm.mon = info->ModifyTimestamp.Month;
1713 tm.year = info->ModifyTimestamp.Year;
1714 p_fs->fs_func->set_entry_time(ep, &tm, TM_MODIFY);
1715
1716 p_fs->fs_func->set_entry_size(ep2, info->Size);
1717
1718 if (p_fs->vol_type != EXFAT) {
1719 buf_modify(sb, sector);
1720 } else {
1721 update_dir_checksum_with_entry_set(sb, es);
1722 release_entry_set(es);
1723 }
1724
1725 if (p_fs->dev_ejected)
1726 ret = FFS_MEDIAERR;
1727
1728out:
1729 /* release the lock for file system critical section */
1730 up(&p_fs->v_sem);
1731
1732 pr_debug("%s exited (%d)\n", __func__, ret);
1733
1734 return ret;
1735}
1736
1737static int ffsMapCluster(struct inode *inode, s32 clu_offset, u32 *clu)
1738{
1739 s32 num_clusters, num_alloced;
1740 bool modified = false;
1741 u32 last_clu;
1742 int ret = FFS_SUCCESS;
1743 sector_t sector = 0;
1744 struct chain_t new_clu;
1745 struct dentry_t *ep;
1746 struct entry_set_cache_t *es = NULL;
1747 struct super_block *sb = inode->i_sb;
1748 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1749 struct file_id_t *fid = &(EXFAT_I(inode)->fid);
1750
1751 /* check the validity of pointer parameters */
1752 if (!clu)
1753 return FFS_ERROR;
1754
1755 /* acquire the lock for file system critical section */
1756 down(&p_fs->v_sem);
1757
1758 fid->rwoffset = (s64)(clu_offset) << p_fs->cluster_size_bits;
1759
1760 if (EXFAT_I(inode)->mmu_private == 0)
1761 num_clusters = 0;
1762 else
1763 num_clusters = (s32)((EXFAT_I(inode)->mmu_private - 1) >>
1764 p_fs->cluster_size_bits) + 1;
1765
1766 *clu = last_clu = fid->start_clu;
1767
1768 if (fid->flags == 0x03) {
1769 if ((clu_offset > 0) && (*clu != CLUSTER_32(~0))) {
1770 last_clu += clu_offset - 1;
1771
1772 if (clu_offset == num_clusters)
1773 *clu = CLUSTER_32(~0);
1774 else
1775 *clu += clu_offset;
1776 }
1777 } else {
1778 /* hint information */
1779 if ((clu_offset > 0) && (fid->hint_last_off > 0) &&
1780 (clu_offset >= fid->hint_last_off)) {
1781 clu_offset -= fid->hint_last_off;
1782 *clu = fid->hint_last_clu;
1783 }
1784
1785 while ((clu_offset > 0) && (*clu != CLUSTER_32(~0))) {
1786 last_clu = *clu;
1787 if (FAT_read(sb, *clu, clu) == -1) {
1788 ret = FFS_MEDIAERR;
1789 goto out;
1790 }
1791 clu_offset--;
1792 }
1793 }
1794
1795 if (*clu == CLUSTER_32(~0)) {
1796 fs_set_vol_flags(sb, VOL_DIRTY);
1797
1798 new_clu.dir = (last_clu == CLUSTER_32(~0)) ? CLUSTER_32(~0) :
1799 last_clu + 1;
1800 new_clu.size = 0;
1801 new_clu.flags = fid->flags;
1802
1803 /* (1) allocate a cluster */
1804 num_alloced = p_fs->fs_func->alloc_cluster(sb, 1, &new_clu);
1805 if (num_alloced < 0) {
1806 ret = FFS_MEDIAERR;
1807 goto out;
1808 } else if (num_alloced == 0) {
1809 ret = FFS_FULL;
1810 goto out;
1811 }
1812
1813 /* (2) append to the FAT chain */
1814 if (last_clu == CLUSTER_32(~0)) {
1815 if (new_clu.flags == 0x01)
1816 fid->flags = 0x01;
1817 fid->start_clu = new_clu.dir;
1818 modified = true;
1819 } else {
1820 if (new_clu.flags != fid->flags) {
1821 exfat_chain_cont_cluster(sb, fid->start_clu,
1822 num_clusters);
1823 fid->flags = 0x01;
1824 modified = true;
1825 }
1826 if (new_clu.flags == 0x01)
1827 FAT_write(sb, last_clu, new_clu.dir);
1828 }
1829
1830 num_clusters += num_alloced;
1831 *clu = new_clu.dir;
1832
1833 if (p_fs->vol_type == EXFAT) {
1834 es = get_entry_set_in_dir(sb, &fid->dir, fid->entry,
1835 ES_ALL_ENTRIES, &ep);
1836 if (!es) {
1837 ret = FFS_MEDIAERR;
1838 goto out;
1839 }
1840 /* get stream entry */
1841 ep++;
1842 }
1843
1844 /* (3) update directory entry */
1845 if (modified) {
1846 if (p_fs->vol_type != EXFAT) {
1847 ep = get_entry_in_dir(sb, &(fid->dir),
1848 fid->entry, &sector);
1849 if (!ep) {
1850 ret = FFS_MEDIAERR;
1851 goto out;
1852 }
1853 }
1854
1855 if (p_fs->fs_func->get_entry_flag(ep) != fid->flags)
1856 p_fs->fs_func->set_entry_flag(ep, fid->flags);
1857
1858 if (p_fs->fs_func->get_entry_clu0(ep) != fid->start_clu)
1859 p_fs->fs_func->set_entry_clu0(ep,
1860 fid->start_clu);
1861
1862 if (p_fs->vol_type != EXFAT)
1863 buf_modify(sb, sector);
1864 }
1865
1866 if (p_fs->vol_type == EXFAT) {
1867 update_dir_checksum_with_entry_set(sb, es);
1868 release_entry_set(es);
1869 }
1870
1871 /* add number of new blocks to inode */
1872 inode->i_blocks += num_alloced << (p_fs->cluster_size_bits - 9);
1873 }
1874
1875 /* hint information */
1876 fid->hint_last_off = (s32)(fid->rwoffset >> p_fs->cluster_size_bits);
1877 fid->hint_last_clu = *clu;
1878
1879 if (p_fs->dev_ejected)
1880 ret = FFS_MEDIAERR;
1881
1882out:
1883 /* release the lock for file system critical section */
1884 up(&p_fs->v_sem);
1885
1886 return ret;
1887}
1888
1889/*----------------------------------------------------------------------*/
1890/* Directory Operation Functions */
1891/*----------------------------------------------------------------------*/
1892
1893static int ffsCreateDir(struct inode *inode, char *path, struct file_id_t *fid)
1894{
1895 int ret = FFS_SUCCESS;
1896 struct chain_t dir;
1897 struct uni_name_t uni_name;
1898 struct super_block *sb = inode->i_sb;
1899 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1900
1901 pr_debug("%s entered\n", __func__);
1902
1903 /* check the validity of pointer parameters */
1904 if (!fid || !path || (*path == '\0'))
1905 return FFS_ERROR;
1906
1907 /* acquire the lock for file system critical section */
1908 down(&p_fs->v_sem);
1909
1910 /* check the validity of directory name in the given old pathname */
1911 ret = resolve_path(inode, path, &dir, &uni_name);
1912 if (ret)
1913 goto out;
1914
1915 fs_set_vol_flags(sb, VOL_DIRTY);
1916
1917 ret = create_dir(inode, &dir, &uni_name, fid);
1918
1919#ifdef CONFIG_EXFAT_DELAYED_SYNC
1920 fs_sync(sb, false);
1921 fs_set_vol_flags(sb, VOL_CLEAN);
1922#endif
1923
1924 if (p_fs->dev_ejected)
1925 ret = FFS_MEDIAERR;
1926out:
1927 /* release the lock for file system critical section */
1928 up(&p_fs->v_sem);
1929
1930 return ret;
1931}
1932
1933static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry)
1934{
1935 int i, dentry, clu_offset;
1936 int ret = FFS_SUCCESS;
1937 s32 dentries_per_clu, dentries_per_clu_bits = 0;
1938 u32 type;
1939 sector_t sector;
1940 struct chain_t dir, clu;
1941 struct uni_name_t uni_name;
1942 struct timestamp_t tm;
1943 struct dentry_t *ep;
1944 struct super_block *sb = inode->i_sb;
1945 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
1946 struct fs_func *fs_func = p_fs->fs_func;
1947 struct file_id_t *fid = &(EXFAT_I(inode)->fid);
1948
1949 /* check the validity of pointer parameters */
1950 if (!dir_entry)
1951 return FFS_ERROR;
1952
1953 /* check if the given file ID is opened */
1954 if (fid->type != TYPE_DIR)
1955 return FFS_PERMISSIONERR;
1956
1957 /* acquire the lock for file system critical section */
1958 down(&p_fs->v_sem);
1959
1960 if (fid->entry == -1) {
1961 dir.dir = p_fs->root_dir;
1962 dir.flags = 0x01;
1963 } else {
1964 dir.dir = fid->start_clu;
1965 dir.size = (s32)(fid->size >> p_fs->cluster_size_bits);
1966 dir.flags = fid->flags;
1967 }
1968
1969 dentry = (s32)fid->rwoffset;
1970
1971 if (dir.dir == CLUSTER_32(0)) {
1972 /* FAT16 root_dir */
1973 dentries_per_clu = p_fs->dentries_in_root;
1974
1975 if (dentry == dentries_per_clu) {
1976 clu.dir = CLUSTER_32(~0);
1977 } else {
1978 clu.dir = dir.dir;
1979 clu.size = dir.size;
1980 clu.flags = dir.flags;
1981 }
1982 } else {
1983 dentries_per_clu = p_fs->dentries_per_clu;
1984 dentries_per_clu_bits = ilog2(dentries_per_clu);
1985
1986 clu_offset = dentry >> dentries_per_clu_bits;
1987 clu.dir = dir.dir;
1988 clu.size = dir.size;
1989 clu.flags = dir.flags;
1990
1991 if (clu.flags == 0x03) {
1992 clu.dir += clu_offset;
1993 clu.size -= clu_offset;
1994 } else {
1995 /* hint_information */
1996 if ((clu_offset > 0) && (fid->hint_last_off > 0) &&
1997 (clu_offset >= fid->hint_last_off)) {
1998 clu_offset -= fid->hint_last_off;
1999 clu.dir = fid->hint_last_clu;
2000 }
2001
2002 while (clu_offset > 0) {
2003 /* clu.dir = FAT_read(sb, clu.dir); */
2004 if (FAT_read(sb, clu.dir, &clu.dir) == -1) {
2005 ret = FFS_MEDIAERR;
2006 goto out;
2007 }
2008 clu_offset--;
2009 }
2010 }
2011 }
2012
2013 while (clu.dir != CLUSTER_32(~0)) {
2014 if (p_fs->dev_ejected)
2015 break;
2016
2017 if (dir.dir == CLUSTER_32(0)) /* FAT16 root_dir */
2018 i = dentry % dentries_per_clu;
2019 else
2020 i = dentry & (dentries_per_clu - 1);
2021
2022 for ( ; i < dentries_per_clu; i++, dentry++) {
2023 ep = get_entry_in_dir(sb, &clu, i, &sector);
2024 if (!ep) {
2025 ret = FFS_MEDIAERR;
2026 goto out;
2027 }
2028 type = fs_func->get_entry_type(ep);
2029
2030 if (type == TYPE_UNUSED)
2031 break;
2032
2033 if ((type != TYPE_FILE) && (type != TYPE_DIR))
2034 continue;
2035
2036 buf_lock(sb, sector);
2037 dir_entry->Attr = fs_func->get_entry_attr(ep);
2038
2039 fs_func->get_entry_time(ep, &tm, TM_CREATE);
2040 dir_entry->CreateTimestamp.Year = tm.year;
2041 dir_entry->CreateTimestamp.Month = tm.mon;
2042 dir_entry->CreateTimestamp.Day = tm.day;
2043 dir_entry->CreateTimestamp.Hour = tm.hour;
2044 dir_entry->CreateTimestamp.Minute = tm.min;
2045 dir_entry->CreateTimestamp.Second = tm.sec;
2046 dir_entry->CreateTimestamp.MilliSecond = 0;
2047
2048 fs_func->get_entry_time(ep, &tm, TM_MODIFY);
2049 dir_entry->ModifyTimestamp.Year = tm.year;
2050 dir_entry->ModifyTimestamp.Month = tm.mon;
2051 dir_entry->ModifyTimestamp.Day = tm.day;
2052 dir_entry->ModifyTimestamp.Hour = tm.hour;
2053 dir_entry->ModifyTimestamp.Minute = tm.min;
2054 dir_entry->ModifyTimestamp.Second = tm.sec;
2055 dir_entry->ModifyTimestamp.MilliSecond = 0;
2056
2057 memset((char *)&dir_entry->AccessTimestamp, 0,
2058 sizeof(struct date_time_t));
2059
2060 *(uni_name.name) = 0x0;
2061 fs_func->get_uni_name_from_ext_entry(sb, &dir, dentry,
2062 uni_name.name);
2063 if (*uni_name.name == 0x0 && p_fs->vol_type != EXFAT)
2064 get_uni_name_from_dos_entry(sb,
2065 (struct dos_dentry_t *)ep,
2066 &uni_name, 0x1);
2067 nls_uniname_to_cstring(sb, dir_entry->Name, &uni_name);
2068 buf_unlock(sb, sector);
2069
2070 if (p_fs->vol_type == EXFAT) {
2071 ep = get_entry_in_dir(sb, &clu, i + 1, NULL);
2072 if (!ep) {
2073 ret = FFS_MEDIAERR;
2074 goto out;
2075 }
2076 } else {
2077 get_uni_name_from_dos_entry(sb,
2078 (struct dos_dentry_t *)ep,
2079 &uni_name, 0x0);
2080 nls_uniname_to_cstring(sb, dir_entry->ShortName,
2081 &uni_name);
2082 }
2083
2084 dir_entry->Size = fs_func->get_entry_size(ep);
2085
2086 /* hint information */
2087 if (dir.dir == CLUSTER_32(0)) { /* FAT16 root_dir */
2088 } else {
2089 fid->hint_last_off = dentry >>
2090 dentries_per_clu_bits;
2091 fid->hint_last_clu = clu.dir;
2092 }
2093
2094 fid->rwoffset = (s64)(++dentry);
2095
2096 if (p_fs->dev_ejected)
2097 ret = FFS_MEDIAERR;
2098 goto out;
2099 }
2100
2101 if (dir.dir == CLUSTER_32(0))
2102 break; /* FAT16 root_dir */
2103
2104 if (clu.flags == 0x03) {
2105 if ((--clu.size) > 0)
2106 clu.dir++;
2107 else
2108 clu.dir = CLUSTER_32(~0);
2109 } else {
2110 /* clu.dir = FAT_read(sb, clu.dir); */
2111 if (FAT_read(sb, clu.dir, &clu.dir) == -1) {
2112 ret = FFS_MEDIAERR;
2113 goto out;
2114 }
2115 }
2116 }
2117
2118 *(dir_entry->Name) = '\0';
2119
2120 fid->rwoffset = (s64)(++dentry);
2121
2122 if (p_fs->dev_ejected)
2123 ret = FFS_MEDIAERR;
2124
2125out:
2126 /* release the lock for file system critical section */
2127 up(&p_fs->v_sem);
2128
2129 return ret;
2130}
2131
2132static int ffsRemoveDir(struct inode *inode, struct file_id_t *fid)
2133{
2134 s32 dentry;
2135 int ret = FFS_SUCCESS;
2136 struct chain_t dir, clu_to_free;
2137 struct super_block *sb = inode->i_sb;
2138 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
2139
2140 /* check the validity of the given file id */
2141 if (!fid)
2142 return FFS_INVALIDFID;
2143
2144 dir.dir = fid->dir.dir;
2145 dir.size = fid->dir.size;
2146 dir.flags = fid->dir.flags;
2147
2148 dentry = fid->entry;
2149
2150 /* check if the file is "." or ".." */
2151 if (p_fs->vol_type != EXFAT) {
2152 if ((dir.dir != p_fs->root_dir) && (dentry < 2))
2153 return FFS_PERMISSIONERR;
2154 }
2155
2156 /* acquire the lock for file system critical section */
2157 down(&p_fs->v_sem);
2158
2159 clu_to_free.dir = fid->start_clu;
2160 clu_to_free.size = (s32)((fid->size - 1) >> p_fs->cluster_size_bits) + 1;
2161 clu_to_free.flags = fid->flags;
2162
2163 if (!is_dir_empty(sb, &clu_to_free)) {
2164 ret = FFS_FILEEXIST;
2165 goto out;
2166 }
2167
2168 fs_set_vol_flags(sb, VOL_DIRTY);
2169
2170 /* (1) update the directory entry */
2171 remove_file(inode, &dir, dentry);
2172
2173 /* (2) free the clusters */
2174 p_fs->fs_func->free_cluster(sb, &clu_to_free, 1);
2175
2176 fid->size = 0;
2177 fid->start_clu = CLUSTER_32(~0);
2178 fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01;
2179
2180#ifdef CONFIG_EXFAT_DELAYED_SYNC
2181 fs_sync(sb, false);
2182 fs_set_vol_flags(sb, VOL_CLEAN);
2183#endif
2184
2185 if (p_fs->dev_ejected)
2186 ret = FFS_MEDIAERR;
2187
2188out:
2189 /* release the lock for file system critical section */
2190 up(&p_fs->v_sem);
2191
2192 return ret;
2193}
2194
2195/*======================================================================*/
2196/* Directory Entry Operations */
2197/*======================================================================*/
2198
2199static int exfat_readdir(struct file *filp, struct dir_context *ctx)
2200{
2201 struct inode *inode = file_inode(filp);
2202 struct super_block *sb = inode->i_sb;
2203 struct exfat_sb_info *sbi = EXFAT_SB(sb);
2204 struct fs_info_t *p_fs = &(sbi->fs_info);
2205 struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info);
2206 struct dir_entry_t de;
2207 unsigned long inum;
2208 loff_t cpos;
2209 int err = 0;
2210
2211 __lock_super(sb);
2212
2213 cpos = ctx->pos;
2214 /* Fake . and .. for the root directory. */
2215 if ((p_fs->vol_type == EXFAT) || (inode->i_ino == EXFAT_ROOT_INO)) {
2216 while (cpos < 2) {
2217 if (inode->i_ino == EXFAT_ROOT_INO)
2218 inum = EXFAT_ROOT_INO;
2219 else if (cpos == 0)
2220 inum = inode->i_ino;
2221 else /* (cpos == 1) */
2222 inum = parent_ino(filp->f_path.dentry);
2223
2224 if (!dir_emit_dots(filp, ctx))
2225 goto out;
2226 cpos++;
2227 ctx->pos++;
2228 }
2229 if (cpos == 2)
2230 cpos = 0;
2231 }
2232 if (cpos & (DENTRY_SIZE - 1)) {
2233 err = -ENOENT;
2234 goto out;
2235 }
2236
2237get_new:
2238 EXFAT_I(inode)->fid.size = i_size_read(inode);
2239 EXFAT_I(inode)->fid.rwoffset = cpos >> DENTRY_SIZE_BITS;
2240
2241 err = ffsReadDir(inode, &de);
2242 if (err) {
2243 /* at least we tried to read a sector
2244 * move cpos to next sector position (should be aligned)
2245 */
2246 if (err == FFS_MEDIAERR) {
2247 cpos += 1 << p_bd->sector_size_bits;
2248 cpos &= ~((1 << p_bd->sector_size_bits) - 1);
2249 }
2250
2251 err = -EIO;
2252 goto end_of_dir;
2253 }
2254
2255 cpos = EXFAT_I(inode)->fid.rwoffset << DENTRY_SIZE_BITS;
2256
2257 if (!de.Name[0])
2258 goto end_of_dir;
2259
2260 if (!memcmp(de.ShortName, DOS_CUR_DIR_NAME, DOS_NAME_LENGTH)) {
2261 inum = inode->i_ino;
2262 } else if (!memcmp(de.ShortName, DOS_PAR_DIR_NAME, DOS_NAME_LENGTH)) {
2263 inum = parent_ino(filp->f_path.dentry);
2264 } else {
2265 loff_t i_pos = ((loff_t)EXFAT_I(inode)->fid.start_clu << 32) |
2266 ((EXFAT_I(inode)->fid.rwoffset - 1) & 0xffffffff);
2267 struct inode *tmp = exfat_iget(sb, i_pos);
2268
2269 if (tmp) {
2270 inum = tmp->i_ino;
2271 iput(tmp);
2272 } else {
2273 inum = iunique(sb, EXFAT_ROOT_INO);
2274 }
2275 }
2276
2277 if (!dir_emit(ctx, de.Name, strlen(de.Name), inum,
2278 (de.Attr & ATTR_SUBDIR) ? DT_DIR : DT_REG))
2279 goto out;
2280
2281 ctx->pos = cpos;
2282 goto get_new;
2283
2284end_of_dir:
2285 ctx->pos = cpos;
2286out:
2287 __unlock_super(sb);
2288 return err;
2289}
2290
2291static int exfat_ioctl_volume_id(struct inode *dir)
2292{
2293 struct super_block *sb = dir->i_sb;
2294 struct exfat_sb_info *sbi = EXFAT_SB(sb);
2295 struct fs_info_t *p_fs = &(sbi->fs_info);
2296
2297 return p_fs->vol_id;
2298}
2299
2300static long exfat_generic_ioctl(struct file *filp, unsigned int cmd,
2301 unsigned long arg)
2302{
2303struct inode *inode = filp->f_path.dentry->d_inode;
2304#ifdef CONFIG_EXFAT_KERNEL_DEBUG
2305 unsigned int flags;
2306#endif /* CONFIG_EXFAT_KERNEL_DEBUG */
2307
2308 switch (cmd) {
2309 case EXFAT_IOCTL_GET_VOLUME_ID:
2310 return exfat_ioctl_volume_id(inode);
2311#ifdef CONFIG_EXFAT_KERNEL_DEBUG
2312 case EXFAT_IOC_GET_DEBUGFLAGS: {
2313 struct super_block *sb = inode->i_sb;
2314 struct exfat_sb_info *sbi = EXFAT_SB(sb);
2315
2316 flags = sbi->debug_flags;
2317 return put_user(flags, (int __user *)arg);
2318 }
2319 case EXFAT_IOC_SET_DEBUGFLAGS: {
2320 struct super_block *sb = inode->i_sb;
2321 struct exfat_sb_info *sbi = EXFAT_SB(sb);
2322
2323 if (!capable(CAP_SYS_ADMIN))
2324 return -EPERM;
2325
2326 if (get_user(flags, (int __user *)arg))
2327 return -EFAULT;
2328
2329 __lock_super(sb);
2330 sbi->debug_flags = flags;
2331 __unlock_super(sb);
2332
2333 return 0;
2334 }
2335#endif /* CONFIG_EXFAT_KERNEL_DEBUG */
2336 default:
2337 return -ENOTTY; /* Inappropriate ioctl for device */
2338 }
2339}
2340
2341static const struct file_operations exfat_dir_operations = {
2342 .llseek = generic_file_llseek,
2343 .read = generic_read_dir,
2344 .iterate = exfat_readdir,
2345 .unlocked_ioctl = exfat_generic_ioctl,
2346 .fsync = generic_file_fsync,
2347};
2348
2349static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
2350 bool excl)
2351{
2352 struct super_block *sb = dir->i_sb;
2353 struct inode *inode;
2354 struct file_id_t fid;
2355 loff_t i_pos;
2356 int err;
2357
2358 __lock_super(sb);
2359
2360 pr_debug("%s entered\n", __func__);
2361
2362 err = ffsCreateFile(dir, (u8 *)dentry->d_name.name, FM_REGULAR, &fid);
2363 if (err) {
2364 if (err == FFS_INVALIDPATH)
2365 err = -EINVAL;
2366 else if (err == FFS_FILEEXIST)
2367 err = -EEXIST;
2368 else if (err == FFS_FULL)
2369 err = -ENOSPC;
2370 else if (err == FFS_NAMETOOLONG)
2371 err = -ENAMETOOLONG;
2372 else
2373 err = -EIO;
2374 goto out;
2375 }
2376 INC_IVERSION(dir);
2377 dir->i_ctime = dir->i_mtime = dir->i_atime = current_time(dir);
2378 if (IS_DIRSYNC(dir))
2379 (void)exfat_sync_inode(dir);
2380 else
2381 mark_inode_dirty(dir);
2382
2383 i_pos = ((loff_t)fid.dir.dir << 32) | (fid.entry & 0xffffffff);
2384
2385 inode = exfat_build_inode(sb, &fid, i_pos);
2386 if (IS_ERR(inode)) {
2387 err = PTR_ERR(inode);
2388 goto out;
2389 }
2390 INC_IVERSION(inode);
2391 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
2392 /*
2393 * timestamp is already written, so mark_inode_dirty() is unnecessary.
2394 */
2395
2396 dentry->d_time = GET_IVERSION(dentry->d_parent->d_inode);
2397 d_instantiate(dentry, inode);
2398
2399out:
2400 __unlock_super(sb);
2401 pr_debug("%s exited\n", __func__);
2402 return err;
2403}
2404
2405static int exfat_find(struct inode *dir, struct qstr *qname,
2406 struct file_id_t *fid)
2407{
2408 int err;
2409
2410 if (qname->len == 0)
2411 return -ENOENT;
2412
2413 err = ffsLookupFile(dir, (u8 *)qname->name, fid);
2414 if (err)
2415 return -ENOENT;
2416
2417 return 0;
2418}
2419
2420static int exfat_d_anon_disconn(struct dentry *dentry)
2421{
2422 return IS_ROOT(dentry) && (dentry->d_flags & DCACHE_DISCONNECTED);
2423}
2424
2425static struct dentry *exfat_lookup(struct inode *dir, struct dentry *dentry,
2426 unsigned int flags)
2427{
2428 struct super_block *sb = dir->i_sb;
2429 struct inode *inode;
2430 struct dentry *alias;
2431 int err;
2432 struct file_id_t fid;
2433 loff_t i_pos;
2434 u64 ret;
2435 mode_t i_mode;
2436
2437 __lock_super(sb);
2438 pr_debug("%s entered\n", __func__);
2439 err = exfat_find(dir, &dentry->d_name, &fid);
2440 if (err) {
2441 if (err == -ENOENT) {
2442 inode = NULL;
2443 goto out;
2444 }
2445 goto error;
2446 }
2447
2448 i_pos = ((loff_t)fid.dir.dir << 32) | (fid.entry & 0xffffffff);
2449 inode = exfat_build_inode(sb, &fid, i_pos);
2450 if (IS_ERR(inode)) {
2451 err = PTR_ERR(inode);
2452 goto error;
2453 }
2454
2455 i_mode = inode->i_mode;
2456 if (S_ISLNK(i_mode) && !EXFAT_I(inode)->target) {
2457 EXFAT_I(inode)->target = kmalloc(i_size_read(inode) + 1,
2458 GFP_KERNEL);
2459 if (!EXFAT_I(inode)->target) {
2460 err = -ENOMEM;
2461 goto error;
2462 }
2463 ffsReadFile(dir, &fid, EXFAT_I(inode)->target,
2464 i_size_read(inode), &ret);
2465 *(EXFAT_I(inode)->target + i_size_read(inode)) = '\0';
2466 }
2467
2468 alias = d_find_alias(inode);
2469 if (alias && !exfat_d_anon_disconn(alias)) {
2470 BUG_ON(d_unhashed(alias));
2471 if (!S_ISDIR(i_mode))
2472 d_move(alias, dentry);
2473 iput(inode);
2474 __unlock_super(sb);
2475 pr_debug("%s exited 1\n", __func__);
2476 return alias;
2477 }
2478 dput(alias);
2479out:
2480 __unlock_super(sb);
2481 dentry->d_time = GET_IVERSION(dentry->d_parent->d_inode);
2482 dentry = d_splice_alias(inode, dentry);
2483 if (dentry)
2484 dentry->d_time = GET_IVERSION(dentry->d_parent->d_inode);
2485 pr_debug("%s exited 2\n", __func__);
2486 return dentry;
2487
2488error:
2489 __unlock_super(sb);
2490 pr_debug("%s exited 3\n", __func__);
2491 return ERR_PTR(err);
2492}
2493
2494static inline unsigned long exfat_hash(loff_t i_pos)
2495{
2496 return hash_32(i_pos, EXFAT_HASH_BITS);
2497}
2498
2499static void exfat_attach(struct inode *inode, loff_t i_pos)
2500{
2501 struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb);
2502 struct hlist_head *head = sbi->inode_hashtable + exfat_hash(i_pos);
2503
2504 spin_lock(&sbi->inode_hash_lock);
2505 EXFAT_I(inode)->i_pos = i_pos;
2506 hlist_add_head(&EXFAT_I(inode)->i_hash_fat, head);
2507 spin_unlock(&sbi->inode_hash_lock);
2508}
2509
2510static void exfat_detach(struct inode *inode)
2511{
2512 struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb);
2513
2514 spin_lock(&sbi->inode_hash_lock);
2515 hlist_del_init(&EXFAT_I(inode)->i_hash_fat);
2516 EXFAT_I(inode)->i_pos = 0;
2517 spin_unlock(&sbi->inode_hash_lock);
2518}
2519
2520static int exfat_unlink(struct inode *dir, struct dentry *dentry)
2521{
2522 struct inode *inode = dentry->d_inode;
2523 struct super_block *sb = dir->i_sb;
2524 int err;
2525
2526 __lock_super(sb);
2527
2528 pr_debug("%s entered\n", __func__);
2529
2530 EXFAT_I(inode)->fid.size = i_size_read(inode);
2531
2532 err = ffsRemoveFile(dir, &(EXFAT_I(inode)->fid));
2533 if (err) {
2534 if (err == FFS_PERMISSIONERR)
2535 err = -EPERM;
2536 else
2537 err = -EIO;
2538 goto out;
2539 }
2540 INC_IVERSION(dir);
2541 dir->i_mtime = dir->i_atime = current_time(dir);
2542 if (IS_DIRSYNC(dir))
2543 (void)exfat_sync_inode(dir);
2544 else
2545 mark_inode_dirty(dir);
2546
2547 clear_nlink(inode);
2548 inode->i_mtime = inode->i_atime = current_time(inode);
2549 exfat_detach(inode);
2550 remove_inode_hash(inode);
2551
2552out:
2553 __unlock_super(sb);
2554 pr_debug("%s exited\n", __func__);
2555 return err;
2556}
2557
2558static int exfat_symlink(struct inode *dir, struct dentry *dentry,
2559 const char *target)
2560{
2561 struct super_block *sb = dir->i_sb;
2562 struct inode *inode;
2563 struct file_id_t fid;
2564 loff_t i_pos;
2565 int err;
2566 u64 len = (u64)strlen(target);
2567 u64 ret;
2568
2569 __lock_super(sb);
2570
2571 pr_debug("%s entered\n", __func__);
2572
2573 err = ffsCreateFile(dir, (u8 *)dentry->d_name.name, FM_SYMLINK, &fid);
2574 if (err) {
2575 if (err == FFS_INVALIDPATH)
2576 err = -EINVAL;
2577 else if (err == FFS_FILEEXIST)
2578 err = -EEXIST;
2579 else if (err == FFS_FULL)
2580 err = -ENOSPC;
2581 else
2582 err = -EIO;
2583 goto out;
2584 }
2585
2586 err = ffsWriteFile(dir, &fid, (char *)target, len, &ret);
2587
2588 if (err) {
2589 ffsRemoveFile(dir, &fid);
2590
2591 if (err == FFS_FULL)
2592 err = -ENOSPC;
2593 else
2594 err = -EIO;
2595 goto out;
2596 }
2597
2598 INC_IVERSION(dir);
2599 dir->i_ctime = dir->i_mtime = dir->i_atime = current_time(dir);
2600 if (IS_DIRSYNC(dir))
2601 (void)exfat_sync_inode(dir);
2602 else
2603 mark_inode_dirty(dir);
2604
2605 i_pos = ((loff_t)fid.dir.dir << 32) | (fid.entry & 0xffffffff);
2606
2607 inode = exfat_build_inode(sb, &fid, i_pos);
2608 if (IS_ERR(inode)) {
2609 err = PTR_ERR(inode);
2610 goto out;
2611 }
2612 INC_IVERSION(inode);
2613 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
2614 /* timestamp is already written, so mark_inode_dirty() is unneeded. */
2615
2616 EXFAT_I(inode)->target = kmemdup(target, len + 1, GFP_KERNEL);
2617 if (!EXFAT_I(inode)->target) {
2618 err = -ENOMEM;
2619 goto out;
2620 }
2621
2622 dentry->d_time = GET_IVERSION(dentry->d_parent->d_inode);
2623 d_instantiate(dentry, inode);
2624
2625out:
2626 __unlock_super(sb);
2627 pr_debug("%s exited\n", __func__);
2628 return err;
2629}
2630
2631static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
2632{
2633 struct super_block *sb = dir->i_sb;
2634 struct inode *inode;
2635 struct file_id_t fid;
2636 loff_t i_pos;
2637 int err;
2638
2639 __lock_super(sb);
2640
2641 pr_debug("%s entered\n", __func__);
2642
2643 err = ffsCreateDir(dir, (u8 *)dentry->d_name.name, &fid);
2644 if (err) {
2645 if (err == FFS_INVALIDPATH)
2646 err = -EINVAL;
2647 else if (err == FFS_FILEEXIST)
2648 err = -EEXIST;
2649 else if (err == FFS_FULL)
2650 err = -ENOSPC;
2651 else if (err == FFS_NAMETOOLONG)
2652 err = -ENAMETOOLONG;
2653 else
2654 err = -EIO;
2655 goto out;
2656 }
2657 INC_IVERSION(dir);
2658 dir->i_ctime = dir->i_mtime = dir->i_atime = current_time(dir);
2659 if (IS_DIRSYNC(dir))
2660 (void)exfat_sync_inode(dir);
2661 else
2662 mark_inode_dirty(dir);
2663 inc_nlink(dir);
2664
2665 i_pos = ((loff_t)fid.dir.dir << 32) | (fid.entry & 0xffffffff);
2666
2667 inode = exfat_build_inode(sb, &fid, i_pos);
2668 if (IS_ERR(inode)) {
2669 err = PTR_ERR(inode);
2670 goto out;
2671 }
2672 INC_IVERSION(inode);
2673 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
2674 /* timestamp is already written, so mark_inode_dirty() is unneeded. */
2675
2676 dentry->d_time = GET_IVERSION(dentry->d_parent->d_inode);
2677 d_instantiate(dentry, inode);
2678
2679out:
2680 __unlock_super(sb);
2681 pr_debug("%s exited\n", __func__);
2682 return err;
2683}
2684
2685static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
2686{
2687 struct inode *inode = dentry->d_inode;
2688 struct super_block *sb = dir->i_sb;
2689 int err;
2690
2691 __lock_super(sb);
2692
2693 pr_debug("%s entered\n", __func__);
2694
2695 EXFAT_I(inode)->fid.size = i_size_read(inode);
2696
2697 err = ffsRemoveDir(dir, &(EXFAT_I(inode)->fid));
2698 if (err) {
2699 if (err == FFS_INVALIDPATH)
2700 err = -EINVAL;
2701 else if (err == FFS_FILEEXIST)
2702 err = -ENOTEMPTY;
2703 else if (err == FFS_NOTFOUND)
2704 err = -ENOENT;
2705 else if (err == FFS_DIRBUSY)
2706 err = -EBUSY;
2707 else
2708 err = -EIO;
2709 goto out;
2710 }
2711 INC_IVERSION(dir);
2712 dir->i_mtime = dir->i_atime = current_time(dir);
2713 if (IS_DIRSYNC(dir))
2714 (void)exfat_sync_inode(dir);
2715 else
2716 mark_inode_dirty(dir);
2717 drop_nlink(dir);
2718
2719 clear_nlink(inode);
2720 inode->i_mtime = inode->i_atime = current_time(inode);
2721 exfat_detach(inode);
2722 remove_inode_hash(inode);
2723
2724out:
2725 __unlock_super(sb);
2726 pr_debug("%s exited\n", __func__);
2727 return err;
2728}
2729
2730static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
2731 struct inode *new_dir, struct dentry *new_dentry,
2732 unsigned int flags)
2733{
2734 struct inode *old_inode, *new_inode;
2735 struct super_block *sb = old_dir->i_sb;
2736 loff_t i_pos;
2737 int err;
2738
2739 if (flags)
2740 return -EINVAL;
2741
2742 __lock_super(sb);
2743
2744 pr_debug("%s entered\n", __func__);
2745
2746 old_inode = old_dentry->d_inode;
2747 new_inode = new_dentry->d_inode;
2748
2749 EXFAT_I(old_inode)->fid.size = i_size_read(old_inode);
2750
2751 err = ffsMoveFile(old_dir, &(EXFAT_I(old_inode)->fid), new_dir,
2752 new_dentry);
2753 if (err) {
2754 if (err == FFS_PERMISSIONERR)
2755 err = -EPERM;
2756 else if (err == FFS_INVALIDPATH)
2757 err = -EINVAL;
2758 else if (err == FFS_FILEEXIST)
2759 err = -EEXIST;
2760 else if (err == FFS_NOTFOUND)
2761 err = -ENOENT;
2762 else if (err == FFS_FULL)
2763 err = -ENOSPC;
2764 else
2765 err = -EIO;
2766 goto out;
2767 }
2768 INC_IVERSION(new_dir);
2769 new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime =
2770 current_time(new_dir);
2771 if (IS_DIRSYNC(new_dir))
2772 (void)exfat_sync_inode(new_dir);
2773 else
2774 mark_inode_dirty(new_dir);
2775
2776 i_pos = ((loff_t)EXFAT_I(old_inode)->fid.dir.dir << 32) |
2777 (EXFAT_I(old_inode)->fid.entry & 0xffffffff);
2778
2779 exfat_detach(old_inode);
2780 exfat_attach(old_inode, i_pos);
2781 if (IS_DIRSYNC(new_dir))
2782 (void)exfat_sync_inode(old_inode);
2783 else
2784 mark_inode_dirty(old_inode);
2785
2786 if ((S_ISDIR(old_inode->i_mode)) && (old_dir != new_dir)) {
2787 drop_nlink(old_dir);
2788 if (!new_inode)
2789 inc_nlink(new_dir);
2790 }
2791 INC_IVERSION(old_dir);
2792 old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir);
2793 if (IS_DIRSYNC(old_dir))
2794 (void)exfat_sync_inode(old_dir);
2795 else
2796 mark_inode_dirty(old_dir);
2797
2798 if (new_inode) {
2799 exfat_detach(new_inode);
2800 drop_nlink(new_inode);
2801 if (S_ISDIR(new_inode->i_mode))
2802 drop_nlink(new_inode);
2803 new_inode->i_ctime = current_time(new_inode);
2804 }
2805
2806out:
2807 __unlock_super(sb);
2808 pr_debug("%s exited\n", __func__);
2809 return err;
2810}
2811
2812static int exfat_cont_expand(struct inode *inode, loff_t size)
2813{
2814 struct address_space *mapping = inode->i_mapping;
2815 loff_t start = i_size_read(inode), count = size - i_size_read(inode);
2816 int err, err2;
2817
2818 err = generic_cont_expand_simple(inode, size);
2819 if (err != 0)
2820 return err;
2821
2822 inode->i_ctime = inode->i_mtime = current_time(inode);
2823 mark_inode_dirty(inode);
2824
2825 if (IS_SYNC(inode)) {
2826 err = filemap_fdatawrite_range(mapping, start,
2827 start + count - 1);
2828 err2 = sync_mapping_buffers(mapping);
2829 err = (err) ? (err) : (err2);
2830 err2 = write_inode_now(inode, 1);
2831 err = (err) ? (err) : (err2);
2832 if (!err)
2833 err = filemap_fdatawait_range(mapping, start,
2834 start + count - 1);
2835 }
2836 return err;
2837}
2838
2839static int exfat_allow_set_time(struct exfat_sb_info *sbi, struct inode *inode)
2840{
2841 mode_t allow_utime = sbi->options.allow_utime;
2842
2843 if (!uid_eq(current_fsuid(), inode->i_uid)) {
2844 if (in_group_p(inode->i_gid))
2845 allow_utime >>= 3;
2846 if (allow_utime & MAY_WRITE)
2847 return 1;
2848 }
2849
2850 /* use a default check */
2851 return 0;
2852}
2853
2854static int exfat_sanitize_mode(const struct exfat_sb_info *sbi,
2855 struct inode *inode, umode_t *mode_ptr)
2856{
2857 mode_t i_mode, mask, perm;
2858
2859 i_mode = inode->i_mode;
2860
2861 if (S_ISREG(i_mode) || S_ISLNK(i_mode))
2862 mask = sbi->options.fs_fmask;
2863 else
2864 mask = sbi->options.fs_dmask;
2865
2866 perm = *mode_ptr & ~(S_IFMT | mask);
2867
2868 /* Of the r and x bits, all (subject to umask) must be present.*/
2869 if ((perm & 0555) != (i_mode & 0555))
2870 return -EPERM;
2871
2872 if (exfat_mode_can_hold_ro(inode)) {
2873 /*
2874 * Of the w bits, either all (subject to umask) or none must be
2875 * present.
2876 */
2877 if ((perm & 0222) && ((perm & 0222) != (0222 & ~mask)))
2878 return -EPERM;
2879 } else {
2880 /*
2881 * If exfat_mode_can_hold_ro(inode) is false, can't change w
2882 * bits.
2883 */
2884 if ((perm & 0222) != (0222 & ~mask))
2885 return -EPERM;
2886 }
2887
2888 *mode_ptr &= S_IFMT | perm;
2889
2890 return 0;
2891}
2892
2893static void exfat_truncate(struct inode *inode, loff_t old_size)
2894{
2895 struct super_block *sb = inode->i_sb;
2896 struct exfat_sb_info *sbi = EXFAT_SB(sb);
2897 struct fs_info_t *p_fs = &(sbi->fs_info);
2898 int err;
2899
2900 __lock_super(sb);
2901
2902 /*
2903 * This protects against truncating a file bigger than it was then
2904 * trying to write into the hole.
2905 */
2906 if (EXFAT_I(inode)->mmu_private > i_size_read(inode))
2907 EXFAT_I(inode)->mmu_private = i_size_read(inode);
2908
2909 if (EXFAT_I(inode)->fid.start_clu == 0)
2910 goto out;
2911
2912 err = ffsTruncateFile(inode, old_size, i_size_read(inode));
2913 if (err)
2914 goto out;
2915
2916 inode->i_ctime = inode->i_mtime = current_time(inode);
2917 if (IS_DIRSYNC(inode))
2918 (void)exfat_sync_inode(inode);
2919 else
2920 mark_inode_dirty(inode);
2921
2922 inode->i_blocks = ((i_size_read(inode) + (p_fs->cluster_size - 1)) &
2923 ~((loff_t)p_fs->cluster_size - 1)) >> 9;
2924out:
2925 __unlock_super(sb);
2926}
2927
2928static int exfat_setattr(struct dentry *dentry, struct iattr *attr)
2929{
2930 struct exfat_sb_info *sbi = EXFAT_SB(dentry->d_sb);
2931 struct inode *inode = dentry->d_inode;
2932 unsigned int ia_valid;
2933 int error;
2934 loff_t old_size;
2935
2936 pr_debug("%s entered\n", __func__);
2937
2938 if ((attr->ia_valid & ATTR_SIZE)
2939 && (attr->ia_size > i_size_read(inode))) {
2940 error = exfat_cont_expand(inode, attr->ia_size);
2941 if (error || attr->ia_valid == ATTR_SIZE)
2942 return error;
2943 attr->ia_valid &= ~ATTR_SIZE;
2944 }
2945
2946 ia_valid = attr->ia_valid;
2947
2948 if ((ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET))
2949 && exfat_allow_set_time(sbi, inode)) {
2950 attr->ia_valid &= ~(ATTR_MTIME_SET |
2951 ATTR_ATIME_SET |
2952 ATTR_TIMES_SET);
2953 }
2954
2955 error = setattr_prepare(dentry, attr);
2956 attr->ia_valid = ia_valid;
2957 if (error)
2958 return error;
2959
2960 if (((attr->ia_valid & ATTR_UID) &&
2961 (!uid_eq(attr->ia_uid, sbi->options.fs_uid))) ||
2962 ((attr->ia_valid & ATTR_GID) &&
2963 (!gid_eq(attr->ia_gid, sbi->options.fs_gid))) ||
2964 ((attr->ia_valid & ATTR_MODE) &&
2965 (attr->ia_mode & ~(S_IFREG | S_IFLNK | S_IFDIR | 0777)))) {
2966 return -EPERM;
2967 }
2968
2969 /*
2970 * We don't return -EPERM here. Yes, strange, but this is too
2971 * old behavior.
2972 */
2973 if (attr->ia_valid & ATTR_MODE) {
2974 if (exfat_sanitize_mode(sbi, inode, &attr->ia_mode) < 0)
2975 attr->ia_valid &= ~ATTR_MODE;
2976 }
2977
2978 EXFAT_I(inode)->fid.size = i_size_read(inode);
2979
2980 if (attr->ia_valid & ATTR_SIZE) {
2981 old_size = i_size_read(inode);
2982 down_write(&EXFAT_I(inode)->truncate_lock);
2983 truncate_setsize(inode, attr->ia_size);
2984 exfat_truncate(inode, old_size);
2985 up_write(&EXFAT_I(inode)->truncate_lock);
2986 }
2987 setattr_copy(inode, attr);
2988 mark_inode_dirty(inode);
2989
2990 pr_debug("%s exited\n", __func__);
2991 return error;
2992}
2993
2994static int exfat_getattr(const struct path *path, struct kstat *stat,
2995 u32 request_mask, unsigned int flags)
2996{
2997 struct inode *inode = path->dentry->d_inode;
2998
2999 pr_debug("%s entered\n", __func__);
3000
3001 generic_fillattr(inode, stat);
3002 stat->blksize = EXFAT_SB(inode->i_sb)->fs_info.cluster_size;
3003
3004 pr_debug("%s exited\n", __func__);
3005 return 0;
3006}
3007
3008static const struct inode_operations exfat_dir_inode_operations = {
3009 .create = exfat_create,
3010 .lookup = exfat_lookup,
3011 .unlink = exfat_unlink,
3012 .symlink = exfat_symlink,
3013 .mkdir = exfat_mkdir,
3014 .rmdir = exfat_rmdir,
3015 .rename = exfat_rename,
3016 .setattr = exfat_setattr,
3017 .getattr = exfat_getattr,
3018};
3019
3020/*======================================================================*/
3021/* File Operations */
3022/*======================================================================*/
3023static const char *exfat_get_link(struct dentry *dentry, struct inode *inode,
3024 struct delayed_call *done)
3025{
3026 struct exfat_inode_info *ei = EXFAT_I(inode);
3027
3028 if (ei->target) {
3029 char *cookie = ei->target;
3030
3031 if (cookie)
3032 return (char *)(ei->target);
3033 }
3034 return NULL;
3035}
3036
3037static const struct inode_operations exfat_symlink_inode_operations = {
3038 .get_link = exfat_get_link,
3039};
3040
3041static int exfat_file_release(struct inode *inode, struct file *filp)
3042{
3043 struct super_block *sb = inode->i_sb;
3044
3045 EXFAT_I(inode)->fid.size = i_size_read(inode);
3046 ffsSyncVol(sb, false);
3047 return 0;
3048}
3049
3050static const struct file_operations exfat_file_operations = {
3051 .llseek = generic_file_llseek,
3052 .read_iter = generic_file_read_iter,
3053 .write_iter = generic_file_write_iter,
3054 .mmap = generic_file_mmap,
3055 .release = exfat_file_release,
3056 .unlocked_ioctl = exfat_generic_ioctl,
3057 .fsync = generic_file_fsync,
3058 .splice_read = generic_file_splice_read,
3059};
3060
3061static const struct inode_operations exfat_file_inode_operations = {
3062 .setattr = exfat_setattr,
3063 .getattr = exfat_getattr,
3064};
3065
3066/*======================================================================*/
3067/* Address Space Operations */
3068/*======================================================================*/
3069
3070static int exfat_bmap(struct inode *inode, sector_t sector, sector_t *phys,
3071 unsigned long *mapped_blocks, int *create)
3072{
3073 struct super_block *sb = inode->i_sb;
3074 struct exfat_sb_info *sbi = EXFAT_SB(sb);
3075 struct fs_info_t *p_fs = &(sbi->fs_info);
3076 struct bd_info_t *p_bd = &(sbi->bd_info);
3077 const unsigned long blocksize = sb->s_blocksize;
3078 const unsigned char blocksize_bits = sb->s_blocksize_bits;
3079 sector_t last_block;
3080 int err, clu_offset, sec_offset;
3081 unsigned int cluster;
3082
3083 *phys = 0;
3084 *mapped_blocks = 0;
3085
3086 if ((p_fs->vol_type == FAT12) || (p_fs->vol_type == FAT16)) {
3087 if (inode->i_ino == EXFAT_ROOT_INO) {
3088 if (sector <
3089 (p_fs->dentries_in_root >>
3090 (p_bd->sector_size_bits - DENTRY_SIZE_BITS))) {
3091 *phys = sector + p_fs->root_start_sector;
3092 *mapped_blocks = 1;
3093 }
3094 return 0;
3095 }
3096 }
3097
3098 last_block = (i_size_read(inode) + (blocksize - 1)) >> blocksize_bits;
3099 if (sector >= last_block) {
3100 if (*create == 0)
3101 return 0;
3102 } else {
3103 *create = 0;
3104 }
3105
3106 /* cluster offset */
3107 clu_offset = sector >> p_fs->sectors_per_clu_bits;
3108
3109 /* sector offset in cluster */
3110 sec_offset = sector & (p_fs->sectors_per_clu - 1);
3111
3112 EXFAT_I(inode)->fid.size = i_size_read(inode);
3113
3114 err = ffsMapCluster(inode, clu_offset, &cluster);
3115
3116 if (err) {
3117 if (err == FFS_FULL)
3118 return -ENOSPC;
3119 else
3120 return -EIO;
3121 } else if (cluster != CLUSTER_32(~0)) {
3122 *phys = START_SECTOR(cluster) + sec_offset;
3123 *mapped_blocks = p_fs->sectors_per_clu - sec_offset;
3124 }
3125
3126 return 0;
3127}
3128
3129static int exfat_get_block(struct inode *inode, sector_t iblock,
3130 struct buffer_head *bh_result, int create)
3131{
3132 struct super_block *sb = inode->i_sb;
3133 unsigned long max_blocks = bh_result->b_size >> inode->i_blkbits;
3134 int err;
3135 unsigned long mapped_blocks;
3136 sector_t phys;
3137
3138 __lock_super(sb);
3139
3140 err = exfat_bmap(inode, iblock, &phys, &mapped_blocks, &create);
3141 if (err) {
3142 __unlock_super(sb);
3143 return err;
3144 }
3145
3146 if (phys) {
3147 max_blocks = min(mapped_blocks, max_blocks);
3148 if (create) {
3149 EXFAT_I(inode)->mmu_private += max_blocks <<
3150 sb->s_blocksize_bits;
3151 set_buffer_new(bh_result);
3152 }
3153 map_bh(bh_result, sb, phys);
3154 }
3155
3156 bh_result->b_size = max_blocks << sb->s_blocksize_bits;
3157 __unlock_super(sb);
3158
3159 return 0;
3160}
3161
3162static int exfat_readpage(struct file *file, struct page *page)
3163{
3164 return mpage_readpage(page, exfat_get_block);
3165}
3166
3167static int exfat_readpages(struct file *file, struct address_space *mapping,
3168 struct list_head *pages, unsigned int nr_pages)
3169{
3170 return mpage_readpages(mapping, pages, nr_pages, exfat_get_block);
3171}
3172
3173static int exfat_writepage(struct page *page, struct writeback_control *wbc)
3174{
3175 return block_write_full_page(page, exfat_get_block, wbc);
3176}
3177
3178static int exfat_writepages(struct address_space *mapping,
3179 struct writeback_control *wbc)
3180{
3181 return mpage_writepages(mapping, wbc, exfat_get_block);
3182}
3183
3184static void exfat_write_failed(struct address_space *mapping, loff_t to)
3185{
3186 struct inode *inode = mapping->host;
3187
3188 if (to > i_size_read(inode)) {
3189 truncate_pagecache(inode, i_size_read(inode));
3190 EXFAT_I(inode)->fid.size = i_size_read(inode);
3191 exfat_truncate(inode, i_size_read(inode));
3192 }
3193}
3194
3195static int exfat_write_begin(struct file *file, struct address_space *mapping,
3196 loff_t pos, unsigned int len, unsigned int flags,
3197 struct page **pagep, void **fsdata)
3198{
3199 int ret;
3200
3201 *pagep = NULL;
3202 ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
3203 exfat_get_block,
3204 &EXFAT_I(mapping->host)->mmu_private);
3205
3206 if (ret < 0)
3207 exfat_write_failed(mapping, pos + len);
3208 return ret;
3209}
3210
3211static int exfat_write_end(struct file *file, struct address_space *mapping,
3212 loff_t pos, unsigned int len, unsigned int copied,
3213 struct page *pagep, void *fsdata)
3214{
3215 struct inode *inode = mapping->host;
3216 struct file_id_t *fid = &(EXFAT_I(inode)->fid);
3217 int err;
3218
3219 err = generic_write_end(file, mapping, pos, len, copied, pagep, fsdata);
3220
3221 if (err < len)
3222 exfat_write_failed(mapping, pos + len);
3223
3224 if (!(err < 0) && !(fid->attr & ATTR_ARCHIVE)) {
3225 inode->i_mtime = inode->i_ctime = current_time(inode);
3226 fid->attr |= ATTR_ARCHIVE;
3227 mark_inode_dirty(inode);
3228 }
3229 return err;
3230}
3231
3232static ssize_t exfat_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
3233{
3234 struct inode *inode = iocb->ki_filp->f_mapping->host;
3235 struct address_space *mapping = iocb->ki_filp->f_mapping;
3236 ssize_t ret;
3237 int rw;
3238
3239 rw = iov_iter_rw(iter);
3240
3241 if (rw == WRITE) {
3242 if (EXFAT_I(inode)->mmu_private < iov_iter_count(iter))
3243 return 0;
3244 }
3245 ret = blockdev_direct_IO(iocb, inode, iter, exfat_get_block);
3246
3247 if ((ret < 0) && (rw & WRITE))
3248 exfat_write_failed(mapping, iov_iter_count(iter));
3249 return ret;
3250}
3251
3252static sector_t _exfat_bmap(struct address_space *mapping, sector_t block)
3253{
3254 sector_t blocknr;
3255
3256 /* exfat_get_cluster() assumes the requested blocknr isn't truncated. */
3257 down_read(&EXFAT_I(mapping->host)->truncate_lock);
3258 blocknr = generic_block_bmap(mapping, block, exfat_get_block);
3259 up_read(&EXFAT_I(mapping->host)->truncate_lock);
3260
3261 return blocknr;
3262}
3263
3264static const struct address_space_operations exfat_aops = {
3265 .readpage = exfat_readpage,
3266 .readpages = exfat_readpages,
3267 .writepage = exfat_writepage,
3268 .writepages = exfat_writepages,
3269 .write_begin = exfat_write_begin,
3270 .write_end = exfat_write_end,
3271 .direct_IO = exfat_direct_IO,
3272 .bmap = _exfat_bmap
3273};
3274
3275/*======================================================================*/
3276/* Super Operations */
3277/*======================================================================*/
3278
3279static struct inode *exfat_iget(struct super_block *sb, loff_t i_pos)
3280{
3281 struct exfat_sb_info *sbi = EXFAT_SB(sb);
3282 struct exfat_inode_info *info;
3283 struct hlist_head *head = sbi->inode_hashtable + exfat_hash(i_pos);
3284 struct inode *inode = NULL;
3285
3286 spin_lock(&sbi->inode_hash_lock);
3287 hlist_for_each_entry(info, head, i_hash_fat) {
3288 BUG_ON(info->vfs_inode.i_sb != sb);
3289
3290 if (i_pos != info->i_pos)
3291 continue;
3292 inode = igrab(&info->vfs_inode);
3293 if (inode)
3294 break;
3295 }
3296 spin_unlock(&sbi->inode_hash_lock);
3297 return inode;
3298}
3299
3300/* doesn't deal with root inode */
3301static int exfat_fill_inode(struct inode *inode, struct file_id_t *fid)
3302{
3303 struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb);
3304 struct fs_info_t *p_fs = &(sbi->fs_info);
3305 struct dir_entry_t info;
3306
3307 memcpy(&(EXFAT_I(inode)->fid), fid, sizeof(struct file_id_t));
3308
3309 ffsReadStat(inode, &info);
3310
3311 EXFAT_I(inode)->i_pos = 0;
3312 EXFAT_I(inode)->target = NULL;
3313 inode->i_uid = sbi->options.fs_uid;
3314 inode->i_gid = sbi->options.fs_gid;
3315 INC_IVERSION(inode);
3316 inode->i_generation = get_seconds();
3317
3318 if (info.Attr & ATTR_SUBDIR) { /* directory */
3319 inode->i_generation &= ~1;
3320 inode->i_mode = exfat_make_mode(sbi, info.Attr, 0777);
3321 inode->i_op = &exfat_dir_inode_operations;
3322 inode->i_fop = &exfat_dir_operations;
3323
3324 i_size_write(inode, info.Size);
3325 EXFAT_I(inode)->mmu_private = i_size_read(inode);
3326 set_nlink(inode, info.NumSubdirs);
3327 } else if (info.Attr & ATTR_SYMLINK) { /* symbolic link */
3328 inode->i_generation |= 1;
3329 inode->i_mode = exfat_make_mode(sbi, info.Attr, 0777);
3330 inode->i_op = &exfat_symlink_inode_operations;
3331
3332 i_size_write(inode, info.Size);
3333 EXFAT_I(inode)->mmu_private = i_size_read(inode);
3334 } else { /* regular file */
3335 inode->i_generation |= 1;
3336 inode->i_mode = exfat_make_mode(sbi, info.Attr, 0777);
3337 inode->i_op = &exfat_file_inode_operations;
3338 inode->i_fop = &exfat_file_operations;
3339 inode->i_mapping->a_ops = &exfat_aops;
3340 inode->i_mapping->nrpages = 0;
3341
3342 i_size_write(inode, info.Size);
3343 EXFAT_I(inode)->mmu_private = i_size_read(inode);
3344 }
3345 exfat_save_attr(inode, info.Attr);
3346
3347 inode->i_blocks = ((i_size_read(inode) + (p_fs->cluster_size - 1))
3348 & ~((loff_t)p_fs->cluster_size - 1)) >> 9;
3349
3350 exfat_time_fat2unix(&inode->i_mtime, &info.ModifyTimestamp);
3351 exfat_time_fat2unix(&inode->i_ctime, &info.CreateTimestamp);
3352 exfat_time_fat2unix(&inode->i_atime, &info.AccessTimestamp);
3353
3354 return 0;
3355}
3356
3357static struct inode *exfat_build_inode(struct super_block *sb,
3358 struct file_id_t *fid, loff_t i_pos)
3359{
3360 struct inode *inode;
3361 int err;
3362
3363 inode = exfat_iget(sb, i_pos);
3364 if (inode)
3365 goto out;
3366 inode = new_inode(sb);
3367 if (!inode) {
3368 inode = ERR_PTR(-ENOMEM);
3369 goto out;
3370 }
3371 inode->i_ino = iunique(sb, EXFAT_ROOT_INO);
3372 SET_IVERSION(inode, 1);
3373 err = exfat_fill_inode(inode, fid);
3374 if (err) {
3375 iput(inode);
3376 inode = ERR_PTR(err);
3377 goto out;
3378 }
3379 exfat_attach(inode, i_pos);
3380 insert_inode_hash(inode);
3381out:
3382 return inode;
3383}
3384
3385static int exfat_sync_inode(struct inode *inode)
3386{
3387 return exfat_write_inode(inode, NULL);
3388}
3389
3390static struct inode *exfat_alloc_inode(struct super_block *sb)
3391{
3392 struct exfat_inode_info *ei;
3393
3394 ei = kmem_cache_alloc(exfat_inode_cachep, GFP_NOFS);
3395 if (!ei)
3396 return NULL;
3397
3398 init_rwsem(&ei->truncate_lock);
3399
3400 return &ei->vfs_inode;
3401}
3402
3403static void exfat_destroy_inode(struct inode *inode)
3404{
3405 kfree(EXFAT_I(inode)->target);
3406 EXFAT_I(inode)->target = NULL;
3407
3408 kmem_cache_free(exfat_inode_cachep, EXFAT_I(inode));
3409}
3410
3411static int exfat_write_inode(struct inode *inode, struct writeback_control *wbc)
3412{
3413 struct dir_entry_t info;
3414
3415 if (inode->i_ino == EXFAT_ROOT_INO)
3416 return 0;
3417
3418 info.Attr = exfat_make_attr(inode);
3419 info.Size = i_size_read(inode);
3420
3421 exfat_time_unix2fat(&inode->i_mtime, &info.ModifyTimestamp);
3422 exfat_time_unix2fat(&inode->i_ctime, &info.CreateTimestamp);
3423 exfat_time_unix2fat(&inode->i_atime, &info.AccessTimestamp);
3424
3425 ffsWriteStat(inode, &info);
3426
3427 return 0;
3428}
3429
3430static void exfat_evict_inode(struct inode *inode)
3431{
3432 truncate_inode_pages(&inode->i_data, 0);
3433
3434 if (!inode->i_nlink)
3435 i_size_write(inode, 0);
3436 invalidate_inode_buffers(inode);
3437 clear_inode(inode);
3438 exfat_detach(inode);
3439
3440 remove_inode_hash(inode);
3441}
3442
3443static void exfat_free_super(struct exfat_sb_info *sbi)
3444{
3445 if (sbi->nls_disk)
3446 unload_nls(sbi->nls_disk);
3447 if (sbi->nls_io)
3448 unload_nls(sbi->nls_io);
3449 if (sbi->options.iocharset != exfat_default_iocharset)
3450 kfree(sbi->options.iocharset);
3451 /* mutex_init is in exfat_fill_super function. only for 3.7+ */
3452 mutex_destroy(&sbi->s_lock);
3453 kfree(sbi);
3454}
3455
3456static void exfat_put_super(struct super_block *sb)
3457{
3458 struct exfat_sb_info *sbi = EXFAT_SB(sb);
3459
3460 if (__is_sb_dirty(sb))
3461 exfat_write_super(sb);
3462
3463 ffsUmountVol(sb);
3464
3465 sb->s_fs_info = NULL;
3466 exfat_free_super(sbi);
3467}
3468
3469static void exfat_write_super(struct super_block *sb)
3470{
3471 __lock_super(sb);
3472
3473 __set_sb_clean(sb);
3474
3475 if (!sb_rdonly(sb))
3476 ffsSyncVol(sb, true);
3477
3478 __unlock_super(sb);
3479}
3480
3481static int exfat_sync_fs(struct super_block *sb, int wait)
3482{
3483 int err = 0;
3484
3485 if (__is_sb_dirty(sb)) {
3486 __lock_super(sb);
3487 __set_sb_clean(sb);
3488 err = ffsSyncVol(sb, true);
3489 __unlock_super(sb);
3490 }
3491
3492 return err;
3493}
3494
3495static int exfat_statfs(struct dentry *dentry, struct kstatfs *buf)
3496{
3497 struct super_block *sb = dentry->d_sb;
3498 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
3499 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
3500 struct vol_info_t info;
3501
3502 if (p_fs->used_clusters == UINT_MAX) {
3503 if (ffsGetVolInfo(sb, &info) == FFS_MEDIAERR)
3504 return -EIO;
3505
3506 } else {
3507 info.FatType = p_fs->vol_type;
3508 info.ClusterSize = p_fs->cluster_size;
3509 info.NumClusters = p_fs->num_clusters - 2;
3510 info.UsedClusters = p_fs->used_clusters;
3511 info.FreeClusters = info.NumClusters - info.UsedClusters;
3512
3513 if (p_fs->dev_ejected)
3514 pr_info("[EXFAT] statfs on device that is ejected\n");
3515 }
3516
3517 buf->f_type = sb->s_magic;
3518 buf->f_bsize = info.ClusterSize;
3519 buf->f_blocks = info.NumClusters;
3520 buf->f_bfree = info.FreeClusters;
3521 buf->f_bavail = info.FreeClusters;
3522 buf->f_fsid.val[0] = (u32)id;
3523 buf->f_fsid.val[1] = (u32)(id >> 32);
3524 buf->f_namelen = 260;
3525
3526 return 0;
3527}
3528
3529static int exfat_remount(struct super_block *sb, int *flags, char *data)
3530{
3531 *flags |= SB_NODIRATIME;
3532 return 0;
3533}
3534
3535static int exfat_show_options(struct seq_file *m, struct dentry *root)
3536{
3537 struct exfat_sb_info *sbi = EXFAT_SB(root->d_sb);
3538 struct exfat_mount_options *opts = &sbi->options;
3539
3540 if (__kuid_val(opts->fs_uid))
3541 seq_printf(m, ",uid=%u", __kuid_val(opts->fs_uid));
3542 if (__kgid_val(opts->fs_gid))
3543 seq_printf(m, ",gid=%u", __kgid_val(opts->fs_gid));
3544 seq_printf(m, ",fmask=%04o", opts->fs_fmask);
3545 seq_printf(m, ",dmask=%04o", opts->fs_dmask);
3546 if (opts->allow_utime)
3547 seq_printf(m, ",allow_utime=%04o", opts->allow_utime);
3548 if (sbi->nls_disk)
3549 seq_printf(m, ",codepage=%s", sbi->nls_disk->charset);
3550 if (sbi->nls_io)
3551 seq_printf(m, ",iocharset=%s", sbi->nls_io->charset);
3552 seq_printf(m, ",namecase=%u", opts->casesensitive);
3553 if (opts->errors == EXFAT_ERRORS_CONT)
3554 seq_puts(m, ",errors=continue");
3555 else if (opts->errors == EXFAT_ERRORS_PANIC)
3556 seq_puts(m, ",errors=panic");
3557 else
3558 seq_puts(m, ",errors=remount-ro");
3559#ifdef CONFIG_EXFAT_DISCARD
3560 if (opts->discard)
3561 seq_puts(m, ",discard");
3562#endif
3563 return 0;
3564}
3565
3566static const struct super_operations exfat_sops = {
3567 .alloc_inode = exfat_alloc_inode,
3568 .destroy_inode = exfat_destroy_inode,
3569 .write_inode = exfat_write_inode,
3570 .evict_inode = exfat_evict_inode,
3571 .put_super = exfat_put_super,
3572 .sync_fs = exfat_sync_fs,
3573 .statfs = exfat_statfs,
3574 .remount_fs = exfat_remount,
3575 .show_options = exfat_show_options,
3576};
3577
3578/*======================================================================*/
3579/* Export Operations */
3580/*======================================================================*/
3581
3582static struct inode *exfat_nfs_get_inode(struct super_block *sb, u64 ino,
3583 u32 generation)
3584{
3585 struct inode *inode = NULL;
3586
3587 if (ino < EXFAT_ROOT_INO)
3588 return inode;
3589 inode = ilookup(sb, ino);
3590
3591 if (inode && generation && (inode->i_generation != generation)) {
3592 iput(inode);
3593 inode = NULL;
3594 }
3595
3596 return inode;
3597}
3598
3599static struct dentry *exfat_fh_to_dentry(struct super_block *sb,
3600 struct fid *fid, int fh_len,
3601 int fh_type)
3602{
3603 return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
3604 exfat_nfs_get_inode);
3605}
3606
3607static struct dentry *exfat_fh_to_parent(struct super_block *sb,
3608 struct fid *fid, int fh_len,
3609 int fh_type)
3610{
3611 return generic_fh_to_parent(sb, fid, fh_len, fh_type,
3612 exfat_nfs_get_inode);
3613}
3614
3615static const struct export_operations exfat_export_ops = {
3616 .fh_to_dentry = exfat_fh_to_dentry,
3617 .fh_to_parent = exfat_fh_to_parent,
3618};
3619
3620/*======================================================================*/
3621/* Super Block Read Operations */
3622/*======================================================================*/
3623
3624enum {
3625 Opt_uid,
3626 Opt_gid,
3627 Opt_umask,
3628 Opt_dmask,
3629 Opt_fmask,
3630 Opt_allow_utime,
3631 Opt_codepage,
3632 Opt_charset,
3633 Opt_namecase,
3634 Opt_debug,
3635 Opt_err_cont,
3636 Opt_err_panic,
3637 Opt_err_ro,
3638 Opt_utf8_hack,
3639 Opt_err,
3640#ifdef CONFIG_EXFAT_DISCARD
3641 Opt_discard,
3642#endif /* EXFAT_CONFIG_DISCARD */
3643};
3644
3645static const match_table_t exfat_tokens = {
3646 {Opt_uid, "uid=%u"},
3647 {Opt_gid, "gid=%u"},
3648 {Opt_umask, "umask=%o"},
3649 {Opt_dmask, "dmask=%o"},
3650 {Opt_fmask, "fmask=%o"},
3651 {Opt_allow_utime, "allow_utime=%o"},
3652 {Opt_codepage, "codepage=%u"},
3653 {Opt_charset, "iocharset=%s"},
3654 {Opt_namecase, "namecase=%u"},
3655 {Opt_debug, "debug"},
3656 {Opt_err_cont, "errors=continue"},
3657 {Opt_err_panic, "errors=panic"},
3658 {Opt_err_ro, "errors=remount-ro"},
3659 {Opt_utf8_hack, "utf8"},
3660#ifdef CONFIG_EXFAT_DISCARD
3661 {Opt_discard, "discard"},
3662#endif /* CONFIG_EXFAT_DISCARD */
3663 {Opt_err, NULL}
3664};
3665
3666static int parse_options(char *options, int silent, int *debug,
3667 struct exfat_mount_options *opts)
3668{
3669 char *p;
3670 substring_t args[MAX_OPT_ARGS];
3671 int option;
3672 char *iocharset;
3673
3674 opts->fs_uid = current_uid();
3675 opts->fs_gid = current_gid();
3676 opts->fs_fmask = opts->fs_dmask = current->fs->umask;
3677 opts->allow_utime = U16_MAX;
3678 opts->codepage = exfat_default_codepage;
3679 opts->iocharset = exfat_default_iocharset;
3680 opts->casesensitive = 0;
3681 opts->errors = EXFAT_ERRORS_RO;
3682#ifdef CONFIG_EXFAT_DISCARD
3683 opts->discard = 0;
3684#endif
3685 *debug = 0;
3686
3687 if (!options)
3688 goto out;
3689
3690 while ((p = strsep(&options, ","))) {
3691 int token;
3692
3693 if (!*p)
3694 continue;
3695
3696 token = match_token(p, exfat_tokens, args);
3697 switch (token) {
3698 case Opt_uid:
3699 if (match_int(&args[0], &option))
3700 return 0;
3701 opts->fs_uid = KUIDT_INIT(option);
3702 break;
3703 case Opt_gid:
3704 if (match_int(&args[0], &option))
3705 return 0;
3706 opts->fs_gid = KGIDT_INIT(option);
3707 break;
3708 case Opt_umask:
3709 case Opt_dmask:
3710 case Opt_fmask:
3711 if (match_octal(&args[0], &option))
3712 return 0;
3713 if (token != Opt_dmask)
3714 opts->fs_fmask = option;
3715 if (token != Opt_fmask)
3716 opts->fs_dmask = option;
3717 break;
3718 case Opt_allow_utime:
3719 if (match_octal(&args[0], &option))
3720 return 0;
3721 opts->allow_utime = option & 0022;
3722 break;
3723 case Opt_codepage:
3724 if (match_int(&args[0], &option))
3725 return 0;
3726 opts->codepage = option;
3727 break;
3728 case Opt_charset:
3729 if (opts->iocharset != exfat_default_iocharset)
3730 kfree(opts->iocharset);
3731 iocharset = match_strdup(&args[0]);
3732 if (!iocharset)
3733 return -ENOMEM;
3734 opts->iocharset = iocharset;
3735 break;
3736 case Opt_namecase:
3737 if (match_int(&args[0], &option))
3738 return 0;
3739 opts->casesensitive = option;
3740 break;
3741 case Opt_err_cont:
3742 opts->errors = EXFAT_ERRORS_CONT;
3743 break;
3744 case Opt_err_panic:
3745 opts->errors = EXFAT_ERRORS_PANIC;
3746 break;
3747 case Opt_err_ro:
3748 opts->errors = EXFAT_ERRORS_RO;
3749 break;
3750 case Opt_debug:
3751 *debug = 1;
3752 break;
3753#ifdef CONFIG_EXFAT_DISCARD
3754 case Opt_discard:
3755 opts->discard = 1;
3756 break;
3757#endif /* CONFIG_EXFAT_DISCARD */
3758 case Opt_utf8_hack:
3759 break;
3760 default:
3761 if (!silent)
3762 pr_err("[EXFAT] Unrecognized mount option %s or missing value\n",
3763 p);
3764 return -EINVAL;
3765 }
3766 }
3767
3768out:
3769 if (opts->allow_utime == U16_MAX)
3770 opts->allow_utime = ~opts->fs_dmask & 0022;
3771
3772 return 0;
3773}
3774
3775static void exfat_hash_init(struct super_block *sb)
3776{
3777 struct exfat_sb_info *sbi = EXFAT_SB(sb);
3778 int i;
3779
3780 spin_lock_init(&sbi->inode_hash_lock);
3781 for (i = 0; i < EXFAT_HASH_SIZE; i++)
3782 INIT_HLIST_HEAD(&sbi->inode_hashtable[i]);
3783}
3784
3785static int exfat_read_root(struct inode *inode)
3786{
3787 struct super_block *sb = inode->i_sb;
3788 struct exfat_sb_info *sbi = EXFAT_SB(sb);
3789 struct fs_info_t *p_fs = &(sbi->fs_info);
3790 struct dir_entry_t info;
3791
3792 EXFAT_I(inode)->fid.dir.dir = p_fs->root_dir;
3793 EXFAT_I(inode)->fid.dir.flags = 0x01;
3794 EXFAT_I(inode)->fid.entry = -1;
3795 EXFAT_I(inode)->fid.start_clu = p_fs->root_dir;
3796 EXFAT_I(inode)->fid.flags = 0x01;
3797 EXFAT_I(inode)->fid.type = TYPE_DIR;
3798 EXFAT_I(inode)->fid.rwoffset = 0;
3799 EXFAT_I(inode)->fid.hint_last_off = -1;
3800
3801 EXFAT_I(inode)->target = NULL;
3802
3803 ffsReadStat(inode, &info);
3804
3805 inode->i_uid = sbi->options.fs_uid;
3806 inode->i_gid = sbi->options.fs_gid;
3807 INC_IVERSION(inode);
3808 inode->i_generation = 0;
3809 inode->i_mode = exfat_make_mode(sbi, ATTR_SUBDIR, 0777);
3810 inode->i_op = &exfat_dir_inode_operations;
3811 inode->i_fop = &exfat_dir_operations;
3812
3813 i_size_write(inode, info.Size);
3814 inode->i_blocks = ((i_size_read(inode) + (p_fs->cluster_size - 1))
3815 & ~((loff_t)p_fs->cluster_size - 1)) >> 9;
3816 EXFAT_I(inode)->i_pos = ((loff_t)p_fs->root_dir << 32) | 0xffffffff;
3817 EXFAT_I(inode)->mmu_private = i_size_read(inode);
3818
3819 exfat_save_attr(inode, ATTR_SUBDIR);
3820 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
3821 set_nlink(inode, info.NumSubdirs + 2);
3822
3823 return 0;
3824}
3825
3826static void setup_dops(struct super_block *sb)
3827{
3828 if (EXFAT_SB(sb)->options.casesensitive == 0)
3829 sb->s_d_op = &exfat_ci_dentry_ops;
3830 else
3831 sb->s_d_op = &exfat_dentry_ops;
3832}
3833
3834static int exfat_fill_super(struct super_block *sb, void *data, int silent)
3835{
3836 struct inode *root_inode = NULL;
3837 struct exfat_sb_info *sbi;
3838 int debug, ret;
3839 long error;
3840 char buf[50];
3841
3842 /*
3843 * GFP_KERNEL is ok here, because while we do hold the
3844 * supeblock lock, memory pressure can't call back into
3845 * the filesystem, since we're only just about to mount
3846 * it and have no inodes etc active!
3847 */
3848 sbi = kzalloc(sizeof(struct exfat_sb_info), GFP_KERNEL);
3849 if (!sbi)
3850 return -ENOMEM;
3851 mutex_init(&sbi->s_lock);
3852 sb->s_fs_info = sbi;
3853 sb->s_flags |= SB_NODIRATIME;
3854 sb->s_magic = EXFAT_SUPER_MAGIC;
3855 sb->s_op = &exfat_sops;
3856 sb->s_export_op = &exfat_export_ops;
3857
3858 error = parse_options(data, silent, &debug, &sbi->options);
3859 if (error)
3860 goto out_fail;
3861
3862 setup_dops(sb);
3863
3864 error = -EIO;
3865 sb_min_blocksize(sb, 512);
3866 sb->s_maxbytes = 0x7fffffffffffffffLL; /* maximum file size */
3867
3868 ret = ffsMountVol(sb);
3869 if (ret) {
3870 if (!silent)
3871 pr_err("[EXFAT] ffsMountVol failed\n");
3872
3873 goto out_fail;
3874 }
3875
3876 /* set up enough so that it can read an inode */
3877 exfat_hash_init(sb);
3878
3879 /*
3880 * The low byte of FAT's first entry must have same value with
3881 * media-field. But in real world, too many devices is
3882 * writing wrong value. So, removed that validity check.
3883 *
3884 * if (FAT_FIRST_ENT(sb, media) != first)
3885 */
3886
3887 /* codepage is not meaningful in exfat */
3888 if (sbi->fs_info.vol_type != EXFAT) {
3889 error = -EINVAL;
3890 sprintf(buf, "cp%d", sbi->options.codepage);
3891 sbi->nls_disk = load_nls(buf);
3892 if (!sbi->nls_disk) {
3893 pr_err("[EXFAT] Codepage %s not found\n", buf);
3894 goto out_fail2;
3895 }
3896 }
3897
3898 sbi->nls_io = load_nls(sbi->options.iocharset);
3899
3900 error = -ENOMEM;
3901 root_inode = new_inode(sb);
3902 if (!root_inode)
3903 goto out_fail2;
3904 root_inode->i_ino = EXFAT_ROOT_INO;
3905 SET_IVERSION(root_inode, 1);
3906
3907 error = exfat_read_root(root_inode);
3908 if (error < 0)
3909 goto out_fail2;
3910 error = -ENOMEM;
3911 exfat_attach(root_inode, EXFAT_I(root_inode)->i_pos);
3912 insert_inode_hash(root_inode);
3913 sb->s_root = d_make_root(root_inode);
3914 if (!sb->s_root) {
3915 pr_err("[EXFAT] Getting the root inode failed\n");
3916 goto out_fail2;
3917 }
3918
3919 return 0;
3920
3921out_fail2:
3922 ffsUmountVol(sb);
3923out_fail:
3924 if (root_inode)
3925 iput(root_inode);
3926 sb->s_fs_info = NULL;
3927 exfat_free_super(sbi);
3928 return error;
3929}
3930
3931static struct dentry *exfat_fs_mount(struct file_system_type *fs_type,
3932 int flags, const char *dev_name,
3933 void *data)
3934{
3935 return mount_bdev(fs_type, flags, dev_name, data, exfat_fill_super);
3936}
3937
3938static void init_once(void *foo)
3939{
3940 struct exfat_inode_info *ei = (struct exfat_inode_info *)foo;
3941
3942 INIT_HLIST_NODE(&ei->i_hash_fat);
3943 inode_init_once(&ei->vfs_inode);
3944}
3945
3946static int __init exfat_init_inodecache(void)
3947{
3948 exfat_inode_cachep = kmem_cache_create("exfat_inode_cache",
3949 sizeof(struct exfat_inode_info),
3950 0,
3951 (SLAB_RECLAIM_ACCOUNT |
3952 SLAB_MEM_SPREAD),
3953 init_once);
3954 if (!exfat_inode_cachep)
3955 return -ENOMEM;
3956 return 0;
3957}
3958
3959static void __exit exfat_destroy_inodecache(void)
3960{
3961 /*
3962 * Make sure all delayed rcu free inodes are flushed before we
3963 * destroy cache.
3964 */
3965 rcu_barrier();
3966 kmem_cache_destroy(exfat_inode_cachep);
3967}
3968
3969#ifdef CONFIG_EXFAT_KERNEL_DEBUG
3970static void exfat_debug_kill_sb(struct super_block *sb)
3971{
3972 struct exfat_sb_info *sbi = EXFAT_SB(sb);
3973 struct block_device *bdev = sb->s_bdev;
3974 struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
3975
3976 long flags;
3977
3978 if (sbi) {
3979 flags = sbi->debug_flags;
3980
3981 if (flags & EXFAT_DEBUGFLAGS_INVALID_UMOUNT) {
3982 /*
3983 * invalidate_bdev drops all device cache include
3984 * dirty. We use this to simulate device removal.
3985 */
3986 down(&p_fs->v_sem);
3987 FAT_release_all(sb);
3988 buf_release_all(sb);
3989 up(&p_fs->v_sem);
3990
3991 invalidate_bdev(bdev);
3992 }
3993 }
3994
3995 kill_block_super(sb);
3996}
3997#endif /* CONFIG_EXFAT_KERNEL_DEBUG */
3998
3999static struct file_system_type exfat_fs_type = {
4000 .owner = THIS_MODULE,
4001 .name = "exfat",
4002 .mount = exfat_fs_mount,
4003#ifdef CONFIG_EXFAT_KERNEL_DEBUG
4004 .kill_sb = exfat_debug_kill_sb,
4005#else
4006 .kill_sb = kill_block_super,
4007#endif /* CONFIG_EXFAT_KERNEL_DEBUG */
4008 .fs_flags = FS_REQUIRES_DEV,
4009};
4010
4011static int __init init_exfat(void)
4012{
4013 int err;
4014
4015 BUILD_BUG_ON(sizeof(struct dentry_t) != DENTRY_SIZE);
4016 BUILD_BUG_ON(sizeof(struct dos_dentry_t) != DENTRY_SIZE);
4017 BUILD_BUG_ON(sizeof(struct ext_dentry_t) != DENTRY_SIZE);
4018 BUILD_BUG_ON(sizeof(struct file_dentry_t) != DENTRY_SIZE);
4019 BUILD_BUG_ON(sizeof(struct strm_dentry_t) != DENTRY_SIZE);
4020 BUILD_BUG_ON(sizeof(struct name_dentry_t) != DENTRY_SIZE);
4021 BUILD_BUG_ON(sizeof(struct bmap_dentry_t) != DENTRY_SIZE);
4022 BUILD_BUG_ON(sizeof(struct case_dentry_t) != DENTRY_SIZE);
4023 BUILD_BUG_ON(sizeof(struct volm_dentry_t) != DENTRY_SIZE);
4024
4025 pr_info("exFAT: Version %s\n", EXFAT_VERSION);
4026
4027 err = exfat_init_inodecache();
4028 if (err)
4029 return err;
4030
4031 err = register_filesystem(&exfat_fs_type);
4032 if (err)
4033 return err;
4034
4035 return 0;
4036}
4037
4038static void __exit exit_exfat(void)
4039{
4040 exfat_destroy_inodecache();
4041 unregister_filesystem(&exfat_fs_type);
4042}
4043
4044module_init(init_exfat);
4045module_exit(exit_exfat);
4046
4047MODULE_LICENSE("GPL");
4048MODULE_DESCRIPTION("exFAT Filesystem Driver");
4049MODULE_ALIAS_FS("exfat");
diff --git a/drivers/staging/exfat/exfat_upcase.c b/drivers/staging/exfat/exfat_upcase.c
new file mode 100644
index 000000000000..366082fb3dab
--- /dev/null
+++ b/drivers/staging/exfat/exfat_upcase.c
@@ -0,0 +1,740 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */
5
6#include <linux/types.h>
7#include "exfat.h"
8
9const u8 uni_upcase[NUM_UPCASE << 1] = {
10 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00,
11 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00,
12 0x08, 0x00, 0x09, 0x00, 0x0A, 0x00, 0x0B, 0x00,
13 0x0C, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x0F, 0x00,
14 0x10, 0x00, 0x11, 0x00, 0x12, 0x00, 0x13, 0x00,
15 0x14, 0x00, 0x15, 0x00, 0x16, 0x00, 0x17, 0x00,
16 0x18, 0x00, 0x19, 0x00, 0x1A, 0x00, 0x1B, 0x00,
17 0x1C, 0x00, 0x1D, 0x00, 0x1E, 0x00, 0x1F, 0x00,
18 0x20, 0x00, 0x21, 0x00, 0x22, 0x00, 0x23, 0x00,
19 0x24, 0x00, 0x25, 0x00, 0x26, 0x00, 0x27, 0x00,
20 0x28, 0x00, 0x29, 0x00, 0x2A, 0x00, 0x2B, 0x00,
21 0x2C, 0x00, 0x2D, 0x00, 0x2E, 0x00, 0x2F, 0x00,
22 0x30, 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00,
23 0x34, 0x00, 0x35, 0x00, 0x36, 0x00, 0x37, 0x00,
24 0x38, 0x00, 0x39, 0x00, 0x3A, 0x00, 0x3B, 0x00,
25 0x3C, 0x00, 0x3D, 0x00, 0x3E, 0x00, 0x3F, 0x00,
26 0x40, 0x00, 0x41, 0x00, 0x42, 0x00, 0x43, 0x00,
27 0x44, 0x00, 0x45, 0x00, 0x46, 0x00, 0x47, 0x00,
28 0x48, 0x00, 0x49, 0x00, 0x4A, 0x00, 0x4B, 0x00,
29 0x4C, 0x00, 0x4D, 0x00, 0x4E, 0x00, 0x4F, 0x00,
30 0x50, 0x00, 0x51, 0x00, 0x52, 0x00, 0x53, 0x00,
31 0x54, 0x00, 0x55, 0x00, 0x56, 0x00, 0x57, 0x00,
32 0x58, 0x00, 0x59, 0x00, 0x5A, 0x00, 0x5B, 0x00,
33 0x5C, 0x00, 0x5D, 0x00, 0x5E, 0x00, 0x5F, 0x00,
34 0x60, 0x00, 0x41, 0x00, 0x42, 0x00, 0x43, 0x00,
35 0x44, 0x00, 0x45, 0x00, 0x46, 0x00, 0x47, 0x00,
36 0x48, 0x00, 0x49, 0x00, 0x4A, 0x00, 0x4B, 0x00,
37 0x4C, 0x00, 0x4D, 0x00, 0x4E, 0x00, 0x4F, 0x00,
38 0x50, 0x00, 0x51, 0x00, 0x52, 0x00, 0x53, 0x00,
39 0x54, 0x00, 0x55, 0x00, 0x56, 0x00, 0x57, 0x00,
40 0x58, 0x00, 0x59, 0x00, 0x5A, 0x00, 0x7B, 0x00,
41 0x7C, 0x00, 0x7D, 0x00, 0x7E, 0x00, 0x7F, 0x00,
42 0x80, 0x00, 0x81, 0x00, 0x82, 0x00, 0x83, 0x00,
43 0x84, 0x00, 0x85, 0x00, 0x86, 0x00, 0x87, 0x00,
44 0x88, 0x00, 0x89, 0x00, 0x8A, 0x00, 0x8B, 0x00,
45 0x8C, 0x00, 0x8D, 0x00, 0x8E, 0x00, 0x8F, 0x00,
46 0x90, 0x00, 0x91, 0x00, 0x92, 0x00, 0x93, 0x00,
47 0x94, 0x00, 0x95, 0x00, 0x96, 0x00, 0x97, 0x00,
48 0x98, 0x00, 0x99, 0x00, 0x9A, 0x00, 0x9B, 0x00,
49 0x9C, 0x00, 0x9D, 0x00, 0x9E, 0x00, 0x9F, 0x00,
50 0xA0, 0x00, 0xA1, 0x00, 0xA2, 0x00, 0xA3, 0x00,
51 0xA4, 0x00, 0xA5, 0x00, 0xA6, 0x00, 0xA7, 0x00,
52 0xA8, 0x00, 0xA9, 0x00, 0xAA, 0x00, 0xAB, 0x00,
53 0xAC, 0x00, 0xAD, 0x00, 0xAE, 0x00, 0xAF, 0x00,
54 0xB0, 0x00, 0xB1, 0x00, 0xB2, 0x00, 0xB3, 0x00,
55 0xB4, 0x00, 0xB5, 0x00, 0xB6, 0x00, 0xB7, 0x00,
56 0xB8, 0x00, 0xB9, 0x00, 0xBA, 0x00, 0xBB, 0x00,
57 0xBC, 0x00, 0xBD, 0x00, 0xBE, 0x00, 0xBF, 0x00,
58 0xC0, 0x00, 0xC1, 0x00, 0xC2, 0x00, 0xC3, 0x00,
59 0xC4, 0x00, 0xC5, 0x00, 0xC6, 0x00, 0xC7, 0x00,
60 0xC8, 0x00, 0xC9, 0x00, 0xCA, 0x00, 0xCB, 0x00,
61 0xCC, 0x00, 0xCD, 0x00, 0xCE, 0x00, 0xCF, 0x00,
62 0xD0, 0x00, 0xD1, 0x00, 0xD2, 0x00, 0xD3, 0x00,
63 0xD4, 0x00, 0xD5, 0x00, 0xD6, 0x00, 0xD7, 0x00,
64 0xD8, 0x00, 0xD9, 0x00, 0xDA, 0x00, 0xDB, 0x00,
65 0xDC, 0x00, 0xDD, 0x00, 0xDE, 0x00, 0xDF, 0x00,
66 0xC0, 0x00, 0xC1, 0x00, 0xC2, 0x00, 0xC3, 0x00,
67 0xC4, 0x00, 0xC5, 0x00, 0xC6, 0x00, 0xC7, 0x00,
68 0xC8, 0x00, 0xC9, 0x00, 0xCA, 0x00, 0xCB, 0x00,
69 0xCC, 0x00, 0xCD, 0x00, 0xCE, 0x00, 0xCF, 0x00,
70 0xD0, 0x00, 0xD1, 0x00, 0xD2, 0x00, 0xD3, 0x00,
71 0xD4, 0x00, 0xD5, 0x00, 0xD6, 0x00, 0xF7, 0x00,
72 0xD8, 0x00, 0xD9, 0x00, 0xDA, 0x00, 0xDB, 0x00,
73 0xDC, 0x00, 0xDD, 0x00, 0xDE, 0x00, 0x78, 0x01,
74 0x00, 0x01, 0x00, 0x01, 0x02, 0x01, 0x02, 0x01,
75 0x04, 0x01, 0x04, 0x01, 0x06, 0x01, 0x06, 0x01,
76 0x08, 0x01, 0x08, 0x01, 0x0A, 0x01, 0x0A, 0x01,
77 0x0C, 0x01, 0x0C, 0x01, 0x0E, 0x01, 0x0E, 0x01,
78 0x10, 0x01, 0x10, 0x01, 0x12, 0x01, 0x12, 0x01,
79 0x14, 0x01, 0x14, 0x01, 0x16, 0x01, 0x16, 0x01,
80 0x18, 0x01, 0x18, 0x01, 0x1A, 0x01, 0x1A, 0x01,
81 0x1C, 0x01, 0x1C, 0x01, 0x1E, 0x01, 0x1E, 0x01,
82 0x20, 0x01, 0x20, 0x01, 0x22, 0x01, 0x22, 0x01,
83 0x24, 0x01, 0x24, 0x01, 0x26, 0x01, 0x26, 0x01,
84 0x28, 0x01, 0x28, 0x01, 0x2A, 0x01, 0x2A, 0x01,
85 0x2C, 0x01, 0x2C, 0x01, 0x2E, 0x01, 0x2E, 0x01,
86 0x30, 0x01, 0x31, 0x01, 0x32, 0x01, 0x32, 0x01,
87 0x34, 0x01, 0x34, 0x01, 0x36, 0x01, 0x36, 0x01,
88 0x38, 0x01, 0x39, 0x01, 0x39, 0x01, 0x3B, 0x01,
89 0x3B, 0x01, 0x3D, 0x01, 0x3D, 0x01, 0x3F, 0x01,
90 0x3F, 0x01, 0x41, 0x01, 0x41, 0x01, 0x43, 0x01,
91 0x43, 0x01, 0x45, 0x01, 0x45, 0x01, 0x47, 0x01,
92 0x47, 0x01, 0x49, 0x01, 0x4A, 0x01, 0x4A, 0x01,
93 0x4C, 0x01, 0x4C, 0x01, 0x4E, 0x01, 0x4E, 0x01,
94 0x50, 0x01, 0x50, 0x01, 0x52, 0x01, 0x52, 0x01,
95 0x54, 0x01, 0x54, 0x01, 0x56, 0x01, 0x56, 0x01,
96 0x58, 0x01, 0x58, 0x01, 0x5A, 0x01, 0x5A, 0x01,
97 0x5C, 0x01, 0x5C, 0x01, 0x5E, 0x01, 0x5E, 0x01,
98 0x60, 0x01, 0x60, 0x01, 0x62, 0x01, 0x62, 0x01,
99 0x64, 0x01, 0x64, 0x01, 0x66, 0x01, 0x66, 0x01,
100 0x68, 0x01, 0x68, 0x01, 0x6A, 0x01, 0x6A, 0x01,
101 0x6C, 0x01, 0x6C, 0x01, 0x6E, 0x01, 0x6E, 0x01,
102 0x70, 0x01, 0x70, 0x01, 0x72, 0x01, 0x72, 0x01,
103 0x74, 0x01, 0x74, 0x01, 0x76, 0x01, 0x76, 0x01,
104 0x78, 0x01, 0x79, 0x01, 0x79, 0x01, 0x7B, 0x01,
105 0x7B, 0x01, 0x7D, 0x01, 0x7D, 0x01, 0x7F, 0x01,
106 0x43, 0x02, 0x81, 0x01, 0x82, 0x01, 0x82, 0x01,
107 0x84, 0x01, 0x84, 0x01, 0x86, 0x01, 0x87, 0x01,
108 0x87, 0x01, 0x89, 0x01, 0x8A, 0x01, 0x8B, 0x01,
109 0x8B, 0x01, 0x8D, 0x01, 0x8E, 0x01, 0x8F, 0x01,
110 0x90, 0x01, 0x91, 0x01, 0x91, 0x01, 0x93, 0x01,
111 0x94, 0x01, 0xF6, 0x01, 0x96, 0x01, 0x97, 0x01,
112 0x98, 0x01, 0x98, 0x01, 0x3D, 0x02, 0x9B, 0x01,
113 0x9C, 0x01, 0x9D, 0x01, 0x20, 0x02, 0x9F, 0x01,
114 0xA0, 0x01, 0xA0, 0x01, 0xA2, 0x01, 0xA2, 0x01,
115 0xA4, 0x01, 0xA4, 0x01, 0xA6, 0x01, 0xA7, 0x01,
116 0xA7, 0x01, 0xA9, 0x01, 0xAA, 0x01, 0xAB, 0x01,
117 0xAC, 0x01, 0xAC, 0x01, 0xAE, 0x01, 0xAF, 0x01,
118 0xAF, 0x01, 0xB1, 0x01, 0xB2, 0x01, 0xB3, 0x01,
119 0xB3, 0x01, 0xB5, 0x01, 0xB5, 0x01, 0xB7, 0x01,
120 0xB8, 0x01, 0xB8, 0x01, 0xBA, 0x01, 0xBB, 0x01,
121 0xBC, 0x01, 0xBC, 0x01, 0xBE, 0x01, 0xF7, 0x01,
122 0xC0, 0x01, 0xC1, 0x01, 0xC2, 0x01, 0xC3, 0x01,
123 0xC4, 0x01, 0xC5, 0x01, 0xC4, 0x01, 0xC7, 0x01,
124 0xC8, 0x01, 0xC7, 0x01, 0xCA, 0x01, 0xCB, 0x01,
125 0xCA, 0x01, 0xCD, 0x01, 0xCD, 0x01, 0xCF, 0x01,
126 0xCF, 0x01, 0xD1, 0x01, 0xD1, 0x01, 0xD3, 0x01,
127 0xD3, 0x01, 0xD5, 0x01, 0xD5, 0x01, 0xD7, 0x01,
128 0xD7, 0x01, 0xD9, 0x01, 0xD9, 0x01, 0xDB, 0x01,
129 0xDB, 0x01, 0x8E, 0x01, 0xDE, 0x01, 0xDE, 0x01,
130 0xE0, 0x01, 0xE0, 0x01, 0xE2, 0x01, 0xE2, 0x01,
131 0xE4, 0x01, 0xE4, 0x01, 0xE6, 0x01, 0xE6, 0x01,
132 0xE8, 0x01, 0xE8, 0x01, 0xEA, 0x01, 0xEA, 0x01,
133 0xEC, 0x01, 0xEC, 0x01, 0xEE, 0x01, 0xEE, 0x01,
134 0xF0, 0x01, 0xF1, 0x01, 0xF2, 0x01, 0xF1, 0x01,
135 0xF4, 0x01, 0xF4, 0x01, 0xF6, 0x01, 0xF7, 0x01,
136 0xF8, 0x01, 0xF8, 0x01, 0xFA, 0x01, 0xFA, 0x01,
137 0xFC, 0x01, 0xFC, 0x01, 0xFE, 0x01, 0xFE, 0x01,
138 0x00, 0x02, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02,
139 0x04, 0x02, 0x04, 0x02, 0x06, 0x02, 0x06, 0x02,
140 0x08, 0x02, 0x08, 0x02, 0x0A, 0x02, 0x0A, 0x02,
141 0x0C, 0x02, 0x0C, 0x02, 0x0E, 0x02, 0x0E, 0x02,
142 0x10, 0x02, 0x10, 0x02, 0x12, 0x02, 0x12, 0x02,
143 0x14, 0x02, 0x14, 0x02, 0x16, 0x02, 0x16, 0x02,
144 0x18, 0x02, 0x18, 0x02, 0x1A, 0x02, 0x1A, 0x02,
145 0x1C, 0x02, 0x1C, 0x02, 0x1E, 0x02, 0x1E, 0x02,
146 0x20, 0x02, 0x21, 0x02, 0x22, 0x02, 0x22, 0x02,
147 0x24, 0x02, 0x24, 0x02, 0x26, 0x02, 0x26, 0x02,
148 0x28, 0x02, 0x28, 0x02, 0x2A, 0x02, 0x2A, 0x02,
149 0x2C, 0x02, 0x2C, 0x02, 0x2E, 0x02, 0x2E, 0x02,
150 0x30, 0x02, 0x30, 0x02, 0x32, 0x02, 0x32, 0x02,
151 0x34, 0x02, 0x35, 0x02, 0x36, 0x02, 0x37, 0x02,
152 0x38, 0x02, 0x39, 0x02, 0x65, 0x2C, 0x3B, 0x02,
153 0x3B, 0x02, 0x3D, 0x02, 0x66, 0x2C, 0x3F, 0x02,
154 0x40, 0x02, 0x41, 0x02, 0x41, 0x02, 0x43, 0x02,
155 0x44, 0x02, 0x45, 0x02, 0x46, 0x02, 0x46, 0x02,
156 0x48, 0x02, 0x48, 0x02, 0x4A, 0x02, 0x4A, 0x02,
157 0x4C, 0x02, 0x4C, 0x02, 0x4E, 0x02, 0x4E, 0x02,
158 0x50, 0x02, 0x51, 0x02, 0x52, 0x02, 0x81, 0x01,
159 0x86, 0x01, 0x55, 0x02, 0x89, 0x01, 0x8A, 0x01,
160 0x58, 0x02, 0x8F, 0x01, 0x5A, 0x02, 0x90, 0x01,
161 0x5C, 0x02, 0x5D, 0x02, 0x5E, 0x02, 0x5F, 0x02,
162 0x93, 0x01, 0x61, 0x02, 0x62, 0x02, 0x94, 0x01,
163 0x64, 0x02, 0x65, 0x02, 0x66, 0x02, 0x67, 0x02,
164 0x97, 0x01, 0x96, 0x01, 0x6A, 0x02, 0x62, 0x2C,
165 0x6C, 0x02, 0x6D, 0x02, 0x6E, 0x02, 0x9C, 0x01,
166 0x70, 0x02, 0x71, 0x02, 0x9D, 0x01, 0x73, 0x02,
167 0x74, 0x02, 0x9F, 0x01, 0x76, 0x02, 0x77, 0x02,
168 0x78, 0x02, 0x79, 0x02, 0x7A, 0x02, 0x7B, 0x02,
169 0x7C, 0x02, 0x64, 0x2C, 0x7E, 0x02, 0x7F, 0x02,
170 0xA6, 0x01, 0x81, 0x02, 0x82, 0x02, 0xA9, 0x01,
171 0x84, 0x02, 0x85, 0x02, 0x86, 0x02, 0x87, 0x02,
172 0xAE, 0x01, 0x44, 0x02, 0xB1, 0x01, 0xB2, 0x01,
173 0x45, 0x02, 0x8D, 0x02, 0x8E, 0x02, 0x8F, 0x02,
174 0x90, 0x02, 0x91, 0x02, 0xB7, 0x01, 0x93, 0x02,
175 0x94, 0x02, 0x95, 0x02, 0x96, 0x02, 0x97, 0x02,
176 0x98, 0x02, 0x99, 0x02, 0x9A, 0x02, 0x9B, 0x02,
177 0x9C, 0x02, 0x9D, 0x02, 0x9E, 0x02, 0x9F, 0x02,
178 0xA0, 0x02, 0xA1, 0x02, 0xA2, 0x02, 0xA3, 0x02,
179 0xA4, 0x02, 0xA5, 0x02, 0xA6, 0x02, 0xA7, 0x02,
180 0xA8, 0x02, 0xA9, 0x02, 0xAA, 0x02, 0xAB, 0x02,
181 0xAC, 0x02, 0xAD, 0x02, 0xAE, 0x02, 0xAF, 0x02,
182 0xB0, 0x02, 0xB1, 0x02, 0xB2, 0x02, 0xB3, 0x02,
183 0xB4, 0x02, 0xB5, 0x02, 0xB6, 0x02, 0xB7, 0x02,
184 0xB8, 0x02, 0xB9, 0x02, 0xBA, 0x02, 0xBB, 0x02,
185 0xBC, 0x02, 0xBD, 0x02, 0xBE, 0x02, 0xBF, 0x02,
186 0xC0, 0x02, 0xC1, 0x02, 0xC2, 0x02, 0xC3, 0x02,
187 0xC4, 0x02, 0xC5, 0x02, 0xC6, 0x02, 0xC7, 0x02,
188 0xC8, 0x02, 0xC9, 0x02, 0xCA, 0x02, 0xCB, 0x02,
189 0xCC, 0x02, 0xCD, 0x02, 0xCE, 0x02, 0xCF, 0x02,
190 0xD0, 0x02, 0xD1, 0x02, 0xD2, 0x02, 0xD3, 0x02,
191 0xD4, 0x02, 0xD5, 0x02, 0xD6, 0x02, 0xD7, 0x02,
192 0xD8, 0x02, 0xD9, 0x02, 0xDA, 0x02, 0xDB, 0x02,
193 0xDC, 0x02, 0xDD, 0x02, 0xDE, 0x02, 0xDF, 0x02,
194 0xE0, 0x02, 0xE1, 0x02, 0xE2, 0x02, 0xE3, 0x02,
195 0xE4, 0x02, 0xE5, 0x02, 0xE6, 0x02, 0xE7, 0x02,
196 0xE8, 0x02, 0xE9, 0x02, 0xEA, 0x02, 0xEB, 0x02,
197 0xEC, 0x02, 0xED, 0x02, 0xEE, 0x02, 0xEF, 0x02,
198 0xF0, 0x02, 0xF1, 0x02, 0xF2, 0x02, 0xF3, 0x02,
199 0xF4, 0x02, 0xF5, 0x02, 0xF6, 0x02, 0xF7, 0x02,
200 0xF8, 0x02, 0xF9, 0x02, 0xFA, 0x02, 0xFB, 0x02,
201 0xFC, 0x02, 0xFD, 0x02, 0xFE, 0x02, 0xFF, 0x02,
202 0x00, 0x03, 0x01, 0x03, 0x02, 0x03, 0x03, 0x03,
203 0x04, 0x03, 0x05, 0x03, 0x06, 0x03, 0x07, 0x03,
204 0x08, 0x03, 0x09, 0x03, 0x0A, 0x03, 0x0B, 0x03,
205 0x0C, 0x03, 0x0D, 0x03, 0x0E, 0x03, 0x0F, 0x03,
206 0x10, 0x03, 0x11, 0x03, 0x12, 0x03, 0x13, 0x03,
207 0x14, 0x03, 0x15, 0x03, 0x16, 0x03, 0x17, 0x03,
208 0x18, 0x03, 0x19, 0x03, 0x1A, 0x03, 0x1B, 0x03,
209 0x1C, 0x03, 0x1D, 0x03, 0x1E, 0x03, 0x1F, 0x03,
210 0x20, 0x03, 0x21, 0x03, 0x22, 0x03, 0x23, 0x03,
211 0x24, 0x03, 0x25, 0x03, 0x26, 0x03, 0x27, 0x03,
212 0x28, 0x03, 0x29, 0x03, 0x2A, 0x03, 0x2B, 0x03,
213 0x2C, 0x03, 0x2D, 0x03, 0x2E, 0x03, 0x2F, 0x03,
214 0x30, 0x03, 0x31, 0x03, 0x32, 0x03, 0x33, 0x03,
215 0x34, 0x03, 0x35, 0x03, 0x36, 0x03, 0x37, 0x03,
216 0x38, 0x03, 0x39, 0x03, 0x3A, 0x03, 0x3B, 0x03,
217 0x3C, 0x03, 0x3D, 0x03, 0x3E, 0x03, 0x3F, 0x03,
218 0x40, 0x03, 0x41, 0x03, 0x42, 0x03, 0x43, 0x03,
219 0x44, 0x03, 0x45, 0x03, 0x46, 0x03, 0x47, 0x03,
220 0x48, 0x03, 0x49, 0x03, 0x4A, 0x03, 0x4B, 0x03,
221 0x4C, 0x03, 0x4D, 0x03, 0x4E, 0x03, 0x4F, 0x03,
222 0x50, 0x03, 0x51, 0x03, 0x52, 0x03, 0x53, 0x03,
223 0x54, 0x03, 0x55, 0x03, 0x56, 0x03, 0x57, 0x03,
224 0x58, 0x03, 0x59, 0x03, 0x5A, 0x03, 0x5B, 0x03,
225 0x5C, 0x03, 0x5D, 0x03, 0x5E, 0x03, 0x5F, 0x03,
226 0x60, 0x03, 0x61, 0x03, 0x62, 0x03, 0x63, 0x03,
227 0x64, 0x03, 0x65, 0x03, 0x66, 0x03, 0x67, 0x03,
228 0x68, 0x03, 0x69, 0x03, 0x6A, 0x03, 0x6B, 0x03,
229 0x6C, 0x03, 0x6D, 0x03, 0x6E, 0x03, 0x6F, 0x03,
230 0x70, 0x03, 0x71, 0x03, 0x72, 0x03, 0x73, 0x03,
231 0x74, 0x03, 0x75, 0x03, 0x76, 0x03, 0x77, 0x03,
232 0x78, 0x03, 0x79, 0x03, 0x7A, 0x03, 0xFD, 0x03,
233 0xFE, 0x03, 0xFF, 0x03, 0x7E, 0x03, 0x7F, 0x03,
234 0x80, 0x03, 0x81, 0x03, 0x82, 0x03, 0x83, 0x03,
235 0x84, 0x03, 0x85, 0x03, 0x86, 0x03, 0x87, 0x03,
236 0x88, 0x03, 0x89, 0x03, 0x8A, 0x03, 0x8B, 0x03,
237 0x8C, 0x03, 0x8D, 0x03, 0x8E, 0x03, 0x8F, 0x03,
238 0x90, 0x03, 0x91, 0x03, 0x92, 0x03, 0x93, 0x03,
239 0x94, 0x03, 0x95, 0x03, 0x96, 0x03, 0x97, 0x03,
240 0x98, 0x03, 0x99, 0x03, 0x9A, 0x03, 0x9B, 0x03,
241 0x9C, 0x03, 0x9D, 0x03, 0x9E, 0x03, 0x9F, 0x03,
242 0xA0, 0x03, 0xA1, 0x03, 0xA2, 0x03, 0xA3, 0x03,
243 0xA4, 0x03, 0xA5, 0x03, 0xA6, 0x03, 0xA7, 0x03,
244 0xA8, 0x03, 0xA9, 0x03, 0xAA, 0x03, 0xAB, 0x03,
245 0x86, 0x03, 0x88, 0x03, 0x89, 0x03, 0x8A, 0x03,
246 0xB0, 0x03, 0x91, 0x03, 0x92, 0x03, 0x93, 0x03,
247 0x94, 0x03, 0x95, 0x03, 0x96, 0x03, 0x97, 0x03,
248 0x98, 0x03, 0x99, 0x03, 0x9A, 0x03, 0x9B, 0x03,
249 0x9C, 0x03, 0x9D, 0x03, 0x9E, 0x03, 0x9F, 0x03,
250 0xA0, 0x03, 0xA1, 0x03, 0xA3, 0x03, 0xA3, 0x03,
251 0xA4, 0x03, 0xA5, 0x03, 0xA6, 0x03, 0xA7, 0x03,
252 0xA8, 0x03, 0xA9, 0x03, 0xAA, 0x03, 0xAB, 0x03,
253 0x8C, 0x03, 0x8E, 0x03, 0x8F, 0x03, 0xCF, 0x03,
254 0xD0, 0x03, 0xD1, 0x03, 0xD2, 0x03, 0xD3, 0x03,
255 0xD4, 0x03, 0xD5, 0x03, 0xD6, 0x03, 0xD7, 0x03,
256 0xD8, 0x03, 0xD8, 0x03, 0xDA, 0x03, 0xDA, 0x03,
257 0xDC, 0x03, 0xDC, 0x03, 0xDE, 0x03, 0xDE, 0x03,
258 0xE0, 0x03, 0xE0, 0x03, 0xE2, 0x03, 0xE2, 0x03,
259 0xE4, 0x03, 0xE4, 0x03, 0xE6, 0x03, 0xE6, 0x03,
260 0xE8, 0x03, 0xE8, 0x03, 0xEA, 0x03, 0xEA, 0x03,
261 0xEC, 0x03, 0xEC, 0x03, 0xEE, 0x03, 0xEE, 0x03,
262 0xF0, 0x03, 0xF1, 0x03, 0xF9, 0x03, 0xF3, 0x03,
263 0xF4, 0x03, 0xF5, 0x03, 0xF6, 0x03, 0xF7, 0x03,
264 0xF7, 0x03, 0xF9, 0x03, 0xFA, 0x03, 0xFA, 0x03,
265 0xFC, 0x03, 0xFD, 0x03, 0xFE, 0x03, 0xFF, 0x03,
266 0x00, 0x04, 0x01, 0x04, 0x02, 0x04, 0x03, 0x04,
267 0x04, 0x04, 0x05, 0x04, 0x06, 0x04, 0x07, 0x04,
268 0x08, 0x04, 0x09, 0x04, 0x0A, 0x04, 0x0B, 0x04,
269 0x0C, 0x04, 0x0D, 0x04, 0x0E, 0x04, 0x0F, 0x04,
270 0x10, 0x04, 0x11, 0x04, 0x12, 0x04, 0x13, 0x04,
271 0x14, 0x04, 0x15, 0x04, 0x16, 0x04, 0x17, 0x04,
272 0x18, 0x04, 0x19, 0x04, 0x1A, 0x04, 0x1B, 0x04,
273 0x1C, 0x04, 0x1D, 0x04, 0x1E, 0x04, 0x1F, 0x04,
274 0x20, 0x04, 0x21, 0x04, 0x22, 0x04, 0x23, 0x04,
275 0x24, 0x04, 0x25, 0x04, 0x26, 0x04, 0x27, 0x04,
276 0x28, 0x04, 0x29, 0x04, 0x2A, 0x04, 0x2B, 0x04,
277 0x2C, 0x04, 0x2D, 0x04, 0x2E, 0x04, 0x2F, 0x04,
278 0x10, 0x04, 0x11, 0x04, 0x12, 0x04, 0x13, 0x04,
279 0x14, 0x04, 0x15, 0x04, 0x16, 0x04, 0x17, 0x04,
280 0x18, 0x04, 0x19, 0x04, 0x1A, 0x04, 0x1B, 0x04,
281 0x1C, 0x04, 0x1D, 0x04, 0x1E, 0x04, 0x1F, 0x04,
282 0x20, 0x04, 0x21, 0x04, 0x22, 0x04, 0x23, 0x04,
283 0x24, 0x04, 0x25, 0x04, 0x26, 0x04, 0x27, 0x04,
284 0x28, 0x04, 0x29, 0x04, 0x2A, 0x04, 0x2B, 0x04,
285 0x2C, 0x04, 0x2D, 0x04, 0x2E, 0x04, 0x2F, 0x04,
286 0x00, 0x04, 0x01, 0x04, 0x02, 0x04, 0x03, 0x04,
287 0x04, 0x04, 0x05, 0x04, 0x06, 0x04, 0x07, 0x04,
288 0x08, 0x04, 0x09, 0x04, 0x0A, 0x04, 0x0B, 0x04,
289 0x0C, 0x04, 0x0D, 0x04, 0x0E, 0x04, 0x0F, 0x04,
290 0x60, 0x04, 0x60, 0x04, 0x62, 0x04, 0x62, 0x04,
291 0x64, 0x04, 0x64, 0x04, 0x66, 0x04, 0x66, 0x04,
292 0x68, 0x04, 0x68, 0x04, 0x6A, 0x04, 0x6A, 0x04,
293 0x6C, 0x04, 0x6C, 0x04, 0x6E, 0x04, 0x6E, 0x04,
294 0x70, 0x04, 0x70, 0x04, 0x72, 0x04, 0x72, 0x04,
295 0x74, 0x04, 0x74, 0x04, 0x76, 0x04, 0x76, 0x04,
296 0x78, 0x04, 0x78, 0x04, 0x7A, 0x04, 0x7A, 0x04,
297 0x7C, 0x04, 0x7C, 0x04, 0x7E, 0x04, 0x7E, 0x04,
298 0x80, 0x04, 0x80, 0x04, 0x82, 0x04, 0x83, 0x04,
299 0x84, 0x04, 0x85, 0x04, 0x86, 0x04, 0x87, 0x04,
300 0x88, 0x04, 0x89, 0x04, 0x8A, 0x04, 0x8A, 0x04,
301 0x8C, 0x04, 0x8C, 0x04, 0x8E, 0x04, 0x8E, 0x04,
302 0x90, 0x04, 0x90, 0x04, 0x92, 0x04, 0x92, 0x04,
303 0x94, 0x04, 0x94, 0x04, 0x96, 0x04, 0x96, 0x04,
304 0x98, 0x04, 0x98, 0x04, 0x9A, 0x04, 0x9A, 0x04,
305 0x9C, 0x04, 0x9C, 0x04, 0x9E, 0x04, 0x9E, 0x04,
306 0xA0, 0x04, 0xA0, 0x04, 0xA2, 0x04, 0xA2, 0x04,
307 0xA4, 0x04, 0xA4, 0x04, 0xA6, 0x04, 0xA6, 0x04,
308 0xA8, 0x04, 0xA8, 0x04, 0xAA, 0x04, 0xAA, 0x04,
309 0xAC, 0x04, 0xAC, 0x04, 0xAE, 0x04, 0xAE, 0x04,
310 0xB0, 0x04, 0xB0, 0x04, 0xB2, 0x04, 0xB2, 0x04,
311 0xB4, 0x04, 0xB4, 0x04, 0xB6, 0x04, 0xB6, 0x04,
312 0xB8, 0x04, 0xB8, 0x04, 0xBA, 0x04, 0xBA, 0x04,
313 0xBC, 0x04, 0xBC, 0x04, 0xBE, 0x04, 0xBE, 0x04,
314 0xC0, 0x04, 0xC1, 0x04, 0xC1, 0x04, 0xC3, 0x04,
315 0xC3, 0x04, 0xC5, 0x04, 0xC5, 0x04, 0xC7, 0x04,
316 0xC7, 0x04, 0xC9, 0x04, 0xC9, 0x04, 0xCB, 0x04,
317 0xCB, 0x04, 0xCD, 0x04, 0xCD, 0x04, 0xC0, 0x04,
318 0xD0, 0x04, 0xD0, 0x04, 0xD2, 0x04, 0xD2, 0x04,
319 0xD4, 0x04, 0xD4, 0x04, 0xD6, 0x04, 0xD6, 0x04,
320 0xD8, 0x04, 0xD8, 0x04, 0xDA, 0x04, 0xDA, 0x04,
321 0xDC, 0x04, 0xDC, 0x04, 0xDE, 0x04, 0xDE, 0x04,
322 0xE0, 0x04, 0xE0, 0x04, 0xE2, 0x04, 0xE2, 0x04,
323 0xE4, 0x04, 0xE4, 0x04, 0xE6, 0x04, 0xE6, 0x04,
324 0xE8, 0x04, 0xE8, 0x04, 0xEA, 0x04, 0xEA, 0x04,
325 0xEC, 0x04, 0xEC, 0x04, 0xEE, 0x04, 0xEE, 0x04,
326 0xF0, 0x04, 0xF0, 0x04, 0xF2, 0x04, 0xF2, 0x04,
327 0xF4, 0x04, 0xF4, 0x04, 0xF6, 0x04, 0xF6, 0x04,
328 0xF8, 0x04, 0xF8, 0x04, 0xFA, 0x04, 0xFA, 0x04,
329 0xFC, 0x04, 0xFC, 0x04, 0xFE, 0x04, 0xFE, 0x04,
330 0x00, 0x05, 0x00, 0x05, 0x02, 0x05, 0x02, 0x05,
331 0x04, 0x05, 0x04, 0x05, 0x06, 0x05, 0x06, 0x05,
332 0x08, 0x05, 0x08, 0x05, 0x0A, 0x05, 0x0A, 0x05,
333 0x0C, 0x05, 0x0C, 0x05, 0x0E, 0x05, 0x0E, 0x05,
334 0x10, 0x05, 0x10, 0x05, 0x12, 0x05, 0x12, 0x05,
335 0x14, 0x05, 0x15, 0x05, 0x16, 0x05, 0x17, 0x05,
336 0x18, 0x05, 0x19, 0x05, 0x1A, 0x05, 0x1B, 0x05,
337 0x1C, 0x05, 0x1D, 0x05, 0x1E, 0x05, 0x1F, 0x05,
338 0x20, 0x05, 0x21, 0x05, 0x22, 0x05, 0x23, 0x05,
339 0x24, 0x05, 0x25, 0x05, 0x26, 0x05, 0x27, 0x05,
340 0x28, 0x05, 0x29, 0x05, 0x2A, 0x05, 0x2B, 0x05,
341 0x2C, 0x05, 0x2D, 0x05, 0x2E, 0x05, 0x2F, 0x05,
342 0x30, 0x05, 0x31, 0x05, 0x32, 0x05, 0x33, 0x05,
343 0x34, 0x05, 0x35, 0x05, 0x36, 0x05, 0x37, 0x05,
344 0x38, 0x05, 0x39, 0x05, 0x3A, 0x05, 0x3B, 0x05,
345 0x3C, 0x05, 0x3D, 0x05, 0x3E, 0x05, 0x3F, 0x05,
346 0x40, 0x05, 0x41, 0x05, 0x42, 0x05, 0x43, 0x05,
347 0x44, 0x05, 0x45, 0x05, 0x46, 0x05, 0x47, 0x05,
348 0x48, 0x05, 0x49, 0x05, 0x4A, 0x05, 0x4B, 0x05,
349 0x4C, 0x05, 0x4D, 0x05, 0x4E, 0x05, 0x4F, 0x05,
350 0x50, 0x05, 0x51, 0x05, 0x52, 0x05, 0x53, 0x05,
351 0x54, 0x05, 0x55, 0x05, 0x56, 0x05, 0x57, 0x05,
352 0x58, 0x05, 0x59, 0x05, 0x5A, 0x05, 0x5B, 0x05,
353 0x5C, 0x05, 0x5D, 0x05, 0x5E, 0x05, 0x5F, 0x05,
354 0x60, 0x05, 0x31, 0x05, 0x32, 0x05, 0x33, 0x05,
355 0x34, 0x05, 0x35, 0x05, 0x36, 0x05, 0x37, 0x05,
356 0x38, 0x05, 0x39, 0x05, 0x3A, 0x05, 0x3B, 0x05,
357 0x3C, 0x05, 0x3D, 0x05, 0x3E, 0x05, 0x3F, 0x05,
358 0x40, 0x05, 0x41, 0x05, 0x42, 0x05, 0x43, 0x05,
359 0x44, 0x05, 0x45, 0x05, 0x46, 0x05, 0x47, 0x05,
360 0x48, 0x05, 0x49, 0x05, 0x4A, 0x05, 0x4B, 0x05,
361 0x4C, 0x05, 0x4D, 0x05, 0x4E, 0x05, 0x4F, 0x05,
362 0x50, 0x05, 0x51, 0x05, 0x52, 0x05, 0x53, 0x05,
363 0x54, 0x05, 0x55, 0x05, 0x56, 0x05, 0xFF, 0xFF,
364 0xF6, 0x17, 0x63, 0x2C, 0x7E, 0x1D, 0x7F, 0x1D,
365 0x80, 0x1D, 0x81, 0x1D, 0x82, 0x1D, 0x83, 0x1D,
366 0x84, 0x1D, 0x85, 0x1D, 0x86, 0x1D, 0x87, 0x1D,
367 0x88, 0x1D, 0x89, 0x1D, 0x8A, 0x1D, 0x8B, 0x1D,
368 0x8C, 0x1D, 0x8D, 0x1D, 0x8E, 0x1D, 0x8F, 0x1D,
369 0x90, 0x1D, 0x91, 0x1D, 0x92, 0x1D, 0x93, 0x1D,
370 0x94, 0x1D, 0x95, 0x1D, 0x96, 0x1D, 0x97, 0x1D,
371 0x98, 0x1D, 0x99, 0x1D, 0x9A, 0x1D, 0x9B, 0x1D,
372 0x9C, 0x1D, 0x9D, 0x1D, 0x9E, 0x1D, 0x9F, 0x1D,
373 0xA0, 0x1D, 0xA1, 0x1D, 0xA2, 0x1D, 0xA3, 0x1D,
374 0xA4, 0x1D, 0xA5, 0x1D, 0xA6, 0x1D, 0xA7, 0x1D,
375 0xA8, 0x1D, 0xA9, 0x1D, 0xAA, 0x1D, 0xAB, 0x1D,
376 0xAC, 0x1D, 0xAD, 0x1D, 0xAE, 0x1D, 0xAF, 0x1D,
377 0xB0, 0x1D, 0xB1, 0x1D, 0xB2, 0x1D, 0xB3, 0x1D,
378 0xB4, 0x1D, 0xB5, 0x1D, 0xB6, 0x1D, 0xB7, 0x1D,
379 0xB8, 0x1D, 0xB9, 0x1D, 0xBA, 0x1D, 0xBB, 0x1D,
380 0xBC, 0x1D, 0xBD, 0x1D, 0xBE, 0x1D, 0xBF, 0x1D,
381 0xC0, 0x1D, 0xC1, 0x1D, 0xC2, 0x1D, 0xC3, 0x1D,
382 0xC4, 0x1D, 0xC5, 0x1D, 0xC6, 0x1D, 0xC7, 0x1D,
383 0xC8, 0x1D, 0xC9, 0x1D, 0xCA, 0x1D, 0xCB, 0x1D,
384 0xCC, 0x1D, 0xCD, 0x1D, 0xCE, 0x1D, 0xCF, 0x1D,
385 0xD0, 0x1D, 0xD1, 0x1D, 0xD2, 0x1D, 0xD3, 0x1D,
386 0xD4, 0x1D, 0xD5, 0x1D, 0xD6, 0x1D, 0xD7, 0x1D,
387 0xD8, 0x1D, 0xD9, 0x1D, 0xDA, 0x1D, 0xDB, 0x1D,
388 0xDC, 0x1D, 0xDD, 0x1D, 0xDE, 0x1D, 0xDF, 0x1D,
389 0xE0, 0x1D, 0xE1, 0x1D, 0xE2, 0x1D, 0xE3, 0x1D,
390 0xE4, 0x1D, 0xE5, 0x1D, 0xE6, 0x1D, 0xE7, 0x1D,
391 0xE8, 0x1D, 0xE9, 0x1D, 0xEA, 0x1D, 0xEB, 0x1D,
392 0xEC, 0x1D, 0xED, 0x1D, 0xEE, 0x1D, 0xEF, 0x1D,
393 0xF0, 0x1D, 0xF1, 0x1D, 0xF2, 0x1D, 0xF3, 0x1D,
394 0xF4, 0x1D, 0xF5, 0x1D, 0xF6, 0x1D, 0xF7, 0x1D,
395 0xF8, 0x1D, 0xF9, 0x1D, 0xFA, 0x1D, 0xFB, 0x1D,
396 0xFC, 0x1D, 0xFD, 0x1D, 0xFE, 0x1D, 0xFF, 0x1D,
397 0x00, 0x1E, 0x00, 0x1E, 0x02, 0x1E, 0x02, 0x1E,
398 0x04, 0x1E, 0x04, 0x1E, 0x06, 0x1E, 0x06, 0x1E,
399 0x08, 0x1E, 0x08, 0x1E, 0x0A, 0x1E, 0x0A, 0x1E,
400 0x0C, 0x1E, 0x0C, 0x1E, 0x0E, 0x1E, 0x0E, 0x1E,
401 0x10, 0x1E, 0x10, 0x1E, 0x12, 0x1E, 0x12, 0x1E,
402 0x14, 0x1E, 0x14, 0x1E, 0x16, 0x1E, 0x16, 0x1E,
403 0x18, 0x1E, 0x18, 0x1E, 0x1A, 0x1E, 0x1A, 0x1E,
404 0x1C, 0x1E, 0x1C, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E,
405 0x20, 0x1E, 0x20, 0x1E, 0x22, 0x1E, 0x22, 0x1E,
406 0x24, 0x1E, 0x24, 0x1E, 0x26, 0x1E, 0x26, 0x1E,
407 0x28, 0x1E, 0x28, 0x1E, 0x2A, 0x1E, 0x2A, 0x1E,
408 0x2C, 0x1E, 0x2C, 0x1E, 0x2E, 0x1E, 0x2E, 0x1E,
409 0x30, 0x1E, 0x30, 0x1E, 0x32, 0x1E, 0x32, 0x1E,
410 0x34, 0x1E, 0x34, 0x1E, 0x36, 0x1E, 0x36, 0x1E,
411 0x38, 0x1E, 0x38, 0x1E, 0x3A, 0x1E, 0x3A, 0x1E,
412 0x3C, 0x1E, 0x3C, 0x1E, 0x3E, 0x1E, 0x3E, 0x1E,
413 0x40, 0x1E, 0x40, 0x1E, 0x42, 0x1E, 0x42, 0x1E,
414 0x44, 0x1E, 0x44, 0x1E, 0x46, 0x1E, 0x46, 0x1E,
415 0x48, 0x1E, 0x48, 0x1E, 0x4A, 0x1E, 0x4A, 0x1E,
416 0x4C, 0x1E, 0x4C, 0x1E, 0x4E, 0x1E, 0x4E, 0x1E,
417 0x50, 0x1E, 0x50, 0x1E, 0x52, 0x1E, 0x52, 0x1E,
418 0x54, 0x1E, 0x54, 0x1E, 0x56, 0x1E, 0x56, 0x1E,
419 0x58, 0x1E, 0x58, 0x1E, 0x5A, 0x1E, 0x5A, 0x1E,
420 0x5C, 0x1E, 0x5C, 0x1E, 0x5E, 0x1E, 0x5E, 0x1E,
421 0x60, 0x1E, 0x60, 0x1E, 0x62, 0x1E, 0x62, 0x1E,
422 0x64, 0x1E, 0x64, 0x1E, 0x66, 0x1E, 0x66, 0x1E,
423 0x68, 0x1E, 0x68, 0x1E, 0x6A, 0x1E, 0x6A, 0x1E,
424 0x6C, 0x1E, 0x6C, 0x1E, 0x6E, 0x1E, 0x6E, 0x1E,
425 0x70, 0x1E, 0x70, 0x1E, 0x72, 0x1E, 0x72, 0x1E,
426 0x74, 0x1E, 0x74, 0x1E, 0x76, 0x1E, 0x76, 0x1E,
427 0x78, 0x1E, 0x78, 0x1E, 0x7A, 0x1E, 0x7A, 0x1E,
428 0x7C, 0x1E, 0x7C, 0x1E, 0x7E, 0x1E, 0x7E, 0x1E,
429 0x80, 0x1E, 0x80, 0x1E, 0x82, 0x1E, 0x82, 0x1E,
430 0x84, 0x1E, 0x84, 0x1E, 0x86, 0x1E, 0x86, 0x1E,
431 0x88, 0x1E, 0x88, 0x1E, 0x8A, 0x1E, 0x8A, 0x1E,
432 0x8C, 0x1E, 0x8C, 0x1E, 0x8E, 0x1E, 0x8E, 0x1E,
433 0x90, 0x1E, 0x90, 0x1E, 0x92, 0x1E, 0x92, 0x1E,
434 0x94, 0x1E, 0x94, 0x1E, 0x96, 0x1E, 0x97, 0x1E,
435 0x98, 0x1E, 0x99, 0x1E, 0x9A, 0x1E, 0x9B, 0x1E,
436 0x9C, 0x1E, 0x9D, 0x1E, 0x9E, 0x1E, 0x9F, 0x1E,
437 0xA0, 0x1E, 0xA0, 0x1E, 0xA2, 0x1E, 0xA2, 0x1E,
438 0xA4, 0x1E, 0xA4, 0x1E, 0xA6, 0x1E, 0xA6, 0x1E,
439 0xA8, 0x1E, 0xA8, 0x1E, 0xAA, 0x1E, 0xAA, 0x1E,
440 0xAC, 0x1E, 0xAC, 0x1E, 0xAE, 0x1E, 0xAE, 0x1E,
441 0xB0, 0x1E, 0xB0, 0x1E, 0xB2, 0x1E, 0xB2, 0x1E,
442 0xB4, 0x1E, 0xB4, 0x1E, 0xB6, 0x1E, 0xB6, 0x1E,
443 0xB8, 0x1E, 0xB8, 0x1E, 0xBA, 0x1E, 0xBA, 0x1E,
444 0xBC, 0x1E, 0xBC, 0x1E, 0xBE, 0x1E, 0xBE, 0x1E,
445 0xC0, 0x1E, 0xC0, 0x1E, 0xC2, 0x1E, 0xC2, 0x1E,
446 0xC4, 0x1E, 0xC4, 0x1E, 0xC6, 0x1E, 0xC6, 0x1E,
447 0xC8, 0x1E, 0xC8, 0x1E, 0xCA, 0x1E, 0xCA, 0x1E,
448 0xCC, 0x1E, 0xCC, 0x1E, 0xCE, 0x1E, 0xCE, 0x1E,
449 0xD0, 0x1E, 0xD0, 0x1E, 0xD2, 0x1E, 0xD2, 0x1E,
450 0xD4, 0x1E, 0xD4, 0x1E, 0xD6, 0x1E, 0xD6, 0x1E,
451 0xD8, 0x1E, 0xD8, 0x1E, 0xDA, 0x1E, 0xDA, 0x1E,
452 0xDC, 0x1E, 0xDC, 0x1E, 0xDE, 0x1E, 0xDE, 0x1E,
453 0xE0, 0x1E, 0xE0, 0x1E, 0xE2, 0x1E, 0xE2, 0x1E,
454 0xE4, 0x1E, 0xE4, 0x1E, 0xE6, 0x1E, 0xE6, 0x1E,
455 0xE8, 0x1E, 0xE8, 0x1E, 0xEA, 0x1E, 0xEA, 0x1E,
456 0xEC, 0x1E, 0xEC, 0x1E, 0xEE, 0x1E, 0xEE, 0x1E,
457 0xF0, 0x1E, 0xF0, 0x1E, 0xF2, 0x1E, 0xF2, 0x1E,
458 0xF4, 0x1E, 0xF4, 0x1E, 0xF6, 0x1E, 0xF6, 0x1E,
459 0xF8, 0x1E, 0xF8, 0x1E, 0xFA, 0x1E, 0xFB, 0x1E,
460 0xFC, 0x1E, 0xFD, 0x1E, 0xFE, 0x1E, 0xFF, 0x1E,
461 0x08, 0x1F, 0x09, 0x1F, 0x0A, 0x1F, 0x0B, 0x1F,
462 0x0C, 0x1F, 0x0D, 0x1F, 0x0E, 0x1F, 0x0F, 0x1F,
463 0x08, 0x1F, 0x09, 0x1F, 0x0A, 0x1F, 0x0B, 0x1F,
464 0x0C, 0x1F, 0x0D, 0x1F, 0x0E, 0x1F, 0x0F, 0x1F,
465 0x18, 0x1F, 0x19, 0x1F, 0x1A, 0x1F, 0x1B, 0x1F,
466 0x1C, 0x1F, 0x1D, 0x1F, 0x16, 0x1F, 0x17, 0x1F,
467 0x18, 0x1F, 0x19, 0x1F, 0x1A, 0x1F, 0x1B, 0x1F,
468 0x1C, 0x1F, 0x1D, 0x1F, 0x1E, 0x1F, 0x1F, 0x1F,
469 0x28, 0x1F, 0x29, 0x1F, 0x2A, 0x1F, 0x2B, 0x1F,
470 0x2C, 0x1F, 0x2D, 0x1F, 0x2E, 0x1F, 0x2F, 0x1F,
471 0x28, 0x1F, 0x29, 0x1F, 0x2A, 0x1F, 0x2B, 0x1F,
472 0x2C, 0x1F, 0x2D, 0x1F, 0x2E, 0x1F, 0x2F, 0x1F,
473 0x38, 0x1F, 0x39, 0x1F, 0x3A, 0x1F, 0x3B, 0x1F,
474 0x3C, 0x1F, 0x3D, 0x1F, 0x3E, 0x1F, 0x3F, 0x1F,
475 0x38, 0x1F, 0x39, 0x1F, 0x3A, 0x1F, 0x3B, 0x1F,
476 0x3C, 0x1F, 0x3D, 0x1F, 0x3E, 0x1F, 0x3F, 0x1F,
477 0x48, 0x1F, 0x49, 0x1F, 0x4A, 0x1F, 0x4B, 0x1F,
478 0x4C, 0x1F, 0x4D, 0x1F, 0x46, 0x1F, 0x47, 0x1F,
479 0x48, 0x1F, 0x49, 0x1F, 0x4A, 0x1F, 0x4B, 0x1F,
480 0x4C, 0x1F, 0x4D, 0x1F, 0x4E, 0x1F, 0x4F, 0x1F,
481 0x50, 0x1F, 0x59, 0x1F, 0x52, 0x1F, 0x5B, 0x1F,
482 0x54, 0x1F, 0x5D, 0x1F, 0x56, 0x1F, 0x5F, 0x1F,
483 0x58, 0x1F, 0x59, 0x1F, 0x5A, 0x1F, 0x5B, 0x1F,
484 0x5C, 0x1F, 0x5D, 0x1F, 0x5E, 0x1F, 0x5F, 0x1F,
485 0x68, 0x1F, 0x69, 0x1F, 0x6A, 0x1F, 0x6B, 0x1F,
486 0x6C, 0x1F, 0x6D, 0x1F, 0x6E, 0x1F, 0x6F, 0x1F,
487 0x68, 0x1F, 0x69, 0x1F, 0x6A, 0x1F, 0x6B, 0x1F,
488 0x6C, 0x1F, 0x6D, 0x1F, 0x6E, 0x1F, 0x6F, 0x1F,
489 0xBA, 0x1F, 0xBB, 0x1F, 0xC8, 0x1F, 0xC9, 0x1F,
490 0xCA, 0x1F, 0xCB, 0x1F, 0xDA, 0x1F, 0xDB, 0x1F,
491 0xF8, 0x1F, 0xF9, 0x1F, 0xEA, 0x1F, 0xEB, 0x1F,
492 0xFA, 0x1F, 0xFB, 0x1F, 0x7E, 0x1F, 0x7F, 0x1F,
493 0x88, 0x1F, 0x89, 0x1F, 0x8A, 0x1F, 0x8B, 0x1F,
494 0x8C, 0x1F, 0x8D, 0x1F, 0x8E, 0x1F, 0x8F, 0x1F,
495 0x88, 0x1F, 0x89, 0x1F, 0x8A, 0x1F, 0x8B, 0x1F,
496 0x8C, 0x1F, 0x8D, 0x1F, 0x8E, 0x1F, 0x8F, 0x1F,
497 0x98, 0x1F, 0x99, 0x1F, 0x9A, 0x1F, 0x9B, 0x1F,
498 0x9C, 0x1F, 0x9D, 0x1F, 0x9E, 0x1F, 0x9F, 0x1F,
499 0x98, 0x1F, 0x99, 0x1F, 0x9A, 0x1F, 0x9B, 0x1F,
500 0x9C, 0x1F, 0x9D, 0x1F, 0x9E, 0x1F, 0x9F, 0x1F,
501 0xA8, 0x1F, 0xA9, 0x1F, 0xAA, 0x1F, 0xAB, 0x1F,
502 0xAC, 0x1F, 0xAD, 0x1F, 0xAE, 0x1F, 0xAF, 0x1F,
503 0xA8, 0x1F, 0xA9, 0x1F, 0xAA, 0x1F, 0xAB, 0x1F,
504 0xAC, 0x1F, 0xAD, 0x1F, 0xAE, 0x1F, 0xAF, 0x1F,
505 0xB8, 0x1F, 0xB9, 0x1F, 0xB2, 0x1F, 0xBC, 0x1F,
506 0xB4, 0x1F, 0xB5, 0x1F, 0xB6, 0x1F, 0xB7, 0x1F,
507 0xB8, 0x1F, 0xB9, 0x1F, 0xBA, 0x1F, 0xBB, 0x1F,
508 0xBC, 0x1F, 0xBD, 0x1F, 0xBE, 0x1F, 0xBF, 0x1F,
509 0xC0, 0x1F, 0xC1, 0x1F, 0xC2, 0x1F, 0xC3, 0x1F,
510 0xC4, 0x1F, 0xC5, 0x1F, 0xC6, 0x1F, 0xC7, 0x1F,
511 0xC8, 0x1F, 0xC9, 0x1F, 0xCA, 0x1F, 0xCB, 0x1F,
512 0xC3, 0x1F, 0xCD, 0x1F, 0xCE, 0x1F, 0xCF, 0x1F,
513 0xD8, 0x1F, 0xD9, 0x1F, 0xD2, 0x1F, 0xD3, 0x1F,
514 0xD4, 0x1F, 0xD5, 0x1F, 0xD6, 0x1F, 0xD7, 0x1F,
515 0xD8, 0x1F, 0xD9, 0x1F, 0xDA, 0x1F, 0xDB, 0x1F,
516 0xDC, 0x1F, 0xDD, 0x1F, 0xDE, 0x1F, 0xDF, 0x1F,
517 0xE8, 0x1F, 0xE9, 0x1F, 0xE2, 0x1F, 0xE3, 0x1F,
518 0xE4, 0x1F, 0xEC, 0x1F, 0xE6, 0x1F, 0xE7, 0x1F,
519 0xE8, 0x1F, 0xE9, 0x1F, 0xEA, 0x1F, 0xEB, 0x1F,
520 0xEC, 0x1F, 0xED, 0x1F, 0xEE, 0x1F, 0xEF, 0x1F,
521 0xF0, 0x1F, 0xF1, 0x1F, 0xF2, 0x1F, 0xF3, 0x1F,
522 0xF4, 0x1F, 0xF5, 0x1F, 0xF6, 0x1F, 0xF7, 0x1F,
523 0xF8, 0x1F, 0xF9, 0x1F, 0xFA, 0x1F, 0xFB, 0x1F,
524 0xF3, 0x1F, 0xFD, 0x1F, 0xFE, 0x1F, 0xFF, 0x1F,
525 0x00, 0x20, 0x01, 0x20, 0x02, 0x20, 0x03, 0x20,
526 0x04, 0x20, 0x05, 0x20, 0x06, 0x20, 0x07, 0x20,
527 0x08, 0x20, 0x09, 0x20, 0x0A, 0x20, 0x0B, 0x20,
528 0x0C, 0x20, 0x0D, 0x20, 0x0E, 0x20, 0x0F, 0x20,
529 0x10, 0x20, 0x11, 0x20, 0x12, 0x20, 0x13, 0x20,
530 0x14, 0x20, 0x15, 0x20, 0x16, 0x20, 0x17, 0x20,
531 0x18, 0x20, 0x19, 0x20, 0x1A, 0x20, 0x1B, 0x20,
532 0x1C, 0x20, 0x1D, 0x20, 0x1E, 0x20, 0x1F, 0x20,
533 0x20, 0x20, 0x21, 0x20, 0x22, 0x20, 0x23, 0x20,
534 0x24, 0x20, 0x25, 0x20, 0x26, 0x20, 0x27, 0x20,
535 0x28, 0x20, 0x29, 0x20, 0x2A, 0x20, 0x2B, 0x20,
536 0x2C, 0x20, 0x2D, 0x20, 0x2E, 0x20, 0x2F, 0x20,
537 0x30, 0x20, 0x31, 0x20, 0x32, 0x20, 0x33, 0x20,
538 0x34, 0x20, 0x35, 0x20, 0x36, 0x20, 0x37, 0x20,
539 0x38, 0x20, 0x39, 0x20, 0x3A, 0x20, 0x3B, 0x20,
540 0x3C, 0x20, 0x3D, 0x20, 0x3E, 0x20, 0x3F, 0x20,
541 0x40, 0x20, 0x41, 0x20, 0x42, 0x20, 0x43, 0x20,
542 0x44, 0x20, 0x45, 0x20, 0x46, 0x20, 0x47, 0x20,
543 0x48, 0x20, 0x49, 0x20, 0x4A, 0x20, 0x4B, 0x20,
544 0x4C, 0x20, 0x4D, 0x20, 0x4E, 0x20, 0x4F, 0x20,
545 0x50, 0x20, 0x51, 0x20, 0x52, 0x20, 0x53, 0x20,
546 0x54, 0x20, 0x55, 0x20, 0x56, 0x20, 0x57, 0x20,
547 0x58, 0x20, 0x59, 0x20, 0x5A, 0x20, 0x5B, 0x20,
548 0x5C, 0x20, 0x5D, 0x20, 0x5E, 0x20, 0x5F, 0x20,
549 0x60, 0x20, 0x61, 0x20, 0x62, 0x20, 0x63, 0x20,
550 0x64, 0x20, 0x65, 0x20, 0x66, 0x20, 0x67, 0x20,
551 0x68, 0x20, 0x69, 0x20, 0x6A, 0x20, 0x6B, 0x20,
552 0x6C, 0x20, 0x6D, 0x20, 0x6E, 0x20, 0x6F, 0x20,
553 0x70, 0x20, 0x71, 0x20, 0x72, 0x20, 0x73, 0x20,
554 0x74, 0x20, 0x75, 0x20, 0x76, 0x20, 0x77, 0x20,
555 0x78, 0x20, 0x79, 0x20, 0x7A, 0x20, 0x7B, 0x20,
556 0x7C, 0x20, 0x7D, 0x20, 0x7E, 0x20, 0x7F, 0x20,
557 0x80, 0x20, 0x81, 0x20, 0x82, 0x20, 0x83, 0x20,
558 0x84, 0x20, 0x85, 0x20, 0x86, 0x20, 0x87, 0x20,
559 0x88, 0x20, 0x89, 0x20, 0x8A, 0x20, 0x8B, 0x20,
560 0x8C, 0x20, 0x8D, 0x20, 0x8E, 0x20, 0x8F, 0x20,
561 0x90, 0x20, 0x91, 0x20, 0x92, 0x20, 0x93, 0x20,
562 0x94, 0x20, 0x95, 0x20, 0x96, 0x20, 0x97, 0x20,
563 0x98, 0x20, 0x99, 0x20, 0x9A, 0x20, 0x9B, 0x20,
564 0x9C, 0x20, 0x9D, 0x20, 0x9E, 0x20, 0x9F, 0x20,
565 0xA0, 0x20, 0xA1, 0x20, 0xA2, 0x20, 0xA3, 0x20,
566 0xA4, 0x20, 0xA5, 0x20, 0xA6, 0x20, 0xA7, 0x20,
567 0xA8, 0x20, 0xA9, 0x20, 0xAA, 0x20, 0xAB, 0x20,
568 0xAC, 0x20, 0xAD, 0x20, 0xAE, 0x20, 0xAF, 0x20,
569 0xB0, 0x20, 0xB1, 0x20, 0xB2, 0x20, 0xB3, 0x20,
570 0xB4, 0x20, 0xB5, 0x20, 0xB6, 0x20, 0xB7, 0x20,
571 0xB8, 0x20, 0xB9, 0x20, 0xBA, 0x20, 0xBB, 0x20,
572 0xBC, 0x20, 0xBD, 0x20, 0xBE, 0x20, 0xBF, 0x20,
573 0xC0, 0x20, 0xC1, 0x20, 0xC2, 0x20, 0xC3, 0x20,
574 0xC4, 0x20, 0xC5, 0x20, 0xC6, 0x20, 0xC7, 0x20,
575 0xC8, 0x20, 0xC9, 0x20, 0xCA, 0x20, 0xCB, 0x20,
576 0xCC, 0x20, 0xCD, 0x20, 0xCE, 0x20, 0xCF, 0x20,
577 0xD0, 0x20, 0xD1, 0x20, 0xD2, 0x20, 0xD3, 0x20,
578 0xD4, 0x20, 0xD5, 0x20, 0xD6, 0x20, 0xD7, 0x20,
579 0xD8, 0x20, 0xD9, 0x20, 0xDA, 0x20, 0xDB, 0x20,
580 0xDC, 0x20, 0xDD, 0x20, 0xDE, 0x20, 0xDF, 0x20,
581 0xE0, 0x20, 0xE1, 0x20, 0xE2, 0x20, 0xE3, 0x20,
582 0xE4, 0x20, 0xE5, 0x20, 0xE6, 0x20, 0xE7, 0x20,
583 0xE8, 0x20, 0xE9, 0x20, 0xEA, 0x20, 0xEB, 0x20,
584 0xEC, 0x20, 0xED, 0x20, 0xEE, 0x20, 0xEF, 0x20,
585 0xF0, 0x20, 0xF1, 0x20, 0xF2, 0x20, 0xF3, 0x20,
586 0xF4, 0x20, 0xF5, 0x20, 0xF6, 0x20, 0xF7, 0x20,
587 0xF8, 0x20, 0xF9, 0x20, 0xFA, 0x20, 0xFB, 0x20,
588 0xFC, 0x20, 0xFD, 0x20, 0xFE, 0x20, 0xFF, 0x20,
589 0x00, 0x21, 0x01, 0x21, 0x02, 0x21, 0x03, 0x21,
590 0x04, 0x21, 0x05, 0x21, 0x06, 0x21, 0x07, 0x21,
591 0x08, 0x21, 0x09, 0x21, 0x0A, 0x21, 0x0B, 0x21,
592 0x0C, 0x21, 0x0D, 0x21, 0x0E, 0x21, 0x0F, 0x21,
593 0x10, 0x21, 0x11, 0x21, 0x12, 0x21, 0x13, 0x21,
594 0x14, 0x21, 0x15, 0x21, 0x16, 0x21, 0x17, 0x21,
595 0x18, 0x21, 0x19, 0x21, 0x1A, 0x21, 0x1B, 0x21,
596 0x1C, 0x21, 0x1D, 0x21, 0x1E, 0x21, 0x1F, 0x21,
597 0x20, 0x21, 0x21, 0x21, 0x22, 0x21, 0x23, 0x21,
598 0x24, 0x21, 0x25, 0x21, 0x26, 0x21, 0x27, 0x21,
599 0x28, 0x21, 0x29, 0x21, 0x2A, 0x21, 0x2B, 0x21,
600 0x2C, 0x21, 0x2D, 0x21, 0x2E, 0x21, 0x2F, 0x21,
601 0x30, 0x21, 0x31, 0x21, 0x32, 0x21, 0x33, 0x21,
602 0x34, 0x21, 0x35, 0x21, 0x36, 0x21, 0x37, 0x21,
603 0x38, 0x21, 0x39, 0x21, 0x3A, 0x21, 0x3B, 0x21,
604 0x3C, 0x21, 0x3D, 0x21, 0x3E, 0x21, 0x3F, 0x21,
605 0x40, 0x21, 0x41, 0x21, 0x42, 0x21, 0x43, 0x21,
606 0x44, 0x21, 0x45, 0x21, 0x46, 0x21, 0x47, 0x21,
607 0x48, 0x21, 0x49, 0x21, 0x4A, 0x21, 0x4B, 0x21,
608 0x4C, 0x21, 0x4D, 0x21, 0x32, 0x21, 0x4F, 0x21,
609 0x50, 0x21, 0x51, 0x21, 0x52, 0x21, 0x53, 0x21,
610 0x54, 0x21, 0x55, 0x21, 0x56, 0x21, 0x57, 0x21,
611 0x58, 0x21, 0x59, 0x21, 0x5A, 0x21, 0x5B, 0x21,
612 0x5C, 0x21, 0x5D, 0x21, 0x5E, 0x21, 0x5F, 0x21,
613 0x60, 0x21, 0x61, 0x21, 0x62, 0x21, 0x63, 0x21,
614 0x64, 0x21, 0x65, 0x21, 0x66, 0x21, 0x67, 0x21,
615 0x68, 0x21, 0x69, 0x21, 0x6A, 0x21, 0x6B, 0x21,
616 0x6C, 0x21, 0x6D, 0x21, 0x6E, 0x21, 0x6F, 0x21,
617 0x60, 0x21, 0x61, 0x21, 0x62, 0x21, 0x63, 0x21,
618 0x64, 0x21, 0x65, 0x21, 0x66, 0x21, 0x67, 0x21,
619 0x68, 0x21, 0x69, 0x21, 0x6A, 0x21, 0x6B, 0x21,
620 0x6C, 0x21, 0x6D, 0x21, 0x6E, 0x21, 0x6F, 0x21,
621 0x80, 0x21, 0x81, 0x21, 0x82, 0x21, 0x83, 0x21,
622 0x83, 0x21, 0xFF, 0xFF, 0x4B, 0x03, 0xB6, 0x24,
623 0xB7, 0x24, 0xB8, 0x24, 0xB9, 0x24, 0xBA, 0x24,
624 0xBB, 0x24, 0xBC, 0x24, 0xBD, 0x24, 0xBE, 0x24,
625 0xBF, 0x24, 0xC0, 0x24, 0xC1, 0x24, 0xC2, 0x24,
626 0xC3, 0x24, 0xC4, 0x24, 0xC5, 0x24, 0xC6, 0x24,
627 0xC7, 0x24, 0xC8, 0x24, 0xC9, 0x24, 0xCA, 0x24,
628 0xCB, 0x24, 0xCC, 0x24, 0xCD, 0x24, 0xCE, 0x24,
629 0xCF, 0x24, 0xFF, 0xFF, 0x46, 0x07, 0x00, 0x2C,
630 0x01, 0x2C, 0x02, 0x2C, 0x03, 0x2C, 0x04, 0x2C,
631 0x05, 0x2C, 0x06, 0x2C, 0x07, 0x2C, 0x08, 0x2C,
632 0x09, 0x2C, 0x0A, 0x2C, 0x0B, 0x2C, 0x0C, 0x2C,
633 0x0D, 0x2C, 0x0E, 0x2C, 0x0F, 0x2C, 0x10, 0x2C,
634 0x11, 0x2C, 0x12, 0x2C, 0x13, 0x2C, 0x14, 0x2C,
635 0x15, 0x2C, 0x16, 0x2C, 0x17, 0x2C, 0x18, 0x2C,
636 0x19, 0x2C, 0x1A, 0x2C, 0x1B, 0x2C, 0x1C, 0x2C,
637 0x1D, 0x2C, 0x1E, 0x2C, 0x1F, 0x2C, 0x20, 0x2C,
638 0x21, 0x2C, 0x22, 0x2C, 0x23, 0x2C, 0x24, 0x2C,
639 0x25, 0x2C, 0x26, 0x2C, 0x27, 0x2C, 0x28, 0x2C,
640 0x29, 0x2C, 0x2A, 0x2C, 0x2B, 0x2C, 0x2C, 0x2C,
641 0x2D, 0x2C, 0x2E, 0x2C, 0x5F, 0x2C, 0x60, 0x2C,
642 0x60, 0x2C, 0x62, 0x2C, 0x63, 0x2C, 0x64, 0x2C,
643 0x65, 0x2C, 0x66, 0x2C, 0x67, 0x2C, 0x67, 0x2C,
644 0x69, 0x2C, 0x69, 0x2C, 0x6B, 0x2C, 0x6B, 0x2C,
645 0x6D, 0x2C, 0x6E, 0x2C, 0x6F, 0x2C, 0x70, 0x2C,
646 0x71, 0x2C, 0x72, 0x2C, 0x73, 0x2C, 0x74, 0x2C,
647 0x75, 0x2C, 0x75, 0x2C, 0x77, 0x2C, 0x78, 0x2C,
648 0x79, 0x2C, 0x7A, 0x2C, 0x7B, 0x2C, 0x7C, 0x2C,
649 0x7D, 0x2C, 0x7E, 0x2C, 0x7F, 0x2C, 0x80, 0x2C,
650 0x80, 0x2C, 0x82, 0x2C, 0x82, 0x2C, 0x84, 0x2C,
651 0x84, 0x2C, 0x86, 0x2C, 0x86, 0x2C, 0x88, 0x2C,
652 0x88, 0x2C, 0x8A, 0x2C, 0x8A, 0x2C, 0x8C, 0x2C,
653 0x8C, 0x2C, 0x8E, 0x2C, 0x8E, 0x2C, 0x90, 0x2C,
654 0x90, 0x2C, 0x92, 0x2C, 0x92, 0x2C, 0x94, 0x2C,
655 0x94, 0x2C, 0x96, 0x2C, 0x96, 0x2C, 0x98, 0x2C,
656 0x98, 0x2C, 0x9A, 0x2C, 0x9A, 0x2C, 0x9C, 0x2C,
657 0x9C, 0x2C, 0x9E, 0x2C, 0x9E, 0x2C, 0xA0, 0x2C,
658 0xA0, 0x2C, 0xA2, 0x2C, 0xA2, 0x2C, 0xA4, 0x2C,
659 0xA4, 0x2C, 0xA6, 0x2C, 0xA6, 0x2C, 0xA8, 0x2C,
660 0xA8, 0x2C, 0xAA, 0x2C, 0xAA, 0x2C, 0xAC, 0x2C,
661 0xAC, 0x2C, 0xAE, 0x2C, 0xAE, 0x2C, 0xB0, 0x2C,
662 0xB0, 0x2C, 0xB2, 0x2C, 0xB2, 0x2C, 0xB4, 0x2C,
663 0xB4, 0x2C, 0xB6, 0x2C, 0xB6, 0x2C, 0xB8, 0x2C,
664 0xB8, 0x2C, 0xBA, 0x2C, 0xBA, 0x2C, 0xBC, 0x2C,
665 0xBC, 0x2C, 0xBE, 0x2C, 0xBE, 0x2C, 0xC0, 0x2C,
666 0xC0, 0x2C, 0xC2, 0x2C, 0xC2, 0x2C, 0xC4, 0x2C,
667 0xC4, 0x2C, 0xC6, 0x2C, 0xC6, 0x2C, 0xC8, 0x2C,
668 0xC8, 0x2C, 0xCA, 0x2C, 0xCA, 0x2C, 0xCC, 0x2C,
669 0xCC, 0x2C, 0xCE, 0x2C, 0xCE, 0x2C, 0xD0, 0x2C,
670 0xD0, 0x2C, 0xD2, 0x2C, 0xD2, 0x2C, 0xD4, 0x2C,
671 0xD4, 0x2C, 0xD6, 0x2C, 0xD6, 0x2C, 0xD8, 0x2C,
672 0xD8, 0x2C, 0xDA, 0x2C, 0xDA, 0x2C, 0xDC, 0x2C,
673 0xDC, 0x2C, 0xDE, 0x2C, 0xDE, 0x2C, 0xE0, 0x2C,
674 0xE0, 0x2C, 0xE2, 0x2C, 0xE2, 0x2C, 0xE4, 0x2C,
675 0xE5, 0x2C, 0xE6, 0x2C, 0xE7, 0x2C, 0xE8, 0x2C,
676 0xE9, 0x2C, 0xEA, 0x2C, 0xEB, 0x2C, 0xEC, 0x2C,
677 0xED, 0x2C, 0xEE, 0x2C, 0xEF, 0x2C, 0xF0, 0x2C,
678 0xF1, 0x2C, 0xF2, 0x2C, 0xF3, 0x2C, 0xF4, 0x2C,
679 0xF5, 0x2C, 0xF6, 0x2C, 0xF7, 0x2C, 0xF8, 0x2C,
680 0xF9, 0x2C, 0xFA, 0x2C, 0xFB, 0x2C, 0xFC, 0x2C,
681 0xFD, 0x2C, 0xFE, 0x2C, 0xFF, 0x2C, 0xA0, 0x10,
682 0xA1, 0x10, 0xA2, 0x10, 0xA3, 0x10, 0xA4, 0x10,
683 0xA5, 0x10, 0xA6, 0x10, 0xA7, 0x10, 0xA8, 0x10,
684 0xA9, 0x10, 0xAA, 0x10, 0xAB, 0x10, 0xAC, 0x10,
685 0xAD, 0x10, 0xAE, 0x10, 0xAF, 0x10, 0xB0, 0x10,
686 0xB1, 0x10, 0xB2, 0x10, 0xB3, 0x10, 0xB4, 0x10,
687 0xB5, 0x10, 0xB6, 0x10, 0xB7, 0x10, 0xB8, 0x10,
688 0xB9, 0x10, 0xBA, 0x10, 0xBB, 0x10, 0xBC, 0x10,
689 0xBD, 0x10, 0xBE, 0x10, 0xBF, 0x10, 0xC0, 0x10,
690 0xC1, 0x10, 0xC2, 0x10, 0xC3, 0x10, 0xC4, 0x10,
691 0xC5, 0x10, 0xFF, 0xFF, 0x1B, 0xD2, 0x21, 0xFF,
692 0x22, 0xFF, 0x23, 0xFF, 0x24, 0xFF, 0x25, 0xFF,
693 0x26, 0xFF, 0x27, 0xFF, 0x28, 0xFF, 0x29, 0xFF,
694 0x2A, 0xFF, 0x2B, 0xFF, 0x2C, 0xFF, 0x2D, 0xFF,
695 0x2E, 0xFF, 0x2F, 0xFF, 0x30, 0xFF, 0x31, 0xFF,
696 0x32, 0xFF, 0x33, 0xFF, 0x34, 0xFF, 0x35, 0xFF,
697 0x36, 0xFF, 0x37, 0xFF, 0x38, 0xFF, 0x39, 0xFF,
698 0x3A, 0xFF, 0x5B, 0xFF, 0x5C, 0xFF, 0x5D, 0xFF,
699 0x5E, 0xFF, 0x5F, 0xFF, 0x60, 0xFF, 0x61, 0xFF,
700 0x62, 0xFF, 0x63, 0xFF, 0x64, 0xFF, 0x65, 0xFF,
701 0x66, 0xFF, 0x67, 0xFF, 0x68, 0xFF, 0x69, 0xFF,
702 0x6A, 0xFF, 0x6B, 0xFF, 0x6C, 0xFF, 0x6D, 0xFF,
703 0x6E, 0xFF, 0x6F, 0xFF, 0x70, 0xFF, 0x71, 0xFF,
704 0x72, 0xFF, 0x73, 0xFF, 0x74, 0xFF, 0x75, 0xFF,
705 0x76, 0xFF, 0x77, 0xFF, 0x78, 0xFF, 0x79, 0xFF,
706 0x7A, 0xFF, 0x7B, 0xFF, 0x7C, 0xFF, 0x7D, 0xFF,
707 0x7E, 0xFF, 0x7F, 0xFF, 0x80, 0xFF, 0x81, 0xFF,
708 0x82, 0xFF, 0x83, 0xFF, 0x84, 0xFF, 0x85, 0xFF,
709 0x86, 0xFF, 0x87, 0xFF, 0x88, 0xFF, 0x89, 0xFF,
710 0x8A, 0xFF, 0x8B, 0xFF, 0x8C, 0xFF, 0x8D, 0xFF,
711 0x8E, 0xFF, 0x8F, 0xFF, 0x90, 0xFF, 0x91, 0xFF,
712 0x92, 0xFF, 0x93, 0xFF, 0x94, 0xFF, 0x95, 0xFF,
713 0x96, 0xFF, 0x97, 0xFF, 0x98, 0xFF, 0x99, 0xFF,
714 0x9A, 0xFF, 0x9B, 0xFF, 0x9C, 0xFF, 0x9D, 0xFF,
715 0x9E, 0xFF, 0x9F, 0xFF, 0xA0, 0xFF, 0xA1, 0xFF,
716 0xA2, 0xFF, 0xA3, 0xFF, 0xA4, 0xFF, 0xA5, 0xFF,
717 0xA6, 0xFF, 0xA7, 0xFF, 0xA8, 0xFF, 0xA9, 0xFF,
718 0xAA, 0xFF, 0xAB, 0xFF, 0xAC, 0xFF, 0xAD, 0xFF,
719 0xAE, 0xFF, 0xAF, 0xFF, 0xB0, 0xFF, 0xB1, 0xFF,
720 0xB2, 0xFF, 0xB3, 0xFF, 0xB4, 0xFF, 0xB5, 0xFF,
721 0xB6, 0xFF, 0xB7, 0xFF, 0xB8, 0xFF, 0xB9, 0xFF,
722 0xBA, 0xFF, 0xBB, 0xFF, 0xBC, 0xFF, 0xBD, 0xFF,
723 0xBE, 0xFF, 0xBF, 0xFF, 0xC0, 0xFF, 0xC1, 0xFF,
724 0xC2, 0xFF, 0xC3, 0xFF, 0xC4, 0xFF, 0xC5, 0xFF,
725 0xC6, 0xFF, 0xC7, 0xFF, 0xC8, 0xFF, 0xC9, 0xFF,
726 0xCA, 0xFF, 0xCB, 0xFF, 0xCC, 0xFF, 0xCD, 0xFF,
727 0xCE, 0xFF, 0xCF, 0xFF, 0xD0, 0xFF, 0xD1, 0xFF,
728 0xD2, 0xFF, 0xD3, 0xFF, 0xD4, 0xFF, 0xD5, 0xFF,
729 0xD6, 0xFF, 0xD7, 0xFF, 0xD8, 0xFF, 0xD9, 0xFF,
730 0xDA, 0xFF, 0xDB, 0xFF, 0xDC, 0xFF, 0xDD, 0xFF,
731 0xDE, 0xFF, 0xDF, 0xFF, 0xE0, 0xFF, 0xE1, 0xFF,
732 0xE2, 0xFF, 0xE3, 0xFF, 0xE4, 0xFF, 0xE5, 0xFF,
733 0xE6, 0xFF, 0xE7, 0xFF, 0xE8, 0xFF, 0xE9, 0xFF,
734 0xEA, 0xFF, 0xEB, 0xFF, 0xEC, 0xFF, 0xED, 0xFF,
735 0xEE, 0xFF, 0xEF, 0xFF, 0xF0, 0xFF, 0xF1, 0xFF,
736 0xF2, 0xFF, 0xF3, 0xFF, 0xF4, 0xFF, 0xF5, 0xFF,
737 0xF6, 0xFF, 0xF7, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF,
738 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD, 0xFF,
739 0xFE, 0xFF, 0xFF, 0xFF
740};
diff --git a/drivers/staging/fbtft/fb_hx8340bn.c b/drivers/staging/fbtft/fb_hx8340bn.c
index d47dcf31fffb..2fd7b87ea0ce 100644
--- a/drivers/staging/fbtft/fb_hx8340bn.c
+++ b/drivers/staging/fbtft/fb_hx8340bn.c
@@ -151,7 +151,7 @@ static int set_var(struct fbtft_par *par)
151#define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)] 151#define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)]
152static int set_gamma(struct fbtft_par *par, u32 *curves) 152static int set_gamma(struct fbtft_par *par, u32 *curves)
153{ 153{
154 unsigned long mask[] = { 154 static const unsigned long mask[] = {
155 0x0f, 0x0f, 0x1f, 0x0f, 0x0f, 0x0f, 0x1f, 0x07, 0x07, 0x07, 155 0x0f, 0x0f, 0x1f, 0x0f, 0x0f, 0x0f, 0x1f, 0x07, 0x07, 0x07,
156 0x07, 0x07, 0x07, 0x03, 0x03, 0x0f, 0x0f, 0x1f, 0x0f, 0x0f, 156 0x07, 0x07, 0x07, 0x03, 0x03, 0x0f, 0x0f, 0x1f, 0x0f, 0x0f,
157 0x0f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x00, 157 0x0f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x00,
diff --git a/drivers/staging/fbtft/fb_hx8347d.c b/drivers/staging/fbtft/fb_hx8347d.c
index 3427a858d17c..37eaf0862c5b 100644
--- a/drivers/staging/fbtft/fb_hx8347d.c
+++ b/drivers/staging/fbtft/fb_hx8347d.c
@@ -95,7 +95,7 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
95#define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)] 95#define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)]
96static int set_gamma(struct fbtft_par *par, u32 *curves) 96static int set_gamma(struct fbtft_par *par, u32 *curves)
97{ 97{
98 unsigned long mask[] = { 98 static const unsigned long mask[] = {
99 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x7f, 0x7f, 0x1f, 0x1f, 99 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x7f, 0x7f, 0x1f, 0x1f,
100 0x1f, 0x1f, 0x1f, 0x0f, 100 0x1f, 0x1f, 0x1f, 0x0f,
101 }; 101 };
diff --git a/drivers/staging/fbtft/fb_ili9163.c b/drivers/staging/fbtft/fb_ili9163.c
index fd32376700e2..05648c3ffe47 100644
--- a/drivers/staging/fbtft/fb_ili9163.c
+++ b/drivers/staging/fbtft/fb_ili9163.c
@@ -195,7 +195,7 @@ static int set_var(struct fbtft_par *par)
195#define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)] 195#define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)]
196static int gamma_adj(struct fbtft_par *par, u32 *curves) 196static int gamma_adj(struct fbtft_par *par, u32 *curves)
197{ 197{
198 unsigned long mask[] = { 198 static const unsigned long mask[] = {
199 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 199 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
200 0x1f, 0x3f, 0x0f, 0x0f, 0x7f, 0x1f, 200 0x1f, 0x3f, 0x0f, 0x0f, 0x7f, 0x1f,
201 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}; 201 0x3F, 0x3F, 0x3F, 0x3F, 0x3F};
diff --git a/drivers/staging/fbtft/fb_ili9320.c b/drivers/staging/fbtft/fb_ili9320.c
index ea6e001288ce..f2e72d14431d 100644
--- a/drivers/staging/fbtft/fb_ili9320.c
+++ b/drivers/staging/fbtft/fb_ili9320.c
@@ -214,7 +214,7 @@ static int set_var(struct fbtft_par *par)
214#define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)] 214#define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)]
215static int set_gamma(struct fbtft_par *par, u32 *curves) 215static int set_gamma(struct fbtft_par *par, u32 *curves)
216{ 216{
217 unsigned long mask[] = { 217 static const unsigned long mask[] = {
218 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 218 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
219 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 219 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
220 }; 220 };
diff --git a/drivers/staging/fbtft/fb_ili9325.c b/drivers/staging/fbtft/fb_ili9325.c
index 85e54a10ed72..c9aa4cb43123 100644
--- a/drivers/staging/fbtft/fb_ili9325.c
+++ b/drivers/staging/fbtft/fb_ili9325.c
@@ -208,7 +208,7 @@ static int set_var(struct fbtft_par *par)
208#define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)] 208#define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)]
209static int set_gamma(struct fbtft_par *par, u32 *curves) 209static int set_gamma(struct fbtft_par *par, u32 *curves)
210{ 210{
211 unsigned long mask[] = { 211 static const unsigned long mask[] = {
212 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 212 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
213 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 213 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
214 }; 214 };
diff --git a/drivers/staging/fbtft/fb_pcd8544.c b/drivers/staging/fbtft/fb_pcd8544.c
index ad49973ad594..08f8a4bb8772 100644
--- a/drivers/staging/fbtft/fb_pcd8544.c
+++ b/drivers/staging/fbtft/fb_pcd8544.c
@@ -157,10 +157,10 @@ static struct fbtft_display display = {
157 .backlight = 1, 157 .backlight = 1,
158}; 158};
159 159
160FBTFT_REGISTER_DRIVER(DRVNAME, "philips,pdc8544", &display); 160FBTFT_REGISTER_DRIVER(DRVNAME, "philips,pcd8544", &display);
161 161
162MODULE_ALIAS("spi:" DRVNAME); 162MODULE_ALIAS("spi:" DRVNAME);
163MODULE_ALIAS("spi:pdc8544"); 163MODULE_ALIAS("spi:pcd8544");
164 164
165MODULE_DESCRIPTION("FB driver for the PCD8544 LCD Controller"); 165MODULE_DESCRIPTION("FB driver for the PCD8544 LCD Controller");
166MODULE_AUTHOR("Noralf Tronnes"); 166MODULE_AUTHOR("Noralf Tronnes");
diff --git a/drivers/staging/fbtft/fb_s6d1121.c b/drivers/staging/fbtft/fb_s6d1121.c
index 5a129b1352cc..8c7de3290343 100644
--- a/drivers/staging/fbtft/fb_s6d1121.c
+++ b/drivers/staging/fbtft/fb_s6d1121.c
@@ -123,7 +123,7 @@ static int set_var(struct fbtft_par *par)
123#define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)] 123#define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)]
124static int set_gamma(struct fbtft_par *par, u32 *curves) 124static int set_gamma(struct fbtft_par *par, u32 *curves)
125{ 125{
126 unsigned long mask[] = { 126 static const unsigned long mask[] = {
127 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 127 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
128 0x3f, 0x3f, 0x1f, 0x1f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 128 0x3f, 0x3f, 0x1f, 0x1f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
129 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 129 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f,
diff --git a/drivers/staging/fbtft/fb_ssd1289.c b/drivers/staging/fbtft/fb_ssd1289.c
index 88a5b6925901..7a3fe022cc69 100644
--- a/drivers/staging/fbtft/fb_ssd1289.c
+++ b/drivers/staging/fbtft/fb_ssd1289.c
@@ -129,7 +129,7 @@ static int set_var(struct fbtft_par *par)
129#define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)] 129#define CURVE(num, idx) curves[(num) * par->gamma.num_values + (idx)]
130static int set_gamma(struct fbtft_par *par, u32 *curves) 130static int set_gamma(struct fbtft_par *par, u32 *curves)
131{ 131{
132 unsigned long mask[] = { 132 static const unsigned long mask[] = {
133 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 133 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
134 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 134 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
135 }; 135 };
diff --git a/Documentation/devicetree/bindings/fieldbus/arcx,anybus-controller.txt b/drivers/staging/fieldbus/Documentation/devicetree/bindings/fieldbus/arcx,anybus-controller.txt
index b1f9474f36d5..b1f9474f36d5 100644
--- a/Documentation/devicetree/bindings/fieldbus/arcx,anybus-controller.txt
+++ b/drivers/staging/fieldbus/Documentation/devicetree/bindings/fieldbus/arcx,anybus-controller.txt
diff --git a/drivers/staging/fsl-dpaa2/ethsw/TODO b/drivers/staging/fsl-dpaa2/ethsw/TODO
index 24b5e95a96f8..4d46857b0b2b 100644
--- a/drivers/staging/fsl-dpaa2/ethsw/TODO
+++ b/drivers/staging/fsl-dpaa2/ethsw/TODO
@@ -1,7 +1,6 @@
1* Add I/O capabilities on switch port netdevices. This will allow control 1* Add I/O capabilities on switch port netdevices. This will allow control
2traffic to reach the CPU. 2traffic to reach the CPU.
3* Add ACL to redirect control traffic to CPU. 3* Add ACL to redirect control traffic to CPU.
4* Add support for displaying learned FDB entries
5* Add support for multiple FDBs and switch port partitioning 4* Add support for multiple FDBs and switch port partitioning
6* MC firmware uprev; the DPAA2 objects used by the Ethernet Switch driver 5* MC firmware uprev; the DPAA2 objects used by the Ethernet Switch driver
7need to be kept in sync with binary interface changes in MC 6need to be kept in sync with binary interface changes in MC
diff --git a/drivers/staging/fsl-dpaa2/ethsw/dpsw-cmd.h b/drivers/staging/fsl-dpaa2/ethsw/dpsw-cmd.h
index 14b974defa3a..5e1339daa7c7 100644
--- a/drivers/staging/fsl-dpaa2/ethsw/dpsw-cmd.h
+++ b/drivers/staging/fsl-dpaa2/ethsw/dpsw-cmd.h
@@ -10,7 +10,7 @@
10 10
11/* DPSW Version */ 11/* DPSW Version */
12#define DPSW_VER_MAJOR 8 12#define DPSW_VER_MAJOR 8
13#define DPSW_VER_MINOR 0 13#define DPSW_VER_MINOR 1
14 14
15#define DPSW_CMD_BASE_VERSION 1 15#define DPSW_CMD_BASE_VERSION 1
16#define DPSW_CMD_ID_OFFSET 4 16#define DPSW_CMD_ID_OFFSET 4
@@ -67,6 +67,7 @@
67#define DPSW_CMDID_FDB_ADD_MULTICAST DPSW_CMD_ID(0x086) 67#define DPSW_CMDID_FDB_ADD_MULTICAST DPSW_CMD_ID(0x086)
68#define DPSW_CMDID_FDB_REMOVE_MULTICAST DPSW_CMD_ID(0x087) 68#define DPSW_CMDID_FDB_REMOVE_MULTICAST DPSW_CMD_ID(0x087)
69#define DPSW_CMDID_FDB_SET_LEARNING_MODE DPSW_CMD_ID(0x088) 69#define DPSW_CMDID_FDB_SET_LEARNING_MODE DPSW_CMD_ID(0x088)
70#define DPSW_CMDID_FDB_DUMP DPSW_CMD_ID(0x08A)
70 71
71/* Macros for accessing command fields smaller than 1byte */ 72/* Macros for accessing command fields smaller than 1byte */
72#define DPSW_MASK(field) \ 73#define DPSW_MASK(field) \
@@ -351,6 +352,18 @@ struct dpsw_cmd_fdb_set_learning_mode {
351 u8 mode; 352 u8 mode;
352}; 353};
353 354
355struct dpsw_cmd_fdb_dump {
356 __le16 fdb_id;
357 __le16 pad0;
358 __le32 pad1;
359 __le64 iova_addr;
360 __le32 iova_size;
361};
362
363struct dpsw_rsp_fdb_dump {
364 __le16 num_entries;
365};
366
354struct dpsw_rsp_get_api_version { 367struct dpsw_rsp_get_api_version {
355 __le16 version_major; 368 __le16 version_major;
356 __le16 version_minor; 369 __le16 version_minor;
diff --git a/drivers/staging/fsl-dpaa2/ethsw/dpsw.c b/drivers/staging/fsl-dpaa2/ethsw/dpsw.c
index cabed77b445d..56b0fa789a67 100644
--- a/drivers/staging/fsl-dpaa2/ethsw/dpsw.c
+++ b/drivers/staging/fsl-dpaa2/ethsw/dpsw.c
@@ -981,6 +981,57 @@ int dpsw_fdb_add_unicast(struct fsl_mc_io *mc_io,
981} 981}
982 982
983/** 983/**
984 * dpsw_fdb_dump() - Dump the content of FDB table into memory.
985 * @mc_io: Pointer to MC portal's I/O object
986 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
987 * @token: Token of DPSW object
988 * @fdb_id: Forwarding Database Identifier
989 * @iova_addr: Data will be stored here as an array of struct fdb_dump_entry
990 * @iova_size: Memory size allocated at iova_addr
991 * @num_entries:Number of entries written at iova_addr
992 *
993 * Return: Completion status. '0' on Success; Error code otherwise.
994 *
995 * The memory allocated at iova_addr must be initialized with zero before
996 * command execution. If the FDB table does not fit into memory MC will stop
997 * after the memory is filled up.
998 * The struct fdb_dump_entry array must be parsed until the end of memory
999 * area or until an entry with mac_addr set to zero is found.
1000 */
1001int dpsw_fdb_dump(struct fsl_mc_io *mc_io,
1002 u32 cmd_flags,
1003 u16 token,
1004 u16 fdb_id,
1005 u64 iova_addr,
1006 u32 iova_size,
1007 u16 *num_entries)
1008{
1009 struct dpsw_cmd_fdb_dump *cmd_params;
1010 struct dpsw_rsp_fdb_dump *rsp_params;
1011 struct fsl_mc_command cmd = { 0 };
1012 int err;
1013
1014 /* prepare command */
1015 cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_DUMP,
1016 cmd_flags,
1017 token);
1018 cmd_params = (struct dpsw_cmd_fdb_dump *)cmd.params;
1019 cmd_params->fdb_id = cpu_to_le16(fdb_id);
1020 cmd_params->iova_addr = cpu_to_le64(iova_addr);
1021 cmd_params->iova_size = cpu_to_le32(iova_size);
1022
1023 /* send command to mc */
1024 err = mc_send_command(mc_io, &cmd);
1025 if (err)
1026 return err;
1027
1028 rsp_params = (struct dpsw_rsp_fdb_dump *)cmd.params;
1029 *num_entries = le16_to_cpu(rsp_params->num_entries);
1030
1031 return 0;
1032}
1033
1034/**
984 * dpsw_fdb_remove_unicast() - removes an entry from MAC lookup table 1035 * dpsw_fdb_remove_unicast() - removes an entry from MAC lookup table
985 * @mc_io: Pointer to MC portal's I/O object 1036 * @mc_io: Pointer to MC portal's I/O object
986 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1037 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
diff --git a/drivers/staging/fsl-dpaa2/ethsw/dpsw.h b/drivers/staging/fsl-dpaa2/ethsw/dpsw.h
index 25635259ce44..25b45850925c 100644
--- a/drivers/staging/fsl-dpaa2/ethsw/dpsw.h
+++ b/drivers/staging/fsl-dpaa2/ethsw/dpsw.h
@@ -75,37 +75,6 @@ enum dpsw_component_type {
75 DPSW_COMPONENT_TYPE_S_VLAN 75 DPSW_COMPONENT_TYPE_S_VLAN
76}; 76};
77 77
78/**
79 * struct dpsw_cfg - DPSW configuration
80 * @num_ifs: Number of external and internal interfaces
81 * @adv: Advanced parameters; default is all zeros;
82 * use this structure to change default settings
83 * @adv.options: Enable/Disable DPSW features (bitmap)
84 * @adv.max_vlans: Maximum Number of VLAN's; 0 - indicates default 16
85 * @adv.max_meters_per_if: Number of meters per interface
86 * @adv.max_fdbs: Maximum Number of FDB's; 0 - indicates default 16
87 * @adv.max_fdb_entries: Number of FDB entries for default FDB table;
88 * 0 - indicates default 1024 entries.
89 * @adv.fdb_aging_time: Default FDB aging time for default FDB table;
90 * 0 - indicates default 300 seconds
91 * @adv.max_fdb_mc_groups: Number of multicast groups in each FDB table;
92 * 0 - indicates default 32
93 * @adv.component_type: Indicates the component type of this bridge
94 */
95struct dpsw_cfg {
96 u16 num_ifs;
97 struct {
98 u64 options;
99 u16 max_vlans;
100 u8 max_meters_per_if;
101 u8 max_fdbs;
102 u16 max_fdb_entries;
103 u16 fdb_aging_time;
104 u16 max_fdb_mc_groups;
105 enum dpsw_component_type component_type;
106 } adv;
107};
108
109int dpsw_enable(struct fsl_mc_io *mc_io, 78int dpsw_enable(struct fsl_mc_io *mc_io,
110 u32 cmd_flags, 79 u32 cmd_flags,
111 u16 token); 80 u16 token);
@@ -496,6 +465,31 @@ int dpsw_fdb_remove_unicast(struct fsl_mc_io *mc_io,
496 u16 fdb_id, 465 u16 fdb_id,
497 const struct dpsw_fdb_unicast_cfg *cfg); 466 const struct dpsw_fdb_unicast_cfg *cfg);
498 467
468#define DPSW_FDB_ENTRY_TYPE_DYNAMIC BIT(0)
469#define DPSW_FDB_ENTRY_TYPE_UNICAST BIT(1)
470
471/**
472 * struct fdb_dump_entry - fdb snapshot entry
473 * @mac_addr: MAC address
474 * @type: bit0 - DINAMIC(1)/STATIC(0), bit1 - UNICAST(1)/MULTICAST(0)
475 * @if_info: unicast - egress interface, multicast - number of egress interfaces
476 * @if_mask: multicast - egress interface mask
477 */
478struct fdb_dump_entry {
479 u8 mac_addr[6];
480 u8 type;
481 u8 if_info;
482 u8 if_mask[8];
483};
484
485int dpsw_fdb_dump(struct fsl_mc_io *mc_io,
486 u32 cmd_flags,
487 u16 token,
488 u16 fdb_id,
489 u64 iova_addr,
490 u32 iova_size,
491 u16 *num_entries);
492
499/** 493/**
500 * struct dpsw_fdb_multicast_cfg - Multi-cast entry configuration 494 * struct dpsw_fdb_multicast_cfg - Multi-cast entry configuration
501 * @type: Select static or dynamic entry 495 * @type: Select static or dynamic entry
diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw-ethtool.c b/drivers/staging/fsl-dpaa2/ethsw/ethsw-ethtool.c
index 926a0c053e18..4f0bff86e43e 100644
--- a/drivers/staging/fsl-dpaa2/ethsw/ethsw-ethtool.c
+++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw-ethtool.c
@@ -65,7 +65,7 @@ ethsw_get_link_ksettings(struct net_device *netdev,
65 port_priv->idx, 65 port_priv->idx,
66 &state); 66 &state);
67 if (err) { 67 if (err) {
68 netdev_err(netdev, "ERROR %d getting link state", err); 68 netdev_err(netdev, "ERROR %d getting link state\n", err);
69 goto out; 69 goto out;
70 } 70 }
71 71
@@ -88,18 +88,21 @@ ethsw_set_link_ksettings(struct net_device *netdev,
88 const struct ethtool_link_ksettings *link_ksettings) 88 const struct ethtool_link_ksettings *link_ksettings)
89{ 89{
90 struct ethsw_port_priv *port_priv = netdev_priv(netdev); 90 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
91 struct ethsw_core *ethsw = port_priv->ethsw_data;
91 struct dpsw_link_cfg cfg = {0}; 92 struct dpsw_link_cfg cfg = {0};
92 int err = 0; 93 bool if_running;
93 94 int err = 0, ret;
94 netdev_dbg(netdev, "Setting link parameters..."); 95
95 96 /* Interface needs to be down to change link settings */
96 /* Due to a temporary MC limitation, the DPSW port must be down 97 if_running = netif_running(netdev);
97 * in order to be able to change link settings. Taking steps to let 98 if (if_running) {
98 * the user know that. 99 err = dpsw_if_disable(ethsw->mc_io, 0,
99 */ 100 ethsw->dpsw_handle,
100 if (netif_running(netdev)) { 101 port_priv->idx);
101 netdev_info(netdev, "Sorry, interface must be brought down first.\n"); 102 if (err) {
102 return -EACCES; 103 netdev_err(netdev, "dpsw_if_disable err %d\n", err);
104 return err;
105 }
103 } 106 }
104 107
105 cfg.rate = link_ksettings->base.speed; 108 cfg.rate = link_ksettings->base.speed;
@@ -116,12 +119,16 @@ ethsw_set_link_ksettings(struct net_device *netdev,
116 port_priv->ethsw_data->dpsw_handle, 119 port_priv->ethsw_data->dpsw_handle,
117 port_priv->idx, 120 port_priv->idx,
118 &cfg); 121 &cfg);
119 if (err)
120 /* ethtool will be loud enough if we return an error; no point
121 * in putting our own error message on the console by default
122 */
123 netdev_dbg(netdev, "ERROR %d setting link cfg", err);
124 122
123 if (if_running) {
124 ret = dpsw_if_enable(ethsw->mc_io, 0,
125 ethsw->dpsw_handle,
126 port_priv->idx);
127 if (ret) {
128 netdev_err(netdev, "dpsw_if_enable err %d\n", ret);
129 return ret;
130 }
131 }
125 return err; 132 return err;
126} 133}
127 134
@@ -156,9 +163,6 @@ static void ethsw_ethtool_get_stats(struct net_device *netdev,
156 struct ethsw_port_priv *port_priv = netdev_priv(netdev); 163 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
157 int i, err; 164 int i, err;
158 165
159 memset(data, 0,
160 sizeof(u64) * ETHSW_NUM_COUNTERS);
161
162 for (i = 0; i < ETHSW_NUM_COUNTERS; i++) { 166 for (i = 0; i < ETHSW_NUM_COUNTERS; i++) {
163 err = dpsw_if_get_counter(port_priv->ethsw_data->mc_io, 0, 167 err = dpsw_if_get_counter(port_priv->ethsw_data->mc_io, 0,
164 port_priv->ethsw_data->dpsw_handle, 168 port_priv->ethsw_data->dpsw_handle,
diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
index f73edaf6ce87..14a9eebf687e 100644
--- a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
+++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
@@ -22,7 +22,7 @@ static struct workqueue_struct *ethsw_owq;
22 22
23/* Minimal supported DPSW version */ 23/* Minimal supported DPSW version */
24#define DPSW_MIN_VER_MAJOR 8 24#define DPSW_MIN_VER_MAJOR 8
25#define DPSW_MIN_VER_MINOR 0 25#define DPSW_MIN_VER_MINOR 1
26 26
27#define DEFAULT_VLAN_ID 1 27#define DEFAULT_VLAN_ID 1
28 28
@@ -34,11 +34,6 @@ static int ethsw_add_vlan(struct ethsw_core *ethsw, u16 vid)
34 .fdb_id = 0, 34 .fdb_id = 0,
35 }; 35 };
36 36
37 if (ethsw->vlans[vid]) {
38 dev_err(ethsw->dev, "VLAN already configured\n");
39 return -EEXIST;
40 }
41
42 err = dpsw_vlan_add(ethsw->mc_io, 0, 37 err = dpsw_vlan_add(ethsw->mc_io, 0,
43 ethsw->dpsw_handle, vid, &vcfg); 38 ethsw->dpsw_handle, vid, &vcfg);
44 if (err) { 39 if (err) {
@@ -149,12 +144,12 @@ static int ethsw_port_add_vlan(struct ethsw_port_priv *port_priv,
149 return 0; 144 return 0;
150} 145}
151 146
152static int ethsw_set_learning(struct ethsw_core *ethsw, u8 flag) 147static int ethsw_set_learning(struct ethsw_core *ethsw, bool enable)
153{ 148{
154 enum dpsw_fdb_learning_mode learn_mode; 149 enum dpsw_fdb_learning_mode learn_mode;
155 int err; 150 int err;
156 151
157 if (flag) 152 if (enable)
158 learn_mode = DPSW_FDB_LEARNING_MODE_HW; 153 learn_mode = DPSW_FDB_LEARNING_MODE_HW;
159 else 154 else
160 learn_mode = DPSW_FDB_LEARNING_MODE_DIS; 155 learn_mode = DPSW_FDB_LEARNING_MODE_DIS;
@@ -165,24 +160,24 @@ static int ethsw_set_learning(struct ethsw_core *ethsw, u8 flag)
165 dev_err(ethsw->dev, "dpsw_fdb_set_learning_mode err %d\n", err); 160 dev_err(ethsw->dev, "dpsw_fdb_set_learning_mode err %d\n", err);
166 return err; 161 return err;
167 } 162 }
168 ethsw->learning = !!flag; 163 ethsw->learning = enable;
169 164
170 return 0; 165 return 0;
171} 166}
172 167
173static int ethsw_port_set_flood(struct ethsw_port_priv *port_priv, u8 flag) 168static int ethsw_port_set_flood(struct ethsw_port_priv *port_priv, bool enable)
174{ 169{
175 int err; 170 int err;
176 171
177 err = dpsw_if_set_flooding(port_priv->ethsw_data->mc_io, 0, 172 err = dpsw_if_set_flooding(port_priv->ethsw_data->mc_io, 0,
178 port_priv->ethsw_data->dpsw_handle, 173 port_priv->ethsw_data->dpsw_handle,
179 port_priv->idx, flag); 174 port_priv->idx, enable);
180 if (err) { 175 if (err) {
181 netdev_err(port_priv->netdev, 176 netdev_err(port_priv->netdev,
182 "dpsw_if_set_flooding err %d\n", err); 177 "dpsw_if_set_flooding err %d\n", err);
183 return err; 178 return err;
184 } 179 }
185 port_priv->flood = !!flag; 180 port_priv->flood = enable;
186 181
187 return 0; 182 return 0;
188} 183}
@@ -316,6 +311,31 @@ static int ethsw_port_fdb_del_mc(struct ethsw_port_priv *port_priv,
316 return err; 311 return err;
317} 312}
318 313
314static int port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
315 struct net_device *dev, const unsigned char *addr,
316 u16 vid, u16 flags,
317 struct netlink_ext_ack *extack)
318{
319 if (is_unicast_ether_addr(addr))
320 return ethsw_port_fdb_add_uc(netdev_priv(dev),
321 addr);
322 else
323 return ethsw_port_fdb_add_mc(netdev_priv(dev),
324 addr);
325}
326
327static int port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
328 struct net_device *dev,
329 const unsigned char *addr, u16 vid)
330{
331 if (is_unicast_ether_addr(addr))
332 return ethsw_port_fdb_del_uc(netdev_priv(dev),
333 addr);
334 else
335 return ethsw_port_fdb_del_mc(netdev_priv(dev),
336 addr);
337}
338
319static void port_get_stats(struct net_device *netdev, 339static void port_get_stats(struct net_device *netdev,
320 struct rtnl_link_stats64 *stats) 340 struct rtnl_link_stats64 *stats)
321{ 341{
@@ -516,17 +536,165 @@ static int swdev_get_port_parent_id(struct net_device *dev,
516 return 0; 536 return 0;
517} 537}
518 538
539static int port_get_phys_name(struct net_device *netdev, char *name,
540 size_t len)
541{
542 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
543 int err;
544
545 err = snprintf(name, len, "p%d", port_priv->idx);
546 if (err >= len)
547 return -EINVAL;
548
549 return 0;
550}
551
552struct ethsw_dump_ctx {
553 struct net_device *dev;
554 struct sk_buff *skb;
555 struct netlink_callback *cb;
556 int idx;
557};
558
559static int ethsw_fdb_do_dump(struct fdb_dump_entry *entry,
560 struct ethsw_dump_ctx *dump)
561{
562 int is_dynamic = entry->type & DPSW_FDB_ENTRY_DINAMIC;
563 u32 portid = NETLINK_CB(dump->cb->skb).portid;
564 u32 seq = dump->cb->nlh->nlmsg_seq;
565 struct nlmsghdr *nlh;
566 struct ndmsg *ndm;
567
568 if (dump->idx < dump->cb->args[2])
569 goto skip;
570
571 nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH,
572 sizeof(*ndm), NLM_F_MULTI);
573 if (!nlh)
574 return -EMSGSIZE;
575
576 ndm = nlmsg_data(nlh);
577 ndm->ndm_family = AF_BRIDGE;
578 ndm->ndm_pad1 = 0;
579 ndm->ndm_pad2 = 0;
580 ndm->ndm_flags = NTF_SELF;
581 ndm->ndm_type = 0;
582 ndm->ndm_ifindex = dump->dev->ifindex;
583 ndm->ndm_state = is_dynamic ? NUD_REACHABLE : NUD_NOARP;
584
585 if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, entry->mac_addr))
586 goto nla_put_failure;
587
588 nlmsg_end(dump->skb, nlh);
589
590skip:
591 dump->idx++;
592 return 0;
593
594nla_put_failure:
595 nlmsg_cancel(dump->skb, nlh);
596 return -EMSGSIZE;
597}
598
599static int port_fdb_valid_entry(struct fdb_dump_entry *entry,
600 struct ethsw_port_priv *port_priv)
601{
602 int idx = port_priv->idx;
603 int valid;
604
605 if (entry->type & DPSW_FDB_ENTRY_TYPE_UNICAST)
606 valid = entry->if_info == port_priv->idx;
607 else
608 valid = entry->if_mask[idx / 8] & BIT(idx % 8);
609
610 return valid;
611}
612
613static int port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
614 struct net_device *net_dev,
615 struct net_device *filter_dev, int *idx)
616{
617 struct ethsw_port_priv *port_priv = netdev_priv(net_dev);
618 struct ethsw_core *ethsw = port_priv->ethsw_data;
619 struct device *dev = net_dev->dev.parent;
620 struct fdb_dump_entry *fdb_entries;
621 struct fdb_dump_entry fdb_entry;
622 struct ethsw_dump_ctx dump = {
623 .dev = net_dev,
624 .skb = skb,
625 .cb = cb,
626 .idx = *idx,
627 };
628 dma_addr_t fdb_dump_iova;
629 u16 num_fdb_entries;
630 u32 fdb_dump_size;
631 int err = 0, i;
632 u8 *dma_mem;
633
634 fdb_dump_size = ethsw->sw_attr.max_fdb_entries * sizeof(fdb_entry);
635 dma_mem = kzalloc(fdb_dump_size, GFP_KERNEL);
636 if (!dma_mem)
637 return -ENOMEM;
638
639 fdb_dump_iova = dma_map_single(dev, dma_mem, fdb_dump_size,
640 DMA_FROM_DEVICE);
641 if (dma_mapping_error(dev, fdb_dump_iova)) {
642 netdev_err(net_dev, "dma_map_single() failed\n");
643 err = -ENOMEM;
644 goto err_map;
645 }
646
647 err = dpsw_fdb_dump(ethsw->mc_io, 0, ethsw->dpsw_handle, 0,
648 fdb_dump_iova, fdb_dump_size, &num_fdb_entries);
649 if (err) {
650 netdev_err(net_dev, "dpsw_fdb_dump() = %d\n", err);
651 goto err_dump;
652 }
653
654 dma_unmap_single(dev, fdb_dump_iova, fdb_dump_size, DMA_FROM_DEVICE);
655
656 fdb_entries = (struct fdb_dump_entry *)dma_mem;
657 for (i = 0; i < num_fdb_entries; i++) {
658 fdb_entry = fdb_entries[i];
659
660 if (!port_fdb_valid_entry(&fdb_entry, port_priv))
661 continue;
662
663 err = ethsw_fdb_do_dump(&fdb_entry, &dump);
664 if (err)
665 goto end;
666 }
667
668end:
669 *idx = dump.idx;
670
671 kfree(dma_mem);
672
673 return 0;
674
675err_dump:
676 dma_unmap_single(dev, fdb_dump_iova, fdb_dump_size, DMA_TO_DEVICE);
677err_map:
678 kfree(dma_mem);
679 return err;
680}
681
519static const struct net_device_ops ethsw_port_ops = { 682static const struct net_device_ops ethsw_port_ops = {
520 .ndo_open = port_open, 683 .ndo_open = port_open,
521 .ndo_stop = port_stop, 684 .ndo_stop = port_stop,
522 685
523 .ndo_set_mac_address = eth_mac_addr, 686 .ndo_set_mac_address = eth_mac_addr,
687 .ndo_get_stats64 = port_get_stats,
524 .ndo_change_mtu = port_change_mtu, 688 .ndo_change_mtu = port_change_mtu,
525 .ndo_has_offload_stats = port_has_offload_stats, 689 .ndo_has_offload_stats = port_has_offload_stats,
526 .ndo_get_offload_stats = port_get_offload_stats, 690 .ndo_get_offload_stats = port_get_offload_stats,
691 .ndo_fdb_add = port_fdb_add,
692 .ndo_fdb_del = port_fdb_del,
693 .ndo_fdb_dump = port_fdb_dump,
527 694
528 .ndo_start_xmit = port_dropframe, 695 .ndo_start_xmit = port_dropframe,
529 .ndo_get_port_parent_id = swdev_get_port_parent_id, 696 .ndo_get_port_parent_id = swdev_get_port_parent_id,
697 .ndo_get_phys_port_name = port_get_phys_name,
530}; 698};
531 699
532static void ethsw_links_state_update(struct ethsw_core *ethsw) 700static void ethsw_links_state_update(struct ethsw_core *ethsw)
@@ -549,12 +717,12 @@ static irqreturn_t ethsw_irq0_handler_thread(int irq_num, void *arg)
549 err = dpsw_get_irq_status(ethsw->mc_io, 0, ethsw->dpsw_handle, 717 err = dpsw_get_irq_status(ethsw->mc_io, 0, ethsw->dpsw_handle,
550 DPSW_IRQ_INDEX_IF, &status); 718 DPSW_IRQ_INDEX_IF, &status);
551 if (err) { 719 if (err) {
552 dev_err(dev, "Can't get irq status (err %d)", err); 720 dev_err(dev, "Can't get irq status (err %d)\n", err);
553 721
554 err = dpsw_clear_irq_status(ethsw->mc_io, 0, ethsw->dpsw_handle, 722 err = dpsw_clear_irq_status(ethsw->mc_io, 0, ethsw->dpsw_handle,
555 DPSW_IRQ_INDEX_IF, 0xFFFFFFFF); 723 DPSW_IRQ_INDEX_IF, 0xFFFFFFFF);
556 if (err) 724 if (err)
557 dev_err(dev, "Can't clear irq status (err %d)", err); 725 dev_err(dev, "Can't clear irq status (err %d)\n", err);
558 goto out; 726 goto out;
559 } 727 }
560 728
@@ -599,21 +767,21 @@ static int ethsw_setup_irqs(struct fsl_mc_device *sw_dev)
599 IRQF_NO_SUSPEND | IRQF_ONESHOT, 767 IRQF_NO_SUSPEND | IRQF_ONESHOT,
600 dev_name(dev), dev); 768 dev_name(dev), dev);
601 if (err) { 769 if (err) {
602 dev_err(dev, "devm_request_threaded_irq(): %d", err); 770 dev_err(dev, "devm_request_threaded_irq(): %d\n", err);
603 goto free_irq; 771 goto free_irq;
604 } 772 }
605 773
606 err = dpsw_set_irq_mask(ethsw->mc_io, 0, ethsw->dpsw_handle, 774 err = dpsw_set_irq_mask(ethsw->mc_io, 0, ethsw->dpsw_handle,
607 DPSW_IRQ_INDEX_IF, mask); 775 DPSW_IRQ_INDEX_IF, mask);
608 if (err) { 776 if (err) {
609 dev_err(dev, "dpsw_set_irq_mask(): %d", err); 777 dev_err(dev, "dpsw_set_irq_mask(): %d\n", err);
610 goto free_devm_irq; 778 goto free_devm_irq;
611 } 779 }
612 780
613 err = dpsw_set_irq_enable(ethsw->mc_io, 0, ethsw->dpsw_handle, 781 err = dpsw_set_irq_enable(ethsw->mc_io, 0, ethsw->dpsw_handle,
614 DPSW_IRQ_INDEX_IF, 1); 782 DPSW_IRQ_INDEX_IF, 1);
615 if (err) { 783 if (err) {
616 dev_err(dev, "dpsw_set_irq_enable(): %d", err); 784 dev_err(dev, "dpsw_set_irq_enable(): %d\n", err);
617 goto free_devm_irq; 785 goto free_devm_irq;
618 } 786 }
619 787
@@ -673,11 +841,12 @@ static int port_attr_br_flags_set(struct net_device *netdev,
673 return 0; 841 return 0;
674 842
675 /* Learning is enabled per switch */ 843 /* Learning is enabled per switch */
676 err = ethsw_set_learning(port_priv->ethsw_data, flags & BR_LEARNING); 844 err = ethsw_set_learning(port_priv->ethsw_data,
845 !!(flags & BR_LEARNING));
677 if (err) 846 if (err)
678 goto exit; 847 goto exit;
679 848
680 err = ethsw_port_set_flood(port_priv, flags & BR_FLOOD); 849 err = ethsw_port_set_flood(port_priv, !!(flags & BR_FLOOD));
681 850
682exit: 851exit:
683 return err; 852 return err;
@@ -950,8 +1119,7 @@ static int port_bridge_join(struct net_device *netdev,
950 if (ethsw->ports[i]->bridge_dev && 1119 if (ethsw->ports[i]->bridge_dev &&
951 (ethsw->ports[i]->bridge_dev != upper_dev)) { 1120 (ethsw->ports[i]->bridge_dev != upper_dev)) {
952 netdev_err(netdev, 1121 netdev_err(netdev,
953 "Another switch port is connected to %s\n", 1122 "Only one bridge supported per DPSW object!\n");
954 ethsw->ports[i]->bridge_dev->name);
955 return -EINVAL; 1123 return -EINVAL;
956 } 1124 }
957 1125
@@ -1023,18 +1191,30 @@ static void ethsw_switchdev_event_work(struct work_struct *work)
1023 container_of(work, struct ethsw_switchdev_event_work, work); 1191 container_of(work, struct ethsw_switchdev_event_work, work);
1024 struct net_device *dev = switchdev_work->dev; 1192 struct net_device *dev = switchdev_work->dev;
1025 struct switchdev_notifier_fdb_info *fdb_info; 1193 struct switchdev_notifier_fdb_info *fdb_info;
1194 int err;
1026 1195
1027 rtnl_lock(); 1196 rtnl_lock();
1028 fdb_info = &switchdev_work->fdb_info; 1197 fdb_info = &switchdev_work->fdb_info;
1029 1198
1030 switch (switchdev_work->event) { 1199 switch (switchdev_work->event) {
1031 case SWITCHDEV_FDB_ADD_TO_DEVICE: 1200 case SWITCHDEV_FDB_ADD_TO_DEVICE:
1201 if (!fdb_info->added_by_user)
1202 break;
1032 if (is_unicast_ether_addr(fdb_info->addr)) 1203 if (is_unicast_ether_addr(fdb_info->addr))
1033 ethsw_port_fdb_add_uc(netdev_priv(dev), fdb_info->addr); 1204 err = ethsw_port_fdb_add_uc(netdev_priv(dev),
1205 fdb_info->addr);
1034 else 1206 else
1035 ethsw_port_fdb_add_mc(netdev_priv(dev), fdb_info->addr); 1207 err = ethsw_port_fdb_add_mc(netdev_priv(dev),
1208 fdb_info->addr);
1209 if (err)
1210 break;
1211 fdb_info->offloaded = true;
1212 call_switchdev_notifiers(SWITCHDEV_FDB_OFFLOADED, dev,
1213 &fdb_info->info, NULL);
1036 break; 1214 break;
1037 case SWITCHDEV_FDB_DEL_TO_DEVICE: 1215 case SWITCHDEV_FDB_DEL_TO_DEVICE:
1216 if (!fdb_info->added_by_user)
1217 break;
1038 if (is_unicast_ether_addr(fdb_info->addr)) 1218 if (is_unicast_ether_addr(fdb_info->addr))
1039 ethsw_port_fdb_del_uc(netdev_priv(dev), fdb_info->addr); 1219 ethsw_port_fdb_del_uc(netdev_priv(dev), fdb_info->addr);
1040 else 1220 else
@@ -1177,48 +1357,6 @@ err_switchdev_nb:
1177 return err; 1357 return err;
1178} 1358}
1179 1359
1180static int ethsw_open(struct ethsw_core *ethsw)
1181{
1182 struct ethsw_port_priv *port_priv = NULL;
1183 int i, err;
1184
1185 err = dpsw_enable(ethsw->mc_io, 0, ethsw->dpsw_handle);
1186 if (err) {
1187 dev_err(ethsw->dev, "dpsw_enable err %d\n", err);
1188 return err;
1189 }
1190
1191 for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
1192 port_priv = ethsw->ports[i];
1193 err = dev_open(port_priv->netdev, NULL);
1194 if (err) {
1195 netdev_err(port_priv->netdev, "dev_open err %d\n", err);
1196 return err;
1197 }
1198 }
1199
1200 return 0;
1201}
1202
1203static int ethsw_stop(struct ethsw_core *ethsw)
1204{
1205 struct ethsw_port_priv *port_priv = NULL;
1206 int i, err;
1207
1208 for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
1209 port_priv = ethsw->ports[i];
1210 dev_close(port_priv->netdev);
1211 }
1212
1213 err = dpsw_disable(ethsw->mc_io, 0, ethsw->dpsw_handle);
1214 if (err) {
1215 dev_err(ethsw->dev, "dpsw_disable err %d\n", err);
1216 return err;
1217 }
1218
1219 return 0;
1220}
1221
1222static int ethsw_init(struct fsl_mc_device *sw_dev) 1360static int ethsw_init(struct fsl_mc_device *sw_dev)
1223{ 1361{
1224 struct device *dev = &sw_dev->dev; 1362 struct device *dev = &sw_dev->dev;
@@ -1320,7 +1458,6 @@ err_close:
1320 1458
1321static int ethsw_port_init(struct ethsw_port_priv *port_priv, u16 port) 1459static int ethsw_port_init(struct ethsw_port_priv *port_priv, u16 port)
1322{ 1460{
1323 const char def_mcast[ETH_ALEN] = {0x01, 0x00, 0x5e, 0x00, 0x00, 0x01};
1324 struct net_device *netdev = port_priv->netdev; 1461 struct net_device *netdev = port_priv->netdev;
1325 struct ethsw_core *ethsw = port_priv->ethsw_data; 1462 struct ethsw_core *ethsw = port_priv->ethsw_data;
1326 struct dpsw_vlan_if_cfg vcfg; 1463 struct dpsw_vlan_if_cfg vcfg;
@@ -1346,12 +1483,10 @@ static int ethsw_port_init(struct ethsw_port_priv *port_priv, u16 port)
1346 1483
1347 err = dpsw_vlan_remove_if(ethsw->mc_io, 0, ethsw->dpsw_handle, 1484 err = dpsw_vlan_remove_if(ethsw->mc_io, 0, ethsw->dpsw_handle,
1348 DEFAULT_VLAN_ID, &vcfg); 1485 DEFAULT_VLAN_ID, &vcfg);
1349 if (err) { 1486 if (err)
1350 netdev_err(netdev, "dpsw_vlan_remove_if err %d\n", err); 1487 netdev_err(netdev, "dpsw_vlan_remove_if err %d\n", err);
1351 return err;
1352 }
1353 1488
1354 return ethsw_port_fdb_add_mc(port_priv, def_mcast); 1489 return err;
1355} 1490}
1356 1491
1357static void ethsw_unregister_notifier(struct device *dev) 1492static void ethsw_unregister_notifier(struct device *dev)
@@ -1403,9 +1538,7 @@ static int ethsw_remove(struct fsl_mc_device *sw_dev)
1403 1538
1404 destroy_workqueue(ethsw_owq); 1539 destroy_workqueue(ethsw_owq);
1405 1540
1406 rtnl_lock(); 1541 dpsw_disable(ethsw->mc_io, 0, ethsw->dpsw_handle);
1407 ethsw_stop(ethsw);
1408 rtnl_unlock();
1409 1542
1410 for (i = 0; i < ethsw->sw_attr.num_ifs; i++) { 1543 for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
1411 port_priv = ethsw->ports[i]; 1544 port_priv = ethsw->ports[i];
@@ -1455,16 +1588,24 @@ static int ethsw_probe_port(struct ethsw_core *ethsw, u16 port_idx)
1455 port_netdev->min_mtu = ETH_MIN_MTU; 1588 port_netdev->min_mtu = ETH_MIN_MTU;
1456 port_netdev->max_mtu = ETHSW_MAX_FRAME_LENGTH; 1589 port_netdev->max_mtu = ETHSW_MAX_FRAME_LENGTH;
1457 1590
1591 err = ethsw_port_init(port_priv, port_idx);
1592 if (err)
1593 goto err_port_probe;
1594
1458 err = register_netdev(port_netdev); 1595 err = register_netdev(port_netdev);
1459 if (err < 0) { 1596 if (err < 0) {
1460 dev_err(dev, "register_netdev error %d\n", err); 1597 dev_err(dev, "register_netdev error %d\n", err);
1461 free_netdev(port_netdev); 1598 goto err_port_probe;
1462 return err;
1463 } 1599 }
1464 1600
1465 ethsw->ports[port_idx] = port_priv; 1601 ethsw->ports[port_idx] = port_priv;
1466 1602
1467 return ethsw_port_init(port_priv, port_idx); 1603 return 0;
1604
1605err_port_probe:
1606 free_netdev(port_netdev);
1607
1608 return err;
1468} 1609}
1469 1610
1470static int ethsw_probe(struct fsl_mc_device *sw_dev) 1611static int ethsw_probe(struct fsl_mc_device *sw_dev)
@@ -1482,7 +1623,8 @@ static int ethsw_probe(struct fsl_mc_device *sw_dev)
1482 ethsw->dev = dev; 1623 ethsw->dev = dev;
1483 dev_set_drvdata(dev, ethsw); 1624 dev_set_drvdata(dev, ethsw);
1484 1625
1485 err = fsl_mc_portal_allocate(sw_dev, 0, &ethsw->mc_io); 1626 err = fsl_mc_portal_allocate(sw_dev, FSL_MC_IO_ATOMIC_CONTEXT_PORTAL,
1627 &ethsw->mc_io);
1486 if (err) { 1628 if (err) {
1487 if (err == -ENXIO) 1629 if (err == -ENXIO)
1488 err = -EPROBE_DEFER; 1630 err = -EPROBE_DEFER;
@@ -1514,12 +1656,11 @@ static int ethsw_probe(struct fsl_mc_device *sw_dev)
1514 goto err_free_ports; 1656 goto err_free_ports;
1515 } 1657 }
1516 1658
1517 /* Switch starts up enabled */ 1659 err = dpsw_enable(ethsw->mc_io, 0, ethsw->dpsw_handle);
1518 rtnl_lock(); 1660 if (err) {
1519 err = ethsw_open(ethsw); 1661 dev_err(ethsw->dev, "dpsw_enable err %d\n", err);
1520 rtnl_unlock();
1521 if (err)
1522 goto err_free_ports; 1662 goto err_free_ports;
1663 }
1523 1664
1524 /* Setup IRQs */ 1665 /* Setup IRQs */
1525 err = ethsw_setup_irqs(sw_dev); 1666 err = ethsw_setup_irqs(sw_dev);
@@ -1530,9 +1671,7 @@ static int ethsw_probe(struct fsl_mc_device *sw_dev)
1530 return 0; 1671 return 0;
1531 1672
1532err_stop: 1673err_stop:
1533 rtnl_lock(); 1674 dpsw_disable(ethsw->mc_io, 0, ethsw->dpsw_handle);
1534 ethsw_stop(ethsw);
1535 rtnl_unlock();
1536 1675
1537err_free_ports: 1676err_free_ports:
1538 /* Cleanup registered ports only */ 1677 /* Cleanup registered ports only */
diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw.h b/drivers/staging/fsl-dpaa2/ethsw/ethsw.h
index c48783680a05..3ea8a0ad8c10 100644
--- a/drivers/staging/fsl-dpaa2/ethsw/ethsw.h
+++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw.h
@@ -23,9 +23,13 @@
23/* Number of IRQs supported */ 23/* Number of IRQs supported */
24#define DPSW_IRQ_NUM 2 24#define DPSW_IRQ_NUM 2
25 25
26/* Port is member of VLAN */
26#define ETHSW_VLAN_MEMBER 1 27#define ETHSW_VLAN_MEMBER 1
28/* VLAN to be treated as untagged on egress */
27#define ETHSW_VLAN_UNTAGGED 2 29#define ETHSW_VLAN_UNTAGGED 2
30/* Untagged frames will be assigned to this VLAN */
28#define ETHSW_VLAN_PVID 4 31#define ETHSW_VLAN_PVID 4
32/* VLAN configured on the switch */
29#define ETHSW_VLAN_GLOBAL 8 33#define ETHSW_VLAN_GLOBAL 8
30 34
31/* Maximum Frame Length supported by HW (currently 10k) */ 35/* Maximum Frame Length supported by HW (currently 10k) */
diff --git a/drivers/staging/gasket/apex_driver.c b/drivers/staging/gasket/apex_driver.c
index 464648ee2036..46199c8ca441 100644
--- a/drivers/staging/gasket/apex_driver.c
+++ b/drivers/staging/gasket/apex_driver.c
@@ -509,6 +509,8 @@ static ssize_t sysfs_show(struct device *device, struct device_attribute *attr,
509 struct gasket_dev *gasket_dev; 509 struct gasket_dev *gasket_dev;
510 struct gasket_sysfs_attribute *gasket_attr; 510 struct gasket_sysfs_attribute *gasket_attr;
511 enum sysfs_attribute_type type; 511 enum sysfs_attribute_type type;
512 struct gasket_page_table *gpt;
513 uint val;
512 514
513 gasket_dev = gasket_sysfs_get_device_data(device); 515 gasket_dev = gasket_sysfs_get_device_data(device);
514 if (!gasket_dev) { 516 if (!gasket_dev) {
@@ -524,29 +526,25 @@ static ssize_t sysfs_show(struct device *device, struct device_attribute *attr,
524 } 526 }
525 527
526 type = (enum sysfs_attribute_type)gasket_attr->data.attr_type; 528 type = (enum sysfs_attribute_type)gasket_attr->data.attr_type;
529 gpt = gasket_dev->page_table[0];
527 switch (type) { 530 switch (type) {
528 case ATTR_KERNEL_HIB_PAGE_TABLE_SIZE: 531 case ATTR_KERNEL_HIB_PAGE_TABLE_SIZE:
529 ret = scnprintf(buf, PAGE_SIZE, "%u\n", 532 val = gasket_page_table_num_entries(gpt);
530 gasket_page_table_num_entries(
531 gasket_dev->page_table[0]));
532 break; 533 break;
533 case ATTR_KERNEL_HIB_SIMPLE_PAGE_TABLE_SIZE: 534 case ATTR_KERNEL_HIB_SIMPLE_PAGE_TABLE_SIZE:
534 ret = scnprintf(buf, PAGE_SIZE, "%u\n", 535 val = gasket_page_table_num_simple_entries(gpt);
535 gasket_page_table_num_simple_entries(
536 gasket_dev->page_table[0]));
537 break; 536 break;
538 case ATTR_KERNEL_HIB_NUM_ACTIVE_PAGES: 537 case ATTR_KERNEL_HIB_NUM_ACTIVE_PAGES:
539 ret = scnprintf(buf, PAGE_SIZE, "%u\n", 538 val = gasket_page_table_num_active_pages(gpt);
540 gasket_page_table_num_active_pages(
541 gasket_dev->page_table[0]));
542 break; 539 break;
543 default: 540 default:
544 dev_dbg(gasket_dev->dev, "Unknown attribute: %s\n", 541 dev_dbg(gasket_dev->dev, "Unknown attribute: %s\n",
545 attr->attr.name); 542 attr->attr.name);
546 ret = 0; 543 ret = 0;
547 break; 544 goto exit;
548 } 545 }
549 546 ret = scnprintf(buf, PAGE_SIZE, "%u\n", val);
547exit:
550 gasket_sysfs_put_attr(device, gasket_attr); 548 gasket_sysfs_put_attr(device, gasket_attr);
551 gasket_sysfs_put_device_data(device, gasket_dev); 549 gasket_sysfs_put_device_data(device, gasket_dev);
552 return ret; 550 return ret;
@@ -659,7 +657,7 @@ static void apex_pci_remove(struct pci_dev *pci_dev)
659 pci_disable_device(pci_dev); 657 pci_disable_device(pci_dev);
660} 658}
661 659
662static struct gasket_driver_desc apex_desc = { 660static const struct gasket_driver_desc apex_desc = {
663 .name = "apex", 661 .name = "apex",
664 .driver_version = APEX_DRIVER_VERSION, 662 .driver_version = APEX_DRIVER_VERSION,
665 .major = 120, 663 .major = 120,
diff --git a/drivers/staging/gasket/gasket_ioctl.c b/drivers/staging/gasket/gasket_ioctl.c
index 7ecfba4f2b06..240f9bb10b71 100644
--- a/drivers/staging/gasket/gasket_ioctl.c
+++ b/drivers/staging/gasket/gasket_ioctl.c
@@ -39,8 +39,7 @@ static int gasket_set_event_fd(struct gasket_dev *gasket_dev,
39} 39}
40 40
41/* Read the size of the page table. */ 41/* Read the size of the page table. */
42static int gasket_read_page_table_size( 42static int gasket_read_page_table_size(struct gasket_dev *gasket_dev,
43 struct gasket_dev *gasket_dev,
44 struct gasket_page_table_ioctl __user *argp) 43 struct gasket_page_table_ioctl __user *argp)
45{ 44{
46 int ret = 0; 45 int ret = 0;
@@ -66,8 +65,7 @@ static int gasket_read_page_table_size(
66} 65}
67 66
68/* Read the size of the simple page table. */ 67/* Read the size of the simple page table. */
69static int gasket_read_simple_page_table_size( 68static int gasket_read_simple_page_table_size(struct gasket_dev *gasket_dev,
70 struct gasket_dev *gasket_dev,
71 struct gasket_page_table_ioctl __user *argp) 69 struct gasket_page_table_ioctl __user *argp)
72{ 70{
73 int ret = 0; 71 int ret = 0;
@@ -93,8 +91,7 @@ static int gasket_read_simple_page_table_size(
93} 91}
94 92
95/* Set the boundary between the simple and extended page tables. */ 93/* Set the boundary between the simple and extended page tables. */
96static int gasket_partition_page_table( 94static int gasket_partition_page_table(struct gasket_dev *gasket_dev,
97 struct gasket_dev *gasket_dev,
98 struct gasket_page_table_ioctl __user *argp) 95 struct gasket_page_table_ioctl __user *argp)
99{ 96{
100 int ret; 97 int ret;
@@ -185,8 +182,7 @@ static int gasket_unmap_buffers(struct gasket_dev *gasket_dev,
185 * Reserve structures for coherent allocation, and allocate or free the 182 * Reserve structures for coherent allocation, and allocate or free the
186 * corresponding memory. 183 * corresponding memory.
187 */ 184 */
188static int gasket_config_coherent_allocator( 185static int gasket_config_coherent_allocator(struct gasket_dev *gasket_dev,
189 struct gasket_dev *gasket_dev,
190 struct gasket_coherent_alloc_config_ioctl __user *argp) 186 struct gasket_coherent_alloc_config_ioctl __user *argp)
191{ 187{
192 int ret; 188 int ret;
diff --git a/drivers/staging/goldfish/goldfish_audio.c b/drivers/staging/goldfish/goldfish_audio.c
index 24a738238f9f..0c65a0121dde 100644
--- a/drivers/staging/goldfish/goldfish_audio.c
+++ b/drivers/staging/goldfish/goldfish_audio.c
@@ -302,10 +302,8 @@ static int goldfish_audio_probe(struct platform_device *pdev)
302 return -ENOMEM; 302 return -ENOMEM;
303 303
304 data->irq = platform_get_irq(pdev, 0); 304 data->irq = platform_get_irq(pdev, 0);
305 if (data->irq < 0) { 305 if (data->irq < 0)
306 dev_err(&pdev->dev, "platform_get_irq failed\n");
307 return -ENODEV; 306 return -ENODEV;
308 }
309 data->buffer_virt = dmam_alloc_coherent(&pdev->dev, 307 data->buffer_virt = dmam_alloc_coherent(&pdev->dev,
310 COMBINED_BUFFER_SIZE, 308 COMBINED_BUFFER_SIZE,
311 &buf_addr, GFP_KERNEL); 309 &buf_addr, GFP_KERNEL);
diff --git a/drivers/staging/greybus/Documentation/firmware/authenticate.c b/drivers/staging/greybus/Documentation/firmware/authenticate.c
index 806e75b7f405..3d2c6f88a138 100644
--- a/drivers/staging/greybus/Documentation/firmware/authenticate.c
+++ b/drivers/staging/greybus/Documentation/firmware/authenticate.c
@@ -2,54 +2,8 @@
2/* 2/*
3 * Sample code to test CAP protocol 3 * Sample code to test CAP protocol
4 * 4 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license.
7 *
8 * GPL LICENSE SUMMARY
9 *
10 * Copyright(c) 2016 Google Inc. All rights reserved. 5 * Copyright(c) 2016 Google Inc. All rights reserved.
11 * Copyright(c) 2016 Linaro Ltd. All rights reserved. 6 * Copyright(c) 2016 Linaro Ltd. All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License version 2 for more details.
21 *
22 * BSD LICENSE
23 *
24 * Copyright(c) 2016 Google Inc. All rights reserved.
25 * Copyright(c) 2016 Linaro Ltd. All rights reserved.
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 *
31 * * Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * * Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in
35 * the documentation and/or other materials provided with the
36 * distribution.
37 * * Neither the name of Google Inc. or Linaro Ltd. nor the names of
38 * its contributors may be used to endorse or promote products
39 * derived from this software without specific prior written
40 * permission.
41 *
42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
46 * LINARO LTD. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
47 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
48 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
49 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
50 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 */ 7 */
54 8
55#include <stdio.h> 9#include <stdio.h>
diff --git a/drivers/staging/greybus/Documentation/firmware/firmware.c b/drivers/staging/greybus/Documentation/firmware/firmware.c
index 31d9c23e2eeb..765d69faa9cc 100644
--- a/drivers/staging/greybus/Documentation/firmware/firmware.c
+++ b/drivers/staging/greybus/Documentation/firmware/firmware.c
@@ -2,54 +2,8 @@
2/* 2/*
3 * Sample code to test firmware-management protocol 3 * Sample code to test firmware-management protocol
4 * 4 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license.
7 *
8 * GPL LICENSE SUMMARY
9 *
10 * Copyright(c) 2016 Google Inc. All rights reserved. 5 * Copyright(c) 2016 Google Inc. All rights reserved.
11 * Copyright(c) 2016 Linaro Ltd. All rights reserved. 6 * Copyright(c) 2016 Linaro Ltd. All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License version 2 for more details.
21 *
22 * BSD LICENSE
23 *
24 * Copyright(c) 2016 Google Inc. All rights reserved.
25 * Copyright(c) 2016 Linaro Ltd. All rights reserved.
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 *
31 * * Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * * Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in
35 * the documentation and/or other materials provided with the
36 * distribution.
37 * * Neither the name of Google Inc. or Linaro Ltd. nor the names of
38 * its contributors may be used to endorse or promote products
39 * derived from this software without specific prior written
40 * permission.
41 *
42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
46 * LINARO LTD. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
47 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
48 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
49 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
50 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 */ 7 */
54 8
55#include <stdio.h> 9#include <stdio.h>
diff --git a/drivers/staging/greybus/Kconfig b/drivers/staging/greybus/Kconfig
index 4894c3514955..d4777f5a8b90 100644
--- a/drivers/staging/greybus/Kconfig
+++ b/drivers/staging/greybus/Kconfig
@@ -1,33 +1,6 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2menuconfig GREYBUS
3 tristate "Greybus support"
4 depends on SYSFS
5 ---help---
6 This option enables the Greybus driver core. Greybus is an
7 hardware protocol that was designed to provide Unipro with a
8 sane application layer. It was originally designed for the
9 ARA project, a module phone system, but has shown up in other
10 phones, and can be tunneled over other busses in order to
11 control hardware devices.
12
13 Say Y here to enable support for these types of drivers.
14
15 To compile this code as a module, chose M here: the module
16 will be called greybus.ko
17
18if GREYBUS 2if GREYBUS
19 3
20config GREYBUS_ES2
21 tristate "Greybus ES3 USB host controller"
22 depends on USB
23 ---help---
24 Select this option if you have a Toshiba ES3 USB device that
25 acts as a Greybus "host controller". This device is a bridge
26 from a USB device to a Unipro network.
27
28 To compile this code as a module, chose M here: the module
29 will be called gb-es2.ko
30
31config GREYBUS_AUDIO 4config GREYBUS_AUDIO
32 tristate "Greybus Audio Class driver" 5 tristate "Greybus Audio Class driver"
33 depends on SOUND 6 depends on SOUND
diff --git a/drivers/staging/greybus/Makefile b/drivers/staging/greybus/Makefile
index 2551ed16b742..627e44f2a983 100644
--- a/drivers/staging/greybus/Makefile
+++ b/drivers/staging/greybus/Makefile
@@ -1,29 +1,7 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2# Greybus core
3greybus-y := core.o \
4 debugfs.o \
5 hd.o \
6 manifest.o \
7 module.o \
8 interface.o \
9 bundle.o \
10 connection.o \
11 control.o \
12 svc.o \
13 svc_watchdog.o \
14 operation.o
15
16obj-$(CONFIG_GREYBUS) += greybus.o
17
18# needed for trace events 2# needed for trace events
19ccflags-y += -I$(src) 3ccflags-y += -I$(src)
20 4
21
22# Greybus Host controller drivers
23gb-es2-y := es2.o
24
25obj-$(CONFIG_GREYBUS_ES2) += gb-es2.o
26
27# Greybus class drivers 5# Greybus class drivers
28gb-bootrom-y := bootrom.o 6gb-bootrom-y := bootrom.o
29gb-camera-y := camera.o 7gb-camera-y := camera.o
diff --git a/drivers/staging/greybus/arche-platform.c b/drivers/staging/greybus/arche-platform.c
index 6eb842040c22..eebf0deb39f5 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -19,8 +19,8 @@
19#include <linux/irq.h> 19#include <linux/irq.h>
20#include <linux/suspend.h> 20#include <linux/suspend.h>
21#include <linux/time.h> 21#include <linux/time.h>
22#include <linux/greybus.h>
22#include "arche_platform.h" 23#include "arche_platform.h"
23#include "greybus.h"
24 24
25#if IS_ENABLED(CONFIG_USB_HSIC_USB3613) 25#if IS_ENABLED(CONFIG_USB_HSIC_USB3613)
26#include <linux/usb/usb3613.h> 26#include <linux/usb/usb3613.h>
diff --git a/drivers/staging/greybus/arpc.h b/drivers/staging/greybus/arpc.h
deleted file mode 100644
index 3dab6375909c..000000000000
--- a/drivers/staging/greybus/arpc.h
+++ /dev/null
@@ -1,109 +0,0 @@
1/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2/*
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2016 Google Inc. All rights reserved.
9 * Copyright(c) 2016 Linaro Ltd. All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License version 2 for more details.
19 *
20 * BSD LICENSE
21 *
22 * Copyright(c) 2016 Google Inc. All rights reserved.
23 * Copyright(c) 2016 Linaro Ltd. All rights reserved.
24 *
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
27 * are met:
28 *
29 * * Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * * Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in
33 * the documentation and/or other materials provided with the
34 * distribution.
35 * * Neither the name of Google Inc. or Linaro Ltd. nor the names of
36 * its contributors may be used to endorse or promote products
37 * derived from this software without specific prior written
38 * permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
44 * LINARO LTD. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
46 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
47 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
48 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 */
52
53#ifndef __ARPC_H
54#define __ARPC_H
55
56/* APBridgeA RPC (ARPC) */
57
58enum arpc_result {
59 ARPC_SUCCESS = 0x00,
60 ARPC_NO_MEMORY = 0x01,
61 ARPC_INVALID = 0x02,
62 ARPC_TIMEOUT = 0x03,
63 ARPC_UNKNOWN_ERROR = 0xff,
64};
65
66struct arpc_request_message {
67 __le16 id; /* RPC unique id */
68 __le16 size; /* Size in bytes of header + payload */
69 __u8 type; /* RPC type */
70 __u8 data[0]; /* ARPC data */
71} __packed;
72
73struct arpc_response_message {
74 __le16 id; /* RPC unique id */
75 __u8 result; /* Result of RPC */
76} __packed;
77
78/* ARPC requests */
79#define ARPC_TYPE_CPORT_CONNECTED 0x01
80#define ARPC_TYPE_CPORT_QUIESCE 0x02
81#define ARPC_TYPE_CPORT_CLEAR 0x03
82#define ARPC_TYPE_CPORT_FLUSH 0x04
83#define ARPC_TYPE_CPORT_SHUTDOWN 0x05
84
85struct arpc_cport_connected_req {
86 __le16 cport_id;
87} __packed;
88
89struct arpc_cport_quiesce_req {
90 __le16 cport_id;
91 __le16 peer_space;
92 __le16 timeout;
93} __packed;
94
95struct arpc_cport_clear_req {
96 __le16 cport_id;
97} __packed;
98
99struct arpc_cport_flush_req {
100 __le16 cport_id;
101} __packed;
102
103struct arpc_cport_shutdown_req {
104 __le16 cport_id;
105 __le16 timeout;
106 __u8 phase;
107} __packed;
108
109#endif /* __ARPC_H */
diff --git a/drivers/staging/greybus/audio_apbridgea.c b/drivers/staging/greybus/audio_apbridgea.c
index 7ebb1bde5cb7..26117e390deb 100644
--- a/drivers/staging/greybus/audio_apbridgea.c
+++ b/drivers/staging/greybus/audio_apbridgea.c
@@ -5,8 +5,7 @@
5 * Copyright 2015-2016 Google Inc. 5 * Copyright 2015-2016 Google Inc.
6 */ 6 */
7 7
8#include "greybus.h" 8#include <linux/greybus.h>
9#include "greybus_protocols.h"
10#include "audio_apbridgea.h" 9#include "audio_apbridgea.h"
11#include "audio_codec.h" 10#include "audio_codec.h"
12 11
diff --git a/drivers/staging/greybus/audio_apbridgea.h b/drivers/staging/greybus/audio_apbridgea.h
index 330fc7a397eb..3f1f4dd2c61a 100644
--- a/drivers/staging/greybus/audio_apbridgea.h
+++ b/drivers/staging/greybus/audio_apbridgea.h
@@ -1,30 +1,6 @@
1/* SPDX-License-Identifier: BSD-3-Clause */ 1/* SPDX-License-Identifier: BSD-3-Clause */
2/** 2/*
3 * Copyright (c) 2015-2016 Google Inc. 3 * Copyright (c) 2015-2016 Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 4 */
29/* 5/*
30 * This is a special protocol for configuring communication over the 6 * This is a special protocol for configuring communication over the
diff --git a/drivers/staging/greybus/audio_codec.h b/drivers/staging/greybus/audio_codec.h
index 9ba09ea9c2fc..cb5d271da1a5 100644
--- a/drivers/staging/greybus/audio_codec.h
+++ b/drivers/staging/greybus/audio_codec.h
@@ -8,12 +8,10 @@
8#ifndef __LINUX_GBAUDIO_CODEC_H 8#ifndef __LINUX_GBAUDIO_CODEC_H
9#define __LINUX_GBAUDIO_CODEC_H 9#define __LINUX_GBAUDIO_CODEC_H
10 10
11#include <linux/greybus.h>
11#include <sound/soc.h> 12#include <sound/soc.h>
12#include <sound/jack.h> 13#include <sound/jack.h>
13 14
14#include "greybus.h"
15#include "greybus_protocols.h"
16
17#define NAME_SIZE 32 15#define NAME_SIZE 32
18#define MAX_DAIS 2 /* APB1, APB2 */ 16#define MAX_DAIS 2 /* APB1, APB2 */
19 17
diff --git a/drivers/staging/greybus/audio_gb.c b/drivers/staging/greybus/audio_gb.c
index 8894f1c87d48..9d8994fdb41a 100644
--- a/drivers/staging/greybus/audio_gb.c
+++ b/drivers/staging/greybus/audio_gb.c
@@ -5,9 +5,7 @@
5 * Copyright 2015-2016 Google Inc. 5 * Copyright 2015-2016 Google Inc.
6 */ 6 */
7 7
8#include "greybus.h" 8#include <linux/greybus.h>
9#include "greybus_protocols.h"
10#include "operation.h"
11#include "audio_codec.h" 9#include "audio_codec.h"
12 10
13/* TODO: Split into separate calls */ 11/* TODO: Split into separate calls */
diff --git a/drivers/staging/greybus/audio_manager.c b/drivers/staging/greybus/audio_manager.c
index c2a4af4c1d06..9b19ea9d3fa1 100644
--- a/drivers/staging/greybus/audio_manager.c
+++ b/drivers/staging/greybus/audio_manager.c
@@ -86,7 +86,7 @@ EXPORT_SYMBOL_GPL(gb_audio_manager_remove);
86void gb_audio_manager_remove_all(void) 86void gb_audio_manager_remove_all(void)
87{ 87{
88 struct gb_audio_manager_module *module, *next; 88 struct gb_audio_manager_module *module, *next;
89 int is_empty = 1; 89 int is_empty;
90 90
91 down_write(&modules_rwsem); 91 down_write(&modules_rwsem);
92 92
diff --git a/drivers/staging/greybus/authentication.c b/drivers/staging/greybus/authentication.c
index a5d7c53df987..297e69f011c7 100644
--- a/drivers/staging/greybus/authentication.c
+++ b/drivers/staging/greybus/authentication.c
@@ -6,8 +6,7 @@
6 * Copyright 2016 Linaro Ltd. 6 * Copyright 2016 Linaro Ltd.
7 */ 7 */
8 8
9#include "greybus.h" 9#include <linux/greybus.h>
10
11#include <linux/cdev.h> 10#include <linux/cdev.h>
12#include <linux/fs.h> 11#include <linux/fs.h>
13#include <linux/ioctl.h> 12#include <linux/ioctl.h>
diff --git a/drivers/staging/greybus/bootrom.c b/drivers/staging/greybus/bootrom.c
index 402e6360834f..a8efb86de140 100644
--- a/drivers/staging/greybus/bootrom.c
+++ b/drivers/staging/greybus/bootrom.c
@@ -10,8 +10,8 @@
10#include <linux/jiffies.h> 10#include <linux/jiffies.h>
11#include <linux/mutex.h> 11#include <linux/mutex.h>
12#include <linux/workqueue.h> 12#include <linux/workqueue.h>
13#include <linux/greybus.h>
13 14
14#include "greybus.h"
15#include "firmware.h" 15#include "firmware.h"
16 16
17/* Timeout, in jiffies, within which the next request must be received */ 17/* Timeout, in jiffies, within which the next request must be received */
diff --git a/drivers/staging/greybus/camera.c b/drivers/staging/greybus/camera.c
index 615c8e7fd51e..b570e13394ac 100644
--- a/drivers/staging/greybus/camera.c
+++ b/drivers/staging/greybus/camera.c
@@ -14,9 +14,9 @@
14#include <linux/string.h> 14#include <linux/string.h>
15#include <linux/uaccess.h> 15#include <linux/uaccess.h>
16#include <linux/vmalloc.h> 16#include <linux/vmalloc.h>
17#include <linux/greybus.h>
17 18
18#include "gb-camera.h" 19#include "gb-camera.h"
19#include "greybus.h"
20#include "greybus_protocols.h" 20#include "greybus_protocols.h"
21 21
22enum gb_camera_debugs_buffer_id { 22enum gb_camera_debugs_buffer_id {
diff --git a/drivers/staging/greybus/firmware.h b/drivers/staging/greybus/firmware.h
index 946221307ef6..5d2564462ffc 100644
--- a/drivers/staging/greybus/firmware.h
+++ b/drivers/staging/greybus/firmware.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Greybus Firmware Management Header 3 * Greybus Firmware Management Header
4 * 4 *
@@ -9,7 +9,7 @@
9#ifndef __FIRMWARE_H 9#ifndef __FIRMWARE_H
10#define __FIRMWARE_H 10#define __FIRMWARE_H
11 11
12#include "greybus.h" 12#include <linux/greybus.h>
13 13
14#define FW_NAME_PREFIX "gmp_" 14#define FW_NAME_PREFIX "gmp_"
15 15
diff --git a/drivers/staging/greybus/fw-core.c b/drivers/staging/greybus/fw-core.c
index 388866d92f5b..57bebf24636b 100644
--- a/drivers/staging/greybus/fw-core.c
+++ b/drivers/staging/greybus/fw-core.c
@@ -8,8 +8,8 @@
8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9 9
10#include <linux/firmware.h> 10#include <linux/firmware.h>
11#include <linux/greybus.h>
11#include "firmware.h" 12#include "firmware.h"
12#include "greybus.h"
13#include "spilib.h" 13#include "spilib.h"
14 14
15struct gb_fw_core { 15struct gb_fw_core {
diff --git a/drivers/staging/greybus/fw-download.c b/drivers/staging/greybus/fw-download.c
index d3b7cccbc10d..543692c567f9 100644
--- a/drivers/staging/greybus/fw-download.c
+++ b/drivers/staging/greybus/fw-download.c
@@ -10,8 +10,8 @@
10#include <linux/jiffies.h> 10#include <linux/jiffies.h>
11#include <linux/mutex.h> 11#include <linux/mutex.h>
12#include <linux/workqueue.h> 12#include <linux/workqueue.h>
13#include <linux/greybus.h>
13#include "firmware.h" 14#include "firmware.h"
14#include "greybus.h"
15 15
16/* Estimated minimum buffer size, actual size can be smaller than this */ 16/* Estimated minimum buffer size, actual size can be smaller than this */
17#define MIN_FETCH_SIZE 512 17#define MIN_FETCH_SIZE 512
diff --git a/drivers/staging/greybus/fw-management.c b/drivers/staging/greybus/fw-management.c
index 71aec14f8181..687c6405c65b 100644
--- a/drivers/staging/greybus/fw-management.c
+++ b/drivers/staging/greybus/fw-management.c
@@ -13,10 +13,10 @@
13#include <linux/idr.h> 13#include <linux/idr.h>
14#include <linux/ioctl.h> 14#include <linux/ioctl.h>
15#include <linux/uaccess.h> 15#include <linux/uaccess.h>
16#include <linux/greybus.h>
16 17
17#include "firmware.h" 18#include "firmware.h"
18#include "greybus_firmware.h" 19#include "greybus_firmware.h"
19#include "greybus.h"
20 20
21#define FW_MGMT_TIMEOUT_MS 1000 21#define FW_MGMT_TIMEOUT_MS 1000
22 22
diff --git a/drivers/staging/greybus/gb-camera.h b/drivers/staging/greybus/gb-camera.h
index ee293e461fc3..5fc469101fc1 100644
--- a/drivers/staging/greybus/gb-camera.h
+++ b/drivers/staging/greybus/gb-camera.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Greybus Camera protocol driver. 3 * Greybus Camera protocol driver.
4 * 4 *
diff --git a/drivers/staging/greybus/gbphy.c b/drivers/staging/greybus/gbphy.c
index 6cb85c3d3572..9fc5c47be9bd 100644
--- a/drivers/staging/greybus/gbphy.c
+++ b/drivers/staging/greybus/gbphy.c
@@ -13,8 +13,8 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/greybus.h>
16 17
17#include "greybus.h"
18#include "gbphy.h" 18#include "gbphy.h"
19 19
20#define GB_GBPHY_AUTOSUSPEND_MS 3000 20#define GB_GBPHY_AUTOSUSPEND_MS 3000
diff --git a/drivers/staging/greybus/gbphy.h b/drivers/staging/greybus/gbphy.h
index 99463489d7d6..087928a586fb 100644
--- a/drivers/staging/greybus/gbphy.h
+++ b/drivers/staging/greybus/gbphy.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Greybus Bridged-Phy Bus driver 3 * Greybus Bridged-Phy Bus driver
4 * 4 *
diff --git a/drivers/staging/greybus/gpio.c b/drivers/staging/greybus/gpio.c
index 3151004d26fb..1ff34abd5692 100644
--- a/drivers/staging/greybus/gpio.c
+++ b/drivers/staging/greybus/gpio.c
@@ -13,8 +13,8 @@
13#include <linux/irqdomain.h> 13#include <linux/irqdomain.h>
14#include <linux/gpio/driver.h> 14#include <linux/gpio/driver.h>
15#include <linux/mutex.h> 15#include <linux/mutex.h>
16#include <linux/greybus.h>
16 17
17#include "greybus.h"
18#include "gbphy.h" 18#include "gbphy.h"
19 19
20struct gb_gpio_line { 20struct gb_gpio_line {
diff --git a/drivers/staging/greybus/greybus_authentication.h b/drivers/staging/greybus/greybus_authentication.h
index 03ea9615b217..7edc7295b7ab 100644
--- a/drivers/staging/greybus/greybus_authentication.h
+++ b/drivers/staging/greybus/greybus_authentication.h
@@ -1,55 +1,9 @@
1// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) 1/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2/* 2/*
3 * Greybus Component Authentication User Header 3 * Greybus Component Authentication User Header
4 * 4 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license.
7 *
8 * GPL LICENSE SUMMARY
9 *
10 * Copyright(c) 2016 Google Inc. All rights reserved. 5 * Copyright(c) 2016 Google Inc. All rights reserved.
11 * Copyright(c) 2016 Linaro Ltd. All rights reserved. 6 * Copyright(c) 2016 Linaro Ltd. All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License version 2 for more details.
21 *
22 * BSD LICENSE
23 *
24 * Copyright(c) 2016 Google Inc. All rights reserved.
25 * Copyright(c) 2016 Linaro Ltd. All rights reserved.
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 *
31 * * Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * * Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in
35 * the documentation and/or other materials provided with the
36 * distribution.
37 * * Neither the name of Google Inc. or Linaro Ltd. nor the names of
38 * its contributors may be used to endorse or promote products
39 * derived from this software without specific prior written
40 * permission.
41 *
42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
46 * LINARO LTD. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
47 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
48 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
49 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
50 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 */ 7 */
54 8
55#ifndef __GREYBUS_AUTHENTICATION_USER_H 9#ifndef __GREYBUS_AUTHENTICATION_USER_H
diff --git a/drivers/staging/greybus/greybus_firmware.h b/drivers/staging/greybus/greybus_firmware.h
index b58281a63ba4..f68fd5e25321 100644
--- a/drivers/staging/greybus/greybus_firmware.h
+++ b/drivers/staging/greybus/greybus_firmware.h
@@ -1,55 +1,9 @@
1// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) 1/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2/* 2/*
3 * Greybus Firmware Management User Header 3 * Greybus Firmware Management User Header
4 * 4 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license.
7 *
8 * GPL LICENSE SUMMARY
9 *
10 * Copyright(c) 2016 Google Inc. All rights reserved. 5 * Copyright(c) 2016 Google Inc. All rights reserved.
11 * Copyright(c) 2016 Linaro Ltd. All rights reserved. 6 * Copyright(c) 2016 Linaro Ltd. All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License version 2 for more details.
21 *
22 * BSD LICENSE
23 *
24 * Copyright(c) 2016 Google Inc. All rights reserved.
25 * Copyright(c) 2016 Linaro Ltd. All rights reserved.
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 *
31 * * Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * * Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in
35 * the documentation and/or other materials provided with the
36 * distribution.
37 * * Neither the name of Google Inc. or Linaro Ltd. nor the names of
38 * its contributors may be used to endorse or promote products
39 * derived from this software without specific prior written
40 * permission.
41 *
42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
46 * LINARO LTD. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
47 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
48 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
49 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
50 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 */ 7 */
54 8
55#ifndef __GREYBUS_FIRMWARE_USER_H 9#ifndef __GREYBUS_FIRMWARE_USER_H
diff --git a/drivers/staging/greybus/hid.c b/drivers/staging/greybus/hid.c
index 8ab810bf5716..04bfd9110502 100644
--- a/drivers/staging/greybus/hid.c
+++ b/drivers/staging/greybus/hid.c
@@ -12,8 +12,7 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/mutex.h> 13#include <linux/mutex.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15 15#include <linux/greybus.h>
16#include "greybus.h"
17 16
18/* Greybus HID device's structure */ 17/* Greybus HID device's structure */
19struct gb_hid { 18struct gb_hid {
diff --git a/drivers/staging/greybus/i2c.c b/drivers/staging/greybus/i2c.c
index 7bb85a75d3b1..ab06fc3b9e7e 100644
--- a/drivers/staging/greybus/i2c.c
+++ b/drivers/staging/greybus/i2c.c
@@ -10,8 +10,8 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/i2c.h> 12#include <linux/i2c.h>
13#include <linux/greybus.h>
13 14
14#include "greybus.h"
15#include "gbphy.h" 15#include "gbphy.h"
16 16
17struct gb_i2c_device { 17struct gb_i2c_device {
@@ -31,7 +31,14 @@ static u32 gb_i2c_functionality_map(u32 gb_i2c_functionality)
31 return gb_i2c_functionality; /* All bits the same for now */ 31 return gb_i2c_functionality; /* All bits the same for now */
32} 32}
33 33
34static int gb_i2c_functionality_operation(struct gb_i2c_device *gb_i2c_dev) 34/*
35 * Do initial setup of the i2c device. This includes verifying we
36 * can support it (based on the protocol version it advertises).
37 * If that's OK, we get and cached its functionality bits.
38 *
39 * Note: gb_i2c_dev->connection is assumed to have been valid.
40 */
41static int gb_i2c_device_setup(struct gb_i2c_device *gb_i2c_dev)
35{ 42{
36 struct gb_i2c_functionality_response response; 43 struct gb_i2c_functionality_response response;
37 u32 functionality; 44 u32 functionality;
@@ -235,19 +242,6 @@ static const struct i2c_algorithm gb_i2c_algorithm = {
235 .functionality = gb_i2c_functionality, 242 .functionality = gb_i2c_functionality,
236}; 243};
237 244
238/*
239 * Do initial setup of the i2c device. This includes verifying we
240 * can support it (based on the protocol version it advertises).
241 * If that's OK, we get and cached its functionality bits.
242 *
243 * Note: gb_i2c_dev->connection is assumed to have been valid.
244 */
245static int gb_i2c_device_setup(struct gb_i2c_device *gb_i2c_dev)
246{
247 /* Assume the functionality never changes, just get it once */
248 return gb_i2c_functionality_operation(gb_i2c_dev);
249}
250
251static int gb_i2c_probe(struct gbphy_device *gbphy_dev, 245static int gb_i2c_probe(struct gbphy_device *gbphy_dev,
252 const struct gbphy_device_id *id) 246 const struct gbphy_device_id *id)
253{ 247{
diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c
index 010ae1e9c7fb..d6ba25f21d80 100644
--- a/drivers/staging/greybus/light.c
+++ b/drivers/staging/greybus/light.c
@@ -11,11 +11,9 @@
11#include <linux/led-class-flash.h> 11#include <linux/led-class-flash.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/greybus.h>
14#include <media/v4l2-flash-led-class.h> 15#include <media/v4l2-flash-led-class.h>
15 16
16#include "greybus.h"
17#include "greybus_protocols.h"
18
19#define NAMES_MAX 32 17#define NAMES_MAX 32
20 18
21struct gb_channel { 19struct gb_channel {
@@ -1098,21 +1096,21 @@ static void gb_lights_channel_release(struct gb_channel *channel)
1098static void gb_lights_light_release(struct gb_light *light) 1096static void gb_lights_light_release(struct gb_light *light)
1099{ 1097{
1100 int i; 1098 int i;
1101 int count;
1102 1099
1103 light->ready = false; 1100 light->ready = false;
1104 1101
1105 count = light->channels_count;
1106
1107 if (light->has_flash) 1102 if (light->has_flash)
1108 gb_lights_light_v4l2_unregister(light); 1103 gb_lights_light_v4l2_unregister(light);
1104 light->has_flash = false;
1109 1105
1110 for (i = 0; i < count; i++) { 1106 for (i = 0; i < light->channels_count; i++)
1111 gb_lights_channel_release(&light->channels[i]); 1107 gb_lights_channel_release(&light->channels[i]);
1112 light->channels_count--; 1108 light->channels_count = 0;
1113 } 1109
1114 kfree(light->channels); 1110 kfree(light->channels);
1111 light->channels = NULL;
1115 kfree(light->name); 1112 kfree(light->name);
1113 light->name = NULL;
1116} 1114}
1117 1115
1118static void gb_lights_release(struct gb_lights *glights) 1116static void gb_lights_release(struct gb_lights *glights)
diff --git a/drivers/staging/greybus/log.c b/drivers/staging/greybus/log.c
index 15a88574dbb0..971f36dccac6 100644
--- a/drivers/staging/greybus/log.c
+++ b/drivers/staging/greybus/log.c
@@ -9,8 +9,7 @@
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/sizes.h> 10#include <linux/sizes.h>
11#include <linux/uaccess.h> 11#include <linux/uaccess.h>
12 12#include <linux/greybus.h>
13#include "greybus.h"
14 13
15struct gb_log { 14struct gb_log {
16 struct gb_connection *connection; 15 struct gb_connection *connection;
@@ -31,14 +30,14 @@ static int gb_log_request_handler(struct gb_operation *op)
31 /* Verify size of payload */ 30 /* Verify size of payload */
32 if (op->request->payload_size < sizeof(*receive)) { 31 if (op->request->payload_size < sizeof(*receive)) {
33 dev_err(dev, "log request too small (%zu < %zu)\n", 32 dev_err(dev, "log request too small (%zu < %zu)\n",
34 op->request->payload_size, sizeof(*receive)); 33 op->request->payload_size, sizeof(*receive));
35 return -EINVAL; 34 return -EINVAL;
36 } 35 }
37 receive = op->request->payload; 36 receive = op->request->payload;
38 len = le16_to_cpu(receive->len); 37 len = le16_to_cpu(receive->len);
39 if (len != (op->request->payload_size - sizeof(*receive))) { 38 if (len != (op->request->payload_size - sizeof(*receive))) {
40 dev_err(dev, "log request wrong size %d vs %zu\n", len, 39 dev_err(dev, "log request wrong size %d vs %zu\n", len,
41 (op->request->payload_size - sizeof(*receive))); 40 (op->request->payload_size - sizeof(*receive)));
42 return -EINVAL; 41 return -EINVAL;
43 } 42 }
44 if (len == 0) { 43 if (len == 0) {
@@ -83,7 +82,7 @@ static int gb_log_probe(struct gb_bundle *bundle,
83 return -ENOMEM; 82 return -ENOMEM;
84 83
85 connection = gb_connection_create(bundle, le16_to_cpu(cport_desc->id), 84 connection = gb_connection_create(bundle, le16_to_cpu(cport_desc->id),
86 gb_log_request_handler); 85 gb_log_request_handler);
87 if (IS_ERR(connection)) { 86 if (IS_ERR(connection)) {
88 retval = PTR_ERR(connection); 87 retval = PTR_ERR(connection);
89 goto error_free; 88 goto error_free;
diff --git a/drivers/staging/greybus/loopback.c b/drivers/staging/greybus/loopback.c
index 48d85ebe404a..583d9708a191 100644
--- a/drivers/staging/greybus/loopback.c
+++ b/drivers/staging/greybus/loopback.c
@@ -25,12 +25,9 @@
25#include <linux/workqueue.h> 25#include <linux/workqueue.h>
26#include <linux/atomic.h> 26#include <linux/atomic.h>
27#include <linux/pm_runtime.h> 27#include <linux/pm_runtime.h>
28 28#include <linux/greybus.h>
29#include <asm/div64.h> 29#include <asm/div64.h>
30 30
31#include "greybus.h"
32#include "connection.h"
33
34#define NSEC_PER_DAY 86400000000000ULL 31#define NSEC_PER_DAY 86400000000000ULL
35 32
36struct gb_loopback_stats { 33struct gb_loopback_stats {
@@ -882,7 +879,7 @@ static int gb_loopback_fn(void *data)
882 gb->type = 0; 879 gb->type = 0;
883 gb->send_count = 0; 880 gb->send_count = 0;
884 sysfs_notify(&gb->dev->kobj, NULL, 881 sysfs_notify(&gb->dev->kobj, NULL,
885 "iteration_count"); 882 "iteration_count");
886 dev_dbg(&bundle->dev, "load test complete\n"); 883 dev_dbg(&bundle->dev, "load test complete\n");
887 } else { 884 } else {
888 dev_dbg(&bundle->dev, 885 dev_dbg(&bundle->dev,
@@ -1054,7 +1051,7 @@ static int gb_loopback_probe(struct gb_bundle *bundle,
1054 1051
1055 /* Allocate kfifo */ 1052 /* Allocate kfifo */
1056 if (kfifo_alloc(&gb->kfifo_lat, kfifo_depth * sizeof(u32), 1053 if (kfifo_alloc(&gb->kfifo_lat, kfifo_depth * sizeof(u32),
1057 GFP_KERNEL)) { 1054 GFP_KERNEL)) {
1058 retval = -ENOMEM; 1055 retval = -ENOMEM;
1059 goto out_conn; 1056 goto out_conn;
1060 } 1057 }
diff --git a/drivers/staging/greybus/power_supply.c b/drivers/staging/greybus/power_supply.c
index 34b40a409ea3..ec96f28887f9 100644
--- a/drivers/staging/greybus/power_supply.c
+++ b/drivers/staging/greybus/power_supply.c
@@ -10,8 +10,7 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/power_supply.h> 11#include <linux/power_supply.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13 13#include <linux/greybus.h>
14#include "greybus.h"
15 14
16#define PROP_MAX 32 15#define PROP_MAX 32
17 16
diff --git a/drivers/staging/greybus/pwm.c b/drivers/staging/greybus/pwm.c
index 4a6d394b6c44..891a6a672378 100644
--- a/drivers/staging/greybus/pwm.c
+++ b/drivers/staging/greybus/pwm.c
@@ -10,8 +10,8 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/pwm.h> 12#include <linux/pwm.h>
13#include <linux/greybus.h>
13 14
14#include "greybus.h"
15#include "gbphy.h" 15#include "gbphy.h"
16 16
17struct gb_pwm_chip { 17struct gb_pwm_chip {
diff --git a/drivers/staging/greybus/raw.c b/drivers/staging/greybus/raw.c
index 838acbe84ca0..64a17dfe3b6e 100644
--- a/drivers/staging/greybus/raw.c
+++ b/drivers/staging/greybus/raw.c
@@ -13,8 +13,7 @@
13#include <linux/fs.h> 13#include <linux/fs.h>
14#include <linux/idr.h> 14#include <linux/idr.h>
15#include <linux/uaccess.h> 15#include <linux/uaccess.h>
16 16#include <linux/greybus.h>
17#include "greybus.h"
18 17
19struct gb_raw { 18struct gb_raw {
20 struct gb_connection *connection; 19 struct gb_connection *connection;
diff --git a/drivers/staging/greybus/sdio.c b/drivers/staging/greybus/sdio.c
index a097a8916b3b..68c5718be827 100644
--- a/drivers/staging/greybus/sdio.c
+++ b/drivers/staging/greybus/sdio.c
@@ -12,8 +12,8 @@
12#include <linux/mmc/mmc.h> 12#include <linux/mmc/mmc.h>
13#include <linux/scatterlist.h> 13#include <linux/scatterlist.h>
14#include <linux/workqueue.h> 14#include <linux/workqueue.h>
15#include <linux/greybus.h>
15 16
16#include "greybus.h"
17#include "gbphy.h" 17#include "gbphy.h"
18 18
19struct gb_sdio_host { 19struct gb_sdio_host {
diff --git a/drivers/staging/greybus/spi.c b/drivers/staging/greybus/spi.c
index 47d896992b35..68e8d272db6d 100644
--- a/drivers/staging/greybus/spi.c
+++ b/drivers/staging/greybus/spi.c
@@ -7,8 +7,8 @@
7 */ 7 */
8 8
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/greybus.h>
10 11
11#include "greybus.h"
12#include "gbphy.h" 12#include "gbphy.h"
13#include "spilib.h" 13#include "spilib.h"
14 14
diff --git a/drivers/staging/greybus/spilib.c b/drivers/staging/greybus/spilib.c
index 2e07c6b41334..fc27c52de74a 100644
--- a/drivers/staging/greybus/spilib.c
+++ b/drivers/staging/greybus/spilib.c
@@ -10,9 +10,9 @@
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/greybus.h>
13#include <linux/spi/spi.h> 14#include <linux/spi/spi.h>
14 15
15#include "greybus.h"
16#include "spilib.h" 16#include "spilib.h"
17 17
18struct gb_spilib { 18struct gb_spilib {
diff --git a/drivers/staging/greybus/spilib.h b/drivers/staging/greybus/spilib.h
index 043d4d32c3ee..9d416839e3be 100644
--- a/drivers/staging/greybus/spilib.h
+++ b/drivers/staging/greybus/spilib.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Greybus SPI library header 3 * Greybus SPI library header
4 * 4 *
diff --git a/drivers/staging/greybus/tools/loopback_test.c b/drivers/staging/greybus/tools/loopback_test.c
index cebc1d90a180..ba6f905f26fa 100644
--- a/drivers/staging/greybus/tools/loopback_test.c
+++ b/drivers/staging/greybus/tools/loopback_test.c
@@ -4,8 +4,6 @@
4 * 4 *
5 * Copyright 2015 Google Inc. 5 * Copyright 2015 Google Inc.
6 * Copyright 2015 Linaro Ltd. 6 * Copyright 2015 Linaro Ltd.
7 *
8 * Provided under the three clause BSD license found in the LICENSE file.
9 */ 7 */
10#include <errno.h> 8#include <errno.h>
11#include <fcntl.h> 9#include <fcntl.h>
diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index b3bffe91ae99..55c51143bb09 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -28,8 +28,8 @@
28#include <linux/kfifo.h> 28#include <linux/kfifo.h>
29#include <linux/workqueue.h> 29#include <linux/workqueue.h>
30#include <linux/completion.h> 30#include <linux/completion.h>
31#include <linux/greybus.h>
31 32
32#include "greybus.h"
33#include "gbphy.h" 33#include "gbphy.h"
34 34
35#define GB_NUM_MINORS 16 /* 16 is more than enough */ 35#define GB_NUM_MINORS 16 /* 16 is more than enough */
diff --git a/drivers/staging/greybus/usb.c b/drivers/staging/greybus/usb.c
index 1c246c73a085..8e9d9d59a357 100644
--- a/drivers/staging/greybus/usb.c
+++ b/drivers/staging/greybus/usb.c
@@ -10,8 +10,8 @@
10#include <linux/slab.h> 10#include <linux/slab.h>
11#include <linux/usb.h> 11#include <linux/usb.h>
12#include <linux/usb/hcd.h> 12#include <linux/usb/hcd.h>
13#include <linux/greybus.h>
13 14
14#include "greybus.h"
15#include "gbphy.h" 15#include "gbphy.h"
16 16
17/* Greybus USB request types */ 17/* Greybus USB request types */
diff --git a/drivers/staging/greybus/vibrator.c b/drivers/staging/greybus/vibrator.c
index 3e5dedeacd5c..0e2b188e5ca3 100644
--- a/drivers/staging/greybus/vibrator.c
+++ b/drivers/staging/greybus/vibrator.c
@@ -13,8 +13,7 @@
13#include <linux/kdev_t.h> 13#include <linux/kdev_t.h>
14#include <linux/idr.h> 14#include <linux/idr.h>
15#include <linux/pm_runtime.h> 15#include <linux/pm_runtime.h>
16 16#include <linux/greybus.h>
17#include "greybus.h"
18 17
19struct gb_vibrator_device { 18struct gb_vibrator_device {
20 struct gb_connection *connection; 19 struct gb_connection *connection;
diff --git a/drivers/staging/iio/accel/adis16240.c b/drivers/staging/iio/accel/adis16240.c
index 62f4b3b1b457..82099db4bf0c 100644
--- a/drivers/staging/iio/accel/adis16240.c
+++ b/drivers/staging/iio/accel/adis16240.c
@@ -309,15 +309,12 @@ static int adis16240_write_raw(struct iio_dev *indio_dev,
309 long mask) 309 long mask)
310{ 310{
311 struct adis *st = iio_priv(indio_dev); 311 struct adis *st = iio_priv(indio_dev);
312 int bits = 10;
313 s16 val16;
314 u8 addr; 312 u8 addr;
315 313
316 switch (mask) { 314 switch (mask) {
317 case IIO_CHAN_INFO_CALIBBIAS: 315 case IIO_CHAN_INFO_CALIBBIAS:
318 val16 = val & ((1 << bits) - 1);
319 addr = adis16240_addresses[chan->scan_index][0]; 316 addr = adis16240_addresses[chan->scan_index][0];
320 return adis_write_reg_16(st, addr, val16); 317 return adis_write_reg_16(st, addr, val & GENMASK(9, 0));
321 } 318 }
322 return -EINVAL; 319 return -EINVAL;
323} 320}
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
index b6d12fe7c12a..e6b660489165 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -25,8 +25,6 @@
25#include <linux/iio/triggered_buffer.h> 25#include <linux/iio/triggered_buffer.h>
26#include <linux/iio/adc/ad_sigma_delta.h> 26#include <linux/iio/adc/ad_sigma_delta.h>
27 27
28#include "ad7192.h"
29
30/* Registers */ 28/* Registers */
31#define AD7192_REG_COMM 0 /* Communications Register (WO, 8-bit) */ 29#define AD7192_REG_COMM 0 /* Communications Register (WO, 8-bit) */
32#define AD7192_REG_STAT 0 /* Status Register (RO, 8-bit) */ 30#define AD7192_REG_STAT 0 /* Status Register (RO, 8-bit) */
@@ -145,6 +143,10 @@
145#define AD7192_EXT_FREQ_MHZ_MAX 5120000 143#define AD7192_EXT_FREQ_MHZ_MAX 5120000
146#define AD7192_INT_FREQ_MHZ 4915200 144#define AD7192_INT_FREQ_MHZ 4915200
147 145
146#define AD7192_NO_SYNC_FILTER 1
147#define AD7192_SYNC3_FILTER 3
148#define AD7192_SYNC4_FILTER 4
149
148/* NOTE: 150/* NOTE:
149 * The AD7190/2/5 features a dual use data out ready DOUT/RDY output. 151 * The AD7190/2/5 features a dual use data out ready DOUT/RDY output.
150 * In order to avoid contentions on the SPI bus, it's therefore necessary 152 * In order to avoid contentions on the SPI bus, it's therefore necessary
@@ -252,7 +254,7 @@ static int ad7192_of_clock_select(struct ad7192_state *st)
252static int ad7192_setup(struct ad7192_state *st, struct device_node *np) 254static int ad7192_setup(struct ad7192_state *st, struct device_node *np)
253{ 255{
254 struct iio_dev *indio_dev = spi_get_drvdata(st->sd.spi); 256 struct iio_dev *indio_dev = spi_get_drvdata(st->sd.spi);
255 bool rej60_en, sinc3_en, refin2_en, chop_en; 257 bool rej60_en, refin2_en;
256 bool buf_en, bipolar, burnout_curr_en; 258 bool buf_en, bipolar, burnout_curr_en;
257 unsigned long long scale_uv; 259 unsigned long long scale_uv;
258 int i, ret, id; 260 int i, ret, id;
@@ -284,24 +286,12 @@ static int ad7192_setup(struct ad7192_state *st, struct device_node *np)
284 if (rej60_en) 286 if (rej60_en)
285 st->mode |= AD7192_MODE_REJ60; 287 st->mode |= AD7192_MODE_REJ60;
286 288
287 sinc3_en = of_property_read_bool(np, "adi,sinc3-filter-enable");
288 if (sinc3_en)
289 st->mode |= AD7192_MODE_SINC3;
290
291 refin2_en = of_property_read_bool(np, "adi,refin2-pins-enable"); 289 refin2_en = of_property_read_bool(np, "adi,refin2-pins-enable");
292 if (refin2_en && st->devid != ID_AD7195) 290 if (refin2_en && st->devid != ID_AD7195)
293 st->conf |= AD7192_CONF_REFSEL; 291 st->conf |= AD7192_CONF_REFSEL;
294 292
295 chop_en = of_property_read_bool(np, "adi,chop-enable"); 293 st->conf &= ~AD7192_CONF_CHOP;
296 if (chop_en) { 294 st->f_order = AD7192_NO_SYNC_FILTER;
297 st->conf |= AD7192_CONF_CHOP;
298 if (sinc3_en)
299 st->f_order = 3; /* SINC 3rd order */
300 else
301 st->f_order = 4; /* SINC 4th order */
302 } else {
303 st->f_order = 1;
304 }
305 295
306 buf_en = of_property_read_bool(np, "adi,buffer-enable"); 296 buf_en = of_property_read_bool(np, "adi,buffer-enable");
307 if (buf_en) 297 if (buf_en)
@@ -313,7 +303,7 @@ static int ad7192_setup(struct ad7192_state *st, struct device_node *np)
313 303
314 burnout_curr_en = of_property_read_bool(np, 304 burnout_curr_en = of_property_read_bool(np,
315 "adi,burnout-currents-enable"); 305 "adi,burnout-currents-enable");
316 if (burnout_curr_en && buf_en && !chop_en) { 306 if (burnout_curr_en && buf_en) {
317 st->conf |= AD7192_CONF_BURN; 307 st->conf |= AD7192_CONF_BURN;
318 } else if (burnout_curr_en) { 308 } else if (burnout_curr_en) {
319 dev_warn(&st->sd.spi->dev, 309 dev_warn(&st->sd.spi->dev,
@@ -411,6 +401,49 @@ static ssize_t ad7192_set(struct device *dev,
411 return ret ? ret : len; 401 return ret ? ret : len;
412} 402}
413 403
404static void ad7192_get_available_filter_freq(struct ad7192_state *st,
405 int *freq)
406{
407 unsigned int fadc;
408
409 /* Formulas for filter at page 25 of the datasheet */
410 fadc = DIV_ROUND_CLOSEST(st->fclk,
411 AD7192_SYNC4_FILTER * AD7192_MODE_RATE(st->mode));
412 freq[0] = DIV_ROUND_CLOSEST(fadc * 240, 1024);
413
414 fadc = DIV_ROUND_CLOSEST(st->fclk,
415 AD7192_SYNC3_FILTER * AD7192_MODE_RATE(st->mode));
416 freq[1] = DIV_ROUND_CLOSEST(fadc * 240, 1024);
417
418 fadc = DIV_ROUND_CLOSEST(st->fclk, AD7192_MODE_RATE(st->mode));
419 freq[2] = DIV_ROUND_CLOSEST(fadc * 230, 1024);
420 freq[3] = DIV_ROUND_CLOSEST(fadc * 272, 1024);
421}
422
423static ssize_t ad7192_show_filter_avail(struct device *dev,
424 struct device_attribute *attr,
425 char *buf)
426{
427 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
428 struct ad7192_state *st = iio_priv(indio_dev);
429 unsigned int freq_avail[4], i;
430 size_t len = 0;
431
432 ad7192_get_available_filter_freq(st, freq_avail);
433
434 for (i = 0; i < ARRAY_SIZE(freq_avail); i++)
435 len += scnprintf(buf + len, PAGE_SIZE - len,
436 "%d.%d ", freq_avail[i] / 1000,
437 freq_avail[i] % 1000);
438
439 buf[len - 1] = '\n';
440
441 return len;
442}
443
444static IIO_DEVICE_ATTR(filter_low_pass_3db_frequency_available,
445 0444, ad7192_show_filter_avail, NULL, 0);
446
414static IIO_DEVICE_ATTR(bridge_switch_en, 0644, 447static IIO_DEVICE_ATTR(bridge_switch_en, 0644,
415 ad7192_show_bridge_switch, ad7192_set, 448 ad7192_show_bridge_switch, ad7192_set,
416 AD7192_REG_GPOCON); 449 AD7192_REG_GPOCON);
@@ -420,6 +453,7 @@ static IIO_DEVICE_ATTR(ac_excitation_en, 0644,
420 AD7192_REG_MODE); 453 AD7192_REG_MODE);
421 454
422static struct attribute *ad7192_attributes[] = { 455static struct attribute *ad7192_attributes[] = {
456 &iio_dev_attr_filter_low_pass_3db_frequency_available.dev_attr.attr,
423 &iio_dev_attr_bridge_switch_en.dev_attr.attr, 457 &iio_dev_attr_bridge_switch_en.dev_attr.attr,
424 &iio_dev_attr_ac_excitation_en.dev_attr.attr, 458 &iio_dev_attr_ac_excitation_en.dev_attr.attr,
425 NULL 459 NULL
@@ -430,6 +464,7 @@ static const struct attribute_group ad7192_attribute_group = {
430}; 464};
431 465
432static struct attribute *ad7195_attributes[] = { 466static struct attribute *ad7195_attributes[] = {
467 &iio_dev_attr_filter_low_pass_3db_frequency_available.dev_attr.attr,
433 &iio_dev_attr_bridge_switch_en.dev_attr.attr, 468 &iio_dev_attr_bridge_switch_en.dev_attr.attr,
434 NULL 469 NULL
435}; 470};
@@ -443,6 +478,75 @@ static unsigned int ad7192_get_temp_scale(bool unipolar)
443 return unipolar ? 2815 * 2 : 2815; 478 return unipolar ? 2815 * 2 : 2815;
444} 479}
445 480
481static int ad7192_set_3db_filter_freq(struct ad7192_state *st,
482 int val, int val2)
483{
484 int freq_avail[4], i, ret, freq;
485 unsigned int diff_new, diff_old;
486 int idx = 0;
487
488 diff_old = U32_MAX;
489 freq = val * 1000 + val2;
490
491 ad7192_get_available_filter_freq(st, freq_avail);
492
493 for (i = 0; i < ARRAY_SIZE(freq_avail); i++) {
494 diff_new = abs(freq - freq_avail[i]);
495 if (diff_new < diff_old) {
496 diff_old = diff_new;
497 idx = i;
498 }
499 }
500
501 switch (idx) {
502 case 0:
503 st->f_order = AD7192_SYNC4_FILTER;
504 st->mode &= ~AD7192_MODE_SINC3;
505
506 st->conf |= AD7192_CONF_CHOP;
507 break;
508 case 1:
509 st->f_order = AD7192_SYNC3_FILTER;
510 st->mode |= AD7192_MODE_SINC3;
511
512 st->conf |= AD7192_CONF_CHOP;
513 break;
514 case 2:
515 st->f_order = AD7192_NO_SYNC_FILTER;
516 st->mode &= ~AD7192_MODE_SINC3;
517
518 st->conf &= ~AD7192_CONF_CHOP;
519 break;
520 case 3:
521 st->f_order = AD7192_NO_SYNC_FILTER;
522 st->mode |= AD7192_MODE_SINC3;
523
524 st->conf &= ~AD7192_CONF_CHOP;
525 break;
526 }
527
528 ret = ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, st->mode);
529 if (ret < 0)
530 return ret;
531
532 return ad_sd_write_reg(&st->sd, AD7192_REG_CONF, 3, st->conf);
533}
534
535static int ad7192_get_3db_filter_freq(struct ad7192_state *st)
536{
537 unsigned int fadc;
538
539 fadc = DIV_ROUND_CLOSEST(st->fclk,
540 st->f_order * AD7192_MODE_RATE(st->mode));
541
542 if (st->conf & AD7192_CONF_CHOP)
543 return DIV_ROUND_CLOSEST(fadc * 240, 1024);
544 if (st->mode & AD7192_MODE_SINC3)
545 return DIV_ROUND_CLOSEST(fadc * 272, 1024);
546 else
547 return DIV_ROUND_CLOSEST(fadc * 230, 1024);
548}
549
446static int ad7192_read_raw(struct iio_dev *indio_dev, 550static int ad7192_read_raw(struct iio_dev *indio_dev,
447 struct iio_chan_spec const *chan, 551 struct iio_chan_spec const *chan,
448 int *val, 552 int *val,
@@ -483,6 +587,10 @@ static int ad7192_read_raw(struct iio_dev *indio_dev,
483 *val = st->fclk / 587 *val = st->fclk /
484 (st->f_order * 1024 * AD7192_MODE_RATE(st->mode)); 588 (st->f_order * 1024 * AD7192_MODE_RATE(st->mode));
485 return IIO_VAL_INT; 589 return IIO_VAL_INT;
590 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
591 *val = ad7192_get_3db_filter_freq(st);
592 *val2 = 1000;
593 return IIO_VAL_FRACTIONAL;
486 } 594 }
487 595
488 return -EINVAL; 596 return -EINVAL;
@@ -537,6 +645,9 @@ static int ad7192_write_raw(struct iio_dev *indio_dev,
537 st->mode |= AD7192_MODE_RATE(div); 645 st->mode |= AD7192_MODE_RATE(div);
538 ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, st->mode); 646 ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, st->mode);
539 break; 647 break;
648 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
649 ret = ad7192_set_3db_filter_freq(st, val, val2 / 1000);
650 break;
540 default: 651 default:
541 ret = -EINVAL; 652 ret = -EINVAL;
542 } 653 }
@@ -555,6 +666,8 @@ static int ad7192_write_raw_get_fmt(struct iio_dev *indio_dev,
555 return IIO_VAL_INT_PLUS_NANO; 666 return IIO_VAL_INT_PLUS_NANO;
556 case IIO_CHAN_INFO_SAMP_FREQ: 667 case IIO_CHAN_INFO_SAMP_FREQ:
557 return IIO_VAL_INT; 668 return IIO_VAL_INT;
669 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
670 return IIO_VAL_INT_PLUS_MICRO;
558 default: 671 default:
559 return -EINVAL; 672 return -EINVAL;
560 } 673 }
@@ -655,6 +768,8 @@ static int ad7192_channels_config(struct iio_dev *indio_dev)
655 768
656 for (i = 0; i < indio_dev->num_channels; i++) { 769 for (i = 0; i < indio_dev->num_channels; i++) {
657 *chan = channels[i]; 770 *chan = channels[i];
771 chan->info_mask_shared_by_all |=
772 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY);
658 if (chan->type != IIO_TEMP) 773 if (chan->type != IIO_TEMP)
659 chan->info_mask_shared_by_type_available |= 774 chan->info_mask_shared_by_type_available |=
660 BIT(IIO_CHAN_INFO_SCALE); 775 BIT(IIO_CHAN_INFO_SCALE);
@@ -666,16 +781,10 @@ static int ad7192_channels_config(struct iio_dev *indio_dev)
666 781
667static int ad7192_probe(struct spi_device *spi) 782static int ad7192_probe(struct spi_device *spi)
668{ 783{
669 const struct ad7192_platform_data *pdata = dev_get_platdata(&spi->dev);
670 struct ad7192_state *st; 784 struct ad7192_state *st;
671 struct iio_dev *indio_dev; 785 struct iio_dev *indio_dev;
672 int ret, voltage_uv = 0; 786 int ret, voltage_uv = 0;
673 787
674 if (!pdata) {
675 dev_err(&spi->dev, "no platform data?\n");
676 return -ENODEV;
677 }
678
679 if (!spi->irq) { 788 if (!spi->irq) {
680 dev_err(&spi->dev, "no IRQ?\n"); 789 dev_err(&spi->dev, "no IRQ?\n");
681 return -ENODEV; 790 return -ENODEV;
@@ -713,12 +822,10 @@ static int ad7192_probe(struct spi_device *spi)
713 822
714 voltage_uv = regulator_get_voltage(st->avdd); 823 voltage_uv = regulator_get_voltage(st->avdd);
715 824
716 if (pdata->vref_mv) 825 if (voltage_uv)
717 st->int_vref_mv = pdata->vref_mv;
718 else if (voltage_uv)
719 st->int_vref_mv = voltage_uv / 1000; 826 st->int_vref_mv = voltage_uv / 1000;
720 else 827 else
721 dev_warn(&spi->dev, "reference voltage undefined\n"); 828 dev_err(&spi->dev, "Device tree error, reference voltage undefined\n");
722 829
723 spi_set_drvdata(spi, indio_dev); 830 spi_set_drvdata(spi, indio_dev);
724 st->devid = spi_get_device_id(spi)->driver_data; 831 st->devid = spi_get_device_id(spi)->driver_data;
@@ -809,11 +916,23 @@ static const struct spi_device_id ad7192_id[] = {
809 {"ad7195", ID_AD7195}, 916 {"ad7195", ID_AD7195},
810 {} 917 {}
811}; 918};
919
812MODULE_DEVICE_TABLE(spi, ad7192_id); 920MODULE_DEVICE_TABLE(spi, ad7192_id);
813 921
922static const struct of_device_id ad7192_of_match[] = {
923 { .compatible = "adi,ad7190" },
924 { .compatible = "adi,ad7192" },
925 { .compatible = "adi,ad7193" },
926 { .compatible = "adi,ad7195" },
927 {}
928};
929
930MODULE_DEVICE_TABLE(of, ad7192_of_match);
931
814static struct spi_driver ad7192_driver = { 932static struct spi_driver ad7192_driver = {
815 .driver = { 933 .driver = {
816 .name = "ad7192", 934 .name = "ad7192",
935 .of_match_table = ad7192_of_match,
817 }, 936 },
818 .probe = ad7192_probe, 937 .probe = ad7192_probe,
819 .remove = ad7192_remove, 938 .remove = ad7192_remove,
diff --git a/drivers/staging/iio/adc/ad7192.h b/drivers/staging/iio/adc/ad7192.h
deleted file mode 100644
index f3669e1df084..000000000000
--- a/drivers/staging/iio/adc/ad7192.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * AD7190 AD7192 AD7195 SPI ADC driver
4 *
5 * Copyright 2011 Analog Devices Inc.
6 */
7#ifndef IIO_ADC_AD7192_H_
8#define IIO_ADC_AD7192_H_
9
10/*
11 * TODO: struct ad7192_platform_data needs to go into include/linux/iio
12 */
13
14/**
15 * struct ad7192_platform_data - platform/board specific information
16 * @vref_mv: the external reference voltage in millivolt
17 * @clock_source_sel: [0..3]
18 * 0 External 4.92 MHz clock connected from MCLK1 to MCLK2
19 * 1 External Clock applied to MCLK2
20 * 2 Internal 4.92 MHz Clock not available at the MCLK2 pin
21 * 3 Internal 4.92 MHz Clock available at the MCLK2 pin
22 * @ext_clk_Hz: the external clock frequency in Hz, if not set
23 * the driver uses the internal clock (16.776 MHz)
24 * @refin2_en: REFIN1/REFIN2 Reference Select (AD7190/2 only)
25 * @rej60_en: 50/60Hz notch filter enable
26 * @sinc3_en: SINC3 filter enable (default SINC4)
27 * @chop_en: CHOP mode enable
28 * @buf_en: buffered input mode enable
29 * @unipolar_en: unipolar mode enable
30 * @burnout_curr_en: constant current generators on AIN(+|-) enable
31 */
32
33struct ad7192_platform_data {
34 u16 vref_mv;
35};
36
37#endif /* IIO_ADC_AD7192_H_ */
diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c
index 0c1bd108c386..4b25a3a314ed 100644
--- a/drivers/staging/iio/resolver/ad2s1210.c
+++ b/drivers/staging/iio/resolver/ad2s1210.c
@@ -671,7 +671,7 @@ static int ad2s1210_probe(struct spi_device *spi)
671 indio_dev->num_channels = ARRAY_SIZE(ad2s1210_channels); 671 indio_dev->num_channels = ARRAY_SIZE(ad2s1210_channels);
672 indio_dev->name = spi_get_device_id(spi)->name; 672 indio_dev->name = spi_get_device_id(spi)->name;
673 673
674 ret = iio_device_register(indio_dev); 674 ret = devm_iio_device_register(&spi->dev, indio_dev);
675 if (ret) 675 if (ret)
676 return ret; 676 return ret;
677 677
@@ -683,15 +683,6 @@ static int ad2s1210_probe(struct spi_device *spi)
683 return 0; 683 return 0;
684} 684}
685 685
686static int ad2s1210_remove(struct spi_device *spi)
687{
688 struct iio_dev *indio_dev = spi_get_drvdata(spi);
689
690 iio_device_unregister(indio_dev);
691
692 return 0;
693}
694
695static const struct of_device_id ad2s1210_of_match[] = { 686static const struct of_device_id ad2s1210_of_match[] = {
696 { .compatible = "adi,ad2s1210", }, 687 { .compatible = "adi,ad2s1210", },
697 { } 688 { }
@@ -710,7 +701,6 @@ static struct spi_driver ad2s1210_driver = {
710 .of_match_table = of_match_ptr(ad2s1210_of_match), 701 .of_match_table = of_match_ptr(ad2s1210_of_match),
711 }, 702 },
712 .probe = ad2s1210_probe, 703 .probe = ad2s1210_probe,
713 .remove = ad2s1210_remove,
714 .id_table = ad2s1210_id, 704 .id_table = ad2s1210_id,
715}; 705};
716module_spi_driver(ad2s1210_driver); 706module_spi_driver(ad2s1210_driver);
diff --git a/drivers/staging/isdn/hysdn/hysdn_net.c b/drivers/staging/isdn/hysdn/hysdn_net.c
index bea37ae30ebb..dcb9ef7a2651 100644
--- a/drivers/staging/isdn/hysdn/hysdn_net.c
+++ b/drivers/staging/isdn/hysdn/hysdn_net.c
@@ -286,7 +286,7 @@ hysdn_net_create(hysdn_card *card)
286 286
287 if (card->debug_flags & LOG_NET_INIT) 287 if (card->debug_flags & LOG_NET_INIT)
288 hysdn_addlog(card, "network device created"); 288 hysdn_addlog(card, "network device created");
289 return (0); /* and return success */ 289 return 0; /* and return success */
290} /* hysdn_net_create */ 290} /* hysdn_net_create */
291 291
292/***************************************************************************/ 292/***************************************************************************/
diff --git a/drivers/staging/isdn/hysdn/hysdn_procconf.c b/drivers/staging/isdn/hysdn/hysdn_procconf.c
index 73079213ec94..48afd9f5316e 100644
--- a/drivers/staging/isdn/hysdn/hysdn_procconf.c
+++ b/drivers/staging/isdn/hysdn/hysdn_procconf.c
@@ -382,7 +382,7 @@ hysdn_procconf_init(void)
382 } 382 }
383 383
384 printk(KERN_NOTICE "HYSDN: procfs initialised\n"); 384 printk(KERN_NOTICE "HYSDN: procfs initialised\n");
385 return (0); 385 return 0;
386} /* hysdn_procconf_init */ 386} /* hysdn_procconf_init */
387 387
388/*************************************************************************************/ 388/*************************************************************************************/
diff --git a/drivers/staging/kpc2000/kpc2000/cell_probe.c b/drivers/staging/kpc2000/kpc2000/cell_probe.c
index c124a836db27..738122afc2ae 100644
--- a/drivers/staging/kpc2000/kpc2000/cell_probe.c
+++ b/drivers/staging/kpc2000/kpc2000/cell_probe.c
@@ -53,15 +53,15 @@ struct core_table_entry {
53static 53static
54void parse_core_table_entry_v0(struct core_table_entry *cte, const u64 read_val) 54void parse_core_table_entry_v0(struct core_table_entry *cte, const u64 read_val)
55{ 55{
56 cte->type = ((read_val & 0xFFF0000000000000) >> 52); 56 cte->type = ((read_val & 0xFFF0000000000000UL) >> 52);
57 cte->offset = ((read_val & 0x00000000FFFF0000) >> 16) * 4096; 57 cte->offset = ((read_val & 0x00000000FFFF0000UL) >> 16) * 4096;
58 cte->length = ((read_val & 0x0000FFFF00000000) >> 32) * 8; 58 cte->length = ((read_val & 0x0000FFFF00000000UL) >> 32) * 8;
59 cte->s2c_dma_present = ((read_val & 0x0008000000000000) >> 51); 59 cte->s2c_dma_present = ((read_val & 0x0008000000000000UL) >> 51);
60 cte->s2c_dma_channel_num = ((read_val & 0x0007000000000000) >> 48); 60 cte->s2c_dma_channel_num = ((read_val & 0x0007000000000000UL) >> 48);
61 cte->c2s_dma_present = ((read_val & 0x0000000000008000) >> 15); 61 cte->c2s_dma_present = ((read_val & 0x0000000000008000UL) >> 15);
62 cte->c2s_dma_channel_num = ((read_val & 0x0000000000007000) >> 12); 62 cte->c2s_dma_channel_num = ((read_val & 0x0000000000007000UL) >> 12);
63 cte->irq_count = ((read_val & 0x0000000000000C00) >> 10); 63 cte->irq_count = ((read_val & 0x0000000000000C00UL) >> 10);
64 cte->irq_base_num = ((read_val & 0x00000000000003F8) >> 3); 64 cte->irq_base_num = ((read_val & 0x00000000000003F8UL) >> 3);
65} 65}
66 66
67static 67static
diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index cb05cca687e1..0a23727d0dc3 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -205,7 +205,7 @@ static void wait_and_read_ssid(struct kp2000_device *pcard)
205 u64 read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID); 205 u64 read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
206 unsigned long timeout; 206 unsigned long timeout;
207 207
208 if (read_val & 0x8000000000000000) { 208 if (read_val & 0x8000000000000000UL) {
209 pcard->ssid = read_val; 209 pcard->ssid = read_val;
210 return; 210 return;
211 } 211 }
@@ -213,7 +213,7 @@ static void wait_and_read_ssid(struct kp2000_device *pcard)
213 timeout = jiffies + (HZ * 2); 213 timeout = jiffies + (HZ * 2);
214 do { 214 do {
215 read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID); 215 read_val = readq(pcard->sysinfo_regs_base + REG_FPGA_SSID);
216 if (read_val & 0x8000000000000000) { 216 if (read_val & 0x8000000000000000UL) {
217 pcard->ssid = read_val; 217 pcard->ssid = read_val;
218 return; 218 return;
219 } 219 }
@@ -241,16 +241,16 @@ static int read_system_regs(struct kp2000_device *pcard)
241 } 241 }
242 242
243 read_val = readq(pcard->sysinfo_regs_base + REG_CARD_ID_AND_BUILD); 243 read_val = readq(pcard->sysinfo_regs_base + REG_CARD_ID_AND_BUILD);
244 pcard->card_id = (read_val & 0xFFFFFFFF00000000) >> 32; 244 pcard->card_id = (read_val & 0xFFFFFFFF00000000UL) >> 32;
245 pcard->build_version = (read_val & 0x00000000FFFFFFFF) >> 0; 245 pcard->build_version = (read_val & 0x00000000FFFFFFFFUL) >> 0;
246 246
247 read_val = readq(pcard->sysinfo_regs_base + REG_DATE_AND_TIME_STAMPS); 247 read_val = readq(pcard->sysinfo_regs_base + REG_DATE_AND_TIME_STAMPS);
248 pcard->build_datestamp = (read_val & 0xFFFFFFFF00000000) >> 32; 248 pcard->build_datestamp = (read_val & 0xFFFFFFFF00000000UL) >> 32;
249 pcard->build_timestamp = (read_val & 0x00000000FFFFFFFF) >> 0; 249 pcard->build_timestamp = (read_val & 0x00000000FFFFFFFFUL) >> 0;
250 250
251 read_val = readq(pcard->sysinfo_regs_base + REG_CORE_TABLE_OFFSET); 251 read_val = readq(pcard->sysinfo_regs_base + REG_CORE_TABLE_OFFSET);
252 pcard->core_table_length = (read_val & 0xFFFFFFFF00000000) >> 32; 252 pcard->core_table_length = (read_val & 0xFFFFFFFF00000000UL) >> 32;
253 pcard->core_table_offset = (read_val & 0x00000000FFFFFFFF) >> 0; 253 pcard->core_table_offset = (read_val & 0x00000000FFFFFFFFUL) >> 0;
254 254
255 wait_and_read_ssid(pcard); 255 wait_and_read_ssid(pcard);
256 256
@@ -401,7 +401,7 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
401 goto err_release_dma; 401 goto err_release_dma;
402 402
403 // Disable all "user" interrupts because they're not used yet. 403 // Disable all "user" interrupts because they're not used yet.
404 writeq(0xFFFFFFFFFFFFFFFF, 404 writeq(0xFFFFFFFFFFFFFFFFUL,
405 pcard->sysinfo_regs_base + REG_INTERRUPT_MASK); 405 pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);
406 406
407 // let the card master PCIe 407 // let the card master PCIe
diff --git a/drivers/staging/kpc2000/kpc2000_i2c.c b/drivers/staging/kpc2000/kpc2000_i2c.c
index b108da4ac633..bc02534d8dc3 100644
--- a/drivers/staging/kpc2000/kpc2000_i2c.c
+++ b/drivers/staging/kpc2000/kpc2000_i2c.c
@@ -123,9 +123,9 @@ struct i2c_device {
123 123
124// FIXME! 124// FIXME!
125#undef inb_p 125#undef inb_p
126#define inb_p(a) readq((void *)a) 126#define inb_p(a) readq((void __iomem *)a)
127#undef outb_p 127#undef outb_p
128#define outb_p(d, a) writeq(d, (void *)a) 128#define outb_p(d, a) writeq(d, (void __iomem *)a)
129 129
130/* Make sure the SMBus host is ready to start transmitting. 130/* Make sure the SMBus host is ready to start transmitting.
131 * Return 0 if it is, -EBUSY if it is not. 131 * Return 0 if it is, -EBUSY if it is not.
diff --git a/drivers/staging/kpc2000/kpc2000_spi.c b/drivers/staging/kpc2000/kpc2000_spi.c
index 35ac1d7070b3..3be33c450cab 100644
--- a/drivers/staging/kpc2000/kpc2000_spi.c
+++ b/drivers/staging/kpc2000/kpc2000_spi.c
@@ -412,8 +412,7 @@ kp_spi_cleanup(struct spi_device *spidev)
412{ 412{
413 struct kp_spi_controller_state *cs = spidev->controller_state; 413 struct kp_spi_controller_state *cs = spidev->controller_state;
414 414
415 if (cs) 415 kfree(cs);
416 kfree(cs);
417} 416}
418 417
419/****************** 418/******************
diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c b/drivers/staging/kpc2000/kpc_dma/fileops.c
index 48ca88bc6b0b..cb52bd9a6d2f 100644
--- a/drivers/staging/kpc2000/kpc_dma/fileops.c
+++ b/drivers/staging/kpc2000/kpc_dma/fileops.c
@@ -146,15 +146,15 @@ static int kpc_dma_transfer(struct dev_private_data *priv,
146 card_addr += desc->DescByteCount; 146 card_addr += desc->DescByteCount;
147 147
148 dma_addr = sg_dma_address(sg) + (p * 0x80000); 148 dma_addr = sg_dma_address(sg) + (p * 0x80000);
149 desc->DescSystemAddrLS = (dma_addr & 0x00000000FFFFFFFF) >> 0; 149 desc->DescSystemAddrLS = (dma_addr & 0x00000000FFFFFFFFUL) >> 0;
150 desc->DescSystemAddrMS = (dma_addr & 0xFFFFFFFF00000000) >> 32; 150 desc->DescSystemAddrMS = (dma_addr & 0xFFFFFFFF00000000UL) >> 32;
151 151
152 user_ctl = acd->priv->user_ctl; 152 user_ctl = acd->priv->user_ctl;
153 if (i == acd->mapped_entry_count-1 && p == pcnt-1) { 153 if (i == acd->mapped_entry_count-1 && p == pcnt-1) {
154 user_ctl = acd->priv->user_ctl_last; 154 user_ctl = acd->priv->user_ctl_last;
155 } 155 }
156 desc->DescUserControlLS = (user_ctl & 0x00000000FFFFFFFF) >> 0; 156 desc->DescUserControlLS = (user_ctl & 0x00000000FFFFFFFFUL) >> 0;
157 desc->DescUserControlMS = (user_ctl & 0xFFFFFFFF00000000) >> 32; 157 desc->DescUserControlMS = (user_ctl & 0xFFFFFFFF00000000UL) >> 32;
158 158
159 if (i == acd->mapped_entry_count-1 && p == pcnt-1) 159 if (i == acd->mapped_entry_count-1 && p == pcnt-1)
160 desc->acd = acd; 160 desc->acd = acd;
diff --git a/drivers/staging/media/allegro-dvt/allegro-core.c b/drivers/staging/media/allegro-dvt/allegro-core.c
index f050c7347fd5..6f0cd0784786 100644
--- a/drivers/staging/media/allegro-dvt/allegro-core.c
+++ b/drivers/staging/media/allegro-dvt/allegro-core.c
@@ -2947,10 +2947,8 @@ static int allegro_probe(struct platform_device *pdev)
2947 } 2947 }
2948 2948
2949 irq = platform_get_irq(pdev, 0); 2949 irq = platform_get_irq(pdev, 0);
2950 if (irq < 0) { 2950 if (irq < 0)
2951 dev_err(&pdev->dev, "failed to get irq resource\n");
2952 return irq; 2951 return irq;
2953 }
2954 ret = devm_request_threaded_irq(&pdev->dev, irq, 2952 ret = devm_request_threaded_irq(&pdev->dev, irq,
2955 allegro_hardirq, 2953 allegro_hardirq,
2956 allegro_irq_thread, 2954 allegro_irq_thread,
diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index d8b6816b643b..6d9d41170832 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -797,10 +797,8 @@ static int hantro_probe(struct platform_device *pdev)
797 continue; 797 continue;
798 798
799 irq = platform_get_irq_byname(vpu->pdev, irq_name); 799 irq = platform_get_irq_byname(vpu->pdev, irq_name);
800 if (irq <= 0) { 800 if (irq <= 0)
801 dev_err(vpu->dev, "Could not get %s IRQ.\n", irq_name);
802 return -ENXIO; 801 return -ENXIO;
803 }
804 802
805 ret = devm_request_irq(vpu->dev, irq, 803 ret = devm_request_irq(vpu->dev, irq,
806 vpu->variant->irqs[i].handler, 0, 804 vpu->variant->irqs[i].handler, 0,
diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 4ca79ff4c9b3..bfd6b5fbf484 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1205,10 +1205,8 @@ static int imx7_csi_probe(struct platform_device *pdev)
1205 } 1205 }
1206 1206
1207 csi->irq = platform_get_irq(pdev, 0); 1207 csi->irq = platform_get_irq(pdev, 0);
1208 if (csi->irq < 0) { 1208 if (csi->irq < 0)
1209 dev_err(dev, "Missing platform resources data\n");
1210 return csi->irq; 1209 return csi->irq;
1211 }
1212 1210
1213 csi->regbase = devm_platform_ioremap_resource(pdev, 0); 1211 csi->regbase = devm_platform_ioremap_resource(pdev, 0);
1214 if (IS_ERR(csi->regbase)) 1212 if (IS_ERR(csi->regbase))
diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index d1cdf011c8f1..73d8354e618c 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -975,10 +975,8 @@ static int mipi_csis_probe(struct platform_device *pdev)
975 return PTR_ERR(state->regs); 975 return PTR_ERR(state->regs);
976 976
977 state->irq = platform_get_irq(pdev, 0); 977 state->irq = platform_get_irq(pdev, 0);
978 if (state->irq < 0) { 978 if (state->irq < 0)
979 dev_err(dev, "Failed to get irq\n");
980 return state->irq; 979 return state->irq;
981 }
982 980
983 ret = mipi_csis_clk_get(state); 981 ret = mipi_csis_clk_get(state);
984 if (ret < 0) 982 if (ret < 0)
diff --git a/drivers/staging/media/meson/vdec/esparser.c b/drivers/staging/media/meson/vdec/esparser.c
index 3a21a8cec799..95102a4bdc62 100644
--- a/drivers/staging/media/meson/vdec/esparser.c
+++ b/drivers/staging/media/meson/vdec/esparser.c
@@ -301,10 +301,8 @@ int esparser_init(struct platform_device *pdev, struct amvdec_core *core)
301 int irq; 301 int irq;
302 302
303 irq = platform_get_irq_byname(pdev, "esparser"); 303 irq = platform_get_irq_byname(pdev, "esparser");
304 if (irq < 0) { 304 if (irq < 0)
305 dev_err(dev, "Failed getting ESPARSER IRQ from dtb\n");
306 return irq; 305 return irq;
307 }
308 306
309 ret = devm_request_irq(dev, irq, esparser_isr, IRQF_SHARED, 307 ret = devm_request_irq(dev, irq, esparser_isr, IRQF_SHARED,
310 "esparserirq", core); 308 "esparserirq", core);
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index c8be1db532ab..1a966cb2f3a6 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -1276,7 +1276,6 @@ static int iss_probe(struct platform_device *pdev)
1276 /* Interrupt */ 1276 /* Interrupt */
1277 ret = platform_get_irq(pdev, 0); 1277 ret = platform_get_irq(pdev, 0);
1278 if (ret <= 0) { 1278 if (ret <= 0) {
1279 dev_err(iss->dev, "No IRQ resource\n");
1280 ret = -ENODEV; 1279 ret = -ENODEV;
1281 goto error_iss; 1280 goto error_iss;
1282 } 1281 }
diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_hw.c b/drivers/staging/media/sunxi/cedrus/cedrus_hw.c
index fc8579b90dab..a942cd9bed57 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_hw.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_hw.c
@@ -157,11 +157,8 @@ int cedrus_hw_probe(struct cedrus_dev *dev)
157 dev->capabilities = variant->capabilities; 157 dev->capabilities = variant->capabilities;
158 158
159 irq_dec = platform_get_irq(dev->pdev, 0); 159 irq_dec = platform_get_irq(dev->pdev, 0);
160 if (irq_dec <= 0) { 160 if (irq_dec <= 0)
161 dev_err(dev->dev, "Failed to get IRQ\n");
162
163 return irq_dec; 161 return irq_dec;
164 }
165 ret = devm_request_irq(dev->dev, irq_dec, cedrus_irq, 162 ret = devm_request_irq(dev->dev, irq_dec, cedrus_irq,
166 0, dev_name(dev->dev), dev); 163 0, dev_name(dev->dev), dev);
167 if (ret) { 164 if (ret) {
diff --git a/drivers/staging/most/cdev/cdev.c b/drivers/staging/most/cdev/cdev.c
index d0cc0b746107..724d098aeef0 100644
--- a/drivers/staging/most/cdev/cdev.c
+++ b/drivers/staging/most/cdev/cdev.c
@@ -463,10 +463,8 @@ static int comp_probe(struct most_interface *iface, int channel_id,
463 spin_lock_init(&c->unlink); 463 spin_lock_init(&c->unlink);
464 INIT_KFIFO(c->fifo); 464 INIT_KFIFO(c->fifo);
465 retval = kfifo_alloc(&c->fifo, cfg->num_buffers, GFP_KERNEL); 465 retval = kfifo_alloc(&c->fifo, cfg->num_buffers, GFP_KERNEL);
466 if (retval) { 466 if (retval)
467 pr_info("failed to alloc channel kfifo");
468 goto err_del_cdev_and_free_channel; 467 goto err_del_cdev_and_free_channel;
469 }
470 init_waitqueue_head(&c->wq); 468 init_waitqueue_head(&c->wq);
471 mutex_init(&c->io_mutex); 469 mutex_init(&c->io_mutex);
472 spin_lock_irqsave(&ch_list_lock, cl_flags); 470 spin_lock_irqsave(&ch_list_lock, cl_flags);
diff --git a/drivers/staging/most/core.c b/drivers/staging/most/core.c
index b9841adb7181..8e9a0b67c6ed 100644
--- a/drivers/staging/most/core.c
+++ b/drivers/staging/most/core.c
@@ -303,7 +303,8 @@ static ssize_t set_datatype_show(struct device *dev,
303 303
304 for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) { 304 for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) {
305 if (c->cfg.data_type & ch_data_type[i].most_ch_data_type) 305 if (c->cfg.data_type & ch_data_type[i].most_ch_data_type)
306 return snprintf(buf, PAGE_SIZE, "%s", ch_data_type[i].name); 306 return snprintf(buf, PAGE_SIZE, "%s",
307 ch_data_type[i].name);
307 } 308 }
308 return snprintf(buf, PAGE_SIZE, "unconfigured\n"); 309 return snprintf(buf, PAGE_SIZE, "unconfigured\n");
309} 310}
@@ -721,6 +722,7 @@ int most_add_link(char *mdev, char *mdev_ch, char *comp_name, char *link_name,
721 722
722 return link_channel_to_component(c, comp, link_name, comp_param); 723 return link_channel_to_component(c, comp, link_name, comp_param);
723} 724}
725
724/** 726/**
725 * remove_link_store - store function for remove_link attribute 727 * remove_link_store - store function for remove_link attribute
726 * @drv: device driver 728 * @drv: device driver
diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c
index 31fbc1a75b06..64c979155a49 100644
--- a/drivers/staging/most/dim2/dim2.c
+++ b/drivers/staging/most/dim2/dim2.c
@@ -129,25 +129,6 @@ bool dim2_sysfs_get_state_cb(void)
129} 129}
130 130
131/** 131/**
132 * dimcb_io_read - callback from HAL to read an I/O register
133 * @ptr32: register address
134 */
135u32 dimcb_io_read(u32 __iomem *ptr32)
136{
137 return readl(ptr32);
138}
139
140/**
141 * dimcb_io_write - callback from HAL to write value to an I/O register
142 * @ptr32: register address
143 * @value: value to write
144 */
145void dimcb_io_write(u32 __iomem *ptr32, u32 value)
146{
147 writel(value, ptr32);
148}
149
150/**
151 * dimcb_on_error - callback from HAL to report miscommunication between 132 * dimcb_on_error - callback from HAL to report miscommunication between
152 * HDM and HAL 133 * HDM and HAL
153 * @error_id: Error ID 134 * @error_id: Error ID
@@ -797,7 +778,6 @@ static int dim2_probe(struct platform_device *pdev)
797 778
798 irq = platform_get_irq(pdev, AHB0_INT_IDX); 779 irq = platform_get_irq(pdev, AHB0_INT_IDX);
799 if (irq < 0) { 780 if (irq < 0) {
800 dev_err(&pdev->dev, "failed to get ahb0_int irq: %d\n", irq);
801 ret = irq; 781 ret = irq;
802 goto err_shutdown_dim; 782 goto err_shutdown_dim;
803 } 783 }
@@ -811,7 +791,6 @@ static int dim2_probe(struct platform_device *pdev)
811 791
812 irq = platform_get_irq(pdev, MLB_INT_IDX); 792 irq = platform_get_irq(pdev, MLB_INT_IDX);
813 if (irq < 0) { 793 if (irq < 0) {
814 dev_err(&pdev->dev, "failed to get mlb_int irq: %d\n", irq);
815 ret = irq; 794 ret = irq;
816 goto err_shutdown_dim; 795 goto err_shutdown_dim;
817 } 796 }
diff --git a/drivers/staging/most/dim2/hal.c b/drivers/staging/most/dim2/hal.c
index 699e02f83bd4..39e17a7d2f24 100644
--- a/drivers/staging/most/dim2/hal.c
+++ b/drivers/staging/most/dim2/hal.c
@@ -13,6 +13,7 @@
13#include "reg.h" 13#include "reg.h"
14#include <linux/stddef.h> 14#include <linux/stddef.h>
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/io.h>
16 17
17/* 18/*
18 * Size factor for isochronous DBR buffer. 19 * Size factor for isochronous DBR buffer.
@@ -143,13 +144,13 @@ static void free_dbr(int offs, int size)
143 144
144static void dim2_transfer_madr(u32 val) 145static void dim2_transfer_madr(u32 val)
145{ 146{
146 dimcb_io_write(&g.dim2->MADR, val); 147 writel(val, &g.dim2->MADR);
147 148
148 /* wait for transfer completion */ 149 /* wait for transfer completion */
149 while ((dimcb_io_read(&g.dim2->MCTL) & 1) != 1) 150 while ((readl(&g.dim2->MCTL) & 1) != 1)
150 continue; 151 continue;
151 152
152 dimcb_io_write(&g.dim2->MCTL, 0); /* clear transfer complete */ 153 writel(0, &g.dim2->MCTL); /* clear transfer complete */
153} 154}
154 155
155static void dim2_clear_dbr(u16 addr, u16 size) 156static void dim2_clear_dbr(u16 addr, u16 size)
@@ -159,8 +160,8 @@ static void dim2_clear_dbr(u16 addr, u16 size)
159 u16 const end_addr = addr + size; 160 u16 const end_addr = addr + size;
160 u32 const cmd = bit_mask(MADR_WNR_BIT) | bit_mask(MADR_TB_BIT); 161 u32 const cmd = bit_mask(MADR_WNR_BIT) | bit_mask(MADR_TB_BIT);
161 162
162 dimcb_io_write(&g.dim2->MCTL, 0); /* clear transfer complete */ 163 writel(0, &g.dim2->MCTL); /* clear transfer complete */
163 dimcb_io_write(&g.dim2->MDAT0, 0); 164 writel(0, &g.dim2->MDAT0);
164 165
165 for (; addr < end_addr; addr++) 166 for (; addr < end_addr; addr++)
166 dim2_transfer_madr(cmd | addr); 167 dim2_transfer_madr(cmd | addr);
@@ -170,28 +171,28 @@ static u32 dim2_read_ctr(u32 ctr_addr, u16 mdat_idx)
170{ 171{
171 dim2_transfer_madr(ctr_addr); 172 dim2_transfer_madr(ctr_addr);
172 173
173 return dimcb_io_read((&g.dim2->MDAT0) + mdat_idx); 174 return readl((&g.dim2->MDAT0) + mdat_idx);
174} 175}
175 176
176static void dim2_write_ctr_mask(u32 ctr_addr, const u32 *mask, const u32 *value) 177static void dim2_write_ctr_mask(u32 ctr_addr, const u32 *mask, const u32 *value)
177{ 178{
178 enum { MADR_WNR_BIT = 31 }; 179 enum { MADR_WNR_BIT = 31 };
179 180
180 dimcb_io_write(&g.dim2->MCTL, 0); /* clear transfer complete */ 181 writel(0, &g.dim2->MCTL); /* clear transfer complete */
181 182
182 if (mask[0] != 0) 183 if (mask[0] != 0)
183 dimcb_io_write(&g.dim2->MDAT0, value[0]); 184 writel(value[0], &g.dim2->MDAT0);
184 if (mask[1] != 0) 185 if (mask[1] != 0)
185 dimcb_io_write(&g.dim2->MDAT1, value[1]); 186 writel(value[1], &g.dim2->MDAT1);
186 if (mask[2] != 0) 187 if (mask[2] != 0)
187 dimcb_io_write(&g.dim2->MDAT2, value[2]); 188 writel(value[2], &g.dim2->MDAT2);
188 if (mask[3] != 0) 189 if (mask[3] != 0)
189 dimcb_io_write(&g.dim2->MDAT3, value[3]); 190 writel(value[3], &g.dim2->MDAT3);
190 191
191 dimcb_io_write(&g.dim2->MDWE0, mask[0]); 192 writel(mask[0], &g.dim2->MDWE0);
192 dimcb_io_write(&g.dim2->MDWE1, mask[1]); 193 writel(mask[1], &g.dim2->MDWE1);
193 dimcb_io_write(&g.dim2->MDWE2, mask[2]); 194 writel(mask[2], &g.dim2->MDWE2);
194 dimcb_io_write(&g.dim2->MDWE3, mask[3]); 195 writel(mask[3], &g.dim2->MDWE3);
195 196
196 dim2_transfer_madr(bit_mask(MADR_WNR_BIT) | ctr_addr); 197 dim2_transfer_madr(bit_mask(MADR_WNR_BIT) | ctr_addr);
197} 198}
@@ -356,15 +357,13 @@ static void dim2_configure_channel(
356 dim2_configure_cat(AHB_CAT, ch_addr, type, is_tx ? 0 : 1); 357 dim2_configure_cat(AHB_CAT, ch_addr, type, is_tx ? 0 : 1);
357 358
358 /* unmask interrupt for used channel, enable mlb_sys_int[0] interrupt */ 359 /* unmask interrupt for used channel, enable mlb_sys_int[0] interrupt */
359 dimcb_io_write(&g.dim2->ACMR0, 360 writel(readl(&g.dim2->ACMR0) | bit_mask(ch_addr), &g.dim2->ACMR0);
360 dimcb_io_read(&g.dim2->ACMR0) | bit_mask(ch_addr));
361} 361}
362 362
363static void dim2_clear_channel(u8 ch_addr) 363static void dim2_clear_channel(u8 ch_addr)
364{ 364{
365 /* mask interrupt for used channel, disable mlb_sys_int[0] interrupt */ 365 /* mask interrupt for used channel, disable mlb_sys_int[0] interrupt */
366 dimcb_io_write(&g.dim2->ACMR0, 366 writel(readl(&g.dim2->ACMR0) & ~bit_mask(ch_addr), &g.dim2->ACMR0);
367 dimcb_io_read(&g.dim2->ACMR0) & ~bit_mask(ch_addr));
368 367
369 dim2_clear_cat(AHB_CAT, ch_addr); 368 dim2_clear_cat(AHB_CAT, ch_addr);
370 dim2_clear_adt(ch_addr); 369 dim2_clear_adt(ch_addr);
@@ -373,7 +372,7 @@ static void dim2_clear_channel(u8 ch_addr)
373 dim2_clear_cdt(ch_addr); 372 dim2_clear_cdt(ch_addr);
374 373
375 /* clear channel status bit */ 374 /* clear channel status bit */
376 dimcb_io_write(&g.dim2->ACSR0, bit_mask(ch_addr)); 375 writel(bit_mask(ch_addr), &g.dim2->ACSR0);
377} 376}
378 377
379/* -------------------------------------------------------------------------- */ 378/* -------------------------------------------------------------------------- */
@@ -471,7 +470,7 @@ static inline bool check_bytes_per_frame(u32 bytes_per_frame)
471 return true; 470 return true;
472} 471}
473 472
474static inline u16 norm_ctrl_async_buffer_size(u16 buf_size) 473u16 dim_norm_ctrl_async_buffer_size(u16 buf_size)
475{ 474{
476 u16 const max_size = (u16)ADT1_CTRL_ASYNC_BD_MASK + 1u; 475 u16 const max_size = (u16)ADT1_CTRL_ASYNC_BD_MASK + 1u;
477 476
@@ -517,20 +516,20 @@ static inline u16 norm_sync_buffer_size(u16 buf_size, u16 bytes_per_frame)
517static void dim2_cleanup(void) 516static void dim2_cleanup(void)
518{ 517{
519 /* disable MediaLB */ 518 /* disable MediaLB */
520 dimcb_io_write(&g.dim2->MLBC0, false << MLBC0_MLBEN_BIT); 519 writel(false << MLBC0_MLBEN_BIT, &g.dim2->MLBC0);
521 520
522 dim2_clear_ctram(); 521 dim2_clear_ctram();
523 522
524 /* disable mlb_int interrupt */ 523 /* disable mlb_int interrupt */
525 dimcb_io_write(&g.dim2->MIEN, 0); 524 writel(0, &g.dim2->MIEN);
526 525
527 /* clear status for all dma channels */ 526 /* clear status for all dma channels */
528 dimcb_io_write(&g.dim2->ACSR0, 0xFFFFFFFF); 527 writel(0xFFFFFFFF, &g.dim2->ACSR0);
529 dimcb_io_write(&g.dim2->ACSR1, 0xFFFFFFFF); 528 writel(0xFFFFFFFF, &g.dim2->ACSR1);
530 529
531 /* mask interrupts for all channels */ 530 /* mask interrupts for all channels */
532 dimcb_io_write(&g.dim2->ACMR0, 0); 531 writel(0, &g.dim2->ACMR0);
533 dimcb_io_write(&g.dim2->ACMR1, 0); 532 writel(0, &g.dim2->ACMR1);
534} 533}
535 534
536static void dim2_initialize(bool enable_6pin, u8 mlb_clock) 535static void dim2_initialize(bool enable_6pin, u8 mlb_clock)
@@ -538,23 +537,22 @@ static void dim2_initialize(bool enable_6pin, u8 mlb_clock)
538 dim2_cleanup(); 537 dim2_cleanup();
539 538
540 /* configure and enable MediaLB */ 539 /* configure and enable MediaLB */
541 dimcb_io_write(&g.dim2->MLBC0, 540 writel(enable_6pin << MLBC0_MLBPEN_BIT |
542 enable_6pin << MLBC0_MLBPEN_BIT | 541 mlb_clock << MLBC0_MLBCLK_SHIFT |
543 mlb_clock << MLBC0_MLBCLK_SHIFT | 542 g.fcnt << MLBC0_FCNT_SHIFT |
544 g.fcnt << MLBC0_FCNT_SHIFT | 543 true << MLBC0_MLBEN_BIT,
545 true << MLBC0_MLBEN_BIT); 544 &g.dim2->MLBC0);
546 545
547 /* activate all HBI channels */ 546 /* activate all HBI channels */
548 dimcb_io_write(&g.dim2->HCMR0, 0xFFFFFFFF); 547 writel(0xFFFFFFFF, &g.dim2->HCMR0);
549 dimcb_io_write(&g.dim2->HCMR1, 0xFFFFFFFF); 548 writel(0xFFFFFFFF, &g.dim2->HCMR1);
550 549
551 /* enable HBI */ 550 /* enable HBI */
552 dimcb_io_write(&g.dim2->HCTL, bit_mask(HCTL_EN_BIT)); 551 writel(bit_mask(HCTL_EN_BIT), &g.dim2->HCTL);
553 552
554 /* configure DMA */ 553 /* configure DMA */
555 dimcb_io_write(&g.dim2->ACTL, 554 writel(ACTL_DMA_MODE_VAL_DMA_MODE_1 << ACTL_DMA_MODE_BIT |
556 ACTL_DMA_MODE_VAL_DMA_MODE_1 << ACTL_DMA_MODE_BIT | 555 true << ACTL_SCE_BIT, &g.dim2->ACTL);
557 true << ACTL_SCE_BIT);
558} 556}
559 557
560static bool dim2_is_mlb_locked(void) 558static bool dim2_is_mlb_locked(void)
@@ -562,12 +560,12 @@ static bool dim2_is_mlb_locked(void)
562 u32 const mask0 = bit_mask(MLBC0_MLBLK_BIT); 560 u32 const mask0 = bit_mask(MLBC0_MLBLK_BIT);
563 u32 const mask1 = bit_mask(MLBC1_CLKMERR_BIT) | 561 u32 const mask1 = bit_mask(MLBC1_CLKMERR_BIT) |
564 bit_mask(MLBC1_LOCKERR_BIT); 562 bit_mask(MLBC1_LOCKERR_BIT);
565 u32 const c1 = dimcb_io_read(&g.dim2->MLBC1); 563 u32 const c1 = readl(&g.dim2->MLBC1);
566 u32 const nda_mask = (u32)MLBC1_NDA_MASK << MLBC1_NDA_SHIFT; 564 u32 const nda_mask = (u32)MLBC1_NDA_MASK << MLBC1_NDA_SHIFT;
567 565
568 dimcb_io_write(&g.dim2->MLBC1, c1 & nda_mask); 566 writel(c1 & nda_mask, &g.dim2->MLBC1);
569 return (dimcb_io_read(&g.dim2->MLBC1) & mask1) == 0 && 567 return (readl(&g.dim2->MLBC1) & mask1) == 0 &&
570 (dimcb_io_read(&g.dim2->MLBC0) & mask0) != 0; 568 (readl(&g.dim2->MLBC0) & mask0) != 0;
571} 569}
572 570
573/* -------------------------------------------------------------------------- */ 571/* -------------------------------------------------------------------------- */
@@ -590,7 +588,7 @@ static inline bool service_channel(u8 ch_addr, u8 idx)
590 dim2_write_ctr_mask(ADT + ch_addr, mask, adt_w); 588 dim2_write_ctr_mask(ADT + ch_addr, mask, adt_w);
591 589
592 /* clear channel status bit */ 590 /* clear channel status bit */
593 dimcb_io_write(&g.dim2->ACSR0, bit_mask(ch_addr)); 591 writel(bit_mask(ch_addr), &g.dim2->ACSR0);
594 592
595 return true; 593 return true;
596} 594}
@@ -652,7 +650,7 @@ static bool channel_start(struct dim_channel *ch, u32 buf_addr, u16 buf_size)
652 return dim_on_error(DIM_ERR_BAD_BUFFER_SIZE, "Bad buffer size"); 650 return dim_on_error(DIM_ERR_BAD_BUFFER_SIZE, "Bad buffer size");
653 651
654 if (ch->packet_length == 0 && ch->bytes_per_frame == 0 && 652 if (ch->packet_length == 0 && ch->bytes_per_frame == 0 &&
655 buf_size != norm_ctrl_async_buffer_size(buf_size)) 653 buf_size != dim_norm_ctrl_async_buffer_size(buf_size))
656 return dim_on_error(DIM_ERR_BAD_BUFFER_SIZE, 654 return dim_on_error(DIM_ERR_BAD_BUFFER_SIZE,
657 "Bad control/async buffer size"); 655 "Bad control/async buffer size");
658 656
@@ -776,13 +774,8 @@ static u8 init_ctrl_async(struct dim_channel *ch, u8 type, u8 is_tx,
776 774
777void dim_service_mlb_int_irq(void) 775void dim_service_mlb_int_irq(void)
778{ 776{
779 dimcb_io_write(&g.dim2->MS0, 0); 777 writel(0, &g.dim2->MS0);
780 dimcb_io_write(&g.dim2->MS1, 0); 778 writel(0, &g.dim2->MS1);
781}
782
783u16 dim_norm_ctrl_async_buffer_size(u16 buf_size)
784{
785 return norm_ctrl_async_buffer_size(buf_size);
786} 779}
787 780
788/** 781/**
@@ -829,7 +822,7 @@ u8 dim_init_async(struct dim_channel *ch, u8 is_tx, u16 ch_address,
829 if (is_tx && !g.atx_dbr.ch_addr) { 822 if (is_tx && !g.atx_dbr.ch_addr) {
830 g.atx_dbr.ch_addr = ch->addr; 823 g.atx_dbr.ch_addr = ch->addr;
831 dbrcnt_init(ch->addr, ch->dbr_size); 824 dbrcnt_init(ch->addr, ch->dbr_size);
832 dimcb_io_write(&g.dim2->MIEN, bit_mask(20)); 825 writel(bit_mask(20), &g.dim2->MIEN);
833 } 826 }
834 827
835 return ret; 828 return ret;
@@ -896,7 +889,7 @@ u8 dim_destroy_channel(struct dim_channel *ch)
896 return DIM_ERR_DRIVER_NOT_INITIALIZED; 889 return DIM_ERR_DRIVER_NOT_INITIALIZED;
897 890
898 if (ch->addr == g.atx_dbr.ch_addr) { 891 if (ch->addr == g.atx_dbr.ch_addr) {
899 dimcb_io_write(&g.dim2->MIEN, 0); 892 writel(0, &g.dim2->MIEN);
900 g.atx_dbr.ch_addr = 0; 893 g.atx_dbr.ch_addr = 0;
901 } 894 }
902 895
diff --git a/drivers/staging/most/dim2/hal.h b/drivers/staging/most/dim2/hal.h
index fca6c22de8a6..20531449acab 100644
--- a/drivers/staging/most/dim2/hal.h
+++ b/drivers/staging/most/dim2/hal.h
@@ -97,10 +97,6 @@ bool dim_enqueue_buffer(struct dim_channel *ch, u32 buffer_addr,
97 97
98bool dim_detach_buffers(struct dim_channel *ch, u16 buffers_number); 98bool dim_detach_buffers(struct dim_channel *ch, u16 buffers_number);
99 99
100u32 dimcb_io_read(u32 __iomem *ptr32);
101
102void dimcb_io_write(u32 __iomem *ptr32, u32 value);
103
104void dimcb_on_error(u8 error_id, const char *error_message); 100void dimcb_on_error(u8 error_id, const char *error_message);
105 101
106#endif /* _DIM2_HAL_H */ 102#endif /* _DIM2_HAL_H */
diff --git a/drivers/staging/most/net/net.c b/drivers/staging/most/net/net.c
index aababdf2be12..26a31854c636 100644
--- a/drivers/staging/most/net/net.c
+++ b/drivers/staging/most/net/net.c
@@ -69,7 +69,7 @@ struct net_dev_context {
69 69
70static struct list_head net_devices = LIST_HEAD_INIT(net_devices); 70static struct list_head net_devices = LIST_HEAD_INIT(net_devices);
71static struct mutex probe_disc_mt; /* ch->linked = true, most_nd_open */ 71static struct mutex probe_disc_mt; /* ch->linked = true, most_nd_open */
72static struct spinlock list_lock; /* list_head, ch->linked = false, dev_hold */ 72static DEFINE_SPINLOCK(list_lock); /* list_head, ch->linked = false, dev_hold */
73static struct core_component comp; 73static struct core_component comp;
74 74
75static int skb_to_mamac(const struct sk_buff *skb, struct mbo *mbo) 75static int skb_to_mamac(const struct sk_buff *skb, struct mbo *mbo)
@@ -509,7 +509,6 @@ static int __init most_net_init(void)
509{ 509{
510 int err; 510 int err;
511 511
512 spin_lock_init(&list_lock);
513 mutex_init(&probe_disc_mt); 512 mutex_init(&probe_disc_mt);
514 err = most_register_component(&comp); 513 err = most_register_component(&comp);
515 if (err) 514 if (err)
diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c
index 342f390d68b3..79817061fcfa 100644
--- a/drivers/staging/most/sound/sound.c
+++ b/drivers/staging/most/sound/sound.c
@@ -802,8 +802,11 @@ static int __init audio_init(void)
802 if (ret) 802 if (ret)
803 pr_err("Failed to register %s\n", comp.name); 803 pr_err("Failed to register %s\n", comp.name);
804 ret = most_register_configfs_subsys(&comp); 804 ret = most_register_configfs_subsys(&comp);
805 if (ret) 805 if (ret) {
806 pr_err("Failed to register %s configfs subsys\n", comp.name); 806 pr_err("Failed to register %s configfs subsys\n", comp.name);
807 most_deregister_component(&comp);
808 }
809
807 return ret; 810 return ret;
808} 811}
809 812
diff --git a/drivers/staging/most/video/video.c b/drivers/staging/most/video/video.c
index 6f6e98ab0550..250af9fb704d 100644
--- a/drivers/staging/most/video/video.c
+++ b/drivers/staging/most/video/video.c
@@ -54,7 +54,7 @@ struct comp_fh {
54}; 54};
55 55
56static struct list_head video_devices = LIST_HEAD_INIT(video_devices); 56static struct list_head video_devices = LIST_HEAD_INIT(video_devices);
57static struct spinlock list_lock; 57static DEFINE_SPINLOCK(list_lock);
58 58
59static inline bool data_ready(struct most_video_dev *mdev) 59static inline bool data_ready(struct most_video_dev *mdev)
60{ 60{
@@ -538,7 +538,6 @@ static int __init comp_init(void)
538{ 538{
539 int err; 539 int err;
540 540
541 spin_lock_init(&list_lock);
542 err = most_register_component(&comp); 541 err = most_register_component(&comp);
543 if (err) 542 if (err)
544 return err; 543 return err;
diff --git a/drivers/staging/mt7621-dma/mtk-hsdma.c b/drivers/staging/mt7621-dma/mtk-hsdma.c
index 60db06768c8a..d964642d95a3 100644
--- a/drivers/staging/mt7621-dma/mtk-hsdma.c
+++ b/drivers/staging/mt7621-dma/mtk-hsdma.c
@@ -675,10 +675,8 @@ static int mtk_hsdma_probe(struct platform_device *pdev)
675 tasklet_init(&hsdma->task, mtk_hsdma_tasklet, (unsigned long)hsdma); 675 tasklet_init(&hsdma->task, mtk_hsdma_tasklet, (unsigned long)hsdma);
676 676
677 irq = platform_get_irq(pdev, 0); 677 irq = platform_get_irq(pdev, 0);
678 if (irq < 0) { 678 if (irq < 0)
679 dev_err(&pdev->dev, "failed to get irq\n");
680 return -EINVAL; 679 return -EINVAL;
681 }
682 ret = devm_request_irq(&pdev->dev, irq, mtk_hsdma_irq, 680 ret = devm_request_irq(&pdev->dev, irq, mtk_hsdma_irq,
683 0, dev_name(&pdev->dev), hsdma); 681 0, dev_name(&pdev->dev), hsdma);
684 if (ret) { 682 if (ret) {
diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c
index 89fa813142ab..6b98827da57f 100644
--- a/drivers/staging/mt7621-pci/pci-mt7621.c
+++ b/drivers/staging/mt7621-pci/pci-mt7621.c
@@ -400,6 +400,7 @@ static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie)
400 400
401 err = of_pci_get_devfn(child); 401 err = of_pci_get_devfn(child);
402 if (err < 0) { 402 if (err < 0) {
403 of_node_put(child);
403 dev_err(dev, "failed to parse devfn: %d\n", err); 404 dev_err(dev, "failed to parse devfn: %d\n", err);
404 return err; 405 return err;
405 } 406 }
@@ -407,8 +408,10 @@ static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie)
407 slot = PCI_SLOT(err); 408 slot = PCI_SLOT(err);
408 409
409 err = mt7621_pcie_parse_port(pcie, child, slot); 410 err = mt7621_pcie_parse_port(pcie, child, slot);
410 if (err) 411 if (err) {
412 of_node_put(child);
411 return err; 413 return err;
414 }
412 } 415 }
413 416
414 return 0; 417 return 0;
@@ -614,17 +617,12 @@ static int mt7621_pcie_request_resources(struct mt7621_pcie *pcie,
614 struct list_head *res) 617 struct list_head *res)
615{ 618{
616 struct device *dev = pcie->dev; 619 struct device *dev = pcie->dev;
617 int err;
618 620
619 pci_add_resource_offset(res, &pcie->io, pcie->offset.io); 621 pci_add_resource_offset(res, &pcie->io, pcie->offset.io);
620 pci_add_resource_offset(res, &pcie->mem, pcie->offset.mem); 622 pci_add_resource_offset(res, &pcie->mem, pcie->offset.mem);
621 pci_add_resource(res, &pcie->busn); 623 pci_add_resource(res, &pcie->busn);
622 624
623 err = devm_request_pci_bus_resources(dev, res); 625 return devm_request_pci_bus_resources(dev, res);
624 if (err < 0)
625 return err;
626
627 return 0;
628} 626}
629 627
630static int mt7621_pcie_register_host(struct pci_host_bridge *host, 628static int mt7621_pcie_register_host(struct pci_host_bridge *host,
diff --git a/drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c b/drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c
index 9b52d44abef1..d0f06790d38f 100644
--- a/drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c
+++ b/drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c
@@ -358,12 +358,15 @@ static int rt2880_pinmux_probe(struct platform_device *pdev)
358 gpiobase = of_get_property(np, "ralink,gpio-base", NULL); 358 gpiobase = of_get_property(np, "ralink,gpio-base", NULL);
359 if (!ngpio || !gpiobase) { 359 if (!ngpio || !gpiobase) {
360 dev_err(&pdev->dev, "failed to load chip info\n"); 360 dev_err(&pdev->dev, "failed to load chip info\n");
361 of_node_put(np);
361 return -EINVAL; 362 return -EINVAL;
362 } 363 }
363 364
364 range = devm_kzalloc(p->dev, sizeof(*range), GFP_KERNEL); 365 range = devm_kzalloc(p->dev, sizeof(*range), GFP_KERNEL);
365 if (!range) 366 if (!range) {
367 of_node_put(np);
366 return -ENOMEM; 368 return -ENOMEM;
369 }
367 range->name = "pio"; 370 range->name = "pio";
368 range->npins = __be32_to_cpu(*ngpio); 371 range->npins = __be32_to_cpu(*ngpio);
369 range->base = __be32_to_cpu(*gpiobase); 372 range->base = __be32_to_cpu(*gpiobase);
diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c
index 08027a36e0bc..360ec0407740 100644
--- a/drivers/staging/nvec/nvec.c
+++ b/drivers/staging/nvec/nvec.c
@@ -767,7 +767,6 @@ static int tegra_nvec_probe(struct platform_device *pdev)
767 struct device *dev = &pdev->dev; 767 struct device *dev = &pdev->dev;
768 struct nvec_chip *nvec; 768 struct nvec_chip *nvec;
769 struct nvec_msg *msg; 769 struct nvec_msg *msg;
770 struct resource *res;
771 void __iomem *base; 770 void __iomem *base;
772 char get_firmware_version[] = { NVEC_CNTL, GET_FIRMWARE_VERSION }, 771 char get_firmware_version[] = { NVEC_CNTL, GET_FIRMWARE_VERSION },
773 unmute_speakers[] = { NVEC_OEM0, 0x10, 0x59, 0x95 }, 772 unmute_speakers[] = { NVEC_OEM0, 0x10, 0x59, 0x95 },
@@ -790,16 +789,13 @@ static int tegra_nvec_probe(struct platform_device *pdev)
790 return -ENODEV; 789 return -ENODEV;
791 } 790 }
792 791
793 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 792 base = devm_platform_ioremap_resource(pdev, 0);
794 base = devm_ioremap_resource(dev, res);
795 if (IS_ERR(base)) 793 if (IS_ERR(base))
796 return PTR_ERR(base); 794 return PTR_ERR(base);
797 795
798 nvec->irq = platform_get_irq(pdev, 0); 796 nvec->irq = platform_get_irq(pdev, 0);
799 if (nvec->irq < 0) { 797 if (nvec->irq < 0)
800 dev_err(dev, "no irq resource?\n");
801 return -ENODEV; 798 return -ENODEV;
802 }
803 799
804 i2c_clk = devm_clk_get(dev, "div-clk"); 800 i2c_clk = devm_clk_get(dev, "div-clk");
805 if (IS_ERR(i2c_clk)) { 801 if (IS_ERR(i2c_clk)) {
diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
index 8847a11c212f..33762f2e9a44 100644
--- a/drivers/staging/octeon/ethernet.c
+++ b/drivers/staging/octeon/ethernet.c
@@ -794,7 +794,7 @@ static int cvm_oct_probe(struct platform_device *pdev)
794 priv->imode = CVMX_HELPER_INTERFACE_MODE_DISABLED; 794 priv->imode = CVMX_HELPER_INTERFACE_MODE_DISABLED;
795 priv->port = CVMX_PIP_NUM_INPUT_PORTS; 795 priv->port = CVMX_PIP_NUM_INPUT_PORTS;
796 priv->queue = -1; 796 priv->queue = -1;
797 strcpy(dev->name, "pow%d"); 797 strscpy(dev->name, "pow%d", sizeof(dev->name));
798 for (qos = 0; qos < 16; qos++) 798 for (qos = 0; qos < 16; qos++)
799 skb_queue_head_init(&priv->tx_free_list[qos]); 799 skb_queue_head_init(&priv->tx_free_list[qos]);
800 dev->min_mtu = VLAN_ETH_ZLEN - mtu_overhead; 800 dev->min_mtu = VLAN_ETH_ZLEN - mtu_overhead;
@@ -866,39 +866,39 @@ static int cvm_oct_probe(struct platform_device *pdev)
866 866
867 case CVMX_HELPER_INTERFACE_MODE_NPI: 867 case CVMX_HELPER_INTERFACE_MODE_NPI:
868 dev->netdev_ops = &cvm_oct_npi_netdev_ops; 868 dev->netdev_ops = &cvm_oct_npi_netdev_ops;
869 strcpy(dev->name, "npi%d"); 869 strscpy(dev->name, "npi%d", sizeof(dev->name));
870 break; 870 break;
871 871
872 case CVMX_HELPER_INTERFACE_MODE_XAUI: 872 case CVMX_HELPER_INTERFACE_MODE_XAUI:
873 dev->netdev_ops = &cvm_oct_xaui_netdev_ops; 873 dev->netdev_ops = &cvm_oct_xaui_netdev_ops;
874 strcpy(dev->name, "xaui%d"); 874 strscpy(dev->name, "xaui%d", sizeof(dev->name));
875 break; 875 break;
876 876
877 case CVMX_HELPER_INTERFACE_MODE_LOOP: 877 case CVMX_HELPER_INTERFACE_MODE_LOOP:
878 dev->netdev_ops = &cvm_oct_npi_netdev_ops; 878 dev->netdev_ops = &cvm_oct_npi_netdev_ops;
879 strcpy(dev->name, "loop%d"); 879 strscpy(dev->name, "loop%d", sizeof(dev->name));
880 break; 880 break;
881 881
882 case CVMX_HELPER_INTERFACE_MODE_SGMII: 882 case CVMX_HELPER_INTERFACE_MODE_SGMII:
883 priv->phy_mode = PHY_INTERFACE_MODE_SGMII; 883 priv->phy_mode = PHY_INTERFACE_MODE_SGMII;
884 dev->netdev_ops = &cvm_oct_sgmii_netdev_ops; 884 dev->netdev_ops = &cvm_oct_sgmii_netdev_ops;
885 strcpy(dev->name, "eth%d"); 885 strscpy(dev->name, "eth%d", sizeof(dev->name));
886 break; 886 break;
887 887
888 case CVMX_HELPER_INTERFACE_MODE_SPI: 888 case CVMX_HELPER_INTERFACE_MODE_SPI:
889 dev->netdev_ops = &cvm_oct_spi_netdev_ops; 889 dev->netdev_ops = &cvm_oct_spi_netdev_ops;
890 strcpy(dev->name, "spi%d"); 890 strscpy(dev->name, "spi%d", sizeof(dev->name));
891 break; 891 break;
892 892
893 case CVMX_HELPER_INTERFACE_MODE_GMII: 893 case CVMX_HELPER_INTERFACE_MODE_GMII:
894 priv->phy_mode = PHY_INTERFACE_MODE_GMII; 894 priv->phy_mode = PHY_INTERFACE_MODE_GMII;
895 dev->netdev_ops = &cvm_oct_rgmii_netdev_ops; 895 dev->netdev_ops = &cvm_oct_rgmii_netdev_ops;
896 strcpy(dev->name, "eth%d"); 896 strscpy(dev->name, "eth%d", sizeof(dev->name));
897 break; 897 break;
898 898
899 case CVMX_HELPER_INTERFACE_MODE_RGMII: 899 case CVMX_HELPER_INTERFACE_MODE_RGMII:
900 dev->netdev_ops = &cvm_oct_rgmii_netdev_ops; 900 dev->netdev_ops = &cvm_oct_rgmii_netdev_ops;
901 strcpy(dev->name, "eth%d"); 901 strscpy(dev->name, "eth%d", sizeof(dev->name));
902 cvm_set_rgmii_delay(priv, interface, 902 cvm_set_rgmii_delay(priv, interface,
903 port_index); 903 port_index);
904 break; 904 break;
diff --git a/drivers/staging/olpc_dcon/TODO b/drivers/staging/olpc_dcon/TODO
index fe09efbc7f77..d8296f2ae872 100644
--- a/drivers/staging/olpc_dcon/TODO
+++ b/drivers/staging/olpc_dcon/TODO
@@ -8,10 +8,6 @@ TODO:
8 internals, but isn't properly integrated, is not the correct solution. 8 internals, but isn't properly integrated, is not the correct solution.
9 - see if vx855 gpio API can be made similar enough to cs5535 so we can 9 - see if vx855 gpio API can be made similar enough to cs5535 so we can
10 share more code 10 share more code
11 - convert all uses of the old GPIO API from <linux/gpio.h> to the
12 GPIO descriptor API in <linux/gpio/consumer.h> and look up GPIO
13 lines from device tree, ACPI or board files, board files should
14 use <linux/gpio/machine.h>
15 - allow simultaneous XO-1 and XO-1.5 support 11 - allow simultaneous XO-1 and XO-1.5 support
16 12
17Please send patches to Greg Kroah-Hartman <greg@kroah.com> and 13Please send patches to Greg Kroah-Hartman <greg@kroah.com> and
diff --git a/drivers/staging/pi433/Documentation/pi433.txt b/drivers/staging/pi433/Documentation/pi433.txt
index 21cffdb86ecf..4a0d34b4ad37 100644
--- a/drivers/staging/pi433/Documentation/pi433.txt
+++ b/drivers/staging/pi433/Documentation/pi433.txt
@@ -14,7 +14,7 @@ until something gets received terminates the read request.
14The driver supports on the fly reloading of the hardware fifo of the rf 14The driver supports on the fly reloading of the hardware fifo of the rf
15chip, thus enabling for much longer telegrams than the hardware fifo size. 15chip, thus enabling for much longer telegrams than the hardware fifo size.
16 16
17Discription of driver operation 17Description of driver operation
18=============================== 18===============================
19 19
20a) transmission 20a) transmission
diff --git a/drivers/staging/ralink-gdma/ralink-gdma.c b/drivers/staging/ralink-gdma/ralink-gdma.c
index 5854551d0a52..900424db9b97 100644
--- a/drivers/staging/ralink-gdma/ralink-gdma.c
+++ b/drivers/staging/ralink-gdma/ralink-gdma.c
@@ -826,10 +826,8 @@ static int gdma_dma_probe(struct platform_device *pdev)
826 tasklet_init(&dma_dev->task, gdma_dma_tasklet, (unsigned long)dma_dev); 826 tasklet_init(&dma_dev->task, gdma_dma_tasklet, (unsigned long)dma_dev);
827 827
828 irq = platform_get_irq(pdev, 0); 828 irq = platform_get_irq(pdev, 0);
829 if (irq < 0) { 829 if (irq < 0)
830 dev_err(&pdev->dev, "failed to get irq\n");
831 return -EINVAL; 830 return -EINVAL;
832 }
833 ret = devm_request_irq(&pdev->dev, irq, gdma_dma_irq, 831 ret = devm_request_irq(&pdev->dev, irq, gdma_dma_irq,
834 0, dev_name(&pdev->dev), dma_dev); 832 0, dev_name(&pdev->dev), dma_dev);
835 if (ret) { 833 if (ret) {
diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index a24b40761af2..815dfee11968 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -1200,7 +1200,7 @@ void rtw_createbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd)
1200 1200
1201 rtw_indicate_connect(padapter); 1201 rtw_indicate_connect(padapter);
1202 } else { 1202 } else {
1203 pwlan = _rtw_alloc_network(pmlmepriv); 1203 pwlan = rtw_alloc_network(pmlmepriv);
1204 spin_lock_bh(&pmlmepriv->scanned_queue.lock); 1204 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
1205 if (!pwlan) { 1205 if (!pwlan) {
1206 pwlan = rtw_get_oldest_wlan_network(&pmlmepriv->scanned_queue); 1206 pwlan = rtw_get_oldest_wlan_network(&pmlmepriv->scanned_queue);
diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c b/drivers/staging/rtl8188eu/core/rtw_efuse.c
index 51c3dd6d7ffb..02c476f45b33 100644
--- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
+++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
@@ -108,7 +108,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
108 /* 1. Read the first byte to check if efuse is empty!!! */ 108 /* 1. Read the first byte to check if efuse is empty!!! */
109 /* */ 109 /* */
110 /* */ 110 /* */
111 rtemp8 = *(phymap+eFuse_Addr); 111 rtemp8 = *(phymap + eFuse_Addr);
112 if (rtemp8 != 0xFF) { 112 if (rtemp8 != 0xFF) {
113 efuse_utilized++; 113 efuse_utilized++;
114 eFuse_Addr++; 114 eFuse_Addr++;
@@ -124,10 +124,10 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
124 /* Check PG header for section num. */ 124 /* Check PG header for section num. */
125 if ((rtemp8 & 0x1F) == 0x0F) { /* extended header */ 125 if ((rtemp8 & 0x1F) == 0x0F) { /* extended header */
126 u1temp = (rtemp8 & 0xE0) >> 5; 126 u1temp = (rtemp8 & 0xE0) >> 5;
127 rtemp8 = *(phymap+eFuse_Addr); 127 rtemp8 = *(phymap + eFuse_Addr);
128 if ((rtemp8 & 0x0F) == 0x0F) { 128 if ((rtemp8 & 0x0F) == 0x0F) {
129 eFuse_Addr++; 129 eFuse_Addr++;
130 rtemp8 = *(phymap+eFuse_Addr); 130 rtemp8 = *(phymap + eFuse_Addr);
131 131
132 if (rtemp8 != 0xFF && (eFuse_Addr < EFUSE_REAL_CONTENT_LEN_88E)) 132 if (rtemp8 != 0xFF && (eFuse_Addr < EFUSE_REAL_CONTENT_LEN_88E))
133 eFuse_Addr++; 133 eFuse_Addr++;
@@ -147,13 +147,13 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
147 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) { 147 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
148 /* Check word enable condition in the section */ 148 /* Check word enable condition in the section */
149 if (!(wren & 0x01)) { 149 if (!(wren & 0x01)) {
150 rtemp8 = *(phymap+eFuse_Addr); 150 rtemp8 = *(phymap + eFuse_Addr);
151 eFuse_Addr++; 151 eFuse_Addr++;
152 efuse_utilized++; 152 efuse_utilized++;
153 eFuseWord[offset][i] = (rtemp8 & 0xff); 153 eFuseWord[offset][i] = (rtemp8 & 0xff);
154 if (eFuse_Addr >= EFUSE_REAL_CONTENT_LEN_88E) 154 if (eFuse_Addr >= EFUSE_REAL_CONTENT_LEN_88E)
155 break; 155 break;
156 rtemp8 = *(phymap+eFuse_Addr); 156 rtemp8 = *(phymap + eFuse_Addr);
157 eFuse_Addr++; 157 eFuse_Addr++;
158 efuse_utilized++; 158 efuse_utilized++;
159 eFuseWord[offset][i] |= (((u16)rtemp8 << 8) & 0xff00); 159 eFuseWord[offset][i] |= (((u16)rtemp8 << 8) & 0xff00);
@@ -165,7 +165,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
165 } 165 }
166 } 166 }
167 /* Read next PG header */ 167 /* Read next PG header */
168 rtemp8 = *(phymap+eFuse_Addr); 168 rtemp8 = *(phymap + eFuse_Addr);
169 169
170 if (rtemp8 != 0xFF && (eFuse_Addr < EFUSE_REAL_CONTENT_LEN_88E)) { 170 if (rtemp8 != 0xFF && (eFuse_Addr < EFUSE_REAL_CONTENT_LEN_88E)) {
171 efuse_utilized++; 171 efuse_utilized++;
@@ -178,8 +178,8 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
178 /* */ 178 /* */
179 for (i = 0; i < EFUSE_MAX_SECTION_88E; i++) { 179 for (i = 0; i < EFUSE_MAX_SECTION_88E; i++) {
180 for (j = 0; j < EFUSE_MAX_WORD_UNIT; j++) { 180 for (j = 0; j < EFUSE_MAX_WORD_UNIT; j++) {
181 efuseTbl[(i*8)+(j*2)] = (eFuseWord[i][j] & 0xff); 181 efuseTbl[(i * 8) + (j * 2)] = (eFuseWord[i][j] & 0xff);
182 efuseTbl[(i*8)+((j*2)+1)] = ((eFuseWord[i][j] >> 8) & 0xff); 182 efuseTbl[(i * 8) + ((j * 2) + 1)] = ((eFuseWord[i][j] >> 8) & 0xff);
183 } 183 }
184 } 184 }
185 185
@@ -187,7 +187,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
187 /* 4. Copy from Efuse map to output pointer memory!!! */ 187 /* 4. Copy from Efuse map to output pointer memory!!! */
188 /* */ 188 /* */
189 for (i = 0; i < _size_byte; i++) 189 for (i = 0; i < _size_byte; i++)
190 pbuf[i] = efuseTbl[_offset+i]; 190 pbuf[i] = efuseTbl[_offset + i];
191 191
192 /* */ 192 /* */
193 /* 5. Calculate Efuse utilization. */ 193 /* 5. Calculate Efuse utilization. */
@@ -218,16 +218,16 @@ static void efuse_read_phymap_from_txpktbuf(
218 u8 *pos = content; 218 u8 *pos = content;
219 219
220 if (bcnhead < 0) /* if not valid */ 220 if (bcnhead < 0) /* if not valid */
221 bcnhead = usb_read8(adapter, REG_TDECTRL+1); 221 bcnhead = usb_read8(adapter, REG_TDECTRL + 1);
222 222
223 DBG_88E("%s bcnhead:%d\n", __func__, bcnhead); 223 DBG_88E("%s bcnhead:%d\n", __func__, bcnhead);
224 224
225 usb_write8(adapter, REG_PKT_BUFF_ACCESS_CTRL, TXPKT_BUF_SELECT); 225 usb_write8(adapter, REG_PKT_BUFF_ACCESS_CTRL, TXPKT_BUF_SELECT);
226 226
227 dbg_addr = bcnhead*128/8; /* 8-bytes addressing */ 227 dbg_addr = bcnhead * 128 / 8; /* 8-bytes addressing */
228 228
229 while (1) { 229 while (1) {
230 usb_write16(adapter, REG_PKTBUF_DBG_ADDR, dbg_addr+i); 230 usb_write16(adapter, REG_PKTBUF_DBG_ADDR, dbg_addr + i);
231 231
232 usb_write8(adapter, REG_TXPKTBUF_DBG, 0); 232 usb_write8(adapter, REG_TXPKTBUF_DBG, 0);
233 start = jiffies; 233 start = jiffies;
@@ -246,34 +246,34 @@ static void efuse_read_phymap_from_txpktbuf(
246 u16 aaa; 246 u16 aaa;
247 247
248 lenc[0] = usb_read8(adapter, REG_PKTBUF_DBG_DATA_L); 248 lenc[0] = usb_read8(adapter, REG_PKTBUF_DBG_DATA_L);
249 lenc[1] = usb_read8(adapter, REG_PKTBUF_DBG_DATA_L+1); 249 lenc[1] = usb_read8(adapter, REG_PKTBUF_DBG_DATA_L + 1);
250 250
251 aaabak = le16_to_cpup((__le16 *)lenc); 251 aaabak = le16_to_cpup((__le16 *)lenc);
252 lenbak = le16_to_cpu(*((__le16 *)lenc)); 252 lenbak = le16_to_cpu(*((__le16 *)lenc));
253 aaa = le16_to_cpup((__le16 *)&lo32); 253 aaa = le16_to_cpup((__le16 *)&lo32);
254 len = le16_to_cpu(*((__le16 *)&lo32)); 254 len = le16_to_cpu(*((__le16 *)&lo32));
255 255
256 limit = min_t(u16, len-2, limit); 256 limit = min_t(u16, len - 2, limit);
257 257
258 DBG_88E("%s len:%u, lenbak:%u, aaa:%u, aaabak:%u\n", __func__, len, lenbak, aaa, aaabak); 258 DBG_88E("%s len:%u, lenbak:%u, aaa:%u, aaabak:%u\n", __func__, len, lenbak, aaa, aaabak);
259 259
260 memcpy(pos, ((u8 *)&lo32)+2, (limit >= count+2) ? 2 : limit-count); 260 memcpy(pos, ((u8 *)&lo32) + 2, (limit >= count + 2) ? 2 : limit - count);
261 count += (limit >= count+2) ? 2 : limit-count; 261 count += (limit >= count + 2) ? 2 : limit - count;
262 pos = content+count; 262 pos = content + count;
263 263
264 } else { 264 } else {
265 memcpy(pos, ((u8 *)&lo32), (limit >= count+4) ? 4 : limit-count); 265 memcpy(pos, ((u8 *)&lo32), (limit >= count + 4) ? 4 : limit - count);
266 count += (limit >= count+4) ? 4 : limit-count; 266 count += (limit >= count + 4) ? 4 : limit - count;
267 pos = content+count; 267 pos = content + count;
268 } 268 }
269 269
270 if (limit > count && len-2 > count) { 270 if (limit > count && len - 2 > count) {
271 memcpy(pos, (u8 *)&hi32, (limit >= count+4) ? 4 : limit-count); 271 memcpy(pos, (u8 *)&hi32, (limit >= count + 4) ? 4 : limit - count);
272 count += (limit >= count+4) ? 4 : limit-count; 272 count += (limit >= count + 4) ? 4 : limit - count;
273 pos = content+count; 273 pos = content + count;
274 } 274 }
275 275
276 if (limit <= count || len-2 <= count) 276 if (limit <= count || len - 2 <= count)
277 break; 277 break;
278 i++; 278 i++;
279 } 279 }
@@ -288,7 +288,7 @@ static s32 iol_read_efuse(struct adapter *padapter, u8 txpktbuf_bndy, u16 offset
288 u8 physical_map[512]; 288 u8 physical_map[512];
289 u16 size = 512; 289 u16 size = 512;
290 290
291 usb_write8(padapter, REG_TDECTRL+1, txpktbuf_bndy); 291 usb_write8(padapter, REG_TDECTRL + 1, txpktbuf_bndy);
292 memset(physical_map, 0xFF, 512); 292 memset(physical_map, 0xFF, 512);
293 usb_write8(padapter, REG_PKT_BUFF_ACCESS_CTRL, TXPKT_BUF_SELECT); 293 usb_write8(padapter, REG_PKT_BUFF_ACCESS_CTRL, TXPKT_BUF_SELECT);
294 status = iol_execute(padapter, CMD_READ_EFUSE_MAP); 294 status = iol_execute(padapter, CMD_READ_EFUSE_MAP);
@@ -323,7 +323,7 @@ u8 Efuse_WordEnableDataWrite(struct adapter *pAdapter, u16 efuse_addr, u8 word_e
323 efuse_OneByteWrite(pAdapter, start_addr++, data[1]); 323 efuse_OneByteWrite(pAdapter, start_addr++, data[1]);
324 324
325 efuse_OneByteRead(pAdapter, tmpaddr, &tmpdata[0]); 325 efuse_OneByteRead(pAdapter, tmpaddr, &tmpdata[0]);
326 efuse_OneByteRead(pAdapter, tmpaddr+1, &tmpdata[1]); 326 efuse_OneByteRead(pAdapter, tmpaddr + 1, &tmpdata[1]);
327 if ((data[0] != tmpdata[0]) || (data[1] != tmpdata[1])) 327 if ((data[0] != tmpdata[0]) || (data[1] != tmpdata[1]))
328 badworden &= (~BIT(0)); 328 badworden &= (~BIT(0));
329 } 329 }
@@ -333,7 +333,7 @@ u8 Efuse_WordEnableDataWrite(struct adapter *pAdapter, u16 efuse_addr, u8 word_e
333 efuse_OneByteWrite(pAdapter, start_addr++, data[3]); 333 efuse_OneByteWrite(pAdapter, start_addr++, data[3]);
334 334
335 efuse_OneByteRead(pAdapter, tmpaddr, &tmpdata[2]); 335 efuse_OneByteRead(pAdapter, tmpaddr, &tmpdata[2]);
336 efuse_OneByteRead(pAdapter, tmpaddr+1, &tmpdata[3]); 336 efuse_OneByteRead(pAdapter, tmpaddr + 1, &tmpdata[3]);
337 if ((data[2] != tmpdata[2]) || (data[3] != tmpdata[3])) 337 if ((data[2] != tmpdata[2]) || (data[3] != tmpdata[3]))
338 badworden &= (~BIT(1)); 338 badworden &= (~BIT(1));
339 } 339 }
@@ -343,7 +343,7 @@ u8 Efuse_WordEnableDataWrite(struct adapter *pAdapter, u16 efuse_addr, u8 word_e
343 efuse_OneByteWrite(pAdapter, start_addr++, data[5]); 343 efuse_OneByteWrite(pAdapter, start_addr++, data[5]);
344 344
345 efuse_OneByteRead(pAdapter, tmpaddr, &tmpdata[4]); 345 efuse_OneByteRead(pAdapter, tmpaddr, &tmpdata[4]);
346 efuse_OneByteRead(pAdapter, tmpaddr+1, &tmpdata[5]); 346 efuse_OneByteRead(pAdapter, tmpaddr + 1, &tmpdata[5]);
347 if ((data[4] != tmpdata[4]) || (data[5] != tmpdata[5])) 347 if ((data[4] != tmpdata[4]) || (data[5] != tmpdata[5]))
348 badworden &= (~BIT(2)); 348 badworden &= (~BIT(2));
349 } 349 }
@@ -353,7 +353,7 @@ u8 Efuse_WordEnableDataWrite(struct adapter *pAdapter, u16 efuse_addr, u8 word_e
353 efuse_OneByteWrite(pAdapter, start_addr++, data[7]); 353 efuse_OneByteWrite(pAdapter, start_addr++, data[7]);
354 354
355 efuse_OneByteRead(pAdapter, tmpaddr, &tmpdata[6]); 355 efuse_OneByteRead(pAdapter, tmpaddr, &tmpdata[6]);
356 efuse_OneByteRead(pAdapter, tmpaddr+1, &tmpdata[7]); 356 efuse_OneByteRead(pAdapter, tmpaddr + 1, &tmpdata[7]);
357 if ((data[6] != tmpdata[6]) || (data[7] != tmpdata[7])) 357 if ((data[6] != tmpdata[6]) || (data[7] != tmpdata[7]))
358 badworden &= (~BIT(3)); 358 badworden &= (~BIT(3));
359 } 359 }
@@ -371,7 +371,7 @@ static u16 Efuse_GetCurrentSize(struct adapter *pAdapter)
371 while (efuse_OneByteRead(pAdapter, efuse_addr, &efuse_data) && 371 while (efuse_OneByteRead(pAdapter, efuse_addr, &efuse_data) &&
372 AVAILABLE_EFUSE_ADDR(efuse_addr)) { 372 AVAILABLE_EFUSE_ADDR(efuse_addr)) {
373 if (efuse_data != 0xFF) { 373 if (efuse_data != 0xFF) {
374 if ((efuse_data&0x1F) == 0x0F) { /* extended header */ 374 if ((efuse_data & 0x1F) == 0x0F) { /* extended header */
375 hoffset = efuse_data; 375 hoffset = efuse_data;
376 efuse_addr++; 376 efuse_addr++;
377 efuse_OneByteRead(pAdapter, efuse_addr, &efuse_data); 377 efuse_OneByteRead(pAdapter, efuse_addr, &efuse_data);
@@ -383,12 +383,12 @@ static u16 Efuse_GetCurrentSize(struct adapter *pAdapter)
383 hworden = efuse_data & 0x0F; 383 hworden = efuse_data & 0x0F;
384 } 384 }
385 } else { 385 } else {
386 hoffset = (efuse_data>>4) & 0x0F; 386 hoffset = (efuse_data >> 4) & 0x0F;
387 hworden = efuse_data & 0x0F; 387 hworden = efuse_data & 0x0F;
388 } 388 }
389 word_cnts = Efuse_CalculateWordCnts(hworden); 389 word_cnts = Efuse_CalculateWordCnts(hworden);
390 /* read next header */ 390 /* read next header */
391 efuse_addr = efuse_addr + (word_cnts*2)+1; 391 efuse_addr = efuse_addr + (word_cnts * 2) + 1;
392 } else { 392 } else {
393 break; 393 break;
394 } 394 }
@@ -439,15 +439,15 @@ int Efuse_PgPacketRead(struct adapter *pAdapter, u8 offset, u8 *data)
439 continue; 439 continue;
440 } 440 }
441 } else { 441 } else {
442 hoffset = (efuse_data>>4) & 0x0F; 442 hoffset = (efuse_data >> 4) & 0x0F;
443 hworden = efuse_data & 0x0F; 443 hworden = efuse_data & 0x0F;
444 } 444 }
445 word_cnts = Efuse_CalculateWordCnts(hworden); 445 word_cnts = Efuse_CalculateWordCnts(hworden);
446 bDataEmpty = true; 446 bDataEmpty = true;
447 447
448 if (hoffset == offset) { 448 if (hoffset == offset) {
449 for (tmpidx = 0; tmpidx < word_cnts*2; tmpidx++) { 449 for (tmpidx = 0; tmpidx < word_cnts * 2; tmpidx++) {
450 if (efuse_OneByteRead(pAdapter, efuse_addr+1+tmpidx, &efuse_data)) { 450 if (efuse_OneByteRead(pAdapter, efuse_addr + 1 + tmpidx, &efuse_data)) {
451 tmpdata[tmpidx] = efuse_data; 451 tmpdata[tmpidx] = efuse_data;
452 if (efuse_data != 0xff) 452 if (efuse_data != 0xff)
453 bDataEmpty = false; 453 bDataEmpty = false;
@@ -456,11 +456,11 @@ int Efuse_PgPacketRead(struct adapter *pAdapter, u8 offset, u8 *data)
456 if (!bDataEmpty) { 456 if (!bDataEmpty) {
457 ReadState = PG_STATE_DATA; 457 ReadState = PG_STATE_DATA;
458 } else {/* read next header */ 458 } else {/* read next header */
459 efuse_addr = efuse_addr + (word_cnts*2)+1; 459 efuse_addr = efuse_addr + (word_cnts * 2) + 1;
460 ReadState = PG_STATE_HEADER; 460 ReadState = PG_STATE_HEADER;
461 } 461 }
462 } else {/* read next header */ 462 } else {/* read next header */
463 efuse_addr = efuse_addr + (word_cnts*2)+1; 463 efuse_addr = efuse_addr + (word_cnts * 2) + 1;
464 ReadState = PG_STATE_HEADER; 464 ReadState = PG_STATE_HEADER;
465 } 465 }
466 } else { 466 } else {
@@ -469,7 +469,7 @@ int Efuse_PgPacketRead(struct adapter *pAdapter, u8 offset, u8 *data)
469 } else if (ReadState & PG_STATE_DATA) { 469 } else if (ReadState & PG_STATE_DATA) {
470 /* Data section Read ------------- */ 470 /* Data section Read ------------- */
471 efuse_WordEnableDataRead(hworden, tmpdata, data); 471 efuse_WordEnableDataRead(hworden, tmpdata, data);
472 efuse_addr = efuse_addr + (word_cnts*2)+1; 472 efuse_addr = efuse_addr + (word_cnts * 2) + 1;
473 ReadState = PG_STATE_HEADER; 473 ReadState = PG_STATE_HEADER;
474 } 474 }
475 } 475 }
@@ -491,7 +491,7 @@ static bool hal_EfuseFixHeaderProcess(struct adapter *pAdapter, u8 efuseType, st
491 491
492 if (Efuse_PgPacketRead(pAdapter, pFixPkt->offset, originaldata)) { 492 if (Efuse_PgPacketRead(pAdapter, pFixPkt->offset, originaldata)) {
493 /* check if data exist */ 493 /* check if data exist */
494 badworden = Efuse_WordEnableDataWrite(pAdapter, efuse_addr+1, pFixPkt->word_en, originaldata); 494 badworden = Efuse_WordEnableDataWrite(pAdapter, efuse_addr + 1, pFixPkt->word_en, originaldata);
495 495
496 if (badworden != 0xf) { /* write fail */ 496 if (badworden != 0xf) { /* write fail */
497 PgWriteSuccess = Efuse_PgPacketWrite(pAdapter, pFixPkt->offset, badworden, originaldata); 497 PgWriteSuccess = Efuse_PgPacketWrite(pAdapter, pFixPkt->offset, badworden, originaldata);
@@ -501,10 +501,10 @@ static bool hal_EfuseFixHeaderProcess(struct adapter *pAdapter, u8 efuseType, st
501 else 501 else
502 efuse_addr = Efuse_GetCurrentSize(pAdapter); 502 efuse_addr = Efuse_GetCurrentSize(pAdapter);
503 } else { 503 } else {
504 efuse_addr = efuse_addr + (pFixPkt->word_cnts*2) + 1; 504 efuse_addr = efuse_addr + (pFixPkt->word_cnts * 2) + 1;
505 } 505 }
506 } else { 506 } else {
507 efuse_addr = efuse_addr + (pFixPkt->word_cnts*2) + 1; 507 efuse_addr = efuse_addr + (pFixPkt->word_cnts * 2) + 1;
508 } 508 }
509 *pAddr = efuse_addr; 509 *pAddr = efuse_addr;
510 return true; 510 return true;
@@ -601,7 +601,7 @@ static bool hal_EfusePgPacketWrite1ByteHeader(struct adapter *pAdapter, u8 efuse
601 } else { 601 } else {
602 struct pgpkt fixPkt; 602 struct pgpkt fixPkt;
603 603
604 fixPkt.offset = (tmp_header>>4) & 0x0F; 604 fixPkt.offset = (tmp_header >> 4) & 0x0F;
605 fixPkt.word_en = tmp_header & 0x0F; 605 fixPkt.word_en = tmp_header & 0x0F;
606 fixPkt.word_cnts = Efuse_CalculateWordCnts(fixPkt.word_en); 606 fixPkt.word_cnts = Efuse_CalculateWordCnts(fixPkt.word_en);
607 if (!hal_EfuseFixHeaderProcess(pAdapter, efuseType, &fixPkt, &efuse_addr)) 607 if (!hal_EfuseFixHeaderProcess(pAdapter, efuseType, &fixPkt, &efuse_addr))
@@ -619,7 +619,7 @@ static bool hal_EfusePgPacketWriteData(struct adapter *pAdapter, u8 efuseType, u
619 u32 PgWriteSuccess = 0; 619 u32 PgWriteSuccess = 0;
620 620
621 badworden = 0x0f; 621 badworden = 0x0f;
622 badworden = Efuse_WordEnableDataWrite(pAdapter, efuse_addr+1, pTargetPkt->word_en, pTargetPkt->data); 622 badworden = Efuse_WordEnableDataWrite(pAdapter, efuse_addr + 1, pTargetPkt->word_en, pTargetPkt->data);
623 if (badworden == 0x0F) { 623 if (badworden == 0x0F) {
624 /* write ok */ 624 /* write ok */
625 return true; 625 return true;
@@ -681,8 +681,8 @@ static bool hal_EfuseCheckIfDatafollowed(struct adapter *pAdapter, u8 word_cnts,
681 bool ret = false; 681 bool ret = false;
682 u8 i, efuse_data; 682 u8 i, efuse_data;
683 683
684 for (i = 0; i < (word_cnts*2); i++) { 684 for (i = 0; i < (word_cnts * 2); i++) {
685 if (efuse_OneByteRead(pAdapter, (startAddr+i), &efuse_data) && (efuse_data != 0xFF)) 685 if (efuse_OneByteRead(pAdapter, (startAddr + i), &efuse_data) && (efuse_data != 0xFF))
686 ret = true; 686 ret = true;
687 } 687 }
688 return ret; 688 return ret;
@@ -721,7 +721,7 @@ static bool hal_EfusePartialWriteCheck(struct adapter *pAdapter, u8 efuseType, u
721 } 721 }
722 } else { 722 } else {
723 cur_header = efuse_data; 723 cur_header = efuse_data;
724 curPkt.offset = (cur_header>>4) & 0x0F; 724 curPkt.offset = (cur_header >> 4) & 0x0F;
725 curPkt.word_en = cur_header & 0x0F; 725 curPkt.word_en = cur_header & 0x0F;
726 } 726 }
727 727
@@ -729,10 +729,10 @@ static bool hal_EfusePartialWriteCheck(struct adapter *pAdapter, u8 efuseType, u
729 /* if same header is found but no data followed */ 729 /* if same header is found but no data followed */
730 /* write some part of data followed by the header. */ 730 /* write some part of data followed by the header. */
731 if ((curPkt.offset == pTargetPkt->offset) && 731 if ((curPkt.offset == pTargetPkt->offset) &&
732 (!hal_EfuseCheckIfDatafollowed(pAdapter, curPkt.word_cnts, startAddr+1)) && 732 (!hal_EfuseCheckIfDatafollowed(pAdapter, curPkt.word_cnts, startAddr + 1)) &&
733 wordEnMatched(pTargetPkt, &curPkt, &matched_wden)) { 733 wordEnMatched(pTargetPkt, &curPkt, &matched_wden)) {
734 /* Here to write partial data */ 734 /* Here to write partial data */
735 badworden = Efuse_WordEnableDataWrite(pAdapter, startAddr+1, matched_wden, pTargetPkt->data); 735 badworden = Efuse_WordEnableDataWrite(pAdapter, startAddr + 1, matched_wden, pTargetPkt->data);
736 if (badworden != 0x0F) { 736 if (badworden != 0x0F) {
737 u32 PgWriteSuccess = 0; 737 u32 PgWriteSuccess = 0;
738 /* if write fail on some words, write these bad words again */ 738 /* if write fail on some words, write these bad words again */
@@ -746,13 +746,13 @@ static bool hal_EfusePartialWriteCheck(struct adapter *pAdapter, u8 efuseType, u
746 } 746 }
747 /* partial write ok, update the target packet for later use */ 747 /* partial write ok, update the target packet for later use */
748 for (i = 0; i < 4; i++) { 748 for (i = 0; i < 4; i++) {
749 if ((matched_wden & (0x1<<i)) == 0) /* this word has been written */ 749 if ((matched_wden & (0x1 << i)) == 0) /* this word has been written */
750 pTargetPkt->word_en |= (0x1<<i); /* disable the word */ 750 pTargetPkt->word_en |= (0x1 << i); /* disable the word */
751 } 751 }
752 pTargetPkt->word_cnts = Efuse_CalculateWordCnts(pTargetPkt->word_en); 752 pTargetPkt->word_cnts = Efuse_CalculateWordCnts(pTargetPkt->word_en);
753 } 753 }
754 /* read from next header */ 754 /* read from next header */
755 startAddr = startAddr + (curPkt.word_cnts*2) + 1; 755 startAddr = startAddr + (curPkt.word_cnts * 2) + 1;
756 } else { 756 } else {
757 /* not used header, 0xff */ 757 /* not used header, 0xff */
758 *pAddr = startAddr; 758 *pAddr = startAddr;
@@ -763,20 +763,9 @@ static bool hal_EfusePartialWriteCheck(struct adapter *pAdapter, u8 efuseType, u
763 return ret; 763 return ret;
764} 764}
765 765
766static bool
767hal_EfusePgCheckAvailableAddr(
768 struct adapter *pAdapter,
769 u8 efuseType
770 )
771{
772 if (Efuse_GetCurrentSize(pAdapter) >= EFUSE_MAP_LEN_88E)
773 return false;
774 return true;
775}
776
777static void hal_EfuseConstructPGPkt(u8 offset, u8 word_en, u8 *pData, struct pgpkt *pTargetPkt) 766static void hal_EfuseConstructPGPkt(u8 offset, u8 word_en, u8 *pData, struct pgpkt *pTargetPkt)
778{ 767{
779 memset((void *)pTargetPkt->data, 0xFF, sizeof(u8)*8); 768 memset((void *)pTargetPkt->data, 0xFF, sizeof(u8) * 8);
780 pTargetPkt->offset = offset; 769 pTargetPkt->offset = offset;
781 pTargetPkt->word_en = word_en; 770 pTargetPkt->word_en = word_en;
782 efuse_WordEnableDataRead(word_en, pData, pTargetPkt->data); 771 efuse_WordEnableDataRead(word_en, pData, pTargetPkt->data);
@@ -789,7 +778,7 @@ bool Efuse_PgPacketWrite(struct adapter *pAdapter, u8 offset, u8 word_en, u8 *pD
789 u16 startAddr = 0; 778 u16 startAddr = 0;
790 u8 efuseType = EFUSE_WIFI; 779 u8 efuseType = EFUSE_WIFI;
791 780
792 if (!hal_EfusePgCheckAvailableAddr(pAdapter, efuseType)) 781 if (Efuse_GetCurrentSize(pAdapter) >= EFUSE_MAP_LEN_88E)
793 return false; 782 return false;
794 783
795 hal_EfuseConstructPGPkt(offset, word_en, pData, &targetPkt); 784 hal_EfuseConstructPGPkt(offset, word_en, pData, &targetPkt);
@@ -826,13 +815,13 @@ u8 efuse_OneByteRead(struct adapter *pAdapter, u16 addr, u8 *data)
826 u8 tmpidx = 0; 815 u8 tmpidx = 0;
827 u8 result; 816 u8 result;
828 817
829 usb_write8(pAdapter, EFUSE_CTRL+1, (u8)(addr & 0xff)); 818 usb_write8(pAdapter, EFUSE_CTRL + 1, (u8)(addr & 0xff));
830 usb_write8(pAdapter, EFUSE_CTRL+2, ((u8)((addr>>8) & 0x03)) | 819 usb_write8(pAdapter, EFUSE_CTRL + 2, ((u8)((addr >> 8) & 0x03)) |
831 (usb_read8(pAdapter, EFUSE_CTRL+2) & 0xFC)); 820 (usb_read8(pAdapter, EFUSE_CTRL + 2) & 0xFC));
832 821
833 usb_write8(pAdapter, EFUSE_CTRL+3, 0x72);/* read cmd */ 822 usb_write8(pAdapter, EFUSE_CTRL + 3, 0x72);/* read cmd */
834 823
835 while (!(0x80 & usb_read8(pAdapter, EFUSE_CTRL+3)) && (tmpidx < 100)) 824 while (!(0x80 & usb_read8(pAdapter, EFUSE_CTRL + 3)) && (tmpidx < 100))
836 tmpidx++; 825 tmpidx++;
837 if (tmpidx < 100) { 826 if (tmpidx < 100) {
838 *data = usb_read8(pAdapter, EFUSE_CTRL); 827 *data = usb_read8(pAdapter, EFUSE_CTRL);
@@ -849,15 +838,15 @@ u8 efuse_OneByteWrite(struct adapter *pAdapter, u16 addr, u8 data)
849 u8 tmpidx = 0; 838 u8 tmpidx = 0;
850 u8 result; 839 u8 result;
851 840
852 usb_write8(pAdapter, EFUSE_CTRL+1, (u8)(addr&0xff)); 841 usb_write8(pAdapter, EFUSE_CTRL + 1, (u8)(addr & 0xff));
853 usb_write8(pAdapter, EFUSE_CTRL+2, 842 usb_write8(pAdapter, EFUSE_CTRL + 2,
854 (usb_read8(pAdapter, EFUSE_CTRL+2) & 0xFC) | 843 (usb_read8(pAdapter, EFUSE_CTRL + 2) & 0xFC) |
855 (u8)((addr>>8) & 0x03)); 844 (u8)((addr >> 8) & 0x03));
856 usb_write8(pAdapter, EFUSE_CTRL, data);/* data */ 845 usb_write8(pAdapter, EFUSE_CTRL, data);/* data */
857 846
858 usb_write8(pAdapter, EFUSE_CTRL+3, 0xF2);/* write cmd */ 847 usb_write8(pAdapter, EFUSE_CTRL + 3, 0xF2);/* write cmd */
859 848
860 while ((0x80 & usb_read8(pAdapter, EFUSE_CTRL+3)) && (tmpidx < 100)) 849 while ((0x80 & usb_read8(pAdapter, EFUSE_CTRL + 3)) && (tmpidx < 100))
861 tmpidx++; 850 tmpidx++;
862 851
863 if (tmpidx < 100) 852 if (tmpidx < 100)
diff --git a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
index 28b3cdd10397..cc1b5438c04c 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
@@ -59,7 +59,7 @@ static u8 WIFI_OFDMRATES[] = {
59 59
60int rtw_get_bit_value_from_ieee_value(u8 val) 60int rtw_get_bit_value_from_ieee_value(u8 val)
61{ 61{
62 unsigned char dot11_rate_table[] = { 62 static const unsigned char dot11_rate_table[] = {
63 2, 4, 11, 22, 12, 18, 24, 36, 48, 63 2, 4, 11, 22, 12, 18, 24, 36, 48,
64 72, 96, 108, 0}; /* last element must be zero!! */ 64 72, 96, 108, 0}; /* last element must be zero!! */
65 int i = 0; 65 int i = 0;
@@ -275,7 +275,7 @@ unsigned char *rtw_get_wpa_ie(unsigned char *pie, uint *wpa_ie_len, int limit)
275 uint len; 275 uint len;
276 u16 val16; 276 u16 val16;
277 __le16 le_tmp; 277 __le16 le_tmp;
278 unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01}; 278 static const unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01};
279 u8 *pbuf = pie; 279 u8 *pbuf = pie;
280 int limit_new = limit; 280 int limit_new = limit;
281 281
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c b/drivers/staging/rtl8188eu/core/rtw_mlme.c
index d2f7a88e992e..1ec3b237212e 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
@@ -104,7 +104,7 @@ void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv)
104 } 104 }
105} 105}
106 106
107struct wlan_network *_rtw_alloc_network(struct mlme_priv *pmlmepriv) 107struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv)
108 /* _queue *free_queue) */ 108 /* _queue *free_queue) */
109{ 109{
110 struct wlan_network *pnetwork; 110 struct wlan_network *pnetwork;
@@ -119,7 +119,7 @@ struct wlan_network *_rtw_alloc_network(struct mlme_priv *pmlmepriv)
119 list_del_init(&pnetwork->list); 119 list_del_init(&pnetwork->list);
120 120
121 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, 121 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
122 ("_rtw_alloc_network: ptr=%p\n", &pnetwork->list)); 122 ("rtw_alloc_network: ptr=%p\n", &pnetwork->list));
123 pnetwork->network_type = 0; 123 pnetwork->network_type = 0;
124 pnetwork->fixed = false; 124 pnetwork->fixed = false;
125 pnetwork->last_scanned = jiffies; 125 pnetwork->last_scanned = jiffies;
@@ -272,11 +272,6 @@ u8 *rtw_get_beacon_interval_from_ie(u8 *ie)
272 return ie + 8; 272 return ie + 8;
273} 273}
274 274
275static struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv)
276{
277 return _rtw_alloc_network(pmlmepriv);
278}
279
280int rtw_is_same_ibss(struct adapter *adapter, struct wlan_network *pnetwork) 275int rtw_is_same_ibss(struct adapter *adapter, struct wlan_network *pnetwork)
281{ 276{
282 int ret = true; 277 int ret = true;
@@ -827,7 +822,7 @@ void rtw_indicate_disconnect(struct adapter *padapter)
827 822
828inline void rtw_indicate_scan_done(struct adapter *padapter, bool aborted) 823inline void rtw_indicate_scan_done(struct adapter *padapter, bool aborted)
829{ 824{
830 rtw_os_indicate_scan_done(padapter, aborted); 825 indicate_wx_scan_complete_event(padapter);
831} 826}
832 827
833static struct sta_info *rtw_joinbss_update_stainfo(struct adapter *padapter, struct wlan_network *pnetwork) 828static struct sta_info *rtw_joinbss_update_stainfo(struct adapter *padapter, struct wlan_network *pnetwork)
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
index 6f3c03201f64..18dc9fc1c04a 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
@@ -4854,7 +4854,7 @@ u8 setopmode_hdl(struct adapter *padapter, u8 *pbuf)
4854 } 4854 }
4855 4855
4856 rtw_hal_set_hwreg(padapter, HW_VAR_SET_OPMODE, (u8 *)(&type)); 4856 rtw_hal_set_hwreg(padapter, HW_VAR_SET_OPMODE, (u8 *)(&type));
4857 /* Set_NETYPE0_MSR(padapter, type); */ 4857 /* Set_MSR(padapter, type); */
4858 4858
4859 return H2C_SUCCESS; 4859 return H2C_SUCCESS;
4860} 4860}
diff --git a/drivers/staging/rtl8188eu/core/rtw_recv.c b/drivers/staging/rtl8188eu/core/rtw_recv.c
index 9caf7041ad60..d4278361e002 100644
--- a/drivers/staging/rtl8188eu/core/rtw_recv.c
+++ b/drivers/staging/rtl8188eu/core/rtw_recv.c
@@ -145,8 +145,8 @@ int rtw_free_recvframe(struct recv_frame *precvframe,
145 145
146int _rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue) 146int _rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
147{ 147{
148 list_del_init(&(precvframe->list)); 148 list_del_init(&precvframe->list);
149 list_add_tail(&(precvframe->list), get_list_head(queue)); 149 list_add_tail(&precvframe->list, get_list_head(queue));
150 150
151 return _SUCCESS; 151 return _SUCCESS;
152} 152}
@@ -219,7 +219,7 @@ static int recvframe_chkmic(struct adapter *adapter,
219 struct security_priv *psecuritypriv = &adapter->securitypriv; 219 struct security_priv *psecuritypriv = &adapter->securitypriv;
220 220
221 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv; 221 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
222 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 222 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
223 223
224 stainfo = rtw_get_stainfo(&adapter->stapriv, &prxattrib->ta[0]); 224 stainfo = rtw_get_stainfo(&adapter->stapriv, &prxattrib->ta[0]);
225 225
@@ -1373,11 +1373,7 @@ static struct recv_frame *recvframe_defrag(struct adapter *adapter,
1373 /* append to first fragment frame's tail (if privacy frame, pull the ICV) */ 1373 /* append to first fragment frame's tail (if privacy frame, pull the ICV) */
1374 skb_trim(prframe->pkt, prframe->pkt->len - prframe->attrib.icv_len); 1374 skb_trim(prframe->pkt, prframe->pkt->len - prframe->attrib.icv_len);
1375 1375
1376 /* memcpy */ 1376 skb_put_data(prframe->pkt, pnfhdr->pkt->data, pnfhdr->pkt->len);
1377 memcpy(skb_tail_pointer(prframe->pkt), pnfhdr->pkt->data,
1378 pnfhdr->pkt->len);
1379
1380 skb_put(prframe->pkt, pnfhdr->pkt->len);
1381 1377
1382 prframe->attrib.icv_len = pnfhdr->attrib.icv_len; 1378 prframe->attrib.icv_len = pnfhdr->attrib.icv_len;
1383 plist = plist->next; 1379 plist = plist->next;
@@ -1500,7 +1496,7 @@ static int amsdu_to_msdu(struct adapter *padapter, struct recv_frame *prframe)
1500 struct rx_pkt_attrib *pattrib; 1496 struct rx_pkt_attrib *pattrib;
1501 struct sk_buff *sub_skb, *subframes[MAX_SUBFRAME_COUNT]; 1497 struct sk_buff *sub_skb, *subframes[MAX_SUBFRAME_COUNT];
1502 struct recv_priv *precvpriv = &padapter->recvpriv; 1498 struct recv_priv *precvpriv = &padapter->recvpriv;
1503 struct __queue *pfree_recv_queue = &(precvpriv->free_recv_queue); 1499 struct __queue *pfree_recv_queue = &precvpriv->free_recv_queue;
1504 1500
1505 nr_subframes = 0; 1501 nr_subframes = 0;
1506 pattrib = &prframe->attrib; 1502 pattrib = &prframe->attrib;
diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c b/drivers/staging/rtl8188eu/core/rtw_security.c
index 2f90f60f1681..435c0fbec54a 100644
--- a/drivers/staging/rtl8188eu/core/rtw_security.c
+++ b/drivers/staging/rtl8188eu/core/rtw_security.c
@@ -87,29 +87,28 @@ static u8 crc32_reverseBit(u8 data)
87 87
88static void crc32_init(void) 88static void crc32_init(void)
89{ 89{
90 if (bcrc32initialized == 1) { 90 int i, j;
91 u32 c;
92 u8 *p = (u8 *)&c, *p1;
93 u8 k;
94
95 if (bcrc32initialized == 1)
91 return; 96 return;
92 } else { 97
93 int i, j; 98 c = 0x12340000;
94 u32 c; 99
95 u8 *p = (u8 *)&c, *p1; 100 for (i = 0; i < 256; ++i) {
96 u8 k; 101 k = crc32_reverseBit((u8)i);
97 102 for (c = ((u32)k) << 24, j = 8; j > 0; --j)
98 c = 0x12340000; 103 c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1);
99 104 p1 = (u8 *)&crc32_table[i];
100 for (i = 0; i < 256; ++i) { 105
101 k = crc32_reverseBit((u8)i); 106 p1[0] = crc32_reverseBit(p[3]);
102 for (c = ((u32)k) << 24, j = 8; j > 0; --j) 107 p1[1] = crc32_reverseBit(p[2]);
103 c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1); 108 p1[2] = crc32_reverseBit(p[1]);
104 p1 = (u8 *)&crc32_table[i]; 109 p1[3] = crc32_reverseBit(p[0]);
105
106 p1[0] = crc32_reverseBit(p[3]);
107 p1[1] = crc32_reverseBit(p[2]);
108 p1[2] = crc32_reverseBit(p[1]);
109 p1[3] = crc32_reverseBit(p[0]);
110 }
111 bcrc32initialized = 1;
112 } 110 }
111 bcrc32initialized = 1;
113} 112}
114 113
115static __le32 getcrc32(u8 *buf, int len) 114static __le32 getcrc32(u8 *buf, int len)
diff --git a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
index 7bfc5b7c2757..c985b1468d41 100644
--- a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
+++ b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
@@ -270,14 +270,9 @@ void Switch_DM_Func(struct adapter *padapter, u32 mode, u8 enable)
270 rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_CLR, (u8 *)(&mode)); 270 rtw_hal_set_hwreg(padapter, HW_VAR_DM_FUNC_CLR, (u8 *)(&mode));
271} 271}
272 272
273static void Set_NETYPE0_MSR(struct adapter *padapter, u8 type)
274{
275 rtw_hal_set_hwreg(padapter, HW_VAR_MEDIA_STATUS, (u8 *)(&type));
276}
277
278void Set_MSR(struct adapter *padapter, u8 type) 273void Set_MSR(struct adapter *padapter, u8 type)
279{ 274{
280 Set_NETYPE0_MSR(padapter, type); 275 rtw_hal_set_hwreg(padapter, HW_VAR_MEDIA_STATUS, (u8 *)(&type));
281} 276}
282 277
283inline u8 rtw_get_oper_ch(struct adapter *adapter) 278inline u8 rtw_get_oper_ch(struct adapter *adapter)
@@ -1179,15 +1174,10 @@ void Update_RA_Entry(struct adapter *padapter, u32 mac_id)
1179 rtw_hal_update_ra_mask(padapter, mac_id, 0); 1174 rtw_hal_update_ra_mask(padapter, mac_id, 0);
1180} 1175}
1181 1176
1182static void enable_rate_adaptive(struct adapter *padapter, u32 mac_id)
1183{
1184 Update_RA_Entry(padapter, mac_id);
1185}
1186
1187void set_sta_rate(struct adapter *padapter, struct sta_info *psta) 1177void set_sta_rate(struct adapter *padapter, struct sta_info *psta)
1188{ 1178{
1189 /* rate adaptive */ 1179 /* rate adaptive */
1190 enable_rate_adaptive(padapter, psta->mac_id); 1180 Update_RA_Entry(padapter, psta->mac_id);
1191} 1181}
1192 1182
1193/* Update RRSR and Rate for USERATE */ 1183/* Update RRSR and Rate for USERATE */
@@ -1476,8 +1466,3 @@ void correct_TSF(struct adapter *padapter, struct mlme_ext_priv *pmlmeext)
1476{ 1466{
1477 rtw_hal_set_hwreg(padapter, HW_VAR_CORRECT_TSF, NULL); 1467 rtw_hal_set_hwreg(padapter, HW_VAR_CORRECT_TSF, NULL);
1478} 1468}
1479
1480void beacon_timing_control(struct adapter *padapter)
1481{
1482 rtw_hal_bcn_related_reg_setting(padapter);
1483}
diff --git a/drivers/staging/rtl8188eu/hal/bb_cfg.c b/drivers/staging/rtl8188eu/hal/bb_cfg.c
index 11e0bb9c67d7..51882858fcf0 100644
--- a/drivers/staging/rtl8188eu/hal/bb_cfg.c
+++ b/drivers/staging/rtl8188eu/hal/bb_cfg.c
@@ -653,7 +653,7 @@ static bool config_parafile(struct adapter *adapt)
653 653
654bool rtl88eu_phy_bb_config(struct adapter *adapt) 654bool rtl88eu_phy_bb_config(struct adapter *adapt)
655{ 655{
656 int rtstatus = true; 656 bool rtstatus;
657 u32 regval; 657 u32 regval;
658 u8 crystal_cap; 658 u8 crystal_cap;
659 659
diff --git a/drivers/staging/rtl8188eu/hal/rf_cfg.c b/drivers/staging/rtl8188eu/hal/rf_cfg.c
index 02aeb12c9870..47b1bf5a6143 100644
--- a/drivers/staging/rtl8188eu/hal/rf_cfg.c
+++ b/drivers/staging/rtl8188eu/hal/rf_cfg.c
@@ -218,11 +218,11 @@ static bool rtl88e_phy_config_rf_with_headerfile(struct adapter *adapt)
218 return true; 218 return true;
219} 219}
220 220
221static bool rf6052_conf_para(struct adapter *adapt) 221bool rtl88eu_phy_rf_config(struct adapter *adapt)
222{ 222{
223 struct hal_data_8188e *hal_data = adapt->HalData; 223 struct hal_data_8188e *hal_data = adapt->HalData;
224 u32 u4val = 0; 224 u32 u4val = 0;
225 bool rtstatus = true; 225 bool rtstatus;
226 struct bb_reg_def *pphyreg; 226 struct bb_reg_def *pphyreg;
227 227
228 pphyreg = &hal_data->PHYRegDef[RF90_PATH_A]; 228 pphyreg = &hal_data->PHYRegDef[RF90_PATH_A];
@@ -246,13 +246,3 @@ static bool rf6052_conf_para(struct adapter *adapt)
246 246
247 return rtstatus; 247 return rtstatus;
248} 248}
249
250static bool rtl88e_phy_rf6052_config(struct adapter *adapt)
251{
252 return rf6052_conf_para(adapt);
253}
254
255bool rtl88eu_phy_rf_config(struct adapter *adapt)
256{
257 return rtl88e_phy_rf6052_config(adapt);
258}
diff --git a/drivers/staging/rtl8188eu/hal/usb_halinit.c b/drivers/staging/rtl8188eu/hal/usb_halinit.c
index ac5552050752..16a57b31a439 100644
--- a/drivers/staging/rtl8188eu/hal/usb_halinit.c
+++ b/drivers/staging/rtl8188eu/hal/usb_halinit.c
@@ -183,14 +183,14 @@ static void _InitTxBufferBoundary(struct adapter *Adapter, u8 txpktbuf_bndy)
183 usb_write8(Adapter, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy); 183 usb_write8(Adapter, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy);
184 usb_write8(Adapter, REG_TXPKTBUF_WMAC_LBK_BF_HD, txpktbuf_bndy); 184 usb_write8(Adapter, REG_TXPKTBUF_WMAC_LBK_BF_HD, txpktbuf_bndy);
185 usb_write8(Adapter, REG_TRXFF_BNDY, txpktbuf_bndy); 185 usb_write8(Adapter, REG_TRXFF_BNDY, txpktbuf_bndy);
186 usb_write8(Adapter, REG_TDECTRL+1, txpktbuf_bndy); 186 usb_write8(Adapter, REG_TDECTRL + 1, txpktbuf_bndy);
187} 187}
188 188
189static void _InitPageBoundary(struct adapter *Adapter) 189static void _InitPageBoundary(struct adapter *Adapter)
190{ 190{
191 /* RX Page Boundary */ 191 /* RX Page Boundary */
192 /* */ 192 /* */
193 u16 rxff_bndy = MAX_RX_DMA_BUFFER_SIZE_88E-1; 193 u16 rxff_bndy = MAX_RX_DMA_BUFFER_SIZE_88E - 1;
194 194
195 usb_write16(Adapter, (REG_TRXFF_BNDY + 2), rxff_bndy); 195 usb_write16(Adapter, (REG_TRXFF_BNDY + 2), rxff_bndy);
196} 196}
@@ -504,7 +504,7 @@ static void usb_AggSettingRxUpdate(struct adapter *Adapter)
504 switch (haldata->UsbRxAggMode) { 504 switch (haldata->UsbRxAggMode) {
505 case USB_RX_AGG_DMA: 505 case USB_RX_AGG_DMA:
506 usb_write8(Adapter, REG_RXDMA_AGG_PG_TH, haldata->UsbRxAggPageCount); 506 usb_write8(Adapter, REG_RXDMA_AGG_PG_TH, haldata->UsbRxAggPageCount);
507 usb_write8(Adapter, REG_RXDMA_AGG_PG_TH+1, haldata->UsbRxAggPageTimeout); 507 usb_write8(Adapter, REG_RXDMA_AGG_PG_TH + 1, haldata->UsbRxAggPageTimeout);
508 break; 508 break;
509 case USB_RX_AGG_USB: 509 case USB_RX_AGG_USB:
510 usb_write8(Adapter, REG_USB_AGG_TH, haldata->UsbRxAggBlockCount); 510 usb_write8(Adapter, REG_USB_AGG_TH, haldata->UsbRxAggBlockCount);
@@ -512,7 +512,7 @@ static void usb_AggSettingRxUpdate(struct adapter *Adapter)
512 break; 512 break;
513 case USB_RX_AGG_MIX: 513 case USB_RX_AGG_MIX:
514 usb_write8(Adapter, REG_RXDMA_AGG_PG_TH, haldata->UsbRxAggPageCount); 514 usb_write8(Adapter, REG_RXDMA_AGG_PG_TH, haldata->UsbRxAggPageCount);
515 usb_write8(Adapter, REG_RXDMA_AGG_PG_TH+1, (haldata->UsbRxAggPageTimeout & 0x1F));/* 0x280[12:8] */ 515 usb_write8(Adapter, REG_RXDMA_AGG_PG_TH + 1, (haldata->UsbRxAggPageTimeout & 0x1F));/* 0x280[12:8] */
516 usb_write8(Adapter, REG_USB_AGG_TH, haldata->UsbRxAggBlockCount); 516 usb_write8(Adapter, REG_USB_AGG_TH, haldata->UsbRxAggBlockCount);
517 usb_write8(Adapter, REG_USB_AGG_TO, haldata->UsbRxAggBlockTimeout); 517 usb_write8(Adapter, REG_USB_AGG_TO, haldata->UsbRxAggBlockTimeout);
518 break; 518 break;
@@ -569,9 +569,9 @@ static void _InitBeaconParameters(struct adapter *Adapter)
569 569
570 haldata->RegBcnCtrlVal = usb_read8(Adapter, REG_BCN_CTRL); 570 haldata->RegBcnCtrlVal = usb_read8(Adapter, REG_BCN_CTRL);
571 haldata->RegTxPause = usb_read8(Adapter, REG_TXPAUSE); 571 haldata->RegTxPause = usb_read8(Adapter, REG_TXPAUSE);
572 haldata->RegFwHwTxQCtrl = usb_read8(Adapter, REG_FWHW_TXQ_CTRL+2); 572 haldata->RegFwHwTxQCtrl = usb_read8(Adapter, REG_FWHW_TXQ_CTRL + 2);
573 haldata->RegReg542 = usb_read8(Adapter, REG_TBTT_PROHIBIT+2); 573 haldata->RegReg542 = usb_read8(Adapter, REG_TBTT_PROHIBIT + 2);
574 haldata->RegCR_1 = usb_read8(Adapter, REG_CR+1); 574 haldata->RegCR_1 = usb_read8(Adapter, REG_CR + 1);
575} 575}
576 576
577static void _BeaconFunctionEnable(struct adapter *Adapter, 577static void _BeaconFunctionEnable(struct adapter *Adapter,
@@ -579,7 +579,7 @@ static void _BeaconFunctionEnable(struct adapter *Adapter,
579{ 579{
580 usb_write8(Adapter, REG_BCN_CTRL, (BIT(4) | BIT(3) | BIT(1))); 580 usb_write8(Adapter, REG_BCN_CTRL, (BIT(4) | BIT(3) | BIT(1)));
581 581
582 usb_write8(Adapter, REG_RD_CTRL+1, 0x6F); 582 usb_write8(Adapter, REG_RD_CTRL + 1, 0x6F);
583} 583}
584 584
585/* Set CCK and OFDM Block "ON" */ 585/* Set CCK and OFDM Block "ON" */
@@ -633,7 +633,7 @@ enum rt_rf_power_state RfOnOffDetect(struct adapter *adapt)
633 DBG_88E("pwrdown, 0x5c(BIT(7))=%02x\n", val8); 633 DBG_88E("pwrdown, 0x5c(BIT(7))=%02x\n", val8);
634 rfpowerstate = (val8 & BIT(7)) ? rf_off : rf_on; 634 rfpowerstate = (val8 & BIT(7)) ? rf_off : rf_on;
635 } else { /* rf on/off */ 635 } else { /* rf on/off */
636 usb_write8(adapt, REG_MAC_PINMUX_CFG, usb_read8(adapt, REG_MAC_PINMUX_CFG)&~(BIT(3))); 636 usb_write8(adapt, REG_MAC_PINMUX_CFG, usb_read8(adapt, REG_MAC_PINMUX_CFG) & ~(BIT(3)));
637 val8 = usb_read8(adapt, REG_GPIO_IO_SEL); 637 val8 = usb_read8(adapt, REG_GPIO_IO_SEL);
638 DBG_88E("GPIO_IN=%02x\n", val8); 638 DBG_88E("GPIO_IN=%02x\n", val8);
639 rfpowerstate = (val8 & BIT(3)) ? rf_on : rf_off; 639 rfpowerstate = (val8 & BIT(3)) ? rf_on : rf_off;
@@ -770,7 +770,7 @@ u32 rtl8188eu_hal_init(struct adapter *Adapter)
770 value8 = usb_read8(Adapter, REG_TX_RPT_CTRL); 770 value8 = usb_read8(Adapter, REG_TX_RPT_CTRL);
771 usb_write8(Adapter, REG_TX_RPT_CTRL, (value8 | BIT(1) | BIT(0))); 771 usb_write8(Adapter, REG_TX_RPT_CTRL, (value8 | BIT(1) | BIT(0)));
772 /* Set MAX RPT MACID */ 772 /* Set MAX RPT MACID */
773 usb_write8(Adapter, REG_TX_RPT_CTRL+1, 2);/* FOR sta mode ,0: bc/mc ,1:AP */ 773 usb_write8(Adapter, REG_TX_RPT_CTRL + 1, 2);/* FOR sta mode ,0: bc/mc ,1:AP */
774 /* Tx RPT Timer. Unit: 32us */ 774 /* Tx RPT Timer. Unit: 32us */
775 usb_write16(Adapter, REG_TX_RPT_TIME, 0xCdf0); 775 usb_write16(Adapter, REG_TX_RPT_TIME, 0xCdf0);
776 776
@@ -827,10 +827,10 @@ u32 rtl8188eu_hal_init(struct adapter *Adapter)
827 pwrctrlpriv->rf_pwrstate = rf_on; 827 pwrctrlpriv->rf_pwrstate = rf_on;
828 828
829 /* enable Tx report. */ 829 /* enable Tx report. */
830 usb_write8(Adapter, REG_FWHW_TXQ_CTRL+1, 0x0F); 830 usb_write8(Adapter, REG_FWHW_TXQ_CTRL + 1, 0x0F);
831 831
832 /* Suggested by SD1 pisa. Added by tynli. 2011.10.21. */ 832 /* Suggested by SD1 pisa. Added by tynli. 2011.10.21. */
833 usb_write8(Adapter, REG_EARLY_MODE_CONTROL+3, 0x01);/* Pretx_en, for WEP/TKIP SEC */ 833 usb_write8(Adapter, REG_EARLY_MODE_CONTROL + 3, 0x01);/* Pretx_en, for WEP/TKIP SEC */
834 834
835 /* tynli_test_tx_report. */ 835 /* tynli_test_tx_report. */
836 usb_write16(Adapter, REG_TX_RPT_TIME, 0x3DF0); 836 usb_write16(Adapter, REG_TX_RPT_TIME, 0x3DF0);
@@ -880,7 +880,7 @@ static void CardDisableRTL8188EU(struct adapter *Adapter)
880 880
881 /* Stop Tx Report Timer. 0x4EC[Bit1]=b'0 */ 881 /* Stop Tx Report Timer. 0x4EC[Bit1]=b'0 */
882 val8 = usb_read8(Adapter, REG_TX_RPT_CTRL); 882 val8 = usb_read8(Adapter, REG_TX_RPT_CTRL);
883 usb_write8(Adapter, REG_TX_RPT_CTRL, val8&(~BIT(1))); 883 usb_write8(Adapter, REG_TX_RPT_CTRL, val8 & (~BIT(1)));
884 884
885 /* stop rx */ 885 /* stop rx */
886 usb_write8(Adapter, REG_CR, 0x0); 886 usb_write8(Adapter, REG_CR, 0x0);
@@ -894,9 +894,9 @@ static void CardDisableRTL8188EU(struct adapter *Adapter)
894 val8 = usb_read8(Adapter, REG_MCUFWDL); 894 val8 = usb_read8(Adapter, REG_MCUFWDL);
895 if ((val8 & RAM_DL_SEL) && Adapter->bFWReady) { /* 8051 RAM code */ 895 if ((val8 & RAM_DL_SEL) && Adapter->bFWReady) { /* 8051 RAM code */
896 /* Reset MCU 0x2[10]=0. */ 896 /* Reset MCU 0x2[10]=0. */
897 val8 = usb_read8(Adapter, REG_SYS_FUNC_EN+1); 897 val8 = usb_read8(Adapter, REG_SYS_FUNC_EN + 1);
898 val8 &= ~BIT(2); /* 0x2[10], FEN_CPUEN */ 898 val8 &= ~BIT(2); /* 0x2[10], FEN_CPUEN */
899 usb_write8(Adapter, REG_SYS_FUNC_EN+1, val8); 899 usb_write8(Adapter, REG_SYS_FUNC_EN + 1, val8);
900 } 900 }
901 901
902 /* reset MCU ready status */ 902 /* reset MCU ready status */
@@ -905,17 +905,17 @@ static void CardDisableRTL8188EU(struct adapter *Adapter)
905 /* YJ,add,111212 */ 905 /* YJ,add,111212 */
906 /* Disable 32k */ 906 /* Disable 32k */
907 val8 = usb_read8(Adapter, REG_32K_CTRL); 907 val8 = usb_read8(Adapter, REG_32K_CTRL);
908 usb_write8(Adapter, REG_32K_CTRL, val8&(~BIT(0))); 908 usb_write8(Adapter, REG_32K_CTRL, val8 & (~BIT(0)));
909 909
910 /* Card disable power action flow */ 910 /* Card disable power action flow */
911 rtl88eu_pwrseqcmdparsing(Adapter, PWR_CUT_ALL_MSK, 911 rtl88eu_pwrseqcmdparsing(Adapter, PWR_CUT_ALL_MSK,
912 Rtl8188E_NIC_DISABLE_FLOW); 912 Rtl8188E_NIC_DISABLE_FLOW);
913 913
914 /* Reset MCU IO Wrapper */ 914 /* Reset MCU IO Wrapper */
915 val8 = usb_read8(Adapter, REG_RSV_CTRL+1); 915 val8 = usb_read8(Adapter, REG_RSV_CTRL + 1);
916 usb_write8(Adapter, REG_RSV_CTRL+1, (val8&(~BIT(3)))); 916 usb_write8(Adapter, REG_RSV_CTRL + 1, (val8 & (~BIT(3))));
917 val8 = usb_read8(Adapter, REG_RSV_CTRL+1); 917 val8 = usb_read8(Adapter, REG_RSV_CTRL + 1);
918 usb_write8(Adapter, REG_RSV_CTRL+1, val8 | BIT(3)); 918 usb_write8(Adapter, REG_RSV_CTRL + 1, val8 | BIT(3));
919 919
920 /* YJ,test add, 111207. For Power Consumption. */ 920 /* YJ,test add, 111207. For Power Consumption. */
921 val8 = usb_read8(Adapter, GPIO_IN); 921 val8 = usb_read8(Adapter, GPIO_IN);
@@ -923,9 +923,9 @@ static void CardDisableRTL8188EU(struct adapter *Adapter)
923 usb_write8(Adapter, GPIO_IO_SEL, 0xFF);/* Reg0x46 */ 923 usb_write8(Adapter, GPIO_IO_SEL, 0xFF);/* Reg0x46 */
924 924
925 val8 = usb_read8(Adapter, REG_GPIO_IO_SEL); 925 val8 = usb_read8(Adapter, REG_GPIO_IO_SEL);
926 usb_write8(Adapter, REG_GPIO_IO_SEL, (val8<<4)); 926 usb_write8(Adapter, REG_GPIO_IO_SEL, (val8 << 4));
927 val8 = usb_read8(Adapter, REG_GPIO_IO_SEL+1); 927 val8 = usb_read8(Adapter, REG_GPIO_IO_SEL + 1);
928 usb_write8(Adapter, REG_GPIO_IO_SEL+1, val8|0x0F);/* Reg0x43 */ 928 usb_write8(Adapter, REG_GPIO_IO_SEL + 1, val8 | 0x0F);/* Reg0x43 */
929 usb_write32(Adapter, REG_BB_PAD_CTRL, 0x00080808);/* set LNA ,TRSW,EX_PA Pin to output mode */ 929 usb_write32(Adapter, REG_BB_PAD_CTRL, 0x00080808);/* set LNA ,TRSW,EX_PA Pin to output mode */
930 Adapter->HalData->bMacPwrCtrlOn = false; 930 Adapter->HalData->bMacPwrCtrlOn = false;
931 Adapter->bFWReady = false; 931 Adapter->bFWReady = false;
@@ -1103,11 +1103,11 @@ static void ResumeTxBeacon(struct adapter *adapt)
1103 /* 2010.03.01. Marked by tynli. No need to call workitem beacause we record the value */ 1103 /* 2010.03.01. Marked by tynli. No need to call workitem beacause we record the value */
1104 /* which should be read from register to a global variable. */ 1104 /* which should be read from register to a global variable. */
1105 1105
1106 usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl) | BIT(6)); 1106 usb_write8(adapt, REG_FWHW_TXQ_CTRL + 2, (haldata->RegFwHwTxQCtrl) | BIT(6));
1107 haldata->RegFwHwTxQCtrl |= BIT(6); 1107 haldata->RegFwHwTxQCtrl |= BIT(6);
1108 usb_write8(adapt, REG_TBTT_PROHIBIT+1, 0xff); 1108 usb_write8(adapt, REG_TBTT_PROHIBIT + 1, 0xff);
1109 haldata->RegReg542 |= BIT(0); 1109 haldata->RegReg542 |= BIT(0);
1110 usb_write8(adapt, REG_TBTT_PROHIBIT+2, haldata->RegReg542); 1110 usb_write8(adapt, REG_TBTT_PROHIBIT + 2, haldata->RegReg542);
1111} 1111}
1112 1112
1113static void StopTxBeacon(struct adapter *adapt) 1113static void StopTxBeacon(struct adapter *adapt)
@@ -1117,11 +1117,11 @@ static void StopTxBeacon(struct adapter *adapt)
1117 /* 2010.03.01. Marked by tynli. No need to call workitem beacause we record the value */ 1117 /* 2010.03.01. Marked by tynli. No need to call workitem beacause we record the value */
1118 /* which should be read from register to a global variable. */ 1118 /* which should be read from register to a global variable. */
1119 1119
1120 usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl) & (~BIT(6))); 1120 usb_write8(adapt, REG_FWHW_TXQ_CTRL + 2, (haldata->RegFwHwTxQCtrl) & (~BIT(6)));
1121 haldata->RegFwHwTxQCtrl &= (~BIT(6)); 1121 haldata->RegFwHwTxQCtrl &= (~BIT(6));
1122 usb_write8(adapt, REG_TBTT_PROHIBIT+1, 0x64); 1122 usb_write8(adapt, REG_TBTT_PROHIBIT + 1, 0x64);
1123 haldata->RegReg542 &= ~(BIT(0)); 1123 haldata->RegReg542 &= ~(BIT(0));
1124 usb_write8(adapt, REG_TBTT_PROHIBIT+2, haldata->RegReg542); 1124 usb_write8(adapt, REG_TBTT_PROHIBIT + 2, haldata->RegReg542);
1125 1125
1126 /* todo: CheckFwRsvdPageContent(Adapter); 2010.06.23. Added by tynli. */ 1126 /* todo: CheckFwRsvdPageContent(Adapter); 2010.06.23. Added by tynli. */
1127} 1127}
@@ -1135,7 +1135,7 @@ static void hw_var_set_opmode(struct adapter *Adapter, u8 variable, u8 *val)
1135 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL) | BIT(4)); 1135 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL) | BIT(4));
1136 1136
1137 /* set net_type */ 1137 /* set net_type */
1138 val8 = usb_read8(Adapter, MSR)&0x0c; 1138 val8 = usb_read8(Adapter, MSR) & 0x0c;
1139 val8 |= mode; 1139 val8 |= mode;
1140 usb_write8(Adapter, MSR, val8); 1140 usb_write8(Adapter, MSR, val8);
1141 1141
@@ -1176,7 +1176,7 @@ static void hw_var_set_opmode(struct adapter *Adapter, u8 variable, u8 *val)
1176 1176
1177 /* enable BCN0 Function for if1 */ 1177 /* enable BCN0 Function for if1 */
1178 /* don't enable update TSF0 for if1 (due to TSF update when beacon/probe rsp are received) */ 1178 /* don't enable update TSF0 for if1 (due to TSF update when beacon/probe rsp are received) */
1179 usb_write8(Adapter, REG_BCN_CTRL, (DIS_TSF_UDT0_NORMAL_CHIP|EN_BCN_FUNCTION | BIT(1))); 1179 usb_write8(Adapter, REG_BCN_CTRL, (DIS_TSF_UDT0_NORMAL_CHIP | EN_BCN_FUNCTION | BIT(1)));
1180 1180
1181 /* dis BCN1 ATIM WND if if2 is station */ 1181 /* dis BCN1 ATIM WND if if2 is station */
1182 usb_write8(Adapter, REG_BCN_CTRL_1, usb_read8(Adapter, REG_BCN_CTRL_1) | BIT(0)); 1182 usb_write8(Adapter, REG_BCN_CTRL_1, usb_read8(Adapter, REG_BCN_CTRL_1) | BIT(0));
@@ -1191,7 +1191,7 @@ static void hw_var_set_macaddr(struct adapter *Adapter, u8 variable, u8 *val)
1191 reg_macid = REG_MACID; 1191 reg_macid = REG_MACID;
1192 1192
1193 for (idx = 0; idx < 6; idx++) 1193 for (idx = 0; idx < 6; idx++)
1194 usb_write8(Adapter, (reg_macid+idx), val[idx]); 1194 usb_write8(Adapter, (reg_macid + idx), val[idx]);
1195} 1195}
1196 1196
1197static void hw_var_set_bssid(struct adapter *Adapter, u8 variable, u8 *val) 1197static void hw_var_set_bssid(struct adapter *Adapter, u8 variable, u8 *val)
@@ -1202,7 +1202,7 @@ static void hw_var_set_bssid(struct adapter *Adapter, u8 variable, u8 *val)
1202 reg_bssid = REG_BSSID; 1202 reg_bssid = REG_BSSID;
1203 1203
1204 for (idx = 0; idx < 6; idx++) 1204 for (idx = 0; idx < 6; idx++)
1205 usb_write8(Adapter, (reg_bssid+idx), val[idx]); 1205 usb_write8(Adapter, (reg_bssid + idx), val[idx]);
1206} 1206}
1207 1207
1208static void hw_var_set_bcn_func(struct adapter *Adapter, u8 variable, u8 *val) 1208static void hw_var_set_bcn_func(struct adapter *Adapter, u8 variable, u8 *val)
@@ -1214,7 +1214,7 @@ static void hw_var_set_bcn_func(struct adapter *Adapter, u8 variable, u8 *val)
1214 if (*((u8 *)val)) 1214 if (*((u8 *)val))
1215 usb_write8(Adapter, bcn_ctrl_reg, (EN_BCN_FUNCTION | EN_TXBCN_RPT)); 1215 usb_write8(Adapter, bcn_ctrl_reg, (EN_BCN_FUNCTION | EN_TXBCN_RPT));
1216 else 1216 else
1217 usb_write8(Adapter, bcn_ctrl_reg, usb_read8(Adapter, bcn_ctrl_reg)&(~(EN_BCN_FUNCTION | EN_TXBCN_RPT))); 1217 usb_write8(Adapter, bcn_ctrl_reg, usb_read8(Adapter, bcn_ctrl_reg) & (~(EN_BCN_FUNCTION | EN_TXBCN_RPT)));
1218} 1218}
1219 1219
1220void rtw_hal_set_hwreg(struct adapter *Adapter, u8 variable, u8 *val) 1220void rtw_hal_set_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
@@ -1228,7 +1228,7 @@ void rtw_hal_set_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
1228 { 1228 {
1229 u8 val8; 1229 u8 val8;
1230 1230
1231 val8 = usb_read8(Adapter, MSR)&0x0c; 1231 val8 = usb_read8(Adapter, MSR) & 0x0c;
1232 val8 |= *((u8 *)val); 1232 val8 |= *((u8 *)val);
1233 usb_write8(Adapter, MSR, val8); 1233 usb_write8(Adapter, MSR, val8);
1234 } 1234 }
@@ -1274,8 +1274,8 @@ void rtw_hal_set_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
1274 BrateCfg |= 0x01; /* default enable 1M ACK rate */ 1274 BrateCfg |= 0x01; /* default enable 1M ACK rate */
1275 /* Set RRSR rate table. */ 1275 /* Set RRSR rate table. */
1276 usb_write8(Adapter, REG_RRSR, BrateCfg & 0xff); 1276 usb_write8(Adapter, REG_RRSR, BrateCfg & 0xff);
1277 usb_write8(Adapter, REG_RRSR+1, (BrateCfg >> 8) & 0xff); 1277 usb_write8(Adapter, REG_RRSR + 1, (BrateCfg >> 8) & 0xff);
1278 usb_write8(Adapter, REG_RRSR+2, usb_read8(Adapter, REG_RRSR+2)&0xf0); 1278 usb_write8(Adapter, REG_RRSR + 2, usb_read8(Adapter, REG_RRSR + 2) & 0xf0);
1279 1279
1280 /* Set RTS initial rate */ 1280 /* Set RTS initial rate */
1281 while (BrateCfg > 0x1) { 1281 while (BrateCfg > 0x1) {
@@ -1298,27 +1298,27 @@ void rtw_hal_set_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
1298 struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv; 1298 struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
1299 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; 1299 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1300 1300
1301 tsf = pmlmeext->TSFValue - rtw_modular64(pmlmeext->TSFValue, (pmlmeinfo->bcn_interval*1024)) - 1024; /* us */ 1301 tsf = pmlmeext->TSFValue - do_div(pmlmeext->TSFValue, (pmlmeinfo->bcn_interval * 1024)) - 1024; /* us */
1302 1302
1303 if (((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)) 1303 if (((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE))
1304 StopTxBeacon(Adapter); 1304 StopTxBeacon(Adapter);
1305 1305
1306 /* disable related TSF function */ 1306 /* disable related TSF function */
1307 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)&(~BIT(3))); 1307 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL) & (~BIT(3)));
1308 1308
1309 usb_write32(Adapter, REG_TSFTR, tsf); 1309 usb_write32(Adapter, REG_TSFTR, tsf);
1310 usb_write32(Adapter, REG_TSFTR+4, tsf>>32); 1310 usb_write32(Adapter, REG_TSFTR + 4, tsf >> 32);
1311 1311
1312 /* enable related TSF function */ 1312 /* enable related TSF function */
1313 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL) | BIT(3)); 1313 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL) | BIT(3));
1314 1314
1315 if (((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)) 1315 if (((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE))
1316 ResumeTxBeacon(Adapter); 1316 ResumeTxBeacon(Adapter);
1317 } 1317 }
1318 break; 1318 break;
1319 case HW_VAR_CHECK_BSSID: 1319 case HW_VAR_CHECK_BSSID:
1320 if (*((u8 *)val)) { 1320 if (*((u8 *)val)) {
1321 usb_write32(Adapter, REG_RCR, usb_read32(Adapter, REG_RCR)|RCR_CBSSID_DATA|RCR_CBSSID_BCN); 1321 usb_write32(Adapter, REG_RCR, usb_read32(Adapter, REG_RCR) | RCR_CBSSID_DATA | RCR_CBSSID_BCN);
1322 } else { 1322 } else {
1323 u32 val32; 1323 u32 val32;
1324 1324
@@ -1357,19 +1357,19 @@ void rtw_hal_set_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
1357 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; 1357 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1358 1358
1359 if ((is_client_associated_to_ap(Adapter)) || 1359 if ((is_client_associated_to_ap(Adapter)) ||
1360 ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE)) { 1360 ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE)) {
1361 /* enable to rx data frame */ 1361 /* enable to rx data frame */
1362 usb_write16(Adapter, REG_RXFLTMAP2, 0xFFFF); 1362 usb_write16(Adapter, REG_RXFLTMAP2, 0xFFFF);
1363 1363
1364 /* enable update TSF */ 1364 /* enable update TSF */
1365 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)&(~BIT(4))); 1365 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL) & (~BIT(4)));
1366 } else if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) { 1366 } else if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) {
1367 usb_write16(Adapter, REG_RXFLTMAP2, 0xFFFF); 1367 usb_write16(Adapter, REG_RXFLTMAP2, 0xFFFF);
1368 /* enable update TSF */ 1368 /* enable update TSF */
1369 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)&(~BIT(4))); 1369 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL) & (~BIT(4)));
1370 } 1370 }
1371 1371
1372 usb_write32(Adapter, REG_RCR, usb_read32(Adapter, REG_RCR)|RCR_CBSSID_BCN); 1372 usb_write32(Adapter, REG_RCR, usb_read32(Adapter, REG_RCR) | RCR_CBSSID_BCN);
1373 } 1373 }
1374 break; 1374 break;
1375 case HW_VAR_MLME_JOIN: 1375 case HW_VAR_MLME_JOIN:
@@ -1382,7 +1382,7 @@ void rtw_hal_set_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
1382 /* enable to rx data frame.Accept all data frame */ 1382 /* enable to rx data frame.Accept all data frame */
1383 usb_write16(Adapter, REG_RXFLTMAP2, 0xFFFF); 1383 usb_write16(Adapter, REG_RXFLTMAP2, 0xFFFF);
1384 1384
1385 usb_write32(Adapter, REG_RCR, usb_read32(Adapter, REG_RCR)|RCR_CBSSID_DATA|RCR_CBSSID_BCN); 1385 usb_write32(Adapter, REG_RCR, usb_read32(Adapter, REG_RCR) | RCR_CBSSID_DATA | RCR_CBSSID_BCN);
1386 1386
1387 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) 1387 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
1388 RetryLimit = (haldata->CustomerID == RT_CID_CCX) ? 7 : 48; 1388 RetryLimit = (haldata->CustomerID == RT_CID_CCX) ? 7 : 48;
@@ -1394,9 +1394,9 @@ void rtw_hal_set_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
1394 } else if (type == 2) { 1394 } else if (type == 2) {
1395 /* sta add event call back */ 1395 /* sta add event call back */
1396 /* enable update TSF */ 1396 /* enable update TSF */
1397 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)&(~BIT(4))); 1397 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL) & (~BIT(4)));
1398 1398
1399 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE)) 1399 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE))
1400 RetryLimit = 0x7; 1400 RetryLimit = 0x7;
1401 } 1401 }
1402 usb_write16(Adapter, REG_RL, RetryLimit << RETRY_LIMIT_SHORT_SHIFT | RetryLimit << RETRY_LIMIT_LONG_SHIFT); 1402 usb_write16(Adapter, REG_RL, RetryLimit << RETRY_LIMIT_SHORT_SHIFT | RetryLimit << RETRY_LIMIT_LONG_SHIFT);
@@ -1432,21 +1432,21 @@ void rtw_hal_set_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
1432 case HW_VAR_RESP_SIFS: 1432 case HW_VAR_RESP_SIFS:
1433 /* RESP_SIFS for CCK */ 1433 /* RESP_SIFS for CCK */
1434 usb_write8(Adapter, REG_R2T_SIFS, val[0]); /* SIFS_T2T_CCK (0x08) */ 1434 usb_write8(Adapter, REG_R2T_SIFS, val[0]); /* SIFS_T2T_CCK (0x08) */
1435 usb_write8(Adapter, REG_R2T_SIFS+1, val[1]); /* SIFS_R2T_CCK(0x08) */ 1435 usb_write8(Adapter, REG_R2T_SIFS + 1, val[1]); /* SIFS_R2T_CCK(0x08) */
1436 /* RESP_SIFS for OFDM */ 1436 /* RESP_SIFS for OFDM */
1437 usb_write8(Adapter, REG_T2T_SIFS, val[2]); /* SIFS_T2T_OFDM (0x0a) */ 1437 usb_write8(Adapter, REG_T2T_SIFS, val[2]); /* SIFS_T2T_OFDM (0x0a) */
1438 usb_write8(Adapter, REG_T2T_SIFS+1, val[3]); /* SIFS_R2T_OFDM(0x0a) */ 1438 usb_write8(Adapter, REG_T2T_SIFS + 1, val[3]); /* SIFS_R2T_OFDM(0x0a) */
1439 break; 1439 break;
1440 case HW_VAR_ACK_PREAMBLE: 1440 case HW_VAR_ACK_PREAMBLE:
1441 { 1441 {
1442 u8 regTmp; 1442 u8 regTmp;
1443 u8 bShortPreamble = *((bool *)val); 1443 u8 bShortPreamble = *((bool *)val);
1444 /* Joseph marked out for Netgear 3500 TKIP channel 7 issue.(Temporarily) */ 1444 /* Joseph marked out for Netgear 3500 TKIP channel 7 issue.(Temporarily) */
1445 regTmp = (haldata->nCur40MhzPrimeSC)<<5; 1445 regTmp = (haldata->nCur40MhzPrimeSC) << 5;
1446 if (bShortPreamble) 1446 if (bShortPreamble)
1447 regTmp |= 0x80; 1447 regTmp |= 0x80;
1448 1448
1449 usb_write8(Adapter, REG_RRSR+2, regTmp); 1449 usb_write8(Adapter, REG_RRSR + 2, regTmp);
1450 } 1450 }
1451 break; 1451 break;
1452 case HW_VAR_SEC_CFG: 1452 case HW_VAR_SEC_CFG:
@@ -1480,12 +1480,13 @@ void rtw_hal_set_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
1480 for (i = 0; i < CAM_CONTENT_COUNT; i++) { 1480 for (i = 0; i < CAM_CONTENT_COUNT; i++) {
1481 /* filled id in CAM config 2 byte */ 1481 /* filled id in CAM config 2 byte */
1482 if (i == 0) 1482 if (i == 0)
1483 ulContent |= (ucIndex & 0x03) | ((u16)(ulEncAlgo)<<2); 1483 ulContent |= (ucIndex & 0x03) | ((u16)(ulEncAlgo) << 2);
1484 else 1484 else
1485 ulContent = 0; 1485 ulContent = 0;
1486 /* polling bit, and No Write enable, and address */ 1486 /* polling bit, and No Write enable, and address */
1487 ulCommand = CAM_CONTENT_COUNT*ucIndex+i; 1487 ulCommand = CAM_CONTENT_COUNT * ucIndex + i;
1488 ulCommand = ulCommand | CAM_POLLINIG|CAM_WRITE; 1488 ulCommand = ulCommand | CAM_POLLINIG |
1489 CAM_WRITE;
1489 /* write content 0 is equall to mark invalid */ 1490 /* write content 0 is equall to mark invalid */
1490 usb_write32(Adapter, WCAMI, ulContent); /* delay_ms(40); */ 1491 usb_write32(Adapter, WCAMI, ulContent); /* delay_ms(40); */
1491 usb_write32(Adapter, RWCAM, ulCommand); /* delay_ms(40); */ 1492 usb_write32(Adapter, RWCAM, ulCommand); /* delay_ms(40); */
@@ -1589,13 +1590,13 @@ void rtw_hal_set_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
1589 FactorToSet = 0xf; 1590 FactorToSet = 0xf;
1590 1591
1591 for (index = 0; index < 4; index++) { 1592 for (index = 0; index < 4; index++) {
1592 if ((pRegToSet[index] & 0xf0) > (FactorToSet<<4)) 1593 if ((pRegToSet[index] & 0xf0) > (FactorToSet << 4))
1593 pRegToSet[index] = (pRegToSet[index] & 0x0f) | (FactorToSet<<4); 1594 pRegToSet[index] = (pRegToSet[index] & 0x0f) | (FactorToSet << 4);
1594 1595
1595 if ((pRegToSet[index] & 0x0f) > FactorToSet) 1596 if ((pRegToSet[index] & 0x0f) > FactorToSet)
1596 pRegToSet[index] = (pRegToSet[index] & 0xf0) | (FactorToSet); 1597 pRegToSet[index] = (pRegToSet[index] & 0xf0) | (FactorToSet);
1597 1598
1598 usb_write8(Adapter, (REG_AGGLEN_LMT+index), pRegToSet[index]); 1599 usb_write8(Adapter, (REG_AGGLEN_LMT + index), pRegToSet[index]);
1599 } 1600 }
1600 } 1601 }
1601 } 1602 }
@@ -1681,9 +1682,9 @@ void rtw_hal_set_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
1681 1682
1682 if (!pwrpriv->bkeepfwalive) { 1683 if (!pwrpriv->bkeepfwalive) {
1683 /* RX DMA stop */ 1684 /* RX DMA stop */
1684 usb_write32(Adapter, REG_RXPKT_NUM, (usb_read32(Adapter, REG_RXPKT_NUM)|RW_RELEASE_EN)); 1685 usb_write32(Adapter, REG_RXPKT_NUM, (usb_read32(Adapter, REG_RXPKT_NUM) | RW_RELEASE_EN));
1685 do { 1686 do {
1686 if (!(usb_read32(Adapter, REG_RXPKT_NUM)&RXDMA_IDLE)) 1687 if (!(usb_read32(Adapter, REG_RXPKT_NUM) & RXDMA_IDLE))
1687 break; 1688 break;
1688 } while (trycnt--); 1689 } while (trycnt--);
1689 if (trycnt == 0) 1690 if (trycnt == 0)
@@ -1706,8 +1707,8 @@ void rtw_hal_set_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
1706 { 1707 {
1707 u8 maxMacid = *val; 1708 u8 maxMacid = *val;
1708 1709
1709 DBG_88E("### MacID(%d),Set Max Tx RPT MID(%d)\n", maxMacid, maxMacid+1); 1710 DBG_88E("### MacID(%d),Set Max Tx RPT MID(%d)\n", maxMacid, maxMacid + 1);
1710 usb_write8(Adapter, REG_TX_RPT_CTRL+1, maxMacid+1); 1711 usb_write8(Adapter, REG_TX_RPT_CTRL + 1, maxMacid + 1);
1711 } 1712 }
1712 break; 1713 break;
1713 case HW_VAR_H2C_MEDIA_STATUS_RPT: 1714 case HW_VAR_H2C_MEDIA_STATUS_RPT:
@@ -1715,7 +1716,7 @@ void rtw_hal_set_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
1715 break; 1716 break;
1716 case HW_VAR_BCN_VALID: 1717 case HW_VAR_BCN_VALID:
1717 /* BCN_VALID, BIT16 of REG_TDECTRL = BIT0 of REG_TDECTRL+2, write 1 to clear, Clear by sw */ 1718 /* BCN_VALID, BIT16 of REG_TDECTRL = BIT0 of REG_TDECTRL+2, write 1 to clear, Clear by sw */
1718 usb_write8(Adapter, REG_TDECTRL+2, usb_read8(Adapter, REG_TDECTRL+2) | BIT(0)); 1719 usb_write8(Adapter, REG_TDECTRL + 2, usb_read8(Adapter, REG_TDECTRL + 2) | BIT(0));
1719 break; 1720 break;
1720 default: 1721 default:
1721 break; 1722 break;
@@ -1733,7 +1734,7 @@ void rtw_hal_get_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
1733 break; 1734 break;
1734 case HW_VAR_BCN_VALID: 1735 case HW_VAR_BCN_VALID:
1735 /* BCN_VALID, BIT16 of REG_TDECTRL = BIT0 of REG_TDECTRL+2 */ 1736 /* BCN_VALID, BIT16 of REG_TDECTRL = BIT0 of REG_TDECTRL+2 */
1736 val[0] = (BIT(0) & usb_read8(Adapter, REG_TDECTRL+2)) ? true : false; 1737 val[0] = (BIT(0) & usb_read8(Adapter, REG_TDECTRL + 2)) ? true : false;
1737 break; 1738 break;
1738 case HW_VAR_FWLPS_RF_ON: 1739 case HW_VAR_FWLPS_RF_ON:
1739 { 1740 {
@@ -1764,7 +1765,7 @@ void rtw_hal_get_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
1764 *val = Adapter->HalData->bMacPwrCtrlOn; 1765 *val = Adapter->HalData->bMacPwrCtrlOn;
1765 break; 1766 break;
1766 case HW_VAR_CHK_HI_QUEUE_EMPTY: 1767 case HW_VAR_CHK_HI_QUEUE_EMPTY:
1767 *val = ((usb_read32(Adapter, REG_HGQ_INFORMATION)&0x0000ff00) == 0) ? true : false; 1768 *val = ((usb_read32(Adapter, REG_HGQ_INFORMATION) & 0x0000ff00) == 0) ? true : false;
1768 break; 1769 break;
1769 default: 1770 default:
1770 break; 1771 break;
@@ -1888,7 +1889,7 @@ void UpdateHalRAMask8188EUsb(struct adapter *adapt, u32 mac_id, u8 rssi_level)
1888 if (mac_id >= NUM_STA) /* CAM_SIZE */ 1889 if (mac_id >= NUM_STA) /* CAM_SIZE */
1889 return; 1890 return;
1890 psta = pmlmeinfo->FW_sta_info[mac_id].psta; 1891 psta = pmlmeinfo->FW_sta_info[mac_id].psta;
1891 if (psta == NULL) 1892 if (!psta)
1892 return; 1893 return;
1893 switch (mac_id) { 1894 switch (mac_id) {
1894 case 0:/* for infra mode */ 1895 case 0:/* for infra mode */
@@ -1925,7 +1926,7 @@ void UpdateHalRAMask8188EUsb(struct adapter *adapt, u32 mac_id, u8 rssi_level)
1925 1926
1926 mask &= rate_bitmap; 1927 mask &= rate_bitmap;
1927 1928
1928 init_rate = get_highest_rate_idx(mask)&0x3f; 1929 init_rate = get_highest_rate_idx(mask) & 0x3f;
1929 1930
1930 ODM_RA_UpdateRateInfo_8188E(odmpriv, mac_id, raid, mask, shortGIrate); 1931 ODM_RA_UpdateRateInfo_8188E(odmpriv, mac_id, raid, mask, shortGIrate);
1931 1932
@@ -1934,7 +1935,7 @@ void UpdateHalRAMask8188EUsb(struct adapter *adapt, u32 mac_id, u8 rssi_level)
1934 psta->init_rate = init_rate; 1935 psta->init_rate = init_rate;
1935} 1936}
1936 1937
1937void rtw_hal_bcn_related_reg_setting(struct adapter *adapt) 1938void beacon_timing_control(struct adapter *adapt)
1938{ 1939{
1939 u32 value32; 1940 u32 value32;
1940 struct mlme_ext_priv *pmlmeext = &adapt->mlmeextpriv; 1941 struct mlme_ext_priv *pmlmeext = &adapt->mlmeextpriv;
diff --git a/drivers/staging/rtl8188eu/include/hal8188e_phy_reg.h b/drivers/staging/rtl8188eu/include/hal8188e_phy_reg.h
index 53afcea21c96..bd915a1f2511 100644
--- a/drivers/staging/rtl8188eu/include/hal8188e_phy_reg.h
+++ b/drivers/staging/rtl8188eu/include/hal8188e_phy_reg.h
@@ -16,55 +16,10 @@
16/* 5. Other definition for BB/RF R/W */ 16/* 5. Other definition for BB/RF R/W */
17/* */ 17/* */
18 18
19
20/* */
21/* 1. PMAC duplicate register due to connection: RF_Mode, TRxRN, NumOf L-STF */
22/* 1. Page1(0x100) */
23/* */
24#define rPMAC_Reset 0x100
25#define rPMAC_TxStart 0x104
26#define rPMAC_TxLegacySIG 0x108
27#define rPMAC_TxHTSIG1 0x10c
28#define rPMAC_TxHTSIG2 0x110
29#define rPMAC_PHYDebug 0x114
30#define rPMAC_TxPacketNum 0x118
31#define rPMAC_TxIdle 0x11c
32#define rPMAC_TxMACHeader0 0x120
33#define rPMAC_TxMACHeader1 0x124
34#define rPMAC_TxMACHeader2 0x128
35#define rPMAC_TxMACHeader3 0x12c
36#define rPMAC_TxMACHeader4 0x130
37#define rPMAC_TxMACHeader5 0x134
38#define rPMAC_TxDataType 0x138
39#define rPMAC_TxRandomSeed 0x13c
40#define rPMAC_CCKPLCPPreamble 0x140
41#define rPMAC_CCKPLCPHeader 0x144
42#define rPMAC_CCKCRC16 0x148
43#define rPMAC_OFDMRxCRC32OK 0x170
44#define rPMAC_OFDMRxCRC32Er 0x174
45#define rPMAC_OFDMRxParityEr 0x178
46#define rPMAC_OFDMRxCRC8Er 0x17c
47#define rPMAC_CCKCRxRC16Er 0x180
48#define rPMAC_CCKCRxRC32Er 0x184
49#define rPMAC_CCKCRxRC32OK 0x188
50#define rPMAC_TxStatus 0x18c
51
52/* 2. Page2(0x200) */
53/* The following two definition are only used for USB interface. */
54#define RF_BB_CMD_ADDR 0x02c0 /* RF/BB r/w cmd address. */
55#define RF_BB_CMD_DATA 0x02c4 /* RF/BB r/w cmd data. */
56
57/* 3. Page8(0x800) */ 19/* 3. Page8(0x800) */
58#define rFPGA0_RFMOD 0x800 /* RF mode & CCK TxSC RF BW Setting */ 20#define rFPGA0_RFMOD 0x800 /* RF mode & CCK TxSC RF BW Setting */
59
60#define rFPGA0_TxInfo 0x804 /* Status report?? */
61#define rFPGA0_PSDFunction 0x808
62
63#define rFPGA0_TxGainStage 0x80c /* Set TX PWR init gain? */ 21#define rFPGA0_TxGainStage 0x80c /* Set TX PWR init gain? */
64 22
65#define rFPGA0_RFTiming1 0x810 /* Useless now */
66#define rFPGA0_RFTiming2 0x814
67
68#define rFPGA0_XA_HSSIParameter1 0x820 /* RF 3 wire register */ 23#define rFPGA0_XA_HSSIParameter1 0x820 /* RF 3 wire register */
69#define rFPGA0_XA_HSSIParameter2 0x824 24#define rFPGA0_XA_HSSIParameter2 0x824
70#define rFPGA0_XB_HSSIParameter1 0x828 25#define rFPGA0_XB_HSSIParameter1 0x828
@@ -73,9 +28,6 @@
73#define rFPGA0_XA_LSSIParameter 0x840 28#define rFPGA0_XA_LSSIParameter 0x840
74#define rFPGA0_XB_LSSIParameter 0x844 29#define rFPGA0_XB_LSSIParameter 0x844
75 30
76#define rFPGA0_RFWakeUpParameter 0x850 /* Useless now */
77#define rFPGA0_RFSleepUpParameter 0x854
78
79#define rFPGA0_XAB_SwitchControl 0x858 /* RF Channel switch */ 31#define rFPGA0_XAB_SwitchControl 0x858 /* RF Channel switch */
80#define rFPGA0_XCD_SwitchControl 0x85c 32#define rFPGA0_XCD_SwitchControl 0x85c
81 33
@@ -86,181 +38,63 @@
86#define rFPGA0_XCD_RFInterfaceSW 0x874 38#define rFPGA0_XCD_RFInterfaceSW 0x874
87 39
88#define rFPGA0_XAB_RFParameter 0x878 /* RF Parameter */ 40#define rFPGA0_XAB_RFParameter 0x878 /* RF Parameter */
89#define rFPGA0_XCD_RFParameter 0x87c
90
91/* Crystal cap setting RF-R/W protection for parameter4?? */
92#define rFPGA0_AnalogParameter1 0x880
93#define rFPGA0_AnalogParameter2 0x884
94#define rFPGA0_AnalogParameter3 0x888
95/* enable ad/da clock1 for dual-phy */
96#define rFPGA0_AdDaClockEn 0x888
97#define rFPGA0_AnalogParameter4 0x88c
98 41
99#define rFPGA0_XA_LSSIReadBack 0x8a0 /* Tranceiver LSSI Readback */ 42#define rFPGA0_XA_LSSIReadBack 0x8a0 /* Tranceiver LSSI Readback */
100#define rFPGA0_XB_LSSIReadBack 0x8a4 43#define rFPGA0_XB_LSSIReadBack 0x8a4
101#define rFPGA0_XC_LSSIReadBack 0x8a8
102#define rFPGA0_XD_LSSIReadBack 0x8ac
103 44
104#define rFPGA0_PSDReport 0x8b4 /* Useless now */
105/* Transceiver A HSPI Readback */
106#define TransceiverA_HSPI_Readback 0x8b8 45#define TransceiverA_HSPI_Readback 0x8b8
107/* Transceiver B HSPI Readback */
108#define TransceiverB_HSPI_Readback 0x8bc 46#define TransceiverB_HSPI_Readback 0x8bc
109/* Useless now RF Interface Readback Value */
110#define rFPGA0_XAB_RFInterfaceRB 0x8e0 47#define rFPGA0_XAB_RFInterfaceRB 0x8e0
111#define rFPGA0_XCD_RFInterfaceRB 0x8e4 /* Useless now */
112 48
113/* 4. Page9(0x900) */ 49/* 4. Page9(0x900) */
114/* RF mode & OFDM TxSC RF BW Setting?? */ 50/* RF mode & OFDM TxSC RF BW Setting?? */
115#define rFPGA1_RFMOD 0x900 51#define rFPGA1_RFMOD 0x900
116 52
117#define rFPGA1_TxBlock 0x904 /* Useless now */
118#define rFPGA1_DebugSelect 0x908 /* Useless now */
119#define rFPGA1_TxInfo 0x90c /* Useless now Status report */
120
121/* 5. PageA(0xA00) */ 53/* 5. PageA(0xA00) */
122/* Set Control channel to upper or lower - required only for 40MHz */ 54/* Set Control channel to upper or lower - required only for 40MHz */
123#define rCCK0_System 0xa00 55#define rCCK0_System 0xa00
124 56
125/* Disable init gain now Select RX path by RSSI */
126#define rCCK0_AFESetting 0xa04
127/* Disable init gain now Init gain */
128#define rCCK0_CCA 0xa08
129
130/* AGC default value, saturation level Antenna Diversity, RX AGC, LNA Threshold,
131 * RX LNA Threshold useless now. Not the same as 90 series
132 */
133#define rCCK0_RxAGC1 0xa0c
134#define rCCK0_RxAGC2 0xa10 /* AGC & DAGC */
135
136#define rCCK0_RxHP 0xa14
137
138/* Timing recovery & Channel estimation threshold */
139#define rCCK0_DSPParameter1 0xa18
140#define rCCK0_DSPParameter2 0xa1c /* SQ threshold */
141
142#define rCCK0_TxFilter1 0xa20
143#define rCCK0_TxFilter2 0xa24
144#define rCCK0_DebugPort 0xa28 /* debug port and Tx filter3 */
145#define rCCK0_FalseAlarmReport 0xa2c /* 0xa2d useless now */
146#define rCCK0_TRSSIReport 0xa50
147#define rCCK0_RxReport 0xa54 /* 0xa57 */
148#define rCCK0_FACounterLower 0xa5c /* 0xa5b */
149#define rCCK0_FACounterUpper 0xa58 /* 0xa5c */
150
151/* */ 57/* */
152/* PageB(0xB00) */ 58/* PageB(0xB00) */
153/* */ 59/* */
154#define rPdp_AntA 0xb00
155#define rPdp_AntA_4 0xb04
156#define rConfig_Pmpd_AntA 0xb28
157#define rConfig_AntA 0xb68 60#define rConfig_AntA 0xb68
158#define rConfig_AntB 0xb6c 61#define rConfig_AntB 0xb6c
159#define rPdp_AntB 0xb70
160#define rPdp_AntB_4 0xb74
161#define rConfig_Pmpd_AntB 0xb98
162#define rAPK 0xbd8
163 62
164/* */ 63/* */
165/* 6. PageC(0xC00) */ 64/* 6. PageC(0xC00) */
166/* */ 65/* */
167#define rOFDM0_LSTF 0xc00
168
169#define rOFDM0_TRxPathEnable 0xc04 66#define rOFDM0_TRxPathEnable 0xc04
170#define rOFDM0_TRMuxPar 0xc08 67#define rOFDM0_TRMuxPar 0xc08
171#define rOFDM0_TRSWIsolation 0xc0c
172 68
173/* RxIQ DC offset, Rx digital filter, DC notch filter */ 69/* RxIQ DC offset, Rx digital filter, DC notch filter */
174#define rOFDM0_XARxAFE 0xc10 70#define rOFDM0_XARxAFE 0xc10
175#define rOFDM0_XARxIQImbalance 0xc14 /* RxIQ imbalance matrix */ 71#define rOFDM0_XARxIQImbalance 0xc14 /* RxIQ imbalance matrix */
176#define rOFDM0_XBRxAFE 0xc18 72#define rOFDM0_XBRxAFE 0xc18
177#define rOFDM0_XBRxIQImbalance 0xc1c 73#define rOFDM0_XBRxIQImbalance 0xc1c
178#define rOFDM0_XCRxAFE 0xc20
179#define rOFDM0_XCRxIQImbalance 0xc24
180#define rOFDM0_XDRxAFE 0xc28
181#define rOFDM0_XDRxIQImbalance 0xc2c
182
183#define rOFDM0_RxDetector1 0xc30 /*PD,BW & SBD DM tune init gain*/
184#define rOFDM0_RxDetector2 0xc34 /* SBD & Fame Sync. */
185#define rOFDM0_RxDetector3 0xc38 /* Frame Sync. */
186#define rOFDM0_RxDetector4 0xc3c /* PD, SBD, Frame Sync & Short-GI */
187 74
188#define rOFDM0_RxDSP 0xc40 /* Rx Sync Path */ 75#define rOFDM0_RxDSP 0xc40 /* Rx Sync Path */
189#define rOFDM0_CFOandDAGC 0xc44 /* CFO & DAGC */
190#define rOFDM0_CCADropThreshold 0xc48 /* CCA Drop threshold */
191#define rOFDM0_ECCAThreshold 0xc4c /* energy CCA */ 76#define rOFDM0_ECCAThreshold 0xc4c /* energy CCA */
192 77
193#define rOFDM0_XAAGCCore1 0xc50 /* DIG */ 78#define rOFDM0_XAAGCCore1 0xc50 /* DIG */
194#define rOFDM0_XAAGCCore2 0xc54 79#define rOFDM0_XAAGCCore2 0xc54
195#define rOFDM0_XBAGCCore1 0xc58 80#define rOFDM0_XBAGCCore1 0xc58
196#define rOFDM0_XBAGCCore2 0xc5c 81#define rOFDM0_XBAGCCore2 0xc5c
197#define rOFDM0_XCAGCCore1 0xc60
198#define rOFDM0_XCAGCCore2 0xc64
199#define rOFDM0_XDAGCCore1 0xc68
200#define rOFDM0_XDAGCCore2 0xc6c
201 82
202#define rOFDM0_AGCParameter1 0xc70
203#define rOFDM0_AGCParameter2 0xc74
204#define rOFDM0_AGCRSSITable 0xc78 83#define rOFDM0_AGCRSSITable 0xc78
205#define rOFDM0_HTSTFAGC 0xc7c
206 84
207#define rOFDM0_XATxIQImbalance 0xc80 /* TX PWR TRACK and DIG */ 85#define rOFDM0_XATxIQImbalance 0xc80 /* TX PWR TRACK and DIG */
208#define rOFDM0_XATxAFE 0xc84 86#define rOFDM0_XATxAFE 0xc84
209#define rOFDM0_XBTxIQImbalance 0xc88 87#define rOFDM0_XBTxIQImbalance 0xc88
210#define rOFDM0_XBTxAFE 0xc8c 88#define rOFDM0_XBTxAFE 0xc8c
211#define rOFDM0_XCTxIQImbalance 0xc90
212#define rOFDM0_XCTxAFE 0xc94 89#define rOFDM0_XCTxAFE 0xc94
213#define rOFDM0_XDTxIQImbalance 0xc98
214#define rOFDM0_XDTxAFE 0xc9c 90#define rOFDM0_XDTxAFE 0xc9c
215 91
216#define rOFDM0_RxIQExtAnta 0xca0 92#define rOFDM0_RxIQExtAnta 0xca0
217#define rOFDM0_TxCoeff1 0xca4
218#define rOFDM0_TxCoeff2 0xca8
219#define rOFDM0_TxCoeff3 0xcac
220#define rOFDM0_TxCoeff4 0xcb0
221#define rOFDM0_TxCoeff5 0xcb4
222#define rOFDM0_TxCoeff6 0xcb8
223#define rOFDM0_RxHPParameter 0xce0
224#define rOFDM0_TxPseudoNoiseWgt 0xce4
225#define rOFDM0_FrameSync 0xcf0
226#define rOFDM0_DFSReport 0xcf4
227
228 93
229/* */ 94/* */
230/* 7. PageD(0xD00) */ 95/* 7. PageD(0xD00) */
231/* */ 96/* */
232#define rOFDM1_LSTF 0xd00 97#define rOFDM1_LSTF 0xd00
233#define rOFDM1_TRxPathEnable 0xd04
234
235#define rOFDM1_CFO 0xd08 /* No setting now */
236#define rOFDM1_CSI1 0xd10
237#define rOFDM1_SBD 0xd14
238#define rOFDM1_CSI2 0xd18
239#define rOFDM1_CFOTracking 0xd2c
240#define rOFDM1_TRxMesaure1 0xd34
241#define rOFDM1_IntfDet 0xd3c
242#define rOFDM1_PseudoNoiseStateAB 0xd50
243#define rOFDM1_PseudoNoiseStateCD 0xd54
244#define rOFDM1_RxPseudoNoiseWgt 0xd58
245
246#define rOFDM_PHYCounter1 0xda0 /* cca, parity fail */
247#define rOFDM_PHYCounter2 0xda4 /* rate illegal, crc8 fail */
248#define rOFDM_PHYCounter3 0xda8 /* MCS not support */
249
250#define rOFDM_ShortCFOAB 0xdac /* No setting now */
251#define rOFDM_ShortCFOCD 0xdb0
252#define rOFDM_LongCFOAB 0xdb4
253#define rOFDM_LongCFOCD 0xdb8
254#define rOFDM_TailCFOAB 0xdbc
255#define rOFDM_TailCFOCD 0xdc0
256#define rOFDM_PWMeasure1 0xdc4
257#define rOFDM_PWMeasure2 0xdc8
258#define rOFDM_BWReport 0xdcc
259#define rOFDM_AGCReport 0xdd0
260#define rOFDM_RxSNR 0xdd4
261#define rOFDM_RxEVMCSI 0xdd8
262#define rOFDM_SIGReport 0xddc
263
264 98
265/* */ 99/* */
266/* 8. PageE(0xE00) */ 100/* 8. PageE(0xE00) */
@@ -292,10 +126,6 @@
292#define rRx_IQK 0xe44 126#define rRx_IQK 0xe44
293#define rIQK_AGC_Pts 0xe48 127#define rIQK_AGC_Pts 0xe48
294#define rIQK_AGC_Rsp 0xe4c 128#define rIQK_AGC_Rsp 0xe4c
295#define rTx_IQK_Tone_B 0xe50
296#define rRx_IQK_Tone_B 0xe54
297#define rTx_IQK_PI_B 0xe58
298#define rRx_IQK_PI_B 0xe5c
299#define rIQK_AGC_Cont 0xe60 129#define rIQK_AGC_Cont 0xe60
300 130
301#define rBlue_Tooth 0xe6c 131#define rBlue_Tooth 0xe6c
@@ -311,17 +141,13 @@
311#define rTx_Power_Before_IQK_A 0xe94 141#define rTx_Power_Before_IQK_A 0xe94
312#define rTx_Power_After_IQK_A 0xe9c 142#define rTx_Power_After_IQK_A 0xe9c
313 143
314#define rRx_Power_Before_IQK_A 0xea0
315#define rRx_Power_Before_IQK_A_2 0xea4 144#define rRx_Power_Before_IQK_A_2 0xea4
316#define rRx_Power_After_IQK_A 0xea8
317#define rRx_Power_After_IQK_A_2 0xeac 145#define rRx_Power_After_IQK_A_2 0xeac
318 146
319#define rTx_Power_Before_IQK_B 0xeb4 147#define rTx_Power_Before_IQK_B 0xeb4
320#define rTx_Power_After_IQK_B 0xebc 148#define rTx_Power_After_IQK_B 0xebc
321 149
322#define rRx_Power_Before_IQK_B 0xec0
323#define rRx_Power_Before_IQK_B_2 0xec4 150#define rRx_Power_Before_IQK_B_2 0xec4
324#define rRx_Power_After_IQK_B 0xec8
325#define rRx_Power_After_IQK_B_2 0xecc 151#define rRx_Power_After_IQK_B_2 0xecc
326 152
327#define rRx_OFDM 0xed0 153#define rRx_OFDM 0xed0
@@ -332,751 +158,44 @@
332#define rPMPD_ANAEN 0xeec 158#define rPMPD_ANAEN 0xeec
333 159
334/* */ 160/* */
335/* 7. RF Register 0x00-0x2E (RF 8256) */
336/* RF-0222D 0x00-3F */
337/* */
338/* Zebra1 */
339#define rZebra1_HSSIEnable 0x0 /* Useless now */
340#define rZebra1_TRxEnable1 0x1
341#define rZebra1_TRxEnable2 0x2
342#define rZebra1_AGC 0x4
343#define rZebra1_ChargePump 0x5
344#define rZebra1_Channel 0x7 /* RF channel switch */
345
346/* endif */
347#define rZebra1_TxGain 0x8 /* Useless now */
348#define rZebra1_TxLPF 0x9
349#define rZebra1_RxLPF 0xb
350#define rZebra1_RxHPFCorner 0xc
351
352/* Zebra4 */
353#define rGlobalCtrl 0 /* Useless now */
354#define rRTL8256_TxLPF 19
355#define rRTL8256_RxLPF 11
356
357/* RTL8258 */
358#define rRTL8258_TxLPF 0x11 /* Useless now */
359#define rRTL8258_RxLPF 0x13
360#define rRTL8258_RSSILPF 0xa
361
362/* */
363/* RL6052 Register definition */ 161/* RL6052 Register definition */
364/* */ 162/* */
365#define RF_AC 0x00 /* */ 163#define RF_AC 0x00 /* */
366
367#define RF_IQADJ_G1 0x01 /* */
368#define RF_IQADJ_G2 0x02 /* */
369
370#define RF_POW_TRSW 0x05 /* */
371
372#define RF_GAIN_RX 0x06 /* */
373#define RF_GAIN_TX 0x07 /* */
374
375#define RF_TXM_IDAC 0x08 /* */
376#define RF_IPA_G 0x09 /* */
377#define RF_TXBIAS_G 0x0A
378#define RF_TXPA_AG 0x0B
379#define RF_IPA_A 0x0C /* */
380#define RF_TXBIAS_A 0x0D
381#define RF_BS_PA_APSET_G9_G11 0x0E
382#define RF_BS_IQGEN 0x0F /* */
383
384#define RF_MODE1 0x10 /* */
385#define RF_MODE2 0x11 /* */
386
387#define RF_RX_AGC_HP 0x12 /* */
388#define RF_TX_AGC 0x13 /* */
389#define RF_BIAS 0x14 /* */
390#define RF_IPA 0x15 /* */
391#define RF_TXBIAS 0x16
392#define RF_POW_ABILITY 0x17 /* */
393#define RF_CHNLBW 0x18 /* RF channel and BW switch */ 164#define RF_CHNLBW 0x18 /* RF channel and BW switch */
394#define RF_TOP 0x19 /* */
395
396#define RF_RX_G1 0x1A /* */
397#define RF_RX_G2 0x1B /* */
398
399#define RF_RX_BB2 0x1C /* */
400#define RF_RX_BB1 0x1D /* */
401
402#define RF_RCK1 0x1E /* */
403#define RF_RCK2 0x1F /* */
404
405#define RF_TX_G1 0x20 /* */
406#define RF_TX_G2 0x21 /* */
407#define RF_TX_G3 0x22 /* */
408
409#define RF_TX_BB1 0x23 /* */
410
411#define RF_T_METER_92D 0x42 /* */
412#define RF_T_METER_88E 0x42 /* */ 165#define RF_T_METER_88E 0x42 /* */
413#define RF_T_METER 0x24 /* */
414
415#define RF_SYN_G1 0x25 /* RF TX Power control */
416#define RF_SYN_G2 0x26 /* RF TX Power control */
417#define RF_SYN_G3 0x27 /* RF TX Power control */
418#define RF_SYN_G4 0x28 /* RF TX Power control */
419#define RF_SYN_G5 0x29 /* RF TX Power control */
420#define RF_SYN_G6 0x2A /* RF TX Power control */
421#define RF_SYN_G7 0x2B /* RF TX Power control */
422#define RF_SYN_G8 0x2C /* RF TX Power control */
423
424#define RF_RCK_OS 0x30 /* RF TX PA control */ 166#define RF_RCK_OS 0x30 /* RF TX PA control */
425#define RF_TXPA_G1 0x31 /* RF TX PA control */ 167#define RF_TXPA_G1 0x31 /* RF TX PA control */
426#define RF_TXPA_G2 0x32 /* RF TX PA control */ 168#define RF_TXPA_G2 0x32 /* RF TX PA control */
427#define RF_TXPA_G3 0x33 /* RF TX PA control */
428#define RF_TX_BIAS_A 0x35
429#define RF_TX_BIAS_D 0x36
430#define RF_LOBF_9 0x38
431#define RF_RXRF_A3 0x3C /* */
432#define RF_TRSW 0x3F
433
434#define RF_TXRF_A2 0x41
435#define RF_TXPA_G4 0x46
436#define RF_TXPA_A4 0x4B
437#define RF_0x52 0x52
438#define RF_WE_LUT 0xEF 169#define RF_WE_LUT 0xEF
439 170
440
441/* */ 171/* */
442/* Bit Mask */ 172/* Bit Mask */
443/* */ 173/* */
444/* 1. Page1(0x100) */
445#define bBBResetB 0x100 /* Useless now? */
446#define bGlobalResetB 0x200
447#define bOFDMTxStart 0x4
448#define bCCKTxStart 0x8
449#define bCRC32Debug 0x100
450#define bPMACLoopback 0x10
451#define bTxLSIG 0xffffff
452#define bOFDMTxRate 0xf
453#define bOFDMTxReserved 0x10
454#define bOFDMTxLength 0x1ffe0
455#define bOFDMTxParity 0x20000
456#define bTxHTSIG1 0xffffff
457#define bTxHTMCSRate 0x7f
458#define bTxHTBW 0x80
459#define bTxHTLength 0xffff00
460#define bTxHTSIG2 0xffffff
461#define bTxHTSmoothing 0x1
462#define bTxHTSounding 0x2
463#define bTxHTReserved 0x4
464#define bTxHTAggreation 0x8
465#define bTxHTSTBC 0x30
466#define bTxHTAdvanceCoding 0x40
467#define bTxHTShortGI 0x80
468#define bTxHTNumberHT_LTF 0x300
469#define bTxHTCRC8 0x3fc00
470#define bCounterReset 0x10000
471#define bNumOfOFDMTx 0xffff
472#define bNumOfCCKTx 0xffff0000
473#define bTxIdleInterval 0xffff
474#define bOFDMService 0xffff0000
475#define bTxMACHeader 0xffffffff
476#define bTxDataInit 0xff
477#define bTxHTMode 0x100
478#define bTxDataType 0x30000
479#define bTxRandomSeed 0xffffffff
480#define bCCKTxPreamble 0x1
481#define bCCKTxSFD 0xffff0000
482#define bCCKTxSIG 0xff
483#define bCCKTxService 0xff00
484#define bCCKLengthExt 0x8000
485#define bCCKTxLength 0xffff0000
486#define bCCKTxCRC16 0xffff
487#define bCCKTxStatus 0x1
488#define bOFDMTxStatus 0x2
489
490#define IS_BB_REG_OFFSET_92S(_Offset) \
491 ((_Offset >= 0x800) && (_Offset <= 0xfff))
492 174
493/* 2. Page8(0x800) */ 175/* 2. Page8(0x800) */
494#define bRFMOD 0x1 /* Reg 0x800 rFPGA0_RFMOD */ 176#define bRFMOD 0x1 /* Reg 0x800 rFPGA0_RFMOD */
495#define bJapanMode 0x2
496#define bCCKTxSC 0x30
497#define bCCKEn 0x1000000 177#define bCCKEn 0x1000000
498#define bOFDMEn 0x2000000 178#define bOFDMEn 0x2000000
499 179
500#define bOFDMRxADCPhase 0x10000 /* Useless now */
501#define bOFDMTxDACPhase 0x40000
502#define bXATxAGC 0x3f
503
504#define bAntennaSelect 0x0300
505
506#define bXBTxAGC 0xf00 /* Reg 80c rFPGA0_TxGainStage */
507#define bXCTxAGC 0xf000
508#define bXDTxAGC 0xf0000
509
510#define bPAStart 0xf0000000 /* Useless now */
511#define bTRStart 0x00f00000
512#define bRFStart 0x0000f000
513#define bBBStart 0x000000f0
514#define bBBCCKStart 0x0000000f
515#define bPAEnd 0xf /* Reg0x814 */
516#define bTREnd 0x0f000000
517#define bRFEnd 0x000f0000
518#define bCCAMask 0x000000f0 /* T2R */
519#define bR2RCCAMask 0x00000f00
520#define bHSSI_R2TDelay 0xf8000000
521#define bHSSI_T2RDelay 0xf80000
522#define bContTxHSSI 0x400 /* change gain at continue Tx */
523#define bIGFromCCK 0x200
524#define bAGCAddress 0x3f
525#define bRxHPTx 0x7000
526#define bRxHPT2R 0x38000
527#define bRxHPCCKIni 0xc0000
528#define bAGCTxCode 0xc00000
529#define bAGCRxCode 0x300000
530
531/* Reg 0x820~84f rFPGA0_XA_HSSIParameter1 */
532#define b3WireDataLength 0x800
533#define b3WireAddressLength 0x400
534
535#define b3WireRFPowerDown 0x1 /* Useless now */
536#define b5GPAPEPolarity 0x40000000
537#define b2GPAPEPolarity 0x80000000
538#define bRFSW_TxDefaultAnt 0x3
539#define bRFSW_TxOptionAnt 0x30
540#define bRFSW_RxDefaultAnt 0x300
541#define bRFSW_RxOptionAnt 0x3000
542#define bRFSI_3WireData 0x1
543#define bRFSI_3WireClock 0x2
544#define bRFSI_3WireLoad 0x4
545#define bRFSI_3WireRW 0x8
546#define bRFSI_3Wire 0xf
547
548#define bRFSI_RFENV 0x10 /* Reg 0x870 rFPGA0_XAB_RFInterfaceSW */
549
550#define bRFSI_TRSW 0x20 /* Useless now */
551#define bRFSI_TRSWB 0x40
552#define bRFSI_ANTSW 0x100
553#define bRFSI_ANTSWB 0x200
554#define bRFSI_PAPE 0x400
555#define bRFSI_PAPE5G 0x800
556#define bBandSelect 0x1
557#define bHTSIG2_GI 0x80
558#define bHTSIG2_Smoothing 0x01
559#define bHTSIG2_Sounding 0x02
560#define bHTSIG2_Aggreaton 0x08
561#define bHTSIG2_STBC 0x30
562#define bHTSIG2_AdvCoding 0x40
563#define bHTSIG2_NumOfHTLTF 0x300
564#define bHTSIG2_CRC8 0x3fc
565#define bHTSIG1_MCS 0x7f
566#define bHTSIG1_BandWidth 0x80
567#define bHTSIG1_HTLength 0xffff
568#define bLSIG_Rate 0xf
569#define bLSIG_Reserved 0x10
570#define bLSIG_Length 0x1fffe
571#define bLSIG_Parity 0x20
572#define bCCKRxPhase 0x4
573
574#define bLSSIReadAddress 0x7f800000 /* T65 RF */ 180#define bLSSIReadAddress 0x7f800000 /* T65 RF */
575
576#define bLSSIReadEdge 0x80000000 /* LSSI "Read" edge signal */ 181#define bLSSIReadEdge 0x80000000 /* LSSI "Read" edge signal */
577
578#define bLSSIReadBackData 0xfffff /* T65 RF */ 182#define bLSSIReadBackData 0xfffff /* T65 RF */
579 183
580#define bLSSIReadOKFlag 0x1000 /* Useless now */
581#define bCCKSampleRate 0x8 /* 0: 44MHz, 1:88MHz */
582#define bRegulator0Standby 0x1
583#define bRegulatorPLLStandby 0x2
584#define bRegulator1Standby 0x4
585#define bPLLPowerUp 0x8
586#define bDPLLPowerUp 0x10
587#define bDA10PowerUp 0x20
588#define bAD7PowerUp 0x200
589#define bDA6PowerUp 0x2000
590#define bXtalPowerUp 0x4000
591#define b40MDClkPowerUP 0x8000
592#define bDA6DebugMode 0x20000
593#define bDA6Swing 0x380000
594
595/* Reg 0x880 rFPGA0_AnalogParameter1 20/40 CCK support switch 40/80 BB MHZ */
596#define bADClkPhase 0x4000000
597
598#define b80MClkDelay 0x18000000 /* Useless */
599#define bAFEWatchDogEnable 0x20000000
600
601/* Reg 0x884 rFPGA0_AnalogParameter2 Crystal cap */
602#define bXtalCap01 0xc0000000
603#define bXtalCap23 0x3
604#define bXtalCap92x 0x0f000000
605#define bXtalCap 0x0f000000
606
607#define bIntDifClkEnable 0x400 /* Useless */
608#define bExtSigClkEnable 0x800
609#define bBandgapMbiasPowerUp 0x10000
610#define bAD11SHGain 0xc0000
611#define bAD11InputRange 0x700000
612#define bAD11OPCurrent 0x3800000
613#define bIPathLoopback 0x4000000
614#define bQPathLoopback 0x8000000
615#define bAFELoopback 0x10000000
616#define bDA10Swing 0x7e0
617#define bDA10Reverse 0x800
618#define bDAClkSource 0x1000
619#define bAD7InputRange 0x6000
620#define bAD7Gain 0x38000
621#define bAD7OutputCMMode 0x40000
622#define bAD7InputCMMode 0x380000
623#define bAD7Current 0xc00000
624#define bRegulatorAdjust 0x7000000
625#define bAD11PowerUpAtTx 0x1
626#define bDA10PSAtTx 0x10
627#define bAD11PowerUpAtRx 0x100
628#define bDA10PSAtRx 0x1000
629#define bCCKRxAGCFormat 0x200
630#define bPSDFFTSamplepPoint 0xc000
631#define bPSDAverageNum 0x3000
632#define bIQPathControl 0xc00
633#define bPSDFreq 0x3ff
634#define bPSDAntennaPath 0x30
635#define bPSDIQSwitch 0x40
636#define bPSDRxTrigger 0x400000
637#define bPSDTxTrigger 0x80000000
638#define bPSDSineToneScale 0x7f000000
639#define bPSDReport 0xffff
640
641/* 3. Page9(0x900) */
642#define bOFDMTxSC 0x30000000 /* Useless */
643#define bCCKTxOn 0x1
644#define bOFDMTxOn 0x2
645#define bDebugPage 0xfff /* reset debug page and HWord, LWord */
646#define bDebugItem 0xff /* reset debug page and LWord */
647#define bAntL 0x10
648#define bAntNonHT 0x100
649#define bAntHT1 0x1000
650#define bAntHT2 0x10000
651#define bAntHT1S1 0x100000
652#define bAntNonHTS1 0x1000000
653
654/* 4. PageA(0xA00) */
655#define bCCKBBMode 0x3 /* Useless */
656#define bCCKTxPowerSaving 0x80
657#define bCCKRxPowerSaving 0x40
658
659#define bCCKSideBand 0x10 /* Reg 0xa00 rCCK0_System 20/40 */ 184#define bCCKSideBand 0x10 /* Reg 0xa00 rCCK0_System 20/40 */
660 185
661#define bCCKScramble 0x8 /* Useless */
662#define bCCKAntDiversity 0x8000
663#define bCCKCarrierRecovery 0x4000
664#define bCCKTxRate 0x3000
665#define bCCKDCCancel 0x0800
666#define bCCKISICancel 0x0400
667#define bCCKMatchFilter 0x0200
668#define bCCKEqualizer 0x0100
669#define bCCKPreambleDetect 0x800000
670#define bCCKFastFalseCCA 0x400000
671#define bCCKChEstStart 0x300000
672#define bCCKCCACount 0x080000
673#define bCCKcs_lim 0x070000
674#define bCCKBistMode 0x80000000
675#define bCCKCCAMask 0x40000000
676#define bCCKTxDACPhase 0x4
677#define bCCKRxADCPhase 0x20000000 /* r_rx_clk */
678#define bCCKr_cp_mode0 0x0100
679#define bCCKTxDCOffset 0xf0
680#define bCCKRxDCOffset 0xf
681#define bCCKCCAMode 0xc000
682#define bCCKFalseCS_lim 0x3f00
683#define bCCKCS_ratio 0xc00000
684#define bCCKCorgBit_sel 0x300000
685#define bCCKPD_lim 0x0f0000
686#define bCCKNewCCA 0x80000000
687#define bCCKRxHPofIG 0x8000
688#define bCCKRxIG 0x7f00
689#define bCCKLNAPolarity 0x800000
690#define bCCKRx1stGain 0x7f0000
691#define bCCKRFExtend 0x20000000 /* CCK Rx Iinital gain polarity */
692#define bCCKRxAGCSatLevel 0x1f000000
693#define bCCKRxAGCSatCount 0xe0
694#define bCCKRxRFSettle 0x1f /* AGCsamp_dly */
695#define bCCKFixedRxAGC 0x8000
696#define bCCKAntennaPolarity 0x2000
697#define bCCKTxFilterType 0x0c00
698#define bCCKRxAGCReportType 0x0300
699#define bCCKRxDAGCEn 0x80000000
700#define bCCKRxDAGCPeriod 0x20000000
701#define bCCKRxDAGCSatLevel 0x1f000000
702#define bCCKTimingRecovery 0x800000
703#define bCCKTxC0 0x3f0000
704#define bCCKTxC1 0x3f000000
705#define bCCKTxC2 0x3f
706#define bCCKTxC3 0x3f00
707#define bCCKTxC4 0x3f0000
708#define bCCKTxC5 0x3f000000
709#define bCCKTxC6 0x3f
710#define bCCKTxC7 0x3f00
711#define bCCKDebugPort 0xff0000
712#define bCCKDACDebug 0x0f000000
713#define bCCKFalseAlarmEnable 0x8000
714#define bCCKFalseAlarmRead 0x4000
715#define bCCKTRSSI 0x7f
716#define bCCKRxAGCReport 0xfe
717#define bCCKRxReport_AntSel 0x80000000
718#define bCCKRxReport_MFOff 0x40000000
719#define bCCKRxRxReport_SQLoss 0x20000000
720#define bCCKRxReport_Pktloss 0x10000000
721#define bCCKRxReport_Lockedbit 0x08000000
722#define bCCKRxReport_RateError 0x04000000
723#define bCCKRxReport_RxRate 0x03000000
724#define bCCKRxFACounterLower 0xff
725#define bCCKRxFACounterUpper 0xff000000
726#define bCCKRxHPAGCStart 0xe000
727#define bCCKRxHPAGCFinal 0x1c00
728#define bCCKRxFalseAlarmEnable 0x8000
729#define bCCKFACounterFreeze 0x4000
730#define bCCKTxPathSel 0x10000000
731#define bCCKDefaultRxPath 0xc000000
732#define bCCKOptionRxPath 0x3000000
733
734/* 5. PageC(0xC00) */
735#define bNumOfSTF 0x3 /* Useless */
736#define bShift_L 0xc0
737#define bGI_TH 0xc
738#define bRxPathA 0x1
739#define bRxPathB 0x2
740#define bRxPathC 0x4
741#define bRxPathD 0x8
742#define bTxPathA 0x1
743#define bTxPathB 0x2
744#define bTxPathC 0x4
745#define bTxPathD 0x8
746#define bTRSSIFreq 0x200
747#define bADCBackoff 0x3000
748#define bDFIRBackoff 0xc000
749#define bTRSSILatchPhase 0x10000
750#define bRxIDCOffset 0xff
751#define bRxQDCOffset 0xff00
752#define bRxDFIRMode 0x1800000
753#define bRxDCNFType 0xe000000
754#define bRXIQImb_A 0x3ff
755#define bRXIQImb_B 0xfc00
756#define bRXIQImb_C 0x3f0000
757#define bRXIQImb_D 0xffc00000
758#define bDC_dc_Notch 0x60000
759#define bRxNBINotch 0x1f000000
760#define bPD_TH 0xf
761#define bPD_TH_Opt2 0xc000
762#define bPWED_TH 0x700
763#define bIfMF_Win_L 0x800
764#define bPD_Option 0x1000
765#define bMF_Win_L 0xe000
766#define bBW_Search_L 0x30000
767#define bwin_enh_L 0xc0000
768#define bBW_TH 0x700000
769#define bED_TH2 0x3800000
770#define bBW_option 0x4000000
771#define bRatio_TH 0x18000000
772#define bWindow_L 0xe0000000
773#define bSBD_Option 0x1
774#define bFrame_TH 0x1c
775#define bFS_Option 0x60
776#define bDC_Slope_check 0x80
777#define bFGuard_Counter_DC_L 0xe00
778#define bFrame_Weight_Short 0x7000
779#define bSub_Tune 0xe00000
780#define bFrame_DC_Length 0xe000000
781#define bSBD_start_offset 0x30000000
782#define bFrame_TH_2 0x7
783#define bFrame_GI2_TH 0x38
784#define bGI2_Sync_en 0x40
785#define bSarch_Short_Early 0x300
786#define bSarch_Short_Late 0xc00
787#define bSarch_GI2_Late 0x70000
788#define bCFOAntSum 0x1
789#define bCFOAcc 0x2
790#define bCFOStartOffset 0xc
791#define bCFOLookBack 0x70
792#define bCFOSumWeight 0x80
793#define bDAGCEnable 0x10000
794#define bTXIQImb_A 0x3ff
795#define bTXIQImb_B 0xfc00
796#define bTXIQImb_C 0x3f0000
797#define bTXIQImb_D 0xffc00000
798#define bTxIDCOffset 0xff
799#define bTxQDCOffset 0xff00
800#define bTxDFIRMode 0x10000
801#define bTxPesudoNoiseOn 0x4000000
802#define bTxPesudoNoise_A 0xff
803#define bTxPesudoNoise_B 0xff00
804#define bTxPesudoNoise_C 0xff0000
805#define bTxPesudoNoise_D 0xff000000
806#define bCCADropOption 0x20000
807#define bCCADropThres 0xfff00000
808#define bEDCCA_H 0xf
809#define bEDCCA_L 0xf0
810#define bLambda_ED 0x300
811#define bRxInitialGain 0x7f
812#define bRxAntDivEn 0x80
813#define bRxAGCAddressForLNA 0x7f00
814#define bRxHighPowerFlow 0x8000
815#define bRxAGCFreezeThres 0xc0000
816#define bRxFreezeStep_AGC1 0x300000
817#define bRxFreezeStep_AGC2 0xc00000
818#define bRxFreezeStep_AGC3 0x3000000
819#define bRxFreezeStep_AGC0 0xc000000
820#define bRxRssi_Cmp_En 0x10000000
821#define bRxQuickAGCEn 0x20000000
822#define bRxAGCFreezeThresMode 0x40000000
823#define bRxOverFlowCheckType 0x80000000
824#define bRxAGCShift 0x7f
825#define bTRSW_Tri_Only 0x80
826#define bPowerThres 0x300
827#define bRxAGCEn 0x1
828#define bRxAGCTogetherEn 0x2
829#define bRxAGCMin 0x4
830#define bRxHP_Ini 0x7
831#define bRxHP_TRLNA 0x70
832#define bRxHP_RSSI 0x700
833#define bRxHP_BBP1 0x7000
834#define bRxHP_BBP2 0x70000
835#define bRxHP_BBP3 0x700000
836#define bRSSI_H 0x7f0000 /* threshold for high power */
837#define bRSSI_Gen 0x7f000000 /* threshold for ant diversity */
838#define bRxSettle_TRSW 0x7
839#define bRxSettle_LNA 0x38
840#define bRxSettle_RSSI 0x1c0
841#define bRxSettle_BBP 0xe00
842#define bRxSettle_RxHP 0x7000
843#define bRxSettle_AntSW_RSSI 0x38000
844#define bRxSettle_AntSW 0xc0000
845#define bRxProcessTime_DAGC 0x300000
846#define bRxSettle_HSSI 0x400000
847#define bRxProcessTime_BBPPW 0x800000
848#define bRxAntennaPowerShift 0x3000000
849#define bRSSITableSelect 0xc000000
850#define bRxHP_Final 0x7000000
851#define bRxHTSettle_BBP 0x7
852#define bRxHTSettle_HSSI 0x8
853#define bRxHTSettle_RxHP 0x70
854#define bRxHTSettle_BBPPW 0x80
855#define bRxHTSettle_Idle 0x300
856#define bRxHTSettle_Reserved 0x1c00
857#define bRxHTRxHPEn 0x8000
858#define bRxHTAGCFreezeThres 0x30000
859#define bRxHTAGCTogetherEn 0x40000
860#define bRxHTAGCMin 0x80000
861#define bRxHTAGCEn 0x100000
862#define bRxHTDAGCEn 0x200000
863#define bRxHTRxHP_BBP 0x1c00000
864#define bRxHTRxHP_Final 0xe0000000
865#define bRxPWRatioTH 0x3
866#define bRxPWRatioEn 0x4
867#define bRxMFHold 0x3800
868#define bRxPD_Delay_TH1 0x38
869#define bRxPD_Delay_TH2 0x1c0
870#define bRxPD_DC_COUNT_MAX 0x600
871#define bRxPD_Delay_TH 0x8000
872#define bRxProcess_Delay 0xf0000
873#define bRxSearchrange_GI2_Early 0x700000
874#define bRxFrame_Guard_Counter_L 0x3800000
875#define bRxSGI_Guard_L 0xc000000
876#define bRxSGI_Search_L 0x30000000
877#define bRxSGI_TH 0xc0000000
878#define bDFSCnt0 0xff
879#define bDFSCnt1 0xff00
880#define bDFSFlag 0xf0000
881#define bMFWeightSum 0x300000
882#define bMinIdxTH 0x7f000000
883#define bDAFormat 0x40000
884#define bTxChEmuEnable 0x01000000
885#define bTRSWIsolation_A 0x7f
886#define bTRSWIsolation_B 0x7f00
887#define bTRSWIsolation_C 0x7f0000
888#define bTRSWIsolation_D 0x7f000000
889#define bExtLNAGain 0x7c00
890
891/* 6. PageE(0xE00) */
892#define bSTBCEn 0x4 /* Useless */
893#define bAntennaMapping 0x10
894#define bNss 0x20
895#define bCFOAntSumD 0x200
896#define bPHYCounterReset 0x8000000
897#define bCFOReportGet 0x4000000
898#define bOFDMContinueTx 0x10000000
899#define bOFDMSingleCarrier 0x20000000
900#define bOFDMSingleTone 0x40000000
901#define bHTDetect 0x100
902#define bCFOEn 0x10000
903#define bCFOValue 0xfff00000
904#define bSigTone_Re 0x3f
905#define bSigTone_Im 0x7f00
906#define bCounter_CCA 0xffff
907#define bCounter_ParityFail 0xffff0000
908#define bCounter_RateIllegal 0xffff
909#define bCounter_CRC8Fail 0xffff0000
910#define bCounter_MCSNoSupport 0xffff
911#define bCounter_FastSync 0xffff
912#define bShortCFO 0xfff
913#define bShortCFOTLength 12 /* total */
914#define bShortCFOFLength 11 /* fraction */
915#define bLongCFO 0x7ff
916#define bLongCFOTLength 11
917#define bLongCFOFLength 11
918#define bTailCFO 0x1fff
919#define bTailCFOTLength 13
920#define bTailCFOFLength 12
921#define bmax_en_pwdB 0xffff
922#define bCC_power_dB 0xffff0000
923#define bnoise_pwdB 0xffff
924#define bPowerMeasTLength 10
925#define bPowerMeasFLength 3
926#define bRx_HT_BW 0x1
927#define bRxSC 0x6
928#define bRx_HT 0x8
929#define bNB_intf_det_on 0x1
930#define bIntf_win_len_cfg 0x30
931#define bNB_Intf_TH_cfg 0x1c0
932#define bRFGain 0x3f
933#define bTableSel 0x40
934#define bTRSW 0x80
935#define bRxSNR_A 0xff
936#define bRxSNR_B 0xff00
937#define bRxSNR_C 0xff0000
938#define bRxSNR_D 0xff000000
939#define bSNREVMTLength 8
940#define bSNREVMFLength 1
941#define bCSI1st 0xff
942#define bCSI2nd 0xff00
943#define bRxEVM1st 0xff0000
944#define bRxEVM2nd 0xff000000
945#define bSIGEVM 0xff
946#define bPWDB 0xff00
947#define bSGIEN 0x10000
948
949#define bSFactorQAM1 0xf /* Useless */
950#define bSFactorQAM2 0xf0
951#define bSFactorQAM3 0xf00
952#define bSFactorQAM4 0xf000
953#define bSFactorQAM5 0xf0000
954#define bSFactorQAM6 0xf0000
955#define bSFactorQAM7 0xf00000
956#define bSFactorQAM8 0xf000000
957#define bSFactorQAM9 0xf0000000
958#define bCSIScheme 0x100000
959
960#define bNoiseLvlTopSet 0x3 /* Useless */
961#define bChSmooth 0x4
962#define bChSmoothCfg1 0x38
963#define bChSmoothCfg2 0x1c0
964#define bChSmoothCfg3 0xe00
965#define bChSmoothCfg4 0x7000
966#define bMRCMode 0x800000
967#define bTHEVMCfg 0x7000000
968
969#define bLoopFitType 0x1 /* Useless */
970#define bUpdCFO 0x40
971#define bUpdCFOOffData 0x80
972#define bAdvUpdCFO 0x100
973#define bAdvTimeCtrl 0x800
974#define bUpdClko 0x1000
975#define bFC 0x6000
976#define bTrackingMode 0x8000
977#define bPhCmpEnable 0x10000
978#define bUpdClkoLTF 0x20000
979#define bComChCFO 0x40000
980#define bCSIEstiMode 0x80000
981#define bAdvUpdEqz 0x100000
982#define bUChCfg 0x7000000
983#define bUpdEqz 0x8000000
984
985/* Rx Pseduo noise */
986#define bRxPesudoNoiseOn 0x20000000 /* Useless */
987#define bRxPesudoNoise_A 0xff
988#define bRxPesudoNoise_B 0xff00
989#define bRxPesudoNoise_C 0xff0000
990#define bRxPesudoNoise_D 0xff000000
991#define bPesudoNoiseState_A 0xffff
992#define bPesudoNoiseState_B 0xffff0000
993#define bPesudoNoiseState_C 0xffff
994#define bPesudoNoiseState_D 0xffff0000
995
996/* 7. RF Register */
997/* Zebra1 */
998#define bZebra1_HSSIEnable 0x8 /* Useless */
999#define bZebra1_TRxControl 0xc00
1000#define bZebra1_TRxGainSetting 0x07f
1001#define bZebra1_RxCorner 0xc00
1002#define bZebra1_TxChargePump 0x38
1003#define bZebra1_RxChargePump 0x7
1004#define bZebra1_ChannelNum 0xf80
1005#define bZebra1_TxLPFBW 0x400
1006#define bZebra1_RxLPFBW 0x600
1007
1008/* Zebra4 */
1009#define bRTL8256RegModeCtrl1 0x100 /* Useless */
1010#define bRTL8256RegModeCtrl0 0x40
1011#define bRTL8256_TxLPFBW 0x18
1012#define bRTL8256_RxLPFBW 0x600
1013
1014/* RTL8258 */
1015#define bRTL8258_TxLPFBW 0xc /* Useless */
1016#define bRTL8258_RxLPFBW 0xc00
1017#define bRTL8258_RSSILPFBW 0xc0
1018
1019
1020/* */ 186/* */
1021/* Other Definition */ 187/* Other Definition */
1022/* */ 188/* */
1023 189
1024/* byte endable for sb_write */
1025#define bByte0 0x1 /* Useless */
1026#define bByte1 0x2
1027#define bByte2 0x4
1028#define bByte3 0x8
1029#define bWord0 0x3
1030#define bWord1 0xc
1031#define bDWord 0xf
1032
1033/* for PutRegsetting & GetRegSetting BitMask */ 190/* for PutRegsetting & GetRegSetting BitMask */
1034#define bMaskByte0 0xff /* Reg 0xc50 rOFDM0_XAAGCCore~0xC6f */ 191#define bMaskByte0 0xff /* Reg 0xc50 rOFDM0_XAAGCCore~0xC6f */
1035#define bMaskByte1 0xff00 192#define bMaskByte1 0xff00
1036#define bMaskByte2 0xff0000
1037#define bMaskByte3 0xff000000 193#define bMaskByte3 0xff000000
1038#define bMaskHWord 0xffff0000
1039#define bMaskLWord 0x0000ffff
1040#define bMaskDWord 0xffffffff 194#define bMaskDWord 0xffffffff
1041#define bMask12Bits 0xfff 195#define bMask12Bits 0xfff
1042#define bMaskH4Bits 0xf0000000
1043#define bMaskOFDM_D 0xffc00000 196#define bMaskOFDM_D 0xffc00000
1044#define bMaskCCK 0x3f3f3f3f
1045 197
1046/* for PutRFRegsetting & GetRFRegSetting BitMask */ 198/* for PutRFRegsetting & GetRFRegSetting BitMask */
1047#define bRFRegOffsetMask 0xfffff 199#define bRFRegOffsetMask 0xfffff
1048 200
1049#define bEnable 0x1 /* Useless */
1050#define bDisable 0x0
1051
1052#define LeftAntenna 0x0 /* Useless */
1053#define RightAntenna 0x1
1054
1055#define tCheckTxStatus 500 /* 500ms Useless */
1056#define tUpdateRxCounter 100 /* 100ms */
1057
1058#define rateCCK 0 /* Useless */
1059#define rateOFDM 1
1060#define rateHT 2
1061
1062/* define Register-End */
1063#define bPMAC_End 0x1ff /* Useless */
1064#define bFPGAPHY0_End 0x8ff
1065#define bFPGAPHY1_End 0x9ff
1066#define bCCKPHY0_End 0xaff
1067#define bOFDMPHY0_End 0xcff
1068#define bOFDMPHY1_End 0xdff
1069
1070#define bPMACControl 0x0 /* Useless */
1071#define bWMACControl 0x1
1072#define bWNICControl 0x2
1073
1074#define PathA 0x0 /* Useless */
1075#define PathB 0x1
1076#define PathC 0x2
1077#define PathD 0x3
1078
1079/*--------------------------Define Parameters-------------------------------*/
1080
1081
1082#endif 201#endif
diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
index 8b65fcba1967..516a89647003 100644
--- a/drivers/staging/rtl8188eu/include/hal_intf.h
+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
@@ -199,7 +199,7 @@ void rtw_hal_add_ra_tid(struct adapter *adapt, u32 bitmap, u8 arg, u8 level);
199void rtw_hal_clone_data(struct adapter *dst_adapt, 199void rtw_hal_clone_data(struct adapter *dst_adapt,
200 struct adapter *src_adapt); 200 struct adapter *src_adapt);
201 201
202void rtw_hal_bcn_related_reg_setting(struct adapter *padapter); 202void beacon_timing_control(struct adapter *padapter);
203 203
204u32 rtw_hal_read_rfreg(struct adapter *padapter, enum rf_radio_path eRFPath, 204u32 rtw_hal_read_rfreg(struct adapter *padapter, enum rf_radio_path eRFPath,
205 u32 RegAddr, u32 BitMask); 205 u32 RegAddr, u32 BitMask);
diff --git a/drivers/staging/rtl8188eu/include/mlme_osdep.h b/drivers/staging/rtl8188eu/include/mlme_osdep.h
index eda16c06336a..8e919441c2aa 100644
--- a/drivers/staging/rtl8188eu/include/mlme_osdep.h
+++ b/drivers/staging/rtl8188eu/include/mlme_osdep.h
@@ -13,7 +13,6 @@
13void rtw_init_mlme_timer(struct adapter *padapter); 13void rtw_init_mlme_timer(struct adapter *padapter);
14void rtw_os_indicate_disconnect(struct adapter *adapter); 14void rtw_os_indicate_disconnect(struct adapter *adapter);
15void rtw_os_indicate_connect(struct adapter *adapter); 15void rtw_os_indicate_connect(struct adapter *adapter);
16void rtw_os_indicate_scan_done(struct adapter *padapter, bool aborted);
17void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie); 16void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie);
18 17
19void rtw_reset_securitypriv(struct adapter *adapter); 18void rtw_reset_securitypriv(struct adapter *adapter);
diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h b/drivers/staging/rtl8188eu/include/osdep_service.h
index cfe5698fbbb1..c0114ad79788 100644
--- a/drivers/staging/rtl8188eu/include/osdep_service.h
+++ b/drivers/staging/rtl8188eu/include/osdep_service.h
@@ -80,8 +80,6 @@ void rtw_free_netdev(struct net_device *netdev);
80#define FUNC_ADPT_FMT "%s(%s)" 80#define FUNC_ADPT_FMT "%s(%s)"
81#define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name 81#define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name
82 82
83u64 rtw_modular64(u64 x, u64 y);
84
85/* Macros for handling unaligned memory accesses */ 83/* Macros for handling unaligned memory accesses */
86 84
87#define RTW_GET_BE24(a) ((((u32)(a)[0]) << 16) | (((u32) (a)[1]) << 8) | \ 85#define RTW_GET_BE24(a) ((((u32)(a)[0]) << 16) | (((u32) (a)[1]) << 8) | \
diff --git a/drivers/staging/rtl8188eu/include/rtw_mlme.h b/drivers/staging/rtl8188eu/include/rtw_mlme.h
index 9abb7c320192..010f0c42368a 100644
--- a/drivers/staging/rtl8188eu/include/rtw_mlme.h
+++ b/drivers/staging/rtl8188eu/include/rtw_mlme.h
@@ -333,7 +333,7 @@ void rtw_dynamic_check_timer_handlder(struct timer_list *t);
333 333
334void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv); 334void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv);
335 335
336struct wlan_network *_rtw_alloc_network(struct mlme_priv *pmlmepriv); 336struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv);
337 337
338int rtw_if_up(struct adapter *padapter); 338int rtw_if_up(struct adapter *padapter);
339 339
diff --git a/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h b/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
index 327f7d1bc20c..d70780c8fd62 100644
--- a/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
+++ b/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
@@ -535,7 +535,6 @@ void report_del_sta_event(struct adapter *padapter,
535void report_add_sta_event(struct adapter *padapter, unsigned char *addr, 535void report_add_sta_event(struct adapter *padapter, unsigned char *addr,
536 int cam_idx); 536 int cam_idx);
537 537
538void beacon_timing_control(struct adapter *padapter);
539u8 set_tx_beacon_cmd(struct adapter *padapter); 538u8 set_tx_beacon_cmd(struct adapter *padapter);
540unsigned int setup_beacon_frame(struct adapter *padapter, 539unsigned int setup_beacon_frame(struct adapter *padapter,
541 unsigned char *beacon_frame); 540 unsigned char *beacon_frame);
diff --git a/drivers/staging/rtl8188eu/os_dep/mlme_linux.c b/drivers/staging/rtl8188eu/os_dep/mlme_linux.c
index e660bd4d91ef..321b2c46479c 100644
--- a/drivers/staging/rtl8188eu/os_dep/mlme_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/mlme_linux.c
@@ -27,11 +27,6 @@ void rtw_os_indicate_connect(struct adapter *adapter)
27 netif_carrier_on(adapter->pnetdev); 27 netif_carrier_on(adapter->pnetdev);
28} 28}
29 29
30void rtw_os_indicate_scan_done(struct adapter *padapter, bool aborted)
31{
32 indicate_wx_scan_complete_event(padapter);
33}
34
35static struct rt_pmkid_list backup_pmkid[NUM_PMKID_CACHE]; 30static struct rt_pmkid_list backup_pmkid[NUM_PMKID_CACHE];
36 31
37void rtw_reset_securitypriv(struct adapter *adapter) 32void rtw_reset_securitypriv(struct adapter *adapter)
diff --git a/drivers/staging/rtl8188eu/os_dep/osdep_service.c b/drivers/staging/rtl8188eu/os_dep/osdep_service.c
index 105f3f21bdea..69d4b1d66b6f 100644
--- a/drivers/staging/rtl8188eu/os_dep/osdep_service.c
+++ b/drivers/staging/rtl8188eu/os_dep/osdep_service.c
@@ -59,11 +59,6 @@ RETURN:
59 return; 59 return;
60} 60}
61 61
62u64 rtw_modular64(u64 x, u64 y)
63{
64 return do_div(x, y);
65}
66
67void rtw_buf_free(u8 **buf, u32 *buf_len) 62void rtw_buf_free(u8 **buf, u32 *buf_len)
68{ 63{
69 *buf_len = 0; 64 *buf_len = 0;
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index eedf2cd831d1..aaab0d577453 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -122,8 +122,7 @@ static int recvbuf2recvframe(struct adapter *adapt, struct sk_buff *pskb)
122 precvframe->pkt = pkt_copy; 122 precvframe->pkt = pkt_copy;
123 skb_reserve(pkt_copy, 8 - ((size_t)(pkt_copy->data) & 7));/* force pkt_copy->data at 8-byte alignment address */ 123 skb_reserve(pkt_copy, 8 - ((size_t)(pkt_copy->data) & 7));/* force pkt_copy->data at 8-byte alignment address */
124 skb_reserve(pkt_copy, shift_sz);/* force ip_hdr at 8-byte alignment address according to shift_sz. */ 124 skb_reserve(pkt_copy, shift_sz);/* force ip_hdr at 8-byte alignment address according to shift_sz. */
125 memcpy(pkt_copy->data, (pbuf + pattrib->drvinfo_sz + RXDESC_SIZE), skb_len); 125 skb_put_data(pkt_copy, (pbuf + pattrib->drvinfo_sz + RXDESC_SIZE), skb_len);
126 skb_put(precvframe->pkt, skb_len);
127 } else { 126 } else {
128 DBG_88E("%s: alloc_skb fail , drop frag frame\n", 127 DBG_88E("%s: alloc_skb fail , drop frag frame\n",
129 __func__); 128 __func__);
diff --git a/drivers/staging/rtl8192e/Kconfig b/drivers/staging/rtl8192e/Kconfig
index 11528d17bb3c..1007eea6c8fc 100644
--- a/drivers/staging/rtl8192e/Kconfig
+++ b/drivers/staging/rtl8192e/Kconfig
@@ -15,6 +15,7 @@ config RTLLIB_CRYPTO_CCMP
15 tristate "Support for rtllib CCMP crypto" 15 tristate "Support for rtllib CCMP crypto"
16 depends on RTLLIB 16 depends on RTLLIB
17 select CRYPTO_AES 17 select CRYPTO_AES
18 select CRYPTO_CCM
18 default y 19 default y
19 help 20 help
20 CCMP crypto driver for rtllib. 21 CCMP crypto driver for rtllib.
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
index 1b7e3fda7905..20e494186c9e 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
@@ -618,7 +618,7 @@ static void _rtl92e_dm_tx_update_tssi_strong_signal(struct net_device *dev,
618static void _rtl92e_dm_tx_power_tracking_callback_tssi(struct net_device *dev) 618static void _rtl92e_dm_tx_power_tracking_callback_tssi(struct net_device *dev)
619{ 619{
620 struct r8192_priv *priv = rtllib_priv(dev); 620 struct r8192_priv *priv = rtllib_priv(dev);
621 bool bHighpowerstate, viviflag = false; 621 bool viviflag = false;
622 struct dcmd_txcmd tx_cmd; 622 struct dcmd_txcmd tx_cmd;
623 u8 powerlevelOFDM24G; 623 u8 powerlevelOFDM24G;
624 int i = 0, j = 0, k = 0; 624 int i = 0, j = 0, k = 0;
@@ -632,7 +632,6 @@ static void _rtl92e_dm_tx_power_tracking_callback_tssi(struct net_device *dev)
632 rtl92e_writeb(dev, Pw_Track_Flag, 0); 632 rtl92e_writeb(dev, Pw_Track_Flag, 0);
633 rtl92e_writeb(dev, FW_Busy_Flag, 0); 633 rtl92e_writeb(dev, FW_Busy_Flag, 0);
634 priv->rtllib->bdynamic_txpower_enable = false; 634 priv->rtllib->bdynamic_txpower_enable = false;
635 bHighpowerstate = priv->bDynamicTxHighPower;
636 635
637 powerlevelOFDM24G = (u8)(priv->Pwr_Track>>24); 636 powerlevelOFDM24G = (u8)(priv->Pwr_Track>>24);
638 RF_Type = priv->rf_type; 637 RF_Type = priv->rf_type;
@@ -1901,7 +1900,7 @@ static void _rtl92e_dm_rx_path_sel_byrssi(struct net_device *dev)
1901 u8 cck_default_Rx = 0x2; 1900 u8 cck_default_Rx = 0x2;
1902 u8 cck_optional_Rx = 0x3; 1901 u8 cck_optional_Rx = 0x3;
1903 long tmp_cck_max_pwdb = 0, tmp_cck_min_pwdb = 0, tmp_cck_sec_pwdb = 0; 1902 long tmp_cck_max_pwdb = 0, tmp_cck_min_pwdb = 0, tmp_cck_sec_pwdb = 0;
1904 u8 cck_rx_ver2_max_index = 0, cck_rx_ver2_min_index = 0; 1903 u8 cck_rx_ver2_max_index = 0;
1905 u8 cck_rx_ver2_sec_index = 0; 1904 u8 cck_rx_ver2_sec_index = 0;
1906 u8 cur_rf_rssi; 1905 u8 cur_rf_rssi;
1907 long cur_cck_pwdb; 1906 long cur_cck_pwdb;
@@ -1984,7 +1983,6 @@ static void _rtl92e_dm_rx_path_sel_byrssi(struct net_device *dev)
1984 1983
1985 if (rf_num == 1) { 1984 if (rf_num == 1) {
1986 cck_rx_ver2_max_index = i; 1985 cck_rx_ver2_max_index = i;
1987 cck_rx_ver2_min_index = i;
1988 cck_rx_ver2_sec_index = i; 1986 cck_rx_ver2_sec_index = i;
1989 tmp_cck_max_pwdb = cur_cck_pwdb; 1987 tmp_cck_max_pwdb = cur_cck_pwdb;
1990 tmp_cck_min_pwdb = cur_cck_pwdb; 1988 tmp_cck_min_pwdb = cur_cck_pwdb;
@@ -1997,7 +1995,6 @@ static void _rtl92e_dm_rx_path_sel_byrssi(struct net_device *dev)
1997 tmp_cck_sec_pwdb = cur_cck_pwdb; 1995 tmp_cck_sec_pwdb = cur_cck_pwdb;
1998 tmp_cck_min_pwdb = cur_cck_pwdb; 1996 tmp_cck_min_pwdb = cur_cck_pwdb;
1999 cck_rx_ver2_sec_index = i; 1997 cck_rx_ver2_sec_index = i;
2000 cck_rx_ver2_min_index = i;
2001 } 1998 }
2002 } else { 1999 } else {
2003 if (cur_cck_pwdb > tmp_cck_max_pwdb) { 2000 if (cur_cck_pwdb > tmp_cck_max_pwdb) {
@@ -2027,13 +2024,10 @@ static void _rtl92e_dm_rx_path_sel_byrssi(struct net_device *dev)
2027 (cur_cck_pwdb > tmp_cck_min_pwdb)) { 2024 (cur_cck_pwdb > tmp_cck_min_pwdb)) {
2028 ; 2025 ;
2029 } else if (cur_cck_pwdb == tmp_cck_min_pwdb) { 2026 } else if (cur_cck_pwdb == tmp_cck_min_pwdb) {
2030 if (tmp_cck_sec_pwdb == tmp_cck_min_pwdb) { 2027 if (tmp_cck_sec_pwdb == tmp_cck_min_pwdb)
2031 tmp_cck_min_pwdb = cur_cck_pwdb; 2028 tmp_cck_min_pwdb = cur_cck_pwdb;
2032 cck_rx_ver2_min_index = i;
2033 }
2034 } else if (cur_cck_pwdb < tmp_cck_min_pwdb) { 2029 } else if (cur_cck_pwdb < tmp_cck_min_pwdb) {
2035 tmp_cck_min_pwdb = cur_cck_pwdb; 2030 tmp_cck_min_pwdb = cur_cck_pwdb;
2036 cck_rx_ver2_min_index = i;
2037 } 2031 }
2038 } 2032 }
2039 2033
diff --git a/drivers/staging/rtl8192e/rtllib.h b/drivers/staging/rtl8192e/rtllib.h
index 2dd57e88276e..328f410daa03 100644
--- a/drivers/staging/rtl8192e/rtllib.h
+++ b/drivers/staging/rtl8192e/rtllib.h
@@ -479,7 +479,6 @@ enum wireless_mode {
479#define P80211_OUI_LEN 3 479#define P80211_OUI_LEN 3
480 480
481struct rtllib_snap_hdr { 481struct rtllib_snap_hdr {
482
483 u8 dsap; /* always 0xAA */ 482 u8 dsap; /* always 0xAA */
484 u8 ssap; /* always 0xAA */ 483 u8 ssap; /* always 0xAA */
485 u8 ctrl; /* always 0x03 */ 484 u8 ctrl; /* always 0x03 */
@@ -1940,7 +1939,7 @@ int rtllib_encrypt_fragment(
1940 int hdr_len); 1939 int hdr_len);
1941 1940
1942int rtllib_xmit(struct sk_buff *skb, struct net_device *dev); 1941int rtllib_xmit(struct sk_buff *skb, struct net_device *dev);
1943void rtllib_txb_free(struct rtllib_txb *); 1942void rtllib_txb_free(struct rtllib_txb *txb);
1944 1943
1945/* rtllib_rx.c */ 1944/* rtllib_rx.c */
1946int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb, 1945int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
@@ -2132,7 +2131,7 @@ static inline const char *escape_essid(const char *essid, u8 essid_len)
2132 return escaped; 2131 return escaped;
2133 } 2132 }
2134 2133
2135 snprintf(escaped, sizeof(escaped), "%*pEn", essid_len, essid); 2134 snprintf(escaped, sizeof(escaped), "%*pE", essid_len, essid);
2136 return escaped; 2135 return escaped;
2137} 2136}
2138 2137
diff --git a/drivers/staging/rtl8192e/rtllib_crypt_ccmp.c b/drivers/staging/rtl8192e/rtllib_crypt_ccmp.c
index 2581ed6d14fa..0cbf4a1a326b 100644
--- a/drivers/staging/rtl8192e/rtllib_crypt_ccmp.c
+++ b/drivers/staging/rtl8192e/rtllib_crypt_ccmp.c
@@ -17,6 +17,7 @@
17#include "rtllib.h" 17#include "rtllib.h"
18 18
19#include <linux/crypto.h> 19#include <linux/crypto.h>
20#include <crypto/aead.h>
20 21
21#include <linux/scatterlist.h> 22#include <linux/scatterlist.h>
22 23
@@ -39,20 +40,13 @@ struct rtllib_ccmp_data {
39 40
40 int key_idx; 41 int key_idx;
41 42
42 struct crypto_tfm *tfm; 43 struct crypto_aead *tfm;
43 44
44 /* scratch buffers for virt_to_page() (crypto API) */ 45 /* scratch buffers for virt_to_page() (crypto API) */
45 u8 tx_b0[AES_BLOCK_LEN], tx_b[AES_BLOCK_LEN], 46 u8 tx_aad[2 * AES_BLOCK_LEN];
46 tx_e[AES_BLOCK_LEN], tx_s0[AES_BLOCK_LEN]; 47 u8 rx_aad[2 * AES_BLOCK_LEN];
47 u8 rx_b0[AES_BLOCK_LEN], rx_b[AES_BLOCK_LEN], rx_a[AES_BLOCK_LEN];
48}; 48};
49 49
50static void rtllib_ccmp_aes_encrypt(struct crypto_tfm *tfm,
51 const u8 pt[16], u8 ct[16])
52{
53 crypto_cipher_encrypt_one((void *)tfm, ct, pt);
54}
55
56static void *rtllib_ccmp_init(int key_idx) 50static void *rtllib_ccmp_init(int key_idx)
57{ 51{
58 struct rtllib_ccmp_data *priv; 52 struct rtllib_ccmp_data *priv;
@@ -62,7 +56,7 @@ static void *rtllib_ccmp_init(int key_idx)
62 goto fail; 56 goto fail;
63 priv->key_idx = key_idx; 57 priv->key_idx = key_idx;
64 58
65 priv->tfm = (void *)crypto_alloc_cipher("aes", 0, 0); 59 priv->tfm = crypto_alloc_aead("ccm(aes)", 0, CRYPTO_ALG_ASYNC);
66 if (IS_ERR(priv->tfm)) { 60 if (IS_ERR(priv->tfm)) {
67 pr_debug("Could not allocate crypto API aes\n"); 61 pr_debug("Could not allocate crypto API aes\n");
68 priv->tfm = NULL; 62 priv->tfm = NULL;
@@ -73,7 +67,7 @@ static void *rtllib_ccmp_init(int key_idx)
73fail: 67fail:
74 if (priv) { 68 if (priv) {
75 if (priv->tfm) 69 if (priv->tfm)
76 crypto_free_cipher((void *)priv->tfm); 70 crypto_free_aead(priv->tfm);
77 kfree(priv); 71 kfree(priv);
78 } 72 }
79 73
@@ -86,31 +80,18 @@ static void rtllib_ccmp_deinit(void *priv)
86 struct rtllib_ccmp_data *_priv = priv; 80 struct rtllib_ccmp_data *_priv = priv;
87 81
88 if (_priv && _priv->tfm) 82 if (_priv && _priv->tfm)
89 crypto_free_cipher((void *)_priv->tfm); 83 crypto_free_aead(_priv->tfm);
90 kfree(priv); 84 kfree(priv);
91} 85}
92 86
93 87
94static inline void xor_block(u8 *b, u8 *a, size_t len) 88static int ccmp_init_iv_and_aad(struct rtllib_hdr_4addr *hdr,
95{ 89 u8 *pn, u8 *iv, u8 *aad)
96 int i;
97
98 for (i = 0; i < len; i++)
99 b[i] ^= a[i];
100}
101
102
103
104static void ccmp_init_blocks(struct crypto_tfm *tfm,
105 struct rtllib_hdr_4addr *hdr,
106 u8 *pn, size_t dlen, u8 *b0, u8 *auth,
107 u8 *s0)
108{ 90{
109 u8 *pos, qc = 0; 91 u8 *pos, qc = 0;
110 size_t aad_len; 92 size_t aad_len;
111 u16 fc; 93 u16 fc;
112 int a4_included, qc_included; 94 int a4_included, qc_included;
113 u8 aad[2 * AES_BLOCK_LEN];
114 95
115 fc = le16_to_cpu(hdr->frame_ctl); 96 fc = le16_to_cpu(hdr->frame_ctl);
116 a4_included = ((fc & (RTLLIB_FCTL_TODS | RTLLIB_FCTL_FROMDS)) == 97 a4_included = ((fc & (RTLLIB_FCTL_TODS | RTLLIB_FCTL_FROMDS)) ==
@@ -128,18 +109,19 @@ static void ccmp_init_blocks(struct crypto_tfm *tfm,
128 qc = *pos & 0x0f; 109 qc = *pos & 0x0f;
129 aad_len += 2; 110 aad_len += 2;
130 } 111 }
131 /* CCM Initial Block: 112 /* In CCM, the initial vectors (IV) used for CTR mode encryption and CBC
132 * Flag (Include authentication header, M=3 (8-octet MIC), 113 * mode authentication are not allowed to collide, yet both are derived
133 * L=1 (2-octet Dlen)) 114 * from the same vector. We only set L := 1 here to indicate that the
134 * Nonce: 0x00 | A2 | PN 115 * data size can be represented in (L+1) bytes. The CCM layer will take
135 * Dlen 116 * care of storing the data length in the top (L+1) bytes and setting
117 * and clearing the other bits as is required to derive the two IVs.
136 */ 118 */
137 b0[0] = 0x59; 119 iv[0] = 0x1;
138 b0[1] = qc; 120
139 memcpy(b0 + 2, hdr->addr2, ETH_ALEN); 121 /* Nonce: QC | A2 | PN */
140 memcpy(b0 + 8, pn, CCMP_PN_LEN); 122 iv[1] = qc;
141 b0[14] = (dlen >> 8) & 0xff; 123 memcpy(iv + 2, hdr->addr2, ETH_ALEN);
142 b0[15] = dlen & 0xff; 124 memcpy(iv + 8, pn, CCMP_PN_LEN);
143 125
144 /* AAD: 126 /* AAD:
145 * FC with bits 4..6 and 11..13 masked to zero; 14 is always one 127 * FC with bits 4..6 and 11..13 masked to zero; 14 is always one
@@ -149,31 +131,21 @@ static void ccmp_init_blocks(struct crypto_tfm *tfm,
149 * QC (if present) 131 * QC (if present)
150 */ 132 */
151 pos = (u8 *) hdr; 133 pos = (u8 *) hdr;
152 aad[0] = 0; /* aad_len >> 8 */ 134 aad[0] = pos[0] & 0x8f;
153 aad[1] = aad_len & 0xff; 135 aad[1] = pos[1] & 0xc7;
154 aad[2] = pos[0] & 0x8f; 136 memcpy(aad + 2, hdr->addr1, 3 * ETH_ALEN);
155 aad[3] = pos[1] & 0xc7;
156 memcpy(aad + 4, hdr->addr1, 3 * ETH_ALEN);
157 pos = (u8 *) &hdr->seq_ctl; 137 pos = (u8 *) &hdr->seq_ctl;
158 aad[22] = pos[0] & 0x0f; 138 aad[20] = pos[0] & 0x0f;
159 aad[23] = 0; /* all bits masked */ 139 aad[21] = 0; /* all bits masked */
160 memset(aad + 24, 0, 8); 140 memset(aad + 22, 0, 8);
161 if (a4_included) 141 if (a4_included)
162 memcpy(aad + 24, hdr->addr4, ETH_ALEN); 142 memcpy(aad + 22, hdr->addr4, ETH_ALEN);
163 if (qc_included) { 143 if (qc_included) {
164 aad[a4_included ? 30 : 24] = qc; 144 aad[a4_included ? 28 : 22] = qc;
165 /* rest of QC masked */ 145 /* rest of QC masked */
166 } 146 }
167 147
168 /* Start with the first block and AAD */ 148 return aad_len;
169 rtllib_ccmp_aes_encrypt(tfm, b0, auth);
170 xor_block(auth, aad, AES_BLOCK_LEN);
171 rtllib_ccmp_aes_encrypt(tfm, auth, auth);
172 xor_block(auth, &aad[AES_BLOCK_LEN], AES_BLOCK_LEN);
173 rtllib_ccmp_aes_encrypt(tfm, auth, auth);
174 b0[0] &= 0x07;
175 b0[14] = b0[15] = 0;
176 rtllib_ccmp_aes_encrypt(tfm, b0, s0);
177} 149}
178 150
179 151
@@ -181,7 +153,7 @@ static void ccmp_init_blocks(struct crypto_tfm *tfm,
181static int rtllib_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv) 153static int rtllib_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
182{ 154{
183 struct rtllib_ccmp_data *key = priv; 155 struct rtllib_ccmp_data *key = priv;
184 int data_len, i; 156 int i;
185 u8 *pos; 157 u8 *pos;
186 struct rtllib_hdr_4addr *hdr; 158 struct rtllib_hdr_4addr *hdr;
187 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 159 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
@@ -191,7 +163,6 @@ static int rtllib_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
191 skb->len < hdr_len) 163 skb->len < hdr_len)
192 return -1; 164 return -1;
193 165
194 data_len = skb->len - hdr_len;
195 pos = skb_push(skb, CCMP_HDR_LEN); 166 pos = skb_push(skb, CCMP_HDR_LEN);
196 memmove(pos, pos + CCMP_HDR_LEN, hdr_len); 167 memmove(pos, pos + CCMP_HDR_LEN, hdr_len);
197 pos += hdr_len; 168 pos += hdr_len;
@@ -213,40 +184,37 @@ static int rtllib_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
213 *pos++ = key->tx_pn[1]; 184 *pos++ = key->tx_pn[1];
214 *pos++ = key->tx_pn[0]; 185 *pos++ = key->tx_pn[0];
215 186
216
217 hdr = (struct rtllib_hdr_4addr *) skb->data; 187 hdr = (struct rtllib_hdr_4addr *) skb->data;
218 if (!tcb_desc->bHwSec) { 188 if (!tcb_desc->bHwSec) {
219 int blocks, last, len; 189 struct aead_request *req;
220 u8 *mic; 190 struct scatterlist sg[2];
221 u8 *b0 = key->tx_b0; 191 u8 *aad = key->tx_aad;
222 u8 *b = key->tx_b; 192 u8 iv[AES_BLOCK_LEN];
223 u8 *e = key->tx_e; 193 int aad_len, ret;
224 u8 *s0 = key->tx_s0; 194 int data_len = skb->len - hdr_len - CCMP_HDR_LEN;
225 195
226 mic = skb_put(skb, CCMP_MIC_LEN); 196 req = aead_request_alloc(key->tfm, GFP_ATOMIC);
227 197 if (!req)
228 ccmp_init_blocks(key->tfm, hdr, key->tx_pn, data_len, 198 return -ENOMEM;
229 b0, b, s0); 199
230 200 aad_len = ccmp_init_iv_and_aad(hdr, key->tx_pn, iv, aad);
231 blocks = DIV_ROUND_UP(data_len, AES_BLOCK_LEN); 201
232 last = data_len % AES_BLOCK_LEN; 202 skb_put(skb, CCMP_MIC_LEN);
233 203 sg_init_table(sg, 2);
234 for (i = 1; i <= blocks; i++) { 204 sg_set_buf(&sg[0], aad, aad_len);
235 len = (i == blocks && last) ? last : AES_BLOCK_LEN; 205 sg_set_buf(&sg[1], skb->data + hdr_len + CCMP_HDR_LEN,
236 /* Authentication */ 206 data_len + CCMP_MIC_LEN);
237 xor_block(b, pos, len);
238 rtllib_ccmp_aes_encrypt(key->tfm, b, b);
239 /* Encryption, with counter */
240 b0[14] = (i >> 8) & 0xff;
241 b0[15] = i & 0xff;
242 rtllib_ccmp_aes_encrypt(key->tfm, b0, e);
243 xor_block(pos, e, len);
244 pos += len;
245 }
246 207
247 for (i = 0; i < CCMP_MIC_LEN; i++) 208 aead_request_set_callback(req, 0, NULL, NULL);
248 mic[i] = b[i] ^ s0[i]; 209 aead_request_set_ad(req, aad_len);
210 aead_request_set_crypt(req, sg, sg, data_len, iv);
211
212 ret = crypto_aead_encrypt(req);
213 aead_request_free(req);
214
215 return ret;
249 } 216 }
217
250 return 0; 218 return 0;
251} 219}
252 220
@@ -302,35 +270,31 @@ static int rtllib_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
302 return -4; 270 return -4;
303 } 271 }
304 if (!tcb_desc->bHwSec) { 272 if (!tcb_desc->bHwSec) {
305 size_t data_len = skb->len - hdr_len - CCMP_HDR_LEN - 273 size_t data_len = skb->len - hdr_len - CCMP_HDR_LEN;
306 CCMP_MIC_LEN; 274 struct aead_request *req;
307 u8 *mic = skb->data + skb->len - CCMP_MIC_LEN; 275 struct scatterlist sg[2];
308 u8 *b0 = key->rx_b0; 276 u8 *aad = key->rx_aad;
309 u8 *b = key->rx_b; 277 u8 iv[AES_BLOCK_LEN];
310 u8 *a = key->rx_a; 278 int aad_len, ret;
311 int i, blocks, last, len; 279
312 280 req = aead_request_alloc(key->tfm, GFP_ATOMIC);
313 281 if(!req)
314 ccmp_init_blocks(key->tfm, hdr, pn, data_len, b0, a, b); 282 return -ENOMEM;
315 xor_block(mic, b, CCMP_MIC_LEN); 283
316 284 aad_len = ccmp_init_iv_and_aad(hdr, pn, iv, aad);
317 blocks = DIV_ROUND_UP(data_len, AES_BLOCK_LEN); 285
318 last = data_len % AES_BLOCK_LEN; 286 sg_init_table(sg, 2);
319 287 sg_set_buf(&sg[0], aad, aad_len);
320 for (i = 1; i <= blocks; i++) { 288 sg_set_buf(&sg[1], pos, data_len);
321 len = (i == blocks && last) ? last : AES_BLOCK_LEN; 289
322 /* Decrypt, with counter */ 290 aead_request_set_callback(req, 0, NULL, NULL);
323 b0[14] = (i >> 8) & 0xff; 291 aead_request_set_ad(req, aad_len);
324 b0[15] = i & 0xff; 292 aead_request_set_crypt(req, sg, sg, data_len, iv);
325 rtllib_ccmp_aes_encrypt(key->tfm, b0, b); 293
326 xor_block(pos, b, len); 294 ret = crypto_aead_decrypt(req);
327 /* Authentication */ 295 aead_request_free(req);
328 xor_block(a, pos, len);
329 rtllib_ccmp_aes_encrypt(key->tfm, a, a);
330 pos += len;
331 }
332 296
333 if (memcmp(mic, a, CCMP_MIC_LEN) != 0) { 297 if (ret) {
334 if (net_ratelimit()) { 298 if (net_ratelimit()) {
335 pr_debug("CCMP: decrypt failed: STA= %pM\n", 299 pr_debug("CCMP: decrypt failed: STA= %pM\n",
336 hdr->addr2); 300 hdr->addr2);
@@ -354,7 +318,7 @@ static int rtllib_ccmp_set_key(void *key, int len, u8 *seq, void *priv)
354{ 318{
355 struct rtllib_ccmp_data *data = priv; 319 struct rtllib_ccmp_data *data = priv;
356 int keyidx; 320 int keyidx;
357 struct crypto_tfm *tfm = data->tfm; 321 struct crypto_aead *tfm = data->tfm;
358 322
359 keyidx = data->key_idx; 323 keyidx = data->key_idx;
360 memset(data, 0, sizeof(*data)); 324 memset(data, 0, sizeof(*data));
@@ -371,7 +335,9 @@ static int rtllib_ccmp_set_key(void *key, int len, u8 *seq, void *priv)
371 data->rx_pn[4] = seq[1]; 335 data->rx_pn[4] = seq[1];
372 data->rx_pn[5] = seq[0]; 336 data->rx_pn[5] = seq[0];
373 } 337 }
374 crypto_cipher_setkey((void *)data->tfm, data->key, CCMP_TK_LEN); 338 if (crypto_aead_setauthsize(data->tfm, CCMP_MIC_LEN) ||
339 crypto_aead_setkey(data->tfm, data->key, CCMP_TK_LEN))
340 return -1;
375 } else if (len == 0) { 341 } else if (len == 0) {
376 data->key_set = 0; 342 data->key_set = 0;
377 } else { 343 } else {
diff --git a/drivers/staging/rtl8192e/rtllib_rx.c b/drivers/staging/rtl8192e/rtllib_rx.c
index 0c19ac2bc3bf..0bae0a0a4cbe 100644
--- a/drivers/staging/rtl8192e/rtllib_rx.c
+++ b/drivers/staging/rtl8192e/rtllib_rx.c
@@ -1300,7 +1300,6 @@ static int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
1300 struct rx_ts_record *pTS = NULL; 1300 struct rx_ts_record *pTS = NULL;
1301 u16 fc, sc, SeqNum = 0; 1301 u16 fc, sc, SeqNum = 0;
1302 u8 type, stype, multicast = 0, unicast = 0, nr_subframes = 0, TID = 0; 1302 u8 type, stype, multicast = 0, unicast = 0, nr_subframes = 0, TID = 0;
1303 u8 *payload;
1304 u8 dst[ETH_ALEN]; 1303 u8 dst[ETH_ALEN];
1305 u8 src[ETH_ALEN]; 1304 u8 src[ETH_ALEN];
1306 u8 bssid[ETH_ALEN] = {0}; 1305 u8 bssid[ETH_ALEN] = {0};
@@ -1412,7 +1411,6 @@ static int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
1412 1411
1413 /* Parse rx data frame (For AMSDU) */ 1412 /* Parse rx data frame (For AMSDU) */
1414 /* skb: hdr + (possible reassembled) full plaintext payload */ 1413 /* skb: hdr + (possible reassembled) full plaintext payload */
1415 payload = skb->data + hdrlen;
1416 rxb = kmalloc(sizeof(struct rtllib_rxb), GFP_ATOMIC); 1414 rxb = kmalloc(sizeof(struct rtllib_rxb), GFP_ATOMIC);
1417 if (!rxb) 1415 if (!rxb)
1418 goto rx_dropped; 1416 goto rx_dropped;
diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
index e29e8d6f4611..f2f7529e7c80 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -1382,15 +1382,10 @@ rtllib_association_req(struct rtllib_network *beacon,
1382 ieee->assocreq_ies = NULL; 1382 ieee->assocreq_ies = NULL;
1383 ies = &(hdr->info_element[0].id); 1383 ies = &(hdr->info_element[0].id);
1384 ieee->assocreq_ies_len = (skb->data + skb->len) - ies; 1384 ieee->assocreq_ies_len = (skb->data + skb->len) - ies;
1385 ieee->assocreq_ies = kmalloc(ieee->assocreq_ies_len, GFP_ATOMIC); 1385 ieee->assocreq_ies = kmemdup(ies, ieee->assocreq_ies_len, GFP_ATOMIC);
1386 if (ieee->assocreq_ies) 1386 if (!ieee->assocreq_ies)
1387 memcpy(ieee->assocreq_ies, ies, ieee->assocreq_ies_len);
1388 else {
1389 netdev_info(ieee->dev,
1390 "%s()Warning: can't alloc memory for assocreq_ies\n",
1391 __func__);
1392 ieee->assocreq_ies_len = 0; 1387 ieee->assocreq_ies_len = 0;
1393 } 1388
1394 return skb; 1389 return skb;
1395} 1390}
1396 1391
@@ -2259,17 +2254,12 @@ rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb,
2259 ieee->assocresp_ies = NULL; 2254 ieee->assocresp_ies = NULL;
2260 ies = &(assoc_resp->info_element[0].id); 2255 ies = &(assoc_resp->info_element[0].id);
2261 ieee->assocresp_ies_len = (skb->data + skb->len) - ies; 2256 ieee->assocresp_ies_len = (skb->data + skb->len) - ies;
2262 ieee->assocresp_ies = kmalloc(ieee->assocresp_ies_len, 2257 ieee->assocresp_ies = kmemdup(ies,
2258 ieee->assocresp_ies_len,
2263 GFP_ATOMIC); 2259 GFP_ATOMIC);
2264 if (ieee->assocresp_ies) 2260 if (!ieee->assocresp_ies)
2265 memcpy(ieee->assocresp_ies, ies,
2266 ieee->assocresp_ies_len);
2267 else {
2268 netdev_info(ieee->dev,
2269 "%s()Warning: can't alloc memory for assocresp_ies\n",
2270 __func__);
2271 ieee->assocresp_ies_len = 0; 2261 ieee->assocresp_ies_len = 0;
2272 } 2262
2273 rtllib_associate_complete(ieee); 2263 rtllib_associate_complete(ieee);
2274 } else { 2264 } else {
2275 /* aid could not been allocated */ 2265 /* aid could not been allocated */
diff --git a/drivers/staging/rtl8192u/Kconfig b/drivers/staging/rtl8192u/Kconfig
index 22c2165e8b1c..1edca5c304fb 100644
--- a/drivers/staging/rtl8192u/Kconfig
+++ b/drivers/staging/rtl8192u/Kconfig
@@ -6,3 +6,5 @@ config RTL8192U
6 select WIRELESS_EXT 6 select WIRELESS_EXT
7 select WEXT_PRIV 7 select WEXT_PRIV
8 select CRYPTO 8 select CRYPTO
9 select CRYPTO_AES
10 select CRYPTO_CCM
diff --git a/drivers/staging/rtl8192u/ieee80211/dot11d.c b/drivers/staging/rtl8192u/ieee80211/dot11d.c
index 130ddfe9868f..bc642076b96f 100644
--- a/drivers/staging/rtl8192u/ieee80211/dot11d.c
+++ b/drivers/staging/rtl8192u/ieee80211/dot11d.c
@@ -12,7 +12,7 @@ void rtl8192u_dot11d_init(struct ieee80211_device *ieee)
12 dot11d_info->state = DOT11D_STATE_NONE; 12 dot11d_info->state = DOT11D_STATE_NONE;
13 dot11d_info->country_ie_len = 0; 13 dot11d_info->country_ie_len = 0;
14 memset(dot11d_info->channel_map, 0, MAX_CHANNEL_NUMBER + 1); 14 memset(dot11d_info->channel_map, 0, MAX_CHANNEL_NUMBER + 1);
15 memset(dot11d_info->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1); 15 memset(dot11d_info->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER + 1);
16 RESET_CIE_WATCHDOG(ieee); 16 RESET_CIE_WATCHDOG(ieee);
17 17
18 netdev_info(ieee->dev, "rtl8192u_dot11d_init()\n"); 18 netdev_info(ieee->dev, "rtl8192u_dot11d_init()\n");
@@ -25,8 +25,8 @@ void dot11d_reset(struct ieee80211_device *ieee)
25 u32 i; 25 u32 i;
26 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(ieee); 26 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(ieee);
27 /* Clear old channel map */ 27 /* Clear old channel map */
28 memset(dot11d_info->channel_map, 0, MAX_CHANNEL_NUMBER+1); 28 memset(dot11d_info->channel_map, 0, MAX_CHANNEL_NUMBER + 1);
29 memset(dot11d_info->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1); 29 memset(dot11d_info->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER + 1);
30 /* Set new channel map */ 30 /* Set new channel map */
31 for (i = 1; i <= 11; i++) 31 for (i = 1; i <= 11; i++)
32 (dot11d_info->channel_map)[i] = 1; 32 (dot11d_info->channel_map)[i] = 1;
@@ -56,8 +56,8 @@ void dot11d_update_country_ie(struct ieee80211_device *dev, u8 *pTaddr,
56 u8 i, j, NumTriples, MaxChnlNum; 56 u8 i, j, NumTriples, MaxChnlNum;
57 struct chnl_txpower_triple *pTriple; 57 struct chnl_txpower_triple *pTriple;
58 58
59 memset(dot11d_info->channel_map, 0, MAX_CHANNEL_NUMBER+1); 59 memset(dot11d_info->channel_map, 0, MAX_CHANNEL_NUMBER + 1);
60 memset(dot11d_info->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1); 60 memset(dot11d_info->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER + 1);
61 MaxChnlNum = 0; 61 MaxChnlNum = 0;
62 NumTriples = (CoutryIeLen - 3) / 3; /* skip 3-byte country string. */ 62 NumTriples = (CoutryIeLen - 3) / 3; /* skip 3-byte country string. */
63 pTriple = (struct chnl_txpower_triple *)(pCoutryIe + 3); 63 pTriple = (struct chnl_txpower_triple *)(pCoutryIe + 3);
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
index d36963469015..9576b647f6b1 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
@@ -169,9 +169,9 @@ struct cb_desc {
169#define MGN_MCS14 0x8e 169#define MGN_MCS14 0x8e
170#define MGN_MCS15 0x8f 170#define MGN_MCS15 0x8f
171 171
172#define aSifsTime ((priv->ieee80211->current_network.mode == IEEE_A || \ 172#define aSifsTime ((priv->ieee80211->current_network.mode == IEEE_A || \
173 priv->ieee80211->current_network.mode == IEEE_N_24G || \ 173 priv->ieee80211->current_network.mode == IEEE_N_24G || \
174 priv->ieee80211->current_network.mode == IEEE_N_5G) ? \ 174 priv->ieee80211->current_network.mode == IEEE_N_5G) ? \
175 16 : 10) 175 16 : 10)
176 176
177#define MGMT_QUEUE_NUM 5 177#define MGMT_QUEUE_NUM 5
@@ -387,7 +387,7 @@ struct ieee_param {
387#define IEEE80211_STYPE_ACK 0x00D0 387#define IEEE80211_STYPE_ACK 0x00D0
388#define IEEE80211_STYPE_CFEND 0x00E0 388#define IEEE80211_STYPE_CFEND 0x00E0
389#define IEEE80211_STYPE_CFENDACK 0x00F0 389#define IEEE80211_STYPE_CFENDACK 0x00F0
390#define IEEE80211_STYPE_BLOCKACK 0x0094 390#define IEEE80211_STYPE_BLOCKACK 0x0094
391 391
392/* data */ 392/* data */
393#define IEEE80211_STYPE_DATA 0x0000 393#define IEEE80211_STYPE_DATA 0x0000
@@ -452,23 +452,23 @@ do { if (ieee80211_debug_level & (level)) \
452 printk(KERN_DEBUG "ieee80211: " fmt, ## args); } while (0) 452 printk(KERN_DEBUG "ieee80211: " fmt, ## args); } while (0)
453//wb added to debug out data buf 453//wb added to debug out data buf
454//if you want print DATA buffer related BA, please set ieee80211_debug_level to DATA|BA 454//if you want print DATA buffer related BA, please set ieee80211_debug_level to DATA|BA
455#define IEEE80211_DEBUG_DATA(level, data, datalen) \ 455#define IEEE80211_DEBUG_DATA(level, data, datalen) \
456 do { if ((ieee80211_debug_level & (level)) == (level)) \ 456 do { if ((ieee80211_debug_level & (level)) == (level)) \
457 { \ 457 { \
458 int i; \ 458 int i; \
459 u8 *pdata = (u8 *) data; \ 459 u8 *pdata = (u8 *)data; \
460 printk(KERN_DEBUG "ieee80211: %s()\n", __func__); \ 460 printk(KERN_DEBUG "ieee80211: %s()\n", __func__); \
461 for (i = 0; i < (int)(datalen); i++) \ 461 for (i = 0; i < (int)(datalen); i++) { \
462 { \ 462 printk("%2x ", pdata[i]); \
463 printk("%2x ", pdata[i]); \ 463 if ((i + 1) % 16 == 0) \
464 if ((i + 1) % 16 == 0) printk("\n"); \ 464 printk("\n"); \
465 } \ 465 } \
466 printk("\n"); \ 466 printk("\n"); \
467 } \ 467 } \
468 } while (0) 468 } while (0)
469#else 469#else
470#define IEEE80211_DEBUG (level, fmt, args...) do {} while (0) 470#define IEEE80211_DEBUG (level, fmt, args...) do {} while (0)
471#define IEEE80211_DEBUG_DATA (level, data, datalen) do {} while(0) 471#define IEEE80211_DEBUG_DATA (level, data, datalen) do {} while (0)
472#endif /* CONFIG_IEEE80211_DEBUG */ 472#endif /* CONFIG_IEEE80211_DEBUG */
473 473
474/* debug macros not dependent on CONFIG_IEEE80211_DEBUG */ 474/* debug macros not dependent on CONFIG_IEEE80211_DEBUG */
@@ -1649,10 +1649,8 @@ struct ieee80211_device {
1649 struct list_head Rx_TS_Pending_List; 1649 struct list_head Rx_TS_Pending_List;
1650 struct list_head Rx_TS_Unused_List; 1650 struct list_head Rx_TS_Unused_List;
1651 struct rx_ts_record RxTsRecord[TOTAL_TS_NUM]; 1651 struct rx_ts_record RxTsRecord[TOTAL_TS_NUM];
1652//#ifdef TO_DO_LIST
1653 struct rx_reorder_entry RxReorderEntry[128]; 1652 struct rx_reorder_entry RxReorderEntry[128];
1654 struct list_head RxReorder_Unused_List; 1653 struct list_head RxReorder_Unused_List;
1655//#endif
1656 // Qos related. Added by Annie, 2005-11-01. 1654 // Qos related. Added by Annie, 2005-11-01.
1657// PSTA_QOS pStaQos; 1655// PSTA_QOS pStaQos;
1658 u8 ForcedPriority; // Force per-packet priority 1~7. (default: 0, not to force it.) 1656 u8 ForcedPriority; // Force per-packet priority 1~7. (default: 0, not to force it.)
@@ -2015,8 +2013,8 @@ struct ieee80211_device {
2015#define IEEE_A (1<<0) 2013#define IEEE_A (1<<0)
2016#define IEEE_B (1<<1) 2014#define IEEE_B (1<<1)
2017#define IEEE_G (1<<2) 2015#define IEEE_G (1<<2)
2018#define IEEE_N_24G (1<<4) 2016#define IEEE_N_24G (1<<4)
2019#define IEEE_N_5G (1<<5) 2017#define IEEE_N_5G (1<<5)
2020#define IEEE_MODE_MASK (IEEE_A | IEEE_B | IEEE_G) 2018#define IEEE_MODE_MASK (IEEE_A | IEEE_B | IEEE_G)
2021 2019
2022/* Generate a 802.11 header */ 2020/* Generate a 802.11 header */
@@ -2426,7 +2424,7 @@ static inline const char *escape_essid(const char *essid, u8 essid_len)
2426 return escaped; 2424 return escaped;
2427 } 2425 }
2428 2426
2429 snprintf(escaped, sizeof(escaped), "%*pEn", essid_len, essid); 2427 snprintf(escaped, sizeof(escaped), "%*pE", essid_len, essid);
2430 return escaped; 2428 return escaped;
2431} 2429}
2432 2430
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.c
index 36987fccac5d..01012dddcd73 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.c
@@ -176,7 +176,7 @@ struct ieee80211_crypto_ops *ieee80211_get_crypto_ops(const char *name)
176} 176}
177 177
178 178
179static void *ieee80211_crypt_null_init(int keyidx) { return (void *) 1; } 179static void *ieee80211_crypt_null_init(int keyidx) { return (void *)1; }
180static void ieee80211_crypt_null_deinit(void *priv) {} 180static void ieee80211_crypt_null_deinit(void *priv) {}
181 181
182static struct ieee80211_crypto_ops ieee80211_crypt_null = { 182static struct ieee80211_crypto_ops ieee80211_crypt_null = {
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c
index d7188b3f3190..c241cf484023 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c
@@ -19,6 +19,7 @@
19#include "ieee80211.h" 19#include "ieee80211.h"
20 20
21#include <linux/crypto.h> 21#include <linux/crypto.h>
22#include <crypto/aead.h>
22 #include <linux/scatterlist.h> 23 #include <linux/scatterlist.h>
23 24
24MODULE_AUTHOR("Jouni Malinen"); 25MODULE_AUTHOR("Jouni Malinen");
@@ -44,20 +45,13 @@ struct ieee80211_ccmp_data {
44 45
45 int key_idx; 46 int key_idx;
46 47
47 struct crypto_tfm *tfm; 48 struct crypto_aead *tfm;
48 49
49 /* scratch buffers for virt_to_page() (crypto API) */ 50 /* scratch buffers for virt_to_page() (crypto API) */
50 u8 tx_b0[AES_BLOCK_LEN], tx_b[AES_BLOCK_LEN], 51 u8 tx_aad[2 * AES_BLOCK_LEN];
51 tx_e[AES_BLOCK_LEN], tx_s0[AES_BLOCK_LEN]; 52 u8 rx_aad[2 * AES_BLOCK_LEN];
52 u8 rx_b0[AES_BLOCK_LEN], rx_b[AES_BLOCK_LEN], rx_a[AES_BLOCK_LEN];
53}; 53};
54 54
55static void ieee80211_ccmp_aes_encrypt(struct crypto_tfm *tfm,
56 const u8 pt[16], u8 ct[16])
57{
58 crypto_cipher_encrypt_one((void *)tfm, ct, pt);
59}
60
61static void *ieee80211_ccmp_init(int key_idx) 55static void *ieee80211_ccmp_init(int key_idx)
62{ 56{
63 struct ieee80211_ccmp_data *priv; 57 struct ieee80211_ccmp_data *priv;
@@ -67,7 +61,7 @@ static void *ieee80211_ccmp_init(int key_idx)
67 goto fail; 61 goto fail;
68 priv->key_idx = key_idx; 62 priv->key_idx = key_idx;
69 63
70 priv->tfm = (void *)crypto_alloc_cipher("aes", 0, 0); 64 priv->tfm = crypto_alloc_aead("ccm(aes)", 0, CRYPTO_ALG_ASYNC);
71 if (IS_ERR(priv->tfm)) { 65 if (IS_ERR(priv->tfm)) {
72 pr_debug("ieee80211_crypt_ccmp: could not allocate crypto API aes\n"); 66 pr_debug("ieee80211_crypt_ccmp: could not allocate crypto API aes\n");
73 priv->tfm = NULL; 67 priv->tfm = NULL;
@@ -79,7 +73,7 @@ static void *ieee80211_ccmp_init(int key_idx)
79fail: 73fail:
80 if (priv) { 74 if (priv) {
81 if (priv->tfm) 75 if (priv->tfm)
82 crypto_free_cipher((void *)priv->tfm); 76 crypto_free_aead(priv->tfm);
83 kfree(priv); 77 kfree(priv);
84 } 78 }
85 79
@@ -91,28 +85,17 @@ static void ieee80211_ccmp_deinit(void *priv)
91 struct ieee80211_ccmp_data *_priv = priv; 85 struct ieee80211_ccmp_data *_priv = priv;
92 86
93 if (_priv && _priv->tfm) 87 if (_priv && _priv->tfm)
94 crypto_free_cipher((void *)_priv->tfm); 88 crypto_free_aead(_priv->tfm);
95 kfree(priv); 89 kfree(priv);
96} 90}
97 91
98static inline void xor_block(u8 *b, u8 *a, size_t len) 92static int ccmp_init_iv_and_aad(struct rtl_80211_hdr_4addr *hdr,
99{ 93 u8 *pn, u8 *iv, u8 *aad)
100 int i;
101
102 for (i = 0; i < len; i++)
103 b[i] ^= a[i];
104}
105
106static void ccmp_init_blocks(struct crypto_tfm *tfm,
107 struct rtl_80211_hdr_4addr *hdr,
108 u8 *pn, size_t dlen, u8 *b0, u8 *auth,
109 u8 *s0)
110{ 94{
111 u8 *pos, qc = 0; 95 u8 *pos, qc = 0;
112 size_t aad_len; 96 size_t aad_len;
113 u16 fc; 97 u16 fc;
114 int a4_included, qc_included; 98 int a4_included, qc_included;
115 u8 aad[2 * AES_BLOCK_LEN];
116 99
117 fc = le16_to_cpu(hdr->frame_ctl); 100 fc = le16_to_cpu(hdr->frame_ctl);
118 a4_included = ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == 101 a4_included = ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
@@ -133,18 +116,20 @@ static void ccmp_init_blocks(struct crypto_tfm *tfm,
133 qc = *pos & 0x0f; 116 qc = *pos & 0x0f;
134 aad_len += 2; 117 aad_len += 2;
135 } 118 }
136 /* CCM Initial Block: 119
137 * Flag (Include authentication header, M=3 (8-octet MIC), 120 /* In CCM, the initial vectors (IV) used for CTR mode encryption and CBC
138 * L=1 (2-octet Dlen)) 121 * mode authentication are not allowed to collide, yet both are derived
139 * Nonce: 0x00 | A2 | PN 122 * from the same vector. We only set L := 1 here to indicate that the
140 * Dlen 123 * data size can be represented in (L+1) bytes. The CCM layer will take
124 * care of storing the data length in the top (L+1) bytes and setting
125 * and clearing the other bits as is required to derive the two IVs.
141 */ 126 */
142 b0[0] = 0x59; 127 iv[0] = 0x1;
143 b0[1] = qc; 128
144 memcpy(b0 + 2, hdr->addr2, ETH_ALEN); 129 /* Nonce: QC | A2 | PN */
145 memcpy(b0 + 8, pn, CCMP_PN_LEN); 130 iv[1] = qc;
146 b0[14] = (dlen >> 8) & 0xff; 131 memcpy(iv + 2, hdr->addr2, ETH_ALEN);
147 b0[15] = dlen & 0xff; 132 memcpy(iv + 8, pn, CCMP_PN_LEN);
148 133
149 /* AAD: 134 /* AAD:
150 * FC with bits 4..6 and 11..13 masked to zero; 14 is always one 135 * FC with bits 4..6 and 11..13 masked to zero; 14 is always one
@@ -154,38 +139,27 @@ static void ccmp_init_blocks(struct crypto_tfm *tfm,
154 * QC (if present) 139 * QC (if present)
155 */ 140 */
156 pos = (u8 *)hdr; 141 pos = (u8 *)hdr;
157 aad[0] = 0; /* aad_len >> 8 */ 142 aad[0] = pos[0] & 0x8f;
158 aad[1] = aad_len & 0xff; 143 aad[1] = pos[1] & 0xc7;
159 aad[2] = pos[0] & 0x8f; 144 memcpy(aad + 2, hdr->addr1, 3 * ETH_ALEN);
160 aad[3] = pos[1] & 0xc7;
161 memcpy(aad + 4, hdr->addr1, 3 * ETH_ALEN);
162 pos = (u8 *)&hdr->seq_ctl; 145 pos = (u8 *)&hdr->seq_ctl;
163 aad[22] = pos[0] & 0x0f; 146 aad[20] = pos[0] & 0x0f;
164 aad[23] = 0; /* all bits masked */ 147 aad[21] = 0; /* all bits masked */
165 memset(aad + 24, 0, 8); 148 memset(aad + 22, 0, 8);
166 if (a4_included) 149 if (a4_included)
167 memcpy(aad + 24, hdr->addr4, ETH_ALEN); 150 memcpy(aad + 22, hdr->addr4, ETH_ALEN);
168 if (qc_included) { 151 if (qc_included) {
169 aad[a4_included ? 30 : 24] = qc; 152 aad[a4_included ? 28 : 22] = qc;
170 /* rest of QC masked */ 153 /* rest of QC masked */
171 } 154 }
172 155
173 /* Start with the first block and AAD */ 156 return aad_len;
174 ieee80211_ccmp_aes_encrypt(tfm, b0, auth);
175 xor_block(auth, aad, AES_BLOCK_LEN);
176 ieee80211_ccmp_aes_encrypt(tfm, auth, auth);
177 xor_block(auth, &aad[AES_BLOCK_LEN], AES_BLOCK_LEN);
178 ieee80211_ccmp_aes_encrypt(tfm, auth, auth);
179 b0[0] &= 0x07;
180 b0[14] = 0;
181 b0[15] = 0;
182 ieee80211_ccmp_aes_encrypt(tfm, b0, s0);
183} 157}
184 158
185static int ieee80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv) 159static int ieee80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
186{ 160{
187 struct ieee80211_ccmp_data *key = priv; 161 struct ieee80211_ccmp_data *key = priv;
188 int data_len, i; 162 int i;
189 u8 *pos; 163 u8 *pos;
190 struct rtl_80211_hdr_4addr *hdr; 164 struct rtl_80211_hdr_4addr *hdr;
191 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 165 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
@@ -195,7 +169,6 @@ static int ieee80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
195 skb->len < hdr_len) 169 skb->len < hdr_len)
196 return -1; 170 return -1;
197 171
198 data_len = skb->len - hdr_len;
199 pos = skb_push(skb, CCMP_HDR_LEN); 172 pos = skb_push(skb, CCMP_HDR_LEN);
200 memmove(pos, pos + CCMP_HDR_LEN, hdr_len); 173 memmove(pos, pos + CCMP_HDR_LEN, hdr_len);
201 pos += hdr_len; 174 pos += hdr_len;
@@ -220,36 +193,34 @@ static int ieee80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
220 193
221 hdr = (struct rtl_80211_hdr_4addr *)skb->data; 194 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
222 if (!tcb_desc->bHwSec) { 195 if (!tcb_desc->bHwSec) {
223 int blocks, last, len; 196 struct aead_request *req;
224 u8 *mic; 197 struct scatterlist sg[2];
225 u8 *b0 = key->tx_b0; 198 u8 *aad = key->tx_aad;
226 u8 *b = key->tx_b; 199 u8 iv[AES_BLOCK_LEN];
227 u8 *e = key->tx_e; 200 int aad_len, ret;
228 u8 *s0 = key->tx_s0; 201 size_t data_len = skb->len - hdr_len - CCMP_HDR_LEN;
229
230 /* mic is moved to here by john */
231 mic = skb_put(skb, CCMP_MIC_LEN);
232
233 ccmp_init_blocks(key->tfm, hdr, key->tx_pn, data_len, b0, b, s0);
234
235 blocks = DIV_ROUND_UP(data_len, AES_BLOCK_LEN);
236 last = data_len % AES_BLOCK_LEN;
237
238 for (i = 1; i <= blocks; i++) {
239 len = (i == blocks && last) ? last : AES_BLOCK_LEN;
240 /* Authentication */
241 xor_block(b, pos, len);
242 ieee80211_ccmp_aes_encrypt(key->tfm, b, b);
243 /* Encryption, with counter */
244 b0[14] = (i >> 8) & 0xff;
245 b0[15] = i & 0xff;
246 ieee80211_ccmp_aes_encrypt(key->tfm, b0, e);
247 xor_block(pos, e, len);
248 pos += len;
249 }
250 202
251 for (i = 0; i < CCMP_MIC_LEN; i++) 203 req = aead_request_alloc(key->tfm, GFP_ATOMIC);
252 mic[i] = b[i] ^ s0[i]; 204 if (!req)
205 return -ENOMEM;
206
207 aad_len = ccmp_init_iv_and_aad(hdr, key->tx_pn, iv, aad);
208
209 skb_put(skb, CCMP_MIC_LEN);
210
211 sg_init_table(sg, 2);
212 sg_set_buf(&sg[0], aad, aad_len);
213 sg_set_buf(&sg[1], skb->data + hdr_len + CCMP_HDR_LEN,
214 data_len + CCMP_MIC_LEN);
215
216 aead_request_set_callback(req, 0, NULL, NULL);
217 aead_request_set_ad(req, aad_len);
218 aead_request_set_crypt(req, sg, sg, data_len, iv);
219
220 ret = crypto_aead_encrypt(req);
221 aead_request_free(req);
222
223 return ret;
253 } 224 }
254 return 0; 225 return 0;
255} 226}
@@ -309,33 +280,31 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
309 return -4; 280 return -4;
310 } 281 }
311 if (!tcb_desc->bHwSec) { 282 if (!tcb_desc->bHwSec) {
312 size_t data_len = skb->len - hdr_len - CCMP_HDR_LEN - CCMP_MIC_LEN; 283 struct aead_request *req;
313 u8 *mic = skb->data + skb->len - CCMP_MIC_LEN; 284 struct scatterlist sg[2];
314 u8 *b0 = key->rx_b0; 285 u8 *aad = key->rx_aad;
315 u8 *b = key->rx_b; 286 u8 iv[AES_BLOCK_LEN];
316 u8 *a = key->rx_a; 287 int aad_len, ret;
317 int i, blocks, last, len; 288 size_t data_len = skb->len - hdr_len - CCMP_HDR_LEN;
318 289
319 ccmp_init_blocks(key->tfm, hdr, pn, data_len, b0, a, b); 290 req = aead_request_alloc(key->tfm, GFP_ATOMIC);
320 xor_block(mic, b, CCMP_MIC_LEN); 291 if (!req)
321 292 return -ENOMEM;
322 blocks = DIV_ROUND_UP(data_len, AES_BLOCK_LEN); 293
323 last = data_len % AES_BLOCK_LEN; 294 aad_len = ccmp_init_iv_and_aad(hdr, pn, iv, aad);
324 295
325 for (i = 1; i <= blocks; i++) { 296 sg_init_table(sg, 2);
326 len = (i == blocks && last) ? last : AES_BLOCK_LEN; 297 sg_set_buf(&sg[0], aad, aad_len);
327 /* Decrypt, with counter */ 298 sg_set_buf(&sg[1], pos, data_len);
328 b0[14] = (i >> 8) & 0xff; 299
329 b0[15] = i & 0xff; 300 aead_request_set_callback(req, 0, NULL, NULL);
330 ieee80211_ccmp_aes_encrypt(key->tfm, b0, b); 301 aead_request_set_ad(req, aad_len);
331 xor_block(pos, b, len); 302 aead_request_set_crypt(req, sg, sg, data_len, iv);
332 /* Authentication */ 303
333 xor_block(a, pos, len); 304 ret = crypto_aead_decrypt(req);
334 ieee80211_ccmp_aes_encrypt(key->tfm, a, a); 305 aead_request_free(req);
335 pos += len;
336 }
337 306
338 if (memcmp(mic, a, CCMP_MIC_LEN) != 0) { 307 if (ret) {
339 if (net_ratelimit()) { 308 if (net_ratelimit()) {
340 netdev_dbg(skb->dev, "CCMP: decrypt failed: STA=%pM\n", 309 netdev_dbg(skb->dev, "CCMP: decrypt failed: STA=%pM\n",
341 hdr->addr2); 310 hdr->addr2);
@@ -358,12 +327,11 @@ static int ieee80211_ccmp_set_key(void *key, int len, u8 *seq, void *priv)
358{ 327{
359 struct ieee80211_ccmp_data *data = priv; 328 struct ieee80211_ccmp_data *data = priv;
360 int keyidx; 329 int keyidx;
361 struct crypto_tfm *tfm = data->tfm; 330 struct crypto_aead *tfm = data->tfm;
362 331
363 keyidx = data->key_idx; 332 keyidx = data->key_idx;
364 memset(data, 0, sizeof(*data)); 333 memset(data, 0, sizeof(*data));
365 data->key_idx = keyidx; 334 data->key_idx = keyidx;
366 data->tfm = tfm;
367 if (len == CCMP_TK_LEN) { 335 if (len == CCMP_TK_LEN) {
368 memcpy(data->key, key, CCMP_TK_LEN); 336 memcpy(data->key, key, CCMP_TK_LEN);
369 data->key_set = 1; 337 data->key_set = 1;
@@ -375,7 +343,9 @@ static int ieee80211_ccmp_set_key(void *key, int len, u8 *seq, void *priv)
375 data->rx_pn[4] = seq[1]; 343 data->rx_pn[4] = seq[1];
376 data->rx_pn[5] = seq[0]; 344 data->rx_pn[5] = seq[0];
377 } 345 }
378 crypto_cipher_setkey((void *)data->tfm, data->key, CCMP_TK_LEN); 346 if (crypto_aead_setauthsize(tfm, CCMP_MIC_LEN) ||
347 crypto_aead_setkey(tfm, data->key, CCMP_TK_LEN))
348 return -1;
379 } else if (len == 0) { 349 } else if (len == 0) {
380 data->key_set = 0; 350 data->key_set = 0;
381 } else { 351 } else {
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
index 0927b2b15151..6f4710171151 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
@@ -160,7 +160,7 @@ static inline u16 Hi16(u32 val)
160 160
161static inline u16 Mk16(u8 hi, u8 lo) 161static inline u16 Mk16(u8 hi, u8 lo)
162{ 162{
163 return lo | (((u16) hi) << 8); 163 return lo | (((u16)hi) << 8);
164} 164}
165 165
166static const u16 Sbox[256] = { 166static const u16 Sbox[256] = {
@@ -238,7 +238,7 @@ static void tkip_mixing_phase2(u8 *WEPSeed, const u8 *TK, const u16 *TTAK,
238 * Make temporary area overlap WEP seed so that the final copy can be 238 * Make temporary area overlap WEP seed so that the final copy can be
239 * avoided on little endian hosts. 239 * avoided on little endian hosts.
240 */ 240 */
241 u16 *PPK = (u16 *) &WEPSeed[4]; 241 u16 *PPK = (u16 *)&WEPSeed[4];
242 242
243 /* Step 1 - make copy of TTAK and bring in TSC */ 243 /* Step 1 - make copy of TTAK and bring in TSC */
244 PPK[0] = TTAK[0]; 244 PPK[0] = TTAK[0];
@@ -299,7 +299,7 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
299 skb->len < hdr_len) 299 skb->len < hdr_len)
300 return -1; 300 return -1;
301 301
302 hdr = (struct rtl_80211_hdr_4addr *) skb->data; 302 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
303 303
304 if (!tcb_desc->bHwSec) { 304 if (!tcb_desc->bHwSec) {
305 if (!tkey->tx_phase1_done) { 305 if (!tkey->tx_phase1_done) {
@@ -343,7 +343,7 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
343 icv[2] = crc >> 16; 343 icv[2] = crc >> 16;
344 icv[3] = crc >> 24; 344 icv[3] = crc >> 24;
345 crypto_sync_skcipher_setkey(tkey->tx_tfm_arc4, rc4key, 16); 345 crypto_sync_skcipher_setkey(tkey->tx_tfm_arc4, rc4key, 16);
346 sg_init_one(&sg, pos, len+4); 346 sg_init_one(&sg, pos, len + 4);
347 skcipher_request_set_sync_tfm(req, tkey->tx_tfm_arc4); 347 skcipher_request_set_sync_tfm(req, tkey->tx_tfm_arc4);
348 skcipher_request_set_callback(req, 0, NULL, NULL); 348 skcipher_request_set_callback(req, 0, NULL, NULL);
349 skcipher_request_set_crypt(req, &sg, &sg, len + 4, NULL); 349 skcipher_request_set_crypt(req, &sg, &sg, len + 4, NULL);
@@ -383,7 +383,7 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
383 if (skb->len < hdr_len + 8 + 4) 383 if (skb->len < hdr_len + 8 + 4)
384 return -1; 384 return -1;
385 385
386 hdr = (struct rtl_80211_hdr_4addr *) skb->data; 386 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
387 pos = skb->data + hdr_len; 387 pos = skb->data + hdr_len;
388 keyidx = pos[3]; 388 keyidx = pos[3];
389 if (!(keyidx & BIT(5))) { 389 if (!(keyidx & BIT(5))) {
@@ -435,7 +435,7 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
435 plen = skb->len - hdr_len - 12; 435 plen = skb->len - hdr_len - 12;
436 436
437 crypto_sync_skcipher_setkey(tkey->rx_tfm_arc4, rc4key, 16); 437 crypto_sync_skcipher_setkey(tkey->rx_tfm_arc4, rc4key, 16);
438 sg_init_one(&sg, pos, plen+4); 438 sg_init_one(&sg, pos, plen + 4);
439 439
440 skcipher_request_set_sync_tfm(req, tkey->rx_tfm_arc4); 440 skcipher_request_set_sync_tfm(req, tkey->rx_tfm_arc4);
441 skcipher_request_set_callback(req, 0, NULL, NULL); 441 skcipher_request_set_callback(req, 0, NULL, NULL);
@@ -523,7 +523,7 @@ static void michael_mic_hdr(struct sk_buff *skb, u8 *hdr)
523{ 523{
524 struct rtl_80211_hdr_4addr *hdr11; 524 struct rtl_80211_hdr_4addr *hdr11;
525 525
526 hdr11 = (struct rtl_80211_hdr_4addr *) skb->data; 526 hdr11 = (struct rtl_80211_hdr_4addr *)skb->data;
527 switch (le16_to_cpu(hdr11->frame_ctl) & 527 switch (le16_to_cpu(hdr11->frame_ctl) &
528 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) { 528 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
529 case IEEE80211_FCTL_TODS: 529 case IEEE80211_FCTL_TODS:
@@ -556,7 +556,7 @@ static int ieee80211_michael_mic_add(struct sk_buff *skb, int hdr_len, void *pri
556 u8 *pos; 556 u8 *pos;
557 struct rtl_80211_hdr_4addr *hdr; 557 struct rtl_80211_hdr_4addr *hdr;
558 558
559 hdr = (struct rtl_80211_hdr_4addr *) skb->data; 559 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
560 560
561 if (skb_tailroom(skb) < 8 || skb->len < hdr_len) { 561 if (skb_tailroom(skb) < 8 || skb->len < hdr_len) {
562 printk(KERN_DEBUG "Invalid packet for Michael MIC add " 562 printk(KERN_DEBUG "Invalid packet for Michael MIC add "
@@ -599,7 +599,7 @@ static void ieee80211_michael_mic_failure(struct net_device *dev,
599 memcpy(ev.src_addr.sa_data, hdr->addr2, ETH_ALEN); 599 memcpy(ev.src_addr.sa_data, hdr->addr2, ETH_ALEN);
600 memset(&wrqu, 0, sizeof(wrqu)); 600 memset(&wrqu, 0, sizeof(wrqu));
601 wrqu.data.length = sizeof(ev); 601 wrqu.data.length = sizeof(ev);
602 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu, (char *) &ev); 602 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu, (char *)&ev);
603} 603}
604 604
605static int ieee80211_michael_mic_verify(struct sk_buff *skb, int keyidx, 605static int ieee80211_michael_mic_verify(struct sk_buff *skb, int keyidx,
@@ -609,7 +609,7 @@ static int ieee80211_michael_mic_verify(struct sk_buff *skb, int keyidx,
609 u8 mic[8]; 609 u8 mic[8];
610 struct rtl_80211_hdr_4addr *hdr; 610 struct rtl_80211_hdr_4addr *hdr;
611 611
612 hdr = (struct rtl_80211_hdr_4addr *) skb->data; 612 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
613 613
614 if (!tkey->key_set) 614 if (!tkey->key_set)
615 return -1; 615 return -1;
@@ -626,7 +626,7 @@ static int ieee80211_michael_mic_verify(struct sk_buff *skb, int keyidx,
626 return -1; 626 return -1;
627 if (memcmp(mic, skb->data + skb->len - 8, 8) != 0) { 627 if (memcmp(mic, skb->data + skb->len - 8, 8) != 0) {
628 struct rtl_80211_hdr_4addr *hdr; 628 struct rtl_80211_hdr_4addr *hdr;
629 hdr = (struct rtl_80211_hdr_4addr *) skb->data; 629 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
630 630
631 printk(KERN_DEBUG "%s: Michael MIC verification failed for " 631 printk(KERN_DEBUG "%s: Michael MIC verification failed for "
632 "MSDU from %pM keyidx=%d\n", 632 "MSDU from %pM keyidx=%d\n",
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c
index 805493a0870d..26482c3dcd1c 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c
@@ -135,7 +135,7 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
135 icv[3] = crc >> 24; 135 icv[3] = crc >> 24;
136 136
137 crypto_sync_skcipher_setkey(wep->tx_tfm, key, klen); 137 crypto_sync_skcipher_setkey(wep->tx_tfm, key, klen);
138 sg_init_one(&sg, pos, len+4); 138 sg_init_one(&sg, pos, len + 4);
139 139
140 skcipher_request_set_sync_tfm(req, wep->tx_tfm); 140 skcipher_request_set_sync_tfm(req, wep->tx_tfm);
141 skcipher_request_set_callback(req, 0, NULL, NULL); 141 skcipher_request_set_callback(req, 0, NULL, NULL);
@@ -192,7 +192,7 @@ static int prism2_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
192 SYNC_SKCIPHER_REQUEST_ON_STACK(req, wep->rx_tfm); 192 SYNC_SKCIPHER_REQUEST_ON_STACK(req, wep->rx_tfm);
193 193
194 crypto_sync_skcipher_setkey(wep->rx_tfm, key, klen); 194 crypto_sync_skcipher_setkey(wep->rx_tfm, key, klen);
195 sg_init_one(&sg, pos, plen+4); 195 sg_init_one(&sg, pos, plen + 4);
196 196
197 skcipher_request_set_sync_tfm(req, wep->rx_tfm); 197 skcipher_request_set_sync_tfm(req, wep->rx_tfm);
198 skcipher_request_set_callback(req, 0, NULL, NULL); 198 skcipher_request_set_callback(req, 0, NULL, NULL);
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
index 0a3e478fccd6..5c33bcb0db2e 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
@@ -103,17 +103,17 @@ ieee80211_frag_cache_get(struct ieee80211_device *ieee,
103 u8 tid; 103 u8 tid;
104 104
105 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) { 105 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) {
106 hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)hdr; 106 hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)hdr;
107 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID; 107 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
108 tid = UP2AC(tid); 108 tid = UP2AC(tid);
109 tid++; 109 tid++;
110 } else if (IEEE80211_QOS_HAS_SEQ(fc)) { 110 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
111 hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)hdr; 111 hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)hdr;
112 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID; 112 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
113 tid = UP2AC(tid); 113 tid = UP2AC(tid);
114 tid++; 114 tid++;
115 } else { 115 } else {
116 tid = 0; 116 tid = 0;
117 } 117 }
118 118
119 if (frag == 0) { 119 if (frag == 0) {
@@ -124,7 +124,7 @@ ieee80211_frag_cache_get(struct ieee80211_device *ieee,
124 2 /* alignment */ + 124 2 /* alignment */ +
125 8 /* WEP */ + 125 8 /* WEP */ +
126 ETH_ALEN /* WDS */ + 126 ETH_ALEN /* WDS */ +
127 (IEEE80211_QOS_HAS_SEQ(fc)?2:0) /* QOS Control */); 127 (IEEE80211_QOS_HAS_SEQ(fc) ? 2 : 0) /* QOS Control */);
128 if (!skb) 128 if (!skb)
129 return NULL; 129 return NULL;
130 130
@@ -145,7 +145,7 @@ ieee80211_frag_cache_get(struct ieee80211_device *ieee,
145 } else { 145 } else {
146 /* received a fragment of a frame for which the head fragment 146 /* received a fragment of a frame for which the head fragment
147 * should have already been received */ 147 * should have already been received */
148 entry = ieee80211_frag_cache_find(ieee, seq, frag, tid,hdr->addr2, 148 entry = ieee80211_frag_cache_find(ieee, seq, frag, tid, hdr->addr2,
149 hdr->addr1); 149 hdr->addr1);
150 if (entry) { 150 if (entry) {
151 entry->last_frag = frag; 151 entry->last_frag = frag;
@@ -169,18 +169,18 @@ static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
169 struct rtl_80211_hdr_4addrqos *hdr_4addrqos; 169 struct rtl_80211_hdr_4addrqos *hdr_4addrqos;
170 u8 tid; 170 u8 tid;
171 171
172 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) { 172 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) {
173 hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)hdr; 173 hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)hdr;
174 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID; 174 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
175 tid = UP2AC(tid); 175 tid = UP2AC(tid);
176 tid++; 176 tid++;
177 } else if (IEEE80211_QOS_HAS_SEQ(fc)) { 177 } else if (IEEE80211_QOS_HAS_SEQ(fc)) {
178 hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)hdr; 178 hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)hdr;
179 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID; 179 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
180 tid = UP2AC(tid); 180 tid = UP2AC(tid);
181 tid++; 181 tid++;
182 } else { 182 } else {
183 tid = 0; 183 tid = 0;
184 } 184 }
185 185
186 entry = ieee80211_frag_cache_find(ieee, seq, -1, tid, hdr->addr2, 186 entry = ieee80211_frag_cache_find(ieee, seq, -1, tid, hdr->addr2,
@@ -216,10 +216,10 @@ ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
216 struct rtl_80211_hdr_3addr *hdr = (struct rtl_80211_hdr_3addr *)skb->data; 216 struct rtl_80211_hdr_3addr *hdr = (struct rtl_80211_hdr_3addr *)skb->data;
217 217
218 rx_stats->len = skb->len; 218 rx_stats->len = skb->len;
219 ieee80211_rx_mgt(ieee,(struct rtl_80211_hdr_4addr *)skb->data,rx_stats); 219 ieee80211_rx_mgt(ieee, (struct rtl_80211_hdr_4addr *)skb->data, rx_stats);
220 /* if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN))) */ 220 /* if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN))) */
221 if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN)))/* use ADDR1 to perform address matching for Management frames */ 221 if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN))) {
222 { 222 /* use ADDR1 to perform address matching for Management frames */
223 dev_kfree_skb_any(skb); 223 dev_kfree_skb_any(skb);
224 return 0; 224 return 0;
225 } 225 }
@@ -281,11 +281,11 @@ ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
281 281
282/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ 282/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
283/* Ethernet-II snap header (RFC1042 for most EtherTypes) */ 283/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
284static unsigned char rfc1042_header[] = 284static unsigned char rfc1042_header[] = {
285{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; 285 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
286/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ 286/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
287static unsigned char bridge_tunnel_header[] = 287static unsigned char bridge_tunnel_header[] = {
288{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; 288 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
289/* No encapsulation header if EtherType < 0x600 (=length) */ 289/* No encapsulation header if EtherType < 0x600 (=length) */
290 290
291/* Called by ieee80211_rx_frame_decrypt */ 291/* Called by ieee80211_rx_frame_decrypt */
@@ -300,7 +300,7 @@ static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
300 if (skb->len < 24) 300 if (skb->len < 24)
301 return 0; 301 return 0;
302 302
303 hdr = (struct rtl_80211_hdr_4addr *) skb->data; 303 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
304 fc = le16_to_cpu(hdr->frame_ctl); 304 fc = le16_to_cpu(hdr->frame_ctl);
305 305
306 /* check that the frame is unicast frame to us */ 306 /* check that the frame is unicast frame to us */
@@ -339,12 +339,11 @@ ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb,
339 339
340 if (!crypt || !crypt->ops->decrypt_mpdu) 340 if (!crypt || !crypt->ops->decrypt_mpdu)
341 return 0; 341 return 0;
342 if (ieee->hwsec_active) 342 if (ieee->hwsec_active) {
343 { 343 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
344 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
345 tcb_desc->bHwSec = 1; 344 tcb_desc->bHwSec = 1;
346 } 345 }
347 hdr = (struct rtl_80211_hdr_4addr *) skb->data; 346 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
348 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); 347 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
349 348
350 if (ieee->tkip_countermeasures && 349 if (ieee->tkip_countermeasures &&
@@ -386,13 +385,12 @@ ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee, struct sk_buff *s
386 385
387 if (!crypt || !crypt->ops->decrypt_msdu) 386 if (!crypt || !crypt->ops->decrypt_msdu)
388 return 0; 387 return 0;
389 if (ieee->hwsec_active) 388 if (ieee->hwsec_active) {
390 { 389 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
391 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
392 tcb_desc->bHwSec = 1; 390 tcb_desc->bHwSec = 1;
393 } 391 }
394 392
395 hdr = (struct rtl_80211_hdr_4addr *) skb->data; 393 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
396 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); 394 hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
397 395
398 atomic_inc(&crypt->refcnt); 396 atomic_inc(&crypt->refcnt);
@@ -410,7 +408,7 @@ ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee, struct sk_buff *s
410 408
411 409
412/* this function is stolen from ipw2200 driver*/ 410/* this function is stolen from ipw2200 driver*/
413#define IEEE_PACKET_RETRY_TIME (5*HZ) 411#define IEEE_PACKET_RETRY_TIME (5 * HZ)
414static int is_duplicate_packet(struct ieee80211_device *ieee, 412static int is_duplicate_packet(struct ieee80211_device *ieee,
415 struct rtl_80211_hdr_4addr *header) 413 struct rtl_80211_hdr_4addr *header)
416{ 414{
@@ -426,18 +424,18 @@ static int is_duplicate_packet(struct ieee80211_device *ieee,
426 424
427 425
428 //TO2DS and QoS 426 //TO2DS and QoS
429 if(((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) { 427 if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) {
430 hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)header; 428 hdr_4addrqos = (struct rtl_80211_hdr_4addrqos *)header;
431 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID; 429 tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QCTL_TID;
432 tid = UP2AC(tid); 430 tid = UP2AC(tid);
433 tid++; 431 tid++;
434 } else if(IEEE80211_QOS_HAS_SEQ(fc)) { //QoS 432 } else if (IEEE80211_QOS_HAS_SEQ(fc)) { //QoS
435 hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)header; 433 hdr_3addrqos = (struct rtl_80211_hdr_3addrqos *)header;
436 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID; 434 tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QCTL_TID;
437 tid = UP2AC(tid); 435 tid = UP2AC(tid);
438 tid++; 436 tid++;
439 } else { // no QoS 437 } else { // no QoS
440 tid = 0; 438 tid = 0;
441 } 439 }
442 440
443 switch (ieee->iw_mode) { 441 switch (ieee->iw_mode) {
@@ -507,8 +505,7 @@ drop:
507static bool AddReorderEntry(struct rx_ts_record *pTS, struct rx_reorder_entry *pReorderEntry) 505static bool AddReorderEntry(struct rx_ts_record *pTS, struct rx_reorder_entry *pReorderEntry)
508{ 506{
509 struct list_head *pList = &pTS->rx_pending_pkt_list; 507 struct list_head *pList = &pTS->rx_pending_pkt_list;
510 while(pList->next != &pTS->rx_pending_pkt_list) 508 while (pList->next != &pTS->rx_pending_pkt_list) {
511 {
512 if (SN_LESS(pReorderEntry->SeqNum, list_entry(pList->next, struct rx_reorder_entry, List)->SeqNum)) 509 if (SN_LESS(pReorderEntry->SeqNum, list_entry(pList->next, struct rx_reorder_entry, List)->SeqNum))
513 pList = pList->next; 510 pList = pList->next;
514 else if (SN_EQUAL(pReorderEntry->SeqNum, list_entry(pList->next, struct rx_reorder_entry, List)->SeqNum)) 511 else if (SN_EQUAL(pReorderEntry->SeqNum, list_entry(pList->next, struct rx_reorder_entry, List)->SeqNum))
@@ -524,17 +521,16 @@ static bool AddReorderEntry(struct rx_ts_record *pTS, struct rx_reorder_entry *p
524 return true; 521 return true;
525} 522}
526 523
527void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb **prxbIndicateArray,u8 index) 524void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb **prxbIndicateArray, u8 index)
528{ 525{
529 u8 i = 0 , j=0; 526 u8 i = 0, j = 0;
530 u16 ethertype; 527 u16 ethertype;
531// if(index > 1) 528// if(index > 1)
532// IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__func__,index); 529// IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): hahahahhhh, We indicate packet from reorder list, index is %u\n",__func__,index);
533 for(j = 0; j<index; j++) 530 for (j = 0; j < index; j++) {
534 {
535//added by amy for reorder 531//added by amy for reorder
536 struct ieee80211_rxb *prxb = prxbIndicateArray[j]; 532 struct ieee80211_rxb *prxb = prxbIndicateArray[j];
537 for(i = 0; i<prxb->nr_subframes; i++) { 533 for (i = 0; i < prxb->nr_subframes; i++) {
538 struct sk_buff *sub_skb = prxb->subframes[i]; 534 struct sk_buff *sub_skb = prxb->subframes[i];
539 535
540 /* convert hdr + possible LLC headers into Ethernet header */ 536 /* convert hdr + possible LLC headers into Ethernet header */
@@ -585,7 +581,7 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
585 u16 WinEnd = (pTS->rx_indicate_seq + WinSize - 1) % 4096; 581 u16 WinEnd = (pTS->rx_indicate_seq + WinSize - 1) % 4096;
586 u8 index = 0; 582 u8 index = 0;
587 bool bMatchWinStart = false, bPktInBuf = false; 583 bool bMatchWinStart = false, bPktInBuf = false;
588 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->rx_indicate_seq is %d, WinSize is %d\n",__func__,SeqNum,pTS->rx_indicate_seq,WinSize); 584 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Seq is %d,pTS->rx_indicate_seq is %d, WinSize is %d\n", __func__, SeqNum, pTS->rx_indicate_seq, WinSize);
589 585
590 prxbIndicateArray = kmalloc_array(REORDER_WIN_SIZE, 586 prxbIndicateArray = kmalloc_array(REORDER_WIN_SIZE,
591 sizeof(struct ieee80211_rxb *), 587 sizeof(struct ieee80211_rxb *),
@@ -599,12 +595,12 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
599 595
600 /* Drop out the packet which SeqNum is smaller than WinStart */ 596 /* Drop out the packet which SeqNum is smaller than WinStart */
601 if (SN_LESS(SeqNum, pTS->rx_indicate_seq)) { 597 if (SN_LESS(SeqNum, pTS->rx_indicate_seq)) {
602 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packet Drop! IndicateSeq: %d, NewSeq: %d\n", 598 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
603 pTS->rx_indicate_seq, SeqNum); 599 pTS->rx_indicate_seq, SeqNum);
604 pHTInfo->RxReorderDropCounter++; 600 pHTInfo->RxReorderDropCounter++;
605 { 601 {
606 int i; 602 int i;
607 for(i =0; i < prxb->nr_subframes; i++) { 603 for (i = 0; i < prxb->nr_subframes; i++) {
608 dev_kfree_skb(prxb->subframes[i]); 604 dev_kfree_skb(prxb->subframes[i]);
609 } 605 }
610 kfree(prxb); 606 kfree(prxb);
@@ -620,16 +616,16 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
620 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1 616 * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
621 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N 617 * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
622 */ 618 */
623 if(SN_EQUAL(SeqNum, pTS->rx_indicate_seq)) { 619 if (SN_EQUAL(SeqNum, pTS->rx_indicate_seq)) {
624 pTS->rx_indicate_seq = (pTS->rx_indicate_seq + 1) % 4096; 620 pTS->rx_indicate_seq = (pTS->rx_indicate_seq + 1) % 4096;
625 bMatchWinStart = true; 621 bMatchWinStart = true;
626 } else if(SN_LESS(WinEnd, SeqNum)) { 622 } else if (SN_LESS(WinEnd, SeqNum)) {
627 if(SeqNum >= (WinSize - 1)) { 623 if (SeqNum >= (WinSize - 1)) {
628 pTS->rx_indicate_seq = SeqNum + 1 -WinSize; 624 pTS->rx_indicate_seq = SeqNum + 1 - WinSize;
629 } else { 625 } else {
630 pTS->rx_indicate_seq = 4095 - (WinSize - (SeqNum + 1)) + 1; 626 pTS->rx_indicate_seq = 4095 - (WinSize - (SeqNum + 1)) + 1;
631 } 627 }
632 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n",pTS->rx_indicate_seq, SeqNum); 628 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n", pTS->rx_indicate_seq, SeqNum);
633 } 629 }
634 630
635 /* 631 /*
@@ -641,7 +637,7 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
641 * 1. All packets with SeqNum smaller than WinStart => Indicate 637 * 1. All packets with SeqNum smaller than WinStart => Indicate
642 * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it. 638 * 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
643 */ 639 */
644 if(bMatchWinStart) { 640 if (bMatchWinStart) {
645 /* Current packet is going to be indicated.*/ 641 /* Current packet is going to be indicated.*/
646 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\ 642 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",\
647 pTS->rx_indicate_seq, SeqNum); 643 pTS->rx_indicate_seq, SeqNum);
@@ -651,7 +647,7 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
651 } else { 647 } else {
652 /* Current packet is going to be inserted into pending list.*/ 648 /* Current packet is going to be inserted into pending list.*/
653 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to ordered list\n",__func__); 649 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): We RX no ordered packed, insert to ordered list\n",__func__);
654 if(!list_empty(&ieee->RxReorder_Unused_List)) { 650 if (!list_empty(&ieee->RxReorder_Unused_List)) {
655 pReorderEntry = list_entry(ieee->RxReorder_Unused_List.next, struct rx_reorder_entry, List); 651 pReorderEntry = list_entry(ieee->RxReorder_Unused_List.next, struct rx_reorder_entry, List);
656 list_del_init(&pReorderEntry->List); 652 list_del_init(&pReorderEntry->List);
657 653
@@ -660,13 +656,13 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
660 pReorderEntry->prxb = prxb; 656 pReorderEntry->prxb = prxb;
661 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__func__,pReorderEntry->SeqNum); 657 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pREorderEntry->SeqNum is %d\n",__func__,pReorderEntry->SeqNum);
662 658
663 if(!AddReorderEntry(pTS, pReorderEntry)) { 659 if (!AddReorderEntry(pTS, pReorderEntry)) {
664 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n", 660 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
665 __func__, pTS->rx_indicate_seq, SeqNum); 661 __func__, pTS->rx_indicate_seq, SeqNum);
666 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List); 662 list_add_tail(&pReorderEntry->List, &ieee->RxReorder_Unused_List);
667 { 663 {
668 int i; 664 int i;
669 for(i =0; i < prxb->nr_subframes; i++) { 665 for (i = 0; i < prxb->nr_subframes; i++) {
670 dev_kfree_skb(prxb->subframes[i]); 666 dev_kfree_skb(prxb->subframes[i]);
671 } 667 }
672 kfree(prxb); 668 kfree(prxb);
@@ -674,10 +670,9 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
674 } 670 }
675 } else { 671 } else {
676 IEEE80211_DEBUG(IEEE80211_DL_REORDER, 672 IEEE80211_DEBUG(IEEE80211_DL_REORDER,
677 "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n",pTS->rx_indicate_seq, SeqNum); 673 "Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n", pTS->rx_indicate_seq, SeqNum);
678 } 674 }
679 } 675 } else {
680 else {
681 /* 676 /*
682 * Packets are dropped if there is not enough reorder entries. 677 * Packets are dropped if there is not enough reorder entries.
683 * This part shall be modified!! We can just indicate all the 678 * This part shall be modified!! We can just indicate all the
@@ -686,7 +681,7 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
686 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n"); 681 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
687 { 682 {
688 int i; 683 int i;
689 for(i =0; i < prxb->nr_subframes; i++) { 684 for (i = 0; i < prxb->nr_subframes; i++) {
690 dev_kfree_skb(prxb->subframes[i]); 685 dev_kfree_skb(prxb->subframes[i]);
691 } 686 }
692 kfree(prxb); 687 kfree(prxb);
@@ -696,12 +691,11 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
696 } 691 }
697 692
698 /* Check if there is any packet need indicate.*/ 693 /* Check if there is any packet need indicate.*/
699 while(!list_empty(&pTS->rx_pending_pkt_list)) { 694 while (!list_empty(&pTS->rx_pending_pkt_list)) {
700 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): start RREORDER indicate\n",__func__); 695 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): start RREORDER indicate\n", __func__);
701 pReorderEntry = list_entry(pTS->rx_pending_pkt_list.prev, struct rx_reorder_entry, List); 696 pReorderEntry = list_entry(pTS->rx_pending_pkt_list.prev, struct rx_reorder_entry, List);
702 if (SN_LESS(pReorderEntry->SeqNum, pTS->rx_indicate_seq) || 697 if (SN_LESS(pReorderEntry->SeqNum, pTS->rx_indicate_seq) ||
703 SN_EQUAL(pReorderEntry->SeqNum, pTS->rx_indicate_seq)) 698 SN_EQUAL(pReorderEntry->SeqNum, pTS->rx_indicate_seq)) {
704 {
705 /* This protect buffer from overflow. */ 699 /* This protect buffer from overflow. */
706 if (index >= REORDER_WIN_SIZE) { 700 if (index >= REORDER_WIN_SIZE) {
707 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!! \n"); 701 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!! \n");
@@ -711,15 +705,15 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
711 705
712 list_del_init(&pReorderEntry->List); 706 list_del_init(&pReorderEntry->List);
713 707
714 if(SN_EQUAL(pReorderEntry->SeqNum, pTS->rx_indicate_seq)) 708 if (SN_EQUAL(pReorderEntry->SeqNum, pTS->rx_indicate_seq))
715 pTS->rx_indicate_seq = (pTS->rx_indicate_seq + 1) % 4096; 709 pTS->rx_indicate_seq = (pTS->rx_indicate_seq + 1) % 4096;
716 710
717 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"Packets indication!! IndicateSeq: %d, NewSeq: %d\n",pTS->rx_indicate_seq, SeqNum); 711 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n", pTS->rx_indicate_seq, SeqNum);
718 prxbIndicateArray[index] = pReorderEntry->prxb; 712 prxbIndicateArray[index] = pReorderEntry->prxb;
719 // printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__func__,pReorderEntry->SeqNum); 713 // printk("========================>%s(): pReorderEntry->SeqNum is %d\n",__func__,pReorderEntry->SeqNum);
720 index++; 714 index++;
721 715
722 list_add_tail(&pReorderEntry->List,&ieee->RxReorder_Unused_List); 716 list_add_tail(&pReorderEntry->List, &ieee->RxReorder_Unused_List);
723 } else { 717 } else {
724 bPktInBuf = true; 718 bPktInBuf = true;
725 break; 719 break;
@@ -727,13 +721,13 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
727 } 721 }
728 722
729 /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/ 723 /* Handling pending timer. Set this timer to prevent from long time Rx buffering.*/
730 if (index>0) { 724 if (index > 0) {
731 // Cancel previous pending timer. 725 // Cancel previous pending timer.
732 // del_timer_sync(&pTS->rx_pkt_pending_timer); 726 // del_timer_sync(&pTS->rx_pkt_pending_timer);
733 pTS->rx_timeout_indicate_seq = 0xffff; 727 pTS->rx_timeout_indicate_seq = 0xffff;
734 728
735 // Indicate packets 729 // Indicate packets
736 if(index>REORDER_WIN_SIZE){ 730 if (index > REORDER_WIN_SIZE) {
737 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorder buffer full!! \n"); 731 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorder buffer full!! \n");
738 kfree(prxbIndicateArray); 732 kfree(prxbIndicateArray);
739 return; 733 return;
@@ -743,9 +737,9 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
743 737
744 if (bPktInBuf && pTS->rx_timeout_indicate_seq == 0xffff) { 738 if (bPktInBuf && pTS->rx_timeout_indicate_seq == 0xffff) {
745 // Set new pending timer. 739 // Set new pending timer.
746 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): SET rx timeout timer\n", __func__); 740 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): SET rx timeout timer\n", __func__);
747 pTS->rx_timeout_indicate_seq = pTS->rx_indicate_seq; 741 pTS->rx_timeout_indicate_seq = pTS->rx_indicate_seq;
748 if(timer_pending(&pTS->rx_pkt_pending_timer)) 742 if (timer_pending(&pTS->rx_pkt_pending_timer))
749 del_timer_sync(&pTS->rx_pkt_pending_timer); 743 del_timer_sync(&pTS->rx_pkt_pending_timer);
750 pTS->rx_pkt_pending_timer.expires = jiffies + 744 pTS->rx_pkt_pending_timer.expires = jiffies +
751 msecs_to_jiffies(pHTInfo->RxReorderPendingTime); 745 msecs_to_jiffies(pHTInfo->RxReorderPendingTime);
@@ -762,12 +756,12 @@ static u8 parse_subframe(struct sk_buff *skb,
762 struct rtl_80211_hdr_3addr *hdr = (struct rtl_80211_hdr_3addr *)skb->data; 756 struct rtl_80211_hdr_3addr *hdr = (struct rtl_80211_hdr_3addr *)skb->data;
763 u16 fc = le16_to_cpu(hdr->frame_ctl); 757 u16 fc = le16_to_cpu(hdr->frame_ctl);
764 758
765 u16 LLCOffset= sizeof(struct rtl_80211_hdr_3addr); 759 u16 LLCOffset = sizeof(struct rtl_80211_hdr_3addr);
766 u16 ChkLength; 760 u16 ChkLength;
767 bool bIsAggregateFrame = false; 761 bool bIsAggregateFrame = false;
768 u16 nSubframe_Length; 762 u16 nSubframe_Length;
769 u8 nPadding_Length = 0; 763 u8 nPadding_Length = 0;
770 u16 SeqNum=0; 764 u16 SeqNum = 0;
771 765
772 struct sk_buff *sub_skb; 766 struct sk_buff *sub_skb;
773 /* just for debug purpose */ 767 /* just for debug purpose */
@@ -793,7 +787,7 @@ static u8 parse_subframe(struct sk_buff *skb,
793 787
794 skb_pull(skb, LLCOffset); 788 skb_pull(skb, LLCOffset);
795 789
796 if(!bIsAggregateFrame) { 790 if (!bIsAggregateFrame) {
797 rxb->nr_subframes = 1; 791 rxb->nr_subframes = 1;
798#ifdef JOHN_NOCPY 792#ifdef JOHN_NOCPY
799 rxb->subframes[0] = skb; 793 rxb->subframes[0] = skb;
@@ -801,26 +795,26 @@ static u8 parse_subframe(struct sk_buff *skb,
801 rxb->subframes[0] = skb_copy(skb, GFP_ATOMIC); 795 rxb->subframes[0] = skb_copy(skb, GFP_ATOMIC);
802#endif 796#endif
803 797
804 memcpy(rxb->src,src,ETH_ALEN); 798 memcpy(rxb->src, src, ETH_ALEN);
805 memcpy(rxb->dst,dst,ETH_ALEN); 799 memcpy(rxb->dst, dst, ETH_ALEN);
806 //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len); 800 //IEEE80211_DEBUG_DATA(IEEE80211_DL_RX,skb->data,skb->len);
807 return 1; 801 return 1;
808 } else { 802 } else {
809 rxb->nr_subframes = 0; 803 rxb->nr_subframes = 0;
810 memcpy(rxb->src,src,ETH_ALEN); 804 memcpy(rxb->src, src, ETH_ALEN);
811 memcpy(rxb->dst,dst,ETH_ALEN); 805 memcpy(rxb->dst, dst, ETH_ALEN);
812 while(skb->len > ETHERNET_HEADER_SIZE) { 806 while (skb->len > ETHERNET_HEADER_SIZE) {
813 /* Offset 12 denote 2 mac address */ 807 /* Offset 12 denote 2 mac address */
814 nSubframe_Length = *((u16 *)(skb->data + 12)); 808 nSubframe_Length = *((u16 *)(skb->data + 12));
815 //==m==>change the length order 809 //==m==>change the length order
816 nSubframe_Length = (nSubframe_Length>>8) + (nSubframe_Length<<8); 810 nSubframe_Length = (nSubframe_Length >> 8) + (nSubframe_Length << 8);
817 811
818 if (skb->len<(ETHERNET_HEADER_SIZE + nSubframe_Length)) { 812 if (skb->len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
819 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\ 813 printk("%s: A-MSDU parse error!! pRfd->nTotalSubframe : %d\n",\
820 __func__, rxb->nr_subframes); 814 __func__, rxb->nr_subframes);
821 printk("%s: A-MSDU parse error!! Subframe Length: %d\n",__func__, nSubframe_Length); 815 printk("%s: A-MSDU parse error!! Subframe Length: %d\n", __func__, nSubframe_Length);
822 printk("nRemain_Length is %d and nSubframe_Length is : %d\n",skb->len,nSubframe_Length); 816 printk("nRemain_Length is %d and nSubframe_Length is : %d\n", skb->len, nSubframe_Length);
823 printk("The Packet SeqNum is %d\n",SeqNum); 817 printk("The Packet SeqNum is %d\n", SeqNum);
824 return 0; 818 return 0;
825 } 819 }
826 820
@@ -923,9 +917,8 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
923 frag = WLAN_GET_SEQ_FRAG(sc); 917 frag = WLAN_GET_SEQ_FRAG(sc);
924 hdrlen = ieee80211_get_hdrlen(fc); 918 hdrlen = ieee80211_get_hdrlen(fc);
925 919
926 if (HTCCheck(ieee, skb->data)) 920 if (HTCCheck(ieee, skb->data)) {
927 { 921 if (net_ratelimit())
928 if(net_ratelimit())
929 printk("find HTCControl\n"); 922 printk("find HTCControl\n");
930 hdrlen += 4; 923 hdrlen += 4;
931 rx_stats->bContainHTC = true; 924 rx_stats->bContainHTC = true;
@@ -972,7 +965,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
972 * stations that do not support WEP key mapping). */ 965 * stations that do not support WEP key mapping). */
973 966
974 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key) 967 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
975 (void) hostap_handle_sta_crypto(local, hdr, &crypt, 968 (void)hostap_handle_sta_crypto(local, hdr, &crypt,
976 &sta); 969 &sta);
977#endif 970#endif
978 971
@@ -998,39 +991,32 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
998 goto rx_dropped; 991 goto rx_dropped;
999 992
1000 // if QoS enabled, should check the sequence for each of the AC 993 // if QoS enabled, should check the sequence for each of the AC
1001 if ((!ieee->pHTInfo->bCurRxReorderEnable) || !ieee->current_network.qos_data.active|| !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)) { 994 if ((!ieee->pHTInfo->bCurRxReorderEnable) || !ieee->current_network.qos_data.active || !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)) {
1002 if (is_duplicate_packet(ieee, hdr)) 995 if (is_duplicate_packet(ieee, hdr))
1003 goto rx_dropped; 996 goto rx_dropped;
1004 997
1005 } 998 } else {
1006 else
1007 {
1008 struct rx_ts_record *pRxTS = NULL; 999 struct rx_ts_record *pRxTS = NULL;
1009 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__func__, tid); 1000 //IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): QOS ENABLE AND RECEIVE QOS DATA , we will get Ts, tid:%d\n",__func__, tid);
1010 if(GetTs( 1001 if (GetTs(
1011 ieee, 1002 ieee,
1012 (struct ts_common_info **) &pRxTS, 1003 (struct ts_common_info **)&pRxTS,
1013 hdr->addr2, 1004 hdr->addr2,
1014 Frame_QoSTID((u8 *)(skb->data)), 1005 Frame_QoSTID((u8 *)(skb->data)),
1015 RX_DIR, 1006 RX_DIR,
1016 true)) 1007 true)) {
1017 {
1018 1008
1019 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pRxTS->rx_last_frag_num is %d,frag is %d,pRxTS->rx_last_seq_num is %d,seq is %d\n",__func__,pRxTS->rx_last_frag_num,frag,pRxTS->rx_last_seq_num,WLAN_GET_SEQ_SEQ(sc)); 1009 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pRxTS->rx_last_frag_num is %d,frag is %d,pRxTS->rx_last_seq_num is %d,seq is %d\n",__func__,pRxTS->rx_last_frag_num,frag,pRxTS->rx_last_seq_num,WLAN_GET_SEQ_SEQ(sc));
1020 if ((fc & (1<<11)) && 1010 if ((fc & (1 << 11)) &&
1021 (frag == pRxTS->rx_last_frag_num) && 1011 (frag == pRxTS->rx_last_frag_num) &&
1022 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->rx_last_seq_num)) { 1012 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->rx_last_seq_num)) {
1023 goto rx_dropped; 1013 goto rx_dropped;
1024 } 1014 } else {
1025 else
1026 {
1027 pRxTS->rx_last_frag_num = frag; 1015 pRxTS->rx_last_frag_num = frag;
1028 pRxTS->rx_last_seq_num = WLAN_GET_SEQ_SEQ(sc); 1016 pRxTS->rx_last_seq_num = WLAN_GET_SEQ_SEQ(sc);
1029 } 1017 }
1030 } 1018 } else {
1031 else 1019 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s(): No TS!! Skip the check!!\n", __func__);
1032 {
1033 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s(): No TS!! Skip the check!!\n",__func__);
1034 goto rx_dropped; 1020 goto rx_dropped;
1035 } 1021 }
1036 } 1022 }
@@ -1126,14 +1112,13 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1126 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */ 1112 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
1127 1113
1128 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) && 1114 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1129 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0) 1115 (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0) {
1130 {
1131 printk("decrypt frame error\n"); 1116 printk("decrypt frame error\n");
1132 goto rx_dropped; 1117 goto rx_dropped;
1133 } 1118 }
1134 1119
1135 1120
1136 hdr = (struct rtl_80211_hdr_4addr *) skb->data; 1121 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
1137 1122
1138 /* skb: hdr + (possibly fragmented) plaintext payload */ 1123 /* skb: hdr + (possibly fragmented) plaintext payload */
1139 // PR: FIXME: hostap has additional conditions in the "if" below: 1124 // PR: FIXME: hostap has additional conditions in the "if" below:
@@ -1185,15 +1170,14 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1185 /* this was the last fragment and the frame will be 1170 /* this was the last fragment and the frame will be
1186 * delivered, so remove skb from fragment cache */ 1171 * delivered, so remove skb from fragment cache */
1187 skb = frag_skb; 1172 skb = frag_skb;
1188 hdr = (struct rtl_80211_hdr_4addr *) skb->data; 1173 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
1189 ieee80211_frag_cache_invalidate(ieee, hdr); 1174 ieee80211_frag_cache_invalidate(ieee, hdr);
1190 } 1175 }
1191 1176
1192 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still 1177 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
1193 * encrypted/authenticated */ 1178 * encrypted/authenticated */
1194 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) && 1179 if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
1195 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt)) 1180 ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt)) {
1196 {
1197 printk("==>decrypt msdu error\n"); 1181 printk("==>decrypt msdu error\n");
1198 goto rx_dropped; 1182 goto rx_dropped;
1199 } 1183 }
@@ -1202,7 +1186,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1202 ieee->LinkDetectInfo.NumRecvDataInPeriod++; 1186 ieee->LinkDetectInfo.NumRecvDataInPeriod++;
1203 ieee->LinkDetectInfo.NumRxOkInPeriod++; 1187 ieee->LinkDetectInfo.NumRxOkInPeriod++;
1204 1188
1205 hdr = (struct rtl_80211_hdr_4addr *) skb->data; 1189 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
1206 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) { 1190 if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) {
1207 if (/*ieee->ieee802_1x &&*/ 1191 if (/*ieee->ieee802_1x &&*/
1208 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) { 1192 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
@@ -1227,10 +1211,10 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1227#ifdef CONFIG_IEEE80211_DEBUG 1211#ifdef CONFIG_IEEE80211_DEBUG
1228 if (crypt && !(fc & IEEE80211_FCTL_WEP) && 1212 if (crypt && !(fc & IEEE80211_FCTL_WEP) &&
1229 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) { 1213 ieee80211_is_eapol_frame(ieee, skb, hdrlen)) {
1230 struct eapol *eap = (struct eapol *)(skb->data + 1214 struct eapol *eap = (struct eapol *)(skb->data +
1231 24); 1215 24);
1232 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n", 1216 IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
1233 eap_get_type(eap->type)); 1217 eap_get_type(eap->type));
1234 } 1218 }
1235#endif 1219#endif
1236 1220
@@ -1250,13 +1234,11 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1250*/ 1234*/
1251//added by amy for reorder 1235//added by amy for reorder
1252 if (ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data) 1236 if (ieee->current_network.qos_data.active && IsQoSDataFrame(skb->data)
1253 && !is_multicast_ether_addr(hdr->addr1)) 1237 && !is_multicast_ether_addr(hdr->addr1)) {
1254 {
1255 TID = Frame_QoSTID(skb->data); 1238 TID = Frame_QoSTID(skb->data);
1256 SeqNum = WLAN_GET_SEQ_SEQ(sc); 1239 SeqNum = WLAN_GET_SEQ_SEQ(sc);
1257 GetTs(ieee,(struct ts_common_info **) &pTS,hdr->addr2,TID,RX_DIR,true); 1240 GetTs(ieee, (struct ts_common_info **)&pTS, hdr->addr2, TID, RX_DIR, true);
1258 if (TID !=0 && TID !=3) 1241 if (TID != 0 && TID != 3) {
1259 {
1260 ieee->bis_any_nonbepkts = true; 1242 ieee->bis_any_nonbepkts = true;
1261 } 1243 }
1262 } 1244 }
@@ -1270,7 +1252,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1270 /* qos data packets & reserved bit is 1 */ 1252 /* qos data packets & reserved bit is 1 */
1271 if (parse_subframe(skb, rx_stats, rxb, src, dst) == 0) { 1253 if (parse_subframe(skb, rx_stats, rxb, src, dst) == 0) {
1272 /* only to free rxb, and not submit the packets to upper layer */ 1254 /* only to free rxb, and not submit the packets to upper layer */
1273 for(i =0; i < rxb->nr_subframes; i++) { 1255 for (i = 0; i < rxb->nr_subframes; i++) {
1274 dev_kfree_skb(rxb->subframes[i]); 1256 dev_kfree_skb(rxb->subframes[i]);
1275 } 1257 }
1276 kfree(rxb); 1258 kfree(rxb);
@@ -1281,7 +1263,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1281//added by amy for reorder 1263//added by amy for reorder
1282 if (!ieee->pHTInfo->bCurRxReorderEnable || !pTS) { 1264 if (!ieee->pHTInfo->bCurRxReorderEnable || !pTS) {
1283//added by amy for reorder 1265//added by amy for reorder
1284 for(i = 0; i<rxb->nr_subframes; i++) { 1266 for (i = 0; i < rxb->nr_subframes; i++) {
1285 struct sk_buff *sub_skb = rxb->subframes[i]; 1267 struct sk_buff *sub_skb = rxb->subframes[i];
1286 1268
1287 if (sub_skb) { 1269 if (sub_skb) {
@@ -1324,10 +1306,8 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1324 kfree(rxb); 1306 kfree(rxb);
1325 rxb = NULL; 1307 rxb = NULL;
1326 1308
1327 } 1309 } else {
1328 else 1310 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n", __func__);
1329 {
1330 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): REORDER ENABLE AND PTS not NULL, and we will enter RxReorderIndicatePacket()\n",__func__);
1331 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum); 1311 RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
1332 } 1312 }
1333#ifndef JOHN_NOCPY 1313#ifndef JOHN_NOCPY
@@ -1407,10 +1387,9 @@ static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
1407/* 1387/*
1408 * Parse a QoS information element 1388 * Parse a QoS information element
1409 */ 1389 */
1410static int ieee80211_read_qos_info_element(struct 1390static int ieee80211_read_qos_info_element(
1411 ieee80211_qos_information_element 1391 struct ieee80211_qos_information_element *element_info,
1412 *element_info, struct ieee80211_info_element 1392 struct ieee80211_info_element *info_element)
1413 *info_element)
1414{ 1393{
1415 int ret = 0; 1394 int ret = 0;
1416 u16 size = sizeof(struct ieee80211_qos_information_element) - 2; 1395 u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
@@ -1438,11 +1417,9 @@ static int ieee80211_read_qos_info_element(struct
1438/* 1417/*
1439 * Write QoS parameters from the ac parameters. 1418 * Write QoS parameters from the ac parameters.
1440 */ 1419 */
1441static int ieee80211_qos_convert_ac_to_parameters(struct 1420static int ieee80211_qos_convert_ac_to_parameters(
1442 ieee80211_qos_parameter_info 1421 struct ieee80211_qos_parameter_info *param_elm,
1443 *param_elm, struct 1422 struct ieee80211_qos_parameters *qos_param)
1444 ieee80211_qos_parameters
1445 *qos_param)
1446{ 1423{
1447 int i; 1424 int i;
1448 struct ieee80211_qos_ac_parameter *ac_params; 1425 struct ieee80211_qos_ac_parameter *ac_params;
@@ -1455,12 +1432,12 @@ static int ieee80211_qos_convert_ac_to_parameters(struct
1455 1432
1456 aci = (ac_params->aci_aifsn & 0x60) >> 5; 1433 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1457 1434
1458 if(aci >= QOS_QUEUE_NUM) 1435 if (aci >= QOS_QUEUE_NUM)
1459 continue; 1436 continue;
1460 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f; 1437 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1461 1438
1462 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */ 1439 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1463 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci]; 1440 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2 : qos_param->aifs[aci];
1464 1441
1465 qos_param->cw_min[aci] = 1442 qos_param->cw_min[aci] =
1466 cpu_to_le16(ac_params->ecw_min_max & 0x0F); 1443 cpu_to_le16(ac_params->ecw_min_max & 0x0F);
@@ -1561,15 +1538,12 @@ static inline void ieee80211_extract_country_ie(
1561 u8 *addr2 1538 u8 *addr2
1562) 1539)
1563{ 1540{
1564 if (IS_DOT11D_ENABLE(ieee)) 1541 if (IS_DOT11D_ENABLE(ieee)) {
1565 { 1542 if (info_element->len != 0) {
1566 if (info_element->len!= 0)
1567 {
1568 memcpy(network->CountryIeBuf, info_element->data, info_element->len); 1543 memcpy(network->CountryIeBuf, info_element->data, info_element->len);
1569 network->CountryIeLen = info_element->len; 1544 network->CountryIeLen = info_element->len;
1570 1545
1571 if (!IS_COUNTRY_IE_VALID(ieee)) 1546 if (!IS_COUNTRY_IE_VALID(ieee)) {
1572 {
1573 dot11d_update_country_ie(ieee, addr2, info_element->len, info_element->data); 1547 dot11d_update_country_ie(ieee, addr2, info_element->len, info_element->data);
1574 } 1548 }
1575 } 1549 }
@@ -1579,8 +1553,7 @@ static inline void ieee80211_extract_country_ie(
1579 // some AP (e.g. Cisco 1242) don't include country IE in their 1553 // some AP (e.g. Cisco 1242) don't include country IE in their
1580 // probe response frame. 1554 // probe response frame.
1581 // 1555 //
1582 if (IS_EQUAL_CIE_SRC(ieee, addr2) ) 1556 if (IS_EQUAL_CIE_SRC(ieee, addr2)) {
1583 {
1584 UPDATE_CIE_WATCHDOG(ieee); 1557 UPDATE_CIE_WATCHDOG(ieee);
1585 } 1558 }
1586 } 1559 }
@@ -1595,9 +1568,9 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1595{ 1568{
1596 u8 i; 1569 u8 i;
1597 short offset; 1570 short offset;
1598 u16 tmp_htcap_len=0; 1571 u16 tmp_htcap_len = 0;
1599 u16 tmp_htinfo_len=0; 1572 u16 tmp_htinfo_len = 0;
1600 u16 ht_realtek_agg_len=0; 1573 u16 ht_realtek_agg_len = 0;
1601 u8 ht_realtek_agg_buf[MAX_IE_LEN]; 1574 u8 ht_realtek_agg_buf[MAX_IE_LEN];
1602// u16 broadcom_len = 0; 1575// u16 broadcom_len = 0;
1603#ifdef CONFIG_IEEE80211_DEBUG 1576#ifdef CONFIG_IEEE80211_DEBUG
@@ -1628,7 +1601,7 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1628 } 1601 }
1629 1602
1630 network->ssid_len = min(info_element->len, 1603 network->ssid_len = min(info_element->len,
1631 (u8) IW_ESSID_MAX_SIZE); 1604 (u8)IW_ESSID_MAX_SIZE);
1632 memcpy(network->ssid, info_element->data, network->ssid_len); 1605 memcpy(network->ssid, info_element->data, network->ssid_len);
1633 if (network->ssid_len < IW_ESSID_MAX_SIZE) 1606 if (network->ssid_len < IW_ESSID_MAX_SIZE)
1634 memset(network->ssid + network->ssid_len, 0, 1607 memset(network->ssid + network->ssid_len, 0,
@@ -1707,14 +1680,14 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1707 break; 1680 break;
1708 1681
1709 case MFIE_TYPE_TIM: 1682 case MFIE_TYPE_TIM:
1710 if(info_element->len < 4) 1683 if (info_element->len < 4)
1711 break; 1684 break;
1712 1685
1713 network->tim.tim_count = info_element->data[0]; 1686 network->tim.tim_count = info_element->data[0];
1714 network->tim.tim_period = info_element->data[1]; 1687 network->tim.tim_period = info_element->data[1];
1715 1688
1716 network->dtim_period = info_element->data[1]; 1689 network->dtim_period = info_element->data[1];
1717 if(ieee->state != IEEE80211_LINKED) 1690 if (ieee->state != IEEE80211_LINKED)
1718 break; 1691 break;
1719 1692
1720 network->last_dtim_sta_time[0] = stats->mac_time[0]; 1693 network->last_dtim_sta_time[0] = stats->mac_time[0];
@@ -1722,22 +1695,22 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1722 1695
1723 network->dtim_data = IEEE80211_DTIM_VALID; 1696 network->dtim_data = IEEE80211_DTIM_VALID;
1724 1697
1725 if(info_element->data[0] != 0) 1698 if (info_element->data[0] != 0)
1726 break; 1699 break;
1727 1700
1728 if(info_element->data[2] & 1) 1701 if (info_element->data[2] & 1)
1729 network->dtim_data |= IEEE80211_DTIM_MBCAST; 1702 network->dtim_data |= IEEE80211_DTIM_MBCAST;
1730 1703
1731 offset = (info_element->data[2] >> 1)*2; 1704 offset = (info_element->data[2] >> 1) * 2;
1732 1705
1733 if(ieee->assoc_id < 8*offset || 1706 if (ieee->assoc_id < 8 * offset ||
1734 ieee->assoc_id > 8*(offset + info_element->len -3)) 1707 ieee->assoc_id > 8 * (offset + info_element->len - 3))
1735 1708
1736 break; 1709 break;
1737 1710
1738 offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ; 1711 offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ;
1739 1712
1740 if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8))) 1713 if (info_element->data[3 + offset] & (1 << (ieee->assoc_id % 8)))
1741 network->dtim_data |= IEEE80211_DTIM_UCAST; 1714 network->dtim_data |= IEEE80211_DTIM_UCAST;
1742 1715
1743 //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n"); 1716 //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
@@ -1790,66 +1763,66 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1790#endif 1763#endif
1791 1764
1792 //for HTcap and HTinfo parameters 1765 //for HTcap and HTinfo parameters
1793 if(tmp_htcap_len == 0){ 1766 if (tmp_htcap_len == 0) {
1794 if(info_element->len >= 4 && 1767 if (info_element->len >= 4 &&
1795 info_element->data[0] == 0x00 && 1768 info_element->data[0] == 0x00 &&
1796 info_element->data[1] == 0x90 && 1769 info_element->data[1] == 0x90 &&
1797 info_element->data[2] == 0x4c && 1770 info_element->data[2] == 0x4c &&
1798 info_element->data[3] == 0x033){ 1771 info_element->data[3] == 0x033){
1799 1772
1800 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN); 1773 tmp_htcap_len = min(info_element->len, (u8)MAX_IE_LEN);
1801 if(tmp_htcap_len != 0){ 1774 if (tmp_htcap_len != 0) {
1802 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC; 1775 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1803 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\ 1776 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf) ? \
1804 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len; 1777 sizeof(network->bssht.bdHTCapBuf) : tmp_htcap_len;
1805 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen); 1778 memcpy(network->bssht.bdHTCapBuf, info_element->data, network->bssht.bdHTCapLen);
1806 } 1779 }
1807 } 1780 }
1808 if(tmp_htcap_len != 0) 1781 if (tmp_htcap_len != 0)
1809 network->bssht.bdSupportHT = true; 1782 network->bssht.bdSupportHT = true;
1810 else 1783 else
1811 network->bssht.bdSupportHT = false; 1784 network->bssht.bdSupportHT = false;
1812 } 1785 }
1813 1786
1814 1787
1815 if(tmp_htinfo_len == 0){ 1788 if (tmp_htinfo_len == 0) {
1816 if(info_element->len >= 4 && 1789 if (info_element->len >= 4 &&
1817 info_element->data[0] == 0x00 && 1790 info_element->data[0] == 0x00 &&
1818 info_element->data[1] == 0x90 && 1791 info_element->data[1] == 0x90 &&
1819 info_element->data[2] == 0x4c && 1792 info_element->data[2] == 0x4c &&
1820 info_element->data[3] == 0x034){ 1793 info_element->data[3] == 0x034){
1821 1794
1822 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN); 1795 tmp_htinfo_len = min(info_element->len, (u8)MAX_IE_LEN);
1823 if(tmp_htinfo_len != 0){ 1796 if (tmp_htinfo_len != 0) {
1824 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC; 1797 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1825 if(tmp_htinfo_len){ 1798 if (tmp_htinfo_len) {
1826 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\ 1799 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf) ? \
1827 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len; 1800 sizeof(network->bssht.bdHTInfoBuf) : tmp_htinfo_len;
1828 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen); 1801 memcpy(network->bssht.bdHTInfoBuf, info_element->data, network->bssht.bdHTInfoLen);
1829 }
1830
1831 } 1802 }
1832 1803
1804 }
1805
1833 } 1806 }
1834 } 1807 }
1835 1808
1836 if(ieee->aggregation){ 1809 if (ieee->aggregation) {
1837 if(network->bssht.bdSupportHT){ 1810 if (network->bssht.bdSupportHT) {
1838 if(info_element->len >= 4 && 1811 if (info_element->len >= 4 &&
1839 info_element->data[0] == 0x00 && 1812 info_element->data[0] == 0x00 &&
1840 info_element->data[1] == 0xe0 && 1813 info_element->data[1] == 0xe0 &&
1841 info_element->data[2] == 0x4c && 1814 info_element->data[2] == 0x4c &&
1842 info_element->data[3] == 0x02){ 1815 info_element->data[3] == 0x02){
1843 1816
1844 ht_realtek_agg_len = min(info_element->len,(u8)MAX_IE_LEN); 1817 ht_realtek_agg_len = min(info_element->len, (u8)MAX_IE_LEN);
1845 memcpy(ht_realtek_agg_buf,info_element->data,info_element->len); 1818 memcpy(ht_realtek_agg_buf, info_element->data, info_element->len);
1846 1819
1847 } 1820 }
1848 if(ht_realtek_agg_len >= 5){ 1821 if (ht_realtek_agg_len >= 5) {
1849 network->bssht.bdRT2RTAggregation = true; 1822 network->bssht.bdRT2RTAggregation = true;
1850 1823
1851 if((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02)) 1824 if ((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
1852 network->bssht.bdRT2RTLongSlotTime = true; 1825 network->bssht.bdRT2RTLongSlotTime = true;
1853 } 1826 }
1854 } 1827 }
1855 1828
@@ -1870,78 +1843,63 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1870 info_element->data[1] == 0x10 && 1843 info_element->data[1] == 0x10 &&
1871 info_element->data[2] == 0x18)){ 1844 info_element->data[2] == 0x18)){
1872 1845
1873 network->broadcom_cap_exist = true; 1846 network->broadcom_cap_exist = true;
1874 1847
1875 } 1848 }
1876 } 1849 }
1877 if(info_element->len >= 3 && 1850 if (info_element->len >= 3 &&
1878 info_element->data[0] == 0x00 && 1851 info_element->data[0] == 0x00 &&
1879 info_element->data[1] == 0x0c && 1852 info_element->data[1] == 0x0c &&
1880 info_element->data[2] == 0x43) 1853 info_element->data[2] == 0x43) {
1881 {
1882 network->ralink_cap_exist = true; 1854 network->ralink_cap_exist = true;
1883 } 1855 } else
1884 else
1885 network->ralink_cap_exist = false; 1856 network->ralink_cap_exist = false;
1886 //added by amy for atheros AP 1857 //added by amy for atheros AP
1887 if((info_element->len >= 3 && 1858 if ((info_element->len >= 3 &&
1888 info_element->data[0] == 0x00 && 1859 info_element->data[0] == 0x00 &&
1889 info_element->data[1] == 0x03 && 1860 info_element->data[1] == 0x03 &&
1890 info_element->data[2] == 0x7f) || 1861 info_element->data[2] == 0x7f) ||
1891 (info_element->len >= 3 && 1862 (info_element->len >= 3 &&
1892 info_element->data[0] == 0x00 && 1863 info_element->data[0] == 0x00 &&
1893 info_element->data[1] == 0x13 && 1864 info_element->data[1] == 0x13 &&
1894 info_element->data[2] == 0x74)) 1865 info_element->data[2] == 0x74)) {
1895 { 1866 printk("========>%s(): athros AP is exist\n", __func__);
1896 printk("========>%s(): athros AP is exist\n",__func__);
1897 network->atheros_cap_exist = true; 1867 network->atheros_cap_exist = true;
1898 } 1868 } else
1899 else
1900 network->atheros_cap_exist = false; 1869 network->atheros_cap_exist = false;
1901 1870
1902 if(info_element->len >= 3 && 1871 if (info_element->len >= 3 &&
1903 info_element->data[0] == 0x00 && 1872 info_element->data[0] == 0x00 &&
1904 info_element->data[1] == 0x40 && 1873 info_element->data[1] == 0x40 &&
1905 info_element->data[2] == 0x96) 1874 info_element->data[2] == 0x96) {
1906 {
1907 network->cisco_cap_exist = true; 1875 network->cisco_cap_exist = true;
1908 } 1876 } else
1909 else
1910 network->cisco_cap_exist = false; 1877 network->cisco_cap_exist = false;
1911 //added by amy for LEAP of cisco 1878 //added by amy for LEAP of cisco
1912 if (info_element->len > 4 && 1879 if (info_element->len > 4 &&
1913 info_element->data[0] == 0x00 && 1880 info_element->data[0] == 0x00 &&
1914 info_element->data[1] == 0x40 && 1881 info_element->data[1] == 0x40 &&
1915 info_element->data[2] == 0x96 && 1882 info_element->data[2] == 0x96 &&
1916 info_element->data[3] == 0x01) 1883 info_element->data[3] == 0x01) {
1917 { 1884 if (info_element->len == 6) {
1918 if(info_element->len == 6)
1919 {
1920 memcpy(network->CcxRmState, &info_element[4], 2); 1885 memcpy(network->CcxRmState, &info_element[4], 2);
1921 if(network->CcxRmState[0] != 0) 1886 if (network->CcxRmState[0] != 0)
1922 {
1923 network->bCcxRmEnable = true; 1887 network->bCcxRmEnable = true;
1924 }
1925 else 1888 else
1926 network->bCcxRmEnable = false; 1889 network->bCcxRmEnable = false;
1927 // 1890 //
1928 // CCXv4 Table 59-1 MBSSID Masks. 1891 // CCXv4 Table 59-1 MBSSID Masks.
1929 // 1892 //
1930 network->MBssidMask = network->CcxRmState[1] & 0x07; 1893 network->MBssidMask = network->CcxRmState[1] & 0x07;
1931 if(network->MBssidMask != 0) 1894 if (network->MBssidMask != 0) {
1932 {
1933 network->bMBssidValid = true; 1895 network->bMBssidValid = true;
1934 network->MBssidMask = 0xff << (network->MBssidMask); 1896 network->MBssidMask = 0xff << (network->MBssidMask);
1935 ether_addr_copy(network->MBssid, network->bssid); 1897 ether_addr_copy(network->MBssid, network->bssid);
1936 network->MBssid[5] &= network->MBssidMask; 1898 network->MBssid[5] &= network->MBssidMask;
1937 } 1899 } else {
1938 else
1939 {
1940 network->bMBssidValid = false; 1900 network->bMBssidValid = false;
1941 } 1901 }
1942 } 1902 } else {
1943 else
1944 {
1945 network->bCcxRmEnable = false; 1903 network->bCcxRmEnable = false;
1946 } 1904 }
1947 } 1905 }
@@ -1949,15 +1907,11 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1949 info_element->data[0] == 0x00 && 1907 info_element->data[0] == 0x00 &&
1950 info_element->data[1] == 0x40 && 1908 info_element->data[1] == 0x40 &&
1951 info_element->data[2] == 0x96 && 1909 info_element->data[2] == 0x96 &&
1952 info_element->data[3] == 0x03) 1910 info_element->data[3] == 0x03) {
1953 { 1911 if (info_element->len == 5) {
1954 if(info_element->len == 5)
1955 {
1956 network->bWithCcxVerNum = true; 1912 network->bWithCcxVerNum = true;
1957 network->BssCcxVerNumber = info_element->data[4]; 1913 network->BssCcxVerNumber = info_element->data[4];
1958 } 1914 } else {
1959 else
1960 {
1961 network->bWithCcxVerNum = false; 1915 network->bWithCcxVerNum = false;
1962 network->BssCcxVerNumber = 0; 1916 network->BssCcxVerNumber = 0;
1963 } 1917 }
@@ -1977,19 +1931,18 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1977 case MFIE_TYPE_HT_CAP: 1931 case MFIE_TYPE_HT_CAP:
1978 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n", 1932 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
1979 info_element->len); 1933 info_element->len);
1980 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN); 1934 tmp_htcap_len = min(info_element->len, (u8)MAX_IE_LEN);
1981 if(tmp_htcap_len != 0){ 1935 if (tmp_htcap_len != 0) {
1982 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC; 1936 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1983 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\ 1937 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf) ? \
1984 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len; 1938 sizeof(network->bssht.bdHTCapBuf) : tmp_htcap_len;
1985 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen); 1939 memcpy(network->bssht.bdHTCapBuf, info_element->data, network->bssht.bdHTCapLen);
1986 1940
1987 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT() 1941 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
1988 // windows driver will update WMM parameters each beacon received once connected 1942 // windows driver will update WMM parameters each beacon received once connected
1989 // Linux driver is a bit different. 1943 // Linux driver is a bit different.
1990 network->bssht.bdSupportHT = true; 1944 network->bssht.bdSupportHT = true;
1991 } 1945 } else
1992 else
1993 network->bssht.bdSupportHT = false; 1946 network->bssht.bdSupportHT = false;
1994 break; 1947 break;
1995 1948
@@ -1997,37 +1950,31 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1997 case MFIE_TYPE_HT_INFO: 1950 case MFIE_TYPE_HT_INFO:
1998 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n", 1951 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
1999 info_element->len); 1952 info_element->len);
2000 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN); 1953 tmp_htinfo_len = min(info_element->len, (u8)MAX_IE_LEN);
2001 if(tmp_htinfo_len){ 1954 if (tmp_htinfo_len) {
2002 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE; 1955 network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
2003 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf)?\ 1956 network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf) ? \
2004 sizeof(network->bssht.bdHTInfoBuf):tmp_htinfo_len; 1957 sizeof(network->bssht.bdHTInfoBuf) : tmp_htinfo_len;
2005 memcpy(network->bssht.bdHTInfoBuf,info_element->data,network->bssht.bdHTInfoLen); 1958 memcpy(network->bssht.bdHTInfoBuf, info_element->data, network->bssht.bdHTInfoLen);
2006 } 1959 }
2007 break; 1960 break;
2008 1961
2009 case MFIE_TYPE_AIRONET: 1962 case MFIE_TYPE_AIRONET:
2010 IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n", 1963 IEEE80211_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
2011 info_element->len); 1964 info_element->len);
2012 if(info_element->len >IE_CISCO_FLAG_POSITION) 1965 if (info_element->len > IE_CISCO_FLAG_POSITION) {
2013 {
2014 network->bWithAironetIE = true; 1966 network->bWithAironetIE = true;
2015 1967
2016 // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23): 1968 // CCX 1 spec v1.13, A01.1 CKIP Negotiation (page23):
2017 // "A Cisco access point advertises support for CKIP in beacon and probe response packets, 1969 // "A Cisco access point advertises support for CKIP in beacon and probe response packets,
2018 // by adding an Aironet element and setting one or both of the CKIP negotiation bits." 1970 // by adding an Aironet element and setting one or both of the CKIP negotiation bits."
2019 if( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) || 1971 if ((info_element->data[IE_CISCO_FLAG_POSITION] & SUPPORT_CKIP_MIC) ||
2020 (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) ) 1972 (info_element->data[IE_CISCO_FLAG_POSITION] & SUPPORT_CKIP_PK)) {
2021 {
2022 network->bCkipSupported = true; 1973 network->bCkipSupported = true;
2023 } 1974 } else {
2024 else
2025 {
2026 network->bCkipSupported = false; 1975 network->bCkipSupported = false;
2027 } 1976 }
2028 } 1977 } else {
2029 else
2030 {
2031 network->bWithAironetIE = false; 1978 network->bWithAironetIE = false;
2032 network->bCkipSupported = false; 1979 network->bCkipSupported = false;
2033 } 1980 }
@@ -2057,13 +2004,10 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
2057 data[info_element->len]; 2004 data[info_element->len];
2058 } 2005 }
2059 2006
2060 if(!network->atheros_cap_exist && !network->broadcom_cap_exist && 2007 if (!network->atheros_cap_exist && !network->broadcom_cap_exist &&
2061 !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation) 2008 !network->cisco_cap_exist && !network->ralink_cap_exist && !network->bssht.bdRT2RTAggregation) {
2062 {
2063 network->unknown_cap_exist = true; 2009 network->unknown_cap_exist = true;
2064 } 2010 } else {
2065 else
2066 {
2067 network->unknown_cap_exist = false; 2011 network->unknown_cap_exist = false;
2068 } 2012 }
2069 return 0; 2013 return 0;
@@ -2076,44 +2020,25 @@ static inline u8 ieee80211_SignalStrengthTranslate(
2076 u8 RetSS; 2020 u8 RetSS;
2077 2021
2078 // Step 1. Scale mapping. 2022 // Step 1. Scale mapping.
2079 if(CurrSS >= 71 && CurrSS <= 100) 2023 if (CurrSS >= 71 && CurrSS <= 100) {
2080 {
2081 RetSS = 90 + ((CurrSS - 70) / 3); 2024 RetSS = 90 + ((CurrSS - 70) / 3);
2082 } 2025 } else if (CurrSS >= 41 && CurrSS <= 70) {
2083 else if(CurrSS >= 41 && CurrSS <= 70)
2084 {
2085 RetSS = 78 + ((CurrSS - 40) / 3); 2026 RetSS = 78 + ((CurrSS - 40) / 3);
2086 } 2027 } else if (CurrSS >= 31 && CurrSS <= 40) {
2087 else if(CurrSS >= 31 && CurrSS <= 40)
2088 {
2089 RetSS = 66 + (CurrSS - 30); 2028 RetSS = 66 + (CurrSS - 30);
2090 } 2029 } else if (CurrSS >= 21 && CurrSS <= 30) {
2091 else if(CurrSS >= 21 && CurrSS <= 30)
2092 {
2093 RetSS = 54 + (CurrSS - 20); 2030 RetSS = 54 + (CurrSS - 20);
2094 } 2031 } else if (CurrSS >= 5 && CurrSS <= 20) {
2095 else if(CurrSS >= 5 && CurrSS <= 20)
2096 {
2097 RetSS = 42 + (((CurrSS - 5) * 2) / 3); 2032 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2098 } 2033 } else if (CurrSS == 4) {
2099 else if(CurrSS == 4)
2100 {
2101 RetSS = 36; 2034 RetSS = 36;
2102 } 2035 } else if (CurrSS == 3) {
2103 else if(CurrSS == 3)
2104 {
2105 RetSS = 27; 2036 RetSS = 27;
2106 } 2037 } else if (CurrSS == 2) {
2107 else if(CurrSS == 2)
2108 {
2109 RetSS = 18; 2038 RetSS = 18;
2110 } 2039 } else if (CurrSS == 1) {
2111 else if(CurrSS == 1)
2112 {
2113 RetSS = 9; 2040 RetSS = 9;
2114 } 2041 } else {
2115 else
2116 {
2117 RetSS = CurrSS; 2042 RetSS = CurrSS;
2118 } 2043 }
2119 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS)); 2044 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
@@ -2193,7 +2118,7 @@ static inline int ieee80211_network_init(
2193 network->rsn_ie_len = 0; 2118 network->rsn_ie_len = 0;
2194 2119
2195 if (ieee80211_parse_info_param 2120 if (ieee80211_parse_info_param
2196 (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats)) 2121 (ieee, beacon->info_element, stats->len - sizeof(*beacon), network, stats))
2197 return 1; 2122 return 1;
2198 2123
2199 network->mode = 0; 2124 network->mode = 0;
@@ -2215,10 +2140,10 @@ static inline int ieee80211_network_init(
2215 return 1; 2140 return 1;
2216 } 2141 }
2217 2142
2218 if(network->bssht.bdSupportHT){ 2143 if (network->bssht.bdSupportHT) {
2219 if(network->mode == IEEE_A) 2144 if (network->mode == IEEE_A)
2220 network->mode = IEEE_N_5G; 2145 network->mode = IEEE_N_5G;
2221 else if(network->mode & (IEEE_G | IEEE_B)) 2146 else if (network->mode & (IEEE_G | IEEE_B))
2222 network->mode = IEEE_N_24G; 2147 network->mode = IEEE_N_24G;
2223 } 2148 }
2224 if (ieee80211_is_empty_essid(network->ssid, network->ssid_len)) 2149 if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
@@ -2226,7 +2151,7 @@ static inline int ieee80211_network_init(
2226 2151
2227 stats->signal = 30 + (stats->SignalStrength * 70) / 100; 2152 stats->signal = 30 + (stats->SignalStrength * 70) / 100;
2228 //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal); 2153 //stats->signal = ieee80211_SignalStrengthTranslate(stats->signal);
2229 stats->noise = ieee80211_translate_todbm((u8)(100-stats->signal)) -25; 2154 stats->noise = ieee80211_translate_todbm((u8)(100 - stats->signal)) - 25;
2230 2155
2231 memcpy(&network->stats, stats, sizeof(network->stats)); 2156 memcpy(&network->stats, stats, sizeof(network->stats));
2232 2157
@@ -2264,8 +2189,7 @@ static inline void update_network(struct ieee80211_network *dst,
2264 dst->rates_len = src->rates_len; 2189 dst->rates_len = src->rates_len;
2265 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len); 2190 memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
2266 dst->rates_ex_len = src->rates_ex_len; 2191 dst->rates_ex_len = src->rates_ex_len;
2267 if (src->ssid_len > 0) 2192 if (src->ssid_len > 0) {
2268 {
2269 memset(dst->ssid, 0, dst->ssid_len); 2193 memset(dst->ssid, 0, dst->ssid_len);
2270 dst->ssid_len = src->ssid_len; 2194 dst->ssid_len = src->ssid_len;
2271 memcpy(dst->ssid, src->ssid, src->ssid_len); 2195 memcpy(dst->ssid, src->ssid, src->ssid_len);
@@ -2274,8 +2198,7 @@ static inline void update_network(struct ieee80211_network *dst,
2274 dst->flags = src->flags; 2198 dst->flags = src->flags;
2275 dst->time_stamp[0] = src->time_stamp[0]; 2199 dst->time_stamp[0] = src->time_stamp[0];
2276 dst->time_stamp[1] = src->time_stamp[1]; 2200 dst->time_stamp[1] = src->time_stamp[1];
2277 if (src->flags & NETWORK_HAS_ERP_VALUE) 2201 if (src->flags & NETWORK_HAS_ERP_VALUE) {
2278 {
2279 dst->erp_value = src->erp_value; 2202 dst->erp_value = src->erp_value;
2280 dst->berp_info_valid = src->berp_info_valid = true; 2203 dst->berp_info_valid = src->berp_info_valid = true;
2281 } 2204 }
@@ -2290,10 +2213,10 @@ static inline void update_network(struct ieee80211_network *dst,
2290 2213
2291 dst->bssht.bdSupportHT = src->bssht.bdSupportHT; 2214 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
2292 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation; 2215 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
2293 dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen; 2216 dst->bssht.bdHTCapLen = src->bssht.bdHTCapLen;
2294 memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen); 2217 memcpy(dst->bssht.bdHTCapBuf, src->bssht.bdHTCapBuf, src->bssht.bdHTCapLen);
2295 dst->bssht.bdHTInfoLen= src->bssht.bdHTInfoLen; 2218 dst->bssht.bdHTInfoLen = src->bssht.bdHTInfoLen;
2296 memcpy(dst->bssht.bdHTInfoBuf,src->bssht.bdHTInfoBuf,src->bssht.bdHTInfoLen); 2219 memcpy(dst->bssht.bdHTInfoBuf, src->bssht.bdHTInfoBuf, src->bssht.bdHTInfoLen);
2297 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer; 2220 dst->bssht.bdHTSpecVer = src->bssht.bdHTSpecVer;
2298 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime; 2221 dst->bssht.bdRT2RTLongSlotTime = src->bssht.bdRT2RTLongSlotTime;
2299 dst->broadcom_cap_exist = src->broadcom_cap_exist; 2222 dst->broadcom_cap_exist = src->broadcom_cap_exist;
@@ -2312,7 +2235,7 @@ static inline void update_network(struct ieee80211_network *dst,
2312 qos_active = dst->qos_data.active; 2235 qos_active = dst->qos_data.active;
2313 //old_param = dst->qos_data.old_param_count; 2236 //old_param = dst->qos_data.old_param_count;
2314 old_param = dst->qos_data.param_count; 2237 old_param = dst->qos_data.param_count;
2315 if(dst->flags & NETWORK_HAS_QOS_MASK) 2238 if (dst->flags & NETWORK_HAS_QOS_MASK)
2316 memcpy(&dst->qos_data, &src->qos_data, 2239 memcpy(&dst->qos_data, &src->qos_data,
2317 sizeof(struct ieee80211_qos_data)); 2240 sizeof(struct ieee80211_qos_data));
2318 else { 2241 else {
@@ -2322,7 +2245,7 @@ static inline void update_network(struct ieee80211_network *dst,
2322 2245
2323 if (dst->qos_data.supported == 1) { 2246 if (dst->qos_data.supported == 1) {
2324 dst->QoS_Enable = 1; 2247 dst->QoS_Enable = 1;
2325 if(dst->ssid_len) 2248 if (dst->ssid_len)
2326 IEEE80211_DEBUG_QOS 2249 IEEE80211_DEBUG_QOS
2327 ("QoS the network %s is QoS supported\n", 2250 ("QoS the network %s is QoS supported\n",
2328 dst->ssid); 2251 dst->ssid);
@@ -2335,11 +2258,11 @@ static inline void update_network(struct ieee80211_network *dst,
2335 2258
2336 /* dst->last_associate is not overwritten */ 2259 /* dst->last_associate is not overwritten */
2337 dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame. 2260 dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame.
2338 if (src->wmm_param[0].aci_aifsn|| \ 2261 if (src->wmm_param[0].aci_aifsn || \
2339 src->wmm_param[1].aci_aifsn|| \ 2262 src->wmm_param[1].aci_aifsn || \
2340 src->wmm_param[2].aci_aifsn|| \ 2263 src->wmm_param[2].aci_aifsn || \
2341 src->wmm_param[3].aci_aifsn) { 2264 src->wmm_param[3].aci_aifsn) {
2342 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN); 2265 memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN);
2343 } 2266 }
2344 //dst->QoS_Enable = src->QoS_Enable; 2267 //dst->QoS_Enable = src->QoS_Enable;
2345#ifdef THOMAS_TURBO 2268#ifdef THOMAS_TURBO
@@ -2429,46 +2352,34 @@ static inline void ieee80211_process_probe_response(
2429 2352
2430 if (!is_legal_channel(ieee, network->channel)) 2353 if (!is_legal_channel(ieee, network->channel))
2431 goto out; 2354 goto out;
2432 if (ieee->bGlobalDomain) 2355 if (ieee->bGlobalDomain) {
2433 { 2356 if (fc == IEEE80211_STYPE_PROBE_RESP) {
2434 if (fc == IEEE80211_STYPE_PROBE_RESP) 2357 if (IS_COUNTRY_IE_VALID(ieee)) {
2435 { 2358 // Case 1: Country code
2436 // Case 1: Country code
2437 if(IS_COUNTRY_IE_VALID(ieee) )
2438 {
2439 if (!is_legal_channel(ieee, network->channel)) { 2359 if (!is_legal_channel(ieee, network->channel)) {
2440 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network->channel); 2360 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network->channel);
2441 goto out; 2361 goto out;
2442 } 2362 }
2443 } 2363 } else {
2444 // Case 2: No any country code. 2364 // Case 2: No any country code.
2445 else
2446 {
2447 // Filter over channel ch12~14 2365 // Filter over channel ch12~14
2448 if (network->channel > 11) 2366 if (network->channel > 11) {
2449 {
2450 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network->channel); 2367 printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network->channel);
2451 goto out; 2368 goto out;
2452 } 2369 }
2453 } 2370 }
2454 } 2371 } else {
2455 else 2372 if (IS_COUNTRY_IE_VALID(ieee)) {
2456 { 2373 // Case 1: Country code
2457 // Case 1: Country code
2458 if(IS_COUNTRY_IE_VALID(ieee) )
2459 {
2460 if (!is_legal_channel(ieee, network->channel)) { 2374 if (!is_legal_channel(ieee, network->channel)) {
2461 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network->channel); 2375 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n", network->channel);
2462 goto out; 2376 goto out;
2463 } 2377 }
2464 } 2378 } else {
2465 // Case 2: No any country code. 2379 // Case 2: No any country code.
2466 else
2467 {
2468 // Filter over channel ch12~14 2380 // Filter over channel ch12~14
2469 if (network->channel > 14) 2381 if (network->channel > 14) {
2470 { 2382 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n", network->channel);
2471 printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n",network->channel);
2472 goto out; 2383 goto out;
2473 } 2384 }
2474 } 2385 }
@@ -2490,19 +2401,17 @@ static inline void ieee80211_process_probe_response(
2490 if (is_same_network(&ieee->current_network, network, ieee)) { 2401 if (is_same_network(&ieee->current_network, network, ieee)) {
2491 update_network(&ieee->current_network, network); 2402 update_network(&ieee->current_network, network);
2492 if ((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G) 2403 if ((ieee->current_network.mode == IEEE_N_24G || ieee->current_network.mode == IEEE_G)
2493 && ieee->current_network.berp_info_valid){ 2404 && ieee->current_network.berp_info_valid){
2494 if(ieee->current_network.erp_value& ERP_UseProtection) 2405 if (ieee->current_network.erp_value & ERP_UseProtection)
2495 ieee->current_network.buseprotection = true; 2406 ieee->current_network.buseprotection = true;
2496 else 2407 else
2497 ieee->current_network.buseprotection = false; 2408 ieee->current_network.buseprotection = false;
2498 } 2409 }
2499 if(is_beacon(beacon->header.frame_ctl)) 2410 if (is_beacon(beacon->header.frame_ctl)) {
2500 { 2411 if (ieee->state == IEEE80211_LINKED)
2501 if(ieee->state == IEEE80211_LINKED)
2502 ieee->LinkDetectInfo.NumRecvBcnInPeriod++; 2412 ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
2503 } 2413 } else //hidden AP
2504 else //hidden AP 2414 network->flags = (~NETWORK_EMPTY_ESSID & network->flags) | (NETWORK_EMPTY_ESSID & ieee->current_network.flags);
2505 network->flags = (~NETWORK_EMPTY_ESSID & network->flags)|(NETWORK_EMPTY_ESSID & ieee->current_network.flags);
2506 } 2415 }
2507 2416
2508 list_for_each_entry(target, &ieee->network_list, list) { 2417 list_for_each_entry(target, &ieee->network_list, list) {
@@ -2543,8 +2452,8 @@ static inline void ieee80211_process_probe_response(
2543#endif 2452#endif
2544 memcpy(target, network, sizeof(*target)); 2453 memcpy(target, network, sizeof(*target));
2545 list_add_tail(&target->list, &ieee->network_list); 2454 list_add_tail(&target->list, &ieee->network_list);
2546 if(ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) 2455 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)
2547 ieee80211_softmac_new_net(ieee,network); 2456 ieee80211_softmac_new_net(ieee, network);
2548 } else { 2457 } else {
2549 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n", 2458 IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n",
2550 escape_essid(target->ssid, 2459 escape_essid(target->ssid,
@@ -2559,26 +2468,26 @@ static inline void ieee80211_process_probe_response(
2559 */ 2468 */
2560 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies); 2469 renew = !time_after(target->last_scanned + ieee->scan_age, jiffies);
2561 //YJ,add,080819,for hidden ap 2470 //YJ,add,080819,for hidden ap
2562 if(is_beacon(beacon->header.frame_ctl) == 0) 2471 if (is_beacon(beacon->header.frame_ctl) == 0)
2563 network->flags = (~NETWORK_EMPTY_ESSID & network->flags)|(NETWORK_EMPTY_ESSID & target->flags); 2472 network->flags = (~NETWORK_EMPTY_ESSID & network->flags) | (NETWORK_EMPTY_ESSID & target->flags);
2564 //if(strncmp(network->ssid, "linksys-c",9) == 0) 2473 //if(strncmp(network->ssid, "linksys-c",9) == 0)
2565 // printk("====>2 network->ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network->ssid, network->flags, target->ssid, target->flags); 2474 // printk("====>2 network->ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network->ssid, network->flags, target->ssid, target->flags);
2566 if(((network->flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \ 2475 if (((network->flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \
2567 && (((network->ssid_len > 0) && (strncmp(target->ssid, network->ssid, network->ssid_len)))\ 2476 && (((network->ssid_len > 0) && (strncmp(target->ssid, network->ssid, network->ssid_len)))\
2568 ||((ieee->current_network.ssid_len == network->ssid_len) && (strncmp(ieee->current_network.ssid, network->ssid, network->ssid_len) == 0) && (ieee->state == IEEE80211_NOLINK)))) 2477 || ((ieee->current_network.ssid_len == network->ssid_len) && (strncmp(ieee->current_network.ssid, network->ssid, network->ssid_len) == 0) && (ieee->state == IEEE80211_NOLINK))))
2569 renew = 1; 2478 renew = 1;
2570 //YJ,add,080819,for hidden ap,end 2479 //YJ,add,080819,for hidden ap,end
2571 2480
2572 update_network(target, network); 2481 update_network(target, network);
2573 if(renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)) 2482 if (renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE))
2574 ieee80211_softmac_new_net(ieee,network); 2483 ieee80211_softmac_new_net(ieee, network);
2575 } 2484 }
2576 2485
2577 spin_unlock_irqrestore(&ieee->lock, flags); 2486 spin_unlock_irqrestore(&ieee->lock, flags);
2578 if (is_beacon(beacon->header.frame_ctl) && is_same_network(&ieee->current_network, network, ieee) && \ 2487 if (is_beacon(beacon->header.frame_ctl) && is_same_network(&ieee->current_network, network, ieee) && \
2579 (ieee->state == IEEE80211_LINKED)) { 2488 (ieee->state == IEEE80211_LINKED)) {
2580 if (ieee->handle_beacon) 2489 if (ieee->handle_beacon)
2581 ieee->handle_beacon(ieee->dev,beacon,&ieee->current_network); 2490 ieee->handle_beacon(ieee->dev, beacon, &ieee->current_network);
2582 } 2491 }
2583 2492
2584out: 2493out:
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index e0da0900a4f7..33a6af7aad22 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -743,7 +743,6 @@ static struct sk_buff *ieee80211_probe_resp(struct ieee80211_device *ieee, u8 *d
743 if (ieee->short_slot && (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_SLOT)) 743 if (ieee->short_slot && (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_SLOT))
744 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT); 744 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
745 745
746 crypt = ieee->crypt[ieee->tx_keyidx];
747 if (encrypt) 746 if (encrypt)
748 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY); 747 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
749 748
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
index 4a8d16a45fc5..b1baaa18b129 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
@@ -42,8 +42,8 @@ int ieee80211_wx_set_freq(struct ieee80211_device *ieee, struct iw_request_info
42 42
43 /* if setting by freq convert to channel */ 43 /* if setting by freq convert to channel */
44 if (fwrq->e == 1) { 44 if (fwrq->e == 1) {
45 if ((fwrq->m >= (int) 2.412e8 && 45 if ((fwrq->m >= (int)2.412e8 &&
46 fwrq->m <= (int) 2.487e8)) { 46 fwrq->m <= (int)2.487e8)) {
47 int f = fwrq->m / 100000; 47 int f = fwrq->m / 100000;
48 int c = 0; 48 int c = 0;
49 49
@@ -92,7 +92,7 @@ int ieee80211_wx_get_freq(struct ieee80211_device *ieee,
92 if (ieee->current_network.channel == 0) 92 if (ieee->current_network.channel == 0)
93 return -1; 93 return -1;
94 /* NM 0.7.0 will not accept channel any more. */ 94 /* NM 0.7.0 will not accept channel any more. */
95 fwrq->m = ieee80211_wlan_frequencies[ieee->current_network.channel-1] * 100000; 95 fwrq->m = ieee80211_wlan_frequencies[ieee->current_network.channel - 1] * 100000;
96 fwrq->e = 1; 96 fwrq->e = 1;
97 /* fwrq->m = ieee->current_network.channel; */ 97 /* fwrq->m = ieee->current_network.channel; */
98 /* fwrq->e = 0; */ 98 /* fwrq->e = 0; */
@@ -220,7 +220,7 @@ int ieee80211_wx_set_rate(struct ieee80211_device *ieee,
220 220
221 u32 target_rate = wrqu->bitrate.value; 221 u32 target_rate = wrqu->bitrate.value;
222 222
223 ieee->rate = target_rate/100000; 223 ieee->rate = target_rate / 100000;
224 /* FIXME: we might want to limit rate also in management protocols. */ 224 /* FIXME: we might want to limit rate also in management protocols. */
225 return 0; 225 return 0;
226} 226}
@@ -415,9 +415,9 @@ int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
415 415
416 if (wrqu->essid.flags && wrqu->essid.length) { 416 if (wrqu->essid.flags && wrqu->essid.length) {
417 /* first flush current network.ssid */ 417 /* first flush current network.ssid */
418 len = ((wrqu->essid.length-1) < IW_ESSID_MAX_SIZE) ? (wrqu->essid.length-1) : IW_ESSID_MAX_SIZE; 418 len = ((wrqu->essid.length - 1) < IW_ESSID_MAX_SIZE) ? (wrqu->essid.length - 1) : IW_ESSID_MAX_SIZE;
419 strncpy(ieee->current_network.ssid, extra, len+1); 419 strncpy(ieee->current_network.ssid, extra, len + 1);
420 ieee->current_network.ssid_len = len+1; 420 ieee->current_network.ssid_len = len + 1;
421 ieee->ssid_set = 1; 421 ieee->ssid_set = 1;
422 } else { 422 } else {
423 ieee->ssid_set = 0; 423 ieee->ssid_set = 0;
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
index fc6eb97801e1..f0b6b8372f91 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
@@ -214,7 +214,8 @@ int ieee80211_encrypt_fragment(
214} 214}
215 215
216 216
217void ieee80211_txb_free(struct ieee80211_txb *txb) { 217void ieee80211_txb_free(struct ieee80211_txb *txb)
218{
218 //int i; 219 //int i;
219 if (unlikely(!txb)) 220 if (unlikely(!txb))
220 return; 221 return;
@@ -293,7 +294,7 @@ static void ieee80211_tx_query_agg_cap(struct ieee80211_device *ieee,
293 struct tx_ts_record *pTxTs = NULL; 294 struct tx_ts_record *pTxTs = NULL;
294 struct rtl_80211_hdr_1addr *hdr = (struct rtl_80211_hdr_1addr *)skb->data; 295 struct rtl_80211_hdr_1addr *hdr = (struct rtl_80211_hdr_1addr *)skb->data;
295 296
296 if (!pHTInfo->bCurrentHTSupport||!pHTInfo->bEnableHT) 297 if (!pHTInfo->bCurrentHTSupport || !pHTInfo->bEnableHT)
297 return; 298 return;
298 if (!IsQoSDataFrame(skb->data)) 299 if (!IsQoSDataFrame(skb->data))
299 return; 300 return;
@@ -301,13 +302,6 @@ static void ieee80211_tx_query_agg_cap(struct ieee80211_device *ieee,
301 if (is_multicast_ether_addr(hdr->addr1)) 302 if (is_multicast_ether_addr(hdr->addr1))
302 return; 303 return;
303 //check packet and mode later 304 //check packet and mode later
304#ifdef TO_DO_LIST
305 if (pTcb->PacketLength >= 4096)
306 return;
307 // For RTL819X, if pairwisekey = wep/tkip, we don't aggrregation.
308 if (!Adapter->HalFunc.GetNmodeSupportBySecCfgHandler(Adapter))
309 return;
310#endif
311 if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) { 305 if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) {
312 return; 306 return;
313 } 307 }
@@ -333,8 +327,7 @@ static void ieee80211_tx_query_agg_cap(struct ieee80211_device *ieee,
333 } 327 }
334 } 328 }
335FORCED_AGG_SETTING: 329FORCED_AGG_SETTING:
336 switch (pHTInfo->ForcedAMPDUMode ) 330 switch (pHTInfo->ForcedAMPDUMode) {
337 {
338 case HT_AGG_AUTO: 331 case HT_AGG_AUTO:
339 break; 332 break;
340 333
@@ -372,7 +365,7 @@ ieee80211_query_HTCapShortGI(struct ieee80211_device *ieee, struct cb_desc *tcb_
372 365
373 tcb_desc->bUseShortGI = false; 366 tcb_desc->bUseShortGI = false;
374 367
375 if (!pHTInfo->bCurrentHTSupport||!pHTInfo->bEnableHT) 368 if (!pHTInfo->bCurrentHTSupport || !pHTInfo->bEnableHT)
376 return; 369 return;
377 370
378 if (pHTInfo->bForcedShortGI) { 371 if (pHTInfo->bForcedShortGI) {
@@ -380,9 +373,9 @@ ieee80211_query_HTCapShortGI(struct ieee80211_device *ieee, struct cb_desc *tcb_
380 return; 373 return;
381 } 374 }
382 375
383 if ((pHTInfo->bCurBW40MHz==true) && pHTInfo->bCurShortGI40MHz) 376 if ((pHTInfo->bCurBW40MHz == true) && pHTInfo->bCurShortGI40MHz)
384 tcb_desc->bUseShortGI = true; 377 tcb_desc->bUseShortGI = true;
385 else if ((pHTInfo->bCurBW40MHz==false) && pHTInfo->bCurShortGI20MHz) 378 else if ((pHTInfo->bCurBW40MHz == false) && pHTInfo->bCurShortGI20MHz)
386 tcb_desc->bUseShortGI = true; 379 tcb_desc->bUseShortGI = true;
387} 380}
388 381
@@ -393,16 +386,16 @@ static void ieee80211_query_BandwidthMode(struct ieee80211_device *ieee,
393 386
394 tcb_desc->bPacketBW = false; 387 tcb_desc->bPacketBW = false;
395 388
396 if (!pHTInfo->bCurrentHTSupport||!pHTInfo->bEnableHT) 389 if (!pHTInfo->bCurrentHTSupport || !pHTInfo->bEnableHT)
397 return; 390 return;
398 391
399 if (tcb_desc->bMulticast || tcb_desc->bBroadcast) 392 if (tcb_desc->bMulticast || tcb_desc->bBroadcast)
400 return; 393 return;
401 394
402 if ((tcb_desc->data_rate & 0x80)==0) // If using legacy rate, it shall use 20MHz channel. 395 if ((tcb_desc->data_rate & 0x80) == 0) // If using legacy rate, it shall use 20MHz channel.
403 return; 396 return;
404 //BandWidthAutoSwitch is for auto switch to 20 or 40 in long distance 397 //BandWidthAutoSwitch is for auto switch to 20 or 40 in long distance
405 if(pHTInfo->bCurBW40MHz && pHTInfo->bCurTxBW40MHz && !ieee->bandwidth_auto_switch.bforced_tx20Mhz) 398 if (pHTInfo->bCurBW40MHz && pHTInfo->bCurTxBW40MHz && !ieee->bandwidth_auto_switch.bforced_tx20Mhz)
406 tcb_desc->bPacketBW = true; 399 tcb_desc->bPacketBW = true;
407 return; 400 return;
408} 401}
@@ -418,25 +411,21 @@ static void ieee80211_query_protectionmode(struct ieee80211_device *ieee,
418 tcb_desc->RTSSC = 0; // 20MHz: Don't care; 40MHz: Duplicate. 411 tcb_desc->RTSSC = 0; // 20MHz: Don't care; 40MHz: Duplicate.
419 tcb_desc->bRTSBW = false; // RTS frame bandwidth is always 20MHz 412 tcb_desc->bRTSBW = false; // RTS frame bandwidth is always 20MHz
420 413
421 if(tcb_desc->bBroadcast || tcb_desc->bMulticast)//only unicast frame will use rts/cts 414 if (tcb_desc->bBroadcast || tcb_desc->bMulticast) //only unicast frame will use rts/cts
422 return; 415 return;
423 416
424 if (is_broadcast_ether_addr(skb->data+16)) //check addr3 as infrastructure add3 is DA. 417 if (is_broadcast_ether_addr(skb->data + 16)) //check addr3 as infrastructure add3 is DA.
425 return; 418 return;
426 419
427 if (ieee->mode < IEEE_N_24G) //b, g mode 420 if (ieee->mode < IEEE_N_24G) /* b, g mode */ {
428 {
429 // (1) RTS_Threshold is compared to the MPDU, not MSDU. 421 // (1) RTS_Threshold is compared to the MPDU, not MSDU.
430 // (2) If there are more than one frag in this MSDU, only the first frag uses protection frame. 422 // (2) If there are more than one frag in this MSDU, only the first frag uses protection frame.
431 // Other fragments are protected by previous fragment. 423 // Other fragments are protected by previous fragment.
432 // So we only need to check the length of first fragment. 424 // So we only need to check the length of first fragment.
433 if (skb->len > ieee->rts) 425 if (skb->len > ieee->rts) {
434 {
435 tcb_desc->bRTSEnable = true; 426 tcb_desc->bRTSEnable = true;
436 tcb_desc->rts_rate = MGN_24M; 427 tcb_desc->rts_rate = MGN_24M;
437 } 428 } else if (ieee->current_network.buseprotection) {
438 else if (ieee->current_network.buseprotection)
439 {
440 // Use CTS-to-SELF in protection mode. 429 // Use CTS-to-SELF in protection mode.
441 tcb_desc->bRTSEnable = true; 430 tcb_desc->bRTSEnable = true;
442 tcb_desc->bCTSEnable = true; 431 tcb_desc->bCTSEnable = true;
@@ -444,43 +433,35 @@ static void ieee80211_query_protectionmode(struct ieee80211_device *ieee,
444 } 433 }
445 //otherwise return; 434 //otherwise return;
446 return; 435 return;
447 } 436 } else { // 11n High throughput case.
448 else
449 {// 11n High throughput case.
450 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 437 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
451 while (true) 438 while (true) {
452 {
453 //check ERP protection 439 //check ERP protection
454 if (ieee->current_network.buseprotection) 440 if (ieee->current_network.buseprotection) {// CTS-to-SELF
455 {// CTS-to-SELF
456 tcb_desc->bRTSEnable = true; 441 tcb_desc->bRTSEnable = true;
457 tcb_desc->bCTSEnable = true; 442 tcb_desc->bCTSEnable = true;
458 tcb_desc->rts_rate = MGN_24M; 443 tcb_desc->rts_rate = MGN_24M;
459 break; 444 break;
460 } 445 }
461 //check HT op mode 446 //check HT op mode
462 if(pHTInfo->bCurrentHTSupport && pHTInfo->bEnableHT) 447 if (pHTInfo->bCurrentHTSupport && pHTInfo->bEnableHT) {
463 {
464 u8 HTOpMode = pHTInfo->CurrentOpMode; 448 u8 HTOpMode = pHTInfo->CurrentOpMode;
465 if((pHTInfo->bCurBW40MHz && (HTOpMode == 2 || HTOpMode == 3)) || 449 if ((pHTInfo->bCurBW40MHz && (HTOpMode == 2 || HTOpMode == 3)) ||
466 (!pHTInfo->bCurBW40MHz && HTOpMode == 3) ) 450 (!pHTInfo->bCurBW40MHz && HTOpMode == 3)) {
467 {
468 tcb_desc->rts_rate = MGN_24M; // Rate is 24Mbps. 451 tcb_desc->rts_rate = MGN_24M; // Rate is 24Mbps.
469 tcb_desc->bRTSEnable = true; 452 tcb_desc->bRTSEnable = true;
470 break; 453 break;
471 } 454 }
472 } 455 }
473 //check rts 456 //check rts
474 if (skb->len > ieee->rts) 457 if (skb->len > ieee->rts) {
475 {
476 tcb_desc->rts_rate = MGN_24M; // Rate is 24Mbps. 458 tcb_desc->rts_rate = MGN_24M; // Rate is 24Mbps.
477 tcb_desc->bRTSEnable = true; 459 tcb_desc->bRTSEnable = true;
478 break; 460 break;
479 } 461 }
480 //to do list: check MIMO power save condition. 462 //to do list: check MIMO power save condition.
481 //check AMPDU aggregation for TXOP 463 //check AMPDU aggregation for TXOP
482 if(tcb_desc->bAMPDUEnable) 464 if (tcb_desc->bAMPDUEnable) {
483 {
484 tcb_desc->rts_rate = MGN_24M; // Rate is 24Mbps. 465 tcb_desc->rts_rate = MGN_24M; // Rate is 24Mbps.
485 // According to 8190 design, firmware sends CF-End only if RTS/CTS is enabled. However, it degrads 466 // According to 8190 design, firmware sends CF-End only if RTS/CTS is enabled. However, it degrads
486 // throughput around 10M, so we disable of this mechanism. 2007.08.03 by Emily 467 // throughput around 10M, so we disable of this mechanism. 2007.08.03 by Emily
@@ -488,8 +469,7 @@ static void ieee80211_query_protectionmode(struct ieee80211_device *ieee,
488 break; 469 break;
489 } 470 }
490 //check IOT action 471 //check IOT action
491 if(pHTInfo->IOTAction & HT_IOT_ACT_FORCED_CTS2SELF) 472 if (pHTInfo->IOTAction & HT_IOT_ACT_FORCED_CTS2SELF) {
492 {
493 tcb_desc->bCTSEnable = true; 473 tcb_desc->bCTSEnable = true;
494 tcb_desc->rts_rate = MGN_24M; 474 tcb_desc->rts_rate = MGN_24M;
495 tcb_desc->bRTSEnable = true; 475 tcb_desc->bRTSEnable = true;
@@ -508,7 +488,7 @@ static void ieee80211_query_protectionmode(struct ieee80211_device *ieee,
508 if (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_PREAMBLE) 488 if (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
509 tcb_desc->bUseShortPreamble = true; 489 tcb_desc->bUseShortPreamble = true;
510 if (ieee->mode == IW_MODE_MASTER) 490 if (ieee->mode == IW_MODE_MASTER)
511 goto NO_PROTECTION; 491 goto NO_PROTECTION;
512 return; 492 return;
513NO_PROTECTION: 493NO_PROTECTION:
514 tcb_desc->bRTSEnable = false; 494 tcb_desc->bRTSEnable = false;
@@ -522,27 +502,12 @@ NO_PROTECTION:
522static void ieee80211_txrate_selectmode(struct ieee80211_device *ieee, 502static void ieee80211_txrate_selectmode(struct ieee80211_device *ieee,
523 struct cb_desc *tcb_desc) 503 struct cb_desc *tcb_desc)
524{ 504{
525#ifdef TO_DO_LIST
526 if (!IsDataFrame(pFrame)) {
527 pTcb->bTxDisableRateFallBack = true;
528 pTcb->bTxUseDriverAssingedRate = true;
529 pTcb->RATRIndex = 7;
530 return;
531 }
532
533 if (pMgntInfo->ForcedDataRate!= 0) {
534 pTcb->bTxDisableRateFallBack = true;
535 pTcb->bTxUseDriverAssingedRate = true;
536 return;
537 }
538#endif
539 if (ieee->bTxDisableRateFallBack) 505 if (ieee->bTxDisableRateFallBack)
540 tcb_desc->bTxDisableRateFallBack = true; 506 tcb_desc->bTxDisableRateFallBack = true;
541 507
542 if (ieee->bTxUseDriverAssingedRate) 508 if (ieee->bTxUseDriverAssingedRate)
543 tcb_desc->bTxUseDriverAssingedRate = true; 509 tcb_desc->bTxUseDriverAssingedRate = true;
544 if (!tcb_desc->bTxDisableRateFallBack || !tcb_desc->bTxUseDriverAssingedRate) 510 if (!tcb_desc->bTxDisableRateFallBack || !tcb_desc->bTxUseDriverAssingedRate) {
545 {
546 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) 511 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC)
547 tcb_desc->RATRIndex = 0; 512 tcb_desc->RATRIndex = 0;
548 } 513 }
@@ -553,11 +518,9 @@ static void ieee80211_query_seqnum(struct ieee80211_device *ieee,
553{ 518{
554 if (is_multicast_ether_addr(dst)) 519 if (is_multicast_ether_addr(dst))
555 return; 520 return;
556 if (IsQoSDataFrame(skb->data)) //we deal qos data only 521 if (IsQoSDataFrame(skb->data)) /* we deal qos data only */ {
557 {
558 struct tx_ts_record *pTS = NULL; 522 struct tx_ts_record *pTS = NULL;
559 if (!GetTs(ieee, (struct ts_common_info **)(&pTS), dst, skb->priority, TX_DIR, true)) 523 if (!GetTs(ieee, (struct ts_common_info **)(&pTS), dst, skb->priority, TX_DIR, true)) {
560 {
561 return; 524 return;
562 } 525 }
563 pTS->tx_cur_seq = (pTS->tx_cur_seq + 1) % 4096; 526 pTS->tx_cur_seq = (pTS->tx_cur_seq + 1) % 4096;
@@ -592,7 +555,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
592 /* If there is no driver handler to take the TXB, dont' bother 555 /* If there is no driver handler to take the TXB, dont' bother
593 * creating it... 556 * creating it...
594 */ 557 */
595 if ((!ieee->hard_start_xmit && !(ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE))|| 558 if ((!ieee->hard_start_xmit && !(ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)) ||
596 ((!ieee->softmac_data_hard_start_xmit && (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)))) { 559 ((!ieee->softmac_data_hard_start_xmit && (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)))) {
597 printk(KERN_WARNING "%s: No xmit handler.\n", 560 printk(KERN_WARNING "%s: No xmit handler.\n",
598 ieee->dev->name); 561 ieee->dev->name);
@@ -631,7 +594,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
631 594
632 /* Save source and destination addresses */ 595 /* Save source and destination addresses */
633 memcpy(&dest, skb->data, ETH_ALEN); 596 memcpy(&dest, skb->data, ETH_ALEN);
634 memcpy(&src, skb->data+ETH_ALEN, ETH_ALEN); 597 memcpy(&src, skb->data + ETH_ALEN, ETH_ALEN);
635 598
636 /* Advance the SKB to the start of the payload */ 599 /* Advance the SKB to the start of the payload */
637 skb_pull(skb, sizeof(struct ethhdr)); 600 skb_pull(skb, sizeof(struct ethhdr));
@@ -646,7 +609,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
646 fc = IEEE80211_FTYPE_DATA; 609 fc = IEEE80211_FTYPE_DATA;
647 610
648 //if(ieee->current_network.QoS_Enable) 611 //if(ieee->current_network.QoS_Enable)
649 if(qos_actived) 612 if (qos_actived)
650 fc |= IEEE80211_STYPE_QOS_DATA; 613 fc |= IEEE80211_STYPE_QOS_DATA;
651 else 614 else
652 fc |= IEEE80211_STYPE_DATA; 615 fc |= IEEE80211_STYPE_DATA;
@@ -740,7 +703,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
740 for (i = 0; i < nr_frags; i++) { 703 for (i = 0; i < nr_frags; i++) {
741 skb_frag = txb->fragments[i]; 704 skb_frag = txb->fragments[i];
742 tcb_desc = (struct cb_desc *)(skb_frag->cb + MAX_DEV_ADDR_SIZE); 705 tcb_desc = (struct cb_desc *)(skb_frag->cb + MAX_DEV_ADDR_SIZE);
743 if(qos_actived){ 706 if (qos_actived) {
744 skb_frag->priority = skb->priority;//UP2AC(skb->priority); 707 skb_frag->priority = skb->priority;//UP2AC(skb->priority);
745 tcb_desc->queue_index = UP2AC(skb->priority); 708 tcb_desc->queue_index = UP2AC(skb->priority);
746 } else { 709 } else {
@@ -749,15 +712,13 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
749 } 712 }
750 skb_reserve(skb_frag, ieee->tx_headroom); 713 skb_reserve(skb_frag, ieee->tx_headroom);
751 714
752 if (encrypt){ 715 if (encrypt) {
753 if (ieee->hwsec_active) 716 if (ieee->hwsec_active)
754 tcb_desc->bHwSec = 1; 717 tcb_desc->bHwSec = 1;
755 else 718 else
756 tcb_desc->bHwSec = 0; 719 tcb_desc->bHwSec = 0;
757 skb_reserve(skb_frag, crypt->ops->extra_prefix_len); 720 skb_reserve(skb_frag, crypt->ops->extra_prefix_len);
758 } 721 } else {
759 else
760 {
761 tcb_desc->bHwSec = 0; 722 tcb_desc->bHwSec = 0;
762 } 723 }
763 frag_hdr = skb_put_data(skb_frag, &header, hdr_len); 724 frag_hdr = skb_put_data(skb_frag, &header, hdr_len);
@@ -775,12 +736,11 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
775 bytes = bytes_last_frag; 736 bytes = bytes_last_frag;
776 } 737 }
777 //if(ieee->current_network.QoS_Enable) 738 //if(ieee->current_network.QoS_Enable)
778 if(qos_actived) 739 if (qos_actived) {
779 {
780 // add 1 only indicate to corresponding seq number control 2006/7/12 740 // add 1 only indicate to corresponding seq number control 2006/7/12
781 frag_hdr->seq_ctl = cpu_to_le16(ieee->seq_ctrl[UP2AC(skb->priority)+1]<<4 | i); 741 frag_hdr->seq_ctl = cpu_to_le16(ieee->seq_ctrl[UP2AC(skb->priority) + 1] << 4 | i);
782 } else { 742 } else {
783 frag_hdr->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0]<<4 | i); 743 frag_hdr->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4 | i);
784 } 744 }
785 745
786 /* Put a SNAP header on the first fragment */ 746 /* Put a SNAP header on the first fragment */
@@ -806,17 +766,16 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
806 skb_put(skb_frag, 4); 766 skb_put(skb_frag, 4);
807 } 767 }
808 768
809 if(qos_actived) 769 if (qos_actived) {
810 { 770 if (ieee->seq_ctrl[UP2AC(skb->priority) + 1] == 0xFFF)
811 if (ieee->seq_ctrl[UP2AC(skb->priority) + 1] == 0xFFF) 771 ieee->seq_ctrl[UP2AC(skb->priority) + 1] = 0;
812 ieee->seq_ctrl[UP2AC(skb->priority) + 1] = 0; 772 else
813 else 773 ieee->seq_ctrl[UP2AC(skb->priority) + 1]++;
814 ieee->seq_ctrl[UP2AC(skb->priority) + 1]++;
815 } else { 774 } else {
816 if (ieee->seq_ctrl[0] == 0xFFF) 775 if (ieee->seq_ctrl[0] == 0xFFF)
817 ieee->seq_ctrl[0] = 0; 776 ieee->seq_ctrl[0] = 0;
818 else 777 else
819 ieee->seq_ctrl[0]++; 778 ieee->seq_ctrl[0]++;
820 } 779 }
821 } else { 780 } else {
822 if (unlikely(skb->len < sizeof(struct rtl_80211_hdr_3addr))) { 781 if (unlikely(skb->len < sizeof(struct rtl_80211_hdr_3addr))) {
@@ -826,7 +785,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
826 } 785 }
827 786
828 txb = ieee80211_alloc_txb(1, skb->len, GFP_ATOMIC); 787 txb = ieee80211_alloc_txb(1, skb->len, GFP_ATOMIC);
829 if(!txb){ 788 if (!txb) {
830 printk(KERN_WARNING "%s: Could not allocate TXB\n", 789 printk(KERN_WARNING "%s: Could not allocate TXB\n",
831 ieee->dev->name); 790 ieee->dev->name);
832 goto failed; 791 goto failed;
@@ -839,8 +798,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
839 798
840 success: 799 success:
841//WB add to fill data tcb_desc here. only first fragment is considered, need to change, and you may remove to other place. 800//WB add to fill data tcb_desc here. only first fragment is considered, need to change, and you may remove to other place.
842 if (txb) 801 if (txb) {
843 {
844 struct cb_desc *tcb_desc = (struct cb_desc *)(txb->fragments[0]->cb + MAX_DEV_ADDR_SIZE); 802 struct cb_desc *tcb_desc = (struct cb_desc *)(txb->fragments[0]->cb + MAX_DEV_ADDR_SIZE);
845 tcb_desc->bTxEnableFwCalcDur = 1; 803 tcb_desc->bTxEnableFwCalcDur = 1;
846 if (is_multicast_ether_addr(header.addr1)) 804 if (is_multicast_ether_addr(header.addr1))
@@ -862,9 +820,9 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
862 spin_unlock_irqrestore(&ieee->lock, flags); 820 spin_unlock_irqrestore(&ieee->lock, flags);
863 dev_kfree_skb_any(skb); 821 dev_kfree_skb_any(skb);
864 if (txb) { 822 if (txb) {
865 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE){ 823 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE) {
866 ieee80211_softmac_xmit(txb, ieee); 824 ieee80211_softmac_xmit(txb, ieee);
867 }else{ 825 } else {
868 if ((*ieee->hard_start_xmit)(txb, dev) == 0) { 826 if ((*ieee->hard_start_xmit)(txb, dev) == 0) {
869 stats->tx_packets++; 827 stats->tx_packets++;
870 stats->tx_bytes += __le16_to_cpu(txb->payload_size); 828 stats->tx_bytes += __le16_to_cpu(txb->payload_size);
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
index be08cd1d37a7..9dd5c04181ea 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
@@ -70,10 +70,10 @@ static inline char *rtl819x_translate_scan(struct ieee80211_device *ieee,
70 } 70 }
71 /* Add the protocol name */ 71 /* Add the protocol name */
72 iwe.cmd = SIOCGIWNAME; 72 iwe.cmd = SIOCGIWNAME;
73 for(i=0; i<ARRAY_SIZE(ieee80211_modes); i++) { 73 for (i = 0; i < ARRAY_SIZE(ieee80211_modes); i++) {
74 if (network->mode & BIT(i)) { 74 if (network->mode & BIT(i)) {
75 sprintf(pname,ieee80211_modes[i].mode_string,ieee80211_modes[i].mode_size); 75 sprintf(pname, ieee80211_modes[i].mode_string, ieee80211_modes[i].mode_size);
76 pname +=ieee80211_modes[i].mode_size; 76 pname += ieee80211_modes[i].mode_size;
77 } 77 }
78 } 78 }
79 *pname = '\0'; 79 *pname = '\0';
@@ -130,8 +130,7 @@ static inline char *rtl819x_translate_scan(struct ieee80211_device *ieee,
130 max_rate = rate; 130 max_rate = rate;
131 } 131 }
132 132
133 if (network->mode >= IEEE_N_24G)//add N rate here; 133 if (network->mode >= IEEE_N_24G) /* add N rate here */ {
134 {
135 struct ht_capability_ele *ht_cap = NULL; 134 struct ht_capability_ele *ht_cap = NULL;
136 bool is40M = false, isShortGI = false; 135 bool is40M = false, isShortGI = false;
137 u8 max_mcs = 0; 136 u8 max_mcs = 0;
@@ -139,13 +138,13 @@ static inline char *rtl819x_translate_scan(struct ieee80211_device *ieee,
139 ht_cap = (struct ht_capability_ele *)&network->bssht.bdHTCapBuf[4]; 138 ht_cap = (struct ht_capability_ele *)&network->bssht.bdHTCapBuf[4];
140 else 139 else
141 ht_cap = (struct ht_capability_ele *)&network->bssht.bdHTCapBuf[0]; 140 ht_cap = (struct ht_capability_ele *)&network->bssht.bdHTCapBuf[0];
142 is40M = (ht_cap->ChlWidth)?1:0; 141 is40M = (ht_cap->ChlWidth) ? 1 : 0;
143 isShortGI = (ht_cap->ChlWidth)? 142 isShortGI = (ht_cap->ChlWidth) ?
144 ((ht_cap->ShortGI40Mhz)?1:0): 143 ((ht_cap->ShortGI40Mhz) ? 1 : 0) :
145 ((ht_cap->ShortGI20Mhz)?1:0); 144 ((ht_cap->ShortGI20Mhz) ? 1 : 0);
146 145
147 max_mcs = HTGetHighestMCSRate(ieee, ht_cap->MCS, MCS_FILTER_ALL); 146 max_mcs = HTGetHighestMCSRate(ieee, ht_cap->MCS, MCS_FILTER_ALL);
148 rate = MCS_DATA_RATE[is40M][isShortGI][max_mcs&0x7f]; 147 rate = MCS_DATA_RATE[is40M][isShortGI][max_mcs & 0x7f];
149 if (rate > max_rate) 148 if (rate > max_rate)
150 max_rate = rate; 149 max_rate = rate;
151 } 150 }
@@ -178,7 +177,7 @@ static inline char *rtl819x_translate_scan(struct ieee80211_device *ieee,
178 177
179 iwe.u.data.length = p - custom; 178 iwe.u.data.length = p - custom;
180 if (iwe.u.data.length) 179 if (iwe.u.data.length)
181 start = iwe_stream_add_point(info, start, stop, &iwe, custom); 180 start = iwe_stream_add_point(info, start, stop, &iwe, custom);
182 181
183 if (ieee->wpa_enabled && network->wpa_ie_len) { 182 if (ieee->wpa_enabled && network->wpa_ie_len) {
184 char buf[MAX_WPA_IE_LEN * 2 + 30]; 183 char buf[MAX_WPA_IE_LEN * 2 + 30];
@@ -219,7 +218,7 @@ static inline char *rtl819x_translate_scan(struct ieee80211_device *ieee,
219 " Last beacon: %lums ago", (jiffies - network->last_scanned) / (HZ / 100)); 218 " Last beacon: %lums ago", (jiffies - network->last_scanned) / (HZ / 100));
220 iwe.u.data.length = p - custom; 219 iwe.u.data.length = p - custom;
221 if (iwe.u.data.length) 220 if (iwe.u.data.length)
222 start = iwe_stream_add_point(info, start, stop, &iwe, custom); 221 start = iwe_stream_add_point(info, start, stop, &iwe, custom);
223 222
224 return start; 223 return start;
225} 224}
@@ -243,7 +242,7 @@ int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
243 242
244 list_for_each_entry(network, &ieee->network_list, list) { 243 list_for_each_entry(network, &ieee->network_list, list) {
245 i++; 244 i++;
246 if((stop-ev)<200) { 245 if ((stop - ev) < 200) {
247 err = -E2BIG; 246 err = -E2BIG;
248 break; 247 break;
249 } 248 }
@@ -454,7 +453,7 @@ int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
454 453
455 IEEE80211_DEBUG_WX("GET_ENCODE\n"); 454 IEEE80211_DEBUG_WX("GET_ENCODE\n");
456 455
457 if(ieee->iw_mode == IW_MODE_MONITOR) 456 if (ieee->iw_mode == IW_MODE_MONITOR)
458 return -1; 457 return -1;
459 458
460 key = erq->flags & IW_ENCODE_INDEX; 459 key = erq->flags & IW_ENCODE_INDEX;
@@ -571,7 +570,7 @@ int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
571 ret = -EINVAL; 570 ret = -EINVAL;
572 goto done; 571 goto done;
573 } 572 }
574 printk("alg name:%s\n",alg); 573 printk("alg name:%s\n", alg);
575 574
576 ops = try_then_request_module(ieee80211_get_crypto_ops(alg), module); 575 ops = try_then_request_module(ieee80211_get_crypto_ops(alg), module);
577 if (!ops) { 576 if (!ops) {
@@ -688,7 +687,7 @@ int ieee80211_wx_get_encode_ext(struct ieee80211_device *ieee,
688 ext->key_len = 0; 687 ext->key_len = 0;
689 encoding->flags |= IW_ENCODE_DISABLED; 688 encoding->flags |= IW_ENCODE_DISABLED;
690 } else { 689 } else {
691 if (strcmp(crypt->ops->name, "WEP") == 0 ) 690 if (strcmp(crypt->ops->name, "WEP") == 0)
692 ext->alg = IW_ENCODE_ALG_WEP; 691 ext->alg = IW_ENCODE_ALG_WEP;
693 else if (strcmp(crypt->ops->name, "TKIP")) 692 else if (strcmp(crypt->ops->name, "TKIP"))
694 ext->alg = IW_ENCODE_ALG_TKIP; 693 ext->alg = IW_ENCODE_ALG_TKIP;
@@ -712,7 +711,7 @@ int ieee80211_wx_set_mlme(struct ieee80211_device *ieee,
712 struct iw_request_info *info, 711 struct iw_request_info *info,
713 union iwreq_data *wrqu, char *extra) 712 union iwreq_data *wrqu, char *extra)
714{ 713{
715 struct iw_mlme *mlme = (struct iw_mlme *) extra; 714 struct iw_mlme *mlme = (struct iw_mlme *)extra;
716 switch (mlme->cmd) { 715 switch (mlme->cmd) {
717 case IW_MLME_DEAUTH: 716 case IW_MLME_DEAUTH:
718 case IW_MLME_DISASSOC: 717 case IW_MLME_DISASSOC:
@@ -765,7 +764,7 @@ int ieee80211_wx_set_auth(struct ieee80211_device *ieee,
765 break; 764 break;
766 765
767 case IW_AUTH_WPA_ENABLED: 766 case IW_AUTH_WPA_ENABLED:
768 ieee->wpa_enabled = (data->value)?1:0; 767 ieee->wpa_enabled = (data->value) ? 1 : 0;
769 break; 768 break;
770 769
771 case IW_AUTH_RX_UNENCRYPTED_EAPOL: 770 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
@@ -785,14 +784,14 @@ int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len)
785{ 784{
786 u8 *buf; 785 u8 *buf;
787 786
788 if (len>MAX_WPA_IE_LEN || (len && !ie)) { 787 if (len > MAX_WPA_IE_LEN || (len && !ie)) {
789 // printk("return error out, len:%d\n", len); 788 //printk("return error out, len:%d\n", len);
790 return -EINVAL; 789 return -EINVAL;
791 } 790 }
792 791
793 792
794 if (len) { 793 if (len) {
795 if (len != ie[1]+2) { 794 if (len != ie[1] + 2) {
796 printk("len:%zu, ie:%d\n", len, ie[1]); 795 printk("len:%zu, ie:%d\n", len, ie[1]);
797 return -EINVAL; 796 return -EINVAL;
798 } 797 }
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
index 53869b3c985c..379a2ccf4d9f 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
@@ -162,7 +162,7 @@ static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, s
162 tag += 2; 162 tag += 2;
163 } 163 }
164 164
165 IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len); 165 IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_BA, skb->data, skb->len);
166 return skb; 166 return skb;
167 //return NULL; 167 //return NULL;
168} 168}
@@ -229,7 +229,7 @@ static struct sk_buff *ieee80211_DELBA(
229 put_unaligned_le16(ReasonCode, tag); 229 put_unaligned_le16(ReasonCode, tag);
230 tag += 2; 230 tag += 2;
231 231
232 IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len); 232 IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_BA, skb->data, skb->len);
233 if (net_ratelimit()) 233 if (net_ratelimit())
234 IEEE80211_DEBUG(IEEE80211_DL_TRACE | IEEE80211_DL_BA, 234 IEEE80211_DEBUG(IEEE80211_DL_TRACE | IEEE80211_DL_BA,
235 "<=====%s()\n", __func__); 235 "<=====%s()\n", __func__);
@@ -331,9 +331,9 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb)
331 return -1; 331 return -1;
332 } 332 }
333 333
334 IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len); 334 IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_BA, skb->data, skb->len);
335 335
336 req = (struct rtl_80211_hdr_3addr *) skb->data; 336 req = (struct rtl_80211_hdr_3addr *)skb->data;
337 tag = (u8 *)req; 337 tag = (u8 *)req;
338 dst = &req->addr2[0]; 338 dst = &req->addr2[0];
339 tag += sizeof(struct rtl_80211_hdr_3addr); 339 tag += sizeof(struct rtl_80211_hdr_3addr);
@@ -556,7 +556,7 @@ int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb)
556 return -1; 556 return -1;
557 } 557 }
558 558
559 IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len); 559 IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_BA, skb->data, skb->len);
560 delba = (struct rtl_80211_hdr_3addr *)skb->data; 560 delba = (struct rtl_80211_hdr_3addr *)skb->data;
561 dst = &delba->addr2[0]; 561 dst = &delba->addr2[0];
562 pDelBaParamSet = (union delba_param_set *)&delba->payload[2]; 562 pDelBaParamSet = (union delba_param_set *)&delba->payload[2];
@@ -643,7 +643,7 @@ TsInitDelBA(struct ieee80211_device *ieee, struct ts_common_info *pTsCommonInfo,
643 ieee80211_send_DELBA( 643 ieee80211_send_DELBA(
644 ieee, 644 ieee,
645 pTsCommonInfo->addr, 645 pTsCommonInfo->addr,
646 (pTxTs->tx_admitted_ba_record.valid)?(&pTxTs->tx_admitted_ba_record):(&pTxTs->tx_pending_ba_record), 646 (pTxTs->tx_admitted_ba_record.valid) ? (&pTxTs->tx_admitted_ba_record) : (&pTxTs->tx_pending_ba_record),
647 TxRxSelect, 647 TxRxSelect,
648 DELBA_REASON_END_BA); 648 DELBA_REASON_END_BA);
649 } else if (TxRxSelect == RX_DIR) { 649 } else if (TxRxSelect == RX_DIR) {
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h
index b7769bca9740..79346a00af09 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h
@@ -253,10 +253,10 @@ extern u8 MCS_FILTER_1SS[16];
253/* 2007/07/12 MH We only define legacy and HT wireless mode now. */ 253/* 2007/07/12 MH We only define legacy and HT wireless mode now. */
254#define LEGACY_WIRELESS_MODE IEEE_MODE_MASK 254#define LEGACY_WIRELESS_MODE IEEE_MODE_MASK
255 255
256#define CURRENT_RATE(WirelessMode, LegacyRate, HTRate) \ 256#define CURRENT_RATE(WirelessMode, LegacyRate, HTRate) \
257 ((WirelessMode & (LEGACY_WIRELESS_MODE)) != 0) ?\ 257 ((WirelessMode & (LEGACY_WIRELESS_MODE)) != 0) ? \
258 (LegacyRate) :\ 258 (LegacyRate) : \
259 (PICK_RATE(LegacyRate, HTRate)) 259 (PICK_RATE(LegacyRate, HTRate))
260 260
261// MCS Bw 40 {1~7, 12~15,32} 261// MCS Bw 40 {1~7, 12~15,32}
262#define RATE_ADPT_1SS_MASK 0xFF 262#define RATE_ADPT_1SS_MASK 0xFF
@@ -270,11 +270,10 @@ typedef enum _HT_AGGRE_SIZE {
270 HT_AGG_SIZE_16K = 1, 270 HT_AGG_SIZE_16K = 1,
271 HT_AGG_SIZE_32K = 2, 271 HT_AGG_SIZE_32K = 2,
272 HT_AGG_SIZE_64K = 3, 272 HT_AGG_SIZE_64K = 3,
273}HT_AGGRE_SIZE_E, *PHT_AGGRE_SIZE_E; 273} HT_AGGRE_SIZE_E, *PHT_AGGRE_SIZE_E;
274 274
275/* Indicate different AP vendor for IOT issue */ 275/* Indicate different AP vendor for IOT issue */
276typedef enum _HT_IOT_PEER 276typedef enum _HT_IOT_PEER {
277{
278 HT_IOT_PEER_UNKNOWN = 0, 277 HT_IOT_PEER_UNKNOWN = 0,
279 HT_IOT_PEER_REALTEK = 1, 278 HT_IOT_PEER_REALTEK = 1,
280 HT_IOT_PEER_BROADCOM = 2, 279 HT_IOT_PEER_BROADCOM = 2,
@@ -282,7 +281,7 @@ typedef enum _HT_IOT_PEER
282 HT_IOT_PEER_ATHEROS = 4, 281 HT_IOT_PEER_ATHEROS = 4,
283 HT_IOT_PEER_CISCO = 5, 282 HT_IOT_PEER_CISCO = 5,
284 HT_IOT_PEER_MAX = 6 283 HT_IOT_PEER_MAX = 6
285}HT_IOT_PEER_E, *PHTIOT_PEER_E; 284} HT_IOT_PEER_E, *PHTIOT_PEER_E;
286 285
287/* 286/*
288 * IOT Action for different AP 287 * IOT Action for different AP
@@ -298,6 +297,6 @@ typedef enum _HT_IOT_ACTION {
298 HT_IOT_ACT_CDD_FSYNC = 0x00000080, 297 HT_IOT_ACT_CDD_FSYNC = 0x00000080,
299 HT_IOT_ACT_PURE_N_MODE = 0x00000100, 298 HT_IOT_ACT_PURE_N_MODE = 0x00000100,
300 HT_IOT_ACT_FORCED_CTS2SELF = 0x00000200, 299 HT_IOT_ACT_FORCED_CTS2SELF = 0x00000200,
301}HT_IOT_ACTION_E, *PHT_IOT_ACTION_E; 300} HT_IOT_ACTION_E, *PHT_IOT_ACTION_E;
302 301
303#endif //_RTL819XU_HTTYPE_H_ 302#endif //_RTL819XU_HTTYPE_H_
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
index c73a8058cf87..dba3f2db9f48 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
@@ -93,10 +93,6 @@ void HTUpdateDefaultSetting(struct ieee80211_device *ieee)
93 ieee->bTxDisableRateFallBack = 0; 93 ieee->bTxDisableRateFallBack = 0;
94 ieee->bTxUseDriverAssingedRate = 0; 94 ieee->bTxUseDriverAssingedRate = 0;
95 95
96#ifdef TO_DO_LIST
97 // 8190 only. Assign duration operation mode to firmware
98 pMgntInfo->bTxEnableFwCalcDur = (BOOLEAN)pNdisCommon->bRegTxEnableFwCalcDur;
99#endif
100 /* 96 /*
101 * 8190 only, Realtek proprietary aggregation mode 97 * 8190 only, Realtek proprietary aggregation mode
102 * Set MPDUDensity=2, 1: Set MPDUDensity=2(32k) for Realtek AP and set MPDUDensity=0(8k) for others 98 * Set MPDUDensity=2, 1: Set MPDUDensity=2(32k) for Realtek AP and set MPDUDensity=0(8k) for others
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
index 59d179ae7ad2..5cee1031a27c 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
@@ -105,7 +105,7 @@ static void ResetTsCommonInfo(struct ts_common_info *pTsCommonInfo)
105{ 105{
106 eth_zero_addr(pTsCommonInfo->addr); 106 eth_zero_addr(pTsCommonInfo->addr);
107 memset(&pTsCommonInfo->t_spec, 0, sizeof(struct tspec_body)); 107 memset(&pTsCommonInfo->t_spec, 0, sizeof(struct tspec_body));
108 memset(&pTsCommonInfo->t_class, 0, sizeof(union qos_tclas)*TCLAS_NUM); 108 memset(&pTsCommonInfo->t_class, 0, sizeof(union qos_tclas) * TCLAS_NUM);
109 pTsCommonInfo->t_clas_proc = 0; 109 pTsCommonInfo->t_clas_proc = 0;
110 pTsCommonInfo->t_clas_num = 0; 110 pTsCommonInfo->t_clas_num = 0;
111} 111}
@@ -180,14 +180,12 @@ void TSInitialize(struct ieee80211_device *ieee)
180 } 180 }
181 // Initialize unused Rx Reorder List. 181 // Initialize unused Rx Reorder List.
182 INIT_LIST_HEAD(&ieee->RxReorder_Unused_List); 182 INIT_LIST_HEAD(&ieee->RxReorder_Unused_List);
183//#ifdef TO_DO_LIST
184 for (count = 0; count < REORDER_ENTRY_NUM; count++) { 183 for (count = 0; count < REORDER_ENTRY_NUM; count++) {
185 list_add_tail(&pRxReorderEntry->List, &ieee->RxReorder_Unused_List); 184 list_add_tail(&pRxReorderEntry->List, &ieee->RxReorder_Unused_List);
186 if (count == (REORDER_ENTRY_NUM-1)) 185 if (count == (REORDER_ENTRY_NUM - 1))
187 break; 186 break;
188 pRxReorderEntry = &ieee->RxReorderEntry[count+1]; 187 pRxReorderEntry = &ieee->RxReorderEntry[count + 1];
189 } 188 }
190//#endif
191} 189}
192 190
193static void AdmitTS(struct ieee80211_device *ieee, 191static void AdmitTS(struct ieee80211_device *ieee,
@@ -259,7 +257,7 @@ static struct ts_common_info *SearchAdmitTRStream(struct ieee80211_device *ieee,
259 } 257 }
260 258
261 if (&pRet->list != psearch_list) 259 if (&pRet->list != psearch_list)
262 return pRet ; 260 return pRet;
263 else 261 else
264 return NULL; 262 return NULL;
265} 263}
@@ -367,8 +365,8 @@ bool GetTs(
367 (&ieee->Rx_TS_Admit_List); 365 (&ieee->Rx_TS_Admit_List);
368 366
369 enum direction_value Dir = (ieee->iw_mode == IW_MODE_MASTER) ? 367 enum direction_value Dir = (ieee->iw_mode == IW_MODE_MASTER) ?
370 ((TxRxSelect == TX_DIR)?DIR_DOWN:DIR_UP) : 368 ((TxRxSelect == TX_DIR) ? DIR_DOWN : DIR_UP) :
371 ((TxRxSelect == TX_DIR)?DIR_UP:DIR_DOWN); 369 ((TxRxSelect == TX_DIR) ? DIR_UP : DIR_DOWN);
372 IEEE80211_DEBUG(IEEE80211_DL_TS, "to add Ts\n"); 370 IEEE80211_DEBUG(IEEE80211_DL_TS, "to add Ts\n");
373 if (!list_empty(pUnusedList)) { 371 if (!list_empty(pUnusedList)) {
374 (*ppTS) = list_entry(pUnusedList->next, struct ts_common_info, list); 372 (*ppTS) = list_entry(pUnusedList->next, struct ts_common_info, list);
@@ -417,7 +415,6 @@ static void RemoveTsEntry(struct ieee80211_device *ieee, struct ts_common_info *
417 TsInitDelBA(ieee, pTs, TxRxSelect); 415 TsInitDelBA(ieee, pTs, TxRxSelect);
418 416
419 if (TxRxSelect == RX_DIR) { 417 if (TxRxSelect == RX_DIR) {
420//#ifdef TO_DO_LIST
421 struct rx_reorder_entry *pRxReorderEntry; 418 struct rx_reorder_entry *pRxReorderEntry;
422 struct rx_ts_record *pRxTS = (struct rx_ts_record *)pTs; 419 struct rx_ts_record *pRxTS = (struct rx_ts_record *)pTs;
423 if (timer_pending(&pRxTS->rx_pkt_pending_timer)) 420 if (timer_pending(&pRxTS->rx_pkt_pending_timer))
@@ -445,7 +442,6 @@ static void RemoveTsEntry(struct ieee80211_device *ieee, struct ts_common_info *
445 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags); 442 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
446 } 443 }
447 444
448//#endif
449 } else { 445 } else {
450 struct tx_ts_record *pTxTS = (struct tx_ts_record *)pTs; 446 struct tx_ts_record *pTxTS = (struct tx_ts_record *)pTs;
451 del_timer_sync(&pTxTS->ts_add_ba_timer); 447 del_timer_sync(&pTxTS->ts_add_ba_timer);
@@ -530,7 +526,7 @@ void TsStartAddBaProcess(struct ieee80211_device *ieee, struct tx_ts_record *pTx
530 jiffies + msecs_to_jiffies(TS_ADDBA_DELAY)); 526 jiffies + msecs_to_jiffies(TS_ADDBA_DELAY));
531 } else { 527 } else {
532 IEEE80211_DEBUG(IEEE80211_DL_BA, "%s: Immediately Start ADDBA now!!\n", __func__); 528 IEEE80211_DEBUG(IEEE80211_DL_BA, "%s: Immediately Start ADDBA now!!\n", __func__);
533 mod_timer(&pTxTS->ts_add_ba_timer, jiffies+10); //set 10 ticks 529 mod_timer(&pTxTS->ts_add_ba_timer, jiffies + 10); //set 10 ticks
534 } 530 }
535 } else { 531 } else {
536 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s()==>BA timer is already added\n", __func__); 532 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s()==>BA timer is already added\n", __func__);
diff --git a/drivers/staging/rtl8192u/r8180_93cx6.c b/drivers/staging/rtl8192u/r8180_93cx6.c
index de83daa0c9ed..2527cea60e3e 100644
--- a/drivers/staging/rtl8192u/r8180_93cx6.c
+++ b/drivers/staging/rtl8192u/r8180_93cx6.c
@@ -39,7 +39,6 @@ static void eprom_cs(struct net_device *dev, short bit)
39 udelay(EPROM_DELAY); 39 udelay(EPROM_DELAY);
40} 40}
41 41
42
43static void eprom_ck_cycle(struct net_device *dev) 42static void eprom_ck_cycle(struct net_device *dev)
44{ 43{
45 u8 cmdreg; 44 u8 cmdreg;
@@ -58,7 +57,6 @@ static void eprom_ck_cycle(struct net_device *dev)
58 udelay(EPROM_DELAY); 57 udelay(EPROM_DELAY);
59} 58}
60 59
61
62static void eprom_w(struct net_device *dev, short bit) 60static void eprom_w(struct net_device *dev, short bit)
63{ 61{
64 u8 cmdreg; 62 u8 cmdreg;
@@ -76,7 +74,6 @@ static void eprom_w(struct net_device *dev, short bit)
76 udelay(EPROM_DELAY); 74 udelay(EPROM_DELAY);
77} 75}
78 76
79
80static short eprom_r(struct net_device *dev) 77static short eprom_r(struct net_device *dev)
81{ 78{
82 u8 bit; 79 u8 bit;
@@ -94,7 +91,6 @@ static short eprom_r(struct net_device *dev)
94 return 0; 91 return 0;
95} 92}
96 93
97
98static void eprom_send_bits_string(struct net_device *dev, short b[], int len) 94static void eprom_send_bits_string(struct net_device *dev, short b[], int len)
99{ 95{
100 int i; 96 int i;
@@ -105,7 +101,6 @@ static void eprom_send_bits_string(struct net_device *dev, short b[], int len)
105 } 101 }
106} 102}
107 103
108
109int eprom_read(struct net_device *dev, u32 addr) 104int eprom_read(struct net_device *dev, u32 addr)
110{ 105{
111 struct r8192_priv *priv = ieee80211_priv(dev); 106 struct r8192_priv *priv = ieee80211_priv(dev);
@@ -119,7 +114,7 @@ int eprom_read(struct net_device *dev, u32 addr)
119 ret = 0; 114 ret = 0;
120 /* enable EPROM programming */ 115 /* enable EPROM programming */
121 write_nic_byte_E(dev, EPROM_CMD, 116 write_nic_byte_E(dev, EPROM_CMD,
122 (EPROM_CMD_PROGRAM<<EPROM_CMD_OPERATING_MODE_SHIFT)); 117 (EPROM_CMD_PROGRAM << EPROM_CMD_OPERATING_MODE_SHIFT));
123 force_pci_posting(dev); 118 force_pci_posting(dev);
124 udelay(EPROM_DELAY); 119 udelay(EPROM_DELAY);
125 120
@@ -162,7 +157,7 @@ int eprom_read(struct net_device *dev, u32 addr)
162 if (err < 0) 157 if (err < 0)
163 return err; 158 return err;
164 159
165 ret |= err<<(15-i); 160 ret |= err << (15 - i);
166 } 161 }
167 162
168 eprom_cs(dev, 0); 163 eprom_cs(dev, 0);
@@ -170,6 +165,6 @@ int eprom_read(struct net_device *dev, u32 addr)
170 165
171 /* disable EPROM programming */ 166 /* disable EPROM programming */
172 write_nic_byte_E(dev, EPROM_CMD, 167 write_nic_byte_E(dev, EPROM_CMD,
173 (EPROM_CMD_NORMAL<<EPROM_CMD_OPERATING_MODE_SHIFT)); 168 (EPROM_CMD_NORMAL << EPROM_CMD_OPERATING_MODE_SHIFT));
174 return ret; 169 return ret;
175} 170}
diff --git a/drivers/staging/rtl8192u/r8190_rtl8256.c b/drivers/staging/rtl8192u/r8190_rtl8256.c
index 92de92a3325a..b169460b9f26 100644
--- a/drivers/staging/rtl8192u/r8190_rtl8256.c
+++ b/drivers/staging/rtl8192u/r8190_rtl8256.c
@@ -42,9 +42,9 @@ void phy_set_rf8256_bandwidth(struct net_device *dev, enum ht_channel_width Band
42 42
43 switch (Bandwidth) { 43 switch (Bandwidth) {
44 case HT_CHANNEL_WIDTH_20: 44 case HT_CHANNEL_WIDTH_20:
45 if (priv->card_8192_version == VERSION_819XU_A 45 if (priv->card_8192_version == VERSION_819XU_A ||
46 || priv->card_8192_version 46 priv->card_8192_version ==
47 == VERSION_819XU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */ 47 VERSION_819XU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */
48 rtl8192_phy_SetRFReg(dev, 48 rtl8192_phy_SetRFReg(dev,
49 (enum rf90_radio_path_e)eRFPath, 49 (enum rf90_radio_path_e)eRFPath,
50 0x0b, bMask12Bits, 0x100); /* phy para:1ba */ 50 0x0b, bMask12Bits, 0x100); /* phy para:1ba */
@@ -79,10 +79,10 @@ void phy_set_rf8256_bandwidth(struct net_device *dev, enum ht_channel_width Band
79 default: 79 default:
80 RT_TRACE(COMP_ERR, "phy_set_rf8256_bandwidth(): unknown Bandwidth: %#X\n", Bandwidth); 80 RT_TRACE(COMP_ERR, "phy_set_rf8256_bandwidth(): unknown Bandwidth: %#X\n", Bandwidth);
81 break; 81 break;
82
83 } 82 }
84 } 83 }
85} 84}
85
86/*-------------------------------------------------------------------------- 86/*--------------------------------------------------------------------------
87 * Overview: Interface to config 8256 87 * Overview: Interface to config 8256
88 * Input: struct net_device* dev 88 * Input: struct net_device* dev
@@ -101,6 +101,7 @@ void phy_rf8256_config(struct net_device *dev)
101 /* Config BB and RF */ 101 /* Config BB and RF */
102 phy_rf8256_config_para_file(dev); 102 phy_rf8256_config_para_file(dev);
103} 103}
104
104/*-------------------------------------------------------------------------- 105/*--------------------------------------------------------------------------
105 * Overview: Interface to config 8256 106 * Overview: Interface to config 8256
106 * Input: struct net_device* dev 107 * Input: struct net_device* dev
@@ -137,12 +138,12 @@ static void phy_rf8256_config_para_file(struct net_device *dev)
137 break; 138 break;
138 case RF90_PATH_B: 139 case RF90_PATH_B:
139 case RF90_PATH_D: 140 case RF90_PATH_D:
140 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16); 141 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, bRFSI_RFENV << 16);
141 break; 142 break;
142 } 143 }
143 144
144 /*----Set RF_ENV enable----*/ 145 /*----Set RF_ENV enable----*/
145 rtl8192_setBBreg(dev, pPhyReg->rfintfe, bRFSI_RFENV<<16, 0x1); 146 rtl8192_setBBreg(dev, pPhyReg->rfintfe, bRFSI_RFENV << 16, 0x1);
146 147
147 /*----Set RF_ENV output high----*/ 148 /*----Set RF_ENV output high----*/
148 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1); 149 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1);
@@ -151,7 +152,7 @@ static void phy_rf8256_config_para_file(struct net_device *dev)
151 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0); /* Set 0 to 4 bits for Z-serial and set 1 to 6 bits for 8258 */ 152 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0); /* Set 0 to 4 bits for Z-serial and set 1 to 6 bits for 8258 */
152 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0); /* Set 0 to 12 bits for Z-serial and 8258, and set 1 to 14 bits for ??? */ 153 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0); /* Set 0 to 12 bits for Z-serial and 8258, and set 1 to 14 bits for ??? */
153 154
154 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e) eRFPath, 0x0, bMask12Bits, 0xbf); 155 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x0, bMask12Bits, 0xbf);
155 156
156 /* Check RF block (for FPGA platform only)---- 157 /* Check RF block (for FPGA platform only)----
157 * TODO: this function should be removed on ASIC , Emily 2007.2.2 158 * TODO: this function should be removed on ASIC , Emily 2007.2.2
@@ -207,7 +208,7 @@ static void phy_rf8256_config_para_file(struct net_device *dev)
207 break; 208 break;
208 case RF90_PATH_B: 209 case RF90_PATH_B:
209 case RF90_PATH_D: 210 case RF90_PATH_D:
210 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16, u4RegValue); 211 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV << 16, u4RegValue);
211 break; 212 break;
212 } 213 }
213 214
@@ -215,7 +216,6 @@ static void phy_rf8256_config_para_file(struct net_device *dev)
215 RT_TRACE(COMP_ERR, "phy_rf8256_config_para_file():Radio[%d] Fail!!", eRFPath); 216 RT_TRACE(COMP_ERR, "phy_rf8256_config_para_file():Radio[%d] Fail!!", eRFPath);
216 goto phy_RF8256_Config_ParaFile_Fail; 217 goto phy_RF8256_Config_ParaFile_Fail;
217 } 218 }
218
219 } 219 }
220 220
221 RT_TRACE(COMP_PHY, "PHY Initialization Success\n"); 221 RT_TRACE(COMP_PHY, "PHY Initialization Success\n");
@@ -225,11 +225,11 @@ phy_RF8256_Config_ParaFile_Fail:
225 RT_TRACE(COMP_ERR, "PHY Initialization failed\n"); 225 RT_TRACE(COMP_ERR, "PHY Initialization failed\n");
226} 226}
227 227
228
229void phy_set_rf8256_cck_tx_power(struct net_device *dev, u8 powerlevel) 228void phy_set_rf8256_cck_tx_power(struct net_device *dev, u8 powerlevel)
230{ 229{
231 u32 TxAGC = 0; 230 u32 TxAGC = 0;
232 struct r8192_priv *priv = ieee80211_priv(dev); 231 struct r8192_priv *priv = ieee80211_priv(dev);
232
233 TxAGC = powerlevel; 233 TxAGC = powerlevel;
234 234
235 if (priv->bDynamicTxLowPower) { 235 if (priv->bDynamicTxLowPower) {
@@ -244,7 +244,6 @@ void phy_set_rf8256_cck_tx_power(struct net_device *dev, u8 powerlevel)
244 rtl8192_setBBreg(dev, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC); 244 rtl8192_setBBreg(dev, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC);
245} 245}
246 246
247
248void phy_set_rf8256_ofdm_tx_power(struct net_device *dev, u8 powerlevel) 247void phy_set_rf8256_ofdm_tx_power(struct net_device *dev, u8 powerlevel)
249{ 248{
250 struct r8192_priv *priv = ieee80211_priv(dev); 249 struct r8192_priv *priv = ieee80211_priv(dev);
@@ -255,16 +254,16 @@ void phy_set_rf8256_ofdm_tx_power(struct net_device *dev, u8 powerlevel)
255 u8 byte0, byte1, byte2, byte3; 254 u8 byte0, byte1, byte2, byte3;
256 255
257 powerBase0 = powerlevel + priv->TxPowerDiff; /* OFDM rates */ 256 powerBase0 = powerlevel + priv->TxPowerDiff; /* OFDM rates */
258 powerBase0 = (powerBase0<<24) | (powerBase0<<16) | (powerBase0<<8) | powerBase0; 257 powerBase0 = (powerBase0 << 24) | (powerBase0 << 16) | (powerBase0 << 8) | powerBase0;
259 powerBase1 = powerlevel; /* MCS rates */ 258 powerBase1 = powerlevel; /* MCS rates */
260 powerBase1 = (powerBase1<<24) | (powerBase1<<16) | (powerBase1<<8) | powerBase1; 259 powerBase1 = (powerBase1 << 24) | (powerBase1 << 16) | (powerBase1 << 8) | powerBase1;
261 260
262 for (index = 0; index < 6; index++) { 261 for (index = 0; index < 6; index++) {
263 writeVal = priv->MCSTxPowerLevelOriginalOffset[index] + ((index < 2)?powerBase0:powerBase1); 262 writeVal = priv->MCSTxPowerLevelOriginalOffset[index] + ((index < 2) ? powerBase0 : powerBase1);
264 byte0 = (u8)(writeVal & 0x7f); 263 byte0 = (u8)(writeVal & 0x7f);
265 byte1 = (u8)((writeVal & 0x7f00)>>8); 264 byte1 = (u8)((writeVal & 0x7f00) >> 8);
266 byte2 = (u8)((writeVal & 0x7f0000)>>16); 265 byte2 = (u8)((writeVal & 0x7f0000) >> 16);
267 byte3 = (u8)((writeVal & 0x7f000000)>>24); 266 byte3 = (u8)((writeVal & 0x7f000000) >> 24);
268 267
269 if (byte0 > 0x24) 268 if (byte0 > 0x24)
270 /* Max power index = 0x24 */ 269 /* Max power index = 0x24 */
@@ -278,7 +277,7 @@ void phy_set_rf8256_ofdm_tx_power(struct net_device *dev, u8 powerlevel)
278 277
279 /* for tx power track */ 278 /* for tx power track */
280 if (index == 3) { 279 if (index == 3) {
281 writeVal_tmp = (byte3<<24) | (byte2<<16) | (byte1<<8) | byte0; 280 writeVal_tmp = (byte3 << 24) | (byte2 << 16) | (byte1 << 8) | byte0;
282 priv->Pwr_Track = writeVal_tmp; 281 priv->Pwr_Track = writeVal_tmp;
283 } 282 }
284 283
@@ -288,10 +287,9 @@ void phy_set_rf8256_ofdm_tx_power(struct net_device *dev, u8 powerlevel)
288 */ 287 */
289 writeVal = 0x03030303; 288 writeVal = 0x03030303;
290 } else { 289 } else {
291 writeVal = (byte3<<24) | (byte2<<16) | (byte1<<8) | byte0; 290 writeVal = (byte3 << 24) | (byte2 << 16) | (byte1 << 8) | byte0;
292 } 291 }
293 rtl8192_setBBreg(dev, RegOffset[index], 0x7f7f7f7f, writeVal); 292 rtl8192_setBBreg(dev, RegOffset[index], 0x7f7f7f7f, writeVal);
294 } 293 }
295 return; 294 return;
296
297} 295}
diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index fe1f279ca368..2821411878ce 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -2076,14 +2076,6 @@ static void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
2076 wireless_mode = WIRELESS_MODE_B; 2076 wireless_mode = WIRELESS_MODE_B;
2077 } 2077 }
2078 } 2078 }
2079#ifdef TO_DO_LIST
2080 /* TODO: this function doesn't work well at this time,
2081 * we should wait for FPGA
2082 */
2083 ActUpdateChannelAccessSetting(
2084 pAdapter, pHalData->CurrentWirelessMode,
2085 &pAdapter->MgntInfo.Info8185.ChannelAccessSetting);
2086#endif
2087 priv->ieee80211->mode = wireless_mode; 2079 priv->ieee80211->mode = wireless_mode;
2088 2080
2089 if (wireless_mode == WIRELESS_MODE_N_24G || 2081 if (wireless_mode == WIRELESS_MODE_N_24G ||
@@ -2096,7 +2088,7 @@ static void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
2096} 2088}
2097 2089
2098/* init priv variables here. only non_zero value should be initialized here. */ 2090/* init priv variables here. only non_zero value should be initialized here. */
2099static void rtl8192_init_priv_variable(struct net_device *dev) 2091static int rtl8192_init_priv_variable(struct net_device *dev)
2100{ 2092{
2101 struct r8192_priv *priv = ieee80211_priv(dev); 2093 struct r8192_priv *priv = ieee80211_priv(dev);
2102 u8 i; 2094 u8 i;
@@ -2159,12 +2151,6 @@ static void rtl8192_init_priv_variable(struct net_device *dev)
2159 2151
2160 priv->ieee80211->InitialGainHandler = InitialGain819xUsb; 2152 priv->ieee80211->InitialGainHandler = InitialGain819xUsb;
2161 priv->card_type = USB; 2153 priv->card_type = USB;
2162#ifdef TO_DO_LIST
2163 if (Adapter->bInHctTest) {
2164 pHalData->ShortRetryLimit = 7;
2165 pHalData->LongRetryLimit = 7;
2166 }
2167#endif
2168 priv->ShortRetryLimit = 0x30; 2154 priv->ShortRetryLimit = 0x30;
2169 priv->LongRetryLimit = 0x30; 2155 priv->LongRetryLimit = 0x30;
2170 priv->EarlyRxThreshold = 7; 2156 priv->EarlyRxThreshold = 7;
@@ -2180,34 +2166,6 @@ static void rtl8192_init_priv_variable(struct net_device *dev)
2180 * TRUE: SW provides them 2166 * TRUE: SW provides them
2181 */ 2167 */
2182 (false ? TCR_SAT : 0); 2168 (false ? TCR_SAT : 0);
2183#ifdef TO_DO_LIST
2184 if (Adapter->bInHctTest)
2185 pHalData->ReceiveConfig =
2186 pHalData->CSMethod |
2187 /* accept management/data */
2188 RCR_AMF | RCR_ADF |
2189 /* accept control frame for SW
2190 * AP needs PS-poll
2191 */
2192 RCR_ACF |
2193 /* accept BC/MC/UC */
2194 RCR_AB | RCR_AM | RCR_APM |
2195 /* accept ICV/CRC error
2196 * packet
2197 */
2198 RCR_AICV | RCR_ACRC32 |
2199 /* Max DMA Burst Size per Tx
2200 * DMA Burst, 7: unlimited.
2201 */
2202 ((u32)7 << RCR_MXDMA_OFFSET) |
2203 /* Rx FIFO Threshold,
2204 * 7: No Rx threshold.
2205 */
2206 (pHalData->EarlyRxThreshold << RCR_FIFO_OFFSET) |
2207 (pHalData->EarlyRxThreshold == 7 ? RCR_OnlyErlPkt : 0);
2208 else
2209
2210#endif
2211 priv->ReceiveConfig = 2169 priv->ReceiveConfig =
2212 /* accept management/data */ 2170 /* accept management/data */
2213 RCR_AMF | RCR_ADF | 2171 RCR_AMF | RCR_ADF |
@@ -2223,6 +2181,8 @@ static void rtl8192_init_priv_variable(struct net_device *dev)
2223 2181
2224 priv->AcmControl = 0; 2182 priv->AcmControl = 0;
2225 priv->pFirmware = kzalloc(sizeof(rt_firmware), GFP_KERNEL); 2183 priv->pFirmware = kzalloc(sizeof(rt_firmware), GFP_KERNEL);
2184 if (!priv->pFirmware)
2185 return -ENOMEM;
2226 2186
2227 /* rx related queue */ 2187 /* rx related queue */
2228 skb_queue_head_init(&priv->rx_queue); 2188 skb_queue_head_init(&priv->rx_queue);
@@ -2236,6 +2196,8 @@ static void rtl8192_init_priv_variable(struct net_device *dev)
2236 for (i = 0; i < MAX_QUEUE_SIZE; i++) 2196 for (i = 0; i < MAX_QUEUE_SIZE; i++)
2237 skb_queue_head_init(&priv->ieee80211->skb_drv_aggQ[i]); 2197 skb_queue_head_init(&priv->ieee80211->skb_drv_aggQ[i]);
2238 priv->rf_set_chan = rtl8192_phy_SwChnl; 2198 priv->rf_set_chan = rtl8192_phy_SwChnl;
2199
2200 return 0;
2239} 2201}
2240 2202
2241/* init lock here */ 2203/* init lock here */
@@ -2605,7 +2567,10 @@ static short rtl8192_init(struct net_device *dev)
2605 memcpy(priv->txqueue_to_outpipemap, queuetopipe, 9); 2567 memcpy(priv->txqueue_to_outpipemap, queuetopipe, 9);
2606 } 2568 }
2607#endif 2569#endif
2608 rtl8192_init_priv_variable(dev); 2570 err = rtl8192_init_priv_variable(dev);
2571 if (err)
2572 return err;
2573
2609 rtl8192_init_priv_lock(priv); 2574 rtl8192_init_priv_lock(priv);
2610 rtl8192_init_priv_task(dev); 2575 rtl8192_init_priv_task(dev);
2611 rtl8192_get_eeprom_size(dev); 2576 rtl8192_get_eeprom_size(dev);
@@ -2658,19 +2623,10 @@ static void rtl8192_hwconfig(struct net_device *dev)
2658 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG; 2623 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2659 break; 2624 break;
2660 case WIRELESS_MODE_AUTO: 2625 case WIRELESS_MODE_AUTO:
2661#ifdef TO_DO_LIST 2626 regBwOpMode = BW_OPMODE_20MHZ;
2662 if (Adapter->bInHctTest) { 2627 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG |
2663 regBwOpMode = BW_OPMODE_20MHZ; 2628 RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
2664 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG; 2629 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2665 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2666 } else
2667#endif
2668 {
2669 regBwOpMode = BW_OPMODE_20MHZ;
2670 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG |
2671 RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
2672 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2673 }
2674 break; 2630 break;
2675 case WIRELESS_MODE_N_24G: 2631 case WIRELESS_MODE_N_24G:
2676 /* It support CCK rate by default. CCK rate will be filtered 2632 /* It support CCK rate by default. CCK rate will be filtered
@@ -2841,48 +2797,6 @@ static bool rtl8192_adapter_start(struct net_device *dev)
2841 } 2797 }
2842 RT_TRACE(COMP_INIT, "%s():after firmware download\n", __func__); 2798 RT_TRACE(COMP_INIT, "%s():after firmware download\n", __func__);
2843 2799
2844#ifdef TO_DO_LIST
2845 if (Adapter->ResetProgress == RESET_TYPE_NORESET) {
2846 if (pMgntInfo->RegRfOff) { /* User disable RF via registry. */
2847 RT_TRACE((COMP_INIT | COMP_RF), DBG_LOUD,
2848 ("InitializeAdapter819xUsb(): Turn off RF for RegRfOff ----------\n"));
2849 MgntActSet_RF_State(Adapter, eRfOff, RF_CHANGE_BY_SW);
2850 /* Those actions will be discard in MgntActSet_RF_State
2851 * because of the same state
2852 */
2853 for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++)
2854 PHY_SetRFReg(Adapter,
2855 (enum rf90_radio_path_e)eRFPath,
2856 0x4, 0xC00, 0x0);
2857 } else if (pMgntInfo->RfOffReason > RF_CHANGE_BY_PS) {
2858 /* H/W or S/W RF OFF before sleep. */
2859 RT_TRACE((COMP_INIT | COMP_RF), DBG_LOUD,
2860 ("InitializeAdapter819xUsb(): Turn off RF for RfOffReason(%d) ----------\n",
2861 pMgntInfo->RfOffReason));
2862 MgntActSet_RF_State(Adapter,
2863 eRfOff,
2864 pMgntInfo->RfOffReason);
2865 } else {
2866 pHalData->eRFPowerState = eRfOn;
2867 pMgntInfo->RfOffReason = 0;
2868 RT_TRACE((COMP_INIT | COMP_RF), DBG_LOUD,
2869 ("InitializeAdapter819xUsb(): RF is on ----------\n"));
2870 }
2871 } else {
2872 if (pHalData->eRFPowerState == eRfOff) {
2873 MgntActSet_RF_State(Adapter,
2874 eRfOff,
2875 pMgntInfo->RfOffReason);
2876 /* Those actions will be discard in MgntActSet_RF_State
2877 * because of the same state
2878 */
2879 for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++)
2880 PHY_SetRFReg(Adapter,
2881 (enum rf90_radio_path_e)eRFPath,
2882 0x4, 0xC00, 0x0);
2883 }
2884 }
2885#endif
2886 /* config RF. */ 2800 /* config RF. */
2887 if (priv->ResetProgress == RESET_TYPE_NORESET) { 2801 if (priv->ResetProgress == RESET_TYPE_NORESET) {
2888 rtl8192_phy_RFConfig(dev); 2802 rtl8192_phy_RFConfig(dev);
diff --git a/drivers/staging/rtl8192u/r8192U_dm.c b/drivers/staging/rtl8192u/r8192U_dm.c
index ade14ef05730..c23e43b095d9 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -1334,7 +1334,7 @@ static void dm_CheckTXPowerTracking_ThermalMeter(struct net_device *dev)
1334 return; 1334 return;
1335 } 1335 }
1336 /*DbgPrint("Schedule TxPowerTrackingWorkItem\n");*/ 1336 /*DbgPrint("Schedule TxPowerTrackingWorkItem\n");*/
1337 queue_delayed_work(priv->priv_wq, &priv->txpower_tracking_wq, 0); 1337 queue_delayed_work(priv->priv_wq, &priv->txpower_tracking_wq, 0);
1338 TM_Trigger = 0; 1338 TM_Trigger = 0;
1339} 1339}
1340 1340
diff --git a/drivers/staging/rtl8192u/r819xU_firmware.c b/drivers/staging/rtl8192u/r819xU_firmware.c
index 153d4ee0ec07..dd81d210bd49 100644
--- a/drivers/staging/rtl8192u/r819xU_firmware.c
+++ b/drivers/staging/rtl8192u/r819xU_firmware.c
@@ -231,7 +231,7 @@ bool init_firmware(struct net_device *dev)
231 rst_opt = OPT_FIRMWARE_RESET; 231 rst_opt = OPT_FIRMWARE_RESET;
232 starting_state = FW_INIT_STEP2_DATA; 232 starting_state = FW_INIT_STEP2_DATA;
233 } else { 233 } else {
234 RT_TRACE(COMP_FIRMWARE, "PlatformInitFirmware: undefined firmware state\n"); 234 RT_TRACE(COMP_FIRMWARE, "PlatformInitFirmware: undefined firmware state\n");
235 } 235 }
236 236
237 /* 237 /*
diff --git a/drivers/staging/rtl8192u/r819xU_phy.c b/drivers/staging/rtl8192u/r819xU_phy.c
index 5f04afe53d69..c04d8eca0cfb 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -516,16 +516,6 @@ static void rtl8192_phyConfigBB(struct net_device *dev,
516{ 516{
517 u32 i; 517 u32 i;
518 518
519#ifdef TO_DO_LIST
520 u32 *rtl8192PhyRegArrayTable = NULL, *rtl8192AgcTabArrayTable = NULL;
521
522 if (Adapter->bInHctTest) {
523 PHY_REGArrayLen = PHY_REGArrayLengthDTM;
524 AGCTAB_ArrayLen = AGCTAB_ArrayLengthDTM;
525 Rtl8190PHY_REGArray_Table = Rtl819XPHY_REGArrayDTM;
526 Rtl8190AGCTAB_Array_Table = Rtl819XAGCTAB_ArrayDTM;
527 }
528#endif
529 if (ConfigType == BASEBAND_CONFIG_PHY_REG) { 519 if (ConfigType == BASEBAND_CONFIG_PHY_REG) {
530 for (i = 0; i < PHY_REG_1T2RArrayLength; i += 2) { 520 for (i = 0; i < PHY_REG_1T2RArrayLength; i += 2) {
531 rtl8192_setBBreg(dev, Rtl8192UsbPHY_REG_1T2RArray[i], 521 rtl8192_setBBreg(dev, Rtl8192UsbPHY_REG_1T2RArray[i],
@@ -1059,10 +1049,6 @@ static void rtl8192_SetTxPowerLevel(struct net_device *dev, u8 channel)
1059 1049
1060 switch (priv->rf_chip) { 1050 switch (priv->rf_chip) {
1061 case RF_8225: 1051 case RF_8225:
1062#ifdef TO_DO_LIST
1063 PHY_SetRF8225CckTxPower(Adapter, powerlevel);
1064 PHY_SetRF8225OfdmTxPower(Adapter, powerlevelOFDM24G);
1065#endif
1066 break; 1052 break;
1067 1053
1068 case RF_8256: 1054 case RF_8256:
@@ -1160,48 +1146,6 @@ bool rtl8192_SetRFPowerState(struct net_device *dev,
1160 RT_TRACE(COMP_ERR, "Not support rf_chip(%x)\n", priv->rf_chip); 1146 RT_TRACE(COMP_ERR, "Not support rf_chip(%x)\n", priv->rf_chip);
1161 break; 1147 break;
1162 } 1148 }
1163#ifdef TO_DO_LIST
1164 if (bResult) {
1165 /* Update current RF state variable. */
1166 pHalData->eRFPowerState = eRFPowerState;
1167 switch (pHalData->RFChipID) {
1168 case RF_8256:
1169 switch (pHalData->eRFPowerState) {
1170 case eRfOff:
1171 /* If Rf off reason is from IPS,
1172 * LED should blink with no link
1173 */
1174 if (pMgntInfo->RfOffReason == RF_CHANGE_BY_IPS)
1175 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_NO_LINK);
1176 else
1177 /* Turn off LED if RF is not ON. */
1178 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_POWER_OFF);
1179 break;
1180
1181 case eRfOn:
1182 /* Turn on RF we are still linked, which might
1183 * happen when we quickly turn off and on HW RF.
1184 */
1185 if (pMgntInfo->bMediaConnect)
1186 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_LINK);
1187 else
1188 /* Turn off LED if RF is not ON. */
1189 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_NO_LINK);
1190 break;
1191
1192 default:
1193 break;
1194 }
1195 break;
1196
1197 default:
1198 RT_TRACE(COMP_RF, DBG_LOUD, "%s(): Unknown RF type\n",
1199 __func__);
1200 break;
1201 }
1202
1203 }
1204#endif
1205 priv->SetRFPowerStateInProgress = false; 1149 priv->SetRFPowerStateInProgress = false;
1206 1150
1207 return bResult; 1151 return bResult;
@@ -1628,9 +1572,6 @@ void rtl8192_SetBWModeWorkItem(struct net_device *dev)
1628 /* <3> Set RF related register */ 1572 /* <3> Set RF related register */
1629 switch (priv->rf_chip) { 1573 switch (priv->rf_chip) {
1630 case RF_8225: 1574 case RF_8225:
1631#ifdef TO_DO_LIST
1632 PHY_SetRF8225Bandwidth(Adapter, pHalData->CurrentChannelBW);
1633#endif
1634 break; 1575 break;
1635 1576
1636 case RF_8256: 1577 case RF_8256:
diff --git a/drivers/staging/rtl8712/os_intfs.c b/drivers/staging/rtl8712/os_intfs.c
index b554cf8bd679..0c3ae8495afb 100644
--- a/drivers/staging/rtl8712/os_intfs.c
+++ b/drivers/staging/rtl8712/os_intfs.c
@@ -258,7 +258,7 @@ void r8712_stop_drv_timers(struct _adapter *padapter)
258 del_timer_sync(&padapter->mlmepriv.sitesurveyctrl.sitesurvey_ctrl_timer); 258 del_timer_sync(&padapter->mlmepriv.sitesurveyctrl.sitesurvey_ctrl_timer);
259} 259}
260 260
261static u8 init_default_value(struct _adapter *padapter) 261static void init_default_value(struct _adapter *padapter)
262{ 262{
263 struct registry_priv *pregistrypriv = &padapter->registrypriv; 263 struct registry_priv *pregistrypriv = &padapter->registrypriv;
264 struct xmit_priv *pxmitpriv = &padapter->xmitpriv; 264 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
@@ -292,37 +292,41 @@ static u8 init_default_value(struct _adapter *padapter)
292 r8712_init_registrypriv_dev_network(padapter); 292 r8712_init_registrypriv_dev_network(padapter);
293 r8712_update_registrypriv_dev_network(padapter); 293 r8712_update_registrypriv_dev_network(padapter);
294 /*misc.*/ 294 /*misc.*/
295 return _SUCCESS;
296} 295}
297 296
298u8 r8712_init_drv_sw(struct _adapter *padapter) 297int r8712_init_drv_sw(struct _adapter *padapter)
299{ 298{
300 if (r8712_init_cmd_priv(&padapter->cmdpriv)) 299 int ret;
301 return _FAIL; 300
301 ret = r8712_init_cmd_priv(&padapter->cmdpriv);
302 if (ret)
303 return ret;
302 padapter->cmdpriv.padapter = padapter; 304 padapter->cmdpriv.padapter = padapter;
303 if (r8712_init_evt_priv(&padapter->evtpriv)) 305 ret = r8712_init_evt_priv(&padapter->evtpriv);
304 return _FAIL; 306 if (ret)
305 if (r8712_init_mlme_priv(padapter) == _FAIL) 307 return ret;
306 return _FAIL; 308 ret = r8712_init_mlme_priv(padapter);
309 if (ret)
310 return ret;
307 _r8712_init_xmit_priv(&padapter->xmitpriv, padapter); 311 _r8712_init_xmit_priv(&padapter->xmitpriv, padapter);
308 _r8712_init_recv_priv(&padapter->recvpriv, padapter); 312 _r8712_init_recv_priv(&padapter->recvpriv, padapter);
309 memset((unsigned char *)&padapter->securitypriv, 0, 313 memset((unsigned char *)&padapter->securitypriv, 0,
310 sizeof(struct security_priv)); 314 sizeof(struct security_priv));
311 timer_setup(&padapter->securitypriv.tkip_timer, 315 timer_setup(&padapter->securitypriv.tkip_timer,
312 r8712_use_tkipkey_handler, 0); 316 r8712_use_tkipkey_handler, 0);
313 if (_r8712_init_sta_priv(&padapter->stapriv)) 317 ret = _r8712_init_sta_priv(&padapter->stapriv);
314 return _FAIL; 318 if (ret)
319 return ret;
315 padapter->stapriv.padapter = padapter; 320 padapter->stapriv.padapter = padapter;
316 r8712_init_bcmc_stainfo(padapter); 321 r8712_init_bcmc_stainfo(padapter);
317 r8712_init_pwrctrl_priv(padapter); 322 r8712_init_pwrctrl_priv(padapter);
318 mp871xinit(padapter); 323 mp871xinit(padapter);
319 if (init_default_value(padapter) != _SUCCESS) 324 init_default_value(padapter);
320 return _FAIL;
321 r8712_InitSwLeds(padapter); 325 r8712_InitSwLeds(padapter);
322 return _SUCCESS; 326 return ret;
323} 327}
324 328
325u8 r8712_free_drv_sw(struct _adapter *padapter) 329void r8712_free_drv_sw(struct _adapter *padapter)
326{ 330{
327 struct net_device *pnetdev = padapter->pnetdev; 331 struct net_device *pnetdev = padapter->pnetdev;
328 332
@@ -337,7 +341,6 @@ u8 r8712_free_drv_sw(struct _adapter *padapter)
337 mp871xdeinit(padapter); 341 mp871xdeinit(padapter);
338 if (pnetdev) 342 if (pnetdev)
339 free_netdev(pnetdev); 343 free_netdev(pnetdev);
340 return _SUCCESS;
341} 344}
342 345
343static void enable_video_mode(struct _adapter *padapter, int cbw40_value) 346static void enable_video_mode(struct _adapter *padapter, int cbw40_value)
diff --git a/drivers/staging/rtl8712/recv_linux.c b/drivers/staging/rtl8712/recv_linux.c
index 84c4c8580f9a..215fca4abb3a 100644
--- a/drivers/staging/rtl8712/recv_linux.c
+++ b/drivers/staging/rtl8712/recv_linux.c
@@ -29,24 +29,23 @@
29 29
30/*init os related resource in struct recv_priv*/ 30/*init os related resource in struct recv_priv*/
31/*alloc os related resource in union recv_frame*/ 31/*alloc os related resource in union recv_frame*/
32int r8712_os_recv_resource_alloc(struct _adapter *padapter, 32void r8712_os_recv_resource_alloc(struct _adapter *padapter,
33 union recv_frame *precvframe) 33 union recv_frame *precvframe)
34{ 34{
35 precvframe->u.hdr.pkt_newalloc = NULL; 35 precvframe->u.hdr.pkt_newalloc = NULL;
36 precvframe->u.hdr.pkt = NULL; 36 precvframe->u.hdr.pkt = NULL;
37 return _SUCCESS;
38} 37}
39 38
40/*alloc os related resource in struct recv_buf*/ 39/*alloc os related resource in struct recv_buf*/
41int r8712_os_recvbuf_resource_alloc(struct _adapter *padapter, 40int r8712_os_recvbuf_resource_alloc(struct _adapter *padapter,
42 struct recv_buf *precvbuf) 41 struct recv_buf *precvbuf)
43{ 42{
44 int res = _SUCCESS; 43 int res = 0;
45 44
46 precvbuf->irp_pending = false; 45 precvbuf->irp_pending = false;
47 precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL); 46 precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL);
48 if (!precvbuf->purb) 47 if (!precvbuf->purb)
49 res = _FAIL; 48 res = -ENOMEM;
50 precvbuf->pskb = NULL; 49 precvbuf->pskb = NULL;
51 precvbuf->pallocated_buf = NULL; 50 precvbuf->pallocated_buf = NULL;
52 precvbuf->pbuf = NULL; 51 precvbuf->pbuf = NULL;
@@ -60,8 +59,8 @@ int r8712_os_recvbuf_resource_alloc(struct _adapter *padapter,
60} 59}
61 60
62/*free os related resource in struct recv_buf*/ 61/*free os related resource in struct recv_buf*/
63int r8712_os_recvbuf_resource_free(struct _adapter *padapter, 62void r8712_os_recvbuf_resource_free(struct _adapter *padapter,
64 struct recv_buf *precvbuf) 63 struct recv_buf *precvbuf)
65{ 64{
66 if (precvbuf->pskb) 65 if (precvbuf->pskb)
67 dev_kfree_skb_any(precvbuf->pskb); 66 dev_kfree_skb_any(precvbuf->pskb);
@@ -69,7 +68,6 @@ int r8712_os_recvbuf_resource_free(struct _adapter *padapter,
69 usb_kill_urb(precvbuf->purb); 68 usb_kill_urb(precvbuf->purb);
70 usb_free_urb(precvbuf->purb); 69 usb_free_urb(precvbuf->purb);
71 } 70 }
72 return _SUCCESS;
73} 71}
74 72
75void r8712_handle_tkip_mic_err(struct _adapter *adapter, u8 bgroup) 73void r8712_handle_tkip_mic_err(struct _adapter *adapter, u8 bgroup)
@@ -115,8 +113,8 @@ void r8712_recv_indicatepkt(struct _adapter *adapter,
115 skb->protocol = eth_type_trans(skb, adapter->pnetdev); 113 skb->protocol = eth_type_trans(skb, adapter->pnetdev);
116 netif_rx(skb); 114 netif_rx(skb);
117 recvframe->u.hdr.pkt = NULL; /* pointers to NULL before 115 recvframe->u.hdr.pkt = NULL; /* pointers to NULL before
118 * r8712_free_recvframe() 116 * r8712_free_recvframe()
119 */ 117 */
120 r8712_free_recvframe(recvframe, free_recv_queue); 118 r8712_free_recvframe(recvframe, free_recv_queue);
121 return; 119 return;
122_recv_indicatepkt_drop: 120_recv_indicatepkt_drop:
diff --git a/drivers/staging/rtl8712/recv_osdep.h b/drivers/staging/rtl8712/recv_osdep.h
index dcd3b484c793..d8c1fa74f544 100644
--- a/drivers/staging/rtl8712/recv_osdep.h
+++ b/drivers/staging/rtl8712/recv_osdep.h
@@ -18,22 +18,22 @@
18#include "drv_types.h" 18#include "drv_types.h"
19#include <linux/skbuff.h> 19#include <linux/skbuff.h>
20 20
21sint _r8712_init_recv_priv(struct recv_priv *precvpriv, 21void _r8712_init_recv_priv(struct recv_priv *precvpriv,
22 struct _adapter *padapter); 22 struct _adapter *padapter);
23void _r8712_free_recv_priv(struct recv_priv *precvpriv); 23void _r8712_free_recv_priv(struct recv_priv *precvpriv);
24s32 r8712_recv_entry(union recv_frame *precv_frame); 24void r8712_recv_entry(union recv_frame *precv_frame);
25void r8712_recv_indicatepkt(struct _adapter *adapter, 25void r8712_recv_indicatepkt(struct _adapter *adapter,
26 union recv_frame *precv_frame); 26 union recv_frame *precv_frame);
27void r8712_handle_tkip_mic_err(struct _adapter *padapter, u8 bgroup); 27void r8712_handle_tkip_mic_err(struct _adapter *padapter, u8 bgroup);
28int r8712_init_recv_priv(struct recv_priv *precvpriv, 28void r8712_init_recv_priv(struct recv_priv *precvpriv,
29 struct _adapter *padapter); 29 struct _adapter *padapter);
30void r8712_free_recv_priv(struct recv_priv *precvpriv); 30void r8712_free_recv_priv(struct recv_priv *precvpriv);
31int r8712_os_recv_resource_alloc(struct _adapter *padapter, 31void r8712_os_recv_resource_alloc(struct _adapter *padapter,
32 union recv_frame *precvframe); 32 union recv_frame *precvframe);
33int r8712_os_recvbuf_resource_alloc(struct _adapter *padapter, 33int r8712_os_recvbuf_resource_alloc(struct _adapter *padapter,
34 struct recv_buf *precvbuf); 34 struct recv_buf *precvbuf);
35int r8712_os_recvbuf_resource_free(struct _adapter *padapter, 35void r8712_os_recvbuf_resource_free(struct _adapter *padapter,
36 struct recv_buf *precvbuf); 36 struct recv_buf *precvbuf);
37void r8712_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl); 37void r8712_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl);
38 38
39#endif 39#endif
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c b/drivers/staging/rtl8712/rtl8712_cmd.c
index 6a72a4ad176a..ff3cb09c57a6 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -263,11 +263,6 @@ static struct cmd_obj *cmd_hdl_filter(struct _adapter *padapter,
263 return pcmd_r; /* if returning pcmd_r == NULL, pcmd must be free. */ 263 return pcmd_r; /* if returning pcmd_r == NULL, pcmd must be free. */
264} 264}
265 265
266static u8 check_cmd_fifo(struct _adapter *padapter, uint sz)
267{
268 return _SUCCESS;
269}
270
271u8 r8712_fw_cmd(struct _adapter *pAdapter, u32 cmd) 266u8 r8712_fw_cmd(struct _adapter *pAdapter, u32 cmd)
272{ 267{
273 int pollingcnts = 50; 268 int pollingcnts = 50;
@@ -311,7 +306,7 @@ int r8712_cmd_thread(void *context)
311 break; 306 break;
312 if (padapter->driver_stopped || padapter->surprise_removed) 307 if (padapter->driver_stopped || padapter->surprise_removed)
313 break; 308 break;
314 if (r8712_register_cmd_alive(padapter) != _SUCCESS) 309 if (r8712_register_cmd_alive(padapter))
315 continue; 310 continue;
316_next: 311_next:
317 pcmd = r8712_dequeue_cmd(&pcmdpriv->cmd_queue); 312 pcmd = r8712_dequeue_cmd(&pcmdpriv->cmd_queue);
@@ -359,13 +354,6 @@ _next:
359 (pcmdpriv->cmd_seq << 24)); 354 (pcmdpriv->cmd_seq << 24));
360 pcmdbuf += 2; /* 8 bytes alignment */ 355 pcmdbuf += 2; /* 8 bytes alignment */
361 memcpy((u8 *)pcmdbuf, pcmd->parmbuf, pcmd->cmdsz); 356 memcpy((u8 *)pcmdbuf, pcmd->parmbuf, pcmd->cmdsz);
362 while (check_cmd_fifo(padapter, wr_sz) == _FAIL) {
363 if (padapter->driver_stopped ||
364 padapter->surprise_removed)
365 break;
366 msleep(100);
367 continue;
368 }
369 if (blnPending) 357 if (blnPending)
370 wr_sz += 8; /* Append 8 bytes */ 358 wr_sz += 8; /* Append 8 bytes */
371 r8712_write_mem(padapter, RTL8712_DMA_H2CCMD, wr_sz, 359 r8712_write_mem(padapter, RTL8712_DMA_H2CCMD, wr_sz,
diff --git a/drivers/staging/rtl8712/rtl8712_recv.c b/drivers/staging/rtl8712/rtl8712_recv.c
index 82ddc0c3ecd4..9901815604f4 100644
--- a/drivers/staging/rtl8712/rtl8712_recv.c
+++ b/drivers/staging/rtl8712/rtl8712_recv.c
@@ -35,11 +35,11 @@ static u8 rfc1042_header[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
35 35
36static void recv_tasklet(void *priv); 36static void recv_tasklet(void *priv);
37 37
38int r8712_init_recv_priv(struct recv_priv *precvpriv, struct _adapter *padapter) 38void r8712_init_recv_priv(struct recv_priv *precvpriv,
39 struct _adapter *padapter)
39{ 40{
40 int i; 41 int i;
41 struct recv_buf *precvbuf; 42 struct recv_buf *precvbuf;
42 int res = _SUCCESS;
43 addr_t tmpaddr = 0; 43 addr_t tmpaddr = 0;
44 int alignment = 0; 44 int alignment = 0;
45 struct sk_buff *pskb = NULL; 45 struct sk_buff *pskb = NULL;
@@ -49,15 +49,14 @@ int r8712_init_recv_priv(struct recv_priv *precvpriv, struct _adapter *padapter)
49 precvpriv->pallocated_recv_buf = 49 precvpriv->pallocated_recv_buf =
50 kzalloc(NR_RECVBUFF * sizeof(struct recv_buf) + 4, GFP_ATOMIC); 50 kzalloc(NR_RECVBUFF * sizeof(struct recv_buf) + 4, GFP_ATOMIC);
51 if (!precvpriv->pallocated_recv_buf) 51 if (!precvpriv->pallocated_recv_buf)
52 return _FAIL; 52 return;
53 precvpriv->precv_buf = precvpriv->pallocated_recv_buf + 4 - 53 precvpriv->precv_buf = precvpriv->pallocated_recv_buf + 4 -
54 ((addr_t)(precvpriv->pallocated_recv_buf) & 3); 54 ((addr_t)(precvpriv->pallocated_recv_buf) & 3);
55 precvbuf = (struct recv_buf *)precvpriv->precv_buf; 55 precvbuf = (struct recv_buf *)precvpriv->precv_buf;
56 for (i = 0; i < NR_RECVBUFF; i++) { 56 for (i = 0; i < NR_RECVBUFF; i++) {
57 INIT_LIST_HEAD(&precvbuf->list); 57 INIT_LIST_HEAD(&precvbuf->list);
58 spin_lock_init(&precvbuf->recvbuf_lock); 58 spin_lock_init(&precvbuf->recvbuf_lock);
59 res = r8712_os_recvbuf_resource_alloc(padapter, precvbuf); 59 if (r8712_os_recvbuf_resource_alloc(padapter, precvbuf))
60 if (res == _FAIL)
61 break; 60 break;
62 precvbuf->ref_cnt = 0; 61 precvbuf->ref_cnt = 0;
63 precvbuf->adapter = padapter; 62 precvbuf->adapter = padapter;
@@ -83,7 +82,6 @@ int r8712_init_recv_priv(struct recv_priv *precvpriv, struct _adapter *padapter)
83 } 82 }
84 pskb = NULL; 83 pskb = NULL;
85 } 84 }
86 return res;
87} 85}
88 86
89void r8712_free_recv_priv(struct recv_priv *precvpriv) 87void r8712_free_recv_priv(struct recv_priv *precvpriv)
@@ -107,7 +105,7 @@ void r8712_free_recv_priv(struct recv_priv *precvpriv)
107 skb_queue_len(&precvpriv->free_recv_skb_queue)); 105 skb_queue_len(&precvpriv->free_recv_skb_queue));
108} 106}
109 107
110int r8712_init_recvbuf(struct _adapter *padapter, struct recv_buf *precvbuf) 108void r8712_init_recvbuf(struct _adapter *padapter, struct recv_buf *precvbuf)
111{ 109{
112 precvbuf->transfer_len = 0; 110 precvbuf->transfer_len = 0;
113 precvbuf->len = 0; 111 precvbuf->len = 0;
@@ -118,10 +116,9 @@ int r8712_init_recvbuf(struct _adapter *padapter, struct recv_buf *precvbuf)
118 precvbuf->ptail = precvbuf->pbuf; 116 precvbuf->ptail = precvbuf->pbuf;
119 precvbuf->pend = precvbuf->pdata + MAX_RECVBUF_SZ; 117 precvbuf->pend = precvbuf->pdata + MAX_RECVBUF_SZ;
120 } 118 }
121 return _SUCCESS;
122} 119}
123 120
124int r8712_free_recvframe(union recv_frame *precvframe, 121void r8712_free_recvframe(union recv_frame *precvframe,
125 struct __queue *pfree_recv_queue) 122 struct __queue *pfree_recv_queue)
126{ 123{
127 unsigned long irqL; 124 unsigned long irqL;
@@ -140,7 +137,6 @@ int r8712_free_recvframe(union recv_frame *precvframe,
140 precvpriv->free_recvframe_cnt++; 137 precvpriv->free_recvframe_cnt++;
141 } 138 }
142 spin_unlock_irqrestore(&pfree_recv_queue->lock, irqL); 139 spin_unlock_irqrestore(&pfree_recv_queue->lock, irqL);
143 return _SUCCESS;
144} 140}
145 141
146static void update_recvframe_attrib_from_recvstat(struct rx_pkt_attrib *pattrib, 142static void update_recvframe_attrib_from_recvstat(struct rx_pkt_attrib *pattrib,
@@ -323,7 +319,7 @@ union recv_frame *r8712_recvframe_chk_defrag(struct _adapter *padapter,
323 return prtnframe; 319 return prtnframe;
324} 320}
325 321
326static int amsdu_to_msdu(struct _adapter *padapter, union recv_frame *prframe) 322static void amsdu_to_msdu(struct _adapter *padapter, union recv_frame *prframe)
327{ 323{
328 int a_len, padding_len; 324 int a_len, padding_len;
329 u16 eth_type, nSubframe_Length; 325 u16 eth_type, nSubframe_Length;
@@ -421,7 +417,6 @@ static int amsdu_to_msdu(struct _adapter *padapter, union recv_frame *prframe)
421exit: 417exit:
422 prframe->u.hdr.len = 0; 418 prframe->u.hdr.len = 0;
423 r8712_free_recvframe(prframe, pfree_recv_queue); 419 r8712_free_recvframe(prframe, pfree_recv_queue);
424 return _SUCCESS;
425} 420}
426 421
427void r8712_rxcmd_event_hdl(struct _adapter *padapter, void *prxcmdbuf) 422void r8712_rxcmd_event_hdl(struct _adapter *padapter, void *prxcmdbuf)
@@ -511,7 +506,6 @@ int r8712_recv_indicatepkts_in_order(struct _adapter *padapter,
511 union recv_frame *prframe; 506 union recv_frame *prframe;
512 struct rx_pkt_attrib *pattrib; 507 struct rx_pkt_attrib *pattrib;
513 int bPktInBuf = false; 508 int bPktInBuf = false;
514 struct recv_priv *precvpriv = &padapter->recvpriv;
515 struct __queue *ppending_recvframe_queue = 509 struct __queue *ppending_recvframe_queue =
516 &preorder_ctrl->pending_recvframe_queue; 510 &preorder_ctrl->pending_recvframe_queue;
517 511
@@ -548,10 +542,7 @@ int r8712_recv_indicatepkts_in_order(struct _adapter *padapter,
548 prframe); 542 prframe);
549 } 543 }
550 } else if (pattrib->amsdu == 1) { 544 } else if (pattrib->amsdu == 1) {
551 if (amsdu_to_msdu(padapter, prframe) != 545 amsdu_to_msdu(padapter, prframe);
552 _SUCCESS)
553 r8712_free_recvframe(prframe,
554 &precvpriv->free_recv_queue);
555 } 546 }
556 /* Update local variables. */ 547 /* Update local variables. */
557 bPktInBuf = false; 548 bPktInBuf = false;
@@ -579,9 +570,9 @@ static int recv_indicatepkt_reorder(struct _adapter *padapter,
579 if (!padapter->driver_stopped && 570 if (!padapter->driver_stopped &&
580 !padapter->surprise_removed) { 571 !padapter->surprise_removed) {
581 r8712_recv_indicatepkt(padapter, prframe); 572 r8712_recv_indicatepkt(padapter, prframe);
582 return _SUCCESS; 573 return 0;
583 } else { 574 } else {
584 return _FAIL; 575 return -EINVAL;
585 } 576 }
586 } 577 }
587 } 578 }
@@ -603,8 +594,7 @@ static int recv_indicatepkt_reorder(struct _adapter *padapter,
603 * 2. All packets with SeqNum larger than or equal to 594 * 2. All packets with SeqNum larger than or equal to
604 * WinStart => Buffer it. 595 * WinStart => Buffer it.
605 */ 596 */
606 if (r8712_recv_indicatepkts_in_order(padapter, preorder_ctrl, false) == 597 if (r8712_recv_indicatepkts_in_order(padapter, preorder_ctrl, false)) {
607 true) {
608 mod_timer(&preorder_ctrl->reordering_ctrl_timer, 598 mod_timer(&preorder_ctrl->reordering_ctrl_timer,
609 jiffies + msecs_to_jiffies(REORDER_WAIT_TIME)); 599 jiffies + msecs_to_jiffies(REORDER_WAIT_TIME));
610 spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql); 600 spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql);
@@ -612,10 +602,10 @@ static int recv_indicatepkt_reorder(struct _adapter *padapter,
612 spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql); 602 spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql);
613 del_timer(&preorder_ctrl->reordering_ctrl_timer); 603 del_timer(&preorder_ctrl->reordering_ctrl_timer);
614 } 604 }
615 return _SUCCESS; 605 return 0;
616_err_exit: 606_err_exit:
617 spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql); 607 spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql);
618 return _FAIL; 608 return -ENOMEM;
619} 609}
620 610
621void r8712_reordering_ctrl_timeout_handler(void *pcontext) 611void r8712_reordering_ctrl_timeout_handler(void *pcontext)
@@ -641,7 +631,7 @@ static int r8712_process_recv_indicatepkts(struct _adapter *padapter,
641 struct ht_priv *phtpriv = &pmlmepriv->htpriv; 631 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
642 632
643 if (phtpriv->ht_option == 1) { /*B/G/N Mode*/ 633 if (phtpriv->ht_option == 1) { /*B/G/N Mode*/
644 if (recv_indicatepkt_reorder(padapter, prframe) != _SUCCESS) { 634 if (recv_indicatepkt_reorder(padapter, prframe)) {
645 /* including perform A-MPDU Rx Ordering Buffer Control*/ 635 /* including perform A-MPDU Rx Ordering Buffer Control*/
646 if (!padapter->driver_stopped && 636 if (!padapter->driver_stopped &&
647 !padapter->surprise_removed) 637 !padapter->surprise_removed)
@@ -649,8 +639,8 @@ static int r8712_process_recv_indicatepkts(struct _adapter *padapter,
649 } 639 }
650 } else { /*B/G mode*/ 640 } else { /*B/G mode*/
651 retval = r8712_wlanhdr_to_ethhdr(prframe); 641 retval = r8712_wlanhdr_to_ethhdr(prframe);
652 if (retval != _SUCCESS) 642 if (retval)
653 return retval; 643 return _FAIL;
654 if (!padapter->driver_stopped && !padapter->surprise_removed) { 644 if (!padapter->driver_stopped && !padapter->surprise_removed) {
655 /* indicate this recv_frame */ 645 /* indicate this recv_frame */
656 r8712_recv_indicatepkt(padapter, prframe); 646 r8712_recv_indicatepkt(padapter, prframe);
@@ -991,7 +981,7 @@ _exit_recv_func:
991 return retval; 981 return retval;
992} 982}
993 983
994static int recvbuf2recvframe(struct _adapter *padapter, struct sk_buff *pskb) 984static void recvbuf2recvframe(struct _adapter *padapter, struct sk_buff *pskb)
995{ 985{
996 u8 *pbuf, shift_sz = 0; 986 u8 *pbuf, shift_sz = 0;
997 u8 frag, mf; 987 u8 frag, mf;
@@ -1018,7 +1008,7 @@ static int recvbuf2recvframe(struct _adapter *padapter, struct sk_buff *pskb)
1018 /* In this case, it means the MAX_RECVBUF_SZ is too small to 1008 /* In this case, it means the MAX_RECVBUF_SZ is too small to
1019 * get the data from 8712u. 1009 * get the data from 8712u.
1020 */ 1010 */
1021 return _FAIL; 1011 return;
1022 } 1012 }
1023 do { 1013 do {
1024 prxstat = (struct recv_stat *)pbuf; 1014 prxstat = (struct recv_stat *)pbuf;
@@ -1031,13 +1021,13 @@ static int recvbuf2recvframe(struct _adapter *padapter, struct sk_buff *pskb)
1031 drvinfo_sz = (le32_to_cpu(prxstat->rxdw0) & 0x000f0000) >> 16; 1021 drvinfo_sz = (le32_to_cpu(prxstat->rxdw0) & 0x000f0000) >> 16;
1032 drvinfo_sz <<= 3; 1022 drvinfo_sz <<= 3;
1033 if (pkt_len <= 0) 1023 if (pkt_len <= 0)
1034 goto _exit_recvbuf2recvframe; 1024 return;
1035 /* Qos data, wireless lan header length is 26 */ 1025 /* Qos data, wireless lan header length is 26 */
1036 if ((le32_to_cpu(prxstat->rxdw0) >> 23) & 0x01) 1026 if ((le32_to_cpu(prxstat->rxdw0) >> 23) & 0x01)
1037 shift_sz = 2; 1027 shift_sz = 2;
1038 precvframe = r8712_alloc_recvframe(pfree_recv_queue); 1028 precvframe = r8712_alloc_recvframe(pfree_recv_queue);
1039 if (!precvframe) 1029 if (!precvframe)
1040 goto _exit_recvbuf2recvframe; 1030 return;
1041 INIT_LIST_HEAD(&precvframe->u.hdr.list); 1031 INIT_LIST_HEAD(&precvframe->u.hdr.list);
1042 precvframe->u.hdr.precvbuf = NULL; /*can't access the precvbuf*/ 1032 precvframe->u.hdr.precvbuf = NULL; /*can't access the precvbuf*/
1043 precvframe->u.hdr.len = 0; 1033 precvframe->u.hdr.len = 0;
@@ -1068,7 +1058,7 @@ static int recvbuf2recvframe(struct _adapter *padapter, struct sk_buff *pskb)
1068 } else { 1058 } else {
1069 precvframe->u.hdr.pkt = skb_clone(pskb, GFP_ATOMIC); 1059 precvframe->u.hdr.pkt = skb_clone(pskb, GFP_ATOMIC);
1070 if (!precvframe->u.hdr.pkt) 1060 if (!precvframe->u.hdr.pkt)
1071 return _FAIL; 1061 return;
1072 precvframe->u.hdr.rx_head = pbuf; 1062 precvframe->u.hdr.rx_head = pbuf;
1073 precvframe->u.hdr.rx_data = pbuf; 1063 precvframe->u.hdr.rx_data = pbuf;
1074 precvframe->u.hdr.rx_tail = pbuf; 1064 precvframe->u.hdr.rx_tail = pbuf;
@@ -1088,8 +1078,6 @@ static int recvbuf2recvframe(struct _adapter *padapter, struct sk_buff *pskb)
1088 precvframe = NULL; 1078 precvframe = NULL;
1089 pkt_copy = NULL; 1079 pkt_copy = NULL;
1090 } while ((transfer_len > 0) && pkt_cnt > 0); 1080 } while ((transfer_len > 0) && pkt_cnt > 0);
1091_exit_recvbuf2recvframe:
1092 return _SUCCESS;
1093} 1081}
1094 1082
1095static void recv_tasklet(void *priv) 1083static void recv_tasklet(void *priv)
diff --git a/drivers/staging/rtl8712/rtl8712_recv.h b/drivers/staging/rtl8712/rtl8712_recv.h
index 6954c5bfbcaf..3e385b2242d8 100644
--- a/drivers/staging/rtl8712/rtl8712_recv.h
+++ b/drivers/staging/rtl8712/rtl8712_recv.h
@@ -136,7 +136,7 @@ union recv_frame {
136 } u; 136 } u;
137}; 137};
138 138
139int r8712_init_recvbuf(struct _adapter *padapter, struct recv_buf *precvbuf); 139void r8712_init_recvbuf(struct _adapter *padapter, struct recv_buf *precvbuf);
140void r8712_rxcmd_event_hdl(struct _adapter *padapter, void *prxcmdbuf); 140void r8712_rxcmd_event_hdl(struct _adapter *padapter, void *prxcmdbuf);
141s32 r8712_signal_scale_mapping(s32 cur_sig); 141s32 r8712_signal_scale_mapping(s32 cur_sig);
142void r8712_reordering_ctrl_timeout_handler(void *pcontext); 142void r8712_reordering_ctrl_timeout_handler(void *pcontext);
diff --git a/drivers/staging/rtl8712/rtl8712_xmit.c b/drivers/staging/rtl8712/rtl8712_xmit.c
index 307b0e292976..c247f92207f5 100644
--- a/drivers/staging/rtl8712/rtl8712_xmit.c
+++ b/drivers/staging/rtl8712/rtl8712_xmit.c
@@ -246,7 +246,7 @@ void r8712_do_queue_select(struct _adapter *padapter,
246} 246}
247 247
248#ifdef CONFIG_R8712_TX_AGGR 248#ifdef CONFIG_R8712_TX_AGGR
249u8 r8712_construct_txaggr_cmd_desc(struct xmit_buf *pxmitbuf) 249void r8712_construct_txaggr_cmd_desc(struct xmit_buf *pxmitbuf)
250{ 250{
251 struct tx_desc *ptx_desc = (struct tx_desc *)pxmitbuf->pbuf; 251 struct tx_desc *ptx_desc = (struct tx_desc *)pxmitbuf->pbuf;
252 252
@@ -260,11 +260,9 @@ u8 r8712_construct_txaggr_cmd_desc(struct xmit_buf *pxmitbuf)
260 260
261 /* dw1 */ 261 /* dw1 */
262 ptx_desc->txdw1 |= cpu_to_le32((0x13 << QSEL_SHT) & 0x00001f00); 262 ptx_desc->txdw1 |= cpu_to_le32((0x13 << QSEL_SHT) & 0x00001f00);
263
264 return _SUCCESS;
265} 263}
266 264
267u8 r8712_construct_txaggr_cmd_hdr(struct xmit_buf *pxmitbuf) 265void r8712_construct_txaggr_cmd_hdr(struct xmit_buf *pxmitbuf)
268{ 266{
269 struct xmit_frame *pxmitframe = (struct xmit_frame *) 267 struct xmit_frame *pxmitframe = (struct xmit_frame *)
270 pxmitbuf->priv_data; 268 pxmitbuf->priv_data;
@@ -278,12 +276,10 @@ u8 r8712_construct_txaggr_cmd_hdr(struct xmit_buf *pxmitbuf)
278 pcmd_hdr->cmd_dw0 = cpu_to_le32((GEN_CMD_CODE(_AMSDU_TO_AMPDU) << 16) | 276 pcmd_hdr->cmd_dw0 = cpu_to_le32((GEN_CMD_CODE(_AMSDU_TO_AMPDU) << 16) |
279 (pcmdpriv->cmd_seq << 24)); 277 (pcmdpriv->cmd_seq << 24));
280 pcmdpriv->cmd_seq++; 278 pcmdpriv->cmd_seq++;
281
282 return _SUCCESS;
283} 279}
284 280
285u8 r8712_append_mpdu_unit(struct xmit_buf *pxmitbuf, 281void r8712_append_mpdu_unit(struct xmit_buf *pxmitbuf,
286 struct xmit_frame *pxmitframe) 282 struct xmit_frame *pxmitframe)
287{ 283{
288 struct _adapter *padapter = pxmitframe->padapter; 284 struct _adapter *padapter = pxmitframe->padapter;
289 struct tx_desc *ptx_desc = (struct tx_desc *)pxmitbuf->pbuf; 285 struct tx_desc *ptx_desc = (struct tx_desc *)pxmitbuf->pbuf;
@@ -319,13 +315,11 @@ u8 r8712_append_mpdu_unit(struct xmit_buf *pxmitbuf,
319 ((ptx_desc->txdw0 & 0x0000ffff) + 315 ((ptx_desc->txdw0 & 0x0000ffff) +
320 ((TXDESC_SIZE + last_txcmdsz + padding_sz) & 316 ((TXDESC_SIZE + last_txcmdsz + padding_sz) &
321 0x0000ffff))); 317 0x0000ffff)));
322
323 return _SUCCESS;
324} 318}
325 319
326 320
327u8 r8712_xmitframe_aggr_1st(struct xmit_buf *pxmitbuf, 321void r8712_xmitframe_aggr_1st(struct xmit_buf *pxmitbuf,
328 struct xmit_frame *pxmitframe) 322 struct xmit_frame *pxmitframe)
329{ 323{
330 /* linux complete context doesn't need to protect */ 324 /* linux complete context doesn't need to protect */
331 pxmitframe->pxmitbuf = pxmitbuf; 325 pxmitframe->pxmitbuf = pxmitbuf;
@@ -336,10 +330,8 @@ u8 r8712_xmitframe_aggr_1st(struct xmit_buf *pxmitbuf,
336 /*RTL8712_DMA_H2CCMD */ 330 /*RTL8712_DMA_H2CCMD */
337 r8712_construct_txaggr_cmd_desc(pxmitbuf); 331 r8712_construct_txaggr_cmd_desc(pxmitbuf);
338 r8712_construct_txaggr_cmd_hdr(pxmitbuf); 332 r8712_construct_txaggr_cmd_hdr(pxmitbuf);
339 if (r8712_append_mpdu_unit(pxmitbuf, pxmitframe) == _SUCCESS) 333 r8712_append_mpdu_unit(pxmitbuf, pxmitframe);
340 pxmitbuf->aggr_nr = 1; 334 pxmitbuf->aggr_nr = 1;
341
342 return _SUCCESS;
343} 335}
344 336
345u16 r8712_xmitframe_aggr_next(struct xmit_buf *pxmitbuf, 337u16 r8712_xmitframe_aggr_next(struct xmit_buf *pxmitbuf,
@@ -351,18 +343,17 @@ u16 r8712_xmitframe_aggr_next(struct xmit_buf *pxmitbuf,
351 /* buffer addr assoc */ 343 /* buffer addr assoc */
352 pxmitframe->buf_addr = pxmitbuf->pbuf + TXDESC_SIZE + 344 pxmitframe->buf_addr = pxmitbuf->pbuf + TXDESC_SIZE +
353 (((struct tx_desc *)pxmitbuf->pbuf)->txdw0 & 0x0000ffff); 345 (((struct tx_desc *)pxmitbuf->pbuf)->txdw0 & 0x0000ffff);
354 if (r8712_append_mpdu_unit(pxmitbuf, pxmitframe) == _SUCCESS) { 346 r8712_append_mpdu_unit(pxmitbuf, pxmitframe);
355 r8712_free_xmitframe_ex(&pxmitframe->padapter->xmitpriv, 347 r8712_free_xmitframe_ex(&pxmitframe->padapter->xmitpriv,
356 pxmitframe); 348 pxmitframe);
357 pxmitbuf->aggr_nr++; 349 pxmitbuf->aggr_nr++;
358 }
359 350
360 return TXDESC_SIZE + 351 return TXDESC_SIZE +
361 (((struct tx_desc *)pxmitbuf->pbuf)->txdw0 & 0x0000ffff); 352 (((struct tx_desc *)pxmitbuf->pbuf)->txdw0 & 0x0000ffff);
362} 353}
363 354
364u8 r8712_dump_aggr_xframe(struct xmit_buf *pxmitbuf, 355void r8712_dump_aggr_xframe(struct xmit_buf *pxmitbuf,
365 struct xmit_frame *pxmitframe) 356 struct xmit_frame *pxmitframe)
366{ 357{
367 struct _adapter *padapter = pxmitframe->padapter; 358 struct _adapter *padapter = pxmitframe->padapter;
368 struct dvobj_priv *pdvobj = &padapter->dvobjpriv; 359 struct dvobj_priv *pdvobj = &padapter->dvobjpriv;
@@ -399,8 +390,6 @@ u8 r8712_dump_aggr_xframe(struct xmit_buf *pxmitbuf,
399 } 390 }
400 r8712_write_port(pxmitframe->padapter, RTL8712_DMA_H2CCMD, 391 r8712_write_port(pxmitframe->padapter, RTL8712_DMA_H2CCMD,
401 total_length + TXDESC_SIZE, (u8 *)pxmitframe); 392 total_length + TXDESC_SIZE, (u8 *)pxmitframe);
402
403 return _SUCCESS;
404} 393}
405 394
406#endif 395#endif
@@ -737,20 +726,19 @@ static void dump_xframe(struct _adapter *padapter,
737 } 726 }
738} 727}
739 728
740int r8712_xmit_direct(struct _adapter *padapter, struct xmit_frame *pxmitframe) 729void r8712_xmit_direct(struct _adapter *padapter, struct xmit_frame *pxmitframe)
741{ 730{
742 int res = _SUCCESS; 731 int res;
743 732
744 res = r8712_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe); 733 res = r8712_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe);
745 pxmitframe->pkt = NULL; 734 pxmitframe->pkt = NULL;
746 if (res == _SUCCESS) 735 if (res == _SUCCESS)
747 dump_xframe(padapter, pxmitframe); 736 dump_xframe(padapter, pxmitframe);
748 return res;
749} 737}
750 738
751int r8712_xmit_enqueue(struct _adapter *padapter, struct xmit_frame *pxmitframe) 739int r8712_xmit_enqueue(struct _adapter *padapter, struct xmit_frame *pxmitframe)
752{ 740{
753 if (r8712_xmit_classifier(padapter, pxmitframe) == _FAIL) { 741 if (r8712_xmit_classifier(padapter, pxmitframe)) {
754 pxmitframe->pkt = NULL; 742 pxmitframe->pkt = NULL;
755 return _FAIL; 743 return _FAIL;
756 } 744 }
diff --git a/drivers/staging/rtl8712/rtl8712_xmit.h b/drivers/staging/rtl8712/rtl8712_xmit.h
index 9be8fb70c92e..0b56bd3ac4d0 100644
--- a/drivers/staging/rtl8712/rtl8712_xmit.h
+++ b/drivers/staging/rtl8712/rtl8712_xmit.h
@@ -102,10 +102,10 @@ void r8712_do_queue_select(struct _adapter *padapter,
102 struct pkt_attrib *pattrib); 102 struct pkt_attrib *pattrib);
103 103
104#ifdef CONFIG_R8712_TX_AGGR 104#ifdef CONFIG_R8712_TX_AGGR
105u8 r8712_xmitframe_aggr_1st(struct xmit_buf *pxmitbuf, 105void r8712_xmitframe_aggr_1st(struct xmit_buf *pxmitbuf,
106 struct xmit_frame *pxmitframe); 106 struct xmit_frame *pxmitframe);
107u8 r8712_dump_aggr_xframe(struct xmit_buf *pxmitbuf, 107void r8712_dump_aggr_xframe(struct xmit_buf *pxmitbuf,
108 struct xmit_frame *pxmitframe); 108 struct xmit_frame *pxmitframe);
109#endif 109#endif
110 110
111#endif 111#endif
diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
index 28941423b7ed..c20dd5a6bbd1 100644
--- a/drivers/staging/rtl8712/rtl871x_io.h
+++ b/drivers/staging/rtl8712/rtl871x_io.h
@@ -11,8 +11,8 @@
11 * Larry Finger <Larry.Finger@lwfinger.net> 11 * Larry Finger <Larry.Finger@lwfinger.net>
12 * 12 *
13 ******************************************************************************/ 13 ******************************************************************************/
14#ifndef _IO_H_ 14#ifndef _RTL871X_IO_H_
15#define _IO_H_ 15#define _RTL871X_IO_H_
16 16
17#include "osdep_service.h" 17#include "osdep_service.h"
18#include "osdep_intf.h" 18#include "osdep_intf.h"
@@ -234,5 +234,4 @@ void r8712_write_port(struct _adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
234uint r8712_alloc_io_queue(struct _adapter *adapter); 234uint r8712_alloc_io_queue(struct _adapter *adapter);
235void r8712_free_io_queue(struct _adapter *adapter); 235void r8712_free_io_queue(struct _adapter *adapter);
236 236
237#endif /*_RTL8711_IO_H_*/ 237#endif /*_RTL871X_IO_H_*/
238
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index b08b9a191a34..944336e0d2e2 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -419,8 +419,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
419 pwep->KeyIndex |= 0x80000000; 419 pwep->KeyIndex |= 0x80000000;
420 memcpy(pwep->KeyMaterial, param->u.crypt.key, pwep->KeyLength); 420 memcpy(pwep->KeyMaterial, param->u.crypt.key, pwep->KeyLength);
421 if (param->u.crypt.set_tx) { 421 if (param->u.crypt.set_tx) {
422 if (r8712_set_802_11_add_wep(padapter, pwep) == 422 if (r8712_set_802_11_add_wep(padapter, pwep))
423 (u8)_FAIL)
424 ret = -EOPNOTSUPP; 423 ret = -EOPNOTSUPP;
425 } else { 424 } else {
426 /* don't update "psecuritypriv->PrivacyAlgrthm" and 425 /* don't update "psecuritypriv->PrivacyAlgrthm" and
@@ -1585,7 +1584,7 @@ static int r8711_wx_set_enc(struct net_device *dev,
1585 } 1584 }
1586 wep.KeyIndex |= 0x80000000; /* transmit key */ 1585 wep.KeyIndex |= 0x80000000; /* transmit key */
1587 memcpy(wep.KeyMaterial, keybuf, wep.KeyLength); 1586 memcpy(wep.KeyMaterial, keybuf, wep.KeyLength);
1588 if (r8712_set_802_11_add_wep(padapter, &wep) == _FAIL) 1587 if (r8712_set_802_11_add_wep(padapter, &wep))
1589 return -EOPNOTSUPP; 1588 return -EOPNOTSUPP;
1590 return 0; 1589 return 0;
1591} 1590}
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_set.c b/drivers/staging/rtl8712/rtl871x_ioctl_set.c
index f3c0a9348f56..6cdc6f1a6bc6 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_set.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_set.c
@@ -320,22 +320,22 @@ u8 r8712_set_802_11_authentication_mode(struct _adapter *padapter,
320 psecuritypriv->ndisauthtype = authmode; 320 psecuritypriv->ndisauthtype = authmode;
321 if (psecuritypriv->ndisauthtype > 3) 321 if (psecuritypriv->ndisauthtype > 3)
322 psecuritypriv->AuthAlgrthm = 2; /* 802.1x */ 322 psecuritypriv->AuthAlgrthm = 2; /* 802.1x */
323 if (r8712_set_auth(padapter, psecuritypriv) == _SUCCESS) 323 if (r8712_set_auth(padapter, psecuritypriv))
324 ret = true;
325 else
326 ret = false; 324 ret = false;
325 else
326 ret = true;
327 return ret; 327 return ret;
328} 328}
329 329
330u8 r8712_set_802_11_add_wep(struct _adapter *padapter, 330int r8712_set_802_11_add_wep(struct _adapter *padapter,
331 struct NDIS_802_11_WEP *wep) 331 struct NDIS_802_11_WEP *wep)
332{ 332{
333 sint keyid; 333 sint keyid;
334 struct security_priv *psecuritypriv = &padapter->securitypriv; 334 struct security_priv *psecuritypriv = &padapter->securitypriv;
335 335
336 keyid = wep->KeyIndex & 0x3fffffff; 336 keyid = wep->KeyIndex & 0x3fffffff;
337 if (keyid >= WEP_KEYS) 337 if (keyid >= WEP_KEYS)
338 return false; 338 return -EINVAL;
339 switch (wep->KeyLength) { 339 switch (wep->KeyLength) {
340 case 5: 340 case 5:
341 psecuritypriv->PrivacyAlgrthm = _WEP40_; 341 psecuritypriv->PrivacyAlgrthm = _WEP40_;
@@ -351,7 +351,5 @@ u8 r8712_set_802_11_add_wep(struct _adapter *padapter,
351 wep->KeyLength); 351 wep->KeyLength);
352 psecuritypriv->DefKeylen[keyid] = wep->KeyLength; 352 psecuritypriv->DefKeylen[keyid] = wep->KeyLength;
353 psecuritypriv->PrivacyKeyIndex = keyid; 353 psecuritypriv->PrivacyKeyIndex = keyid;
354 if (r8712_set_key(padapter, psecuritypriv, keyid) == _FAIL) 354 return r8712_set_key(padapter, psecuritypriv, keyid);
355 return false;
356 return _SUCCESS;
357} 355}
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_set.h b/drivers/staging/rtl8712/rtl871x_ioctl_set.h
index 8b1085aea962..e2de820f61d9 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_set.h
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_set.h
@@ -28,8 +28,8 @@ u8 r8712_set_802_11_authentication_mode(struct _adapter *pdapter,
28 28
29u8 r8712_set_802_11_bssid(struct _adapter *padapter, u8 *bssid); 29u8 r8712_set_802_11_bssid(struct _adapter *padapter, u8 *bssid);
30 30
31u8 r8712_set_802_11_add_wep(struct _adapter *padapter, 31int r8712_set_802_11_add_wep(struct _adapter *padapter,
32 struct NDIS_802_11_WEP *wep); 32 struct NDIS_802_11_WEP *wep);
33 33
34u8 r8712_set_802_11_disassociate(struct _adapter *padapter); 34u8 r8712_set_802_11_disassociate(struct _adapter *padapter);
35 35
diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c b/drivers/staging/rtl8712/rtl871x_mlme.c
index 0cc879a4d43f..cabdb3549a5a 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.c
+++ b/drivers/staging/rtl8712/rtl871x_mlme.c
@@ -53,7 +53,7 @@ int r8712_init_mlme_priv(struct _adapter *padapter)
53 pbuf = kmalloc_array(MAX_BSS_CNT, sizeof(struct wlan_network), 53 pbuf = kmalloc_array(MAX_BSS_CNT, sizeof(struct wlan_network),
54 GFP_ATOMIC); 54 GFP_ATOMIC);
55 if (!pbuf) 55 if (!pbuf)
56 return _FAIL; 56 return -ENOMEM;
57 pmlmepriv->free_bss_buf = pbuf; 57 pmlmepriv->free_bss_buf = pbuf;
58 pnetwork = (struct wlan_network *)pbuf; 58 pnetwork = (struct wlan_network *)pbuf;
59 for (i = 0; i < MAX_BSS_CNT; i++) { 59 for (i = 0; i < MAX_BSS_CNT; i++) {
@@ -67,7 +67,7 @@ int r8712_init_mlme_priv(struct _adapter *padapter)
67 pmlmepriv->sitesurveyctrl.traffic_busy = false; 67 pmlmepriv->sitesurveyctrl.traffic_busy = false;
68 /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */ 68 /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
69 r8712_init_mlme_timer(padapter); 69 r8712_init_mlme_timer(padapter);
70 return _SUCCESS; 70 return 0;
71} 71}
72 72
73struct wlan_network *_r8712_alloc_network(struct mlme_priv *pmlmepriv) 73struct wlan_network *_r8712_alloc_network(struct mlme_priv *pmlmepriv)
@@ -1144,8 +1144,8 @@ ask_for_joinbss:
1144 return r8712_joinbss_cmd(adapter, pnetwork); 1144 return r8712_joinbss_cmd(adapter, pnetwork);
1145} 1145}
1146 1146
1147sint r8712_set_auth(struct _adapter *adapter, 1147int r8712_set_auth(struct _adapter *adapter,
1148 struct security_priv *psecuritypriv) 1148 struct security_priv *psecuritypriv)
1149{ 1149{
1150 struct cmd_priv *pcmdpriv = &adapter->cmdpriv; 1150 struct cmd_priv *pcmdpriv = &adapter->cmdpriv;
1151 struct cmd_obj *pcmd; 1151 struct cmd_obj *pcmd;
@@ -1153,12 +1153,12 @@ sint r8712_set_auth(struct _adapter *adapter,
1153 1153
1154 pcmd = kmalloc(sizeof(*pcmd), GFP_ATOMIC); 1154 pcmd = kmalloc(sizeof(*pcmd), GFP_ATOMIC);
1155 if (!pcmd) 1155 if (!pcmd)
1156 return _FAIL; 1156 return -ENOMEM;
1157 1157
1158 psetauthparm = kzalloc(sizeof(*psetauthparm), GFP_ATOMIC); 1158 psetauthparm = kzalloc(sizeof(*psetauthparm), GFP_ATOMIC);
1159 if (!psetauthparm) { 1159 if (!psetauthparm) {
1160 kfree(pcmd); 1160 kfree(pcmd);
1161 return _FAIL; 1161 return -ENOMEM;
1162 } 1162 }
1163 psetauthparm->mode = (u8)psecuritypriv->AuthAlgrthm; 1163 psetauthparm->mode = (u8)psecuritypriv->AuthAlgrthm;
1164 pcmd->cmdcode = _SetAuth_CMD_; 1164 pcmd->cmdcode = _SetAuth_CMD_;
@@ -1168,25 +1168,25 @@ sint r8712_set_auth(struct _adapter *adapter,
1168 pcmd->rspsz = 0; 1168 pcmd->rspsz = 0;
1169 INIT_LIST_HEAD(&pcmd->list); 1169 INIT_LIST_HEAD(&pcmd->list);
1170 r8712_enqueue_cmd(pcmdpriv, pcmd); 1170 r8712_enqueue_cmd(pcmdpriv, pcmd);
1171 return _SUCCESS; 1171 return 0;
1172} 1172}
1173 1173
1174sint r8712_set_key(struct _adapter *adapter, 1174int r8712_set_key(struct _adapter *adapter,
1175 struct security_priv *psecuritypriv, 1175 struct security_priv *psecuritypriv,
1176 sint keyid) 1176 sint keyid)
1177{ 1177{
1178 struct cmd_priv *pcmdpriv = &adapter->cmdpriv; 1178 struct cmd_priv *pcmdpriv = &adapter->cmdpriv;
1179 struct cmd_obj *pcmd; 1179 struct cmd_obj *pcmd;
1180 struct setkey_parm *psetkeyparm; 1180 struct setkey_parm *psetkeyparm;
1181 u8 keylen; 1181 u8 keylen;
1182 sint ret = _SUCCESS; 1182 int ret;
1183 1183
1184 pcmd = kmalloc(sizeof(*pcmd), GFP_ATOMIC); 1184 pcmd = kmalloc(sizeof(*pcmd), GFP_ATOMIC);
1185 if (!pcmd) 1185 if (!pcmd)
1186 return _FAIL; 1186 return -ENOMEM;
1187 psetkeyparm = kzalloc(sizeof(*psetkeyparm), GFP_ATOMIC); 1187 psetkeyparm = kzalloc(sizeof(*psetkeyparm), GFP_ATOMIC);
1188 if (!psetkeyparm) { 1188 if (!psetkeyparm) {
1189 ret = _FAIL; 1189 ret = -ENOMEM;
1190 goto err_free_cmd; 1190 goto err_free_cmd;
1191 } 1191 }
1192 if (psecuritypriv->AuthAlgrthm == 2) { /* 802.1X */ 1192 if (psecuritypriv->AuthAlgrthm == 2) { /* 802.1X */
@@ -1211,7 +1211,7 @@ sint r8712_set_key(struct _adapter *adapter,
1211 break; 1211 break;
1212 case _TKIP_: 1212 case _TKIP_:
1213 if (keyid < 1 || keyid > 2) { 1213 if (keyid < 1 || keyid > 2) {
1214 ret = _FAIL; 1214 ret = -EINVAL;
1215 goto err_free_parm; 1215 goto err_free_parm;
1216 } 1216 }
1217 keylen = 16; 1217 keylen = 16;
@@ -1221,7 +1221,7 @@ sint r8712_set_key(struct _adapter *adapter,
1221 break; 1221 break;
1222 case _AES_: 1222 case _AES_:
1223 if (keyid < 1 || keyid > 2) { 1223 if (keyid < 1 || keyid > 2) {
1224 ret = _FAIL; 1224 ret = -EINVAL;
1225 goto err_free_parm; 1225 goto err_free_parm;
1226 } 1226 }
1227 keylen = 16; 1227 keylen = 16;
@@ -1230,7 +1230,7 @@ sint r8712_set_key(struct _adapter *adapter,
1230 psetkeyparm->grpkey = 1; 1230 psetkeyparm->grpkey = 1;
1231 break; 1231 break;
1232 default: 1232 default:
1233 ret = _FAIL; 1233 ret = -EINVAL;
1234 goto err_free_parm; 1234 goto err_free_parm;
1235 } 1235 }
1236 pcmd->cmdcode = _SetKey_CMD_; 1236 pcmd->cmdcode = _SetKey_CMD_;
@@ -1240,7 +1240,7 @@ sint r8712_set_key(struct _adapter *adapter,
1240 pcmd->rspsz = 0; 1240 pcmd->rspsz = 0;
1241 INIT_LIST_HEAD(&pcmd->list); 1241 INIT_LIST_HEAD(&pcmd->list);
1242 r8712_enqueue_cmd(pcmdpriv, pcmd); 1242 r8712_enqueue_cmd(pcmdpriv, pcmd);
1243 return ret; 1243 return 0;
1244 1244
1245err_free_parm: 1245err_free_parm:
1246 kfree(psetkeyparm); 1246 kfree(psetkeyparm);
diff --git a/drivers/staging/rtl8712/rtl871x_mlme.h b/drivers/staging/rtl8712/rtl871x_mlme.h
index a160107e9801..46effb469fd4 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.h
+++ b/drivers/staging/rtl8712/rtl871x_mlme.h
@@ -173,10 +173,10 @@ void r8712_free_network_queue(struct _adapter *adapter);
173int r8712_init_mlme_priv(struct _adapter *adapter); 173int r8712_init_mlme_priv(struct _adapter *adapter);
174void r8712_free_mlme_priv(struct mlme_priv *pmlmepriv); 174void r8712_free_mlme_priv(struct mlme_priv *pmlmepriv);
175int r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv); 175int r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv);
176sint r8712_set_key(struct _adapter *adapter, 176int r8712_set_key(struct _adapter *adapter,
177 struct security_priv *psecuritypriv, sint keyid); 177 struct security_priv *psecuritypriv, sint keyid);
178sint r8712_set_auth(struct _adapter *adapter, 178int r8712_set_auth(struct _adapter *adapter,
179 struct security_priv *psecuritypriv); 179 struct security_priv *psecuritypriv);
180uint r8712_get_wlan_bssid_ex_sz(struct wlan_bssid_ex *bss); 180uint r8712_get_wlan_bssid_ex_sz(struct wlan_bssid_ex *bss);
181void r8712_generate_random_ibss(u8 *pibss); 181void r8712_generate_random_ibss(u8 *pibss);
182u8 *r8712_get_capability_from_ie(u8 *ie); 182u8 *r8712_get_capability_from_ie(u8 *ie);
diff --git a/drivers/staging/rtl8712/rtl871x_mp.c b/drivers/staging/rtl8712/rtl871x_mp.c
index edd3da05fc06..1a39a96b726f 100644
--- a/drivers/staging/rtl8712/rtl871x_mp.c
+++ b/drivers/staging/rtl8712/rtl871x_mp.c
@@ -35,7 +35,7 @@ static void _init_mp_priv_(struct mp_priv *pmp_priv)
35 35
36static int init_mp_priv(struct mp_priv *pmp_priv) 36static int init_mp_priv(struct mp_priv *pmp_priv)
37{ 37{
38 int i, res; 38 int i;
39 struct mp_xmit_frame *pmp_xmitframe; 39 struct mp_xmit_frame *pmp_xmitframe;
40 40
41 _init_mp_priv_(pmp_priv); 41 _init_mp_priv_(pmp_priv);
@@ -45,8 +45,7 @@ static int init_mp_priv(struct mp_priv *pmp_priv)
45 sizeof(struct mp_xmit_frame) + 4, 45 sizeof(struct mp_xmit_frame) + 4,
46 GFP_ATOMIC); 46 GFP_ATOMIC);
47 if (!pmp_priv->pallocated_mp_xmitframe_buf) { 47 if (!pmp_priv->pallocated_mp_xmitframe_buf) {
48 res = _FAIL; 48 return -ENOMEM;
49 goto _exit_init_mp_priv;
50 } 49 }
51 pmp_priv->pmp_xmtframe_buf = pmp_priv->pallocated_mp_xmitframe_buf + 50 pmp_priv->pmp_xmtframe_buf = pmp_priv->pallocated_mp_xmitframe_buf +
52 4 - 51 4 -
@@ -62,9 +61,7 @@ static int init_mp_priv(struct mp_priv *pmp_priv)
62 pmp_xmitframe++; 61 pmp_xmitframe++;
63 } 62 }
64 pmp_priv->free_mp_xmitframe_cnt = NR_MP_XMITFRAME; 63 pmp_priv->free_mp_xmitframe_cnt = NR_MP_XMITFRAME;
65 res = _SUCCESS; 64 return 0;
66_exit_init_mp_priv:
67 return res;
68} 65}
69 66
70static int free_mp_priv(struct mp_priv *pmp_priv) 67static int free_mp_priv(struct mp_priv *pmp_priv)
diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.c b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
index 2beafc7742b3..23cff43437e2 100644
--- a/drivers/staging/rtl8712/rtl871x_pwrctrl.c
+++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
@@ -184,19 +184,19 @@ void r8712_init_pwrctrl_priv(struct _adapter *padapter)
184 * will raise the cpwm to be greater than or equal to P2. 184 * will raise the cpwm to be greater than or equal to P2.
185 * Calling Context: Passive 185 * Calling Context: Passive
186 * Return Value: 186 * Return Value:
187 * _SUCCESS: r8712_cmd_thread can issue cmds to firmware afterwards. 187 * 0: r8712_cmd_thread can issue cmds to firmware afterwards.
188 * _FAIL: r8712_cmd_thread can not do anything. 188 * -EINVAL: r8712_cmd_thread can not do anything.
189 */ 189 */
190sint r8712_register_cmd_alive(struct _adapter *padapter) 190int r8712_register_cmd_alive(struct _adapter *padapter)
191{ 191{
192 uint res = _SUCCESS; 192 int res = 0;
193 struct pwrctrl_priv *pwrctrl = &padapter->pwrctrlpriv; 193 struct pwrctrl_priv *pwrctrl = &padapter->pwrctrlpriv;
194 194
195 mutex_lock(&pwrctrl->mutex_lock); 195 mutex_lock(&pwrctrl->mutex_lock);
196 register_task_alive(pwrctrl, CMD_ALIVE); 196 register_task_alive(pwrctrl, CMD_ALIVE);
197 if (pwrctrl->cpwm < PS_STATE_S2) { 197 if (pwrctrl->cpwm < PS_STATE_S2) {
198 r8712_set_rpwm(padapter, PS_STATE_S3); 198 r8712_set_rpwm(padapter, PS_STATE_S3);
199 res = _FAIL; 199 res = -EINVAL;
200 } 200 }
201 mutex_unlock(&pwrctrl->mutex_lock); 201 mutex_unlock(&pwrctrl->mutex_lock);
202 return res; 202 return res;
diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.h b/drivers/staging/rtl8712/rtl871x_pwrctrl.h
index 11b5034f203d..dd5a79f90b1a 100644
--- a/drivers/staging/rtl8712/rtl871x_pwrctrl.h
+++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.h
@@ -104,7 +104,7 @@ struct pwrctrl_priv {
104}; 104};
105 105
106void r8712_init_pwrctrl_priv(struct _adapter *adapter); 106void r8712_init_pwrctrl_priv(struct _adapter *adapter);
107sint r8712_register_cmd_alive(struct _adapter *padapter); 107int r8712_register_cmd_alive(struct _adapter *padapter);
108void r8712_unregister_cmd_alive(struct _adapter *padapter); 108void r8712_unregister_cmd_alive(struct _adapter *padapter);
109void r8712_cpwm_int_hdl(struct _adapter *padapter, 109void r8712_cpwm_int_hdl(struct _adapter *padapter,
110 struct reportpwrstate_parm *preportpwrstate); 110 struct reportpwrstate_parm *preportpwrstate);
diff --git a/drivers/staging/rtl8712/rtl871x_recv.c b/drivers/staging/rtl8712/rtl871x_recv.c
index 5298fe603437..e5092b6da4bd 100644
--- a/drivers/staging/rtl8712/rtl871x_recv.c
+++ b/drivers/staging/rtl8712/rtl871x_recv.c
@@ -48,7 +48,7 @@ void _r8712_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv)
48 _init_queue(&psta_recvpriv->defrag_q); 48 _init_queue(&psta_recvpriv->defrag_q);
49} 49}
50 50
51sint _r8712_init_recv_priv(struct recv_priv *precvpriv, 51void _r8712_init_recv_priv(struct recv_priv *precvpriv,
52 struct _adapter *padapter) 52 struct _adapter *padapter)
53{ 53{
54 sint i; 54 sint i;
@@ -64,7 +64,7 @@ sint _r8712_init_recv_priv(struct recv_priv *precvpriv,
64 sizeof(union recv_frame) + RXFRAME_ALIGN_SZ, 64 sizeof(union recv_frame) + RXFRAME_ALIGN_SZ,
65 GFP_ATOMIC); 65 GFP_ATOMIC);
66 if (precvpriv->pallocated_frame_buf == NULL) 66 if (precvpriv->pallocated_frame_buf == NULL)
67 return _FAIL; 67 return;
68 kmemleak_not_leak(precvpriv->pallocated_frame_buf); 68 kmemleak_not_leak(precvpriv->pallocated_frame_buf);
69 precvpriv->precv_frame_buf = precvpriv->pallocated_frame_buf + 69 precvpriv->precv_frame_buf = precvpriv->pallocated_frame_buf +
70 RXFRAME_ALIGN_SZ - 70 RXFRAME_ALIGN_SZ -
@@ -80,7 +80,7 @@ sint _r8712_init_recv_priv(struct recv_priv *precvpriv,
80 precvframe++; 80 precvframe++;
81 } 81 }
82 precvpriv->rx_pending_cnt = 1; 82 precvpriv->rx_pending_cnt = 1;
83 return r8712_init_recv_priv(precvpriv, padapter); 83 r8712_init_recv_priv(precvpriv, padapter);
84} 84}
85 85
86void _r8712_free_recv_priv(struct recv_priv *precvpriv) 86void _r8712_free_recv_priv(struct recv_priv *precvpriv)
@@ -245,8 +245,7 @@ union recv_frame *r8712_portctrl(struct _adapter *adapter,
245 if (auth_alg == 2) { 245 if (auth_alg == 2) {
246 /* get ether_type */ 246 /* get ether_type */
247 ptr = ptr + pfhdr->attrib.hdrlen + LLC_HEADER_SIZE; 247 ptr = ptr + pfhdr->attrib.hdrlen + LLC_HEADER_SIZE;
248 memcpy(&ether_type, ptr, 2); 248 ether_type = get_unaligned_be16(ptr);
249 be16_to_cpus(&ether_type);
250 249
251 if ((psta != NULL) && (psta->ieee8021x_blocked)) { 250 if ((psta != NULL) && (psta->ieee8021x_blocked)) {
252 /* blocked 251 /* blocked
@@ -586,7 +585,7 @@ sint r8712_validate_recv_frame(struct _adapter *adapter,
586 return retval; 585 return retval;
587} 586}
588 587
589sint r8712_wlanhdr_to_ethhdr(union recv_frame *precvframe) 588int r8712_wlanhdr_to_ethhdr(union recv_frame *precvframe)
590{ 589{
591 /*remove the wlanhdr and add the eth_hdr*/ 590 /*remove the wlanhdr and add the eth_hdr*/
592 sint rmv_len; 591 sint rmv_len;
@@ -629,14 +628,14 @@ sint r8712_wlanhdr_to_ethhdr(union recv_frame *precvframe)
629 ptr = recvframe_pull(precvframe, (rmv_len - 628 ptr = recvframe_pull(precvframe, (rmv_len -
630 sizeof(struct ethhdr) + 2) - 24); 629 sizeof(struct ethhdr) + 2) - 24);
631 if (!ptr) 630 if (!ptr)
632 return _FAIL; 631 return -ENOMEM;
633 memcpy(ptr, get_rxmem(precvframe), 24); 632 memcpy(ptr, get_rxmem(precvframe), 24);
634 ptr += 24; 633 ptr += 24;
635 } else { 634 } else {
636 ptr = recvframe_pull(precvframe, (rmv_len - 635 ptr = recvframe_pull(precvframe, (rmv_len -
637 sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0))); 636 sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0)));
638 if (!ptr) 637 if (!ptr)
639 return _FAIL; 638 return -ENOMEM;
640 } 639 }
641 640
642 memcpy(ptr, pattrib->dst, ETH_ALEN); 641 memcpy(ptr, pattrib->dst, ETH_ALEN);
@@ -646,10 +645,10 @@ sint r8712_wlanhdr_to_ethhdr(union recv_frame *precvframe)
646 645
647 memcpy(ptr + 12, &be_tmp, 2); 646 memcpy(ptr + 12, &be_tmp, 2);
648 } 647 }
649 return _SUCCESS; 648 return 0;
650} 649}
651 650
652s32 r8712_recv_entry(union recv_frame *precvframe) 651void r8712_recv_entry(union recv_frame *precvframe)
653{ 652{
654 struct _adapter *padapter; 653 struct _adapter *padapter;
655 struct recv_priv *precvpriv; 654 struct recv_priv *precvpriv;
@@ -667,9 +666,8 @@ s32 r8712_recv_entry(union recv_frame *precvframe)
667 precvpriv->rx_pkts++; 666 precvpriv->rx_pkts++;
668 precvpriv->rx_bytes += (uint)(precvframe->u.hdr.rx_tail - 667 precvpriv->rx_bytes += (uint)(precvframe->u.hdr.rx_tail -
669 precvframe->u.hdr.rx_data); 668 precvframe->u.hdr.rx_data);
670 return ret; 669 return;
671_recv_entry_drop: 670_recv_entry_drop:
672 precvpriv->rx_drop++; 671 precvpriv->rx_drop++;
673 padapter->mppriv.rx_pktloss = precvpriv->rx_drop; 672 padapter->mppriv.rx_pktloss = precvpriv->rx_drop;
674 return ret;
675} 673}
diff --git a/drivers/staging/rtl8712/rtl871x_recv.h b/drivers/staging/rtl8712/rtl871x_recv.h
index f87b2ff5de1c..0146a774e19d 100644
--- a/drivers/staging/rtl8712/rtl871x_recv.h
+++ b/drivers/staging/rtl8712/rtl871x_recv.h
@@ -128,7 +128,7 @@ struct sta_recv_priv {
128 128
129/* get a free recv_frame from pfree_recv_queue */ 129/* get a free recv_frame from pfree_recv_queue */
130union recv_frame *r8712_alloc_recvframe(struct __queue *pfree_recv_queue); 130union recv_frame *r8712_alloc_recvframe(struct __queue *pfree_recv_queue);
131int r8712_free_recvframe(union recv_frame *precvframe, 131void r8712_free_recvframe(union recv_frame *precvframe,
132 struct __queue *pfree_recv_queue); 132 struct __queue *pfree_recv_queue);
133void r8712_free_recvframe_queue(struct __queue *pframequeue, 133void r8712_free_recvframe_queue(struct __queue *pframequeue,
134 struct __queue *pfree_recv_queue); 134 struct __queue *pfree_recv_queue);
diff --git a/drivers/staging/rtl8712/rtl871x_rf.h b/drivers/staging/rtl8712/rtl871x_rf.h
index cc54453cd424..7d98921a48fa 100644
--- a/drivers/staging/rtl8712/rtl871x_rf.h
+++ b/drivers/staging/rtl8712/rtl871x_rf.h
@@ -52,5 +52,4 @@ enum {
52 RTL8712_RFC_2T2R = 0x22 52 RTL8712_RFC_2T2R = 0x22
53}; 53};
54 54
55#endif /*_RTL8711_RF_H_*/ 55#endif /*__RTL871X_RF_H_*/
56
diff --git a/drivers/staging/rtl8712/rtl871x_security.c b/drivers/staging/rtl8712/rtl871x_security.c
index 693008bba83e..73e3d5ef3af2 100644
--- a/drivers/staging/rtl8712/rtl871x_security.c
+++ b/drivers/staging/rtl8712/rtl871x_security.c
@@ -636,7 +636,7 @@ u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe)
636} 636}
637 637
638/* The hlen doesn't include the IV */ 638/* The hlen doesn't include the IV */
639u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe) 639void r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe)
640{ /* exclude ICV */ 640{ /* exclude ICV */
641 u16 pnl; 641 u16 pnl;
642 u32 pnh; 642 u32 pnh;
@@ -670,7 +670,7 @@ u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe)
670 prwskey = &psecuritypriv->XGrpKey[ 670 prwskey = &psecuritypriv->XGrpKey[
671 ((idx >> 6) & 0x3) - 1].skey[0]; 671 ((idx >> 6) & 0x3) - 1].skey[0];
672 if (!psecuritypriv->binstallGrpkey) 672 if (!psecuritypriv->binstallGrpkey)
673 return _FAIL; 673 return;
674 } else { 674 } else {
675 prwskey = &stainfo->x_UncstKey.skey[0]; 675 prwskey = &stainfo->x_UncstKey.skey[0];
676 } 676 }
@@ -686,16 +686,8 @@ u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe)
686 arcfour_encrypt(&mycontext, payload, payload, length); 686 arcfour_encrypt(&mycontext, payload, payload, length);
687 *((__le32 *)crc) = cpu_to_le32(getcrc32(payload, 687 *((__le32 *)crc) = cpu_to_le32(getcrc32(payload,
688 length - 4)); 688 length - 4));
689 if (crc[3] != payload[length - 1] ||
690 crc[2] != payload[length - 2] ||
691 crc[1] != payload[length - 3] ||
692 crc[0] != payload[length - 4])
693 return _FAIL;
694 } else {
695 return _FAIL;
696 } 689 }
697 } 690 }
698 return _SUCCESS;
699} 691}
700 692
701/* 3 =====AES related===== */ 693/* 3 =====AES related===== */
@@ -1019,8 +1011,8 @@ static void bitwise_xor(u8 *ina, u8 *inb, u8 *out)
1019 out[i] = ina[i] ^ inb[i]; 1011 out[i] = ina[i] ^ inb[i];
1020} 1012}
1021 1013
1022static sint aes_cipher(u8 *key, uint hdrlen, 1014static void aes_cipher(u8 *key, uint hdrlen,
1023 u8 *pframe, uint plen) 1015 u8 *pframe, uint plen)
1024{ 1016{
1025 uint qc_exists, a4_exists, i, j, payload_remainder; 1017 uint qc_exists, a4_exists, i, j, payload_remainder;
1026 uint num_blocks, payload_index; 1018 uint num_blocks, payload_index;
@@ -1140,7 +1132,6 @@ static sint aes_cipher(u8 *key, uint hdrlen,
1140 bitwise_xor(aes_out, padded_buffer, chain_buffer); 1132 bitwise_xor(aes_out, padded_buffer, chain_buffer);
1141 for (j = 0; j < 8; j++) 1133 for (j = 0; j < 8; j++)
1142 pframe[payload_index++] = chain_buffer[j]; 1134 pframe[payload_index++] = chain_buffer[j];
1143 return _SUCCESS;
1144} 1135}
1145 1136
1146u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe) 1137u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe)
@@ -1193,8 +1184,8 @@ u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe)
1193 return res; 1184 return res;
1194} 1185}
1195 1186
1196static sint aes_decipher(u8 *key, uint hdrlen, 1187static void aes_decipher(u8 *key, uint hdrlen,
1197 u8 *pframe, uint plen) 1188 u8 *pframe, uint plen)
1198{ 1189{
1199 static u8 message[MAX_MSG_SIZE]; 1190 static u8 message[MAX_MSG_SIZE];
1200 uint qc_exists, a4_exists, i, j, payload_remainder; 1191 uint qc_exists, a4_exists, i, j, payload_remainder;
@@ -1348,10 +1339,9 @@ static sint aes_decipher(u8 *key, uint hdrlen,
1348 for (j = 0; j < 8; j++) 1339 for (j = 0; j < 8; j++)
1349 message[payload_index++] = chain_buffer[j]; 1340 message[payload_index++] = chain_buffer[j];
1350 /* compare the mic */ 1341 /* compare the mic */
1351 return _SUCCESS;
1352} 1342}
1353 1343
1354u32 r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe) 1344void r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe)
1355{ /* exclude ICV */ 1345{ /* exclude ICV */
1356 /* Intermediate Buffers */ 1346 /* Intermediate Buffers */
1357 sint length; 1347 sint length;
@@ -1374,7 +1364,7 @@ u32 r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe)
1374 prwskey = &psecuritypriv->XGrpKey[ 1364 prwskey = &psecuritypriv->XGrpKey[
1375 ((idx >> 6) & 0x3) - 1].skey[0]; 1365 ((idx >> 6) & 0x3) - 1].skey[0];
1376 if (!psecuritypriv->binstallGrpkey) 1366 if (!psecuritypriv->binstallGrpkey)
1377 return _FAIL; 1367 return;
1378 1368
1379 } else { 1369 } else {
1380 prwskey = &stainfo->x_UncstKey.skey[0]; 1370 prwskey = &stainfo->x_UncstKey.skey[0];
@@ -1384,11 +1374,8 @@ u32 r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe)
1384 prxattrib->iv_len; 1374 prxattrib->iv_len;
1385 aes_decipher(prwskey, prxattrib->hdrlen, pframe, 1375 aes_decipher(prwskey, prxattrib->hdrlen, pframe,
1386 length); 1376 length);
1387 } else {
1388 return _FAIL;
1389 } 1377 }
1390 } 1378 }
1391 return _SUCCESS;
1392} 1379}
1393 1380
1394void r8712_use_tkipkey_handler(struct timer_list *t) 1381void r8712_use_tkipkey_handler(struct timer_list *t)
diff --git a/drivers/staging/rtl8712/rtl871x_security.h b/drivers/staging/rtl8712/rtl871x_security.h
index 25b4d379766d..b2dda16cbd0a 100644
--- a/drivers/staging/rtl8712/rtl871x_security.h
+++ b/drivers/staging/rtl8712/rtl871x_security.h
@@ -209,8 +209,8 @@ void r8712_secgetmic(struct mic_data *pmicdata, u8 *dst);
209u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe); 209u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe);
210u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe); 210u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe);
211void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe); 211void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe);
212u32 r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe); 212void r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe);
213u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe); 213void r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe);
214void r8712_wep_decrypt(struct _adapter *padapter, u8 *precvframe); 214void r8712_wep_decrypt(struct _adapter *padapter, u8 *precvframe);
215void r8712_use_tkipkey_handler(struct timer_list *t); 215void r8712_use_tkipkey_handler(struct timer_list *t);
216 216
diff --git a/drivers/staging/rtl8712/rtl871x_xmit.c b/drivers/staging/rtl8712/rtl871x_xmit.c
index 0a26d71e5340..cc5809e49e35 100644
--- a/drivers/staging/rtl8712/rtl871x_xmit.c
+++ b/drivers/staging/rtl8712/rtl871x_xmit.c
@@ -49,8 +49,8 @@ void _r8712_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv)
49 INIT_LIST_HEAD(&psta_xmitpriv->apsd); 49 INIT_LIST_HEAD(&psta_xmitpriv->apsd);
50} 50}
51 51
52sint _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv, 52int _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv,
53 struct _adapter *padapter) 53 struct _adapter *padapter)
54{ 54{
55 sint i; 55 sint i;
56 struct xmit_buf *pxmitbuf; 56 struct xmit_buf *pxmitbuf;
@@ -79,7 +79,7 @@ sint _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv,
79 kmalloc(NR_XMITFRAME * sizeof(struct xmit_frame) + 4, GFP_ATOMIC); 79 kmalloc(NR_XMITFRAME * sizeof(struct xmit_frame) + 4, GFP_ATOMIC);
80 if (!pxmitpriv->pallocated_frame_buf) { 80 if (!pxmitpriv->pallocated_frame_buf) {
81 pxmitpriv->pxmit_frame_buf = NULL; 81 pxmitpriv->pxmit_frame_buf = NULL;
82 return _FAIL; 82 return -ENOMEM;
83 } 83 }
84 pxmitpriv->pxmit_frame_buf = pxmitpriv->pallocated_frame_buf + 4 - 84 pxmitpriv->pxmit_frame_buf = pxmitpriv->pallocated_frame_buf + 4 -
85 ((addr_t) (pxmitpriv->pallocated_frame_buf) & 3); 85 ((addr_t) (pxmitpriv->pallocated_frame_buf) & 3);
@@ -119,7 +119,7 @@ sint _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv,
119 if (!pxmitpriv->pallocated_xmitbuf) { 119 if (!pxmitpriv->pallocated_xmitbuf) {
120 kfree(pxmitpriv->pallocated_frame_buf); 120 kfree(pxmitpriv->pallocated_frame_buf);
121 pxmitpriv->pallocated_frame_buf = NULL; 121 pxmitpriv->pallocated_frame_buf = NULL;
122 return _FAIL; 122 return -ENOMEM;
123 } 123 }
124 pxmitpriv->pxmitbuf = pxmitpriv->pallocated_xmitbuf + 4 - 124 pxmitpriv->pxmitbuf = pxmitpriv->pallocated_xmitbuf + 4 -
125 ((addr_t)(pxmitpriv->pallocated_xmitbuf) & 3); 125 ((addr_t)(pxmitpriv->pallocated_xmitbuf) & 3);
@@ -129,12 +129,12 @@ sint _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv,
129 pxmitbuf->pallocated_buf = kmalloc(MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ, 129 pxmitbuf->pallocated_buf = kmalloc(MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ,
130 GFP_ATOMIC); 130 GFP_ATOMIC);
131 if (!pxmitbuf->pallocated_buf) 131 if (!pxmitbuf->pallocated_buf)
132 return _FAIL; 132 return -ENOMEM;
133 pxmitbuf->pbuf = pxmitbuf->pallocated_buf + XMITBUF_ALIGN_SZ - 133 pxmitbuf->pbuf = pxmitbuf->pallocated_buf + XMITBUF_ALIGN_SZ -
134 ((addr_t) (pxmitbuf->pallocated_buf) & 134 ((addr_t) (pxmitbuf->pallocated_buf) &
135 (XMITBUF_ALIGN_SZ - 1)); 135 (XMITBUF_ALIGN_SZ - 1));
136 if (r8712_xmit_resource_alloc(padapter, pxmitbuf)) 136 if (r8712_xmit_resource_alloc(padapter, pxmitbuf))
137 return _FAIL; 137 return -ENOMEM;
138 list_add_tail(&pxmitbuf->list, 138 list_add_tail(&pxmitbuf->list,
139 &(pxmitpriv->free_xmitbuf_queue.queue)); 139 &(pxmitpriv->free_xmitbuf_queue.queue));
140 pxmitbuf++; 140 pxmitbuf++;
@@ -146,7 +146,7 @@ sint _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv,
146 tasklet_init(&pxmitpriv->xmit_tasklet, 146 tasklet_init(&pxmitpriv->xmit_tasklet,
147 (void(*)(unsigned long))r8712_xmit_bh, 147 (void(*)(unsigned long))r8712_xmit_bh,
148 (unsigned long)padapter); 148 (unsigned long)padapter);
149 return _SUCCESS; 149 return 0;
150} 150}
151 151
152void _free_xmit_priv(struct xmit_priv *pxmitpriv) 152void _free_xmit_priv(struct xmit_priv *pxmitpriv)
@@ -173,8 +173,8 @@ void _free_xmit_priv(struct xmit_priv *pxmitpriv)
173 free_hwxmits(padapter); 173 free_hwxmits(padapter);
174} 174}
175 175
176sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt, 176int r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
177 struct pkt_attrib *pattrib) 177 struct pkt_attrib *pattrib)
178{ 178{
179 struct pkt_file pktfile; 179 struct pkt_file pktfile;
180 struct sta_info *psta = NULL; 180 struct sta_info *psta = NULL;
@@ -224,7 +224,7 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
224 } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) { 224 } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
225 /*firstly, filter packet not belongs to mp*/ 225 /*firstly, filter packet not belongs to mp*/
226 if (pattrib->ether_type != 0x8712) 226 if (pattrib->ether_type != 0x8712)
227 return _FAIL; 227 return -EINVAL;
228 /* for mp storing the txcmd per packet, 228 /* for mp storing the txcmd per packet,
229 * according to the info of txcmd to update pattrib 229 * according to the info of txcmd to update pattrib
230 */ 230 */
@@ -271,7 +271,7 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
271 } else { 271 } else {
272 psta = r8712_get_stainfo(pstapriv, pattrib->ra); 272 psta = r8712_get_stainfo(pstapriv, pattrib->ra);
273 if (psta == NULL) /* drop the pkt */ 273 if (psta == NULL) /* drop the pkt */
274 return _FAIL; 274 return -ENOMEM;
275 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) 275 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
276 pattrib->mac_id = 5; 276 pattrib->mac_id = 5;
277 else 277 else
@@ -283,7 +283,7 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
283 pattrib->psta = psta; 283 pattrib->psta = psta;
284 } else { 284 } else {
285 /* if we cannot get psta => drrp the pkt */ 285 /* if we cannot get psta => drrp the pkt */
286 return _FAIL; 286 return -ENOMEM;
287 } 287 }
288 288
289 pattrib->ack_policy = 0; 289 pattrib->ack_policy = 0;
@@ -301,7 +301,7 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
301 pattrib->encrypt = 0; 301 pattrib->encrypt = 0;
302 if ((pattrib->ether_type != 0x888e) && 302 if ((pattrib->ether_type != 0x888e) &&
303 !check_fwstate(pmlmepriv, WIFI_MP_STATE)) 303 !check_fwstate(pmlmepriv, WIFI_MP_STATE))
304 return _FAIL; 304 return -EINVAL;
305 } else { 305 } else {
306 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, bmcast); 306 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, bmcast);
307 } 307 }
@@ -315,7 +315,7 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
315 pattrib->iv_len = 8; 315 pattrib->iv_len = 8;
316 pattrib->icv_len = 4; 316 pattrib->icv_len = 4;
317 if (padapter->securitypriv.busetkipkey == _FAIL) 317 if (padapter->securitypriv.busetkipkey == _FAIL)
318 return _FAIL; 318 return -EINVAL;
319 break; 319 break;
320 case _AES_: 320 case _AES_:
321 pattrib->iv_len = 8; 321 pattrib->iv_len = 8;
@@ -339,11 +339,11 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
339 if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) 339 if (check_fwstate(pmlmepriv, WIFI_MP_STATE))
340 pattrib->priority = 340 pattrib->priority =
341 (le32_to_cpu(txdesc.txdw1) >> QSEL_SHT) & 0x1f; 341 (le32_to_cpu(txdesc.txdw1) >> QSEL_SHT) & 0x1f;
342 return _SUCCESS; 342 return 0;
343} 343}
344 344
345static sint xmitframe_addmic(struct _adapter *padapter, 345static int xmitframe_addmic(struct _adapter *padapter,
346 struct xmit_frame *pxmitframe) 346 struct xmit_frame *pxmitframe)
347{ 347{
348 u32 curfragnum, length; 348 u32 curfragnum, length;
349 u8 *pframe, *payload, mic[8]; 349 u8 *pframe, *payload, mic[8];
@@ -372,7 +372,7 @@ static sint xmitframe_addmic(struct _adapter *padapter,
372 if (!memcmp(psecuritypriv->XGrptxmickey 372 if (!memcmp(psecuritypriv->XGrptxmickey
373 [psecuritypriv->XGrpKeyid].skey, 373 [psecuritypriv->XGrpKeyid].skey,
374 null_key, 16)) 374 null_key, 16))
375 return _FAIL; 375 return -ENOMEM;
376 /*start to calculate the mic code*/ 376 /*start to calculate the mic code*/
377 r8712_secmicsetkey(&micdata, 377 r8712_secmicsetkey(&micdata,
378 psecuritypriv-> 378 psecuritypriv->
@@ -381,7 +381,7 @@ static sint xmitframe_addmic(struct _adapter *padapter,
381 } else { 381 } else {
382 if (!memcmp(&stainfo->tkiptxmickey.skey[0], 382 if (!memcmp(&stainfo->tkiptxmickey.skey[0],
383 null_key, 16)) 383 null_key, 16))
384 return _FAIL; 384 return -ENOMEM;
385 /* start to calculate the mic code */ 385 /* start to calculate the mic code */
386 r8712_secmicsetkey(&micdata, 386 r8712_secmicsetkey(&micdata,
387 &stainfo->tkiptxmickey.skey[0]); 387 &stainfo->tkiptxmickey.skey[0]);
@@ -442,7 +442,7 @@ static sint xmitframe_addmic(struct _adapter *padapter,
442 payload = payload - pattrib->last_txcmdsz + 8; 442 payload = payload - pattrib->last_txcmdsz + 8;
443 } 443 }
444 } 444 }
445 return _SUCCESS; 445 return 0;
446} 446}
447 447
448static sint xmitframe_swencrypt(struct _adapter *padapter, 448static sint xmitframe_swencrypt(struct _adapter *padapter,
@@ -469,8 +469,8 @@ static sint xmitframe_swencrypt(struct _adapter *padapter,
469 return _SUCCESS; 469 return _SUCCESS;
470} 470}
471 471
472static sint make_wlanhdr(struct _adapter *padapter, u8 *hdr, 472static int make_wlanhdr(struct _adapter *padapter, u8 *hdr,
473 struct pkt_attrib *pattrib) 473 struct pkt_attrib *pattrib)
474{ 474{
475 u16 *qc; 475 u16 *qc;
476 476
@@ -509,7 +509,7 @@ static sint make_wlanhdr(struct _adapter *padapter, u8 *hdr,
509 memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv), 509 memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv),
510 ETH_ALEN); 510 ETH_ALEN);
511 } else { 511 } else {
512 return _FAIL; 512 return -EINVAL;
513 } 513 }
514 514
515 if (pattrib->encrypt) 515 if (pattrib->encrypt)
@@ -547,7 +547,7 @@ static sint make_wlanhdr(struct _adapter *padapter, u8 *hdr,
547 } 547 }
548 } 548 }
549 } 549 }
550 return _SUCCESS; 550 return 0;
551} 551}
552 552
553static sint r8712_put_snap(u8 *data, u16 h_proto) 553static sint r8712_put_snap(u8 *data, u16 h_proto)
@@ -605,7 +605,7 @@ sint r8712_xmitframe_coalesce(struct _adapter *padapter, _pkt *pkt,
605 pbuf_start = pxmitframe->buf_addr; 605 pbuf_start = pxmitframe->buf_addr;
606 ptxdesc = pbuf_start; 606 ptxdesc = pbuf_start;
607 mem_start = pbuf_start + TXDESC_OFFSET; 607 mem_start = pbuf_start + TXDESC_OFFSET;
608 if (make_wlanhdr(padapter, mem_start, pattrib) == _FAIL) 608 if (make_wlanhdr(padapter, mem_start, pattrib))
609 return _FAIL; 609 return _FAIL;
610 _r8712_open_pktfile(pkt, &pktfile); 610 _r8712_open_pktfile(pkt, &pktfile);
611 _r8712_pktfile_read(&pktfile, NULL, (uint) pattrib->pkt_hdrlen); 611 _r8712_pktfile_read(&pktfile, NULL, (uint) pattrib->pkt_hdrlen);
@@ -696,7 +696,7 @@ sint r8712_xmitframe_coalesce(struct _adapter *padapter, _pkt *pkt,
696 memcpy(mem_start, pbuf_start + TXDESC_OFFSET, pattrib->hdrlen); 696 memcpy(mem_start, pbuf_start + TXDESC_OFFSET, pattrib->hdrlen);
697 } 697 }
698 698
699 if (xmitframe_addmic(padapter, pxmitframe) == _FAIL) 699 if (xmitframe_addmic(padapter, pxmitframe))
700 return _FAIL; 700 return _FAIL;
701 xmitframe_swencrypt(padapter, pxmitframe); 701 xmitframe_swencrypt(padapter, pxmitframe);
702 return _SUCCESS; 702 return _SUCCESS;
@@ -753,19 +753,18 @@ struct xmit_buf *r8712_alloc_xmitbuf(struct xmit_priv *pxmitpriv)
753 return pxmitbuf; 753 return pxmitbuf;
754} 754}
755 755
756int r8712_free_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf) 756void r8712_free_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
757{ 757{
758 unsigned long irqL; 758 unsigned long irqL;
759 struct __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue; 759 struct __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
760 760
761 if (pxmitbuf == NULL) 761 if (pxmitbuf == NULL)
762 return _FAIL; 762 return;
763 spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irqL); 763 spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irqL);
764 list_del_init(&pxmitbuf->list); 764 list_del_init(&pxmitbuf->list);
765 list_add_tail(&(pxmitbuf->list), &pfree_xmitbuf_queue->queue); 765 list_add_tail(&(pxmitbuf->list), &pfree_xmitbuf_queue->queue);
766 pxmitpriv->free_xmitbuf_cnt++; 766 pxmitpriv->free_xmitbuf_cnt++;
767 spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irqL); 767 spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irqL);
768 return _SUCCESS;
769} 768}
770 769
771/* 770/*
@@ -894,8 +893,8 @@ static inline struct tx_servq *get_sta_pending(struct _adapter *padapter,
894 * Will enqueue pxmitframe to the proper queue, and indicate it 893 * Will enqueue pxmitframe to the proper queue, and indicate it
895 * to xx_pending list..... 894 * to xx_pending list.....
896 */ 895 */
897sint r8712_xmit_classifier(struct _adapter *padapter, 896int r8712_xmit_classifier(struct _adapter *padapter,
898 struct xmit_frame *pxmitframe) 897 struct xmit_frame *pxmitframe)
899{ 898{
900 unsigned long irqL0; 899 unsigned long irqL0;
901 struct __queue *pstapending; 900 struct __queue *pstapending;
@@ -920,7 +919,7 @@ sint r8712_xmit_classifier(struct _adapter *padapter,
920 } 919 }
921 } 920 }
922 if (psta == NULL) 921 if (psta == NULL)
923 return _FAIL; 922 return -EINVAL;
924 ptxservq = get_sta_pending(padapter, &pstapending, 923 ptxservq = get_sta_pending(padapter, &pstapending,
925 psta, pattrib->priority); 924 psta, pattrib->priority);
926 spin_lock_irqsave(&pstapending->lock, irqL0); 925 spin_lock_irqsave(&pstapending->lock, irqL0);
@@ -929,7 +928,7 @@ sint r8712_xmit_classifier(struct _adapter *padapter,
929 list_add_tail(&pxmitframe->list, &ptxservq->sta_pending.queue); 928 list_add_tail(&pxmitframe->list, &ptxservq->sta_pending.queue);
930 ptxservq->qcnt++; 929 ptxservq->qcnt++;
931 spin_unlock_irqrestore(&pstapending->lock, irqL0); 930 spin_unlock_irqrestore(&pstapending->lock, irqL0);
932 return _SUCCESS; 931 return 0;
933} 932}
934 933
935static void alloc_hwxmits(struct _adapter *padapter) 934static void alloc_hwxmits(struct _adapter *padapter)
diff --git a/drivers/staging/rtl8712/rtl871x_xmit.h b/drivers/staging/rtl8712/rtl871x_xmit.h
index 4199cb586fb1..b14da38bf652 100644
--- a/drivers/staging/rtl8712/rtl871x_xmit.h
+++ b/drivers/staging/rtl8712/rtl871x_xmit.h
@@ -41,7 +41,7 @@ do { \
41 pattrib_iv[0] = txpn._byte_.TSC0;\ 41 pattrib_iv[0] = txpn._byte_.TSC0;\
42 pattrib_iv[1] = txpn._byte_.TSC1;\ 42 pattrib_iv[1] = txpn._byte_.TSC1;\
43 pattrib_iv[2] = txpn._byte_.TSC2;\ 43 pattrib_iv[2] = txpn._byte_.TSC2;\
44 pattrib_iv[3] = ((keyidx & 0x3)<<6);\ 44 pattrib_iv[3] = ((keyidx & 0x3) << 6);\
45 txpn.val = (txpn.val == 0xffffff) ? 0 : (txpn.val+1);\ 45 txpn.val = (txpn.val == 0xffffff) ? 0 : (txpn.val+1);\
46} while (0) 46} while (0)
47 47
@@ -249,8 +249,8 @@ struct xmit_priv {
249 uint free_xmitbuf_cnt; 249 uint free_xmitbuf_cnt;
250}; 250};
251 251
252int r8712_free_xmitbuf(struct xmit_priv *pxmitpriv, 252void r8712_free_xmitbuf(struct xmit_priv *pxmitpriv,
253 struct xmit_buf *pxmitbuf); 253 struct xmit_buf *pxmitbuf);
254struct xmit_buf *r8712_alloc_xmitbuf(struct xmit_priv *pxmitpriv); 254struct xmit_buf *r8712_alloc_xmitbuf(struct xmit_priv *pxmitpriv);
255void r8712_update_protection(struct _adapter *padapter, u8 *ie, uint ie_len); 255void r8712_update_protection(struct _adapter *padapter, u8 *ie, uint ie_len);
256struct xmit_frame *r8712_alloc_xmitframe(struct xmit_priv *pxmitpriv); 256struct xmit_frame *r8712_alloc_xmitframe(struct xmit_priv *pxmitpriv);
@@ -258,25 +258,25 @@ void r8712_free_xmitframe(struct xmit_priv *pxmitpriv,
258 struct xmit_frame *pxmitframe); 258 struct xmit_frame *pxmitframe);
259void r8712_free_xmitframe_queue(struct xmit_priv *pxmitpriv, 259void r8712_free_xmitframe_queue(struct xmit_priv *pxmitpriv,
260 struct __queue *pframequeue); 260 struct __queue *pframequeue);
261sint r8712_xmit_classifier(struct _adapter *padapter, 261int r8712_xmit_classifier(struct _adapter *padapter,
262 struct xmit_frame *pxmitframe); 262 struct xmit_frame *pxmitframe);
263sint r8712_xmitframe_coalesce(struct _adapter *padapter, _pkt *pkt, 263sint r8712_xmitframe_coalesce(struct _adapter *padapter, _pkt *pkt,
264 struct xmit_frame *pxmitframe); 264 struct xmit_frame *pxmitframe);
265sint _r8712_init_hw_txqueue(struct hw_txqueue *phw_txqueue, u8 ac_tag); 265sint _r8712_init_hw_txqueue(struct hw_txqueue *phw_txqueue, u8 ac_tag);
266void _r8712_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv); 266void _r8712_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv);
267sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt, 267int r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
268 struct pkt_attrib *pattrib); 268 struct pkt_attrib *pattrib);
269int r8712_txframes_sta_ac_pending(struct _adapter *padapter, 269int r8712_txframes_sta_ac_pending(struct _adapter *padapter,
270 struct pkt_attrib *pattrib); 270 struct pkt_attrib *pattrib);
271sint _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv, 271int _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv,
272 struct _adapter *padapter); 272 struct _adapter *padapter);
273void _free_xmit_priv(struct xmit_priv *pxmitpriv); 273void _free_xmit_priv(struct xmit_priv *pxmitpriv);
274void r8712_free_xmitframe_ex(struct xmit_priv *pxmitpriv, 274void r8712_free_xmitframe_ex(struct xmit_priv *pxmitpriv,
275 struct xmit_frame *pxmitframe); 275 struct xmit_frame *pxmitframe);
276int r8712_pre_xmit(struct _adapter *padapter, struct xmit_frame *pxmitframe); 276int r8712_pre_xmit(struct _adapter *padapter, struct xmit_frame *pxmitframe);
277int r8712_xmit_enqueue(struct _adapter *padapter, 277int r8712_xmit_enqueue(struct _adapter *padapter,
278 struct xmit_frame *pxmitframe); 278 struct xmit_frame *pxmitframe);
279int r8712_xmit_direct(struct _adapter *padapter, struct xmit_frame *pxmitframe); 279void r8712_xmit_direct(struct _adapter *padapter, struct xmit_frame *pxmitframe);
280void r8712_xmit_bh(void *priv); 280void r8712_xmit_bh(void *priv);
281 281
282void xmitframe_xmitbuf_attach(struct xmit_frame *pxmitframe, 282void xmitframe_xmitbuf_attach(struct xmit_frame *pxmitframe,
diff --git a/drivers/staging/rtl8712/usb_intf.c b/drivers/staging/rtl8712/usb_intf.c
index d0daae0b8299..ba1288297ee4 100644
--- a/drivers/staging/rtl8712/usb_intf.c
+++ b/drivers/staging/rtl8712/usb_intf.c
@@ -389,7 +389,7 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf,
389 } 389 }
390 /* step 4. */ 390 /* step 4. */
391 status = r8712_init_drv_sw(padapter); 391 status = r8712_init_drv_sw(padapter);
392 if (status == _FAIL) 392 if (status)
393 goto error; 393 goto error;
394 /* step 5. read efuse/eeprom data and get mac_addr */ 394 /* step 5. read efuse/eeprom data and get mac_addr */
395 { 395 {
diff --git a/drivers/staging/rtl8712/usb_osintf.h b/drivers/staging/rtl8712/usb_osintf.h
index ddfa405d0c9b..2e512b4a564c 100644
--- a/drivers/staging/rtl8712/usb_osintf.h
+++ b/drivers/staging/rtl8712/usb_osintf.h
@@ -28,8 +28,8 @@ void rtl871x_intf_stop(struct _adapter *padapter);
28void r871x_dev_unload(struct _adapter *padapter); 28void r871x_dev_unload(struct _adapter *padapter);
29void r8712_stop_drv_threads(struct _adapter *padapter); 29void r8712_stop_drv_threads(struct _adapter *padapter);
30void r8712_stop_drv_timers(struct _adapter *padapter); 30void r8712_stop_drv_timers(struct _adapter *padapter);
31u8 r8712_init_drv_sw(struct _adapter *padapter); 31int r8712_init_drv_sw(struct _adapter *padapter);
32u8 r8712_free_drv_sw(struct _adapter *padapter); 32void r8712_free_drv_sw(struct _adapter *padapter);
33struct net_device *r8712_init_netdev(void); 33struct net_device *r8712_init_netdev(void);
34 34
35#endif 35#endif
diff --git a/drivers/staging/rtl8712/wifi.h b/drivers/staging/rtl8712/wifi.h
index 1a5b966a167e..be731f1a2209 100644
--- a/drivers/staging/rtl8712/wifi.h
+++ b/drivers/staging/rtl8712/wifi.h
@@ -300,7 +300,6 @@ static inline unsigned char *get_da(unsigned char *pframe)
300 return da; 300 return da;
301} 301}
302 302
303
304static inline unsigned char *get_sa(unsigned char *pframe) 303static inline unsigned char *get_sa(unsigned char *pframe)
305{ 304{
306 unsigned char *sa; 305 unsigned char *sa;
@@ -346,8 +345,6 @@ static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
346 return sa; 345 return sa;
347} 346}
348 347
349
350
351/*----------------------------------------------------------------------------- 348/*-----------------------------------------------------------------------------
352 * Below is for the security related definition 349 * Below is for the security related definition
353 *----------------------------------------------------------------------------- 350 *-----------------------------------------------------------------------------
@@ -392,7 +389,6 @@ static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
392 389
393#define _RESERVED47_ 47 390#define _RESERVED47_ 47
394 391
395
396/* --------------------------------------------------------------------------- 392/* ---------------------------------------------------------------------------
397 * Below is the fixed elements... 393 * Below is the fixed elements...
398 * --------------------------------------------------------------------------- 394 * ---------------------------------------------------------------------------
@@ -436,7 +432,6 @@ static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
436#define _WMM_IE_Length_ 7 /* for WMM STA */ 432#define _WMM_IE_Length_ 7 /* for WMM STA */
437#define _WMM_Para_Element_Length_ 24 433#define _WMM_Para_Element_Length_ 24
438 434
439
440/*----------------------------------------------------------------------------- 435/*-----------------------------------------------------------------------------
441 * Below is the definition for 802.11n 436 * Below is the definition for 802.11n
442 *------------------------------------------------------------------------------ 437 *------------------------------------------------------------------------------
@@ -456,7 +451,6 @@ static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
456#define GetOrderBit(pbuf) (((*(__le16 *)(pbuf)) & \ 451#define GetOrderBit(pbuf) (((*(__le16 *)(pbuf)) & \
457 le16_to_cpu(_ORDER_)) != 0) 452 le16_to_cpu(_ORDER_)) != 0)
458 453
459
460/** 454/**
461 * struct ieee80211_bar - HT Block Ack Request 455 * struct ieee80211_bar - HT Block Ack Request
462 * 456 *
@@ -476,7 +470,6 @@ struct ieee80211_bar {
476#define IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL 0x0000 470#define IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL 0x0000
477#define IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA 0x0004 471#define IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA 0x0004
478 472
479
480/* 473/*
481 * struct ieee80211_ht_cap - HT capabilities 474 * struct ieee80211_ht_cap - HT capabilities
482 * 475 *
@@ -552,7 +545,6 @@ struct ieee80211_ht_addt_info {
552 */ 545 */
553#define IEEE80211_MIN_AMPDU_BUF 0x8 546#define IEEE80211_MIN_AMPDU_BUF 0x8
554 547
555
556/* Spatial Multiplexing Power Save Modes */ 548/* Spatial Multiplexing Power Save Modes */
557#define WLAN_HT_CAP_SM_PS_STATIC 0 549#define WLAN_HT_CAP_SM_PS_STATIC 0
558#define WLAN_HT_CAP_SM_PS_DYNAMIC 1 550#define WLAN_HT_CAP_SM_PS_DYNAMIC 1
diff --git a/drivers/staging/rtl8712/xmit_linux.c b/drivers/staging/rtl8712/xmit_linux.c
index 01d713d027b0..1f67d86c606f 100644
--- a/drivers/staging/rtl8712/xmit_linux.c
+++ b/drivers/staging/rtl8712/xmit_linux.c
@@ -160,7 +160,7 @@ int r8712_xmit_entry(_pkt *pkt, struct net_device *netdev)
160 if (!xmitframe) 160 if (!xmitframe)
161 goto _xmit_entry_drop; 161 goto _xmit_entry_drop;
162 162
163 if ((!r8712_update_attrib(adapter, pkt, &xmitframe->attrib))) 163 if (r8712_update_attrib(adapter, pkt, &xmitframe->attrib))
164 goto _xmit_entry_drop; 164 goto _xmit_entry_drop;
165 165
166 adapter->ledpriv.LedControlHandler(adapter, LED_CTL_TX); 166 adapter->ledpriv.LedControlHandler(adapter, LED_CTL_TX);
diff --git a/drivers/staging/rtl8723bs/Makefile b/drivers/staging/rtl8723bs/Makefile
index a12cf8dd8ed9..dfe410283ca0 100644
--- a/drivers/staging/rtl8723bs/Makefile
+++ b/drivers/staging/rtl8723bs/Makefile
@@ -60,7 +60,6 @@ r8723bs-y = \
60 os_dep/osdep_service.o \ 60 os_dep/osdep_service.o \
61 os_dep/os_intfs.o \ 61 os_dep/os_intfs.o \
62 os_dep/recv_linux.o \ 62 os_dep/recv_linux.o \
63 os_dep/rtw_proc.o \
64 os_dep/sdio_intf.o \ 63 os_dep/sdio_intf.o \
65 os_dep/sdio_ops_linux.o \ 64 os_dep/sdio_ops_linux.o \
66 os_dep/wifi_regd.o \ 65 os_dep/wifi_regd.o \
diff --git a/drivers/staging/rtl8723bs/core/rtw_ap.c b/drivers/staging/rtl8723bs/core/rtw_ap.c
index 7bd5c61b055c..6d18d23acdc0 100644
--- a/drivers/staging/rtl8723bs/core/rtw_ap.c
+++ b/drivers/staging/rtl8723bs/core/rtw_ap.c
@@ -13,11 +13,10 @@ extern unsigned char RTW_WPA_OUI[];
13extern unsigned char WMM_OUI[]; 13extern unsigned char WMM_OUI[];
14extern unsigned char WPS_OUI[]; 14extern unsigned char WPS_OUI[];
15extern unsigned char P2P_OUI[]; 15extern unsigned char P2P_OUI[];
16extern unsigned char WFD_OUI[];
17 16
18void init_mlme_ap_info(struct adapter *padapter) 17void init_mlme_ap_info(struct adapter *padapter)
19{ 18{
20 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 19 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
21 struct sta_priv *pstapriv = &padapter->stapriv; 20 struct sta_priv *pstapriv = &padapter->stapriv;
22 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list; 21 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
23 22
@@ -34,9 +33,9 @@ void init_mlme_ap_info(struct adapter *padapter)
34void free_mlme_ap_info(struct adapter *padapter) 33void free_mlme_ap_info(struct adapter *padapter)
35{ 34{
36 struct sta_info *psta = NULL; 35 struct sta_info *psta = NULL;
37 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 36 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
38 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 37 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
39 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 38 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
40 39
41 /* stop_ap_mode(padapter); */ 40 /* stop_ap_mode(padapter); */
42 41
@@ -58,9 +57,9 @@ void free_mlme_ap_info(struct adapter *padapter)
58static void update_BCNTIM(struct adapter *padapter) 57static void update_BCNTIM(struct adapter *padapter)
59{ 58{
60 struct sta_priv *pstapriv = &padapter->stapriv; 59 struct sta_priv *pstapriv = &padapter->stapriv;
61 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); 60 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
62 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 61 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
63 struct wlan_bssid_ex *pnetwork_mlmeext = &(pmlmeinfo->network); 62 struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network;
64 unsigned char *pie = pnetwork_mlmeext->IEs; 63 unsigned char *pie = pnetwork_mlmeext->IEs;
65 64
66 /* DBG_871X("%s\n", __func__); */ 65 /* DBG_871X("%s\n", __func__); */
@@ -83,7 +82,7 @@ static void update_BCNTIM(struct adapter *padapter)
83 if (p != NULL && tim_ielen > 0) { 82 if (p != NULL && tim_ielen > 0) {
84 tim_ielen += 2; 83 tim_ielen += 2;
85 84
86 premainder_ie = p+tim_ielen; 85 premainder_ie = p + tim_ielen;
87 86
88 tim_ie_offset = (sint)(p - pie); 87 tim_ie_offset = (sint)(p - pie);
89 88
@@ -94,7 +93,7 @@ static void update_BCNTIM(struct adapter *padapter)
94 } else { 93 } else {
95 tim_ielen = 0; 94 tim_ielen = 0;
96 95
97 /* calucate head_len */ 96 /* calculate head_len */
98 offset = _FIXED_IE_LENGTH_; 97 offset = _FIXED_IE_LENGTH_;
99 98
100 /* get ssid_ie len */ 99 /* get ssid_ie len */
@@ -105,7 +104,7 @@ static void update_BCNTIM(struct adapter *padapter)
105 (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_) 104 (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_)
106 ); 105 );
107 if (p != NULL) 106 if (p != NULL)
108 offset += tmp_len+2; 107 offset += tmp_len + 2;
109 108
110 /* get supported rates len */ 109 /* get supported rates len */
111 p = rtw_get_ie( 110 p = rtw_get_ie(
@@ -114,7 +113,7 @@ static void update_BCNTIM(struct adapter *padapter)
114 (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_) 113 (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_)
115 ); 114 );
116 if (p != NULL) 115 if (p != NULL)
117 offset += tmp_len+2; 116 offset += tmp_len + 2;
118 117
119 /* DS Parameter Set IE, len =3 */ 118 /* DS Parameter Set IE, len =3 */
120 offset += 3; 119 offset += 3;
@@ -135,7 +134,7 @@ static void update_BCNTIM(struct adapter *padapter)
135 134
136 *dst_ie++ = _TIM_IE_; 135 *dst_ie++ = _TIM_IE_;
137 136
138 if ((pstapriv->tim_bitmap&0xff00) && (pstapriv->tim_bitmap&0x00fe)) 137 if ((pstapriv->tim_bitmap & 0xff00) && (pstapriv->tim_bitmap & 0x00fe))
139 tim_ielen = 5; 138 tim_ielen = 5;
140 else 139 else
141 tim_ielen = 4; 140 tim_ielen = 4;
@@ -143,9 +142,9 @@ static void update_BCNTIM(struct adapter *padapter)
143 *dst_ie++ = tim_ielen; 142 *dst_ie++ = tim_ielen;
144 143
145 *dst_ie++ = 0;/* DTIM count */ 144 *dst_ie++ = 0;/* DTIM count */
146 *dst_ie++ = 1;/* DTIM peroid */ 145 *dst_ie++ = 1;/* DTIM period */
147 146
148 if (pstapriv->tim_bitmap&BIT(0))/* for bc/mc frames */ 147 if (pstapriv->tim_bitmap & BIT(0))/* for bc/mc frames */
149 *dst_ie++ = BIT(0);/* bitmap ctrl */ 148 *dst_ie++ = BIT(0);/* bitmap ctrl */
150 else 149 else
151 *dst_ie++ = 0; 150 *dst_ie++ = 0;
@@ -153,7 +152,7 @@ static void update_BCNTIM(struct adapter *padapter)
153 if (tim_ielen == 4) { 152 if (tim_ielen == 4) {
154 __le16 pvb; 153 __le16 pvb;
155 154
156 if (pstapriv->tim_bitmap&0xff00) 155 if (pstapriv->tim_bitmap & 0xff00)
157 pvb = cpu_to_le16(pstapriv->tim_bitmap >> 8); 156 pvb = cpu_to_le16(pstapriv->tim_bitmap >> 8);
158 else 157 else
159 pvb = tim_bitmap_le; 158 pvb = tim_bitmap_le;
@@ -188,8 +187,8 @@ u8 chk_sta_is_alive(struct sta_info *psta)
188 /* STA_RX_PKTS_ARG(psta) */ 187 /* STA_RX_PKTS_ARG(psta) */
189 , STA_RX_PKTS_DIFF_ARG(psta) 188 , STA_RX_PKTS_DIFF_ARG(psta)
190 , psta->expire_to 189 , psta->expire_to
191 , psta->state&WIFI_SLEEP_STATE?"PS, ":"" 190 , psta->state & WIFI_SLEEP_STATE ? "PS, " : ""
192 , psta->state&WIFI_STA_ALIVE_CHK_STATE?"SAC, ":"" 191 , psta->state & WIFI_STA_ALIVE_CHK_STATE ? "SAC, " : ""
193 , psta->sleepq_len 192 , psta->sleepq_len
194 ); 193 );
195 #endif 194 #endif
@@ -292,7 +291,7 @@ void expire_timeout_chk(struct adapter *padapter)
292 291
293 if (psta->state & WIFI_SLEEP_STATE) { 292 if (psta->state & WIFI_SLEEP_STATE) {
294 if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) { 293 if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
295 /* to check if alive by another methods if staion is at ps mode. */ 294 /* to check if alive by another methods if station is at ps mode. */
296 psta->expire_to = pstapriv->expire_to; 295 psta->expire_to = pstapriv->expire_to;
297 psta->state |= WIFI_STA_ALIVE_CHK_STATE; 296 psta->state |= WIFI_STA_ALIVE_CHK_STATE;
298 297
@@ -325,10 +324,10 @@ void expire_timeout_chk(struct adapter *padapter)
325 updated = ap_free_sta(padapter, psta, false, WLAN_REASON_DEAUTH_LEAVING); 324 updated = ap_free_sta(padapter, psta, false, WLAN_REASON_DEAUTH_LEAVING);
326 } else { 325 } else {
327 /* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */ 326 /* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
328 if (psta->sleepq_len > (NR_XMITFRAME/pstapriv->asoc_list_cnt) 327 if (psta->sleepq_len > (NR_XMITFRAME / pstapriv->asoc_list_cnt)
329 && padapter->xmitpriv.free_xmitframe_cnt < (( 328 && padapter->xmitpriv.free_xmitframe_cnt < ((
330 NR_XMITFRAME/pstapriv->asoc_list_cnt 329 NR_XMITFRAME / pstapriv->asoc_list_cnt
331 )/2) 330 ) / 2)
332 ) { 331 ) {
333 DBG_871X( 332 DBG_871X(
334 "%s sta:"MAC_FMT", sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n", 333 "%s sta:"MAC_FMT", sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n",
@@ -586,8 +585,8 @@ void update_sta_info_apmode(struct adapter *padapter, struct sta_info *psta)
586 phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable; 585 phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
587 586
588 phtpriv_sta->rx_ampdu_min_spacing = ( 587 phtpriv_sta->rx_ampdu_min_spacing = (
589 phtpriv_sta->ht_cap.ampdu_params_info&IEEE80211_HT_CAP_AMPDU_DENSITY 588 phtpriv_sta->ht_cap.ampdu_params_info & IEEE80211_HT_CAP_AMPDU_DENSITY
590 )>>2; 589 ) >> 2;
591 590
592 /* bwmode */ 591 /* bwmode */
593 if (( 592 if ((
@@ -782,8 +781,8 @@ void start_bss_network(struct adapter *padapter, u8 *pbuf)
782 /* check if there is wps ie, */ 781 /* check if there is wps ie, */
783 /* if there is wpsie in beacon, the hostapd will update beacon twice when stating hostapd, */ 782 /* if there is wpsie in beacon, the hostapd will update beacon twice when stating hostapd, */
784 /* and at first time the security ie (RSN/WPA IE) will not include in beacon. */ 783 /* and at first time the security ie (RSN/WPA IE) will not include in beacon. */
785 if (!rtw_get_wps_ie(pnetwork->IEs+_FIXED_IE_LENGTH_, 784 if (!rtw_get_wps_ie(pnetwork->IEs + _FIXED_IE_LENGTH_,
786 pnetwork->IELength-_FIXED_IE_LENGTH_, NULL, NULL)) 785 pnetwork->IELength - _FIXED_IE_LENGTH_, NULL, NULL))
787 pmlmeext->bstart_bss = true; 786 pmlmeext->bstart_bss = true;
788 787
789 /* todo: update wmm, ht cap */ 788 /* todo: update wmm, ht cap */
@@ -861,7 +860,7 @@ void start_bss_network(struct adapter *padapter, u8 *pbuf)
861 (pnetwork->IELength - sizeof(struct ndis_802_11_fix_ie)) 860 (pnetwork->IELength - sizeof(struct ndis_802_11_fix_ie))
862 ); 861 );
863 if (p && ie_len) { 862 if (p && ie_len) {
864 pht_info = (struct HT_info_element *)(p+2); 863 pht_info = (struct HT_info_element *)(p + 2);
865 864
866 if (cur_channel > 14) { 865 if (cur_channel > 14) {
867 if ((pregpriv->bw_mode & 0xf0) > 0) 866 if ((pregpriv->bw_mode & 0xf0) > 0)
@@ -916,7 +915,7 @@ void start_bss_network(struct adapter *padapter, u8 *pbuf)
916 UpdateBrateTbl(padapter, pnetwork->SupportedRates); 915 UpdateBrateTbl(padapter, pnetwork->SupportedRates);
917 rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, pnetwork->SupportedRates); 916 rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, pnetwork->SupportedRates);
918 917
919 /* udpate capability after cur_wireless_mode updated */ 918 /* update capability after cur_wireless_mode updated */
920 update_capinfo( 919 update_capinfo(
921 padapter, 920 padapter,
922 rtw_get_capability((struct wlan_bssid_ex *)pnetwork) 921 rtw_get_capability((struct wlan_bssid_ex *)pnetwork)
@@ -1015,7 +1014,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
1015 pbss_network->Ssid.SsidLength = ie_len; 1014 pbss_network->Ssid.SsidLength = ie_len;
1016 } 1015 }
1017 1016
1018 /* chnnel */ 1017 /* channel */
1019 channel = 0; 1018 channel = 0;
1020 pbss_network->Configuration.Length = 0; 1019 pbss_network->Configuration.Length = 0;
1021 p = rtw_get_ie( 1020 p = rtw_get_ie(
@@ -1037,7 +1036,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
1037 (pbss_network->IELength - _BEACON_IE_OFFSET_) 1036 (pbss_network->IELength - _BEACON_IE_OFFSET_)
1038 ); 1037 );
1039 if (p != NULL) { 1038 if (p != NULL) {
1040 memcpy(supportRate, p+2, ie_len); 1039 memcpy(supportRate, p + 2, ie_len);
1041 supportRateNum = ie_len; 1040 supportRateNum = ie_len;
1042 } 1041 }
1043 1042
@@ -1049,7 +1048,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
1049 pbss_network->IELength - _BEACON_IE_OFFSET_ 1048 pbss_network->IELength - _BEACON_IE_OFFSET_
1050 ); 1049 );
1051 if (p != NULL) { 1050 if (p != NULL) {
1052 memcpy(supportRate+supportRateNum, p+2, ie_len); 1051 memcpy(supportRate + supportRateNum, p + 2, ie_len);
1053 supportRateNum += ie_len; 1052 supportRateNum += ie_len;
1054 } 1053 }
1055 1054
@@ -1088,7 +1087,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
1088 if (p && ie_len > 0) { 1087 if (p && ie_len > 0) {
1089 if (rtw_parse_wpa2_ie( 1088 if (rtw_parse_wpa2_ie(
1090 p, 1089 p,
1091 ie_len+2, 1090 ie_len + 2,
1092 &group_cipher, 1091 &group_cipher,
1093 &pairwise_cipher, 1092 &pairwise_cipher,
1094 NULL 1093 NULL
@@ -1115,10 +1114,10 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
1115 &ie_len, 1114 &ie_len,
1116 (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)) 1115 (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2))
1117 ); 1116 );
1118 if ((p) && (!memcmp(p+2, OUI1, 4))) { 1117 if ((p) && (!memcmp(p + 2, OUI1, 4))) {
1119 if (rtw_parse_wpa_ie( 1118 if (rtw_parse_wpa_ie(
1120 p, 1119 p,
1121 ie_len+2, 1120 ie_len + 2,
1122 &group_cipher, 1121 &group_cipher,
1123 &pairwise_cipher, 1122 &pairwise_cipher,
1124 NULL 1123 NULL
@@ -1151,10 +1150,10 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
1151 &ie_len, 1150 &ie_len,
1152 (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)) 1151 (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2))
1153 ); 1152 );
1154 if ((p) && !memcmp(p+2, WMM_PARA_IE, 6)) { 1153 if ((p) && !memcmp(p + 2, WMM_PARA_IE, 6)) {
1155 pmlmepriv->qospriv.qos_option = 1; 1154 pmlmepriv->qospriv.qos_option = 1;
1156 1155
1157 *(p+8) |= BIT(7);/* QoS Info, support U-APSD */ 1156 *(p + 8) |= BIT(7);/* QoS Info, support U-APSD */
1158 1157
1159 /* disable all ACM bits since the WMM admission control is not supported */ 1158 /* disable all ACM bits since the WMM admission control is not supported */
1160 *(p + 10) &= ~BIT(4); /* BE */ 1159 *(p + 10) &= ~BIT(4); /* BE */
@@ -1180,7 +1179,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
1180 if (p && ie_len > 0) { 1179 if (p && ie_len > 0) {
1181 u8 rf_type = 0; 1180 u8 rf_type = 0;
1182 u8 max_rx_ampdu_factor = 0; 1181 u8 max_rx_ampdu_factor = 0;
1183 struct rtw_ieee80211_ht_cap *pht_cap = (struct rtw_ieee80211_ht_cap *)(p+2); 1182 struct rtw_ieee80211_ht_cap *pht_cap = (struct rtw_ieee80211_ht_cap *)(p + 2);
1184 1183
1185 pHT_caps_ie = p; 1184 pHT_caps_ie = p;
1186 1185
@@ -1205,14 +1204,14 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
1205 pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_RX_STBC_3R)); 1204 pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_RX_STBC_3R));
1206 1205
1207 pht_cap->ampdu_params_info &= ~( 1206 pht_cap->ampdu_params_info &= ~(
1208 IEEE80211_HT_CAP_AMPDU_FACTOR|IEEE80211_HT_CAP_AMPDU_DENSITY 1207 IEEE80211_HT_CAP_AMPDU_FACTOR | IEEE80211_HT_CAP_AMPDU_DENSITY
1209 ); 1208 );
1210 1209
1211 if ((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) || 1210 if ((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) ||
1212 (psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP)) { 1211 (psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP)) {
1213 pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY&(0x07<<2)); 1212 pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & (0x07 << 2));
1214 } else { 1213 } else {
1215 pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY&0x00); 1214 pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00);
1216 } 1215 }
1217 1216
1218 rtw_hal_get_def_var( 1217 rtw_hal_get_def_var(
@@ -1230,7 +1229,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
1230 pht_cap->supp_mcs_set[1] = 0x0; 1229 pht_cap->supp_mcs_set[1] = 0x0;
1231 } 1230 }
1232 1231
1233 memcpy(&pmlmepriv->htpriv.ht_cap, p+2, ie_len); 1232 memcpy(&pmlmepriv->htpriv.ht_cap, p + 2, ie_len);
1234 } 1233 }
1235 1234
1236 /* parsing HT_INFO_IE */ 1235 /* parsing HT_INFO_IE */
@@ -1265,8 +1264,8 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
1265 1264
1266 pmlmepriv->htpriv.ht_option = false; 1265 pmlmepriv->htpriv.ht_option = false;
1267 1266
1268 if ((psecuritypriv->wpa2_pairwise_cipher&WPA_CIPHER_TKIP) || 1267 if ((psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_TKIP) ||
1269 (psecuritypriv->wpa_pairwise_cipher&WPA_CIPHER_TKIP)) { 1268 (psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_TKIP)) {
1270 /* todo: */ 1269 /* todo: */
1271 /* ht_cap = false; */ 1270 /* ht_cap = false; */
1272 } 1271 }
@@ -1341,7 +1340,7 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr)
1341 MAC_ARG(addr) 1340 MAC_ARG(addr)
1342 ); 1341 );
1343 1342
1344 if ((NUM_ACL-1) < pacl_list->num) 1343 if ((NUM_ACL - 1) < pacl_list->num)
1345 return (-1); 1344 return (-1);
1346 1345
1347 spin_lock_bh(&(pacl_node_q->lock)); 1346 spin_lock_bh(&(pacl_node_q->lock));
@@ -1454,7 +1453,7 @@ u8 rtw_ap_set_pairwise_key(struct adapter *padapter, struct sta_info *psta)
1454 1453
1455 psetstakey_para = rtw_zmalloc(sizeof(struct set_stakey_parm)); 1454 psetstakey_para = rtw_zmalloc(sizeof(struct set_stakey_parm));
1456 if (psetstakey_para == NULL) { 1455 if (psetstakey_para == NULL) {
1457 kfree((u8 *) ph2c); 1456 kfree((u8 *)ph2c);
1458 res = _FAIL; 1457 res = _FAIL;
1459 goto exit; 1458 goto exit;
1460 } 1459 }
@@ -1604,10 +1603,10 @@ static void update_bcn_erpinfo_ie(struct adapter *padapter)
1604 struct ndis_80211_var_ie *pIE = (struct ndis_80211_var_ie *)p; 1603 struct ndis_80211_var_ie *pIE = (struct ndis_80211_var_ie *)p;
1605 1604
1606 if (pmlmepriv->num_sta_non_erp == 1) 1605 if (pmlmepriv->num_sta_non_erp == 1)
1607 pIE->data[0] |= RTW_ERP_INFO_NON_ERP_PRESENT|RTW_ERP_INFO_USE_PROTECTION; 1606 pIE->data[0] |= RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION;
1608 else 1607 else
1609 pIE->data[0] &= ~( 1608 pIE->data[0] &= ~(
1610 RTW_ERP_INFO_NON_ERP_PRESENT|RTW_ERP_INFO_USE_PROTECTION 1609 RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION
1611 ); 1610 );
1612 1611
1613 if (pmlmepriv->num_sta_no_short_preamble > 0) 1612 if (pmlmepriv->num_sta_no_short_preamble > 0)
@@ -1662,8 +1661,8 @@ static void update_bcn_wps_ie(struct adapter *padapter)
1662 DBG_871X("%s\n", __func__); 1661 DBG_871X("%s\n", __func__);
1663 1662
1664 pwps_ie = rtw_get_wps_ie( 1663 pwps_ie = rtw_get_wps_ie(
1665 ie+_FIXED_IE_LENGTH_, 1664 ie + _FIXED_IE_LENGTH_,
1666 ielen-_FIXED_IE_LENGTH_, 1665 ielen - _FIXED_IE_LENGTH_,
1667 NULL, 1666 NULL,
1668 &wps_ielen 1667 &wps_ielen
1669 ); 1668 );
@@ -1675,7 +1674,7 @@ static void update_bcn_wps_ie(struct adapter *padapter)
1675 if (pwps_ie_src == NULL) 1674 if (pwps_ie_src == NULL)
1676 return; 1675 return;
1677 1676
1678 wps_offset = (uint)(pwps_ie-ie); 1677 wps_offset = (uint)(pwps_ie - ie);
1679 1678
1680 premainder_ie = pwps_ie + wps_ielen; 1679 premainder_ie = pwps_ie + wps_ielen;
1681 1680
@@ -1688,22 +1687,22 @@ static void update_bcn_wps_ie(struct adapter *padapter)
1688 } 1687 }
1689 1688
1690 wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */ 1689 wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
1691 if ((wps_offset+wps_ielen+2+remainder_ielen) <= MAX_IE_SZ) { 1690 if ((wps_offset + wps_ielen + 2 + remainder_ielen) <= MAX_IE_SZ) {
1692 memcpy(pwps_ie, pwps_ie_src, wps_ielen+2); 1691 memcpy(pwps_ie, pwps_ie_src, wps_ielen + 2);
1693 pwps_ie += (wps_ielen+2); 1692 pwps_ie += (wps_ielen+2);
1694 1693
1695 if (pbackup_remainder_ie) 1694 if (pbackup_remainder_ie)
1696 memcpy(pwps_ie, pbackup_remainder_ie, remainder_ielen); 1695 memcpy(pwps_ie, pbackup_remainder_ie, remainder_ielen);
1697 1696
1698 /* update IELength */ 1697 /* update IELength */
1699 pnetwork->IELength = wps_offset + (wps_ielen+2) + remainder_ielen; 1698 pnetwork->IELength = wps_offset + (wps_ielen + 2) + remainder_ielen;
1700 } 1699 }
1701 1700
1702 kfree(pbackup_remainder_ie); 1701 kfree(pbackup_remainder_ie);
1703 1702
1704 /* deal with the case without set_tx_beacon_cmd() in update_beacon() */ 1703 /* deal with the case without set_tx_beacon_cmd() in update_beacon() */
1705#if defined(CONFIG_INTERRUPT_BASED_TXBCN) 1704#if defined(CONFIG_INTERRUPT_BASED_TXBCN)
1706 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) { 1705 if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) {
1707 u8 sr = 0; 1706 u8 sr = 0;
1708 1707
1709 rtw_get_wps_attr_content( 1708 rtw_get_wps_attr_content(
@@ -1827,7 +1826,7 @@ void update_beacon(struct adapter *padapter, u8 ie_id, u8 *oui, u8 tx)
1827 1826
1828/* 1827/*
1829op_mode 1828op_mode
1830Set to 0 (HT pure) under the followign conditions 1829Set to 0 (HT pure) under the following conditions
1831 - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or 1830 - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
1832 - all STAs in the BSS are 20 MHz HT in 20 MHz BSS 1831 - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
1833Set to 1 (HT non-member protection) if there may be non-HT STAs 1832Set to 1 (HT non-member protection) if there may be non-HT STAs
@@ -2196,7 +2195,7 @@ void rtw_sta_flush(struct adapter *padapter)
2196 2195
2197 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev)); 2196 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
2198 2197
2199 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE) 2198 if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
2200 return; 2199 return;
2201 2200
2202 spin_lock_bh(&pstapriv->asoc_list_lock); 2201 spin_lock_bh(&pstapriv->asoc_list_lock);
@@ -2230,7 +2229,7 @@ void sta_info_update(struct adapter *padapter, struct sta_info *psta)
2230 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 2229 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2231 2230
2232 /* update wmm cap. */ 2231 /* update wmm cap. */
2233 if (WLAN_STA_WME&flags) 2232 if (WLAN_STA_WME & flags)
2234 psta->qos_option = 1; 2233 psta->qos_option = 1;
2235 else 2234 else
2236 psta->qos_option = 0; 2235 psta->qos_option = 0;
@@ -2239,7 +2238,7 @@ void sta_info_update(struct adapter *padapter, struct sta_info *psta)
2239 psta->qos_option = 0; 2238 psta->qos_option = 0;
2240 2239
2241 /* update 802.11n ht cap. */ 2240 /* update 802.11n ht cap. */
2242 if (WLAN_STA_HT&flags) { 2241 if (WLAN_STA_HT & flags) {
2243 psta->htpriv.ht_option = true; 2242 psta->htpriv.ht_option = true;
2244 psta->qos_option = 1; 2243 psta->qos_option = 1;
2245 } else { 2244 } else {
diff --git a/drivers/staging/rtl8723bs/core/rtw_cmd.c b/drivers/staging/rtl8723bs/core/rtw_cmd.c
index addc55706a3c..8d93c2f26890 100644
--- a/drivers/staging/rtl8723bs/core/rtw_cmd.c
+++ b/drivers/staging/rtl8723bs/core/rtw_cmd.c
@@ -402,7 +402,7 @@ int rtw_cmd_thread(void *context)
402{ 402{
403 u8 ret; 403 u8 ret;
404 struct cmd_obj *pcmd; 404 struct cmd_obj *pcmd;
405 u8 *pcmdbuf, *prspbuf; 405 u8 *pcmdbuf;
406 unsigned long cmd_start_time; 406 unsigned long cmd_start_time;
407 unsigned long cmd_process_time; 407 unsigned long cmd_process_time;
408 u8 (*cmd_hdl)(struct adapter *padapter, u8 *pbuf); 408 u8 (*cmd_hdl)(struct adapter *padapter, u8 *pbuf);
@@ -414,7 +414,6 @@ int rtw_cmd_thread(void *context)
414 thread_enter("RTW_CMD_THREAD"); 414 thread_enter("RTW_CMD_THREAD");
415 415
416 pcmdbuf = pcmdpriv->cmd_buf; 416 pcmdbuf = pcmdpriv->cmd_buf;
417 prspbuf = pcmdpriv->rsp_buf;
418 417
419 pcmdpriv->stop_req = 0; 418 pcmdpriv->stop_req = 0;
420 atomic_set(&(pcmdpriv->cmdthd_running), true); 419 atomic_set(&(pcmdpriv->cmdthd_running), true);
@@ -768,7 +767,7 @@ exit:
768 767
769u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork) 768u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork)
770{ 769{
771 u8 *auth, res = _SUCCESS; 770 u8 res = _SUCCESS;
772 uint t_len = 0; 771 uint t_len = 0;
773 struct wlan_bssid_ex *psecnetwork; 772 struct wlan_bssid_ex *psecnetwork;
774 struct cmd_obj *pcmd; 773 struct cmd_obj *pcmd;
@@ -825,7 +824,6 @@ u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork)
825 824
826 memcpy(psecnetwork, &pnetwork->network, get_wlan_bssid_ex_sz(&pnetwork->network)); 825 memcpy(psecnetwork, &pnetwork->network, get_wlan_bssid_ex_sz(&pnetwork->network));
827 826
828 auth = &psecuritypriv->authenticator_ie[0];
829 psecuritypriv->authenticator_ie[0] = (unsigned char)psecnetwork->IELength; 827 psecuritypriv->authenticator_ie[0] = (unsigned char)psecnetwork->IELength;
830 828
831 if ((psecnetwork->IELength-12) < (256-1)) { 829 if ((psecnetwork->IELength-12) < (256-1)) {
@@ -1819,11 +1817,6 @@ static void rtw_btinfo_hdl(struct adapter *adapter, u8 *buf, u16 buf_len)
1819 len = info->len; 1817 len = info->len;
1820 } 1818 }
1821 1819
1822/* define DBG_PROC_SET_BTINFO_EVT */
1823#ifdef DBG_PROC_SET_BTINFO_EVT
1824 btinfo_evt_dump(RTW_DBGDUMP, info);
1825#endif
1826
1827 /* transform BT-FW btinfo to WiFI-FW C2H format and notify */ 1820 /* transform BT-FW btinfo to WiFI-FW C2H format and notify */
1828 if (cmd_idx == BTINFO_WIFI_FETCH) 1821 if (cmd_idx == BTINFO_WIFI_FETCH)
1829 buf[1] = 0; 1822 buf[1] = 0;
diff --git a/drivers/staging/rtl8723bs/core/rtw_debug.c b/drivers/staging/rtl8723bs/core/rtw_debug.c
index 695a85999270..c48a8b80af4c 100644
--- a/drivers/staging/rtl8723bs/core/rtw_debug.c
+++ b/drivers/staging/rtl8723bs/core/rtw_debug.c
@@ -132,1310 +132,3 @@ void rf_reg_dump(void *sel, struct adapter *adapter)
132 } 132 }
133 } 133 }
134} 134}
135
136#ifdef PROC_DEBUG
137ssize_t proc_set_write_reg(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
138{
139 struct net_device *dev = data;
140 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
141 char tmp[32];
142 u32 addr, val, len;
143
144 if (count < 3) {
145 DBG_871X("argument size is less than 3\n");
146 return -EFAULT;
147 }
148
149 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
150
151 int num = sscanf(tmp, "%x %x %x", &addr, &val, &len);
152
153 if (num != 3) {
154 DBG_871X("invalid write_reg parameter!\n");
155 return count;
156 }
157
158 switch (len) {
159 case 1:
160 rtw_write8(padapter, addr, (u8)val);
161 break;
162 case 2:
163 rtw_write16(padapter, addr, (u16)val);
164 break;
165 case 4:
166 rtw_write32(padapter, addr, val);
167 break;
168 default:
169 DBG_871X("error write length =%d", len);
170 break;
171 }
172
173 }
174
175 return count;
176
177}
178
179static u32 proc_get_read_addr = 0xeeeeeeee;
180static u32 proc_get_read_len = 0x4;
181
182int proc_get_read_reg(struct seq_file *m, void *v)
183{
184 struct net_device *dev = m->private;
185 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
186
187 if (proc_get_read_addr == 0xeeeeeeee) {
188 DBG_871X_SEL_NL(m, "address not initialized\n");
189 return 0;
190 }
191
192 switch (proc_get_read_len) {
193 case 1:
194 DBG_871X_SEL_NL(m, "rtw_read8(0x%x) = 0x%x\n", proc_get_read_addr, rtw_read8(padapter, proc_get_read_addr));
195 break;
196 case 2:
197 DBG_871X_SEL_NL(m, "rtw_read16(0x%x) = 0x%x\n", proc_get_read_addr, rtw_read16(padapter, proc_get_read_addr));
198 break;
199 case 4:
200 DBG_871X_SEL_NL(m, "rtw_read32(0x%x) = 0x%x\n", proc_get_read_addr, rtw_read32(padapter, proc_get_read_addr));
201 break;
202 default:
203 DBG_871X_SEL_NL(m, "error read length =%d\n", proc_get_read_len);
204 break;
205 }
206
207 return 0;
208}
209
210ssize_t proc_set_read_reg(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
211{
212 char tmp[16];
213 u32 addr, len;
214
215 if (count < 2) {
216 DBG_871X("argument size is less than 2\n");
217 return -EFAULT;
218 }
219
220 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
221
222 int num = sscanf(tmp, "%x %x", &addr, &len);
223
224 if (num != 2) {
225 DBG_871X("invalid read_reg parameter!\n");
226 return count;
227 }
228
229 proc_get_read_addr = addr;
230
231 proc_get_read_len = len;
232 }
233
234 return count;
235
236}
237
238int proc_get_fwstate(struct seq_file *m, void *v)
239{
240 struct net_device *dev = m->private;
241 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
242 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
243
244 DBG_871X_SEL_NL(m, "fwstate = 0x%x\n", get_fwstate(pmlmepriv));
245
246 return 0;
247}
248
249int proc_get_sec_info(struct seq_file *m, void *v)
250{
251 struct net_device *dev = m->private;
252 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
253 struct security_priv *sec = &padapter->securitypriv;
254
255 DBG_871X_SEL_NL(m, "auth_alg = 0x%x, enc_alg = 0x%x, auth_type = 0x%x, enc_type = 0x%x\n",
256 sec->dot11AuthAlgrthm, sec->dot11PrivacyAlgrthm,
257 sec->ndisauthtype, sec->ndisencryptstatus);
258
259 DBG_871X_SEL_NL(m, "hw_decrypted =%d\n", sec->hw_decrypted);
260
261#ifdef DBG_SW_SEC_CNT
262 DBG_871X_SEL_NL(m, "wep_sw_enc_cnt =%llu, %llu, %llu\n"
263 , sec->wep_sw_enc_cnt_bc, sec->wep_sw_enc_cnt_mc, sec->wep_sw_enc_cnt_uc);
264 DBG_871X_SEL_NL(m, "wep_sw_dec_cnt =%llu, %llu, %llu\n"
265 , sec->wep_sw_dec_cnt_bc, sec->wep_sw_dec_cnt_mc, sec->wep_sw_dec_cnt_uc);
266
267 DBG_871X_SEL_NL(m, "tkip_sw_enc_cnt =%llu, %llu, %llu\n"
268 , sec->tkip_sw_enc_cnt_bc, sec->tkip_sw_enc_cnt_mc, sec->tkip_sw_enc_cnt_uc);
269 DBG_871X_SEL_NL(m, "tkip_sw_dec_cnt =%llu, %llu, %llu\n"
270 , sec->tkip_sw_dec_cnt_bc, sec->tkip_sw_dec_cnt_mc, sec->tkip_sw_dec_cnt_uc);
271
272 DBG_871X_SEL_NL(m, "aes_sw_enc_cnt =%llu, %llu, %llu\n"
273 , sec->aes_sw_enc_cnt_bc, sec->aes_sw_enc_cnt_mc, sec->aes_sw_enc_cnt_uc);
274 DBG_871X_SEL_NL(m, "aes_sw_dec_cnt =%llu, %llu, %llu\n"
275 , sec->aes_sw_dec_cnt_bc, sec->aes_sw_dec_cnt_mc, sec->aes_sw_dec_cnt_uc);
276#endif /* DBG_SW_SEC_CNT */
277
278 return 0;
279}
280
281int proc_get_mlmext_state(struct seq_file *m, void *v)
282{
283 struct net_device *dev = m->private;
284 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
285 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
286 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
287
288 DBG_871X_SEL_NL(m, "pmlmeinfo->state = 0x%x\n", pmlmeinfo->state);
289
290 return 0;
291}
292
293int proc_get_roam_flags(struct seq_file *m, void *v)
294{
295 struct net_device *dev = m->private;
296 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
297
298 DBG_871X_SEL_NL(m, "0x%02x\n", rtw_roam_flags(adapter));
299
300 return 0;
301}
302
303ssize_t proc_set_roam_flags(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
304{
305 struct net_device *dev = data;
306 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
307
308 char tmp[32];
309 u8 flags;
310
311 if (count < 1)
312 return -EFAULT;
313
314 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
315
316 int num = sscanf(tmp, "%hhx", &flags);
317
318 if (num == 1)
319 rtw_assign_roam_flags(adapter, flags);
320 }
321
322 return count;
323
324}
325
326int proc_get_roam_param(struct seq_file *m, void *v)
327{
328 struct net_device *dev = m->private;
329 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
330 struct mlme_priv *mlme = &adapter->mlmepriv;
331
332 DBG_871X_SEL_NL(m, "%12s %12s %11s\n", "rssi_diff_th", "scanr_exp_ms", "scan_int_ms");
333 DBG_871X_SEL_NL(m, "%-12u %-12u %-11u\n"
334 , mlme->roam_rssi_diff_th
335 , mlme->roam_scanr_exp_ms
336 , mlme->roam_scan_int_ms
337 );
338
339 return 0;
340}
341
342ssize_t proc_set_roam_param(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
343{
344 struct net_device *dev = data;
345 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
346 struct mlme_priv *mlme = &adapter->mlmepriv;
347
348 char tmp[32];
349 u8 rssi_diff_th;
350 u32 scanr_exp_ms;
351 u32 scan_int_ms;
352
353 if (count < 1)
354 return -EFAULT;
355
356 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
357
358 int num = sscanf(tmp, "%hhu %u %u", &rssi_diff_th, &scanr_exp_ms, &scan_int_ms);
359
360 if (num >= 1)
361 mlme->roam_rssi_diff_th = rssi_diff_th;
362 if (num >= 2)
363 mlme->roam_scanr_exp_ms = scanr_exp_ms;
364 if (num >= 3)
365 mlme->roam_scan_int_ms = scan_int_ms;
366 }
367
368 return count;
369
370}
371
372ssize_t proc_set_roam_tgt_addr(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
373{
374 struct net_device *dev = data;
375 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
376
377 char tmp[32];
378 u8 addr[ETH_ALEN];
379
380 if (count < 1)
381 return -EFAULT;
382
383 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
384
385 int num = sscanf(tmp, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", addr, addr+1, addr+2, addr+3, addr+4, addr+5);
386 if (num == 6)
387 memcpy(adapter->mlmepriv.roam_tgt_addr, addr, ETH_ALEN);
388
389 DBG_871X("set roam_tgt_addr to "MAC_FMT"\n", MAC_ARG(adapter->mlmepriv.roam_tgt_addr));
390 }
391
392 return count;
393}
394
395int proc_get_qos_option(struct seq_file *m, void *v)
396{
397 struct net_device *dev = m->private;
398 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
399 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
400
401 DBG_871X_SEL_NL(m, "qos_option =%d\n", pmlmepriv->qospriv.qos_option);
402
403 return 0;
404}
405
406int proc_get_ht_option(struct seq_file *m, void *v)
407{
408 struct net_device *dev = m->private;
409 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
410 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
411
412 DBG_871X_SEL_NL(m, "ht_option =%d\n", pmlmepriv->htpriv.ht_option);
413
414 return 0;
415}
416
417int proc_get_rf_info(struct seq_file *m, void *v)
418{
419 struct net_device *dev = m->private;
420 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
421 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
422
423 DBG_871X_SEL_NL(m, "cur_ch =%d, cur_bw =%d, cur_ch_offet =%d\n",
424 pmlmeext->cur_channel, pmlmeext->cur_bwmode, pmlmeext->cur_ch_offset);
425
426 DBG_871X_SEL_NL(m, "oper_ch =%d, oper_bw =%d, oper_ch_offet =%d\n",
427 rtw_get_oper_ch(padapter), rtw_get_oper_bw(padapter), rtw_get_oper_choffset(padapter));
428
429 return 0;
430}
431
432int proc_get_survey_info(struct seq_file *m, void *v)
433{
434 struct net_device *dev = m->private;
435 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
436 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
437 struct __queue *queue = &(pmlmepriv->scanned_queue);
438 struct wlan_network *pnetwork = NULL;
439 struct list_head *plist, *phead;
440 s32 notify_signal;
441 s16 notify_noise = 0;
442 u16 index = 0;
443
444 spin_lock_bh(&(pmlmepriv->scanned_queue.lock));
445 phead = get_list_head(queue);
446 plist = phead ? get_next(phead) : NULL;
447 if ((!phead) || (!plist)) {
448 spin_unlock_bh(&(pmlmepriv->scanned_queue.lock));
449 return 0;
450 }
451
452 DBG_871X_SEL_NL(m, "%5s %-17s %3s %-3s %-4s %-4s %5s %s\n", "index", "bssid", "ch", "RSSI", "SdBm", "Noise", "age", "ssid");
453 while (1) {
454 if (phead == plist)
455 break;
456
457 pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
458
459 if (!pnetwork)
460 break;
461
462 if (check_fwstate(pmlmepriv, _FW_LINKED) == true &&
463 is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network, 0)) {
464 notify_signal = translate_percentage_to_dbm(padapter->recvpriv.signal_strength);/*dbm*/
465 } else {
466 notify_signal = translate_percentage_to_dbm(pnetwork->network.PhyInfo.SignalStrength);/*dbm*/
467 }
468
469 #if defined(CONFIG_SIGNAL_DISPLAY_DBM) && defined(CONFIG_BACKGROUND_NOISE_MONITOR)
470 rtw_hal_get_odm_var(padapter, HAL_ODM_NOISE_MONITOR, &(pnetwork->network.Configuration.DSConfig), &(notify_noise));
471 #endif
472
473 DBG_871X_SEL_NL(m, "%5d "MAC_FMT" %3d %3d %4d %4d %5d %s\n",
474 ++index,
475 MAC_ARG(pnetwork->network.MacAddress),
476 pnetwork->network.Configuration.DSConfig,
477 (int)pnetwork->network.Rssi,
478 notify_signal,
479 notify_noise,
480 jiffies_to_msecs(jiffies - pnetwork->last_scanned),
481 /*translate_percentage_to_dbm(pnetwork->network.PhyInfo.SignalStrength),*/
482 pnetwork->network.Ssid.Ssid);
483 plist = get_next(plist);
484 }
485 spin_unlock_bh(&(pmlmepriv->scanned_queue.lock));
486
487 return 0;
488}
489
490int proc_get_ap_info(struct seq_file *m, void *v)
491{
492 struct net_device *dev = m->private;
493 struct sta_info *psta;
494 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
495 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
496 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
497 struct wlan_network *cur_network = &(pmlmepriv->cur_network);
498 struct sta_priv *pstapriv = &padapter->stapriv;
499
500 psta = rtw_get_stainfo(pstapriv, cur_network->network.MacAddress);
501 if (psta) {
502 int i;
503 struct recv_reorder_ctrl *preorder_ctrl;
504
505 DBG_871X_SEL_NL(m, "SSID =%s\n", cur_network->network.Ssid.Ssid);
506 DBG_871X_SEL_NL(m, "sta's macaddr:" MAC_FMT "\n", MAC_ARG(psta->hwaddr));
507 DBG_871X_SEL_NL(m, "cur_channel =%d, cur_bwmode =%d, cur_ch_offset =%d\n", pmlmeext->cur_channel, pmlmeext->cur_bwmode, pmlmeext->cur_ch_offset);
508 DBG_871X_SEL_NL(m, "wireless_mode = 0x%x, rtsen =%d, cts2slef =%d\n", psta->wireless_mode, psta->rtsen, psta->cts2self);
509 DBG_871X_SEL_NL(m, "state = 0x%x, aid =%d, macid =%d, raid =%d\n", psta->state, psta->aid, psta->mac_id, psta->raid);
510 DBG_871X_SEL_NL(m, "qos_en =%d, ht_en =%d, init_rate =%d\n", psta->qos_option, psta->htpriv.ht_option, psta->init_rate);
511 DBG_871X_SEL_NL(m, "bwmode =%d, ch_offset =%d, sgi_20m =%d, sgi_40m =%d\n", psta->bw_mode, psta->htpriv.ch_offset, psta->htpriv.sgi_20m, psta->htpriv.sgi_40m);
512 DBG_871X_SEL_NL(m, "ampdu_enable = %d\n", psta->htpriv.ampdu_enable);
513 DBG_871X_SEL_NL(m, "agg_enable_bitmap =%x, candidate_tid_bitmap =%x\n", psta->htpriv.agg_enable_bitmap, psta->htpriv.candidate_tid_bitmap);
514 DBG_871X_SEL_NL(m, "ldpc_cap = 0x%x, stbc_cap = 0x%x, beamform_cap = 0x%x\n", psta->htpriv.ldpc_cap, psta->htpriv.stbc_cap, psta->htpriv.beamform_cap);
515
516 for (i = 0; i < 16; i++) {
517 preorder_ctrl = &psta->recvreorder_ctrl[i];
518 if (preorder_ctrl->enable) {
519 DBG_871X_SEL_NL(m, "tid =%d, indicate_seq =%d\n", i, preorder_ctrl->indicate_seq);
520 }
521 }
522
523 } else {
524 DBG_871X_SEL_NL(m, "can't get sta's macaddr, cur_network's macaddr:" MAC_FMT "\n", MAC_ARG(cur_network->network.MacAddress));
525 }
526
527 return 0;
528}
529
530int proc_get_adapter_state(struct seq_file *m, void *v)
531{
532 struct net_device *dev = m->private;
533 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
534
535 DBG_871X_SEL_NL(m, "name =%s, bSurpriseRemoved =%d, bDriverStopped =%d\n",
536 dev->name, padapter->bSurpriseRemoved, padapter->bDriverStopped);
537
538 return 0;
539}
540
541int proc_get_trx_info(struct seq_file *m, void *v)
542{
543 struct net_device *dev = m->private;
544 int i;
545 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
546 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
547 struct recv_priv *precvpriv = &padapter->recvpriv;
548 struct hw_xmit *phwxmit;
549
550 DBG_871X_SEL_NL(m, "free_xmitbuf_cnt =%d, free_xmitframe_cnt =%d\n"
551 , pxmitpriv->free_xmitbuf_cnt, pxmitpriv->free_xmitframe_cnt);
552 DBG_871X_SEL_NL(m, "free_ext_xmitbuf_cnt =%d, free_xframe_ext_cnt =%d\n"
553 , pxmitpriv->free_xmit_extbuf_cnt, pxmitpriv->free_xframe_ext_cnt);
554 DBG_871X_SEL_NL(m, "free_recvframe_cnt =%d\n"
555 , precvpriv->free_recvframe_cnt);
556
557 for (i = 0; i < 4; i++) {
558 phwxmit = pxmitpriv->hwxmits + i;
559 DBG_871X_SEL_NL(m, "%d, hwq.accnt =%d\n", i, phwxmit->accnt);
560 }
561
562 return 0;
563}
564
565int proc_get_rate_ctl(struct seq_file *m, void *v)
566{
567 struct net_device *dev = m->private;
568 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
569
570 if (adapter->fix_rate != 0xff) {
571 DBG_871X_SEL_NL(m, "FIX\n");
572 DBG_871X_SEL_NL(m, "0x%02x\n", adapter->fix_rate);
573 } else {
574 DBG_871X_SEL_NL(m, "RA\n");
575 }
576
577 return 0;
578}
579
580ssize_t proc_set_rate_ctl(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
581{
582 struct net_device *dev = data;
583 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
584 char tmp[32];
585 u8 fix_rate;
586
587 if (count < 1)
588 return -EFAULT;
589
590 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
591
592 int num = sscanf(tmp, "%hhx", &fix_rate);
593
594 if (num >= 1)
595 adapter->fix_rate = fix_rate;
596 }
597
598 return count;
599}
600
601ssize_t proc_set_fwdl_test_case(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
602{
603 char tmp[32];
604
605 if (count < 1)
606 return -EFAULT;
607
608 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
609 sscanf(tmp, "%hhu %hhu", &g_fwdl_chksum_fail, &g_fwdl_wintint_rdy_fail);
610 }
611
612 return count;
613}
614
615ssize_t proc_set_wait_hiq_empty(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
616{
617 char tmp[32];
618
619 if (count < 1)
620 return -EFAULT;
621
622 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
623 sscanf(tmp, "%u", &g_wait_hiq_empty);
624 }
625
626 return count;
627}
628
629int proc_get_suspend_resume_info(struct seq_file *m, void *v)
630{
631 struct net_device *dev = m->private;
632 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
633 struct dvobj_priv *dvobj = padapter->dvobj;
634 struct debug_priv *pdbgpriv = &dvobj->drv_dbg;
635
636 DBG_871X_SEL_NL(m, "dbg_sdio_alloc_irq_cnt =%d\n", pdbgpriv->dbg_sdio_alloc_irq_cnt);
637 DBG_871X_SEL_NL(m, "dbg_sdio_free_irq_cnt =%d\n", pdbgpriv->dbg_sdio_free_irq_cnt);
638 DBG_871X_SEL_NL(m, "dbg_sdio_alloc_irq_error_cnt =%d\n", pdbgpriv->dbg_sdio_alloc_irq_error_cnt);
639 DBG_871X_SEL_NL(m, "dbg_sdio_free_irq_error_cnt =%d\n", pdbgpriv->dbg_sdio_free_irq_error_cnt);
640 DBG_871X_SEL_NL(m, "dbg_sdio_init_error_cnt =%d\n", pdbgpriv->dbg_sdio_init_error_cnt);
641 DBG_871X_SEL_NL(m, "dbg_sdio_deinit_error_cnt =%d\n", pdbgpriv->dbg_sdio_deinit_error_cnt);
642 DBG_871X_SEL_NL(m, "dbg_suspend_error_cnt =%d\n", pdbgpriv->dbg_suspend_error_cnt);
643 DBG_871X_SEL_NL(m, "dbg_suspend_cnt =%d\n", pdbgpriv->dbg_suspend_cnt);
644 DBG_871X_SEL_NL(m, "dbg_resume_cnt =%d\n", pdbgpriv->dbg_resume_cnt);
645 DBG_871X_SEL_NL(m, "dbg_resume_error_cnt =%d\n", pdbgpriv->dbg_resume_error_cnt);
646 DBG_871X_SEL_NL(m, "dbg_deinit_fail_cnt =%d\n", pdbgpriv->dbg_deinit_fail_cnt);
647 DBG_871X_SEL_NL(m, "dbg_carddisable_cnt =%d\n", pdbgpriv->dbg_carddisable_cnt);
648 DBG_871X_SEL_NL(m, "dbg_ps_insuspend_cnt =%d\n", pdbgpriv->dbg_ps_insuspend_cnt);
649 DBG_871X_SEL_NL(m, "dbg_dev_unload_inIPS_cnt =%d\n", pdbgpriv->dbg_dev_unload_inIPS_cnt);
650 DBG_871X_SEL_NL(m, "dbg_scan_pwr_state_cnt =%d\n", pdbgpriv->dbg_scan_pwr_state_cnt);
651 DBG_871X_SEL_NL(m, "dbg_downloadfw_pwr_state_cnt =%d\n", pdbgpriv->dbg_downloadfw_pwr_state_cnt);
652 DBG_871X_SEL_NL(m, "dbg_carddisable_error_cnt =%d\n", pdbgpriv->dbg_carddisable_error_cnt);
653 DBG_871X_SEL_NL(m, "dbg_fw_read_ps_state_fail_cnt =%d\n", pdbgpriv->dbg_fw_read_ps_state_fail_cnt);
654 DBG_871X_SEL_NL(m, "dbg_leave_ips_fail_cnt =%d\n", pdbgpriv->dbg_leave_ips_fail_cnt);
655 DBG_871X_SEL_NL(m, "dbg_leave_lps_fail_cnt =%d\n", pdbgpriv->dbg_leave_lps_fail_cnt);
656 DBG_871X_SEL_NL(m, "dbg_h2c_leave32k_fail_cnt =%d\n", pdbgpriv->dbg_h2c_leave32k_fail_cnt);
657 DBG_871X_SEL_NL(m, "dbg_diswow_dload_fw_fail_cnt =%d\n", pdbgpriv->dbg_diswow_dload_fw_fail_cnt);
658 DBG_871X_SEL_NL(m, "dbg_enwow_dload_fw_fail_cnt =%d\n", pdbgpriv->dbg_enwow_dload_fw_fail_cnt);
659 DBG_871X_SEL_NL(m, "dbg_ips_drvopen_fail_cnt =%d\n", pdbgpriv->dbg_ips_drvopen_fail_cnt);
660 DBG_871X_SEL_NL(m, "dbg_poll_fail_cnt =%d\n", pdbgpriv->dbg_poll_fail_cnt);
661 DBG_871X_SEL_NL(m, "dbg_rpwm_toggle_cnt =%d\n", pdbgpriv->dbg_rpwm_toggle_cnt);
662 DBG_871X_SEL_NL(m, "dbg_rpwm_timeout_fail_cnt =%d\n", pdbgpriv->dbg_rpwm_timeout_fail_cnt);
663
664 return 0;
665}
666
667#ifdef CONFIG_DBG_COUNTER
668
669int proc_get_rx_logs(struct seq_file *m, void *v)
670{
671 struct net_device *dev = m->private;
672 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
673 struct rx_logs *rx_logs = &padapter->rx_logs;
674
675 DBG_871X_SEL_NL(m,
676 "intf_rx =%d\n"
677 "intf_rx_err_recvframe =%d\n"
678 "intf_rx_err_skb =%d\n"
679 "intf_rx_report =%d\n"
680 "core_rx =%d\n"
681 "core_rx_pre =%d\n"
682 "core_rx_pre_ver_err =%d\n"
683 "core_rx_pre_mgmt =%d\n"
684 "core_rx_pre_mgmt_err_80211w =%d\n"
685 "core_rx_pre_mgmt_err =%d\n"
686 "core_rx_pre_ctrl =%d\n"
687 "core_rx_pre_ctrl_err =%d\n"
688 "core_rx_pre_data =%d\n"
689 "core_rx_pre_data_wapi_seq_err =%d\n"
690 "core_rx_pre_data_wapi_key_err =%d\n"
691 "core_rx_pre_data_handled =%d\n"
692 "core_rx_pre_data_err =%d\n"
693 "core_rx_pre_data_unknown =%d\n"
694 "core_rx_pre_unknown =%d\n"
695 "core_rx_enqueue =%d\n"
696 "core_rx_dequeue =%d\n"
697 "core_rx_post =%d\n"
698 "core_rx_post_decrypt =%d\n"
699 "core_rx_post_decrypt_wep =%d\n"
700 "core_rx_post_decrypt_tkip =%d\n"
701 "core_rx_post_decrypt_aes =%d\n"
702 "core_rx_post_decrypt_wapi =%d\n"
703 "core_rx_post_decrypt_hw =%d\n"
704 "core_rx_post_decrypt_unknown =%d\n"
705 "core_rx_post_decrypt_err =%d\n"
706 "core_rx_post_defrag_err =%d\n"
707 "core_rx_post_portctrl_err =%d\n"
708 "core_rx_post_indicate =%d\n"
709 "core_rx_post_indicate_in_oder =%d\n"
710 "core_rx_post_indicate_reoder =%d\n"
711 "core_rx_post_indicate_err =%d\n"
712 "os_indicate =%d\n"
713 "os_indicate_ap_mcast =%d\n"
714 "os_indicate_ap_forward =%d\n"
715 "os_indicate_ap_self =%d\n"
716 "os_indicate_err =%d\n"
717 "os_netif_ok =%d\n"
718 "os_netif_err =%d\n",
719 rx_logs->intf_rx,
720 rx_logs->intf_rx_err_recvframe,
721 rx_logs->intf_rx_err_skb,
722 rx_logs->intf_rx_report,
723 rx_logs->core_rx,
724 rx_logs->core_rx_pre,
725 rx_logs->core_rx_pre_ver_err,
726 rx_logs->core_rx_pre_mgmt,
727 rx_logs->core_rx_pre_mgmt_err_80211w,
728 rx_logs->core_rx_pre_mgmt_err,
729 rx_logs->core_rx_pre_ctrl,
730 rx_logs->core_rx_pre_ctrl_err,
731 rx_logs->core_rx_pre_data,
732 rx_logs->core_rx_pre_data_wapi_seq_err,
733 rx_logs->core_rx_pre_data_wapi_key_err,
734 rx_logs->core_rx_pre_data_handled,
735 rx_logs->core_rx_pre_data_err,
736 rx_logs->core_rx_pre_data_unknown,
737 rx_logs->core_rx_pre_unknown,
738 rx_logs->core_rx_enqueue,
739 rx_logs->core_rx_dequeue,
740 rx_logs->core_rx_post,
741 rx_logs->core_rx_post_decrypt,
742 rx_logs->core_rx_post_decrypt_wep,
743 rx_logs->core_rx_post_decrypt_tkip,
744 rx_logs->core_rx_post_decrypt_aes,
745 rx_logs->core_rx_post_decrypt_wapi,
746 rx_logs->core_rx_post_decrypt_hw,
747 rx_logs->core_rx_post_decrypt_unknown,
748 rx_logs->core_rx_post_decrypt_err,
749 rx_logs->core_rx_post_defrag_err,
750 rx_logs->core_rx_post_portctrl_err,
751 rx_logs->core_rx_post_indicate,
752 rx_logs->core_rx_post_indicate_in_oder,
753 rx_logs->core_rx_post_indicate_reoder,
754 rx_logs->core_rx_post_indicate_err,
755 rx_logs->os_indicate,
756 rx_logs->os_indicate_ap_mcast,
757 rx_logs->os_indicate_ap_forward,
758 rx_logs->os_indicate_ap_self,
759 rx_logs->os_indicate_err,
760 rx_logs->os_netif_ok,
761 rx_logs->os_netif_err
762 );
763
764 return 0;
765}
766
767int proc_get_tx_logs(struct seq_file *m, void *v)
768{
769 struct net_device *dev = m->private;
770 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
771 struct tx_logs *tx_logs = &padapter->tx_logs;
772
773 DBG_871X_SEL_NL(m,
774 "os_tx =%d\n"
775 "os_tx_err_up =%d\n"
776 "os_tx_err_xmit =%d\n"
777 "os_tx_m2u =%d\n"
778 "os_tx_m2u_ignore_fw_linked =%d\n"
779 "os_tx_m2u_ignore_self =%d\n"
780 "os_tx_m2u_entry =%d\n"
781 "os_tx_m2u_entry_err_xmit =%d\n"
782 "os_tx_m2u_entry_err_skb =%d\n"
783 "os_tx_m2u_stop =%d\n"
784 "core_tx =%d\n"
785 "core_tx_err_pxmitframe =%d\n"
786 "core_tx_err_brtx =%d\n"
787 "core_tx_upd_attrib =%d\n"
788 "core_tx_upd_attrib_adhoc =%d\n"
789 "core_tx_upd_attrib_sta =%d\n"
790 "core_tx_upd_attrib_ap =%d\n"
791 "core_tx_upd_attrib_unknown =%d\n"
792 "core_tx_upd_attrib_dhcp =%d\n"
793 "core_tx_upd_attrib_icmp =%d\n"
794 "core_tx_upd_attrib_active =%d\n"
795 "core_tx_upd_attrib_err_ucast_sta =%d\n"
796 "core_tx_upd_attrib_err_ucast_ap_link =%d\n"
797 "core_tx_upd_attrib_err_sta =%d\n"
798 "core_tx_upd_attrib_err_link =%d\n"
799 "core_tx_upd_attrib_err_sec =%d\n"
800 "core_tx_ap_enqueue_warn_fwstate =%d\n"
801 "core_tx_ap_enqueue_warn_sta =%d\n"
802 "core_tx_ap_enqueue_warn_nosta =%d\n"
803 "core_tx_ap_enqueue_warn_link =%d\n"
804 "core_tx_ap_enqueue_warn_trigger =%d\n"
805 "core_tx_ap_enqueue_mcast =%d\n"
806 "core_tx_ap_enqueue_ucast =%d\n"
807 "core_tx_ap_enqueue =%d\n"
808 "intf_tx =%d\n"
809 "intf_tx_pending_ac =%d\n"
810 "intf_tx_pending_fw_under_survey =%d\n"
811 "intf_tx_pending_fw_under_linking =%d\n"
812 "intf_tx_pending_xmitbuf =%d\n"
813 "intf_tx_enqueue =%d\n"
814 "core_tx_enqueue =%d\n"
815 "core_tx_enqueue_class =%d\n"
816 "core_tx_enqueue_class_err_sta =%d\n"
817 "core_tx_enqueue_class_err_nosta =%d\n"
818 "core_tx_enqueue_class_err_fwlink =%d\n"
819 "intf_tx_direct =%d\n"
820 "intf_tx_direct_err_coalesce =%d\n"
821 "intf_tx_dequeue =%d\n"
822 "intf_tx_dequeue_err_coalesce =%d\n"
823 "intf_tx_dump_xframe =%d\n"
824 "intf_tx_dump_xframe_err_txdesc =%d\n"
825 "intf_tx_dump_xframe_err_port =%d\n",
826 tx_logs->os_tx,
827 tx_logs->os_tx_err_up,
828 tx_logs->os_tx_err_xmit,
829 tx_logs->os_tx_m2u,
830 tx_logs->os_tx_m2u_ignore_fw_linked,
831 tx_logs->os_tx_m2u_ignore_self,
832 tx_logs->os_tx_m2u_entry,
833 tx_logs->os_tx_m2u_entry_err_xmit,
834 tx_logs->os_tx_m2u_entry_err_skb,
835 tx_logs->os_tx_m2u_stop,
836 tx_logs->core_tx,
837 tx_logs->core_tx_err_pxmitframe,
838 tx_logs->core_tx_err_brtx,
839 tx_logs->core_tx_upd_attrib,
840 tx_logs->core_tx_upd_attrib_adhoc,
841 tx_logs->core_tx_upd_attrib_sta,
842 tx_logs->core_tx_upd_attrib_ap,
843 tx_logs->core_tx_upd_attrib_unknown,
844 tx_logs->core_tx_upd_attrib_dhcp,
845 tx_logs->core_tx_upd_attrib_icmp,
846 tx_logs->core_tx_upd_attrib_active,
847 tx_logs->core_tx_upd_attrib_err_ucast_sta,
848 tx_logs->core_tx_upd_attrib_err_ucast_ap_link,
849 tx_logs->core_tx_upd_attrib_err_sta,
850 tx_logs->core_tx_upd_attrib_err_link,
851 tx_logs->core_tx_upd_attrib_err_sec,
852 tx_logs->core_tx_ap_enqueue_warn_fwstate,
853 tx_logs->core_tx_ap_enqueue_warn_sta,
854 tx_logs->core_tx_ap_enqueue_warn_nosta,
855 tx_logs->core_tx_ap_enqueue_warn_link,
856 tx_logs->core_tx_ap_enqueue_warn_trigger,
857 tx_logs->core_tx_ap_enqueue_mcast,
858 tx_logs->core_tx_ap_enqueue_ucast,
859 tx_logs->core_tx_ap_enqueue,
860 tx_logs->intf_tx,
861 tx_logs->intf_tx_pending_ac,
862 tx_logs->intf_tx_pending_fw_under_survey,
863 tx_logs->intf_tx_pending_fw_under_linking,
864 tx_logs->intf_tx_pending_xmitbuf,
865 tx_logs->intf_tx_enqueue,
866 tx_logs->core_tx_enqueue,
867 tx_logs->core_tx_enqueue_class,
868 tx_logs->core_tx_enqueue_class_err_sta,
869 tx_logs->core_tx_enqueue_class_err_nosta,
870 tx_logs->core_tx_enqueue_class_err_fwlink,
871 tx_logs->intf_tx_direct,
872 tx_logs->intf_tx_direct_err_coalesce,
873 tx_logs->intf_tx_dequeue,
874 tx_logs->intf_tx_dequeue_err_coalesce,
875 tx_logs->intf_tx_dump_xframe,
876 tx_logs->intf_tx_dump_xframe_err_txdesc,
877 tx_logs->intf_tx_dump_xframe_err_port
878 );
879
880 return 0;
881}
882
883int proc_get_int_logs(struct seq_file *m, void *v)
884{
885 struct net_device *dev = m->private;
886 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
887
888 DBG_871X_SEL_NL(m,
889 "all =%d\n"
890 "err =%d\n"
891 "tbdok =%d\n"
892 "tbder =%d\n"
893 "bcnderr =%d\n"
894 "bcndma =%d\n"
895 "bcndma_e =%d\n"
896 "rx =%d\n"
897 "rx_rdu =%d\n"
898 "rx_fovw =%d\n"
899 "txfovw =%d\n"
900 "mgntok =%d\n"
901 "highdok =%d\n"
902 "bkdok =%d\n"
903 "bedok =%d\n"
904 "vidok =%d\n"
905 "vodok =%d\n",
906 padapter->int_logs.all,
907 padapter->int_logs.err,
908 padapter->int_logs.tbdok,
909 padapter->int_logs.tbder,
910 padapter->int_logs.bcnderr,
911 padapter->int_logs.bcndma,
912 padapter->int_logs.bcndma_e,
913 padapter->int_logs.rx,
914 padapter->int_logs.rx_rdu,
915 padapter->int_logs.rx_fovw,
916 padapter->int_logs.txfovw,
917 padapter->int_logs.mgntok,
918 padapter->int_logs.highdok,
919 padapter->int_logs.bkdok,
920 padapter->int_logs.bedok,
921 padapter->int_logs.vidok,
922 padapter->int_logs.vodok
923 );
924
925 return 0;
926}
927
928#endif /* CONFIG_DBG_COUNTER*/
929
930int proc_get_rx_signal(struct seq_file *m, void *v)
931{
932 struct net_device *dev = m->private;
933 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
934
935 DBG_871X_SEL_NL(m, "rssi:%d\n", padapter->recvpriv.rssi);
936 /*DBG_871X_SEL_NL(m, "rxpwdb:%d\n", padapter->recvpriv.rxpwdb);*/
937 DBG_871X_SEL_NL(m, "signal_strength:%u\n", padapter->recvpriv.signal_strength);
938 DBG_871X_SEL_NL(m, "signal_qual:%u\n", padapter->recvpriv.signal_qual);
939 DBG_871X_SEL_NL(m, "noise:%d\n", padapter->recvpriv.noise);
940 rtw_odm_get_perpkt_rssi(m, padapter);
941 #ifdef DBG_RX_SIGNAL_DISPLAY_RAW_DATA
942 rtw_get_raw_rssi_info(m, padapter);
943 #endif
944 return 0;
945}
946
947
948int proc_get_hw_status(struct seq_file *m, void *v)
949{
950 struct net_device *dev = m->private;
951 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
952 struct dvobj_priv *dvobj = padapter->dvobj;
953 struct debug_priv *pdbgpriv = &dvobj->drv_dbg;
954
955 DBG_871X_SEL_NL(m, "RX FIFO full count: last_time =%lld, current_time =%lld, differential =%lld\n"
956 , pdbgpriv->dbg_rx_fifo_last_overflow, pdbgpriv->dbg_rx_fifo_curr_overflow, pdbgpriv->dbg_rx_fifo_diff_overflow);
957
958 return 0;
959}
960
961ssize_t proc_set_rx_signal(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
962{
963 struct net_device *dev = data;
964 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
965 char tmp[32];
966 u32 is_signal_dbg, signal_strength;
967
968 if (count < 1)
969 return -EFAULT;
970
971 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
972
973 int num = sscanf(tmp, "%u %u", &is_signal_dbg, &signal_strength);
974
975 is_signal_dbg = is_signal_dbg == 0?0:1;
976
977 if (is_signal_dbg && num != 2)
978 return count;
979
980 signal_strength = signal_strength > 100?100:signal_strength;
981
982 padapter->recvpriv.is_signal_dbg = is_signal_dbg;
983 padapter->recvpriv.signal_strength_dbg = signal_strength;
984
985 if (is_signal_dbg)
986 DBG_871X("set %s %u\n", "DBG_SIGNAL_STRENGTH", signal_strength);
987 else
988 DBG_871X("set %s\n", "HW_SIGNAL_STRENGTH");
989
990 }
991
992 return count;
993
994}
995
996int proc_get_ht_enable(struct seq_file *m, void *v)
997{
998 struct net_device *dev = m->private;
999 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1000 struct registry_priv *pregpriv = &padapter->registrypriv;
1001
1002 if (pregpriv)
1003 DBG_871X_SEL_NL(m, "%d\n", pregpriv->ht_enable);
1004
1005 return 0;
1006}
1007
1008ssize_t proc_set_ht_enable(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
1009{
1010 struct net_device *dev = data;
1011 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1012 struct registry_priv *pregpriv = &padapter->registrypriv;
1013 char tmp[32];
1014 u32 mode;
1015
1016 if (count < 1)
1017 return -EFAULT;
1018
1019 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
1020 sscanf(tmp, "%d ", &mode);
1021
1022 if (pregpriv && mode < 2) {
1023 pregpriv->ht_enable = mode;
1024 printk("ht_enable =%d\n", pregpriv->ht_enable);
1025 }
1026 }
1027
1028 return count;
1029
1030}
1031
1032int proc_get_bw_mode(struct seq_file *m, void *v)
1033{
1034 struct net_device *dev = m->private;
1035 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1036 struct registry_priv *pregpriv = &padapter->registrypriv;
1037
1038 if (pregpriv)
1039 DBG_871X_SEL_NL(m, "0x%02x\n", pregpriv->bw_mode);
1040
1041 return 0;
1042}
1043
1044ssize_t proc_set_bw_mode(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
1045{
1046 struct net_device *dev = data;
1047 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1048 struct registry_priv *pregpriv = &padapter->registrypriv;
1049 char tmp[32];
1050 u32 mode;
1051
1052 if (count < 1)
1053 return -EFAULT;
1054
1055 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
1056 sscanf(tmp, "%d ", &mode);
1057
1058 if (pregpriv && mode < 2) {
1059
1060 pregpriv->bw_mode = mode;
1061 printk("bw_mode =%d\n", mode);
1062
1063 }
1064 }
1065
1066 return count;
1067
1068}
1069
1070int proc_get_ampdu_enable(struct seq_file *m, void *v)
1071{
1072 struct net_device *dev = m->private;
1073 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1074 struct registry_priv *pregpriv = &padapter->registrypriv;
1075
1076 if (pregpriv)
1077 DBG_871X_SEL_NL(m, "%d\n", pregpriv->ampdu_enable);
1078
1079 return 0;
1080}
1081
1082ssize_t proc_set_ampdu_enable(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
1083{
1084 struct net_device *dev = data;
1085 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1086 struct registry_priv *pregpriv = &padapter->registrypriv;
1087 char tmp[32];
1088 u32 mode;
1089
1090 if (count < 1)
1091 return -EFAULT;
1092
1093 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
1094
1095 sscanf(tmp, "%d ", &mode);
1096
1097 if (pregpriv && mode < 3) {
1098 pregpriv->ampdu_enable = mode;
1099 printk("ampdu_enable =%d\n", mode);
1100 }
1101
1102 }
1103
1104 return count;
1105
1106}
1107
1108int proc_get_rx_ampdu(struct seq_file *m, void *v)
1109{
1110 struct net_device *dev = m->private;
1111 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1112 struct registry_priv *pregpriv = &padapter->registrypriv;
1113 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1114 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1115
1116 if (pregpriv)
1117 DBG_871X_SEL_NL(m,
1118 "accept_addba_req = %d , 0:Reject AP's Add BA req, 1:Accept AP's Add BA req.\n",
1119 pmlmeinfo->accept_addba_req
1120 );
1121
1122 return 0;
1123}
1124
1125ssize_t proc_set_rx_ampdu(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
1126{
1127 struct net_device *dev = data;
1128 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1129 struct registry_priv *pregpriv = &padapter->registrypriv;
1130 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1131 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1132 char tmp[32];
1133 u32 mode;
1134
1135 if (count < 1)
1136 return -EFAULT;
1137
1138 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
1139
1140 sscanf(tmp, "%d ", &mode);
1141
1142 if (pregpriv && mode < 2) {
1143 pmlmeinfo->accept_addba_req = mode;
1144 DBG_871X("pmlmeinfo->accept_addba_req =%d\n",
1145 pmlmeinfo->accept_addba_req);
1146 if (mode == 0) {
1147 /*tear down Rx AMPDU*/
1148 send_delba(padapter, 0, get_my_bssid(&(pmlmeinfo->network)));/* recipient*/
1149 }
1150 }
1151
1152 }
1153
1154 return count;
1155}
1156
1157int proc_get_en_fwps(struct seq_file *m, void *v)
1158{
1159 struct net_device *dev = m->private;
1160 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1161 struct registry_priv *pregpriv = &padapter->registrypriv;
1162
1163 if (pregpriv)
1164 DBG_871X_SEL_NL(m, "check_fw_ps = %d , 1:enable get FW PS state , 0: disable get FW PS state\n"
1165 , pregpriv->check_fw_ps);
1166
1167 return 0;
1168}
1169
1170ssize_t proc_set_en_fwps(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
1171{
1172 struct net_device *dev = data;
1173 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1174 struct registry_priv *pregpriv = &padapter->registrypriv;
1175 char tmp[32];
1176 u32 mode;
1177
1178 if (count < 1)
1179 return -EFAULT;
1180
1181 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
1182 sscanf(tmp, "%d ", &mode);
1183
1184 if (pregpriv && mode < 2) {
1185 pregpriv->check_fw_ps = mode;
1186 DBG_871X("pregpriv->check_fw_ps =%d\n", pregpriv->check_fw_ps);
1187 }
1188 }
1189 return count;
1190}
1191
1192int proc_get_rx_stbc(struct seq_file *m, void *v)
1193{
1194 struct net_device *dev = m->private;
1195 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1196 struct registry_priv *pregpriv = &padapter->registrypriv;
1197
1198 if (pregpriv)
1199 DBG_871X_SEL_NL(m, "%d\n", pregpriv->rx_stbc);
1200
1201 return 0;
1202}
1203
1204ssize_t proc_set_rx_stbc(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
1205{
1206 struct net_device *dev = data;
1207 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1208 struct registry_priv *pregpriv = &padapter->registrypriv;
1209 char tmp[32];
1210 u32 mode;
1211
1212 if (count < 1)
1213 return -EFAULT;
1214
1215 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
1216 sscanf(tmp, "%d ", &mode);
1217
1218 if (pregpriv && (mode == 0 || mode == 1 ||
1219 mode == 2 || mode == 3)) {
1220 pregpriv->rx_stbc = mode;
1221 printk("rx_stbc =%d\n", mode);
1222 }
1223 }
1224
1225 return count;
1226
1227}
1228
1229int proc_get_rssi_disp(struct seq_file *m, void *v)
1230{
1231 return 0;
1232}
1233
1234ssize_t proc_set_rssi_disp(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
1235{
1236 struct net_device *dev = data;
1237 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1238 char tmp[32];
1239 u32 enable = 0;
1240
1241 if (count < 1) {
1242 DBG_8192C("argument size is less than 1\n");
1243 return -EFAULT;
1244 }
1245
1246 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
1247 int num = sscanf(tmp, "%x", &enable);
1248
1249 if (num != 1) {
1250 DBG_8192C("invalid set_rssi_disp parameter!\n");
1251 return count;
1252 }
1253
1254 if (enable) {
1255 DBG_8192C("Linked info Function Enable\n");
1256 padapter->bLinkInfoDump = enable;
1257 } else {
1258 DBG_8192C("Linked info Function Disable\n");
1259 padapter->bLinkInfoDump = 0;
1260 }
1261 }
1262 return count;
1263}
1264
1265int proc_get_all_sta_info(struct seq_file *m, void *v)
1266{
1267 struct net_device *dev = m->private;
1268 struct sta_info *psta;
1269 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1270 struct sta_priv *pstapriv = &padapter->stapriv;
1271 int i, j;
1272 struct list_head *plist, *phead;
1273 struct recv_reorder_ctrl *preorder_ctrl;
1274
1275 DBG_871X_SEL_NL(m, "sta_dz_bitmap = 0x%x, tim_bitmap = 0x%x\n", pstapriv->sta_dz_bitmap, pstapriv->tim_bitmap);
1276
1277 spin_lock_bh(&pstapriv->sta_hash_lock);
1278
1279 for (i = 0; i < NUM_STA; i++) {
1280 phead = &(pstapriv->sta_hash[i]);
1281 plist = get_next(phead);
1282
1283 while (phead != plist) {
1284 psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
1285
1286 plist = get_next(plist);
1287
1288 DBG_871X_SEL_NL(m, "==============================\n");
1289 DBG_871X_SEL_NL(m, "sta's macaddr:" MAC_FMT "\n",
1290 MAC_ARG(psta->hwaddr));
1291 DBG_871X_SEL_NL(m, "rtsen =%d, cts2slef =%d\n",
1292 psta->rtsen, psta->cts2self);
1293 DBG_871X_SEL_NL(m, "state = 0x%x, aid =%d, macid =%d, raid =%d\n",
1294 psta->state, psta->aid, psta->mac_id,
1295 psta->raid);
1296 DBG_871X_SEL_NL(m, "qos_en =%d, ht_en =%d, init_rate =%d\n",
1297 psta->qos_option,
1298 psta->htpriv.ht_option,
1299 psta->init_rate);
1300 DBG_871X_SEL_NL(m, "bwmode =%d, ch_offset =%d, sgi_20m =%d, sgi_40m =%d\n",
1301 psta->bw_mode, psta->htpriv.ch_offset,
1302 psta->htpriv.sgi_20m,
1303 psta->htpriv.sgi_40m);
1304 DBG_871X_SEL_NL(m, "ampdu_enable = %d\n",
1305 psta->htpriv.ampdu_enable);
1306 DBG_871X_SEL_NL(m, "agg_enable_bitmap =%x, candidate_tid_bitmap =%x\n",
1307 psta->htpriv.agg_enable_bitmap,
1308 psta->htpriv.candidate_tid_bitmap);
1309 DBG_871X_SEL_NL(m, "sleepq_len =%d\n",
1310 psta->sleepq_len);
1311 DBG_871X_SEL_NL(m, "sta_xmitpriv.vo_q_qcnt =%d\n",
1312 psta->sta_xmitpriv.vo_q.qcnt);
1313 DBG_871X_SEL_NL(m, "sta_xmitpriv.vi_q_qcnt =%d\n",
1314 psta->sta_xmitpriv.vi_q.qcnt);
1315 DBG_871X_SEL_NL(m, "sta_xmitpriv.be_q_qcnt =%d\n",
1316 psta->sta_xmitpriv.be_q.qcnt);
1317 DBG_871X_SEL_NL(m, "sta_xmitpriv.bk_q_qcnt =%d\n",
1318 psta->sta_xmitpriv.bk_q.qcnt);
1319
1320 DBG_871X_SEL_NL(m, "capability = 0x%x\n",
1321 psta->capability);
1322 DBG_871X_SEL_NL(m, "flags = 0x%x\n", psta->flags);
1323 DBG_871X_SEL_NL(m, "wpa_psk = 0x%x\n", psta->wpa_psk);
1324 DBG_871X_SEL_NL(m, "wpa2_group_cipher = 0x%x\n",
1325 psta->wpa2_group_cipher);
1326 DBG_871X_SEL_NL(m, "wpa2_pairwise_cipher = 0x%x\n",
1327 psta->wpa2_pairwise_cipher);
1328 DBG_871X_SEL_NL(m, "qos_info = 0x%x\n", psta->qos_info);
1329 DBG_871X_SEL_NL(m, "dot118021XPrivacy = 0x%x\n",
1330 psta->dot118021XPrivacy);
1331
1332 for (j = 0; j < 16; j++) {
1333 preorder_ctrl = &psta->recvreorder_ctrl[j];
1334 if (preorder_ctrl->enable)
1335 DBG_871X_SEL_NL(m, "tid =%d, indicate_seq =%d\n",
1336 j, preorder_ctrl->indicate_seq);
1337 }
1338 DBG_871X_SEL_NL(m, "==============================\n");
1339 }
1340 }
1341
1342 spin_unlock_bh(&pstapriv->sta_hash_lock);
1343
1344 return 0;
1345}
1346
1347int proc_get_btcoex_dbg(struct seq_file *m, void *v)
1348{
1349 struct net_device *dev = m->private;
1350 struct adapter *padapter;
1351 char buf[512] = {0};
1352 padapter = (struct adapter *)rtw_netdev_priv(dev);
1353
1354 hal_btcoex_GetDBG(padapter, buf, 512);
1355
1356 DBG_871X_SEL(m, "%s", buf);
1357
1358 return 0;
1359}
1360
1361ssize_t proc_set_btcoex_dbg(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
1362{
1363 struct net_device *dev = data;
1364 struct adapter *padapter;
1365 u8 tmp[80] = {0};
1366 u32 module[2] = {0};
1367 u32 num;
1368
1369 padapter = (struct adapter *)rtw_netdev_priv(dev);
1370
1371/* DBG_871X("+" FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(padapter));*/
1372
1373 if (NULL == buffer) {
1374 DBG_871X(FUNC_ADPT_FMT ": input buffer is NULL!\n",
1375 FUNC_ADPT_ARG(padapter));
1376
1377 return -EFAULT;
1378 }
1379
1380 if (count < 1) {
1381 DBG_871X(FUNC_ADPT_FMT ": input length is 0!\n",
1382 FUNC_ADPT_ARG(padapter));
1383
1384 return -EFAULT;
1385 }
1386
1387 num = count;
1388 if (num > (sizeof(tmp) - 1))
1389 num = (sizeof(tmp) - 1);
1390
1391 if (copy_from_user(tmp, buffer, num)) {
1392 DBG_871X(FUNC_ADPT_FMT ": copy buffer from user space FAIL!\n",
1393 FUNC_ADPT_ARG(padapter));
1394
1395 return -EFAULT;
1396 }
1397
1398 num = sscanf(tmp, "%x %x", module, module+1);
1399 if (num == 1) {
1400 if (module[0] == 0)
1401 memset(module, 0, sizeof(module));
1402 else
1403 memset(module, 0xFF, sizeof(module));
1404 } else if (num != 2) {
1405 DBG_871X(FUNC_ADPT_FMT ": input(\"%s\") format incorrect!\n",
1406 FUNC_ADPT_ARG(padapter), tmp);
1407
1408 if (num == 0)
1409 return -EFAULT;
1410 }
1411
1412 DBG_871X(FUNC_ADPT_FMT ": input 0x%08X 0x%08X\n",
1413 FUNC_ADPT_ARG(padapter), module[0], module[1]);
1414 hal_btcoex_SetDBG(padapter, module);
1415
1416 return count;
1417}
1418
1419int proc_get_btcoex_info(struct seq_file *m, void *v)
1420{
1421 struct net_device *dev = m->private;
1422 struct adapter *padapter;
1423 const u32 bufsize = 30*100;
1424 u8 *pbuf = NULL;
1425
1426 padapter = (struct adapter *)rtw_netdev_priv(dev);
1427
1428 pbuf = rtw_zmalloc(bufsize);
1429 if (!pbuf)
1430 return -ENOMEM;
1431
1432 hal_btcoex_DisplayBtCoexInfo(padapter, pbuf, bufsize);
1433
1434 DBG_871X_SEL(m, "%s\n", pbuf);
1435
1436 kfree(pbuf);
1437
1438 return 0;
1439}
1440
1441#endif
diff --git a/drivers/staging/rtl8723bs/core/rtw_io.c b/drivers/staging/rtl8723bs/core/rtw_io.c
index a92bc19b196a..57168578663a 100644
--- a/drivers/staging/rtl8723bs/core/rtw_io.c
+++ b/drivers/staging/rtl8723bs/core/rtw_io.c
@@ -142,7 +142,7 @@ u32 _rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
142 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem); 142 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
143 struct io_priv *pio_priv = &adapter->iopriv; 143 struct io_priv *pio_priv = &adapter->iopriv;
144 struct intf_hdl *pintfhdl = &(pio_priv->intf); 144 struct intf_hdl *pintfhdl = &(pio_priv->intf);
145 u32 ret = _SUCCESS; 145 u32 ret;
146 146
147 _write_port = pintfhdl->io_ops._write_port; 147 _write_port = pintfhdl->io_ops._write_port;
148 148
diff --git a/drivers/staging/rtl8723bs/core/rtw_ioctl_set.c b/drivers/staging/rtl8723bs/core/rtw_ioctl_set.c
index 8eb0ff57925f..eb08569db5ea 100644
--- a/drivers/staging/rtl8723bs/core/rtw_ioctl_set.c
+++ b/drivers/staging/rtl8723bs/core/rtw_ioctl_set.c
@@ -9,13 +9,6 @@
9#include <drv_types.h> 9#include <drv_types.h>
10#include <rtw_debug.h> 10#include <rtw_debug.h>
11 11
12#define IS_MAC_ADDRESS_BROADCAST(addr) \
13(\
14 ((addr[0] == 0xff) && (addr[1] == 0xff) && \
15 (addr[2] == 0xff) && (addr[3] == 0xff) && \
16 (addr[4] == 0xff) && (addr[5] == 0xff)) ? true : false \
17)
18
19u8 rtw_validate_bssid(u8 *bssid) 12u8 rtw_validate_bssid(u8 *bssid)
20{ 13{
21 u8 ret = true; 14 u8 ret = true;
diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
index 4285844420cb..2128886c9924 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
@@ -295,11 +295,7 @@ static void init_mlme_ext_priv_value(struct adapter *padapter)
295 295
296 init_mlme_default_rate_set(padapter); 296 init_mlme_default_rate_set(padapter);
297 297
298 if (pmlmeext->cur_channel > 14) 298 pmlmeext->tx_rate = IEEE80211_CCK_RATE_1MB;
299 pmlmeext->tx_rate = IEEE80211_OFDM_RATE_6MB;
300 else
301 pmlmeext->tx_rate = IEEE80211_CCK_RATE_1MB;
302
303 pmlmeext->sitesurvey_res.state = SCAN_DISABLE; 299 pmlmeext->sitesurvey_res.state = SCAN_DISABLE;
304 pmlmeext->sitesurvey_res.channel_idx = 0; 300 pmlmeext->sitesurvey_res.channel_idx = 0;
305 pmlmeext->sitesurvey_res.bss_cnt = 0; 301 pmlmeext->sitesurvey_res.bss_cnt = 0;
@@ -459,9 +455,8 @@ static u8 init_channel_set(struct adapter *padapter, u8 ChannelPlan, RT_CHANNEL_
459 return chanset_size; 455 return chanset_size;
460} 456}
461 457
462int init_mlme_ext_priv(struct adapter *padapter) 458void init_mlme_ext_priv(struct adapter *padapter)
463{ 459{
464 int res = _SUCCESS;
465 struct registry_priv *pregistrypriv = &padapter->registrypriv; 460 struct registry_priv *pregistrypriv = &padapter->registrypriv;
466 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 461 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
467 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 462 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
@@ -488,9 +483,6 @@ int init_mlme_ext_priv(struct adapter *padapter)
488#ifdef DBG_FIXED_CHAN 483#ifdef DBG_FIXED_CHAN
489 pmlmeext->fixed_chan = 0xFF; 484 pmlmeext->fixed_chan = 0xFF;
490#endif 485#endif
491
492 return res;
493
494} 486}
495 487
496void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext) 488void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext)
@@ -1882,7 +1874,6 @@ unsigned int OnAtim(struct adapter *padapter, union recv_frame *precv_frame)
1882 1874
1883unsigned int on_action_spct(struct adapter *padapter, union recv_frame *precv_frame) 1875unsigned int on_action_spct(struct adapter *padapter, union recv_frame *precv_frame)
1884{ 1876{
1885 unsigned int ret = _FAIL;
1886 struct sta_info *psta = NULL; 1877 struct sta_info *psta = NULL;
1887 struct sta_priv *pstapriv = &padapter->stapriv; 1878 struct sta_priv *pstapriv = &padapter->stapriv;
1888 u8 *pframe = precv_frame->u.hdr.rx_data; 1879 u8 *pframe = precv_frame->u.hdr.rx_data;
@@ -1914,7 +1905,7 @@ unsigned int on_action_spct(struct adapter *padapter, union recv_frame *precv_fr
1914 } 1905 }
1915 1906
1916exit: 1907exit:
1917 return ret; 1908 return _FAIL;
1918} 1909}
1919 1910
1920unsigned int OnAction_back(struct adapter *padapter, union recv_frame *precv_frame) 1911unsigned int OnAction_back(struct adapter *padapter, union recv_frame *precv_frame)
diff --git a/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c b/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c
index ae7fb7046c93..4075de07e0a9 100644
--- a/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c
+++ b/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c
@@ -103,7 +103,7 @@ static bool rtw_pwr_unassociated_idle(struct adapter *adapter)
103 103
104 bool ret = false; 104 bool ret = false;
105 105
106 if (adapter_to_pwrctl(adapter)->bpower_saving == true) { 106 if (adapter_to_pwrctl(adapter)->bpower_saving) {
107 /* DBG_871X("%s: already in LPS or IPS mode\n", __func__); */ 107 /* DBG_871X("%s: already in LPS or IPS mode\n", __func__); */
108 goto exit; 108 goto exit;
109 } 109 }
@@ -167,7 +167,7 @@ void rtw_ps_processor(struct adapter *padapter)
167 goto exit; 167 goto exit;
168 } 168 }
169 169
170 if (pwrpriv->bInSuspend == true) {/* system suspend or autosuspend */ 170 if (pwrpriv->bInSuspend) {/* system suspend or autosuspend */
171 pdbgpriv->dbg_ps_insuspend_cnt++; 171 pdbgpriv->dbg_ps_insuspend_cnt++;
172 DBG_871X("%s, pwrpriv->bInSuspend == true ignore this process\n", __func__); 172 DBG_871X("%s, pwrpriv->bInSuspend == true ignore this process\n", __func__);
173 return; 173 return;
@@ -219,10 +219,9 @@ void traffic_check_for_leave_lps(struct adapter *padapter, u8 tx, u32 tx_packets
219 219
220 if (jiffies_to_msecs(jiffies - start_time) > 2000) { /* 2 sec == watch dog timer */ 220 if (jiffies_to_msecs(jiffies - start_time) > 2000) { /* 2 sec == watch dog timer */
221 if (xmit_cnt > 8) { 221 if (xmit_cnt > 8) {
222 if ((adapter_to_pwrctl(padapter)->bLeisurePs) 222 if (adapter_to_pwrctl(padapter)->bLeisurePs
223 && (adapter_to_pwrctl(padapter)->pwr_mode != PS_MODE_ACTIVE) 223 && (adapter_to_pwrctl(padapter)->pwr_mode != PS_MODE_ACTIVE)
224 && (hal_btcoex_IsBtControlLps(padapter) == false) 224 && !(hal_btcoex_IsBtControlLps(padapter))) {
225 ) {
226 DBG_871X("leave lps via Tx = %d\n", xmit_cnt); 225 DBG_871X("leave lps via Tx = %d\n", xmit_cnt);
227 bLeaveLPS = true; 226 bLeaveLPS = true;
228 } 227 }
@@ -234,10 +233,9 @@ void traffic_check_for_leave_lps(struct adapter *padapter, u8 tx, u32 tx_packets
234 233
235 } else { /* from rx path */ 234 } else { /* from rx path */
236 if (pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod > 4/*2*/) { 235 if (pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod > 4/*2*/) {
237 if ((adapter_to_pwrctl(padapter)->bLeisurePs) 236 if (adapter_to_pwrctl(padapter)->bLeisurePs
238 && (adapter_to_pwrctl(padapter)->pwr_mode != PS_MODE_ACTIVE) 237 && (adapter_to_pwrctl(padapter)->pwr_mode != PS_MODE_ACTIVE)
239 && (hal_btcoex_IsBtControlLps(padapter) == false) 238 && !(hal_btcoex_IsBtControlLps(padapter))) {
240 ) {
241 DBG_871X("leave lps via Rx = %d\n", pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod); 239 DBG_871X("leave lps via Rx = %d\n", pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod);
242 bLeaveLPS = true; 240 bLeaveLPS = true;
243 } 241 }
@@ -267,7 +265,7 @@ void rtw_set_rpwm(struct adapter *padapter, u8 pslv)
267 265
268 pslv = PS_STATE(pslv); 266 pslv = PS_STATE(pslv);
269 267
270 if (pwrpriv->brpwmtimeout == true) { 268 if (pwrpriv->brpwmtimeout) {
271 DBG_871X("%s: RPWM timeout, force to set RPWM(0x%02X) again!\n", __func__, pslv); 269 DBG_871X("%s: RPWM timeout, force to set RPWM(0x%02X) again!\n", __func__, pslv);
272 } else { 270 } else {
273 if ((pwrpriv->rpwm == pslv) 271 if ((pwrpriv->rpwm == pslv)
@@ -278,8 +276,7 @@ void rtw_set_rpwm(struct adapter *padapter, u8 pslv)
278 } 276 }
279 } 277 }
280 278
281 if ((padapter->bSurpriseRemoved == true) || 279 if ((padapter->bSurpriseRemoved) || !(padapter->hw_init_completed)) {
282 (padapter->hw_init_completed == false)) {
283 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_, 280 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
284 ("%s: SurpriseRemoved(%d) hw_init_completed(%d)\n", 281 ("%s: SurpriseRemoved(%d) hw_init_completed(%d)\n",
285 __func__, padapter->bSurpriseRemoved, padapter->hw_init_completed)); 282 __func__, padapter->bSurpriseRemoved, padapter->hw_init_completed));
@@ -289,7 +286,7 @@ void rtw_set_rpwm(struct adapter *padapter, u8 pslv)
289 return; 286 return;
290 } 287 }
291 288
292 if (padapter->bDriverStopped == true) { 289 if (padapter->bDriverStopped) {
293 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_, 290 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
294 ("%s: change power state(0x%02X) when DriverStopped\n", __func__, pslv)); 291 ("%s: change power state(0x%02X) when DriverStopped\n", __func__, pslv));
295 292
@@ -355,14 +352,14 @@ static u8 PS_RDY_CHECK(struct adapter *padapter)
355 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 352 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
356 353
357#if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN) 354#if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN)
358 if (true == pwrpriv->bInSuspend && pwrpriv->wowlan_mode) 355 if (pwrpriv->bInSuspend && pwrpriv->wowlan_mode)
359 return true; 356 return true;
360 else if (true == pwrpriv->bInSuspend && pwrpriv->wowlan_ap_mode) 357 else if (pwrpriv->bInSuspend && pwrpriv->wowlan_ap_mode)
361 return true; 358 return true;
362 else if (true == pwrpriv->bInSuspend) 359 else if (pwrpriv->bInSuspend)
363 return false; 360 return false;
364#else 361#else
365 if (true == pwrpriv->bInSuspend) 362 if (pwrpriv->bInSuspend)
366 return false; 363 return false;
367#endif 364#endif
368 365
@@ -381,7 +378,7 @@ static u8 PS_RDY_CHECK(struct adapter *padapter)
381 ) 378 )
382 return false; 379 return false;
383 380
384 if ((padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) && (padapter->securitypriv.binstallGrpkey == false)) { 381 if ((padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) && !(padapter->securitypriv.binstallGrpkey)) {
385 DBG_871X("Group handshake still in progress !!!\n"); 382 DBG_871X("Group handshake still in progress !!!\n");
386 return false; 383 return false;
387 } 384 }
@@ -417,13 +414,9 @@ void rtw_set_ps_mode(struct adapter *padapter, u8 ps_mode, u8 smart_ps, u8 bcn_a
417 414
418 /* if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) */ 415 /* if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) */
419 if (ps_mode == PS_MODE_ACTIVE) { 416 if (ps_mode == PS_MODE_ACTIVE) {
420 if (1 417 if (!(hal_btcoex_IsBtControlLps(padapter))
421 && (((hal_btcoex_IsBtControlLps(padapter) == false) 418 || (hal_btcoex_IsBtControlLps(padapter)
422 ) 419 && !(hal_btcoex_IsLpsOn(padapter)))) {
423 || ((hal_btcoex_IsBtControlLps(padapter) == true)
424 && (hal_btcoex_IsLpsOn(padapter) == false))
425 )
426 ) {
427 DBG_871X(FUNC_ADPT_FMT" Leave 802.11 power save - %s\n", 420 DBG_871X(FUNC_ADPT_FMT" Leave 802.11 power save - %s\n",
428 FUNC_ADPT_ARG(padapter), msg); 421 FUNC_ADPT_ARG(padapter), msg);
429 422
@@ -431,8 +424,7 @@ void rtw_set_ps_mode(struct adapter *padapter, u8 ps_mode, u8 smart_ps, u8 bcn_a
431 rtw_set_rpwm(padapter, PS_STATE_S4); 424 rtw_set_rpwm(padapter, PS_STATE_S4);
432 425
433#if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN) 426#if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN)
434 if (pwrpriv->wowlan_mode == true || 427 if (pwrpriv->wowlan_mode || pwrpriv->wowlan_ap_mode) {
435 pwrpriv->wowlan_ap_mode == true) {
436 unsigned long start_time; 428 unsigned long start_time;
437 u32 delay_ms; 429 u32 delay_ms;
438 u8 val8; 430 u8 val8;
@@ -461,8 +453,8 @@ void rtw_set_ps_mode(struct adapter *padapter, u8 ps_mode, u8 smart_ps, u8 bcn_a
461 } 453 }
462 } else { 454 } else {
463 if ((PS_RDY_CHECK(padapter) && check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE)) 455 if ((PS_RDY_CHECK(padapter) && check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE))
464 || ((hal_btcoex_IsBtControlLps(padapter) == true) 456 || ((hal_btcoex_IsBtControlLps(padapter))
465 && (hal_btcoex_IsLpsOn(padapter) == true)) 457 && (hal_btcoex_IsLpsOn(padapter)))
466 ) { 458 ) {
467 u8 pslv; 459 u8 pslv;
468 460
@@ -481,8 +473,8 @@ void rtw_set_ps_mode(struct adapter *padapter, u8 ps_mode, u8 smart_ps, u8 bcn_a
481 if (pwrpriv->alives == 0) 473 if (pwrpriv->alives == 0)
482 pslv = PS_STATE_S0; 474 pslv = PS_STATE_S0;
483 475
484 if ((hal_btcoex_IsBtDisabled(padapter) == false) 476 if (!(hal_btcoex_IsBtDisabled(padapter))
485 && (hal_btcoex_IsBtControlLps(padapter) == true)) { 477 && (hal_btcoex_IsBtControlLps(padapter))) {
486 u8 val8; 478 u8 val8;
487 479
488 val8 = hal_btcoex_LpsVal(padapter); 480 val8 = hal_btcoex_LpsVal(padapter);
@@ -513,10 +505,10 @@ s32 LPS_RF_ON_check(struct adapter *padapter, u32 delay_ms)
513 start_time = jiffies; 505 start_time = jiffies;
514 while (1) { 506 while (1) {
515 rtw_hal_get_hwreg(padapter, HW_VAR_FWLPS_RF_ON, &bAwake); 507 rtw_hal_get_hwreg(padapter, HW_VAR_FWLPS_RF_ON, &bAwake);
516 if (true == bAwake) 508 if (bAwake)
517 break; 509 break;
518 510
519 if (true == padapter->bSurpriseRemoved) { 511 if (padapter->bSurpriseRemoved) {
520 err = -2; 512 err = -2;
521 DBG_871X("%s: device surprise removed!!\n", __func__); 513 DBG_871X("%s: device surprise removed!!\n", __func__);
522 break; 514 break;
@@ -544,7 +536,7 @@ void LPS_Enter(struct adapter *padapter, const char *msg)
544 int n_assoc_iface = 0; 536 int n_assoc_iface = 0;
545 char buf[32] = {0}; 537 char buf[32] = {0};
546 538
547 if (hal_btcoex_IsBtControlLps(padapter) == true) 539 if (hal_btcoex_IsBtControlLps(padapter))
548 return; 540 return;
549 541
550 /* Skip lps enter request if number of assocated adapters is not 1 */ 542 /* Skip lps enter request if number of assocated adapters is not 1 */
@@ -557,8 +549,8 @@ void LPS_Enter(struct adapter *padapter, const char *msg)
557 if (get_iface_type(padapter) != IFACE_PORT0) 549 if (get_iface_type(padapter) != IFACE_PORT0)
558 return; 550 return;
559 551
560 if (PS_RDY_CHECK(dvobj->padapters) == false) 552 if (!PS_RDY_CHECK(dvobj->padapters))
561 return; 553 return;
562 554
563 if (pwrpriv->bLeisurePs) { 555 if (pwrpriv->bLeisurePs) {
564 /* Idle for a while if we connect to AP a while ago. */ 556 /* Idle for a while if we connect to AP a while ago. */
@@ -589,7 +581,7 @@ void LPS_Leave(struct adapter *padapter, const char *msg)
589 581
590/* DBG_871X("+LeisurePSLeave\n"); */ 582/* DBG_871X("+LeisurePSLeave\n"); */
591 583
592 if (hal_btcoex_IsBtControlLps(padapter) == true) 584 if (hal_btcoex_IsBtControlLps(padapter))
593 return; 585 return;
594 586
595 if (pwrpriv->bLeisurePs) { 587 if (pwrpriv->bLeisurePs) {
@@ -615,13 +607,13 @@ void LeaveAllPowerSaveModeDirect(struct adapter *Adapter)
615 607
616 DBG_871X("%s.....\n", __func__); 608 DBG_871X("%s.....\n", __func__);
617 609
618 if (true == Adapter->bSurpriseRemoved) { 610 if (Adapter->bSurpriseRemoved) {
619 DBG_871X(FUNC_ADPT_FMT ": bSurpriseRemoved =%d Skip!\n", 611 DBG_871X(FUNC_ADPT_FMT ": bSurpriseRemoved =%d Skip!\n",
620 FUNC_ADPT_ARG(Adapter), Adapter->bSurpriseRemoved); 612 FUNC_ADPT_ARG(Adapter), Adapter->bSurpriseRemoved);
621 return; 613 return;
622 } 614 }
623 615
624 if ((check_fwstate(pmlmepriv, _FW_LINKED) == true)) { /* connect */ 616 if (check_fwstate(pmlmepriv, _FW_LINKED)) { /* connect */
625 617
626 if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) { 618 if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) {
627 DBG_871X("%s: Driver Already Leave LPS\n", __func__); 619 DBG_871X("%s: Driver Already Leave LPS\n", __func__);
@@ -637,7 +629,7 @@ void LeaveAllPowerSaveModeDirect(struct adapter *Adapter)
637 rtw_lps_ctrl_wk_cmd(pri_padapter, LPS_CTRL_LEAVE, 0); 629 rtw_lps_ctrl_wk_cmd(pri_padapter, LPS_CTRL_LEAVE, 0);
638 } else { 630 } else {
639 if (pwrpriv->rf_pwrstate == rf_off) 631 if (pwrpriv->rf_pwrstate == rf_off)
640 if (false == ips_leave(pri_padapter)) 632 if (!ips_leave(pri_padapter))
641 DBG_871X("======> ips_leave fail.............\n"); 633 DBG_871X("======> ips_leave fail.............\n");
642 } 634 }
643} 635}
@@ -675,7 +667,7 @@ void LeaveAllPowerSaveMode(struct adapter *Adapter)
675 LPS_Leave_check(Adapter); 667 LPS_Leave_check(Adapter);
676 } else { 668 } else {
677 if (adapter_to_pwrctl(Adapter)->rf_pwrstate == rf_off) { 669 if (adapter_to_pwrctl(Adapter)->rf_pwrstate == rf_off) {
678 if (false == ips_leave(Adapter)) 670 if (!ips_leave(Adapter))
679 DBG_871X("======> ips_leave fail.............\n"); 671 DBG_871X("======> ips_leave fail.............\n");
680 } 672 }
681 } 673 }
@@ -698,15 +690,14 @@ void LPS_Leave_check(
698 while (1) { 690 while (1) {
699 mutex_lock(&pwrpriv->lock); 691 mutex_lock(&pwrpriv->lock);
700 692
701 if ((padapter->bSurpriseRemoved == true) 693 if (padapter->bSurpriseRemoved
702 || (padapter->hw_init_completed == false) 694 || !(padapter->hw_init_completed)
703 || (pwrpriv->pwr_mode == PS_MODE_ACTIVE) 695 || (pwrpriv->pwr_mode == PS_MODE_ACTIVE))
704 )
705 bReady = true; 696 bReady = true;
706 697
707 mutex_unlock(&pwrpriv->lock); 698 mutex_unlock(&pwrpriv->lock);
708 699
709 if (true == bReady) 700 if (bReady)
710 break; 701 break;
711 702
712 if (jiffies_to_msecs(jiffies - start_time) > 100) { 703 if (jiffies_to_msecs(jiffies - start_time) > 100) {
@@ -830,12 +821,12 @@ static void pwr_rpwm_timeout_handler(struct timer_list *t)
830 _set_workitem(&pwrpriv->rpwmtimeoutwi); 821 _set_workitem(&pwrpriv->rpwmtimeoutwi);
831} 822}
832 823
833static __inline void register_task_alive(struct pwrctrl_priv *pwrctrl, u32 tag) 824static inline void register_task_alive(struct pwrctrl_priv *pwrctrl, u32 tag)
834{ 825{
835 pwrctrl->alives |= tag; 826 pwrctrl->alives |= tag;
836} 827}
837 828
838static __inline void unregister_task_alive(struct pwrctrl_priv *pwrctrl, u32 tag) 829static inline void unregister_task_alive(struct pwrctrl_priv *pwrctrl, u32 tag)
839{ 830{
840 pwrctrl->alives &= ~tag; 831 pwrctrl->alives &= ~tag;
841} 832}
@@ -870,7 +861,7 @@ s32 rtw_register_task_alive(struct adapter *padapter, u32 task)
870 861
871 register_task_alive(pwrctrl, task); 862 register_task_alive(pwrctrl, task);
872 863
873 if (pwrctrl->bFwCurrentInPSMode == true) { 864 if (pwrctrl->bFwCurrentInPSMode) {
874 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_, 865 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
875 ("%s: task = 0x%x cpwm = 0x%02x alives = 0x%08x\n", 866 ("%s: task = 0x%x cpwm = 0x%02x alives = 0x%08x\n",
876 __func__, task, pwrctrl->cpwm, pwrctrl->alives)); 867 __func__, task, pwrctrl->cpwm, pwrctrl->alives));
@@ -910,8 +901,8 @@ void rtw_unregister_task_alive(struct adapter *padapter, u32 task)
910 pwrctrl = adapter_to_pwrctl(padapter); 901 pwrctrl = adapter_to_pwrctl(padapter);
911 pslv = PS_STATE_S0; 902 pslv = PS_STATE_S0;
912 903
913 if ((hal_btcoex_IsBtDisabled(padapter) == false) 904 if (!(hal_btcoex_IsBtDisabled(padapter))
914 && (hal_btcoex_IsBtControlLps(padapter) == true)) { 905 && hal_btcoex_IsBtControlLps(padapter)) {
915 u8 val8; 906 u8 val8;
916 907
917 val8 = hal_btcoex_LpsVal(padapter); 908 val8 = hal_btcoex_LpsVal(padapter);
@@ -924,7 +915,7 @@ void rtw_unregister_task_alive(struct adapter *padapter, u32 task)
924 unregister_task_alive(pwrctrl, task); 915 unregister_task_alive(pwrctrl, task);
925 916
926 if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE) 917 if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE)
927 && (pwrctrl->bFwCurrentInPSMode == true)) { 918 && pwrctrl->bFwCurrentInPSMode) {
928 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_, 919 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
929 ("%s: cpwm = 0x%02x alives = 0x%08x\n", 920 ("%s: cpwm = 0x%02x alives = 0x%08x\n",
930 __func__, pwrctrl->cpwm, pwrctrl->alives)); 921 __func__, pwrctrl->cpwm, pwrctrl->alives));
@@ -965,7 +956,7 @@ s32 rtw_register_tx_alive(struct adapter *padapter)
965 956
966 register_task_alive(pwrctrl, XMIT_ALIVE); 957 register_task_alive(pwrctrl, XMIT_ALIVE);
967 958
968 if (pwrctrl->bFwCurrentInPSMode == true) { 959 if (pwrctrl->bFwCurrentInPSMode) {
969 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_, 960 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
970 ("rtw_register_tx_alive: cpwm = 0x%02x alives = 0x%08x\n", 961 ("rtw_register_tx_alive: cpwm = 0x%02x alives = 0x%08x\n",
971 pwrctrl->cpwm, pwrctrl->alives)); 962 pwrctrl->cpwm, pwrctrl->alives));
@@ -1014,7 +1005,7 @@ s32 rtw_register_cmd_alive(struct adapter *padapter)
1014 1005
1015 register_task_alive(pwrctrl, CMD_ALIVE); 1006 register_task_alive(pwrctrl, CMD_ALIVE);
1016 1007
1017 if (pwrctrl->bFwCurrentInPSMode == true) { 1008 if (pwrctrl->bFwCurrentInPSMode) {
1018 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_info_, 1009 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_info_,
1019 ("rtw_register_cmd_alive: cpwm = 0x%02x alives = 0x%08x\n", 1010 ("rtw_register_cmd_alive: cpwm = 0x%02x alives = 0x%08x\n",
1020 pwrctrl->cpwm, pwrctrl->alives)); 1011 pwrctrl->cpwm, pwrctrl->alives));
@@ -1051,8 +1042,8 @@ void rtw_unregister_tx_alive(struct adapter *padapter)
1051 pwrctrl = adapter_to_pwrctl(padapter); 1042 pwrctrl = adapter_to_pwrctl(padapter);
1052 pslv = PS_STATE_S0; 1043 pslv = PS_STATE_S0;
1053 1044
1054 if ((hal_btcoex_IsBtDisabled(padapter) == false) 1045 if (!(hal_btcoex_IsBtDisabled(padapter))
1055 && (hal_btcoex_IsBtControlLps(padapter) == true)) { 1046 && hal_btcoex_IsBtControlLps(padapter)) {
1056 u8 val8; 1047 u8 val8;
1057 1048
1058 val8 = hal_btcoex_LpsVal(padapter); 1049 val8 = hal_btcoex_LpsVal(padapter);
@@ -1065,7 +1056,7 @@ void rtw_unregister_tx_alive(struct adapter *padapter)
1065 unregister_task_alive(pwrctrl, XMIT_ALIVE); 1056 unregister_task_alive(pwrctrl, XMIT_ALIVE);
1066 1057
1067 if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE) 1058 if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE)
1068 && (pwrctrl->bFwCurrentInPSMode == true)) { 1059 && pwrctrl->bFwCurrentInPSMode) {
1069 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_, 1060 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
1070 ("%s: cpwm = 0x%02x alives = 0x%08x\n", 1061 ("%s: cpwm = 0x%02x alives = 0x%08x\n",
1071 __func__, pwrctrl->cpwm, pwrctrl->alives)); 1062 __func__, pwrctrl->cpwm, pwrctrl->alives));
@@ -1093,8 +1084,8 @@ void rtw_unregister_cmd_alive(struct adapter *padapter)
1093 pwrctrl = adapter_to_pwrctl(padapter); 1084 pwrctrl = adapter_to_pwrctl(padapter);
1094 pslv = PS_STATE_S0; 1085 pslv = PS_STATE_S0;
1095 1086
1096 if ((hal_btcoex_IsBtDisabled(padapter) == false) 1087 if (!(hal_btcoex_IsBtDisabled(padapter))
1097 && (hal_btcoex_IsBtControlLps(padapter) == true)) { 1088 && hal_btcoex_IsBtControlLps(padapter)) {
1098 u8 val8; 1089 u8 val8;
1099 1090
1100 val8 = hal_btcoex_LpsVal(padapter); 1091 val8 = hal_btcoex_LpsVal(padapter);
@@ -1107,7 +1098,7 @@ void rtw_unregister_cmd_alive(struct adapter *padapter)
1107 unregister_task_alive(pwrctrl, CMD_ALIVE); 1098 unregister_task_alive(pwrctrl, CMD_ALIVE);
1108 1099
1109 if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE) 1100 if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE)
1110 && (pwrctrl->bFwCurrentInPSMode == true)) { 1101 && pwrctrl->bFwCurrentInPSMode) {
1111 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_info_, 1102 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_info_,
1112 ("%s: cpwm = 0x%02x alives = 0x%08x\n", 1103 ("%s: cpwm = 0x%02x alives = 0x%08x\n",
1113 __func__, pwrctrl->cpwm, pwrctrl->alives)); 1104 __func__, pwrctrl->cpwm, pwrctrl->alives));
@@ -1237,7 +1228,7 @@ int _rtw_pwr_wakeup(struct adapter *padapter, u32 ips_deffer_ms, const char *cal
1237 DBG_871X("%s wait ps_processing done\n", __func__); 1228 DBG_871X("%s wait ps_processing done\n", __func__);
1238 } 1229 }
1239 1230
1240 if (pwrpriv->bInternalAutoSuspend == false && pwrpriv->bInSuspend) { 1231 if (!(pwrpriv->bInternalAutoSuspend) && pwrpriv->bInSuspend) {
1241 DBG_871X("%s wait bInSuspend...\n", __func__); 1232 DBG_871X("%s wait bInSuspend...\n", __func__);
1242 while (pwrpriv->bInSuspend 1233 while (pwrpriv->bInSuspend
1243 && jiffies_to_msecs(jiffies - start) <= 3000 1234 && jiffies_to_msecs(jiffies - start) <= 3000
@@ -1251,19 +1242,19 @@ int _rtw_pwr_wakeup(struct adapter *padapter, u32 ips_deffer_ms, const char *cal
1251 } 1242 }
1252 1243
1253 /* System suspend is not allowed to wakeup */ 1244 /* System suspend is not allowed to wakeup */
1254 if ((pwrpriv->bInternalAutoSuspend == false) && (true == pwrpriv->bInSuspend)) { 1245 if (!(pwrpriv->bInternalAutoSuspend) && pwrpriv->bInSuspend) {
1255 ret = _FAIL; 1246 ret = _FAIL;
1256 goto exit; 1247 goto exit;
1257 } 1248 }
1258 1249
1259 /* block??? */ 1250 /* block??? */
1260 if ((pwrpriv->bInternalAutoSuspend == true) && (padapter->net_closed == true)) { 1251 if (pwrpriv->bInternalAutoSuspend && padapter->net_closed) {
1261 ret = _FAIL; 1252 ret = _FAIL;
1262 goto exit; 1253 goto exit;
1263 } 1254 }
1264 1255
1265 /* I think this should be check in IPS, LPS, autosuspend functions... */ 1256 /* I think this should be check in IPS, LPS, autosuspend functions... */
1266 if (check_fwstate(pmlmepriv, _FW_LINKED) == true) { 1257 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
1267 ret = _SUCCESS; 1258 ret = _SUCCESS;
1268 goto exit; 1259 goto exit;
1269 } 1260 }
diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c b/drivers/staging/rtl8723bs/core/rtw_security.c
index 979056c3d397..57cfe06d7d73 100644
--- a/drivers/staging/rtl8723bs/core/rtw_security.c
+++ b/drivers/staging/rtl8723bs/core/rtw_security.c
@@ -2290,8 +2290,7 @@ static void gf_mulx(u8 *pad)
2290 2290
2291static void aes_encrypt_deinit(void *ctx) 2291static void aes_encrypt_deinit(void *ctx)
2292{ 2292{
2293 memset(ctx, 0, AES_PRIV_SIZE); 2293 kzfree(ctx);
2294 kfree(ctx);
2295} 2294}
2296 2295
2297 2296
diff --git a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c b/drivers/staging/rtl8723bs/core/rtw_wlan_util.c
index 76c50377f0fe..ea3ea2a6b314 100644
--- a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c
+++ b/drivers/staging/rtl8723bs/core/rtw_wlan_util.c
@@ -451,7 +451,7 @@ void set_channel_bwmode(struct adapter *padapter, unsigned char channel, unsigne
451 mutex_unlock(&(adapter_to_dvobj(padapter)->setch_mutex)); 451 mutex_unlock(&(adapter_to_dvobj(padapter)->setch_mutex));
452} 452}
453 453
454__inline u8 *get_my_bssid(struct wlan_bssid_ex *pnetwork) 454inline u8 *get_my_bssid(struct wlan_bssid_ex *pnetwork)
455{ 455{
456 return pnetwork->MacAddress; 456 return pnetwork->MacAddress;
457} 457}
@@ -1996,11 +1996,6 @@ void adaptive_early_32k(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len)
1996 } 1996 }
1997} 1997}
1998 1998
1999void beacon_timing_control(struct adapter *padapter)
2000{
2001 rtw_hal_bcn_related_reg_setting(padapter);
2002}
2003
2004void rtw_alloc_macid(struct adapter *padapter, struct sta_info *psta) 1999void rtw_alloc_macid(struct adapter *padapter, struct sta_info *psta)
2005{ 2000{
2006 int i; 2001 int i;
diff --git a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c b/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
index 8e4caeeb4070..dd349c506da8 100644
--- a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
+++ b/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
@@ -1758,7 +1758,6 @@ static void halbtc8723b1ant_TdmaDurationAdjustForAcl(
1758 static s32 up, dn, m, n, WaitCount; 1758 static s32 up, dn, m, n, WaitCount;
1759 s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */ 1759 s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
1760 u8 retryCount = 0, btInfoExt; 1760 u8 retryCount = 0, btInfoExt;
1761 bool bWifiBusy = false;
1762 1761
1763 BTC_PRINT( 1762 BTC_PRINT(
1764 BTC_MSG_ALGORITHM, 1763 BTC_MSG_ALGORITHM,
@@ -1766,11 +1765,6 @@ static void halbtc8723b1ant_TdmaDurationAdjustForAcl(
1766 ("[BTCoex], TdmaDurationAdjustForAcl()\n") 1765 ("[BTCoex], TdmaDurationAdjustForAcl()\n")
1767 ); 1766 );
1768 1767
1769 if (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifiStatus)
1770 bWifiBusy = true;
1771 else
1772 bWifiBusy = false;
1773
1774 if ( 1768 if (
1775 (BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) || 1769 (BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) ||
1776 (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) || 1770 (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) ||
diff --git a/drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h b/drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h
index aad86570b59c..7150d54d49ab 100644
--- a/drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h
+++ b/drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h
@@ -532,7 +532,6 @@ typedef struct _BTC_COEXIST {
532 532
533extern BTC_COEXIST GLBtCoexist; 533extern BTC_COEXIST GLBtCoexist;
534 534
535u8 EXhalbtcoutsrc_InitlizeVariables(void *Adapter);
536void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist); 535void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist);
537void EXhalbtcoutsrc_InitHwConfig(PBTC_COEXIST pBtCoexist, u8 bWifiOnly); 536void EXhalbtcoutsrc_InitHwConfig(PBTC_COEXIST pBtCoexist, u8 bWifiOnly);
538void EXhalbtcoutsrc_InitCoexDm(PBTC_COEXIST pBtCoexist); 537void EXhalbtcoutsrc_InitCoexDm(PBTC_COEXIST pBtCoexist);
diff --git a/drivers/staging/rtl8723bs/hal/hal_btcoex.c b/drivers/staging/rtl8723bs/hal/hal_btcoex.c
index 5257287b4f4d..6e4a1fcb8790 100644
--- a/drivers/staging/rtl8723bs/hal/hal_btcoex.c
+++ b/drivers/staging/rtl8723bs/hal/hal_btcoex.c
@@ -389,7 +389,6 @@ static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
389 u8 *pu8; 389 u8 *pu8;
390 s32 *pS4Tmp; 390 s32 *pS4Tmp;
391 u32 *pU4Tmp; 391 u32 *pU4Tmp;
392 u8 *pU1Tmp;
393 u8 ret; 392 u8 ret;
394 393
395 394
@@ -403,7 +402,6 @@ static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
403 pu8 = pOutBuf; 402 pu8 = pOutBuf;
404 pS4Tmp = pOutBuf; 403 pS4Tmp = pOutBuf;
405 pU4Tmp = pOutBuf; 404 pU4Tmp = pOutBuf;
406 pU1Tmp = pOutBuf;
407 ret = true; 405 ret = true;
408 406
409 switch (getType) { 407 switch (getType) {
@@ -484,10 +482,8 @@ static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
484 *pU4Tmp = BTC_WIFI_BW_LEGACY; 482 *pU4Tmp = BTC_WIFI_BW_LEGACY;
485 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20) 483 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
486 *pU4Tmp = BTC_WIFI_BW_HT20; 484 *pU4Tmp = BTC_WIFI_BW_HT20;
487 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_40)
488 *pU4Tmp = BTC_WIFI_BW_HT40;
489 else 485 else
490 *pU4Tmp = BTC_WIFI_BW_HT40; /* todo */ 486 *pU4Tmp = BTC_WIFI_BW_HT40;
491 break; 487 break;
492 488
493 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION: 489 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
@@ -516,32 +512,32 @@ static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
516 break; 512 break;
517 513
518 case BTC_GET_U1_WIFI_DOT11_CHNL: 514 case BTC_GET_U1_WIFI_DOT11_CHNL:
519 *pU1Tmp = padapter->mlmeextpriv.cur_channel; 515 *pu8 = padapter->mlmeextpriv.cur_channel;
520 break; 516 break;
521 517
522 case BTC_GET_U1_WIFI_CENTRAL_CHNL: 518 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
523 *pU1Tmp = pHalData->CurrentChannel; 519 *pu8 = pHalData->CurrentChannel;
524 break; 520 break;
525 521
526 case BTC_GET_U1_WIFI_HS_CHNL: 522 case BTC_GET_U1_WIFI_HS_CHNL:
527 *pU1Tmp = 0; 523 *pu8 = 0;
528 ret = false; 524 ret = false;
529 break; 525 break;
530 526
531 case BTC_GET_U1_MAC_PHY_MODE: 527 case BTC_GET_U1_MAC_PHY_MODE:
532 *pU1Tmp = BTC_SMSP; 528 *pu8 = BTC_SMSP;
533/* *pU1Tmp = BTC_DMSP; */ 529/* *pU1Tmp = BTC_DMSP; */
534/* *pU1Tmp = BTC_DMDP; */ 530/* *pU1Tmp = BTC_DMDP; */
535/* *pU1Tmp = BTC_MP_UNKNOWN; */ 531/* *pU1Tmp = BTC_MP_UNKNOWN; */
536 break; 532 break;
537 533
538 case BTC_GET_U1_AP_NUM: 534 case BTC_GET_U1_AP_NUM:
539 *pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter); 535 *pu8 = halbtcoutsrc_GetWifiScanAPNum(padapter);
540 break; 536 break;
541 537
542 /* 1Ant =========== */ 538 /* 1Ant =========== */
543 case BTC_GET_U1_LPS_MODE: 539 case BTC_GET_U1_LPS_MODE:
544 *pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode; 540 *pu8 = padapter->dvobj->pwrctl_priv.pwr_mode;
545 break; 541 break;
546 542
547 default: 543 default:
@@ -959,9 +955,13 @@ static u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
959 return true; 955 return true;
960} 956}
961 957
962u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter) 958void hal_btcoex_Initialize(void *padapter)
963{ 959{
964 PBTC_COEXIST pBtCoexist = &GLBtCoexist; 960 PBTC_COEXIST pBtCoexist;
961
962 memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
963
964 pBtCoexist = &GLBtCoexist;
965 965
966 /* pBtCoexist->statistics.cntBind++; */ 966 /* pBtCoexist->statistics.cntBind++; */
967 967
@@ -1001,8 +1001,6 @@ u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter)
1001 GLBtcWiFiInScanState = false; 1001 GLBtcWiFiInScanState = false;
1002 1002
1003 GLBtcWiFiInIQKState = false; 1003 GLBtcWiFiInIQKState = false;
1004
1005 return true;
1006} 1004}
1007 1005
1008void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist) 1006void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)
@@ -1337,7 +1335,7 @@ void hal_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist)
1337 *true Enable BT co-exist mechanism 1335 *true Enable BT co-exist mechanism
1338 *false Disable BT co-exist mechanism 1336 *false Disable BT co-exist mechanism
1339 */ 1337 */
1340u8 hal_btcoex_IsBtExist(struct adapter *padapter) 1338bool hal_btcoex_IsBtExist(struct adapter *padapter)
1341{ 1339{
1342 struct hal_com_data *pHalData; 1340 struct hal_com_data *pHalData;
1343 1341
@@ -1384,12 +1382,6 @@ void hal_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath)
1384 EXhalbtcoutsrc_SetSingleAntPath(singleAntPath); 1382 EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
1385} 1383}
1386 1384
1387u8 hal_btcoex_Initialize(struct adapter *padapter)
1388{
1389 memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
1390 return EXhalbtcoutsrc_InitlizeVariables((void *)padapter);
1391}
1392
1393void hal_btcoex_PowerOnSetting(struct adapter *padapter) 1385void hal_btcoex_PowerOnSetting(struct adapter *padapter)
1394{ 1386{
1395 EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist); 1387 EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
@@ -1477,9 +1469,9 @@ void hal_btcoex_SetManualControl(struct adapter *padapter, u8 bmanual)
1477 GLBtCoexist.bManualControl = bmanual; 1469 GLBtCoexist.bManualControl = bmanual;
1478} 1470}
1479 1471
1480u8 hal_btcoex_IsBtControlLps(struct adapter *padapter) 1472bool hal_btcoex_IsBtControlLps(struct adapter *padapter)
1481{ 1473{
1482 if (hal_btcoex_IsBtExist(padapter) == false) 1474 if (!hal_btcoex_IsBtExist(padapter))
1483 return false; 1475 return false;
1484 1476
1485 if (GLBtCoexist.btInfo.bBtDisabled) 1477 if (GLBtCoexist.btInfo.bBtDisabled)
@@ -1491,9 +1483,9 @@ u8 hal_btcoex_IsBtControlLps(struct adapter *padapter)
1491 return false; 1483 return false;
1492} 1484}
1493 1485
1494u8 hal_btcoex_IsLpsOn(struct adapter *padapter) 1486bool hal_btcoex_IsLpsOn(struct adapter *padapter)
1495{ 1487{
1496 if (hal_btcoex_IsBtExist(padapter) == false) 1488 if (!hal_btcoex_IsBtExist(padapter))
1497 return false; 1489 return false;
1498 1490
1499 if (GLBtCoexist.btInfo.bBtDisabled) 1491 if (GLBtCoexist.btInfo.bBtDisabled)
diff --git a/drivers/staging/rtl8723bs/hal/hal_com.c b/drivers/staging/rtl8723bs/hal/hal_com.c
index 638b12ae6ee9..eddd56abbb2d 100644
--- a/drivers/staging/rtl8723bs/hal/hal_com.c
+++ b/drivers/staging/rtl8723bs/hal/hal_com.c
@@ -152,10 +152,7 @@ bool HAL_IsLegalChannel(struct adapter *Adapter, u32 Channel)
152{ 152{
153 bool bLegalChannel = true; 153 bool bLegalChannel = true;
154 154
155 if (Channel > 14) { 155 if ((Channel <= 14) && (Channel >= 1)) {
156 bLegalChannel = false;
157 DBG_871X("Channel > 14 but wireless_mode do not support 5G\n");
158 } else if ((Channel <= 14) && (Channel >= 1)) {
159 if (IsSupported24G(Adapter->registrypriv.wireless_mode) == false) { 156 if (IsSupported24G(Adapter->registrypriv.wireless_mode) == false) {
160 bLegalChannel = false; 157 bLegalChannel = false;
161 DBG_871X("(Channel <= 14) && (Channel >= 1) but wireless_mode do not support 2.4G\n"); 158 DBG_871X("(Channel <= 14) && (Channel >= 1) but wireless_mode do not support 2.4G\n");
diff --git a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
index 336764464e7d..6539bee9b5ba 100644
--- a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
+++ b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
@@ -2040,24 +2040,6 @@ void PHY_SetTxPowerLimit(
2040 } 2040 }
2041} 2041}
2042 2042
2043u8 PHY_GetTxPowerIndex(
2044 struct adapter *padapter,
2045 u8 RFPath,
2046 u8 Rate,
2047 enum CHANNEL_WIDTH BandWidth,
2048 u8 Channel
2049)
2050{
2051 return PHY_GetTxPowerIndex_8723B(padapter, RFPath, Rate, BandWidth, Channel);
2052}
2053
2054void PHY_SetTxPowerIndex(
2055 struct adapter *padapter, u32 PowerIndex, u8 RFPath, u8 Rate
2056)
2057{
2058 PHY_SetTxPowerIndex_8723B(padapter, PowerIndex, RFPath, Rate);
2059}
2060
2061void Hal_ChannelPlanToRegulation(struct adapter *Adapter, u16 ChannelPlan) 2043void Hal_ChannelPlanToRegulation(struct adapter *Adapter, u16 ChannelPlan)
2062{ 2044{
2063 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); 2045 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
diff --git a/drivers/staging/rtl8723bs/hal/hal_intf.c b/drivers/staging/rtl8723bs/hal/hal_intf.c
index acb25978a46c..7d8f21f32fb9 100644
--- a/drivers/staging/rtl8723bs/hal/hal_intf.c
+++ b/drivers/staging/rtl8723bs/hal/hal_intf.c
@@ -369,7 +369,7 @@ void rtw_hal_dm_watchdog_in_lps(struct adapter *padapter)
369 } 369 }
370} 370}
371 371
372void rtw_hal_bcn_related_reg_setting(struct adapter *padapter) 372void beacon_timing_control(struct adapter *padapter)
373{ 373{
374 if (padapter->HalFunc.SetBeaconRelatedRegistersHandler) 374 if (padapter->HalFunc.SetBeaconRelatedRegistersHandler)
375 padapter->HalFunc.SetBeaconRelatedRegistersHandler(padapter); 375 padapter->HalFunc.SetBeaconRelatedRegistersHandler(padapter);
diff --git a/drivers/staging/rtl8723bs/hal/hal_phy.c b/drivers/staging/rtl8723bs/hal/hal_phy.c
deleted file mode 100644
index 24a9d8f783f0..000000000000
--- a/drivers/staging/rtl8723bs/hal/hal_phy.c
+++ /dev/null
@@ -1,157 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/******************************************************************************
3 *
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 *
6 ******************************************************************************/
7#define _HAL_PHY_C_
8
9#include <drv_types.h>
10
11/* */
12/* ==> RF shadow Operation API Code Section!!! */
13/* */
14/*-----------------------------------------------------------------------------
15 * Function: PHY_RFShadowRead
16 * PHY_RFShadowWrite
17 * PHY_RFShadowCompare
18 * PHY_RFShadowRecorver
19 * PHY_RFShadowCompareAll
20 * PHY_RFShadowRecorverAll
21 * PHY_RFShadowCompareFlagSet
22 * PHY_RFShadowRecorverFlagSet
23 *
24 * Overview: When we set RF register, we must write shadow at first.
25 * When we are running, we must compare shadow abd locate error addr.
26 * Decide to recorver or not.
27 *
28 * Input: NONE
29 *
30 * Output: NONE
31 *
32 * Return: NONE
33 *
34 * Revised History:
35 * When Who Remark
36 * 11/20/2008 MHC Create Version 0.
37 *
38 *---------------------------------------------------------------------------*/
39u32 PHY_RFShadowRead(IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset)
40{
41 return RF_Shadow[eRFPath][Offset].Value;
42
43} /* PHY_RFShadowRead */
44
45
46void PHY_RFShadowWrite(
47 IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset, IN u32 Data
48)
49{
50 RF_Shadow[eRFPath][Offset].Value = (Data & bRFRegOffsetMask);
51 RF_Shadow[eRFPath][Offset].Driver_Write = true;
52
53} /* PHY_RFShadowWrite */
54
55
56bool PHY_RFShadowCompare(IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset)
57{
58 u32 reg;
59 /* Check if we need to check the register */
60 if (RF_Shadow[eRFPath][Offset].Compare == true) {
61 reg = rtw_hal_read_rfreg(Adapter, eRFPath, Offset, bRFRegOffsetMask);
62 /* Compare shadow and real rf register for 20bits!! */
63 if (RF_Shadow[eRFPath][Offset].Value != reg) {
64 /* Locate error position. */
65 RF_Shadow[eRFPath][Offset].ErrorOrNot = true;
66 /* RT_TRACE(COMP_INIT, DBG_LOUD, */
67 /* PHY_RFShadowCompare RF-%d Addr%02lx Err = %05lx\n", */
68 /* eRFPath, Offset, reg)); */
69 }
70 return RF_Shadow[eRFPath][Offset].ErrorOrNot;
71 }
72 return false;
73} /* PHY_RFShadowCompare */
74
75
76void PHY_RFShadowRecorver(IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset)
77{
78 /* Check if the address is error */
79 if (RF_Shadow[eRFPath][Offset].ErrorOrNot == true) {
80 /* Check if we need to recorver the register. */
81 if (RF_Shadow[eRFPath][Offset].Recorver == true) {
82 rtw_hal_write_rfreg(Adapter, eRFPath, Offset, bRFRegOffsetMask,
83 RF_Shadow[eRFPath][Offset].Value);
84 /* RT_TRACE(COMP_INIT, DBG_LOUD, */
85 /* PHY_RFShadowRecorver RF-%d Addr%02lx=%05lx", */
86 /* eRFPath, Offset, RF_Shadow[eRFPath][Offset].Value)); */
87 }
88 }
89
90} /* PHY_RFShadowRecorver */
91
92
93void PHY_RFShadowCompareAll(IN PADAPTER Adapter)
94{
95 u8 eRFPath = 0;
96 u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
97
98 for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
99 for (Offset = 0; Offset < maxReg; Offset++) {
100 PHY_RFShadowCompare(Adapter, eRFPath, Offset);
101 }
102 }
103
104} /* PHY_RFShadowCompareAll */
105
106
107void PHY_RFShadowRecorverAll(IN PADAPTER Adapter)
108{
109 u8 eRFPath = 0;
110 u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
111
112 for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
113 for (Offset = 0; Offset < maxReg; Offset++) {
114 PHY_RFShadowRecorver(Adapter, eRFPath, Offset);
115 }
116 }
117
118} /* PHY_RFShadowRecorverAll */
119
120
121void
122PHY_RFShadowCompareFlagSet(
123 IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset, IN u8 Type
124)
125{
126 /* Set True or False!!! */
127 RF_Shadow[eRFPath][Offset].Compare = Type;
128
129} /* PHY_RFShadowCompareFlagSet */
130
131
132void PHY_RFShadowRecorverFlagSet(
133 IN PADAPTER Adapter, IN u8 eRFPath, IN u32 Offset, IN u8 Type
134)
135{
136 /* Set True or False!!! */
137 RF_Shadow[eRFPath][Offset].Recorver = Type;
138
139} /* PHY_RFShadowRecorverFlagSet */
140
141
142void PHY_RFShadowCompareFlagSetAll(IN PADAPTER Adapter)
143{
144 u8 eRFPath = 0;
145 u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
146
147 for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
148 for (Offset = 0; Offset < maxReg; Offset++) {
149 /* 2008/11/20 MH For S3S4 test, we only check reg 26/27 now!!!! */
150 if (Offset != 0x26 && Offset != 0x27)
151 PHY_RFShadowCompareFlagSet(Adapter, eRFPath, Offset, false);
152 else
153 PHY_RFShadowCompareFlagSet(Adapter, eRFPath, Offset, true);
154 }
155 }
156
157} /* PHY_RFShadowCompareFlagSetAll */
diff --git a/drivers/staging/rtl8723bs/hal/odm.c b/drivers/staging/rtl8723bs/hal/odm.c
index e3f4307f3d20..aa6631ee4ea7 100644
--- a/drivers/staging/rtl8723bs/hal/odm.c
+++ b/drivers/staging/rtl8723bs/hal/odm.c
@@ -339,13 +339,9 @@ void ODM_TXPowerTrackingCheck(PDM_ODM_T pDM_Odm);
339 339
340void odm_RateAdaptiveMaskInit(PDM_ODM_T pDM_Odm); 340void odm_RateAdaptiveMaskInit(PDM_ODM_T pDM_Odm);
341 341
342void odm_TXPowerTrackingThermalMeterInit(PDM_ODM_T pDM_Odm);
343
344 342
345void odm_TXPowerTrackingInit(PDM_ODM_T pDM_Odm); 343void odm_TXPowerTrackingInit(PDM_ODM_T pDM_Odm);
346 344
347void odm_TXPowerTrackingCheckCE(PDM_ODM_T pDM_Odm);
348
349/* Remove Edca by Yu Chen */ 345/* Remove Edca by Yu Chen */
350 346
351 347
@@ -1259,13 +1255,11 @@ void odm_RSSIMonitorCheckCE(PDM_ODM_T pDM_Odm)
1259 int tmpEntryMaxPWDB = 0, tmpEntryMinPWDB = 0xff; 1255 int tmpEntryMaxPWDB = 0, tmpEntryMinPWDB = 0xff;
1260 u8 sta_cnt = 0; 1256 u8 sta_cnt = 0;
1261 u32 PWDB_rssi[NUM_STA] = {0};/* 0~15]:MACID, [16~31]:PWDB_rssi */ 1257 u32 PWDB_rssi[NUM_STA] = {0};/* 0~15]:MACID, [16~31]:PWDB_rssi */
1262 bool FirstConnect = false;
1263 pRA_T pRA_Table = &pDM_Odm->DM_RA_Table; 1258 pRA_T pRA_Table = &pDM_Odm->DM_RA_Table;
1264 1259
1265 if (pDM_Odm->bLinked != true) 1260 if (pDM_Odm->bLinked != true)
1266 return; 1261 return;
1267 1262
1268 FirstConnect = (pDM_Odm->bLinked) && (pRA_Table->firstconnect == false);
1269 pRA_Table->firstconnect = pDM_Odm->bLinked; 1263 pRA_Table->firstconnect = pDM_Odm->bLinked;
1270 1264
1271 /* if (check_fwstate(&Adapter->mlmepriv, WIFI_AP_STATE|WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE) == true) */ 1265 /* if (check_fwstate(&Adapter->mlmepriv, WIFI_AP_STATE|WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE) == true) */
@@ -1324,11 +1318,6 @@ void odm_RSSIMonitorCheckCE(PDM_ODM_T pDM_Odm)
1324/* 3 Tx Power Tracking */ 1318/* 3 Tx Power Tracking */
1325/* 3 ============================================================ */ 1319/* 3 ============================================================ */
1326 1320
1327void odm_TXPowerTrackingInit(PDM_ODM_T pDM_Odm)
1328{
1329 odm_TXPowerTrackingThermalMeterInit(pDM_Odm);
1330}
1331
1332static u8 getSwingIndex(PDM_ODM_T pDM_Odm) 1321static u8 getSwingIndex(PDM_ODM_T pDM_Odm)
1333{ 1322{
1334 struct adapter *Adapter = pDM_Odm->Adapter; 1323 struct adapter *Adapter = pDM_Odm->Adapter;
@@ -1353,7 +1342,7 @@ static u8 getSwingIndex(PDM_ODM_T pDM_Odm)
1353 return i; 1342 return i;
1354} 1343}
1355 1344
1356void odm_TXPowerTrackingThermalMeterInit(PDM_ODM_T pDM_Odm) 1345void odm_TXPowerTrackingInit(PDM_ODM_T pDM_Odm)
1357{ 1346{
1358 u8 defaultSwingIndex = getSwingIndex(pDM_Odm); 1347 u8 defaultSwingIndex = getSwingIndex(pDM_Odm);
1359 u8 p = 0; 1348 u8 p = 0;
@@ -1397,14 +1386,8 @@ void odm_TXPowerTrackingThermalMeterInit(PDM_ODM_T pDM_Odm)
1397 1386
1398} 1387}
1399 1388
1400
1401void ODM_TXPowerTrackingCheck(PDM_ODM_T pDM_Odm) 1389void ODM_TXPowerTrackingCheck(PDM_ODM_T pDM_Odm)
1402{ 1390{
1403 odm_TXPowerTrackingCheckCE(pDM_Odm);
1404}
1405
1406void odm_TXPowerTrackingCheckCE(PDM_ODM_T pDM_Odm)
1407{
1408 struct adapter *Adapter = pDM_Odm->Adapter; 1391 struct adapter *Adapter = pDM_Odm->Adapter;
1409 1392
1410 if (!(pDM_Odm->SupportAbility & ODM_RF_TX_PWR_TRACK)) 1393 if (!(pDM_Odm->SupportAbility & ODM_RF_TX_PWR_TRACK))
diff --git a/drivers/staging/rtl8723bs/hal/odm.h b/drivers/staging/rtl8723bs/hal/odm.h
index 6ba77bb70889..fba3b9e1491b 100644
--- a/drivers/staging/rtl8723bs/hal/odm.h
+++ b/drivers/staging/rtl8723bs/hal/odm.h
@@ -1365,10 +1365,6 @@ extern u32 TxScalingTable_Jaguar[TXSCALE_TABLE_SIZE];
1365#define SWAW_STEP_PEAK 0 1365#define SWAW_STEP_PEAK 0
1366#define SWAW_STEP_DETERMINE 1 1366#define SWAW_STEP_DETERMINE 1
1367 1367
1368/* Remove DIG by yuchen */
1369
1370void ODM_SetAntenna(PDM_ODM_T pDM_Odm, u8 Antenna);
1371
1372/* Remove BB power saving by Yuchen */ 1368/* Remove BB power saving by Yuchen */
1373 1369
1374#define dm_CheckTXPowerTracking ODM_TXPowerTrackingCheck 1370#define dm_CheckTXPowerTracking ODM_TXPowerTrackingCheck
diff --git a/drivers/staging/rtl8723bs/hal/odm_CfoTracking.c b/drivers/staging/rtl8723bs/hal/odm_CfoTracking.c
index a73304639226..95edd148ac24 100644
--- a/drivers/staging/rtl8723bs/hal/odm_CfoTracking.c
+++ b/drivers/staging/rtl8723bs/hal/odm_CfoTracking.c
@@ -11,11 +11,6 @@ static void odm_SetCrystalCap(void *pDM_VOID, u8 CrystalCap)
11{ 11{
12 PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID; 12 PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID;
13 PCFO_TRACKING pCfoTrack = &pDM_Odm->DM_CfoTrack; 13 PCFO_TRACKING pCfoTrack = &pDM_Odm->DM_CfoTrack;
14 bool bEEPROMCheck;
15 struct adapter *Adapter = pDM_Odm->Adapter;
16 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
17
18 bEEPROMCheck = pHalData->EEPROMVersion >= 0x01;
19 14
20 if (pCfoTrack->CrystalCap == CrystalCap) 15 if (pCfoTrack->CrystalCap == CrystalCap)
21 return; 16 return;
diff --git a/drivers/staging/rtl8723bs/hal/odm_HWConfig.c b/drivers/staging/rtl8723bs/hal/odm_HWConfig.c
index 49fa814068b8..71919a3d81ab 100644
--- a/drivers/staging/rtl8723bs/hal/odm_HWConfig.c
+++ b/drivers/staging/rtl8723bs/hal/odm_HWConfig.c
@@ -89,7 +89,6 @@ static void odm_RxPhyStatus92CSeries_Parsing(
89 u8 RSSI, total_rssi = 0; 89 u8 RSSI, total_rssi = 0;
90 bool isCCKrate = false; 90 bool isCCKrate = false;
91 u8 rf_rx_num = 0; 91 u8 rf_rx_num = 0;
92 u8 cck_highpwr = 0;
93 u8 LNA_idx, VGA_idx; 92 u8 LNA_idx, VGA_idx;
94 PPHY_STATUS_RPT_8192CD_T pPhyStaRpt = (PPHY_STATUS_RPT_8192CD_T)pPhyStatus; 93 PPHY_STATUS_RPT_8192CD_T pPhyStaRpt = (PPHY_STATUS_RPT_8192CD_T)pPhyStatus;
95 94
@@ -107,16 +106,10 @@ static void odm_RxPhyStatus92CSeries_Parsing(
107 /* (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive) */ 106 /* (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive) */
108 /* */ 107 /* */
109 108
110 /* if (pHalData->eRFPowerState == eRfOn) */
111 cck_highpwr = pDM_Odm->bCckHighPower;
112 /* else */
113 /* cck_highpwr = false; */
114
115 cck_agc_rpt = pPhyStaRpt->cck_agc_rpt_ofdm_cfosho_a ; 109 cck_agc_rpt = pPhyStaRpt->cck_agc_rpt_ofdm_cfosho_a ;
116 110
117 /* 2011.11.28 LukeLee: 88E use different LNA & VGA gain table */ 111 /* 2011.11.28 LukeLee: 88E use different LNA & VGA gain table */
118 /* The RSSI formula should be modified according to the gain table */ 112 /* The RSSI formula should be modified according to the gain table */
119 /* In 88E, cck_highpwr is always set to 1 */
120 LNA_idx = ((cck_agc_rpt & 0xE0)>>5); 113 LNA_idx = ((cck_agc_rpt & 0xE0)>>5);
121 VGA_idx = (cck_agc_rpt & 0x1F); 114 VGA_idx = (cck_agc_rpt & 0x1F);
122 rx_pwr_all = odm_CCKRSSI_8723B(LNA_idx, VGA_idx); 115 rx_pwr_all = odm_CCKRSSI_8723B(LNA_idx, VGA_idx);
diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c b/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c
index 080e974914b6..7760fd0eb6c9 100644
--- a/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c
+++ b/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c
@@ -1300,7 +1300,7 @@ static void rtl8723b_set_FwScanOffloadInfo_cmd(struct adapter *padapter, PRSVDPA
1300} 1300}
1301#endif /* CONFIG_PNO_SUPPORT */ 1301#endif /* CONFIG_PNO_SUPPORT */
1302 1302
1303static void rtl8723b_set_FwWoWlanRelated_cmd(struct adapter *padapter, u8 enable) 1303void rtl8723b_set_wowlan_cmd(struct adapter *padapter, u8 enable)
1304{ 1304{
1305 struct security_priv *psecpriv = &padapter->securitypriv; 1305 struct security_priv *psecpriv = &padapter->securitypriv;
1306 struct pwrctrl_priv *ppwrpriv = adapter_to_pwrctl(padapter); 1306 struct pwrctrl_priv *ppwrpriv = adapter_to_pwrctl(padapter);
@@ -1346,11 +1346,6 @@ static void rtl8723b_set_FwWoWlanRelated_cmd(struct adapter *padapter, u8 enable
1346 1346
1347 DBG_871X_LEVEL(_drv_always_, "-%s()-\n", __func__); 1347 DBG_871X_LEVEL(_drv_always_, "-%s()-\n", __func__);
1348} 1348}
1349
1350void rtl8723b_set_wowlan_cmd(struct adapter *padapter, u8 enable)
1351{
1352 rtl8723b_set_FwWoWlanRelated_cmd(padapter, enable);
1353}
1354#endif /* CONFIG_WOWLAN */ 1349#endif /* CONFIG_WOWLAN */
1355 1350
1356#ifdef CONFIG_AP_WOWLAN 1351#ifdef CONFIG_AP_WOWLAN
@@ -1398,7 +1393,7 @@ static void rtl8723b_set_Fw_AP_Offload_Cmd(struct adapter *padapter, u8 bFuncEn)
1398 H2C_AP_OFFLOAD_LEN, u1H2CAPOffloadCtrlParm); 1393 H2C_AP_OFFLOAD_LEN, u1H2CAPOffloadCtrlParm);
1399} 1394}
1400 1395
1401static void rtl8723b_set_AP_FwWoWlan_cmd(struct adapter *padapter, u8 enable) 1396void rtl8723b_set_ap_wowlan_cmd(struct adapter *padapter, u8 enable)
1402{ 1397{
1403 DBG_871X_LEVEL(_drv_always_, "+%s()+: enable =%d\n", __func__, enable); 1398 DBG_871X_LEVEL(_drv_always_, "+%s()+: enable =%d\n", __func__, enable);
1404 if (enable) { 1399 if (enable) {
@@ -1411,12 +1406,6 @@ static void rtl8723b_set_AP_FwWoWlan_cmd(struct adapter *padapter, u8 enable)
1411 rtl8723b_set_Fw_AP_Offload_Cmd(padapter, enable); 1406 rtl8723b_set_Fw_AP_Offload_Cmd(padapter, enable);
1412 msleep(10); 1407 msleep(10);
1413 DBG_871X_LEVEL(_drv_always_, "-%s()-\n", __func__); 1408 DBG_871X_LEVEL(_drv_always_, "-%s()-\n", __func__);
1414 return ;
1415}
1416
1417void rtl8723b_set_ap_wowlan_cmd(struct adapter *padapter, u8 enable)
1418{
1419 rtl8723b_set_AP_FwWoWlan_cmd(padapter, enable);
1420} 1409}
1421#endif /* CONFIG_AP_WOWLAN */ 1410#endif /* CONFIG_AP_WOWLAN */
1422 1411
diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c b/drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c
index 25c75b977666..6df2b58bdc67 100644
--- a/drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c
+++ b/drivers/staging/rtl8723bs/hal/rtl8723b_phycfg.c
@@ -431,14 +431,12 @@ static int phy_BB8723b_Config_ParaFile(struct adapter *Adapter)
431 u8 sz8723BBRegFile[] = RTL8723B_PHY_REG; 431 u8 sz8723BBRegFile[] = RTL8723B_PHY_REG;
432 u8 sz8723AGCTableFile[] = RTL8723B_AGC_TAB; 432 u8 sz8723AGCTableFile[] = RTL8723B_AGC_TAB;
433 u8 sz8723BBBRegPgFile[] = RTL8723B_PHY_REG_PG; 433 u8 sz8723BBBRegPgFile[] = RTL8723B_PHY_REG_PG;
434 u8 sz8723BBRegMpFile[] = RTL8723B_PHY_REG_MP;
435 u8 sz8723BRFTxPwrLmtFile[] = RTL8723B_TXPWR_LMT; 434 u8 sz8723BRFTxPwrLmtFile[] = RTL8723B_TXPWR_LMT;
436 u8 *pszBBRegFile = NULL, *pszAGCTableFile = NULL, *pszBBRegPgFile = NULL, *pszBBRegMpFile = NULL, *pszRFTxPwrLmtFile = NULL; 435 u8 *pszBBRegFile = NULL, *pszAGCTableFile = NULL, *pszBBRegPgFile = NULL, *pszRFTxPwrLmtFile = NULL;
437 436
438 pszBBRegFile = sz8723BBRegFile; 437 pszBBRegFile = sz8723BBRegFile;
439 pszAGCTableFile = sz8723AGCTableFile; 438 pszAGCTableFile = sz8723AGCTableFile;
440 pszBBRegPgFile = sz8723BBBRegPgFile; 439 pszBBRegPgFile = sz8723BBBRegPgFile;
441 pszBBRegMpFile = sz8723BBRegMpFile;
442 pszRFTxPwrLmtFile = sz8723BRFTxPwrLmtFile; 440 pszRFTxPwrLmtFile = sz8723BRFTxPwrLmtFile;
443 441
444 /* Read Tx Power Limit File */ 442 /* Read Tx Power Limit File */
@@ -585,7 +583,7 @@ int PHY_RFConfig8723B(struct adapter *Adapter)
585 * <20120830, Kordan> 583 * <20120830, Kordan>
586 **************************************************************************************************************/ 584 **************************************************************************************************************/
587 585
588void PHY_SetTxPowerIndex_8723B( 586void PHY_SetTxPowerIndex(
589 struct adapter *Adapter, 587 struct adapter *Adapter,
590 u32 PowerIndex, 588 u32 PowerIndex,
591 u8 RFPath, 589 u8 RFPath,
@@ -668,7 +666,7 @@ void PHY_SetTxPowerIndex_8723B(
668 } 666 }
669} 667}
670 668
671u8 PHY_GetTxPowerIndex_8723B( 669u8 PHY_GetTxPowerIndex(
672 struct adapter *padapter, 670 struct adapter *padapter,
673 u8 RFPath, 671 u8 RFPath,
674 u8 Rate, 672 u8 Rate,
diff --git a/drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c b/drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c
index e23b39ab16c5..0f3301091258 100644
--- a/drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c
+++ b/drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c
@@ -486,7 +486,6 @@ initbuferror:
486 } 486 }
487 487
488 if (precvpriv->pallocated_recv_buf) { 488 if (precvpriv->pallocated_recv_buf) {
489 n = NR_RECVBUFF * sizeof(struct recv_buf) + 4;
490 kfree(precvpriv->pallocated_recv_buf); 489 kfree(precvpriv->pallocated_recv_buf);
491 precvpriv->pallocated_recv_buf = NULL; 490 precvpriv->pallocated_recv_buf = NULL;
492 } 491 }
@@ -503,7 +502,7 @@ exit:
503 */ 502 */
504void rtl8723bs_free_recv_priv(struct adapter *padapter) 503void rtl8723bs_free_recv_priv(struct adapter *padapter)
505{ 504{
506 u32 i, n; 505 u32 i;
507 struct recv_priv *precvpriv; 506 struct recv_priv *precvpriv;
508 struct recv_buf *precvbuf; 507 struct recv_buf *precvbuf;
509 508
@@ -515,9 +514,8 @@ void rtl8723bs_free_recv_priv(struct adapter *padapter)
515 /* 3 2. free all recv buffers */ 514 /* 3 2. free all recv buffers */
516 precvbuf = (struct recv_buf *)precvpriv->precv_buf; 515 precvbuf = (struct recv_buf *)precvpriv->precv_buf;
517 if (precvbuf) { 516 if (precvbuf) {
518 n = NR_RECVBUFF;
519 precvpriv->free_recv_buf_queue_cnt = 0; 517 precvpriv->free_recv_buf_queue_cnt = 0;
520 for (i = 0; i < n ; i++) { 518 for (i = 0; i < NR_RECVBUFF; i++) {
521 list_del_init(&precvbuf->list); 519 list_del_init(&precvbuf->list);
522 rtw_os_recvbuf_resource_free(padapter, precvbuf); 520 rtw_os_recvbuf_resource_free(padapter, precvbuf);
523 precvbuf++; 521 precvbuf++;
@@ -526,7 +524,6 @@ void rtl8723bs_free_recv_priv(struct adapter *padapter)
526 } 524 }
527 525
528 if (precvpriv->pallocated_recv_buf) { 526 if (precvpriv->pallocated_recv_buf) {
529 n = NR_RECVBUFF * sizeof(struct recv_buf) + 4;
530 kfree(precvpriv->pallocated_recv_buf); 527 kfree(precvpriv->pallocated_recv_buf);
531 precvpriv->pallocated_recv_buf = NULL; 528 precvpriv->pallocated_recv_buf = NULL;
532 } 529 }
diff --git a/drivers/staging/rtl8723bs/include/autoconf.h b/drivers/staging/rtl8723bs/include/autoconf.h
index 196aca3aed7b..8f4c1e734473 100644
--- a/drivers/staging/rtl8723bs/include/autoconf.h
+++ b/drivers/staging/rtl8723bs/include/autoconf.h
@@ -57,9 +57,5 @@
57#define DBG 0 /* for ODM & BTCOEX debug */ 57#define DBG 0 /* for ODM & BTCOEX debug */
58#endif /* !DEBUG */ 58#endif /* !DEBUG */
59 59
60#ifdef CONFIG_PROC_FS
61#define PROC_DEBUG
62#endif
63
64/* define DBG_XMIT_BUF */ 60/* define DBG_XMIT_BUF */
65/* define DBG_XMIT_BUF_EXT */ 61/* define DBG_XMIT_BUF_EXT */
diff --git a/drivers/staging/rtl8723bs/include/drv_types.h b/drivers/staging/rtl8723bs/include/drv_types.h
index 96346ce064aa..8d7fce1e39b7 100644
--- a/drivers/staging/rtl8723bs/include/drv_types.h
+++ b/drivers/staging/rtl8723bs/include/drv_types.h
@@ -478,7 +478,7 @@ struct sdio_data intf_data;
478#define dvobj_to_pwrctl(dvobj) (&(dvobj->pwrctl_priv)) 478#define dvobj_to_pwrctl(dvobj) (&(dvobj->pwrctl_priv))
479#define pwrctl_to_dvobj(pwrctl) container_of(pwrctl, struct dvobj_priv, pwrctl_priv) 479#define pwrctl_to_dvobj(pwrctl) container_of(pwrctl, struct dvobj_priv, pwrctl_priv)
480 480
481__inline static struct device *dvobj_to_dev(struct dvobj_priv *dvobj) 481static inline struct device *dvobj_to_dev(struct dvobj_priv *dvobj)
482{ 482{
483 /* todo: get interface type from dvobj and the return the dev accordingly */ 483 /* todo: get interface type from dvobj and the return the dev accordingly */
484#ifdef RTW_DVOBJ_CHIP_HW_TYPE 484#ifdef RTW_DVOBJ_CHIP_HW_TYPE
@@ -576,8 +576,6 @@ struct adapter {
576 int bup; 576 int bup;
577 struct net_device_stats stats; 577 struct net_device_stats stats;
578 struct iw_statistics iwstats; 578 struct iw_statistics iwstats;
579 struct proc_dir_entry *dir_dev;/* for proc directory */
580 struct proc_dir_entry *dir_odm;
581 579
582 struct wireless_dev *rtw_wdev; 580 struct wireless_dev *rtw_wdev;
583 struct rtw_wdev_priv wdev_data; 581 struct rtw_wdev_priv wdev_data;
@@ -636,14 +634,14 @@ struct adapter {
636 634
637/* define RTW_DISABLE_FUNC(padapter, func) (atomic_add(&adapter_to_dvobj(padapter)->disable_func, (func))) */ 635/* define RTW_DISABLE_FUNC(padapter, func) (atomic_add(&adapter_to_dvobj(padapter)->disable_func, (func))) */
638/* define RTW_ENABLE_FUNC(padapter, func) (atomic_sub(&adapter_to_dvobj(padapter)->disable_func, (func))) */ 636/* define RTW_ENABLE_FUNC(padapter, func) (atomic_sub(&adapter_to_dvobj(padapter)->disable_func, (func))) */
639__inline static void RTW_DISABLE_FUNC(struct adapter *padapter, int func_bit) 637static inline void RTW_DISABLE_FUNC(struct adapter *padapter, int func_bit)
640{ 638{
641 int df = atomic_read(&adapter_to_dvobj(padapter)->disable_func); 639 int df = atomic_read(&adapter_to_dvobj(padapter)->disable_func);
642 df |= func_bit; 640 df |= func_bit;
643 atomic_set(&adapter_to_dvobj(padapter)->disable_func, df); 641 atomic_set(&adapter_to_dvobj(padapter)->disable_func, df);
644} 642}
645 643
646__inline static void RTW_ENABLE_FUNC(struct adapter *padapter, int func_bit) 644static inline void RTW_ENABLE_FUNC(struct adapter *padapter, int func_bit)
647{ 645{
648 int df = atomic_read(&adapter_to_dvobj(padapter)->disable_func); 646 int df = atomic_read(&adapter_to_dvobj(padapter)->disable_func);
649 df &= ~(func_bit); 647 df &= ~(func_bit);
diff --git a/drivers/staging/rtl8723bs/include/hal_btcoex.h b/drivers/staging/rtl8723bs/include/hal_btcoex.h
index 6f7514be998f..eb03813fdcb9 100644
--- a/drivers/staging/rtl8723bs/include/hal_btcoex.h
+++ b/drivers/staging/rtl8723bs/include/hal_btcoex.h
@@ -22,13 +22,13 @@ typedef struct _BT_COEXIST
22void DBG_BT_INFO(u8 *dbgmsg); 22void DBG_BT_INFO(u8 *dbgmsg);
23 23
24void hal_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist); 24void hal_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist);
25u8 hal_btcoex_IsBtExist(struct adapter *padapter); 25bool hal_btcoex_IsBtExist(struct adapter *padapter);
26bool hal_btcoex_IsBtDisabled(struct adapter *); 26bool hal_btcoex_IsBtDisabled(struct adapter *);
27void hal_btcoex_SetChipType(struct adapter *padapter, u8 chipType); 27void hal_btcoex_SetChipType(struct adapter *padapter, u8 chipType);
28void hal_btcoex_SetPgAntNum(struct adapter *padapter, u8 antNum); 28void hal_btcoex_SetPgAntNum(struct adapter *padapter, u8 antNum);
29void hal_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath); 29void hal_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath);
30 30
31u8 hal_btcoex_Initialize(struct adapter *padapter); 31void hal_btcoex_Initialize(void *padapter);
32void hal_btcoex_PowerOnSetting(struct adapter *padapter); 32void hal_btcoex_PowerOnSetting(struct adapter *padapter);
33void hal_btcoex_InitHwConfig(struct adapter *padapter, u8 bWifiOnly); 33void hal_btcoex_InitHwConfig(struct adapter *padapter, u8 bWifiOnly);
34 34
@@ -47,8 +47,8 @@ void hal_btcoex_Handler(struct adapter *padapter);
47 47
48s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *padapter); 48s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *padapter);
49void hal_btcoex_SetManualControl(struct adapter *padapter, u8 bmanual); 49void hal_btcoex_SetManualControl(struct adapter *padapter, u8 bmanual);
50u8 hal_btcoex_IsBtControlLps(struct adapter *); 50bool hal_btcoex_IsBtControlLps(struct adapter *padapter);
51u8 hal_btcoex_IsLpsOn(struct adapter *); 51bool hal_btcoex_IsLpsOn(struct adapter *padapter);
52u8 hal_btcoex_RpwmVal(struct adapter *); 52u8 hal_btcoex_RpwmVal(struct adapter *);
53u8 hal_btcoex_LpsVal(struct adapter *); 53u8 hal_btcoex_LpsVal(struct adapter *);
54u32 hal_btcoex_GetRaMask(struct adapter *); 54u32 hal_btcoex_GetRaMask(struct adapter *);
diff --git a/drivers/staging/rtl8723bs/include/hal_com_phycfg.h b/drivers/staging/rtl8723bs/include/hal_com_phycfg.h
index f841546584a7..9167f1e7827f 100644
--- a/drivers/staging/rtl8723bs/include/hal_com_phycfg.h
+++ b/drivers/staging/rtl8723bs/include/hal_com_phycfg.h
@@ -213,23 +213,6 @@ PHY_GetTxPowerTrackingOffset(
213 u8 RFPath 213 u8 RFPath
214 ); 214 );
215 215
216u8
217PHY_GetTxPowerIndex(
218struct adapter * padapter,
219u8 RFPath,
220u8 Rate,
221enum CHANNEL_WIDTH BandWidth,
222u8 Channel
223 );
224
225void
226PHY_SetTxPowerIndex(
227struct adapter * padapter,
228u32 PowerIndex,
229u8 RFPath,
230u8 Rate
231 );
232
233void 216void
234Hal_ChannelPlanToRegulation( 217Hal_ChannelPlanToRegulation(
235struct adapter * Adapter, 218struct adapter * Adapter,
diff --git a/drivers/staging/rtl8723bs/include/hal_intf.h b/drivers/staging/rtl8723bs/include/hal_intf.h
index 3a0c3d079d50..24926ebaf950 100644
--- a/drivers/staging/rtl8723bs/include/hal_intf.h
+++ b/drivers/staging/rtl8723bs/include/hal_intf.h
@@ -362,7 +362,7 @@ void rtw_hal_add_ra_tid(struct adapter *padapter, u32 bitmap, u8 *arg, u8 rssi_l
362void rtw_hal_start_thread(struct adapter *padapter); 362void rtw_hal_start_thread(struct adapter *padapter);
363void rtw_hal_stop_thread(struct adapter *padapter); 363void rtw_hal_stop_thread(struct adapter *padapter);
364 364
365void rtw_hal_bcn_related_reg_setting(struct adapter *padapter); 365void beacon_timing_control(struct adapter *padapter);
366 366
367u32 rtw_hal_read_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask); 367u32 rtw_hal_read_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask);
368void rtw_hal_write_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask, u32 Data); 368void rtw_hal_write_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask, u32 Data);
diff --git a/drivers/staging/rtl8723bs/include/hal_phy_cfg.h b/drivers/staging/rtl8723bs/include/hal_phy_cfg.h
index 640427f407e3..b40868b2e76f 100644
--- a/drivers/staging/rtl8723bs/include/hal_phy_cfg.h
+++ b/drivers/staging/rtl8723bs/include/hal_phy_cfg.h
@@ -65,7 +65,7 @@ int PHY_RFConfig8723B(struct adapter *Adapter );
65s32 PHY_MACConfig8723B(struct adapter *padapter); 65s32 PHY_MACConfig8723B(struct adapter *padapter);
66 66
67void 67void
68PHY_SetTxPowerIndex_8723B( 68PHY_SetTxPowerIndex(
69struct adapter * Adapter, 69struct adapter * Adapter,
70u32 PowerIndex, 70u32 PowerIndex,
71u8 RFPath, 71u8 RFPath,
@@ -73,7 +73,7 @@ u8 Rate
73 ); 73 );
74 74
75u8 75u8
76PHY_GetTxPowerIndex_8723B( 76PHY_GetTxPowerIndex(
77struct adapter * padapter, 77struct adapter * padapter,
78u8 RFPath, 78u8 RFPath,
79u8 Rate, 79u8 Rate,
diff --git a/drivers/staging/rtl8723bs/include/osdep_intf.h b/drivers/staging/rtl8723bs/include/osdep_intf.h
index 40313d17a242..fa16139fcce6 100644
--- a/drivers/staging/rtl8723bs/include/osdep_intf.h
+++ b/drivers/staging/rtl8723bs/include/osdep_intf.h
@@ -64,8 +64,6 @@ u16 rtw_recv_select_queue(struct sk_buff *skb);
64int rtw_ndev_notifier_register(void); 64int rtw_ndev_notifier_register(void);
65void rtw_ndev_notifier_unregister(void); 65void rtw_ndev_notifier_unregister(void);
66 66
67#include "../os_dep/rtw_proc.h"
68
69void rtw_ips_dev_unload(struct adapter *padapter); 67void rtw_ips_dev_unload(struct adapter *padapter);
70 68
71int rtw_ips_pwr_up(struct adapter *padapter); 69int rtw_ips_pwr_up(struct adapter *padapter);
diff --git a/drivers/staging/rtl8723bs/include/osdep_service.h b/drivers/staging/rtl8723bs/include/osdep_service.h
index d2616af95ffa..81a9c19ecc6a 100644
--- a/drivers/staging/rtl8723bs/include/osdep_service.h
+++ b/drivers/staging/rtl8723bs/include/osdep_service.h
@@ -110,12 +110,12 @@ int _rtw_netif_rx(_nic_hdl ndev, struct sk_buff *skb);
110 110
111extern void _rtw_init_queue(struct __queue *pqueue); 111extern void _rtw_init_queue(struct __queue *pqueue);
112 112
113static __inline void thread_enter(char *name) 113static inline void thread_enter(char *name)
114{ 114{
115 allow_signal(SIGTERM); 115 allow_signal(SIGTERM);
116} 116}
117 117
118__inline static void flush_signals_thread(void) 118static inline void flush_signals_thread(void)
119{ 119{
120 if (signal_pending (current)) 120 if (signal_pending (current))
121 { 121 {
@@ -125,7 +125,7 @@ __inline static void flush_signals_thread(void)
125 125
126#define rtw_warn_on(condition) WARN_ON(condition) 126#define rtw_warn_on(condition) WARN_ON(condition)
127 127
128__inline static int rtw_bug_check(void *parg1, void *parg2, void *parg3, void *parg4) 128static inline int rtw_bug_check(void *parg1, void *parg2, void *parg3, void *parg4)
129{ 129{
130 int ret = true; 130 int ret = true;
131 131
@@ -136,7 +136,7 @@ __inline static int rtw_bug_check(void *parg1, void *parg2, void *parg3, void *p
136#define _RND(sz, r) ((((sz)+((r)-1))/(r))*(r)) 136#define _RND(sz, r) ((((sz)+((r)-1))/(r))*(r))
137#define RND4(x) (((x >> 2) + (((x & 3) == 0) ? 0: 1)) << 2) 137#define RND4(x) (((x >> 2) + (((x & 3) == 0) ? 0: 1)) << 2)
138 138
139__inline static u32 _RND4(u32 sz) 139static inline u32 _RND4(u32 sz)
140{ 140{
141 141
142 u32 val; 142 u32 val;
@@ -147,7 +147,7 @@ __inline static u32 _RND4(u32 sz)
147 147
148} 148}
149 149
150__inline static u32 _RND8(u32 sz) 150static inline u32 _RND8(u32 sz)
151{ 151{
152 152
153 u32 val; 153 u32 val;
diff --git a/drivers/staging/rtl8723bs/include/osdep_service_linux.h b/drivers/staging/rtl8723bs/include/osdep_service_linux.h
index 2f1b51e614fb..c582ede1ac12 100644
--- a/drivers/staging/rtl8723bs/include/osdep_service_linux.h
+++ b/drivers/staging/rtl8723bs/include/osdep_service_linux.h
@@ -64,12 +64,12 @@
64 64
65 typedef struct work_struct _workitem; 65 typedef struct work_struct _workitem;
66 66
67__inline static struct list_head *get_next(struct list_head *list) 67static inline struct list_head *get_next(struct list_head *list)
68{ 68{
69 return list->next; 69 return list->next;
70} 70}
71 71
72__inline static struct list_head *get_list_head(struct __queue *queue) 72static inline struct list_head *get_list_head(struct __queue *queue)
73{ 73{
74 return (&(queue->queue)); 74 return (&(queue->queue));
75} 75}
@@ -78,28 +78,28 @@ __inline static struct list_head *get_list_head(struct __queue *queue)
78#define LIST_CONTAINOR(ptr, type, member) \ 78#define LIST_CONTAINOR(ptr, type, member) \
79 container_of(ptr, type, member) 79 container_of(ptr, type, member)
80 80
81__inline static void _set_timer(_timer *ptimer, u32 delay_time) 81static inline void _set_timer(_timer *ptimer, u32 delay_time)
82{ 82{
83 mod_timer(ptimer , (jiffies+(delay_time*HZ/1000))); 83 mod_timer(ptimer , (jiffies+(delay_time*HZ/1000)));
84} 84}
85 85
86__inline static void _cancel_timer(_timer *ptimer, u8 *bcancelled) 86static inline void _cancel_timer(_timer *ptimer, u8 *bcancelled)
87{ 87{
88 del_timer_sync(ptimer); 88 del_timer_sync(ptimer);
89 *bcancelled = true;/* true == 1; false == 0 */ 89 *bcancelled = true;/* true == 1; false == 0 */
90} 90}
91 91
92__inline static void _init_workitem(_workitem *pwork, void *pfunc, void *cntx) 92static inline void _init_workitem(_workitem *pwork, void *pfunc, void *cntx)
93{ 93{
94 INIT_WORK(pwork, pfunc); 94 INIT_WORK(pwork, pfunc);
95} 95}
96 96
97__inline static void _set_workitem(_workitem *pwork) 97static inline void _set_workitem(_workitem *pwork)
98{ 98{
99 schedule_work(pwork); 99 schedule_work(pwork);
100} 100}
101 101
102__inline static void _cancel_workitem_sync(_workitem *pwork) 102static inline void _cancel_workitem_sync(_workitem *pwork)
103{ 103{
104 cancel_work_sync(pwork); 104 cancel_work_sync(pwork);
105} 105}
diff --git a/drivers/staging/rtl8723bs/include/rtw_debug.h b/drivers/staging/rtl8723bs/include/rtw_debug.h
index 216d9492575e..22fc5d730d7b 100644
--- a/drivers/staging/rtl8723bs/include/rtw_debug.h
+++ b/drivers/staging/rtl8723bs/include/rtw_debug.h
@@ -267,81 +267,4 @@ void mac_reg_dump(void *sel, struct adapter *adapter);
267void bb_reg_dump(void *sel, struct adapter *adapter); 267void bb_reg_dump(void *sel, struct adapter *adapter);
268void rf_reg_dump(void *sel, struct adapter *adapter); 268void rf_reg_dump(void *sel, struct adapter *adapter);
269 269
270#ifdef PROC_DEBUG
271ssize_t proc_set_write_reg(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
272int proc_get_read_reg(struct seq_file *m, void *v);
273ssize_t proc_set_read_reg(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
274
275int proc_get_fwstate(struct seq_file *m, void *v);
276int proc_get_sec_info(struct seq_file *m, void *v);
277int proc_get_mlmext_state(struct seq_file *m, void *v);
278
279int proc_get_roam_flags(struct seq_file *m, void *v);
280ssize_t proc_set_roam_flags(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
281int proc_get_roam_param(struct seq_file *m, void *v);
282ssize_t proc_set_roam_param(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
283ssize_t proc_set_roam_tgt_addr(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
284
285int proc_get_qos_option(struct seq_file *m, void *v);
286int proc_get_ht_option(struct seq_file *m, void *v);
287int proc_get_rf_info(struct seq_file *m, void *v);
288int proc_get_survey_info(struct seq_file *m, void *v);
289int proc_get_ap_info(struct seq_file *m, void *v);
290int proc_get_adapter_state(struct seq_file *m, void *v);
291int proc_get_trx_info(struct seq_file *m, void *v);
292int proc_get_rate_ctl(struct seq_file *m, void *v);
293ssize_t proc_set_rate_ctl(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
294int proc_get_suspend_resume_info(struct seq_file *m, void *v);
295
296ssize_t proc_set_fwdl_test_case(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
297ssize_t proc_set_wait_hiq_empty(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
298
299int proc_get_all_sta_info(struct seq_file *m, void *v);
300
301int proc_get_rx_signal(struct seq_file *m, void *v);
302ssize_t proc_set_rx_signal(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
303int proc_get_hw_status(struct seq_file *m, void *v);
304
305int proc_get_ht_enable(struct seq_file *m, void *v);
306ssize_t proc_set_ht_enable(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
307
308int proc_get_bw_mode(struct seq_file *m, void *v);
309ssize_t proc_set_bw_mode(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
310
311int proc_get_ampdu_enable(struct seq_file *m, void *v);
312ssize_t proc_set_ampdu_enable(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
313
314int proc_get_rx_ampdu(struct seq_file *m, void *v);
315ssize_t proc_set_rx_ampdu(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
316
317int proc_get_rx_stbc(struct seq_file *m, void *v);
318ssize_t proc_set_rx_stbc(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
319
320int proc_get_en_fwps(struct seq_file *m, void *v);
321ssize_t proc_set_en_fwps(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
322
323/* int proc_get_two_path_rssi(struct seq_file *m, void *v); */
324int proc_get_rssi_disp(struct seq_file *m, void *v);
325ssize_t proc_set_rssi_disp(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
326
327int proc_get_btcoex_dbg(struct seq_file *m, void *v);
328ssize_t proc_set_btcoex_dbg(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
329int proc_get_btcoex_info(struct seq_file *m, void *v);
330
331int proc_get_odm_dbg_comp(struct seq_file *m, void *v);
332ssize_t proc_set_odm_dbg_comp(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
333int proc_get_odm_dbg_level(struct seq_file *m, void *v);
334ssize_t proc_set_odm_dbg_level(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
335
336int proc_get_odm_adaptivity(struct seq_file *m, void *v);
337ssize_t proc_set_odm_adaptivity(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
338
339#ifdef CONFIG_DBG_COUNTER
340int proc_get_rx_logs(struct seq_file *m, void *v);
341int proc_get_tx_logs(struct seq_file *m, void *v);
342int proc_get_int_logs(struct seq_file *m, void *v);
343#endif
344
345#endif /* PROC_DEBUG */
346
347#endif /* __RTW_DEBUG_H__ */ 270#endif /* __RTW_DEBUG_H__ */
diff --git a/drivers/staging/rtl8723bs/include/rtw_mlme.h b/drivers/staging/rtl8723bs/include/rtw_mlme.h
index d3c07d1c36e9..362737b83c3a 100644
--- a/drivers/staging/rtl8723bs/include/rtw_mlme.h
+++ b/drivers/staging/rtl8723bs/include/rtw_mlme.h
@@ -81,15 +81,13 @@ enum dot11AuthAlgrthmNum {
81}; 81};
82 82
83/* Scan type including active and passive scan. */ 83/* Scan type including active and passive scan. */
84typedef enum _RT_SCAN_TYPE 84typedef enum _RT_SCAN_TYPE {
85{
86 SCAN_PASSIVE, 85 SCAN_PASSIVE,
87 SCAN_ACTIVE, 86 SCAN_ACTIVE,
88 SCAN_MIX, 87 SCAN_MIX,
89}RT_SCAN_TYPE, *PRT_SCAN_TYPE; 88}RT_SCAN_TYPE, *PRT_SCAN_TYPE;
90 89
91enum _BAND 90enum _BAND {
92{
93 GHZ24_50 = 0, 91 GHZ24_50 = 0,
94 GHZ_50, 92 GHZ_50,
95 GHZ_24, 93 GHZ_24,
@@ -498,13 +496,13 @@ extern sint rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv);
498extern sint rtw_set_key(struct adapter *adapter, struct security_priv *psecuritypriv, sint keyid, u8 set_tx, bool enqueue); 496extern sint rtw_set_key(struct adapter *adapter, struct security_priv *psecuritypriv, sint keyid, u8 set_tx, bool enqueue);
499extern sint rtw_set_auth(struct adapter *adapter, struct security_priv *psecuritypriv); 497extern sint rtw_set_auth(struct adapter *adapter, struct security_priv *psecuritypriv);
500 498
501__inline static u8 *get_bssid(struct mlme_priv *pmlmepriv) 499static inline u8 *get_bssid(struct mlme_priv *pmlmepriv)
502{ /* if sta_mode:pmlmepriv->cur_network.network.MacAddress => bssid */ 500{ /* if sta_mode:pmlmepriv->cur_network.network.MacAddress => bssid */
503 /* if adhoc_mode:pmlmepriv->cur_network.network.MacAddress => ibss mac address */ 501 /* if adhoc_mode:pmlmepriv->cur_network.network.MacAddress => ibss mac address */
504 return pmlmepriv->cur_network.network.MacAddress; 502 return pmlmepriv->cur_network.network.MacAddress;
505} 503}
506 504
507__inline static sint check_fwstate(struct mlme_priv *pmlmepriv, sint state) 505static inline sint check_fwstate(struct mlme_priv *pmlmepriv, sint state)
508{ 506{
509 if (pmlmepriv->fw_state & state) 507 if (pmlmepriv->fw_state & state)
510 return true; 508 return true;
@@ -512,7 +510,7 @@ __inline static sint check_fwstate(struct mlme_priv *pmlmepriv, sint state)
512 return false; 510 return false;
513} 511}
514 512
515__inline static sint get_fwstate(struct mlme_priv *pmlmepriv) 513static inline sint get_fwstate(struct mlme_priv *pmlmepriv)
516{ 514{
517 return pmlmepriv->fw_state; 515 return pmlmepriv->fw_state;
518} 516}
@@ -524,7 +522,7 @@ __inline static sint get_fwstate(struct mlme_priv *pmlmepriv)
524 * ### NOTE:#### (!!!!) 522 * ### NOTE:#### (!!!!)
525 * MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock 523 * MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock
526 */ 524 */
527__inline static void set_fwstate(struct mlme_priv *pmlmepriv, sint state) 525static inline void set_fwstate(struct mlme_priv *pmlmepriv, sint state)
528{ 526{
529 pmlmepriv->fw_state |= state; 527 pmlmepriv->fw_state |= state;
530 /* FOR HW integration */ 528 /* FOR HW integration */
@@ -533,7 +531,7 @@ __inline static void set_fwstate(struct mlme_priv *pmlmepriv, sint state)
533 } 531 }
534} 532}
535 533
536__inline static void _clr_fwstate_(struct mlme_priv *pmlmepriv, sint state) 534static inline void _clr_fwstate_(struct mlme_priv *pmlmepriv, sint state)
537{ 535{
538 pmlmepriv->fw_state &= ~state; 536 pmlmepriv->fw_state &= ~state;
539 /* FOR HW integration */ 537 /* FOR HW integration */
@@ -546,7 +544,7 @@ __inline static void _clr_fwstate_(struct mlme_priv *pmlmepriv, sint state)
546 * No Limit on the calling context, 544 * No Limit on the calling context,
547 * therefore set it to be the critical section... 545 * therefore set it to be the critical section...
548 */ 546 */
549__inline static void clr_fwstate(struct mlme_priv *pmlmepriv, sint state) 547static inline void clr_fwstate(struct mlme_priv *pmlmepriv, sint state)
550{ 548{
551 spin_lock_bh(&pmlmepriv->lock); 549 spin_lock_bh(&pmlmepriv->lock);
552 if (check_fwstate(pmlmepriv, state) == true) 550 if (check_fwstate(pmlmepriv, state) == true)
@@ -554,7 +552,7 @@ __inline static void clr_fwstate(struct mlme_priv *pmlmepriv, sint state)
554 spin_unlock_bh(&pmlmepriv->lock); 552 spin_unlock_bh(&pmlmepriv->lock);
555} 553}
556 554
557__inline static void set_scanned_network_val(struct mlme_priv *pmlmepriv, sint val) 555static inline void set_scanned_network_val(struct mlme_priv *pmlmepriv, sint val)
558{ 556{
559 spin_lock_bh(&pmlmepriv->lock); 557 spin_lock_bh(&pmlmepriv->lock);
560 pmlmepriv->num_of_scanned = val; 558 pmlmepriv->num_of_scanned = val;
diff --git a/drivers/staging/rtl8723bs/include/rtw_mlme_ext.h b/drivers/staging/rtl8723bs/include/rtw_mlme_ext.h
index 733bb9425448..fd3cf955c9f8 100644
--- a/drivers/staging/rtl8723bs/include/rtw_mlme_ext.h
+++ b/drivers/staging/rtl8723bs/include/rtw_mlme_ext.h
@@ -535,7 +535,7 @@ struct mlme_ext_priv
535}; 535};
536 536
537void init_mlme_default_rate_set(struct adapter *padapter); 537void init_mlme_default_rate_set(struct adapter *padapter);
538int init_mlme_ext_priv(struct adapter *padapter); 538void init_mlme_ext_priv(struct adapter *padapter);
539int init_hw_mlme_ext(struct adapter *padapter); 539int init_hw_mlme_ext(struct adapter *padapter);
540void free_mlme_ext_priv (struct mlme_ext_priv *pmlmeext); 540void free_mlme_ext_priv (struct mlme_ext_priv *pmlmeext);
541extern void init_mlme_ext_timer(struct adapter *padapter); 541extern void init_mlme_ext_timer(struct adapter *padapter);
@@ -650,7 +650,6 @@ void report_del_sta_event(struct adapter *padapter, unsigned char* MacAddr, unsi
650void report_add_sta_event(struct adapter *padapter, unsigned char* MacAddr, int cam_idx); 650void report_add_sta_event(struct adapter *padapter, unsigned char* MacAddr, int cam_idx);
651void report_wmm_edca_update(struct adapter *padapter); 651void report_wmm_edca_update(struct adapter *padapter);
652 652
653void beacon_timing_control(struct adapter *padapter);
654u8 chk_bmc_sleepq_cmd(struct adapter *padapter); 653u8 chk_bmc_sleepq_cmd(struct adapter *padapter);
655extern u8 set_tx_beacon_cmd(struct adapter *padapter); 654extern u8 set_tx_beacon_cmd(struct adapter *padapter);
656unsigned int setup_beacon_frame(struct adapter *padapter, unsigned char *beacon_frame); 655unsigned int setup_beacon_frame(struct adapter *padapter, unsigned char *beacon_frame);
diff --git a/drivers/staging/rtl8723bs/include/rtw_recv.h b/drivers/staging/rtl8723bs/include/rtw_recv.h
index 5de946e66302..012d8f54814f 100644
--- a/drivers/staging/rtl8723bs/include/rtw_recv.h
+++ b/drivers/staging/rtl8723bs/include/rtw_recv.h
@@ -405,7 +405,7 @@ struct recv_buf *rtw_dequeue_recvbuf (struct __queue *queue);
405 405
406void rtw_reordering_ctrl_timeout_handler(struct timer_list *t); 406void rtw_reordering_ctrl_timeout_handler(struct timer_list *t);
407 407
408__inline static u8 *get_rxmem(union recv_frame *precvframe) 408static inline u8 *get_rxmem(union recv_frame *precvframe)
409{ 409{
410 /* always return rx_head... */ 410 /* always return rx_head... */
411 if (precvframe == NULL) 411 if (precvframe == NULL)
@@ -414,7 +414,7 @@ __inline static u8 *get_rxmem(union recv_frame *precvframe)
414 return precvframe->u.hdr.rx_head; 414 return precvframe->u.hdr.rx_head;
415} 415}
416 416
417__inline static u8 *get_recvframe_data(union recv_frame *precvframe) 417static inline u8 *get_recvframe_data(union recv_frame *precvframe)
418{ 418{
419 419
420 /* alwasy return rx_data */ 420 /* alwasy return rx_data */
@@ -425,7 +425,7 @@ __inline static u8 *get_recvframe_data(union recv_frame *precvframe)
425 425
426} 426}
427 427
428__inline static u8 *recvframe_pull(union recv_frame *precvframe, sint sz) 428static inline u8 *recvframe_pull(union recv_frame *precvframe, sint sz)
429{ 429{
430 /* rx_data += sz; move rx_data sz bytes hereafter */ 430 /* rx_data += sz; move rx_data sz bytes hereafter */
431 431
@@ -450,7 +450,7 @@ __inline static u8 *recvframe_pull(union recv_frame *precvframe, sint sz)
450 450
451} 451}
452 452
453__inline static u8 *recvframe_put(union recv_frame *precvframe, sint sz) 453static inline u8 *recvframe_put(union recv_frame *precvframe, sint sz)
454{ 454{
455 /* rx_tai += sz; move rx_tail sz bytes hereafter */ 455 /* rx_tai += sz; move rx_tail sz bytes hereafter */
456 456
@@ -479,7 +479,7 @@ __inline static u8 *recvframe_put(union recv_frame *precvframe, sint sz)
479 479
480 480
481 481
482__inline static u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz) 482static inline u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz)
483{ 483{
484 /* rmv data from rx_tail (by yitsen) */ 484 /* rmv data from rx_tail (by yitsen) */
485 485
@@ -503,7 +503,7 @@ __inline static u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz)
503 503
504} 504}
505 505
506__inline static union recv_frame *rxmem_to_recvframe(u8 *rxmem) 506static inline union recv_frame *rxmem_to_recvframe(u8 *rxmem)
507{ 507{
508 /* due to the design of 2048 bytes alignment of recv_frame, we can reference the union recv_frame */ 508 /* due to the design of 2048 bytes alignment of recv_frame, we can reference the union recv_frame */
509 /* from any given member of recv_frame. */ 509 /* from any given member of recv_frame. */
@@ -513,13 +513,13 @@ __inline static union recv_frame *rxmem_to_recvframe(u8 *rxmem)
513 513
514} 514}
515 515
516__inline static sint get_recvframe_len(union recv_frame *precvframe) 516static inline sint get_recvframe_len(union recv_frame *precvframe)
517{ 517{
518 return precvframe->u.hdr.len; 518 return precvframe->u.hdr.len;
519} 519}
520 520
521 521
522__inline static s32 translate_percentage_to_dbm(u32 SignalStrengthIndex) 522static inline s32 translate_percentage_to_dbm(u32 SignalStrengthIndex)
523{ 523{
524 s32 SignalPower; /* in dBm. */ 524 s32 SignalPower; /* in dBm. */
525 525
diff --git a/drivers/staging/rtl8723bs/include/sta_info.h b/drivers/staging/rtl8723bs/include/sta_info.h
index b9df42d0677e..3acce5630f8e 100644
--- a/drivers/staging/rtl8723bs/include/sta_info.h
+++ b/drivers/staging/rtl8723bs/include/sta_info.h
@@ -348,7 +348,7 @@ struct sta_priv {
348}; 348};
349 349
350 350
351__inline static u32 wifi_mac_hash(u8 *mac) 351static inline u32 wifi_mac_hash(u8 *mac)
352{ 352{
353 u32 x; 353 u32 x;
354 354
diff --git a/drivers/staging/rtl8723bs/include/wifi.h b/drivers/staging/rtl8723bs/include/wifi.h
index 8c50bbb20f3b..2faf83704ff0 100644
--- a/drivers/staging/rtl8723bs/include/wifi.h
+++ b/drivers/staging/rtl8723bs/include/wifi.h
@@ -347,7 +347,7 @@ enum WIFI_REG_DOMAIN {
347 (addr[4] == 0xff) && (addr[5] == 0xff)) ? true : false \ 347 (addr[4] == 0xff) && (addr[5] == 0xff)) ? true : false \
348) 348)
349 349
350__inline static int IS_MCAST(unsigned char *da) 350static inline int IS_MCAST(unsigned char *da)
351{ 351{
352 if ((*da) & 0x01) 352 if ((*da) & 0x01)
353 return true; 353 return true;
@@ -355,20 +355,20 @@ __inline static int IS_MCAST(unsigned char *da)
355 return false; 355 return false;
356} 356}
357 357
358__inline static unsigned char * get_ra(unsigned char *pframe) 358static inline unsigned char * get_ra(unsigned char *pframe)
359{ 359{
360 unsigned char *ra; 360 unsigned char *ra;
361 ra = GetAddr1Ptr(pframe); 361 ra = GetAddr1Ptr(pframe);
362 return ra; 362 return ra;
363} 363}
364__inline static unsigned char * get_ta(unsigned char *pframe) 364static inline unsigned char * get_ta(unsigned char *pframe)
365{ 365{
366 unsigned char *ta; 366 unsigned char *ta;
367 ta = GetAddr2Ptr(pframe); 367 ta = GetAddr2Ptr(pframe);
368 return ta; 368 return ta;
369} 369}
370 370
371__inline static unsigned char * get_da(unsigned char *pframe) 371static inline unsigned char * get_da(unsigned char *pframe)
372{ 372{
373 unsigned char *da; 373 unsigned char *da;
374 unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe); 374 unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
@@ -392,7 +392,7 @@ __inline static unsigned char * get_da(unsigned char *pframe)
392} 392}
393 393
394 394
395__inline static unsigned char * get_sa(unsigned char *pframe) 395static inline unsigned char * get_sa(unsigned char *pframe)
396{ 396{
397 unsigned char *sa; 397 unsigned char *sa;
398 unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe); 398 unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
@@ -415,7 +415,7 @@ __inline static unsigned char * get_sa(unsigned char *pframe)
415 return sa; 415 return sa;
416} 416}
417 417
418__inline static unsigned char * get_hdr_bssid(unsigned char *pframe) 418static inline unsigned char * get_hdr_bssid(unsigned char *pframe)
419{ 419{
420 unsigned char *sa = NULL; 420 unsigned char *sa = NULL;
421 unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe); 421 unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
@@ -439,7 +439,7 @@ __inline static unsigned char * get_hdr_bssid(unsigned char *pframe)
439} 439}
440 440
441 441
442__inline static int IsFrameTypeCtrl(unsigned char *pframe) 442static inline int IsFrameTypeCtrl(unsigned char *pframe)
443{ 443{
444 if (WIFI_CTRL_TYPE == GetFrameType(pframe)) 444 if (WIFI_CTRL_TYPE == GetFrameType(pframe))
445 return true; 445 return true;
diff --git a/drivers/staging/rtl8723bs/include/wlan_bssdef.h b/drivers/staging/rtl8723bs/include/wlan_bssdef.h
index 88890b1c3c4c..723fc5b546ef 100644
--- a/drivers/staging/rtl8723bs/include/wlan_bssdef.h
+++ b/drivers/staging/rtl8723bs/include/wlan_bssdef.h
@@ -223,7 +223,7 @@ struct wlan_bssid_ex {
223 u8 IEs[MAX_IE_SZ]; /* timestamp, beacon interval, and capability information) */ 223 u8 IEs[MAX_IE_SZ]; /* timestamp, beacon interval, and capability information) */
224} __packed; 224} __packed;
225 225
226__inline static uint get_wlan_bssid_ex_sz(struct wlan_bssid_ex *bss) 226static inline uint get_wlan_bssid_ex_sz(struct wlan_bssid_ex *bss)
227{ 227{
228 return (sizeof(struct wlan_bssid_ex) - MAX_IE_SZ + bss->IELength); 228 return (sizeof(struct wlan_bssid_ex) - MAX_IE_SZ + bss->IELength);
229} 229}
diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
index 9bc685632651..f819abb756dc 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
@@ -19,8 +19,6 @@
19#define RTW_MAX_REMAIN_ON_CHANNEL_DURATION 5000 /* ms */ 19#define RTW_MAX_REMAIN_ON_CHANNEL_DURATION 5000 /* ms */
20#define RTW_MAX_NUM_PMKIDS 4 20#define RTW_MAX_NUM_PMKIDS 4
21 21
22#define RTW_CH_MAX_2G_CHANNEL 14 /* Max channel in 2G band */
23
24static const u32 rtw_cipher_suites[] = { 22static const u32 rtw_cipher_suites[] = {
25 WLAN_CIPHER_SUITE_WEP40, 23 WLAN_CIPHER_SUITE_WEP40,
26 WLAN_CIPHER_SUITE_WEP104, 24 WLAN_CIPHER_SUITE_WEP104,
@@ -2024,8 +2022,6 @@ static int cfg80211_rtw_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
2024 2022
2025 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 2023 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
2026 2024
2027 padapter->mlmepriv.not_indic_disco = true;
2028
2029 old_type = rtw_wdev->iftype; 2025 old_type = rtw_wdev->iftype;
2030 2026
2031 rtw_set_to_roam(padapter, 0); 2027 rtw_set_to_roam(padapter, 0);
@@ -2047,8 +2043,6 @@ static int cfg80211_rtw_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
2047 } 2043 }
2048 2044
2049leave_ibss: 2045leave_ibss:
2050 padapter->mlmepriv.not_indic_disco = false;
2051
2052 return 0; 2046 return 0;
2053} 2047}
2054 2048
@@ -2246,8 +2240,6 @@ static int cfg80211_rtw_disconnect(struct wiphy *wiphy, struct net_device *ndev,
2246 2240
2247 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 2241 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
2248 2242
2249 padapter->mlmepriv.not_indic_disco = true;
2250
2251 rtw_set_to_roam(padapter, 0); 2243 rtw_set_to_roam(padapter, 0);
2252 2244
2253 rtw_scan_abort(padapter); 2245 rtw_scan_abort(padapter);
@@ -2261,8 +2253,6 @@ static int cfg80211_rtw_disconnect(struct wiphy *wiphy, struct net_device *ndev,
2261 rtw_free_assoc_resources(padapter, 1); 2253 rtw_free_assoc_resources(padapter, 1);
2262 rtw_pwr_wakeup(padapter); 2254 rtw_pwr_wakeup(padapter);
2263 2255
2264 padapter->mlmepriv.not_indic_disco = false;
2265
2266 DBG_871X(FUNC_NDEV_FMT" return 0\n", FUNC_NDEV_ARG(ndev)); 2256 DBG_871X(FUNC_NDEV_FMT" return 0\n", FUNC_NDEV_ARG(ndev));
2267 return 0; 2257 return 0;
2268} 2258}
diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
index 99e6b1028f71..d1b199e3e5bd 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
@@ -21,13 +21,10 @@
21#define RATE_COUNT 4 21#define RATE_COUNT 4
22 22
23/* combo scan */ 23/* combo scan */
24#define WEXT_CSCAN_AMOUNT 9
25#define WEXT_CSCAN_BUF_LEN 360
26#define WEXT_CSCAN_HEADER "CSCAN S\x01\x00\x00S\x00" 24#define WEXT_CSCAN_HEADER "CSCAN S\x01\x00\x00S\x00"
27#define WEXT_CSCAN_HEADER_SIZE 12 25#define WEXT_CSCAN_HEADER_SIZE 12
28#define WEXT_CSCAN_SSID_SECTION 'S' 26#define WEXT_CSCAN_SSID_SECTION 'S'
29#define WEXT_CSCAN_CHANNEL_SECTION 'C' 27#define WEXT_CSCAN_CHANNEL_SECTION 'C'
30#define WEXT_CSCAN_NPROBE_SECTION 'N'
31#define WEXT_CSCAN_ACTV_DWELL_SECTION 'A' 28#define WEXT_CSCAN_ACTV_DWELL_SECTION 'A'
32#define WEXT_CSCAN_PASV_DWELL_SECTION 'P' 29#define WEXT_CSCAN_PASV_DWELL_SECTION 'P'
33#define WEXT_CSCAN_HOME_DWELL_SECTION 'H' 30#define WEXT_CSCAN_HOME_DWELL_SECTION 'H'
@@ -215,8 +212,6 @@ static char *translate_scan(struct adapter *padapter,
215 } else if (ht_cap) { 212 } else if (ht_cap) {
216 if (mcs_rate&0x8000) { /* MCS15 */ 213 if (mcs_rate&0x8000) { /* MCS15 */
217 max_rate = (bw_40MHz) ? ((short_GI)?300:270):((short_GI)?144:130); 214 max_rate = (bw_40MHz) ? ((short_GI)?300:270):((short_GI)?144:130);
218 } else if (mcs_rate&0x0080) { /* MCS7 */
219 max_rate = (bw_40MHz) ? ((short_GI)?150:135):((short_GI)?72:65);
220 } else { /* default MCS7 */ 215 } else { /* default MCS7 */
221 /* DBG_871X("wx_get_scan, mcs_rate_bitmap = 0x%x\n", mcs_rate); */ 216 /* DBG_871X("wx_get_scan, mcs_rate_bitmap = 0x%x\n", mcs_rate); */
222 max_rate = (bw_40MHz) ? ((short_GI)?150:135):((short_GI)?72:65); 217 max_rate = (bw_40MHz) ? ((short_GI)?150:135):((short_GI)?72:65);
@@ -4912,7 +4907,6 @@ static int rtw_ioctl_wext_private(struct net_device *dev, union iwreq_data *wrq_
4912 s32 k; 4907 s32 k;
4913 const iw_handler *priv; /* Private ioctl */ 4908 const iw_handler *priv; /* Private ioctl */
4914 const struct iw_priv_args *priv_args; /* Private ioctl description */ 4909 const struct iw_priv_args *priv_args; /* Private ioctl description */
4915 u32 num_priv; /* Number of ioctl */
4916 u32 num_priv_args; /* Number of descriptions */ 4910 u32 num_priv_args; /* Number of descriptions */
4917 iw_handler handler; 4911 iw_handler handler;
4918 int temp; 4912 int temp;
@@ -4948,7 +4942,6 @@ static int rtw_ioctl_wext_private(struct net_device *dev, union iwreq_data *wrq_
4948 4942
4949 priv = rtw_private_handler; 4943 priv = rtw_private_handler;
4950 priv_args = rtw_private_args; 4944 priv_args = rtw_private_args;
4951 num_priv = ARRAY_SIZE(rtw_private_handler);
4952 num_priv_args = ARRAY_SIZE(rtw_private_args); 4945 num_priv_args = ARRAY_SIZE(rtw_private_args);
4953 4946
4954 if (num_priv_args == 0) { 4947 if (num_priv_args == 0) {
diff --git a/drivers/staging/rtl8723bs/os_dep/os_intfs.c b/drivers/staging/rtl8723bs/os_dep/os_intfs.c
index 544e799d0a03..ec3a75485233 100644
--- a/drivers/staging/rtl8723bs/os_dep/os_intfs.c
+++ b/drivers/staging/rtl8723bs/os_dep/os_intfs.c
@@ -239,9 +239,6 @@ static void loadparam(struct adapter *padapter, _nic_hdl pnetdev)
239 registry_par->channel = (u8)rtw_channel; 239 registry_par->channel = (u8)rtw_channel;
240 registry_par->wireless_mode = (u8)rtw_wireless_mode; 240 registry_par->wireless_mode = (u8)rtw_wireless_mode;
241 241
242 if (registry_par->channel > 14)
243 registry_par->channel = 1;
244
245 registry_par->vrtl_carrier_sense = (u8)rtw_vrtl_carrier_sense ; 242 registry_par->vrtl_carrier_sense = (u8)rtw_vrtl_carrier_sense ;
246 registry_par->vcs_type = (u8)rtw_vcs_type; 243 registry_par->vcs_type = (u8)rtw_vcs_type;
247 registry_par->rts_thresh = (u16)rtw_rts_thresh; 244 registry_par->rts_thresh = (u16)rtw_rts_thresh;
@@ -448,12 +445,6 @@ static int rtw_ndev_notifier_call(struct notifier_block *nb, unsigned long state
448 445
449 DBG_871X_LEVEL(_drv_info_, FUNC_NDEV_FMT " state:%lu\n", FUNC_NDEV_ARG(dev), state); 446 DBG_871X_LEVEL(_drv_info_, FUNC_NDEV_FMT " state:%lu\n", FUNC_NDEV_ARG(dev), state);
450 447
451 switch (state) {
452 case NETDEV_CHANGENAME:
453 rtw_adapter_proc_replace(dev);
454 break;
455 }
456
457 return NOTIFY_DONE; 448 return NOTIFY_DONE;
458} 449}
459 450
@@ -478,7 +469,6 @@ static int rtw_ndev_init(struct net_device *dev)
478 469
479 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(adapter)); 470 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(adapter));
480 strncpy(adapter->old_ifname, dev->name, IFNAMSIZ); 471 strncpy(adapter->old_ifname, dev->name, IFNAMSIZ);
481 rtw_adapter_proc_init(dev);
482 472
483 return 0; 473 return 0;
484} 474}
@@ -488,7 +478,6 @@ static void rtw_ndev_uninit(struct net_device *dev)
488 struct adapter *adapter = rtw_netdev_priv(dev); 478 struct adapter *adapter = rtw_netdev_priv(dev);
489 479
490 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(adapter)); 480 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(adapter));
491 rtw_adapter_proc_deinit(dev);
492} 481}
493 482
494static const struct net_device_ops rtw_netdev_ops = { 483static const struct net_device_ops rtw_netdev_ops = {
@@ -768,11 +757,7 @@ u8 rtw_init_drv_sw(struct adapter *padapter)
768 goto exit; 757 goto exit;
769 } 758 }
770 759
771 if (init_mlme_ext_priv(padapter) == _FAIL) { 760 init_mlme_ext_priv(padapter);
772 RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init mlme_ext_priv\n"));
773 ret8 = _FAIL;
774 goto exit;
775 }
776 761
777 if (_rtw_init_xmit_priv(&padapter->xmitpriv, padapter) == _FAIL) { 762 if (_rtw_init_xmit_priv(&padapter->xmitpriv, padapter) == _FAIL) {
778 DBG_871X("Can't _rtw_init_xmit_priv\n"); 763 DBG_871X("Can't _rtw_init_xmit_priv\n");
@@ -1361,13 +1346,12 @@ void rtw_suspend_wow(struct adapter *padapter)
1361#endif /* ifdef CONFIG_WOWLAN */ 1346#endif /* ifdef CONFIG_WOWLAN */
1362 1347
1363#ifdef CONFIG_AP_WOWLAN 1348#ifdef CONFIG_AP_WOWLAN
1364int rtw_suspend_ap_wow(struct adapter *padapter) 1349void rtw_suspend_ap_wow(struct adapter *padapter)
1365{ 1350{
1366 u8 ch, bw, offset; 1351 u8 ch, bw, offset;
1367 struct net_device *pnetdev = padapter->pnetdev; 1352 struct net_device *pnetdev = padapter->pnetdev;
1368 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); 1353 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1369 struct wowlan_ioctl_param poidparam; 1354 struct wowlan_ioctl_param poidparam;
1370 int ret = _SUCCESS;
1371 1355
1372 DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter)); 1356 DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
1373 1357
@@ -1409,7 +1393,6 @@ int rtw_suspend_ap_wow(struct adapter *padapter)
1409 rtw_set_ps_mode(padapter, PS_MODE_MIN, 0, 0, "AP-WOWLAN"); 1393 rtw_set_ps_mode(padapter, PS_MODE_MIN, 0, 0, "AP-WOWLAN");
1410 1394
1411 DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter)); 1395 DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
1412 return ret;
1413} 1396}
1414#endif /* ifdef CONFIG_AP_WOWLAN */ 1397#endif /* ifdef CONFIG_AP_WOWLAN */
1415 1398
diff --git a/drivers/staging/rtl8723bs/os_dep/osdep_service.c b/drivers/staging/rtl8723bs/os_dep/osdep_service.c
index 62fdd24ba427..25a80041ce87 100644
--- a/drivers/staging/rtl8723bs/os_dep/osdep_service.c
+++ b/drivers/staging/rtl8723bs/os_dep/osdep_service.c
@@ -318,13 +318,9 @@ error:
318 318
319void rtw_buf_free(u8 **buf, u32 *buf_len) 319void rtw_buf_free(u8 **buf, u32 *buf_len)
320{ 320{
321 u32 ori_len;
322
323 if (!buf || !buf_len) 321 if (!buf || !buf_len)
324 return; 322 return;
325 323
326 ori_len = *buf_len;
327
328 if (*buf) { 324 if (*buf) {
329 *buf_len = 0; 325 *buf_len = 0;
330 kfree(*buf); 326 kfree(*buf);
diff --git a/drivers/staging/rtl8723bs/os_dep/rtw_proc.c b/drivers/staging/rtl8723bs/os_dep/rtw_proc.c
deleted file mode 100644
index 5f950fda48ea..000000000000
--- a/drivers/staging/rtl8723bs/os_dep/rtw_proc.c
+++ /dev/null
@@ -1,779 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/******************************************************************************
3 *
4 * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.
5 *
6 ******************************************************************************/
7
8#include <drv_types.h>
9#include <rtw_debug.h>
10#include "rtw_proc.h"
11
12#ifdef PROC_DEBUG
13
14static struct proc_dir_entry *rtw_proc;
15
16#define RTW_PROC_NAME "rtl8723bs"
17
18#define get_proc_net init_net.proc_net
19
20inline struct proc_dir_entry *rtw_proc_create_dir(const char *name, struct proc_dir_entry *parent, void *data)
21{
22 struct proc_dir_entry *entry;
23
24 entry = proc_mkdir_data(name, S_IRUGO|S_IXUGO, parent, data);
25
26 return entry;
27}
28
29inline struct proc_dir_entry *rtw_proc_create_entry(const char *name, struct proc_dir_entry *parent,
30 const struct file_operations *fops, void *data)
31{
32 struct proc_dir_entry *entry;
33
34 entry = proc_create_data(name, S_IFREG|S_IRUGO, parent, fops, data);
35
36 return entry;
37}
38
39static int proc_get_dummy(struct seq_file *m, void *v)
40{
41 return 0;
42}
43
44static int proc_get_drv_version(struct seq_file *m, void *v)
45{
46 dump_drv_version(m);
47 return 0;
48}
49
50static int proc_get_log_level(struct seq_file *m, void *v)
51{
52 dump_log_level(m);
53 return 0;
54}
55
56static ssize_t proc_set_log_level(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
57{
58 char tmp[32];
59 int log_level;
60
61 if (count < 1)
62 return -EINVAL;
63
64 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
65 sscanf(tmp, "%d ", &log_level);
66 if (log_level >= _drv_always_ && log_level <= _drv_debug_) {
67 GlobalDebugLevel = log_level;
68 printk("%d\n", GlobalDebugLevel);
69 }
70 } else {
71 return -EFAULT;
72 }
73
74 return count;
75}
76
77/*
78* rtw_drv_proc:
79* init/deinit when register/unregister driver
80*/
81static const struct rtw_proc_hdl drv_proc_hdls[] = {
82 {"ver_info", proc_get_drv_version, NULL},
83 {"log_level", proc_get_log_level, proc_set_log_level},
84};
85
86static const int drv_proc_hdls_num = sizeof(drv_proc_hdls) / sizeof(struct rtw_proc_hdl);
87
88static int rtw_drv_proc_open(struct inode *inode, struct file *file)
89{
90 /* struct net_device *dev = proc_get_parent_data(inode); */
91 ssize_t index = (ssize_t)PDE_DATA(inode);
92 const struct rtw_proc_hdl *hdl = drv_proc_hdls+index;
93
94 return single_open(file, hdl->show, NULL);
95}
96
97static ssize_t rtw_drv_proc_write(struct file *file, const char __user *buffer, size_t count, loff_t *pos)
98{
99 ssize_t index = (ssize_t)PDE_DATA(file_inode(file));
100 const struct rtw_proc_hdl *hdl = drv_proc_hdls+index;
101 ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *, void *) = hdl->write;
102
103 if (write)
104 return write(file, buffer, count, pos, NULL);
105
106 return -EROFS;
107}
108
109static const struct file_operations rtw_drv_proc_fops = {
110 .owner = THIS_MODULE,
111 .open = rtw_drv_proc_open,
112 .read = seq_read,
113 .llseek = seq_lseek,
114 .release = single_release,
115 .write = rtw_drv_proc_write,
116};
117
118int rtw_drv_proc_init(void)
119{
120 int ret = _FAIL;
121 ssize_t i;
122 struct proc_dir_entry *entry = NULL;
123
124 if (rtw_proc) {
125 rtw_warn_on(1);
126 goto exit;
127 }
128
129 rtw_proc = rtw_proc_create_dir(RTW_PROC_NAME, get_proc_net, NULL);
130
131 if (!rtw_proc) {
132 rtw_warn_on(1);
133 goto exit;
134 }
135
136 for (i = 0; i < drv_proc_hdls_num; i++) {
137 entry = rtw_proc_create_entry(drv_proc_hdls[i].name, rtw_proc, &rtw_drv_proc_fops, (void *)i);
138 if (!entry) {
139 rtw_warn_on(1);
140 goto exit;
141 }
142 }
143
144 ret = _SUCCESS;
145
146exit:
147 return ret;
148}
149
150void rtw_drv_proc_deinit(void)
151{
152 int i;
153
154 if (!rtw_proc)
155 return;
156
157 for (i = 0; i < drv_proc_hdls_num; i++)
158 remove_proc_entry(drv_proc_hdls[i].name, rtw_proc);
159
160 remove_proc_entry(RTW_PROC_NAME, get_proc_net);
161 rtw_proc = NULL;
162}
163
164static int proc_get_sd_f0_reg_dump(struct seq_file *m, void *v)
165{
166 struct net_device *dev = m->private;
167 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
168
169 sd_f0_reg_dump(m, adapter);
170
171 return 0;
172}
173
174static int proc_get_mac_reg_dump(struct seq_file *m, void *v)
175{
176 struct net_device *dev = m->private;
177 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
178
179 mac_reg_dump(m, adapter);
180
181 return 0;
182}
183
184static int proc_get_bb_reg_dump(struct seq_file *m, void *v)
185{
186 struct net_device *dev = m->private;
187 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
188
189 bb_reg_dump(m, adapter);
190
191 return 0;
192}
193
194static int proc_get_rf_reg_dump(struct seq_file *m, void *v)
195{
196 struct net_device *dev = m->private;
197 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
198
199 rf_reg_dump(m, adapter);
200
201 return 0;
202}
203static int proc_get_linked_info_dump(struct seq_file *m, void *v)
204{
205 struct net_device *dev = m->private;
206 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
207
208 if (padapter)
209 DBG_871X_SEL_NL(m, "linked_info_dump :%s\n", (padapter->bLinkInfoDump)?"enable":"disable");
210
211 return 0;
212}
213
214static ssize_t proc_set_linked_info_dump(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
215{
216 struct net_device *dev = data;
217 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
218
219 char tmp[2];
220 int mode = 0;
221
222 if (count < 1)
223 return -EFAULT;
224
225 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
226 if (padapter) {
227 /* padapter->bLinkInfoDump = mode; */
228 /* DBG_871X("linked_info_dump =%s\n", (padapter->bLinkInfoDump)?"enable":"disable"); */
229 linked_info_dump(padapter, mode);
230 }
231
232 }
233
234 return count;
235
236}
237
238static int proc_get_rx_info(struct seq_file *m, void *v)
239{
240 struct net_device *dev = m->private;
241 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
242 struct dvobj_priv *psdpriv = padapter->dvobj;
243 struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
244
245 /* Counts of packets whose seq_num is less than preorder_ctrl->indicate_seq, Ex delay, retransmission, redundant packets and so on */
246 DBG_871X_SEL_NL(m,"Counts of Packets Whose Seq_Num Less Than Reorder Control Seq_Num: %llu\n", (unsigned long long)pdbgpriv->dbg_rx_ampdu_drop_count);
247 /* How many times the Rx Reorder Timer is triggered. */
248 DBG_871X_SEL_NL(m,"Rx Reorder Time-out Trigger Counts: %llu\n", (unsigned long long)pdbgpriv->dbg_rx_ampdu_forced_indicate_count);
249 /* Total counts of packets loss */
250 DBG_871X_SEL_NL(m,"Rx Packet Loss Counts: %llu\n", (unsigned long long)pdbgpriv->dbg_rx_ampdu_loss_count);
251 DBG_871X_SEL_NL(m,"Duplicate Management Frame Drop Count: %llu\n", (unsigned long long)pdbgpriv->dbg_rx_dup_mgt_frame_drop_count);
252 DBG_871X_SEL_NL(m,"AMPDU BA window shift Count: %llu\n", (unsigned long long)pdbgpriv->dbg_rx_ampdu_window_shift_cnt);
253 return 0;
254}
255
256
257static ssize_t proc_reset_rx_info(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
258{
259 struct net_device *dev = data;
260 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
261 struct dvobj_priv *psdpriv = padapter->dvobj;
262 struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
263 char cmd[32];
264 if (buffer && !copy_from_user(cmd, buffer, sizeof(cmd))) {
265 if ('0' == cmd[0]) {
266 pdbgpriv->dbg_rx_ampdu_drop_count = 0;
267 pdbgpriv->dbg_rx_ampdu_forced_indicate_count = 0;
268 pdbgpriv->dbg_rx_ampdu_loss_count = 0;
269 pdbgpriv->dbg_rx_dup_mgt_frame_drop_count = 0;
270 pdbgpriv->dbg_rx_ampdu_window_shift_cnt = 0;
271 }
272 }
273
274 return count;
275}
276
277static int proc_get_cam(struct seq_file *m, void *v)
278{
279 return 0;
280}
281
282static ssize_t proc_set_cam(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
283{
284 struct net_device *dev = data;
285 struct adapter *adapter;
286
287 char tmp[32];
288 char cmd[5];
289 u8 id;
290
291 adapter = (struct adapter *)rtw_netdev_priv(dev);
292 if (!adapter)
293 return -EFAULT;
294
295 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
296
297 /* c <id>: clear specific cam entry */
298 /* wfc <id>: write specific cam entry from cam cache */
299
300 int num = sscanf(tmp, "%4s %hhu", cmd, &id);
301
302 if (num < 2)
303 return count;
304 if (id >= TOTAL_CAM_ENTRY)
305 return -EINVAL;
306
307 if (strcmp("c", cmd) == 0) {
308 _clear_cam_entry(adapter, id);
309 adapter->securitypriv.hw_decrypted = false; /* temporarily set this for TX path to use SW enc */
310 } else if (strcmp("wfc", cmd) == 0) {
311 write_cam_from_cache(adapter, id);
312 }
313 }
314
315 return count;
316}
317
318static int proc_get_cam_cache(struct seq_file *m, void *v)
319{
320 struct net_device *dev = m->private;
321 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
322 struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
323 u8 i;
324
325 DBG_871X_SEL_NL(m, "cam bitmap:0x%016llx\n", dvobj->cam_ctl.bitmap);
326
327 DBG_871X_SEL_NL(m, "%-2s %-6s %-17s %-32s %-3s %-7s"
328 /* %-2s %-2s %-4s %-5s" */
329 "\n"
330 , "id", "ctrl", "addr", "key", "kid", "type"
331 /* "MK", "GK", "MFB", "valid" */
332 );
333
334 for (i = 0; i < 32; i++) {
335 if (dvobj->cam_cache[i].ctrl != 0)
336 DBG_871X_SEL_NL(m, "%2u 0x%04x "MAC_FMT" "KEY_FMT" %3u %-7s"
337 /* %2u %2u 0x%02x %5u" */
338 "\n", i
339 , dvobj->cam_cache[i].ctrl
340 , MAC_ARG(dvobj->cam_cache[i].mac)
341 , KEY_ARG(dvobj->cam_cache[i].key)
342 , (dvobj->cam_cache[i].ctrl)&0x03
343 , security_type_str(((dvobj->cam_cache[i].ctrl)>>2)&0x07)
344 /* ((dvobj->cam_cache[i].ctrl)>>5)&0x01 */
345 /* ((dvobj->cam_cache[i].ctrl)>>6)&0x01 */
346 /* ((dvobj->cam_cache[i].ctrl)>>8)&0x7f */
347 /* ((dvobj->cam_cache[i].ctrl)>>15)&0x01 */
348 );
349 }
350
351 return 0;
352}
353
354/*
355* rtw_adapter_proc:
356* init/deinit when register/unregister net_device
357*/
358static const struct rtw_proc_hdl adapter_proc_hdls[] = {
359 {"write_reg", proc_get_dummy, proc_set_write_reg},
360 {"read_reg", proc_get_read_reg, proc_set_read_reg},
361 {"fwstate", proc_get_fwstate, NULL},
362 {"sec_info", proc_get_sec_info, NULL},
363 {"mlmext_state", proc_get_mlmext_state, NULL},
364 {"qos_option", proc_get_qos_option, NULL},
365 {"ht_option", proc_get_ht_option, NULL},
366 {"rf_info", proc_get_rf_info, NULL},
367 {"survey_info", proc_get_survey_info, NULL},
368 {"ap_info", proc_get_ap_info, NULL},
369 {"adapter_state", proc_get_adapter_state, NULL},
370 {"trx_info", proc_get_trx_info, NULL},
371 {"rate_ctl", proc_get_rate_ctl, proc_set_rate_ctl},
372 {"cam", proc_get_cam, proc_set_cam},
373 {"cam_cache", proc_get_cam_cache, NULL},
374 {"suspend_info", proc_get_suspend_resume_info, NULL},
375 {"rx_info", proc_get_rx_info, proc_reset_rx_info},
376
377 {"roam_flags", proc_get_roam_flags, proc_set_roam_flags},
378 {"roam_param", proc_get_roam_param, proc_set_roam_param},
379 {"roam_tgt_addr", proc_get_dummy, proc_set_roam_tgt_addr},
380
381 {"sd_f0_reg_dump", proc_get_sd_f0_reg_dump, NULL},
382
383 {"fwdl_test_case", proc_get_dummy, proc_set_fwdl_test_case},
384 {"wait_hiq_empty", proc_get_dummy, proc_set_wait_hiq_empty},
385
386 {"mac_reg_dump", proc_get_mac_reg_dump, NULL},
387 {"bb_reg_dump", proc_get_bb_reg_dump, NULL},
388 {"rf_reg_dump", proc_get_rf_reg_dump, NULL},
389
390 {"all_sta_info", proc_get_all_sta_info, NULL},
391
392 {"rx_signal", proc_get_rx_signal, proc_set_rx_signal},
393 {"hw_info", proc_get_hw_status, NULL},
394
395 {"ht_enable", proc_get_ht_enable, proc_set_ht_enable},
396 {"bw_mode", proc_get_bw_mode, proc_set_bw_mode},
397 {"ampdu_enable", proc_get_ampdu_enable, proc_set_ampdu_enable},
398 {"rx_stbc", proc_get_rx_stbc, proc_set_rx_stbc},
399 {"rx_ampdu", proc_get_rx_ampdu, proc_set_rx_ampdu},
400
401 {"en_fwps", proc_get_en_fwps, proc_set_en_fwps},
402
403 /* path_rssi", proc_get_two_path_rssi, NULL}, */
404 {"rssi_disp", proc_get_rssi_disp, proc_set_rssi_disp},
405
406 {"btcoex_dbg", proc_get_btcoex_dbg, proc_set_btcoex_dbg},
407 {"btcoex", proc_get_btcoex_info, NULL},
408
409 {"linked_info_dump", proc_get_linked_info_dump, proc_set_linked_info_dump},
410#ifdef CONFIG_DBG_COUNTER
411 {"rx_logs", proc_get_rx_logs, NULL},
412 {"tx_logs", proc_get_tx_logs, NULL},
413 {"int_logs", proc_get_int_logs, NULL},
414#endif
415};
416
417static const int adapter_proc_hdls_num = sizeof(adapter_proc_hdls) / sizeof(struct rtw_proc_hdl);
418
419static int rtw_adapter_proc_open(struct inode *inode, struct file *file)
420{
421 ssize_t index = (ssize_t)PDE_DATA(inode);
422 const struct rtw_proc_hdl *hdl = adapter_proc_hdls+index;
423
424 return single_open(file, hdl->show, proc_get_parent_data(inode));
425}
426
427static ssize_t rtw_adapter_proc_write(struct file *file, const char __user *buffer, size_t count, loff_t *pos)
428{
429 ssize_t index = (ssize_t)PDE_DATA(file_inode(file));
430 const struct rtw_proc_hdl *hdl = adapter_proc_hdls+index;
431 ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *, void *) = hdl->write;
432
433 if (write)
434 return write(file, buffer, count, pos, ((struct seq_file *)file->private_data)->private);
435
436 return -EROFS;
437}
438
439static const struct file_operations rtw_adapter_proc_fops = {
440 .owner = THIS_MODULE,
441 .open = rtw_adapter_proc_open,
442 .read = seq_read,
443 .llseek = seq_lseek,
444 .release = single_release,
445 .write = rtw_adapter_proc_write,
446};
447
448int proc_get_odm_dbg_comp(struct seq_file *m, void *v)
449{
450 struct net_device *dev = m->private;
451 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
452
453 rtw_odm_dbg_comp_msg(m, adapter);
454
455 return 0;
456}
457
458ssize_t proc_set_odm_dbg_comp(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
459{
460 struct net_device *dev = data;
461 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
462 char tmp[32];
463
464 u64 dbg_comp;
465
466 if (count < 1)
467 return -EFAULT;
468
469 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
470
471 int num = sscanf(tmp, "%llx", &dbg_comp);
472
473 if (num != 1)
474 return count;
475
476 rtw_odm_dbg_comp_set(adapter, dbg_comp);
477 }
478
479 return count;
480}
481
482int proc_get_odm_dbg_level(struct seq_file *m, void *v)
483{
484 struct net_device *dev = m->private;
485 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
486
487 rtw_odm_dbg_level_msg(m, adapter);
488
489 return 0;
490}
491
492ssize_t proc_set_odm_dbg_level(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
493{
494 struct net_device *dev = data;
495 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
496 char tmp[32];
497
498 u32 dbg_level;
499
500 if (count < 1)
501 return -EFAULT;
502
503 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
504
505 int num = sscanf(tmp, "%u", &dbg_level);
506
507 if (num != 1)
508 return count;
509
510 rtw_odm_dbg_level_set(adapter, dbg_level);
511 }
512
513 return count;
514}
515
516static int proc_get_odm_ability(struct seq_file *m, void *v)
517{
518 struct net_device *dev = m->private;
519 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
520
521 rtw_odm_ability_msg(m, adapter);
522
523 return 0;
524}
525
526static ssize_t proc_set_odm_ability(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
527{
528 struct net_device *dev = data;
529 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(dev);
530 char tmp[32];
531
532 u32 ability;
533
534 if (count < 1)
535 return -EFAULT;
536
537 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
538
539 int num = sscanf(tmp, "%x", &ability);
540
541 if (num != 1)
542 return count;
543
544 rtw_odm_ability_set(adapter, ability);
545 }
546
547 return count;
548}
549
550int proc_get_odm_adaptivity(struct seq_file *m, void *v)
551{
552 struct net_device *dev = m->private;
553 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
554
555 rtw_odm_adaptivity_parm_msg(m, padapter);
556
557 return 0;
558}
559
560ssize_t proc_set_odm_adaptivity(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data)
561{
562 struct net_device *dev = data;
563 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
564 char tmp[32];
565 u32 TH_L2H_ini;
566 s8 TH_EDCCA_HL_diff;
567 u32 IGI_Base;
568 int ForceEDCCA;
569 u8 AdapEn_RSSI;
570 u8 IGI_LowerBound;
571
572 if (count < 1)
573 return -EFAULT;
574
575 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
576
577 int num = sscanf(tmp, "%x %hhd %x %d %hhu %hhu",
578 &TH_L2H_ini, &TH_EDCCA_HL_diff, &IGI_Base, &ForceEDCCA, &AdapEn_RSSI, &IGI_LowerBound);
579
580 if (num != 6)
581 return count;
582
583 rtw_odm_adaptivity_parm_set(padapter, (s8)TH_L2H_ini, TH_EDCCA_HL_diff, (s8)IGI_Base, (bool)ForceEDCCA, AdapEn_RSSI, IGI_LowerBound);
584 }
585
586 return count;
587}
588
589/*
590* rtw_odm_proc:
591* init/deinit when register/unregister net_device, along with rtw_adapter_proc
592*/
593static const struct rtw_proc_hdl odm_proc_hdls[] = {
594 {"dbg_comp", proc_get_odm_dbg_comp, proc_set_odm_dbg_comp},
595 {"dbg_level", proc_get_odm_dbg_level, proc_set_odm_dbg_level},
596 {"ability", proc_get_odm_ability, proc_set_odm_ability},
597 {"adaptivity", proc_get_odm_adaptivity, proc_set_odm_adaptivity},
598};
599
600static const int odm_proc_hdls_num = sizeof(odm_proc_hdls) / sizeof(struct rtw_proc_hdl);
601
602static int rtw_odm_proc_open(struct inode *inode, struct file *file)
603{
604 ssize_t index = (ssize_t)PDE_DATA(inode);
605 const struct rtw_proc_hdl *hdl = odm_proc_hdls+index;
606
607 return single_open(file, hdl->show, proc_get_parent_data(inode));
608}
609
610static ssize_t rtw_odm_proc_write(struct file *file, const char __user *buffer, size_t count, loff_t *pos)
611{
612 ssize_t index = (ssize_t)PDE_DATA(file_inode(file));
613 const struct rtw_proc_hdl *hdl = odm_proc_hdls+index;
614 ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *, void *) = hdl->write;
615
616 if (write)
617 return write(file, buffer, count, pos, ((struct seq_file *)file->private_data)->private);
618
619 return -EROFS;
620}
621
622static const struct file_operations rtw_odm_proc_fops = {
623 .owner = THIS_MODULE,
624 .open = rtw_odm_proc_open,
625 .read = seq_read,
626 .llseek = seq_lseek,
627 .release = single_release,
628 .write = rtw_odm_proc_write,
629};
630
631static struct proc_dir_entry *rtw_odm_proc_init(struct net_device *dev)
632{
633 struct proc_dir_entry *dir_odm = NULL;
634 struct proc_dir_entry *entry = NULL;
635 struct adapter *adapter = rtw_netdev_priv(dev);
636 ssize_t i;
637
638 if (!adapter->dir_dev) {
639 rtw_warn_on(1);
640 goto exit;
641 }
642
643 if (adapter->dir_odm) {
644 rtw_warn_on(1);
645 goto exit;
646 }
647
648 dir_odm = rtw_proc_create_dir("odm", adapter->dir_dev, dev);
649 if (!dir_odm) {
650 rtw_warn_on(1);
651 goto exit;
652 }
653
654 adapter->dir_odm = dir_odm;
655
656 for (i = 0; i < odm_proc_hdls_num; i++) {
657 entry = rtw_proc_create_entry(odm_proc_hdls[i].name, dir_odm, &rtw_odm_proc_fops, (void *)i);
658 if (!entry) {
659 rtw_warn_on(1);
660 goto exit;
661 }
662 }
663
664exit:
665 return dir_odm;
666}
667
668static void rtw_odm_proc_deinit(struct adapter *adapter)
669{
670 struct proc_dir_entry *dir_odm = NULL;
671 int i;
672
673 dir_odm = adapter->dir_odm;
674
675 if (!dir_odm) {
676 rtw_warn_on(1);
677 return;
678 }
679
680 for (i = 0; i < odm_proc_hdls_num; i++)
681 remove_proc_entry(odm_proc_hdls[i].name, dir_odm);
682
683 remove_proc_entry("odm", adapter->dir_dev);
684
685 adapter->dir_odm = NULL;
686}
687
688struct proc_dir_entry *rtw_adapter_proc_init(struct net_device *dev)
689{
690 struct proc_dir_entry *drv_proc = rtw_proc;
691 struct proc_dir_entry *dir_dev = NULL;
692 struct proc_dir_entry *entry = NULL;
693 struct adapter *adapter = rtw_netdev_priv(dev);
694 ssize_t i;
695
696 if (!drv_proc) {
697 rtw_warn_on(1);
698 goto exit;
699 }
700
701 if (adapter->dir_dev) {
702 rtw_warn_on(1);
703 goto exit;
704 }
705
706 dir_dev = rtw_proc_create_dir(dev->name, drv_proc, dev);
707 if (!dir_dev) {
708 rtw_warn_on(1);
709 goto exit;
710 }
711
712 adapter->dir_dev = dir_dev;
713
714 for (i = 0; i < adapter_proc_hdls_num; i++) {
715 entry = rtw_proc_create_entry(adapter_proc_hdls[i].name, dir_dev, &rtw_adapter_proc_fops, (void *)i);
716 if (!entry) {
717 rtw_warn_on(1);
718 goto exit;
719 }
720 }
721
722 rtw_odm_proc_init(dev);
723
724exit:
725 return dir_dev;
726}
727
728void rtw_adapter_proc_deinit(struct net_device *dev)
729{
730 struct proc_dir_entry *drv_proc = rtw_proc;
731 struct proc_dir_entry *dir_dev = NULL;
732 struct adapter *adapter = rtw_netdev_priv(dev);
733 int i;
734
735 dir_dev = adapter->dir_dev;
736
737 if (!dir_dev) {
738 rtw_warn_on(1);
739 return;
740 }
741
742 for (i = 0; i < adapter_proc_hdls_num; i++)
743 remove_proc_entry(adapter_proc_hdls[i].name, dir_dev);
744
745 rtw_odm_proc_deinit(adapter);
746
747 remove_proc_entry(dev->name, drv_proc);
748
749 adapter->dir_dev = NULL;
750}
751
752void rtw_adapter_proc_replace(struct net_device *dev)
753{
754 struct proc_dir_entry *drv_proc = rtw_proc;
755 struct proc_dir_entry *dir_dev = NULL;
756 struct adapter *adapter = rtw_netdev_priv(dev);
757 int i;
758
759 dir_dev = adapter->dir_dev;
760
761 if (!dir_dev) {
762 rtw_warn_on(1);
763 return;
764 }
765
766 for (i = 0; i < adapter_proc_hdls_num; i++)
767 remove_proc_entry(adapter_proc_hdls[i].name, dir_dev);
768
769 rtw_odm_proc_deinit(adapter);
770
771 remove_proc_entry(adapter->old_ifname, drv_proc);
772
773 adapter->dir_dev = NULL;
774
775 rtw_adapter_proc_init(dev);
776
777}
778
779#endif /* PROC_DEBUG */
diff --git a/drivers/staging/rtl8723bs/os_dep/rtw_proc.h b/drivers/staging/rtl8723bs/os_dep/rtw_proc.h
deleted file mode 100644
index c7e6f62b61ef..000000000000
--- a/drivers/staging/rtl8723bs/os_dep/rtw_proc.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/******************************************************************************
3 *
4 * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.
5 *
6 ******************************************************************************/
7#ifndef __RTW_PROC_H__
8#define __RTW_PROC_H__
9
10#include <linux/proc_fs.h>
11#include <linux/seq_file.h>
12
13struct rtw_proc_hdl {
14 char *name;
15 int (*show)(struct seq_file *, void *);
16 ssize_t (*write)(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
17};
18
19#ifdef PROC_DEBUG
20
21int rtw_drv_proc_init(void);
22void rtw_drv_proc_deinit(void);
23struct proc_dir_entry *rtw_adapter_proc_init(struct net_device *dev);
24void rtw_adapter_proc_deinit(struct net_device *dev);
25void rtw_adapter_proc_replace(struct net_device *dev);
26
27#else //!PROC_DEBUG
28
29static inline int rtw_drv_proc_init(void) {return 0;}
30static inline void rtw_drv_proc_deinit(void) {}
31static inline struct proc_dir_entry *rtw_adapter_proc_init(struct net_device *dev){return NULL;}
32static inline void rtw_adapter_proc_deinit(struct net_device *dev){}
33static inline void rtw_adapter_proc_replace(struct net_device *dev){}
34
35#endif //!PROC_DEBUG
36
37#endif //__RTW_PROC_H__
diff --git a/drivers/staging/rtl8723bs/os_dep/sdio_intf.c b/drivers/staging/rtl8723bs/os_dep/sdio_intf.c
index 540a7eed621d..d3784c44f6d0 100644
--- a/drivers/staging/rtl8723bs/os_dep/sdio_intf.c
+++ b/drivers/staging/rtl8723bs/os_dep/sdio_intf.c
@@ -371,7 +371,7 @@ static struct adapter *rtw_sdio_if1_init(struct dvobj_priv *dvobj, const struct
371 371
372 rtw_hal_chip_configure(padapter); 372 rtw_hal_chip_configure(padapter);
373 373
374 hal_btcoex_Initialize(padapter); 374 hal_btcoex_Initialize((void *) padapter);
375 375
376 /* 3 6. read efuse/eeprom data */ 376 /* 3 6. read efuse/eeprom data */
377 rtw_hal_read_chip_info(padapter); 377 rtw_hal_read_chip_info(padapter);
@@ -620,12 +620,10 @@ static int __init rtw_drv_entry(void)
620#endif /* BTCOEXVERSION */ 620#endif /* BTCOEXVERSION */
621 621
622 sdio_drvpriv.drv_registered = true; 622 sdio_drvpriv.drv_registered = true;
623 rtw_drv_proc_init();
624 623
625 ret = sdio_register_driver(&sdio_drvpriv.r871xs_drv); 624 ret = sdio_register_driver(&sdio_drvpriv.r871xs_drv);
626 if (ret != 0) { 625 if (ret != 0) {
627 sdio_drvpriv.drv_registered = false; 626 sdio_drvpriv.drv_registered = false;
628 rtw_drv_proc_deinit();
629 rtw_ndev_notifier_unregister(); 627 rtw_ndev_notifier_unregister();
630 DBG_871X("%s: register driver failed!!(%d)\n", __func__, ret); 628 DBG_871X("%s: register driver failed!!(%d)\n", __func__, ret);
631 goto exit; 629 goto exit;
@@ -646,7 +644,6 @@ static void __exit rtw_drv_halt(void)
646 644
647 sdio_unregister_driver(&sdio_drvpriv.r871xs_drv); 645 sdio_unregister_driver(&sdio_drvpriv.r871xs_drv);
648 646
649 rtw_drv_proc_deinit();
650 rtw_ndev_notifier_unregister(); 647 rtw_ndev_notifier_unregister();
651 648
652 DBG_871X_LEVEL(_drv_always_, "module exit success\n"); 649 DBG_871X_LEVEL(_drv_always_, "module exit success\n");
diff --git a/drivers/staging/rtl8723bs/os_dep/wifi_regd.c b/drivers/staging/rtl8723bs/os_dep/wifi_regd.c
index aa2f62acc994..578b9f734231 100644
--- a/drivers/staging/rtl8723bs/os_dep/wifi_regd.c
+++ b/drivers/staging/rtl8723bs/os_dep/wifi_regd.c
@@ -33,11 +33,6 @@
33 REG_RULE(2467 - 10, 2472 + 10, 40, 0, 20, \ 33 REG_RULE(2467 - 10, 2472 + 10, 40, 0, 20, \
34 NL80211_RRF_PASSIVE_SCAN) 34 NL80211_RRF_PASSIVE_SCAN)
35 35
36/* 2G chan 14, PASSIVS SCAN, NO OFDM (B only) */
37#define RTW_2GHZ_CH14 \
38 REG_RULE(2484 - 10, 2484 + 10, 40, 0, 20, \
39 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_OFDM)
40
41static const struct ieee80211_regdomain rtw_regdom_rd = { 36static const struct ieee80211_regdomain rtw_regdom_rd = {
42 .n_reg_rules = 3, 37 .n_reg_rules = 3,
43 .alpha2 = "99", 38 .alpha2 = "99",
diff --git a/drivers/staging/rts5208/ms.c b/drivers/staging/rts5208/ms.c
index 1128eec3bd08..e853fa9cc950 100644
--- a/drivers/staging/rts5208/ms.c
+++ b/drivers/staging/rts5208/ms.c
@@ -3842,7 +3842,7 @@ int mg_set_leaf_id(struct scsi_cmnd *srb, struct rtsx_chip *chip)
3842 3842
3843int mg_get_local_EKB(struct scsi_cmnd *srb, struct rtsx_chip *chip) 3843int mg_get_local_EKB(struct scsi_cmnd *srb, struct rtsx_chip *chip)
3844{ 3844{
3845 int retval = STATUS_FAIL; 3845 int retval;
3846 int bufflen; 3846 int bufflen;
3847 unsigned int lun = SCSI_LUN(srb); 3847 unsigned int lun = SCSI_LUN(srb);
3848 u8 *buf = NULL; 3848 u8 *buf = NULL;
diff --git a/drivers/staging/rts5208/rtsx_transport.c b/drivers/staging/rts5208/rtsx_transport.c
index 8277d7895608..561851cc8780 100644
--- a/drivers/staging/rts5208/rtsx_transport.c
+++ b/drivers/staging/rts5208/rtsx_transport.c
@@ -393,10 +393,9 @@ static int rtsx_transfer_sglist_adma_partial(struct rtsx_chip *chip, u8 card,
393 *offset = 0; 393 *offset = 0;
394 *index = *index + 1; 394 *index = *index + 1;
395 } 395 }
396 if ((i == (sg_cnt - 1)) || !resid) 396 option = RTSX_SG_VALID | RTSX_SG_TRANS_DATA;
397 option = RTSX_SG_VALID | RTSX_SG_END | RTSX_SG_TRANS_DATA; 397 if ((i == sg_cnt - 1) || !resid)
398 else 398 option |= RTSX_SG_END;
399 option = RTSX_SG_VALID | RTSX_SG_TRANS_DATA;
400 399
401 rtsx_add_sg_tbl(chip, (u32)addr, (u32)len, option); 400 rtsx_add_sg_tbl(chip, (u32)addr, (u32)len, option);
402 401
@@ -541,10 +540,9 @@ static int rtsx_transfer_sglist_adma(struct rtsx_chip *chip, u8 card,
541 dev_dbg(rtsx_dev(chip), "DMA addr: 0x%x, Len: 0x%x\n", 540 dev_dbg(rtsx_dev(chip), "DMA addr: 0x%x, Len: 0x%x\n",
542 (unsigned int)addr, len); 541 (unsigned int)addr, len);
543 542
543 option = RTSX_SG_VALID | RTSX_SG_TRANS_DATA;
544 if (j == (sg_cnt - 1)) 544 if (j == (sg_cnt - 1))
545 option = RTSX_SG_VALID | RTSX_SG_END | RTSX_SG_TRANS_DATA; 545 option |= RTSX_SG_END;
546 else
547 option = RTSX_SG_VALID | RTSX_SG_TRANS_DATA;
548 546
549 rtsx_add_sg_tbl(chip, (u32)addr, (u32)len, option); 547 rtsx_add_sg_tbl(chip, (u32)addr, (u32)len, option);
550 548
diff --git a/drivers/staging/rts5208/sd.c b/drivers/staging/rts5208/sd.c
index a06045344301..25c31496757e 100644
--- a/drivers/staging/rts5208/sd.c
+++ b/drivers/staging/rts5208/sd.c
@@ -2573,17 +2573,13 @@ SD_UNLOCK_ENTRY:
2573 retval = sd_sdr_tuning(chip); 2573 retval = sd_sdr_tuning(chip);
2574 2574
2575 if (retval != STATUS_SUCCESS) { 2575 if (retval != STATUS_SUCCESS) {
2576 if (sd20_mode) { 2576 retval = sd_init_power(chip);
2577 if (retval != STATUS_SUCCESS)
2577 goto status_fail; 2578 goto status_fail;
2578 } else {
2579 retval = sd_init_power(chip);
2580 if (retval != STATUS_SUCCESS)
2581 goto status_fail;
2582 2579
2583 try_sdio = false; 2580 try_sdio = false;
2584 sd20_mode = true; 2581 sd20_mode = true;
2585 goto switch_fail; 2582 goto switch_fail;
2586 }
2587 } 2583 }
2588 2584
2589 sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr, 2585 sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr,
@@ -2598,17 +2594,13 @@ SD_UNLOCK_ENTRY:
2598 if (read_lba0) { 2594 if (read_lba0) {
2599 retval = sd_read_lba0(chip); 2595 retval = sd_read_lba0(chip);
2600 if (retval != STATUS_SUCCESS) { 2596 if (retval != STATUS_SUCCESS) {
2601 if (sd20_mode) { 2597 retval = sd_init_power(chip);
2598 if (retval != STATUS_SUCCESS)
2602 goto status_fail; 2599 goto status_fail;
2603 } else {
2604 retval = sd_init_power(chip);
2605 if (retval != STATUS_SUCCESS)
2606 goto status_fail;
2607 2600
2608 try_sdio = false; 2601 try_sdio = false;
2609 sd20_mode = true; 2602 sd20_mode = true;
2610 goto switch_fail; 2603 goto switch_fail;
2611 }
2612 } 2604 }
2613 } 2605 }
2614 } 2606 }
diff --git a/drivers/staging/sm750fb/ddk750.h b/drivers/staging/sm750fb/ddk750.h
index 482c1c6ba422..64ef4d258a91 100644
--- a/drivers/staging/sm750fb/ddk750.h
+++ b/drivers/staging/sm750fb/ddk750.h
@@ -2,9 +2,6 @@
2/* 2/*
3 * Copyright (c) 2007 by Silicon Motion, Inc. (SMI) 3 * Copyright (c) 2007 by Silicon Motion, Inc. (SMI)
4 * 4 *
5 * All rights are reserved. Reproduction or in part is prohibited
6 * without the written consent of the copyright owner.
7 *
8 * RegSC.h --- SM718 SDK 5 * RegSC.h --- SM718 SDK
9 * This file contains the definitions for the System Configuration registers. 6 * This file contains the definitions for the System Configuration registers.
10 */ 7 */
diff --git a/drivers/staging/sm750fb/ddk750_swi2c.c b/drivers/staging/sm750fb/ddk750_swi2c.c
index 5c0ac747ea2b..0ef8d4ff2ef9 100644
--- a/drivers/staging/sm750fb/ddk750_swi2c.c
+++ b/drivers/staging/sm750fb/ddk750_swi2c.c
@@ -2,9 +2,6 @@
2/* 2/*
3 * Copyright (c) 2007 by Silicon Motion, Inc. (SMI) 3 * Copyright (c) 2007 by Silicon Motion, Inc. (SMI)
4 * 4 *
5 * All rights are reserved. Reproduction or in part is prohibited
6 * without the written consent of the copyright owner.
7 *
8 * swi2c.c --- SM750/SM718 DDK 5 * swi2c.c --- SM750/SM718 DDK
9 * This file contains the source code for I2C using software 6 * This file contains the source code for I2C using software
10 * implementation. 7 * implementation.
diff --git a/drivers/staging/sm750fb/ddk750_swi2c.h b/drivers/staging/sm750fb/ddk750_swi2c.h
index 5868feea791b..dfa166060da7 100644
--- a/drivers/staging/sm750fb/ddk750_swi2c.h
+++ b/drivers/staging/sm750fb/ddk750_swi2c.h
@@ -2,9 +2,6 @@
2/* 2/*
3 * Copyright (c) 2007 by Silicon Motion, Inc. (SMI) 3 * Copyright (c) 2007 by Silicon Motion, Inc. (SMI)
4 * 4 *
5 * All rights are reserved. Reproduction or in part is prohibited
6 * without the written consent of the copyright owner.
7 *
8 * swi2c.h --- SM750/SM718 DDK 5 * swi2c.h --- SM750/SM718 DDK
9 * This file contains the definitions for i2c using software 6 * This file contains the definitions for i2c using software
10 * implementation. 7 * implementation.
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
index f738e7f99e96..47897e81ec58 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
@@ -56,7 +56,7 @@ struct vchiq_mmal_port {
56 /* component port belongs to, allows simple deref */ 56 /* component port belongs to, allows simple deref */
57 struct vchiq_mmal_component *component; 57 struct vchiq_mmal_component *component;
58 58
59 struct vchiq_mmal_port *connected; /* port conencted to */ 59 struct vchiq_mmal_port *connected; /* port connected to */
60 60
61 /* buffer info */ 61 /* buffer info */
62 struct vchiq_mmal_port_buffer minimum_buffer; 62 struct vchiq_mmal_port_buffer minimum_buffer;
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
index 61c69f353cdb..8dc730cfe7a6 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
@@ -141,10 +141,8 @@ int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state *state)
141 return PTR_ERR(g_regs); 141 return PTR_ERR(g_regs);
142 142
143 irq = platform_get_irq(pdev, 0); 143 irq = platform_get_irq(pdev, 0);
144 if (irq <= 0) { 144 if (irq <= 0)
145 dev_err(dev, "failed to get IRQ\n");
146 return irq; 145 return irq;
147 }
148 146
149 err = devm_request_irq(dev, irq, vchiq_doorbell_irq, IRQF_IRQPOLL, 147 err = devm_request_irq(dev, irq, vchiq_doorbell_irq, IRQF_IRQPOLL,
150 "VCHIQ doorbell", state); 148 "VCHIQ doorbell", state);
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index cc4383d1ec3e..b1595b13dea8 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -2824,7 +2824,6 @@ vchiq_release_internal(struct vchiq_state *state, struct vchiq_service *service)
2824 VCHIQ_STATUS_T ret = VCHIQ_SUCCESS; 2824 VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
2825 char entity[16]; 2825 char entity[16];
2826 int *entity_uc; 2826 int *entity_uc;
2827 int local_uc, local_entity_uc;
2828 2827
2829 if (!arm_state) 2828 if (!arm_state)
2830 goto out; 2829 goto out;
@@ -2849,8 +2848,8 @@ vchiq_release_internal(struct vchiq_state *state, struct vchiq_service *service)
2849 ret = VCHIQ_ERROR; 2848 ret = VCHIQ_ERROR;
2850 goto unlock; 2849 goto unlock;
2851 } 2850 }
2852 local_uc = --arm_state->videocore_use_count; 2851 --arm_state->videocore_use_count;
2853 local_entity_uc = --(*entity_uc); 2852 --(*entity_uc);
2854 2853
2855 if (!vchiq_videocore_wanted(state)) { 2854 if (!vchiq_videocore_wanted(state)) {
2856 if (vchiq_platform_use_suspend_timer() && 2855 if (vchiq_platform_use_suspend_timer() &&
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
index 183f5cf887e0..56a23a297fa4 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
@@ -3322,13 +3322,13 @@ vchiq_dump_shared_state(void *dump_context, struct vchiq_state *state,
3322 char buf[80]; 3322 char buf[80];
3323 int len; 3323 int len;
3324 3324
3325 len = snprintf(buf, sizeof(buf), 3325 len = scnprintf(buf, sizeof(buf),
3326 " %s: slots %d-%d tx_pos=%x recycle=%x", 3326 " %s: slots %d-%d tx_pos=%x recycle=%x",
3327 label, shared->slot_first, shared->slot_last, 3327 label, shared->slot_first, shared->slot_last,
3328 shared->tx_pos, shared->slot_queue_recycle); 3328 shared->tx_pos, shared->slot_queue_recycle);
3329 vchiq_dump(dump_context, buf, len + 1); 3329 vchiq_dump(dump_context, buf, len + 1);
3330 3330
3331 len = snprintf(buf, sizeof(buf), 3331 len = scnprintf(buf, sizeof(buf),
3332 " Slots claimed:"); 3332 " Slots claimed:");
3333 vchiq_dump(dump_context, buf, len + 1); 3333 vchiq_dump(dump_context, buf, len + 1);
3334 3334
@@ -3336,7 +3336,7 @@ vchiq_dump_shared_state(void *dump_context, struct vchiq_state *state,
3336 struct vchiq_slot_info slot_info = 3336 struct vchiq_slot_info slot_info =
3337 *SLOT_INFO_FROM_INDEX(state, i); 3337 *SLOT_INFO_FROM_INDEX(state, i);
3338 if (slot_info.use_count != slot_info.release_count) { 3338 if (slot_info.use_count != slot_info.release_count) {
3339 len = snprintf(buf, sizeof(buf), 3339 len = scnprintf(buf, sizeof(buf),
3340 " %d: %d/%d", i, slot_info.use_count, 3340 " %d: %d/%d", i, slot_info.use_count,
3341 slot_info.release_count); 3341 slot_info.release_count);
3342 vchiq_dump(dump_context, buf, len + 1); 3342 vchiq_dump(dump_context, buf, len + 1);
@@ -3344,7 +3344,7 @@ vchiq_dump_shared_state(void *dump_context, struct vchiq_state *state,
3344 } 3344 }
3345 3345
3346 for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) { 3346 for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) {
3347 len = snprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)", 3347 len = scnprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)",
3348 debug_names[i], shared->debug[i], shared->debug[i]); 3348 debug_names[i], shared->debug[i], shared->debug[i]);
3349 vchiq_dump(dump_context, buf, len + 1); 3349 vchiq_dump(dump_context, buf, len + 1);
3350 } 3350 }
@@ -3357,11 +3357,11 @@ vchiq_dump_state(void *dump_context, struct vchiq_state *state)
3357 int len; 3357 int len;
3358 int i; 3358 int i;
3359 3359
3360 len = snprintf(buf, sizeof(buf), "State %d: %s", state->id, 3360 len = scnprintf(buf, sizeof(buf), "State %d: %s", state->id,
3361 conn_state_names[state->conn_state]); 3361 conn_state_names[state->conn_state]);
3362 vchiq_dump(dump_context, buf, len + 1); 3362 vchiq_dump(dump_context, buf, len + 1);
3363 3363
3364 len = snprintf(buf, sizeof(buf), 3364 len = scnprintf(buf, sizeof(buf),
3365 " tx_pos=%x(@%pK), rx_pos=%x(@%pK)", 3365 " tx_pos=%x(@%pK), rx_pos=%x(@%pK)",
3366 state->local->tx_pos, 3366 state->local->tx_pos,
3367 state->tx_data + (state->local_tx_pos & VCHIQ_SLOT_MASK), 3367 state->tx_data + (state->local_tx_pos & VCHIQ_SLOT_MASK),
@@ -3369,13 +3369,13 @@ vchiq_dump_state(void *dump_context, struct vchiq_state *state)
3369 state->rx_data + (state->rx_pos & VCHIQ_SLOT_MASK)); 3369 state->rx_data + (state->rx_pos & VCHIQ_SLOT_MASK));
3370 vchiq_dump(dump_context, buf, len + 1); 3370 vchiq_dump(dump_context, buf, len + 1);
3371 3371
3372 len = snprintf(buf, sizeof(buf), 3372 len = scnprintf(buf, sizeof(buf),
3373 " Version: %d (min %d)", 3373 " Version: %d (min %d)",
3374 VCHIQ_VERSION, VCHIQ_VERSION_MIN); 3374 VCHIQ_VERSION, VCHIQ_VERSION_MIN);
3375 vchiq_dump(dump_context, buf, len + 1); 3375 vchiq_dump(dump_context, buf, len + 1);
3376 3376
3377 if (VCHIQ_ENABLE_STATS) { 3377 if (VCHIQ_ENABLE_STATS) {
3378 len = snprintf(buf, sizeof(buf), 3378 len = scnprintf(buf, sizeof(buf),
3379 " Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, " 3379 " Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, "
3380 "error_count=%d", 3380 "error_count=%d",
3381 state->stats.ctrl_tx_count, state->stats.ctrl_rx_count, 3381 state->stats.ctrl_tx_count, state->stats.ctrl_rx_count,
@@ -3383,7 +3383,7 @@ vchiq_dump_state(void *dump_context, struct vchiq_state *state)
3383 vchiq_dump(dump_context, buf, len + 1); 3383 vchiq_dump(dump_context, buf, len + 1);
3384 } 3384 }
3385 3385
3386 len = snprintf(buf, sizeof(buf), 3386 len = scnprintf(buf, sizeof(buf),
3387 " Slots: %d available (%d data), %d recyclable, %d stalls " 3387 " Slots: %d available (%d data), %d recyclable, %d stalls "
3388 "(%d data)", 3388 "(%d data)",
3389 ((state->slot_queue_available * VCHIQ_SLOT_SIZE) - 3389 ((state->slot_queue_available * VCHIQ_SLOT_SIZE) -
@@ -3416,7 +3416,7 @@ vchiq_dump_service_state(void *dump_context, struct vchiq_service *service)
3416 char buf[80]; 3416 char buf[80];
3417 int len; 3417 int len;
3418 3418
3419 len = snprintf(buf, sizeof(buf), "Service %u: %s (ref %u)", 3419 len = scnprintf(buf, sizeof(buf), "Service %u: %s (ref %u)",
3420 service->localport, srvstate_names[service->srvstate], 3420 service->localport, srvstate_names[service->srvstate],
3421 service->ref_count - 1); /*Don't include the lock just taken*/ 3421 service->ref_count - 1); /*Don't include the lock just taken*/
3422 3422
@@ -3428,17 +3428,17 @@ vchiq_dump_service_state(void *dump_context, struct vchiq_service *service)
3428 int tx_pending, rx_pending; 3428 int tx_pending, rx_pending;
3429 3429
3430 if (service->remoteport != VCHIQ_PORT_FREE) { 3430 if (service->remoteport != VCHIQ_PORT_FREE) {
3431 int len2 = snprintf(remoteport, sizeof(remoteport), 3431 int len2 = scnprintf(remoteport, sizeof(remoteport),
3432 "%u", service->remoteport); 3432 "%u", service->remoteport);
3433 3433
3434 if (service->public_fourcc != VCHIQ_FOURCC_INVALID) 3434 if (service->public_fourcc != VCHIQ_FOURCC_INVALID)
3435 snprintf(remoteport + len2, 3435 scnprintf(remoteport + len2,
3436 sizeof(remoteport) - len2, 3436 sizeof(remoteport) - len2,
3437 " (client %x)", service->client_id); 3437 " (client %x)", service->client_id);
3438 } else 3438 } else
3439 strcpy(remoteport, "n/a"); 3439 strcpy(remoteport, "n/a");
3440 3440
3441 len += snprintf(buf + len, sizeof(buf) - len, 3441 len += scnprintf(buf + len, sizeof(buf) - len,
3442 " '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)", 3442 " '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)",
3443 VCHIQ_FOURCC_AS_4CHARS(fourcc), 3443 VCHIQ_FOURCC_AS_4CHARS(fourcc),
3444 remoteport, 3444 remoteport,
@@ -3455,7 +3455,7 @@ vchiq_dump_service_state(void *dump_context, struct vchiq_service *service)
3455 rx_pending = service->bulk_rx.local_insert - 3455 rx_pending = service->bulk_rx.local_insert -
3456 service->bulk_rx.remote_insert; 3456 service->bulk_rx.remote_insert;
3457 3457
3458 len = snprintf(buf, sizeof(buf), 3458 len = scnprintf(buf, sizeof(buf),
3459 " Bulk: tx_pending=%d (size %d)," 3459 " Bulk: tx_pending=%d (size %d),"
3460 " rx_pending=%d (size %d)", 3460 " rx_pending=%d (size %d)",
3461 tx_pending, 3461 tx_pending,
@@ -3468,7 +3468,7 @@ vchiq_dump_service_state(void *dump_context, struct vchiq_service *service)
3468 if (VCHIQ_ENABLE_STATS) { 3468 if (VCHIQ_ENABLE_STATS) {
3469 vchiq_dump(dump_context, buf, len + 1); 3469 vchiq_dump(dump_context, buf, len + 1);
3470 3470
3471 len = snprintf(buf, sizeof(buf), 3471 len = scnprintf(buf, sizeof(buf),
3472 " Ctrl: tx_count=%d, tx_bytes=%llu, " 3472 " Ctrl: tx_count=%d, tx_bytes=%llu, "
3473 "rx_count=%d, rx_bytes=%llu", 3473 "rx_count=%d, rx_bytes=%llu",
3474 service->stats.ctrl_tx_count, 3474 service->stats.ctrl_tx_count,
@@ -3477,7 +3477,7 @@ vchiq_dump_service_state(void *dump_context, struct vchiq_service *service)
3477 service->stats.ctrl_rx_bytes); 3477 service->stats.ctrl_rx_bytes);
3478 vchiq_dump(dump_context, buf, len + 1); 3478 vchiq_dump(dump_context, buf, len + 1);
3479 3479
3480 len = snprintf(buf, sizeof(buf), 3480 len = scnprintf(buf, sizeof(buf),
3481 " Bulk: tx_count=%d, tx_bytes=%llu, " 3481 " Bulk: tx_count=%d, tx_bytes=%llu, "
3482 "rx_count=%d, rx_bytes=%llu", 3482 "rx_count=%d, rx_bytes=%llu",
3483 service->stats.bulk_tx_count, 3483 service->stats.bulk_tx_count,
@@ -3486,7 +3486,7 @@ vchiq_dump_service_state(void *dump_context, struct vchiq_service *service)
3486 service->stats.bulk_rx_bytes); 3486 service->stats.bulk_rx_bytes);
3487 vchiq_dump(dump_context, buf, len + 1); 3487 vchiq_dump(dump_context, buf, len + 1);
3488 3488
3489 len = snprintf(buf, sizeof(buf), 3489 len = scnprintf(buf, sizeof(buf),
3490 " %d quota stalls, %d slot stalls, " 3490 " %d quota stalls, %d slot stalls, "
3491 "%d bulk stalls, %d aborted, %d errors", 3491 "%d bulk stalls, %d aborted, %d errors",
3492 service->stats.quota_stalls, 3492 service->stats.quota_stalls,
@@ -3562,9 +3562,9 @@ void vchiq_log_dump_mem(const char *label, u32 addr, const void *void_mem,
3562 3562
3563 for (offset = 0; offset < 16; offset++) { 3563 for (offset = 0; offset < 16; offset++) {
3564 if (offset < num_bytes) 3564 if (offset < num_bytes)
3565 s += snprintf(s, 4, "%02x ", mem[offset]); 3565 s += scnprintf(s, 4, "%02x ", mem[offset]);
3566 else 3566 else
3567 s += snprintf(s, 4, " "); 3567 s += scnprintf(s, 4, " ");
3568 } 3568 }
3569 3569
3570 for (offset = 0; offset < 16; offset++) { 3570 for (offset = 0; offset < 16; offset++) {
diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c
index 9def0748ffee..4e9cfacf75f2 100644
--- a/drivers/staging/vt6656/rxtx.c
+++ b/drivers/staging/vt6656/rxtx.c
@@ -287,12 +287,12 @@ static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
287 buf->duration_a = vnt_get_duration_le(priv, 287 buf->duration_a = vnt_get_duration_le(priv,
288 tx_context->pkt_type, need_ack); 288 tx_context->pkt_type, need_ack);
289 buf->duration_b = vnt_get_duration_le(priv, 289 buf->duration_b = vnt_get_duration_le(priv,
290 PK_TYPE_11B, need_ack); 290 PK_TYPE_11B, need_ack);
291 } 291 }
292 292
293 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate); 293 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
294 buf->time_stamp_off_b = vnt_time_stamp_off(priv, 294 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
295 priv->top_cck_basic_rate); 295 priv->top_cck_basic_rate);
296 296
297 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); 297 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
298 298
@@ -325,7 +325,7 @@ static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
325 325
326 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate); 326 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
327 buf->time_stamp_off_b = vnt_time_stamp_off(priv, 327 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
328 priv->top_cck_basic_rate); 328 priv->top_cck_basic_rate);
329 329
330 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); 330 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
331 331
@@ -655,7 +655,7 @@ static u16 vnt_rxtx_ab(struct vnt_usb_send_context *tx_context,
655 u8 need_ack = tx_context->need_ack; 655 u8 need_ack = tx_context->need_ack;
656 656
657 buf->rrv_time = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type, 657 buf->rrv_time = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type,
658 frame_len, current_rate, need_ack); 658 frame_len, current_rate, need_ack);
659 659
660 if (need_mic) 660 if (need_mic)
661 head = &tx_head->tx_ab.tx.mic.head; 661 head = &tx_head->tx_ab.tx.mic.head;
@@ -1036,7 +1036,7 @@ static int vnt_beacon_xmit(struct vnt_private *priv, struct sk_buff *skb)
1036 1036
1037 /* Get Duration and TimeStampOff */ 1037 /* Get Duration and TimeStampOff */
1038 short_head->duration = vnt_get_duration_le(priv, 1038 short_head->duration = vnt_get_duration_le(priv,
1039 PK_TYPE_11B, false); 1039 PK_TYPE_11B, false);
1040 short_head->time_stamp_off = 1040 short_head->time_stamp_off =
1041 vnt_time_stamp_off(priv, current_rate); 1041 vnt_time_stamp_off(priv, current_rate);
1042 } 1042 }
diff --git a/drivers/staging/vt6656/usbpipe.c b/drivers/staging/vt6656/usbpipe.c
index ff351a7a0876..d3304df6bd53 100644
--- a/drivers/staging/vt6656/usbpipe.c
+++ b/drivers/staging/vt6656/usbpipe.c
@@ -216,7 +216,7 @@ static void vnt_submit_rx_urb_complete(struct urb *urb)
216 } 216 }
217 217
218 urb->transfer_buffer = skb_put(rcb->skb, 218 urb->transfer_buffer = skb_put(rcb->skb,
219 skb_tailroom(rcb->skb)); 219 skb_tailroom(rcb->skb));
220 } 220 }
221 221
222 if (usb_submit_urb(urb, GFP_ATOMIC)) { 222 if (usb_submit_urb(urb, GFP_ATOMIC)) {
diff --git a/drivers/staging/wilc1000/microchip,wilc1000,sdio.txt b/drivers/staging/wilc1000/microchip,wilc1000,sdio.txt
index 4f7d1c2be4d0..da5235950a70 100644
--- a/drivers/staging/wilc1000/microchip,wilc1000,sdio.txt
+++ b/drivers/staging/wilc1000/microchip,wilc1000,sdio.txt
@@ -10,7 +10,9 @@ Required properties:
10 10
11Optional: 11Optional:
12- bus-width : Number of data lines wired up the slot. Default 1 bit. 12- bus-width : Number of data lines wired up the slot. Default 1 bit.
13 13- rtc_clk : Clock connected on the rtc clock line. Must be assigned
14 a frequency with assigned-clocks property, and must be
15 connected to a clock provider.
14 16
15Examples: 17Examples:
16mmc1: mmc@fc000000 { 18mmc1: mmc@fc000000 {
@@ -24,6 +26,10 @@ mmc1: mmc@fc000000 {
24 wilc_sdio@0 { 26 wilc_sdio@0 {
25 compatible = "microchip,wilc1000-sdio"; 27 compatible = "microchip,wilc1000-sdio";
26 irq-gpios = <&pioC 27 0>; 28 irq-gpios = <&pioC 27 0>;
29 clocks = <&pck1>;
30 clock-names = "rtc_clk";
31 assigned-clocks = <&pck1>;
32 assigned-clock-rates = <32768>;
27 status = "okay"; 33 status = "okay";
28 reg = <0>; 34 reg = <0>;
29 bus-width = <4>; 35 bus-width = <4>;
diff --git a/drivers/staging/wilc1000/microchip,wilc1000,spi.txt b/drivers/staging/wilc1000/microchip,wilc1000,spi.txt
index 87db87b2d901..34236932dbb6 100644
--- a/drivers/staging/wilc1000/microchip,wilc1000,spi.txt
+++ b/drivers/staging/wilc1000/microchip,wilc1000,spi.txt
@@ -9,6 +9,10 @@ Required properties:
9- reg : Chip select address of device 9- reg : Chip select address of device
10- irq-gpios : Connect to a host IRQ 10- irq-gpios : Connect to a host IRQ
11 11
12Optional:
13- rtc_clk : Clock connected on the rtc clock line. Must be assigned
14 a frequency with assigned-clocks property, and must be
15 connected to a clock provider.
12 16
13Examples: 17Examples:
14 18
@@ -21,6 +25,10 @@ spi1: spi@fc018000 {
21 spi-max-frequency = <48000000>; 25 spi-max-frequency = <48000000>;
22 reg = <0>; 26 reg = <0>;
23 irq-gpios = <&pioC 27 0>; 27 irq-gpios = <&pioC 27 0>;
28 clocks = <&pck1>;
29 clock-names = "rtc_clk";
30 assigned-clocks = <&pck1>;
31 assigned-clock-rates = <32768>;
24 status = "okay"; 32 status = "okay";
25 }; 33 };
26}; 34};
diff --git a/drivers/staging/wilc1000/wilc_hif.c b/drivers/staging/wilc1000/wilc_hif.c
index 9345cabe3c93..f2b7d5a1be17 100644
--- a/drivers/staging/wilc1000/wilc_hif.c
+++ b/drivers/staging/wilc1000/wilc_hif.c
@@ -248,7 +248,7 @@ int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
248 goto error; 248 goto error;
249 } 249 }
250 250
251 if (vif->obtaining_ip || vif->connecting) { 251 if (vif->connecting) {
252 netdev_err(vif->ndev, "Don't do obss scan\n"); 252 netdev_err(vif->ndev, "Don't do obss scan\n");
253 result = -EBUSY; 253 result = -EBUSY;
254 goto error; 254 goto error;
@@ -679,13 +679,7 @@ static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
679 if (mac_status == WILC_MAC_STATUS_CONNECTED && 679 if (mac_status == WILC_MAC_STATUS_CONNECTED &&
680 conn_info->status == WLAN_STATUS_SUCCESS) { 680 conn_info->status == WLAN_STATUS_SUCCESS) {
681 ether_addr_copy(hif_drv->assoc_bssid, conn_info->bssid); 681 ether_addr_copy(hif_drv->assoc_bssid, conn_info->bssid);
682 wilc_set_power_mgmt(vif, 0, 0);
683
684 hif_drv->hif_state = HOST_IF_CONNECTED; 682 hif_drv->hif_state = HOST_IF_CONNECTED;
685
686 vif->obtaining_ip = true;
687 mod_timer(&vif->during_ip_timer,
688 jiffies + msecs_to_jiffies(10000));
689 } else { 683 } else {
690 hif_drv->hif_state = HOST_IF_IDLE; 684 hif_drv->hif_state = HOST_IF_IDLE;
691 } 685 }
@@ -708,15 +702,11 @@ static inline void host_int_handle_disconnect(struct wilc_vif *vif)
708 handle_scan_done(vif, SCAN_EVENT_ABORTED); 702 handle_scan_done(vif, SCAN_EVENT_ABORTED);
709 } 703 }
710 704
711 if (hif_drv->conn_info.conn_result) { 705 if (hif_drv->conn_info.conn_result)
712 vif->obtaining_ip = false;
713 wilc_set_power_mgmt(vif, 0, 0);
714
715 hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, 706 hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
716 0, hif_drv->conn_info.arg); 707 0, hif_drv->conn_info.arg);
717 } else { 708 else
718 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__); 709 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
719 }
720 710
721 eth_zero_addr(hif_drv->assoc_bssid); 711 eth_zero_addr(hif_drv->assoc_bssid);
722 712
@@ -772,9 +762,6 @@ int wilc_disconnect(struct wilc_vif *vif)
772 wid.val = (s8 *)&dummy_reason_code; 762 wid.val = (s8 *)&dummy_reason_code;
773 wid.size = sizeof(char); 763 wid.size = sizeof(char);
774 764
775 vif->obtaining_ip = false;
776 wilc_set_power_mgmt(vif, 0, 0);
777
778 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 765 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
779 if (result) { 766 if (result) {
780 netdev_err(vif->ndev, "Failed to send disconnect\n"); 767 netdev_err(vif->ndev, "Failed to send disconnect\n");
@@ -811,15 +798,6 @@ int wilc_disconnect(struct wilc_vif *vif)
811 return 0; 798 return 0;
812} 799}
813 800
814void wilc_resolve_disconnect_aberration(struct wilc_vif *vif)
815{
816 if (!vif->hif_drv)
817 return;
818 if (vif->hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP ||
819 vif->hif_drv->hif_state == HOST_IF_CONNECTING)
820 wilc_disconnect(vif);
821}
822
823int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats) 801int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
824{ 802{
825 struct wid wid_list[5]; 803 struct wid wid_list[5];
@@ -924,7 +902,7 @@ static int handle_remain_on_chan(struct wilc_vif *vif,
924 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) 902 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
925 return -EBUSY; 903 return -EBUSY;
926 904
927 if (vif->obtaining_ip || vif->connecting) 905 if (vif->connecting)
928 return -EBUSY; 906 return -EBUSY;
929 907
930 remain_on_chan_flag = true; 908 remain_on_chan_flag = true;
@@ -1069,13 +1047,9 @@ static void handle_scan_timer(struct work_struct *work)
1069static void handle_scan_complete(struct work_struct *work) 1047static void handle_scan_complete(struct work_struct *work)
1070{ 1048{
1071 struct host_if_msg *msg = container_of(work, struct host_if_msg, work); 1049 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1072 struct wilc *wilc = msg->vif->wilc;
1073 1050
1074 del_timer(&msg->vif->hif_drv->scan_timer); 1051 del_timer(&msg->vif->hif_drv->scan_timer);
1075 1052
1076 if (!wilc_wlan_get_num_conn_ifcs(wilc))
1077 wilc_chip_sleep_manually(wilc);
1078
1079 handle_scan_done(msg->vif, SCAN_EVENT_DONE); 1053 handle_scan_done(msg->vif, SCAN_EVENT_DONE);
1080 1054
1081 kfree(msg); 1055 kfree(msg);
@@ -1426,18 +1400,14 @@ int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
1426 return result; 1400 return result;
1427} 1401}
1428 1402
1429int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode, 1403int wilc_set_operation_mode(struct wilc_vif *vif, int index, u8 mode,
1430 u8 ifc_id) 1404 u8 ifc_id)
1431{ 1405{
1432 struct wid wid; 1406 struct wid wid;
1433 struct host_if_drv *hif_drv = vif->hif_drv;
1434 int result; 1407 int result;
1435 struct wilc_drv_handler drv; 1408 struct wilc_drv_handler drv;
1436 1409
1437 if (!hif_drv) 1410 wid.id = WID_SET_OPERATION_MODE;
1438 return -EFAULT;
1439
1440 wid.id = WID_SET_DRV_HANDLER;
1441 wid.type = WID_STR; 1411 wid.type = WID_STR;
1442 wid.size = sizeof(drv); 1412 wid.size = sizeof(drv);
1443 wid.val = (u8 *)&drv; 1413 wid.val = (u8 *)&drv;
@@ -1452,26 +1422,6 @@ int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
1452 return result; 1422 return result;
1453} 1423}
1454 1424
1455int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode)
1456{
1457 struct wid wid;
1458 struct wilc_op_mode op_mode;
1459 int result;
1460
1461 wid.id = WID_SET_OPERATION_MODE;
1462 wid.type = WID_INT;
1463 wid.size = sizeof(op_mode);
1464 wid.val = (u8 *)&op_mode;
1465
1466 op_mode.mode = cpu_to_le32(mode);
1467
1468 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1469 if (result)
1470 netdev_err(vif->ndev, "Failed to set operation mode\n");
1471
1472 return result;
1473}
1474
1475s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac, u32 *out_val) 1425s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac, u32 *out_val)
1476{ 1426{
1477 struct wid wid; 1427 struct wid wid;
@@ -1610,7 +1560,6 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
1610 *hif_drv_handler = hif_drv; 1560 *hif_drv_handler = hif_drv;
1611 1561
1612 vif->hif_drv = hif_drv; 1562 vif->hif_drv = hif_drv;
1613 vif->obtaining_ip = false;
1614 1563
1615 if (wilc->clients_count == 0) 1564 if (wilc->clients_count == 0)
1616 mutex_init(&wilc->deinit_lock); 1565 mutex_init(&wilc->deinit_lock);
@@ -1648,8 +1597,6 @@ int wilc_deinit(struct wilc_vif *vif)
1648 del_timer_sync(&vif->periodic_rssi); 1597 del_timer_sync(&vif->periodic_rssi);
1649 del_timer_sync(&hif_drv->remain_on_ch_timer); 1598 del_timer_sync(&hif_drv->remain_on_ch_timer);
1650 1599
1651 wilc_set_wfi_drv_handler(vif, 0, 0, 0);
1652
1653 if (hif_drv->usr_scan_req.scan_result) { 1600 if (hif_drv->usr_scan_req.scan_result) {
1654 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL, 1601 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL,
1655 hif_drv->usr_scan_req.arg); 1602 hif_drv->usr_scan_req.arg);
@@ -2024,9 +1971,6 @@ int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
2024 int result; 1971 int result;
2025 s8 power_mode; 1972 s8 power_mode;
2026 1973
2027 if (wilc_wlan_get_num_conn_ifcs(vif->wilc) == 2 && enabled)
2028 return 0;
2029
2030 if (enabled) 1974 if (enabled)
2031 power_mode = WILC_FW_MIN_FAST_PS; 1975 power_mode = WILC_FW_MIN_FAST_PS;
2032 else 1976 else
diff --git a/drivers/staging/wilc1000/wilc_hif.h b/drivers/staging/wilc1000/wilc_hif.h
index be1d2497cde9..ac5fe57f872b 100644
--- a/drivers/staging/wilc1000/wilc_hif.h
+++ b/drivers/staging/wilc1000/wilc_hif.h
@@ -219,11 +219,9 @@ int wilc_remain_on_channel(struct wilc_vif *vif, u64 cookie,
219 void *user_arg); 219 void *user_arg);
220int wilc_listen_state_expired(struct wilc_vif *vif, u64 cookie); 220int wilc_listen_state_expired(struct wilc_vif *vif, u64 cookie);
221void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg); 221void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg);
222int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode, 222int wilc_set_operation_mode(struct wilc_vif *vif, int index, u8 mode,
223 u8 ifc_id); 223 u8 ifc_id);
224int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode);
225int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats); 224int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats);
226void wilc_resolve_disconnect_aberration(struct wilc_vif *vif);
227int wilc_get_vif_idx(struct wilc_vif *vif); 225int wilc_get_vif_idx(struct wilc_vif *vif);
228int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power); 226int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power);
229int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power); 227int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power);
diff --git a/drivers/staging/wilc1000/wilc_mon.c b/drivers/staging/wilc1000/wilc_mon.c
index 7d7933d40924..d6f14f69ad64 100644
--- a/drivers/staging/wilc1000/wilc_mon.c
+++ b/drivers/staging/wilc1000/wilc_mon.c
@@ -35,8 +35,7 @@ void wilc_wfi_monitor_rx(struct net_device *mon_dev, u8 *buff, u32 size)
35 return; 35 return;
36 36
37 /* Get WILC header */ 37 /* Get WILC header */
38 memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET); 38 header = get_unaligned_le32(buff - HOST_HDR_OFFSET);
39 le32_to_cpus(&header);
40 /* 39 /*
41 * The packet offset field contain info about what type of management 40 * The packet offset field contain info about what type of management
42 * the frame we are dealing with and ack status 41 * the frame we are dealing with and ack status
diff --git a/drivers/staging/wilc1000/wilc_netdev.c b/drivers/staging/wilc1000/wilc_netdev.c
index 565e2b5d0616..508acb8bb089 100644
--- a/drivers/staging/wilc1000/wilc_netdev.c
+++ b/drivers/staging/wilc1000/wilc_netdev.c
@@ -11,6 +11,7 @@
11#include <linux/inetdevice.h> 11#include <linux/inetdevice.h>
12 12
13#include "wilc_wfi_cfgoperations.h" 13#include "wilc_wfi_cfgoperations.h"
14#include "wilc_wlan_cfg.h"
14 15
15#define WILC_MULTICAST_TABLE_SIZE 8 16#define WILC_MULTICAST_TABLE_SIZE 8
16 17
@@ -59,7 +60,7 @@ static int init_irq(struct net_device *dev)
59 60
60 ret = request_threaded_irq(wl->dev_irq_num, isr_uh_routine, 61 ret = request_threaded_irq(wl->dev_irq_num, isr_uh_routine,
61 isr_bh_routine, 62 isr_bh_routine,
62 IRQF_TRIGGER_LOW | IRQF_ONESHOT, 63 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
63 "WILC_IRQ", dev); 64 "WILC_IRQ", dev);
64 if (ret < 0) 65 if (ret < 0)
65 netdev_err(dev, "Failed to request IRQ\n"); 66 netdev_err(dev, "Failed to request IRQ\n");
@@ -474,7 +475,7 @@ static void wilc_wlan_deinitialize(struct net_device *dev)
474 wlan_deinitialize_threads(dev); 475 wlan_deinitialize_threads(dev);
475 deinit_irq(dev); 476 deinit_irq(dev);
476 477
477 wilc_wlan_stop(wl); 478 wilc_wlan_stop(wl, vif);
478 wilc_wlan_cleanup(dev); 479 wilc_wlan_cleanup(dev);
479 wlan_deinit_locks(dev); 480 wlan_deinit_locks(dev);
480 481
@@ -503,12 +504,6 @@ static int wlan_initialize_threads(struct net_device *dev)
503 return 0; 504 return 0;
504} 505}
505 506
506static int dev_state_ev_handler(struct notifier_block *this,
507 unsigned long event, void *ptr);
508static struct notifier_block g_dev_notifier = {
509 .notifier_call = dev_state_ev_handler
510};
511
512static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif) 507static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif)
513{ 508{
514 int ret = 0; 509 int ret = 0;
@@ -574,12 +569,11 @@ static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif)
574 ret = -EIO; 569 ret = -EIO;
575 goto fail_fw_start; 570 goto fail_fw_start;
576 } 571 }
577 register_inetaddr_notifier(&g_dev_notifier);
578 wl->initialized = true; 572 wl->initialized = true;
579 return 0; 573 return 0;
580 574
581fail_fw_start: 575fail_fw_start:
582 wilc_wlan_stop(wl); 576 wilc_wlan_stop(wl, vif);
583 577
584fail_irq_enable: 578fail_irq_enable:
585 if (!wl->dev_irq_num && 579 if (!wl->dev_irq_num &&
@@ -632,10 +626,8 @@ static int wilc_mac_open(struct net_device *ndev)
632 return ret; 626 return ret;
633 } 627 }
634 628
635 wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif), vif->iftype, 629 wilc_set_operation_mode(vif, wilc_get_vif_idx(vif), vif->iftype,
636 vif->idx); 630 vif->idx);
637 wilc_set_operation_mode(vif, vif->iftype);
638
639 wilc_get_mac_address(vif, mac_add); 631 wilc_get_mac_address(vif, mac_add);
640 netdev_dbg(ndev, "Mac address: %pM\n", mac_add); 632 netdev_dbg(ndev, "Mac address: %pM\n", mac_add);
641 ether_addr_copy(ndev->dev_addr, mac_add); 633 ether_addr_copy(ndev->dev_addr, mac_add);
@@ -780,7 +772,6 @@ static int wilc_mac_close(struct net_device *ndev)
780 if (wl->open_ifcs == 0) { 772 if (wl->open_ifcs == 0) {
781 netdev_dbg(ndev, "Deinitializing wilc1000\n"); 773 netdev_dbg(ndev, "Deinitializing wilc1000\n");
782 wl->close = 1; 774 wl->close = 1;
783 unregister_inetaddr_notifier(&g_dev_notifier);
784 wilc_wlan_deinitialize(ndev); 775 wilc_wlan_deinitialize(ndev);
785 } 776 }
786 777
@@ -863,63 +854,6 @@ static const struct net_device_ops wilc_netdev_ops = {
863 .ndo_set_rx_mode = wilc_set_multicast_list, 854 .ndo_set_rx_mode = wilc_set_multicast_list,
864}; 855};
865 856
866static int dev_state_ev_handler(struct notifier_block *this,
867 unsigned long event, void *ptr)
868{
869 struct in_ifaddr *dev_iface = ptr;
870 struct wilc_priv *priv;
871 struct host_if_drv *hif_drv;
872 struct net_device *dev;
873 struct wilc_vif *vif;
874
875 if (!dev_iface || !dev_iface->ifa_dev || !dev_iface->ifa_dev->dev)
876 return NOTIFY_DONE;
877
878 dev = (struct net_device *)dev_iface->ifa_dev->dev;
879 if (dev->netdev_ops != &wilc_netdev_ops)
880 return NOTIFY_DONE;
881
882 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
883 return NOTIFY_DONE;
884
885 vif = netdev_priv(dev);
886 priv = &vif->priv;
887
888 hif_drv = (struct host_if_drv *)priv->hif_drv;
889
890 switch (event) {
891 case NETDEV_UP:
892 if (vif->iftype == WILC_STATION_MODE ||
893 vif->iftype == WILC_CLIENT_MODE) {
894 hif_drv->ifc_up = 1;
895 vif->obtaining_ip = false;
896 del_timer(&vif->during_ip_timer);
897 }
898
899 if (vif->wilc->enable_ps)
900 wilc_set_power_mgmt(vif, 1, 0);
901
902 break;
903
904 case NETDEV_DOWN:
905 if (vif->iftype == WILC_STATION_MODE ||
906 vif->iftype == WILC_CLIENT_MODE) {
907 hif_drv->ifc_up = 0;
908 vif->obtaining_ip = false;
909 wilc_set_power_mgmt(vif, 0, 0);
910 }
911
912 wilc_resolve_disconnect_aberration(vif);
913
914 break;
915
916 default:
917 break;
918 }
919
920 return NOTIFY_DONE;
921}
922
923void wilc_netdev_cleanup(struct wilc *wilc) 857void wilc_netdev_cleanup(struct wilc *wilc)
924{ 858{
925 int i; 859 int i;
diff --git a/drivers/staging/wilc1000/wilc_sdio.c b/drivers/staging/wilc1000/wilc_sdio.c
index 4c1c81fed11f..c787c5da8f2b 100644
--- a/drivers/staging/wilc1000/wilc_sdio.c
+++ b/drivers/staging/wilc1000/wilc_sdio.c
@@ -4,6 +4,7 @@
4 * All rights reserved. 4 * All rights reserved.
5 */ 5 */
6 6
7#include <linux/clk.h>
7#include <linux/mmc/sdio_func.h> 8#include <linux/mmc/sdio_func.h>
8#include <linux/mmc/host.h> 9#include <linux/mmc/host.h>
9 10
@@ -151,6 +152,12 @@ static int wilc_sdio_probe(struct sdio_func *func,
151 wilc->dev = &func->dev; 152 wilc->dev = &func->dev;
152 wilc->gpio_irq = gpio; 153 wilc->gpio_irq = gpio;
153 154
155 wilc->rtc_clk = devm_clk_get(&func->card->dev, "rtc_clk");
156 if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER)
157 return -EPROBE_DEFER;
158 else if (!IS_ERR(wilc->rtc_clk))
159 clk_prepare_enable(wilc->rtc_clk);
160
154 dev_info(&func->dev, "Driver Initializing success\n"); 161 dev_info(&func->dev, "Driver Initializing success\n");
155 return 0; 162 return 0;
156} 163}
@@ -162,6 +169,10 @@ static void wilc_sdio_remove(struct sdio_func *func)
162 /* free the GPIO in module remove */ 169 /* free the GPIO in module remove */
163 if (wilc->gpio_irq) 170 if (wilc->gpio_irq)
164 gpiod_put(wilc->gpio_irq); 171 gpiod_put(wilc->gpio_irq);
172
173 if (!IS_ERR(wilc->rtc_clk))
174 clk_disable_unprepare(wilc->rtc_clk);
175
165 wilc_netdev_cleanup(wilc); 176 wilc_netdev_cleanup(wilc);
166} 177}
167 178
@@ -193,9 +204,10 @@ static int wilc_sdio_suspend(struct device *dev)
193 dev_info(dev, "sdio suspend\n"); 204 dev_info(dev, "sdio suspend\n");
194 chip_wakeup(wilc); 205 chip_wakeup(wilc);
195 206
196 if (!wilc->suspend_event) { 207 if (!IS_ERR(wilc->rtc_clk))
197 wilc_chip_sleep_manually(wilc); 208 clk_disable_unprepare(wilc->rtc_clk);
198 } else { 209
210 if (wilc->suspend_event) {
199 host_sleep_notify(wilc); 211 host_sleep_notify(wilc);
200 chip_allow_sleep(wilc); 212 chip_allow_sleep(wilc);
201 } 213 }
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 736eedef23b6..22f21831649b 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -70,15 +70,6 @@ struct wilc_p2p_mgmt_data {
70static const u8 p2p_oui[] = {0x50, 0x6f, 0x9A, 0x09}; 70static const u8 p2p_oui[] = {0x50, 0x6f, 0x9A, 0x09};
71static const u8 p2p_vendor_spec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03}; 71static const u8 p2p_vendor_spec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03};
72 72
73#define WILC_IP_TIMEOUT_MS 15000
74
75static void clear_during_ip(struct timer_list *t)
76{
77 struct wilc_vif *vif = from_timer(vif, t, during_ip_timer);
78
79 vif->obtaining_ip = false;
80}
81
82static void cfg_scan_result(enum scan_event scan_event, 73static void cfg_scan_result(enum scan_event scan_event,
83 struct wilc_rcvd_net_info *info, void *user_void) 74 struct wilc_rcvd_net_info *info, void *user_void)
84{ 75{
@@ -176,7 +167,6 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt, u8 mac_status,
176 } else if (conn_disconn_evt == CONN_DISCONN_EVENT_DISCONN_NOTIF) { 167 } else if (conn_disconn_evt == CONN_DISCONN_EVENT_DISCONN_NOTIF) {
177 u16 reason = 0; 168 u16 reason = 0;
178 169
179 vif->obtaining_ip = false;
180 priv->p2p.local_random = 0x01; 170 priv->p2p.local_random = 0x01;
181 priv->p2p.recv_random = 0x00; 171 priv->p2p.recv_random = 0x00;
182 priv->p2p.is_wilc_ie = false; 172 priv->p2p.is_wilc_ie = false;
@@ -1038,8 +1028,7 @@ void wilc_wfi_p2p_rx(struct wilc_vif *vif, u8 *buff, u32 size)
1038 s32 freq; 1028 s32 freq;
1039 __le16 fc; 1029 __le16 fc;
1040 1030
1041 memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET); 1031 header = get_unaligned_le32(buff - HOST_HDR_OFFSET);
1042 le32_to_cpus(&header);
1043 pkt_offset = GET_PKT_OFFSET(header); 1032 pkt_offset = GET_PKT_OFFSET(header);
1044 1033
1045 if (pkt_offset & IS_MANAGMEMENT_CALLBACK) { 1034 if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
@@ -1404,8 +1393,7 @@ static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1404 if (!priv->hif_drv) 1393 if (!priv->hif_drv)
1405 return -EIO; 1394 return -EIO;
1406 1395
1407 if (vif->wilc->enable_ps) 1396 wilc_set_power_mgmt(vif, enabled, timeout);
1408 wilc_set_power_mgmt(vif, enabled, timeout);
1409 1397
1410 return 0; 1398 return 0;
1411} 1399}
@@ -1421,8 +1409,6 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
1421 priv->p2p.local_random = 0x01; 1409 priv->p2p.local_random = 0x01;
1422 priv->p2p.recv_random = 0x00; 1410 priv->p2p.recv_random = 0x00;
1423 priv->p2p.is_wilc_ie = false; 1411 priv->p2p.is_wilc_ie = false;
1424 vif->obtaining_ip = false;
1425 del_timer(&vif->during_ip_timer);
1426 1412
1427 switch (type) { 1413 switch (type) {
1428 case NL80211_IFTYPE_STATION: 1414 case NL80211_IFTYPE_STATION:
@@ -1433,13 +1419,11 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
1433 if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE) 1419 if (vif->iftype == WILC_AP_MODE || vif->iftype == WILC_GO_MODE)
1434 wilc_wfi_deinit_mon_interface(wl, true); 1420 wilc_wfi_deinit_mon_interface(wl, true);
1435 vif->iftype = WILC_STATION_MODE; 1421 vif->iftype = WILC_STATION_MODE;
1436 wilc_set_operation_mode(vif, WILC_STATION_MODE); 1422 wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1423 WILC_STATION_MODE, vif->idx);
1437 1424
1438 memset(priv->assoc_stainfo.sta_associated_bss, 0, 1425 memset(priv->assoc_stainfo.sta_associated_bss, 0,
1439 WILC_MAX_NUM_STA * ETH_ALEN); 1426 WILC_MAX_NUM_STA * ETH_ALEN);
1440
1441 wl->enable_ps = true;
1442 wilc_set_power_mgmt(vif, 1, 0);
1443 break; 1427 break;
1444 1428
1445 case NL80211_IFTYPE_P2P_CLIENT: 1429 case NL80211_IFTYPE_P2P_CLIENT:
@@ -1448,37 +1432,26 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
1448 priv->wdev.iftype = type; 1432 priv->wdev.iftype = type;
1449 vif->monitor_flag = 0; 1433 vif->monitor_flag = 0;
1450 vif->iftype = WILC_CLIENT_MODE; 1434 vif->iftype = WILC_CLIENT_MODE;
1451 wilc_set_operation_mode(vif, WILC_STATION_MODE); 1435 wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1452 1436 WILC_STATION_MODE, vif->idx);
1453 wl->enable_ps = false;
1454 wilc_set_power_mgmt(vif, 0, 0);
1455 break; 1437 break;
1456 1438
1457 case NL80211_IFTYPE_AP: 1439 case NL80211_IFTYPE_AP:
1458 wl->enable_ps = false;
1459 dev->ieee80211_ptr->iftype = type; 1440 dev->ieee80211_ptr->iftype = type;
1460 priv->wdev.iftype = type; 1441 priv->wdev.iftype = type;
1461 vif->iftype = WILC_AP_MODE; 1442 vif->iftype = WILC_AP_MODE;
1462 1443
1463 if (wl->initialized) { 1444 if (wl->initialized)
1464 wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif), 1445 wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1465 0, vif->idx); 1446 WILC_AP_MODE, vif->idx);
1466 wilc_set_operation_mode(vif, WILC_AP_MODE);
1467 wilc_set_power_mgmt(vif, 0, 0);
1468 }
1469 break; 1447 break;
1470 1448
1471 case NL80211_IFTYPE_P2P_GO: 1449 case NL80211_IFTYPE_P2P_GO:
1472 vif->obtaining_ip = true;
1473 mod_timer(&vif->during_ip_timer,
1474 jiffies + msecs_to_jiffies(WILC_IP_TIMEOUT_MS));
1475 wilc_set_operation_mode(vif, WILC_AP_MODE);
1476 dev->ieee80211_ptr->iftype = type; 1450 dev->ieee80211_ptr->iftype = type;
1477 priv->wdev.iftype = type; 1451 priv->wdev.iftype = type;
1478 vif->iftype = WILC_GO_MODE; 1452 vif->iftype = WILC_GO_MODE;
1479 1453 wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1480 wl->enable_ps = false; 1454 WILC_AP_MODE, vif->idx);
1481 wilc_set_power_mgmt(vif, 0, 0);
1482 break; 1455 break;
1483 1456
1484 default: 1457 default:
@@ -1500,7 +1473,6 @@ static int start_ap(struct wiphy *wiphy, struct net_device *dev,
1500 netdev_err(dev, "Error in setting channel\n"); 1473 netdev_err(dev, "Error in setting channel\n");
1501 1474
1502 wilc_wlan_set_bssid(dev, dev->dev_addr, WILC_AP_MODE); 1475 wilc_wlan_set_bssid(dev, dev->dev_addr, WILC_AP_MODE);
1503 wilc_set_power_mgmt(vif, 0, 0);
1504 1476
1505 return wilc_add_beacon(vif, settings->beacon_interval, 1477 return wilc_add_beacon(vif, settings->beacon_interval,
1506 settings->dtim_period, &settings->beacon); 1478 settings->dtim_period, &settings->beacon);
@@ -1687,16 +1659,16 @@ static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
1687 vif->monitor_flag = 0; 1659 vif->monitor_flag = 0;
1688 1660
1689 mutex_lock(&wl->vif_mutex); 1661 mutex_lock(&wl->vif_mutex);
1690 wilc_set_wfi_drv_handler(vif, 0, 0, 0); 1662 wilc_set_operation_mode(vif, 0, 0, 0);
1691 for (i = vif->idx; i < wl->vif_num ; i++) { 1663 for (i = vif->idx; i < wl->vif_num; i++) {
1692 if ((i + 1) >= wl->vif_num) { 1664 if ((i + 1) >= wl->vif_num) {
1693 wl->vif[i] = NULL; 1665 wl->vif[i] = NULL;
1694 } else { 1666 } else {
1695 vif = wl->vif[i + 1]; 1667 vif = wl->vif[i + 1];
1696 vif->idx = i; 1668 vif->idx = i;
1697 wl->vif[i] = vif; 1669 wl->vif[i] = vif;
1698 wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif), 1670 wilc_set_operation_mode(vif, wilc_get_vif_idx(vif),
1699 vif->iftype, vif->idx); 1671 vif->iftype, vif->idx);
1700 } 1672 }
1701 } 1673 }
1702 wl->vif_num--; 1674 wl->vif_num--;
@@ -1851,7 +1823,6 @@ int wilc_cfg80211_init(struct wilc **wilc, struct device *dev, int io_type,
1851 *wilc = wl; 1823 *wilc = wl;
1852 wl->io_type = io_type; 1824 wl->io_type = io_type;
1853 wl->hif_func = ops; 1825 wl->hif_func = ops;
1854 wl->enable_ps = false;
1855 wl->chip_ps_state = WILC_CHIP_WAKEDUP; 1826 wl->chip_ps_state = WILC_CHIP_WAKEDUP;
1856 INIT_LIST_HEAD(&wl->txq_head.list); 1827 INIT_LIST_HEAD(&wl->txq_head.list);
1857 INIT_LIST_HEAD(&wl->rxq_head.list); 1828 INIT_LIST_HEAD(&wl->rxq_head.list);
@@ -1949,8 +1920,6 @@ int wilc_init_host_int(struct net_device *net)
1949 struct wilc_vif *vif = netdev_priv(net); 1920 struct wilc_vif *vif = netdev_priv(net);
1950 struct wilc_priv *priv = &vif->priv; 1921 struct wilc_priv *priv = &vif->priv;
1951 1922
1952 timer_setup(&vif->during_ip_timer, clear_during_ip, 0);
1953
1954 priv->p2p_listen_state = false; 1923 priv->p2p_listen_state = false;
1955 1924
1956 mutex_init(&priv->scan_req_lock); 1925 mutex_init(&priv->scan_req_lock);
@@ -1973,8 +1942,6 @@ void wilc_deinit_host_int(struct net_device *net)
1973 mutex_destroy(&priv->scan_req_lock); 1942 mutex_destroy(&priv->scan_req_lock);
1974 ret = wilc_deinit(vif); 1943 ret = wilc_deinit(vif);
1975 1944
1976 del_timer_sync(&vif->during_ip_timer);
1977
1978 if (ret) 1945 if (ret)
1979 netdev_err(net, "Error while deinitializing host interface\n"); 1946 netdev_err(net, "Error while deinitializing host interface\n");
1980} 1947}
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 1e74a08e7cf1..978a8bdbfc40 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -203,7 +203,6 @@ struct wilc_vif {
203 struct net_device *ndev; 203 struct net_device *ndev;
204 u8 mode; 204 u8 mode;
205 struct timer_list during_ip_timer; 205 struct timer_list during_ip_timer;
206 bool obtaining_ip;
207 struct timer_list periodic_rssi; 206 struct timer_list periodic_rssi;
208 struct rf_info periodic_stat; 207 struct rf_info periodic_stat;
209 struct tcp_ack_filter ack_filter; 208 struct tcp_ack_filter ack_filter;
@@ -217,6 +216,7 @@ struct wilc {
217 int io_type; 216 int io_type;
218 s8 mac_status; 217 s8 mac_status;
219 struct gpio_desc *gpio_irq; 218 struct gpio_desc *gpio_irq;
219 struct clk *rtc_clk;
220 bool initialized; 220 bool initialized;
221 int dev_irq_num; 221 int dev_irq_num;
222 int close; 222 int close;
@@ -262,7 +262,6 @@ struct wilc {
262 struct device *dev; 262 struct device *dev;
263 bool suspend_event; 263 bool suspend_event;
264 264
265 bool enable_ps;
266 int clients_count; 265 int clients_count;
267 struct workqueue_struct *hif_workqueue; 266 struct workqueue_struct *hif_workqueue;
268 enum chip_ps_states chip_ps_state; 267 enum chip_ps_states chip_ps_state;
diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c
index d46876edcfeb..771d8cb68dc1 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -455,20 +455,6 @@ void chip_wakeup(struct wilc *wilc)
455} 455}
456EXPORT_SYMBOL_GPL(chip_wakeup); 456EXPORT_SYMBOL_GPL(chip_wakeup);
457 457
458void wilc_chip_sleep_manually(struct wilc *wilc)
459{
460 if (wilc->chip_ps_state != WILC_CHIP_WAKEDUP)
461 return;
462 acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
463
464 chip_allow_sleep(wilc);
465 wilc->hif_func->hif_write_reg(wilc, 0x10a8, 1);
466
467 wilc->chip_ps_state = WILC_CHIP_SLEEPING_MANUAL;
468 release_bus(wilc, WILC_BUS_RELEASE_ONLY);
469}
470EXPORT_SYMBOL_GPL(wilc_chip_sleep_manually);
471
472void host_wakeup_notify(struct wilc *wilc) 458void host_wakeup_notify(struct wilc *wilc)
473{ 459{
474 acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY); 460 acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
@@ -703,8 +689,7 @@ static void wilc_wlan_handle_rx_buff(struct wilc *wilc, u8 *buffer, int size)
703 689
704 do { 690 do {
705 buff_ptr = buffer + offset; 691 buff_ptr = buffer + offset;
706 memcpy(&header, buff_ptr, 4); 692 header = get_unaligned_le32(buff_ptr);
707 le32_to_cpus(&header);
708 693
709 is_cfg_packet = (header >> 31) & 0x1; 694 is_cfg_packet = (header >> 31) & 0x1;
710 pkt_offset = (header >> 22) & 0x1ff; 695 pkt_offset = (header >> 22) & 0x1ff;
@@ -773,26 +758,6 @@ static void wilc_unknown_isr_ext(struct wilc *wilc)
773 wilc->hif_func->hif_clear_int_ext(wilc, 0); 758 wilc->hif_func->hif_clear_int_ext(wilc, 0);
774} 759}
775 760
776static void wilc_pllupdate_isr_ext(struct wilc *wilc, u32 int_stats)
777{
778 int trials = 10;
779
780 wilc->hif_func->hif_clear_int_ext(wilc, PLL_INT_CLR);
781
782 if (wilc->io_type == WILC_HIF_SDIO)
783 mdelay(WILC_PLL_TO_SDIO);
784 else
785 mdelay(WILC_PLL_TO_SPI);
786
787 while (!(is_wilc1000(wilc_get_chipid(wilc, true)) && --trials))
788 mdelay(1);
789}
790
791static void wilc_sleeptimer_isr_ext(struct wilc *wilc, u32 int_stats1)
792{
793 wilc->hif_func->hif_clear_int_ext(wilc, SLEEP_INT_CLR);
794}
795
796static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status) 761static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status)
797{ 762{
798 u32 offset = wilc->rx_buffer_offset; 763 u32 offset = wilc->rx_buffer_offset;
@@ -842,15 +807,9 @@ void wilc_handle_isr(struct wilc *wilc)
842 acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP); 807 acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
843 wilc->hif_func->hif_read_int(wilc, &int_status); 808 wilc->hif_func->hif_read_int(wilc, &int_status);
844 809
845 if (int_status & PLL_INT_EXT)
846 wilc_pllupdate_isr_ext(wilc, int_status);
847
848 if (int_status & DATA_INT_EXT) 810 if (int_status & DATA_INT_EXT)
849 wilc_wlan_handle_isr_ext(wilc, int_status); 811 wilc_wlan_handle_isr_ext(wilc, int_status);
850 812
851 if (int_status & SLEEP_INT_EXT)
852 wilc_sleeptimer_isr_ext(wilc, int_status);
853
854 if (!(int_status & (ALL_INT_EXT))) 813 if (!(int_status & (ALL_INT_EXT)))
855 wilc_unknown_isr_ext(wilc); 814 wilc_unknown_isr_ext(wilc);
856 815
@@ -874,10 +833,8 @@ int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
874 833
875 offset = 0; 834 offset = 0;
876 do { 835 do {
877 memcpy(&addr, &buffer[offset], 4); 836 addr = get_unaligned_le32(&buffer[offset]);
878 memcpy(&size, &buffer[offset + 4], 4); 837 size = get_unaligned_le32(&buffer[offset + 4]);
879 le32_to_cpus(&addr);
880 le32_to_cpus(&size);
881 acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY); 838 acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
882 offset += 8; 839 offset += 8;
883 while (((int)size) && (offset < buffer_size)) { 840 while (((int)size) && (offset < buffer_size)) {
@@ -985,72 +942,52 @@ int wilc_wlan_start(struct wilc *wilc)
985 return (ret < 0) ? ret : 0; 942 return (ret < 0) ? ret : 0;
986} 943}
987 944
988int wilc_wlan_stop(struct wilc *wilc) 945int wilc_wlan_stop(struct wilc *wilc, struct wilc_vif *vif)
989{ 946{
990 u32 reg = 0; 947 u32 reg = 0;
991 int ret; 948 int ret;
992 u8 timeout = 10;
993 949
994 acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP); 950 acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
995 951
996 ret = wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, &reg); 952 ret = wilc->hif_func->hif_read_reg(wilc, WILC_GP_REG_0, &reg);
997 if (!ret) { 953 if (!ret) {
954 netdev_err(vif->ndev, "Error while reading reg\n");
998 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP); 955 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
999 return ret; 956 return -EIO;
1000 } 957 }
1001 958
1002 reg &= ~BIT(10); 959 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_0,
1003 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg); 960 (reg | WILC_ABORT_REQ_BIT));
1004 if (!ret) { 961 if (!ret) {
962 netdev_err(vif->ndev, "Error while writing reg\n");
1005 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP); 963 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
1006 return ret; 964 return -EIO;
1007 } 965 }
1008 966
1009 do { 967 ret = wilc->hif_func->hif_read_reg(wilc, WILC_FW_HOST_COMM, &reg);
1010 ret = wilc->hif_func->hif_read_reg(wilc, 968 if (!ret) {
1011 WILC_GLB_RESET_0, &reg); 969 netdev_err(vif->ndev, "Error while reading reg\n");
1012 if (!ret) { 970 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
1013 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP); 971 return -EIO;
1014 return ret; 972 }
1015 } 973 reg = BIT(0);
1016
1017 if ((reg & BIT(10))) {
1018 reg &= ~BIT(10);
1019 ret = wilc->hif_func->hif_write_reg(wilc,
1020 WILC_GLB_RESET_0,
1021 reg);
1022 timeout--;
1023 } else {
1024 ret = wilc->hif_func->hif_read_reg(wilc,
1025 WILC_GLB_RESET_0,
1026 &reg);
1027 if (!ret) {
1028 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
1029 return ret;
1030 }
1031 break;
1032 }
1033
1034 } while (timeout);
1035 reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) |
1036 BIT(29) | BIT(30) | BIT(31));
1037
1038 wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1039 reg = (u32)~BIT(10);
1040 974
1041 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg); 975 ret = wilc->hif_func->hif_write_reg(wilc, WILC_FW_HOST_COMM, reg);
976 if (!ret) {
977 netdev_err(vif->ndev, "Error while writing reg\n");
978 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
979 return -EIO;
980 }
1042 981
1043 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP); 982 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
1044 983
1045 return ret; 984 return 0;
1046} 985}
1047 986
1048void wilc_wlan_cleanup(struct net_device *dev) 987void wilc_wlan_cleanup(struct net_device *dev)
1049{ 988{
1050 struct txq_entry_t *tqe; 989 struct txq_entry_t *tqe;
1051 struct rxq_entry_t *rqe; 990 struct rxq_entry_t *rqe;
1052 u32 reg = 0;
1053 int ret;
1054 struct wilc_vif *vif = netdev_priv(dev); 991 struct wilc_vif *vif = netdev_priv(dev);
1055 struct wilc *wilc = vif->wilc; 992 struct wilc *wilc = vif->wilc;
1056 993
@@ -1075,23 +1012,6 @@ void wilc_wlan_cleanup(struct net_device *dev)
1075 wilc->rx_buffer = NULL; 1012 wilc->rx_buffer = NULL;
1076 kfree(wilc->tx_buffer); 1013 kfree(wilc->tx_buffer);
1077 wilc->tx_buffer = NULL; 1014 wilc->tx_buffer = NULL;
1078
1079 acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
1080
1081 ret = wilc->hif_func->hif_read_reg(wilc, WILC_GP_REG_0, &reg);
1082 if (!ret) {
1083 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
1084 return;
1085 }
1086
1087 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_0,
1088 (reg | ABORT_INT));
1089 if (!ret) {
1090 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
1091 return;
1092 }
1093
1094 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
1095 wilc->hif_func->hif_deinit(NULL); 1015 wilc->hif_func->hif_deinit(NULL);
1096} 1016}
1097 1017
@@ -1196,11 +1116,6 @@ int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u16 wid, int commit,
1196 return ret_size; 1116 return ret_size;
1197} 1117}
1198 1118
1199int wilc_wlan_cfg_get_val(struct wilc *wl, u16 wid, u8 *buffer, u32 buffer_size)
1200{
1201 return wilc_wlan_cfg_get_wid_value(wl, wid, buffer, buffer_size);
1202}
1203
1204int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids, 1119int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
1205 u32 count) 1120 u32 count)
1206{ 1121{
diff --git a/drivers/staging/wilc1000/wilc_wlan.h b/drivers/staging/wilc1000/wilc_wlan.h
index d2eef7b4c3b7..7469fa47d588 100644
--- a/drivers/staging/wilc1000/wilc_wlan.h
+++ b/drivers/staging/wilc1000/wilc_wlan.h
@@ -98,6 +98,7 @@
98#define WILC_VMM_TBL_RX_SHADOW_BASE WILC_AHB_SHARE_MEM_BASE 98#define WILC_VMM_TBL_RX_SHADOW_BASE WILC_AHB_SHARE_MEM_BASE
99#define WILC_VMM_TBL_RX_SHADOW_SIZE 256 99#define WILC_VMM_TBL_RX_SHADOW_SIZE 256
100 100
101#define WILC_FW_HOST_COMM 0x13c0
101#define WILC_GP_REG_0 0x149c 102#define WILC_GP_REG_0 0x149c
102#define WILC_GP_REG_1 0x14a0 103#define WILC_GP_REG_1 0x14a0
103 104
@@ -127,9 +128,7 @@
127#define WILC_CFG_RSP_STATUS 2 128#define WILC_CFG_RSP_STATUS 2
128#define WILC_CFG_RSP_SCAN 3 129#define WILC_CFG_RSP_SCAN 3
129 130
130#define WILC_PLL_TO_SDIO 4 131#define WILC_ABORT_REQ_BIT BIT(31)
131#define WILC_PLL_TO_SPI 2
132#define ABORT_INT BIT(31)
133 132
134#define WILC_RX_BUFF_SIZE (96 * 1024) 133#define WILC_RX_BUFF_SIZE (96 * 1024)
135#define WILC_TX_BUFF_SIZE (64 * 1024) 134#define WILC_TX_BUFF_SIZE (64 * 1024)
@@ -184,14 +183,10 @@
184#define EN_VMM BIT(8) 183#define EN_VMM BIT(8)
185 184
186#define DATA_INT_EXT INT_0 185#define DATA_INT_EXT INT_0
187#define PLL_INT_EXT INT_1 186#define ALL_INT_EXT DATA_INT_EXT
188#define SLEEP_INT_EXT INT_2 187#define NUM_INT_EXT 1
189#define ALL_INT_EXT (DATA_INT_EXT | PLL_INT_EXT | SLEEP_INT_EXT)
190#define NUM_INT_EXT 3
191 188
192#define DATA_INT_CLR CLR_INT0 189#define DATA_INT_CLR CLR_INT0
193#define PLL_INT_CLR CLR_INT1
194#define SLEEP_INT_CLR CLR_INT2
195 190
196#define ENABLE_RX_VMM (SEL_VMM_TBL1 | EN_VMM) 191#define ENABLE_RX_VMM (SEL_VMM_TBL1 | EN_VMM)
197#define ENABLE_TX_VMM (SEL_VMM_TBL0 | EN_VMM) 192#define ENABLE_TX_VMM (SEL_VMM_TBL0 | EN_VMM)
@@ -280,7 +275,7 @@ struct wilc_vif;
280int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer, 275int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
281 u32 buffer_size); 276 u32 buffer_size);
282int wilc_wlan_start(struct wilc *wilc); 277int wilc_wlan_start(struct wilc *wilc);
283int wilc_wlan_stop(struct wilc *wilc); 278int wilc_wlan_stop(struct wilc *wilc, struct wilc_vif *vif);
284int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer, 279int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
285 u32 buffer_size, 280 u32 buffer_size,
286 void (*tx_complete_fn)(void *, int)); 281 void (*tx_complete_fn)(void *, int));
@@ -291,12 +286,8 @@ int wilc_wlan_cfg_set(struct wilc_vif *vif, int start, u16 wid, u8 *buffer,
291 u32 buffer_size, int commit, u32 drv_handler); 286 u32 buffer_size, int commit, u32 drv_handler);
292int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u16 wid, int commit, 287int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u16 wid, int commit,
293 u32 drv_handler); 288 u32 drv_handler);
294int wilc_wlan_cfg_get_val(struct wilc *wl, u16 wid, u8 *buffer,
295 u32 buffer_size);
296int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer, 289int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
297 u32 buffer_size, void (*func)(void *, int)); 290 u32 buffer_size, void (*func)(void *, int));
298void wilc_chip_sleep_manually(struct wilc *wilc);
299
300void wilc_enable_tcp_ack_filter(struct wilc_vif *vif, bool value); 291void wilc_enable_tcp_ack_filter(struct wilc_vif *vif, bool value);
301int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc); 292int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc);
302netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *dev); 293netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *dev);
diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.c b/drivers/staging/wilc1000/wilc_wlan_cfg.c
index 9dc5de4eb08d..3f53807cee0f 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.c
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.c
@@ -52,57 +52,35 @@ static const struct wilc_cfg_str g_cfg_str[] = {
52 52
53static int wilc_wlan_cfg_set_byte(u8 *frame, u32 offset, u16 id, u8 val8) 53static int wilc_wlan_cfg_set_byte(u8 *frame, u32 offset, u16 id, u8 val8)
54{ 54{
55 u8 *buf;
56
57 if ((offset + 4) >= WILC_MAX_CFG_FRAME_SIZE) 55 if ((offset + 4) >= WILC_MAX_CFG_FRAME_SIZE)
58 return 0; 56 return 0;
59 57
60 buf = &frame[offset]; 58 put_unaligned_le16(id, &frame[offset]);
61 59 put_unaligned_le16(1, &frame[offset + 2]);
62 buf[0] = (u8)id; 60 frame[offset + 4] = val8;
63 buf[1] = (u8)(id >> 8);
64 buf[2] = 1;
65 buf[3] = 0;
66 buf[4] = val8;
67 return 5; 61 return 5;
68} 62}
69 63
70static int wilc_wlan_cfg_set_hword(u8 *frame, u32 offset, u16 id, u16 val16) 64static int wilc_wlan_cfg_set_hword(u8 *frame, u32 offset, u16 id, u16 val16)
71{ 65{
72 u8 *buf;
73
74 if ((offset + 5) >= WILC_MAX_CFG_FRAME_SIZE) 66 if ((offset + 5) >= WILC_MAX_CFG_FRAME_SIZE)
75 return 0; 67 return 0;
76 68
77 buf = &frame[offset]; 69 put_unaligned_le16(id, &frame[offset]);
78 70 put_unaligned_le16(2, &frame[offset + 2]);
79 buf[0] = (u8)id; 71 put_unaligned_le16(val16, &frame[offset + 4]);
80 buf[1] = (u8)(id >> 8);
81 buf[2] = 2;
82 buf[3] = 0;
83 buf[4] = (u8)val16;
84 buf[5] = (u8)(val16 >> 8);
85 72
86 return 6; 73 return 6;
87} 74}
88 75
89static int wilc_wlan_cfg_set_word(u8 *frame, u32 offset, u16 id, u32 val32) 76static int wilc_wlan_cfg_set_word(u8 *frame, u32 offset, u16 id, u32 val32)
90{ 77{
91 u8 *buf;
92
93 if ((offset + 7) >= WILC_MAX_CFG_FRAME_SIZE) 78 if ((offset + 7) >= WILC_MAX_CFG_FRAME_SIZE)
94 return 0; 79 return 0;
95 80
96 buf = &frame[offset]; 81 put_unaligned_le16(id, &frame[offset]);
97 82 put_unaligned_le16(4, &frame[offset + 2]);
98 buf[0] = (u8)id; 83 put_unaligned_le32(val32, &frame[offset + 4]);
99 buf[1] = (u8)(id >> 8);
100 buf[2] = 4;
101 buf[3] = 0;
102 buf[4] = (u8)val32;
103 buf[5] = (u8)(val32 >> 8);
104 buf[6] = (u8)(val32 >> 16);
105 buf[7] = (u8)(val32 >> 24);
106 84
107 return 8; 85 return 8;
108} 86}
@@ -110,46 +88,35 @@ static int wilc_wlan_cfg_set_word(u8 *frame, u32 offset, u16 id, u32 val32)
110static int wilc_wlan_cfg_set_str(u8 *frame, u32 offset, u16 id, u8 *str, 88static int wilc_wlan_cfg_set_str(u8 *frame, u32 offset, u16 id, u8 *str,
111 u32 size) 89 u32 size)
112{ 90{
113 u8 *buf;
114
115 if ((offset + size + 4) >= WILC_MAX_CFG_FRAME_SIZE) 91 if ((offset + size + 4) >= WILC_MAX_CFG_FRAME_SIZE)
116 return 0; 92 return 0;
117 93
118 buf = &frame[offset]; 94 put_unaligned_le16(id, &frame[offset]);
119 95 put_unaligned_le16(size, &frame[offset + 2]);
120 buf[0] = (u8)id;
121 buf[1] = (u8)(id >> 8);
122 buf[2] = (u8)size;
123 buf[3] = (u8)(size >> 8);
124
125 if (str && size != 0) 96 if (str && size != 0)
126 memcpy(&buf[4], str, size); 97 memcpy(&frame[offset + 4], str, size);
127 98
128 return (size + 4); 99 return (size + 4);
129} 100}
130 101
131static int wilc_wlan_cfg_set_bin(u8 *frame, u32 offset, u16 id, u8 *b, u32 size) 102static int wilc_wlan_cfg_set_bin(u8 *frame, u32 offset, u16 id, u8 *b, u32 size)
132{ 103{
133 u8 *buf;
134 u32 i; 104 u32 i;
135 u8 checksum = 0; 105 u8 checksum = 0;
136 106
137 if ((offset + size + 5) >= WILC_MAX_CFG_FRAME_SIZE) 107 if ((offset + size + 5) >= WILC_MAX_CFG_FRAME_SIZE)
138 return 0; 108 return 0;
139 109
140 buf = &frame[offset]; 110 put_unaligned_le16(id, &frame[offset]);
141 buf[0] = (u8)id; 111 put_unaligned_le16(size, &frame[offset + 2]);
142 buf[1] = (u8)(id >> 8);
143 buf[2] = (u8)size;
144 buf[3] = (u8)(size >> 8);
145 112
146 if ((b) && size != 0) { 113 if ((b) && size != 0) {
147 memcpy(&buf[4], b, size); 114 memcpy(&frame[offset + 4], b, size);
148 for (i = 0; i < size; i++) 115 for (i = 0; i < size; i++)
149 checksum += buf[i + 4]; 116 checksum += frame[offset + i + 4];
150 } 117 }
151 118
152 buf[size + 4] = checksum; 119 frame[offset + size + 4] = checksum;
153 120
154 return (size + 5); 121 return (size + 5);
155} 122}
@@ -307,21 +274,16 @@ int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size)
307 274
308int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id) 275int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id)
309{ 276{
310 u8 *buf;
311
312 if ((offset + 2) >= WILC_MAX_CFG_FRAME_SIZE) 277 if ((offset + 2) >= WILC_MAX_CFG_FRAME_SIZE)
313 return 0; 278 return 0;
314 279
315 buf = &frame[offset]; 280 put_unaligned_le16(id, &frame[offset]);
316
317 buf[0] = (u8)id;
318 buf[1] = (u8)(id >> 8);
319 281
320 return 2; 282 return 2;
321} 283}
322 284
323int wilc_wlan_cfg_get_wid_value(struct wilc *wl, u16 wid, u8 *buffer, 285int wilc_wlan_cfg_get_val(struct wilc *wl, u16 wid, u8 *buffer,
324 u32 buffer_size) 286 u32 buffer_size)
325{ 287{
326 u32 type = (wid >> 12) & 0xf; 288 u32 type = (wid >> 12) & 0xf;
327 int i, ret = 0; 289 int i, ret = 0;
diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.h b/drivers/staging/wilc1000/wilc_wlan_cfg.h
index e5ca6cea0682..614c5673f232 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.h
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.h
@@ -44,8 +44,8 @@ struct wilc_cfg {
44struct wilc; 44struct wilc;
45int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size); 45int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size);
46int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id); 46int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id);
47int wilc_wlan_cfg_get_wid_value(struct wilc *wl, u16 wid, u8 *buffer, 47int wilc_wlan_cfg_get_val(struct wilc *wl, u16 wid, u8 *buffer,
48 u32 buffer_size); 48 u32 buffer_size);
49void wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size, 49void wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
50 struct wilc_cfg_rsp *rsp); 50 struct wilc_cfg_rsp *rsp);
51int wilc_wlan_cfg_init(struct wilc *wl); 51int wilc_wlan_cfg_init(struct wilc *wl);
diff --git a/drivers/staging/wilc1000/wilc_wlan_if.h b/drivers/staging/wilc1000/wilc_wlan_if.h
index b89d0e0f04cc..70eac586f80c 100644
--- a/drivers/staging/wilc1000/wilc_wlan_if.h
+++ b/drivers/staging/wilc1000/wilc_wlan_if.h
@@ -724,7 +724,6 @@ enum {
724 /* NMAC Integer WID list */ 724 /* NMAC Integer WID list */
725 /* Custom Integer WID list */ 725 /* Custom Integer WID list */
726 WID_GET_INACTIVE_TIME = 0x2084, 726 WID_GET_INACTIVE_TIME = 0x2084,
727 WID_SET_OPERATION_MODE = 0X2086,
728 /* EMAC String WID list */ 727 /* EMAC String WID list */
729 WID_SSID = 0x3000, 728 WID_SSID = 0x3000,
730 WID_FIRMWARE_VERSION = 0x3001, 729 WID_FIRMWARE_VERSION = 0x3001,
@@ -755,9 +754,9 @@ enum {
755 WID_MODEL_NAME = 0x3027, /*Added for CAPI tool */ 754 WID_MODEL_NAME = 0x3027, /*Added for CAPI tool */
756 WID_MODEL_NUM = 0x3028, /*Added for CAPI tool */ 755 WID_MODEL_NUM = 0x3028, /*Added for CAPI tool */
757 WID_DEVICE_NAME = 0x3029, /*Added for CAPI tool */ 756 WID_DEVICE_NAME = 0x3029, /*Added for CAPI tool */
758 WID_SET_DRV_HANDLER = 0x3079,
759 757
760 /* NMAC String WID list */ 758 /* NMAC String WID list */
759 WID_SET_OPERATION_MODE = 0x3079,
761 WID_11N_P_ACTION_REQ = 0x3080, 760 WID_11N_P_ACTION_REQ = 0x3080,
762 WID_HUT_TEST_ID = 0x3081, 761 WID_HUT_TEST_ID = 0x3081,
763 WID_PMKID_INFO = 0x3082, 762 WID_PMKID_INFO = 0x3082,
diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
index ab734534093b..28d372a0663a 100644
--- a/drivers/staging/wlan-ng/hfa384x_usb.c
+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
@@ -226,11 +226,9 @@ usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp,
226 226
227/*---------------------------------------------------*/ 227/*---------------------------------------------------*/
228/* Low level req/resp CTLX formatters and submitters */ 228/* Low level req/resp CTLX formatters and submitters */
229static int 229static inline int
230hfa384x_docmd(struct hfa384x *hw, 230hfa384x_docmd(struct hfa384x *hw,
231 enum cmd_mode mode, 231 struct hfa384x_metacmd *cmd);
232 struct hfa384x_metacmd *cmd,
233 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
234 232
235static int 233static int
236hfa384x_dorrid(struct hfa384x *hw, 234hfa384x_dorrid(struct hfa384x *hw,
@@ -250,21 +248,17 @@ hfa384x_dowrid(struct hfa384x *hw,
250 248
251static int 249static int
252hfa384x_dormem(struct hfa384x *hw, 250hfa384x_dormem(struct hfa384x *hw,
253 enum cmd_mode mode,
254 u16 page, 251 u16 page,
255 u16 offset, 252 u16 offset,
256 void *data, 253 void *data,
257 unsigned int len, 254 unsigned int len);
258 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
259 255
260static int 256static int
261hfa384x_dowmem(struct hfa384x *hw, 257hfa384x_dowmem(struct hfa384x *hw,
262 enum cmd_mode mode,
263 u16 page, 258 u16 page,
264 u16 offset, 259 u16 offset,
265 void *data, 260 void *data,
266 unsigned int len, 261 unsigned int len);
267 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
268 262
269static int hfa384x_isgood_pdrcode(u16 pdrcode); 263static int hfa384x_isgood_pdrcode(u16 pdrcode);
270 264
@@ -820,99 +814,6 @@ static void hfa384x_cb_status(struct hfa384x *hw,
820 } 814 }
821} 815}
822 816
823static inline int hfa384x_docmd_wait(struct hfa384x *hw,
824 struct hfa384x_metacmd *cmd)
825{
826 return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL);
827}
828
829static inline int
830hfa384x_docmd_async(struct hfa384x *hw,
831 struct hfa384x_metacmd *cmd,
832 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
833{
834 return hfa384x_docmd(hw, DOASYNC, cmd, cmdcb, usercb, usercb_data);
835}
836
837static inline int
838hfa384x_dorrid_wait(struct hfa384x *hw, u16 rid, void *riddata,
839 unsigned int riddatalen)
840{
841 return hfa384x_dorrid(hw, DOWAIT,
842 rid, riddata, riddatalen, NULL, NULL, NULL);
843}
844
845static inline int
846hfa384x_dorrid_async(struct hfa384x *hw,
847 u16 rid, void *riddata, unsigned int riddatalen,
848 ctlx_cmdcb_t cmdcb,
849 ctlx_usercb_t usercb, void *usercb_data)
850{
851 return hfa384x_dorrid(hw, DOASYNC,
852 rid, riddata, riddatalen,
853 cmdcb, usercb, usercb_data);
854}
855
856static inline int
857hfa384x_dowrid_wait(struct hfa384x *hw, u16 rid, void *riddata,
858 unsigned int riddatalen)
859{
860 return hfa384x_dowrid(hw, DOWAIT,
861 rid, riddata, riddatalen, NULL, NULL, NULL);
862}
863
864static inline int
865hfa384x_dowrid_async(struct hfa384x *hw,
866 u16 rid, void *riddata, unsigned int riddatalen,
867 ctlx_cmdcb_t cmdcb,
868 ctlx_usercb_t usercb, void *usercb_data)
869{
870 return hfa384x_dowrid(hw, DOASYNC,
871 rid, riddata, riddatalen,
872 cmdcb, usercb, usercb_data);
873}
874
875static inline int
876hfa384x_dormem_wait(struct hfa384x *hw,
877 u16 page, u16 offset, void *data, unsigned int len)
878{
879 return hfa384x_dormem(hw, DOWAIT,
880 page, offset, data, len, NULL, NULL, NULL);
881}
882
883static inline int
884hfa384x_dormem_async(struct hfa384x *hw,
885 u16 page, u16 offset, void *data, unsigned int len,
886 ctlx_cmdcb_t cmdcb,
887 ctlx_usercb_t usercb, void *usercb_data)
888{
889 return hfa384x_dormem(hw, DOASYNC,
890 page, offset, data, len,
891 cmdcb, usercb, usercb_data);
892}
893
894static inline int
895hfa384x_dowmem_wait(struct hfa384x *hw,
896 u16 page, u16 offset, void *data, unsigned int len)
897{
898 return hfa384x_dowmem(hw, DOWAIT,
899 page, offset, data, len, NULL, NULL, NULL);
900}
901
902static inline int
903hfa384x_dowmem_async(struct hfa384x *hw,
904 u16 page,
905 u16 offset,
906 void *data,
907 unsigned int len,
908 ctlx_cmdcb_t cmdcb,
909 ctlx_usercb_t usercb, void *usercb_data)
910{
911 return hfa384x_dowmem(hw, DOASYNC,
912 page, offset, data, len,
913 cmdcb, usercb, usercb_data);
914}
915
916/*---------------------------------------------------------------- 817/*----------------------------------------------------------------
917 * hfa384x_cmd_initialize 818 * hfa384x_cmd_initialize
918 * 819 *
@@ -944,7 +845,7 @@ int hfa384x_cmd_initialize(struct hfa384x *hw)
944 cmd.parm1 = 0; 845 cmd.parm1 = 0;
945 cmd.parm2 = 0; 846 cmd.parm2 = 0;
946 847
947 result = hfa384x_docmd_wait(hw, &cmd); 848 result = hfa384x_docmd(hw, &cmd);
948 849
949 pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n", 850 pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n",
950 cmd.result.status, 851 cmd.result.status,
@@ -990,7 +891,7 @@ int hfa384x_cmd_disable(struct hfa384x *hw, u16 macport)
990 cmd.parm1 = 0; 891 cmd.parm1 = 0;
991 cmd.parm2 = 0; 892 cmd.parm2 = 0;
992 893
993 return hfa384x_docmd_wait(hw, &cmd); 894 return hfa384x_docmd(hw, &cmd);
994} 895}
995 896
996/*---------------------------------------------------------------- 897/*----------------------------------------------------------------
@@ -1024,7 +925,7 @@ int hfa384x_cmd_enable(struct hfa384x *hw, u16 macport)
1024 cmd.parm1 = 0; 925 cmd.parm1 = 0;
1025 cmd.parm2 = 0; 926 cmd.parm2 = 0;
1026 927
1027 return hfa384x_docmd_wait(hw, &cmd); 928 return hfa384x_docmd(hw, &cmd);
1028} 929}
1029 930
1030/*---------------------------------------------------------------- 931/*----------------------------------------------------------------
@@ -1067,7 +968,7 @@ int hfa384x_cmd_monitor(struct hfa384x *hw, u16 enable)
1067 cmd.parm1 = 0; 968 cmd.parm1 = 0;
1068 cmd.parm2 = 0; 969 cmd.parm2 = 0;
1069 970
1070 return hfa384x_docmd_wait(hw, &cmd); 971 return hfa384x_docmd(hw, &cmd);
1071} 972}
1072 973
1073/*---------------------------------------------------------------- 974/*----------------------------------------------------------------
@@ -1124,7 +1025,7 @@ int hfa384x_cmd_download(struct hfa384x *hw, u16 mode, u16 lowaddr,
1124 cmd.parm1 = highaddr; 1025 cmd.parm1 = highaddr;
1125 cmd.parm2 = codelen; 1026 cmd.parm2 = codelen;
1126 1027
1127 return hfa384x_docmd_wait(hw, &cmd); 1028 return hfa384x_docmd(hw, &cmd);
1128} 1029}
1129 1030
1130/*---------------------------------------------------------------- 1031/*----------------------------------------------------------------
@@ -1284,13 +1185,8 @@ cleanup:
1284 * 1185 *
1285 * Arguments: 1186 * Arguments:
1286 * hw device structure 1187 * hw device structure
1287 * mode DOWAIT or DOASYNC
1288 * cmd cmd structure. Includes all arguments and result 1188 * cmd cmd structure. Includes all arguments and result
1289 * data points. All in host order. in host order 1189 * data points. All in host order. in host order
1290 * cmdcb command-specific callback
1291 * usercb user callback for async calls, NULL for DOWAIT calls
1292 * usercb_data user supplied data pointer for async calls, NULL
1293 * for DOWAIT calls
1294 * 1190 *
1295 * Returns: 1191 * Returns:
1296 * 0 success 1192 * 0 success
@@ -1306,11 +1202,9 @@ cleanup:
1306 * process 1202 * process
1307 *---------------------------------------------------------------- 1203 *----------------------------------------------------------------
1308 */ 1204 */
1309static int 1205static inline int
1310hfa384x_docmd(struct hfa384x *hw, 1206hfa384x_docmd(struct hfa384x *hw,
1311 enum cmd_mode mode, 1207 struct hfa384x_metacmd *cmd)
1312 struct hfa384x_metacmd *cmd,
1313 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1314{ 1208{
1315 int result; 1209 int result;
1316 struct hfa384x_usbctlx *ctlx; 1210 struct hfa384x_usbctlx *ctlx;
@@ -1333,15 +1227,15 @@ hfa384x_docmd(struct hfa384x *hw,
1333 pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n", 1227 pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
1334 cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2); 1228 cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2);
1335 1229
1336 ctlx->reapable = mode; 1230 ctlx->reapable = DOWAIT;
1337 ctlx->cmdcb = cmdcb; 1231 ctlx->cmdcb = NULL;
1338 ctlx->usercb = usercb; 1232 ctlx->usercb = NULL;
1339 ctlx->usercb_data = usercb_data; 1233 ctlx->usercb_data = NULL;
1340 1234
1341 result = hfa384x_usbctlx_submit(hw, ctlx); 1235 result = hfa384x_usbctlx_submit(hw, ctlx);
1342 if (result != 0) { 1236 if (result != 0) {
1343 kfree(ctlx); 1237 kfree(ctlx);
1344 } else if (mode == DOWAIT) { 1238 } else {
1345 struct usbctlx_cmd_completor cmd_completor; 1239 struct usbctlx_cmd_completor cmd_completor;
1346 struct usbctlx_completor *completor; 1240 struct usbctlx_completor *completor;
1347 1241
@@ -1540,14 +1434,10 @@ done:
1540 * 1434 *
1541 * Arguments: 1435 * Arguments:
1542 * hw device structure 1436 * hw device structure
1543 * mode DOWAIT or DOASYNC
1544 * page MAC address space page (CMD format) 1437 * page MAC address space page (CMD format)
1545 * offset MAC address space offset 1438 * offset MAC address space offset
1546 * data Ptr to data buffer to receive read 1439 * data Ptr to data buffer to receive read
1547 * len Length of the data to read (max == 2048) 1440 * len Length of the data to read (max == 2048)
1548 * cmdcb command callback for async calls, NULL for DOWAIT calls
1549 * usercb user callback for async calls, NULL for DOWAIT calls
1550 * usercb_data user supplied data pointer for async calls
1551 * 1441 *
1552 * Returns: 1442 * Returns:
1553 * 0 success 1443 * 0 success
@@ -1559,18 +1449,15 @@ done:
1559 * Side effects: 1449 * Side effects:
1560 * 1450 *
1561 * Call context: 1451 * Call context:
1562 * interrupt (DOASYNC) 1452 * process (DOWAIT)
1563 * process (DOWAIT or DOASYNC)
1564 *---------------------------------------------------------------- 1453 *----------------------------------------------------------------
1565 */ 1454 */
1566static int 1455static int
1567hfa384x_dormem(struct hfa384x *hw, 1456hfa384x_dormem(struct hfa384x *hw,
1568 enum cmd_mode mode,
1569 u16 page, 1457 u16 page,
1570 u16 offset, 1458 u16 offset,
1571 void *data, 1459 void *data,
1572 unsigned int len, 1460 unsigned int len)
1573 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1574{ 1461{
1575 int result; 1462 int result;
1576 struct hfa384x_usbctlx *ctlx; 1463 struct hfa384x_usbctlx *ctlx;
@@ -1598,15 +1485,15 @@ hfa384x_dormem(struct hfa384x *hw,
1598 1485
1599 pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq))); 1486 pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
1600 1487
1601 ctlx->reapable = mode; 1488 ctlx->reapable = DOWAIT;
1602 ctlx->cmdcb = cmdcb; 1489 ctlx->cmdcb = NULL;
1603 ctlx->usercb = usercb; 1490 ctlx->usercb = NULL;
1604 ctlx->usercb_data = usercb_data; 1491 ctlx->usercb_data = NULL;
1605 1492
1606 result = hfa384x_usbctlx_submit(hw, ctlx); 1493 result = hfa384x_usbctlx_submit(hw, ctlx);
1607 if (result != 0) { 1494 if (result != 0) {
1608 kfree(ctlx); 1495 kfree(ctlx);
1609 } else if (mode == DOWAIT) { 1496 } else {
1610 struct usbctlx_rmem_completor completor; 1497 struct usbctlx_rmem_completor completor;
1611 1498
1612 result = 1499 result =
@@ -1632,14 +1519,10 @@ done:
1632 * 1519 *
1633 * Arguments: 1520 * Arguments:
1634 * hw device structure 1521 * hw device structure
1635 * mode DOWAIT or DOASYNC
1636 * page MAC address space page (CMD format) 1522 * page MAC address space page (CMD format)
1637 * offset MAC address space offset 1523 * offset MAC address space offset
1638 * data Ptr to data buffer containing write data 1524 * data Ptr to data buffer containing write data
1639 * len Length of the data to read (max == 2048) 1525 * len Length of the data to read (max == 2048)
1640 * cmdcb command callback for async calls, NULL for DOWAIT calls
1641 * usercb user callback for async calls, NULL for DOWAIT calls
1642 * usercb_data user supplied data pointer for async calls.
1643 * 1526 *
1644 * Returns: 1527 * Returns:
1645 * 0 success 1528 * 0 success
@@ -1652,17 +1535,15 @@ done:
1652 * 1535 *
1653 * Call context: 1536 * Call context:
1654 * interrupt (DOWAIT) 1537 * interrupt (DOWAIT)
1655 * process (DOWAIT or DOASYNC) 1538 * process (DOWAIT)
1656 *---------------------------------------------------------------- 1539 *----------------------------------------------------------------
1657 */ 1540 */
1658static int 1541static int
1659hfa384x_dowmem(struct hfa384x *hw, 1542hfa384x_dowmem(struct hfa384x *hw,
1660 enum cmd_mode mode,
1661 u16 page, 1543 u16 page,
1662 u16 offset, 1544 u16 offset,
1663 void *data, 1545 void *data,
1664 unsigned int len, 1546 unsigned int len)
1665 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1666{ 1547{
1667 int result; 1548 int result;
1668 struct hfa384x_usbctlx *ctlx; 1549 struct hfa384x_usbctlx *ctlx;
@@ -1689,15 +1570,15 @@ hfa384x_dowmem(struct hfa384x *hw,
1689 sizeof(ctlx->outbuf.wmemreq.offset) + 1570 sizeof(ctlx->outbuf.wmemreq.offset) +
1690 sizeof(ctlx->outbuf.wmemreq.page) + len; 1571 sizeof(ctlx->outbuf.wmemreq.page) + len;
1691 1572
1692 ctlx->reapable = mode; 1573 ctlx->reapable = DOWAIT;
1693 ctlx->cmdcb = cmdcb; 1574 ctlx->cmdcb = NULL;
1694 ctlx->usercb = usercb; 1575 ctlx->usercb = NULL;
1695 ctlx->usercb_data = usercb_data; 1576 ctlx->usercb_data = NULL;
1696 1577
1697 result = hfa384x_usbctlx_submit(hw, ctlx); 1578 result = hfa384x_usbctlx_submit(hw, ctlx);
1698 if (result != 0) { 1579 if (result != 0) {
1699 kfree(ctlx); 1580 kfree(ctlx);
1700 } else if (mode == DOWAIT) { 1581 } else {
1701 struct usbctlx_cmd_completor completor; 1582 struct usbctlx_cmd_completor completor;
1702 struct hfa384x_cmdresult wmemresult; 1583 struct hfa384x_cmdresult wmemresult;
1703 1584
@@ -2004,10 +1885,10 @@ int hfa384x_drvr_flashdl_write(struct hfa384x *hw, u32 daddr,
2004 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ? 1885 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
2005 HFA384x_USB_RWMEM_MAXLEN : writelen; 1886 HFA384x_USB_RWMEM_MAXLEN : writelen;
2006 1887
2007 result = hfa384x_dowmem_wait(hw, 1888 result = hfa384x_dowmem(hw,
2008 writepage, 1889 writepage,
2009 writeoffset, 1890 writeoffset,
2010 writebuf, writelen); 1891 writebuf, writelen);
2011 } 1892 }
2012 1893
2013 /* set the download 'write flash' mode */ 1894 /* set the download 'write flash' mode */
@@ -2061,7 +1942,7 @@ exit_proc:
2061 */ 1942 */
2062int hfa384x_drvr_getconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len) 1943int hfa384x_drvr_getconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len)
2063{ 1944{
2064 return hfa384x_dorrid_wait(hw, rid, buf, len); 1945 return hfa384x_dorrid(hw, DOWAIT, rid, buf, len, NULL, NULL, NULL);
2065} 1946}
2066 1947
2067/*---------------------------------------------------------------- 1948/*----------------------------------------------------------------
@@ -2094,8 +1975,8 @@ hfa384x_drvr_setconfig_async(struct hfa384x *hw,
2094 void *buf, 1975 void *buf,
2095 u16 len, ctlx_usercb_t usercb, void *usercb_data) 1976 u16 len, ctlx_usercb_t usercb, void *usercb_data)
2096{ 1977{
2097 return hfa384x_dowrid_async(hw, rid, buf, len, 1978 return hfa384x_dowrid(hw, DOASYNC, rid, buf, len, hfa384x_cb_status,
2098 hfa384x_cb_status, usercb, usercb_data); 1979 usercb, usercb_data);
2099} 1980}
2100 1981
2101/*---------------------------------------------------------------- 1982/*----------------------------------------------------------------
@@ -2261,12 +2142,11 @@ int hfa384x_drvr_ramdl_write(struct hfa384x *hw, u32 daddr, void *buf, u32 len)
2261 currlen = HFA384x_USB_RWMEM_MAXLEN; 2142 currlen = HFA384x_USB_RWMEM_MAXLEN;
2262 2143
2263 /* Do blocking ctlx */ 2144 /* Do blocking ctlx */
2264 result = hfa384x_dowmem_wait(hw, 2145 result = hfa384x_dowmem(hw,
2265 currpage, 2146 currpage,
2266 curroffset, 2147 curroffset,
2267 data + 2148 data + (i * HFA384x_USB_RWMEM_MAXLEN),
2268 (i * HFA384x_USB_RWMEM_MAXLEN), 2149 currlen);
2269 currlen);
2270 2150
2271 if (result) 2151 if (result)
2272 break; 2152 break;
@@ -2338,8 +2218,8 @@ int hfa384x_drvr_readpda(struct hfa384x *hw, void *buf, unsigned int len)
2338 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr); 2218 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
2339 2219
2340 /* units of bytes */ 2220 /* units of bytes */
2341 result = hfa384x_dormem_wait(hw, currpage, curroffset, buf, 2221 result = hfa384x_dormem(hw, currpage, curroffset, buf,
2342 len); 2222 len);
2343 2223
2344 if (result) { 2224 if (result) {
2345 netdev_warn(hw->wlandev->netdev, 2225 netdev_warn(hw->wlandev->netdev,
@@ -2422,7 +2302,7 @@ int hfa384x_drvr_readpda(struct hfa384x *hw, void *buf, unsigned int len)
2422 */ 2302 */
2423int hfa384x_drvr_setconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len) 2303int hfa384x_drvr_setconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len)
2424{ 2304{
2425 return hfa384x_dowrid_wait(hw, rid, buf, len); 2305 return hfa384x_dowrid(hw, DOWAIT, rid, buf, len, NULL, NULL, NULL);
2426} 2306}
2427 2307
2428/*---------------------------------------------------------------- 2308/*----------------------------------------------------------------
diff --git a/drivers/staging/wlan-ng/prism2mib.c b/drivers/staging/wlan-ng/prism2mib.c
index 1eba5fa28d8f..7d7d77b04255 100644
--- a/drivers/staging/wlan-ng/prism2mib.c
+++ b/drivers/staging/wlan-ng/prism2mib.c
@@ -126,13 +126,6 @@ static int prism2mib_privacyinvoked(struct mibrec *mib,
126 struct p80211msg_dot11req_mibset *msg, 126 struct p80211msg_dot11req_mibset *msg,
127 void *data); 127 void *data);
128 128
129static int prism2mib_excludeunencrypted(struct mibrec *mib,
130 int isget,
131 struct wlandevice *wlandev,
132 struct hfa384x *hw,
133 struct p80211msg_dot11req_mibset *msg,
134 void *data);
135
136static int 129static int
137prism2mib_fragmentationthreshold(struct mibrec *mib, 130prism2mib_fragmentationthreshold(struct mibrec *mib,
138 int isget, 131 int isget,
@@ -176,7 +169,7 @@ static struct mibrec mibtab[] = {
176 {DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED, 169 {DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED,
177 F_STA | F_READ | F_WRITE, 170 F_STA | F_READ | F_WRITE,
178 HFA384x_RID_CNFWEPFLAGS, HFA384x_WEPFLAGS_EXCLUDE, 0, 171 HFA384x_RID_CNFWEPFLAGS, HFA384x_WEPFLAGS_EXCLUDE, 0,
179 prism2mib_excludeunencrypted}, 172 prism2mib_flag},
180 173
181 /* dot11mac MIB's */ 174 /* dot11mac MIB's */
182 175
@@ -594,41 +587,6 @@ static int prism2mib_privacyinvoked(struct mibrec *mib,
594} 587}
595 588
596/* 589/*
597 * prism2mib_excludeunencrypted
598 *
599 * Get/set the dot11ExcludeUnencrypted value.
600 *
601 * MIB record parameters:
602 * parm1 Prism2 RID value.
603 * parm2 Bit value for ExcludeUnencrypted flag.
604 * parm3 Not used.
605 *
606 * Arguments:
607 * mib MIB record.
608 * isget MIBGET/MIBSET flag.
609 * wlandev wlan device structure.
610 * priv "priv" structure.
611 * hw "hw" structure.
612 * msg Message structure.
613 * data Data buffer.
614 *
615 * Returns:
616 * 0 - Success.
617 * ~0 - Error.
618 *
619 */
620
621static int prism2mib_excludeunencrypted(struct mibrec *mib,
622 int isget,
623 struct wlandevice *wlandev,
624 struct hfa384x *hw,
625 struct p80211msg_dot11req_mibset *msg,
626 void *data)
627{
628 return prism2mib_flag(mib, isget, wlandev, hw, msg, data);
629}
630
631/*
632 * prism2mib_fragmentationthreshold 590 * prism2mib_fragmentationthreshold
633 * 591 *
634 * Get/set the fragmentation threshold. 592 * Get/set the fragmentation threshold.
diff --git a/drivers/staging/wlan-ng/prism2sta.c b/drivers/staging/wlan-ng/prism2sta.c
index fb5441399131..8f25496188aa 100644
--- a/drivers/staging/wlan-ng/prism2sta.c
+++ b/drivers/staging/wlan-ng/prism2sta.c
@@ -846,7 +846,7 @@ static int prism2sta_getcardinfo(struct wlandevice *wlandev)
846 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICSERIALNUMBER, 846 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICSERIALNUMBER,
847 snum, HFA384x_RID_NICSERIALNUMBER_LEN); 847 snum, HFA384x_RID_NICSERIALNUMBER_LEN);
848 if (!result) { 848 if (!result) {
849 netdev_info(wlandev->netdev, "Prism2 card SN: %*pEhp\n", 849 netdev_info(wlandev->netdev, "Prism2 card SN: %*pE\n",
850 HFA384x_RID_NICSERIALNUMBER_LEN, snum); 850 HFA384x_RID_NICSERIALNUMBER_LEN, snum);
851 } else { 851 } else {
852 netdev_err(wlandev->netdev, "Failed to retrieve Prism2 Card SN\n"); 852 netdev_err(wlandev->netdev, "Failed to retrieve Prism2 Card SN\n");
diff --git a/fs/Kconfig b/fs/Kconfig
index bfb1c6095c7a..669d46550e6d 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -261,6 +261,7 @@ source "fs/romfs/Kconfig"
261source "fs/pstore/Kconfig" 261source "fs/pstore/Kconfig"
262source "fs/sysv/Kconfig" 262source "fs/sysv/Kconfig"
263source "fs/ufs/Kconfig" 263source "fs/ufs/Kconfig"
264source "fs/erofs/Kconfig"
264 265
265endif # MISC_FILESYSTEMS 266endif # MISC_FILESYSTEMS
266 267
diff --git a/fs/Makefile b/fs/Makefile
index d60089fd689b..b2e4973a0bea 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -130,3 +130,4 @@ obj-$(CONFIG_F2FS_FS) += f2fs/
130obj-$(CONFIG_CEPH_FS) += ceph/ 130obj-$(CONFIG_CEPH_FS) += ceph/
131obj-$(CONFIG_PSTORE) += pstore/ 131obj-$(CONFIG_PSTORE) += pstore/
132obj-$(CONFIG_EFIVAR_FS) += efivarfs/ 132obj-$(CONFIG_EFIVAR_FS) += efivarfs/
133obj-$(CONFIG_EROFS_FS) += erofs/
diff --git a/fs/erofs/Kconfig b/fs/erofs/Kconfig
new file mode 100644
index 000000000000..9d634d3a1845
--- /dev/null
+++ b/fs/erofs/Kconfig
@@ -0,0 +1,91 @@
1# SPDX-License-Identifier: GPL-2.0-only
2
3config EROFS_FS
4 tristate "EROFS filesystem support"
5 depends on BLOCK
6 help
7 EROFS (Enhanced Read-Only File System) is a lightweight
8 read-only file system with modern designs (eg. page-sized
9 blocks, inline xattrs/data, etc.) for scenarios which need
10 high-performance read-only requirements, e.g. Android OS
11 for mobile phones and LIVECDs.
12
13 It also provides fixed-sized output compression support,
14 which improves storage density, keeps relatively higher
15 compression ratios, which is more useful to achieve high
16 performance for embedded devices with limited memory.
17
18 If unsure, say N.
19
20config EROFS_FS_DEBUG
21 bool "EROFS debugging feature"
22 depends on EROFS_FS
23 help
24 Print debugging messages and enable more BUG_ONs which check
25 filesystem consistency and find potential issues aggressively,
26 which can be used for Android eng build, for example.
27
28 For daily use, say N.
29
30config EROFS_FS_XATTR
31 bool "EROFS extended attributes"
32 depends on EROFS_FS
33 default y
34 help
35 Extended attributes are name:value pairs associated with inodes by
36 the kernel or by users (see the attr(5) manual page, or visit
37 <http://acl.bestbits.at/> for details).
38
39 If unsure, say N.
40
41config EROFS_FS_POSIX_ACL
42 bool "EROFS Access Control Lists"
43 depends on EROFS_FS_XATTR
44 select FS_POSIX_ACL
45 default y
46 help
47 Posix Access Control Lists (ACLs) support permissions for users and
48 groups beyond the owner/group/world scheme.
49
50 To learn more about Access Control Lists, visit the POSIX ACLs for
51 Linux website <http://acl.bestbits.at/>.
52
53 If you don't know what Access Control Lists are, say N.
54
55config EROFS_FS_SECURITY
56 bool "EROFS Security Labels"
57 depends on EROFS_FS_XATTR
58 default y
59 help
60 Security labels provide an access control facility to support Linux
61 Security Models (LSMs) accepted by AppArmor, SELinux, Smack and TOMOYO
62 Linux. This option enables an extended attribute handler for file
63 security labels in the erofs filesystem, so that it requires enabling
64 the extended attribute support in advance.
65
66 If you are not using a security module, say N.
67
68config EROFS_FS_ZIP
69 bool "EROFS Data Compression Support"
70 depends on EROFS_FS
71 select LZ4_DECOMPRESS
72 default y
73 help
74 Enable fixed-sized output compression for EROFS.
75
76 If you don't want to enable compression feature, say N.
77
78config EROFS_FS_CLUSTER_PAGE_LIMIT
79 int "EROFS Cluster Pages Hard Limit"
80 depends on EROFS_FS_ZIP
81 range 1 256
82 default "1"
83 help
84 Indicates maximum # of pages of a compressed
85 physical cluster.
86
87 For example, if files in a image were compressed
88 into 8k-unit, hard limit should not be configured
89 less than 2. Otherwise, the image will be refused
90 to mount on this kernel.
91
diff --git a/fs/erofs/Makefile b/fs/erofs/Makefile
new file mode 100644
index 000000000000..46f2aa4ba46c
--- /dev/null
+++ b/fs/erofs/Makefile
@@ -0,0 +1,11 @@
1# SPDX-License-Identifier: GPL-2.0-only
2
3EROFS_VERSION = "1.0"
4
5ccflags-y += -DEROFS_VERSION=\"$(EROFS_VERSION)\"
6
7obj-$(CONFIG_EROFS_FS) += erofs.o
8erofs-objs := super.o inode.o data.o namei.o dir.o utils.o
9erofs-$(CONFIG_EROFS_FS_XATTR) += xattr.o
10erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o
11
diff --git a/drivers/staging/erofs/compress.h b/fs/erofs/compress.h
index c43aa3374d28..07d279fd5d67 100644
--- a/drivers/staging/erofs/compress.h
+++ b/fs/erofs/compress.h
@@ -1,7 +1,5 @@
1/* SPDX-License-Identifier: GPL-2.0 */ 1/* SPDX-License-Identifier: GPL-2.0-only */
2/* 2/*
3 * linux/drivers/staging/erofs/compress.h
4 *
5 * Copyright (C) 2019 HUAWEI, Inc. 3 * Copyright (C) 2019 HUAWEI, Inc.
6 * http://www.huawei.com/ 4 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com> 5 * Created by Gao Xiang <gaoxiang25@huawei.com>
diff --git a/drivers/staging/erofs/data.c b/fs/erofs/data.c
index cc31c3e5984c..8a9fcbd0e8ac 100644
--- a/drivers/staging/erofs/data.c
+++ b/fs/erofs/data.c
@@ -1,39 +1,27 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0-only
2/* 2/*
3 * linux/drivers/staging/erofs/data.c
4 *
5 * Copyright (C) 2017-2018 HUAWEI, Inc. 3 * Copyright (C) 2017-2018 HUAWEI, Inc.
6 * http://www.huawei.com/ 4 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com> 5 * Created by Gao Xiang <gaoxiang25@huawei.com>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of the Linux
11 * distribution for more details.
12 */ 6 */
13#include "internal.h" 7#include "internal.h"
14#include <linux/prefetch.h> 8#include <linux/prefetch.h>
15 9
16#include <trace/events/erofs.h> 10#include <trace/events/erofs.h>
17 11
18static inline void read_endio(struct bio *bio) 12static void erofs_readendio(struct bio *bio)
19{ 13{
20 struct super_block *const sb = bio->bi_private;
21 struct bio_vec *bvec; 14 struct bio_vec *bvec;
22 blk_status_t err = bio->bi_status; 15 blk_status_t err = bio->bi_status;
23 struct bvec_iter_all iter_all; 16 struct bvec_iter_all iter_all;
24 17
25 if (time_to_inject(EROFS_SB(sb), FAULT_READ_IO)) {
26 erofs_show_injection_info(FAULT_READ_IO);
27 err = BLK_STS_IOERR;
28 }
29
30 bio_for_each_segment_all(bvec, bio, iter_all) { 18 bio_for_each_segment_all(bvec, bio, iter_all) {
31 struct page *page = bvec->bv_page; 19 struct page *page = bvec->bv_page;
32 20
33 /* page is already locked */ 21 /* page is already locked */
34 DBG_BUGON(PageUptodate(page)); 22 DBG_BUGON(PageUptodate(page));
35 23
36 if (unlikely(err)) 24 if (err)
37 SetPageError(page); 25 SetPageError(page);
38 else 26 else
39 SetPageUptodate(page); 27 SetPageUptodate(page);
@@ -44,72 +32,13 @@ static inline void read_endio(struct bio *bio)
44 bio_put(bio); 32 bio_put(bio);
45} 33}
46 34
47/* prio -- true is used for dir */ 35struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr)
48struct page *__erofs_get_meta_page(struct super_block *sb,
49 erofs_blk_t blkaddr, bool prio, bool nofail)
50{ 36{
51 struct inode *const bd_inode = sb->s_bdev->bd_inode; 37 struct inode *const bd_inode = sb->s_bdev->bd_inode;
52 struct address_space *const mapping = bd_inode->i_mapping; 38 struct address_space *const mapping = bd_inode->i_mapping;
53 /* prefer retrying in the allocator to blindly looping below */
54 const gfp_t gfp = mapping_gfp_constraint(mapping, ~__GFP_FS) |
55 (nofail ? __GFP_NOFAIL : 0);
56 unsigned int io_retries = nofail ? EROFS_IO_MAX_RETRIES_NOFAIL : 0;
57 struct page *page;
58 int err;
59
60repeat:
61 page = find_or_create_page(mapping, blkaddr, gfp);
62 if (unlikely(!page)) {
63 DBG_BUGON(nofail);
64 return ERR_PTR(-ENOMEM);
65 }
66 DBG_BUGON(!PageLocked(page));
67
68 if (!PageUptodate(page)) {
69 struct bio *bio;
70
71 bio = erofs_grab_bio(sb, blkaddr, 1, sb, read_endio, nofail);
72 if (IS_ERR(bio)) {
73 DBG_BUGON(nofail);
74 err = PTR_ERR(bio);
75 goto err_out;
76 }
77
78 err = bio_add_page(bio, page, PAGE_SIZE, 0);
79 if (unlikely(err != PAGE_SIZE)) {
80 err = -EFAULT;
81 goto err_out;
82 }
83 39
84 __submit_bio(bio, REQ_OP_READ, 40 return read_cache_page_gfp(mapping, blkaddr,
85 REQ_META | (prio ? REQ_PRIO : 0)); 41 mapping_gfp_constraint(mapping, ~__GFP_FS));
86
87 lock_page(page);
88
89 /* this page has been truncated by others */
90 if (unlikely(page->mapping != mapping)) {
91unlock_repeat:
92 unlock_page(page);
93 put_page(page);
94 goto repeat;
95 }
96
97 /* more likely a read error */
98 if (unlikely(!PageUptodate(page))) {
99 if (io_retries) {
100 --io_retries;
101 goto unlock_repeat;
102 }
103 err = -EIO;
104 goto err_out;
105 }
106 }
107 return page;
108
109err_out:
110 unlock_page(page);
111 put_page(page);
112 return ERR_PTR(err);
113} 42}
114 43
115static int erofs_map_blocks_flatmode(struct inode *inode, 44static int erofs_map_blocks_flatmode(struct inode *inode,
@@ -119,14 +48,15 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
119 int err = 0; 48 int err = 0;
120 erofs_blk_t nblocks, lastblk; 49 erofs_blk_t nblocks, lastblk;
121 u64 offset = map->m_la; 50 u64 offset = map->m_la;
122 struct erofs_vnode *vi = EROFS_V(inode); 51 struct erofs_inode *vi = EROFS_I(inode);
52 bool tailendpacking = (vi->datalayout == EROFS_INODE_FLAT_INLINE);
123 53
124 trace_erofs_map_blocks_flatmode_enter(inode, map, flags); 54 trace_erofs_map_blocks_flatmode_enter(inode, map, flags);
125 55
126 nblocks = DIV_ROUND_UP(inode->i_size, PAGE_SIZE); 56 nblocks = DIV_ROUND_UP(inode->i_size, PAGE_SIZE);
127 lastblk = nblocks - is_inode_flat_inline(inode); 57 lastblk = nblocks - tailendpacking;
128 58
129 if (unlikely(offset >= inode->i_size)) { 59 if (offset >= inode->i_size) {
130 /* leave out-of-bound access unmapped */ 60 /* leave out-of-bound access unmapped */
131 map->m_flags = 0; 61 map->m_flags = 0;
132 map->m_plen = 0; 62 map->m_plen = 0;
@@ -139,7 +69,7 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
139 if (offset < blknr_to_addr(lastblk)) { 69 if (offset < blknr_to_addr(lastblk)) {
140 map->m_pa = blknr_to_addr(vi->raw_blkaddr) + map->m_la; 70 map->m_pa = blknr_to_addr(vi->raw_blkaddr) + map->m_la;
141 map->m_plen = blknr_to_addr(lastblk) - offset; 71 map->m_plen = blknr_to_addr(lastblk) - offset;
142 } else if (is_inode_flat_inline(inode)) { 72 } else if (tailendpacking) {
143 /* 2 - inode inline B: inode, [xattrs], inline last blk... */ 73 /* 2 - inode inline B: inode, [xattrs], inline last blk... */
144 struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); 74 struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
145 75
@@ -147,17 +77,21 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
147 vi->xattr_isize + erofs_blkoff(map->m_la); 77 vi->xattr_isize + erofs_blkoff(map->m_la);
148 map->m_plen = inode->i_size - offset; 78 map->m_plen = inode->i_size - offset;
149 79
150 /* inline data should locate in one meta block */ 80 /* inline data should be located in one meta block */
151 if (erofs_blkoff(map->m_pa) + map->m_plen > PAGE_SIZE) { 81 if (erofs_blkoff(map->m_pa) + map->m_plen > PAGE_SIZE) {
82 erofs_err(inode->i_sb,
83 "inline data cross block boundary @ nid %llu",
84 vi->nid);
152 DBG_BUGON(1); 85 DBG_BUGON(1);
153 err = -EIO; 86 err = -EFSCORRUPTED;
154 goto err_out; 87 goto err_out;
155 } 88 }
156 89
157 map->m_flags |= EROFS_MAP_META; 90 map->m_flags |= EROFS_MAP_META;
158 } else { 91 } else {
159 errln("internal error @ nid: %llu (size %llu), m_la 0x%llx", 92 erofs_err(inode->i_sb,
160 vi->nid, inode->i_size, map->m_la); 93 "internal error @ nid: %llu (size %llu), m_la 0x%llx",
94 vi->nid, inode->i_size, map->m_la);
161 DBG_BUGON(1); 95 DBG_BUGON(1);
162 err = -EIO; 96 err = -EIO;
163 goto err_out; 97 goto err_out;
@@ -174,7 +108,7 @@ err_out:
174int erofs_map_blocks(struct inode *inode, 108int erofs_map_blocks(struct inode *inode,
175 struct erofs_map_blocks *map, int flags) 109 struct erofs_map_blocks *map, int flags)
176{ 110{
177 if (unlikely(is_inode_layout_compression(inode))) { 111 if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout)) {
178 int err = z_erofs_map_blocks_iter(inode, map, flags); 112 int err = z_erofs_map_blocks_iter(inode, map, flags);
179 113
180 if (map->mpage) { 114 if (map->mpage) {
@@ -205,18 +139,12 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio,
205 goto has_updated; 139 goto has_updated;
206 } 140 }
207 141
208 if (cleancache_get_page(page) == 0) {
209 err = 0;
210 SetPageUptodate(page);
211 goto has_updated;
212 }
213
214 /* note that for readpage case, bio also equals to NULL */ 142 /* note that for readpage case, bio also equals to NULL */
215 if (bio && 143 if (bio &&
216 /* not continuous */ 144 /* not continuous */
217 *last_block + 1 != current_block) { 145 *last_block + 1 != current_block) {
218submit_bio_retry: 146submit_bio_retry:
219 __submit_bio(bio, REQ_OP_READ, 0); 147 submit_bio(bio);
220 bio = NULL; 148 bio = NULL;
221 } 149 }
222 150
@@ -228,11 +156,11 @@ submit_bio_retry:
228 unsigned int blkoff; 156 unsigned int blkoff;
229 157
230 err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW); 158 err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
231 if (unlikely(err)) 159 if (err)
232 goto err_out; 160 goto err_out;
233 161
234 /* zero out the holed page */ 162 /* zero out the holed page */
235 if (unlikely(!(map.m_flags & EROFS_MAP_MAPPED))) { 163 if (!(map.m_flags & EROFS_MAP_MAPPED)) {
236 zero_user_segment(page, 0, PAGE_SIZE); 164 zero_user_segment(page, 0, PAGE_SIZE);
237 SetPageUptodate(page); 165 SetPageUptodate(page);
238 166
@@ -253,7 +181,7 @@ submit_bio_retry:
253 181
254 DBG_BUGON(map.m_plen > PAGE_SIZE); 182 DBG_BUGON(map.m_plen > PAGE_SIZE);
255 183
256 ipage = erofs_get_meta_page(inode->i_sb, blknr, 0); 184 ipage = erofs_get_meta_page(inode->i_sb, blknr);
257 185
258 if (IS_ERR(ipage)) { 186 if (IS_ERR(ipage)) {
259 err = PTR_ERR(ipage); 187 err = PTR_ERR(ipage);
@@ -286,13 +214,13 @@ submit_bio_retry:
286 if (nblocks > BIO_MAX_PAGES) 214 if (nblocks > BIO_MAX_PAGES)
287 nblocks = BIO_MAX_PAGES; 215 nblocks = BIO_MAX_PAGES;
288 216
289 bio = erofs_grab_bio(sb, blknr, nblocks, sb, 217 bio = bio_alloc(GFP_NOIO, nblocks);
290 read_endio, false); 218
291 if (IS_ERR(bio)) { 219 bio->bi_end_io = erofs_readendio;
292 err = PTR_ERR(bio); 220 bio_set_dev(bio, sb->s_bdev);
293 bio = NULL; 221 bio->bi_iter.bi_sector = (sector_t)blknr <<
294 goto err_out; 222 LOG_SECTORS_PER_BLOCK;
295 } 223 bio->bi_opf = REQ_OP_READ;
296 } 224 }
297 225
298 err = bio_add_page(bio, page, PAGE_SIZE, 0); 226 err = bio_add_page(bio, page, PAGE_SIZE, 0);
@@ -323,9 +251,8 @@ has_updated:
323 /* if updated manually, continuous pages has a gap */ 251 /* if updated manually, continuous pages has a gap */
324 if (bio) 252 if (bio)
325submit_bio_out: 253submit_bio_out:
326 __submit_bio(bio, REQ_OP_READ, 0); 254 submit_bio(bio);
327 255 return err ? ERR_PTR(err) : NULL;
328 return unlikely(err) ? ERR_PTR(err) : NULL;
329} 256}
330 257
331/* 258/*
@@ -375,7 +302,7 @@ static int erofs_raw_access_readpages(struct file *filp,
375 if (IS_ERR(bio)) { 302 if (IS_ERR(bio)) {
376 pr_err("%s, readahead error at page %lu of nid %llu\n", 303 pr_err("%s, readahead error at page %lu of nid %llu\n",
377 __func__, page->index, 304 __func__, page->index,
378 EROFS_V(mapping->host)->nid); 305 EROFS_I(mapping->host)->nid);
379 306
380 bio = NULL; 307 bio = NULL;
381 } 308 }
@@ -387,14 +314,47 @@ static int erofs_raw_access_readpages(struct file *filp,
387 DBG_BUGON(!list_empty(pages)); 314 DBG_BUGON(!list_empty(pages));
388 315
389 /* the rare case (end in gaps) */ 316 /* the rare case (end in gaps) */
390 if (unlikely(bio)) 317 if (bio)
391 __submit_bio(bio, REQ_OP_READ, 0); 318 submit_bio(bio);
392 return 0; 319 return 0;
393} 320}
394 321
322static int erofs_get_block(struct inode *inode, sector_t iblock,
323 struct buffer_head *bh, int create)
324{
325 struct erofs_map_blocks map = {
326 .m_la = iblock << 9,
327 };
328 int err;
329
330 err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
331 if (err)
332 return err;
333
334 if (map.m_flags & EROFS_MAP_MAPPED)
335 bh->b_blocknr = erofs_blknr(map.m_pa);
336
337 return err;
338}
339
340static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
341{
342 struct inode *inode = mapping->host;
343
344 if (EROFS_I(inode)->datalayout == EROFS_INODE_FLAT_INLINE) {
345 erofs_blk_t blks = i_size_read(inode) >> LOG_BLOCK_SIZE;
346
347 if (block >> LOG_SECTORS_PER_BLOCK >= blks)
348 return 0;
349 }
350
351 return generic_block_bmap(mapping, block, erofs_get_block);
352}
353
395/* for uncompressed (aligned) files and raw access for other files */ 354/* for uncompressed (aligned) files and raw access for other files */
396const struct address_space_operations erofs_raw_access_aops = { 355const struct address_space_operations erofs_raw_access_aops = {
397 .readpage = erofs_raw_access_readpage, 356 .readpage = erofs_raw_access_readpage,
398 .readpages = erofs_raw_access_readpages, 357 .readpages = erofs_raw_access_readpages,
358 .bmap = erofs_bmap,
399}; 359};
400 360
diff --git a/drivers/staging/erofs/decompressor.c b/fs/erofs/decompressor.c
index 1fb0abb98dff..19f89f9fb10c 100644
--- a/drivers/staging/erofs/decompressor.c
+++ b/fs/erofs/decompressor.c
@@ -1,12 +1,11 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0-only
2/* 2/*
3 * linux/drivers/staging/erofs/decompressor.c
4 *
5 * Copyright (C) 2019 HUAWEI, Inc. 3 * Copyright (C) 2019 HUAWEI, Inc.
6 * http://www.huawei.com/ 4 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com> 5 * Created by Gao Xiang <gaoxiang25@huawei.com>
8 */ 6 */
9#include "compress.h" 7#include "compress.h"
8#include <linux/module.h>
10#include <linux/lz4.h> 9#include <linux/lz4.h>
11 10
12#ifndef LZ4_DISTANCE_MAX /* history window size */ 11#ifndef LZ4_DISTANCE_MAX /* history window size */
@@ -29,8 +28,8 @@ struct z_erofs_decompressor {
29 char *name; 28 char *name;
30}; 29};
31 30
32static int lz4_prepare_destpages(struct z_erofs_decompress_req *rq, 31static int z_erofs_lz4_prepare_destpages(struct z_erofs_decompress_req *rq,
33 struct list_head *pagepool) 32 struct list_head *pagepool)
34{ 33{
35 const unsigned int nr = 34 const unsigned int nr =
36 PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT; 35 PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
@@ -74,15 +73,9 @@ static int lz4_prepare_destpages(struct z_erofs_decompress_req *rq,
74 victim = availables[--top]; 73 victim = availables[--top];
75 get_page(victim); 74 get_page(victim);
76 } else { 75 } else {
77 if (!list_empty(pagepool)) { 76 victim = erofs_allocpage(pagepool, GFP_KERNEL, false);
78 victim = lru_to_page(pagepool); 77 if (!victim)
79 list_del(&victim->lru); 78 return -ENOMEM;
80 DBG_BUGON(page_ref_count(victim) != 1);
81 } else {
82 victim = alloc_pages(GFP_KERNEL, 0);
83 if (!victim)
84 return -ENOMEM;
85 }
86 victim->mapping = Z_EROFS_MAPPING_STAGING; 79 victim->mapping = Z_EROFS_MAPPING_STAGING;
87 } 80 }
88 rq->out[i] = victim; 81 rq->out[i] = victim;
@@ -117,7 +110,7 @@ static void *generic_copy_inplace_data(struct z_erofs_decompress_req *rq,
117 return tmp; 110 return tmp;
118} 111}
119 112
120static int lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out) 113static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out)
121{ 114{
122 unsigned int inputmargin, inlen; 115 unsigned int inputmargin, inlen;
123 u8 *src; 116 u8 *src;
@@ -125,14 +118,15 @@ static int lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out)
125 int ret; 118 int ret;
126 119
127 if (rq->inputsize > PAGE_SIZE) 120 if (rq->inputsize > PAGE_SIZE)
128 return -ENOTSUPP; 121 return -EOPNOTSUPP;
129 122
130 src = kmap_atomic(*rq->in); 123 src = kmap_atomic(*rq->in);
131 inputmargin = 0; 124 inputmargin = 0;
132 support_0padding = false; 125 support_0padding = false;
133 126
134 /* decompression inplace is only safe when 0padding is enabled */ 127 /* decompression inplace is only safe when 0padding is enabled */
135 if (EROFS_SB(rq->sb)->requirements & EROFS_REQUIREMENT_LZ4_0PADDING) { 128 if (EROFS_SB(rq->sb)->feature_incompat &
129 EROFS_FEATURE_INCOMPAT_LZ4_0PADDING) {
136 support_0padding = true; 130 support_0padding = true;
137 131
138 while (!src[inputmargin & ~PAGE_MASK]) 132 while (!src[inputmargin & ~PAGE_MASK])
@@ -167,9 +161,8 @@ static int lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out)
167 inlen, rq->outputsize, 161 inlen, rq->outputsize,
168 rq->outputsize); 162 rq->outputsize);
169 if (ret < 0) { 163 if (ret < 0) {
170 errln("%s, failed to decompress, in[%p, %u, %u] out[%p, %u]", 164 erofs_err(rq->sb, "failed to decompress, in[%u, %u] out[%u]",
171 __func__, src + inputmargin, inlen, inputmargin, 165 inlen, inputmargin, rq->outputsize);
172 out, rq->outputsize);
173 WARN_ON(1); 166 WARN_ON(1);
174 print_hex_dump(KERN_DEBUG, "[ in]: ", DUMP_PREFIX_OFFSET, 167 print_hex_dump(KERN_DEBUG, "[ in]: ", DUMP_PREFIX_OFFSET,
175 16, 1, src + inputmargin, inlen, true); 168 16, 1, src + inputmargin, inlen, true);
@@ -190,8 +183,8 @@ static struct z_erofs_decompressor decompressors[] = {
190 .name = "shifted" 183 .name = "shifted"
191 }, 184 },
192 [Z_EROFS_COMPRESSION_LZ4] = { 185 [Z_EROFS_COMPRESSION_LZ4] = {
193 .prepare_destpages = lz4_prepare_destpages, 186 .prepare_destpages = z_erofs_lz4_prepare_destpages,
194 .decompress = lz4_decompress, 187 .decompress = z_erofs_lz4_decompress,
195 .name = "lz4" 188 .name = "lz4"
196 }, 189 },
197}; 190};
@@ -223,15 +216,15 @@ static void copy_from_pcpubuf(struct page **out, const char *dst,
223 } 216 }
224} 217}
225 218
226static int decompress_generic(struct z_erofs_decompress_req *rq, 219static int z_erofs_decompress_generic(struct z_erofs_decompress_req *rq,
227 struct list_head *pagepool) 220 struct list_head *pagepool)
228{ 221{
229 const unsigned int nrpages_out = 222 const unsigned int nrpages_out =
230 PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT; 223 PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
231 const struct z_erofs_decompressor *alg = decompressors + rq->alg; 224 const struct z_erofs_decompressor *alg = decompressors + rq->alg;
232 unsigned int dst_maptype; 225 unsigned int dst_maptype;
233 void *dst; 226 void *dst;
234 int ret; 227 int ret, i;
235 228
236 if (nrpages_out == 1 && !rq->inplace_io) { 229 if (nrpages_out == 1 && !rq->inplace_io) {
237 DBG_BUGON(!*rq->out); 230 DBG_BUGON(!*rq->out);
@@ -269,9 +262,19 @@ static int decompress_generic(struct z_erofs_decompress_req *rq,
269 goto dstmap_out; 262 goto dstmap_out;
270 } 263 }
271 264
272 dst = erofs_vmap(rq->out, nrpages_out); 265 i = 0;
266 while (1) {
267 dst = vm_map_ram(rq->out, nrpages_out, -1, PAGE_KERNEL);
268
269 /* retry two more times (totally 3 times) */
270 if (dst || ++i >= 3)
271 break;
272 vm_unmap_aliases();
273 }
274
273 if (!dst) 275 if (!dst)
274 return -ENOMEM; 276 return -ENOMEM;
277
275 dst_maptype = 2; 278 dst_maptype = 2;
276 279
277dstmap_out: 280dstmap_out:
@@ -280,12 +283,12 @@ dstmap_out:
280 if (!dst_maptype) 283 if (!dst_maptype)
281 kunmap_atomic(dst); 284 kunmap_atomic(dst);
282 else if (dst_maptype == 2) 285 else if (dst_maptype == 2)
283 erofs_vunmap(dst, nrpages_out); 286 vm_unmap_ram(dst, nrpages_out);
284 return ret; 287 return ret;
285} 288}
286 289
287static int shifted_decompress(const struct z_erofs_decompress_req *rq, 290static int z_erofs_shifted_transform(const struct z_erofs_decompress_req *rq,
288 struct list_head *pagepool) 291 struct list_head *pagepool)
289{ 292{
290 const unsigned int nrpages_out = 293 const unsigned int nrpages_out =
291 PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT; 294 PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
@@ -329,7 +332,7 @@ int z_erofs_decompress(struct z_erofs_decompress_req *rq,
329 struct list_head *pagepool) 332 struct list_head *pagepool)
330{ 333{
331 if (rq->alg == Z_EROFS_COMPRESSION_SHIFTED) 334 if (rq->alg == Z_EROFS_COMPRESSION_SHIFTED)
332 return shifted_decompress(rq, pagepool); 335 return z_erofs_shifted_transform(rq, pagepool);
333 return decompress_generic(rq, pagepool); 336 return z_erofs_decompress_generic(rq, pagepool);
334} 337}
335 338
diff --git a/drivers/staging/erofs/dir.c b/fs/erofs/dir.c
index dbf6a151886c..d28c623dfef9 100644
--- a/drivers/staging/erofs/dir.c
+++ b/fs/erofs/dir.c
@@ -1,28 +1,11 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0-only
2/* 2/*
3 * linux/drivers/staging/erofs/dir.c
4 *
5 * Copyright (C) 2017-2018 HUAWEI, Inc. 3 * Copyright (C) 2017-2018 HUAWEI, Inc.
6 * http://www.huawei.com/ 4 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com> 5 * Created by Gao Xiang <gaoxiang25@huawei.com>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of the Linux
11 * distribution for more details.
12 */ 6 */
13#include "internal.h" 7#include "internal.h"
14 8
15static const unsigned char erofs_filetype_table[EROFS_FT_MAX] = {
16 [EROFS_FT_UNKNOWN] = DT_UNKNOWN,
17 [EROFS_FT_REG_FILE] = DT_REG,
18 [EROFS_FT_DIR] = DT_DIR,
19 [EROFS_FT_CHRDEV] = DT_CHR,
20 [EROFS_FT_BLKDEV] = DT_BLK,
21 [EROFS_FT_FIFO] = DT_FIFO,
22 [EROFS_FT_SOCK] = DT_SOCK,
23 [EROFS_FT_SYMLINK] = DT_LNK,
24};
25
26static void debug_one_dentry(unsigned char d_type, const char *de_name, 9static void debug_one_dentry(unsigned char d_type, const char *de_name,
27 unsigned int de_namelen) 10 unsigned int de_namelen)
28{ 11{
@@ -33,12 +16,12 @@ static void debug_one_dentry(unsigned char d_type, const char *de_name,
33 memcpy(dbg_namebuf, de_name, de_namelen); 16 memcpy(dbg_namebuf, de_name, de_namelen);
34 dbg_namebuf[de_namelen] = '\0'; 17 dbg_namebuf[de_namelen] = '\0';
35 18
36 debugln("found dirent %s de_len %u d_type %d", dbg_namebuf, 19 erofs_dbg("found dirent %s de_len %u d_type %d", dbg_namebuf,
37 de_namelen, d_type); 20 de_namelen, d_type);
38#endif 21#endif
39} 22}
40 23
41static int erofs_fill_dentries(struct dir_context *ctx, 24static int erofs_fill_dentries(struct inode *dir, struct dir_context *ctx,
42 void *dentry_blk, unsigned int *ofs, 25 void *dentry_blk, unsigned int *ofs,
43 unsigned int nameoff, unsigned int maxsize) 26 unsigned int nameoff, unsigned int maxsize)
44{ 27{
@@ -50,10 +33,7 @@ static int erofs_fill_dentries(struct dir_context *ctx,
50 unsigned int de_namelen; 33 unsigned int de_namelen;
51 unsigned char d_type; 34 unsigned char d_type;
52 35
53 if (de->file_type < EROFS_FT_MAX) 36 d_type = fs_ftype_to_dtype(de->file_type);
54 d_type = erofs_filetype_table[de->file_type];
55 else
56 d_type = DT_UNKNOWN;
57 37
58 nameoff = le16_to_cpu(de->nameoff); 38 nameoff = le16_to_cpu(de->nameoff);
59 de_name = (char *)dentry_blk + nameoff; 39 de_name = (char *)dentry_blk + nameoff;
@@ -65,10 +45,12 @@ static int erofs_fill_dentries(struct dir_context *ctx,
65 de_namelen = le16_to_cpu(de[1].nameoff) - nameoff; 45 de_namelen = le16_to_cpu(de[1].nameoff) - nameoff;
66 46
67 /* a corrupted entry is found */ 47 /* a corrupted entry is found */
68 if (unlikely(nameoff + de_namelen > maxsize || 48 if (nameoff + de_namelen > maxsize ||
69 de_namelen > EROFS_NAME_LEN)) { 49 de_namelen > EROFS_NAME_LEN) {
50 erofs_err(dir->i_sb, "bogus dirent @ nid %llu",
51 EROFS_I(dir)->nid);
70 DBG_BUGON(1); 52 DBG_BUGON(1);
71 return -EIO; 53 return -EFSCORRUPTED;
72 } 54 }
73 55
74 debug_one_dentry(d_type, de_name, de_namelen); 56 debug_one_dentry(d_type, de_name, de_namelen);
@@ -99,19 +81,27 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx)
99 unsigned int nameoff, maxsize; 81 unsigned int nameoff, maxsize;
100 82
101 dentry_page = read_mapping_page(mapping, i, NULL); 83 dentry_page = read_mapping_page(mapping, i, NULL);
102 if (IS_ERR(dentry_page)) 84 if (dentry_page == ERR_PTR(-ENOMEM)) {
103 continue; 85 err = -ENOMEM;
86 break;
87 } else if (IS_ERR(dentry_page)) {
88 erofs_err(dir->i_sb,
89 "fail to readdir of logical block %u of nid %llu",
90 i, EROFS_I(dir)->nid);
91 err = -EFSCORRUPTED;
92 break;
93 }
104 94
105 de = (struct erofs_dirent *)kmap(dentry_page); 95 de = (struct erofs_dirent *)kmap(dentry_page);
106 96
107 nameoff = le16_to_cpu(de->nameoff); 97 nameoff = le16_to_cpu(de->nameoff);
108 98
109 if (unlikely(nameoff < sizeof(struct erofs_dirent) || 99 if (nameoff < sizeof(struct erofs_dirent) ||
110 nameoff >= PAGE_SIZE)) { 100 nameoff >= PAGE_SIZE) {
111 errln("%s, invalid de[0].nameoff %u", 101 erofs_err(dir->i_sb,
112 __func__, nameoff); 102 "invalid de[0].nameoff %u @ nid %llu",
113 103 nameoff, EROFS_I(dir)->nid);
114 err = -EIO; 104 err = -EFSCORRUPTED;
115 goto skip_this; 105 goto skip_this;
116 } 106 }
117 107
@@ -119,15 +109,16 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx)
119 dirsize - ctx->pos + ofs, PAGE_SIZE); 109 dirsize - ctx->pos + ofs, PAGE_SIZE);
120 110
121 /* search dirents at the arbitrary position */ 111 /* search dirents at the arbitrary position */
122 if (unlikely(initial)) { 112 if (initial) {
123 initial = false; 113 initial = false;
124 114
125 ofs = roundup(ofs, sizeof(struct erofs_dirent)); 115 ofs = roundup(ofs, sizeof(struct erofs_dirent));
126 if (unlikely(ofs >= nameoff)) 116 if (ofs >= nameoff)
127 goto skip_this; 117 goto skip_this;
128 } 118 }
129 119
130 err = erofs_fill_dentries(ctx, de, &ofs, nameoff, maxsize); 120 err = erofs_fill_dentries(dir, ctx, de, &ofs,
121 nameoff, maxsize);
131skip_this: 122skip_this:
132 kunmap(dentry_page); 123 kunmap(dentry_page);
133 124
@@ -135,7 +126,7 @@ skip_this:
135 126
136 ctx->pos = blknr_to_addr(i) + ofs; 127 ctx->pos = blknr_to_addr(i) + ofs;
137 128
138 if (unlikely(err)) 129 if (err)
139 break; 130 break;
140 ++i; 131 ++i;
141 ofs = 0; 132 ofs = 0;
diff --git a/drivers/staging/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h
index 9f61abb7c1ca..b1ee5654750d 100644
--- a/drivers/staging/erofs/erofs_fs.h
+++ b/fs/erofs/erofs_fs.h
@@ -1,53 +1,48 @@
1/* SPDX-License-Identifier: GPL-2.0 OR Apache-2.0 1/* SPDX-License-Identifier: GPL-2.0-only OR Apache-2.0 */
2 * 2/*
3 * linux/drivers/staging/erofs/erofs_fs.h 3 * EROFS (Enhanced ROM File System) on-disk format definition
4 * 4 *
5 * Copyright (C) 2017-2018 HUAWEI, Inc. 5 * Copyright (C) 2017-2018 HUAWEI, Inc.
6 * http://www.huawei.com/ 6 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com> 7 * Created by Gao Xiang <gaoxiang25@huawei.com>
8 *
9 * This file is dual-licensed; you may select either the GNU General Public
10 * License version 2 or Apache License, Version 2.0. See the file COPYING
11 * in the main directory of the Linux distribution for more details.
12 */ 8 */
13#ifndef __EROFS_FS_H 9#ifndef __EROFS_FS_H
14#define __EROFS_FS_H 10#define __EROFS_FS_H
15 11
16/* Enhanced(Extended) ROM File System */
17#define EROFS_SUPER_MAGIC_V1 0xE0F5E1E2
18#define EROFS_SUPER_OFFSET 1024 12#define EROFS_SUPER_OFFSET 1024
19 13
20/* 14/*
21 * Any bits that aren't in EROFS_ALL_REQUIREMENTS should be 15 * Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should
22 * incompatible with this kernel version. 16 * be incompatible with this kernel version.
23 */ 17 */
24#define EROFS_REQUIREMENT_LZ4_0PADDING 0x00000001 18#define EROFS_FEATURE_INCOMPAT_LZ4_0PADDING 0x00000001
25#define EROFS_ALL_REQUIREMENTS EROFS_REQUIREMENT_LZ4_0PADDING 19#define EROFS_ALL_FEATURE_INCOMPAT EROFS_FEATURE_INCOMPAT_LZ4_0PADDING
26 20
21/* 128-byte erofs on-disk super block */
27struct erofs_super_block { 22struct erofs_super_block {
28/* 0 */__le32 magic; /* in the little endian */ 23 __le32 magic; /* file system magic number */
29/* 4 */__le32 checksum; /* crc32c(super_block) */ 24 __le32 checksum; /* crc32c(super_block) */
30/* 8 */__le32 features; /* (aka. feature_compat) */ 25 __le32 feature_compat;
31/* 12 */__u8 blkszbits; /* support block_size == PAGE_SIZE only */ 26 __u8 blkszbits; /* support block_size == PAGE_SIZE only */
32/* 13 */__u8 reserved; 27 __u8 reserved;
33 28
34/* 14 */__le16 root_nid; 29 __le16 root_nid; /* nid of root directory */
35/* 16 */__le64 inos; /* total valid ino # (== f_files - f_favail) */ 30 __le64 inos; /* total valid ino # (== f_files - f_favail) */
36 31
37/* 24 */__le64 build_time; /* inode v1 time derivation */ 32 __le64 build_time; /* inode v1 time derivation */
38/* 32 */__le32 build_time_nsec; 33 __le32 build_time_nsec; /* inode v1 time derivation in nano scale */
39/* 36 */__le32 blocks; /* used for statfs */ 34 __le32 blocks; /* used for statfs */
40/* 40 */__le32 meta_blkaddr; 35 __le32 meta_blkaddr; /* start block address of metadata area */
41/* 44 */__le32 xattr_blkaddr; 36 __le32 xattr_blkaddr; /* start block address of shared xattr area */
42/* 48 */__u8 uuid[16]; /* 128-bit uuid for volume */ 37 __u8 uuid[16]; /* 128-bit uuid for volume */
43/* 64 */__u8 volume_name[16]; /* volume name */ 38 __u8 volume_name[16]; /* volume name */
44/* 80 */__le32 requirements; /* (aka. feature_incompat) */ 39 __le32 feature_incompat;
45 40
46/* 84 */__u8 reserved2[44]; 41 __u8 reserved2[44];
47} __packed; /* 128 bytes */ 42};
48 43
49/* 44/*
50 * erofs inode data mapping: 45 * erofs inode datalayout (i_format in on-disk inode):
51 * 0 - inode plain without inline data A: 46 * 0 - inode plain without inline data A:
52 * inode, [xattrs], ... | ... | no-holed data 47 * inode, [xattrs], ... | ... | no-holed data
53 * 1 - inode VLE compression B (legacy): 48 * 1 - inode VLE compression B (legacy):
@@ -59,63 +54,64 @@ struct erofs_super_block {
59 * 4~7 - reserved 54 * 4~7 - reserved
60 */ 55 */
61enum { 56enum {
62 EROFS_INODE_FLAT_PLAIN, 57 EROFS_INODE_FLAT_PLAIN = 0,
63 EROFS_INODE_FLAT_COMPRESSION_LEGACY, 58 EROFS_INODE_FLAT_COMPRESSION_LEGACY = 1,
64 EROFS_INODE_FLAT_INLINE, 59 EROFS_INODE_FLAT_INLINE = 2,
65 EROFS_INODE_FLAT_COMPRESSION, 60 EROFS_INODE_FLAT_COMPRESSION = 3,
66 EROFS_INODE_LAYOUT_MAX 61 EROFS_INODE_DATALAYOUT_MAX
67}; 62};
68 63
69static bool erofs_inode_is_data_compressed(unsigned int datamode) 64static inline bool erofs_inode_is_data_compressed(unsigned int datamode)
70{ 65{
71 if (datamode == EROFS_INODE_FLAT_COMPRESSION) 66 return datamode == EROFS_INODE_FLAT_COMPRESSION ||
72 return true; 67 datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY;
73 return datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY;
74} 68}
75 69
76/* bit definitions of inode i_advise */ 70/* bit definitions of inode i_advise */
77#define EROFS_I_VERSION_BITS 1 71#define EROFS_I_VERSION_BITS 1
78#define EROFS_I_DATA_MAPPING_BITS 3 72#define EROFS_I_DATALAYOUT_BITS 3
79 73
80#define EROFS_I_VERSION_BIT 0 74#define EROFS_I_VERSION_BIT 0
81#define EROFS_I_DATA_MAPPING_BIT 1 75#define EROFS_I_DATALAYOUT_BIT 1
82 76
83struct erofs_inode_v1 { 77/* 32-byte reduced form of an ondisk inode */
84/* 0 */__le16 i_advise; 78struct erofs_inode_compact {
79 __le16 i_format; /* inode format hints */
85 80
86/* 1 header + n-1 * 4 bytes inline xattr to keep continuity */ 81/* 1 header + n-1 * 4 bytes inline xattr to keep continuity */
87/* 2 */__le16 i_xattr_icount; 82 __le16 i_xattr_icount;
88/* 4 */__le16 i_mode; 83 __le16 i_mode;
89/* 6 */__le16 i_nlink; 84 __le16 i_nlink;
90/* 8 */__le32 i_size; 85 __le32 i_size;
91/* 12 */__le32 i_reserved; 86 __le32 i_reserved;
92/* 16 */union { 87 union {
93 /* file total compressed blocks for data mapping 1 */ 88 /* file total compressed blocks for data mapping 1 */
94 __le32 compressed_blocks; 89 __le32 compressed_blocks;
95 __le32 raw_blkaddr; 90 __le32 raw_blkaddr;
96 91
97 /* for device files, used to indicate old/new device # */ 92 /* for device files, used to indicate old/new device # */
98 __le32 rdev; 93 __le32 rdev;
99 } i_u __packed; 94 } i_u;
100/* 20 */__le32 i_ino; /* only used for 32-bit stat compatibility */ 95 __le32 i_ino; /* only used for 32-bit stat compatibility */
101/* 24 */__le16 i_uid; 96 __le16 i_uid;
102/* 26 */__le16 i_gid; 97 __le16 i_gid;
103/* 28 */__le32 i_checksum; 98 __le32 i_reserved2;
104} __packed; 99};
105 100
106/* 32 bytes on-disk inode */ 101/* 32 bytes on-disk inode */
107#define EROFS_INODE_LAYOUT_V1 0 102#define EROFS_INODE_LAYOUT_COMPACT 0
108/* 64 bytes on-disk inode */ 103/* 64 bytes on-disk inode */
109#define EROFS_INODE_LAYOUT_V2 1 104#define EROFS_INODE_LAYOUT_EXTENDED 1
110 105
111struct erofs_inode_v2 { 106/* 64-byte complete form of an ondisk inode */
112 __le16 i_advise; 107struct erofs_inode_extended {
108 __le16 i_format; /* inode format hints */
113 109
114 /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */ 110/* 1 header + n-1 * 4 bytes inline xattr to keep continuity */
115 __le16 i_xattr_icount; 111 __le16 i_xattr_icount;
116 __le16 i_mode; 112 __le16 i_mode;
117 __le16 i_reserved; /* 8 bytes */ 113 __le16 i_reserved;
118 __le64 i_size; /* 16 bytes */ 114 __le64 i_size;
119 union { 115 union {
120 /* file total compressed blocks for data mapping 1 */ 116 /* file total compressed blocks for data mapping 1 */
121 __le32 compressed_blocks; 117 __le32 compressed_blocks;
@@ -123,19 +119,18 @@ struct erofs_inode_v2 {
123 119
124 /* for device files, used to indicate old/new device # */ 120 /* for device files, used to indicate old/new device # */
125 __le32 rdev; 121 __le32 rdev;
126 } i_u __packed; 122 } i_u;
127 123
128 /* only used for 32-bit stat compatibility */ 124 /* only used for 32-bit stat compatibility */
129 __le32 i_ino; /* 24 bytes */ 125 __le32 i_ino;
130 126
131 __le32 i_uid; 127 __le32 i_uid;
132 __le32 i_gid; 128 __le32 i_gid;
133 __le64 i_ctime; /* 32 bytes */ 129 __le64 i_ctime;
134 __le32 i_ctime_nsec; 130 __le32 i_ctime_nsec;
135 __le32 i_nlink; 131 __le32 i_nlink;
136 __u8 i_reserved2[12]; 132 __u8 i_reserved2[16];
137 __le32 i_checksum; /* 64 bytes */ 133};
138} __packed;
139 134
140#define EROFS_MAX_SHARED_XATTRS (128) 135#define EROFS_MAX_SHARED_XATTRS (128)
141/* h_shared_count between 129 ... 255 are special # */ 136/* h_shared_count between 129 ... 255 are special # */
@@ -153,11 +148,11 @@ struct erofs_inode_v2 {
153 * for read-only fs, no need to introduce h_refcount 148 * for read-only fs, no need to introduce h_refcount
154 */ 149 */
155struct erofs_xattr_ibody_header { 150struct erofs_xattr_ibody_header {
156 __le32 h_checksum; 151 __le32 h_reserved;
157 __u8 h_shared_count; 152 __u8 h_shared_count;
158 __u8 h_reserved[7]; 153 __u8 h_reserved2[7];
159 __le32 h_shared_xattrs[0]; /* shared xattr id array */ 154 __le32 h_shared_xattrs[0]; /* shared xattr id array */
160} __packed; 155};
161 156
162/* Name indexes */ 157/* Name indexes */
163#define EROFS_XATTR_INDEX_USER 1 158#define EROFS_XATTR_INDEX_USER 1
@@ -174,22 +169,28 @@ struct erofs_xattr_entry {
174 __le16 e_value_size; /* size of attribute value */ 169 __le16 e_value_size; /* size of attribute value */
175 /* followed by e_name and e_value */ 170 /* followed by e_name and e_value */
176 char e_name[0]; /* attribute name */ 171 char e_name[0]; /* attribute name */
177} __packed; 172};
178 173
179#define ondisk_xattr_ibody_size(count) ({\ 174static inline unsigned int erofs_xattr_ibody_size(__le16 i_xattr_icount)
180 u32 __count = le16_to_cpu(count); \ 175{
181 ((__count) == 0) ? 0 : \ 176 if (!i_xattr_icount)
182 sizeof(struct erofs_xattr_ibody_header) + \ 177 return 0;
183 sizeof(__u32) * ((__count) - 1); }) 178
179 return sizeof(struct erofs_xattr_ibody_header) +
180 sizeof(__u32) * (le16_to_cpu(i_xattr_icount) - 1);
181}
184 182
185#define EROFS_XATTR_ALIGN(size) round_up(size, sizeof(struct erofs_xattr_entry)) 183#define EROFS_XATTR_ALIGN(size) round_up(size, sizeof(struct erofs_xattr_entry))
186#define EROFS_XATTR_ENTRY_SIZE(entry) EROFS_XATTR_ALIGN( \
187 sizeof(struct erofs_xattr_entry) + \
188 (entry)->e_name_len + le16_to_cpu((entry)->e_value_size))
189 184
190/* available compression algorithm types */ 185static inline unsigned int erofs_xattr_entry_size(struct erofs_xattr_entry *e)
186{
187 return EROFS_XATTR_ALIGN(sizeof(struct erofs_xattr_entry) +
188 e->e_name_len + le16_to_cpu(e->e_value_size));
189}
190
191/* available compression algorithm types (for h_algorithmtype) */
191enum { 192enum {
192 Z_EROFS_COMPRESSION_LZ4, 193 Z_EROFS_COMPRESSION_LZ4 = 0,
193 Z_EROFS_COMPRESSION_MAX 194 Z_EROFS_COMPRESSION_MAX
194}; 195};
195 196
@@ -222,7 +223,7 @@ struct z_erofs_map_header {
222#define Z_EROFS_VLE_LEGACY_HEADER_PADDING 8 223#define Z_EROFS_VLE_LEGACY_HEADER_PADDING 8
223 224
224/* 225/*
225 * Z_EROFS Variable-sized Logical Extent cluster type: 226 * Fixed-sized output compression ondisk Logical Extent cluster type:
226 * 0 - literal (uncompressed) cluster 227 * 0 - literal (uncompressed) cluster
227 * 1 - compressed cluster (for the head logical cluster) 228 * 1 - compressed cluster (for the head logical cluster)
228 * 2 - compressed cluster (for the other logical clusters) 229 * 2 - compressed cluster (for the other logical clusters)
@@ -247,10 +248,10 @@ struct z_erofs_map_header {
247 * (di_advise could be 0, 1 or 2) 248 * (di_advise could be 0, 1 or 2)
248 */ 249 */
249enum { 250enum {
250 Z_EROFS_VLE_CLUSTER_TYPE_PLAIN, 251 Z_EROFS_VLE_CLUSTER_TYPE_PLAIN = 0,
251 Z_EROFS_VLE_CLUSTER_TYPE_HEAD, 252 Z_EROFS_VLE_CLUSTER_TYPE_HEAD = 1,
252 Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD, 253 Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD = 2,
253 Z_EROFS_VLE_CLUSTER_TYPE_RESERVED, 254 Z_EROFS_VLE_CLUSTER_TYPE_RESERVED = 3,
254 Z_EROFS_VLE_CLUSTER_TYPE_MAX 255 Z_EROFS_VLE_CLUSTER_TYPE_MAX
255}; 256};
256 257
@@ -272,8 +273,8 @@ struct z_erofs_vle_decompressed_index {
272 * [1] - pointing to the tail cluster 273 * [1] - pointing to the tail cluster
273 */ 274 */
274 __le16 delta[2]; 275 __le16 delta[2];
275 } di_u __packed; /* 8 bytes */ 276 } di_u;
276} __packed; 277};
277 278
278#define Z_EROFS_VLE_LEGACY_INDEX_ALIGN(size) \ 279#define Z_EROFS_VLE_LEGACY_INDEX_ALIGN(size) \
279 (round_up(size, sizeof(struct z_erofs_vle_decompressed_index)) + \ 280 (round_up(size, sizeof(struct z_erofs_vle_decompressed_index)) + \
@@ -281,24 +282,17 @@ struct z_erofs_vle_decompressed_index {
281 282
282/* dirent sorts in alphabet order, thus we can do binary search */ 283/* dirent sorts in alphabet order, thus we can do binary search */
283struct erofs_dirent { 284struct erofs_dirent {
284 __le64 nid; /* 0, node number */ 285 __le64 nid; /* node number */
285 __le16 nameoff; /* 8, start offset of file name */ 286 __le16 nameoff; /* start offset of file name */
286 __u8 file_type; /* 10, file type */ 287 __u8 file_type; /* file type */
287 __u8 reserved; /* 11, reserved */ 288 __u8 reserved; /* reserved */
288} __packed; 289} __packed;
289 290
290/* file types used in inode_info->flags */ 291/*
291enum { 292 * EROFS file types should match generic FT_* types and
292 EROFS_FT_UNKNOWN, 293 * it seems no need to add BUILD_BUG_ONs since potential
293 EROFS_FT_REG_FILE, 294 * unmatchness will break other fses as well...
294 EROFS_FT_DIR, 295 */
295 EROFS_FT_CHRDEV,
296 EROFS_FT_BLKDEV,
297 EROFS_FT_FIFO,
298 EROFS_FT_SOCK,
299 EROFS_FT_SYMLINK,
300 EROFS_FT_MAX
301};
302 296
303#define EROFS_NAME_LEN 255 297#define EROFS_NAME_LEN 255
304 298
@@ -306,8 +300,8 @@ enum {
306static inline void erofs_check_ondisk_layout_definitions(void) 300static inline void erofs_check_ondisk_layout_definitions(void)
307{ 301{
308 BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128); 302 BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
309 BUILD_BUG_ON(sizeof(struct erofs_inode_v1) != 32); 303 BUILD_BUG_ON(sizeof(struct erofs_inode_compact) != 32);
310 BUILD_BUG_ON(sizeof(struct erofs_inode_v2) != 64); 304 BUILD_BUG_ON(sizeof(struct erofs_inode_extended) != 64);
311 BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12); 305 BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
312 BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4); 306 BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
313 BUILD_BUG_ON(sizeof(struct z_erofs_map_header) != 8); 307 BUILD_BUG_ON(sizeof(struct z_erofs_map_header) != 8);
diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
new file mode 100644
index 000000000000..3350ab65d892
--- /dev/null
+++ b/fs/erofs/inode.c
@@ -0,0 +1,337 @@
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2017-2018 HUAWEI, Inc.
4 * http://www.huawei.com/
5 * Created by Gao Xiang <gaoxiang25@huawei.com>
6 */
7#include "xattr.h"
8
9#include <trace/events/erofs.h>
10
11/* no locking */
12static int erofs_read_inode(struct inode *inode, void *data)
13{
14 struct erofs_inode *vi = EROFS_I(inode);
15 struct erofs_inode_compact *dic = data;
16 struct erofs_inode_extended *die;
17
18 const unsigned int ifmt = le16_to_cpu(dic->i_format);
19 struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
20 erofs_blk_t nblks = 0;
21
22 vi->datalayout = erofs_inode_datalayout(ifmt);
23
24 if (vi->datalayout >= EROFS_INODE_DATALAYOUT_MAX) {
25 erofs_err(inode->i_sb, "unsupported datalayout %u of nid %llu",
26 vi->datalayout, vi->nid);
27 DBG_BUGON(1);
28 return -EOPNOTSUPP;
29 }
30
31 switch (erofs_inode_version(ifmt)) {
32 case EROFS_INODE_LAYOUT_EXTENDED:
33 die = data;
34
35 vi->inode_isize = sizeof(struct erofs_inode_extended);
36 vi->xattr_isize = erofs_xattr_ibody_size(die->i_xattr_icount);
37
38 inode->i_mode = le16_to_cpu(die->i_mode);
39 switch (inode->i_mode & S_IFMT) {
40 case S_IFREG:
41 case S_IFDIR:
42 case S_IFLNK:
43 vi->raw_blkaddr = le32_to_cpu(die->i_u.raw_blkaddr);
44 break;
45 case S_IFCHR:
46 case S_IFBLK:
47 inode->i_rdev =
48 new_decode_dev(le32_to_cpu(die->i_u.rdev));
49 break;
50 case S_IFIFO:
51 case S_IFSOCK:
52 inode->i_rdev = 0;
53 break;
54 default:
55 goto bogusimode;
56 }
57 i_uid_write(inode, le32_to_cpu(die->i_uid));
58 i_gid_write(inode, le32_to_cpu(die->i_gid));
59 set_nlink(inode, le32_to_cpu(die->i_nlink));
60
61 /* ns timestamp */
62 inode->i_mtime.tv_sec = inode->i_ctime.tv_sec =
63 le64_to_cpu(die->i_ctime);
64 inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec =
65 le32_to_cpu(die->i_ctime_nsec);
66
67 inode->i_size = le64_to_cpu(die->i_size);
68
69 /* total blocks for compressed files */
70 if (erofs_inode_is_data_compressed(vi->datalayout))
71 nblks = le32_to_cpu(die->i_u.compressed_blocks);
72 break;
73 case EROFS_INODE_LAYOUT_COMPACT:
74 vi->inode_isize = sizeof(struct erofs_inode_compact);
75 vi->xattr_isize = erofs_xattr_ibody_size(dic->i_xattr_icount);
76
77 inode->i_mode = le16_to_cpu(dic->i_mode);
78 switch (inode->i_mode & S_IFMT) {
79 case S_IFREG:
80 case S_IFDIR:
81 case S_IFLNK:
82 vi->raw_blkaddr = le32_to_cpu(dic->i_u.raw_blkaddr);
83 break;
84 case S_IFCHR:
85 case S_IFBLK:
86 inode->i_rdev =
87 new_decode_dev(le32_to_cpu(dic->i_u.rdev));
88 break;
89 case S_IFIFO:
90 case S_IFSOCK:
91 inode->i_rdev = 0;
92 break;
93 default:
94 goto bogusimode;
95 }
96 i_uid_write(inode, le16_to_cpu(dic->i_uid));
97 i_gid_write(inode, le16_to_cpu(dic->i_gid));
98 set_nlink(inode, le16_to_cpu(dic->i_nlink));
99
100 /* use build time to derive all file time */
101 inode->i_mtime.tv_sec = inode->i_ctime.tv_sec =
102 sbi->build_time;
103 inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec =
104 sbi->build_time_nsec;
105
106 inode->i_size = le32_to_cpu(dic->i_size);
107 if (erofs_inode_is_data_compressed(vi->datalayout))
108 nblks = le32_to_cpu(dic->i_u.compressed_blocks);
109 break;
110 default:
111 erofs_err(inode->i_sb,
112 "unsupported on-disk inode version %u of nid %llu",
113 erofs_inode_version(ifmt), vi->nid);
114 DBG_BUGON(1);
115 return -EOPNOTSUPP;
116 }
117
118 if (!nblks)
119 /* measure inode.i_blocks as generic filesystems */
120 inode->i_blocks = roundup(inode->i_size, EROFS_BLKSIZ) >> 9;
121 else
122 inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK;
123 return 0;
124
125bogusimode:
126 erofs_err(inode->i_sb, "bogus i_mode (%o) @ nid %llu",
127 inode->i_mode, vi->nid);
128 DBG_BUGON(1);
129 return -EFSCORRUPTED;
130}
131
132static int erofs_fill_symlink(struct inode *inode, void *data,
133 unsigned int m_pofs)
134{
135 struct erofs_inode *vi = EROFS_I(inode);
136 char *lnk;
137
138 /* if it cannot be handled with fast symlink scheme */
139 if (vi->datalayout != EROFS_INODE_FLAT_INLINE ||
140 inode->i_size >= PAGE_SIZE) {
141 inode->i_op = &erofs_symlink_iops;
142 return 0;
143 }
144
145 lnk = kmalloc(inode->i_size + 1, GFP_KERNEL);
146 if (!lnk)
147 return -ENOMEM;
148
149 m_pofs += vi->inode_isize + vi->xattr_isize;
150 /* inline symlink data shouldn't cross page boundary as well */
151 if (m_pofs + inode->i_size > PAGE_SIZE) {
152 kfree(lnk);
153 erofs_err(inode->i_sb,
154 "inline data cross block boundary @ nid %llu",
155 vi->nid);
156 DBG_BUGON(1);
157 return -EFSCORRUPTED;
158 }
159
160 memcpy(lnk, data + m_pofs, inode->i_size);
161 lnk[inode->i_size] = '\0';
162
163 inode->i_link = lnk;
164 inode->i_op = &erofs_fast_symlink_iops;
165 return 0;
166}
167
168static int erofs_fill_inode(struct inode *inode, int isdir)
169{
170 struct super_block *sb = inode->i_sb;
171 struct erofs_inode *vi = EROFS_I(inode);
172 struct page *page;
173 void *data;
174 int err;
175 erofs_blk_t blkaddr;
176 unsigned int ofs;
177 erofs_off_t inode_loc;
178
179 trace_erofs_fill_inode(inode, isdir);
180 inode_loc = iloc(EROFS_SB(sb), vi->nid);
181 blkaddr = erofs_blknr(inode_loc);
182 ofs = erofs_blkoff(inode_loc);
183
184 erofs_dbg("%s, reading inode nid %llu at %u of blkaddr %u",
185 __func__, vi->nid, ofs, blkaddr);
186
187 page = erofs_get_meta_page(sb, blkaddr);
188
189 if (IS_ERR(page)) {
190 erofs_err(sb, "failed to get inode (nid: %llu) page, err %ld",
191 vi->nid, PTR_ERR(page));
192 return PTR_ERR(page);
193 }
194
195 DBG_BUGON(!PageUptodate(page));
196 data = page_address(page);
197
198 err = erofs_read_inode(inode, data + ofs);
199 if (err)
200 goto out_unlock;
201
202 /* setup the new inode */
203 switch (inode->i_mode & S_IFMT) {
204 case S_IFREG:
205 inode->i_op = &erofs_generic_iops;
206 inode->i_fop = &generic_ro_fops;
207 break;
208 case S_IFDIR:
209 inode->i_op = &erofs_dir_iops;
210 inode->i_fop = &erofs_dir_fops;
211 break;
212 case S_IFLNK:
213 err = erofs_fill_symlink(inode, data, ofs);
214 if (err)
215 goto out_unlock;
216 inode_nohighmem(inode);
217 break;
218 case S_IFCHR:
219 case S_IFBLK:
220 case S_IFIFO:
221 case S_IFSOCK:
222 inode->i_op = &erofs_generic_iops;
223 init_special_inode(inode, inode->i_mode, inode->i_rdev);
224 goto out_unlock;
225 default:
226 err = -EFSCORRUPTED;
227 goto out_unlock;
228 }
229
230 if (erofs_inode_is_data_compressed(vi->datalayout)) {
231 err = z_erofs_fill_inode(inode);
232 goto out_unlock;
233 }
234 inode->i_mapping->a_ops = &erofs_raw_access_aops;
235
236out_unlock:
237 unlock_page(page);
238 put_page(page);
239 return err;
240}
241
242/*
243 * erofs nid is 64bits, but i_ino is 'unsigned long', therefore
244 * we should do more for 32-bit platform to find the right inode.
245 */
246static int erofs_ilookup_test_actor(struct inode *inode, void *opaque)
247{
248 const erofs_nid_t nid = *(erofs_nid_t *)opaque;
249
250 return EROFS_I(inode)->nid == nid;
251}
252
253static int erofs_iget_set_actor(struct inode *inode, void *opaque)
254{
255 const erofs_nid_t nid = *(erofs_nid_t *)opaque;
256
257 inode->i_ino = erofs_inode_hash(nid);
258 return 0;
259}
260
261static inline struct inode *erofs_iget_locked(struct super_block *sb,
262 erofs_nid_t nid)
263{
264 const unsigned long hashval = erofs_inode_hash(nid);
265
266 return iget5_locked(sb, hashval, erofs_ilookup_test_actor,
267 erofs_iget_set_actor, &nid);
268}
269
270struct inode *erofs_iget(struct super_block *sb,
271 erofs_nid_t nid,
272 bool isdir)
273{
274 struct inode *inode = erofs_iget_locked(sb, nid);
275
276 if (!inode)
277 return ERR_PTR(-ENOMEM);
278
279 if (inode->i_state & I_NEW) {
280 int err;
281 struct erofs_inode *vi = EROFS_I(inode);
282
283 vi->nid = nid;
284
285 err = erofs_fill_inode(inode, isdir);
286 if (!err)
287 unlock_new_inode(inode);
288 else {
289 iget_failed(inode);
290 inode = ERR_PTR(err);
291 }
292 }
293 return inode;
294}
295
296int erofs_getattr(const struct path *path, struct kstat *stat,
297 u32 request_mask, unsigned int query_flags)
298{
299 struct inode *const inode = d_inode(path->dentry);
300
301 if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout))
302 stat->attributes |= STATX_ATTR_COMPRESSED;
303
304 stat->attributes |= STATX_ATTR_IMMUTABLE;
305 stat->attributes_mask |= (STATX_ATTR_COMPRESSED |
306 STATX_ATTR_IMMUTABLE);
307
308 generic_fillattr(inode, stat);
309 return 0;
310}
311
312const struct inode_operations erofs_generic_iops = {
313 .getattr = erofs_getattr,
314#ifdef CONFIG_EROFS_FS_XATTR
315 .listxattr = erofs_listxattr,
316#endif
317 .get_acl = erofs_get_acl,
318};
319
320const struct inode_operations erofs_symlink_iops = {
321 .get_link = page_get_link,
322 .getattr = erofs_getattr,
323#ifdef CONFIG_EROFS_FS_XATTR
324 .listxattr = erofs_listxattr,
325#endif
326 .get_acl = erofs_get_acl,
327};
328
329const struct inode_operations erofs_fast_symlink_iops = {
330 .get_link = simple_get_link,
331 .getattr = erofs_getattr,
332#ifdef CONFIG_EROFS_FS_XATTR
333 .listxattr = erofs_listxattr,
334#endif
335 .get_acl = erofs_get_acl,
336};
337
diff --git a/drivers/staging/erofs/internal.h b/fs/erofs/internal.h
index 963cc1b8b896..544a453f3076 100644
--- a/drivers/staging/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -1,17 +1,11 @@
1/* SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0-only */
2 * 2/*
3 * linux/drivers/staging/erofs/internal.h
4 *
5 * Copyright (C) 2017-2018 HUAWEI, Inc. 3 * Copyright (C) 2017-2018 HUAWEI, Inc.
6 * http://www.huawei.com/ 4 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com> 5 * Created by Gao Xiang <gaoxiang25@huawei.com>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of the Linux
11 * distribution for more details.
12 */ 6 */
13#ifndef __INTERNAL_H 7#ifndef __EROFS_INTERNAL_H
14#define __INTERNAL_H 8#define __EROFS_INTERNAL_H
15 9
16#include <linux/fs.h> 10#include <linux/fs.h>
17#include <linux/dcache.h> 11#include <linux/dcache.h>
@@ -19,7 +13,7 @@
19#include <linux/pagemap.h> 13#include <linux/pagemap.h>
20#include <linux/bio.h> 14#include <linux/bio.h>
21#include <linux/buffer_head.h> 15#include <linux/buffer_head.h>
22#include <linux/cleancache.h> 16#include <linux/magic.h>
23#include <linux/slab.h> 17#include <linux/slab.h>
24#include <linux/vmalloc.h> 18#include <linux/vmalloc.h>
25#include "erofs_fs.h" 19#include "erofs_fs.h"
@@ -28,82 +22,58 @@
28#undef pr_fmt 22#undef pr_fmt
29#define pr_fmt(fmt) "erofs: " fmt 23#define pr_fmt(fmt) "erofs: " fmt
30 24
31#define errln(x, ...) pr_err(x "\n", ##__VA_ARGS__) 25__printf(3, 4) void _erofs_err(struct super_block *sb,
32#define infoln(x, ...) pr_info(x "\n", ##__VA_ARGS__) 26 const char *function, const char *fmt, ...);
27#define erofs_err(sb, fmt, ...) \
28 _erofs_err(sb, __func__, fmt "\n", ##__VA_ARGS__)
29__printf(3, 4) void _erofs_info(struct super_block *sb,
30 const char *function, const char *fmt, ...);
31#define erofs_info(sb, fmt, ...) \
32 _erofs_info(sb, __func__, fmt "\n", ##__VA_ARGS__)
33#ifdef CONFIG_EROFS_FS_DEBUG 33#ifdef CONFIG_EROFS_FS_DEBUG
34#define debugln(x, ...) pr_debug(x "\n", ##__VA_ARGS__) 34#define erofs_dbg(x, ...) pr_debug(x "\n", ##__VA_ARGS__)
35
36#define dbg_might_sleep might_sleep
37#define DBG_BUGON BUG_ON 35#define DBG_BUGON BUG_ON
38#else 36#else
39#define debugln(x, ...) ((void)0) 37#define erofs_dbg(x, ...) ((void)0)
40
41#define dbg_might_sleep() ((void)0)
42#define DBG_BUGON(x) ((void)(x)) 38#define DBG_BUGON(x) ((void)(x))
43#endif 39#endif /* !CONFIG_EROFS_FS_DEBUG */
44
45enum {
46 FAULT_KMALLOC,
47 FAULT_READ_IO,
48 FAULT_MAX,
49};
50
51#ifdef CONFIG_EROFS_FAULT_INJECTION
52extern const char *erofs_fault_name[FAULT_MAX];
53#define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type)))
54
55struct erofs_fault_info {
56 atomic_t inject_ops;
57 unsigned int inject_rate;
58 unsigned int inject_type;
59};
60#endif
61
62#ifdef CONFIG_EROFS_FS_ZIP_CACHE_BIPOLAR
63#define EROFS_FS_ZIP_CACHE_LVL (2)
64#elif defined(EROFS_FS_ZIP_CACHE_UNIPOLAR)
65#define EROFS_FS_ZIP_CACHE_LVL (1)
66#else
67#define EROFS_FS_ZIP_CACHE_LVL (0)
68#endif
69
70#if (!defined(EROFS_FS_HAS_MANAGED_CACHE) && (EROFS_FS_ZIP_CACHE_LVL > 0))
71#define EROFS_FS_HAS_MANAGED_CACHE
72#endif
73 40
74/* EROFS_SUPER_MAGIC_V1 to represent the whole file system */ 41/* EROFS_SUPER_MAGIC_V1 to represent the whole file system */
75#define EROFS_SUPER_MAGIC EROFS_SUPER_MAGIC_V1 42#define EROFS_SUPER_MAGIC EROFS_SUPER_MAGIC_V1
76 43
77typedef u64 erofs_nid_t; 44typedef u64 erofs_nid_t;
45typedef u64 erofs_off_t;
46/* data type for filesystem-wide blocks number */
47typedef u32 erofs_blk_t;
78 48
79struct erofs_sb_info { 49struct erofs_sb_info {
50#ifdef CONFIG_EROFS_FS_ZIP
80 /* list for all registered superblocks, mainly for shrinker */ 51 /* list for all registered superblocks, mainly for shrinker */
81 struct list_head list; 52 struct list_head list;
82 struct mutex umount_mutex; 53 struct mutex umount_mutex;
83 54
84 u32 blocks;
85 u32 meta_blkaddr;
86#ifdef CONFIG_EROFS_FS_XATTR
87 u32 xattr_blkaddr;
88#endif
89
90 /* inode slot unit size in bit shift */
91 unsigned char islotbits;
92#ifdef CONFIG_EROFS_FS_ZIP
93 /* cluster size in bit shift */
94 unsigned char clusterbits;
95
96 /* the dedicated workstation for compression */ 55 /* the dedicated workstation for compression */
97 struct radix_tree_root workstn_tree; 56 struct radix_tree_root workstn_tree;
98 57
99 /* threshold for decompression synchronously */ 58 /* threshold for decompression synchronously */
100 unsigned int max_sync_decompress_pages; 59 unsigned int max_sync_decompress_pages;
101 60
102#ifdef EROFS_FS_HAS_MANAGED_CACHE 61 unsigned int shrinker_run_no;
62
63 /* current strategy of how to use managed cache */
64 unsigned char cache_strategy;
65
66 /* pseudo inode to manage cached pages */
103 struct inode *managed_cache; 67 struct inode *managed_cache;
68#endif /* CONFIG_EROFS_FS_ZIP */
69 u32 blocks;
70 u32 meta_blkaddr;
71#ifdef CONFIG_EROFS_FS_XATTR
72 u32 xattr_blkaddr;
104#endif 73#endif
105 74
106#endif 75 /* inode slot unit size in bit shift */
76 unsigned char islotbits;
107 77
108 u32 build_time_nsec; 78 u32 build_time_nsec;
109 u64 build_time; 79 u64 build_time;
@@ -115,76 +85,30 @@ struct erofs_sb_info {
115 85
116 u8 uuid[16]; /* 128-bit uuid for volume */ 86 u8 uuid[16]; /* 128-bit uuid for volume */
117 u8 volume_name[16]; /* volume name */ 87 u8 volume_name[16]; /* volume name */
118 u32 requirements; 88 u32 feature_incompat;
119
120 char *dev_name;
121 89
122 unsigned int mount_opt; 90 unsigned int mount_opt;
123 unsigned int shrinker_run_no;
124
125#ifdef CONFIG_EROFS_FAULT_INJECTION
126 struct erofs_fault_info fault_info; /* For fault injection */
127#endif
128}; 91};
129 92
130#ifdef CONFIG_EROFS_FAULT_INJECTION
131#define erofs_show_injection_info(type) \
132 infoln("inject %s in %s of %pS", erofs_fault_name[type], \
133 __func__, __builtin_return_address(0))
134
135static inline bool time_to_inject(struct erofs_sb_info *sbi, int type)
136{
137 struct erofs_fault_info *ffi = &sbi->fault_info;
138
139 if (!ffi->inject_rate)
140 return false;
141
142 if (!IS_FAULT_SET(ffi, type))
143 return false;
144
145 atomic_inc(&ffi->inject_ops);
146 if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) {
147 atomic_set(&ffi->inject_ops, 0);
148 return true;
149 }
150 return false;
151}
152#else
153static inline bool time_to_inject(struct erofs_sb_info *sbi, int type)
154{
155 return false;
156}
157
158static inline void erofs_show_injection_info(int type)
159{
160}
161#endif
162
163static inline void *erofs_kmalloc(struct erofs_sb_info *sbi,
164 size_t size, gfp_t flags)
165{
166 if (time_to_inject(sbi, FAULT_KMALLOC)) {
167 erofs_show_injection_info(FAULT_KMALLOC);
168 return NULL;
169 }
170 return kmalloc(size, flags);
171}
172
173#define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info) 93#define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info)
174#define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info) 94#define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info)
175 95
176/* Mount flags set via mount options or defaults */ 96/* Mount flags set via mount options or defaults */
177#define EROFS_MOUNT_XATTR_USER 0x00000010 97#define EROFS_MOUNT_XATTR_USER 0x00000010
178#define EROFS_MOUNT_POSIX_ACL 0x00000020 98#define EROFS_MOUNT_POSIX_ACL 0x00000020
179#define EROFS_MOUNT_FAULT_INJECTION 0x00000040
180 99
181#define clear_opt(sbi, option) ((sbi)->mount_opt &= ~EROFS_MOUNT_##option) 100#define clear_opt(sbi, option) ((sbi)->mount_opt &= ~EROFS_MOUNT_##option)
182#define set_opt(sbi, option) ((sbi)->mount_opt |= EROFS_MOUNT_##option) 101#define set_opt(sbi, option) ((sbi)->mount_opt |= EROFS_MOUNT_##option)
183#define test_opt(sbi, option) ((sbi)->mount_opt & EROFS_MOUNT_##option) 102#define test_opt(sbi, option) ((sbi)->mount_opt & EROFS_MOUNT_##option)
184 103
185#ifdef CONFIG_EROFS_FS_ZIP 104#ifdef CONFIG_EROFS_FS_ZIP
186#define erofs_workstn_lock(sbi) xa_lock(&(sbi)->workstn_tree) 105enum {
187#define erofs_workstn_unlock(sbi) xa_unlock(&(sbi)->workstn_tree) 106 EROFS_ZIP_CACHE_DISABLED,
107 EROFS_ZIP_CACHE_READAHEAD,
108 EROFS_ZIP_CACHE_READAROUND
109};
110
111#define EROFS_LOCKED_MAGIC (INT_MIN | 0xE0F510CCL)
188 112
189/* basic unit of the workstation of a super_block */ 113/* basic unit of the workstation of a super_block */
190struct erofs_workgroup { 114struct erofs_workgroup {
@@ -195,8 +119,6 @@ struct erofs_workgroup {
195 atomic_t refcount; 119 atomic_t refcount;
196}; 120};
197 121
198#define EROFS_LOCKED_MAGIC (INT_MIN | 0xE0F510CCL)
199
200#if defined(CONFIG_SMP) 122#if defined(CONFIG_SMP)
201static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp, 123static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp,
202 int val) 124 int val)
@@ -253,50 +175,14 @@ static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
253 DBG_BUGON(v == EROFS_LOCKED_MAGIC); 175 DBG_BUGON(v == EROFS_LOCKED_MAGIC);
254 return v; 176 return v;
255} 177}
256#endif 178#endif /* !CONFIG_SMP */
257
258int erofs_workgroup_put(struct erofs_workgroup *grp);
259struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
260 pgoff_t index, bool *tag);
261int erofs_register_workgroup(struct super_block *sb,
262 struct erofs_workgroup *grp, bool tag);
263unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi,
264 unsigned long nr_shrink, bool cleanup);
265void erofs_workgroup_free_rcu(struct erofs_workgroup *grp);
266
267#ifdef EROFS_FS_HAS_MANAGED_CACHE
268int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
269 struct erofs_workgroup *egrp);
270int erofs_try_to_free_cached_page(struct address_space *mapping,
271 struct page *page);
272
273#define MNGD_MAPPING(sbi) ((sbi)->managed_cache->i_mapping)
274static inline bool erofs_page_is_managed(const struct erofs_sb_info *sbi,
275 struct page *page)
276{
277 return page->mapping == MNGD_MAPPING(sbi);
278}
279#else
280#define MNGD_MAPPING(sbi) (NULL)
281static inline bool erofs_page_is_managed(const struct erofs_sb_info *sbi,
282 struct page *page) { return false; }
283#endif
284
285#define DEFAULT_MAX_SYNC_DECOMPRESS_PAGES 3
286
287static inline bool __should_decompress_synchronously(struct erofs_sb_info *sbi,
288 unsigned int nr)
289{
290 return nr <= sbi->max_sync_decompress_pages;
291}
292 179
293int __init z_erofs_init_zip_subsystem(void); 180/* hard limit of pages per compressed cluster */
294void z_erofs_exit_zip_subsystem(void); 181#define Z_EROFS_CLUSTER_MAX_PAGES (CONFIG_EROFS_FS_CLUSTER_PAGE_LIMIT)
182#define EROFS_PCPUBUF_NR_PAGES Z_EROFS_CLUSTER_MAX_PAGES
295#else 183#else
296/* dummy initializer/finalizer for the decompression subsystem */ 184#define EROFS_PCPUBUF_NR_PAGES 0
297static inline int z_erofs_init_zip_subsystem(void) { return 0; } 185#endif /* !CONFIG_EROFS_FS_ZIP */
298static inline void z_erofs_exit_zip_subsystem(void) {}
299#endif
300 186
301/* we strictly follow PAGE_SIZE and no buffer head yet */ 187/* we strictly follow PAGE_SIZE and no buffer head yet */
302#define LOG_BLOCK_SIZE PAGE_SHIFT 188#define LOG_BLOCK_SIZE PAGE_SHIFT
@@ -315,23 +201,6 @@ static inline void z_erofs_exit_zip_subsystem(void) {}
315 201
316#define ROOT_NID(sb) ((sb)->root_nid) 202#define ROOT_NID(sb) ((sb)->root_nid)
317 203
318#ifdef CONFIG_EROFS_FS_ZIP
319/* hard limit of pages per compressed cluster */
320#define Z_EROFS_CLUSTER_MAX_PAGES (CONFIG_EROFS_FS_CLUSTER_PAGE_LIMIT)
321
322/* page count of a compressed cluster */
323#define erofs_clusterpages(sbi) ((1 << (sbi)->clusterbits) / PAGE_SIZE)
324
325#define EROFS_PCPUBUF_NR_PAGES Z_EROFS_CLUSTER_MAX_PAGES
326#else
327#define EROFS_PCPUBUF_NR_PAGES 0
328#endif
329
330typedef u64 erofs_off_t;
331
332/* data type for filesystem-wide blocks number */
333typedef u32 erofs_blk_t;
334
335#define erofs_blknr(addr) ((addr) / EROFS_BLKSIZ) 204#define erofs_blknr(addr) ((addr) / EROFS_BLKSIZ)
336#define erofs_blkoff(addr) ((addr) % EROFS_BLKSIZ) 205#define erofs_blkoff(addr) ((addr) % EROFS_BLKSIZ)
337#define blknr_to_addr(nr) ((erofs_off_t)(nr) * EROFS_BLKSIZ) 206#define blknr_to_addr(nr) ((erofs_off_t)(nr) * EROFS_BLKSIZ)
@@ -342,25 +211,25 @@ static inline erofs_off_t iloc(struct erofs_sb_info *sbi, erofs_nid_t nid)
342} 211}
343 212
344/* atomic flag definitions */ 213/* atomic flag definitions */
345#define EROFS_V_EA_INITED_BIT 0 214#define EROFS_I_EA_INITED_BIT 0
346#define EROFS_V_Z_INITED_BIT 1 215#define EROFS_I_Z_INITED_BIT 1
347 216
348/* bitlock definitions (arranged in reverse order) */ 217/* bitlock definitions (arranged in reverse order) */
349#define EROFS_V_BL_XATTR_BIT (BITS_PER_LONG - 1) 218#define EROFS_I_BL_XATTR_BIT (BITS_PER_LONG - 1)
350#define EROFS_V_BL_Z_BIT (BITS_PER_LONG - 2) 219#define EROFS_I_BL_Z_BIT (BITS_PER_LONG - 2)
351 220
352struct erofs_vnode { 221struct erofs_inode {
353 erofs_nid_t nid; 222 erofs_nid_t nid;
354 223
355 /* atomic flags (including bitlocks) */ 224 /* atomic flags (including bitlocks) */
356 unsigned long flags; 225 unsigned long flags;
357 226
358 unsigned char datamode; 227 unsigned char datalayout;
359 unsigned char inode_isize; 228 unsigned char inode_isize;
360 unsigned short xattr_isize; 229 unsigned short xattr_isize;
361 230
362 unsigned xattr_shared_count; 231 unsigned int xattr_shared_count;
363 unsigned *xattr_shared_xattrs; 232 unsigned int *xattr_shared_xattrs;
364 233
365 union { 234 union {
366 erofs_blk_t raw_blkaddr; 235 erofs_blk_t raw_blkaddr;
@@ -371,40 +240,39 @@ struct erofs_vnode {
371 unsigned char z_logical_clusterbits; 240 unsigned char z_logical_clusterbits;
372 unsigned char z_physical_clusterbits[2]; 241 unsigned char z_physical_clusterbits[2];
373 }; 242 };
374#endif 243#endif /* CONFIG_EROFS_FS_ZIP */
375 }; 244 };
376 /* the corresponding vfs inode */ 245 /* the corresponding vfs inode */
377 struct inode vfs_inode; 246 struct inode vfs_inode;
378}; 247};
379 248
380#define EROFS_V(ptr) \ 249#define EROFS_I(ptr) \
381 container_of(ptr, struct erofs_vnode, vfs_inode) 250 container_of(ptr, struct erofs_inode, vfs_inode)
382 251
383#define __inode_advise(x, bit, bits) \ 252static inline unsigned long erofs_inode_datablocks(struct inode *inode)
384 (((x) >> (bit)) & ((1 << (bits)) - 1))
385
386#define __inode_version(advise) \
387 __inode_advise(advise, EROFS_I_VERSION_BIT, \
388 EROFS_I_VERSION_BITS)
389
390#define __inode_data_mapping(advise) \
391 __inode_advise(advise, EROFS_I_DATA_MAPPING_BIT,\
392 EROFS_I_DATA_MAPPING_BITS)
393
394static inline unsigned long inode_datablocks(struct inode *inode)
395{ 253{
396 /* since i_size cannot be changed */ 254 /* since i_size cannot be changed */
397 return DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ); 255 return DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ);
398} 256}
399 257
400static inline bool is_inode_layout_compression(struct inode *inode) 258static inline unsigned int erofs_bitrange(unsigned int value, unsigned int bit,
259 unsigned int bits)
401{ 260{
402 return erofs_inode_is_data_compressed(EROFS_V(inode)->datamode); 261
262 return (value >> bit) & ((1 << bits) - 1);
403} 263}
404 264
405static inline bool is_inode_flat_inline(struct inode *inode) 265
266static inline unsigned int erofs_inode_version(unsigned int value)
406{ 267{
407 return EROFS_V(inode)->datamode == EROFS_INODE_FLAT_INLINE; 268 return erofs_bitrange(value, EROFS_I_VERSION_BIT,
269 EROFS_I_VERSION_BITS);
270}
271
272static inline unsigned int erofs_inode_datalayout(unsigned int value)
273{
274 return erofs_bitrange(value, EROFS_I_DATALAYOUT_BIT,
275 EROFS_I_DATALAYOUT_BITS);
408} 276}
409 277
410extern const struct super_operations erofs_sops; 278extern const struct super_operations erofs_sops;
@@ -472,81 +340,20 @@ int z_erofs_map_blocks_iter(struct inode *inode,
472 struct erofs_map_blocks *map, 340 struct erofs_map_blocks *map,
473 int flags); 341 int flags);
474#else 342#else
475static inline int z_erofs_fill_inode(struct inode *inode) { return -ENOTSUPP; } 343static inline int z_erofs_fill_inode(struct inode *inode) { return -EOPNOTSUPP; }
476static inline int z_erofs_map_blocks_iter(struct inode *inode, 344static inline int z_erofs_map_blocks_iter(struct inode *inode,
477 struct erofs_map_blocks *map, 345 struct erofs_map_blocks *map,
478 int flags) 346 int flags)
479{ 347{
480 return -ENOTSUPP; 348 return -EOPNOTSUPP;
481} 349}
482#endif 350#endif /* !CONFIG_EROFS_FS_ZIP */
483 351
484/* data.c */ 352/* data.c */
485static inline struct bio * 353struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr);
486erofs_grab_bio(struct super_block *sb,
487 erofs_blk_t blkaddr, unsigned int nr_pages, void *bi_private,
488 bio_end_io_t endio, bool nofail)
489{
490 const gfp_t gfp = GFP_NOIO;
491 struct bio *bio;
492
493 do {
494 if (nr_pages == 1) {
495 bio = bio_alloc(gfp | (nofail ? __GFP_NOFAIL : 0), 1);
496 if (unlikely(!bio)) {
497 DBG_BUGON(nofail);
498 return ERR_PTR(-ENOMEM);
499 }
500 break;
501 }
502 bio = bio_alloc(gfp, nr_pages);
503 nr_pages /= 2;
504 } while (unlikely(!bio));
505
506 bio->bi_end_io = endio;
507 bio_set_dev(bio, sb->s_bdev);
508 bio->bi_iter.bi_sector = (sector_t)blkaddr << LOG_SECTORS_PER_BLOCK;
509 bio->bi_private = bi_private;
510 return bio;
511}
512
513static inline void __submit_bio(struct bio *bio, unsigned op, unsigned op_flags)
514{
515 bio_set_op_attrs(bio, op, op_flags);
516 submit_bio(bio);
517}
518
519#ifndef CONFIG_EROFS_FS_IO_MAX_RETRIES
520#define EROFS_IO_MAX_RETRIES_NOFAIL 0
521#else
522#define EROFS_IO_MAX_RETRIES_NOFAIL CONFIG_EROFS_FS_IO_MAX_RETRIES
523#endif
524
525struct page *__erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr,
526 bool prio, bool nofail);
527
528static inline struct page *erofs_get_meta_page(struct super_block *sb,
529 erofs_blk_t blkaddr, bool prio)
530{
531 return __erofs_get_meta_page(sb, blkaddr, prio, false);
532}
533
534static inline struct page *erofs_get_meta_page_nofail(struct super_block *sb,
535 erofs_blk_t blkaddr, bool prio)
536{
537 return __erofs_get_meta_page(sb, blkaddr, prio, true);
538}
539 354
540int erofs_map_blocks(struct inode *, struct erofs_map_blocks *, int); 355int erofs_map_blocks(struct inode *, struct erofs_map_blocks *, int);
541 356
542static inline struct page *
543erofs_get_inline_page(struct inode *inode,
544 erofs_blk_t blkaddr)
545{
546 return erofs_get_meta_page(inode->i_sb,
547 blkaddr, S_ISDIR(inode->i_mode));
548}
549
550/* inode.c */ 357/* inode.c */
551static inline unsigned long erofs_inode_hash(erofs_nid_t nid) 358static inline unsigned long erofs_inode_hash(erofs_nid_t nid)
552{ 359{
@@ -561,16 +368,6 @@ extern const struct inode_operations erofs_generic_iops;
561extern const struct inode_operations erofs_symlink_iops; 368extern const struct inode_operations erofs_symlink_iops;
562extern const struct inode_operations erofs_fast_symlink_iops; 369extern const struct inode_operations erofs_fast_symlink_iops;
563 370
564static inline void set_inode_fast_symlink(struct inode *inode)
565{
566 inode->i_op = &erofs_fast_symlink_iops;
567}
568
569static inline bool is_inode_fast_symlink(struct inode *inode)
570{
571 return inode->i_op == &erofs_fast_symlink_iops;
572}
573
574struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid, bool dir); 371struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid, bool dir);
575int erofs_getattr(const struct path *path, struct kstat *stat, 372int erofs_getattr(const struct path *path, struct kstat *stat,
576 u32 request_mask, unsigned int query_flags); 373 u32 request_mask, unsigned int query_flags);
@@ -584,37 +381,8 @@ int erofs_namei(struct inode *dir, struct qstr *name,
584/* dir.c */ 381/* dir.c */
585extern const struct file_operations erofs_dir_fops; 382extern const struct file_operations erofs_dir_fops;
586 383
587static inline void *erofs_vmap(struct page **pages, unsigned int count) 384/* utils.c / zdata.c */
588{ 385struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp, bool nofail);
589#ifdef CONFIG_EROFS_FS_USE_VM_MAP_RAM
590 int i = 0;
591
592 while (1) {
593 void *addr = vm_map_ram(pages, count, -1, PAGE_KERNEL);
594 /* retry two more times (totally 3 times) */
595 if (addr || ++i >= 3)
596 return addr;
597 vm_unmap_aliases();
598 }
599 return NULL;
600#else
601 return vmap(pages, count, VM_MAP, PAGE_KERNEL);
602#endif
603}
604
605static inline void erofs_vunmap(const void *mem, unsigned int count)
606{
607#ifdef CONFIG_EROFS_FS_USE_VM_MAP_RAM
608 vm_unmap_ram(mem, count);
609#else
610 vunmap(mem);
611#endif
612}
613
614/* utils.c */
615extern struct shrinker erofs_shrinker_info;
616
617struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp);
618 386
619#if (EROFS_PCPUBUF_NR_PAGES > 0) 387#if (EROFS_PCPUBUF_NR_PAGES > 0)
620void *erofs_get_pcpubuf(unsigned int pagenr); 388void *erofs_get_pcpubuf(unsigned int pagenr);
@@ -625,18 +393,39 @@ void *erofs_get_pcpubuf(unsigned int pagenr);
625#else 393#else
626static inline void *erofs_get_pcpubuf(unsigned int pagenr) 394static inline void *erofs_get_pcpubuf(unsigned int pagenr)
627{ 395{
628 return ERR_PTR(-ENOTSUPP); 396 return ERR_PTR(-EOPNOTSUPP);
629} 397}
630 398
631#define erofs_put_pcpubuf(buf) do {} while (0) 399#define erofs_put_pcpubuf(buf) do {} while (0)
632#endif 400#endif
633 401
634void erofs_register_super(struct super_block *sb); 402#ifdef CONFIG_EROFS_FS_ZIP
635void erofs_unregister_super(struct super_block *sb); 403int erofs_workgroup_put(struct erofs_workgroup *grp);
404struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
405 pgoff_t index, bool *tag);
406int erofs_register_workgroup(struct super_block *sb,
407 struct erofs_workgroup *grp, bool tag);
408void erofs_workgroup_free_rcu(struct erofs_workgroup *grp);
409void erofs_shrinker_register(struct super_block *sb);
410void erofs_shrinker_unregister(struct super_block *sb);
411int __init erofs_init_shrinker(void);
412void erofs_exit_shrinker(void);
413int __init z_erofs_init_zip_subsystem(void);
414void z_erofs_exit_zip_subsystem(void);
415int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
416 struct erofs_workgroup *egrp);
417int erofs_try_to_free_cached_page(struct address_space *mapping,
418 struct page *page);
419#else
420static inline void erofs_shrinker_register(struct super_block *sb) {}
421static inline void erofs_shrinker_unregister(struct super_block *sb) {}
422static inline int erofs_init_shrinker(void) { return 0; }
423static inline void erofs_exit_shrinker(void) {}
424static inline int z_erofs_init_zip_subsystem(void) { return 0; }
425static inline void z_erofs_exit_zip_subsystem(void) {}
426#endif /* !CONFIG_EROFS_FS_ZIP */
636 427
637#ifndef lru_to_page 428#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
638#define lru_to_page(head) (list_entry((head)->prev, struct page, lru))
639#endif
640 429
641#endif 430#endif /* __EROFS_INTERNAL_H */
642 431
diff --git a/drivers/staging/erofs/namei.c b/fs/erofs/namei.c
index fd3ae78d0ba5..3abbecbf73de 100644
--- a/drivers/staging/erofs/namei.c
+++ b/fs/erofs/namei.c
@@ -1,16 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0-only
2/* 2/*
3 * linux/drivers/staging/erofs/namei.c
4 *
5 * Copyright (C) 2017-2018 HUAWEI, Inc. 3 * Copyright (C) 2017-2018 HUAWEI, Inc.
6 * http://www.huawei.com/ 4 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com> 5 * Created by Gao Xiang <gaoxiang25@huawei.com>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of the Linux
11 * distribution for more details.
12 */ 6 */
13#include "internal.h"
14#include "xattr.h" 7#include "xattr.h"
15 8
16#include <trace/events/erofs.h> 9#include <trace/events/erofs.h>
@@ -21,9 +14,9 @@ struct erofs_qstr {
21}; 14};
22 15
23/* based on the end of qn is accurate and it must have the trailing '\0' */ 16/* based on the end of qn is accurate and it must have the trailing '\0' */
24static inline int dirnamecmp(const struct erofs_qstr *qn, 17static inline int erofs_dirnamecmp(const struct erofs_qstr *qn,
25 const struct erofs_qstr *qd, 18 const struct erofs_qstr *qd,
26 unsigned int *matched) 19 unsigned int *matched)
27{ 20{
28 unsigned int i = *matched; 21 unsigned int i = *matched;
29 22
@@ -71,16 +64,16 @@ static struct erofs_dirent *find_target_dirent(struct erofs_qstr *name,
71 unsigned int matched = min(startprfx, endprfx); 64 unsigned int matched = min(startprfx, endprfx);
72 struct erofs_qstr dname = { 65 struct erofs_qstr dname = {
73 .name = data + nameoff, 66 .name = data + nameoff,
74 .end = unlikely(mid >= ndirents - 1) ? 67 .end = mid >= ndirents - 1 ?
75 data + dirblksize : 68 data + dirblksize :
76 data + nameoff_from_disk(de[mid + 1].nameoff, 69 data + nameoff_from_disk(de[mid + 1].nameoff,
77 dirblksize) 70 dirblksize)
78 }; 71 };
79 72
80 /* string comparison without already matched prefix */ 73 /* string comparison without already matched prefix */
81 int ret = dirnamecmp(name, &dname, &matched); 74 int ret = erofs_dirnamecmp(name, &dname, &matched);
82 75
83 if (unlikely(!ret)) { 76 if (!ret) {
84 return de + mid; 77 return de + mid;
85 } else if (ret > 0) { 78 } else if (ret > 0) {
86 head = mid + 1; 79 head = mid + 1;
@@ -105,7 +98,7 @@ static struct page *find_target_block_classic(struct inode *dir,
105 98
106 startprfx = endprfx = 0; 99 startprfx = endprfx = 0;
107 head = 0; 100 head = 0;
108 back = inode_datablocks(dir) - 1; 101 back = erofs_inode_datablocks(dir) - 1;
109 102
110 while (head <= back) { 103 while (head <= back) {
111 const int mid = head + (back - head) / 2; 104 const int mid = head + (back - head) / 2;
@@ -120,11 +113,14 @@ static struct page *find_target_block_classic(struct inode *dir,
120 unsigned int matched; 113 unsigned int matched;
121 struct erofs_qstr dname; 114 struct erofs_qstr dname;
122 115
123 if (unlikely(!ndirents)) { 116 if (!ndirents) {
124 DBG_BUGON(1);
125 kunmap_atomic(de); 117 kunmap_atomic(de);
126 put_page(page); 118 put_page(page);
127 page = ERR_PTR(-EIO); 119 erofs_err(dir->i_sb,
120 "corrupted dir block %d @ nid %llu",
121 mid, EROFS_I(dir)->nid);
122 DBG_BUGON(1);
123 page = ERR_PTR(-EFSCORRUPTED);
128 goto out; 124 goto out;
129 } 125 }
130 126
@@ -139,10 +135,10 @@ static struct page *find_target_block_classic(struct inode *dir,
139 EROFS_BLKSIZ); 135 EROFS_BLKSIZ);
140 136
141 /* string comparison without already matched prefix */ 137 /* string comparison without already matched prefix */
142 diff = dirnamecmp(name, &dname, &matched); 138 diff = erofs_dirnamecmp(name, &dname, &matched);
143 kunmap_atomic(de); 139 kunmap_atomic(de);
144 140
145 if (unlikely(!diff)) { 141 if (!diff) {
146 *_ndirents = 0; 142 *_ndirents = 0;
147 goto out; 143 goto out;
148 } else if (diff > 0) { 144 } else if (diff > 0) {
@@ -179,7 +175,7 @@ int erofs_namei(struct inode *dir,
179 struct erofs_dirent *de; 175 struct erofs_dirent *de;
180 struct erofs_qstr qn; 176 struct erofs_qstr qn;
181 177
182 if (unlikely(!dir->i_size)) 178 if (!dir->i_size)
183 return -ENOENT; 179 return -ENOENT;
184 180
185 qn.name = name->name; 181 qn.name = name->name;
@@ -226,7 +222,7 @@ static struct dentry *erofs_lookup(struct inode *dir,
226 trace_erofs_lookup(dir, dentry, flags); 222 trace_erofs_lookup(dir, dentry, flags);
227 223
228 /* file name exceeds fs limit */ 224 /* file name exceeds fs limit */
229 if (unlikely(dentry->d_name.len > EROFS_NAME_LEN)) 225 if (dentry->d_name.len > EROFS_NAME_LEN)
230 return ERR_PTR(-ENAMETOOLONG); 226 return ERR_PTR(-ENAMETOOLONG);
231 227
232 /* false uninitialized warnings on gcc 4.8.x */ 228 /* false uninitialized warnings on gcc 4.8.x */
@@ -235,12 +231,12 @@ static struct dentry *erofs_lookup(struct inode *dir,
235 if (err == -ENOENT) { 231 if (err == -ENOENT) {
236 /* negative dentry */ 232 /* negative dentry */
237 inode = NULL; 233 inode = NULL;
238 } else if (unlikely(err)) { 234 } else if (err) {
239 inode = ERR_PTR(err); 235 inode = ERR_PTR(err);
240 } else { 236 } else {
241 debugln("%s, %s (nid %llu) found, d_type %u", __func__, 237 erofs_dbg("%s, %s (nid %llu) found, d_type %u", __func__,
242 dentry->d_name.name, nid, d_type); 238 dentry->d_name.name, nid, d_type);
243 inode = erofs_iget(dir->i_sb, nid, d_type == EROFS_FT_DIR); 239 inode = erofs_iget(dir->i_sb, nid, d_type == FT_DIR);
244 } 240 }
245 return d_splice_alias(inode, dentry); 241 return d_splice_alias(inode, dentry);
246} 242}
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
new file mode 100644
index 000000000000..caf9a95173b0
--- /dev/null
+++ b/fs/erofs/super.c
@@ -0,0 +1,615 @@
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2017-2018 HUAWEI, Inc.
4 * http://www.huawei.com/
5 * Created by Gao Xiang <gaoxiang25@huawei.com>
6 */
7#include <linux/module.h>
8#include <linux/buffer_head.h>
9#include <linux/statfs.h>
10#include <linux/parser.h>
11#include <linux/seq_file.h>
12#include "xattr.h"
13
14#define CREATE_TRACE_POINTS
15#include <trace/events/erofs.h>
16
17static struct kmem_cache *erofs_inode_cachep __read_mostly;
18
19void _erofs_err(struct super_block *sb, const char *function,
20 const char *fmt, ...)
21{
22 struct va_format vaf;
23 va_list args;
24
25 va_start(args, fmt);
26
27 vaf.fmt = fmt;
28 vaf.va = &args;
29
30 pr_err("(device %s): %s: %pV", sb->s_id, function, &vaf);
31 va_end(args);
32}
33
34void _erofs_info(struct super_block *sb, const char *function,
35 const char *fmt, ...)
36{
37 struct va_format vaf;
38 va_list args;
39
40 va_start(args, fmt);
41
42 vaf.fmt = fmt;
43 vaf.va = &args;
44
45 pr_info("(device %s): %pV", sb->s_id, &vaf);
46 va_end(args);
47}
48
49static void erofs_inode_init_once(void *ptr)
50{
51 struct erofs_inode *vi = ptr;
52
53 inode_init_once(&vi->vfs_inode);
54}
55
56static struct inode *erofs_alloc_inode(struct super_block *sb)
57{
58 struct erofs_inode *vi =
59 kmem_cache_alloc(erofs_inode_cachep, GFP_KERNEL);
60
61 if (!vi)
62 return NULL;
63
64 /* zero out everything except vfs_inode */
65 memset(vi, 0, offsetof(struct erofs_inode, vfs_inode));
66 return &vi->vfs_inode;
67}
68
69static void erofs_free_inode(struct inode *inode)
70{
71 struct erofs_inode *vi = EROFS_I(inode);
72
73 /* be careful of RCU symlink path */
74 if (inode->i_op == &erofs_fast_symlink_iops)
75 kfree(inode->i_link);
76 kfree(vi->xattr_shared_xattrs);
77
78 kmem_cache_free(erofs_inode_cachep, vi);
79}
80
81static bool check_layout_compatibility(struct super_block *sb,
82 struct erofs_super_block *dsb)
83{
84 const unsigned int feature = le32_to_cpu(dsb->feature_incompat);
85
86 EROFS_SB(sb)->feature_incompat = feature;
87
88 /* check if current kernel meets all mandatory requirements */
89 if (feature & (~EROFS_ALL_FEATURE_INCOMPAT)) {
90 erofs_err(sb,
91 "unidentified incompatible feature %x, please upgrade kernel version",
92 feature & ~EROFS_ALL_FEATURE_INCOMPAT);
93 return false;
94 }
95 return true;
96}
97
98static int erofs_read_superblock(struct super_block *sb)
99{
100 struct erofs_sb_info *sbi;
101 struct page *page;
102 struct erofs_super_block *dsb;
103 unsigned int blkszbits;
104 void *data;
105 int ret;
106
107 page = read_mapping_page(sb->s_bdev->bd_inode->i_mapping, 0, NULL);
108 if (!page) {
109 erofs_err(sb, "cannot read erofs superblock");
110 return -EIO;
111 }
112
113 sbi = EROFS_SB(sb);
114
115 data = kmap_atomic(page);
116 dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET);
117
118 ret = -EINVAL;
119 if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) {
120 erofs_err(sb, "cannot find valid erofs superblock");
121 goto out;
122 }
123
124 blkszbits = dsb->blkszbits;
125 /* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */
126 if (blkszbits != LOG_BLOCK_SIZE) {
127 erofs_err(sb, "blksize %u isn't supported on this platform",
128 1 << blkszbits);
129 goto out;
130 }
131
132 if (!check_layout_compatibility(sb, dsb))
133 goto out;
134
135 sbi->blocks = le32_to_cpu(dsb->blocks);
136 sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr);
137#ifdef CONFIG_EROFS_FS_XATTR
138 sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr);
139#endif
140 sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact));
141 sbi->root_nid = le16_to_cpu(dsb->root_nid);
142 sbi->inos = le64_to_cpu(dsb->inos);
143
144 sbi->build_time = le64_to_cpu(dsb->build_time);
145 sbi->build_time_nsec = le32_to_cpu(dsb->build_time_nsec);
146
147 memcpy(&sb->s_uuid, dsb->uuid, sizeof(dsb->uuid));
148
149 ret = strscpy(sbi->volume_name, dsb->volume_name,
150 sizeof(dsb->volume_name));
151 if (ret < 0) { /* -E2BIG */
152 erofs_err(sb, "bad volume name without NIL terminator");
153 ret = -EFSCORRUPTED;
154 goto out;
155 }
156 ret = 0;
157out:
158 kunmap_atomic(data);
159 put_page(page);
160 return ret;
161}
162
163#ifdef CONFIG_EROFS_FS_ZIP
164static int erofs_build_cache_strategy(struct super_block *sb,
165 substring_t *args)
166{
167 struct erofs_sb_info *sbi = EROFS_SB(sb);
168 const char *cs = match_strdup(args);
169 int err = 0;
170
171 if (!cs) {
172 erofs_err(sb, "Not enough memory to store cache strategy");
173 return -ENOMEM;
174 }
175
176 if (!strcmp(cs, "disabled")) {
177 sbi->cache_strategy = EROFS_ZIP_CACHE_DISABLED;
178 } else if (!strcmp(cs, "readahead")) {
179 sbi->cache_strategy = EROFS_ZIP_CACHE_READAHEAD;
180 } else if (!strcmp(cs, "readaround")) {
181 sbi->cache_strategy = EROFS_ZIP_CACHE_READAROUND;
182 } else {
183 erofs_err(sb, "Unrecognized cache strategy \"%s\"", cs);
184 err = -EINVAL;
185 }
186 kfree(cs);
187 return err;
188}
189#else
190static int erofs_build_cache_strategy(struct super_block *sb,
191 substring_t *args)
192{
193 erofs_info(sb, "EROFS compression is disabled, so cache strategy is ignored");
194 return 0;
195}
196#endif
197
198/* set up default EROFS parameters */
199static void erofs_default_options(struct erofs_sb_info *sbi)
200{
201#ifdef CONFIG_EROFS_FS_ZIP
202 sbi->cache_strategy = EROFS_ZIP_CACHE_READAROUND;
203 sbi->max_sync_decompress_pages = 3;
204#endif
205#ifdef CONFIG_EROFS_FS_XATTR
206 set_opt(sbi, XATTR_USER);
207#endif
208#ifdef CONFIG_EROFS_FS_POSIX_ACL
209 set_opt(sbi, POSIX_ACL);
210#endif
211}
212
213enum {
214 Opt_user_xattr,
215 Opt_nouser_xattr,
216 Opt_acl,
217 Opt_noacl,
218 Opt_cache_strategy,
219 Opt_err
220};
221
222static match_table_t erofs_tokens = {
223 {Opt_user_xattr, "user_xattr"},
224 {Opt_nouser_xattr, "nouser_xattr"},
225 {Opt_acl, "acl"},
226 {Opt_noacl, "noacl"},
227 {Opt_cache_strategy, "cache_strategy=%s"},
228 {Opt_err, NULL}
229};
230
231static int erofs_parse_options(struct super_block *sb, char *options)
232{
233 substring_t args[MAX_OPT_ARGS];
234 char *p;
235 int err;
236
237 if (!options)
238 return 0;
239
240 while ((p = strsep(&options, ","))) {
241 int token;
242
243 if (!*p)
244 continue;
245
246 args[0].to = args[0].from = NULL;
247 token = match_token(p, erofs_tokens, args);
248
249 switch (token) {
250#ifdef CONFIG_EROFS_FS_XATTR
251 case Opt_user_xattr:
252 set_opt(EROFS_SB(sb), XATTR_USER);
253 break;
254 case Opt_nouser_xattr:
255 clear_opt(EROFS_SB(sb), XATTR_USER);
256 break;
257#else
258 case Opt_user_xattr:
259 erofs_info(sb, "user_xattr options not supported");
260 break;
261 case Opt_nouser_xattr:
262 erofs_info(sb, "nouser_xattr options not supported");
263 break;
264#endif
265#ifdef CONFIG_EROFS_FS_POSIX_ACL
266 case Opt_acl:
267 set_opt(EROFS_SB(sb), POSIX_ACL);
268 break;
269 case Opt_noacl:
270 clear_opt(EROFS_SB(sb), POSIX_ACL);
271 break;
272#else
273 case Opt_acl:
274 erofs_info(sb, "acl options not supported");
275 break;
276 case Opt_noacl:
277 erofs_info(sb, "noacl options not supported");
278 break;
279#endif
280 case Opt_cache_strategy:
281 err = erofs_build_cache_strategy(sb, args);
282 if (err)
283 return err;
284 break;
285 default:
286 erofs_err(sb, "Unrecognized mount option \"%s\" or missing value", p);
287 return -EINVAL;
288 }
289 }
290 return 0;
291}
292
293#ifdef CONFIG_EROFS_FS_ZIP
294static const struct address_space_operations managed_cache_aops;
295
296static int erofs_managed_cache_releasepage(struct page *page, gfp_t gfp_mask)
297{
298 int ret = 1; /* 0 - busy */
299 struct address_space *const mapping = page->mapping;
300
301 DBG_BUGON(!PageLocked(page));
302 DBG_BUGON(mapping->a_ops != &managed_cache_aops);
303
304 if (PagePrivate(page))
305 ret = erofs_try_to_free_cached_page(mapping, page);
306
307 return ret;
308}
309
310static void erofs_managed_cache_invalidatepage(struct page *page,
311 unsigned int offset,
312 unsigned int length)
313{
314 const unsigned int stop = length + offset;
315
316 DBG_BUGON(!PageLocked(page));
317
318 /* Check for potential overflow in debug mode */
319 DBG_BUGON(stop > PAGE_SIZE || stop < length);
320
321 if (offset == 0 && stop == PAGE_SIZE)
322 while (!erofs_managed_cache_releasepage(page, GFP_NOFS))
323 cond_resched();
324}
325
326static const struct address_space_operations managed_cache_aops = {
327 .releasepage = erofs_managed_cache_releasepage,
328 .invalidatepage = erofs_managed_cache_invalidatepage,
329};
330
331static int erofs_init_managed_cache(struct super_block *sb)
332{
333 struct erofs_sb_info *const sbi = EROFS_SB(sb);
334 struct inode *const inode = new_inode(sb);
335
336 if (!inode)
337 return -ENOMEM;
338
339 set_nlink(inode, 1);
340 inode->i_size = OFFSET_MAX;
341
342 inode->i_mapping->a_ops = &managed_cache_aops;
343 mapping_set_gfp_mask(inode->i_mapping,
344 GFP_NOFS | __GFP_HIGHMEM | __GFP_MOVABLE);
345 sbi->managed_cache = inode;
346 return 0;
347}
348#else
349static int erofs_init_managed_cache(struct super_block *sb) { return 0; }
350#endif
351
352static int erofs_fill_super(struct super_block *sb, void *data, int silent)
353{
354 struct inode *inode;
355 struct erofs_sb_info *sbi;
356 int err;
357
358 sb->s_magic = EROFS_SUPER_MAGIC;
359
360 if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) {
361 erofs_err(sb, "failed to set erofs blksize");
362 return -EINVAL;
363 }
364
365 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
366 if (!sbi)
367 return -ENOMEM;
368
369 sb->s_fs_info = sbi;
370 err = erofs_read_superblock(sb);
371 if (err)
372 return err;
373
374 sb->s_flags |= SB_RDONLY | SB_NOATIME;
375 sb->s_maxbytes = MAX_LFS_FILESIZE;
376 sb->s_time_gran = 1;
377
378 sb->s_op = &erofs_sops;
379
380#ifdef CONFIG_EROFS_FS_XATTR
381 sb->s_xattr = erofs_xattr_handlers;
382#endif
383 /* set erofs default mount options */
384 erofs_default_options(sbi);
385
386 err = erofs_parse_options(sb, data);
387 if (err)
388 return err;
389
390 if (test_opt(sbi, POSIX_ACL))
391 sb->s_flags |= SB_POSIXACL;
392 else
393 sb->s_flags &= ~SB_POSIXACL;
394
395#ifdef CONFIG_EROFS_FS_ZIP
396 INIT_RADIX_TREE(&sbi->workstn_tree, GFP_ATOMIC);
397#endif
398
399 /* get the root inode */
400 inode = erofs_iget(sb, ROOT_NID(sbi), true);
401 if (IS_ERR(inode))
402 return PTR_ERR(inode);
403
404 if (!S_ISDIR(inode->i_mode)) {
405 erofs_err(sb, "rootino(nid %llu) is not a directory(i_mode %o)",
406 ROOT_NID(sbi), inode->i_mode);
407 iput(inode);
408 return -EINVAL;
409 }
410
411 sb->s_root = d_make_root(inode);
412 if (!sb->s_root)
413 return -ENOMEM;
414
415 erofs_shrinker_register(sb);
416 /* sb->s_umount is already locked, SB_ACTIVE and SB_BORN are not set */
417 err = erofs_init_managed_cache(sb);
418 if (err)
419 return err;
420
421 erofs_info(sb, "mounted with opts: %s, root inode @ nid %llu.",
422 (char *)data, ROOT_NID(sbi));
423 return 0;
424}
425
426static struct dentry *erofs_mount(struct file_system_type *fs_type, int flags,
427 const char *dev_name, void *data)
428{
429 return mount_bdev(fs_type, flags, dev_name, data, erofs_fill_super);
430}
431
432/*
433 * could be triggered after deactivate_locked_super()
434 * is called, thus including umount and failed to initialize.
435 */
436static void erofs_kill_sb(struct super_block *sb)
437{
438 struct erofs_sb_info *sbi;
439
440 WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC);
441
442 kill_block_super(sb);
443
444 sbi = EROFS_SB(sb);
445 if (!sbi)
446 return;
447 kfree(sbi);
448 sb->s_fs_info = NULL;
449}
450
451/* called when ->s_root is non-NULL */
452static void erofs_put_super(struct super_block *sb)
453{
454 struct erofs_sb_info *const sbi = EROFS_SB(sb);
455
456 DBG_BUGON(!sbi);
457
458 erofs_shrinker_unregister(sb);
459#ifdef CONFIG_EROFS_FS_ZIP
460 iput(sbi->managed_cache);
461 sbi->managed_cache = NULL;
462#endif
463}
464
465static struct file_system_type erofs_fs_type = {
466 .owner = THIS_MODULE,
467 .name = "erofs",
468 .mount = erofs_mount,
469 .kill_sb = erofs_kill_sb,
470 .fs_flags = FS_REQUIRES_DEV,
471};
472MODULE_ALIAS_FS("erofs");
473
474static int __init erofs_module_init(void)
475{
476 int err;
477
478 erofs_check_ondisk_layout_definitions();
479
480 erofs_inode_cachep = kmem_cache_create("erofs_inode",
481 sizeof(struct erofs_inode), 0,
482 SLAB_RECLAIM_ACCOUNT,
483 erofs_inode_init_once);
484 if (!erofs_inode_cachep) {
485 err = -ENOMEM;
486 goto icache_err;
487 }
488
489 err = erofs_init_shrinker();
490 if (err)
491 goto shrinker_err;
492
493 err = z_erofs_init_zip_subsystem();
494 if (err)
495 goto zip_err;
496
497 err = register_filesystem(&erofs_fs_type);
498 if (err)
499 goto fs_err;
500
501 return 0;
502
503fs_err:
504 z_erofs_exit_zip_subsystem();
505zip_err:
506 erofs_exit_shrinker();
507shrinker_err:
508 kmem_cache_destroy(erofs_inode_cachep);
509icache_err:
510 return err;
511}
512
513static void __exit erofs_module_exit(void)
514{
515 unregister_filesystem(&erofs_fs_type);
516 z_erofs_exit_zip_subsystem();
517 erofs_exit_shrinker();
518
519 /* Ensure all RCU free inodes are safe before cache is destroyed. */
520 rcu_barrier();
521 kmem_cache_destroy(erofs_inode_cachep);
522}
523
524/* get filesystem statistics */
525static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf)
526{
527 struct super_block *sb = dentry->d_sb;
528 struct erofs_sb_info *sbi = EROFS_SB(sb);
529 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
530
531 buf->f_type = sb->s_magic;
532 buf->f_bsize = EROFS_BLKSIZ;
533 buf->f_blocks = sbi->blocks;
534 buf->f_bfree = buf->f_bavail = 0;
535
536 buf->f_files = ULLONG_MAX;
537 buf->f_ffree = ULLONG_MAX - sbi->inos;
538
539 buf->f_namelen = EROFS_NAME_LEN;
540
541 buf->f_fsid.val[0] = (u32)id;
542 buf->f_fsid.val[1] = (u32)(id >> 32);
543 return 0;
544}
545
546static int erofs_show_options(struct seq_file *seq, struct dentry *root)
547{
548 struct erofs_sb_info *sbi __maybe_unused = EROFS_SB(root->d_sb);
549
550#ifdef CONFIG_EROFS_FS_XATTR
551 if (test_opt(sbi, XATTR_USER))
552 seq_puts(seq, ",user_xattr");
553 else
554 seq_puts(seq, ",nouser_xattr");
555#endif
556#ifdef CONFIG_EROFS_FS_POSIX_ACL
557 if (test_opt(sbi, POSIX_ACL))
558 seq_puts(seq, ",acl");
559 else
560 seq_puts(seq, ",noacl");
561#endif
562#ifdef CONFIG_EROFS_FS_ZIP
563 if (sbi->cache_strategy == EROFS_ZIP_CACHE_DISABLED) {
564 seq_puts(seq, ",cache_strategy=disabled");
565 } else if (sbi->cache_strategy == EROFS_ZIP_CACHE_READAHEAD) {
566 seq_puts(seq, ",cache_strategy=readahead");
567 } else if (sbi->cache_strategy == EROFS_ZIP_CACHE_READAROUND) {
568 seq_puts(seq, ",cache_strategy=readaround");
569 } else {
570 seq_puts(seq, ",cache_strategy=(unknown)");
571 DBG_BUGON(1);
572 }
573#endif
574 return 0;
575}
576
577static int erofs_remount(struct super_block *sb, int *flags, char *data)
578{
579 struct erofs_sb_info *sbi = EROFS_SB(sb);
580 unsigned int org_mnt_opt = sbi->mount_opt;
581 int err;
582
583 DBG_BUGON(!sb_rdonly(sb));
584 err = erofs_parse_options(sb, data);
585 if (err)
586 goto out;
587
588 if (test_opt(sbi, POSIX_ACL))
589 sb->s_flags |= SB_POSIXACL;
590 else
591 sb->s_flags &= ~SB_POSIXACL;
592
593 *flags |= SB_RDONLY;
594 return 0;
595out:
596 sbi->mount_opt = org_mnt_opt;
597 return err;
598}
599
600const struct super_operations erofs_sops = {
601 .put_super = erofs_put_super,
602 .alloc_inode = erofs_alloc_inode,
603 .free_inode = erofs_free_inode,
604 .statfs = erofs_statfs,
605 .show_options = erofs_show_options,
606 .remount_fs = erofs_remount,
607};
608
609module_init(erofs_module_init);
610module_exit(erofs_module_exit);
611
612MODULE_DESCRIPTION("Enhanced ROM File System");
613MODULE_AUTHOR("Gao Xiang, Chao Yu, Miao Xie, CONSUMER BG, HUAWEI Inc.");
614MODULE_LICENSE("GPL");
615
diff --git a/drivers/staging/erofs/include/linux/tagptr.h b/fs/erofs/tagptr.h
index ccd106dbd48e..a72897c86744 100644
--- a/drivers/staging/erofs/include/linux/tagptr.h
+++ b/fs/erofs/tagptr.h
@@ -1,11 +1,11 @@
1/* SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0-only */
2 * 2/*
3 * Tagged pointer implementation 3 * A tagged pointer implementation
4 * 4 *
5 * Copyright (C) 2018 Gao Xiang <gaoxiang25@huawei.com> 5 * Copyright (C) 2018 Gao Xiang <gaoxiang25@huawei.com>
6 */ 6 */
7#ifndef _LINUX_TAGPTR_H 7#ifndef __EROFS_FS_TAGPTR_H
8#define _LINUX_TAGPTR_H 8#define __EROFS_FS_TAGPTR_H
9 9
10#include <linux/types.h> 10#include <linux/types.h>
11#include <linux/build_bug.h> 11#include <linux/build_bug.h>
@@ -106,5 +106,5 @@ tagptr_init(o, cmpxchg(&ptptr->v, o.v, n.v)); })
106 ptptr->v &= ~tags; \ 106 ptptr->v &= ~tags; \
107*ptptr; }) 107*ptptr; })
108 108
109#endif 109#endif /* __EROFS_FS_TAGPTR_H */
110 110
diff --git a/drivers/staging/erofs/utils.c b/fs/erofs/utils.c
index 4bbd3bf34acd..d92b3e753a6f 100644
--- a/drivers/staging/erofs/utils.c
+++ b/fs/erofs/utils.c
@@ -1,28 +1,22 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0-only
2/* 2/*
3 * linux/drivers/staging/erofs/utils.c
4 *
5 * Copyright (C) 2018 HUAWEI, Inc. 3 * Copyright (C) 2018 HUAWEI, Inc.
6 * http://www.huawei.com/ 4 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com> 5 * Created by Gao Xiang <gaoxiang25@huawei.com>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of the Linux
11 * distribution for more details.
12 */ 6 */
13
14#include "internal.h" 7#include "internal.h"
15#include <linux/pagevec.h> 8#include <linux/pagevec.h>
16 9
17struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp) 10struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp, bool nofail)
18{ 11{
19 struct page *page; 12 struct page *page;
20 13
21 if (!list_empty(pool)) { 14 if (!list_empty(pool)) {
22 page = lru_to_page(pool); 15 page = lru_to_page(pool);
16 DBG_BUGON(page_ref_count(page) != 1);
23 list_del(&page->lru); 17 list_del(&page->lru);
24 } else { 18 } else {
25 page = alloc_pages(gfp | __GFP_NOFAIL, 0); 19 page = alloc_pages(gfp | (nofail ? __GFP_NOFAIL : 0), 0);
26 } 20 }
27 return page; 21 return page;
28} 22}
@@ -39,10 +33,10 @@ void *erofs_get_pcpubuf(unsigned int pagenr)
39} 33}
40#endif 34#endif
41 35
36#ifdef CONFIG_EROFS_FS_ZIP
42/* global shrink count (for all mounted EROFS instances) */ 37/* global shrink count (for all mounted EROFS instances) */
43static atomic_long_t erofs_global_shrink_cnt; 38static atomic_long_t erofs_global_shrink_cnt;
44 39
45#ifdef CONFIG_EROFS_FS_ZIP
46#define __erofs_workgroup_get(grp) atomic_inc(&(grp)->refcount) 40#define __erofs_workgroup_get(grp) atomic_inc(&(grp)->refcount)
47#define __erofs_workgroup_put(grp) atomic_dec(&(grp)->refcount) 41#define __erofs_workgroup_put(grp) atomic_dec(&(grp)->refcount)
48 42
@@ -52,14 +46,14 @@ static int erofs_workgroup_get(struct erofs_workgroup *grp)
52 46
53repeat: 47repeat:
54 o = erofs_wait_on_workgroup_freezed(grp); 48 o = erofs_wait_on_workgroup_freezed(grp);
55 if (unlikely(o <= 0)) 49 if (o <= 0)
56 return -1; 50 return -1;
57 51
58 if (unlikely(atomic_cmpxchg(&grp->refcount, o, o + 1) != o)) 52 if (atomic_cmpxchg(&grp->refcount, o, o + 1) != o)
59 goto repeat; 53 goto repeat;
60 54
61 /* decrease refcount paired by erofs_workgroup_put */ 55 /* decrease refcount paired by erofs_workgroup_put */
62 if (unlikely(o == 1)) 56 if (o == 1)
63 atomic_long_dec(&erofs_global_shrink_cnt); 57 atomic_long_dec(&erofs_global_shrink_cnt);
64 return 0; 58 return 0;
65} 59}
@@ -97,7 +91,7 @@ int erofs_register_workgroup(struct super_block *sb,
97 int err; 91 int err;
98 92
99 /* grp shouldn't be broken or used before */ 93 /* grp shouldn't be broken or used before */
100 if (unlikely(atomic_read(&grp->refcount) != 1)) { 94 if (atomic_read(&grp->refcount) != 1) {
101 DBG_BUGON(1); 95 DBG_BUGON(1);
102 return -EINVAL; 96 return -EINVAL;
103 } 97 }
@@ -107,27 +101,26 @@ int erofs_register_workgroup(struct super_block *sb,
107 return err; 101 return err;
108 102
109 sbi = EROFS_SB(sb); 103 sbi = EROFS_SB(sb);
110 erofs_workstn_lock(sbi); 104 xa_lock(&sbi->workstn_tree);
111 105
112 grp = xa_tag_pointer(grp, tag); 106 grp = xa_tag_pointer(grp, tag);
113 107
114 /* 108 /*
115 * Bump up reference count before making this workgroup 109 * Bump up reference count before making this workgroup
116 * visible to other users in order to avoid potential UAF 110 * visible to other users in order to avoid potential UAF
117 * without serialized by erofs_workstn_lock. 111 * without serialized by workstn_lock.
118 */ 112 */
119 __erofs_workgroup_get(grp); 113 __erofs_workgroup_get(grp);
120 114
121 err = radix_tree_insert(&sbi->workstn_tree, 115 err = radix_tree_insert(&sbi->workstn_tree, grp->index, grp);
122 grp->index, grp); 116 if (err)
123 if (unlikely(err))
124 /* 117 /*
125 * it's safe to decrease since the workgroup isn't visible 118 * it's safe to decrease since the workgroup isn't visible
126 * and refcount >= 2 (cannot be freezed). 119 * and refcount >= 2 (cannot be freezed).
127 */ 120 */
128 __erofs_workgroup_put(grp); 121 __erofs_workgroup_put(grp);
129 122
130 erofs_workstn_unlock(sbi); 123 xa_unlock(&sbi->workstn_tree);
131 radix_tree_preload_end(); 124 radix_tree_preload_end();
132 return err; 125 return err;
133} 126}
@@ -149,8 +142,6 @@ int erofs_workgroup_put(struct erofs_workgroup *grp)
149 return count; 142 return count;
150} 143}
151 144
152#ifdef EROFS_FS_HAS_MANAGED_CACHE
153/* for cache-managed case, customized reclaim paths exist */
154static void erofs_workgroup_unfreeze_final(struct erofs_workgroup *grp) 145static void erofs_workgroup_unfreeze_final(struct erofs_workgroup *grp)
155{ 146{
156 erofs_workgroup_unfreeze(grp, 0); 147 erofs_workgroup_unfreeze(grp, 0);
@@ -162,18 +153,18 @@ static bool erofs_try_to_release_workgroup(struct erofs_sb_info *sbi,
162 bool cleanup) 153 bool cleanup)
163{ 154{
164 /* 155 /*
165 * for managed cache enabled, the refcount of workgroups 156 * If managed cache is on, refcount of workgroups
166 * themselves could be < 0 (freezed). So there is no guarantee 157 * themselves could be < 0 (freezed). In other words,
167 * that all refcount > 0 if managed cache is enabled. 158 * there is no guarantee that all refcounts > 0.
168 */ 159 */
169 if (!erofs_workgroup_try_to_freeze(grp, 1)) 160 if (!erofs_workgroup_try_to_freeze(grp, 1))
170 return false; 161 return false;
171 162
172 /* 163 /*
173 * note that all cached pages should be unlinked 164 * Note that all cached pages should be unattached
174 * before delete it from the radix tree. 165 * before deleted from the radix tree. Otherwise some
175 * Otherwise some cached pages of an orphan old workgroup 166 * cached pages could be still attached to the orphan
176 * could be still linked after the new one is available. 167 * old workgroup when the new one is available in the tree.
177 */ 168 */
178 if (erofs_try_to_free_all_cached_pages(sbi, grp)) { 169 if (erofs_try_to_free_all_cached_pages(sbi, grp)) {
179 erofs_workgroup_unfreeze(grp, 1); 170 erofs_workgroup_unfreeze(grp, 1);
@@ -181,7 +172,7 @@ static bool erofs_try_to_release_workgroup(struct erofs_sb_info *sbi,
181 } 172 }
182 173
183 /* 174 /*
184 * it is impossible to fail after the workgroup is freezed, 175 * It's impossible to fail after the workgroup is freezed,
185 * however in order to avoid some race conditions, add a 176 * however in order to avoid some race conditions, add a
186 * DBG_BUGON to observe this in advance. 177 * DBG_BUGON to observe this in advance.
187 */ 178 */
@@ -189,40 +180,16 @@ static bool erofs_try_to_release_workgroup(struct erofs_sb_info *sbi,
189 grp->index)) != grp); 180 grp->index)) != grp);
190 181
191 /* 182 /*
192 * if managed cache is enable, the last refcount 183 * If managed cache is on, last refcount should indicate
193 * should indicate the related workstation. 184 * the related workstation.
194 */ 185 */
195 erofs_workgroup_unfreeze_final(grp); 186 erofs_workgroup_unfreeze_final(grp);
196 return true; 187 return true;
197} 188}
198 189
199#else 190static unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi,
200/* for nocache case, no customized reclaim path at all */ 191 unsigned long nr_shrink,
201static bool erofs_try_to_release_workgroup(struct erofs_sb_info *sbi, 192 bool cleanup)
202 struct erofs_workgroup *grp,
203 bool cleanup)
204{
205 int cnt = atomic_read(&grp->refcount);
206
207 DBG_BUGON(cnt <= 0);
208 DBG_BUGON(cleanup && cnt != 1);
209
210 if (cnt > 1)
211 return false;
212
213 DBG_BUGON(xa_untag_pointer(radix_tree_delete(&sbi->workstn_tree,
214 grp->index)) != grp);
215
216 /* (rarely) could be grabbed again when freeing */
217 erofs_workgroup_put(grp);
218 return true;
219}
220
221#endif
222
223unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi,
224 unsigned long nr_shrink,
225 bool cleanup)
226{ 193{
227 pgoff_t first_index = 0; 194 pgoff_t first_index = 0;
228 void *batch[PAGEVEC_SIZE]; 195 void *batch[PAGEVEC_SIZE];
@@ -230,7 +197,7 @@ unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi,
230 197
231 int i, found; 198 int i, found;
232repeat: 199repeat:
233 erofs_workstn_lock(sbi); 200 xa_lock(&sbi->workstn_tree);
234 201
235 found = radix_tree_gang_lookup(&sbi->workstn_tree, 202 found = radix_tree_gang_lookup(&sbi->workstn_tree,
236 batch, first_index, PAGEVEC_SIZE); 203 batch, first_index, PAGEVEC_SIZE);
@@ -245,18 +212,16 @@ repeat:
245 continue; 212 continue;
246 213
247 ++freed; 214 ++freed;
248 if (unlikely(!--nr_shrink)) 215 if (!--nr_shrink)
249 break; 216 break;
250 } 217 }
251 erofs_workstn_unlock(sbi); 218 xa_unlock(&sbi->workstn_tree);
252 219
253 if (i && nr_shrink) 220 if (i && nr_shrink)
254 goto repeat; 221 goto repeat;
255 return freed; 222 return freed;
256} 223}
257 224
258#endif
259
260/* protected by 'erofs_sb_list_lock' */ 225/* protected by 'erofs_sb_list_lock' */
261static unsigned int shrinker_run_no; 226static unsigned int shrinker_run_no;
262 227
@@ -264,7 +229,7 @@ static unsigned int shrinker_run_no;
264static DEFINE_SPINLOCK(erofs_sb_list_lock); 229static DEFINE_SPINLOCK(erofs_sb_list_lock);
265static LIST_HEAD(erofs_sb_list); 230static LIST_HEAD(erofs_sb_list);
266 231
267void erofs_register_super(struct super_block *sb) 232void erofs_shrinker_register(struct super_block *sb)
268{ 233{
269 struct erofs_sb_info *sbi = EROFS_SB(sb); 234 struct erofs_sb_info *sbi = EROFS_SB(sb);
270 235
@@ -275,11 +240,17 @@ void erofs_register_super(struct super_block *sb)
275 spin_unlock(&erofs_sb_list_lock); 240 spin_unlock(&erofs_sb_list_lock);
276} 241}
277 242
278void erofs_unregister_super(struct super_block *sb) 243void erofs_shrinker_unregister(struct super_block *sb)
279{ 244{
245 struct erofs_sb_info *const sbi = EROFS_SB(sb);
246
247 mutex_lock(&sbi->umount_mutex);
248 erofs_shrink_workstation(sbi, ~0UL, true);
249
280 spin_lock(&erofs_sb_list_lock); 250 spin_lock(&erofs_sb_list_lock);
281 list_del(&EROFS_SB(sb)->list); 251 list_del(&sbi->list);
282 spin_unlock(&erofs_sb_list_lock); 252 spin_unlock(&erofs_sb_list_lock);
253 mutex_unlock(&sbi->umount_mutex);
283} 254}
284 255
285static unsigned long erofs_shrink_count(struct shrinker *shrink, 256static unsigned long erofs_shrink_count(struct shrinker *shrink,
@@ -299,9 +270,9 @@ static unsigned long erofs_shrink_scan(struct shrinker *shrink,
299 unsigned long freed = 0; 270 unsigned long freed = 0;
300 271
301 spin_lock(&erofs_sb_list_lock); 272 spin_lock(&erofs_sb_list_lock);
302 do 273 do {
303 run_no = ++shrinker_run_no; 274 run_no = ++shrinker_run_no;
304 while (run_no == 0); 275 } while (run_no == 0);
305 276
306 /* Iterate over all mounted superblocks and try to shrink them */ 277 /* Iterate over all mounted superblocks and try to shrink them */
307 p = erofs_sb_list.next; 278 p = erofs_sb_list.next;
@@ -323,9 +294,7 @@ static unsigned long erofs_shrink_scan(struct shrinker *shrink,
323 spin_unlock(&erofs_sb_list_lock); 294 spin_unlock(&erofs_sb_list_lock);
324 sbi->shrinker_run_no = run_no; 295 sbi->shrinker_run_no = run_no;
325 296
326#ifdef CONFIG_EROFS_FS_ZIP
327 freed += erofs_shrink_workstation(sbi, nr, false); 297 freed += erofs_shrink_workstation(sbi, nr, false);
328#endif
329 298
330 spin_lock(&erofs_sb_list_lock); 299 spin_lock(&erofs_sb_list_lock);
331 /* Get the next list element before we move this one */ 300 /* Get the next list element before we move this one */
@@ -345,9 +314,20 @@ static unsigned long erofs_shrink_scan(struct shrinker *shrink,
345 return freed; 314 return freed;
346} 315}
347 316
348struct shrinker erofs_shrinker_info = { 317static struct shrinker erofs_shrinker_info = {
349 .scan_objects = erofs_shrink_scan, 318 .scan_objects = erofs_shrink_scan,
350 .count_objects = erofs_shrink_count, 319 .count_objects = erofs_shrink_count,
351 .seeks = DEFAULT_SEEKS, 320 .seeks = DEFAULT_SEEKS,
352}; 321};
353 322
323int __init erofs_init_shrinker(void)
324{
325 return register_shrinker(&erofs_shrinker_info);
326}
327
328void erofs_exit_shrinker(void)
329{
330 unregister_shrinker(&erofs_shrinker_info);
331}
332#endif /* !CONFIG_EROFS_FS_ZIP */
333
diff --git a/drivers/staging/erofs/xattr.c b/fs/erofs/xattr.c
index df40654b9fbb..a13a78725c57 100644
--- a/drivers/staging/erofs/xattr.c
+++ b/fs/erofs/xattr.c
@@ -1,14 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0-only
2/* 2/*
3 * linux/drivers/staging/erofs/xattr.c
4 *
5 * Copyright (C) 2017-2018 HUAWEI, Inc. 3 * Copyright (C) 2017-2018 HUAWEI, Inc.
6 * http://www.huawei.com/ 4 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com> 5 * Created by Gao Xiang <gaoxiang25@huawei.com>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of the Linux
11 * distribution for more details.
12 */ 6 */
13#include <linux/security.h> 7#include <linux/security.h>
14#include "xattr.h" 8#include "xattr.h"
@@ -25,7 +19,7 @@ struct xattr_iter {
25static inline void xattr_iter_end(struct xattr_iter *it, bool atomic) 19static inline void xattr_iter_end(struct xattr_iter *it, bool atomic)
26{ 20{
27 /* the only user of kunmap() is 'init_inode_xattrs' */ 21 /* the only user of kunmap() is 'init_inode_xattrs' */
28 if (unlikely(!atomic)) 22 if (!atomic)
29 kunmap(it->page); 23 kunmap(it->page);
30 else 24 else
31 kunmap_atomic(it->kaddr); 25 kunmap_atomic(it->kaddr);
@@ -44,7 +38,7 @@ static inline void xattr_iter_end_final(struct xattr_iter *it)
44 38
45static int init_inode_xattrs(struct inode *inode) 39static int init_inode_xattrs(struct inode *inode)
46{ 40{
47 struct erofs_vnode *const vi = EROFS_V(inode); 41 struct erofs_inode *const vi = EROFS_I(inode);
48 struct xattr_iter it; 42 struct xattr_iter it;
49 unsigned int i; 43 unsigned int i;
50 struct erofs_xattr_ibody_header *ih; 44 struct erofs_xattr_ibody_header *ih;
@@ -54,14 +48,14 @@ static int init_inode_xattrs(struct inode *inode)
54 int ret = 0; 48 int ret = 0;
55 49
56 /* the most case is that xattrs of this inode are initialized. */ 50 /* the most case is that xattrs of this inode are initialized. */
57 if (test_bit(EROFS_V_EA_INITED_BIT, &vi->flags)) 51 if (test_bit(EROFS_I_EA_INITED_BIT, &vi->flags))
58 return 0; 52 return 0;
59 53
60 if (wait_on_bit_lock(&vi->flags, EROFS_V_BL_XATTR_BIT, TASK_KILLABLE)) 54 if (wait_on_bit_lock(&vi->flags, EROFS_I_BL_XATTR_BIT, TASK_KILLABLE))
61 return -ERESTARTSYS; 55 return -ERESTARTSYS;
62 56
63 /* someone has initialized xattrs for us? */ 57 /* someone has initialized xattrs for us? */
64 if (test_bit(EROFS_V_EA_INITED_BIT, &vi->flags)) 58 if (test_bit(EROFS_I_EA_INITED_BIT, &vi->flags))
65 goto out_unlock; 59 goto out_unlock;
66 60
67 /* 61 /*
@@ -73,14 +67,17 @@ static int init_inode_xattrs(struct inode *inode)
73 * undefined right now (maybe use later with some new sb feature). 67 * undefined right now (maybe use later with some new sb feature).
74 */ 68 */
75 if (vi->xattr_isize == sizeof(struct erofs_xattr_ibody_header)) { 69 if (vi->xattr_isize == sizeof(struct erofs_xattr_ibody_header)) {
76 errln("xattr_isize %d of nid %llu is not supported yet", 70 erofs_err(inode->i_sb,
77 vi->xattr_isize, vi->nid); 71 "xattr_isize %d of nid %llu is not supported yet",
78 ret = -ENOTSUPP; 72 vi->xattr_isize, vi->nid);
73 ret = -EOPNOTSUPP;
79 goto out_unlock; 74 goto out_unlock;
80 } else if (vi->xattr_isize < sizeof(struct erofs_xattr_ibody_header)) { 75 } else if (vi->xattr_isize < sizeof(struct erofs_xattr_ibody_header)) {
81 if (unlikely(vi->xattr_isize)) { 76 if (vi->xattr_isize) {
77 erofs_err(inode->i_sb,
78 "bogus xattr ibody @ nid %llu", vi->nid);
82 DBG_BUGON(1); 79 DBG_BUGON(1);
83 ret = -EIO; 80 ret = -EFSCORRUPTED;
84 goto out_unlock; /* xattr ondisk layout error */ 81 goto out_unlock; /* xattr ondisk layout error */
85 } 82 }
86 ret = -ENOATTR; 83 ret = -ENOATTR;
@@ -92,7 +89,7 @@ static int init_inode_xattrs(struct inode *inode)
92 it.blkaddr = erofs_blknr(iloc(sbi, vi->nid) + vi->inode_isize); 89 it.blkaddr = erofs_blknr(iloc(sbi, vi->nid) + vi->inode_isize);
93 it.ofs = erofs_blkoff(iloc(sbi, vi->nid) + vi->inode_isize); 90 it.ofs = erofs_blkoff(iloc(sbi, vi->nid) + vi->inode_isize);
94 91
95 it.page = erofs_get_inline_page(inode, it.blkaddr); 92 it.page = erofs_get_meta_page(sb, it.blkaddr);
96 if (IS_ERR(it.page)) { 93 if (IS_ERR(it.page)) {
97 ret = PTR_ERR(it.page); 94 ret = PTR_ERR(it.page);
98 goto out_unlock; 95 goto out_unlock;
@@ -117,13 +114,12 @@ static int init_inode_xattrs(struct inode *inode)
117 it.ofs += sizeof(struct erofs_xattr_ibody_header); 114 it.ofs += sizeof(struct erofs_xattr_ibody_header);
118 115
119 for (i = 0; i < vi->xattr_shared_count; ++i) { 116 for (i = 0; i < vi->xattr_shared_count; ++i) {
120 if (unlikely(it.ofs >= EROFS_BLKSIZ)) { 117 if (it.ofs >= EROFS_BLKSIZ) {
121 /* cannot be unaligned */ 118 /* cannot be unaligned */
122 BUG_ON(it.ofs != EROFS_BLKSIZ); 119 DBG_BUGON(it.ofs != EROFS_BLKSIZ);
123 xattr_iter_end(&it, atomic_map); 120 xattr_iter_end(&it, atomic_map);
124 121
125 it.page = erofs_get_meta_page(sb, ++it.blkaddr, 122 it.page = erofs_get_meta_page(sb, ++it.blkaddr);
126 S_ISDIR(inode->i_mode));
127 if (IS_ERR(it.page)) { 123 if (IS_ERR(it.page)) {
128 kfree(vi->xattr_shared_xattrs); 124 kfree(vi->xattr_shared_xattrs);
129 vi->xattr_shared_xattrs = NULL; 125 vi->xattr_shared_xattrs = NULL;
@@ -141,10 +137,10 @@ static int init_inode_xattrs(struct inode *inode)
141 } 137 }
142 xattr_iter_end(&it, atomic_map); 138 xattr_iter_end(&it, atomic_map);
143 139
144 set_bit(EROFS_V_EA_INITED_BIT, &vi->flags); 140 set_bit(EROFS_I_EA_INITED_BIT, &vi->flags);
145 141
146out_unlock: 142out_unlock:
147 clear_and_wake_up_bit(EROFS_V_BL_XATTR_BIT, &vi->flags); 143 clear_and_wake_up_bit(EROFS_I_BL_XATTR_BIT, &vi->flags);
148 return ret; 144 return ret;
149} 145}
150 146
@@ -173,7 +169,7 @@ static inline int xattr_iter_fixup(struct xattr_iter *it)
173 169
174 it->blkaddr += erofs_blknr(it->ofs); 170 it->blkaddr += erofs_blknr(it->ofs);
175 171
176 it->page = erofs_get_meta_page(it->sb, it->blkaddr, false); 172 it->page = erofs_get_meta_page(it->sb, it->blkaddr);
177 if (IS_ERR(it->page)) { 173 if (IS_ERR(it->page)) {
178 int err = PTR_ERR(it->page); 174 int err = PTR_ERR(it->page);
179 175
@@ -189,13 +185,13 @@ static inline int xattr_iter_fixup(struct xattr_iter *it)
189static int inline_xattr_iter_begin(struct xattr_iter *it, 185static int inline_xattr_iter_begin(struct xattr_iter *it,
190 struct inode *inode) 186 struct inode *inode)
191{ 187{
192 struct erofs_vnode *const vi = EROFS_V(inode); 188 struct erofs_inode *const vi = EROFS_I(inode);
193 struct erofs_sb_info *const sbi = EROFS_SB(inode->i_sb); 189 struct erofs_sb_info *const sbi = EROFS_SB(inode->i_sb);
194 unsigned int xattr_header_sz, inline_xattr_ofs; 190 unsigned int xattr_header_sz, inline_xattr_ofs;
195 191
196 xattr_header_sz = inlinexattr_header_size(inode); 192 xattr_header_sz = inlinexattr_header_size(inode);
197 if (unlikely(xattr_header_sz >= vi->xattr_isize)) { 193 if (xattr_header_sz >= vi->xattr_isize) {
198 BUG_ON(xattr_header_sz > vi->xattr_isize); 194 DBG_BUGON(xattr_header_sz > vi->xattr_isize);
199 return -ENOATTR; 195 return -ENOATTR;
200 } 196 }
201 197
@@ -204,7 +200,7 @@ static int inline_xattr_iter_begin(struct xattr_iter *it,
204 it->blkaddr = erofs_blknr(iloc(sbi, vi->nid) + inline_xattr_ofs); 200 it->blkaddr = erofs_blknr(iloc(sbi, vi->nid) + inline_xattr_ofs);
205 it->ofs = erofs_blkoff(iloc(sbi, vi->nid) + inline_xattr_ofs); 201 it->ofs = erofs_blkoff(iloc(sbi, vi->nid) + inline_xattr_ofs);
206 202
207 it->page = erofs_get_inline_page(inode, it->blkaddr); 203 it->page = erofs_get_meta_page(inode->i_sb, it->blkaddr);
208 if (IS_ERR(it->page)) 204 if (IS_ERR(it->page))
209 return PTR_ERR(it->page); 205 return PTR_ERR(it->page);
210 206
@@ -236,9 +232,13 @@ static int xattr_foreach(struct xattr_iter *it,
236 */ 232 */
237 entry = *(struct erofs_xattr_entry *)(it->kaddr + it->ofs); 233 entry = *(struct erofs_xattr_entry *)(it->kaddr + it->ofs);
238 if (tlimit) { 234 if (tlimit) {
239 unsigned int entry_sz = EROFS_XATTR_ENTRY_SIZE(&entry); 235 unsigned int entry_sz = erofs_xattr_entry_size(&entry);
240 236
241 BUG_ON(*tlimit < entry_sz); 237 /* xattr on-disk corruption: xattr entry beyond xattr_isize */
238 if (*tlimit < entry_sz) {
239 DBG_BUGON(1);
240 return -EFSCORRUPTED;
241 }
242 *tlimit -= entry_sz; 242 *tlimit -= entry_sz;
243 } 243 }
244 244
@@ -257,7 +257,7 @@ static int xattr_foreach(struct xattr_iter *it,
257 257
258 while (processed < entry.e_name_len) { 258 while (processed < entry.e_name_len) {
259 if (it->ofs >= EROFS_BLKSIZ) { 259 if (it->ofs >= EROFS_BLKSIZ) {
260 BUG_ON(it->ofs > EROFS_BLKSIZ); 260 DBG_BUGON(it->ofs > EROFS_BLKSIZ);
261 261
262 err = xattr_iter_fixup(it); 262 err = xattr_iter_fixup(it);
263 if (err) 263 if (err)
@@ -292,7 +292,7 @@ static int xattr_foreach(struct xattr_iter *it,
292 292
293 while (processed < value_sz) { 293 while (processed < value_sz) {
294 if (it->ofs >= EROFS_BLKSIZ) { 294 if (it->ofs >= EROFS_BLKSIZ) {
295 BUG_ON(it->ofs > EROFS_BLKSIZ); 295 DBG_BUGON(it->ofs > EROFS_BLKSIZ);
296 296
297 err = xattr_iter_fixup(it); 297 err = xattr_iter_fixup(it);
298 if (err) 298 if (err)
@@ -386,7 +386,7 @@ static int inline_getxattr(struct inode *inode, struct getxattr_iter *it)
386 386
387static int shared_getxattr(struct inode *inode, struct getxattr_iter *it) 387static int shared_getxattr(struct inode *inode, struct getxattr_iter *it)
388{ 388{
389 struct erofs_vnode *const vi = EROFS_V(inode); 389 struct erofs_inode *const vi = EROFS_I(inode);
390 struct super_block *const sb = inode->i_sb; 390 struct super_block *const sb = inode->i_sb;
391 struct erofs_sb_info *const sbi = EROFS_SB(sb); 391 struct erofs_sb_info *const sbi = EROFS_SB(sb);
392 unsigned int i; 392 unsigned int i;
@@ -402,7 +402,7 @@ static int shared_getxattr(struct inode *inode, struct getxattr_iter *it)
402 if (i) 402 if (i)
403 xattr_iter_end(&it->it, true); 403 xattr_iter_end(&it->it, true);
404 404
405 it->it.page = erofs_get_meta_page(sb, blkaddr, false); 405 it->it.page = erofs_get_meta_page(sb, blkaddr);
406 if (IS_ERR(it->it.page)) 406 if (IS_ERR(it->it.page))
407 return PTR_ERR(it->it.page); 407 return PTR_ERR(it->it.page);
408 408
@@ -437,7 +437,7 @@ int erofs_getxattr(struct inode *inode, int index,
437 int ret; 437 int ret;
438 struct getxattr_iter it; 438 struct getxattr_iter it;
439 439
440 if (unlikely(!name)) 440 if (!name)
441 return -EINVAL; 441 return -EINVAL;
442 442
443 ret = init_inode_xattrs(inode); 443 ret = init_inode_xattrs(inode);
@@ -609,7 +609,7 @@ static int inline_listxattr(struct listxattr_iter *it)
609static int shared_listxattr(struct listxattr_iter *it) 609static int shared_listxattr(struct listxattr_iter *it)
610{ 610{
611 struct inode *const inode = d_inode(it->dentry); 611 struct inode *const inode = d_inode(it->dentry);
612 struct erofs_vnode *const vi = EROFS_V(inode); 612 struct erofs_inode *const vi = EROFS_I(inode);
613 struct super_block *const sb = inode->i_sb; 613 struct super_block *const sb = inode->i_sb;
614 struct erofs_sb_info *const sbi = EROFS_SB(sb); 614 struct erofs_sb_info *const sbi = EROFS_SB(sb);
615 unsigned int i; 615 unsigned int i;
@@ -624,7 +624,7 @@ static int shared_listxattr(struct listxattr_iter *it)
624 if (i) 624 if (i)
625 xattr_iter_end(&it->it, true); 625 xattr_iter_end(&it->it, true);
626 626
627 it->it.page = erofs_get_meta_page(sb, blkaddr, false); 627 it->it.page = erofs_get_meta_page(sb, blkaddr);
628 if (IS_ERR(it->it.page)) 628 if (IS_ERR(it->it.page))
629 return PTR_ERR(it->it.page); 629 return PTR_ERR(it->it.page);
630 630
diff --git a/drivers/staging/erofs/xattr.h b/fs/erofs/xattr.h
index 35ba5ac2139a..3585b84d2f20 100644
--- a/drivers/staging/erofs/xattr.h
+++ b/fs/erofs/xattr.h
@@ -1,14 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0-only */
2 * 2/*
3 * linux/drivers/staging/erofs/xattr.h
4 *
5 * Copyright (C) 2017-2018 HUAWEI, Inc. 3 * Copyright (C) 2017-2018 HUAWEI, Inc.
6 * http://www.huawei.com/ 4 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com> 5 * Created by Gao Xiang <gaoxiang25@huawei.com>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of the Linux
11 * distribution for more details.
12 */ 6 */
13#ifndef __EROFS_XATTR_H 7#ifndef __EROFS_XATTR_H
14#define __EROFS_XATTR_H 8#define __EROFS_XATTR_H
@@ -20,14 +14,14 @@
20/* Attribute not found */ 14/* Attribute not found */
21#define ENOATTR ENODATA 15#define ENOATTR ENODATA
22 16
23static inline unsigned inlinexattr_header_size(struct inode *inode) 17static inline unsigned int inlinexattr_header_size(struct inode *inode)
24{ 18{
25 return sizeof(struct erofs_xattr_ibody_header) 19 return sizeof(struct erofs_xattr_ibody_header) +
26 + sizeof(u32) * EROFS_V(inode)->xattr_shared_count; 20 sizeof(u32) * EROFS_I(inode)->xattr_shared_count;
27} 21}
28 22
29static inline erofs_blk_t 23static inline erofs_blk_t xattrblock_addr(struct erofs_sb_info *sbi,
30xattrblock_addr(struct erofs_sb_info *sbi, unsigned xattr_id) 24 unsigned int xattr_id)
31{ 25{
32#ifdef CONFIG_EROFS_FS_XATTR 26#ifdef CONFIG_EROFS_FS_XATTR
33 return sbi->xattr_blkaddr + 27 return sbi->xattr_blkaddr +
@@ -37,19 +31,20 @@ xattrblock_addr(struct erofs_sb_info *sbi, unsigned xattr_id)
37#endif 31#endif
38} 32}
39 33
40static inline unsigned 34static inline unsigned int xattrblock_offset(struct erofs_sb_info *sbi,
41xattrblock_offset(struct erofs_sb_info *sbi, unsigned xattr_id) 35 unsigned int xattr_id)
42{ 36{
43 return (xattr_id * sizeof(__u32)) % EROFS_BLKSIZ; 37 return (xattr_id * sizeof(__u32)) % EROFS_BLKSIZ;
44} 38}
45 39
40#ifdef CONFIG_EROFS_FS_XATTR
46extern const struct xattr_handler erofs_xattr_user_handler; 41extern const struct xattr_handler erofs_xattr_user_handler;
47extern const struct xattr_handler erofs_xattr_trusted_handler; 42extern const struct xattr_handler erofs_xattr_trusted_handler;
48#ifdef CONFIG_EROFS_FS_SECURITY 43#ifdef CONFIG_EROFS_FS_SECURITY
49extern const struct xattr_handler erofs_xattr_security_handler; 44extern const struct xattr_handler erofs_xattr_security_handler;
50#endif 45#endif
51 46
52static inline const struct xattr_handler *erofs_xattr_handler(unsigned index) 47static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx)
53{ 48{
54static const struct xattr_handler *xattr_handler_map[] = { 49static const struct xattr_handler *xattr_handler_map[] = {
55 [EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler, 50 [EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler,
@@ -63,29 +58,29 @@ static const struct xattr_handler *xattr_handler_map[] = {
63 [EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler, 58 [EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler,
64#endif 59#endif
65}; 60};
66 return index && index < ARRAY_SIZE(xattr_handler_map) ? 61
67 xattr_handler_map[index] : NULL; 62 return idx && idx < ARRAY_SIZE(xattr_handler_map) ?
63 xattr_handler_map[idx] : NULL;
68} 64}
69 65
70#ifdef CONFIG_EROFS_FS_XATTR
71extern const struct xattr_handler *erofs_xattr_handlers[]; 66extern const struct xattr_handler *erofs_xattr_handlers[];
72 67
73int erofs_getxattr(struct inode *, int, const char *, void *, size_t); 68int erofs_getxattr(struct inode *, int, const char *, void *, size_t);
74ssize_t erofs_listxattr(struct dentry *, char *, size_t); 69ssize_t erofs_listxattr(struct dentry *, char *, size_t);
75#else 70#else
76static int __maybe_unused erofs_getxattr(struct inode *inode, int index, 71static inline int erofs_getxattr(struct inode *inode, int index,
77 const char *name, 72 const char *name, void *buffer,
78 void *buffer, size_t buffer_size) 73 size_t buffer_size)
79{ 74{
80 return -ENOTSUPP; 75 return -EOPNOTSUPP;
81} 76}
82 77
83static ssize_t __maybe_unused erofs_listxattr(struct dentry *dentry, 78static inline ssize_t erofs_listxattr(struct dentry *dentry,
84 char *buffer, size_t buffer_size) 79 char *buffer, size_t buffer_size)
85{ 80{
86 return -ENOTSUPP; 81 return -EOPNOTSUPP;
87} 82}
88#endif 83#endif /* !CONFIG_EROFS_FS_XATTR */
89 84
90#ifdef CONFIG_EROFS_FS_POSIX_ACL 85#ifdef CONFIG_EROFS_FS_POSIX_ACL
91struct posix_acl *erofs_get_acl(struct inode *inode, int type); 86struct posix_acl *erofs_get_acl(struct inode *inode, int type);
diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
new file mode 100644
index 000000000000..96e34c90f814
--- /dev/null
+++ b/fs/erofs/zdata.c
@@ -0,0 +1,1431 @@
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2018 HUAWEI, Inc.
4 * http://www.huawei.com/
5 * Created by Gao Xiang <gaoxiang25@huawei.com>
6 */
7#include "zdata.h"
8#include "compress.h"
9#include <linux/prefetch.h>
10
11#include <trace/events/erofs.h>
12
13/*
14 * a compressed_pages[] placeholder in order to avoid
15 * being filled with file pages for in-place decompression.
16 */
17#define PAGE_UNALLOCATED ((void *)0x5F0E4B1D)
18
19/* how to allocate cached pages for a pcluster */
20enum z_erofs_cache_alloctype {
21 DONTALLOC, /* don't allocate any cached pages */
22 DELAYEDALLOC, /* delayed allocation (at the time of submitting io) */
23};
24
25/*
26 * tagged pointer with 1-bit tag for all compressed pages
27 * tag 0 - the page is just found with an extra page reference
28 */
29typedef tagptr1_t compressed_page_t;
30
31#define tag_compressed_page_justfound(page) \
32 tagptr_fold(compressed_page_t, page, 1)
33
34static struct workqueue_struct *z_erofs_workqueue __read_mostly;
35static struct kmem_cache *pcluster_cachep __read_mostly;
36
37void z_erofs_exit_zip_subsystem(void)
38{
39 destroy_workqueue(z_erofs_workqueue);
40 kmem_cache_destroy(pcluster_cachep);
41}
42
43static inline int z_erofs_init_workqueue(void)
44{
45 const unsigned int onlinecpus = num_possible_cpus();
46 const unsigned int flags = WQ_UNBOUND | WQ_HIGHPRI | WQ_CPU_INTENSIVE;
47
48 /*
49 * no need to spawn too many threads, limiting threads could minimum
50 * scheduling overhead, perhaps per-CPU threads should be better?
51 */
52 z_erofs_workqueue = alloc_workqueue("erofs_unzipd", flags,
53 onlinecpus + onlinecpus / 4);
54 return z_erofs_workqueue ? 0 : -ENOMEM;
55}
56
57static void z_erofs_pcluster_init_once(void *ptr)
58{
59 struct z_erofs_pcluster *pcl = ptr;
60 struct z_erofs_collection *cl = z_erofs_primarycollection(pcl);
61 unsigned int i;
62
63 mutex_init(&cl->lock);
64 cl->nr_pages = 0;
65 cl->vcnt = 0;
66 for (i = 0; i < Z_EROFS_CLUSTER_MAX_PAGES; ++i)
67 pcl->compressed_pages[i] = NULL;
68}
69
70static void z_erofs_pcluster_init_always(struct z_erofs_pcluster *pcl)
71{
72 struct z_erofs_collection *cl = z_erofs_primarycollection(pcl);
73
74 atomic_set(&pcl->obj.refcount, 1);
75
76 DBG_BUGON(cl->nr_pages);
77 DBG_BUGON(cl->vcnt);
78}
79
80int __init z_erofs_init_zip_subsystem(void)
81{
82 pcluster_cachep = kmem_cache_create("erofs_compress",
83 Z_EROFS_WORKGROUP_SIZE, 0,
84 SLAB_RECLAIM_ACCOUNT,
85 z_erofs_pcluster_init_once);
86 if (pcluster_cachep) {
87 if (!z_erofs_init_workqueue())
88 return 0;
89
90 kmem_cache_destroy(pcluster_cachep);
91 }
92 return -ENOMEM;
93}
94
95enum z_erofs_collectmode {
96 COLLECT_SECONDARY,
97 COLLECT_PRIMARY,
98 /*
99 * The current collection was the tail of an exist chain, in addition
100 * that the previous processed chained collections are all decided to
101 * be hooked up to it.
102 * A new chain will be created for the remaining collections which are
103 * not processed yet, therefore different from COLLECT_PRIMARY_FOLLOWED,
104 * the next collection cannot reuse the whole page safely in
105 * the following scenario:
106 * ________________________________________________________________
107 * | tail (partial) page | head (partial) page |
108 * | (belongs to the next cl) | (belongs to the current cl) |
109 * |_______PRIMARY_FOLLOWED_______|________PRIMARY_HOOKED___________|
110 */
111 COLLECT_PRIMARY_HOOKED,
112 COLLECT_PRIMARY_FOLLOWED_NOINPLACE,
113 /*
114 * The current collection has been linked with the owned chain, and
115 * could also be linked with the remaining collections, which means
116 * if the processing page is the tail page of the collection, thus
117 * the current collection can safely use the whole page (since
118 * the previous collection is under control) for in-place I/O, as
119 * illustrated below:
120 * ________________________________________________________________
121 * | tail (partial) page | head (partial) page |
122 * | (of the current cl) | (of the previous collection) |
123 * | PRIMARY_FOLLOWED or | |
124 * |_____PRIMARY_HOOKED___|____________PRIMARY_FOLLOWED____________|
125 *
126 * [ (*) the above page can be used as inplace I/O. ]
127 */
128 COLLECT_PRIMARY_FOLLOWED,
129};
130
131struct z_erofs_collector {
132 struct z_erofs_pagevec_ctor vector;
133
134 struct z_erofs_pcluster *pcl, *tailpcl;
135 struct z_erofs_collection *cl;
136 struct page **compressedpages;
137 z_erofs_next_pcluster_t owned_head;
138
139 enum z_erofs_collectmode mode;
140};
141
142struct z_erofs_decompress_frontend {
143 struct inode *const inode;
144
145 struct z_erofs_collector clt;
146 struct erofs_map_blocks map;
147
148 /* used for applying cache strategy on the fly */
149 bool backmost;
150 erofs_off_t headoffset;
151};
152
153#define COLLECTOR_INIT() { \
154 .owned_head = Z_EROFS_PCLUSTER_TAIL, \
155 .mode = COLLECT_PRIMARY_FOLLOWED }
156
157#define DECOMPRESS_FRONTEND_INIT(__i) { \
158 .inode = __i, .clt = COLLECTOR_INIT(), \
159 .backmost = true, }
160
161static struct page *z_pagemap_global[Z_EROFS_VMAP_GLOBAL_PAGES];
162static DEFINE_MUTEX(z_pagemap_global_lock);
163
164static void preload_compressed_pages(struct z_erofs_collector *clt,
165 struct address_space *mc,
166 enum z_erofs_cache_alloctype type,
167 struct list_head *pagepool)
168{
169 const struct z_erofs_pcluster *pcl = clt->pcl;
170 const unsigned int clusterpages = BIT(pcl->clusterbits);
171 struct page **pages = clt->compressedpages;
172 pgoff_t index = pcl->obj.index + (pages - pcl->compressed_pages);
173 bool standalone = true;
174
175 if (clt->mode < COLLECT_PRIMARY_FOLLOWED)
176 return;
177
178 for (; pages < pcl->compressed_pages + clusterpages; ++pages) {
179 struct page *page;
180 compressed_page_t t;
181
182 /* the compressed page was loaded before */
183 if (READ_ONCE(*pages))
184 continue;
185
186 page = find_get_page(mc, index);
187
188 if (page) {
189 t = tag_compressed_page_justfound(page);
190 } else if (type == DELAYEDALLOC) {
191 t = tagptr_init(compressed_page_t, PAGE_UNALLOCATED);
192 } else { /* DONTALLOC */
193 if (standalone)
194 clt->compressedpages = pages;
195 standalone = false;
196 continue;
197 }
198
199 if (!cmpxchg_relaxed(pages, NULL, tagptr_cast_ptr(t)))
200 continue;
201
202 if (page)
203 put_page(page);
204 }
205
206 if (standalone) /* downgrade to PRIMARY_FOLLOWED_NOINPLACE */
207 clt->mode = COLLECT_PRIMARY_FOLLOWED_NOINPLACE;
208}
209
210/* called by erofs_shrinker to get rid of all compressed_pages */
211int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
212 struct erofs_workgroup *grp)
213{
214 struct z_erofs_pcluster *const pcl =
215 container_of(grp, struct z_erofs_pcluster, obj);
216 struct address_space *const mapping = MNGD_MAPPING(sbi);
217 const unsigned int clusterpages = BIT(pcl->clusterbits);
218 int i;
219
220 /*
221 * refcount of workgroup is now freezed as 1,
222 * therefore no need to worry about available decompression users.
223 */
224 for (i = 0; i < clusterpages; ++i) {
225 struct page *page = pcl->compressed_pages[i];
226
227 if (!page)
228 continue;
229
230 /* block other users from reclaiming or migrating the page */
231 if (!trylock_page(page))
232 return -EBUSY;
233
234 if (page->mapping != mapping)
235 continue;
236
237 /* barrier is implied in the following 'unlock_page' */
238 WRITE_ONCE(pcl->compressed_pages[i], NULL);
239 set_page_private(page, 0);
240 ClearPagePrivate(page);
241
242 unlock_page(page);
243 put_page(page);
244 }
245 return 0;
246}
247
248int erofs_try_to_free_cached_page(struct address_space *mapping,
249 struct page *page)
250{
251 struct z_erofs_pcluster *const pcl = (void *)page_private(page);
252 const unsigned int clusterpages = BIT(pcl->clusterbits);
253 int ret = 0; /* 0 - busy */
254
255 if (erofs_workgroup_try_to_freeze(&pcl->obj, 1)) {
256 unsigned int i;
257
258 for (i = 0; i < clusterpages; ++i) {
259 if (pcl->compressed_pages[i] == page) {
260 WRITE_ONCE(pcl->compressed_pages[i], NULL);
261 ret = 1;
262 break;
263 }
264 }
265 erofs_workgroup_unfreeze(&pcl->obj, 1);
266
267 if (ret) {
268 ClearPagePrivate(page);
269 put_page(page);
270 }
271 }
272 return ret;
273}
274
275/* page_type must be Z_EROFS_PAGE_TYPE_EXCLUSIVE */
276static inline bool z_erofs_try_inplace_io(struct z_erofs_collector *clt,
277 struct page *page)
278{
279 struct z_erofs_pcluster *const pcl = clt->pcl;
280 const unsigned int clusterpages = BIT(pcl->clusterbits);
281
282 while (clt->compressedpages < pcl->compressed_pages + clusterpages) {
283 if (!cmpxchg(clt->compressedpages++, NULL, page))
284 return true;
285 }
286 return false;
287}
288
289/* callers must be with collection lock held */
290static int z_erofs_attach_page(struct z_erofs_collector *clt,
291 struct page *page,
292 enum z_erofs_page_type type)
293{
294 int ret;
295 bool occupied;
296
297 /* give priority for inplaceio */
298 if (clt->mode >= COLLECT_PRIMARY &&
299 type == Z_EROFS_PAGE_TYPE_EXCLUSIVE &&
300 z_erofs_try_inplace_io(clt, page))
301 return 0;
302
303 ret = z_erofs_pagevec_enqueue(&clt->vector,
304 page, type, &occupied);
305 clt->cl->vcnt += (unsigned int)ret;
306
307 return ret ? 0 : -EAGAIN;
308}
309
310static enum z_erofs_collectmode
311try_to_claim_pcluster(struct z_erofs_pcluster *pcl,
312 z_erofs_next_pcluster_t *owned_head)
313{
314 /* let's claim these following types of pclusters */
315retry:
316 if (pcl->next == Z_EROFS_PCLUSTER_NIL) {
317 /* type 1, nil pcluster */
318 if (cmpxchg(&pcl->next, Z_EROFS_PCLUSTER_NIL,
319 *owned_head) != Z_EROFS_PCLUSTER_NIL)
320 goto retry;
321
322 *owned_head = &pcl->next;
323 /* lucky, I am the followee :) */
324 return COLLECT_PRIMARY_FOLLOWED;
325 } else if (pcl->next == Z_EROFS_PCLUSTER_TAIL) {
326 /*
327 * type 2, link to the end of a existing open chain,
328 * be careful that its submission itself is governed
329 * by the original owned chain.
330 */
331 if (cmpxchg(&pcl->next, Z_EROFS_PCLUSTER_TAIL,
332 *owned_head) != Z_EROFS_PCLUSTER_TAIL)
333 goto retry;
334 *owned_head = Z_EROFS_PCLUSTER_TAIL;
335 return COLLECT_PRIMARY_HOOKED;
336 }
337 return COLLECT_PRIMARY; /* :( better luck next time */
338}
339
340static struct z_erofs_collection *cllookup(struct z_erofs_collector *clt,
341 struct inode *inode,
342 struct erofs_map_blocks *map)
343{
344 struct erofs_workgroup *grp;
345 struct z_erofs_pcluster *pcl;
346 struct z_erofs_collection *cl;
347 unsigned int length;
348 bool tag;
349
350 grp = erofs_find_workgroup(inode->i_sb, map->m_pa >> PAGE_SHIFT, &tag);
351 if (!grp)
352 return NULL;
353
354 pcl = container_of(grp, struct z_erofs_pcluster, obj);
355 if (clt->owned_head == &pcl->next || pcl == clt->tailpcl) {
356 DBG_BUGON(1);
357 erofs_workgroup_put(grp);
358 return ERR_PTR(-EFSCORRUPTED);
359 }
360
361 cl = z_erofs_primarycollection(pcl);
362 if (cl->pageofs != (map->m_la & ~PAGE_MASK)) {
363 DBG_BUGON(1);
364 erofs_workgroup_put(grp);
365 return ERR_PTR(-EFSCORRUPTED);
366 }
367
368 length = READ_ONCE(pcl->length);
369 if (length & Z_EROFS_PCLUSTER_FULL_LENGTH) {
370 if ((map->m_llen << Z_EROFS_PCLUSTER_LENGTH_BIT) > length) {
371 DBG_BUGON(1);
372 erofs_workgroup_put(grp);
373 return ERR_PTR(-EFSCORRUPTED);
374 }
375 } else {
376 unsigned int llen = map->m_llen << Z_EROFS_PCLUSTER_LENGTH_BIT;
377
378 if (map->m_flags & EROFS_MAP_FULL_MAPPED)
379 llen |= Z_EROFS_PCLUSTER_FULL_LENGTH;
380
381 while (llen > length &&
382 length != cmpxchg_relaxed(&pcl->length, length, llen)) {
383 cpu_relax();
384 length = READ_ONCE(pcl->length);
385 }
386 }
387 mutex_lock(&cl->lock);
388 /* used to check tail merging loop due to corrupted images */
389 if (clt->owned_head == Z_EROFS_PCLUSTER_TAIL)
390 clt->tailpcl = pcl;
391 clt->mode = try_to_claim_pcluster(pcl, &clt->owned_head);
392 /* clean tailpcl if the current owned_head is Z_EROFS_PCLUSTER_TAIL */
393 if (clt->owned_head == Z_EROFS_PCLUSTER_TAIL)
394 clt->tailpcl = NULL;
395 clt->pcl = pcl;
396 clt->cl = cl;
397 return cl;
398}
399
400static struct z_erofs_collection *clregister(struct z_erofs_collector *clt,
401 struct inode *inode,
402 struct erofs_map_blocks *map)
403{
404 struct z_erofs_pcluster *pcl;
405 struct z_erofs_collection *cl;
406 int err;
407
408 /* no available workgroup, let's allocate one */
409 pcl = kmem_cache_alloc(pcluster_cachep, GFP_NOFS);
410 if (!pcl)
411 return ERR_PTR(-ENOMEM);
412
413 z_erofs_pcluster_init_always(pcl);
414 pcl->obj.index = map->m_pa >> PAGE_SHIFT;
415
416 pcl->length = (map->m_llen << Z_EROFS_PCLUSTER_LENGTH_BIT) |
417 (map->m_flags & EROFS_MAP_FULL_MAPPED ?
418 Z_EROFS_PCLUSTER_FULL_LENGTH : 0);
419
420 if (map->m_flags & EROFS_MAP_ZIPPED)
421 pcl->algorithmformat = Z_EROFS_COMPRESSION_LZ4;
422 else
423 pcl->algorithmformat = Z_EROFS_COMPRESSION_SHIFTED;
424
425 pcl->clusterbits = EROFS_I(inode)->z_physical_clusterbits[0];
426 pcl->clusterbits -= PAGE_SHIFT;
427
428 /* new pclusters should be claimed as type 1, primary and followed */
429 pcl->next = clt->owned_head;
430 clt->mode = COLLECT_PRIMARY_FOLLOWED;
431
432 cl = z_erofs_primarycollection(pcl);
433 cl->pageofs = map->m_la & ~PAGE_MASK;
434
435 /*
436 * lock all primary followed works before visible to others
437 * and mutex_trylock *never* fails for a new pcluster.
438 */
439 mutex_trylock(&cl->lock);
440
441 err = erofs_register_workgroup(inode->i_sb, &pcl->obj, 0);
442 if (err) {
443 mutex_unlock(&cl->lock);
444 kmem_cache_free(pcluster_cachep, pcl);
445 return ERR_PTR(-EAGAIN);
446 }
447 /* used to check tail merging loop due to corrupted images */
448 if (clt->owned_head == Z_EROFS_PCLUSTER_TAIL)
449 clt->tailpcl = pcl;
450 clt->owned_head = &pcl->next;
451 clt->pcl = pcl;
452 clt->cl = cl;
453 return cl;
454}
455
456static int z_erofs_collector_begin(struct z_erofs_collector *clt,
457 struct inode *inode,
458 struct erofs_map_blocks *map)
459{
460 struct z_erofs_collection *cl;
461
462 DBG_BUGON(clt->cl);
463
464 /* must be Z_EROFS_PCLUSTER_TAIL or pointed to previous collection */
465 DBG_BUGON(clt->owned_head == Z_EROFS_PCLUSTER_NIL);
466 DBG_BUGON(clt->owned_head == Z_EROFS_PCLUSTER_TAIL_CLOSED);
467
468 if (!PAGE_ALIGNED(map->m_pa)) {
469 DBG_BUGON(1);
470 return -EINVAL;
471 }
472
473repeat:
474 cl = cllookup(clt, inode, map);
475 if (!cl) {
476 cl = clregister(clt, inode, map);
477
478 if (cl == ERR_PTR(-EAGAIN))
479 goto repeat;
480 }
481
482 if (IS_ERR(cl))
483 return PTR_ERR(cl);
484
485 z_erofs_pagevec_ctor_init(&clt->vector, Z_EROFS_NR_INLINE_PAGEVECS,
486 cl->pagevec, cl->vcnt);
487
488 clt->compressedpages = clt->pcl->compressed_pages;
489 if (clt->mode <= COLLECT_PRIMARY) /* cannot do in-place I/O */
490 clt->compressedpages += Z_EROFS_CLUSTER_MAX_PAGES;
491 return 0;
492}
493
494/*
495 * keep in mind that no referenced pclusters will be freed
496 * only after a RCU grace period.
497 */
498static void z_erofs_rcu_callback(struct rcu_head *head)
499{
500 struct z_erofs_collection *const cl =
501 container_of(head, struct z_erofs_collection, rcu);
502
503 kmem_cache_free(pcluster_cachep,
504 container_of(cl, struct z_erofs_pcluster,
505 primary_collection));
506}
507
508void erofs_workgroup_free_rcu(struct erofs_workgroup *grp)
509{
510 struct z_erofs_pcluster *const pcl =
511 container_of(grp, struct z_erofs_pcluster, obj);
512 struct z_erofs_collection *const cl = z_erofs_primarycollection(pcl);
513
514 call_rcu(&cl->rcu, z_erofs_rcu_callback);
515}
516
517static void z_erofs_collection_put(struct z_erofs_collection *cl)
518{
519 struct z_erofs_pcluster *const pcl =
520 container_of(cl, struct z_erofs_pcluster, primary_collection);
521
522 erofs_workgroup_put(&pcl->obj);
523}
524
525static bool z_erofs_collector_end(struct z_erofs_collector *clt)
526{
527 struct z_erofs_collection *cl = clt->cl;
528
529 if (!cl)
530 return false;
531
532 z_erofs_pagevec_ctor_exit(&clt->vector, false);
533 mutex_unlock(&cl->lock);
534
535 /*
536 * if all pending pages are added, don't hold its reference
537 * any longer if the pcluster isn't hosted by ourselves.
538 */
539 if (clt->mode < COLLECT_PRIMARY_FOLLOWED_NOINPLACE)
540 z_erofs_collection_put(cl);
541
542 clt->cl = NULL;
543 return true;
544}
545
546static inline struct page *__stagingpage_alloc(struct list_head *pagepool,
547 gfp_t gfp)
548{
549 struct page *page = erofs_allocpage(pagepool, gfp, true);
550
551 page->mapping = Z_EROFS_MAPPING_STAGING;
552 return page;
553}
554
555static bool should_alloc_managed_pages(struct z_erofs_decompress_frontend *fe,
556 unsigned int cachestrategy,
557 erofs_off_t la)
558{
559 if (cachestrategy <= EROFS_ZIP_CACHE_DISABLED)
560 return false;
561
562 if (fe->backmost)
563 return true;
564
565 return cachestrategy >= EROFS_ZIP_CACHE_READAROUND &&
566 la < fe->headoffset;
567}
568
569static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
570 struct page *page,
571 struct list_head *pagepool)
572{
573 struct inode *const inode = fe->inode;
574 struct erofs_sb_info *const sbi __maybe_unused = EROFS_I_SB(inode);
575 struct erofs_map_blocks *const map = &fe->map;
576 struct z_erofs_collector *const clt = &fe->clt;
577 const loff_t offset = page_offset(page);
578 bool tight = (clt->mode >= COLLECT_PRIMARY_HOOKED);
579
580 enum z_erofs_cache_alloctype cache_strategy;
581 enum z_erofs_page_type page_type;
582 unsigned int cur, end, spiltted, index;
583 int err = 0;
584
585 /* register locked file pages as online pages in pack */
586 z_erofs_onlinepage_init(page);
587
588 spiltted = 0;
589 end = PAGE_SIZE;
590repeat:
591 cur = end - 1;
592
593 /* lucky, within the range of the current map_blocks */
594 if (offset + cur >= map->m_la &&
595 offset + cur < map->m_la + map->m_llen) {
596 /* didn't get a valid collection previously (very rare) */
597 if (!clt->cl)
598 goto restart_now;
599 goto hitted;
600 }
601
602 /* go ahead the next map_blocks */
603 erofs_dbg("%s: [out-of-range] pos %llu", __func__, offset + cur);
604
605 if (z_erofs_collector_end(clt))
606 fe->backmost = false;
607
608 map->m_la = offset + cur;
609 map->m_llen = 0;
610 err = z_erofs_map_blocks_iter(inode, map, 0);
611 if (err)
612 goto err_out;
613
614restart_now:
615 if (!(map->m_flags & EROFS_MAP_MAPPED))
616 goto hitted;
617
618 err = z_erofs_collector_begin(clt, inode, map);
619 if (err)
620 goto err_out;
621
622 /* preload all compressed pages (maybe downgrade role if necessary) */
623 if (should_alloc_managed_pages(fe, sbi->cache_strategy, map->m_la))
624 cache_strategy = DELAYEDALLOC;
625 else
626 cache_strategy = DONTALLOC;
627
628 preload_compressed_pages(clt, MNGD_MAPPING(sbi),
629 cache_strategy, pagepool);
630
631 tight &= (clt->mode >= COLLECT_PRIMARY_HOOKED);
632hitted:
633 cur = end - min_t(unsigned int, offset + end - map->m_la, end);
634 if (!(map->m_flags & EROFS_MAP_MAPPED)) {
635 zero_user_segment(page, cur, end);
636 goto next_part;
637 }
638
639 /* let's derive page type */
640 page_type = cur ? Z_EROFS_VLE_PAGE_TYPE_HEAD :
641 (!spiltted ? Z_EROFS_PAGE_TYPE_EXCLUSIVE :
642 (tight ? Z_EROFS_PAGE_TYPE_EXCLUSIVE :
643 Z_EROFS_VLE_PAGE_TYPE_TAIL_SHARED));
644
645 if (cur)
646 tight &= (clt->mode >= COLLECT_PRIMARY_FOLLOWED);
647
648retry:
649 err = z_erofs_attach_page(clt, page, page_type);
650 /* should allocate an additional staging page for pagevec */
651 if (err == -EAGAIN) {
652 struct page *const newpage =
653 __stagingpage_alloc(pagepool, GFP_NOFS);
654
655 err = z_erofs_attach_page(clt, newpage,
656 Z_EROFS_PAGE_TYPE_EXCLUSIVE);
657 if (!err)
658 goto retry;
659 }
660
661 if (err)
662 goto err_out;
663
664 index = page->index - (map->m_la >> PAGE_SHIFT);
665
666 z_erofs_onlinepage_fixup(page, index, true);
667
668 /* bump up the number of spiltted parts of a page */
669 ++spiltted;
670 /* also update nr_pages */
671 clt->cl->nr_pages = max_t(pgoff_t, clt->cl->nr_pages, index + 1);
672next_part:
673 /* can be used for verification */
674 map->m_llen = offset + cur - map->m_la;
675
676 end = cur;
677 if (end > 0)
678 goto repeat;
679
680out:
681 z_erofs_onlinepage_endio(page);
682
683 erofs_dbg("%s, finish page: %pK spiltted: %u map->m_llen %llu",
684 __func__, page, spiltted, map->m_llen);
685 return err;
686
687 /* if some error occurred while processing this page */
688err_out:
689 SetPageError(page);
690 goto out;
691}
692
693static void z_erofs_vle_unzip_kickoff(void *ptr, int bios)
694{
695 tagptr1_t t = tagptr_init(tagptr1_t, ptr);
696 struct z_erofs_unzip_io *io = tagptr_unfold_ptr(t);
697 bool background = tagptr_unfold_tags(t);
698
699 if (!background) {
700 unsigned long flags;
701
702 spin_lock_irqsave(&io->u.wait.lock, flags);
703 if (!atomic_add_return(bios, &io->pending_bios))
704 wake_up_locked(&io->u.wait);
705 spin_unlock_irqrestore(&io->u.wait.lock, flags);
706 return;
707 }
708
709 if (!atomic_add_return(bios, &io->pending_bios))
710 queue_work(z_erofs_workqueue, &io->u.work);
711}
712
713static inline void z_erofs_vle_read_endio(struct bio *bio)
714{
715 struct erofs_sb_info *sbi = NULL;
716 blk_status_t err = bio->bi_status;
717 struct bio_vec *bvec;
718 struct bvec_iter_all iter_all;
719
720 bio_for_each_segment_all(bvec, bio, iter_all) {
721 struct page *page = bvec->bv_page;
722 bool cachemngd = false;
723
724 DBG_BUGON(PageUptodate(page));
725 DBG_BUGON(!page->mapping);
726
727 if (!sbi && !z_erofs_page_is_staging(page))
728 sbi = EROFS_SB(page->mapping->host->i_sb);
729
730 /* sbi should already be gotten if the page is managed */
731 if (sbi)
732 cachemngd = erofs_page_is_managed(sbi, page);
733
734 if (err)
735 SetPageError(page);
736 else if (cachemngd)
737 SetPageUptodate(page);
738
739 if (cachemngd)
740 unlock_page(page);
741 }
742
743 z_erofs_vle_unzip_kickoff(bio->bi_private, -1);
744 bio_put(bio);
745}
746
747static int z_erofs_decompress_pcluster(struct super_block *sb,
748 struct z_erofs_pcluster *pcl,
749 struct list_head *pagepool)
750{
751 struct erofs_sb_info *const sbi = EROFS_SB(sb);
752 const unsigned int clusterpages = BIT(pcl->clusterbits);
753 struct z_erofs_pagevec_ctor ctor;
754 unsigned int i, outputsize, llen, nr_pages;
755 struct page *pages_onstack[Z_EROFS_VMAP_ONSTACK_PAGES];
756 struct page **pages, **compressed_pages, *page;
757
758 enum z_erofs_page_type page_type;
759 bool overlapped, partial;
760 struct z_erofs_collection *cl;
761 int err;
762
763 might_sleep();
764 cl = z_erofs_primarycollection(pcl);
765 DBG_BUGON(!READ_ONCE(cl->nr_pages));
766
767 mutex_lock(&cl->lock);
768 nr_pages = cl->nr_pages;
769
770 if (nr_pages <= Z_EROFS_VMAP_ONSTACK_PAGES) {
771 pages = pages_onstack;
772 } else if (nr_pages <= Z_EROFS_VMAP_GLOBAL_PAGES &&
773 mutex_trylock(&z_pagemap_global_lock)) {
774 pages = z_pagemap_global;
775 } else {
776 gfp_t gfp_flags = GFP_KERNEL;
777
778 if (nr_pages > Z_EROFS_VMAP_GLOBAL_PAGES)
779 gfp_flags |= __GFP_NOFAIL;
780
781 pages = kvmalloc_array(nr_pages, sizeof(struct page *),
782 gfp_flags);
783
784 /* fallback to global pagemap for the lowmem scenario */
785 if (!pages) {
786 mutex_lock(&z_pagemap_global_lock);
787 pages = z_pagemap_global;
788 }
789 }
790
791 for (i = 0; i < nr_pages; ++i)
792 pages[i] = NULL;
793
794 err = 0;
795 z_erofs_pagevec_ctor_init(&ctor, Z_EROFS_NR_INLINE_PAGEVECS,
796 cl->pagevec, 0);
797
798 for (i = 0; i < cl->vcnt; ++i) {
799 unsigned int pagenr;
800
801 page = z_erofs_pagevec_dequeue(&ctor, &page_type);
802
803 /* all pages in pagevec ought to be valid */
804 DBG_BUGON(!page);
805 DBG_BUGON(!page->mapping);
806
807 if (z_erofs_put_stagingpage(pagepool, page))
808 continue;
809
810 if (page_type == Z_EROFS_VLE_PAGE_TYPE_HEAD)
811 pagenr = 0;
812 else
813 pagenr = z_erofs_onlinepage_index(page);
814
815 DBG_BUGON(pagenr >= nr_pages);
816
817 /*
818 * currently EROFS doesn't support multiref(dedup),
819 * so here erroring out one multiref page.
820 */
821 if (pages[pagenr]) {
822 DBG_BUGON(1);
823 SetPageError(pages[pagenr]);
824 z_erofs_onlinepage_endio(pages[pagenr]);
825 err = -EFSCORRUPTED;
826 }
827 pages[pagenr] = page;
828 }
829 z_erofs_pagevec_ctor_exit(&ctor, true);
830
831 overlapped = false;
832 compressed_pages = pcl->compressed_pages;
833
834 for (i = 0; i < clusterpages; ++i) {
835 unsigned int pagenr;
836
837 page = compressed_pages[i];
838
839 /* all compressed pages ought to be valid */
840 DBG_BUGON(!page);
841 DBG_BUGON(!page->mapping);
842
843 if (!z_erofs_page_is_staging(page)) {
844 if (erofs_page_is_managed(sbi, page)) {
845 if (!PageUptodate(page))
846 err = -EIO;
847 continue;
848 }
849
850 /*
851 * only if non-head page can be selected
852 * for inplace decompression
853 */
854 pagenr = z_erofs_onlinepage_index(page);
855
856 DBG_BUGON(pagenr >= nr_pages);
857 if (pages[pagenr]) {
858 DBG_BUGON(1);
859 SetPageError(pages[pagenr]);
860 z_erofs_onlinepage_endio(pages[pagenr]);
861 err = -EFSCORRUPTED;
862 }
863 pages[pagenr] = page;
864
865 overlapped = true;
866 }
867
868 /* PG_error needs checking for inplaced and staging pages */
869 if (PageError(page)) {
870 DBG_BUGON(PageUptodate(page));
871 err = -EIO;
872 }
873 }
874
875 if (err)
876 goto out;
877
878 llen = pcl->length >> Z_EROFS_PCLUSTER_LENGTH_BIT;
879 if (nr_pages << PAGE_SHIFT >= cl->pageofs + llen) {
880 outputsize = llen;
881 partial = !(pcl->length & Z_EROFS_PCLUSTER_FULL_LENGTH);
882 } else {
883 outputsize = (nr_pages << PAGE_SHIFT) - cl->pageofs;
884 partial = true;
885 }
886
887 err = z_erofs_decompress(&(struct z_erofs_decompress_req) {
888 .sb = sb,
889 .in = compressed_pages,
890 .out = pages,
891 .pageofs_out = cl->pageofs,
892 .inputsize = PAGE_SIZE,
893 .outputsize = outputsize,
894 .alg = pcl->algorithmformat,
895 .inplace_io = overlapped,
896 .partial_decoding = partial
897 }, pagepool);
898
899out:
900 /* must handle all compressed pages before endding pages */
901 for (i = 0; i < clusterpages; ++i) {
902 page = compressed_pages[i];
903
904 if (erofs_page_is_managed(sbi, page))
905 continue;
906
907 /* recycle all individual staging pages */
908 (void)z_erofs_put_stagingpage(pagepool, page);
909
910 WRITE_ONCE(compressed_pages[i], NULL);
911 }
912
913 for (i = 0; i < nr_pages; ++i) {
914 page = pages[i];
915 if (!page)
916 continue;
917
918 DBG_BUGON(!page->mapping);
919
920 /* recycle all individual staging pages */
921 if (z_erofs_put_stagingpage(pagepool, page))
922 continue;
923
924 if (err < 0)
925 SetPageError(page);
926
927 z_erofs_onlinepage_endio(page);
928 }
929
930 if (pages == z_pagemap_global)
931 mutex_unlock(&z_pagemap_global_lock);
932 else if (pages != pages_onstack)
933 kvfree(pages);
934
935 cl->nr_pages = 0;
936 cl->vcnt = 0;
937
938 /* all cl locks MUST be taken before the following line */
939 WRITE_ONCE(pcl->next, Z_EROFS_PCLUSTER_NIL);
940
941 /* all cl locks SHOULD be released right now */
942 mutex_unlock(&cl->lock);
943
944 z_erofs_collection_put(cl);
945 return err;
946}
947
948static void z_erofs_vle_unzip_all(struct super_block *sb,
949 struct z_erofs_unzip_io *io,
950 struct list_head *pagepool)
951{
952 z_erofs_next_pcluster_t owned = io->head;
953
954 while (owned != Z_EROFS_PCLUSTER_TAIL_CLOSED) {
955 struct z_erofs_pcluster *pcl;
956
957 /* no possible that 'owned' equals Z_EROFS_WORK_TPTR_TAIL */
958 DBG_BUGON(owned == Z_EROFS_PCLUSTER_TAIL);
959
960 /* no possible that 'owned' equals NULL */
961 DBG_BUGON(owned == Z_EROFS_PCLUSTER_NIL);
962
963 pcl = container_of(owned, struct z_erofs_pcluster, next);
964 owned = READ_ONCE(pcl->next);
965
966 z_erofs_decompress_pcluster(sb, pcl, pagepool);
967 }
968}
969
970static void z_erofs_vle_unzip_wq(struct work_struct *work)
971{
972 struct z_erofs_unzip_io_sb *iosb =
973 container_of(work, struct z_erofs_unzip_io_sb, io.u.work);
974 LIST_HEAD(pagepool);
975
976 DBG_BUGON(iosb->io.head == Z_EROFS_PCLUSTER_TAIL_CLOSED);
977 z_erofs_vle_unzip_all(iosb->sb, &iosb->io, &pagepool);
978
979 put_pages_list(&pagepool);
980 kvfree(iosb);
981}
982
983static struct page *pickup_page_for_submission(struct z_erofs_pcluster *pcl,
984 unsigned int nr,
985 struct list_head *pagepool,
986 struct address_space *mc,
987 gfp_t gfp)
988{
989 /* determined at compile time to avoid too many #ifdefs */
990 const bool nocache = __builtin_constant_p(mc) ? !mc : false;
991 const pgoff_t index = pcl->obj.index;
992 bool tocache = false;
993
994 struct address_space *mapping;
995 struct page *oldpage, *page;
996
997 compressed_page_t t;
998 int justfound;
999
1000repeat:
1001 page = READ_ONCE(pcl->compressed_pages[nr]);
1002 oldpage = page;
1003
1004 if (!page)
1005 goto out_allocpage;
1006
1007 /*
1008 * the cached page has not been allocated and
1009 * an placeholder is out there, prepare it now.
1010 */
1011 if (!nocache && page == PAGE_UNALLOCATED) {
1012 tocache = true;
1013 goto out_allocpage;
1014 }
1015
1016 /* process the target tagged pointer */
1017 t = tagptr_init(compressed_page_t, page);
1018 justfound = tagptr_unfold_tags(t);
1019 page = tagptr_unfold_ptr(t);
1020
1021 mapping = READ_ONCE(page->mapping);
1022
1023 /*
1024 * if managed cache is disabled, it's no way to
1025 * get such a cached-like page.
1026 */
1027 if (nocache) {
1028 /* if managed cache is disabled, it is impossible `justfound' */
1029 DBG_BUGON(justfound);
1030
1031 /* and it should be locked, not uptodate, and not truncated */
1032 DBG_BUGON(!PageLocked(page));
1033 DBG_BUGON(PageUptodate(page));
1034 DBG_BUGON(!mapping);
1035 goto out;
1036 }
1037
1038 /*
1039 * unmanaged (file) pages are all locked solidly,
1040 * therefore it is impossible for `mapping' to be NULL.
1041 */
1042 if (mapping && mapping != mc)
1043 /* ought to be unmanaged pages */
1044 goto out;
1045
1046 lock_page(page);
1047
1048 /* only true if page reclaim goes wrong, should never happen */
1049 DBG_BUGON(justfound && PagePrivate(page));
1050
1051 /* the page is still in manage cache */
1052 if (page->mapping == mc) {
1053 WRITE_ONCE(pcl->compressed_pages[nr], page);
1054
1055 ClearPageError(page);
1056 if (!PagePrivate(page)) {
1057 /*
1058 * impossible to be !PagePrivate(page) for
1059 * the current restriction as well if
1060 * the page is already in compressed_pages[].
1061 */
1062 DBG_BUGON(!justfound);
1063
1064 justfound = 0;
1065 set_page_private(page, (unsigned long)pcl);
1066 SetPagePrivate(page);
1067 }
1068
1069 /* no need to submit io if it is already up-to-date */
1070 if (PageUptodate(page)) {
1071 unlock_page(page);
1072 page = NULL;
1073 }
1074 goto out;
1075 }
1076
1077 /*
1078 * the managed page has been truncated, it's unsafe to
1079 * reuse this one, let's allocate a new cache-managed page.
1080 */
1081 DBG_BUGON(page->mapping);
1082 DBG_BUGON(!justfound);
1083
1084 tocache = true;
1085 unlock_page(page);
1086 put_page(page);
1087out_allocpage:
1088 page = __stagingpage_alloc(pagepool, gfp);
1089 if (oldpage != cmpxchg(&pcl->compressed_pages[nr], oldpage, page)) {
1090 list_add(&page->lru, pagepool);
1091 cpu_relax();
1092 goto repeat;
1093 }
1094 if (nocache || !tocache)
1095 goto out;
1096 if (add_to_page_cache_lru(page, mc, index + nr, gfp)) {
1097 page->mapping = Z_EROFS_MAPPING_STAGING;
1098 goto out;
1099 }
1100
1101 set_page_private(page, (unsigned long)pcl);
1102 SetPagePrivate(page);
1103out: /* the only exit (for tracing and debugging) */
1104 return page;
1105}
1106
1107static struct z_erofs_unzip_io *jobqueue_init(struct super_block *sb,
1108 struct z_erofs_unzip_io *io,
1109 bool foreground)
1110{
1111 struct z_erofs_unzip_io_sb *iosb;
1112
1113 if (foreground) {
1114 /* waitqueue available for foreground io */
1115 DBG_BUGON(!io);
1116
1117 init_waitqueue_head(&io->u.wait);
1118 atomic_set(&io->pending_bios, 0);
1119 goto out;
1120 }
1121
1122 iosb = kvzalloc(sizeof(*iosb), GFP_KERNEL | __GFP_NOFAIL);
1123 DBG_BUGON(!iosb);
1124
1125 /* initialize fields in the allocated descriptor */
1126 io = &iosb->io;
1127 iosb->sb = sb;
1128 INIT_WORK(&io->u.work, z_erofs_vle_unzip_wq);
1129out:
1130 io->head = Z_EROFS_PCLUSTER_TAIL_CLOSED;
1131 return io;
1132}
1133
1134/* define decompression jobqueue types */
1135enum {
1136 JQ_BYPASS,
1137 JQ_SUBMIT,
1138 NR_JOBQUEUES,
1139};
1140
1141static void *jobqueueset_init(struct super_block *sb,
1142 z_erofs_next_pcluster_t qtail[],
1143 struct z_erofs_unzip_io *q[],
1144 struct z_erofs_unzip_io *fgq,
1145 bool forcefg)
1146{
1147 /*
1148 * if managed cache is enabled, bypass jobqueue is needed,
1149 * no need to read from device for all pclusters in this queue.
1150 */
1151 q[JQ_BYPASS] = jobqueue_init(sb, fgq + JQ_BYPASS, true);
1152 qtail[JQ_BYPASS] = &q[JQ_BYPASS]->head;
1153
1154 q[JQ_SUBMIT] = jobqueue_init(sb, fgq + JQ_SUBMIT, forcefg);
1155 qtail[JQ_SUBMIT] = &q[JQ_SUBMIT]->head;
1156
1157 return tagptr_cast_ptr(tagptr_fold(tagptr1_t, q[JQ_SUBMIT], !forcefg));
1158}
1159
1160static void move_to_bypass_jobqueue(struct z_erofs_pcluster *pcl,
1161 z_erofs_next_pcluster_t qtail[],
1162 z_erofs_next_pcluster_t owned_head)
1163{
1164 z_erofs_next_pcluster_t *const submit_qtail = qtail[JQ_SUBMIT];
1165 z_erofs_next_pcluster_t *const bypass_qtail = qtail[JQ_BYPASS];
1166
1167 DBG_BUGON(owned_head == Z_EROFS_PCLUSTER_TAIL_CLOSED);
1168 if (owned_head == Z_EROFS_PCLUSTER_TAIL)
1169 owned_head = Z_EROFS_PCLUSTER_TAIL_CLOSED;
1170
1171 WRITE_ONCE(pcl->next, Z_EROFS_PCLUSTER_TAIL_CLOSED);
1172
1173 WRITE_ONCE(*submit_qtail, owned_head);
1174 WRITE_ONCE(*bypass_qtail, &pcl->next);
1175
1176 qtail[JQ_BYPASS] = &pcl->next;
1177}
1178
1179static bool postsubmit_is_all_bypassed(struct z_erofs_unzip_io *q[],
1180 unsigned int nr_bios,
1181 bool force_fg)
1182{
1183 /*
1184 * although background is preferred, no one is pending for submission.
1185 * don't issue workqueue for decompression but drop it directly instead.
1186 */
1187 if (force_fg || nr_bios)
1188 return false;
1189
1190 kvfree(container_of(q[JQ_SUBMIT], struct z_erofs_unzip_io_sb, io));
1191 return true;
1192}
1193
1194static bool z_erofs_vle_submit_all(struct super_block *sb,
1195 z_erofs_next_pcluster_t owned_head,
1196 struct list_head *pagepool,
1197 struct z_erofs_unzip_io *fgq,
1198 bool force_fg)
1199{
1200 struct erofs_sb_info *const sbi __maybe_unused = EROFS_SB(sb);
1201 z_erofs_next_pcluster_t qtail[NR_JOBQUEUES];
1202 struct z_erofs_unzip_io *q[NR_JOBQUEUES];
1203 struct bio *bio;
1204 void *bi_private;
1205 /* since bio will be NULL, no need to initialize last_index */
1206 pgoff_t uninitialized_var(last_index);
1207 bool force_submit = false;
1208 unsigned int nr_bios;
1209
1210 if (owned_head == Z_EROFS_PCLUSTER_TAIL)
1211 return false;
1212
1213 force_submit = false;
1214 bio = NULL;
1215 nr_bios = 0;
1216 bi_private = jobqueueset_init(sb, qtail, q, fgq, force_fg);
1217
1218 /* by default, all need io submission */
1219 q[JQ_SUBMIT]->head = owned_head;
1220
1221 do {
1222 struct z_erofs_pcluster *pcl;
1223 unsigned int clusterpages;
1224 pgoff_t first_index;
1225 struct page *page;
1226 unsigned int i = 0, bypass = 0;
1227 int err;
1228
1229 /* no possible 'owned_head' equals the following */
1230 DBG_BUGON(owned_head == Z_EROFS_PCLUSTER_TAIL_CLOSED);
1231 DBG_BUGON(owned_head == Z_EROFS_PCLUSTER_NIL);
1232
1233 pcl = container_of(owned_head, struct z_erofs_pcluster, next);
1234
1235 clusterpages = BIT(pcl->clusterbits);
1236
1237 /* close the main owned chain at first */
1238 owned_head = cmpxchg(&pcl->next, Z_EROFS_PCLUSTER_TAIL,
1239 Z_EROFS_PCLUSTER_TAIL_CLOSED);
1240
1241 first_index = pcl->obj.index;
1242 force_submit |= (first_index != last_index + 1);
1243
1244repeat:
1245 page = pickup_page_for_submission(pcl, i, pagepool,
1246 MNGD_MAPPING(sbi),
1247 GFP_NOFS);
1248 if (!page) {
1249 force_submit = true;
1250 ++bypass;
1251 goto skippage;
1252 }
1253
1254 if (bio && force_submit) {
1255submit_bio_retry:
1256 submit_bio(bio);
1257 bio = NULL;
1258 }
1259
1260 if (!bio) {
1261 bio = bio_alloc(GFP_NOIO, BIO_MAX_PAGES);
1262
1263 bio->bi_end_io = z_erofs_vle_read_endio;
1264 bio_set_dev(bio, sb->s_bdev);
1265 bio->bi_iter.bi_sector = (sector_t)(first_index + i) <<
1266 LOG_SECTORS_PER_BLOCK;
1267 bio->bi_private = bi_private;
1268 bio->bi_opf = REQ_OP_READ;
1269
1270 ++nr_bios;
1271 }
1272
1273 err = bio_add_page(bio, page, PAGE_SIZE, 0);
1274 if (err < PAGE_SIZE)
1275 goto submit_bio_retry;
1276
1277 force_submit = false;
1278 last_index = first_index + i;
1279skippage:
1280 if (++i < clusterpages)
1281 goto repeat;
1282
1283 if (bypass < clusterpages)
1284 qtail[JQ_SUBMIT] = &pcl->next;
1285 else
1286 move_to_bypass_jobqueue(pcl, qtail, owned_head);
1287 } while (owned_head != Z_EROFS_PCLUSTER_TAIL);
1288
1289 if (bio)
1290 submit_bio(bio);
1291
1292 if (postsubmit_is_all_bypassed(q, nr_bios, force_fg))
1293 return true;
1294
1295 z_erofs_vle_unzip_kickoff(bi_private, nr_bios);
1296 return true;
1297}
1298
1299static void z_erofs_submit_and_unzip(struct super_block *sb,
1300 struct z_erofs_collector *clt,
1301 struct list_head *pagepool,
1302 bool force_fg)
1303{
1304 struct z_erofs_unzip_io io[NR_JOBQUEUES];
1305
1306 if (!z_erofs_vle_submit_all(sb, clt->owned_head,
1307 pagepool, io, force_fg))
1308 return;
1309
1310 /* decompress no I/O pclusters immediately */
1311 z_erofs_vle_unzip_all(sb, &io[JQ_BYPASS], pagepool);
1312
1313 if (!force_fg)
1314 return;
1315
1316 /* wait until all bios are completed */
1317 wait_event(io[JQ_SUBMIT].u.wait,
1318 !atomic_read(&io[JQ_SUBMIT].pending_bios));
1319
1320 /* let's synchronous decompression */
1321 z_erofs_vle_unzip_all(sb, &io[JQ_SUBMIT], pagepool);
1322}
1323
1324static int z_erofs_vle_normalaccess_readpage(struct file *file,
1325 struct page *page)
1326{
1327 struct inode *const inode = page->mapping->host;
1328 struct z_erofs_decompress_frontend f = DECOMPRESS_FRONTEND_INIT(inode);
1329 int err;
1330 LIST_HEAD(pagepool);
1331
1332 trace_erofs_readpage(page, false);
1333
1334 f.headoffset = (erofs_off_t)page->index << PAGE_SHIFT;
1335
1336 err = z_erofs_do_read_page(&f, page, &pagepool);
1337 (void)z_erofs_collector_end(&f.clt);
1338
1339 /* if some compressed cluster ready, need submit them anyway */
1340 z_erofs_submit_and_unzip(inode->i_sb, &f.clt, &pagepool, true);
1341
1342 if (err)
1343 erofs_err(inode->i_sb, "failed to read, err [%d]", err);
1344
1345 if (f.map.mpage)
1346 put_page(f.map.mpage);
1347
1348 /* clean up the remaining free pages */
1349 put_pages_list(&pagepool);
1350 return err;
1351}
1352
1353static bool should_decompress_synchronously(struct erofs_sb_info *sbi,
1354 unsigned int nr)
1355{
1356 return nr <= sbi->max_sync_decompress_pages;
1357}
1358
1359static int z_erofs_vle_normalaccess_readpages(struct file *filp,
1360 struct address_space *mapping,
1361 struct list_head *pages,
1362 unsigned int nr_pages)
1363{
1364 struct inode *const inode = mapping->host;
1365 struct erofs_sb_info *const sbi = EROFS_I_SB(inode);
1366
1367 bool sync = should_decompress_synchronously(sbi, nr_pages);
1368 struct z_erofs_decompress_frontend f = DECOMPRESS_FRONTEND_INIT(inode);
1369 gfp_t gfp = mapping_gfp_constraint(mapping, GFP_KERNEL);
1370 struct page *head = NULL;
1371 LIST_HEAD(pagepool);
1372
1373 trace_erofs_readpages(mapping->host, lru_to_page(pages),
1374 nr_pages, false);
1375
1376 f.headoffset = (erofs_off_t)lru_to_page(pages)->index << PAGE_SHIFT;
1377
1378 for (; nr_pages; --nr_pages) {
1379 struct page *page = lru_to_page(pages);
1380
1381 prefetchw(&page->flags);
1382 list_del(&page->lru);
1383
1384 /*
1385 * A pure asynchronous readahead is indicated if
1386 * a PG_readahead marked page is hitted at first.
1387 * Let's also do asynchronous decompression for this case.
1388 */
1389 sync &= !(PageReadahead(page) && !head);
1390
1391 if (add_to_page_cache_lru(page, mapping, page->index, gfp)) {
1392 list_add(&page->lru, &pagepool);
1393 continue;
1394 }
1395
1396 set_page_private(page, (unsigned long)head);
1397 head = page;
1398 }
1399
1400 while (head) {
1401 struct page *page = head;
1402 int err;
1403
1404 /* traversal in reverse order */
1405 head = (void *)page_private(page);
1406
1407 err = z_erofs_do_read_page(&f, page, &pagepool);
1408 if (err)
1409 erofs_err(inode->i_sb,
1410 "readahead error at page %lu @ nid %llu",
1411 page->index, EROFS_I(inode)->nid);
1412 put_page(page);
1413 }
1414
1415 (void)z_erofs_collector_end(&f.clt);
1416
1417 z_erofs_submit_and_unzip(inode->i_sb, &f.clt, &pagepool, sync);
1418
1419 if (f.map.mpage)
1420 put_page(f.map.mpage);
1421
1422 /* clean up the remaining free pages */
1423 put_pages_list(&pagepool);
1424 return 0;
1425}
1426
1427const struct address_space_operations z_erofs_vle_normalaccess_aops = {
1428 .readpage = z_erofs_vle_normalaccess_readpage,
1429 .readpages = z_erofs_vle_normalaccess_readpages,
1430};
1431
diff --git a/drivers/staging/erofs/unzip_vle.h b/fs/erofs/zdata.h
index ab509d75aefd..faf950189bd7 100644
--- a/drivers/staging/erofs/unzip_vle.h
+++ b/fs/erofs/zdata.h
@@ -1,20 +1,14 @@
1/* SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0-only */
2 * 2/*
3 * linux/drivers/staging/erofs/unzip_vle.h
4 *
5 * Copyright (C) 2018 HUAWEI, Inc. 3 * Copyright (C) 2018 HUAWEI, Inc.
6 * http://www.huawei.com/ 4 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com> 5 * Created by Gao Xiang <gaoxiang25@huawei.com>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of the Linux
11 * distribution for more details.
12 */ 6 */
13#ifndef __EROFS_FS_UNZIP_VLE_H 7#ifndef __EROFS_FS_ZDATA_H
14#define __EROFS_FS_UNZIP_VLE_H 8#define __EROFS_FS_ZDATA_H
15 9
16#include "internal.h" 10#include "internal.h"
17#include "unzip_pagevec.h" 11#include "zpvec.h"
18 12
19#define Z_EROFS_NR_INLINE_PAGEVECS 3 13#define Z_EROFS_NR_INLINE_PAGEVECS 3
20 14
@@ -22,80 +16,77 @@
22 * Structure fields follow one of the following exclusion rules. 16 * Structure fields follow one of the following exclusion rules.
23 * 17 *
24 * I: Modifiable by initialization/destruction paths and read-only 18 * I: Modifiable by initialization/destruction paths and read-only
25 * for everyone else. 19 * for everyone else;
20 *
21 * L: Field should be protected by pageset lock;
26 * 22 *
23 * A: Field should be accessed / updated in atomic for parallelized code.
27 */ 24 */
28 25struct z_erofs_collection {
29struct z_erofs_vle_work {
30 struct mutex lock; 26 struct mutex lock;
31 27
32 /* I: decompression offset in page */ 28 /* I: page offset of start position of decompression */
33 unsigned short pageofs; 29 unsigned short pageofs;
30
31 /* L: maximum relative page index in pagevec[] */
34 unsigned short nr_pages; 32 unsigned short nr_pages;
35 33
36 /* L: queued pages in pagevec[] */ 34 /* L: total number of pages in pagevec[] */
37 unsigned vcnt; 35 unsigned int vcnt;
38 36
39 union { 37 union {
40 /* L: pagevec */ 38 /* L: inline a certain number of pagevecs for bootstrap */
41 erofs_vtptr_t pagevec[Z_EROFS_NR_INLINE_PAGEVECS]; 39 erofs_vtptr_t pagevec[Z_EROFS_NR_INLINE_PAGEVECS];
40
41 /* I: can be used to free the pcluster by RCU. */
42 struct rcu_head rcu; 42 struct rcu_head rcu;
43 }; 43 };
44}; 44};
45 45
46#define Z_EROFS_VLE_WORKGRP_FMT_PLAIN 0 46#define Z_EROFS_PCLUSTER_FULL_LENGTH 0x00000001
47#define Z_EROFS_VLE_WORKGRP_FMT_LZ4 1 47#define Z_EROFS_PCLUSTER_LENGTH_BIT 1
48#define Z_EROFS_VLE_WORKGRP_FMT_MASK 1
49#define Z_EROFS_VLE_WORKGRP_FULL_LENGTH 2
50 48
51typedef void *z_erofs_vle_owned_workgrp_t; 49/*
50 * let's leave a type here in case of introducing
51 * another tagged pointer later.
52 */
53typedef void *z_erofs_next_pcluster_t;
52 54
53struct z_erofs_vle_workgroup { 55struct z_erofs_pcluster {
54 struct erofs_workgroup obj; 56 struct erofs_workgroup obj;
55 struct z_erofs_vle_work work; 57 struct z_erofs_collection primary_collection;
56 58
57 /* point to next owned_workgrp_t */ 59 /* A: point to next chained pcluster or TAILs */
58 z_erofs_vle_owned_workgrp_t next; 60 z_erofs_next_pcluster_t next;
59 61
60 /* compressed pages (including multi-usage pages) */ 62 /* A: compressed pages (including multi-usage pages) */
61 struct page *compressed_pages[Z_EROFS_CLUSTER_MAX_PAGES]; 63 struct page *compressed_pages[Z_EROFS_CLUSTER_MAX_PAGES];
62 unsigned int llen, flags; 64
65 /* A: lower limit of decompressed length and if full length or not */
66 unsigned int length;
67
68 /* I: compression algorithm format */
69 unsigned char algorithmformat;
70 /* I: bit shift of physical cluster size */
71 unsigned char clusterbits;
63}; 72};
64 73
74#define z_erofs_primarycollection(pcluster) (&(pcluster)->primary_collection)
75
65/* let's avoid the valid 32-bit kernel addresses */ 76/* let's avoid the valid 32-bit kernel addresses */
66 77
67/* the chained workgroup has't submitted io (still open) */ 78/* the chained workgroup has't submitted io (still open) */
68#define Z_EROFS_VLE_WORKGRP_TAIL ((void *)0x5F0ECAFE) 79#define Z_EROFS_PCLUSTER_TAIL ((void *)0x5F0ECAFE)
69/* the chained workgroup has already submitted io */ 80/* the chained workgroup has already submitted io */
70#define Z_EROFS_VLE_WORKGRP_TAIL_CLOSED ((void *)0x5F0EDEAD) 81#define Z_EROFS_PCLUSTER_TAIL_CLOSED ((void *)0x5F0EDEAD)
71
72#define Z_EROFS_VLE_WORKGRP_NIL (NULL)
73
74#define z_erofs_vle_workgrp_fmt(grp) \
75 ((grp)->flags & Z_EROFS_VLE_WORKGRP_FMT_MASK)
76
77static inline void z_erofs_vle_set_workgrp_fmt(
78 struct z_erofs_vle_workgroup *grp,
79 unsigned int fmt)
80{
81 grp->flags = fmt | (grp->flags & ~Z_EROFS_VLE_WORKGRP_FMT_MASK);
82}
83 82
83#define Z_EROFS_PCLUSTER_NIL (NULL)
84 84
85/* definitions if multiref is disabled */ 85#define Z_EROFS_WORKGROUP_SIZE sizeof(struct z_erofs_pcluster)
86#define z_erofs_vle_grab_primary_work(grp) (&(grp)->work)
87#define z_erofs_vle_grab_work(grp, pageofs) (&(grp)->work)
88#define z_erofs_vle_work_workgroup(wrk, primary) \
89 ((primary) ? container_of(wrk, \
90 struct z_erofs_vle_workgroup, work) : \
91 ({ BUG(); (void *)NULL; }))
92 86
93 87struct z_erofs_unzip_io {
94#define Z_EROFS_WORKGROUP_SIZE sizeof(struct z_erofs_vle_workgroup)
95
96struct z_erofs_vle_unzip_io {
97 atomic_t pending_bios; 88 atomic_t pending_bios;
98 z_erofs_vle_owned_workgrp_t head; 89 z_erofs_next_pcluster_t head;
99 90
100 union { 91 union {
101 wait_queue_head_t wait; 92 wait_queue_head_t wait;
@@ -103,13 +94,20 @@ struct z_erofs_vle_unzip_io {
103 } u; 94 } u;
104}; 95};
105 96
106struct z_erofs_vle_unzip_io_sb { 97struct z_erofs_unzip_io_sb {
107 struct z_erofs_vle_unzip_io io; 98 struct z_erofs_unzip_io io;
108 struct super_block *sb; 99 struct super_block *sb;
109}; 100};
110 101
111#define Z_EROFS_ONLINEPAGE_COUNT_BITS 2 102#define MNGD_MAPPING(sbi) ((sbi)->managed_cache->i_mapping)
112#define Z_EROFS_ONLINEPAGE_COUNT_MASK ((1 << Z_EROFS_ONLINEPAGE_COUNT_BITS) - 1) 103static inline bool erofs_page_is_managed(const struct erofs_sb_info *sbi,
104 struct page *page)
105{
106 return page->mapping == MNGD_MAPPING(sbi);
107}
108
109#define Z_EROFS_ONLINEPAGE_COUNT_BITS 2
110#define Z_EROFS_ONLINEPAGE_COUNT_MASK ((1 << Z_EROFS_ONLINEPAGE_COUNT_BITS) - 1)
113#define Z_EROFS_ONLINEPAGE_INDEX_SHIFT (Z_EROFS_ONLINEPAGE_COUNT_BITS) 111#define Z_EROFS_ONLINEPAGE_INDEX_SHIFT (Z_EROFS_ONLINEPAGE_COUNT_BITS)
114 112
115/* 113/*
@@ -124,7 +122,7 @@ union z_erofs_onlinepage_converter {
124 unsigned long *v; 122 unsigned long *v;
125}; 123};
126 124
127static inline unsigned z_erofs_onlinepage_index(struct page *page) 125static inline unsigned int z_erofs_onlinepage_index(struct page *page)
128{ 126{
129 union z_erofs_onlinepage_converter u; 127 union z_erofs_onlinepage_converter u;
130 128
@@ -164,7 +162,7 @@ repeat:
164 } 162 }
165 163
166 v = (index << Z_EROFS_ONLINEPAGE_INDEX_SHIFT) | 164 v = (index << Z_EROFS_ONLINEPAGE_INDEX_SHIFT) |
167 ((o & Z_EROFS_ONLINEPAGE_COUNT_MASK) + (unsigned)down); 165 ((o & Z_EROFS_ONLINEPAGE_COUNT_MASK) + (unsigned int)down);
168 if (cmpxchg(p, o, v) != o) 166 if (cmpxchg(p, o, v) != o)
169 goto repeat; 167 goto repeat;
170} 168}
@@ -172,7 +170,7 @@ repeat:
172static inline void z_erofs_onlinepage_endio(struct page *page) 170static inline void z_erofs_onlinepage_endio(struct page *page)
173{ 171{
174 union z_erofs_onlinepage_converter u; 172 union z_erofs_onlinepage_converter u;
175 unsigned v; 173 unsigned int v;
176 174
177 DBG_BUGON(!PagePrivate(page)); 175 DBG_BUGON(!PagePrivate(page));
178 u.v = &page_private(page); 176 u.v = &page_private(page);
@@ -184,13 +182,12 @@ static inline void z_erofs_onlinepage_endio(struct page *page)
184 SetPageUptodate(page); 182 SetPageUptodate(page);
185 unlock_page(page); 183 unlock_page(page);
186 } 184 }
187 185 erofs_dbg("%s, page %p value %x", __func__, page, atomic_read(u.o));
188 debugln("%s, page %p value %x", __func__, page, atomic_read(u.o));
189} 186}
190 187
191#define Z_EROFS_VLE_VMAP_ONSTACK_PAGES \ 188#define Z_EROFS_VMAP_ONSTACK_PAGES \
192 min_t(unsigned int, THREAD_SIZE / 8 / sizeof(struct page *), 96U) 189 min_t(unsigned int, THREAD_SIZE / 8 / sizeof(struct page *), 96U)
193#define Z_EROFS_VLE_VMAP_GLOBAL_PAGES 2048 190#define Z_EROFS_VMAP_GLOBAL_PAGES 2048
194 191
195#endif 192#endif
196 193
diff --git a/drivers/staging/erofs/zmap.c b/fs/erofs/zmap.c
index 9c0bd65c46bf..6a26c293ae2d 100644
--- a/drivers/staging/erofs/zmap.c
+++ b/fs/erofs/zmap.c
@@ -1,7 +1,5 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0-only
2/* 2/*
3 * linux/drivers/staging/erofs/zmap.c
4 *
5 * Copyright (C) 2018-2019 HUAWEI, Inc. 3 * Copyright (C) 2018-2019 HUAWEI, Inc.
6 * http://www.huawei.com/ 4 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com> 5 * Created by Gao Xiang <gaoxiang25@huawei.com>
@@ -12,17 +10,16 @@
12 10
13int z_erofs_fill_inode(struct inode *inode) 11int z_erofs_fill_inode(struct inode *inode)
14{ 12{
15 struct erofs_vnode *const vi = EROFS_V(inode); 13 struct erofs_inode *const vi = EROFS_I(inode);
16 struct super_block *const sb = inode->i_sb;
17 14
18 if (vi->datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY) { 15 if (vi->datalayout == EROFS_INODE_FLAT_COMPRESSION_LEGACY) {
19 vi->z_advise = 0; 16 vi->z_advise = 0;
20 vi->z_algorithmtype[0] = 0; 17 vi->z_algorithmtype[0] = 0;
21 vi->z_algorithmtype[1] = 0; 18 vi->z_algorithmtype[1] = 0;
22 vi->z_logical_clusterbits = EROFS_SB(sb)->clusterbits; 19 vi->z_logical_clusterbits = LOG_BLOCK_SIZE;
23 vi->z_physical_clusterbits[0] = vi->z_logical_clusterbits; 20 vi->z_physical_clusterbits[0] = vi->z_logical_clusterbits;
24 vi->z_physical_clusterbits[1] = vi->z_logical_clusterbits; 21 vi->z_physical_clusterbits[1] = vi->z_logical_clusterbits;
25 set_bit(EROFS_V_Z_INITED_BIT, &vi->flags); 22 set_bit(EROFS_I_Z_INITED_BIT, &vi->flags);
26 } 23 }
27 24
28 inode->i_mapping->a_ops = &z_erofs_vle_normalaccess_aops; 25 inode->i_mapping->a_ops = &z_erofs_vle_normalaccess_aops;
@@ -31,7 +28,7 @@ int z_erofs_fill_inode(struct inode *inode)
31 28
32static int fill_inode_lazy(struct inode *inode) 29static int fill_inode_lazy(struct inode *inode)
33{ 30{
34 struct erofs_vnode *const vi = EROFS_V(inode); 31 struct erofs_inode *const vi = EROFS_I(inode);
35 struct super_block *const sb = inode->i_sb; 32 struct super_block *const sb = inode->i_sb;
36 int err; 33 int err;
37 erofs_off_t pos; 34 erofs_off_t pos;
@@ -39,21 +36,21 @@ static int fill_inode_lazy(struct inode *inode)
39 void *kaddr; 36 void *kaddr;
40 struct z_erofs_map_header *h; 37 struct z_erofs_map_header *h;
41 38
42 if (test_bit(EROFS_V_Z_INITED_BIT, &vi->flags)) 39 if (test_bit(EROFS_I_Z_INITED_BIT, &vi->flags))
43 return 0; 40 return 0;
44 41
45 if (wait_on_bit_lock(&vi->flags, EROFS_V_BL_Z_BIT, TASK_KILLABLE)) 42 if (wait_on_bit_lock(&vi->flags, EROFS_I_BL_Z_BIT, TASK_KILLABLE))
46 return -ERESTARTSYS; 43 return -ERESTARTSYS;
47 44
48 err = 0; 45 err = 0;
49 if (test_bit(EROFS_V_Z_INITED_BIT, &vi->flags)) 46 if (test_bit(EROFS_I_Z_INITED_BIT, &vi->flags))
50 goto out_unlock; 47 goto out_unlock;
51 48
52 DBG_BUGON(vi->datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY); 49 DBG_BUGON(vi->datalayout == EROFS_INODE_FLAT_COMPRESSION_LEGACY);
53 50
54 pos = ALIGN(iloc(EROFS_SB(sb), vi->nid) + vi->inode_isize + 51 pos = ALIGN(iloc(EROFS_SB(sb), vi->nid) + vi->inode_isize +
55 vi->xattr_isize, 8); 52 vi->xattr_isize, 8);
56 page = erofs_get_meta_page(sb, erofs_blknr(pos), false); 53 page = erofs_get_meta_page(sb, erofs_blknr(pos));
57 if (IS_ERR(page)) { 54 if (IS_ERR(page)) {
58 err = PTR_ERR(page); 55 err = PTR_ERR(page);
59 goto out_unlock; 56 goto out_unlock;
@@ -67,9 +64,9 @@ static int fill_inode_lazy(struct inode *inode)
67 vi->z_algorithmtype[1] = h->h_algorithmtype >> 4; 64 vi->z_algorithmtype[1] = h->h_algorithmtype >> 4;
68 65
69 if (vi->z_algorithmtype[0] >= Z_EROFS_COMPRESSION_MAX) { 66 if (vi->z_algorithmtype[0] >= Z_EROFS_COMPRESSION_MAX) {
70 errln("unknown compression format %u for nid %llu, please upgrade kernel", 67 erofs_err(sb, "unknown compression format %u for nid %llu, please upgrade kernel",
71 vi->z_algorithmtype[0], vi->nid); 68 vi->z_algorithmtype[0], vi->nid);
72 err = -ENOTSUPP; 69 err = -EOPNOTSUPP;
73 goto unmap_done; 70 goto unmap_done;
74 } 71 }
75 72
@@ -78,22 +75,21 @@ static int fill_inode_lazy(struct inode *inode)
78 ((h->h_clusterbits >> 3) & 3); 75 ((h->h_clusterbits >> 3) & 3);
79 76
80 if (vi->z_physical_clusterbits[0] != LOG_BLOCK_SIZE) { 77 if (vi->z_physical_clusterbits[0] != LOG_BLOCK_SIZE) {
81 errln("unsupported physical clusterbits %u for nid %llu, please upgrade kernel", 78 erofs_err(sb, "unsupported physical clusterbits %u for nid %llu, please upgrade kernel",
82 vi->z_physical_clusterbits[0], vi->nid); 79 vi->z_physical_clusterbits[0], vi->nid);
83 err = -ENOTSUPP; 80 err = -EOPNOTSUPP;
84 goto unmap_done; 81 goto unmap_done;
85 } 82 }
86 83
87 vi->z_physical_clusterbits[1] = vi->z_logical_clusterbits + 84 vi->z_physical_clusterbits[1] = vi->z_logical_clusterbits +
88 ((h->h_clusterbits >> 5) & 7); 85 ((h->h_clusterbits >> 5) & 7);
86 set_bit(EROFS_I_Z_INITED_BIT, &vi->flags);
89unmap_done: 87unmap_done:
90 kunmap_atomic(kaddr); 88 kunmap_atomic(kaddr);
91 unlock_page(page); 89 unlock_page(page);
92 put_page(page); 90 put_page(page);
93
94 set_bit(EROFS_V_Z_INITED_BIT, &vi->flags);
95out_unlock: 91out_unlock:
96 clear_and_wake_up_bit(EROFS_V_BL_Z_BIT, &vi->flags); 92 clear_and_wake_up_bit(EROFS_I_BL_Z_BIT, &vi->flags);
97 return err; 93 return err;
98} 94}
99 95
@@ -131,7 +127,7 @@ static int z_erofs_reload_indexes(struct z_erofs_maprecorder *m,
131 put_page(mpage); 127 put_page(mpage);
132 } 128 }
133 129
134 mpage = erofs_get_meta_page(sb, eblk, false); 130 mpage = erofs_get_meta_page(sb, eblk);
135 if (IS_ERR(mpage)) { 131 if (IS_ERR(mpage)) {
136 map->mpage = NULL; 132 map->mpage = NULL;
137 return PTR_ERR(mpage); 133 return PTR_ERR(mpage);
@@ -146,7 +142,7 @@ static int vle_legacy_load_cluster_from_disk(struct z_erofs_maprecorder *m,
146 unsigned long lcn) 142 unsigned long lcn)
147{ 143{
148 struct inode *const inode = m->inode; 144 struct inode *const inode = m->inode;
149 struct erofs_vnode *const vi = EROFS_V(inode); 145 struct erofs_inode *const vi = EROFS_I(inode);
150 const erofs_off_t ibase = iloc(EROFS_I_SB(inode), vi->nid); 146 const erofs_off_t ibase = iloc(EROFS_I_SB(inode), vi->nid);
151 const erofs_off_t pos = 147 const erofs_off_t pos =
152 Z_EROFS_VLE_LEGACY_INDEX_ALIGN(ibase + vi->inode_isize + 148 Z_EROFS_VLE_LEGACY_INDEX_ALIGN(ibase + vi->inode_isize +
@@ -179,7 +175,7 @@ static int vle_legacy_load_cluster_from_disk(struct z_erofs_maprecorder *m,
179 break; 175 break;
180 default: 176 default:
181 DBG_BUGON(1); 177 DBG_BUGON(1);
182 return -EIO; 178 return -EOPNOTSUPP;
183 } 179 }
184 m->type = type; 180 m->type = type;
185 return 0; 181 return 0;
@@ -200,7 +196,7 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
200 unsigned int amortizedshift, 196 unsigned int amortizedshift,
201 unsigned int eofs) 197 unsigned int eofs)
202{ 198{
203 struct erofs_vnode *const vi = EROFS_V(m->inode); 199 struct erofs_inode *const vi = EROFS_I(m->inode);
204 const unsigned int lclusterbits = vi->z_logical_clusterbits; 200 const unsigned int lclusterbits = vi->z_logical_clusterbits;
205 const unsigned int lomask = (1 << lclusterbits) - 1; 201 const unsigned int lomask = (1 << lclusterbits) - 1;
206 unsigned int vcnt, base, lo, encodebits, nblk; 202 unsigned int vcnt, base, lo, encodebits, nblk;
@@ -212,7 +208,7 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
212 else if (1 << amortizedshift == 2 && lclusterbits == 12) 208 else if (1 << amortizedshift == 2 && lclusterbits == 12)
213 vcnt = 16; 209 vcnt = 16;
214 else 210 else
215 return -ENOTSUPP; 211 return -EOPNOTSUPP;
216 212
217 encodebits = ((vcnt << amortizedshift) - sizeof(__le32)) * 8 / vcnt; 213 encodebits = ((vcnt << amortizedshift) - sizeof(__le32)) * 8 / vcnt;
218 base = round_down(eofs, vcnt << amortizedshift); 214 base = round_down(eofs, vcnt << amortizedshift);
@@ -264,7 +260,7 @@ static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m,
264 unsigned long lcn) 260 unsigned long lcn)
265{ 261{
266 struct inode *const inode = m->inode; 262 struct inode *const inode = m->inode;
267 struct erofs_vnode *const vi = EROFS_V(inode); 263 struct erofs_inode *const vi = EROFS_I(inode);
268 const unsigned int lclusterbits = vi->z_logical_clusterbits; 264 const unsigned int lclusterbits = vi->z_logical_clusterbits;
269 const erofs_off_t ebase = ALIGN(iloc(EROFS_I_SB(inode), vi->nid) + 265 const erofs_off_t ebase = ALIGN(iloc(EROFS_I_SB(inode), vi->nid) +
270 vi->inode_isize + vi->xattr_isize, 8) + 266 vi->inode_isize + vi->xattr_isize, 8) +
@@ -276,7 +272,7 @@ static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m,
276 int err; 272 int err;
277 273
278 if (lclusterbits != 12) 274 if (lclusterbits != 12)
279 return -ENOTSUPP; 275 return -EOPNOTSUPP;
280 276
281 if (lcn >= totalidx) 277 if (lcn >= totalidx)
282 return -EINVAL; 278 return -EINVAL;
@@ -318,7 +314,7 @@ out:
318static int vle_load_cluster_from_disk(struct z_erofs_maprecorder *m, 314static int vle_load_cluster_from_disk(struct z_erofs_maprecorder *m,
319 unsigned int lcn) 315 unsigned int lcn)
320{ 316{
321 const unsigned int datamode = EROFS_V(m->inode)->datamode; 317 const unsigned int datamode = EROFS_I(m->inode)->datalayout;
322 318
323 if (datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY) 319 if (datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY)
324 return vle_legacy_load_cluster_from_disk(m, lcn); 320 return vle_legacy_load_cluster_from_disk(m, lcn);
@@ -332,15 +328,17 @@ static int vle_load_cluster_from_disk(struct z_erofs_maprecorder *m,
332static int vle_extent_lookback(struct z_erofs_maprecorder *m, 328static int vle_extent_lookback(struct z_erofs_maprecorder *m,
333 unsigned int lookback_distance) 329 unsigned int lookback_distance)
334{ 330{
335 struct erofs_vnode *const vi = EROFS_V(m->inode); 331 struct erofs_inode *const vi = EROFS_I(m->inode);
336 struct erofs_map_blocks *const map = m->map; 332 struct erofs_map_blocks *const map = m->map;
337 const unsigned int lclusterbits = vi->z_logical_clusterbits; 333 const unsigned int lclusterbits = vi->z_logical_clusterbits;
338 unsigned long lcn = m->lcn; 334 unsigned long lcn = m->lcn;
339 int err; 335 int err;
340 336
341 if (lcn < lookback_distance) { 337 if (lcn < lookback_distance) {
338 erofs_err(m->inode->i_sb,
339 "bogus lookback distance @ nid %llu", vi->nid);
342 DBG_BUGON(1); 340 DBG_BUGON(1);
343 return -EIO; 341 return -EFSCORRUPTED;
344 } 342 }
345 343
346 /* load extent head logical cluster if needed */ 344 /* load extent head logical cluster if needed */
@@ -351,6 +349,13 @@ static int vle_extent_lookback(struct z_erofs_maprecorder *m,
351 349
352 switch (m->type) { 350 switch (m->type) {
353 case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD: 351 case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
352 if (!m->delta[0]) {
353 erofs_err(m->inode->i_sb,
354 "invalid lookback distance 0 @ nid %llu",
355 vi->nid);
356 DBG_BUGON(1);
357 return -EFSCORRUPTED;
358 }
354 return vle_extent_lookback(m, m->delta[0]); 359 return vle_extent_lookback(m, m->delta[0]);
355 case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN: 360 case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN:
356 map->m_flags &= ~EROFS_MAP_ZIPPED; 361 map->m_flags &= ~EROFS_MAP_ZIPPED;
@@ -359,10 +364,11 @@ static int vle_extent_lookback(struct z_erofs_maprecorder *m,
359 map->m_la = (lcn << lclusterbits) | m->clusterofs; 364 map->m_la = (lcn << lclusterbits) | m->clusterofs;
360 break; 365 break;
361 default: 366 default:
362 errln("unknown type %u at lcn %lu of nid %llu", 367 erofs_err(m->inode->i_sb,
363 m->type, lcn, vi->nid); 368 "unknown type %u @ lcn %lu of nid %llu",
369 m->type, lcn, vi->nid);
364 DBG_BUGON(1); 370 DBG_BUGON(1);
365 return -EIO; 371 return -EOPNOTSUPP;
366 } 372 }
367 return 0; 373 return 0;
368} 374}
@@ -371,7 +377,7 @@ int z_erofs_map_blocks_iter(struct inode *inode,
371 struct erofs_map_blocks *map, 377 struct erofs_map_blocks *map,
372 int flags) 378 int flags)
373{ 379{
374 struct erofs_vnode *const vi = EROFS_V(inode); 380 struct erofs_inode *const vi = EROFS_I(inode);
375 struct z_erofs_maprecorder m = { 381 struct z_erofs_maprecorder m = {
376 .inode = inode, 382 .inode = inode,
377 .map = map, 383 .map = map,
@@ -383,7 +389,7 @@ int z_erofs_map_blocks_iter(struct inode *inode,
383 trace_z_erofs_map_blocks_iter_enter(inode, map, flags); 389 trace_z_erofs_map_blocks_iter_enter(inode, map, flags);
384 390
385 /* when trying to read beyond EOF, leave it unmapped */ 391 /* when trying to read beyond EOF, leave it unmapped */
386 if (unlikely(map->m_la >= inode->i_size)) { 392 if (map->m_la >= inode->i_size) {
387 map->m_llen = map->m_la + 1 - inode->i_size; 393 map->m_llen = map->m_la + 1 - inode->i_size;
388 map->m_la = inode->i_size; 394 map->m_la = inode->i_size;
389 map->m_flags = 0; 395 map->m_flags = 0;
@@ -417,10 +423,11 @@ int z_erofs_map_blocks_iter(struct inode *inode,
417 break; 423 break;
418 } 424 }
419 /* m.lcn should be >= 1 if endoff < m.clusterofs */ 425 /* m.lcn should be >= 1 if endoff < m.clusterofs */
420 if (unlikely(!m.lcn)) { 426 if (!m.lcn) {
421 errln("invalid logical cluster 0 at nid %llu", 427 erofs_err(inode->i_sb,
422 vi->nid); 428 "invalid logical cluster 0 at nid %llu",
423 err = -EIO; 429 vi->nid);
430 err = -EFSCORRUPTED;
424 goto unmap_out; 431 goto unmap_out;
425 } 432 }
426 end = (m.lcn << lclusterbits) | m.clusterofs; 433 end = (m.lcn << lclusterbits) | m.clusterofs;
@@ -430,13 +437,14 @@ int z_erofs_map_blocks_iter(struct inode *inode,
430 case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD: 437 case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
431 /* get the correspoinding first chunk */ 438 /* get the correspoinding first chunk */
432 err = vle_extent_lookback(&m, m.delta[0]); 439 err = vle_extent_lookback(&m, m.delta[0]);
433 if (unlikely(err)) 440 if (err)
434 goto unmap_out; 441 goto unmap_out;
435 break; 442 break;
436 default: 443 default:
437 errln("unknown type %u at offset %llu of nid %llu", 444 erofs_err(inode->i_sb,
438 m.type, ofs, vi->nid); 445 "unknown type %u @ offset %llu of nid %llu",
439 err = -EIO; 446 m.type, ofs, vi->nid);
447 err = -EOPNOTSUPP;
440 goto unmap_out; 448 goto unmap_out;
441 } 449 }
442 450
@@ -450,9 +458,9 @@ unmap_out:
450 kunmap_atomic(m.kaddr); 458 kunmap_atomic(m.kaddr);
451 459
452out: 460out:
453 debugln("%s, m_la %llu m_pa %llu m_llen %llu m_plen %llu m_flags 0%o", 461 erofs_dbg("%s, m_la %llu m_pa %llu m_llen %llu m_plen %llu m_flags 0%o",
454 __func__, map->m_la, map->m_pa, 462 __func__, map->m_la, map->m_pa,
455 map->m_llen, map->m_plen, map->m_flags); 463 map->m_llen, map->m_plen, map->m_flags);
456 464
457 trace_z_erofs_map_blocks_iter_exit(inode, map, flags, err); 465 trace_z_erofs_map_blocks_iter_exit(inode, map, flags, err);
458 466
diff --git a/drivers/staging/erofs/unzip_pagevec.h b/fs/erofs/zpvec.h
index 7af0ba8d8495..58556903aa94 100644
--- a/drivers/staging/erofs/unzip_pagevec.h
+++ b/fs/erofs/zpvec.h
@@ -1,21 +1,15 @@
1/* SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0-only */
2 * 2/*
3 * linux/drivers/staging/erofs/unzip_pagevec.h
4 *
5 * Copyright (C) 2018 HUAWEI, Inc. 3 * Copyright (C) 2018 HUAWEI, Inc.
6 * http://www.huawei.com/ 4 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com> 5 * Created by Gao Xiang <gaoxiang25@huawei.com>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of the Linux
11 * distribution for more details.
12 */ 6 */
13#ifndef __EROFS_UNZIP_PAGEVEC_H 7#ifndef __EROFS_FS_ZPVEC_H
14#define __EROFS_UNZIP_PAGEVEC_H 8#define __EROFS_FS_ZPVEC_H
15 9
16#include <linux/tagptr.h> 10#include "tagptr.h"
17 11
18/* page type in pagevec for unzip subsystem */ 12/* page type in pagevec for decompress subsystem */
19enum z_erofs_page_type { 13enum z_erofs_page_type {
20 /* including Z_EROFS_VLE_PAGE_TAIL_EXCLUSIVE */ 14 /* including Z_EROFS_VLE_PAGE_TAIL_EXCLUSIVE */
21 Z_EROFS_PAGE_TYPE_EXCLUSIVE, 15 Z_EROFS_PAGE_TYPE_EXCLUSIVE,
@@ -54,9 +48,9 @@ static inline void z_erofs_pagevec_ctor_exit(struct z_erofs_pagevec_ctor *ctor,
54 48
55static inline struct page * 49static inline struct page *
56z_erofs_pagevec_ctor_next_page(struct z_erofs_pagevec_ctor *ctor, 50z_erofs_pagevec_ctor_next_page(struct z_erofs_pagevec_ctor *ctor,
57 unsigned nr) 51 unsigned int nr)
58{ 52{
59 unsigned index; 53 unsigned int index;
60 54
61 /* keep away from occupied pages */ 55 /* keep away from occupied pages */
62 if (ctor->next) 56 if (ctor->next)
@@ -64,7 +58,7 @@ z_erofs_pagevec_ctor_next_page(struct z_erofs_pagevec_ctor *ctor,
64 58
65 for (index = 0; index < nr; ++index) { 59 for (index = 0; index < nr; ++index) {
66 const erofs_vtptr_t t = ctor->pages[index]; 60 const erofs_vtptr_t t = ctor->pages[index];
67 const unsigned tags = tagptr_unfold_tags(t); 61 const unsigned int tags = tagptr_unfold_tags(t);
68 62
69 if (tags == Z_EROFS_PAGE_TYPE_EXCLUSIVE) 63 if (tags == Z_EROFS_PAGE_TYPE_EXCLUSIVE)
70 return tagptr_unfold_ptr(t); 64 return tagptr_unfold_ptr(t);
@@ -91,8 +85,9 @@ z_erofs_pagevec_ctor_pagedown(struct z_erofs_pagevec_ctor *ctor,
91} 85}
92 86
93static inline void z_erofs_pagevec_ctor_init(struct z_erofs_pagevec_ctor *ctor, 87static inline void z_erofs_pagevec_ctor_init(struct z_erofs_pagevec_ctor *ctor,
94 unsigned nr, 88 unsigned int nr,
95 erofs_vtptr_t *pages, unsigned i) 89 erofs_vtptr_t *pages,
90 unsigned int i)
96{ 91{
97 ctor->nr = nr; 92 ctor->nr = nr;
98 ctor->curr = ctor->next = NULL; 93 ctor->curr = ctor->next = NULL;
@@ -106,23 +101,21 @@ static inline void z_erofs_pagevec_ctor_init(struct z_erofs_pagevec_ctor *ctor,
106 z_erofs_pagevec_ctor_pagedown(ctor, false); 101 z_erofs_pagevec_ctor_pagedown(ctor, false);
107 } 102 }
108 } 103 }
109
110 ctor->next = z_erofs_pagevec_ctor_next_page(ctor, i); 104 ctor->next = z_erofs_pagevec_ctor_next_page(ctor, i);
111 ctor->index = i; 105 ctor->index = i;
112} 106}
113 107
114static inline bool 108static inline bool z_erofs_pagevec_enqueue(struct z_erofs_pagevec_ctor *ctor,
115z_erofs_pagevec_ctor_enqueue(struct z_erofs_pagevec_ctor *ctor, 109 struct page *page,
116 struct page *page, 110 enum z_erofs_page_type type,
117 enum z_erofs_page_type type, 111 bool *occupied)
118 bool *occupied)
119{ 112{
120 *occupied = false; 113 *occupied = false;
121 if (unlikely(!ctor->next && type)) 114 if (!ctor->next && type)
122 if (ctor->index + 1 == ctor->nr) 115 if (ctor->index + 1 == ctor->nr)
123 return false; 116 return false;
124 117
125 if (unlikely(ctor->index >= ctor->nr)) 118 if (ctor->index >= ctor->nr)
126 z_erofs_pagevec_ctor_pagedown(ctor, false); 119 z_erofs_pagevec_ctor_pagedown(ctor, false);
127 120
128 /* exclusive page type must be 0 */ 121 /* exclusive page type must be 0 */
@@ -134,19 +127,17 @@ z_erofs_pagevec_ctor_enqueue(struct z_erofs_pagevec_ctor *ctor,
134 ctor->next = page; 127 ctor->next = page;
135 *occupied = true; 128 *occupied = true;
136 } 129 }
137 130 ctor->pages[ctor->index++] = tagptr_fold(erofs_vtptr_t, page, type);
138 ctor->pages[ctor->index++] =
139 tagptr_fold(erofs_vtptr_t, page, type);
140 return true; 131 return true;
141} 132}
142 133
143static inline struct page * 134static inline struct page *
144z_erofs_pagevec_ctor_dequeue(struct z_erofs_pagevec_ctor *ctor, 135z_erofs_pagevec_dequeue(struct z_erofs_pagevec_ctor *ctor,
145 enum z_erofs_page_type *type) 136 enum z_erofs_page_type *type)
146{ 137{
147 erofs_vtptr_t t; 138 erofs_vtptr_t t;
148 139
149 if (unlikely(ctor->index >= ctor->nr)) { 140 if (ctor->index >= ctor->nr) {
150 DBG_BUGON(!ctor->next); 141 DBG_BUGON(!ctor->next);
151 z_erofs_pagevec_ctor_pagedown(ctor, true); 142 z_erofs_pagevec_ctor_pagedown(ctor, true);
152 } 143 }
@@ -159,11 +150,8 @@ z_erofs_pagevec_ctor_dequeue(struct z_erofs_pagevec_ctor *ctor,
159 if (*type == (uintptr_t)ctor->next) 150 if (*type == (uintptr_t)ctor->next)
160 ctor->next = tagptr_unfold_ptr(t); 151 ctor->next = tagptr_unfold_ptr(t);
161 152
162 ctor->pages[ctor->index++] = 153 ctor->pages[ctor->index++] = tagptr_fold(erofs_vtptr_t, NULL, 0);
163 tagptr_fold(erofs_vtptr_t, NULL, 0);
164
165 return tagptr_unfold_ptr(t); 154 return tagptr_unfold_ptr(t);
166} 155}
167
168#endif 156#endif
169 157
diff --git a/drivers/staging/greybus/greybus.h b/include/linux/greybus.h
index d03ddb7c9df0..18c0fb958b74 100644
--- a/drivers/staging/greybus/greybus.h
+++ b/include/linux/greybus.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Greybus driver and device API 3 * Greybus driver and device API
4 * 4 *
@@ -20,18 +20,18 @@
20#include <linux/pm_runtime.h> 20#include <linux/pm_runtime.h>
21#include <linux/idr.h> 21#include <linux/idr.h>
22 22
23#include "greybus_id.h" 23#include <linux/greybus/greybus_id.h>
24#include "greybus_manifest.h" 24#include <linux/greybus/greybus_manifest.h>
25#include "greybus_protocols.h" 25#include <linux/greybus/greybus_protocols.h>
26#include "manifest.h" 26#include <linux/greybus/manifest.h>
27#include "hd.h" 27#include <linux/greybus/hd.h>
28#include "svc.h" 28#include <linux/greybus/svc.h>
29#include "control.h" 29#include <linux/greybus/control.h>
30#include "module.h" 30#include <linux/greybus/module.h>
31#include "interface.h" 31#include <linux/greybus/interface.h>
32#include "bundle.h" 32#include <linux/greybus/bundle.h>
33#include "connection.h" 33#include <linux/greybus/connection.h>
34#include "operation.h" 34#include <linux/greybus/operation.h>
35 35
36/* Matches up with the Greybus Protocol specification document */ 36/* Matches up with the Greybus Protocol specification document */
37#define GREYBUS_VERSION_MAJOR 0x00 37#define GREYBUS_VERSION_MAJOR 0x00
diff --git a/drivers/staging/greybus/bundle.h b/include/linux/greybus/bundle.h
index 8734d2055657..df8d88424cb7 100644
--- a/drivers/staging/greybus/bundle.h
+++ b/include/linux/greybus/bundle.h
@@ -9,7 +9,10 @@
9#ifndef __BUNDLE_H 9#ifndef __BUNDLE_H
10#define __BUNDLE_H 10#define __BUNDLE_H
11 11
12#include <linux/types.h>
12#include <linux/list.h> 13#include <linux/list.h>
14#include <linux/pm_runtime.h>
15#include <linux/device.h>
13 16
14#define BUNDLE_ID_NONE U8_MAX 17#define BUNDLE_ID_NONE U8_MAX
15 18
diff --git a/drivers/staging/greybus/connection.h b/include/linux/greybus/connection.h
index 5ca3befc0636..d59b7fc1de3e 100644
--- a/drivers/staging/greybus/connection.h
+++ b/include/linux/greybus/connection.h
@@ -9,8 +9,11 @@
9#ifndef __CONNECTION_H 9#ifndef __CONNECTION_H
10#define __CONNECTION_H 10#define __CONNECTION_H
11 11
12#include <linux/bits.h>
12#include <linux/list.h> 13#include <linux/list.h>
13#include <linux/kfifo.h> 14#include <linux/kfifo.h>
15#include <linux/kref.h>
16#include <linux/workqueue.h>
14 17
15#define GB_CONNECTION_FLAG_CSD BIT(0) 18#define GB_CONNECTION_FLAG_CSD BIT(0)
16#define GB_CONNECTION_FLAG_NO_FLOWCTRL BIT(1) 19#define GB_CONNECTION_FLAG_NO_FLOWCTRL BIT(1)
diff --git a/drivers/staging/greybus/control.h b/include/linux/greybus/control.h
index 3a29ec05f631..da11fe871653 100644
--- a/drivers/staging/greybus/control.h
+++ b/include/linux/greybus/control.h
@@ -9,6 +9,9 @@
9#ifndef __CONTROL_H 9#ifndef __CONTROL_H
10#define __CONTROL_H 10#define __CONTROL_H
11 11
12#include <linux/types.h>
13#include <linux/device.h>
14
12struct gb_control { 15struct gb_control {
13 struct device dev; 16 struct device dev;
14 struct gb_interface *intf; 17 struct gb_interface *intf;
diff --git a/drivers/staging/greybus/greybus_id.h b/include/linux/greybus/greybus_id.h
index f4c8440093e4..f4c8440093e4 100644
--- a/drivers/staging/greybus/greybus_id.h
+++ b/include/linux/greybus/greybus_id.h
diff --git a/drivers/staging/greybus/greybus_manifest.h b/include/linux/greybus/greybus_manifest.h
index 2cec5cf7a846..6e62fe478712 100644
--- a/drivers/staging/greybus/greybus_manifest.h
+++ b/include/linux/greybus/greybus_manifest.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Greybus manifest definition 3 * Greybus manifest definition
4 * 4 *
@@ -14,6 +14,9 @@
14#ifndef __GREYBUS_MANIFEST_H 14#ifndef __GREYBUS_MANIFEST_H
15#define __GREYBUS_MANIFEST_H 15#define __GREYBUS_MANIFEST_H
16 16
17#include <linux/bits.h>
18#include <linux/types.h>
19
17enum greybus_descriptor_type { 20enum greybus_descriptor_type {
18 GREYBUS_TYPE_INVALID = 0x00, 21 GREYBUS_TYPE_INVALID = 0x00,
19 GREYBUS_TYPE_INTERFACE = 0x01, 22 GREYBUS_TYPE_INTERFACE = 0x01,
diff --git a/drivers/staging/greybus/greybus_protocols.h b/include/linux/greybus/greybus_protocols.h
index ddc73f10eb22..dfbc6c39a74b 100644
--- a/drivers/staging/greybus/greybus_protocols.h
+++ b/include/linux/greybus/greybus_protocols.h
@@ -1,58 +1,14 @@
1// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) 1/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2/* 2/*
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2014 - 2015 Google Inc. All rights reserved.
9 * Copyright(c) 2014 - 2015 Linaro Ltd. All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License version 2 for more details.
19 *
20 * BSD LICENSE
21 *
22 * Copyright(c) 2014 - 2015 Google Inc. All rights reserved. 3 * Copyright(c) 2014 - 2015 Google Inc. All rights reserved.
23 * Copyright(c) 2014 - 2015 Linaro Ltd. All rights reserved. 4 * Copyright(c) 2014 - 2015 Linaro Ltd. All rights reserved.
24 *
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
27 * are met:
28 *
29 * * Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * * Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in
33 * the documentation and/or other materials provided with the
34 * distribution.
35 * * Neither the name of Google Inc. or Linaro Ltd. nor the names of
36 * its contributors may be used to endorse or promote products
37 * derived from this software without specific prior written
38 * permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
44 * LINARO LTD. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
46 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
47 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
48 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 */ 5 */
52 6
53#ifndef __GREYBUS_PROTOCOLS_H 7#ifndef __GREYBUS_PROTOCOLS_H
54#define __GREYBUS_PROTOCOLS_H 8#define __GREYBUS_PROTOCOLS_H
55 9
10#include <linux/types.h>
11
56/* Fixed IDs for control/svc protocols */ 12/* Fixed IDs for control/svc protocols */
57 13
58/* SVC switch-port device ids */ 14/* SVC switch-port device ids */
diff --git a/drivers/staging/greybus/hd.h b/include/linux/greybus/hd.h
index 6cf024a20a58..d3faf0c1a569 100644
--- a/drivers/staging/greybus/hd.h
+++ b/include/linux/greybus/hd.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Greybus Host Device 3 * Greybus Host Device
4 * 4 *
@@ -9,6 +9,9 @@
9#ifndef __HD_H 9#ifndef __HD_H
10#define __HD_H 10#define __HD_H
11 11
12#include <linux/types.h>
13#include <linux/device.h>
14
12struct gb_host_device; 15struct gb_host_device;
13struct gb_message; 16struct gb_message;
14 17
diff --git a/drivers/staging/greybus/interface.h b/include/linux/greybus/interface.h
index 1c00c5bb3ec9..ce4def881e6f 100644
--- a/drivers/staging/greybus/interface.h
+++ b/include/linux/greybus/interface.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Greybus Interface Block code 3 * Greybus Interface Block code
4 * 4 *
@@ -9,6 +9,9 @@
9#ifndef __INTERFACE_H 9#ifndef __INTERFACE_H
10#define __INTERFACE_H 10#define __INTERFACE_H
11 11
12#include <linux/types.h>
13#include <linux/device.h>
14
12enum gb_interface_type { 15enum gb_interface_type {
13 GB_INTERFACE_TYPE_INVALID = 0, 16 GB_INTERFACE_TYPE_INVALID = 0,
14 GB_INTERFACE_TYPE_UNKNOWN, 17 GB_INTERFACE_TYPE_UNKNOWN,
diff --git a/drivers/staging/greybus/manifest.h b/include/linux/greybus/manifest.h
index f3c95a255631..830301b7a8bc 100644
--- a/drivers/staging/greybus/manifest.h
+++ b/include/linux/greybus/manifest.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Greybus manifest parsing 3 * Greybus manifest parsing
4 * 4 *
@@ -9,6 +9,8 @@
9#ifndef __MANIFEST_H 9#ifndef __MANIFEST_H
10#define __MANIFEST_H 10#define __MANIFEST_H
11 11
12#include <linux/types.h>
13
12struct gb_interface; 14struct gb_interface;
13bool gb_manifest_parse(struct gb_interface *intf, void *data, size_t size); 15bool gb_manifest_parse(struct gb_interface *intf, void *data, size_t size);
14 16
diff --git a/drivers/staging/greybus/module.h b/include/linux/greybus/module.h
index b1ebcc6636db..47b839af145d 100644
--- a/drivers/staging/greybus/module.h
+++ b/include/linux/greybus/module.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Greybus Module code 3 * Greybus Module code
4 * 4 *
@@ -9,6 +9,9 @@
9#ifndef __MODULE_H 9#ifndef __MODULE_H
10#define __MODULE_H 10#define __MODULE_H
11 11
12#include <linux/types.h>
13#include <linux/device.h>
14
12struct gb_module { 15struct gb_module {
13 struct device dev; 16 struct device dev;
14 struct gb_host_device *hd; 17 struct gb_host_device *hd;
diff --git a/drivers/staging/greybus/operation.h b/include/linux/greybus/operation.h
index 40b7b02fff88..cb8e4ef45222 100644
--- a/drivers/staging/greybus/operation.h
+++ b/include/linux/greybus/operation.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Greybus operations 3 * Greybus operations
4 * 4 *
@@ -10,7 +10,12 @@
10#define __OPERATION_H 10#define __OPERATION_H
11 11
12#include <linux/completion.h> 12#include <linux/completion.h>
13#include <linux/kref.h>
14#include <linux/timer.h>
15#include <linux/types.h>
16#include <linux/workqueue.h>
13 17
18struct gb_host_device;
14struct gb_operation; 19struct gb_operation;
15 20
16/* The default amount of time a request is given to complete */ 21/* The default amount of time a request is given to complete */
diff --git a/drivers/staging/greybus/svc.h b/include/linux/greybus/svc.h
index ad01783bac9c..5afaf5f06856 100644
--- a/drivers/staging/greybus/svc.h
+++ b/include/linux/greybus/svc.h
@@ -1,4 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Greybus SVC code 3 * Greybus SVC code
4 * 4 *
@@ -9,6 +9,11 @@
9#ifndef __SVC_H 9#ifndef __SVC_H
10#define __SVC_H 10#define __SVC_H
11 11
12#include <linux/types.h>
13#include <linux/device.h>
14
15struct gb_svc_l2_timer_cfg;
16
12#define GB_SVC_CPORT_FLAG_E2EFC BIT(0) 17#define GB_SVC_CPORT_FLAG_E2EFC BIT(0)
13#define GB_SVC_CPORT_FLAG_CSD_N BIT(1) 18#define GB_SVC_CPORT_FLAG_CSD_N BIT(1)
14#define GB_SVC_CPORT_FLAG_CSV_N BIT(2) 19#define GB_SVC_CPORT_FLAG_CSV_N BIT(2)
diff --git a/include/linux/iio/common/cros_ec_sensors_core.h b/include/linux/iio/common/cros_ec_sensors_core.h
index 0c636b9fe8d7..ea1f50ce2e49 100644
--- a/include/linux/iio/common/cros_ec_sensors_core.h
+++ b/include/linux/iio/common/cros_ec_sensors_core.h
@@ -62,14 +62,20 @@ struct cros_ec_sensors_core_state {
62 enum motionsensor_type type; 62 enum motionsensor_type type;
63 enum motionsensor_location loc; 63 enum motionsensor_location loc;
64 64
65 s16 calib[CROS_EC_SENSOR_MAX_AXIS]; 65 struct calib_data {
66 66 s16 offset;
67 u16 scale;
68 } calib[CROS_EC_SENSOR_MAX_AXIS];
69 s8 sign[CROS_EC_SENSOR_MAX_AXIS];
67 u8 samples[CROS_EC_SAMPLE_SIZE]; 70 u8 samples[CROS_EC_SAMPLE_SIZE];
68 71
69 int (*read_ec_sensors_data)(struct iio_dev *indio_dev, 72 int (*read_ec_sensors_data)(struct iio_dev *indio_dev,
70 unsigned long scan_mask, s16 *data); 73 unsigned long scan_mask, s16 *data);
71 74
72 int curr_sampl_freq; 75 int curr_sampl_freq;
76
77 /* Table of known available frequencies : 0, Min and Max in mHz */
78 int frequencies[3];
73}; 79};
74 80
75/** 81/**
@@ -151,6 +157,24 @@ int cros_ec_sensors_core_read(struct cros_ec_sensors_core_state *st,
151 int *val, int *val2, long mask); 157 int *val, int *val2, long mask);
152 158
153/** 159/**
160 * cros_ec_sensors_core_read_avail() - get available values
161 * @indio_dev: pointer to state information for device
162 * @chan: channel specification structure table
163 * @vals: list of available values
164 * @type: type of data returned
165 * @length: number of data returned in the array
166 * @mask: specifies which values to be requested
167 *
168 * Return: an error code, IIO_AVAIL_RANGE or IIO_AVAIL_LIST
169 */
170int cros_ec_sensors_core_read_avail(struct iio_dev *indio_dev,
171 struct iio_chan_spec const *chan,
172 const int **vals,
173 int *type,
174 int *length,
175 long mask);
176
177/**
154 * cros_ec_sensors_core_write() - function to write a value to the sensor 178 * cros_ec_sensors_core_write() - function to write a value to the sensor
155 * @st: pointer to state information for device 179 * @st: pointer to state information for device
156 * @chan: channel specification structure table 180 * @chan: channel specification structure table
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
index 2948ac99e2da..686be532f4cb 100644
--- a/include/linux/iio/common/st_sensors.h
+++ b/include/linux/iio/common/st_sensors.h
@@ -16,11 +16,16 @@
16#include <linux/iio/trigger.h> 16#include <linux/iio/trigger.h>
17#include <linux/bitops.h> 17#include <linux/bitops.h>
18#include <linux/regulator/consumer.h> 18#include <linux/regulator/consumer.h>
19#include <linux/regmap.h>
19 20
20#include <linux/platform_data/st_sensors_pdata.h> 21#include <linux/platform_data/st_sensors_pdata.h>
21 22
22#define ST_SENSORS_TX_MAX_LENGTH 2 23/*
23#define ST_SENSORS_RX_MAX_LENGTH 6 24 * Buffer size max case: 2bytes per channel, 3 channels in total +
25 * 8bytes timestamp channel (s64)
26 */
27#define ST_SENSORS_MAX_BUFFER_SIZE (ALIGN(2 * 3, sizeof(s64)) + \
28 sizeof(s64))
24 29
25#define ST_SENSORS_ODR_LIST_MAX 10 30#define ST_SENSORS_ODR_LIST_MAX 10
26#define ST_SENSORS_FULLSCALE_AVL_MAX 10 31#define ST_SENSORS_FULLSCALE_AVL_MAX 10
@@ -170,36 +175,6 @@ struct st_sensor_data_ready_irq {
170}; 175};
171 176
172/** 177/**
173 * struct st_sensor_transfer_buffer - ST sensor device I/O buffer
174 * @buf_lock: Mutex to protect rx and tx buffers.
175 * @tx_buf: Buffer used by SPI transfer function to send data to the sensors.
176 * This buffer is used to avoid DMA not-aligned issue.
177 * @rx_buf: Buffer used by SPI transfer to receive data from sensors.
178 * This buffer is used to avoid DMA not-aligned issue.
179 */
180struct st_sensor_transfer_buffer {
181 struct mutex buf_lock;
182 u8 rx_buf[ST_SENSORS_RX_MAX_LENGTH];
183 u8 tx_buf[ST_SENSORS_TX_MAX_LENGTH] ____cacheline_aligned;
184};
185
186/**
187 * struct st_sensor_transfer_function - ST sensor device I/O function
188 * @read_byte: Function used to read one byte.
189 * @write_byte: Function used to write one byte.
190 * @read_multiple_byte: Function used to read multiple byte.
191 */
192struct st_sensor_transfer_function {
193 int (*read_byte) (struct st_sensor_transfer_buffer *tb,
194 struct device *dev, u8 reg_addr, u8 *res_byte);
195 int (*write_byte) (struct st_sensor_transfer_buffer *tb,
196 struct device *dev, u8 reg_addr, u8 data);
197 int (*read_multiple_byte) (struct st_sensor_transfer_buffer *tb,
198 struct device *dev, u8 reg_addr, int len, u8 *data,
199 bool multiread_bit);
200};
201
202/**
203 * struct st_sensor_settings - ST specific sensor settings 178 * struct st_sensor_settings - ST specific sensor settings
204 * @wai: Contents of WhoAmI register. 179 * @wai: Contents of WhoAmI register.
205 * @wai_addr: The address of WhoAmI register. 180 * @wai_addr: The address of WhoAmI register.
@@ -242,19 +217,17 @@ struct st_sensor_settings {
242 * @current_fullscale: Maximum range of measure by the sensor. 217 * @current_fullscale: Maximum range of measure by the sensor.
243 * @vdd: Pointer to sensor's Vdd power supply 218 * @vdd: Pointer to sensor's Vdd power supply
244 * @vdd_io: Pointer to sensor's Vdd-IO power supply 219 * @vdd_io: Pointer to sensor's Vdd-IO power supply
220 * @regmap: Pointer to specific sensor regmap configuration.
245 * @enabled: Status of the sensor (false->off, true->on). 221 * @enabled: Status of the sensor (false->off, true->on).
246 * @multiread_bit: Use or not particular bit for [I2C/SPI] multiread.
247 * @buffer_data: Data used by buffer part.
248 * @odr: Output data rate of the sensor [Hz]. 222 * @odr: Output data rate of the sensor [Hz].
249 * num_data_channels: Number of data channels used in buffer. 223 * num_data_channels: Number of data channels used in buffer.
250 * @drdy_int_pin: Redirect DRDY on pin 1 (1) or pin 2 (2). 224 * @drdy_int_pin: Redirect DRDY on pin 1 (1) or pin 2 (2).
251 * @int_pin_open_drain: Set the interrupt/DRDY to open drain. 225 * @int_pin_open_drain: Set the interrupt/DRDY to open drain.
252 * @get_irq_data_ready: Function to get the IRQ used for data ready signal. 226 * @irq: the IRQ number.
253 * @tf: Transfer function structure used by I/O operations.
254 * @tb: Transfer buffers and mutex used by I/O operations.
255 * @edge_irq: the IRQ triggers on edges and need special handling. 227 * @edge_irq: the IRQ triggers on edges and need special handling.
256 * @hw_irq_trigger: if we're using the hardware interrupt on the sensor. 228 * @hw_irq_trigger: if we're using the hardware interrupt on the sensor.
257 * @hw_timestamp: Latest timestamp from the interrupt handler, when in use. 229 * @hw_timestamp: Latest timestamp from the interrupt handler, when in use.
230 * @buffer_data: Data used by buffer part.
258 */ 231 */
259struct st_sensor_data { 232struct st_sensor_data {
260 struct device *dev; 233 struct device *dev;
@@ -264,26 +237,22 @@ struct st_sensor_data {
264 struct st_sensor_fullscale_avl *current_fullscale; 237 struct st_sensor_fullscale_avl *current_fullscale;
265 struct regulator *vdd; 238 struct regulator *vdd;
266 struct regulator *vdd_io; 239 struct regulator *vdd_io;
240 struct regmap *regmap;
267 241
268 bool enabled; 242 bool enabled;
269 bool multiread_bit;
270
271 char *buffer_data;
272 243
273 unsigned int odr; 244 unsigned int odr;
274 unsigned int num_data_channels; 245 unsigned int num_data_channels;
275 246
276 u8 drdy_int_pin; 247 u8 drdy_int_pin;
277 bool int_pin_open_drain; 248 bool int_pin_open_drain;
278 249 int irq;
279 unsigned int (*get_irq_data_ready) (struct iio_dev *indio_dev);
280
281 const struct st_sensor_transfer_function *tf;
282 struct st_sensor_transfer_buffer tb;
283 250
284 bool edge_irq; 251 bool edge_irq;
285 bool hw_irq_trigger; 252 bool hw_irq_trigger;
286 s64 hw_timestamp; 253 s64 hw_timestamp;
254
255 char buffer_data[ST_SENSORS_MAX_BUFFER_SIZE] ____cacheline_aligned;
287}; 256};
288 257
289#ifdef CONFIG_IIO_BUFFER 258#ifdef CONFIG_IIO_BUFFER
@@ -334,8 +303,11 @@ int st_sensors_set_fullscale_by_gain(struct iio_dev *indio_dev, int scale);
334int st_sensors_read_info_raw(struct iio_dev *indio_dev, 303int st_sensors_read_info_raw(struct iio_dev *indio_dev,
335 struct iio_chan_spec const *ch, int *val); 304 struct iio_chan_spec const *ch, int *val);
336 305
337int st_sensors_check_device_support(struct iio_dev *indio_dev, 306int st_sensors_get_settings_index(const char *name,
338 int num_sensors_list, const struct st_sensor_settings *sensor_settings); 307 const struct st_sensor_settings *list,
308 const int list_length);
309
310int st_sensors_verify_id(struct iio_dev *indio_dev);
339 311
340ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev, 312ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
341 struct device_attribute *attr, char *buf); 313 struct device_attribute *attr, char *buf);
diff --git a/include/linux/iio/common/st_sensors_i2c.h b/include/linux/iio/common/st_sensors_i2c.h
index 5ada89944698..01e424e2af4f 100644
--- a/include/linux/iio/common/st_sensors_i2c.h
+++ b/include/linux/iio/common/st_sensors_i2c.h
@@ -14,8 +14,8 @@
14#include <linux/iio/common/st_sensors.h> 14#include <linux/iio/common/st_sensors.h>
15#include <linux/of.h> 15#include <linux/of.h>
16 16
17void st_sensors_i2c_configure(struct iio_dev *indio_dev, 17int st_sensors_i2c_configure(struct iio_dev *indio_dev,
18 struct i2c_client *client, struct st_sensor_data *sdata); 18 struct i2c_client *client);
19 19
20#ifdef CONFIG_ACPI 20#ifdef CONFIG_ACPI
21int st_sensors_match_acpi_device(struct device *dev); 21int st_sensors_match_acpi_device(struct device *dev);
diff --git a/include/linux/iio/common/st_sensors_spi.h b/include/linux/iio/common/st_sensors_spi.h
index 6020f7167859..90b25f087f06 100644
--- a/include/linux/iio/common/st_sensors_spi.h
+++ b/include/linux/iio/common/st_sensors_spi.h
@@ -13,7 +13,7 @@
13#include <linux/spi/spi.h> 13#include <linux/spi/spi.h>
14#include <linux/iio/common/st_sensors.h> 14#include <linux/iio/common/st_sensors.h>
15 15
16void st_sensors_spi_configure(struct iio_dev *indio_dev, 16int st_sensors_spi_configure(struct iio_dev *indio_dev,
17 struct spi_device *spi, struct st_sensor_data *sdata); 17 struct spi_device *spi);
18 18
19#endif /* ST_SENSORS_SPI_H */ 19#endif /* ST_SENSORS_SPI_H */
diff --git a/include/linux/iio/imu/adis.h b/include/linux/iio/imu/adis.h
index 3428d06b2f44..4c53815bb729 100644
--- a/include/linux/iio/imu/adis.h
+++ b/include/linux/iio/imu/adis.h
@@ -26,6 +26,7 @@ struct adis_burst;
26 * struct adis_data - ADIS chip variant specific data 26 * struct adis_data - ADIS chip variant specific data
27 * @read_delay: SPI delay for read operations in us 27 * @read_delay: SPI delay for read operations in us
28 * @write_delay: SPI delay for write operations in us 28 * @write_delay: SPI delay for write operations in us
29 * @cs_change_delay: SPI delay between CS changes in us
29 * @glob_cmd_reg: Register address of the GLOB_CMD register 30 * @glob_cmd_reg: Register address of the GLOB_CMD register
30 * @msc_ctrl_reg: Register address of the MSC_CTRL register 31 * @msc_ctrl_reg: Register address of the MSC_CTRL register
31 * @diag_stat_reg: Register address of the DIAG_STAT register 32 * @diag_stat_reg: Register address of the DIAG_STAT register
@@ -35,6 +36,7 @@ struct adis_burst;
35struct adis_data { 36struct adis_data {
36 unsigned int read_delay; 37 unsigned int read_delay;
37 unsigned int write_delay; 38 unsigned int write_delay;
39 unsigned int cs_change_delay;
38 40
39 unsigned int glob_cmd_reg; 41 unsigned int glob_cmd_reg;
40 unsigned int msc_ctrl_reg; 42 unsigned int msc_ctrl_reg;
diff --git a/drivers/staging/erofs/include/trace/events/erofs.h b/include/trace/events/erofs.h
index 660c92fc1803..27f5caa6299a 100644
--- a/drivers/staging/erofs/include/trace/events/erofs.h
+++ b/include/trace/events/erofs.h
@@ -1,4 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */ 1/* SPDX-License-Identifier: GPL-2.0-only */
2#undef TRACE_SYSTEM 2#undef TRACE_SYSTEM
3#define TRACE_SYSTEM erofs 3#define TRACE_SYSTEM erofs
4 4
@@ -6,6 +6,9 @@
6#define _TRACE_EROFS_H 6#define _TRACE_EROFS_H
7 7
8#include <linux/tracepoint.h> 8#include <linux/tracepoint.h>
9#include <linux/fs.h>
10
11struct erofs_map_blocks;
9 12
10#define show_dev(dev) MAJOR(dev), MINOR(dev) 13#define show_dev(dev) MAJOR(dev), MINOR(dev)
11#define show_dev_nid(entry) show_dev(entry->dev), entry->nid 14#define show_dev_nid(entry) show_dev(entry->dev), entry->nid
@@ -38,7 +41,7 @@ TRACE_EVENT(erofs_lookup,
38 41
39 TP_fast_assign( 42 TP_fast_assign(
40 __entry->dev = dir->i_sb->s_dev; 43 __entry->dev = dir->i_sb->s_dev;
41 __entry->nid = EROFS_V(dir)->nid; 44 __entry->nid = EROFS_I(dir)->nid;
42 __entry->name = dentry->d_name.name; 45 __entry->name = dentry->d_name.name;
43 __entry->flags = flags; 46 __entry->flags = flags;
44 ), 47 ),
@@ -63,7 +66,7 @@ TRACE_EVENT(erofs_fill_inode,
63 66
64 TP_fast_assign( 67 TP_fast_assign(
65 __entry->dev = inode->i_sb->s_dev; 68 __entry->dev = inode->i_sb->s_dev;
66 __entry->nid = EROFS_V(inode)->nid; 69 __entry->nid = EROFS_I(inode)->nid;
67 __entry->blkaddr = erofs_blknr(iloc(EROFS_I_SB(inode), __entry->nid)); 70 __entry->blkaddr = erofs_blknr(iloc(EROFS_I_SB(inode), __entry->nid));
68 __entry->ofs = erofs_blkoff(iloc(EROFS_I_SB(inode), __entry->nid)); 71 __entry->ofs = erofs_blkoff(iloc(EROFS_I_SB(inode), __entry->nid));
69 __entry->isdir = isdir; 72 __entry->isdir = isdir;
@@ -92,7 +95,7 @@ TRACE_EVENT(erofs_readpage,
92 95
93 TP_fast_assign( 96 TP_fast_assign(
94 __entry->dev = page->mapping->host->i_sb->s_dev; 97 __entry->dev = page->mapping->host->i_sb->s_dev;
95 __entry->nid = EROFS_V(page->mapping->host)->nid; 98 __entry->nid = EROFS_I(page->mapping->host)->nid;
96 __entry->dir = S_ISDIR(page->mapping->host->i_mode); 99 __entry->dir = S_ISDIR(page->mapping->host->i_mode);
97 __entry->index = page->index; 100 __entry->index = page->index;
98 __entry->uptodate = PageUptodate(page); 101 __entry->uptodate = PageUptodate(page);
@@ -125,7 +128,7 @@ TRACE_EVENT(erofs_readpages,
125 128
126 TP_fast_assign( 129 TP_fast_assign(
127 __entry->dev = inode->i_sb->s_dev; 130 __entry->dev = inode->i_sb->s_dev;
128 __entry->nid = EROFS_V(inode)->nid; 131 __entry->nid = EROFS_I(inode)->nid;
129 __entry->start = page->index; 132 __entry->start = page->index;
130 __entry->nrpage = nrpage; 133 __entry->nrpage = nrpage;
131 __entry->raw = raw; 134 __entry->raw = raw;
@@ -154,7 +157,7 @@ DECLARE_EVENT_CLASS(erofs__map_blocks_enter,
154 157
155 TP_fast_assign( 158 TP_fast_assign(
156 __entry->dev = inode->i_sb->s_dev; 159 __entry->dev = inode->i_sb->s_dev;
157 __entry->nid = EROFS_V(inode)->nid; 160 __entry->nid = EROFS_I(inode)->nid;
158 __entry->la = map->m_la; 161 __entry->la = map->m_la;
159 __entry->llen = map->m_llen; 162 __entry->llen = map->m_llen;
160 __entry->flags = flags; 163 __entry->flags = flags;
@@ -200,7 +203,7 @@ DECLARE_EVENT_CLASS(erofs__map_blocks_exit,
200 203
201 TP_fast_assign( 204 TP_fast_assign(
202 __entry->dev = inode->i_sb->s_dev; 205 __entry->dev = inode->i_sb->s_dev;
203 __entry->nid = EROFS_V(inode)->nid; 206 __entry->nid = EROFS_I(inode)->nid;
204 __entry->flags = flags; 207 __entry->flags = flags;
205 __entry->la = map->m_la; 208 __entry->la = map->m_la;
206 __entry->pa = map->m_pa; 209 __entry->pa = map->m_pa;
@@ -244,7 +247,7 @@ TRACE_EVENT(erofs_destroy_inode,
244 247
245 TP_fast_assign( 248 TP_fast_assign(
246 __entry->dev = inode->i_sb->s_dev; 249 __entry->dev = inode->i_sb->s_dev;
247 __entry->nid = EROFS_V(inode)->nid; 250 __entry->nid = EROFS_I(inode)->nid;
248 ), 251 ),
249 252
250 TP_printk("dev = (%d,%d), nid = %llu", show_dev_nid(__entry)) 253 TP_printk("dev = (%d,%d), nid = %llu", show_dev_nid(__entry))
diff --git a/include/uapi/linux/magic.h b/include/uapi/linux/magic.h
index 1274c692e59c..903cc2d2750b 100644
--- a/include/uapi/linux/magic.h
+++ b/include/uapi/linux/magic.h
@@ -19,6 +19,7 @@
19#define SQUASHFS_MAGIC 0x73717368 19#define SQUASHFS_MAGIC 0x73717368
20#define ECRYPTFS_SUPER_MAGIC 0xf15f 20#define ECRYPTFS_SUPER_MAGIC 0xf15f
21#define EFS_SUPER_MAGIC 0x414A53 21#define EFS_SUPER_MAGIC 0x414A53
22#define EROFS_SUPER_MAGIC_V1 0xE0F5E1E2
22#define EXT2_SUPER_MAGIC 0xEF53 23#define EXT2_SUPER_MAGIC 0xEF53
23#define EXT3_SUPER_MAGIC 0xEF53 24#define EXT3_SUPER_MAGIC 0xEF53
24#define XENFS_SUPER_MAGIC 0xabba1974 25#define XENFS_SUPER_MAGIC 0xabba1974
diff --git a/tools/iio/.gitignore b/tools/iio/.gitignore
new file mode 100644
index 000000000000..3758202618bd
--- /dev/null
+++ b/tools/iio/.gitignore
@@ -0,0 +1,4 @@
1iio_event_monitor
2iio_generic_buffer
3lsiio
4include/