aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-08-31 12:24:06 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-08-31 12:24:06 -0400
commit2f37d65a6a5c360ba0c386a6aa0d2afcbda7060d (patch)
treea2c0ab8b6d7fd7ea57d0140f22a79337064d761e
parent1af115d675f323afee1e64650277a9b170845b81 (diff)
parent415bcb5c6eff630967baa4e671cebe883d83ee79 (diff)
Merge tag 'staging-4.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging driver updates from Greg KH: "Here is the big staging driver updates for 4.3-rc1. Lots of things all over the place, almost all of them trivial fixups and changes. The usual IIO updates and new drivers and we have added the MOST driver subsystem which is getting cleaned up in the tree. The ozwpan driver is finally being deleted as it is obviously abandoned and no one cares about it. Full details are in the shortlog, and all of these have been in linux-next with no reported issues" * tag 'staging-4.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (912 commits) staging/lustre/o2iblnd: remove references to ib_reg_phsy_mr() staging: wilc1000: fix build warning with setup_timer() staging: wilc1000: remove DECLARE_WILC_BUFFER() staging: wilc1000: remove void function return statements that are not useful staging: wilc1000: coreconfigurator.c: fix kmalloc error check staging: wilc1000: coreconfigurator.c: use kmalloc instead of WILC_MALLOC staging: wilc1000: remove unused codes of gps8ConfigPacket staging: wilc1000: remove unnecessary void pointer cast staging: wilc1000: remove WILC_NEW and WILC_NEW_EX staging: wilc1000: use kmalloc instead of WILC_NEW staging: wilc1000: Process WARN, INFO options of debug levels from user staging: wilc1000: remove unneeded tstrWILC_MsgQueueAttrs typedef staging: wilc1000: delete wilc_osconfig.h staging: wilc1000: delete wilc_log.h staging: wilc1000: delete wilc_timer.h staging: wilc1000: remove WILC_TimerStart() staging: wilc1000: remove WILC_TimerCreate() staging: wilc1000: remove WILC_TimerDestroy() staging: wilc1000: remove WILC_TimerStop() staging: wilc1000: remove tstrWILC_TimerAttrs typedef ...
-rw-r--r--Documentation/ABI/testing/sysfs-bus-iio18
-rw-r--r--Documentation/ABI/testing/sysfs-bus-iio-trigger-sysfs9
-rw-r--r--Documentation/DocBook/Makefile2
-rw-r--r--Documentation/DocBook/iio.tmpl697
-rw-r--r--Documentation/devicetree/bindings/iio/adc/mcp320x.txt1
-rw-r--r--Documentation/devicetree/bindings/iio/adc/vf610-adc.txt5
-rw-r--r--Documentation/devicetree/bindings/iio/magnetometer/mmc35240.txt13
-rw-r--r--Documentation/devicetree/bindings/iio/st-sensors.txt2
-rw-r--r--Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt2
-rw-r--r--Documentation/fb/sm712fb.txt31
-rw-r--r--MAINTAINERS22
-rw-r--r--drivers/iio/accel/Kconfig26
-rw-r--r--drivers/iio/accel/bma180.c1
-rw-r--r--drivers/iio/accel/bmc150-accel.c243
-rw-r--r--drivers/iio/accel/kxcjk-1013.c5
-rw-r--r--drivers/iio/accel/mma8452.c217
-rw-r--r--drivers/iio/accel/mma9551_core.c35
-rw-r--r--drivers/iio/accel/mma9551_core.h6
-rw-r--r--drivers/iio/accel/mma9553.c83
-rw-r--r--drivers/iio/accel/st_accel.h1
-rw-r--r--drivers/iio/accel/st_accel_core.c6
-rw-r--r--drivers/iio/accel/st_accel_i2c.c6
-rw-r--r--drivers/iio/accel/st_accel_spi.c1
-rw-r--r--drivers/iio/accel/stk8312.c429
-rw-r--r--drivers/iio/accel/stk8ba50.c369
-rw-r--r--drivers/iio/adc/Kconfig52
-rw-r--r--drivers/iio/adc/berlin2-adc.c22
-rw-r--r--drivers/iio/adc/cc10001_adc.c26
-rw-r--r--drivers/iio/adc/mcp320x.c16
-rw-r--r--drivers/iio/adc/mcp3422.c1
-rw-r--r--drivers/iio/adc/ti-adc081c.c1
-rw-r--r--drivers/iio/adc/vf610_adc.c79
-rw-r--r--drivers/iio/common/ssp_sensors/ssp_dev.c1
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_core.c52
-rw-r--r--drivers/iio/dac/ad5064.c1
-rw-r--r--drivers/iio/dac/ad5380.c1
-rw-r--r--drivers/iio/dac/ad5446.c1
-rw-r--r--drivers/iio/dac/max5821.c1
-rw-r--r--drivers/iio/frequency/adf4350.c1
-rw-r--r--drivers/iio/gyro/Kconfig3
-rw-r--r--drivers/iio/gyro/adis16136.c6
-rw-r--r--drivers/iio/gyro/adis16260.c137
-rw-r--r--drivers/iio/gyro/itg3200_core.c1
-rw-r--r--drivers/iio/gyro/st_gyro_core.c3
-rw-r--r--drivers/iio/gyro/st_gyro_i2c.c1
-rw-r--r--drivers/iio/humidity/dht11.c65
-rw-r--r--drivers/iio/humidity/si7005.c1
-rw-r--r--drivers/iio/imu/adis16400_core.c46
-rw-r--r--drivers/iio/imu/adis16480.c39
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_core.c7
-rw-r--r--drivers/iio/imu/kmx61.c8
-rw-r--r--drivers/iio/industrialio-buffer.c35
-rw-r--r--drivers/iio/industrialio-core.c33
-rw-r--r--drivers/iio/industrialio-event.c8
-rw-r--r--drivers/iio/industrialio-trigger.c27
-rw-r--r--drivers/iio/industrialio-triggered-buffer.c12
-rw-r--r--drivers/iio/light/Kconfig34
-rw-r--r--drivers/iio/light/Makefile3
-rw-r--r--drivers/iio/light/acpi-als.c18
-rw-r--r--drivers/iio/light/apds9300.c1
-rw-r--r--drivers/iio/light/bh1750.c1
-rw-r--r--drivers/iio/light/cm32181.c2
-rw-r--r--drivers/iio/light/cm3232.c2
-rw-r--r--drivers/iio/light/cm3323.c19
-rw-r--r--drivers/iio/light/cm36651.c2
-rw-r--r--drivers/iio/light/gp2ap020a00f.c2
-rw-r--r--drivers/iio/light/hid-sensor-prox.c3
-rw-r--r--drivers/iio/light/isl29125.c13
-rw-r--r--drivers/iio/light/jsa1212.c1
-rw-r--r--drivers/iio/light/ltr501.c1
-rw-r--r--drivers/iio/light/opt3001.c804
-rw-r--r--drivers/iio/light/pa12203001.c483
-rw-r--r--drivers/iio/light/rpr0521.c615
-rw-r--r--drivers/iio/light/stk3310.c1
-rw-r--r--drivers/iio/light/tcs3414.c1
-rw-r--r--drivers/iio/light/tcs3472.c1
-rw-r--r--drivers/iio/light/tsl4531.c1
-rw-r--r--drivers/iio/light/vcnl4000.c1
-rw-r--r--drivers/iio/magnetometer/bmc150_magn.c95
-rw-r--r--drivers/iio/magnetometer/mmc35240.c33
-rw-r--r--drivers/iio/magnetometer/st_magn.h3
-rw-r--r--drivers/iio/magnetometer/st_magn_buffer.c7
-rw-r--r--drivers/iio/magnetometer/st_magn_core.c98
-rw-r--r--drivers/iio/magnetometer/st_magn_i2c.c6
-rw-r--r--drivers/iio/magnetometer/st_magn_spi.c1
-rw-r--r--drivers/iio/pressure/Kconfig6
-rw-r--r--drivers/iio/pressure/ms5611.h16
-rw-r--r--drivers/iio/pressure/ms5611_core.c82
-rw-r--r--drivers/iio/pressure/ms5611_i2c.c6
-rw-r--r--drivers/iio/pressure/ms5611_spi.c6
-rw-r--r--drivers/iio/pressure/st_pressure_core.c3
-rw-r--r--drivers/iio/pressure/st_pressure_i2c.c1
-rw-r--r--drivers/iio/temperature/mlx90614.c21
-rw-r--r--drivers/iio/temperature/tmp006.c5
-rw-r--r--drivers/staging/Kconfig6
-rw-r--r--drivers/staging/Makefile3
-rw-r--r--drivers/staging/android/Kconfig3
-rw-r--r--drivers/staging/android/TODO10
-rw-r--r--drivers/staging/android/ashmem.c4
-rw-r--r--drivers/staging/android/ion/ion.c24
-rw-r--r--drivers/staging/android/ion/ion_chunk_heap.c4
-rw-r--r--drivers/staging/android/ion/ion_cma_heap.c4
-rw-r--r--drivers/staging/android/ion/ion_page_pool.c5
-rw-r--r--drivers/staging/android/ion/ion_system_heap.c16
-rw-r--r--drivers/staging/android/sync.h10
-rw-r--r--drivers/staging/android/timed_gpio.c4
-rw-r--r--drivers/staging/comedi/Kconfig2
-rw-r--r--drivers/staging/comedi/comedi_compat32.c3
-rw-r--r--drivers/staging/comedi/comedi_fops.c35
-rw-r--r--drivers/staging/comedi/drivers.c2
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c93
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c154
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1564.c35
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_3501.c60
-rw-r--r--drivers/staging/comedi/drivers/addi_tcw.h63
-rw-r--r--drivers/staging/comedi/drivers/adl_pci7x3x.c16
-rw-r--r--drivers/staging/comedi/drivers/cb_pcimdas.c6
-rw-r--r--drivers/staging/comedi/drivers/dac02.c6
-rw-r--r--drivers/staging/comedi/drivers/das08_cs.c4
-rw-r--r--drivers/staging/comedi/drivers/das16.c3
-rw-r--r--drivers/staging/comedi/drivers/das16m1.c41
-rw-r--r--drivers/staging/comedi/drivers/dmm32at.c6
-rw-r--r--drivers/staging/comedi/drivers/fl512.c6
-rw-r--r--drivers/staging/comedi/drivers/me4000.c1000
-rw-r--r--drivers/staging/comedi/drivers/ni_daq_dio24.c6
-rw-r--r--drivers/staging/comedi/drivers/ni_usb6501.c27
-rw-r--r--drivers/staging/comedi/drivers/pcl816.c2
-rw-r--r--drivers/staging/comedi/drivers/s626.c6
-rw-r--r--drivers/staging/comedi/drivers/serial2002.c10
-rw-r--r--drivers/staging/comedi/drivers/usbduxsigma.c214
-rw-r--r--drivers/staging/comedi/range.c13
-rw-r--r--drivers/staging/dgap/dgap.c45
-rw-r--r--drivers/staging/dgnc/dgnc_driver.h6
-rw-r--r--drivers/staging/dgnc/dgnc_sysfs.h16
-rw-r--r--drivers/staging/fbtft/Kconfig9
-rw-r--r--drivers/staging/fbtft/Makefile1
-rw-r--r--drivers/staging/fbtft/fb_uc1611.c350
-rw-r--r--drivers/staging/fbtft/fbtft-core.c17
-rw-r--r--drivers/staging/fbtft/fbtft.h57
-rw-r--r--drivers/staging/fbtft/fbtft_device.c31
-rw-r--r--drivers/staging/fbtft/flexfb.c258
-rw-r--r--drivers/staging/fsl-mc/README.txt364
-rw-r--r--drivers/staging/fsl-mc/TODO28
-rw-r--r--drivers/staging/ft1000/ft1000-pcmcia/ft1000.h19
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_debug.c31
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_download.c24
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_hw.c1
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_usb.h4
-rw-r--r--drivers/staging/gdm72xx/usb_ids.h6
-rw-r--r--drivers/staging/iio/adc/mxs-lradc.c122
-rw-r--r--drivers/staging/iio/addac/adt7316-i2c.c1
-rw-r--r--drivers/staging/iio/iio_dummy_evgen.c1
-rw-r--r--drivers/staging/iio/iio_simple_dummy.c2
-rw-r--r--drivers/staging/iio/iio_simple_dummy.h1
-rw-r--r--drivers/staging/iio/iio_simple_dummy_buffer.c2
-rw-r--r--drivers/staging/iio/iio_simple_dummy_events.c4
-rw-r--r--drivers/staging/iio/light/isl29018.c1
-rw-r--r--drivers/staging/iio/light/isl29028.c1
-rw-r--r--drivers/staging/iio/meter/ade7854.h4
-rw-r--r--drivers/staging/iio/trigger/iio-trig-bfin-timer.c7
-rw-r--r--drivers/staging/iio/trigger/iio-trig-periodic-rtc.c5
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs.h15
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h1
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h18
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_private.h28
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_string.h2
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c265
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h146
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c58
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c6
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c5
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h142
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c3
-rw-r--r--drivers/staging/lustre/lnet/lnet/router_proc.c11
-rw-r--r--drivers/staging/lustre/lnet/selftest/console.h90
-rw-r--r--drivers/staging/lustre/lnet/selftest/framework.c12
-rw-r--r--drivers/staging/lustre/lustre/fid/fid_request.c4
-rw-r--r--drivers/staging/lustre/lustre/fld/fld_cache.c2
-rw-r--r--drivers/staging/lustre/lustre/fld/fld_request.c2
-rw-r--r--drivers/staging/lustre/lustre/include/linux/lustre_compat25.h119
-rw-r--r--drivers/staging/lustre/lustre/include/linux/lustre_patchless_compat.h12
-rw-r--r--drivers/staging/lustre/lustre/include/lprocfs_status.h313
-rw-r--r--drivers/staging/lustre/lustre/include/lustre/lustre_idl.h133
-rw-r--r--drivers/staging/lustre/lustre/include/lustre/lustre_user.h2
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_dlm.h2
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_export.h4
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_import.h4
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_net.h18
-rw-r--r--drivers/staging/lustre/lustre/include/obd.h2
-rw-r--r--drivers/staging/lustre/lustre/include/obd_class.h17
-rw-r--r--drivers/staging/lustre/lustre/include/obd_support.h22
-rw-r--r--drivers/staging/lustre/lustre/lclient/lcommon_cl.c2
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_internal.h2
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_lib.c3
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_lock.c4
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c17
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_pool.c8
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_resource.c1
-rw-r--r--drivers/staging/lustre/lustre/libcfs/debug.c149
-rw-r--r--drivers/staging/lustre/lustre/libcfs/fail.c2
-rw-r--r--drivers/staging/lustre/lustre/libcfs/libcfs_cpu.c2
-rw-r--r--drivers/staging/lustre/lustre/libcfs/libcfs_string.c4
-rw-r--r--drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c4
-rw-r--r--drivers/staging/lustre/lustre/libcfs/linux/linux-module.c6
-rw-r--r--drivers/staging/lustre/lustre/libcfs/module.c357
-rw-r--r--drivers/staging/lustre/lustre/libcfs/tracefile.c12
-rw-r--r--drivers/staging/lustre/lustre/libcfs/tracefile.h33
-rw-r--r--drivers/staging/lustre/lustre/llite/dcache.c3
-rw-r--r--drivers/staging/lustre/lustre/llite/dir.c4
-rw-r--r--drivers/staging/lustre/lustre/llite/file.c5
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_capa.c40
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_internal.h17
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_lib.c23
-rw-r--r--drivers/staging/lustre/lustre/llite/lloop.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/namei.c12
-rw-r--r--drivers/staging/lustre/lustre/llite/remote_perm.c17
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_io.c5
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_page.c27
-rw-r--r--drivers/staging/lustre/lustre/llite/xattr_cache.c2
-rw-r--r--drivers/staging/lustre/lustre/lmv/lmv_intent.c2
-rw-r--r--drivers/staging/lustre/lustre/lmv/lmv_obd.c8
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_dev.c2
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_io.c2
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_merge.c1
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_obd.c13
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_pool.c2
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_request.c18
-rw-r--r--drivers/staging/lustre/lustre/mdc/mdc_lib.c2
-rw-r--r--drivers/staging/lustre/lustre/mdc/mdc_request.c6
-rw-r--r--drivers/staging/lustre/lustre/mgc/mgc_request.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/acl.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/cl_page.c30
-rw-r--r--drivers/staging/lustre/lustre/obdclass/class_obd.c19
-rw-r--r--drivers/staging/lustre/lustre/obdclass/genops.c22
-rw-r--r--drivers/staging/lustre/lustre/obdclass/linux/linux-module.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c374
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog.c8
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lprocfs_status.c4
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lu_object.c8
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lustre_peer.c2
-rw-r--r--drivers/staging/lustre/lustre/obdclass/obd_config.c17
-rw-r--r--drivers/staging/lustre/lustre/obdclass/obd_mount.c24
-rw-r--r--drivers/staging/lustre/lustre/obdclass/uuid.c34
-rw-r--r--drivers/staging/lustre/lustre/obdecho/echo_client.c14
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_cache.c6
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_dev.c2
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_page.c2
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_request.c8
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/client.c2
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/events.c4
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/import.c6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c8
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/nrs.c2
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/pack_generic.c2
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/pinger.c2
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c2
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c2
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c2
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/sec_config.c2
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/sec_plain.c2
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/service.c18
-rw-r--r--drivers/staging/lustre/sysfs-fs-lustre103
-rw-r--r--drivers/staging/most/Documentation/ABI/sysfs-class-most.txt181
-rw-r--r--drivers/staging/most/Documentation/driver_usage.txt180
-rw-r--r--drivers/staging/most/Kconfig30
-rw-r--r--drivers/staging/most/Makefile8
-rw-r--r--drivers/staging/most/TODO8
-rw-r--r--drivers/staging/most/aim-cdev/Kconfig12
-rw-r--r--drivers/staging/most/aim-cdev/Makefile4
-rw-r--r--drivers/staging/most/aim-cdev/cdev.c528
-rw-r--r--drivers/staging/most/aim-network/Kconfig13
-rw-r--r--drivers/staging/most/aim-network/Makefile4
-rw-r--r--drivers/staging/most/aim-network/networking.c567
-rw-r--r--drivers/staging/most/aim-network/networking.h23
-rw-r--r--drivers/staging/most/aim-sound/Kconfig13
-rw-r--r--drivers/staging/most/aim-sound/Makefile4
-rw-r--r--drivers/staging/most/aim-sound/sound.c758
-rw-r--r--drivers/staging/most/aim-v4l2/Kconfig12
-rw-r--r--drivers/staging/most/aim-v4l2/Makefile6
-rw-r--r--drivers/staging/most/aim-v4l2/video.c635
-rw-r--r--drivers/staging/most/hdm-dim2/Kconfig16
-rw-r--r--drivers/staging/most/hdm-dim2/Makefile5
-rw-r--r--drivers/staging/most/hdm-dim2/dim2_errors.h67
-rw-r--r--drivers/staging/most/hdm-dim2/dim2_hal.c919
-rw-r--r--drivers/staging/most/hdm-dim2/dim2_hal.h124
-rw-r--r--drivers/staging/most/hdm-dim2/dim2_hdm.c964
-rw-r--r--drivers/staging/most/hdm-dim2/dim2_hdm.h26
-rw-r--r--drivers/staging/most/hdm-dim2/dim2_reg.h176
-rw-r--r--drivers/staging/most/hdm-dim2/dim2_sysfs.c116
-rw-r--r--drivers/staging/most/hdm-dim2/dim2_sysfs.h39
-rw-r--r--drivers/staging/most/hdm-i2c/Kconfig12
-rw-r--r--drivers/staging/most/hdm-i2c/Makefile3
-rw-r--r--drivers/staging/most/hdm-i2c/hdm_i2c.c451
-rw-r--r--drivers/staging/most/hdm-usb/Kconfig14
-rw-r--r--drivers/staging/most/hdm-usb/Makefile4
-rw-r--r--drivers/staging/most/hdm-usb/hdm_usb.c1454
-rw-r--r--drivers/staging/most/mostcore/Kconfig13
-rw-r--r--drivers/staging/most/mostcore/Makefile3
-rw-r--r--drivers/staging/most/mostcore/core.c1932
-rw-r--r--drivers/staging/most/mostcore/mostcore.h316
-rw-r--r--drivers/staging/mt29f_spinand/mt29f_spinand.c1
-rw-r--r--drivers/staging/mt29f_spinand/mt29f_spinand.h4
-rw-r--r--drivers/staging/netlogic/platform_net.c2
-rw-r--r--drivers/staging/netlogic/xlr_net.h2
-rw-r--r--drivers/staging/nvec/nvec.h19
-rw-r--r--drivers/staging/octeon/ethernet-mdio.h2
-rw-r--r--drivers/staging/octeon/ethernet-rgmii.c7
-rw-r--r--drivers/staging/octeon/ethernet-tx.c10
-rw-r--r--drivers/staging/octeon/ethernet.c1
-rw-r--r--drivers/staging/octeon/octeon-ethernet.h22
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon.h2
-rw-r--r--drivers/staging/ozwpan/Kconfig9
-rw-r--r--drivers/staging/ozwpan/Makefile16
-rw-r--r--drivers/staging/ozwpan/README25
-rw-r--r--drivers/staging/ozwpan/TODO14
-rw-r--r--drivers/staging/ozwpan/ozappif.h36
-rw-r--r--drivers/staging/ozwpan/ozcdev.c554
-rw-r--r--drivers/staging/ozwpan/ozcdev.h17
-rw-r--r--drivers/staging/ozwpan/ozdbg.h54
-rw-r--r--drivers/staging/ozwpan/ozeltbuf.c252
-rw-r--r--drivers/staging/ozwpan/ozeltbuf.h65
-rw-r--r--drivers/staging/ozwpan/ozhcd.c2301
-rw-r--r--drivers/staging/ozwpan/ozhcd.h15
-rw-r--r--drivers/staging/ozwpan/ozmain.c71
-rw-r--r--drivers/staging/ozwpan/ozpd.c886
-rw-r--r--drivers/staging/ozwpan/ozpd.h134
-rw-r--r--drivers/staging/ozwpan/ozproto.c813
-rw-r--r--drivers/staging/ozwpan/ozproto.h62
-rw-r--r--drivers/staging/ozwpan/ozprotocol.h375
-rw-r--r--drivers/staging/ozwpan/ozurbparanoia.c54
-rw-r--r--drivers/staging/ozwpan/ozurbparanoia.h19
-rw-r--r--drivers/staging/ozwpan/ozusbif.h43
-rw-r--r--drivers/staging/ozwpan/ozusbsvc.c263
-rw-r--r--drivers/staging/ozwpan/ozusbsvc.h32
-rw-r--r--drivers/staging/ozwpan/ozusbsvc1.c471
-rw-r--r--drivers/staging/panel/panel.c12
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_ap.c5
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_debug.c6
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_efuse.c2
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_ieee80211.c4
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_ioctl_set.c10
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_mlme.c43
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_mlme_ext.c10
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_pwrctrl.c8
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_recv.c44
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_security.c2
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_wlan_util.c2
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_xmit.c36
-rw-r--r--drivers/staging/rtl8188eu/hal/Hal8188ERateAdaptive.c8
-rw-r--r--drivers/staging/rtl8188eu/hal/bb_cfg.c6
-rw-r--r--drivers/staging/rtl8188eu/hal/hal_com.c27
-rw-r--r--drivers/staging/rtl8188eu/hal/hal_intf.c32
-rw-r--r--drivers/staging/rtl8188eu/hal/odm.c11
-rw-r--r--drivers/staging/rtl8188eu/hal/rf.c2
-rw-r--r--drivers/staging/rtl8188eu/hal/rf_cfg.c2
-rw-r--r--drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c21
-rw-r--r--drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c33
-rw-r--r--drivers/staging/rtl8188eu/hal/usb_halinit.c99
-rw-r--r--drivers/staging/rtl8188eu/include/HalVerDef.h84
-rw-r--r--drivers/staging/rtl8188eu/include/hal_intf.h16
-rw-r--r--drivers/staging/rtl8188eu/include/ieee80211.h54
-rw-r--r--drivers/staging/rtl8188eu/include/osdep_service.h2
-rw-r--r--drivers/staging/rtl8188eu/include/recv_osdep.h3
-rw-r--r--drivers/staging/rtl8188eu/include/rtl8188e_cmd.h1
-rw-r--r--drivers/staging/rtl8188eu/include/rtl8188e_hal.h8
-rw-r--r--drivers/staging/rtl8188eu/include/rtw_mlme.h3
-rw-r--r--drivers/staging/rtl8188eu/include/rtw_mlme_ext.h8
-rw-r--r--drivers/staging/rtl8188eu/include/rtw_pwrctrl.h1
-rw-r--r--drivers/staging/rtl8188eu/include/sta_info.h19
-rw-r--r--drivers/staging/rtl8188eu/include/wifi.h7
-rw-r--r--drivers/staging/rtl8188eu/os_dep/ioctl_linux.c22
-rw-r--r--drivers/staging/rtl8188eu/os_dep/os_intfs.c2
-rw-r--r--drivers/staging/rtl8188eu/os_dep/recv_linux.c16
-rw-r--r--drivers/staging/rtl8188eu/os_dep/usb_intf.c79
-rw-r--r--drivers/staging/rtl8192e/dot11d.c39
-rw-r--r--drivers/staging/rtl8192e/dot11d.h6
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8190P_def.h46
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8190P_rtl8256.c192
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8190P_rtl8256.h11
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.c11
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.h5
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c440
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8192E_dev.h58
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c20
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.h6
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8192E_hw.h8
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c448
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8192E_phy.h66
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_cam.c125
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_cam.h16
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_core.c615
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_core.h112
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_dm.c472
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_dm.h44
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_eeprom.c130
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_eeprom.h2
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_pci.c2
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_pci.h2
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_pm.c24
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_pm.h4
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_ps.c53
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_ps.h19
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_wx.c132
-rw-r--r--drivers/staging/rtl8192e/rtl819x_BA.h5
-rw-r--r--drivers/staging/rtl8192e/rtl819x_BAProc.c5
-rw-r--r--drivers/staging/rtl8192e/rtl819x_HT.h2
-rw-r--r--drivers/staging/rtl8192e/rtl819x_HTProc.c5
-rw-r--r--drivers/staging/rtl8192e/rtl819x_Qos.h5
-rw-r--r--drivers/staging/rtl8192e/rtl819x_TS.h2
-rw-r--r--drivers/staging/rtl8192e/rtl819x_TSProc.c2
-rw-r--r--drivers/staging/rtl8192e/rtllib.h439
-rw-r--r--drivers/staging/rtl8192e/rtllib_debug.h8
-rw-r--r--drivers/staging/rtl8192e/rtllib_rx.c91
-rw-r--r--drivers/staging/rtl8192e/rtllib_softmac.c30
-rw-r--r--drivers/staging/rtl8192e/rtllib_tx.c9
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211.h345
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c4
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c6
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c2
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c4
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c17
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c16
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c4
-rw-r--r--drivers/staging/rtl8192u/r8190_rtl8256.h11
-rw-r--r--drivers/staging/rtl8192u/r8192U.h2
-rw-r--r--drivers/staging/rtl8192u/r8192U_core.c14
-rw-r--r--drivers/staging/rtl8192u/r8192U_dm.c8
-rw-r--r--drivers/staging/rtl8192u/r8192U_dm.h36
-rw-r--r--drivers/staging/rtl8192u/r8192U_wx.h2
-rw-r--r--drivers/staging/rtl8192u/r819xU_cmdpkt.h8
-rw-r--r--drivers/staging/rtl8192u/r819xU_firmware.c15
-rw-r--r--drivers/staging/rtl8192u/r819xU_phy.h55
-rw-r--r--drivers/staging/rtl8712/ieee80211.c25
-rw-r--r--drivers/staging/rtl8712/rtl8712_recv.c4
-rw-r--r--drivers/staging/rtl8712/rtl871x_cmd.c28
-rw-r--r--drivers/staging/rtl8712/rtl871x_cmd.h18
-rw-r--r--drivers/staging/rtl8712/rtl871x_event.h2
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl.h28
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_linux.c34
-rw-r--r--drivers/staging/rtl8712/rtl871x_mlme.c47
-rw-r--r--drivers/staging/rtl8712/rtl871x_mlme.h2
-rw-r--r--drivers/staging/rtl8712/rtl871x_mp_ioctl.c6
-rw-r--r--drivers/staging/rtl8712/rtl871x_security.c35
-rw-r--r--drivers/staging/rtl8712/wlan_bssdef.h42
-rw-r--r--drivers/staging/rtl8723au/core/rtw_recv.c3
-rw-r--r--drivers/staging/rtl8723au/core/rtw_security.c24
-rw-r--r--drivers/staging/rtl8723au/hal/odm.c2
-rw-r--r--drivers/staging/rtl8723au/hal/odm_RegConfig8723A.c2
-rw-r--r--drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c4
-rw-r--r--drivers/staging/rts5208/ms.c5
-rw-r--r--drivers/staging/rts5208/sd.c21
-rw-r--r--drivers/staging/slicoss/slicoss.c1
-rw-r--r--drivers/staging/sm750fb/ddk750_chip.c15
-rw-r--r--drivers/staging/sm750fb/ddk750_chip.h12
-rw-r--r--drivers/staging/sm750fb/ddk750_display.c170
-rw-r--r--drivers/staging/sm750fb/ddk750_display.h11
-rw-r--r--drivers/staging/sm750fb/ddk750_dvi.c75
-rw-r--r--drivers/staging/sm750fb/ddk750_dvi.h3
-rw-r--r--drivers/staging/sm750fb/ddk750_help.c8
-rw-r--r--drivers/staging/sm750fb/ddk750_help.h4
-rw-r--r--drivers/staging/sm750fb/ddk750_hwi2c.c244
-rw-r--r--drivers/staging/sm750fb/ddk750_mode.c164
-rw-r--r--drivers/staging/sm750fb/ddk750_mode.h52
-rw-r--r--drivers/staging/sm750fb/ddk750_power.c261
-rw-r--r--drivers/staging/sm750fb/ddk750_power.h11
-rw-r--r--drivers/staging/sm750fb/ddk750_reg.h18
-rw-r--r--drivers/staging/sm750fb/ddk750_sii164.c389
-rw-r--r--drivers/staging/sm750fb/ddk750_sii164.h31
-rw-r--r--drivers/staging/sm750fb/sm750.c160
-rw-r--r--drivers/staging/sm750fb/sm750.h72
-rw-r--r--drivers/staging/sm750fb/sm750_accel.c381
-rw-r--r--drivers/staging/sm750fb/sm750_accel.h4
-rw-r--r--drivers/staging/sm750fb/sm750_cursor.c55
-rw-r--r--drivers/staging/sm750fb/sm750_cursor.h4
-rw-r--r--drivers/staging/sm750fb/sm750_help.h28
-rw-r--r--drivers/staging/sm750fb/sm750_hw.c414
-rw-r--r--drivers/staging/sm750fb/sm750_hw.h48
-rw-r--r--drivers/staging/sm7xxfb/Kconfig13
-rw-r--r--drivers/staging/sm7xxfb/Makefile1
-rw-r--r--drivers/staging/sm7xxfb/TODO12
-rw-r--r--drivers/staging/speakup/buffers.c3
-rw-r--r--drivers/staging/speakup/i18n.c3
-rw-r--r--drivers/staging/speakup/i18n.h12
-rw-r--r--drivers/staging/speakup/keyhelp.c2
-rw-r--r--drivers/staging/speakup/kobjects.c3
-rw-r--r--drivers/staging/speakup/main.c15
-rw-r--r--drivers/staging/speakup/selection.c3
-rw-r--r--drivers/staging/speakup/serialio.c10
-rw-r--r--drivers/staging/speakup/speakup.h68
-rw-r--r--drivers/staging/speakup/speakup_acnt.h8
-rw-r--r--drivers/staging/speakup/speakup_decpc.c6
-rw-r--r--drivers/staging/speakup/speakup_dtlk.h52
-rw-r--r--drivers/staging/speakup/speakup_soft.c1
-rw-r--r--drivers/staging/speakup/thread.c3
-rw-r--r--drivers/staging/speakup/varhandlers.c3
-rw-r--r--drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c1
-rw-r--r--drivers/staging/unisys/Kconfig2
-rw-r--r--drivers/staging/unisys/include/channel_guid.h24
-rw-r--r--drivers/staging/unisys/include/visorbus.h5
-rw-r--r--drivers/staging/unisys/visorbus/controlvmchannel.h9
-rw-r--r--drivers/staging/unisys/visorbus/controlvmcompletionstatus.h9
-rw-r--r--drivers/staging/unisys/visorbus/iovmcall_gnuc.h9
-rw-r--r--drivers/staging/unisys/visorbus/periodic_work.c9
-rw-r--r--drivers/staging/unisys/visorbus/vbuschannel.h9
-rw-r--r--drivers/staging/unisys/visorbus/vbusdeviceinfo.h9
-rw-r--r--drivers/staging/unisys/visorbus/visorbus_main.c109
-rw-r--r--drivers/staging/unisys/visorbus/visorbus_private.h9
-rw-r--r--drivers/staging/unisys/visorbus/visorchannel.c43
-rw-r--r--drivers/staging/unisys/visorbus/visorchipset.c22
-rw-r--r--drivers/staging/unisys/visorbus/vmcallinterface.h9
-rw-r--r--drivers/staging/unisys/visornic/visornic_main.c1122
-rw-r--r--drivers/staging/vme/devices/vme_pio2_core.c18
-rw-r--r--drivers/staging/vme/devices/vme_user.c168
-rw-r--r--drivers/staging/vt6655/baseband.c6
-rw-r--r--drivers/staging/vt6655/card.c15
-rw-r--r--drivers/staging/vt6655/desc.h146
-rw-r--r--drivers/staging/vt6655/device.h13
-rw-r--r--drivers/staging/vt6655/device_cfg.h15
-rw-r--r--drivers/staging/vt6655/device_main.c146
-rw-r--r--drivers/staging/vt6655/dpc.c2
-rw-r--r--drivers/staging/vt6655/mac.c18
-rw-r--r--drivers/staging/vt6655/power.c16
-rw-r--r--drivers/staging/vt6655/rf.c532
-rw-r--r--drivers/staging/vt6655/rf.h24
-rw-r--r--drivers/staging/vt6655/rxtx.c23
-rw-r--r--drivers/staging/vt6655/rxtx.h4
-rw-r--r--drivers/staging/vt6655/upc.h36
-rw-r--r--drivers/staging/vt6656/rxtx.c7
-rw-r--r--drivers/staging/wilc1000/Kconfig28
-rw-r--r--drivers/staging/wilc1000/Makefile8
-rw-r--r--drivers/staging/wilc1000/coreconfigsimulator.h17
-rw-r--r--drivers/staging/wilc1000/coreconfigurator.c225
-rw-r--r--drivers/staging/wilc1000/coreconfigurator.h37
-rw-r--r--drivers/staging/wilc1000/fifo_buffer.c133
-rw-r--r--drivers/staging/wilc1000/fifo_buffer.h26
-rw-r--r--drivers/staging/wilc1000/host_interface.c1433
-rw-r--r--drivers/staging/wilc1000/host_interface.h115
-rw-r--r--drivers/staging/wilc1000/linux_mon.c23
-rw-r--r--drivers/staging/wilc1000/linux_wlan.c248
-rw-r--r--drivers/staging/wilc1000/linux_wlan_common.h4
-rw-r--r--drivers/staging/wilc1000/linux_wlan_sdio.c1
-rw-r--r--drivers/staging/wilc1000/wilc_debugfs.c30
-rw-r--r--drivers/staging/wilc1000/wilc_exported_buf.c13
-rw-r--r--drivers/staging/wilc1000/wilc_log.h47
-rw-r--r--drivers/staging/wilc1000/wilc_memory.c46
-rw-r--r--drivers/staging/wilc1000/wilc_memory.h173
-rw-r--r--drivers/staging/wilc1000/wilc_msgqueue.c28
-rw-r--r--drivers/staging/wilc1000/wilc_msgqueue.h35
-rw-r--r--drivers/staging/wilc1000/wilc_osconfig.h9
-rw-r--r--drivers/staging/wilc1000/wilc_oswrapper.h12
-rw-r--r--drivers/staging/wilc1000/wilc_platform.h8
-rw-r--r--drivers/staging/wilc1000/wilc_sdio.c288
-rw-r--r--drivers/staging/wilc1000/wilc_sleep.c18
-rw-r--r--drivers/staging/wilc1000/wilc_sleep.h20
-rw-r--r--drivers/staging/wilc1000/wilc_spi.c15
-rw-r--r--drivers/staging/wilc1000/wilc_strutils.c80
-rw-r--r--drivers/staging/wilc1000/wilc_strutils.h134
-rw-r--r--drivers/staging/wilc1000/wilc_timer.c45
-rw-r--r--drivers/staging/wilc1000/wilc_timer.h129
-rw-r--r--drivers/staging/wilc1000/wilc_type.h34
-rw-r--r--drivers/staging/wilc1000/wilc_wfi_cfgoperations.c321
-rw-r--r--drivers/staging/wilc1000/wilc_wfi_cfgoperations.h2
-rw-r--r--drivers/staging/wilc1000/wilc_wfi_netdevice.c951
-rw-r--r--drivers/staging/wilc1000/wilc_wfi_netdevice.h16
-rw-r--r--drivers/staging/wilc1000/wilc_wlan.c53
-rw-r--r--drivers/staging/wilc1000/wilc_wlan.h2
-rw-r--r--drivers/staging/wilc1000/wilc_wlan_cfg.c16
-rw-r--r--drivers/staging/wilc1000/wilc_wlan_if.h6
-rw-r--r--drivers/staging/xgifb/Makefile2
-rw-r--r--drivers/staging/xgifb/XGI_main_26.c12
-rw-r--r--drivers/staging/xgifb/vb_init.h4
-rw-r--r--drivers/staging/xgifb/vb_setmode.h34
-rw-r--r--drivers/staging/xgifb/vb_util.c42
-rw-r--r--drivers/staging/xgifb/vb_util.h44
-rw-r--r--drivers/video/fbdev/Kconfig14
-rw-r--r--drivers/video/fbdev/Makefile1
-rw-r--r--drivers/video/fbdev/sm712.h (renamed from drivers/staging/sm7xxfb/sm7xx.h)39
-rw-r--r--drivers/video/fbdev/sm712fb.c (renamed from drivers/staging/sm7xxfb/sm7xxfb.c)71
-rw-r--r--include/linux/iio/common/st_sensors.h2
-rw-r--r--include/linux/iio/consumer.h2
-rw-r--r--include/linux/iio/iio.h17
-rw-r--r--include/linux/iio/sysfs.h3
-rw-r--r--include/linux/iio/trigger.h3
-rw-r--r--include/linux/iio/triggered_buffer.h4
-rw-r--r--tools/iio/generic_buffer.c115
-rw-r--r--tools/iio/iio_event_monitor.c40
-rw-r--r--tools/iio/iio_utils.c243
-rw-r--r--tools/iio/iio_utils.h19
-rw-r--r--tools/iio/lsiio.c55
589 files changed, 23657 insertions, 20684 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index 70c9b1ac66db..42d360fe66a5 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -413,6 +413,11 @@ Description:
413 to compute the calories burnt by the user. 413 to compute the calories burnt by the user.
414 414
415What: /sys/bus/iio/devices/iio:deviceX/in_accel_scale_available 415What: /sys/bus/iio/devices/iio:deviceX/in_accel_scale_available
416What: /sys/.../iio:deviceX/in_anglvel_scale_available
417What: /sys/.../iio:deviceX/in_magn_scale_available
418What: /sys/.../iio:deviceX/in_illuminance_scale_available
419What: /sys/.../iio:deviceX/in_intensity_scale_available
420What: /sys/.../iio:deviceX/in_proximity_scale_available
416What: /sys/.../iio:deviceX/in_voltageX_scale_available 421What: /sys/.../iio:deviceX/in_voltageX_scale_available
417What: /sys/.../iio:deviceX/in_voltage-voltage_scale_available 422What: /sys/.../iio:deviceX/in_voltage-voltage_scale_available
418What: /sys/.../iio:deviceX/out_voltageX_scale_available 423What: /sys/.../iio:deviceX/out_voltageX_scale_available
@@ -488,7 +493,7 @@ Contact: linux-iio@vger.kernel.org
488Description: 493Description:
489 Specifies the output powerdown mode. 494 Specifies the output powerdown mode.
490 DAC output stage is disconnected from the amplifier and 495 DAC output stage is disconnected from the amplifier and
491 1kohm_to_gnd: connected to ground via an 1kOhm resistor, 496 1kohm_to_gnd: connected to ground via an 1kOhm resistor,
492 6kohm_to_gnd: connected to ground via a 6kOhm resistor, 497 6kohm_to_gnd: connected to ground via a 6kOhm resistor,
493 20kohm_to_gnd: connected to ground via a 20kOhm resistor, 498 20kohm_to_gnd: connected to ground via a 20kOhm resistor,
494 100kohm_to_gnd: connected to ground via an 100kOhm resistor, 499 100kohm_to_gnd: connected to ground via an 100kOhm resistor,
@@ -498,9 +503,9 @@ Description:
498 outX_powerdown_mode_available. If Y is not present the 503 outX_powerdown_mode_available. If Y is not present the
499 mode is shared across all outputs. 504 mode is shared across all outputs.
500 505
501What: /sys/.../iio:deviceX/out_votlageY_powerdown_mode_available 506What: /sys/.../iio:deviceX/out_voltageY_powerdown_mode_available
502What: /sys/.../iio:deviceX/out_voltage_powerdown_mode_available 507What: /sys/.../iio:deviceX/out_voltage_powerdown_mode_available
503What: /sys/.../iio:deviceX/out_altvotlageY_powerdown_mode_available 508What: /sys/.../iio:deviceX/out_altvoltageY_powerdown_mode_available
504What: /sys/.../iio:deviceX/out_altvoltage_powerdown_mode_available 509What: /sys/.../iio:deviceX/out_altvoltage_powerdown_mode_available
505KernelVersion: 2.6.38 510KernelVersion: 2.6.38
506Contact: linux-iio@vger.kernel.org 511Contact: linux-iio@vger.kernel.org
@@ -1035,13 +1040,6 @@ Contact: linux-iio@vger.kernel.org
1035Description: 1040Description:
1036 Number of scans contained by the buffer. 1041 Number of scans contained by the buffer.
1037 1042
1038What: /sys/bus/iio/devices/iio:deviceX/buffer/bytes_per_datum
1039KernelVersion: 2.6.37
1040Contact: linux-iio@vger.kernel.org
1041Description:
1042 Bytes per scan. Due to alignment fun, the scan may be larger
1043 than implied directly by the scan_element parameters.
1044
1045What: /sys/bus/iio/devices/iio:deviceX/buffer/enable 1043What: /sys/bus/iio/devices/iio:deviceX/buffer/enable
1046KernelVersion: 2.6.35 1044KernelVersion: 2.6.35
1047Contact: linux-iio@vger.kernel.org 1045Contact: linux-iio@vger.kernel.org
diff --git a/Documentation/ABI/testing/sysfs-bus-iio-trigger-sysfs b/Documentation/ABI/testing/sysfs-bus-iio-trigger-sysfs
index 5235e6c749ab..bbb039237a25 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio-trigger-sysfs
+++ b/Documentation/ABI/testing/sysfs-bus-iio-trigger-sysfs
@@ -9,3 +9,12 @@ Description:
9 automated testing or in situations, where other trigger methods 9 automated testing or in situations, where other trigger methods
10 are not applicable. For example no RTC or spare GPIOs. 10 are not applicable. For example no RTC or spare GPIOs.
11 X is the IIO index of the trigger. 11 X is the IIO index of the trigger.
12
13What: /sys/bus/iio/devices/triggerX/name
14KernelVersion: 2.6.39
15Contact: linux-iio@vger.kernel.org
16Description:
17 The name attribute holds a description string for the current
18 trigger. In order to associate the trigger with an IIO device
19 one should write this name string to
20 /sys/bus/iio/devices/iio:deviceY/trigger/current_trigger.
diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile
index b6a6a2e0dd3b..9e086067b4ae 100644
--- a/Documentation/DocBook/Makefile
+++ b/Documentation/DocBook/Makefile
@@ -15,7 +15,7 @@ DOCBOOKS := z8530book.xml device-drivers.xml \
15 80211.xml debugobjects.xml sh.xml regulator.xml \ 15 80211.xml debugobjects.xml sh.xml regulator.xml \
16 alsa-driver-api.xml writing-an-alsa-driver.xml \ 16 alsa-driver-api.xml writing-an-alsa-driver.xml \
17 tracepoint.xml drm.xml media_api.xml w1.xml \ 17 tracepoint.xml drm.xml media_api.xml w1.xml \
18 writing_musb_glue_layer.xml crypto-API.xml 18 writing_musb_glue_layer.xml crypto-API.xml iio.xml
19 19
20include Documentation/DocBook/media/Makefile 20include Documentation/DocBook/media/Makefile
21 21
diff --git a/Documentation/DocBook/iio.tmpl b/Documentation/DocBook/iio.tmpl
new file mode 100644
index 000000000000..06bb53de5a47
--- /dev/null
+++ b/Documentation/DocBook/iio.tmpl
@@ -0,0 +1,697 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
4
5<book id="iioid">
6 <bookinfo>
7 <title>Industrial I/O driver developer's guide </title>
8
9 <authorgroup>
10 <author>
11 <firstname>Daniel</firstname>
12 <surname>Baluta</surname>
13 <affiliation>
14 <address>
15 <email>daniel.baluta@intel.com</email>
16 </address>
17 </affiliation>
18 </author>
19 </authorgroup>
20
21 <copyright>
22 <year>2015</year>
23 <holder>Intel Corporation</holder>
24 </copyright>
25
26 <legalnotice>
27 <para>
28 This documentation is free software; you can redistribute
29 it and/or modify it under the terms of the GNU General Public
30 License version 2.
31 </para>
32 </legalnotice>
33 </bookinfo>
34
35 <toc></toc>
36
37 <chapter id="intro">
38 <title>Introduction</title>
39 <para>
40 The main purpose of the Industrial I/O subsystem (IIO) is to provide
41 support for devices that in some sense perform either analog-to-digital
42 conversion (ADC) or digital-to-analog conversion (DAC) or both. The aim
43 is to fill the gap between the somewhat similar hwmon and input
44 subsystems.
45 Hwmon is directed at low sample rate sensors used to monitor and
46 control the system itself, like fan speed control or temperature
47 measurement. Input is, as its name suggests, focused on human interaction
48 input devices (keyboard, mouse, touchscreen). In some cases there is
49 considerable overlap between these and IIO.
50 </para>
51 <para>
52 Devices that fall into this category include:
53 <itemizedlist>
54 <listitem>
55 analog to digital converters (ADCs)
56 </listitem>
57 <listitem>
58 accelerometers
59 </listitem>
60 <listitem>
61 capacitance to digital converters (CDCs)
62 </listitem>
63 <listitem>
64 digital to analog converters (DACs)
65 </listitem>
66 <listitem>
67 gyroscopes
68 </listitem>
69 <listitem>
70 inertial measurement units (IMUs)
71 </listitem>
72 <listitem>
73 color and light sensors
74 </listitem>
75 <listitem>
76 magnetometers
77 </listitem>
78 <listitem>
79 pressure sensors
80 </listitem>
81 <listitem>
82 proximity sensors
83 </listitem>
84 <listitem>
85 temperature sensors
86 </listitem>
87 </itemizedlist>
88 Usually these sensors are connected via SPI or I2C. A common use case of the
89 sensors devices is to have combined functionality (e.g. light plus proximity
90 sensor).
91 </para>
92 </chapter>
93 <chapter id='iiosubsys'>
94 <title>Industrial I/O core</title>
95 <para>
96 The Industrial I/O core offers:
97 <itemizedlist>
98 <listitem>
99 a unified framework for writing drivers for many different types of
100 embedded sensors.
101 </listitem>
102 <listitem>
103 a standard interface to user space applications manipulating sensors.
104 </listitem>
105 </itemizedlist>
106 The implementation can be found under <filename>
107 drivers/iio/industrialio-*</filename>
108 </para>
109 <sect1 id="iiodevice">
110 <title> Industrial I/O devices </title>
111
112!Finclude/linux/iio/iio.h iio_dev
113!Fdrivers/iio/industrialio-core.c iio_device_alloc
114!Fdrivers/iio/industrialio-core.c iio_device_free
115!Fdrivers/iio/industrialio-core.c iio_device_register
116!Fdrivers/iio/industrialio-core.c iio_device_unregister
117
118 <para>
119 An IIO device usually corresponds to a single hardware sensor and it
120 provides all the information needed by a driver handling a device.
121 Let's first have a look at the functionality embedded in an IIO
122 device then we will show how a device driver makes use of an IIO
123 device.
124 </para>
125 <para>
126 There are two ways for a user space application to interact
127 with an IIO driver.
128 <itemizedlist>
129 <listitem>
130 <filename>/sys/bus/iio/iio:deviceX/</filename>, this
131 represents a hardware sensor and groups together the data
132 channels of the same chip.
133 </listitem>
134 <listitem>
135 <filename>/dev/iio:deviceX</filename>, character device node
136 interface used for buffered data transfer and for events information
137 retrieval.
138 </listitem>
139 </itemizedlist>
140 </para>
141 A typical IIO driver will register itself as an I2C or SPI driver and will
142 create two routines, <function> probe </function> and <function> remove
143 </function>. At <function>probe</function>:
144 <itemizedlist>
145 <listitem>call <function>iio_device_alloc</function>, which allocates memory
146 for an IIO device.
147 </listitem>
148 <listitem> initialize IIO device fields with driver specific information
149 (e.g. device name, device channels).
150 </listitem>
151 <listitem>call <function> iio_device_register</function>, this registers the
152 device with the IIO core. After this call the device is ready to accept
153 requests from user space applications.
154 </listitem>
155 </itemizedlist>
156 At <function>remove</function>, we free the resources allocated in
157 <function>probe</function> in reverse order:
158 <itemizedlist>
159 <listitem><function>iio_device_unregister</function>, unregister the device
160 from the IIO core.
161 </listitem>
162 <listitem><function>iio_device_free</function>, free the memory allocated
163 for the IIO device.
164 </listitem>
165 </itemizedlist>
166
167 <sect2 id="iioattr"> <title> IIO device sysfs interface </title>
168 <para>
169 Attributes are sysfs files used to expose chip info and also allowing
170 applications to set various configuration parameters. For device
171 with index X, attributes can be found under
172 <filename>/sys/bus/iio/iio:deviceX/ </filename> directory.
173 Common attributes are:
174 <itemizedlist>
175 <listitem><filename>name</filename>, description of the physical
176 chip.
177 </listitem>
178 <listitem><filename>dev</filename>, shows the major:minor pair
179 associated with <filename>/dev/iio:deviceX</filename> node.
180 </listitem>
181 <listitem><filename>sampling_frequency_available</filename>,
182 available discrete set of sampling frequency values for
183 device.
184 </listitem>
185 </itemizedlist>
186 Available standard attributes for IIO devices are described in the
187 <filename>Documentation/ABI/testing/sysfs-bus-iio </filename> file
188 in the Linux kernel sources.
189 </para>
190 </sect2>
191 <sect2 id="iiochannel"> <title> IIO device channels </title>
192!Finclude/linux/iio/iio.h iio_chan_spec structure.
193 <para>
194 An IIO device channel is a representation of a data channel. An
195 IIO device can have one or multiple channels. For example:
196 <itemizedlist>
197 <listitem>
198 a thermometer sensor has one channel representing the
199 temperature measurement.
200 </listitem>
201 <listitem>
202 a light sensor with two channels indicating the measurements in
203 the visible and infrared spectrum.
204 </listitem>
205 <listitem>
206 an accelerometer can have up to 3 channels representing
207 acceleration on X, Y and Z axes.
208 </listitem>
209 </itemizedlist>
210 An IIO channel is described by the <type> struct iio_chan_spec
211 </type>. A thermometer driver for the temperature sensor in the
212 example above would have to describe its channel as follows:
213 <programlisting>
214 static const struct iio_chan_spec temp_channel[] = {
215 {
216 .type = IIO_TEMP,
217 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
218 },
219 };
220
221 </programlisting>
222 Channel sysfs attributes exposed to userspace are specified in
223 the form of <emphasis>bitmasks</emphasis>. Depending on their
224 shared info, attributes can be set in one of the following masks:
225 <itemizedlist>
226 <listitem><emphasis>info_mask_separate</emphasis>, attributes will
227 be specific to this channel</listitem>
228 <listitem><emphasis>info_mask_shared_by_type</emphasis>,
229 attributes are shared by all channels of the same type</listitem>
230 <listitem><emphasis>info_mask_shared_by_dir</emphasis>, attributes
231 are shared by all channels of the same direction </listitem>
232 <listitem><emphasis>info_mask_shared_by_all</emphasis>,
233 attributes are shared by all channels</listitem>
234 </itemizedlist>
235 When there are multiple data channels per channel type we have two
236 ways to distinguish between them:
237 <itemizedlist>
238 <listitem> set <emphasis> .modified</emphasis> field of <type>
239 iio_chan_spec</type> to 1. Modifiers are specified using
240 <emphasis>.channel2</emphasis> field of the same
241 <type>iio_chan_spec</type> structure and are used to indicate a
242 physically unique characteristic of the channel such as its direction
243 or spectral response. For example, a light sensor can have two channels,
244 one for infrared light and one for both infrared and visible light.
245 </listitem>
246 <listitem> set <emphasis>.indexed </emphasis> field of
247 <type>iio_chan_spec</type> to 1. In this case the channel is
248 simply another instance with an index specified by the
249 <emphasis>.channel</emphasis> field.
250 </listitem>
251 </itemizedlist>
252 Here is how we can make use of the channel's modifiers:
253 <programlisting>
254 static const struct iio_chan_spec light_channels[] = {
255 {
256 .type = IIO_INTENSITY,
257 .modified = 1,
258 .channel2 = IIO_MOD_LIGHT_IR,
259 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
260 .info_mask_shared = BIT(IIO_CHAN_INFO_SAMP_FREQ),
261 },
262 {
263 .type = IIO_INTENSITY,
264 .modified = 1,
265 .channel2 = IIO_MOD_LIGHT_BOTH,
266 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
267 .info_mask_shared = BIT(IIO_CHAN_INFO_SAMP_FREQ),
268 },
269 {
270 .type = IIO_LIGHT,
271 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
272 .info_mask_shared = BIT(IIO_CHAN_INFO_SAMP_FREQ),
273 },
274
275 }
276 </programlisting>
277 This channel's definition will generate two separate sysfs files
278 for raw data retrieval:
279 <itemizedlist>
280 <listitem>
281 <filename>/sys/bus/iio/iio:deviceX/in_intensity_ir_raw</filename>
282 </listitem>
283 <listitem>
284 <filename>/sys/bus/iio/iio:deviceX/in_intensity_both_raw</filename>
285 </listitem>
286 </itemizedlist>
287 one file for processed data:
288 <itemizedlist>
289 <listitem>
290 <filename>/sys/bus/iio/iio:deviceX/in_illuminance_input
291 </filename>
292 </listitem>
293 </itemizedlist>
294 and one shared sysfs file for sampling frequency:
295 <itemizedlist>
296 <listitem>
297 <filename>/sys/bus/iio/iio:deviceX/sampling_frequency.
298 </filename>
299 </listitem>
300 </itemizedlist>
301 </para>
302 <para>
303 Here is how we can make use of the channel's indexing:
304 <programlisting>
305 static const struct iio_chan_spec light_channels[] = {
306 {
307 .type = IIO_VOLTAGE,
308 .indexed = 1,
309 .channel = 0,
310 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
311 },
312 {
313 .type = IIO_VOLTAGE,
314 .indexed = 1,
315 .channel = 1,
316 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
317 },
318 }
319 </programlisting>
320 This will generate two separate attributes files for raw data
321 retrieval:
322 <itemizedlist>
323 <listitem>
324 <filename>/sys/bus/iio/devices/iio:deviceX/in_voltage0_raw</filename>,
325 representing voltage measurement for channel 0.
326 </listitem>
327 <listitem>
328 <filename>/sys/bus/iio/devices/iio:deviceX/in_voltage1_raw</filename>,
329 representing voltage measurement for channel 1.
330 </listitem>
331 </itemizedlist>
332 </para>
333 </sect2>
334 </sect1>
335
336 <sect1 id="iiobuffer"> <title> Industrial I/O buffers </title>
337!Finclude/linux/iio/buffer.h iio_buffer
338!Edrivers/iio/industrialio-buffer.c
339
340 <para>
341 The Industrial I/O core offers a way for continuous data capture
342 based on a trigger source. Multiple data channels can be read at once
343 from <filename>/dev/iio:deviceX</filename> character device node,
344 thus reducing the CPU load.
345 </para>
346
347 <sect2 id="iiobuffersysfs">
348 <title>IIO buffer sysfs interface </title>
349 <para>
350 An IIO buffer has an associated attributes directory under <filename>
351 /sys/bus/iio/iio:deviceX/buffer/</filename>. Here are the existing
352 attributes:
353 <itemizedlist>
354 <listitem>
355 <emphasis>length</emphasis>, the total number of data samples
356 (capacity) that can be stored by the buffer.
357 </listitem>
358 <listitem>
359 <emphasis>enable</emphasis>, activate buffer capture.
360 </listitem>
361 </itemizedlist>
362
363 </para>
364 </sect2>
365 <sect2 id="iiobuffersetup"> <title> IIO buffer setup </title>
366 <para>The meta information associated with a channel reading
367 placed in a buffer is called a <emphasis> scan element </emphasis>.
368 The important bits configuring scan elements are exposed to
369 userspace applications via the <filename>
370 /sys/bus/iio/iio:deviceX/scan_elements/</filename> directory. This
371 file contains attributes of the following form:
372 <itemizedlist>
373 <listitem><emphasis>enable</emphasis>, used for enabling a channel.
374 If and only if its attribute is non zero, then a triggered capture
375 will contain data samples for this channel.
376 </listitem>
377 <listitem><emphasis>type</emphasis>, description of the scan element
378 data storage within the buffer and hence the form in which it is
379 read from user space. Format is <emphasis>
380 [be|le]:[s|u]bits/storagebitsXrepeat[>>shift] </emphasis>.
381 <itemizedlist>
382 <listitem> <emphasis>be</emphasis> or <emphasis>le</emphasis>, specifies
383 big or little endian.
384 </listitem>
385 <listitem>
386 <emphasis>s </emphasis>or <emphasis>u</emphasis>, specifies if
387 signed (2's complement) or unsigned.
388 </listitem>
389 <listitem><emphasis>bits</emphasis>, is the number of valid data
390 bits.
391 </listitem>
392 <listitem><emphasis>storagebits</emphasis>, is the number of bits
393 (after padding) that it occupies in the buffer.
394 </listitem>
395 <listitem>
396 <emphasis>shift</emphasis>, if specified, is the shift that needs
397 to be applied prior to masking out unused bits.
398 </listitem>
399 <listitem>
400 <emphasis>repeat</emphasis>, specifies the number of bits/storagebits
401 repetitions. When the repeat element is 0 or 1, then the repeat
402 value is omitted.
403 </listitem>
404 </itemizedlist>
405 </listitem>
406 </itemizedlist>
407 For example, a driver for a 3-axis accelerometer with 12 bit
408 resolution where data is stored in two 8-bits registers as
409 follows:
410 <programlisting>
411 7 6 5 4 3 2 1 0
412 +---+---+---+---+---+---+---+---+
413 |D3 |D2 |D1 |D0 | X | X | X | X | (LOW byte, address 0x06)
414 +---+---+---+---+---+---+---+---+
415
416 7 6 5 4 3 2 1 0
417 +---+---+---+---+---+---+---+---+
418 |D11|D10|D9 |D8 |D7 |D6 |D5 |D4 | (HIGH byte, address 0x07)
419 +---+---+---+---+---+---+---+---+
420 </programlisting>
421
422 will have the following scan element type for each axis:
423 <programlisting>
424 $ cat /sys/bus/iio/devices/iio:device0/scan_elements/in_accel_y_type
425 le:s12/16>>4
426 </programlisting>
427 A user space application will interpret data samples read from the
428 buffer as two byte little endian signed data, that needs a 4 bits
429 right shift before masking out the 12 valid bits of data.
430 </para>
431 <para>
432 For implementing buffer support a driver should initialize the following
433 fields in <type>iio_chan_spec</type> definition:
434 <programlisting>
435 struct iio_chan_spec {
436 /* other members */
437 int scan_index
438 struct {
439 char sign;
440 u8 realbits;
441 u8 storagebits;
442 u8 shift;
443 u8 repeat;
444 enum iio_endian endianness;
445 } scan_type;
446 };
447 </programlisting>
448 The driver implementing the accelerometer described above will
449 have the following channel definition:
450 <programlisting>
451 struct struct iio_chan_spec accel_channels[] = {
452 {
453 .type = IIO_ACCEL,
454 .modified = 1,
455 .channel2 = IIO_MOD_X,
456 /* other stuff here */
457 .scan_index = 0,
458 .scan_type = {
459 .sign = 's',
460 .realbits = 12,
461 .storgebits = 16,
462 .shift = 4,
463 .endianness = IIO_LE,
464 },
465 }
466 /* similar for Y (with channel2 = IIO_MOD_Y, scan_index = 1)
467 * and Z (with channel2 = IIO_MOD_Z, scan_index = 2) axis
468 */
469 }
470 </programlisting>
471 </para>
472 <para>
473 Here <emphasis> scan_index </emphasis> defines the order in which
474 the enabled channels are placed inside the buffer. Channels with a lower
475 scan_index will be placed before channels with a higher index. Each
476 channel needs to have a unique scan_index.
477 </para>
478 <para>
479 Setting scan_index to -1 can be used to indicate that the specific
480 channel does not support buffered capture. In this case no entries will
481 be created for the channel in the scan_elements directory.
482 </para>
483 </sect2>
484 </sect1>
485
486 <sect1 id="iiotrigger"> <title> Industrial I/O triggers </title>
487!Finclude/linux/iio/trigger.h iio_trigger
488!Edrivers/iio/industrialio-trigger.c
489 <para>
490 In many situations it is useful for a driver to be able to
491 capture data based on some external event (trigger) as opposed
492 to periodically polling for data. An IIO trigger can be provided
493 by a device driver that also has an IIO device based on hardware
494 generated events (e.g. data ready or threshold exceeded) or
495 provided by a separate driver from an independent interrupt
496 source (e.g. GPIO line connected to some external system, timer
497 interrupt or user space writing a specific file in sysfs). A
498 trigger may initiate data capture for a number of sensors and
499 also it may be completely unrelated to the sensor itself.
500 </para>
501
502 <sect2 id="iiotrigsysfs"> <title> IIO trigger sysfs interface </title>
503 There are two locations in sysfs related to triggers:
504 <itemizedlist>
505 <listitem><filename>/sys/bus/iio/devices/triggerY</filename>,
506 this file is created once an IIO trigger is registered with
507 the IIO core and corresponds to trigger with index Y. Because
508 triggers can be very different depending on type there are few
509 standard attributes that we can describe here:
510 <itemizedlist>
511 <listitem>
512 <emphasis>name</emphasis>, trigger name that can be later
513 used for association with a device.
514 </listitem>
515 <listitem>
516 <emphasis>sampling_frequency</emphasis>, some timer based
517 triggers use this attribute to specify the frequency for
518 trigger calls.
519 </listitem>
520 </itemizedlist>
521 </listitem>
522 <listitem>
523 <filename>/sys/bus/iio/devices/iio:deviceX/trigger/</filename>, this
524 directory is created once the device supports a triggered
525 buffer. We can associate a trigger with our device by writing
526 the trigger's name in the <filename>current_trigger</filename> file.
527 </listitem>
528 </itemizedlist>
529 </sect2>
530
531 <sect2 id="iiotrigattr"> <title> IIO trigger setup</title>
532
533 <para>
534 Let's see a simple example of how to setup a trigger to be used
535 by a driver.
536
537 <programlisting>
538 struct iio_trigger_ops trigger_ops = {
539 .set_trigger_state = sample_trigger_state,
540 .validate_device = sample_validate_device,
541 }
542
543 struct iio_trigger *trig;
544
545 /* first, allocate memory for our trigger */
546 trig = iio_trigger_alloc(dev, "trig-%s-%d", name, idx);
547
548 /* setup trigger operations field */
549 trig->ops = &amp;trigger_ops;
550
551 /* now register the trigger with the IIO core */
552 iio_trigger_register(trig);
553 </programlisting>
554 </para>
555 </sect2>
556
557 <sect2 id="iiotrigsetup"> <title> IIO trigger ops</title>
558!Finclude/linux/iio/trigger.h iio_trigger_ops
559 <para>
560 Notice that a trigger has a set of operations attached:
561 <itemizedlist>
562 <listitem>
563 <function>set_trigger_state</function>, switch the trigger on/off
564 on demand.
565 </listitem>
566 <listitem>
567 <function>validate_device</function>, function to validate the
568 device when the current trigger gets changed.
569 </listitem>
570 </itemizedlist>
571 </para>
572 </sect2>
573 </sect1>
574 <sect1 id="iiotriggered_buffer">
575 <title> Industrial I/O triggered buffers </title>
576 <para>
577 Now that we know what buffers and triggers are let's see how they
578 work together.
579 </para>
580 <sect2 id="iiotrigbufsetup"> <title> IIO triggered buffer setup</title>
581!Edrivers/iio/industrialio-triggered-buffer.c
582!Finclude/linux/iio/iio.h iio_buffer_setup_ops
583
584
585 <para>
586 A typical triggered buffer setup looks like this:
587 <programlisting>
588 const struct iio_buffer_setup_ops sensor_buffer_setup_ops = {
589 .preenable = sensor_buffer_preenable,
590 .postenable = sensor_buffer_postenable,
591 .postdisable = sensor_buffer_postdisable,
592 .predisable = sensor_buffer_predisable,
593 };
594
595 irqreturn_t sensor_iio_pollfunc(int irq, void *p)
596 {
597 pf->timestamp = iio_get_time_ns();
598 return IRQ_WAKE_THREAD;
599 }
600
601 irqreturn_t sensor_trigger_handler(int irq, void *p)
602 {
603 u16 buf[8];
604 int i = 0;
605
606 /* read data for each active channel */
607 for_each_set_bit(bit, active_scan_mask, masklength)
608 buf[i++] = sensor_get_data(bit)
609
610 iio_push_to_buffers_with_timestamp(indio_dev, buf, timestamp);
611
612 iio_trigger_notify_done(trigger);
613 return IRQ_HANDLED;
614 }
615
616 /* setup triggered buffer, usually in probe function */
617 iio_triggered_buffer_setup(indio_dev, sensor_iio_polfunc,
618 sensor_trigger_handler,
619 sensor_buffer_setup_ops);
620 </programlisting>
621 </para>
622 The important things to notice here are:
623 <itemizedlist>
624 <listitem><function> iio_buffer_setup_ops</function>, the buffer setup
625 functions to be called at predefined points in the buffer configuration
626 sequence (e.g. before enable, after disable). If not specified, the
627 IIO core uses the default <type>iio_triggered_buffer_setup_ops</type>.
628 </listitem>
629 <listitem><function>sensor_iio_pollfunc</function>, the function that
630 will be used as top half of poll function. It should do as little
631 processing as possible, because it runs in interrupt context. The most
632 common operation is recording of the current timestamp and for this reason
633 one can use the IIO core defined <function>iio_pollfunc_store_time
634 </function> function.
635 </listitem>
636 <listitem><function>sensor_trigger_handler</function>, the function that
637 will be used as bottom half of the poll function. This runs in the
638 context of a kernel thread and all the processing takes place here.
639 It usually reads data from the device and stores it in the internal
640 buffer together with the timestamp recorded in the top half.
641 </listitem>
642 </itemizedlist>
643 </sect2>
644 </sect1>
645 </chapter>
646 <chapter id='iioresources'>
647 <title> Resources </title>
648 IIO core may change during time so the best documentation to read is the
649 source code. There are several locations where you should look:
650 <itemizedlist>
651 <listitem>
652 <filename>drivers/iio/</filename>, contains the IIO core plus
653 and directories for each sensor type (e.g. accel, magnetometer,
654 etc.)
655 </listitem>
656 <listitem>
657 <filename>include/linux/iio/</filename>, contains the header
658 files, nice to read for the internal kernel interfaces.
659 </listitem>
660 <listitem>
661 <filename>include/uapi/linux/iio/</filename>, contains files to be
662 used by user space applications.
663 </listitem>
664 <listitem>
665 <filename>tools/iio/</filename>, contains tools for rapidly
666 testing buffers, events and device creation.
667 </listitem>
668 <listitem>
669 <filename>drivers/staging/iio/</filename>, contains code for some
670 drivers or experimental features that are not yet mature enough
671 to be moved out.
672 </listitem>
673 </itemizedlist>
674 <para>
675 Besides the code, there are some good online documentation sources:
676 <itemizedlist>
677 <listitem>
678 <ulink url="http://marc.info/?l=linux-iio"> Industrial I/O mailing
679 list </ulink>
680 </listitem>
681 <listitem>
682 <ulink url="http://wiki.analog.com/software/linux/docs/iio/iio">
683 Analog Device IIO wiki page </ulink>
684 </listitem>
685 <listitem>
686 <ulink url="https://fosdem.org/2015/schedule/event/iiosdr/">
687 Using the Linux IIO framework for SDR, Lars-Peter Clausen's
688 presentation at FOSDEM </ulink>
689 </listitem>
690 </itemizedlist>
691 </para>
692 </chapter>
693</book>
694
695<!--
696vim: softtabstop=2:shiftwidth=2:expandtab:textwidth=72
697-->
diff --git a/Documentation/devicetree/bindings/iio/adc/mcp320x.txt b/Documentation/devicetree/bindings/iio/adc/mcp320x.txt
index b85184391b78..2a1f3af30155 100644
--- a/Documentation/devicetree/bindings/iio/adc/mcp320x.txt
+++ b/Documentation/devicetree/bindings/iio/adc/mcp320x.txt
@@ -18,6 +18,7 @@ Required properties:
18 "mcp3202" 18 "mcp3202"
19 "mcp3204" 19 "mcp3204"
20 "mcp3208" 20 "mcp3208"
21 "mcp3301"
21 22
22 23
23Examples: 24Examples:
diff --git a/Documentation/devicetree/bindings/iio/adc/vf610-adc.txt b/Documentation/devicetree/bindings/iio/adc/vf610-adc.txt
index 3eb40e20c143..1aad0514e647 100644
--- a/Documentation/devicetree/bindings/iio/adc/vf610-adc.txt
+++ b/Documentation/devicetree/bindings/iio/adc/vf610-adc.txt
@@ -17,6 +17,11 @@ Recommended properties:
17 - Frequency in normal mode (ADLPC=0, ADHSC=0) 17 - Frequency in normal mode (ADLPC=0, ADHSC=0)
18 - Frequency in high-speed mode (ADLPC=0, ADHSC=1) 18 - Frequency in high-speed mode (ADLPC=0, ADHSC=1)
19 - Frequency in low-power mode (ADLPC=1, ADHSC=0) 19 - Frequency in low-power mode (ADLPC=1, ADHSC=0)
20- min-sample-time: Minimum sampling time in nanoseconds. This value has
21 to be chosen according to the conversion mode and the connected analog
22 source resistance (R_as) and capacitance (C_as). Refer the datasheet's
23 operating requirements. A safe default across a wide range of R_as and
24 C_as as well as conversion modes is 1000ns.
20 25
21Example: 26Example:
22adc0: adc@4003b000 { 27adc0: adc@4003b000 {
diff --git a/Documentation/devicetree/bindings/iio/magnetometer/mmc35240.txt b/Documentation/devicetree/bindings/iio/magnetometer/mmc35240.txt
new file mode 100644
index 000000000000..a01235c7fa15
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/magnetometer/mmc35240.txt
@@ -0,0 +1,13 @@
1* MEMSIC MMC35240 magnetometer sensor
2
3Required properties:
4
5 - compatible : should be "memsic,mmc35240"
6 - reg : the I2C address of the magnetometer
7
8Example:
9
10mmc35240@30 {
11 compatible = "memsic,mmc35240";
12 reg = <0x30>;
13};
diff --git a/Documentation/devicetree/bindings/iio/st-sensors.txt b/Documentation/devicetree/bindings/iio/st-sensors.txt
index 8a6be3bdf267..d3ccdb190c53 100644
--- a/Documentation/devicetree/bindings/iio/st-sensors.txt
+++ b/Documentation/devicetree/bindings/iio/st-sensors.txt
@@ -35,6 +35,7 @@ Accelerometers:
35- st,lsm303dl-accel 35- st,lsm303dl-accel
36- st,lsm303dlm-accel 36- st,lsm303dlm-accel
37- st,lsm330-accel 37- st,lsm330-accel
38- st,lsm303agr-accel
38 39
39Gyroscopes: 40Gyroscopes:
40- st,l3g4200d-gyro 41- st,l3g4200d-gyro
@@ -46,6 +47,7 @@ Gyroscopes:
46- st,lsm330-gyro 47- st,lsm330-gyro
47 48
48Magnetometers: 49Magnetometers:
50- st,lsm303agr-magn
49- st,lsm303dlh-magn 51- st,lsm303dlh-magn
50- st,lsm303dlhc-magn 52- st,lsm303dlhc-magn
51- st,lsm303dlm-magn 53- st,lsm303dlm-magn
diff --git a/Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt b/Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt
index 307537787574..555fb117d4fa 100644
--- a/Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt
+++ b/Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt
@@ -1,4 +1,4 @@
1* Freescale i.MX28 LRADC device driver 1* Freescale MXS LRADC device driver
2 2
3Required properties: 3Required properties:
4- compatible: Should be "fsl,imx23-lradc" for i.MX23 SoC and "fsl,imx28-lradc" 4- compatible: Should be "fsl,imx23-lradc" for i.MX23 SoC and "fsl,imx28-lradc"
diff --git a/Documentation/fb/sm712fb.txt b/Documentation/fb/sm712fb.txt
new file mode 100644
index 000000000000..c388442edf51
--- /dev/null
+++ b/Documentation/fb/sm712fb.txt
@@ -0,0 +1,31 @@
1What is sm712fb?
2=================
3
4This is a graphics framebuffer driver for Silicon Motion SM712 based processors.
5
6How to use it?
7==============
8
9Switching modes is done using the video=sm712fb:... boot parameter.
10
11If you want, for example, enable a resolution of 1280x1024x24bpp you should
12pass to the kernel this command line: "video=sm712fb:0x31B".
13
14You should not compile-in vesafb.
15
16Currently supported video modes are:
17
18[Graphic modes]
19
20bpp | 640x480 800x600 1024x768 1280x1024
21----+--------------------------------------------
22 8 | 0x301 0x303 0x305 0x307
23 16 | 0x311 0x314 0x317 0x31A
24 24 | 0x312 0x315 0x318 0x31B
25
26Missing Features
27================
28(alias TODO list)
29
30 * 2D acceleratrion
31 * dual-head support
diff --git a/MAINTAINERS b/MAINTAINERS
index 7899b3f5bec9..973002719b80 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9348,6 +9348,15 @@ S: Maintained
9348F: drivers/media/i2c/ov2659.c 9348F: drivers/media/i2c/ov2659.c
9349F: include/media/ov2659.h 9349F: include/media/ov2659.h
9350 9350
9351SILICON MOTION SM712 FRAME BUFFER DRIVER
9352M: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
9353M: Teddy Wang <teddy.wang@siliconmotion.com>
9354M: Sudip Mukherjee <sudip@vectorindia.org>
9355L: linux-fbdev@vger.kernel.org
9356S: Maintained
9357F: drivers/video/fbdev/sm712*
9358F: Documentation/fb/sm712fb.txt
9359
9351SIS 190 ETHERNET DRIVER 9360SIS 190 ETHERNET DRIVER
9352M: Francois Romieu <romieu@fr.zoreil.com> 9361M: Francois Romieu <romieu@fr.zoreil.com>
9353L: netdev@vger.kernel.org 9362L: netdev@vger.kernel.org
@@ -9745,11 +9754,6 @@ W: http://wiki.laptop.org/go/DCON
9745S: Maintained 9754S: Maintained
9746F: drivers/staging/olpc_dcon/ 9755F: drivers/staging/olpc_dcon/
9747 9756
9748STAGING - OZMO DEVICES USB OVER WIFI DRIVER
9749M: Shigekatsu Tateno <shigekatsu.tateno@atmel.com>
9750S: Maintained
9751F: drivers/staging/ozwpan/
9752
9753STAGING - PARALLEL LCD/KEYPAD PANEL DRIVER 9757STAGING - PARALLEL LCD/KEYPAD PANEL DRIVER
9754M: Willy Tarreau <willy@meta-x.org> 9758M: Willy Tarreau <willy@meta-x.org>
9755S: Odd Fixes 9759S: Odd Fixes
@@ -9768,14 +9772,6 @@ L: linux-wireless@vger.kernel.org
9768S: Maintained 9772S: Maintained
9769F: drivers/staging/rtl8723au/ 9773F: drivers/staging/rtl8723au/
9770 9774
9771STAGING - SILICON MOTION SM7XX FRAME BUFFER DRIVER
9772M: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
9773M: Teddy Wang <teddy.wang@siliconmotion.com>
9774M: Sudip Mukherjee <sudip@vectorindia.org>
9775L: linux-fbdev@vger.kernel.org
9776S: Maintained
9777F: drivers/staging/sm7xxfb/
9778
9779STAGING - SILICON MOTION SM750 FRAME BUFFER DRIVER 9775STAGING - SILICON MOTION SM750 FRAME BUFFER DRIVER
9780M: Sudip Mukherjee <sudipm.mukherjee@gmail.com> 9776M: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
9781M: Teddy Wang <teddy.wang@siliconmotion.com> 9777M: Teddy Wang <teddy.wang@siliconmotion.com>
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index 00e7bcbdbe24..a59047d7657e 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -86,18 +86,6 @@ config KXSD9
86 To compile this driver as a module, choose M here: the module 86 To compile this driver as a module, choose M here: the module
87 will be called kxsd9. 87 will be called kxsd9.
88 88
89config MMA8452
90 tristate "Freescale MMA8452Q Accelerometer Driver"
91 depends on I2C
92 select IIO_BUFFER
93 select IIO_TRIGGERED_BUFFER
94 help
95 Say yes here to build support for the Freescale MMA8452Q 3-axis
96 accelerometer.
97
98 To compile this driver as a module, choose M here: the module
99 will be called mma8452.
100
101config KXCJK1013 89config KXCJK1013
102 tristate "Kionix 3-Axis Accelerometer Driver" 90 tristate "Kionix 3-Axis Accelerometer Driver"
103 depends on I2C 91 depends on I2C
@@ -111,6 +99,18 @@ config KXCJK1013
111 To compile this driver as a module, choose M here: the module will 99 To compile this driver as a module, choose M here: the module will
112 be called kxcjk-1013. 100 be called kxcjk-1013.
113 101
102config MMA8452
103 tristate "Freescale MMA8452Q Accelerometer Driver"
104 depends on I2C
105 select IIO_BUFFER
106 select IIO_TRIGGERED_BUFFER
107 help
108 Say yes here to build support for the Freescale MMA8452Q 3-axis
109 accelerometer.
110
111 To compile this driver as a module, choose M here: the module
112 will be called mma8452.
113
114config MMA9551_CORE 114config MMA9551_CORE
115 tristate 115 tristate
116 116
@@ -140,6 +140,8 @@ config MMA9553
140config STK8312 140config STK8312
141 tristate "Sensortek STK8312 3-Axis Accelerometer Driver" 141 tristate "Sensortek STK8312 3-Axis Accelerometer Driver"
142 depends on I2C 142 depends on I2C
143 select IIO_BUFFER
144 select IIO_TRIGGERED_BUFFER
143 help 145 help
144 Say yes here to get support for the Sensortek STK8312 3-axis 146 Say yes here to get support for the Sensortek STK8312 3-axis
145 accelerometer. 147 accelerometer.
diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
index 75c6d2103e07..f04b88406995 100644
--- a/drivers/iio/accel/bma180.c
+++ b/drivers/iio/accel/bma180.c
@@ -846,7 +846,6 @@ MODULE_DEVICE_TABLE(i2c, bma180_ids);
846static struct i2c_driver bma180_driver = { 846static struct i2c_driver bma180_driver = {
847 .driver = { 847 .driver = {
848 .name = "bma180", 848 .name = "bma180",
849 .owner = THIS_MODULE,
850 .pm = BMA180_PM_OPS, 849 .pm = BMA180_PM_OPS,
851 }, 850 },
852 .probe = bma180_probe, 851 .probe = bma180_probe,
diff --git a/drivers/iio/accel/bmc150-accel.c b/drivers/iio/accel/bmc150-accel.c
index cc5a35750b50..0104cdef8709 100644
--- a/drivers/iio/accel/bmc150-accel.c
+++ b/drivers/iio/accel/bmc150-accel.c
@@ -151,6 +151,7 @@ struct bmc150_scale_info {
151}; 151};
152 152
153struct bmc150_accel_chip_info { 153struct bmc150_accel_chip_info {
154 const char *name;
154 u8 chip_id; 155 u8 chip_id;
155 const struct iio_chan_spec *channels; 156 const struct iio_chan_spec *channels;
156 int num_channels; 157 int num_channels;
@@ -241,7 +242,6 @@ static const struct {
241 {500000, BMC150_ACCEL_SLEEP_500_MS}, 242 {500000, BMC150_ACCEL_SLEEP_500_MS},
242 {1000000, BMC150_ACCEL_SLEEP_1_SEC} }; 243 {1000000, BMC150_ACCEL_SLEEP_1_SEC} };
243 244
244
245static int bmc150_accel_set_mode(struct bmc150_accel_data *data, 245static int bmc150_accel_set_mode(struct bmc150_accel_data *data,
246 enum bmc150_power_modes mode, 246 enum bmc150_power_modes mode,
247 int dur_us) 247 int dur_us)
@@ -259,8 +259,9 @@ static int bmc150_accel_set_mode(struct bmc150_accel_data *data,
259 dur_val = 259 dur_val =
260 bmc150_accel_sleep_value_table[i].reg_value; 260 bmc150_accel_sleep_value_table[i].reg_value;
261 } 261 }
262 } else 262 } else {
263 dur_val = 0; 263 dur_val = 0;
264 }
264 265
265 if (dur_val < 0) 266 if (dur_val < 0)
266 return -EINVAL; 267 return -EINVAL;
@@ -288,7 +289,7 @@ static int bmc150_accel_set_bw(struct bmc150_accel_data *data, int val,
288 289
289 for (i = 0; i < ARRAY_SIZE(bmc150_accel_samp_freq_table); ++i) { 290 for (i = 0; i < ARRAY_SIZE(bmc150_accel_samp_freq_table); ++i) {
290 if (bmc150_accel_samp_freq_table[i].val == val && 291 if (bmc150_accel_samp_freq_table[i].val == val &&
291 bmc150_accel_samp_freq_table[i].val2 == val2) { 292 bmc150_accel_samp_freq_table[i].val2 == val2) {
292 ret = i2c_smbus_write_byte_data( 293 ret = i2c_smbus_write_byte_data(
293 data->client, 294 data->client,
294 BMC150_ACCEL_REG_PMU_BW, 295 BMC150_ACCEL_REG_PMU_BW,
@@ -345,65 +346,6 @@ static int bmc150_accel_any_motion_setup(struct bmc150_accel_trigger *t,
345 return 0; 346 return 0;
346} 347}
347 348
348static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
349{
350 int ret;
351
352 ret = i2c_smbus_read_byte_data(data->client, BMC150_ACCEL_REG_CHIP_ID);
353 if (ret < 0) {
354 dev_err(&data->client->dev,
355 "Error: Reading chip id\n");
356 return ret;
357 }
358
359 dev_dbg(&data->client->dev, "Chip Id %x\n", ret);
360 if (ret != data->chip_info->chip_id) {
361 dev_err(&data->client->dev, "Invalid chip %x\n", ret);
362 return -ENODEV;
363 }
364
365 ret = bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_NORMAL, 0);
366 if (ret < 0)
367 return ret;
368
369 /* Set Bandwidth */
370 ret = bmc150_accel_set_bw(data, BMC150_ACCEL_DEF_BW, 0);
371 if (ret < 0)
372 return ret;
373
374 /* Set Default Range */
375 ret = i2c_smbus_write_byte_data(data->client,
376 BMC150_ACCEL_REG_PMU_RANGE,
377 BMC150_ACCEL_DEF_RANGE_4G);
378 if (ret < 0) {
379 dev_err(&data->client->dev,
380 "Error writing reg_pmu_range\n");
381 return ret;
382 }
383
384 data->range = BMC150_ACCEL_DEF_RANGE_4G;
385
386 /* Set default slope duration and thresholds */
387 data->slope_thres = BMC150_ACCEL_DEF_SLOPE_THRESHOLD;
388 data->slope_dur = BMC150_ACCEL_DEF_SLOPE_DURATION;
389 ret = bmc150_accel_update_slope(data);
390 if (ret < 0)
391 return ret;
392
393 /* Set default as latched interrupts */
394 ret = i2c_smbus_write_byte_data(data->client,
395 BMC150_ACCEL_REG_INT_RST_LATCH,
396 BMC150_ACCEL_INT_MODE_LATCH_INT |
397 BMC150_ACCEL_INT_MODE_LATCH_RESET);
398 if (ret < 0) {
399 dev_err(&data->client->dev,
400 "Error writing reg_int_rst_latch\n");
401 return ret;
402 }
403
404 return 0;
405}
406
407static int bmc150_accel_get_bw(struct bmc150_accel_data *data, int *val, 349static int bmc150_accel_get_bw(struct bmc150_accel_data *data, int *val,
408 int *val2) 350 int *val2)
409{ 351{
@@ -437,12 +379,13 @@ static int bmc150_accel_set_power_state(struct bmc150_accel_data *data, bool on)
437{ 379{
438 int ret; 380 int ret;
439 381
440 if (on) 382 if (on) {
441 ret = pm_runtime_get_sync(&data->client->dev); 383 ret = pm_runtime_get_sync(&data->client->dev);
442 else { 384 } else {
443 pm_runtime_mark_last_busy(&data->client->dev); 385 pm_runtime_mark_last_busy(&data->client->dev);
444 ret = pm_runtime_put_autosuspend(&data->client->dev); 386 ret = pm_runtime_put_autosuspend(&data->client->dev);
445 } 387 }
388
446 if (ret < 0) { 389 if (ret < 0) {
447 dev_err(&data->client->dev, 390 dev_err(&data->client->dev,
448 "Failed: bmc150_accel_set_power_state for %d\n", on); 391 "Failed: bmc150_accel_set_power_state for %d\n", on);
@@ -514,13 +457,13 @@ static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i,
514 } 457 }
515 458
516 /* 459 /*
517 * We will expect the enable and disable to do operation in 460 * We will expect the enable and disable to do operation in reverse
518 * in reverse order. This will happen here anyway as our 461 * order. This will happen here anyway, as our resume operation uses
519 * resume operation uses sync mode runtime pm calls, the 462 * sync mode runtime pm calls. The suspend operation will be delayed
520 * suspend operation will be delayed by autosuspend delay 463 * by autosuspend delay.
521 * So the disable operation will still happen in reverse of 464 * So the disable operation will still happen in reverse order of
522 * enable operation. When runtime pm is disabled the mode 465 * enable operation. When runtime pm is disabled the mode is always on,
523 * is always on so sequence doesn't matter 466 * so sequence doesn't matter.
524 */ 467 */
525 ret = bmc150_accel_set_power_state(data, state); 468 ret = bmc150_accel_set_power_state(data, state);
526 if (ret < 0) 469 if (ret < 0)
@@ -574,7 +517,6 @@ out_fix_power_state:
574 return ret; 517 return ret;
575} 518}
576 519
577
578static int bmc150_accel_set_scale(struct bmc150_accel_data *data, int val) 520static int bmc150_accel_set_scale(struct bmc150_accel_data *data, int val)
579{ 521{
580 int ret, i; 522 int ret, i;
@@ -674,8 +616,9 @@ static int bmc150_accel_read_raw(struct iio_dev *indio_dev,
674 if (chan->type == IIO_TEMP) { 616 if (chan->type == IIO_TEMP) {
675 *val = BMC150_ACCEL_TEMP_CENTER_VAL; 617 *val = BMC150_ACCEL_TEMP_CENTER_VAL;
676 return IIO_VAL_INT; 618 return IIO_VAL_INT;
677 } else 619 } else {
678 return -EINVAL; 620 return -EINVAL;
621 }
679 case IIO_CHAN_INFO_SCALE: 622 case IIO_CHAN_INFO_SCALE:
680 *val = 0; 623 *val = 0;
681 switch (chan->type) { 624 switch (chan->type) {
@@ -776,7 +719,7 @@ static int bmc150_accel_write_event(struct iio_dev *indio_dev,
776 719
777 switch (info) { 720 switch (info) {
778 case IIO_EV_INFO_VALUE: 721 case IIO_EV_INFO_VALUE:
779 data->slope_thres = val & 0xFF; 722 data->slope_thres = val & BMC150_ACCEL_SLOPE_THRES_MASK;
780 break; 723 break;
781 case IIO_EV_INFO_PERIOD: 724 case IIO_EV_INFO_PERIOD:
782 data->slope_dur = val & BMC150_ACCEL_SLOPE_DUR_MASK; 725 data->slope_dur = val & BMC150_ACCEL_SLOPE_DUR_MASK;
@@ -793,7 +736,6 @@ static int bmc150_accel_read_event_config(struct iio_dev *indio_dev,
793 enum iio_event_type type, 736 enum iio_event_type type,
794 enum iio_event_direction dir) 737 enum iio_event_direction dir)
795{ 738{
796
797 struct bmc150_accel_data *data = iio_priv(indio_dev); 739 struct bmc150_accel_data *data = iio_priv(indio_dev);
798 740
799 return data->ev_enable_state; 741 return data->ev_enable_state;
@@ -827,7 +769,7 @@ static int bmc150_accel_write_event_config(struct iio_dev *indio_dev,
827} 769}
828 770
829static int bmc150_accel_validate_trigger(struct iio_dev *indio_dev, 771static int bmc150_accel_validate_trigger(struct iio_dev *indio_dev,
830 struct iio_trigger *trig) 772 struct iio_trigger *trig)
831{ 773{
832 struct bmc150_accel_data *data = iio_priv(indio_dev); 774 struct bmc150_accel_data *data = iio_priv(indio_dev);
833 int i; 775 int i;
@@ -963,6 +905,7 @@ static int __bmc150_accel_fifo_flush(struct iio_dev *indio_dev,
963 u16 buffer[BMC150_ACCEL_FIFO_LENGTH * 3]; 905 u16 buffer[BMC150_ACCEL_FIFO_LENGTH * 3];
964 int64_t tstamp; 906 int64_t tstamp;
965 uint64_t sample_period; 907 uint64_t sample_period;
908
966 ret = i2c_smbus_read_byte_data(data->client, 909 ret = i2c_smbus_read_byte_data(data->client,
967 BMC150_ACCEL_REG_FIFO_STATUS); 910 BMC150_ACCEL_REG_FIFO_STATUS);
968 if (ret < 0) { 911 if (ret < 0) {
@@ -1120,6 +1063,7 @@ enum {
1120 1063
1121static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = { 1064static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
1122 [bmc150] = { 1065 [bmc150] = {
1066 .name = "BMC150A",
1123 .chip_id = 0xFA, 1067 .chip_id = 0xFA,
1124 .channels = bmc150_accel_channels, 1068 .channels = bmc150_accel_channels,
1125 .num_channels = ARRAY_SIZE(bmc150_accel_channels), 1069 .num_channels = ARRAY_SIZE(bmc150_accel_channels),
@@ -1129,6 +1073,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
1129 {76590, BMC150_ACCEL_DEF_RANGE_16G} }, 1073 {76590, BMC150_ACCEL_DEF_RANGE_16G} },
1130 }, 1074 },
1131 [bmi055] = { 1075 [bmi055] = {
1076 .name = "BMI055A",
1132 .chip_id = 0xFA, 1077 .chip_id = 0xFA,
1133 .channels = bmc150_accel_channels, 1078 .channels = bmc150_accel_channels,
1134 .num_channels = ARRAY_SIZE(bmc150_accel_channels), 1079 .num_channels = ARRAY_SIZE(bmc150_accel_channels),
@@ -1138,6 +1083,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
1138 {76590, BMC150_ACCEL_DEF_RANGE_16G} }, 1083 {76590, BMC150_ACCEL_DEF_RANGE_16G} },
1139 }, 1084 },
1140 [bma255] = { 1085 [bma255] = {
1086 .name = "BMA0255",
1141 .chip_id = 0xFA, 1087 .chip_id = 0xFA,
1142 .channels = bmc150_accel_channels, 1088 .channels = bmc150_accel_channels,
1143 .num_channels = ARRAY_SIZE(bmc150_accel_channels), 1089 .num_channels = ARRAY_SIZE(bmc150_accel_channels),
@@ -1147,6 +1093,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
1147 {76590, BMC150_ACCEL_DEF_RANGE_16G} }, 1093 {76590, BMC150_ACCEL_DEF_RANGE_16G} },
1148 }, 1094 },
1149 [bma250e] = { 1095 [bma250e] = {
1096 .name = "BMA250E",
1150 .chip_id = 0xF9, 1097 .chip_id = 0xF9,
1151 .channels = bma250e_accel_channels, 1098 .channels = bma250e_accel_channels,
1152 .num_channels = ARRAY_SIZE(bma250e_accel_channels), 1099 .num_channels = ARRAY_SIZE(bma250e_accel_channels),
@@ -1156,6 +1103,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
1156 {306457, BMC150_ACCEL_DEF_RANGE_16G} }, 1103 {306457, BMC150_ACCEL_DEF_RANGE_16G} },
1157 }, 1104 },
1158 [bma222e] = { 1105 [bma222e] = {
1106 .name = "BMA222E",
1159 .chip_id = 0xF8, 1107 .chip_id = 0xF8,
1160 .channels = bma222e_accel_channels, 1108 .channels = bma222e_accel_channels,
1161 .num_channels = ARRAY_SIZE(bma222e_accel_channels), 1109 .num_channels = ARRAY_SIZE(bma222e_accel_channels),
@@ -1165,6 +1113,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
1165 {1225831, BMC150_ACCEL_DEF_RANGE_16G} }, 1113 {1225831, BMC150_ACCEL_DEF_RANGE_16G} },
1166 }, 1114 },
1167 [bma280] = { 1115 [bma280] = {
1116 .name = "BMA0280",
1168 .chip_id = 0xFB, 1117 .chip_id = 0xFB,
1169 .channels = bma280_accel_channels, 1118 .channels = bma280_accel_channels,
1170 .num_channels = ARRAY_SIZE(bma280_accel_channels), 1119 .num_channels = ARRAY_SIZE(bma280_accel_channels),
@@ -1255,7 +1204,7 @@ static int bmc150_accel_trig_try_reen(struct iio_trigger *trig)
1255} 1204}
1256 1205
1257static int bmc150_accel_trigger_set_state(struct iio_trigger *trig, 1206static int bmc150_accel_trigger_set_state(struct iio_trigger *trig,
1258 bool state) 1207 bool state)
1259{ 1208{
1260 struct bmc150_accel_trigger *t = iio_trigger_get_drvdata(trig); 1209 struct bmc150_accel_trigger *t = iio_trigger_get_drvdata(trig);
1261 struct bmc150_accel_data *data = t->data; 1210 struct bmc150_accel_data *data = t->data;
@@ -1314,26 +1263,32 @@ static int bmc150_accel_handle_roc_event(struct iio_dev *indio_dev)
1314 dir = IIO_EV_DIR_RISING; 1263 dir = IIO_EV_DIR_RISING;
1315 1264
1316 if (ret & BMC150_ACCEL_ANY_MOTION_BIT_X) 1265 if (ret & BMC150_ACCEL_ANY_MOTION_BIT_X)
1317 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, 1266 iio_push_event(indio_dev,
1318 0, 1267 IIO_MOD_EVENT_CODE(IIO_ACCEL,
1319 IIO_MOD_X, 1268 0,
1320 IIO_EV_TYPE_ROC, 1269 IIO_MOD_X,
1321 dir), 1270 IIO_EV_TYPE_ROC,
1322 data->timestamp); 1271 dir),
1272 data->timestamp);
1273
1323 if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Y) 1274 if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Y)
1324 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, 1275 iio_push_event(indio_dev,
1325 0, 1276 IIO_MOD_EVENT_CODE(IIO_ACCEL,
1326 IIO_MOD_Y, 1277 0,
1327 IIO_EV_TYPE_ROC, 1278 IIO_MOD_Y,
1328 dir), 1279 IIO_EV_TYPE_ROC,
1329 data->timestamp); 1280 dir),
1281 data->timestamp);
1282
1330 if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Z) 1283 if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Z)
1331 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, 1284 iio_push_event(indio_dev,
1332 0, 1285 IIO_MOD_EVENT_CODE(IIO_ACCEL,
1333 IIO_MOD_Z, 1286 0,
1334 IIO_EV_TYPE_ROC, 1287 IIO_MOD_Z,
1335 dir), 1288 IIO_EV_TYPE_ROC,
1336 data->timestamp); 1289 dir),
1290 data->timestamp);
1291
1337 return ret; 1292 return ret;
1338} 1293}
1339 1294
@@ -1365,7 +1320,9 @@ static irqreturn_t bmc150_accel_irq_thread_handler(int irq, void *private)
1365 BMC150_ACCEL_INT_MODE_LATCH_INT | 1320 BMC150_ACCEL_INT_MODE_LATCH_INT |
1366 BMC150_ACCEL_INT_MODE_LATCH_RESET); 1321 BMC150_ACCEL_INT_MODE_LATCH_RESET);
1367 if (ret) 1322 if (ret)
1368 dev_err(&data->client->dev, "Error writing reg_int_rst_latch\n"); 1323 dev_err(&data->client->dev,
1324 "Error writing reg_int_rst_latch\n");
1325
1369 ret = IRQ_HANDLED; 1326 ret = IRQ_HANDLED;
1370 } else { 1327 } else {
1371 ret = IRQ_NONE; 1328 ret = IRQ_NONE;
@@ -1403,22 +1360,8 @@ static irqreturn_t bmc150_accel_irq_handler(int irq, void *private)
1403 return IRQ_NONE; 1360 return IRQ_NONE;
1404} 1361}
1405 1362
1406static const char *bmc150_accel_match_acpi_device(struct device *dev, int *data)
1407{
1408 const struct acpi_device_id *id;
1409
1410 id = acpi_match_device(dev->driver->acpi_match_table, dev);
1411
1412 if (!id)
1413 return NULL;
1414
1415 *data = (int) id->driver_data;
1416
1417 return dev_name(dev);
1418}
1419
1420static int bmc150_accel_gpio_probe(struct i2c_client *client, 1363static int bmc150_accel_gpio_probe(struct i2c_client *client,
1421 struct bmc150_accel_data *data) 1364 struct bmc150_accel_data *data)
1422{ 1365{
1423 struct device *dev; 1366 struct device *dev;
1424 struct gpio_desc *gpio; 1367 struct gpio_desc *gpio;
@@ -1611,6 +1554,70 @@ static const struct iio_buffer_setup_ops bmc150_accel_buffer_ops = {
1611 .postdisable = bmc150_accel_buffer_postdisable, 1554 .postdisable = bmc150_accel_buffer_postdisable,
1612}; 1555};
1613 1556
1557static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
1558{
1559 int ret, i;
1560
1561 ret = i2c_smbus_read_byte_data(data->client, BMC150_ACCEL_REG_CHIP_ID);
1562 if (ret < 0) {
1563 dev_err(&data->client->dev, "Error: Reading chip id\n");
1564 return ret;
1565 }
1566
1567 dev_dbg(&data->client->dev, "Chip Id %x\n", ret);
1568 for (i = 0; i < ARRAY_SIZE(bmc150_accel_chip_info_tbl); i++) {
1569 if (bmc150_accel_chip_info_tbl[i].chip_id == ret) {
1570 data->chip_info = &bmc150_accel_chip_info_tbl[i];
1571 break;
1572 }
1573 }
1574
1575 if (!data->chip_info) {
1576 dev_err(&data->client->dev, "Unsupported chip %x\n", ret);
1577 return -ENODEV;
1578 }
1579
1580 ret = bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_NORMAL, 0);
1581 if (ret < 0)
1582 return ret;
1583
1584 /* Set Bandwidth */
1585 ret = bmc150_accel_set_bw(data, BMC150_ACCEL_DEF_BW, 0);
1586 if (ret < 0)
1587 return ret;
1588
1589 /* Set Default Range */
1590 ret = i2c_smbus_write_byte_data(data->client,
1591 BMC150_ACCEL_REG_PMU_RANGE,
1592 BMC150_ACCEL_DEF_RANGE_4G);
1593 if (ret < 0) {
1594 dev_err(&data->client->dev, "Error writing reg_pmu_range\n");
1595 return ret;
1596 }
1597
1598 data->range = BMC150_ACCEL_DEF_RANGE_4G;
1599
1600 /* Set default slope duration and thresholds */
1601 data->slope_thres = BMC150_ACCEL_DEF_SLOPE_THRESHOLD;
1602 data->slope_dur = BMC150_ACCEL_DEF_SLOPE_DURATION;
1603 ret = bmc150_accel_update_slope(data);
1604 if (ret < 0)
1605 return ret;
1606
1607 /* Set default as latched interrupts */
1608 ret = i2c_smbus_write_byte_data(data->client,
1609 BMC150_ACCEL_REG_INT_RST_LATCH,
1610 BMC150_ACCEL_INT_MODE_LATCH_INT |
1611 BMC150_ACCEL_INT_MODE_LATCH_RESET);
1612 if (ret < 0) {
1613 dev_err(&data->client->dev,
1614 "Error writing reg_int_rst_latch\n");
1615 return ret;
1616 }
1617
1618 return 0;
1619}
1620
1614static int bmc150_accel_probe(struct i2c_client *client, 1621static int bmc150_accel_probe(struct i2c_client *client,
1615 const struct i2c_device_id *id) 1622 const struct i2c_device_id *id)
1616{ 1623{
@@ -1618,7 +1625,6 @@ static int bmc150_accel_probe(struct i2c_client *client,
1618 struct iio_dev *indio_dev; 1625 struct iio_dev *indio_dev;
1619 int ret; 1626 int ret;
1620 const char *name = NULL; 1627 const char *name = NULL;
1621 int chip_id = 0;
1622 1628
1623 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 1629 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
1624 if (!indio_dev) 1630 if (!indio_dev)
@@ -1628,15 +1634,8 @@ static int bmc150_accel_probe(struct i2c_client *client,
1628 i2c_set_clientdata(client, indio_dev); 1634 i2c_set_clientdata(client, indio_dev);
1629 data->client = client; 1635 data->client = client;
1630 1636
1631 if (id) { 1637 if (id)
1632 name = id->name; 1638 name = id->name;
1633 chip_id = id->driver_data;
1634 }
1635
1636 if (ACPI_HANDLE(&client->dev))
1637 name = bmc150_accel_match_acpi_device(&client->dev, &chip_id);
1638
1639 data->chip_info = &bmc150_accel_chip_info_tbl[chip_id];
1640 1639
1641 ret = bmc150_accel_chip_init(data); 1640 ret = bmc150_accel_chip_init(data);
1642 if (ret < 0) 1641 if (ret < 0)
@@ -1647,7 +1646,7 @@ static int bmc150_accel_probe(struct i2c_client *client,
1647 indio_dev->dev.parent = &client->dev; 1646 indio_dev->dev.parent = &client->dev;
1648 indio_dev->channels = data->chip_info->channels; 1647 indio_dev->channels = data->chip_info->channels;
1649 indio_dev->num_channels = data->chip_info->num_channels; 1648 indio_dev->num_channels = data->chip_info->num_channels;
1650 indio_dev->name = name; 1649 indio_dev->name = name ? name : data->chip_info->name;
1651 indio_dev->modes = INDIO_DIRECT_MODE; 1650 indio_dev->modes = INDIO_DIRECT_MODE;
1652 indio_dev->info = &bmc150_accel_info; 1651 indio_dev->info = &bmc150_accel_info;
1653 1652
@@ -1663,7 +1662,7 @@ static int bmc150_accel_probe(struct i2c_client *client,
1663 if (client->irq < 0) 1662 if (client->irq < 0)
1664 client->irq = bmc150_accel_gpio_probe(client, data); 1663 client->irq = bmc150_accel_gpio_probe(client, data);
1665 1664
1666 if (client->irq >= 0) { 1665 if (client->irq > 0) {
1667 ret = devm_request_threaded_irq( 1666 ret = devm_request_threaded_irq(
1668 &client->dev, client->irq, 1667 &client->dev, client->irq,
1669 bmc150_accel_irq_handler, 1668 bmc150_accel_irq_handler,
diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
index 0d9bd35ff258..3292bc0c1d0e 100644
--- a/drivers/iio/accel/kxcjk-1013.c
+++ b/drivers/iio/accel/kxcjk-1013.c
@@ -658,10 +658,8 @@ static int kxcjk1013_set_scale(struct kxcjk1013_data *data, int val)
658 int ret, i; 658 int ret, i;
659 enum kxcjk1013_mode store_mode; 659 enum kxcjk1013_mode store_mode;
660 660
661
662 for (i = 0; i < ARRAY_SIZE(KXCJK1013_scale_table); ++i) { 661 for (i = 0; i < ARRAY_SIZE(KXCJK1013_scale_table); ++i) {
663 if (KXCJK1013_scale_table[i].scale == val) { 662 if (KXCJK1013_scale_table[i].scale == val) {
664
665 ret = kxcjk1013_get_mode(data, &store_mode); 663 ret = kxcjk1013_get_mode(data, &store_mode);
666 if (ret < 0) 664 if (ret < 0)
667 return ret; 665 return ret;
@@ -820,7 +818,6 @@ static int kxcjk1013_read_event_config(struct iio_dev *indio_dev,
820 enum iio_event_type type, 818 enum iio_event_type type,
821 enum iio_event_direction dir) 819 enum iio_event_direction dir)
822{ 820{
823
824 struct kxcjk1013_data *data = iio_priv(indio_dev); 821 struct kxcjk1013_data *data = iio_priv(indio_dev);
825 822
826 return data->ev_enable_state; 823 return data->ev_enable_state;
@@ -1243,7 +1240,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
1243 if (client->irq < 0) 1240 if (client->irq < 0)
1244 client->irq = kxcjk1013_gpio_probe(client, data); 1241 client->irq = kxcjk1013_gpio_probe(client, data);
1245 1242
1246 if (client->irq >= 0) { 1243 if (client->irq > 0) {
1247 ret = devm_request_threaded_irq(&client->dev, client->irq, 1244 ret = devm_request_threaded_irq(&client->dev, client->irq,
1248 kxcjk1013_data_rdy_trig_poll, 1245 kxcjk1013_data_rdy_trig_poll,
1249 kxcjk1013_event_handler, 1246 kxcjk1013_event_handler,
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 13ea1ea23328..b921d84c1be6 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -16,7 +16,6 @@
16#include <linux/i2c.h> 16#include <linux/i2c.h>
17#include <linux/iio/iio.h> 17#include <linux/iio/iio.h>
18#include <linux/iio/sysfs.h> 18#include <linux/iio/sysfs.h>
19#include <linux/iio/trigger_consumer.h>
20#include <linux/iio/buffer.h> 19#include <linux/iio/buffer.h>
21#include <linux/iio/trigger.h> 20#include <linux/iio/trigger.h>
22#include <linux/iio/trigger_consumer.h> 21#include <linux/iio/trigger_consumer.h>
@@ -24,54 +23,51 @@
24#include <linux/iio/events.h> 23#include <linux/iio/events.h>
25#include <linux/delay.h> 24#include <linux/delay.h>
26 25
27#define MMA8452_STATUS 0x00 26#define MMA8452_STATUS 0x00
28#define MMA8452_OUT_X 0x01 /* MSB first, 12-bit */ 27#define MMA8452_STATUS_DRDY (BIT(2) | BIT(1) | BIT(0))
29#define MMA8452_OUT_Y 0x03 28#define MMA8452_OUT_X 0x01 /* MSB first, 12-bit */
30#define MMA8452_OUT_Z 0x05 29#define MMA8452_OUT_Y 0x03
31#define MMA8452_INT_SRC 0x0c 30#define MMA8452_OUT_Z 0x05
32#define MMA8452_WHO_AM_I 0x0d 31#define MMA8452_INT_SRC 0x0c
33#define MMA8452_DATA_CFG 0x0e 32#define MMA8452_WHO_AM_I 0x0d
34#define MMA8452_HP_FILTER_CUTOFF 0x0f 33#define MMA8452_DATA_CFG 0x0e
35#define MMA8452_HP_FILTER_CUTOFF_SEL_MASK (BIT(0) | BIT(1)) 34#define MMA8452_DATA_CFG_FS_MASK GENMASK(1, 0)
36#define MMA8452_TRANSIENT_CFG 0x1d 35#define MMA8452_DATA_CFG_FS_2G 0
37#define MMA8452_TRANSIENT_CFG_ELE BIT(4) 36#define MMA8452_DATA_CFG_FS_4G 1
38#define MMA8452_TRANSIENT_CFG_CHAN(chan) BIT(chan + 1) 37#define MMA8452_DATA_CFG_FS_8G 2
39#define MMA8452_TRANSIENT_CFG_HPF_BYP BIT(0) 38#define MMA8452_DATA_CFG_HPF_MASK BIT(4)
40#define MMA8452_TRANSIENT_SRC 0x1e 39#define MMA8452_HP_FILTER_CUTOFF 0x0f
41#define MMA8452_TRANSIENT_SRC_XTRANSE BIT(1) 40#define MMA8452_HP_FILTER_CUTOFF_SEL_MASK GENMASK(1, 0)
42#define MMA8452_TRANSIENT_SRC_YTRANSE BIT(3) 41#define MMA8452_TRANSIENT_CFG 0x1d
43#define MMA8452_TRANSIENT_SRC_ZTRANSE BIT(5) 42#define MMA8452_TRANSIENT_CFG_HPF_BYP BIT(0)
44#define MMA8452_TRANSIENT_THS 0x1f 43#define MMA8452_TRANSIENT_CFG_CHAN(chan) BIT(chan + 1)
45#define MMA8452_TRANSIENT_THS_MASK 0x7f 44#define MMA8452_TRANSIENT_CFG_ELE BIT(4)
46#define MMA8452_TRANSIENT_COUNT 0x20 45#define MMA8452_TRANSIENT_SRC 0x1e
47#define MMA8452_OFF_X 0x2f 46#define MMA8452_TRANSIENT_SRC_XTRANSE BIT(1)
48#define MMA8452_OFF_Y 0x30 47#define MMA8452_TRANSIENT_SRC_YTRANSE BIT(3)
49#define MMA8452_OFF_Z 0x31 48#define MMA8452_TRANSIENT_SRC_ZTRANSE BIT(5)
50#define MMA8452_CTRL_REG1 0x2a 49#define MMA8452_TRANSIENT_THS 0x1f
51#define MMA8452_CTRL_REG2 0x2b 50#define MMA8452_TRANSIENT_THS_MASK GENMASK(6, 0)
52#define MMA8452_CTRL_REG2_RST BIT(6) 51#define MMA8452_TRANSIENT_COUNT 0x20
53#define MMA8452_CTRL_REG4 0x2d 52#define MMA8452_CTRL_REG1 0x2a
54#define MMA8452_CTRL_REG5 0x2e 53#define MMA8452_CTRL_ACTIVE BIT(0)
55 54#define MMA8452_CTRL_DR_MASK GENMASK(5, 3)
56#define MMA8452_MAX_REG 0x31 55#define MMA8452_CTRL_DR_SHIFT 3
57 56#define MMA8452_CTRL_DR_DEFAULT 0x4 /* 50 Hz sample frequency */
58#define MMA8452_STATUS_DRDY (BIT(2) | BIT(1) | BIT(0)) 57#define MMA8452_CTRL_REG2 0x2b
59 58#define MMA8452_CTRL_REG2_RST BIT(6)
60#define MMA8452_CTRL_DR_MASK (BIT(5) | BIT(4) | BIT(3)) 59#define MMA8452_CTRL_REG4 0x2d
61#define MMA8452_CTRL_DR_SHIFT 3 60#define MMA8452_CTRL_REG5 0x2e
62#define MMA8452_CTRL_DR_DEFAULT 0x4 /* 50 Hz sample frequency */ 61#define MMA8452_OFF_X 0x2f
63#define MMA8452_CTRL_ACTIVE BIT(0) 62#define MMA8452_OFF_Y 0x30
64 63#define MMA8452_OFF_Z 0x31
65#define MMA8452_DATA_CFG_FS_MASK (BIT(1) | BIT(0)) 64
66#define MMA8452_DATA_CFG_FS_2G 0 65#define MMA8452_MAX_REG 0x31
67#define MMA8452_DATA_CFG_FS_4G 1 66
68#define MMA8452_DATA_CFG_FS_8G 2 67#define MMA8452_INT_DRDY BIT(0)
69#define MMA8452_DATA_CFG_HPF_MASK BIT(4) 68#define MMA8452_INT_TRANS BIT(5)
70 69
71#define MMA8452_INT_DRDY BIT(0) 70#define MMA8452_DEVICE_ID 0x2a
72#define MMA8452_INT_TRANS BIT(5)
73
74#define MMA8452_DEVICE_ID 0x2a
75 71
76struct mma8452_data { 72struct mma8452_data {
77 struct i2c_client *client; 73 struct i2c_client *client;
@@ -91,30 +87,34 @@ static int mma8452_drdy(struct mma8452_data *data)
91 return ret; 87 return ret;
92 if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY) 88 if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY)
93 return 0; 89 return 0;
90
94 msleep(20); 91 msleep(20);
95 } 92 }
96 93
97 dev_err(&data->client->dev, "data not ready\n"); 94 dev_err(&data->client->dev, "data not ready\n");
95
98 return -EIO; 96 return -EIO;
99} 97}
100 98
101static int mma8452_read(struct mma8452_data *data, __be16 buf[3]) 99static int mma8452_read(struct mma8452_data *data, __be16 buf[3])
102{ 100{
103 int ret = mma8452_drdy(data); 101 int ret = mma8452_drdy(data);
102
104 if (ret < 0) 103 if (ret < 0)
105 return ret; 104 return ret;
106 return i2c_smbus_read_i2c_block_data(data->client, 105
107 MMA8452_OUT_X, 3 * sizeof(__be16), (u8 *) buf); 106 return i2c_smbus_read_i2c_block_data(data->client, MMA8452_OUT_X,
107 3 * sizeof(__be16), (u8 *)buf);
108} 108}
109 109
110static ssize_t mma8452_show_int_plus_micros(char *buf, 110static ssize_t mma8452_show_int_plus_micros(char *buf, const int (*vals)[2],
111 const int (*vals)[2], int n) 111 int n)
112{ 112{
113 size_t len = 0; 113 size_t len = 0;
114 114
115 while (n-- > 0) 115 while (n-- > 0)
116 len += scnprintf(buf + len, PAGE_SIZE - len, 116 len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06d ",
117 "%d.%06d ", vals[n][0], vals[n][1]); 117 vals[n][0], vals[n][1]);
118 118
119 /* replace trailing space by newline */ 119 /* replace trailing space by newline */
120 buf[len - 1] = '\n'; 120 buf[len - 1] = '\n';
@@ -123,7 +123,7 @@ static ssize_t mma8452_show_int_plus_micros(char *buf,
123} 123}
124 124
125static int mma8452_get_int_plus_micros_index(const int (*vals)[2], int n, 125static int mma8452_get_int_plus_micros_index(const int (*vals)[2], int n,
126 int val, int val2) 126 int val, int val2)
127{ 127{
128 while (n-- > 0) 128 while (n-- > 0)
129 if (val == vals[n][0] && val2 == vals[n][1]) 129 if (val == vals[n][0] && val2 == vals[n][1])
@@ -147,7 +147,7 @@ static const int mma8452_samp_freq[8][2] = {
147 * Hardware has fullscale of -2G, -4G, -8G corresponding to raw value -2048 147 * Hardware has fullscale of -2G, -4G, -8G corresponding to raw value -2048
148 * The userspace interface uses m/s^2 and we declare micro units 148 * The userspace interface uses m/s^2 and we declare micro units
149 * So scale factor is given by: 149 * So scale factor is given by:
150 * g * N * 1000000 / 2048 for N = 2, 4, 8 and g=9.80665 150 * g * N * 1000000 / 2048 for N = 2, 4, 8 and g = 9.80665
151 */ 151 */
152static const int mma8452_scales[3][2] = { 152static const int mma8452_scales[3][2] = {
153 {0, 9577}, {0, 19154}, {0, 38307} 153 {0, 9577}, {0, 19154}, {0, 38307}
@@ -178,17 +178,19 @@ static const int mma8452_hp_filter_cutoff[8][4][2] = {
178}; 178};
179 179
180static ssize_t mma8452_show_samp_freq_avail(struct device *dev, 180static ssize_t mma8452_show_samp_freq_avail(struct device *dev,
181 struct device_attribute *attr, char *buf) 181 struct device_attribute *attr,
182 char *buf)
182{ 183{
183 return mma8452_show_int_plus_micros(buf, mma8452_samp_freq, 184 return mma8452_show_int_plus_micros(buf, mma8452_samp_freq,
184 ARRAY_SIZE(mma8452_samp_freq)); 185 ARRAY_SIZE(mma8452_samp_freq));
185} 186}
186 187
187static ssize_t mma8452_show_scale_avail(struct device *dev, 188static ssize_t mma8452_show_scale_avail(struct device *dev,
188 struct device_attribute *attr, char *buf) 189 struct device_attribute *attr,
190 char *buf)
189{ 191{
190 return mma8452_show_int_plus_micros(buf, mma8452_scales, 192 return mma8452_show_int_plus_micros(buf, mma8452_scales,
191 ARRAY_SIZE(mma8452_scales)); 193 ARRAY_SIZE(mma8452_scales));
192} 194}
193 195
194static ssize_t mma8452_show_hp_cutoff_avail(struct device *dev, 196static ssize_t mma8452_show_hp_cutoff_avail(struct device *dev,
@@ -205,22 +207,23 @@ static ssize_t mma8452_show_hp_cutoff_avail(struct device *dev,
205 207
206static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(mma8452_show_samp_freq_avail); 208static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(mma8452_show_samp_freq_avail);
207static IIO_DEVICE_ATTR(in_accel_scale_available, S_IRUGO, 209static IIO_DEVICE_ATTR(in_accel_scale_available, S_IRUGO,
208 mma8452_show_scale_avail, NULL, 0); 210 mma8452_show_scale_avail, NULL, 0);
209static IIO_DEVICE_ATTR(in_accel_filter_high_pass_3db_frequency_available, 211static IIO_DEVICE_ATTR(in_accel_filter_high_pass_3db_frequency_available,
210 S_IRUGO, mma8452_show_hp_cutoff_avail, NULL, 0); 212 S_IRUGO, mma8452_show_hp_cutoff_avail, NULL, 0);
211 213
212static int mma8452_get_samp_freq_index(struct mma8452_data *data, 214static int mma8452_get_samp_freq_index(struct mma8452_data *data,
213 int val, int val2) 215 int val, int val2)
214{ 216{
215 return mma8452_get_int_plus_micros_index(mma8452_samp_freq, 217 return mma8452_get_int_plus_micros_index(mma8452_samp_freq,
216 ARRAY_SIZE(mma8452_samp_freq), val, val2); 218 ARRAY_SIZE(mma8452_samp_freq),
219 val, val2);
217} 220}
218 221
219static int mma8452_get_scale_index(struct mma8452_data *data, 222static int mma8452_get_scale_index(struct mma8452_data *data, int val, int val2)
220 int val, int val2)
221{ 223{
222 return mma8452_get_int_plus_micros_index(mma8452_scales, 224 return mma8452_get_int_plus_micros_index(mma8452_scales,
223 ARRAY_SIZE(mma8452_scales), val, val2); 225 ARRAY_SIZE(mma8452_scales),
226 val, val2);
224} 227}
225 228
226static int mma8452_get_hp_filter_index(struct mma8452_data *data, 229static int mma8452_get_hp_filter_index(struct mma8452_data *data,
@@ -229,7 +232,7 @@ static int mma8452_get_hp_filter_index(struct mma8452_data *data,
229 int i = mma8452_get_odr_index(data); 232 int i = mma8452_get_odr_index(data);
230 233
231 return mma8452_get_int_plus_micros_index(mma8452_hp_filter_cutoff[i], 234 return mma8452_get_int_plus_micros_index(mma8452_hp_filter_cutoff[i],
232 ARRAY_SIZE(mma8452_scales[0]), val, val2); 235 ARRAY_SIZE(mma8452_hp_filter_cutoff[0]), val, val2);
233} 236}
234 237
235static int mma8452_read_hp_filter(struct mma8452_data *data, int *hz, int *uHz) 238static int mma8452_read_hp_filter(struct mma8452_data *data, int *hz, int *uHz)
@@ -266,25 +269,31 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
266 mutex_unlock(&data->lock); 269 mutex_unlock(&data->lock);
267 if (ret < 0) 270 if (ret < 0)
268 return ret; 271 return ret;
269 *val = sign_extend32( 272
270 be16_to_cpu(buffer[chan->scan_index]) >> 4, 11); 273 *val = sign_extend32(be16_to_cpu(buffer[chan->scan_index]) >> 4,
274 11);
275
271 return IIO_VAL_INT; 276 return IIO_VAL_INT;
272 case IIO_CHAN_INFO_SCALE: 277 case IIO_CHAN_INFO_SCALE:
273 i = data->data_cfg & MMA8452_DATA_CFG_FS_MASK; 278 i = data->data_cfg & MMA8452_DATA_CFG_FS_MASK;
274 *val = mma8452_scales[i][0]; 279 *val = mma8452_scales[i][0];
275 *val2 = mma8452_scales[i][1]; 280 *val2 = mma8452_scales[i][1];
281
276 return IIO_VAL_INT_PLUS_MICRO; 282 return IIO_VAL_INT_PLUS_MICRO;
277 case IIO_CHAN_INFO_SAMP_FREQ: 283 case IIO_CHAN_INFO_SAMP_FREQ:
278 i = mma8452_get_odr_index(data); 284 i = mma8452_get_odr_index(data);
279 *val = mma8452_samp_freq[i][0]; 285 *val = mma8452_samp_freq[i][0];
280 *val2 = mma8452_samp_freq[i][1]; 286 *val2 = mma8452_samp_freq[i][1];
287
281 return IIO_VAL_INT_PLUS_MICRO; 288 return IIO_VAL_INT_PLUS_MICRO;
282 case IIO_CHAN_INFO_CALIBBIAS: 289 case IIO_CHAN_INFO_CALIBBIAS:
283 ret = i2c_smbus_read_byte_data(data->client, MMA8452_OFF_X + 290 ret = i2c_smbus_read_byte_data(data->client,
284 chan->scan_index); 291 MMA8452_OFF_X + chan->scan_index);
285 if (ret < 0) 292 if (ret < 0)
286 return ret; 293 return ret;
294
287 *val = sign_extend32(ret, 7); 295 *val = sign_extend32(ret, 7);
296
288 return IIO_VAL_INT; 297 return IIO_VAL_INT;
289 case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY: 298 case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY:
290 if (data->data_cfg & MMA8452_DATA_CFG_HPF_MASK) { 299 if (data->data_cfg & MMA8452_DATA_CFG_HPF_MASK) {
@@ -295,21 +304,23 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
295 *val = 0; 304 *val = 0;
296 *val2 = 0; 305 *val2 = 0;
297 } 306 }
307
298 return IIO_VAL_INT_PLUS_MICRO; 308 return IIO_VAL_INT_PLUS_MICRO;
299 } 309 }
310
300 return -EINVAL; 311 return -EINVAL;
301} 312}
302 313
303static int mma8452_standby(struct mma8452_data *data) 314static int mma8452_standby(struct mma8452_data *data)
304{ 315{
305 return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1, 316 return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1,
306 data->ctrl_reg1 & ~MMA8452_CTRL_ACTIVE); 317 data->ctrl_reg1 & ~MMA8452_CTRL_ACTIVE);
307} 318}
308 319
309static int mma8452_active(struct mma8452_data *data) 320static int mma8452_active(struct mma8452_data *data)
310{ 321{
311 return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1, 322 return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1,
312 data->ctrl_reg1); 323 data->ctrl_reg1);
313} 324}
314 325
315static int mma8452_change_config(struct mma8452_data *data, u8 reg, u8 val) 326static int mma8452_change_config(struct mma8452_data *data, u8 reg, u8 val)
@@ -334,6 +345,7 @@ static int mma8452_change_config(struct mma8452_data *data, u8 reg, u8 val)
334 ret = 0; 345 ret = 0;
335fail: 346fail:
336 mutex_unlock(&data->lock); 347 mutex_unlock(&data->lock);
348
337 return ret; 349 return ret;
338} 350}
339 351
@@ -344,12 +356,13 @@ static int mma8452_set_hp_filter_frequency(struct mma8452_data *data,
344 356
345 i = mma8452_get_hp_filter_index(data, val, val2); 357 i = mma8452_get_hp_filter_index(data, val, val2);
346 if (i < 0) 358 if (i < 0)
347 return -EINVAL; 359 return i;
348 360
349 reg = i2c_smbus_read_byte_data(data->client, 361 reg = i2c_smbus_read_byte_data(data->client,
350 MMA8452_HP_FILTER_CUTOFF); 362 MMA8452_HP_FILTER_CUTOFF);
351 if (reg < 0) 363 if (reg < 0)
352 return reg; 364 return reg;
365
353 reg &= ~MMA8452_HP_FILTER_CUTOFF_SEL_MASK; 366 reg &= ~MMA8452_HP_FILTER_CUTOFF_SEL_MASK;
354 reg |= i; 367 reg |= i;
355 368
@@ -370,25 +383,30 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
370 case IIO_CHAN_INFO_SAMP_FREQ: 383 case IIO_CHAN_INFO_SAMP_FREQ:
371 i = mma8452_get_samp_freq_index(data, val, val2); 384 i = mma8452_get_samp_freq_index(data, val, val2);
372 if (i < 0) 385 if (i < 0)
373 return -EINVAL; 386 return i;
374 387
375 data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK; 388 data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK;
376 data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT; 389 data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT;
390
377 return mma8452_change_config(data, MMA8452_CTRL_REG1, 391 return mma8452_change_config(data, MMA8452_CTRL_REG1,
378 data->ctrl_reg1); 392 data->ctrl_reg1);
379 case IIO_CHAN_INFO_SCALE: 393 case IIO_CHAN_INFO_SCALE:
380 i = mma8452_get_scale_index(data, val, val2); 394 i = mma8452_get_scale_index(data, val, val2);
381 if (i < 0) 395 if (i < 0)
382 return -EINVAL; 396 return i;
397
383 data->data_cfg &= ~MMA8452_DATA_CFG_FS_MASK; 398 data->data_cfg &= ~MMA8452_DATA_CFG_FS_MASK;
384 data->data_cfg |= i; 399 data->data_cfg |= i;
400
385 return mma8452_change_config(data, MMA8452_DATA_CFG, 401 return mma8452_change_config(data, MMA8452_DATA_CFG,
386 data->data_cfg); 402 data->data_cfg);
387 case IIO_CHAN_INFO_CALIBBIAS: 403 case IIO_CHAN_INFO_CALIBBIAS:
388 if (val < -128 || val > 127) 404 if (val < -128 || val > 127)
389 return -EINVAL; 405 return -EINVAL;
390 return mma8452_change_config(data, MMA8452_OFF_X + 406
391 chan->scan_index, val); 407 return mma8452_change_config(data,
408 MMA8452_OFF_X + chan->scan_index,
409 val);
392 410
393 case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY: 411 case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY:
394 if (val == 0 && val2 == 0) { 412 if (val == 0 && val2 == 0) {
@@ -399,8 +417,9 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
399 if (ret < 0) 417 if (ret < 0)
400 return ret; 418 return ret;
401 } 419 }
420
402 return mma8452_change_config(data, MMA8452_DATA_CFG, 421 return mma8452_change_config(data, MMA8452_DATA_CFG,
403 data->data_cfg); 422 data->data_cfg);
404 423
405 default: 424 default:
406 return -EINVAL; 425 return -EINVAL;
@@ -425,6 +444,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev,
425 return ret; 444 return ret;
426 445
427 *val = ret & MMA8452_TRANSIENT_THS_MASK; 446 *val = ret & MMA8452_TRANSIENT_THS_MASK;
447
428 return IIO_VAL_INT; 448 return IIO_VAL_INT;
429 449
430 case IIO_EV_INFO_PERIOD: 450 case IIO_EV_INFO_PERIOD:
@@ -437,6 +457,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev,
437 mma8452_get_odr_index(data)]; 457 mma8452_get_odr_index(data)];
438 *val = us / USEC_PER_SEC; 458 *val = us / USEC_PER_SEC;
439 *val2 = us % USEC_PER_SEC; 459 *val2 = us % USEC_PER_SEC;
460
440 return IIO_VAL_INT_PLUS_MICRO; 461 return IIO_VAL_INT_PLUS_MICRO;
441 462
442 case IIO_EV_INFO_HIGH_PASS_FILTER_3DB: 463 case IIO_EV_INFO_HIGH_PASS_FILTER_3DB:
@@ -453,6 +474,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev,
453 if (ret < 0) 474 if (ret < 0)
454 return ret; 475 return ret;
455 } 476 }
477
456 return IIO_VAL_INT_PLUS_MICRO; 478 return IIO_VAL_INT_PLUS_MICRO;
457 479
458 default: 480 default:
@@ -472,19 +494,22 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev,
472 494
473 switch (info) { 495 switch (info) {
474 case IIO_EV_INFO_VALUE: 496 case IIO_EV_INFO_VALUE:
475 return mma8452_change_config(data, MMA8452_TRANSIENT_THS, 497 if (val < 0 || val > MMA8452_TRANSIENT_THS_MASK)
476 val & MMA8452_TRANSIENT_THS_MASK); 498 return -EINVAL;
499
500 return mma8452_change_config(data, MMA8452_TRANSIENT_THS, val);
477 501
478 case IIO_EV_INFO_PERIOD: 502 case IIO_EV_INFO_PERIOD:
479 steps = (val * USEC_PER_SEC + val2) / 503 steps = (val * USEC_PER_SEC + val2) /
480 mma8452_transient_time_step_us[ 504 mma8452_transient_time_step_us[
481 mma8452_get_odr_index(data)]; 505 mma8452_get_odr_index(data)];
482 506
483 if (steps > 0xff) 507 if (steps < 0 || steps > 0xff)
484 return -EINVAL; 508 return -EINVAL;
485 509
486 return mma8452_change_config(data, MMA8452_TRANSIENT_COUNT, 510 return mma8452_change_config(data, MMA8452_TRANSIENT_COUNT,
487 steps); 511 steps);
512
488 case IIO_EV_INFO_HIGH_PASS_FILTER_3DB: 513 case IIO_EV_INFO_HIGH_PASS_FILTER_3DB:
489 reg = i2c_smbus_read_byte_data(data->client, 514 reg = i2c_smbus_read_byte_data(data->client,
490 MMA8452_TRANSIENT_CFG); 515 MMA8452_TRANSIENT_CFG);
@@ -499,6 +524,7 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev,
499 if (ret < 0) 524 if (ret < 0)
500 return ret; 525 return ret;
501 } 526 }
527
502 return mma8452_change_config(data, MMA8452_TRANSIENT_CFG, reg); 528 return mma8452_change_config(data, MMA8452_TRANSIENT_CFG, reg);
503 529
504 default: 530 default:
@@ -608,15 +634,16 @@ static irqreturn_t mma8452_trigger_handler(int irq, void *p)
608 u8 buffer[16]; /* 3 16-bit channels + padding + ts */ 634 u8 buffer[16]; /* 3 16-bit channels + padding + ts */
609 int ret; 635 int ret;
610 636
611 ret = mma8452_read(data, (__be16 *) buffer); 637 ret = mma8452_read(data, (__be16 *)buffer);
612 if (ret < 0) 638 if (ret < 0)
613 goto done; 639 goto done;
614 640
615 iio_push_to_buffers_with_timestamp(indio_dev, buffer, 641 iio_push_to_buffers_with_timestamp(indio_dev, buffer,
616 iio_get_time_ns()); 642 iio_get_time_ns());
617 643
618done: 644done:
619 iio_trigger_notify_done(indio_dev->trig); 645 iio_trigger_notify_done(indio_dev->trig);
646
620 return IRQ_HANDLED; 647 return IRQ_HANDLED;
621} 648}
622 649
@@ -674,10 +701,10 @@ static struct attribute_group mma8452_event_attribute_group = {
674 .modified = 1, \ 701 .modified = 1, \
675 .channel2 = IIO_MOD_##axis, \ 702 .channel2 = IIO_MOD_##axis, \
676 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 703 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
677 BIT(IIO_CHAN_INFO_CALIBBIAS), \ 704 BIT(IIO_CHAN_INFO_CALIBBIAS), \
678 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ 705 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
679 BIT(IIO_CHAN_INFO_SCALE) | \ 706 BIT(IIO_CHAN_INFO_SCALE) | \
680 BIT(IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY), \ 707 BIT(IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY), \
681 .scan_index = idx, \ 708 .scan_index = idx, \
682 .scan_type = { \ 709 .scan_type = { \
683 .sign = 's', \ 710 .sign = 's', \
@@ -780,6 +807,7 @@ static int mma8452_trigger_setup(struct iio_dev *indio_dev)
780 return ret; 807 return ret;
781 808
782 indio_dev->trig = trig; 809 indio_dev->trig = trig;
810
783 return 0; 811 return 0;
784} 812}
785 813
@@ -849,7 +877,7 @@ static int mma8452_probe(struct i2c_client *client,
849 877
850 data->data_cfg = MMA8452_DATA_CFG_FS_2G; 878 data->data_cfg = MMA8452_DATA_CFG_FS_2G;
851 ret = i2c_smbus_write_byte_data(client, MMA8452_DATA_CFG, 879 ret = i2c_smbus_write_byte_data(client, MMA8452_DATA_CFG,
852 data->data_cfg); 880 data->data_cfg);
853 if (ret < 0) 881 if (ret < 0)
854 return ret; 882 return ret;
855 883
@@ -891,14 +919,14 @@ static int mma8452_probe(struct i2c_client *client,
891 } 919 }
892 920
893 data->ctrl_reg1 = MMA8452_CTRL_ACTIVE | 921 data->ctrl_reg1 = MMA8452_CTRL_ACTIVE |
894 (MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT); 922 (MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT);
895 ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1, 923 ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1,
896 data->ctrl_reg1); 924 data->ctrl_reg1);
897 if (ret < 0) 925 if (ret < 0)
898 goto trigger_cleanup; 926 goto trigger_cleanup;
899 927
900 ret = iio_triggered_buffer_setup(indio_dev, NULL, 928 ret = iio_triggered_buffer_setup(indio_dev, NULL,
901 mma8452_trigger_handler, NULL); 929 mma8452_trigger_handler, NULL);
902 if (ret < 0) 930 if (ret < 0)
903 goto trigger_cleanup; 931 goto trigger_cleanup;
904 932
@@ -968,6 +996,7 @@ static const struct of_device_id mma8452_dt_ids[] = {
968 { .compatible = "fsl,mma8452" }, 996 { .compatible = "fsl,mma8452" },
969 { } 997 { }
970}; 998};
999MODULE_DEVICE_TABLE(of, mma8452_dt_ids);
971 1000
972static struct i2c_driver mma8452_driver = { 1001static struct i2c_driver mma8452_driver = {
973 .driver = { 1002 .driver = {
diff --git a/drivers/iio/accel/mma9551_core.c b/drivers/iio/accel/mma9551_core.c
index 2fd2a995686b..c34c5ce8123b 100644
--- a/drivers/iio/accel/mma9551_core.c
+++ b/drivers/iio/accel/mma9551_core.c
@@ -297,7 +297,7 @@ EXPORT_SYMBOL(mma9551_read_status_byte);
297 * Returns: 0 on success, negative value on failure. 297 * Returns: 0 on success, negative value on failure.
298 */ 298 */
299int mma9551_read_config_word(struct i2c_client *client, u8 app_id, 299int mma9551_read_config_word(struct i2c_client *client, u8 app_id,
300 u16 reg, u16 *val) 300 u16 reg, u16 *val)
301{ 301{
302 int ret; 302 int ret;
303 __be16 v; 303 __be16 v;
@@ -328,12 +328,12 @@ EXPORT_SYMBOL(mma9551_read_config_word);
328 * Returns: 0 on success, negative value on failure. 328 * Returns: 0 on success, negative value on failure.
329 */ 329 */
330int mma9551_write_config_word(struct i2c_client *client, u8 app_id, 330int mma9551_write_config_word(struct i2c_client *client, u8 app_id,
331 u16 reg, u16 val) 331 u16 reg, u16 val)
332{ 332{
333 __be16 v = cpu_to_be16(val); 333 __be16 v = cpu_to_be16(val);
334 334
335 return mma9551_transfer(client, app_id, MMA9551_CMD_WRITE_CONFIG, reg, 335 return mma9551_transfer(client, app_id, MMA9551_CMD_WRITE_CONFIG, reg,
336 (u8 *) &v, 2, NULL, 0); 336 (u8 *)&v, 2, NULL, 0);
337} 337}
338EXPORT_SYMBOL(mma9551_write_config_word); 338EXPORT_SYMBOL(mma9551_write_config_word);
339 339
@@ -373,7 +373,7 @@ EXPORT_SYMBOL(mma9551_read_status_word);
373 * @client: I2C client 373 * @client: I2C client
374 * @app_id: Application ID 374 * @app_id: Application ID
375 * @reg: Application register 375 * @reg: Application register
376 * @len: Length of array to read in bytes 376 * @len: Length of array to read (in words)
377 * @buf: Array of words to read 377 * @buf: Array of words to read
378 * 378 *
379 * Read multiple configuration registers (word-sized registers). 379 * Read multiple configuration registers (word-sized registers).
@@ -385,23 +385,22 @@ EXPORT_SYMBOL(mma9551_read_status_word);
385 * Returns: 0 on success, negative value on failure. 385 * Returns: 0 on success, negative value on failure.
386 */ 386 */
387int mma9551_read_config_words(struct i2c_client *client, u8 app_id, 387int mma9551_read_config_words(struct i2c_client *client, u8 app_id,
388 u16 reg, u8 len, u16 *buf) 388 u16 reg, u8 len, u16 *buf)
389{ 389{
390 int ret, i; 390 int ret, i;
391 int len_words = len / sizeof(u16);
392 __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2]; 391 __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2];
393 392
394 if (len_words > ARRAY_SIZE(be_buf)) { 393 if (len > ARRAY_SIZE(be_buf)) {
395 dev_err(&client->dev, "Invalid buffer size %d\n", len); 394 dev_err(&client->dev, "Invalid buffer size %d\n", len);
396 return -EINVAL; 395 return -EINVAL;
397 } 396 }
398 397
399 ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_CONFIG, 398 ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_CONFIG,
400 reg, NULL, 0, (u8 *) be_buf, len); 399 reg, NULL, 0, (u8 *)be_buf, len * sizeof(u16));
401 if (ret < 0) 400 if (ret < 0)
402 return ret; 401 return ret;
403 402
404 for (i = 0; i < len_words; i++) 403 for (i = 0; i < len; i++)
405 buf[i] = be16_to_cpu(be_buf[i]); 404 buf[i] = be16_to_cpu(be_buf[i]);
406 405
407 return 0; 406 return 0;
@@ -413,7 +412,7 @@ EXPORT_SYMBOL(mma9551_read_config_words);
413 * @client: I2C client 412 * @client: I2C client
414 * @app_id: Application ID 413 * @app_id: Application ID
415 * @reg: Application register 414 * @reg: Application register
416 * @len: Length of array to read in bytes 415 * @len: Length of array to read (in words)
417 * @buf: Array of words to read 416 * @buf: Array of words to read
418 * 417 *
419 * Read multiple status registers (word-sized registers). 418 * Read multiple status registers (word-sized registers).
@@ -428,20 +427,19 @@ int mma9551_read_status_words(struct i2c_client *client, u8 app_id,
428 u16 reg, u8 len, u16 *buf) 427 u16 reg, u8 len, u16 *buf)
429{ 428{
430 int ret, i; 429 int ret, i;
431 int len_words = len / sizeof(u16);
432 __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2]; 430 __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2];
433 431
434 if (len_words > ARRAY_SIZE(be_buf)) { 432 if (len > ARRAY_SIZE(be_buf)) {
435 dev_err(&client->dev, "Invalid buffer size %d\n", len); 433 dev_err(&client->dev, "Invalid buffer size %d\n", len);
436 return -EINVAL; 434 return -EINVAL;
437 } 435 }
438 436
439 ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_STATUS, 437 ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_STATUS,
440 reg, NULL, 0, (u8 *) be_buf, len); 438 reg, NULL, 0, (u8 *)be_buf, len * sizeof(u16));
441 if (ret < 0) 439 if (ret < 0)
442 return ret; 440 return ret;
443 441
444 for (i = 0; i < len_words; i++) 442 for (i = 0; i < len; i++)
445 buf[i] = be16_to_cpu(be_buf[i]); 443 buf[i] = be16_to_cpu(be_buf[i]);
446 444
447 return 0; 445 return 0;
@@ -453,7 +451,7 @@ EXPORT_SYMBOL(mma9551_read_status_words);
453 * @client: I2C client 451 * @client: I2C client
454 * @app_id: Application ID 452 * @app_id: Application ID
455 * @reg: Application register 453 * @reg: Application register
456 * @len: Length of array to write in bytes 454 * @len: Length of array to write (in words)
457 * @buf: Array of words to write 455 * @buf: Array of words to write
458 * 456 *
459 * Write multiple configuration registers (word-sized registers). 457 * Write multiple configuration registers (word-sized registers).
@@ -468,19 +466,18 @@ int mma9551_write_config_words(struct i2c_client *client, u8 app_id,
468 u16 reg, u8 len, u16 *buf) 466 u16 reg, u8 len, u16 *buf)
469{ 467{
470 int i; 468 int i;
471 int len_words = len / sizeof(u16);
472 __be16 be_buf[(MMA9551_MAX_MAILBOX_DATA_REGS - 1) / 2]; 469 __be16 be_buf[(MMA9551_MAX_MAILBOX_DATA_REGS - 1) / 2];
473 470
474 if (len_words > ARRAY_SIZE(be_buf)) { 471 if (len > ARRAY_SIZE(be_buf)) {
475 dev_err(&client->dev, "Invalid buffer size %d\n", len); 472 dev_err(&client->dev, "Invalid buffer size %d\n", len);
476 return -EINVAL; 473 return -EINVAL;
477 } 474 }
478 475
479 for (i = 0; i < len_words; i++) 476 for (i = 0; i < len; i++)
480 be_buf[i] = cpu_to_be16(buf[i]); 477 be_buf[i] = cpu_to_be16(buf[i]);
481 478
482 return mma9551_transfer(client, app_id, MMA9551_CMD_WRITE_CONFIG, 479 return mma9551_transfer(client, app_id, MMA9551_CMD_WRITE_CONFIG,
483 reg, (u8 *) be_buf, len, NULL, 0); 480 reg, (u8 *)be_buf, len * sizeof(u16), NULL, 0);
484} 481}
485EXPORT_SYMBOL(mma9551_write_config_words); 482EXPORT_SYMBOL(mma9551_write_config_words);
486 483
diff --git a/drivers/iio/accel/mma9551_core.h b/drivers/iio/accel/mma9551_core.h
index 79939e40805a..5e88e6454dfd 100644
--- a/drivers/iio/accel/mma9551_core.h
+++ b/drivers/iio/accel/mma9551_core.h
@@ -53,13 +53,13 @@ int mma9551_write_config_byte(struct i2c_client *client, u8 app_id,
53int mma9551_read_status_byte(struct i2c_client *client, u8 app_id, 53int mma9551_read_status_byte(struct i2c_client *client, u8 app_id,
54 u16 reg, u8 *val); 54 u16 reg, u8 *val);
55int mma9551_read_config_word(struct i2c_client *client, u8 app_id, 55int mma9551_read_config_word(struct i2c_client *client, u8 app_id,
56 u16 reg, u16 *val); 56 u16 reg, u16 *val);
57int mma9551_write_config_word(struct i2c_client *client, u8 app_id, 57int mma9551_write_config_word(struct i2c_client *client, u8 app_id,
58 u16 reg, u16 val); 58 u16 reg, u16 val);
59int mma9551_read_status_word(struct i2c_client *client, u8 app_id, 59int mma9551_read_status_word(struct i2c_client *client, u8 app_id,
60 u16 reg, u16 *val); 60 u16 reg, u16 *val);
61int mma9551_read_config_words(struct i2c_client *client, u8 app_id, 61int mma9551_read_config_words(struct i2c_client *client, u8 app_id,
62 u16 reg, u8 len, u16 *buf); 62 u16 reg, u8 len, u16 *buf);
63int mma9551_read_status_words(struct i2c_client *client, u8 app_id, 63int mma9551_read_status_words(struct i2c_client *client, u8 app_id,
64 u16 reg, u8 len, u16 *buf); 64 u16 reg, u8 len, u16 *buf);
65int mma9551_write_config_words(struct i2c_client *client, u8 app_id, 65int mma9551_write_config_words(struct i2c_client *client, u8 app_id,
diff --git a/drivers/iio/accel/mma9553.c b/drivers/iio/accel/mma9553.c
index 8bfc61824fb2..771858cb67a1 100644
--- a/drivers/iio/accel/mma9553.c
+++ b/drivers/iio/accel/mma9553.c
@@ -182,6 +182,10 @@ struct mma9553_conf_regs {
182 182
183struct mma9553_data { 183struct mma9553_data {
184 struct i2c_client *client; 184 struct i2c_client *client;
185 /*
186 * 1. Serialize access to HW (requested by mma9551_core API).
187 * 2. Serialize sequences that power on/off the device and access HW.
188 */
185 struct mutex mutex; 189 struct mutex mutex;
186 struct mma9553_conf_regs conf; 190 struct mma9553_conf_regs conf;
187 struct mma9553_event events[MMA9553_EVENTS_INFO_SIZE]; 191 struct mma9553_event events[MMA9553_EVENTS_INFO_SIZE];
@@ -322,7 +326,8 @@ static int mma9553_read_activity_stepcnt(struct mma9553_data *data,
322 int ret; 326 int ret;
323 327
324 ret = mma9551_read_status_words(data->client, MMA9551_APPID_PEDOMETER, 328 ret = mma9551_read_status_words(data->client, MMA9551_APPID_PEDOMETER,
325 MMA9553_REG_STATUS, sizeof(u32), buf); 329 MMA9553_REG_STATUS, ARRAY_SIZE(buf),
330 buf);
326 if (ret < 0) { 331 if (ret < 0) {
327 dev_err(&data->client->dev, 332 dev_err(&data->client->dev,
328 "error reading status and stepcnt\n"); 333 "error reading status and stepcnt\n");
@@ -342,10 +347,10 @@ static int mma9553_conf_gpio(struct mma9553_data *data)
342 struct mma9553_event *ev_step_detect; 347 struct mma9553_event *ev_step_detect;
343 bool activity_enabled; 348 bool activity_enabled;
344 349
345 activity_enabled = 350 activity_enabled = mma9553_is_any_event_enabled(data, true,
346 mma9553_is_any_event_enabled(data, true, IIO_ACTIVITY); 351 IIO_ACTIVITY);
347 ev_step_detect = 352 ev_step_detect = mma9553_get_event(data, IIO_STEPS, IIO_NO_MOD,
348 mma9553_get_event(data, IIO_STEPS, IIO_NO_MOD, IIO_EV_DIR_NONE); 353 IIO_EV_DIR_NONE);
349 354
350 /* 355 /*
351 * If both step detector and activity are enabled, use the MRGFL bit. 356 * If both step detector and activity are enabled, use the MRGFL bit.
@@ -371,9 +376,8 @@ static int mma9553_conf_gpio(struct mma9553_data *data)
371 return ret; 376 return ret;
372 } 377 }
373 378
374 ret = mma9551_gpio_config(data->client, 379 ret = mma9551_gpio_config(data->client, MMA9553_DEFAULT_GPIO_PIN, appid,
375 MMA9553_DEFAULT_GPIO_PIN, 380 bitnum, MMA9553_DEFAULT_GPIO_POLARITY);
376 appid, bitnum, MMA9553_DEFAULT_GPIO_POLARITY);
377 if (ret < 0) 381 if (ret < 0)
378 return ret; 382 return ret;
379 data->gpio_bitnum = bitnum; 383 data->gpio_bitnum = bitnum;
@@ -394,17 +398,16 @@ static int mma9553_init(struct mma9553_data *data)
394 * a device identification command to differentiate the MMA9553L 398 * a device identification command to differentiate the MMA9553L
395 * from the MMA9550L. 399 * from the MMA9550L.
396 */ 400 */
397 ret = 401 ret = mma9551_read_config_words(data->client, MMA9551_APPID_PEDOMETER,
398 mma9551_read_config_words(data->client, MMA9551_APPID_PEDOMETER, 402 MMA9553_REG_CONF_SLEEPMIN,
399 MMA9553_REG_CONF_SLEEPMIN, 403 sizeof(data->conf) / sizeof(u16),
400 sizeof(data->conf), (u16 *) &data->conf); 404 (u16 *)&data->conf);
401 if (ret < 0) { 405 if (ret < 0) {
402 dev_err(&data->client->dev, 406 dev_err(&data->client->dev,
403 "failed to read configuration registers\n"); 407 "failed to read configuration registers\n");
404 return ret; 408 return ret;
405 } 409 }
406 410
407
408 /* Reset GPIO */ 411 /* Reset GPIO */
409 data->gpio_bitnum = MMA9553_MAX_BITNUM; 412 data->gpio_bitnum = MMA9553_MAX_BITNUM;
410 ret = mma9553_conf_gpio(data); 413 ret = mma9553_conf_gpio(data);
@@ -419,18 +422,18 @@ static int mma9553_init(struct mma9553_data *data)
419 data->conf.sleepmin = MMA9553_DEFAULT_SLEEPMIN; 422 data->conf.sleepmin = MMA9553_DEFAULT_SLEEPMIN;
420 data->conf.sleepmax = MMA9553_DEFAULT_SLEEPMAX; 423 data->conf.sleepmax = MMA9553_DEFAULT_SLEEPMAX;
421 data->conf.sleepthd = MMA9553_DEFAULT_SLEEPTHD; 424 data->conf.sleepthd = MMA9553_DEFAULT_SLEEPTHD;
422 data->conf.config = 425 data->conf.config = mma9553_set_bits(data->conf.config, 1,
423 mma9553_set_bits(data->conf.config, 1, MMA9553_MASK_CONF_CONFIG); 426 MMA9553_MASK_CONF_CONFIG);
424 /* 427 /*
425 * Clear the activity debounce counter when the activity level changes, 428 * Clear the activity debounce counter when the activity level changes,
426 * so that the confidence level applies for any activity level. 429 * so that the confidence level applies for any activity level.
427 */ 430 */
428 data->conf.config = mma9553_set_bits(data->conf.config, 1, 431 data->conf.config = mma9553_set_bits(data->conf.config, 1,
429 MMA9553_MASK_CONF_ACT_DBCNTM); 432 MMA9553_MASK_CONF_ACT_DBCNTM);
430 ret = 433 ret = mma9551_write_config_words(data->client, MMA9551_APPID_PEDOMETER,
431 mma9551_write_config_words(data->client, MMA9551_APPID_PEDOMETER, 434 MMA9553_REG_CONF_SLEEPMIN,
432 MMA9553_REG_CONF_SLEEPMIN, 435 sizeof(data->conf) / sizeof(u16),
433 sizeof(data->conf), (u16 *) &data->conf); 436 (u16 *)&data->conf);
434 if (ret < 0) { 437 if (ret < 0) {
435 dev_err(&data->client->dev, 438 dev_err(&data->client->dev,
436 "failed to write configuration registers\n"); 439 "failed to write configuration registers\n");
@@ -567,7 +570,7 @@ static int mma9553_read_raw(struct iio_dev *indio_dev,
567 return IIO_VAL_INT; 570 return IIO_VAL_INT;
568 case IIO_CHAN_INFO_CALIBHEIGHT: 571 case IIO_CHAN_INFO_CALIBHEIGHT:
569 tmp = mma9553_get_bits(data->conf.height_weight, 572 tmp = mma9553_get_bits(data->conf.height_weight,
570 MMA9553_MASK_CONF_HEIGHT); 573 MMA9553_MASK_CONF_HEIGHT);
571 *val = tmp / 100; /* cm to m */ 574 *val = tmp / 100; /* cm to m */
572 *val2 = (tmp % 100) * 10000; 575 *val2 = (tmp % 100) * 10000;
573 return IIO_VAL_INT_PLUS_MICRO; 576 return IIO_VAL_INT_PLUS_MICRO;
@@ -719,7 +722,6 @@ static int mma9553_read_event_config(struct iio_dev *indio_dev,
719 enum iio_event_type type, 722 enum iio_event_type type,
720 enum iio_event_direction dir) 723 enum iio_event_direction dir)
721{ 724{
722
723 struct mma9553_data *data = iio_priv(indio_dev); 725 struct mma9553_data *data = iio_priv(indio_dev);
724 struct mma9553_event *event; 726 struct mma9553_event *event;
725 727
@@ -1026,22 +1028,22 @@ static irqreturn_t mma9553_event_handler(int irq, void *private)
1026 return IRQ_HANDLED; 1028 return IRQ_HANDLED;
1027 } 1029 }
1028 1030
1029 ev_prev_activity = 1031 ev_prev_activity = mma9553_get_event(data, IIO_ACTIVITY,
1030 mma9553_get_event(data, IIO_ACTIVITY, 1032 mma9553_activity_to_mod(
1031 mma9553_activity_to_mod(data->activity), 1033 data->activity),
1032 IIO_EV_DIR_FALLING); 1034 IIO_EV_DIR_FALLING);
1033 ev_activity = 1035 ev_activity = mma9553_get_event(data, IIO_ACTIVITY,
1034 mma9553_get_event(data, IIO_ACTIVITY, 1036 mma9553_activity_to_mod(activity),
1035 mma9553_activity_to_mod(activity), 1037 IIO_EV_DIR_RISING);
1036 IIO_EV_DIR_RISING); 1038 ev_step_detect = mma9553_get_event(data, IIO_STEPS, IIO_NO_MOD,
1037 ev_step_detect = 1039 IIO_EV_DIR_NONE);
1038 mma9553_get_event(data, IIO_STEPS, IIO_NO_MOD, IIO_EV_DIR_NONE);
1039 1040
1040 if (ev_step_detect->enabled && (stepcnt != data->stepcnt)) { 1041 if (ev_step_detect->enabled && (stepcnt != data->stepcnt)) {
1041 data->stepcnt = stepcnt; 1042 data->stepcnt = stepcnt;
1042 iio_push_event(indio_dev, 1043 iio_push_event(indio_dev,
1043 IIO_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD, 1044 IIO_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD,
1044 IIO_EV_DIR_NONE, IIO_EV_TYPE_CHANGE, 0, 0, 0), 1045 IIO_EV_DIR_NONE,
1046 IIO_EV_TYPE_CHANGE, 0, 0, 0),
1045 data->timestamp); 1047 data->timestamp);
1046 } 1048 }
1047 1049
@@ -1051,17 +1053,19 @@ static irqreturn_t mma9553_event_handler(int irq, void *private)
1051 if (ev_prev_activity && ev_prev_activity->enabled) 1053 if (ev_prev_activity && ev_prev_activity->enabled)
1052 iio_push_event(indio_dev, 1054 iio_push_event(indio_dev,
1053 IIO_EVENT_CODE(IIO_ACTIVITY, 0, 1055 IIO_EVENT_CODE(IIO_ACTIVITY, 0,
1054 ev_prev_activity->info->mod, 1056 ev_prev_activity->info->mod,
1055 IIO_EV_DIR_FALLING, 1057 IIO_EV_DIR_FALLING,
1056 IIO_EV_TYPE_THRESH, 0, 0, 0), 1058 IIO_EV_TYPE_THRESH, 0, 0,
1059 0),
1057 data->timestamp); 1060 data->timestamp);
1058 1061
1059 if (ev_activity && ev_activity->enabled) 1062 if (ev_activity && ev_activity->enabled)
1060 iio_push_event(indio_dev, 1063 iio_push_event(indio_dev,
1061 IIO_EVENT_CODE(IIO_ACTIVITY, 0, 1064 IIO_EVENT_CODE(IIO_ACTIVITY, 0,
1062 ev_activity->info->mod, 1065 ev_activity->info->mod,
1063 IIO_EV_DIR_RISING, 1066 IIO_EV_DIR_RISING,
1064 IIO_EV_TYPE_THRESH, 0, 0, 0), 1067 IIO_EV_TYPE_THRESH, 0, 0,
1068 0),
1065 data->timestamp); 1069 data->timestamp);
1066 } 1070 }
1067 mutex_unlock(&data->mutex); 1071 mutex_unlock(&data->mutex);
@@ -1145,7 +1149,7 @@ static int mma9553_probe(struct i2c_client *client,
1145 if (client->irq < 0) 1149 if (client->irq < 0)
1146 client->irq = mma9553_gpio_probe(client); 1150 client->irq = mma9553_gpio_probe(client);
1147 1151
1148 if (client->irq >= 0) { 1152 if (client->irq > 0) {
1149 ret = devm_request_threaded_irq(&client->dev, client->irq, 1153 ret = devm_request_threaded_irq(&client->dev, client->irq,
1150 mma9553_irq_handler, 1154 mma9553_irq_handler,
1151 mma9553_event_handler, 1155 mma9553_event_handler,
@@ -1156,7 +1160,6 @@ static int mma9553_probe(struct i2c_client *client,
1156 client->irq); 1160 client->irq);
1157 goto out_poweroff; 1161 goto out_poweroff;
1158 } 1162 }
1159
1160 } 1163 }
1161 1164
1162 ret = iio_device_register(indio_dev); 1165 ret = iio_device_register(indio_dev);
diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h
index aa1001931d0c..468f21fa2950 100644
--- a/drivers/iio/accel/st_accel.h
+++ b/drivers/iio/accel/st_accel.h
@@ -26,6 +26,7 @@
26#define LSM303DLH_ACCEL_DEV_NAME "lsm303dlh_accel" 26#define LSM303DLH_ACCEL_DEV_NAME "lsm303dlh_accel"
27#define LSM303DLM_ACCEL_DEV_NAME "lsm303dlm_accel" 27#define LSM303DLM_ACCEL_DEV_NAME "lsm303dlm_accel"
28#define LSM330_ACCEL_DEV_NAME "lsm330_accel" 28#define LSM330_ACCEL_DEV_NAME "lsm330_accel"
29#define LSM303AGR_ACCEL_DEV_NAME "lsm303agr_accel"
29 30
30/** 31/**
31* struct st_sensors_platform_data - default accel platform data 32* struct st_sensors_platform_data - default accel platform data
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 4002e6410444..ff30f8806880 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -226,12 +226,14 @@ static const struct iio_chan_spec st_accel_16bit_channels[] = {
226static const struct st_sensor_settings st_accel_sensors_settings[] = { 226static const struct st_sensor_settings st_accel_sensors_settings[] = {
227 { 227 {
228 .wai = ST_ACCEL_1_WAI_EXP, 228 .wai = ST_ACCEL_1_WAI_EXP,
229 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
229 .sensors_supported = { 230 .sensors_supported = {
230 [0] = LIS3DH_ACCEL_DEV_NAME, 231 [0] = LIS3DH_ACCEL_DEV_NAME,
231 [1] = LSM303DLHC_ACCEL_DEV_NAME, 232 [1] = LSM303DLHC_ACCEL_DEV_NAME,
232 [2] = LSM330D_ACCEL_DEV_NAME, 233 [2] = LSM330D_ACCEL_DEV_NAME,
233 [3] = LSM330DL_ACCEL_DEV_NAME, 234 [3] = LSM330DL_ACCEL_DEV_NAME,
234 [4] = LSM330DLC_ACCEL_DEV_NAME, 235 [4] = LSM330DLC_ACCEL_DEV_NAME,
236 [5] = LSM303AGR_ACCEL_DEV_NAME,
235 }, 237 },
236 .ch = (struct iio_chan_spec *)st_accel_12bit_channels, 238 .ch = (struct iio_chan_spec *)st_accel_12bit_channels,
237 .odr = { 239 .odr = {
@@ -297,6 +299,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
297 }, 299 },
298 { 300 {
299 .wai = ST_ACCEL_2_WAI_EXP, 301 .wai = ST_ACCEL_2_WAI_EXP,
302 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
300 .sensors_supported = { 303 .sensors_supported = {
301 [0] = LIS331DLH_ACCEL_DEV_NAME, 304 [0] = LIS331DLH_ACCEL_DEV_NAME,
302 [1] = LSM303DL_ACCEL_DEV_NAME, 305 [1] = LSM303DL_ACCEL_DEV_NAME,
@@ -359,6 +362,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
359 }, 362 },
360 { 363 {
361 .wai = ST_ACCEL_3_WAI_EXP, 364 .wai = ST_ACCEL_3_WAI_EXP,
365 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
362 .sensors_supported = { 366 .sensors_supported = {
363 [0] = LSM330_ACCEL_DEV_NAME, 367 [0] = LSM330_ACCEL_DEV_NAME,
364 }, 368 },
@@ -437,6 +441,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
437 }, 441 },
438 { 442 {
439 .wai = ST_ACCEL_4_WAI_EXP, 443 .wai = ST_ACCEL_4_WAI_EXP,
444 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
440 .sensors_supported = { 445 .sensors_supported = {
441 [0] = LIS3LV02DL_ACCEL_DEV_NAME, 446 [0] = LIS3LV02DL_ACCEL_DEV_NAME,
442 }, 447 },
@@ -494,6 +499,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
494 }, 499 },
495 { 500 {
496 .wai = ST_ACCEL_5_WAI_EXP, 501 .wai = ST_ACCEL_5_WAI_EXP,
502 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
497 .sensors_supported = { 503 .sensors_supported = {
498 [0] = LIS331DL_ACCEL_DEV_NAME, 504 [0] = LIS331DL_ACCEL_DEV_NAME,
499 }, 505 },
diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
index d4ad72ca4a3d..8b9cc84fd44f 100644
--- a/drivers/iio/accel/st_accel_i2c.c
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -68,6 +68,10 @@ static const struct of_device_id st_accel_of_match[] = {
68 .compatible = "st,lsm330-accel", 68 .compatible = "st,lsm330-accel",
69 .data = LSM330_ACCEL_DEV_NAME, 69 .data = LSM330_ACCEL_DEV_NAME,
70 }, 70 },
71 {
72 .compatible = "st,lsm303agr-accel",
73 .data = LSM303AGR_ACCEL_DEV_NAME,
74 },
71 {}, 75 {},
72}; 76};
73MODULE_DEVICE_TABLE(of, st_accel_of_match); 77MODULE_DEVICE_TABLE(of, st_accel_of_match);
@@ -116,13 +120,13 @@ static const struct i2c_device_id st_accel_id_table[] = {
116 { LSM303DL_ACCEL_DEV_NAME }, 120 { LSM303DL_ACCEL_DEV_NAME },
117 { LSM303DLM_ACCEL_DEV_NAME }, 121 { LSM303DLM_ACCEL_DEV_NAME },
118 { LSM330_ACCEL_DEV_NAME }, 122 { LSM330_ACCEL_DEV_NAME },
123 { LSM303AGR_ACCEL_DEV_NAME },
119 {}, 124 {},
120}; 125};
121MODULE_DEVICE_TABLE(i2c, st_accel_id_table); 126MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
122 127
123static struct i2c_driver st_accel_driver = { 128static struct i2c_driver st_accel_driver = {
124 .driver = { 129 .driver = {
125 .owner = THIS_MODULE,
126 .name = "st-accel-i2c", 130 .name = "st-accel-i2c",
127 .of_match_table = of_match_ptr(st_accel_of_match), 131 .of_match_table = of_match_ptr(st_accel_of_match),
128 }, 132 },
diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c
index 12ec29389e4b..54b61a3961c3 100644
--- a/drivers/iio/accel/st_accel_spi.c
+++ b/drivers/iio/accel/st_accel_spi.c
@@ -57,6 +57,7 @@ static const struct spi_device_id st_accel_id_table[] = {
57 { LSM303DL_ACCEL_DEV_NAME }, 57 { LSM303DL_ACCEL_DEV_NAME },
58 { LSM303DLM_ACCEL_DEV_NAME }, 58 { LSM303DLM_ACCEL_DEV_NAME },
59 { LSM330_ACCEL_DEV_NAME }, 59 { LSM330_ACCEL_DEV_NAME },
60 { LSM303AGR_ACCEL_DEV_NAME },
60 {}, 61 {},
61}; 62};
62MODULE_DEVICE_TABLE(spi, st_accel_id_table); 63MODULE_DEVICE_TABLE(spi, st_accel_id_table);
diff --git a/drivers/iio/accel/stk8312.c b/drivers/iio/accel/stk8312.c
index d211d9f3975b..c764af284c94 100644
--- a/drivers/iio/accel/stk8312.c
+++ b/drivers/iio/accel/stk8312.c
@@ -11,17 +11,25 @@
11 */ 11 */
12 12
13#include <linux/acpi.h> 13#include <linux/acpi.h>
14#include <linux/gpio/consumer.h>
14#include <linux/i2c.h> 15#include <linux/i2c.h>
16#include <linux/interrupt.h>
15#include <linux/kernel.h> 17#include <linux/kernel.h>
16#include <linux/module.h> 18#include <linux/module.h>
17#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/iio/buffer.h>
18#include <linux/iio/iio.h> 21#include <linux/iio/iio.h>
19#include <linux/iio/sysfs.h> 22#include <linux/iio/sysfs.h>
23#include <linux/iio/trigger.h>
24#include <linux/iio/triggered_buffer.h>
25#include <linux/iio/trigger_consumer.h>
20 26
21#define STK8312_REG_XOUT 0x00 27#define STK8312_REG_XOUT 0x00
22#define STK8312_REG_YOUT 0x01 28#define STK8312_REG_YOUT 0x01
23#define STK8312_REG_ZOUT 0x02 29#define STK8312_REG_ZOUT 0x02
30#define STK8312_REG_INTSU 0x06
24#define STK8312_REG_MODE 0x07 31#define STK8312_REG_MODE 0x07
32#define STK8312_REG_SR 0x08
25#define STK8312_REG_STH 0x13 33#define STK8312_REG_STH 0x13
26#define STK8312_REG_RESET 0x20 34#define STK8312_REG_RESET 0x20
27#define STK8312_REG_AFECTRL 0x24 35#define STK8312_REG_AFECTRL 0x24
@@ -29,14 +37,21 @@
29#define STK8312_REG_OTPDATA 0x3E 37#define STK8312_REG_OTPDATA 0x3E
30#define STK8312_REG_OTPCTRL 0x3F 38#define STK8312_REG_OTPCTRL 0x3F
31 39
32#define STK8312_MODE_ACTIVE 1 40#define STK8312_MODE_ACTIVE BIT(0)
33#define STK8312_MODE_STANDBY 0 41#define STK8312_MODE_STANDBY 0x00
34#define STK8312_MODE_MASK 0x01 42#define STK8312_MODE_INT_AH_PP 0xC0 /* active-high, push-pull */
35#define STK8312_RNG_MASK 0xC0 43#define STK8312_DREADY_BIT BIT(4)
44#define STK8312_RNG_6G 1
36#define STK8312_RNG_SHIFT 6 45#define STK8312_RNG_SHIFT 6
37#define STK8312_READ_RETRIES 16 46#define STK8312_RNG_MASK GENMASK(7, 6)
47#define STK8312_SR_MASK GENMASK(2, 0)
48#define STK8312_SR_400HZ_IDX 0
49#define STK8312_ALL_CHANNEL_MASK GENMASK(2, 0)
50#define STK8312_ALL_CHANNEL_SIZE 3
38 51
39#define STK8312_DRIVER_NAME "stk8312" 52#define STK8312_DRIVER_NAME "stk8312"
53#define STK8312_GPIO "stk8312_gpio"
54#define STK8312_IRQ_NAME "stk8312_event"
40 55
41/* 56/*
42 * The accelerometer has two measurement ranges: 57 * The accelerometer has two measurement ranges:
@@ -53,32 +68,56 @@ static const int stk8312_scale_table[][2] = {
53 {0, 461600}, {1, 231100} 68 {0, 461600}, {1, 231100}
54}; 69};
55 70
56#define STK8312_ACCEL_CHANNEL(reg, axis) { \ 71static const struct {
57 .type = IIO_ACCEL, \ 72 int val;
58 .address = reg, \ 73 int val2;
59 .modified = 1, \ 74} stk8312_samp_freq_table[] = {
60 .channel2 = IIO_MOD_##axis, \ 75 {400, 0}, {200, 0}, {100, 0}, {50, 0}, {25, 0},
61 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 76 {12, 500000}, {6, 250000}, {3, 125000}
62 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 77};
78
79#define STK8312_ACCEL_CHANNEL(index, reg, axis) { \
80 .type = IIO_ACCEL, \
81 .address = reg, \
82 .modified = 1, \
83 .channel2 = IIO_MOD_##axis, \
84 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
85 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
86 BIT(IIO_CHAN_INFO_SAMP_FREQ), \
87 .scan_index = index, \
88 .scan_type = { \
89 .sign = 's', \
90 .realbits = 8, \
91 .storagebits = 8, \
92 .endianness = IIO_CPU, \
93 }, \
63} 94}
64 95
65static const struct iio_chan_spec stk8312_channels[] = { 96static const struct iio_chan_spec stk8312_channels[] = {
66 STK8312_ACCEL_CHANNEL(STK8312_REG_XOUT, X), 97 STK8312_ACCEL_CHANNEL(0, STK8312_REG_XOUT, X),
67 STK8312_ACCEL_CHANNEL(STK8312_REG_YOUT, Y), 98 STK8312_ACCEL_CHANNEL(1, STK8312_REG_YOUT, Y),
68 STK8312_ACCEL_CHANNEL(STK8312_REG_ZOUT, Z), 99 STK8312_ACCEL_CHANNEL(2, STK8312_REG_ZOUT, Z),
100 IIO_CHAN_SOFT_TIMESTAMP(3),
69}; 101};
70 102
71struct stk8312_data { 103struct stk8312_data {
72 struct i2c_client *client; 104 struct i2c_client *client;
73 struct mutex lock; 105 struct mutex lock;
74 int range; 106 u8 range;
107 u8 sample_rate_idx;
75 u8 mode; 108 u8 mode;
109 struct iio_trigger *dready_trig;
110 bool dready_trigger_on;
111 s8 buffer[16]; /* 3x8-bit channels + 5x8 padding + 64-bit timestamp */
76}; 112};
77 113
78static IIO_CONST_ATTR(in_accel_scale_available, STK8312_SCALE_AVAIL); 114static IIO_CONST_ATTR(in_accel_scale_available, STK8312_SCALE_AVAIL);
79 115
116static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("3.125 6.25 12.5 25 50 100 200 400");
117
80static struct attribute *stk8312_attributes[] = { 118static struct attribute *stk8312_attributes[] = {
81 &iio_const_attr_in_accel_scale_available.dev_attr.attr, 119 &iio_const_attr_in_accel_scale_available.dev_attr.attr,
120 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
82 NULL, 121 NULL,
83}; 122};
84 123
@@ -105,22 +144,25 @@ static int stk8312_otp_init(struct stk8312_data *data)
105 if (ret < 0) 144 if (ret < 0)
106 goto exit_err; 145 goto exit_err;
107 count--; 146 count--;
108 } while (!(ret & 0x80) && count > 0); 147 } while (!(ret & BIT(7)) && count > 0);
109 148
110 if (count == 0) 149 if (count == 0) {
150 ret = -ETIMEDOUT;
111 goto exit_err; 151 goto exit_err;
152 }
112 153
113 ret = i2c_smbus_read_byte_data(client, STK8312_REG_OTPDATA); 154 ret = i2c_smbus_read_byte_data(client, STK8312_REG_OTPDATA);
155 if (ret == 0)
156 ret = -EINVAL;
114 if (ret < 0) 157 if (ret < 0)
115 goto exit_err; 158 goto exit_err;
116 159
117 ret = i2c_smbus_write_byte_data(data->client, 160 ret = i2c_smbus_write_byte_data(data->client, STK8312_REG_AFECTRL, ret);
118 STK8312_REG_AFECTRL, ret);
119 if (ret < 0) 161 if (ret < 0)
120 goto exit_err; 162 goto exit_err;
121 msleep(150); 163 msleep(150);
122 164
123 return ret; 165 return 0;
124 166
125exit_err: 167exit_err:
126 dev_err(&client->dev, "failed to initialize sensor\n"); 168 dev_err(&client->dev, "failed to initialize sensor\n");
@@ -130,31 +172,19 @@ exit_err:
130static int stk8312_set_mode(struct stk8312_data *data, u8 mode) 172static int stk8312_set_mode(struct stk8312_data *data, u8 mode)
131{ 173{
132 int ret; 174 int ret;
133 u8 masked_reg;
134 struct i2c_client *client = data->client; 175 struct i2c_client *client = data->client;
135 176
136 if (mode > 1) 177 if (mode == data->mode)
137 return -EINVAL;
138 else if (mode == data->mode)
139 return 0; 178 return 0;
140 179
141 ret = i2c_smbus_read_byte_data(client, STK8312_REG_MODE); 180 ret = i2c_smbus_write_byte_data(client, STK8312_REG_MODE, mode);
142 if (ret < 0) {
143 dev_err(&client->dev, "failed to change sensor mode\n");
144 return ret;
145 }
146 masked_reg = ret & (~STK8312_MODE_MASK);
147 masked_reg |= mode;
148
149 ret = i2c_smbus_write_byte_data(client,
150 STK8312_REG_MODE, masked_reg);
151 if (ret < 0) { 181 if (ret < 0) {
152 dev_err(&client->dev, "failed to change sensor mode\n"); 182 dev_err(&client->dev, "failed to change sensor mode\n");
153 return ret; 183 return ret;
154 } 184 }
155 185
156 data->mode = mode; 186 data->mode = mode;
157 if (mode == STK8312_MODE_ACTIVE) { 187 if (mode & STK8312_MODE_ACTIVE) {
158 /* Need to run OTP sequence before entering active mode */ 188 /* Need to run OTP sequence before entering active mode */
159 usleep_range(1000, 5000); 189 usleep_range(1000, 5000);
160 ret = stk8312_otp_init(data); 190 ret = stk8312_otp_init(data);
@@ -163,6 +193,92 @@ static int stk8312_set_mode(struct stk8312_data *data, u8 mode)
163 return ret; 193 return ret;
164} 194}
165 195
196static int stk8312_set_interrupts(struct stk8312_data *data, u8 int_mask)
197{
198 int ret;
199 u8 mode;
200 struct i2c_client *client = data->client;
201
202 mode = data->mode;
203 /* We need to go in standby mode to modify registers */
204 ret = stk8312_set_mode(data, STK8312_MODE_STANDBY);
205 if (ret < 0)
206 return ret;
207
208 ret = i2c_smbus_write_byte_data(client, STK8312_REG_INTSU, int_mask);
209 if (ret < 0) {
210 dev_err(&client->dev, "failed to set interrupts\n");
211 stk8312_set_mode(data, mode);
212 return ret;
213 }
214
215 return stk8312_set_mode(data, mode);
216}
217
218static int stk8312_data_rdy_trigger_set_state(struct iio_trigger *trig,
219 bool state)
220{
221 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
222 struct stk8312_data *data = iio_priv(indio_dev);
223 int ret;
224
225 if (state)
226 ret = stk8312_set_interrupts(data, STK8312_DREADY_BIT);
227 else
228 ret = stk8312_set_interrupts(data, 0x00);
229
230 if (ret < 0) {
231 dev_err(&data->client->dev, "failed to set trigger state\n");
232 return ret;
233 }
234
235 data->dready_trigger_on = state;
236
237 return 0;
238}
239
240static const struct iio_trigger_ops stk8312_trigger_ops = {
241 .set_trigger_state = stk8312_data_rdy_trigger_set_state,
242 .owner = THIS_MODULE,
243};
244
245static int stk8312_set_sample_rate(struct stk8312_data *data, u8 rate)
246{
247 int ret;
248 u8 masked_reg;
249 u8 mode;
250 struct i2c_client *client = data->client;
251
252 if (rate == data->sample_rate_idx)
253 return 0;
254
255 mode = data->mode;
256 /* We need to go in standby mode to modify registers */
257 ret = stk8312_set_mode(data, STK8312_MODE_STANDBY);
258 if (ret < 0)
259 return ret;
260
261 ret = i2c_smbus_read_byte_data(client, STK8312_REG_SR);
262 if (ret < 0)
263 goto err_activate;
264
265 masked_reg = (ret & (~STK8312_SR_MASK)) | rate;
266
267 ret = i2c_smbus_write_byte_data(client, STK8312_REG_SR, masked_reg);
268 if (ret < 0)
269 goto err_activate;
270
271 data->sample_rate_idx = rate;
272
273 return stk8312_set_mode(data, mode);
274
275err_activate:
276 dev_err(&client->dev, "failed to set sampling rate\n");
277 stk8312_set_mode(data, mode);
278
279 return ret;
280}
281
166static int stk8312_set_range(struct stk8312_data *data, u8 range) 282static int stk8312_set_range(struct stk8312_data *data, u8 range)
167{ 283{
168 int ret; 284 int ret;
@@ -182,21 +298,25 @@ static int stk8312_set_range(struct stk8312_data *data, u8 range)
182 return ret; 298 return ret;
183 299
184 ret = i2c_smbus_read_byte_data(client, STK8312_REG_STH); 300 ret = i2c_smbus_read_byte_data(client, STK8312_REG_STH);
185 if (ret < 0) { 301 if (ret < 0)
186 dev_err(&client->dev, "failed to change sensor range\n"); 302 goto err_activate;
187 return ret;
188 }
189 303
190 masked_reg = ret & (~STK8312_RNG_MASK); 304 masked_reg = ret & (~STK8312_RNG_MASK);
191 masked_reg |= range << STK8312_RNG_SHIFT; 305 masked_reg |= range << STK8312_RNG_SHIFT;
192 306
193 ret = i2c_smbus_write_byte_data(client, STK8312_REG_STH, masked_reg); 307 ret = i2c_smbus_write_byte_data(client, STK8312_REG_STH, masked_reg);
194 if (ret < 0) 308 if (ret < 0)
195 dev_err(&client->dev, "failed to change sensor range\n"); 309 goto err_activate;
196 else 310
197 data->range = range; 311 data->range = range;
198 312
199 return stk8312_set_mode(data, mode); 313 return stk8312_set_mode(data, mode);
314
315err_activate:
316 dev_err(&client->dev, "failed to change sensor range\n");
317 stk8312_set_mode(data, mode);
318
319 return ret;
200} 320}
201 321
202static int stk8312_read_accel(struct stk8312_data *data, u8 address) 322static int stk8312_read_accel(struct stk8312_data *data, u8 address)
@@ -208,12 +328,10 @@ static int stk8312_read_accel(struct stk8312_data *data, u8 address)
208 return -EINVAL; 328 return -EINVAL;
209 329
210 ret = i2c_smbus_read_byte_data(client, address); 330 ret = i2c_smbus_read_byte_data(client, address);
211 if (ret < 0) { 331 if (ret < 0)
212 dev_err(&client->dev, "register read failed\n"); 332 dev_err(&client->dev, "register read failed\n");
213 return ret;
214 }
215 333
216 return sign_extend32(ret, 7); 334 return ret;
217} 335}
218 336
219static int stk8312_read_raw(struct iio_dev *indio_dev, 337static int stk8312_read_raw(struct iio_dev *indio_dev,
@@ -221,20 +339,40 @@ static int stk8312_read_raw(struct iio_dev *indio_dev,
221 int *val, int *val2, long mask) 339 int *val, int *val2, long mask)
222{ 340{
223 struct stk8312_data *data = iio_priv(indio_dev); 341 struct stk8312_data *data = iio_priv(indio_dev);
224 342 int ret;
225 if (chan->type != IIO_ACCEL)
226 return -EINVAL;
227 343
228 switch (mask) { 344 switch (mask) {
229 case IIO_CHAN_INFO_RAW: 345 case IIO_CHAN_INFO_RAW:
346 if (iio_buffer_enabled(indio_dev))
347 return -EBUSY;
230 mutex_lock(&data->lock); 348 mutex_lock(&data->lock);
231 *val = stk8312_read_accel(data, chan->address); 349 ret = stk8312_set_mode(data, data->mode | STK8312_MODE_ACTIVE);
350 if (ret < 0) {
351 mutex_unlock(&data->lock);
352 return ret;
353 }
354 ret = stk8312_read_accel(data, chan->address);
355 if (ret < 0) {
356 stk8312_set_mode(data,
357 data->mode & (~STK8312_MODE_ACTIVE));
358 mutex_unlock(&data->lock);
359 return ret;
360 }
361 *val = sign_extend32(ret, 7);
362 ret = stk8312_set_mode(data,
363 data->mode & (~STK8312_MODE_ACTIVE));
232 mutex_unlock(&data->lock); 364 mutex_unlock(&data->lock);
365 if (ret < 0)
366 return ret;
233 return IIO_VAL_INT; 367 return IIO_VAL_INT;
234 case IIO_CHAN_INFO_SCALE: 368 case IIO_CHAN_INFO_SCALE:
235 *val = stk8312_scale_table[data->range - 1][0]; 369 *val = stk8312_scale_table[data->range - 1][0];
236 *val2 = stk8312_scale_table[data->range - 1][1]; 370 *val2 = stk8312_scale_table[data->range - 1][1];
237 return IIO_VAL_INT_PLUS_MICRO; 371 return IIO_VAL_INT_PLUS_MICRO;
372 case IIO_CHAN_INFO_SAMP_FREQ:
373 *val = stk8312_samp_freq_table[data->sample_rate_idx].val;
374 *val2 = stk8312_samp_freq_table[data->sample_rate_idx].val2;
375 return IIO_VAL_INT_PLUS_MICRO;
238 } 376 }
239 377
240 return -EINVAL; 378 return -EINVAL;
@@ -265,6 +403,20 @@ static int stk8312_write_raw(struct iio_dev *indio_dev,
265 mutex_unlock(&data->lock); 403 mutex_unlock(&data->lock);
266 404
267 return ret; 405 return ret;
406 case IIO_CHAN_INFO_SAMP_FREQ:
407 for (i = 0; i < ARRAY_SIZE(stk8312_samp_freq_table); i++)
408 if (val == stk8312_samp_freq_table[i].val &&
409 val2 == stk8312_samp_freq_table[i].val2) {
410 index = i;
411 break;
412 }
413 if (index < 0)
414 return -EINVAL;
415 mutex_lock(&data->lock);
416 ret = stk8312_set_sample_rate(data, index);
417 mutex_unlock(&data->lock);
418
419 return ret;
268 } 420 }
269 421
270 return -EINVAL; 422 return -EINVAL;
@@ -277,6 +429,105 @@ static const struct iio_info stk8312_info = {
277 .attrs = &stk8312_attribute_group, 429 .attrs = &stk8312_attribute_group,
278}; 430};
279 431
432static irqreturn_t stk8312_trigger_handler(int irq, void *p)
433{
434 struct iio_poll_func *pf = p;
435 struct iio_dev *indio_dev = pf->indio_dev;
436 struct stk8312_data *data = iio_priv(indio_dev);
437 int bit, ret, i = 0;
438
439 mutex_lock(&data->lock);
440 /*
441 * Do a bulk read if all channels are requested,
442 * from 0x00 (XOUT) to 0x02 (ZOUT)
443 */
444 if (*(indio_dev->active_scan_mask) == STK8312_ALL_CHANNEL_MASK) {
445 ret = i2c_smbus_read_i2c_block_data(data->client,
446 STK8312_REG_XOUT,
447 STK8312_ALL_CHANNEL_SIZE,
448 data->buffer);
449 if (ret < STK8312_ALL_CHANNEL_SIZE) {
450 dev_err(&data->client->dev, "register read failed\n");
451 mutex_unlock(&data->lock);
452 goto err;
453 }
454 } else {
455 for_each_set_bit(bit, indio_dev->active_scan_mask,
456 indio_dev->masklength) {
457 ret = stk8312_read_accel(data, bit);
458 if (ret < 0) {
459 mutex_unlock(&data->lock);
460 goto err;
461 }
462 data->buffer[i++] = ret;
463 }
464 }
465 mutex_unlock(&data->lock);
466
467 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
468 pf->timestamp);
469err:
470 iio_trigger_notify_done(indio_dev->trig);
471
472 return IRQ_HANDLED;
473}
474
475static irqreturn_t stk8312_data_rdy_trig_poll(int irq, void *private)
476{
477 struct iio_dev *indio_dev = private;
478 struct stk8312_data *data = iio_priv(indio_dev);
479
480 if (data->dready_trigger_on)
481 iio_trigger_poll(data->dready_trig);
482
483 return IRQ_HANDLED;
484}
485
486static int stk8312_buffer_preenable(struct iio_dev *indio_dev)
487{
488 struct stk8312_data *data = iio_priv(indio_dev);
489
490 return stk8312_set_mode(data, data->mode | STK8312_MODE_ACTIVE);
491}
492
493static int stk8312_buffer_postdisable(struct iio_dev *indio_dev)
494{
495 struct stk8312_data *data = iio_priv(indio_dev);
496
497 return stk8312_set_mode(data, data->mode & (~STK8312_MODE_ACTIVE));
498}
499
500static const struct iio_buffer_setup_ops stk8312_buffer_setup_ops = {
501 .preenable = stk8312_buffer_preenable,
502 .postenable = iio_triggered_buffer_postenable,
503 .predisable = iio_triggered_buffer_predisable,
504 .postdisable = stk8312_buffer_postdisable,
505};
506
507static int stk8312_gpio_probe(struct i2c_client *client)
508{
509 struct device *dev;
510 struct gpio_desc *gpio;
511 int ret;
512
513 if (!client)
514 return -EINVAL;
515
516 dev = &client->dev;
517
518 /* data ready gpio interrupt pin */
519 gpio = devm_gpiod_get_index(dev, STK8312_GPIO, 0, GPIOD_IN);
520 if (IS_ERR(gpio)) {
521 dev_err(dev, "acpi gpio get index failed\n");
522 return PTR_ERR(gpio);
523 }
524
525 ret = gpiod_to_irq(gpio);
526 dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
527
528 return ret;
529}
530
280static int stk8312_probe(struct i2c_client *client, 531static int stk8312_probe(struct i2c_client *client,
281 const struct i2c_device_id *id) 532 const struct i2c_device_id *id)
282{ 533{
@@ -308,30 +559,91 @@ static int stk8312_probe(struct i2c_client *client,
308 dev_err(&client->dev, "failed to reset sensor\n"); 559 dev_err(&client->dev, "failed to reset sensor\n");
309 return ret; 560 return ret;
310 } 561 }
311 ret = stk8312_set_range(data, 1); 562 data->sample_rate_idx = STK8312_SR_400HZ_IDX;
563 ret = stk8312_set_range(data, STK8312_RNG_6G);
312 if (ret < 0) 564 if (ret < 0)
313 return ret; 565 return ret;
314 566
315 ret = stk8312_set_mode(data, STK8312_MODE_ACTIVE); 567 ret = stk8312_set_mode(data,
568 STK8312_MODE_INT_AH_PP | STK8312_MODE_ACTIVE);
316 if (ret < 0) 569 if (ret < 0)
317 return ret; 570 return ret;
318 571
572 if (client->irq < 0)
573 client->irq = stk8312_gpio_probe(client);
574
575 if (client->irq >= 0) {
576 ret = devm_request_threaded_irq(&client->dev, client->irq,
577 stk8312_data_rdy_trig_poll,
578 NULL,
579 IRQF_TRIGGER_RISING |
580 IRQF_ONESHOT,
581 STK8312_IRQ_NAME,
582 indio_dev);
583 if (ret < 0) {
584 dev_err(&client->dev, "request irq %d failed\n",
585 client->irq);
586 goto err_power_off;
587 }
588
589 data->dready_trig = devm_iio_trigger_alloc(&client->dev,
590 "%s-dev%d",
591 indio_dev->name,
592 indio_dev->id);
593 if (!data->dready_trig) {
594 ret = -ENOMEM;
595 goto err_power_off;
596 }
597
598 data->dready_trig->dev.parent = &client->dev;
599 data->dready_trig->ops = &stk8312_trigger_ops;
600 iio_trigger_set_drvdata(data->dready_trig, indio_dev);
601 ret = iio_trigger_register(data->dready_trig);
602 if (ret) {
603 dev_err(&client->dev, "iio trigger register failed\n");
604 goto err_power_off;
605 }
606 }
607
608 ret = iio_triggered_buffer_setup(indio_dev,
609 iio_pollfunc_store_time,
610 stk8312_trigger_handler,
611 &stk8312_buffer_setup_ops);
612 if (ret < 0) {
613 dev_err(&client->dev, "iio triggered buffer setup failed\n");
614 goto err_trigger_unregister;
615 }
616
319 ret = iio_device_register(indio_dev); 617 ret = iio_device_register(indio_dev);
320 if (ret < 0) { 618 if (ret < 0) {
321 dev_err(&client->dev, "device_register failed\n"); 619 dev_err(&client->dev, "device_register failed\n");
322 stk8312_set_mode(data, STK8312_MODE_STANDBY); 620 goto err_buffer_cleanup;
323 } 621 }
324 622
623 return 0;
624
625err_buffer_cleanup:
626 iio_triggered_buffer_cleanup(indio_dev);
627err_trigger_unregister:
628 if (data->dready_trig)
629 iio_trigger_unregister(data->dready_trig);
630err_power_off:
631 stk8312_set_mode(data, STK8312_MODE_STANDBY);
325 return ret; 632 return ret;
326} 633}
327 634
328static int stk8312_remove(struct i2c_client *client) 635static int stk8312_remove(struct i2c_client *client)
329{ 636{
330 struct iio_dev *indio_dev = i2c_get_clientdata(client); 637 struct iio_dev *indio_dev = i2c_get_clientdata(client);
638 struct stk8312_data *data = iio_priv(indio_dev);
331 639
332 iio_device_unregister(indio_dev); 640 iio_device_unregister(indio_dev);
641 iio_triggered_buffer_cleanup(indio_dev);
642
643 if (data->dready_trig)
644 iio_trigger_unregister(data->dready_trig);
333 645
334 return stk8312_set_mode(iio_priv(indio_dev), STK8312_MODE_STANDBY); 646 return stk8312_set_mode(data, STK8312_MODE_STANDBY);
335} 647}
336 648
337#ifdef CONFIG_PM_SLEEP 649#ifdef CONFIG_PM_SLEEP
@@ -341,7 +653,7 @@ static int stk8312_suspend(struct device *dev)
341 653
342 data = iio_priv(i2c_get_clientdata(to_i2c_client(dev))); 654 data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
343 655
344 return stk8312_set_mode(data, STK8312_MODE_STANDBY); 656 return stk8312_set_mode(data, data->mode & (~STK8312_MODE_ACTIVE));
345} 657}
346 658
347static int stk8312_resume(struct device *dev) 659static int stk8312_resume(struct device *dev)
@@ -350,7 +662,7 @@ static int stk8312_resume(struct device *dev)
350 662
351 data = iio_priv(i2c_get_clientdata(to_i2c_client(dev))); 663 data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
352 664
353 return stk8312_set_mode(data, STK8312_MODE_ACTIVE); 665 return stk8312_set_mode(data, data->mode | STK8312_MODE_ACTIVE);
354} 666}
355 667
356static SIMPLE_DEV_PM_OPS(stk8312_pm_ops, stk8312_suspend, stk8312_resume); 668static SIMPLE_DEV_PM_OPS(stk8312_pm_ops, stk8312_suspend, stk8312_resume);
@@ -364,6 +676,7 @@ static const struct i2c_device_id stk8312_i2c_id[] = {
364 {"STK8312", 0}, 676 {"STK8312", 0},
365 {} 677 {}
366}; 678};
679MODULE_DEVICE_TABLE(i2c, stk8312_i2c_id);
367 680
368static const struct acpi_device_id stk8312_acpi_id[] = { 681static const struct acpi_device_id stk8312_acpi_id[] = {
369 {"STK8312", 0}, 682 {"STK8312", 0},
@@ -374,7 +687,7 @@ MODULE_DEVICE_TABLE(acpi, stk8312_acpi_id);
374 687
375static struct i2c_driver stk8312_driver = { 688static struct i2c_driver stk8312_driver = {
376 .driver = { 689 .driver = {
377 .name = "stk8312", 690 .name = STK8312_DRIVER_NAME,
378 .pm = STK8312_PM_OPS, 691 .pm = STK8312_PM_OPS,
379 .acpi_match_table = ACPI_PTR(stk8312_acpi_id), 692 .acpi_match_table = ACPI_PTR(stk8312_acpi_id),
380 }, 693 },
diff --git a/drivers/iio/accel/stk8ba50.c b/drivers/iio/accel/stk8ba50.c
index 30950c6b36de..80f77d8704b5 100644
--- a/drivers/iio/accel/stk8ba50.c
+++ b/drivers/iio/accel/stk8ba50.c
@@ -11,26 +11,42 @@
11 */ 11 */
12 12
13#include <linux/acpi.h> 13#include <linux/acpi.h>
14#include <linux/gpio/consumer.h>
14#include <linux/i2c.h> 15#include <linux/i2c.h>
16#include <linux/interrupt.h>
15#include <linux/kernel.h> 17#include <linux/kernel.h>
16#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/iio/buffer.h>
17#include <linux/iio/iio.h> 20#include <linux/iio/iio.h>
18#include <linux/iio/sysfs.h> 21#include <linux/iio/sysfs.h>
22#include <linux/iio/trigger.h>
23#include <linux/iio/triggered_buffer.h>
24#include <linux/iio/trigger_consumer.h>
19 25
20#define STK8BA50_REG_XOUT 0x02 26#define STK8BA50_REG_XOUT 0x02
21#define STK8BA50_REG_YOUT 0x04 27#define STK8BA50_REG_YOUT 0x04
22#define STK8BA50_REG_ZOUT 0x06 28#define STK8BA50_REG_ZOUT 0x06
23#define STK8BA50_REG_RANGE 0x0F 29#define STK8BA50_REG_RANGE 0x0F
30#define STK8BA50_REG_BWSEL 0x10
24#define STK8BA50_REG_POWMODE 0x11 31#define STK8BA50_REG_POWMODE 0x11
25#define STK8BA50_REG_SWRST 0x14 32#define STK8BA50_REG_SWRST 0x14
33#define STK8BA50_REG_INTEN2 0x17
34#define STK8BA50_REG_INTMAP2 0x1A
26 35
27#define STK8BA50_MODE_NORMAL 0 36#define STK8BA50_MODE_NORMAL 0
28#define STK8BA50_MODE_SUSPEND 1 37#define STK8BA50_MODE_SUSPEND 1
29#define STK8BA50_MODE_POWERBIT BIT(7) 38#define STK8BA50_MODE_POWERBIT BIT(7)
30#define STK8BA50_DATA_SHIFT 6 39#define STK8BA50_DATA_SHIFT 6
31#define STK8BA50_RESET_CMD 0xB6 40#define STK8BA50_RESET_CMD 0xB6
41#define STK8BA50_SR_1792HZ_IDX 7
42#define STK8BA50_DREADY_INT_MASK 0x10
43#define STK8BA50_DREADY_INT_MAP 0x81
44#define STK8BA50_ALL_CHANNEL_MASK 7
45#define STK8BA50_ALL_CHANNEL_SIZE 6
32 46
33#define STK8BA50_DRIVER_NAME "stk8ba50" 47#define STK8BA50_DRIVER_NAME "stk8ba50"
48#define STK8BA50_GPIO "stk8ba50_gpio"
49#define STK8BA50_IRQ_NAME "stk8ba50_event"
34 50
35#define STK8BA50_SCALE_AVAIL "0.0384 0.0767 0.1534 0.3069" 51#define STK8BA50_SCALE_AVAIL "0.0384 0.0767 0.1534 0.3069"
36 52
@@ -50,35 +66,76 @@
50 * 66 *
51 * Locally, the range is stored as a table index. 67 * Locally, the range is stored as a table index.
52 */ 68 */
53static const int stk8ba50_scale_table[][2] = { 69static const struct {
70 u8 reg_val;
71 u32 scale_val;
72} stk8ba50_scale_table[] = {
54 {3, 38400}, {5, 76700}, {8, 153400}, {12, 306900} 73 {3, 38400}, {5, 76700}, {8, 153400}, {12, 306900}
55}; 74};
56 75
76/* Sample rates are stored as { <register value>, <Hz value> } */
77static const struct {
78 u8 reg_val;
79 u16 samp_freq;
80} stk8ba50_samp_freq_table[] = {
81 {0x08, 14}, {0x09, 25}, {0x0A, 56}, {0x0B, 112},
82 {0x0C, 224}, {0x0D, 448}, {0x0E, 896}, {0x0F, 1792}
83};
84
85/* Used to map scan mask bits to their corresponding channel register. */
86static const int stk8ba50_channel_table[] = {
87 STK8BA50_REG_XOUT,
88 STK8BA50_REG_YOUT,
89 STK8BA50_REG_ZOUT
90};
91
57struct stk8ba50_data { 92struct stk8ba50_data {
58 struct i2c_client *client; 93 struct i2c_client *client;
59 struct mutex lock; 94 struct mutex lock;
60 int range; 95 int range;
96 u8 sample_rate_idx;
97 struct iio_trigger *dready_trig;
98 bool dready_trigger_on;
99 /*
100 * 3 x 16-bit channels (10-bit data, 6-bit padding) +
101 * 1 x 16 padding +
102 * 4 x 16 64-bit timestamp
103 */
104 s16 buffer[8];
61}; 105};
62 106
63#define STK8BA50_ACCEL_CHANNEL(reg, axis) { \ 107#define STK8BA50_ACCEL_CHANNEL(index, reg, axis) { \
64 .type = IIO_ACCEL, \ 108 .type = IIO_ACCEL, \
65 .address = reg, \ 109 .address = reg, \
66 .modified = 1, \ 110 .modified = 1, \
67 .channel2 = IIO_MOD_##axis, \ 111 .channel2 = IIO_MOD_##axis, \
68 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 112 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
69 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 113 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
114 BIT(IIO_CHAN_INFO_SAMP_FREQ), \
115 .scan_index = index, \
116 .scan_type = { \
117 .sign = 's', \
118 .realbits = 10, \
119 .storagebits = 16, \
120 .shift = STK8BA50_DATA_SHIFT, \
121 .endianness = IIO_CPU, \
122 }, \
70} 123}
71 124
72static const struct iio_chan_spec stk8ba50_channels[] = { 125static const struct iio_chan_spec stk8ba50_channels[] = {
73 STK8BA50_ACCEL_CHANNEL(STK8BA50_REG_XOUT, X), 126 STK8BA50_ACCEL_CHANNEL(0, STK8BA50_REG_XOUT, X),
74 STK8BA50_ACCEL_CHANNEL(STK8BA50_REG_YOUT, Y), 127 STK8BA50_ACCEL_CHANNEL(1, STK8BA50_REG_YOUT, Y),
75 STK8BA50_ACCEL_CHANNEL(STK8BA50_REG_ZOUT, Z), 128 STK8BA50_ACCEL_CHANNEL(2, STK8BA50_REG_ZOUT, Z),
129 IIO_CHAN_SOFT_TIMESTAMP(3),
76}; 130};
77 131
78static IIO_CONST_ATTR(in_accel_scale_available, STK8BA50_SCALE_AVAIL); 132static IIO_CONST_ATTR(in_accel_scale_available, STK8BA50_SCALE_AVAIL);
79 133
134static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("14 25 56 112 224 448 896 1792");
135
80static struct attribute *stk8ba50_attributes[] = { 136static struct attribute *stk8ba50_attributes[] = {
81 &iio_const_attr_in_accel_scale_available.dev_attr.attr, 137 &iio_const_attr_in_accel_scale_available.dev_attr.attr,
138 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
82 NULL, 139 NULL,
83}; 140};
84 141
@@ -97,7 +154,61 @@ static int stk8ba50_read_accel(struct stk8ba50_data *data, u8 reg)
97 return ret; 154 return ret;
98 } 155 }
99 156
100 return sign_extend32(ret >> STK8BA50_DATA_SHIFT, 9); 157 return ret;
158}
159
160static int stk8ba50_data_rdy_trigger_set_state(struct iio_trigger *trig,
161 bool state)
162{
163 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
164 struct stk8ba50_data *data = iio_priv(indio_dev);
165 int ret;
166
167 if (state)
168 ret = i2c_smbus_write_byte_data(data->client,
169 STK8BA50_REG_INTEN2, STK8BA50_DREADY_INT_MASK);
170 else
171 ret = i2c_smbus_write_byte_data(data->client,
172 STK8BA50_REG_INTEN2, 0x00);
173
174 if (ret < 0)
175 dev_err(&data->client->dev, "failed to set trigger state\n");
176 else
177 data->dready_trigger_on = state;
178
179 return ret;
180}
181
182static const struct iio_trigger_ops stk8ba50_trigger_ops = {
183 .set_trigger_state = stk8ba50_data_rdy_trigger_set_state,
184 .owner = THIS_MODULE,
185};
186
187static int stk8ba50_set_power(struct stk8ba50_data *data, bool mode)
188{
189 int ret;
190 u8 masked_reg;
191 struct i2c_client *client = data->client;
192
193 ret = i2c_smbus_read_byte_data(client, STK8BA50_REG_POWMODE);
194 if (ret < 0)
195 goto exit_err;
196
197 if (mode)
198 masked_reg = ret | STK8BA50_MODE_POWERBIT;
199 else
200 masked_reg = ret & (~STK8BA50_MODE_POWERBIT);
201
202 ret = i2c_smbus_write_byte_data(client, STK8BA50_REG_POWMODE,
203 masked_reg);
204 if (ret < 0)
205 goto exit_err;
206
207 return ret;
208
209exit_err:
210 dev_err(&client->dev, "failed to change sensor mode\n");
211 return ret;
101} 212}
102 213
103static int stk8ba50_read_raw(struct iio_dev *indio_dev, 214static int stk8ba50_read_raw(struct iio_dev *indio_dev,
@@ -105,17 +216,37 @@ static int stk8ba50_read_raw(struct iio_dev *indio_dev,
105 int *val, int *val2, long mask) 216 int *val, int *val2, long mask)
106{ 217{
107 struct stk8ba50_data *data = iio_priv(indio_dev); 218 struct stk8ba50_data *data = iio_priv(indio_dev);
219 int ret;
108 220
109 switch (mask) { 221 switch (mask) {
110 case IIO_CHAN_INFO_RAW: 222 case IIO_CHAN_INFO_RAW:
223 if (iio_buffer_enabled(indio_dev))
224 return -EBUSY;
111 mutex_lock(&data->lock); 225 mutex_lock(&data->lock);
112 *val = stk8ba50_read_accel(data, chan->address); 226 ret = stk8ba50_set_power(data, STK8BA50_MODE_NORMAL);
227 if (ret < 0) {
228 mutex_unlock(&data->lock);
229 return -EINVAL;
230 }
231 ret = stk8ba50_read_accel(data, chan->address);
232 if (ret < 0) {
233 stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
234 mutex_unlock(&data->lock);
235 return -EINVAL;
236 }
237 *val = sign_extend32(ret >> STK8BA50_DATA_SHIFT, 9);
238 stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
113 mutex_unlock(&data->lock); 239 mutex_unlock(&data->lock);
114 return IIO_VAL_INT; 240 return IIO_VAL_INT;
115 case IIO_CHAN_INFO_SCALE: 241 case IIO_CHAN_INFO_SCALE:
116 *val = 0; 242 *val = 0;
117 *val2 = stk8ba50_scale_table[data->range][1]; 243 *val2 = stk8ba50_scale_table[data->range].scale_val;
118 return IIO_VAL_INT_PLUS_MICRO; 244 return IIO_VAL_INT_PLUS_MICRO;
245 case IIO_CHAN_INFO_SAMP_FREQ:
246 *val = stk8ba50_samp_freq_table
247 [data->sample_rate_idx].samp_freq;
248 *val2 = 0;
249 return IIO_VAL_INT;
119 } 250 }
120 251
121 return -EINVAL; 252 return -EINVAL;
@@ -136,7 +267,7 @@ static int stk8ba50_write_raw(struct iio_dev *indio_dev,
136 return -EINVAL; 267 return -EINVAL;
137 268
138 for (i = 0; i < ARRAY_SIZE(stk8ba50_scale_table); i++) 269 for (i = 0; i < ARRAY_SIZE(stk8ba50_scale_table); i++)
139 if (val2 == stk8ba50_scale_table[i][1]) { 270 if (val2 == stk8ba50_scale_table[i].scale_val) {
140 index = i; 271 index = i;
141 break; 272 break;
142 } 273 }
@@ -145,7 +276,7 @@ static int stk8ba50_write_raw(struct iio_dev *indio_dev,
145 276
146 ret = i2c_smbus_write_byte_data(data->client, 277 ret = i2c_smbus_write_byte_data(data->client,
147 STK8BA50_REG_RANGE, 278 STK8BA50_REG_RANGE,
148 stk8ba50_scale_table[index][0]); 279 stk8ba50_scale_table[index].reg_val);
149 if (ret < 0) 280 if (ret < 0)
150 dev_err(&data->client->dev, 281 dev_err(&data->client->dev,
151 "failed to set measurement range\n"); 282 "failed to set measurement range\n");
@@ -153,6 +284,25 @@ static int stk8ba50_write_raw(struct iio_dev *indio_dev,
153 data->range = index; 284 data->range = index;
154 285
155 return ret; 286 return ret;
287 case IIO_CHAN_INFO_SAMP_FREQ:
288 for (i = 0; i < ARRAY_SIZE(stk8ba50_samp_freq_table); i++)
289 if (val == stk8ba50_samp_freq_table[i].samp_freq) {
290 index = i;
291 break;
292 }
293 if (index < 0)
294 return -EINVAL;
295
296 ret = i2c_smbus_write_byte_data(data->client,
297 STK8BA50_REG_BWSEL,
298 stk8ba50_samp_freq_table[index].reg_val);
299 if (ret < 0)
300 dev_err(&data->client->dev,
301 "failed to set sampling rate\n");
302 else
303 data->sample_rate_idx = index;
304
305 return ret;
156 } 306 }
157 307
158 return -EINVAL; 308 return -EINVAL;
@@ -165,30 +315,100 @@ static const struct iio_info stk8ba50_info = {
165 .attrs = &stk8ba50_attribute_group, 315 .attrs = &stk8ba50_attribute_group,
166}; 316};
167 317
168static int stk8ba50_set_power(struct stk8ba50_data *data, bool mode) 318static irqreturn_t stk8ba50_trigger_handler(int irq, void *p)
169{ 319{
320 struct iio_poll_func *pf = p;
321 struct iio_dev *indio_dev = pf->indio_dev;
322 struct stk8ba50_data *data = iio_priv(indio_dev);
323 int bit, ret, i = 0;
324
325 mutex_lock(&data->lock);
326 /*
327 * Do a bulk read if all channels are requested,
328 * from 0x02 (XOUT1) to 0x07 (ZOUT2)
329 */
330 if (*(indio_dev->active_scan_mask) == STK8BA50_ALL_CHANNEL_MASK) {
331 ret = i2c_smbus_read_i2c_block_data(data->client,
332 STK8BA50_REG_XOUT,
333 STK8BA50_ALL_CHANNEL_SIZE,
334 (u8 *)data->buffer);
335 if (ret < STK8BA50_ALL_CHANNEL_SIZE) {
336 dev_err(&data->client->dev, "register read failed\n");
337 goto err;
338 }
339 } else {
340 for_each_set_bit(bit, indio_dev->active_scan_mask,
341 indio_dev->masklength) {
342 ret = stk8ba50_read_accel(data,
343 stk8ba50_channel_table[bit]);
344 if (ret < 0)
345 goto err;
346
347 data->buffer[i++] = ret;
348 }
349 }
350 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
351 pf->timestamp);
352err:
353 mutex_unlock(&data->lock);
354 iio_trigger_notify_done(indio_dev->trig);
355
356 return IRQ_HANDLED;
357}
358
359static irqreturn_t stk8ba50_data_rdy_trig_poll(int irq, void *private)
360{
361 struct iio_dev *indio_dev = private;
362 struct stk8ba50_data *data = iio_priv(indio_dev);
363
364 if (data->dready_trigger_on)
365 iio_trigger_poll(data->dready_trig);
366
367 return IRQ_HANDLED;
368}
369
370static int stk8ba50_buffer_preenable(struct iio_dev *indio_dev)
371{
372 struct stk8ba50_data *data = iio_priv(indio_dev);
373
374 return stk8ba50_set_power(data, STK8BA50_MODE_NORMAL);
375}
376
377static int stk8ba50_buffer_postdisable(struct iio_dev *indio_dev)
378{
379 struct stk8ba50_data *data = iio_priv(indio_dev);
380
381 return stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
382}
383
384static const struct iio_buffer_setup_ops stk8ba50_buffer_setup_ops = {
385 .preenable = stk8ba50_buffer_preenable,
386 .postenable = iio_triggered_buffer_postenable,
387 .predisable = iio_triggered_buffer_predisable,
388 .postdisable = stk8ba50_buffer_postdisable,
389};
390
391static int stk8ba50_gpio_probe(struct i2c_client *client)
392{
393 struct device *dev;
394 struct gpio_desc *gpio;
170 int ret; 395 int ret;
171 u8 masked_reg;
172 struct i2c_client *client = data->client;
173 396
174 ret = i2c_smbus_read_byte_data(client, STK8BA50_REG_POWMODE); 397 if (!client)
175 if (ret < 0) 398 return -EINVAL;
176 goto exit_err;
177 399
178 if (mode) 400 dev = &client->dev;
179 masked_reg = ret | STK8BA50_MODE_POWERBIT;
180 else
181 masked_reg = ret & (~STK8BA50_MODE_POWERBIT);
182 401
183 ret = i2c_smbus_write_byte_data(client, STK8BA50_REG_POWMODE, 402 /* data ready gpio interrupt pin */
184 masked_reg); 403 gpio = devm_gpiod_get_index(dev, STK8BA50_GPIO, 0, GPIOD_IN);
185 if (ret < 0) 404 if (IS_ERR(gpio)) {
186 goto exit_err; 405 dev_err(dev, "acpi gpio get index failed\n");
406 return PTR_ERR(gpio);
407 }
187 408
188 return ret; 409 ret = gpiod_to_irq(gpio);
410 dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
189 411
190exit_err:
191 dev_err(&client->dev, "failed to change sensor mode\n");
192 return ret; 412 return ret;
193} 413}
194 414
@@ -222,28 +442,104 @@ static int stk8ba50_probe(struct i2c_client *client,
222 STK8BA50_REG_SWRST, STK8BA50_RESET_CMD); 442 STK8BA50_REG_SWRST, STK8BA50_RESET_CMD);
223 if (ret < 0) { 443 if (ret < 0) {
224 dev_err(&client->dev, "failed to reset sensor\n"); 444 dev_err(&client->dev, "failed to reset sensor\n");
225 return ret; 445 goto err_power_off;
226 } 446 }
227 447
228 /* The default range is +/-2g */ 448 /* The default range is +/-2g */
229 data->range = 0; 449 data->range = 0;
230 450
451 /* The default sampling rate is 1792 Hz (maximum) */
452 data->sample_rate_idx = STK8BA50_SR_1792HZ_IDX;
453
454 /* Set up interrupts */
455 ret = i2c_smbus_write_byte_data(client,
456 STK8BA50_REG_INTEN2, STK8BA50_DREADY_INT_MASK);
457 if (ret < 0) {
458 dev_err(&client->dev, "failed to set up interrupts\n");
459 goto err_power_off;
460 }
461 ret = i2c_smbus_write_byte_data(client,
462 STK8BA50_REG_INTMAP2, STK8BA50_DREADY_INT_MAP);
463 if (ret < 0) {
464 dev_err(&client->dev, "failed to set up interrupts\n");
465 goto err_power_off;
466 }
467
468 if (client->irq < 0)
469 client->irq = stk8ba50_gpio_probe(client);
470
471 if (client->irq >= 0) {
472 ret = devm_request_threaded_irq(&client->dev, client->irq,
473 stk8ba50_data_rdy_trig_poll,
474 NULL,
475 IRQF_TRIGGER_RISING |
476 IRQF_ONESHOT,
477 STK8BA50_IRQ_NAME,
478 indio_dev);
479 if (ret < 0) {
480 dev_err(&client->dev, "request irq %d failed\n",
481 client->irq);
482 goto err_power_off;
483 }
484
485 data->dready_trig = devm_iio_trigger_alloc(&client->dev,
486 "%s-dev%d",
487 indio_dev->name,
488 indio_dev->id);
489 if (!data->dready_trig) {
490 ret = -ENOMEM;
491 goto err_power_off;
492 }
493
494 data->dready_trig->dev.parent = &client->dev;
495 data->dready_trig->ops = &stk8ba50_trigger_ops;
496 iio_trigger_set_drvdata(data->dready_trig, indio_dev);
497 ret = iio_trigger_register(data->dready_trig);
498 if (ret) {
499 dev_err(&client->dev, "iio trigger register failed\n");
500 goto err_power_off;
501 }
502 }
503
504 ret = iio_triggered_buffer_setup(indio_dev,
505 iio_pollfunc_store_time,
506 stk8ba50_trigger_handler,
507 &stk8ba50_buffer_setup_ops);
508 if (ret < 0) {
509 dev_err(&client->dev, "iio triggered buffer setup failed\n");
510 goto err_trigger_unregister;
511 }
512
231 ret = iio_device_register(indio_dev); 513 ret = iio_device_register(indio_dev);
232 if (ret < 0) { 514 if (ret < 0) {
233 dev_err(&client->dev, "device_register failed\n"); 515 dev_err(&client->dev, "device_register failed\n");
234 stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND); 516 goto err_buffer_cleanup;
235 } 517 }
236 518
237 return ret; 519 return ret;
520
521err_buffer_cleanup:
522 iio_triggered_buffer_cleanup(indio_dev);
523err_trigger_unregister:
524 if (data->dready_trig)
525 iio_trigger_unregister(data->dready_trig);
526err_power_off:
527 stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
528 return ret;
238} 529}
239 530
240static int stk8ba50_remove(struct i2c_client *client) 531static int stk8ba50_remove(struct i2c_client *client)
241{ 532{
242 struct iio_dev *indio_dev = i2c_get_clientdata(client); 533 struct iio_dev *indio_dev = i2c_get_clientdata(client);
534 struct stk8ba50_data *data = iio_priv(indio_dev);
243 535
244 iio_device_unregister(indio_dev); 536 iio_device_unregister(indio_dev);
537 iio_triggered_buffer_cleanup(indio_dev);
245 538
246 return stk8ba50_set_power(iio_priv(indio_dev), STK8BA50_MODE_SUSPEND); 539 if (data->dready_trig)
540 iio_trigger_unregister(data->dready_trig);
541
542 return stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
247} 543}
248 544
249#ifdef CONFIG_PM_SLEEP 545#ifdef CONFIG_PM_SLEEP
@@ -276,6 +572,7 @@ static const struct i2c_device_id stk8ba50_i2c_id[] = {
276 {"stk8ba50", 0}, 572 {"stk8ba50", 0},
277 {} 573 {}
278}; 574};
575MODULE_DEVICE_TABLE(i2c, stk8ba50_i2c_id);
279 576
280static const struct acpi_device_id stk8ba50_acpi_id[] = { 577static const struct acpi_device_id stk8ba50_acpi_id[] = {
281 {"STK8BA50", 0}, 578 {"STK8BA50", 0},
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index eb0cd897714a..50c103d75af9 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -20,6 +20,9 @@ config AD7266
20 Say yes here to build support for Analog Devices AD7265 and AD7266 20 Say yes here to build support for Analog Devices AD7265 and AD7266
21 ADCs. 21 ADCs.
22 22
23 To compile this driver as a module, choose M here: the module will be
24 called ad7266.
25
23config AD7291 26config AD7291
24 tristate "Analog Devices AD7291 ADC driver" 27 tristate "Analog Devices AD7291 ADC driver"
25 depends on I2C 28 depends on I2C
@@ -52,8 +55,6 @@ config AD7476
52 AD7277, AD7278, AD7475, AD7476, AD7477, AD7478, AD7466, AD7467, AD7468, 55 AD7277, AD7278, AD7475, AD7476, AD7477, AD7478, AD7466, AD7467, AD7468,
53 AD7495, AD7910, AD7920, AD7920 SPI analog to digital converters (ADC). 56 AD7495, AD7910, AD7920, AD7920 SPI analog to digital converters (ADC).
54 57
55 If unsure, say N (but it's safe to say "Y").
56
57 To compile this driver as a module, choose M here: the 58 To compile this driver as a module, choose M here: the
58 module will be called ad7476. 59 module will be called ad7476.
59 60
@@ -63,8 +64,7 @@ config AD7791
63 select AD_SIGMA_DELTA 64 select AD_SIGMA_DELTA
64 help 65 help
65 Say yes here to build support for Analog Devices AD7787, AD7788, AD7789, 66 Say yes here to build support for Analog Devices AD7787, AD7788, AD7789,
66 AD7790 and AD7791 SPI analog to digital converters (ADC). If unsure, say 67 AD7790 and AD7791 SPI analog to digital converters (ADC).
67 N (but it is safe to say "Y").
68 68
69 To compile this driver as a module, choose M here: the module will be 69 To compile this driver as a module, choose M here: the module will be
70 called ad7791. 70 called ad7791.
@@ -76,7 +76,6 @@ config AD7793
76 help 76 help
77 Say yes here to build support for Analog Devices AD7785, AD7792, AD7793, 77 Say yes here to build support for Analog Devices AD7785, AD7792, AD7793,
78 AD7794 and AD7795 SPI analog to digital converters (ADC). 78 AD7794 and AD7795 SPI analog to digital converters (ADC).
79 If unsure, say N (but it's safe to say "Y").
80 79
81 To compile this driver as a module, choose M here: the 80 To compile this driver as a module, choose M here: the
82 module will be called AD7793. 81 module will be called AD7793.
@@ -89,7 +88,6 @@ config AD7887
89 help 88 help
90 Say yes here to build support for Analog Devices 89 Say yes here to build support for Analog Devices
91 AD7887 SPI analog to digital converter (ADC). 90 AD7887 SPI analog to digital converter (ADC).
92 If unsure, say N (but it's safe to say "Y").
93 91
94 To compile this driver as a module, choose M here: the 92 To compile this driver as a module, choose M here: the
95 module will be called ad7887. 93 module will be called ad7887.
@@ -117,6 +115,9 @@ config AD799X
117 i2c analog to digital converters (ADC). Provides direct access 115 i2c analog to digital converters (ADC). Provides direct access
118 via sysfs. 116 via sysfs.
119 117
118 To compile this driver as a module, choose M here: the module will be
119 called ad799x.
120
120config AT91_ADC 121config AT91_ADC
121 tristate "Atmel AT91 ADC" 122 tristate "Atmel AT91 ADC"
122 depends on ARCH_AT91 123 depends on ARCH_AT91
@@ -127,6 +128,9 @@ config AT91_ADC
127 help 128 help
128 Say yes here to build support for Atmel AT91 ADC. 129 Say yes here to build support for Atmel AT91 ADC.
129 130
131 To compile this driver as a module, choose M here: the module will be
132 called at91_adc.
133
130config AXP288_ADC 134config AXP288_ADC
131 tristate "X-Powers AXP288 ADC driver" 135 tristate "X-Powers AXP288 ADC driver"
132 depends on MFD_AXP20X 136 depends on MFD_AXP20X
@@ -135,6 +139,9 @@ config AXP288_ADC
135 device. Depending on platform configuration, this general purpose ADC can 139 device. Depending on platform configuration, this general purpose ADC can
136 be used for sampling sensors such as thermal resistors. 140 be used for sampling sensors such as thermal resistors.
137 141
142 To compile this driver as a module, choose M here: the module will be
143 called axp288_adc.
144
138config BERLIN2_ADC 145config BERLIN2_ADC
139 tristate "Marvell Berlin2 ADC driver" 146 tristate "Marvell Berlin2 ADC driver"
140 depends on ARCH_BERLIN 147 depends on ARCH_BERLIN
@@ -151,6 +158,9 @@ config DA9150_GPADC
151 This driver can also be built as a module. If chosen, the module name 158 This driver can also be built as a module. If chosen, the module name
152 will be da9150-gpadc. 159 will be da9150-gpadc.
153 160
161 To compile this driver as a module, choose M here: the module will be
162 called berlin2-adc.
163
154config CC10001_ADC 164config CC10001_ADC
155 tristate "Cosmic Circuits 10001 ADC driver" 165 tristate "Cosmic Circuits 10001 ADC driver"
156 depends on HAS_IOMEM && HAVE_CLK && REGULATOR 166 depends on HAS_IOMEM && HAVE_CLK && REGULATOR
@@ -170,12 +180,18 @@ config EXYNOS_ADC
170 of SoCs for drivers such as the touchscreen and hwmon to use to share 180 of SoCs for drivers such as the touchscreen and hwmon to use to share
171 this resource. 181 this resource.
172 182
183 To compile this driver as a module, choose M here: the module will be
184 called exynos_adc.
185
173config LP8788_ADC 186config LP8788_ADC
174 tristate "LP8788 ADC driver" 187 tristate "LP8788 ADC driver"
175 depends on MFD_LP8788 188 depends on MFD_LP8788
176 help 189 help
177 Say yes here to build support for TI LP8788 ADC. 190 Say yes here to build support for TI LP8788 ADC.
178 191
192 To compile this driver as a module, choose M here: the module will be
193 called lp8788_adc.
194
179config MAX1027 195config MAX1027
180 tristate "Maxim max1027 ADC driver" 196 tristate "Maxim max1027 ADC driver"
181 depends on SPI 197 depends on SPI
@@ -185,6 +201,9 @@ config MAX1027
185 Say yes here to build support for Maxim SPI ADC models 201 Say yes here to build support for Maxim SPI ADC models
186 max1027, max1029 and max1031. 202 max1027, max1029 and max1031.
187 203
204 To compile this driver as a module, choose M here: the module will be
205 called max1027.
206
188config MAX1363 207config MAX1363
189 tristate "Maxim max1363 ADC driver" 208 tristate "Maxim max1363 ADC driver"
190 depends on I2C 209 depends on I2C
@@ -201,13 +220,16 @@ config MAX1363
201 max11646, max11647) Provides direct access via sysfs and buffered 220 max11646, max11647) Provides direct access via sysfs and buffered
202 data via the iio dev interface. 221 data via the iio dev interface.
203 222
223 To compile this driver as a module, choose M here: the module will be
224 called max1363.
225
204config MCP320X 226config MCP320X
205 tristate "Microchip Technology MCP3x01/02/04/08" 227 tristate "Microchip Technology MCP3x01/02/04/08"
206 depends on SPI 228 depends on SPI
207 help 229 help
208 Say yes here to build support for Microchip Technology's 230 Say yes here to build support for Microchip Technology's
209 MCP3001, MCP3002, MCP3004, MCP3008, MCP3201, MCP3202, MCP3204 or 231 MCP3001, MCP3002, MCP3004, MCP3008, MCP3201, MCP3202, MCP3204,
210 MCP3208 analog to digital converter. 232 MCP3208 or MCP3301 analog to digital converter.
211 233
212 This driver can also be built as a module. If so, the module will be 234 This driver can also be built as a module. If so, the module will be
213 called mcp320x. 235 called mcp320x.
@@ -309,15 +331,18 @@ config TI_AM335X_ADC
309 Say yes here to build support for Texas Instruments ADC 331 Say yes here to build support for Texas Instruments ADC
310 driver which is also a MFD client. 332 driver which is also a MFD client.
311 333
334 To compile this driver as a module, choose M here: the module will be
335 called ti_am335x_adc.
336
312config TWL4030_MADC 337config TWL4030_MADC
313 tristate "TWL4030 MADC (Monitoring A/D Converter)" 338 tristate "TWL4030 MADC (Monitoring A/D Converter)"
314 depends on TWL4030_CORE 339 depends on TWL4030_CORE
315 help 340 help
316 This driver provides support for Triton TWL4030-MADC. The 341 This driver provides support for Triton TWL4030-MADC. The
317 driver supports both RT and SW conversion methods. 342 driver supports both RT and SW conversion methods.
318 343
319 This driver can also be built as a module. If so, the module will be 344 This driver can also be built as a module. If so, the module will be
320 called twl4030-madc. 345 called twl4030-madc.
321 346
322config TWL6030_GPADC 347config TWL6030_GPADC
323 tristate "TWL6030 GPADC (General Purpose A/D Converter) Support" 348 tristate "TWL6030 GPADC (General Purpose A/D Converter) Support"
@@ -350,6 +375,9 @@ config VIPERBOARD_ADC
350 Say yes here to access the ADC part of the Nano River 375 Say yes here to access the ADC part of the Nano River
351 Technologies Viperboard. 376 Technologies Viperboard.
352 377
378 To compile this driver as a module, choose M here: the module will be
379 called viperboard_adc.
380
353config XILINX_XADC 381config XILINX_XADC
354 tristate "Xilinx XADC driver" 382 tristate "Xilinx XADC driver"
355 depends on ARCH_ZYNQ || MICROBLAZE || COMPILE_TEST 383 depends on ARCH_ZYNQ || MICROBLAZE || COMPILE_TEST
diff --git a/drivers/iio/adc/berlin2-adc.c b/drivers/iio/adc/berlin2-adc.c
index aecc9ad995ad..4946d9bf1764 100644
--- a/drivers/iio/adc/berlin2-adc.c
+++ b/drivers/iio/adc/berlin2-adc.c
@@ -26,7 +26,7 @@
26#define BERLIN2_SM_CTRL 0x14 26#define BERLIN2_SM_CTRL 0x14
27#define BERLIN2_SM_CTRL_SM_SOC_INT BIT(1) 27#define BERLIN2_SM_CTRL_SM_SOC_INT BIT(1)
28#define BERLIN2_SM_CTRL_SOC_SM_INT BIT(2) 28#define BERLIN2_SM_CTRL_SOC_SM_INT BIT(2)
29#define BERLIN2_SM_CTRL_ADC_SEL(x) (BIT(x) << 5) /* 0-15 */ 29#define BERLIN2_SM_CTRL_ADC_SEL(x) ((x) << 5) /* 0-15 */
30#define BERLIN2_SM_CTRL_ADC_SEL_MASK (0xf << 5) 30#define BERLIN2_SM_CTRL_ADC_SEL_MASK (0xf << 5)
31#define BERLIN2_SM_CTRL_ADC_POWER BIT(9) 31#define BERLIN2_SM_CTRL_ADC_POWER BIT(9)
32#define BERLIN2_SM_CTRL_ADC_CLKSEL_DIV2 (0x0 << 10) 32#define BERLIN2_SM_CTRL_ADC_CLKSEL_DIV2 (0x0 << 10)
@@ -53,14 +53,14 @@
53#define BERLIN2_SM_ADC_MASK 0x3ff 53#define BERLIN2_SM_ADC_MASK 0x3ff
54#define BERLIN2_SM_ADC_STATUS 0x1c 54#define BERLIN2_SM_ADC_STATUS 0x1c
55#define BERLIN2_SM_ADC_STATUS_DATA_RDY(x) BIT(x) /* 0-15 */ 55#define BERLIN2_SM_ADC_STATUS_DATA_RDY(x) BIT(x) /* 0-15 */
56#define BERLIN2_SM_ADC_STATUS_DATA_RDY_MASK 0xf 56#define BERLIN2_SM_ADC_STATUS_DATA_RDY_MASK GENMASK(15, 0)
57#define BERLIN2_SM_ADC_STATUS_INT_EN(x) (BIT(x) << 16) /* 0-15 */ 57#define BERLIN2_SM_ADC_STATUS_INT_EN(x) (BIT(x) << 16) /* 0-15 */
58#define BERLIN2_SM_ADC_STATUS_INT_EN_MASK (0xf << 16) 58#define BERLIN2_SM_ADC_STATUS_INT_EN_MASK GENMASK(31, 16)
59#define BERLIN2_SM_TSEN_STATUS 0x24 59#define BERLIN2_SM_TSEN_STATUS 0x24
60#define BERLIN2_SM_TSEN_STATUS_DATA_RDY BIT(0) 60#define BERLIN2_SM_TSEN_STATUS_DATA_RDY BIT(0)
61#define BERLIN2_SM_TSEN_STATUS_INT_EN BIT(1) 61#define BERLIN2_SM_TSEN_STATUS_INT_EN BIT(1)
62#define BERLIN2_SM_TSEN_DATA 0x28 62#define BERLIN2_SM_TSEN_DATA 0x28
63#define BERLIN2_SM_TSEN_MASK 0xfff 63#define BERLIN2_SM_TSEN_MASK GENMASK(9, 0)
64#define BERLIN2_SM_TSEN_CTRL 0x74 64#define BERLIN2_SM_TSEN_CTRL 0x74
65#define BERLIN2_SM_TSEN_CTRL_START BIT(8) 65#define BERLIN2_SM_TSEN_CTRL_START BIT(8)
66#define BERLIN2_SM_TSEN_CTRL_SETTLING_4 (0x0 << 21) /* 4 us */ 66#define BERLIN2_SM_TSEN_CTRL_SETTLING_4 (0x0 << 21) /* 4 us */
@@ -86,7 +86,7 @@ struct berlin2_adc_priv {
86 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 86 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
87 } 87 }
88 88
89static struct iio_chan_spec berlin2_adc_channels[] = { 89static const struct iio_chan_spec berlin2_adc_channels[] = {
90 BERLIN2_ADC_CHANNEL(0, IIO_VOLTAGE), /* external input */ 90 BERLIN2_ADC_CHANNEL(0, IIO_VOLTAGE), /* external input */
91 BERLIN2_ADC_CHANNEL(1, IIO_VOLTAGE), /* external input */ 91 BERLIN2_ADC_CHANNEL(1, IIO_VOLTAGE), /* external input */
92 BERLIN2_ADC_CHANNEL(2, IIO_VOLTAGE), /* external input */ 92 BERLIN2_ADC_CHANNEL(2, IIO_VOLTAGE), /* external input */
@@ -103,7 +103,6 @@ static struct iio_chan_spec berlin2_adc_channels[] = {
103 BERLIN2_ADC_CHANNEL(7, IIO_VOLTAGE), /* reserved */ 103 BERLIN2_ADC_CHANNEL(7, IIO_VOLTAGE), /* reserved */
104 IIO_CHAN_SOFT_TIMESTAMP(8), /* timestamp */ 104 IIO_CHAN_SOFT_TIMESTAMP(8), /* timestamp */
105}; 105};
106#define BERLIN2_N_CHANNELS ARRAY_SIZE(berlin2_adc_channels)
107 106
108static int berlin2_adc_read(struct iio_dev *indio_dev, int channel) 107static int berlin2_adc_read(struct iio_dev *indio_dev, int channel)
109{ 108{
@@ -221,7 +220,7 @@ static int berlin2_adc_read_raw(struct iio_dev *indio_dev,
221 return temp; 220 return temp;
222 221
223 if (temp > 2047) 222 if (temp > 2047)
224 temp = -(4096 - temp); 223 temp -= 4096;
225 224
226 /* Convert to milli Celsius */ 225 /* Convert to milli Celsius */
227 *val = ((temp * 100000) / 264 - 270000); 226 *val = ((temp * 100000) / 264 - 270000);
@@ -286,8 +285,7 @@ static int berlin2_adc_probe(struct platform_device *pdev)
286 int irq, tsen_irq; 285 int irq, tsen_irq;
287 int ret; 286 int ret;
288 287
289 indio_dev = devm_iio_device_alloc(&pdev->dev, 288 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*priv));
290 sizeof(struct berlin2_adc_priv));
291 if (!indio_dev) 289 if (!indio_dev)
292 return -ENOMEM; 290 return -ENOMEM;
293 291
@@ -301,11 +299,11 @@ static int berlin2_adc_probe(struct platform_device *pdev)
301 299
302 irq = platform_get_irq_byname(pdev, "adc"); 300 irq = platform_get_irq_byname(pdev, "adc");
303 if (irq < 0) 301 if (irq < 0)
304 return -ENODEV; 302 return irq;
305 303
306 tsen_irq = platform_get_irq_byname(pdev, "tsen"); 304 tsen_irq = platform_get_irq_byname(pdev, "tsen");
307 if (tsen_irq < 0) 305 if (tsen_irq < 0)
308 return -ENODEV; 306 return tsen_irq;
309 307
310 ret = devm_request_irq(&pdev->dev, irq, berlin2_adc_irq, 0, 308 ret = devm_request_irq(&pdev->dev, irq, berlin2_adc_irq, 0,
311 pdev->dev.driver->name, indio_dev); 309 pdev->dev.driver->name, indio_dev);
@@ -325,8 +323,8 @@ static int berlin2_adc_probe(struct platform_device *pdev)
325 indio_dev->modes = INDIO_DIRECT_MODE; 323 indio_dev->modes = INDIO_DIRECT_MODE;
326 indio_dev->info = &berlin2_adc_info; 324 indio_dev->info = &berlin2_adc_info;
327 325
328 indio_dev->num_channels = BERLIN2_N_CHANNELS;
329 indio_dev->channels = berlin2_adc_channels; 326 indio_dev->channels = berlin2_adc_channels;
327 indio_dev->num_channels = ARRAY_SIZE(berlin2_adc_channels);
330 328
331 /* Power up the ADC */ 329 /* Power up the ADC */
332 regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL, 330 regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL,
diff --git a/drivers/iio/adc/cc10001_adc.c b/drivers/iio/adc/cc10001_adc.c
index 115f6e99a7fa..8254f529b2a9 100644
--- a/drivers/iio/adc/cc10001_adc.c
+++ b/drivers/iio/adc/cc10001_adc.c
@@ -62,6 +62,7 @@ struct cc10001_adc_device {
62 struct regulator *reg; 62 struct regulator *reg;
63 u16 *buf; 63 u16 *buf;
64 64
65 bool shared;
65 struct mutex lock; 66 struct mutex lock;
66 unsigned int start_delay_ns; 67 unsigned int start_delay_ns;
67 unsigned int eoc_delay_ns; 68 unsigned int eoc_delay_ns;
@@ -153,7 +154,8 @@ static irqreturn_t cc10001_adc_trigger_h(int irq, void *p)
153 154
154 mutex_lock(&adc_dev->lock); 155 mutex_lock(&adc_dev->lock);
155 156
156 cc10001_adc_power_up(adc_dev); 157 if (!adc_dev->shared)
158 cc10001_adc_power_up(adc_dev);
157 159
158 /* Calculate delay step for eoc and sampled data */ 160 /* Calculate delay step for eoc and sampled data */
159 delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT; 161 delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT;
@@ -177,7 +179,8 @@ static irqreturn_t cc10001_adc_trigger_h(int irq, void *p)
177 } 179 }
178 180
179done: 181done:
180 cc10001_adc_power_down(adc_dev); 182 if (!adc_dev->shared)
183 cc10001_adc_power_down(adc_dev);
181 184
182 mutex_unlock(&adc_dev->lock); 185 mutex_unlock(&adc_dev->lock);
183 186
@@ -196,7 +199,8 @@ static u16 cc10001_adc_read_raw_voltage(struct iio_dev *indio_dev,
196 unsigned int delay_ns; 199 unsigned int delay_ns;
197 u16 val; 200 u16 val;
198 201
199 cc10001_adc_power_up(adc_dev); 202 if (!adc_dev->shared)
203 cc10001_adc_power_up(adc_dev);
200 204
201 /* Calculate delay step for eoc and sampled data */ 205 /* Calculate delay step for eoc and sampled data */
202 delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT; 206 delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT;
@@ -205,7 +209,8 @@ static u16 cc10001_adc_read_raw_voltage(struct iio_dev *indio_dev,
205 209
206 val = cc10001_adc_poll_done(indio_dev, chan->channel, delay_ns); 210 val = cc10001_adc_poll_done(indio_dev, chan->channel, delay_ns);
207 211
208 cc10001_adc_power_down(adc_dev); 212 if (!adc_dev->shared)
213 cc10001_adc_power_down(adc_dev);
209 214
210 return val; 215 return val;
211} 216}
@@ -322,8 +327,10 @@ static int cc10001_adc_probe(struct platform_device *pdev)
322 adc_dev = iio_priv(indio_dev); 327 adc_dev = iio_priv(indio_dev);
323 328
324 channel_map = GENMASK(CC10001_ADC_NUM_CHANNELS - 1, 0); 329 channel_map = GENMASK(CC10001_ADC_NUM_CHANNELS - 1, 0);
325 if (!of_property_read_u32(node, "adc-reserved-channels", &ret)) 330 if (!of_property_read_u32(node, "adc-reserved-channels", &ret)) {
331 adc_dev->shared = true;
326 channel_map &= ~ret; 332 channel_map &= ~ret;
333 }
327 334
328 adc_dev->reg = devm_regulator_get(&pdev->dev, "vref"); 335 adc_dev->reg = devm_regulator_get(&pdev->dev, "vref");
329 if (IS_ERR(adc_dev->reg)) 336 if (IS_ERR(adc_dev->reg))
@@ -368,6 +375,14 @@ static int cc10001_adc_probe(struct platform_device *pdev)
368 adc_dev->eoc_delay_ns = NSEC_PER_SEC / adc_clk_rate; 375 adc_dev->eoc_delay_ns = NSEC_PER_SEC / adc_clk_rate;
369 adc_dev->start_delay_ns = adc_dev->eoc_delay_ns * CC10001_WAIT_CYCLES; 376 adc_dev->start_delay_ns = adc_dev->eoc_delay_ns * CC10001_WAIT_CYCLES;
370 377
378 /*
379 * There is only one register to power-up/power-down the AUX ADC.
380 * If the ADC is shared among multiple CPUs, always power it up here.
381 * If the ADC is used only by the MIPS, power-up/power-down at runtime.
382 */
383 if (adc_dev->shared)
384 cc10001_adc_power_up(adc_dev);
385
371 /* Setup the ADC channels available on the device */ 386 /* Setup the ADC channels available on the device */
372 ret = cc10001_adc_channel_init(indio_dev, channel_map); 387 ret = cc10001_adc_channel_init(indio_dev, channel_map);
373 if (ret < 0) 388 if (ret < 0)
@@ -402,6 +417,7 @@ static int cc10001_adc_remove(struct platform_device *pdev)
402 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 417 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
403 struct cc10001_adc_device *adc_dev = iio_priv(indio_dev); 418 struct cc10001_adc_device *adc_dev = iio_priv(indio_dev);
404 419
420 cc10001_adc_power_down(adc_dev);
405 iio_device_unregister(indio_dev); 421 iio_device_unregister(indio_dev);
406 iio_triggered_buffer_cleanup(indio_dev); 422 iio_triggered_buffer_cleanup(indio_dev);
407 clk_disable_unprepare(adc_dev->adc_clk); 423 clk_disable_unprepare(adc_dev->adc_clk);
diff --git a/drivers/iio/adc/mcp320x.c b/drivers/iio/adc/mcp320x.c
index d819823f7257..b19e4f9d16e0 100644
--- a/drivers/iio/adc/mcp320x.c
+++ b/drivers/iio/adc/mcp320x.c
@@ -25,6 +25,7 @@
25 * http://ww1.microchip.com/downloads/en/DeviceDoc/21290D.pdf mcp3201 25 * http://ww1.microchip.com/downloads/en/DeviceDoc/21290D.pdf mcp3201
26 * http://ww1.microchip.com/downloads/en/DeviceDoc/21034D.pdf mcp3202 26 * http://ww1.microchip.com/downloads/en/DeviceDoc/21034D.pdf mcp3202
27 * http://ww1.microchip.com/downloads/en/DeviceDoc/21298c.pdf mcp3204/08 27 * http://ww1.microchip.com/downloads/en/DeviceDoc/21298c.pdf mcp3204/08
28 * http://ww1.microchip.com/downloads/en/DeviceDoc/21700E.pdf mcp3301
28 * 29 *
29 * This program is free software; you can redistribute it and/or modify 30 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License version 2 as 31 * it under the terms of the GNU General Public License version 2 as
@@ -47,6 +48,7 @@ enum {
47 mcp3202, 48 mcp3202,
48 mcp3204, 49 mcp3204,
49 mcp3208, 50 mcp3208,
51 mcp3301,
50}; 52};
51 53
52struct mcp320x_chip_info { 54struct mcp320x_chip_info {
@@ -76,6 +78,7 @@ static int mcp320x_channel_to_tx_data(int device_index,
76 switch (device_index) { 78 switch (device_index) {
77 case mcp3001: 79 case mcp3001:
78 case mcp3201: 80 case mcp3201:
81 case mcp3301:
79 return 0; 82 return 0;
80 case mcp3002: 83 case mcp3002:
81 case mcp3202: 84 case mcp3202:
@@ -102,7 +105,7 @@ static int mcp320x_adc_conversion(struct mcp320x *adc, u8 channel,
102 adc->tx_buf = mcp320x_channel_to_tx_data(device_index, 105 adc->tx_buf = mcp320x_channel_to_tx_data(device_index,
103 channel, differential); 106 channel, differential);
104 107
105 if (device_index != mcp3001 && device_index != mcp3201) { 108 if (device_index != mcp3001 && device_index != mcp3201 && device_index != mcp3301) {
106 ret = spi_sync(adc->spi, &adc->msg); 109 ret = spi_sync(adc->spi, &adc->msg);
107 if (ret < 0) 110 if (ret < 0)
108 return ret; 111 return ret;
@@ -125,6 +128,8 @@ static int mcp320x_adc_conversion(struct mcp320x *adc, u8 channel,
125 case mcp3204: 128 case mcp3204:
126 case mcp3208: 129 case mcp3208:
127 return (adc->rx_buf[0] << 4 | adc->rx_buf[1] >> 4); 130 return (adc->rx_buf[0] << 4 | adc->rx_buf[1] >> 4);
131 case mcp3301:
132 return sign_extend32((adc->rx_buf[0] & 0x1f) << 8 | adc->rx_buf[1], 12);
128 default: 133 default:
129 return -EINVAL; 134 return -EINVAL;
130 } 135 }
@@ -274,6 +279,11 @@ static const struct mcp320x_chip_info mcp320x_chip_infos[] = {
274 .num_channels = ARRAY_SIZE(mcp3208_channels), 279 .num_channels = ARRAY_SIZE(mcp3208_channels),
275 .resolution = 12 280 .resolution = 12
276 }, 281 },
282 [mcp3301] = {
283 .channels = mcp3201_channels,
284 .num_channels = ARRAY_SIZE(mcp3201_channels),
285 .resolution = 13
286 },
277}; 287};
278 288
279static int mcp320x_probe(struct spi_device *spi) 289static int mcp320x_probe(struct spi_device *spi)
@@ -369,6 +379,9 @@ static const struct of_device_id mcp320x_dt_ids[] = {
369 .compatible = "mcp3208", 379 .compatible = "mcp3208",
370 .data = &mcp320x_chip_infos[mcp3208], 380 .data = &mcp320x_chip_infos[mcp3208],
371 }, { 381 }, {
382 .compatible = "mcp3301",
383 .data = &mcp320x_chip_infos[mcp3301],
384 }, {
372 } 385 }
373}; 386};
374MODULE_DEVICE_TABLE(of, mcp320x_dt_ids); 387MODULE_DEVICE_TABLE(of, mcp320x_dt_ids);
@@ -383,6 +396,7 @@ static const struct spi_device_id mcp320x_id[] = {
383 { "mcp3202", mcp3202 }, 396 { "mcp3202", mcp3202 },
384 { "mcp3204", mcp3204 }, 397 { "mcp3204", mcp3204 },
385 { "mcp3208", mcp3208 }, 398 { "mcp3208", mcp3208 },
399 { "mcp3301", mcp3301 },
386 { } 400 { }
387}; 401};
388MODULE_DEVICE_TABLE(spi, mcp320x_id); 402MODULE_DEVICE_TABLE(spi, mcp320x_id);
diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c
index b96c636470ef..3555122008b4 100644
--- a/drivers/iio/adc/mcp3422.c
+++ b/drivers/iio/adc/mcp3422.c
@@ -404,7 +404,6 @@ MODULE_DEVICE_TABLE(of, mcp3422_of_match);
404static struct i2c_driver mcp3422_driver = { 404static struct i2c_driver mcp3422_driver = {
405 .driver = { 405 .driver = {
406 .name = "mcp3422", 406 .name = "mcp3422",
407 .owner = THIS_MODULE,
408 .of_match_table = of_match_ptr(mcp3422_of_match), 407 .of_match_table = of_match_ptr(mcp3422_of_match),
409 }, 408 },
410 .probe = mcp3422_probe, 409 .probe = mcp3422_probe,
diff --git a/drivers/iio/adc/ti-adc081c.c b/drivers/iio/adc/ti-adc081c.c
index b3a82b4d1a75..2c8374f86252 100644
--- a/drivers/iio/adc/ti-adc081c.c
+++ b/drivers/iio/adc/ti-adc081c.c
@@ -140,7 +140,6 @@ MODULE_DEVICE_TABLE(of, adc081c_of_match);
140static struct i2c_driver adc081c_driver = { 140static struct i2c_driver adc081c_driver = {
141 .driver = { 141 .driver = {
142 .name = "adc081c", 142 .name = "adc081c",
143 .owner = THIS_MODULE,
144 .of_match_table = of_match_ptr(adc081c_of_match), 143 .of_match_table = of_match_ptr(adc081c_of_match),
145 }, 144 },
146 .probe = adc081c_probe, 145 .probe = adc081c_probe,
diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c
index 819632bf1fda..6bf4c20eb231 100644
--- a/drivers/iio/adc/vf610_adc.c
+++ b/drivers/iio/adc/vf610_adc.c
@@ -68,6 +68,9 @@
68#define VF610_ADC_CLK_DIV8 0x60 68#define VF610_ADC_CLK_DIV8 0x60
69#define VF610_ADC_CLK_MASK 0x60 69#define VF610_ADC_CLK_MASK 0x60
70#define VF610_ADC_ADLSMP_LONG 0x10 70#define VF610_ADC_ADLSMP_LONG 0x10
71#define VF610_ADC_ADSTS_SHORT 0x100
72#define VF610_ADC_ADSTS_NORMAL 0x200
73#define VF610_ADC_ADSTS_LONG 0x300
71#define VF610_ADC_ADSTS_MASK 0x300 74#define VF610_ADC_ADSTS_MASK 0x300
72#define VF610_ADC_ADLPC_EN 0x80 75#define VF610_ADC_ADLPC_EN 0x80
73#define VF610_ADC_ADHSC_EN 0x400 76#define VF610_ADC_ADHSC_EN 0x400
@@ -98,6 +101,8 @@
98#define VF610_ADC_CALF 0x2 101#define VF610_ADC_CALF 0x2
99#define VF610_ADC_TIMEOUT msecs_to_jiffies(100) 102#define VF610_ADC_TIMEOUT msecs_to_jiffies(100)
100 103
104#define DEFAULT_SAMPLE_TIME 1000
105
101enum clk_sel { 106enum clk_sel {
102 VF610_ADCIOC_BUSCLK_SET, 107 VF610_ADCIOC_BUSCLK_SET,
103 VF610_ADCIOC_ALTCLK_SET, 108 VF610_ADCIOC_ALTCLK_SET,
@@ -124,6 +129,17 @@ enum conversion_mode_sel {
124 VF610_ADC_CONV_LOW_POWER, 129 VF610_ADC_CONV_LOW_POWER,
125}; 130};
126 131
132enum lst_adder_sel {
133 VF610_ADCK_CYCLES_3,
134 VF610_ADCK_CYCLES_5,
135 VF610_ADCK_CYCLES_7,
136 VF610_ADCK_CYCLES_9,
137 VF610_ADCK_CYCLES_13,
138 VF610_ADCK_CYCLES_17,
139 VF610_ADCK_CYCLES_21,
140 VF610_ADCK_CYCLES_25,
141};
142
127struct vf610_adc_feature { 143struct vf610_adc_feature {
128 enum clk_sel clk_sel; 144 enum clk_sel clk_sel;
129 enum vol_ref vol_ref; 145 enum vol_ref vol_ref;
@@ -132,6 +148,8 @@ struct vf610_adc_feature {
132 int clk_div; 148 int clk_div;
133 int sample_rate; 149 int sample_rate;
134 int res_mode; 150 int res_mode;
151 u32 lst_adder_index;
152 u32 default_sample_time;
135 153
136 bool calibration; 154 bool calibration;
137 bool ovwren; 155 bool ovwren;
@@ -155,11 +173,13 @@ struct vf610_adc {
155}; 173};
156 174
157static const u32 vf610_hw_avgs[] = { 1, 4, 8, 16, 32 }; 175static const u32 vf610_hw_avgs[] = { 1, 4, 8, 16, 32 };
176static const u32 vf610_lst_adder[] = { 3, 5, 7, 9, 13, 17, 21, 25 };
158 177
159static inline void vf610_adc_calculate_rates(struct vf610_adc *info) 178static inline void vf610_adc_calculate_rates(struct vf610_adc *info)
160{ 179{
161 struct vf610_adc_feature *adc_feature = &info->adc_feature; 180 struct vf610_adc_feature *adc_feature = &info->adc_feature;
162 unsigned long adck_rate, ipg_rate = clk_get_rate(info->clk); 181 unsigned long adck_rate, ipg_rate = clk_get_rate(info->clk);
182 u32 adck_period, lst_addr_min;
163 int divisor, i; 183 int divisor, i;
164 184
165 adck_rate = info->max_adck_rate[adc_feature->conv_mode]; 185 adck_rate = info->max_adck_rate[adc_feature->conv_mode];
@@ -174,6 +194,19 @@ static inline void vf610_adc_calculate_rates(struct vf610_adc *info)
174 } 194 }
175 195
176 /* 196 /*
197 * Determine the long sample time adder value to be used based
198 * on the default minimum sample time provided.
199 */
200 adck_period = NSEC_PER_SEC / adck_rate;
201 lst_addr_min = adc_feature->default_sample_time / adck_period;
202 for (i = 0; i < ARRAY_SIZE(vf610_lst_adder); i++) {
203 if (vf610_lst_adder[i] > lst_addr_min) {
204 adc_feature->lst_adder_index = i;
205 break;
206 }
207 }
208
209 /*
177 * Calculate ADC sample frequencies 210 * Calculate ADC sample frequencies
178 * Sample time unit is ADCK cycles. ADCK clk source is ipg clock, 211 * Sample time unit is ADCK cycles. ADCK clk source is ipg clock,
179 * which is the same as bus clock. 212 * which is the same as bus clock.
@@ -182,12 +215,13 @@ static inline void vf610_adc_calculate_rates(struct vf610_adc *info)
182 * SFCAdder: fixed to 6 ADCK cycles 215 * SFCAdder: fixed to 6 ADCK cycles
183 * AverageNum: 1, 4, 8, 16, 32 samples for hardware average. 216 * AverageNum: 1, 4, 8, 16, 32 samples for hardware average.
184 * BCT (Base Conversion Time): fixed to 25 ADCK cycles for 12 bit mode 217 * BCT (Base Conversion Time): fixed to 25 ADCK cycles for 12 bit mode
185 * LSTAdder(Long Sample Time): fixed to 3 ADCK cycles 218 * LSTAdder(Long Sample Time): 3, 5, 7, 9, 13, 17, 21, 25 ADCK cycles
186 */ 219 */
187 adck_rate = ipg_rate / info->adc_feature.clk_div; 220 adck_rate = ipg_rate / info->adc_feature.clk_div;
188 for (i = 0; i < ARRAY_SIZE(vf610_hw_avgs); i++) 221 for (i = 0; i < ARRAY_SIZE(vf610_hw_avgs); i++)
189 info->sample_freq_avail[i] = 222 info->sample_freq_avail[i] =
190 adck_rate / (6 + vf610_hw_avgs[i] * (25 + 3)); 223 adck_rate / (6 + vf610_hw_avgs[i] *
224 (25 + vf610_lst_adder[adc_feature->lst_adder_index]));
191} 225}
192 226
193static inline void vf610_adc_cfg_init(struct vf610_adc *info) 227static inline void vf610_adc_cfg_init(struct vf610_adc *info)
@@ -347,8 +381,40 @@ static void vf610_adc_sample_set(struct vf610_adc *info)
347 break; 381 break;
348 } 382 }
349 383
350 /* Use the short sample mode */ 384 /*
351 cfg_data &= ~(VF610_ADC_ADLSMP_LONG | VF610_ADC_ADSTS_MASK); 385 * Set ADLSMP and ADSTS based on the Long Sample Time Adder value
386 * determined.
387 */
388 switch (adc_feature->lst_adder_index) {
389 case VF610_ADCK_CYCLES_3:
390 break;
391 case VF610_ADCK_CYCLES_5:
392 cfg_data |= VF610_ADC_ADSTS_SHORT;
393 break;
394 case VF610_ADCK_CYCLES_7:
395 cfg_data |= VF610_ADC_ADSTS_NORMAL;
396 break;
397 case VF610_ADCK_CYCLES_9:
398 cfg_data |= VF610_ADC_ADSTS_LONG;
399 break;
400 case VF610_ADCK_CYCLES_13:
401 cfg_data |= VF610_ADC_ADLSMP_LONG;
402 break;
403 case VF610_ADCK_CYCLES_17:
404 cfg_data |= VF610_ADC_ADLSMP_LONG;
405 cfg_data |= VF610_ADC_ADSTS_SHORT;
406 break;
407 case VF610_ADCK_CYCLES_21:
408 cfg_data |= VF610_ADC_ADLSMP_LONG;
409 cfg_data |= VF610_ADC_ADSTS_NORMAL;
410 break;
411 case VF610_ADCK_CYCLES_25:
412 cfg_data |= VF610_ADC_ADLSMP_LONG;
413 cfg_data |= VF610_ADC_ADSTS_NORMAL;
414 break;
415 default:
416 dev_err(info->dev, "error in sample time select\n");
417 }
352 418
353 /* update hardware average selection */ 419 /* update hardware average selection */
354 cfg_data &= ~VF610_ADC_AVGS_MASK; 420 cfg_data &= ~VF610_ADC_AVGS_MASK;
@@ -713,6 +779,11 @@ static int vf610_adc_probe(struct platform_device *pdev)
713 of_property_read_u32_array(pdev->dev.of_node, "fsl,adck-max-frequency", 779 of_property_read_u32_array(pdev->dev.of_node, "fsl,adck-max-frequency",
714 info->max_adck_rate, 3); 780 info->max_adck_rate, 3);
715 781
782 ret = of_property_read_u32(pdev->dev.of_node, "min-sample-time",
783 &info->adc_feature.default_sample_time);
784 if (ret)
785 info->adc_feature.default_sample_time = DEFAULT_SAMPLE_TIME;
786
716 platform_set_drvdata(pdev, indio_dev); 787 platform_set_drvdata(pdev, indio_dev);
717 788
718 init_completion(&info->completion); 789 init_completion(&info->completion);
diff --git a/drivers/iio/common/ssp_sensors/ssp_dev.c b/drivers/iio/common/ssp_sensors/ssp_dev.c
index 9a40097e7cf8..d338bb595db3 100644
--- a/drivers/iio/common/ssp_sensors/ssp_dev.c
+++ b/drivers/iio/common/ssp_sensors/ssp_dev.c
@@ -700,7 +700,6 @@ static struct spi_driver ssp_driver = {
700 .remove = ssp_remove, 700 .remove = ssp_remove,
701 .driver = { 701 .driver = {
702 .pm = &ssp_pm_ops, 702 .pm = &ssp_pm_ops,
703 .bus = &spi_bus_type,
704 .owner = THIS_MODULE, 703 .owner = THIS_MODULE,
705 .of_match_table = of_match_ptr(ssp_of_match), 704 .of_match_table = of_match_ptr(ssp_of_match),
706 .name = "sensorhub" 705 .name = "sensorhub"
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index 8086cbcff87d..2e7fdb502645 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -126,6 +126,9 @@ static int st_sensors_set_fullscale(struct iio_dev *indio_dev, unsigned int fs)
126 int err, i = 0; 126 int err, i = 0;
127 struct st_sensor_data *sdata = iio_priv(indio_dev); 127 struct st_sensor_data *sdata = iio_priv(indio_dev);
128 128
129 if (sdata->sensor_settings->fs.addr == 0)
130 return 0;
131
129 err = st_sensors_match_fs(sdata->sensor_settings, fs, &i); 132 err = st_sensors_match_fs(sdata->sensor_settings, fs, &i);
130 if (err < 0) 133 if (err < 0)
131 goto st_accel_set_fullscale_error; 134 goto st_accel_set_fullscale_error;
@@ -479,46 +482,43 @@ int st_sensors_check_device_support(struct iio_dev *indio_dev,
479 int num_sensors_list, 482 int num_sensors_list,
480 const struct st_sensor_settings *sensor_settings) 483 const struct st_sensor_settings *sensor_settings)
481{ 484{
482 u8 wai;
483 int i, n, err; 485 int i, n, err;
486 u8 wai;
484 struct st_sensor_data *sdata = iio_priv(indio_dev); 487 struct st_sensor_data *sdata = iio_priv(indio_dev);
485 488
486 err = sdata->tf->read_byte(&sdata->tb, sdata->dev,
487 ST_SENSORS_DEFAULT_WAI_ADDRESS, &wai);
488 if (err < 0) {
489 dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n");
490 goto read_wai_error;
491 }
492
493 for (i = 0; i < num_sensors_list; i++) { 489 for (i = 0; i < num_sensors_list; i++) {
494 if (sensor_settings[i].wai == wai) 490 for (n = 0; n < ST_SENSORS_MAX_4WAI; n++) {
491 if (strcmp(indio_dev->name,
492 sensor_settings[i].sensors_supported[n]) == 0) {
493 break;
494 }
495 }
496 if (n < ST_SENSORS_MAX_4WAI)
495 break; 497 break;
496 } 498 }
497 if (i == num_sensors_list) 499 if (i == num_sensors_list) {
498 goto device_not_supported; 500 dev_err(&indio_dev->dev, "device name %s not recognized.\n",
501 indio_dev->name);
502 return -ENODEV;
503 }
499 504
500 for (n = 0; n < ARRAY_SIZE(sensor_settings[i].sensors_supported); n++) { 505 err = sdata->tf->read_byte(&sdata->tb, sdata->dev,
501 if (strcmp(indio_dev->name, 506 sensor_settings[i].wai_addr, &wai);
502 &sensor_settings[i].sensors_supported[n][0]) == 0) 507 if (err < 0) {
503 break; 508 dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n");
509 return err;
504 } 510 }
505 if (n == ARRAY_SIZE(sensor_settings[i].sensors_supported)) { 511
506 dev_err(&indio_dev->dev, "device name \"%s\" and WhoAmI (0x%02x) mismatch", 512 if (sensor_settings[i].wai != wai) {
507 indio_dev->name, wai); 513 dev_err(&indio_dev->dev, "%s: WhoAmI mismatch (0x%x).\n",
508 goto sensor_name_mismatch; 514 indio_dev->name, wai);
515 return -EINVAL;
509 } 516 }
510 517
511 sdata->sensor_settings = 518 sdata->sensor_settings =
512 (struct st_sensor_settings *)&sensor_settings[i]; 519 (struct st_sensor_settings *)&sensor_settings[i];
513 520
514 return i; 521 return i;
515
516device_not_supported:
517 dev_err(&indio_dev->dev, "device not supported: WhoAmI (0x%x).\n", wai);
518sensor_name_mismatch:
519 err = -ENODEV;
520read_wai_error:
521 return err;
522} 522}
523EXPORT_SYMBOL(st_sensors_check_device_support); 523EXPORT_SYMBOL(st_sensors_check_device_support);
524 524
diff --git a/drivers/iio/dac/ad5064.c b/drivers/iio/dac/ad5064.c
index f03b92fd3803..c067e6821496 100644
--- a/drivers/iio/dac/ad5064.c
+++ b/drivers/iio/dac/ad5064.c
@@ -630,7 +630,6 @@ MODULE_DEVICE_TABLE(i2c, ad5064_i2c_ids);
630static struct i2c_driver ad5064_i2c_driver = { 630static struct i2c_driver ad5064_i2c_driver = {
631 .driver = { 631 .driver = {
632 .name = "ad5064", 632 .name = "ad5064",
633 .owner = THIS_MODULE,
634 }, 633 },
635 .probe = ad5064_i2c_probe, 634 .probe = ad5064_i2c_probe,
636 .remove = ad5064_i2c_remove, 635 .remove = ad5064_i2c_remove,
diff --git a/drivers/iio/dac/ad5380.c b/drivers/iio/dac/ad5380.c
index 9de4c4d38280..130de9b3e0bf 100644
--- a/drivers/iio/dac/ad5380.c
+++ b/drivers/iio/dac/ad5380.c
@@ -593,7 +593,6 @@ MODULE_DEVICE_TABLE(i2c, ad5380_i2c_ids);
593static struct i2c_driver ad5380_i2c_driver = { 593static struct i2c_driver ad5380_i2c_driver = {
594 .driver = { 594 .driver = {
595 .name = "ad5380", 595 .name = "ad5380",
596 .owner = THIS_MODULE,
597 }, 596 },
598 .probe = ad5380_i2c_probe, 597 .probe = ad5380_i2c_probe,
599 .remove = ad5380_i2c_remove, 598 .remove = ad5380_i2c_remove,
diff --git a/drivers/iio/dac/ad5446.c b/drivers/iio/dac/ad5446.c
index 46bb62a5c1d4..07e17d72a3f3 100644
--- a/drivers/iio/dac/ad5446.c
+++ b/drivers/iio/dac/ad5446.c
@@ -569,7 +569,6 @@ MODULE_DEVICE_TABLE(i2c, ad5446_i2c_ids);
569static struct i2c_driver ad5446_i2c_driver = { 569static struct i2c_driver ad5446_i2c_driver = {
570 .driver = { 570 .driver = {
571 .name = "ad5446", 571 .name = "ad5446",
572 .owner = THIS_MODULE,
573 }, 572 },
574 .probe = ad5446_i2c_probe, 573 .probe = ad5446_i2c_probe,
575 .remove = ad5446_i2c_remove, 574 .remove = ad5446_i2c_remove,
diff --git a/drivers/iio/dac/max5821.c b/drivers/iio/dac/max5821.c
index 6e914495b346..28b8748ea824 100644
--- a/drivers/iio/dac/max5821.c
+++ b/drivers/iio/dac/max5821.c
@@ -392,7 +392,6 @@ static struct i2c_driver max5821_driver = {
392 .driver = { 392 .driver = {
393 .name = "max5821", 393 .name = "max5821",
394 .pm = MAX5821_PM_OPS, 394 .pm = MAX5821_PM_OPS,
395 .owner = THIS_MODULE,
396 }, 395 },
397 .probe = max5821_probe, 396 .probe = max5821_probe,
398 .remove = max5821_remove, 397 .remove = max5821_remove,
diff --git a/drivers/iio/frequency/adf4350.c b/drivers/iio/frequency/adf4350.c
index 10a0dfc3b01f..9890c81c027d 100644
--- a/drivers/iio/frequency/adf4350.c
+++ b/drivers/iio/frequency/adf4350.c
@@ -72,7 +72,6 @@ static int adf4350_sync_config(struct adf4350_state *st)
72 for (i = ADF4350_REG5; i >= ADF4350_REG0; i--) { 72 for (i = ADF4350_REG5; i >= ADF4350_REG0; i--) {
73 if ((st->regs_hw[i] != st->regs[i]) || 73 if ((st->regs_hw[i] != st->regs[i]) ||
74 ((i == ADF4350_REG0) && doublebuf)) { 74 ((i == ADF4350_REG0) && doublebuf)) {
75
76 switch (i) { 75 switch (i) {
77 case ADF4350_REG1: 76 case ADF4350_REG1:
78 case ADF4350_REG4: 77 case ADF4350_REG4:
diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
index b3d0e94f72eb..8d2439345673 100644
--- a/drivers/iio/gyro/Kconfig
+++ b/drivers/iio/gyro/Kconfig
@@ -53,7 +53,8 @@ config ADXRS450
53config BMG160 53config BMG160
54 tristate "BOSCH BMG160 Gyro Sensor" 54 tristate "BOSCH BMG160 Gyro Sensor"
55 depends on I2C 55 depends on I2C
56 select IIO_TRIGGERED_BUFFER if IIO_BUFFER 56 select IIO_BUFFER
57 select IIO_TRIGGERED_BUFFER
57 help 58 help
58 Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor 59 Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
59 driver. This driver also supports BMI055 gyroscope. 60 driver. This driver also supports BMI055 gyroscope.
diff --git a/drivers/iio/gyro/adis16136.c b/drivers/iio/gyro/adis16136.c
index 591bd555e1f3..26de876b223d 100644
--- a/drivers/iio/gyro/adis16136.c
+++ b/drivers/iio/gyro/adis16136.c
@@ -473,6 +473,7 @@ enum adis16136_id {
473 ID_ADIS16133, 473 ID_ADIS16133,
474 ID_ADIS16135, 474 ID_ADIS16135,
475 ID_ADIS16136, 475 ID_ADIS16136,
476 ID_ADIS16137,
476}; 477};
477 478
478static const struct adis16136_chip_info adis16136_chip_info[] = { 479static const struct adis16136_chip_info adis16136_chip_info[] = {
@@ -488,6 +489,10 @@ static const struct adis16136_chip_info adis16136_chip_info[] = {
488 .precision = IIO_DEGREE_TO_RAD(450), 489 .precision = IIO_DEGREE_TO_RAD(450),
489 .fullscale = 24623, 490 .fullscale = 24623,
490 }, 491 },
492 [ID_ADIS16137] = {
493 .precision = IIO_DEGREE_TO_RAD(1000),
494 .fullscale = 24609,
495 },
491}; 496};
492 497
493static int adis16136_probe(struct spi_device *spi) 498static int adis16136_probe(struct spi_device *spi)
@@ -557,6 +562,7 @@ static const struct spi_device_id adis16136_ids[] = {
557 { "adis16133", ID_ADIS16133 }, 562 { "adis16133", ID_ADIS16133 },
558 { "adis16135", ID_ADIS16135 }, 563 { "adis16135", ID_ADIS16135 },
559 { "adis16136", ID_ADIS16136 }, 564 { "adis16136", ID_ADIS16136 },
565 { "adis16137", ID_ADIS16137 },
560 { } 566 { }
561}; 567};
562MODULE_DEVICE_TABLE(spi, adis16136_ids); 568MODULE_DEVICE_TABLE(spi, adis16136_ids);
diff --git a/drivers/iio/gyro/adis16260.c b/drivers/iio/gyro/adis16260.c
index 75fe0edd3d0f..00c6ad9bf35f 100644
--- a/drivers/iio/gyro/adis16260.c
+++ b/drivers/iio/gyro/adis16260.c
@@ -101,19 +101,24 @@
101#define ADIS16260_SCAN_TEMP 3 101#define ADIS16260_SCAN_TEMP 3
102#define ADIS16260_SCAN_ANGL 4 102#define ADIS16260_SCAN_ANGL 4
103 103
104/* Power down the device */ 104struct adis16260_chip_info {
105static int adis16260_stop_device(struct iio_dev *indio_dev) 105 unsigned int gyro_max_val;
106{ 106 unsigned int gyro_max_scale;
107 struct adis *adis = iio_priv(indio_dev); 107 const struct iio_chan_spec *channels;
108 int ret; 108 unsigned int num_channels;
109 u16 val = ADIS16260_SLP_CNT_POWER_OFF; 109};
110 110
111 ret = adis_write_reg_16(adis, ADIS16260_SLP_CNT, val); 111struct adis16260 {
112 if (ret) 112 const struct adis16260_chip_info *info;
113 dev_err(&indio_dev->dev, "problem with turning device off: SLP_CNT");
114 113
115 return ret; 114 struct adis adis;
116} 115};
116
117enum adis16260_type {
118 ADIS16251,
119 ADIS16260,
120 ADIS16266,
121};
117 122
118static const struct iio_chan_spec adis16260_channels[] = { 123static const struct iio_chan_spec adis16260_channels[] = {
119 ADIS_GYRO_CHAN(X, ADIS16260_GYRO_OUT, ADIS16260_SCAN_GYRO, 124 ADIS_GYRO_CHAN(X, ADIS16260_GYRO_OUT, ADIS16260_SCAN_GYRO,
@@ -131,6 +136,55 @@ static const struct iio_chan_spec adis16260_channels[] = {
131 IIO_CHAN_SOFT_TIMESTAMP(5), 136 IIO_CHAN_SOFT_TIMESTAMP(5),
132}; 137};
133 138
139static const struct iio_chan_spec adis16266_channels[] = {
140 ADIS_GYRO_CHAN(X, ADIS16260_GYRO_OUT, ADIS16260_SCAN_GYRO,
141 BIT(IIO_CHAN_INFO_CALIBBIAS) |
142 BIT(IIO_CHAN_INFO_CALIBSCALE),
143 BIT(IIO_CHAN_INFO_SAMP_FREQ), 14),
144 ADIS_TEMP_CHAN(ADIS16260_TEMP_OUT, ADIS16260_SCAN_TEMP,
145 BIT(IIO_CHAN_INFO_SAMP_FREQ), 12),
146 ADIS_SUPPLY_CHAN(ADIS16260_SUPPLY_OUT, ADIS16260_SCAN_SUPPLY,
147 BIT(IIO_CHAN_INFO_SAMP_FREQ), 12),
148 ADIS_AUX_ADC_CHAN(ADIS16260_AUX_ADC, ADIS16260_SCAN_AUX_ADC,
149 BIT(IIO_CHAN_INFO_SAMP_FREQ), 12),
150 IIO_CHAN_SOFT_TIMESTAMP(4),
151};
152
153static const struct adis16260_chip_info adis16260_chip_info_table[] = {
154 [ADIS16251] = {
155 .gyro_max_scale = 80,
156 .gyro_max_val = IIO_RAD_TO_DEGREE(4368),
157 .channels = adis16260_channels,
158 .num_channels = ARRAY_SIZE(adis16260_channels),
159 },
160 [ADIS16260] = {
161 .gyro_max_scale = 320,
162 .gyro_max_val = IIO_RAD_TO_DEGREE(4368),
163 .channels = adis16260_channels,
164 .num_channels = ARRAY_SIZE(adis16260_channels),
165 },
166 [ADIS16266] = {
167 .gyro_max_scale = 14000,
168 .gyro_max_val = IIO_RAD_TO_DEGREE(3357),
169 .channels = adis16266_channels,
170 .num_channels = ARRAY_SIZE(adis16266_channels),
171 },
172};
173
174/* Power down the device */
175static int adis16260_stop_device(struct iio_dev *indio_dev)
176{
177 struct adis16260 *adis16260 = iio_priv(indio_dev);
178 int ret;
179 u16 val = ADIS16260_SLP_CNT_POWER_OFF;
180
181 ret = adis_write_reg_16(&adis16260->adis, ADIS16260_SLP_CNT, val);
182 if (ret)
183 dev_err(&indio_dev->dev, "problem with turning device off: SLP_CNT");
184
185 return ret;
186}
187
134static const u8 adis16260_addresses[][2] = { 188static const u8 adis16260_addresses[][2] = {
135 [ADIS16260_SCAN_GYRO] = { ADIS16260_GYRO_OFF, ADIS16260_GYRO_SCALE }, 189 [ADIS16260_SCAN_GYRO] = { ADIS16260_GYRO_OFF, ADIS16260_GYRO_SCALE },
136}; 190};
@@ -140,7 +194,9 @@ static int adis16260_read_raw(struct iio_dev *indio_dev,
140 int *val, int *val2, 194 int *val, int *val2,
141 long mask) 195 long mask)
142{ 196{
143 struct adis *adis = iio_priv(indio_dev); 197 struct adis16260 *adis16260 = iio_priv(indio_dev);
198 const struct adis16260_chip_info *info = adis16260->info;
199 struct adis *adis = &adis16260->adis;
144 int ret; 200 int ret;
145 u8 addr; 201 u8 addr;
146 s16 val16; 202 s16 val16;
@@ -152,15 +208,9 @@ static int adis16260_read_raw(struct iio_dev *indio_dev,
152 case IIO_CHAN_INFO_SCALE: 208 case IIO_CHAN_INFO_SCALE:
153 switch (chan->type) { 209 switch (chan->type) {
154 case IIO_ANGL_VEL: 210 case IIO_ANGL_VEL:
155 *val = 0; 211 *val = info->gyro_max_scale;
156 if (spi_get_device_id(adis->spi)->driver_data) { 212 *val2 = info->gyro_max_val;
157 /* 0.01832 degree / sec */ 213 return IIO_VAL_FRACTIONAL;
158 *val2 = IIO_DEGREE_TO_RAD(18320);
159 } else {
160 /* 0.07326 degree / sec */
161 *val2 = IIO_DEGREE_TO_RAD(73260);
162 }
163 return IIO_VAL_INT_PLUS_MICRO;
164 case IIO_INCLI: 214 case IIO_INCLI:
165 *val = 0; 215 *val = 0;
166 *val2 = IIO_DEGREE_TO_RAD(36630); 216 *val2 = IIO_DEGREE_TO_RAD(36630);
@@ -224,7 +274,8 @@ static int adis16260_write_raw(struct iio_dev *indio_dev,
224 int val2, 274 int val2,
225 long mask) 275 long mask)
226{ 276{
227 struct adis *adis = iio_priv(indio_dev); 277 struct adis16260 *adis16260 = iio_priv(indio_dev);
278 struct adis *adis = &adis16260->adis;
228 int ret; 279 int ret;
229 u8 addr; 280 u8 addr;
230 u8 t; 281 u8 t;
@@ -305,35 +356,42 @@ static const struct adis_data adis16260_data = {
305 356
306static int adis16260_probe(struct spi_device *spi) 357static int adis16260_probe(struct spi_device *spi)
307{ 358{
359 const struct spi_device_id *id;
360 struct adis16260 *adis16260;
308 struct iio_dev *indio_dev; 361 struct iio_dev *indio_dev;
309 struct adis *adis;
310 int ret; 362 int ret;
311 363
364 id = spi_get_device_id(spi);
365 if (!id)
366 return -ENODEV;
367
312 /* setup the industrialio driver allocated elements */ 368 /* setup the industrialio driver allocated elements */
313 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adis)); 369 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adis16260));
314 if (!indio_dev) 370 if (!indio_dev)
315 return -ENOMEM; 371 return -ENOMEM;
316 adis = iio_priv(indio_dev); 372 adis16260 = iio_priv(indio_dev);
317 /* this is only used for removal purposes */ 373 /* this is only used for removal purposes */
318 spi_set_drvdata(spi, indio_dev); 374 spi_set_drvdata(spi, indio_dev);
319 375
320 indio_dev->name = spi_get_device_id(spi)->name; 376 adis16260->info = &adis16260_chip_info_table[id->driver_data];
377
378 indio_dev->name = id->name;
321 indio_dev->dev.parent = &spi->dev; 379 indio_dev->dev.parent = &spi->dev;
322 indio_dev->info = &adis16260_info; 380 indio_dev->info = &adis16260_info;
323 indio_dev->channels = adis16260_channels; 381 indio_dev->channels = adis16260->info->channels;
324 indio_dev->num_channels = ARRAY_SIZE(adis16260_channels); 382 indio_dev->num_channels = adis16260->info->num_channels;
325 indio_dev->modes = INDIO_DIRECT_MODE; 383 indio_dev->modes = INDIO_DIRECT_MODE;
326 384
327 ret = adis_init(adis, indio_dev, spi, &adis16260_data); 385 ret = adis_init(&adis16260->adis, indio_dev, spi, &adis16260_data);
328 if (ret) 386 if (ret)
329 return ret; 387 return ret;
330 388
331 ret = adis_setup_buffer_and_trigger(adis, indio_dev, NULL); 389 ret = adis_setup_buffer_and_trigger(&adis16260->adis, indio_dev, NULL);
332 if (ret) 390 if (ret)
333 return ret; 391 return ret;
334 392
335 /* Get the device into a sane initial state */ 393 /* Get the device into a sane initial state */
336 ret = adis_initial_startup(adis); 394 ret = adis_initial_startup(&adis16260->adis);
337 if (ret) 395 if (ret)
338 goto error_cleanup_buffer_trigger; 396 goto error_cleanup_buffer_trigger;
339 ret = iio_device_register(indio_dev); 397 ret = iio_device_register(indio_dev);
@@ -343,18 +401,18 @@ static int adis16260_probe(struct spi_device *spi)
343 return 0; 401 return 0;
344 402
345error_cleanup_buffer_trigger: 403error_cleanup_buffer_trigger:
346 adis_cleanup_buffer_and_trigger(adis, indio_dev); 404 adis_cleanup_buffer_and_trigger(&adis16260->adis, indio_dev);
347 return ret; 405 return ret;
348} 406}
349 407
350static int adis16260_remove(struct spi_device *spi) 408static int adis16260_remove(struct spi_device *spi)
351{ 409{
352 struct iio_dev *indio_dev = spi_get_drvdata(spi); 410 struct iio_dev *indio_dev = spi_get_drvdata(spi);
353 struct adis *adis = iio_priv(indio_dev); 411 struct adis16260 *adis16260 = iio_priv(indio_dev);
354 412
355 iio_device_unregister(indio_dev); 413 iio_device_unregister(indio_dev);
356 adis16260_stop_device(indio_dev); 414 adis16260_stop_device(indio_dev);
357 adis_cleanup_buffer_and_trigger(adis, indio_dev); 415 adis_cleanup_buffer_and_trigger(&adis16260->adis, indio_dev);
358 416
359 return 0; 417 return 0;
360} 418}
@@ -364,11 +422,12 @@ static int adis16260_remove(struct spi_device *spi)
364 * support for the on chip filtering. 422 * support for the on chip filtering.
365 */ 423 */
366static const struct spi_device_id adis16260_id[] = { 424static const struct spi_device_id adis16260_id[] = {
367 {"adis16260", 0}, 425 {"adis16260", ADIS16260},
368 {"adis16265", 0}, 426 {"adis16265", ADIS16260},
369 {"adis16250", 0}, 427 {"adis16266", ADIS16266},
370 {"adis16255", 0}, 428 {"adis16250", ADIS16260},
371 {"adis16251", 1}, 429 {"adis16255", ADIS16260},
430 {"adis16251", ADIS16251},
372 {} 431 {}
373}; 432};
374MODULE_DEVICE_TABLE(spi, adis16260_id); 433MODULE_DEVICE_TABLE(spi, adis16260_id);
diff --git a/drivers/iio/gyro/itg3200_core.c b/drivers/iio/gyro/itg3200_core.c
index f0fd94055d88..c102a6325bb0 100644
--- a/drivers/iio/gyro/itg3200_core.c
+++ b/drivers/iio/gyro/itg3200_core.c
@@ -379,7 +379,6 @@ MODULE_DEVICE_TABLE(i2c, itg3200_id);
379 379
380static struct i2c_driver itg3200_driver = { 380static struct i2c_driver itg3200_driver = {
381 .driver = { 381 .driver = {
382 .owner = THIS_MODULE,
383 .name = "itg3200", 382 .name = "itg3200",
384 .pm = &itg3200_pm_ops, 383 .pm = &itg3200_pm_ops,
385 }, 384 },
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index ffe96642b6d0..4b993a5bc9a1 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -131,6 +131,7 @@ static const struct iio_chan_spec st_gyro_16bit_channels[] = {
131static const struct st_sensor_settings st_gyro_sensors_settings[] = { 131static const struct st_sensor_settings st_gyro_sensors_settings[] = {
132 { 132 {
133 .wai = ST_GYRO_1_WAI_EXP, 133 .wai = ST_GYRO_1_WAI_EXP,
134 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
134 .sensors_supported = { 135 .sensors_supported = {
135 [0] = L3G4200D_GYRO_DEV_NAME, 136 [0] = L3G4200D_GYRO_DEV_NAME,
136 [1] = LSM330DL_GYRO_DEV_NAME, 137 [1] = LSM330DL_GYRO_DEV_NAME,
@@ -190,6 +191,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
190 }, 191 },
191 { 192 {
192 .wai = ST_GYRO_2_WAI_EXP, 193 .wai = ST_GYRO_2_WAI_EXP,
194 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
193 .sensors_supported = { 195 .sensors_supported = {
194 [0] = L3GD20_GYRO_DEV_NAME, 196 [0] = L3GD20_GYRO_DEV_NAME,
195 [1] = LSM330D_GYRO_DEV_NAME, 197 [1] = LSM330D_GYRO_DEV_NAME,
@@ -252,6 +254,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
252 }, 254 },
253 { 255 {
254 .wai = ST_GYRO_3_WAI_EXP, 256 .wai = ST_GYRO_3_WAI_EXP,
257 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
255 .sensors_supported = { 258 .sensors_supported = {
256 [0] = L3GD20_GYRO_DEV_NAME, 259 [0] = L3GD20_GYRO_DEV_NAME,
257 }, 260 },
diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c
index 64480b16c689..6848451f817a 100644
--- a/drivers/iio/gyro/st_gyro_i2c.c
+++ b/drivers/iio/gyro/st_gyro_i2c.c
@@ -99,7 +99,6 @@ MODULE_DEVICE_TABLE(i2c, st_gyro_id_table);
99 99
100static struct i2c_driver st_gyro_driver = { 100static struct i2c_driver st_gyro_driver = {
101 .driver = { 101 .driver = {
102 .owner = THIS_MODULE,
103 .name = "st-gyro-i2c", 102 .name = "st-gyro-i2c",
104 .of_match_table = of_match_ptr(st_gyro_of_match), 103 .of_match_table = of_match_ptr(st_gyro_of_match),
105 }, 104 },
diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c
index 7d79a1ac5f5f..1165b1c4f9d6 100644
--- a/drivers/iio/humidity/dht11.c
+++ b/drivers/iio/humidity/dht11.c
@@ -33,6 +33,7 @@
33#include <linux/delay.h> 33#include <linux/delay.h>
34#include <linux/gpio.h> 34#include <linux/gpio.h>
35#include <linux/of_gpio.h> 35#include <linux/of_gpio.h>
36#include <linux/timekeeping.h>
36 37
37#include <linux/iio/iio.h> 38#include <linux/iio/iio.h>
38 39
@@ -46,7 +47,8 @@
46 * Note that when reading the sensor actually 84 edges are detected, but 47 * Note that when reading the sensor actually 84 edges are detected, but
47 * since the last edge is not significant, we only store 83: 48 * since the last edge is not significant, we only store 83:
48 */ 49 */
49#define DHT11_EDGES_PER_READ (2*DHT11_BITS_PER_READ + DHT11_EDGES_PREAMBLE + 1) 50#define DHT11_EDGES_PER_READ (2 * DHT11_BITS_PER_READ + \
51 DHT11_EDGES_PREAMBLE + 1)
50 52
51/* Data transmission timing (nano seconds) */ 53/* Data transmission timing (nano seconds) */
52#define DHT11_START_TRANSMISSION 18 /* ms */ 54#define DHT11_START_TRANSMISSION 18 /* ms */
@@ -62,6 +64,7 @@ struct dht11 {
62 int irq; 64 int irq;
63 65
64 struct completion completion; 66 struct completion completion;
67 /* The iio sysfs interface doesn't prevent concurrent reads: */
65 struct mutex lock; 68 struct mutex lock;
66 69
67 s64 timestamp; 70 s64 timestamp;
@@ -87,32 +90,20 @@ static unsigned char dht11_decode_byte(int *timing, int threshold)
87 return ret; 90 return ret;
88} 91}
89 92
90static int dht11_decode(struct dht11 *dht11, int offset) 93static int dht11_decode(struct dht11 *dht11, int offset, int timeres)
91{ 94{
92 int i, t, timing[DHT11_BITS_PER_READ], threshold, 95 int i, t, timing[DHT11_BITS_PER_READ], threshold;
93 timeres = DHT11_SENSOR_RESPONSE;
94 unsigned char temp_int, temp_dec, hum_int, hum_dec, checksum; 96 unsigned char temp_int, temp_dec, hum_int, hum_dec, checksum;
95 97
96 /* Calculate timestamp resolution */
97 for (i = 1; i < dht11->num_edges; ++i) {
98 t = dht11->edges[i].ts - dht11->edges[i-1].ts;
99 if (t > 0 && t < timeres)
100 timeres = t;
101 }
102 if (2*timeres > DHT11_DATA_BIT_HIGH) {
103 pr_err("dht11: timeresolution %d too bad for decoding\n",
104 timeres);
105 return -EIO;
106 }
107 threshold = DHT11_DATA_BIT_HIGH / timeres; 98 threshold = DHT11_DATA_BIT_HIGH / timeres;
108 if (DHT11_DATA_BIT_LOW/timeres + 1 >= threshold) 99 if (DHT11_DATA_BIT_LOW / timeres + 1 >= threshold)
109 pr_err("dht11: WARNING: decoding ambiguous\n"); 100 pr_err("dht11: WARNING: decoding ambiguous\n");
110 101
111 /* scale down with timeres and check validity */ 102 /* scale down with timeres and check validity */
112 for (i = 0; i < DHT11_BITS_PER_READ; ++i) { 103 for (i = 0; i < DHT11_BITS_PER_READ; ++i) {
113 t = dht11->edges[offset + 2*i + 2].ts - 104 t = dht11->edges[offset + 2 * i + 2].ts -
114 dht11->edges[offset + 2*i + 1].ts; 105 dht11->edges[offset + 2 * i + 1].ts;
115 if (!dht11->edges[offset + 2*i + 1].value) 106 if (!dht11->edges[offset + 2 * i + 1].value)
116 return -EIO; /* lost synchronisation */ 107 return -EIO; /* lost synchronisation */
117 timing[i] = t / timeres; 108 timing[i] = t / timeres;
118 } 109 }
@@ -126,7 +117,7 @@ static int dht11_decode(struct dht11 *dht11, int offset)
126 if (((hum_int + hum_dec + temp_int + temp_dec) & 0xff) != checksum) 117 if (((hum_int + hum_dec + temp_int + temp_dec) & 0xff) != checksum)
127 return -EIO; 118 return -EIO;
128 119
129 dht11->timestamp = iio_get_time_ns(); 120 dht11->timestamp = ktime_get_real_ns();
130 if (hum_int < 20) { /* DHT22 */ 121 if (hum_int < 20) { /* DHT22 */
131 dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) * 122 dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) *
132 ((temp_int & 0x80) ? -100 : 100); 123 ((temp_int & 0x80) ? -100 : 100);
@@ -154,7 +145,7 @@ static irqreturn_t dht11_handle_irq(int irq, void *data)
154 145
155 /* TODO: Consider making the handler safe for IRQ sharing */ 146 /* TODO: Consider making the handler safe for IRQ sharing */
156 if (dht11->num_edges < DHT11_EDGES_PER_READ && dht11->num_edges >= 0) { 147 if (dht11->num_edges < DHT11_EDGES_PER_READ && dht11->num_edges >= 0) {
157 dht11->edges[dht11->num_edges].ts = iio_get_time_ns(); 148 dht11->edges[dht11->num_edges].ts = ktime_get_real_ns();
158 dht11->edges[dht11->num_edges++].value = 149 dht11->edges[dht11->num_edges++].value =
159 gpio_get_value(dht11->gpio); 150 gpio_get_value(dht11->gpio);
160 151
@@ -166,14 +157,26 @@ static irqreturn_t dht11_handle_irq(int irq, void *data)
166} 157}
167 158
168static int dht11_read_raw(struct iio_dev *iio_dev, 159static int dht11_read_raw(struct iio_dev *iio_dev,
169 const struct iio_chan_spec *chan, 160 const struct iio_chan_spec *chan,
170 int *val, int *val2, long m) 161 int *val, int *val2, long m)
171{ 162{
172 struct dht11 *dht11 = iio_priv(iio_dev); 163 struct dht11 *dht11 = iio_priv(iio_dev);
173 int ret; 164 int ret, timeres;
174 165
175 mutex_lock(&dht11->lock); 166 mutex_lock(&dht11->lock);
176 if (dht11->timestamp + DHT11_DATA_VALID_TIME < iio_get_time_ns()) { 167 if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_real_ns()) {
168 timeres = ktime_get_resolution_ns();
169 if (DHT11_DATA_BIT_HIGH < 2 * timeres) {
170 dev_err(dht11->dev, "timeresolution %dns too low\n",
171 timeres);
172 /* In theory a better clock could become available
173 * at some point ... and there is no error code
174 * that really fits better.
175 */
176 ret = -EAGAIN;
177 goto err;
178 }
179
177 reinit_completion(&dht11->completion); 180 reinit_completion(&dht11->completion);
178 181
179 dht11->num_edges = 0; 182 dht11->num_edges = 0;
@@ -192,13 +195,13 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
192 goto err; 195 goto err;
193 196
194 ret = wait_for_completion_killable_timeout(&dht11->completion, 197 ret = wait_for_completion_killable_timeout(&dht11->completion,
195 HZ); 198 HZ);
196 199
197 free_irq(dht11->irq, iio_dev); 200 free_irq(dht11->irq, iio_dev);
198 201
199 if (ret == 0 && dht11->num_edges < DHT11_EDGES_PER_READ - 1) { 202 if (ret == 0 && dht11->num_edges < DHT11_EDGES_PER_READ - 1) {
200 dev_err(&iio_dev->dev, 203 dev_err(&iio_dev->dev,
201 "Only %d signal edges detected\n", 204 "Only %d signal edges detected\n",
202 dht11->num_edges); 205 dht11->num_edges);
203 ret = -ETIMEDOUT; 206 ret = -ETIMEDOUT;
204 } 207 }
@@ -206,9 +209,10 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
206 goto err; 209 goto err;
207 210
208 ret = dht11_decode(dht11, 211 ret = dht11_decode(dht11,
209 dht11->num_edges == DHT11_EDGES_PER_READ ? 212 dht11->num_edges == DHT11_EDGES_PER_READ ?
210 DHT11_EDGES_PREAMBLE : 213 DHT11_EDGES_PREAMBLE :
211 DHT11_EDGES_PREAMBLE - 2); 214 DHT11_EDGES_PREAMBLE - 2,
215 timeres);
212 if (ret) 216 if (ret)
213 goto err; 217 goto err;
214 } 218 }
@@ -261,9 +265,10 @@ static int dht11_probe(struct platform_device *pdev)
261 dht11 = iio_priv(iio); 265 dht11 = iio_priv(iio);
262 dht11->dev = dev; 266 dht11->dev = dev;
263 267
264 dht11->gpio = ret = of_get_gpio(node, 0); 268 ret = of_get_gpio(node, 0);
265 if (ret < 0) 269 if (ret < 0)
266 return ret; 270 return ret;
271 dht11->gpio = ret;
267 ret = devm_gpio_request_one(dev, dht11->gpio, GPIOF_IN, pdev->name); 272 ret = devm_gpio_request_one(dev, dht11->gpio, GPIOF_IN, pdev->name);
268 if (ret) 273 if (ret)
269 return ret; 274 return ret;
@@ -274,7 +279,7 @@ static int dht11_probe(struct platform_device *pdev)
274 return -EINVAL; 279 return -EINVAL;
275 } 280 }
276 281
277 dht11->timestamp = iio_get_time_ns() - DHT11_DATA_VALID_TIME - 1; 282 dht11->timestamp = ktime_get_real_ns() - DHT11_DATA_VALID_TIME - 1;
278 dht11->num_edges = -1; 283 dht11->num_edges = -1;
279 284
280 platform_set_drvdata(pdev, iio); 285 platform_set_drvdata(pdev, iio);
diff --git a/drivers/iio/humidity/si7005.c b/drivers/iio/humidity/si7005.c
index bdd586e6d955..91972ccd8aaf 100644
--- a/drivers/iio/humidity/si7005.c
+++ b/drivers/iio/humidity/si7005.c
@@ -177,7 +177,6 @@ MODULE_DEVICE_TABLE(i2c, si7005_id);
177static struct i2c_driver si7005_driver = { 177static struct i2c_driver si7005_driver = {
178 .driver = { 178 .driver = {
179 .name = "si7005", 179 .name = "si7005",
180 .owner = THIS_MODULE,
181 }, 180 },
182 .probe = si7005_probe, 181 .probe = si7005_probe,
183 .id_table = si7005_id, 182 .id_table = si7005_id,
diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c
index 2fd68f2219a7..abc4c50de9e8 100644
--- a/drivers/iio/imu/adis16400_core.c
+++ b/drivers/iio/imu/adis16400_core.c
@@ -139,7 +139,9 @@ enum adis16400_chip_variant {
139 ADIS16360, 139 ADIS16360,
140 ADIS16362, 140 ADIS16362,
141 ADIS16364, 141 ADIS16364,
142 ADIS16367,
142 ADIS16400, 143 ADIS16400,
144 ADIS16445,
143 ADIS16448, 145 ADIS16448,
144}; 146};
145 147
@@ -622,6 +624,17 @@ static const struct iio_chan_spec adis16400_channels[] = {
622 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP), 624 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP),
623}; 625};
624 626
627static const struct iio_chan_spec adis16445_channels[] = {
628 ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 16),
629 ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 16),
630 ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 16),
631 ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 16),
632 ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 16),
633 ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 16),
634 ADIS16400_TEMP_CHAN(ADIS16448_TEMP_OUT, 12),
635 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP),
636};
637
625static const struct iio_chan_spec adis16448_channels[] = { 638static const struct iio_chan_spec adis16448_channels[] = {
626 ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 16), 639 ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 16),
627 ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 16), 640 ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 16),
@@ -696,7 +709,8 @@ static struct adis16400_chip_info adis16400_chips[] = {
696 [ADIS16300] = { 709 [ADIS16300] = {
697 .channels = adis16300_channels, 710 .channels = adis16300_channels,
698 .num_channels = ARRAY_SIZE(adis16300_channels), 711 .num_channels = ARRAY_SIZE(adis16300_channels),
699 .flags = ADIS16400_HAS_SLOW_MODE, 712 .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE |
713 ADIS16400_HAS_SERIAL_NUMBER,
700 .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ 714 .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
701 .accel_scale_micro = 5884, 715 .accel_scale_micro = 5884,
702 .temp_scale_nano = 140000000, /* 0.14 C */ 716 .temp_scale_nano = 140000000, /* 0.14 C */
@@ -763,6 +777,18 @@ static struct adis16400_chip_info adis16400_chips[] = {
763 .set_freq = adis16400_set_freq, 777 .set_freq = adis16400_set_freq,
764 .get_freq = adis16400_get_freq, 778 .get_freq = adis16400_get_freq,
765 }, 779 },
780 [ADIS16367] = {
781 .channels = adis16350_channels,
782 .num_channels = ARRAY_SIZE(adis16350_channels),
783 .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE |
784 ADIS16400_HAS_SERIAL_NUMBER,
785 .gyro_scale_micro = IIO_DEGREE_TO_RAD(2000), /* 0.2 deg/s */
786 .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */
787 .temp_scale_nano = 136000000, /* 0.136 C */
788 .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */
789 .set_freq = adis16400_set_freq,
790 .get_freq = adis16400_get_freq,
791 },
766 [ADIS16400] = { 792 [ADIS16400] = {
767 .channels = adis16400_channels, 793 .channels = adis16400_channels,
768 .num_channels = ARRAY_SIZE(adis16400_channels), 794 .num_channels = ARRAY_SIZE(adis16400_channels),
@@ -774,13 +800,26 @@ static struct adis16400_chip_info adis16400_chips[] = {
774 .set_freq = adis16400_set_freq, 800 .set_freq = adis16400_set_freq,
775 .get_freq = adis16400_get_freq, 801 .get_freq = adis16400_get_freq,
776 }, 802 },
803 [ADIS16445] = {
804 .channels = adis16445_channels,
805 .num_channels = ARRAY_SIZE(adis16445_channels),
806 .flags = ADIS16400_HAS_PROD_ID |
807 ADIS16400_HAS_SERIAL_NUMBER |
808 ADIS16400_BURST_DIAG_STAT,
809 .gyro_scale_micro = IIO_DEGREE_TO_RAD(10000), /* 0.01 deg/s */
810 .accel_scale_micro = IIO_G_TO_M_S_2(250), /* 1/4000 g */
811 .temp_scale_nano = 73860000, /* 0.07386 C */
812 .temp_offset = 31000000 / 73860, /* 31 C = 0x00 */
813 .set_freq = adis16334_set_freq,
814 .get_freq = adis16334_get_freq,
815 },
777 [ADIS16448] = { 816 [ADIS16448] = {
778 .channels = adis16448_channels, 817 .channels = adis16448_channels,
779 .num_channels = ARRAY_SIZE(adis16448_channels), 818 .num_channels = ARRAY_SIZE(adis16448_channels),
780 .flags = ADIS16400_HAS_PROD_ID | 819 .flags = ADIS16400_HAS_PROD_ID |
781 ADIS16400_HAS_SERIAL_NUMBER | 820 ADIS16400_HAS_SERIAL_NUMBER |
782 ADIS16400_BURST_DIAG_STAT, 821 ADIS16400_BURST_DIAG_STAT,
783 .gyro_scale_micro = IIO_DEGREE_TO_RAD(10000), /* 0.01 deg/s */ 822 .gyro_scale_micro = IIO_DEGREE_TO_RAD(40000), /* 0.04 deg/s */
784 .accel_scale_micro = IIO_G_TO_M_S_2(833), /* 1/1200 g */ 823 .accel_scale_micro = IIO_G_TO_M_S_2(833), /* 1/1200 g */
785 .temp_scale_nano = 73860000, /* 0.07386 C */ 824 .temp_scale_nano = 73860000, /* 0.07386 C */
786 .temp_offset = 31000000 / 73860, /* 31 C = 0x00 */ 825 .temp_offset = 31000000 / 73860, /* 31 C = 0x00 */
@@ -926,6 +965,7 @@ static int adis16400_remove(struct spi_device *spi)
926 965
927static const struct spi_device_id adis16400_id[] = { 966static const struct spi_device_id adis16400_id[] = {
928 {"adis16300", ADIS16300}, 967 {"adis16300", ADIS16300},
968 {"adis16305", ADIS16300},
929 {"adis16334", ADIS16334}, 969 {"adis16334", ADIS16334},
930 {"adis16350", ADIS16350}, 970 {"adis16350", ADIS16350},
931 {"adis16354", ADIS16350}, 971 {"adis16354", ADIS16350},
@@ -934,8 +974,10 @@ static const struct spi_device_id adis16400_id[] = {
934 {"adis16362", ADIS16362}, 974 {"adis16362", ADIS16362},
935 {"adis16364", ADIS16364}, 975 {"adis16364", ADIS16364},
936 {"adis16365", ADIS16360}, 976 {"adis16365", ADIS16360},
977 {"adis16367", ADIS16367},
937 {"adis16400", ADIS16400}, 978 {"adis16400", ADIS16400},
938 {"adis16405", ADIS16400}, 979 {"adis16405", ADIS16400},
980 {"adis16445", ADIS16445},
939 {"adis16448", ADIS16448}, 981 {"adis16448", ADIS16448},
940 {} 982 {}
941}; 983};
diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 989605dd6f78..b94bfd3f595b 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -110,6 +110,10 @@
110struct adis16480_chip_info { 110struct adis16480_chip_info {
111 unsigned int num_channels; 111 unsigned int num_channels;
112 const struct iio_chan_spec *channels; 112 const struct iio_chan_spec *channels;
113 unsigned int gyro_max_val;
114 unsigned int gyro_max_scale;
115 unsigned int accel_max_val;
116 unsigned int accel_max_scale;
113}; 117};
114 118
115struct adis16480 { 119struct adis16480 {
@@ -497,19 +501,21 @@ static int adis16480_set_filter_freq(struct iio_dev *indio_dev,
497static int adis16480_read_raw(struct iio_dev *indio_dev, 501static int adis16480_read_raw(struct iio_dev *indio_dev,
498 const struct iio_chan_spec *chan, int *val, int *val2, long info) 502 const struct iio_chan_spec *chan, int *val, int *val2, long info)
499{ 503{
504 struct adis16480 *st = iio_priv(indio_dev);
505
500 switch (info) { 506 switch (info) {
501 case IIO_CHAN_INFO_RAW: 507 case IIO_CHAN_INFO_RAW:
502 return adis_single_conversion(indio_dev, chan, 0, val); 508 return adis_single_conversion(indio_dev, chan, 0, val);
503 case IIO_CHAN_INFO_SCALE: 509 case IIO_CHAN_INFO_SCALE:
504 switch (chan->type) { 510 switch (chan->type) {
505 case IIO_ANGL_VEL: 511 case IIO_ANGL_VEL:
506 *val = 0; 512 *val = st->chip_info->gyro_max_scale;
507 *val2 = IIO_DEGREE_TO_RAD(20000); /* 0.02 degree/sec */ 513 *val2 = st->chip_info->gyro_max_val;
508 return IIO_VAL_INT_PLUS_MICRO; 514 return IIO_VAL_FRACTIONAL;
509 case IIO_ACCEL: 515 case IIO_ACCEL:
510 *val = 0; 516 *val = st->chip_info->accel_max_scale;
511 *val2 = IIO_G_TO_M_S_2(800); /* 0.8 mg */ 517 *val2 = st->chip_info->accel_max_val;
512 return IIO_VAL_INT_PLUS_MICRO; 518 return IIO_VAL_FRACTIONAL;
513 case IIO_MAGN: 519 case IIO_MAGN:
514 *val = 0; 520 *val = 0;
515 *val2 = 100; /* 0.0001 gauss */ 521 *val2 = 100; /* 0.0001 gauss */
@@ -674,18 +680,39 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
674 [ADIS16375] = { 680 [ADIS16375] = {
675 .channels = adis16485_channels, 681 .channels = adis16485_channels,
676 .num_channels = ARRAY_SIZE(adis16485_channels), 682 .num_channels = ARRAY_SIZE(adis16485_channels),
683 /*
684 * storing the value in rad/degree and the scale in degree
685 * gives us the result in rad and better precession than
686 * storing the scale directly in rad.
687 */
688 .gyro_max_val = IIO_RAD_TO_DEGREE(22887),
689 .gyro_max_scale = 300,
690 .accel_max_val = IIO_M_S_2_TO_G(21973),
691 .accel_max_scale = 18,
677 }, 692 },
678 [ADIS16480] = { 693 [ADIS16480] = {
679 .channels = adis16480_channels, 694 .channels = adis16480_channels,
680 .num_channels = ARRAY_SIZE(adis16480_channels), 695 .num_channels = ARRAY_SIZE(adis16480_channels),
696 .gyro_max_val = IIO_RAD_TO_DEGREE(22500),
697 .gyro_max_scale = 450,
698 .accel_max_val = IIO_M_S_2_TO_G(12500),
699 .accel_max_scale = 5,
681 }, 700 },
682 [ADIS16485] = { 701 [ADIS16485] = {
683 .channels = adis16485_channels, 702 .channels = adis16485_channels,
684 .num_channels = ARRAY_SIZE(adis16485_channels), 703 .num_channels = ARRAY_SIZE(adis16485_channels),
704 .gyro_max_val = IIO_RAD_TO_DEGREE(22500),
705 .gyro_max_scale = 450,
706 .accel_max_val = IIO_M_S_2_TO_G(20000),
707 .accel_max_scale = 5,
685 }, 708 },
686 [ADIS16488] = { 709 [ADIS16488] = {
687 .channels = adis16480_channels, 710 .channels = adis16480_channels,
688 .num_channels = ARRAY_SIZE(adis16480_channels), 711 .num_channels = ARRAY_SIZE(adis16480_channels),
712 .gyro_max_val = IIO_RAD_TO_DEGREE(22500),
713 .gyro_max_scale = 450,
714 .accel_max_val = IIO_M_S_2_TO_G(22500),
715 .accel_max_scale = 18,
689 }, 716 },
690}; 717};
691 718
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 65ce86837177..f0e06093b5e8 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -690,6 +690,10 @@ static const struct iio_chan_spec inv_mpu_channels[] = {
690 690
691/* constant IIO attribute */ 691/* constant IIO attribute */
692static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("10 20 50 100 200 500"); 692static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("10 20 50 100 200 500");
693static IIO_CONST_ATTR(in_anglvel_scale_available,
694 "0.000133090 0.000266181 0.000532362 0.001064724");
695static IIO_CONST_ATTR(in_accel_scale_available,
696 "0.000598 0.001196 0.002392 0.004785");
693static IIO_DEV_ATTR_SAMP_FREQ(S_IRUGO | S_IWUSR, inv_fifo_rate_show, 697static IIO_DEV_ATTR_SAMP_FREQ(S_IRUGO | S_IWUSR, inv_fifo_rate_show,
694 inv_mpu6050_fifo_rate_store); 698 inv_mpu6050_fifo_rate_store);
695static IIO_DEVICE_ATTR(in_gyro_matrix, S_IRUGO, inv_attr_show, NULL, 699static IIO_DEVICE_ATTR(in_gyro_matrix, S_IRUGO, inv_attr_show, NULL,
@@ -702,6 +706,8 @@ static struct attribute *inv_attributes[] = {
702 &iio_dev_attr_in_accel_matrix.dev_attr.attr, 706 &iio_dev_attr_in_accel_matrix.dev_attr.attr,
703 &iio_dev_attr_sampling_frequency.dev_attr.attr, 707 &iio_dev_attr_sampling_frequency.dev_attr.attr,
704 &iio_const_attr_sampling_frequency_available.dev_attr.attr, 708 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
709 &iio_const_attr_in_accel_scale_available.dev_attr.attr,
710 &iio_const_attr_in_anglvel_scale_available.dev_attr.attr,
705 NULL, 711 NULL,
706}; 712};
707 713
@@ -921,7 +927,6 @@ static struct i2c_driver inv_mpu_driver = {
921 .remove = inv_mpu_remove, 927 .remove = inv_mpu_remove,
922 .id_table = inv_mpu_id, 928 .id_table = inv_mpu_id,
923 .driver = { 929 .driver = {
924 .owner = THIS_MODULE,
925 .name = "inv-mpu6050", 930 .name = "inv-mpu6050",
926 .pm = INV_MPU6050_PMOPS, 931 .pm = INV_MPU6050_PMOPS,
927 .acpi_match_table = ACPI_PTR(inv_acpi_match), 932 .acpi_match_table = ACPI_PTR(inv_acpi_match),
diff --git a/drivers/iio/imu/kmx61.c b/drivers/iio/imu/kmx61.c
index 462a010628cd..82cdf5090fa7 100644
--- a/drivers/iio/imu/kmx61.c
+++ b/drivers/iio/imu/kmx61.c
@@ -1363,7 +1363,7 @@ static int kmx61_probe(struct i2c_client *client,
1363 if (client->irq < 0) 1363 if (client->irq < 0)
1364 client->irq = kmx61_gpio_probe(client, data); 1364 client->irq = kmx61_gpio_probe(client, data);
1365 1365
1366 if (client->irq >= 0) { 1366 if (client->irq > 0) {
1367 ret = devm_request_threaded_irq(&client->dev, client->irq, 1367 ret = devm_request_threaded_irq(&client->dev, client->irq,
1368 kmx61_data_rdy_trig_poll, 1368 kmx61_data_rdy_trig_poll,
1369 kmx61_event_handler, 1369 kmx61_event_handler,
@@ -1445,10 +1445,10 @@ err_iio_unregister_mag:
1445err_iio_unregister_acc: 1445err_iio_unregister_acc:
1446 iio_device_unregister(data->acc_indio_dev); 1446 iio_device_unregister(data->acc_indio_dev);
1447err_buffer_cleanup_mag: 1447err_buffer_cleanup_mag:
1448 if (client->irq >= 0) 1448 if (client->irq > 0)
1449 iio_triggered_buffer_cleanup(data->mag_indio_dev); 1449 iio_triggered_buffer_cleanup(data->mag_indio_dev);
1450err_buffer_cleanup_acc: 1450err_buffer_cleanup_acc:
1451 if (client->irq >= 0) 1451 if (client->irq > 0)
1452 iio_triggered_buffer_cleanup(data->acc_indio_dev); 1452 iio_triggered_buffer_cleanup(data->acc_indio_dev);
1453err_trigger_unregister_motion: 1453err_trigger_unregister_motion:
1454 iio_trigger_unregister(data->motion_trig); 1454 iio_trigger_unregister(data->motion_trig);
@@ -1472,7 +1472,7 @@ static int kmx61_remove(struct i2c_client *client)
1472 iio_device_unregister(data->acc_indio_dev); 1472 iio_device_unregister(data->acc_indio_dev);
1473 iio_device_unregister(data->mag_indio_dev); 1473 iio_device_unregister(data->mag_indio_dev);
1474 1474
1475 if (client->irq >= 0) { 1475 if (client->irq > 0) {
1476 iio_triggered_buffer_cleanup(data->acc_indio_dev); 1476 iio_triggered_buffer_cleanup(data->acc_indio_dev);
1477 iio_triggered_buffer_cleanup(data->mag_indio_dev); 1477 iio_triggered_buffer_cleanup(data->mag_indio_dev);
1478 iio_trigger_unregister(data->acc_dready_trig); 1478 iio_trigger_unregister(data->acc_dready_trig);
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 6eee1b044c60..d7e908acb480 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -71,8 +71,9 @@ static bool iio_buffer_ready(struct iio_dev *indio_dev, struct iio_buffer *buf,
71 71
72 if (avail >= to_wait) { 72 if (avail >= to_wait) {
73 /* force a flush for non-blocking reads */ 73 /* force a flush for non-blocking reads */
74 if (!to_wait && !avail && to_flush) 74 if (!to_wait && avail < to_flush)
75 iio_buffer_flush_hwfifo(indio_dev, buf, to_flush); 75 iio_buffer_flush_hwfifo(indio_dev, buf,
76 to_flush - avail);
76 return true; 77 return true;
77 } 78 }
78 79
@@ -90,9 +91,16 @@ static bool iio_buffer_ready(struct iio_dev *indio_dev, struct iio_buffer *buf,
90 91
91/** 92/**
92 * iio_buffer_read_first_n_outer() - chrdev read for buffer access 93 * iio_buffer_read_first_n_outer() - chrdev read for buffer access
94 * @filp: File structure pointer for the char device
95 * @buf: Destination buffer for iio buffer read
96 * @n: First n bytes to read
97 * @f_ps: Long offset provided by the user as a seek position
93 * 98 *
94 * This function relies on all buffer implementations having an 99 * This function relies on all buffer implementations having an
95 * iio_buffer as their first element. 100 * iio_buffer as their first element.
101 *
102 * Return: negative values corresponding to error codes or ret != 0
103 * for ending the reading activity
96 **/ 104 **/
97ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf, 105ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
98 size_t n, loff_t *f_ps) 106 size_t n, loff_t *f_ps)
@@ -100,8 +108,7 @@ ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
100 struct iio_dev *indio_dev = filp->private_data; 108 struct iio_dev *indio_dev = filp->private_data;
101 struct iio_buffer *rb = indio_dev->buffer; 109 struct iio_buffer *rb = indio_dev->buffer;
102 size_t datum_size; 110 size_t datum_size;
103 size_t to_wait = 0; 111 size_t to_wait;
104 size_t to_read;
105 int ret; 112 int ret;
106 113
107 if (!indio_dev->info) 114 if (!indio_dev->info)
@@ -119,14 +126,14 @@ ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
119 if (!datum_size) 126 if (!datum_size)
120 return 0; 127 return 0;
121 128
122 to_read = min_t(size_t, n / datum_size, rb->watermark); 129 if (filp->f_flags & O_NONBLOCK)
123 130 to_wait = 0;
124 if (!(filp->f_flags & O_NONBLOCK)) 131 else
125 to_wait = to_read; 132 to_wait = min_t(size_t, n / datum_size, rb->watermark);
126 133
127 do { 134 do {
128 ret = wait_event_interruptible(rb->pollq, 135 ret = wait_event_interruptible(rb->pollq,
129 iio_buffer_ready(indio_dev, rb, to_wait, to_read)); 136 iio_buffer_ready(indio_dev, rb, to_wait, n / datum_size));
130 if (ret) 137 if (ret)
131 return ret; 138 return ret;
132 139
@@ -143,6 +150,12 @@ ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
143 150
144/** 151/**
145 * iio_buffer_poll() - poll the buffer to find out if it has data 152 * iio_buffer_poll() - poll the buffer to find out if it has data
153 * @filp: File structure pointer for device access
154 * @wait: Poll table structure pointer for which the driver adds
155 * a wait queue
156 *
157 * Return: (POLLIN | POLLRDNORM) if data is available for reading
158 * or 0 for other cases
146 */ 159 */
147unsigned int iio_buffer_poll(struct file *filp, 160unsigned int iio_buffer_poll(struct file *filp,
148 struct poll_table_struct *wait) 161 struct poll_table_struct *wait)
@@ -151,7 +164,7 @@ unsigned int iio_buffer_poll(struct file *filp,
151 struct iio_buffer *rb = indio_dev->buffer; 164 struct iio_buffer *rb = indio_dev->buffer;
152 165
153 if (!indio_dev->info) 166 if (!indio_dev->info)
154 return -ENODEV; 167 return 0;
155 168
156 poll_wait(filp, &rb->pollq, wait); 169 poll_wait(filp, &rb->pollq, wait);
157 if (iio_buffer_ready(indio_dev, rb, rb->watermark, 0)) 170 if (iio_buffer_ready(indio_dev, rb, rb->watermark, 0))
@@ -1136,7 +1149,7 @@ int iio_scan_mask_query(struct iio_dev *indio_dev,
1136EXPORT_SYMBOL_GPL(iio_scan_mask_query); 1149EXPORT_SYMBOL_GPL(iio_scan_mask_query);
1137 1150
1138/** 1151/**
1139 * struct iio_demux_table() - table describing demux memcpy ops 1152 * struct iio_demux_table - table describing demux memcpy ops
1140 * @from: index to copy from 1153 * @from: index to copy from
1141 * @to: index to copy to 1154 * @to: index to copy to
1142 * @length: how many bytes to copy 1155 * @length: how many bytes to copy
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 3524b0de8721..b3fcc2c449d8 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -81,6 +81,14 @@ static const char * const iio_modifier_names[] = {
81 [IIO_MOD_X] = "x", 81 [IIO_MOD_X] = "x",
82 [IIO_MOD_Y] = "y", 82 [IIO_MOD_Y] = "y",
83 [IIO_MOD_Z] = "z", 83 [IIO_MOD_Z] = "z",
84 [IIO_MOD_X_AND_Y] = "x&y",
85 [IIO_MOD_X_AND_Z] = "x&z",
86 [IIO_MOD_Y_AND_Z] = "y&z",
87 [IIO_MOD_X_AND_Y_AND_Z] = "x&y&z",
88 [IIO_MOD_X_OR_Y] = "x|y",
89 [IIO_MOD_X_OR_Z] = "x|z",
90 [IIO_MOD_Y_OR_Z] = "y|z",
91 [IIO_MOD_X_OR_Y_OR_Z] = "x|y|z",
84 [IIO_MOD_ROOT_SUM_SQUARED_X_Y] = "sqrt(x^2+y^2)", 92 [IIO_MOD_ROOT_SUM_SQUARED_X_Y] = "sqrt(x^2+y^2)",
85 [IIO_MOD_SUM_SQUARED_X_Y_Z] = "x^2+y^2+z^2", 93 [IIO_MOD_SUM_SQUARED_X_Y_Z] = "x^2+y^2+z^2",
86 [IIO_MOD_LIGHT_BOTH] = "both", 94 [IIO_MOD_LIGHT_BOTH] = "both",
@@ -398,10 +406,16 @@ EXPORT_SYMBOL_GPL(iio_enum_write);
398 406
399/** 407/**
400 * iio_format_value() - Formats a IIO value into its string representation 408 * iio_format_value() - Formats a IIO value into its string representation
401 * @buf: The buffer to which the formated value gets written 409 * @buf: The buffer to which the formatted value gets written
402 * @type: One of the IIO_VAL_... constants. This decides how the val and val2 410 * @type: One of the IIO_VAL_... constants. This decides how the val
403 * parameters are formatted. 411 * and val2 parameters are formatted.
404 * @vals: pointer to the values, exact meaning depends on the type parameter. 412 * @size: Number of IIO value entries contained in vals
413 * @vals: Pointer to the values, exact meaning depends on the
414 * type parameter.
415 *
416 * Return: 0 by default, a negative number on failure or the
417 * total number of characters written for a type that belongs
418 * to the IIO_VAL_... constant.
405 */ 419 */
406ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals) 420ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals)
407{ 421{
@@ -1088,6 +1102,11 @@ EXPORT_SYMBOL_GPL(devm_iio_device_free);
1088 1102
1089/** 1103/**
1090 * iio_chrdev_open() - chrdev file open for buffer access and ioctls 1104 * iio_chrdev_open() - chrdev file open for buffer access and ioctls
1105 * @inode: Inode structure for identifying the device in the file system
1106 * @filp: File structure for iio device used to keep and later access
1107 * private data
1108 *
1109 * Return: 0 on success or -EBUSY if the device is already opened
1091 **/ 1110 **/
1092static int iio_chrdev_open(struct inode *inode, struct file *filp) 1111static int iio_chrdev_open(struct inode *inode, struct file *filp)
1093{ 1112{
@@ -1106,7 +1125,11 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)
1106 1125
1107/** 1126/**
1108 * iio_chrdev_release() - chrdev file close buffer access and ioctls 1127 * iio_chrdev_release() - chrdev file close buffer access and ioctls
1109 **/ 1128 * @inode: Inode structure pointer for the char device
1129 * @filp: File structure pointer for the char device
1130 *
1131 * Return: 0 for successful release
1132 */
1110static int iio_chrdev_release(struct inode *inode, struct file *filp) 1133static int iio_chrdev_release(struct inode *inode, struct file *filp)
1111{ 1134{
1112 struct iio_dev *indio_dev = container_of(inode->i_cdev, 1135 struct iio_dev *indio_dev = container_of(inode->i_cdev,
diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
index 894d8137c4cf..cae332b1d7ea 100644
--- a/drivers/iio/industrialio-event.c
+++ b/drivers/iio/industrialio-event.c
@@ -32,6 +32,7 @@
32 * @dev_attr_list: list of event interface sysfs attribute 32 * @dev_attr_list: list of event interface sysfs attribute
33 * @flags: file operations related flags including busy flag. 33 * @flags: file operations related flags including busy flag.
34 * @group: event interface sysfs attribute group 34 * @group: event interface sysfs attribute group
35 * @read_lock: lock to protect kfifo read operations
35 */ 36 */
36struct iio_event_interface { 37struct iio_event_interface {
37 wait_queue_head_t wait; 38 wait_queue_head_t wait;
@@ -75,6 +76,11 @@ EXPORT_SYMBOL(iio_push_event);
75 76
76/** 77/**
77 * iio_event_poll() - poll the event queue to find out if it has data 78 * iio_event_poll() - poll the event queue to find out if it has data
79 * @filep: File structure pointer to identify the device
80 * @wait: Poll table pointer to add the wait queue on
81 *
82 * Return: (POLLIN | POLLRDNORM) if data is available for reading
83 * or a negative error code on failure
78 */ 84 */
79static unsigned int iio_event_poll(struct file *filep, 85static unsigned int iio_event_poll(struct file *filep,
80 struct poll_table_struct *wait) 86 struct poll_table_struct *wait)
@@ -84,7 +90,7 @@ static unsigned int iio_event_poll(struct file *filep,
84 unsigned int events = 0; 90 unsigned int events = 0;
85 91
86 if (!indio_dev->info) 92 if (!indio_dev->info)
87 return -ENODEV; 93 return events;
88 94
89 poll_wait(filep, &ev_int->wait, wait); 95 poll_wait(filep, &ev_int->wait, wait);
90 96
diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index d31098e0c43f..570606c2adbd 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -40,7 +40,14 @@ static DEFINE_MUTEX(iio_trigger_list_lock);
40 40
41/** 41/**
42 * iio_trigger_read_name() - retrieve useful identifying name 42 * iio_trigger_read_name() - retrieve useful identifying name
43 **/ 43 * @dev: device associated with the iio_trigger
44 * @attr: pointer to the device_attribute structure that is
45 * being processed
46 * @buf: buffer to print the name into
47 *
48 * Return: a negative number on failure or the number of written
49 * characters on success.
50 */
44static ssize_t iio_trigger_read_name(struct device *dev, 51static ssize_t iio_trigger_read_name(struct device *dev,
45 struct device_attribute *attr, 52 struct device_attribute *attr,
46 char *buf) 53 char *buf)
@@ -288,10 +295,17 @@ EXPORT_SYMBOL_GPL(iio_dealloc_pollfunc);
288 295
289/** 296/**
290 * iio_trigger_read_current() - trigger consumer sysfs query current trigger 297 * iio_trigger_read_current() - trigger consumer sysfs query current trigger
298 * @dev: device associated with an industrial I/O device
299 * @attr: pointer to the device_attribute structure that
300 * is being processed
301 * @buf: buffer where the current trigger name will be printed into
291 * 302 *
292 * For trigger consumers the current_trigger interface allows the trigger 303 * For trigger consumers the current_trigger interface allows the trigger
293 * used by the device to be queried. 304 * used by the device to be queried.
294 **/ 305 *
306 * Return: a negative number on failure, the number of characters written
307 * on success or 0 if no trigger is available
308 */
295static ssize_t iio_trigger_read_current(struct device *dev, 309static ssize_t iio_trigger_read_current(struct device *dev,
296 struct device_attribute *attr, 310 struct device_attribute *attr,
297 char *buf) 311 char *buf)
@@ -305,11 +319,18 @@ static ssize_t iio_trigger_read_current(struct device *dev,
305 319
306/** 320/**
307 * iio_trigger_write_current() - trigger consumer sysfs set current trigger 321 * iio_trigger_write_current() - trigger consumer sysfs set current trigger
322 * @dev: device associated with an industrial I/O device
323 * @attr: device attribute that is being processed
324 * @buf: string buffer that holds the name of the trigger
325 * @len: length of the trigger name held by buf
308 * 326 *
309 * For trigger consumers the current_trigger interface allows the trigger 327 * For trigger consumers the current_trigger interface allows the trigger
310 * used for this device to be specified at run time based on the trigger's 328 * used for this device to be specified at run time based on the trigger's
311 * name. 329 * name.
312 **/ 330 *
331 * Return: negative error code on failure or length of the buffer
332 * on success
333 */
313static ssize_t iio_trigger_write_current(struct device *dev, 334static ssize_t iio_trigger_write_current(struct device *dev,
314 struct device_attribute *attr, 335 struct device_attribute *attr,
315 const char *buf, 336 const char *buf,
diff --git a/drivers/iio/industrialio-triggered-buffer.c b/drivers/iio/industrialio-triggered-buffer.c
index 15a5341b5e7b..4b2858ba1fd6 100644
--- a/drivers/iio/industrialio-triggered-buffer.c
+++ b/drivers/iio/industrialio-triggered-buffer.c
@@ -24,8 +24,8 @@ static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = {
24/** 24/**
25 * iio_triggered_buffer_setup() - Setup triggered buffer and pollfunc 25 * iio_triggered_buffer_setup() - Setup triggered buffer and pollfunc
26 * @indio_dev: IIO device structure 26 * @indio_dev: IIO device structure
27 * @pollfunc_bh: Function which will be used as pollfunc bottom half 27 * @h: Function which will be used as pollfunc top half
28 * @pollfunc_th: Function which will be used as pollfunc top half 28 * @thread: Function which will be used as pollfunc bottom half
29 * @setup_ops: Buffer setup functions to use for this device. 29 * @setup_ops: Buffer setup functions to use for this device.
30 * If NULL the default setup functions for triggered 30 * If NULL the default setup functions for triggered
31 * buffers will be used. 31 * buffers will be used.
@@ -42,8 +42,8 @@ static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = {
42 * iio_triggered_buffer_cleanup(). 42 * iio_triggered_buffer_cleanup().
43 */ 43 */
44int iio_triggered_buffer_setup(struct iio_dev *indio_dev, 44int iio_triggered_buffer_setup(struct iio_dev *indio_dev,
45 irqreturn_t (*pollfunc_bh)(int irq, void *p), 45 irqreturn_t (*h)(int irq, void *p),
46 irqreturn_t (*pollfunc_th)(int irq, void *p), 46 irqreturn_t (*thread)(int irq, void *p),
47 const struct iio_buffer_setup_ops *setup_ops) 47 const struct iio_buffer_setup_ops *setup_ops)
48{ 48{
49 struct iio_buffer *buffer; 49 struct iio_buffer *buffer;
@@ -57,8 +57,8 @@ int iio_triggered_buffer_setup(struct iio_dev *indio_dev,
57 57
58 iio_device_attach_buffer(indio_dev, buffer); 58 iio_device_attach_buffer(indio_dev, buffer);
59 59
60 indio_dev->pollfunc = iio_alloc_pollfunc(pollfunc_bh, 60 indio_dev->pollfunc = iio_alloc_pollfunc(h,
61 pollfunc_th, 61 thread,
62 IRQF_ONESHOT, 62 IRQF_ONESHOT,
63 indio_dev, 63 indio_dev,
64 "%s_consumer%d", 64 "%s_consumer%d",
diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index a5c59251ec0e..7ed859a700c4 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -86,7 +86,7 @@ config CM3323
86 depends on I2C 86 depends on I2C
87 tristate "Capella CM3323 color light sensor" 87 tristate "Capella CM3323 color light sensor"
88 help 88 help
89 Say Y here if you want to build a driver for Capela CM3323 89 Say Y here if you want to build a driver for Capella CM3323
90 color sensor. 90 color sensor.
91 91
92 To compile this driver as a module, choose M here: the module will 92 To compile this driver as a module, choose M here: the module will
@@ -168,6 +168,17 @@ config JSA1212
168 To compile this driver as a module, choose M here: 168 To compile this driver as a module, choose M here:
169 the module will be called jsa1212. 169 the module will be called jsa1212.
170 170
171config RPR0521
172 tristate "ROHM RPR0521 ALS and proximity sensor driver"
173 depends on I2C
174 select REGMAP_I2C
175 help
176 Say Y here if you want to build support for ROHM's RPR0521
177 ambient light and proximity sensor device.
178
179 To compile this driver as a module, choose M here:
180 the module will be called rpr0521.
181
171config SENSORS_LM3533 182config SENSORS_LM3533
172 tristate "LM3533 ambient light sensor" 183 tristate "LM3533 ambient light sensor"
173 depends on MFD_LM3533 184 depends on MFD_LM3533
@@ -199,6 +210,27 @@ config LTR501
199 This driver can also be built as a module. If so, the module 210 This driver can also be built as a module. If so, the module
200 will be called ltr501. 211 will be called ltr501.
201 212
213config OPT3001
214 tristate "Texas Instruments OPT3001 Light Sensor"
215 depends on I2C
216 help
217 If you say Y or M here, you get support for Texas Instruments
218 OPT3001 Ambient Light Sensor.
219
220 If built as a dynamically linked module, it will be called
221 opt3001.
222
223config PA12203001
224 tristate "TXC PA12203001 light and proximity sensor"
225 depends on I2C
226 select REGMAP_I2C
227 help
228 If you say yes here you get support for the TXC PA12203001
229 ambient light and proximity sensor.
230
231 This driver can also be built as a module. If so, the module
232 will be called pa12203001.
233
202config STK3310 234config STK3310
203 tristate "STK3310 ALS and proximity sensor" 235 tristate "STK3310 ALS and proximity sensor"
204 depends on I2C 236 depends on I2C
diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
index e2d50fd59c66..91c74c014b6f 100644
--- a/drivers/iio/light/Makefile
+++ b/drivers/iio/light/Makefile
@@ -19,6 +19,9 @@ obj-$(CONFIG_ISL29125) += isl29125.o
19obj-$(CONFIG_JSA1212) += jsa1212.o 19obj-$(CONFIG_JSA1212) += jsa1212.o
20obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o 20obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o
21obj-$(CONFIG_LTR501) += ltr501.o 21obj-$(CONFIG_LTR501) += ltr501.o
22obj-$(CONFIG_OPT3001) += opt3001.o
23obj-$(CONFIG_PA12203001) += pa12203001.o
24obj-$(CONFIG_RPR0521) += rpr0521.o
22obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o 25obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o
23obj-$(CONFIG_STK3310) += stk3310.o 26obj-$(CONFIG_STK3310) += stk3310.o
24obj-$(CONFIG_TCS3414) += tcs3414.o 27obj-$(CONFIG_TCS3414) += tcs3414.o
diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
index 1dafa0756bfa..60537ec0c923 100644
--- a/drivers/iio/light/acpi-als.c
+++ b/drivers/iio/light/acpi-als.c
@@ -65,20 +65,20 @@ static const struct iio_chan_spec acpi_als_channels[] = {
65 * to acpi_als_channels[], the evt_buffer below will grow 65 * to acpi_als_channels[], the evt_buffer below will grow
66 * automatically. 66 * automatically.
67 */ 67 */
68#define EVT_NR_SOURCES ARRAY_SIZE(acpi_als_channels) 68#define ACPI_ALS_EVT_NR_SOURCES ARRAY_SIZE(acpi_als_channels)
69#define EVT_BUFFER_SIZE \ 69#define ACPI_ALS_EVT_BUFFER_SIZE \
70 (sizeof(s64) + (EVT_NR_SOURCES * sizeof(s32))) 70 (sizeof(s64) + (ACPI_ALS_EVT_NR_SOURCES * sizeof(s32)))
71 71
72struct acpi_als { 72struct acpi_als {
73 struct acpi_device *device; 73 struct acpi_device *device;
74 struct mutex lock; 74 struct mutex lock;
75 75
76 s32 evt_buffer[EVT_BUFFER_SIZE]; 76 s32 evt_buffer[ACPI_ALS_EVT_BUFFER_SIZE];
77}; 77};
78 78
79/* 79/*
80 * All types of properties the ACPI0008 block can report. The ALI, ALC, ALT 80 * All types of properties the ACPI0008 block can report. The ALI, ALC, ALT
81 * and ALP can all be handled by als_read_value() below, while the ALR is 81 * and ALP can all be handled by acpi_als_read_value() below, while the ALR is
82 * special. 82 * special.
83 * 83 *
84 * The _ALR property returns tables that can be used to fine-tune the values 84 * The _ALR property returns tables that can be used to fine-tune the values
@@ -93,7 +93,7 @@ struct acpi_als {
93#define ACPI_ALS_POLLING "_ALP" 93#define ACPI_ALS_POLLING "_ALP"
94#define ACPI_ALS_TABLES "_ALR" 94#define ACPI_ALS_TABLES "_ALR"
95 95
96static int als_read_value(struct acpi_als *als, char *prop, s32 *val) 96static int acpi_als_read_value(struct acpi_als *als, char *prop, s32 *val)
97{ 97{
98 unsigned long long temp_val; 98 unsigned long long temp_val;
99 acpi_status status; 99 acpi_status status;
@@ -122,11 +122,11 @@ static void acpi_als_notify(struct acpi_device *device, u32 event)
122 122
123 mutex_lock(&als->lock); 123 mutex_lock(&als->lock);
124 124
125 memset(buffer, 0, EVT_BUFFER_SIZE); 125 memset(buffer, 0, ACPI_ALS_EVT_BUFFER_SIZE);
126 126
127 switch (event) { 127 switch (event) {
128 case ACPI_ALS_NOTIFY_ILLUMINANCE: 128 case ACPI_ALS_NOTIFY_ILLUMINANCE:
129 ret = als_read_value(als, ACPI_ALS_ILLUMINANCE, &val); 129 ret = acpi_als_read_value(als, ACPI_ALS_ILLUMINANCE, &val);
130 if (ret < 0) 130 if (ret < 0)
131 goto out; 131 goto out;
132 *buffer++ = val; 132 *buffer++ = val;
@@ -159,7 +159,7 @@ static int acpi_als_read_raw(struct iio_dev *indio_dev,
159 if (chan->type != IIO_LIGHT) 159 if (chan->type != IIO_LIGHT)
160 return -EINVAL; 160 return -EINVAL;
161 161
162 ret = als_read_value(als, ACPI_ALS_ILLUMINANCE, &temp_val); 162 ret = acpi_als_read_value(als, ACPI_ALS_ILLUMINANCE, &temp_val);
163 if (ret < 0) 163 if (ret < 0)
164 return ret; 164 return ret;
165 165
diff --git a/drivers/iio/light/apds9300.c b/drivers/iio/light/apds9300.c
index 9ddde0ca9c34..e1b9fa5a7e91 100644
--- a/drivers/iio/light/apds9300.c
+++ b/drivers/iio/light/apds9300.c
@@ -515,7 +515,6 @@ MODULE_DEVICE_TABLE(i2c, apds9300_id);
515static struct i2c_driver apds9300_driver = { 515static struct i2c_driver apds9300_driver = {
516 .driver = { 516 .driver = {
517 .name = APDS9300_DRV_NAME, 517 .name = APDS9300_DRV_NAME,
518 .owner = THIS_MODULE,
519 .pm = APDS9300_PM_OPS, 518 .pm = APDS9300_PM_OPS,
520 }, 519 },
521 .probe = apds9300_probe, 520 .probe = apds9300_probe,
diff --git a/drivers/iio/light/bh1750.c b/drivers/iio/light/bh1750.c
index 564c2b3c1a83..8b4164343f20 100644
--- a/drivers/iio/light/bh1750.c
+++ b/drivers/iio/light/bh1750.c
@@ -319,7 +319,6 @@ MODULE_DEVICE_TABLE(i2c, bh1750_id);
319static struct i2c_driver bh1750_driver = { 319static struct i2c_driver bh1750_driver = {
320 .driver = { 320 .driver = {
321 .name = "bh1750", 321 .name = "bh1750",
322 .owner = THIS_MODULE,
323 .pm = BH1750_PM_OPS, 322 .pm = BH1750_PM_OPS,
324 }, 323 },
325 .probe = bh1750_probe, 324 .probe = bh1750_probe,
diff --git a/drivers/iio/light/cm32181.c b/drivers/iio/light/cm32181.c
index 5d12ae54d088..d6fd0dace74f 100644
--- a/drivers/iio/light/cm32181.c
+++ b/drivers/iio/light/cm32181.c
@@ -353,12 +353,12 @@ static const struct of_device_id cm32181_of_match[] = {
353 { .compatible = "capella,cm32181" }, 353 { .compatible = "capella,cm32181" },
354 { } 354 { }
355}; 355};
356MODULE_DEVICE_TABLE(of, cm32181_of_match);
356 357
357static struct i2c_driver cm32181_driver = { 358static struct i2c_driver cm32181_driver = {
358 .driver = { 359 .driver = {
359 .name = "cm32181", 360 .name = "cm32181",
360 .of_match_table = of_match_ptr(cm32181_of_match), 361 .of_match_table = of_match_ptr(cm32181_of_match),
361 .owner = THIS_MODULE,
362 }, 362 },
363 .id_table = cm32181_id, 363 .id_table = cm32181_id,
364 .probe = cm32181_probe, 364 .probe = cm32181_probe,
diff --git a/drivers/iio/light/cm3232.c b/drivers/iio/light/cm3232.c
index 39c8d99cc48e..fe89b6823217 100644
--- a/drivers/iio/light/cm3232.c
+++ b/drivers/iio/light/cm3232.c
@@ -417,11 +417,11 @@ static const struct of_device_id cm3232_of_match[] = {
417 {.compatible = "capella,cm3232"}, 417 {.compatible = "capella,cm3232"},
418 {} 418 {}
419}; 419};
420MODULE_DEVICE_TABLE(of, cm3232_of_match);
420 421
421static struct i2c_driver cm3232_driver = { 422static struct i2c_driver cm3232_driver = {
422 .driver = { 423 .driver = {
423 .name = "cm3232", 424 .name = "cm3232",
424 .owner = THIS_MODULE,
425 .of_match_table = of_match_ptr(cm3232_of_match), 425 .of_match_table = of_match_ptr(cm3232_of_match),
426#ifdef CONFIG_PM_SLEEP 426#ifdef CONFIG_PM_SLEEP
427 .pm = &cm3232_pm_ops, 427 .pm = &cm3232_pm_ops,
diff --git a/drivers/iio/light/cm3323.c b/drivers/iio/light/cm3323.c
index a1d4905cc9d2..d823c112d54b 100644
--- a/drivers/iio/light/cm3323.c
+++ b/drivers/iio/light/cm3323.c
@@ -29,7 +29,7 @@
29 29
30#define CM3323_CONF_SD_BIT BIT(0) /* sensor disable */ 30#define CM3323_CONF_SD_BIT BIT(0) /* sensor disable */
31#define CM3323_CONF_AF_BIT BIT(1) /* auto/manual force mode */ 31#define CM3323_CONF_AF_BIT BIT(1) /* auto/manual force mode */
32#define CM3323_CONF_IT_MASK (BIT(4) | BIT(5) | BIT(6)) 32#define CM3323_CONF_IT_MASK GENMASK(6, 4)
33#define CM3323_CONF_IT_SHIFT 4 33#define CM3323_CONF_IT_SHIFT 4
34 34
35#define CM3323_INT_TIME_AVAILABLE "0.04 0.08 0.16 0.32 0.64 1.28" 35#define CM3323_INT_TIME_AVAILABLE "0.04 0.08 0.16 0.32 0.64 1.28"
@@ -133,9 +133,11 @@ static int cm3323_set_it_bits(struct cm3323_data *data, int val, int val2)
133 return ret; 133 return ret;
134 134
135 data->reg_conf = reg_conf; 135 data->reg_conf = reg_conf;
136
136 return 0; 137 return 0;
137 } 138 }
138 } 139 }
140
139 return -EINVAL; 141 return -EINVAL;
140} 142}
141 143
@@ -148,6 +150,7 @@ static int cm3323_get_it_bits(struct cm3323_data *data)
148 150
149 if (bits >= ARRAY_SIZE(cm3323_int_time)) 151 if (bits >= ARRAY_SIZE(cm3323_int_time))
150 return -EINVAL; 152 return -EINVAL;
153
151 return bits; 154 return bits;
152} 155}
153 156
@@ -155,7 +158,7 @@ static int cm3323_read_raw(struct iio_dev *indio_dev,
155 struct iio_chan_spec const *chan, int *val, 158 struct iio_chan_spec const *chan, int *val,
156 int *val2, long mask) 159 int *val2, long mask)
157{ 160{
158 int i, ret; 161 int ret;
159 struct cm3323_data *data = iio_priv(indio_dev); 162 struct cm3323_data *data = iio_priv(indio_dev);
160 163
161 switch (mask) { 164 switch (mask) {
@@ -172,14 +175,14 @@ static int cm3323_read_raw(struct iio_dev *indio_dev,
172 return IIO_VAL_INT; 175 return IIO_VAL_INT;
173 case IIO_CHAN_INFO_INT_TIME: 176 case IIO_CHAN_INFO_INT_TIME:
174 mutex_lock(&data->mutex); 177 mutex_lock(&data->mutex);
175 i = cm3323_get_it_bits(data); 178 ret = cm3323_get_it_bits(data);
176 if (i < 0) { 179 if (ret < 0) {
177 mutex_unlock(&data->mutex); 180 mutex_unlock(&data->mutex);
178 return -EINVAL; 181 return ret;
179 } 182 }
180 183
181 *val = cm3323_int_time[i].val; 184 *val = cm3323_int_time[ret].val;
182 *val2 = cm3323_int_time[i].val2; 185 *val2 = cm3323_int_time[ret].val2;
183 mutex_unlock(&data->mutex); 186 mutex_unlock(&data->mutex);
184 187
185 return IIO_VAL_INT_PLUS_MICRO; 188 return IIO_VAL_INT_PLUS_MICRO;
@@ -243,11 +246,13 @@ static int cm3323_probe(struct i2c_client *client,
243 dev_err(&client->dev, "cm3323 chip init failed\n"); 246 dev_err(&client->dev, "cm3323 chip init failed\n");
244 return ret; 247 return ret;
245 } 248 }
249
246 ret = iio_device_register(indio_dev); 250 ret = iio_device_register(indio_dev);
247 if (ret < 0) { 251 if (ret < 0) {
248 dev_err(&client->dev, "failed to register iio dev\n"); 252 dev_err(&client->dev, "failed to register iio dev\n");
249 goto err_init; 253 goto err_init;
250 } 254 }
255
251 return 0; 256 return 0;
252err_init: 257err_init:
253 cm3323_disable(indio_dev); 258 cm3323_disable(indio_dev);
diff --git a/drivers/iio/light/cm36651.c b/drivers/iio/light/cm36651.c
index 39fc67e82138..c8d7b5ea7e78 100644
--- a/drivers/iio/light/cm36651.c
+++ b/drivers/iio/light/cm36651.c
@@ -731,12 +731,12 @@ static const struct of_device_id cm36651_of_match[] = {
731 { .compatible = "capella,cm36651" }, 731 { .compatible = "capella,cm36651" },
732 { } 732 { }
733}; 733};
734MODULE_DEVICE_TABLE(of, cm36651_of_match);
734 735
735static struct i2c_driver cm36651_driver = { 736static struct i2c_driver cm36651_driver = {
736 .driver = { 737 .driver = {
737 .name = "cm36651", 738 .name = "cm36651",
738 .of_match_table = cm36651_of_match, 739 .of_match_table = cm36651_of_match,
739 .owner = THIS_MODULE,
740 }, 740 },
741 .probe = cm36651_probe, 741 .probe = cm36651_probe,
742 .remove = cm36651_remove, 742 .remove = cm36651_remove,
diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a00f.c
index 32b6449833fa..6d41086f7c64 100644
--- a/drivers/iio/light/gp2ap020a00f.c
+++ b/drivers/iio/light/gp2ap020a00f.c
@@ -1634,13 +1634,13 @@ static const struct of_device_id gp2ap020a00f_of_match[] = {
1634 { .compatible = "sharp,gp2ap020a00f" }, 1634 { .compatible = "sharp,gp2ap020a00f" },
1635 { } 1635 { }
1636}; 1636};
1637MODULE_DEVICE_TABLE(of, gp2ap020a00f_of_match);
1637#endif 1638#endif
1638 1639
1639static struct i2c_driver gp2ap020a00f_driver = { 1640static struct i2c_driver gp2ap020a00f_driver = {
1640 .driver = { 1641 .driver = {
1641 .name = GP2A_I2C_NAME, 1642 .name = GP2A_I2C_NAME,
1642 .of_match_table = of_match_ptr(gp2ap020a00f_of_match), 1643 .of_match_table = of_match_ptr(gp2ap020a00f_of_match),
1643 .owner = THIS_MODULE,
1644 }, 1644 },
1645 .probe = gp2ap020a00f_probe, 1645 .probe = gp2ap020a00f_probe,
1646 .remove = gp2ap020a00f_remove, 1646 .remove = gp2ap020a00f_remove,
diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c
index 0d248476f4c9..45ca056f019e 100644
--- a/drivers/iio/light/hid-sensor-prox.c
+++ b/drivers/iio/light/hid-sensor-prox.c
@@ -284,8 +284,7 @@ static int hid_prox_probe(struct platform_device *pdev)
284 goto error_free_dev_mem; 284 goto error_free_dev_mem;
285 } 285 }
286 286
287 indio_dev->num_channels = 287 indio_dev->num_channels = ARRAY_SIZE(prox_channels);
288 ARRAY_SIZE(prox_channels);
289 indio_dev->dev.parent = &pdev->dev; 288 indio_dev->dev.parent = &pdev->dev;
290 indio_dev->info = &prox_info; 289 indio_dev->info = &prox_info;
291 indio_dev->name = name; 290 indio_dev->name = name;
diff --git a/drivers/iio/light/isl29125.c b/drivers/iio/light/isl29125.c
index c82f4a6f8464..e2945a20e5f6 100644
--- a/drivers/iio/light/isl29125.c
+++ b/drivers/iio/light/isl29125.c
@@ -197,9 +197,21 @@ done:
197 return IRQ_HANDLED; 197 return IRQ_HANDLED;
198} 198}
199 199
200static IIO_CONST_ATTR(scale_available, "0.005722 0.152590");
201
202static struct attribute *isl29125_attributes[] = {
203 &iio_const_attr_scale_available.dev_attr.attr,
204 NULL
205};
206
207static const struct attribute_group isl29125_attribute_group = {
208 .attrs = isl29125_attributes,
209};
210
200static const struct iio_info isl29125_info = { 211static const struct iio_info isl29125_info = {
201 .read_raw = isl29125_read_raw, 212 .read_raw = isl29125_read_raw,
202 .write_raw = isl29125_write_raw, 213 .write_raw = isl29125_write_raw,
214 .attrs = &isl29125_attribute_group,
203 .driver_module = THIS_MODULE, 215 .driver_module = THIS_MODULE,
204}; 216};
205 217
@@ -334,7 +346,6 @@ static struct i2c_driver isl29125_driver = {
334 .driver = { 346 .driver = {
335 .name = ISL29125_DRV_NAME, 347 .name = ISL29125_DRV_NAME,
336 .pm = &isl29125_pm_ops, 348 .pm = &isl29125_pm_ops,
337 .owner = THIS_MODULE,
338 }, 349 },
339 .probe = isl29125_probe, 350 .probe = isl29125_probe,
340 .remove = isl29125_remove, 351 .remove = isl29125_remove,
diff --git a/drivers/iio/light/jsa1212.c b/drivers/iio/light/jsa1212.c
index 3a3af89beaf9..c4e8c6b6c3c3 100644
--- a/drivers/iio/light/jsa1212.c
+++ b/drivers/iio/light/jsa1212.c
@@ -457,7 +457,6 @@ static struct i2c_driver jsa1212_driver = {
457 .driver = { 457 .driver = {
458 .name = JSA1212_DRIVER_NAME, 458 .name = JSA1212_DRIVER_NAME,
459 .pm = JSA1212_PM_OPS, 459 .pm = JSA1212_PM_OPS,
460 .owner = THIS_MODULE,
461 .acpi_match_table = ACPI_PTR(jsa1212_acpi_match), 460 .acpi_match_table = ACPI_PTR(jsa1212_acpi_match),
462 }, 461 },
463 .probe = jsa1212_probe, 462 .probe = jsa1212_probe,
diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index b5a0e66b5f28..809a961b9a7f 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -1551,7 +1551,6 @@ static struct i2c_driver ltr501_driver = {
1551 .name = LTR501_DRV_NAME, 1551 .name = LTR501_DRV_NAME,
1552 .pm = &ltr501_pm_ops, 1552 .pm = &ltr501_pm_ops,
1553 .acpi_match_table = ACPI_PTR(ltr_acpi_match), 1553 .acpi_match_table = ACPI_PTR(ltr_acpi_match),
1554 .owner = THIS_MODULE,
1555 }, 1554 },
1556 .probe = ltr501_probe, 1555 .probe = ltr501_probe,
1557 .remove = ltr501_remove, 1556 .remove = ltr501_remove,
diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
new file mode 100644
index 000000000000..923aa6aef0ed
--- /dev/null
+++ b/drivers/iio/light/opt3001.c
@@ -0,0 +1,804 @@
1/**
2 * opt3001.c - Texas Instruments OPT3001 Light Sensor
3 *
4 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Author: Andreas Dannenberg <dannenberg@ti.com>
7 * Based on previous work from: Felipe Balbi <balbi@ti.com>
8 *
9 * This program is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 of the License
11 * as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 */
18
19#include <linux/bitops.h>
20#include <linux/delay.h>
21#include <linux/device.h>
22#include <linux/i2c.h>
23#include <linux/interrupt.h>
24#include <linux/irq.h>
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/mutex.h>
28#include <linux/slab.h>
29#include <linux/types.h>
30
31#include <linux/iio/events.h>
32#include <linux/iio/iio.h>
33#include <linux/iio/sysfs.h>
34
35#define OPT3001_RESULT 0x00
36#define OPT3001_CONFIGURATION 0x01
37#define OPT3001_LOW_LIMIT 0x02
38#define OPT3001_HIGH_LIMIT 0x03
39#define OPT3001_MANUFACTURER_ID 0x7e
40#define OPT3001_DEVICE_ID 0x7f
41
42#define OPT3001_CONFIGURATION_RN_MASK (0xf << 12)
43#define OPT3001_CONFIGURATION_RN_AUTO (0xc << 12)
44
45#define OPT3001_CONFIGURATION_CT BIT(11)
46
47#define OPT3001_CONFIGURATION_M_MASK (3 << 9)
48#define OPT3001_CONFIGURATION_M_SHUTDOWN (0 << 9)
49#define OPT3001_CONFIGURATION_M_SINGLE (1 << 9)
50#define OPT3001_CONFIGURATION_M_CONTINUOUS (2 << 9) /* also 3 << 9 */
51
52#define OPT3001_CONFIGURATION_OVF BIT(8)
53#define OPT3001_CONFIGURATION_CRF BIT(7)
54#define OPT3001_CONFIGURATION_FH BIT(6)
55#define OPT3001_CONFIGURATION_FL BIT(5)
56#define OPT3001_CONFIGURATION_L BIT(4)
57#define OPT3001_CONFIGURATION_POL BIT(3)
58#define OPT3001_CONFIGURATION_ME BIT(2)
59
60#define OPT3001_CONFIGURATION_FC_MASK (3 << 0)
61
62/* The end-of-conversion enable is located in the low-limit register */
63#define OPT3001_LOW_LIMIT_EOC_ENABLE 0xc000
64
65#define OPT3001_REG_EXPONENT(n) ((n) >> 12)
66#define OPT3001_REG_MANTISSA(n) ((n) & 0xfff)
67
68/*
69 * Time to wait for conversion result to be ready. The device datasheet
70 * worst-case max value is 880ms. Add some slack to be on the safe side.
71 */
72#define OPT3001_RESULT_READY_TIMEOUT msecs_to_jiffies(1000)
73
74struct opt3001 {
75 struct i2c_client *client;
76 struct device *dev;
77
78 struct mutex lock;
79 u16 ok_to_ignore_lock:1;
80 u16 result_ready:1;
81 wait_queue_head_t result_ready_queue;
82 u16 result;
83
84 u32 int_time;
85 u32 mode;
86
87 u16 high_thresh_mantissa;
88 u16 low_thresh_mantissa;
89
90 u8 high_thresh_exp;
91 u8 low_thresh_exp;
92};
93
94struct opt3001_scale {
95 int val;
96 int val2;
97};
98
99static const struct opt3001_scale opt3001_scales[] = {
100 {
101 .val = 40,
102 .val2 = 950000,
103 },
104 {
105 .val = 81,
106 .val2 = 900000,
107 },
108 {
109 .val = 163,
110 .val2 = 800000,
111 },
112 {
113 .val = 327,
114 .val2 = 600000,
115 },
116 {
117 .val = 655,
118 .val2 = 200000,
119 },
120 {
121 .val = 1310,
122 .val2 = 400000,
123 },
124 {
125 .val = 2620,
126 .val2 = 800000,
127 },
128 {
129 .val = 5241,
130 .val2 = 600000,
131 },
132 {
133 .val = 10483,
134 .val2 = 200000,
135 },
136 {
137 .val = 20966,
138 .val2 = 400000,
139 },
140 {
141 .val = 83865,
142 .val2 = 600000,
143 },
144};
145
146static int opt3001_find_scale(const struct opt3001 *opt, int val,
147 int val2, u8 *exponent)
148{
149 int i;
150
151 for (i = 0; i < ARRAY_SIZE(opt3001_scales); i++) {
152 const struct opt3001_scale *scale = &opt3001_scales[i];
153
154 /*
155 * Combine the integer and micro parts for comparison
156 * purposes. Use milli lux precision to avoid 32-bit integer
157 * overflows.
158 */
159 if ((val * 1000 + val2 / 1000) <=
160 (scale->val * 1000 + scale->val2 / 1000)) {
161 *exponent = i;
162 return 0;
163 }
164 }
165
166 return -EINVAL;
167}
168
169static void opt3001_to_iio_ret(struct opt3001 *opt, u8 exponent,
170 u16 mantissa, int *val, int *val2)
171{
172 int lux;
173
174 lux = 10 * (mantissa << exponent);
175 *val = lux / 1000;
176 *val2 = (lux - (*val * 1000)) * 1000;
177}
178
179static void opt3001_set_mode(struct opt3001 *opt, u16 *reg, u16 mode)
180{
181 *reg &= ~OPT3001_CONFIGURATION_M_MASK;
182 *reg |= mode;
183 opt->mode = mode;
184}
185
186static IIO_CONST_ATTR_INT_TIME_AVAIL("0.1 0.8");
187
188static struct attribute *opt3001_attributes[] = {
189 &iio_const_attr_integration_time_available.dev_attr.attr,
190 NULL
191};
192
193static const struct attribute_group opt3001_attribute_group = {
194 .attrs = opt3001_attributes,
195};
196
197static const struct iio_event_spec opt3001_event_spec[] = {
198 {
199 .type = IIO_EV_TYPE_THRESH,
200 .dir = IIO_EV_DIR_RISING,
201 .mask_separate = BIT(IIO_EV_INFO_VALUE) |
202 BIT(IIO_EV_INFO_ENABLE),
203 },
204 {
205 .type = IIO_EV_TYPE_THRESH,
206 .dir = IIO_EV_DIR_FALLING,
207 .mask_separate = BIT(IIO_EV_INFO_VALUE) |
208 BIT(IIO_EV_INFO_ENABLE),
209 },
210};
211
212static const struct iio_chan_spec opt3001_channels[] = {
213 {
214 .type = IIO_LIGHT,
215 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
216 BIT(IIO_CHAN_INFO_INT_TIME),
217 .event_spec = opt3001_event_spec,
218 .num_event_specs = ARRAY_SIZE(opt3001_event_spec),
219 },
220 IIO_CHAN_SOFT_TIMESTAMP(1),
221};
222
223static int opt3001_get_lux(struct opt3001 *opt, int *val, int *val2)
224{
225 int ret;
226 u16 mantissa;
227 u16 reg;
228 u8 exponent;
229 u16 value;
230
231 /*
232 * Enable the end-of-conversion interrupt mechanism. Note that doing
233 * so will overwrite the low-level limit value however we will restore
234 * this value later on.
235 */
236 ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_LOW_LIMIT,
237 OPT3001_LOW_LIMIT_EOC_ENABLE);
238 if (ret < 0) {
239 dev_err(opt->dev, "failed to write register %02x\n",
240 OPT3001_LOW_LIMIT);
241 return ret;
242 }
243
244 /* Reset data-ready indicator flag (will be set in the IRQ routine) */
245 opt->result_ready = false;
246
247 /* Allow IRQ to access the device despite lock being set */
248 opt->ok_to_ignore_lock = true;
249
250 /* Configure for single-conversion mode and start a new conversion */
251 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
252 if (ret < 0) {
253 dev_err(opt->dev, "failed to read register %02x\n",
254 OPT3001_CONFIGURATION);
255 goto err;
256 }
257
258 reg = ret;
259 opt3001_set_mode(opt, &reg, OPT3001_CONFIGURATION_M_SINGLE);
260
261 ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION,
262 reg);
263 if (ret < 0) {
264 dev_err(opt->dev, "failed to write register %02x\n",
265 OPT3001_CONFIGURATION);
266 goto err;
267 }
268
269 /* Wait for the IRQ to indicate the conversion is complete */
270 ret = wait_event_timeout(opt->result_ready_queue, opt->result_ready,
271 OPT3001_RESULT_READY_TIMEOUT);
272
273err:
274 /* Disallow IRQ to access the device while lock is active */
275 opt->ok_to_ignore_lock = false;
276
277 if (ret == 0)
278 return -ETIMEDOUT;
279 else if (ret < 0)
280 return ret;
281
282 /*
283 * Disable the end-of-conversion interrupt mechanism by restoring the
284 * low-level limit value (clearing OPT3001_LOW_LIMIT_EOC_ENABLE). Note
285 * that selectively clearing those enable bits would affect the actual
286 * limit value due to bit-overlap and therefore can't be done.
287 */
288 value = (opt->low_thresh_exp << 12) | opt->low_thresh_mantissa;
289 ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_LOW_LIMIT,
290 value);
291 if (ret < 0) {
292 dev_err(opt->dev, "failed to write register %02x\n",
293 OPT3001_LOW_LIMIT);
294 return ret;
295 }
296
297 exponent = OPT3001_REG_EXPONENT(opt->result);
298 mantissa = OPT3001_REG_MANTISSA(opt->result);
299
300 opt3001_to_iio_ret(opt, exponent, mantissa, val, val2);
301
302 return IIO_VAL_INT_PLUS_MICRO;
303}
304
305static int opt3001_get_int_time(struct opt3001 *opt, int *val, int *val2)
306{
307 *val = 0;
308 *val2 = opt->int_time;
309
310 return IIO_VAL_INT_PLUS_MICRO;
311}
312
313static int opt3001_set_int_time(struct opt3001 *opt, int time)
314{
315 int ret;
316 u16 reg;
317
318 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
319 if (ret < 0) {
320 dev_err(opt->dev, "failed to read register %02x\n",
321 OPT3001_CONFIGURATION);
322 return ret;
323 }
324
325 reg = ret;
326
327 switch (time) {
328 case 100000:
329 reg &= ~OPT3001_CONFIGURATION_CT;
330 opt->int_time = 100000;
331 break;
332 case 800000:
333 reg |= OPT3001_CONFIGURATION_CT;
334 opt->int_time = 800000;
335 break;
336 default:
337 return -EINVAL;
338 }
339
340 return i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION,
341 reg);
342}
343
344static int opt3001_read_raw(struct iio_dev *iio,
345 struct iio_chan_spec const *chan, int *val, int *val2,
346 long mask)
347{
348 struct opt3001 *opt = iio_priv(iio);
349 int ret;
350
351 if (opt->mode == OPT3001_CONFIGURATION_M_CONTINUOUS)
352 return -EBUSY;
353
354 if (chan->type != IIO_LIGHT)
355 return -EINVAL;
356
357 mutex_lock(&opt->lock);
358
359 switch (mask) {
360 case IIO_CHAN_INFO_PROCESSED:
361 ret = opt3001_get_lux(opt, val, val2);
362 break;
363 case IIO_CHAN_INFO_INT_TIME:
364 ret = opt3001_get_int_time(opt, val, val2);
365 break;
366 default:
367 ret = -EINVAL;
368 }
369
370 mutex_unlock(&opt->lock);
371
372 return ret;
373}
374
375static int opt3001_write_raw(struct iio_dev *iio,
376 struct iio_chan_spec const *chan, int val, int val2,
377 long mask)
378{
379 struct opt3001 *opt = iio_priv(iio);
380 int ret;
381
382 if (opt->mode == OPT3001_CONFIGURATION_M_CONTINUOUS)
383 return -EBUSY;
384
385 if (chan->type != IIO_LIGHT)
386 return -EINVAL;
387
388 if (mask != IIO_CHAN_INFO_INT_TIME)
389 return -EINVAL;
390
391 if (val != 0)
392 return -EINVAL;
393
394 mutex_lock(&opt->lock);
395 ret = opt3001_set_int_time(opt, val2);
396 mutex_unlock(&opt->lock);
397
398 return ret;
399}
400
401static int opt3001_read_event_value(struct iio_dev *iio,
402 const struct iio_chan_spec *chan, enum iio_event_type type,
403 enum iio_event_direction dir, enum iio_event_info info,
404 int *val, int *val2)
405{
406 struct opt3001 *opt = iio_priv(iio);
407 int ret = IIO_VAL_INT_PLUS_MICRO;
408
409 mutex_lock(&opt->lock);
410
411 switch (dir) {
412 case IIO_EV_DIR_RISING:
413 opt3001_to_iio_ret(opt, opt->high_thresh_exp,
414 opt->high_thresh_mantissa, val, val2);
415 break;
416 case IIO_EV_DIR_FALLING:
417 opt3001_to_iio_ret(opt, opt->low_thresh_exp,
418 opt->low_thresh_mantissa, val, val2);
419 break;
420 default:
421 ret = -EINVAL;
422 }
423
424 mutex_unlock(&opt->lock);
425
426 return ret;
427}
428
429static int opt3001_write_event_value(struct iio_dev *iio,
430 const struct iio_chan_spec *chan, enum iio_event_type type,
431 enum iio_event_direction dir, enum iio_event_info info,
432 int val, int val2)
433{
434 struct opt3001 *opt = iio_priv(iio);
435 int ret;
436
437 u16 mantissa;
438 u16 value;
439 u16 reg;
440
441 u8 exponent;
442
443 if (val < 0)
444 return -EINVAL;
445
446 mutex_lock(&opt->lock);
447
448 ret = opt3001_find_scale(opt, val, val2, &exponent);
449 if (ret < 0) {
450 dev_err(opt->dev, "can't find scale for %d.%06u\n", val, val2);
451 goto err;
452 }
453
454 mantissa = (((val * 1000) + (val2 / 1000)) / 10) >> exponent;
455 value = (exponent << 12) | mantissa;
456
457 switch (dir) {
458 case IIO_EV_DIR_RISING:
459 reg = OPT3001_HIGH_LIMIT;
460 opt->high_thresh_mantissa = mantissa;
461 opt->high_thresh_exp = exponent;
462 break;
463 case IIO_EV_DIR_FALLING:
464 reg = OPT3001_LOW_LIMIT;
465 opt->low_thresh_mantissa = mantissa;
466 opt->low_thresh_exp = exponent;
467 break;
468 default:
469 ret = -EINVAL;
470 goto err;
471 }
472
473 ret = i2c_smbus_write_word_swapped(opt->client, reg, value);
474 if (ret < 0) {
475 dev_err(opt->dev, "failed to write register %02x\n", reg);
476 goto err;
477 }
478
479err:
480 mutex_unlock(&opt->lock);
481
482 return ret;
483}
484
485static int opt3001_read_event_config(struct iio_dev *iio,
486 const struct iio_chan_spec *chan, enum iio_event_type type,
487 enum iio_event_direction dir)
488{
489 struct opt3001 *opt = iio_priv(iio);
490
491 return opt->mode == OPT3001_CONFIGURATION_M_CONTINUOUS;
492}
493
494static int opt3001_write_event_config(struct iio_dev *iio,
495 const struct iio_chan_spec *chan, enum iio_event_type type,
496 enum iio_event_direction dir, int state)
497{
498 struct opt3001 *opt = iio_priv(iio);
499 int ret;
500 u16 mode;
501 u16 reg;
502
503 if (state && opt->mode == OPT3001_CONFIGURATION_M_CONTINUOUS)
504 return 0;
505
506 if (!state && opt->mode == OPT3001_CONFIGURATION_M_SHUTDOWN)
507 return 0;
508
509 mutex_lock(&opt->lock);
510
511 mode = state ? OPT3001_CONFIGURATION_M_CONTINUOUS
512 : OPT3001_CONFIGURATION_M_SHUTDOWN;
513
514 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
515 if (ret < 0) {
516 dev_err(opt->dev, "failed to read register %02x\n",
517 OPT3001_CONFIGURATION);
518 goto err;
519 }
520
521 reg = ret;
522 opt3001_set_mode(opt, &reg, mode);
523
524 ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION,
525 reg);
526 if (ret < 0) {
527 dev_err(opt->dev, "failed to write register %02x\n",
528 OPT3001_CONFIGURATION);
529 goto err;
530 }
531
532err:
533 mutex_unlock(&opt->lock);
534
535 return ret;
536}
537
538static const struct iio_info opt3001_info = {
539 .driver_module = THIS_MODULE,
540 .attrs = &opt3001_attribute_group,
541 .read_raw = opt3001_read_raw,
542 .write_raw = opt3001_write_raw,
543 .read_event_value = opt3001_read_event_value,
544 .write_event_value = opt3001_write_event_value,
545 .read_event_config = opt3001_read_event_config,
546 .write_event_config = opt3001_write_event_config,
547};
548
549static int opt3001_read_id(struct opt3001 *opt)
550{
551 char manufacturer[2];
552 u16 device_id;
553 int ret;
554
555 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_MANUFACTURER_ID);
556 if (ret < 0) {
557 dev_err(opt->dev, "failed to read register %02x\n",
558 OPT3001_MANUFACTURER_ID);
559 return ret;
560 }
561
562 manufacturer[0] = ret >> 8;
563 manufacturer[1] = ret & 0xff;
564
565 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_DEVICE_ID);
566 if (ret < 0) {
567 dev_err(opt->dev, "failed to read register %02x\n",
568 OPT3001_DEVICE_ID);
569 return ret;
570 }
571
572 device_id = ret;
573
574 dev_info(opt->dev, "Found %c%c OPT%04x\n", manufacturer[0],
575 manufacturer[1], device_id);
576
577 return 0;
578}
579
580static int opt3001_configure(struct opt3001 *opt)
581{
582 int ret;
583 u16 reg;
584
585 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
586 if (ret < 0) {
587 dev_err(opt->dev, "failed to read register %02x\n",
588 OPT3001_CONFIGURATION);
589 return ret;
590 }
591
592 reg = ret;
593
594 /* Enable automatic full-scale setting mode */
595 reg &= ~OPT3001_CONFIGURATION_RN_MASK;
596 reg |= OPT3001_CONFIGURATION_RN_AUTO;
597
598 /* Reflect status of the device's integration time setting */
599 if (reg & OPT3001_CONFIGURATION_CT)
600 opt->int_time = 800000;
601 else
602 opt->int_time = 100000;
603
604 /* Ensure device is in shutdown initially */
605 opt3001_set_mode(opt, &reg, OPT3001_CONFIGURATION_M_SHUTDOWN);
606
607 /* Configure for latched window-style comparison operation */
608 reg |= OPT3001_CONFIGURATION_L;
609 reg &= ~OPT3001_CONFIGURATION_POL;
610 reg &= ~OPT3001_CONFIGURATION_ME;
611 reg &= ~OPT3001_CONFIGURATION_FC_MASK;
612
613 ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION,
614 reg);
615 if (ret < 0) {
616 dev_err(opt->dev, "failed to write register %02x\n",
617 OPT3001_CONFIGURATION);
618 return ret;
619 }
620
621 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_LOW_LIMIT);
622 if (ret < 0) {
623 dev_err(opt->dev, "failed to read register %02x\n",
624 OPT3001_LOW_LIMIT);
625 return ret;
626 }
627
628 opt->low_thresh_mantissa = OPT3001_REG_MANTISSA(ret);
629 opt->low_thresh_exp = OPT3001_REG_EXPONENT(ret);
630
631 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_HIGH_LIMIT);
632 if (ret < 0) {
633 dev_err(opt->dev, "failed to read register %02x\n",
634 OPT3001_HIGH_LIMIT);
635 return ret;
636 }
637
638 opt->high_thresh_mantissa = OPT3001_REG_MANTISSA(ret);
639 opt->high_thresh_exp = OPT3001_REG_EXPONENT(ret);
640
641 return 0;
642}
643
644static irqreturn_t opt3001_irq(int irq, void *_iio)
645{
646 struct iio_dev *iio = _iio;
647 struct opt3001 *opt = iio_priv(iio);
648 int ret;
649
650 if (!opt->ok_to_ignore_lock)
651 mutex_lock(&opt->lock);
652
653 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
654 if (ret < 0) {
655 dev_err(opt->dev, "failed to read register %02x\n",
656 OPT3001_CONFIGURATION);
657 goto out;
658 }
659
660 if ((ret & OPT3001_CONFIGURATION_M_MASK) ==
661 OPT3001_CONFIGURATION_M_CONTINUOUS) {
662 if (ret & OPT3001_CONFIGURATION_FH)
663 iio_push_event(iio,
664 IIO_UNMOD_EVENT_CODE(IIO_LIGHT, 0,
665 IIO_EV_TYPE_THRESH,
666 IIO_EV_DIR_RISING),
667 iio_get_time_ns());
668 if (ret & OPT3001_CONFIGURATION_FL)
669 iio_push_event(iio,
670 IIO_UNMOD_EVENT_CODE(IIO_LIGHT, 0,
671 IIO_EV_TYPE_THRESH,
672 IIO_EV_DIR_FALLING),
673 iio_get_time_ns());
674 } else if (ret & OPT3001_CONFIGURATION_CRF) {
675 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_RESULT);
676 if (ret < 0) {
677 dev_err(opt->dev, "failed to read register %02x\n",
678 OPT3001_RESULT);
679 goto out;
680 }
681 opt->result = ret;
682 opt->result_ready = true;
683 wake_up(&opt->result_ready_queue);
684 }
685
686out:
687 if (!opt->ok_to_ignore_lock)
688 mutex_unlock(&opt->lock);
689
690 return IRQ_HANDLED;
691}
692
693static int opt3001_probe(struct i2c_client *client,
694 const struct i2c_device_id *id)
695{
696 struct device *dev = &client->dev;
697
698 struct iio_dev *iio;
699 struct opt3001 *opt;
700 int irq = client->irq;
701 int ret;
702
703 iio = devm_iio_device_alloc(dev, sizeof(*opt));
704 if (!iio)
705 return -ENOMEM;
706
707 opt = iio_priv(iio);
708 opt->client = client;
709 opt->dev = dev;
710
711 mutex_init(&opt->lock);
712 init_waitqueue_head(&opt->result_ready_queue);
713 i2c_set_clientdata(client, iio);
714
715 ret = opt3001_read_id(opt);
716 if (ret)
717 return ret;
718
719 ret = opt3001_configure(opt);
720 if (ret)
721 return ret;
722
723 iio->name = client->name;
724 iio->channels = opt3001_channels;
725 iio->num_channels = ARRAY_SIZE(opt3001_channels);
726 iio->dev.parent = dev;
727 iio->modes = INDIO_DIRECT_MODE;
728 iio->info = &opt3001_info;
729
730 ret = devm_iio_device_register(dev, iio);
731 if (ret) {
732 dev_err(dev, "failed to register IIO device\n");
733 return ret;
734 }
735
736 ret = request_threaded_irq(irq, NULL, opt3001_irq,
737 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
738 "opt3001", iio);
739 if (ret) {
740 dev_err(dev, "failed to request IRQ #%d\n", irq);
741 return ret;
742 }
743
744 return 0;
745}
746
747static int opt3001_remove(struct i2c_client *client)
748{
749 struct iio_dev *iio = i2c_get_clientdata(client);
750 struct opt3001 *opt = iio_priv(iio);
751 int ret;
752 u16 reg;
753
754 free_irq(client->irq, iio);
755
756 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
757 if (ret < 0) {
758 dev_err(opt->dev, "failed to read register %02x\n",
759 OPT3001_CONFIGURATION);
760 return ret;
761 }
762
763 reg = ret;
764 opt3001_set_mode(opt, &reg, OPT3001_CONFIGURATION_M_SHUTDOWN);
765
766 ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION,
767 reg);
768 if (ret < 0) {
769 dev_err(opt->dev, "failed to write register %02x\n",
770 OPT3001_CONFIGURATION);
771 return ret;
772 }
773
774 return 0;
775}
776
777static const struct i2c_device_id opt3001_id[] = {
778 { "opt3001", 0 },
779 { } /* Terminating Entry */
780};
781MODULE_DEVICE_TABLE(i2c, opt3001_id);
782
783static const struct of_device_id opt3001_of_match[] = {
784 { .compatible = "ti,opt3001" },
785 { }
786};
787
788static struct i2c_driver opt3001_driver = {
789 .probe = opt3001_probe,
790 .remove = opt3001_remove,
791 .id_table = opt3001_id,
792
793 .driver = {
794 .name = "opt3001",
795 .of_match_table = of_match_ptr(opt3001_of_match),
796 .owner = THIS_MODULE,
797 },
798};
799
800module_i2c_driver(opt3001_driver);
801
802MODULE_LICENSE("GPL v2");
803MODULE_AUTHOR("Andreas Dannenberg <dannenberg@ti.com>");
804MODULE_DESCRIPTION("Texas Instruments OPT3001 Light Sensor Driver");
diff --git a/drivers/iio/light/pa12203001.c b/drivers/iio/light/pa12203001.c
new file mode 100644
index 000000000000..45f7bde02bbf
--- /dev/null
+++ b/drivers/iio/light/pa12203001.c
@@ -0,0 +1,483 @@
1/*
2 * Copyright (c) 2015 Intel Corporation
3 *
4 * Driver for TXC PA12203001 Proximity and Ambient Light Sensor.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 * To do: Interrupt support.
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/acpi.h>
15#include <linux/delay.h>
16#include <linux/i2c.h>
17#include <linux/iio/iio.h>
18#include <linux/iio/sysfs.h>
19#include <linux/mutex.h>
20#include <linux/pm.h>
21#include <linux/pm_runtime.h>
22#include <linux/regmap.h>
23
24#define PA12203001_DRIVER_NAME "pa12203001"
25
26#define PA12203001_REG_CFG0 0x00
27#define PA12203001_REG_CFG1 0x01
28#define PA12203001_REG_CFG2 0x02
29#define PA12203001_REG_CFG3 0x03
30
31#define PA12203001_REG_ADL 0x0b
32#define PA12203001_REG_PDH 0x0e
33
34#define PA12203001_REG_POFS 0x10
35#define PA12203001_REG_PSET 0x11
36
37#define PA12203001_ALS_EN_MASK BIT(0)
38#define PA12203001_PX_EN_MASK BIT(1)
39#define PA12203001_PX_NORMAL_MODE_MASK GENMASK(7, 6)
40#define PA12203001_AFSR_MASK GENMASK(5, 4)
41#define PA12203001_AFSR_SHIFT 4
42
43#define PA12203001_PSCAN 0x03
44
45/* als range 31000, ps, als disabled */
46#define PA12203001_REG_CFG0_DEFAULT 0x30
47
48/* led current: 100 mA */
49#define PA12203001_REG_CFG1_DEFAULT 0x20
50
51/* ps mode: normal, interrupts not active */
52#define PA12203001_REG_CFG2_DEFAULT 0xcc
53
54#define PA12203001_REG_CFG3_DEFAULT 0x00
55
56#define PA12203001_SLEEP_DELAY_MS 3000
57
58#define PA12203001_CHIP_ENABLE 0xff
59#define PA12203001_CHIP_DISABLE 0x00
60
61/* available scales: corresponding to [500, 4000, 7000, 31000] lux */
62static const int pa12203001_scales[] = { 7629, 61036, 106813, 473029};
63
64struct pa12203001_data {
65 struct i2c_client *client;
66
67 /* protect device states */
68 struct mutex lock;
69
70 bool als_enabled;
71 bool px_enabled;
72 bool als_needs_enable;
73 bool px_needs_enable;
74
75 struct regmap *map;
76};
77
78static const struct {
79 u8 reg;
80 u8 val;
81} regvals[] = {
82 {PA12203001_REG_CFG0, PA12203001_REG_CFG0_DEFAULT},
83 {PA12203001_REG_CFG1, PA12203001_REG_CFG1_DEFAULT},
84 {PA12203001_REG_CFG2, PA12203001_REG_CFG2_DEFAULT},
85 {PA12203001_REG_CFG3, PA12203001_REG_CFG3_DEFAULT},
86 {PA12203001_REG_PSET, PA12203001_PSCAN},
87};
88
89static IIO_CONST_ATTR(in_illuminance_scale_available,
90 "0.007629 0.061036 0.106813 0.473029");
91
92static struct attribute *pa12203001_attrs[] = {
93 &iio_const_attr_in_illuminance_scale_available.dev_attr.attr,
94 NULL
95};
96
97static const struct attribute_group pa12203001_attr_group = {
98 .attrs = pa12203001_attrs,
99};
100
101static const struct iio_chan_spec pa12203001_channels[] = {
102 {
103 .type = IIO_LIGHT,
104 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
105 BIT(IIO_CHAN_INFO_SCALE),
106 },
107 {
108 .type = IIO_PROXIMITY,
109 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
110 }
111};
112
113static const struct regmap_range pa12203001_volatile_regs_ranges[] = {
114 regmap_reg_range(PA12203001_REG_ADL, PA12203001_REG_ADL + 1),
115 regmap_reg_range(PA12203001_REG_PDH, PA12203001_REG_PDH),
116};
117
118static const struct regmap_access_table pa12203001_volatile_regs = {
119 .yes_ranges = pa12203001_volatile_regs_ranges,
120 .n_yes_ranges = ARRAY_SIZE(pa12203001_volatile_regs_ranges),
121};
122
123static const struct regmap_config pa12203001_regmap_config = {
124 .reg_bits = 8,
125 .val_bits = 8,
126 .max_register = PA12203001_REG_PSET,
127 .cache_type = REGCACHE_RBTREE,
128 .volatile_table = &pa12203001_volatile_regs,
129};
130
131static inline int pa12203001_als_enable(struct pa12203001_data *data, u8 enable)
132{
133 int ret;
134
135 ret = regmap_update_bits(data->map, PA12203001_REG_CFG0,
136 PA12203001_ALS_EN_MASK, enable);
137 if (ret < 0)
138 return ret;
139
140 data->als_enabled = !!enable;
141
142 return 0;
143}
144
145static inline int pa12203001_px_enable(struct pa12203001_data *data, u8 enable)
146{
147 int ret;
148
149 ret = regmap_update_bits(data->map, PA12203001_REG_CFG0,
150 PA12203001_PX_EN_MASK, enable);
151 if (ret < 0)
152 return ret;
153
154 data->px_enabled = !!enable;
155
156 return 0;
157}
158
159static int pa12203001_set_power_state(struct pa12203001_data *data, bool on,
160 u8 mask)
161{
162#ifdef CONFIG_PM
163 int ret;
164
165 if (on && (mask & PA12203001_ALS_EN_MASK)) {
166 mutex_lock(&data->lock);
167 if (data->px_enabled) {
168 ret = pa12203001_als_enable(data,
169 PA12203001_ALS_EN_MASK);
170 if (ret < 0)
171 goto err;
172 } else {
173 data->als_needs_enable = true;
174 }
175 mutex_unlock(&data->lock);
176 }
177
178 if (on && (mask & PA12203001_PX_EN_MASK)) {
179 mutex_lock(&data->lock);
180 if (data->als_enabled) {
181 ret = pa12203001_px_enable(data, PA12203001_PX_EN_MASK);
182 if (ret < 0)
183 goto err;
184 } else {
185 data->px_needs_enable = true;
186 }
187 mutex_unlock(&data->lock);
188 }
189
190 if (on) {
191 ret = pm_runtime_get_sync(&data->client->dev);
192 if (ret < 0)
193 pm_runtime_put_noidle(&data->client->dev);
194
195 } else {
196 pm_runtime_mark_last_busy(&data->client->dev);
197 ret = pm_runtime_put_autosuspend(&data->client->dev);
198 }
199
200 return ret;
201
202err:
203 mutex_unlock(&data->lock);
204 return ret;
205
206#endif
207 return 0;
208}
209
210static int pa12203001_read_raw(struct iio_dev *indio_dev,
211 struct iio_chan_spec const *chan, int *val,
212 int *val2, long mask)
213{
214 struct pa12203001_data *data = iio_priv(indio_dev);
215 int ret;
216 u8 dev_mask;
217 unsigned int reg_byte;
218 __le16 reg_word;
219
220 switch (mask) {
221 case IIO_CHAN_INFO_RAW:
222 switch (chan->type) {
223 case IIO_LIGHT:
224 dev_mask = PA12203001_ALS_EN_MASK;
225 ret = pa12203001_set_power_state(data, true, dev_mask);
226 if (ret < 0)
227 return ret;
228 /*
229 * ALS ADC value is stored in registers
230 * PA12203001_REG_ADL and in PA12203001_REG_ADL + 1.
231 */
232 ret = regmap_bulk_read(data->map, PA12203001_REG_ADL,
233 &reg_word, 2);
234 if (ret < 0)
235 goto reg_err;
236
237 *val = le16_to_cpu(reg_word);
238 ret = pa12203001_set_power_state(data, false, dev_mask);
239 if (ret < 0)
240 return ret;
241 break;
242 case IIO_PROXIMITY:
243 dev_mask = PA12203001_PX_EN_MASK;
244 ret = pa12203001_set_power_state(data, true, dev_mask);
245 if (ret < 0)
246 return ret;
247 ret = regmap_read(data->map, PA12203001_REG_PDH,
248 &reg_byte);
249 if (ret < 0)
250 goto reg_err;
251
252 *val = reg_byte;
253 ret = pa12203001_set_power_state(data, false, dev_mask);
254 if (ret < 0)
255 return ret;
256 break;
257 default:
258 return -EINVAL;
259 }
260 return IIO_VAL_INT;
261 case IIO_CHAN_INFO_SCALE:
262 ret = regmap_read(data->map, PA12203001_REG_CFG0, &reg_byte);
263 if (ret < 0)
264 return ret;
265 *val = 0;
266 reg_byte = (reg_byte & PA12203001_AFSR_MASK);
267 *val2 = pa12203001_scales[reg_byte >> 4];
268 return IIO_VAL_INT_PLUS_MICRO;
269 default:
270 return -EINVAL;
271 }
272
273reg_err:
274 pa12203001_set_power_state(data, false, dev_mask);
275 return ret;
276}
277
278static int pa12203001_write_raw(struct iio_dev *indio_dev,
279 struct iio_chan_spec const *chan, int val,
280 int val2, long mask)
281{
282 struct pa12203001_data *data = iio_priv(indio_dev);
283 int i, ret, new_val;
284 unsigned int reg_byte;
285
286 switch (mask) {
287 case IIO_CHAN_INFO_SCALE:
288 ret = regmap_read(data->map, PA12203001_REG_CFG0, &reg_byte);
289 if (val != 0 || ret < 0)
290 return -EINVAL;
291 for (i = 0; i < ARRAY_SIZE(pa12203001_scales); i++) {
292 if (val2 == pa12203001_scales[i]) {
293 new_val = i << PA12203001_AFSR_SHIFT;
294 return regmap_update_bits(data->map,
295 PA12203001_REG_CFG0,
296 PA12203001_AFSR_MASK,
297 new_val);
298 }
299 }
300 break;
301 default:
302 break;
303 }
304
305 return -EINVAL;
306}
307
308static const struct iio_info pa12203001_info = {
309 .driver_module = THIS_MODULE,
310 .read_raw = pa12203001_read_raw,
311 .write_raw = pa12203001_write_raw,
312 .attrs = &pa12203001_attr_group,
313};
314
315static int pa12203001_init(struct iio_dev *indio_dev)
316{
317 struct pa12203001_data *data = iio_priv(indio_dev);
318 int i, ret;
319
320 for (i = 0; i < ARRAY_SIZE(regvals); i++) {
321 ret = regmap_write(data->map, regvals[i].reg, regvals[i].val);
322 if (ret < 0)
323 return ret;
324 }
325
326 return 0;
327}
328
329static int pa12203001_power_chip(struct iio_dev *indio_dev, u8 state)
330{
331 struct pa12203001_data *data = iio_priv(indio_dev);
332 int ret;
333
334 mutex_lock(&data->lock);
335 ret = pa12203001_als_enable(data, state);
336 if (ret < 0)
337 goto out;
338
339 ret = pa12203001_px_enable(data, state);
340
341out:
342 mutex_unlock(&data->lock);
343 return ret;
344}
345
346static int pa12203001_probe(struct i2c_client *client,
347 const struct i2c_device_id *id)
348{
349 struct pa12203001_data *data;
350 struct iio_dev *indio_dev;
351 int ret;
352
353 indio_dev = devm_iio_device_alloc(&client->dev,
354 sizeof(struct pa12203001_data));
355 if (!indio_dev)
356 return -ENOMEM;
357
358 data = iio_priv(indio_dev);
359 i2c_set_clientdata(client, indio_dev);
360 data->client = client;
361
362 data->map = devm_regmap_init_i2c(client, &pa12203001_regmap_config);
363 if (IS_ERR(data->map))
364 return PTR_ERR(data->map);
365
366 mutex_init(&data->lock);
367
368 indio_dev->dev.parent = &client->dev;
369 indio_dev->info = &pa12203001_info;
370 indio_dev->name = PA12203001_DRIVER_NAME;
371 indio_dev->channels = pa12203001_channels;
372 indio_dev->num_channels = ARRAY_SIZE(pa12203001_channels);
373 indio_dev->modes = INDIO_DIRECT_MODE;
374
375 ret = pa12203001_init(indio_dev);
376 if (ret < 0)
377 return ret;
378
379 ret = pa12203001_power_chip(indio_dev, PA12203001_CHIP_ENABLE);
380 if (ret < 0)
381 return ret;
382
383 ret = pm_runtime_set_active(&client->dev);
384 if (ret < 0) {
385 pa12203001_power_chip(indio_dev, PA12203001_CHIP_DISABLE);
386 return ret;
387 }
388
389 pm_runtime_enable(&client->dev);
390 pm_runtime_set_autosuspend_delay(&client->dev,
391 PA12203001_SLEEP_DELAY_MS);
392 pm_runtime_use_autosuspend(&client->dev);
393
394 return iio_device_register(indio_dev);
395}
396
397static int pa12203001_remove(struct i2c_client *client)
398{
399 struct iio_dev *indio_dev = i2c_get_clientdata(client);
400
401 iio_device_unregister(indio_dev);
402
403 pm_runtime_disable(&client->dev);
404 pm_runtime_set_suspended(&client->dev);
405
406 return pa12203001_power_chip(indio_dev, PA12203001_CHIP_DISABLE);
407}
408
409#if defined(CONFIG_PM_SLEEP) || defined(CONFIG_PM)
410static int pa12203001_suspend(struct device *dev)
411{
412 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
413
414 return pa12203001_power_chip(indio_dev, PA12203001_CHIP_DISABLE);
415}
416#endif
417
418#ifdef CONFIG_PM_SLEEP
419static int pa12203001_resume(struct device *dev)
420{
421 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
422
423 return pa12203001_power_chip(indio_dev, PA12203001_CHIP_ENABLE);
424}
425#endif
426
427#ifdef CONFIG_PM
428static int pa12203001_runtime_resume(struct device *dev)
429{
430 struct pa12203001_data *data;
431
432 data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
433
434 mutex_lock(&data->lock);
435 if (data->als_needs_enable) {
436 pa12203001_als_enable(data, PA12203001_ALS_EN_MASK);
437 data->als_needs_enable = false;
438 }
439 if (data->px_needs_enable) {
440 pa12203001_px_enable(data, PA12203001_PX_EN_MASK);
441 data->px_needs_enable = false;
442 }
443 mutex_unlock(&data->lock);
444
445 return 0;
446}
447#endif
448
449static const struct dev_pm_ops pa12203001_pm_ops = {
450 SET_SYSTEM_SLEEP_PM_OPS(pa12203001_suspend, pa12203001_resume)
451 SET_RUNTIME_PM_OPS(pa12203001_suspend, pa12203001_runtime_resume, NULL)
452};
453
454static const struct acpi_device_id pa12203001_acpi_match[] = {
455 { "TXCPA122", 0},
456 {}
457};
458
459MODULE_DEVICE_TABLE(acpi, pa12203001_acpi_match);
460
461static const struct i2c_device_id pa12203001_id[] = {
462 {"txcpa122", 0},
463 {}
464};
465
466MODULE_DEVICE_TABLE(i2c, pa12203001_id);
467
468static struct i2c_driver pa12203001_driver = {
469 .driver = {
470 .name = PA12203001_DRIVER_NAME,
471 .pm = &pa12203001_pm_ops,
472 .acpi_match_table = ACPI_PTR(pa12203001_acpi_match),
473 },
474 .probe = pa12203001_probe,
475 .remove = pa12203001_remove,
476 .id_table = pa12203001_id,
477
478};
479module_i2c_driver(pa12203001_driver);
480
481MODULE_AUTHOR("Adriana Reus <adriana.reus@intel.com>");
482MODULE_DESCRIPTION("Driver for TXC PA12203001 Proximity and Light Sensor");
483MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/light/rpr0521.c b/drivers/iio/light/rpr0521.c
new file mode 100644
index 000000000000..4b75bb0998b3
--- /dev/null
+++ b/drivers/iio/light/rpr0521.c
@@ -0,0 +1,615 @@
1/*
2 * RPR-0521 ROHM Ambient Light and Proximity Sensor
3 *
4 * Copyright (c) 2015, Intel Corporation.
5 *
6 * This file is subject to the terms and conditions of version 2 of
7 * the GNU General Public License. See the file COPYING in the main
8 * directory of this archive for more details.
9 *
10 * IIO driver for RPR-0521RS (7-bit I2C slave address 0x38).
11 *
12 * TODO: illuminance channel, PM support, buffer
13 */
14
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/i2c.h>
18#include <linux/regmap.h>
19#include <linux/delay.h>
20#include <linux/acpi.h>
21
22#include <linux/iio/iio.h>
23#include <linux/iio/sysfs.h>
24#include <linux/pm_runtime.h>
25
26#define RPR0521_REG_SYSTEM_CTRL 0x40
27#define RPR0521_REG_MODE_CTRL 0x41
28#define RPR0521_REG_ALS_CTRL 0x42
29#define RPR0521_REG_PXS_CTRL 0x43
30#define RPR0521_REG_PXS_DATA 0x44 /* 16-bit, little endian */
31#define RPR0521_REG_ALS_DATA0 0x46 /* 16-bit, little endian */
32#define RPR0521_REG_ALS_DATA1 0x48 /* 16-bit, little endian */
33#define RPR0521_REG_ID 0x92
34
35#define RPR0521_MODE_ALS_MASK BIT(7)
36#define RPR0521_MODE_PXS_MASK BIT(6)
37#define RPR0521_MODE_MEAS_TIME_MASK GENMASK(3, 0)
38#define RPR0521_ALS_DATA0_GAIN_MASK GENMASK(5, 4)
39#define RPR0521_ALS_DATA0_GAIN_SHIFT 4
40#define RPR0521_ALS_DATA1_GAIN_MASK GENMASK(3, 2)
41#define RPR0521_ALS_DATA1_GAIN_SHIFT 2
42#define RPR0521_PXS_GAIN_MASK GENMASK(5, 4)
43#define RPR0521_PXS_GAIN_SHIFT 4
44
45#define RPR0521_MODE_ALS_ENABLE BIT(7)
46#define RPR0521_MODE_ALS_DISABLE 0x00
47#define RPR0521_MODE_PXS_ENABLE BIT(6)
48#define RPR0521_MODE_PXS_DISABLE 0x00
49
50#define RPR0521_MANUFACT_ID 0xE0
51#define RPR0521_DEFAULT_MEAS_TIME 0x06 /* ALS - 100ms, PXS - 100ms */
52
53#define RPR0521_DRV_NAME "RPR0521"
54#define RPR0521_REGMAP_NAME "rpr0521_regmap"
55
56#define RPR0521_SLEEP_DELAY_MS 2000
57
58#define RPR0521_ALS_SCALE_AVAIL "0.007812 0.015625 0.5 1"
59#define RPR0521_PXS_SCALE_AVAIL "0.125 0.5 1"
60
61struct rpr0521_gain {
62 int scale;
63 int uscale;
64};
65
66static const struct rpr0521_gain rpr0521_als_gain[4] = {
67 {1, 0}, /* x1 */
68 {0, 500000}, /* x2 */
69 {0, 15625}, /* x64 */
70 {0, 7812}, /* x128 */
71};
72
73static const struct rpr0521_gain rpr0521_pxs_gain[3] = {
74 {1, 0}, /* x1 */
75 {0, 500000}, /* x2 */
76 {0, 125000}, /* x4 */
77};
78
79enum rpr0521_channel {
80 RPR0521_CHAN_ALS_DATA0,
81 RPR0521_CHAN_ALS_DATA1,
82 RPR0521_CHAN_PXS,
83};
84
85struct rpr0521_reg_desc {
86 u8 address;
87 u8 device_mask;
88};
89
90static const struct rpr0521_reg_desc rpr0521_data_reg[] = {
91 [RPR0521_CHAN_ALS_DATA0] = {
92 .address = RPR0521_REG_ALS_DATA0,
93 .device_mask = RPR0521_MODE_ALS_MASK,
94 },
95 [RPR0521_CHAN_ALS_DATA1] = {
96 .address = RPR0521_REG_ALS_DATA1,
97 .device_mask = RPR0521_MODE_ALS_MASK,
98 },
99 [RPR0521_CHAN_PXS] = {
100 .address = RPR0521_REG_PXS_DATA,
101 .device_mask = RPR0521_MODE_PXS_MASK,
102 },
103};
104
105static const struct rpr0521_gain_info {
106 u8 reg;
107 u8 mask;
108 u8 shift;
109 const struct rpr0521_gain *gain;
110 int size;
111} rpr0521_gain[] = {
112 [RPR0521_CHAN_ALS_DATA0] = {
113 .reg = RPR0521_REG_ALS_CTRL,
114 .mask = RPR0521_ALS_DATA0_GAIN_MASK,
115 .shift = RPR0521_ALS_DATA0_GAIN_SHIFT,
116 .gain = rpr0521_als_gain,
117 .size = ARRAY_SIZE(rpr0521_als_gain),
118 },
119 [RPR0521_CHAN_ALS_DATA1] = {
120 .reg = RPR0521_REG_ALS_CTRL,
121 .mask = RPR0521_ALS_DATA1_GAIN_MASK,
122 .shift = RPR0521_ALS_DATA1_GAIN_SHIFT,
123 .gain = rpr0521_als_gain,
124 .size = ARRAY_SIZE(rpr0521_als_gain),
125 },
126 [RPR0521_CHAN_PXS] = {
127 .reg = RPR0521_REG_PXS_CTRL,
128 .mask = RPR0521_PXS_GAIN_MASK,
129 .shift = RPR0521_PXS_GAIN_SHIFT,
130 .gain = rpr0521_pxs_gain,
131 .size = ARRAY_SIZE(rpr0521_pxs_gain),
132 },
133};
134
135struct rpr0521_data {
136 struct i2c_client *client;
137
138 /* protect device params updates (e.g state, gain) */
139 struct mutex lock;
140
141 /* device active status */
142 bool als_dev_en;
143 bool pxs_dev_en;
144
145 /* optimize runtime pm ops - enable device only if needed */
146 bool als_ps_need_en;
147 bool pxs_ps_need_en;
148
149 struct regmap *regmap;
150};
151
152static IIO_CONST_ATTR(in_intensity_scale_available, RPR0521_ALS_SCALE_AVAIL);
153static IIO_CONST_ATTR(in_proximity_scale_available, RPR0521_PXS_SCALE_AVAIL);
154
155static struct attribute *rpr0521_attributes[] = {
156 &iio_const_attr_in_intensity_scale_available.dev_attr.attr,
157 &iio_const_attr_in_proximity_scale_available.dev_attr.attr,
158 NULL,
159};
160
161static const struct attribute_group rpr0521_attribute_group = {
162 .attrs = rpr0521_attributes,
163};
164
165static const struct iio_chan_spec rpr0521_channels[] = {
166 {
167 .type = IIO_INTENSITY,
168 .modified = 1,
169 .address = RPR0521_CHAN_ALS_DATA0,
170 .channel2 = IIO_MOD_LIGHT_BOTH,
171 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
172 BIT(IIO_CHAN_INFO_SCALE),
173 },
174 {
175 .type = IIO_INTENSITY,
176 .modified = 1,
177 .address = RPR0521_CHAN_ALS_DATA1,
178 .channel2 = IIO_MOD_LIGHT_IR,
179 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
180 BIT(IIO_CHAN_INFO_SCALE),
181 },
182 {
183 .type = IIO_PROXIMITY,
184 .address = RPR0521_CHAN_PXS,
185 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
186 BIT(IIO_CHAN_INFO_SCALE),
187 }
188};
189
190static int rpr0521_als_enable(struct rpr0521_data *data, u8 status)
191{
192 int ret;
193
194 ret = regmap_update_bits(data->regmap, RPR0521_REG_MODE_CTRL,
195 RPR0521_MODE_ALS_MASK,
196 status);
197 if (ret < 0)
198 return ret;
199
200 data->als_dev_en = true;
201
202 return 0;
203}
204
205static int rpr0521_pxs_enable(struct rpr0521_data *data, u8 status)
206{
207 int ret;
208
209 ret = regmap_update_bits(data->regmap, RPR0521_REG_MODE_CTRL,
210 RPR0521_MODE_PXS_MASK,
211 status);
212 if (ret < 0)
213 return ret;
214
215 data->pxs_dev_en = true;
216
217 return 0;
218}
219
220/**
221 * rpr0521_set_power_state - handles runtime PM state and sensors enabled status
222 *
223 * @data: rpr0521 device private data
224 * @on: state to be set for devices in @device_mask
225 * @device_mask: bitmask specifying for which device we need to update @on state
226 *
227 * We rely on rpr0521_runtime_resume to enable our @device_mask devices, but
228 * if (for example) PXS was enabled (pxs_dev_en = true) by a previous call to
229 * rpr0521_runtime_resume and we want to enable ALS we MUST set ALS enable
230 * bit of RPR0521_REG_MODE_CTRL here because rpr0521_runtime_resume will not
231 * be called twice.
232 */
233static int rpr0521_set_power_state(struct rpr0521_data *data, bool on,
234 u8 device_mask)
235{
236#ifdef CONFIG_PM
237 int ret;
238 u8 update_mask = 0;
239
240 if (device_mask & RPR0521_MODE_ALS_MASK) {
241 if (on && !data->als_ps_need_en && data->pxs_dev_en)
242 update_mask |= RPR0521_MODE_ALS_MASK;
243 else
244 data->als_ps_need_en = on;
245 }
246
247 if (device_mask & RPR0521_MODE_PXS_MASK) {
248 if (on && !data->pxs_ps_need_en && data->als_dev_en)
249 update_mask |= RPR0521_MODE_PXS_MASK;
250 else
251 data->pxs_ps_need_en = on;
252 }
253
254 if (update_mask) {
255 ret = regmap_update_bits(data->regmap, RPR0521_REG_MODE_CTRL,
256 update_mask, update_mask);
257 if (ret < 0)
258 return ret;
259 }
260
261 if (on) {
262 ret = pm_runtime_get_sync(&data->client->dev);
263 } else {
264 pm_runtime_mark_last_busy(&data->client->dev);
265 ret = pm_runtime_put_autosuspend(&data->client->dev);
266 }
267 if (ret < 0) {
268 dev_err(&data->client->dev,
269 "Failed: rpr0521_set_power_state for %d, ret %d\n",
270 on, ret);
271 if (on)
272 pm_runtime_put_noidle(&data->client->dev);
273
274 return ret;
275 }
276#endif
277 return 0;
278}
279
280static int rpr0521_get_gain(struct rpr0521_data *data, int chan,
281 int *val, int *val2)
282{
283 int ret, reg, idx;
284
285 ret = regmap_read(data->regmap, rpr0521_gain[chan].reg, &reg);
286 if (ret < 0)
287 return ret;
288
289 idx = (rpr0521_gain[chan].mask & reg) >> rpr0521_gain[chan].shift;
290 *val = rpr0521_gain[chan].gain[idx].scale;
291 *val2 = rpr0521_gain[chan].gain[idx].uscale;
292
293 return 0;
294}
295
296static int rpr0521_set_gain(struct rpr0521_data *data, int chan,
297 int val, int val2)
298{
299 int i, idx = -EINVAL;
300
301 /* get gain index */
302 for (i = 0; i < rpr0521_gain[chan].size; i++)
303 if (val == rpr0521_gain[chan].gain[i].scale &&
304 val2 == rpr0521_gain[chan].gain[i].uscale) {
305 idx = i;
306 break;
307 }
308
309 if (idx < 0)
310 return idx;
311
312 return regmap_update_bits(data->regmap, rpr0521_gain[chan].reg,
313 rpr0521_gain[chan].mask,
314 idx << rpr0521_gain[chan].shift);
315}
316
317static int rpr0521_read_raw(struct iio_dev *indio_dev,
318 struct iio_chan_spec const *chan, int *val,
319 int *val2, long mask)
320{
321 struct rpr0521_data *data = iio_priv(indio_dev);
322 int ret;
323 u8 device_mask;
324 __le16 raw_data;
325
326 switch (mask) {
327 case IIO_CHAN_INFO_RAW:
328 if (chan->type != IIO_INTENSITY && chan->type != IIO_PROXIMITY)
329 return -EINVAL;
330
331 device_mask = rpr0521_data_reg[chan->address].device_mask;
332
333 mutex_lock(&data->lock);
334 ret = rpr0521_set_power_state(data, true, device_mask);
335 if (ret < 0) {
336 mutex_unlock(&data->lock);
337 return ret;
338 }
339
340 ret = regmap_bulk_read(data->regmap,
341 rpr0521_data_reg[chan->address].address,
342 &raw_data, 2);
343 if (ret < 0) {
344 rpr0521_set_power_state(data, false, device_mask);
345 mutex_unlock(&data->lock);
346 return ret;
347 }
348
349 ret = rpr0521_set_power_state(data, false, device_mask);
350 mutex_unlock(&data->lock);
351 if (ret < 0)
352 return ret;
353
354 *val = le16_to_cpu(raw_data);
355
356 return IIO_VAL_INT;
357 case IIO_CHAN_INFO_SCALE:
358 mutex_lock(&data->lock);
359 ret = rpr0521_get_gain(data, chan->address, val, val2);
360 mutex_unlock(&data->lock);
361 if (ret < 0)
362 return ret;
363
364 return IIO_VAL_INT_PLUS_MICRO;
365 default:
366 return -EINVAL;
367 }
368}
369
370static int rpr0521_write_raw(struct iio_dev *indio_dev,
371 struct iio_chan_spec const *chan, int val,
372 int val2, long mask)
373{
374 struct rpr0521_data *data = iio_priv(indio_dev);
375 int ret;
376
377 switch (mask) {
378 case IIO_CHAN_INFO_SCALE:
379 mutex_lock(&data->lock);
380 ret = rpr0521_set_gain(data, chan->address, val, val2);
381 mutex_unlock(&data->lock);
382
383 return ret;
384 default:
385 return -EINVAL;
386 }
387}
388
389static const struct iio_info rpr0521_info = {
390 .driver_module = THIS_MODULE,
391 .read_raw = rpr0521_read_raw,
392 .write_raw = rpr0521_write_raw,
393 .attrs = &rpr0521_attribute_group,
394};
395
396static int rpr0521_init(struct rpr0521_data *data)
397{
398 int ret;
399 int id;
400
401 ret = regmap_read(data->regmap, RPR0521_REG_ID, &id);
402 if (ret < 0) {
403 dev_err(&data->client->dev, "Failed to read REG_ID register\n");
404 return ret;
405 }
406
407 if (id != RPR0521_MANUFACT_ID) {
408 dev_err(&data->client->dev, "Wrong id, got %x, expected %x\n",
409 id, RPR0521_MANUFACT_ID);
410 return -ENODEV;
411 }
412
413 /* set default measurement time - 100 ms for both ALS and PS */
414 ret = regmap_update_bits(data->regmap, RPR0521_REG_MODE_CTRL,
415 RPR0521_MODE_MEAS_TIME_MASK,
416 RPR0521_DEFAULT_MEAS_TIME);
417 if (ret) {
418 pr_err("regmap_update_bits returned %d\n", ret);
419 return ret;
420 }
421
422 ret = rpr0521_als_enable(data, RPR0521_MODE_ALS_ENABLE);
423 if (ret < 0)
424 return ret;
425 ret = rpr0521_pxs_enable(data, RPR0521_MODE_PXS_ENABLE);
426 if (ret < 0)
427 return ret;
428
429 return 0;
430}
431
432static int rpr0521_poweroff(struct rpr0521_data *data)
433{
434 int ret;
435
436 ret = regmap_update_bits(data->regmap, RPR0521_REG_MODE_CTRL,
437 RPR0521_MODE_ALS_MASK |
438 RPR0521_MODE_PXS_MASK,
439 RPR0521_MODE_ALS_DISABLE |
440 RPR0521_MODE_PXS_DISABLE);
441 if (ret < 0)
442 return ret;
443
444 data->als_dev_en = false;
445 data->pxs_dev_en = false;
446
447 return 0;
448}
449
450static bool rpr0521_is_volatile_reg(struct device *dev, unsigned int reg)
451{
452 switch (reg) {
453 case RPR0521_REG_MODE_CTRL:
454 case RPR0521_REG_ALS_CTRL:
455 case RPR0521_REG_PXS_CTRL:
456 return false;
457 default:
458 return true;
459 }
460}
461
462static const struct regmap_config rpr0521_regmap_config = {
463 .name = RPR0521_REGMAP_NAME,
464
465 .reg_bits = 8,
466 .val_bits = 8,
467
468 .max_register = RPR0521_REG_ID,
469 .cache_type = REGCACHE_RBTREE,
470 .volatile_reg = rpr0521_is_volatile_reg,
471};
472
473static int rpr0521_probe(struct i2c_client *client,
474 const struct i2c_device_id *id)
475{
476 struct rpr0521_data *data;
477 struct iio_dev *indio_dev;
478 struct regmap *regmap;
479 int ret;
480
481 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
482 if (!indio_dev)
483 return -ENOMEM;
484
485 regmap = devm_regmap_init_i2c(client, &rpr0521_regmap_config);
486 if (IS_ERR(regmap)) {
487 dev_err(&client->dev, "regmap_init failed!\n");
488 return PTR_ERR(regmap);
489 }
490
491 data = iio_priv(indio_dev);
492 i2c_set_clientdata(client, indio_dev);
493 data->client = client;
494 data->regmap = regmap;
495
496 mutex_init(&data->lock);
497
498 indio_dev->dev.parent = &client->dev;
499 indio_dev->info = &rpr0521_info;
500 indio_dev->name = RPR0521_DRV_NAME;
501 indio_dev->channels = rpr0521_channels;
502 indio_dev->num_channels = ARRAY_SIZE(rpr0521_channels);
503 indio_dev->modes = INDIO_DIRECT_MODE;
504
505 ret = rpr0521_init(data);
506 if (ret < 0) {
507 dev_err(&client->dev, "rpr0521 chip init failed\n");
508 return ret;
509 }
510 ret = iio_device_register(indio_dev);
511 if (ret < 0)
512 return ret;
513
514 ret = pm_runtime_set_active(&client->dev);
515 if (ret < 0)
516 goto err_iio_unregister;
517
518 pm_runtime_enable(&client->dev);
519 pm_runtime_set_autosuspend_delay(&client->dev, RPR0521_SLEEP_DELAY_MS);
520 pm_runtime_use_autosuspend(&client->dev);
521
522 return 0;
523
524err_iio_unregister:
525 iio_device_unregister(indio_dev);
526 return ret;
527}
528
529static int rpr0521_remove(struct i2c_client *client)
530{
531 struct iio_dev *indio_dev = i2c_get_clientdata(client);
532
533 pm_runtime_disable(&client->dev);
534 pm_runtime_set_suspended(&client->dev);
535 pm_runtime_put_noidle(&client->dev);
536
537 iio_device_unregister(indio_dev);
538 rpr0521_poweroff(iio_priv(indio_dev));
539
540 return 0;
541}
542
543#ifdef CONFIG_PM
544static int rpr0521_runtime_suspend(struct device *dev)
545{
546 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
547 struct rpr0521_data *data = iio_priv(indio_dev);
548 int ret;
549
550 /* disable channels and sets {als,pxs}_dev_en to false */
551 mutex_lock(&data->lock);
552 ret = rpr0521_poweroff(data);
553 mutex_unlock(&data->lock);
554
555 return ret;
556}
557
558static int rpr0521_runtime_resume(struct device *dev)
559{
560 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
561 struct rpr0521_data *data = iio_priv(indio_dev);
562 int ret;
563
564 if (data->als_ps_need_en) {
565 ret = rpr0521_als_enable(data, RPR0521_MODE_ALS_ENABLE);
566 if (ret < 0)
567 return ret;
568 data->als_ps_need_en = false;
569 }
570
571 if (data->pxs_ps_need_en) {
572 ret = rpr0521_pxs_enable(data, RPR0521_MODE_PXS_ENABLE);
573 if (ret < 0)
574 return ret;
575 data->pxs_ps_need_en = false;
576 }
577
578 return 0;
579}
580#endif
581
582static const struct dev_pm_ops rpr0521_pm_ops = {
583 SET_RUNTIME_PM_OPS(rpr0521_runtime_suspend,
584 rpr0521_runtime_resume, NULL)
585};
586
587static const struct acpi_device_id rpr0521_acpi_match[] = {
588 {"RPR0521", 0},
589 { }
590};
591MODULE_DEVICE_TABLE(acpi, rpr0521_acpi_match);
592
593static const struct i2c_device_id rpr0521_id[] = {
594 {"rpr0521", 0},
595 { }
596};
597
598MODULE_DEVICE_TABLE(i2c, rpr0521_id);
599
600static struct i2c_driver rpr0521_driver = {
601 .driver = {
602 .name = RPR0521_DRV_NAME,
603 .pm = &rpr0521_pm_ops,
604 .acpi_match_table = ACPI_PTR(rpr0521_acpi_match),
605 },
606 .probe = rpr0521_probe,
607 .remove = rpr0521_remove,
608 .id_table = rpr0521_id,
609};
610
611module_i2c_driver(rpr0521_driver);
612
613MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>");
614MODULE_DESCRIPTION("RPR0521 ROHM Ambient Light and Proximity Sensor driver");
615MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c
index 11a027adc204..f101bb5bddc7 100644
--- a/drivers/iio/light/stk3310.c
+++ b/drivers/iio/light/stk3310.c
@@ -676,6 +676,7 @@ static const struct i2c_device_id stk3310_i2c_id[] = {
676 {"STK3311", 0}, 676 {"STK3311", 0},
677 {} 677 {}
678}; 678};
679MODULE_DEVICE_TABLE(i2c, stk3310_i2c_id);
679 680
680static const struct acpi_device_id stk3310_acpi_id[] = { 681static const struct acpi_device_id stk3310_acpi_id[] = {
681 {"STK3310", 0}, 682 {"STK3310", 0},
diff --git a/drivers/iio/light/tcs3414.c b/drivers/iio/light/tcs3414.c
index f8b1df018abe..f90f8c5919fe 100644
--- a/drivers/iio/light/tcs3414.c
+++ b/drivers/iio/light/tcs3414.c
@@ -392,7 +392,6 @@ static struct i2c_driver tcs3414_driver = {
392 .driver = { 392 .driver = {
393 .name = TCS3414_DRV_NAME, 393 .name = TCS3414_DRV_NAME,
394 .pm = &tcs3414_pm_ops, 394 .pm = &tcs3414_pm_ops,
395 .owner = THIS_MODULE,
396 }, 395 },
397 .probe = tcs3414_probe, 396 .probe = tcs3414_probe,
398 .remove = tcs3414_remove, 397 .remove = tcs3414_remove,
diff --git a/drivers/iio/light/tcs3472.c b/drivers/iio/light/tcs3472.c
index 752569985d1d..1b530bf04c89 100644
--- a/drivers/iio/light/tcs3472.c
+++ b/drivers/iio/light/tcs3472.c
@@ -366,7 +366,6 @@ static struct i2c_driver tcs3472_driver = {
366 .driver = { 366 .driver = {
367 .name = TCS3472_DRV_NAME, 367 .name = TCS3472_DRV_NAME,
368 .pm = &tcs3472_pm_ops, 368 .pm = &tcs3472_pm_ops,
369 .owner = THIS_MODULE,
370 }, 369 },
371 .probe = tcs3472_probe, 370 .probe = tcs3472_probe,
372 .remove = tcs3472_remove, 371 .remove = tcs3472_remove,
diff --git a/drivers/iio/light/tsl4531.c b/drivers/iio/light/tsl4531.c
index 63c26e2d5d97..26979183d27c 100644
--- a/drivers/iio/light/tsl4531.c
+++ b/drivers/iio/light/tsl4531.c
@@ -247,7 +247,6 @@ static struct i2c_driver tsl4531_driver = {
247 .driver = { 247 .driver = {
248 .name = TSL4531_DRV_NAME, 248 .name = TSL4531_DRV_NAME,
249 .pm = TSL4531_PM_OPS, 249 .pm = TSL4531_PM_OPS,
250 .owner = THIS_MODULE,
251 }, 250 },
252 .probe = tsl4531_probe, 251 .probe = tsl4531_probe,
253 .remove = tsl4531_remove, 252 .remove = tsl4531_remove,
diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
index d948c4778ba6..c9d85bbc9230 100644
--- a/drivers/iio/light/vcnl4000.c
+++ b/drivers/iio/light/vcnl4000.c
@@ -185,7 +185,6 @@ static int vcnl4000_probe(struct i2c_client *client,
185static struct i2c_driver vcnl4000_driver = { 185static struct i2c_driver vcnl4000_driver = {
186 .driver = { 186 .driver = {
187 .name = VCNL4000_DRV_NAME, 187 .name = VCNL4000_DRV_NAME,
188 .owner = THIS_MODULE,
189 }, 188 },
190 .probe = vcnl4000_probe, 189 .probe = vcnl4000_probe,
191 .id_table = vcnl4000_id, 190 .id_table = vcnl4000_id,
diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c
index 1347a1f2e46f..e330205f8194 100644
--- a/drivers/iio/magnetometer/bmc150_magn.c
+++ b/drivers/iio/magnetometer/bmc150_magn.c
@@ -85,6 +85,7 @@
85#define BMC150_MAGN_REG_HIGH_THRESH 0x50 85#define BMC150_MAGN_REG_HIGH_THRESH 0x50
86#define BMC150_MAGN_REG_REP_XY 0x51 86#define BMC150_MAGN_REG_REP_XY 0x51
87#define BMC150_MAGN_REG_REP_Z 0x52 87#define BMC150_MAGN_REG_REP_Z 0x52
88#define BMC150_MAGN_REG_REP_DATAMASK GENMASK(7, 0)
88 89
89#define BMC150_MAGN_REG_TRIM_START 0x5D 90#define BMC150_MAGN_REG_TRIM_START 0x5D
90#define BMC150_MAGN_REG_TRIM_END 0x71 91#define BMC150_MAGN_REG_TRIM_END 0x71
@@ -559,7 +560,7 @@ static int bmc150_magn_write_raw(struct iio_dev *indio_dev,
559 } 560 }
560 ret = regmap_update_bits(data->regmap, 561 ret = regmap_update_bits(data->regmap,
561 BMC150_MAGN_REG_REP_XY, 562 BMC150_MAGN_REG_REP_XY,
562 0xFF, 563 BMC150_MAGN_REG_REP_DATAMASK,
563 BMC150_MAGN_REPXY_TO_REGVAL 564 BMC150_MAGN_REPXY_TO_REGVAL
564 (val)); 565 (val));
565 mutex_unlock(&data->mutex); 566 mutex_unlock(&data->mutex);
@@ -575,7 +576,7 @@ static int bmc150_magn_write_raw(struct iio_dev *indio_dev,
575 } 576 }
576 ret = regmap_update_bits(data->regmap, 577 ret = regmap_update_bits(data->regmap,
577 BMC150_MAGN_REG_REP_Z, 578 BMC150_MAGN_REG_REP_Z,
578 0xFF, 579 BMC150_MAGN_REG_REP_DATAMASK,
579 BMC150_MAGN_REPZ_TO_REGVAL 580 BMC150_MAGN_REPZ_TO_REGVAL
580 (val)); 581 (val));
581 mutex_unlock(&data->mutex); 582 mutex_unlock(&data->mutex);
@@ -588,17 +589,6 @@ static int bmc150_magn_write_raw(struct iio_dev *indio_dev,
588 } 589 }
589} 590}
590 591
591static int bmc150_magn_validate_trigger(struct iio_dev *indio_dev,
592 struct iio_trigger *trig)
593{
594 struct bmc150_magn_data *data = iio_priv(indio_dev);
595
596 if (data->dready_trig != trig)
597 return -EINVAL;
598
599 return 0;
600}
601
602static ssize_t bmc150_magn_show_samp_freq_avail(struct device *dev, 592static ssize_t bmc150_magn_show_samp_freq_avail(struct device *dev,
603 struct device_attribute *attr, 593 struct device_attribute *attr,
604 char *buf) 594 char *buf)
@@ -659,11 +649,12 @@ static const struct iio_info bmc150_magn_info = {
659 .attrs = &bmc150_magn_attrs_group, 649 .attrs = &bmc150_magn_attrs_group,
660 .read_raw = bmc150_magn_read_raw, 650 .read_raw = bmc150_magn_read_raw,
661 .write_raw = bmc150_magn_write_raw, 651 .write_raw = bmc150_magn_write_raw,
662 .validate_trigger = bmc150_magn_validate_trigger,
663 .driver_module = THIS_MODULE, 652 .driver_module = THIS_MODULE,
664}; 653};
665 654
666static const unsigned long bmc150_magn_scan_masks[] = {0x07, 0}; 655static const unsigned long bmc150_magn_scan_masks[] = {
656 BIT(AXIS_X) | BIT(AXIS_Y) | BIT(AXIS_Z),
657 0};
667 658
668static irqreturn_t bmc150_magn_trigger_handler(int irq, void *p) 659static irqreturn_t bmc150_magn_trigger_handler(int irq, void *p)
669{ 660{
@@ -674,7 +665,6 @@ static irqreturn_t bmc150_magn_trigger_handler(int irq, void *p)
674 665
675 mutex_lock(&data->mutex); 666 mutex_lock(&data->mutex);
676 ret = bmc150_magn_read_xyz(data, data->buffer); 667 ret = bmc150_magn_read_xyz(data, data->buffer);
677 mutex_unlock(&data->mutex);
678 if (ret < 0) 668 if (ret < 0)
679 goto err; 669 goto err;
680 670
@@ -682,7 +672,8 @@ static irqreturn_t bmc150_magn_trigger_handler(int irq, void *p)
682 pf->timestamp); 672 pf->timestamp);
683 673
684err: 674err:
685 iio_trigger_notify_done(data->dready_trig); 675 mutex_unlock(&data->mutex);
676 iio_trigger_notify_done(indio_dev->trig);
686 677
687 return IRQ_HANDLED; 678 return IRQ_HANDLED;
688} 679}
@@ -793,29 +784,23 @@ static int bmc150_magn_data_rdy_trigger_set_state(struct iio_trigger *trig,
793 if (state == data->dready_trigger_on) 784 if (state == data->dready_trigger_on)
794 goto err_unlock; 785 goto err_unlock;
795 786
796 ret = bmc150_magn_set_power_state(data, state);
797 if (ret < 0)
798 goto err_unlock;
799
800 ret = regmap_update_bits(data->regmap, BMC150_MAGN_REG_INT_DRDY, 787 ret = regmap_update_bits(data->regmap, BMC150_MAGN_REG_INT_DRDY,
801 BMC150_MAGN_MASK_DRDY_EN, 788 BMC150_MAGN_MASK_DRDY_EN,
802 state << BMC150_MAGN_SHIFT_DRDY_EN); 789 state << BMC150_MAGN_SHIFT_DRDY_EN);
803 if (ret < 0) 790 if (ret < 0)
804 goto err_poweroff; 791 goto err_unlock;
805 792
806 data->dready_trigger_on = state; 793 data->dready_trigger_on = state;
807 794
808 if (state) { 795 if (state) {
809 ret = bmc150_magn_reset_intr(data); 796 ret = bmc150_magn_reset_intr(data);
810 if (ret < 0) 797 if (ret < 0)
811 goto err_poweroff; 798 goto err_unlock;
812 } 799 }
813 mutex_unlock(&data->mutex); 800 mutex_unlock(&data->mutex);
814 801
815 return 0; 802 return 0;
816 803
817err_poweroff:
818 bmc150_magn_set_power_state(data, false);
819err_unlock: 804err_unlock:
820 mutex_unlock(&data->mutex); 805 mutex_unlock(&data->mutex);
821 return ret; 806 return ret;
@@ -827,6 +812,27 @@ static const struct iio_trigger_ops bmc150_magn_trigger_ops = {
827 .owner = THIS_MODULE, 812 .owner = THIS_MODULE,
828}; 813};
829 814
815static int bmc150_magn_buffer_preenable(struct iio_dev *indio_dev)
816{
817 struct bmc150_magn_data *data = iio_priv(indio_dev);
818
819 return bmc150_magn_set_power_state(data, true);
820}
821
822static int bmc150_magn_buffer_postdisable(struct iio_dev *indio_dev)
823{
824 struct bmc150_magn_data *data = iio_priv(indio_dev);
825
826 return bmc150_magn_set_power_state(data, false);
827}
828
829static const struct iio_buffer_setup_ops bmc150_magn_buffer_setup_ops = {
830 .preenable = bmc150_magn_buffer_preenable,
831 .postenable = iio_triggered_buffer_postenable,
832 .predisable = iio_triggered_buffer_predisable,
833 .postdisable = bmc150_magn_buffer_postdisable,
834};
835
830static int bmc150_magn_gpio_probe(struct i2c_client *client) 836static int bmc150_magn_gpio_probe(struct i2c_client *client)
831{ 837{
832 struct device *dev; 838 struct device *dev;
@@ -932,16 +938,6 @@ static int bmc150_magn_probe(struct i2c_client *client,
932 goto err_poweroff; 938 goto err_poweroff;
933 } 939 }
934 940
935 ret = iio_triggered_buffer_setup(indio_dev,
936 &iio_pollfunc_store_time,
937 bmc150_magn_trigger_handler,
938 NULL);
939 if (ret < 0) {
940 dev_err(&client->dev,
941 "iio triggered buffer setup failed\n");
942 goto err_trigger_unregister;
943 }
944
945 ret = request_threaded_irq(client->irq, 941 ret = request_threaded_irq(client->irq,
946 iio_trigger_generic_data_rdy_poll, 942 iio_trigger_generic_data_rdy_poll,
947 NULL, 943 NULL,
@@ -951,14 +947,24 @@ static int bmc150_magn_probe(struct i2c_client *client,
951 if (ret < 0) { 947 if (ret < 0) {
952 dev_err(&client->dev, "request irq %d failed\n", 948 dev_err(&client->dev, "request irq %d failed\n",
953 client->irq); 949 client->irq);
954 goto err_buffer_cleanup; 950 goto err_trigger_unregister;
955 } 951 }
956 } 952 }
957 953
954 ret = iio_triggered_buffer_setup(indio_dev,
955 iio_pollfunc_store_time,
956 bmc150_magn_trigger_handler,
957 &bmc150_magn_buffer_setup_ops);
958 if (ret < 0) {
959 dev_err(&client->dev,
960 "iio triggered buffer setup failed\n");
961 goto err_free_irq;
962 }
963
958 ret = iio_device_register(indio_dev); 964 ret = iio_device_register(indio_dev);
959 if (ret < 0) { 965 if (ret < 0) {
960 dev_err(&client->dev, "unable to register iio device\n"); 966 dev_err(&client->dev, "unable to register iio device\n");
961 goto err_free_irq; 967 goto err_buffer_cleanup;
962 } 968 }
963 969
964 ret = pm_runtime_set_active(&client->dev); 970 ret = pm_runtime_set_active(&client->dev);
@@ -976,12 +982,11 @@ static int bmc150_magn_probe(struct i2c_client *client,
976 982
977err_iio_unregister: 983err_iio_unregister:
978 iio_device_unregister(indio_dev); 984 iio_device_unregister(indio_dev);
985err_buffer_cleanup:
986 iio_triggered_buffer_cleanup(indio_dev);
979err_free_irq: 987err_free_irq:
980 if (client->irq > 0) 988 if (client->irq > 0)
981 free_irq(client->irq, data->dready_trig); 989 free_irq(client->irq, data->dready_trig);
982err_buffer_cleanup:
983 if (data->dready_trig)
984 iio_triggered_buffer_cleanup(indio_dev);
985err_trigger_unregister: 990err_trigger_unregister:
986 if (data->dready_trig) 991 if (data->dready_trig)
987 iio_trigger_unregister(data->dready_trig); 992 iio_trigger_unregister(data->dready_trig);
@@ -1000,14 +1005,13 @@ static int bmc150_magn_remove(struct i2c_client *client)
1000 pm_runtime_put_noidle(&client->dev); 1005 pm_runtime_put_noidle(&client->dev);
1001 1006
1002 iio_device_unregister(indio_dev); 1007 iio_device_unregister(indio_dev);
1008 iio_triggered_buffer_cleanup(indio_dev);
1003 1009
1004 if (client->irq > 0) 1010 if (client->irq > 0)
1005 free_irq(data->client->irq, data->dready_trig); 1011 free_irq(data->client->irq, data->dready_trig);
1006 1012
1007 if (data->dready_trig) { 1013 if (data->dready_trig)
1008 iio_triggered_buffer_cleanup(indio_dev);
1009 iio_trigger_unregister(data->dready_trig); 1014 iio_trigger_unregister(data->dready_trig);
1010 }
1011 1015
1012 mutex_lock(&data->mutex); 1016 mutex_lock(&data->mutex);
1013 bmc150_magn_set_power_mode(data, BMC150_MAGN_POWER_MODE_SUSPEND, true); 1017 bmc150_magn_set_power_mode(data, BMC150_MAGN_POWER_MODE_SUSPEND, true);
@@ -1034,6 +1038,9 @@ static int bmc150_magn_runtime_suspend(struct device *dev)
1034 return 0; 1038 return 0;
1035} 1039}
1036 1040
1041/*
1042 * Should be called with data->mutex held.
1043 */
1037static int bmc150_magn_runtime_resume(struct device *dev) 1044static int bmc150_magn_runtime_resume(struct device *dev)
1038{ 1045{
1039 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 1046 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
@@ -1082,12 +1089,14 @@ static const struct dev_pm_ops bmc150_magn_pm_ops = {
1082 1089
1083static const struct acpi_device_id bmc150_magn_acpi_match[] = { 1090static const struct acpi_device_id bmc150_magn_acpi_match[] = {
1084 {"BMC150B", 0}, 1091 {"BMC150B", 0},
1092 {"BMC156B", 0},
1085 {}, 1093 {},
1086}; 1094};
1087MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match); 1095MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match);
1088 1096
1089static const struct i2c_device_id bmc150_magn_id[] = { 1097static const struct i2c_device_id bmc150_magn_id[] = {
1090 {"bmc150_magn", 0}, 1098 {"bmc150_magn", 0},
1099 {"bmc156_magn", 0},
1091 {}, 1100 {},
1092}; 1101};
1093MODULE_DEVICE_TABLE(i2c, bmc150_magn_id); 1102MODULE_DEVICE_TABLE(i2c, bmc150_magn_id);
diff --git a/drivers/iio/magnetometer/mmc35240.c b/drivers/iio/magnetometer/mmc35240.c
index 706ebfd6297f..176e14a61558 100644
--- a/drivers/iio/magnetometer/mmc35240.c
+++ b/drivers/iio/magnetometer/mmc35240.c
@@ -316,31 +316,31 @@ static int mmc35240_read_measurement(struct mmc35240_data *data, __le16 buf[3])
316static int mmc35240_raw_to_mgauss(struct mmc35240_data *data, int index, 316static int mmc35240_raw_to_mgauss(struct mmc35240_data *data, int index,
317 __le16 buf[], int *val) 317 __le16 buf[], int *val)
318{ 318{
319 int raw_x, raw_y, raw_z; 319 int raw[3];
320 int sens_x, sens_y, sens_z; 320 int sens[3];
321 int nfo; 321 int nfo;
322 322
323 raw_x = le16_to_cpu(buf[AXIS_X]); 323 raw[AXIS_X] = le16_to_cpu(buf[AXIS_X]);
324 raw_y = le16_to_cpu(buf[AXIS_Y]); 324 raw[AXIS_Y] = le16_to_cpu(buf[AXIS_Y]);
325 raw_z = le16_to_cpu(buf[AXIS_Z]); 325 raw[AXIS_Z] = le16_to_cpu(buf[AXIS_Z]);
326 326
327 sens_x = mmc35240_props_table[data->res].sens[AXIS_X]; 327 sens[AXIS_X] = mmc35240_props_table[data->res].sens[AXIS_X];
328 sens_y = mmc35240_props_table[data->res].sens[AXIS_Y]; 328 sens[AXIS_Y] = mmc35240_props_table[data->res].sens[AXIS_Y];
329 sens_z = mmc35240_props_table[data->res].sens[AXIS_Z]; 329 sens[AXIS_Z] = mmc35240_props_table[data->res].sens[AXIS_Z];
330 330
331 nfo = mmc35240_props_table[data->res].nfo; 331 nfo = mmc35240_props_table[data->res].nfo;
332 332
333 switch (index) { 333 switch (index) {
334 case AXIS_X: 334 case AXIS_X:
335 *val = (raw_x - nfo) * 1000 / sens_x; 335 *val = (raw[AXIS_X] - nfo) * 1000 / sens[AXIS_X];
336 break; 336 break;
337 case AXIS_Y: 337 case AXIS_Y:
338 *val = (raw_y - nfo) * 1000 / sens_y - 338 *val = (raw[AXIS_Y] - nfo) * 1000 / sens[AXIS_Y] -
339 (raw_z - nfo) * 1000 / sens_z; 339 (raw[AXIS_Z] - nfo) * 1000 / sens[AXIS_Z];
340 break; 340 break;
341 case AXIS_Z: 341 case AXIS_Z:
342 *val = (raw_y - nfo) * 1000 / sens_y + 342 *val = (raw[AXIS_Y] - nfo) * 1000 / sens[AXIS_Y] +
343 (raw_z - nfo) * 1000 / sens_z; 343 (raw[AXIS_Z] - nfo) * 1000 / sens[AXIS_Z];
344 break; 344 break;
345 default: 345 default:
346 return -EINVAL; 346 return -EINVAL;
@@ -559,6 +559,12 @@ static const struct dev_pm_ops mmc35240_pm_ops = {
559 SET_SYSTEM_SLEEP_PM_OPS(mmc35240_suspend, mmc35240_resume) 559 SET_SYSTEM_SLEEP_PM_OPS(mmc35240_suspend, mmc35240_resume)
560}; 560};
561 561
562static const struct of_device_id mmc35240_of_match[] = {
563 { .compatible = "memsic,mmc35240", },
564 { }
565};
566MODULE_DEVICE_TABLE(of, mmc35240_of_match);
567
562static const struct acpi_device_id mmc35240_acpi_match[] = { 568static const struct acpi_device_id mmc35240_acpi_match[] = {
563 {"MMC35240", 0}, 569 {"MMC35240", 0},
564 { }, 570 { },
@@ -574,6 +580,7 @@ MODULE_DEVICE_TABLE(i2c, mmc35240_id);
574static struct i2c_driver mmc35240_driver = { 580static struct i2c_driver mmc35240_driver = {
575 .driver = { 581 .driver = {
576 .name = MMC35240_DRV_NAME, 582 .name = MMC35240_DRV_NAME,
583 .of_match_table = mmc35240_of_match,
577 .pm = &mmc35240_pm_ops, 584 .pm = &mmc35240_pm_ops,
578 .acpi_match_table = ACPI_PTR(mmc35240_acpi_match), 585 .acpi_match_table = ACPI_PTR(mmc35240_acpi_match),
579 }, 586 },
diff --git a/drivers/iio/magnetometer/st_magn.h b/drivers/iio/magnetometer/st_magn.h
index 287691ca56c1..06a4d9c35581 100644
--- a/drivers/iio/magnetometer/st_magn.h
+++ b/drivers/iio/magnetometer/st_magn.h
@@ -18,6 +18,7 @@
18#define LSM303DLHC_MAGN_DEV_NAME "lsm303dlhc_magn" 18#define LSM303DLHC_MAGN_DEV_NAME "lsm303dlhc_magn"
19#define LSM303DLM_MAGN_DEV_NAME "lsm303dlm_magn" 19#define LSM303DLM_MAGN_DEV_NAME "lsm303dlm_magn"
20#define LIS3MDL_MAGN_DEV_NAME "lis3mdl" 20#define LIS3MDL_MAGN_DEV_NAME "lis3mdl"
21#define LSM303AGR_MAGN_DEV_NAME "lsm303agr_magn"
21 22
22int st_magn_common_probe(struct iio_dev *indio_dev); 23int st_magn_common_probe(struct iio_dev *indio_dev);
23void st_magn_common_remove(struct iio_dev *indio_dev); 24void st_magn_common_remove(struct iio_dev *indio_dev);
@@ -25,6 +26,8 @@ void st_magn_common_remove(struct iio_dev *indio_dev);
25#ifdef CONFIG_IIO_BUFFER 26#ifdef CONFIG_IIO_BUFFER
26int st_magn_allocate_ring(struct iio_dev *indio_dev); 27int st_magn_allocate_ring(struct iio_dev *indio_dev);
27void st_magn_deallocate_ring(struct iio_dev *indio_dev); 28void st_magn_deallocate_ring(struct iio_dev *indio_dev);
29int st_magn_trig_set_state(struct iio_trigger *trig, bool state);
30#define ST_MAGN_TRIGGER_SET_STATE (&st_magn_trig_set_state)
28#else /* CONFIG_IIO_BUFFER */ 31#else /* CONFIG_IIO_BUFFER */
29static inline int st_magn_probe_trigger(struct iio_dev *indio_dev, int irq) 32static inline int st_magn_probe_trigger(struct iio_dev *indio_dev, int irq)
30{ 33{
diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c
index bf427dc0d226..ecd3bd0a9769 100644
--- a/drivers/iio/magnetometer/st_magn_buffer.c
+++ b/drivers/iio/magnetometer/st_magn_buffer.c
@@ -23,6 +23,13 @@
23#include <linux/iio/common/st_sensors.h> 23#include <linux/iio/common/st_sensors.h>
24#include "st_magn.h" 24#include "st_magn.h"
25 25
26int st_magn_trig_set_state(struct iio_trigger *trig, bool state)
27{
28 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
29
30 return st_sensors_set_dataready_irq(indio_dev, state);
31}
32
26static int st_magn_buffer_preenable(struct iio_dev *indio_dev) 33static int st_magn_buffer_preenable(struct iio_dev *indio_dev)
27{ 34{
28 return st_sensors_set_enable(indio_dev, true); 35 return st_sensors_set_enable(indio_dev, true);
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index b4bcfb790f49..f8dc4b85d70c 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -43,6 +43,7 @@
43#define ST_MAGN_FS_AVL_8000MG 8000 43#define ST_MAGN_FS_AVL_8000MG 8000
44#define ST_MAGN_FS_AVL_8100MG 8100 44#define ST_MAGN_FS_AVL_8100MG 8100
45#define ST_MAGN_FS_AVL_12000MG 12000 45#define ST_MAGN_FS_AVL_12000MG 12000
46#define ST_MAGN_FS_AVL_15000MG 15000
46#define ST_MAGN_FS_AVL_16000MG 16000 47#define ST_MAGN_FS_AVL_16000MG 16000
47 48
48/* CUSTOM VALUES FOR SENSOR 0 */ 49/* CUSTOM VALUES FOR SENSOR 0 */
@@ -157,6 +158,29 @@
157#define ST_MAGN_2_OUT_Y_L_ADDR 0x2a 158#define ST_MAGN_2_OUT_Y_L_ADDR 0x2a
158#define ST_MAGN_2_OUT_Z_L_ADDR 0x2c 159#define ST_MAGN_2_OUT_Z_L_ADDR 0x2c
159 160
161/* CUSTOM VALUES FOR SENSOR 3 */
162#define ST_MAGN_3_WAI_ADDR 0x4f
163#define ST_MAGN_3_WAI_EXP 0x40
164#define ST_MAGN_3_ODR_ADDR 0x60
165#define ST_MAGN_3_ODR_MASK 0x0c
166#define ST_MAGN_3_ODR_AVL_10HZ_VAL 0x00
167#define ST_MAGN_3_ODR_AVL_20HZ_VAL 0x01
168#define ST_MAGN_3_ODR_AVL_50HZ_VAL 0x02
169#define ST_MAGN_3_ODR_AVL_100HZ_VAL 0x03
170#define ST_MAGN_3_PW_ADDR 0x60
171#define ST_MAGN_3_PW_MASK 0x03
172#define ST_MAGN_3_PW_ON 0x00
173#define ST_MAGN_3_PW_OFF 0x03
174#define ST_MAGN_3_BDU_ADDR 0x62
175#define ST_MAGN_3_BDU_MASK 0x10
176#define ST_MAGN_3_DRDY_IRQ_ADDR 0x62
177#define ST_MAGN_3_DRDY_INT_MASK 0x01
178#define ST_MAGN_3_FS_AVL_15000_GAIN 1500
179#define ST_MAGN_3_MULTIREAD_BIT false
180#define ST_MAGN_3_OUT_X_L_ADDR 0x68
181#define ST_MAGN_3_OUT_Y_L_ADDR 0x6a
182#define ST_MAGN_3_OUT_Z_L_ADDR 0x6c
183
160static const struct iio_chan_spec st_magn_16bit_channels[] = { 184static const struct iio_chan_spec st_magn_16bit_channels[] = {
161 ST_SENSORS_LSM_CHANNELS(IIO_MAGN, 185 ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
162 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 186 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
@@ -189,9 +213,26 @@ static const struct iio_chan_spec st_magn_2_16bit_channels[] = {
189 IIO_CHAN_SOFT_TIMESTAMP(3) 213 IIO_CHAN_SOFT_TIMESTAMP(3)
190}; 214};
191 215
216static const struct iio_chan_spec st_magn_3_16bit_channels[] = {
217 ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
218 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
219 ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16,
220 ST_MAGN_3_OUT_X_L_ADDR),
221 ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
222 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
223 ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16,
224 ST_MAGN_3_OUT_Y_L_ADDR),
225 ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
226 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
227 ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16,
228 ST_MAGN_3_OUT_Z_L_ADDR),
229 IIO_CHAN_SOFT_TIMESTAMP(3)
230};
231
192static const struct st_sensor_settings st_magn_sensors_settings[] = { 232static const struct st_sensor_settings st_magn_sensors_settings[] = {
193 { 233 {
194 .wai = 0, /* This sensor has no valid WhoAmI report 0 */ 234 .wai = 0, /* This sensor has no valid WhoAmI report 0 */
235 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
195 .sensors_supported = { 236 .sensors_supported = {
196 [0] = LSM303DLH_MAGN_DEV_NAME, 237 [0] = LSM303DLH_MAGN_DEV_NAME,
197 }, 238 },
@@ -268,6 +309,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
268 }, 309 },
269 { 310 {
270 .wai = ST_MAGN_1_WAI_EXP, 311 .wai = ST_MAGN_1_WAI_EXP,
312 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
271 .sensors_supported = { 313 .sensors_supported = {
272 [0] = LSM303DLHC_MAGN_DEV_NAME, 314 [0] = LSM303DLHC_MAGN_DEV_NAME,
273 [1] = LSM303DLM_MAGN_DEV_NAME, 315 [1] = LSM303DLM_MAGN_DEV_NAME,
@@ -346,6 +388,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
346 }, 388 },
347 { 389 {
348 .wai = ST_MAGN_2_WAI_EXP, 390 .wai = ST_MAGN_2_WAI_EXP,
391 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
349 .sensors_supported = { 392 .sensors_supported = {
350 [0] = LIS3MDL_MAGN_DEV_NAME, 393 [0] = LIS3MDL_MAGN_DEV_NAME,
351 }, 394 },
@@ -399,6 +442,48 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
399 .multi_read_bit = ST_MAGN_2_MULTIREAD_BIT, 442 .multi_read_bit = ST_MAGN_2_MULTIREAD_BIT,
400 .bootime = 2, 443 .bootime = 2,
401 }, 444 },
445 {
446 .wai = ST_MAGN_3_WAI_EXP,
447 .wai_addr = ST_MAGN_3_WAI_ADDR,
448 .sensors_supported = {
449 [0] = LSM303AGR_MAGN_DEV_NAME,
450 },
451 .ch = (struct iio_chan_spec *)st_magn_3_16bit_channels,
452 .odr = {
453 .addr = ST_MAGN_3_ODR_ADDR,
454 .mask = ST_MAGN_3_ODR_MASK,
455 .odr_avl = {
456 { 10, ST_MAGN_3_ODR_AVL_10HZ_VAL, },
457 { 20, ST_MAGN_3_ODR_AVL_20HZ_VAL, },
458 { 50, ST_MAGN_3_ODR_AVL_50HZ_VAL, },
459 { 100, ST_MAGN_3_ODR_AVL_100HZ_VAL, },
460 },
461 },
462 .pw = {
463 .addr = ST_MAGN_3_PW_ADDR,
464 .mask = ST_MAGN_3_PW_MASK,
465 .value_on = ST_MAGN_3_PW_ON,
466 .value_off = ST_MAGN_3_PW_OFF,
467 },
468 .fs = {
469 .fs_avl = {
470 [0] = {
471 .num = ST_MAGN_FS_AVL_15000MG,
472 .gain = ST_MAGN_3_FS_AVL_15000_GAIN,
473 },
474 },
475 },
476 .bdu = {
477 .addr = ST_MAGN_3_BDU_ADDR,
478 .mask = ST_MAGN_3_BDU_MASK,
479 },
480 .drdy_irq = {
481 .addr = ST_MAGN_3_DRDY_IRQ_ADDR,
482 .mask_int1 = ST_MAGN_3_DRDY_INT_MASK,
483 },
484 .multi_read_bit = ST_MAGN_3_MULTIREAD_BIT,
485 .bootime = 2,
486 },
402}; 487};
403 488
404static int st_magn_read_raw(struct iio_dev *indio_dev, 489static int st_magn_read_raw(struct iio_dev *indio_dev,
@@ -477,6 +562,16 @@ static const struct iio_info magn_info = {
477 .write_raw = &st_magn_write_raw, 562 .write_raw = &st_magn_write_raw,
478}; 563};
479 564
565#ifdef CONFIG_IIO_TRIGGER
566static const struct iio_trigger_ops st_magn_trigger_ops = {
567 .owner = THIS_MODULE,
568 .set_trigger_state = ST_MAGN_TRIGGER_SET_STATE,
569};
570#define ST_MAGN_TRIGGER_OPS (&st_magn_trigger_ops)
571#else
572#define ST_MAGN_TRIGGER_OPS NULL
573#endif
574
480int st_magn_common_probe(struct iio_dev *indio_dev) 575int st_magn_common_probe(struct iio_dev *indio_dev)
481{ 576{
482 struct st_sensor_data *mdata = iio_priv(indio_dev); 577 struct st_sensor_data *mdata = iio_priv(indio_dev);
@@ -513,7 +608,8 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
513 return err; 608 return err;
514 609
515 if (irq > 0) { 610 if (irq > 0) {
516 err = st_sensors_allocate_trigger(indio_dev, NULL); 611 err = st_sensors_allocate_trigger(indio_dev,
612 ST_MAGN_TRIGGER_OPS);
517 if (err < 0) 613 if (err < 0)
518 goto st_magn_probe_trigger_error; 614 goto st_magn_probe_trigger_error;
519 } 615 }
diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c
index 5311d8aea8cc..8aa37af306ed 100644
--- a/drivers/iio/magnetometer/st_magn_i2c.c
+++ b/drivers/iio/magnetometer/st_magn_i2c.c
@@ -36,6 +36,10 @@ static const struct of_device_id st_magn_of_match[] = {
36 .compatible = "st,lis3mdl-magn", 36 .compatible = "st,lis3mdl-magn",
37 .data = LIS3MDL_MAGN_DEV_NAME, 37 .data = LIS3MDL_MAGN_DEV_NAME,
38 }, 38 },
39 {
40 .compatible = "st,lsm303agr-magn",
41 .data = LSM303AGR_MAGN_DEV_NAME,
42 },
39 {}, 43 {},
40}; 44};
41MODULE_DEVICE_TABLE(of, st_magn_of_match); 45MODULE_DEVICE_TABLE(of, st_magn_of_match);
@@ -79,13 +83,13 @@ static const struct i2c_device_id st_magn_id_table[] = {
79 { LSM303DLHC_MAGN_DEV_NAME }, 83 { LSM303DLHC_MAGN_DEV_NAME },
80 { LSM303DLM_MAGN_DEV_NAME }, 84 { LSM303DLM_MAGN_DEV_NAME },
81 { LIS3MDL_MAGN_DEV_NAME }, 85 { LIS3MDL_MAGN_DEV_NAME },
86 { LSM303AGR_MAGN_DEV_NAME },
82 {}, 87 {},
83}; 88};
84MODULE_DEVICE_TABLE(i2c, st_magn_id_table); 89MODULE_DEVICE_TABLE(i2c, st_magn_id_table);
85 90
86static struct i2c_driver st_magn_driver = { 91static struct i2c_driver st_magn_driver = {
87 .driver = { 92 .driver = {
88 .owner = THIS_MODULE,
89 .name = "st-magn-i2c", 93 .name = "st-magn-i2c",
90 .of_match_table = of_match_ptr(st_magn_of_match), 94 .of_match_table = of_match_ptr(st_magn_of_match),
91 }, 95 },
diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c
index 7adacf160146..0abca2c6afa6 100644
--- a/drivers/iio/magnetometer/st_magn_spi.c
+++ b/drivers/iio/magnetometer/st_magn_spi.c
@@ -51,6 +51,7 @@ static const struct spi_device_id st_magn_id_table[] = {
51 { LSM303DLHC_MAGN_DEV_NAME }, 51 { LSM303DLHC_MAGN_DEV_NAME },
52 { LSM303DLM_MAGN_DEV_NAME }, 52 { LSM303DLM_MAGN_DEV_NAME },
53 { LIS3MDL_MAGN_DEV_NAME }, 53 { LIS3MDL_MAGN_DEV_NAME },
54 { LSM303AGR_MAGN_DEV_NAME },
54 {}, 55 {},
55}; 56};
56MODULE_DEVICE_TABLE(spi, st_magn_id_table); 57MODULE_DEVICE_TABLE(spi, st_magn_id_table);
diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig
index fa6295041947..4745179ff64b 100644
--- a/drivers/iio/pressure/Kconfig
+++ b/drivers/iio/pressure/Kconfig
@@ -53,10 +53,10 @@ config MPL3115
53 will be called mpl3115. 53 will be called mpl3115.
54 54
55config MS5611 55config MS5611
56 tristate "Measurement Specialities MS5611 pressure sensor driver" 56 tristate "Measurement Specialties MS5611 pressure sensor driver"
57 help 57 help
58 Say Y here to build support for the Measurement Specialities 58 Say Y here to build support for the Measurement Specialties
59 MS5611 pressure and temperature sensor. 59 MS5611, MS5607 pressure and temperature sensors.
60 60
61 To compile this driver as a module, choose M here: the module will 61 To compile this driver as a module, choose M here: the module will
62 be called ms5611_core. 62 be called ms5611_core.
diff --git a/drivers/iio/pressure/ms5611.h b/drivers/iio/pressure/ms5611.h
index 099c6cdea43f..23b93c797dba 100644
--- a/drivers/iio/pressure/ms5611.h
+++ b/drivers/iio/pressure/ms5611.h
@@ -27,6 +27,18 @@
27 27
28#define MS5611_PROM_WORDS_NB 8 28#define MS5611_PROM_WORDS_NB 8
29 29
30enum {
31 MS5611,
32 MS5607,
33};
34
35struct ms5611_chip_info {
36 u16 prom[MS5611_PROM_WORDS_NB];
37
38 int (*temp_and_pressure_compensate)(struct ms5611_chip_info *chip_info,
39 s32 *temp, s32 *pressure);
40};
41
30struct ms5611_state { 42struct ms5611_state {
31 void *client; 43 void *client;
32 struct mutex lock; 44 struct mutex lock;
@@ -36,9 +48,9 @@ struct ms5611_state {
36 int (*read_adc_temp_and_pressure)(struct device *dev, 48 int (*read_adc_temp_and_pressure)(struct device *dev,
37 s32 *temp, s32 *pressure); 49 s32 *temp, s32 *pressure);
38 50
39 u16 prom[MS5611_PROM_WORDS_NB]; 51 struct ms5611_chip_info *chip_info;
40}; 52};
41 53
42int ms5611_probe(struct iio_dev *indio_dev, struct device *dev); 54int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, int type);
43 55
44#endif /* _MS5611_H */ 56#endif /* _MS5611_H */
diff --git a/drivers/iio/pressure/ms5611_core.c b/drivers/iio/pressure/ms5611_core.c
index e42c8531d9b3..2f3d9b4aca4e 100644
--- a/drivers/iio/pressure/ms5611_core.c
+++ b/drivers/iio/pressure/ms5611_core.c
@@ -9,6 +9,7 @@
9 * 9 *
10 * Data sheet: 10 * Data sheet:
11 * http://www.meas-spec.com/downloads/MS5611-01BA03.pdf 11 * http://www.meas-spec.com/downloads/MS5611-01BA03.pdf
12 * http://www.meas-spec.com/downloads/MS5607-02BA03.pdf
12 * 13 *
13 */ 14 */
14 15
@@ -50,7 +51,8 @@ static int ms5611_read_prom(struct iio_dev *indio_dev)
50 struct ms5611_state *st = iio_priv(indio_dev); 51 struct ms5611_state *st = iio_priv(indio_dev);
51 52
52 for (i = 0; i < MS5611_PROM_WORDS_NB; i++) { 53 for (i = 0; i < MS5611_PROM_WORDS_NB; i++) {
53 ret = st->read_prom_word(&indio_dev->dev, i, &st->prom[i]); 54 ret = st->read_prom_word(&indio_dev->dev,
55 i, &st->chip_info->prom[i]);
54 if (ret < 0) { 56 if (ret < 0) {
55 dev_err(&indio_dev->dev, 57 dev_err(&indio_dev->dev,
56 "failed to read prom at %d\n", i); 58 "failed to read prom at %d\n", i);
@@ -58,7 +60,7 @@ static int ms5611_read_prom(struct iio_dev *indio_dev)
58 } 60 }
59 } 61 }
60 62
61 if (!ms5611_prom_is_valid(st->prom, MS5611_PROM_WORDS_NB)) { 63 if (!ms5611_prom_is_valid(st->chip_info->prom, MS5611_PROM_WORDS_NB)) {
62 dev_err(&indio_dev->dev, "PROM integrity check failed\n"); 64 dev_err(&indio_dev->dev, "PROM integrity check failed\n");
63 return -ENODEV; 65 return -ENODEV;
64 } 66 }
@@ -70,22 +72,30 @@ static int ms5611_read_temp_and_pressure(struct iio_dev *indio_dev,
70 s32 *temp, s32 *pressure) 72 s32 *temp, s32 *pressure)
71{ 73{
72 int ret; 74 int ret;
73 s32 t, p;
74 s64 off, sens, dt;
75 struct ms5611_state *st = iio_priv(indio_dev); 75 struct ms5611_state *st = iio_priv(indio_dev);
76 76
77 ret = st->read_adc_temp_and_pressure(&indio_dev->dev, &t, &p); 77 ret = st->read_adc_temp_and_pressure(&indio_dev->dev, temp, pressure);
78 if (ret < 0) { 78 if (ret < 0) {
79 dev_err(&indio_dev->dev, 79 dev_err(&indio_dev->dev,
80 "failed to read temperature and pressure\n"); 80 "failed to read temperature and pressure\n");
81 return ret; 81 return ret;
82 } 82 }
83 83
84 dt = t - (st->prom[5] << 8); 84 return st->chip_info->temp_and_pressure_compensate(st->chip_info,
85 off = ((s64)st->prom[2] << 16) + ((st->prom[4] * dt) >> 7); 85 temp, pressure);
86 sens = ((s64)st->prom[1] << 15) + ((st->prom[3] * dt) >> 8); 86}
87
88static int ms5611_temp_and_pressure_compensate(struct ms5611_chip_info *chip_info,
89 s32 *temp, s32 *pressure)
90{
91 s32 t = *temp, p = *pressure;
92 s64 off, sens, dt;
87 93
88 t = 2000 + ((st->prom[6] * dt) >> 23); 94 dt = t - (chip_info->prom[5] << 8);
95 off = ((s64)chip_info->prom[2] << 16) + ((chip_info->prom[4] * dt) >> 7);
96 sens = ((s64)chip_info->prom[1] << 15) + ((chip_info->prom[3] * dt) >> 8);
97
98 t = 2000 + ((chip_info->prom[6] * dt) >> 23);
89 if (t < 2000) { 99 if (t < 2000) {
90 s64 off2, sens2, t2; 100 s64 off2, sens2, t2;
91 101
@@ -111,6 +121,42 @@ static int ms5611_read_temp_and_pressure(struct iio_dev *indio_dev,
111 return 0; 121 return 0;
112} 122}
113 123
124static int ms5607_temp_and_pressure_compensate(struct ms5611_chip_info *chip_info,
125 s32 *temp, s32 *pressure)
126{
127 s32 t = *temp, p = *pressure;
128 s64 off, sens, dt;
129
130 dt = t - (chip_info->prom[5] << 8);
131 off = ((s64)chip_info->prom[2] << 17) + ((chip_info->prom[4] * dt) >> 6);
132 sens = ((s64)chip_info->prom[1] << 16) + ((chip_info->prom[3] * dt) >> 7);
133
134 t = 2000 + ((chip_info->prom[6] * dt) >> 23);
135 if (t < 2000) {
136 s64 off2, sens2, t2;
137
138 t2 = (dt * dt) >> 31;
139 off2 = (61 * (t - 2000) * (t - 2000)) >> 4;
140 sens2 = off2 << 1;
141
142 if (t < -1500) {
143 s64 tmp = (t + 1500) * (t + 1500);
144
145 off2 += 15 * tmp;
146 sens2 += (8 * tmp);
147 }
148
149 t -= t2;
150 off -= off2;
151 sens -= sens2;
152 }
153
154 *temp = t;
155 *pressure = (((p * sens) >> 21) - off) >> 15;
156
157 return 0;
158}
159
114static int ms5611_reset(struct iio_dev *indio_dev) 160static int ms5611_reset(struct iio_dev *indio_dev)
115{ 161{
116 int ret; 162 int ret;
@@ -160,16 +206,23 @@ static int ms5611_read_raw(struct iio_dev *indio_dev,
160 return -EINVAL; 206 return -EINVAL;
161} 207}
162 208
209static struct ms5611_chip_info chip_info_tbl[] = {
210 [MS5611] = {
211 .temp_and_pressure_compensate = ms5611_temp_and_pressure_compensate,
212 },
213 [MS5607] = {
214 .temp_and_pressure_compensate = ms5607_temp_and_pressure_compensate,
215 }
216};
217
163static const struct iio_chan_spec ms5611_channels[] = { 218static const struct iio_chan_spec ms5611_channels[] = {
164 { 219 {
165 .type = IIO_PRESSURE, 220 .type = IIO_PRESSURE,
166 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 221 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
167 BIT(IIO_CHAN_INFO_SCALE)
168 }, 222 },
169 { 223 {
170 .type = IIO_TEMP, 224 .type = IIO_TEMP,
171 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 225 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
172 BIT(IIO_CHAN_INFO_SCALE)
173 } 226 }
174}; 227};
175 228
@@ -189,12 +242,13 @@ static int ms5611_init(struct iio_dev *indio_dev)
189 return ms5611_read_prom(indio_dev); 242 return ms5611_read_prom(indio_dev);
190} 243}
191 244
192int ms5611_probe(struct iio_dev *indio_dev, struct device *dev) 245int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, int type)
193{ 246{
194 int ret; 247 int ret;
195 struct ms5611_state *st = iio_priv(indio_dev); 248 struct ms5611_state *st = iio_priv(indio_dev);
196 249
197 mutex_init(&st->lock); 250 mutex_init(&st->lock);
251 st->chip_info = &chip_info_tbl[type];
198 indio_dev->dev.parent = dev; 252 indio_dev->dev.parent = dev;
199 indio_dev->name = dev->driver->name; 253 indio_dev->name = dev->driver->name;
200 indio_dev->info = &ms5611_info; 254 indio_dev->info = &ms5611_info;
diff --git a/drivers/iio/pressure/ms5611_i2c.c b/drivers/iio/pressure/ms5611_i2c.c
index 748fd9acaad8..245797d1ecf0 100644
--- a/drivers/iio/pressure/ms5611_i2c.c
+++ b/drivers/iio/pressure/ms5611_i2c.c
@@ -104,11 +104,12 @@ static int ms5611_i2c_probe(struct i2c_client *client,
104 st->read_adc_temp_and_pressure = ms5611_i2c_read_adc_temp_and_pressure; 104 st->read_adc_temp_and_pressure = ms5611_i2c_read_adc_temp_and_pressure;
105 st->client = client; 105 st->client = client;
106 106
107 return ms5611_probe(indio_dev, &client->dev); 107 return ms5611_probe(indio_dev, &client->dev, id->driver_data);
108} 108}
109 109
110static const struct i2c_device_id ms5611_id[] = { 110static const struct i2c_device_id ms5611_id[] = {
111 { "ms5611", 0 }, 111 { "ms5611", MS5611 },
112 { "ms5607", MS5607 },
112 { } 113 { }
113}; 114};
114MODULE_DEVICE_TABLE(i2c, ms5611_id); 115MODULE_DEVICE_TABLE(i2c, ms5611_id);
@@ -116,7 +117,6 @@ MODULE_DEVICE_TABLE(i2c, ms5611_id);
116static struct i2c_driver ms5611_driver = { 117static struct i2c_driver ms5611_driver = {
117 .driver = { 118 .driver = {
118 .name = "ms5611", 119 .name = "ms5611",
119 .owner = THIS_MODULE,
120 }, 120 },
121 .id_table = ms5611_id, 121 .id_table = ms5611_id,
122 .probe = ms5611_i2c_probe, 122 .probe = ms5611_i2c_probe,
diff --git a/drivers/iio/pressure/ms5611_spi.c b/drivers/iio/pressure/ms5611_spi.c
index 976726fd4e6c..08ee6e88c79f 100644
--- a/drivers/iio/pressure/ms5611_spi.c
+++ b/drivers/iio/pressure/ms5611_spi.c
@@ -103,11 +103,13 @@ static int ms5611_spi_probe(struct spi_device *spi)
103 st->read_adc_temp_and_pressure = ms5611_spi_read_adc_temp_and_pressure; 103 st->read_adc_temp_and_pressure = ms5611_spi_read_adc_temp_and_pressure;
104 st->client = spi; 104 st->client = spi;
105 105
106 return ms5611_probe(indio_dev, &spi->dev); 106 return ms5611_probe(indio_dev, &spi->dev,
107 spi_get_device_id(spi)->driver_data);
107} 108}
108 109
109static const struct spi_device_id ms5611_id[] = { 110static const struct spi_device_id ms5611_id[] = {
110 { "ms5611", 0 }, 111 { "ms5611", MS5611 },
112 { "ms5607", MS5607 },
111 { } 113 { }
112}; 114};
113MODULE_DEVICE_TABLE(spi, ms5611_id); 115MODULE_DEVICE_TABLE(spi, ms5611_id);
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index e881fa6291e9..eb41d2b92c24 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -178,6 +178,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
178static const struct st_sensor_settings st_press_sensors_settings[] = { 178static const struct st_sensor_settings st_press_sensors_settings[] = {
179 { 179 {
180 .wai = ST_PRESS_LPS331AP_WAI_EXP, 180 .wai = ST_PRESS_LPS331AP_WAI_EXP,
181 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
181 .sensors_supported = { 182 .sensors_supported = {
182 [0] = LPS331AP_PRESS_DEV_NAME, 183 [0] = LPS331AP_PRESS_DEV_NAME,
183 }, 184 },
@@ -225,6 +226,7 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
225 }, 226 },
226 { 227 {
227 .wai = ST_PRESS_LPS001WP_WAI_EXP, 228 .wai = ST_PRESS_LPS001WP_WAI_EXP,
229 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
228 .sensors_supported = { 230 .sensors_supported = {
229 [0] = LPS001WP_PRESS_DEV_NAME, 231 [0] = LPS001WP_PRESS_DEV_NAME,
230 }, 232 },
@@ -260,6 +262,7 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
260 }, 262 },
261 { 263 {
262 .wai = ST_PRESS_LPS25H_WAI_EXP, 264 .wai = ST_PRESS_LPS25H_WAI_EXP,
265 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
263 .sensors_supported = { 266 .sensors_supported = {
264 [0] = LPS25H_PRESS_DEV_NAME, 267 [0] = LPS25H_PRESS_DEV_NAME,
265 }, 268 },
diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c
index 137788bba4a3..8fcf9766eaec 100644
--- a/drivers/iio/pressure/st_pressure_i2c.c
+++ b/drivers/iio/pressure/st_pressure_i2c.c
@@ -79,7 +79,6 @@ MODULE_DEVICE_TABLE(i2c, st_press_id_table);
79 79
80static struct i2c_driver st_press_driver = { 80static struct i2c_driver st_press_driver = {
81 .driver = { 81 .driver = {
82 .owner = THIS_MODULE,
83 .name = "st-press-i2c", 82 .name = "st-press-i2c",
84 .of_match_table = of_match_ptr(st_press_of_match), 83 .of_match_table = of_match_ptr(st_press_of_match),
85 }, 84 },
diff --git a/drivers/iio/temperature/mlx90614.c b/drivers/iio/temperature/mlx90614.c
index 7a2b639eaa96..5d033a5af615 100644
--- a/drivers/iio/temperature/mlx90614.c
+++ b/drivers/iio/temperature/mlx90614.c
@@ -65,6 +65,13 @@
65 65
66#define MLX90614_AUTOSLEEP_DELAY 5000 /* default autosleep delay */ 66#define MLX90614_AUTOSLEEP_DELAY 5000 /* default autosleep delay */
67 67
68/* Magic constants */
69#define MLX90614_CONST_OFFSET_DEC -13657 /* decimal part of the Kelvin offset */
70#define MLX90614_CONST_OFFSET_REM 500000 /* remainder of offset (273.15*50) */
71#define MLX90614_CONST_SCALE 20 /* Scale in milliKelvin (0.02 * 1000) */
72#define MLX90614_CONST_RAW_EMISSIVITY_MAX 65535 /* max value for emissivity */
73#define MLX90614_CONST_EMISSIVITY_RESOLUTION 15259 /* 1/65535 ~ 0.000015259 */
74
68struct mlx90614_data { 75struct mlx90614_data {
69 struct i2c_client *client; 76 struct i2c_client *client;
70 struct mutex lock; /* for EEPROM access only */ 77 struct mutex lock; /* for EEPROM access only */
@@ -204,11 +211,11 @@ static int mlx90614_read_raw(struct iio_dev *indio_dev,
204 *val = ret; 211 *val = ret;
205 return IIO_VAL_INT; 212 return IIO_VAL_INT;
206 case IIO_CHAN_INFO_OFFSET: 213 case IIO_CHAN_INFO_OFFSET:
207 *val = -13657; 214 *val = MLX90614_CONST_OFFSET_DEC;
208 *val2 = 500000; 215 *val2 = MLX90614_CONST_OFFSET_REM;
209 return IIO_VAL_INT_PLUS_MICRO; 216 return IIO_VAL_INT_PLUS_MICRO;
210 case IIO_CHAN_INFO_SCALE: 217 case IIO_CHAN_INFO_SCALE:
211 *val = 20; 218 *val = MLX90614_CONST_SCALE;
212 return IIO_VAL_INT; 219 return IIO_VAL_INT;
213 case IIO_CHAN_INFO_CALIBEMISSIVITY: /* 1/65535 / LSB */ 220 case IIO_CHAN_INFO_CALIBEMISSIVITY: /* 1/65535 / LSB */
214 mlx90614_power_get(data, false); 221 mlx90614_power_get(data, false);
@@ -221,12 +228,12 @@ static int mlx90614_read_raw(struct iio_dev *indio_dev,
221 if (ret < 0) 228 if (ret < 0)
222 return ret; 229 return ret;
223 230
224 if (ret == 65535) { 231 if (ret == MLX90614_CONST_RAW_EMISSIVITY_MAX) {
225 *val = 1; 232 *val = 1;
226 *val2 = 0; 233 *val2 = 0;
227 } else { 234 } else {
228 *val = 0; 235 *val = 0;
229 *val2 = ret * 15259; /* 1/65535 ~ 0.000015259 */ 236 *val2 = ret * MLX90614_CONST_EMISSIVITY_RESOLUTION;
230 } 237 }
231 return IIO_VAL_INT_PLUS_NANO; 238 return IIO_VAL_INT_PLUS_NANO;
232 default: 239 default:
@@ -245,7 +252,8 @@ static int mlx90614_write_raw(struct iio_dev *indio_dev,
245 case IIO_CHAN_INFO_CALIBEMISSIVITY: /* 1/65535 / LSB */ 252 case IIO_CHAN_INFO_CALIBEMISSIVITY: /* 1/65535 / LSB */
246 if (val < 0 || val2 < 0 || val > 1 || (val == 1 && val2 != 0)) 253 if (val < 0 || val2 < 0 || val > 1 || (val == 1 && val2 != 0))
247 return -EINVAL; 254 return -EINVAL;
248 val = val * 65535 + val2 / 15259; /* 1/65535 ~ 0.000015259 */ 255 val = val * MLX90614_CONST_RAW_EMISSIVITY_MAX +
256 val2 / MLX90614_CONST_EMISSIVITY_RESOLUTION;
249 257
250 mlx90614_power_get(data, false); 258 mlx90614_power_get(data, false);
251 mutex_lock(&data->lock); 259 mutex_lock(&data->lock);
@@ -551,7 +559,6 @@ static const struct dev_pm_ops mlx90614_pm_ops = {
551static struct i2c_driver mlx90614_driver = { 559static struct i2c_driver mlx90614_driver = {
552 .driver = { 560 .driver = {
553 .name = "mlx90614", 561 .name = "mlx90614",
554 .owner = THIS_MODULE,
555 .pm = &mlx90614_pm_ops, 562 .pm = &mlx90614_pm_ops,
556 }, 563 },
557 .probe = mlx90614_probe, 564 .probe = mlx90614_probe,
diff --git a/drivers/iio/temperature/tmp006.c b/drivers/iio/temperature/tmp006.c
index 8f21f32f9739..e78c1069a6a9 100644
--- a/drivers/iio/temperature/tmp006.c
+++ b/drivers/iio/temperature/tmp006.c
@@ -36,9 +36,9 @@
36#define TMP006_CONFIG_DRDY_EN BIT(8) 36#define TMP006_CONFIG_DRDY_EN BIT(8)
37#define TMP006_CONFIG_DRDY BIT(7) 37#define TMP006_CONFIG_DRDY BIT(7)
38 38
39#define TMP006_CONFIG_MOD_MASK 0x7000 39#define TMP006_CONFIG_MOD_MASK GENMASK(14, 12)
40 40
41#define TMP006_CONFIG_CR_MASK 0x0e00 41#define TMP006_CONFIG_CR_MASK GENMASK(11, 9)
42#define TMP006_CONFIG_CR_SHIFT 9 42#define TMP006_CONFIG_CR_SHIFT 9
43 43
44#define TMP006_MANUFACTURER_MAGIC 0x5449 44#define TMP006_MANUFACTURER_MAGIC 0x5449
@@ -280,7 +280,6 @@ static struct i2c_driver tmp006_driver = {
280 .driver = { 280 .driver = {
281 .name = "tmp006", 281 .name = "tmp006",
282 .pm = &tmp006_pm_ops, 282 .pm = &tmp006_pm_ops,
283 .owner = THIS_MODULE,
284 }, 283 },
285 .probe = tmp006_probe, 284 .probe = tmp006_probe,
286 .remove = tmp006_remove, 285 .remove = tmp006_remove,
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 7f6cae5beb90..e29293c0c71e 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -56,8 +56,6 @@ source "drivers/staging/vt6656/Kconfig"
56 56
57source "drivers/staging/iio/Kconfig" 57source "drivers/staging/iio/Kconfig"
58 58
59source "drivers/staging/sm7xxfb/Kconfig"
60
61source "drivers/staging/sm750fb/Kconfig" 59source "drivers/staging/sm750fb/Kconfig"
62 60
63source "drivers/staging/xgifb/Kconfig" 61source "drivers/staging/xgifb/Kconfig"
@@ -78,8 +76,6 @@ source "drivers/staging/android/Kconfig"
78 76
79source "drivers/staging/board/Kconfig" 77source "drivers/staging/board/Kconfig"
80 78
81source "drivers/staging/ozwpan/Kconfig"
82
83source "drivers/staging/gdm72xx/Kconfig" 79source "drivers/staging/gdm72xx/Kconfig"
84 80
85source "drivers/staging/gdm724x/Kconfig" 81source "drivers/staging/gdm724x/Kconfig"
@@ -112,4 +108,6 @@ source "drivers/staging/fsl-mc/Kconfig"
112 108
113source "drivers/staging/wilc1000/Kconfig" 109source "drivers/staging/wilc1000/Kconfig"
114 110
111source "drivers/staging/most/Kconfig"
112
115endif # STAGING 113endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 347f6477aa3e..50824dde2c09 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -22,7 +22,6 @@ obj-$(CONFIG_VT6655) += vt6655/
22obj-$(CONFIG_VT6656) += vt6656/ 22obj-$(CONFIG_VT6656) += vt6656/
23obj-$(CONFIG_VME_BUS) += vme/ 23obj-$(CONFIG_VME_BUS) += vme/
24obj-$(CONFIG_IIO) += iio/ 24obj-$(CONFIG_IIO) += iio/
25obj-$(CONFIG_FB_SM7XX) += sm7xxfb/
26obj-$(CONFIG_FB_SM750) += sm750fb/ 25obj-$(CONFIG_FB_SM750) += sm750fb/
27obj-$(CONFIG_FB_XGI) += xgifb/ 26obj-$(CONFIG_FB_XGI) += xgifb/
28obj-$(CONFIG_USB_EMXX) += emxx_udc/ 27obj-$(CONFIG_USB_EMXX) += emxx_udc/
@@ -32,7 +31,6 @@ obj-$(CONFIG_TOUCHSCREEN_SYNAPTICS_I2C_RMI4) += ste_rmi4/
32obj-$(CONFIG_MFD_NVEC) += nvec/ 31obj-$(CONFIG_MFD_NVEC) += nvec/
33obj-$(CONFIG_ANDROID) += android/ 32obj-$(CONFIG_ANDROID) += android/
34obj-$(CONFIG_STAGING_BOARD) += board/ 33obj-$(CONFIG_STAGING_BOARD) += board/
35obj-$(CONFIG_USB_WPAN_HCD) += ozwpan/
36obj-$(CONFIG_WIMAX_GDM72XX) += gdm72xx/ 34obj-$(CONFIG_WIMAX_GDM72XX) += gdm72xx/
37obj-$(CONFIG_LTE_GDM724X) += gdm724x/ 35obj-$(CONFIG_LTE_GDM724X) += gdm724x/
38obj-$(CONFIG_FIREWIRE_SERIAL) += fwserial/ 36obj-$(CONFIG_FIREWIRE_SERIAL) += fwserial/
@@ -48,3 +46,4 @@ obj-$(CONFIG_COMMON_CLK_XLNX_CLKWZRD) += clocking-wizard/
48obj-$(CONFIG_FB_TFT) += fbtft/ 46obj-$(CONFIG_FB_TFT) += fbtft/
49obj-$(CONFIG_FSL_MC_BUS) += fsl-mc/ 47obj-$(CONFIG_FSL_MC_BUS) += fsl-mc/
50obj-$(CONFIG_WILC1000) += wilc1000/ 48obj-$(CONFIG_WILC1000) += wilc1000/
49obj-$(CONFIG_MOST) += most/
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index 24d657b3ab99..68307121c9c1 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -20,7 +20,8 @@ config ANDROID_TIMED_OUTPUT
20 20
21config ANDROID_TIMED_GPIO 21config ANDROID_TIMED_GPIO
22 tristate "Android timed gpio driver" 22 tristate "Android timed gpio driver"
23 depends on GPIOLIB && ANDROID_TIMED_OUTPUT 23 depends on GPIOLIB || COMPILE_TEST
24 depends on ANDROID_TIMED_OUTPUT
24 default n 25 default n
25 ---help--- 26 ---help---
26 Unlike generic gpio is to allow programs to access and manipulate gpio 27 Unlike generic gpio is to allow programs to access and manipulate gpio
diff --git a/drivers/staging/android/TODO b/drivers/staging/android/TODO
index 06954cdf3dba..20288fc53946 100644
--- a/drivers/staging/android/TODO
+++ b/drivers/staging/android/TODO
@@ -2,16 +2,8 @@ TODO:
2 - checkpatch.pl cleanups 2 - checkpatch.pl cleanups
3 - sparse fixes 3 - sparse fixes
4 - rename files to be not so "generic" 4 - rename files to be not so "generic"
5 - make sure things build as modules properly
6 - add proper arch dependencies as needed 5 - add proper arch dependencies as needed
7 - audit userspace interfaces to make sure they are sane 6 - audit userspace interfaces to make sure they are sane
8 - kuid_t should never be exposed to user space as it is
9 kernel internal type. Data structure for this kuid_t is:
10 typedef struct {
11 uid_t val;
12 } kuid_t;
13 - This bug is introduced by Xiong Zhou in the patch bd471258f2e09
14 - ("staging: android: logger: use kuid_t instead of uid_t")
15 7
16Please send patches to Greg Kroah-Hartman <greg@kroah.com> and Cc: 8Please send patches to Greg Kroah-Hartman <greg@kroah.com> and Cc:
17Brian Swetland <swetland@google.com> 9Arve Hjønnevåg <arve@android.com> and Riley Andrews <riandrews@android.com>
diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
index 2c75d90b26c8..60200a3da821 100644
--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -388,7 +388,7 @@ static int ashmem_mmap(struct file *file, struct vm_area_struct *vma)
388 388
389 /* ... and allocate the backing shmem file */ 389 /* ... and allocate the backing shmem file */
390 vmfile = shmem_file_setup(name, asma->size, vma->vm_flags); 390 vmfile = shmem_file_setup(name, asma->size, vma->vm_flags);
391 if (unlikely(IS_ERR(vmfile))) { 391 if (IS_ERR(vmfile)) {
392 ret = PTR_ERR(vmfile); 392 ret = PTR_ERR(vmfile);
393 goto out; 393 goto out;
394 } 394 }
@@ -660,7 +660,7 @@ restart:
660 if (page_range_subsumed_by_range(range, pgstart, pgend)) 660 if (page_range_subsumed_by_range(range, pgstart, pgend))
661 return 0; 661 return 0;
662 if (page_range_in_range(range, pgstart, pgend)) { 662 if (page_range_in_range(range, pgstart, pgend)) {
663 pgstart = min_t(size_t, range->pgstart, pgstart), 663 pgstart = min_t(size_t, range->pgstart, pgstart);
664 pgend = max_t(size_t, range->pgend, pgend); 664 pgend = max_t(size_t, range->pgend, pgend);
665 purged |= range->purged; 665 purged |= range->purged;
666 range_del(range); 666 range_del(range);
diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
index 6f4811263557..eec878e183f5 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -1103,10 +1103,10 @@ static struct dma_buf_ops dma_buf_ops = {
1103struct dma_buf *ion_share_dma_buf(struct ion_client *client, 1103struct dma_buf *ion_share_dma_buf(struct ion_client *client,
1104 struct ion_handle *handle) 1104 struct ion_handle *handle)
1105{ 1105{
1106 DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
1106 struct ion_buffer *buffer; 1107 struct ion_buffer *buffer;
1107 struct dma_buf *dmabuf; 1108 struct dma_buf *dmabuf;
1108 bool valid_handle; 1109 bool valid_handle;
1109 DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
1110 1110
1111 mutex_lock(&client->lock); 1111 mutex_lock(&client->lock);
1112 valid_handle = ion_handle_validate(client, handle); 1112 valid_handle = ion_handle_validate(client, handle);
@@ -1466,7 +1466,6 @@ static const struct file_operations debug_heap_fops = {
1466 .release = single_release, 1466 .release = single_release,
1467}; 1467};
1468 1468
1469#ifdef DEBUG_HEAP_SHRINKER
1470static int debug_shrink_set(void *data, u64 val) 1469static int debug_shrink_set(void *data, u64 val)
1471{ 1470{
1472 struct ion_heap *heap = data; 1471 struct ion_heap *heap = data;
@@ -1474,15 +1473,14 @@ static int debug_shrink_set(void *data, u64 val)
1474 int objs; 1473 int objs;
1475 1474
1476 sc.gfp_mask = -1; 1475 sc.gfp_mask = -1;
1477 sc.nr_to_scan = 0; 1476 sc.nr_to_scan = val;
1478 1477
1479 if (!val) 1478 if (!val) {
1480 return 0; 1479 objs = heap->shrinker.count_objects(&heap->shrinker, &sc);
1481 1480 sc.nr_to_scan = objs;
1482 objs = heap->shrinker.shrink(&heap->shrinker, &sc); 1481 }
1483 sc.nr_to_scan = objs;
1484 1482
1485 heap->shrinker.shrink(&heap->shrinker, &sc); 1483 heap->shrinker.scan_objects(&heap->shrinker, &sc);
1486 return 0; 1484 return 0;
1487} 1485}
1488 1486
@@ -1495,14 +1493,13 @@ static int debug_shrink_get(void *data, u64 *val)
1495 sc.gfp_mask = -1; 1493 sc.gfp_mask = -1;
1496 sc.nr_to_scan = 0; 1494 sc.nr_to_scan = 0;
1497 1495
1498 objs = heap->shrinker.shrink(&heap->shrinker, &sc); 1496 objs = heap->shrinker.count_objects(&heap->shrinker, &sc);
1499 *val = objs; 1497 *val = objs;
1500 return 0; 1498 return 0;
1501} 1499}
1502 1500
1503DEFINE_SIMPLE_ATTRIBUTE(debug_shrink_fops, debug_shrink_get, 1501DEFINE_SIMPLE_ATTRIBUTE(debug_shrink_fops, debug_shrink_get,
1504 debug_shrink_set, "%llu\n"); 1502 debug_shrink_set, "%llu\n");
1505#endif
1506 1503
1507void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap) 1504void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
1508{ 1505{
@@ -1540,8 +1537,7 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
1540 path, heap->name); 1537 path, heap->name);
1541 } 1538 }
1542 1539
1543#ifdef DEBUG_HEAP_SHRINKER 1540 if (heap->shrinker.count_objects && heap->shrinker.scan_objects) {
1544 if (heap->shrinker.shrink) {
1545 char debug_name[64]; 1541 char debug_name[64];
1546 1542
1547 snprintf(debug_name, 64, "%s_shrink", heap->name); 1543 snprintf(debug_name, 64, "%s_shrink", heap->name);
@@ -1556,7 +1552,7 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
1556 path, debug_name); 1552 path, debug_name);
1557 } 1553 }
1558 } 1554 }
1559#endif 1555
1560 up_write(&dev->lock); 1556 up_write(&dev->lock);
1561} 1557}
1562 1558
diff --git a/drivers/staging/android/ion/ion_chunk_heap.c b/drivers/staging/android/ion/ion_chunk_heap.c
index 54746157d799..0813163f962f 100644
--- a/drivers/staging/android/ion/ion_chunk_heap.c
+++ b/drivers/staging/android/ion/ion_chunk_heap.c
@@ -173,8 +173,8 @@ struct ion_heap *ion_chunk_heap_create(struct ion_platform_heap *heap_data)
173 chunk_heap->heap.ops = &chunk_heap_ops; 173 chunk_heap->heap.ops = &chunk_heap_ops;
174 chunk_heap->heap.type = ION_HEAP_TYPE_CHUNK; 174 chunk_heap->heap.type = ION_HEAP_TYPE_CHUNK;
175 chunk_heap->heap.flags = ION_HEAP_FLAG_DEFER_FREE; 175 chunk_heap->heap.flags = ION_HEAP_FLAG_DEFER_FREE;
176 pr_debug("%s: base %lu size %zu align %ld\n", __func__, chunk_heap->base, 176 pr_debug("%s: base %lu size %zu align %ld\n", __func__,
177 heap_data->size, heap_data->align); 177 chunk_heap->base, heap_data->size, heap_data->align);
178 178
179 return &chunk_heap->heap; 179 return &chunk_heap->heap;
180 180
diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c
index f4211f1be488..0b2448c32495 100644
--- a/drivers/staging/android/ion/ion_cma_heap.c
+++ b/drivers/staging/android/ion/ion_cma_heap.c
@@ -73,8 +73,8 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
73 if (!info->table) 73 if (!info->table)
74 goto free_mem; 74 goto free_mem;
75 75
76 if (dma_common_get_sgtable 76 if (dma_get_sgtable(dev, info->table, info->cpu_addr, info->handle,
77 (dev, info->table, info->cpu_addr, info->handle, len)) 77 len))
78 goto free_table; 78 goto free_table;
79 /* keep this for memory release */ 79 /* keep this for memory release */
80 buffer->priv_virt = info; 80 buffer->priv_virt = info;
diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c
index 4b88f11e52d3..19ad3aba499a 100644
--- a/drivers/staging/android/ion/ion_page_pool.c
+++ b/drivers/staging/android/ion/ion_page_pool.c
@@ -116,7 +116,7 @@ static int ion_page_pool_total(struct ion_page_pool *pool, bool high)
116int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask, 116int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,
117 int nr_to_scan) 117 int nr_to_scan)
118{ 118{
119 int freed; 119 int freed = 0;
120 bool high; 120 bool high;
121 121
122 if (current_is_kswapd()) 122 if (current_is_kswapd())
@@ -127,7 +127,7 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,
127 if (nr_to_scan == 0) 127 if (nr_to_scan == 0)
128 return ion_page_pool_total(pool, high); 128 return ion_page_pool_total(pool, high);
129 129
130 for (freed = 0; freed < nr_to_scan; freed++) { 130 while (freed < nr_to_scan) {
131 struct page *page; 131 struct page *page;
132 132
133 mutex_lock(&pool->mutex); 133 mutex_lock(&pool->mutex);
@@ -141,6 +141,7 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,
141 } 141 }
142 mutex_unlock(&pool->mutex); 142 mutex_unlock(&pool->mutex);
143 ion_page_pool_free_pages(pool, page); 143 ion_page_pool_free_pages(pool, page);
144 freed += (1 << pool->order);
144 } 145 }
145 146
146 return freed; 147 return freed;
diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
index da2a63c0a9ba..7a7a9a047230 100644
--- a/drivers/staging/android/ion/ion_system_heap.c
+++ b/drivers/staging/android/ion/ion_system_heap.c
@@ -212,14 +212,26 @@ static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask,
212{ 212{
213 struct ion_system_heap *sys_heap; 213 struct ion_system_heap *sys_heap;
214 int nr_total = 0; 214 int nr_total = 0;
215 int i; 215 int i, nr_freed;
216 int only_scan = 0;
216 217
217 sys_heap = container_of(heap, struct ion_system_heap, heap); 218 sys_heap = container_of(heap, struct ion_system_heap, heap);
218 219
220 if (!nr_to_scan)
221 only_scan = 1;
222
219 for (i = 0; i < num_orders; i++) { 223 for (i = 0; i < num_orders; i++) {
220 struct ion_page_pool *pool = sys_heap->pools[i]; 224 struct ion_page_pool *pool = sys_heap->pools[i];
221 225
222 nr_total += ion_page_pool_shrink(pool, gfp_mask, nr_to_scan); 226 nr_freed = ion_page_pool_shrink(pool, gfp_mask, nr_to_scan);
227 nr_total += nr_freed;
228
229 if (!only_scan) {
230 nr_to_scan -= nr_freed;
231 /* shrink completed */
232 if (nr_to_scan <= 0)
233 break;
234 }
223 } 235 }
224 236
225 return nr_total; 237 return nr_total;
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index a21b79fb4c8e..61f8a3aede96 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -337,11 +337,11 @@ int sync_fence_wait(struct sync_fence *fence, long timeout);
337 337
338#ifdef CONFIG_DEBUG_FS 338#ifdef CONFIG_DEBUG_FS
339 339
340extern void sync_timeline_debug_add(struct sync_timeline *obj); 340void sync_timeline_debug_add(struct sync_timeline *obj);
341extern void sync_timeline_debug_remove(struct sync_timeline *obj); 341void sync_timeline_debug_remove(struct sync_timeline *obj);
342extern void sync_fence_debug_add(struct sync_fence *fence); 342void sync_fence_debug_add(struct sync_fence *fence);
343extern void sync_fence_debug_remove(struct sync_fence *fence); 343void sync_fence_debug_remove(struct sync_fence *fence);
344extern void sync_dump(void); 344void sync_dump(void);
345 345
346#else 346#else
347# define sync_timeline_debug_add(obj) 347# define sync_timeline_debug_add(obj)
diff --git a/drivers/staging/android/timed_gpio.c b/drivers/staging/android/timed_gpio.c
index 938a35cd99bb..ce11726f1a6c 100644
--- a/drivers/staging/android/timed_gpio.c
+++ b/drivers/staging/android/timed_gpio.c
@@ -61,9 +61,9 @@ static int gpio_get_time(struct timed_output_dev *dev)
61 61
62static void gpio_enable(struct timed_output_dev *dev, int value) 62static void gpio_enable(struct timed_output_dev *dev, int value)
63{ 63{
64 struct timed_gpio_data *data = 64 struct timed_gpio_data *data =
65 container_of(dev, struct timed_gpio_data, dev); 65 container_of(dev, struct timed_gpio_data, dev);
66 unsigned long flags; 66 unsigned long flags;
67 67
68 spin_lock_irqsave(&data->lock, flags); 68 spin_lock_irqsave(&data->lock, flags);
69 69
diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig
index 7dee73dfbf88..57e71f9f14a2 100644
--- a/drivers/staging/comedi/Kconfig
+++ b/drivers/staging/comedi/Kconfig
@@ -2,7 +2,7 @@ config COMEDI
2 tristate "Data acquisition support (comedi)" 2 tristate "Data acquisition support (comedi)"
3 depends on m 3 depends on m
4 ---help--- 4 ---help---
5 Enable support a wide range of data acquisition devices 5 Enable support for a wide range of data acquisition devices
6 for Linux. 6 for Linux.
7 7
8if COMEDI 8if COMEDI
diff --git a/drivers/staging/comedi/comedi_compat32.c b/drivers/staging/comedi/comedi_compat32.c
index 25848244c4b1..f356386d833a 100644
--- a/drivers/staging/comedi/comedi_compat32.c
+++ b/drivers/staging/comedi/comedi_compat32.c
@@ -202,7 +202,8 @@ static int get_compat_cmd(struct comedi_cmd __user *cmd,
202 err |= __get_user(temp.uint, &cmd32->stop_arg); 202 err |= __get_user(temp.uint, &cmd32->stop_arg);
203 err |= __put_user(temp.uint, &cmd->stop_arg); 203 err |= __put_user(temp.uint, &cmd->stop_arg);
204 err |= __get_user(temp.uptr, &cmd32->chanlist); 204 err |= __get_user(temp.uptr, &cmd32->chanlist);
205 err |= __put_user(compat_ptr(temp.uptr), &cmd->chanlist); 205 err |= __put_user((unsigned int __force *)compat_ptr(temp.uptr),
206 &cmd->chanlist);
206 err |= __get_user(temp.uint, &cmd32->chanlist_len); 207 err |= __get_user(temp.uint, &cmd32->chanlist_len);
207 err |= __put_user(temp.uint, &cmd->chanlist_len); 208 err |= __put_user(temp.uint, &cmd->chanlist_len);
208 err |= __get_user(temp.uptr, &cmd32->data); 209 err |= __get_user(temp.uptr, &cmd32->data);
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 985d94b6cbfd..fd54d098ab02 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -215,7 +215,6 @@ static struct comedi_subdevice
215 struct comedi_subdevice *s; 215 struct comedi_subdevice *s;
216 unsigned int i = minor - COMEDI_NUM_BOARD_MINORS; 216 unsigned int i = minor - COMEDI_NUM_BOARD_MINORS;
217 217
218 BUG_ON(i >= COMEDI_NUM_SUBDEVICE_MINORS);
219 mutex_lock(&comedi_subdevice_minor_table_lock); 218 mutex_lock(&comedi_subdevice_minor_table_lock);
220 s = comedi_subdevice_minor_table[i]; 219 s = comedi_subdevice_minor_table[i];
221 if (s && s->device != dev) 220 if (s && s->device != dev)
@@ -228,7 +227,6 @@ static struct comedi_device *comedi_dev_get_from_board_minor(unsigned minor)
228{ 227{
229 struct comedi_device *dev; 228 struct comedi_device *dev;
230 229
231 BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
232 mutex_lock(&comedi_board_minor_table_lock); 230 mutex_lock(&comedi_board_minor_table_lock);
233 dev = comedi_dev_get(comedi_board_minor_table[minor]); 231 dev = comedi_dev_get(comedi_board_minor_table[minor]);
234 mutex_unlock(&comedi_board_minor_table_lock); 232 mutex_unlock(&comedi_board_minor_table_lock);
@@ -241,7 +239,6 @@ static struct comedi_device *comedi_dev_get_from_subdevice_minor(unsigned minor)
241 struct comedi_subdevice *s; 239 struct comedi_subdevice *s;
242 unsigned int i = minor - COMEDI_NUM_BOARD_MINORS; 240 unsigned int i = minor - COMEDI_NUM_BOARD_MINORS;
243 241
244 BUG_ON(i >= COMEDI_NUM_SUBDEVICE_MINORS);
245 mutex_lock(&comedi_subdevice_minor_table_lock); 242 mutex_lock(&comedi_subdevice_minor_table_lock);
246 s = comedi_subdevice_minor_table[i]; 243 s = comedi_subdevice_minor_table[i];
247 dev = comedi_dev_get(s ? s->device : NULL); 244 dev = comedi_dev_get(s ? s->device : NULL);
@@ -2599,14 +2596,14 @@ static int comedi_open(struct inode *inode, struct file *file)
2599 cfp->dev = dev; 2596 cfp->dev = dev;
2600 2597
2601 mutex_lock(&dev->mutex); 2598 mutex_lock(&dev->mutex);
2602 if (!dev->attached && !capable(CAP_NET_ADMIN)) { 2599 if (!dev->attached && !capable(CAP_SYS_ADMIN)) {
2603 dev_dbg(dev->class_dev, "not attached and not CAP_NET_ADMIN\n"); 2600 dev_dbg(dev->class_dev, "not attached and not CAP_SYS_ADMIN\n");
2604 rc = -ENODEV; 2601 rc = -ENODEV;
2605 goto out; 2602 goto out;
2606 } 2603 }
2607 if (dev->attached && dev->use_count == 0) { 2604 if (dev->attached && dev->use_count == 0) {
2608 if (!try_module_get(dev->driver->module)) { 2605 if (!try_module_get(dev->driver->module)) {
2609 rc = -ENOSYS; 2606 rc = -ENXIO;
2610 goto out; 2607 goto out;
2611 } 2608 }
2612 if (dev->open) { 2609 if (dev->open) {
@@ -2777,12 +2774,6 @@ struct comedi_device *comedi_alloc_board_minor(struct device *hardware_device)
2777 return dev; 2774 return dev;
2778} 2775}
2779 2776
2780static void comedi_free_board_minor(unsigned minor)
2781{
2782 BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
2783 comedi_free_board_dev(comedi_clear_board_minor(minor));
2784}
2785
2786void comedi_release_hardware_device(struct device *hardware_device) 2777void comedi_release_hardware_device(struct device *hardware_device)
2787{ 2778{
2788 int minor; 2779 int minor;
@@ -2838,12 +2829,10 @@ void comedi_free_subdevice_minor(struct comedi_subdevice *s)
2838 2829
2839 if (!s) 2830 if (!s)
2840 return; 2831 return;
2841 if (s->minor < 0) 2832 if (s->minor < COMEDI_NUM_BOARD_MINORS ||
2833 s->minor >= COMEDI_NUM_MINORS)
2842 return; 2834 return;
2843 2835
2844 BUG_ON(s->minor >= COMEDI_NUM_MINORS);
2845 BUG_ON(s->minor < COMEDI_NUM_BOARD_MINORS);
2846
2847 i = s->minor - COMEDI_NUM_BOARD_MINORS; 2836 i = s->minor - COMEDI_NUM_BOARD_MINORS;
2848 mutex_lock(&comedi_subdevice_minor_table_lock); 2837 mutex_lock(&comedi_subdevice_minor_table_lock);
2849 if (s == comedi_subdevice_minor_table[i]) 2838 if (s == comedi_subdevice_minor_table[i])
@@ -2857,10 +2846,13 @@ void comedi_free_subdevice_minor(struct comedi_subdevice *s)
2857 2846
2858static void comedi_cleanup_board_minors(void) 2847static void comedi_cleanup_board_minors(void)
2859{ 2848{
2849 struct comedi_device *dev;
2860 unsigned i; 2850 unsigned i;
2861 2851
2862 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) 2852 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
2863 comedi_free_board_minor(i); 2853 dev = comedi_clear_board_minor(i);
2854 comedi_free_board_dev(dev);
2855 }
2864} 2856}
2865 2857
2866static int __init comedi_init(void) 2858static int __init comedi_init(void)
@@ -2932,14 +2924,7 @@ module_init(comedi_init);
2932 2924
2933static void __exit comedi_cleanup(void) 2925static void __exit comedi_cleanup(void)
2934{ 2926{
2935 int i;
2936
2937 comedi_cleanup_board_minors(); 2927 comedi_cleanup_board_minors();
2938 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; ++i)
2939 BUG_ON(comedi_board_minor_table[i]);
2940 for (i = 0; i < COMEDI_NUM_SUBDEVICE_MINORS; ++i)
2941 BUG_ON(comedi_subdevice_minor_table[i]);
2942
2943 class_destroy(comedi_class); 2928 class_destroy(comedi_class);
2944 cdev_del(&comedi_cdev); 2929 cdev_del(&comedi_cdev);
2945 unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS); 2930 unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS);
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index ed0b60c925de..b03bc6639f79 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -820,7 +820,7 @@ int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it)
820 "driver '%s' does not support attach using comedi_config\n", 820 "driver '%s' does not support attach using comedi_config\n",
821 driv->driver_name); 821 driv->driver_name);
822 module_put(driv->module); 822 module_put(driv->module);
823 ret = -ENOSYS; 823 ret = -EIO;
824 goto out; 824 goto out;
825 } 825 }
826 dev->driver = driv; 826 dev->driver = driv;
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c
index fa99c8ca4f95..f0c0d58383ca 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c
@@ -1,22 +1,3 @@
1/* Digital Input IRQ Function Selection */
2#define APCI1564_DI_INT_OR (0 << 1)
3#define APCI1564_DI_INT_AND (1 << 1)
4
5/* Digital Input Interrupt Enable Disable. */
6#define APCI1564_DI_INT_ENABLE 0x4
7#define APCI1564_DI_INT_DISABLE 0xfffffffb
8
9/* Digital Output Interrupt Enable Disable. */
10#define APCI1564_DO_VCC_INT_ENABLE 0x1
11#define APCI1564_DO_VCC_INT_DISABLE 0xfffffffe
12#define APCI1564_DO_CC_INT_ENABLE 0x2
13#define APCI1564_DO_CC_INT_DISABLE 0xfffffffd
14
15/* TIMER COUNTER WATCHDOG DEFINES */
16#define ADDIDATA_TIMER 0
17#define ADDIDATA_COUNTER 1
18#define ADDIDATA_WATCHDOG 2
19
20static int apci1564_timer_insn_config(struct comedi_device *dev, 1static int apci1564_timer_insn_config(struct comedi_device *dev,
21 struct comedi_subdevice *s, 2 struct comedi_subdevice *s,
22 struct comedi_insn *insn, 3 struct comedi_insn *insn,
@@ -27,15 +8,16 @@ static int apci1564_timer_insn_config(struct comedi_device *dev,
27 8
28 devpriv->tsk_current = current; 9 devpriv->tsk_current = current;
29 10
30 /* First Stop The Timer */ 11 /* Stop the timer */
31 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG); 12 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG);
32 ctrl &= 0xfffff9fe; 13 ctrl &= ~(ADDI_TCW_CTRL_GATE | ADDI_TCW_CTRL_TRIG |
33 /* Stop The Timer */ 14 ADDI_TCW_CTRL_ENA);
34 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG); 15 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG);
35 16
36 if (data[1] == 1) { 17 if (data[1] == 1) {
37 /* Enable timer int & disable all the other int sources */ 18 /* Enable timer int & disable all the other int sources */
38 outl(0x02, devpriv->timer + ADDI_TCW_CTRL_REG); 19 outl(ADDI_TCW_CTRL_IRQ_ENA,
20 devpriv->timer + ADDI_TCW_CTRL_REG);
39 outl(0x0, dev->iobase + APCI1564_DI_IRQ_REG); 21 outl(0x0, dev->iobase + APCI1564_DI_IRQ_REG);
40 outl(0x0, dev->iobase + APCI1564_DO_IRQ_REG); 22 outl(0x0, dev->iobase + APCI1564_DO_IRQ_REG);
41 outl(0x0, dev->iobase + APCI1564_WDOG_IRQ_REG); 23 outl(0x0, dev->iobase + APCI1564_WDOG_IRQ_REG);
@@ -59,9 +41,11 @@ static int apci1564_timer_insn_config(struct comedi_device *dev,
59 outl(data[3], devpriv->timer + ADDI_TCW_RELOAD_REG); 41 outl(data[3], devpriv->timer + ADDI_TCW_RELOAD_REG);
60 42
61 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG); 43 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG);
62 ctrl &= 0xfff719e2; 44 ctrl &= ~(ADDI_TCW_CTRL_CNTR_ENA | ADDI_TCW_CTRL_MODE_MASK |
63 ctrl |= (2 << 13) | 0x10; 45 ADDI_TCW_CTRL_GATE | ADDI_TCW_CTRL_TRIG |
64 /* mode 2 */ 46 ADDI_TCW_CTRL_TIMER_ENA | ADDI_TCW_CTRL_RESET_ENA |
47 ADDI_TCW_CTRL_WARN_ENA | ADDI_TCW_CTRL_ENA);
48 ctrl |= ADDI_TCW_CTRL_MODE(2) | ADDI_TCW_CTRL_TIMER_ENA;
65 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG); 49 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG);
66 50
67 return insn->n; 51 return insn->n;
@@ -76,13 +60,13 @@ static int apci1564_timer_insn_write(struct comedi_device *dev,
76 unsigned int ctrl; 60 unsigned int ctrl;
77 61
78 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG); 62 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG);
63 ctrl &= ~(ADDI_TCW_CTRL_GATE | ADDI_TCW_CTRL_TRIG);
79 switch (data[1]) { 64 switch (data[1]) {
80 case 0: /* Stop The Timer */ 65 case 0: /* Stop The Timer */
81 ctrl &= 0xfffff9fe; 66 ctrl &= ~ADDI_TCW_CTRL_ENA;
82 break; 67 break;
83 case 1: /* Enable the Timer */ 68 case 1: /* Enable the Timer */
84 ctrl &= 0xfffff9ff; 69 ctrl |= ADDI_TCW_CTRL_ENA;
85 ctrl |= 0x1;
86 break; 70 break;
87 } 71 }
88 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG); 72 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG);
@@ -98,7 +82,8 @@ static int apci1564_timer_insn_read(struct comedi_device *dev,
98 struct apci1564_private *devpriv = dev->private; 82 struct apci1564_private *devpriv = dev->private;
99 83
100 /* Stores the status of the Timer */ 84 /* Stores the status of the Timer */
101 data[0] = inl(devpriv->timer + ADDI_TCW_STATUS_REG) & 0x1; 85 data[0] = inl(devpriv->timer + ADDI_TCW_STATUS_REG) &
86 ADDI_TCW_STATUS_OVERFLOW;
102 87
103 /* Stores the Actual value of the Timer */ 88 /* Stores the Actual value of the Timer */
104 data[1] = inl(devpriv->timer + ADDI_TCW_VAL_REG); 89 data[1] = inl(devpriv->timer + ADDI_TCW_VAL_REG);
@@ -118,35 +103,34 @@ static int apci1564_counter_insn_config(struct comedi_device *dev,
118 103
119 devpriv->tsk_current = current; 104 devpriv->tsk_current = current;
120 105
121 /* First Stop The Counter */
122 ctrl = inl(iobase + ADDI_TCW_CTRL_REG);
123 ctrl &= 0xfffff9fe;
124 /* Stop The Timer */ 106 /* Stop The Timer */
107 ctrl = inl(iobase + ADDI_TCW_CTRL_REG);
108 ctrl &= ~(ADDI_TCW_CTRL_GATE | ADDI_TCW_CTRL_TRIG |
109 ADDI_TCW_CTRL_ENA);
125 outl(ctrl, iobase + ADDI_TCW_CTRL_REG); 110 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
126 111
127 /* Set the reload value */ 112 /* Set the reload value */
128 outl(data[3], iobase + ADDI_TCW_RELOAD_REG); 113 outl(data[3], iobase + ADDI_TCW_RELOAD_REG);
129 114
130 /* Set the mode : */ 115 /* Set the mode */
131 /* - Disable the hardware */ 116 ctrl &= ~(ADDI_TCW_CTRL_EXT_CLK_MASK | ADDI_TCW_CTRL_MODE_MASK |
132 /* - Disable the counter mode */ 117 ADDI_TCW_CTRL_TIMER_ENA | ADDI_TCW_CTRL_RESET_ENA |
133 /* - Disable the warning */ 118 ADDI_TCW_CTRL_WARN_ENA);
134 /* - Disable the reset */ 119 ctrl |= ADDI_TCW_CTRL_CNTR_ENA | ADDI_TCW_CTRL_MODE(data[4]);
135 /* - Disable the timer mode */
136 /* - Enable the counter mode */
137
138 ctrl &= 0xfffc19e2;
139 ctrl |= 0x80000 | (data[4] << 16);
140 outl(ctrl, iobase + ADDI_TCW_CTRL_REG); 120 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
141 121
142 /* Enable or Disable Interrupt */ 122 /* Enable or Disable Interrupt */
143 ctrl &= 0xfffff9fd; 123 if (data[1])
144 ctrl |= (data[1] << 1); 124 ctrl |= ADDI_TCW_CTRL_IRQ_ENA;
125 else
126 ctrl &= ~ADDI_TCW_CTRL_IRQ_ENA;
145 outl(ctrl, iobase + ADDI_TCW_CTRL_REG); 127 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
146 128
147 /* Set the Up/Down selection */ 129 /* Set the Up/Down selection */
148 ctrl &= 0xfffbf9ff; 130 if (data[6])
149 ctrl |= (data[6] << 18); 131 ctrl |= ADDI_TCW_CTRL_CNT_UP;
132 else
133 ctrl &= ~ADDI_TCW_CTRL_CNT_UP;
150 outl(ctrl, iobase + ADDI_TCW_CTRL_REG); 134 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
151 135
152 return insn->n; 136 return insn->n;
@@ -163,17 +147,16 @@ static int apci1564_counter_insn_write(struct comedi_device *dev,
163 unsigned int ctrl; 147 unsigned int ctrl;
164 148
165 ctrl = inl(iobase + ADDI_TCW_CTRL_REG); 149 ctrl = inl(iobase + ADDI_TCW_CTRL_REG);
150 ctrl &= ~(ADDI_TCW_CTRL_GATE | ADDI_TCW_CTRL_TRIG);
166 switch (data[1]) { 151 switch (data[1]) {
167 case 0: /* Stops the Counter subdevice */ 152 case 0: /* Stops the Counter subdevice */
168 ctrl = 0; 153 ctrl = 0;
169 break; 154 break;
170 case 1: /* Start the Counter subdevice */ 155 case 1: /* Start the Counter subdevice */
171 ctrl &= 0xfffff9ff; 156 ctrl |= ADDI_TCW_CTRL_ENA;
172 ctrl |= 0x1;
173 break; 157 break;
174 case 2: /* Clears the Counter subdevice */ 158 case 2: /* Clears the Counter subdevice */
175 ctrl &= 0xfffff9ff; 159 ctrl |= ADDI_TCW_CTRL_GATE;
176 ctrl |= 0x400;
177 break; 160 break;
178 } 161 }
179 outl(ctrl, iobase + ADDI_TCW_CTRL_REG); 162 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
@@ -195,10 +178,10 @@ static int apci1564_counter_insn_read(struct comedi_device *dev,
195 data[0] = inl(iobase + ADDI_TCW_VAL_REG); 178 data[0] = inl(iobase + ADDI_TCW_VAL_REG);
196 179
197 status = inl(iobase + ADDI_TCW_STATUS_REG); 180 status = inl(iobase + ADDI_TCW_STATUS_REG);
198 data[1] = (status >> 1) & 1; /* software trigger status */ 181 data[1] = (status & ADDI_TCW_STATUS_SOFT_TRIG) ? 1 : 0;
199 data[2] = (status >> 2) & 1; /* hardware trigger status */ 182 data[2] = (status & ADDI_TCW_STATUS_HARDWARE_TRIG) ? 1 : 0;
200 data[3] = (status >> 3) & 1; /* software clear status */ 183 data[3] = (status & ADDI_TCW_STATUS_SOFT_CLR) ? 1 : 0;
201 data[4] = (status >> 0) & 1; /* overflow status */ 184 data[4] = (status & ADDI_TCW_STATUS_OVERFLOW) ? 1 : 0;
202 185
203 return insn->n; 186 return insn->n;
204} 187}
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c
index 1f2f78186d58..375707497896 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c
@@ -22,54 +22,50 @@ static int apci3501_config_insn_timer(struct comedi_device *dev,
22 unsigned int *data) 22 unsigned int *data)
23{ 23{
24 struct apci3501_private *devpriv = dev->private; 24 struct apci3501_private *devpriv = dev->private;
25 unsigned int ul_Command1 = 0; 25 unsigned int ctrl;
26
27 if (data[0] != ADDIDATA_WATCHDOG &&
28 data[0] != ADDIDATA_TIMER)
29 return -EINVAL;
26 30
27 devpriv->tsk_Current = current; 31 devpriv->tsk_Current = current;
28 if (data[0] == ADDIDATA_WATCHDOG) {
29
30 devpriv->b_TimerSelectMode = ADDIDATA_WATCHDOG;
31 /* Disable the watchdog */
32 outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG);
33
34 if (data[1] == 1) {
35 /* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */
36 outl(0x02, dev->iobase + APCI3501_TIMER_CTRL_REG);
37 } else {
38 /* disable Timer interrupt */
39 outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG);
40 }
41 32
42 outl(data[2], dev->iobase + APCI3501_TIMER_TIMEBASE_REG); 33 devpriv->timer_mode = data[0];
43 outl(data[3], dev->iobase + APCI3501_TIMER_RELOAD_REG);
44 34
45 /* Set the mode (e2->e0) */ 35 /* first, disable the watchdog or stop the timer */
46 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG) | 0xFFF819E0UL; 36 if (devpriv->timer_mode == ADDIDATA_WATCHDOG) {
47 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); 37 ctrl = 0;
38 } else {
39 ctrl = inl(devpriv->tcw + ADDI_TCW_CTRL_REG);
40 ctrl &= ~(ADDI_TCW_CTRL_GATE | ADDI_TCW_CTRL_TRIG |
41 ADDI_TCW_CTRL_ENA);
48 } 42 }
49 43 outl(ctrl, devpriv->tcw + ADDI_TCW_CTRL_REG);
50 else if (data[0] == ADDIDATA_TIMER) { 44
51 /* First Stop The Timer */ 45 /* enable/disable the timer interrupt */
52 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); 46 ctrl = (data[1] == 1) ? ADDI_TCW_CTRL_IRQ_ENA : 0;
53 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; 47 outl(ctrl, devpriv->tcw + ADDI_TCW_CTRL_REG);
54 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); 48
55 devpriv->b_TimerSelectMode = ADDIDATA_TIMER; 49 outl(data[2], devpriv->tcw + ADDI_TCW_TIMEBASE_REG);
56 if (data[1] == 1) { 50 outl(data[3], devpriv->tcw + ADDI_TCW_RELOAD_REG);
57 /* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */ 51
58 outl(0x02, dev->iobase + APCI3501_TIMER_CTRL_REG); 52 ctrl = inl(devpriv->tcw + ADDI_TCW_CTRL_REG);
59 } else { 53 if (devpriv->timer_mode == ADDIDATA_WATCHDOG) {
60 /* disable Timer interrupt */ 54 /* Set the mode (e2->e0) NOTE: this doesn't look correct */
61 outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG); 55 ctrl |= ~(ADDI_TCW_CTRL_CNT_UP | ADDI_TCW_CTRL_EXT_CLK_MASK |
62 } 56 ADDI_TCW_CTRL_MODE_MASK | ADDI_TCW_CTRL_GATE |
63 57 ADDI_TCW_CTRL_TRIG | ADDI_TCW_CTRL_TIMER_ENA |
64 outl(data[2], dev->iobase + APCI3501_TIMER_TIMEBASE_REG); 58 ADDI_TCW_CTRL_RESET_ENA | ADDI_TCW_CTRL_WARN_ENA |
65 outl(data[3], dev->iobase + APCI3501_TIMER_RELOAD_REG); 59 ADDI_TCW_CTRL_IRQ_ENA | ADDI_TCW_CTRL_ENA);
66 60 } else {
67 /* mode 2 */ 61 /* mode 2 */
68 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); 62 ctrl &= ~(ADDI_TCW_CTRL_CNTR_ENA | ADDI_TCW_CTRL_MODE_MASK |
69 ul_Command1 = 63 ADDI_TCW_CTRL_GATE | ADDI_TCW_CTRL_TRIG |
70 (ul_Command1 & 0xFFF719E2UL) | 2UL << 13UL | 0x10UL; 64 ADDI_TCW_CTRL_TIMER_ENA | ADDI_TCW_CTRL_RESET_ENA |
71 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); 65 ADDI_TCW_CTRL_WARN_ENA | ADDI_TCW_CTRL_ENA);
66 ctrl |= ADDI_TCW_CTRL_MODE(2) | ADDI_TCW_CTRL_TIMER_ENA;
72 } 67 }
68 outl(ctrl, devpriv->tcw + ADDI_TCW_CTRL_REG);
73 69
74 return insn->n; 70 return insn->n;
75} 71}
@@ -92,49 +88,27 @@ static int apci3501_write_insn_timer(struct comedi_device *dev,
92 unsigned int *data) 88 unsigned int *data)
93{ 89{
94 struct apci3501_private *devpriv = dev->private; 90 struct apci3501_private *devpriv = dev->private;
95 unsigned int ul_Command1 = 0; 91 unsigned int ctrl;
96 92
97 if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) { 93 if (devpriv->timer_mode == ADDIDATA_WATCHDOG ||
98 94 devpriv->timer_mode == ADDIDATA_TIMER) {
99 if (data[1] == 1) { 95 ctrl = inl(devpriv->tcw + ADDI_TCW_CTRL_REG);
100 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); 96 ctrl &= ~(ADDI_TCW_CTRL_GATE | ADDI_TCW_CTRL_TRIG);
101 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL; 97
102 /* Enable the Watchdog */ 98 if (data[1] == 1) { /* enable */
103 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); 99 ctrl |= ADDI_TCW_CTRL_ENA;
104 } else if (data[1] == 0) { /* Stop The Watchdog */ 100 } else if (data[1] == 0) { /* stop */
105 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); 101 if (devpriv->timer_mode == ADDIDATA_WATCHDOG)
106 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; 102 ctrl = 0;
107 outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG); 103 else
108 } else if (data[1] == 2) { 104 ctrl &= ~ADDI_TCW_CTRL_ENA;
109 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); 105 } else if (data[1] == 2) { /* trigger */
110 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL; 106 ctrl |= ADDI_TCW_CTRL_TRIG;
111 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
112 }
113 }
114
115 if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) {
116 if (data[1] == 1) {
117
118 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
119 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL;
120 /* Enable the Timer */
121 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
122 } else if (data[1] == 0) {
123 /* Stop The Timer */
124 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
125 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL;
126 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
127 }
128
129 else if (data[1] == 2) {
130 /* Trigger the Timer */
131 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
132 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL;
133 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
134 } 107 }
108 outl(ctrl, devpriv->tcw + ADDI_TCW_CTRL_REG);
135 } 109 }
136 110
137 inl(dev->iobase + APCI3501_TIMER_STATUS_REG); 111 inl(devpriv->tcw + ADDI_TCW_STATUS_REG);
138 return insn->n; 112 return insn->n;
139} 113}
140 114
@@ -155,19 +129,13 @@ static int apci3501_read_insn_timer(struct comedi_device *dev,
155{ 129{
156 struct apci3501_private *devpriv = dev->private; 130 struct apci3501_private *devpriv = dev->private;
157 131
158 if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) { 132 if (devpriv->timer_mode != ADDIDATA_TIMER &&
159 data[0] = inl(dev->iobase + APCI3501_TIMER_STATUS_REG) & 0x1; 133 devpriv->timer_mode != ADDIDATA_WATCHDOG)
160 data[1] = inl(dev->iobase + APCI3501_TIMER_SYNC_REG); 134 return -EINVAL;
161 }
162 135
163 else if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) { 136 data[0] = inl(devpriv->tcw + ADDI_TCW_STATUS_REG) &
164 data[0] = inl(dev->iobase + APCI3501_TIMER_STATUS_REG) & 0x1; 137 ADDI_TCW_STATUS_OVERFLOW;
165 data[1] = inl(dev->iobase + APCI3501_TIMER_SYNC_REG); 138 data[1] = inl(devpriv->tcw + ADDI_TCW_VAL_REG);
166 }
167 139
168 else if ((devpriv->b_TimerSelectMode != ADDIDATA_TIMER)
169 && (devpriv->b_TimerSelectMode != ADDIDATA_WATCHDOG)) {
170 dev_err(dev->class_dev, "Invalid subdevice.\n");
171 }
172 return insn->n; 140 return insn->n;
173} 141}
diff --git a/drivers/staging/comedi/drivers/addi_apci_1564.c b/drivers/staging/comedi/drivers/addi_apci_1564.c
index 33e58b9a21b2..f1ccfbd4c578 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1564.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1564.c
@@ -44,12 +44,12 @@
44 * 0x48 - 0x64 Timer 12-Bit 44 * 0x48 - 0x64 Timer 12-Bit
45 */ 45 */
46#define APCI1564_EEPROM_REG 0x00 46#define APCI1564_EEPROM_REG 0x00
47#define APCI1564_EEPROM_VCC_STATUS (1 << 8) 47#define APCI1564_EEPROM_VCC_STATUS BIT(8)
48#define APCI1564_EEPROM_TO_REV(x) (((x) >> 4) & 0xf) 48#define APCI1564_EEPROM_TO_REV(x) (((x) >> 4) & 0xf)
49#define APCI1564_EEPROM_DI (1 << 3) 49#define APCI1564_EEPROM_DI BIT(3)
50#define APCI1564_EEPROM_DO (1 << 2) 50#define APCI1564_EEPROM_DO BIT(2)
51#define APCI1564_EEPROM_CS (1 << 1) 51#define APCI1564_EEPROM_CS BIT(1)
52#define APCI1564_EEPROM_CLK (1 << 0) 52#define APCI1564_EEPROM_CLK BIT(0)
53#define APCI1564_REV1_TIMER_IOBASE 0x04 53#define APCI1564_REV1_TIMER_IOBASE 0x04
54#define APCI1564_REV2_MAIN_IOBASE 0x04 54#define APCI1564_REV2_MAIN_IOBASE 0x04
55#define APCI1564_REV2_TIMER_IOBASE 0x48 55#define APCI1564_REV2_TIMER_IOBASE 0x48
@@ -79,10 +79,17 @@
79#define APCI1564_DI_INT_MODE2_REG 0x08 79#define APCI1564_DI_INT_MODE2_REG 0x08
80#define APCI1564_DI_INT_STATUS_REG 0x0c 80#define APCI1564_DI_INT_STATUS_REG 0x0c
81#define APCI1564_DI_IRQ_REG 0x10 81#define APCI1564_DI_IRQ_REG 0x10
82#define APCI1564_DI_IRQ_ENA BIT(2)
83#define APCI1564_DI_IRQ_MODE BIT(1) /* 1=AND, 0=OR */
82#define APCI1564_DO_REG 0x14 84#define APCI1564_DO_REG 0x14
83#define APCI1564_DO_INT_CTRL_REG 0x18 85#define APCI1564_DO_INT_CTRL_REG 0x18
86#define APCI1564_DO_INT_CTRL_CC_INT_ENA BIT(1)
87#define APCI1564_DO_INT_CTRL_VCC_INT_ENA BIT(0)
84#define APCI1564_DO_INT_STATUS_REG 0x1c 88#define APCI1564_DO_INT_STATUS_REG 0x1c
89#define APCI1564_DO_INT_STATUS_CC BIT(1)
90#define APCI1564_DO_INT_STATUS_VCC BIT(0)
85#define APCI1564_DO_IRQ_REG 0x20 91#define APCI1564_DO_IRQ_REG 0x20
92#define APCI1564_DO_IRQ_INTR BIT(0)
86#define APCI1564_WDOG_REG 0x24 93#define APCI1564_WDOG_REG 0x24
87#define APCI1564_WDOG_RELOAD_REG 0x28 94#define APCI1564_WDOG_RELOAD_REG 0x28
88#define APCI1564_WDOG_TIMEBASE_REG 0x2c 95#define APCI1564_WDOG_TIMEBASE_REG 0x2c
@@ -159,9 +166,9 @@ static irqreturn_t apci1564_interrupt(int irq, void *d)
159 unsigned int chan; 166 unsigned int chan;
160 167
161 status = inl(dev->iobase + APCI1564_DI_IRQ_REG); 168 status = inl(dev->iobase + APCI1564_DI_IRQ_REG);
162 if (status & APCI1564_DI_INT_ENABLE) { 169 if (status & APCI1564_DI_IRQ_ENA) {
163 /* disable the interrupt */ 170 /* disable the interrupt */
164 outl(status & APCI1564_DI_INT_DISABLE, 171 outl(status & ~APCI1564_DI_IRQ_ENA,
165 dev->iobase + APCI1564_DI_IRQ_REG); 172 dev->iobase + APCI1564_DI_IRQ_REG);
166 173
167 s->state = inl(dev->iobase + APCI1564_DI_INT_STATUS_REG) & 174 s->state = inl(dev->iobase + APCI1564_DI_INT_STATUS_REG) &
@@ -300,11 +307,9 @@ static int apci1564_cos_insn_config(struct comedi_device *dev,
300 outl(0x0, dev->iobase + APCI1564_DI_INT_MODE2_REG); 307 outl(0x0, dev->iobase + APCI1564_DI_INT_MODE2_REG);
301 break; 308 break;
302 case COMEDI_DIGITAL_TRIG_ENABLE_EDGES: 309 case COMEDI_DIGITAL_TRIG_ENABLE_EDGES:
303 if (devpriv->ctrl != (APCI1564_DI_INT_ENABLE | 310 if (devpriv->ctrl != APCI1564_DI_IRQ_ENA) {
304 APCI1564_DI_INT_OR)) {
305 /* switching to 'OR' mode */ 311 /* switching to 'OR' mode */
306 devpriv->ctrl = APCI1564_DI_INT_ENABLE | 312 devpriv->ctrl = APCI1564_DI_IRQ_ENA;
307 APCI1564_DI_INT_OR;
308 /* wipe old channels */ 313 /* wipe old channels */
309 devpriv->mode1 = 0; 314 devpriv->mode1 = 0;
310 devpriv->mode2 = 0; 315 devpriv->mode2 = 0;
@@ -318,11 +323,11 @@ static int apci1564_cos_insn_config(struct comedi_device *dev,
318 devpriv->mode2 |= data[5] << shift; 323 devpriv->mode2 |= data[5] << shift;
319 break; 324 break;
320 case COMEDI_DIGITAL_TRIG_ENABLE_LEVELS: 325 case COMEDI_DIGITAL_TRIG_ENABLE_LEVELS:
321 if (devpriv->ctrl != (APCI1564_DI_INT_ENABLE | 326 if (devpriv->ctrl != (APCI1564_DI_IRQ_ENA |
322 APCI1564_DI_INT_AND)) { 327 APCI1564_DI_IRQ_MODE)) {
323 /* switching to 'AND' mode */ 328 /* switching to 'AND' mode */
324 devpriv->ctrl = APCI1564_DI_INT_ENABLE | 329 devpriv->ctrl = APCI1564_DI_IRQ_ENA |
325 APCI1564_DI_INT_AND; 330 APCI1564_DI_IRQ_MODE;
326 /* wipe old channels */ 331 /* wipe old channels */
327 devpriv->mode1 = 0; 332 devpriv->mode1 = 0;
328 devpriv->mode2 = 0; 333 devpriv->mode2 = 0;
diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c
index 73786a3f3df9..40ff91411139 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3501.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3501.c
@@ -27,27 +27,21 @@
27#include <linux/sched.h> 27#include <linux/sched.h>
28 28
29#include "../comedi_pci.h" 29#include "../comedi_pci.h"
30#include "addi_tcw.h"
30#include "amcc_s5933.h" 31#include "amcc_s5933.h"
31 32
32/* 33/*
33 * PCI bar 1 register I/O map 34 * PCI bar 1 register I/O map
34 */ 35 */
35#define APCI3501_AO_CTRL_STATUS_REG 0x00 36#define APCI3501_AO_CTRL_STATUS_REG 0x00
36#define APCI3501_AO_CTRL_BIPOLAR (1 << 0) 37#define APCI3501_AO_CTRL_BIPOLAR BIT(0)
37#define APCI3501_AO_STATUS_READY (1 << 8) 38#define APCI3501_AO_STATUS_READY BIT(8)
38#define APCI3501_AO_DATA_REG 0x04 39#define APCI3501_AO_DATA_REG 0x04
39#define APCI3501_AO_DATA_CHAN(x) ((x) << 0) 40#define APCI3501_AO_DATA_CHAN(x) ((x) << 0)
40#define APCI3501_AO_DATA_VAL(x) ((x) << 8) 41#define APCI3501_AO_DATA_VAL(x) ((x) << 8)
41#define APCI3501_AO_DATA_BIPOLAR (1 << 31) 42#define APCI3501_AO_DATA_BIPOLAR BIT(31)
42#define APCI3501_AO_TRIG_SCS_REG 0x08 43#define APCI3501_AO_TRIG_SCS_REG 0x08
43#define APCI3501_TIMER_SYNC_REG 0x20 44#define APCI3501_TIMER_BASE 0x20
44#define APCI3501_TIMER_RELOAD_REG 0x24
45#define APCI3501_TIMER_TIMEBASE_REG 0x28
46#define APCI3501_TIMER_CTRL_REG 0x2c
47#define APCI3501_TIMER_STATUS_REG 0x30
48#define APCI3501_TIMER_IRQ_REG 0x34
49#define APCI3501_TIMER_WARN_RELOAD_REG 0x38
50#define APCI3501_TIMER_WARN_TIMEBASE_REG 0x3c
51#define APCI3501_DO_REG 0x40 45#define APCI3501_DO_REG 0x40
52#define APCI3501_DI_REG 0x50 46#define APCI3501_DI_REG 0x50
53 47
@@ -72,9 +66,10 @@
72#define EEPROM_TIMER_WATCHDOG_COUNTER 10 66#define EEPROM_TIMER_WATCHDOG_COUNTER 10
73 67
74struct apci3501_private { 68struct apci3501_private {
75 int i_IobaseAmcc; 69 unsigned long amcc;
70 unsigned long tcw;
76 struct task_struct *tsk_Current; 71 struct task_struct *tsk_Current;
77 unsigned char b_TimerSelectMode; 72 unsigned char timer_mode;
78}; 73};
79 74
80static struct comedi_lrange apci3501_ao_range = { 75static struct comedi_lrange apci3501_ao_range = {
@@ -222,11 +217,10 @@ static unsigned short apci3501_eeprom_readw(unsigned long iobase,
222static int apci3501_eeprom_get_ao_n_chan(struct comedi_device *dev) 217static int apci3501_eeprom_get_ao_n_chan(struct comedi_device *dev)
223{ 218{
224 struct apci3501_private *devpriv = dev->private; 219 struct apci3501_private *devpriv = dev->private;
225 unsigned long iobase = devpriv->i_IobaseAmcc;
226 unsigned char nfuncs; 220 unsigned char nfuncs;
227 int i; 221 int i;
228 222
229 nfuncs = apci3501_eeprom_readw(iobase, 10) & 0xff; 223 nfuncs = apci3501_eeprom_readw(devpriv->amcc, 10) & 0xff;
230 224
231 /* Read functionality details */ 225 /* Read functionality details */
232 for (i = 0; i < nfuncs; i++) { 226 for (i = 0; i < nfuncs; i++) {
@@ -235,11 +229,11 @@ static int apci3501_eeprom_get_ao_n_chan(struct comedi_device *dev)
235 unsigned char func; 229 unsigned char func;
236 unsigned short val; 230 unsigned short val;
237 231
238 func = apci3501_eeprom_readw(iobase, 12 + offset) & 0x3f; 232 func = apci3501_eeprom_readw(devpriv->amcc, 12 + offset) & 0x3f;
239 addr = apci3501_eeprom_readw(iobase, 14 + offset); 233 addr = apci3501_eeprom_readw(devpriv->amcc, 14 + offset);
240 234
241 if (func == EEPROM_ANALOGOUTPUT) { 235 if (func == EEPROM_ANALOGOUTPUT) {
242 val = apci3501_eeprom_readw(iobase, addr + 10); 236 val = apci3501_eeprom_readw(devpriv->amcc, addr + 10);
243 return (val >> 4) & 0x3ff; 237 return (val >> 4) & 0x3ff;
244 } 238 }
245 } 239 }
@@ -254,7 +248,7 @@ static int apci3501_eeprom_insn_read(struct comedi_device *dev,
254 struct apci3501_private *devpriv = dev->private; 248 struct apci3501_private *devpriv = dev->private;
255 unsigned short addr = CR_CHAN(insn->chanspec); 249 unsigned short addr = CR_CHAN(insn->chanspec);
256 250
257 data[0] = apci3501_eeprom_readw(devpriv->i_IobaseAmcc, 2 * addr); 251 data[0] = apci3501_eeprom_readw(devpriv->amcc, 2 * addr);
258 252
259 return insn->n; 253 return insn->n;
260} 254}
@@ -263,26 +257,29 @@ static irqreturn_t apci3501_interrupt(int irq, void *d)
263{ 257{
264 struct comedi_device *dev = d; 258 struct comedi_device *dev = d;
265 struct apci3501_private *devpriv = dev->private; 259 struct apci3501_private *devpriv = dev->private;
266 unsigned int ui_Timer_AOWatchdog; 260 unsigned int status;
267 unsigned long ul_Command1; 261 unsigned int ctrl;
268 262
269 /* Disable Interrupt */ 263 /* Disable Interrupt */
270 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); 264 ctrl = inl(devpriv->tcw + ADDI_TCW_CTRL_REG);
271 ul_Command1 = ul_Command1 & 0xFFFFF9FDul; 265 ctrl &= ~(ADDI_TCW_CTRL_GATE | ADDI_TCW_CTRL_TRIG |
272 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); 266 ADDI_TCW_CTRL_IRQ_ENA);
267 outl(ctrl, devpriv->tcw + ADDI_TCW_CTRL_REG);
273 268
274 ui_Timer_AOWatchdog = inl(dev->iobase + APCI3501_TIMER_IRQ_REG) & 0x1; 269 status = inl(devpriv->tcw + ADDI_TCW_IRQ_REG);
275 if ((!ui_Timer_AOWatchdog)) { 270 if (!(status & ADDI_TCW_IRQ)) {
276 dev_err(dev->class_dev, "IRQ from unknown source\n"); 271 dev_err(dev->class_dev, "IRQ from unknown source\n");
277 return IRQ_NONE; 272 return IRQ_NONE;
278 } 273 }
279 274
280 /* Enable Interrupt Send a signal to from kernel to user space */ 275 /* Enable Interrupt Send a signal to from kernel to user space */
281 send_sig(SIGIO, devpriv->tsk_Current, 0); 276 send_sig(SIGIO, devpriv->tsk_Current, 0);
282 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); 277 ctrl = inl(devpriv->tcw + ADDI_TCW_CTRL_REG);
283 ul_Command1 = (ul_Command1 & 0xFFFFF9FDul) | 1 << 1; 278 ctrl &= ~(ADDI_TCW_CTRL_GATE | ADDI_TCW_CTRL_TRIG |
284 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG); 279 ADDI_TCW_CTRL_IRQ_ENA);
285 inl(dev->iobase + APCI3501_TIMER_STATUS_REG); 280 ctrl |= ADDI_TCW_CTRL_IRQ_ENA;
281 outl(ctrl, devpriv->tcw + ADDI_TCW_CTRL_REG);
282 inl(devpriv->tcw + ADDI_TCW_STATUS_REG);
286 283
287 return IRQ_HANDLED; 284 return IRQ_HANDLED;
288} 285}
@@ -334,8 +331,9 @@ static int apci3501_auto_attach(struct comedi_device *dev,
334 if (ret) 331 if (ret)
335 return ret; 332 return ret;
336 333
334 devpriv->amcc = pci_resource_start(pcidev, 0);
337 dev->iobase = pci_resource_start(pcidev, 1); 335 dev->iobase = pci_resource_start(pcidev, 1);
338 devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); 336 devpriv->tcw = dev->iobase + APCI3501_TIMER_BASE;
339 337
340 ao_n_chan = apci3501_eeprom_get_ao_n_chan(dev); 338 ao_n_chan = apci3501_eeprom_get_ao_n_chan(dev);
341 339
diff --git a/drivers/staging/comedi/drivers/addi_tcw.h b/drivers/staging/comedi/drivers/addi_tcw.h
index 8794d4cbbfb0..db6d5a4e8889 100644
--- a/drivers/staging/comedi/drivers/addi_tcw.h
+++ b/drivers/staging/comedi/drivers/addi_tcw.h
@@ -10,44 +10,51 @@
10#define ADDI_TCW_VAL_REG 0x00 10#define ADDI_TCW_VAL_REG 0x00
11 11
12#define ADDI_TCW_SYNC_REG 0x00 12#define ADDI_TCW_SYNC_REG 0x00
13#define ADDI_TCW_SYNC_CTR_TRIG (1 << 8) 13#define ADDI_TCW_SYNC_CTR_TRIG BIT(8)
14#define ADDI_TCW_SYNC_CTR_DIS (1 << 7) 14#define ADDI_TCW_SYNC_CTR_DIS BIT(7)
15#define ADDI_TCW_SYNC_CTR_ENA (1 << 6) 15#define ADDI_TCW_SYNC_CTR_ENA BIT(6)
16#define ADDI_TCW_SYNC_TIMER_TRIG (1 << 5) 16#define ADDI_TCW_SYNC_TIMER_TRIG BIT(5)
17#define ADDI_TCW_SYNC_TIMER_DIS (1 << 4) 17#define ADDI_TCW_SYNC_TIMER_DIS BIT(4)
18#define ADDI_TCW_SYNC_TIMER_ENA (1 << 3) 18#define ADDI_TCW_SYNC_TIMER_ENA BIT(3)
19#define ADDI_TCW_SYNC_WDOG_TRIG (1 << 2) 19#define ADDI_TCW_SYNC_WDOG_TRIG BIT(2)
20#define ADDI_TCW_SYNC_WDOG_DIS (1 << 1) 20#define ADDI_TCW_SYNC_WDOG_DIS BIT(1)
21#define ADDI_TCW_SYNC_WDOG_ENA (1 << 0) 21#define ADDI_TCW_SYNC_WDOG_ENA BIT(0)
22 22
23#define ADDI_TCW_RELOAD_REG 0x04 23#define ADDI_TCW_RELOAD_REG 0x04
24 24
25#define ADDI_TCW_TIMEBASE_REG 0x08 25#define ADDI_TCW_TIMEBASE_REG 0x08
26 26
27#define ADDI_TCW_CTRL_REG 0x0c 27#define ADDI_TCW_CTRL_REG 0x0c
28#define ADDI_TCW_CTRL_EXT_CLK_STATUS (1 << 21) 28#define ADDI_TCW_CTRL_EXT_CLK_STATUS BIT(21)
29#define ADDI_TCW_CTRL_CASCADE (1 << 20) 29#define ADDI_TCW_CTRL_CASCADE BIT(20)
30#define ADDI_TCW_CTRL_CNTR_ENA (1 << 19) 30#define ADDI_TCW_CTRL_CNTR_ENA BIT(19)
31#define ADDI_TCW_CTRL_CNT_UP (1 << 18) 31#define ADDI_TCW_CTRL_CNT_UP BIT(18)
32#define ADDI_TCW_CTRL_EXT_CLK(x) ((x) << 16) 32#define ADDI_TCW_CTRL_EXT_CLK(x) (((x) & 3) << 16)
33#define ADDI_TCW_CTRL_OUT(x) ((x) << 11) 33#define ADDI_TCW_CTRL_EXT_CLK_MASK ADDI_TCW_CTRL_EXT_CLK(3)
34#define ADDI_TCW_CTRL_GATE (1 << 10) 34#define ADDI_TCW_CTRL_MODE(x) (((x) & 7) << 13)
35#define ADDI_TCW_CTRL_TRIG (1 << 9) 35#define ADDI_TCW_CTRL_MODE_MASK ADDI_TCW_CTRL_MODE(7)
36#define ADDI_TCW_CTRL_EXT_GATE(x) ((x) << 7) 36#define ADDI_TCW_CTRL_OUT(x) (((x) & 3) << 11)
37#define ADDI_TCW_CTRL_EXT_TRIG(x) ((x) << 5) 37#define ADDI_TCW_CTRL_OUT_MASK ADDI_TCW_CTRL_OUT(3)
38#define ADDI_TCW_CTRL_TIMER_ENA (1 << 4) 38#define ADDI_TCW_CTRL_GATE BIT(10)
39#define ADDI_TCW_CTRL_RESET_ENA (1 << 3) 39#define ADDI_TCW_CTRL_TRIG BIT(9)
40#define ADDI_TCW_CTRL_WARN_ENA (1 << 2) 40#define ADDI_TCW_CTRL_EXT_GATE(x) (((x) & 3) << 7)
41#define ADDI_TCW_CTRL_IRQ_ENA (1 << 1) 41#define ADDI_TCW_CTRL_EXT_GATE_MASK ADDI_TCW_CTRL_EXT_GATE(3)
42#define ADDI_TCW_CTRL_ENA (1 << 0) 42#define ADDI_TCW_CTRL_EXT_TRIG(x) (((x) & 3) << 5)
43#define ADDI_TCW_CTRL_EXT_TRIG_MASK ADDI_TCW_CTRL_EXT_TRIG(3)
44#define ADDI_TCW_CTRL_TIMER_ENA BIT(4)
45#define ADDI_TCW_CTRL_RESET_ENA BIT(3)
46#define ADDI_TCW_CTRL_WARN_ENA BIT(2)
47#define ADDI_TCW_CTRL_IRQ_ENA BIT(1)
48#define ADDI_TCW_CTRL_ENA BIT(0)
43 49
44#define ADDI_TCW_STATUS_REG 0x10 50#define ADDI_TCW_STATUS_REG 0x10
45#define ADDI_TCW_STATUS_SOFT_CLR (1 << 3) 51#define ADDI_TCW_STATUS_SOFT_CLR BIT(3)
46#define ADDI_TCW_STATUS_SOFT_TRIG (1 << 1) 52#define ADDI_TCW_STATUS_HARDWARE_TRIG BIT(2)
47#define ADDI_TCW_STATUS_OVERFLOW (1 << 0) 53#define ADDI_TCW_STATUS_SOFT_TRIG BIT(1)
54#define ADDI_TCW_STATUS_OVERFLOW BIT(0)
48 55
49#define ADDI_TCW_IRQ_REG 0x14 56#define ADDI_TCW_IRQ_REG 0x14
50#define ADDI_TCW_IRQ (1 << 0) 57#define ADDI_TCW_IRQ BIT(0)
51 58
52#define ADDI_TCW_WARN_TIMEVAL_REG 0x18 59#define ADDI_TCW_WARN_TIMEVAL_REG 0x18
53 60
diff --git a/drivers/staging/comedi/drivers/adl_pci7x3x.c b/drivers/staging/comedi/drivers/adl_pci7x3x.c
index 934af3ff7897..b0fc027cf485 100644
--- a/drivers/staging/comedi/drivers/adl_pci7x3x.c
+++ b/drivers/staging/comedi/drivers/adl_pci7x3x.c
@@ -120,8 +120,20 @@ static int adl_pci7x3x_do_insn_bits(struct comedi_device *dev,
120{ 120{
121 unsigned long reg = (unsigned long)s->private; 121 unsigned long reg = (unsigned long)s->private;
122 122
123 if (comedi_dio_update_state(s, data)) 123 if (comedi_dio_update_state(s, data)) {
124 outl(s->state, dev->iobase + reg); 124 unsigned int val = s->state;
125
126 if (s->n_chan == 16) {
127 /*
128 * It seems the PCI-7230 needs the 16-bit DO state
129 * to be shifted left by 16 bits before being written
130 * to the 32-bit register. Set the value in both
131 * halves of the register to be sure.
132 */
133 val |= val << 16;
134 }
135 outl(val, dev->iobase + reg);
136 }
125 137
126 data[1] = s->state; 138 data[1] = s->state;
127 139
diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c b/drivers/staging/comedi/drivers/cb_pcimdas.c
index 4ebf5aae5019..47e38398921e 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -141,11 +141,13 @@ static const struct comedi_lrange cb_pcimdas_ai_uni_range = {
141 * jumper-settable on the board. The settings are not software-readable. 141 * jumper-settable on the board. The settings are not software-readable.
142 */ 142 */
143static const struct comedi_lrange cb_pcimdas_ao_range = { 143static const struct comedi_lrange cb_pcimdas_ao_range = {
144 4, { 144 6, {
145 BIP_RANGE(10), 145 BIP_RANGE(10),
146 BIP_RANGE(5), 146 BIP_RANGE(5),
147 UNI_RANGE(10), 147 UNI_RANGE(10),
148 UNI_RANGE(5) 148 UNI_RANGE(5),
149 RANGE_ext(-1, 1),
150 RANGE_ext(0, 1)
149 } 151 }
150}; 152};
151 153
diff --git a/drivers/staging/comedi/drivers/dac02.c b/drivers/staging/comedi/drivers/dac02.c
index a6798ad8fa7f..a562df498b01 100644
--- a/drivers/staging/comedi/drivers/dac02.c
+++ b/drivers/staging/comedi/drivers/dac02.c
@@ -130,11 +130,7 @@ static int dac02_attach(struct comedi_device *dev, struct comedi_devconfig *it)
130 s->range_table = &das02_ao_ranges; 130 s->range_table = &das02_ao_ranges;
131 s->insn_write = dac02_ao_insn_write; 131 s->insn_write = dac02_ao_insn_write;
132 132
133 ret = comedi_alloc_subdev_readback(s); 133 return comedi_alloc_subdev_readback(s);
134 if (ret)
135 return ret;
136
137 return 0;
138} 134}
139 135
140static struct comedi_driver dac02_driver = { 136static struct comedi_driver dac02_driver = {
diff --git a/drivers/staging/comedi/drivers/das08_cs.c b/drivers/staging/comedi/drivers/das08_cs.c
index 93fab6890161..9c02b17a2834 100644
--- a/drivers/staging/comedi/drivers/das08_cs.c
+++ b/drivers/staging/comedi/drivers/das08_cs.c
@@ -108,7 +108,7 @@ static struct pcmcia_driver das08_cs_driver = {
108}; 108};
109module_comedi_pcmcia_driver(driver_das08_cs, das08_cs_driver); 109module_comedi_pcmcia_driver(driver_das08_cs, das08_cs_driver);
110 110
111MODULE_AUTHOR("David A. Schleef <ds@schleef.org>, " 111MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
112 "Frank Mori Hess <fmhess@users.sourceforge.net>"); 112MODULE_AUTHOR("Frank Mori Hess <fmhess@users.sourceforge.net>");
113MODULE_DESCRIPTION("Comedi driver for ComputerBoards DAS-08 PCMCIA boards"); 113MODULE_DESCRIPTION("Comedi driver for ComputerBoards DAS-08 PCMCIA boards");
114MODULE_LICENSE("GPL"); 114MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/das16.c b/drivers/staging/comedi/drivers/das16.c
index d7cf4b153f7c..056bca9c67d5 100644
--- a/drivers/staging/comedi/drivers/das16.c
+++ b/drivers/staging/comedi/drivers/das16.c
@@ -1032,8 +1032,7 @@ static int das16_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1032 1032
1033 /* check that clock setting is valid */ 1033 /* check that clock setting is valid */
1034 if (it->options[3]) { 1034 if (it->options[3]) {
1035 if (it->options[3] != 0 && 1035 if (it->options[3] != 1 && it->options[3] != 10) {
1036 it->options[3] != 1 && it->options[3] != 10) {
1037 dev_err(dev->class_dev, 1036 dev_err(dev->class_dev,
1038 "Invalid option. Master clock must be set to 1 or 10 (MHz)\n"); 1037 "Invalid option. Master clock must be set to 1 or 10 (MHz)\n");
1039 return -EINVAL; 1038 return -EINVAL;
diff --git a/drivers/staging/comedi/drivers/das16m1.c b/drivers/staging/comedi/drivers/das16m1.c
index a18a8878bdb8..3a37373fbb6f 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -69,18 +69,18 @@ irq can be omitted, although the cmd interface will not work without it.
69 69
70 "cio-das16/m1" 70 "cio-das16/m1"
71 71
72 0 a/d bits 0-3, mux start 12 bit 72 0 a/d bits 0-3, mux start 12 bit
73 1 a/d bits 4-11 unused 73 1 a/d bits 4-11 unused
74 2 status control 74 2 status control
75 3 di 4 bit do 4 bit 75 3 di 4 bit do 4 bit
76 4 unused clear interrupt 76 4 unused clear interrupt
77 5 interrupt, pacer 77 5 interrupt, pacer
78 6 channel/gain queue address 78 6 channel/gain queue address
79 7 channel/gain queue data 79 7 channel/gain queue data
80 89ab 8254 80 89ab 8254
81 cdef 8254 81 cdef 8254
82 400 8255 82 400 8255
83 404-407 8254 83 404-407 8254
84 84
85*/ 85*/
86 86
@@ -411,15 +411,18 @@ static void das16m1_handler(struct comedi_device *dev, unsigned int status)
411 hw_counter = comedi_8254_read(devpriv->counter, 1); 411 hw_counter = comedi_8254_read(devpriv->counter, 1);
412 /* make sure hardware counter reading is not bogus due to initial value 412 /* make sure hardware counter reading is not bogus due to initial value
413 * not having been loaded yet */ 413 * not having been loaded yet */
414 if (devpriv->adc_count == 0 && hw_counter == devpriv->initial_hw_count) { 414 if (devpriv->adc_count == 0 &&
415 hw_counter == devpriv->initial_hw_count) {
415 num_samples = 0; 416 num_samples = 0;
416 } else { 417 } else {
417 /* The calculation of num_samples looks odd, but it uses the following facts. 418 /* The calculation of num_samples looks odd, but it uses the
418 * 16 bit hardware counter is initialized with value of zero (which really 419 * following facts. 16 bit hardware counter is initialized with
419 * means 0x1000). The counter decrements by one on each conversion 420 * value of zero (which really means 0x1000). The counter
420 * (when the counter decrements from zero it goes to 0xffff). num_samples 421 * decrements by one on each conversion (when the counter
421 * is a 16 bit variable, so it will roll over in a similar fashion to the 422 * decrements from zero it goes to 0xffff). num_samples is a
422 * hardware counter. Work it out, and this is what you get. */ 423 * 16 bit variable, so it will roll over in a similar fashion
424 * to the hardware counter. Work it out, and this is what you
425 * get. */
423 num_samples = -hw_counter - devpriv->adc_count; 426 num_samples = -hw_counter - devpriv->adc_count;
424 } 427 }
425 /* check if we only need some of the points */ 428 /* check if we only need some of the points */
diff --git a/drivers/staging/comedi/drivers/dmm32at.c b/drivers/staging/comedi/drivers/dmm32at.c
index bb2883c83afa..958c0d4aae5c 100644
--- a/drivers/staging/comedi/drivers/dmm32at.c
+++ b/drivers/staging/comedi/drivers/dmm32at.c
@@ -607,11 +607,7 @@ static int dmm32at_attach(struct comedi_device *dev,
607 607
608 /* Digital I/O subdevice */ 608 /* Digital I/O subdevice */
609 s = &dev->subdevices[2]; 609 s = &dev->subdevices[2];
610 ret = subdev_8255_init(dev, s, dmm32at_8255_io, DMM32AT_8255_IOBASE); 610 return subdev_8255_init(dev, s, dmm32at_8255_io, DMM32AT_8255_IOBASE);
611 if (ret)
612 return ret;
613
614 return 0;
615} 611}
616 612
617static struct comedi_driver dmm32at_driver = { 613static struct comedi_driver dmm32at_driver = {
diff --git a/drivers/staging/comedi/drivers/fl512.c b/drivers/staging/comedi/drivers/fl512.c
index e1f493241cd6..55cae61458cb 100644
--- a/drivers/staging/comedi/drivers/fl512.c
+++ b/drivers/staging/comedi/drivers/fl512.c
@@ -136,11 +136,7 @@ static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
136 s->range_table = &range_fl512; 136 s->range_table = &range_fl512;
137 s->insn_write = fl512_ao_insn_write; 137 s->insn_write = fl512_ao_insn_write;
138 138
139 ret = comedi_alloc_subdev_readback(s); 139 return comedi_alloc_subdev_readback(s);
140 if (ret)
141 return ret;
142
143 return 0;
144} 140}
145 141
146static struct comedi_driver fl512_driver = { 142static struct comedi_driver fl512_driver = {
diff --git a/drivers/staging/comedi/drivers/me4000.c b/drivers/staging/comedi/drivers/me4000.c
index a8f3ca48784b..15a53204a36a 100644
--- a/drivers/staging/comedi/drivers/me4000.c
+++ b/drivers/staging/comedi/drivers/me4000.c
@@ -1,43 +1,41 @@
1/* 1/*
2 comedi/drivers/me4000.c 2 * me4000.c
3 Source code for the Meilhaus ME-4000 board family. 3 * Source code for the Meilhaus ME-4000 board family.
4 4 *
5 COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 2000 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17 */ 17 */
18/*
19Driver: me4000
20Description: Meilhaus ME-4000 series boards
21Devices: [Meilhaus] ME-4650 (me4000), ME-4670i, ME-4680, ME-4680i, ME-4680is
22Author: gg (Guenter Gebhardt <g.gebhardt@meilhaus.com>)
23Updated: Mon, 18 Mar 2002 15:34:01 -0800
24Status: broken (no support for loading firmware)
25
26Supports:
27
28 - Analog Input
29 - Analog Output
30 - Digital I/O
31 - Counter
32
33Configuration Options: not applicable, uses PCI auto config
34
35The firmware required by these boards is available in the
36comedi_nonfree_firmware tarball available from
37http://www.comedi.org. However, the driver's support for
38loading the firmware through comedi_config is currently
39broken.
40 18
19/*
20 * Driver: me4000
21 * Description: Meilhaus ME-4000 series boards
22 * Devices: [Meilhaus] ME-4650 (me4000), ME-4670i, ME-4680, ME-4680i,
23 * ME-4680is
24 * Author: gg (Guenter Gebhardt <g.gebhardt@meilhaus.com>)
25 * Updated: Mon, 18 Mar 2002 15:34:01 -0800
26 * Status: untested
27 *
28 * Supports:
29 * - Analog Input
30 * - Analog Output
31 * - Digital I/O
32 * - Counter
33 *
34 * Configuration Options: not applicable, uses PCI auto config
35 *
36 * The firmware required by these boards is available in the
37 * comedi_nonfree_firmware tarball available from
38 * http://www.comedi.org.
41 */ 39 */
42 40
43#include <linux/module.h> 41#include <linux/module.h>
@@ -57,66 +55,61 @@ broken.
57#define ME4000_AO_CHAN(x) ((x) * 0x18) 55#define ME4000_AO_CHAN(x) ((x) * 0x18)
58 56
59#define ME4000_AO_CTRL_REG(x) (0x00 + ME4000_AO_CHAN(x)) 57#define ME4000_AO_CTRL_REG(x) (0x00 + ME4000_AO_CHAN(x))
60#define ME4000_AO_CTRL_BIT_MODE_0 (1 << 0) 58#define ME4000_AO_CTRL_MODE_0 BIT(0)
61#define ME4000_AO_CTRL_BIT_MODE_1 (1 << 1) 59#define ME4000_AO_CTRL_MODE_1 BIT(1)
62#define ME4000_AO_CTRL_MASK_MODE (3 << 0) 60#define ME4000_AO_CTRL_STOP BIT(2)
63#define ME4000_AO_CTRL_BIT_STOP (1 << 2) 61#define ME4000_AO_CTRL_ENABLE_FIFO BIT(3)
64#define ME4000_AO_CTRL_BIT_ENABLE_FIFO (1 << 3) 62#define ME4000_AO_CTRL_ENABLE_EX_TRIG BIT(4)
65#define ME4000_AO_CTRL_BIT_ENABLE_EX_TRIG (1 << 4) 63#define ME4000_AO_CTRL_EX_TRIG_EDGE BIT(5)
66#define ME4000_AO_CTRL_BIT_EX_TRIG_EDGE (1 << 5) 64#define ME4000_AO_CTRL_IMMEDIATE_STOP BIT(7)
67#define ME4000_AO_CTRL_BIT_IMMEDIATE_STOP (1 << 7) 65#define ME4000_AO_CTRL_ENABLE_DO BIT(8)
68#define ME4000_AO_CTRL_BIT_ENABLE_DO (1 << 8) 66#define ME4000_AO_CTRL_ENABLE_IRQ BIT(9)
69#define ME4000_AO_CTRL_BIT_ENABLE_IRQ (1 << 9) 67#define ME4000_AO_CTRL_RESET_IRQ BIT(10)
70#define ME4000_AO_CTRL_BIT_RESET_IRQ (1 << 10)
71#define ME4000_AO_STATUS_REG(x) (0x04 + ME4000_AO_CHAN(x)) 68#define ME4000_AO_STATUS_REG(x) (0x04 + ME4000_AO_CHAN(x))
72#define ME4000_AO_STATUS_BIT_FSM (1 << 0) 69#define ME4000_AO_STATUS_FSM BIT(0)
73#define ME4000_AO_STATUS_BIT_FF (1 << 1) 70#define ME4000_AO_STATUS_FF BIT(1)
74#define ME4000_AO_STATUS_BIT_HF (1 << 2) 71#define ME4000_AO_STATUS_HF BIT(2)
75#define ME4000_AO_STATUS_BIT_EF (1 << 3) 72#define ME4000_AO_STATUS_EF BIT(3)
76#define ME4000_AO_FIFO_REG(x) (0x08 + ME4000_AO_CHAN(x)) 73#define ME4000_AO_FIFO_REG(x) (0x08 + ME4000_AO_CHAN(x))
77#define ME4000_AO_SINGLE_REG(x) (0x0c + ME4000_AO_CHAN(x)) 74#define ME4000_AO_SINGLE_REG(x) (0x0c + ME4000_AO_CHAN(x))
78#define ME4000_AO_TIMER_REG(x) (0x10 + ME4000_AO_CHAN(x)) 75#define ME4000_AO_TIMER_REG(x) (0x10 + ME4000_AO_CHAN(x))
79#define ME4000_AI_CTRL_REG 0x74 76#define ME4000_AI_CTRL_REG 0x74
80#define ME4000_AI_STATUS_REG 0x74 77#define ME4000_AI_STATUS_REG 0x74
81#define ME4000_AI_CTRL_BIT_MODE_0 (1 << 0) 78#define ME4000_AI_CTRL_MODE_0 BIT(0)
82#define ME4000_AI_CTRL_BIT_MODE_1 (1 << 1) 79#define ME4000_AI_CTRL_MODE_1 BIT(1)
83#define ME4000_AI_CTRL_BIT_MODE_2 (1 << 2) 80#define ME4000_AI_CTRL_MODE_2 BIT(2)
84#define ME4000_AI_CTRL_BIT_SAMPLE_HOLD (1 << 3) 81#define ME4000_AI_CTRL_SAMPLE_HOLD BIT(3)
85#define ME4000_AI_CTRL_BIT_IMMEDIATE_STOP (1 << 4) 82#define ME4000_AI_CTRL_IMMEDIATE_STOP BIT(4)
86#define ME4000_AI_CTRL_BIT_STOP (1 << 5) 83#define ME4000_AI_CTRL_STOP BIT(5)
87#define ME4000_AI_CTRL_BIT_CHANNEL_FIFO (1 << 6) 84#define ME4000_AI_CTRL_CHANNEL_FIFO BIT(6)
88#define ME4000_AI_CTRL_BIT_DATA_FIFO (1 << 7) 85#define ME4000_AI_CTRL_DATA_FIFO BIT(7)
89#define ME4000_AI_CTRL_BIT_FULLSCALE (1 << 8) 86#define ME4000_AI_CTRL_FULLSCALE BIT(8)
90#define ME4000_AI_CTRL_BIT_OFFSET (1 << 9) 87#define ME4000_AI_CTRL_OFFSET BIT(9)
91#define ME4000_AI_CTRL_BIT_EX_TRIG_ANALOG (1 << 10) 88#define ME4000_AI_CTRL_EX_TRIG_ANALOG BIT(10)
92#define ME4000_AI_CTRL_BIT_EX_TRIG (1 << 11) 89#define ME4000_AI_CTRL_EX_TRIG BIT(11)
93#define ME4000_AI_CTRL_BIT_EX_TRIG_FALLING (1 << 12) 90#define ME4000_AI_CTRL_EX_TRIG_FALLING BIT(12)
94#define ME4000_AI_CTRL_BIT_EX_IRQ (1 << 13) 91#define ME4000_AI_CTRL_EX_IRQ BIT(13)
95#define ME4000_AI_CTRL_BIT_EX_IRQ_RESET (1 << 14) 92#define ME4000_AI_CTRL_EX_IRQ_RESET BIT(14)
96#define ME4000_AI_CTRL_BIT_LE_IRQ (1 << 15) 93#define ME4000_AI_CTRL_LE_IRQ BIT(15)
97#define ME4000_AI_CTRL_BIT_LE_IRQ_RESET (1 << 16) 94#define ME4000_AI_CTRL_LE_IRQ_RESET BIT(16)
98#define ME4000_AI_CTRL_BIT_HF_IRQ (1 << 17) 95#define ME4000_AI_CTRL_HF_IRQ BIT(17)
99#define ME4000_AI_CTRL_BIT_HF_IRQ_RESET (1 << 18) 96#define ME4000_AI_CTRL_HF_IRQ_RESET BIT(18)
100#define ME4000_AI_CTRL_BIT_SC_IRQ (1 << 19) 97#define ME4000_AI_CTRL_SC_IRQ BIT(19)
101#define ME4000_AI_CTRL_BIT_SC_IRQ_RESET (1 << 20) 98#define ME4000_AI_CTRL_SC_IRQ_RESET BIT(20)
102#define ME4000_AI_CTRL_BIT_SC_RELOAD (1 << 21) 99#define ME4000_AI_CTRL_SC_RELOAD BIT(21)
103#define ME4000_AI_STATUS_BIT_EF_CHANNEL (1 << 22) 100#define ME4000_AI_STATUS_EF_CHANNEL BIT(22)
104#define ME4000_AI_STATUS_BIT_HF_CHANNEL (1 << 23) 101#define ME4000_AI_STATUS_HF_CHANNEL BIT(23)
105#define ME4000_AI_STATUS_BIT_FF_CHANNEL (1 << 24) 102#define ME4000_AI_STATUS_FF_CHANNEL BIT(24)
106#define ME4000_AI_STATUS_BIT_EF_DATA (1 << 25) 103#define ME4000_AI_STATUS_EF_DATA BIT(25)
107#define ME4000_AI_STATUS_BIT_HF_DATA (1 << 26) 104#define ME4000_AI_STATUS_HF_DATA BIT(26)
108#define ME4000_AI_STATUS_BIT_FF_DATA (1 << 27) 105#define ME4000_AI_STATUS_FF_DATA BIT(27)
109#define ME4000_AI_STATUS_BIT_LE (1 << 28) 106#define ME4000_AI_STATUS_LE BIT(28)
110#define ME4000_AI_STATUS_BIT_FSM (1 << 29) 107#define ME4000_AI_STATUS_FSM BIT(29)
111#define ME4000_AI_CTRL_BIT_EX_TRIG_BOTH (1 << 31) 108#define ME4000_AI_CTRL_EX_TRIG_BOTH BIT(31)
112#define ME4000_AI_CHANNEL_LIST_REG 0x78 109#define ME4000_AI_CHANNEL_LIST_REG 0x78
113#define ME4000_AI_LIST_INPUT_SINGLE_ENDED (0 << 5) 110#define ME4000_AI_LIST_INPUT_DIFFERENTIAL BIT(5)
114#define ME4000_AI_LIST_INPUT_DIFFERENTIAL (1 << 5) 111#define ME4000_AI_LIST_RANGE(x) ((3 - ((x) & 3)) << 6)
115#define ME4000_AI_LIST_RANGE_BIPOLAR_10 (0 << 6) 112#define ME4000_AI_LIST_LAST_ENTRY BIT(8)
116#define ME4000_AI_LIST_RANGE_BIPOLAR_2_5 (1 << 6)
117#define ME4000_AI_LIST_RANGE_UNIPOLAR_10 (2 << 6)
118#define ME4000_AI_LIST_RANGE_UNIPOLAR_2_5 (3 << 6)
119#define ME4000_AI_LIST_LAST_ENTRY (1 << 8)
120#define ME4000_AI_DATA_REG 0x7c 113#define ME4000_AI_DATA_REG 0x7c
121#define ME4000_AI_CHAN_TIMER_REG 0x80 114#define ME4000_AI_CHAN_TIMER_REG 0x80
122#define ME4000_AI_CHAN_PRE_TIMER_REG 0x84 115#define ME4000_AI_CHAN_PRE_TIMER_REG 0x84
@@ -126,14 +119,14 @@ broken.
126#define ME4000_AI_SCAN_PRE_TIMER_HIGH_REG 0x94 119#define ME4000_AI_SCAN_PRE_TIMER_HIGH_REG 0x94
127#define ME4000_AI_START_REG 0x98 120#define ME4000_AI_START_REG 0x98
128#define ME4000_IRQ_STATUS_REG 0x9c 121#define ME4000_IRQ_STATUS_REG 0x9c
129#define ME4000_IRQ_STATUS_BIT_EX (1 << 0) 122#define ME4000_IRQ_STATUS_EX BIT(0)
130#define ME4000_IRQ_STATUS_BIT_LE (1 << 1) 123#define ME4000_IRQ_STATUS_LE BIT(1)
131#define ME4000_IRQ_STATUS_BIT_AI_HF (1 << 2) 124#define ME4000_IRQ_STATUS_AI_HF BIT(2)
132#define ME4000_IRQ_STATUS_BIT_AO_0_HF (1 << 3) 125#define ME4000_IRQ_STATUS_AO_0_HF BIT(3)
133#define ME4000_IRQ_STATUS_BIT_AO_1_HF (1 << 4) 126#define ME4000_IRQ_STATUS_AO_1_HF BIT(4)
134#define ME4000_IRQ_STATUS_BIT_AO_2_HF (1 << 5) 127#define ME4000_IRQ_STATUS_AO_2_HF BIT(5)
135#define ME4000_IRQ_STATUS_BIT_AO_3_HF (1 << 6) 128#define ME4000_IRQ_STATUS_AO_3_HF BIT(6)
136#define ME4000_IRQ_STATUS_BIT_SC (1 << 7) 129#define ME4000_IRQ_STATUS_SC BIT(7)
137#define ME4000_DIO_PORT_0_REG 0xa0 130#define ME4000_DIO_PORT_0_REG 0xa0
138#define ME4000_DIO_PORT_1_REG 0xa4 131#define ME4000_DIO_PORT_1_REG 0xa4
139#define ME4000_DIO_PORT_2_REG 0xa8 132#define ME4000_DIO_PORT_2_REG 0xa8
@@ -141,20 +134,20 @@ broken.
141#define ME4000_DIO_DIR_REG 0xb0 134#define ME4000_DIO_DIR_REG 0xb0
142#define ME4000_AO_LOADSETREG_XX 0xb4 135#define ME4000_AO_LOADSETREG_XX 0xb4
143#define ME4000_DIO_CTRL_REG 0xb8 136#define ME4000_DIO_CTRL_REG 0xb8
144#define ME4000_DIO_CTRL_BIT_MODE_0 (1 << 0) 137#define ME4000_DIO_CTRL_MODE_0 BIT(0)
145#define ME4000_DIO_CTRL_BIT_MODE_1 (1 << 1) 138#define ME4000_DIO_CTRL_MODE_1 BIT(1)
146#define ME4000_DIO_CTRL_BIT_MODE_2 (1 << 2) 139#define ME4000_DIO_CTRL_MODE_2 BIT(2)
147#define ME4000_DIO_CTRL_BIT_MODE_3 (1 << 3) 140#define ME4000_DIO_CTRL_MODE_3 BIT(3)
148#define ME4000_DIO_CTRL_BIT_MODE_4 (1 << 4) 141#define ME4000_DIO_CTRL_MODE_4 BIT(4)
149#define ME4000_DIO_CTRL_BIT_MODE_5 (1 << 5) 142#define ME4000_DIO_CTRL_MODE_5 BIT(5)
150#define ME4000_DIO_CTRL_BIT_MODE_6 (1 << 6) 143#define ME4000_DIO_CTRL_MODE_6 BIT(6)
151#define ME4000_DIO_CTRL_BIT_MODE_7 (1 << 7) 144#define ME4000_DIO_CTRL_MODE_7 BIT(7)
152#define ME4000_DIO_CTRL_BIT_FUNCTION_0 (1 << 8) 145#define ME4000_DIO_CTRL_FUNCTION_0 BIT(8)
153#define ME4000_DIO_CTRL_BIT_FUNCTION_1 (1 << 9) 146#define ME4000_DIO_CTRL_FUNCTION_1 BIT(9)
154#define ME4000_DIO_CTRL_BIT_FIFO_HIGH_0 (1 << 10) 147#define ME4000_DIO_CTRL_FIFO_HIGH_0 BIT(10)
155#define ME4000_DIO_CTRL_BIT_FIFO_HIGH_1 (1 << 11) 148#define ME4000_DIO_CTRL_FIFO_HIGH_1 BIT(11)
156#define ME4000_DIO_CTRL_BIT_FIFO_HIGH_2 (1 << 12) 149#define ME4000_DIO_CTRL_FIFO_HIGH_2 BIT(12)
157#define ME4000_DIO_CTRL_BIT_FIFO_HIGH_3 (1 << 13) 150#define ME4000_DIO_CTRL_FIFO_HIGH_3 BIT(13)
158#define ME4000_AO_DEMUX_ADJUST_REG 0xbc 151#define ME4000_AO_DEMUX_ADJUST_REG 0xbc
159#define ME4000_AO_DEMUX_ADJUST_VALUE 0x4c 152#define ME4000_AO_DEMUX_ADJUST_VALUE 0x4c
160#define ME4000_AI_SAMPLE_COUNTER_REG 0xc0 153#define ME4000_AI_SAMPLE_COUNTER_REG 0xc0
@@ -166,8 +159,12 @@ broken.
166 159
167#define ME4000_AI_CHANNEL_LIST_COUNT 1024 160#define ME4000_AI_CHANNEL_LIST_COUNT 1024
168 161
169struct me4000_info { 162struct me4000_private {
170 unsigned long plx_regbase; 163 unsigned long plx_regbase;
164 unsigned int ai_ctrl_mode;
165 unsigned int ai_init_ticks;
166 unsigned int ai_scan_ticks;
167 unsigned int ai_chan_ticks;
171}; 168};
172 169
173enum me4000_boardid { 170enum me4000_boardid {
@@ -188,134 +185,126 @@ enum me4000_boardid {
188 185
189struct me4000_board { 186struct me4000_board {
190 const char *name; 187 const char *name;
191 int ao_nchan;
192 int ao_fifo;
193 int ai_nchan; 188 int ai_nchan;
194 int ai_diff_nchan; 189 unsigned int can_do_diff_ai:1;
195 int ai_sh_nchan; 190 unsigned int can_do_sh_ai:1; /* sample & hold (8 channels) */
196 int ex_trig_analog; 191 unsigned int ex_trig_analog:1;
197 int dio_nchan; 192 unsigned int has_ao:1;
198 int has_counter; 193 unsigned int has_ao_fifo:1;
194 unsigned int has_counter:1;
199}; 195};
200 196
201static const struct me4000_board me4000_boards[] = { 197static const struct me4000_board me4000_boards[] = {
202 [BOARD_ME4650] = { 198 [BOARD_ME4650] = {
203 .name = "ME-4650", 199 .name = "ME-4650",
204 .ai_nchan = 16, 200 .ai_nchan = 16,
205 .dio_nchan = 32,
206 }, 201 },
207 [BOARD_ME4660] = { 202 [BOARD_ME4660] = {
208 .name = "ME-4660", 203 .name = "ME-4660",
209 .ai_nchan = 32, 204 .ai_nchan = 32,
210 .ai_diff_nchan = 16, 205 .can_do_diff_ai = 1,
211 .dio_nchan = 32,
212 .has_counter = 1, 206 .has_counter = 1,
213 }, 207 },
214 [BOARD_ME4660I] = { 208 [BOARD_ME4660I] = {
215 .name = "ME-4660i", 209 .name = "ME-4660i",
216 .ai_nchan = 32, 210 .ai_nchan = 32,
217 .ai_diff_nchan = 16, 211 .can_do_diff_ai = 1,
218 .dio_nchan = 32,
219 .has_counter = 1, 212 .has_counter = 1,
220 }, 213 },
221 [BOARD_ME4660S] = { 214 [BOARD_ME4660S] = {
222 .name = "ME-4660s", 215 .name = "ME-4660s",
223 .ai_nchan = 32, 216 .ai_nchan = 32,
224 .ai_diff_nchan = 16, 217 .can_do_diff_ai = 1,
225 .ai_sh_nchan = 8, 218 .can_do_sh_ai = 1,
226 .dio_nchan = 32,
227 .has_counter = 1, 219 .has_counter = 1,
228 }, 220 },
229 [BOARD_ME4660IS] = { 221 [BOARD_ME4660IS] = {
230 .name = "ME-4660is", 222 .name = "ME-4660is",
231 .ai_nchan = 32, 223 .ai_nchan = 32,
232 .ai_diff_nchan = 16, 224 .can_do_diff_ai = 1,
233 .ai_sh_nchan = 8, 225 .can_do_sh_ai = 1,
234 .dio_nchan = 32,
235 .has_counter = 1, 226 .has_counter = 1,
236 }, 227 },
237 [BOARD_ME4670] = { 228 [BOARD_ME4670] = {
238 .name = "ME-4670", 229 .name = "ME-4670",
239 .ao_nchan = 4,
240 .ai_nchan = 32, 230 .ai_nchan = 32,
241 .ai_diff_nchan = 16, 231 .can_do_diff_ai = 1,
242 .ex_trig_analog = 1, 232 .ex_trig_analog = 1,
243 .dio_nchan = 32, 233 .has_ao = 1,
244 .has_counter = 1, 234 .has_counter = 1,
245 }, 235 },
246 [BOARD_ME4670I] = { 236 [BOARD_ME4670I] = {
247 .name = "ME-4670i", 237 .name = "ME-4670i",
248 .ao_nchan = 4,
249 .ai_nchan = 32, 238 .ai_nchan = 32,
250 .ai_diff_nchan = 16, 239 .can_do_diff_ai = 1,
251 .ex_trig_analog = 1, 240 .ex_trig_analog = 1,
252 .dio_nchan = 32, 241 .has_ao = 1,
253 .has_counter = 1, 242 .has_counter = 1,
254 }, 243 },
255 [BOARD_ME4670S] = { 244 [BOARD_ME4670S] = {
256 .name = "ME-4670s", 245 .name = "ME-4670s",
257 .ao_nchan = 4,
258 .ai_nchan = 32, 246 .ai_nchan = 32,
259 .ai_diff_nchan = 16, 247 .can_do_diff_ai = 1,
260 .ai_sh_nchan = 8, 248 .can_do_sh_ai = 1,
261 .ex_trig_analog = 1, 249 .ex_trig_analog = 1,
262 .dio_nchan = 32, 250 .has_ao = 1,
263 .has_counter = 1, 251 .has_counter = 1,
264 }, 252 },
265 [BOARD_ME4670IS] = { 253 [BOARD_ME4670IS] = {
266 .name = "ME-4670is", 254 .name = "ME-4670is",
267 .ao_nchan = 4,
268 .ai_nchan = 32, 255 .ai_nchan = 32,
269 .ai_diff_nchan = 16, 256 .can_do_diff_ai = 1,
270 .ai_sh_nchan = 8, 257 .can_do_sh_ai = 1,
271 .ex_trig_analog = 1, 258 .ex_trig_analog = 1,
272 .dio_nchan = 32, 259 .has_ao = 1,
273 .has_counter = 1, 260 .has_counter = 1,
274 }, 261 },
275 [BOARD_ME4680] = { 262 [BOARD_ME4680] = {
276 .name = "ME-4680", 263 .name = "ME-4680",
277 .ao_nchan = 4,
278 .ao_fifo = 4,
279 .ai_nchan = 32, 264 .ai_nchan = 32,
280 .ai_diff_nchan = 16, 265 .can_do_diff_ai = 1,
281 .ex_trig_analog = 1, 266 .ex_trig_analog = 1,
282 .dio_nchan = 32, 267 .has_ao = 1,
268 .has_ao_fifo = 1,
283 .has_counter = 1, 269 .has_counter = 1,
284 }, 270 },
285 [BOARD_ME4680I] = { 271 [BOARD_ME4680I] = {
286 .name = "ME-4680i", 272 .name = "ME-4680i",
287 .ao_nchan = 4,
288 .ao_fifo = 4,
289 .ai_nchan = 32, 273 .ai_nchan = 32,
290 .ai_diff_nchan = 16, 274 .can_do_diff_ai = 1,
291 .ex_trig_analog = 1, 275 .ex_trig_analog = 1,
292 .dio_nchan = 32, 276 .has_ao = 1,
277 .has_ao_fifo = 1,
293 .has_counter = 1, 278 .has_counter = 1,
294 }, 279 },
295 [BOARD_ME4680S] = { 280 [BOARD_ME4680S] = {
296 .name = "ME-4680s", 281 .name = "ME-4680s",
297 .ao_nchan = 4,
298 .ao_fifo = 4,
299 .ai_nchan = 32, 282 .ai_nchan = 32,
300 .ai_diff_nchan = 16, 283 .can_do_diff_ai = 1,
301 .ai_sh_nchan = 8, 284 .can_do_sh_ai = 1,
302 .ex_trig_analog = 1, 285 .ex_trig_analog = 1,
303 .dio_nchan = 32, 286 .has_ao = 1,
287 .has_ao_fifo = 1,
304 .has_counter = 1, 288 .has_counter = 1,
305 }, 289 },
306 [BOARD_ME4680IS] = { 290 [BOARD_ME4680IS] = {
307 .name = "ME-4680is", 291 .name = "ME-4680is",
308 .ao_nchan = 4,
309 .ao_fifo = 4,
310 .ai_nchan = 32, 292 .ai_nchan = 32,
311 .ai_diff_nchan = 16, 293 .can_do_diff_ai = 1,
312 .ai_sh_nchan = 8, 294 .can_do_sh_ai = 1,
313 .ex_trig_analog = 1, 295 .ex_trig_analog = 1,
314 .dio_nchan = 32, 296 .has_ao = 1,
297 .has_ao_fifo = 1,
315 .has_counter = 1, 298 .has_counter = 1,
316 }, 299 },
317}; 300};
318 301
302/*
303 * NOTE: the ranges here are inverted compared to the values
304 * written to the ME4000_AI_CHANNEL_LIST_REG,
305 *
306 * The ME4000_AI_LIST_RANGE() macro handles the inversion.
307 */
319static const struct comedi_lrange me4000_ai_range = { 308static const struct comedi_lrange me4000_ai_range = {
320 4, { 309 4, {
321 UNI_RANGE(2.5), 310 UNI_RANGE(2.5),
@@ -330,7 +319,7 @@ static int me4000_xilinx_download(struct comedi_device *dev,
330 unsigned long context) 319 unsigned long context)
331{ 320{
332 struct pci_dev *pcidev = comedi_to_pci_dev(dev); 321 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
333 struct me4000_info *info = dev->private; 322 struct me4000_private *devpriv = dev->private;
334 unsigned long xilinx_iobase = pci_resource_start(pcidev, 5); 323 unsigned long xilinx_iobase = pci_resource_start(pcidev, 5);
335 unsigned int file_length; 324 unsigned int file_length;
336 unsigned int val; 325 unsigned int val;
@@ -343,42 +332,42 @@ static int me4000_xilinx_download(struct comedi_device *dev,
343 * Set PLX local interrupt 2 polarity to high. 332 * Set PLX local interrupt 2 polarity to high.
344 * Interrupt is thrown by init pin of xilinx. 333 * Interrupt is thrown by init pin of xilinx.
345 */ 334 */
346 outl(PLX9052_INTCSR_LI2POL, info->plx_regbase + PLX9052_INTCSR); 335 outl(PLX9052_INTCSR_LI2POL, devpriv->plx_regbase + PLX9052_INTCSR);
347 336
348 /* Set /CS and /WRITE of the Xilinx */ 337 /* Set /CS and /WRITE of the Xilinx */
349 val = inl(info->plx_regbase + PLX9052_CNTRL); 338 val = inl(devpriv->plx_regbase + PLX9052_CNTRL);
350 val |= PLX9052_CNTRL_UIO2_DATA; 339 val |= PLX9052_CNTRL_UIO2_DATA;
351 outl(val, info->plx_regbase + PLX9052_CNTRL); 340 outl(val, devpriv->plx_regbase + PLX9052_CNTRL);
352 341
353 /* Init Xilinx with CS1 */ 342 /* Init Xilinx with CS1 */
354 inb(xilinx_iobase + 0xC8); 343 inb(xilinx_iobase + 0xC8);
355 344
356 /* Wait until /INIT pin is set */ 345 /* Wait until /INIT pin is set */
357 udelay(20); 346 usleep_range(20, 1000);
358 val = inl(info->plx_regbase + PLX9052_INTCSR); 347 val = inl(devpriv->plx_regbase + PLX9052_INTCSR);
359 if (!(val & PLX9052_INTCSR_LI2STAT)) { 348 if (!(val & PLX9052_INTCSR_LI2STAT)) {
360 dev_err(dev->class_dev, "Can't init Xilinx\n"); 349 dev_err(dev->class_dev, "Can't init Xilinx\n");
361 return -EIO; 350 return -EIO;
362 } 351 }
363 352
364 /* Reset /CS and /WRITE of the Xilinx */ 353 /* Reset /CS and /WRITE of the Xilinx */
365 val = inl(info->plx_regbase + PLX9052_CNTRL); 354 val = inl(devpriv->plx_regbase + PLX9052_CNTRL);
366 val &= ~PLX9052_CNTRL_UIO2_DATA; 355 val &= ~PLX9052_CNTRL_UIO2_DATA;
367 outl(val, info->plx_regbase + PLX9052_CNTRL); 356 outl(val, devpriv->plx_regbase + PLX9052_CNTRL);
368 357
369 /* Download Xilinx firmware */ 358 /* Download Xilinx firmware */
370 file_length = (((unsigned int)data[0] & 0xff) << 24) + 359 file_length = (((unsigned int)data[0] & 0xff) << 24) +
371 (((unsigned int)data[1] & 0xff) << 16) + 360 (((unsigned int)data[1] & 0xff) << 16) +
372 (((unsigned int)data[2] & 0xff) << 8) + 361 (((unsigned int)data[2] & 0xff) << 8) +
373 ((unsigned int)data[3] & 0xff); 362 ((unsigned int)data[3] & 0xff);
374 udelay(10); 363 usleep_range(10, 1000);
375 364
376 for (i = 0; i < file_length; i++) { 365 for (i = 0; i < file_length; i++) {
377 outb(data[16 + i], xilinx_iobase); 366 outb(data[16 + i], xilinx_iobase);
378 udelay(10); 367 usleep_range(10, 1000);
379 368
380 /* Check if BUSY flag is low */ 369 /* Check if BUSY flag is low */
381 val = inl(info->plx_regbase + PLX9052_CNTRL); 370 val = inl(devpriv->plx_regbase + PLX9052_CNTRL);
382 if (val & PLX9052_CNTRL_UIO1_DATA) { 371 if (val & PLX9052_CNTRL_UIO1_DATA) {
383 dev_err(dev->class_dev, 372 dev_err(dev->class_dev,
384 "Xilinx is still busy (i = %d)\n", i); 373 "Xilinx is still busy (i = %d)\n", i);
@@ -387,7 +376,7 @@ static int me4000_xilinx_download(struct comedi_device *dev,
387 } 376 }
388 377
389 /* If done flag is high download was successful */ 378 /* If done flag is high download was successful */
390 val = inl(info->plx_regbase + PLX9052_CNTRL); 379 val = inl(devpriv->plx_regbase + PLX9052_CNTRL);
391 if (!(val & PLX9052_CNTRL_UIO0_DATA)) { 380 if (!(val & PLX9052_CNTRL_UIO0_DATA)) {
392 dev_err(dev->class_dev, "DONE flag is not set\n"); 381 dev_err(dev->class_dev, "DONE flag is not set\n");
393 dev_err(dev->class_dev, "Download not successful\n"); 382 dev_err(dev->class_dev, "Download not successful\n");
@@ -395,44 +384,53 @@ static int me4000_xilinx_download(struct comedi_device *dev,
395 } 384 }
396 385
397 /* Set /CS and /WRITE */ 386 /* Set /CS and /WRITE */
398 val = inl(info->plx_regbase + PLX9052_CNTRL); 387 val = inl(devpriv->plx_regbase + PLX9052_CNTRL);
399 val |= PLX9052_CNTRL_UIO2_DATA; 388 val |= PLX9052_CNTRL_UIO2_DATA;
400 outl(val, info->plx_regbase + PLX9052_CNTRL); 389 outl(val, devpriv->plx_regbase + PLX9052_CNTRL);
401 390
402 return 0; 391 return 0;
403} 392}
404 393
394static void me4000_ai_reset(struct comedi_device *dev)
395{
396 unsigned int ctrl;
397
398 /* Stop any running conversion */
399 ctrl = inl(dev->iobase + ME4000_AI_CTRL_REG);
400 ctrl |= ME4000_AI_CTRL_STOP | ME4000_AI_CTRL_IMMEDIATE_STOP;
401 outl(ctrl, dev->iobase + ME4000_AI_CTRL_REG);
402
403 /* Clear the control register */
404 outl(0x0, dev->iobase + ME4000_AI_CTRL_REG);
405}
406
405static void me4000_reset(struct comedi_device *dev) 407static void me4000_reset(struct comedi_device *dev)
406{ 408{
407 struct me4000_info *info = dev->private; 409 struct me4000_private *devpriv = dev->private;
408 unsigned int val; 410 unsigned int val;
409 int chan; 411 int chan;
410 412
411 /* Make a hardware reset */ 413 /* Disable interrupts on the PLX */
412 val = inl(info->plx_regbase + PLX9052_CNTRL); 414 outl(0, devpriv->plx_regbase + PLX9052_INTCSR);
415
416 /* Software reset the PLX */
417 val = inl(devpriv->plx_regbase + PLX9052_CNTRL);
413 val |= PLX9052_CNTRL_PCI_RESET; 418 val |= PLX9052_CNTRL_PCI_RESET;
414 outl(val, info->plx_regbase + PLX9052_CNTRL); 419 outl(val, devpriv->plx_regbase + PLX9052_CNTRL);
415 val &= ~PLX9052_CNTRL_PCI_RESET; 420 val &= ~PLX9052_CNTRL_PCI_RESET;
416 outl(val, info->plx_regbase + PLX9052_CNTRL); 421 outl(val, devpriv->plx_regbase + PLX9052_CNTRL);
417 422
418 /* 0x8000 to the DACs means an output voltage of 0V */ 423 /* 0x8000 to the DACs means an output voltage of 0V */
419 for (chan = 0; chan < 4; chan++) 424 for (chan = 0; chan < 4; chan++)
420 outl(0x8000, dev->iobase + ME4000_AO_SINGLE_REG(chan)); 425 outl(0x8000, dev->iobase + ME4000_AO_SINGLE_REG(chan));
421 426
422 /* Set both stop bits in the analog input control register */ 427 me4000_ai_reset(dev);
423 outl(ME4000_AI_CTRL_BIT_IMMEDIATE_STOP | ME4000_AI_CTRL_BIT_STOP,
424 dev->iobase + ME4000_AI_CTRL_REG);
425 428
426 /* Set both stop bits in the analog output control register */ 429 /* Set both stop bits in the analog output control register */
427 val = ME4000_AO_CTRL_BIT_IMMEDIATE_STOP | ME4000_AO_CTRL_BIT_STOP; 430 val = ME4000_AO_CTRL_IMMEDIATE_STOP | ME4000_AO_CTRL_STOP;
428 for (chan = 0; chan < 4; chan++) 431 for (chan = 0; chan < 4; chan++)
429 outl(val, dev->iobase + ME4000_AO_CTRL_REG(chan)); 432 outl(val, dev->iobase + ME4000_AO_CTRL_REG(chan));
430 433
431 /* Enable interrupts on the PLX */
432 outl(PLX9052_INTCSR_LI1ENAB |
433 PLX9052_INTCSR_LI1POL |
434 PLX9052_INTCSR_PCIENAB, info->plx_regbase + PLX9052_INTCSR);
435
436 /* Set the adustment register for AO demux */ 434 /* Set the adustment register for AO demux */
437 outl(ME4000_AO_DEMUX_ADJUST_VALUE, 435 outl(ME4000_AO_DEMUX_ADJUST_VALUE,
438 dev->iobase + ME4000_AO_DEMUX_ADJUST_REG); 436 dev->iobase + ME4000_AO_DEMUX_ADJUST_REG);
@@ -445,96 +443,68 @@ static void me4000_reset(struct comedi_device *dev)
445 outl(0x1, dev->iobase + ME4000_DIO_CTRL_REG); 443 outl(0x1, dev->iobase + ME4000_DIO_CTRL_REG);
446} 444}
447 445
448/*============================================================================= 446static unsigned int me4000_ai_get_sample(struct comedi_device *dev,
449 Analog input section 447 struct comedi_subdevice *s)
450 ===========================================================================*/
451
452static int me4000_ai_insn_read(struct comedi_device *dev,
453 struct comedi_subdevice *subdevice,
454 struct comedi_insn *insn, unsigned int *data)
455{ 448{
456 const struct me4000_board *board = dev->board_ptr; 449 unsigned int val;
457 int chan = CR_CHAN(insn->chanspec);
458 int rang = CR_RANGE(insn->chanspec);
459 int aref = CR_AREF(insn->chanspec);
460 450
461 unsigned int entry = 0; 451 /* read two's complement value and munge to offset binary */
462 unsigned int tmp; 452 val = inl(dev->iobase + ME4000_AI_DATA_REG);
463 unsigned int lval; 453 return comedi_offset_munge(s, val);
454}
464 455
465 if (insn->n == 0) { 456static int me4000_ai_eoc(struct comedi_device *dev,
457 struct comedi_subdevice *s,
458 struct comedi_insn *insn,
459 unsigned long context)
460{
461 unsigned int status;
462
463 status = inl(dev->iobase + ME4000_AI_STATUS_REG);
464 if (status & ME4000_AI_STATUS_EF_DATA)
466 return 0; 465 return 0;
467 } else if (insn->n > 1) { 466 return -EBUSY;
468 dev_err(dev->class_dev, "Invalid instruction length %d\n", 467}
469 insn->n);
470 return -EINVAL;
471 }
472 468
473 switch (rang) { 469static int me4000_ai_insn_read(struct comedi_device *dev,
474 case 0: 470 struct comedi_subdevice *s,
475 entry |= ME4000_AI_LIST_RANGE_UNIPOLAR_2_5; 471 struct comedi_insn *insn,
476 break; 472 unsigned int *data)
477 case 1: 473{
478 entry |= ME4000_AI_LIST_RANGE_UNIPOLAR_10; 474 unsigned int chan = CR_CHAN(insn->chanspec);
479 break; 475 unsigned int range = CR_RANGE(insn->chanspec);
480 case 2: 476 unsigned int aref = CR_AREF(insn->chanspec);
481 entry |= ME4000_AI_LIST_RANGE_BIPOLAR_2_5; 477 unsigned int entry;
482 break; 478 int ret = 0;
483 case 3: 479 int i;
484 entry |= ME4000_AI_LIST_RANGE_BIPOLAR_10;
485 break;
486 default:
487 dev_err(dev->class_dev, "Invalid range specified\n");
488 return -EINVAL;
489 }
490 480
491 switch (aref) { 481 entry = chan | ME4000_AI_LIST_RANGE(range);
492 case AREF_GROUND: 482 if (aref == AREF_DIFF) {
493 case AREF_COMMON: 483 if (!(s->subdev_flags & SDF_DIFF)) {
494 if (chan >= board->ai_nchan) {
495 dev_err(dev->class_dev, 484 dev_err(dev->class_dev,
496 "Analog input is not available\n"); 485 "Differential inputs are not available\n");
497 return -EINVAL; 486 return -EINVAL;
498 } 487 }
499 entry |= ME4000_AI_LIST_INPUT_SINGLE_ENDED | chan;
500 break;
501 488
502 case AREF_DIFF: 489 if (!comedi_range_is_bipolar(s, range)) {
503 if (rang == 0 || rang == 1) {
504 dev_err(dev->class_dev, 490 dev_err(dev->class_dev,
505 "Range must be bipolar when aref = diff\n"); 491 "Range must be bipolar when aref = diff\n");
506 return -EINVAL; 492 return -EINVAL;
507 } 493 }
508 494
509 if (chan >= board->ai_diff_nchan) { 495 if (chan >= (s->n_chan / 2)) {
510 dev_err(dev->class_dev, 496 dev_err(dev->class_dev,
511 "Analog input is not available\n"); 497 "Analog input is not available\n");
512 return -EINVAL; 498 return -EINVAL;
513 } 499 }
514 entry |= ME4000_AI_LIST_INPUT_DIFFERENTIAL | chan; 500 entry |= ME4000_AI_LIST_INPUT_DIFFERENTIAL;
515 break;
516 default:
517 dev_err(dev->class_dev, "Invalid aref specified\n");
518 return -EINVAL;
519 } 501 }
520 502
521 entry |= ME4000_AI_LIST_LAST_ENTRY; 503 entry |= ME4000_AI_LIST_LAST_ENTRY;
522 504
523 /* Clear channel list, data fifo and both stop bits */ 505 /* Enable channel list and data fifo for single acquisition mode */
524 tmp = inl(dev->iobase + ME4000_AI_CTRL_REG); 506 outl(ME4000_AI_CTRL_CHANNEL_FIFO | ME4000_AI_CTRL_DATA_FIFO,
525 tmp &= ~(ME4000_AI_CTRL_BIT_CHANNEL_FIFO | 507 dev->iobase + ME4000_AI_CTRL_REG);
526 ME4000_AI_CTRL_BIT_DATA_FIFO |
527 ME4000_AI_CTRL_BIT_STOP | ME4000_AI_CTRL_BIT_IMMEDIATE_STOP);
528 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG);
529
530 /* Set the acquisition mode to single */
531 tmp &= ~(ME4000_AI_CTRL_BIT_MODE_0 | ME4000_AI_CTRL_BIT_MODE_1 |
532 ME4000_AI_CTRL_BIT_MODE_2);
533 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG);
534
535 /* Enable channel list and data fifo */
536 tmp |= ME4000_AI_CTRL_BIT_CHANNEL_FIFO | ME4000_AI_CTRL_BIT_DATA_FIFO;
537 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG);
538 508
539 /* Generate channel list entry */ 509 /* Generate channel list entry */
540 outl(entry, dev->iobase + ME4000_AI_CHANNEL_LIST_REG); 510 outl(entry, dev->iobase + ME4000_AI_CHANNEL_LIST_REG);
@@ -543,36 +513,29 @@ static int me4000_ai_insn_read(struct comedi_device *dev,
543 outl(ME4000_AI_MIN_TICKS, dev->iobase + ME4000_AI_CHAN_TIMER_REG); 513 outl(ME4000_AI_MIN_TICKS, dev->iobase + ME4000_AI_CHAN_TIMER_REG);
544 outl(ME4000_AI_MIN_TICKS, dev->iobase + ME4000_AI_CHAN_PRE_TIMER_REG); 514 outl(ME4000_AI_MIN_TICKS, dev->iobase + ME4000_AI_CHAN_PRE_TIMER_REG);
545 515
546 /* Start conversion by dummy read */ 516 for (i = 0; i < insn->n; i++) {
547 inl(dev->iobase + ME4000_AI_START_REG); 517 unsigned int val;
548 518
549 /* Wait until ready */ 519 /* start conversion by dummy read */
550 udelay(10); 520 inl(dev->iobase + ME4000_AI_START_REG);
551 if (!(inl(dev->iobase + ME4000_AI_STATUS_REG) & 521
552 ME4000_AI_STATUS_BIT_EF_DATA)) { 522 ret = comedi_timeout(dev, s, insn, me4000_ai_eoc, 0);
553 dev_err(dev->class_dev, "Value not available after wait\n"); 523 if (ret)
554 return -EIO; 524 break;
525
526 val = me4000_ai_get_sample(dev, s);
527 data[i] = comedi_offset_munge(s, val);
555 } 528 }
556 529
557 /* Read value from data fifo */ 530 me4000_ai_reset(dev);
558 lval = inl(dev->iobase + ME4000_AI_DATA_REG) & 0xFFFF;
559 data[0] = lval ^ 0x8000;
560 531
561 return 1; 532 return ret ? ret : insn->n;
562} 533}
563 534
564static int me4000_ai_cancel(struct comedi_device *dev, 535static int me4000_ai_cancel(struct comedi_device *dev,
565 struct comedi_subdevice *s) 536 struct comedi_subdevice *s)
566{ 537{
567 unsigned int tmp; 538 me4000_ai_reset(dev);
568
569 /* Stop any running conversion */
570 tmp = inl(dev->iobase + ME4000_AI_CTRL_REG);
571 tmp &= ~(ME4000_AI_CTRL_BIT_STOP | ME4000_AI_CTRL_BIT_IMMEDIATE_STOP);
572 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG);
573
574 /* Clear the control register */
575 outl(0x0, dev->iobase + ME4000_AI_CTRL_REG);
576 539
577 return 0; 540 return 0;
578} 541}
@@ -581,8 +544,6 @@ static int me4000_ai_check_chanlist(struct comedi_device *dev,
581 struct comedi_subdevice *s, 544 struct comedi_subdevice *s,
582 struct comedi_cmd *cmd) 545 struct comedi_cmd *cmd)
583{ 546{
584 const struct me4000_board *board = dev->board_ptr;
585 unsigned int max_diff_chan = board->ai_diff_nchan;
586 unsigned int aref0 = CR_AREF(cmd->chanlist[0]); 547 unsigned int aref0 = CR_AREF(cmd->chanlist[0]);
587 int i; 548 int i;
588 549
@@ -598,7 +559,13 @@ static int me4000_ai_check_chanlist(struct comedi_device *dev,
598 } 559 }
599 560
600 if (aref == AREF_DIFF) { 561 if (aref == AREF_DIFF) {
601 if (chan >= max_diff_chan) { 562 if (!(s->subdev_flags & SDF_DIFF)) {
563 dev_err(dev->class_dev,
564 "Differential inputs are not available\n");
565 return -EINVAL;
566 }
567
568 if (chan >= (s->n_chan / 2)) {
602 dev_dbg(dev->class_dev, 569 dev_dbg(dev->class_dev,
603 "Channel number to high\n"); 570 "Channel number to high\n");
604 return -EINVAL; 571 return -EINVAL;
@@ -615,202 +582,127 @@ static int me4000_ai_check_chanlist(struct comedi_device *dev,
615 return 0; 582 return 0;
616} 583}
617 584
618static int ai_round_cmd_args(struct comedi_device *dev, 585static void me4000_ai_round_cmd_args(struct comedi_device *dev,
619 struct comedi_subdevice *s, 586 struct comedi_subdevice *s,
620 struct comedi_cmd *cmd, 587 struct comedi_cmd *cmd)
621 unsigned int *init_ticks,
622 unsigned int *scan_ticks, unsigned int *chan_ticks)
623{ 588{
589 struct me4000_private *devpriv = dev->private;
624 int rest; 590 int rest;
625 591
626 *init_ticks = 0; 592 devpriv->ai_init_ticks = 0;
627 *scan_ticks = 0; 593 devpriv->ai_scan_ticks = 0;
628 *chan_ticks = 0; 594 devpriv->ai_chan_ticks = 0;
629 595
630 if (cmd->start_arg) { 596 if (cmd->start_arg) {
631 *init_ticks = (cmd->start_arg * 33) / 1000; 597 devpriv->ai_init_ticks = (cmd->start_arg * 33) / 1000;
632 rest = (cmd->start_arg * 33) % 1000; 598 rest = (cmd->start_arg * 33) % 1000;
633 599
634 if ((cmd->flags & CMDF_ROUND_MASK) == CMDF_ROUND_NEAREST) { 600 if ((cmd->flags & CMDF_ROUND_MASK) == CMDF_ROUND_NEAREST) {
635 if (rest > 33) 601 if (rest > 33)
636 (*init_ticks)++; 602 devpriv->ai_init_ticks++;
637 } else if ((cmd->flags & CMDF_ROUND_MASK) == CMDF_ROUND_UP) { 603 } else if ((cmd->flags & CMDF_ROUND_MASK) == CMDF_ROUND_UP) {
638 if (rest) 604 if (rest)
639 (*init_ticks)++; 605 devpriv->ai_init_ticks++;
640 } 606 }
641 } 607 }
642 608
643 if (cmd->scan_begin_arg) { 609 if (cmd->scan_begin_arg) {
644 *scan_ticks = (cmd->scan_begin_arg * 33) / 1000; 610 devpriv->ai_scan_ticks = (cmd->scan_begin_arg * 33) / 1000;
645 rest = (cmd->scan_begin_arg * 33) % 1000; 611 rest = (cmd->scan_begin_arg * 33) % 1000;
646 612
647 if ((cmd->flags & CMDF_ROUND_MASK) == CMDF_ROUND_NEAREST) { 613 if ((cmd->flags & CMDF_ROUND_MASK) == CMDF_ROUND_NEAREST) {
648 if (rest > 33) 614 if (rest > 33)
649 (*scan_ticks)++; 615 devpriv->ai_scan_ticks++;
650 } else if ((cmd->flags & CMDF_ROUND_MASK) == CMDF_ROUND_UP) { 616 } else if ((cmd->flags & CMDF_ROUND_MASK) == CMDF_ROUND_UP) {
651 if (rest) 617 if (rest)
652 (*scan_ticks)++; 618 devpriv->ai_scan_ticks++;
653 } 619 }
654 } 620 }
655 621
656 if (cmd->convert_arg) { 622 if (cmd->convert_arg) {
657 *chan_ticks = (cmd->convert_arg * 33) / 1000; 623 devpriv->ai_chan_ticks = (cmd->convert_arg * 33) / 1000;
658 rest = (cmd->convert_arg * 33) % 1000; 624 rest = (cmd->convert_arg * 33) % 1000;
659 625
660 if ((cmd->flags & CMDF_ROUND_MASK) == CMDF_ROUND_NEAREST) { 626 if ((cmd->flags & CMDF_ROUND_MASK) == CMDF_ROUND_NEAREST) {
661 if (rest > 33) 627 if (rest > 33)
662 (*chan_ticks)++; 628 devpriv->ai_chan_ticks++;
663 } else if ((cmd->flags & CMDF_ROUND_MASK) == CMDF_ROUND_UP) { 629 } else if ((cmd->flags & CMDF_ROUND_MASK) == CMDF_ROUND_UP) {
664 if (rest) 630 if (rest)
665 (*chan_ticks)++; 631 devpriv->ai_chan_ticks++;
666 } 632 }
667 } 633 }
668
669 return 0;
670}
671
672static void ai_write_timer(struct comedi_device *dev,
673 unsigned int init_ticks,
674 unsigned int scan_ticks, unsigned int chan_ticks)
675{
676 outl(init_ticks - 1, dev->iobase + ME4000_AI_SCAN_PRE_TIMER_LOW_REG);
677 outl(0x0, dev->iobase + ME4000_AI_SCAN_PRE_TIMER_HIGH_REG);
678
679 if (scan_ticks) {
680 outl(scan_ticks - 1, dev->iobase + ME4000_AI_SCAN_TIMER_LOW_REG);
681 outl(0x0, dev->iobase + ME4000_AI_SCAN_TIMER_HIGH_REG);
682 }
683
684 outl(chan_ticks - 1, dev->iobase + ME4000_AI_CHAN_PRE_TIMER_REG);
685 outl(chan_ticks - 1, dev->iobase + ME4000_AI_CHAN_TIMER_REG);
686} 634}
687 635
688static int ai_write_chanlist(struct comedi_device *dev, 636static void me4000_ai_write_chanlist(struct comedi_device *dev,
689 struct comedi_subdevice *s, struct comedi_cmd *cmd) 637 struct comedi_subdevice *s,
638 struct comedi_cmd *cmd)
690{ 639{
691 unsigned int entry;
692 unsigned int chan;
693 unsigned int rang;
694 unsigned int aref;
695 int i; 640 int i;
696 641
697 for (i = 0; i < cmd->chanlist_len; i++) { 642 for (i = 0; i < cmd->chanlist_len; i++) {
698 chan = CR_CHAN(cmd->chanlist[i]); 643 unsigned int chan = CR_CHAN(cmd->chanlist[i]);
699 rang = CR_RANGE(cmd->chanlist[i]); 644 unsigned int range = CR_RANGE(cmd->chanlist[i]);
700 aref = CR_AREF(cmd->chanlist[i]); 645 unsigned int aref = CR_AREF(cmd->chanlist[i]);
701 646 unsigned int entry;
702 entry = chan;
703 647
704 if (rang == 0) 648 entry = chan | ME4000_AI_LIST_RANGE(range);
705 entry |= ME4000_AI_LIST_RANGE_UNIPOLAR_2_5;
706 else if (rang == 1)
707 entry |= ME4000_AI_LIST_RANGE_UNIPOLAR_10;
708 else if (rang == 2)
709 entry |= ME4000_AI_LIST_RANGE_BIPOLAR_2_5;
710 else
711 entry |= ME4000_AI_LIST_RANGE_BIPOLAR_10;
712 649
713 if (aref == AREF_DIFF) 650 if (aref == AREF_DIFF)
714 entry |= ME4000_AI_LIST_INPUT_DIFFERENTIAL; 651 entry |= ME4000_AI_LIST_INPUT_DIFFERENTIAL;
715 else 652
716 entry |= ME4000_AI_LIST_INPUT_SINGLE_ENDED; 653 if (i == (cmd->chanlist_len - 1))
654 entry |= ME4000_AI_LIST_LAST_ENTRY;
717 655
718 outl(entry, dev->iobase + ME4000_AI_CHANNEL_LIST_REG); 656 outl(entry, dev->iobase + ME4000_AI_CHANNEL_LIST_REG);
719 } 657 }
720
721 return 0;
722} 658}
723 659
724static int ai_prepare(struct comedi_device *dev, 660static int me4000_ai_do_cmd(struct comedi_device *dev,
725 struct comedi_subdevice *s, 661 struct comedi_subdevice *s)
726 struct comedi_cmd *cmd,
727 unsigned int init_ticks,
728 unsigned int scan_ticks, unsigned int chan_ticks)
729{ 662{
730 unsigned int tmp = 0; 663 struct me4000_private *devpriv = dev->private;
664 struct comedi_cmd *cmd = &s->async->cmd;
665 unsigned int ctrl;
731 666
732 /* Write timer arguments */ 667 /* Write timer arguments */
733 ai_write_timer(dev, init_ticks, scan_ticks, chan_ticks); 668 outl(devpriv->ai_init_ticks - 1,
669 dev->iobase + ME4000_AI_SCAN_PRE_TIMER_LOW_REG);
670 outl(0x0, dev->iobase + ME4000_AI_SCAN_PRE_TIMER_HIGH_REG);
671
672 if (devpriv->ai_scan_ticks) {
673 outl(devpriv->ai_scan_ticks - 1,
674 dev->iobase + ME4000_AI_SCAN_TIMER_LOW_REG);
675 outl(0x0, dev->iobase + ME4000_AI_SCAN_TIMER_HIGH_REG);
676 }
734 677
735 /* Reset control register */ 678 outl(devpriv->ai_chan_ticks - 1,
736 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG); 679 dev->iobase + ME4000_AI_CHAN_PRE_TIMER_REG);
680 outl(devpriv->ai_chan_ticks - 1,
681 dev->iobase + ME4000_AI_CHAN_TIMER_REG);
737 682
738 /* Start sources */ 683 /* Start sources */
739 if ((cmd->start_src == TRIG_EXT && 684 ctrl = devpriv->ai_ctrl_mode |
740 cmd->scan_begin_src == TRIG_TIMER && 685 ME4000_AI_CTRL_CHANNEL_FIFO |
741 cmd->convert_src == TRIG_TIMER) || 686 ME4000_AI_CTRL_DATA_FIFO;
742 (cmd->start_src == TRIG_EXT &&
743 cmd->scan_begin_src == TRIG_FOLLOW &&
744 cmd->convert_src == TRIG_TIMER)) {
745 tmp = ME4000_AI_CTRL_BIT_MODE_1 |
746 ME4000_AI_CTRL_BIT_CHANNEL_FIFO |
747 ME4000_AI_CTRL_BIT_DATA_FIFO;
748 } else if (cmd->start_src == TRIG_EXT &&
749 cmd->scan_begin_src == TRIG_EXT &&
750 cmd->convert_src == TRIG_TIMER) {
751 tmp = ME4000_AI_CTRL_BIT_MODE_2 |
752 ME4000_AI_CTRL_BIT_CHANNEL_FIFO |
753 ME4000_AI_CTRL_BIT_DATA_FIFO;
754 } else if (cmd->start_src == TRIG_EXT &&
755 cmd->scan_begin_src == TRIG_EXT &&
756 cmd->convert_src == TRIG_EXT) {
757 tmp = ME4000_AI_CTRL_BIT_MODE_0 |
758 ME4000_AI_CTRL_BIT_MODE_1 |
759 ME4000_AI_CTRL_BIT_CHANNEL_FIFO |
760 ME4000_AI_CTRL_BIT_DATA_FIFO;
761 } else {
762 tmp = ME4000_AI_CTRL_BIT_MODE_0 |
763 ME4000_AI_CTRL_BIT_CHANNEL_FIFO |
764 ME4000_AI_CTRL_BIT_DATA_FIFO;
765 }
766 687
767 /* Stop triggers */ 688 /* Stop triggers */
768 if (cmd->stop_src == TRIG_COUNT) { 689 if (cmd->stop_src == TRIG_COUNT) {
769 outl(cmd->chanlist_len * cmd->stop_arg, 690 outl(cmd->chanlist_len * cmd->stop_arg,
770 dev->iobase + ME4000_AI_SAMPLE_COUNTER_REG); 691 dev->iobase + ME4000_AI_SAMPLE_COUNTER_REG);
771 tmp |= ME4000_AI_CTRL_BIT_HF_IRQ | ME4000_AI_CTRL_BIT_SC_IRQ; 692 ctrl |= ME4000_AI_CTRL_SC_IRQ;
772 } else if (cmd->stop_src == TRIG_NONE && 693 } else if (cmd->stop_src == TRIG_NONE &&
773 cmd->scan_end_src == TRIG_COUNT) { 694 cmd->scan_end_src == TRIG_COUNT) {
774 outl(cmd->scan_end_arg, 695 outl(cmd->scan_end_arg,
775 dev->iobase + ME4000_AI_SAMPLE_COUNTER_REG); 696 dev->iobase + ME4000_AI_SAMPLE_COUNTER_REG);
776 tmp |= ME4000_AI_CTRL_BIT_HF_IRQ | ME4000_AI_CTRL_BIT_SC_IRQ; 697 ctrl |= ME4000_AI_CTRL_SC_IRQ;
777 } else {
778 tmp |= ME4000_AI_CTRL_BIT_HF_IRQ;
779 } 698 }
699 ctrl |= ME4000_AI_CTRL_HF_IRQ;
780 700
781 /* Write the setup to the control register */ 701 /* Write the setup to the control register */
782 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG); 702 outl(ctrl, dev->iobase + ME4000_AI_CTRL_REG);
783 703
784 /* Write the channel list */ 704 /* Write the channel list */
785 ai_write_chanlist(dev, s, cmd); 705 me4000_ai_write_chanlist(dev, s, cmd);
786
787 return 0;
788}
789
790static int me4000_ai_do_cmd(struct comedi_device *dev,
791 struct comedi_subdevice *s)
792{
793 int err;
794 unsigned int init_ticks = 0;
795 unsigned int scan_ticks = 0;
796 unsigned int chan_ticks = 0;
797 struct comedi_cmd *cmd = &s->async->cmd;
798
799 /* Reset the analog input */
800 err = me4000_ai_cancel(dev, s);
801 if (err)
802 return err;
803
804 /* Round the timer arguments */
805 err = ai_round_cmd_args(dev,
806 s, cmd, &init_ticks, &scan_ticks, &chan_ticks);
807 if (err)
808 return err;
809
810 /* Prepare the AI for acquisition */
811 err = ai_prepare(dev, s, cmd, init_ticks, scan_ticks, chan_ticks);
812 if (err)
813 return err;
814 706
815 /* Start acquistion by dummy read */ 707 /* Start acquistion by dummy read */
816 inl(dev->iobase + ME4000_AI_START_REG); 708 inl(dev->iobase + ME4000_AI_START_REG);
@@ -822,14 +714,9 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev,
822 struct comedi_subdevice *s, 714 struct comedi_subdevice *s,
823 struct comedi_cmd *cmd) 715 struct comedi_cmd *cmd)
824{ 716{
825 unsigned int init_ticks; 717 struct me4000_private *devpriv = dev->private;
826 unsigned int chan_ticks;
827 unsigned int scan_ticks;
828 int err = 0; 718 int err = 0;
829 719
830 /* Round the timer arguments */
831 ai_round_cmd_args(dev, s, cmd, &init_ticks, &scan_ticks, &chan_ticks);
832
833 /* Step 1 : check if triggers are trivially valid */ 720 /* Step 1 : check if triggers are trivially valid */
834 721
835 err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT); 722 err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
@@ -857,21 +744,28 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev,
857 if (cmd->start_src == TRIG_NOW && 744 if (cmd->start_src == TRIG_NOW &&
858 cmd->scan_begin_src == TRIG_TIMER && 745 cmd->scan_begin_src == TRIG_TIMER &&
859 cmd->convert_src == TRIG_TIMER) { 746 cmd->convert_src == TRIG_TIMER) {
747 devpriv->ai_ctrl_mode = ME4000_AI_CTRL_MODE_0;
860 } else if (cmd->start_src == TRIG_NOW && 748 } else if (cmd->start_src == TRIG_NOW &&
861 cmd->scan_begin_src == TRIG_FOLLOW && 749 cmd->scan_begin_src == TRIG_FOLLOW &&
862 cmd->convert_src == TRIG_TIMER) { 750 cmd->convert_src == TRIG_TIMER) {
751 devpriv->ai_ctrl_mode = ME4000_AI_CTRL_MODE_0;
863 } else if (cmd->start_src == TRIG_EXT && 752 } else if (cmd->start_src == TRIG_EXT &&
864 cmd->scan_begin_src == TRIG_TIMER && 753 cmd->scan_begin_src == TRIG_TIMER &&
865 cmd->convert_src == TRIG_TIMER) { 754 cmd->convert_src == TRIG_TIMER) {
755 devpriv->ai_ctrl_mode = ME4000_AI_CTRL_MODE_1;
866 } else if (cmd->start_src == TRIG_EXT && 756 } else if (cmd->start_src == TRIG_EXT &&
867 cmd->scan_begin_src == TRIG_FOLLOW && 757 cmd->scan_begin_src == TRIG_FOLLOW &&
868 cmd->convert_src == TRIG_TIMER) { 758 cmd->convert_src == TRIG_TIMER) {
759 devpriv->ai_ctrl_mode = ME4000_AI_CTRL_MODE_1;
869 } else if (cmd->start_src == TRIG_EXT && 760 } else if (cmd->start_src == TRIG_EXT &&
870 cmd->scan_begin_src == TRIG_EXT && 761 cmd->scan_begin_src == TRIG_EXT &&
871 cmd->convert_src == TRIG_TIMER) { 762 cmd->convert_src == TRIG_TIMER) {
763 devpriv->ai_ctrl_mode = ME4000_AI_CTRL_MODE_2;
872 } else if (cmd->start_src == TRIG_EXT && 764 } else if (cmd->start_src == TRIG_EXT &&
873 cmd->scan_begin_src == TRIG_EXT && 765 cmd->scan_begin_src == TRIG_EXT &&
874 cmd->convert_src == TRIG_EXT) { 766 cmd->convert_src == TRIG_EXT) {
767 devpriv->ai_ctrl_mode = ME4000_AI_CTRL_MODE_0 |
768 ME4000_AI_CTRL_MODE_1;
875 } else { 769 } else {
876 err |= -EINVAL; 770 err |= -EINVAL;
877 } 771 }
@@ -887,15 +781,19 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev,
887 cmd->chanlist_len = 1; 781 cmd->chanlist_len = 1;
888 err |= -EINVAL; 782 err |= -EINVAL;
889 } 783 }
890 if (init_ticks < 66) { 784
785 /* Round the timer arguments */
786 me4000_ai_round_cmd_args(dev, s, cmd);
787
788 if (devpriv->ai_init_ticks < 66) {
891 cmd->start_arg = 2000; 789 cmd->start_arg = 2000;
892 err |= -EINVAL; 790 err |= -EINVAL;
893 } 791 }
894 if (scan_ticks && scan_ticks < 67) { 792 if (devpriv->ai_scan_ticks && devpriv->ai_scan_ticks < 67) {
895 cmd->scan_begin_arg = 2031; 793 cmd->scan_begin_arg = 2031;
896 err |= -EINVAL; 794 err |= -EINVAL;
897 } 795 }
898 if (chan_ticks < 66) { 796 if (devpriv->ai_chan_ticks < 66) {
899 cmd->convert_arg = 2000; 797 cmd->convert_arg = 2000;
900 err |= -EINVAL; 798 err |= -EINVAL;
901 } 799 }
@@ -915,17 +813,18 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev,
915 cmd->scan_begin_src == TRIG_TIMER && 813 cmd->scan_begin_src == TRIG_TIMER &&
916 cmd->convert_src == TRIG_TIMER) { 814 cmd->convert_src == TRIG_TIMER) {
917 /* Check timer arguments */ 815 /* Check timer arguments */
918 if (init_ticks < ME4000_AI_MIN_TICKS) { 816 if (devpriv->ai_init_ticks < ME4000_AI_MIN_TICKS) {
919 dev_err(dev->class_dev, "Invalid start arg\n"); 817 dev_err(dev->class_dev, "Invalid start arg\n");
920 cmd->start_arg = 2000; /* 66 ticks at least */ 818 cmd->start_arg = 2000; /* 66 ticks at least */
921 err++; 819 err++;
922 } 820 }
923 if (chan_ticks < ME4000_AI_MIN_TICKS) { 821 if (devpriv->ai_chan_ticks < ME4000_AI_MIN_TICKS) {
924 dev_err(dev->class_dev, "Invalid convert arg\n"); 822 dev_err(dev->class_dev, "Invalid convert arg\n");
925 cmd->convert_arg = 2000; /* 66 ticks at least */ 823 cmd->convert_arg = 2000; /* 66 ticks at least */
926 err++; 824 err++;
927 } 825 }
928 if (scan_ticks <= cmd->chanlist_len * chan_ticks) { 826 if (devpriv->ai_scan_ticks <=
827 cmd->chanlist_len * devpriv->ai_chan_ticks) {
929 dev_err(dev->class_dev, "Invalid scan end arg\n"); 828 dev_err(dev->class_dev, "Invalid scan end arg\n");
930 829
931 /* At least one tick more */ 830 /* At least one tick more */
@@ -936,12 +835,12 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev,
936 cmd->scan_begin_src == TRIG_FOLLOW && 835 cmd->scan_begin_src == TRIG_FOLLOW &&
937 cmd->convert_src == TRIG_TIMER) { 836 cmd->convert_src == TRIG_TIMER) {
938 /* Check timer arguments */ 837 /* Check timer arguments */
939 if (init_ticks < ME4000_AI_MIN_TICKS) { 838 if (devpriv->ai_init_ticks < ME4000_AI_MIN_TICKS) {
940 dev_err(dev->class_dev, "Invalid start arg\n"); 839 dev_err(dev->class_dev, "Invalid start arg\n");
941 cmd->start_arg = 2000; /* 66 ticks at least */ 840 cmd->start_arg = 2000; /* 66 ticks at least */
942 err++; 841 err++;
943 } 842 }
944 if (chan_ticks < ME4000_AI_MIN_TICKS) { 843 if (devpriv->ai_chan_ticks < ME4000_AI_MIN_TICKS) {
945 dev_err(dev->class_dev, "Invalid convert arg\n"); 844 dev_err(dev->class_dev, "Invalid convert arg\n");
946 cmd->convert_arg = 2000; /* 66 ticks at least */ 845 cmd->convert_arg = 2000; /* 66 ticks at least */
947 err++; 846 err++;
@@ -950,17 +849,18 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev,
950 cmd->scan_begin_src == TRIG_TIMER && 849 cmd->scan_begin_src == TRIG_TIMER &&
951 cmd->convert_src == TRIG_TIMER) { 850 cmd->convert_src == TRIG_TIMER) {
952 /* Check timer arguments */ 851 /* Check timer arguments */
953 if (init_ticks < ME4000_AI_MIN_TICKS) { 852 if (devpriv->ai_init_ticks < ME4000_AI_MIN_TICKS) {
954 dev_err(dev->class_dev, "Invalid start arg\n"); 853 dev_err(dev->class_dev, "Invalid start arg\n");
955 cmd->start_arg = 2000; /* 66 ticks at least */ 854 cmd->start_arg = 2000; /* 66 ticks at least */
956 err++; 855 err++;
957 } 856 }
958 if (chan_ticks < ME4000_AI_MIN_TICKS) { 857 if (devpriv->ai_chan_ticks < ME4000_AI_MIN_TICKS) {
959 dev_err(dev->class_dev, "Invalid convert arg\n"); 858 dev_err(dev->class_dev, "Invalid convert arg\n");
960 cmd->convert_arg = 2000; /* 66 ticks at least */ 859 cmd->convert_arg = 2000; /* 66 ticks at least */
961 err++; 860 err++;
962 } 861 }
963 if (scan_ticks <= cmd->chanlist_len * chan_ticks) { 862 if (devpriv->ai_scan_ticks <=
863 cmd->chanlist_len * devpriv->ai_chan_ticks) {
964 dev_err(dev->class_dev, "Invalid scan end arg\n"); 864 dev_err(dev->class_dev, "Invalid scan end arg\n");
965 865
966 /* At least one tick more */ 866 /* At least one tick more */
@@ -971,12 +871,12 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev,
971 cmd->scan_begin_src == TRIG_FOLLOW && 871 cmd->scan_begin_src == TRIG_FOLLOW &&
972 cmd->convert_src == TRIG_TIMER) { 872 cmd->convert_src == TRIG_TIMER) {
973 /* Check timer arguments */ 873 /* Check timer arguments */
974 if (init_ticks < ME4000_AI_MIN_TICKS) { 874 if (devpriv->ai_init_ticks < ME4000_AI_MIN_TICKS) {
975 dev_err(dev->class_dev, "Invalid start arg\n"); 875 dev_err(dev->class_dev, "Invalid start arg\n");
976 cmd->start_arg = 2000; /* 66 ticks at least */ 876 cmd->start_arg = 2000; /* 66 ticks at least */
977 err++; 877 err++;
978 } 878 }
979 if (chan_ticks < ME4000_AI_MIN_TICKS) { 879 if (devpriv->ai_chan_ticks < ME4000_AI_MIN_TICKS) {
980 dev_err(dev->class_dev, "Invalid convert arg\n"); 880 dev_err(dev->class_dev, "Invalid convert arg\n");
981 cmd->convert_arg = 2000; /* 66 ticks at least */ 881 cmd->convert_arg = 2000; /* 66 ticks at least */
982 err++; 882 err++;
@@ -985,12 +885,12 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev,
985 cmd->scan_begin_src == TRIG_EXT && 885 cmd->scan_begin_src == TRIG_EXT &&
986 cmd->convert_src == TRIG_TIMER) { 886 cmd->convert_src == TRIG_TIMER) {
987 /* Check timer arguments */ 887 /* Check timer arguments */
988 if (init_ticks < ME4000_AI_MIN_TICKS) { 888 if (devpriv->ai_init_ticks < ME4000_AI_MIN_TICKS) {
989 dev_err(dev->class_dev, "Invalid start arg\n"); 889 dev_err(dev->class_dev, "Invalid start arg\n");
990 cmd->start_arg = 2000; /* 66 ticks at least */ 890 cmd->start_arg = 2000; /* 66 ticks at least */
991 err++; 891 err++;
992 } 892 }
993 if (chan_ticks < ME4000_AI_MIN_TICKS) { 893 if (devpriv->ai_chan_ticks < ME4000_AI_MIN_TICKS) {
994 dev_err(dev->class_dev, "Invalid convert arg\n"); 894 dev_err(dev->class_dev, "Invalid convert arg\n");
995 cmd->convert_arg = 2000; /* 66 ticks at least */ 895 cmd->convert_arg = 2000; /* 66 ticks at least */
996 err++; 896 err++;
@@ -999,7 +899,7 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev,
999 cmd->scan_begin_src == TRIG_EXT && 899 cmd->scan_begin_src == TRIG_EXT &&
1000 cmd->convert_src == TRIG_EXT) { 900 cmd->convert_src == TRIG_EXT) {
1001 /* Check timer arguments */ 901 /* Check timer arguments */
1002 if (init_ticks < ME4000_AI_MIN_TICKS) { 902 if (devpriv->ai_init_ticks < ME4000_AI_MIN_TICKS) {
1003 dev_err(dev->class_dev, "Invalid start arg\n"); 903 dev_err(dev->class_dev, "Invalid start arg\n");
1004 cmd->start_arg = 2000; /* 66 ticks at least */ 904 cmd->start_arg = 2000; /* 66 ticks at least */
1005 err++; 905 err++;
@@ -1039,103 +939,57 @@ static irqreturn_t me4000_ai_isr(int irq, void *dev_id)
1039 return IRQ_NONE; 939 return IRQ_NONE;
1040 940
1041 if (inl(dev->iobase + ME4000_IRQ_STATUS_REG) & 941 if (inl(dev->iobase + ME4000_IRQ_STATUS_REG) &
1042 ME4000_IRQ_STATUS_BIT_AI_HF) { 942 ME4000_IRQ_STATUS_AI_HF) {
1043 /* Read status register to find out what happened */ 943 /* Read status register to find out what happened */
1044 tmp = inl(dev->iobase + ME4000_AI_CTRL_REG); 944 tmp = inl(dev->iobase + ME4000_AI_STATUS_REG);
1045
1046 if (!(tmp & ME4000_AI_STATUS_BIT_FF_DATA) &&
1047 !(tmp & ME4000_AI_STATUS_BIT_HF_DATA) &&
1048 (tmp & ME4000_AI_STATUS_BIT_EF_DATA)) {
1049 c = ME4000_AI_FIFO_COUNT;
1050
1051 /*
1052 * FIFO overflow, so stop conversion
1053 * and disable all interrupts
1054 */
1055 tmp |= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP;
1056 tmp &= ~(ME4000_AI_CTRL_BIT_HF_IRQ |
1057 ME4000_AI_CTRL_BIT_SC_IRQ);
1058 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG);
1059
1060 s->async->events |= COMEDI_CB_ERROR;
1061 945
946 if (!(tmp & ME4000_AI_STATUS_FF_DATA) &&
947 !(tmp & ME4000_AI_STATUS_HF_DATA) &&
948 (tmp & ME4000_AI_STATUS_EF_DATA)) {
1062 dev_err(dev->class_dev, "FIFO overflow\n"); 949 dev_err(dev->class_dev, "FIFO overflow\n");
1063 } else if ((tmp & ME4000_AI_STATUS_BIT_FF_DATA) 950 s->async->events |= COMEDI_CB_ERROR;
1064 && !(tmp & ME4000_AI_STATUS_BIT_HF_DATA) 951 c = ME4000_AI_FIFO_COUNT;
1065 && (tmp & ME4000_AI_STATUS_BIT_EF_DATA)) { 952 } else if ((tmp & ME4000_AI_STATUS_FF_DATA) &&
953 !(tmp & ME4000_AI_STATUS_HF_DATA) &&
954 (tmp & ME4000_AI_STATUS_EF_DATA)) {
1066 c = ME4000_AI_FIFO_COUNT / 2; 955 c = ME4000_AI_FIFO_COUNT / 2;
1067 } else { 956 } else {
1068 dev_err(dev->class_dev,
1069 "Can't determine state of fifo\n");
1070 c = 0;
1071
1072 /*
1073 * Undefined state, so stop conversion
1074 * and disable all interrupts
1075 */
1076 tmp |= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP;
1077 tmp &= ~(ME4000_AI_CTRL_BIT_HF_IRQ |
1078 ME4000_AI_CTRL_BIT_SC_IRQ);
1079 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG);
1080
1081 s->async->events |= COMEDI_CB_ERROR;
1082
1083 dev_err(dev->class_dev, "Undefined FIFO state\n"); 957 dev_err(dev->class_dev, "Undefined FIFO state\n");
958 s->async->events |= COMEDI_CB_ERROR;
959 c = 0;
1084 } 960 }
1085 961
1086 for (i = 0; i < c; i++) { 962 for (i = 0; i < c; i++) {
1087 /* Read value from data fifo */ 963 lval = me4000_ai_get_sample(dev, s);
1088 lval = inl(dev->iobase + ME4000_AI_DATA_REG) & 0xFFFF; 964 if (!comedi_buf_write_samples(s, &lval, 1))
1089 lval ^= 0x8000;
1090
1091 if (!comedi_buf_write_samples(s, &lval, 1)) {
1092 /*
1093 * Buffer overflow, so stop conversion
1094 * and disable all interrupts
1095 */
1096 tmp |= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP;
1097 tmp &= ~(ME4000_AI_CTRL_BIT_HF_IRQ |
1098 ME4000_AI_CTRL_BIT_SC_IRQ);
1099 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG);
1100 break; 965 break;
1101 }
1102 } 966 }
1103 967
1104 /* Work is done, so reset the interrupt */ 968 /* Work is done, so reset the interrupt */
1105 tmp |= ME4000_AI_CTRL_BIT_HF_IRQ_RESET; 969 tmp |= ME4000_AI_CTRL_HF_IRQ_RESET;
1106 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG); 970 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG);
1107 tmp &= ~ME4000_AI_CTRL_BIT_HF_IRQ_RESET; 971 tmp &= ~ME4000_AI_CTRL_HF_IRQ_RESET;
1108 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG); 972 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG);
1109 } 973 }
1110 974
1111 if (inl(dev->iobase + ME4000_IRQ_STATUS_REG) & 975 if (inl(dev->iobase + ME4000_IRQ_STATUS_REG) &
1112 ME4000_IRQ_STATUS_BIT_SC) { 976 ME4000_IRQ_STATUS_SC) {
977 /* Acquisition is complete */
1113 s->async->events |= COMEDI_CB_EOA; 978 s->async->events |= COMEDI_CB_EOA;
1114 979
1115 /*
1116 * Acquisition is complete, so stop
1117 * conversion and disable all interrupts
1118 */
1119 tmp = inl(dev->iobase + ME4000_AI_CTRL_REG);
1120 tmp |= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP;
1121 tmp &= ~(ME4000_AI_CTRL_BIT_HF_IRQ | ME4000_AI_CTRL_BIT_SC_IRQ);
1122 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG);
1123
1124 /* Poll data until fifo empty */ 980 /* Poll data until fifo empty */
1125 while (inl(dev->iobase + ME4000_AI_CTRL_REG) & 981 while (inl(dev->iobase + ME4000_AI_STATUS_REG) &
1126 ME4000_AI_STATUS_BIT_EF_DATA) { 982 ME4000_AI_STATUS_EF_DATA) {
1127 /* Read value from data fifo */ 983 lval = me4000_ai_get_sample(dev, s);
1128 lval = inl(dev->iobase + ME4000_AI_DATA_REG) & 0xFFFF;
1129 lval ^= 0x8000;
1130
1131 if (!comedi_buf_write_samples(s, &lval, 1)) 984 if (!comedi_buf_write_samples(s, &lval, 1))
1132 break; 985 break;
1133 } 986 }
1134 987
1135 /* Work is done, so reset the interrupt */ 988 /* Work is done, so reset the interrupt */
1136 tmp |= ME4000_AI_CTRL_BIT_SC_IRQ_RESET; 989 tmp = inl(dev->iobase + ME4000_AI_CTRL_REG);
990 tmp |= ME4000_AI_CTRL_SC_IRQ_RESET;
1137 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG); 991 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG);
1138 tmp &= ~ME4000_AI_CTRL_BIT_SC_IRQ_RESET; 992 tmp &= ~ME4000_AI_CTRL_SC_IRQ_RESET;
1139 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG); 993 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG);
1140 } 994 }
1141 995
@@ -1149,12 +1003,12 @@ static int me4000_ao_insn_write(struct comedi_device *dev,
1149 struct comedi_insn *insn, 1003 struct comedi_insn *insn,
1150 unsigned int *data) 1004 unsigned int *data)
1151{ 1005{
1152 int chan = CR_CHAN(insn->chanspec); 1006 unsigned int chan = CR_CHAN(insn->chanspec);
1153 unsigned int tmp; 1007 unsigned int tmp;
1154 1008
1155 /* Stop any running conversion */ 1009 /* Stop any running conversion */
1156 tmp = inl(dev->iobase + ME4000_AO_CTRL_REG(chan)); 1010 tmp = inl(dev->iobase + ME4000_AO_CTRL_REG(chan));
1157 tmp |= ME4000_AO_CTRL_BIT_IMMEDIATE_STOP; 1011 tmp |= ME4000_AO_CTRL_IMMEDIATE_STOP;
1158 outl(tmp, dev->iobase + ME4000_AO_CTRL_REG(chan)); 1012 outl(tmp, dev->iobase + ME4000_AO_CTRL_REG(chan));
1159 1013
1160 /* Clear control register and set to single mode */ 1014 /* Clear control register and set to single mode */
@@ -1217,18 +1071,18 @@ static int me4000_dio_insn_config(struct comedi_device *dev,
1217 return ret; 1071 return ret;
1218 1072
1219 tmp = inl(dev->iobase + ME4000_DIO_CTRL_REG); 1073 tmp = inl(dev->iobase + ME4000_DIO_CTRL_REG);
1220 tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_0 | ME4000_DIO_CTRL_BIT_MODE_1 | 1074 tmp &= ~(ME4000_DIO_CTRL_MODE_0 | ME4000_DIO_CTRL_MODE_1 |
1221 ME4000_DIO_CTRL_BIT_MODE_2 | ME4000_DIO_CTRL_BIT_MODE_3 | 1075 ME4000_DIO_CTRL_MODE_2 | ME4000_DIO_CTRL_MODE_3 |
1222 ME4000_DIO_CTRL_BIT_MODE_4 | ME4000_DIO_CTRL_BIT_MODE_5 | 1076 ME4000_DIO_CTRL_MODE_4 | ME4000_DIO_CTRL_MODE_5 |
1223 ME4000_DIO_CTRL_BIT_MODE_6 | ME4000_DIO_CTRL_BIT_MODE_7); 1077 ME4000_DIO_CTRL_MODE_6 | ME4000_DIO_CTRL_MODE_7);
1224 if (s->io_bits & 0x000000ff) 1078 if (s->io_bits & 0x000000ff)
1225 tmp |= ME4000_DIO_CTRL_BIT_MODE_0; 1079 tmp |= ME4000_DIO_CTRL_MODE_0;
1226 if (s->io_bits & 0x0000ff00) 1080 if (s->io_bits & 0x0000ff00)
1227 tmp |= ME4000_DIO_CTRL_BIT_MODE_2; 1081 tmp |= ME4000_DIO_CTRL_MODE_2;
1228 if (s->io_bits & 0x00ff0000) 1082 if (s->io_bits & 0x00ff0000)
1229 tmp |= ME4000_DIO_CTRL_BIT_MODE_4; 1083 tmp |= ME4000_DIO_CTRL_MODE_4;
1230 if (s->io_bits & 0xff000000) 1084 if (s->io_bits & 0xff000000)
1231 tmp |= ME4000_DIO_CTRL_BIT_MODE_6; 1085 tmp |= ME4000_DIO_CTRL_MODE_6;
1232 1086
1233 /* 1087 /*
1234 * Check for optoisolated ME-4000 version. 1088 * Check for optoisolated ME-4000 version.
@@ -1238,9 +1092,8 @@ static int me4000_dio_insn_config(struct comedi_device *dev,
1238 if (inl(dev->iobase + ME4000_DIO_DIR_REG)) { 1092 if (inl(dev->iobase + ME4000_DIO_DIR_REG)) {
1239 s->io_bits |= 0x000000ff; 1093 s->io_bits |= 0x000000ff;
1240 s->io_bits &= ~0x0000ff00; 1094 s->io_bits &= ~0x0000ff00;
1241 tmp |= ME4000_DIO_CTRL_BIT_MODE_0; 1095 tmp |= ME4000_DIO_CTRL_MODE_0;
1242 tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_2 | 1096 tmp &= ~(ME4000_DIO_CTRL_MODE_2 | ME4000_DIO_CTRL_MODE_3);
1243 ME4000_DIO_CTRL_BIT_MODE_3);
1244 } 1097 }
1245 1098
1246 outl(tmp, dev->iobase + ME4000_DIO_CTRL_REG); 1099 outl(tmp, dev->iobase + ME4000_DIO_CTRL_REG);
@@ -1253,7 +1106,7 @@ static int me4000_auto_attach(struct comedi_device *dev,
1253{ 1106{
1254 struct pci_dev *pcidev = comedi_to_pci_dev(dev); 1107 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
1255 const struct me4000_board *board = NULL; 1108 const struct me4000_board *board = NULL;
1256 struct me4000_info *info; 1109 struct me4000_private *devpriv;
1257 struct comedi_subdevice *s; 1110 struct comedi_subdevice *s;
1258 int result; 1111 int result;
1259 1112
@@ -1264,17 +1117,17 @@ static int me4000_auto_attach(struct comedi_device *dev,
1264 dev->board_ptr = board; 1117 dev->board_ptr = board;
1265 dev->board_name = board->name; 1118 dev->board_name = board->name;
1266 1119
1267 info = comedi_alloc_devpriv(dev, sizeof(*info)); 1120 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
1268 if (!info) 1121 if (!devpriv)
1269 return -ENOMEM; 1122 return -ENOMEM;
1270 1123
1271 result = comedi_pci_enable(dev); 1124 result = comedi_pci_enable(dev);
1272 if (result) 1125 if (result)
1273 return result; 1126 return result;
1274 1127
1275 info->plx_regbase = pci_resource_start(pcidev, 1); 1128 devpriv->plx_regbase = pci_resource_start(pcidev, 1);
1276 dev->iobase = pci_resource_start(pcidev, 2); 1129 dev->iobase = pci_resource_start(pcidev, 2);
1277 if (!info->plx_regbase || !dev->iobase) 1130 if (!devpriv->plx_regbase || !dev->iobase)
1278 return -ENODEV; 1131 return -ENODEV;
1279 1132
1280 result = comedi_load_firmware(dev, &pcidev->dev, ME4000_FIRMWARE, 1133 result = comedi_load_firmware(dev, &pcidev->dev, ME4000_FIRMWARE,
@@ -1287,79 +1140,66 @@ static int me4000_auto_attach(struct comedi_device *dev,
1287 if (pcidev->irq > 0) { 1140 if (pcidev->irq > 0) {
1288 result = request_irq(pcidev->irq, me4000_ai_isr, IRQF_SHARED, 1141 result = request_irq(pcidev->irq, me4000_ai_isr, IRQF_SHARED,
1289 dev->board_name, dev); 1142 dev->board_name, dev);
1290 if (result == 0) 1143 if (result == 0) {
1291 dev->irq = pcidev->irq; 1144 dev->irq = pcidev->irq;
1145
1146 /* Enable interrupts on the PLX */
1147 outl(PLX9052_INTCSR_LI1ENAB | PLX9052_INTCSR_LI1POL |
1148 PLX9052_INTCSR_PCIENAB,
1149 devpriv->plx_regbase + PLX9052_INTCSR);
1150 }
1292 } 1151 }
1293 1152
1294 result = comedi_alloc_subdevices(dev, 4); 1153 result = comedi_alloc_subdevices(dev, 4);
1295 if (result) 1154 if (result)
1296 return result; 1155 return result;
1297 1156
1298 /*========================================================================= 1157 /* Analog Input subdevice */
1299 Analog input subdevice
1300 ========================================================================*/
1301
1302 s = &dev->subdevices[0]; 1158 s = &dev->subdevices[0];
1303 1159 s->type = COMEDI_SUBD_AI;
1304 if (board->ai_nchan) { 1160 s->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_GROUND;
1305 s->type = COMEDI_SUBD_AI; 1161 if (board->can_do_diff_ai)
1306 s->subdev_flags = 1162 s->subdev_flags |= SDF_DIFF;
1307 SDF_READABLE | SDF_COMMON | SDF_GROUND | SDF_DIFF; 1163 s->n_chan = board->ai_nchan;
1308 s->n_chan = board->ai_nchan; 1164 s->maxdata = 0xffff;
1309 s->maxdata = 0xFFFF; /* 16 bit ADC */ 1165 s->len_chanlist = ME4000_AI_CHANNEL_LIST_COUNT;
1310 s->len_chanlist = ME4000_AI_CHANNEL_LIST_COUNT; 1166 s->range_table = &me4000_ai_range;
1311 s->range_table = &me4000_ai_range; 1167 s->insn_read = me4000_ai_insn_read;
1312 s->insn_read = me4000_ai_insn_read; 1168
1313 1169 if (dev->irq) {
1314 if (dev->irq) { 1170 dev->read_subdev = s;
1315 dev->read_subdev = s; 1171 s->subdev_flags |= SDF_CMD_READ;
1316 s->subdev_flags |= SDF_CMD_READ; 1172 s->cancel = me4000_ai_cancel;
1317 s->cancel = me4000_ai_cancel; 1173 s->do_cmdtest = me4000_ai_do_cmd_test;
1318 s->do_cmdtest = me4000_ai_do_cmd_test; 1174 s->do_cmd = me4000_ai_do_cmd;
1319 s->do_cmd = me4000_ai_do_cmd;
1320 }
1321 } else {
1322 s->type = COMEDI_SUBD_UNUSED;
1323 } 1175 }
1324 1176
1325 /*========================================================================= 1177 /* Analog Output subdevice */
1326 Analog output subdevice
1327 ========================================================================*/
1328
1329 s = &dev->subdevices[1]; 1178 s = &dev->subdevices[1];
1330 1179 if (board->has_ao) {
1331 if (board->ao_nchan) { 1180 s->type = COMEDI_SUBD_AO;
1332 s->type = COMEDI_SUBD_AO; 1181 s->subdev_flags = SDF_WRITABLE | SDF_COMMON | SDF_GROUND;
1333 s->subdev_flags = SDF_WRITABLE | SDF_COMMON | SDF_GROUND; 1182 s->n_chan = 4;
1334 s->n_chan = board->ao_nchan; 1183 s->maxdata = 0xffff;
1335 s->maxdata = 0xFFFF; /* 16 bit DAC */ 1184 s->range_table = &range_bipolar10;
1336 s->range_table = &range_bipolar10; 1185 s->insn_write = me4000_ao_insn_write;
1337 s->insn_write = me4000_ao_insn_write;
1338 1186
1339 result = comedi_alloc_subdev_readback(s); 1187 result = comedi_alloc_subdev_readback(s);
1340 if (result) 1188 if (result)
1341 return result; 1189 return result;
1342 } else { 1190 } else {
1343 s->type = COMEDI_SUBD_UNUSED; 1191 s->type = COMEDI_SUBD_UNUSED;
1344 } 1192 }
1345 1193
1346 /*========================================================================= 1194 /* Digital I/O subdevice */
1347 Digital I/O subdevice
1348 ========================================================================*/
1349
1350 s = &dev->subdevices[2]; 1195 s = &dev->subdevices[2];
1351 1196 s->type = COMEDI_SUBD_DIO;
1352 if (board->dio_nchan) { 1197 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
1353 s->type = COMEDI_SUBD_DIO; 1198 s->n_chan = 32;
1354 s->subdev_flags = SDF_READABLE | SDF_WRITABLE; 1199 s->maxdata = 1;
1355 s->n_chan = board->dio_nchan; 1200 s->range_table = &range_digital;
1356 s->maxdata = 1; 1201 s->insn_bits = me4000_dio_insn_bits;
1357 s->range_table = &range_digital; 1202 s->insn_config = me4000_dio_insn_config;
1358 s->insn_bits = me4000_dio_insn_bits;
1359 s->insn_config = me4000_dio_insn_config;
1360 } else {
1361 s->type = COMEDI_SUBD_UNUSED;
1362 }
1363 1203
1364 /* 1204 /*
1365 * Check for optoisolated ME-4000 version. If one the first 1205 * Check for optoisolated ME-4000 version. If one the first
@@ -1367,7 +1207,7 @@ static int me4000_auto_attach(struct comedi_device *dev,
1367 */ 1207 */
1368 if (!inl(dev->iobase + ME4000_DIO_DIR_REG)) { 1208 if (!inl(dev->iobase + ME4000_DIO_DIR_REG)) {
1369 s->io_bits |= 0xFF; 1209 s->io_bits |= 0xFF;
1370 outl(ME4000_DIO_CTRL_BIT_MODE_0, 1210 outl(ME4000_DIO_CTRL_MODE_0,
1371 dev->iobase + ME4000_DIO_DIR_REG); 1211 dev->iobase + ME4000_DIO_DIR_REG);
1372 } 1212 }
1373 1213
@@ -1393,8 +1233,12 @@ static int me4000_auto_attach(struct comedi_device *dev,
1393 1233
1394static void me4000_detach(struct comedi_device *dev) 1234static void me4000_detach(struct comedi_device *dev)
1395{ 1235{
1396 if (dev->iobase) 1236 if (dev->irq) {
1397 me4000_reset(dev); 1237 struct me4000_private *devpriv = dev->private;
1238
1239 /* Disable interrupts on the PLX */
1240 outl(0, devpriv->plx_regbase + PLX9052_INTCSR);
1241 }
1398 comedi_pci_detach(dev); 1242 comedi_pci_detach(dev);
1399} 1243}
1400 1244
@@ -1438,6 +1282,6 @@ static struct pci_driver me4000_pci_driver = {
1438module_comedi_pci_driver(me4000_driver, me4000_pci_driver); 1282module_comedi_pci_driver(me4000_driver, me4000_pci_driver);
1439 1283
1440MODULE_AUTHOR("Comedi http://www.comedi.org"); 1284MODULE_AUTHOR("Comedi http://www.comedi.org");
1441MODULE_DESCRIPTION("Comedi low-level driver"); 1285MODULE_DESCRIPTION("Comedi driver for Meilhaus ME-4000 series boards");
1442MODULE_LICENSE("GPL"); 1286MODULE_LICENSE("GPL");
1443MODULE_FIRMWARE(ME4000_FIRMWARE); 1287MODULE_FIRMWARE(ME4000_FIRMWARE);
diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c
index a208cb348437..d9de83ab0267 100644
--- a/drivers/staging/comedi/drivers/ni_daq_dio24.c
+++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c
@@ -55,11 +55,7 @@ static int dio24_auto_attach(struct comedi_device *dev,
55 55
56 /* 8255 dio */ 56 /* 8255 dio */
57 s = &dev->subdevices[0]; 57 s = &dev->subdevices[0];
58 ret = subdev_8255_init(dev, s, NULL, 0x00); 58 return subdev_8255_init(dev, s, NULL, 0x00);
59 if (ret)
60 return ret;
61
62 return 0;
63} 59}
64 60
65static struct comedi_driver driver_dio24 = { 61static struct comedi_driver driver_dio24 = {
diff --git a/drivers/staging/comedi/drivers/ni_usb6501.c b/drivers/staging/comedi/drivers/ni_usb6501.c
index 5f649f88d55c..88de8da3eff3 100644
--- a/drivers/staging/comedi/drivers/ni_usb6501.c
+++ b/drivers/staging/comedi/drivers/ni_usb6501.c
@@ -172,7 +172,7 @@ struct ni6501_private {
172}; 172};
173 173
174static int ni6501_port_command(struct comedi_device *dev, int command, 174static int ni6501_port_command(struct comedi_device *dev, int command,
175 const u8 *port, u8 *bitmap) 175 unsigned int val, u8 *bitmap)
176{ 176{
177 struct usb_device *usb = comedi_to_usb_dev(dev); 177 struct usb_device *usb = comedi_to_usb_dev(dev);
178 struct ni6501_private *devpriv = dev->private; 178 struct ni6501_private *devpriv = dev->private;
@@ -190,22 +190,22 @@ static int ni6501_port_command(struct comedi_device *dev, int command,
190 request_size = sizeof(READ_PORT_REQUEST); 190 request_size = sizeof(READ_PORT_REQUEST);
191 response_size = sizeof(READ_PORT_RESPONSE); 191 response_size = sizeof(READ_PORT_RESPONSE);
192 memcpy(tx, READ_PORT_REQUEST, request_size); 192 memcpy(tx, READ_PORT_REQUEST, request_size);
193 tx[14] = port[0]; 193 tx[14] = val & 0xff;
194 break; 194 break;
195 case WRITE_PORT: 195 case WRITE_PORT:
196 request_size = sizeof(WRITE_PORT_REQUEST); 196 request_size = sizeof(WRITE_PORT_REQUEST);
197 response_size = sizeof(GENERIC_RESPONSE); 197 response_size = sizeof(GENERIC_RESPONSE);
198 memcpy(tx, WRITE_PORT_REQUEST, request_size); 198 memcpy(tx, WRITE_PORT_REQUEST, request_size);
199 tx[14] = port[0]; 199 tx[14] = val & 0xff;
200 tx[17] = bitmap[0]; 200 tx[17] = *bitmap;
201 break; 201 break;
202 case SET_PORT_DIR: 202 case SET_PORT_DIR:
203 request_size = sizeof(SET_PORT_DIR_REQUEST); 203 request_size = sizeof(SET_PORT_DIR_REQUEST);
204 response_size = sizeof(GENERIC_RESPONSE); 204 response_size = sizeof(GENERIC_RESPONSE);
205 memcpy(tx, SET_PORT_DIR_REQUEST, request_size); 205 memcpy(tx, SET_PORT_DIR_REQUEST, request_size);
206 tx[14] = port[0]; 206 tx[14] = val & 0xff;
207 tx[15] = port[1]; 207 tx[15] = (val >> 8) & 0xff;
208 tx[16] = port[2]; 208 tx[16] = (val >> 16) & 0xff;
209 break; 209 break;
210 default: 210 default:
211 ret = -EINVAL; 211 ret = -EINVAL;
@@ -235,7 +235,7 @@ static int ni6501_port_command(struct comedi_device *dev, int command,
235 /* Check if results are valid */ 235 /* Check if results are valid */
236 236
237 if (command == READ_PORT) { 237 if (command == READ_PORT) {
238 bitmap[0] = devpriv->usb_rx_buf[14]; 238 *bitmap = devpriv->usb_rx_buf[14];
239 /* mask bitmap for comparing */ 239 /* mask bitmap for comparing */
240 devpriv->usb_rx_buf[14] = 0x00; 240 devpriv->usb_rx_buf[14] = 0x00;
241 241
@@ -349,17 +349,12 @@ static int ni6501_dio_insn_config(struct comedi_device *dev,
349 unsigned int *data) 349 unsigned int *data)
350{ 350{
351 int ret; 351 int ret;
352 u8 port[3];
353 352
354 ret = comedi_dio_insn_config(dev, s, insn, data, 0); 353 ret = comedi_dio_insn_config(dev, s, insn, data, 0);
355 if (ret) 354 if (ret)
356 return ret; 355 return ret;
357 356
358 port[0] = (s->io_bits) & 0xff; 357 ret = ni6501_port_command(dev, SET_PORT_DIR, s->io_bits, NULL);
359 port[1] = (s->io_bits >> 8) & 0xff;
360 port[2] = (s->io_bits >> 16) & 0xff;
361
362 ret = ni6501_port_command(dev, SET_PORT_DIR, port, NULL);
363 if (ret) 358 if (ret)
364 return ret; 359 return ret;
365 360
@@ -382,7 +377,7 @@ static int ni6501_dio_insn_bits(struct comedi_device *dev,
382 if (mask & (0xFF << port * 8)) { 377 if (mask & (0xFF << port * 8)) {
383 bitmap = (s->state >> port * 8) & 0xFF; 378 bitmap = (s->state >> port * 8) & 0xFF;
384 ret = ni6501_port_command(dev, WRITE_PORT, 379 ret = ni6501_port_command(dev, WRITE_PORT,
385 &port, &bitmap); 380 port, &bitmap);
386 if (ret) 381 if (ret)
387 return ret; 382 return ret;
388 } 383 }
@@ -391,7 +386,7 @@ static int ni6501_dio_insn_bits(struct comedi_device *dev,
391 data[1] = 0; 386 data[1] = 0;
392 387
393 for (port = 0; port < 3; port++) { 388 for (port = 0; port < 3; port++) {
394 ret = ni6501_port_command(dev, READ_PORT, &port, &bitmap); 389 ret = ni6501_port_command(dev, READ_PORT, port, &bitmap);
395 if (ret) 390 if (ret)
396 return ret; 391 return ret;
397 data[1] |= bitmap << port * 8; 392 data[1] |= bitmap << port * 8;
diff --git a/drivers/staging/comedi/drivers/pcl816.c b/drivers/staging/comedi/drivers/pcl816.c
index 781b321587dc..a353d1b155bb 100644
--- a/drivers/staging/comedi/drivers/pcl816.c
+++ b/drivers/staging/comedi/drivers/pcl816.c
@@ -305,7 +305,7 @@ static int check_channel_list(struct comedi_device *dev,
305 chansegment[0] = chanlist[0]; 305 chansegment[0] = chanlist[0];
306 for (i = 1, seglen = 1; i < chanlen; i++, seglen++) { 306 for (i = 1, seglen = 1; i < chanlen; i++, seglen++) {
307 /* we detect loop, this must by finish */ 307 /* we detect loop, this must by finish */
308 if (chanlist[0] == chanlist[i]) 308 if (chanlist[0] == chanlist[i])
309 break; 309 break;
310 nowmustbechan = 310 nowmustbechan =
311 (CR_CHAN(chansegment[i - 1]) + 1) % chanlen; 311 (CR_CHAN(chansegment[i - 1]) + 1) % chanlen;
diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c
index 781918d8d85f..35f0f676eb28 100644
--- a/drivers/staging/comedi/drivers/s626.c
+++ b/drivers/staging/comedi/drivers/s626.c
@@ -2852,11 +2852,7 @@ static int s626_auto_attach(struct comedi_device *dev,
2852 s->insn_read = s626_enc_insn_read; 2852 s->insn_read = s626_enc_insn_read;
2853 s->insn_write = s626_enc_insn_write; 2853 s->insn_write = s626_enc_insn_write;
2854 2854
2855 ret = s626_initialize(dev); 2855 return s626_initialize(dev);
2856 if (ret)
2857 return ret;
2858
2859 return 0;
2860} 2856}
2861 2857
2862static void s626_detach(struct comedi_device *dev) 2858static void s626_detach(struct comedi_device *dev)
diff --git a/drivers/staging/comedi/drivers/serial2002.c b/drivers/staging/comedi/drivers/serial2002.c
index 83da162deb52..5f19374c460d 100644
--- a/drivers/staging/comedi/drivers/serial2002.c
+++ b/drivers/staging/comedi/drivers/serial2002.c
@@ -32,6 +32,7 @@ Status: in development
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/sched.h> 33#include <linux/sched.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/ktime.h>
35 36
36#include <linux/termios.h> 37#include <linux/termios.h>
37#include <asm/ioctls.h> 38#include <asm/ioctls.h>
@@ -121,9 +122,9 @@ static int serial2002_tty_write(struct file *f, unsigned char *buf, int count)
121static void serial2002_tty_read_poll_wait(struct file *f, int timeout) 122static void serial2002_tty_read_poll_wait(struct file *f, int timeout)
122{ 123{
123 struct poll_wqueues table; 124 struct poll_wqueues table;
124 struct timeval start, now; 125 ktime_t start, now;
125 126
126 do_gettimeofday(&start); 127 start = ktime_get();
127 poll_initwait(&table); 128 poll_initwait(&table);
128 while (1) { 129 while (1) {
129 long elapsed; 130 long elapsed;
@@ -134,9 +135,8 @@ static void serial2002_tty_read_poll_wait(struct file *f, int timeout)
134 POLLHUP | POLLERR)) { 135 POLLHUP | POLLERR)) {
135 break; 136 break;
136 } 137 }
137 do_gettimeofday(&now); 138 now = ktime_get();
138 elapsed = 1000000 * (now.tv_sec - start.tv_sec) + 139 elapsed = ktime_us_delta(now, start);
139 now.tv_usec - start.tv_usec;
140 if (elapsed > timeout) 140 if (elapsed > timeout)
141 break; 141 break;
142 set_current_state(TASK_INTERRUPTIBLE); 142 set_current_state(TASK_INTERRUPTIBLE);
diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c b/drivers/staging/comedi/drivers/usbduxsigma.c
index eaa9add491df..649cf47184a4 100644
--- a/drivers/staging/comedi/drivers/usbduxsigma.c
+++ b/drivers/staging/comedi/drivers/usbduxsigma.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * usbduxsigma.c 2 * usbduxsigma.c
3 * Copyright (C) 2011-2014 Bernd Porr, mail@berndporr.me.uk 3 * Copyright (C) 2011-2015 Bernd Porr, mail@berndporr.me.uk
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@
18 * Description: University of Stirling USB DAQ & INCITE Technology Limited 18 * Description: University of Stirling USB DAQ & INCITE Technology Limited
19 * Devices: [ITL] USB-DUX-SIGMA (usbduxsigma) 19 * Devices: [ITL] USB-DUX-SIGMA (usbduxsigma)
20 * Author: Bernd Porr <mail@berndporr.me.uk> 20 * Author: Bernd Porr <mail@berndporr.me.uk>
21 * Updated: 10 Oct 2014 21 * Updated: 20 July 2015
22 * Status: stable 22 * Status: stable
23 */ 23 */
24 24
@@ -39,6 +39,7 @@
39 * 0.4: fixed D/A voltage range 39 * 0.4: fixed D/A voltage range
40 * 0.5: various bug fixes, health check at startup 40 * 0.5: various bug fixes, health check at startup
41 * 0.6: corrected wrong input range 41 * 0.6: corrected wrong input range
42 * 0.7: rewrite code that urb->interval is always 1
42 */ 43 */
43 44
44#include <linux/kernel.h> 45#include <linux/kernel.h>
@@ -122,7 +123,7 @@
122#define RETRIES 10 123#define RETRIES 10
123 124
124/* bulk transfer commands to usbduxsigma */ 125/* bulk transfer commands to usbduxsigma */
125#define USBBUXSIGMA_AD_CMD 0 126#define USBBUXSIGMA_AD_CMD 9
126#define USBDUXSIGMA_DA_CMD 1 127#define USBDUXSIGMA_DA_CMD 1
127#define USBDUXSIGMA_DIO_CFG_CMD 2 128#define USBDUXSIGMA_DIO_CFG_CMD 2
128#define USBDUXSIGMA_DIO_BITS_CMD 3 129#define USBDUXSIGMA_DIO_BITS_CMD 3
@@ -217,24 +218,28 @@ static void usbduxsigma_ai_handle_urb(struct comedi_device *dev,
217 int ret; 218 int ret;
218 int i; 219 int i;
219 220
220 devpriv->ai_counter--; 221 if ((urb->actual_length > 0) && (urb->status != -EXDEV)) {
221 if (devpriv->ai_counter == 0) { 222 devpriv->ai_counter--;
222 devpriv->ai_counter = devpriv->ai_timer; 223 if (devpriv->ai_counter == 0) {
223 224 devpriv->ai_counter = devpriv->ai_timer;
224 /* get the data from the USB bus and hand it over to comedi */ 225
225 for (i = 0; i < cmd->chanlist_len; i++) { 226 /* get the data from the USB bus
226 /* transfer data, note first byte is the DIO state */ 227 and hand it over to comedi */
227 val = be32_to_cpu(devpriv->in_buf[i+1]); 228 for (i = 0; i < cmd->chanlist_len; i++) {
228 val &= 0x00ffffff; /* strip status byte */ 229 /* transfer data,
229 val ^= 0x00800000; /* convert to unsigned */ 230 note first byte is the DIO state */
231 val = be32_to_cpu(devpriv->in_buf[i+1]);
232 val &= 0x00ffffff; /* strip status byte */
233 val ^= 0x00800000; /* convert to unsigned */
234
235 if (!comedi_buf_write_samples(s, &val, 1))
236 return;
237 }
230 238
231 if (!comedi_buf_write_samples(s, &val, 1)) 239 if (cmd->stop_src == TRIG_COUNT &&
232 return; 240 async->scans_done >= cmd->stop_arg)
241 async->events |= COMEDI_CB_EOA;
233 } 242 }
234
235 if (cmd->stop_src == TRIG_COUNT &&
236 async->scans_done >= cmd->stop_arg)
237 async->events |= COMEDI_CB_EOA;
238 } 243 }
239 244
240 /* if command is still running, resubmit urb */ 245 /* if command is still running, resubmit urb */
@@ -374,10 +379,7 @@ static void usbduxsigma_ao_handle_urb(struct comedi_device *dev,
374 urb->transfer_buffer_length = SIZEOUTBUF; 379 urb->transfer_buffer_length = SIZEOUTBUF;
375 urb->dev = comedi_to_usb_dev(dev); 380 urb->dev = comedi_to_usb_dev(dev);
376 urb->status = 0; 381 urb->status = 0;
377 if (devpriv->high_speed) 382 urb->interval = 1; /* (u)frames */
378 urb->interval = 8; /* uframes */
379 else
380 urb->interval = 1; /* frames */
381 urb->number_of_packets = 1; 383 urb->number_of_packets = 1;
382 urb->iso_frame_desc[0].offset = 0; 384 urb->iso_frame_desc[0].offset = 0;
383 urb->iso_frame_desc[0].length = SIZEOUTBUF; 385 urb->iso_frame_desc[0].length = SIZEOUTBUF;
@@ -441,7 +443,6 @@ static int usbduxsigma_submit_urbs(struct comedi_device *dev,
441 int input_urb) 443 int input_urb)
442{ 444{
443 struct usb_device *usb = comedi_to_usb_dev(dev); 445 struct usb_device *usb = comedi_to_usb_dev(dev);
444 struct usbduxsigma_private *devpriv = dev->private;
445 struct urb *urb; 446 struct urb *urb;
446 int ret; 447 int ret;
447 int i; 448 int i;
@@ -452,7 +453,7 @@ static int usbduxsigma_submit_urbs(struct comedi_device *dev,
452 453
453 /* in case of a resubmission after an unlink... */ 454 /* in case of a resubmission after an unlink... */
454 if (input_urb) 455 if (input_urb)
455 urb->interval = devpriv->ai_interval; 456 urb->interval = 1;
456 urb->context = dev; 457 urb->context = dev;
457 urb->dev = usb; 458 urb->dev = usb;
458 urb->status = 0; 459 urb->status = 0;
@@ -481,6 +482,7 @@ static int usbduxsigma_ai_cmdtest(struct comedi_device *dev,
481 struct usbduxsigma_private *devpriv = dev->private; 482 struct usbduxsigma_private *devpriv = dev->private;
482 int high_speed = devpriv->high_speed; 483 int high_speed = devpriv->high_speed;
483 int interval = usbduxsigma_chans_to_interval(cmd->chanlist_len); 484 int interval = usbduxsigma_chans_to_interval(cmd->chanlist_len);
485 unsigned int tmp;
484 int err = 0; 486 int err = 0;
485 487
486 /* Step 1 : check if triggers are trivially valid */ 488 /* Step 1 : check if triggers are trivially valid */
@@ -508,35 +510,20 @@ static int usbduxsigma_ai_cmdtest(struct comedi_device *dev,
508 510
509 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0); 511 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0);
510 512
511 if (cmd->scan_begin_src == TRIG_FOLLOW) /* internal trigger */ 513 if (high_speed) {
512 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0); 514 /*
513 515 * In high speed mode microframes are possible.
514 if (cmd->scan_begin_src == TRIG_TIMER) { 516 * However, during one microframe we can roughly
515 unsigned int tmp; 517 * sample two channels. Thus, the more channels
516 518 * are in the channel list the more time we need.
517 if (high_speed) { 519 */
518 /* 520 err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg,
519 * In high speed mode microframes are possible. 521 (125000 * interval));
520 * However, during one microframe we can roughly 522 } else {
521 * sample two channels. Thus, the more channels 523 /* full speed */
522 * are in the channel list the more time we need. 524 /* 1kHz scans every USB frame */
523 */ 525 err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg,
524 err |= comedi_check_trigger_arg_min(&cmd-> 526 1000000);
525 scan_begin_arg,
526 (1000000 / 8 *
527 interval));
528
529 tmp = (cmd->scan_begin_arg / 125000) * 125000;
530 } else {
531 /* full speed */
532 /* 1kHz scans every USB frame */
533 err |= comedi_check_trigger_arg_min(&cmd->
534 scan_begin_arg,
535 1000000);
536
537 tmp = (cmd->scan_begin_arg / 1000000) * 1000000;
538 }
539 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, tmp);
540 } 527 }
541 528
542 err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg, 529 err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
@@ -552,21 +539,8 @@ static int usbduxsigma_ai_cmdtest(struct comedi_device *dev,
552 539
553 /* Step 4: fix up any arguments */ 540 /* Step 4: fix up any arguments */
554 541
555 if (high_speed) { 542 tmp = rounddown(cmd->scan_begin_arg, high_speed ? 125000 : 1000000);
556 /* 543 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, tmp);
557 * every 2 channels get a time window of 125us. Thus, if we
558 * sample all 16 channels we need 1ms. If we sample only one
559 * channel we need only 125us
560 */
561 devpriv->ai_interval = interval;
562 devpriv->ai_timer = cmd->scan_begin_arg / (125000 * interval);
563 } else {
564 /* interval always 1ms */
565 devpriv->ai_interval = 1;
566 devpriv->ai_timer = cmd->scan_begin_arg / 1000000;
567 }
568 if (devpriv->ai_timer < 1)
569 err |= -EINVAL;
570 544
571 if (err) 545 if (err)
572 return 4; 546 return 4;
@@ -668,19 +642,36 @@ static int usbduxsigma_ai_cmd(struct comedi_device *dev,
668 642
669 down(&devpriv->sem); 643 down(&devpriv->sem);
670 644
645 if (devpriv->high_speed) {
646 /*
647 * every 2 channels get a time window of 125us. Thus, if we
648 * sample all 16 channels we need 1ms. If we sample only one
649 * channel we need only 125us
650 */
651 unsigned int interval = usbduxsigma_chans_to_interval(len);
652
653 devpriv->ai_interval = interval;
654 devpriv->ai_timer = cmd->scan_begin_arg / (125000 * interval);
655 } else {
656 /* interval always 1ms */
657 devpriv->ai_interval = 1;
658 devpriv->ai_timer = cmd->scan_begin_arg / 1000000;
659 }
660
671 for (i = 0; i < len; i++) { 661 for (i = 0; i < len; i++) {
672 unsigned int chan = CR_CHAN(cmd->chanlist[i]); 662 unsigned int chan = CR_CHAN(cmd->chanlist[i]);
673 663
674 create_adc_command(chan, &muxsg0, &muxsg1); 664 create_adc_command(chan, &muxsg0, &muxsg1);
675 } 665 }
676 666
677 devpriv->dux_commands[1] = len; /* num channels per time step */ 667 devpriv->dux_commands[1] = devpriv->ai_interval;
678 devpriv->dux_commands[2] = 0x12; /* CONFIG0 */ 668 devpriv->dux_commands[2] = len; /* num channels per time step */
679 devpriv->dux_commands[3] = 0x03; /* CONFIG1: 23kHz sample, delay 0us */ 669 devpriv->dux_commands[3] = 0x12; /* CONFIG0 */
680 devpriv->dux_commands[4] = 0x00; /* CONFIG3: diff. channels off */ 670 devpriv->dux_commands[4] = 0x03; /* CONFIG1: 23kHz sample, delay 0us */
681 devpriv->dux_commands[5] = muxsg0; 671 devpriv->dux_commands[5] = 0x00; /* CONFIG3: diff. channels off */
682 devpriv->dux_commands[6] = muxsg1; 672 devpriv->dux_commands[6] = muxsg0;
683 devpriv->dux_commands[7] = sysred; 673 devpriv->dux_commands[7] = muxsg1;
674 devpriv->dux_commands[8] = sysred;
684 675
685 ret = usbbuxsigma_send_cmd(dev, USBBUXSIGMA_AD_CMD); 676 ret = usbbuxsigma_send_cmd(dev, USBBUXSIGMA_AD_CMD);
686 if (ret < 0) { 677 if (ret < 0) {
@@ -848,29 +839,22 @@ static int usbduxsigma_ao_cmdtest(struct comedi_device *dev,
848 struct comedi_cmd *cmd) 839 struct comedi_cmd *cmd)
849{ 840{
850 struct usbduxsigma_private *devpriv = dev->private; 841 struct usbduxsigma_private *devpriv = dev->private;
842 unsigned int tmp;
851 int err = 0; 843 int err = 0;
852 int high_speed;
853 unsigned int flags;
854
855 /* high speed conversions are not used yet */
856 high_speed = 0; /* (devpriv->high_speed) */
857 844
858 /* Step 1 : check if triggers are trivially valid */ 845 /* Step 1 : check if triggers are trivially valid */
859 846
860 err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT); 847 err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
861 848
862 if (high_speed) { 849 /*
863 /* 850 * For now, always use "scan" timing with all channels updated at once
864 * start immediately a new scan 851 * (cmd->scan_begin_src == TRIG_TIMER, cmd->convert_src == TRIG_NOW).
865 * the sampling rate is set by the coversion rate 852 *
866 */ 853 * In a future version, "convert" timing with channels updated
867 flags = TRIG_FOLLOW; 854 * indivually may be supported in high speed mode
868 } else { 855 * (cmd->scan_begin_src == TRIG_FOLLOW, cmd->convert_src == TRIG_TIMER).
869 /* start a new scan (output at once) with a timer */ 856 */
870 flags = TRIG_TIMER; 857 err |= comedi_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER);
871 }
872 err |= comedi_check_trigger_src(&cmd->scan_begin_src, flags);
873
874 err |= comedi_check_trigger_src(&cmd->convert_src, TRIG_NOW); 858 err |= comedi_check_trigger_src(&cmd->convert_src, TRIG_NOW);
875 err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); 859 err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
876 err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE); 860 err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
@@ -894,17 +878,7 @@ static int usbduxsigma_ao_cmdtest(struct comedi_device *dev,
894 878
895 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0); 879 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0);
896 880
897 if (cmd->scan_begin_src == TRIG_FOLLOW) /* internal trigger */ 881 err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg, 1000000);
898 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
899
900 if (cmd->scan_begin_src == TRIG_TIMER) {
901 err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg,
902 1000000);
903 }
904
905 /* not used now, is for later use */
906 if (cmd->convert_src == TRIG_TIMER)
907 err |= comedi_check_trigger_arg_min(&cmd->convert_arg, 125000);
908 882
909 err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg, 883 err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
910 cmd->chanlist_len); 884 cmd->chanlist_len);
@@ -919,19 +893,8 @@ static int usbduxsigma_ao_cmdtest(struct comedi_device *dev,
919 893
920 /* Step 4: fix up any arguments */ 894 /* Step 4: fix up any arguments */
921 895
922 /* we count in timer steps */ 896 tmp = rounddown(cmd->scan_begin_arg, 1000000);
923 if (high_speed) { 897 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, tmp);
924 /* timing of the conversion itself: every 125 us */
925 devpriv->ao_timer = cmd->convert_arg / 125000;
926 } else {
927 /*
928 * timing of the scan: every 1ms
929 * we get all channels at once
930 */
931 devpriv->ao_timer = cmd->scan_begin_arg / 1000000;
932 }
933 if (devpriv->ao_timer < 1)
934 err |= -EINVAL;
935 898
936 if (err) 899 if (err)
937 return 4; 900 return 4;
@@ -948,6 +911,14 @@ static int usbduxsigma_ao_cmd(struct comedi_device *dev,
948 911
949 down(&devpriv->sem); 912 down(&devpriv->sem);
950 913
914 /*
915 * For now, only "scan" timing is supported. A future version may
916 * support "convert" timing in high speed mode.
917 *
918 * Timing of the scan: every 1ms all channels updated at once.
919 */
920 devpriv->ao_timer = cmd->scan_begin_arg / 1000000;
921
951 devpriv->ao_counter = devpriv->ao_timer; 922 devpriv->ao_counter = devpriv->ao_timer;
952 923
953 if (cmd->start_src == TRIG_NOW) { 924 if (cmd->start_src == TRIG_NOW) {
@@ -1427,10 +1398,7 @@ static int usbduxsigma_alloc_usb_buffers(struct comedi_device *dev)
1427 urb->transfer_buffer_length = SIZEOUTBUF; 1398 urb->transfer_buffer_length = SIZEOUTBUF;
1428 urb->iso_frame_desc[0].offset = 0; 1399 urb->iso_frame_desc[0].offset = 0;
1429 urb->iso_frame_desc[0].length = SIZEOUTBUF; 1400 urb->iso_frame_desc[0].length = SIZEOUTBUF;
1430 if (devpriv->high_speed) 1401 urb->interval = 1; /* (u)frames */
1431 urb->interval = 8; /* uframes */
1432 else
1433 urb->interval = 1; /* frames */
1434 } 1402 }
1435 1403
1436 if (devpriv->pwm_buf_sz) { 1404 if (devpriv->pwm_buf_sz) {
@@ -1653,7 +1621,7 @@ static struct usb_driver usbduxsigma_usb_driver = {
1653}; 1621};
1654module_comedi_usb_driver(usbduxsigma_driver, usbduxsigma_usb_driver); 1622module_comedi_usb_driver(usbduxsigma_driver, usbduxsigma_usb_driver);
1655 1623
1656MODULE_AUTHOR("Bernd Porr, BerndPorr@f2s.com"); 1624MODULE_AUTHOR("Bernd Porr, mail@berndporr.me.uk");
1657MODULE_DESCRIPTION("Stirling/ITL USB-DUX SIGMA -- Bernd.Porr@f2s.com"); 1625MODULE_DESCRIPTION("Stirling/ITL USB-DUX SIGMA -- mail@berndporr.me.uk");
1658MODULE_LICENSE("GPL"); 1626MODULE_LICENSE("GPL");
1659MODULE_FIRMWARE(FIRMWARE); 1627MODULE_FIRMWARE(FIRMWARE);
diff --git a/drivers/staging/comedi/range.c b/drivers/staging/comedi/range.c
index 6a393b24bdd9..ce3a58a7a171 100644
--- a/drivers/staging/comedi/range.c
+++ b/drivers/staging/comedi/range.c
@@ -102,7 +102,18 @@ int do_rangeinfo_ioctl(struct comedi_device *dev,
102 * @s: comedi_subdevice struct 102 * @s: comedi_subdevice struct
103 * @n: number of elements in the chanlist 103 * @n: number of elements in the chanlist
104 * @chanlist: the chanlist to validate 104 * @chanlist: the chanlist to validate
105*/ 105 *
106 * Each element consists of a channel number, a range index, an analog
107 * reference type and some flags, all packed into an unsigned int.
108 *
109 * This checks that the channel number and range index are supported by
110 * the comedi subdevice. It does not check whether the analog reference
111 * type and the flags are supported. Drivers that care should check those
112 * themselves.
113 *
114 * Return: %0 if all @chanlist elements are valid (success),
115 * %-EINVAL if one or more elements are invalid.
116 */
106int comedi_check_chanlist(struct comedi_subdevice *s, int n, 117int comedi_check_chanlist(struct comedi_subdevice *s, int n,
107 unsigned int *chanlist) 118 unsigned int *chanlist)
108{ 119{
diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index 26b0446d943a..9112dd2bf4d7 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -4953,9 +4953,8 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
4953 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); 4953 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4954 spin_unlock_irqrestore(&bd->bd_lock, lock_flags); 4954 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4955 4955
4956 rc = put_user(C_CLOCAL(tty) ? 1 : 0, 4956 return put_user(C_CLOCAL(tty) ? 1 : 0,
4957 (unsigned long __user *) arg); 4957 (unsigned long __user *) arg);
4958 return rc;
4959 4958
4960 case TIOCSSOFTCAR: 4959 case TIOCSSOFTCAR:
4961 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); 4960 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
@@ -7004,25 +7003,29 @@ static void dgap_cleanup_board(struct board_t *brd)
7004 kfree(brd); 7003 kfree(brd);
7005} 7004}
7006 7005
7007static void dgap_remove_one(struct pci_dev *dev) 7006static void dgap_stop(bool removesys, struct pci_driver *drv)
7008{ 7007{
7009 unsigned int i; 7008 unsigned long lock_flags;
7010 ulong lock_flags;
7011 struct pci_driver *drv = to_pci_driver(dev->dev.driver);
7012 7009
7013 spin_lock_irqsave(&dgap_poll_lock, lock_flags); 7010 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
7014 dgap_poll_stop = 1; 7011 dgap_poll_stop = 1;
7015 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags); 7012 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
7016 7013
7017 /* Turn off poller right away. */
7018 del_timer_sync(&dgap_poll_timer); 7014 del_timer_sync(&dgap_poll_timer);
7019 7015 if (removesys)
7020 dgap_remove_driver_sysfiles(drv); 7016 dgap_remove_driver_sysfiles(drv);
7021 7017
7022 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0)); 7018 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
7023 class_destroy(dgap_class); 7019 class_destroy(dgap_class);
7024 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap"); 7020 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
7021}
7025 7022
7023static void dgap_remove_one(struct pci_dev *dev)
7024{
7025 unsigned int i;
7026 struct pci_driver *drv = to_pci_driver(dev->dev.driver);
7027
7028 dgap_stop(true, drv);
7026 for (i = 0; i < dgap_numboards; ++i) { 7029 for (i = 0; i < dgap_numboards; ++i) {
7027 dgap_remove_ports_sysfiles(dgap_board[i]); 7030 dgap_remove_ports_sysfiles(dgap_board[i]);
7028 dgap_cleanup_tty(dgap_board[i]); 7031 dgap_cleanup_tty(dgap_board[i]);
@@ -7096,21 +7099,6 @@ failed_class:
7096 return rc; 7099 return rc;
7097} 7100}
7098 7101
7099static void dgap_stop(void)
7100{
7101 unsigned long lock_flags;
7102
7103 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
7104 dgap_poll_stop = 1;
7105 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
7106
7107 del_timer_sync(&dgap_poll_timer);
7108
7109 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
7110 class_destroy(dgap_class);
7111 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
7112}
7113
7114/************************************************************************ 7102/************************************************************************
7115 * 7103 *
7116 * Driver load/unload functions 7104 * Driver load/unload functions
@@ -7133,8 +7121,10 @@ static int dgap_init_module(void)
7133 return rc; 7121 return rc;
7134 7122
7135 rc = pci_register_driver(&dgap_driver); 7123 rc = pci_register_driver(&dgap_driver);
7136 if (rc) 7124 if (rc) {
7137 goto err_stop; 7125 dgap_stop(false, NULL);
7126 return rc;
7127 }
7138 7128
7139 rc = dgap_create_driver_sysfiles(&dgap_driver); 7129 rc = dgap_create_driver_sysfiles(&dgap_driver);
7140 if (rc) 7130 if (rc)
@@ -7146,9 +7136,6 @@ static int dgap_init_module(void)
7146 7136
7147err_unregister: 7137err_unregister:
7148 pci_unregister_driver(&dgap_driver); 7138 pci_unregister_driver(&dgap_driver);
7149err_stop:
7150 dgap_stop();
7151
7152 return rc; 7139 return rc;
7153} 7140}
7154 7141
diff --git a/drivers/staging/dgnc/dgnc_driver.h b/drivers/staging/dgnc/dgnc_driver.h
index d04671fa4b75..06ece5151fe4 100644
--- a/drivers/staging/dgnc/dgnc_driver.h
+++ b/drivers/staging/dgnc/dgnc_driver.h
@@ -21,9 +21,9 @@
21#ifndef __DGNC_DRIVER_H 21#ifndef __DGNC_DRIVER_H
22#define __DGNC_DRIVER_H 22#define __DGNC_DRIVER_H
23 23
24#include <linux/types.h> /* To pick up the varions Linux types */ 24#include <linux/types.h>
25#include <linux/tty.h> /* To pick up the various tty structs/defines */ 25#include <linux/tty.h>
26#include <linux/interrupt.h> /* For irqreturn_t type */ 26#include <linux/interrupt.h>
27 27
28#include "digi.h" /* Digi specific ioctl header */ 28#include "digi.h" /* Digi specific ioctl header */
29#include "dgnc_sysfs.h" /* Support for SYSFS */ 29#include "dgnc_sysfs.h" /* Support for SYSFS */
diff --git a/drivers/staging/dgnc/dgnc_sysfs.h b/drivers/staging/dgnc/dgnc_sysfs.h
index be0f90a6768b..7be7d55bc49e 100644
--- a/drivers/staging/dgnc/dgnc_sysfs.h
+++ b/drivers/staging/dgnc/dgnc_sysfs.h
@@ -25,16 +25,16 @@ struct un_t;
25struct pci_driver; 25struct pci_driver;
26struct class_device; 26struct class_device;
27 27
28extern void dgnc_create_ports_sysfiles(struct dgnc_board *bd); 28void dgnc_create_ports_sysfiles(struct dgnc_board *bd);
29extern void dgnc_remove_ports_sysfiles(struct dgnc_board *bd); 29void dgnc_remove_ports_sysfiles(struct dgnc_board *bd);
30 30
31extern void dgnc_create_driver_sysfiles(struct pci_driver *); 31void dgnc_create_driver_sysfiles(struct pci_driver *);
32extern void dgnc_remove_driver_sysfiles(struct pci_driver *); 32void dgnc_remove_driver_sysfiles(struct pci_driver *);
33 33
34extern int dgnc_tty_class_init(void); 34int dgnc_tty_class_init(void);
35extern int dgnc_tty_class_destroy(void); 35int dgnc_tty_class_destroy(void);
36 36
37extern void dgnc_create_tty_sysfs(struct un_t *un, struct device *c); 37void dgnc_create_tty_sysfs(struct un_t *un, struct device *c);
38extern void dgnc_remove_tty_sysfs(struct device *c); 38void dgnc_remove_tty_sysfs(struct device *c);
39 39
40#endif 40#endif
diff --git a/drivers/staging/fbtft/Kconfig b/drivers/staging/fbtft/Kconfig
index d4018780ce58..d473010fa474 100644
--- a/drivers/staging/fbtft/Kconfig
+++ b/drivers/staging/fbtft/Kconfig
@@ -1,6 +1,7 @@
1menuconfig FB_TFT 1menuconfig FB_TFT
2 tristate "Support for small TFT LCD display modules" 2 tristate "Support for small TFT LCD display modules"
3 depends on FB && SPI && GPIOLIB 3 depends on FB && SPI
4 depends on GPIOLIB || COMPILE_TEST
4 select FB_SYS_FILLRECT 5 select FB_SYS_FILLRECT
5 select FB_SYS_COPYAREA 6 select FB_SYS_COPYAREA
6 select FB_SYS_IMAGEBLIT 7 select FB_SYS_IMAGEBLIT
@@ -152,6 +153,12 @@ config FB_TFT_TLS8204
152 help 153 help
153 Generic Framebuffer support for TLS8204 154 Generic Framebuffer support for TLS8204
154 155
156config FB_TFT_UC1611
157 tristate "FB driver for the UC1611 LCD controller"
158 depends on FB_TFT
159 help
160 Generic Framebuffer support for UC1611
161
155config FB_TFT_UC1701 162config FB_TFT_UC1701
156 tristate "FB driver for the UC1701 LCD Controller" 163 tristate "FB driver for the UC1701 LCD Controller"
157 depends on FB_TFT 164 depends on FB_TFT
diff --git a/drivers/staging/fbtft/Makefile b/drivers/staging/fbtft/Makefile
index 554b5260b0ee..b26efdc87775 100644
--- a/drivers/staging/fbtft/Makefile
+++ b/drivers/staging/fbtft/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_FB_TFT_SSD1351) += fb_ssd1351.o
27obj-$(CONFIG_FB_TFT_ST7735R) += fb_st7735r.o 27obj-$(CONFIG_FB_TFT_ST7735R) += fb_st7735r.o
28obj-$(CONFIG_FB_TFT_TINYLCD) += fb_tinylcd.o 28obj-$(CONFIG_FB_TFT_TINYLCD) += fb_tinylcd.o
29obj-$(CONFIG_FB_TFT_TLS8204) += fb_tls8204.o 29obj-$(CONFIG_FB_TFT_TLS8204) += fb_tls8204.o
30obj-$(CONFIG_FB_TFT_UC1611) += fb_uc1611.o
30obj-$(CONFIG_FB_TFT_UC1701) += fb_uc1701.o 31obj-$(CONFIG_FB_TFT_UC1701) += fb_uc1701.o
31obj-$(CONFIG_FB_TFT_UPD161704) += fb_upd161704.o 32obj-$(CONFIG_FB_TFT_UPD161704) += fb_upd161704.o
32obj-$(CONFIG_FB_TFT_WATTEROTT) += fb_watterott.o 33obj-$(CONFIG_FB_TFT_WATTEROTT) += fb_watterott.o
diff --git a/drivers/staging/fbtft/fb_uc1611.c b/drivers/staging/fbtft/fb_uc1611.c
new file mode 100644
index 000000000000..32f3a9d921d6
--- /dev/null
+++ b/drivers/staging/fbtft/fb_uc1611.c
@@ -0,0 +1,350 @@
1/*
2 * FB driver for the UltraChip UC1611 LCD controller
3 *
4 * The display is 4-bit grayscale (16 shades) 240x160.
5 *
6 * Copyright (C) 2015 Henri Chain
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18
19#include <linux/module.h>
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/gpio.h>
23#include <linux/spi/spi.h>
24#include <linux/delay.h>
25
26#include "fbtft.h"
27
28#define DRVNAME "fb_uc1611"
29#define WIDTH 240
30#define HEIGHT 160
31#define BPP 8
32#define FPS 40
33
34/*
35 * LCD voltage is a combination of ratio, gain, pot and temp
36 *
37 * V_LCD = V_BIAS * ratio
38 * V_LCD = (C_V0 + C_PM × pot) * (1 + (T - 25) * temp)
39 * C_V0 and C_PM depend on ratio and gain
40 * T is ambient temperature
41 */
42
43/* BR -> actual ratio: 0-3 -> 5, 10, 11, 13 */
44static unsigned ratio = 2;
45module_param(ratio, uint, 0);
46MODULE_PARM_DESC(ratio, "BR[1:0] Bias voltage ratio: 0-3 (default: 2)");
47
48static unsigned gain = 3;
49module_param(gain, uint, 0);
50MODULE_PARM_DESC(gain, "GN[1:0] Bias voltage gain: 0-3 (default: 3)");
51
52static unsigned pot = 16;
53module_param(pot, uint, 0);
54MODULE_PARM_DESC(pot, "PM[6:0] Bias voltage pot.: 0-63 (default: 16)");
55
56/* TC -> % compensation per deg C: 0-3 -> -.05, -.10, -.015, -.20 */
57static unsigned temp;
58module_param(temp, uint, 0);
59MODULE_PARM_DESC(temp, "TC[1:0] Temperature compensation: 0-3 (default: 0)");
60
61/* PC[1:0] -> LCD capacitance: 0-3 -> <20nF, 20-28 nF, 29-40 nF, 40-56 nF */
62static unsigned load = 1;
63module_param(load, uint, 0);
64MODULE_PARM_DESC(load, "PC[1:0] Panel Loading: 0-3 (default: 1)");
65
66/* PC[3:2] -> V_LCD: 0, 1, 3 -> ext., int. with ratio = 5, int. standard */
67static unsigned pump = 3;
68module_param(pump, uint, 0);
69MODULE_PARM_DESC(pump, "PC[3:2] Pump control: 0,1,3 (default: 3)");
70
71static int init_display(struct fbtft_par *par)
72{
73 int ret;
74
75 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
76
77 /* Set CS active high */
78 par->spi->mode |= SPI_CS_HIGH;
79 ret = par->spi->master->setup(par->spi);
80 if (ret) {
81 dev_err(par->info->device, "Could not set SPI_CS_HIGH\n");
82 return ret;
83 }
84
85 /* Reset controller */
86 write_reg(par, 0xE2);
87
88 /* Set bias ratio */
89 write_reg(par, 0xE8 | (ratio & 0x03));
90
91 /* Set bias gain and potentiometer */
92 write_reg(par, 0x81);
93 write_reg(par, (gain & 0x03) << 6 | (pot & 0x3F));
94
95 /* Set temperature compensation */
96 write_reg(par, 0x24 | (temp & 0x03));
97
98 /* Set panel loading */
99 write_reg(par, 0x28 | (load & 0x03));
100
101 /* Set pump control */
102 write_reg(par, 0x2C | (pump & 0x03));
103
104 /* Set inverse display */
105 write_reg(par, 0xA6 | (0x01 & 0x01));
106
107 /* Set 4-bit grayscale mode */
108 write_reg(par, 0xD0 | (0x02 & 0x03));
109
110 /* Set Display enable */
111 write_reg(par, 0xA8 | 0x07);
112
113 return 0;
114}
115
116static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
117{
118 fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
119 "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n",
120 __func__, xs, ys, xe, ye);
121
122 switch (par->info->var.rotate) {
123 case 90:
124 case 270:
125 /* Set column address */
126 write_reg(par, ys & 0x0F);
127 write_reg(par, 0x10 | (ys >> 4));
128
129 /* Set page address (divide xs by 2) (not used by driver) */
130 write_reg(par, 0x60 | ((xs >> 1) & 0x0F));
131 write_reg(par, 0x70 | (xs >> 5));
132 break;
133 default:
134 /* Set column address (not used by driver) */
135 write_reg(par, xs & 0x0F);
136 write_reg(par, 0x10 | (xs >> 4));
137
138 /* Set page address (divide ys by 2) */
139 write_reg(par, 0x60 | ((ys >> 1) & 0x0F));
140 write_reg(par, 0x70 | (ys >> 5));
141 break;
142 }
143}
144
145static int blank(struct fbtft_par *par, bool on)
146{
147 fbtft_par_dbg(DEBUG_BLANK, par, "%s(blank=%s)\n",
148 __func__, on ? "true" : "false");
149
150 if (on)
151 write_reg(par, 0xA8 | 0x00);
152 else
153 write_reg(par, 0xA8 | 0x07);
154 return 0;
155}
156
157static int set_var(struct fbtft_par *par)
158{
159 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
160
161 /* par->info->fix.visual = FB_VISUAL_PSEUDOCOLOR; */
162 par->info->var.grayscale = 1;
163 par->info->var.red.offset = 0;
164 par->info->var.red.length = 8;
165 par->info->var.green.offset = 0;
166 par->info->var.green.length = 8;
167 par->info->var.blue.offset = 0;
168 par->info->var.blue.length = 8;
169 par->info->var.transp.offset = 0;
170 par->info->var.transp.length = 0;
171
172 switch (par->info->var.rotate) {
173 case 90:
174 /* Set RAM address control */
175 write_reg(par, 0x88
176 | (0x0 & 0x1) << 2 /* Increment positively */
177 | (0x1 & 0x1) << 1 /* Increment page first */
178 | (0x1 & 0x1)); /* Wrap around (default) */
179
180 /* Set LCD mapping */
181 write_reg(par, 0xC0
182 | (0x0 & 0x1) << 2 /* Mirror Y OFF */
183 | (0x0 & 0x1) << 1 /* Mirror X OFF */
184 | (0x0 & 0x1)); /* MS nibble last (default) */
185 break;
186 case 180:
187 /* Set RAM address control */
188 write_reg(par, 0x88
189 | (0x0 & 0x1) << 2 /* Increment positively */
190 | (0x0 & 0x1) << 1 /* Increment column first */
191 | (0x1 & 0x1)); /* Wrap around (default) */
192
193 /* Set LCD mapping */
194 write_reg(par, 0xC0
195 | (0x1 & 0x1) << 2 /* Mirror Y ON */
196 | (0x0 & 0x1) << 1 /* Mirror X OFF */
197 | (0x0 & 0x1)); /* MS nibble last (default) */
198 break;
199 case 270:
200 /* Set RAM address control */
201 write_reg(par, 0x88
202 | (0x0 & 0x1) << 2 /* Increment positively */
203 | (0x1 & 0x1) << 1 /* Increment page first */
204 | (0x1 & 0x1)); /* Wrap around (default) */
205
206 /* Set LCD mapping */
207 write_reg(par, 0xC0
208 | (0x1 & 0x1) << 2 /* Mirror Y ON */
209 | (0x1 & 0x1) << 1 /* Mirror X ON */
210 | (0x0 & 0x1)); /* MS nibble last (default) */
211 break;
212 default:
213 /* Set RAM address control */
214 write_reg(par, 0x88
215 | (0x0 & 0x1) << 2 /* Increment positively */
216 | (0x0 & 0x1) << 1 /* Increment column first */
217 | (0x1 & 0x1)); /* Wrap around (default) */
218
219 /* Set LCD mapping */
220 write_reg(par, 0xC0
221 | (0x0 & 0x1) << 2 /* Mirror Y OFF */
222 | (0x1 & 0x1) << 1 /* Mirror X ON */
223 | (0x0 & 0x1)); /* MS nibble last (default) */
224 break;
225 }
226
227 return 0;
228}
229
230static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
231{
232 u8 *vmem8 = (u8 *)(par->info->screen_base);
233 u8 *buf8 = (u8 *)(par->txbuf.buf);
234 u16 *buf16 = (u16 *)(par->txbuf.buf);
235 int line_length = par->info->fix.line_length;
236 int y_start = (offset / line_length);
237 int y_end = (offset + len - 1) / line_length;
238 int x, y, i;
239 int ret = 0;
240
241 fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
242
243 switch (par->pdata->display.buswidth) {
244 case 8:
245 switch (par->info->var.rotate) {
246 case 90:
247 case 270:
248 i = y_start * line_length;
249 for (y = y_start; y <= y_end; y++) {
250 for (x = 0; x < line_length; x += 2) {
251 *buf8 = vmem8[i] >> 4;
252 *buf8 |= vmem8[i + 1] & 0xF0;
253 buf8++;
254 i += 2;
255 }
256 }
257 break;
258 default:
259 /* Must be even because pages are two lines */
260 y_start &= 0xFE;
261 i = y_start * line_length;
262 for (y = y_start; y <= y_end; y += 2) {
263 for (x = 0; x < line_length; x++) {
264 *buf8 = vmem8[i] >> 4;
265 *buf8 |= vmem8[i + line_length] & 0xF0;
266 buf8++;
267 i++;
268 }
269 i += line_length;
270 }
271 break;
272 }
273 gpio_set_value(par->gpio.dc, 1);
274
275 /* Write data */
276 ret = par->fbtftops.write(par, par->txbuf.buf, len / 2);
277 break;
278 case 9:
279 switch (par->info->var.rotate) {
280 case 90:
281 case 270:
282 i = y_start * line_length;
283 for (y = y_start; y <= y_end; y++) {
284 for (x = 0; x < line_length; x += 2) {
285 *buf16 = 0x100;
286 *buf16 |= vmem8[i] >> 4;
287 *buf16 |= vmem8[i + 1] & 0xF0;
288 buf16++;
289 i += 2;
290 }
291 }
292 break;
293 default:
294 /* Must be even because pages are two lines */
295 y_start &= 0xFE;
296 i = y_start * line_length;
297 for (y = y_start; y <= y_end; y += 2) {
298 for (x = 0; x < line_length; x++) {
299 *buf16 = 0x100;
300 *buf16 |= vmem8[i] >> 4;
301 *buf16 |= vmem8[i + line_length] & 0xF0;
302 buf16++;
303 i++;
304 }
305 i += line_length;
306 }
307 break;
308 }
309
310 /* Write data */
311 ret = par->fbtftops.write(par, par->txbuf.buf, len);
312 break;
313 default:
314 dev_err(par->info->device, "unsupported buswidth %d\n",
315 par->pdata->display.buswidth);
316 }
317
318 if (ret < 0)
319 dev_err(par->info->device, "write failed and returned: %d\n",
320 ret);
321
322 return ret;
323}
324
325static struct fbtft_display display = {
326 .txbuflen = -1,
327 .regwidth = 8,
328 .width = WIDTH,
329 .height = HEIGHT,
330 .bpp = BPP,
331 .fps = FPS,
332 .fbtftops = {
333 .write_vmem = write_vmem,
334 .init_display = init_display,
335 .set_addr_win = set_addr_win,
336 .set_var = set_var,
337 .blank = blank,
338 },
339};
340
341FBTFT_REGISTER_DRIVER(DRVNAME, "ultrachip,uc1611", &display);
342
343MODULE_ALIAS("spi:" DRVNAME);
344MODULE_ALIAS("platform:" DRVNAME);
345MODULE_ALIAS("spi:uc1611");
346MODULE_ALIAS("platform:uc1611");
347
348MODULE_DESCRIPTION("FB driver for the UC1611 LCD controller");
349MODULE_AUTHOR("Henri Chain");
350MODULE_LICENSE("GPL");
diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c
index 9cc81412be69..23392eb6799e 100644
--- a/drivers/staging/fbtft/fbtft-core.c
+++ b/drivers/staging/fbtft/fbtft-core.c
@@ -677,13 +677,13 @@ static void fbtft_merge_fbtftops(struct fbtft_ops *dst, struct fbtft_ops *src)
677 * 677 *
678 */ 678 */
679struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display, 679struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
680 struct device *dev) 680 struct device *dev,
681 struct fbtft_platform_data *pdata)
681{ 682{
682 struct fb_info *info; 683 struct fb_info *info;
683 struct fbtft_par *par; 684 struct fbtft_par *par;
684 struct fb_ops *fbops = NULL; 685 struct fb_ops *fbops = NULL;
685 struct fb_deferred_io *fbdefio = NULL; 686 struct fb_deferred_io *fbdefio = NULL;
686 struct fbtft_platform_data *pdata = dev->platform_data;
687 u8 *vmem = NULL; 687 u8 *vmem = NULL;
688 void *txbuf = NULL; 688 void *txbuf = NULL;
689 void *buf = NULL; 689 void *buf = NULL;
@@ -828,7 +828,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
828 828
829 par = info->par; 829 par = info->par;
830 par->info = info; 830 par->info = info;
831 par->pdata = dev->platform_data; 831 par->pdata = pdata;
832 par->debug = display->debug; 832 par->debug = display->debug;
833 par->buf = buf; 833 par->buf = buf;
834 spin_lock_init(&par->dirty_lock); 834 spin_lock_init(&par->dirty_lock);
@@ -1076,6 +1076,11 @@ static int fbtft_init_display_dt(struct fbtft_par *par)
1076 p = of_prop_next_u32(prop, NULL, &val); 1076 p = of_prop_next_u32(prop, NULL, &val);
1077 if (!p) 1077 if (!p)
1078 return -EINVAL; 1078 return -EINVAL;
1079
1080 par->fbtftops.reset(par);
1081 if (par->gpio.cs != -1)
1082 gpio_set_value(par->gpio.cs, 0); /* Activate chip */
1083
1079 while (p) { 1084 while (p) {
1080 if (val & FBTFT_OF_INIT_CMD) { 1085 if (val & FBTFT_OF_INIT_CMD) {
1081 val &= 0xFFFF; 1086 val &= 0xFFFF;
@@ -1260,12 +1265,11 @@ EXPORT_SYMBOL(fbtft_init_display);
1260 */ 1265 */
1261static int fbtft_verify_gpios(struct fbtft_par *par) 1266static int fbtft_verify_gpios(struct fbtft_par *par)
1262{ 1267{
1263 struct fbtft_platform_data *pdata; 1268 struct fbtft_platform_data *pdata = par->pdata;
1264 int i; 1269 int i;
1265 1270
1266 fbtft_par_dbg(DEBUG_VERIFY_GPIOS, par, "%s()\n", __func__); 1271 fbtft_par_dbg(DEBUG_VERIFY_GPIOS, par, "%s()\n", __func__);
1267 1272
1268 pdata = par->info->device->platform_data;
1269 if (pdata->display.buswidth != 9 && par->startbyte == 0 && 1273 if (pdata->display.buswidth != 9 && par->startbyte == 0 &&
1270 par->gpio.dc < 0) { 1274 par->gpio.dc < 0) {
1271 dev_err(par->info->device, 1275 dev_err(par->info->device,
@@ -1383,10 +1387,9 @@ int fbtft_probe_common(struct fbtft_display *display,
1383 pdata = fbtft_probe_dt(dev); 1387 pdata = fbtft_probe_dt(dev);
1384 if (IS_ERR(pdata)) 1388 if (IS_ERR(pdata))
1385 return PTR_ERR(pdata); 1389 return PTR_ERR(pdata);
1386 dev->platform_data = pdata;
1387 } 1390 }
1388 1391
1389 info = fbtft_framebuffer_alloc(display, dev); 1392 info = fbtft_framebuffer_alloc(display, dev, pdata);
1390 if (!info) 1393 if (!info)
1391 return -ENOMEM; 1394 return -ENOMEM;
1392 1395
diff --git a/drivers/staging/fbtft/fbtft.h b/drivers/staging/fbtft/fbtft.h
index 7d817eb26eab..7e9a506d65f9 100644
--- a/drivers/staging/fbtft/fbtft.h
+++ b/drivers/staging/fbtft/fbtft.h
@@ -262,39 +262,38 @@ struct fbtft_par {
262 par->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__) 262 par->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__)
263 263
264/* fbtft-core.c */ 264/* fbtft-core.c */
265extern void fbtft_dbg_hex(const struct device *dev, 265void fbtft_dbg_hex(const struct device *dev, int groupsize,
266 int groupsize, void *buf, size_t len, const char *fmt, ...); 266 void *buf, size_t len, const char *fmt, ...);
267extern struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display, 267struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
268 struct device *dev); 268 struct device *dev,
269extern void fbtft_framebuffer_release(struct fb_info *info); 269 struct fbtft_platform_data *pdata);
270extern int fbtft_register_framebuffer(struct fb_info *fb_info); 270void fbtft_framebuffer_release(struct fb_info *info);
271extern int fbtft_unregister_framebuffer(struct fb_info *fb_info); 271int fbtft_register_framebuffer(struct fb_info *fb_info);
272extern void fbtft_register_backlight(struct fbtft_par *par); 272int fbtft_unregister_framebuffer(struct fb_info *fb_info);
273extern void fbtft_unregister_backlight(struct fbtft_par *par); 273void fbtft_register_backlight(struct fbtft_par *par);
274extern int fbtft_init_display(struct fbtft_par *par); 274void fbtft_unregister_backlight(struct fbtft_par *par);
275extern int fbtft_probe_common(struct fbtft_display *display, 275int fbtft_init_display(struct fbtft_par *par);
276 struct spi_device *sdev, struct platform_device *pdev); 276int fbtft_probe_common(struct fbtft_display *display, struct spi_device *sdev,
277extern int fbtft_remove_common(struct device *dev, struct fb_info *info); 277 struct platform_device *pdev);
278int fbtft_remove_common(struct device *dev, struct fb_info *info);
278 279
279/* fbtft-io.c */ 280/* fbtft-io.c */
280extern int fbtft_write_spi(struct fbtft_par *par, void *buf, size_t len); 281int fbtft_write_spi(struct fbtft_par *par, void *buf, size_t len);
281extern int fbtft_write_spi_emulate_9(struct fbtft_par *par, 282int fbtft_write_spi_emulate_9(struct fbtft_par *par, void *buf, size_t len);
282 void *buf, size_t len); 283int fbtft_read_spi(struct fbtft_par *par, void *buf, size_t len);
283extern int fbtft_read_spi(struct fbtft_par *par, void *buf, size_t len); 284int fbtft_write_gpio8_wr(struct fbtft_par *par, void *buf, size_t len);
284extern int fbtft_write_gpio8_wr(struct fbtft_par *par, void *buf, size_t len); 285int fbtft_write_gpio16_wr(struct fbtft_par *par, void *buf, size_t len);
285extern int fbtft_write_gpio16_wr(struct fbtft_par *par, void *buf, size_t len); 286int fbtft_write_gpio16_wr_latched(struct fbtft_par *par, void *buf, size_t len);
286extern int fbtft_write_gpio16_wr_latched(struct fbtft_par *par,
287 void *buf, size_t len);
288 287
289/* fbtft-bus.c */ 288/* fbtft-bus.c */
290extern int fbtft_write_vmem8_bus8(struct fbtft_par *par, size_t offset, size_t len); 289int fbtft_write_vmem8_bus8(struct fbtft_par *par, size_t offset, size_t len);
291extern int fbtft_write_vmem16_bus16(struct fbtft_par *par, size_t offset, size_t len); 290int fbtft_write_vmem16_bus16(struct fbtft_par *par, size_t offset, size_t len);
292extern int fbtft_write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len); 291int fbtft_write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len);
293extern int fbtft_write_vmem16_bus9(struct fbtft_par *par, size_t offset, size_t len); 292int fbtft_write_vmem16_bus9(struct fbtft_par *par, size_t offset, size_t len);
294extern void fbtft_write_reg8_bus8(struct fbtft_par *par, int len, ...); 293void fbtft_write_reg8_bus8(struct fbtft_par *par, int len, ...);
295extern void fbtft_write_reg8_bus9(struct fbtft_par *par, int len, ...); 294void fbtft_write_reg8_bus9(struct fbtft_par *par, int len, ...);
296extern void fbtft_write_reg16_bus8(struct fbtft_par *par, int len, ...); 295void fbtft_write_reg16_bus8(struct fbtft_par *par, int len, ...);
297extern void fbtft_write_reg16_bus16(struct fbtft_par *par, int len, ...); 296void fbtft_write_reg16_bus16(struct fbtft_par *par, int len, ...);
298 297
299 298
300#define FBTFT_REGISTER_DRIVER(_name, _compatible, _display) \ 299#define FBTFT_REGISTER_DRIVER(_name, _compatible, _display) \
diff --git a/drivers/staging/fbtft/fbtft_device.c b/drivers/staging/fbtft/fbtft_device.c
index 211d504901f2..fa916e88d549 100644
--- a/drivers/staging/fbtft/fbtft_device.c
+++ b/drivers/staging/fbtft/fbtft_device.c
@@ -397,6 +397,37 @@ static struct fbtft_device_display displays[] = {
397 } 397 }
398 } 398 }
399 }, { 399 }, {
400 .name = "ew24ha0",
401 .spi = &(struct spi_board_info) {
402 .modalias = "fb_uc1611",
403 .max_speed_hz = 32000000,
404 .mode = SPI_MODE_3,
405 .platform_data = &(struct fbtft_platform_data) {
406 .display = {
407 .buswidth = 8,
408 },
409 .gpios = (const struct fbtft_gpio []) {
410 { "dc", 24 },
411 {},
412 },
413 }
414 }
415 }, {
416 .name = "ew24ha0_9bit",
417 .spi = &(struct spi_board_info) {
418 .modalias = "fb_uc1611",
419 .max_speed_hz = 32000000,
420 .mode = SPI_MODE_3,
421 .platform_data = &(struct fbtft_platform_data) {
422 .display = {
423 .buswidth = 9,
424 },
425 .gpios = (const struct fbtft_gpio []) {
426 {},
427 },
428 }
429 }
430 }, {
400 .name = "flexfb", 431 .name = "flexfb",
401 .spi = &(struct spi_board_info) { 432 .spi = &(struct spi_board_info) {
402 .modalias = "flexfb", 433 .modalias = "flexfb",
diff --git a/drivers/staging/fbtft/flexfb.c b/drivers/staging/fbtft/flexfb.c
index 2c4ce07f5106..c763efc5de7d 100644
--- a/drivers/staging/fbtft/flexfb.c
+++ b/drivers/staging/fbtft/flexfb.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 15 */
20 16
21#include <linux/module.h> 17#include <linux/module.h>
@@ -30,7 +26,6 @@
30 26
31#define DRVNAME "flexfb" 27#define DRVNAME "flexfb"
32 28
33
34static char *chip; 29static char *chip;
35module_param(chip, charp, 0); 30module_param(chip, charp, 0);
36MODULE_PARM_DESC(chip, "LCD controller"); 31MODULE_PARM_DESC(chip, "LCD controller");
@@ -68,7 +63,6 @@ static bool latched;
68module_param(latched, bool, 0); 63module_param(latched, bool, 0);
69MODULE_PARM_DESC(latched, "Use with latched 16-bit databus"); 64MODULE_PARM_DESC(latched, "Use with latched 16-bit databus");
70 65
71
72static int *initp; 66static int *initp;
73static int initp_num; 67static int initp_num;
74 68
@@ -132,14 +126,115 @@ static int ssd1351_init[] = { -1, 0xfd, 0x12, -1, 0xfd, 0xb1, -1, 0xae, -1, 0xb3
132 -1, 0xab, 0x01, -1, 0xb1, 0x32, -1, 0xb4, 0xa0, 0xb5, 0x55, -1, 0xbb, 0x17, -1, 0xbe, 0x05, 126 -1, 0xab, 0x01, -1, 0xb1, 0x32, -1, 0xb4, 0xa0, 0xb5, 0x55, -1, 0xbb, 0x17, -1, 0xbe, 0x05,
133 -1, 0xc1, 0xc8, 0x80, 0xc8, -1, 0xc7, 0x0f, -1, 0xb6, 0x01, -1, 0xa6, -1, 0xaf, -3 }; 127 -1, 0xc1, 0xc8, 0x80, 0xc8, -1, 0xc7, 0x0f, -1, 0xb6, 0x01, -1, 0xa6, -1, 0xaf, -3 };
134 128
129/**
130 * struct flexfb_lcd_controller - Describes the LCD controller properties
131 * @name: Model name of the chip
132 * @width: Width of display in pixels
133 * @height: Height of display in pixels
134 * @setaddrwin: Which set_addr_win() implementation to use
135 * @regwidth: LCD Controller Register width in bits
136 * @init_seq: LCD initialization sequence
137 * @init_seq_sz: Size of LCD initialization sequence
138 */
139struct flexfb_lcd_controller {
140 const char *name;
141 unsigned int width;
142 unsigned int height;
143 unsigned int setaddrwin;
144 unsigned int regwidth;
145 int *init_seq;
146 int init_seq_sz;
147};
148
149static const struct flexfb_lcd_controller flexfb_chip_table[] = {
150 {
151 .name = "st7735r",
152 .width = 120,
153 .height = 160,
154 .init_seq = st7735r_init,
155 .init_seq_sz = ARRAY_SIZE(st7735r_init),
156 },
157 {
158 .name = "hx8340bn",
159 .width = 176,
160 .height = 220,
161 .init_seq = hx8340bn_init,
162 .init_seq_sz = ARRAY_SIZE(hx8340bn_init),
163 },
164 {
165 .name = "ili9225",
166 .width = 176,
167 .height = 220,
168 .regwidth = 16,
169 .init_seq = ili9225_init,
170 .init_seq_sz = ARRAY_SIZE(ili9225_init),
171 },
172 {
173 .name = "ili9225",
174 .width = 176,
175 .height = 220,
176 .regwidth = 16,
177 .init_seq = ili9225_init,
178 .init_seq_sz = ARRAY_SIZE(ili9225_init),
179 },
180 {
181 .name = "ili9225",
182 .width = 176,
183 .height = 220,
184 .regwidth = 16,
185 .init_seq = ili9225_init,
186 .init_seq_sz = ARRAY_SIZE(ili9225_init),
187 },
188 {
189 .name = "ili9320",
190 .width = 240,
191 .height = 320,
192 .setaddrwin = 1,
193 .regwidth = 16,
194 .init_seq = ili9320_init,
195 .init_seq_sz = ARRAY_SIZE(ili9320_init),
196 },
197 {
198 .name = "ili9325",
199 .width = 240,
200 .height = 320,
201 .setaddrwin = 1,
202 .regwidth = 16,
203 .init_seq = ili9325_init,
204 .init_seq_sz = ARRAY_SIZE(ili9325_init),
205 },
206 {
207 .name = "ili9341",
208 .width = 240,
209 .height = 320,
210 .init_seq = ili9341_init,
211 .init_seq_sz = ARRAY_SIZE(ili9341_init),
212 },
213 {
214 .name = "ssd1289",
215 .width = 240,
216 .height = 320,
217 .setaddrwin = 2,
218 .regwidth = 16,
219 .init_seq = ssd1289_init,
220 .init_seq_sz = ARRAY_SIZE(ssd1289_init),
221 },
222 {
223 .name = "ssd1351",
224 .width = 128,
225 .height = 128,
226 .setaddrwin = 3,
227 .init_seq = ssd1351_init,
228 .init_seq_sz = ARRAY_SIZE(ssd1351_init),
229 },
230};
135 231
136/* ili9320, ili9325 */ 232/* ili9320, ili9325 */
137static void flexfb_set_addr_win_1(struct fbtft_par *par, 233static void flexfb_set_addr_win_1(struct fbtft_par *par,
138 int xs, int ys, int xe, int ye) 234 int xs, int ys, int xe, int ye)
139{ 235{
140 fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, 236 fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n",
141 "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", 237 __func__, xs, ys, xe, ye);
142 __func__, xs, ys, xe, ye);
143 switch (par->info->var.rotate) { 238 switch (par->info->var.rotate) {
144 /* R20h = Horizontal GRAM Start Address */ 239 /* R20h = Horizontal GRAM Start Address */
145 /* R21h = Vertical GRAM Start Address */ 240 /* R21h = Vertical GRAM Start Address */
@@ -242,7 +337,7 @@ static int flexfb_verify_gpios_db(struct fbtft_par *par)
242 return -EINVAL; 337 return -EINVAL;
243 } 338 }
244 if (latched) 339 if (latched)
245 num_db = buswidth/2; 340 num_db = buswidth / 2;
246 for (i = 0; i < num_db; i++) { 341 for (i = 0; i < num_db; i++) {
247 if (par->gpio.db[i] < 0) { 342 if (par->gpio.db[i] < 0) {
248 dev_err(par->info->device, 343 dev_err(par->info->device,
@@ -255,8 +350,38 @@ static int flexfb_verify_gpios_db(struct fbtft_par *par)
255 return 0; 350 return 0;
256} 351}
257 352
353static void flexfb_chip_load_param(const struct flexfb_lcd_controller *chip)
354{
355 if (!width)
356 width = chip->width;
357 if (!height)
358 height = chip->height;
359 setaddrwin = chip->setaddrwin;
360 if (chip->regwidth)
361 regwidth = chip->regwidth;
362 if (!init_num) {
363 initp = chip->init_seq;
364 initp_num = chip->init_seq_sz;
365 }
366}
367
258static struct fbtft_display flex_display = { }; 368static struct fbtft_display flex_display = { };
259 369
370static int flexfb_chip_init(const struct device *dev)
371{
372 int i;
373
374 for (i = 0; i < ARRAY_SIZE(flexfb_chip_table); i++)
375 if (!strcmp(chip, flexfb_chip_table[i].name)) {
376 flexfb_chip_load_param(&flexfb_chip_table[i]);
377 return 0;
378 }
379
380 dev_err(dev, "chip=%s is not supported\n", chip);
381
382 return -EINVAL;
383}
384
260static int flexfb_probe_common(struct spi_device *sdev, 385static int flexfb_probe_common(struct spi_device *sdev,
261 struct platform_device *pdev) 386 struct platform_device *pdev)
262{ 387{
@@ -277,110 +402,9 @@ static int flexfb_probe_common(struct spi_device *sdev,
277 sdev ? "'SPI device'" : "'Platform device'"); 402 sdev ? "'SPI device'" : "'Platform device'");
278 403
279 if (chip) { 404 if (chip) {
280 405 ret = flexfb_chip_init(dev);
281 if (!strcmp(chip, "st7735r")) { 406 if (ret)
282 if (!width) 407 return ret;
283 width = 128;
284 if (!height)
285 height = 160;
286 if (init_num == 0) {
287 initp = st7735r_init;
288 initp_num = ARRAY_SIZE(st7735r_init);
289 }
290
291
292 } else if (!strcmp(chip, "hx8340bn")) {
293 if (!width)
294 width = 176;
295 if (!height)
296 height = 220;
297 setaddrwin = 0;
298 if (init_num == 0) {
299 initp = hx8340bn_init;
300 initp_num = ARRAY_SIZE(hx8340bn_init);
301 }
302
303
304 } else if (!strcmp(chip, "ili9225")) {
305 if (!width)
306 width = 176;
307 if (!height)
308 height = 220;
309 setaddrwin = 0;
310 regwidth = 16;
311 if (init_num == 0) {
312 initp = ili9225_init;
313 initp_num = ARRAY_SIZE(ili9225_init);
314 }
315
316
317
318 } else if (!strcmp(chip, "ili9320")) {
319 if (!width)
320 width = 240;
321 if (!height)
322 height = 320;
323 setaddrwin = 1;
324 regwidth = 16;
325 if (init_num == 0) {
326 initp = ili9320_init;
327 initp_num = ARRAY_SIZE(ili9320_init);
328 }
329
330
331 } else if (!strcmp(chip, "ili9325")) {
332 if (!width)
333 width = 240;
334 if (!height)
335 height = 320;
336 setaddrwin = 1;
337 regwidth = 16;
338 if (init_num == 0) {
339 initp = ili9325_init;
340 initp_num = ARRAY_SIZE(ili9325_init);
341 }
342
343 } else if (!strcmp(chip, "ili9341")) {
344 if (!width)
345 width = 240;
346 if (!height)
347 height = 320;
348 setaddrwin = 0;
349 regwidth = 8;
350 if (init_num == 0) {
351 initp = ili9341_init;
352 initp_num = ARRAY_SIZE(ili9341_init);
353 }
354
355
356 } else if (!strcmp(chip, "ssd1289")) {
357 if (!width)
358 width = 240;
359 if (!height)
360 height = 320;
361 setaddrwin = 2;
362 regwidth = 16;
363 if (init_num == 0) {
364 initp = ssd1289_init;
365 initp_num = ARRAY_SIZE(ssd1289_init);
366 }
367
368
369
370 } else if (!strcmp(chip, "ssd1351")) {
371 if (!width)
372 width = 128;
373 if (!height)
374 height = 128;
375 setaddrwin = 3;
376 if (init_num == 0) {
377 initp = ssd1351_init;
378 initp_num = ARRAY_SIZE(ssd1351_init);
379 }
380 } else {
381 dev_err(dev, "chip=%s is not supported\n", chip);
382 return -EINVAL;
383 }
384 } 408 }
385 409
386 if (width == 0 || height == 0) { 410 if (width == 0 || height == 0) {
@@ -395,7 +419,7 @@ static int flexfb_probe_common(struct spi_device *sdev,
395 fbtft_init_dbg(dev, "regwidth = %d\n", regwidth); 419 fbtft_init_dbg(dev, "regwidth = %d\n", regwidth);
396 fbtft_init_dbg(dev, "buswidth = %d\n", buswidth); 420 fbtft_init_dbg(dev, "buswidth = %d\n", buswidth);
397 421
398 info = fbtft_framebuffer_alloc(&flex_display, dev); 422 info = fbtft_framebuffer_alloc(&flex_display, dev, dev->platform_data);
399 if (!info) 423 if (!info)
400 return -ENOMEM; 424 return -ENOMEM;
401 425
@@ -527,8 +551,8 @@ static int flexfb_remove_common(struct device *dev, struct fb_info *info)
527 return -EINVAL; 551 return -EINVAL;
528 par = info->par; 552 par = info->par;
529 if (par) 553 if (par)
530 fbtft_par_dbg(DEBUG_DRIVER_INIT_FUNCTIONS, par, 554 fbtft_par_dbg(DEBUG_DRIVER_INIT_FUNCTIONS, par, "%s()\n",
531 "%s()\n", __func__); 555 __func__);
532 fbtft_unregister_framebuffer(info); 556 fbtft_unregister_framebuffer(info);
533 fbtft_framebuffer_release(info); 557 fbtft_framebuffer_release(info);
534 558
diff --git a/drivers/staging/fsl-mc/README.txt b/drivers/staging/fsl-mc/README.txt
new file mode 100644
index 000000000000..8214102f104b
--- /dev/null
+++ b/drivers/staging/fsl-mc/README.txt
@@ -0,0 +1,364 @@
1Copyright (C) 2015 Freescale Semiconductor Inc.
2
3DPAA2 (Data Path Acceleration Architecture Gen2)
4------------------------------------------------
5
6This document provides an overview of the Freescale DPAA2 architecture
7and how it is integrated into the Linux kernel.
8
9Contents summary
10 -DPAA2 overview
11 -Overview of DPAA2 objects
12 -DPAA2 Linux driver architecture overview
13 -bus driver
14 -dprc driver
15 -allocator
16 -dpio driver
17 -Ethernet
18 -mac
19
20DPAA2 Overview
21--------------
22
23DPAA2 is a hardware architecture designed for high-speeed network
24packet processing. DPAA2 consists of sophisticated mechanisms for
25processing Ethernet packets, queue management, buffer management,
26autonomous L2 switching, virtual Ethernet bridging, and accelerator
27(e.g. crypto) sharing.
28
29A DPAA2 hardware component called the Management Complex (or MC) manages the
30DPAA2 hardware resources. The MC provides an object-based abstraction for
31software drivers to use the DPAA2 hardware.
32
33The MC uses DPAA2 hardware resources such as queues, buffer pools, and
34network ports to create functional objects/devices such as network
35interfaces, an L2 switch, or accelerator instances.
36
37The MC provides memory-mapped I/O command interfaces (MC portals)
38which DPAA2 software drivers use to operate on DPAA2 objects:
39
40 +--------------------------------------+
41 | OS |
42 | DPAA2 drivers |
43 | | |
44 +-----------------------------|--------+
45 |
46 | (create,discover,connect
47 | config,use,destroy)
48 |
49 DPAA2 |
50 +------------------------| mc portal |-+
51 | | |
52 | +- - - - - - - - - - - - -V- - -+ |
53 | | | |
54 | | Management Complex (MC) | |
55 | | | |
56 | +- - - - - - - - - - - - - - - -+ |
57 | |
58 | Hardware Hardware |
59 | Resources Objects |
60 | --------- ------- |
61 | -queues -DPRC |
62 | -buffer pools -DPMCP |
63 | -Eth MACs/ports -DPIO |
64 | -network interface -DPNI |
65 | profiles -DPMAC |
66 | -queue portals -DPBP |
67 | -MC portals ... |
68 | ... |
69 | |
70 +--------------------------------------+
71
72The MC mediates operations such as create, discover,
73connect, configuration, and destroy. Fast-path operations
74on data, such as packet transmit/receive, are not mediated by
75the MC and are done directly using memory mapped regions in
76DPIO objects.
77
78Overview of DPAA2 Objects
79-------------------------
80The section provides a brief overview of some key objects
81in the DPAA2 hardware. A simple scenario is described illustrating
82the objects involved in creating a network interfaces.
83
84-DPRC (Datapath Resource Container)
85
86 A DPRC is an container object that holds all the other
87 types of DPAA2 objects. In the example diagram below there
88 are 8 objects of 5 types (DPMCP, DPIO, DPBP, DPNI, and DPMAC)
89 in the container.
90
91 +---------------------------------------------------------+
92 | DPRC |
93 | |
94 | +-------+ +-------+ +-------+ +-------+ +-------+ |
95 | | DPMCP | | DPIO | | DPBP | | DPNI | | DPMAC | |
96 | +-------+ +-------+ +-------+ +---+---+ +---+---+ |
97 | | DPMCP | | DPIO | |
98 | +-------+ +-------+ |
99 | | DPMCP | |
100 | +-------+ |
101 | |
102 +---------------------------------------------------------+
103
104 From the point of view of an OS, a DPRC is bus-like. Like
105 a plug-and-play bus, such as PCI, DPRC commands can be used to
106 enumerate the contents of the DPRC, discover the hardware
107 objects present (including mappable regions and interrupts).
108
109 dprc.1 (bus)
110 |
111 +--+--------+-------+-------+-------+
112 | | | | |
113 dpmcp.1 dpio.1 dpbp.1 dpni.1 dpmac.1
114 dpmcp.2 dpio.2
115 dpmcp.3
116
117 Hardware objects can be created and destroyed dynamically, providing
118 the ability to hot plug/unplug objects in and out of the DPRC.
119
120 A DPRC has a mappable mmio region (an MC portal) that can be used
121 to send MC commands. It has an interrupt for status events (like
122 hotplug).
123
124 All objects in a container share the same hardware "isolation context".
125 This means that with respect to an IOMMU the isolation granularity
126 is at the DPRC (container) level, not at the individual object
127 level.
128
129 DPRCs can be defined statically and populated with objects
130 via a config file passed to the MC when firmware starts
131 it. There is also a Linux user space tool called "restool"
132 that can be used to create/destroy containers and objects
133 dynamically.
134
135-DPAA2 Objects for an Ethernet Network Interface
136
137 A typical Ethernet NIC is monolithic-- the NIC device contains TX/RX
138 queuing mechanisms, configuration mechanisms, buffer management,
139 physical ports, and interrupts. DPAA2 uses a more granular approach
140 utilizing multiple hardware objects. Each object has specialized
141 functions, and are used together by software to provide Ethernet network
142 interface functionality. This approach provides efficient use of finite
143 hardware resources, flexibility, and performance advantages.
144
145 The diagram below shows the objects needed for a simple
146 network interface configuration on a system with 2 CPUs.
147
148 +---+---+ +---+---+
149 CPU0 CPU1
150 +---+---+ +---+---+
151 | |
152 +---+---+ +---+---+
153 DPIO DPIO
154 +---+---+ +---+---+
155 \ /
156 \ /
157 \ /
158 +---+---+
159 DPNI --- DPBP,DPMCP
160 +---+---+
161 |
162 |
163 +---+---+
164 DPMAC
165 +---+---+
166 |
167 port/PHY
168
169 Below the objects are described. For each object a brief description
170 is provided along with a summary of the kinds of operations the object
171 supports and a summary of key resources of the object (mmio regions
172 and irqs).
173
174 -DPMAC (Datapath Ethernet MAC): represents an Ethernet MAC, a
175 hardware device that connects to an Ethernet PHY and allows
176 physical transmission and reception of Ethernet frames.
177 -mmio regions: none
178 -irqs: dpni link change
179 -commands: set link up/down, link config, get stats,
180 irq config, enable, reset
181
182 -DPNI (Datapath Network Interface): contains TX/RX queues,
183 network interface configuration, and rx buffer pool configuration
184 mechanisms.
185 -mmio regions: none
186 -irqs: link state
187 -commands: port config, offload config, queue config,
188 parse/classify config, irq config, enable, reset
189
190 -DPIO (Datapath I/O): provides interfaces to enqueue and dequeue
191 packets and do hardware buffer pool management operations. For
192 optimum performance there is typically DPIO per CPU. This allows
193 each CPU to perform simultaneous enqueue/dequeue operations.
194 -mmio regions: queue operations, buffer mgmt
195 -irqs: data availability, congestion notification, buffer
196 pool depletion
197 -commands: irq config, enable, reset
198
199 -DPBP (Datapath Buffer Pool): represents a hardware buffer
200 pool.
201 -mmio regions: none
202 -irqs: none
203 -commands: enable, reset
204
205 -DPMCP (Datapath MC Portal): provides an MC command portal.
206 Used by drivers to send commands to the MC to manage
207 objects.
208 -mmio regions: MC command portal
209 -irqs: command completion
210 -commands: irq config, enable, reset
211
212 Object Connections
213 ------------------
214 Some objects have explicit relationships that must
215 be configured:
216
217 -DPNI <--> DPMAC
218 -DPNI <--> DPNI
219 -DPNI <--> L2-switch-port
220 A DPNI must be connected to something such as a DPMAC,
221 another DPNI, or L2 switch port. The DPNI connection
222 is made via a DPRC command.
223
224 +-------+ +-------+
225 | DPNI | | DPMAC |
226 +---+---+ +---+---+
227 | |
228 +==========+
229
230 -DPNI <--> DPBP
231 A network interface requires a 'buffer pool' (DPBP
232 object) which provides a list of pointers to memory
233 where received Ethernet data is to be copied. The
234 Ethernet driver configures the DPBPs associated with
235 the network interface.
236
237 Interrupts
238 ----------
239 All interrupts generated by DPAA2 objects are message
240 interrupts. At the hardware level message interrupts
241 generated by devices will normally have 3 components--
242 1) a non-spoofable 'device-id' expressed on the hardware
243 bus, 2) an address, 3) a data value.
244
245 In the case of DPAA2 devices/objects, all objects in the
246 same container/DPRC share the same 'device-id'.
247 For ARM-based SoC this is the same as the stream ID.
248
249
250DPAA2 Linux Driver Overview
251---------------------------
252
253This section provides an overview of the Linux kernel drivers for
254DPAA2-- 1) the bus driver and associated "DPAA2 infrastructure"
255drivers and 2) functional object drivers (such as Ethernet).
256
257As described previously, a DPRC is a container that holds the other
258types of DPAA2 objects. It is functionally similar to a plug-and-play
259bus controller.
260
261Each object in the DPRC is a Linux "device" and is bound to a driver.
262The diagram below shows the Linux drivers involved in a networking
263scenario and the objects bound to each driver. A brief description
264of each driver follows.
265
266 +------------+
267 | OS Network |
268 | Stack |
269 +------------+ +------------+
270 | Allocator |. . . . . . . | Ethernet |
271 |(dpmcp,dpbp)| | (dpni) |
272 +-.----------+ +---+---+----+
273 . . ^ |
274 . . <data avail, | |<enqueue,
275 . . tx confirm> | | dequeue>
276 +-------------+ . | |
277 | DPRC driver | . +---+---V----+ +---------+
278 | (dprc) | . . . . . .| DPIO driver| | MAC |
279 +----------+--+ | (dpio) | | (dpmac) |
280 | +------+-----+ +-----+---+
281 |<dev add/remove> | |
282 | | |
283 +----+--------------+ | +--+---+
284 | mc-bus driver | | | PHY |
285 | | | |driver|
286 | /fsl-mc@80c000000 | | +--+---+
287 +-------------------+ | |
288 | |
289 ================================ HARDWARE =========|=================|======
290 DPIO |
291 | |
292 DPNI---DPBP |
293 | |
294 DPMAC |
295 | |
296 PHY ---------------+
297 ===================================================|========================
298
299A brief description of each driver is provided below.
300
301 mc-bus driver
302 -------------
303 The mc-bus driver is a platform driver and is probed from an
304 "/fsl-mc@xxxx" node in the device tree passed in by boot firmware.
305 It is responsible for bootstrapping the DPAA2 kernel infrastructure.
306 Key functions include:
307 -registering a new bus type named "fsl-mc" with the kernel,
308 and implementing bus call-backs (e.g. match/uevent/dev_groups)
309 -implemeting APIs for DPAA2 driver registration and for device
310 add/remove
311 -creates an MSI irq domain
312 -do a device add of the 'root' DPRC device, which is needed
313 to bootstrap things
314
315 DPRC driver
316 -----------
317 The dprc-driver is bound DPRC objects and does runtime management
318 of a bus instance. It performs the initial bus scan of the DPRC
319 and handles interrupts for container events such as hot plug.
320
321 Allocator
322 ----------
323 Certain objects such as DPMCP and DPBP are generic and fungible,
324 and are intended to be used by other drivers. For example,
325 the DPAA2 Ethernet driver needs:
326 -DPMCPs to send MC commands, to configure network interfaces
327 -DPBPs for network buffer pools
328
329 The allocator driver registers for these allocatable object types
330 and those objects are bound to the allocator when the bus is probed.
331 The allocator maintains a pool of objects that are available for
332 allocation by other DPAA2 drivers.
333
334 DPIO driver
335 -----------
336 The DPIO driver is bound to DPIO objects and provides services that allow
337 other drivers such as the Ethernet driver to receive and transmit data.
338 Key services include:
339 -data availability notifications
340 -hardware queuing operations (enqueue and dequeue of data)
341 -hardware buffer pool management
342
343 There is typically one DPIO object per physical CPU for optimum
344 performance, allowing each CPU to simultaneously enqueue
345 and dequeue data.
346
347 The DPIO driver operates on behalf of all DPAA2 drivers
348 active in the kernel-- Ethernet, crypto, compression,
349 etc.
350
351 Ethernet
352 --------
353 The Ethernet driver is bound to a DPNI and implements the kernel
354 interfaces needed to connect the DPAA2 network interface to
355 the network stack.
356
357 Each DPNI corresponds to a Linux network interface.
358
359 MAC driver
360 ----------
361 An Ethernet PHY is an off-chip, board specific component and is managed
362 by the appropriate PHY driver via an mdio bus. The MAC driver
363 plays a role of being a proxy between the PHY driver and the
364 MC. It does this proxy via the MC commands to a DPMAC object.
diff --git a/drivers/staging/fsl-mc/TODO b/drivers/staging/fsl-mc/TODO
index d78288b4e721..389436891b93 100644
--- a/drivers/staging/fsl-mc/TODO
+++ b/drivers/staging/fsl-mc/TODO
@@ -1,13 +1,31 @@
1* Add README file (with ASCII art) describing relationships between
2 DPAA2 objects and how combine them to make a NIC, an LS2 switch, etc.
3 Also, define all acronyms used.
4
5* Decide if multiple root fsl-mc buses will be supported per Linux instance, 1* Decide if multiple root fsl-mc buses will be supported per Linux instance,
6 and if so add support for this. 2 and if so add support for this.
7 3
8* Add at least one device driver for a DPAA2 object (child device of the 4* Add at least one device driver for a DPAA2 object (child device of the
9 fsl-mc bus). 5 fsl-mc bus). Most likely candidate for this is adding DPAA2 Ethernet
6 driver support, which depends on drivers for several objects: DPNI,
7 DPIO, DPMAC. Other pre-requisites include:
8
9 * interrupt support. for meaningful driver support we need
10 interrupts, and thus need message interrupt support by the bus
11 driver.
12 -Note: this has dependencies on generic MSI support work
13 in process upstream, see [1] and [2].
14
15 * Management Complex (MC) command serialization. locking mechanisms
16 are needed by drivers to serialize commands sent to the MC, including
17 from atomic context.
18
19 * MC firmware uprev. The MC firmware upon which the fsl-mc
20 bus driver and DPAA2 object drivers are based is continuing
21 to evolve, so minor updates are needed to keep in sync with binary
22 interface changes to the MC.
23
24* Cleanup
10 25
11Please send any patches to Greg Kroah-Hartman <gregkh@linuxfoundation.org>, 26Please send any patches to Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
12german.rivera@freescale.com, devel@driverdev.osuosl.org, 27german.rivera@freescale.com, devel@driverdev.osuosl.org,
13linux-kernel@vger.kernel.org 28linux-kernel@vger.kernel.org
29
30[1] https://lkml.org/lkml/2015/7/9/93
31[2] https://lkml.org/lkml/2015/7/7/712
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h b/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h
index 5992670f7747..e1861cf5de73 100644
--- a/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h
+++ b/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h
@@ -42,17 +42,16 @@ struct ft1000_pcmcia {
42 42
43struct pcmcia_device; 43struct pcmcia_device;
44struct net_device; 44struct net_device;
45extern struct net_device *init_ft1000_card(struct pcmcia_device *link, 45struct net_device *init_ft1000_card(struct pcmcia_device *link,
46 void *ft1000_reset); 46 void *ft1000_reset);
47extern void stop_ft1000_card(struct net_device *dev); 47void stop_ft1000_card(struct net_device *dev);
48extern int card_download(struct net_device *dev, const u8 *pFileStart, 48int card_download(struct net_device *dev, const u8 *pFileStart,
49 size_t FileLength); 49 size_t FileLength);
50 50
51extern u16 ft1000_read_dpram(struct net_device *dev, int offset); 51u16 ft1000_read_dpram(struct net_device *dev, int offset);
52extern void card_bootload(struct net_device *dev); 52void card_bootload(struct net_device *dev);
53extern u16 ft1000_read_dpram_mag_16(struct net_device *dev, int offset, 53u16 ft1000_read_dpram_mag_16(struct net_device *dev, int offset, int Index);
54 int Index); 54u32 ft1000_read_dpram_mag_32(struct net_device *dev, int offset);
55extern u32 ft1000_read_dpram_mag_32(struct net_device *dev, int offset);
56void ft1000_write_dpram_mag_32(struct net_device *dev, int offset, u32 value); 55void ft1000_write_dpram_mag_32(struct net_device *dev, int offset, u32 value);
57 56
58/* Read the value of a given ASIC register. */ 57/* Read the value of a given ASIC register. */
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
index 409266b1a886..f241a3a5a684 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
@@ -260,7 +260,8 @@ void ft1000_destroy_dev(struct net_device *netdev)
260 /* Make sure we free any memory reserve for slow Queue */ 260 /* Make sure we free any memory reserve for slow Queue */
261 for (i = 0; i < MAX_NUM_APP; i++) { 261 for (i = 0; i < MAX_NUM_APP; i++) {
262 while (list_empty(&dev->app_info[i].app_sqlist) == 0) { 262 while (list_empty(&dev->app_info[i].app_sqlist) == 0) {
263 pdpram_blk = list_entry(dev->app_info[i].app_sqlist.next, struct dpram_blk, list); 263 pdpram_blk = list_entry(dev->app_info[i].app_sqlist.next,
264 struct dpram_blk, list);
264 list_del(&pdpram_blk->list); 265 list_del(&pdpram_blk->list);
265 ft1000_free_buffer(pdpram_blk, &freercvpool); 266 ft1000_free_buffer(pdpram_blk, &freercvpool);
266 267
@@ -415,12 +416,19 @@ static long ft1000_ioctl(struct file *file, unsigned int command,
415 struct timeval tv; 416 struct timeval tv;
416 struct IOCTL_GET_VER get_ver_data; 417 struct IOCTL_GET_VER get_ver_data;
417 struct IOCTL_GET_DSP_STAT get_stat_data; 418 struct IOCTL_GET_DSP_STAT get_stat_data;
418 u8 ConnectionMsg[] = {0x00, 0x44, 0x10, 0x20, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x93, 0x64, 419 u8 ConnectionMsg[] = {
419 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x0a, 420 0x00, 0x44, 0x10, 0x20, 0x80, 0x00, 0x00, 0x00,
420 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 421 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x93, 0x64,
421 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 422 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
422 0x00, 0x00, 0x02, 0x37, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x7f, 0x00, 423 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x0a,
423 0x00, 0x01, 0x00, 0x00}; 424 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
425 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
426 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12,
427 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
428 0x00, 0x00, 0x02, 0x37, 0x00, 0x00, 0x00, 0x08,
429 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x7f, 0x00,
430 0x00, 0x01, 0x00, 0x00
431 };
424 432
425 unsigned short ledStat = 0; 433 unsigned short ledStat = 0;
426 unsigned short conStat = 0; 434 unsigned short conStat = 0;
@@ -495,10 +503,12 @@ static long ft1000_ioctl(struct file *file, unsigned int command,
495 memcpy(get_stat_data.eui64, info->eui64, EUISZ); 503 memcpy(get_stat_data.eui64, info->eui64, EUISZ);
496 504
497 if (info->ProgConStat != 0xFF) { 505 if (info->ProgConStat != 0xFF) {
498 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_LED, (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX); 506 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_LED,
507 (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX);
499 get_stat_data.LedStat = ntohs(ledStat); 508 get_stat_data.LedStat = ntohs(ledStat);
500 pr_debug("LedStat = 0x%x\n", get_stat_data.LedStat); 509 pr_debug("LedStat = 0x%x\n", get_stat_data.LedStat);
501 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_CON_STATE, (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX); 510 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_CON_STATE,
511 (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX);
502 get_stat_data.ConStat = ntohs(conStat); 512 get_stat_data.ConStat = ntohs(conStat);
503 pr_debug("ConStat = 0x%x\n", get_stat_data.ConStat); 513 pr_debug("ConStat = 0x%x\n", get_stat_data.ConStat);
504 } else { 514 } else {
@@ -689,7 +699,8 @@ static long ft1000_ioctl(struct file *file, unsigned int command,
689 if (list_empty(&ft1000dev->app_info[i].app_sqlist) == 0) { 699 if (list_empty(&ft1000dev->app_info[i].app_sqlist) == 0) {
690 /* pr_debug("Message detected in slow queue\n"); */ 700 /* pr_debug("Message detected in slow queue\n"); */
691 spin_lock_irqsave(&free_buff_lock, flags); 701 spin_lock_irqsave(&free_buff_lock, flags);
692 pdpram_blk = list_entry(ft1000dev->app_info[i].app_sqlist.next, struct dpram_blk, list); 702 pdpram_blk = list_entry(ft1000dev->app_info[i].app_sqlist.next,
703 struct dpram_blk, list);
693 list_del(&pdpram_blk->list); 704 list_del(&pdpram_blk->list);
694 ft1000dev->app_info[i].NumOfMsg--; 705 ft1000dev->app_info[i].NumOfMsg--;
695 /* pr_debug("NumOfMsg for app %d = %d\n", i, ft1000dev->app_info[i].NumOfMsg); */ 706 /* pr_debug("NumOfMsg for app %d = %d\n", i, ft1000dev->app_info[i].NumOfMsg); */
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
index 5def347beb08..297b7aece506 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
@@ -95,7 +95,6 @@ struct dsp_file_hdr {
95 long nDspImages; /* Number of DSP images in file. */ 95 long nDspImages; /* Number of DSP images in file. */
96}; 96};
97 97
98#pragma pack(1)
99struct dsp_image_info { 98struct dsp_image_info {
100 long coff_date; /* Date/time when DSP Coff image was built. */ 99 long coff_date; /* Date/time when DSP Coff image was built. */
101 long begin_offset; /* Offset in file where image begins. */ 100 long begin_offset; /* Offset in file where image begins. */
@@ -105,7 +104,7 @@ struct dsp_image_info {
105 long version; /* Embedded version # of DSP code. */ 104 long version; /* Embedded version # of DSP code. */
106 unsigned short checksum; /* DSP File checksum */ 105 unsigned short checksum; /* DSP File checksum */
107 unsigned short pad1; 106 unsigned short pad1;
108}; 107} __packed;
109 108
110 109
111/* checks if the doorbell register is cleared */ 110/* checks if the doorbell register is cleared */
@@ -180,7 +179,8 @@ static u16 get_handshake(struct ft1000_usb *ft1000dev, u16 expected_value)
180 } 179 }
181 180
182 status = ft1000_read_dpram16(ft1000dev, 181 status = ft1000_read_dpram16(ft1000dev,
183 DWNLD_MAG1_HANDSHAKE_LOC, (u8 *)&handshake, 1); 182 DWNLD_MAG1_HANDSHAKE_LOC,
183 (u8 *)&handshake, 1);
184 handshake = ntohs(handshake); 184 handshake = ntohs(handshake);
185 185
186 if (status) 186 if (status)
@@ -281,12 +281,14 @@ static u16 get_request_type(struct ft1000_usb *ft1000dev)
281 281
282 if (ft1000dev->bootmode == 1) { 282 if (ft1000dev->bootmode == 1) {
283 status = fix_ft1000_read_dpram32(ft1000dev, 283 status = fix_ft1000_read_dpram32(ft1000dev,
284 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx); 284 DWNLD_MAG1_TYPE_LOC,
285 (u8 *)&tempx);
285 tempx = ntohl(tempx); 286 tempx = ntohl(tempx);
286 } else { 287 } else {
287 tempx = 0; 288 tempx = 0;
288 status = ft1000_read_dpram16(ft1000dev, 289 status = ft1000_read_dpram16(ft1000dev,
289 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempword, 1); 290 DWNLD_MAG1_TYPE_LOC,
291 (u8 *)&tempword, 1);
290 tempx |= (tempword << 16); 292 tempx |= (tempword << 16);
291 tempx = ntohl(tempx); 293 tempx = ntohl(tempx);
292 } 294 }
@@ -304,7 +306,8 @@ static u16 get_request_type_usb(struct ft1000_usb *ft1000dev)
304 306
305 if (ft1000dev->bootmode == 1) { 307 if (ft1000dev->bootmode == 1) {
306 status = fix_ft1000_read_dpram32(ft1000dev, 308 status = fix_ft1000_read_dpram32(ft1000dev,
307 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx); 309 DWNLD_MAG1_TYPE_LOC,
310 (u8 *)&tempx);
308 tempx = ntohl(tempx); 311 tempx = ntohl(tempx);
309 } else { 312 } else {
310 if (ft1000dev->usbboot == 2) { 313 if (ft1000dev->usbboot == 2) {
@@ -332,14 +335,17 @@ static long get_request_value(struct ft1000_usb *ft1000dev)
332 335
333 if (ft1000dev->bootmode == 1) { 336 if (ft1000dev->bootmode == 1) {
334 status = fix_ft1000_read_dpram32(ft1000dev, 337 status = fix_ft1000_read_dpram32(ft1000dev,
335 DWNLD_MAG1_SIZE_LOC, (u8 *)&value); 338 DWNLD_MAG1_SIZE_LOC,
339 (u8 *)&value);
336 value = ntohl(value); 340 value = ntohl(value);
337 } else { 341 } else {
338 status = ft1000_read_dpram16(ft1000dev, 342 status = ft1000_read_dpram16(ft1000dev,
339 DWNLD_MAG1_SIZE_LOC, (u8 *)&tempword, 0); 343 DWNLD_MAG1_SIZE_LOC,
344 (u8 *)&tempword, 0);
340 value = tempword; 345 value = tempword;
341 status = ft1000_read_dpram16(ft1000dev, 346 status = ft1000_read_dpram16(ft1000dev,
342 DWNLD_MAG1_SIZE_LOC, (u8 *)&tempword, 1); 347 DWNLD_MAG1_SIZE_LOC,
348 (u8 *)&tempword, 1);
343 value |= (tempword << 16); 349 value |= (tempword << 16);
344 value = ntohl(value); 350 value = ntohl(value);
345 } 351 }
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
index e6b5976a09e3..96209703ba25 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
@@ -842,7 +842,6 @@ static int ft1000_copy_up_pkt(struct urb *urb)
842 skb = dev_alloc_skb(len + 12 + 2); 842 skb = dev_alloc_skb(len + 12 + 2);
843 843
844 if (skb == NULL) { 844 if (skb == NULL) {
845 pr_debug("No Network buffers available\n");
846 info->stats.rx_errors++; 845 info->stats.rx_errors++;
847 ft1000_submit_rx_urb(info); 846 ft1000_submit_rx_urb(info);
848 return -1; 847 return -1;
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h
index fea60d5651a7..9b5050fcbb66 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h
@@ -134,8 +134,8 @@ extern spinlock_t free_buff_lock;
134 134
135int ft1000_create_dev(struct ft1000_usb *dev); 135int ft1000_create_dev(struct ft1000_usb *dev);
136void ft1000_destroy_dev(struct net_device *dev); 136void ft1000_destroy_dev(struct net_device *dev);
137extern int card_send_command(struct ft1000_usb *ft1000dev, 137int card_send_command(struct ft1000_usb *ft1000dev,
138 void *ptempbuffer, int size); 138 void *ptempbuffer, int size);
139 139
140struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist); 140struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist);
141void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist); 141void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist);
diff --git a/drivers/staging/gdm72xx/usb_ids.h b/drivers/staging/gdm72xx/usb_ids.h
index 8ce544de7342..7afb9ba5fdba 100644
--- a/drivers/staging/gdm72xx/usb_ids.h
+++ b/drivers/staging/gdm72xx/usb_ids.h
@@ -32,7 +32,9 @@
32#define BL_PID_MASK 0xffc0 32#define BL_PID_MASK 0xffc0
33 33
34#define USB_DEVICE_BOOTLOADER(vid, pid) \ 34#define USB_DEVICE_BOOTLOADER(vid, pid) \
35 {USB_DEVICE((vid), ((pid)&BL_PID_MASK)|B_DOWNLOAD)}, \ 35 {USB_DEVICE((vid), ((pid)&BL_PID_MASK)|B_DOWNLOAD)}
36
37#define USB_DEVICE_BOOTLOADER_DRV(vid, pid) \
36 {USB_DEVICE((vid), ((pid)&BL_PID_MASK)|B_DOWNLOAD|B_DIFF_DL_DRV)} 38 {USB_DEVICE((vid), ((pid)&BL_PID_MASK)|B_DOWNLOAD|B_DIFF_DL_DRV)}
37 39
38#define USB_DEVICE_CDC_DATA(vid, pid) \ 40#define USB_DEVICE_CDC_DATA(vid, pid) \
@@ -40,6 +42,7 @@
40 42
41static const struct usb_device_id id_table[] = { 43static const struct usb_device_id id_table[] = {
42 USB_DEVICE_BOOTLOADER(GCT_VID, GCT_PID1), 44 USB_DEVICE_BOOTLOADER(GCT_VID, GCT_PID1),
45 USB_DEVICE_BOOTLOADER_DRV(GCT_VID, GCT_PID1),
43 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1), 46 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1),
44 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0x1), 47 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0x1),
45 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0x2), 48 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0x2),
@@ -58,6 +61,7 @@ static const struct usb_device_id id_table[] = {
58 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0xf), 61 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID1+0xf),
59 62
60 USB_DEVICE_BOOTLOADER(GCT_VID, GCT_PID2), 63 USB_DEVICE_BOOTLOADER(GCT_VID, GCT_PID2),
64 USB_DEVICE_BOOTLOADER_DRV(GCT_VID, GCT_PID2),
61 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2), 65 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2),
62 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0x1), 66 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0x1),
63 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0x2), 67 USB_DEVICE_CDC_DATA(GCT_VID, GCT_PID2+0x2),
diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
index d7c5223f1c3e..3f7715c9968b 100644
--- a/drivers/staging/iio/adc/mxs-lradc.c
+++ b/drivers/staging/iio/adc/mxs-lradc.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Freescale i.MX28 LRADC driver 2 * Freescale MXS LRADC driver
3 * 3 *
4 * Copyright (c) 2012 DENX Software Engineering, GmbH. 4 * Copyright (c) 2012 DENX Software Engineering, GmbH.
5 * Marek Vasut <marex@denx.de> 5 * Marek Vasut <marex@denx.de>
@@ -15,34 +15,30 @@
15 * GNU General Public License for more details. 15 * GNU General Public License for more details.
16 */ 16 */
17 17
18#include <linux/bitops.h>
19#include <linux/clk.h>
20#include <linux/completion.h>
21#include <linux/device.h>
18#include <linux/err.h> 22#include <linux/err.h>
23#include <linux/input.h>
19#include <linux/interrupt.h> 24#include <linux/interrupt.h>
20#include <linux/device.h> 25#include <linux/io.h>
21#include <linux/kernel.h> 26#include <linux/kernel.h>
22#include <linux/slab.h> 27#include <linux/module.h>
28#include <linux/mutex.h>
23#include <linux/of.h> 29#include <linux/of.h>
24#include <linux/of_device.h> 30#include <linux/of_device.h>
25#include <linux/sysfs.h>
26#include <linux/list.h>
27#include <linux/io.h>
28#include <linux/module.h>
29#include <linux/platform_device.h> 31#include <linux/platform_device.h>
30#include <linux/spinlock.h> 32#include <linux/slab.h>
31#include <linux/wait.h>
32#include <linux/sched.h>
33#include <linux/stmp_device.h> 33#include <linux/stmp_device.h>
34#include <linux/bitops.h> 34#include <linux/sysfs.h>
35#include <linux/completion.h>
36#include <linux/delay.h>
37#include <linux/input.h>
38#include <linux/clk.h>
39 35
40#include <linux/iio/iio.h>
41#include <linux/iio/sysfs.h>
42#include <linux/iio/buffer.h> 36#include <linux/iio/buffer.h>
37#include <linux/iio/iio.h>
43#include <linux/iio/trigger.h> 38#include <linux/iio/trigger.h>
44#include <linux/iio/trigger_consumer.h> 39#include <linux/iio/trigger_consumer.h>
45#include <linux/iio/triggered_buffer.h> 40#include <linux/iio/triggered_buffer.h>
41#include <linux/iio/sysfs.h>
46 42
47#define DRIVER_NAME "mxs-lradc" 43#define DRIVER_NAME "mxs-lradc"
48 44
@@ -65,14 +61,14 @@
65 * Once the pen touches the touchscreen, the touchscreen switches from 61 * Once the pen touches the touchscreen, the touchscreen switches from
66 * IRQ-driven mode to polling mode to prevent interrupt storm. The polling 62 * IRQ-driven mode to polling mode to prevent interrupt storm. The polling
67 * is realized by worker thread, which is called every 20 or so milliseconds. 63 * is realized by worker thread, which is called every 20 or so milliseconds.
68 * This gives the touchscreen enough fluence and does not strain the system 64 * This gives the touchscreen enough fluency and does not strain the system
69 * too much. 65 * too much.
70 */ 66 */
71#define LRADC_TS_SAMPLE_DELAY_MS 5 67#define LRADC_TS_SAMPLE_DELAY_MS 5
72 68
73/* 69/*
74 * The LRADC reads the following amount of samples from each touchscreen 70 * The LRADC reads the following amount of samples from each touchscreen
75 * channel and the driver then computes avarage of these. 71 * channel and the driver then computes average of these.
76 */ 72 */
77#define LRADC_TS_SAMPLE_AMOUNT 4 73#define LRADC_TS_SAMPLE_AMOUNT 4
78 74
@@ -238,7 +234,7 @@ struct mxs_lradc {
238 * CH5 -- Touch screen YNLR 234 * CH5 -- Touch screen YNLR
239 * CH6 -- Touch screen WIPER (5-wire only) 235 * CH6 -- Touch screen WIPER (5-wire only)
240 * 236 *
241 * The bitfields below represents which parts of the LRADC block are 237 * The bit fields below represents which parts of the LRADC block are
242 * switched into special mode of operation. These channels can not 238 * switched into special mode of operation. These channels can not
243 * be sampled as regular LRADC channels. The driver will refuse any 239 * be sampled as regular LRADC channels. The driver will refuse any
244 * attempt to sample these channels. 240 * attempt to sample these channels.
@@ -252,7 +248,7 @@ struct mxs_lradc {
252 struct input_dev *ts_input; 248 struct input_dev *ts_input;
253 249
254 enum mxs_lradc_id soc; 250 enum mxs_lradc_id soc;
255 enum lradc_ts_plate cur_plate; /* statemachine */ 251 enum lradc_ts_plate cur_plate; /* state machine */
256 bool ts_valid; 252 bool ts_valid;
257 unsigned ts_x_pos; 253 unsigned ts_x_pos;
258 unsigned ts_y_pos; 254 unsigned ts_y_pos;
@@ -812,7 +808,7 @@ static int mxs_lradc_read_single(struct iio_dev *iio_dev, int chan, int *val)
812 int ret; 808 int ret;
813 809
814 /* 810 /*
815 * See if there is no buffered operation in progess. If there is, simply 811 * See if there is no buffered operation in progress. If there is, simply
816 * bail out. This can be improved to support both buffered and raw IO at 812 * bail out. This can be improved to support both buffered and raw IO at
817 * the same time, yet the code becomes horribly complicated. Therefore I 813 * the same time, yet the code becomes horribly complicated. Therefore I
818 * applied KISS principle here. 814 * applied KISS principle here.
@@ -1369,7 +1365,7 @@ static const struct iio_buffer_setup_ops mxs_lradc_buffer_ops = {
1369 * Driver initialization 1365 * Driver initialization
1370 */ 1366 */
1371 1367
1372#define MXS_ADC_CHAN(idx, chan_type) { \ 1368#define MXS_ADC_CHAN(idx, chan_type, name) { \
1373 .type = (chan_type), \ 1369 .type = (chan_type), \
1374 .indexed = 1, \ 1370 .indexed = 1, \
1375 .scan_index = (idx), \ 1371 .scan_index = (idx), \
@@ -1382,17 +1378,18 @@ static const struct iio_buffer_setup_ops mxs_lradc_buffer_ops = {
1382 .realbits = LRADC_RESOLUTION, \ 1378 .realbits = LRADC_RESOLUTION, \
1383 .storagebits = 32, \ 1379 .storagebits = 32, \
1384 }, \ 1380 }, \
1381 .datasheet_name = (name), \
1385} 1382}
1386 1383
1387static const struct iio_chan_spec mxs_lradc_chan_spec[] = { 1384static const struct iio_chan_spec mx23_lradc_chan_spec[] = {
1388 MXS_ADC_CHAN(0, IIO_VOLTAGE), 1385 MXS_ADC_CHAN(0, IIO_VOLTAGE, "LRADC0"),
1389 MXS_ADC_CHAN(1, IIO_VOLTAGE), 1386 MXS_ADC_CHAN(1, IIO_VOLTAGE, "LRADC1"),
1390 MXS_ADC_CHAN(2, IIO_VOLTAGE), 1387 MXS_ADC_CHAN(2, IIO_VOLTAGE, "LRADC2"),
1391 MXS_ADC_CHAN(3, IIO_VOLTAGE), 1388 MXS_ADC_CHAN(3, IIO_VOLTAGE, "LRADC3"),
1392 MXS_ADC_CHAN(4, IIO_VOLTAGE), 1389 MXS_ADC_CHAN(4, IIO_VOLTAGE, "LRADC4"),
1393 MXS_ADC_CHAN(5, IIO_VOLTAGE), 1390 MXS_ADC_CHAN(5, IIO_VOLTAGE, "LRADC5"),
1394 MXS_ADC_CHAN(6, IIO_VOLTAGE), 1391 MXS_ADC_CHAN(6, IIO_VOLTAGE, "VDDIO"),
1395 MXS_ADC_CHAN(7, IIO_VOLTAGE), /* VBATT */ 1392 MXS_ADC_CHAN(7, IIO_VOLTAGE, "VBATT"),
1396 /* Combined Temperature sensors */ 1393 /* Combined Temperature sensors */
1397 { 1394 {
1398 .type = IIO_TEMP, 1395 .type = IIO_TEMP,
@@ -1403,6 +1400,7 @@ static const struct iio_chan_spec mxs_lradc_chan_spec[] = {
1403 BIT(IIO_CHAN_INFO_SCALE), 1400 BIT(IIO_CHAN_INFO_SCALE),
1404 .channel = 8, 1401 .channel = 8,
1405 .scan_type = {.sign = 'u', .realbits = 18, .storagebits = 32,}, 1402 .scan_type = {.sign = 'u', .realbits = 18, .storagebits = 32,},
1403 .datasheet_name = "TEMP_DIE",
1406 }, 1404 },
1407 /* Hidden channel to keep indexes */ 1405 /* Hidden channel to keep indexes */
1408 { 1406 {
@@ -1411,12 +1409,48 @@ static const struct iio_chan_spec mxs_lradc_chan_spec[] = {
1411 .scan_index = -1, 1409 .scan_index = -1,
1412 .channel = 9, 1410 .channel = 9,
1413 }, 1411 },
1414 MXS_ADC_CHAN(10, IIO_VOLTAGE), /* VDDIO */ 1412 MXS_ADC_CHAN(10, IIO_VOLTAGE, NULL),
1415 MXS_ADC_CHAN(11, IIO_VOLTAGE), /* VTH */ 1413 MXS_ADC_CHAN(11, IIO_VOLTAGE, NULL),
1416 MXS_ADC_CHAN(12, IIO_VOLTAGE), /* VDDA */ 1414 MXS_ADC_CHAN(12, IIO_VOLTAGE, "USB_DP"),
1417 MXS_ADC_CHAN(13, IIO_VOLTAGE), /* VDDD */ 1415 MXS_ADC_CHAN(13, IIO_VOLTAGE, "USB_DN"),
1418 MXS_ADC_CHAN(14, IIO_VOLTAGE), /* VBG */ 1416 MXS_ADC_CHAN(14, IIO_VOLTAGE, "VBG"),
1419 MXS_ADC_CHAN(15, IIO_VOLTAGE), /* VDD5V */ 1417 MXS_ADC_CHAN(15, IIO_VOLTAGE, "VDD5V"),
1418};
1419
1420static const struct iio_chan_spec mx28_lradc_chan_spec[] = {
1421 MXS_ADC_CHAN(0, IIO_VOLTAGE, "LRADC0"),
1422 MXS_ADC_CHAN(1, IIO_VOLTAGE, "LRADC1"),
1423 MXS_ADC_CHAN(2, IIO_VOLTAGE, "LRADC2"),
1424 MXS_ADC_CHAN(3, IIO_VOLTAGE, "LRADC3"),
1425 MXS_ADC_CHAN(4, IIO_VOLTAGE, "LRADC4"),
1426 MXS_ADC_CHAN(5, IIO_VOLTAGE, "LRADC5"),
1427 MXS_ADC_CHAN(6, IIO_VOLTAGE, "LRADC6"),
1428 MXS_ADC_CHAN(7, IIO_VOLTAGE, "VBATT"),
1429 /* Combined Temperature sensors */
1430 {
1431 .type = IIO_TEMP,
1432 .indexed = 1,
1433 .scan_index = 8,
1434 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
1435 BIT(IIO_CHAN_INFO_OFFSET) |
1436 BIT(IIO_CHAN_INFO_SCALE),
1437 .channel = 8,
1438 .scan_type = {.sign = 'u', .realbits = 18, .storagebits = 32,},
1439 .datasheet_name = "TEMP_DIE",
1440 },
1441 /* Hidden channel to keep indexes */
1442 {
1443 .type = IIO_TEMP,
1444 .indexed = 1,
1445 .scan_index = -1,
1446 .channel = 9,
1447 },
1448 MXS_ADC_CHAN(10, IIO_VOLTAGE, "VDDIO"),
1449 MXS_ADC_CHAN(11, IIO_VOLTAGE, "VTH"),
1450 MXS_ADC_CHAN(12, IIO_VOLTAGE, "VDDA"),
1451 MXS_ADC_CHAN(13, IIO_VOLTAGE, "VDDD"),
1452 MXS_ADC_CHAN(14, IIO_VOLTAGE, "VBG"),
1453 MXS_ADC_CHAN(15, IIO_VOLTAGE, "VDD5V"),
1420}; 1454};
1421 1455
1422static int mxs_lradc_hw_init(struct mxs_lradc *lradc) 1456static int mxs_lradc_hw_init(struct mxs_lradc *lradc)
@@ -1612,10 +1646,16 @@ static int mxs_lradc_probe(struct platform_device *pdev)
1612 iio->dev.parent = &pdev->dev; 1646 iio->dev.parent = &pdev->dev;
1613 iio->info = &mxs_lradc_iio_info; 1647 iio->info = &mxs_lradc_iio_info;
1614 iio->modes = INDIO_DIRECT_MODE; 1648 iio->modes = INDIO_DIRECT_MODE;
1615 iio->channels = mxs_lradc_chan_spec;
1616 iio->num_channels = ARRAY_SIZE(mxs_lradc_chan_spec);
1617 iio->masklength = LRADC_MAX_TOTAL_CHANS; 1649 iio->masklength = LRADC_MAX_TOTAL_CHANS;
1618 1650
1651 if (lradc->soc == IMX23_LRADC) {
1652 iio->channels = mx23_lradc_chan_spec;
1653 iio->num_channels = ARRAY_SIZE(mx23_lradc_chan_spec);
1654 } else {
1655 iio->channels = mx28_lradc_chan_spec;
1656 iio->num_channels = ARRAY_SIZE(mx28_lradc_chan_spec);
1657 }
1658
1619 ret = iio_triggered_buffer_setup(iio, &iio_pollfunc_store_time, 1659 ret = iio_triggered_buffer_setup(iio, &iio_pollfunc_store_time,
1620 &mxs_lradc_trigger_handler, 1660 &mxs_lradc_trigger_handler,
1621 &mxs_lradc_buffer_ops); 1661 &mxs_lradc_buffer_ops);
@@ -1707,6 +1747,6 @@ static struct platform_driver mxs_lradc_driver = {
1707module_platform_driver(mxs_lradc_driver); 1747module_platform_driver(mxs_lradc_driver);
1708 1748
1709MODULE_AUTHOR("Marek Vasut <marex@denx.de>"); 1749MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
1710MODULE_DESCRIPTION("Freescale i.MX28 LRADC driver"); 1750MODULE_DESCRIPTION("Freescale MXS LRADC driver");
1711MODULE_LICENSE("GPL v2"); 1751MODULE_LICENSE("GPL v2");
1712MODULE_ALIAS("platform:" DRIVER_NAME); 1752MODULE_ALIAS("platform:" DRIVER_NAME);
diff --git a/drivers/staging/iio/addac/adt7316-i2c.c b/drivers/staging/iio/addac/adt7316-i2c.c
index 75ddd4f801a3..78fe0b557280 100644
--- a/drivers/staging/iio/addac/adt7316-i2c.c
+++ b/drivers/staging/iio/addac/adt7316-i2c.c
@@ -124,7 +124,6 @@ static struct i2c_driver adt7316_driver = {
124 .driver = { 124 .driver = {
125 .name = "adt7316", 125 .name = "adt7316",
126 .pm = ADT7316_PM_OPS, 126 .pm = ADT7316_PM_OPS,
127 .owner = THIS_MODULE,
128 }, 127 },
129 .probe = adt7316_i2c_probe, 128 .probe = adt7316_i2c_probe,
130 .id_table = adt7316_i2c_id, 129 .id_table = adt7316_i2c_id,
diff --git a/drivers/staging/iio/iio_dummy_evgen.c b/drivers/staging/iio/iio_dummy_evgen.c
index c54d5b5443a6..6d38854c38c8 100644
--- a/drivers/staging/iio/iio_dummy_evgen.c
+++ b/drivers/staging/iio/iio_dummy_evgen.c
@@ -214,6 +214,7 @@ static struct device iio_evgen_dev = {
214 .groups = iio_evgen_groups, 214 .groups = iio_evgen_groups,
215 .release = &iio_evgen_release, 215 .release = &iio_evgen_release,
216}; 216};
217
217static __init int iio_dummy_evgen_init(void) 218static __init int iio_dummy_evgen_init(void)
218{ 219{
219 int ret = iio_dummy_evgen_create(); 220 int ret = iio_dummy_evgen_create();
diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/staging/iio/iio_simple_dummy.c
index 1629a8a6bf26..381f90ff468a 100644
--- a/drivers/staging/iio/iio_simple_dummy.c
+++ b/drivers/staging/iio/iio_simple_dummy.c
@@ -611,7 +611,6 @@ static int iio_dummy_probe(int index)
611 */ 611 */
612 iio_dummy_devs[index] = indio_dev; 612 iio_dummy_devs[index] = indio_dev;
613 613
614
615 /* 614 /*
616 * Set the device name. 615 * Set the device name.
617 * 616 *
@@ -675,7 +674,6 @@ static void iio_dummy_remove(int index)
675 */ 674 */
676 struct iio_dev *indio_dev = iio_dummy_devs[index]; 675 struct iio_dev *indio_dev = iio_dummy_devs[index];
677 676
678
679 /* Unregister the device */ 677 /* Unregister the device */
680 iio_device_unregister(indio_dev); 678 iio_device_unregister(indio_dev);
681 679
diff --git a/drivers/staging/iio/iio_simple_dummy.h b/drivers/staging/iio/iio_simple_dummy.h
index e877a99540ab..8d00224e6fad 100644
--- a/drivers/staging/iio/iio_simple_dummy.h
+++ b/drivers/staging/iio/iio_simple_dummy.h
@@ -119,6 +119,7 @@ static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
119{ 119{
120 return 0; 120 return 0;
121}; 121};
122
122static inline 123static inline
123void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev) 124void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
124{}; 125{};
diff --git a/drivers/staging/iio/iio_simple_dummy_buffer.c b/drivers/staging/iio/iio_simple_dummy_buffer.c
index a651b8922d0a..00ed7745f3c5 100644
--- a/drivers/staging/iio/iio_simple_dummy_buffer.c
+++ b/drivers/staging/iio/iio_simple_dummy_buffer.c
@@ -32,6 +32,7 @@ static const s16 fakedata[] = {
32 [diffvoltage3m4] = -2, 32 [diffvoltage3m4] = -2,
33 [accelx] = 344, 33 [accelx] = 344,
34}; 34};
35
35/** 36/**
36 * iio_simple_dummy_trigger_h() - the trigger handler function 37 * iio_simple_dummy_trigger_h() - the trigger handler function
37 * @irq: the interrupt number 38 * @irq: the interrupt number
@@ -178,7 +179,6 @@ error_free_buffer:
178 iio_kfifo_free(indio_dev->buffer); 179 iio_kfifo_free(indio_dev->buffer);
179error_ret: 180error_ret:
180 return ret; 181 return ret;
181
182} 182}
183 183
184/** 184/**
diff --git a/drivers/staging/iio/iio_simple_dummy_events.c b/drivers/staging/iio/iio_simple_dummy_events.c
index ecc563cb6cb9..73108baf80ad 100644
--- a/drivers/staging/iio/iio_simple_dummy_events.c
+++ b/drivers/staging/iio/iio_simple_dummy_events.c
@@ -120,7 +120,7 @@ int iio_simple_dummy_read_event_value(struct iio_dev *indio_dev,
120 const struct iio_chan_spec *chan, 120 const struct iio_chan_spec *chan,
121 enum iio_event_type type, 121 enum iio_event_type type,
122 enum iio_event_direction dir, 122 enum iio_event_direction dir,
123 enum iio_event_info info, 123 enum iio_event_info info,
124 int *val, int *val2) 124 int *val, int *val2)
125{ 125{
126 struct iio_dummy_state *st = iio_priv(indio_dev); 126 struct iio_dummy_state *st = iio_priv(indio_dev);
@@ -143,7 +143,7 @@ int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
143 const struct iio_chan_spec *chan, 143 const struct iio_chan_spec *chan,
144 enum iio_event_type type, 144 enum iio_event_type type,
145 enum iio_event_direction dir, 145 enum iio_event_direction dir,
146 enum iio_event_info info, 146 enum iio_event_info info,
147 int val, int val2) 147 int val, int val2)
148{ 148{
149 struct iio_dummy_state *st = iio_priv(indio_dev); 149 struct iio_dummy_state *st = iio_priv(indio_dev);
diff --git a/drivers/staging/iio/light/isl29018.c b/drivers/staging/iio/light/isl29018.c
index e646c5d24004..019ba5245c23 100644
--- a/drivers/staging/iio/light/isl29018.c
+++ b/drivers/staging/iio/light/isl29018.c
@@ -838,7 +838,6 @@ static struct i2c_driver isl29018_driver = {
838 .name = "isl29018", 838 .name = "isl29018",
839 .acpi_match_table = ACPI_PTR(isl29018_acpi_match), 839 .acpi_match_table = ACPI_PTR(isl29018_acpi_match),
840 .pm = ISL29018_PM_OPS, 840 .pm = ISL29018_PM_OPS,
841 .owner = THIS_MODULE,
842 .of_match_table = isl29018_of_match, 841 .of_match_table = isl29018_of_match,
843 }, 842 },
844 .probe = isl29018_probe, 843 .probe = isl29018_probe,
diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c
index e5b2fdc2334b..cd6f2727aa58 100644
--- a/drivers/staging/iio/light/isl29028.c
+++ b/drivers/staging/iio/light/isl29028.c
@@ -547,7 +547,6 @@ static struct i2c_driver isl29028_driver = {
547 .class = I2C_CLASS_HWMON, 547 .class = I2C_CLASS_HWMON,
548 .driver = { 548 .driver = {
549 .name = "isl29028", 549 .name = "isl29028",
550 .owner = THIS_MODULE,
551 .of_match_table = isl29028_of_match, 550 .of_match_table = isl29028_of_match,
552 }, 551 },
553 .probe = isl29028_probe, 552 .probe = isl29028_probe,
diff --git a/drivers/staging/iio/meter/ade7854.h b/drivers/staging/iio/meter/ade7854.h
index 52ca5412a18d..52f4195cf6f4 100644
--- a/drivers/staging/iio/meter/ade7854.h
+++ b/drivers/staging/iio/meter/ade7854.h
@@ -168,7 +168,7 @@ struct ade7854_state {
168 168
169}; 169};
170 170
171extern int ade7854_probe(struct iio_dev *indio_dev, struct device *dev); 171int ade7854_probe(struct iio_dev *indio_dev, struct device *dev);
172extern int ade7854_remove(struct iio_dev *indio_dev); 172int ade7854_remove(struct iio_dev *indio_dev);
173 173
174#endif 174#endif
diff --git a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c
index 3c1c8c6c4a6c..9fe48ef11473 100644
--- a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c
+++ b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c
@@ -79,7 +79,8 @@ static int iio_bfin_tmr_set_state(struct iio_trigger *trig, bool state)
79} 79}
80 80
81static ssize_t iio_bfin_tmr_frequency_store(struct device *dev, 81static ssize_t iio_bfin_tmr_frequency_store(struct device *dev,
82 struct device_attribute *attr, const char *buf, size_t count) 82 struct device_attribute *attr,
83 const char *buf, size_t count)
83{ 84{
84 struct iio_trigger *trig = to_iio_trigger(dev); 85 struct iio_trigger *trig = to_iio_trigger(dev);
85 struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig); 86 struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig);
@@ -116,8 +117,8 @@ static ssize_t iio_bfin_tmr_frequency_store(struct device *dev,
116} 117}
117 118
118static ssize_t iio_bfin_tmr_frequency_show(struct device *dev, 119static ssize_t iio_bfin_tmr_frequency_show(struct device *dev,
119 struct device_attribute *attr, 120 struct device_attribute *attr,
120 char *buf) 121 char *buf)
121{ 122{
122 struct iio_trigger *trig = to_iio_trigger(dev); 123 struct iio_trigger *trig = to_iio_trigger(dev);
123 struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig); 124 struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig);
diff --git a/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c b/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c
index 0c1976ddee74..2db885750fb8 100644
--- a/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c
+++ b/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c
@@ -37,7 +37,7 @@ static int iio_trig_periodic_rtc_set_state(struct iio_trigger *trig, bool state)
37 if (trig_info->frequency == 0 && state) 37 if (trig_info->frequency == 0 && state)
38 return -EINVAL; 38 return -EINVAL;
39 dev_dbg(&trig_info->rtc->dev, "trigger frequency is %u\n", 39 dev_dbg(&trig_info->rtc->dev, "trigger frequency is %u\n",
40 trig_info->frequency); 40 trig_info->frequency);
41 ret = rtc_irq_set_state(trig_info->rtc, &trig_info->task, state); 41 ret = rtc_irq_set_state(trig_info->rtc, &trig_info->task, state);
42 if (ret == 0) 42 if (ret == 0)
43 trig_info->state = state; 43 trig_info->state = state;
@@ -74,8 +74,9 @@ static ssize_t iio_trig_periodic_write_freq(struct device *dev,
74 if (ret == 0 && trig_info->state && trig_info->frequency == 0) 74 if (ret == 0 && trig_info->state && trig_info->frequency == 0)
75 ret = rtc_irq_set_state(trig_info->rtc, 75 ret = rtc_irq_set_state(trig_info->rtc,
76 &trig_info->task, 1); 76 &trig_info->task, 1);
77 } else 77 } else {
78 ret = rtc_irq_set_state(trig_info->rtc, &trig_info->task, 0); 78 ret = rtc_irq_set_state(trig_info->rtc, &trig_info->task, 0);
79 }
79 if (ret) 80 if (ret)
80 goto error_ret; 81 goto error_ret;
81 82
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs.h b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
index 5dd9cdfae30c..01961d9e6c36 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
@@ -134,7 +134,7 @@ void cfs_get_random_bytes(void *buf, int size);
134/* container_of depends on "likely" which is defined in libcfs_private.h */ 134/* container_of depends on "likely" which is defined in libcfs_private.h */
135static inline void *__container_of(void *ptr, unsigned long shift) 135static inline void *__container_of(void *ptr, unsigned long shift)
136{ 136{
137 if (unlikely(IS_ERR(ptr) || ptr == NULL)) 137 if (IS_ERR_OR_NULL(ptr))
138 return ptr; 138 return ptr;
139 return (char *)ptr - shift; 139 return (char *)ptr - shift;
140} 140}
@@ -148,4 +148,17 @@ void *libcfs_kvzalloc(size_t size, gfp_t flags);
148void *libcfs_kvzalloc_cpt(struct cfs_cpt_table *cptab, int cpt, size_t size, 148void *libcfs_kvzalloc_cpt(struct cfs_cpt_table *cptab, int cpt, size_t size,
149 gfp_t flags); 149 gfp_t flags);
150 150
151extern struct miscdevice libcfs_dev;
152/**
153 * The path of debug log dump upcall script.
154 */
155extern char lnet_upcall[1024];
156extern char lnet_debug_log_upcall[1024];
157
158extern void libcfs_init_nidstrings(void);
159
160extern struct cfs_psdev_ops libcfs_psdev_ops;
161
162extern struct cfs_wi_sched *cfs_sched_rehash;
163
151#endif /* _LIBCFS_H */ 164#endif /* _LIBCFS_H */
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h
index 8251ac932e37..a3aa644154e2 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h
@@ -50,7 +50,6 @@ extern unsigned int libcfs_stack;
50extern unsigned int libcfs_debug; 50extern unsigned int libcfs_debug;
51extern unsigned int libcfs_printk; 51extern unsigned int libcfs_printk;
52extern unsigned int libcfs_console_ratelimit; 52extern unsigned int libcfs_console_ratelimit;
53extern unsigned int libcfs_watchdog_ratelimit;
54extern unsigned int libcfs_console_max_delay; 53extern unsigned int libcfs_console_max_delay;
55extern unsigned int libcfs_console_min_delay; 54extern unsigned int libcfs_console_min_delay;
56extern unsigned int libcfs_console_backoff; 55extern unsigned int libcfs_console_backoff;
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h
index eea55d94e6be..aa69c6a33d19 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h
@@ -79,14 +79,16 @@ static inline int cfs_fail_check_set(__u32 id, __u32 value,
79{ 79{
80 int ret = 0; 80 int ret = 0;
81 81
82 if (unlikely(CFS_FAIL_PRECHECK(id) && 82 if (unlikely(CFS_FAIL_PRECHECK(id))) {
83 (ret = __cfs_fail_check_set(id, value, set)))) { 83 ret = __cfs_fail_check_set(id, value, set);
84 if (quiet) { 84 if (ret) {
85 CDEBUG(D_INFO, "*** cfs_fail_loc=%x, val=%u***\n", 85 if (quiet) {
86 id, value); 86 CDEBUG(D_INFO, "*** cfs_fail_loc=%x, val=%u***\n",
87 } else { 87 id, value);
88 LCONSOLE_INFO("*** cfs_fail_loc=%x, val=%u***\n", 88 } else {
89 id, value); 89 LCONSOLE_INFO("*** cfs_fail_loc=%x, val=%u***\n",
90 id, value);
91 }
90 } 92 }
91 } 93 }
92 94
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
index ed37d26eb20d..9544860e3292 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
@@ -87,24 +87,6 @@ do { \
87 lbug_with_loc(&msgdata); \ 87 lbug_with_loc(&msgdata); \
88} while (0) 88} while (0)
89 89
90extern atomic_t libcfs_kmemory;
91/*
92 * Memory
93 */
94
95# define libcfs_kmem_inc(ptr, size) \
96do { \
97 atomic_add(size, &libcfs_kmemory); \
98} while (0)
99
100# define libcfs_kmem_dec(ptr, size) \
101do { \
102 atomic_sub(size, &libcfs_kmemory); \
103} while (0)
104
105# define libcfs_kmem_read() \
106 atomic_read(&libcfs_kmemory)
107
108#ifndef LIBCFS_VMALLOC_SIZE 90#ifndef LIBCFS_VMALLOC_SIZE
109#define LIBCFS_VMALLOC_SIZE (2 << PAGE_CACHE_SHIFT) /* 2 pages */ 91#define LIBCFS_VMALLOC_SIZE (2 << PAGE_CACHE_SHIFT) /* 2 pages */
110#endif 92#endif
@@ -121,14 +103,9 @@ do { \
121 if (unlikely((ptr) == NULL)) { \ 103 if (unlikely((ptr) == NULL)) { \
122 CERROR("LNET: out of memory at %s:%d (tried to alloc '" \ 104 CERROR("LNET: out of memory at %s:%d (tried to alloc '" \
123 #ptr "' = %d)\n", __FILE__, __LINE__, (int)(size)); \ 105 #ptr "' = %d)\n", __FILE__, __LINE__, (int)(size)); \
124 CERROR("LNET: %d total bytes allocated by lnet\n", \
125 libcfs_kmem_read()); \
126 } else { \ 106 } else { \
127 memset((ptr), 0, (size)); \ 107 memset((ptr), 0, (size)); \
128 libcfs_kmem_inc((ptr), (size)); \ 108 } \
129 CDEBUG(D_MALLOC, "alloc '" #ptr "': %d at %p (tot %d).\n", \
130 (int)(size), (ptr), libcfs_kmem_read()); \
131 } \
132} while (0) 109} while (0)
133 110
134/** 111/**
@@ -180,9 +157,6 @@ do { \
180 "%s:%d\n", s, __FILE__, __LINE__); \ 157 "%s:%d\n", s, __FILE__, __LINE__); \
181 break; \ 158 break; \
182 } \ 159 } \
183 libcfs_kmem_dec((ptr), s); \
184 CDEBUG(D_MALLOC, "kfreed '" #ptr "': %d at %p (tot %d).\n", \
185 s, (ptr), libcfs_kmem_read()); \
186 if (unlikely(s > LIBCFS_VMALLOC_SIZE)) \ 160 if (unlikely(s > LIBCFS_VMALLOC_SIZE)) \
187 vfree(ptr); \ 161 vfree(ptr); \
188 else \ 162 else \
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
index 509dc1e5c3b1..478e9582ff54 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
@@ -102,6 +102,4 @@ int cfs_ip_addr_parse(char *str, int len, struct list_head *list);
102int cfs_ip_addr_match(__u32 addr, struct list_head *list); 102int cfs_ip_addr_match(__u32 addr, struct list_head *list);
103void cfs_ip_addr_free(struct list_head *list); 103void cfs_ip_addr_free(struct list_head *list);
104 104
105#define strtoul(str, endp, base) simple_strtoul(str, endp, base)
106
107#endif 105#endif
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
index 4eb24a11b02a..c29d2ced258c 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
@@ -1390,7 +1390,7 @@ static int kiblnd_create_fmr_pool(kib_fmr_poolset_t *fps,
1390 .max_pages_per_fmr = LNET_MAX_PAYLOAD/PAGE_SIZE, 1390 .max_pages_per_fmr = LNET_MAX_PAYLOAD/PAGE_SIZE,
1391 .page_shift = PAGE_SHIFT, 1391 .page_shift = PAGE_SHIFT,
1392 .access = (IB_ACCESS_LOCAL_WRITE | 1392 .access = (IB_ACCESS_LOCAL_WRITE |
1393 IB_ACCESS_REMOTE_WRITE), 1393 IB_ACCESS_REMOTE_WRITE),
1394 .pool_size = fps->fps_pool_size, 1394 .pool_size = fps->fps_pool_size,
1395 .dirty_watermark = fps->fps_flush_trigger, 1395 .dirty_watermark = fps->fps_flush_trigger,
1396 .flush_function = NULL, 1396 .flush_function = NULL,
@@ -1789,140 +1789,6 @@ struct list_head *kiblnd_pool_alloc_node(kib_poolset_t *ps)
1789 goto again; 1789 goto again;
1790} 1790}
1791 1791
1792void kiblnd_pmr_pool_unmap(kib_phys_mr_t *pmr)
1793{
1794 kib_pmr_pool_t *ppo = pmr->pmr_pool;
1795 struct ib_mr *mr = pmr->pmr_mr;
1796
1797 pmr->pmr_mr = NULL;
1798 kiblnd_pool_free_node(&ppo->ppo_pool, &pmr->pmr_list);
1799 if (mr != NULL)
1800 ib_dereg_mr(mr);
1801}
1802
1803int kiblnd_pmr_pool_map(kib_pmr_poolset_t *pps, kib_hca_dev_t *hdev,
1804 kib_rdma_desc_t *rd, __u64 *iova, kib_phys_mr_t **pp_pmr)
1805{
1806 kib_phys_mr_t *pmr;
1807 struct list_head *node;
1808 int rc;
1809 int i;
1810
1811 node = kiblnd_pool_alloc_node(&pps->pps_poolset);
1812 if (node == NULL) {
1813 CERROR("Failed to allocate PMR descriptor\n");
1814 return -ENOMEM;
1815 }
1816
1817 pmr = container_of(node, kib_phys_mr_t, pmr_list);
1818 if (pmr->pmr_pool->ppo_hdev != hdev) {
1819 kiblnd_pool_free_node(&pmr->pmr_pool->ppo_pool, node);
1820 return -EAGAIN;
1821 }
1822
1823 for (i = 0; i < rd->rd_nfrags; i++) {
1824 pmr->pmr_ipb[i].addr = rd->rd_frags[i].rf_addr;
1825 pmr->pmr_ipb[i].size = rd->rd_frags[i].rf_nob;
1826 }
1827
1828 pmr->pmr_mr = ib_reg_phys_mr(hdev->ibh_pd,
1829 pmr->pmr_ipb, rd->rd_nfrags,
1830 IB_ACCESS_LOCAL_WRITE |
1831 IB_ACCESS_REMOTE_WRITE,
1832 iova);
1833 if (!IS_ERR(pmr->pmr_mr)) {
1834 pmr->pmr_iova = *iova;
1835 *pp_pmr = pmr;
1836 return 0;
1837 }
1838
1839 rc = PTR_ERR(pmr->pmr_mr);
1840 CERROR("Failed ib_reg_phys_mr: %d\n", rc);
1841
1842 pmr->pmr_mr = NULL;
1843 kiblnd_pool_free_node(&pmr->pmr_pool->ppo_pool, node);
1844
1845 return rc;
1846}
1847
1848static void kiblnd_destroy_pmr_pool(kib_pool_t *pool)
1849{
1850 kib_pmr_pool_t *ppo = container_of(pool, kib_pmr_pool_t, ppo_pool);
1851 kib_phys_mr_t *pmr;
1852 kib_phys_mr_t *tmp;
1853
1854 LASSERT(pool->po_allocated == 0);
1855
1856 list_for_each_entry_safe(pmr, tmp, &pool->po_free_list, pmr_list) {
1857 LASSERT(pmr->pmr_mr == NULL);
1858 list_del(&pmr->pmr_list);
1859
1860 if (pmr->pmr_ipb != NULL) {
1861 LIBCFS_FREE(pmr->pmr_ipb,
1862 IBLND_MAX_RDMA_FRAGS *
1863 sizeof(struct ib_phys_buf));
1864 }
1865
1866 LIBCFS_FREE(pmr, sizeof(kib_phys_mr_t));
1867 }
1868
1869 kiblnd_fini_pool(pool);
1870 if (ppo->ppo_hdev != NULL)
1871 kiblnd_hdev_decref(ppo->ppo_hdev);
1872
1873 LIBCFS_FREE(ppo, sizeof(kib_pmr_pool_t));
1874}
1875
1876static inline int kiblnd_pmr_pool_size(int ncpts)
1877{
1878 int size = *kiblnd_tunables.kib_pmr_pool_size / ncpts;
1879
1880 return max(IBLND_PMR_POOL, size);
1881}
1882
1883static int kiblnd_create_pmr_pool(kib_poolset_t *ps, int size,
1884 kib_pool_t **pp_po)
1885{
1886 struct kib_pmr_pool *ppo;
1887 struct kib_pool *pool;
1888 kib_phys_mr_t *pmr;
1889 int i;
1890
1891 LIBCFS_CPT_ALLOC(ppo, lnet_cpt_table(),
1892 ps->ps_cpt, sizeof(kib_pmr_pool_t));
1893 if (ppo == NULL) {
1894 CERROR("Failed to allocate PMR pool\n");
1895 return -ENOMEM;
1896 }
1897
1898 pool = &ppo->ppo_pool;
1899 kiblnd_init_pool(ps, pool, size);
1900
1901 for (i = 0; i < size; i++) {
1902 LIBCFS_CPT_ALLOC(pmr, lnet_cpt_table(),
1903 ps->ps_cpt, sizeof(kib_phys_mr_t));
1904 if (pmr == NULL)
1905 break;
1906
1907 pmr->pmr_pool = ppo;
1908 LIBCFS_CPT_ALLOC(pmr->pmr_ipb, lnet_cpt_table(), ps->ps_cpt,
1909 IBLND_MAX_RDMA_FRAGS * sizeof(*pmr->pmr_ipb));
1910 if (pmr->pmr_ipb == NULL)
1911 break;
1912
1913 list_add(&pmr->pmr_list, &pool->po_free_list);
1914 }
1915
1916 if (i < size) {
1917 ps->ps_pool_destroy(pool);
1918 return -ENOMEM;
1919 }
1920
1921 ppo->ppo_hdev = kiblnd_current_hdev(ps->ps_net->ibn_dev);
1922 *pp_po = pool;
1923 return 0;
1924}
1925
1926static void kiblnd_destroy_tx_pool(kib_pool_t *pool) 1792static void kiblnd_destroy_tx_pool(kib_pool_t *pool)
1927{ 1793{
1928 kib_tx_pool_t *tpo = container_of(pool, kib_tx_pool_t, tpo_pool); 1794 kib_tx_pool_t *tpo = container_of(pool, kib_tx_pool_t, tpo_pool);
@@ -2078,7 +1944,6 @@ static void kiblnd_net_fini_pools(kib_net_t *net)
2078 cfs_cpt_for_each(i, lnet_cpt_table()) { 1944 cfs_cpt_for_each(i, lnet_cpt_table()) {
2079 kib_tx_poolset_t *tps; 1945 kib_tx_poolset_t *tps;
2080 kib_fmr_poolset_t *fps; 1946 kib_fmr_poolset_t *fps;
2081 kib_pmr_poolset_t *pps;
2082 1947
2083 if (net->ibn_tx_ps != NULL) { 1948 if (net->ibn_tx_ps != NULL) {
2084 tps = net->ibn_tx_ps[i]; 1949 tps = net->ibn_tx_ps[i];
@@ -2089,11 +1954,6 @@ static void kiblnd_net_fini_pools(kib_net_t *net)
2089 fps = net->ibn_fmr_ps[i]; 1954 fps = net->ibn_fmr_ps[i];
2090 kiblnd_fini_fmr_poolset(fps); 1955 kiblnd_fini_fmr_poolset(fps);
2091 } 1956 }
2092
2093 if (net->ibn_pmr_ps != NULL) {
2094 pps = net->ibn_pmr_ps[i];
2095 kiblnd_fini_poolset(&pps->pps_poolset);
2096 }
2097 } 1957 }
2098 1958
2099 if (net->ibn_tx_ps != NULL) { 1959 if (net->ibn_tx_ps != NULL) {
@@ -2105,18 +1965,13 @@ static void kiblnd_net_fini_pools(kib_net_t *net)
2105 cfs_percpt_free(net->ibn_fmr_ps); 1965 cfs_percpt_free(net->ibn_fmr_ps);
2106 net->ibn_fmr_ps = NULL; 1966 net->ibn_fmr_ps = NULL;
2107 } 1967 }
2108
2109 if (net->ibn_pmr_ps != NULL) {
2110 cfs_percpt_free(net->ibn_pmr_ps);
2111 net->ibn_pmr_ps = NULL;
2112 }
2113} 1968}
2114 1969
2115static int kiblnd_net_init_pools(kib_net_t *net, __u32 *cpts, int ncpts) 1970static int kiblnd_net_init_pools(kib_net_t *net, __u32 *cpts, int ncpts)
2116{ 1971{
2117 unsigned long flags; 1972 unsigned long flags;
2118 int cpt; 1973 int cpt;
2119 int rc; 1974 int rc = 0;
2120 int i; 1975 int i;
2121 1976
2122 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags); 1977 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
@@ -2137,12 +1992,16 @@ static int kiblnd_net_init_pools(kib_net_t *net, __u32 *cpts, int ncpts)
2137 goto failed; 1992 goto failed;
2138 } 1993 }
2139 1994
2140 /* TX pool must be created later than FMR/PMR, see LU-2268 1995 /*
2141 * for details */ 1996 * TX pool must be created later than FMR, see LU-2268
1997 * for details
1998 */
2142 LASSERT(net->ibn_tx_ps == NULL); 1999 LASSERT(net->ibn_tx_ps == NULL);
2143 2000
2144 /* premapping can fail if ibd_nmr > 1, so we always create 2001 /*
2145 * FMR/PMR pool and map-on-demand if premapping failed */ 2002 * premapping can fail if ibd_nmr > 1, so we always create
2003 * FMR pool and map-on-demand if premapping failed
2004 */
2146 2005
2147 net->ibn_fmr_ps = cfs_percpt_alloc(lnet_cpt_table(), 2006 net->ibn_fmr_ps = cfs_percpt_alloc(lnet_cpt_table(),
2148 sizeof(kib_fmr_poolset_t)); 2007 sizeof(kib_fmr_poolset_t));
@@ -2158,7 +2017,7 @@ static int kiblnd_net_init_pools(kib_net_t *net, __u32 *cpts, int ncpts)
2158 kiblnd_fmr_pool_size(ncpts), 2017 kiblnd_fmr_pool_size(ncpts),
2159 kiblnd_fmr_flush_trigger(ncpts)); 2018 kiblnd_fmr_flush_trigger(ncpts));
2160 if (rc == -ENOSYS && i == 0) /* no FMR */ 2019 if (rc == -ENOSYS && i == 0) /* no FMR */
2161 break; /* create PMR pool */ 2020 break;
2162 2021
2163 if (rc != 0) { /* a real error */ 2022 if (rc != 0) { /* a real error */
2164 CERROR("Can't initialize FMR pool for CPT %d: %d\n", 2023 CERROR("Can't initialize FMR pool for CPT %d: %d\n",
@@ -2175,38 +2034,8 @@ static int kiblnd_net_init_pools(kib_net_t *net, __u32 *cpts, int ncpts)
2175 cfs_percpt_free(net->ibn_fmr_ps); 2034 cfs_percpt_free(net->ibn_fmr_ps);
2176 net->ibn_fmr_ps = NULL; 2035 net->ibn_fmr_ps = NULL;
2177 2036
2178 CWARN("Device does not support FMR, failing back to PMR\n"); 2037 CWARN("Device does not support FMR\n");
2179
2180 if (*kiblnd_tunables.kib_pmr_pool_size <
2181 *kiblnd_tunables.kib_ntx / 4) {
2182 CERROR("Can't set pmr pool size (%d) < ntx / 4(%d)\n",
2183 *kiblnd_tunables.kib_pmr_pool_size,
2184 *kiblnd_tunables.kib_ntx / 4);
2185 rc = -EINVAL;
2186 goto failed;
2187 }
2188
2189 net->ibn_pmr_ps = cfs_percpt_alloc(lnet_cpt_table(),
2190 sizeof(kib_pmr_poolset_t));
2191 if (net->ibn_pmr_ps == NULL) {
2192 CERROR("Failed to allocate PMR pool array\n");
2193 rc = -ENOMEM;
2194 goto failed;
2195 }
2196
2197 for (i = 0; i < ncpts; i++) {
2198 cpt = (cpts == NULL) ? i : cpts[i];
2199 rc = kiblnd_init_poolset(&net->ibn_pmr_ps[cpt]->pps_poolset,
2200 cpt, net, "PMR",
2201 kiblnd_pmr_pool_size(ncpts),
2202 kiblnd_create_pmr_pool,
2203 kiblnd_destroy_pmr_pool, NULL, NULL);
2204 if (rc != 0) {
2205 CERROR("Can't initialize PMR pool for CPT %d: %d\n",
2206 cpt, rc);
2207 goto failed; 2038 goto failed;
2208 }
2209 }
2210 2039
2211 create_tx_pool: 2040 create_tx_pool:
2212 net->ibn_tx_ps = cfs_percpt_alloc(lnet_cpt_table(), 2041 net->ibn_tx_ps = cfs_percpt_alloc(lnet_cpt_table(),
@@ -2318,17 +2147,13 @@ void kiblnd_hdev_destroy(kib_hca_dev_t *hdev)
2318static int kiblnd_hdev_setup_mrs(kib_hca_dev_t *hdev) 2147static int kiblnd_hdev_setup_mrs(kib_hca_dev_t *hdev)
2319{ 2148{
2320 struct ib_mr *mr; 2149 struct ib_mr *mr;
2321 int i;
2322 int rc; 2150 int rc;
2323 __u64 mm_size;
2324 __u64 mr_size;
2325 int acflags = IB_ACCESS_LOCAL_WRITE | IB_ACCESS_REMOTE_WRITE; 2151 int acflags = IB_ACCESS_LOCAL_WRITE | IB_ACCESS_REMOTE_WRITE;
2326 2152
2327 rc = kiblnd_hdev_get_attr(hdev); 2153 rc = kiblnd_hdev_get_attr(hdev);
2328 if (rc != 0) 2154 if (rc != 0)
2329 return rc; 2155 return rc;
2330 2156
2331 if (hdev->ibh_mr_shift == 64) {
2332 LIBCFS_ALLOC(hdev->ibh_mrs, 1 * sizeof(*hdev->ibh_mrs)); 2157 LIBCFS_ALLOC(hdev->ibh_mrs, 1 * sizeof(*hdev->ibh_mrs));
2333 if (hdev->ibh_mrs == NULL) { 2158 if (hdev->ibh_mrs == NULL) {
2334 CERROR("Failed to allocate MRs table\n"); 2159 CERROR("Failed to allocate MRs table\n");
@@ -2347,53 +2172,6 @@ static int kiblnd_hdev_setup_mrs(kib_hca_dev_t *hdev)
2347 2172
2348 hdev->ibh_mrs[0] = mr; 2173 hdev->ibh_mrs[0] = mr;
2349 2174
2350 goto out;
2351 }
2352
2353 mr_size = 1ULL << hdev->ibh_mr_shift;
2354 mm_size = (unsigned long)high_memory - PAGE_OFFSET;
2355
2356 hdev->ibh_nmrs = (int)((mm_size + mr_size - 1) >> hdev->ibh_mr_shift);
2357
2358 if (hdev->ibh_mr_shift < 32 || hdev->ibh_nmrs > 1024) {
2359 /* it's 4T..., assume we will re-code at that time */
2360 CERROR("Can't support memory size: x%#llx with MR size: x%#llx\n",
2361 mm_size, mr_size);
2362 return -EINVAL;
2363 }
2364
2365 /* create an array of MRs to cover all memory */
2366 LIBCFS_ALLOC(hdev->ibh_mrs, sizeof(*hdev->ibh_mrs) * hdev->ibh_nmrs);
2367 if (hdev->ibh_mrs == NULL) {
2368 CERROR("Failed to allocate MRs' table\n");
2369 return -ENOMEM;
2370 }
2371
2372 for (i = 0; i < hdev->ibh_nmrs; i++) {
2373 struct ib_phys_buf ipb;
2374 __u64 iova;
2375
2376 ipb.size = hdev->ibh_mr_size;
2377 ipb.addr = i * mr_size;
2378 iova = ipb.addr;
2379
2380 mr = ib_reg_phys_mr(hdev->ibh_pd, &ipb, 1, acflags, &iova);
2381 if (IS_ERR(mr)) {
2382 CERROR("Failed ib_reg_phys_mr addr %#llx size %#llx : %ld\n",
2383 ipb.addr, ipb.size, PTR_ERR(mr));
2384 kiblnd_hdev_cleanup_mrs(hdev);
2385 return PTR_ERR(mr);
2386 }
2387
2388 LASSERT(iova == ipb.addr);
2389
2390 hdev->ibh_mrs[i] = mr;
2391 }
2392
2393out:
2394 if (hdev->ibh_mr_size != ~0ULL || hdev->ibh_nmrs != 1)
2395 LCONSOLE_INFO("Register global MR array, MR size: %#llx, array size: %d\n",
2396 hdev->ibh_mr_size, hdev->ibh_nmrs);
2397 return 0; 2175 return 0;
2398} 2176}
2399 2177
@@ -2564,14 +2342,9 @@ int kiblnd_dev_failover(kib_dev_t *dev)
2564 kiblnd_fail_poolset(&net->ibn_tx_ps[i]->tps_poolset, 2342 kiblnd_fail_poolset(&net->ibn_tx_ps[i]->tps_poolset,
2565 &zombie_tpo); 2343 &zombie_tpo);
2566 2344
2567 if (net->ibn_fmr_ps != NULL) { 2345 if (net->ibn_fmr_ps)
2568 kiblnd_fail_fmr_poolset(net->ibn_fmr_ps[i], 2346 kiblnd_fail_fmr_poolset(net->ibn_fmr_ps[i],
2569 &zombie_fpo); 2347 &zombie_fpo);
2570
2571 } else if (net->ibn_pmr_ps != NULL) {
2572 kiblnd_fail_poolset(&net->ibn_pmr_ps[i]->
2573 pps_poolset, &zombie_ppo);
2574 }
2575 } 2348 }
2576 } 2349 }
2577 2350
@@ -2667,9 +2440,6 @@ static void kiblnd_base_shutdown(void)
2667 2440
2668 LASSERT(list_empty(&kiblnd_data.kib_devs)); 2441 LASSERT(list_empty(&kiblnd_data.kib_devs));
2669 2442
2670 CDEBUG(D_MALLOC, "before LND base cleanup: kmem %d\n",
2671 atomic_read(&libcfs_kmemory));
2672
2673 switch (kiblnd_data.kib_init) { 2443 switch (kiblnd_data.kib_init) {
2674 default: 2444 default:
2675 LBUG(); 2445 LBUG();
@@ -2720,9 +2490,6 @@ static void kiblnd_base_shutdown(void)
2720 if (kiblnd_data.kib_scheds != NULL) 2490 if (kiblnd_data.kib_scheds != NULL)
2721 cfs_percpt_free(kiblnd_data.kib_scheds); 2491 cfs_percpt_free(kiblnd_data.kib_scheds);
2722 2492
2723 CDEBUG(D_MALLOC, "after LND base cleanup: kmem %d\n",
2724 atomic_read(&libcfs_kmemory));
2725
2726 kiblnd_data.kib_init = IBLND_INIT_NOTHING; 2493 kiblnd_data.kib_init = IBLND_INIT_NOTHING;
2727 module_put(THIS_MODULE); 2494 module_put(THIS_MODULE);
2728} 2495}
@@ -2739,9 +2506,6 @@ void kiblnd_shutdown(lnet_ni_t *ni)
2739 if (net == NULL) 2506 if (net == NULL)
2740 goto out; 2507 goto out;
2741 2508
2742 CDEBUG(D_MALLOC, "before LND net cleanup: kmem %d\n",
2743 atomic_read(&libcfs_kmemory));
2744
2745 write_lock_irqsave(g_lock, flags); 2509 write_lock_irqsave(g_lock, flags);
2746 net->ibn_shutdown = 1; 2510 net->ibn_shutdown = 1;
2747 write_unlock_irqrestore(g_lock, flags); 2511 write_unlock_irqrestore(g_lock, flags);
@@ -2786,9 +2550,6 @@ void kiblnd_shutdown(lnet_ni_t *ni)
2786 break; 2550 break;
2787 } 2551 }
2788 2552
2789 CDEBUG(D_MALLOC, "after LND net cleanup: kmem %d\n",
2790 atomic_read(&libcfs_kmemory));
2791
2792 net->ibn_init = IBLND_INIT_NOTHING; 2553 net->ibn_init = IBLND_INIT_NOTHING;
2793 ni->ni_data = NULL; 2554 ni->ni_data = NULL;
2794 2555
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
index f5d1d9f8f1ed..f4b6c33ac318 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
@@ -48,7 +48,7 @@
48#include <linux/uio.h> 48#include <linux/uio.h>
49#include <linux/uaccess.h> 49#include <linux/uaccess.h>
50 50
51#include <asm/io.h> 51#include <linux/io.h>
52 52
53#include <linux/fs.h> 53#include <linux/fs.h>
54#include <linux/file.h> 54#include <linux/file.h>
@@ -104,7 +104,6 @@ typedef struct {
104 int *kib_map_on_demand; /* map-on-demand if RD has more 104 int *kib_map_on_demand; /* map-on-demand if RD has more
105 * fragments than this value, 0 105 * fragments than this value, 0
106 * disable map-on-demand */ 106 * disable map-on-demand */
107 int *kib_pmr_pool_size; /* # physical MR in pool */
108 int *kib_fmr_pool_size; /* # FMRs in pool */ 107 int *kib_fmr_pool_size; /* # FMRs in pool */
109 int *kib_fmr_flush_trigger; /* When to trigger FMR flush */ 108 int *kib_fmr_flush_trigger; /* When to trigger FMR flush */
110 int *kib_fmr_cache; /* enable FMR pool cache? */ 109 int *kib_fmr_cache; /* enable FMR pool cache? */
@@ -120,7 +119,7 @@ extern kib_tunables_t kiblnd_tunables;
120#define IBLND_CREDIT_HIGHWATER_V1 7 /* V1 only : when eagerly to return credits */ 119#define IBLND_CREDIT_HIGHWATER_V1 7 /* V1 only : when eagerly to return credits */
121 120
122#define IBLND_CREDITS_DEFAULT 8 /* default # of peer credits */ 121#define IBLND_CREDITS_DEFAULT 8 /* default # of peer credits */
123#define IBLND_CREDITS_MAX ((typeof(((kib_msg_t*) 0)->ibm_credits)) - 1) /* Max # of peer credits */ 122#define IBLND_CREDITS_MAX ((typeof(((kib_msg_t *) 0)->ibm_credits)) - 1) /* Max # of peer credits */
124 123
125#define IBLND_MSG_QUEUE_SIZE(v) ((v) == IBLND_MSG_VERSION_1 ? \ 124#define IBLND_MSG_QUEUE_SIZE(v) ((v) == IBLND_MSG_VERSION_1 ? \
126 IBLND_MSG_QUEUE_SIZE_V1 : \ 125 IBLND_MSG_QUEUE_SIZE_V1 : \
@@ -163,7 +162,6 @@ kiblnd_concurrent_sends_v1(void)
163/* Pools (shared by connections on each CPT) */ 162/* Pools (shared by connections on each CPT) */
164/* These pools can grow at runtime, so don't need give a very large value */ 163/* These pools can grow at runtime, so don't need give a very large value */
165#define IBLND_TX_POOL 256 164#define IBLND_TX_POOL 256
166#define IBLND_PMR_POOL 256
167#define IBLND_FMR_POOL 256 165#define IBLND_FMR_POOL 256
168#define IBLND_FMR_POOL_FLUSH 192 166#define IBLND_FMR_POOL_FLUSH 192
169 167
@@ -232,17 +230,6 @@ typedef struct {
232 struct page *ibp_pages[0]; /* page array */ 230 struct page *ibp_pages[0]; /* page array */
233} kib_pages_t; 231} kib_pages_t;
234 232
235struct kib_pmr_pool;
236
237typedef struct {
238 struct list_head pmr_list; /* chain node */
239 struct ib_phys_buf *pmr_ipb; /* physical buffer */
240 struct ib_mr *pmr_mr; /* IB MR */
241 struct kib_pmr_pool *pmr_pool; /* owner of this MR */
242 __u64 pmr_iova; /* Virtual I/O address */
243 int pmr_refcount; /* reference count */
244} kib_phys_mr_t;
245
246struct kib_pool; 233struct kib_pool;
247struct kib_poolset; 234struct kib_poolset;
248 235
@@ -299,15 +286,6 @@ typedef struct {
299} kib_tx_pool_t; 286} kib_tx_pool_t;
300 287
301typedef struct { 288typedef struct {
302 kib_poolset_t pps_poolset; /* pool-set */
303} kib_pmr_poolset_t;
304
305typedef struct kib_pmr_pool {
306 struct kib_hca_dev *ppo_hdev; /* device for this pool */
307 kib_pool_t ppo_pool; /* pool */
308} kib_pmr_pool_t;
309
310typedef struct {
311 spinlock_t fps_lock; /* serialize */ 289 spinlock_t fps_lock; /* serialize */
312 struct kib_net *fps_net; /* IB network */ 290 struct kib_net *fps_net; /* IB network */
313 struct list_head fps_pool_list; /* FMR pool list */ 291 struct list_head fps_pool_list; /* FMR pool list */
@@ -347,7 +325,6 @@ typedef struct kib_net {
347 325
348 kib_tx_poolset_t **ibn_tx_ps; /* tx pool-set */ 326 kib_tx_poolset_t **ibn_tx_ps; /* tx pool-set */
349 kib_fmr_poolset_t **ibn_fmr_ps; /* fmr pool-set */ 327 kib_fmr_poolset_t **ibn_fmr_ps; /* fmr pool-set */
350 kib_pmr_poolset_t **ibn_pmr_ps; /* pmr pool-set */
351 328
352 kib_dev_t *ibn_dev; /* underlying IB device */ 329 kib_dev_t *ibn_dev; /* underlying IB device */
353} kib_net_t; 330} kib_net_t;
@@ -519,7 +496,7 @@ typedef struct kib_rx /* receive message */
519 enum ib_wc_status rx_status; /* completion status */ 496 enum ib_wc_status rx_status; /* completion status */
520 kib_msg_t *rx_msg; /* message buffer (host vaddr) */ 497 kib_msg_t *rx_msg; /* message buffer (host vaddr) */
521 __u64 rx_msgaddr; /* message buffer (I/O addr) */ 498 __u64 rx_msgaddr; /* message buffer (I/O addr) */
522 DECLARE_PCI_UNMAP_ADDR (rx_msgunmap); /* for dma_unmap_single() */ 499 DECLARE_PCI_UNMAP_ADDR(rx_msgunmap); /* for dma_unmap_single() */
523 struct ib_recv_wr rx_wrq; /* receive work item... */ 500 struct ib_recv_wr rx_wrq; /* receive work item... */
524 struct ib_sge rx_sge; /* ...and its memory */ 501 struct ib_sge rx_sge; /* ...and its memory */
525} kib_rx_t; 502} kib_rx_t;
@@ -546,7 +523,7 @@ typedef struct kib_tx /* transmit message */
546 * completion */ 523 * completion */
547 kib_msg_t *tx_msg; /* message buffer (host vaddr) */ 524 kib_msg_t *tx_msg; /* message buffer (host vaddr) */
548 __u64 tx_msgaddr; /* message buffer (I/O addr) */ 525 __u64 tx_msgaddr; /* message buffer (I/O addr) */
549 DECLARE_PCI_UNMAP_ADDR (tx_msgunmap); /* for dma_unmap_single() */ 526 DECLARE_PCI_UNMAP_ADDR(tx_msgunmap); /* for dma_unmap_single() */
550 int tx_nwrq; /* # send work items */ 527 int tx_nwrq; /* # send work items */
551 struct ib_send_wr *tx_wrq; /* send work items... */ 528 struct ib_send_wr *tx_wrq; /* send work items... */
552 struct ib_sge *tx_sge; /* ...and their memory */ 529 struct ib_sge *tx_sge; /* ...and their memory */
@@ -554,10 +531,7 @@ typedef struct kib_tx /* transmit message */
554 int tx_nfrags; /* # entries in... */ 531 int tx_nfrags; /* # entries in... */
555 struct scatterlist *tx_frags; /* dma_map_sg descriptor */ 532 struct scatterlist *tx_frags; /* dma_map_sg descriptor */
556 __u64 *tx_pages; /* rdma phys page addrs */ 533 __u64 *tx_pages; /* rdma phys page addrs */
557 union { 534 kib_fmr_t fmr; /* FMR */
558 kib_phys_mr_t *pmr; /* MR for physical buffer */
559 kib_fmr_t fmr; /* FMR */
560 } tx_u;
561 int tx_dmadir; /* dma direction */ 535 int tx_dmadir; /* dma direction */
562} kib_tx_t; 536} kib_tx_t;
563 537
@@ -642,19 +616,19 @@ typedef struct kib_peer {
642 616
643extern kib_data_t kiblnd_data; 617extern kib_data_t kiblnd_data;
644 618
645extern void kiblnd_hdev_destroy(kib_hca_dev_t *hdev); 619void kiblnd_hdev_destroy(kib_hca_dev_t *hdev);
646 620
647static inline void 621static inline void
648kiblnd_hdev_addref_locked(kib_hca_dev_t *hdev) 622kiblnd_hdev_addref_locked(kib_hca_dev_t *hdev)
649{ 623{
650 LASSERT (atomic_read(&hdev->ibh_ref) > 0); 624 LASSERT(atomic_read(&hdev->ibh_ref) > 0);
651 atomic_inc(&hdev->ibh_ref); 625 atomic_inc(&hdev->ibh_ref);
652} 626}
653 627
654static inline void 628static inline void
655kiblnd_hdev_decref(kib_hca_dev_t *hdev) 629kiblnd_hdev_decref(kib_hca_dev_t *hdev)
656{ 630{
657 LASSERT (atomic_read(&hdev->ibh_ref) > 0); 631 LASSERT(atomic_read(&hdev->ibh_ref) > 0);
658 if (atomic_dec_and_test(&hdev->ibh_ref)) 632 if (atomic_dec_and_test(&hdev->ibh_ref))
659 kiblnd_hdev_destroy(hdev); 633 kiblnd_hdev_destroy(hdev);
660} 634}
@@ -701,7 +675,7 @@ do { \
701do { \ 675do { \
702 CDEBUG(D_NET, "peer[%p] -> %s (%d)++\n", \ 676 CDEBUG(D_NET, "peer[%p] -> %s (%d)++\n", \
703 (peer), libcfs_nid2str((peer)->ibp_nid), \ 677 (peer), libcfs_nid2str((peer)->ibp_nid), \
704 atomic_read (&(peer)->ibp_refcount)); \ 678 atomic_read(&(peer)->ibp_refcount)); \
705 atomic_inc(&(peer)->ibp_refcount); \ 679 atomic_inc(&(peer)->ibp_refcount); \
706} while (0) 680} while (0)
707 681
@@ -709,32 +683,32 @@ do { \
709do { \ 683do { \
710 CDEBUG(D_NET, "peer[%p] -> %s (%d)--\n", \ 684 CDEBUG(D_NET, "peer[%p] -> %s (%d)--\n", \
711 (peer), libcfs_nid2str((peer)->ibp_nid), \ 685 (peer), libcfs_nid2str((peer)->ibp_nid), \
712 atomic_read (&(peer)->ibp_refcount)); \ 686 atomic_read(&(peer)->ibp_refcount)); \
713 LASSERT_ATOMIC_POS(&(peer)->ibp_refcount); \ 687 LASSERT_ATOMIC_POS(&(peer)->ibp_refcount); \
714 if (atomic_dec_and_test(&(peer)->ibp_refcount)) \ 688 if (atomic_dec_and_test(&(peer)->ibp_refcount)) \
715 kiblnd_destroy_peer(peer); \ 689 kiblnd_destroy_peer(peer); \
716} while (0) 690} while (0)
717 691
718static inline struct list_head * 692static inline struct list_head *
719kiblnd_nid2peerlist (lnet_nid_t nid) 693kiblnd_nid2peerlist(lnet_nid_t nid)
720{ 694{
721 unsigned int hash = 695 unsigned int hash =
722 ((unsigned int)nid) % kiblnd_data.kib_peer_hash_size; 696 ((unsigned int)nid) % kiblnd_data.kib_peer_hash_size;
723 697
724 return (&kiblnd_data.kib_peers [hash]); 698 return &kiblnd_data.kib_peers[hash];
725} 699}
726 700
727static inline int 701static inline int
728kiblnd_peer_active (kib_peer_t *peer) 702kiblnd_peer_active(kib_peer_t *peer)
729{ 703{
730 /* Am I in the peer hash table? */ 704 /* Am I in the peer hash table? */
731 return (!list_empty(&peer->ibp_list)); 705 return !list_empty(&peer->ibp_list);
732} 706}
733 707
734static inline kib_conn_t * 708static inline kib_conn_t *
735kiblnd_get_conn_locked (kib_peer_t *peer) 709kiblnd_get_conn_locked(kib_peer_t *peer)
736{ 710{
737 LASSERT (!list_empty(&peer->ibp_conns)); 711 LASSERT(!list_empty(&peer->ibp_conns));
738 712
739 /* just return the first connection */ 713 /* just return the first connection */
740 return list_entry(peer->ibp_conns.next, kib_conn_t, ibc_list); 714 return list_entry(peer->ibp_conns.next, kib_conn_t, ibc_list);
@@ -751,7 +725,7 @@ kiblnd_send_keepalive(kib_conn_t *conn)
751static inline int 725static inline int
752kiblnd_need_noop(kib_conn_t *conn) 726kiblnd_need_noop(kib_conn_t *conn)
753{ 727{
754 LASSERT (conn->ibc_state >= IBLND_CONN_ESTABLISHED); 728 LASSERT(conn->ibc_state >= IBLND_CONN_ESTABLISHED);
755 729
756 if (conn->ibc_outstanding_credits < 730 if (conn->ibc_outstanding_credits <
757 IBLND_CREDITS_HIGHWATER(conn->ibc_version) && 731 IBLND_CREDITS_HIGHWATER(conn->ibc_version) &&
@@ -788,7 +762,7 @@ kiblnd_abort_receives(kib_conn_t *conn)
788} 762}
789 763
790static inline const char * 764static inline const char *
791kiblnd_queue2str (kib_conn_t *conn, struct list_head *q) 765kiblnd_queue2str(kib_conn_t *conn, struct list_head *q)
792{ 766{
793 if (q == &conn->ibc_tx_queue) 767 if (q == &conn->ibc_tx_queue)
794 return "tx_queue"; 768 return "tx_queue";
@@ -815,43 +789,43 @@ kiblnd_queue2str (kib_conn_t *conn, struct list_head *q)
815#define IBLND_WID_MASK 3UL 789#define IBLND_WID_MASK 3UL
816 790
817static inline __u64 791static inline __u64
818kiblnd_ptr2wreqid (void *ptr, int type) 792kiblnd_ptr2wreqid(void *ptr, int type)
819{ 793{
820 unsigned long lptr = (unsigned long)ptr; 794 unsigned long lptr = (unsigned long)ptr;
821 795
822 LASSERT ((lptr & IBLND_WID_MASK) == 0); 796 LASSERT((lptr & IBLND_WID_MASK) == 0);
823 LASSERT ((type & ~IBLND_WID_MASK) == 0); 797 LASSERT((type & ~IBLND_WID_MASK) == 0);
824 return (__u64)(lptr | type); 798 return (__u64)(lptr | type);
825} 799}
826 800
827static inline void * 801static inline void *
828kiblnd_wreqid2ptr (__u64 wreqid) 802kiblnd_wreqid2ptr(__u64 wreqid)
829{ 803{
830 return (void *)(((unsigned long)wreqid) & ~IBLND_WID_MASK); 804 return (void *)(((unsigned long)wreqid) & ~IBLND_WID_MASK);
831} 805}
832 806
833static inline int 807static inline int
834kiblnd_wreqid2type (__u64 wreqid) 808kiblnd_wreqid2type(__u64 wreqid)
835{ 809{
836 return (wreqid & IBLND_WID_MASK); 810 return wreqid & IBLND_WID_MASK;
837} 811}
838 812
839static inline void 813static inline void
840kiblnd_set_conn_state (kib_conn_t *conn, int state) 814kiblnd_set_conn_state(kib_conn_t *conn, int state)
841{ 815{
842 conn->ibc_state = state; 816 conn->ibc_state = state;
843 mb(); 817 mb();
844} 818}
845 819
846static inline void 820static inline void
847kiblnd_init_msg (kib_msg_t *msg, int type, int body_nob) 821kiblnd_init_msg(kib_msg_t *msg, int type, int body_nob)
848{ 822{
849 msg->ibm_type = type; 823 msg->ibm_type = type;
850 msg->ibm_nob = offsetof(kib_msg_t, ibm_u) + body_nob; 824 msg->ibm_nob = offsetof(kib_msg_t, ibm_u) + body_nob;
851} 825}
852 826
853static inline int 827static inline int
854kiblnd_rd_size (kib_rdma_desc_t *rd) 828kiblnd_rd_size(kib_rdma_desc_t *rd)
855{ 829{
856 int i; 830 int i;
857 int size; 831 int size;
@@ -887,7 +861,7 @@ kiblnd_rd_consume_frag(kib_rdma_desc_t *rd, int index, __u32 nob)
887 rd->rd_frags[index].rf_addr += nob; 861 rd->rd_frags[index].rf_addr += nob;
888 rd->rd_frags[index].rf_nob -= nob; 862 rd->rd_frags[index].rf_nob -= nob;
889 } else { 863 } else {
890 index ++; 864 index++;
891 } 865 }
892 866
893 return index; 867 return index;
@@ -896,8 +870,8 @@ kiblnd_rd_consume_frag(kib_rdma_desc_t *rd, int index, __u32 nob)
896static inline int 870static inline int
897kiblnd_rd_msg_size(kib_rdma_desc_t *rd, int msgtype, int n) 871kiblnd_rd_msg_size(kib_rdma_desc_t *rd, int msgtype, int n)
898{ 872{
899 LASSERT (msgtype == IBLND_MSG_GET_REQ || 873 LASSERT(msgtype == IBLND_MSG_GET_REQ ||
900 msgtype == IBLND_MSG_PUT_ACK); 874 msgtype == IBLND_MSG_PUT_ACK);
901 875
902 return msgtype == IBLND_MSG_GET_REQ ? 876 return msgtype == IBLND_MSG_GET_REQ ?
903 offsetof(kib_get_msg_t, ibgm_rd.rd_frags[n]) : 877 offsetof(kib_get_msg_t, ibgm_rd.rd_frags[n]) :
@@ -978,57 +952,53 @@ int kiblnd_fmr_pool_map(kib_fmr_poolset_t *fps, __u64 *pages,
978 int npages, __u64 iov, kib_fmr_t *fmr); 952 int npages, __u64 iov, kib_fmr_t *fmr);
979void kiblnd_fmr_pool_unmap(kib_fmr_t *fmr, int status); 953void kiblnd_fmr_pool_unmap(kib_fmr_t *fmr, int status);
980 954
981int kiblnd_pmr_pool_map(kib_pmr_poolset_t *pps, kib_hca_dev_t *hdev, 955int kiblnd_startup(lnet_ni_t *ni);
982 kib_rdma_desc_t *rd, __u64 *iova, kib_phys_mr_t **pp_pmr); 956void kiblnd_shutdown(lnet_ni_t *ni);
983void kiblnd_pmr_pool_unmap(kib_phys_mr_t *pmr); 957int kiblnd_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg);
984 958void kiblnd_query(struct lnet_ni *ni, lnet_nid_t nid, unsigned long *when);
985int kiblnd_startup (lnet_ni_t *ni);
986void kiblnd_shutdown (lnet_ni_t *ni);
987int kiblnd_ctl (lnet_ni_t *ni, unsigned int cmd, void *arg);
988void kiblnd_query (struct lnet_ni *ni, lnet_nid_t nid, unsigned long *when);
989 959
990int kiblnd_tunables_init(void); 960int kiblnd_tunables_init(void);
991void kiblnd_tunables_fini(void); 961void kiblnd_tunables_fini(void);
992 962
993int kiblnd_connd (void *arg); 963int kiblnd_connd(void *arg);
994int kiblnd_scheduler(void *arg); 964int kiblnd_scheduler(void *arg);
995int kiblnd_thread_start(int (*fn)(void *arg), void *arg, char *name); 965int kiblnd_thread_start(int (*fn)(void *arg), void *arg, char *name);
996int kiblnd_failover_thread (void *arg); 966int kiblnd_failover_thread(void *arg);
997 967
998int kiblnd_alloc_pages(kib_pages_t **pp, int cpt, int npages); 968int kiblnd_alloc_pages(kib_pages_t **pp, int cpt, int npages);
999void kiblnd_free_pages (kib_pages_t *p); 969void kiblnd_free_pages(kib_pages_t *p);
1000 970
1001int kiblnd_cm_callback(struct rdma_cm_id *cmid, 971int kiblnd_cm_callback(struct rdma_cm_id *cmid,
1002 struct rdma_cm_event *event); 972 struct rdma_cm_event *event);
1003int kiblnd_translate_mtu(int value); 973int kiblnd_translate_mtu(int value);
1004 974
1005int kiblnd_dev_failover(kib_dev_t *dev); 975int kiblnd_dev_failover(kib_dev_t *dev);
1006int kiblnd_create_peer (lnet_ni_t *ni, kib_peer_t **peerp, lnet_nid_t nid); 976int kiblnd_create_peer(lnet_ni_t *ni, kib_peer_t **peerp, lnet_nid_t nid);
1007void kiblnd_destroy_peer (kib_peer_t *peer); 977void kiblnd_destroy_peer(kib_peer_t *peer);
1008void kiblnd_destroy_dev (kib_dev_t *dev); 978void kiblnd_destroy_dev(kib_dev_t *dev);
1009void kiblnd_unlink_peer_locked (kib_peer_t *peer); 979void kiblnd_unlink_peer_locked(kib_peer_t *peer);
1010void kiblnd_peer_alive (kib_peer_t *peer); 980void kiblnd_peer_alive(kib_peer_t *peer);
1011kib_peer_t *kiblnd_find_peer_locked (lnet_nid_t nid); 981kib_peer_t *kiblnd_find_peer_locked(lnet_nid_t nid);
1012void kiblnd_peer_connect_failed (kib_peer_t *peer, int active, int error); 982void kiblnd_peer_connect_failed(kib_peer_t *peer, int active, int error);
1013int kiblnd_close_stale_conns_locked (kib_peer_t *peer, 983int kiblnd_close_stale_conns_locked(kib_peer_t *peer,
1014 int version, __u64 incarnation); 984 int version, __u64 incarnation);
1015int kiblnd_close_peer_conns_locked (kib_peer_t *peer, int why); 985int kiblnd_close_peer_conns_locked(kib_peer_t *peer, int why);
1016 986
1017void kiblnd_connreq_done(kib_conn_t *conn, int status); 987void kiblnd_connreq_done(kib_conn_t *conn, int status);
1018kib_conn_t *kiblnd_create_conn (kib_peer_t *peer, struct rdma_cm_id *cmid, 988kib_conn_t *kiblnd_create_conn(kib_peer_t *peer, struct rdma_cm_id *cmid,
1019 int state, int version); 989 int state, int version);
1020void kiblnd_destroy_conn (kib_conn_t *conn); 990void kiblnd_destroy_conn(kib_conn_t *conn);
1021void kiblnd_close_conn (kib_conn_t *conn, int error); 991void kiblnd_close_conn(kib_conn_t *conn, int error);
1022void kiblnd_close_conn_locked (kib_conn_t *conn, int error); 992void kiblnd_close_conn_locked(kib_conn_t *conn, int error);
1023 993
1024int kiblnd_init_rdma (kib_conn_t *conn, kib_tx_t *tx, int type, 994int kiblnd_init_rdma(kib_conn_t *conn, kib_tx_t *tx, int type,
1025 int nob, kib_rdma_desc_t *dstrd, __u64 dstcookie); 995 int nob, kib_rdma_desc_t *dstrd, __u64 dstcookie);
1026 996
1027void kiblnd_launch_tx (lnet_ni_t *ni, kib_tx_t *tx, lnet_nid_t nid); 997void kiblnd_launch_tx(lnet_ni_t *ni, kib_tx_t *tx, lnet_nid_t nid);
1028void kiblnd_queue_tx_locked (kib_tx_t *tx, kib_conn_t *conn); 998void kiblnd_queue_tx_locked(kib_tx_t *tx, kib_conn_t *conn);
1029void kiblnd_queue_tx (kib_tx_t *tx, kib_conn_t *conn); 999void kiblnd_queue_tx(kib_tx_t *tx, kib_conn_t *conn);
1030void kiblnd_init_tx_msg (lnet_ni_t *ni, kib_tx_t *tx, int type, int body_nob); 1000void kiblnd_init_tx_msg(lnet_ni_t *ni, kib_tx_t *tx, int type, int body_nob);
1031void kiblnd_txlist_done (lnet_ni_t *ni, struct list_head *txlist, 1001void kiblnd_txlist_done(lnet_ni_t *ni, struct list_head *txlist,
1032 int status); 1002 int status);
1033void kiblnd_check_sends (kib_conn_t *conn); 1003void kiblnd_check_sends (kib_conn_t *conn);
1034 1004
@@ -1036,10 +1006,10 @@ void kiblnd_qp_event(struct ib_event *event, void *arg);
1036void kiblnd_cq_event(struct ib_event *event, void *arg); 1006void kiblnd_cq_event(struct ib_event *event, void *arg);
1037void kiblnd_cq_completion(struct ib_cq *cq, void *arg); 1007void kiblnd_cq_completion(struct ib_cq *cq, void *arg);
1038 1008
1039void kiblnd_pack_msg (lnet_ni_t *ni, kib_msg_t *msg, int version, 1009void kiblnd_pack_msg(lnet_ni_t *ni, kib_msg_t *msg, int version,
1040 int credits, lnet_nid_t dstnid, __u64 dststamp); 1010 int credits, lnet_nid_t dstnid, __u64 dststamp);
1041int kiblnd_unpack_msg(kib_msg_t *msg, int nob); 1011int kiblnd_unpack_msg(kib_msg_t *msg, int nob);
1042int kiblnd_post_rx (kib_rx_t *rx, int credit); 1012int kiblnd_post_rx(kib_rx_t *rx, int credit);
1043 1013
1044int kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg); 1014int kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg);
1045int kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed, 1015int kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
index 477aa8b76f32..a23a6d956a4d 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
@@ -121,7 +121,6 @@ kiblnd_get_idle_tx(lnet_ni_t *ni, lnet_nid_t target)
121 LASSERT(tx->tx_conn == NULL); 121 LASSERT(tx->tx_conn == NULL);
122 LASSERT(tx->tx_lntmsg[0] == NULL); 122 LASSERT(tx->tx_lntmsg[0] == NULL);
123 LASSERT(tx->tx_lntmsg[1] == NULL); 123 LASSERT(tx->tx_lntmsg[1] == NULL);
124 LASSERT(tx->tx_u.pmr == NULL);
125 LASSERT(tx->tx_nfrags == 0); 124 LASSERT(tx->tx_nfrags == 0);
126 125
127 return tx; 126 return tx;
@@ -575,7 +574,7 @@ kiblnd_fmr_map_tx(kib_net_t *net, kib_tx_t *tx, kib_rdma_desc_t *rd, int nob)
575 cpt = tx->tx_pool->tpo_pool.po_owner->ps_cpt; 574 cpt = tx->tx_pool->tpo_pool.po_owner->ps_cpt;
576 575
577 fps = net->ibn_fmr_ps[cpt]; 576 fps = net->ibn_fmr_ps[cpt];
578 rc = kiblnd_fmr_pool_map(fps, pages, npages, 0, &tx->tx_u.fmr); 577 rc = kiblnd_fmr_pool_map(fps, pages, npages, 0, &tx->fmr);
579 if (rc != 0) { 578 if (rc != 0) {
580 CERROR("Can't map %d pages: %d\n", npages, rc); 579 CERROR("Can't map %d pages: %d\n", npages, rc);
581 return rc; 580 return rc;
@@ -583,8 +582,8 @@ kiblnd_fmr_map_tx(kib_net_t *net, kib_tx_t *tx, kib_rdma_desc_t *rd, int nob)
583 582
584 /* If rd is not tx_rd, it's going to get sent to a peer, who will need 583 /* If rd is not tx_rd, it's going to get sent to a peer, who will need
585 * the rkey */ 584 * the rkey */
586 rd->rd_key = (rd != tx->tx_rd) ? tx->tx_u.fmr.fmr_pfmr->fmr->rkey : 585 rd->rd_key = (rd != tx->tx_rd) ? tx->fmr.fmr_pfmr->fmr->rkey :
587 tx->tx_u.fmr.fmr_pfmr->fmr->lkey; 586 tx->fmr.fmr_pfmr->fmr->lkey;
588 rd->rd_frags[0].rf_addr &= ~hdev->ibh_page_mask; 587 rd->rd_frags[0].rf_addr &= ~hdev->ibh_page_mask;
589 rd->rd_frags[0].rf_nob = nob; 588 rd->rd_frags[0].rf_nob = nob;
590 rd->rd_nfrags = 1; 589 rd->rd_nfrags = 1;
@@ -592,42 +591,6 @@ kiblnd_fmr_map_tx(kib_net_t *net, kib_tx_t *tx, kib_rdma_desc_t *rd, int nob)
592 return 0; 591 return 0;
593} 592}
594 593
595static int
596kiblnd_pmr_map_tx(kib_net_t *net, kib_tx_t *tx, kib_rdma_desc_t *rd, int nob)
597{
598 kib_hca_dev_t *hdev;
599 kib_pmr_poolset_t *pps;
600 __u64 iova;
601 int cpt;
602 int rc;
603
604 LASSERT(tx->tx_pool != NULL);
605 LASSERT(tx->tx_pool->tpo_pool.po_owner != NULL);
606
607 hdev = tx->tx_pool->tpo_hdev;
608
609 iova = rd->rd_frags[0].rf_addr & ~hdev->ibh_page_mask;
610
611 cpt = tx->tx_pool->tpo_pool.po_owner->ps_cpt;
612
613 pps = net->ibn_pmr_ps[cpt];
614 rc = kiblnd_pmr_pool_map(pps, hdev, rd, &iova, &tx->tx_u.pmr);
615 if (rc != 0) {
616 CERROR("Failed to create MR by phybuf: %d\n", rc);
617 return rc;
618 }
619
620 /* If rd is not tx_rd, it's going to get sent to a peer, who will need
621 * the rkey */
622 rd->rd_key = (rd != tx->tx_rd) ? tx->tx_u.pmr->pmr_mr->rkey :
623 tx->tx_u.pmr->pmr_mr->lkey;
624 rd->rd_nfrags = 1;
625 rd->rd_frags[0].rf_addr = iova;
626 rd->rd_frags[0].rf_nob = nob;
627
628 return 0;
629}
630
631void 594void
632kiblnd_unmap_tx(lnet_ni_t *ni, kib_tx_t *tx) 595kiblnd_unmap_tx(lnet_ni_t *ni, kib_tx_t *tx)
633{ 596{
@@ -635,13 +598,9 @@ kiblnd_unmap_tx(lnet_ni_t *ni, kib_tx_t *tx)
635 598
636 LASSERT(net != NULL); 599 LASSERT(net != NULL);
637 600
638 if (net->ibn_fmr_ps != NULL && tx->tx_u.fmr.fmr_pfmr != NULL) { 601 if (net->ibn_fmr_ps && tx->fmr.fmr_pfmr) {
639 kiblnd_fmr_pool_unmap(&tx->tx_u.fmr, tx->tx_status); 602 kiblnd_fmr_pool_unmap(&tx->fmr, tx->tx_status);
640 tx->tx_u.fmr.fmr_pfmr = NULL; 603 tx->fmr.fmr_pfmr = NULL;
641
642 } else if (net->ibn_pmr_ps != NULL && tx->tx_u.pmr != NULL) {
643 kiblnd_pmr_pool_unmap(tx->tx_u.pmr);
644 tx->tx_u.pmr = NULL;
645 } 604 }
646 605
647 if (tx->tx_nfrags != 0) { 606 if (tx->tx_nfrags != 0) {
@@ -687,8 +646,6 @@ kiblnd_map_tx(lnet_ni_t *ni, kib_tx_t *tx,
687 646
688 if (net->ibn_fmr_ps != NULL) 647 if (net->ibn_fmr_ps != NULL)
689 return kiblnd_fmr_map_tx(net, tx, rd, nob); 648 return kiblnd_fmr_map_tx(net, tx, rd, nob);
690 else if (net->ibn_pmr_ps != NULL)
691 return kiblnd_pmr_map_tx(net, tx, rd, nob);
692 649
693 return -EINVAL; 650 return -EINVAL;
694} 651}
@@ -3133,8 +3090,7 @@ kiblnd_connd(void *arg)
3133 dropped_lock = 0; 3090 dropped_lock = 0;
3134 3091
3135 if (!list_empty(&kiblnd_data.kib_connd_zombies)) { 3092 if (!list_empty(&kiblnd_data.kib_connd_zombies)) {
3136 conn = list_entry(kiblnd_data. \ 3093 conn = list_entry(kiblnd_data.kib_connd_zombies.next,
3137 kib_connd_zombies.next,
3138 kib_conn_t, ibc_list); 3094 kib_conn_t, ibc_list);
3139 list_del(&conn->ibc_list); 3095 list_del(&conn->ibc_list);
3140 3096
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c
index b0e00361cfce..b3d1b5d627cb 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c
@@ -126,11 +126,6 @@ static int fmr_cache = 1;
126module_param(fmr_cache, int, 0444); 126module_param(fmr_cache, int, 0444);
127MODULE_PARM_DESC(fmr_cache, "non-zero to enable FMR caching"); 127MODULE_PARM_DESC(fmr_cache, "non-zero to enable FMR caching");
128 128
129/* NB: this value is shared by all CPTs, it can grow at runtime */
130static int pmr_pool_size = 512;
131module_param(pmr_pool_size, int, 0444);
132MODULE_PARM_DESC(pmr_pool_size, "size of MR cache pmr pool on each CPT");
133
134/* 129/*
135 * 0: disable failover 130 * 0: disable failover
136 * 1: enable failover if necessary 131 * 1: enable failover if necessary
@@ -170,7 +165,6 @@ kib_tunables_t kiblnd_tunables = {
170 .kib_fmr_pool_size = &fmr_pool_size, 165 .kib_fmr_pool_size = &fmr_pool_size,
171 .kib_fmr_flush_trigger = &fmr_flush_trigger, 166 .kib_fmr_flush_trigger = &fmr_flush_trigger,
172 .kib_fmr_cache = &fmr_cache, 167 .kib_fmr_cache = &fmr_cache,
173 .kib_pmr_pool_size = &pmr_pool_size,
174 .kib_require_priv_port = &require_privileged_port, 168 .kib_require_priv_port = &require_privileged_port,
175 .kib_use_priv_port = &use_privileged_port, 169 .kib_use_priv_port = &use_privileged_port,
176 .kib_nscheds = &nscheds 170 .kib_nscheds = &nscheds
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
index 4128a92218a9..d8bfcadd184a 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
@@ -2252,8 +2252,6 @@ ksocknal_base_shutdown(void)
2252 int i; 2252 int i;
2253 int j; 2253 int j;
2254 2254
2255 CDEBUG(D_MALLOC, "before NAL cleanup: kmem %d\n",
2256 atomic_read(&libcfs_kmemory));
2257 LASSERT(ksocknal_data.ksnd_nnets == 0); 2255 LASSERT(ksocknal_data.ksnd_nnets == 0);
2258 2256
2259 switch (ksocknal_data.ksnd_init) { 2257 switch (ksocknal_data.ksnd_init) {
@@ -2331,9 +2329,6 @@ ksocknal_base_shutdown(void)
2331 break; 2329 break;
2332 } 2330 }
2333 2331
2334 CDEBUG(D_MALLOC, "after NAL cleanup: kmem %d\n",
2335 atomic_read(&libcfs_kmemory));
2336
2337 module_put(THIS_MODULE); 2332 module_put(THIS_MODULE);
2338} 2333}
2339 2334
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h
index 8a9d4a0de129..a0fcbc39f86b 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h
@@ -46,6 +46,7 @@
46#include <linux/sysctl.h> 46#include <linux/sysctl.h>
47#include <linux/uio.h> 47#include <linux/uio.h>
48#include <linux/unistd.h> 48#include <linux/unistd.h>
49#include <asm/irq.h>
49#include <net/sock.h> 50#include <net/sock.h>
50#include <net/tcp.h> 51#include <net/tcp.h>
51 52
@@ -519,8 +520,8 @@ ksocknal_conn_addref(ksock_conn_t *conn)
519 atomic_inc(&conn->ksnc_conn_refcount); 520 atomic_inc(&conn->ksnc_conn_refcount);
520} 521}
521 522
522extern void ksocknal_queue_zombie_conn(ksock_conn_t *conn); 523void ksocknal_queue_zombie_conn(ksock_conn_t *conn);
523extern void ksocknal_finalize_zcreq(ksock_conn_t *conn); 524void ksocknal_finalize_zcreq(ksock_conn_t *conn);
524 525
525static inline void 526static inline void
526ksocknal_conn_decref(ksock_conn_t *conn) 527ksocknal_conn_decref(ksock_conn_t *conn)
@@ -565,8 +566,8 @@ ksocknal_tx_addref(ksock_tx_t *tx)
565 atomic_inc(&tx->tx_refcount); 566 atomic_inc(&tx->tx_refcount);
566} 567}
567 568
568extern void ksocknal_tx_prep(ksock_conn_t *, ksock_tx_t *tx); 569void ksocknal_tx_prep(ksock_conn_t *, ksock_tx_t *tx);
569extern void ksocknal_tx_done(lnet_ni_t *ni, ksock_tx_t *tx); 570void ksocknal_tx_done(lnet_ni_t *ni, ksock_tx_t *tx);
570 571
571static inline void 572static inline void
572ksocknal_tx_decref(ksock_tx_t *tx) 573ksocknal_tx_decref(ksock_tx_t *tx)
@@ -583,7 +584,7 @@ ksocknal_route_addref(ksock_route_t *route)
583 atomic_inc(&route->ksnr_refcount); 584 atomic_inc(&route->ksnr_refcount);
584} 585}
585 586
586extern void ksocknal_destroy_route(ksock_route_t *route); 587void ksocknal_destroy_route(ksock_route_t *route);
587 588
588static inline void 589static inline void
589ksocknal_route_decref(ksock_route_t *route) 590ksocknal_route_decref(ksock_route_t *route)
@@ -600,7 +601,7 @@ ksocknal_peer_addref(ksock_peer_t *peer)
600 atomic_inc(&peer->ksnp_refcount); 601 atomic_inc(&peer->ksnp_refcount);
601} 602}
602 603
603extern void ksocknal_destroy_peer(ksock_peer_t *peer); 604void ksocknal_destroy_peer(ksock_peer_t *peer);
604 605
605static inline void 606static inline void
606ksocknal_peer_decref(ksock_peer_t *peer) 607ksocknal_peer_decref(ksock_peer_t *peer)
@@ -620,70 +621,69 @@ int ksocknal_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg,
620 unsigned int offset, unsigned int mlen, unsigned int rlen); 621 unsigned int offset, unsigned int mlen, unsigned int rlen);
621int ksocknal_accept(lnet_ni_t *ni, struct socket *sock); 622int ksocknal_accept(lnet_ni_t *ni, struct socket *sock);
622 623
623extern int ksocknal_add_peer(lnet_ni_t *ni, lnet_process_id_t id, __u32 ip, int port); 624int ksocknal_add_peer(lnet_ni_t *ni, lnet_process_id_t id, __u32 ip, int port);
624extern ksock_peer_t *ksocknal_find_peer_locked(lnet_ni_t *ni, lnet_process_id_t id); 625ksock_peer_t *ksocknal_find_peer_locked(lnet_ni_t *ni, lnet_process_id_t id);
625extern ksock_peer_t *ksocknal_find_peer(lnet_ni_t *ni, lnet_process_id_t id); 626ksock_peer_t *ksocknal_find_peer(lnet_ni_t *ni, lnet_process_id_t id);
626extern void ksocknal_peer_failed(ksock_peer_t *peer); 627void ksocknal_peer_failed(ksock_peer_t *peer);
627extern int ksocknal_create_conn(lnet_ni_t *ni, ksock_route_t *route, 628int ksocknal_create_conn(lnet_ni_t *ni, ksock_route_t *route,
628 struct socket *sock, int type); 629 struct socket *sock, int type);
629extern void ksocknal_close_conn_locked(ksock_conn_t *conn, int why); 630void ksocknal_close_conn_locked(ksock_conn_t *conn, int why);
630extern void ksocknal_terminate_conn(ksock_conn_t *conn); 631void ksocknal_terminate_conn(ksock_conn_t *conn);
631extern void ksocknal_destroy_conn(ksock_conn_t *conn); 632void ksocknal_destroy_conn(ksock_conn_t *conn);
632extern int ksocknal_close_peer_conns_locked(ksock_peer_t *peer, 633int ksocknal_close_peer_conns_locked(ksock_peer_t *peer,
633 __u32 ipaddr, int why); 634 __u32 ipaddr, int why);
634extern int ksocknal_close_conn_and_siblings(ksock_conn_t *conn, int why); 635int ksocknal_close_conn_and_siblings(ksock_conn_t *conn, int why);
635extern int ksocknal_close_matching_conns(lnet_process_id_t id, __u32 ipaddr); 636int ksocknal_close_matching_conns(lnet_process_id_t id, __u32 ipaddr);
636extern ksock_conn_t *ksocknal_find_conn_locked(ksock_peer_t *peer, 637ksock_conn_t *ksocknal_find_conn_locked(ksock_peer_t *peer,
637 ksock_tx_t *tx, int nonblk); 638 ksock_tx_t *tx, int nonblk);
638 639
639extern int ksocknal_launch_packet(lnet_ni_t *ni, ksock_tx_t *tx, 640int ksocknal_launch_packet(lnet_ni_t *ni, ksock_tx_t *tx,
640 lnet_process_id_t id); 641 lnet_process_id_t id);
641extern ksock_tx_t *ksocknal_alloc_tx(int type, int size); 642ksock_tx_t *ksocknal_alloc_tx(int type, int size);
642extern void ksocknal_free_tx(ksock_tx_t *tx); 643void ksocknal_free_tx(ksock_tx_t *tx);
643extern ksock_tx_t *ksocknal_alloc_tx_noop(__u64 cookie, int nonblk); 644ksock_tx_t *ksocknal_alloc_tx_noop(__u64 cookie, int nonblk);
644extern void ksocknal_next_tx_carrier(ksock_conn_t *conn); 645void ksocknal_next_tx_carrier(ksock_conn_t *conn);
645extern void ksocknal_queue_tx_locked(ksock_tx_t *tx, ksock_conn_t *conn); 646void ksocknal_queue_tx_locked(ksock_tx_t *tx, ksock_conn_t *conn);
646extern void ksocknal_txlist_done(lnet_ni_t *ni, struct list_head *txlist, 647void ksocknal_txlist_done(lnet_ni_t *ni, struct list_head *txlist, int error);
647 int error); 648void ksocknal_notify(lnet_ni_t *ni, lnet_nid_t gw_nid, int alive);
648extern void ksocknal_notify(lnet_ni_t *ni, lnet_nid_t gw_nid, int alive); 649void ksocknal_query(struct lnet_ni *ni, lnet_nid_t nid, unsigned long *when);
649extern void ksocknal_query(struct lnet_ni *ni, lnet_nid_t nid, unsigned long *when); 650int ksocknal_thread_start(int (*fn)(void *arg), void *arg, char *name);
650extern int ksocknal_thread_start(int (*fn)(void *arg), void *arg, char *name); 651void ksocknal_thread_fini(void);
651extern void ksocknal_thread_fini(void); 652void ksocknal_launch_all_connections_locked(ksock_peer_t *peer);
652extern void ksocknal_launch_all_connections_locked(ksock_peer_t *peer); 653ksock_route_t *ksocknal_find_connectable_route_locked(ksock_peer_t *peer);
653extern ksock_route_t *ksocknal_find_connectable_route_locked(ksock_peer_t *peer); 654ksock_route_t *ksocknal_find_connecting_route_locked(ksock_peer_t *peer);
654extern ksock_route_t *ksocknal_find_connecting_route_locked(ksock_peer_t *peer); 655int ksocknal_new_packet(ksock_conn_t *conn, int skip);
655extern int ksocknal_new_packet(ksock_conn_t *conn, int skip); 656int ksocknal_scheduler(void *arg);
656extern int ksocknal_scheduler(void *arg); 657int ksocknal_connd(void *arg);
657extern int ksocknal_connd(void *arg); 658int ksocknal_reaper(void *arg);
658extern int ksocknal_reaper(void *arg); 659int ksocknal_send_hello(lnet_ni_t *ni, ksock_conn_t *conn,
659extern int ksocknal_send_hello(lnet_ni_t *ni, ksock_conn_t *conn, 660 lnet_nid_t peer_nid, ksock_hello_msg_t *hello);
660 lnet_nid_t peer_nid, ksock_hello_msg_t *hello); 661int ksocknal_recv_hello(lnet_ni_t *ni, ksock_conn_t *conn,
661extern int ksocknal_recv_hello(lnet_ni_t *ni, ksock_conn_t *conn, 662 ksock_hello_msg_t *hello, lnet_process_id_t *id,
662 ksock_hello_msg_t *hello, lnet_process_id_t *id, 663 __u64 *incarnation);
663 __u64 *incarnation); 664void ksocknal_read_callback(ksock_conn_t *conn);
664extern void ksocknal_read_callback(ksock_conn_t *conn); 665void ksocknal_write_callback(ksock_conn_t *conn);
665extern void ksocknal_write_callback(ksock_conn_t *conn); 666
666 667int ksocknal_lib_zc_capable(ksock_conn_t *conn);
667extern int ksocknal_lib_zc_capable(ksock_conn_t *conn); 668void ksocknal_lib_save_callback(struct socket *sock, ksock_conn_t *conn);
668extern void ksocknal_lib_save_callback(struct socket *sock, ksock_conn_t *conn); 669void ksocknal_lib_set_callback(struct socket *sock, ksock_conn_t *conn);
669extern void ksocknal_lib_set_callback(struct socket *sock, ksock_conn_t *conn); 670void ksocknal_lib_reset_callback(struct socket *sock, ksock_conn_t *conn);
670extern void ksocknal_lib_reset_callback(struct socket *sock, ksock_conn_t *conn); 671void ksocknal_lib_push_conn(ksock_conn_t *conn);
671extern void ksocknal_lib_push_conn(ksock_conn_t *conn); 672int ksocknal_lib_get_conn_addrs(ksock_conn_t *conn);
672extern int ksocknal_lib_get_conn_addrs(ksock_conn_t *conn); 673int ksocknal_lib_setup_sock(struct socket *so);
673extern int ksocknal_lib_setup_sock(struct socket *so); 674int ksocknal_lib_send_iov(ksock_conn_t *conn, ksock_tx_t *tx);
674extern int ksocknal_lib_send_iov(ksock_conn_t *conn, ksock_tx_t *tx); 675int ksocknal_lib_send_kiov(ksock_conn_t *conn, ksock_tx_t *tx);
675extern int ksocknal_lib_send_kiov(ksock_conn_t *conn, ksock_tx_t *tx); 676void ksocknal_lib_eager_ack(ksock_conn_t *conn);
676extern void ksocknal_lib_eager_ack(ksock_conn_t *conn); 677int ksocknal_lib_recv_iov(ksock_conn_t *conn);
677extern int ksocknal_lib_recv_iov(ksock_conn_t *conn); 678int ksocknal_lib_recv_kiov(ksock_conn_t *conn);
678extern int ksocknal_lib_recv_kiov(ksock_conn_t *conn); 679int ksocknal_lib_get_conn_tunables(ksock_conn_t *conn, int *txmem,
679extern int ksocknal_lib_get_conn_tunables(ksock_conn_t *conn, int *txmem, 680 int *rxmem, int *nagle);
680 int *rxmem, int *nagle); 681
681 682int ksocknal_tunables_init(void);
682extern int ksocknal_tunables_init(void); 683
683 684void ksocknal_lib_csum_tx(ksock_tx_t *tx);
684extern void ksocknal_lib_csum_tx(ksock_tx_t *tx); 685
685 686int ksocknal_lib_memory_pressure(ksock_conn_t *conn);
686extern int ksocknal_lib_memory_pressure(ksock_conn_t *conn); 687int ksocknal_lib_bind_thread_to_cpu(int id);
687extern int ksocknal_lib_bind_thread_to_cpu(int id);
688 688
689#endif /* _SOCKLND_SOCKLND_H_ */ 689#endif /* _SOCKLND_SOCKLND_H_ */
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
index fe2a83a540cd..0d5aac6a2bb3 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
@@ -526,8 +526,7 @@ ksocknal_process_transmit (ksock_conn_t *conn, ksock_tx_t *tx)
526 526
527 counter++; /* exponential backoff warnings */ 527 counter++; /* exponential backoff warnings */
528 if ((counter & (-counter)) == counter) 528 if ((counter & (-counter)) == counter)
529 CWARN("%u ENOMEM tx %p (%u allocated)\n", 529 CWARN("%u ENOMEM tx %p\n", counter, conn);
530 counter, conn, atomic_read(&libcfs_kmemory));
531 530
532 /* Queue on ksnd_enomem_conns for retry after a timeout */ 531 /* Queue on ksnd_enomem_conns for retry after a timeout */
533 spin_lock_bh(&ksocknal_data.ksnd_reaper_lock); 532 spin_lock_bh(&ksocknal_data.ksnd_reaper_lock);
diff --git a/drivers/staging/lustre/lnet/lnet/router_proc.c b/drivers/staging/lustre/lnet/lnet/router_proc.c
index ee902dc43823..40f418b82960 100644
--- a/drivers/staging/lustre/lnet/lnet/router_proc.c
+++ b/drivers/staging/lustre/lnet/lnet/router_proc.c
@@ -32,17 +32,6 @@
32 32
33static struct ctl_table_header *lnet_table_header; 33static struct ctl_table_header *lnet_table_header;
34 34
35#define CTL_LNET (0x100)
36enum {
37 PSDEV_LNET_STATS = 100,
38 PSDEV_LNET_ROUTES,
39 PSDEV_LNET_ROUTERS,
40 PSDEV_LNET_PEERS,
41 PSDEV_LNET_BUFFERS,
42 PSDEV_LNET_NIS,
43 PSDEV_LNET_PTL_ROTOR,
44};
45
46#define LNET_LOFFT_BITS (sizeof(loff_t) * 8) 35#define LNET_LOFFT_BITS (sizeof(loff_t) * 8)
47/* 36/*
48 * NB: max allowed LNET_CPT_BITS is 8 on 64-bit system and 2 on 32-bit system 37 * NB: max allowed LNET_CPT_BITS is 8 on 64-bit system and 2 on 32-bit system
diff --git a/drivers/staging/lustre/lnet/selftest/console.h b/drivers/staging/lustre/lnet/selftest/console.h
index c4cf0aed80e1..cdce2dd6be7c 100644
--- a/drivers/staging/lustre/lnet/selftest/console.h
+++ b/drivers/staging/lustre/lnet/selftest/console.h
@@ -187,51 +187,49 @@ lstcon_id2hash (lnet_process_id_t id, struct list_head *hash)
187int lstcon_console_init(void); 187int lstcon_console_init(void);
188int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data); 188int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
189int lstcon_console_fini(void); 189int lstcon_console_fini(void);
190extern int lstcon_session_match(lst_sid_t sid); 190int lstcon_session_match(lst_sid_t sid);
191extern int lstcon_session_new(char *name, int key, unsigned version, 191int lstcon_session_new(char *name, int key, unsigned version,
192 int timeout, int flags, lst_sid_t *sid_up); 192 int timeout, int flags, lst_sid_t *sid_up);
193extern int lstcon_session_info(lst_sid_t *sid_up, int *key, unsigned *verp, 193int lstcon_session_info(lst_sid_t *sid_up, int *key, unsigned *verp,
194 lstcon_ndlist_ent_t *entp, char *name_up, int len); 194 lstcon_ndlist_ent_t *entp, char *name_up, int len);
195extern int lstcon_session_end(void); 195int lstcon_session_end(void);
196extern int lstcon_session_debug(int timeout, struct list_head *result_up); 196int lstcon_session_debug(int timeout, struct list_head *result_up);
197extern int lstcon_session_feats_check(unsigned feats); 197int lstcon_session_feats_check(unsigned feats);
198extern int lstcon_batch_debug(int timeout, char *name, 198int lstcon_batch_debug(int timeout, char *name,
199 int client, struct list_head *result_up); 199 int client, struct list_head *result_up);
200extern int lstcon_group_debug(int timeout, char *name, 200int lstcon_group_debug(int timeout, char *name,
201 struct list_head *result_up); 201 struct list_head *result_up);
202extern int lstcon_nodes_debug(int timeout, int nnd, lnet_process_id_t *nds_up, 202int lstcon_nodes_debug(int timeout, int nnd, lnet_process_id_t *nds_up,
203 struct list_head *result_up); 203 struct list_head *result_up);
204extern int lstcon_group_add(char *name); 204int lstcon_group_add(char *name);
205extern int lstcon_group_del(char *name); 205int lstcon_group_del(char *name);
206extern int lstcon_group_clean(char *name, int args); 206int lstcon_group_clean(char *name, int args);
207extern int lstcon_group_refresh(char *name, struct list_head *result_up); 207int lstcon_group_refresh(char *name, struct list_head *result_up);
208extern int lstcon_nodes_add(char *name, int nnd, lnet_process_id_t *nds_up, 208int lstcon_nodes_add(char *name, int nnd, lnet_process_id_t *nds_up,
209 unsigned *featp, struct list_head *result_up); 209 unsigned *featp, struct list_head *result_up);
210extern int lstcon_nodes_remove(char *name, int nnd, lnet_process_id_t *nds_up, 210int lstcon_nodes_remove(char *name, int nnd, lnet_process_id_t *nds_up,
211 struct list_head *result_up); 211 struct list_head *result_up);
212extern int lstcon_group_info(char *name, lstcon_ndlist_ent_t *gent_up, 212int lstcon_group_info(char *name, lstcon_ndlist_ent_t *gent_up,
213 int *index_p, int *ndent_p, lstcon_node_ent_t *ndents_up); 213 int *index_p, int *ndent_p, lstcon_node_ent_t *ndents_up);
214extern int lstcon_group_list(int idx, int len, char *name_up); 214int lstcon_group_list(int idx, int len, char *name_up);
215extern int lstcon_batch_add(char *name); 215int lstcon_batch_add(char *name);
216extern int lstcon_batch_run(char *name, int timeout, 216int lstcon_batch_run(char *name, int timeout, struct list_head *result_up);
217int lstcon_batch_stop(char *name, int force, struct list_head *result_up);
218int lstcon_test_batch_query(char *name, int testidx,
219 int client, int timeout,
217 struct list_head *result_up); 220 struct list_head *result_up);
218extern int lstcon_batch_stop(char *name, int force, 221int lstcon_batch_del(char *name);
219 struct list_head *result_up); 222int lstcon_batch_list(int idx, int namelen, char *name_up);
220extern int lstcon_test_batch_query(char *name, int testidx, 223int lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up,
221 int client, int timeout, 224 int server, int testidx, int *index_p,
222 struct list_head *result_up); 225 int *ndent_p, lstcon_node_ent_t *dents_up);
223extern int lstcon_batch_del(char *name); 226int lstcon_group_stat(char *grp_name, int timeout,
224extern int lstcon_batch_list(int idx, int namelen, char *name_up); 227 struct list_head *result_up);
225extern int lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, 228int lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
226 int server, int testidx, int *index_p, 229 int timeout, struct list_head *result_up);
227 int *ndent_p, lstcon_node_ent_t *dents_up); 230int lstcon_test_add(char *batch_name, int type, int loop,
228extern int lstcon_group_stat(char *grp_name, int timeout, 231 int concur, int dist, int span,
229 struct list_head *result_up); 232 char *src_name, char *dst_name,
230extern int lstcon_nodes_stat(int count, lnet_process_id_t *ids_up, 233 void *param, int paramlen, int *retp,
231 int timeout, struct list_head *result_up); 234 struct list_head *result_up);
232extern int lstcon_test_add(char *batch_name, int type, int loop,
233 int concur, int dist, int span,
234 char *src_name, char *dst_name,
235 void *param, int paramlen, int *retp,
236 struct list_head *result_up);
237#endif 235#endif
diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
index 7c5185a2a795..257de3537671 100644
--- a/drivers/staging/lustre/lnet/selftest/framework.c
+++ b/drivers/staging/lustre/lnet/selftest/framework.c
@@ -203,7 +203,8 @@ sfw_deactivate_session(void)
203 sfw_batch_t *tsb; 203 sfw_batch_t *tsb;
204 sfw_test_case_t *tsc; 204 sfw_test_case_t *tsc;
205 205
206 if (sn == NULL) return; 206 if (sn == NULL)
207 return;
207 208
208 LASSERT(!sn->sn_timer_active); 209 LASSERT(!sn->sn_timer_active);
209 210
@@ -613,7 +614,8 @@ sfw_destroy_test_instance(sfw_test_instance_t *tsi)
613 srpc_client_rpc_t *rpc; 614 srpc_client_rpc_t *rpc;
614 sfw_test_unit_t *tsu; 615 sfw_test_unit_t *tsu;
615 616
616 if (!tsi->tsi_is_client) goto clean; 617 if (!tsi->tsi_is_client)
618 goto clean;
617 619
618 tsi->tsi_ops->tso_fini(tsi); 620 tsi->tsi_ops->tso_fini(tsi);
619 621
@@ -1700,7 +1702,8 @@ sfw_startup(void)
1700 1702
1701 for (i = 0; ; i++) { 1703 for (i = 0; ; i++) {
1702 sv = &sfw_services[i]; 1704 sv = &sfw_services[i];
1703 if (sv->sv_name == NULL) break; 1705 if (sv->sv_name == NULL)
1706 break;
1704 1707
1705 sv->sv_bulk_ready = NULL; 1708 sv->sv_bulk_ready = NULL;
1706 sv->sv_handler = sfw_handle_server_rpc; 1709 sv->sv_handler = sfw_handle_server_rpc;
@@ -1717,7 +1720,8 @@ sfw_startup(void)
1717 } 1720 }
1718 1721
1719 /* about to sfw_shutdown, no need to add buffer */ 1722 /* about to sfw_shutdown, no need to add buffer */
1720 if (error) continue; 1723 if (error)
1724 continue;
1721 1725
1722 rc = srpc_service_add_buffers(sv, sv->sv_wi_total); 1726 rc = srpc_service_add_buffers(sv, sv->sv_wi_total);
1723 if (rc != 0) { 1727 if (rc != 0) {
diff --git a/drivers/staging/lustre/lustre/fid/fid_request.c b/drivers/staging/lustre/lustre/fid/fid_request.c
index 1362783b7eab..a16d577c6cb1 100644
--- a/drivers/staging/lustre/lustre/fid/fid_request.c
+++ b/drivers/staging/lustre/lustre/fid/fid_request.c
@@ -498,11 +498,11 @@ int client_fid_init(struct obd_device *obd,
498 int rc; 498 int rc;
499 499
500 cli->cl_seq = kzalloc(sizeof(*cli->cl_seq), GFP_NOFS); 500 cli->cl_seq = kzalloc(sizeof(*cli->cl_seq), GFP_NOFS);
501 if (cli->cl_seq == NULL) 501 if (!cli->cl_seq)
502 return -ENOMEM; 502 return -ENOMEM;
503 503
504 prefix = kzalloc(MAX_OBD_NAME + 5, GFP_NOFS); 504 prefix = kzalloc(MAX_OBD_NAME + 5, GFP_NOFS);
505 if (prefix == NULL) { 505 if (!prefix) {
506 rc = -ENOMEM; 506 rc = -ENOMEM;
507 goto out_free_seq; 507 goto out_free_seq;
508 } 508 }
diff --git a/drivers/staging/lustre/lustre/fld/fld_cache.c b/drivers/staging/lustre/lustre/fld/fld_cache.c
index ec2fc4339a2e..1b1066b2461c 100644
--- a/drivers/staging/lustre/lustre/fld/fld_cache.c
+++ b/drivers/staging/lustre/lustre/fld/fld_cache.c
@@ -70,7 +70,7 @@ struct fld_cache *fld_cache_init(const char *name,
70 LASSERT(cache_threshold < cache_size); 70 LASSERT(cache_threshold < cache_size);
71 71
72 cache = kzalloc(sizeof(*cache), GFP_NOFS); 72 cache = kzalloc(sizeof(*cache), GFP_NOFS);
73 if (cache == NULL) 73 if (!cache)
74 return ERR_PTR(-ENOMEM); 74 return ERR_PTR(-ENOMEM);
75 75
76 INIT_LIST_HEAD(&cache->fci_entries_head); 76 INIT_LIST_HEAD(&cache->fci_entries_head);
diff --git a/drivers/staging/lustre/lustre/fld/fld_request.c b/drivers/staging/lustre/lustre/fld/fld_request.c
index c3b47f2346df..1e450bf95383 100644
--- a/drivers/staging/lustre/lustre/fld/fld_request.c
+++ b/drivers/staging/lustre/lustre/fld/fld_request.c
@@ -222,7 +222,7 @@ int fld_client_add_target(struct lu_client_fld *fld,
222 fld->lcf_name, name, tar->ft_idx); 222 fld->lcf_name, name, tar->ft_idx);
223 223
224 target = kzalloc(sizeof(*target), GFP_NOFS); 224 target = kzalloc(sizeof(*target), GFP_NOFS);
225 if (target == NULL) 225 if (!target)
226 return -ENOMEM; 226 return -ENOMEM;
227 227
228 spin_lock(&fld->lcf_lock); 228 spin_lock(&fld->lcf_lock);
diff --git a/drivers/staging/lustre/lustre/include/linux/lustre_compat25.h b/drivers/staging/lustre/lustre/include/linux/lustre_compat25.h
index 513c81f43d6e..6b14406b2920 100644
--- a/drivers/staging/lustre/lustre/include/linux/lustre_compat25.h
+++ b/drivers/staging/lustre/lustre/include/linux/lustre_compat25.h
@@ -64,98 +64,6 @@
64 64
65#define LTIME_S(time) (time.tv_sec) 65#define LTIME_S(time) (time.tv_sec)
66 66
67/* inode_dio_wait(i) use as-is for write lock */
68# define inode_dio_write_done(i) do {} while (0) /* for write unlock */
69# define inode_dio_read(i) atomic_inc(&(i)->i_dio_count)
70/* inode_dio_done(i) use as-is for read unlock */
71
72
73#ifndef FS_HAS_FIEMAP
74#define FS_HAS_FIEMAP (0)
75#endif
76
77#define ll_vfs_rmdir(dir, entry, mnt) vfs_rmdir(dir, entry)
78#define ll_vfs_mkdir(inode, dir, mnt, mode) vfs_mkdir(inode, dir, mode)
79#define ll_vfs_link(old, mnt, dir, new, mnt1) vfs_link(old, dir, new)
80#define ll_vfs_unlink(inode, entry, mnt) vfs_unlink(inode, entry)
81#define ll_vfs_mknod(dir, entry, mnt, mode, dev) \
82 vfs_mknod(dir, entry, mode, dev)
83#define ll_security_inode_unlink(dir, entry, mnt) \
84 security_inode_unlink(dir, entry)
85#define ll_vfs_rename(old, old_dir, mnt, new, new_dir, mnt1) \
86 vfs_rename(old, old_dir, new, new_dir, NULL, 0)
87
88#define cfs_bio_io_error(a, b) bio_io_error((a))
89#define cfs_bio_endio(a, b, c) bio_endio((a), (c))
90
91#define cfs_path_put(nd) path_put(&(nd)->path)
92
93
94#ifndef SLAB_DESTROY_BY_RCU
95#define SLAB_DESTROY_BY_RCU 0
96#endif
97
98
99
100static inline int
101ll_quota_on(struct super_block *sb, int off, int ver, char *name, int remount)
102{
103 int rc;
104
105 if (sb->s_qcop->quota_on) {
106 struct path path;
107
108 rc = kern_path(name, LOOKUP_FOLLOW, &path);
109 if (!rc)
110 return rc;
111 rc = sb->s_qcop->quota_on(sb, off, ver
112 , &path
113 );
114 path_put(&path);
115 return rc;
116 } else
117 return -ENOSYS;
118}
119
120static inline int ll_quota_off(struct super_block *sb, int off, int remount)
121{
122 if (sb->s_qcop->quota_off) {
123 return sb->s_qcop->quota_off(sb, off
124 );
125 } else
126 return -ENOSYS;
127}
128
129
130# define ll_vfs_dq_init dquot_initialize
131# define ll_vfs_dq_drop dquot_drop
132# define ll_vfs_dq_transfer dquot_transfer
133# define ll_vfs_dq_off(sb, remount) dquot_suspend(sb, -1)
134
135
136
137
138
139#define queue_max_phys_segments(rq) queue_max_segments(rq)
140#define queue_max_hw_segments(rq) queue_max_segments(rq)
141
142
143#define ll_d_hlist_node hlist_node
144#define ll_d_hlist_empty(list) hlist_empty(list)
145#define ll_d_hlist_entry(ptr, type, name) hlist_entry(ptr.first, type, name)
146#define ll_d_hlist_for_each(tmp, i_dentry) hlist_for_each(tmp, i_dentry)
147#define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
148 p = NULL; hlist_for_each_entry(dentry, i_dentry, alias)
149
150
151#define bio_hw_segments(q, bio) 0
152
153
154#define ll_pagevec_init(pv, cold) do {} while (0)
155#define ll_pagevec_add(pv, pg) (0)
156#define ll_pagevec_lru_add_file(pv) do {} while (0)
157
158
159#ifndef QUOTA_OK 67#ifndef QUOTA_OK
160# define QUOTA_OK 0 68# define QUOTA_OK 0
161#endif 69#endif
@@ -163,17 +71,6 @@ static inline int ll_quota_off(struct super_block *sb, int off, int remount)
163# define NO_QUOTA (-EDQUOT) 71# define NO_QUOTA (-EDQUOT)
164#endif 72#endif
165 73
166#ifndef SEEK_DATA
167#define SEEK_DATA 3 /* seek to the next data */
168#endif
169#ifndef SEEK_HOLE
170#define SEEK_HOLE 4 /* seek to the next hole */
171#endif
172
173#ifndef FMODE_UNSIGNED_OFFSET
174#define FMODE_UNSIGNED_OFFSET ((__force fmode_t)0x2000)
175#endif
176
177#if !defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_) && !defined(ext2_set_bit) 74#if !defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_) && !defined(ext2_set_bit)
178# define ext2_set_bit __test_and_set_bit_le 75# define ext2_set_bit __test_and_set_bit_le
179# define ext2_clear_bit __test_and_clear_bit_le 76# define ext2_clear_bit __test_and_clear_bit_le
@@ -182,20 +79,4 @@ static inline int ll_quota_off(struct super_block *sb, int off, int remount)
182# define ext2_find_next_zero_bit find_next_zero_bit_le 79# define ext2_find_next_zero_bit find_next_zero_bit_le
183#endif 80#endif
184 81
185#ifdef ATTR_TIMES_SET
186# define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
187#else
188# define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET)
189#endif
190
191
192#include <linux/version.h>
193#include <linux/fs.h>
194
195# define ll_umode_t umode_t
196
197#include <linux/dcache.h>
198
199# define ll_dirty_inode(inode, flag) (inode)->i_sb->s_op->dirty_inode((inode), flag)
200
201#endif /* _COMPAT25_H */ 82#endif /* _COMPAT25_H */
diff --git a/drivers/staging/lustre/lustre/include/linux/lustre_patchless_compat.h b/drivers/staging/lustre/lustre/include/linux/lustre_patchless_compat.h
index 14562788e4e0..ebe8d68ed813 100644
--- a/drivers/staging/lustre/lustre/include/linux/lustre_patchless_compat.h
+++ b/drivers/staging/lustre/lustre/include/linux/lustre_patchless_compat.h
@@ -60,18 +60,6 @@ truncate_complete_page(struct address_space *mapping, struct page *page)
60 ll_delete_from_page_cache(page); 60 ll_delete_from_page_cache(page);
61} 61}
62 62
63#ifdef ATTR_OPEN
64# define ATTR_FROM_OPEN ATTR_OPEN
65#else
66# ifndef ATTR_FROM_OPEN
67# define ATTR_FROM_OPEN 0
68# endif
69#endif /* ATTR_OPEN */
70
71#ifndef ATTR_RAW
72#define ATTR_RAW 0
73#endif
74
75#ifndef ATTR_CTIME_SET 63#ifndef ATTR_CTIME_SET
76/* 64/*
77 * set ATTR_CTIME_SET to a high value to avoid any risk of collision with other 65 * set ATTR_CTIME_SET to a high value to avoid any risk of collision with other
diff --git a/drivers/staging/lustre/lustre/include/lprocfs_status.h b/drivers/staging/lustre/lustre/include/lprocfs_status.h
index 8ede2a00ca4f..fd3c4df319c2 100644
--- a/drivers/staging/lustre/lustre/include/lprocfs_status.h
+++ b/drivers/staging/lustre/lustre/include/lprocfs_status.h
@@ -375,12 +375,11 @@ static inline void s2dhms(struct dhms *ts, time_t secs)
375#define JOBSTATS_PROCNAME_UID "procname_uid" 375#define JOBSTATS_PROCNAME_UID "procname_uid"
376#define JOBSTATS_NODELOCAL "nodelocal" 376#define JOBSTATS_NODELOCAL "nodelocal"
377 377
378extern int lprocfs_write_frac_helper(const char __user *buffer, 378int lprocfs_write_frac_helper(const char __user *buffer,
379 unsigned long count, int *val, int mult); 379 unsigned long count, int *val, int mult);
380extern int lprocfs_read_frac_helper(char *buffer, unsigned long count, 380int lprocfs_read_frac_helper(char *buffer, unsigned long count,
381 long val, int mult); 381 long val, int mult);
382extern int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, 382int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid);
383 unsigned int cpuid);
384/* 383/*
385 * \return value 384 * \return value
386 * < 0 : on error (only possible for opc as LPROCFS_GET_SMP_ID) 385 * < 0 : on error (only possible for opc as LPROCFS_GET_SMP_ID)
@@ -497,20 +496,18 @@ lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
497 * count itself to reside within a single cache line. 496 * count itself to reside within a single cache line.
498 */ 497 */
499 498
500extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx, 499void lprocfs_counter_add(struct lprocfs_stats *stats, int idx, long amount);
501 long amount); 500void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx, long amount);
502extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
503 long amount);
504 501
505#define lprocfs_counter_incr(stats, idx) \ 502#define lprocfs_counter_incr(stats, idx) \
506 lprocfs_counter_add(stats, idx, 1) 503 lprocfs_counter_add(stats, idx, 1)
507#define lprocfs_counter_decr(stats, idx) \ 504#define lprocfs_counter_decr(stats, idx) \
508 lprocfs_counter_sub(stats, idx, 1) 505 lprocfs_counter_sub(stats, idx, 1)
509 506
510extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc, 507__s64 lprocfs_read_helper(struct lprocfs_counter *lc,
511 struct lprocfs_counter_header *header, 508 struct lprocfs_counter_header *header,
512 enum lprocfs_stats_flags flags, 509 enum lprocfs_stats_flags flags,
513 enum lprocfs_fields_flags field); 510 enum lprocfs_fields_flags field);
514static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, 511static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats,
515 int idx, 512 int idx,
516 enum lprocfs_fields_flags field) 513 enum lprocfs_fields_flags field)
@@ -537,107 +534,103 @@ static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats,
537 534
538extern struct lprocfs_stats * 535extern struct lprocfs_stats *
539lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags); 536lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
540extern void lprocfs_clear_stats(struct lprocfs_stats *stats); 537void lprocfs_clear_stats(struct lprocfs_stats *stats);
541extern void lprocfs_free_stats(struct lprocfs_stats **stats); 538void lprocfs_free_stats(struct lprocfs_stats **stats);
542extern void lprocfs_init_ops_stats(int num_private_stats, 539void lprocfs_init_ops_stats(int num_private_stats, struct lprocfs_stats *stats);
543 struct lprocfs_stats *stats); 540void lprocfs_init_mps_stats(int num_private_stats, struct lprocfs_stats *stats);
544extern void lprocfs_init_mps_stats(int num_private_stats, 541void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
545 struct lprocfs_stats *stats); 542int lprocfs_alloc_obd_stats(struct obd_device *obddev,
546extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats); 543 unsigned int num_private_stats);
547extern int lprocfs_alloc_obd_stats(struct obd_device *obddev, 544int lprocfs_alloc_md_stats(struct obd_device *obddev,
548 unsigned int num_private_stats); 545 unsigned int num_private_stats);
549extern int lprocfs_alloc_md_stats(struct obd_device *obddev, 546void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
550 unsigned int num_private_stats); 547 unsigned conf, const char *name, const char *units);
551extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index, 548void lprocfs_free_obd_stats(struct obd_device *obddev);
552 unsigned conf, const char *name, 549void lprocfs_free_md_stats(struct obd_device *obddev);
553 const char *units);
554extern void lprocfs_free_obd_stats(struct obd_device *obddev);
555extern void lprocfs_free_md_stats(struct obd_device *obddev);
556struct obd_export; 550struct obd_export;
557extern int lprocfs_exp_cleanup(struct obd_export *exp); 551int lprocfs_exp_cleanup(struct obd_export *exp);
558extern struct dentry *ldebugfs_add_simple(struct dentry *root, 552struct dentry *ldebugfs_add_simple(struct dentry *root,
559 char *name, 553 char *name,
560 void *data, 554 void *data,
561 struct file_operations *fops); 555 struct file_operations *fops);
562extern struct dentry * 556struct dentry *
563ldebugfs_add_symlink(const char *name, struct dentry *parent, 557ldebugfs_add_symlink(const char *name, struct dentry *parent,
564 const char *format, ...); 558 const char *format, ...);
565 559
566extern int ldebugfs_register_stats(struct dentry *parent, 560int ldebugfs_register_stats(struct dentry *parent,
567 const char *name, 561 const char *name,
568 struct lprocfs_stats *stats); 562 struct lprocfs_stats *stats);
569 563
570/* lprocfs_status.c */ 564/* lprocfs_status.c */
571extern int ldebugfs_add_vars(struct dentry *parent, 565int ldebugfs_add_vars(struct dentry *parent,
572 struct lprocfs_vars *var, 566 struct lprocfs_vars *var,
573 void *data); 567 void *data);
574 568
575extern struct dentry *ldebugfs_register(const char *name, 569struct dentry *ldebugfs_register(const char *name,
576 struct dentry *parent, 570 struct dentry *parent,
577 struct lprocfs_vars *list, 571 struct lprocfs_vars *list,
578 void *data); 572 void *data);
579 573
580extern void ldebugfs_remove(struct dentry **entryp); 574void ldebugfs_remove(struct dentry **entryp);
581 575
582extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list, 576int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list,
583 struct attribute_group *attrs); 577 struct attribute_group *attrs);
584extern int lprocfs_obd_cleanup(struct obd_device *obd); 578int lprocfs_obd_cleanup(struct obd_device *obd);
585 579
586extern int ldebugfs_seq_create(struct dentry *parent, 580int ldebugfs_seq_create(struct dentry *parent,
587 const char *name, 581 const char *name,
588 umode_t mode, 582 umode_t mode,
589 const struct file_operations *seq_fops, 583 const struct file_operations *seq_fops,
590 void *data); 584 void *data);
591extern int ldebugfs_obd_seq_create(struct obd_device *dev, 585int ldebugfs_obd_seq_create(struct obd_device *dev,
592 const char *name, 586 const char *name,
593 umode_t mode, 587 umode_t mode,
594 const struct file_operations *seq_fops, 588 const struct file_operations *seq_fops,
595 void *data); 589 void *data);
596 590
597/* Generic callbacks */ 591/* Generic callbacks */
598 592
599extern int lprocfs_rd_u64(struct seq_file *m, void *data); 593int lprocfs_rd_u64(struct seq_file *m, void *data);
600extern int lprocfs_rd_atomic(struct seq_file *m, void *data); 594int lprocfs_rd_atomic(struct seq_file *m, void *data);
601extern int lprocfs_wr_atomic(struct file *file, const char __user *buffer, 595int lprocfs_wr_atomic(struct file *file, const char __user *buffer,
602 unsigned long count, void *data); 596 unsigned long count, void *data);
603extern int lprocfs_rd_uint(struct seq_file *m, void *data); 597int lprocfs_rd_uint(struct seq_file *m, void *data);
604extern int lprocfs_wr_uint(struct file *file, const char __user *buffer, 598int lprocfs_wr_uint(struct file *file, const char __user *buffer,
605 unsigned long count, void *data); 599 unsigned long count, void *data);
606extern int lprocfs_rd_name(struct seq_file *m, void *data); 600int lprocfs_rd_name(struct seq_file *m, void *data);
607extern int lprocfs_rd_server_uuid(struct seq_file *m, void *data); 601int lprocfs_rd_server_uuid(struct seq_file *m, void *data);
608extern int lprocfs_rd_conn_uuid(struct seq_file *m, void *data); 602int lprocfs_rd_conn_uuid(struct seq_file *m, void *data);
609extern int lprocfs_rd_import(struct seq_file *m, void *data); 603int lprocfs_rd_import(struct seq_file *m, void *data);
610extern int lprocfs_rd_state(struct seq_file *m, void *data); 604int lprocfs_rd_state(struct seq_file *m, void *data);
611extern int lprocfs_rd_connect_flags(struct seq_file *m, void *data); 605int lprocfs_rd_connect_flags(struct seq_file *m, void *data);
612 606
613struct adaptive_timeout; 607struct adaptive_timeout;
614extern int lprocfs_at_hist_helper(struct seq_file *m, 608int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at);
615 struct adaptive_timeout *at); 609int lprocfs_rd_timeouts(struct seq_file *m, void *data);
616extern int lprocfs_rd_timeouts(struct seq_file *m, void *data); 610int lprocfs_wr_timeouts(struct file *file, const char __user *buffer,
617extern int lprocfs_wr_timeouts(struct file *file, const char __user *buffer, 611 unsigned long count, void *data);
618 unsigned long count, void *data); 612int lprocfs_wr_evict_client(struct file *file, const char __user *buffer,
619extern int lprocfs_wr_evict_client(struct file *file, const char __user *buffer,
620 size_t count, loff_t *off); 613 size_t count, loff_t *off);
621extern int lprocfs_wr_ping(struct file *file, const char __user *buffer, 614int lprocfs_wr_ping(struct file *file, const char __user *buffer,
622 size_t count, loff_t *off); 615 size_t count, loff_t *off);
623extern int lprocfs_wr_import(struct file *file, const char __user *buffer, 616int lprocfs_wr_import(struct file *file, const char __user *buffer,
624 size_t count, loff_t *off); 617 size_t count, loff_t *off);
625extern int lprocfs_rd_pinger_recov(struct seq_file *m, void *n); 618int lprocfs_rd_pinger_recov(struct seq_file *m, void *n);
626extern int lprocfs_wr_pinger_recov(struct file *file, const char __user *buffer, 619int lprocfs_wr_pinger_recov(struct file *file, const char __user *buffer,
627 size_t count, loff_t *off); 620 size_t count, loff_t *off);
628 621
629/* Statfs helpers */ 622/* Statfs helpers */
630 623
631extern int lprocfs_write_helper(const char __user *buffer, unsigned long count, 624int lprocfs_write_helper(const char __user *buffer, unsigned long count,
632 int *val); 625 int *val);
633extern int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult); 626int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult);
634extern int lprocfs_write_u64_helper(const char __user *buffer, 627int lprocfs_write_u64_helper(const char __user *buffer,
635 unsigned long count, __u64 *val); 628 unsigned long count, __u64 *val);
636extern int lprocfs_write_frac_u64_helper(const char *buffer, 629int lprocfs_write_frac_u64_helper(const char *buffer,
637 unsigned long count, 630 unsigned long count,
638 __u64 *val, int mult); 631 __u64 *val, int mult);
639extern char *lprocfs_find_named_value(const char *buffer, const char *name, 632char *lprocfs_find_named_value(const char *buffer, const char *name,
640 size_t *count); 633 size_t *count);
641void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value); 634void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
642void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value); 635void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
643void lprocfs_oh_clear(struct obd_histogram *oh); 636void lprocfs_oh_clear(struct obd_histogram *oh);
@@ -646,8 +639,8 @@ unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
646void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx, 639void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
647 struct lprocfs_counter *cnt); 640 struct lprocfs_counter *cnt);
648 641
649extern int lprocfs_single_release(struct inode *, struct file *); 642int lprocfs_single_release(struct inode *, struct file *);
650extern int lprocfs_seq_release(struct inode *, struct file *); 643int lprocfs_seq_release(struct inode *, struct file *);
651 644
652/* You must use these macros when you want to refer to 645/* You must use these macros when you want to refer to
653 * the import in a client obd_device for a lprocfs entry */ 646 * the import in a client obd_device for a lprocfs entry */
@@ -746,7 +739,7 @@ extern const struct sysfs_ops lustre_sysfs_ops;
746 739
747/* lproc_ptlrpc.c */ 740/* lproc_ptlrpc.c */
748struct ptlrpc_request; 741struct ptlrpc_request;
749extern void target_print_req(void *seq_file, struct ptlrpc_request *req); 742void target_print_req(void *seq_file, struct ptlrpc_request *req);
750 743
751/* lproc_status.c */ 744/* lproc_status.c */
752int lprocfs_obd_rd_max_pages_per_rpc(struct seq_file *m, void *data); 745int lprocfs_obd_rd_max_pages_per_rpc(struct seq_file *m, void *data);
@@ -754,62 +747,62 @@ int lprocfs_obd_wr_max_pages_per_rpc(struct file *file, const char *buffer,
754 size_t count, loff_t *off); 747 size_t count, loff_t *off);
755 748
756/* all quota proc functions */ 749/* all quota proc functions */
757extern int lprocfs_quota_rd_bunit(char *page, char **start, 750int lprocfs_quota_rd_bunit(char *page, char **start,
758 loff_t off, int count, 751 loff_t off, int count,
759 int *eof, void *data); 752 int *eof, void *data);
760extern int lprocfs_quota_wr_bunit(struct file *file, const char *buffer, 753int lprocfs_quota_wr_bunit(struct file *file, const char *buffer,
761 unsigned long count, void *data); 754 unsigned long count, void *data);
762extern int lprocfs_quota_rd_btune(char *page, char **start, 755int lprocfs_quota_rd_btune(char *page, char **start,
763 loff_t off, int count, 756 loff_t off, int count,
764 int *eof, void *data); 757 int *eof, void *data);
765extern int lprocfs_quota_wr_btune(struct file *file, const char *buffer, 758int lprocfs_quota_wr_btune(struct file *file, const char *buffer,
766 unsigned long count, void *data); 759 unsigned long count, void *data);
767extern int lprocfs_quota_rd_iunit(char *page, char **start, 760int lprocfs_quota_rd_iunit(char *page, char **start,
768 loff_t off, int count, 761 loff_t off, int count,
769 int *eof, void *data); 762 int *eof, void *data);
770extern int lprocfs_quota_wr_iunit(struct file *file, const char *buffer, 763int lprocfs_quota_wr_iunit(struct file *file, const char *buffer,
771 unsigned long count, void *data); 764 unsigned long count, void *data);
772extern int lprocfs_quota_rd_itune(char *page, char **start, 765int lprocfs_quota_rd_itune(char *page, char **start,
773 loff_t off, int count, 766 loff_t off, int count,
774 int *eof, void *data); 767 int *eof, void *data);
775extern int lprocfs_quota_wr_itune(struct file *file, const char *buffer, 768int lprocfs_quota_wr_itune(struct file *file, const char *buffer,
776 unsigned long count, void *data); 769 unsigned long count, void *data);
777extern int lprocfs_quota_rd_type(char *page, char **start, loff_t off, int count, 770int lprocfs_quota_rd_type(char *page, char **start, loff_t off, int count,
778 int *eof, void *data); 771 int *eof, void *data);
779extern int lprocfs_quota_wr_type(struct file *file, const char *buffer, 772int lprocfs_quota_wr_type(struct file *file, const char *buffer,
780 unsigned long count, void *data); 773 unsigned long count, void *data);
781extern int lprocfs_quota_rd_switch_seconds(char *page, char **start, loff_t off, 774int lprocfs_quota_rd_switch_seconds(char *page, char **start, loff_t off,
782 int count, int *eof, void *data); 775 int count, int *eof, void *data);
783extern int lprocfs_quota_wr_switch_seconds(struct file *file, 776int lprocfs_quota_wr_switch_seconds(struct file *file,
784 const char *buffer, 777 const char *buffer,
785 unsigned long count, void *data); 778 unsigned long count, void *data);
786extern int lprocfs_quota_rd_sync_blk(char *page, char **start, loff_t off, 779int lprocfs_quota_rd_sync_blk(char *page, char **start, loff_t off,
780 int count, int *eof, void *data);
781int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
782 unsigned long count, void *data);
783int lprocfs_quota_rd_switch_qs(char *page, char **start, loff_t off,
784 int count, int *eof, void *data);
785int lprocfs_quota_wr_switch_qs(struct file *file,
786 const char *buffer, unsigned long count,
787 void *data);
788int lprocfs_quota_rd_boundary_factor(char *page, char **start, loff_t off,
787 int count, int *eof, void *data); 789 int count, int *eof, void *data);
788extern int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer, 790int lprocfs_quota_wr_boundary_factor(struct file *file,
789 unsigned long count, void *data); 791 const char *buffer, unsigned long count,
790extern int lprocfs_quota_rd_switch_qs(char *page, char **start, loff_t off, 792 void *data);
791 int count, int *eof, void *data); 793int lprocfs_quota_rd_least_bunit(char *page, char **start, loff_t off,
792extern int lprocfs_quota_wr_switch_qs(struct file *file, 794 int count, int *eof, void *data);
793 const char *buffer, 795int lprocfs_quota_wr_least_bunit(struct file *file,
794 unsigned long count, void *data); 796 const char *buffer, unsigned long count,
795extern int lprocfs_quota_rd_boundary_factor(char *page, char **start, loff_t off, 797 void *data);
796 int count, int *eof, void *data); 798int lprocfs_quota_rd_least_iunit(char *page, char **start, loff_t off,
797extern int lprocfs_quota_wr_boundary_factor(struct file *file, 799 int count, int *eof, void *data);
798 const char *buffer, 800int lprocfs_quota_wr_least_iunit(struct file *file,
799 unsigned long count, void *data); 801 const char *buffer, unsigned long count,
800extern int lprocfs_quota_rd_least_bunit(char *page, char **start, loff_t off, 802 void *data);
801 int count, int *eof, void *data); 803int lprocfs_quota_rd_qs_factor(char *page, char **start, loff_t off,
802extern int lprocfs_quota_wr_least_bunit(struct file *file, 804 int count, int *eof, void *data);
803 const char *buffer, 805int lprocfs_quota_wr_qs_factor(struct file *file,
804 unsigned long count, void *data); 806 const char *buffer, unsigned long count,
805extern int lprocfs_quota_rd_least_iunit(char *page, char **start, loff_t off, 807 void *data);
806 int count, int *eof, void *data);
807extern int lprocfs_quota_wr_least_iunit(struct file *file,
808 const char *buffer,
809 unsigned long count, void *data);
810extern int lprocfs_quota_rd_qs_factor(char *page, char **start, loff_t off,
811 int count, int *eof, void *data);
812extern int lprocfs_quota_wr_qs_factor(struct file *file,
813 const char *buffer,
814 unsigned long count, void *data);
815#endif /* LPROCFS_SNMP_H */ 808#endif /* LPROCFS_SNMP_H */
diff --git a/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h b/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h
index 4d72d6ed26b0..ac78dbc38b9f 100644
--- a/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h
+++ b/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h
@@ -747,7 +747,7 @@ static inline ino_t lu_igif_ino(const struct lu_fid *fid)
747 return fid_seq(fid); 747 return fid_seq(fid);
748} 748}
749 749
750extern void lustre_swab_ost_id(struct ost_id *oid); 750void lustre_swab_ost_id(struct ost_id *oid);
751 751
752/** 752/**
753 * Get inode generation from a igif. 753 * Get inode generation from a igif.
@@ -814,8 +814,8 @@ static inline int fid_is_zero(const struct lu_fid *fid)
814 return fid_seq(fid) == 0 && fid_oid(fid) == 0; 814 return fid_seq(fid) == 0 && fid_oid(fid) == 0;
815} 815}
816 816
817extern void lustre_swab_lu_fid(struct lu_fid *fid); 817void lustre_swab_lu_fid(struct lu_fid *fid);
818extern void lustre_swab_lu_seq_range(struct lu_seq_range *range); 818void lustre_swab_lu_seq_range(struct lu_seq_range *range);
819 819
820static inline int lu_fid_eq(const struct lu_fid *f0, const struct lu_fid *f1) 820static inline int lu_fid_eq(const struct lu_fid *f0, const struct lu_fid *f1)
821{ 821{
@@ -1131,7 +1131,7 @@ struct ptlrpc_body_v2 {
1131 __u64 pb_padding[4]; 1131 __u64 pb_padding[4];
1132}; 1132};
1133 1133
1134extern void lustre_swab_ptlrpc_body(struct ptlrpc_body *pb); 1134void lustre_swab_ptlrpc_body(struct ptlrpc_body *pb);
1135 1135
1136/* message body offset for lustre_msg_v2 */ 1136/* message body offset for lustre_msg_v2 */
1137/* ptlrpc body offset in all request/reply messages */ 1137/* ptlrpc body offset in all request/reply messages */
@@ -1395,7 +1395,7 @@ struct obd_connect_data {
1395 * reserve the flag for future use. */ 1395 * reserve the flag for future use. */
1396 1396
1397 1397
1398extern void lustre_swab_connect(struct obd_connect_data *ocd); 1398void lustre_swab_connect(struct obd_connect_data *ocd);
1399 1399
1400/* 1400/*
1401 * Supported checksum algorithms. Up to 32 checksum types are supported. 1401 * Supported checksum algorithms. Up to 32 checksum types are supported.
@@ -1737,10 +1737,10 @@ struct hsm_state_set {
1737 __u64 hss_clearmask; 1737 __u64 hss_clearmask;
1738}; 1738};
1739 1739
1740extern void lustre_swab_hsm_user_state(struct hsm_user_state *hus); 1740void lustre_swab_hsm_user_state(struct hsm_user_state *hus);
1741extern void lustre_swab_hsm_state_set(struct hsm_state_set *hss); 1741void lustre_swab_hsm_state_set(struct hsm_state_set *hss);
1742 1742
1743extern void lustre_swab_obd_statfs (struct obd_statfs *os); 1743void lustre_swab_obd_statfs(struct obd_statfs *os);
1744 1744
1745/* ost_body.data values for OST_BRW */ 1745/* ost_body.data values for OST_BRW */
1746 1746
@@ -1780,7 +1780,7 @@ struct obd_ioobj {
1780#define ioobj_max_brw_set(ioo, num) \ 1780#define ioobj_max_brw_set(ioo, num) \
1781do { (ioo)->ioo_max_brw = ((num) - 1) << IOOBJ_MAX_BRW_BITS; } while (0) 1781do { (ioo)->ioo_max_brw = ((num) - 1) << IOOBJ_MAX_BRW_BITS; } while (0)
1782 1782
1783extern void lustre_swab_obd_ioobj (struct obd_ioobj *ioo); 1783void lustre_swab_obd_ioobj(struct obd_ioobj *ioo);
1784 1784
1785/* multiple of 8 bytes => can array */ 1785/* multiple of 8 bytes => can array */
1786struct niobuf_remote { 1786struct niobuf_remote {
@@ -1789,7 +1789,7 @@ struct niobuf_remote {
1789 __u32 flags; 1789 __u32 flags;
1790}; 1790};
1791 1791
1792extern void lustre_swab_niobuf_remote (struct niobuf_remote *nbr); 1792void lustre_swab_niobuf_remote(struct niobuf_remote *nbr);
1793 1793
1794/* lock value block communicated between the filter and llite */ 1794/* lock value block communicated between the filter and llite */
1795 1795
@@ -1811,7 +1811,7 @@ struct ost_lvb_v1 {
1811 __u64 lvb_blocks; 1811 __u64 lvb_blocks;
1812}; 1812};
1813 1813
1814extern void lustre_swab_ost_lvb_v1(struct ost_lvb_v1 *lvb); 1814void lustre_swab_ost_lvb_v1(struct ost_lvb_v1 *lvb);
1815 1815
1816struct ost_lvb { 1816struct ost_lvb {
1817 __u64 lvb_size; 1817 __u64 lvb_size;
@@ -1825,7 +1825,7 @@ struct ost_lvb {
1825 __u32 lvb_padding; 1825 __u32 lvb_padding;
1826}; 1826};
1827 1827
1828extern void lustre_swab_ost_lvb(struct ost_lvb *lvb); 1828void lustre_swab_ost_lvb(struct ost_lvb *lvb);
1829 1829
1830/* 1830/*
1831 * lquota data structures 1831 * lquota data structures
@@ -1864,7 +1864,7 @@ struct obd_quotactl {
1864 struct obd_dqblk qc_dqblk; 1864 struct obd_dqblk qc_dqblk;
1865}; 1865};
1866 1866
1867extern void lustre_swab_obd_quotactl(struct obd_quotactl *q); 1867void lustre_swab_obd_quotactl(struct obd_quotactl *q);
1868 1868
1869#define Q_QUOTACHECK 0x800100 /* deprecated as of 2.4 */ 1869#define Q_QUOTACHECK 0x800100 /* deprecated as of 2.4 */
1870#define Q_INITQUOTA 0x800101 /* deprecated as of 2.4 */ 1870#define Q_INITQUOTA 0x800101 /* deprecated as of 2.4 */
@@ -1913,7 +1913,7 @@ struct quota_body {
1913#define QUOTA_DQACQ_FL_REL 0x4 /* release quota */ 1913#define QUOTA_DQACQ_FL_REL 0x4 /* release quota */
1914#define QUOTA_DQACQ_FL_REPORT 0x8 /* report usage */ 1914#define QUOTA_DQACQ_FL_REPORT 0x8 /* report usage */
1915 1915
1916extern void lustre_swab_quota_body(struct quota_body *b); 1916void lustre_swab_quota_body(struct quota_body *b);
1917 1917
1918/* Quota types currently supported */ 1918/* Quota types currently supported */
1919enum { 1919enum {
@@ -1993,7 +1993,7 @@ struct lquota_lvb {
1993 __u64 lvb_pad1; 1993 __u64 lvb_pad1;
1994}; 1994};
1995 1995
1996extern void lustre_swab_lquota_lvb(struct lquota_lvb *lvb); 1996void lustre_swab_lquota_lvb(struct lquota_lvb *lvb);
1997 1997
1998/* LVB used with global quota lock */ 1998/* LVB used with global quota lock */
1999#define lvb_glb_ver lvb_id_may_rel /* current version of the global index */ 1999#define lvb_glb_ver lvb_id_may_rel /* current version of the global index */
@@ -2072,7 +2072,7 @@ typedef enum {
2072 REINT_MAX 2072 REINT_MAX
2073} mds_reint_t, mdt_reint_t; 2073} mds_reint_t, mdt_reint_t;
2074 2074
2075extern void lustre_swab_generic_32s (__u32 *val); 2075void lustre_swab_generic_32s(__u32 *val);
2076 2076
2077/* the disposition of the intent outlines what was executed */ 2077/* the disposition of the intent outlines what was executed */
2078#define DISP_IT_EXECD 0x00000001 2078#define DISP_IT_EXECD 0x00000001
@@ -2112,7 +2112,7 @@ extern void lustre_swab_generic_32s (__u32 *val);
2112/* This FULL lock is useful to take on unlink sort of operations */ 2112/* This FULL lock is useful to take on unlink sort of operations */
2113#define MDS_INODELOCK_FULL ((1<<(MDS_INODELOCK_MAXSHIFT+1))-1) 2113#define MDS_INODELOCK_FULL ((1<<(MDS_INODELOCK_MAXSHIFT+1))-1)
2114 2114
2115extern void lustre_swab_ll_fid (struct ll_fid *fid); 2115void lustre_swab_ll_fid(struct ll_fid *fid);
2116 2116
2117/* NOTE: until Lustre 1.8.7/2.1.1 the fid_ver() was packed into name[2], 2117/* NOTE: until Lustre 1.8.7/2.1.1 the fid_ver() was packed into name[2],
2118 * but was moved into name[1] along with the OID to avoid consuming the 2118 * but was moved into name[1] along with the OID to avoid consuming the
@@ -2231,7 +2231,7 @@ struct mdt_body {
2231 __u64 padding_10; 2231 __u64 padding_10;
2232}; /* 216 */ 2232}; /* 216 */
2233 2233
2234extern void lustre_swab_mdt_body (struct mdt_body *b); 2234void lustre_swab_mdt_body(struct mdt_body *b);
2235 2235
2236struct mdt_ioepoch { 2236struct mdt_ioepoch {
2237 struct lustre_handle handle; 2237 struct lustre_handle handle;
@@ -2240,7 +2240,7 @@ struct mdt_ioepoch {
2240 __u32 padding; 2240 __u32 padding;
2241}; 2241};
2242 2242
2243extern void lustre_swab_mdt_ioepoch (struct mdt_ioepoch *b); 2243void lustre_swab_mdt_ioepoch(struct mdt_ioepoch *b);
2244 2244
2245/* permissions for md_perm.mp_perm */ 2245/* permissions for md_perm.mp_perm */
2246enum { 2246enum {
@@ -2264,7 +2264,7 @@ struct mdt_remote_perm {
2264 __u32 rp_padding; 2264 __u32 rp_padding;
2265}; 2265};
2266 2266
2267extern void lustre_swab_mdt_remote_perm(struct mdt_remote_perm *p); 2267void lustre_swab_mdt_remote_perm(struct mdt_remote_perm *p);
2268 2268
2269struct mdt_rec_setattr { 2269struct mdt_rec_setattr {
2270 __u32 sa_opcode; 2270 __u32 sa_opcode;
@@ -2294,7 +2294,7 @@ struct mdt_rec_setattr {
2294 __u32 sa_padding_5; 2294 __u32 sa_padding_5;
2295}; 2295};
2296 2296
2297extern void lustre_swab_mdt_rec_setattr (struct mdt_rec_setattr *sa); 2297void lustre_swab_mdt_rec_setattr(struct mdt_rec_setattr *sa);
2298 2298
2299/* 2299/*
2300 * Attribute flags used in mdt_rec_setattr::sa_valid. 2300 * Attribute flags used in mdt_rec_setattr::sa_valid.
@@ -2584,7 +2584,7 @@ struct mdt_rec_reint {
2584 __u32 rr_padding_4; /* also fix lustre_swab_mdt_rec_reint */ 2584 __u32 rr_padding_4; /* also fix lustre_swab_mdt_rec_reint */
2585}; 2585};
2586 2586
2587extern void lustre_swab_mdt_rec_reint(struct mdt_rec_reint *rr); 2587void lustre_swab_mdt_rec_reint(struct mdt_rec_reint *rr);
2588 2588
2589struct lmv_desc { 2589struct lmv_desc {
2590 __u32 ld_tgt_count; /* how many MDS's */ 2590 __u32 ld_tgt_count; /* how many MDS's */
@@ -2600,7 +2600,7 @@ struct lmv_desc {
2600 struct obd_uuid ld_uuid; 2600 struct obd_uuid ld_uuid;
2601}; 2601};
2602 2602
2603extern void lustre_swab_lmv_desc (struct lmv_desc *ld); 2603void lustre_swab_lmv_desc(struct lmv_desc *ld);
2604 2604
2605/* TODO: lmv_stripe_md should contain mds capabilities for all slave fids */ 2605/* TODO: lmv_stripe_md should contain mds capabilities for all slave fids */
2606struct lmv_stripe_md { 2606struct lmv_stripe_md {
@@ -2612,7 +2612,7 @@ struct lmv_stripe_md {
2612 struct lu_fid mea_ids[0]; 2612 struct lu_fid mea_ids[0];
2613}; 2613};
2614 2614
2615extern void lustre_swab_lmv_stripe_md(struct lmv_stripe_md *mea); 2615void lustre_swab_lmv_stripe_md(struct lmv_stripe_md *mea);
2616 2616
2617/* lmv structures */ 2617/* lmv structures */
2618#define MEA_MAGIC_LAST_CHAR 0xb2221ca1 2618#define MEA_MAGIC_LAST_CHAR 0xb2221ca1
@@ -2670,7 +2670,7 @@ struct lov_desc {
2670 2670
2671#define ld_magic ld_active_tgt_count /* for swabbing from llogs */ 2671#define ld_magic ld_active_tgt_count /* for swabbing from llogs */
2672 2672
2673extern void lustre_swab_lov_desc (struct lov_desc *ld); 2673void lustre_swab_lov_desc(struct lov_desc *ld);
2674 2674
2675/* 2675/*
2676 * LDLM requests: 2676 * LDLM requests:
@@ -2697,7 +2697,7 @@ struct ldlm_res_id {
2697#define PLDLMRES(res) (res)->lr_name.name[0], (res)->lr_name.name[1], \ 2697#define PLDLMRES(res) (res)->lr_name.name[0], (res)->lr_name.name[1], \
2698 (res)->lr_name.name[2], (res)->lr_name.name[3] 2698 (res)->lr_name.name[2], (res)->lr_name.name[3]
2699 2699
2700extern void lustre_swab_ldlm_res_id (struct ldlm_res_id *id); 2700void lustre_swab_ldlm_res_id(struct ldlm_res_id *id);
2701 2701
2702static inline int ldlm_res_eq(const struct ldlm_res_id *res0, 2702static inline int ldlm_res_eq(const struct ldlm_res_id *res0,
2703 const struct ldlm_res_id *res1) 2703 const struct ldlm_res_id *res1)
@@ -2774,19 +2774,19 @@ typedef union {
2774 struct ldlm_inodebits l_inodebits; 2774 struct ldlm_inodebits l_inodebits;
2775} ldlm_wire_policy_data_t; 2775} ldlm_wire_policy_data_t;
2776 2776
2777extern void lustre_swab_ldlm_policy_data (ldlm_wire_policy_data_t *d); 2777void lustre_swab_ldlm_policy_data(ldlm_wire_policy_data_t *d);
2778 2778
2779union ldlm_gl_desc { 2779union ldlm_gl_desc {
2780 struct ldlm_gl_lquota_desc lquota_desc; 2780 struct ldlm_gl_lquota_desc lquota_desc;
2781}; 2781};
2782 2782
2783extern void lustre_swab_gl_desc(union ldlm_gl_desc *); 2783void lustre_swab_gl_desc(union ldlm_gl_desc *);
2784 2784
2785struct ldlm_intent { 2785struct ldlm_intent {
2786 __u64 opc; 2786 __u64 opc;
2787}; 2787};
2788 2788
2789extern void lustre_swab_ldlm_intent (struct ldlm_intent *i); 2789void lustre_swab_ldlm_intent(struct ldlm_intent *i);
2790 2790
2791struct ldlm_resource_desc { 2791struct ldlm_resource_desc {
2792 ldlm_type_t lr_type; 2792 ldlm_type_t lr_type;
@@ -2794,7 +2794,7 @@ struct ldlm_resource_desc {
2794 struct ldlm_res_id lr_name; 2794 struct ldlm_res_id lr_name;
2795}; 2795};
2796 2796
2797extern void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r); 2797void lustre_swab_ldlm_resource_desc(struct ldlm_resource_desc *r);
2798 2798
2799struct ldlm_lock_desc { 2799struct ldlm_lock_desc {
2800 struct ldlm_resource_desc l_resource; 2800 struct ldlm_resource_desc l_resource;
@@ -2803,7 +2803,7 @@ struct ldlm_lock_desc {
2803 ldlm_wire_policy_data_t l_policy_data; 2803 ldlm_wire_policy_data_t l_policy_data;
2804}; 2804};
2805 2805
2806extern void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l); 2806void lustre_swab_ldlm_lock_desc(struct ldlm_lock_desc *l);
2807 2807
2808#define LDLM_LOCKREQ_HANDLES 2 2808#define LDLM_LOCKREQ_HANDLES 2
2809#define LDLM_ENQUEUE_CANCEL_OFF 1 2809#define LDLM_ENQUEUE_CANCEL_OFF 1
@@ -2815,7 +2815,7 @@ struct ldlm_request {
2815 struct lustre_handle lock_handle[LDLM_LOCKREQ_HANDLES]; 2815 struct lustre_handle lock_handle[LDLM_LOCKREQ_HANDLES];
2816}; 2816};
2817 2817
2818extern void lustre_swab_ldlm_request (struct ldlm_request *rq); 2818void lustre_swab_ldlm_request(struct ldlm_request *rq);
2819 2819
2820/* If LDLM_ENQUEUE, 1 slot is already occupied, 1 is available. 2820/* If LDLM_ENQUEUE, 1 slot is already occupied, 1 is available.
2821 * Otherwise, 2 are available. */ 2821 * Otherwise, 2 are available. */
@@ -2837,7 +2837,7 @@ struct ldlm_reply {
2837 __u64 lock_policy_res2; 2837 __u64 lock_policy_res2;
2838}; 2838};
2839 2839
2840extern void lustre_swab_ldlm_reply (struct ldlm_reply *r); 2840void lustre_swab_ldlm_reply(struct ldlm_reply *r);
2841 2841
2842#define ldlm_flags_to_wire(flags) ((__u32)(flags)) 2842#define ldlm_flags_to_wire(flags) ((__u32)(flags))
2843#define ldlm_flags_from_wire(flags) ((__u64)(flags)) 2843#define ldlm_flags_from_wire(flags) ((__u64)(flags))
@@ -2881,7 +2881,8 @@ struct mgs_target_info {
2881 __u64 mti_nids[MTI_NIDS_MAX]; /* host nids (lnet_nid_t)*/ 2881 __u64 mti_nids[MTI_NIDS_MAX]; /* host nids (lnet_nid_t)*/
2882 char mti_params[MTI_PARAM_MAXLEN]; 2882 char mti_params[MTI_PARAM_MAXLEN];
2883}; 2883};
2884extern void lustre_swab_mgs_target_info(struct mgs_target_info *oinfo); 2884
2885void lustre_swab_mgs_target_info(struct mgs_target_info *oinfo);
2885 2886
2886struct mgs_nidtbl_entry { 2887struct mgs_nidtbl_entry {
2887 __u64 mne_version; /* table version of this entry */ 2888 __u64 mne_version; /* table version of this entry */
@@ -2896,7 +2897,8 @@ struct mgs_nidtbl_entry {
2896 lnet_nid_t nids[0]; /* variable size buffer for NIDs. */ 2897 lnet_nid_t nids[0]; /* variable size buffer for NIDs. */
2897 } u; 2898 } u;
2898}; 2899};
2899extern void lustre_swab_mgs_nidtbl_entry(struct mgs_nidtbl_entry *oinfo); 2900
2901void lustre_swab_mgs_nidtbl_entry(struct mgs_nidtbl_entry *oinfo);
2900 2902
2901struct mgs_config_body { 2903struct mgs_config_body {
2902 char mcb_name[MTI_NAME_MAXLEN]; /* logname */ 2904 char mcb_name[MTI_NAME_MAXLEN]; /* logname */
@@ -2906,13 +2908,15 @@ struct mgs_config_body {
2906 __u8 mcb_bits; /* bits unit size of config log */ 2908 __u8 mcb_bits; /* bits unit size of config log */
2907 __u32 mcb_units; /* # of units for bulk transfer */ 2909 __u32 mcb_units; /* # of units for bulk transfer */
2908}; 2910};
2909extern void lustre_swab_mgs_config_body(struct mgs_config_body *body); 2911
2912void lustre_swab_mgs_config_body(struct mgs_config_body *body);
2910 2913
2911struct mgs_config_res { 2914struct mgs_config_res {
2912 __u64 mcr_offset; /* index of last config log */ 2915 __u64 mcr_offset; /* index of last config log */
2913 __u64 mcr_size; /* size of the log */ 2916 __u64 mcr_size; /* size of the log */
2914}; 2917};
2915extern void lustre_swab_mgs_config_res(struct mgs_config_res *body); 2918
2919void lustre_swab_mgs_config_res(struct mgs_config_res *body);
2916 2920
2917/* Config marker flags (in config log) */ 2921/* Config marker flags (in config log) */
2918#define CM_START 0x01 2922#define CM_START 0x01
@@ -2933,8 +2937,7 @@ struct cfg_marker {
2933 char cm_comment[MTI_NAME_MAXLEN]; 2937 char cm_comment[MTI_NAME_MAXLEN];
2934}; 2938};
2935 2939
2936extern void lustre_swab_cfg_marker(struct cfg_marker *marker, 2940void lustre_swab_cfg_marker(struct cfg_marker *marker, int swab, int size);
2937 int swab, int size);
2938 2941
2939/* 2942/*
2940 * Opcodes for multiple servers. 2943 * Opcodes for multiple servers.
@@ -3334,7 +3337,7 @@ static inline void lustre_get_wire_obdo(struct obd_connect_data *ocd,
3334 } 3337 }
3335} 3338}
3336 3339
3337extern void lustre_swab_obdo (struct obdo *o); 3340void lustre_swab_obdo(struct obdo *o);
3338 3341
3339/* request structure for OST's */ 3342/* request structure for OST's */
3340struct ost_body { 3343struct ost_body {
@@ -3348,25 +3351,25 @@ struct ll_fiemap_info_key {
3348 struct ll_user_fiemap fiemap; 3351 struct ll_user_fiemap fiemap;
3349}; 3352};
3350 3353
3351extern void lustre_swab_ost_body (struct ost_body *b); 3354void lustre_swab_ost_body(struct ost_body *b);
3352extern void lustre_swab_ost_last_id(__u64 *id); 3355void lustre_swab_ost_last_id(__u64 *id);
3353extern void lustre_swab_fiemap(struct ll_user_fiemap *fiemap); 3356void lustre_swab_fiemap(struct ll_user_fiemap *fiemap);
3354 3357
3355extern void lustre_swab_lov_user_md_v1(struct lov_user_md_v1 *lum); 3358void lustre_swab_lov_user_md_v1(struct lov_user_md_v1 *lum);
3356extern void lustre_swab_lov_user_md_v3(struct lov_user_md_v3 *lum); 3359void lustre_swab_lov_user_md_v3(struct lov_user_md_v3 *lum);
3357extern void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod, 3360void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
3358 int stripe_count); 3361 int stripe_count);
3359extern void lustre_swab_lov_mds_md(struct lov_mds_md *lmm); 3362void lustre_swab_lov_mds_md(struct lov_mds_md *lmm);
3360 3363
3361/* llog_swab.c */ 3364/* llog_swab.c */
3362extern void lustre_swab_llogd_body (struct llogd_body *d); 3365void lustre_swab_llogd_body(struct llogd_body *d);
3363extern void lustre_swab_llog_hdr (struct llog_log_hdr *h); 3366void lustre_swab_llog_hdr(struct llog_log_hdr *h);
3364extern void lustre_swab_llogd_conn_body (struct llogd_conn_body *d); 3367void lustre_swab_llogd_conn_body(struct llogd_conn_body *d);
3365extern void lustre_swab_llog_rec(struct llog_rec_hdr *rec); 3368void lustre_swab_llog_rec(struct llog_rec_hdr *rec);
3366extern void lustre_swab_llog_id(struct llog_logid *lid); 3369void lustre_swab_llog_id(struct llog_logid *lid);
3367 3370
3368struct lustre_cfg; 3371struct lustre_cfg;
3369extern void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg); 3372void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg);
3370 3373
3371/* Functions for dumping PTLRPC fields */ 3374/* Functions for dumping PTLRPC fields */
3372void dump_rniobuf(struct niobuf_remote *rnb); 3375void dump_rniobuf(struct niobuf_remote *rnb);
@@ -3418,7 +3421,8 @@ struct idx_info {
3418 __u64 ii_pad2; 3421 __u64 ii_pad2;
3419 __u64 ii_pad3; 3422 __u64 ii_pad3;
3420}; 3423};
3421extern void lustre_swab_idx_info(struct idx_info *ii); 3424
3425void lustre_swab_idx_info(struct idx_info *ii);
3422 3426
3423#define II_END_OFF MDS_DIR_END_OFF /* all entries have been read */ 3427#define II_END_OFF MDS_DIR_END_OFF /* all entries have been read */
3424 3428
@@ -3450,7 +3454,8 @@ struct lu_idxpage {
3450 * For the time being, we only support fixed-size key & record. */ 3454 * For the time being, we only support fixed-size key & record. */
3451 char lip_entries[0]; 3455 char lip_entries[0];
3452}; 3456};
3453extern void lustre_swab_lip_header(struct lu_idxpage *lip); 3457
3458void lustre_swab_lip_header(struct lu_idxpage *lip);
3454 3459
3455#define LIP_HDR_SIZE (offsetof(struct lu_idxpage, lip_entries)) 3460#define LIP_HDR_SIZE (offsetof(struct lu_idxpage, lip_entries))
3456 3461
@@ -3490,7 +3495,7 @@ struct lustre_capa {
3490 __u8 lc_hmac[CAPA_HMAC_MAX_LEN]; /** HMAC */ 3495 __u8 lc_hmac[CAPA_HMAC_MAX_LEN]; /** HMAC */
3491} __attribute__((packed)); 3496} __attribute__((packed));
3492 3497
3493extern void lustre_swab_lustre_capa(struct lustre_capa *c); 3498void lustre_swab_lustre_capa(struct lustre_capa *c);
3494 3499
3495/** lustre_capa::lc_opc */ 3500/** lustre_capa::lc_opc */
3496enum { 3501enum {
@@ -3548,7 +3553,7 @@ struct lustre_capa_key {
3548 __u8 lk_key[CAPA_HMAC_KEY_MAX_LEN]; /**< key */ 3553 __u8 lk_key[CAPA_HMAC_KEY_MAX_LEN]; /**< key */
3549} __attribute__((packed)); 3554} __attribute__((packed));
3550 3555
3551extern void lustre_swab_lustre_capa_key(struct lustre_capa_key *k); 3556void lustre_swab_lustre_capa_key(struct lustre_capa_key *k);
3552 3557
3553/** The link ea holds 1 \a link_ea_entry for each hardlink */ 3558/** The link ea holds 1 \a link_ea_entry for each hardlink */
3554#define LINK_EA_MAGIC 0x11EAF1DFUL 3559#define LINK_EA_MAGIC 0x11EAF1DFUL
@@ -3620,12 +3625,12 @@ struct hsm_progress_kernel {
3620 __u64 hpk_padding2; 3625 __u64 hpk_padding2;
3621} __attribute__((packed)); 3626} __attribute__((packed));
3622 3627
3623extern void lustre_swab_hsm_user_state(struct hsm_user_state *hus); 3628void lustre_swab_hsm_user_state(struct hsm_user_state *hus);
3624extern void lustre_swab_hsm_current_action(struct hsm_current_action *action); 3629void lustre_swab_hsm_current_action(struct hsm_current_action *action);
3625extern void lustre_swab_hsm_progress_kernel(struct hsm_progress_kernel *hpk); 3630void lustre_swab_hsm_progress_kernel(struct hsm_progress_kernel *hpk);
3626extern void lustre_swab_hsm_user_state(struct hsm_user_state *hus); 3631void lustre_swab_hsm_user_state(struct hsm_user_state *hus);
3627extern void lustre_swab_hsm_user_item(struct hsm_user_item *hui); 3632void lustre_swab_hsm_user_item(struct hsm_user_item *hui);
3628extern void lustre_swab_hsm_request(struct hsm_request *hr); 3633void lustre_swab_hsm_request(struct hsm_request *hr);
3629 3634
3630/** 3635/**
3631 * These are object update opcode under UPDATE_OBJ, which is currently 3636 * These are object update opcode under UPDATE_OBJ, which is currently
diff --git a/drivers/staging/lustre/lustre/include/lustre/lustre_user.h b/drivers/staging/lustre/lustre/include/lustre/lustre_user.h
index e095ada40ed2..9b1bb23c4d3c 100644
--- a/drivers/staging/lustre/lustre/include/lustre/lustre_user.h
+++ b/drivers/staging/lustre/lustre/include/lustre/lustre_user.h
@@ -406,7 +406,7 @@ static inline int lmv_user_md_size(int stripes, int lmm_magic)
406 stripes * sizeof(struct lmv_user_mds_data); 406 stripes * sizeof(struct lmv_user_mds_data);
407} 407}
408 408
409extern void lustre_swab_lmv_user_md(struct lmv_user_md *lum); 409void lustre_swab_lmv_user_md(struct lmv_user_md *lum);
410 410
411struct ll_recreate_obj { 411struct ll_recreate_obj {
412 __u64 lrc_id; 412 __u64 lrc_id;
diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
index f6f4c037fb30..355254689dee 100644
--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
@@ -1017,7 +1017,7 @@ extern struct obd_ops ldlm_obd_ops;
1017 1017
1018extern char *ldlm_lockname[]; 1018extern char *ldlm_lockname[];
1019extern char *ldlm_typename[]; 1019extern char *ldlm_typename[];
1020extern char *ldlm_it2str(int it); 1020char *ldlm_it2str(int it);
1021 1021
1022/** 1022/**
1023 * Just a fancy CDEBUG call with log level preset to LDLM_DEBUG. 1023 * Just a fancy CDEBUG call with log level preset to LDLM_DEBUG.
diff --git a/drivers/staging/lustre/lustre/include/lustre_export.h b/drivers/staging/lustre/lustre/include/lustre_export.h
index 3b992b42fd91..5189fad0b73c 100644
--- a/drivers/staging/lustre/lustre/include/lustre_export.h
+++ b/drivers/staging/lustre/lustre/include/lustre_export.h
@@ -368,8 +368,8 @@ static inline bool imp_connect_disp_stripe(struct obd_import *imp)
368 return ocd->ocd_connect_flags & OBD_CONNECT_DISP_STRIPE; 368 return ocd->ocd_connect_flags & OBD_CONNECT_DISP_STRIPE;
369} 369}
370 370
371extern struct obd_export *class_conn2export(struct lustre_handle *conn); 371struct obd_export *class_conn2export(struct lustre_handle *conn);
372extern struct obd_device *class_conn2obd(struct lustre_handle *conn); 372struct obd_device *class_conn2obd(struct lustre_handle *conn);
373 373
374/** @} export */ 374/** @} export */
375 375
diff --git a/drivers/staging/lustre/lustre/include/lustre_import.h b/drivers/staging/lustre/lustre/include/lustre_import.h
index dcc807676c49..5a38f3d5e011 100644
--- a/drivers/staging/lustre/lustre/include/lustre_import.h
+++ b/drivers/staging/lustre/lustre/include/lustre_import.h
@@ -375,8 +375,8 @@ extern unsigned int at_max;
375 375
376/* genops.c */ 376/* genops.c */
377struct obd_export; 377struct obd_export;
378extern struct obd_import *class_exp2cliimp(struct obd_export *); 378struct obd_import *class_exp2cliimp(struct obd_export *);
379extern struct obd_import *class_conn2cliimp(struct lustre_handle *); 379struct obd_import *class_conn2cliimp(struct lustre_handle *);
380 380
381/** @} import */ 381/** @} import */
382 382
diff --git a/drivers/staging/lustre/lustre/include/lustre_net.h b/drivers/staging/lustre/lustre/include/lustre_net.h
index 77a7de98fc8e..48ad60b22122 100644
--- a/drivers/staging/lustre/lustre/include/lustre_net.h
+++ b/drivers/staging/lustre/lustre/include/lustre_net.h
@@ -2183,7 +2183,7 @@ struct ptlrpcd_ctl {
2183 */ 2183 */
2184 struct ptlrpc_request_set *pc_set; 2184 struct ptlrpc_request_set *pc_set;
2185 /** 2185 /**
2186 * Thread name used in cfs_daemonize() 2186 * Thread name used in kthread_run()
2187 */ 2187 */
2188 char pc_name[16]; 2188 char pc_name[16];
2189 /** 2189 /**
@@ -2277,18 +2277,18 @@ static inline bool nrs_policy_compat_one(const struct ptlrpc_service *svc,
2277 2277
2278/* ptlrpc/events.c */ 2278/* ptlrpc/events.c */
2279extern lnet_handle_eq_t ptlrpc_eq_h; 2279extern lnet_handle_eq_t ptlrpc_eq_h;
2280extern int ptlrpc_uuid_to_peer(struct obd_uuid *uuid, 2280int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
2281 lnet_process_id_t *peer, lnet_nid_t *self); 2281 lnet_process_id_t *peer, lnet_nid_t *self);
2282/** 2282/**
2283 * These callbacks are invoked by LNet when something happened to 2283 * These callbacks are invoked by LNet when something happened to
2284 * underlying buffer 2284 * underlying buffer
2285 * @{ 2285 * @{
2286 */ 2286 */
2287extern void request_out_callback(lnet_event_t *ev); 2287void request_out_callback(lnet_event_t *ev);
2288extern void reply_in_callback(lnet_event_t *ev); 2288void reply_in_callback(lnet_event_t *ev);
2289extern void client_bulk_callback(lnet_event_t *ev); 2289void client_bulk_callback(lnet_event_t *ev);
2290extern void request_in_callback(lnet_event_t *ev); 2290void request_in_callback(lnet_event_t *ev);
2291extern void reply_out_callback(lnet_event_t *ev); 2291void reply_out_callback(lnet_event_t *ev);
2292/** @} */ 2292/** @} */
2293 2293
2294/* ptlrpc/connection.c */ 2294/* ptlrpc/connection.c */
@@ -2299,7 +2299,7 @@ int ptlrpc_connection_put(struct ptlrpc_connection *c);
2299struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *); 2299struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
2300int ptlrpc_connection_init(void); 2300int ptlrpc_connection_init(void);
2301void ptlrpc_connection_fini(void); 2301void ptlrpc_connection_fini(void);
2302extern lnet_pid_t ptl_get_pid(void); 2302lnet_pid_t ptl_get_pid(void);
2303 2303
2304/* ptlrpc/niobuf.c */ 2304/* ptlrpc/niobuf.c */
2305/** 2305/**
diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
index 55452e562bd4..9ad8c268da10 100644
--- a/drivers/staging/lustre/lustre/include/obd.h
+++ b/drivers/staging/lustre/lustre/include/obd.h
@@ -1472,7 +1472,7 @@ static inline bool filename_is_volatile(const char *name, int namelen, int *idx)
1472 } 1472 }
1473 /* we have an idx, read it */ 1473 /* we have an idx, read it */
1474 start = name + LUSTRE_VOLATILE_HDR_LEN + 1; 1474 start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
1475 *idx = strtoul(start, &end, 0); 1475 *idx = simple_strtoul(start, &end, 0);
1476 /* error cases: 1476 /* error cases:
1477 * no digit, no trailing :, negative value 1477 * no digit, no trailing :, negative value
1478 */ 1478 */
diff --git a/drivers/staging/lustre/lustre/include/obd_class.h b/drivers/staging/lustre/lustre/include/obd_class.h
index 36ed78127830..87bb2cedca7d 100644
--- a/drivers/staging/lustre/lustre/include/obd_class.h
+++ b/drivers/staging/lustre/lustre/include/obd_class.h
@@ -64,10 +64,10 @@ extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
64extern rwlock_t obd_dev_lock; 64extern rwlock_t obd_dev_lock;
65 65
66/* OBD Operations Declarations */ 66/* OBD Operations Declarations */
67extern struct obd_device *class_conn2obd(struct lustre_handle *); 67struct obd_device *class_conn2obd(struct lustre_handle *);
68extern struct obd_device *class_exp2obd(struct obd_export *); 68struct obd_device *class_exp2obd(struct obd_export *);
69extern int class_handle_ioctl(unsigned int cmd, unsigned long arg); 69int class_handle_ioctl(unsigned int cmd, unsigned long arg);
70extern int lustre_get_jobid(char *jobid); 70int lustre_get_jobid(char *jobid);
71 71
72struct lu_device_type; 72struct lu_device_type;
73 73
@@ -139,7 +139,7 @@ int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
139int class_add_uuid(const char *uuid, __u64 nid); 139int class_add_uuid(const char *uuid, __u64 nid);
140 140
141/*obdecho*/ 141/*obdecho*/
142extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars); 142void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
143 143
144#define CFG_F_START 0x01 /* Set when we start updating from a log */ 144#define CFG_F_START 0x01 /* Set when we start updating from a log */
145#define CFG_F_MARKER 0x02 /* We are within a maker */ 145#define CFG_F_MARKER 0x02 /* We are within a maker */
@@ -1823,8 +1823,8 @@ static inline int md_revalidate_lock(struct obd_export *exp,
1823 1823
1824/* OBD Metadata Support */ 1824/* OBD Metadata Support */
1825 1825
1826extern int obd_init_caches(void); 1826int obd_init_caches(void);
1827extern void obd_cleanup_caches(void); 1827void obd_cleanup_caches(void);
1828 1828
1829/* support routines */ 1829/* support routines */
1830extern struct kmem_cache *obdo_cachep; 1830extern struct kmem_cache *obdo_cachep;
@@ -1869,8 +1869,7 @@ extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1869/* obd_mount.c */ 1869/* obd_mount.c */
1870 1870
1871/* sysctl.c */ 1871/* sysctl.c */
1872extern void obd_sysctl_init (void); 1872int obd_sysctl_init(void);
1873extern void obd_sysctl_clean (void);
1874 1873
1875/* uuid.c */ 1874/* uuid.c */
1876typedef __u8 class_uuid_t[16]; 1875typedef __u8 class_uuid_t[16];
diff --git a/drivers/staging/lustre/lustre/include/obd_support.h b/drivers/staging/lustre/lustre/include/obd_support.h
index 73e2d4880b9b..18aec796a724 100644
--- a/drivers/staging/lustre/lustre/include/obd_support.h
+++ b/drivers/staging/lustre/lustre/include/obd_support.h
@@ -56,9 +56,7 @@ extern unsigned int obd_dump_on_eviction;
56/* obd_timeout should only be used for recovery, not for 56/* obd_timeout should only be used for recovery, not for
57 networking / disk / timings affected by load (use Adaptive Timeouts) */ 57 networking / disk / timings affected by load (use Adaptive Timeouts) */
58extern unsigned int obd_timeout; /* seconds */ 58extern unsigned int obd_timeout; /* seconds */
59extern unsigned int ldlm_timeout; /* seconds */
60extern unsigned int obd_timeout_set; 59extern unsigned int obd_timeout_set;
61extern unsigned int ldlm_timeout_set;
62extern unsigned int at_min; 60extern unsigned int at_min;
63extern unsigned int at_max; 61extern unsigned int at_max;
64extern unsigned int at_history; 62extern unsigned int at_history;
@@ -105,8 +103,6 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
105 103
106/* Timeout definitions */ 104/* Timeout definitions */
107#define OBD_TIMEOUT_DEFAULT 100 105#define OBD_TIMEOUT_DEFAULT 100
108#define LDLM_TIMEOUT_DEFAULT 20
109#define MDS_LDLM_TIMEOUT_DEFAULT 6
110/* Time to wait for all clients to reconnect during recovery (hard limit) */ 106/* Time to wait for all clients to reconnect during recovery (hard limit) */
111#define OBD_RECOVERY_TIME_HARD (obd_timeout * 9) 107#define OBD_RECOVERY_TIME_HARD (obd_timeout * 9)
112/* Time to wait for all clients to reconnect during recovery (soft limit) */ 108/* Time to wait for all clients to reconnect during recovery (soft limit) */
@@ -505,9 +501,7 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
505#define OBD_FAIL_ONCE CFS_FAIL_ONCE 501#define OBD_FAIL_ONCE CFS_FAIL_ONCE
506#define OBD_FAILED CFS_FAILED 502#define OBD_FAILED CFS_FAILED
507 503
508extern atomic_t libcfs_kmemory; 504void obd_update_maxusage(void);
509
510extern void obd_update_maxusage(void);
511 505
512#define obd_memory_add(size) \ 506#define obd_memory_add(size) \
513 lprocfs_counter_add(obd_memory, OBD_MEMORY_STAT, (long)(size)) 507 lprocfs_counter_add(obd_memory, OBD_MEMORY_STAT, (long)(size))
@@ -526,8 +520,8 @@ extern void obd_update_maxusage(void);
526 lprocfs_stats_collector(obd_memory, OBD_MEMORY_PAGES_STAT, \ 520 lprocfs_stats_collector(obd_memory, OBD_MEMORY_PAGES_STAT, \
527 LPROCFS_FIELDS_FLAGS_SUM) 521 LPROCFS_FIELDS_FLAGS_SUM)
528 522
529extern __u64 obd_memory_max(void); 523__u64 obd_memory_max(void);
530extern __u64 obd_pages_max(void); 524__u64 obd_pages_max(void);
531 525
532#define OBD_DEBUG_MEMUSAGE (1) 526#define OBD_DEBUG_MEMUSAGE (1)
533 527
@@ -622,8 +616,8 @@ do { \
622 if (unlikely((ptr) == NULL)) { \ 616 if (unlikely((ptr) == NULL)) { \
623 CERROR("vmalloc of '" #ptr "' (%d bytes) failed\n", \ 617 CERROR("vmalloc of '" #ptr "' (%d bytes) failed\n", \
624 (int)(size)); \ 618 (int)(size)); \
625 CERROR("%llu total bytes allocated by Lustre, %d by LNET\n", \ 619 CERROR("%llu total bytes allocated by Lustre\n", \
626 obd_memory_sum(), atomic_read(&libcfs_kmemory)); \ 620 obd_memory_sum()); \
627 } else { \ 621 } else { \
628 OBD_ALLOC_POST(ptr, size, "vmalloced"); \ 622 OBD_ALLOC_POST(ptr, size, "vmalloced"); \
629 } \ 623 } \
@@ -769,12 +763,10 @@ do { \
769 "failed\n", (int)1, \ 763 "failed\n", (int)1, \
770 (__u64)(1 << PAGE_CACHE_SHIFT)); \ 764 (__u64)(1 << PAGE_CACHE_SHIFT)); \
771 CERROR("%llu total bytes and %llu total pages " \ 765 CERROR("%llu total bytes and %llu total pages " \
772 "(%llu bytes) allocated by Lustre, " \ 766 "(%llu bytes) allocated by Lustre\n", \
773 "%d total bytes by LNET\n", \
774 obd_memory_sum(), \ 767 obd_memory_sum(), \
775 obd_pages_sum() << PAGE_CACHE_SHIFT, \ 768 obd_pages_sum() << PAGE_CACHE_SHIFT, \
776 obd_pages_sum(), \ 769 obd_pages_sum()); \
777 atomic_read(&libcfs_kmemory)); \
778 } else { \ 770 } else { \
779 obd_pages_add(0); \ 771 obd_pages_add(0); \
780 CDEBUG(D_MALLOC, "alloc_pages '" #ptr "': %d page(s) / " \ 772 CDEBUG(D_MALLOC, "alloc_pages '" #ptr "': %d page(s) / " \
diff --git a/drivers/staging/lustre/lustre/lclient/lcommon_cl.c b/drivers/staging/lustre/lustre/lclient/lcommon_cl.c
index e0c1ccafbd63..9053f8116298 100644
--- a/drivers/staging/lustre/lustre/lclient/lcommon_cl.c
+++ b/drivers/staging/lustre/lustre/lclient/lcommon_cl.c
@@ -203,7 +203,7 @@ struct lu_device *ccc_device_alloc(const struct lu_env *env,
203 int rc; 203 int rc;
204 204
205 vdv = kzalloc(sizeof(*vdv), GFP_NOFS); 205 vdv = kzalloc(sizeof(*vdv), GFP_NOFS);
206 if (vdv == NULL) 206 if (!vdv)
207 return ERR_PTR(-ENOMEM); 207 return ERR_PTR(-ENOMEM);
208 208
209 lud = &vdv->cdv_cl.cd_lu_dev; 209 lud = &vdv->cdv_cl.cd_lu_dev;
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
index 6601e6b12c32..fa4b7c760d49 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
@@ -209,7 +209,7 @@ struct ldlm_state {
209 209
210/* interval tree, for LDLM_EXTENT. */ 210/* interval tree, for LDLM_EXTENT. */
211extern struct kmem_cache *ldlm_interval_slab; /* slab cache for ldlm_interval */ 211extern struct kmem_cache *ldlm_interval_slab; /* slab cache for ldlm_interval */
212extern void ldlm_interval_attach(struct ldlm_interval *n, struct ldlm_lock *l); 212void ldlm_interval_attach(struct ldlm_interval *n, struct ldlm_lock *l);
213struct ldlm_interval *ldlm_interval_detach(struct ldlm_lock *l); 213struct ldlm_interval *ldlm_interval_detach(struct ldlm_lock *l);
214struct ldlm_interval *ldlm_interval_alloc(struct ldlm_lock *lock); 214struct ldlm_interval *ldlm_interval_alloc(struct ldlm_lock *lock);
215void ldlm_interval_free(struct ldlm_interval *node); 215void ldlm_interval_free(struct ldlm_interval *node);
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
index 764f98684d74..badd227e4f67 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
@@ -656,7 +656,8 @@ int target_pack_pool_reply(struct ptlrpc_request *req)
656} 656}
657EXPORT_SYMBOL(target_pack_pool_reply); 657EXPORT_SYMBOL(target_pack_pool_reply);
658 658
659int target_send_reply_msg(struct ptlrpc_request *req, int rc, int fail_id) 659static int
660target_send_reply_msg(struct ptlrpc_request *req, int rc, int fail_id)
660{ 661{
661 if (OBD_FAIL_CHECK_ORSET(fail_id & ~OBD_FAIL_ONCE, OBD_FAIL_ONCE)) { 662 if (OBD_FAIL_CHECK_ORSET(fail_id & ~OBD_FAIL_ONCE, OBD_FAIL_ONCE)) {
662 DEBUG_REQ(D_ERROR, req, "dropping reply"); 663 DEBUG_REQ(D_ERROR, req, "dropping reply");
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
index bb2246d3b22b..cd340fc8ceab 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
@@ -1528,7 +1528,7 @@ struct ldlm_lock *ldlm_lock_create(struct ldlm_namespace *ns,
1528 if (lvb_len) { 1528 if (lvb_len) {
1529 lock->l_lvb_len = lvb_len; 1529 lock->l_lvb_len = lvb_len;
1530 lock->l_lvb_data = kzalloc(lvb_len, GFP_NOFS); 1530 lock->l_lvb_data = kzalloc(lvb_len, GFP_NOFS);
1531 if (lock->l_lvb_data == NULL) 1531 if (!lock->l_lvb_data)
1532 goto out; 1532 goto out;
1533 } 1533 }
1534 1534
@@ -1813,7 +1813,7 @@ int ldlm_run_ast_work(struct ldlm_namespace *ns, struct list_head *rpc_list,
1813 return 0; 1813 return 0;
1814 1814
1815 arg = kzalloc(sizeof(*arg), GFP_NOFS); 1815 arg = kzalloc(sizeof(*arg), GFP_NOFS);
1816 if (arg == NULL) 1816 if (!arg)
1817 return -ENOMEM; 1817 return -ENOMEM;
1818 1818
1819 atomic_set(&arg->restart, 0); 1819 atomic_set(&arg->restart, 0);
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
index b7b6ca1196b7..ac79db952da7 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
@@ -76,15 +76,6 @@ inline unsigned long round_timeout(unsigned long timeout)
76 return cfs_time_seconds((int)cfs_duration_sec(cfs_time_sub(timeout, 0)) + 1); 76 return cfs_time_seconds((int)cfs_duration_sec(cfs_time_sub(timeout, 0)) + 1);
77} 77}
78 78
79/* timeout for initial callback (AST) reply (bz10399) */
80static inline unsigned int ldlm_get_rq_timeout(void)
81{
82 /* Non-AT value */
83 unsigned int timeout = min(ldlm_timeout, obd_timeout / 3);
84
85 return timeout < 1 ? 1 : timeout;
86}
87
88#define ELT_STOPPED 0 79#define ELT_STOPPED 0
89#define ELT_READY 1 80#define ELT_READY 1
90#define ELT_TERMINATE 2 81#define ELT_TERMINATE 2
@@ -225,7 +216,7 @@ static void ldlm_handle_cp_callback(struct ptlrpc_request *req,
225 void *lvb_data; 216 void *lvb_data;
226 217
227 lvb_data = kzalloc(lvb_len, GFP_NOFS); 218 lvb_data = kzalloc(lvb_len, GFP_NOFS);
228 if (lvb_data == NULL) { 219 if (!lvb_data) {
229 LDLM_ERROR(lock, "No memory: %d.\n", lvb_len); 220 LDLM_ERROR(lock, "No memory: %d.\n", lvb_len);
230 rc = -ENOMEM; 221 rc = -ENOMEM;
231 goto out; 222 goto out;
@@ -453,7 +444,7 @@ static int ldlm_bl_to_thread(struct ldlm_namespace *ns,
453 struct ldlm_bl_work_item *blwi; 444 struct ldlm_bl_work_item *blwi;
454 445
455 blwi = kzalloc(sizeof(*blwi), GFP_NOFS); 446 blwi = kzalloc(sizeof(*blwi), GFP_NOFS);
456 if (blwi == NULL) 447 if (!blwi)
457 return -ENOMEM; 448 return -ENOMEM;
458 init_blwi(blwi, ns, ld, cancels, count, lock, cancel_flags); 449 init_blwi(blwi, ns, ld, cancels, count, lock, cancel_flags);
459 450
@@ -1053,7 +1044,7 @@ static int ldlm_setup(void)
1053 return -EALREADY; 1044 return -EALREADY;
1054 1045
1055 ldlm_state = kzalloc(sizeof(*ldlm_state), GFP_NOFS); 1046 ldlm_state = kzalloc(sizeof(*ldlm_state), GFP_NOFS);
1056 if (ldlm_state == NULL) 1047 if (!ldlm_state)
1057 return -ENOMEM; 1048 return -ENOMEM;
1058 1049
1059 ldlm_kobj = kobject_create_and_add("ldlm", lustre_kobj); 1050 ldlm_kobj = kobject_create_and_add("ldlm", lustre_kobj);
@@ -1123,7 +1114,7 @@ static int ldlm_setup(void)
1123 1114
1124 1115
1125 blp = kzalloc(sizeof(*blp), GFP_NOFS); 1116 blp = kzalloc(sizeof(*blp), GFP_NOFS);
1126 if (blp == NULL) { 1117 if (!blp) {
1127 rc = -ENOMEM; 1118 rc = -ENOMEM;
1128 goto out; 1119 goto out;
1129 } 1120 }
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
index 1605b9c69271..c234acb85f10 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
@@ -1422,7 +1422,7 @@ static int ldlm_pools_thread_start(void)
1422 return -EALREADY; 1422 return -EALREADY;
1423 1423
1424 ldlm_pools_thread = kzalloc(sizeof(*ldlm_pools_thread), GFP_NOFS); 1424 ldlm_pools_thread = kzalloc(sizeof(*ldlm_pools_thread), GFP_NOFS);
1425 if (ldlm_pools_thread == NULL) 1425 if (!ldlm_pools_thread)
1426 return -ENOMEM; 1426 return -ENOMEM;
1427 1427
1428 init_completion(&ldlm_pools_comp); 1428 init_completion(&ldlm_pools_comp);
@@ -1486,8 +1486,10 @@ EXPORT_SYMBOL(ldlm_pools_init);
1486 1486
1487void ldlm_pools_fini(void) 1487void ldlm_pools_fini(void)
1488{ 1488{
1489 unregister_shrinker(&ldlm_pools_srv_shrinker); 1489 if (ldlm_pools_thread) {
1490 unregister_shrinker(&ldlm_pools_cli_shrinker); 1490 unregister_shrinker(&ldlm_pools_srv_shrinker);
1491 unregister_shrinker(&ldlm_pools_cli_shrinker);
1492 }
1491 ldlm_pools_thread_stop(); 1493 ldlm_pools_thread_stop();
1492} 1494}
1493EXPORT_SYMBOL(ldlm_pools_fini); 1495EXPORT_SYMBOL(ldlm_pools_fini);
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
index cdb63665a113..4bb3173bcd5f 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
@@ -939,6 +939,7 @@ void ldlm_namespace_free_post(struct ldlm_namespace *ns)
939 ldlm_pool_fini(&ns->ns_pool); 939 ldlm_pool_fini(&ns->ns_pool);
940 940
941 ldlm_namespace_debugfs_unregister(ns); 941 ldlm_namespace_debugfs_unregister(ns);
942 ldlm_namespace_sysfs_unregister(ns);
942 cfs_hash_putref(ns->ns_rs_hash); 943 cfs_hash_putref(ns->ns_rs_hash);
943 /* Namespace \a ns should be not on list at this time, otherwise 944 /* Namespace \a ns should be not on list at this time, otherwise
944 * this will cause issues related to using freed \a ns in poold 945 * this will cause issues related to using freed \a ns in poold
diff --git a/drivers/staging/lustre/lustre/libcfs/debug.c b/drivers/staging/lustre/lustre/libcfs/debug.c
index 021c92fa0333..e93f556fac0d 100644
--- a/drivers/staging/lustre/lustre/libcfs/debug.c
+++ b/drivers/staging/lustre/lustre/libcfs/debug.c
@@ -57,8 +57,42 @@ module_param(libcfs_debug, int, 0644);
57MODULE_PARM_DESC(libcfs_debug, "Lustre kernel debug mask"); 57MODULE_PARM_DESC(libcfs_debug, "Lustre kernel debug mask");
58EXPORT_SYMBOL(libcfs_debug); 58EXPORT_SYMBOL(libcfs_debug);
59 59
60static int libcfs_param_debug_mb_set(const char *val,
61 const struct kernel_param *kp)
62{
63 int rc;
64 unsigned num;
65
66 rc = kstrtouint(val, 0, &num);
67 if (rc < 0)
68 return rc;
69
70 if (!*((unsigned int *)kp->arg)) {
71 *((unsigned int *)kp->arg) = num;
72 return 0;
73 }
74
75 rc = cfs_trace_set_debug_mb(num);
76
77 if (!rc)
78 *((unsigned int *)kp->arg) = cfs_trace_get_debug_mb();
79
80 return rc;
81}
82
83/* While debug_mb setting look like unsigned int, in fact
84 * it needs quite a bunch of extra processing, so we define special
85 * debugmb parameter type with corresponding methods to handle this case */
86static struct kernel_param_ops param_ops_debugmb = {
87 .set = libcfs_param_debug_mb_set,
88 .get = param_get_uint,
89};
90
91#define param_check_debugmb(name, p) \
92 __param_check(name, p, unsigned int)
93
60static unsigned int libcfs_debug_mb; 94static unsigned int libcfs_debug_mb;
61module_param(libcfs_debug_mb, uint, 0644); 95module_param(libcfs_debug_mb, debugmb, 0644);
62MODULE_PARM_DESC(libcfs_debug_mb, "Total debug buffer size."); 96MODULE_PARM_DESC(libcfs_debug_mb, "Total debug buffer size.");
63EXPORT_SYMBOL(libcfs_debug_mb); 97EXPORT_SYMBOL(libcfs_debug_mb);
64 98
@@ -72,18 +106,106 @@ module_param(libcfs_console_ratelimit, uint, 0644);
72MODULE_PARM_DESC(libcfs_console_ratelimit, "Lustre kernel debug console ratelimit (0 to disable)"); 106MODULE_PARM_DESC(libcfs_console_ratelimit, "Lustre kernel debug console ratelimit (0 to disable)");
73EXPORT_SYMBOL(libcfs_console_ratelimit); 107EXPORT_SYMBOL(libcfs_console_ratelimit);
74 108
109static int param_set_delay_minmax(const char *val,
110 const struct kernel_param *kp,
111 long min, long max)
112{
113 long d;
114 int sec;
115 int rc;
116
117 rc = kstrtoint(val, 0, &sec);
118 if (rc)
119 return -EINVAL;
120
121 d = cfs_time_seconds(sec) / 100;
122 if (d < min || d > max)
123 return -EINVAL;
124
125 *((unsigned int *)kp->arg) = d;
126
127 return 0;
128}
129
130static int param_get_delay(char *buffer, const struct kernel_param *kp)
131{
132 unsigned int d = *(unsigned int *)kp->arg;
133
134 return sprintf(buffer, "%u", (unsigned int)cfs_duration_sec(d * 100));
135}
136
75unsigned int libcfs_console_max_delay; 137unsigned int libcfs_console_max_delay;
76module_param(libcfs_console_max_delay, uint, 0644);
77MODULE_PARM_DESC(libcfs_console_max_delay, "Lustre kernel debug console max delay (jiffies)");
78EXPORT_SYMBOL(libcfs_console_max_delay); 138EXPORT_SYMBOL(libcfs_console_max_delay);
79
80unsigned int libcfs_console_min_delay; 139unsigned int libcfs_console_min_delay;
81module_param(libcfs_console_min_delay, uint, 0644);
82MODULE_PARM_DESC(libcfs_console_min_delay, "Lustre kernel debug console min delay (jiffies)");
83EXPORT_SYMBOL(libcfs_console_min_delay); 140EXPORT_SYMBOL(libcfs_console_min_delay);
84 141
142static int param_set_console_max_delay(const char *val,
143 const struct kernel_param *kp)
144{
145 return param_set_delay_minmax(val, kp,
146 libcfs_console_min_delay, INT_MAX);
147}
148
149static struct kernel_param_ops param_ops_console_max_delay = {
150 .set = param_set_console_max_delay,
151 .get = param_get_delay,
152};
153
154#define param_check_console_max_delay(name, p) \
155 __param_check(name, p, unsigned int)
156
157module_param(libcfs_console_max_delay, console_max_delay, 0644);
158MODULE_PARM_DESC(libcfs_console_max_delay, "Lustre kernel debug console max delay (jiffies)");
159
160static int param_set_console_min_delay(const char *val,
161 const struct kernel_param *kp)
162{
163 return param_set_delay_minmax(val, kp,
164 1, libcfs_console_max_delay);
165}
166
167static struct kernel_param_ops param_ops_console_min_delay = {
168 .set = param_set_console_min_delay,
169 .get = param_get_delay,
170};
171
172#define param_check_console_min_delay(name, p) \
173 __param_check(name, p, unsigned int)
174
175module_param(libcfs_console_min_delay, console_min_delay, 0644);
176MODULE_PARM_DESC(libcfs_console_min_delay, "Lustre kernel debug console min delay (jiffies)");
177
178static int param_set_uint_minmax(const char *val,
179 const struct kernel_param *kp,
180 unsigned int min, unsigned int max)
181{
182 unsigned int num;
183 int ret;
184
185 if (!val)
186 return -EINVAL;
187 ret = kstrtouint(val, 0, &num);
188 if (ret < 0 || num < min || num > max)
189 return -EINVAL;
190 *((unsigned int *)kp->arg) = num;
191 return 0;
192}
193
194static int param_set_uintpos(const char *val, const struct kernel_param *kp)
195{
196 return param_set_uint_minmax(val, kp, 1, -1);
197}
198
199static struct kernel_param_ops param_ops_uintpos = {
200 .set = param_set_uintpos,
201 .get = param_get_uint,
202};
203
204#define param_check_uintpos(name, p) \
205 __param_check(name, p, unsigned int)
206
85unsigned int libcfs_console_backoff = CDEBUG_DEFAULT_BACKOFF; 207unsigned int libcfs_console_backoff = CDEBUG_DEFAULT_BACKOFF;
86module_param(libcfs_console_backoff, uint, 0644); 208module_param(libcfs_console_backoff, uintpos, 0644);
87MODULE_PARM_DESC(libcfs_console_backoff, "Lustre kernel debug console backoff factor"); 209MODULE_PARM_DESC(libcfs_console_backoff, "Lustre kernel debug console backoff factor");
88EXPORT_SYMBOL(libcfs_console_backoff); 210EXPORT_SYMBOL(libcfs_console_backoff);
89 211
@@ -93,23 +215,14 @@ EXPORT_SYMBOL(libcfs_debug_binary);
93unsigned int libcfs_stack = 3 * THREAD_SIZE / 4; 215unsigned int libcfs_stack = 3 * THREAD_SIZE / 4;
94EXPORT_SYMBOL(libcfs_stack); 216EXPORT_SYMBOL(libcfs_stack);
95 217
96static unsigned int portal_enter_debugger;
97EXPORT_SYMBOL(portal_enter_debugger);
98
99unsigned int libcfs_catastrophe; 218unsigned int libcfs_catastrophe;
100EXPORT_SYMBOL(libcfs_catastrophe); 219EXPORT_SYMBOL(libcfs_catastrophe);
101 220
102unsigned int libcfs_watchdog_ratelimit = 300;
103EXPORT_SYMBOL(libcfs_watchdog_ratelimit);
104
105unsigned int libcfs_panic_on_lbug = 1; 221unsigned int libcfs_panic_on_lbug = 1;
106module_param(libcfs_panic_on_lbug, uint, 0644); 222module_param(libcfs_panic_on_lbug, uint, 0644);
107MODULE_PARM_DESC(libcfs_panic_on_lbug, "Lustre kernel panic on LBUG"); 223MODULE_PARM_DESC(libcfs_panic_on_lbug, "Lustre kernel panic on LBUG");
108EXPORT_SYMBOL(libcfs_panic_on_lbug); 224EXPORT_SYMBOL(libcfs_panic_on_lbug);
109 225
110atomic_t libcfs_kmemory = ATOMIC_INIT(0);
111EXPORT_SYMBOL(libcfs_kmemory);
112
113static wait_queue_head_t debug_ctlwq; 226static wait_queue_head_t debug_ctlwq;
114 227
115char libcfs_debug_file_path_arr[PATH_MAX] = LIBCFS_DEBUG_FILE_PATH_DEFAULT; 228char libcfs_debug_file_path_arr[PATH_MAX] = LIBCFS_DEBUG_FILE_PATH_DEFAULT;
@@ -414,8 +527,10 @@ int libcfs_debug_init(unsigned long bufsize)
414 } 527 }
415 rc = cfs_tracefile_init(max); 528 rc = cfs_tracefile_init(max);
416 529
417 if (rc == 0) 530 if (rc == 0) {
418 libcfs_register_panic_notifier(); 531 libcfs_register_panic_notifier();
532 libcfs_debug_mb = cfs_trace_get_debug_mb();
533 }
419 534
420 return rc; 535 return rc;
421} 536}
diff --git a/drivers/staging/lustre/lustre/libcfs/fail.c b/drivers/staging/lustre/lustre/libcfs/fail.c
index 7b7fc215e633..42d615fbd664 100644
--- a/drivers/staging/lustre/lustre/libcfs/fail.c
+++ b/drivers/staging/lustre/lustre/libcfs/fail.c
@@ -123,7 +123,7 @@ EXPORT_SYMBOL(__cfs_fail_check_set);
123 123
124int __cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set) 124int __cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set)
125{ 125{
126 int ret = 0; 126 int ret;
127 127
128 ret = __cfs_fail_check_set(id, value, set); 128 ret = __cfs_fail_check_set(id, value, set);
129 if (ret) { 129 if (ret) {
diff --git a/drivers/staging/lustre/lustre/libcfs/libcfs_cpu.c b/drivers/staging/lustre/lustre/libcfs/libcfs_cpu.c
index 31a558115a96..933525c73da1 100644
--- a/drivers/staging/lustre/lustre/libcfs/libcfs_cpu.c
+++ b/drivers/staging/lustre/lustre/libcfs/libcfs_cpu.c
@@ -78,7 +78,7 @@ EXPORT_SYMBOL(cfs_cpt_table_free);
78int 78int
79cfs_cpt_table_print(struct cfs_cpt_table *cptab, char *buf, int len) 79cfs_cpt_table_print(struct cfs_cpt_table *cptab, char *buf, int len)
80{ 80{
81 int rc = 0; 81 int rc;
82 82
83 rc = snprintf(buf, len, "%d\t: %d\n", 0, 0); 83 rc = snprintf(buf, len, "%d\t: %d\n", 0, 0);
84 len -= rc; 84 len -= rc;
diff --git a/drivers/staging/lustre/lustre/libcfs/libcfs_string.c b/drivers/staging/lustre/lustre/libcfs/libcfs_string.c
index 76d4392bd282..efe5e667a2e5 100644
--- a/drivers/staging/lustre/lustre/libcfs/libcfs_string.c
+++ b/drivers/staging/lustre/lustre/libcfs/libcfs_string.c
@@ -231,7 +231,7 @@ cfs_str2num_check(char *str, int nob, unsigned *num,
231 char *endp; 231 char *endp;
232 232
233 str = cfs_trimwhite(str); 233 str = cfs_trimwhite(str);
234 *num = strtoul(str, &endp, 0); 234 *num = simple_strtoul(str, &endp, 0);
235 if (endp == str) 235 if (endp == str)
236 return 0; 236 return 0;
237 237
@@ -400,7 +400,7 @@ cfs_expr_list_free(struct cfs_expr_list *expr_list)
400 struct cfs_range_expr *expr; 400 struct cfs_range_expr *expr;
401 401
402 expr = list_entry(expr_list->el_exprs.next, 402 expr = list_entry(expr_list->el_exprs.next,
403 struct cfs_range_expr, re_link), 403 struct cfs_range_expr, re_link);
404 list_del(&expr->re_link); 404 list_del(&expr->re_link);
405 LIBCFS_FREE(expr, sizeof(*expr)); 405 LIBCFS_FREE(expr, sizeof(*expr));
406 } 406 }
diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c
index aa3fffed1519..fbbc8a7e308d 100644
--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c
+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c
@@ -114,7 +114,7 @@ int cfs_crypto_hash_digest(unsigned char alg_id,
114 crypto_free_hash(hdesc.tfm); 114 crypto_free_hash(hdesc.tfm);
115 return -ENOSPC; 115 return -ENOSPC;
116 } 116 }
117 sg_init_one(&sl, (void *)buf, buf_len); 117 sg_init_one(&sl, buf, buf_len);
118 118
119 hdesc.flags = 0; 119 hdesc.flags = 0;
120 err = crypto_hash_digest(&hdesc, &sl, sl.length, hash); 120 err = crypto_hash_digest(&hdesc, &sl, sl.length, hash);
@@ -165,7 +165,7 @@ int cfs_crypto_hash_update(struct cfs_crypto_hash_desc *hdesc,
165{ 165{
166 struct scatterlist sl; 166 struct scatterlist sl;
167 167
168 sg_init_one(&sl, (void *)buf, buf_len); 168 sg_init_one(&sl, buf, buf_len);
169 169
170 return crypto_hash_update((struct hash_desc *)hdesc, &sl, sl.length); 170 return crypto_hash_update((struct hash_desc *)hdesc, &sl, sl.length);
171} 171}
diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-module.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-module.c
index e962f89683a6..64a984b42845 100644
--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-module.c
@@ -49,7 +49,7 @@ int libcfs_ioctl_getdata(char *buf, char *end, void *arg)
49 hdr = (struct libcfs_ioctl_hdr *)buf; 49 hdr = (struct libcfs_ioctl_hdr *)buf;
50 data = (struct libcfs_ioctl_data *)buf; 50 data = (struct libcfs_ioctl_data *)buf;
51 51
52 if (copy_from_user(buf, (void *)arg, sizeof(*hdr))) 52 if (copy_from_user(buf, arg, sizeof(*hdr)))
53 return -EFAULT; 53 return -EFAULT;
54 54
55 if (hdr->ioc_version != LIBCFS_IOCTL_VERSION) { 55 if (hdr->ioc_version != LIBCFS_IOCTL_VERSION) {
@@ -69,7 +69,7 @@ int libcfs_ioctl_getdata(char *buf, char *end, void *arg)
69 } 69 }
70 70
71 orig_len = hdr->ioc_len; 71 orig_len = hdr->ioc_len;
72 if (copy_from_user(buf, (void *)arg, hdr->ioc_len)) 72 if (copy_from_user(buf, arg, hdr->ioc_len))
73 return -EFAULT; 73 return -EFAULT;
74 if (orig_len != data->ioc_len) 74 if (orig_len != data->ioc_len)
75 return -EINVAL; 75 return -EINVAL;
@@ -96,8 +96,6 @@ int libcfs_ioctl_popdata(void *arg, void *data, int size)
96 return 0; 96 return 0;
97} 97}
98 98
99extern struct cfs_psdev_ops libcfs_psdev_ops;
100
101static int 99static int
102libcfs_psdev_open(struct inode *inode, struct file *file) 100libcfs_psdev_open(struct inode *inode, struct file *file)
103{ 101{
diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
index e7074006e41b..806f9747a3a2 100644
--- a/drivers/staging/lustre/lustre/libcfs/module.c
+++ b/drivers/staging/lustre/lustre/libcfs/module.c
@@ -50,6 +50,7 @@
50#include <linux/list.h> 50#include <linux/list.h>
51 51
52#include <linux/sysctl.h> 52#include <linux/sysctl.h>
53#include <linux/debugfs.h>
53 54
54# define DEBUG_SUBSYSTEM S_LNET 55# define DEBUG_SUBSYSTEM S_LNET
55 56
@@ -65,48 +66,12 @@ MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
65MODULE_DESCRIPTION("Portals v3.1"); 66MODULE_DESCRIPTION("Portals v3.1");
66MODULE_LICENSE("GPL"); 67MODULE_LICENSE("GPL");
67 68
68extern struct miscdevice libcfs_dev; 69static void insert_debugfs(void);
69extern struct cfs_wi_sched *cfs_sched_rehash; 70static void remove_debugfs(void);
70extern void libcfs_init_nidstrings(void);
71 71
72static int insert_proc(void); 72static struct dentry *lnet_debugfs_root;
73static void remove_proc(void);
74 73
75static struct ctl_table_header *lnet_table_header; 74static void kportal_memhog_free(struct libcfs_device_userstate *ldu)
76extern char lnet_upcall[1024];
77/**
78 * The path of debug log dump upcall script.
79 */
80extern char lnet_debug_log_upcall[1024];
81
82#define CTL_LNET (0x100)
83
84enum {
85 PSDEV_DEBUG = 1, /* control debugging */
86 PSDEV_SUBSYSTEM_DEBUG, /* control debugging */
87 PSDEV_PRINTK, /* force all messages to console */
88 PSDEV_CONSOLE_RATELIMIT, /* ratelimit console messages */
89 PSDEV_CONSOLE_MAX_DELAY_CS, /* maximum delay over which we skip messages */
90 PSDEV_CONSOLE_MIN_DELAY_CS, /* initial delay over which we skip messages */
91 PSDEV_CONSOLE_BACKOFF, /* delay increase factor */
92 PSDEV_DEBUG_PATH, /* crashdump log location */
93 PSDEV_DEBUG_DUMP_PATH, /* crashdump tracelog location */
94 PSDEV_CPT_TABLE, /* information about cpu partitions */
95 PSDEV_LNET_UPCALL, /* User mode upcall script */
96 PSDEV_LNET_MEMUSED, /* bytes currently PORTAL_ALLOCated */
97 PSDEV_LNET_CATASTROPHE, /* if we have LBUGged or panic'd */
98 PSDEV_LNET_PANIC_ON_LBUG, /* flag to panic on LBUG */
99 PSDEV_LNET_DUMP_KERNEL, /* snapshot kernel debug buffer to file */
100 PSDEV_LNET_DAEMON_FILE, /* spool kernel debug buffer to file */
101 PSDEV_LNET_DEBUG_MB, /* size of debug buffer */
102 PSDEV_LNET_DEBUG_LOG_UPCALL, /* debug log upcall script */
103 PSDEV_LNET_WATCHDOG_RATELIMIT, /* ratelimit watchdog messages */
104 PSDEV_LNET_FORCE_LBUG, /* hook to force an LBUG */
105 PSDEV_LNET_FAIL_LOC, /* control test failures instrumentation */
106 PSDEV_LNET_FAIL_VAL, /* userdata for fail loc */
107};
108
109static void kportal_memhog_free (struct libcfs_device_userstate *ldu)
110{ 75{
111 struct page **level0p = &ldu->ldu_memhog_root_page; 76 struct page **level0p = &ldu->ldu_memhog_root_page;
112 struct page **level1p; 77 struct page **level1p;
@@ -146,7 +111,7 @@ static void kportal_memhog_free (struct libcfs_device_userstate *ldu)
146 *level0p = NULL; 111 *level0p = NULL;
147 } 112 }
148 113
149 LASSERT (ldu->ldu_memhog_pages == 0); 114 LASSERT(ldu->ldu_memhog_pages == 0);
150} 115}
151 116
152static int kportal_memhog_alloc(struct libcfs_device_userstate *ldu, int npages, 117static int kportal_memhog_alloc(struct libcfs_device_userstate *ldu, int npages,
@@ -158,8 +123,8 @@ static int kportal_memhog_alloc(struct libcfs_device_userstate *ldu, int npages,
158 int count1; 123 int count1;
159 int count2; 124 int count2;
160 125
161 LASSERT (ldu->ldu_memhog_pages == 0); 126 LASSERT(ldu->ldu_memhog_pages == 0);
162 LASSERT (ldu->ldu_memhog_root_page == NULL); 127 LASSERT(ldu->ldu_memhog_root_page == NULL);
163 128
164 if (npages < 0) 129 if (npages < 0)
165 return -EINVAL; 130 return -EINVAL;
@@ -338,7 +303,7 @@ static int libcfs_ioctl_int(struct cfs_psdev_file *pfile, unsigned long cmd,
338 if (err != -EINVAL) { 303 if (err != -EINVAL) {
339 if (err == 0) 304 if (err == 0)
340 err = libcfs_ioctl_popdata(arg, 305 err = libcfs_ioctl_popdata(arg,
341 data, sizeof (*data)); 306 data, sizeof(*data));
342 break; 307 break;
343 } 308 }
344 } 309 }
@@ -361,7 +326,7 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, unsigned long cmd, void *a
361 return -ENOMEM; 326 return -ENOMEM;
362 327
363 /* 'cmd' and permissions get checked in our arch-specific caller */ 328 /* 'cmd' and permissions get checked in our arch-specific caller */
364 if (libcfs_ioctl_getdata(buf, buf + 800, (void *)arg)) { 329 if (libcfs_ioctl_getdata(buf, buf + 800, arg)) {
365 CERROR("PORTALS ioctl: data error\n"); 330 CERROR("PORTALS ioctl: data error\n");
366 err = -EINVAL; 331 err = -EINVAL;
367 goto out; 332 goto out;
@@ -428,17 +393,10 @@ static int init_libcfs_module(void)
428 goto cleanup_wi; 393 goto cleanup_wi;
429 } 394 }
430 395
396 insert_debugfs();
431 397
432 rc = insert_proc(); 398 CDEBUG(D_OTHER, "portals setup OK\n");
433 if (rc) {
434 CERROR("insert_proc: error %d\n", rc);
435 goto cleanup_crypto;
436 }
437
438 CDEBUG (D_OTHER, "portals setup OK\n");
439 return 0; 399 return 0;
440 cleanup_crypto:
441 cfs_crypto_unregister();
442 cleanup_wi: 400 cleanup_wi:
443 cfs_wi_shutdown(); 401 cfs_wi_shutdown();
444 cleanup_deregister: 402 cleanup_deregister:
@@ -454,10 +412,7 @@ static void exit_libcfs_module(void)
454{ 412{
455 int rc; 413 int rc;
456 414
457 remove_proc(); 415 remove_debugfs();
458
459 CDEBUG(D_MALLOC, "before Portals cleanup: kmem %d\n",
460 atomic_read(&libcfs_kmemory));
461 416
462 if (cfs_sched_rehash != NULL) { 417 if (cfs_sched_rehash != NULL) {
463 cfs_wi_sched_destroy(cfs_sched_rehash); 418 cfs_wi_sched_destroy(cfs_sched_rehash);
@@ -471,10 +426,6 @@ static void exit_libcfs_module(void)
471 426
472 cfs_cpu_fini(); 427 cfs_cpu_fini();
473 428
474 if (atomic_read(&libcfs_kmemory) != 0)
475 CERROR("Portals memory leaked: %d bytes\n",
476 atomic_read(&libcfs_kmemory));
477
478 rc = libcfs_debug_cleanup(); 429 rc = libcfs_debug_cleanup();
479 if (rc) 430 if (rc)
480 pr_err("LustreError: libcfs_debug_cleanup: %d\n", rc); 431 pr_err("LustreError: libcfs_debug_cleanup: %d\n", rc);
@@ -549,9 +500,6 @@ static int proc_dobitmasks(struct ctl_table *table, int write,
549 __proc_dobitmasks); 500 __proc_dobitmasks);
550} 501}
551 502
552static int min_watchdog_ratelimit; /* disable ratelimiting */
553static int max_watchdog_ratelimit = (24*60*60); /* limit to once per day */
554
555static int __proc_dump_kernel(void *data, int write, 503static int __proc_dump_kernel(void *data, int write,
556 loff_t pos, void __user *buffer, int nob) 504 loff_t pos, void __user *buffer, int nob)
557{ 505{
@@ -591,125 +539,6 @@ static int proc_daemon_file(struct ctl_table *table, int write,
591 __proc_daemon_file); 539 __proc_daemon_file);
592} 540}
593 541
594static int __proc_debug_mb(void *data, int write,
595 loff_t pos, void __user *buffer, int nob)
596{
597 if (!write) {
598 char tmpstr[32];
599 int len = snprintf(tmpstr, sizeof(tmpstr), "%d",
600 cfs_trace_get_debug_mb());
601
602 if (pos >= len)
603 return 0;
604
605 return cfs_trace_copyout_string(buffer, nob, tmpstr + pos,
606 "\n");
607 }
608
609 return cfs_trace_set_debug_mb_usrstr(buffer, nob);
610}
611
612static int proc_debug_mb(struct ctl_table *table, int write,
613 void __user *buffer, size_t *lenp, loff_t *ppos)
614{
615 return proc_call_handler(table->data, write, ppos, buffer, lenp,
616 __proc_debug_mb);
617}
618
619static int proc_console_max_delay_cs(struct ctl_table *table, int write,
620 void __user *buffer, size_t *lenp,
621 loff_t *ppos)
622{
623 int rc, max_delay_cs;
624 struct ctl_table dummy = *table;
625 long d;
626
627 dummy.data = &max_delay_cs;
628 dummy.proc_handler = &proc_dointvec;
629
630 if (!write) { /* read */
631 max_delay_cs = cfs_duration_sec(libcfs_console_max_delay * 100);
632 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
633 return rc;
634 }
635
636 /* write */
637 max_delay_cs = 0;
638 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
639 if (rc < 0)
640 return rc;
641 if (max_delay_cs <= 0)
642 return -EINVAL;
643
644 d = cfs_time_seconds(max_delay_cs) / 100;
645 if (d == 0 || d < libcfs_console_min_delay)
646 return -EINVAL;
647 libcfs_console_max_delay = d;
648
649 return rc;
650}
651
652static int proc_console_min_delay_cs(struct ctl_table *table, int write,
653 void __user *buffer, size_t *lenp,
654 loff_t *ppos)
655{
656 int rc, min_delay_cs;
657 struct ctl_table dummy = *table;
658 long d;
659
660 dummy.data = &min_delay_cs;
661 dummy.proc_handler = &proc_dointvec;
662
663 if (!write) { /* read */
664 min_delay_cs = cfs_duration_sec(libcfs_console_min_delay * 100);
665 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
666 return rc;
667 }
668
669 /* write */
670 min_delay_cs = 0;
671 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
672 if (rc < 0)
673 return rc;
674 if (min_delay_cs <= 0)
675 return -EINVAL;
676
677 d = cfs_time_seconds(min_delay_cs) / 100;
678 if (d == 0 || d > libcfs_console_max_delay)
679 return -EINVAL;
680 libcfs_console_min_delay = d;
681
682 return rc;
683}
684
685static int proc_console_backoff(struct ctl_table *table, int write,
686 void __user *buffer, size_t *lenp, loff_t *ppos)
687{
688 int rc, backoff;
689 struct ctl_table dummy = *table;
690
691 dummy.data = &backoff;
692 dummy.proc_handler = &proc_dointvec;
693
694 if (!write) { /* read */
695 backoff = libcfs_console_backoff;
696 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
697 return rc;
698 }
699
700 /* write */
701 backoff = 0;
702 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
703 if (rc < 0)
704 return rc;
705 if (backoff <= 0)
706 return -EINVAL;
707
708 libcfs_console_backoff = backoff;
709
710 return rc;
711}
712
713static int libcfs_force_lbug(struct ctl_table *table, int write, 542static int libcfs_force_lbug(struct ctl_table *table, int write,
714 void __user *buffer, 543 void __user *buffer,
715 size_t *lenp, loff_t *ppos) 544 size_t *lenp, loff_t *ppos)
@@ -807,40 +636,6 @@ static struct ctl_table lnet_table[] = {
807 .proc_handler = &proc_dobitmasks, 636 .proc_handler = &proc_dobitmasks,
808 }, 637 },
809 { 638 {
810 .procname = "console_ratelimit",
811 .data = &libcfs_console_ratelimit,
812 .maxlen = sizeof(int),
813 .mode = 0644,
814 .proc_handler = &proc_dointvec
815 },
816 {
817 .procname = "console_max_delay_centisecs",
818 .maxlen = sizeof(int),
819 .mode = 0644,
820 .proc_handler = &proc_console_max_delay_cs
821 },
822 {
823 .procname = "console_min_delay_centisecs",
824 .maxlen = sizeof(int),
825 .mode = 0644,
826 .proc_handler = &proc_console_min_delay_cs
827 },
828 {
829 .procname = "console_backoff",
830 .maxlen = sizeof(int),
831 .mode = 0644,
832 .proc_handler = &proc_console_backoff
833 },
834
835 {
836 .procname = "debug_path",
837 .data = libcfs_debug_file_path_arr,
838 .maxlen = sizeof(libcfs_debug_file_path_arr),
839 .mode = 0644,
840 .proc_handler = &proc_dostring,
841 },
842
843 {
844 .procname = "cpu_partition_table", 639 .procname = "cpu_partition_table",
845 .maxlen = 128, 640 .maxlen = 128,
846 .mode = 0444, 641 .mode = 0444,
@@ -862,13 +657,6 @@ static struct ctl_table lnet_table[] = {
862 .proc_handler = &proc_dostring, 657 .proc_handler = &proc_dostring,
863 }, 658 },
864 { 659 {
865 .procname = "lnet_memused",
866 .data = (int *)&libcfs_kmemory.counter,
867 .maxlen = sizeof(int),
868 .mode = 0444,
869 .proc_handler = &proc_dointvec,
870 },
871 {
872 .procname = "catastrophe", 660 .procname = "catastrophe",
873 .data = &libcfs_catastrophe, 661 .data = &libcfs_catastrophe,
874 .maxlen = sizeof(int), 662 .maxlen = sizeof(int),
@@ -876,13 +664,6 @@ static struct ctl_table lnet_table[] = {
876 .proc_handler = &proc_dointvec, 664 .proc_handler = &proc_dointvec,
877 }, 665 },
878 { 666 {
879 .procname = "panic_on_lbug",
880 .data = &libcfs_panic_on_lbug,
881 .maxlen = sizeof(int),
882 .mode = 0644,
883 .proc_handler = &proc_dointvec,
884 },
885 {
886 .procname = "dump_kernel", 667 .procname = "dump_kernel",
887 .maxlen = 256, 668 .maxlen = 256,
888 .mode = 0200, 669 .mode = 0200,
@@ -895,20 +676,6 @@ static struct ctl_table lnet_table[] = {
895 .proc_handler = &proc_daemon_file, 676 .proc_handler = &proc_daemon_file,
896 }, 677 },
897 { 678 {
898 .procname = "debug_mb",
899 .mode = 0644,
900 .proc_handler = &proc_debug_mb,
901 },
902 {
903 .procname = "watchdog_ratelimit",
904 .data = &libcfs_watchdog_ratelimit,
905 .maxlen = sizeof(int),
906 .mode = 0644,
907 .proc_handler = &proc_dointvec_minmax,
908 .extra1 = &min_watchdog_ratelimit,
909 .extra2 = &max_watchdog_ratelimit,
910 },
911 {
912 .procname = "force_lbug", 679 .procname = "force_lbug",
913 .data = NULL, 680 .data = NULL,
914 .maxlen = 0, 681 .maxlen = 0,
@@ -933,31 +700,93 @@ static struct ctl_table lnet_table[] = {
933 } 700 }
934}; 701};
935 702
936static struct ctl_table top_table[] = { 703struct lnet_debugfs_symlink_def {
937 { 704 char *name;
938 .procname = "lnet", 705 char *target;
939 .mode = 0555,
940 .data = NULL,
941 .maxlen = 0,
942 .child = lnet_table,
943 },
944 {
945 }
946}; 706};
947 707
948static int insert_proc(void) 708static const struct lnet_debugfs_symlink_def lnet_debugfs_symlinks[] = {
709 { "console_ratelimit",
710 "/sys/module/libcfs/parameters/libcfs_console_ratelimit"},
711 { "debug_path",
712 "/sys/module/libcfs/parameters/libcfs_debug_file_path"},
713 { "panic_on_lbug",
714 "/sys/module/libcfs/parameters/libcfs_panic_on_lbug"},
715 { "libcfs_console_backoff",
716 "/sys/module/libcfs/parameters/libcfs_console_backoff"},
717 { "debug_mb",
718 "/sys/module/libcfs/parameters/libcfs_debug_mb"},
719 { "console_min_delay_centisecs",
720 "/sys/module/libcfs/parameters/libcfs_console_min_delay"},
721 { "console_max_delay_centisecs",
722 "/sys/module/libcfs/parameters/libcfs_console_max_delay"},
723 {},
724};
725
726static ssize_t lnet_debugfs_read(struct file *filp, char __user *buf,
727 size_t count, loff_t *ppos)
949{ 728{
950 if (lnet_table_header == NULL) 729 struct ctl_table *table = filp->private_data;
951 lnet_table_header = register_sysctl_table(top_table); 730 int error;
952 return 0; 731
732 error = table->proc_handler(table, 0, (void __user *)buf, &count, ppos);
733 if (!error)
734 error = count;
735
736 return error;
737}
738
739static ssize_t lnet_debugfs_write(struct file *filp, const char __user *buf,
740 size_t count, loff_t *ppos)
741{
742 struct ctl_table *table = filp->private_data;
743 int error;
744
745 error = table->proc_handler(table, 1, (void __user *)buf, &count, ppos);
746 if (!error)
747 error = count;
748
749 return error;
750}
751
752static const struct file_operations lnet_debugfs_file_operations = {
753 .open = simple_open,
754 .read = lnet_debugfs_read,
755 .write = lnet_debugfs_write,
756 .llseek = default_llseek,
757};
758
759static void insert_debugfs(void)
760{
761 struct ctl_table *table;
762 struct dentry *entry;
763 const struct lnet_debugfs_symlink_def *symlinks;
764
765 if (lnet_debugfs_root == NULL)
766 lnet_debugfs_root = debugfs_create_dir("lnet", NULL);
767
768 /* Even if we cannot create, just ignore it altogether) */
769 if (IS_ERR_OR_NULL(lnet_debugfs_root))
770 return;
771
772 for (table = lnet_table; table->procname; table++)
773 entry = debugfs_create_file(table->procname, table->mode,
774 lnet_debugfs_root, table,
775 &lnet_debugfs_file_operations);
776
777 for (symlinks = lnet_debugfs_symlinks; symlinks->name; symlinks++)
778 entry = debugfs_create_symlink(symlinks->name,
779 lnet_debugfs_root,
780 symlinks->target);
781
953} 782}
954 783
955static void remove_proc(void) 784static void remove_debugfs(void)
956{ 785{
957 if (lnet_table_header != NULL) 786 if (lnet_debugfs_root != NULL)
958 unregister_sysctl_table(lnet_table_header); 787 debugfs_remove_recursive(lnet_debugfs_root);
959 788
960 lnet_table_header = NULL; 789 lnet_debugfs_root = NULL;
961} 790}
962 791
963MODULE_VERSION("1.0.0"); 792MODULE_VERSION("1.0.0");
diff --git a/drivers/staging/lustre/lustre/libcfs/tracefile.c b/drivers/staging/lustre/lustre/libcfs/tracefile.c
index 6ee2adcf8890..effa2af58c13 100644
--- a/drivers/staging/lustre/lustre/libcfs/tracefile.c
+++ b/drivers/staging/lustre/lustre/libcfs/tracefile.c
@@ -937,18 +937,6 @@ int cfs_trace_set_debug_mb(int mb)
937 return 0; 937 return 0;
938} 938}
939 939
940int cfs_trace_set_debug_mb_usrstr(void __user *usr_str, int usr_str_nob)
941{
942 char str[32];
943 int rc;
944
945 rc = cfs_trace_copyin_string(str, sizeof(str), usr_str, usr_str_nob);
946 if (rc < 0)
947 return rc;
948
949 return cfs_trace_set_debug_mb(simple_strtoul(str, NULL, 0));
950}
951
952int cfs_trace_get_debug_mb(void) 940int cfs_trace_get_debug_mb(void)
953{ 941{
954 int i; 942 int i;
diff --git a/drivers/staging/lustre/lustre/libcfs/tracefile.h b/drivers/staging/lustre/lustre/libcfs/tracefile.h
index 0601476e1dc3..e931f6d98de9 100644
--- a/drivers/staging/lustre/lustre/libcfs/tracefile.h
+++ b/drivers/staging/lustre/lustre/libcfs/tracefile.h
@@ -47,7 +47,7 @@
47extern char cfs_tracefile[TRACEFILE_NAME_SIZE]; 47extern char cfs_tracefile[TRACEFILE_NAME_SIZE];
48extern long long cfs_tracefile_size; 48extern long long cfs_tracefile_size;
49 49
50extern void libcfs_run_debug_log_upcall(char *file); 50void libcfs_run_debug_log_upcall(char *file);
51 51
52int cfs_tracefile_init_arch(void); 52int cfs_tracefile_init_arch(void);
53void cfs_tracefile_fini_arch(void); 53void cfs_tracefile_fini_arch(void);
@@ -77,14 +77,13 @@ int cfs_trace_dump_debug_buffer_usrstr(void __user *usr_str, int usr_str_nob);
77int cfs_trace_daemon_command(char *str); 77int cfs_trace_daemon_command(char *str);
78int cfs_trace_daemon_command_usrstr(void __user *usr_str, int usr_str_nob); 78int cfs_trace_daemon_command_usrstr(void __user *usr_str, int usr_str_nob);
79int cfs_trace_set_debug_mb(int mb); 79int cfs_trace_set_debug_mb(int mb);
80int cfs_trace_set_debug_mb_usrstr(void __user *usr_str, int usr_str_nob);
81int cfs_trace_get_debug_mb(void); 80int cfs_trace_get_debug_mb(void);
82 81
83extern void libcfs_debug_dumplog_internal(void *arg); 82void libcfs_debug_dumplog_internal(void *arg);
84extern void libcfs_register_panic_notifier(void); 83void libcfs_register_panic_notifier(void);
85extern void libcfs_unregister_panic_notifier(void); 84void libcfs_unregister_panic_notifier(void);
86extern int libcfs_panic_in_progress; 85extern int libcfs_panic_in_progress;
87extern int cfs_trace_max_debug_mb(void); 86int cfs_trace_max_debug_mb(void);
88 87
89#define TCD_MAX_PAGES (5 << (20 - PAGE_CACHE_SHIFT)) 88#define TCD_MAX_PAGES (5 << (20 - PAGE_CACHE_SHIFT))
90#define TCD_STOCK_PAGES (TCD_MAX_PAGES) 89#define TCD_STOCK_PAGES (TCD_MAX_PAGES)
@@ -253,15 +252,15 @@ struct cfs_trace_page {
253 unsigned short type; 252 unsigned short type;
254}; 253};
255 254
256extern void cfs_set_ptldebug_header(struct ptldebug_header *header, 255void cfs_set_ptldebug_header(struct ptldebug_header *header,
257 struct libcfs_debug_msg_data *m, 256 struct libcfs_debug_msg_data *m,
258 unsigned long stack); 257 unsigned long stack);
259extern void cfs_print_to_console(struct ptldebug_header *hdr, int mask, 258void cfs_print_to_console(struct ptldebug_header *hdr, int mask,
260 const char *buf, int len, const char *file, 259 const char *buf, int len, const char *file,
261 const char *fn); 260 const char *fn);
262 261
263extern int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking); 262int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking);
264extern void cfs_trace_unlock_tcd(struct cfs_trace_cpu_data *tcd, int walking); 263void cfs_trace_unlock_tcd(struct cfs_trace_cpu_data *tcd, int walking);
265 264
266/** 265/**
267 * trace_buf_type_t, trace_buf_idx_get() and trace_console_buffers[][] 266 * trace_buf_type_t, trace_buf_idx_get() and trace_console_buffers[][]
@@ -271,7 +270,7 @@ extern void cfs_trace_unlock_tcd(struct cfs_trace_cpu_data *tcd, int walking);
271 */ 270 */
272 271
273extern char *cfs_trace_console_buffers[NR_CPUS][CFS_TCD_TYPE_MAX]; 272extern char *cfs_trace_console_buffers[NR_CPUS][CFS_TCD_TYPE_MAX];
274extern cfs_trace_buf_type_t cfs_trace_buf_idx_get(void); 273cfs_trace_buf_type_t cfs_trace_buf_idx_get(void);
275 274
276static inline char * 275static inline char *
277cfs_trace_get_console_buffer(void) 276cfs_trace_get_console_buffer(void)
@@ -314,8 +313,8 @@ int cfs_trace_refill_stock(struct cfs_trace_cpu_data *tcd, gfp_t gfp,
314int cfs_tcd_owns_tage(struct cfs_trace_cpu_data *tcd, 313int cfs_tcd_owns_tage(struct cfs_trace_cpu_data *tcd,
315 struct cfs_trace_page *tage); 314 struct cfs_trace_page *tage);
316 315
317extern void cfs_trace_assertion_failed(const char *str, 316void cfs_trace_assertion_failed(const char *str,
318 struct libcfs_debug_msg_data *m); 317 struct libcfs_debug_msg_data *m);
319 318
320/* ASSERTION that is safe to use within the debug system */ 319/* ASSERTION that is safe to use within the debug system */
321#define __LASSERT(cond) \ 320#define __LASSERT(cond) \
diff --git a/drivers/staging/lustre/lustre/llite/dcache.c b/drivers/staging/lustre/lustre/llite/dcache.c
index 7b008a64707d..b86685912d28 100644
--- a/drivers/staging/lustre/lustre/llite/dcache.c
+++ b/drivers/staging/lustre/lustre/llite/dcache.c
@@ -250,7 +250,6 @@ void ll_intent_release(struct lookup_intent *it)
250void ll_invalidate_aliases(struct inode *inode) 250void ll_invalidate_aliases(struct inode *inode)
251{ 251{
252 struct dentry *dentry; 252 struct dentry *dentry;
253 struct ll_d_hlist_node *p;
254 253
255 LASSERT(inode != NULL); 254 LASSERT(inode != NULL);
256 255
@@ -258,7 +257,7 @@ void ll_invalidate_aliases(struct inode *inode)
258 inode->i_ino, inode->i_generation, inode); 257 inode->i_ino, inode->i_generation, inode);
259 258
260 ll_lock_dcache(inode); 259 ll_lock_dcache(inode);
261 ll_d_hlist_for_each_entry(dentry, p, &inode->i_dentry, d_u.d_alias) { 260 hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
262 CDEBUG(D_DENTRY, "dentry in drop %pd (%p) parent %p inode %p flags %d\n", 261 CDEBUG(D_DENTRY, "dentry in drop %pd (%p) parent %p inode %p flags %d\n",
263 dentry, dentry, dentry->d_parent, 262 dentry, dentry, dentry->d_parent,
264 d_inode(dentry), dentry->d_flags); 263 d_inode(dentry), dentry->d_flags);
diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
index 3d746a94f92e..769b61193d87 100644
--- a/drivers/staging/lustre/lustre/llite/dir.c
+++ b/drivers/staging/lustre/lustre/llite/dir.c
@@ -203,7 +203,6 @@ static int ll_dir_filler(void *_hash, struct page *page0)
203 203
204 CDEBUG(D_VFSTRACE, "read %d/%d pages\n", nrdpgs, npages); 204 CDEBUG(D_VFSTRACE, "read %d/%d pages\n", nrdpgs, npages);
205 205
206 ll_pagevec_init(&lru_pvec, 0);
207 for (i = 1; i < npages; i++) { 206 for (i = 1; i < npages; i++) {
208 unsigned long offset; 207 unsigned long offset;
209 int ret; 208 int ret;
@@ -228,15 +227,12 @@ static int ll_dir_filler(void *_hash, struct page *page0)
228 GFP_KERNEL); 227 GFP_KERNEL);
229 if (ret == 0) { 228 if (ret == 0) {
230 unlock_page(page); 229 unlock_page(page);
231 if (ll_pagevec_add(&lru_pvec, page) == 0)
232 ll_pagevec_lru_add_file(&lru_pvec);
233 } else { 230 } else {
234 CDEBUG(D_VFSTRACE, "page %lu add to page cache failed: %d\n", 231 CDEBUG(D_VFSTRACE, "page %lu add to page cache failed: %d\n",
235 offset, ret); 232 offset, ret);
236 } 233 }
237 page_cache_release(page); 234 page_cache_release(page);
238 } 235 }
239 ll_pagevec_lru_add_file(&lru_pvec);
240 236
241 if (page_pool != &page0) 237 if (page_pool != &page0)
242 kfree(page_pool); 238 kfree(page_pool);
diff --git a/drivers/staging/lustre/lustre/llite/file.c b/drivers/staging/lustre/lustre/llite/file.c
index 3075db211106..dcd0c6d65efb 100644
--- a/drivers/staging/lustre/lustre/llite/file.c
+++ b/drivers/staging/lustre/lustre/llite/file.c
@@ -702,8 +702,7 @@ out_och_free:
702out_openerr: 702out_openerr:
703 if (opendir_set != 0) 703 if (opendir_set != 0)
704 ll_stop_statahead(inode, lli->lli_opendir_key); 704 ll_stop_statahead(inode, lli->lli_opendir_key);
705 if (fd != NULL) 705 ll_file_data_put(fd);
706 ll_file_data_put(fd);
707 } else { 706 } else {
708 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_OPEN, 1); 707 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_OPEN, 1);
709 } 708 }
@@ -3005,7 +3004,7 @@ int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat)
3005 struct inode *inode = d_inode(de); 3004 struct inode *inode = d_inode(de);
3006 struct ll_sb_info *sbi = ll_i2sbi(inode); 3005 struct ll_sb_info *sbi = ll_i2sbi(inode);
3007 struct ll_inode_info *lli = ll_i2info(inode); 3006 struct ll_inode_info *lli = ll_i2info(inode);
3008 int res = 0; 3007 int res;
3009 3008
3010 res = ll_inode_revalidate(de, MDS_INODELOCK_UPDATE | 3009 res = ll_inode_revalidate(de, MDS_INODELOCK_UPDATE |
3011 MDS_INODELOCK_LOOKUP); 3010 MDS_INODELOCK_LOOKUP);
diff --git a/drivers/staging/lustre/lustre/llite/llite_capa.c b/drivers/staging/lustre/lustre/llite/llite_capa.c
index a6268718b76e..24590ae36090 100644
--- a/drivers/staging/lustre/lustre/llite/llite_capa.c
+++ b/drivers/staging/lustre/lustre/llite/llite_capa.c
@@ -70,7 +70,8 @@ static unsigned long long ll_capa_renewal_retries;
70 70
71static int ll_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa); 71static int ll_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa);
72 72
73static inline void update_capa_timer(struct obd_capa *ocapa, unsigned long expiry) 73static inline void update_capa_timer(struct obd_capa *ocapa,
74 unsigned long expiry)
74{ 75{
75 if (time_before(expiry, ll_capa_timer.expires) || 76 if (time_before(expiry, ll_capa_timer.expires) ||
76 !timer_pending(&ll_capa_timer)) { 77 !timer_pending(&ll_capa_timer)) {
@@ -102,13 +103,13 @@ static inline int have_expired_capa(void)
102 spin_lock(&capa_lock); 103 spin_lock(&capa_lock);
103 if (!list_empty(ll_capa_list)) { 104 if (!list_empty(ll_capa_list)) {
104 ocapa = list_entry(ll_capa_list->next, struct obd_capa, 105 ocapa = list_entry(ll_capa_list->next, struct obd_capa,
105 c_list); 106 c_list);
106 expired = capa_is_to_expire(ocapa); 107 expired = capa_is_to_expire(ocapa);
107 if (!expired) 108 if (!expired)
108 update_capa_timer(ocapa, capa_renewal_time(ocapa)); 109 update_capa_timer(ocapa, capa_renewal_time(ocapa));
109 } else if (!list_empty(&ll_idle_capas)) { 110 } else if (!list_empty(&ll_idle_capas)) {
110 ocapa = list_entry(ll_idle_capas.next, struct obd_capa, 111 ocapa = list_entry(ll_idle_capas.next, struct obd_capa,
111 c_list); 112 c_list);
112 expired = capa_is_expired(ocapa); 113 expired = capa_is_expired(ocapa);
113 if (!expired) 114 if (!expired)
114 update_capa_timer(ocapa, ocapa->c_expiry); 115 update_capa_timer(ocapa, ocapa->c_expiry);
@@ -165,7 +166,8 @@ static void ll_delete_capa(struct obd_capa *ocapa)
165/* three places where client capa is deleted: 166/* three places where client capa is deleted:
166 * 1. capa_thread_main(), main place to delete expired capa. 167 * 1. capa_thread_main(), main place to delete expired capa.
167 * 2. ll_clear_inode_capas() in ll_clear_inode(). 168 * 2. ll_clear_inode_capas() in ll_clear_inode().
168 * 3. ll_truncate_free_capa() delete truncate capa explicitly in ll_setattr_ost(). 169 * 3. ll_truncate_free_capa() delete truncate capa explicitly in
170 * ll_setattr_ost().
169 */ 171 */
170static int capa_thread_main(void *unused) 172static int capa_thread_main(void *unused)
171{ 173{
@@ -206,7 +208,8 @@ static int capa_thread_main(void *unused)
206 * lock. 208 * lock.
207 */ 209 */
208 /* ibits may be changed by ll_have_md_lock() so we have 210 /* ibits may be changed by ll_have_md_lock() so we have
209 * to set it each time */ 211 * to set it each time
212 */
210 ibits = MDS_INODELOCK_LOOKUP; 213 ibits = MDS_INODELOCK_LOOKUP;
211 if (capa_for_mds(&ocapa->c_capa) && 214 if (capa_for_mds(&ocapa->c_capa) &&
212 !S_ISDIR(ocapa->u.cli.inode->i_mode) && 215 !S_ISDIR(ocapa->u.cli.inode->i_mode) &&
@@ -225,14 +228,15 @@ static int capa_thread_main(void *unused)
225 if (capa_for_oss(&ocapa->c_capa) && 228 if (capa_for_oss(&ocapa->c_capa) &&
226 obd_capa_open_count(ocapa) == 0) { 229 obd_capa_open_count(ocapa) == 0) {
227 /* oss capa with open count == 0 won't renew, 230 /* oss capa with open count == 0 won't renew,
228 * move to idle list */ 231 * move to idle list
232 */
229 sort_add_capa(ocapa, &ll_idle_capas); 233 sort_add_capa(ocapa, &ll_idle_capas);
230 continue; 234 continue;
231 } 235 }
232 236
233 /* NB iput() is in ll_update_capa() */ 237 /* NB iput() is in ll_update_capa() */
234 inode = igrab(ocapa->u.cli.inode); 238 inode = igrab(ocapa->u.cli.inode);
235 if (inode == NULL) { 239 if (!inode) {
236 DEBUG_CAPA(D_ERROR, &ocapa->c_capa, 240 DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
237 "igrab failed for"); 241 "igrab failed for");
238 continue; 242 continue;
@@ -255,7 +259,7 @@ static int capa_thread_main(void *unused)
255 update_capa_timer(next, capa_renewal_time(next)); 259 update_capa_timer(next, capa_renewal_time(next));
256 260
257 list_for_each_entry_safe(ocapa, tmp, &ll_idle_capas, 261 list_for_each_entry_safe(ocapa, tmp, &ll_idle_capas,
258 c_list) { 262 c_list) {
259 if (!capa_is_expired(ocapa)) { 263 if (!capa_is_expired(ocapa)) {
260 if (!next) 264 if (!next)
261 update_capa_timer(ocapa, 265 update_capa_timer(ocapa,
@@ -299,11 +303,11 @@ int ll_capa_thread_start(void)
299 task = kthread_run(capa_thread_main, NULL, "ll_capa"); 303 task = kthread_run(capa_thread_main, NULL, "ll_capa");
300 if (IS_ERR(task)) { 304 if (IS_ERR(task)) {
301 CERROR("cannot start expired capa thread: rc %ld\n", 305 CERROR("cannot start expired capa thread: rc %ld\n",
302 PTR_ERR(task)); 306 PTR_ERR(task));
303 return PTR_ERR(task); 307 return PTR_ERR(task);
304 } 308 }
305 wait_event(ll_capa_thread.t_ctl_waitq, 309 wait_event(ll_capa_thread.t_ctl_waitq,
306 thread_is_running(&ll_capa_thread)); 310 thread_is_running(&ll_capa_thread));
307 311
308 return 0; 312 return 0;
309} 313}
@@ -313,7 +317,7 @@ void ll_capa_thread_stop(void)
313 thread_set_flags(&ll_capa_thread, SVC_STOPPING); 317 thread_set_flags(&ll_capa_thread, SVC_STOPPING);
314 wake_up(&ll_capa_thread.t_ctl_waitq); 318 wake_up(&ll_capa_thread.t_ctl_waitq);
315 wait_event(ll_capa_thread.t_ctl_waitq, 319 wait_event(ll_capa_thread.t_ctl_waitq,
316 thread_is_stopped(&ll_capa_thread)); 320 thread_is_stopped(&ll_capa_thread));
317} 321}
318 322
319struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc) 323struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc)
@@ -360,7 +364,7 @@ struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc)
360 ocapa = NULL; 364 ocapa = NULL;
361 365
362 if (atomic_read(&ll_capa_debug)) { 366 if (atomic_read(&ll_capa_debug)) {
363 CERROR("no capability for "DFID" opc %#llx\n", 367 CERROR("no capability for " DFID " opc %#llx\n",
364 PFID(&lli->lli_fid), opc); 368 PFID(&lli->lli_fid), opc);
365 atomic_set(&ll_capa_debug, 0); 369 atomic_set(&ll_capa_debug, 0);
366 } 370 }
@@ -376,7 +380,7 @@ struct obd_capa *ll_mdscapa_get(struct inode *inode)
376 struct ll_inode_info *lli = ll_i2info(inode); 380 struct ll_inode_info *lli = ll_i2info(inode);
377 struct obd_capa *ocapa; 381 struct obd_capa *ocapa;
378 382
379 LASSERT(inode != NULL); 383 LASSERT(inode);
380 384
381 if ((ll_i2sbi(inode)->ll_flags & LL_SBI_MDS_CAPA) == 0) 385 if ((ll_i2sbi(inode)->ll_flags & LL_SBI_MDS_CAPA) == 0)
382 return NULL; 386 return NULL;
@@ -385,7 +389,7 @@ struct obd_capa *ll_mdscapa_get(struct inode *inode)
385 ocapa = capa_get(lli->lli_mds_capa); 389 ocapa = capa_get(lli->lli_mds_capa);
386 spin_unlock(&capa_lock); 390 spin_unlock(&capa_lock);
387 if (!ocapa && atomic_read(&ll_capa_debug)) { 391 if (!ocapa && atomic_read(&ll_capa_debug)) {
388 CERROR("no mds capability for "DFID"\n", PFID(&lli->lli_fid)); 392 CERROR("no mds capability for " DFID "\n", PFID(&lli->lli_fid));
389 atomic_set(&ll_capa_debug, 0); 393 atomic_set(&ll_capa_debug, 0);
390 } 394 }
391 395
@@ -447,7 +451,8 @@ static inline void inode_add_oss_capa(struct inode *inode,
447 struct list_head *next = NULL; 451 struct list_head *next = NULL;
448 452
449 /* capa is sorted in lli_oss_capas so lookup can always find the 453 /* capa is sorted in lli_oss_capas so lookup can always find the
450 * latest one */ 454 * latest one
455 */
451 list_for_each_entry(tmp, &lli->lli_oss_capas, u.cli.lli_list) { 456 list_for_each_entry(tmp, &lli->lli_oss_capas, u.cli.lli_list) {
452 if (cfs_time_after(ocapa->c_expiry, tmp->c_expiry)) { 457 if (cfs_time_after(ocapa->c_expiry, tmp->c_expiry)) {
453 next = &tmp->u.cli.lli_list; 458 next = &tmp->u.cli.lli_list;
@@ -537,7 +542,8 @@ static int ll_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa)
537 ll_capa_renewal_failed++; 542 ll_capa_renewal_failed++;
538 543
539 /* failed capa won't be renewed any longer, but if -EIO, 544 /* failed capa won't be renewed any longer, but if -EIO,
540 * client might be doing recovery, retry in 2 min. */ 545 * client might be doing recovery, retry in 2 min.
546 */
541 if (rc == -EIO && !capa_is_expired(ocapa)) { 547 if (rc == -EIO && !capa_is_expired(ocapa)) {
542 delay_capa_renew(ocapa, 120); 548 delay_capa_renew(ocapa, 120);
543 DEBUG_CAPA(D_ERROR, &ocapa->c_capa, 549 DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
@@ -638,7 +644,7 @@ void ll_clear_inode_capas(struct inode *inode)
638 ll_delete_capa(ocapa); 644 ll_delete_capa(ocapa);
639 645
640 list_for_each_entry_safe(ocapa, tmp, &lli->lli_oss_capas, 646 list_for_each_entry_safe(ocapa, tmp, &lli->lli_oss_capas,
641 u.cli.lli_list) 647 u.cli.lli_list)
642 ll_delete_capa(ocapa); 648 ll_delete_capa(ocapa);
643 spin_unlock(&capa_lock); 649 spin_unlock(&capa_lock);
644} 650}
diff --git a/drivers/staging/lustre/lustre/llite/llite_internal.h b/drivers/staging/lustre/lustre/llite/llite_internal.h
index f097d4d167d5..ec8fff463208 100644
--- a/drivers/staging/lustre/lustre/llite/llite_internal.h
+++ b/drivers/staging/lustre/lustre/llite/llite_internal.h
@@ -456,7 +456,6 @@ struct eacl_table {
456}; 456};
457 457
458struct ll_sb_info { 458struct ll_sb_info {
459 struct list_head ll_list;
460 /* this protects pglist and ra_info. It isn't safe to 459 /* this protects pglist and ra_info. It isn't safe to
461 * grab from interrupt contexts */ 460 * grab from interrupt contexts */
462 spinlock_t ll_lock; 461 spinlock_t ll_lock;
@@ -711,11 +710,11 @@ extern struct file_operations ll_file_operations;
711extern struct file_operations ll_file_operations_flock; 710extern struct file_operations ll_file_operations_flock;
712extern struct file_operations ll_file_operations_noflock; 711extern struct file_operations ll_file_operations_noflock;
713extern struct inode_operations ll_file_inode_operations; 712extern struct inode_operations ll_file_inode_operations;
714extern int ll_have_md_lock(struct inode *inode, __u64 *bits, 713int ll_have_md_lock(struct inode *inode, __u64 *bits,
715 ldlm_mode_t l_req_mode); 714 ldlm_mode_t l_req_mode);
716extern ldlm_mode_t ll_take_md_lock(struct inode *inode, __u64 bits, 715ldlm_mode_t ll_take_md_lock(struct inode *inode, __u64 bits,
717 struct lustre_handle *lockh, __u64 flags, 716 struct lustre_handle *lockh, __u64 flags,
718 ldlm_mode_t mode); 717 ldlm_mode_t mode);
719int ll_file_open(struct inode *inode, struct file *file); 718int ll_file_open(struct inode *inode, struct file *file);
720int ll_file_release(struct inode *inode, struct file *file); 719int ll_file_release(struct inode *inode, struct file *file);
721int ll_glimpse_ioctl(struct ll_sb_info *sbi, 720int ll_glimpse_ioctl(struct ll_sb_info *sbi,
@@ -1376,9 +1375,9 @@ static inline void cl_stats_tally(struct cl_device *dev, enum cl_req_type crt,
1376 ll_stats_ops_tally(ll_s2sbi(cl2ccc_dev(dev)->cdv_sb), opc, rc); 1375 ll_stats_ops_tally(ll_s2sbi(cl2ccc_dev(dev)->cdv_sb), opc, rc);
1377} 1376}
1378 1377
1379extern ssize_t ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io, 1378ssize_t ll_direct_rw_pages(const struct lu_env *env, struct cl_io *io,
1380 int rw, struct inode *inode, 1379 int rw, struct inode *inode,
1381 struct ll_dio_pages *pv); 1380 struct ll_dio_pages *pv);
1382 1381
1383static inline int ll_file_nolock(const struct file *file) 1382static inline int ll_file_nolock(const struct file *file)
1384{ 1383{
diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c
index 25139885b5a7..b4ed6c89af3d 100644
--- a/drivers/staging/lustre/lustre/llite/llite_lib.c
+++ b/drivers/staging/lustre/lustre/llite/llite_lib.c
@@ -60,9 +60,6 @@ struct kmem_cache *ll_file_data_slab;
60struct dentry *llite_root; 60struct dentry *llite_root;
61struct kset *llite_kset; 61struct kset *llite_kset;
62 62
63static LIST_HEAD(ll_super_blocks);
64static DEFINE_SPINLOCK(ll_sb_lock);
65
66#ifndef log2 63#ifndef log2
67#define log2(n) ffz(~(n)) 64#define log2(n) ffz(~(n))
68#endif 65#endif
@@ -112,10 +109,6 @@ static struct ll_sb_info *ll_init_sbi(struct super_block *sb)
112 class_uuid_unparse(uuid, &sbi->ll_sb_uuid); 109 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
113 CDEBUG(D_CONFIG, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid); 110 CDEBUG(D_CONFIG, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid);
114 111
115 spin_lock(&ll_sb_lock);
116 list_add_tail(&sbi->ll_list, &ll_super_blocks);
117 spin_unlock(&ll_sb_lock);
118
119 sbi->ll_flags |= LL_SBI_VERBOSE; 112 sbi->ll_flags |= LL_SBI_VERBOSE;
120 sbi->ll_flags |= LL_SBI_CHECKSUM; 113 sbi->ll_flags |= LL_SBI_CHECKSUM;
121 114
@@ -144,12 +137,7 @@ static void ll_free_sbi(struct super_block *sb)
144{ 137{
145 struct ll_sb_info *sbi = ll_s2sbi(sb); 138 struct ll_sb_info *sbi = ll_s2sbi(sb);
146 139
147 if (sbi != NULL) { 140 kfree(sbi);
148 spin_lock(&ll_sb_lock);
149 list_del(&sbi->ll_list);
150 spin_unlock(&ll_sb_lock);
151 kfree(sbi);
152 }
153} 141}
154 142
155static int client_common_fill_super(struct super_block *sb, char *md, char *dt, 143static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
@@ -1114,7 +1102,7 @@ void ll_clear_inode(struct inode *inode)
1114 if (lli->lli_mds_read_och) 1102 if (lli->lli_mds_read_och)
1115 ll_md_real_close(inode, FMODE_READ); 1103 ll_md_real_close(inode, FMODE_READ);
1116 1104
1117 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) { 1105 if (S_ISLNK(inode->i_mode)) {
1118 kfree(lli->lli_symlink_name); 1106 kfree(lli->lli_symlink_name);
1119 lli->lli_symlink_name = NULL; 1107 lli->lli_symlink_name = NULL;
1120 } 1108 }
@@ -1150,6 +1138,8 @@ void ll_clear_inode(struct inode *inode)
1150 lli->lli_has_smd = false; 1138 lli->lli_has_smd = false;
1151} 1139}
1152 1140
1141#define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
1142
1153static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data, 1143static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data,
1154 struct md_open_data **mod) 1144 struct md_open_data **mod)
1155{ 1145{
@@ -1354,11 +1344,8 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
1354 if (!op_data) 1344 if (!op_data)
1355 return -ENOMEM; 1345 return -ENOMEM;
1356 1346
1357 if (!S_ISDIR(inode->i_mode)) { 1347 if (!S_ISDIR(inode->i_mode))
1358 if (attr->ia_valid & ATTR_SIZE)
1359 inode_dio_write_done(inode);
1360 mutex_unlock(&inode->i_mutex); 1348 mutex_unlock(&inode->i_mutex);
1361 }
1362 1349
1363 memcpy(&op_data->op_attr, attr, sizeof(*attr)); 1350 memcpy(&op_data->op_attr, attr, sizeof(*attr));
1364 1351
diff --git a/drivers/staging/lustre/lustre/llite/lloop.c b/drivers/staging/lustre/lustre/llite/lloop.c
index cc00fd10fbcf..06f5e51ecd9e 100644
--- a/drivers/staging/lustre/lustre/llite/lloop.c
+++ b/drivers/staging/lustre/lustre/llite/lloop.c
@@ -162,7 +162,7 @@ static int max_loop = MAX_LOOP_DEFAULT;
162static struct lloop_device *loop_dev; 162static struct lloop_device *loop_dev;
163static struct gendisk **disks; 163static struct gendisk **disks;
164static struct mutex lloop_mutex; 164static struct mutex lloop_mutex;
165static void *ll_iocontrol_magic = NULL; 165static void *ll_iocontrol_magic;
166 166
167static loff_t get_loop_size(struct lloop_device *lo, struct file *file) 167static loff_t get_loop_size(struct lloop_device *lo, struct file *file)
168{ 168{
@@ -365,7 +365,7 @@ static void loop_make_request(struct request_queue *q, struct bio *old_bio)
365 loop_add_bio(lo, old_bio); 365 loop_add_bio(lo, old_bio);
366 return; 366 return;
367err: 367err:
368 cfs_bio_io_error(old_bio, old_bio->bi_iter.bi_size); 368 bio_io_error(old_bio);
369} 369}
370 370
371 371
@@ -376,7 +376,7 @@ static inline void loop_handle_bio(struct lloop_device *lo, struct bio *bio)
376 while (bio) { 376 while (bio) {
377 struct bio *tmp = bio->bi_next; 377 struct bio *tmp = bio->bi_next;
378 bio->bi_next = NULL; 378 bio->bi_next = NULL;
379 cfs_bio_endio(bio, bio->bi_iter.bi_size, ret); 379 bio_endio(bio, ret);
380 bio = tmp; 380 bio = tmp;
381 } 381 }
382} 382}
diff --git a/drivers/staging/lustre/lustre/llite/namei.c b/drivers/staging/lustre/lustre/llite/namei.c
index 72ce6e72845f..05e7dc85989e 100644
--- a/drivers/staging/lustre/lustre/llite/namei.c
+++ b/drivers/staging/lustre/lustre/llite/namei.c
@@ -144,10 +144,9 @@ struct inode *ll_iget(struct super_block *sb, ino_t hash,
144static void ll_invalidate_negative_children(struct inode *dir) 144static void ll_invalidate_negative_children(struct inode *dir)
145{ 145{
146 struct dentry *dentry, *tmp_subdir; 146 struct dentry *dentry, *tmp_subdir;
147 struct ll_d_hlist_node *p;
148 147
149 ll_lock_dcache(dir); 148 ll_lock_dcache(dir);
150 ll_d_hlist_for_each_entry(dentry, p, &dir->i_dentry, d_u.d_alias) { 149 hlist_for_each_entry(dentry, &dir->i_dentry, d_u.d_alias) {
151 spin_lock(&dentry->d_lock); 150 spin_lock(&dentry->d_lock);
152 if (!list_empty(&dentry->d_subdirs)) { 151 if (!list_empty(&dentry->d_subdirs)) {
153 struct dentry *child; 152 struct dentry *child;
@@ -334,15 +333,14 @@ void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2)
334static struct dentry *ll_find_alias(struct inode *inode, struct dentry *dentry) 333static struct dentry *ll_find_alias(struct inode *inode, struct dentry *dentry)
335{ 334{
336 struct dentry *alias, *discon_alias, *invalid_alias; 335 struct dentry *alias, *discon_alias, *invalid_alias;
337 struct ll_d_hlist_node *p;
338 336
339 if (ll_d_hlist_empty(&inode->i_dentry)) 337 if (hlist_empty(&inode->i_dentry))
340 return NULL; 338 return NULL;
341 339
342 discon_alias = invalid_alias = NULL; 340 discon_alias = invalid_alias = NULL;
343 341
344 ll_lock_dcache(inode); 342 ll_lock_dcache(inode);
345 ll_d_hlist_for_each_entry(alias, p, &inode->i_dentry, d_u.d_alias) { 343 hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) {
346 LASSERT(alias != dentry); 344 LASSERT(alias != dentry);
347 345
348 spin_lock(&alias->d_lock); 346 spin_lock(&alias->d_lock);
@@ -690,7 +688,7 @@ static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)
690 goto out; 688 goto out;
691 } 689 }
692 690
693 LASSERT(ll_d_hlist_empty(&inode->i_dentry)); 691 LASSERT(hlist_empty(&inode->i_dentry));
694 692
695 /* We asked for a lock on the directory, but were granted a 693 /* We asked for a lock on the directory, but were granted a
696 * lock on the inode. Since we finally have an inode pointer, 694 * lock on the inode. Since we finally have an inode pointer,
@@ -1008,7 +1006,7 @@ static int ll_unlink(struct inode *dir, struct dentry *dentry)
1008 return rc; 1006 return rc;
1009} 1007}
1010 1008
1011static int ll_mkdir(struct inode *dir, struct dentry *dentry, ll_umode_t mode) 1009static int ll_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
1012{ 1010{
1013 int err; 1011 int err;
1014 1012
diff --git a/drivers/staging/lustre/lustre/llite/remote_perm.c b/drivers/staging/lustre/lustre/llite/remote_perm.c
index a58182600dae..39022ea88b5f 100644
--- a/drivers/staging/lustre/lustre/llite/remote_perm.c
+++ b/drivers/staging/lustre/lustre/llite/remote_perm.c
@@ -54,8 +54,8 @@
54#include "../include/lustre_param.h" 54#include "../include/lustre_param.h"
55#include "llite_internal.h" 55#include "llite_internal.h"
56 56
57struct kmem_cache *ll_remote_perm_cachep = NULL; 57struct kmem_cache *ll_remote_perm_cachep;
58struct kmem_cache *ll_rmtperm_hash_cachep = NULL; 58struct kmem_cache *ll_rmtperm_hash_cachep;
59 59
60static inline struct ll_remote_perm *alloc_ll_remote_perm(void) 60static inline struct ll_remote_perm *alloc_ll_remote_perm(void)
61{ 61{
@@ -104,8 +104,7 @@ void free_rmtperm_hash(struct hlist_head *hash)
104 return; 104 return;
105 105
106 for (i = 0; i < REMOTE_PERM_HASHSIZE; i++) 106 for (i = 0; i < REMOTE_PERM_HASHSIZE; i++)
107 hlist_for_each_entry_safe(lrp, next, hash + i, 107 hlist_for_each_entry_safe(lrp, next, hash + i, lrp_list)
108 lrp_list)
109 free_ll_remote_perm(lrp); 108 free_ll_remote_perm(lrp);
110 OBD_SLAB_FREE(hash, ll_rmtperm_hash_cachep, 109 OBD_SLAB_FREE(hash, ll_rmtperm_hash_cachep,
111 REMOTE_PERM_HASHSIZE * sizeof(*hash)); 110 REMOTE_PERM_HASHSIZE * sizeof(*hash));
@@ -117,7 +116,8 @@ static inline int remote_perm_hashfunc(uid_t uid)
117} 116}
118 117
119/* NB: setxid permission is not checked here, instead it's done on 118/* NB: setxid permission is not checked here, instead it's done on
120 * MDT when client get remote permission. */ 119 * MDT when client get remote permission.
120 */
121static int do_check_remote_perm(struct ll_inode_info *lli, int mask) 121static int do_check_remote_perm(struct ll_inode_info *lli, int mask)
122{ 122{
123 struct hlist_head *head; 123 struct hlist_head *head;
@@ -184,7 +184,7 @@ int ll_update_remote_perm(struct inode *inode, struct mdt_remote_perm *perm)
184 184
185 if (!lli->lli_remote_perms) { 185 if (!lli->lli_remote_perms) {
186 perm_hash = alloc_rmtperm_hash(); 186 perm_hash = alloc_rmtperm_hash();
187 if (perm_hash == NULL) { 187 if (!perm_hash) {
188 CERROR("alloc lli_remote_perms failed!\n"); 188 CERROR("alloc lli_remote_perms failed!\n");
189 return -ENOMEM; 189 return -ENOMEM;
190 } 190 }
@@ -287,7 +287,7 @@ int lustre_check_remote_perm(struct inode *inode, int mask)
287 287
288 perm = req_capsule_server_swab_get(&req->rq_pill, &RMF_ACL, 288 perm = req_capsule_server_swab_get(&req->rq_pill, &RMF_ACL,
289 lustre_swab_mdt_remote_perm); 289 lustre_swab_mdt_remote_perm);
290 if (unlikely(perm == NULL)) { 290 if (unlikely(!perm)) {
291 mutex_unlock(&lli->lli_rmtperm_mutex); 291 mutex_unlock(&lli->lli_rmtperm_mutex);
292 rc = -EPROTO; 292 rc = -EPROTO;
293 break; 293 break;
@@ -321,8 +321,7 @@ void ll_free_remote_perms(struct inode *inode)
321 spin_lock(&lli->lli_lock); 321 spin_lock(&lli->lli_lock);
322 322
323 for (i = 0; i < REMOTE_PERM_HASHSIZE; i++) { 323 for (i = 0; i < REMOTE_PERM_HASHSIZE; i++) {
324 hlist_for_each_entry_safe(lrp, node, next, hash + i, 324 hlist_for_each_entry_safe(lrp, node, next, hash + i, lrp_list)
325 lrp_list)
326 free_ll_remote_perm(lrp); 325 free_ll_remote_perm(lrp);
327 } 326 }
328 327
diff --git a/drivers/staging/lustre/lustre/llite/vvp_io.c b/drivers/staging/lustre/lustre/llite/vvp_io.c
index 91bba79678cf..a659962e09c8 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_io.c
+++ b/drivers/staging/lustre/lustre/llite/vvp_io.c
@@ -455,12 +455,11 @@ static void vvp_io_setattr_end(const struct lu_env *env,
455 struct cl_io *io = ios->cis_io; 455 struct cl_io *io = ios->cis_io;
456 struct inode *inode = ccc_object_inode(io->ci_obj); 456 struct inode *inode = ccc_object_inode(io->ci_obj);
457 457
458 if (cl_io_is_trunc(io)) { 458 if (cl_io_is_trunc(io))
459 /* Truncate in memory pages - they must be clean pages 459 /* Truncate in memory pages - they must be clean pages
460 * because osc has already notified to destroy osc_extents. */ 460 * because osc has already notified to destroy osc_extents. */
461 vvp_do_vmtruncate(inode, io->u.ci_setattr.sa_attr.lvb_size); 461 vvp_do_vmtruncate(inode, io->u.ci_setattr.sa_attr.lvb_size);
462 inode_dio_write_done(inode); 462
463 }
464 mutex_unlock(&inode->i_mutex); 463 mutex_unlock(&inode->i_mutex);
465} 464}
466 465
diff --git a/drivers/staging/lustre/lustre/llite/vvp_page.c b/drivers/staging/lustre/lustre/llite/vvp_page.c
index 954ed08c6af2..a3cf5ad20c60 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_page.c
+++ b/drivers/staging/lustre/lustre/llite/vvp_page.c
@@ -227,11 +227,16 @@ static int vvp_page_prep_write(const struct lu_env *env,
227 struct cl_io *unused) 227 struct cl_io *unused)
228{ 228{
229 struct page *vmpage = cl2vm_page(slice); 229 struct page *vmpage = cl2vm_page(slice);
230 struct cl_page *pg = slice->cpl_page;
230 231
231 LASSERT(PageLocked(vmpage)); 232 LASSERT(PageLocked(vmpage));
232 LASSERT(!PageDirty(vmpage)); 233 LASSERT(!PageDirty(vmpage));
233 234
234 set_page_writeback(vmpage); 235 /* ll_writepage path is not a sync write, so need to set page writeback
236 * flag */
237 if (!pg->cp_sync_io)
238 set_page_writeback(vmpage);
239
235 vvp_write_pending(cl2ccc(slice->cpl_obj), cl2ccc_page(slice)); 240 vvp_write_pending(cl2ccc(slice->cpl_obj), cl2ccc_page(slice));
236 241
237 return 0; 242 return 0;
@@ -298,9 +303,6 @@ static void vvp_page_completion_write(const struct lu_env *env,
298 struct cl_page *pg = slice->cpl_page; 303 struct cl_page *pg = slice->cpl_page;
299 struct page *vmpage = cp->cpg_page; 304 struct page *vmpage = cp->cpg_page;
300 305
301 LASSERT(ergo(pg->cp_sync_io != NULL, PageLocked(vmpage)));
302 LASSERT(PageWriteback(vmpage));
303
304 CL_PAGE_HEADER(D_PAGE, env, pg, "completing WRITE with %d\n", ioret); 306 CL_PAGE_HEADER(D_PAGE, env, pg, "completing WRITE with %d\n", ioret);
305 307
306 /* 308 /*
@@ -316,14 +318,19 @@ static void vvp_page_completion_write(const struct lu_env *env,
316 cp->cpg_write_queued = 0; 318 cp->cpg_write_queued = 0;
317 vvp_write_complete(cl2ccc(slice->cpl_obj), cp); 319 vvp_write_complete(cl2ccc(slice->cpl_obj), cp);
318 320
319 /* 321 if (pg->cp_sync_io != NULL) {
320 * Only mark the page error only when it's an async write because 322 LASSERT(PageLocked(vmpage));
321 * applications won't wait for IO to finish. 323 LASSERT(!PageWriteback(vmpage));
322 */ 324 } else {
323 if (pg->cp_sync_io == NULL) 325 LASSERT(PageWriteback(vmpage));
326 /*
327 * Only mark the page error only when it's an async write
328 * because applications won't wait for IO to finish.
329 */
324 vvp_vmpage_error(ccc_object_inode(pg->cp_obj), vmpage, ioret); 330 vvp_vmpage_error(ccc_object_inode(pg->cp_obj), vmpage, ioret);
325 331
326 end_page_writeback(vmpage); 332 end_page_writeback(vmpage);
333 }
327} 334}
328 335
329/** 336/**
diff --git a/drivers/staging/lustre/lustre/llite/xattr_cache.c b/drivers/staging/lustre/lustre/llite/xattr_cache.c
index 6956dec53fcc..9e763ce244e3 100644
--- a/drivers/staging/lustre/lustre/llite/xattr_cache.c
+++ b/drivers/staging/lustre/lustre/llite/xattr_cache.c
@@ -357,7 +357,7 @@ static int ll_xattr_cache_refill(struct inode *inode, struct lookup_intent *oit)
357 struct ll_inode_info *lli = ll_i2info(inode); 357 struct ll_inode_info *lli = ll_i2info(inode);
358 struct mdt_body *body; 358 struct mdt_body *body;
359 __u32 *xsizes; 359 __u32 *xsizes;
360 int rc = 0, i; 360 int rc, i;
361 361
362 362
363 363
diff --git a/drivers/staging/lustre/lustre/lmv/lmv_intent.c b/drivers/staging/lustre/lustre/lmv/lmv_intent.c
index cb35f6341fb2..eebe45bdceb6 100644
--- a/drivers/staging/lustre/lustre/lmv/lmv_intent.c
+++ b/drivers/staging/lustre/lustre/lmv/lmv_intent.c
@@ -100,7 +100,7 @@ static int lmv_intent_remote(struct obd_export *exp, void *lmm,
100 } 100 }
101 101
102 op_data = kzalloc(sizeof(*op_data), GFP_NOFS); 102 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
103 if (op_data == NULL) { 103 if (!op_data) {
104 rc = -ENOMEM; 104 rc = -ENOMEM;
105 goto out; 105 goto out;
106 } 106 }
diff --git a/drivers/staging/lustre/lustre/lmv/lmv_obd.c b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
index ac5053cd5da5..c9e0536e9f2a 100644
--- a/drivers/staging/lustre/lustre/lmv/lmv_obd.c
+++ b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
@@ -716,7 +716,7 @@ repeat_fid2path:
716 if (remote_gf == NULL) { 716 if (remote_gf == NULL) {
717 remote_gf_size = sizeof(*remote_gf) + PATH_MAX; 717 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
718 remote_gf = kzalloc(remote_gf_size, GFP_NOFS); 718 remote_gf = kzalloc(remote_gf_size, GFP_NOFS);
719 if (remote_gf == NULL) { 719 if (!remote_gf) {
720 rc = -ENOMEM; 720 rc = -ENOMEM;
721 goto out_fid2path; 721 goto out_fid2path;
722 } 722 }
@@ -1398,7 +1398,7 @@ static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1398 return rc; 1398 return rc;
1399 1399
1400 temp = kzalloc(sizeof(*temp), GFP_NOFS); 1400 temp = kzalloc(sizeof(*temp), GFP_NOFS);
1401 if (temp == NULL) 1401 if (!temp)
1402 return -ENOMEM; 1402 return -ENOMEM;
1403 1403
1404 for (i = 0; i < lmv->desc.ld_tgt_count; i++) { 1404 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
@@ -1730,7 +1730,7 @@ lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1730 } 1730 }
1731 1731
1732 rdata = kzalloc(sizeof(*rdata), GFP_NOFS); 1732 rdata = kzalloc(sizeof(*rdata), GFP_NOFS);
1733 if (rdata == NULL) { 1733 if (!rdata) {
1734 rc = -ENOMEM; 1734 rc = -ENOMEM;
1735 goto out; 1735 goto out;
1736 } 1736 }
@@ -1993,7 +1993,7 @@ static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
1993 struct obd_device *obd = exp->exp_obd; 1993 struct obd_device *obd = exp->exp_obd;
1994 struct lmv_obd *lmv = &obd->u.lmv; 1994 struct lmv_obd *lmv = &obd->u.lmv;
1995 struct lmv_tgt_desc *tgt; 1995 struct lmv_tgt_desc *tgt;
1996 int rc = 0; 1996 int rc;
1997 1997
1998 rc = lmv_check_connect(obd); 1998 rc = lmv_check_connect(obd);
1999 if (rc) 1999 if (rc)
diff --git a/drivers/staging/lustre/lustre/lov/lov_dev.c b/drivers/staging/lustre/lustre/lov/lov_dev.c
index 504b24a468fc..8c3bbe574723 100644
--- a/drivers/staging/lustre/lustre/lov/lov_dev.c
+++ b/drivers/staging/lustre/lustre/lov/lov_dev.c
@@ -478,7 +478,7 @@ static struct lu_device *lov_device_alloc(const struct lu_env *env,
478 int rc; 478 int rc;
479 479
480 ld = kzalloc(sizeof(*ld), GFP_NOFS); 480 ld = kzalloc(sizeof(*ld), GFP_NOFS);
481 if (ld == NULL) 481 if (!ld)
482 return ERR_PTR(-ENOMEM); 482 return ERR_PTR(-ENOMEM);
483 483
484 cl_device_init(&ld->ld_cl, t); 484 cl_device_init(&ld->ld_cl, t);
diff --git a/drivers/staging/lustre/lustre/lov/lov_io.c b/drivers/staging/lustre/lustre/lov/lov_io.c
index 11c1081b1d3d..bf3629151d68 100644
--- a/drivers/staging/lustre/lustre/lov/lov_io.c
+++ b/drivers/staging/lustre/lustre/lov/lov_io.c
@@ -181,7 +181,7 @@ static int lov_io_sub_init(const struct lu_env *env, struct lov_io *lio,
181 } else { 181 } else {
182 sub->sub_io = kzalloc(sizeof(*sub->sub_io), 182 sub->sub_io = kzalloc(sizeof(*sub->sub_io),
183 GFP_NOFS); 183 GFP_NOFS);
184 if (sub->sub_io == NULL) 184 if (!sub->sub_io)
185 result = -ENOMEM; 185 result = -ENOMEM;
186 } 186 }
187 } 187 }
diff --git a/drivers/staging/lustre/lustre/lov/lov_merge.c b/drivers/staging/lustre/lustre/lov/lov_merge.c
index b7e7bfabe382..dd1cf3d2d039 100644
--- a/drivers/staging/lustre/lustre/lov/lov_merge.c
+++ b/drivers/staging/lustre/lustre/lov/lov_merge.c
@@ -123,6 +123,7 @@ int lov_adjust_kms(struct obd_export *exp, struct lov_stripe_md *lsm,
123 if (shrink) { 123 if (shrink) {
124 for (; stripe < lsm->lsm_stripe_count; stripe++) { 124 for (; stripe < lsm->lsm_stripe_count; stripe++) {
125 struct lov_oinfo *loi = lsm->lsm_oinfo[stripe]; 125 struct lov_oinfo *loi = lsm->lsm_oinfo[stripe];
126
126 kms = lov_size_to_stripe(lsm, size, stripe); 127 kms = lov_size_to_stripe(lsm, size, stripe);
127 CDEBUG(D_INODE, 128 CDEBUG(D_INODE,
128 "stripe %d KMS %sing %llu->%llu\n", 129 "stripe %d KMS %sing %llu->%llu\n",
diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c
index 96c55acd52ae..c5c67d982ef2 100644
--- a/drivers/staging/lustre/lustre/lov/lov_obd.c
+++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
@@ -107,6 +107,10 @@ static void lov_putref(struct obd_device *obd)
107 /* Disconnect */ 107 /* Disconnect */
108 __lov_del_obd(obd, tgt); 108 __lov_del_obd(obd, tgt);
109 } 109 }
110
111 if (lov->lov_tgts_kobj)
112 kobject_put(lov->lov_tgts_kobj);
113
110 } else { 114 } else {
111 mutex_unlock(&lov->lov_lock); 115 mutex_unlock(&lov->lov_lock);
112 } 116 }
@@ -322,9 +326,6 @@ static int lov_disconnect(struct obd_export *exp)
322 } 326 }
323 } 327 }
324 328
325 if (lov->lov_tgts_kobj)
326 kobject_put(lov->lov_tgts_kobj);
327
328 obd_putref(obd); 329 obd_putref(obd);
329 330
330out: 331out:
@@ -976,7 +977,7 @@ static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
976 src_oa->o_flags & OBD_FL_RECREATE_OBJS); 977 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
977 978
978 obj_mdp = kzalloc(sizeof(*obj_mdp), GFP_NOFS); 979 obj_mdp = kzalloc(sizeof(*obj_mdp), GFP_NOFS);
979 if (obj_mdp == NULL) 980 if (!obj_mdp)
980 return -ENOMEM; 981 return -ENOMEM;
981 982
982 ost_idx = src_oa->o_nlink; 983 ost_idx = src_oa->o_nlink;
@@ -1439,7 +1440,7 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1439 __u32 *genp; 1440 __u32 *genp;
1440 1441
1441 len = 0; 1442 len = 0;
1442 if (obd_ioctl_getdata(&buf, &len, (void *)uarg)) 1443 if (obd_ioctl_getdata(&buf, &len, uarg))
1443 return -EINVAL; 1444 return -EINVAL;
1444 1445
1445 data = (struct obd_ioctl_data *)buf; 1446 data = (struct obd_ioctl_data *)buf;
@@ -1472,7 +1473,7 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1472 *genp = lov->lov_tgts[i]->ltd_gen; 1473 *genp = lov->lov_tgts[i]->ltd_gen;
1473 } 1474 }
1474 1475
1475 if (copy_to_user((void *)uarg, buf, len)) 1476 if (copy_to_user(uarg, buf, len))
1476 rc = -EFAULT; 1477 rc = -EFAULT;
1477 obd_ioctl_freedata(buf, len); 1478 obd_ioctl_freedata(buf, len);
1478 break; 1479 break;
diff --git a/drivers/staging/lustre/lustre/lov/lov_pool.c b/drivers/staging/lustre/lustre/lov/lov_pool.c
index 1e4d3fbee323..c59b1402616e 100644
--- a/drivers/staging/lustre/lustre/lov/lov_pool.c
+++ b/drivers/staging/lustre/lustre/lov/lov_pool.c
@@ -431,7 +431,7 @@ int lov_pool_new(struct obd_device *obd, char *poolname)
431 return -ENAMETOOLONG; 431 return -ENAMETOOLONG;
432 432
433 new_pool = kzalloc(sizeof(*new_pool), GFP_NOFS); 433 new_pool = kzalloc(sizeof(*new_pool), GFP_NOFS);
434 if (new_pool == NULL) 434 if (!new_pool)
435 return -ENOMEM; 435 return -ENOMEM;
436 436
437 strncpy(new_pool->pool_name, poolname, LOV_MAXPOOLNAME); 437 strncpy(new_pool->pool_name, poolname, LOV_MAXPOOLNAME);
diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c b/drivers/staging/lustre/lustre/lov/lov_request.c
index f4de8b84c5c2..416e42ed7792 100644
--- a/drivers/staging/lustre/lustre/lov/lov_request.c
+++ b/drivers/staging/lustre/lustre/lov/lov_request.c
@@ -275,7 +275,7 @@ int lov_prep_getattr_set(struct obd_export *exp, struct obd_info *oinfo,
275 int rc = 0, i; 275 int rc = 0, i;
276 276
277 set = kzalloc(sizeof(*set), GFP_NOFS); 277 set = kzalloc(sizeof(*set), GFP_NOFS);
278 if (set == NULL) 278 if (!set)
279 return -ENOMEM; 279 return -ENOMEM;
280 lov_init_set(set); 280 lov_init_set(set);
281 281
@@ -301,7 +301,7 @@ int lov_prep_getattr_set(struct obd_export *exp, struct obd_info *oinfo,
301 } 301 }
302 302
303 req = kzalloc(sizeof(*req), GFP_NOFS); 303 req = kzalloc(sizeof(*req), GFP_NOFS);
304 if (req == NULL) { 304 if (!req) {
305 rc = -ENOMEM; 305 rc = -ENOMEM;
306 goto out_set; 306 goto out_set;
307 } 307 }
@@ -358,7 +358,7 @@ int lov_prep_destroy_set(struct obd_export *exp, struct obd_info *oinfo,
358 int rc = 0, i; 358 int rc = 0, i;
359 359
360 set = kzalloc(sizeof(*set), GFP_NOFS); 360 set = kzalloc(sizeof(*set), GFP_NOFS);
361 if (set == NULL) 361 if (!set)
362 return -ENOMEM; 362 return -ENOMEM;
363 lov_init_set(set); 363 lov_init_set(set);
364 364
@@ -384,7 +384,7 @@ int lov_prep_destroy_set(struct obd_export *exp, struct obd_info *oinfo,
384 } 384 }
385 385
386 req = kzalloc(sizeof(*req), GFP_NOFS); 386 req = kzalloc(sizeof(*req), GFP_NOFS);
387 if (req == NULL) { 387 if (!req) {
388 rc = -ENOMEM; 388 rc = -ENOMEM;
389 goto out_set; 389 goto out_set;
390 } 390 }
@@ -477,7 +477,7 @@ int lov_prep_setattr_set(struct obd_export *exp, struct obd_info *oinfo,
477 int rc = 0, i; 477 int rc = 0, i;
478 478
479 set = kzalloc(sizeof(*set), GFP_NOFS); 479 set = kzalloc(sizeof(*set), GFP_NOFS);
480 if (set == NULL) 480 if (!set)
481 return -ENOMEM; 481 return -ENOMEM;
482 lov_init_set(set); 482 lov_init_set(set);
483 483
@@ -500,7 +500,7 @@ int lov_prep_setattr_set(struct obd_export *exp, struct obd_info *oinfo,
500 } 500 }
501 501
502 req = kzalloc(sizeof(*req), GFP_NOFS); 502 req = kzalloc(sizeof(*req), GFP_NOFS);
503 if (req == NULL) { 503 if (!req) {
504 rc = -ENOMEM; 504 rc = -ENOMEM;
505 goto out_set; 505 goto out_set;
506 } 506 }
@@ -704,7 +704,7 @@ int lov_prep_statfs_set(struct obd_device *obd, struct obd_info *oinfo,
704 int rc = 0, i; 704 int rc = 0, i;
705 705
706 set = kzalloc(sizeof(*set), GFP_NOFS); 706 set = kzalloc(sizeof(*set), GFP_NOFS);
707 if (set == NULL) 707 if (!set)
708 return -ENOMEM; 708 return -ENOMEM;
709 lov_init_set(set); 709 lov_init_set(set);
710 710
@@ -730,14 +730,14 @@ int lov_prep_statfs_set(struct obd_device *obd, struct obd_info *oinfo,
730 } 730 }
731 731
732 req = kzalloc(sizeof(*req), GFP_NOFS); 732 req = kzalloc(sizeof(*req), GFP_NOFS);
733 if (req == NULL) { 733 if (!req) {
734 rc = -ENOMEM; 734 rc = -ENOMEM;
735 goto out_set; 735 goto out_set;
736 } 736 }
737 737
738 req->rq_oi.oi_osfs = kzalloc(sizeof(*req->rq_oi.oi_osfs), 738 req->rq_oi.oi_osfs = kzalloc(sizeof(*req->rq_oi.oi_osfs),
739 GFP_NOFS); 739 GFP_NOFS);
740 if (req->rq_oi.oi_osfs == NULL) { 740 if (!req->rq_oi.oi_osfs) {
741 kfree(req); 741 kfree(req);
742 rc = -ENOMEM; 742 rc = -ENOMEM;
743 goto out_set; 743 goto out_set;
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_lib.c b/drivers/staging/lustre/lustre/mdc/mdc_lib.c
index d3234cb1ea22..1a850ea26849 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_lib.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_lib.c
@@ -286,7 +286,7 @@ static inline __u64 attr_pack(unsigned int ia_valid)
286 sa_valid |= MDS_ATTR_KILL_SGID; 286 sa_valid |= MDS_ATTR_KILL_SGID;
287 if (ia_valid & ATTR_CTIME_SET) 287 if (ia_valid & ATTR_CTIME_SET)
288 sa_valid |= MDS_ATTR_CTIME_SET; 288 sa_valid |= MDS_ATTR_CTIME_SET;
289 if (ia_valid & ATTR_FROM_OPEN) 289 if (ia_valid & ATTR_OPEN)
290 sa_valid |= MDS_ATTR_FROM_OPEN; 290 sa_valid |= MDS_ATTR_FROM_OPEN;
291 if (ia_valid & ATTR_BLOCKS) 291 if (ia_valid & ATTR_BLOCKS)
292 sa_valid |= MDS_ATTR_BLOCKS; 292 sa_valid |= MDS_ATTR_BLOCKS;
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c
index 7f208a6621e6..204d51262560 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_request.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c
@@ -1202,7 +1202,7 @@ static int mdc_ioc_fid2path(struct obd_export *exp, struct getinfo_fid2path *gf)
1202 /* Key is KEY_FID2PATH + getinfo_fid2path description */ 1202 /* Key is KEY_FID2PATH + getinfo_fid2path description */
1203 keylen = cfs_size_round(sizeof(KEY_FID2PATH)) + sizeof(*gf); 1203 keylen = cfs_size_round(sizeof(KEY_FID2PATH)) + sizeof(*gf);
1204 key = kzalloc(keylen, GFP_NOFS); 1204 key = kzalloc(keylen, GFP_NOFS);
1205 if (key == NULL) 1205 if (!key)
1206 return -ENOMEM; 1206 return -ENOMEM;
1207 memcpy(key, KEY_FID2PATH, sizeof(KEY_FID2PATH)); 1207 memcpy(key, KEY_FID2PATH, sizeof(KEY_FID2PATH));
1208 memcpy(key + cfs_size_round(sizeof(KEY_FID2PATH)), gf, sizeof(*gf)); 1208 memcpy(key + cfs_size_round(sizeof(KEY_FID2PATH)), gf, sizeof(*gf));
@@ -1605,7 +1605,7 @@ static int mdc_changelog_send_thread(void *csdata)
1605 cs->cs_fp, cs->cs_startrec); 1605 cs->cs_fp, cs->cs_startrec);
1606 1606
1607 cs->cs_buf = kzalloc(KUC_CHANGELOG_MSG_MAXSIZE, GFP_NOFS); 1607 cs->cs_buf = kzalloc(KUC_CHANGELOG_MSG_MAXSIZE, GFP_NOFS);
1608 if (cs->cs_buf == NULL) { 1608 if (!cs->cs_buf) {
1609 rc = -ENOMEM; 1609 rc = -ENOMEM;
1610 goto out; 1610 goto out;
1611 } 1611 }
@@ -1934,7 +1934,7 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1934 struct obd_quotactl *oqctl; 1934 struct obd_quotactl *oqctl;
1935 1935
1936 oqctl = kzalloc(sizeof(*oqctl), GFP_NOFS); 1936 oqctl = kzalloc(sizeof(*oqctl), GFP_NOFS);
1937 if (oqctl == NULL) { 1937 if (!oqctl) {
1938 rc = -ENOMEM; 1938 rc = -ENOMEM;
1939 goto out; 1939 goto out;
1940 } 1940 }
diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c
index 174dfc32876b..019ee2f256aa 100644
--- a/drivers/staging/lustre/lustre/mgc/mgc_request.c
+++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c
@@ -1128,7 +1128,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
1128 LASSERT(cfg->cfg_sb == cfg->cfg_instance); 1128 LASSERT(cfg->cfg_sb == cfg->cfg_instance);
1129 1129
1130 inst = kzalloc(PAGE_CACHE_SIZE, GFP_NOFS); 1130 inst = kzalloc(PAGE_CACHE_SIZE, GFP_NOFS);
1131 if (inst == NULL) 1131 if (!inst)
1132 return -ENOMEM; 1132 return -ENOMEM;
1133 1133
1134 if (!IS_SERVER(lsi)) { 1134 if (!IS_SERVER(lsi)) {
@@ -1232,7 +1232,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
1232 pos += sprintf(obdname + pos, "-%s%04x", 1232 pos += sprintf(obdname + pos, "-%s%04x",
1233 is_ost ? "OST" : "MDT", entry->mne_index); 1233 is_ost ? "OST" : "MDT", entry->mne_index);
1234 1234
1235 cname = is_ost ? "osc" : "mdc", 1235 cname = is_ost ? "osc" : "mdc";
1236 pos += sprintf(obdname + pos, "-%s-%s", cname, inst); 1236 pos += sprintf(obdname + pos, "-%s-%s", cname, inst);
1237 lustre_cfg_bufs_reset(&bufs, obdname); 1237 lustre_cfg_bufs_reset(&bufs, obdname);
1238 1238
@@ -1493,7 +1493,7 @@ static int mgc_process_cfg_log(struct obd_device *mgc,
1493 lsi = s2lsi(cld->cld_cfg.cfg_sb); 1493 lsi = s2lsi(cld->cld_cfg.cfg_sb);
1494 1494
1495 env = kzalloc(sizeof(*env), GFP_NOFS); 1495 env = kzalloc(sizeof(*env), GFP_NOFS);
1496 if (env == NULL) 1496 if (!env)
1497 return -ENOMEM; 1497 return -ENOMEM;
1498 1498
1499 rc = lu_env_init(env, LCT_MG_THREAD); 1499 rc = lu_env_init(env, LCT_MG_THREAD);
diff --git a/drivers/staging/lustre/lustre/obdclass/acl.c b/drivers/staging/lustre/lustre/obdclass/acl.c
index bc3fc4780cb9..933456c502d1 100644
--- a/drivers/staging/lustre/lustre/obdclass/acl.c
+++ b/drivers/staging/lustre/lustre/obdclass/acl.c
@@ -104,11 +104,10 @@ static int lustre_posix_acl_xattr_reduce_space(posix_acl_xattr_header **header,
104 if (unlikely(old_count <= new_count)) 104 if (unlikely(old_count <= new_count))
105 return old_size; 105 return old_size;
106 106
107 new = kzalloc(new_size, GFP_NOFS); 107 new = kmemdup(*header, new_size, GFP_NOFS);
108 if (unlikely(new == NULL)) 108 if (unlikely(new == NULL))
109 return -ENOMEM; 109 return -ENOMEM;
110 110
111 memcpy(new, *header, new_size);
112 kfree(*header); 111 kfree(*header);
113 *header = new; 112 *header = new;
114 return new_size; 113 return new_size;
@@ -125,11 +124,10 @@ static int lustre_ext_acl_xattr_reduce_space(ext_acl_xattr_header **header,
125 if (unlikely(old_count <= ext_count)) 124 if (unlikely(old_count <= ext_count))
126 return 0; 125 return 0;
127 126
128 new = kzalloc(ext_size, GFP_NOFS); 127 new = kmemdup(*header, ext_size, GFP_NOFS);
129 if (unlikely(new == NULL)) 128 if (unlikely(new == NULL))
130 return -ENOMEM; 129 return -ENOMEM;
131 130
132 memcpy(new, *header, ext_size);
133 kfree(*header); 131 kfree(*header);
134 *header = new; 132 *header = new;
135 return 0; 133 return 0;
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_page.c b/drivers/staging/lustre/lustre/obdclass/cl_page.c
index a7f3032f34dd..d5fb81f84cd4 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_page.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_page.c
@@ -51,13 +51,13 @@
51static void cl_page_delete0(const struct lu_env *env, struct cl_page *pg, 51static void cl_page_delete0(const struct lu_env *env, struct cl_page *pg,
52 int radix); 52 int radix);
53 53
54# define PASSERT(env, page, expr) \ 54# define PASSERT(env, page, expr) \
55 do { \ 55 do { \
56 if (unlikely(!(expr))) { \ 56 if (unlikely(!(expr))) { \
57 CL_PAGE_DEBUG(D_ERROR, (env), (page), #expr "\n"); \ 57 CL_PAGE_DEBUG(D_ERROR, (env), (page), #expr "\n"); \
58 LASSERT(0); \ 58 LASSERT(0); \
59 } \ 59 } \
60 } while (0) 60 } while (0)
61 61
62# define PINVRNT(env, page, exp) \ 62# define PINVRNT(env, page, exp) \
63 ((void)sizeof(env), (void)sizeof(page), (void)sizeof !!(exp)) 63 ((void)sizeof(env), (void)sizeof(page), (void)sizeof !!(exp))
@@ -169,6 +169,7 @@ int cl_page_gang_lookup(const struct lu_env *env, struct cl_object *obj,
169 while ((nr = radix_tree_gang_lookup(&hdr->coh_tree, (void **)pvec, 169 while ((nr = radix_tree_gang_lookup(&hdr->coh_tree, (void **)pvec,
170 idx, CLT_PVEC_SIZE)) > 0) { 170 idx, CLT_PVEC_SIZE)) > 0) {
171 int end_of_region = 0; 171 int end_of_region = 0;
172
172 idx = pvec[nr - 1]->cp_index + 1; 173 idx = pvec[nr - 1]->cp_index + 1;
173 for (i = 0, j = 0; i < nr; ++i) { 174 for (i = 0, j = 0; i < nr; ++i) {
174 page = pvec[i]; 175 page = pvec[i];
@@ -286,6 +287,7 @@ static struct cl_page *cl_page_alloc(const struct lu_env *env,
286 GFP_NOFS); 287 GFP_NOFS);
287 if (page != NULL) { 288 if (page != NULL) {
288 int result = 0; 289 int result = 0;
290
289 atomic_set(&page->cp_ref, 1); 291 atomic_set(&page->cp_ref, 1);
290 if (type == CPT_CACHEABLE) /* for radix tree */ 292 if (type == CPT_CACHEABLE) /* for radix tree */
291 atomic_inc(&page->cp_ref); 293 atomic_inc(&page->cp_ref);
@@ -352,8 +354,10 @@ static struct cl_page *cl_page_find0(const struct lu_env *env,
352 idx, PFID(&hdr->coh_lu.loh_fid), vmpage, vmpage->private, type); 354 idx, PFID(&hdr->coh_lu.loh_fid), vmpage, vmpage->private, type);
353 /* fast path. */ 355 /* fast path. */
354 if (type == CPT_CACHEABLE) { 356 if (type == CPT_CACHEABLE) {
355 /* vmpage lock is used to protect the child/parent 357 /*
356 * relationship */ 358 * vmpage lock is used to protect the child/parent
359 * relationship
360 */
357 KLASSERT(PageLocked(vmpage)); 361 KLASSERT(PageLocked(vmpage));
358 /* 362 /*
359 * cl_vmpage_page() can be called here without any locks as 363 * cl_vmpage_page() can be called here without any locks as
@@ -372,9 +376,8 @@ static struct cl_page *cl_page_find0(const struct lu_env *env,
372 idx) == page)); 376 idx) == page));
373 } 377 }
374 378
375 if (page != NULL) { 379 if (page != NULL)
376 return page; 380 return page;
377 }
378 381
379 /* allocate and initialize cl_page */ 382 /* allocate and initialize cl_page */
380 page = cl_page_alloc(env, o, idx, vmpage, type); 383 page = cl_page_alloc(env, o, idx, vmpage, type);
@@ -1189,9 +1192,6 @@ int cl_page_prep(const struct lu_env *env, struct cl_io *io,
1189 if (result == 0) 1192 if (result == 0)
1190 cl_page_io_start(env, pg, crt); 1193 cl_page_io_start(env, pg, crt);
1191 1194
1192 KLASSERT(ergo(crt == CRT_WRITE && pg->cp_type == CPT_CACHEABLE,
1193 equi(result == 0,
1194 PageWriteback(cl_page_vmpage(env, pg)))));
1195 CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", crt, result); 1195 CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", crt, result);
1196 return result; 1196 return result;
1197} 1197}
@@ -1425,7 +1425,7 @@ void cl_page_clip(const struct lu_env *env, struct cl_page *pg,
1425 CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", from, to); 1425 CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", from, to);
1426 CL_PAGE_INVOID(env, pg, CL_PAGE_OP(cpo_clip), 1426 CL_PAGE_INVOID(env, pg, CL_PAGE_OP(cpo_clip),
1427 (const struct lu_env *, 1427 (const struct lu_env *,
1428 const struct cl_page_slice *,int, int), 1428 const struct cl_page_slice *, int, int),
1429 from, to); 1429 from, to);
1430} 1430}
1431EXPORT_SYMBOL(cl_page_clip); 1431EXPORT_SYMBOL(cl_page_clip);
diff --git a/drivers/staging/lustre/lustre/obdclass/class_obd.c b/drivers/staging/lustre/lustre/obdclass/class_obd.c
index 1bc37566b3a5..2c705d76211f 100644
--- a/drivers/staging/lustre/lustre/obdclass/class_obd.c
+++ b/drivers/staging/lustre/lustre/obdclass/class_obd.c
@@ -78,12 +78,8 @@ atomic_t obd_dirty_pages;
78EXPORT_SYMBOL(obd_dirty_pages); 78EXPORT_SYMBOL(obd_dirty_pages);
79unsigned int obd_timeout = OBD_TIMEOUT_DEFAULT; /* seconds */ 79unsigned int obd_timeout = OBD_TIMEOUT_DEFAULT; /* seconds */
80EXPORT_SYMBOL(obd_timeout); 80EXPORT_SYMBOL(obd_timeout);
81unsigned int ldlm_timeout = LDLM_TIMEOUT_DEFAULT; /* seconds */
82EXPORT_SYMBOL(ldlm_timeout);
83unsigned int obd_timeout_set; 81unsigned int obd_timeout_set;
84EXPORT_SYMBOL(obd_timeout_set); 82EXPORT_SYMBOL(obd_timeout_set);
85unsigned int ldlm_timeout_set;
86EXPORT_SYMBOL(ldlm_timeout_set);
87/* Adaptive timeout defs here instead of ptlrpc module for /proc/sys/ access */ 83/* Adaptive timeout defs here instead of ptlrpc module for /proc/sys/ access */
88unsigned int at_min = 0; 84unsigned int at_min = 0;
89EXPORT_SYMBOL(at_min); 85EXPORT_SYMBOL(at_min);
@@ -144,11 +140,11 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
144 CERROR("%s%salloc of %s (%llu bytes) failed at %s:%d\n", 140 CERROR("%s%salloc of %s (%llu bytes) failed at %s:%d\n",
145 ptr ? "force " :"", type, name, (__u64)size, file, 141 ptr ? "force " :"", type, name, (__u64)size, file,
146 line); 142 line);
147 CERROR("%llu total bytes and %llu total pages (%llu bytes) allocated by Lustre, %d total bytes by LNET\n", 143 CERROR("%llu total bytes and %llu total pages"
144 " (%llu bytes) allocated by Lustre\n",
148 obd_memory_sum(), 145 obd_memory_sum(),
149 obd_pages_sum() << PAGE_CACHE_SHIFT, 146 obd_pages_sum() << PAGE_CACHE_SHIFT,
150 obd_pages_sum(), 147 obd_pages_sum());
151 atomic_read(&libcfs_kmemory));
152 return 1; 148 return 1;
153 } 149 }
154 return 0; 150 return 0;
@@ -232,7 +228,7 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)
232 goto out; 228 goto out;
233 } 229 }
234 lcfg = kzalloc(data->ioc_plen1, GFP_NOFS); 230 lcfg = kzalloc(data->ioc_plen1, GFP_NOFS);
235 if (lcfg == NULL) { 231 if (!lcfg) {
236 err = -ENOMEM; 232 err = -ENOMEM;
237 goto out; 233 goto out;
238 } 234 }
@@ -571,12 +567,14 @@ static int __init init_obdclass(void)
571 if (err) 567 if (err)
572 return err; 568 return err;
573 569
574 obd_sysctl_init();
575
576 err = class_procfs_init(); 570 err = class_procfs_init();
577 if (err) 571 if (err)
578 return err; 572 return err;
579 573
574 err = obd_sysctl_init();
575 if (err)
576 return err;
577
580 err = lu_global_init(); 578 err = lu_global_init();
581 if (err) 579 if (err)
582 return err; 580 return err;
@@ -661,7 +659,6 @@ static void cleanup_obdclass(void)
661 lu_global_fini(); 659 lu_global_fini();
662 660
663 obd_cleanup_caches(); 661 obd_cleanup_caches();
664 obd_sysctl_clean();
665 662
666 class_procfs_clean(); 663 class_procfs_clean();
667 664
diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c
index 978c3c5c460a..0ca730948f7a 100644
--- a/drivers/staging/lustre/lustre/obdclass/genops.c
+++ b/drivers/staging/lustre/lustre/obdclass/genops.c
@@ -45,7 +45,7 @@
45 45
46spinlock_t obd_types_lock; 46spinlock_t obd_types_lock;
47 47
48struct kmem_cache *obd_device_cachep; 48static struct kmem_cache *obd_device_cachep;
49struct kmem_cache *obdo_cachep; 49struct kmem_cache *obdo_cachep;
50EXPORT_SYMBOL(obdo_cachep); 50EXPORT_SYMBOL(obdo_cachep);
51static struct kmem_cache *import_cachep; 51static struct kmem_cache *import_cachep;
@@ -71,9 +71,8 @@ static struct obd_device *obd_device_alloc(void)
71 struct obd_device *obd; 71 struct obd_device *obd;
72 72
73 OBD_SLAB_ALLOC_PTR_GFP(obd, obd_device_cachep, GFP_NOFS); 73 OBD_SLAB_ALLOC_PTR_GFP(obd, obd_device_cachep, GFP_NOFS);
74 if (obd != NULL) { 74 if (obd != NULL)
75 obd->obd_magic = OBD_DEVICE_MAGIC; 75 obd->obd_magic = OBD_DEVICE_MAGIC;
76 }
77 return obd; 76 return obd;
78} 77}
79 78
@@ -172,7 +171,7 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
172 171
173 rc = -ENOMEM; 172 rc = -ENOMEM;
174 type = kzalloc(sizeof(*type), GFP_NOFS); 173 type = kzalloc(sizeof(*type), GFP_NOFS);
175 if (type == NULL) 174 if (!type)
176 return rc; 175 return rc;
177 176
178 type->typ_dt_ops = kzalloc(sizeof(*type->typ_dt_ops), GFP_NOFS); 177 type->typ_dt_ops = kzalloc(sizeof(*type->typ_dt_ops), GFP_NOFS);
@@ -294,7 +293,7 @@ struct obd_device *class_newdev(const char *type_name, const char *name)
294 } 293 }
295 294
296 type = class_get_type(type_name); 295 type = class_get_type(type_name);
297 if (type == NULL){ 296 if (type == NULL) {
298 CERROR("OBD: unknown type: %s\n", type_name); 297 CERROR("OBD: unknown type: %s\n", type_name);
299 return ERR_PTR(-ENODEV); 298 return ERR_PTR(-ENODEV);
300 } 299 }
@@ -999,7 +998,8 @@ void class_import_put(struct obd_import *imp)
999} 998}
1000EXPORT_SYMBOL(class_import_put); 999EXPORT_SYMBOL(class_import_put);
1001 1000
1002static void init_imp_at(struct imp_at *at) { 1001static void init_imp_at(struct imp_at *at)
1002{
1003 int i; 1003 int i;
1004 at_init(&at->iat_net_latency, 0, 0); 1004 at_init(&at->iat_net_latency, 0, 0);
1005 for (i = 0; i < IMP_AT_MAX_PORTALS; i++) { 1005 for (i = 0; i < IMP_AT_MAX_PORTALS; i++) {
@@ -1016,7 +1016,7 @@ struct obd_import *class_new_import(struct obd_device *obd)
1016 struct obd_import *imp; 1016 struct obd_import *imp;
1017 1017
1018 imp = kzalloc(sizeof(*imp), GFP_NOFS); 1018 imp = kzalloc(sizeof(*imp), GFP_NOFS);
1019 if (imp == NULL) 1019 if (!imp)
1020 return NULL; 1020 return NULL;
1021 1021
1022 INIT_LIST_HEAD(&imp->imp_pinger_chain); 1022 INIT_LIST_HEAD(&imp->imp_pinger_chain);
@@ -1642,7 +1642,8 @@ static int obd_zombie_impexp_check(void *arg)
1642/** 1642/**
1643 * Add export to the obd_zombie thread and notify it. 1643 * Add export to the obd_zombie thread and notify it.
1644 */ 1644 */
1645static void obd_zombie_export_add(struct obd_export *exp) { 1645static void obd_zombie_export_add(struct obd_export *exp)
1646{
1646 spin_lock(&exp->exp_obd->obd_dev_lock); 1647 spin_lock(&exp->exp_obd->obd_dev_lock);
1647 LASSERT(!list_empty(&exp->exp_obd_chain)); 1648 LASSERT(!list_empty(&exp->exp_obd_chain));
1648 list_del_init(&exp->exp_obd_chain); 1649 list_del_init(&exp->exp_obd_chain);
@@ -1658,7 +1659,8 @@ static void obd_zombie_export_add(struct obd_export *exp) {
1658/** 1659/**
1659 * Add import to the obd_zombie thread and notify it. 1660 * Add import to the obd_zombie thread and notify it.
1660 */ 1661 */
1661static void obd_zombie_import_add(struct obd_import *imp) { 1662static void obd_zombie_import_add(struct obd_import *imp)
1663{
1662 LASSERT(imp->imp_sec == NULL); 1664 LASSERT(imp->imp_sec == NULL);
1663 LASSERT(imp->imp_rq_pool == NULL); 1665 LASSERT(imp->imp_rq_pool == NULL);
1664 spin_lock(&obd_zombie_impexp_lock); 1666 spin_lock(&obd_zombie_impexp_lock);
@@ -1819,7 +1821,7 @@ void *kuc_alloc(int payload_len, int transport, int type)
1819 int len = kuc_len(payload_len); 1821 int len = kuc_len(payload_len);
1820 1822
1821 lh = kzalloc(len, GFP_NOFS); 1823 lh = kzalloc(len, GFP_NOFS);
1822 if (lh == NULL) 1824 if (!lh)
1823 return ERR_PTR(-ENOMEM); 1825 return ERR_PTR(-ENOMEM);
1824 1826
1825 lh->kuc_magic = KUC_MAGIC; 1827 lh->kuc_magic = KUC_MAGIC;
diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
index 84f75dce0d4c..6218ef34ee80 100644
--- a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
+++ b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
@@ -385,7 +385,7 @@ static int obd_device_list_seq_show(struct seq_file *p, void *v)
385 return 0; 385 return 0;
386} 386}
387 387
388struct seq_operations obd_device_list_sops = { 388static const struct seq_operations obd_device_list_sops = {
389 .start = obd_device_list_seq_start, 389 .start = obd_device_list_seq_start,
390 .stop = obd_device_list_seq_stop, 390 .stop = obd_device_list_seq_stop,
391 .next = obd_device_list_seq_next, 391 .next = obd_device_list_seq_next,
@@ -406,7 +406,7 @@ static int obd_device_list_open(struct inode *inode, struct file *file)
406 return 0; 406 return 0;
407} 407}
408 408
409struct file_operations obd_device_list_fops = { 409static const struct file_operations obd_device_list_fops = {
410 .owner = THIS_MODULE, 410 .owner = THIS_MODULE,
411 .open = obd_device_list_open, 411 .open = obd_device_list_open,
412 .read = seq_read, 412 .read = seq_read,
@@ -423,7 +423,7 @@ static struct attribute_group lustre_attr_group = {
423 423
424int class_procfs_init(void) 424int class_procfs_init(void)
425{ 425{
426 int rc = 0; 426 int rc = -ENOMEM;
427 struct dentry *file; 427 struct dentry *file;
428 428
429 lustre_kobj = kobject_create_and_add("lustre", fs_kobj); 429 lustre_kobj = kobject_create_and_add("lustre", fs_kobj);
diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
index 54f0a81f7b51..1515163a81a5 100644
--- a/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
+++ b/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
@@ -50,331 +50,119 @@
50#include "../../include/obd_support.h" 50#include "../../include/obd_support.h"
51#include "../../include/lprocfs_status.h" 51#include "../../include/lprocfs_status.h"
52 52
53#ifdef CONFIG_SYSCTL 53struct static_lustre_uintvalue_attr {
54static struct ctl_table_header *obd_table_header; 54 struct {
55#endif 55 struct attribute attr;
56 ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
57 char *buf);
58 ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
59 const char *buf, size_t len);
60 } u;
61 int *value;
62};
56 63
57#ifdef CONFIG_SYSCTL 64static ssize_t static_uintvalue_show(struct kobject *kobj,
58static int proc_set_timeout(struct ctl_table *table, int write, 65 struct attribute *attr,
59 void __user *buffer, size_t *lenp, loff_t *ppos) 66 char *buf)
60{ 67{
61 int rc; 68 struct static_lustre_uintvalue_attr *lattr = (void *)attr;
62 69
63 rc = proc_dointvec(table, write, buffer, lenp, ppos); 70 return sprintf(buf, "%d\n", *lattr->value);
64 if (ldlm_timeout >= obd_timeout)
65 ldlm_timeout = max(obd_timeout / 3, 1U);
66 return rc;
67} 71}
68 72
69static int proc_memory_alloc(struct ctl_table *table, int write, 73static ssize_t static_uintvalue_store(struct kobject *kobj,
70 void __user *buffer, size_t *lenp, loff_t *ppos) 74 struct attribute *attr,
75 const char *buffer, size_t count)
71{ 76{
72 char buf[22]; 77 struct static_lustre_uintvalue_attr *lattr = (void *)attr;
73 int len; 78 int rc;
74 79 unsigned int val;
75 if (!*lenp || (*ppos && !write)) {
76 *lenp = 0;
77 return 0;
78 }
79 if (write)
80 return -EINVAL;
81 80
82 len = snprintf(buf, sizeof(buf), "%llu\n", obd_memory_sum()); 81 rc = kstrtouint(buffer, 10, &val);
83 if (len > *lenp) 82 if (rc)
84 len = *lenp; 83 return rc;
85 buf[len] = '\0';
86 if (copy_to_user(buffer, buf, len))
87 return -EFAULT;
88 *lenp = len;
89 *ppos += *lenp;
90 return 0;
91}
92 84
93static int proc_pages_alloc(struct ctl_table *table, int write, 85 *lattr->value = val;
94 void __user *buffer, size_t *lenp, loff_t *ppos)
95{
96 char buf[22];
97 int len;
98 86
99 if (!*lenp || (*ppos && !write)) { 87 return count;
100 *lenp = 0;
101 return 0;
102 }
103 if (write)
104 return -EINVAL;
105
106 len = snprintf(buf, sizeof(buf), "%llu\n", obd_pages_sum());
107 if (len > *lenp)
108 len = *lenp;
109 buf[len] = '\0';
110 if (copy_to_user(buffer, buf, len))
111 return -EFAULT;
112 *lenp = len;
113 *ppos += *lenp;
114 return 0;
115} 88}
116 89
117static int proc_mem_max(struct ctl_table *table, int write, void __user *buffer, 90#define LUSTRE_STATIC_UINT_ATTR(name, value) \
118 size_t *lenp, loff_t *ppos) 91static struct static_lustre_uintvalue_attr lustre_sattr_##name = \
119{ 92 {__ATTR(name, 0644, \
120 char buf[22]; 93 static_uintvalue_show, \
121 int len; 94 static_uintvalue_store),\
95 value }
122 96
123 if (!*lenp || (*ppos && !write)) { 97LUSTRE_STATIC_UINT_ATTR(timeout, &obd_timeout);
124 *lenp = 0;
125 return 0;
126 }
127 if (write)
128 return -EINVAL;
129 98
130 len = snprintf(buf, sizeof(buf), "%llu\n", obd_memory_max()); 99static ssize_t max_dirty_mb_show(struct kobject *kobj, struct attribute *attr,
131 if (len > *lenp) 100 char *buf)
132 len = *lenp; 101{
133 buf[len] = '\0'; 102 return sprintf(buf, "%ul\n",
134 if (copy_to_user(buffer, buf, len)) 103 obd_max_dirty_pages / (1 << (20 - PAGE_CACHE_SHIFT)));
135 return -EFAULT;
136 *lenp = len;
137 *ppos += *lenp;
138 return 0;
139} 104}
140 105
141static int proc_pages_max(struct ctl_table *table, int write, 106static ssize_t max_dirty_mb_store(struct kobject *kobj, struct attribute *attr,
142 void __user *buffer, size_t *lenp, loff_t *ppos) 107 const char *buffer, size_t count)
143{ 108{
144 char buf[22]; 109 int rc;
145 int len; 110 unsigned long val;
146 111
147 if (!*lenp || (*ppos && !write)) { 112 rc = kstrtoul(buffer, 10, &val);
148 *lenp = 0; 113 if (rc)
149 return 0; 114 return rc;
150 }
151 if (write)
152 return -EINVAL;
153 115
154 len = snprintf(buf, sizeof(buf), "%llu\n", obd_pages_max()); 116 val *= 1 << (20 - PAGE_CACHE_SHIFT); /* convert to pages */
155 if (len > *lenp)
156 len = *lenp;
157 buf[len] = '\0';
158 if (copy_to_user(buffer, buf, len))
159 return -EFAULT;
160 *lenp = len;
161 *ppos += *lenp;
162 return 0;
163}
164 117
165static int proc_max_dirty_pages_in_mb(struct ctl_table *table, int write, 118 if (val > ((totalram_pages / 10) * 9)) {
166 void __user *buffer, size_t *lenp, loff_t *ppos) 119 /* Somebody wants to assign too much memory to dirty pages */
167{ 120 return -EINVAL;
168 int rc = 0;
169
170 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
171 *lenp = 0;
172 return 0;
173 } 121 }
174 if (write) {
175 rc = lprocfs_write_frac_helper(buffer, *lenp,
176 (unsigned int *)table->data,
177 1 << (20 - PAGE_CACHE_SHIFT));
178 /* Don't allow them to let dirty pages exceed 90% of system
179 * memory and set a hard minimum of 4MB. */
180 if (obd_max_dirty_pages > ((totalram_pages / 10) * 9)) {
181 CERROR("Refusing to set max dirty pages to %u, which is more than 90%% of available RAM; setting to %lu\n",
182 obd_max_dirty_pages,
183 ((totalram_pages / 10) * 9));
184 obd_max_dirty_pages = (totalram_pages / 10) * 9;
185 } else if (obd_max_dirty_pages < 4 << (20 - PAGE_CACHE_SHIFT)) {
186 obd_max_dirty_pages = 4 << (20 - PAGE_CACHE_SHIFT);
187 }
188 } else {
189 char buf[21];
190 int len;
191 122
192 len = lprocfs_read_frac_helper(buf, sizeof(buf), 123 if (val < 4 << (20 - PAGE_CACHE_SHIFT)) {
193 *(unsigned int *)table->data, 124 /* Less than 4 Mb for dirty cache is also bad */
194 1 << (20 - PAGE_CACHE_SHIFT)); 125 return -EINVAL;
195 if (len > *lenp)
196 len = *lenp;
197 buf[len] = '\0';
198 if (copy_to_user(buffer, buf, len))
199 return -EFAULT;
200 *lenp = len;
201 } 126 }
202 *ppos += *lenp;
203 return rc;
204}
205 127
206static int proc_alloc_fail_rate(struct ctl_table *table, int write, 128 obd_max_dirty_pages = val;
207 void __user *buffer, size_t *lenp, loff_t *ppos)
208{
209 int rc = 0;
210 129
211 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) { 130 return count;
212 *lenp = 0;
213 return 0;
214 }
215 if (write) {
216 rc = lprocfs_write_frac_helper(buffer, *lenp,
217 (unsigned int *)table->data,
218 OBD_ALLOC_FAIL_MULT);
219 } else {
220 char buf[21];
221 int len;
222
223 len = lprocfs_read_frac_helper(buf, 21,
224 *(unsigned int *)table->data,
225 OBD_ALLOC_FAIL_MULT);
226 if (len > *lenp)
227 len = *lenp;
228 buf[len] = '\0';
229 if (copy_to_user(buffer, buf, len))
230 return -EFAULT;
231 *lenp = len;
232 }
233 *ppos += *lenp;
234 return rc;
235} 131}
236 132LUSTRE_RW_ATTR(max_dirty_mb);
237static struct ctl_table obd_table[] = { 133
238 { 134LUSTRE_STATIC_UINT_ATTR(debug_peer_on_timeout, &obd_debug_peer_on_timeout);
239 .procname = "timeout", 135LUSTRE_STATIC_UINT_ATTR(dump_on_timeout, &obd_dump_on_timeout);
240 .data = &obd_timeout, 136LUSTRE_STATIC_UINT_ATTR(dump_on_eviction, &obd_dump_on_eviction);
241 .maxlen = sizeof(int), 137LUSTRE_STATIC_UINT_ATTR(at_min, &at_min);
242 .mode = 0644, 138LUSTRE_STATIC_UINT_ATTR(at_max, &at_max);
243 .proc_handler = &proc_set_timeout 139LUSTRE_STATIC_UINT_ATTR(at_extra, &at_extra);
244 }, 140LUSTRE_STATIC_UINT_ATTR(at_early_margin, &at_early_margin);
245 { 141LUSTRE_STATIC_UINT_ATTR(at_history, &at_history);
246 .procname = "debug_peer_on_timeout", 142
247 .data = &obd_debug_peer_on_timeout, 143static struct attribute *lustre_attrs[] = {
248 .maxlen = sizeof(int), 144 &lustre_sattr_timeout.u.attr,
249 .mode = 0644, 145 &lustre_attr_max_dirty_mb.attr,
250 .proc_handler = &proc_dointvec 146 &lustre_sattr_debug_peer_on_timeout.u.attr,
251 }, 147 &lustre_sattr_dump_on_timeout.u.attr,
252 { 148 &lustre_sattr_dump_on_eviction.u.attr,
253 .procname = "dump_on_timeout", 149 &lustre_sattr_at_min.u.attr,
254 .data = &obd_dump_on_timeout, 150 &lustre_sattr_at_max.u.attr,
255 .maxlen = sizeof(int), 151 &lustre_sattr_at_extra.u.attr,
256 .mode = 0644, 152 &lustre_sattr_at_early_margin.u.attr,
257 .proc_handler = &proc_dointvec 153 &lustre_sattr_at_history.u.attr,
258 }, 154 NULL,
259 {
260 .procname = "dump_on_eviction",
261 .data = &obd_dump_on_eviction,
262 .maxlen = sizeof(int),
263 .mode = 0644,
264 .proc_handler = &proc_dointvec
265 },
266 {
267 .procname = "memused",
268 .data = NULL,
269 .maxlen = 0,
270 .mode = 0444,
271 .proc_handler = &proc_memory_alloc
272 },
273 {
274 .procname = "pagesused",
275 .data = NULL,
276 .maxlen = 0,
277 .mode = 0444,
278 .proc_handler = &proc_pages_alloc
279 },
280 {
281 .procname = "memused_max",
282 .data = NULL,
283 .maxlen = 0,
284 .mode = 0444,
285 .proc_handler = &proc_mem_max
286 },
287 {
288 .procname = "pagesused_max",
289 .data = NULL,
290 .maxlen = 0,
291 .mode = 0444,
292 .proc_handler = &proc_pages_max
293 },
294 {
295 .procname = "ldlm_timeout",
296 .data = &ldlm_timeout,
297 .maxlen = sizeof(int),
298 .mode = 0644,
299 .proc_handler = &proc_set_timeout
300 },
301 {
302 .procname = "alloc_fail_rate",
303 .data = &obd_alloc_fail_rate,
304 .maxlen = sizeof(int),
305 .mode = 0644,
306 .proc_handler = &proc_alloc_fail_rate
307 },
308 {
309 .procname = "max_dirty_mb",
310 .data = &obd_max_dirty_pages,
311 .maxlen = sizeof(int),
312 .mode = 0644,
313 .proc_handler = &proc_max_dirty_pages_in_mb
314 },
315 {
316 .procname = "at_min",
317 .data = &at_min,
318 .maxlen = sizeof(int),
319 .mode = 0644,
320 .proc_handler = &proc_dointvec,
321 },
322 {
323 .procname = "at_max",
324 .data = &at_max,
325 .maxlen = sizeof(int),
326 .mode = 0644,
327 .proc_handler = &proc_dointvec,
328 },
329 {
330 .procname = "at_extra",
331 .data = &at_extra,
332 .maxlen = sizeof(int),
333 .mode = 0644,
334 .proc_handler = &proc_dointvec,
335 },
336 {
337 .procname = "at_early_margin",
338 .data = &at_early_margin,
339 .maxlen = sizeof(int),
340 .mode = 0644,
341 .proc_handler = &proc_dointvec,
342 },
343 {
344 .procname = "at_history",
345 .data = &at_history,
346 .maxlen = sizeof(int),
347 .mode = 0644,
348 .proc_handler = &proc_dointvec,
349 },
350 {}
351}; 155};
352 156
353static struct ctl_table parent_table[] = { 157static struct attribute_group lustre_attr_group = {
354 { 158 .attrs = lustre_attrs,
355 .procname = "lustre",
356 .data = NULL,
357 .maxlen = 0,
358 .mode = 0555,
359 .child = obd_table
360 },
361 {}
362}; 159};
363#endif
364 160
365void obd_sysctl_init(void) 161int obd_sysctl_init(void)
366{ 162{
367#ifdef CONFIG_SYSCTL 163 return sysfs_create_group(lustre_kobj, &lustre_attr_group);
368 if (!obd_table_header)
369 obd_table_header = register_sysctl_table(parent_table);
370#endif
371} 164}
372 165
373void obd_sysctl_clean(void) 166void obd_sysctl_clean(void)
374{ 167{
375#ifdef CONFIG_SYSCTL
376 if (obd_table_header)
377 unregister_sysctl_table(obd_table_header);
378 obd_table_header = NULL;
379#endif
380} 168}
diff --git a/drivers/staging/lustre/lustre/obdclass/llog.c b/drivers/staging/lustre/lustre/obdclass/llog.c
index 4fa52d1b79d1..facc8351fcea 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog.c
@@ -61,7 +61,7 @@ static struct llog_handle *llog_alloc_handle(void)
61 struct llog_handle *loghandle; 61 struct llog_handle *loghandle;
62 62
63 loghandle = kzalloc(sizeof(*loghandle), GFP_NOFS); 63 loghandle = kzalloc(sizeof(*loghandle), GFP_NOFS);
64 if (loghandle == NULL) 64 if (!loghandle)
65 return NULL; 65 return NULL;
66 66
67 init_rwsem(&loghandle->lgh_lock); 67 init_rwsem(&loghandle->lgh_lock);
@@ -208,7 +208,7 @@ int llog_init_handle(const struct lu_env *env, struct llog_handle *handle,
208 LASSERT(handle->lgh_hdr == NULL); 208 LASSERT(handle->lgh_hdr == NULL);
209 209
210 llh = kzalloc(sizeof(*llh), GFP_NOFS); 210 llh = kzalloc(sizeof(*llh), GFP_NOFS);
211 if (llh == NULL) 211 if (!llh)
212 return -ENOMEM; 212 return -ENOMEM;
213 handle->lgh_hdr = llh; 213 handle->lgh_hdr = llh;
214 /* first assign flags to use llog_client_ops */ 214 /* first assign flags to use llog_client_ops */
@@ -435,7 +435,7 @@ int llog_process_or_fork(const struct lu_env *env,
435 int rc; 435 int rc;
436 436
437 lpi = kzalloc(sizeof(*lpi), GFP_NOFS); 437 lpi = kzalloc(sizeof(*lpi), GFP_NOFS);
438 if (lpi == NULL) { 438 if (!lpi) {
439 CERROR("cannot alloc pointer\n"); 439 CERROR("cannot alloc pointer\n");
440 return -ENOMEM; 440 return -ENOMEM;
441 } 441 }
@@ -907,7 +907,7 @@ int llog_is_empty(const struct lu_env *env, struct llog_ctxt *ctxt,
907 char *name) 907 char *name)
908{ 908{
909 struct llog_handle *llh; 909 struct llog_handle *llh;
910 int rc = 0; 910 int rc;
911 911
912 rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS); 912 rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
913 if (rc < 0) { 913 if (rc < 0) {
diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
index 17e7c1807863..08d1f0edf98d 100644
--- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
+++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
@@ -275,7 +275,7 @@ struct dentry *ldebugfs_add_symlink(const char *name, struct dentry *parent,
275 return NULL; 275 return NULL;
276 276
277 dest = kzalloc(MAX_STRING_SIZE + 1, GFP_KERNEL); 277 dest = kzalloc(MAX_STRING_SIZE + 1, GFP_KERNEL);
278 if (dest == NULL) 278 if (!dest)
279 return NULL; 279 return NULL;
280 280
281 va_start(ap, format); 281 va_start(ap, format);
@@ -329,7 +329,7 @@ EXPORT_SYMBOL(ldebugfs_add_vars);
329 329
330void ldebugfs_remove(struct dentry **entryp) 330void ldebugfs_remove(struct dentry **entryp)
331{ 331{
332 debugfs_remove(*entryp); 332 debugfs_remove_recursive(*entryp);
333 *entryp = NULL; 333 *entryp = NULL;
334} 334}
335EXPORT_SYMBOL(ldebugfs_remove); 335EXPORT_SYMBOL(ldebugfs_remove);
diff --git a/drivers/staging/lustre/lustre/obdclass/lu_object.c b/drivers/staging/lustre/lustre/obdclass/lu_object.c
index 4d9b6333eeae..8e472327c880 100644
--- a/drivers/staging/lustre/lustre/obdclass/lu_object.c
+++ b/drivers/staging/lustre/lustre/obdclass/lu_object.c
@@ -602,7 +602,7 @@ static struct lu_object *lu_object_new(const struct lu_env *env,
602 struct lu_site_bkt_data *bkt; 602 struct lu_site_bkt_data *bkt;
603 603
604 o = lu_object_alloc(env, dev, f, conf); 604 o = lu_object_alloc(env, dev, f, conf);
605 if (unlikely(IS_ERR(o))) 605 if (IS_ERR(o))
606 return o; 606 return o;
607 607
608 hs = dev->ld_site->ls_obj_hash; 608 hs = dev->ld_site->ls_obj_hash;
@@ -666,7 +666,7 @@ static struct lu_object *lu_object_find_try(const struct lu_env *env,
666 * operations, including fld queries, inode loading, etc. 666 * operations, including fld queries, inode loading, etc.
667 */ 667 */
668 o = lu_object_alloc(env, dev, f, conf); 668 o = lu_object_alloc(env, dev, f, conf);
669 if (unlikely(IS_ERR(o))) 669 if (IS_ERR(o))
670 return o; 670 return o;
671 671
672 LASSERT(lu_fid_eq(lu_object_fid(o), f)); 672 LASSERT(lu_fid_eq(lu_object_fid(o), f));
@@ -674,7 +674,7 @@ static struct lu_object *lu_object_find_try(const struct lu_env *env,
674 cfs_hash_bd_lock(hs, &bd, 1); 674 cfs_hash_bd_lock(hs, &bd, 1);
675 675
676 shadow = htable_lookup(s, &bd, f, waiter, &version); 676 shadow = htable_lookup(s, &bd, f, waiter, &version);
677 if (likely(IS_ERR(shadow) && PTR_ERR(shadow) == -ENOENT)) { 677 if (likely(PTR_ERR(shadow) == -ENOENT)) {
678 struct lu_site_bkt_data *bkt; 678 struct lu_site_bkt_data *bkt;
679 679
680 bkt = cfs_hash_bd_extra_get(hs, &bd); 680 bkt = cfs_hash_bd_extra_get(hs, &bd);
@@ -1558,7 +1558,7 @@ static int keys_fill(struct lu_context *ctx)
1558 LINVRNT(key->lct_index == i); 1558 LINVRNT(key->lct_index == i);
1559 1559
1560 value = key->lct_init(ctx, key); 1560 value = key->lct_init(ctx, key);
1561 if (unlikely(IS_ERR(value))) 1561 if (IS_ERR(value))
1562 return PTR_ERR(value); 1562 return PTR_ERR(value);
1563 1563
1564 if (!(ctx->lc_tags & LCT_NOREF)) 1564 if (!(ctx->lc_tags & LCT_NOREF))
diff --git a/drivers/staging/lustre/lustre/obdclass/lustre_peer.c b/drivers/staging/lustre/lustre/obdclass/lustre_peer.c
index 5cc6435cc47a..d6184f821cd0 100644
--- a/drivers/staging/lustre/lustre/obdclass/lustre_peer.c
+++ b/drivers/staging/lustre/lustre/obdclass/lustre_peer.c
@@ -105,7 +105,7 @@ int class_add_uuid(const char *uuid, __u64 nid)
105 return -EOVERFLOW; 105 return -EOVERFLOW;
106 106
107 data = kzalloc(sizeof(*data), GFP_NOFS); 107 data = kzalloc(sizeof(*data), GFP_NOFS);
108 if (data == NULL) 108 if (!data)
109 return -ENOMEM; 109 return -ENOMEM;
110 110
111 obd_str2uuid(&data->un_uuid, uuid); 111 obd_str2uuid(&data->un_uuid, uuid);
diff --git a/drivers/staging/lustre/lustre/obdclass/obd_config.c b/drivers/staging/lustre/lustre/obdclass/obd_config.c
index fbdb748a36b9..93805ac93c5a 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_config.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_config.c
@@ -835,7 +835,7 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc,
835 CDEBUG(D_CONFIG, "Add profile %s\n", prof); 835 CDEBUG(D_CONFIG, "Add profile %s\n", prof);
836 836
837 lprof = kzalloc(sizeof(*lprof), GFP_NOFS); 837 lprof = kzalloc(sizeof(*lprof), GFP_NOFS);
838 if (lprof == NULL) 838 if (!lprof)
839 return -ENOMEM; 839 return -ENOMEM;
840 INIT_LIST_HEAD(&lprof->lp_list); 840 INIT_LIST_HEAD(&lprof->lp_list);
841 841
@@ -979,7 +979,7 @@ struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
979 new_len = LUSTRE_CFG_BUFLEN(cfg, 1) + strlen(new_name) - name_len; 979 new_len = LUSTRE_CFG_BUFLEN(cfg, 1) + strlen(new_name) - name_len;
980 980
981 new_param = kzalloc(new_len, GFP_NOFS); 981 new_param = kzalloc(new_len, GFP_NOFS);
982 if (new_param == NULL) 982 if (!new_param)
983 return ERR_PTR(-ENOMEM); 983 return ERR_PTR(-ENOMEM);
984 984
985 strcpy(new_param, new_name); 985 strcpy(new_param, new_name);
@@ -987,7 +987,7 @@ struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
987 strcat(new_param, value); 987 strcat(new_param, value);
988 988
989 bufs = kzalloc(sizeof(*bufs), GFP_NOFS); 989 bufs = kzalloc(sizeof(*bufs), GFP_NOFS);
990 if (bufs == NULL) { 990 if (!bufs) {
991 kfree(new_param); 991 kfree(new_param);
992 return ERR_PTR(-ENOMEM); 992 return ERR_PTR(-ENOMEM);
993 } 993 }
@@ -1123,12 +1123,7 @@ int class_process_config(struct lustre_cfg *lcfg)
1123 goto out; 1123 goto out;
1124 } 1124 }
1125 case LCFG_SET_LDLM_TIMEOUT: { 1125 case LCFG_SET_LDLM_TIMEOUT: {
1126 CDEBUG(D_IOCTL, "changing lustre ldlm_timeout from %d to %d\n", 1126 /* ldlm_timeout is not used on the client */
1127 ldlm_timeout, lcfg->lcfg_num);
1128 ldlm_timeout = max(lcfg->lcfg_num, 1U);
1129 if (ldlm_timeout >= obd_timeout)
1130 ldlm_timeout = max(obd_timeout / 3, 1U);
1131 ldlm_timeout_set = 1;
1132 err = 0; 1127 err = 0;
1133 goto out; 1128 goto out;
1134 } 1129 }
@@ -1461,7 +1456,7 @@ int class_config_llog_handler(const struct lu_env *env,
1461 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) + 1456 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
1462 sizeof(clli->cfg_instance) * 2 + 4; 1457 sizeof(clli->cfg_instance) * 2 + 4;
1463 inst_name = kzalloc(inst_len, GFP_NOFS); 1458 inst_name = kzalloc(inst_len, GFP_NOFS);
1464 if (inst_name == NULL) { 1459 if (!inst_name) {
1465 rc = -ENOMEM; 1460 rc = -ENOMEM;
1466 goto out; 1461 goto out;
1467 } 1462 }
@@ -1639,7 +1634,7 @@ int class_config_dump_handler(const struct lu_env *env,
1639 int rc = 0; 1634 int rc = 0;
1640 1635
1641 outstr = kzalloc(256, GFP_NOFS); 1636 outstr = kzalloc(256, GFP_NOFS);
1642 if (outstr == NULL) 1637 if (!outstr)
1643 return -ENOMEM; 1638 return -ENOMEM;
1644 1639
1645 if (rec->lrh_type == OBD_CFG_REC) { 1640 if (rec->lrh_type == OBD_CFG_REC) {
diff --git a/drivers/staging/lustre/lustre/obdclass/obd_mount.c b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
index ce4a71f7171a..7c5bab377f5c 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
@@ -85,7 +85,7 @@ int lustre_process_log(struct super_block *sb, char *logname,
85 LASSERT(cfg); 85 LASSERT(cfg);
86 86
87 bufs = kzalloc(sizeof(*bufs), GFP_NOFS); 87 bufs = kzalloc(sizeof(*bufs), GFP_NOFS);
88 if (bufs == NULL) 88 if (!bufs)
89 return -ENOMEM; 89 return -ENOMEM;
90 90
91 /* mgc_process_config */ 91 /* mgc_process_config */
@@ -247,18 +247,18 @@ int lustre_start_mgc(struct super_block *sb)
247 mutex_lock(&mgc_start_lock); 247 mutex_lock(&mgc_start_lock);
248 248
249 len = strlen(LUSTRE_MGC_OBDNAME) + strlen(libcfs_nid2str(nid)) + 1; 249 len = strlen(LUSTRE_MGC_OBDNAME) + strlen(libcfs_nid2str(nid)) + 1;
250 mgcname = kzalloc(len, GFP_NOFS); 250 mgcname = kasprintf(GFP_NOFS,
251 niduuid = kzalloc(len + 2, GFP_NOFS); 251 "%s%s", LUSTRE_MGC_OBDNAME, libcfs_nid2str(nid));
252 niduuid = kasprintf(GFP_NOFS, "%s_%x", mgcname, i);
252 if (!mgcname || !niduuid) { 253 if (!mgcname || !niduuid) {
253 rc = -ENOMEM; 254 rc = -ENOMEM;
254 goto out_free; 255 goto out_free;
255 } 256 }
256 sprintf(mgcname, "%s%s", LUSTRE_MGC_OBDNAME, libcfs_nid2str(nid));
257 257
258 mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : ""; 258 mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
259 259
260 data = kzalloc(sizeof(*data), GFP_NOFS); 260 data = kzalloc(sizeof(*data), GFP_NOFS);
261 if (data == NULL) { 261 if (!data) {
262 rc = -ENOMEM; 262 rc = -ENOMEM;
263 goto out_free; 263 goto out_free;
264 } 264 }
@@ -326,7 +326,6 @@ int lustre_start_mgc(struct super_block *sb)
326 326
327 /* Add the primary nids for the MGS */ 327 /* Add the primary nids for the MGS */
328 i = 0; 328 i = 0;
329 sprintf(niduuid, "%s_%x", mgcname, i);
330 if (IS_SERVER(lsi)) { 329 if (IS_SERVER(lsi)) {
331 ptr = lsi->lsi_lmd->lmd_mgs; 330 ptr = lsi->lsi_lmd->lmd_mgs;
332 if (IS_MGS(lsi)) { 331 if (IS_MGS(lsi)) {
@@ -885,7 +884,7 @@ static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
885 length = tail - ptr; 884 length = tail - ptr;
886 885
887 lmd->lmd_mgssec = kzalloc(length + 1, GFP_NOFS); 886 lmd->lmd_mgssec = kzalloc(length + 1, GFP_NOFS);
888 if (lmd->lmd_mgssec == NULL) 887 if (!lmd->lmd_mgssec)
889 return -ENOMEM; 888 return -ENOMEM;
890 889
891 memcpy(lmd->lmd_mgssec, ptr, length); 890 memcpy(lmd->lmd_mgssec, ptr, length);
@@ -911,7 +910,7 @@ static int lmd_parse_string(char **handle, char *ptr)
911 length = tail - ptr; 910 length = tail - ptr;
912 911
913 *handle = kzalloc(length + 1, GFP_NOFS); 912 *handle = kzalloc(length + 1, GFP_NOFS);
914 if (*handle == NULL) 913 if (!*handle)
915 return -ENOMEM; 914 return -ENOMEM;
916 915
917 memcpy(*handle, ptr, length); 916 memcpy(*handle, ptr, length);
@@ -941,7 +940,7 @@ static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
941 oldlen = strlen(lmd->lmd_mgs) + 1; 940 oldlen = strlen(lmd->lmd_mgs) + 1;
942 941
943 mgsnid = kzalloc(oldlen + length + 1, GFP_NOFS); 942 mgsnid = kzalloc(oldlen + length + 1, GFP_NOFS);
944 if (mgsnid == NULL) 943 if (!mgsnid)
945 return -ENOMEM; 944 return -ENOMEM;
946 945
947 if (lmd->lmd_mgs != NULL) { 946 if (lmd->lmd_mgs != NULL) {
@@ -983,7 +982,7 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
983 lmd->lmd_magic = LMD_MAGIC; 982 lmd->lmd_magic = LMD_MAGIC;
984 983
985 lmd->lmd_params = kzalloc(4096, GFP_NOFS); 984 lmd->lmd_params = kzalloc(4096, GFP_NOFS);
986 if (lmd->lmd_params == NULL) 985 if (!lmd->lmd_params)
987 return -ENOMEM; 986 return -ENOMEM;
988 lmd->lmd_params[0] = '\0'; 987 lmd->lmd_params[0] = '\0';
989 988
@@ -1120,10 +1119,9 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
1120 /* Remove leading /s from fsname */ 1119 /* Remove leading /s from fsname */
1121 while (*++s1 == '/') ; 1120 while (*++s1 == '/') ;
1122 /* Freed in lustre_free_lsi */ 1121 /* Freed in lustre_free_lsi */
1123 lmd->lmd_profile = kzalloc(strlen(s1) + 8, GFP_NOFS); 1122 lmd->lmd_profile = kasprintf(GFP_NOFS, "%s-client", s1);
1124 if (!lmd->lmd_profile) 1123 if (!lmd->lmd_profile)
1125 return -ENOMEM; 1124 return -ENOMEM;
1126 sprintf(lmd->lmd_profile, "%s-client", s1);
1127 } 1125 }
1128 1126
1129 /* Freed in lustre_free_lsi */ 1127 /* Freed in lustre_free_lsi */
@@ -1281,7 +1279,7 @@ struct file_system_type lustre_fs_type = {
1281 .mount = lustre_mount, 1279 .mount = lustre_mount,
1282 .kill_sb = lustre_kill_super, 1280 .kill_sb = lustre_kill_super,
1283 .fs_flags = FS_BINARY_MOUNTDATA | FS_REQUIRES_DEV | 1281 .fs_flags = FS_BINARY_MOUNTDATA | FS_REQUIRES_DEV |
1284 FS_HAS_FIEMAP | FS_RENAME_DOES_D_MOVE, 1282 FS_RENAME_DOES_D_MOVE,
1285}; 1283};
1286MODULE_ALIAS_FS("lustre"); 1284MODULE_ALIAS_FS("lustre");
1287 1285
diff --git a/drivers/staging/lustre/lustre/obdclass/uuid.c b/drivers/staging/lustre/lustre/obdclass/uuid.c
index ff0a01bcf8da..b0b0157a6334 100644
--- a/drivers/staging/lustre/lustre/obdclass/uuid.c
+++ b/drivers/staging/lustre/lustre/obdclass/uuid.c
@@ -43,40 +43,8 @@
43#include "../include/obd_support.h" 43#include "../include/obd_support.h"
44#include "../include/obd_class.h" 44#include "../include/obd_class.h"
45 45
46
47static inline __u32 consume(int nob, __u8 **ptr)
48{
49 __u32 value;
50
51 LASSERT(nob <= sizeof(value));
52
53 for (value = 0; nob > 0; --nob)
54 value = (value << 8) | *((*ptr)++);
55 return value;
56}
57
58#define CONSUME(val, ptr) (val) = consume(sizeof(val), (ptr))
59
60static void uuid_unpack(class_uuid_t in, __u16 *uu, int nr)
61{
62 __u8 *ptr = in;
63
64 LASSERT(nr * sizeof(*uu) == sizeof(class_uuid_t));
65
66 while (nr-- > 0)
67 CONSUME(uu[nr], &ptr);
68}
69
70void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out) 46void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
71{ 47{
72 /* uu as an array of __u16's */ 48 sprintf(out->uuid, "%pU", uu);
73 __u16 uuid[sizeof(class_uuid_t) / sizeof(__u16)];
74
75 CLASSERT(ARRAY_SIZE(uuid) == 8);
76
77 uuid_unpack(uu, uuid, ARRAY_SIZE(uuid));
78 sprintf(out->uuid, "%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
79 uuid[0], uuid[1], uuid[2], uuid[3],
80 uuid[4], uuid[5], uuid[6], uuid[7]);
81} 49}
82EXPORT_SYMBOL(class_uuid_unparse); 50EXPORT_SYMBOL(class_uuid_unparse);
diff --git a/drivers/staging/lustre/lustre/obdecho/echo_client.c b/drivers/staging/lustre/lustre/obdecho/echo_client.c
index 0222fd2e4757..27bd170c3a28 100644
--- a/drivers/staging/lustre/lustre/obdecho/echo_client.c
+++ b/drivers/staging/lustre/lustre/obdecho/echo_client.c
@@ -480,11 +480,11 @@ static int echo_alloc_memmd(struct echo_device *ed,
480 480
481 LASSERT(*lsmp == NULL); 481 LASSERT(*lsmp == NULL);
482 *lsmp = kzalloc(lsm_size, GFP_NOFS); 482 *lsmp = kzalloc(lsm_size, GFP_NOFS);
483 if (*lsmp == NULL) 483 if (!*lsmp)
484 return -ENOMEM; 484 return -ENOMEM;
485 485
486 (*lsmp)->lsm_oinfo[0] = kzalloc(sizeof(struct lov_oinfo), GFP_NOFS); 486 (*lsmp)->lsm_oinfo[0] = kzalloc(sizeof(struct lov_oinfo), GFP_NOFS);
487 if ((*lsmp)->lsm_oinfo[0] == NULL) { 487 if (!(*lsmp)->lsm_oinfo[0]) {
488 kfree(*lsmp); 488 kfree(*lsmp);
489 return -ENOMEM; 489 return -ENOMEM;
490 } 490 }
@@ -701,7 +701,7 @@ static struct lu_device *echo_device_alloc(const struct lu_env *env,
701 int cleanup = 0; 701 int cleanup = 0;
702 702
703 ed = kzalloc(sizeof(*ed), GFP_NOFS); 703 ed = kzalloc(sizeof(*ed), GFP_NOFS);
704 if (ed == NULL) { 704 if (!ed) {
705 rc = -ENOMEM; 705 rc = -ENOMEM;
706 goto out; 706 goto out;
707 } 707 }
@@ -1878,7 +1878,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1878 return rc; 1878 return rc;
1879 1879
1880 env = kzalloc(sizeof(*env), GFP_NOFS); 1880 env = kzalloc(sizeof(*env), GFP_NOFS);
1881 if (env == NULL) 1881 if (!env)
1882 return -ENOMEM; 1882 return -ENOMEM;
1883 1883
1884 rc = lu_env_init(env, LCT_DT_THREAD); 1884 rc = lu_env_init(env, LCT_DT_THREAD);
@@ -2049,7 +2049,7 @@ static int echo_client_setup(const struct lu_env *env,
2049 ec->ec_nstripes = 0; 2049 ec->ec_nstripes = 0;
2050 2050
2051 ocd = kzalloc(sizeof(*ocd), GFP_NOFS); 2051 ocd = kzalloc(sizeof(*ocd), GFP_NOFS);
2052 if (ocd == NULL) { 2052 if (!ocd) {
2053 CERROR("Can't alloc ocd connecting to %s\n", 2053 CERROR("Can't alloc ocd connecting to %s\n",
2054 lustre_cfg_string(lcfg, 1)); 2054 lustre_cfg_string(lcfg, 1));
2055 return -ENOMEM; 2055 return -ENOMEM;
@@ -2139,7 +2139,7 @@ static struct obd_ops echo_client_obd_ops = {
2139 .o_disconnect = echo_client_disconnect 2139 .o_disconnect = echo_client_disconnect
2140}; 2140};
2141 2141
2142int echo_client_init(void) 2142static int echo_client_init(void)
2143{ 2143{
2144 int rc; 2144 int rc;
2145 2145
@@ -2154,7 +2154,7 @@ int echo_client_init(void)
2154 return rc; 2154 return rc;
2155} 2155}
2156 2156
2157void echo_client_exit(void) 2157static void echo_client_exit(void)
2158{ 2158{
2159 class_unregister_type(LUSTRE_ECHO_CLIENT_NAME); 2159 class_unregister_type(LUSTRE_ECHO_CLIENT_NAME);
2160 lu_kmem_fini(echo_caches); 2160 lu_kmem_fini(echo_caches);
diff --git a/drivers/staging/lustre/lustre/osc/osc_cache.c b/drivers/staging/lustre/lustre/osc/osc_cache.c
index 5592d32a1a95..c72035e048aa 100644
--- a/drivers/staging/lustre/lustre/osc/osc_cache.c
+++ b/drivers/staging/lustre/lustre/osc/osc_cache.c
@@ -1837,12 +1837,6 @@ static int try_to_add_extent_for_io(struct client_obd *cli,
1837 oap2 = list_first_entry(&tmp->oe_pages, struct osc_async_page, 1837 oap2 = list_first_entry(&tmp->oe_pages, struct osc_async_page,
1838 oap_pending_item); 1838 oap_pending_item);
1839 EASSERT(tmp->oe_owner == current, tmp); 1839 EASSERT(tmp->oe_owner == current, tmp);
1840#if 0
1841 if (overlapped(tmp, ext)) {
1842 OSC_EXTENT_DUMP(D_ERROR, tmp, "overlapped %p.\n", ext);
1843 EASSERT(0, ext);
1844 }
1845#endif
1846 if (oap2cl_page(oap)->cp_type != oap2cl_page(oap2)->cp_type) { 1840 if (oap2cl_page(oap)->cp_type != oap2cl_page(oap2)->cp_type) {
1847 CDEBUG(D_CACHE, "Do not permit different type of IO" 1841 CDEBUG(D_CACHE, "Do not permit different type of IO"
1848 " for a same RPC\n"); 1842 " for a same RPC\n");
diff --git a/drivers/staging/lustre/lustre/osc/osc_dev.c b/drivers/staging/lustre/lustre/osc/osc_dev.c
index 9222c9f4faae..91fdec44792b 100644
--- a/drivers/staging/lustre/lustre/osc/osc_dev.c
+++ b/drivers/staging/lustre/lustre/osc/osc_dev.c
@@ -218,7 +218,7 @@ static struct lu_device *osc_device_alloc(const struct lu_env *env,
218 int rc; 218 int rc;
219 219
220 od = kzalloc(sizeof(*od), GFP_NOFS); 220 od = kzalloc(sizeof(*od), GFP_NOFS);
221 if (od == NULL) 221 if (!od)
222 return ERR_PTR(-ENOMEM); 222 return ERR_PTR(-ENOMEM);
223 223
224 cl_device_init(&od->od_cl, t); 224 cl_device_init(&od->od_cl, t);
diff --git a/drivers/staging/lustre/lustre/osc/osc_page.c b/drivers/staging/lustre/lustre/osc/osc_page.c
index 43dfa73dd3a6..f9cf5cea643d 100644
--- a/drivers/staging/lustre/lustre/osc/osc_page.c
+++ b/drivers/staging/lustre/lustre/osc/osc_page.c
@@ -471,7 +471,7 @@ static int osc_page_flush(const struct lu_env *env,
471 struct cl_io *io) 471 struct cl_io *io)
472{ 472{
473 struct osc_page *opg = cl2osc_page(slice); 473 struct osc_page *opg = cl2osc_page(slice);
474 int rc = 0; 474 int rc;
475 475
476 rc = osc_flush_async_page(env, io, opg); 476 rc = osc_flush_async_page(env, io, opg);
477 return rc; 477 return rc;
diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c
index f84b4c78a8a0..12113dfd87b8 100644
--- a/drivers/staging/lustre/lustre/osc/osc_request.c
+++ b/drivers/staging/lustre/lustre/osc/osc_request.c
@@ -119,7 +119,7 @@ static int osc_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
119 119
120 if (*lmmp == NULL) { 120 if (*lmmp == NULL) {
121 *lmmp = kzalloc(lmm_size, GFP_NOFS); 121 *lmmp = kzalloc(lmm_size, GFP_NOFS);
122 if (*lmmp == NULL) 122 if (!*lmmp)
123 return -ENOMEM; 123 return -ENOMEM;
124 } 124 }
125 125
@@ -1909,7 +1909,7 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
1909 mpflag = cfs_memory_pressure_get_and_set(); 1909 mpflag = cfs_memory_pressure_get_and_set();
1910 1910
1911 crattr = kzalloc(sizeof(*crattr), GFP_NOFS); 1911 crattr = kzalloc(sizeof(*crattr), GFP_NOFS);
1912 if (crattr == NULL) { 1912 if (!crattr) {
1913 rc = -ENOMEM; 1913 rc = -ENOMEM;
1914 goto out; 1914 goto out;
1915 } 1915 }
@@ -2665,7 +2665,7 @@ static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2665 2665
2666 buf = NULL; 2666 buf = NULL;
2667 len = 0; 2667 len = 0;
2668 if (obd_ioctl_getdata(&buf, &len, (void *)uarg)) { 2668 if (obd_ioctl_getdata(&buf, &len, uarg)) {
2669 err = -EINVAL; 2669 err = -EINVAL;
2670 goto out; 2670 goto out;
2671 } 2671 }
@@ -2695,7 +2695,7 @@ static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2695 2695
2696 memcpy(data->ioc_inlbuf2, &obd->obd_uuid, sizeof(uuid)); 2696 memcpy(data->ioc_inlbuf2, &obd->obd_uuid, sizeof(uuid));
2697 2697
2698 err = copy_to_user((void *)uarg, buf, len); 2698 err = copy_to_user(uarg, buf, len);
2699 if (err) 2699 if (err)
2700 err = -EFAULT; 2700 err = -EFAULT;
2701 obd_ioctl_freedata(buf, len); 2701 obd_ioctl_freedata(buf, len);
diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c
index a12cd66b2365..c83a34a01e65 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/client.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/client.c
@@ -971,7 +971,7 @@ int ptlrpc_set_add_cb(struct ptlrpc_request_set *set,
971 struct ptlrpc_set_cbdata *cbdata; 971 struct ptlrpc_set_cbdata *cbdata;
972 972
973 cbdata = kzalloc(sizeof(*cbdata), GFP_NOFS); 973 cbdata = kzalloc(sizeof(*cbdata), GFP_NOFS);
974 if (cbdata == NULL) 974 if (!cbdata)
975 return -ENOMEM; 975 return -ENOMEM;
976 976
977 cbdata->psc_interpret = fn; 977 cbdata->psc_interpret = fn;
diff --git a/drivers/staging/lustre/lustre/ptlrpc/events.c b/drivers/staging/lustre/lustre/ptlrpc/events.c
index 8cb1929fd31d..c8ef9e578263 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/events.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/events.c
@@ -485,7 +485,7 @@ int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
485 return rc; 485 return rc;
486} 486}
487 487
488void ptlrpc_ni_fini(void) 488static void ptlrpc_ni_fini(void)
489{ 489{
490 wait_queue_head_t waitq; 490 wait_queue_head_t waitq;
491 struct l_wait_info lwi; 491 struct l_wait_info lwi;
@@ -529,7 +529,7 @@ lnet_pid_t ptl_get_pid(void)
529 return pid; 529 return pid;
530} 530}
531 531
532int ptlrpc_ni_init(void) 532static int ptlrpc_ni_init(void)
533{ 533{
534 int rc; 534 int rc;
535 lnet_pid_t pid; 535 lnet_pid_t pid;
diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c
index c9b8481dd384..1eae3896c037 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/import.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/import.c
@@ -555,14 +555,12 @@ static int import_select_connection(struct obd_import *imp)
555 imp_conn->oic_last_attempt = cfs_time_current_64(); 555 imp_conn->oic_last_attempt = cfs_time_current_64();
556 556
557 /* switch connection, don't mind if it's same as the current one */ 557 /* switch connection, don't mind if it's same as the current one */
558 if (imp->imp_connection) 558 ptlrpc_connection_put(imp->imp_connection);
559 ptlrpc_connection_put(imp->imp_connection);
560 imp->imp_connection = ptlrpc_connection_addref(imp_conn->oic_conn); 559 imp->imp_connection = ptlrpc_connection_addref(imp_conn->oic_conn);
561 560
562 dlmexp = class_conn2export(&imp->imp_dlm_handle); 561 dlmexp = class_conn2export(&imp->imp_dlm_handle);
563 LASSERT(dlmexp != NULL); 562 LASSERT(dlmexp != NULL);
564 if (dlmexp->exp_connection) 563 ptlrpc_connection_put(dlmexp->exp_connection);
565 ptlrpc_connection_put(dlmexp->exp_connection);
566 dlmexp->exp_connection = ptlrpc_connection_addref(imp_conn->oic_conn); 564 dlmexp->exp_connection = ptlrpc_connection_addref(imp_conn->oic_conn);
567 class_export_put(dlmexp); 565 class_export_put(dlmexp);
568 566
diff --git a/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c b/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
index aaaabbf5f1b9..53f9af1f2f3e 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
@@ -652,7 +652,7 @@ static ssize_t ptlrpc_lprocfs_nrs_seq_write(struct file *file,
652 return -EINVAL; 652 return -EINVAL;
653 653
654 cmd = kzalloc(LPROCFS_NRS_WR_MAX_CMD, GFP_NOFS); 654 cmd = kzalloc(LPROCFS_NRS_WR_MAX_CMD, GFP_NOFS);
655 if (cmd == NULL) 655 if (!cmd)
656 return -ENOMEM; 656 return -ENOMEM;
657 /** 657 /**
658 * strsep() modifies its argument, so keep a copy 658 * strsep() modifies its argument, so keep a copy
@@ -819,7 +819,7 @@ ptlrpc_lprocfs_svc_req_history_start(struct seq_file *s, loff_t *pos)
819 } 819 }
820 820
821 srhi = kzalloc(sizeof(*srhi), GFP_NOFS); 821 srhi = kzalloc(sizeof(*srhi), GFP_NOFS);
822 if (srhi == NULL) 822 if (!srhi)
823 return NULL; 823 return NULL;
824 824
825 srhi->srhi_seq = 0; 825 srhi->srhi_seq = 0;
@@ -1219,7 +1219,7 @@ int lprocfs_wr_evict_client(struct file *file, const char __user *buffer,
1219 char *tmpbuf; 1219 char *tmpbuf;
1220 1220
1221 kbuf = kzalloc(BUFLEN, GFP_NOFS); 1221 kbuf = kzalloc(BUFLEN, GFP_NOFS);
1222 if (kbuf == NULL) 1222 if (!kbuf)
1223 return -ENOMEM; 1223 return -ENOMEM;
1224 1224
1225 /* 1225 /*
@@ -1303,7 +1303,7 @@ int lprocfs_wr_import(struct file *file, const char __user *buffer,
1303 return -EINVAL; 1303 return -EINVAL;
1304 1304
1305 kbuf = kzalloc(count + 1, GFP_NOFS); 1305 kbuf = kzalloc(count + 1, GFP_NOFS);
1306 if (kbuf == NULL) 1306 if (!kbuf)
1307 return -ENOMEM; 1307 return -ENOMEM;
1308 1308
1309 if (copy_from_user(kbuf, buffer, count)) { 1309 if (copy_from_user(kbuf, buffer, count)) {
diff --git a/drivers/staging/lustre/lustre/ptlrpc/nrs.c b/drivers/staging/lustre/lustre/ptlrpc/nrs.c
index 9516acadb7a1..d37cdd5ac580 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/nrs.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/nrs.c
@@ -1156,7 +1156,7 @@ int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf)
1156 } 1156 }
1157 1157
1158 desc = kzalloc(sizeof(*desc), GFP_NOFS); 1158 desc = kzalloc(sizeof(*desc), GFP_NOFS);
1159 if (desc == NULL) { 1159 if (!desc) {
1160 rc = -ENOMEM; 1160 rc = -ENOMEM;
1161 goto fail; 1161 goto fail;
1162 } 1162 }
diff --git a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c
index 2787bfd67165..84937ad90570 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c
@@ -52,6 +52,8 @@
52#include "../include/obd_cksum.h" 52#include "../include/obd_cksum.h"
53#include "../include/lustre/ll_fiemap.h" 53#include "../include/lustre/ll_fiemap.h"
54 54
55#include "ptlrpc_internal.h"
56
55static inline int lustre_msg_hdr_size_v2(int count) 57static inline int lustre_msg_hdr_size_v2(int count)
56{ 58{
57 return cfs_size_round(offsetof(struct lustre_msg_v2, 59 return cfs_size_round(offsetof(struct lustre_msg_v2,
diff --git a/drivers/staging/lustre/lustre/ptlrpc/pinger.c b/drivers/staging/lustre/lustre/ptlrpc/pinger.c
index d05c37c1fd30..f8edb791a998 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/pinger.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/pinger.c
@@ -318,8 +318,6 @@ int ptlrpc_start_pinger(void)
318 318
319 strcpy(pinger_thread.t_name, "ll_ping"); 319 strcpy(pinger_thread.t_name, "ll_ping");
320 320
321 /* CLONE_VM and CLONE_FILES just avoid a needless copy, because we
322 * just drop the VM and FILES in cfs_daemonize_ctxt() right away. */
323 rc = PTR_ERR(kthread_run(ptlrpc_pinger_main, &pinger_thread, 321 rc = PTR_ERR(kthread_run(ptlrpc_pinger_main, &pinger_thread,
324 "%s", pinger_thread.t_name)); 322 "%s", pinger_thread.t_name));
325 if (IS_ERR_VALUE(rc)) { 323 if (IS_ERR_VALUE(rc)) {
diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c
index 5268887ca6b3..ae99180d6036 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c
@@ -51,7 +51,7 @@ extern spinlock_t ptlrpc_rs_debug_lock;
51extern struct mutex pinger_mutex; 51extern struct mutex pinger_mutex;
52extern struct mutex ptlrpcd_mutex; 52extern struct mutex ptlrpcd_mutex;
53 53
54__init int ptlrpc_init(void) 54static int __init ptlrpc_init(void)
55{ 55{
56 int rc, cleanup_phase = 0; 56 int rc, cleanup_phase = 0;
57 57
diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
index e591cff323ec..17cc81d5074f 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
@@ -739,7 +739,7 @@ static int ptlrpcd_init(void)
739 739
740 size = offsetof(struct ptlrpcd, pd_threads[nthreads]); 740 size = offsetof(struct ptlrpcd, pd_threads[nthreads]);
741 ptlrpcds = kzalloc(size, GFP_NOFS); 741 ptlrpcds = kzalloc(size, GFP_NOFS);
742 if (ptlrpcds == NULL) { 742 if (!ptlrpcds) {
743 rc = -ENOMEM; 743 rc = -ENOMEM;
744 goto out; 744 goto out;
745 } 745 }
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
index 69d73c430696..2ee3e8b2e879 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
@@ -415,7 +415,7 @@ static int enc_pools_add_pages(int npages)
415 415
416 for (i = 0; i < npools; i++) { 416 for (i = 0; i < npools; i++) {
417 pools[i] = kzalloc(PAGE_CACHE_SIZE, GFP_NOFS); 417 pools[i] = kzalloc(PAGE_CACHE_SIZE, GFP_NOFS);
418 if (pools[i] == NULL) 418 if (!pools[i])
419 goto out_pools; 419 goto out_pools;
420 420
421 for (j = 0; j < PAGES_PER_POOL && alloced < npages; j++) { 421 for (j = 0; j < PAGES_PER_POOL && alloced < npages; j++) {
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_config.c b/drivers/staging/lustre/lustre/ptlrpc/sec_config.c
index 31da43e8b3c6..e7f2f333257d 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_config.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_config.c
@@ -564,7 +564,7 @@ struct sptlrpc_conf *sptlrpc_conf_get(const char *fsname,
564 return NULL; 564 return NULL;
565 565
566 conf = kzalloc(sizeof(*conf), GFP_NOFS); 566 conf = kzalloc(sizeof(*conf), GFP_NOFS);
567 if (conf == NULL) 567 if (!conf)
568 return NULL; 568 return NULL;
569 569
570 strcpy(conf->sc_fsname, fsname); 570 strcpy(conf->sc_fsname, fsname);
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c b/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
index 53ce0d14bd46..a243db60f697 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
@@ -444,7 +444,7 @@ struct ptlrpc_sec *plain_create_sec(struct obd_import *imp,
444 LASSERT(SPTLRPC_FLVR_POLICY(sf->sf_rpc) == SPTLRPC_POLICY_PLAIN); 444 LASSERT(SPTLRPC_FLVR_POLICY(sf->sf_rpc) == SPTLRPC_POLICY_PLAIN);
445 445
446 plsec = kzalloc(sizeof(*plsec), GFP_NOFS); 446 plsec = kzalloc(sizeof(*plsec), GFP_NOFS);
447 if (plsec == NULL) 447 if (!plsec)
448 return NULL; 448 return NULL;
449 449
450 /* 450 /*
diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c
index 9117f1c15a8e..003344ccfffc 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/service.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/service.c
@@ -43,7 +43,7 @@
43#include "ptlrpc_internal.h" 43#include "ptlrpc_internal.h"
44 44
45/* The following are visible and mutable through /sys/module/ptlrpc */ 45/* The following are visible and mutable through /sys/module/ptlrpc */
46int test_req_buffer_pressure = 0; 46int test_req_buffer_pressure;
47module_param(test_req_buffer_pressure, int, 0444); 47module_param(test_req_buffer_pressure, int, 0444);
48MODULE_PARM_DESC(test_req_buffer_pressure, "set non-zero to put pressure on request buffer pools"); 48MODULE_PARM_DESC(test_req_buffer_pressure, "set non-zero to put pressure on request buffer pools");
49module_param(at_min, int, 0644); 49module_param(at_min, int, 0644);
@@ -69,7 +69,7 @@ LIST_HEAD(ptlrpc_all_services);
69/** Used to protect the \e ptlrpc_all_services list */ 69/** Used to protect the \e ptlrpc_all_services list */
70struct mutex ptlrpc_all_services_mutex; 70struct mutex ptlrpc_all_services_mutex;
71 71
72struct ptlrpc_request_buffer_desc * 72static struct ptlrpc_request_buffer_desc *
73ptlrpc_alloc_rqbd(struct ptlrpc_service_part *svcpt) 73ptlrpc_alloc_rqbd(struct ptlrpc_service_part *svcpt)
74{ 74{
75 struct ptlrpc_service *svc = svcpt->scp_service; 75 struct ptlrpc_service *svc = svcpt->scp_service;
@@ -101,7 +101,7 @@ ptlrpc_alloc_rqbd(struct ptlrpc_service_part *svcpt)
101 return rqbd; 101 return rqbd;
102} 102}
103 103
104void 104static void
105ptlrpc_free_rqbd(struct ptlrpc_request_buffer_desc *rqbd) 105ptlrpc_free_rqbd(struct ptlrpc_request_buffer_desc *rqbd)
106{ 106{
107 struct ptlrpc_service_part *svcpt = rqbd->rqbd_svcpt; 107 struct ptlrpc_service_part *svcpt = rqbd->rqbd_svcpt;
@@ -118,7 +118,7 @@ ptlrpc_free_rqbd(struct ptlrpc_request_buffer_desc *rqbd)
118 kfree(rqbd); 118 kfree(rqbd);
119} 119}
120 120
121int 121static int
122ptlrpc_grow_req_bufs(struct ptlrpc_service_part *svcpt, int post) 122ptlrpc_grow_req_bufs(struct ptlrpc_service_part *svcpt, int post)
123{ 123{
124 struct ptlrpc_service *svc = svcpt->scp_service; 124 struct ptlrpc_service *svc = svcpt->scp_service;
@@ -732,7 +732,7 @@ ptlrpc_register_service(struct ptlrpc_service_conf *conf,
732 732
733 service = kzalloc(offsetof(struct ptlrpc_service, srv_parts[ncpts]), 733 service = kzalloc(offsetof(struct ptlrpc_service, srv_parts[ncpts]),
734 GFP_NOFS); 734 GFP_NOFS);
735 if (service == NULL) { 735 if (!service) {
736 kfree(cpts); 736 kfree(cpts);
737 return ERR_PTR(-ENOMEM); 737 return ERR_PTR(-ENOMEM);
738 } 738 }
@@ -2298,7 +2298,7 @@ static int ptlrpc_main(void *arg)
2298 } 2298 }
2299 2299
2300 env = kzalloc(sizeof(*env), GFP_NOFS); 2300 env = kzalloc(sizeof(*env), GFP_NOFS);
2301 if (env == NULL) { 2301 if (!env) {
2302 rc = -ENOMEM; 2302 rc = -ENOMEM;
2303 goto out_srv_fini; 2303 goto out_srv_fini;
2304 } 2304 }
@@ -2826,9 +2826,7 @@ void ptlrpc_hr_fini(void)
2826 ptlrpc_stop_hr_threads(); 2826 ptlrpc_stop_hr_threads();
2827 2827
2828 cfs_percpt_for_each(hrp, i, ptlrpc_hr.hr_partitions) { 2828 cfs_percpt_for_each(hrp, i, ptlrpc_hr.hr_partitions) {
2829 if (hrp->hrp_thrs != NULL) { 2829 kfree(hrp->hrp_thrs);
2830 kfree(hrp->hrp_thrs);
2831 }
2832 } 2830 }
2833 2831
2834 cfs_percpt_free(ptlrpc_hr.hr_partitions); 2832 cfs_percpt_free(ptlrpc_hr.hr_partitions);
@@ -3054,7 +3052,7 @@ EXPORT_SYMBOL(ptlrpc_unregister_service);
3054 * Right now, it just checks to make sure that requests aren't languishing 3052 * Right now, it just checks to make sure that requests aren't languishing
3055 * in the queue. We'll use this health check to govern whether a node needs 3053 * in the queue. We'll use this health check to govern whether a node needs
3056 * to be shot, so it's intentionally non-aggressive. */ 3054 * to be shot, so it's intentionally non-aggressive. */
3057int ptlrpc_svcpt_health_check(struct ptlrpc_service_part *svcpt) 3055static int ptlrpc_svcpt_health_check(struct ptlrpc_service_part *svcpt)
3058{ 3056{
3059 struct ptlrpc_request *request = NULL; 3057 struct ptlrpc_request *request = NULL;
3060 struct timeval right_now; 3058 struct timeval right_now;
diff --git a/drivers/staging/lustre/sysfs-fs-lustre b/drivers/staging/lustre/sysfs-fs-lustre
index 1e302e8516ce..873e2cf31217 100644
--- a/drivers/staging/lustre/sysfs-fs-lustre
+++ b/drivers/staging/lustre/sysfs-fs-lustre
@@ -40,6 +40,109 @@ Description:
40 e.g. dd.1253 40 e.g. dd.1253
41 nodelocal - use jobid_name value from above. 41 nodelocal - use jobid_name value from above.
42 42
43What: /sys/fs/lustre/timeout
44Date: June 2015
45Contact: "Oleg Drokin" <oleg.drokin@intel.com>
46Description:
47 Controls "lustre timeout" variable, also known as obd_timeout
48 in some old manual. In the past obd_timeout was of paramount
49 importance as the timeout value used everywhere and where
50 other timeouts were derived from. These days it's much less
51 important as network timeouts are mostly determined by
52 AT (adaptive timeouts).
53 Unit: seconds, default: 100
54
55What: /sys/fs/lustre/max_dirty_mb
56Date: June 2015
57Contact: "Oleg Drokin" <oleg.drokin@intel.com>
58Description:
59 Controls total number of dirty cache (in megabytes) allowed
60 across all mounted lustre filesystems.
61 Since writeout of dirty pages in Lustre is somewhat expensive,
62 when you allow to many dirty pages, this might lead to
63 performance degradations as kernel tries to desperately
64 find some pages to free/writeout.
65 Default 1/2 RAM. Min value 4, max value 9/10 of RAM.
66
67What: /sys/fs/lustre/debug_peer_on_timeout
68Date: June 2015
69Contact: "Oleg Drokin" <oleg.drokin@intel.com>
70Description:
71 Control if lnet debug information should be printed when
72 an RPC timeout occurs.
73 0 disabled (default)
74 1 enabled
75
76What: /sys/fs/lustre/dump_on_timeout
77Date: June 2015
78Contact: "Oleg Drokin" <oleg.drokin@intel.com>
79Description:
80 Controls if Lustre debug log should be dumped when an RPC
81 timeout occurs. This is useful if yout debug buffer typically
82 rolls over by the time you notice RPC timeouts.
83
84What: /sys/fs/lustre/dump_on_eviction
85Date: June 2015
86Contact: "Oleg Drokin" <oleg.drokin@intel.com>
87Description:
88 Controls if Lustre debug log should be dumped when an this
89 client is evicted from one of the servers.
90 This is useful if yout debug buffer typically rolls over
91 by the time you notice the eviction event.
92
93What: /sys/fs/lustre/at_min
94Date: July 2015
95Contact: "Oleg Drokin" <oleg.drokin@intel.com>
96Description:
97 Controls minimum adaptive timeout in seconds. If you encounter
98 a case where clients timeout due to server-reported processing
99 time being too short, you might consider increasing this value.
100 One common case of this if the underlying network has
101 unpredictable long delays.
102 Default: 0
103
104What: /sys/fs/lustre/at_max
105Date: July 2015
106Contact: "Oleg Drokin" <oleg.drokin@intel.com>
107Description:
108 Controls maximum adaptive timeout in seconds. If at_max timeout
109 is reached for an RPC, the RPC will time out.
110 Some genuinuely slow network hardware might warrant increasing
111 this value.
112 Setting this value to 0 disables Adaptive Timeouts
113 functionality and old-style obd_timeout value is then used.
114 Default: 600
115
116What: /sys/fs/lustre/at_extra
117Date: July 2015
118Contact: "Oleg Drokin" <oleg.drokin@intel.com>
119Description:
120 Controls how much extra time to request for unfinished requests
121 in processing in seconds. Normally a server-side parameter, it
122 is also used on the client for responses to various LDLM ASTs
123 that are handled with a special server thread on the client.
124 This is a way for the servers to ask the clients not to time
125 out the request that reached current servicing time estimate
126 yet and give it some more time.
127 Default: 30
128
129What: /sys/fs/lustre/at_early_margin
130Date: July 2015
131Contact: "Oleg Drokin" <oleg.drokin@intel.com>
132Description:
133 Controls when to send the early reply for requests that are
134 about to timeout as an offset to the estimated service time in
135 seconds..
136 Default: 5
137
138What: /sys/fs/lustre/at_history
139Date: July 2015
140Contact: "Oleg Drokin" <oleg.drokin@intel.com>
141Description:
142 Controls for how many seconds to remember slowest events
143 encountered by adaptive timeouts code.
144 Default: 600
145
43What: /sys/fs/lustre/llite/<fsname>-<uuid>/blocksize 146What: /sys/fs/lustre/llite/<fsname>-<uuid>/blocksize
44Date: May 2015 147Date: May 2015
45Contact: "Oleg Drokin" <oleg.drokin@intel.com> 148Contact: "Oleg Drokin" <oleg.drokin@intel.com>
diff --git a/drivers/staging/most/Documentation/ABI/sysfs-class-most.txt b/drivers/staging/most/Documentation/ABI/sysfs-class-most.txt
new file mode 100644
index 000000000000..380c137089d0
--- /dev/null
+++ b/drivers/staging/most/Documentation/ABI/sysfs-class-most.txt
@@ -0,0 +1,181 @@
1What: /sys/class/most/mostcore/aims
2Date: June 2015
3KernelVersion: 4.3
4Contact: Christian Gromm <christian.gromm@microchip.com>
5Description:
6 List of AIMs that have been loaded.
7Users:
8
9What: /sys/class/most/mostcore/aims/<aim>/add_link
10Date: June 2015
11KernelVersion: 4.3
12Contact: Christian Gromm <christian.gromm@microchip.com>
13Description:
14 This is used to establish a connection of a channel and the
15 current AIM.
16Users:
17
18What: /sys/class/most/mostcore/aims/<aim>/remove_link
19Date: June 2015
20KernelVersion: 4.3
21Contact: Christian Gromm <christian.gromm@microchip.com>
22Description:
23 This is used to remove a connected channel from the
24 current AIM.
25Users:
26
27What: /sys/class/most/mostcore/devices
28Date: June 2015
29KernelVersion: 4.3
30Contact: Christian Gromm <christian.gromm@microchip.com>
31Description:
32 List of attached MOST interfaces.
33Users:
34
35What: /sys/class/most/mostcore/devices/<mdev>/description
36Date: June 2015
37KernelVersion: 4.3
38Contact: Christian Gromm <christian.gromm@microchip.com>
39Description:
40 Provides information about the interface type and the physical
41 location of the device. Hardware attached via USB, for instance,
42 might return <usb_device 1-1.1:1.0>
43Users:
44
45What: /sys/class/most/mostcore/devices/<mdev>/interface
46Date: June 2015
47KernelVersion: 4.3
48Contact: Christian Gromm <christian.gromm@microchip.com>
49Description:
50 Indicates the type of peripherial interface the current device
51 uses.
52Users:
53
54What: /sys/class/most/mostcore/devices/<mdev>/<channel>/
55Date: June 2015
56KernelVersion: 4.3
57Contact: Christian Gromm <christian.gromm@microchip.com>
58Description:
59 For every channel of the device a directory is created, whose
60 name is dictated by the HDM. This enables an application to
61 collect information about the channel's capabilities and
62 configure it.
63Users:
64
65What: /sys/class/most/mostcore/devices/<mdev>/<channel>/available_datatypes
66Date: June 2015
67KernelVersion: 4.3
68Contact: Christian Gromm <christian.gromm@microchip.com>
69Description:
70 Indicates the data types the current channel can transport.
71Users:
72
73What: /sys/class/most/mostcore/devices/<mdev>/<channel>/available_directions
74Date: June 2015
75KernelVersion: 4.3
76Contact: Christian Gromm <christian.gromm@microchip.com>
77Description:
78 Indicates the directions the current channel is capable of.
79Users:
80
81What: /sys/class/most/mostcore/devices/<mdev>/<channel>/number_of_packet_buffers
82Date: June 2015
83KernelVersion: 4.3
84Contact: Christian Gromm <christian.gromm@microchip.com>
85Description:
86 Indicates the number of packet buffers the current channel can
87 handle.
88Users:
89
90What: /sys/class/most/mostcore/devices/<mdev>/<channel>/number_of_stream_buffers
91Date: June 2015
92KernelVersion: 4.3
93Contact: Christian Gromm <christian.gromm@microchip.com>
94Description:
95 Indicates the number of streaming buffers the current channel can
96 handle.
97Users:
98
99What: /sys/class/most/mostcore/devices/<mdev>/<channel>/size_of_packet_buffer
100Date: June 2015
101KernelVersion: 4.3
102Contact: Christian Gromm <christian.gromm@microchip.com>
103Description:
104 Indicates the size of a packet buffer the current channel can
105 handle.
106Users:
107
108What: /sys/class/most/mostcore/devices/<mdev>/<channel>/size_of_stream_buffer
109Date: June 2015
110KernelVersion: 4.3
111Contact: Christian Gromm <christian.gromm@microchip.com>
112Description:
113 Indicates the size of a streaming buffer the current channel can
114 handle.
115Users:
116
117What: /sys/class/most/mostcore/devices/<mdev>/<channel>/set_number_of_buffers
118Date: June 2015
119KernelVersion: 4.3
120Contact: Christian Gromm <christian.gromm@microchip.com>
121Description:
122 This is to configure the number of buffers of the current channel.
123Users:
124
125What: /sys/class/most/mostcore/devices/<mdev>/<channel>/set_buffer_size
126Date: June 2015
127KernelVersion: 4.3
128Contact: Christian Gromm <christian.gromm@microchip.com>
129Description:
130 This is to configure the size of a buffer of the current channel.
131Users:
132
133What: /sys/class/most/mostcore/devices/<mdev>/<channel>/set_direction
134Date: June 2015
135KernelVersion: 4.3
136Contact: Christian Gromm <christian.gromm@microchip.com>
137Description:
138 This is to configure the direction of the current channel.
139 The following strings will be accepted:
140 'dir_tx',
141 'dir_rx'
142Users:
143
144What: /sys/class/most/mostcore/devices/<mdev>/<channel>/set_datatype
145Date: June 2015
146KernelVersion: 4.3
147Contact: Christian Gromm <christian.gromm@microchip.com>
148Description:
149 This is to configure the data type of the current channel.
150 The following strings will be accepted:
151 'control',
152 'async',
153 'sync',
154 'isoc_avp'
155Users:
156
157What: /sys/class/most/mostcore/devices/<mdev>/<channel>/set_subbuffer_size
158Date: June 2015
159KernelVersion: 4.3
160Contact: Christian Gromm <christian.gromm@microchip.com>
161Description:
162 This is to configure the subbuffer size of the current channel.
163Users:
164
165What: /sys/class/most/mostcore/devices/<mdev>/<channel>/set_packets_per_xact
166Date: June 2015
167KernelVersion: 4.3
168Contact: Christian Gromm <christian.gromm@microchip.com>
169Description:
170 This is to configure the number of packets per transaction of
171 the current channel. This is only needed network interface
172 controller is attached via USB.
173Users:
174
175What: /sys/class/most/mostcore/devices/<mdev>/<channel>/channel_starving
176Date: June 2015
177KernelVersion: 4.3
178Contact: Christian Gromm <christian.gromm@microchip.com>
179Description:
180 Indicates whether current channel ran out of buffers.
181Users:
diff --git a/drivers/staging/most/Documentation/driver_usage.txt b/drivers/staging/most/Documentation/driver_usage.txt
new file mode 100644
index 000000000000..a4dc0c348fbc
--- /dev/null
+++ b/drivers/staging/most/Documentation/driver_usage.txt
@@ -0,0 +1,180 @@
1
2 Section 1 Overview
3
4The Media Oriented Systems Transport (MOST) driver gives Linux applications
5access a MOST network: The Automotive Information Backbone and the de-facto
6standard for high-bandwidth automotive multimedia networking.
7
8MOST defines the protocol, hardware and software layers necessary to allow
9for the efficient and low-cost transport of control, real-time and packet
10data using a single medium (physical layer). Media currently in use are
11fiber optics, unshielded twisted pair cables (UTP) and coax cables. MOST
12also supports various speed grades up to 150 Mbps.
13For more information on MOST, visit the MOST Cooperation website:
14www.mostcooperation.com.
15
16Cars continue to evolve into sophisticated consumer electronics platforms,
17increasing the demand for reliable and simple solutions to support audio,
18video and data communications. MOST can be used to connect multiple
19consumer devices via optical or electrical physical layers directly to one
20another or in a network configuration. As a synchronous network, MOST
21provides excellent Quality of Service and seamless connectivity for
22audio/video streaming. Therefore, the driver perfectly fits to the mission
23of Automotive Grade Linux to create open source software solutions for
24automotive applications.
25
26The driver consists basically of three layers. The hardware layer, the
27core layer and the application layer. The core layer consists of the core
28module only. This module handles the communication flow through all three
29layers, the configuration of the driver, the configuration interface
30representation in sysfs, and the buffer management.
31For each of the other two layers a selection of modules is provided. These
32modules can arbitrarily be combined to meet the needs of the desired
33system architecture. A module of the hardware layer is referred to as an
34HDM (hardware dependent module). Each module of this layer handles exactly
35one of the peripheral interfaces of a network interface controller (e.g.
36USB, MediaLB, I2C). A module of the application layer is referred to as an
37AIM (application interfacing module). The modules of this layer give access
38to MOST via one the following ways: character devices, ALSA, Networking or
39V4L2.
40
41To physically access MOST, an Intelligent Network Interface Controller
42(INIC) is needed. For more information on available controllers visit:
43www.microchip.com
44
45
46
47 Section 1.1 Hardware Layer
48
49The hardware layer contains so called hardware dependent modules (HDM). For each
50peripheral interface the hardware supports the driver has a suitable module
51that handles the interface.
52
53The HDMs encapsulate the peripheral interface specific knowledge of the driver
54and provides an easy way of extending the number of supported interfaces.
55Currently the following HDMs are available:
56
57 1) MediaLB (DIM2)
58 Host wants to communicate with hardware via MediaLB.
59
60 2) I2C
61 Host wants to communicate with the hardware via I2C.
62
63 3) USB
64 Host wants to communicate with the hardware via USB.
65
66
67 Section 1.2 Core Layer
68
69The core layer contains the mostcore module only, which processes the driver
70configuration via sysfs, buffer management and data forwarding.
71
72
73
74 Section 1.2 Application Layer
75
76The application layer contains so called application interfacing modules (AIM).
77Depending on how the driver should interface to the application, one or more
78suitable modules can be selected.
79
80The AIMs encapsulate the application interface specific knowledge of the driver
81and provides access to user space or other kernel subsystems.
82Currently the following AIMs are available
83
84 1) Character Device
85 Applications can access the driver by means of character devices.
86
87 2) Networking
88 Standard networking applications (e.g. iperf) can by used to access
89 the driver via the networking subsystem.
90
91 3) Video4Linux (v4l2)
92 Standard video applications (e.g. VLC) can by used to access the
93 driver via the V4L subsystem.
94
95 4) Advanced Linux Sound Architecture (ALSA)
96 Standard sound applications (e.g. aplay, arecord, audacity) can by
97 used to access the driver via the ALSA subsystem.
98
99
100
101 Section 2 Configuration
102
103See ABI/sysfs-class-most.txt
104
105
106
107 Section 3 USB Padding
108
109When transceiving synchronous or isochronous data, the number of packets per USB
110transaction and the sub-buffer size need to be configured. These values
111are needed for the driver to process buffer padding, as expected by hardware,
112which is for performance optimization purposes of the USB transmission.
113
114When transmitting synchronous data the allocated channel width needs to be
115written to 'set_subbuffer_size'. Additionally, the number of MOST frames that
116should travel to the host within one USB transaction need to be written to
117'packets_per_xact'.
118
119Internally the synchronous threshold is calculated as follows:
120
121 frame_size = set_subbuffer_size * packets_per_xact
122
123In case 'packets_per_xact' is set to 0xFF the maximum number of packets,
124allocated within one MOST frame, is calculated that fit into _one_ 512 byte
125USB full packet.
126
127 frame_size = floor(MTU_USB / bandwidth_sync) * bandwidth_sync
128
129This frame_size is the number of synchronous data within an USB transaction,
130which renders MTU_USB - frame_size bytes for padding.
131
132When transmitting isochronous AVP data the desired packet size needs to be
133written to 'set_subbuffer_size' and hardware will always expect two isochronous
134packets within one USB transaction. This renders
135
136 MTU_USB - (2 * set_subbuffer_size)
137
138bytes for padding.
139
140Note that at least 2 times set_subbuffer_size bytes for isochronous data or
141set_subbuffer_size times packts_per_xact bytes for synchronous data need to be
142put in the transmission buffer and passed to the driver.
143
144Since HDMs are allowed to change a chosen configuration to best fit its
145constraints, it is recommended to always double check the configuration and read
146back the previously written files.
147
148
149
150 Section 4 Routing Channels
151
152To connect a channel that has been configured as outlined above to an AIM and
153make it accessible to user space applications, the attribute file 'add_link' is
154used. To actually bind a channel to the AIM a string needs to be written to the
155file that complies with the following syntax:
156
157 "most_device:channel_name:link_name[.param]"
158
159The example above links the channel "channel_name" of the device "most_device"
160to the AIM. In case the AIM interfaces the VFS this would also create a device
161node "link_name" in the /dev directory. The parameter "param" is an AIM dependent
162string, which can be omitted in case the used AIM does not make any use of it.
163
164Cdev AIM example:
165 $ echo "mdev0:ep_81:my_rx_channel" >add_link
166 $ echo "mdev0:ep_81" >add_link
167
168
169Sound/ALSA AIM example:
170
171The sound/ALSA AIM needs an additional parameter to determine the audio resolution
172that is going to be used. The following strings can be used:
173
174 - "1x8" (Mono)
175 - "2x16" (16-bit stereo)
176 - "2x24" (24-bit stereo)
177 - "2x32" (32-bit stereo)
178
179 $ echo "mdev0:ep_81:audio_rx.2x16" >add_link
180 $ echo "mdev0:ep_81" >add_link
diff --git a/drivers/staging/most/Kconfig b/drivers/staging/most/Kconfig
new file mode 100644
index 000000000000..d50de03de7b9
--- /dev/null
+++ b/drivers/staging/most/Kconfig
@@ -0,0 +1,30 @@
1menuconfig MOST
2 tristate "MOST driver"
3 select MOSTCORE
4 default n
5 ---help---
6 This option allows you to enable support for MOST Network transceivers.
7
8 If in doubt, say N here.
9
10
11
12if MOST
13
14source "drivers/staging/most/mostcore/Kconfig"
15
16source "drivers/staging/most/aim-cdev/Kconfig"
17
18source "drivers/staging/most/aim-network/Kconfig"
19
20source "drivers/staging/most/aim-sound/Kconfig"
21
22source "drivers/staging/most/aim-v4l2/Kconfig"
23
24source "drivers/staging/most/hdm-dim2/Kconfig"
25
26source "drivers/staging/most/hdm-i2c/Kconfig"
27
28source "drivers/staging/most/hdm-usb/Kconfig"
29
30endif
diff --git a/drivers/staging/most/Makefile b/drivers/staging/most/Makefile
new file mode 100644
index 000000000000..9ee981c7786b
--- /dev/null
+++ b/drivers/staging/most/Makefile
@@ -0,0 +1,8 @@
1obj-$(CONFIG_MOSTCORE) += mostcore/
2obj-$(CONFIG_AIM_CDEV) += aim-cdev/
3obj-$(CONFIG_AIM_NETWORK) += aim-network/
4obj-$(CONFIG_AIM_SOUND) += aim-sound/
5obj-$(CONFIG_AIM_V4L2) += aim-v4l2/
6obj-$(CONFIG_HDM_DIM2) += hdm-dim2/
7obj-$(CONFIG_HDM_I2C) += hdm-i2c/
8obj-$(CONFIG_HDM_USB) += hdm-usb/
diff --git a/drivers/staging/most/TODO b/drivers/staging/most/TODO
new file mode 100644
index 000000000000..4fa11a9d2cf7
--- /dev/null
+++ b/drivers/staging/most/TODO
@@ -0,0 +1,8 @@
1* Get through code review with Greg Kroah-Hartman
2
3Contact:
4To:
5Christian Gromm <christian.gromm@microchip.com>
6Cc:
7Michael Fabry <Michael.Fabry@microchip.com>
8Christian Gromm <chris@engineersdelight.de>
diff --git a/drivers/staging/most/aim-cdev/Kconfig b/drivers/staging/most/aim-cdev/Kconfig
new file mode 100644
index 000000000000..3c59f1bac127
--- /dev/null
+++ b/drivers/staging/most/aim-cdev/Kconfig
@@ -0,0 +1,12 @@
1#
2# MOST Cdev configuration
3#
4
5config AIM_CDEV
6 tristate "Cdev AIM"
7
8 ---help---
9 Say Y here if you want to commumicate via character devices.
10
11 To compile this driver as a module, choose M here: the
12 module will be called aim_cdev. \ No newline at end of file
diff --git a/drivers/staging/most/aim-cdev/Makefile b/drivers/staging/most/aim-cdev/Makefile
new file mode 100644
index 000000000000..0bcc6c637b75
--- /dev/null
+++ b/drivers/staging/most/aim-cdev/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_AIM_CDEV) += aim_cdev.o
2
3aim_cdev-objs := cdev.o
4ccflags-y += -Idrivers/staging/most/mostcore/ \ No newline at end of file
diff --git a/drivers/staging/most/aim-cdev/cdev.c b/drivers/staging/most/aim-cdev/cdev.c
new file mode 100644
index 000000000000..0a13d8d0fa39
--- /dev/null
+++ b/drivers/staging/most/aim-cdev/cdev.c
@@ -0,0 +1,528 @@
1/*
2 * cdev.c - Application interfacing module for character devices
3 *
4 * Copyright (C) 2013-2015 Microchip Technology Germany II GmbH & Co. KG
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * This file is licensed under GPLv2.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15#include <linux/module.h>
16#include <linux/sched.h>
17#include <linux/fs.h>
18#include <linux/slab.h>
19#include <linux/device.h>
20#include <linux/cdev.h>
21#include <linux/kfifo.h>
22#include <linux/uaccess.h>
23#include <linux/idr.h>
24#include "mostcore.h"
25
26static dev_t aim_devno;
27static struct class *aim_class;
28static struct ida minor_id;
29static unsigned int major;
30
31struct aim_channel {
32 wait_queue_head_t wq;
33 struct cdev cdev;
34 struct device *dev;
35 struct mutex io_mutex;
36 struct most_interface *iface;
37 struct most_channel_config *cfg;
38 unsigned int channel_id;
39 dev_t devno;
40 bool keep_mbo;
41 unsigned int mbo_offs;
42 struct mbo *stacked_mbo;
43 DECLARE_KFIFO_PTR(fifo, typeof(struct mbo *));
44 atomic_t access_ref;
45 struct list_head list;
46};
47#define to_channel(d) container_of(d, struct aim_channel, cdev)
48static struct list_head channel_list;
49static spinlock_t ch_list_lock;
50
51
52static struct aim_channel *get_channel(struct most_interface *iface, int id)
53{
54 struct aim_channel *channel, *tmp;
55 unsigned long flags;
56 int found_channel = 0;
57
58 spin_lock_irqsave(&ch_list_lock, flags);
59 list_for_each_entry_safe(channel, tmp, &channel_list, list) {
60 if ((channel->iface == iface) && (channel->channel_id == id)) {
61 found_channel = 1;
62 break;
63 }
64 }
65 spin_unlock_irqrestore(&ch_list_lock, flags);
66 if (!found_channel)
67 return NULL;
68 return channel;
69}
70
71/**
72 * aim_open - implements the syscall to open the device
73 * @inode: inode pointer
74 * @filp: file pointer
75 *
76 * This stores the channel pointer in the private data field of
77 * the file structure and activates the channel within the core.
78 */
79static int aim_open(struct inode *inode, struct file *filp)
80{
81 struct aim_channel *channel;
82 int ret;
83
84 channel = to_channel(inode->i_cdev);
85 filp->private_data = channel;
86
87 if (((channel->cfg->direction == MOST_CH_RX) &&
88 ((filp->f_flags & O_ACCMODE) != O_RDONLY))
89 || ((channel->cfg->direction == MOST_CH_TX) &&
90 ((filp->f_flags & O_ACCMODE) != O_WRONLY))) {
91 pr_info("WARN: Access flags mismatch\n");
92 return -EACCES;
93 }
94 if (!atomic_inc_and_test(&channel->access_ref)) {
95 pr_info("WARN: Device is busy\n");
96 atomic_dec(&channel->access_ref);
97 return -EBUSY;
98 }
99
100 ret = most_start_channel(channel->iface, channel->channel_id);
101 if (ret)
102 atomic_dec(&channel->access_ref);
103 return ret;
104}
105
106/**
107 * aim_close - implements the syscall to close the device
108 * @inode: inode pointer
109 * @filp: file pointer
110 *
111 * This stops the channel within the core.
112 */
113static int aim_close(struct inode *inode, struct file *filp)
114{
115 int ret;
116 struct mbo *mbo;
117 struct aim_channel *channel = to_channel(inode->i_cdev);
118
119 mutex_lock(&channel->io_mutex);
120 if (!channel->dev) {
121 mutex_unlock(&channel->io_mutex);
122 atomic_dec(&channel->access_ref);
123 device_destroy(aim_class, channel->devno);
124 cdev_del(&channel->cdev);
125 kfifo_free(&channel->fifo);
126 list_del(&channel->list);
127 ida_simple_remove(&minor_id, MINOR(channel->devno));
128 wake_up_interruptible(&channel->wq);
129 kfree(channel);
130 return 0;
131 }
132 mutex_unlock(&channel->io_mutex);
133
134 while (0 != kfifo_out((struct kfifo *)&channel->fifo, &mbo, 1))
135 most_put_mbo(mbo);
136 if (channel->keep_mbo == true)
137 most_put_mbo(channel->stacked_mbo);
138 ret = most_stop_channel(channel->iface, channel->channel_id);
139 atomic_dec(&channel->access_ref);
140 wake_up_interruptible(&channel->wq);
141 return ret;
142}
143
144/**
145 * aim_write - implements the syscall to write to the device
146 * @filp: file pointer
147 * @buf: pointer to user buffer
148 * @count: number of bytes to write
149 * @offset: offset from where to start writing
150 */
151static ssize_t aim_write(struct file *filp, const char __user *buf,
152 size_t count, loff_t *offset)
153{
154 int ret, err;
155 size_t actual_len = 0;
156 size_t max_len = 0;
157 ssize_t retval;
158 struct mbo *mbo;
159 struct aim_channel *channel = filp->private_data;
160
161 mutex_lock(&channel->io_mutex);
162 if (unlikely(!channel->dev)) {
163 mutex_unlock(&channel->io_mutex);
164 return -EPIPE;
165 }
166 mutex_unlock(&channel->io_mutex);
167
168 mbo = most_get_mbo(channel->iface, channel->channel_id);
169
170 if (!mbo && channel->dev) {
171 if ((filp->f_flags & O_NONBLOCK))
172 return -EAGAIN;
173 if (wait_event_interruptible(
174 channel->wq,
175 (mbo = most_get_mbo(channel->iface,
176 channel->channel_id)) ||
177 (channel->dev == NULL)))
178 return -ERESTARTSYS;
179 }
180
181 mutex_lock(&channel->io_mutex);
182 if (unlikely(!channel->dev)) {
183 mutex_unlock(&channel->io_mutex);
184 err = -EPIPE;
185 goto error;
186 }
187 mutex_unlock(&channel->io_mutex);
188
189 max_len = channel->cfg->buffer_size;
190 actual_len = min(count, max_len);
191 mbo->buffer_length = actual_len;
192
193 retval = copy_from_user(mbo->virt_address, buf, mbo->buffer_length);
194 if (retval) {
195 err = -EIO;
196 goto error;
197 }
198
199 ret = most_submit_mbo(mbo);
200 if (ret) {
201 pr_info("submitting MBO to core failed\n");
202 err = ret;
203 goto error;
204 }
205 return actual_len - retval;
206error:
207 if (mbo)
208 most_put_mbo(mbo);
209 return err;
210}
211
212/**
213 * aim_read - implements the syscall to read from the device
214 * @filp: file pointer
215 * @buf: pointer to user buffer
216 * @count: number of bytes to read
217 * @offset: offset from where to start reading
218 */
219static ssize_t
220aim_read(struct file *filp, char __user *buf, size_t count, loff_t *offset)
221{
222 ssize_t retval;
223 size_t not_copied, proc_len;
224 struct mbo *mbo;
225 struct aim_channel *channel = filp->private_data;
226
227 if (channel->keep_mbo == true) {
228 mbo = channel->stacked_mbo;
229 channel->keep_mbo = false;
230 goto start_copy;
231 }
232 while ((0 == kfifo_out(&channel->fifo, &mbo, 1))
233 && (channel->dev != NULL)) {
234 if (filp->f_flags & O_NONBLOCK)
235 return -EAGAIN;
236 if (wait_event_interruptible(channel->wq,
237 (!kfifo_is_empty(&channel->fifo) ||
238 (channel->dev == NULL))))
239 return -ERESTARTSYS;
240 }
241
242start_copy:
243 /* make sure we don't submit to gone devices */
244 mutex_lock(&channel->io_mutex);
245 if (unlikely(!channel->dev)) {
246 mutex_unlock(&channel->io_mutex);
247 return -EIO;
248 }
249
250 if (count < mbo->processed_length)
251 channel->keep_mbo = true;
252
253 proc_len = min((int)count,
254 (int)(mbo->processed_length - channel->mbo_offs));
255
256 not_copied = copy_to_user(buf,
257 mbo->virt_address + channel->mbo_offs,
258 proc_len);
259
260 retval = not_copied ? proc_len - not_copied : proc_len;
261
262 if (channel->keep_mbo == true) {
263 channel->mbo_offs = retval;
264 channel->stacked_mbo = mbo;
265 } else {
266 most_put_mbo(mbo);
267 channel->mbo_offs = 0;
268 }
269 mutex_unlock(&channel->io_mutex);
270 return retval;
271}
272
273/**
274 * Initialization of struct file_operations
275 */
276static const struct file_operations channel_fops = {
277 .owner = THIS_MODULE,
278 .read = aim_read,
279 .write = aim_write,
280 .open = aim_open,
281 .release = aim_close,
282};
283
284/**
285 * aim_disconnect_channel - disconnect a channel
286 * @iface: pointer to interface instance
287 * @channel_id: channel index
288 *
289 * This frees allocated memory and removes the cdev that represents this
290 * channel in user space.
291 */
292static int aim_disconnect_channel(struct most_interface *iface, int channel_id)
293{
294 struct aim_channel *channel;
295 unsigned long flags;
296
297 if (!iface) {
298 pr_info("Bad interface pointer\n");
299 return -EINVAL;
300 }
301
302 channel = get_channel(iface, channel_id);
303 if (channel == NULL)
304 return -ENXIO;
305
306 mutex_lock(&channel->io_mutex);
307 channel->dev = NULL;
308 mutex_unlock(&channel->io_mutex);
309
310 if (atomic_read(&channel->access_ref)) {
311 device_destroy(aim_class, channel->devno);
312 cdev_del(&channel->cdev);
313 kfifo_free(&channel->fifo);
314 ida_simple_remove(&minor_id, MINOR(channel->devno));
315 spin_lock_irqsave(&ch_list_lock, flags);
316 list_del(&channel->list);
317 spin_unlock_irqrestore(&ch_list_lock, flags);
318 kfree(channel);
319 } else {
320 wake_up_interruptible(&channel->wq);
321 }
322 return 0;
323}
324
325/**
326 * aim_rx_completion - completion handler for rx channels
327 * @mbo: pointer to buffer object that has completed
328 *
329 * This searches for the channel linked to this MBO and stores it in the local
330 * fifo buffer.
331 */
332static int aim_rx_completion(struct mbo *mbo)
333{
334 struct aim_channel *channel;
335
336 if (!mbo)
337 return -EINVAL;
338
339 channel = get_channel(mbo->ifp, mbo->hdm_channel_id);
340 if (channel == NULL)
341 return -ENXIO;
342
343 kfifo_in(&channel->fifo, &mbo, 1);
344#ifdef DEBUG_MESG
345 if (kfifo_is_full(&channel->fifo))
346 pr_info("WARN: Fifo is full\n");
347#endif
348 wake_up_interruptible(&channel->wq);
349 return 0;
350}
351
352/**
353 * aim_tx_completion - completion handler for tx channels
354 * @iface: pointer to interface instance
355 * @channel_id: channel index/ID
356 *
357 * This wakes sleeping processes in the wait-queue.
358 */
359static int aim_tx_completion(struct most_interface *iface, int channel_id)
360{
361 struct aim_channel *channel;
362
363 if (!iface) {
364 pr_info("Bad interface pointer\n");
365 return -EINVAL;
366 }
367 if ((channel_id < 0) || (channel_id >= iface->num_channels)) {
368 pr_info("Channel ID out of range\n");
369 return -EINVAL;
370 }
371
372 channel = get_channel(iface, channel_id);
373 if (channel == NULL)
374 return -ENXIO;
375 wake_up_interruptible(&channel->wq);
376 return 0;
377}
378
379static struct most_aim cdev_aim;
380
381/**
382 * aim_probe - probe function of the driver module
383 * @iface: pointer to interface instance
384 * @channel_id: channel index/ID
385 * @cfg: pointer to actual channel configuration
386 * @parent: pointer to kobject (needed for sysfs hook-up)
387 * @name: name of the device to be created
388 *
389 * This allocates achannel object and creates the device node in /dev
390 *
391 * Returns 0 on success or error code otherwise.
392 */
393static int aim_probe(struct most_interface *iface, int channel_id,
394 struct most_channel_config *cfg,
395 struct kobject *parent, char *name)
396{
397 struct aim_channel *channel;
398 unsigned long cl_flags;
399 int retval;
400 int current_minor;
401
402 if ((!iface) || (!cfg) || (!parent) || (!name)) {
403 pr_info("Probing AIM with bad arguments");
404 return -EINVAL;
405 }
406 channel = get_channel(iface, channel_id);
407 if (channel)
408 return -EEXIST;
409
410 current_minor = ida_simple_get(&minor_id, 0, 0, GFP_KERNEL);
411 if (current_minor < 0)
412 return current_minor;
413
414 channel = kzalloc(sizeof(*channel), GFP_KERNEL);
415 if (!channel) {
416 pr_info("failed to alloc channel object\n");
417 retval = -ENOMEM;
418 goto error_alloc_channel;
419 }
420
421 channel->devno = MKDEV(major, current_minor);
422 cdev_init(&channel->cdev, &channel_fops);
423 channel->cdev.owner = THIS_MODULE;
424 cdev_add(&channel->cdev, channel->devno, 1);
425 channel->iface = iface;
426 channel->cfg = cfg;
427 channel->channel_id = channel_id;
428 channel->mbo_offs = 0;
429 atomic_set(&channel->access_ref, -1);
430 INIT_KFIFO(channel->fifo);
431 retval = kfifo_alloc(&channel->fifo, cfg->num_buffers, GFP_KERNEL);
432 if (retval) {
433 pr_info("failed to alloc channel kfifo");
434 goto error_alloc_kfifo;
435 }
436 init_waitqueue_head(&channel->wq);
437 mutex_init(&channel->io_mutex);
438 spin_lock_irqsave(&ch_list_lock, cl_flags);
439 list_add_tail(&channel->list, &channel_list);
440 spin_unlock_irqrestore(&ch_list_lock, cl_flags);
441 channel->dev = device_create(aim_class,
442 NULL,
443 channel->devno,
444 NULL,
445 "%s", name);
446
447 retval = IS_ERR(channel->dev);
448 if (retval) {
449 pr_info("failed to create new device node %s\n", name);
450 goto error_create_device;
451 }
452 kobject_uevent(&channel->dev->kobj, KOBJ_ADD);
453 return 0;
454
455error_create_device:
456 kfifo_free(&channel->fifo);
457 list_del(&channel->list);
458error_alloc_kfifo:
459 cdev_del(&channel->cdev);
460 kfree(channel);
461error_alloc_channel:
462 ida_simple_remove(&minor_id, current_minor);
463 return retval;
464}
465
466static struct most_aim cdev_aim = {
467 .name = "cdev",
468 .probe_channel = aim_probe,
469 .disconnect_channel = aim_disconnect_channel,
470 .rx_completion = aim_rx_completion,
471 .tx_completion = aim_tx_completion,
472};
473
474static int __init mod_init(void)
475{
476 pr_info("init()\n");
477
478 INIT_LIST_HEAD(&channel_list);
479 spin_lock_init(&ch_list_lock);
480 ida_init(&minor_id);
481
482 if (alloc_chrdev_region(&aim_devno, 0, 50, "cdev") < 0)
483 return -EIO;
484 major = MAJOR(aim_devno);
485
486 aim_class = class_create(THIS_MODULE, "most_cdev_aim");
487 if (IS_ERR(aim_class)) {
488 pr_err("no udev support\n");
489 goto free_cdev;
490 }
491
492 if (most_register_aim(&cdev_aim))
493 goto dest_class;
494 return 0;
495
496dest_class:
497 class_destroy(aim_class);
498free_cdev:
499 unregister_chrdev_region(aim_devno, 1);
500 return -EIO;
501}
502
503static void __exit mod_exit(void)
504{
505 struct aim_channel *channel, *tmp;
506
507 pr_info("exit module\n");
508
509 most_deregister_aim(&cdev_aim);
510
511 list_for_each_entry_safe(channel, tmp, &channel_list, list) {
512 device_destroy(aim_class, channel->devno);
513 cdev_del(&channel->cdev);
514 kfifo_free(&channel->fifo);
515 list_del(&channel->list);
516 ida_simple_remove(&minor_id, MINOR(channel->devno));
517 kfree(channel);
518 }
519 class_destroy(aim_class);
520 unregister_chrdev_region(aim_devno, 1);
521 ida_destroy(&minor_id);
522}
523
524module_init(mod_init);
525module_exit(mod_exit);
526MODULE_AUTHOR("Christian Gromm <christian.gromm@microchip.com>");
527MODULE_LICENSE("GPL");
528MODULE_DESCRIPTION("character device AIM for mostcore");
diff --git a/drivers/staging/most/aim-network/Kconfig b/drivers/staging/most/aim-network/Kconfig
new file mode 100644
index 000000000000..4c66b24cf73c
--- /dev/null
+++ b/drivers/staging/most/aim-network/Kconfig
@@ -0,0 +1,13 @@
1#
2# MOST Networking configuration
3#
4
5config AIM_NETWORK
6 tristate "Networking AIM"
7 depends on NET
8
9 ---help---
10 Say Y here if you want to commumicate via a networking device.
11
12 To compile this driver as a module, choose M here: the
13 module will be called aim_network.
diff --git a/drivers/staging/most/aim-network/Makefile b/drivers/staging/most/aim-network/Makefile
new file mode 100644
index 000000000000..840c1dd94873
--- /dev/null
+++ b/drivers/staging/most/aim-network/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_AIM_NETWORK) += aim_network.o
2
3aim_network-objs := networking.o
4ccflags-y += -Idrivers/staging/most/mostcore/
diff --git a/drivers/staging/most/aim-network/networking.c b/drivers/staging/most/aim-network/networking.c
new file mode 100644
index 000000000000..c8ab2399faad
--- /dev/null
+++ b/drivers/staging/most/aim-network/networking.c
@@ -0,0 +1,567 @@
1/*
2 * Networking AIM - Networking Application Interface Module for MostCore
3 *
4 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * This file is licensed under GPLv2.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
16#include <linux/module.h>
17#include <linux/netdevice.h>
18#include <linux/etherdevice.h>
19#include <linux/slab.h>
20#include <linux/init.h>
21#include <linux/list.h>
22#include <linux/wait.h>
23#include <linux/kobject.h>
24#include "mostcore.h"
25#include "networking.h"
26
27
28#define MEP_HDR_LEN 8
29#define MDP_HDR_LEN 16
30#define MAMAC_DATA_LEN (1024 - MDP_HDR_LEN)
31
32#define PMHL 5
33
34#define PMS_TELID_UNSEGM_MAMAC 0x0A
35#define PMS_FIFONO_MDP 0x01
36#define PMS_FIFONO_MEP 0x04
37#define PMS_MSGTYPE_DATA 0x04
38#define PMS_DEF_PRIO 0
39#define MEP_DEF_RETRY 15
40
41#define PMS_FIFONO_MASK 0x07
42#define PMS_FIFONO_SHIFT 3
43#define PMS_RETRY_SHIFT 4
44#define PMS_TELID_MASK 0x0F
45#define PMS_TELID_SHIFT 4
46
47#define HB(value) ((u8)((u16)(value) >> 8))
48#define LB(value) ((u8)(value))
49
50
51
52#define EXTRACT_BIT_SET(bitset_name, value) \
53 (((value) >> bitset_name##_SHIFT) & bitset_name##_MASK)
54
55#define PMS_IS_MEP(buf, len) \
56 ((len) > MEP_HDR_LEN && \
57 EXTRACT_BIT_SET(PMS_FIFONO, (buf)[3]) == PMS_FIFONO_MEP)
58
59#define PMS_IS_MAMAC(buf, len) \
60 ((len) > MDP_HDR_LEN && \
61 EXTRACT_BIT_SET(PMS_FIFONO, (buf)[3]) == PMS_FIFONO_MDP && \
62 EXTRACT_BIT_SET(PMS_TELID, (buf)[14]) == PMS_TELID_UNSEGM_MAMAC)
63
64struct net_dev_channel {
65 bool linked;
66 int ch_id;
67};
68
69struct net_dev_context {
70 struct most_interface *iface;
71 bool channels_opened;
72 bool is_mamac;
73 unsigned char link_stat;
74 struct net_device *dev;
75 struct net_dev_channel rx;
76 struct net_dev_channel tx;
77 struct list_head list;
78};
79
80static struct list_head net_devices = LIST_HEAD_INIT(net_devices);
81static struct spinlock list_lock;
82static struct most_aim aim;
83
84
85static int skb_to_mamac(const struct sk_buff *skb, struct mbo *mbo)
86{
87 u8 *buff = mbo->virt_address;
88 const u8 broadcast[] = { 0x03, 0xFF };
89 const u8 *dest_addr = skb->data + 4;
90 const u8 *eth_type = skb->data + 12;
91 unsigned int payload_len = skb->len - ETH_HLEN;
92 unsigned int mdp_len = payload_len + MDP_HDR_LEN;
93
94 if (mbo->buffer_length < mdp_len) {
95 pr_err("drop: too small buffer! (%d for %d)\n",
96 mbo->buffer_length, mdp_len);
97 return -EINVAL;
98 }
99
100 if (skb->len < ETH_HLEN) {
101 pr_err("drop: too small packet! (%d)\n", skb->len);
102 return -EINVAL;
103 }
104
105 if (dest_addr[0] == 0xFF && dest_addr[1] == 0xFF)
106 dest_addr = broadcast;
107
108 *buff++ = HB(mdp_len - 2);
109 *buff++ = LB(mdp_len - 2);
110
111 *buff++ = PMHL;
112 *buff++ = (PMS_FIFONO_MDP << PMS_FIFONO_SHIFT) | PMS_MSGTYPE_DATA;
113 *buff++ = PMS_DEF_PRIO;
114 *buff++ = dest_addr[0];
115 *buff++ = dest_addr[1];
116 *buff++ = 0x00;
117
118 *buff++ = HB(payload_len + 6);
119 *buff++ = LB(payload_len + 6);
120
121 /* end of FPH here */
122
123 *buff++ = eth_type[0];
124 *buff++ = eth_type[1];
125 *buff++ = 0;
126 *buff++ = 0;
127
128 *buff++ = PMS_TELID_UNSEGM_MAMAC << 4 | HB(payload_len);
129 *buff++ = LB(payload_len);
130
131 memcpy(buff, skb->data + ETH_HLEN, payload_len);
132 mbo->buffer_length = mdp_len;
133 return 0;
134}
135
136static int skb_to_mep(const struct sk_buff *skb, struct mbo *mbo)
137{
138 u8 *buff = mbo->virt_address;
139 unsigned int mep_len = skb->len + MEP_HDR_LEN;
140
141 if (mbo->buffer_length < mep_len) {
142 pr_err("drop: too small buffer! (%d for %d)\n",
143 mbo->buffer_length, mep_len);
144 return -EINVAL;
145 }
146
147 *buff++ = HB(mep_len - 2);
148 *buff++ = LB(mep_len - 2);
149
150 *buff++ = PMHL;
151 *buff++ = (PMS_FIFONO_MEP << PMS_FIFONO_SHIFT) | PMS_MSGTYPE_DATA;
152 *buff++ = (MEP_DEF_RETRY << PMS_RETRY_SHIFT) | PMS_DEF_PRIO;
153 *buff++ = 0;
154 *buff++ = 0;
155 *buff++ = 0;
156
157 memcpy(buff, skb->data, skb->len);
158 mbo->buffer_length = mep_len;
159 return 0;
160}
161
162static int most_nd_set_mac_address(struct net_device *dev, void *p)
163{
164 struct net_dev_context *nd = dev->ml_priv;
165 int err = eth_mac_addr(dev, p);
166
167 if (err)
168 return err;
169
170 BUG_ON(nd->dev != dev);
171
172 nd->is_mamac =
173 (dev->dev_addr[0] == 0 && dev->dev_addr[1] == 0 &&
174 dev->dev_addr[2] == 0 && dev->dev_addr[3] == 0);
175
176 /*
177 * Set default MTU for the given packet type.
178 * It is still possible to change MTU using ip tools afterwards.
179 */
180 dev->mtu = nd->is_mamac ? MAMAC_DATA_LEN : ETH_DATA_LEN;
181
182 return 0;
183}
184
185static int most_nd_open(struct net_device *dev)
186{
187 struct net_dev_context *nd = dev->ml_priv;
188
189 pr_info("open net device %s\n", dev->name);
190
191 BUG_ON(nd->dev != dev);
192
193 if (nd->channels_opened)
194 return -EFAULT;
195
196 BUG_ON(!nd->tx.linked || !nd->rx.linked);
197
198 if (most_start_channel(nd->iface, nd->rx.ch_id)) {
199 pr_err("most_start_channel() failed\n");
200 return -EBUSY;
201 }
202
203 if (most_start_channel(nd->iface, nd->tx.ch_id)) {
204 pr_err("most_start_channel() failed\n");
205 most_stop_channel(nd->iface, nd->rx.ch_id);
206 return -EBUSY;
207 }
208
209 nd->channels_opened = true;
210
211 if (nd->is_mamac) {
212 nd->link_stat = 1;
213 netif_wake_queue(dev);
214 } else {
215 nd->iface->request_netinfo(nd->iface, nd->tx.ch_id);
216 }
217
218 return 0;
219}
220
221static int most_nd_stop(struct net_device *dev)
222{
223 struct net_dev_context *nd = dev->ml_priv;
224
225 pr_info("stop net device %s\n", dev->name);
226
227 BUG_ON(nd->dev != dev);
228 netif_stop_queue(dev);
229
230 if (nd->channels_opened) {
231 most_stop_channel(nd->iface, nd->rx.ch_id);
232 most_stop_channel(nd->iface, nd->tx.ch_id);
233 nd->channels_opened = false;
234 }
235
236 return 0;
237}
238
239static netdev_tx_t most_nd_start_xmit(struct sk_buff *skb,
240 struct net_device *dev)
241{
242 struct net_dev_context *nd = dev->ml_priv;
243 struct mbo *mbo;
244 int ret;
245
246 BUG_ON(nd->dev != dev);
247
248 mbo = most_get_mbo(nd->iface, nd->tx.ch_id);
249
250 if (!mbo) {
251 netif_stop_queue(dev);
252 dev->stats.tx_fifo_errors++;
253 return NETDEV_TX_BUSY;
254 }
255
256 if (nd->is_mamac)
257 ret = skb_to_mamac(skb, mbo);
258 else
259 ret = skb_to_mep(skb, mbo);
260
261 if (ret) {
262 most_put_mbo(mbo);
263 dev->stats.tx_dropped++;
264 kfree_skb(skb);
265 return NETDEV_TX_OK;
266 }
267
268 most_submit_mbo(mbo);
269 dev->stats.tx_packets++;
270 dev->stats.tx_bytes += skb->len;
271 kfree_skb(skb);
272 return NETDEV_TX_OK;
273}
274
275static const struct net_device_ops most_nd_ops = {
276 .ndo_open = most_nd_open,
277 .ndo_stop = most_nd_stop,
278 .ndo_start_xmit = most_nd_start_xmit,
279 .ndo_set_mac_address = most_nd_set_mac_address,
280};
281
282static void most_nd_setup(struct net_device *dev)
283{
284 pr_info("setup net device %s\n", dev->name);
285 ether_setup(dev);
286 dev->netdev_ops = &most_nd_ops;
287}
288
289static void most_net_rm_netdev_safe(struct net_dev_context *nd)
290{
291 if (!nd->dev)
292 return;
293
294 pr_info("remove net device %p\n", nd->dev);
295
296 unregister_netdev(nd->dev);
297 free_netdev(nd->dev);
298 nd->dev = 0;
299}
300
301static struct net_dev_context *get_net_dev_context(
302 struct most_interface *iface)
303{
304 struct net_dev_context *nd, *tmp;
305
306 spin_lock(&list_lock);
307 list_for_each_entry_safe(nd, tmp, &net_devices, list) {
308 if (nd->iface == iface) {
309 spin_unlock(&list_lock);
310 return nd;
311 }
312 }
313 spin_unlock(&list_lock);
314 return NULL;
315}
316
317static int aim_probe_channel(struct most_interface *iface, int channel_idx,
318 struct most_channel_config *ccfg,
319 struct kobject *parent, char *name)
320{
321 struct net_dev_context *nd;
322 struct net_dev_channel *ch;
323
324 if (!iface)
325 return -EINVAL;
326
327 if (ccfg->data_type != MOST_CH_ASYNC)
328 return -EINVAL;
329
330 nd = get_net_dev_context(iface);
331
332 if (!nd) {
333 nd = kzalloc(sizeof(*nd), GFP_KERNEL);
334 if (!nd)
335 return -ENOMEM;
336
337 nd->iface = iface;
338
339 spin_lock(&list_lock);
340 list_add(&nd->list, &net_devices);
341 spin_unlock(&list_lock);
342 }
343
344 ch = ccfg->direction == MOST_CH_TX ? &nd->tx : &nd->rx;
345 if (ch->linked) {
346 pr_err("only one channel per instance & direction allowed\n");
347 return -EINVAL;
348 }
349
350 if (nd->tx.linked || nd->rx.linked) {
351 struct net_device *dev =
352 alloc_netdev(0, "meth%d", NET_NAME_UNKNOWN, most_nd_setup);
353
354 if (!dev) {
355 pr_err("no memory for net_device\n");
356 return -ENOMEM;
357 }
358
359 nd->dev = dev;
360
361 dev->ml_priv = nd;
362 if (register_netdev(dev)) {
363 pr_err("registering net device failed\n");
364 free_netdev(dev);
365 return -EINVAL;
366 }
367 }
368
369 ch->ch_id = channel_idx;
370 ch->linked = true;
371
372 return 0;
373}
374
375static int aim_disconnect_channel(struct most_interface *iface,
376 int channel_idx)
377{
378 struct net_dev_context *nd;
379 struct net_dev_channel *ch;
380
381 nd = get_net_dev_context(iface);
382 if (!nd)
383 return -EINVAL;
384
385 if (nd->rx.linked && channel_idx == nd->rx.ch_id)
386 ch = &nd->rx;
387 else if (nd->tx.linked && channel_idx == nd->tx.ch_id)
388 ch = &nd->tx;
389 else
390 return -EINVAL;
391
392 ch->linked = false;
393
394 /*
395 * do not call most_stop_channel() here, because channels are
396 * going to be closed in ndo_stop() after unregister_netdev()
397 */
398 most_net_rm_netdev_safe(nd);
399
400 if (!nd->rx.linked && !nd->tx.linked) {
401 spin_lock(&list_lock);
402 list_del(&nd->list);
403 spin_unlock(&list_lock);
404 kfree(nd);
405 }
406
407 return 0;
408}
409
410static int aim_resume_tx_channel(struct most_interface *iface,
411 int channel_idx)
412{
413 struct net_dev_context *nd;
414
415 nd = get_net_dev_context(iface);
416 if (!nd || !nd->channels_opened || nd->tx.ch_id != channel_idx)
417 return 0;
418
419 if (!nd->dev)
420 return 0;
421
422 netif_wake_queue(nd->dev);
423 return 0;
424}
425
426static int aim_rx_data(struct mbo *mbo)
427{
428 const u32 zero = 0;
429 struct net_dev_context *nd;
430 char *buf = mbo->virt_address;
431 uint32_t len = mbo->processed_length;
432 struct sk_buff *skb;
433 struct net_device *dev;
434
435 nd = get_net_dev_context(mbo->ifp);
436 if (!nd || !nd->channels_opened || nd->rx.ch_id != mbo->hdm_channel_id)
437 return -EIO;
438
439 dev = nd->dev;
440 if (!dev) {
441 pr_err_once("drop packet: missing net_device\n");
442 return -EIO;
443 }
444
445 if (nd->is_mamac) {
446 if (!PMS_IS_MAMAC(buf, len))
447 return -EIO;
448
449 skb = dev_alloc_skb(len - MDP_HDR_LEN + 2 * ETH_ALEN + 2);
450 } else {
451 if (!PMS_IS_MEP(buf, len))
452 return -EIO;
453
454 skb = dev_alloc_skb(len - MEP_HDR_LEN);
455 }
456
457 if (!skb) {
458 dev->stats.rx_dropped++;
459 pr_err_once("drop packet: no memory for skb\n");
460 goto out;
461 }
462
463 skb->dev = dev;
464
465 if (nd->is_mamac) {
466 /* dest */
467 memcpy(skb_put(skb, ETH_ALEN), dev->dev_addr, ETH_ALEN);
468
469 /* src */
470 memcpy(skb_put(skb, 4), &zero, 4);
471 memcpy(skb_put(skb, 2), buf + 5, 2);
472
473 /* eth type */
474 memcpy(skb_put(skb, 2), buf + 10, 2);
475
476 buf += MDP_HDR_LEN;
477 len -= MDP_HDR_LEN;
478 } else {
479 buf += MEP_HDR_LEN;
480 len -= MEP_HDR_LEN;
481 }
482
483 memcpy(skb_put(skb, len), buf, len);
484 skb->protocol = eth_type_trans(skb, dev);
485 dev->stats.rx_packets++;
486 dev->stats.rx_bytes += skb->len;
487 netif_rx(skb);
488
489out:
490 most_put_mbo(mbo);
491 return 0;
492}
493
494static int __init most_net_init(void)
495{
496 pr_info("most_net_init()\n");
497 spin_lock_init(&list_lock);
498 aim.name = "networking";
499 aim.probe_channel = aim_probe_channel;
500 aim.disconnect_channel = aim_disconnect_channel;
501 aim.tx_completion = aim_resume_tx_channel;
502 aim.rx_completion = aim_rx_data;
503 return most_register_aim(&aim);
504}
505
506static void __exit most_net_exit(void)
507{
508 struct net_dev_context *nd, *tmp;
509
510 spin_lock(&list_lock);
511 list_for_each_entry_safe(nd, tmp, &net_devices, list) {
512 list_del(&nd->list);
513 spin_unlock(&list_lock);
514 /*
515 * do not call most_stop_channel() here, because channels are
516 * going to be closed in ndo_stop() after unregister_netdev()
517 */
518 most_net_rm_netdev_safe(nd);
519 kfree(nd);
520 spin_lock(&list_lock);
521 }
522 spin_unlock(&list_lock);
523
524 most_deregister_aim(&aim);
525 pr_info("most_net_exit()\n");
526}
527
528/**
529 * most_deliver_netinfo - callback for HDM to be informed about HW's MAC
530 * @param iface - most interface instance
531 * @param link_stat - link status
532 * @param mac_addr - MAC address
533 */
534void most_deliver_netinfo(struct most_interface *iface,
535 unsigned char link_stat, unsigned char *mac_addr)
536{
537 struct net_dev_context *nd;
538 struct net_device *dev;
539
540 pr_info("Received netinfo from %s\n", iface->description);
541
542 nd = get_net_dev_context(iface);
543 if (!nd)
544 return;
545
546 dev = nd->dev;
547 if (!dev)
548 return;
549
550 if (mac_addr)
551 memcpy(dev->dev_addr, mac_addr, ETH_ALEN);
552
553 if (nd->link_stat != link_stat) {
554 nd->link_stat = link_stat;
555 if (nd->link_stat)
556 netif_wake_queue(dev);
557 else
558 netif_stop_queue(dev);
559 }
560}
561EXPORT_SYMBOL(most_deliver_netinfo);
562
563module_init(most_net_init);
564module_exit(most_net_exit);
565MODULE_LICENSE("GPL");
566MODULE_AUTHOR("Andrey Shvetsov <andrey.shvetsov@k2l.de>");
567MODULE_DESCRIPTION("Networking Application Interface Module for MostCore");
diff --git a/drivers/staging/most/aim-network/networking.h b/drivers/staging/most/aim-network/networking.h
new file mode 100644
index 000000000000..1b8b434fabb0
--- /dev/null
+++ b/drivers/staging/most/aim-network/networking.h
@@ -0,0 +1,23 @@
1/*
2 * Networking AIM - Networking Application Interface Module for MostCore
3 *
4 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * This file is licensed under GPLv2.
12 */
13#ifndef _NETWORKING_H_
14#define _NETWORKING_H_
15
16#include "mostcore.h"
17
18
19void most_deliver_netinfo(struct most_interface *iface,
20 unsigned char link_stat, unsigned char *mac_addr);
21
22
23#endif
diff --git a/drivers/staging/most/aim-sound/Kconfig b/drivers/staging/most/aim-sound/Kconfig
new file mode 100644
index 000000000000..3194c219ff14
--- /dev/null
+++ b/drivers/staging/most/aim-sound/Kconfig
@@ -0,0 +1,13 @@
1#
2# MOST ALSA configuration
3#
4
5config AIM_SOUND
6 tristate "ALSA AIM"
7 depends on SND
8 select SND_PCM
9 ---help---
10 Say Y here if you want to commumicate via ALSA/sound devices.
11
12 To compile this driver as a module, choose M here: the
13 module will be called aim_sound.
diff --git a/drivers/staging/most/aim-sound/Makefile b/drivers/staging/most/aim-sound/Makefile
new file mode 100644
index 000000000000..beba9586fd28
--- /dev/null
+++ b/drivers/staging/most/aim-sound/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_AIM_SOUND) += aim_sound.o
2
3aim_sound-objs := sound.o
4ccflags-y += -Idrivers/staging/most/mostcore/
diff --git a/drivers/staging/most/aim-sound/sound.c b/drivers/staging/most/aim-sound/sound.c
new file mode 100644
index 000000000000..860302eebda7
--- /dev/null
+++ b/drivers/staging/most/aim-sound/sound.c
@@ -0,0 +1,758 @@
1/*
2 * sound.c - Audio Application Interface Module for Mostcore
3 *
4 * Copyright (C) 2015 Microchip Technology Germany II GmbH & Co. KG
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * This file is licensed under GPLv2.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
16#include <linux/module.h>
17#include <linux/printk.h>
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <sound/core.h>
21#include <sound/pcm.h>
22#include <linux/sched.h>
23#include <linux/kthread.h>
24#include <mostcore.h>
25
26#define DRIVER_NAME "sound"
27
28static struct list_head dev_list;
29
30/**
31 * struct channel - private structure to keep channel specific data
32 * @substream: stores the substream structure
33 * @iface: interface for which the channel belongs to
34 * @cfg: channel configuration
35 * @card: registered sound card
36 * @list: list for private use
37 * @id: channel index
38 * @period_pos: current period position (ring buffer)
39 * @buffer_pos: current buffer position (ring buffer)
40 * @is_stream_running: identifies whether a stream is running or not
41 * @opened: set when the stream is opened
42 * @playback_task: playback thread
43 * @playback_waitq: waitq used by playback thread
44 */
45struct channel {
46 struct snd_pcm_substream *substream;
47 struct most_interface *iface;
48 struct most_channel_config *cfg;
49 struct snd_card *card;
50 struct list_head list;
51 int id;
52 unsigned int period_pos;
53 unsigned int buffer_pos;
54 bool is_stream_running;
55
56 struct task_struct *playback_task;
57 wait_queue_head_t playback_waitq;
58
59 void (*copy_fn)(void *alsa, void *most, unsigned int bytes);
60};
61
62#define MOST_PCM_INFO (SNDRV_PCM_INFO_MMAP | \
63 SNDRV_PCM_INFO_MMAP_VALID | \
64 SNDRV_PCM_INFO_BATCH | \
65 SNDRV_PCM_INFO_INTERLEAVED | \
66 SNDRV_PCM_INFO_BLOCK_TRANSFER)
67
68/**
69 * Initialization of struct snd_pcm_hardware
70 */
71static struct snd_pcm_hardware pcm_hardware_template = {
72 .info = MOST_PCM_INFO,
73 .rates = SNDRV_PCM_RATE_48000,
74 .rate_min = 48000,
75 .rate_max = 48000,
76 .channels_min = 1,
77 .channels_max = 8,
78};
79
80#define swap16(val) ( \
81 (((u16)(val) << 8) & (u16)0xFF00) | \
82 (((u16)(val) >> 8) & (u16)0x00FF))
83
84#define swap32(val) ( \
85 (((u32)(val) << 24) & (u32)0xFF000000) | \
86 (((u32)(val) << 8) & (u32)0x00FF0000) | \
87 (((u32)(val) >> 8) & (u32)0x0000FF00) | \
88 (((u32)(val) >> 24) & (u32)0x000000FF))
89
90static void swap_copy16(u16 *dest, const u16 *source, unsigned int bytes)
91{
92 unsigned int i = 0;
93
94 while (i < (bytes / 2)) {
95 dest[i] = swap16(source[i]);
96 i++;
97 }
98}
99
100static void swap_copy24(u8 *dest, const u8 *source, unsigned int bytes)
101{
102 unsigned int i = 0;
103
104 while (i < bytes - 2) {
105 dest[i] = source[i + 2];
106 dest[i + 1] = source[i + 1];
107 dest[i + 2] = source[i];
108 i += 3;
109 }
110}
111
112static void swap_copy32(u32 *dest, const u32 *source, unsigned int bytes)
113{
114 unsigned int i = 0;
115
116 while (i < bytes / 4) {
117 dest[i] = swap32(source[i]);
118 i++;
119 }
120}
121
122static void alsa_to_most_memcpy(void *alsa, void *most, unsigned int bytes)
123{
124 memcpy(most, alsa, bytes);
125}
126
127static void alsa_to_most_copy16(void *alsa, void *most, unsigned int bytes)
128{
129 swap_copy16(most, alsa, bytes);
130}
131
132static void alsa_to_most_copy24(void *alsa, void *most, unsigned int bytes)
133{
134 swap_copy24(most, alsa, bytes);
135}
136
137static void alsa_to_most_copy32(void *alsa, void *most, unsigned int bytes)
138{
139 swap_copy32(most, alsa, bytes);
140}
141
142static void most_to_alsa_memcpy(void *alsa, void *most, unsigned int bytes)
143{
144 memcpy(alsa, most, bytes);
145}
146
147static void most_to_alsa_copy16(void *alsa, void *most, unsigned int bytes)
148{
149 swap_copy16(alsa, most, bytes);
150}
151
152static void most_to_alsa_copy24(void *alsa, void *most, unsigned int bytes)
153{
154 swap_copy24(alsa, most, bytes);
155}
156
157static void most_to_alsa_copy32(void *alsa, void *most, unsigned int bytes)
158{
159 swap_copy32(alsa, most, bytes);
160}
161
162/**
163 * get_channel - get pointer to channel
164 * @iface: interface structure
165 * @channel_id: channel ID
166 *
167 * This traverses the channel list and returns the channel matching the
168 * ID and interface.
169 *
170 * Returns pointer to channel on success or NULL otherwise.
171 */
172static struct channel *get_channel(struct most_interface *iface,
173 int channel_id)
174{
175 struct channel *channel, *tmp;
176
177 list_for_each_entry_safe(channel, tmp, &dev_list, list) {
178 if ((channel->iface == iface) && (channel->id == channel_id))
179 return channel;
180 }
181
182 return NULL;
183}
184
185/**
186 * copy_data - implements data copying function
187 * @channel: channel
188 * @mbo: MBO from core
189 *
190 * Copy data from/to ring buffer to/from MBO and update the buffer position
191 */
192static bool copy_data(struct channel *channel, struct mbo *mbo)
193{
194 struct snd_pcm_runtime *const runtime = channel->substream->runtime;
195 unsigned int const frame_bytes = channel->cfg->subbuffer_size;
196 unsigned int const buffer_size = runtime->buffer_size;
197 unsigned int frames;
198 unsigned int fr0;
199
200 if (channel->cfg->direction & MOST_CH_RX)
201 frames = mbo->processed_length / frame_bytes;
202 else
203 frames = mbo->buffer_length / frame_bytes;
204 fr0 = min(buffer_size - channel->buffer_pos, frames);
205
206 channel->copy_fn(runtime->dma_area + channel->buffer_pos * frame_bytes,
207 mbo->virt_address,
208 fr0 * frame_bytes);
209
210 if (frames > fr0) {
211 /* wrap around at end of ring buffer */
212 channel->copy_fn(runtime->dma_area,
213 mbo->virt_address + fr0 * frame_bytes,
214 (frames - fr0) * frame_bytes);
215 }
216
217 channel->buffer_pos += frames;
218 if (channel->buffer_pos >= buffer_size)
219 channel->buffer_pos -= buffer_size;
220 channel->period_pos += frames;
221 if (channel->period_pos >= runtime->period_size) {
222 channel->period_pos -= runtime->period_size;
223 return true;
224 }
225
226 return false;
227}
228
229/**
230 * playback_thread - function implements the playback thread
231 * @data: private data
232 *
233 * Thread which does the playback functionality in a loop. It waits for a free
234 * MBO from mostcore for a particular channel and copy the data from ring buffer
235 * to MBO. Submit the MBO back to mostcore, after copying the data.
236 *
237 * Returns 0 on success or error code otherwise.
238 */
239static int playback_thread(void *data)
240{
241 struct channel *const channel = data;
242
243 pr_info("playback thread started\n");
244
245 while (!kthread_should_stop()) {
246 struct mbo *mbo = NULL;
247 bool period_elapsed = false;
248 int ret;
249
250 wait_event_interruptible(
251 channel->playback_waitq,
252 kthread_should_stop() ||
253 (mbo = most_get_mbo(channel->iface, channel->id)));
254
255 if (!mbo)
256 continue;
257
258 if (channel->is_stream_running)
259 period_elapsed = copy_data(channel, mbo);
260 else
261 memset(mbo->virt_address, 0, mbo->buffer_length);
262
263 ret = most_submit_mbo(mbo);
264 if (ret)
265 channel->is_stream_running = false;
266
267 if (period_elapsed)
268 snd_pcm_period_elapsed(channel->substream);
269 }
270
271 return 0;
272}
273
274/**
275 * pcm_open - implements open callback function for PCM middle layer
276 * @substream: pointer to ALSA PCM substream
277 *
278 * This is called when a PCM substream is opened. At least, the function should
279 * initialize the runtime->hw record.
280 *
281 * Returns 0 on success or error code otherwise.
282 */
283static int pcm_open(struct snd_pcm_substream *substream)
284{
285 struct channel *channel = substream->private_data;
286 struct snd_pcm_runtime *runtime = substream->runtime;
287 struct most_channel_config *cfg = channel->cfg;
288
289 pr_info("pcm_open(), %s\n", substream->name);
290
291 channel->substream = substream;
292
293 if (cfg->direction == MOST_CH_TX) {
294 init_waitqueue_head(&channel->playback_waitq);
295 channel->playback_task = kthread_run(&playback_thread, channel,
296 "most_audio_playback");
297 if (IS_ERR(channel->playback_task))
298 return PTR_ERR(channel->playback_task);
299 }
300
301 if (most_start_channel(channel->iface, channel->id)) {
302 pr_err("most_start_channel() failed!\n");
303 if (cfg->direction == MOST_CH_TX)
304 kthread_stop(channel->playback_task);
305 return -EBUSY;
306 }
307
308 runtime->hw = pcm_hardware_template;
309 runtime->hw.buffer_bytes_max = cfg->num_buffers * cfg->buffer_size;
310 runtime->hw.period_bytes_min = cfg->buffer_size;
311 runtime->hw.period_bytes_max = cfg->buffer_size;
312 runtime->hw.periods_min = 1;
313 runtime->hw.periods_max = cfg->num_buffers;
314
315 return 0;
316}
317
318/**
319 * pcm_close - implements close callback function for PCM middle layer
320 * @substream: sub-stream pointer
321 *
322 * Obviously, this is called when a PCM substream is closed. Any private
323 * instance for a PCM substream allocated in the open callback will be
324 * released here.
325 *
326 * Returns 0 on success or error code otherwise.
327 */
328static int pcm_close(struct snd_pcm_substream *substream)
329{
330 struct channel *channel = substream->private_data;
331
332 pr_info("pcm_close(), %s\n", substream->name);
333
334 if (channel->cfg->direction == MOST_CH_TX)
335 kthread_stop(channel->playback_task);
336 most_stop_channel(channel->iface, channel->id);
337
338 return 0;
339}
340
341/**
342 * pcm_hw_params - implements hw_params callback function for PCM middle layer
343 * @substream: sub-stream pointer
344 * @hw_params: contains the hardware parameters set by the application
345 *
346 * This is called when the hardware parameters is set by the application, that
347 * is, once when the buffer size, the period size, the format, etc. are defined
348 * for the PCM substream. Many hardware setups should be done is this callback,
349 * including the allocation of buffers.
350 *
351 * Returns 0 on success or error code otherwise.
352 */
353static int pcm_hw_params(struct snd_pcm_substream *substream,
354 struct snd_pcm_hw_params *hw_params)
355{
356 pr_info("pcm_hw_params()\n");
357
358 return snd_pcm_lib_alloc_vmalloc_buffer(substream,
359 params_buffer_bytes(hw_params));
360}
361
362/**
363 * pcm_hw_free - implements hw_free callback function for PCM middle layer
364 * @substream: substream pointer
365 *
366 * This is called to release the resources allocated via hw_params.
367 * This function will be always called before the close callback is called.
368 *
369 * Returns 0 on success or error code otherwise.
370 */
371static int pcm_hw_free(struct snd_pcm_substream *substream)
372{
373 pr_info("pcm_hw_free()\n");
374
375 return snd_pcm_lib_free_vmalloc_buffer(substream);
376}
377
378/**
379 * pcm_prepare - implements prepare callback function for PCM middle layer
380 * @substream: substream pointer
381 *
382 * This callback is called when the PCM is "prepared". Format rate, sample rate,
383 * etc., can be set here. This callback can be called many times at each setup.
384 *
385 * Returns 0 on success or error code otherwise.
386 */
387static int pcm_prepare(struct snd_pcm_substream *substream)
388{
389 struct channel *channel = substream->private_data;
390 struct snd_pcm_runtime *runtime = substream->runtime;
391 struct most_channel_config *cfg = channel->cfg;
392 int width = snd_pcm_format_physical_width(runtime->format);
393
394 channel->copy_fn = NULL;
395
396 if (cfg->direction == MOST_CH_TX) {
397 if (snd_pcm_format_big_endian(runtime->format) || width == 8)
398 channel->copy_fn = alsa_to_most_memcpy;
399 else if (width == 16)
400 channel->copy_fn = alsa_to_most_copy16;
401 else if (width == 24)
402 channel->copy_fn = alsa_to_most_copy24;
403 else if (width == 32)
404 channel->copy_fn = alsa_to_most_copy32;
405 } else {
406 if (snd_pcm_format_big_endian(runtime->format) || width == 8)
407 channel->copy_fn = most_to_alsa_memcpy;
408 else if (width == 16)
409 channel->copy_fn = most_to_alsa_copy16;
410 else if (width == 24)
411 channel->copy_fn = most_to_alsa_copy24;
412 else if (width == 32)
413 channel->copy_fn = most_to_alsa_copy32;
414 }
415
416 if (!channel->copy_fn) {
417 pr_err("unsupported format\n");
418 return -EINVAL;
419 }
420
421 channel->period_pos = 0;
422 channel->buffer_pos = 0;
423
424 return 0;
425}
426
427/**
428 * pcm_trigger - implements trigger callback function for PCM middle layer
429 * @substream: substream pointer
430 * @cmd: action to perform
431 *
432 * This is called when the PCM is started, stopped or paused. The action will be
433 * specified in the second argument, SNDRV_PCM_TRIGGER_XXX
434 *
435 * Returns 0 on success or error code otherwise.
436 */
437static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
438{
439 struct channel *channel = substream->private_data;
440
441 switch (cmd) {
442 case SNDRV_PCM_TRIGGER_START:
443 channel->is_stream_running = true;
444 return 0;
445
446 case SNDRV_PCM_TRIGGER_STOP:
447 channel->is_stream_running = false;
448 return 0;
449
450 default:
451 pr_info("pcm_trigger(), invalid\n");
452 return -EINVAL;
453 }
454 return 0;
455}
456
457/**
458 * pcm_pointer - implements pointer callback function for PCM middle layer
459 * @substream: substream pointer
460 *
461 * This callback is called when the PCM middle layer inquires the current
462 * hardware position on the buffer. The position must be returned in frames,
463 * ranging from 0 to buffer_size-1.
464 */
465static snd_pcm_uframes_t pcm_pointer(struct snd_pcm_substream *substream)
466{
467 struct channel *channel = substream->private_data;
468
469 return channel->buffer_pos;
470}
471
472/**
473 * Initialization of struct snd_pcm_ops
474 */
475static struct snd_pcm_ops pcm_ops = {
476 .open = pcm_open,
477 .close = pcm_close,
478 .ioctl = snd_pcm_lib_ioctl,
479 .hw_params = pcm_hw_params,
480 .hw_free = pcm_hw_free,
481 .prepare = pcm_prepare,
482 .trigger = pcm_trigger,
483 .pointer = pcm_pointer,
484 .page = snd_pcm_lib_get_vmalloc_page,
485 .mmap = snd_pcm_lib_mmap_vmalloc,
486};
487
488
489int split_arg_list(char *buf, char **card_name, char **pcm_format)
490{
491 *card_name = strsep(&buf, ".");
492 if (!*card_name)
493 return -EIO;
494 *pcm_format = strsep(&buf, ".\n");
495 if (!*pcm_format)
496 return -EIO;
497 return 0;
498}
499
500int audio_set_pcm_format(char *pcm_format, struct most_channel_config *cfg)
501{
502 if (!strcmp(pcm_format, "1x8")) {
503 if (cfg->subbuffer_size != 1)
504 goto error;
505 pr_info("PCM format is 8-bit mono\n");
506 pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S8;
507 } else if (!strcmp(pcm_format, "2x16")) {
508 if (cfg->subbuffer_size != 4)
509 goto error;
510 pr_info("PCM format is 16-bit stereo\n");
511 pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S16_LE |
512 SNDRV_PCM_FMTBIT_S16_BE;
513 } else if (!strcmp(pcm_format, "2x24")) {
514 if (cfg->subbuffer_size != 6)
515 goto error;
516 pr_info("PCM format is 24-bit stereo\n");
517 pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S24_3LE |
518 SNDRV_PCM_FMTBIT_S24_3BE;
519 } else if (!strcmp(pcm_format, "2x32")) {
520 if (cfg->subbuffer_size != 8)
521 goto error;
522 pr_info("PCM format is 32-bit stereo\n");
523 pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S32_LE |
524 SNDRV_PCM_FMTBIT_S32_BE;
525 } else {
526 pr_err("PCM format %s not supported\n", pcm_format);
527 return -EIO;
528 }
529 return 0;
530error:
531 pr_err("Audio resolution doesn't fit subbuffer size\n");
532 return -EINVAL;
533}
534
535/**
536 * audio_probe_channel - probe function of the driver module
537 * @iface: pointer to interface instance
538 * @channel_id: channel index/ID
539 * @cfg: pointer to actual channel configuration
540 * @parent: pointer to kobject (needed for sysfs hook-up)
541 * @arg_list: string that provides the name of the device to be created in /dev
542 * plus the desired audio resolution
543 *
544 * Creates sound card, pcm device, sets pcm ops and registers sound card.
545 *
546 * Returns 0 on success or error code otherwise.
547 */
548static int audio_probe_channel(struct most_interface *iface, int channel_id,
549 struct most_channel_config *cfg,
550 struct kobject *parent, char *arg_list)
551{
552 struct channel *channel;
553 struct snd_card *card;
554 struct snd_pcm *pcm;
555 int playback_count = 0;
556 int capture_count = 0;
557 int ret;
558 int direction;
559 char *card_name;
560 char *pcm_format;
561
562 pr_info("sound_probe_channel()\n");
563
564 if (!iface)
565 return -EINVAL;
566
567 if (cfg->data_type != MOST_CH_SYNC) {
568 pr_err("Incompatible channel type\n");
569 return -EINVAL;
570 }
571
572 if (get_channel(iface, channel_id)) {
573 pr_err("channel (%s:%d) is already linked\n",
574 iface->description, channel_id);
575 return -EINVAL;
576 }
577
578 if (cfg->direction == MOST_CH_TX) {
579 playback_count = 1;
580 direction = SNDRV_PCM_STREAM_PLAYBACK;
581 } else {
582 capture_count = 1;
583 direction = SNDRV_PCM_STREAM_CAPTURE;
584 }
585
586 ret = split_arg_list(arg_list, &card_name, &pcm_format);
587 if (ret < 0) {
588 pr_info("PCM format missing\n");
589 return ret;
590 }
591 if (audio_set_pcm_format(pcm_format, cfg))
592 return ret;
593
594 ret = snd_card_new(NULL, -1, card_name, THIS_MODULE,
595 sizeof(*channel), &card);
596 if (ret < 0)
597 return ret;
598
599 channel = card->private_data;
600 channel->card = card;
601 channel->cfg = cfg;
602 channel->iface = iface;
603 channel->id = channel_id;
604
605 snprintf(card->driver, sizeof(card->driver), "%s", DRIVER_NAME);
606 snprintf(card->shortname, sizeof(card->shortname), "MOST:%d",
607 card->number);
608 snprintf(card->longname, sizeof(card->longname), "%s at %s, ch %d",
609 card->shortname, iface->description, channel_id);
610
611 ret = snd_pcm_new(card, card_name, 0, playback_count,
612 capture_count, &pcm);
613 if (ret < 0)
614 goto err_free_card;
615
616 pcm->private_data = channel;
617
618 snd_pcm_set_ops(pcm, direction, &pcm_ops);
619
620 ret = snd_card_register(card);
621 if (ret < 0)
622 goto err_free_card;
623
624 list_add_tail(&channel->list, &dev_list);
625
626 return 0;
627
628err_free_card:
629 snd_card_free(card);
630 return ret;
631}
632
633/**
634 * audio_disconnect_channel - function to disconnect a channel
635 * @iface: pointer to interface instance
636 * @channel_id: channel index
637 *
638 * This frees allocated memory and removes the sound card from ALSA
639 *
640 * Returns 0 on success or error code otherwise.
641 */
642static int audio_disconnect_channel(struct most_interface *iface,
643 int channel_id)
644{
645 struct channel *channel;
646
647 pr_info("sound_disconnect_channel()\n");
648
649 channel = get_channel(iface, channel_id);
650 if (!channel) {
651 pr_err("sound_disconnect_channel(), invalid channel %d\n",
652 channel_id);
653 return -EINVAL;
654 }
655
656 list_del(&channel->list);
657 snd_card_free(channel->card);
658
659 return 0;
660}
661
662/**
663 * audio_rx_completion - completion handler for rx channels
664 * @mbo: pointer to buffer object that has completed
665 *
666 * This searches for the channel this MBO belongs to and copy the data from MBO
667 * to ring buffer
668 *
669 * Returns 0 on success or error code otherwise.
670 */
671static int audio_rx_completion(struct mbo *mbo)
672{
673 struct channel *channel = get_channel(mbo->ifp, mbo->hdm_channel_id);
674 bool period_elapsed = false;
675
676 if (!channel) {
677 pr_err("sound_rx_completion(), invalid channel %d\n",
678 mbo->hdm_channel_id);
679 return -EINVAL;
680 }
681
682 if (channel->is_stream_running)
683 period_elapsed = copy_data(channel, mbo);
684
685 most_put_mbo(mbo);
686
687 if (period_elapsed)
688 snd_pcm_period_elapsed(channel->substream);
689
690 return 0;
691}
692
693/**
694 * audio_tx_completion - completion handler for tx channels
695 * @iface: pointer to interface instance
696 * @channel_id: channel index/ID
697 *
698 * This searches the channel that belongs to this combination of interface
699 * pointer and channel ID and wakes a process sitting in the wait queue of
700 * this channel.
701 *
702 * Returns 0 on success or error code otherwise.
703 */
704static int audio_tx_completion(struct most_interface *iface, int channel_id)
705{
706 struct channel *channel = get_channel(iface, channel_id);
707
708 if (!channel) {
709 pr_err("sound_tx_completion(), invalid channel %d\n",
710 channel_id);
711 return -EINVAL;
712 }
713
714 wake_up_interruptible(&channel->playback_waitq);
715
716 return 0;
717}
718
719/**
720 * Initialization of the struct most_aim
721 */
722static struct most_aim audio_aim = {
723 .name = DRIVER_NAME,
724 .probe_channel = audio_probe_channel,
725 .disconnect_channel = audio_disconnect_channel,
726 .rx_completion = audio_rx_completion,
727 .tx_completion = audio_tx_completion,
728};
729
730static int __init audio_init(void)
731{
732 pr_info("init()\n");
733
734 INIT_LIST_HEAD(&dev_list);
735
736 return most_register_aim(&audio_aim);
737}
738
739static void __exit audio_exit(void)
740{
741 struct channel *channel, *tmp;
742
743 pr_info("exit()\n");
744
745 list_for_each_entry_safe(channel, tmp, &dev_list, list) {
746 list_del(&channel->list);
747 snd_card_free(channel->card);
748 }
749
750 most_deregister_aim(&audio_aim);
751}
752
753module_init(audio_init);
754module_exit(audio_exit);
755
756MODULE_LICENSE("GPL");
757MODULE_AUTHOR("Christian Gromm <christian.gromm@microchip.com>");
758MODULE_DESCRIPTION("Audio Application Interface Module for MostCore");
diff --git a/drivers/staging/most/aim-v4l2/Kconfig b/drivers/staging/most/aim-v4l2/Kconfig
new file mode 100644
index 000000000000..d70eaaf0936c
--- /dev/null
+++ b/drivers/staging/most/aim-v4l2/Kconfig
@@ -0,0 +1,12 @@
1#
2# MOST V4L2 configuration
3#
4
5config AIM_V4L2
6 tristate "V4L2 AIM"
7 depends on VIDEO_V4L2
8 ---help---
9 Say Y here if you want to commumicate via Video 4 Linux.
10
11 To compile this driver as a module, choose M here: the
12 module will be called aim_v4l2. \ No newline at end of file
diff --git a/drivers/staging/most/aim-v4l2/Makefile b/drivers/staging/most/aim-v4l2/Makefile
new file mode 100644
index 000000000000..28aa948d6609
--- /dev/null
+++ b/drivers/staging/most/aim-v4l2/Makefile
@@ -0,0 +1,6 @@
1obj-$(CONFIG_AIM_V4L2) += aim_v4l2.o
2
3aim_v4l2-objs := video.o
4
5ccflags-y += -Idrivers/staging/most/mostcore/
6ccflags-y += -Idrivers/media/video
diff --git a/drivers/staging/most/aim-v4l2/video.c b/drivers/staging/most/aim-v4l2/video.c
new file mode 100644
index 000000000000..d9687910e4a4
--- /dev/null
+++ b/drivers/staging/most/aim-v4l2/video.c
@@ -0,0 +1,635 @@
1/*
2 * V4L2 AIM - V4L2 Application Interface Module for MostCore
3 *
4 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * This file is licensed under GPLv2.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
16#include <linux/module.h>
17#include <linux/slab.h>
18#include <linux/init.h>
19#include <linux/device.h>
20#include <linux/suspend.h>
21#include <linux/videodev2.h>
22#include <linux/mutex.h>
23#include <media/v4l2-common.h>
24#include <media/v4l2-ioctl.h>
25#include <media/v4l2-event.h>
26#include <media/v4l2-device.h>
27#include <media/v4l2-ctrls.h>
28#include <media/v4l2-fh.h>
29
30#include "mostcore.h"
31
32
33#define V4L2_AIM_MAX_INPUT 1
34
35
36struct most_video_dev {
37 struct most_interface *iface;
38 int ch_idx;
39 struct list_head list;
40 bool mute;
41
42 struct list_head pending_mbos;
43 spinlock_t list_lock;
44
45 struct v4l2_device v4l2_dev;
46 atomic_t access_ref;
47 struct video_device *vdev;
48 unsigned int ctrl_input;
49
50 struct mutex lock;
51
52 wait_queue_head_t wait_data;
53};
54
55struct aim_fh {
56 /* must be the first field of this struct! */
57 struct v4l2_fh fh;
58 struct most_video_dev *mdev;
59 u32 offs;
60};
61
62
63static struct list_head video_devices = LIST_HEAD_INIT(video_devices);
64static struct spinlock list_lock;
65static struct most_aim aim_info;
66
67
68static inline bool data_ready(struct most_video_dev *mdev)
69{
70 return !list_empty(&mdev->pending_mbos);
71}
72
73static inline struct mbo *get_top_mbo(struct most_video_dev *mdev)
74{
75 return list_first_entry(&mdev->pending_mbos, struct mbo, list);
76}
77
78
79static int aim_vdev_open(struct file *filp)
80{
81 int ret;
82 struct video_device *vdev = video_devdata(filp);
83 struct most_video_dev *mdev = video_drvdata(filp);
84 struct aim_fh *fh;
85
86 pr_info("aim_vdev_open()\n");
87
88 switch (vdev->vfl_type) {
89 case VFL_TYPE_GRABBER:
90 break;
91 default:
92 return -EINVAL;
93 }
94
95 fh = kzalloc(sizeof(struct aim_fh), GFP_KERNEL);
96 if (!fh)
97 return -ENOMEM;
98
99 if (!atomic_inc_and_test(&mdev->access_ref)) {
100 pr_err("too many clients\n");
101 ret = -EBUSY;
102 goto err_dec;
103 }
104
105 fh->mdev = mdev;
106 v4l2_fh_init(&fh->fh, vdev);
107 filp->private_data = fh;
108
109 v4l2_fh_add(&fh->fh);
110
111 ret = most_start_channel(mdev->iface, mdev->ch_idx);
112 if (ret) {
113 pr_err("most_start_channel() failed\n");
114 goto err_rm;
115 }
116
117 return 0;
118
119err_rm:
120 v4l2_fh_del(&fh->fh);
121 v4l2_fh_exit(&fh->fh);
122
123err_dec:
124 atomic_dec(&mdev->access_ref);
125 kfree(fh);
126 return ret;
127}
128
129static int aim_vdev_close(struct file *filp)
130{
131 struct aim_fh *fh = filp->private_data;
132 struct most_video_dev *mdev = fh->mdev;
133 struct mbo *mbo, *tmp;
134
135 pr_info("aim_vdev_close()\n");
136
137 /*
138 * We need to put MBOs back before we call most_stop_channel()
139 * to deallocate MBOs.
140 * From the other hand mostcore still calling rx_completion()
141 * to deliver MBOs until most_stop_channel() is called.
142 * Use mute to work around this issue.
143 * This must be implemented in core.
144 */
145
146 spin_lock(&mdev->list_lock);
147 mdev->mute = true;
148 list_for_each_entry_safe(mbo, tmp, &mdev->pending_mbos, list) {
149 list_del(&mbo->list);
150 spin_unlock(&mdev->list_lock);
151 most_put_mbo(mbo);
152 spin_lock(&mdev->list_lock);
153 }
154 spin_unlock(&mdev->list_lock);
155 most_stop_channel(mdev->iface, mdev->ch_idx);
156 mdev->mute = false;
157
158 v4l2_fh_del(&fh->fh);
159 v4l2_fh_exit(&fh->fh);
160
161 atomic_dec(&mdev->access_ref);
162 kfree(fh);
163 return 0;
164}
165
166static ssize_t aim_vdev_read(struct file *filp, char __user *buf,
167 size_t count, loff_t *pos)
168{
169 struct aim_fh *fh = filp->private_data;
170 struct most_video_dev *mdev = fh->mdev;
171 int ret = 0;
172
173 if (*pos)
174 return -ESPIPE;
175
176 if (!mdev)
177 return -ENODEV;
178
179 /* wait for the first buffer */
180 if (!(filp->f_flags & O_NONBLOCK)) {
181 if (wait_event_interruptible(mdev->wait_data, data_ready(mdev)))
182 return -ERESTARTSYS;
183 }
184
185 if (!data_ready(mdev))
186 return -EAGAIN;
187
188 while (count > 0 && data_ready(mdev)) {
189 struct mbo *const mbo = get_top_mbo(mdev);
190 int const rem = mbo->processed_length - fh->offs;
191 int const cnt = rem < count ? rem : count;
192
193 if (copy_to_user(buf, mbo->virt_address + fh->offs, cnt)) {
194 pr_err("read: copy_to_user failed\n");
195 if (!ret)
196 ret = -EFAULT;
197 return ret;
198 }
199
200 fh->offs += cnt;
201 count -= cnt;
202 buf += cnt;
203 ret += cnt;
204
205 if (cnt >= rem) {
206 fh->offs = 0;
207 spin_lock(&mdev->list_lock);
208 list_del(&mbo->list);
209 spin_unlock(&mdev->list_lock);
210 most_put_mbo(mbo);
211 }
212 }
213 return ret;
214}
215
216static unsigned int aim_vdev_poll(struct file *filp, poll_table *wait)
217{
218 struct aim_fh *fh = filp->private_data;
219 struct most_video_dev *mdev = fh->mdev;
220 unsigned int mask = 0;
221
222 /* only wait if no data is available */
223 if (!data_ready(mdev))
224 poll_wait(filp, &mdev->wait_data, wait);
225 if (data_ready(mdev))
226 mask |= POLLIN | POLLRDNORM;
227
228 return mask;
229}
230
231static void aim_set_format_struct(struct v4l2_format *f)
232{
233 f->fmt.pix.width = 8;
234 f->fmt.pix.height = 8;
235 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
236 f->fmt.pix.bytesperline = 0;
237 f->fmt.pix.sizeimage = 188 * 2;
238 f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709;
239 f->fmt.pix.field = V4L2_FIELD_NONE;
240 f->fmt.pix.priv = 0;
241}
242
243static int aim_set_format(struct most_video_dev *mdev, unsigned int cmd,
244 struct v4l2_format *format)
245{
246#if 0
247 u32 const pixfmt = format->fmt.pix.pixelformat;
248 const char *fmt;
249
250 if (pixfmt != V4L2_PIX_FMT_MPEG) {
251 if (cmd == VIDIOC_TRY_FMT)
252 fmt = KERN_ERR "try %c%c%c%c failed\n";
253 else
254 fmt = KERN_ERR "set %c%c%c%c failed\n";
255 } else {
256 if (cmd == VIDIOC_TRY_FMT)
257 fmt = KERN_ERR "try %c%c%c%c\n";
258 else
259 fmt = KERN_ERR "set %c%c%c%c\n";
260 }
261 printk(fmt,
262 (pixfmt) & 255,
263 (pixfmt >> 8) & 255,
264 (pixfmt >> 16) & 255,
265 (pixfmt >> 24) & 255);
266#endif
267
268 if (format->fmt.pix.pixelformat != V4L2_PIX_FMT_MPEG)
269 return -EINVAL;
270
271 if (cmd == VIDIOC_TRY_FMT)
272 return 0;
273
274 aim_set_format_struct(format);
275
276 return 0;
277}
278
279
280static int vidioc_querycap(struct file *file, void *priv,
281 struct v4l2_capability *cap)
282{
283 struct aim_fh *fh = priv;
284 struct most_video_dev *mdev = fh->mdev;
285
286 pr_info("vidioc_querycap()\n");
287
288 strlcpy(cap->driver, "v4l2_most_aim", sizeof(cap->driver));
289 strlcpy(cap->card, "my_card", sizeof(cap->card));
290 snprintf(cap->bus_info, sizeof(cap->bus_info),
291 "%s", mdev->iface->description);
292
293 cap->capabilities =
294 V4L2_CAP_READWRITE |
295 V4L2_CAP_TUNER |
296 V4L2_CAP_VIDEO_CAPTURE;
297 return 0;
298}
299
300static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
301 struct v4l2_fmtdesc *f)
302{
303 pr_info("vidioc_enum_fmt_vid_cap() %d\n", f->index);
304
305 if (f->index)
306 return -EINVAL;
307
308 strcpy(f->description, "MPEG");
309 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
310 f->flags = V4L2_FMT_FLAG_COMPRESSED;
311 f->pixelformat = V4L2_PIX_FMT_MPEG;
312
313 return 0;
314}
315
316static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
317 struct v4l2_format *f)
318{
319 pr_info("vidioc_g_fmt_vid_cap()\n");
320
321 aim_set_format_struct(f);
322 return 0;
323}
324
325static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
326 struct v4l2_format *f)
327{
328 struct aim_fh *fh = priv;
329 struct most_video_dev *mdev = fh->mdev;
330
331 return aim_set_format(mdev, VIDIOC_TRY_FMT, f);
332}
333
334static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
335 struct v4l2_format *f)
336{
337 struct aim_fh *fh = priv;
338 struct most_video_dev *mdev = fh->mdev;
339
340 return aim_set_format(mdev, VIDIOC_S_FMT, f);
341}
342
343static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
344{
345 pr_info("vidioc_g_std()\n");
346
347 *norm = V4L2_STD_UNKNOWN;
348 return 0;
349}
350
351static int vidioc_enum_input(struct file *file, void *priv,
352 struct v4l2_input *input)
353{
354 struct aim_fh *fh = priv;
355 struct most_video_dev *mdev = fh->mdev;
356
357 if (input->index >= V4L2_AIM_MAX_INPUT)
358 return -EINVAL;
359
360 strcpy(input->name, "MOST Video");
361 input->type |= V4L2_INPUT_TYPE_CAMERA;
362 input->audioset = 0;
363
364 input->std = mdev->vdev->tvnorms;
365
366 return 0;
367}
368
369static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
370{
371 struct aim_fh *fh = priv;
372 struct most_video_dev *mdev = fh->mdev;
373 *i = mdev->ctrl_input;
374 return 0;
375}
376
377static int vidioc_s_input(struct file *file, void *priv, unsigned int index)
378{
379 struct aim_fh *fh = priv;
380 struct most_video_dev *mdev = fh->mdev;
381
382 pr_info("vidioc_s_input(%d)\n", index);
383
384 if (index >= V4L2_AIM_MAX_INPUT)
385 return -EINVAL;
386 mdev->ctrl_input = index;
387 return 0;
388}
389
390static struct v4l2_file_operations aim_fops = {
391 .owner = THIS_MODULE,
392 .open = aim_vdev_open,
393 .release = aim_vdev_close,
394 .read = aim_vdev_read,
395 .poll = aim_vdev_poll,
396 .unlocked_ioctl = video_ioctl2,
397};
398
399static const struct v4l2_ioctl_ops video_ioctl_ops = {
400 .vidioc_querycap = vidioc_querycap,
401 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
402 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
403 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
404 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
405 .vidioc_g_std = vidioc_g_std,
406 .vidioc_enum_input = vidioc_enum_input,
407 .vidioc_g_input = vidioc_g_input,
408 .vidioc_s_input = vidioc_s_input,
409};
410
411static const struct video_device aim_videodev_template = {
412 .fops = &aim_fops,
413 .release = video_device_release,
414 .ioctl_ops = &video_ioctl_ops,
415 .tvnorms = V4L2_STD_UNKNOWN,
416};
417
418/**************************************************************************/
419
420static struct most_video_dev *get_aim_dev(
421 struct most_interface *iface, int channel_idx)
422{
423 struct most_video_dev *mdev, *tmp;
424
425 spin_lock(&list_lock);
426 list_for_each_entry_safe(mdev, tmp, &video_devices, list) {
427 if (mdev->iface == iface && mdev->ch_idx == channel_idx) {
428 spin_unlock(&list_lock);
429 return mdev;
430 }
431 }
432 spin_unlock(&list_lock);
433 return 0;
434}
435
436static int aim_rx_data(struct mbo *mbo)
437{
438 struct most_video_dev *mdev =
439 get_aim_dev(mbo->ifp, mbo->hdm_channel_id);
440
441 if (!mdev)
442 return -EIO;
443
444 spin_lock(&mdev->list_lock);
445 if (unlikely(mdev->mute)) {
446 spin_unlock(&mdev->list_lock);
447 return -EIO;
448 }
449
450 list_add_tail(&mbo->list, &mdev->pending_mbos);
451 spin_unlock(&mdev->list_lock);
452 wake_up_interruptible(&mdev->wait_data);
453 return 0;
454}
455
456static int aim_register_videodev(struct most_video_dev *mdev)
457{
458 int retval = -ENOMEM;
459 int ret;
460
461 pr_info("aim_register_videodev()\n");
462
463 init_waitqueue_head(&mdev->wait_data);
464
465 /* allocate and fill v4l2 video struct */
466 mdev->vdev = video_device_alloc();
467 if (!mdev->vdev)
468 return -ENOMEM;
469
470 /* Fill the video capture device struct */
471 *mdev->vdev = aim_videodev_template;
472 mdev->vdev->v4l2_dev = &mdev->v4l2_dev;
473 mdev->vdev->lock = &mdev->lock;
474 strcpy(mdev->vdev->name, "most v4l2 aim video");
475
476 /* Register the v4l2 device */
477 video_set_drvdata(mdev->vdev, mdev);
478 retval = video_register_device(mdev->vdev, VFL_TYPE_GRABBER, -1);
479 if (retval != 0) {
480 pr_err("video_register_device failed (%d)\n", retval);
481 ret = -ENODEV;
482 goto err_vbi_dev;
483 }
484
485 return 0;
486
487err_vbi_dev:
488 video_device_release(mdev->vdev);
489 return ret;
490}
491
492static void aim_unregister_videodev(struct most_video_dev *mdev)
493{
494 pr_info("aim_unregister_videodev()\n");
495
496 video_unregister_device(mdev->vdev);
497}
498
499
500static void aim_v4l2_dev_release(struct v4l2_device *v4l2_dev)
501{
502 struct most_video_dev *mdev =
503 container_of(v4l2_dev, struct most_video_dev, v4l2_dev);
504
505 v4l2_device_unregister(v4l2_dev);
506 kfree(mdev);
507}
508
509static int aim_probe_channel(struct most_interface *iface, int channel_idx,
510 struct most_channel_config *ccfg,
511 struct kobject *parent, char *name)
512{
513 int ret;
514 struct most_video_dev *mdev = get_aim_dev(iface, channel_idx);
515
516 pr_info("aim_probe_channel()\n");
517
518 if (mdev) {
519 pr_err("channel already linked\n");
520 return -EEXIST;
521 }
522
523 if (ccfg->direction != MOST_CH_RX) {
524 pr_err("wrong direction, expect rx\n");
525 return -EINVAL;
526 }
527
528 if (ccfg->data_type != MOST_CH_SYNC &&
529 ccfg->data_type != MOST_CH_ISOC_AVP) {
530 pr_err("wrong channel type, expect sync or isoc_avp\n");
531 return -EINVAL;
532 }
533
534 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
535 if (!mdev)
536 return -ENOMEM;
537
538 mutex_init(&mdev->lock);
539 atomic_set(&mdev->access_ref, -1);
540 spin_lock_init(&mdev->list_lock);
541 INIT_LIST_HEAD(&mdev->pending_mbos);
542 mdev->iface = iface;
543 mdev->ch_idx = channel_idx;
544 mdev->v4l2_dev.release = aim_v4l2_dev_release;
545
546 /* Create the v4l2_device */
547 strlcpy(mdev->v4l2_dev.name, "most_video_device",
548 sizeof(mdev->v4l2_dev.name));
549 ret = v4l2_device_register(NULL, &mdev->v4l2_dev);
550 if (ret) {
551 pr_err("v4l2_device_register() failed\n");
552 kfree(mdev);
553 return ret;
554 }
555
556 ret = aim_register_videodev(mdev);
557 if (ret)
558 goto err_unreg;
559
560 spin_lock(&list_lock);
561 list_add(&mdev->list, &video_devices);
562 spin_unlock(&list_lock);
563 return 0;
564
565err_unreg:
566 v4l2_device_disconnect(&mdev->v4l2_dev);
567 v4l2_device_put(&mdev->v4l2_dev);
568 return ret;
569}
570
571static int aim_disconnect_channel(struct most_interface *iface,
572 int channel_idx)
573{
574 struct most_video_dev *mdev = get_aim_dev(iface, channel_idx);
575
576 pr_info("aim_disconnect_channel()\n");
577
578 if (!mdev) {
579 pr_err("no such channel is linked\n");
580 return -ENOENT;
581 }
582
583 spin_lock(&list_lock);
584 list_del(&mdev->list);
585 spin_unlock(&list_lock);
586
587 aim_unregister_videodev(mdev);
588 v4l2_device_disconnect(&mdev->v4l2_dev);
589 v4l2_device_put(&mdev->v4l2_dev);
590 return 0;
591}
592
593static int __init aim_init(void)
594{
595 spin_lock_init(&list_lock);
596
597 aim_info.name = "v4l";
598 aim_info.probe_channel = aim_probe_channel;
599 aim_info.disconnect_channel = aim_disconnect_channel;
600 aim_info.rx_completion = aim_rx_data;
601 return most_register_aim(&aim_info);
602}
603
604static void __exit aim_exit(void)
605{
606 struct most_video_dev *mdev, *tmp;
607
608 /*
609 * As the mostcore currently doesn't call disconnect_channel()
610 * for linked channels while we call most_deregister_aim()
611 * we simulate this call here.
612 * This must be fixed in core.
613 */
614 spin_lock(&list_lock);
615 list_for_each_entry_safe(mdev, tmp, &video_devices, list) {
616 list_del(&mdev->list);
617 spin_unlock(&list_lock);
618
619 aim_unregister_videodev(mdev);
620 v4l2_device_disconnect(&mdev->v4l2_dev);
621 v4l2_device_put(&mdev->v4l2_dev);
622 spin_lock(&list_lock);
623 }
624 spin_unlock(&list_lock);
625
626 most_deregister_aim(&aim_info);
627 BUG_ON(!list_empty(&video_devices));
628}
629
630module_init(aim_init);
631module_exit(aim_exit);
632
633MODULE_DESCRIPTION("V4L2 Application Interface Module for MostCore");
634MODULE_AUTHOR("Andrey Shvetsov <andrey.shvetsov@k2l.de>");
635MODULE_LICENSE("GPL");
diff --git a/drivers/staging/most/hdm-dim2/Kconfig b/drivers/staging/most/hdm-dim2/Kconfig
new file mode 100644
index 000000000000..1d4ad1d67758
--- /dev/null
+++ b/drivers/staging/most/hdm-dim2/Kconfig
@@ -0,0 +1,16 @@
1#
2# MediaLB configuration
3#
4
5config HDM_DIM2
6 tristate "DIM2 HDM"
7 depends on AIM_NETWORK
8
9 ---help---
10 Say Y here if you want to connect via MediaLB to network transceiver.
11 This device driver is platform dependent and needs an addtional
12 platform driver to be installed. For more information contact
13 maintainer of this driver.
14
15 To compile this driver as a module, choose M here: the
16 module will be called hdm_dim2.
diff --git a/drivers/staging/most/hdm-dim2/Makefile b/drivers/staging/most/hdm-dim2/Makefile
new file mode 100644
index 000000000000..6bbee879a8ea
--- /dev/null
+++ b/drivers/staging/most/hdm-dim2/Makefile
@@ -0,0 +1,5 @@
1obj-$(CONFIG_HDM_DIM2) += hdm_dim2.o
2
3hdm_dim2-objs := dim2_hdm.o dim2_hal.o dim2_sysfs.o
4ccflags-y += -Idrivers/staging/most/mostcore/
5ccflags-y += -Idrivers/staging/most/aim-network/
diff --git a/drivers/staging/most/hdm-dim2/dim2_errors.h b/drivers/staging/most/hdm-dim2/dim2_errors.h
new file mode 100644
index 000000000000..314f7de2be73
--- /dev/null
+++ b/drivers/staging/most/hdm-dim2/dim2_errors.h
@@ -0,0 +1,67 @@
1/*
2 * dim2_errors.h - Definitions of errors for DIM2 HAL API
3 * (MediaLB, Device Interface Macro IP, OS62420)
4 *
5 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * This file is licensed under GPLv2.
13 */
14
15#ifndef _MOST_DIM_ERRORS_H
16#define _MOST_DIM_ERRORS_H
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22
23/**
24 * MOST DIM errors.
25 */
26enum dim_errors_t {
27 /** Not an error */
28 DIM_NO_ERROR = 0,
29
30 /** Bad base address for DIM2 IP */
31 DIM_INIT_ERR_DIM_ADDR = 0x10,
32
33 /**< Bad MediaLB clock */
34 DIM_INIT_ERR_MLB_CLOCK,
35
36 /** Bad channel address */
37 DIM_INIT_ERR_CHANNEL_ADDRESS,
38
39 /** Out of DBR memory */
40 DIM_INIT_ERR_OUT_OF_MEMORY,
41
42 /** DIM API is called while DIM is not initialized successfully */
43 DIM_ERR_DRIVER_NOT_INITIALIZED = 0x20,
44
45 /**
46 * Configuration does not respect hardware limitations
47 * for isochronous or synchronous channels
48 */
49 DIM_ERR_BAD_CONFIG,
50
51 /**
52 * Buffer size does not respect hardware limitations
53 * for isochronous or synchronous channels
54 */
55 DIM_ERR_BAD_BUFFER_SIZE,
56
57 DIM_ERR_UNDERFLOW,
58
59 DIM_ERR_OVERFLOW,
60};
61
62
63#ifdef __cplusplus
64}
65#endif
66
67#endif /* _MOST_DIM_ERRORS_H */
diff --git a/drivers/staging/most/hdm-dim2/dim2_hal.c b/drivers/staging/most/hdm-dim2/dim2_hal.c
new file mode 100644
index 000000000000..a54cf2cedac3
--- /dev/null
+++ b/drivers/staging/most/hdm-dim2/dim2_hal.c
@@ -0,0 +1,919 @@
1/*
2 * dim2_hal.c - DIM2 HAL implementation
3 * (MediaLB, Device Interface Macro IP, OS62420)
4 *
5 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * This file is licensed under GPLv2.
13 */
14
15/* Author: Andrey Shvetsov <andrey.shvetsov@k2l.de> */
16
17#include "dim2_hal.h"
18#include "dim2_errors.h"
19#include "dim2_reg.h"
20#include <linux/stddef.h>
21
22
23/*
24 * The number of frames per sub-buffer for synchronous channels.
25 * Allowed values: 1, 2, 4, 8, 16, 32, 64.
26 */
27#define FRAMES_PER_SUBBUFF 16
28
29/*
30 * Size factor for synchronous DBR buffer.
31 * Minimal value is 4*FRAMES_PER_SUBBUFF.
32 */
33#define SYNC_DBR_FACTOR (4u * (u16)FRAMES_PER_SUBBUFF)
34
35/*
36 * Size factor for isochronous DBR buffer.
37 * Minimal value is 3.
38 */
39#define ISOC_DBR_FACTOR 3u
40
41/*
42 * Number of 32-bit units for DBR map.
43 *
44 * 1: block size is 512, max allocation is 16K
45 * 2: block size is 256, max allocation is 8K
46 * 4: block size is 128, max allocation is 4K
47 * 8: block size is 64, max allocation is 2K
48 *
49 * Min allocated space is block size.
50 * Max possible allocated space is 32 blocks.
51 */
52#define DBR_MAP_SIZE 2
53
54
55/* -------------------------------------------------------------------------- */
56/* not configurable area */
57
58#define CDT 0x00
59#define ADT 0x40
60#define MLB_CAT 0x80
61#define AHB_CAT 0x88
62
63#define DBR_SIZE (16*1024) /* specified by IP */
64#define DBR_BLOCK_SIZE (DBR_SIZE / 32 / DBR_MAP_SIZE)
65
66
67/* -------------------------------------------------------------------------- */
68/* generic helper functions and macros */
69
70#define MLBC0_FCNT_VAL_MACRO(n) MLBC0_FCNT_VAL_ ## n ## FPSB
71#define MLBC0_FCNT_VAL(fpsb) MLBC0_FCNT_VAL_MACRO(fpsb)
72
73static inline u32 bit_mask(u8 position)
74{
75 return (u32)1 << position;
76}
77
78static inline bool dim_on_error(u8 error_id, const char *error_message)
79{
80 DIMCB_OnError(error_id, error_message);
81 return false;
82}
83
84
85/* -------------------------------------------------------------------------- */
86/* types and local variables */
87
88struct lld_global_vars_t {
89 bool dim_is_initialized;
90 bool mcm_is_initialized;
91 struct dim2_regs *dim2; /* DIM2 core base address */
92 u32 dbr_map[DBR_MAP_SIZE];
93};
94
95static struct lld_global_vars_t g = { false };
96
97
98/* -------------------------------------------------------------------------- */
99
100static int dbr_get_mask_size(u16 size)
101{
102 int i;
103
104 for (i = 0; i < 6; i++)
105 if (size <= (DBR_BLOCK_SIZE << i))
106 return 1 << i;
107 return 0;
108}
109
110/**
111 * Allocates DBR memory.
112 * @param size Allocating memory size.
113 * @return Offset in DBR memory by success or DBR_SIZE if out of memory.
114 */
115static int alloc_dbr(u16 size)
116{
117 int mask_size;
118 int i, block_idx = 0;
119
120 if (size <= 0)
121 return DBR_SIZE; /* out of memory */
122
123 mask_size = dbr_get_mask_size(size);
124 if (mask_size == 0)
125 return DBR_SIZE; /* out of memory */
126
127 for (i = 0; i < DBR_MAP_SIZE; i++) {
128 u32 const blocks = (size + DBR_BLOCK_SIZE - 1) / DBR_BLOCK_SIZE;
129 u32 mask = ~((~(u32)0) << blocks);
130
131 do {
132 if ((g.dbr_map[i] & mask) == 0) {
133 g.dbr_map[i] |= mask;
134 return block_idx * DBR_BLOCK_SIZE;
135 }
136 block_idx += mask_size;
137 /* do shift left with 2 steps for case mask_size == 32 */
138 mask <<= mask_size - 1;
139 } while ((mask <<= 1) != 0);
140 }
141
142 return DBR_SIZE; /* out of memory */
143}
144
145static void free_dbr(int offs, int size)
146{
147 int block_idx = offs / DBR_BLOCK_SIZE;
148 u32 const blocks = (size + DBR_BLOCK_SIZE - 1) / DBR_BLOCK_SIZE;
149 u32 mask = ~((~(u32)0) << blocks);
150
151 mask <<= block_idx % 32;
152 g.dbr_map[block_idx / 32] &= ~mask;
153}
154
155/* -------------------------------------------------------------------------- */
156
157static u32 dim2_read_ctr(u32 ctr_addr, u16 mdat_idx)
158{
159 DIMCB_IoWrite(&g.dim2->MADR, ctr_addr);
160
161 /* wait till transfer is completed */
162 while ((DIMCB_IoRead(&g.dim2->MCTL) & 1) != 1)
163 continue;
164
165 DIMCB_IoWrite(&g.dim2->MCTL, 0); /* clear transfer complete */
166
167 return DIMCB_IoRead((&g.dim2->MDAT0) + mdat_idx);
168}
169
170static void dim2_write_ctr_mask(u32 ctr_addr, const u32 *mask, const u32 *value)
171{
172 enum { MADR_WNR_BIT = 31 };
173
174 DIMCB_IoWrite(&g.dim2->MCTL, 0); /* clear transfer complete */
175
176 if (mask[0] != 0)
177 DIMCB_IoWrite(&g.dim2->MDAT0, value[0]);
178 if (mask[1] != 0)
179 DIMCB_IoWrite(&g.dim2->MDAT1, value[1]);
180 if (mask[2] != 0)
181 DIMCB_IoWrite(&g.dim2->MDAT2, value[2]);
182 if (mask[3] != 0)
183 DIMCB_IoWrite(&g.dim2->MDAT3, value[3]);
184
185 DIMCB_IoWrite(&g.dim2->MDWE0, mask[0]);
186 DIMCB_IoWrite(&g.dim2->MDWE1, mask[1]);
187 DIMCB_IoWrite(&g.dim2->MDWE2, mask[2]);
188 DIMCB_IoWrite(&g.dim2->MDWE3, mask[3]);
189
190 DIMCB_IoWrite(&g.dim2->MADR, bit_mask(MADR_WNR_BIT) | ctr_addr);
191
192 /* wait till transfer is completed */
193 while ((DIMCB_IoRead(&g.dim2->MCTL) & 1) != 1)
194 continue;
195
196 DIMCB_IoWrite(&g.dim2->MCTL, 0); /* clear transfer complete */
197}
198
199static inline void dim2_write_ctr(u32 ctr_addr, const u32 *value)
200{
201 u32 const mask[4] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
202
203 dim2_write_ctr_mask(ctr_addr, mask, value);
204}
205
206static inline void dim2_clear_ctr(u32 ctr_addr)
207{
208 u32 const value[4] = { 0, 0, 0, 0 };
209
210 dim2_write_ctr(ctr_addr, value);
211}
212
213static void dim2_configure_cat(u8 cat_base, u8 ch_addr, u8 ch_type,
214 bool read_not_write, bool sync_mfe)
215{
216 u16 const cat =
217 (read_not_write << CAT_RNW_BIT) |
218 (ch_type << CAT_CT_SHIFT) |
219 (ch_addr << CAT_CL_SHIFT) |
220 (sync_mfe << CAT_MFE_BIT) |
221 (false << CAT_MT_BIT) |
222 (true << CAT_CE_BIT);
223 u8 const ctr_addr = cat_base + ch_addr / 8;
224 u8 const idx = (ch_addr % 8) / 2;
225 u8 const shift = (ch_addr % 2) * 16;
226 u32 mask[4] = { 0, 0, 0, 0 };
227 u32 value[4] = { 0, 0, 0, 0 };
228
229 mask[idx] = (u32)0xFFFF << shift;
230 value[idx] = cat << shift;
231 dim2_write_ctr_mask(ctr_addr, mask, value);
232}
233
234static void dim2_clear_cat(u8 cat_base, u8 ch_addr)
235{
236 u8 const ctr_addr = cat_base + ch_addr / 8;
237 u8 const idx = (ch_addr % 8) / 2;
238 u8 const shift = (ch_addr % 2) * 16;
239 u32 mask[4] = { 0, 0, 0, 0 };
240 u32 value[4] = { 0, 0, 0, 0 };
241
242 mask[idx] = (u32)0xFFFF << shift;
243 dim2_write_ctr_mask(ctr_addr, mask, value);
244}
245
246static void dim2_configure_cdt(u8 ch_addr, u16 dbr_address, u16 hw_buffer_size,
247 u16 packet_length)
248{
249 u32 cdt[4] = { 0, 0, 0, 0 };
250
251 if (packet_length)
252 cdt[1] = ((packet_length - 1) << CDT1_BS_ISOC_SHIFT);
253
254 cdt[3] =
255 ((hw_buffer_size - 1) << CDT3_BD_SHIFT) |
256 (dbr_address << CDT3_BA_SHIFT);
257 dim2_write_ctr(CDT + ch_addr, cdt);
258}
259
260static void dim2_clear_cdt(u8 ch_addr)
261{
262 u32 cdt[4] = { 0, 0, 0, 0 };
263
264 dim2_write_ctr(CDT + ch_addr, cdt);
265}
266
267static void dim2_configure_adt(u8 ch_addr)
268{
269 u32 adt[4] = { 0, 0, 0, 0 };
270
271 adt[0] =
272 (true << ADT0_CE_BIT) |
273 (true << ADT0_LE_BIT) |
274 (0 << ADT0_PG_BIT);
275
276 dim2_write_ctr(ADT + ch_addr, adt);
277}
278
279static void dim2_clear_adt(u8 ch_addr)
280{
281 u32 adt[4] = { 0, 0, 0, 0 };
282
283 dim2_write_ctr(ADT + ch_addr, adt);
284}
285
286static void dim2_start_ctrl_async(u8 ch_addr, u8 idx, u32 buf_addr,
287 u16 buffer_size)
288{
289 u8 const shift = idx * 16;
290
291 u32 mask[4] = { 0, 0, 0, 0 };
292 u32 adt[4] = { 0, 0, 0, 0 };
293
294 mask[1] =
295 bit_mask(ADT1_PS_BIT + shift) |
296 bit_mask(ADT1_RDY_BIT + shift) |
297 (ADT1_CTRL_ASYNC_BD_MASK << (ADT1_BD_SHIFT + shift));
298 adt[1] =
299 (true << (ADT1_PS_BIT + shift)) |
300 (true << (ADT1_RDY_BIT + shift)) |
301 ((buffer_size - 1) << (ADT1_BD_SHIFT + shift));
302
303 mask[idx + 2] = 0xFFFFFFFF;
304 adt[idx + 2] = buf_addr;
305
306 dim2_write_ctr_mask(ADT + ch_addr, mask, adt);
307}
308
309static void dim2_start_isoc_sync(u8 ch_addr, u8 idx, u32 buf_addr,
310 u16 buffer_size)
311{
312 u8 const shift = idx * 16;
313
314 u32 mask[4] = { 0, 0, 0, 0 };
315 u32 adt[4] = { 0, 0, 0, 0 };
316
317 mask[1] =
318 bit_mask(ADT1_RDY_BIT + shift) |
319 (ADT1_ISOC_SYNC_BD_MASK << (ADT1_BD_SHIFT + shift));
320 adt[1] =
321 (true << (ADT1_RDY_BIT + shift)) |
322 ((buffer_size - 1) << (ADT1_BD_SHIFT + shift));
323
324 mask[idx + 2] = 0xFFFFFFFF;
325 adt[idx + 2] = buf_addr;
326
327 dim2_write_ctr_mask(ADT + ch_addr, mask, adt);
328}
329
330
331static void dim2_clear_ctram(void)
332{
333 u32 ctr_addr;
334
335 for (ctr_addr = 0; ctr_addr < 0x90; ctr_addr++)
336 dim2_clear_ctr(ctr_addr);
337}
338
339static void dim2_configure_channel(
340 u8 ch_addr, u8 type, u8 is_tx, u16 dbr_address, u16 hw_buffer_size,
341 u16 packet_length, bool sync_mfe)
342{
343 dim2_configure_cdt(ch_addr, dbr_address, hw_buffer_size, packet_length);
344 dim2_configure_cat(MLB_CAT, ch_addr, type, is_tx ? 1 : 0, sync_mfe);
345
346 dim2_configure_adt(ch_addr);
347 dim2_configure_cat(AHB_CAT, ch_addr, type, is_tx ? 0 : 1, sync_mfe);
348
349 /* unmask interrupt for used channel, enable mlb_sys_int[0] interrupt */
350 DIMCB_IoWrite(&g.dim2->ACMR0,
351 DIMCB_IoRead(&g.dim2->ACMR0) | bit_mask(ch_addr));
352}
353
354static void dim2_clear_channel(u8 ch_addr)
355{
356 /* mask interrupt for used channel, disable mlb_sys_int[0] interrupt */
357 DIMCB_IoWrite(&g.dim2->ACMR0,
358 DIMCB_IoRead(&g.dim2->ACMR0) & ~bit_mask(ch_addr));
359
360 dim2_clear_cat(AHB_CAT, ch_addr);
361 dim2_clear_adt(ch_addr);
362
363 dim2_clear_cat(MLB_CAT, ch_addr);
364 dim2_clear_cdt(ch_addr);
365}
366
367/* -------------------------------------------------------------------------- */
368/* channel state helpers */
369
370static void state_init(struct int_ch_state *state)
371{
372 state->request_counter = 0;
373 state->service_counter = 0;
374
375 state->idx1 = 0;
376 state->idx2 = 0;
377 state->level = 0;
378}
379
380/* -------------------------------------------------------------------------- */
381/* macro helper functions */
382
383static inline bool check_channel_address(u32 ch_address)
384{
385 return ch_address > 0 && (ch_address % 2) == 0 &&
386 (ch_address / 2) <= (u32)CAT_CL_MASK;
387}
388
389static inline bool check_packet_length(u32 packet_length)
390{
391 u16 const max_size = ((u16)CDT3_BD_ISOC_MASK + 1u) / ISOC_DBR_FACTOR;
392
393 if (packet_length <= 0)
394 return false; /* too small */
395
396 if (packet_length > max_size)
397 return false; /* too big */
398
399 if (packet_length - 1u > (u32)CDT1_BS_ISOC_MASK)
400 return false; /* too big */
401
402 return true;
403}
404
405static inline bool check_bytes_per_frame(u32 bytes_per_frame)
406{
407 u16 const max_size = ((u16)CDT3_BD_MASK + 1u) / SYNC_DBR_FACTOR;
408
409 if (bytes_per_frame <= 0)
410 return false; /* too small */
411
412 if (bytes_per_frame > max_size)
413 return false; /* too big */
414
415 return true;
416}
417
418static inline u16 norm_ctrl_async_buffer_size(u16 buf_size)
419{
420 u16 const max_size = (u16)ADT1_CTRL_ASYNC_BD_MASK + 1u;
421
422 if (buf_size > max_size)
423 return max_size;
424
425 return buf_size;
426}
427
428static inline u16 norm_isoc_buffer_size(u16 buf_size, u16 packet_length)
429{
430 u16 n;
431 u16 const max_size = (u16)ADT1_ISOC_SYNC_BD_MASK + 1u;
432
433 if (buf_size > max_size)
434 buf_size = max_size;
435
436 n = buf_size / packet_length;
437
438 if (n < 2u)
439 return 0; /* too small buffer for given packet_length */
440
441 return packet_length * n;
442}
443
444static inline u16 norm_sync_buffer_size(u16 buf_size, u16 bytes_per_frame)
445{
446 u16 n;
447 u16 const max_size = (u16)ADT1_ISOC_SYNC_BD_MASK + 1u;
448 u32 const unit = bytes_per_frame * (u16)FRAMES_PER_SUBBUFF;
449
450 if (buf_size > max_size)
451 buf_size = max_size;
452
453 n = buf_size / unit;
454
455 if (n < 1u)
456 return 0; /* too small buffer for given bytes_per_frame */
457
458 return unit * n;
459}
460
461static void dim2_cleanup(void)
462{
463 /* disable MediaLB */
464 DIMCB_IoWrite(&g.dim2->MLBC0, false << MLBC0_MLBEN_BIT);
465
466 dim2_clear_ctram();
467
468 /* disable mlb_int interrupt */
469 DIMCB_IoWrite(&g.dim2->MIEN, 0);
470
471 /* clear status for all dma channels */
472 DIMCB_IoWrite(&g.dim2->ACSR0, 0xFFFFFFFF);
473 DIMCB_IoWrite(&g.dim2->ACSR1, 0xFFFFFFFF);
474
475 /* mask interrupts for all channels */
476 DIMCB_IoWrite(&g.dim2->ACMR0, 0);
477 DIMCB_IoWrite(&g.dim2->ACMR1, 0);
478}
479
480static void dim2_initialize(bool enable_6pin, u8 mlb_clock)
481{
482 dim2_cleanup();
483
484 /* configure and enable MediaLB */
485 DIMCB_IoWrite(&g.dim2->MLBC0,
486 enable_6pin << MLBC0_MLBPEN_BIT |
487 mlb_clock << MLBC0_MLBCLK_SHIFT |
488 MLBC0_FCNT_VAL(FRAMES_PER_SUBBUFF) << MLBC0_FCNT_SHIFT |
489 true << MLBC0_MLBEN_BIT);
490
491 /* activate all HBI channels */
492 DIMCB_IoWrite(&g.dim2->HCMR0, 0xFFFFFFFF);
493 DIMCB_IoWrite(&g.dim2->HCMR1, 0xFFFFFFFF);
494
495 /* enable HBI */
496 DIMCB_IoWrite(&g.dim2->HCTL, bit_mask(HCTL_EN_BIT));
497
498 /* configure DMA */
499 DIMCB_IoWrite(&g.dim2->ACTL,
500 ACTL_DMA_MODE_VAL_DMA_MODE_1 << ACTL_DMA_MODE_BIT |
501 true << ACTL_SCE_BIT);
502
503#if 0
504 DIMCB_IoWrite(&g.dim2->MIEN,
505 bit_mask(MIEN_CTX_BREAK_BIT) |
506 bit_mask(MIEN_CTX_PE_BIT) |
507 bit_mask(MIEN_CTX_DONE_BIT) |
508 bit_mask(MIEN_CRX_BREAK_BIT) |
509 bit_mask(MIEN_CRX_PE_BIT) |
510 bit_mask(MIEN_CRX_DONE_BIT) |
511 bit_mask(MIEN_ATX_BREAK_BIT) |
512 bit_mask(MIEN_ATX_PE_BIT) |
513 bit_mask(MIEN_ATX_DONE_BIT) |
514 bit_mask(MIEN_ARX_BREAK_BIT) |
515 bit_mask(MIEN_ARX_PE_BIT) |
516 bit_mask(MIEN_ARX_DONE_BIT));
517#endif
518}
519
520static bool dim2_is_mlb_locked(void)
521{
522 u32 const mask0 = bit_mask(MLBC0_MLBLK_BIT);
523 u32 const mask1 = bit_mask(MLBC1_CLKMERR_BIT) |
524 bit_mask(MLBC1_LOCKERR_BIT);
525 u32 const c1 = DIMCB_IoRead(&g.dim2->MLBC1);
526 u32 const nda_mask = (u32)MLBC1_NDA_MASK << MLBC1_NDA_SHIFT;
527
528 DIMCB_IoWrite(&g.dim2->MLBC1, c1 & nda_mask);
529 return (DIMCB_IoRead(&g.dim2->MLBC1) & mask1) == 0 &&
530 (DIMCB_IoRead(&g.dim2->MLBC0) & mask0) != 0;
531}
532
533
534/* -------------------------------------------------------------------------- */
535/* channel help routines */
536
537static inline bool service_channel(u8 ch_addr, u8 idx)
538{
539 u8 const shift = idx * 16;
540 u32 const adt1 = dim2_read_ctr(ADT + ch_addr, 1);
541
542 if (((adt1 >> (ADT1_DNE_BIT + shift)) & 1) == 0)
543 return false;
544
545 {
546 u32 mask[4] = { 0, 0, 0, 0 };
547 u32 adt_w[4] = { 0, 0, 0, 0 };
548
549 mask[1] =
550 bit_mask(ADT1_DNE_BIT + shift) |
551 bit_mask(ADT1_ERR_BIT + shift) |
552 bit_mask(ADT1_RDY_BIT + shift);
553 dim2_write_ctr_mask(ADT + ch_addr, mask, adt_w);
554 }
555
556 /* clear channel status bit */
557 DIMCB_IoWrite(&g.dim2->ACSR0, bit_mask(ch_addr));
558
559 return true;
560}
561
562
563/* -------------------------------------------------------------------------- */
564/* channel init routines */
565
566static void isoc_init(struct dim_channel *ch, u8 ch_addr, u16 packet_length)
567{
568 state_init(&ch->state);
569
570 ch->addr = ch_addr;
571
572 ch->packet_length = packet_length;
573 ch->bytes_per_frame = 0;
574 ch->done_sw_buffers_number = 0;
575}
576
577static void sync_init(struct dim_channel *ch, u8 ch_addr, u16 bytes_per_frame)
578{
579 state_init(&ch->state);
580
581 ch->addr = ch_addr;
582
583 ch->packet_length = 0;
584 ch->bytes_per_frame = bytes_per_frame;
585 ch->done_sw_buffers_number = 0;
586}
587
588static void channel_init(struct dim_channel *ch, u8 ch_addr)
589{
590 state_init(&ch->state);
591
592 ch->addr = ch_addr;
593
594 ch->packet_length = 0;
595 ch->bytes_per_frame = 0;
596 ch->done_sw_buffers_number = 0;
597}
598
599/* returns true if channel interrupt state is cleared */
600static bool channel_service_interrupt(struct dim_channel *ch)
601{
602 struct int_ch_state *const state = &ch->state;
603
604 if (!service_channel(ch->addr, state->idx2))
605 return false;
606
607 state->idx2 ^= 1;
608 state->request_counter++;
609 return true;
610}
611
612static bool channel_start(struct dim_channel *ch, u32 buf_addr, u16 buf_size)
613{
614 struct int_ch_state *const state = &ch->state;
615
616 if (buf_size <= 0)
617 return dim_on_error(DIM_ERR_BAD_BUFFER_SIZE, "Bad buffer size");
618
619 if (ch->packet_length == 0 && ch->bytes_per_frame == 0 &&
620 buf_size != norm_ctrl_async_buffer_size(buf_size))
621 return dim_on_error(DIM_ERR_BAD_BUFFER_SIZE,
622 "Bad control/async buffer size");
623
624 if (ch->packet_length &&
625 buf_size != norm_isoc_buffer_size(buf_size, ch->packet_length))
626 return dim_on_error(DIM_ERR_BAD_BUFFER_SIZE,
627 "Bad isochronous buffer size");
628
629 if (ch->bytes_per_frame &&
630 buf_size != norm_sync_buffer_size(buf_size, ch->bytes_per_frame))
631 return dim_on_error(DIM_ERR_BAD_BUFFER_SIZE,
632 "Bad synchronous buffer size");
633
634 if (state->level >= 2u)
635 return dim_on_error(DIM_ERR_OVERFLOW, "Channel overflow");
636
637 ++state->level;
638
639 if (ch->packet_length || ch->bytes_per_frame)
640 dim2_start_isoc_sync(ch->addr, state->idx1, buf_addr, buf_size);
641 else
642 dim2_start_ctrl_async(ch->addr, state->idx1, buf_addr, buf_size);
643 state->idx1 ^= 1;
644
645 return true;
646}
647
648static u8 channel_service(struct dim_channel *ch)
649{
650 struct int_ch_state *const state = &ch->state;
651
652 if (state->service_counter != state->request_counter) {
653 state->service_counter++;
654 if (state->level == 0)
655 return DIM_ERR_UNDERFLOW;
656
657 --state->level;
658 ch->done_sw_buffers_number++;
659 }
660
661 return DIM_NO_ERROR;
662}
663
664static bool channel_detach_buffers(struct dim_channel *ch, u16 buffers_number)
665{
666 if (buffers_number > ch->done_sw_buffers_number)
667 return dim_on_error(DIM_ERR_UNDERFLOW, "Channel underflow");
668
669 ch->done_sw_buffers_number -= buffers_number;
670 return true;
671}
672
673
674/* -------------------------------------------------------------------------- */
675/* API */
676
677u8 DIM_Startup(void *dim_base_address, u32 mlb_clock)
678{
679 g.dim_is_initialized = false;
680
681 if (!dim_base_address)
682 return DIM_INIT_ERR_DIM_ADDR;
683
684 /* MediaLB clock: 0 - 256 fs, 1 - 512 fs, 2 - 1024 fs, 3 - 2048 fs */
685 /* MediaLB clock: 4 - 3072 fs, 5 - 4096 fs, 6 - 6144 fs, 7 - 8192 fs */
686 if (mlb_clock >= 8)
687 return DIM_INIT_ERR_MLB_CLOCK;
688
689 g.dim2 = dim_base_address;
690 g.dbr_map[0] = g.dbr_map[1] = 0;
691
692 dim2_initialize(mlb_clock >= 3, mlb_clock);
693
694 g.dim_is_initialized = true;
695
696 return DIM_NO_ERROR;
697}
698
699void DIM_Shutdown(void)
700{
701 g.dim_is_initialized = false;
702 dim2_cleanup();
703}
704
705bool DIM_GetLockState(void)
706{
707 return dim2_is_mlb_locked();
708}
709
710static u8 init_ctrl_async(struct dim_channel *ch, u8 type, u8 is_tx,
711 u16 ch_address, u16 hw_buffer_size)
712{
713 if (!g.dim_is_initialized || !ch)
714 return DIM_ERR_DRIVER_NOT_INITIALIZED;
715
716 if (!check_channel_address(ch_address))
717 return DIM_INIT_ERR_CHANNEL_ADDRESS;
718
719 ch->dbr_size = hw_buffer_size;
720 ch->dbr_addr = alloc_dbr(ch->dbr_size);
721 if (ch->dbr_addr >= DBR_SIZE)
722 return DIM_INIT_ERR_OUT_OF_MEMORY;
723
724 channel_init(ch, ch_address / 2);
725
726 dim2_configure_channel(ch->addr, type, is_tx,
727 ch->dbr_addr, ch->dbr_size, 0, false);
728
729 return DIM_NO_ERROR;
730}
731
732u16 DIM_NormCtrlAsyncBufferSize(u16 buf_size)
733{
734 return norm_ctrl_async_buffer_size(buf_size);
735}
736
737/**
738 * Retrieves maximal possible correct buffer size for isochronous data type
739 * conform to given packet length and not bigger than given buffer size.
740 *
741 * Returns non-zero correct buffer size or zero by error.
742 */
743u16 DIM_NormIsocBufferSize(u16 buf_size, u16 packet_length)
744{
745 if (!check_packet_length(packet_length))
746 return 0;
747
748 return norm_isoc_buffer_size(buf_size, packet_length);
749}
750
751/**
752 * Retrieves maximal possible correct buffer size for synchronous data type
753 * conform to given bytes per frame and not bigger than given buffer size.
754 *
755 * Returns non-zero correct buffer size or zero by error.
756 */
757u16 DIM_NormSyncBufferSize(u16 buf_size, u16 bytes_per_frame)
758{
759 if (!check_bytes_per_frame(bytes_per_frame))
760 return 0;
761
762 return norm_sync_buffer_size(buf_size, bytes_per_frame);
763}
764
765u8 DIM_InitControl(struct dim_channel *ch, u8 is_tx, u16 ch_address,
766 u16 max_buffer_size)
767{
768 return init_ctrl_async(ch, CAT_CT_VAL_CONTROL, is_tx, ch_address,
769 max_buffer_size * 2);
770}
771
772u8 DIM_InitAsync(struct dim_channel *ch, u8 is_tx, u16 ch_address,
773 u16 max_buffer_size)
774{
775 return init_ctrl_async(ch, CAT_CT_VAL_ASYNC, is_tx, ch_address,
776 max_buffer_size * 2);
777}
778
779u8 DIM_InitIsoc(struct dim_channel *ch, u8 is_tx, u16 ch_address,
780 u16 packet_length)
781{
782 if (!g.dim_is_initialized || !ch)
783 return DIM_ERR_DRIVER_NOT_INITIALIZED;
784
785 if (!check_channel_address(ch_address))
786 return DIM_INIT_ERR_CHANNEL_ADDRESS;
787
788 if (!check_packet_length(packet_length))
789 return DIM_ERR_BAD_CONFIG;
790
791 ch->dbr_size = packet_length * ISOC_DBR_FACTOR;
792 ch->dbr_addr = alloc_dbr(ch->dbr_size);
793 if (ch->dbr_addr >= DBR_SIZE)
794 return DIM_INIT_ERR_OUT_OF_MEMORY;
795
796 isoc_init(ch, ch_address / 2, packet_length);
797
798 dim2_configure_channel(ch->addr, CAT_CT_VAL_ISOC, is_tx, ch->dbr_addr,
799 ch->dbr_size, packet_length, false);
800
801 return DIM_NO_ERROR;
802}
803
804u8 DIM_InitSync(struct dim_channel *ch, u8 is_tx, u16 ch_address,
805 u16 bytes_per_frame)
806{
807 if (!g.dim_is_initialized || !ch)
808 return DIM_ERR_DRIVER_NOT_INITIALIZED;
809
810 if (!check_channel_address(ch_address))
811 return DIM_INIT_ERR_CHANNEL_ADDRESS;
812
813 if (!check_bytes_per_frame(bytes_per_frame))
814 return DIM_ERR_BAD_CONFIG;
815
816 ch->dbr_size = bytes_per_frame * SYNC_DBR_FACTOR;
817 ch->dbr_addr = alloc_dbr(ch->dbr_size);
818 if (ch->dbr_addr >= DBR_SIZE)
819 return DIM_INIT_ERR_OUT_OF_MEMORY;
820
821 sync_init(ch, ch_address / 2, bytes_per_frame);
822
823 dim2_configure_channel(ch->addr, CAT_CT_VAL_SYNC, is_tx,
824 ch->dbr_addr, ch->dbr_size, 0, true);
825
826 return DIM_NO_ERROR;
827}
828
829u8 DIM_DestroyChannel(struct dim_channel *ch)
830{
831 if (!g.dim_is_initialized || !ch)
832 return DIM_ERR_DRIVER_NOT_INITIALIZED;
833
834 dim2_clear_channel(ch->addr);
835 if (ch->dbr_addr < DBR_SIZE)
836 free_dbr(ch->dbr_addr, ch->dbr_size);
837 ch->dbr_addr = DBR_SIZE;
838
839 return DIM_NO_ERROR;
840}
841
842void DIM_ServiceIrq(struct dim_channel *const *channels)
843{
844 bool state_changed;
845
846 if (!g.dim_is_initialized) {
847 dim_on_error(DIM_ERR_DRIVER_NOT_INITIALIZED,
848 "DIM is not initialized");
849 return;
850 }
851
852 if (!channels) {
853 dim_on_error(DIM_ERR_DRIVER_NOT_INITIALIZED, "Bad channels");
854 return;
855 }
856
857 /*
858 * Use while-loop and a flag to make sure the age is changed back at least once,
859 * otherwise the interrupt may never come if CPU generates interrupt on changing age.
860 *
861 * This cycle runs not more than number of channels, because service_interrupts
862 * routine doesn't start the channel again.
863 */
864 do {
865 struct dim_channel *const *ch = channels;
866
867 state_changed = false;
868
869 while (*ch) {
870 state_changed |= channel_service_interrupt(*ch);
871 ++ch;
872 }
873 } while (state_changed);
874
875 /* clear pending Interrupts */
876 DIMCB_IoWrite(&g.dim2->MS0, 0);
877 DIMCB_IoWrite(&g.dim2->MS1, 0);
878}
879
880u8 DIM_ServiceChannel(struct dim_channel *ch)
881{
882 if (!g.dim_is_initialized || !ch)
883 return DIM_ERR_DRIVER_NOT_INITIALIZED;
884
885 return channel_service(ch);
886}
887
888struct dim_ch_state_t *DIM_GetChannelState(struct dim_channel *ch,
889 struct dim_ch_state_t *state_ptr)
890{
891 if (!ch || !state_ptr)
892 return NULL;
893
894 state_ptr->ready = ch->state.level < 2;
895 state_ptr->done_buffers = ch->done_sw_buffers_number;
896
897 return state_ptr;
898}
899
900bool DIM_EnqueueBuffer(struct dim_channel *ch, u32 buffer_addr, u16 buffer_size)
901{
902 if (!ch)
903 return dim_on_error(DIM_ERR_DRIVER_NOT_INITIALIZED, "Bad channel");
904
905 return channel_start(ch, buffer_addr, buffer_size);
906}
907
908bool DIM_DetachBuffers(struct dim_channel *ch, u16 buffers_number)
909{
910 if (!ch)
911 return dim_on_error(DIM_ERR_DRIVER_NOT_INITIALIZED, "Bad channel");
912
913 return channel_detach_buffers(ch, buffers_number);
914}
915
916u32 DIM_ReadRegister(u8 register_index)
917{
918 return DIMCB_IoRead((u32 *)g.dim2 + register_index);
919}
diff --git a/drivers/staging/most/hdm-dim2/dim2_hal.h b/drivers/staging/most/hdm-dim2/dim2_hal.h
new file mode 100644
index 000000000000..8929af9712ef
--- /dev/null
+++ b/drivers/staging/most/hdm-dim2/dim2_hal.h
@@ -0,0 +1,124 @@
1/*
2 * dim2_hal.h - DIM2 HAL interface
3 * (MediaLB, Device Interface Macro IP, OS62420)
4 *
5 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * This file is licensed under GPLv2.
13 */
14
15#ifndef _DIM2_HAL_H
16#define _DIM2_HAL_H
17
18#include <linux/types.h>
19
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/*
26 * The values below are specified in the hardware specification.
27 * So, they should not be changed until the hardware specification changes.
28 */
29enum mlb_clk_speed {
30 CLK_256FS = 0,
31 CLK_512FS = 1,
32 CLK_1024FS = 2,
33 CLK_2048FS = 3,
34 CLK_3072FS = 4,
35 CLK_4096FS = 5,
36 CLK_6144FS = 6,
37 CLK_8192FS = 7,
38};
39
40struct dim_ch_state_t {
41 bool ready; /* Shows readiness to enqueue next buffer */
42 u16 done_buffers; /* Number of completed buffers */
43};
44
45typedef int atomic_counter_t;
46
47struct int_ch_state {
48 /* changed only in interrupt context */
49 volatile atomic_counter_t request_counter;
50
51 /* changed only in task context */
52 volatile atomic_counter_t service_counter;
53
54 u8 idx1;
55 u8 idx2;
56 u8 level; /* [0..2], buffering level */
57};
58
59struct dim_channel {
60 struct int_ch_state state;
61 u8 addr;
62 u16 dbr_addr;
63 u16 dbr_size;
64 u16 packet_length; /*< Isochronous packet length in bytes. */
65 u16 bytes_per_frame; /*< Synchronous bytes per frame. */
66 u16 done_sw_buffers_number; /*< Done software buffers number. */
67};
68
69
70u8 DIM_Startup(void *dim_base_address, u32 mlb_clock);
71
72void DIM_Shutdown(void);
73
74bool DIM_GetLockState(void);
75
76u16 DIM_NormCtrlAsyncBufferSize(u16 buf_size);
77
78u16 DIM_NormIsocBufferSize(u16 buf_size, u16 packet_length);
79
80u16 DIM_NormSyncBufferSize(u16 buf_size, u16 bytes_per_frame);
81
82u8 DIM_InitControl(struct dim_channel *ch, u8 is_tx, u16 ch_address,
83 u16 max_buffer_size);
84
85u8 DIM_InitAsync(struct dim_channel *ch, u8 is_tx, u16 ch_address,
86 u16 max_buffer_size);
87
88u8 DIM_InitIsoc(struct dim_channel *ch, u8 is_tx, u16 ch_address,
89 u16 packet_length);
90
91u8 DIM_InitSync(struct dim_channel *ch, u8 is_tx, u16 ch_address,
92 u16 bytes_per_frame);
93
94u8 DIM_DestroyChannel(struct dim_channel *ch);
95
96void DIM_ServiceIrq(struct dim_channel *const *channels);
97
98u8 DIM_ServiceChannel(struct dim_channel *ch);
99
100struct dim_ch_state_t *DIM_GetChannelState(struct dim_channel *ch,
101 struct dim_ch_state_t *dim_ch_state_ptr);
102
103bool DIM_EnqueueBuffer(struct dim_channel *ch, u32 buffer_addr,
104 u16 buffer_size);
105
106bool DIM_DetachBuffers(struct dim_channel *ch, u16 buffers_number);
107
108u32 DIM_ReadRegister(u8 register_index);
109
110
111u32 DIMCB_IoRead(u32 *ptr32);
112
113void DIMCB_IoWrite(u32 *ptr32, u32 value);
114
115void DIMCB_OnError(u8 error_id, const char *error_message);
116
117void DIMCB_OnFail(const char *filename, int linenum);
118
119
120#ifdef __cplusplus
121}
122#endif
123
124#endif /* _DIM2_HAL_H */
diff --git a/drivers/staging/most/hdm-dim2/dim2_hdm.c b/drivers/staging/most/hdm-dim2/dim2_hdm.c
new file mode 100644
index 000000000000..6a5a3a2775f3
--- /dev/null
+++ b/drivers/staging/most/hdm-dim2/dim2_hdm.c
@@ -0,0 +1,964 @@
1/*
2 * dim2_hdm.c - MediaLB DIM2 Hardware Dependent Module
3 *
4 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * This file is licensed under GPLv2.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
16#include <linux/module.h>
17#include <linux/printk.h>
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/platform_device.h>
21#include <linux/interrupt.h>
22#include <linux/slab.h>
23#include <linux/io.h>
24#include <linux/dma-mapping.h>
25#include <linux/sched.h>
26#include <linux/kthread.h>
27
28#include <mostcore.h>
29#include <networking.h>
30#include "dim2_hal.h"
31#include "dim2_hdm.h"
32#include "dim2_errors.h"
33#include "dim2_sysfs.h"
34
35#define DMA_CHANNELS (32 - 1) /* channel 0 is a system channel */
36
37#define MAX_BUFFERS_PACKET 32
38#define MAX_BUFFERS_STREAMING 32
39#define MAX_BUF_SIZE_PACKET 2048
40#define MAX_BUF_SIZE_STREAMING (8*1024)
41
42/* command line parameter to select clock speed */
43static char *clock_speed;
44module_param(clock_speed, charp, 0);
45MODULE_PARM_DESC(clock_speed, "MediaLB Clock Speed");
46
47/*
48 * #############################################################################
49 *
50 * The define below activates an utility function used by HAL-simu
51 * for calling DIM interrupt handler.
52 * It is used only for TEST PURPOSE and shall be commented before release.
53 *
54 * #############################################################################
55 */
56/* #define ENABLE_HDM_TEST */
57
58static DEFINE_SPINLOCK(dim_lock);
59
60static void dim2_tasklet_fn(unsigned long data);
61static DECLARE_TASKLET(dim2_tasklet, dim2_tasklet_fn, 0);
62
63/**
64 * struct hdm_channel - private structure to keep channel specific data
65 * @is_initialized: identifier to know whether the channel is initialized
66 * @ch: HAL specific channel data
67 * @pending_list: list to keep MBO's before starting transfer
68 * @started_list: list to keep MBO's after starting transfer
69 * @direction: channel direction (TX or RX)
70 * @data_type: channel data type
71 */
72struct hdm_channel {
73 char name[sizeof "caNNN"];
74 bool is_initialized;
75 struct dim_channel ch;
76 struct list_head pending_list; /* before DIM_EnqueueBuffer() */
77 struct list_head started_list; /* after DIM_EnqueueBuffer() */
78 enum most_channel_direction direction;
79 enum most_channel_data_type data_type;
80};
81
82/**
83 * struct dim2_hdm - private structure to keep interface specific data
84 * @hch: an array of channel specific data
85 * @most_iface: most interface structure
86 * @capabilities: an array of channel capability data
87 * @io_base: I/O register base address
88 * @irq_ahb0: dim2 AHB0 irq number
89 * @clk_speed: user selectable (through command line parameter) clock speed
90 * @netinfo_task: thread to deliver network status
91 * @netinfo_waitq: waitq for the thread to sleep
92 * @deliver_netinfo: to identify whether network status received
93 * @mac_addrs: INIC mac address
94 * @link_state: network link state
95 * @atx_idx: index of async tx channel
96 */
97struct dim2_hdm {
98 struct hdm_channel hch[DMA_CHANNELS];
99 struct most_channel_capability capabilities[DMA_CHANNELS];
100 struct most_interface most_iface;
101 char name[16 + sizeof "dim2-"];
102 void *io_base;
103 unsigned int irq_ahb0;
104 int clk_speed;
105 struct task_struct *netinfo_task;
106 wait_queue_head_t netinfo_waitq;
107 int deliver_netinfo;
108 unsigned char mac_addrs[6];
109 unsigned char link_state;
110 int atx_idx;
111 struct medialb_bus bus;
112};
113
114#define iface_to_hdm(iface) container_of(iface, struct dim2_hdm, most_iface)
115
116/* Macro to identify a network status message */
117#define PACKET_IS_NET_INFO(p) \
118 (((p)[1] == 0x18) && ((p)[2] == 0x05) && ((p)[3] == 0x0C) && \
119 ((p)[13] == 0x3C) && ((p)[14] == 0x00) && ((p)[15] == 0x0A))
120
121#if defined(ENABLE_HDM_TEST)
122static struct dim2_hdm *test_dev;
123#endif
124
125bool dim2_sysfs_get_state_cb(void)
126{
127 bool state;
128 unsigned long flags;
129
130 spin_lock_irqsave(&dim_lock, flags);
131 state = DIM_GetLockState();
132 spin_unlock_irqrestore(&dim_lock, flags);
133
134 return state;
135}
136
137/**
138 * DIMCB_IoRead - callback from HAL to read an I/O register
139 * @ptr32: register address
140 */
141u32 DIMCB_IoRead(u32 *ptr32)
142{
143 return __raw_readl(ptr32);
144}
145
146/**
147 * DIMCB_IoWrite - callback from HAL to write value to an I/O register
148 * @ptr32: register address
149 * @value: value to write
150 */
151void DIMCB_IoWrite(u32 *ptr32, u32 value)
152{
153 __raw_writel(value, ptr32);
154}
155
156/**
157 * DIMCB_OnError - callback from HAL to report miscommunication between
158 * HDM and HAL
159 * @error_id: Error ID
160 * @error_message: Error message. Some text in a free format
161 */
162void DIMCB_OnError(u8 error_id, const char *error_message)
163{
164 pr_err("DIMCB_OnError: error_id - %d, error_message - %s\n", error_id,
165 error_message);
166}
167
168/**
169 * DIMCB_OnFail - callback from HAL to report unrecoverable errors
170 * @filename: Source file where the error happened
171 * @linenum: Line number of the file where the error happened
172 */
173void DIMCB_OnFail(const char *filename, int linenum)
174{
175 pr_err("DIMCB_OnFail: file - %s, line no. - %d\n", filename, linenum);
176}
177
178/**
179 * startup_dim - initialize the dim2 interface
180 * @pdev: platform device
181 *
182 * Get the value of command line parameter "clock_speed" if given or use the
183 * default value, enable the clock and PLL, and initialize the dim2 interface.
184 */
185static int startup_dim(struct platform_device *pdev)
186{
187 struct dim2_hdm *dev = platform_get_drvdata(pdev);
188 struct dim2_platform_data *pdata = pdev->dev.platform_data;
189 u8 hal_ret;
190
191 dev->clk_speed = -1;
192
193 if (clock_speed) {
194 if (!strcmp(clock_speed, "256fs"))
195 dev->clk_speed = CLK_256FS;
196 else if (!strcmp(clock_speed, "512fs"))
197 dev->clk_speed = CLK_512FS;
198 else if (!strcmp(clock_speed, "1024fs"))
199 dev->clk_speed = CLK_1024FS;
200 else if (!strcmp(clock_speed, "2048fs"))
201 dev->clk_speed = CLK_2048FS;
202 else if (!strcmp(clock_speed, "3072fs"))
203 dev->clk_speed = CLK_3072FS;
204 else if (!strcmp(clock_speed, "4096fs"))
205 dev->clk_speed = CLK_4096FS;
206 else if (!strcmp(clock_speed, "6144fs"))
207 dev->clk_speed = CLK_6144FS;
208 else if (!strcmp(clock_speed, "8192fs"))
209 dev->clk_speed = CLK_8192FS;
210 }
211
212 if (dev->clk_speed == -1) {
213 pr_info("Bad or missing clock speed parameter,"
214 " using default value: 3072fs\n");
215 dev->clk_speed = CLK_3072FS;
216 } else
217 pr_info("Selected clock speed: %s\n", clock_speed);
218
219 if (pdata && pdata->init) {
220 int ret = pdata->init(pdata, dev->io_base, dev->clk_speed);
221
222 if (ret)
223 return ret;
224 }
225
226 hal_ret = DIM_Startup(dev->io_base, dev->clk_speed);
227 if (hal_ret != DIM_NO_ERROR) {
228 pr_err("DIM_Startup failed: %d\n", hal_ret);
229 if (pdata && pdata->destroy)
230 pdata->destroy(pdata);
231 return -ENODEV;
232 }
233
234 return 0;
235}
236
237/**
238 * try_start_dim_transfer - try to transfer a buffer on a channel
239 * @hdm_ch: channel specific data
240 *
241 * Transfer a buffer from pending_list if the channel is ready
242 */
243static int try_start_dim_transfer(struct hdm_channel *hdm_ch)
244{
245 u16 buf_size;
246 struct list_head *head = &hdm_ch->pending_list;
247 struct mbo *mbo;
248 unsigned long flags;
249 struct dim_ch_state_t st;
250
251 BUG_ON(hdm_ch == 0);
252 BUG_ON(!hdm_ch->is_initialized);
253
254 spin_lock_irqsave(&dim_lock, flags);
255 if (list_empty(head)) {
256 spin_unlock_irqrestore(&dim_lock, flags);
257 return -EAGAIN;
258 }
259
260 if (!DIM_GetChannelState(&hdm_ch->ch, &st)->ready) {
261 spin_unlock_irqrestore(&dim_lock, flags);
262 return -EAGAIN;
263 }
264
265 mbo = list_entry(head->next, struct mbo, list);
266 buf_size = mbo->buffer_length;
267
268 BUG_ON(mbo->bus_address == 0);
269 if (!DIM_EnqueueBuffer(&hdm_ch->ch, mbo->bus_address, buf_size)) {
270 list_del(head->next);
271 spin_unlock_irqrestore(&dim_lock, flags);
272 mbo->processed_length = 0;
273 mbo->status = MBO_E_INVAL;
274 mbo->complete(mbo);
275 return -EFAULT;
276 }
277
278 list_move_tail(head->next, &hdm_ch->started_list);
279 spin_unlock_irqrestore(&dim_lock, flags);
280
281 return 0;
282}
283
284/**
285 * deliver_netinfo_thread - thread to deliver network status to mostcore
286 * @data: private data
287 *
288 * Wait for network status and deliver it to mostcore once it is received
289 */
290static int deliver_netinfo_thread(void *data)
291{
292 struct dim2_hdm *dev = (struct dim2_hdm *)data;
293
294 while (!kthread_should_stop()) {
295 wait_event_interruptible(dev->netinfo_waitq,
296 dev->deliver_netinfo ||
297 kthread_should_stop());
298
299 if (dev->deliver_netinfo) {
300 dev->deliver_netinfo--;
301 most_deliver_netinfo(&dev->most_iface, dev->link_state,
302 dev->mac_addrs);
303 }
304 }
305
306 return 0;
307}
308
309/**
310 * retrieve_netinfo - retrieve network status from received buffer
311 * @dev: private data
312 * @mbo: received MBO
313 *
314 * Parse the message in buffer and get node address, link state, MAC address.
315 * Wake up a thread to deliver this status to mostcore
316 */
317static void retrieve_netinfo(struct dim2_hdm *dev, struct mbo *mbo)
318{
319 u8 *data = mbo->virt_address;
320 u8 *mac = dev->mac_addrs;
321
322 pr_info("Node Address: 0x%03x\n", (u16)data[16] << 8 | data[17]);
323 dev->link_state = data[18];
324 pr_info("NIState: %d\n", dev->link_state);
325 memcpy(mac, data + 19, 6);
326 pr_info("MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
327 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
328 dev->deliver_netinfo++;
329 wake_up_interruptible(&dev->netinfo_waitq);
330}
331
332/**
333 * service_done_flag - handle completed buffers
334 * @dev: private data
335 * @ch_idx: channel index
336 *
337 * Return back the completed buffers to mostcore, using completion callback
338 */
339static void service_done_flag(struct dim2_hdm *dev, int ch_idx)
340{
341 struct hdm_channel *hdm_ch = dev->hch + ch_idx;
342 struct dim_ch_state_t st;
343 struct list_head *head;
344 struct mbo *mbo;
345 int done_buffers;
346 unsigned long flags;
347 u8 *data;
348
349 BUG_ON(hdm_ch == 0);
350 BUG_ON(!hdm_ch->is_initialized);
351
352 spin_lock_irqsave(&dim_lock, flags);
353
354 done_buffers = DIM_GetChannelState(&hdm_ch->ch, &st)->done_buffers;
355 if (!done_buffers) {
356 spin_unlock_irqrestore(&dim_lock, flags);
357 return;
358 }
359
360 if (!DIM_DetachBuffers(&hdm_ch->ch, done_buffers)) {
361 spin_unlock_irqrestore(&dim_lock, flags);
362 return;
363 }
364 spin_unlock_irqrestore(&dim_lock, flags);
365
366 head = &hdm_ch->started_list;
367
368 while (done_buffers) {
369 spin_lock_irqsave(&dim_lock, flags);
370 if (list_empty(head)) {
371 spin_unlock_irqrestore(&dim_lock, flags);
372 pr_crit("hard error: started_mbo list is empty "
373 "whereas DIM2 has sent buffers\n");
374 break;
375 }
376
377 mbo = list_entry(head->next, struct mbo, list);
378 list_del(head->next);
379 spin_unlock_irqrestore(&dim_lock, flags);
380
381 data = mbo->virt_address;
382
383 if (hdm_ch->data_type == MOST_CH_ASYNC &&
384 hdm_ch->direction == MOST_CH_RX &&
385 PACKET_IS_NET_INFO(data)) {
386
387 retrieve_netinfo(dev, mbo);
388
389 spin_lock_irqsave(&dim_lock, flags);
390 list_add_tail(&mbo->list, &hdm_ch->pending_list);
391 spin_unlock_irqrestore(&dim_lock, flags);
392 } else {
393 if (hdm_ch->data_type == MOST_CH_CONTROL ||
394 hdm_ch->data_type == MOST_CH_ASYNC) {
395
396 u32 const data_size =
397 (u32)data[0] * 256 + data[1] + 2;
398
399 mbo->processed_length =
400 min(data_size, (u32)mbo->buffer_length);
401 } else {
402 mbo->processed_length = mbo->buffer_length;
403 }
404 mbo->status = MBO_SUCCESS;
405 mbo->complete(mbo);
406 }
407
408 done_buffers--;
409 }
410}
411
412static struct dim_channel **get_active_channels(struct dim2_hdm *dev,
413 struct dim_channel **buffer)
414{
415 int idx = 0;
416 int ch_idx;
417
418 for (ch_idx = 0; ch_idx < DMA_CHANNELS; ch_idx++) {
419 if (dev->hch[ch_idx].is_initialized)
420 buffer[idx++] = &dev->hch[ch_idx].ch;
421 }
422 buffer[idx++] = 0;
423
424 return buffer;
425}
426
427/**
428 * dim2_tasklet_fn - tasklet function
429 * @data: private data
430 *
431 * Service each initialized channel, if needed
432 */
433static void dim2_tasklet_fn(unsigned long data)
434{
435 struct dim2_hdm *dev = (struct dim2_hdm *)data;
436 unsigned long flags;
437 int ch_idx;
438
439 for (ch_idx = 0; ch_idx < DMA_CHANNELS; ch_idx++) {
440 if (!dev->hch[ch_idx].is_initialized)
441 continue;
442
443 spin_lock_irqsave(&dim_lock, flags);
444 DIM_ServiceChannel(&(dev->hch[ch_idx].ch));
445 spin_unlock_irqrestore(&dim_lock, flags);
446
447 service_done_flag(dev, ch_idx);
448 while (!try_start_dim_transfer(dev->hch + ch_idx))
449 continue;
450 }
451}
452
453/**
454 * dim2_ahb_isr - interrupt service routine
455 * @irq: irq number
456 * @_dev: private data
457 *
458 * Acknowledge the interrupt and schedule a tasklet to service channels.
459 * Return IRQ_HANDLED.
460 */
461static irqreturn_t dim2_ahb_isr(int irq, void *_dev)
462{
463 struct dim2_hdm *dev = (struct dim2_hdm *)_dev;
464 struct dim_channel *buffer[DMA_CHANNELS + 1];
465 unsigned long flags;
466
467 spin_lock_irqsave(&dim_lock, flags);
468 DIM_ServiceIrq(get_active_channels(dev, buffer));
469 spin_unlock_irqrestore(&dim_lock, flags);
470
471#if !defined(ENABLE_HDM_TEST)
472 dim2_tasklet.data = (unsigned long)dev;
473 tasklet_schedule(&dim2_tasklet);
474#else
475 dim2_tasklet_fn((unsigned long)dev);
476#endif
477 return IRQ_HANDLED;
478}
479
480#if defined(ENABLE_HDM_TEST)
481
482/*
483 * Utility function used by HAL-simu for calling DIM interrupt handler.
484 * It is used only for TEST PURPOSE.
485 */
486void raise_dim_interrupt(void)
487{
488 (void)dim2_ahb_isr(0, test_dev);
489}
490#endif
491
492/**
493 * complete_all_mbos - complete MBO's in a list
494 * @head: list head
495 *
496 * Delete all the entries in list and return back MBO's to mostcore using
497 * completion call back.
498 */
499static void complete_all_mbos(struct list_head *head)
500{
501 unsigned long flags;
502 struct mbo *mbo;
503
504 for (;;) {
505 spin_lock_irqsave(&dim_lock, flags);
506 if (list_empty(head)) {
507 spin_unlock_irqrestore(&dim_lock, flags);
508 break;
509 }
510
511 mbo = list_entry(head->next, struct mbo, list);
512 list_del(head->next);
513 spin_unlock_irqrestore(&dim_lock, flags);
514
515 mbo->processed_length = 0;
516 mbo->status = MBO_E_CLOSE;
517 mbo->complete(mbo);
518 }
519}
520
521/**
522 * configure_channel - initialize a channel
523 * @iface: interface the channel belongs to
524 * @channel: channel to be configured
525 * @channel_config: structure that holds the configuration information
526 *
527 * Receives configuration information from mostcore and initialize
528 * the corresponding channel. Return 0 on success, negative on failure.
529 */
530static int configure_channel(struct most_interface *most_iface, int ch_idx,
531 struct most_channel_config *ccfg)
532{
533 struct dim2_hdm *dev = iface_to_hdm(most_iface);
534 bool const is_tx = ccfg->direction == MOST_CH_TX;
535 u16 const sub_size = ccfg->subbuffer_size;
536 u16 const buf_size = ccfg->buffer_size;
537 u16 new_size;
538 unsigned long flags;
539 u8 hal_ret;
540 int const ch_addr = ch_idx * 2 + 2;
541 struct hdm_channel *const hdm_ch = dev->hch + ch_idx;
542
543 BUG_ON(ch_idx < 0 || ch_idx >= DMA_CHANNELS);
544
545 if (hdm_ch->is_initialized)
546 return -EPERM;
547
548 switch (ccfg->data_type) {
549 case MOST_CH_CONTROL:
550 new_size = DIM_NormCtrlAsyncBufferSize(buf_size);
551 if (new_size == 0) {
552 pr_err("%s: too small buffer size\n", hdm_ch->name);
553 return -EINVAL;
554 }
555 ccfg->buffer_size = new_size;
556 if (new_size != buf_size)
557 pr_warn("%s: fixed buffer size (%d -> %d)\n",
558 hdm_ch->name, buf_size, new_size);
559 spin_lock_irqsave(&dim_lock, flags);
560 hal_ret = DIM_InitControl(&hdm_ch->ch, is_tx, ch_addr, buf_size);
561 break;
562 case MOST_CH_ASYNC:
563 new_size = DIM_NormCtrlAsyncBufferSize(buf_size);
564 if (new_size == 0) {
565 pr_err("%s: too small buffer size\n", hdm_ch->name);
566 return -EINVAL;
567 }
568 ccfg->buffer_size = new_size;
569 if (new_size != buf_size)
570 pr_warn("%s: fixed buffer size (%d -> %d)\n",
571 hdm_ch->name, buf_size, new_size);
572 spin_lock_irqsave(&dim_lock, flags);
573 hal_ret = DIM_InitAsync(&hdm_ch->ch, is_tx, ch_addr, buf_size);
574 break;
575 case MOST_CH_ISOC_AVP:
576 new_size = DIM_NormIsocBufferSize(buf_size, sub_size);
577 if (new_size == 0) {
578 pr_err("%s: invalid sub-buffer size or "
579 "too small buffer size\n", hdm_ch->name);
580 return -EINVAL;
581 }
582 ccfg->buffer_size = new_size;
583 if (new_size != buf_size)
584 pr_warn("%s: fixed buffer size (%d -> %d)\n",
585 hdm_ch->name, buf_size, new_size);
586 spin_lock_irqsave(&dim_lock, flags);
587 hal_ret = DIM_InitIsoc(&hdm_ch->ch, is_tx, ch_addr, sub_size);
588 break;
589 case MOST_CH_SYNC:
590 new_size = DIM_NormSyncBufferSize(buf_size, sub_size);
591 if (new_size == 0) {
592 pr_err("%s: invalid sub-buffer size or "
593 "too small buffer size\n", hdm_ch->name);
594 return -EINVAL;
595 }
596 ccfg->buffer_size = new_size;
597 if (new_size != buf_size)
598 pr_warn("%s: fixed buffer size (%d -> %d)\n",
599 hdm_ch->name, buf_size, new_size);
600 spin_lock_irqsave(&dim_lock, flags);
601 hal_ret = DIM_InitSync(&hdm_ch->ch, is_tx, ch_addr, sub_size);
602 break;
603 default:
604 pr_err("%s: configure failed, bad channel type: %d\n",
605 hdm_ch->name, ccfg->data_type);
606 return -EINVAL;
607 }
608
609 if (hal_ret != DIM_NO_ERROR) {
610 spin_unlock_irqrestore(&dim_lock, flags);
611 pr_err("%s: configure failed (%d), type: %d, is_tx: %d\n",
612 hdm_ch->name, hal_ret, ccfg->data_type, (int)is_tx);
613 return -ENODEV;
614 }
615
616 hdm_ch->data_type = ccfg->data_type;
617 hdm_ch->direction = ccfg->direction;
618 hdm_ch->is_initialized = true;
619
620 if (hdm_ch->data_type == MOST_CH_ASYNC &&
621 hdm_ch->direction == MOST_CH_TX &&
622 dev->atx_idx < 0)
623 dev->atx_idx = ch_idx;
624
625 spin_unlock_irqrestore(&dim_lock, flags);
626
627 return 0;
628}
629
630/**
631 * enqueue - enqueue a buffer for data transfer
632 * @iface: intended interface
633 * @channel: ID of the channel the buffer is intended for
634 * @mbo: pointer to the buffer object
635 *
636 * Push the buffer into pending_list and try to transfer one buffer from
637 * pending_list. Return 0 on success, negative on failure.
638 */
639static int enqueue(struct most_interface *most_iface, int ch_idx,
640 struct mbo *mbo)
641{
642 struct dim2_hdm *dev = iface_to_hdm(most_iface);
643 struct hdm_channel *hdm_ch = dev->hch + ch_idx;
644 unsigned long flags;
645
646 BUG_ON(ch_idx < 0 || ch_idx >= DMA_CHANNELS);
647
648 if (!hdm_ch->is_initialized)
649 return -EPERM;
650
651 if (mbo->bus_address == 0)
652 return -EFAULT;
653
654 spin_lock_irqsave(&dim_lock, flags);
655 list_add_tail(&mbo->list, &hdm_ch->pending_list);
656 spin_unlock_irqrestore(&dim_lock, flags);
657
658 (void)try_start_dim_transfer(hdm_ch);
659
660 return 0;
661}
662
663/**
664 * request_netinfo - triggers retrieving of network info
665 * @iface: pointer to the interface
666 * @channel_id: corresponding channel ID
667 *
668 * Send a command to INIC which triggers retrieving of network info by means of
669 * "Message exchange over MDP/MEP". Return 0 on success, negative on failure.
670 */
671static void request_netinfo(struct most_interface *most_iface, int ch_idx)
672{
673 struct dim2_hdm *dev = iface_to_hdm(most_iface);
674 struct mbo *mbo;
675 u8 *data;
676
677 if (dev->atx_idx < 0) {
678 pr_err("Async Tx Not initialized\n");
679 return;
680 }
681
682 mbo = most_get_mbo(&dev->most_iface, dev->atx_idx);
683 if (!mbo)
684 return;
685
686 mbo->buffer_length = 5;
687
688 data = mbo->virt_address;
689
690 data[0] = 0x00; /* PML High byte */
691 data[1] = 0x03; /* PML Low byte */
692 data[2] = 0x02; /* PMHL */
693 data[3] = 0x08; /* FPH */
694 data[4] = 0x40; /* FMF (FIFO cmd msg - Triggers NAOverMDP) */
695
696 most_submit_mbo(mbo);
697}
698
699/**
700 * poison_channel - poison buffers of a channel
701 * @iface: pointer to the interface the channel to be poisoned belongs to
702 * @channel_id: corresponding channel ID
703 *
704 * Destroy a channel and complete all the buffers in both started_list &
705 * pending_list. Return 0 on success, negative on failure.
706 */
707static int poison_channel(struct most_interface *most_iface, int ch_idx)
708{
709 struct dim2_hdm *dev = iface_to_hdm(most_iface);
710 struct hdm_channel *hdm_ch = dev->hch + ch_idx;
711 unsigned long flags;
712 u8 hal_ret;
713 int ret = 0;
714
715 BUG_ON(ch_idx < 0 || ch_idx >= DMA_CHANNELS);
716
717 if (!hdm_ch->is_initialized)
718 return -EPERM;
719
720 spin_lock_irqsave(&dim_lock, flags);
721 hal_ret = DIM_DestroyChannel(&hdm_ch->ch);
722 hdm_ch->is_initialized = false;
723 if (ch_idx == dev->atx_idx)
724 dev->atx_idx = -1;
725 spin_unlock_irqrestore(&dim_lock, flags);
726 if (hal_ret != DIM_NO_ERROR) {
727 pr_err("HAL Failed to close channel %s\n", hdm_ch->name);
728 ret = -EFAULT;
729 }
730
731 complete_all_mbos(&hdm_ch->started_list);
732 complete_all_mbos(&hdm_ch->pending_list);
733
734 return ret;
735}
736
737/*
738 * dim2_probe - dim2 probe handler
739 * @pdev: platform device structure
740 *
741 * Register the dim2 interface with mostcore and initialize it.
742 * Return 0 on success, negative on failure.
743 */
744static int dim2_probe(struct platform_device *pdev)
745{
746 struct dim2_hdm *dev;
747 struct resource *res;
748 int ret, i;
749 struct kobject *kobj;
750
751 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
752 if (!dev)
753 return -ENOMEM;
754
755 dev->atx_idx = -1;
756
757 platform_set_drvdata(pdev, dev);
758#if defined(ENABLE_HDM_TEST)
759 test_dev = dev;
760#else
761 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
762 if (!res) {
763 pr_err("no memory region defined\n");
764 ret = -ENOENT;
765 goto err_free_dev;
766 }
767
768 if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
769 pr_err("failed to request mem region\n");
770 ret = -EBUSY;
771 goto err_free_dev;
772 }
773
774 dev->io_base = ioremap(res->start, resource_size(res));
775 if (!dev->io_base) {
776 pr_err("failed to ioremap\n");
777 ret = -ENOMEM;
778 goto err_release_mem;
779 }
780
781 ret = platform_get_irq(pdev, 0);
782 if (ret < 0) {
783 pr_err("failed to get irq\n");
784 goto err_unmap_io;
785 }
786 dev->irq_ahb0 = ret;
787
788 ret = request_irq(dev->irq_ahb0, dim2_ahb_isr, 0, "mlb_ahb0", dev);
789 if (ret) {
790 pr_err("failed to request IRQ: %d, err: %d\n", dev->irq_ahb0, ret);
791 goto err_unmap_io;
792 }
793#endif
794 init_waitqueue_head(&dev->netinfo_waitq);
795 dev->deliver_netinfo = 0;
796 dev->netinfo_task = kthread_run(&deliver_netinfo_thread, (void *)dev,
797 "dim2_netinfo");
798 if (IS_ERR(dev->netinfo_task)) {
799 ret = PTR_ERR(dev->netinfo_task);
800 goto err_free_irq;
801 }
802
803 for (i = 0; i < DMA_CHANNELS; i++) {
804 struct most_channel_capability *cap = dev->capabilities + i;
805 struct hdm_channel *hdm_ch = dev->hch + i;
806
807 INIT_LIST_HEAD(&hdm_ch->pending_list);
808 INIT_LIST_HEAD(&hdm_ch->started_list);
809 hdm_ch->is_initialized = false;
810 snprintf(hdm_ch->name, sizeof(hdm_ch->name), "ca%d", i * 2 + 2);
811
812 cap->name_suffix = hdm_ch->name;
813 cap->direction = MOST_CH_RX | MOST_CH_TX;
814 cap->data_type = MOST_CH_CONTROL | MOST_CH_ASYNC |
815 MOST_CH_ISOC_AVP | MOST_CH_SYNC;
816 cap->num_buffers_packet = MAX_BUFFERS_PACKET;
817 cap->buffer_size_packet = MAX_BUF_SIZE_PACKET;
818 cap->num_buffers_streaming = MAX_BUFFERS_STREAMING;
819 cap->buffer_size_streaming = MAX_BUF_SIZE_STREAMING;
820 }
821
822 {
823 const char *fmt;
824
825 if (sizeof(res->start) == sizeof(long long))
826 fmt = "dim2-%016llx";
827 else if (sizeof(res->start) == sizeof(long))
828 fmt = "dim2-%016lx";
829 else
830 fmt = "dim2-%016x";
831
832 snprintf(dev->name, sizeof(dev->name), fmt, res->start);
833 }
834
835 dev->most_iface.interface = ITYPE_MEDIALB_DIM2;
836 dev->most_iface.description = dev->name;
837 dev->most_iface.num_channels = DMA_CHANNELS;
838 dev->most_iface.channel_vector = dev->capabilities;
839 dev->most_iface.configure = configure_channel;
840 dev->most_iface.enqueue = enqueue;
841 dev->most_iface.poison_channel = poison_channel;
842 dev->most_iface.request_netinfo = request_netinfo;
843
844 kobj = most_register_interface(&dev->most_iface);
845 if (IS_ERR(kobj)) {
846 ret = PTR_ERR(kobj);
847 pr_err("failed to register MOST interface\n");
848 goto err_stop_thread;
849 }
850
851 ret = dim2_sysfs_probe(&dev->bus, kobj);
852 if (ret)
853 goto err_unreg_iface;
854
855 ret = startup_dim(pdev);
856 if (ret) {
857 pr_err("failed to initialize DIM2\n");
858 goto err_destroy_bus;
859 }
860
861 return 0;
862
863err_destroy_bus:
864 dim2_sysfs_destroy(&dev->bus);
865err_unreg_iface:
866 most_deregister_interface(&dev->most_iface);
867err_stop_thread:
868 kthread_stop(dev->netinfo_task);
869err_free_irq:
870#if !defined(ENABLE_HDM_TEST)
871 free_irq(dev->irq_ahb0, dev);
872err_unmap_io:
873 iounmap(dev->io_base);
874err_release_mem:
875 release_mem_region(res->start, resource_size(res));
876err_free_dev:
877#endif
878 kfree(dev);
879
880 return ret;
881}
882
883/**
884 * dim2_remove - dim2 remove handler
885 * @pdev: platform device structure
886 *
887 * Unregister the interface from mostcore
888 */
889static int dim2_remove(struct platform_device *pdev)
890{
891 struct dim2_hdm *dev = platform_get_drvdata(pdev);
892 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
893 struct dim2_platform_data *pdata = pdev->dev.platform_data;
894 unsigned long flags;
895
896 spin_lock_irqsave(&dim_lock, flags);
897 DIM_Shutdown();
898 spin_unlock_irqrestore(&dim_lock, flags);
899
900 if (pdata && pdata->destroy)
901 pdata->destroy(pdata);
902
903 dim2_sysfs_destroy(&dev->bus);
904 most_deregister_interface(&dev->most_iface);
905 kthread_stop(dev->netinfo_task);
906#if !defined(ENABLE_HDM_TEST)
907 free_irq(dev->irq_ahb0, dev);
908 iounmap(dev->io_base);
909 release_mem_region(res->start, resource_size(res));
910#endif
911 kfree(dev);
912 platform_set_drvdata(pdev, NULL);
913
914 /*
915 * break link to local platform_device_id struct
916 * to prevent crash by unload platform device module
917 */
918 pdev->id_entry = 0;
919
920 return 0;
921}
922
923static struct platform_device_id dim2_id[] = {
924 { "medialb_dim2" },
925 { }, /* Terminating entry */
926};
927
928MODULE_DEVICE_TABLE(platform, dim2_id);
929
930static struct platform_driver dim2_driver = {
931 .probe = dim2_probe,
932 .remove = dim2_remove,
933 .id_table = dim2_id,
934 .driver = {
935 .name = "hdm_dim2",
936 .owner = THIS_MODULE,
937 },
938};
939
940/**
941 * dim2_hdm_init - Driver Registration Routine
942 */
943static int __init dim2_hdm_init(void)
944{
945 pr_info("dim2_hdm_init()\n");
946 return platform_driver_register(&dim2_driver);
947}
948
949/**
950 * dim2_hdm_exit - Driver Cleanup Routine
951 **/
952static void __exit dim2_hdm_exit(void)
953{
954 pr_info("dim2_hdm_exit()\n");
955 platform_driver_unregister(&dim2_driver);
956}
957
958module_init(dim2_hdm_init);
959module_exit(dim2_hdm_exit);
960
961MODULE_AUTHOR("Jain Roy Ambi <JainRoy.Ambi@microchip.com>");
962MODULE_AUTHOR("Andrey Shvetsov <andrey.shvetsov@k2l.de>");
963MODULE_DESCRIPTION("MediaLB DIM2 Hardware Dependent Module");
964MODULE_LICENSE("GPL");
diff --git a/drivers/staging/most/hdm-dim2/dim2_hdm.h b/drivers/staging/most/hdm-dim2/dim2_hdm.h
new file mode 100644
index 000000000000..6e6883232809
--- /dev/null
+++ b/drivers/staging/most/hdm-dim2/dim2_hdm.h
@@ -0,0 +1,26 @@
1/*
2 * dim2_hdm.h - MediaLB DIM2 HDM Header
3 *
4 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * This file is licensed under GPLv2.
12 */
13
14#ifndef DIM2_HDM_H
15#define DIM2_HDM_H
16
17struct device;
18
19/* platform dependent data for dim2 interface */
20struct dim2_platform_data {
21 int (*init)(struct dim2_platform_data *pd, void *io_base, int clk_speed);
22 void (*destroy)(struct dim2_platform_data *pd);
23 void *priv;
24};
25
26#endif /* DIM2_HDM_H */
diff --git a/drivers/staging/most/hdm-dim2/dim2_reg.h b/drivers/staging/most/hdm-dim2/dim2_reg.h
new file mode 100644
index 000000000000..476f66f4c566
--- /dev/null
+++ b/drivers/staging/most/hdm-dim2/dim2_reg.h
@@ -0,0 +1,176 @@
1/*
2 * dim2_reg.h - Definitions for registers of DIM2
3 * (MediaLB, Device Interface Macro IP, OS62420)
4 *
5 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * This file is licensed under GPLv2.
13 */
14
15#ifndef DIM2_OS62420_H
16#define DIM2_OS62420_H
17
18#include <linux/types.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24
25struct dim2_regs {
26 /* 0x00 */ u32 MLBC0;
27 /* 0x01 */ u32 rsvd0[1];
28 /* 0x02 */ u32 MLBPC0;
29 /* 0x03 */ u32 MS0;
30 /* 0x04 */ u32 rsvd1[1];
31 /* 0x05 */ u32 MS1;
32 /* 0x06 */ u32 rsvd2[2];
33 /* 0x08 */ u32 MSS;
34 /* 0x09 */ u32 MSD;
35 /* 0x0A */ u32 rsvd3[1];
36 /* 0x0B */ u32 MIEN;
37 /* 0x0C */ u32 rsvd4[1];
38 /* 0x0D */ u32 MLBPC2;
39 /* 0x0E */ u32 MLBPC1;
40 /* 0x0F */ u32 MLBC1;
41 /* 0x10 */ u32 rsvd5[0x10];
42 /* 0x20 */ u32 HCTL;
43 /* 0x21 */ u32 rsvd6[1];
44 /* 0x22 */ u32 HCMR0;
45 /* 0x23 */ u32 HCMR1;
46 /* 0x24 */ u32 HCER0;
47 /* 0x25 */ u32 HCER1;
48 /* 0x26 */ u32 HCBR0;
49 /* 0x27 */ u32 HCBR1;
50 /* 0x28 */ u32 rsvd7[8];
51 /* 0x30 */ u32 MDAT0;
52 /* 0x31 */ u32 MDAT1;
53 /* 0x32 */ u32 MDAT2;
54 /* 0x33 */ u32 MDAT3;
55 /* 0x34 */ u32 MDWE0;
56 /* 0x35 */ u32 MDWE1;
57 /* 0x36 */ u32 MDWE2;
58 /* 0x37 */ u32 MDWE3;
59 /* 0x38 */ u32 MCTL;
60 /* 0x39 */ u32 MADR;
61 /* 0x3A */ u32 rsvd8[0xB6];
62 /* 0xF0 */ u32 ACTL;
63 /* 0xF1 */ u32 rsvd9[3];
64 /* 0xF4 */ u32 ACSR0;
65 /* 0xF5 */ u32 ACSR1;
66 /* 0xF6 */ u32 ACMR0;
67 /* 0xF7 */ u32 ACMR1;
68};
69
70
71#define DIM2_MASK(n) (~((~(u32)0)<<(n)))
72
73enum {
74 MLBC0_MLBLK_BIT = 7,
75
76 MLBC0_MLBPEN_BIT = 5,
77
78 MLBC0_MLBCLK_SHIFT = 2,
79 MLBC0_MLBCLK_VAL_256FS = 0,
80 MLBC0_MLBCLK_VAL_512FS = 1,
81 MLBC0_MLBCLK_VAL_1024FS = 2,
82 MLBC0_MLBCLK_VAL_2048FS = 3,
83
84 MLBC0_FCNT_SHIFT = 15,
85 MLBC0_FCNT_MASK = 7,
86 MLBC0_FCNT_VAL_1FPSB = 0,
87 MLBC0_FCNT_VAL_2FPSB = 1,
88 MLBC0_FCNT_VAL_4FPSB = 2,
89 MLBC0_FCNT_VAL_8FPSB = 3,
90 MLBC0_FCNT_VAL_16FPSB = 4,
91 MLBC0_FCNT_VAL_32FPSB = 5,
92 MLBC0_FCNT_VAL_64FPSB = 6,
93
94 MLBC0_MLBEN_BIT = 0,
95
96 MIEN_CTX_BREAK_BIT = 29,
97 MIEN_CTX_PE_BIT = 28,
98 MIEN_CTX_DONE_BIT = 27,
99
100 MIEN_CRX_BREAK_BIT = 26,
101 MIEN_CRX_PE_BIT = 25,
102 MIEN_CRX_DONE_BIT = 24,
103
104 MIEN_ATX_BREAK_BIT = 22,
105 MIEN_ATX_PE_BIT = 21,
106 MIEN_ATX_DONE_BIT = 20,
107
108 MIEN_ARX_BREAK_BIT = 19,
109 MIEN_ARX_PE_BIT = 18,
110 MIEN_ARX_DONE_BIT = 17,
111
112 MIEN_SYNC_PE_BIT = 16,
113
114 MIEN_ISOC_BUFO_BIT = 1,
115 MIEN_ISOC_PE_BIT = 0,
116
117 MLBC1_NDA_SHIFT = 8,
118 MLBC1_NDA_MASK = 0xFF,
119
120 MLBC1_CLKMERR_BIT = 7,
121 MLBC1_LOCKERR_BIT = 6,
122
123 ACTL_DMA_MODE_BIT = 2,
124 ACTL_DMA_MODE_VAL_DMA_MODE_0 = 0,
125 ACTL_DMA_MODE_VAL_DMA_MODE_1 = 1,
126 ACTL_SCE_BIT = 0,
127
128 HCTL_EN_BIT = 15
129};
130
131enum {
132 CDT1_BS_ISOC_SHIFT = 0,
133 CDT1_BS_ISOC_MASK = DIM2_MASK(9),
134
135 CDT3_BD_SHIFT = 0,
136 CDT3_BD_MASK = DIM2_MASK(12),
137 CDT3_BD_ISOC_MASK = DIM2_MASK(13),
138 CDT3_BA_SHIFT = 16,
139
140 ADT0_CE_BIT = 15,
141 ADT0_LE_BIT = 14,
142 ADT0_PG_BIT = 13,
143
144 ADT1_RDY_BIT = 15,
145 ADT1_DNE_BIT = 14,
146 ADT1_ERR_BIT = 13,
147 ADT1_PS_BIT = 12,
148 ADT1_MEP_BIT = 11,
149 ADT1_BD_SHIFT = 0,
150 ADT1_CTRL_ASYNC_BD_MASK = DIM2_MASK(11),
151 ADT1_ISOC_SYNC_BD_MASK = DIM2_MASK(13),
152
153 CAT_MFE_BIT = 14,
154
155 CAT_MT_BIT = 13,
156
157 CAT_RNW_BIT = 12,
158
159 CAT_CE_BIT = 11,
160
161 CAT_CT_SHIFT = 8,
162 CAT_CT_VAL_SYNC = 0,
163 CAT_CT_VAL_CONTROL = 1,
164 CAT_CT_VAL_ASYNC = 2,
165 CAT_CT_VAL_ISOC = 3,
166
167 CAT_CL_SHIFT = 0,
168 CAT_CL_MASK = DIM2_MASK(6)
169};
170
171
172#ifdef __cplusplus
173}
174#endif
175
176#endif /* DIM2_OS62420_H */
diff --git a/drivers/staging/most/hdm-dim2/dim2_sysfs.c b/drivers/staging/most/hdm-dim2/dim2_sysfs.c
new file mode 100644
index 000000000000..8e331a286fc3
--- /dev/null
+++ b/drivers/staging/most/hdm-dim2/dim2_sysfs.c
@@ -0,0 +1,116 @@
1/*
2 * dim2_sysfs.c - MediaLB sysfs information
3 *
4 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * This file is licensed under GPLv2.
12 */
13
14/* Author: Andrey Shvetsov <andrey.shvetsov@k2l.de> */
15
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
18#include <linux/kernel.h>
19#include "dim2_sysfs.h"
20
21struct bus_attr {
22 struct attribute attr;
23 ssize_t (*show)(struct medialb_bus *bus, char *buf);
24 ssize_t (*store)(struct medialb_bus *bus, const char *buf, size_t count);
25};
26
27static ssize_t state_show(struct medialb_bus *bus, char *buf)
28{
29 bool state = dim2_sysfs_get_state_cb();
30
31 return sprintf(buf, "%s\n", state ? "locked" : "");
32}
33
34static struct bus_attr state_attr = __ATTR_RO(state);
35
36static struct attribute *bus_default_attrs[] = {
37 &state_attr.attr,
38 NULL,
39};
40
41static struct attribute_group bus_attr_group = {
42 .attrs = bus_default_attrs,
43};
44
45static void bus_kobj_release(struct kobject *kobj)
46{
47}
48
49static ssize_t bus_kobj_attr_show(struct kobject *kobj, struct attribute *attr,
50 char *buf)
51{
52 struct medialb_bus *bus =
53 container_of(kobj, struct medialb_bus, kobj_group);
54 struct bus_attr *xattr = container_of(attr, struct bus_attr, attr);
55
56 if (!xattr->show)
57 return -EIO;
58
59 return xattr->show(bus, buf);
60}
61
62static ssize_t bus_kobj_attr_store(struct kobject *kobj, struct attribute *attr,
63 const char *buf, size_t count)
64{
65 ssize_t ret;
66 struct medialb_bus *bus =
67 container_of(kobj, struct medialb_bus, kobj_group);
68 struct bus_attr *xattr = container_of(attr, struct bus_attr, attr);
69
70 if (!xattr->store)
71 return -EIO;
72
73 ret = xattr->store(bus, buf, count);
74 return ret;
75}
76
77static struct sysfs_ops const bus_kobj_sysfs_ops = {
78 .show = bus_kobj_attr_show,
79 .store = bus_kobj_attr_store,
80};
81
82static struct kobj_type bus_ktype = {
83 .release = bus_kobj_release,
84 .sysfs_ops = &bus_kobj_sysfs_ops,
85};
86
87int dim2_sysfs_probe(struct medialb_bus *bus, struct kobject *parent_kobj)
88{
89 int err;
90
91 kobject_init(&bus->kobj_group, &bus_ktype);
92 err = kobject_add(&bus->kobj_group, parent_kobj, "bus");
93 if (err) {
94 pr_err("kobject_add() failed: %d\n", err);
95 goto err_kobject_add;
96 }
97
98 err = sysfs_create_group(&bus->kobj_group, &bus_attr_group);
99 if (err) {
100 pr_err("sysfs_create_group() failed: %d\n", err);
101 goto err_create_group;
102 }
103
104 return 0;
105
106err_create_group:
107 kobject_put(&bus->kobj_group);
108
109err_kobject_add:
110 return err;
111}
112
113void dim2_sysfs_destroy(struct medialb_bus *bus)
114{
115 kobject_put(&bus->kobj_group);
116}
diff --git a/drivers/staging/most/hdm-dim2/dim2_sysfs.h b/drivers/staging/most/hdm-dim2/dim2_sysfs.h
new file mode 100644
index 000000000000..e719691035b0
--- /dev/null
+++ b/drivers/staging/most/hdm-dim2/dim2_sysfs.h
@@ -0,0 +1,39 @@
1/*
2 * dim2_sysfs.h - MediaLB sysfs information
3 *
4 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * This file is licensed under GPLv2.
12 */
13
14/* Author: Andrey Shvetsov <andrey.shvetsov@k2l.de> */
15
16#ifndef DIM2_SYSFS_H
17#define DIM2_SYSFS_H
18
19
20#include <linux/kobject.h>
21
22
23struct medialb_bus {
24 struct kobject kobj_group;
25};
26
27struct dim2_hdm;
28
29int dim2_sysfs_probe(struct medialb_bus *bus, struct kobject *parent_kobj);
30void dim2_sysfs_destroy(struct medialb_bus *bus);
31
32/*
33 * callback,
34 * must deliver MediaLB state as true if locked or false if unlocked
35 */
36bool dim2_sysfs_get_state_cb(void);
37
38
39#endif /* DIM2_SYSFS_H */
diff --git a/drivers/staging/most/hdm-i2c/Kconfig b/drivers/staging/most/hdm-i2c/Kconfig
new file mode 100644
index 000000000000..6fd7983668ad
--- /dev/null
+++ b/drivers/staging/most/hdm-i2c/Kconfig
@@ -0,0 +1,12 @@
1#
2# MOST I2C configuration
3#
4
5config HDM_I2C
6 tristate "I2C HDM"
7 depends on I2C
8 ---help---
9 Say Y here if you want to connect via I2C to network tranceiver.
10
11 To compile this driver as a module, choose M here: the
12 module will be called hdm_i2c.
diff --git a/drivers/staging/most/hdm-i2c/Makefile b/drivers/staging/most/hdm-i2c/Makefile
new file mode 100644
index 000000000000..03a4a59b1f9f
--- /dev/null
+++ b/drivers/staging/most/hdm-i2c/Makefile
@@ -0,0 +1,3 @@
1obj-$(CONFIG_HDM_I2C) += hdm_i2c.o
2
3ccflags-y += -Idrivers/staging/most/mostcore/
diff --git a/drivers/staging/most/hdm-i2c/hdm_i2c.c b/drivers/staging/most/hdm-i2c/hdm_i2c.c
new file mode 100644
index 000000000000..029ded3f250b
--- /dev/null
+++ b/drivers/staging/most/hdm-i2c/hdm_i2c.c
@@ -0,0 +1,451 @@
1/*
2 * hdm_i2c.c - Hardware Dependent Module for I2C Interface
3 *
4 * Copyright (C) 2013-2015, Microchip Technology Germany II GmbH & Co. KG
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * This file is licensed under GPLv2.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
16#include <linux/init.h>
17#include <linux/module.h>
18#include <linux/slab.h>
19#include <linux/i2c.h>
20#include <linux/sched.h>
21#include <linux/interrupt.h>
22#include <linux/err.h>
23
24#include <mostcore.h>
25
26enum { CH_RX, CH_TX, NUM_CHANNELS };
27
28#define MAX_BUFFERS_CONTROL 32
29#define MAX_BUF_SIZE_CONTROL 256
30
31/**
32 * list_first_mbo - get the first mbo from a list
33 * @ptr: the list head to take the mbo from.
34 */
35#define list_first_mbo(ptr) \
36 list_first_entry(ptr, struct mbo, list)
37
38
39/* IRQ / Polling option */
40static bool polling_req;
41module_param(polling_req, bool, S_IRUGO);
42MODULE_PARM_DESC(polling_req, "Request Polling. Default = 0 (use irq)");
43
44/* Polling Rate */
45static int scan_rate = 100;
46module_param(scan_rate, int, 0644);
47MODULE_PARM_DESC(scan_rate, "Polling rate in times/sec. Default = 100");
48
49struct hdm_i2c {
50 bool is_open[NUM_CHANNELS];
51 bool polling_mode;
52 struct most_interface most_iface;
53 struct most_channel_capability capabilities[NUM_CHANNELS];
54 struct i2c_client *client;
55 struct rx {
56 struct delayed_work dwork;
57 wait_queue_head_t waitq;
58 struct list_head list;
59 struct mutex list_mutex;
60 } rx;
61 char name[64];
62};
63
64#define to_hdm(iface) container_of(iface, struct hdm_i2c, most_iface)
65
66/**
67 * configure_channel - called from MOST core to configure a channel
68 * @iface: interface the channel belongs to
69 * @channel: channel to be configured
70 * @channel_config: structure that holds the configuration information
71 *
72 * Return 0 on success, negative on failure.
73 *
74 * Receives configuration information from MOST core and initialize the
75 * corresponding channel.
76 */
77static int configure_channel(struct most_interface *most_iface,
78 int ch_idx,
79 struct most_channel_config *channel_config)
80{
81 struct hdm_i2c *dev = to_hdm(most_iface);
82
83 BUG_ON(ch_idx < 0 || ch_idx >= NUM_CHANNELS);
84 BUG_ON(dev->is_open[ch_idx]);
85
86 if (channel_config->data_type != MOST_CH_CONTROL) {
87 pr_err("bad data type for channel %d\n", ch_idx);
88 return -EPERM;
89 }
90
91 if (channel_config->direction != dev->capabilities[ch_idx].direction) {
92 pr_err("bad direction for channel %d\n", ch_idx);
93 return -EPERM;
94 }
95
96 if (channel_config->direction == MOST_CH_RX) {
97 if (dev->polling_mode)
98 schedule_delayed_work(&dev->rx.dwork,
99 msecs_to_jiffies(MSEC_PER_SEC / 4));
100 }
101 dev->is_open[ch_idx] = true;
102
103 return 0;
104}
105
106/**
107 * enqueue - called from MOST core to enqueue a buffer for data transfer
108 * @iface: intended interface
109 * @channel: ID of the channel the buffer is intended for
110 * @mbo: pointer to the buffer object
111 *
112 * Return 0 on success, negative on failure.
113 *
114 * Transmit the data over I2C if it is a "write" request or push the buffer into
115 * list if it is an "read" request
116 */
117static int enqueue(struct most_interface *most_iface,
118 int ch_idx, struct mbo *mbo)
119{
120 struct hdm_i2c *dev = to_hdm(most_iface);
121 int ret;
122
123 BUG_ON(ch_idx < 0 || ch_idx >= NUM_CHANNELS);
124 BUG_ON(!dev->is_open[ch_idx]);
125
126 if (ch_idx == CH_RX) {
127 /* RX */
128 mutex_lock(&dev->rx.list_mutex);
129 list_add_tail(&mbo->list, &dev->rx.list);
130 mutex_unlock(&dev->rx.list_mutex);
131 wake_up_interruptible(&dev->rx.waitq);
132 } else {
133 /* TX */
134 ret = i2c_master_send(dev->client, mbo->virt_address,
135 mbo->buffer_length);
136 if (ret <= 0) {
137 mbo->processed_length = 0;
138 mbo->status = MBO_E_INVAL;
139 } else {
140 mbo->processed_length = mbo->buffer_length;
141 mbo->status = MBO_SUCCESS;
142 }
143 mbo->complete(mbo);
144 }
145
146 return 0;
147}
148
149/**
150 * poison_channel - called from MOST core to poison buffers of a channel
151 * @iface: pointer to the interface the channel to be poisoned belongs to
152 * @channel_id: corresponding channel ID
153 *
154 * Return 0 on success, negative on failure.
155 *
156 * If channel direction is RX, complete the buffers in list with
157 * status MBO_E_CLOSE
158 */
159static int poison_channel(struct most_interface *most_iface,
160 int ch_idx)
161{
162 struct hdm_i2c *dev = to_hdm(most_iface);
163 struct mbo *mbo;
164
165 BUG_ON(ch_idx < 0 || ch_idx >= NUM_CHANNELS);
166 BUG_ON(!dev->is_open[ch_idx]);
167
168 dev->is_open[ch_idx] = false;
169
170 if (ch_idx == CH_RX) {
171 mutex_lock(&dev->rx.list_mutex);
172 while (!list_empty(&dev->rx.list)) {
173 mbo = list_first_mbo(&dev->rx.list);
174 list_del(&mbo->list);
175 mutex_unlock(&dev->rx.list_mutex);
176
177 mbo->processed_length = 0;
178 mbo->status = MBO_E_CLOSE;
179 mbo->complete(mbo);
180
181 mutex_lock(&dev->rx.list_mutex);
182 }
183 mutex_unlock(&dev->rx.list_mutex);
184 wake_up_interruptible(&dev->rx.waitq);
185 }
186
187 return 0;
188}
189
190static void request_netinfo(struct most_interface *most_iface,
191 int ch_idx)
192{
193 pr_info("request_netinfo()\n");
194}
195
196static void do_rx_work(struct hdm_i2c *dev)
197{
198 struct mbo *mbo;
199 unsigned char msg[MAX_BUF_SIZE_CONTROL];
200 int ret, ch_idx = CH_RX;
201 uint16_t pml, data_size;
202
203 /* Read PML (2 bytes) */
204 ret = i2c_master_recv(dev->client, msg, 2);
205 if (ret <= 0) {
206 pr_err("Failed to receive PML\n");
207 return;
208 }
209
210 pml = (msg[0] << 8) | msg[1];
211 if (!pml)
212 return;
213
214 data_size = pml + 2;
215
216 /* Read the whole message, including PML */
217 ret = i2c_master_recv(dev->client, msg, data_size);
218 if (ret <= 0) {
219 pr_err("Failed to receive a Port Message\n");
220 return;
221 }
222
223 for (;;) {
224 /* Conditions to wait for: poisoned channel or free buffer
225 available for reading */
226 if (wait_event_interruptible(dev->rx.waitq,
227 !dev->is_open[ch_idx] ||
228 !list_empty(&dev->rx.list))) {
229 pr_err("wait_event_interruptible() failed\n");
230 return;
231 }
232
233 if (!dev->is_open[ch_idx])
234 return;
235
236 mutex_lock(&dev->rx.list_mutex);
237
238 /* list may be empty if poison or remove is called */
239 if (!list_empty(&dev->rx.list))
240 break;
241
242 mutex_unlock(&dev->rx.list_mutex);
243 }
244
245 mbo = list_first_mbo(&dev->rx.list);
246 list_del(&mbo->list);
247 mutex_unlock(&dev->rx.list_mutex);
248
249 mbo->processed_length = min(data_size, mbo->buffer_length);
250 memcpy(mbo->virt_address, msg, mbo->processed_length);
251 mbo->status = MBO_SUCCESS;
252 mbo->complete(mbo);
253}
254
255/**
256 * pending_rx_work - Read pending messages through I2C
257 * @work: definition of this work item
258 *
259 * Invoked by the Interrupt Service Routine, most_irq_handler()
260 */
261static void pending_rx_work(struct work_struct *work)
262{
263 struct hdm_i2c *dev = container_of(work, struct hdm_i2c, rx.dwork.work);
264
265 do_rx_work(dev);
266
267 if (dev->polling_mode) {
268 if (dev->is_open[CH_RX])
269 schedule_delayed_work(&dev->rx.dwork,
270 msecs_to_jiffies(MSEC_PER_SEC
271 / scan_rate));
272 } else
273 enable_irq(dev->client->irq);
274}
275
276/*
277 * most_irq_handler - Interrupt Service Routine
278 * @irq: irq number
279 * @_dev: private data
280 *
281 * Schedules a delayed work
282 *
283 * By default the interrupt line behavior is Active Low. Once an interrupt is
284 * generated by the device, until driver clears the interrupt (by reading
285 * the PMP message), device keeps the interrupt line in low state. Since i2c
286 * read is done in work queue, the interrupt line must be disabled temporarily
287 * to avoid ISR being called repeatedly. Re-enable the interrupt in workqueue,
288 * after reading the message.
289 *
290 * Note: If we use the interrupt line in Falling edge mode, there is a
291 * possibility to miss interrupts when ISR is getting executed.
292 *
293 */
294static irqreturn_t most_irq_handler(int irq, void *_dev)
295{
296 struct hdm_i2c *dev = _dev;
297
298 disable_irq_nosync(irq);
299
300 schedule_delayed_work(&dev->rx.dwork, 0);
301
302 return IRQ_HANDLED;
303}
304
305/*
306 * i2c_probe - i2c probe handler
307 * @client: i2c client device structure
308 * @id: i2c client device id
309 *
310 * Return 0 on success, negative on failure.
311 *
312 * Register the i2c client device as a MOST interface
313 */
314static int i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
315{
316 struct hdm_i2c *dev;
317 int ret, i;
318 struct kobject *kobj;
319
320 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
321 if (!dev)
322 return -ENOMEM;
323
324 /* ID format: i2c-<bus>-<address> */
325 snprintf(dev->name, sizeof(dev->name), "i2c-%d-%04x",
326 client->adapter->nr, client->addr);
327
328 for (i = 0; i < NUM_CHANNELS; i++) {
329 dev->is_open[i] = false;
330 dev->capabilities[i].data_type = MOST_CH_CONTROL;
331 dev->capabilities[i].num_buffers_packet = MAX_BUFFERS_CONTROL;
332 dev->capabilities[i].buffer_size_packet = MAX_BUF_SIZE_CONTROL;
333 }
334 dev->capabilities[CH_RX].direction = MOST_CH_RX;
335 dev->capabilities[CH_RX].name_suffix = "rx";
336 dev->capabilities[CH_TX].direction = MOST_CH_TX;
337 dev->capabilities[CH_TX].name_suffix = "tx";
338
339 dev->most_iface.interface = ITYPE_I2C;
340 dev->most_iface.description = dev->name;
341 dev->most_iface.num_channels = NUM_CHANNELS;
342 dev->most_iface.channel_vector = dev->capabilities;
343 dev->most_iface.configure = configure_channel;
344 dev->most_iface.enqueue = enqueue;
345 dev->most_iface.poison_channel = poison_channel;
346 dev->most_iface.request_netinfo = request_netinfo;
347
348 INIT_LIST_HEAD(&dev->rx.list);
349 mutex_init(&dev->rx.list_mutex);
350 init_waitqueue_head(&dev->rx.waitq);
351
352 INIT_DELAYED_WORK(&dev->rx.dwork, pending_rx_work);
353
354 dev->client = client;
355 i2c_set_clientdata(client, dev);
356
357 kobj = most_register_interface(&dev->most_iface);
358 if (IS_ERR(kobj)) {
359 pr_err("Failed to register i2c as a MOST interface\n");
360 kfree(dev);
361 return PTR_ERR(kobj);
362 }
363
364 dev->polling_mode = polling_req || client->irq <= 0;
365 if (!dev->polling_mode) {
366 pr_info("Requesting IRQ: %d\n", client->irq);
367 ret = request_irq(client->irq, most_irq_handler, IRQF_SHARED,
368 client->name, dev);
369 if (ret) {
370 pr_info("IRQ request failed: %d, "
371 "falling back to polling\n", ret);
372 dev->polling_mode = true;
373 }
374 }
375
376 if (dev->polling_mode)
377 pr_info("Using polling at rate: %d times/sec\n", scan_rate);
378
379 return 0;
380}
381
382/*
383 * i2c_remove - i2c remove handler
384 * @client: i2c client device structure
385 *
386 * Return 0 on success.
387 *
388 * Unregister the i2c client device as a MOST interface
389 */
390static int i2c_remove(struct i2c_client *client)
391{
392 struct hdm_i2c *dev = i2c_get_clientdata(client);
393 int i;
394
395 if (!dev->polling_mode)
396 free_irq(client->irq, dev);
397
398 most_deregister_interface(&dev->most_iface);
399
400 for (i = 0 ; i < NUM_CHANNELS; i++)
401 if (dev->is_open[i])
402 poison_channel(&dev->most_iface, i);
403 cancel_delayed_work_sync(&dev->rx.dwork);
404 kfree(dev);
405
406 return 0;
407}
408
409static const struct i2c_device_id i2c_id[] = {
410 { "most_i2c", 0 },
411 { }, /* Terminating entry */
412};
413
414MODULE_DEVICE_TABLE(i2c, i2c_id);
415
416static struct i2c_driver i2c_driver = {
417 .driver = {
418 .name = "hdm_i2c",
419 .owner = THIS_MODULE,
420 },
421 .probe = i2c_probe,
422 .remove = i2c_remove,
423 .id_table = i2c_id,
424};
425
426/**
427 * hdm_i2c_init - Driver Registration Routine
428 */
429static int __init hdm_i2c_init(void)
430{
431 pr_info("hdm_i2c_init()\n");
432
433 return i2c_add_driver(&i2c_driver);
434}
435
436/**
437 * hdm_i2c_exit - Driver Cleanup Routine
438 **/
439static void __exit hdm_i2c_exit(void)
440{
441 i2c_del_driver(&i2c_driver);
442 pr_info("hdm_i2c_exit()\n");
443}
444
445module_init(hdm_i2c_init);
446module_exit(hdm_i2c_exit);
447
448MODULE_AUTHOR("Jain Roy Ambi <JainRoy.Ambi@microchip.com>");
449MODULE_AUTHOR("Andrey Shvetsov <andrey.shvetsov@k2l.de>");
450MODULE_DESCRIPTION("I2C Hardware Dependent Module");
451MODULE_LICENSE("GPL");
diff --git a/drivers/staging/most/hdm-usb/Kconfig b/drivers/staging/most/hdm-usb/Kconfig
new file mode 100644
index 000000000000..a482c3fdf34b
--- /dev/null
+++ b/drivers/staging/most/hdm-usb/Kconfig
@@ -0,0 +1,14 @@
1#
2# MOST USB configuration
3#
4
5config HDM_USB
6 tristate "USB HDM"
7 depends on USB
8 select AIM_NETWORK
9 ---help---
10 Say Y here if you want to connect via USB to network tranceiver.
11 This device driver depends on the networking AIM.
12
13 To compile this driver as a module, choose M here: the
14 module will be called hdm_usb.
diff --git a/drivers/staging/most/hdm-usb/Makefile b/drivers/staging/most/hdm-usb/Makefile
new file mode 100644
index 000000000000..6bbacb41e94b
--- /dev/null
+++ b/drivers/staging/most/hdm-usb/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_HDM_USB) += hdm_usb.o
2
3ccflags-y += -Idrivers/staging/most/mostcore/
4ccflags-y += -Idrivers/staging/most/aim-network/
diff --git a/drivers/staging/most/hdm-usb/hdm_usb.c b/drivers/staging/most/hdm-usb/hdm_usb.c
new file mode 100644
index 000000000000..305303f2f17c
--- /dev/null
+++ b/drivers/staging/most/hdm-usb/hdm_usb.c
@@ -0,0 +1,1454 @@
1/*
2 * hdm_usb.c - Hardware dependent module for USB
3 *
4 * Copyright (C) 2013-2015 Microchip Technology Germany II GmbH & Co. KG
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * This file is licensed under GPLv2.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15#include <linux/module.h>
16#include <linux/fs.h>
17#include <linux/usb.h>
18#include <linux/slab.h>
19#include <linux/init.h>
20#include <linux/cdev.h>
21#include <linux/device.h>
22#include <linux/list.h>
23#include <linux/completion.h>
24#include <linux/mutex.h>
25#include <linux/spinlock.h>
26#include <linux/interrupt.h>
27#include <linux/workqueue.h>
28#include <linux/sysfs.h>
29#include <linux/dma-mapping.h>
30#include <linux/etherdevice.h>
31#include <linux/uaccess.h>
32#include "mostcore.h"
33#include "networking.h"
34
35#define USB_MTU 512
36#define NO_ISOCHRONOUS_URB 0
37#define AV_PACKETS_PER_XACT 2
38#define BUF_CHAIN_SIZE 0xFFFF
39#define MAX_NUM_ENDPOINTS 30
40#define MAX_SUFFIX_LEN 10
41#define MAX_STRING_LEN 80
42#define MAX_BUF_SIZE 0xFFFF
43#define CEILING(x, y) (((x) + (y) - 1) / (y))
44
45#define USB_VENDOR_ID_SMSC 0x0424 /* VID: SMSC */
46#define USB_DEV_ID_BRDG 0xC001 /* PID: USB Bridge */
47#define USB_DEV_ID_INIC 0xCF18 /* PID: USB INIC */
48#define HW_RESYNC 0x0000
49/* DRCI Addresses */
50#define DRCI_REG_NI_STATE 0x0100
51#define DRCI_REG_PACKET_BW 0x0101
52#define DRCI_REG_NODE_ADDR 0x0102
53#define DRCI_REG_NODE_POS 0x0103
54#define DRCI_REG_MEP_FILTER 0x0140
55#define DRCI_REG_HASH_TBL0 0x0141
56#define DRCI_REG_HASH_TBL1 0x0142
57#define DRCI_REG_HASH_TBL2 0x0143
58#define DRCI_REG_HASH_TBL3 0x0144
59#define DRCI_REG_HW_ADDR_HI 0x0145
60#define DRCI_REG_HW_ADDR_MI 0x0146
61#define DRCI_REG_HW_ADDR_LO 0x0147
62#define DRCI_READ_REQ 0xA0
63#define DRCI_WRITE_REQ 0xA1
64
65/**
66 * struct buf_anchor - used to create a list of pending URBs
67 * @urb: pointer to USB request block
68 * @clear_work_obj:
69 * @list: linked list
70 * @urb_completion:
71 */
72struct buf_anchor {
73 struct urb *urb;
74 struct work_struct clear_work_obj;
75 struct list_head list;
76 struct completion urb_compl;
77};
78#define to_buf_anchor(w) container_of(w, struct buf_anchor, clear_work_obj)
79
80/**
81 * struct most_dci_obj - Direct Communication Interface
82 * @kobj:position in sysfs
83 * @usb_device: pointer to the usb device
84 */
85struct most_dci_obj {
86 struct kobject kobj;
87 struct usb_device *usb_device;
88};
89#define to_dci_obj(p) container_of(p, struct most_dci_obj, kobj)
90
91/**
92 * struct most_dev - holds all usb interface specific stuff
93 * @parent: parent object in sysfs
94 * @usb_device: pointer to usb device
95 * @iface: hardware interface
96 * @cap: channel capabilities
97 * @conf: channel configuration
98 * @dci: direct communication interface of hardware
99 * @hw_addr: MAC address of hardware
100 * @ep_address: endpoint address table
101 * @link_stat: link status of hardware
102 * @description: device description
103 * @suffix: suffix for channel name
104 * @anchor_list_lock: locks list access
105 * @padding_active: indicates channel uses padding
106 * @is_channel_healthy: health status table of each channel
107 * @anchor_list: list of anchored items
108 * @io_mutex: synchronize I/O with disconnect
109 * @link_stat_timer: timer for link status reports
110 * @poll_work_obj: work for polling link status
111 */
112struct most_dev {
113 struct kobject *parent;
114 struct usb_device *usb_device;
115 struct most_interface iface;
116 struct most_channel_capability *cap;
117 struct most_channel_config *conf;
118 struct most_dci_obj *dci;
119 u8 hw_addr[6];
120 u8 *ep_address;
121 u16 link_stat;
122 char description[MAX_STRING_LEN];
123 char suffix[MAX_NUM_ENDPOINTS][MAX_SUFFIX_LEN];
124 spinlock_t anchor_list_lock[MAX_NUM_ENDPOINTS];
125 bool padding_active[MAX_NUM_ENDPOINTS];
126 bool is_channel_healthy[MAX_NUM_ENDPOINTS];
127 struct list_head *anchor_list;
128 struct mutex io_mutex;
129 struct timer_list link_stat_timer;
130 struct work_struct poll_work_obj;
131};
132#define to_mdev(d) container_of(d, struct most_dev, iface)
133#define to_mdev_from_work(w) container_of(w, struct most_dev, poll_work_obj)
134
135static struct workqueue_struct *schedule_usb_work;
136static void wq_clear_halt(struct work_struct *wq_obj);
137static void wq_netinfo(struct work_struct *wq_obj);
138
139/**
140 * trigger_resync_vr - Vendor request to trigger HW re-sync mechanism
141 * @dev: usb device
142 *
143 */
144static void trigger_resync_vr(struct usb_device *dev)
145{
146 int retval;
147 u8 request_type = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT;
148 int *data = kzalloc(sizeof(*data), GFP_KERNEL);
149
150 if (!data)
151 goto error;
152 *data = HW_RESYNC;
153 retval = usb_control_msg(dev,
154 usb_sndctrlpipe(dev, 0),
155 0,
156 request_type,
157 0,
158 0,
159 data,
160 0,
161 5 * HZ);
162 kfree(data);
163 if (retval >= 0)
164 return;
165error:
166 dev_err(&dev->dev, "Vendor request \"stall\" failed\n");
167}
168
169/**
170 * drci_rd_reg - read a DCI register
171 * @dev: usb device
172 * @reg: register address
173 * @buf: buffer to store data
174 *
175 * This is reads data from INIC's direct register communication interface
176 */
177static inline int drci_rd_reg(struct usb_device *dev, u16 reg, void *buf)
178{
179 return usb_control_msg(dev,
180 usb_rcvctrlpipe(dev, 0),
181 DRCI_READ_REQ,
182 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
183 0x0000,
184 reg,
185 buf,
186 2,
187 5 * HZ);
188}
189
190/**
191 * drci_wr_reg - write a DCI register
192 * @dev: usb device
193 * @reg: register address
194 * @data: data to write
195 *
196 * This is writes data to INIC's direct register communication interface
197 */
198static inline int drci_wr_reg(struct usb_device *dev, u16 reg, u16 data)
199{
200 return usb_control_msg(dev,
201 usb_sndctrlpipe(dev, 0),
202 DRCI_WRITE_REQ,
203 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
204 data,
205 reg,
206 NULL,
207 0,
208 5 * HZ);
209}
210
211/**
212 * free_anchored_buffers - free device's anchored items
213 * @mdev: the device
214 * @channel: channel ID
215 */
216static void free_anchored_buffers(struct most_dev *mdev, unsigned int channel)
217{
218 struct mbo *mbo;
219 struct buf_anchor *anchor, *tmp;
220 unsigned long flags;
221
222 spin_lock_irqsave(&mdev->anchor_list_lock[channel], flags);
223 list_for_each_entry_safe(anchor, tmp, &mdev->anchor_list[channel], list) {
224 struct urb *urb = anchor->urb;
225
226 spin_unlock_irqrestore(&mdev->anchor_list_lock[channel], flags);
227 if (likely(urb)) {
228 mbo = urb->context;
229 if (!irqs_disabled()) {
230 usb_kill_urb(urb);
231 } else {
232 usb_unlink_urb(urb);
233 wait_for_completion(&anchor->urb_compl);
234 }
235 if ((mbo) && (mbo->complete)) {
236 mbo->status = MBO_E_CLOSE;
237 mbo->processed_length = 0;
238 mbo->complete(mbo);
239 }
240 usb_free_urb(urb);
241 }
242 spin_lock_irqsave(&mdev->anchor_list_lock[channel], flags);
243 list_del(&anchor->list);
244 kfree(anchor);
245 }
246 spin_unlock_irqrestore(&mdev->anchor_list_lock[channel], flags);
247}
248
249/**
250 * get_stream_frame_size - calculate frame size of current configuration
251 * @cfg: channel configuration
252 */
253static unsigned int get_stream_frame_size(struct most_channel_config *cfg)
254{
255 unsigned int frame_size = 0;
256 unsigned int sub_size = cfg->subbuffer_size;
257
258 if (!sub_size) {
259 pr_warn("Misconfig: Subbuffer size zero.\n");
260 return frame_size;
261 }
262 switch (cfg->data_type) {
263 case MOST_CH_ISOC_AVP:
264 frame_size = AV_PACKETS_PER_XACT * sub_size;
265 break;
266 case MOST_CH_SYNC:
267 if (cfg->packets_per_xact == 0) {
268 pr_warn("Misconfig: Packets per XACT zero\n");
269 frame_size = 0;
270 } else if (cfg->packets_per_xact == 0xFF)
271 frame_size = (USB_MTU / sub_size) * sub_size;
272 else
273 frame_size = cfg->packets_per_xact * sub_size;
274 break;
275 default:
276 pr_warn("Query frame size of non-streaming channel\n");
277 break;
278 }
279 return frame_size;
280}
281
282/**
283 * hdm_poison_channel - mark buffers of this channel as invalid
284 * @iface: pointer to the interface
285 * @channel: channel ID
286 *
287 * This unlinks all URBs submitted to the HCD,
288 * calls the associated completion function of the core and removes
289 * them from the list.
290 *
291 * Returns 0 on success or error code otherwise.
292 */
293static int hdm_poison_channel(struct most_interface *iface, int channel)
294{
295 struct most_dev *mdev;
296
297 mdev = to_mdev(iface);
298 if (unlikely(!iface)) {
299 dev_warn(&mdev->usb_device->dev, "Poison: Bad interface.\n");
300 return -EIO;
301 }
302 if (unlikely((channel < 0) || (channel >= iface->num_channels))) {
303 dev_warn(&mdev->usb_device->dev, "Channel ID out of range.\n");
304 return -ECHRNG;
305 }
306
307 mdev->is_channel_healthy[channel] = false;
308
309 mutex_lock(&mdev->io_mutex);
310 free_anchored_buffers(mdev, channel);
311 if (mdev->padding_active[channel] == true)
312 mdev->padding_active[channel] = false;
313
314 if (mdev->conf[channel].data_type == MOST_CH_ASYNC) {
315 del_timer_sync(&mdev->link_stat_timer);
316 cancel_work_sync(&mdev->poll_work_obj);
317 }
318 mutex_unlock(&mdev->io_mutex);
319 return 0;
320}
321
322/**
323 * hdm_add_padding - add padding bytes
324 * @mdev: most device
325 * @channel: channel ID
326 * @mbo: buffer object
327 *
328 * This inserts the INIC hardware specific padding bytes into a streaming
329 * channel's buffer
330 */
331static int hdm_add_padding(struct most_dev *mdev, int channel, struct mbo *mbo)
332{
333 struct most_channel_config *conf = &mdev->conf[channel];
334 unsigned int j, num_frames, frame_size;
335 u16 rd_addr, wr_addr;
336
337 frame_size = get_stream_frame_size(conf);
338 if (!frame_size)
339 return -EIO;
340 num_frames = mbo->buffer_length / frame_size;
341
342 if (num_frames < 1) {
343 dev_err(&mdev->usb_device->dev,
344 "Missed minimal transfer unit.\n");
345 return -EIO;
346 }
347
348 for (j = 1; j < num_frames; j++) {
349 wr_addr = (num_frames - j) * USB_MTU;
350 rd_addr = (num_frames - j) * frame_size;
351 memmove(mbo->virt_address + wr_addr,
352 mbo->virt_address + rd_addr,
353 frame_size);
354 }
355 mbo->buffer_length = num_frames * USB_MTU;
356 return 0;
357}
358
359/**
360 * hdm_remove_padding - remove padding bytes
361 * @mdev: most device
362 * @channel: channel ID
363 * @mbo: buffer object
364 *
365 * This takes the INIC hardware specific padding bytes off a streaming
366 * channel's buffer.
367 */
368static int hdm_remove_padding(struct most_dev *mdev, int channel, struct mbo *mbo)
369{
370 unsigned int j, num_frames, frame_size;
371 struct most_channel_config *const conf = &mdev->conf[channel];
372
373 frame_size = get_stream_frame_size(conf);
374 if (!frame_size)
375 return -EIO;
376 num_frames = mbo->processed_length / USB_MTU;
377
378 for (j = 1; j < num_frames; j++)
379 memmove(mbo->virt_address + frame_size * j,
380 mbo->virt_address + USB_MTU * j,
381 frame_size);
382
383 mbo->processed_length = frame_size * num_frames;
384 return 0;
385}
386
387/**
388 * hdm_write_completion - completion function for submitted Tx URBs
389 * @urb: the URB that has been completed
390 *
391 * This checks the status of the completed URB. In case the URB has been
392 * unlinked before, it is immediately freed. On any other error the MBO
393 * transfer flag is set. On success it frees allocated resources and calls
394 * the completion function.
395 *
396 * Context: interrupt!
397 */
398static void hdm_write_completion(struct urb *urb)
399{
400 struct mbo *mbo;
401 struct buf_anchor *anchor;
402 struct most_dev *mdev;
403 struct device *dev;
404 unsigned int channel;
405 unsigned long flags;
406
407 mbo = urb->context;
408 anchor = mbo->priv;
409 mdev = to_mdev(mbo->ifp);
410 channel = mbo->hdm_channel_id;
411 dev = &mdev->usb_device->dev;
412
413 if ((urb->status == -ENOENT) || (urb->status == -ECONNRESET) ||
414 (mdev->is_channel_healthy[channel] == false)) {
415 complete(&anchor->urb_compl);
416 return;
417 }
418
419 if (unlikely(urb->status && !(urb->status == -ENOENT ||
420 urb->status == -ECONNRESET ||
421 urb->status == -ESHUTDOWN))) {
422 mbo->processed_length = 0;
423 switch (urb->status) {
424 case -EPIPE:
425 dev_warn(dev, "Broken OUT pipe detected\n");
426 most_stop_enqueue(&mdev->iface, channel);
427 mbo->status = MBO_E_INVAL;
428 usb_unlink_urb(urb);
429 INIT_WORK(&anchor->clear_work_obj, wq_clear_halt);
430 queue_work(schedule_usb_work, &anchor->clear_work_obj);
431 return;
432 case -ENODEV:
433 case -EPROTO:
434 mbo->status = MBO_E_CLOSE;
435 break;
436 default:
437 mbo->status = MBO_E_INVAL;
438 break;
439 }
440 } else {
441 mbo->status = MBO_SUCCESS;
442 mbo->processed_length = urb->actual_length;
443 }
444
445 spin_lock_irqsave(&mdev->anchor_list_lock[channel], flags);
446 list_del(&anchor->list);
447 spin_unlock_irqrestore(&mdev->anchor_list_lock[channel], flags);
448 kfree(anchor);
449
450 if (likely(mbo->complete))
451 mbo->complete(mbo);
452 usb_free_urb(urb);
453}
454
455/**
456 * hdm_read_completion - completion funciton for submitted Rx URBs
457 * @urb: the URB that has been completed
458 *
459 * This checks the status of the completed URB. In case the URB has been
460 * unlinked before it is immediately freed. On any other error the MBO transfer
461 * flag is set. On success it frees allocated resources, removes
462 * padding bytes -if necessary- and calls the completion function.
463 *
464 * Context: interrupt!
465 *
466 * **************************************************************************
467 * Error codes returned by in urb->status
468 * or in iso_frame_desc[n].status (for ISO)
469 * *************************************************************************
470 *
471 * USB device drivers may only test urb status values in completion handlers.
472 * This is because otherwise there would be a race between HCDs updating
473 * these values on one CPU, and device drivers testing them on another CPU.
474 *
475 * A transfer's actual_length may be positive even when an error has been
476 * reported. That's because transfers often involve several packets, so that
477 * one or more packets could finish before an error stops further endpoint I/O.
478 *
479 * For isochronous URBs, the urb status value is non-zero only if the URB is
480 * unlinked, the device is removed, the host controller is disabled or the total
481 * transferred length is less than the requested length and the URB_SHORT_NOT_OK
482 * flag is set. Completion handlers for isochronous URBs should only see
483 * urb->status set to zero, -ENOENT, -ECONNRESET, -ESHUTDOWN, or -EREMOTEIO.
484 * Individual frame descriptor status fields may report more status codes.
485 *
486 *
487 * 0 Transfer completed successfully
488 *
489 * -ENOENT URB was synchronously unlinked by usb_unlink_urb
490 *
491 * -EINPROGRESS URB still pending, no results yet
492 * (That is, if drivers see this it's a bug.)
493 *
494 * -EPROTO (*, **) a) bitstuff error
495 * b) no response packet received within the
496 * prescribed bus turn-around time
497 * c) unknown USB error
498 *
499 * -EILSEQ (*, **) a) CRC mismatch
500 * b) no response packet received within the
501 * prescribed bus turn-around time
502 * c) unknown USB error
503 *
504 * Note that often the controller hardware does not
505 * distinguish among cases a), b), and c), so a
506 * driver cannot tell whether there was a protocol
507 * error, a failure to respond (often caused by
508 * device disconnect), or some other fault.
509 *
510 * -ETIME (**) No response packet received within the prescribed
511 * bus turn-around time. This error may instead be
512 * reported as -EPROTO or -EILSEQ.
513 *
514 * -ETIMEDOUT Synchronous USB message functions use this code
515 * to indicate timeout expired before the transfer
516 * completed, and no other error was reported by HC.
517 *
518 * -EPIPE (**) Endpoint stalled. For non-control endpoints,
519 * reset this status with usb_clear_halt().
520 *
521 * -ECOMM During an IN transfer, the host controller
522 * received data from an endpoint faster than it
523 * could be written to system memory
524 *
525 * -ENOSR During an OUT transfer, the host controller
526 * could not retrieve data from system memory fast
527 * enough to keep up with the USB data rate
528 *
529 * -EOVERFLOW (*) The amount of data returned by the endpoint was
530 * greater than either the max packet size of the
531 * endpoint or the remaining buffer size. "Babble".
532 *
533 * -EREMOTEIO The data read from the endpoint did not fill the
534 * specified buffer, and URB_SHORT_NOT_OK was set in
535 * urb->transfer_flags.
536 *
537 * -ENODEV Device was removed. Often preceded by a burst of
538 * other errors, since the hub driver doesn't detect
539 * device removal events immediately.
540 *
541 * -EXDEV ISO transfer only partially completed
542 * (only set in iso_frame_desc[n].status, not urb->status)
543 *
544 * -EINVAL ISO madness, if this happens: Log off and go home
545 *
546 * -ECONNRESET URB was asynchronously unlinked by usb_unlink_urb
547 *
548 * -ESHUTDOWN The device or host controller has been disabled due
549 * to some problem that could not be worked around,
550 * such as a physical disconnect.
551 *
552 *
553 * (*) Error codes like -EPROTO, -EILSEQ and -EOVERFLOW normally indicate
554 * hardware problems such as bad devices (including firmware) or cables.
555 *
556 * (**) This is also one of several codes that different kinds of host
557 * controller use to indicate a transfer has failed because of device
558 * disconnect. In the interval before the hub driver starts disconnect
559 * processing, devices may receive such fault reports for every request.
560 *
561 * See <https://www.kernel.org/doc/Documentation/usb/error-codes.txt>
562 */
563static void hdm_read_completion(struct urb *urb)
564{
565 struct mbo *mbo;
566 struct buf_anchor *anchor;
567 struct most_dev *mdev;
568 struct device *dev;
569 unsigned long flags;
570 unsigned int channel;
571 struct most_channel_config *conf;
572
573 mbo = urb->context;
574 anchor = mbo->priv;
575 mdev = to_mdev(mbo->ifp);
576 channel = mbo->hdm_channel_id;
577 dev = &mdev->usb_device->dev;
578
579 if ((urb->status == -ENOENT) || (urb->status == -ECONNRESET) ||
580 (mdev->is_channel_healthy[channel] == false)) {
581 complete(&anchor->urb_compl);
582 return;
583 }
584
585 conf = &mdev->conf[channel];
586
587 if (unlikely(urb->status && !(urb->status == -ENOENT ||
588 urb->status == -ECONNRESET ||
589 urb->status == -ESHUTDOWN))) {
590 mbo->processed_length = 0;
591 switch (urb->status) {
592 case -EPIPE:
593 dev_warn(dev, "Broken IN pipe detected\n");
594 mbo->status = MBO_E_INVAL;
595 usb_unlink_urb(urb);
596 INIT_WORK(&anchor->clear_work_obj, wq_clear_halt);
597 queue_work(schedule_usb_work, &anchor->clear_work_obj);
598 return;
599 case -ENODEV:
600 case -EPROTO:
601 mbo->status = MBO_E_CLOSE;
602 break;
603 case -EOVERFLOW:
604 dev_warn(dev, "Babble on IN pipe detected\n");
605 default:
606 mbo->status = MBO_E_INVAL;
607 break;
608 }
609 } else {
610 mbo->processed_length = urb->actual_length;
611 if (mdev->padding_active[channel] == false) {
612 mbo->status = MBO_SUCCESS;
613 } else {
614 if (hdm_remove_padding(mdev, channel, mbo)) {
615 mbo->processed_length = 0;
616 mbo->status = MBO_E_INVAL;
617 } else {
618 mbo->status = MBO_SUCCESS;
619 }
620 }
621 }
622 spin_lock_irqsave(&mdev->anchor_list_lock[channel], flags);
623 list_del(&anchor->list);
624 spin_unlock_irqrestore(&mdev->anchor_list_lock[channel], flags);
625 kfree(anchor);
626
627 if (likely(mbo->complete))
628 mbo->complete(mbo);
629 usb_free_urb(urb);
630}
631
632/**
633 * hdm_enqueue - receive a buffer to be used for data transfer
634 * @iface: interface to enqueue to
635 * @channel: ID of the channel
636 * @mbo: pointer to the buffer object
637 *
638 * This allocates a new URB and fills it according to the channel
639 * that is being used for transmission of data. Before the URB is
640 * submitted it is stored in the private anchor list.
641 *
642 * Returns 0 on success. On any error the URB is freed and a error code
643 * is returned.
644 *
645 * Context: Could in _some_ cases be interrupt!
646 */
647static int hdm_enqueue(struct most_interface *iface, int channel, struct mbo *mbo)
648{
649 struct most_dev *mdev;
650 struct buf_anchor *anchor;
651 struct most_channel_config *conf;
652 struct device *dev;
653 int retval = 0;
654 struct urb *urb;
655 unsigned long flags;
656 unsigned long length;
657 void *virt_address;
658
659 if (unlikely(!iface || !mbo))
660 return -EIO;
661 if (unlikely(iface->num_channels <= channel) || (channel < 0))
662 return -ECHRNG;
663
664 mdev = to_mdev(iface);
665 conf = &mdev->conf[channel];
666 dev = &mdev->usb_device->dev;
667
668 if (!mdev->usb_device)
669 return -ENODEV;
670
671 urb = usb_alloc_urb(NO_ISOCHRONOUS_URB, GFP_ATOMIC);
672 if (!urb) {
673 dev_err(dev, "Failed to allocate URB\n");
674 return -ENOMEM;
675 }
676
677 anchor = kzalloc(sizeof(*anchor), GFP_ATOMIC);
678 if (!anchor) {
679 retval = -ENOMEM;
680 goto _error;
681 }
682
683 anchor->urb = urb;
684 init_completion(&anchor->urb_compl);
685 mbo->priv = anchor;
686
687 spin_lock_irqsave(&mdev->anchor_list_lock[channel], flags);
688 list_add_tail(&anchor->list, &mdev->anchor_list[channel]);
689 spin_unlock_irqrestore(&mdev->anchor_list_lock[channel], flags);
690
691 if ((mdev->padding_active[channel] == true) &&
692 (conf->direction & MOST_CH_TX))
693 if (hdm_add_padding(mdev, channel, mbo)) {
694 retval = -EIO;
695 goto _error_1;
696 }
697
698 urb->transfer_dma = mbo->bus_address;
699 virt_address = mbo->virt_address;
700 length = mbo->buffer_length;
701
702 if (conf->direction & MOST_CH_TX) {
703 usb_fill_bulk_urb(urb, mdev->usb_device,
704 usb_sndbulkpipe(mdev->usb_device,
705 mdev->ep_address[channel]),
706 virt_address,
707 length,
708 hdm_write_completion,
709 mbo);
710 if (conf->data_type != MOST_CH_ISOC_AVP)
711 urb->transfer_flags |= URB_ZERO_PACKET;
712 } else {
713 usb_fill_bulk_urb(urb, mdev->usb_device,
714 usb_rcvbulkpipe(mdev->usb_device,
715 mdev->ep_address[channel]),
716 virt_address,
717 length,
718 hdm_read_completion,
719 mbo);
720 }
721 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
722
723 retval = usb_submit_urb(urb, GFP_KERNEL);
724 if (retval) {
725 dev_err(dev, "URB submit failed with error %d.\n", retval);
726 goto _error_1;
727 }
728 return 0;
729
730_error_1:
731 spin_lock_irqsave(&mdev->anchor_list_lock[channel], flags);
732 list_del(&anchor->list);
733 spin_unlock_irqrestore(&mdev->anchor_list_lock[channel], flags);
734 kfree(anchor);
735_error:
736 usb_free_urb(urb);
737 return retval;
738}
739
740/**
741 * hdm_configure_channel - receive channel configuration from core
742 * @iface: interface
743 * @channel: channel ID
744 * @conf: structure that holds the configuration information
745 */
746static int hdm_configure_channel(struct most_interface *iface, int channel,
747 struct most_channel_config *conf)
748{
749 unsigned int num_frames;
750 unsigned int frame_size;
751 unsigned int temp_size;
752 unsigned int tail_space;
753 struct most_dev *mdev;
754 struct device *dev;
755
756 mdev = to_mdev(iface);
757 mdev->is_channel_healthy[channel] = true;
758 dev = &mdev->usb_device->dev;
759
760 if (unlikely(!iface || !conf)) {
761 dev_err(dev, "Bad interface or config pointer.\n");
762 return -EINVAL;
763 }
764 if (unlikely((channel < 0) || (channel >= iface->num_channels))) {
765 dev_err(dev, "Channel ID out of range.\n");
766 return -EINVAL;
767 }
768 if ((!conf->num_buffers) || (!conf->buffer_size)) {
769 dev_err(dev, "Misconfig: buffer size or #buffers zero.\n");
770 return -EINVAL;
771 }
772
773 if (!(conf->data_type == MOST_CH_SYNC) &&
774 !((conf->data_type == MOST_CH_ISOC_AVP) &&
775 (conf->packets_per_xact != 0xFF))) {
776 mdev->padding_active[channel] = false;
777 goto exit;
778 }
779
780 mdev->padding_active[channel] = true;
781 temp_size = conf->buffer_size;
782
783 if ((conf->data_type != MOST_CH_SYNC) &&
784 (conf->data_type != MOST_CH_ISOC_AVP)) {
785 dev_warn(dev, "Unsupported data type\n");
786 return -EINVAL;
787 }
788
789 frame_size = get_stream_frame_size(conf);
790 if ((frame_size == 0) || (frame_size > USB_MTU)) {
791 dev_warn(dev, "Misconfig: frame size wrong\n");
792 return -EINVAL;
793 }
794
795 if (conf->buffer_size % frame_size) {
796 u16 tmp_val;
797
798 tmp_val = conf->buffer_size / frame_size;
799 conf->buffer_size = tmp_val * frame_size;
800 dev_notice(dev,
801 "Channel %d - rouding buffer size to %d bytes, "
802 "channel config says %d bytes\n",
803 channel,
804 conf->buffer_size,
805 temp_size);
806 }
807
808 num_frames = conf->buffer_size / frame_size;
809 tail_space = num_frames * (USB_MTU - frame_size);
810 temp_size += tail_space;
811
812 /* calculate extra length to comply w/ HW padding */
813 conf->extra_len = (CEILING(temp_size, USB_MTU) * USB_MTU)
814 - conf->buffer_size;
815exit:
816 mdev->conf[channel] = *conf;
817 return 0;
818}
819
820/**
821 * hdm_update_netinfo - retrieve latest networking information
822 * @mdev: device interface
823 *
824 * This triggers the USB vendor requests to read the hardware address and
825 * the current link status of the attached device.
826 */
827static int hdm_update_netinfo(struct most_dev *mdev)
828{
829 struct device *dev = &mdev->usb_device->dev;
830 int i;
831 u16 link;
832 u8 addr[6];
833
834 if (!is_valid_ether_addr(mdev->hw_addr)) {
835 if (0 > drci_rd_reg(mdev->usb_device,
836 DRCI_REG_HW_ADDR_HI, addr)) {
837 dev_err(dev, "Vendor request \"hw_addr_hi\" failed\n");
838 return -1;
839 }
840 if (0 > drci_rd_reg(mdev->usb_device,
841 DRCI_REG_HW_ADDR_MI, addr + 2)) {
842 dev_err(dev, "Vendor request \"hw_addr_mid\" failed\n");
843 return -1;
844 }
845 if (0 > drci_rd_reg(mdev->usb_device,
846 DRCI_REG_HW_ADDR_LO, addr + 4)) {
847 dev_err(dev, "Vendor request \"hw_addr_low\" failed\n");
848 return -1;
849 }
850 mutex_lock(&mdev->io_mutex);
851 for (i = 0; i < 6; i++)
852 mdev->hw_addr[i] = addr[i];
853 mutex_unlock(&mdev->io_mutex);
854
855 }
856 if (0 > drci_rd_reg(mdev->usb_device, DRCI_REG_NI_STATE, &link)) {
857 dev_err(dev, "Vendor request \"link status\" failed\n");
858 return -1;
859 }
860 le16_to_cpus(&link);
861 mutex_lock(&mdev->io_mutex);
862 mdev->link_stat = link;
863 mutex_unlock(&mdev->io_mutex);
864 return 0;
865}
866
867/**
868 * hdm_request_netinfo - request network information
869 * @iface: pointer to interface
870 * @channel: channel ID
871 *
872 * This is used as trigger to set up the link status timer that
873 * polls for the NI state of the INIC every 2 seconds.
874 *
875 */
876static void hdm_request_netinfo(struct most_interface *iface, int channel)
877{
878 struct most_dev *mdev;
879
880 BUG_ON(!iface);
881 mdev = to_mdev(iface);
882 mdev->link_stat_timer.expires = jiffies + HZ;
883 mod_timer(&mdev->link_stat_timer, mdev->link_stat_timer.expires);
884}
885
886/**
887 * link_stat_timer_handler - add work to link_stat work queue
888 * @data: pointer to USB device instance
889 *
890 * The handler runs in interrupt context. That's why we need to defer the
891 * tasks to a work queue.
892 */
893static void link_stat_timer_handler(unsigned long data)
894{
895 struct most_dev *mdev = (struct most_dev *)data;
896
897 queue_work(schedule_usb_work, &mdev->poll_work_obj);
898 mdev->link_stat_timer.expires = jiffies + (2 * HZ);
899 add_timer(&mdev->link_stat_timer);
900}
901
902/**
903 * wq_netinfo - work queue function
904 * @wq_obj: object that holds data for our deferred work to do
905 *
906 * This retrieves the network interface status of the USB INIC
907 * and compares it with the current status. If the status has
908 * changed, it updates the status of the core.
909 */
910static void wq_netinfo(struct work_struct *wq_obj)
911{
912 struct most_dev *mdev;
913 int i, prev_link_stat;
914 u8 prev_hw_addr[6];
915
916 mdev = to_mdev_from_work(wq_obj);
917 prev_link_stat = mdev->link_stat;
918
919 for (i = 0; i < 6; i++)
920 prev_hw_addr[i] = mdev->hw_addr[i];
921
922 if (0 > hdm_update_netinfo(mdev))
923 return;
924 if ((prev_link_stat != mdev->link_stat) ||
925 (prev_hw_addr[0] != mdev->hw_addr[0]) ||
926 (prev_hw_addr[1] != mdev->hw_addr[1]) ||
927 (prev_hw_addr[2] != mdev->hw_addr[2]) ||
928 (prev_hw_addr[3] != mdev->hw_addr[3]) ||
929 (prev_hw_addr[4] != mdev->hw_addr[4]) ||
930 (prev_hw_addr[5] != mdev->hw_addr[5]))
931 most_deliver_netinfo(&mdev->iface, mdev->link_stat,
932 &mdev->hw_addr[0]);
933}
934
935/**
936 * wq_clear_halt - work queue function
937 * @wq_obj: work_struct object to execute
938 *
939 * This sends a clear_halt to the given USB pipe.
940 */
941static void wq_clear_halt(struct work_struct *wq_obj)
942{
943 struct buf_anchor *anchor;
944 struct most_dev *mdev;
945 struct mbo *mbo;
946 struct urb *urb;
947 unsigned int channel;
948 unsigned long flags;
949
950 anchor = to_buf_anchor(wq_obj);
951 urb = anchor->urb;
952 mbo = urb->context;
953 mdev = to_mdev(mbo->ifp);
954 channel = mbo->hdm_channel_id;
955
956 if (usb_clear_halt(urb->dev, urb->pipe))
957 dev_warn(&mdev->usb_device->dev, "Failed to reset endpoint.\n");
958
959 usb_free_urb(urb);
960 spin_lock_irqsave(&mdev->anchor_list_lock[channel], flags);
961 list_del(&anchor->list);
962 spin_unlock_irqrestore(&mdev->anchor_list_lock[channel], flags);
963
964 if (likely(mbo->complete))
965 mbo->complete(mbo);
966 if (mdev->conf[channel].direction & MOST_CH_TX)
967 most_resume_enqueue(&mdev->iface, channel);
968
969 kfree(anchor);
970}
971
972/**
973 * hdm_usb_fops - file operation table for USB driver
974 */
975static const struct file_operations hdm_usb_fops = {
976 .owner = THIS_MODULE,
977};
978
979/**
980 * usb_device_id - ID table for HCD device probing
981 */
982static struct usb_device_id usbid[] = {
983 { USB_DEVICE(USB_VENDOR_ID_SMSC, USB_DEV_ID_BRDG), },
984 { USB_DEVICE(USB_VENDOR_ID_SMSC, USB_DEV_ID_INIC), },
985 { } /* Terminating entry */
986};
987
988#define MOST_DCI_RO_ATTR(_name) \
989 struct most_dci_attribute most_dci_attr_##_name = \
990 __ATTR(_name, S_IRUGO, show_value, NULL)
991
992#define MOST_DCI_ATTR(_name) \
993 struct most_dci_attribute most_dci_attr_##_name = \
994 __ATTR(_name, S_IRUGO | S_IWUSR, show_value, store_value)
995
996/**
997 * struct most_dci_attribute - to access the attributes of a dci object
998 * @attr: attributes of a dci object
999 * @show: pointer to the show function
1000 * @store: pointer to the store function
1001 */
1002struct most_dci_attribute {
1003 struct attribute attr;
1004 ssize_t (*show)(struct most_dci_obj *d,
1005 struct most_dci_attribute *attr,
1006 char *buf);
1007 ssize_t (*store)(struct most_dci_obj *d,
1008 struct most_dci_attribute *attr,
1009 const char *buf,
1010 size_t count);
1011};
1012#define to_dci_attr(a) container_of(a, struct most_dci_attribute, attr)
1013
1014
1015/**
1016 * dci_attr_show - show function for dci object
1017 * @kobj: pointer to kobject
1018 * @attr: pointer to attribute struct
1019 * @buf: buffer
1020 */
1021static ssize_t dci_attr_show(struct kobject *kobj, struct attribute *attr,
1022 char *buf)
1023{
1024 struct most_dci_attribute *dci_attr = to_dci_attr(attr);
1025 struct most_dci_obj *dci_obj = to_dci_obj(kobj);
1026
1027 if (!dci_attr->show)
1028 return -EIO;
1029
1030 return dci_attr->show(dci_obj, dci_attr, buf);
1031}
1032
1033/**
1034 * dci_attr_store - store function for dci object
1035 * @kobj: pointer to kobject
1036 * @attr: pointer to attribute struct
1037 * @buf: buffer
1038 * @len: length of buffer
1039 */
1040static ssize_t dci_attr_store(struct kobject *kobj,
1041 struct attribute *attr,
1042 const char *buf,
1043 size_t len)
1044{
1045 struct most_dci_attribute *dci_attr = to_dci_attr(attr);
1046 struct most_dci_obj *dci_obj = to_dci_obj(kobj);
1047
1048 if (!dci_attr->store)
1049 return -EIO;
1050
1051 return dci_attr->store(dci_obj, dci_attr, buf, len);
1052}
1053
1054static const struct sysfs_ops most_dci_sysfs_ops = {
1055 .show = dci_attr_show,
1056 .store = dci_attr_store,
1057};
1058
1059/**
1060 * most_dci_release - release function for dci object
1061 * @kobj: pointer to kobject
1062 *
1063 * This frees the memory allocated for the dci object
1064 */
1065static void most_dci_release(struct kobject *kobj)
1066{
1067 struct most_dci_obj *dci_obj = to_dci_obj(kobj);
1068
1069 kfree(dci_obj);
1070}
1071
1072static ssize_t show_value(struct most_dci_obj *dci_obj,
1073 struct most_dci_attribute *attr, char *buf)
1074{
1075 u16 tmp_val;
1076 u16 reg_addr;
1077 int err;
1078
1079 if (!strcmp(attr->attr.name, "ni_state"))
1080 reg_addr = DRCI_REG_NI_STATE;
1081 else if (!strcmp(attr->attr.name, "packet_bandwidth"))
1082 reg_addr = DRCI_REG_PACKET_BW;
1083 else if (!strcmp(attr->attr.name, "node_address"))
1084 reg_addr = DRCI_REG_NODE_ADDR;
1085 else if (!strcmp(attr->attr.name, "node_position"))
1086 reg_addr = DRCI_REG_NODE_POS;
1087 else if (!strcmp(attr->attr.name, "mep_filter"))
1088 reg_addr = DRCI_REG_MEP_FILTER;
1089 else if (!strcmp(attr->attr.name, "mep_hash0"))
1090 reg_addr = DRCI_REG_HASH_TBL0;
1091 else if (!strcmp(attr->attr.name, "mep_hash1"))
1092 reg_addr = DRCI_REG_HASH_TBL1;
1093 else if (!strcmp(attr->attr.name, "mep_hash2"))
1094 reg_addr = DRCI_REG_HASH_TBL2;
1095 else if (!strcmp(attr->attr.name, "mep_hash3"))
1096 reg_addr = DRCI_REG_HASH_TBL3;
1097 else if (!strcmp(attr->attr.name, "mep_eui48_hi"))
1098 reg_addr = DRCI_REG_HW_ADDR_HI;
1099 else if (!strcmp(attr->attr.name, "mep_eui48_mi"))
1100 reg_addr = DRCI_REG_HW_ADDR_MI;
1101 else if (!strcmp(attr->attr.name, "mep_eui48_lo"))
1102 reg_addr = DRCI_REG_HW_ADDR_LO;
1103 else
1104 return -EIO;
1105
1106 err = drci_rd_reg(dci_obj->usb_device, reg_addr, &tmp_val);
1107 if (err < 0)
1108 return err;
1109
1110 return snprintf(buf, PAGE_SIZE, "%04x\n", le16_to_cpu(tmp_val));
1111}
1112
1113static ssize_t store_value(struct most_dci_obj *dci_obj,
1114 struct most_dci_attribute *attr,
1115 const char *buf, size_t count)
1116{
1117 u16 v16;
1118 u16 reg_addr;
1119 int err;
1120
1121 if (!strcmp(attr->attr.name, "mep_filter"))
1122 reg_addr = DRCI_REG_MEP_FILTER;
1123 else if (!strcmp(attr->attr.name, "mep_hash0"))
1124 reg_addr = DRCI_REG_HASH_TBL0;
1125 else if (!strcmp(attr->attr.name, "mep_hash1"))
1126 reg_addr = DRCI_REG_HASH_TBL1;
1127 else if (!strcmp(attr->attr.name, "mep_hash2"))
1128 reg_addr = DRCI_REG_HASH_TBL2;
1129 else if (!strcmp(attr->attr.name, "mep_hash3"))
1130 reg_addr = DRCI_REG_HASH_TBL3;
1131 else if (!strcmp(attr->attr.name, "mep_eui48_hi"))
1132 reg_addr = DRCI_REG_HW_ADDR_HI;
1133 else if (!strcmp(attr->attr.name, "mep_eui48_mi"))
1134 reg_addr = DRCI_REG_HW_ADDR_MI;
1135 else if (!strcmp(attr->attr.name, "mep_eui48_lo"))
1136 reg_addr = DRCI_REG_HW_ADDR_LO;
1137 else
1138 return -EIO;
1139
1140 err = kstrtou16(buf, 16, &v16);
1141 if (err)
1142 return err;
1143
1144 err = drci_wr_reg(dci_obj->usb_device, reg_addr, cpu_to_le16(v16));
1145 if (err < 0)
1146 return err;
1147
1148 return count;
1149}
1150
1151static MOST_DCI_RO_ATTR(ni_state);
1152static MOST_DCI_RO_ATTR(packet_bandwidth);
1153static MOST_DCI_RO_ATTR(node_address);
1154static MOST_DCI_RO_ATTR(node_position);
1155static MOST_DCI_ATTR(mep_filter);
1156static MOST_DCI_ATTR(mep_hash0);
1157static MOST_DCI_ATTR(mep_hash1);
1158static MOST_DCI_ATTR(mep_hash2);
1159static MOST_DCI_ATTR(mep_hash3);
1160static MOST_DCI_ATTR(mep_eui48_hi);
1161static MOST_DCI_ATTR(mep_eui48_mi);
1162static MOST_DCI_ATTR(mep_eui48_lo);
1163
1164/**
1165 * most_dci_def_attrs - array of default attribute files of the dci object
1166 */
1167static struct attribute *most_dci_def_attrs[] = {
1168 &most_dci_attr_ni_state.attr,
1169 &most_dci_attr_packet_bandwidth.attr,
1170 &most_dci_attr_node_address.attr,
1171 &most_dci_attr_node_position.attr,
1172 &most_dci_attr_mep_filter.attr,
1173 &most_dci_attr_mep_hash0.attr,
1174 &most_dci_attr_mep_hash1.attr,
1175 &most_dci_attr_mep_hash2.attr,
1176 &most_dci_attr_mep_hash3.attr,
1177 &most_dci_attr_mep_eui48_hi.attr,
1178 &most_dci_attr_mep_eui48_mi.attr,
1179 &most_dci_attr_mep_eui48_lo.attr,
1180 NULL,
1181};
1182
1183/**
1184 * DCI ktype
1185 */
1186static struct kobj_type most_dci_ktype = {
1187 .sysfs_ops = &most_dci_sysfs_ops,
1188 .release = most_dci_release,
1189 .default_attrs = most_dci_def_attrs,
1190};
1191
1192/**
1193 * create_most_dci_obj - allocates a dci object
1194 * @parent: parent kobject
1195 *
1196 * This creates a dci object and registers it with sysfs.
1197 * Returns a pointer to the object or NULL when something went wrong.
1198 */
1199static struct
1200most_dci_obj *create_most_dci_obj(struct kobject *parent)
1201{
1202 struct most_dci_obj *most_dci;
1203 int retval;
1204
1205 most_dci = kzalloc(sizeof(*most_dci), GFP_KERNEL);
1206 if (!most_dci)
1207 return NULL;
1208
1209 retval = kobject_init_and_add(&most_dci->kobj, &most_dci_ktype, parent,
1210 "dci");
1211 if (retval) {
1212 kobject_put(&most_dci->kobj);
1213 return NULL;
1214 }
1215 return most_dci;
1216}
1217
1218/**
1219 * destroy_most_dci_obj - DCI object release function
1220 * @p: pointer to dci object
1221 */
1222static void destroy_most_dci_obj(struct most_dci_obj *p)
1223{
1224 kobject_put(&p->kobj);
1225}
1226
1227/**
1228 * hdm_probe - probe function of USB device driver
1229 * @interface: Interface of the attached USB device
1230 * @id: Pointer to the USB ID table.
1231 *
1232 * This allocates and initializes the device instance, adds the new
1233 * entry to the internal list, scans the USB descriptors and registers
1234 * the interface with the core.
1235 * Additionally, the DCI objects are created and the hardware is sync'd.
1236 *
1237 * Return 0 on success. In case of an error a negative number is returned.
1238 */
1239static int
1240hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
1241{
1242 unsigned int i;
1243 unsigned int num_endpoints;
1244 struct most_channel_capability *tmp_cap;
1245 struct most_dev *mdev;
1246 struct usb_device *usb_dev;
1247 struct device *dev;
1248 struct usb_host_interface *usb_iface_desc;
1249 struct usb_endpoint_descriptor *ep_desc;
1250 int ret = 0;
1251
1252 usb_iface_desc = interface->cur_altsetting;
1253 usb_dev = interface_to_usbdev(interface);
1254 dev = &usb_dev->dev;
1255 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
1256 if (!mdev)
1257 goto exit_ENOMEM;
1258
1259 usb_set_intfdata(interface, mdev);
1260 num_endpoints = usb_iface_desc->desc.bNumEndpoints;
1261 mutex_init(&mdev->io_mutex);
1262 INIT_WORK(&mdev->poll_work_obj, wq_netinfo);
1263 init_timer(&mdev->link_stat_timer);
1264
1265 mdev->usb_device = usb_dev;
1266 mdev->link_stat_timer.function = link_stat_timer_handler;
1267 mdev->link_stat_timer.data = (unsigned long)mdev;
1268 mdev->link_stat_timer.expires = jiffies + (2 * HZ);
1269
1270 mdev->iface.mod = hdm_usb_fops.owner;
1271 mdev->iface.interface = ITYPE_USB;
1272 mdev->iface.configure = hdm_configure_channel;
1273 mdev->iface.request_netinfo = hdm_request_netinfo;
1274 mdev->iface.enqueue = hdm_enqueue;
1275 mdev->iface.poison_channel = hdm_poison_channel;
1276 mdev->iface.description = mdev->description;
1277 mdev->iface.num_channels = num_endpoints;
1278
1279 snprintf(mdev->description, sizeof(mdev->description),
1280 "usb_device %d-%s:%d.%d",
1281 usb_dev->bus->busnum,
1282 usb_dev->devpath,
1283 usb_dev->config->desc.bConfigurationValue,
1284 usb_iface_desc->desc.bInterfaceNumber);
1285
1286 mdev->conf = kcalloc(num_endpoints, sizeof(*mdev->conf), GFP_KERNEL);
1287 if (!mdev->conf)
1288 goto exit_free;
1289
1290 mdev->cap = kcalloc(num_endpoints, sizeof(*mdev->cap), GFP_KERNEL);
1291 if (!mdev->cap)
1292 goto exit_free1;
1293
1294 mdev->iface.channel_vector = mdev->cap;
1295 mdev->iface.priv = NULL;
1296
1297 mdev->ep_address =
1298 kcalloc(num_endpoints, sizeof(*mdev->ep_address), GFP_KERNEL);
1299 if (!mdev->ep_address)
1300 goto exit_free2;
1301
1302 mdev->anchor_list =
1303 kcalloc(num_endpoints, sizeof(*mdev->anchor_list), GFP_KERNEL);
1304 if (!mdev->anchor_list)
1305 goto exit_free3;
1306
1307 tmp_cap = mdev->cap;
1308 for (i = 0; i < num_endpoints; i++) {
1309 ep_desc = &usb_iface_desc->endpoint[i].desc;
1310 mdev->ep_address[i] = ep_desc->bEndpointAddress;
1311 mdev->padding_active[i] = false;
1312 mdev->is_channel_healthy[i] = true;
1313
1314 snprintf(&mdev->suffix[i][0], MAX_SUFFIX_LEN, "ep%02x",
1315 mdev->ep_address[i]);
1316
1317 tmp_cap->name_suffix = &mdev->suffix[i][0];
1318 tmp_cap->buffer_size_packet = MAX_BUF_SIZE;
1319 tmp_cap->buffer_size_streaming = MAX_BUF_SIZE;
1320 tmp_cap->num_buffers_packet = BUF_CHAIN_SIZE;
1321 tmp_cap->num_buffers_streaming = BUF_CHAIN_SIZE;
1322 tmp_cap->data_type = MOST_CH_CONTROL | MOST_CH_ASYNC |
1323 MOST_CH_ISOC_AVP | MOST_CH_SYNC;
1324 if (ep_desc->bEndpointAddress & USB_DIR_IN)
1325 tmp_cap->direction = MOST_CH_RX;
1326 else
1327 tmp_cap->direction = MOST_CH_TX;
1328 tmp_cap++;
1329 INIT_LIST_HEAD(&mdev->anchor_list[i]);
1330 spin_lock_init(&mdev->anchor_list_lock[i]);
1331 }
1332 dev_notice(dev, "claimed gadget: Vendor=%4.4x ProdID=%4.4x Bus=%02x Device=%02x\n",
1333 le16_to_cpu(usb_dev->descriptor.idVendor),
1334 le16_to_cpu(usb_dev->descriptor.idProduct),
1335 usb_dev->bus->busnum,
1336 usb_dev->devnum);
1337
1338 dev_notice(dev, "device path: /sys/bus/usb/devices/%d-%s:%d.%d\n",
1339 usb_dev->bus->busnum,
1340 usb_dev->devpath,
1341 usb_dev->config->desc.bConfigurationValue,
1342 usb_iface_desc->desc.bInterfaceNumber);
1343
1344 mdev->parent = most_register_interface(&mdev->iface);
1345 if (IS_ERR(mdev->parent)) {
1346 ret = PTR_ERR(mdev->parent);
1347 goto exit_free4;
1348 }
1349
1350 mutex_lock(&mdev->io_mutex);
1351 if (le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_INIC) {
1352 /* this increments the reference count of the instance
1353 * object of the core
1354 */
1355 mdev->dci = create_most_dci_obj(mdev->parent);
1356 if (!mdev->dci) {
1357 mutex_unlock(&mdev->io_mutex);
1358 most_deregister_interface(&mdev->iface);
1359 ret = -ENOMEM;
1360 goto exit_free4;
1361 }
1362
1363 kobject_uevent(&mdev->dci->kobj, KOBJ_ADD);
1364 mdev->dci->usb_device = mdev->usb_device;
1365 trigger_resync_vr(usb_dev);
1366 }
1367 mutex_unlock(&mdev->io_mutex);
1368 return 0;
1369
1370exit_free4:
1371 kfree(mdev->anchor_list);
1372exit_free3:
1373 kfree(mdev->ep_address);
1374exit_free2:
1375 kfree(mdev->cap);
1376exit_free1:
1377 kfree(mdev->conf);
1378exit_free:
1379 kfree(mdev);
1380exit_ENOMEM:
1381 if (ret == 0 || ret == -ENOMEM) {
1382 ret = -ENOMEM;
1383 dev_err(dev, "out of memory\n");
1384 }
1385 return ret;
1386}
1387
1388/**
1389 * hdm_disconnect - disconnect function of USB device driver
1390 * @interface: Interface of the attached USB device
1391 *
1392 * This deregisters the interface with the core, removes the kernel timer
1393 * and frees resources.
1394 *
1395 * Context: hub kernel thread
1396 */
1397static void hdm_disconnect(struct usb_interface *interface)
1398{
1399 struct most_dev *mdev;
1400
1401 mdev = usb_get_intfdata(interface);
1402 mutex_lock(&mdev->io_mutex);
1403 usb_set_intfdata(interface, NULL);
1404 mdev->usb_device = NULL;
1405 mutex_unlock(&mdev->io_mutex);
1406
1407 del_timer_sync(&mdev->link_stat_timer);
1408 cancel_work_sync(&mdev->poll_work_obj);
1409
1410 destroy_most_dci_obj(mdev->dci);
1411 most_deregister_interface(&mdev->iface);
1412
1413 kfree(mdev->anchor_list);
1414 kfree(mdev->cap);
1415 kfree(mdev->conf);
1416 kfree(mdev->ep_address);
1417 kfree(mdev);
1418}
1419
1420static struct usb_driver hdm_usb = {
1421 .name = "hdm_usb",
1422 .id_table = usbid,
1423 .probe = hdm_probe,
1424 .disconnect = hdm_disconnect,
1425};
1426
1427static int __init hdm_usb_init(void)
1428{
1429 pr_info("hdm_usb_init()\n");
1430 if (usb_register(&hdm_usb)) {
1431 pr_err("could not register hdm_usb driver\n");
1432 return -EIO;
1433 }
1434 schedule_usb_work = create_workqueue("hdmu_work");
1435 if (schedule_usb_work == NULL) {
1436 pr_err("could not create workqueue\n");
1437 usb_deregister(&hdm_usb);
1438 return -ENOMEM;
1439 }
1440 return 0;
1441}
1442
1443static void __exit hdm_usb_exit(void)
1444{
1445 pr_info("hdm_usb_exit()\n");
1446 destroy_workqueue(schedule_usb_work);
1447 usb_deregister(&hdm_usb);
1448}
1449
1450module_init(hdm_usb_init);
1451module_exit(hdm_usb_exit);
1452MODULE_LICENSE("GPL");
1453MODULE_AUTHOR("Christian Gromm <christian.gromm@microchip.com>");
1454MODULE_DESCRIPTION("HDM_4_USB");
diff --git a/drivers/staging/most/mostcore/Kconfig b/drivers/staging/most/mostcore/Kconfig
new file mode 100644
index 000000000000..38abf1b21b66
--- /dev/null
+++ b/drivers/staging/most/mostcore/Kconfig
@@ -0,0 +1,13 @@
1#
2# MOSTCore configuration
3#
4
5config MOSTCORE
6 tristate "MOST Core"
7
8 ---help---
9 Say Y here if you want to enable MOST support.
10 This device driver needs at least an additional AIM and HDM to work.
11
12 To compile this driver as a module, choose M here: the
13 module will be called mostcore.
diff --git a/drivers/staging/most/mostcore/Makefile b/drivers/staging/most/mostcore/Makefile
new file mode 100644
index 000000000000..a078f01cf7c2
--- /dev/null
+++ b/drivers/staging/most/mostcore/Makefile
@@ -0,0 +1,3 @@
1obj-$(CONFIG_MOSTCORE) += mostcore.o
2
3mostcore-objs := core.o
diff --git a/drivers/staging/most/mostcore/core.c b/drivers/staging/most/mostcore/core.c
new file mode 100644
index 000000000000..7bb16db42893
--- /dev/null
+++ b/drivers/staging/most/mostcore/core.c
@@ -0,0 +1,1932 @@
1/*
2 * core.c - Implementation of core module of MOST Linux driver stack
3 *
4 * Copyright (C) 2013-2015 Microchip Technology Germany II GmbH & Co. KG
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * This file is licensed under GPLv2.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15#include <linux/module.h>
16#include <linux/fs.h>
17#include <linux/slab.h>
18#include <linux/init.h>
19#include <linux/device.h>
20#include <linux/list.h>
21#include <linux/poll.h>
22#include <linux/wait.h>
23#include <linux/kobject.h>
24#include <linux/mutex.h>
25#include <linux/completion.h>
26#include <linux/sysfs.h>
27#include <linux/kthread.h>
28#include <linux/dma-mapping.h>
29#include <linux/idr.h>
30#include "mostcore.h"
31
32#define MAX_CHANNELS 64
33#define STRING_SIZE 80
34
35static struct class *most_class;
36static struct device *class_glue_dir;
37static struct ida mdev_id;
38static int modref;
39
40struct most_c_obj {
41 struct kobject kobj;
42 struct completion cleanup;
43 atomic_t mbo_ref;
44 atomic_t mbo_nq_level;
45 uint16_t channel_id;
46 bool is_poisoned;
47 bool is_started;
48 int is_starving;
49 struct most_interface *iface;
50 struct most_inst_obj *inst;
51 struct most_channel_config cfg;
52 bool keep_mbo;
53 bool enqueue_halt;
54 struct list_head fifo;
55 spinlock_t fifo_lock;
56 struct list_head halt_fifo;
57 struct list_head list;
58 struct most_aim *first_aim;
59 struct most_aim *second_aim;
60 struct list_head trash_fifo;
61 struct task_struct *hdm_enqueue_task;
62 struct mutex stop_task_mutex;
63 wait_queue_head_t hdm_fifo_wq;
64};
65#define to_c_obj(d) container_of(d, struct most_c_obj, kobj)
66
67struct most_inst_obj {
68 int dev_id;
69 atomic_t tainted;
70 struct most_interface *iface;
71 struct list_head channel_list;
72 struct most_c_obj *channel[MAX_CHANNELS];
73 struct kobject kobj;
74 struct list_head list;
75};
76#define to_inst_obj(d) container_of(d, struct most_inst_obj, kobj)
77
78/**
79 * list_pop_mbo - retrieves the first MBO of the list and removes it
80 * @ptr: the list head to grab the MBO from.
81 */
82#define list_pop_mbo(ptr) \
83({ \
84 struct mbo *_mbo = list_first_entry(ptr, struct mbo, list); \
85 list_del(&_mbo->list); \
86 _mbo; \
87})
88
89static struct mutex deregister_mutex;
90
91/* ___ ___
92 * ___C H A N N E L___
93 */
94
95/**
96 * struct most_c_attr - to access the attributes of a channel object
97 * @attr: attributes of a channel
98 * @show: pointer to the show function
99 * @store: pointer to the store function
100 */
101struct most_c_attr {
102 struct attribute attr;
103 ssize_t (*show)(struct most_c_obj *d,
104 struct most_c_attr *attr,
105 char *buf);
106 ssize_t (*store)(struct most_c_obj *d,
107 struct most_c_attr *attr,
108 const char *buf,
109 size_t count);
110};
111#define to_channel_attr(a) container_of(a, struct most_c_attr, attr)
112
113#define MOST_CHNL_ATTR(_name, _mode, _show, _store) \
114 struct most_c_attr most_chnl_attr_##_name = \
115 __ATTR(_name, _mode, _show, _store)
116
117/**
118 * channel_attr_show - show function of channel object
119 * @kobj: pointer to its kobject
120 * @attr: pointer to its attributes
121 * @buf: buffer
122 */
123static ssize_t channel_attr_show(struct kobject *kobj, struct attribute *attr,
124 char *buf)
125{
126 struct most_c_attr *channel_attr = to_channel_attr(attr);
127 struct most_c_obj *c_obj = to_c_obj(kobj);
128
129 if (!channel_attr->show)
130 return -EIO;
131
132 return channel_attr->show(c_obj, channel_attr, buf);
133}
134
135/**
136 * channel_attr_store - store function of channel object
137 * @kobj: pointer to its kobject
138 * @attr: pointer to its attributes
139 * @buf: buffer
140 * @len: length of buffer
141 */
142static ssize_t channel_attr_store(struct kobject *kobj,
143 struct attribute *attr,
144 const char *buf,
145 size_t len)
146{
147 struct most_c_attr *channel_attr = to_channel_attr(attr);
148 struct most_c_obj *c_obj = to_c_obj(kobj);
149
150 if (!channel_attr->store)
151 return -EIO;
152 return channel_attr->store(c_obj, channel_attr, buf, len);
153}
154
155static const struct sysfs_ops most_channel_sysfs_ops = {
156 .show = channel_attr_show,
157 .store = channel_attr_store,
158};
159
160/**
161 * most_free_mbo_coherent - free an MBO and its coherent buffer
162 * @mbo: buffer to be released
163 *
164 */
165static void most_free_mbo_coherent(struct mbo *mbo)
166{
167 struct most_c_obj *c = mbo->context;
168 u16 const coherent_buf_size = c->cfg.buffer_size + c->cfg.extra_len;
169
170 dma_free_coherent(NULL, coherent_buf_size, mbo->virt_address,
171 mbo->bus_address);
172 kfree(mbo);
173 if (atomic_sub_and_test(1, &c->mbo_ref))
174 complete(&c->cleanup);
175}
176
177/**
178 * flush_channel_fifos - clear the channel fifos
179 * @c: pointer to channel object
180 */
181static void flush_channel_fifos(struct most_c_obj *c)
182{
183 unsigned long flags, hf_flags;
184 struct mbo *mbo, *tmp;
185
186 if (list_empty(&c->fifo) && list_empty(&c->halt_fifo))
187 return;
188
189 spin_lock_irqsave(&c->fifo_lock, flags);
190 list_for_each_entry_safe(mbo, tmp, &c->fifo, list) {
191 list_del(&mbo->list);
192 spin_unlock_irqrestore(&c->fifo_lock, flags);
193 if (likely(mbo))
194 most_free_mbo_coherent(mbo);
195 spin_lock_irqsave(&c->fifo_lock, flags);
196 }
197 spin_unlock_irqrestore(&c->fifo_lock, flags);
198
199 spin_lock_irqsave(&c->fifo_lock, hf_flags);
200 list_for_each_entry_safe(mbo, tmp, &c->halt_fifo, list) {
201 list_del(&mbo->list);
202 spin_unlock_irqrestore(&c->fifo_lock, hf_flags);
203 if (likely(mbo))
204 most_free_mbo_coherent(mbo);
205 spin_lock_irqsave(&c->fifo_lock, hf_flags);
206 }
207 spin_unlock_irqrestore(&c->fifo_lock, hf_flags);
208
209 if (unlikely((!list_empty(&c->fifo) || !list_empty(&c->halt_fifo))))
210 pr_info("WARN: fifo | trash fifo not empty\n");
211}
212
213/**
214 * flush_trash_fifo - clear the trash fifo
215 * @c: pointer to channel object
216 */
217static int flush_trash_fifo(struct most_c_obj *c)
218{
219 struct mbo *mbo, *tmp;
220 unsigned long flags;
221
222 spin_lock_irqsave(&c->fifo_lock, flags);
223 list_for_each_entry_safe(mbo, tmp, &c->trash_fifo, list) {
224 list_del(&mbo->list);
225 spin_unlock_irqrestore(&c->fifo_lock, flags);
226 most_free_mbo_coherent(mbo);
227 spin_lock_irqsave(&c->fifo_lock, flags);
228 }
229 spin_unlock_irqrestore(&c->fifo_lock, flags);
230 return 0;
231}
232
233/**
234 * most_channel_release - release function of channel object
235 * @kobj: pointer to channel's kobject
236 */
237static void most_channel_release(struct kobject *kobj)
238{
239 struct most_c_obj *c = to_c_obj(kobj);
240
241 kfree(c);
242}
243
244static ssize_t show_available_directions(struct most_c_obj *c,
245 struct most_c_attr *attr,
246 char *buf)
247{
248 unsigned int i = c->channel_id;
249
250 strcpy(buf, "");
251 if (c->iface->channel_vector[i].direction & MOST_CH_RX)
252 strcat(buf, "dir_rx ");
253 if (c->iface->channel_vector[i].direction & MOST_CH_TX)
254 strcat(buf, "dir_tx ");
255 strcat(buf, "\n");
256 return strlen(buf) + 1;
257}
258
259static ssize_t show_available_datatypes(struct most_c_obj *c,
260 struct most_c_attr *attr,
261 char *buf)
262{
263 unsigned int i = c->channel_id;
264
265 strcpy(buf, "");
266 if (c->iface->channel_vector[i].data_type & MOST_CH_CONTROL)
267 strcat(buf, "control ");
268 if (c->iface->channel_vector[i].data_type & MOST_CH_ASYNC)
269 strcat(buf, "async ");
270 if (c->iface->channel_vector[i].data_type & MOST_CH_SYNC)
271 strcat(buf, "sync ");
272 if (c->iface->channel_vector[i].data_type & MOST_CH_ISOC_AVP)
273 strcat(buf, "isoc_avp ");
274 strcat(buf, "\n");
275 return strlen(buf) + 1;
276}
277
278static
279ssize_t show_number_of_packet_buffers(struct most_c_obj *c,
280 struct most_c_attr *attr,
281 char *buf)
282{
283 unsigned int i = c->channel_id;
284
285 return snprintf(buf, PAGE_SIZE, "%d\n",
286 c->iface->channel_vector[i].num_buffers_packet);
287}
288
289static
290ssize_t show_number_of_stream_buffers(struct most_c_obj *c,
291 struct most_c_attr *attr,
292 char *buf)
293{
294 unsigned int i = c->channel_id;
295
296 return snprintf(buf, PAGE_SIZE, "%d\n",
297 c->iface->channel_vector[i].num_buffers_streaming);
298}
299
300static
301ssize_t show_size_of_packet_buffer(struct most_c_obj *c,
302 struct most_c_attr *attr,
303 char *buf)
304{
305 unsigned int i = c->channel_id;
306
307 return snprintf(buf, PAGE_SIZE, "%d\n",
308 c->iface->channel_vector[i].buffer_size_packet);
309}
310
311static
312ssize_t show_size_of_stream_buffer(struct most_c_obj *c,
313 struct most_c_attr *attr,
314 char *buf)
315{
316 unsigned int i = c->channel_id;
317
318 return snprintf(buf, PAGE_SIZE, "%d\n",
319 c->iface->channel_vector[i].buffer_size_streaming);
320}
321
322static ssize_t show_channel_starving(struct most_c_obj *c,
323 struct most_c_attr *attr,
324 char *buf)
325{
326 return snprintf(buf, PAGE_SIZE, "%d\n", c->is_starving);
327}
328
329
330#define create_show_channel_attribute(val) \
331 static MOST_CHNL_ATTR(val, S_IRUGO, show_##val, NULL)
332
333create_show_channel_attribute(available_directions);
334create_show_channel_attribute(available_datatypes);
335create_show_channel_attribute(number_of_packet_buffers);
336create_show_channel_attribute(number_of_stream_buffers);
337create_show_channel_attribute(size_of_stream_buffer);
338create_show_channel_attribute(size_of_packet_buffer);
339create_show_channel_attribute(channel_starving);
340
341static ssize_t show_set_number_of_buffers(struct most_c_obj *c,
342 struct most_c_attr *attr,
343 char *buf)
344{
345 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.num_buffers);
346}
347
348static ssize_t store_set_number_of_buffers(struct most_c_obj *c,
349 struct most_c_attr *attr,
350 const char *buf,
351 size_t count)
352{
353 int ret = kstrtou16(buf, 0, &c->cfg.num_buffers);
354
355 if (ret)
356 return ret;
357 return count;
358}
359
360static ssize_t show_set_buffer_size(struct most_c_obj *c,
361 struct most_c_attr *attr,
362 char *buf)
363{
364 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.buffer_size);
365}
366
367static ssize_t store_set_buffer_size(struct most_c_obj *c,
368 struct most_c_attr *attr,
369 const char *buf,
370 size_t count)
371{
372 int ret = kstrtou16(buf, 0, &c->cfg.buffer_size);
373
374 if (ret)
375 return ret;
376 return count;
377}
378
379static ssize_t show_set_direction(struct most_c_obj *c,
380 struct most_c_attr *attr,
381 char *buf)
382{
383 if (c->cfg.direction & MOST_CH_TX)
384 return snprintf(buf, PAGE_SIZE, "dir_tx\n");
385 else if (c->cfg.direction & MOST_CH_RX)
386 return snprintf(buf, PAGE_SIZE, "dir_rx\n");
387 return snprintf(buf, PAGE_SIZE, "unconfigured\n");
388}
389
390static ssize_t store_set_direction(struct most_c_obj *c,
391 struct most_c_attr *attr,
392 const char *buf,
393 size_t count)
394{
395 if (!strcmp(buf, "dir_rx\n"))
396 c->cfg.direction = MOST_CH_RX;
397 else if (!strcmp(buf, "dir_tx\n"))
398 c->cfg.direction = MOST_CH_TX;
399 else {
400 pr_info("WARN: invalid attribute settings\n");
401 return -EINVAL;
402 }
403 return count;
404}
405
406static ssize_t show_set_datatype(struct most_c_obj *c,
407 struct most_c_attr *attr,
408 char *buf)
409{
410 if (c->cfg.data_type & MOST_CH_CONTROL)
411 return snprintf(buf, PAGE_SIZE, "control\n");
412 else if (c->cfg.data_type & MOST_CH_ASYNC)
413 return snprintf(buf, PAGE_SIZE, "async\n");
414 else if (c->cfg.data_type & MOST_CH_SYNC)
415 return snprintf(buf, PAGE_SIZE, "sync\n");
416 else if (c->cfg.data_type & MOST_CH_ISOC_AVP)
417 return snprintf(buf, PAGE_SIZE, "isoc_avp\n");
418 return snprintf(buf, PAGE_SIZE, "unconfigured\n");
419}
420
421static ssize_t store_set_datatype(struct most_c_obj *c,
422 struct most_c_attr *attr,
423 const char *buf,
424 size_t count)
425{
426 if (!strcmp(buf, "control\n"))
427 c->cfg.data_type = MOST_CH_CONTROL;
428 else if (!strcmp(buf, "async\n"))
429 c->cfg.data_type = MOST_CH_ASYNC;
430 else if (!strcmp(buf, "sync\n"))
431 c->cfg.data_type = MOST_CH_SYNC;
432 else if (!strcmp(buf, "isoc_avp\n"))
433 c->cfg.data_type = MOST_CH_ISOC_AVP;
434 else {
435 pr_info("WARN: invalid attribute settings\n");
436 return -EINVAL;
437 }
438 return count;
439}
440
441static ssize_t show_set_subbuffer_size(struct most_c_obj *c,
442 struct most_c_attr *attr,
443 char *buf)
444{
445 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.subbuffer_size);
446}
447
448static ssize_t store_set_subbuffer_size(struct most_c_obj *c,
449 struct most_c_attr *attr,
450 const char *buf,
451 size_t count)
452{
453 int ret = kstrtou16(buf, 0, &c->cfg.subbuffer_size);
454
455 if (ret)
456 return ret;
457 return count;
458}
459
460static ssize_t show_set_packets_per_xact(struct most_c_obj *c,
461 struct most_c_attr *attr,
462 char *buf)
463{
464 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.packets_per_xact);
465}
466
467static ssize_t store_set_packets_per_xact(struct most_c_obj *c,
468 struct most_c_attr *attr,
469 const char *buf,
470 size_t count)
471{
472 int ret = kstrtou16(buf, 0, &c->cfg.packets_per_xact);
473
474 if (ret)
475 return ret;
476 return count;
477}
478
479#define create_channel_attribute(value) \
480 static MOST_CHNL_ATTR(value, S_IRUGO | S_IWUSR, \
481 show_##value, \
482 store_##value)
483
484create_channel_attribute(set_buffer_size);
485create_channel_attribute(set_number_of_buffers);
486create_channel_attribute(set_direction);
487create_channel_attribute(set_datatype);
488create_channel_attribute(set_subbuffer_size);
489create_channel_attribute(set_packets_per_xact);
490
491
492/**
493 * most_channel_def_attrs - array of default attributes of channel object
494 */
495static struct attribute *most_channel_def_attrs[] = {
496 &most_chnl_attr_available_directions.attr,
497 &most_chnl_attr_available_datatypes.attr,
498 &most_chnl_attr_number_of_packet_buffers.attr,
499 &most_chnl_attr_number_of_stream_buffers.attr,
500 &most_chnl_attr_size_of_packet_buffer.attr,
501 &most_chnl_attr_size_of_stream_buffer.attr,
502 &most_chnl_attr_set_number_of_buffers.attr,
503 &most_chnl_attr_set_buffer_size.attr,
504 &most_chnl_attr_set_direction.attr,
505 &most_chnl_attr_set_datatype.attr,
506 &most_chnl_attr_set_subbuffer_size.attr,
507 &most_chnl_attr_set_packets_per_xact.attr,
508 &most_chnl_attr_channel_starving.attr,
509 NULL,
510};
511
512static struct kobj_type most_channel_ktype = {
513 .sysfs_ops = &most_channel_sysfs_ops,
514 .release = most_channel_release,
515 .default_attrs = most_channel_def_attrs,
516};
517
518static struct kset *most_channel_kset;
519
520/**
521 * create_most_c_obj - allocates a channel object
522 * @name: name of the channel object
523 * @parent: parent kobject
524 *
525 * This create a channel object and registers it with sysfs.
526 * Returns a pointer to the object or NULL when something went wrong.
527 */
528static struct most_c_obj *
529create_most_c_obj(const char *name, struct kobject *parent)
530{
531 struct most_c_obj *c;
532 int retval;
533
534 c = kzalloc(sizeof(*c), GFP_KERNEL);
535 if (!c)
536 return NULL;
537 c->kobj.kset = most_channel_kset;
538 retval = kobject_init_and_add(&c->kobj, &most_channel_ktype, parent,
539 "%s", name);
540 if (retval) {
541 kobject_put(&c->kobj);
542 return NULL;
543 }
544 kobject_uevent(&c->kobj, KOBJ_ADD);
545 return c;
546}
547
548/**
549 * destroy_most_c_obj - channel release function
550 * @c: pointer to channel object
551 *
552 * This decrements the reference counter of the channel object.
553 * If the reference count turns zero, its release function is called.
554 */
555static void destroy_most_c_obj(struct most_c_obj *c)
556{
557 if (c->first_aim)
558 c->first_aim->disconnect_channel(c->iface, c->channel_id);
559 if (c->second_aim)
560 c->second_aim->disconnect_channel(c->iface, c->channel_id);
561 c->first_aim = NULL;
562 c->second_aim = NULL;
563
564 mutex_lock(&deregister_mutex);
565 flush_trash_fifo(c);
566 flush_channel_fifos(c);
567 mutex_unlock(&deregister_mutex);
568 kobject_put(&c->kobj);
569}
570
571/* ___ ___
572 * ___I N S T A N C E___
573 */
574#define MOST_INST_ATTR(_name, _mode, _show, _store) \
575 struct most_inst_attribute most_inst_attr_##_name = \
576 __ATTR(_name, _mode, _show, _store)
577
578static struct list_head instance_list;
579
580/**
581 * struct most_inst_attribute - to access the attributes of instance object
582 * @attr: attributes of an instance
583 * @show: pointer to the show function
584 * @store: pointer to the store function
585 */
586struct most_inst_attribute {
587 struct attribute attr;
588 ssize_t (*show)(struct most_inst_obj *d,
589 struct most_inst_attribute *attr,
590 char *buf);
591 ssize_t (*store)(struct most_inst_obj *d,
592 struct most_inst_attribute *attr,
593 const char *buf,
594 size_t count);
595};
596#define to_instance_attr(a) \
597 container_of(a, struct most_inst_attribute, attr)
598
599/**
600 * instance_attr_show - show function for an instance object
601 * @kobj: pointer to kobject
602 * @attr: pointer to attribute struct
603 * @buf: buffer
604 */
605static ssize_t instance_attr_show(struct kobject *kobj,
606 struct attribute *attr,
607 char *buf)
608{
609 struct most_inst_attribute *instance_attr;
610 struct most_inst_obj *instance_obj;
611
612 instance_attr = to_instance_attr(attr);
613 instance_obj = to_inst_obj(kobj);
614
615 if (!instance_attr->show)
616 return -EIO;
617
618 return instance_attr->show(instance_obj, instance_attr, buf);
619}
620
621/**
622 * instance_attr_store - store function for an instance object
623 * @kobj: pointer to kobject
624 * @attr: pointer to attribute struct
625 * @buf: buffer
626 * @len: length of buffer
627 */
628static ssize_t instance_attr_store(struct kobject *kobj,
629 struct attribute *attr,
630 const char *buf,
631 size_t len)
632{
633 struct most_inst_attribute *instance_attr;
634 struct most_inst_obj *instance_obj;
635
636 instance_attr = to_instance_attr(attr);
637 instance_obj = to_inst_obj(kobj);
638
639 if (!instance_attr->store)
640 return -EIO;
641
642 return instance_attr->store(instance_obj, instance_attr, buf, len);
643}
644
645static const struct sysfs_ops most_inst_sysfs_ops = {
646 .show = instance_attr_show,
647 .store = instance_attr_store,
648};
649
650/**
651 * most_inst_release - release function for instance object
652 * @kobj: pointer to instance's kobject
653 *
654 * This frees the allocated memory for the instance object
655 */
656static void most_inst_release(struct kobject *kobj)
657{
658 struct most_inst_obj *inst = to_inst_obj(kobj);
659
660 kfree(inst);
661}
662
663static ssize_t show_description(struct most_inst_obj *instance_obj,
664 struct most_inst_attribute *attr,
665 char *buf)
666{
667 return snprintf(buf, PAGE_SIZE, "%s\n",
668 instance_obj->iface->description);
669}
670
671static ssize_t show_interface(struct most_inst_obj *instance_obj,
672 struct most_inst_attribute *attr,
673 char *buf)
674{
675 switch (instance_obj->iface->interface) {
676 case ITYPE_LOOPBACK:
677 return snprintf(buf, PAGE_SIZE, "loopback\n");
678 case ITYPE_I2C:
679 return snprintf(buf, PAGE_SIZE, "i2c\n");
680 case ITYPE_I2S:
681 return snprintf(buf, PAGE_SIZE, "i2s\n");
682 case ITYPE_TSI:
683 return snprintf(buf, PAGE_SIZE, "tsi\n");
684 case ITYPE_HBI:
685 return snprintf(buf, PAGE_SIZE, "hbi\n");
686 case ITYPE_MEDIALB_DIM:
687 return snprintf(buf, PAGE_SIZE, "mlb_dim\n");
688 case ITYPE_MEDIALB_DIM2:
689 return snprintf(buf, PAGE_SIZE, "mlb_dim2\n");
690 case ITYPE_USB:
691 return snprintf(buf, PAGE_SIZE, "usb\n");
692 case ITYPE_PCIE:
693 return snprintf(buf, PAGE_SIZE, "pcie\n");
694 }
695 return snprintf(buf, PAGE_SIZE, "unknown\n");
696}
697
698#define create_inst_attribute(value) \
699 static MOST_INST_ATTR(value, S_IRUGO, show_##value, NULL)
700
701create_inst_attribute(description);
702create_inst_attribute(interface);
703
704static struct attribute *most_inst_def_attrs[] = {
705 &most_inst_attr_description.attr,
706 &most_inst_attr_interface.attr,
707 NULL,
708};
709
710static struct kobj_type most_inst_ktype = {
711 .sysfs_ops = &most_inst_sysfs_ops,
712 .release = most_inst_release,
713 .default_attrs = most_inst_def_attrs,
714};
715
716static struct kset *most_inst_kset;
717
718
719/**
720 * create_most_inst_obj - creates an instance object
721 * @name: name of the object to be created
722 *
723 * This allocates memory for an instance structure, assigns the proper kset
724 * and registers it with sysfs.
725 *
726 * Returns a pointer to the instance object or NULL when something went wrong.
727 */
728static struct most_inst_obj *create_most_inst_obj(const char *name)
729{
730 struct most_inst_obj *inst;
731 int retval;
732
733 inst = kzalloc(sizeof(*inst), GFP_KERNEL);
734 if (!inst)
735 return NULL;
736 inst->kobj.kset = most_inst_kset;
737 retval = kobject_init_and_add(&inst->kobj, &most_inst_ktype, NULL,
738 "%s", name);
739 if (retval) {
740 kobject_put(&inst->kobj);
741 return NULL;
742 }
743 kobject_uevent(&inst->kobj, KOBJ_ADD);
744 return inst;
745}
746
747/**
748 * destroy_most_inst_obj - MOST instance release function
749 * @inst: pointer to the instance object
750 *
751 * This decrements the reference counter of the instance object.
752 * If the reference count turns zero, its release function is called
753 */
754static void destroy_most_inst_obj(struct most_inst_obj *inst)
755{
756 struct most_c_obj *c, *tmp;
757
758 /* need to destroy channels first, since
759 * each channel incremented the
760 * reference count of the inst->kobj
761 */
762 list_for_each_entry_safe(c, tmp, &inst->channel_list, list) {
763 destroy_most_c_obj(c);
764 }
765 kobject_put(&inst->kobj);
766}
767
768/* ___ ___
769 * ___A I M___
770 */
771struct most_aim_obj {
772 struct kobject kobj;
773 struct list_head list;
774 struct most_aim *driver;
775 char add_link[STRING_SIZE];
776 char remove_link[STRING_SIZE];
777};
778#define to_aim_obj(d) container_of(d, struct most_aim_obj, kobj)
779
780static struct list_head aim_list;
781
782
783/**
784 * struct most_aim_attribute - to access the attributes of AIM object
785 * @attr: attributes of an AIM
786 * @show: pointer to the show function
787 * @store: pointer to the store function
788 */
789struct most_aim_attribute {
790 struct attribute attr;
791 ssize_t (*show)(struct most_aim_obj *d,
792 struct most_aim_attribute *attr,
793 char *buf);
794 ssize_t (*store)(struct most_aim_obj *d,
795 struct most_aim_attribute *attr,
796 const char *buf,
797 size_t count);
798};
799#define to_aim_attr(a) container_of(a, struct most_aim_attribute, attr)
800
801/**
802 * aim_attr_show - show function of an AIM object
803 * @kobj: pointer to kobject
804 * @attr: pointer to attribute struct
805 * @buf: buffer
806 */
807static ssize_t aim_attr_show(struct kobject *kobj,
808 struct attribute *attr,
809 char *buf)
810{
811 struct most_aim_attribute *aim_attr;
812 struct most_aim_obj *aim_obj;
813
814 aim_attr = to_aim_attr(attr);
815 aim_obj = to_aim_obj(kobj);
816
817 if (!aim_attr->show)
818 return -EIO;
819
820 return aim_attr->show(aim_obj, aim_attr, buf);
821}
822
823/**
824 * aim_attr_store - store function of an AIM object
825 * @kobj: pointer to kobject
826 * @attr: pointer to attribute struct
827 * @buf: buffer
828 * @len: length of buffer
829 */
830static ssize_t aim_attr_store(struct kobject *kobj,
831 struct attribute *attr,
832 const char *buf,
833 size_t len)
834{
835 struct most_aim_attribute *aim_attr;
836 struct most_aim_obj *aim_obj;
837
838 aim_attr = to_aim_attr(attr);
839 aim_obj = to_aim_obj(kobj);
840
841 if (!aim_attr->store)
842 return -EIO;
843 return aim_attr->store(aim_obj, aim_attr, buf, len);
844}
845
846static const struct sysfs_ops most_aim_sysfs_ops = {
847 .show = aim_attr_show,
848 .store = aim_attr_store,
849};
850
851/**
852 * most_aim_release - AIM release function
853 * @kobj: pointer to AIM's kobject
854 */
855static void most_aim_release(struct kobject *kobj)
856{
857 struct most_aim_obj *aim_obj = to_aim_obj(kobj);
858
859 kfree(aim_obj);
860}
861
862static ssize_t show_add_link(struct most_aim_obj *aim_obj,
863 struct most_aim_attribute *attr,
864 char *buf)
865{
866 return snprintf(buf, PAGE_SIZE, "%s\n", aim_obj->add_link);
867}
868
869/**
870 * split_string - parses and changes string in the buffer buf and
871 * splits it into two mandatory and one optional substrings.
872 *
873 * @buf: complete string from attribute 'add_channel'
874 * @a: address of pointer to 1st substring (=instance name)
875 * @b: address of pointer to 2nd substring (=channel name)
876 * @c: optional address of pointer to 3rd substring (=user defined name)
877 *
878 * Examples:
879 *
880 * Input: "mdev0:ch0@ep_81:my_channel\n" or
881 * "mdev0:ch0@ep_81:my_channel"
882 *
883 * Output: *a -> "mdev0", *b -> "ch0@ep_81", *c -> "my_channel"
884 *
885 * Input: "mdev0:ch0@ep_81\n"
886 * Output: *a -> "mdev0", *b -> "ch0@ep_81", *c -> ""
887 *
888 * Input: "mdev0:ch0@ep_81"
889 * Output: *a -> "mdev0", *b -> "ch0@ep_81", *c == NULL
890 */
891static int split_string(char *buf, char **a, char **b, char **c)
892{
893 *a = strsep(&buf, ":");
894 if (!*a)
895 return -EIO;
896
897 *b = strsep(&buf, ":\n");
898 if (!*b)
899 return -EIO;
900
901 if (c)
902 *c = strsep(&buf, ":\n");
903
904 return 0;
905}
906
907/**
908 * get_channel_by_name - get pointer to channel object
909 * @mdev: name of the device instance
910 * @mdev_ch: name of the respective channel
911 *
912 * This retrieves the pointer to a channel object.
913 */
914static struct
915most_c_obj *get_channel_by_name(char *mdev, char *mdev_ch)
916{
917 struct most_c_obj *c, *tmp;
918 struct most_inst_obj *i, *i_tmp;
919 int found = 0;
920
921 list_for_each_entry_safe(i, i_tmp, &instance_list, list) {
922 if (!strcmp(kobject_name(&i->kobj), mdev)) {
923 found++;
924 break;
925 }
926 }
927 if (unlikely(!found))
928 return ERR_PTR(-EIO);
929
930 list_for_each_entry_safe(c, tmp, &i->channel_list, list) {
931 if (!strcmp(kobject_name(&c->kobj), mdev_ch)) {
932 found++;
933 break;
934 }
935 }
936 if (unlikely(2 > found))
937 return ERR_PTR(-EIO);
938 return c;
939}
940
941/**
942 * store_add_link - store() function for add_link attribute
943 * @aim_obj: pointer to AIM object
944 * @attr: its attributes
945 * @buf: buffer
946 * @len: buffer length
947 *
948 * This parses the string given by buf and splits it into
949 * three substrings. Note: third substring is optional. In case a cdev
950 * AIM is loaded the optional 3rd substring will make up the name of
951 * device node in the /dev directory. If omitted, the device node will
952 * inherit the channel's name within sysfs.
953 *
954 * Searches for a pair of device and channel and probes the AIM
955 *
956 * Example:
957 * (1) echo -n -e "mdev0:ch0@ep_81:my_rxchannel\n" >add_link
958 * (2) echo -n -e "mdev0:ch0@ep_81\n" >add_link
959 *
960 * (1) would create the device node /dev/my_rxchannel
961 * (2) would create the device node /dev/mdev0-ch0@ep_81
962 */
963static ssize_t store_add_link(struct most_aim_obj *aim_obj,
964 struct most_aim_attribute *attr,
965 const char *buf,
966 size_t len)
967{
968 struct most_c_obj *c;
969 struct most_aim **aim_ptr;
970 char buffer[STRING_SIZE];
971 char *mdev;
972 char *mdev_ch;
973 char *mdev_devnod;
974 char devnod_buf[STRING_SIZE];
975 int ret;
976 size_t max_len = min_t(size_t, len + 1, STRING_SIZE);
977
978 strlcpy(buffer, buf, max_len);
979 strlcpy(aim_obj->add_link, buf, max_len);
980
981 ret = split_string(buffer, &mdev, &mdev_ch, &mdev_devnod);
982 if (ret)
983 return ret;
984
985 if (!mdev_devnod || *mdev_devnod == 0) {
986 snprintf(devnod_buf, sizeof(devnod_buf), "%s-%s", mdev, mdev_ch);
987 mdev_devnod = devnod_buf;
988 }
989
990 c = get_channel_by_name(mdev, mdev_ch);
991 if (IS_ERR(c))
992 return -ENODEV;
993
994 if (!c->first_aim)
995 aim_ptr = &c->first_aim;
996 else if (!c->second_aim)
997 aim_ptr = &c->second_aim;
998 else
999 return -ENOSPC;
1000
1001 ret = aim_obj->driver->probe_channel(c->iface, c->channel_id,
1002 &c->cfg, &c->kobj, mdev_devnod);
1003 if (ret)
1004 return ret;
1005 *aim_ptr = aim_obj->driver;
1006 return len;
1007}
1008
1009static struct most_aim_attribute most_aim_attr_add_link =
1010 __ATTR(add_link, S_IRUGO | S_IWUSR, show_add_link, store_add_link);
1011
1012static ssize_t show_remove_link(struct most_aim_obj *aim_obj,
1013 struct most_aim_attribute *attr,
1014 char *buf)
1015{
1016 return snprintf(buf, PAGE_SIZE, "%s\n", aim_obj->remove_link);
1017}
1018
1019/**
1020 * store_remove_link - store function for remove_link attribute
1021 * @aim_obj: pointer to AIM object
1022 * @attr: its attributes
1023 * @buf: buffer
1024 * @len: buffer length
1025 *
1026 * Example:
1027 * echo -n -e "mdev0:ch0@ep_81\n" >remove_link
1028 */
1029static ssize_t store_remove_link(struct most_aim_obj *aim_obj,
1030 struct most_aim_attribute *attr,
1031 const char *buf,
1032 size_t len)
1033{
1034 struct most_c_obj *c;
1035 char buffer[STRING_SIZE];
1036 char *mdev;
1037 char *mdev_ch;
1038 int ret;
1039 size_t max_len = min_t(size_t, len + 1, STRING_SIZE);
1040
1041 strlcpy(buffer, buf, max_len);
1042 strlcpy(aim_obj->remove_link, buf, max_len);
1043 ret = split_string(buffer, &mdev, &mdev_ch, NULL);
1044 if (ret)
1045 return ret;
1046
1047 c = get_channel_by_name(mdev, mdev_ch);
1048 if (IS_ERR(c))
1049 return -ENODEV;
1050
1051 if (c->first_aim == aim_obj->driver)
1052 c->first_aim = NULL;
1053 if (c->second_aim == aim_obj->driver)
1054 c->second_aim = NULL;
1055 if (aim_obj->driver->disconnect_channel(c->iface, c->channel_id))
1056 return -EIO;
1057 return len;
1058}
1059
1060static struct most_aim_attribute most_aim_attr_remove_link =
1061 __ATTR(remove_link, S_IRUGO | S_IWUSR, show_remove_link, store_remove_link);
1062
1063static struct attribute *most_aim_def_attrs[] = {
1064 &most_aim_attr_add_link.attr,
1065 &most_aim_attr_remove_link.attr,
1066 NULL,
1067};
1068
1069static struct kobj_type most_aim_ktype = {
1070 .sysfs_ops = &most_aim_sysfs_ops,
1071 .release = most_aim_release,
1072 .default_attrs = most_aim_def_attrs,
1073};
1074
1075static struct kset *most_aim_kset;
1076
1077/**
1078 * create_most_aim_obj - creates an AIM object
1079 * @name: name of the AIM
1080 *
1081 * This creates an AIM object assigns the proper kset and registers
1082 * it with sysfs.
1083 * Returns a pointer to the object or NULL if something went wrong.
1084 */
1085static struct most_aim_obj *create_most_aim_obj(const char *name)
1086{
1087 struct most_aim_obj *most_aim;
1088 int retval;
1089
1090 most_aim = kzalloc(sizeof(*most_aim), GFP_KERNEL);
1091 if (!most_aim)
1092 return NULL;
1093 most_aim->kobj.kset = most_aim_kset;
1094 retval = kobject_init_and_add(&most_aim->kobj, &most_aim_ktype,
1095 NULL, "%s", name);
1096 if (retval) {
1097 kobject_put(&most_aim->kobj);
1098 return NULL;
1099 }
1100 kobject_uevent(&most_aim->kobj, KOBJ_ADD);
1101 return most_aim;
1102}
1103
1104/**
1105 * destroy_most_aim_obj - AIM release function
1106 * @p: pointer to AIM object
1107 *
1108 * This decrements the reference counter of the AIM object. If the
1109 * reference count turns zero, its release function will be called.
1110 */
1111static void destroy_most_aim_obj(struct most_aim_obj *p)
1112{
1113 kobject_put(&p->kobj);
1114}
1115
1116
1117/* ___ ___
1118 * ___C O R E___
1119 */
1120
1121/**
1122 * Instantiation of the MOST bus
1123 */
1124static struct bus_type most_bus = {
1125 .name = "most",
1126};
1127
1128/**
1129 * Instantiation of the core driver
1130 */
1131static struct device_driver mostcore = {
1132 .name = "mostcore",
1133 .bus = &most_bus,
1134};
1135
1136static inline void trash_mbo(struct mbo *mbo)
1137{
1138 unsigned long flags;
1139 struct most_c_obj *c = mbo->context;
1140
1141 spin_lock_irqsave(&c->fifo_lock, flags);
1142 list_add(&mbo->list, &c->trash_fifo);
1143 spin_unlock_irqrestore(&c->fifo_lock, flags);
1144}
1145
1146static struct mbo *get_hdm_mbo(struct most_c_obj *c)
1147{
1148 unsigned long flags;
1149 struct mbo *mbo;
1150
1151 spin_lock_irqsave(&c->fifo_lock, flags);
1152 if (c->enqueue_halt || list_empty(&c->halt_fifo))
1153 mbo = NULL;
1154 else
1155 mbo = list_pop_mbo(&c->halt_fifo);
1156 spin_unlock_irqrestore(&c->fifo_lock, flags);
1157 return mbo;
1158}
1159
1160static void nq_hdm_mbo(struct mbo *mbo)
1161{
1162 unsigned long flags;
1163 struct most_c_obj *c = mbo->context;
1164
1165 spin_lock_irqsave(&c->fifo_lock, flags);
1166 list_add_tail(&mbo->list, &c->halt_fifo);
1167 spin_unlock_irqrestore(&c->fifo_lock, flags);
1168 wake_up_interruptible(&c->hdm_fifo_wq);
1169}
1170
1171static int hdm_enqueue_thread(void *data)
1172{
1173 struct most_c_obj *c = data;
1174 struct mbo *mbo;
1175 typeof(c->iface->enqueue) enqueue = c->iface->enqueue;
1176
1177 while (likely(!kthread_should_stop())) {
1178 wait_event_interruptible(c->hdm_fifo_wq,
1179 (mbo = get_hdm_mbo(c))
1180 || kthread_should_stop());
1181
1182 if (unlikely(!mbo))
1183 continue;
1184
1185 if (c->cfg.direction == MOST_CH_RX)
1186 mbo->buffer_length = c->cfg.buffer_size;
1187
1188 if (unlikely(enqueue(mbo->ifp, mbo->hdm_channel_id, mbo))) {
1189 pr_err("hdm enqueue failed\n");
1190 nq_hdm_mbo(mbo);
1191 c->hdm_enqueue_task = NULL;
1192 return 0;
1193 }
1194 }
1195
1196 return 0;
1197}
1198
1199static int run_enqueue_thread(struct most_c_obj *c, int channel_id)
1200{
1201 struct task_struct *task =
1202 kthread_run(&hdm_enqueue_thread, c, "hdm_fifo_%d", channel_id);
1203
1204 if (IS_ERR(task))
1205 return PTR_ERR(task);
1206
1207 c->hdm_enqueue_task = task;
1208 return 0;
1209}
1210
1211/**
1212 * arm_mbo - recycle MBO for further usage
1213 * @mbo: buffer object
1214 *
1215 * This puts an MBO back to the list to have it ready for up coming
1216 * tx transactions.
1217 *
1218 * In case the MBO belongs to a channel that recently has been
1219 * poisoned, the MBO is scheduled to be trashed.
1220 * Calls the completion handler of an attached AIM.
1221 */
1222static void arm_mbo(struct mbo *mbo)
1223{
1224 unsigned long flags;
1225 struct most_c_obj *c;
1226
1227 BUG_ON((!mbo) || (!mbo->context));
1228 c = mbo->context;
1229
1230 if (c->is_poisoned) {
1231 trash_mbo(mbo);
1232 return;
1233 }
1234
1235 spin_lock_irqsave(&c->fifo_lock, flags);
1236 list_add_tail(&mbo->list, &c->fifo);
1237 spin_unlock_irqrestore(&c->fifo_lock, flags);
1238
1239 if (c->second_aim && c->second_aim->tx_completion)
1240 c->second_aim->tx_completion(c->iface, c->channel_id);
1241 if (c->first_aim && c->first_aim->tx_completion)
1242 c->first_aim->tx_completion(c->iface, c->channel_id);
1243}
1244
1245/**
1246 * arm_mbo_chain - helper function that arms an MBO chain for the HDM
1247 * @c: pointer to interface channel
1248 * @dir: direction of the channel
1249 * @compl: pointer to completion function
1250 *
1251 * This allocates buffer objects including the containing DMA coherent
1252 * buffer and puts them in the fifo.
1253 * Buffers of Rx channels are put in the kthread fifo, hence immediately
1254 * submitted to the HDM.
1255 *
1256 * Returns the number of allocated and enqueued MBOs.
1257 */
1258static int arm_mbo_chain(struct most_c_obj *c, int dir,
1259 void (*compl)(struct mbo *))
1260{
1261 unsigned int i;
1262 int retval;
1263 struct mbo *mbo;
1264 u32 coherent_buf_size = c->cfg.buffer_size + c->cfg.extra_len;
1265
1266 atomic_set(&c->mbo_nq_level, 0);
1267
1268 for (i = 0; i < c->cfg.num_buffers; i++) {
1269 mbo = kzalloc(sizeof(*mbo), GFP_KERNEL);
1270 if (!mbo) {
1271 pr_info("WARN: Allocation of MBO failed.\n");
1272 retval = i;
1273 goto _exit;
1274 }
1275 mbo->context = c;
1276 mbo->ifp = c->iface;
1277 mbo->hdm_channel_id = c->channel_id;
1278 mbo->virt_address = dma_alloc_coherent(NULL,
1279 coherent_buf_size,
1280 &mbo->bus_address,
1281 GFP_KERNEL);
1282 if (!mbo->virt_address) {
1283 pr_info("WARN: No DMA coherent buffer.\n");
1284 retval = i;
1285 goto _error1;
1286 }
1287 mbo->complete = compl;
1288 if (dir == MOST_CH_RX) {
1289 nq_hdm_mbo(mbo);
1290 atomic_inc(&c->mbo_nq_level);
1291 } else {
1292 arm_mbo(mbo);
1293 }
1294 }
1295 return i;
1296
1297_error1:
1298 kfree(mbo);
1299_exit:
1300 return retval;
1301}
1302
1303/**
1304 * most_submit_mbo - submits an MBO to fifo
1305 * @mbo: pointer to the MBO
1306 *
1307 */
1308int most_submit_mbo(struct mbo *mbo)
1309{
1310 struct most_c_obj *c;
1311 struct most_inst_obj *i;
1312
1313 if (unlikely((!mbo) || (!mbo->context))) {
1314 pr_err("Bad MBO or missing channel reference\n");
1315 return -EINVAL;
1316 }
1317 c = mbo->context;
1318 i = c->inst;
1319
1320 if (unlikely(atomic_read(&i->tainted)))
1321 return -ENODEV;
1322
1323 nq_hdm_mbo(mbo);
1324 return 0;
1325}
1326EXPORT_SYMBOL_GPL(most_submit_mbo);
1327
1328/**
1329 * most_write_completion - write completion handler
1330 * @mbo: pointer to MBO
1331 *
1332 * This recycles the MBO for further usage. In case the channel has been
1333 * poisoned, the MBO is scheduled to be trashed.
1334 */
1335static void most_write_completion(struct mbo *mbo)
1336{
1337 struct most_c_obj *c;
1338
1339 BUG_ON((!mbo) || (!mbo->context));
1340
1341 c = mbo->context;
1342 if (mbo->status == MBO_E_INVAL)
1343 pr_info("WARN: Tx MBO status: invalid\n");
1344 if (unlikely((c->is_poisoned == true) || (mbo->status == MBO_E_CLOSE)))
1345 trash_mbo(mbo);
1346 else
1347 arm_mbo(mbo);
1348}
1349
1350/**
1351 * get_channel_by_iface - get pointer to channel object
1352 * @iface: pointer to interface instance
1353 * @id: channel ID
1354 *
1355 * This retrieves a pointer to a channel of the given interface and channel ID.
1356 */
1357static struct
1358most_c_obj *get_channel_by_iface(struct most_interface *iface, int id)
1359{
1360 struct most_inst_obj *i;
1361
1362 if (unlikely(!iface)) {
1363 pr_err("Bad interface\n");
1364 return NULL;
1365 }
1366 if (unlikely((id < 0) || (id >= iface->num_channels))) {
1367 pr_err("Channel index (%d) out of range\n", id);
1368 return NULL;
1369 }
1370 i = iface->priv;
1371 if (unlikely(!i)) {
1372 pr_err("interface is not registered\n");
1373 return NULL;
1374 }
1375 return i->channel[id];
1376}
1377
1378/**
1379 * most_get_mbo - get pointer to an MBO of pool
1380 * @iface: pointer to interface instance
1381 * @id: channel ID
1382 *
1383 * This attempts to get a free buffer out of the channel fifo.
1384 * Returns a pointer to MBO on success or NULL otherwise.
1385 */
1386struct mbo *most_get_mbo(struct most_interface *iface, int id)
1387{
1388 struct mbo *mbo;
1389 struct most_c_obj *c;
1390 unsigned long flags;
1391
1392 c = get_channel_by_iface(iface, id);
1393 if (unlikely(!c))
1394 return NULL;
1395 spin_lock_irqsave(&c->fifo_lock, flags);
1396 if (list_empty(&c->fifo)) {
1397 spin_unlock_irqrestore(&c->fifo_lock, flags);
1398 return NULL;
1399 }
1400 mbo = list_pop_mbo(&c->fifo);
1401 spin_unlock_irqrestore(&c->fifo_lock, flags);
1402 mbo->buffer_length = c->cfg.buffer_size;
1403 return mbo;
1404}
1405EXPORT_SYMBOL_GPL(most_get_mbo);
1406
1407
1408/**
1409 * most_put_mbo - return buffer to pool
1410 * @mbo: buffer object
1411 */
1412void most_put_mbo(struct mbo *mbo)
1413{
1414 struct most_c_obj *c;
1415 struct most_inst_obj *i;
1416
1417 c = mbo->context;
1418 i = c->inst;
1419
1420 if (unlikely(atomic_read(&i->tainted))) {
1421 mbo->status = MBO_E_CLOSE;
1422 trash_mbo(mbo);
1423 return;
1424 }
1425 if (c->cfg.direction == MOST_CH_TX) {
1426 arm_mbo(mbo);
1427 return;
1428 }
1429 nq_hdm_mbo(mbo);
1430 atomic_inc(&c->mbo_nq_level);
1431}
1432EXPORT_SYMBOL_GPL(most_put_mbo);
1433
1434/**
1435 * most_read_completion - read completion handler
1436 * @mbo: pointer to MBO
1437 *
1438 * This function is called by the HDM when data has been received from the
1439 * hardware and copied to the buffer of the MBO.
1440 *
1441 * In case the channel has been poisoned it puts the buffer in the trash queue.
1442 * Otherwise, it passes the buffer to an AIM for further processing.
1443 */
1444static void most_read_completion(struct mbo *mbo)
1445{
1446 struct most_c_obj *c;
1447
1448 c = mbo->context;
1449 if (unlikely((c->is_poisoned == true) || (mbo->status == MBO_E_CLOSE)))
1450 goto release_mbo;
1451
1452 if (mbo->status == MBO_E_INVAL) {
1453 nq_hdm_mbo(mbo);
1454 atomic_inc(&c->mbo_nq_level);
1455 return;
1456 }
1457
1458 if (atomic_sub_and_test(1, &c->mbo_nq_level)) {
1459 pr_info("WARN: rx device out of buffers\n");
1460 c->is_starving = 1;
1461 }
1462
1463 if (c->first_aim && c->first_aim->rx_completion &&
1464 c->first_aim->rx_completion(mbo) == 0)
1465 return;
1466 if (c->second_aim && c->second_aim->rx_completion &&
1467 c->second_aim->rx_completion(mbo) == 0)
1468 return;
1469 pr_info("WARN: no driver linked with this channel\n");
1470 mbo->status = MBO_E_CLOSE;
1471release_mbo:
1472 trash_mbo(mbo);
1473}
1474
1475/**
1476 * most_start_channel - prepares a channel for communication
1477 * @iface: pointer to interface instance
1478 * @id: channel ID
1479 *
1480 * This prepares the channel for usage. Cross-checks whether the
1481 * channel's been properly configured.
1482 *
1483 * Returns 0 on success or error code otherwise.
1484 */
1485int most_start_channel(struct most_interface *iface, int id)
1486{
1487 int num_buffer;
1488 int ret;
1489 struct most_c_obj *c = get_channel_by_iface(iface, id);
1490
1491 if (unlikely(!c))
1492 return -EINVAL;
1493
1494 if (c->is_started)
1495 return -EBUSY;
1496
1497 if (!try_module_get(iface->mod)) {
1498 pr_info("failed to acquire HDM lock\n");
1499 return -ENOLCK;
1500 }
1501 modref++;
1502
1503 c->cfg.extra_len = 0;
1504 if (c->iface->configure(c->iface, c->channel_id, &c->cfg)) {
1505 pr_info("channel configuration failed. Go check settings...\n");
1506 ret = -EINVAL;
1507 goto error;
1508 }
1509
1510 init_waitqueue_head(&c->hdm_fifo_wq);
1511
1512 if (c->cfg.direction == MOST_CH_RX)
1513 num_buffer = arm_mbo_chain(c, c->cfg.direction,
1514 most_read_completion);
1515 else
1516 num_buffer = arm_mbo_chain(c, c->cfg.direction,
1517 most_write_completion);
1518 if (unlikely(0 == num_buffer)) {
1519 pr_info("failed to allocate memory\n");
1520 ret = -ENOMEM;
1521 goto error;
1522 }
1523
1524 ret = run_enqueue_thread(c, id);
1525 if (ret)
1526 goto error;
1527
1528 c->is_started = true;
1529 c->is_starving = 0;
1530 atomic_set(&c->mbo_ref, num_buffer);
1531 return 0;
1532error:
1533 if (iface->mod)
1534 module_put(iface->mod);
1535 modref--;
1536 return ret;
1537}
1538EXPORT_SYMBOL_GPL(most_start_channel);
1539
1540/**
1541 * most_stop_channel - stops a running channel
1542 * @iface: pointer to interface instance
1543 * @id: channel ID
1544 */
1545int most_stop_channel(struct most_interface *iface, int id)
1546{
1547 struct most_c_obj *c;
1548
1549 if (unlikely((!iface) || (id >= iface->num_channels) || (id < 0))) {
1550 pr_err("Bad interface or index out of range\n");
1551 return -EINVAL;
1552 }
1553 c = get_channel_by_iface(iface, id);
1554 if (unlikely(!c))
1555 return -EINVAL;
1556
1557 if (!c->is_started)
1558 return 0;
1559
1560 /* FIXME: we need to know calling AIM to reset only one link */
1561 c->first_aim = NULL;
1562 c->second_aim = NULL;
1563 /* do not go into recursion calling aim->disconnect_channel */
1564
1565 mutex_lock(&c->stop_task_mutex);
1566 if (c->hdm_enqueue_task)
1567 kthread_stop(c->hdm_enqueue_task);
1568 c->hdm_enqueue_task = NULL;
1569 mutex_unlock(&c->stop_task_mutex);
1570
1571 mutex_lock(&deregister_mutex);
1572 if (atomic_read(&c->inst->tainted)) {
1573 mutex_unlock(&deregister_mutex);
1574 return -ENODEV;
1575 }
1576 mutex_unlock(&deregister_mutex);
1577
1578 if (iface->mod && modref) {
1579 module_put(iface->mod);
1580 modref--;
1581 }
1582
1583 c->is_poisoned = true;
1584 if (c->iface->poison_channel(c->iface, c->channel_id)) {
1585 pr_err("Cannot stop channel %d of mdev %s\n", c->channel_id,
1586 c->iface->description);
1587 return -EAGAIN;
1588 }
1589 flush_trash_fifo(c);
1590 flush_channel_fifos(c);
1591
1592#ifdef CMPL_INTERRUPTIBLE
1593 if (wait_for_completion_interruptible(&c->cleanup)) {
1594 pr_info("Interrupted while clean up ch %d\n", c->channel_id);
1595 return -EINTR;
1596 }
1597#else
1598 wait_for_completion(&c->cleanup);
1599#endif
1600 c->is_poisoned = false;
1601 c->is_started = false;
1602 return 0;
1603}
1604EXPORT_SYMBOL_GPL(most_stop_channel);
1605
1606/**
1607 * most_register_aim - registers an AIM (driver) with the core
1608 * @aim: instance of AIM to be registered
1609 */
1610int most_register_aim(struct most_aim *aim)
1611{
1612 struct most_aim_obj *aim_obj;
1613
1614 if (!aim) {
1615 pr_err("Bad driver\n");
1616 return -EINVAL;
1617 }
1618 aim_obj = create_most_aim_obj(aim->name);
1619 if (!aim_obj) {
1620 pr_info("failed to alloc driver object\n");
1621 return -ENOMEM;
1622 }
1623 aim_obj->driver = aim;
1624 aim->context = aim_obj;
1625 pr_info("registered new application interfacing module %s\n",
1626 aim->name);
1627 list_add_tail(&aim_obj->list, &aim_list);
1628 return 0;
1629}
1630EXPORT_SYMBOL_GPL(most_register_aim);
1631
1632/**
1633 * most_deregister_aim - deregisters an AIM (driver) with the core
1634 * @aim: AIM to be removed
1635 */
1636int most_deregister_aim(struct most_aim *aim)
1637{
1638 struct most_aim_obj *aim_obj;
1639 struct most_c_obj *c, *tmp;
1640 struct most_inst_obj *i, *i_tmp;
1641
1642 if (!aim) {
1643 pr_err("Bad driver\n");
1644 return -EINVAL;
1645 }
1646
1647 aim_obj = aim->context;
1648 if (!aim_obj) {
1649 pr_info("driver not registered.\n");
1650 return -EINVAL;
1651 }
1652 list_for_each_entry_safe(i, i_tmp, &instance_list, list) {
1653 list_for_each_entry_safe(c, tmp, &i->channel_list, list) {
1654 if (c->first_aim == aim || c->second_aim == aim)
1655 aim->disconnect_channel(
1656 c->iface, c->channel_id);
1657 if (c->first_aim == aim)
1658 c->first_aim = NULL;
1659 if (c->second_aim == aim)
1660 c->second_aim = NULL;
1661 }
1662 }
1663 list_del(&aim_obj->list);
1664 destroy_most_aim_obj(aim_obj);
1665 pr_info("deregistering application interfacing module %s\n", aim->name);
1666 return 0;
1667}
1668EXPORT_SYMBOL_GPL(most_deregister_aim);
1669
1670/**
1671 * most_register_interface - registers an interface with core
1672 * @iface: pointer to the instance of the interface description.
1673 *
1674 * Allocates and initializes a new interface instance and all of its channels.
1675 * Returns a pointer to kobject or an error pointer.
1676 */
1677struct kobject *most_register_interface(struct most_interface *iface)
1678{
1679 unsigned int i;
1680 int id;
1681 char name[STRING_SIZE];
1682 char channel_name[STRING_SIZE];
1683 struct most_c_obj *c;
1684 struct most_inst_obj *inst;
1685
1686 if (!iface || !iface->enqueue || !iface->configure ||
1687 !iface->poison_channel || (iface->num_channels > MAX_CHANNELS)) {
1688 pr_err("Bad interface or channel overflow\n");
1689 return ERR_PTR(-EINVAL);
1690 }
1691
1692 id = ida_simple_get(&mdev_id, 0, 0, GFP_KERNEL);
1693 if (id < 0) {
1694 pr_info("Failed to alloc mdev ID\n");
1695 return ERR_PTR(id);
1696 }
1697 snprintf(name, STRING_SIZE, "mdev%d", id);
1698
1699 inst = create_most_inst_obj(name);
1700 if (!inst) {
1701 pr_info("Failed to allocate interface instance\n");
1702 return ERR_PTR(-ENOMEM);
1703 }
1704
1705 iface->priv = inst;
1706 INIT_LIST_HEAD(&inst->channel_list);
1707 inst->iface = iface;
1708 inst->dev_id = id;
1709 atomic_set(&inst->tainted, 0);
1710 list_add_tail(&inst->list, &instance_list);
1711
1712 for (i = 0; i < iface->num_channels; i++) {
1713 const char *name_suffix = iface->channel_vector[i].name_suffix;
1714
1715 if (!name_suffix)
1716 snprintf(channel_name, STRING_SIZE, "ch%d", i);
1717 else if (name_suffix[0] == '@')
1718 snprintf(channel_name, STRING_SIZE, "ch%d%s", i,
1719 name_suffix);
1720 else
1721 snprintf(channel_name, STRING_SIZE, "%s", name_suffix);
1722
1723 /* this increments the reference count of this instance */
1724 c = create_most_c_obj(channel_name, &inst->kobj);
1725 if (!c)
1726 goto free_instance;
1727 inst->channel[i] = c;
1728 c->is_starving = 0;
1729 c->iface = iface;
1730 c->inst = inst;
1731 c->channel_id = i;
1732 c->keep_mbo = false;
1733 c->enqueue_halt = false;
1734 c->is_poisoned = false;
1735 c->is_started = false;
1736 c->cfg.direction = 0;
1737 c->cfg.data_type = 0;
1738 c->cfg.num_buffers = 0;
1739 c->cfg.buffer_size = 0;
1740 c->cfg.subbuffer_size = 0;
1741 c->cfg.packets_per_xact = 0;
1742 spin_lock_init(&c->fifo_lock);
1743 INIT_LIST_HEAD(&c->fifo);
1744 INIT_LIST_HEAD(&c->trash_fifo);
1745 INIT_LIST_HEAD(&c->halt_fifo);
1746 init_completion(&c->cleanup);
1747 atomic_set(&c->mbo_ref, 0);
1748 mutex_init(&c->stop_task_mutex);
1749 list_add_tail(&c->list, &inst->channel_list);
1750 }
1751 pr_info("registered new MOST device mdev%d (%s)\n",
1752 inst->dev_id, iface->description);
1753 return &inst->kobj;
1754
1755free_instance:
1756 pr_info("Failed allocate channel(s)\n");
1757 list_del(&inst->list);
1758 destroy_most_inst_obj(inst);
1759 return ERR_PTR(-ENOMEM);
1760}
1761EXPORT_SYMBOL_GPL(most_register_interface);
1762
1763/**
1764 * most_deregister_interface - deregisters an interface with core
1765 * @iface: pointer to the interface instance description.
1766 *
1767 * Before removing an interface instance from the list, all running
1768 * channels are stopped and poisoned.
1769 */
1770void most_deregister_interface(struct most_interface *iface)
1771{
1772 struct most_inst_obj *i = iface->priv;
1773 struct most_c_obj *c;
1774
1775 mutex_lock(&deregister_mutex);
1776 if (unlikely(!i)) {
1777 pr_info("Bad Interface\n");
1778 mutex_unlock(&deregister_mutex);
1779 return;
1780 }
1781 pr_info("deregistering MOST device %s (%s)\n", i->kobj.name,
1782 iface->description);
1783
1784 atomic_set(&i->tainted, 1);
1785 mutex_unlock(&deregister_mutex);
1786
1787 while (modref) {
1788 if (iface->mod && modref)
1789 module_put(iface->mod);
1790 modref--;
1791 }
1792
1793 list_for_each_entry(c, &i->channel_list, list) {
1794 if (!c->is_started)
1795 continue;
1796
1797 mutex_lock(&c->stop_task_mutex);
1798 if (c->hdm_enqueue_task)
1799 kthread_stop(c->hdm_enqueue_task);
1800 c->hdm_enqueue_task = NULL;
1801 mutex_unlock(&c->stop_task_mutex);
1802
1803 if (iface->poison_channel(iface, c->channel_id))
1804 pr_err("Can't poison channel %d\n", c->channel_id);
1805 }
1806 ida_simple_remove(&mdev_id, i->dev_id);
1807 list_del(&i->list);
1808 destroy_most_inst_obj(i);
1809}
1810EXPORT_SYMBOL_GPL(most_deregister_interface);
1811
1812/**
1813 * most_stop_enqueue - prevents core from enqueueing MBOs
1814 * @iface: pointer to interface
1815 * @id: channel id
1816 *
1817 * This is called by an HDM that _cannot_ attend to its duties and
1818 * is imminent to get run over by the core. The core is not going to
1819 * enqueue any further packets unless the flagging HDM calls
1820 * most_resume enqueue().
1821 */
1822void most_stop_enqueue(struct most_interface *iface, int id)
1823{
1824 struct most_c_obj *c = get_channel_by_iface(iface, id);
1825
1826 if (likely(c))
1827 c->enqueue_halt = true;
1828}
1829EXPORT_SYMBOL_GPL(most_stop_enqueue);
1830
1831/**
1832 * most_resume_enqueue - allow core to enqueue MBOs again
1833 * @iface: pointer to interface
1834 * @id: channel id
1835 *
1836 * This clears the enqueue halt flag and enqueues all MBOs currently
1837 * sitting in the wait fifo.
1838 */
1839void most_resume_enqueue(struct most_interface *iface, int id)
1840{
1841 struct most_c_obj *c = get_channel_by_iface(iface, id);
1842
1843 if (unlikely(!c))
1844 return;
1845 c->enqueue_halt = false;
1846
1847 wake_up_interruptible(&c->hdm_fifo_wq);
1848}
1849EXPORT_SYMBOL_GPL(most_resume_enqueue);
1850
1851static int __init most_init(void)
1852{
1853 pr_info("init()\n");
1854 INIT_LIST_HEAD(&instance_list);
1855 INIT_LIST_HEAD(&aim_list);
1856 mutex_init(&deregister_mutex);
1857 ida_init(&mdev_id);
1858
1859 if (bus_register(&most_bus)) {
1860 pr_info("Cannot register most bus\n");
1861 goto exit;
1862 }
1863
1864 most_class = class_create(THIS_MODULE, "most");
1865 if (IS_ERR(most_class)) {
1866 pr_info("No udev support.\n");
1867 goto exit_bus;
1868 }
1869 if (driver_register(&mostcore)) {
1870 pr_info("Cannot register core driver\n");
1871 goto exit_class;
1872 }
1873
1874 class_glue_dir =
1875 device_create(most_class, NULL, 0, NULL, "mostcore");
1876 if (!class_glue_dir)
1877 goto exit_driver;
1878
1879 most_aim_kset =
1880 kset_create_and_add("aims", NULL, &class_glue_dir->kobj);
1881 if (!most_aim_kset)
1882 goto exit_class_container;
1883
1884 most_inst_kset =
1885 kset_create_and_add("devices", NULL, &class_glue_dir->kobj);
1886 if (!most_inst_kset)
1887 goto exit_driver_kset;
1888
1889 return 0;
1890
1891exit_driver_kset:
1892 kset_unregister(most_aim_kset);
1893exit_class_container:
1894 device_destroy(most_class, 0);
1895exit_driver:
1896 driver_unregister(&mostcore);
1897exit_class:
1898 class_destroy(most_class);
1899exit_bus:
1900 bus_unregister(&most_bus);
1901exit:
1902 return -ENOMEM;
1903}
1904
1905static void __exit most_exit(void)
1906{
1907 struct most_inst_obj *i, *i_tmp;
1908 struct most_aim_obj *d, *d_tmp;
1909
1910 pr_info("exit core module\n");
1911 list_for_each_entry_safe(d, d_tmp, &aim_list, list) {
1912 destroy_most_aim_obj(d);
1913 }
1914
1915 list_for_each_entry_safe(i, i_tmp, &instance_list, list) {
1916 list_del(&i->list);
1917 destroy_most_inst_obj(i);
1918 }
1919 kset_unregister(most_inst_kset);
1920 kset_unregister(most_aim_kset);
1921 device_destroy(most_class, 0);
1922 driver_unregister(&mostcore);
1923 class_destroy(most_class);
1924 bus_unregister(&most_bus);
1925 ida_destroy(&mdev_id);
1926}
1927
1928module_init(most_init);
1929module_exit(most_exit);
1930MODULE_LICENSE("GPL");
1931MODULE_AUTHOR("Christian Gromm <christian.gromm@microchip.com>");
1932MODULE_DESCRIPTION("Core module of stacked MOST Linux driver");
diff --git a/drivers/staging/most/mostcore/mostcore.h b/drivers/staging/most/mostcore/mostcore.h
new file mode 100644
index 000000000000..299c7d5aa73a
--- /dev/null
+++ b/drivers/staging/most/mostcore/mostcore.h
@@ -0,0 +1,316 @@
1/*
2 * mostcore.h - Interface between MostCore,
3 * Hardware Dependent Module (HDM) and Application Interface Module (AIM).
4 *
5 * Copyright (C) 2013-2015, Microchip Technology Germany II GmbH & Co. KG
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * This file is licensed under GPLv2.
13 */
14
15/*
16 * Authors:
17 * Andrey Shvetsov <andrey.shvetsov@k2l.de>
18 * Christian Gromm <christian.gromm@microchip.com>
19 * Sebastian Graf
20 */
21
22#ifndef __MOST_CORE_H__
23#define __MOST_CORE_H__
24
25#include <linux/types.h>
26
27struct kobject;
28struct module;
29
30/**
31 * Interface type
32 */
33enum most_interface_type {
34 ITYPE_LOOPBACK = 1,
35 ITYPE_I2C,
36 ITYPE_I2S,
37 ITYPE_TSI,
38 ITYPE_HBI,
39 ITYPE_MEDIALB_DIM,
40 ITYPE_MEDIALB_DIM2,
41 ITYPE_USB,
42 ITYPE_PCIE
43};
44
45/**
46 * Channel direction.
47 */
48enum most_channel_direction {
49 MOST_CH_RX = 1 << 0,
50 MOST_CH_TX = 1 << 1,
51};
52
53/**
54 * Channel data type.
55 */
56enum most_channel_data_type {
57 MOST_CH_CONTROL = 1 << 0,
58 MOST_CH_ASYNC = 1 << 1,
59 MOST_CH_ISOC_AVP = 1 << 2,
60 MOST_CH_SYNC = 1 << 5,
61};
62
63
64enum mbo_status_flags {
65 /* MBO was processed successfully (data was send or received )*/
66 MBO_SUCCESS = 0,
67 /* The MBO contains wrong or missing information. */
68 MBO_E_INVAL,
69 /* MBO was completed as HDM Channel will be closed */
70 MBO_E_CLOSE,
71};
72
73/**
74 * struct most_channel_capability - Channel capability
75 * @direction: Supported channel directions.
76 * The value is bitwise OR-combination of the values from the
77 * enumeration most_channel_direction. Zero is allowed value and means
78 * "channel may not be used".
79 * @data_type: Supported channel data types.
80 * The value is bitwise OR-combination of the values from the
81 * enumeration most_channel_data_type. Zero is allowed value and means
82 * "channel may not be used".
83 * @num_buffer_packet: Maximum number of buffers supported by this channel
84 * for packet data types (Async,Control,QoS)
85 * @buffer_size_packet: Maximum buffer size supported by this channel
86 * for packet data types (Async,Control,QoS)
87 * @num_buffer_streaming: Maximum number of buffers supported by this channel
88 * for streaming data types (Sync,AV Packetized)
89 * @buffer_size_streaming: Maximum buffer size supported by this channel
90 * for streaming data types (Sync,AV Packetized)
91 * @name_suffix: Optional suffix providean by an HDM that is attached to the
92 * regular channel name.
93 *
94 * Describes the capabilities of a MostCore channel like supported Data Types
95 * and directions. This information is provided by an HDM for the MostCore.
96 *
97 * The Core creates read only sysfs attribute files in
98 * /sys/devices/virtual/most/mostcore/devices/mdev-#/mdev#-ch#/ with the
99 * following attributes:
100 * -available_directions
101 * -available_datatypes
102 * -number_of_packet_buffers
103 * -number_of_stream_buffers
104 * -size_of_packet_buffer
105 * -size_of_stream_buffer
106 * where content of each file is a string with all supported properties of this
107 * very channel attribute.
108 */
109struct most_channel_capability {
110 u16 direction;
111 u16 data_type;
112 u16 num_buffers_packet;
113 u16 buffer_size_packet;
114 u16 num_buffers_streaming;
115 u16 buffer_size_streaming;
116 char *name_suffix;
117};
118
119/**
120 * struct most_channel_config - stores channel configuration
121 * @direction: direction of the channel
122 * @data_type: data type travelling over this channel
123 * @num_buffers: number of buffers
124 * @buffer_size: size of a buffer for AIM.
125 * Buffer size may be cutted down by HDM in a configure callback
126 * to match to a given interface and channel type.
127 * @extra_len: additional buffer space for internal HDM purposes like padding.
128 * May be set by HDM in a configure callback if needed.
129 * @subbuffer_size: size of a subbuffer
130 * @packets_per_xact: number of MOST frames that are packet inside one USB
131 * packet. This is USB specific
132 *
133 * Describes the configuration for a MostCore channel. This information is
134 * provided from the MostCore to a HDM (like the Medusa PCIe Interface) as a
135 * parameter of the "configure" function call.
136 */
137struct most_channel_config {
138 enum most_channel_direction direction;
139 enum most_channel_data_type data_type;
140 u16 num_buffers;
141 u16 buffer_size;
142 u16 extra_len;
143 u16 subbuffer_size;
144 u16 packets_per_xact;
145};
146
147/*
148 * struct mbo - MOST Buffer Object.
149 * @context: context for core completion handler
150 * @priv: private data for HDM
151 *
152 * public: documented fields that are used for the communications
153 * between MostCore and HDMs
154 *
155 * @list: list head for use by the mbo's current owner
156 * @ifp: (in) associated interface instance
157 * @hdm_channel_id: (in) HDM channel instance
158 * @virt_address: (in) kernel virtual address of the buffer
159 * @bus_address: (in) bus address of the buffer
160 * @buffer_length: (in) buffer payload length
161 * @processed_length: (out) processed length
162 * @status: (out) transfer status
163 * @complete: (in) completion routine
164 *
165 * The MostCore allocates and initializes the MBO.
166 *
167 * The HDM receives MBO for transfer from MostCore with the call to enqueue().
168 * The HDM copies the data to- or from the buffer depending on configured
169 * channel direction, set "processed_length" and "status" and completes
170 * the transfer procedure by calling the completion routine.
171 *
172 * At the end the MostCore deallocates the MBO or recycles it for further
173 * transfers for the same or different HDM.
174 *
175 * Directions of usage:
176 * The core driver should never access any MBO fields (even if marked
177 * as "public") while the MBO is owned by an HDM. The ownership starts with
178 * the call of enqueue() and ends with the call of its complete() routine.
179 *
180 * II.
181 * Every HDM attached to the core driver _must_ ensure that it returns any MBO
182 * it owns (due to a previous call to enqueue() by the core driver) before it
183 * de-registers an interface or gets unloaded from the kernel. If this direction
184 * is violated memory leaks will occur, since the core driver does _not_ track
185 * MBOs it is currently not in control of.
186 *
187 */
188struct mbo {
189 void *context;
190 void *priv;
191 struct list_head list;
192 struct most_interface *ifp;
193 u16 hdm_channel_id;
194 void *virt_address;
195 dma_addr_t bus_address;
196 u16 buffer_length;
197 u16 processed_length;
198 enum mbo_status_flags status;
199 void (*complete)(struct mbo *);
200};
201
202/**
203 * Interface instance description.
204 *
205 * Describes one instance of an interface like Medusa PCIe or Vantage USB.
206 * This structure is allocated and initialized in the HDM. MostCore may not
207 * modify this structure.
208 *
209 * @interface Interface type. \sa most_interface_type.
210 * @description PRELIMINARY.
211 * Unique description of the device instance from point of view of the
212 * interface in free text form (ASCII).
213 * It may be a hexadecimal presentation of the memory address for the MediaLB
214 * IP or USB device ID with USB properties for USB interface, etc.
215 * @num_channels Number of channels and size of the channel_vector.
216 * @channel_vector Properties of the channels.
217 * Array index represents channel ID by the driver.
218 * @configure Callback to change data type for the channel of the
219 * interface instance. May be zero if the instance of the interface is not
220 * configurable. Parameter channel_config describes direction and data
221 * type for the channel, configured by the higher level. The content of
222 * @enqueue Delivers MBO to the HDM for processing.
223 * After HDM completes Rx- or Tx- operation the processed MBO shall
224 * be returned back to the MostCore using completion routine.
225 * The reason to get the MBO delivered from the MostCore after the channel
226 * is poisoned is the re-opening of the channel by the application.
227 * In this case the HDM shall hold MBOs and service the channel as usual.
228 * The HDM must be able to hold at least one MBO for each channel.
229 * The callback returns a negative value on error, otherwise 0.
230 * @poison_channel Informs HDM about closing the channel. The HDM shall
231 * cancel all transfers and synchronously or asynchronously return
232 * all enqueued for this channel MBOs using the completion routine.
233 * The callback returns a negative value on error, otherwise 0.
234 * @request_netinfo: triggers retrieving of network info from the HDM by
235 * means of "Message exchange over MDP/MEP"
236 * @priv Private field used by mostcore to store context information.
237 */
238struct most_interface {
239 struct module *mod;
240 enum most_interface_type interface;
241 const char *description;
242 int num_channels;
243 struct most_channel_capability *channel_vector;
244 int (*configure)(struct most_interface *iface, int channel_idx,
245 struct most_channel_config *channel_config);
246 int (*enqueue)(struct most_interface *iface, int channel_idx,
247 struct mbo *mbo);
248 int (*poison_channel)(struct most_interface *iface, int channel_idx);
249 void (*request_netinfo)(struct most_interface *iface, int channel_idx);
250 void *priv;
251};
252
253/**
254 * struct most_aim - identifies MOST device driver to mostcore
255 * @name: Driver name
256 * @probe_channel: function for core to notify driver about channel connection
257 * @disconnect_channel: notification that a certain channel isn't available anymore
258 * @rx_completion: completion handler for received packets
259 * @tx_completion: completion handler for transmitted packets
260 * @context: context pointer to be used by mostcore
261 */
262struct most_aim {
263 const char *name;
264 int (*probe_channel)(struct most_interface *iface, int channel_idx,
265 struct most_channel_config *cfg,
266 struct kobject *parent, char *name);
267 int (*disconnect_channel)(struct most_interface *iface,
268 int channel_idx);
269 int (*rx_completion)(struct mbo *mbo);
270 int (*tx_completion)(struct most_interface *iface, int channel_idx);
271 void *context;
272};
273
274/**
275 * most_register_interface - Registers instance of the interface.
276 * @iface: Pointer to the interface instance description.
277 *
278 * Returns a pointer to the kobject of the generated instance.
279 *
280 * Note: HDM has to ensure that any reference held on the kobj is
281 * released before deregistering the interface.
282 */
283struct kobject *most_register_interface(struct most_interface *iface);
284
285/**
286 * Deregisters instance of the interface.
287 * @intf_instance Pointer to the interface instance description.
288 */
289void most_deregister_interface(struct most_interface *iface);
290int most_submit_mbo(struct mbo *mbo);
291
292/**
293 * most_stop_enqueue - prevents core from enqueing MBOs
294 * @iface: pointer to interface
295 * @channel_idx: channel index
296 */
297void most_stop_enqueue(struct most_interface *iface, int channel_idx);
298
299/**
300 * most_resume_enqueue - allow core to enqueue MBOs again
301 * @iface: pointer to interface
302 * @channel_idx: channel index
303 *
304 * This clears the enqueue halt flag and enqueues all MBOs currently
305 * in wait fifo.
306 */
307void most_resume_enqueue(struct most_interface *iface, int channel_idx);
308int most_register_aim(struct most_aim *aim);
309int most_deregister_aim(struct most_aim *aim);
310struct mbo *most_get_mbo(struct most_interface *iface, int channel_idx);
311void most_put_mbo(struct mbo *mbo);
312int most_start_channel(struct most_interface *iface, int channel_idx);
313int most_stop_channel(struct most_interface *iface, int channel_idx);
314
315
316#endif /* MOST_CORE_H_ */
diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.c b/drivers/staging/mt29f_spinand/mt29f_spinand.c
index 7285c64bac24..ad30ce4206ef 100644
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.c
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.c
@@ -948,7 +948,6 @@ static const struct of_device_id spinand_dt[] = {
948static struct spi_driver spinand_driver = { 948static struct spi_driver spinand_driver = {
949 .driver = { 949 .driver = {
950 .name = "mt29f", 950 .name = "mt29f",
951 .bus = &spi_bus_type,
952 .owner = THIS_MODULE, 951 .owner = THIS_MODULE,
953 .of_match_table = spinand_dt, 952 .of_match_table = spinand_dt,
954 }, 953 },
diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.h b/drivers/staging/mt29f_spinand/mt29f_spinand.h
index 7f2c24dc51b4..6c8e413b5b63 100644
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.h
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.h
@@ -101,7 +101,7 @@ struct spinand_cmd {
101 u8 *rx_buf; /* Rx buf */ 101 u8 *rx_buf; /* Rx buf */
102}; 102};
103 103
104extern int spinand_mtd(struct mtd_info *mtd); 104int spinand_mtd(struct mtd_info *mtd);
105extern void spinand_mtd_release(struct mtd_info *mtd); 105void spinand_mtd_release(struct mtd_info *mtd);
106 106
107#endif /* __LINUX_MTD_SPI_NAND_H */ 107#endif /* __LINUX_MTD_SPI_NAND_H */
diff --git a/drivers/staging/netlogic/platform_net.c b/drivers/staging/netlogic/platform_net.c
index 77c3c3522afa..e914147d7379 100644
--- a/drivers/staging/netlogic/platform_net.c
+++ b/drivers/staging/netlogic/platform_net.c
@@ -163,7 +163,7 @@ static void xls_gmac_init(void)
163 switch (nlm_prom_info.board_major_version) { 163 switch (nlm_prom_info.board_major_version) {
164 case 12: 164 case 12:
165 /* first block RGMII or XAUI, use RGMII */ 165 /* first block RGMII or XAUI, use RGMII */
166 ndata0.phy_interface = PHY_INTERFACE_MODE_RGMII, 166 ndata0.phy_interface = PHY_INTERFACE_MODE_RGMII;
167 ndata0.tx_stnid[0] = FMN_STNID_GMAC0_TX0; 167 ndata0.tx_stnid[0] = FMN_STNID_GMAC0_TX0;
168 ndata0.phy_addr[0] = 0; 168 ndata0.phy_addr[0] = 0;
169 169
diff --git a/drivers/staging/netlogic/xlr_net.h b/drivers/staging/netlogic/xlr_net.h
index 13e03f0a0a46..2f65ec5a615c 100644
--- a/drivers/staging/netlogic/xlr_net.h
+++ b/drivers/staging/netlogic/xlr_net.h
@@ -1102,4 +1102,4 @@ struct xlr_net_priv {
1102 u64 *class_3_spill; 1102 u64 *class_3_spill;
1103}; 1103};
1104 1104
1105extern void xlr_set_gmac_speed(struct xlr_net_priv *priv); 1105void xlr_set_gmac_speed(struct xlr_net_priv *priv);
diff --git a/drivers/staging/nvec/nvec.h b/drivers/staging/nvec/nvec.h
index e271375053fa..2ec9de906ca3 100644
--- a/drivers/staging/nvec/nvec.h
+++ b/drivers/staging/nvec/nvec.h
@@ -165,19 +165,18 @@ struct nvec_chip {
165 int state; 165 int state;
166}; 166};
167 167
168extern int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data, 168int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
169 short size); 169 short size);
170 170
171extern struct nvec_msg *nvec_write_sync(struct nvec_chip *nvec, 171struct nvec_msg *nvec_write_sync(struct nvec_chip *nvec,
172 const unsigned char *data, short size); 172 const unsigned char *data, short size);
173 173
174extern int nvec_register_notifier(struct nvec_chip *nvec, 174int nvec_register_notifier(struct nvec_chip *nvec,
175 struct notifier_block *nb, 175 struct notifier_block *nb,
176 unsigned int events); 176 unsigned int events);
177 177
178extern int nvec_unregister_notifier(struct nvec_chip *dev, 178int nvec_unregister_notifier(struct nvec_chip *dev, struct notifier_block *nb);
179 struct notifier_block *nb);
180 179
181extern void nvec_msg_free(struct nvec_chip *nvec, struct nvec_msg *msg); 180void nvec_msg_free(struct nvec_chip *nvec, struct nvec_msg *msg);
182 181
183#endif 182#endif
diff --git a/drivers/staging/octeon/ethernet-mdio.h b/drivers/staging/octeon/ethernet-mdio.h
index a530b55f27d8..5ed8483fc24d 100644
--- a/drivers/staging/octeon/ethernet-mdio.h
+++ b/drivers/staging/octeon/ethernet-mdio.h
@@ -25,7 +25,7 @@
25 25
26extern const struct ethtool_ops cvm_oct_ethtool_ops; 26extern const struct ethtool_ops cvm_oct_ethtool_ops;
27 27
28extern void octeon_mdiobus_force_mod_depencency(void); 28void octeon_mdiobus_force_mod_depencency(void);
29 29
30int cvm_oct_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 30int cvm_oct_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
31int cvm_oct_phy_setup_device(struct net_device *dev); 31int cvm_oct_phy_setup_device(struct net_device *dev);
diff --git a/drivers/staging/octeon/ethernet-rgmii.c b/drivers/staging/octeon/ethernet-rgmii.c
index beb7aac9c289..51dcb611702f 100644
--- a/drivers/staging/octeon/ethernet-rgmii.c
+++ b/drivers/staging/octeon/ethernet-rgmii.c
@@ -118,9 +118,10 @@ static void cvm_oct_rgmii_poll(struct net_device *dev)
118 } 118 }
119 119
120 /* Since the 10Mbps preamble workaround is allowed we need to enable 120 /* Since the 10Mbps preamble workaround is allowed we need to enable
121 preamble checking, FCS stripping, and clear error bits on 121 * preamble checking, FCS stripping, and clear error bits on
122 every speed change. If errors occur during 10Mbps operation 122 * every speed change. If errors occur during 10Mbps operation
123 the above code will change this stuff */ 123 * the above code will change this stuff
124 */
124 cvm_oct_set_hw_preamble(priv, true); 125 cvm_oct_set_hw_preamble(priv, true);
125 126
126 if (priv->phydev == NULL) { 127 if (priv->phydev == NULL) {
diff --git a/drivers/staging/octeon/ethernet-tx.c b/drivers/staging/octeon/ethernet-tx.c
index 7c1c1b052b7d..e2df041ca82d 100644
--- a/drivers/staging/octeon/ethernet-tx.c
+++ b/drivers/staging/octeon/ethernet-tx.c
@@ -396,10 +396,12 @@ dont_put_skbuff_in_hw:
396 396
397 /* Check if we can use the hardware checksumming */ 397 /* Check if we can use the hardware checksumming */
398 if ((skb->protocol == htons(ETH_P_IP)) && 398 if ((skb->protocol == htons(ETH_P_IP)) &&
399 (ip_hdr(skb)->version == 4) && (ip_hdr(skb)->ihl == 5) && 399 (ip_hdr(skb)->version == 4) &&
400 ((ip_hdr(skb)->frag_off == 0) || (ip_hdr(skb)->frag_off == htons(1 << 14))) 400 (ip_hdr(skb)->ihl == 5) &&
401 && ((ip_hdr(skb)->protocol == IPPROTO_TCP) 401 ((ip_hdr(skb)->frag_off == 0) ||
402 || (ip_hdr(skb)->protocol == IPPROTO_UDP))) { 402 (ip_hdr(skb)->frag_off == htons(1 << 14))) &&
403 ((ip_hdr(skb)->protocol == IPPROTO_TCP) ||
404 (ip_hdr(skb)->protocol == IPPROTO_UDP))) {
403 /* Use hardware checksum calc */ 405 /* Use hardware checksum calc */
404 pko_command.s.ipoffp1 = sizeof(struct ethhdr) + 1; 406 pko_command.s.ipoffp1 = sizeof(struct ethhdr) + 1;
405 } 407 }
diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
index f9dba23a3759..0718b35f7335 100644
--- a/drivers/staging/octeon/ethernet.c
+++ b/drivers/staging/octeon/ethernet.c
@@ -157,6 +157,7 @@ static void cvm_oct_configure_common_hw(void)
157#ifdef __LITTLE_ENDIAN 157#ifdef __LITTLE_ENDIAN
158 { 158 {
159 union cvmx_ipd_ctl_status ipd_ctl_status; 159 union cvmx_ipd_ctl_status ipd_ctl_status;
160
160 ipd_ctl_status.u64 = cvmx_read_csr(CVMX_IPD_CTL_STATUS); 161 ipd_ctl_status.u64 = cvmx_read_csr(CVMX_IPD_CTL_STATUS);
161 ipd_ctl_status.s.pkt_lend = 1; 162 ipd_ctl_status.s.pkt_lend = 1;
162 ipd_ctl_status.s.wqe_lend = 1; 163 ipd_ctl_status.s.wqe_lend = 1;
diff --git a/drivers/staging/octeon/octeon-ethernet.h b/drivers/staging/octeon/octeon-ethernet.h
index e9d3e9a7e8a7..a242c700bc53 100644
--- a/drivers/staging/octeon/octeon-ethernet.h
+++ b/drivers/staging/octeon/octeon-ethernet.h
@@ -53,20 +53,20 @@ struct octeon_ethernet {
53 53
54int cvm_oct_free_work(void *work_queue_entry); 54int cvm_oct_free_work(void *work_queue_entry);
55 55
56extern int cvm_oct_rgmii_init(struct net_device *dev); 56int cvm_oct_rgmii_init(struct net_device *dev);
57extern void cvm_oct_rgmii_uninit(struct net_device *dev); 57void cvm_oct_rgmii_uninit(struct net_device *dev);
58extern int cvm_oct_rgmii_open(struct net_device *dev); 58int cvm_oct_rgmii_open(struct net_device *dev);
59 59
60extern int cvm_oct_sgmii_init(struct net_device *dev); 60int cvm_oct_sgmii_init(struct net_device *dev);
61extern int cvm_oct_sgmii_open(struct net_device *dev); 61int cvm_oct_sgmii_open(struct net_device *dev);
62 62
63extern int cvm_oct_spi_init(struct net_device *dev); 63int cvm_oct_spi_init(struct net_device *dev);
64extern void cvm_oct_spi_uninit(struct net_device *dev); 64void cvm_oct_spi_uninit(struct net_device *dev);
65extern int cvm_oct_xaui_init(struct net_device *dev); 65int cvm_oct_xaui_init(struct net_device *dev);
66extern int cvm_oct_xaui_open(struct net_device *dev); 66int cvm_oct_xaui_open(struct net_device *dev);
67 67
68extern int cvm_oct_common_init(struct net_device *dev); 68int cvm_oct_common_init(struct net_device *dev);
69extern void cvm_oct_common_uninit(struct net_device *dev); 69void cvm_oct_common_uninit(struct net_device *dev);
70void cvm_oct_adjust_link(struct net_device *dev); 70void cvm_oct_adjust_link(struct net_device *dev);
71int cvm_oct_common_stop(struct net_device *dev); 71int cvm_oct_common_stop(struct net_device *dev);
72int cvm_oct_common_open(struct net_device *dev, 72int cvm_oct_common_open(struct net_device *dev,
diff --git a/drivers/staging/olpc_dcon/olpc_dcon.h b/drivers/staging/olpc_dcon/olpc_dcon.h
index aec98958f795..d06e19db1b80 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon.h
+++ b/drivers/staging/olpc_dcon/olpc_dcon.h
@@ -98,7 +98,7 @@ struct dcon_platform_data {
98 98
99#include <linux/interrupt.h> 99#include <linux/interrupt.h>
100 100
101extern irqreturn_t dcon_interrupt(int irq, void *id); 101irqreturn_t dcon_interrupt(int irq, void *id);
102 102
103#ifdef CONFIG_FB_OLPC_DCON_1 103#ifdef CONFIG_FB_OLPC_DCON_1
104extern struct dcon_platform_data dcon_pdata_xo_1; 104extern struct dcon_platform_data dcon_pdata_xo_1;
diff --git a/drivers/staging/ozwpan/Kconfig b/drivers/staging/ozwpan/Kconfig
deleted file mode 100644
index 7904caec546a..000000000000
--- a/drivers/staging/ozwpan/Kconfig
+++ /dev/null
@@ -1,9 +0,0 @@
1config USB_WPAN_HCD
2 tristate "USB over WiFi Host Controller"
3 depends on USB && NET
4 help
5 A driver for USB Host Controllers that are compatible with
6 Ozmo Devices USB over WiFi technology.
7
8 To compile this driver a module, choose M here: the module
9 will be called "ozwpan".
diff --git a/drivers/staging/ozwpan/Makefile b/drivers/staging/ozwpan/Makefile
deleted file mode 100644
index 29529c1a8e3c..000000000000
--- a/drivers/staging/ozwpan/Makefile
+++ /dev/null
@@ -1,16 +0,0 @@
1# -----------------------------------------------------------------------------
2# Copyright (c) 2011 Ozmo Inc
3# Released under the GNU General Public License Version 2 (GPLv2).
4# -----------------------------------------------------------------------------
5
6obj-$(CONFIG_USB_WPAN_HCD) += ozwpan.o
7ozwpan-y := \
8 ozmain.o \
9 ozpd.o \
10 ozusbsvc.o \
11 ozusbsvc1.o \
12 ozhcd.o \
13 ozeltbuf.o \
14 ozproto.o \
15 ozcdev.o \
16 ozurbparanoia.o
diff --git a/drivers/staging/ozwpan/README b/drivers/staging/ozwpan/README
deleted file mode 100644
index 7c055ec99544..000000000000
--- a/drivers/staging/ozwpan/README
+++ /dev/null
@@ -1,25 +0,0 @@
1OZWPAN USB Host Controller Driver
2---------------------------------
3This driver is a USB HCD driver that does not have an associated a physical
4device but instead uses Wi-Fi to communicate with the wireless peripheral.
5The USB requests are converted into a layer 2 network protocol and transmitted
6on the network using an ethertype (0x892e) regestered to Ozmo Device Inc.
7This driver is compatible with existing wireless devices that use Ozmo Devices
8technology.
9
10To operate the driver must be bound to a suitable network interface. This can
11be done when the module is loaded (specifying the name of the network interface
12as a parameter - e.g. 'insmod ozwpan g_net_dev=go0') or can be bound after
13loading using an ioctl call. See the ozappif.h file and the ioctls
14OZ_IOCTL_ADD_BINDING and OZ_IOCTL_REMOVE_BINDING.
15
16The devices connect to the host use Wi-Fi Direct so a network card that supports
17Wi-Fi direct is required. A recent version (0.8.x or later) version of the
18wpa_supplicant can be used to setup the network interface to create a persistent
19autonomous group (for older pre-WFD peripherals) or put in a listen state to
20allow group negotiation to occur for more recent devices that support WFD.
21
22The protocol used over the network does not directly mimic the USB bus
23transactions as this would be rather busy and inefficient. Instead the chapter 9
24requests are converted into a request/response pair of messages. (See
25ozprotocol.h for data structures used in the protocol).
diff --git a/drivers/staging/ozwpan/TODO b/drivers/staging/ozwpan/TODO
deleted file mode 100644
index f32c1c0bc875..000000000000
--- a/drivers/staging/ozwpan/TODO
+++ /dev/null
@@ -1,14 +0,0 @@
1TODO:
2 - Convert event tracing code to in-kernel tracing infrastructure
3 - Check for remaining ioctl & check if that can be converted into
4 sysfs entries
5 - Convert debug prints to appropriate dev_debug or something better
6 - Modify Kconfig to add CONFIG option for enabling/disabling event
7 tracing.
8 - check USB HCD implementation is complete and correct.
9 - code review by USB developer community.
10 - testing with as many devices as possible.
11
12Please send any patches for this driver to
13Shigekatsu Tateno <shigekatsu.tateno@atmel.com>
14and Greg Kroah-Hartman <gregkh@linuxfoundation.org>.
diff --git a/drivers/staging/ozwpan/ozappif.h b/drivers/staging/ozwpan/ozappif.h
deleted file mode 100644
index ea1b271fdcda..000000000000
--- a/drivers/staging/ozwpan/ozappif.h
+++ /dev/null
@@ -1,36 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
5 */
6#ifndef _OZAPPIF_H
7#define _OZAPPIF_H
8
9#define OZ_IOCTL_MAGIC 0xf4
10
11struct oz_mac_addr {
12 __u8 a[6];
13};
14
15#define OZ_MAX_PDS 8
16
17struct oz_pd_list {
18 __u32 count;
19 struct oz_mac_addr addr[OZ_MAX_PDS];
20};
21
22#define OZ_MAX_BINDING_LEN 32
23
24struct oz_binding_info {
25 char name[OZ_MAX_BINDING_LEN];
26};
27
28#define OZ_IOCTL_GET_PD_LIST _IOR(OZ_IOCTL_MAGIC, 0, struct oz_pd_list)
29#define OZ_IOCTL_SET_ACTIVE_PD _IOW(OZ_IOCTL_MAGIC, 1, struct oz_mac_addr)
30#define OZ_IOCTL_GET_ACTIVE_PD _IOR(OZ_IOCTL_MAGIC, 2, struct oz_mac_addr)
31#define OZ_IOCTL_ADD_BINDING _IOW(OZ_IOCTL_MAGIC, 3, struct oz_binding_info)
32#define OZ_IOCTL_REMOVE_BINDING _IOW(OZ_IOCTL_MAGIC, 4, struct oz_binding_info)
33#define OZ_IOCTL_MAX 5
34
35
36#endif /* _OZAPPIF_H */
diff --git a/drivers/staging/ozwpan/ozcdev.c b/drivers/staging/ozwpan/ozcdev.c
deleted file mode 100644
index da0e1fd50f26..000000000000
--- a/drivers/staging/ozwpan/ozcdev.c
+++ /dev/null
@@ -1,554 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
5 */
6#include <linux/module.h>
7#include <linux/fs.h>
8#include <linux/cdev.h>
9#include <linux/uaccess.h>
10#include <linux/netdevice.h>
11#include <linux/etherdevice.h>
12#include <linux/poll.h>
13#include <linux/sched.h>
14#include "ozdbg.h"
15#include "ozprotocol.h"
16#include "ozappif.h"
17#include "ozeltbuf.h"
18#include "ozpd.h"
19#include "ozproto.h"
20#include "ozcdev.h"
21
22#define OZ_RD_BUF_SZ 256
23struct oz_cdev {
24 dev_t devnum;
25 struct cdev cdev;
26 wait_queue_head_t rdq;
27 spinlock_t lock;
28 u8 active_addr[ETH_ALEN];
29 struct oz_pd *active_pd;
30};
31
32/* Per PD context for the serial service stored in the PD. */
33struct oz_serial_ctx {
34 atomic_t ref_count;
35 u8 tx_seq_num;
36 u8 rx_seq_num;
37 u8 rd_buf[OZ_RD_BUF_SZ];
38 int rd_in;
39 int rd_out;
40};
41
42static struct oz_cdev g_cdev;
43static struct class *g_oz_class;
44
45/*
46 * Context: process and softirq
47 */
48static struct oz_serial_ctx *oz_cdev_claim_ctx(struct oz_pd *pd)
49{
50 struct oz_serial_ctx *ctx;
51
52 spin_lock_bh(&pd->app_lock[OZ_APPID_SERIAL]);
53 ctx = (struct oz_serial_ctx *) pd->app_ctx[OZ_APPID_SERIAL];
54 if (ctx)
55 atomic_inc(&ctx->ref_count);
56 spin_unlock_bh(&pd->app_lock[OZ_APPID_SERIAL]);
57 return ctx;
58}
59
60/*
61 * Context: softirq or process
62 */
63static void oz_cdev_release_ctx(struct oz_serial_ctx *ctx)
64{
65 if (atomic_dec_and_test(&ctx->ref_count)) {
66 oz_dbg(ON, "Dealloc serial context\n");
67 kfree(ctx);
68 }
69}
70
71/*
72 * Context: process
73 */
74static int oz_cdev_open(struct inode *inode, struct file *filp)
75{
76 struct oz_cdev *dev = container_of(inode->i_cdev, struct oz_cdev, cdev);
77
78 oz_dbg(ON, "major = %d minor = %d\n", imajor(inode), iminor(inode));
79
80 filp->private_data = dev;
81 return 0;
82}
83
84/*
85 * Context: process
86 */
87static int oz_cdev_release(struct inode *inode, struct file *filp)
88{
89 return 0;
90}
91
92/*
93 * Context: process
94 */
95static ssize_t oz_cdev_read(struct file *filp, char __user *buf, size_t count,
96 loff_t *fpos)
97{
98 int n;
99 int ix;
100
101 struct oz_pd *pd;
102 struct oz_serial_ctx *ctx;
103
104 spin_lock_bh(&g_cdev.lock);
105 pd = g_cdev.active_pd;
106 if (pd)
107 oz_pd_get(pd);
108 spin_unlock_bh(&g_cdev.lock);
109 if (pd == NULL)
110 return -1;
111 ctx = oz_cdev_claim_ctx(pd);
112 if (ctx == NULL)
113 goto out2;
114 n = ctx->rd_in - ctx->rd_out;
115 if (n < 0)
116 n += OZ_RD_BUF_SZ;
117 if (count > n)
118 count = n;
119 ix = ctx->rd_out;
120 n = OZ_RD_BUF_SZ - ix;
121 if (n > count)
122 n = count;
123 if (copy_to_user(buf, &ctx->rd_buf[ix], n)) {
124 count = 0;
125 goto out1;
126 }
127 ix += n;
128 if (ix == OZ_RD_BUF_SZ)
129 ix = 0;
130 if (n < count) {
131 if (copy_to_user(&buf[n], ctx->rd_buf, count-n)) {
132 count = 0;
133 goto out1;
134 }
135 ix = count-n;
136 }
137 ctx->rd_out = ix;
138out1:
139 oz_cdev_release_ctx(ctx);
140out2:
141 oz_pd_put(pd);
142 return count;
143}
144
145/*
146 * Context: process
147 */
148static ssize_t oz_cdev_write(struct file *filp, const char __user *buf,
149 size_t count, loff_t *fpos)
150{
151 struct oz_pd *pd;
152 struct oz_elt_buf *eb;
153 struct oz_elt_info *ei;
154 struct oz_elt *elt;
155 struct oz_app_hdr *app_hdr;
156 struct oz_serial_ctx *ctx;
157
158 if (count > sizeof(ei->data) - sizeof(*elt) - sizeof(*app_hdr))
159 return -EINVAL;
160
161 spin_lock_bh(&g_cdev.lock);
162 pd = g_cdev.active_pd;
163 if (pd)
164 oz_pd_get(pd);
165 spin_unlock_bh(&g_cdev.lock);
166 if (pd == NULL)
167 return -ENXIO;
168 if (!(pd->state & OZ_PD_S_CONNECTED))
169 return -EAGAIN;
170 eb = &pd->elt_buff;
171 ei = oz_elt_info_alloc(eb);
172 if (ei == NULL) {
173 count = 0;
174 goto out;
175 }
176 elt = (struct oz_elt *)ei->data;
177 app_hdr = (struct oz_app_hdr *)(elt+1);
178 elt->length = sizeof(struct oz_app_hdr) + count;
179 elt->type = OZ_ELT_APP_DATA;
180 ei->app_id = OZ_APPID_SERIAL;
181 ei->length = elt->length + sizeof(struct oz_elt);
182 app_hdr->app_id = OZ_APPID_SERIAL;
183 if (copy_from_user(app_hdr+1, buf, count))
184 goto out;
185 spin_lock_bh(&pd->app_lock[OZ_APPID_USB]);
186 ctx = (struct oz_serial_ctx *) pd->app_ctx[OZ_APPID_SERIAL];
187 if (ctx) {
188 app_hdr->elt_seq_num = ctx->tx_seq_num++;
189 if (ctx->tx_seq_num == 0)
190 ctx->tx_seq_num = 1;
191 spin_lock(&eb->lock);
192 if (oz_queue_elt_info(eb, 0, 0, ei) == 0)
193 ei = NULL;
194 spin_unlock(&eb->lock);
195 }
196 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB]);
197out:
198 if (ei) {
199 count = 0;
200 spin_lock_bh(&eb->lock);
201 oz_elt_info_free(eb, ei);
202 spin_unlock_bh(&eb->lock);
203 }
204 oz_pd_put(pd);
205 return count;
206}
207
208/*
209 * Context: process
210 */
211static int oz_set_active_pd(const u8 *addr)
212{
213 int rc = 0;
214 struct oz_pd *pd;
215 struct oz_pd *old_pd;
216
217 pd = oz_pd_find(addr);
218 if (pd) {
219 spin_lock_bh(&g_cdev.lock);
220 ether_addr_copy(g_cdev.active_addr, addr);
221 old_pd = g_cdev.active_pd;
222 g_cdev.active_pd = pd;
223 spin_unlock_bh(&g_cdev.lock);
224 if (old_pd)
225 oz_pd_put(old_pd);
226 } else {
227 if (is_zero_ether_addr(addr)) {
228 spin_lock_bh(&g_cdev.lock);
229 pd = g_cdev.active_pd;
230 g_cdev.active_pd = NULL;
231 memset(g_cdev.active_addr, 0,
232 sizeof(g_cdev.active_addr));
233 spin_unlock_bh(&g_cdev.lock);
234 if (pd)
235 oz_pd_put(pd);
236 } else {
237 rc = -1;
238 }
239 }
240 return rc;
241}
242
243/*
244 * Context: process
245 */
246static long oz_cdev_ioctl(struct file *filp, unsigned int cmd,
247 unsigned long arg)
248{
249 int rc = 0;
250
251 if (_IOC_TYPE(cmd) != OZ_IOCTL_MAGIC)
252 return -ENOTTY;
253 if (_IOC_NR(cmd) > OZ_IOCTL_MAX)
254 return -ENOTTY;
255 if (_IOC_DIR(cmd) & _IOC_READ)
256 rc = !access_ok(VERIFY_WRITE, (void __user *)arg,
257 _IOC_SIZE(cmd));
258 else if (_IOC_DIR(cmd) & _IOC_WRITE)
259 rc = !access_ok(VERIFY_READ, (void __user *)arg,
260 _IOC_SIZE(cmd));
261 if (rc)
262 return -EFAULT;
263 switch (cmd) {
264 case OZ_IOCTL_GET_PD_LIST: {
265 struct oz_pd_list list;
266
267 oz_dbg(ON, "OZ_IOCTL_GET_PD_LIST\n");
268 memset(&list, 0, sizeof(list));
269 list.count = oz_get_pd_list(list.addr, OZ_MAX_PDS);
270 if (copy_to_user((void __user *)arg, &list,
271 sizeof(list)))
272 return -EFAULT;
273 }
274 break;
275 case OZ_IOCTL_SET_ACTIVE_PD: {
276 u8 addr[ETH_ALEN];
277
278 oz_dbg(ON, "OZ_IOCTL_SET_ACTIVE_PD\n");
279 if (copy_from_user(addr, (void __user *)arg, ETH_ALEN))
280 return -EFAULT;
281 rc = oz_set_active_pd(addr);
282 }
283 break;
284 case OZ_IOCTL_GET_ACTIVE_PD: {
285 u8 addr[ETH_ALEN];
286
287 oz_dbg(ON, "OZ_IOCTL_GET_ACTIVE_PD\n");
288 spin_lock_bh(&g_cdev.lock);
289 ether_addr_copy(addr, g_cdev.active_addr);
290 spin_unlock_bh(&g_cdev.lock);
291 if (copy_to_user((void __user *)arg, addr, ETH_ALEN))
292 return -EFAULT;
293 }
294 break;
295 case OZ_IOCTL_ADD_BINDING:
296 case OZ_IOCTL_REMOVE_BINDING: {
297 struct oz_binding_info b;
298
299 if (copy_from_user(&b, (void __user *)arg,
300 sizeof(struct oz_binding_info))) {
301 return -EFAULT;
302 }
303 /* Make sure name is null terminated. */
304 b.name[OZ_MAX_BINDING_LEN-1] = 0;
305 if (cmd == OZ_IOCTL_ADD_BINDING)
306 oz_binding_add(b.name);
307 else
308 oz_binding_remove(b.name);
309 }
310 break;
311 }
312 return rc;
313}
314
315/*
316 * Context: process
317 */
318static unsigned int oz_cdev_poll(struct file *filp, poll_table *wait)
319{
320 unsigned int ret = 0;
321 struct oz_cdev *dev = filp->private_data;
322
323 oz_dbg(ON, "Poll called wait = %p\n", wait);
324 spin_lock_bh(&dev->lock);
325 if (dev->active_pd) {
326 struct oz_serial_ctx *ctx = oz_cdev_claim_ctx(dev->active_pd);
327
328 if (ctx) {
329 if (ctx->rd_in != ctx->rd_out)
330 ret |= POLLIN | POLLRDNORM;
331 oz_cdev_release_ctx(ctx);
332 }
333 }
334 spin_unlock_bh(&dev->lock);
335 if (wait)
336 poll_wait(filp, &dev->rdq, wait);
337 return ret;
338}
339
340/*
341 */
342static const struct file_operations oz_fops = {
343 .owner = THIS_MODULE,
344 .open = oz_cdev_open,
345 .release = oz_cdev_release,
346 .read = oz_cdev_read,
347 .write = oz_cdev_write,
348 .unlocked_ioctl = oz_cdev_ioctl,
349 .poll = oz_cdev_poll
350};
351
352/*
353 * Context: process
354 */
355int oz_cdev_register(void)
356{
357 int err;
358 struct device *dev;
359
360 memset(&g_cdev, 0, sizeof(g_cdev));
361 err = alloc_chrdev_region(&g_cdev.devnum, 0, 1, "ozwpan");
362 if (err < 0)
363 return err;
364 oz_dbg(ON, "Alloc dev number %d:%d\n",
365 MAJOR(g_cdev.devnum), MINOR(g_cdev.devnum));
366 cdev_init(&g_cdev.cdev, &oz_fops);
367 g_cdev.cdev.owner = THIS_MODULE;
368 spin_lock_init(&g_cdev.lock);
369 init_waitqueue_head(&g_cdev.rdq);
370 err = cdev_add(&g_cdev.cdev, g_cdev.devnum, 1);
371 if (err < 0) {
372 oz_dbg(ON, "Failed to add cdev\n");
373 goto unregister;
374 }
375 g_oz_class = class_create(THIS_MODULE, "ozmo_wpan");
376 if (IS_ERR(g_oz_class)) {
377 oz_dbg(ON, "Failed to register ozmo_wpan class\n");
378 err = PTR_ERR(g_oz_class);
379 goto delete;
380 }
381 dev = device_create(g_oz_class, NULL, g_cdev.devnum, NULL, "ozwpan");
382 if (IS_ERR(dev)) {
383 oz_dbg(ON, "Failed to create sysfs entry for cdev\n");
384 err = PTR_ERR(dev);
385 goto delete;
386 }
387 return 0;
388
389delete:
390 cdev_del(&g_cdev.cdev);
391unregister:
392 unregister_chrdev_region(g_cdev.devnum, 1);
393 return err;
394}
395
396/*
397 * Context: process
398 */
399int oz_cdev_deregister(void)
400{
401 cdev_del(&g_cdev.cdev);
402 unregister_chrdev_region(g_cdev.devnum, 1);
403 if (g_oz_class) {
404 device_destroy(g_oz_class, g_cdev.devnum);
405 class_destroy(g_oz_class);
406 }
407 return 0;
408}
409
410/*
411 * Context: process
412 */
413int oz_cdev_init(void)
414{
415 oz_app_enable(OZ_APPID_SERIAL, 1);
416 return 0;
417}
418
419/*
420 * Context: process
421 */
422void oz_cdev_term(void)
423{
424 oz_app_enable(OZ_APPID_SERIAL, 0);
425}
426
427/*
428 * Context: softirq-serialized
429 */
430int oz_cdev_start(struct oz_pd *pd, int resume)
431{
432 struct oz_serial_ctx *ctx;
433 struct oz_serial_ctx *old_ctx;
434
435 if (resume) {
436 oz_dbg(ON, "Serial service resumed\n");
437 return 0;
438 }
439 ctx = kzalloc(sizeof(struct oz_serial_ctx), GFP_ATOMIC);
440 if (ctx == NULL)
441 return -ENOMEM;
442 atomic_set(&ctx->ref_count, 1);
443 ctx->tx_seq_num = 1;
444 spin_lock_bh(&pd->app_lock[OZ_APPID_SERIAL]);
445 old_ctx = pd->app_ctx[OZ_APPID_SERIAL];
446 if (old_ctx) {
447 spin_unlock_bh(&pd->app_lock[OZ_APPID_SERIAL]);
448 kfree(ctx);
449 } else {
450 pd->app_ctx[OZ_APPID_SERIAL] = ctx;
451 spin_unlock_bh(&pd->app_lock[OZ_APPID_SERIAL]);
452 }
453 spin_lock(&g_cdev.lock);
454 if ((g_cdev.active_pd == NULL) &&
455 ether_addr_equal(pd->mac_addr, g_cdev.active_addr)) {
456 oz_pd_get(pd);
457 g_cdev.active_pd = pd;
458 oz_dbg(ON, "Active PD arrived\n");
459 }
460 spin_unlock(&g_cdev.lock);
461 oz_dbg(ON, "Serial service started\n");
462 return 0;
463}
464
465/*
466 * Context: softirq or process
467 */
468void oz_cdev_stop(struct oz_pd *pd, int pause)
469{
470 struct oz_serial_ctx *ctx;
471
472 if (pause) {
473 oz_dbg(ON, "Serial service paused\n");
474 return;
475 }
476 spin_lock_bh(&pd->app_lock[OZ_APPID_SERIAL]);
477 ctx = (struct oz_serial_ctx *) pd->app_ctx[OZ_APPID_SERIAL];
478 pd->app_ctx[OZ_APPID_SERIAL] = NULL;
479 spin_unlock_bh(&pd->app_lock[OZ_APPID_SERIAL]);
480 if (ctx)
481 oz_cdev_release_ctx(ctx);
482 spin_lock(&g_cdev.lock);
483 if (pd == g_cdev.active_pd)
484 g_cdev.active_pd = NULL;
485 else
486 pd = NULL;
487 spin_unlock(&g_cdev.lock);
488 if (pd) {
489 oz_pd_put(pd);
490 oz_dbg(ON, "Active PD departed\n");
491 }
492 oz_dbg(ON, "Serial service stopped\n");
493}
494
495/*
496 * Context: softirq-serialized
497 */
498void oz_cdev_rx(struct oz_pd *pd, struct oz_elt *elt)
499{
500 struct oz_serial_ctx *ctx;
501 struct oz_app_hdr *app_hdr;
502 u8 *data;
503 int len;
504 int space;
505 int copy_sz;
506 int ix;
507
508 ctx = oz_cdev_claim_ctx(pd);
509 if (ctx == NULL) {
510 oz_dbg(ON, "Cannot claim serial context\n");
511 return;
512 }
513
514 app_hdr = (struct oz_app_hdr *)(elt+1);
515 /* If sequence number is non-zero then check it is not a duplicate.
516 */
517 if (app_hdr->elt_seq_num != 0) {
518 if (((ctx->rx_seq_num - app_hdr->elt_seq_num) & 0x80) == 0) {
519 /* Reject duplicate element. */
520 oz_dbg(ON, "Duplicate element:%02x %02x\n",
521 app_hdr->elt_seq_num, ctx->rx_seq_num);
522 goto out;
523 }
524 }
525 ctx->rx_seq_num = app_hdr->elt_seq_num;
526 len = elt->length - sizeof(struct oz_app_hdr);
527 data = ((u8 *)(elt+1)) + sizeof(struct oz_app_hdr);
528 if (len <= 0)
529 goto out;
530 space = ctx->rd_out - ctx->rd_in - 1;
531 if (space < 0)
532 space += OZ_RD_BUF_SZ;
533 if (len > space) {
534 oz_dbg(ON, "Not enough space:%d %d\n", len, space);
535 len = space;
536 }
537 ix = ctx->rd_in;
538 copy_sz = OZ_RD_BUF_SZ - ix;
539 if (copy_sz > len)
540 copy_sz = len;
541 memcpy(&ctx->rd_buf[ix], data, copy_sz);
542 len -= copy_sz;
543 ix += copy_sz;
544 if (ix == OZ_RD_BUF_SZ)
545 ix = 0;
546 if (len) {
547 memcpy(ctx->rd_buf, data+copy_sz, len);
548 ix = len;
549 }
550 ctx->rd_in = ix;
551 wake_up(&g_cdev.rdq);
552out:
553 oz_cdev_release_ctx(ctx);
554}
diff --git a/drivers/staging/ozwpan/ozcdev.h b/drivers/staging/ozwpan/ozcdev.h
deleted file mode 100644
index dd11935a093f..000000000000
--- a/drivers/staging/ozwpan/ozcdev.h
+++ /dev/null
@@ -1,17 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
5 */
6#ifndef _OZCDEV_H
7#define _OZCDEV_H
8
9int oz_cdev_register(void);
10int oz_cdev_deregister(void);
11int oz_cdev_init(void);
12void oz_cdev_term(void);
13int oz_cdev_start(struct oz_pd *pd, int resume);
14void oz_cdev_stop(struct oz_pd *pd, int pause);
15void oz_cdev_rx(struct oz_pd *pd, struct oz_elt *elt);
16
17#endif /* _OZCDEV_H */
diff --git a/drivers/staging/ozwpan/ozdbg.h b/drivers/staging/ozwpan/ozdbg.h
deleted file mode 100644
index b86a2b7e0178..000000000000
--- a/drivers/staging/ozwpan/ozdbg.h
+++ /dev/null
@@ -1,54 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * ---------------------------------------------------------------------------*/
5
6#ifndef _OZDBG_H
7#define _OZDBG_H
8
9#define OZ_WANT_DBG 0
10#define OZ_WANT_VERBOSE_DBG 1
11
12#define OZ_DBG_ON 0x0
13#define OZ_DBG_STREAM 0x1
14#define OZ_DBG_URB 0x2
15#define OZ_DBG_CTRL_DETAIL 0x4
16#define OZ_DBG_HUB 0x8
17#define OZ_DBG_RX_FRAMES 0x10
18#define OZ_DBG_TX_FRAMES 0x20
19
20#define OZ_DEFAULT_DBG_MASK \
21 ( \
22 /* OZ_DBG_STREAM | */ \
23 /* OZ_DBG_URB | */ \
24 /* OZ_DBG_CTRL_DETAIL | */ \
25 OZ_DBG_HUB | \
26 /* OZ_DBG_RX_FRAMES | */ \
27 /* OZ_DBG_TX_FRAMES | */ \
28 0)
29
30extern unsigned int oz_dbg_mask;
31
32#define oz_want_dbg(mask) \
33 ((OZ_WANT_DBG && (OZ_DBG_##mask == OZ_DBG_ON)) || \
34 (OZ_WANT_VERBOSE_DBG && (OZ_DBG_##mask & oz_dbg_mask)))
35
36#define oz_dbg(mask, fmt, ...) \
37do { \
38 if (oz_want_dbg(mask)) \
39 pr_debug(fmt, ##__VA_ARGS__); \
40} while (0)
41
42#define oz_cdev_dbg(cdev, mask, fmt, ...) \
43do { \
44 if (oz_want_dbg(mask)) \
45 netdev_dbg((cdev)->dev, fmt, ##__VA_ARGS__); \
46} while (0)
47
48#define oz_pd_dbg(pd, mask, fmt, ...) \
49do { \
50 if (oz_want_dbg(mask)) \
51 pr_debug(fmt, ##__VA_ARGS__); \
52} while (0)
53
54#endif /* _OZDBG_H */
diff --git a/drivers/staging/ozwpan/ozeltbuf.c b/drivers/staging/ozwpan/ozeltbuf.c
deleted file mode 100644
index 01b25da44241..000000000000
--- a/drivers/staging/ozwpan/ozeltbuf.c
+++ /dev/null
@@ -1,252 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
5 */
6#include <linux/module.h>
7#include <linux/netdevice.h>
8#include "ozdbg.h"
9#include "ozprotocol.h"
10#include "ozeltbuf.h"
11#include "ozpd.h"
12
13/*
14 * Context: softirq-serialized
15 */
16void oz_elt_buf_init(struct oz_elt_buf *buf)
17{
18 memset(buf, 0, sizeof(struct oz_elt_buf));
19 INIT_LIST_HEAD(&buf->stream_list);
20 INIT_LIST_HEAD(&buf->order_list);
21 INIT_LIST_HEAD(&buf->isoc_list);
22 spin_lock_init(&buf->lock);
23}
24
25/*
26 * Context: softirq or process
27 */
28void oz_elt_buf_term(struct oz_elt_buf *buf)
29{
30 struct oz_elt_info *ei, *n;
31
32 list_for_each_entry_safe(ei, n, &buf->isoc_list, link_order)
33 kfree(ei);
34 list_for_each_entry_safe(ei, n, &buf->order_list, link_order)
35 kfree(ei);
36}
37
38/*
39 * Context: softirq or process
40 */
41struct oz_elt_info *oz_elt_info_alloc(struct oz_elt_buf *buf)
42{
43 struct oz_elt_info *ei;
44
45 ei = kmem_cache_zalloc(oz_elt_info_cache, GFP_ATOMIC);
46 if (ei) {
47 INIT_LIST_HEAD(&ei->link);
48 INIT_LIST_HEAD(&ei->link_order);
49 }
50 return ei;
51}
52
53/*
54 * Precondition: oz_elt_buf.lock must be held.
55 * Context: softirq or process
56 */
57void oz_elt_info_free(struct oz_elt_buf *buf, struct oz_elt_info *ei)
58{
59 if (ei)
60 kmem_cache_free(oz_elt_info_cache, ei);
61}
62
63/*------------------------------------------------------------------------------
64 * Context: softirq
65 */
66void oz_elt_info_free_chain(struct oz_elt_buf *buf, struct list_head *list)
67{
68 struct oz_elt_info *ei, *n;
69
70 spin_lock_bh(&buf->lock);
71 list_for_each_entry_safe(ei, n, list->next, link)
72 oz_elt_info_free(buf, ei);
73 spin_unlock_bh(&buf->lock);
74}
75
76int oz_elt_stream_create(struct oz_elt_buf *buf, u8 id, int max_buf_count)
77{
78 struct oz_elt_stream *st;
79
80 oz_dbg(ON, "%s: (0x%x)\n", __func__, id);
81
82 st = kzalloc(sizeof(struct oz_elt_stream), GFP_ATOMIC);
83 if (st == NULL)
84 return -ENOMEM;
85 atomic_set(&st->ref_count, 1);
86 st->id = id;
87 st->max_buf_count = max_buf_count;
88 INIT_LIST_HEAD(&st->elt_list);
89 spin_lock_bh(&buf->lock);
90 list_add_tail(&st->link, &buf->stream_list);
91 spin_unlock_bh(&buf->lock);
92 return 0;
93}
94
95int oz_elt_stream_delete(struct oz_elt_buf *buf, u8 id)
96{
97 struct list_head *e, *n;
98 struct oz_elt_stream *st = NULL;
99
100 oz_dbg(ON, "%s: (0x%x)\n", __func__, id);
101 spin_lock_bh(&buf->lock);
102 list_for_each(e, &buf->stream_list) {
103 st = list_entry(e, struct oz_elt_stream, link);
104 if (st->id == id) {
105 list_del(e);
106 break;
107 }
108 st = NULL;
109 }
110 if (!st) {
111 spin_unlock_bh(&buf->lock);
112 return -1;
113 }
114 list_for_each_safe(e, n, &st->elt_list) {
115 struct oz_elt_info *ei =
116 list_entry(e, struct oz_elt_info, link);
117 list_del_init(&ei->link);
118 list_del_init(&ei->link_order);
119 st->buf_count -= ei->length;
120 oz_dbg(STREAM, "Stream down: %d %d %d\n",
121 st->buf_count, ei->length, atomic_read(&st->ref_count));
122 oz_elt_stream_put(st);
123 oz_elt_info_free(buf, ei);
124 }
125 spin_unlock_bh(&buf->lock);
126 oz_elt_stream_put(st);
127 return 0;
128}
129
130void oz_elt_stream_get(struct oz_elt_stream *st)
131{
132 atomic_inc(&st->ref_count);
133}
134
135void oz_elt_stream_put(struct oz_elt_stream *st)
136{
137 if (atomic_dec_and_test(&st->ref_count)) {
138 oz_dbg(ON, "Stream destroyed\n");
139 kfree(st);
140 }
141}
142
143/*
144 * Precondition: Element buffer lock must be held.
145 * If this function fails the caller is responsible for deallocating the elt
146 * info structure.
147 */
148int oz_queue_elt_info(struct oz_elt_buf *buf, u8 isoc, u8 id,
149 struct oz_elt_info *ei)
150{
151 struct oz_elt_stream *st = NULL;
152 struct list_head *e;
153
154 if (id) {
155 list_for_each(e, &buf->stream_list) {
156 st = list_entry(e, struct oz_elt_stream, link);
157 if (st->id == id)
158 break;
159 }
160 if (e == &buf->stream_list) {
161 /* Stream specified but stream not known so fail.
162 * Caller deallocates element info. */
163 return -1;
164 }
165 }
166 if (st) {
167 /* If this is an ISOC fixed element that needs a frame number
168 * then insert that now. Earlier we stored the unit count in
169 * this field.
170 */
171 struct oz_isoc_fixed *body = (struct oz_isoc_fixed *)
172 &ei->data[sizeof(struct oz_elt)];
173 if ((body->app_id == OZ_APPID_USB) && (body->type
174 == OZ_USB_ENDPOINT_DATA) &&
175 (body->format == OZ_DATA_F_ISOC_FIXED)) {
176 u8 unit_count = body->frame_number;
177
178 body->frame_number = st->frame_number;
179 st->frame_number += unit_count;
180 }
181 /* Claim stream and update accounts */
182 oz_elt_stream_get(st);
183 ei->stream = st;
184 st->buf_count += ei->length;
185 /* Add to list in stream. */
186 list_add_tail(&ei->link, &st->elt_list);
187 oz_dbg(STREAM, "Stream up: %d %d\n", st->buf_count, ei->length);
188 /* Check if we have too much buffered for this stream. If so
189 * start dropping elements until we are back in bounds.
190 */
191 while ((st->buf_count > st->max_buf_count) &&
192 !list_empty(&st->elt_list)) {
193 struct oz_elt_info *ei2 =
194 list_first_entry(&st->elt_list,
195 struct oz_elt_info, link);
196 list_del_init(&ei2->link);
197 list_del_init(&ei2->link_order);
198 st->buf_count -= ei2->length;
199 oz_elt_info_free(buf, ei2);
200 oz_elt_stream_put(st);
201 }
202 }
203 list_add_tail(&ei->link_order, isoc ?
204 &buf->isoc_list : &buf->order_list);
205 return 0;
206}
207
208int oz_select_elts_for_tx(struct oz_elt_buf *buf, u8 isoc, unsigned *len,
209 unsigned max_len, struct list_head *list)
210{
211 int count = 0;
212 struct list_head *el;
213 struct oz_elt_info *ei, *n;
214
215 spin_lock_bh(&buf->lock);
216 if (isoc)
217 el = &buf->isoc_list;
218 else
219 el = &buf->order_list;
220
221 list_for_each_entry_safe(ei, n, el, link_order) {
222 if ((*len + ei->length) <= max_len) {
223 struct oz_app_hdr *app_hdr = (struct oz_app_hdr *)
224 &ei->data[sizeof(struct oz_elt)];
225 app_hdr->elt_seq_num = buf->tx_seq_num[ei->app_id]++;
226 if (buf->tx_seq_num[ei->app_id] == 0)
227 buf->tx_seq_num[ei->app_id] = 1;
228 *len += ei->length;
229 list_del(&ei->link);
230 list_del(&ei->link_order);
231 if (ei->stream) {
232 ei->stream->buf_count -= ei->length;
233 oz_dbg(STREAM, "Stream down: %d %d\n",
234 ei->stream->buf_count, ei->length);
235 oz_elt_stream_put(ei->stream);
236 ei->stream = NULL;
237 }
238 INIT_LIST_HEAD(&ei->link_order);
239 list_add_tail(&ei->link, list);
240 count++;
241 } else {
242 break;
243 }
244 }
245 spin_unlock_bh(&buf->lock);
246 return count;
247}
248
249int oz_are_elts_available(struct oz_elt_buf *buf)
250{
251 return !list_empty(&buf->order_list);
252}
diff --git a/drivers/staging/ozwpan/ozeltbuf.h b/drivers/staging/ozwpan/ozeltbuf.h
deleted file mode 100644
index f09f5fe3ffbe..000000000000
--- a/drivers/staging/ozwpan/ozeltbuf.h
+++ /dev/null
@@ -1,65 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
5 */
6#ifndef _OZELTBUF_H
7#define _OZELTBUF_H
8
9#include "ozprotocol.h"
10
11/*-----------------------------------------------------------------------------
12 */
13struct oz_pd;
14typedef void (*oz_elt_callback_t)(struct oz_pd *pd, long context);
15
16struct oz_elt_stream {
17 struct list_head link;
18 struct list_head elt_list;
19 atomic_t ref_count;
20 unsigned buf_count;
21 unsigned max_buf_count;
22 u8 frame_number;
23 u8 id;
24};
25
26#define OZ_MAX_ELT_PAYLOAD 255
27struct oz_elt_info {
28 struct list_head link;
29 struct list_head link_order;
30 u8 flags;
31 u8 app_id;
32 oz_elt_callback_t callback;
33 long context;
34 struct oz_elt_stream *stream;
35 u8 data[sizeof(struct oz_elt) + OZ_MAX_ELT_PAYLOAD];
36 int length;
37};
38/* Flags values */
39#define OZ_EI_F_MARKED 0x1
40
41struct oz_elt_buf {
42 spinlock_t lock;
43 struct list_head stream_list;
44 struct list_head order_list;
45 struct list_head isoc_list;
46 u8 tx_seq_num[OZ_NB_APPS];
47};
48
49void oz_elt_buf_init(struct oz_elt_buf *buf);
50void oz_elt_buf_term(struct oz_elt_buf *buf);
51struct oz_elt_info *oz_elt_info_alloc(struct oz_elt_buf *buf);
52void oz_elt_info_free(struct oz_elt_buf *buf, struct oz_elt_info *ei);
53void oz_elt_info_free_chain(struct oz_elt_buf *buf, struct list_head *list);
54int oz_elt_stream_create(struct oz_elt_buf *buf, u8 id, int max_buf_count);
55int oz_elt_stream_delete(struct oz_elt_buf *buf, u8 id);
56void oz_elt_stream_get(struct oz_elt_stream *st);
57void oz_elt_stream_put(struct oz_elt_stream *st);
58int oz_queue_elt_info(struct oz_elt_buf *buf, u8 isoc, u8 id,
59 struct oz_elt_info *ei);
60int oz_select_elts_for_tx(struct oz_elt_buf *buf, u8 isoc, unsigned *len,
61 unsigned max_len, struct list_head *list);
62int oz_are_elts_available(struct oz_elt_buf *buf);
63
64#endif /* _OZELTBUF_H */
65
diff --git a/drivers/staging/ozwpan/ozhcd.c b/drivers/staging/ozwpan/ozhcd.c
deleted file mode 100644
index 784b5ecfa849..000000000000
--- a/drivers/staging/ozwpan/ozhcd.c
+++ /dev/null
@@ -1,2301 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 *
5 * This file provides the implementation of a USB host controller device that
6 * does not have any associated hardware. Instead the virtual device is
7 * connected to the WiFi network and emulates the operation of a USB hcd by
8 * receiving and sending network frames.
9 * Note:
10 * We take great pains to reduce the amount of code where interrupts need to be
11 * disabled and in this respect we are different from standard HCD's. In
12 * particular we don't want in_irq() code bleeding over to the protocol side of
13 * the driver.
14 * The troublesome functions are the urb enqueue and dequeue functions both of
15 * which can be called in_irq(). So for these functions we put the urbs into a
16 * queue and request a tasklet to process them. This means that a spinlock with
17 * interrupts disabled must be held for insertion and removal but most code is
18 * is in tasklet or soft irq context. The lock that protects this list is called
19 * the tasklet lock and serves the purpose of the 'HCD lock' which must be held
20 * when calling the following functions.
21 * usb_hcd_link_urb_to_ep()
22 * usb_hcd_unlink_urb_from_ep()
23 * usb_hcd_flush_endpoint()
24 * usb_hcd_check_unlink_urb()
25 * -----------------------------------------------------------------------------
26 */
27#include <linux/platform_device.h>
28#include <linux/usb.h>
29#include <linux/slab.h>
30#include <linux/export.h>
31#include "linux/usb/hcd.h"
32#include <asm/unaligned.h>
33#include "ozdbg.h"
34#include "ozusbif.h"
35#include "ozurbparanoia.h"
36#include "ozhcd.h"
37
38/*
39 * Number of units of buffering to capture for an isochronous IN endpoint before
40 * allowing data to be indicated up.
41 */
42#define OZ_IN_BUFFERING_UNITS 100
43
44/* Name of our platform device.
45 */
46#define OZ_PLAT_DEV_NAME "ozwpan"
47
48/*EP0 timeout before ep0 request is again added to TX queue. (13*8 = 98mSec)
49 */
50#define EP0_TIMEOUT_COUNTER 13
51
52/* Debounce time HCD driver should wait before unregistering.
53 */
54#define OZ_HUB_DEBOUNCE_TIMEOUT 1500
55
56/*
57 * Used to link urbs together and also store some status information for each
58 * urb.
59 * A cache of these are kept in a pool to reduce number of calls to kmalloc.
60 */
61struct oz_urb_link {
62 struct list_head link;
63 struct urb *urb;
64 struct oz_port *port;
65 u8 req_id;
66 u8 ep_num;
67 unsigned submit_counter;
68};
69
70static struct kmem_cache *oz_urb_link_cache;
71
72/* Holds state information about a USB endpoint.
73 */
74#define OZ_EP_BUFFER_SIZE_ISOC (1024 * 24)
75#define OZ_EP_BUFFER_SIZE_INT 512
76struct oz_endpoint {
77 struct list_head urb_list; /* List of oz_urb_link items. */
78 struct list_head link; /* For isoc ep, links in to isoc
79 lists of oz_port. */
80 struct timespec timestamp;
81 int credit;
82 int credit_ceiling;
83 u8 ep_num;
84 u8 attrib;
85 u8 *buffer;
86 int buffer_size;
87 int in_ix;
88 int out_ix;
89 int buffered_units;
90 unsigned flags;
91 int start_frame;
92};
93
94/* Bits in the flags field. */
95#define OZ_F_EP_BUFFERING 0x1
96#define OZ_F_EP_HAVE_STREAM 0x2
97
98/* Holds state information about a USB interface.
99 */
100struct oz_interface {
101 unsigned ep_mask;
102 u8 alt;
103};
104
105/* Holds state information about an hcd port.
106 */
107#define OZ_NB_ENDPOINTS 16
108struct oz_port {
109 unsigned flags;
110 unsigned status;
111 void *hpd;
112 struct oz_hcd *ozhcd;
113 spinlock_t port_lock;
114 u8 bus_addr;
115 u8 next_req_id;
116 u8 config_num;
117 int num_iface;
118 struct oz_interface *iface;
119 struct oz_endpoint *out_ep[OZ_NB_ENDPOINTS];
120 struct oz_endpoint *in_ep[OZ_NB_ENDPOINTS];
121 struct list_head isoc_out_ep;
122 struct list_head isoc_in_ep;
123};
124
125#define OZ_PORT_F_PRESENT 0x1
126#define OZ_PORT_F_CHANGED 0x2
127#define OZ_PORT_F_DYING 0x4
128
129/* Data structure in the private context area of struct usb_hcd.
130 */
131#define OZ_NB_PORTS 8
132struct oz_hcd {
133 spinlock_t hcd_lock;
134 struct list_head urb_pending_list;
135 struct list_head urb_cancel_list;
136 struct list_head orphanage;
137 int conn_port; /* Port that is currently connecting, -1 if none.*/
138 struct oz_port ports[OZ_NB_PORTS];
139 uint flags;
140 struct usb_hcd *hcd;
141};
142
143/* Bits in flags field.
144 */
145#define OZ_HDC_F_SUSPENDED 0x1
146
147/*
148 * Static function prototypes.
149 */
150static int oz_hcd_start(struct usb_hcd *hcd);
151static void oz_hcd_stop(struct usb_hcd *hcd);
152static void oz_hcd_shutdown(struct usb_hcd *hcd);
153static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
154 gfp_t mem_flags);
155static int oz_hcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
156static void oz_hcd_endpoint_disable(struct usb_hcd *hcd,
157 struct usb_host_endpoint *ep);
158static void oz_hcd_endpoint_reset(struct usb_hcd *hcd,
159 struct usb_host_endpoint *ep);
160static int oz_hcd_get_frame_number(struct usb_hcd *hcd);
161static int oz_hcd_hub_status_data(struct usb_hcd *hcd, char *buf);
162static int oz_hcd_hub_control(struct usb_hcd *hcd, u16 req_type, u16 wvalue,
163 u16 windex, char *buf, u16 wlength);
164static int oz_hcd_bus_suspend(struct usb_hcd *hcd);
165static int oz_hcd_bus_resume(struct usb_hcd *hcd);
166static int oz_plat_probe(struct platform_device *dev);
167static int oz_plat_remove(struct platform_device *dev);
168static void oz_plat_shutdown(struct platform_device *dev);
169static int oz_plat_suspend(struct platform_device *dev, pm_message_t msg);
170static int oz_plat_resume(struct platform_device *dev);
171static void oz_urb_process_tasklet(unsigned long unused);
172static int oz_build_endpoints_for_config(struct usb_hcd *hcd,
173 struct oz_port *port, struct usb_host_config *config,
174 gfp_t mem_flags);
175static void oz_clean_endpoints_for_config(struct usb_hcd *hcd,
176 struct oz_port *port);
177static int oz_build_endpoints_for_interface(struct usb_hcd *hcd,
178 struct oz_port *port,
179 struct usb_host_interface *intf, gfp_t mem_flags);
180static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd,
181 struct oz_port *port, int if_ix);
182static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb,
183 gfp_t mem_flags);
184static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep,
185 struct urb *urb);
186static void oz_hcd_clear_orphanage(struct oz_hcd *ozhcd, int status);
187
188/*
189 * Static external variables.
190 */
191static struct platform_device *g_plat_dev;
192static struct oz_hcd *g_ozhcd;
193static DEFINE_SPINLOCK(g_hcdlock); /* Guards g_ozhcd. */
194static const char g_hcd_name[] = "Ozmo WPAN";
195static DEFINE_SPINLOCK(g_tasklet_lock);
196static struct tasklet_struct g_urb_process_tasklet;
197static struct tasklet_struct g_urb_cancel_tasklet;
198static atomic_t g_pending_urbs = ATOMIC_INIT(0);
199static atomic_t g_usb_frame_number = ATOMIC_INIT(0);
200static const struct hc_driver g_oz_hc_drv = {
201 .description = g_hcd_name,
202 .product_desc = "Ozmo Devices WPAN",
203 .hcd_priv_size = sizeof(struct oz_hcd),
204 .flags = HCD_USB11,
205 .start = oz_hcd_start,
206 .stop = oz_hcd_stop,
207 .shutdown = oz_hcd_shutdown,
208 .urb_enqueue = oz_hcd_urb_enqueue,
209 .urb_dequeue = oz_hcd_urb_dequeue,
210 .endpoint_disable = oz_hcd_endpoint_disable,
211 .endpoint_reset = oz_hcd_endpoint_reset,
212 .get_frame_number = oz_hcd_get_frame_number,
213 .hub_status_data = oz_hcd_hub_status_data,
214 .hub_control = oz_hcd_hub_control,
215 .bus_suspend = oz_hcd_bus_suspend,
216 .bus_resume = oz_hcd_bus_resume,
217};
218
219static struct platform_driver g_oz_plat_drv = {
220 .probe = oz_plat_probe,
221 .remove = oz_plat_remove,
222 .shutdown = oz_plat_shutdown,
223 .suspend = oz_plat_suspend,
224 .resume = oz_plat_resume,
225 .driver = {
226 .name = OZ_PLAT_DEV_NAME,
227 },
228};
229
230/*
231 * Gets our private context area (which is of type struct oz_hcd) from the
232 * usb_hcd structure.
233 * Context: any
234 */
235static inline struct oz_hcd *oz_hcd_private(struct usb_hcd *hcd)
236{
237 return (struct oz_hcd *)hcd->hcd_priv;
238}
239
240/*
241 * Searches list of ports to find the index of the one with a specified USB
242 * bus address. If none of the ports has the bus address then the connection
243 * port is returned, if there is one or -1 otherwise.
244 * Context: any
245 */
246static int oz_get_port_from_addr(struct oz_hcd *ozhcd, u8 bus_addr)
247{
248 int i;
249
250 for (i = 0; i < OZ_NB_PORTS; i++) {
251 if (ozhcd->ports[i].bus_addr == bus_addr)
252 return i;
253 }
254 return ozhcd->conn_port;
255}
256
257/*
258 * Context: any
259 */
260static struct oz_urb_link *oz_alloc_urb_link(void)
261{
262 return kmem_cache_alloc(oz_urb_link_cache, GFP_ATOMIC);
263}
264
265/*
266 * Context: any
267 */
268static void oz_free_urb_link(struct oz_urb_link *urbl)
269{
270 if (!urbl)
271 return;
272
273 kmem_cache_free(oz_urb_link_cache, urbl);
274}
275
276/*
277 * Allocates endpoint structure and optionally a buffer. If a buffer is
278 * allocated it immediately follows the endpoint structure.
279 * Context: softirq
280 */
281static struct oz_endpoint *oz_ep_alloc(int buffer_size, gfp_t mem_flags)
282{
283 struct oz_endpoint *ep;
284
285 ep = kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
286 if (!ep)
287 return NULL;
288
289 INIT_LIST_HEAD(&ep->urb_list);
290 INIT_LIST_HEAD(&ep->link);
291 ep->credit = -1;
292 if (buffer_size) {
293 ep->buffer_size = buffer_size;
294 ep->buffer = (u8 *)(ep+1);
295 }
296
297 return ep;
298}
299
300/*
301 * Pre-condition: Must be called with g_tasklet_lock held and interrupts
302 * disabled.
303 * Context: softirq or process
304 */
305static struct oz_urb_link *oz_uncancel_urb(struct oz_hcd *ozhcd,
306 struct urb *urb)
307{
308 struct oz_urb_link *urbl;
309
310 list_for_each_entry(urbl, &ozhcd->urb_cancel_list, link) {
311 if (urb == urbl->urb) {
312 list_del_init(&urbl->link);
313 return urbl;
314 }
315 }
316 return NULL;
317}
318
319/*
320 * This is called when we have finished processing an urb. It unlinks it from
321 * the ep and returns it to the core.
322 * Context: softirq or process
323 */
324static void oz_complete_urb(struct usb_hcd *hcd, struct urb *urb,
325 int status)
326{
327 struct oz_hcd *ozhcd = oz_hcd_private(hcd);
328 unsigned long irq_state;
329 struct oz_urb_link *cancel_urbl;
330
331 spin_lock_irqsave(&g_tasklet_lock, irq_state);
332 usb_hcd_unlink_urb_from_ep(hcd, urb);
333 /* Clear hcpriv which will prevent it being put in the cancel list
334 * in the event that an attempt is made to cancel it.
335 */
336 urb->hcpriv = NULL;
337 /* Walk the cancel list in case the urb is already sitting there.
338 * Since we process the cancel list in a tasklet rather than in
339 * the dequeue function this could happen.
340 */
341 cancel_urbl = oz_uncancel_urb(ozhcd, urb);
342 /* Note: we release lock but do not enable local irqs.
343 * It appears that usb_hcd_giveback_urb() expects irqs to be disabled,
344 * or at least other host controllers disable interrupts at this point
345 * so we do the same. We must, however, release the lock otherwise a
346 * deadlock will occur if an urb is submitted to our driver in the urb
347 * completion function. Because we disable interrupts it is possible
348 * that the urb_enqueue function can be called with them disabled.
349 */
350 spin_unlock(&g_tasklet_lock);
351 if (oz_forget_urb(urb)) {
352 oz_dbg(ON, "ERROR Unknown URB %p\n", urb);
353 } else {
354 atomic_dec(&g_pending_urbs);
355 usb_hcd_giveback_urb(hcd, urb, status);
356 }
357 spin_lock(&g_tasklet_lock);
358 spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
359 oz_free_urb_link(cancel_urbl);
360}
361
362/*
363 * Deallocates an endpoint including deallocating any associated stream and
364 * returning any queued urbs to the core.
365 * Context: softirq
366 */
367static void oz_ep_free(struct oz_port *port, struct oz_endpoint *ep)
368{
369 if (port) {
370 LIST_HEAD(list);
371 struct oz_hcd *ozhcd = port->ozhcd;
372
373 if (ep->flags & OZ_F_EP_HAVE_STREAM)
374 oz_usb_stream_delete(port->hpd, ep->ep_num);
375 /* Transfer URBs to the orphanage while we hold the lock. */
376 spin_lock_bh(&ozhcd->hcd_lock);
377 /* Note: this works even if ep->urb_list is empty.*/
378 list_replace_init(&ep->urb_list, &list);
379 /* Put the URBs in the orphanage. */
380 list_splice_tail(&list, &ozhcd->orphanage);
381 spin_unlock_bh(&ozhcd->hcd_lock);
382 }
383 oz_dbg(ON, "Freeing endpoint memory\n");
384 kfree(ep);
385}
386
387/*
388 * Context: softirq
389 */
390static void oz_complete_buffered_urb(struct oz_port *port,
391 struct oz_endpoint *ep,
392 struct urb *urb)
393{
394 int data_len, available_space, copy_len;
395
396 data_len = ep->buffer[ep->out_ix];
397 if (data_len <= urb->transfer_buffer_length)
398 available_space = data_len;
399 else
400 available_space = urb->transfer_buffer_length;
401
402 if (++ep->out_ix == ep->buffer_size)
403 ep->out_ix = 0;
404 copy_len = ep->buffer_size - ep->out_ix;
405 if (copy_len >= available_space)
406 copy_len = available_space;
407 memcpy(urb->transfer_buffer, &ep->buffer[ep->out_ix], copy_len);
408
409 if (copy_len < available_space) {
410 memcpy((urb->transfer_buffer + copy_len), ep->buffer,
411 (available_space - copy_len));
412 ep->out_ix = available_space - copy_len;
413 } else {
414 ep->out_ix += copy_len;
415 }
416 urb->actual_length = available_space;
417 if (ep->out_ix == ep->buffer_size)
418 ep->out_ix = 0;
419
420 ep->buffered_units--;
421 oz_dbg(ON, "Trying to give back buffered frame of size=%d\n",
422 available_space);
423 oz_complete_urb(port->ozhcd->hcd, urb, 0);
424}
425
426/*
427 * Context: softirq
428 */
429static int oz_enqueue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir,
430 struct urb *urb, u8 req_id)
431{
432 struct oz_urb_link *urbl;
433 struct oz_endpoint *ep = NULL;
434 int err = 0;
435
436 if (ep_addr >= OZ_NB_ENDPOINTS) {
437 oz_dbg(ON, "%s: Invalid endpoint number\n", __func__);
438 return -EINVAL;
439 }
440 urbl = oz_alloc_urb_link();
441 if (!urbl)
442 return -ENOMEM;
443 urbl->submit_counter = 0;
444 urbl->urb = urb;
445 urbl->req_id = req_id;
446 urbl->ep_num = ep_addr;
447 /* Hold lock while we insert the URB into the list within the
448 * endpoint structure.
449 */
450 spin_lock_bh(&port->ozhcd->hcd_lock);
451 /* If the urb has been unlinked while out of any list then
452 * complete it now.
453 */
454 if (urb->unlinked) {
455 spin_unlock_bh(&port->ozhcd->hcd_lock);
456 oz_dbg(ON, "urb %p unlinked so complete immediately\n", urb);
457 oz_complete_urb(port->ozhcd->hcd, urb, 0);
458 oz_free_urb_link(urbl);
459 return 0;
460 }
461
462 if (in_dir)
463 ep = port->in_ep[ep_addr];
464 else
465 ep = port->out_ep[ep_addr];
466 if (!ep) {
467 err = -ENOMEM;
468 goto out;
469 }
470
471 /*For interrupt endpoint check for buffered data
472 * & complete urb
473 */
474 if (((ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)
475 && ep->buffered_units > 0) {
476 oz_free_urb_link(urbl);
477 spin_unlock_bh(&port->ozhcd->hcd_lock);
478 oz_complete_buffered_urb(port, ep, urb);
479 return 0;
480 }
481
482 if (port->hpd) {
483 list_add_tail(&urbl->link, &ep->urb_list);
484 if (!in_dir && ep_addr && (ep->credit < 0)) {
485 getrawmonotonic(&ep->timestamp);
486 ep->credit = 0;
487 }
488 } else {
489 err = -EPIPE;
490 }
491out:
492 spin_unlock_bh(&port->ozhcd->hcd_lock);
493 if (err)
494 oz_free_urb_link(urbl);
495 return err;
496}
497
498/*
499 * Removes an urb from the queue in the endpoint.
500 * Returns 0 if it is found and -EIDRM otherwise.
501 * Context: softirq
502 */
503static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir,
504 struct urb *urb)
505{
506 struct oz_urb_link *urbl = NULL;
507 struct oz_endpoint *ep;
508
509 spin_lock_bh(&port->ozhcd->hcd_lock);
510 if (in_dir)
511 ep = port->in_ep[ep_addr];
512 else
513 ep = port->out_ep[ep_addr];
514 if (ep) {
515 struct list_head *e;
516
517 list_for_each(e, &ep->urb_list) {
518 urbl = list_entry(e, struct oz_urb_link, link);
519 if (urbl->urb == urb) {
520 list_del_init(e);
521 break;
522 }
523 urbl = NULL;
524 }
525 }
526 spin_unlock_bh(&port->ozhcd->hcd_lock);
527 oz_free_urb_link(urbl);
528 return urbl ? 0 : -EIDRM;
529}
530
531/*
532 * Finds an urb given its request id.
533 * Context: softirq
534 */
535static struct urb *oz_find_urb_by_id(struct oz_port *port, int ep_ix,
536 u8 req_id)
537{
538 struct oz_hcd *ozhcd = port->ozhcd;
539 struct urb *urb = NULL;
540 struct oz_urb_link *urbl;
541 struct oz_endpoint *ep;
542
543 spin_lock_bh(&ozhcd->hcd_lock);
544 ep = port->out_ep[ep_ix];
545 if (ep) {
546 struct list_head *e;
547
548 list_for_each(e, &ep->urb_list) {
549 urbl = list_entry(e, struct oz_urb_link, link);
550 if (urbl->req_id == req_id) {
551 urb = urbl->urb;
552 list_del_init(e);
553 break;
554 }
555 }
556 }
557 spin_unlock_bh(&ozhcd->hcd_lock);
558 /* If urb is non-zero then we we must have an urb link to delete.
559 */
560 if (urb)
561 oz_free_urb_link(urbl);
562 return urb;
563}
564
565/*
566 * Pre-condition: Port lock must be held.
567 * Context: softirq
568 */
569static void oz_acquire_port(struct oz_port *port, void *hpd)
570{
571 INIT_LIST_HEAD(&port->isoc_out_ep);
572 INIT_LIST_HEAD(&port->isoc_in_ep);
573 port->flags |= OZ_PORT_F_PRESENT | OZ_PORT_F_CHANGED;
574 port->status |= USB_PORT_STAT_CONNECTION |
575 (USB_PORT_STAT_C_CONNECTION << 16);
576 oz_usb_get(hpd);
577 port->hpd = hpd;
578}
579
580/*
581 * Context: softirq
582 */
583static struct oz_hcd *oz_hcd_claim(void)
584{
585 struct oz_hcd *ozhcd;
586
587 spin_lock_bh(&g_hcdlock);
588 ozhcd = g_ozhcd;
589 if (ozhcd)
590 usb_get_hcd(ozhcd->hcd);
591 spin_unlock_bh(&g_hcdlock);
592 return ozhcd;
593}
594
595/*
596 * Context: softirq
597 */
598static inline void oz_hcd_put(struct oz_hcd *ozhcd)
599{
600 if (ozhcd)
601 usb_put_hcd(ozhcd->hcd);
602}
603
604/*
605 * This is called by the protocol handler to notify that a PD has arrived.
606 * We allocate a port to associate with the PD and create a structure for
607 * endpoint 0. This port is made the connection port.
608 * In the event that one of the other port is already a connection port then
609 * we fail.
610 * TODO We should be able to do better than fail and should be able remember
611 * that this port needs configuring and make it the connection port once the
612 * current connection port has been assigned an address. Collisions here are
613 * probably very rare indeed.
614 * Context: softirq
615 */
616struct oz_port *oz_hcd_pd_arrived(void *hpd)
617{
618 int i;
619 struct oz_port *hport;
620 struct oz_hcd *ozhcd;
621 struct oz_endpoint *ep;
622
623 ozhcd = oz_hcd_claim();
624 if (!ozhcd)
625 return NULL;
626 /* Allocate an endpoint object in advance (before holding hcd lock) to
627 * use for out endpoint 0.
628 */
629 ep = oz_ep_alloc(0, GFP_ATOMIC);
630 if (!ep)
631 goto err_put;
632
633 spin_lock_bh(&ozhcd->hcd_lock);
634 if (ozhcd->conn_port >= 0)
635 goto err_unlock;
636
637 for (i = 0; i < OZ_NB_PORTS; i++) {
638 struct oz_port *port = &ozhcd->ports[i];
639
640 spin_lock(&port->port_lock);
641 if (!(port->flags & (OZ_PORT_F_PRESENT | OZ_PORT_F_CHANGED))) {
642 oz_acquire_port(port, hpd);
643 spin_unlock(&port->port_lock);
644 break;
645 }
646 spin_unlock(&port->port_lock);
647 }
648 if (i == OZ_NB_PORTS)
649 goto err_unlock;
650
651 ozhcd->conn_port = i;
652 hport = &ozhcd->ports[i];
653 hport->out_ep[0] = ep;
654 spin_unlock_bh(&ozhcd->hcd_lock);
655 if (ozhcd->flags & OZ_HDC_F_SUSPENDED)
656 usb_hcd_resume_root_hub(ozhcd->hcd);
657 usb_hcd_poll_rh_status(ozhcd->hcd);
658 oz_hcd_put(ozhcd);
659
660 return hport;
661
662err_unlock:
663 spin_unlock_bh(&ozhcd->hcd_lock);
664 oz_ep_free(NULL, ep);
665err_put:
666 oz_hcd_put(ozhcd);
667 return NULL;
668}
669
670/*
671 * This is called by the protocol handler to notify that the PD has gone away.
672 * We need to deallocate all resources and then request that the root hub is
673 * polled. We release the reference we hold on the PD.
674 * Context: softirq
675 */
676void oz_hcd_pd_departed(struct oz_port *port)
677{
678 struct oz_hcd *ozhcd;
679 void *hpd;
680 struct oz_endpoint *ep = NULL;
681
682 if (port == NULL) {
683 oz_dbg(ON, "%s: port = 0\n", __func__);
684 return;
685 }
686 ozhcd = port->ozhcd;
687 if (ozhcd == NULL)
688 return;
689 /* Check if this is the connection port - if so clear it.
690 */
691 spin_lock_bh(&ozhcd->hcd_lock);
692 if ((ozhcd->conn_port >= 0) &&
693 (port == &ozhcd->ports[ozhcd->conn_port])) {
694 oz_dbg(ON, "Clearing conn_port\n");
695 ozhcd->conn_port = -1;
696 }
697 spin_lock(&port->port_lock);
698 port->flags |= OZ_PORT_F_DYING;
699 spin_unlock(&port->port_lock);
700 spin_unlock_bh(&ozhcd->hcd_lock);
701
702 oz_clean_endpoints_for_config(ozhcd->hcd, port);
703 spin_lock_bh(&port->port_lock);
704 hpd = port->hpd;
705 port->hpd = NULL;
706 port->bus_addr = 0xff;
707 port->config_num = 0;
708 port->flags &= ~(OZ_PORT_F_PRESENT | OZ_PORT_F_DYING);
709 port->flags |= OZ_PORT_F_CHANGED;
710 port->status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE);
711 port->status |= (USB_PORT_STAT_C_CONNECTION << 16);
712 /* If there is an endpont 0 then clear the pointer while we hold
713 * the spinlock be we deallocate it after releasing the lock.
714 */
715 if (port->out_ep[0]) {
716 ep = port->out_ep[0];
717 port->out_ep[0] = NULL;
718 }
719 spin_unlock_bh(&port->port_lock);
720 if (ep)
721 oz_ep_free(port, ep);
722 usb_hcd_poll_rh_status(ozhcd->hcd);
723 oz_usb_put(hpd);
724}
725
726/*
727 * Context: softirq
728 */
729void oz_hcd_pd_reset(void *hpd, void *hport)
730{
731 /* Cleanup the current configuration and report reset to the core.
732 */
733 struct oz_port *port = hport;
734 struct oz_hcd *ozhcd = port->ozhcd;
735
736 oz_dbg(ON, "PD Reset\n");
737 spin_lock_bh(&port->port_lock);
738 port->flags |= OZ_PORT_F_CHANGED;
739 port->status |= USB_PORT_STAT_RESET;
740 port->status |= (USB_PORT_STAT_C_RESET << 16);
741 spin_unlock_bh(&port->port_lock);
742 oz_clean_endpoints_for_config(ozhcd->hcd, port);
743 usb_hcd_poll_rh_status(ozhcd->hcd);
744}
745
746/*
747 * Context: softirq
748 */
749void oz_hcd_get_desc_cnf(void *hport, u8 req_id, u8 status, const u8 *desc,
750 u8 length, u16 offset, u16 total_size)
751{
752 struct oz_port *port = hport;
753 struct urb *urb;
754 int err = 0;
755
756 oz_dbg(ON, "oz_hcd_get_desc_cnf length = %d offs = %d tot_size = %d\n",
757 length, offset, total_size);
758 urb = oz_find_urb_by_id(port, 0, req_id);
759 if (!urb)
760 return;
761 if (status == 0) {
762 unsigned int copy_len;
763 unsigned int required_size = urb->transfer_buffer_length;
764
765 if (required_size > total_size)
766 required_size = total_size;
767 copy_len = required_size-offset;
768 if (length <= copy_len)
769 copy_len = length;
770 memcpy(urb->transfer_buffer+offset, desc, copy_len);
771 offset += copy_len;
772 if (offset < required_size) {
773 struct usb_ctrlrequest *setup =
774 (struct usb_ctrlrequest *)urb->setup_packet;
775 unsigned wvalue = le16_to_cpu(setup->wValue);
776
777 if (oz_enqueue_ep_urb(port, 0, 0, urb, req_id))
778 err = -ENOMEM;
779 else if (oz_usb_get_desc_req(port->hpd, req_id,
780 setup->bRequestType, (u8)(wvalue>>8),
781 (u8)wvalue, setup->wIndex, offset,
782 required_size-offset)) {
783 oz_dequeue_ep_urb(port, 0, 0, urb);
784 err = -ENOMEM;
785 }
786 if (err == 0)
787 return;
788 }
789 }
790 urb->actual_length = total_size;
791 oz_complete_urb(port->ozhcd->hcd, urb, 0);
792}
793
794/*
795 * Context: softirq
796 */
797static void oz_display_conf_type(u8 t)
798{
799 switch (t) {
800 case USB_REQ_GET_STATUS:
801 oz_dbg(ON, "USB_REQ_GET_STATUS - cnf\n");
802 break;
803 case USB_REQ_CLEAR_FEATURE:
804 oz_dbg(ON, "USB_REQ_CLEAR_FEATURE - cnf\n");
805 break;
806 case USB_REQ_SET_FEATURE:
807 oz_dbg(ON, "USB_REQ_SET_FEATURE - cnf\n");
808 break;
809 case USB_REQ_SET_ADDRESS:
810 oz_dbg(ON, "USB_REQ_SET_ADDRESS - cnf\n");
811 break;
812 case USB_REQ_GET_DESCRIPTOR:
813 oz_dbg(ON, "USB_REQ_GET_DESCRIPTOR - cnf\n");
814 break;
815 case USB_REQ_SET_DESCRIPTOR:
816 oz_dbg(ON, "USB_REQ_SET_DESCRIPTOR - cnf\n");
817 break;
818 case USB_REQ_GET_CONFIGURATION:
819 oz_dbg(ON, "USB_REQ_GET_CONFIGURATION - cnf\n");
820 break;
821 case USB_REQ_SET_CONFIGURATION:
822 oz_dbg(ON, "USB_REQ_SET_CONFIGURATION - cnf\n");
823 break;
824 case USB_REQ_GET_INTERFACE:
825 oz_dbg(ON, "USB_REQ_GET_INTERFACE - cnf\n");
826 break;
827 case USB_REQ_SET_INTERFACE:
828 oz_dbg(ON, "USB_REQ_SET_INTERFACE - cnf\n");
829 break;
830 case USB_REQ_SYNCH_FRAME:
831 oz_dbg(ON, "USB_REQ_SYNCH_FRAME - cnf\n");
832 break;
833 }
834}
835
836/*
837 * Context: softirq
838 */
839static void oz_hcd_complete_set_config(struct oz_port *port, struct urb *urb,
840 u8 rcode, u8 config_num)
841{
842 int rc = 0;
843 struct usb_hcd *hcd = port->ozhcd->hcd;
844
845 if (rcode == 0) {
846 port->config_num = config_num;
847 oz_clean_endpoints_for_config(hcd, port);
848 if (oz_build_endpoints_for_config(hcd, port,
849 &urb->dev->config[port->config_num-1], GFP_ATOMIC)) {
850 rc = -ENOMEM;
851 }
852 } else {
853 rc = -ENOMEM;
854 }
855 oz_complete_urb(hcd, urb, rc);
856}
857
858/*
859 * Context: softirq
860 */
861static void oz_hcd_complete_set_interface(struct oz_port *port, struct urb *urb,
862 u8 rcode, u8 if_num, u8 alt)
863{
864 struct usb_hcd *hcd = port->ozhcd->hcd;
865 int rc = 0;
866
867 if ((rcode == 0) && (port->config_num > 0)) {
868 struct usb_host_config *config;
869 struct usb_host_interface *intf;
870
871 oz_dbg(ON, "Set interface %d alt %d\n", if_num, alt);
872 oz_clean_endpoints_for_interface(hcd, port, if_num);
873 config = &urb->dev->config[port->config_num-1];
874 intf = &config->intf_cache[if_num]->altsetting[alt];
875 if (oz_build_endpoints_for_interface(hcd, port, intf,
876 GFP_ATOMIC))
877 rc = -ENOMEM;
878 else
879 port->iface[if_num].alt = alt;
880 } else {
881 rc = -ENOMEM;
882 }
883 oz_complete_urb(hcd, urb, rc);
884}
885
886/*
887 * Context: softirq
888 */
889void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, const u8 *data,
890 int data_len)
891{
892 struct oz_port *port = hport;
893 struct urb *urb;
894 struct usb_ctrlrequest *setup;
895 struct usb_hcd *hcd = port->ozhcd->hcd;
896 unsigned windex;
897 unsigned wvalue;
898
899 oz_dbg(ON, "oz_hcd_control_cnf rcode=%u len=%d\n", rcode, data_len);
900 urb = oz_find_urb_by_id(port, 0, req_id);
901 if (!urb) {
902 oz_dbg(ON, "URB not found\n");
903 return;
904 }
905 setup = (struct usb_ctrlrequest *)urb->setup_packet;
906 windex = le16_to_cpu(setup->wIndex);
907 wvalue = le16_to_cpu(setup->wValue);
908 if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
909 /* Standard requests */
910 oz_display_conf_type(setup->bRequest);
911 switch (setup->bRequest) {
912 case USB_REQ_SET_CONFIGURATION:
913 oz_hcd_complete_set_config(port, urb, rcode,
914 (u8)wvalue);
915 break;
916 case USB_REQ_SET_INTERFACE:
917 oz_hcd_complete_set_interface(port, urb, rcode,
918 (u8)windex, (u8)wvalue);
919 break;
920 default:
921 oz_complete_urb(hcd, urb, 0);
922 }
923
924 } else {
925 int copy_len;
926
927 oz_dbg(ON, "VENDOR-CLASS - cnf\n");
928 if (data_len) {
929 if (data_len <= urb->transfer_buffer_length)
930 copy_len = data_len;
931 else
932 copy_len = urb->transfer_buffer_length;
933 memcpy(urb->transfer_buffer, data, copy_len);
934 urb->actual_length = copy_len;
935 }
936 oz_complete_urb(hcd, urb, 0);
937 }
938}
939
940/*
941 * Context: softirq-serialized
942 */
943static int oz_hcd_buffer_data(struct oz_endpoint *ep, const u8 *data,
944 int data_len)
945{
946 int space;
947 int copy_len;
948
949 if (!ep->buffer)
950 return -1;
951 space = ep->out_ix-ep->in_ix-1;
952 if (space < 0)
953 space += ep->buffer_size;
954 if (space < (data_len+1)) {
955 oz_dbg(ON, "Buffer full\n");
956 return -1;
957 }
958 ep->buffer[ep->in_ix] = (u8)data_len;
959 if (++ep->in_ix == ep->buffer_size)
960 ep->in_ix = 0;
961 copy_len = ep->buffer_size - ep->in_ix;
962 if (copy_len > data_len)
963 copy_len = data_len;
964 memcpy(&ep->buffer[ep->in_ix], data, copy_len);
965
966 if (copy_len < data_len) {
967 memcpy(ep->buffer, data+copy_len, data_len-copy_len);
968 ep->in_ix = data_len-copy_len;
969 } else {
970 ep->in_ix += copy_len;
971 }
972 if (ep->in_ix == ep->buffer_size)
973 ep->in_ix = 0;
974 ep->buffered_units++;
975 return 0;
976}
977
978/*
979 * Context: softirq-serialized
980 */
981void oz_hcd_data_ind(void *hport, u8 endpoint, const u8 *data, int data_len)
982{
983 struct oz_port *port = (struct oz_port *)hport;
984 struct oz_endpoint *ep;
985 struct oz_hcd *ozhcd = port->ozhcd;
986
987 spin_lock_bh(&ozhcd->hcd_lock);
988 ep = port->in_ep[endpoint & USB_ENDPOINT_NUMBER_MASK];
989 if (ep == NULL)
990 goto done;
991 switch (ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) {
992 case USB_ENDPOINT_XFER_INT:
993 case USB_ENDPOINT_XFER_BULK:
994 if (!list_empty(&ep->urb_list)) {
995 struct oz_urb_link *urbl =
996 list_first_entry(&ep->urb_list,
997 struct oz_urb_link, link);
998 struct urb *urb;
999 int copy_len;
1000
1001 list_del_init(&urbl->link);
1002 spin_unlock_bh(&ozhcd->hcd_lock);
1003 urb = urbl->urb;
1004 oz_free_urb_link(urbl);
1005 if (data_len <= urb->transfer_buffer_length)
1006 copy_len = data_len;
1007 else
1008 copy_len = urb->transfer_buffer_length;
1009 memcpy(urb->transfer_buffer, data, copy_len);
1010 urb->actual_length = copy_len;
1011 oz_complete_urb(port->ozhcd->hcd, urb, 0);
1012 return;
1013 }
1014 oz_dbg(ON, "buffering frame as URB is not available\n");
1015 oz_hcd_buffer_data(ep, data, data_len);
1016 break;
1017 case USB_ENDPOINT_XFER_ISOC:
1018 oz_hcd_buffer_data(ep, data, data_len);
1019 break;
1020 }
1021done:
1022 spin_unlock_bh(&ozhcd->hcd_lock);
1023}
1024
1025/*
1026 * Context: unknown
1027 */
1028static inline int oz_usb_get_frame_number(void)
1029{
1030 return atomic_inc_return(&g_usb_frame_number);
1031}
1032
1033/*
1034 * Context: softirq
1035 */
1036int oz_hcd_heartbeat(void *hport)
1037{
1038 int rc = 0;
1039 struct oz_port *port = hport;
1040 struct oz_hcd *ozhcd = port->ozhcd;
1041 struct oz_urb_link *urbl, *n;
1042 LIST_HEAD(xfr_list);
1043 struct urb *urb;
1044 struct oz_endpoint *ep;
1045 struct timespec ts, delta;
1046
1047 getrawmonotonic(&ts);
1048 /* Check the OUT isoc endpoints to see if any URB data can be sent.
1049 */
1050 spin_lock_bh(&ozhcd->hcd_lock);
1051 list_for_each_entry(ep, &port->isoc_out_ep, link) {
1052 if (ep->credit < 0)
1053 continue;
1054 delta = timespec_sub(ts, ep->timestamp);
1055 ep->credit += div_u64(timespec_to_ns(&delta), NSEC_PER_MSEC);
1056 if (ep->credit > ep->credit_ceiling)
1057 ep->credit = ep->credit_ceiling;
1058 ep->timestamp = ts;
1059 while (ep->credit && !list_empty(&ep->urb_list)) {
1060 urbl = list_first_entry(&ep->urb_list,
1061 struct oz_urb_link, link);
1062 urb = urbl->urb;
1063 if ((ep->credit + 1) < urb->number_of_packets)
1064 break;
1065 ep->credit -= urb->number_of_packets;
1066 if (ep->credit < 0)
1067 ep->credit = 0;
1068 list_move_tail(&urbl->link, &xfr_list);
1069 }
1070 }
1071 spin_unlock_bh(&ozhcd->hcd_lock);
1072 /* Send to PD and complete URBs.
1073 */
1074 list_for_each_entry_safe(urbl, n, &xfr_list, link) {
1075 urb = urbl->urb;
1076 list_del_init(&urbl->link);
1077 urb->error_count = 0;
1078 urb->start_frame = oz_usb_get_frame_number();
1079 oz_usb_send_isoc(port->hpd, urbl->ep_num, urb);
1080 oz_free_urb_link(urbl);
1081 oz_complete_urb(port->ozhcd->hcd, urb, 0);
1082 }
1083 /* Check the IN isoc endpoints to see if any URBs can be completed.
1084 */
1085 spin_lock_bh(&ozhcd->hcd_lock);
1086 list_for_each_entry(ep, &port->isoc_in_ep, link) {
1087 if (ep->flags & OZ_F_EP_BUFFERING) {
1088 if (ep->buffered_units >= OZ_IN_BUFFERING_UNITS) {
1089 ep->flags &= ~OZ_F_EP_BUFFERING;
1090 ep->credit = 0;
1091 ep->timestamp = ts;
1092 ep->start_frame = 0;
1093 }
1094 continue;
1095 }
1096 delta = timespec_sub(ts, ep->timestamp);
1097 ep->credit += div_u64(timespec_to_ns(&delta), NSEC_PER_MSEC);
1098 ep->timestamp = ts;
1099 list_for_each_entry_safe(urbl, n, &ep->urb_list, link) {
1100 struct urb *urb = urbl->urb;
1101 int len = 0;
1102 int copy_len;
1103 int i;
1104
1105 if (ep->credit < urb->number_of_packets)
1106 break;
1107 if (ep->buffered_units < urb->number_of_packets)
1108 break;
1109 urb->actual_length = 0;
1110 for (i = 0; i < urb->number_of_packets; i++) {
1111 len = ep->buffer[ep->out_ix];
1112 if (++ep->out_ix == ep->buffer_size)
1113 ep->out_ix = 0;
1114 copy_len = ep->buffer_size - ep->out_ix;
1115 if (copy_len > len)
1116 copy_len = len;
1117 memcpy(urb->transfer_buffer,
1118 &ep->buffer[ep->out_ix], copy_len);
1119 if (copy_len < len) {
1120 memcpy(urb->transfer_buffer+copy_len,
1121 ep->buffer, len-copy_len);
1122 ep->out_ix = len-copy_len;
1123 } else
1124 ep->out_ix += copy_len;
1125 if (ep->out_ix == ep->buffer_size)
1126 ep->out_ix = 0;
1127 urb->iso_frame_desc[i].offset =
1128 urb->actual_length;
1129 urb->actual_length += len;
1130 urb->iso_frame_desc[i].actual_length = len;
1131 urb->iso_frame_desc[i].status = 0;
1132 }
1133 ep->buffered_units -= urb->number_of_packets;
1134 urb->error_count = 0;
1135 urb->start_frame = ep->start_frame;
1136 ep->start_frame += urb->number_of_packets;
1137 list_move_tail(&urbl->link, &xfr_list);
1138 ep->credit -= urb->number_of_packets;
1139 }
1140 }
1141 if (!list_empty(&port->isoc_out_ep) || !list_empty(&port->isoc_in_ep))
1142 rc = 1;
1143 spin_unlock_bh(&ozhcd->hcd_lock);
1144 /* Complete the filled URBs.
1145 */
1146 list_for_each_entry_safe(urbl, n, &xfr_list, link) {
1147 urb = urbl->urb;
1148 list_del_init(&urbl->link);
1149 oz_free_urb_link(urbl);
1150 oz_complete_urb(port->ozhcd->hcd, urb, 0);
1151 }
1152 /* Check if there are any ep0 requests that have timed out.
1153 * If so resent to PD.
1154 */
1155 ep = port->out_ep[0];
1156 if (ep) {
1157 spin_lock_bh(&ozhcd->hcd_lock);
1158 list_for_each_entry_safe(urbl, n, &ep->urb_list, link) {
1159 if (urbl->submit_counter > EP0_TIMEOUT_COUNTER) {
1160 oz_dbg(ON, "Request 0x%p timeout\n", urbl->urb);
1161 list_move_tail(&urbl->link, &xfr_list);
1162 urbl->submit_counter = 0;
1163 } else {
1164 urbl->submit_counter++;
1165 }
1166 }
1167 if (!list_empty(&ep->urb_list))
1168 rc = 1;
1169 spin_unlock_bh(&ozhcd->hcd_lock);
1170 list_for_each_entry_safe(urbl, n, &xfr_list, link) {
1171 oz_dbg(ON, "Resending request to PD\n");
1172 oz_process_ep0_urb(ozhcd, urbl->urb, GFP_ATOMIC);
1173 oz_free_urb_link(urbl);
1174 }
1175 }
1176 return rc;
1177}
1178
1179/*
1180 * Context: softirq
1181 */
1182static int oz_build_endpoints_for_interface(struct usb_hcd *hcd,
1183 struct oz_port *port,
1184 struct usb_host_interface *intf, gfp_t mem_flags)
1185{
1186 struct oz_hcd *ozhcd = port->ozhcd;
1187 int i;
1188 int if_ix = intf->desc.bInterfaceNumber;
1189 int request_heartbeat = 0;
1190
1191 oz_dbg(ON, "interface[%d] = %p\n", if_ix, intf);
1192 if (if_ix >= port->num_iface || port->iface == NULL)
1193 return -ENOMEM;
1194 for (i = 0; i < intf->desc.bNumEndpoints; i++) {
1195 struct usb_host_endpoint *hep = &intf->endpoint[i];
1196 u8 ep_addr = hep->desc.bEndpointAddress;
1197 u8 ep_num = ep_addr & USB_ENDPOINT_NUMBER_MASK;
1198 struct oz_endpoint *ep;
1199 int buffer_size = 0;
1200
1201 oz_dbg(ON, "%d bEndpointAddress = %x\n", i, ep_addr);
1202 if (ep_addr & USB_ENDPOINT_DIR_MASK) {
1203 switch (hep->desc.bmAttributes &
1204 USB_ENDPOINT_XFERTYPE_MASK) {
1205 case USB_ENDPOINT_XFER_ISOC:
1206 buffer_size = OZ_EP_BUFFER_SIZE_ISOC;
1207 break;
1208 case USB_ENDPOINT_XFER_INT:
1209 buffer_size = OZ_EP_BUFFER_SIZE_INT;
1210 break;
1211 }
1212 }
1213
1214 ep = oz_ep_alloc(buffer_size, mem_flags);
1215 if (!ep) {
1216 oz_clean_endpoints_for_interface(hcd, port, if_ix);
1217 return -ENOMEM;
1218 }
1219 ep->attrib = hep->desc.bmAttributes;
1220 ep->ep_num = ep_num;
1221 if ((ep->attrib & USB_ENDPOINT_XFERTYPE_MASK)
1222 == USB_ENDPOINT_XFER_ISOC) {
1223 oz_dbg(ON, "wMaxPacketSize = %d\n",
1224 usb_endpoint_maxp(&hep->desc));
1225 ep->credit_ceiling = 200;
1226 if (ep_addr & USB_ENDPOINT_DIR_MASK) {
1227 ep->flags |= OZ_F_EP_BUFFERING;
1228 } else {
1229 ep->flags |= OZ_F_EP_HAVE_STREAM;
1230 if (oz_usb_stream_create(port->hpd, ep_num))
1231 ep->flags &= ~OZ_F_EP_HAVE_STREAM;
1232 }
1233 }
1234 spin_lock_bh(&ozhcd->hcd_lock);
1235 if (ep_addr & USB_ENDPOINT_DIR_MASK) {
1236 port->in_ep[ep_num] = ep;
1237 port->iface[if_ix].ep_mask |=
1238 (1<<(ep_num+OZ_NB_ENDPOINTS));
1239 if ((ep->attrib & USB_ENDPOINT_XFERTYPE_MASK)
1240 == USB_ENDPOINT_XFER_ISOC) {
1241 list_add_tail(&ep->link, &port->isoc_in_ep);
1242 request_heartbeat = 1;
1243 }
1244 } else {
1245 port->out_ep[ep_num] = ep;
1246 port->iface[if_ix].ep_mask |= (1<<ep_num);
1247 if ((ep->attrib & USB_ENDPOINT_XFERTYPE_MASK)
1248 == USB_ENDPOINT_XFER_ISOC) {
1249 list_add_tail(&ep->link, &port->isoc_out_ep);
1250 request_heartbeat = 1;
1251 }
1252 }
1253 spin_unlock_bh(&ozhcd->hcd_lock);
1254 if (request_heartbeat && port->hpd)
1255 oz_usb_request_heartbeat(port->hpd);
1256 }
1257 return 0;
1258}
1259
1260/*
1261 * Context: softirq
1262 */
1263static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd,
1264 struct oz_port *port, int if_ix)
1265{
1266 struct oz_hcd *ozhcd = port->ozhcd;
1267 unsigned mask;
1268 int i;
1269 LIST_HEAD(ep_list);
1270 struct oz_endpoint *ep, *n;
1271
1272 oz_dbg(ON, "Deleting endpoints for interface %d\n", if_ix);
1273 if (if_ix >= port->num_iface)
1274 return;
1275 spin_lock_bh(&ozhcd->hcd_lock);
1276 mask = port->iface[if_ix].ep_mask;
1277 port->iface[if_ix].ep_mask = 0;
1278 for (i = 0; i < OZ_NB_ENDPOINTS; i++) {
1279 struct list_head *e;
1280 /* Gather OUT endpoints.
1281 */
1282 if ((mask & (1<<i)) && port->out_ep[i]) {
1283 e = &port->out_ep[i]->link;
1284 port->out_ep[i] = NULL;
1285 /* Remove from isoc list if present.
1286 */
1287 list_move_tail(e, &ep_list);
1288 }
1289 /* Gather IN endpoints.
1290 */
1291 if ((mask & (1<<(i+OZ_NB_ENDPOINTS))) && port->in_ep[i]) {
1292 e = &port->in_ep[i]->link;
1293 port->in_ep[i] = NULL;
1294 list_move_tail(e, &ep_list);
1295 }
1296 }
1297 spin_unlock_bh(&ozhcd->hcd_lock);
1298 list_for_each_entry_safe(ep, n, &ep_list, link) {
1299 list_del_init(&ep->link);
1300 oz_ep_free(port, ep);
1301 }
1302}
1303
1304/*
1305 * Context: softirq
1306 */
1307static int oz_build_endpoints_for_config(struct usb_hcd *hcd,
1308 struct oz_port *port, struct usb_host_config *config,
1309 gfp_t mem_flags)
1310{
1311 struct oz_hcd *ozhcd = port->ozhcd;
1312 int i;
1313 int num_iface = config->desc.bNumInterfaces;
1314
1315 if (num_iface) {
1316 struct oz_interface *iface;
1317
1318 iface = kmalloc_array(num_iface, sizeof(struct oz_interface),
1319 mem_flags | __GFP_ZERO);
1320 if (!iface)
1321 return -ENOMEM;
1322 spin_lock_bh(&ozhcd->hcd_lock);
1323 port->iface = iface;
1324 port->num_iface = num_iface;
1325 spin_unlock_bh(&ozhcd->hcd_lock);
1326 }
1327 for (i = 0; i < num_iface; i++) {
1328 struct usb_host_interface *intf =
1329 &config->intf_cache[i]->altsetting[0];
1330 if (oz_build_endpoints_for_interface(hcd, port, intf,
1331 mem_flags))
1332 goto fail;
1333 }
1334 return 0;
1335fail:
1336 oz_clean_endpoints_for_config(hcd, port);
1337 return -1;
1338}
1339
1340/*
1341 * Context: softirq
1342 */
1343static void oz_clean_endpoints_for_config(struct usb_hcd *hcd,
1344 struct oz_port *port)
1345{
1346 struct oz_hcd *ozhcd = port->ozhcd;
1347 int i;
1348
1349 oz_dbg(ON, "Deleting endpoints for configuration\n");
1350 for (i = 0; i < port->num_iface; i++)
1351 oz_clean_endpoints_for_interface(hcd, port, i);
1352 spin_lock_bh(&ozhcd->hcd_lock);
1353 if (port->iface) {
1354 oz_dbg(ON, "Freeing interfaces object\n");
1355 kfree(port->iface);
1356 port->iface = NULL;
1357 }
1358 port->num_iface = 0;
1359 spin_unlock_bh(&ozhcd->hcd_lock);
1360}
1361
1362/*
1363 * Context: tasklet
1364 */
1365static void *oz_claim_hpd(struct oz_port *port)
1366{
1367 void *hpd;
1368 struct oz_hcd *ozhcd = port->ozhcd;
1369
1370 spin_lock_bh(&ozhcd->hcd_lock);
1371 hpd = port->hpd;
1372 if (hpd)
1373 oz_usb_get(hpd);
1374 spin_unlock_bh(&ozhcd->hcd_lock);
1375 return hpd;
1376}
1377
1378/*
1379 * Context: tasklet
1380 */
1381static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb,
1382 gfp_t mem_flags)
1383{
1384 struct usb_ctrlrequest *setup;
1385 unsigned windex;
1386 unsigned wvalue;
1387 unsigned wlength;
1388 void *hpd;
1389 u8 req_id;
1390 int rc = 0;
1391 unsigned complete = 0;
1392
1393 int port_ix = -1;
1394 struct oz_port *port = NULL;
1395
1396 oz_dbg(URB, "[%s]:(%p)\n", __func__, urb);
1397 port_ix = oz_get_port_from_addr(ozhcd, urb->dev->devnum);
1398 if (port_ix < 0) {
1399 rc = -EPIPE;
1400 goto out;
1401 }
1402 port = &ozhcd->ports[port_ix];
1403 if (((port->flags & OZ_PORT_F_PRESENT) == 0)
1404 || (port->flags & OZ_PORT_F_DYING)) {
1405 oz_dbg(ON, "Refusing URB port_ix = %d devnum = %d\n",
1406 port_ix, urb->dev->devnum);
1407 rc = -EPIPE;
1408 goto out;
1409 }
1410 /* Store port in private context data.
1411 */
1412 urb->hcpriv = port;
1413 setup = (struct usb_ctrlrequest *)urb->setup_packet;
1414 windex = le16_to_cpu(setup->wIndex);
1415 wvalue = le16_to_cpu(setup->wValue);
1416 wlength = le16_to_cpu(setup->wLength);
1417 oz_dbg(CTRL_DETAIL, "bRequestType = %x\n", setup->bRequestType);
1418 oz_dbg(CTRL_DETAIL, "bRequest = %x\n", setup->bRequest);
1419 oz_dbg(CTRL_DETAIL, "wValue = %x\n", wvalue);
1420 oz_dbg(CTRL_DETAIL, "wIndex = %x\n", windex);
1421 oz_dbg(CTRL_DETAIL, "wLength = %x\n", wlength);
1422
1423 req_id = port->next_req_id++;
1424 hpd = oz_claim_hpd(port);
1425 if (hpd == NULL) {
1426 oz_dbg(ON, "Cannot claim port\n");
1427 rc = -EPIPE;
1428 goto out;
1429 }
1430
1431 if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
1432 /* Standard requests
1433 */
1434 switch (setup->bRequest) {
1435 case USB_REQ_GET_DESCRIPTOR:
1436 oz_dbg(ON, "USB_REQ_GET_DESCRIPTOR - req\n");
1437 break;
1438 case USB_REQ_SET_ADDRESS:
1439 oz_dbg(ON, "USB_REQ_SET_ADDRESS - req\n");
1440 oz_dbg(ON, "Port %d address is 0x%x\n",
1441 ozhcd->conn_port,
1442 (u8)le16_to_cpu(setup->wValue));
1443 spin_lock_bh(&ozhcd->hcd_lock);
1444 if (ozhcd->conn_port >= 0) {
1445 ozhcd->ports[ozhcd->conn_port].bus_addr =
1446 (u8)le16_to_cpu(setup->wValue);
1447 oz_dbg(ON, "Clearing conn_port\n");
1448 ozhcd->conn_port = -1;
1449 }
1450 spin_unlock_bh(&ozhcd->hcd_lock);
1451 complete = 1;
1452 break;
1453 case USB_REQ_SET_CONFIGURATION:
1454 oz_dbg(ON, "USB_REQ_SET_CONFIGURATION - req\n");
1455 break;
1456 case USB_REQ_GET_CONFIGURATION:
1457 /* We short circuit this case and reply directly since
1458 * we have the selected configuration number cached.
1459 */
1460 oz_dbg(ON, "USB_REQ_GET_CONFIGURATION - reply now\n");
1461 if (urb->transfer_buffer_length >= 1) {
1462 urb->actual_length = 1;
1463 *((u8 *)urb->transfer_buffer) =
1464 port->config_num;
1465 complete = 1;
1466 } else {
1467 rc = -EPIPE;
1468 }
1469 break;
1470 case USB_REQ_GET_INTERFACE:
1471 /* We short circuit this case and reply directly since
1472 * we have the selected interface alternative cached.
1473 */
1474 oz_dbg(ON, "USB_REQ_GET_INTERFACE - reply now\n");
1475 if (urb->transfer_buffer_length >= 1) {
1476 urb->actual_length = 1;
1477 *((u8 *)urb->transfer_buffer) =
1478 port->iface[(u8)windex].alt;
1479 oz_dbg(ON, "interface = %d alt = %d\n",
1480 windex, port->iface[(u8)windex].alt);
1481 complete = 1;
1482 } else {
1483 rc = -EPIPE;
1484 }
1485 break;
1486 case USB_REQ_SET_INTERFACE:
1487 oz_dbg(ON, "USB_REQ_SET_INTERFACE - req\n");
1488 break;
1489 }
1490 }
1491 if (!rc && !complete) {
1492 int data_len = 0;
1493
1494 if ((setup->bRequestType & USB_DIR_IN) == 0)
1495 data_len = wlength;
1496 urb->actual_length = data_len;
1497 if (oz_usb_control_req(port->hpd, req_id, setup,
1498 urb->transfer_buffer, data_len)) {
1499 rc = -ENOMEM;
1500 } else {
1501 /* Note: we are queuing the request after we have
1502 * submitted it to be transmitted. If the request were
1503 * to complete before we queued it then it would not
1504 * be found in the queue. It seems impossible for
1505 * this to happen but if it did the request would
1506 * be resubmitted so the problem would hopefully
1507 * resolve itself. Putting the request into the
1508 * queue before it has been sent is worse since the
1509 * urb could be cancelled while we are using it
1510 * to build the request.
1511 */
1512 if (oz_enqueue_ep_urb(port, 0, 0, urb, req_id))
1513 rc = -ENOMEM;
1514 }
1515 }
1516 oz_usb_put(hpd);
1517out:
1518 if (rc || complete) {
1519 oz_dbg(ON, "Completing request locally\n");
1520 oz_complete_urb(ozhcd->hcd, urb, rc);
1521 } else {
1522 oz_usb_request_heartbeat(port->hpd);
1523 }
1524}
1525
1526/*
1527 * Context: tasklet
1528 */
1529static int oz_urb_process(struct oz_hcd *ozhcd, struct urb *urb)
1530{
1531 int rc = 0;
1532 struct oz_port *port = urb->hcpriv;
1533 u8 ep_addr;
1534
1535 /* When we are paranoid we keep a list of urbs which we check against
1536 * before handing one back. This is just for debugging during
1537 * development and should be turned off in the released driver.
1538 */
1539 oz_remember_urb(urb);
1540 /* Check buffer is valid.
1541 */
1542 if (!urb->transfer_buffer && urb->transfer_buffer_length)
1543 return -EINVAL;
1544 /* Check if there is a device at the port - refuse if not.
1545 */
1546 if ((port->flags & OZ_PORT_F_PRESENT) == 0)
1547 return -EPIPE;
1548 ep_addr = usb_pipeendpoint(urb->pipe);
1549 if (ep_addr) {
1550 /* If the request is not for EP0 then queue it.
1551 */
1552 if (oz_enqueue_ep_urb(port, ep_addr, usb_pipein(urb->pipe),
1553 urb, 0))
1554 rc = -EPIPE;
1555 } else {
1556 oz_process_ep0_urb(ozhcd, urb, GFP_ATOMIC);
1557 }
1558 return rc;
1559}
1560
1561/*
1562 * Context: tasklet
1563 */
1564static void oz_urb_process_tasklet(unsigned long unused)
1565{
1566 unsigned long irq_state;
1567 struct urb *urb;
1568 struct oz_hcd *ozhcd = oz_hcd_claim();
1569 struct oz_urb_link *urbl, *n;
1570 int rc = 0;
1571
1572 if (ozhcd == NULL)
1573 return;
1574 /* This is called from a tasklet so is in softirq context but the urb
1575 * list is filled from any context so we need to lock
1576 * appropriately while removing urbs.
1577 */
1578 spin_lock_irqsave(&g_tasklet_lock, irq_state);
1579 list_for_each_entry_safe(urbl, n, &ozhcd->urb_pending_list, link) {
1580 list_del_init(&urbl->link);
1581 spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
1582 urb = urbl->urb;
1583 oz_free_urb_link(urbl);
1584 rc = oz_urb_process(ozhcd, urb);
1585 if (rc)
1586 oz_complete_urb(ozhcd->hcd, urb, rc);
1587 spin_lock_irqsave(&g_tasklet_lock, irq_state);
1588 }
1589 spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
1590 oz_hcd_put(ozhcd);
1591}
1592
1593/*
1594 * This function searches for the urb in any of the lists it could be in.
1595 * If it is found it is removed from the list and completed. If the urb is
1596 * being processed then it won't be in a list so won't be found. However, the
1597 * call to usb_hcd_check_unlink_urb() will set the value of the unlinked field
1598 * to a non-zero value. When an attempt is made to put the urb back in a list
1599 * the unlinked field will be checked and the urb will then be completed.
1600 * Context: tasklet
1601 */
1602static void oz_urb_cancel(struct oz_port *port, u8 ep_num, struct urb *urb)
1603{
1604 struct oz_urb_link *urbl = NULL;
1605 struct list_head *e;
1606 struct oz_hcd *ozhcd;
1607 unsigned long irq_state;
1608 u8 ix;
1609
1610 if (port == NULL) {
1611 oz_dbg(ON, "%s: ERROR: (%p) port is null\n", __func__, urb);
1612 return;
1613 }
1614 ozhcd = port->ozhcd;
1615 if (ozhcd == NULL) {
1616 oz_dbg(ON, "%s; ERROR: (%p) ozhcd is null\n", __func__, urb);
1617 return;
1618 }
1619
1620 /* Look in the tasklet queue.
1621 */
1622 spin_lock_irqsave(&g_tasklet_lock, irq_state);
1623 list_for_each(e, &ozhcd->urb_cancel_list) {
1624 urbl = list_entry(e, struct oz_urb_link, link);
1625 if (urb == urbl->urb) {
1626 list_del_init(e);
1627 spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
1628 goto out2;
1629 }
1630 }
1631 spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
1632 urbl = NULL;
1633
1634 /* Look in the orphanage.
1635 */
1636 spin_lock_irqsave(&ozhcd->hcd_lock, irq_state);
1637 list_for_each(e, &ozhcd->orphanage) {
1638 urbl = list_entry(e, struct oz_urb_link, link);
1639 if (urbl->urb == urb) {
1640 list_del(e);
1641 oz_dbg(ON, "Found urb in orphanage\n");
1642 goto out;
1643 }
1644 }
1645 ix = (ep_num & 0xf);
1646 urbl = NULL;
1647 if ((ep_num & USB_DIR_IN) && ix)
1648 urbl = oz_remove_urb(port->in_ep[ix], urb);
1649 else
1650 urbl = oz_remove_urb(port->out_ep[ix], urb);
1651out:
1652 spin_unlock_irqrestore(&ozhcd->hcd_lock, irq_state);
1653out2:
1654 if (urbl) {
1655 urb->actual_length = 0;
1656 oz_free_urb_link(urbl);
1657 oz_complete_urb(ozhcd->hcd, urb, -EPIPE);
1658 }
1659}
1660
1661/*
1662 * Context: tasklet
1663 */
1664static void oz_urb_cancel_tasklet(unsigned long unused)
1665{
1666 unsigned long irq_state;
1667 struct urb *urb;
1668 struct oz_urb_link *urbl, *n;
1669 struct oz_hcd *ozhcd = oz_hcd_claim();
1670
1671 if (ozhcd == NULL)
1672 return;
1673 spin_lock_irqsave(&g_tasklet_lock, irq_state);
1674 list_for_each_entry_safe(urbl, n, &ozhcd->urb_cancel_list, link) {
1675 list_del_init(&urbl->link);
1676 spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
1677 urb = urbl->urb;
1678 if (urb->unlinked)
1679 oz_urb_cancel(urbl->port, urbl->ep_num, urb);
1680 oz_free_urb_link(urbl);
1681 spin_lock_irqsave(&g_tasklet_lock, irq_state);
1682 }
1683 spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
1684 oz_hcd_put(ozhcd);
1685}
1686
1687/*
1688 * Context: unknown
1689 */
1690static void oz_hcd_clear_orphanage(struct oz_hcd *ozhcd, int status)
1691{
1692 if (ozhcd) {
1693 struct oz_urb_link *urbl, *n;
1694
1695 list_for_each_entry_safe(urbl, n, &ozhcd->orphanage, link) {
1696 list_del(&urbl->link);
1697 oz_complete_urb(ozhcd->hcd, urbl->urb, status);
1698 oz_free_urb_link(urbl);
1699 }
1700 }
1701}
1702
1703/*
1704 * Context: unknown
1705 */
1706static int oz_hcd_start(struct usb_hcd *hcd)
1707{
1708 hcd->power_budget = 200;
1709 hcd->state = HC_STATE_RUNNING;
1710 hcd->uses_new_polling = 1;
1711 return 0;
1712}
1713
1714/*
1715 * Context: unknown
1716 */
1717static void oz_hcd_stop(struct usb_hcd *hcd)
1718{
1719}
1720
1721/*
1722 * Context: unknown
1723 */
1724static void oz_hcd_shutdown(struct usb_hcd *hcd)
1725{
1726}
1727
1728/*
1729 * Called to queue an urb for the device.
1730 * This function should return a non-zero error code if it fails the urb but
1731 * should not call usb_hcd_giveback_urb().
1732 * Context: any
1733 */
1734static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
1735 gfp_t mem_flags)
1736{
1737 struct oz_hcd *ozhcd = oz_hcd_private(hcd);
1738 int rc;
1739 int port_ix;
1740 struct oz_port *port;
1741 unsigned long irq_state;
1742 struct oz_urb_link *urbl;
1743
1744 oz_dbg(URB, "%s: (%p)\n", __func__, urb);
1745 if (unlikely(ozhcd == NULL)) {
1746 oz_dbg(URB, "Refused urb(%p) not ozhcd\n", urb);
1747 return -EPIPE;
1748 }
1749 if (unlikely(hcd->state != HC_STATE_RUNNING)) {
1750 oz_dbg(URB, "Refused urb(%p) not running\n", urb);
1751 return -EPIPE;
1752 }
1753 port_ix = oz_get_port_from_addr(ozhcd, urb->dev->devnum);
1754 if (port_ix < 0)
1755 return -EPIPE;
1756 port = &ozhcd->ports[port_ix];
1757 if (port == NULL)
1758 return -EPIPE;
1759 if (!(port->flags & OZ_PORT_F_PRESENT) ||
1760 (port->flags & OZ_PORT_F_CHANGED)) {
1761 oz_dbg(ON, "Refusing URB port_ix = %d devnum = %d\n",
1762 port_ix, urb->dev->devnum);
1763 return -EPIPE;
1764 }
1765 urb->hcpriv = port;
1766 /* Put request in queue for processing by tasklet.
1767 */
1768 urbl = oz_alloc_urb_link();
1769 if (unlikely(urbl == NULL))
1770 return -ENOMEM;
1771 urbl->urb = urb;
1772 spin_lock_irqsave(&g_tasklet_lock, irq_state);
1773 rc = usb_hcd_link_urb_to_ep(hcd, urb);
1774 if (unlikely(rc)) {
1775 spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
1776 oz_free_urb_link(urbl);
1777 return rc;
1778 }
1779 list_add_tail(&urbl->link, &ozhcd->urb_pending_list);
1780 spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
1781 tasklet_schedule(&g_urb_process_tasklet);
1782 atomic_inc(&g_pending_urbs);
1783 return 0;
1784}
1785
1786/*
1787 * Context: tasklet
1788 */
1789static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep,
1790 struct urb *urb)
1791{
1792 struct oz_urb_link *urbl;
1793
1794 if (unlikely(ep == NULL))
1795 return NULL;
1796
1797 list_for_each_entry(urbl, &ep->urb_list, link) {
1798 if (urbl->urb == urb) {
1799 list_del_init(&urbl->link);
1800 if (usb_pipeisoc(urb->pipe)) {
1801 ep->credit -= urb->number_of_packets;
1802 if (ep->credit < 0)
1803 ep->credit = 0;
1804 }
1805 return urbl;
1806 }
1807 }
1808 return NULL;
1809}
1810
1811/*
1812 * Called to dequeue a previously submitted urb for the device.
1813 * Context: any
1814 */
1815static int oz_hcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1816{
1817 struct oz_hcd *ozhcd = oz_hcd_private(hcd);
1818 struct oz_urb_link *urbl;
1819 int rc;
1820 unsigned long irq_state;
1821
1822 oz_dbg(URB, "%s: (%p)\n", __func__, urb);
1823 urbl = oz_alloc_urb_link();
1824 if (unlikely(urbl == NULL))
1825 return -ENOMEM;
1826 spin_lock_irqsave(&g_tasklet_lock, irq_state);
1827 /* The following function checks the urb is still in the queue
1828 * maintained by the core and that the unlinked field is zero.
1829 * If both are true the function sets the unlinked field and returns
1830 * zero. Otherwise it returns an error.
1831 */
1832 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
1833 /* We have to check we haven't completed the urb or are about
1834 * to complete it. When we do we set hcpriv to 0 so if this has
1835 * already happened we don't put the urb in the cancel queue.
1836 */
1837 if ((rc == 0) && urb->hcpriv) {
1838 urbl->urb = urb;
1839 urbl->port = (struct oz_port *)urb->hcpriv;
1840 urbl->ep_num = usb_pipeendpoint(urb->pipe);
1841 if (usb_pipein(urb->pipe))
1842 urbl->ep_num |= USB_DIR_IN;
1843 list_add_tail(&urbl->link, &ozhcd->urb_cancel_list);
1844 spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
1845 tasklet_schedule(&g_urb_cancel_tasklet);
1846 } else {
1847 spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
1848 oz_free_urb_link(urbl);
1849 }
1850 return rc;
1851}
1852
1853/*
1854 * Context: unknown
1855 */
1856static void oz_hcd_endpoint_disable(struct usb_hcd *hcd,
1857 struct usb_host_endpoint *ep)
1858{
1859}
1860
1861/*
1862 * Context: unknown
1863 */
1864static void oz_hcd_endpoint_reset(struct usb_hcd *hcd,
1865 struct usb_host_endpoint *ep)
1866{
1867}
1868
1869/*
1870 * Context: unknown
1871 */
1872static int oz_hcd_get_frame_number(struct usb_hcd *hcd)
1873{
1874 oz_dbg(ON, "oz_hcd_get_frame_number\n");
1875 return oz_usb_get_frame_number();
1876}
1877
1878/*
1879 * Context: softirq
1880 * This is called as a consquence of us calling usb_hcd_poll_rh_status() and we
1881 * always do that in softirq context.
1882 */
1883static int oz_hcd_hub_status_data(struct usb_hcd *hcd, char *buf)
1884{
1885 struct oz_hcd *ozhcd = oz_hcd_private(hcd);
1886 int i;
1887
1888 buf[0] = 0;
1889 buf[1] = 0;
1890
1891 spin_lock_bh(&ozhcd->hcd_lock);
1892 for (i = 0; i < OZ_NB_PORTS; i++) {
1893 if (ozhcd->ports[i].flags & OZ_PORT_F_CHANGED) {
1894 oz_dbg(HUB, "Port %d changed\n", i);
1895 ozhcd->ports[i].flags &= ~OZ_PORT_F_CHANGED;
1896 if (i < 7)
1897 buf[0] |= 1 << (i + 1);
1898 else
1899 buf[1] |= 1 << (i - 7);
1900 }
1901 }
1902 spin_unlock_bh(&ozhcd->hcd_lock);
1903 if (buf[0] != 0 || buf[1] != 0)
1904 return 2;
1905 return 0;
1906}
1907
1908/*
1909 * Context: process
1910 */
1911static void oz_get_hub_descriptor(struct usb_hcd *hcd,
1912 struct usb_hub_descriptor *desc)
1913{
1914 memset(desc, 0, sizeof(*desc));
1915 desc->bDescriptorType = 0x29;
1916 desc->bDescLength = 9;
1917 desc->wHubCharacteristics = cpu_to_le16(0x0001);
1918 desc->bNbrPorts = OZ_NB_PORTS;
1919}
1920
1921/*
1922 * Context: process
1923 */
1924static int oz_set_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex)
1925{
1926 struct oz_port *port;
1927 u8 port_id = (u8)windex;
1928 struct oz_hcd *ozhcd = oz_hcd_private(hcd);
1929 unsigned set_bits = 0;
1930 unsigned clear_bits = 0;
1931
1932 if ((port_id < 1) || (port_id > OZ_NB_PORTS))
1933 return -EPIPE;
1934 port = &ozhcd->ports[port_id-1];
1935 switch (wvalue) {
1936 case USB_PORT_FEAT_CONNECTION:
1937 oz_dbg(HUB, "USB_PORT_FEAT_CONNECTION\n");
1938 break;
1939 case USB_PORT_FEAT_ENABLE:
1940 oz_dbg(HUB, "USB_PORT_FEAT_ENABLE\n");
1941 break;
1942 case USB_PORT_FEAT_SUSPEND:
1943 oz_dbg(HUB, "USB_PORT_FEAT_SUSPEND\n");
1944 break;
1945 case USB_PORT_FEAT_OVER_CURRENT:
1946 oz_dbg(HUB, "USB_PORT_FEAT_OVER_CURRENT\n");
1947 break;
1948 case USB_PORT_FEAT_RESET:
1949 oz_dbg(HUB, "USB_PORT_FEAT_RESET\n");
1950 set_bits = USB_PORT_STAT_ENABLE | (USB_PORT_STAT_C_RESET<<16);
1951 clear_bits = USB_PORT_STAT_RESET;
1952 ozhcd->ports[port_id-1].bus_addr = 0;
1953 break;
1954 case USB_PORT_FEAT_POWER:
1955 oz_dbg(HUB, "USB_PORT_FEAT_POWER\n");
1956 set_bits |= USB_PORT_STAT_POWER;
1957 break;
1958 case USB_PORT_FEAT_LOWSPEED:
1959 oz_dbg(HUB, "USB_PORT_FEAT_LOWSPEED\n");
1960 break;
1961 case USB_PORT_FEAT_C_CONNECTION:
1962 oz_dbg(HUB, "USB_PORT_FEAT_C_CONNECTION\n");
1963 break;
1964 case USB_PORT_FEAT_C_ENABLE:
1965 oz_dbg(HUB, "USB_PORT_FEAT_C_ENABLE\n");
1966 break;
1967 case USB_PORT_FEAT_C_SUSPEND:
1968 oz_dbg(HUB, "USB_PORT_FEAT_C_SUSPEND\n");
1969 break;
1970 case USB_PORT_FEAT_C_OVER_CURRENT:
1971 oz_dbg(HUB, "USB_PORT_FEAT_C_OVER_CURRENT\n");
1972 break;
1973 case USB_PORT_FEAT_C_RESET:
1974 oz_dbg(HUB, "USB_PORT_FEAT_C_RESET\n");
1975 break;
1976 case USB_PORT_FEAT_TEST:
1977 oz_dbg(HUB, "USB_PORT_FEAT_TEST\n");
1978 break;
1979 case USB_PORT_FEAT_INDICATOR:
1980 oz_dbg(HUB, "USB_PORT_FEAT_INDICATOR\n");
1981 break;
1982 default:
1983 oz_dbg(HUB, "Other %d\n", wvalue);
1984 break;
1985 }
1986 if (set_bits || clear_bits) {
1987 spin_lock_bh(&port->port_lock);
1988 port->status &= ~clear_bits;
1989 port->status |= set_bits;
1990 spin_unlock_bh(&port->port_lock);
1991 }
1992 oz_dbg(HUB, "Port[%d] status = 0x%x\n", port_id, port->status);
1993 return 0;
1994}
1995
1996/*
1997 * Context: process
1998 */
1999static int oz_clear_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex)
2000{
2001 struct oz_port *port;
2002 u8 port_id = (u8)windex;
2003 struct oz_hcd *ozhcd = oz_hcd_private(hcd);
2004 unsigned clear_bits = 0;
2005
2006 if ((port_id < 1) || (port_id > OZ_NB_PORTS))
2007 return -EPIPE;
2008 port = &ozhcd->ports[port_id-1];
2009 switch (wvalue) {
2010 case USB_PORT_FEAT_CONNECTION:
2011 oz_dbg(HUB, "USB_PORT_FEAT_CONNECTION\n");
2012 break;
2013 case USB_PORT_FEAT_ENABLE:
2014 oz_dbg(HUB, "USB_PORT_FEAT_ENABLE\n");
2015 clear_bits = USB_PORT_STAT_ENABLE;
2016 break;
2017 case USB_PORT_FEAT_SUSPEND:
2018 oz_dbg(HUB, "USB_PORT_FEAT_SUSPEND\n");
2019 break;
2020 case USB_PORT_FEAT_OVER_CURRENT:
2021 oz_dbg(HUB, "USB_PORT_FEAT_OVER_CURRENT\n");
2022 break;
2023 case USB_PORT_FEAT_RESET:
2024 oz_dbg(HUB, "USB_PORT_FEAT_RESET\n");
2025 break;
2026 case USB_PORT_FEAT_POWER:
2027 oz_dbg(HUB, "USB_PORT_FEAT_POWER\n");
2028 clear_bits |= USB_PORT_STAT_POWER;
2029 break;
2030 case USB_PORT_FEAT_LOWSPEED:
2031 oz_dbg(HUB, "USB_PORT_FEAT_LOWSPEED\n");
2032 break;
2033 case USB_PORT_FEAT_C_CONNECTION:
2034 oz_dbg(HUB, "USB_PORT_FEAT_C_CONNECTION\n");
2035 clear_bits = USB_PORT_STAT_C_CONNECTION << 16;
2036 break;
2037 case USB_PORT_FEAT_C_ENABLE:
2038 oz_dbg(HUB, "USB_PORT_FEAT_C_ENABLE\n");
2039 clear_bits = USB_PORT_STAT_C_ENABLE << 16;
2040 break;
2041 case USB_PORT_FEAT_C_SUSPEND:
2042 oz_dbg(HUB, "USB_PORT_FEAT_C_SUSPEND\n");
2043 break;
2044 case USB_PORT_FEAT_C_OVER_CURRENT:
2045 oz_dbg(HUB, "USB_PORT_FEAT_C_OVER_CURRENT\n");
2046 break;
2047 case USB_PORT_FEAT_C_RESET:
2048 oz_dbg(HUB, "USB_PORT_FEAT_C_RESET\n");
2049 clear_bits = USB_PORT_FEAT_C_RESET << 16;
2050 break;
2051 case USB_PORT_FEAT_TEST:
2052 oz_dbg(HUB, "USB_PORT_FEAT_TEST\n");
2053 break;
2054 case USB_PORT_FEAT_INDICATOR:
2055 oz_dbg(HUB, "USB_PORT_FEAT_INDICATOR\n");
2056 break;
2057 default:
2058 oz_dbg(HUB, "Other %d\n", wvalue);
2059 break;
2060 }
2061 if (clear_bits) {
2062 spin_lock_bh(&port->port_lock);
2063 port->status &= ~clear_bits;
2064 spin_unlock_bh(&port->port_lock);
2065 }
2066 oz_dbg(HUB, "Port[%d] status = 0x%x\n",
2067 port_id, ozhcd->ports[port_id-1].status);
2068 return 0;
2069}
2070
2071/*
2072 * Context: process
2073 */
2074static int oz_get_port_status(struct usb_hcd *hcd, u16 windex, char *buf)
2075{
2076 struct oz_hcd *ozhcd;
2077 u32 status;
2078
2079 if ((windex < 1) || (windex > OZ_NB_PORTS))
2080 return -EPIPE;
2081 ozhcd = oz_hcd_private(hcd);
2082 oz_dbg(HUB, "GetPortStatus windex = %d\n", windex);
2083 status = ozhcd->ports[windex-1].status;
2084 put_unaligned(cpu_to_le32(status), (__le32 *)buf);
2085 oz_dbg(HUB, "Port[%d] status = %x\n", windex, status);
2086 return 0;
2087}
2088
2089/*
2090 * Context: process
2091 */
2092static int oz_hcd_hub_control(struct usb_hcd *hcd, u16 req_type, u16 wvalue,
2093 u16 windex, char *buf, u16 wlength)
2094{
2095 int err = 0;
2096
2097 switch (req_type) {
2098 case ClearHubFeature:
2099 oz_dbg(HUB, "ClearHubFeature: %d\n", req_type);
2100 break;
2101 case ClearPortFeature:
2102 err = oz_clear_port_feature(hcd, wvalue, windex);
2103 break;
2104 case GetHubDescriptor:
2105 oz_get_hub_descriptor(hcd, (struct usb_hub_descriptor *)buf);
2106 break;
2107 case GetHubStatus:
2108 oz_dbg(HUB, "GetHubStatus: req_type = 0x%x\n", req_type);
2109 put_unaligned(cpu_to_le32(0), (__le32 *)buf);
2110 break;
2111 case GetPortStatus:
2112 err = oz_get_port_status(hcd, windex, buf);
2113 break;
2114 case SetHubFeature:
2115 oz_dbg(HUB, "SetHubFeature: %d\n", req_type);
2116 break;
2117 case SetPortFeature:
2118 err = oz_set_port_feature(hcd, wvalue, windex);
2119 break;
2120 default:
2121 oz_dbg(HUB, "Other: %d\n", req_type);
2122 break;
2123 }
2124 return err;
2125}
2126
2127/*
2128 * Context: process
2129 */
2130static int oz_hcd_bus_suspend(struct usb_hcd *hcd)
2131{
2132 struct oz_hcd *ozhcd;
2133
2134 ozhcd = oz_hcd_private(hcd);
2135 spin_lock_bh(&ozhcd->hcd_lock);
2136 hcd->state = HC_STATE_SUSPENDED;
2137 ozhcd->flags |= OZ_HDC_F_SUSPENDED;
2138 spin_unlock_bh(&ozhcd->hcd_lock);
2139 return 0;
2140}
2141
2142/*
2143 * Context: process
2144 */
2145static int oz_hcd_bus_resume(struct usb_hcd *hcd)
2146{
2147 struct oz_hcd *ozhcd;
2148
2149 ozhcd = oz_hcd_private(hcd);
2150 spin_lock_bh(&ozhcd->hcd_lock);
2151 ozhcd->flags &= ~OZ_HDC_F_SUSPENDED;
2152 hcd->state = HC_STATE_RUNNING;
2153 spin_unlock_bh(&ozhcd->hcd_lock);
2154 return 0;
2155}
2156
2157static void oz_plat_shutdown(struct platform_device *dev)
2158{
2159}
2160
2161/*
2162 * Context: process
2163 */
2164static int oz_plat_probe(struct platform_device *dev)
2165{
2166 int i;
2167 int err;
2168 struct usb_hcd *hcd;
2169 struct oz_hcd *ozhcd;
2170
2171 hcd = usb_create_hcd(&g_oz_hc_drv, &dev->dev, dev_name(&dev->dev));
2172 if (hcd == NULL) {
2173 oz_dbg(ON, "Failed to created hcd object OK\n");
2174 return -ENOMEM;
2175 }
2176 ozhcd = oz_hcd_private(hcd);
2177 memset(ozhcd, 0, sizeof(*ozhcd));
2178 INIT_LIST_HEAD(&ozhcd->urb_pending_list);
2179 INIT_LIST_HEAD(&ozhcd->urb_cancel_list);
2180 INIT_LIST_HEAD(&ozhcd->orphanage);
2181 ozhcd->hcd = hcd;
2182 ozhcd->conn_port = -1;
2183 spin_lock_init(&ozhcd->hcd_lock);
2184 for (i = 0; i < OZ_NB_PORTS; i++) {
2185 struct oz_port *port = &ozhcd->ports[i];
2186
2187 port->ozhcd = ozhcd;
2188 port->flags = 0;
2189 port->status = 0;
2190 port->bus_addr = 0xff;
2191 spin_lock_init(&port->port_lock);
2192 }
2193 err = usb_add_hcd(hcd, 0, 0);
2194 if (err) {
2195 oz_dbg(ON, "Failed to add hcd object OK\n");
2196 usb_put_hcd(hcd);
2197 return -1;
2198 }
2199 device_wakeup_enable(hcd->self.controller);
2200
2201 spin_lock_bh(&g_hcdlock);
2202 g_ozhcd = ozhcd;
2203 spin_unlock_bh(&g_hcdlock);
2204 return 0;
2205}
2206
2207/*
2208 * Context: unknown
2209 */
2210static int oz_plat_remove(struct platform_device *dev)
2211{
2212 struct usb_hcd *hcd = platform_get_drvdata(dev);
2213 struct oz_hcd *ozhcd;
2214
2215 if (hcd == NULL)
2216 return -1;
2217 ozhcd = oz_hcd_private(hcd);
2218 spin_lock_bh(&g_hcdlock);
2219 if (ozhcd == g_ozhcd)
2220 g_ozhcd = NULL;
2221 spin_unlock_bh(&g_hcdlock);
2222 oz_dbg(ON, "Clearing orphanage\n");
2223 oz_hcd_clear_orphanage(ozhcd, -EPIPE);
2224 oz_dbg(ON, "Removing hcd\n");
2225 usb_remove_hcd(hcd);
2226 usb_put_hcd(hcd);
2227 return 0;
2228}
2229
2230/*
2231 * Context: unknown
2232 */
2233static int oz_plat_suspend(struct platform_device *dev, pm_message_t msg)
2234{
2235 return 0;
2236}
2237
2238
2239/*
2240 * Context: unknown
2241 */
2242static int oz_plat_resume(struct platform_device *dev)
2243{
2244 return 0;
2245}
2246
2247/*
2248 * Context: process
2249 */
2250int oz_hcd_init(void)
2251{
2252 int err;
2253
2254 if (usb_disabled())
2255 return -ENODEV;
2256
2257 oz_urb_link_cache = KMEM_CACHE(oz_urb_link, 0);
2258 if (!oz_urb_link_cache)
2259 return -ENOMEM;
2260
2261 tasklet_init(&g_urb_process_tasklet, oz_urb_process_tasklet, 0);
2262 tasklet_init(&g_urb_cancel_tasklet, oz_urb_cancel_tasklet, 0);
2263 err = platform_driver_register(&g_oz_plat_drv);
2264 oz_dbg(ON, "platform_driver_register() returned %d\n", err);
2265 if (err)
2266 goto error;
2267 g_plat_dev = platform_device_alloc(OZ_PLAT_DEV_NAME, -1);
2268 if (g_plat_dev == NULL) {
2269 err = -ENOMEM;
2270 goto error1;
2271 }
2272 oz_dbg(ON, "platform_device_alloc() succeeded\n");
2273 err = platform_device_add(g_plat_dev);
2274 if (err)
2275 goto error2;
2276 oz_dbg(ON, "platform_device_add() succeeded\n");
2277 return 0;
2278error2:
2279 platform_device_put(g_plat_dev);
2280error1:
2281 platform_driver_unregister(&g_oz_plat_drv);
2282error:
2283 tasklet_disable(&g_urb_process_tasklet);
2284 tasklet_disable(&g_urb_cancel_tasklet);
2285 oz_dbg(ON, "oz_hcd_init() failed %d\n", err);
2286 return err;
2287}
2288
2289/*
2290 * Context: process
2291 */
2292void oz_hcd_term(void)
2293{
2294 msleep(OZ_HUB_DEBOUNCE_TIMEOUT);
2295 tasklet_kill(&g_urb_process_tasklet);
2296 tasklet_kill(&g_urb_cancel_tasklet);
2297 platform_device_unregister(g_plat_dev);
2298 platform_driver_unregister(&g_oz_plat_drv);
2299 oz_dbg(ON, "Pending urbs:%d\n", atomic_read(&g_pending_urbs));
2300 kmem_cache_destroy(oz_urb_link_cache);
2301}
diff --git a/drivers/staging/ozwpan/ozhcd.h b/drivers/staging/ozwpan/ozhcd.h
deleted file mode 100644
index 55e97b1c7079..000000000000
--- a/drivers/staging/ozwpan/ozhcd.h
+++ /dev/null
@@ -1,15 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * ---------------------------------------------------------------------------*/
5#ifndef _OZHCD_H
6#define _OZHCD_H
7
8int oz_hcd_init(void);
9void oz_hcd_term(void);
10struct oz_port *oz_hcd_pd_arrived(void *ctx);
11void oz_hcd_pd_departed(struct oz_port *hport);
12void oz_hcd_pd_reset(void *hpd, void *hport);
13
14#endif /* _OZHCD_H */
15
diff --git a/drivers/staging/ozwpan/ozmain.c b/drivers/staging/ozwpan/ozmain.c
deleted file mode 100644
index 74ef34815b98..000000000000
--- a/drivers/staging/ozwpan/ozmain.c
+++ /dev/null
@@ -1,71 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
5 */
6
7#include <linux/init.h>
8#include <linux/module.h>
9#include <linux/timer.h>
10#include <linux/sched.h>
11#include <linux/netdevice.h>
12#include <linux/errno.h>
13#include <linux/ieee80211.h>
14#include "ozdbg.h"
15#include "ozpd.h"
16#include "ozproto.h"
17#include "ozcdev.h"
18
19unsigned int oz_dbg_mask = OZ_DEFAULT_DBG_MASK;
20
21/*
22 * The name of the 802.11 mac device. Empty string is the default value but a
23 * value can be supplied as a parameter to the module. An empty string means
24 * bind to nothing. '*' means bind to all netcards - this includes non-802.11
25 * netcards. Bindings can be added later using an IOCTL.
26 */
27static char *g_net_dev = "";
28module_param(g_net_dev, charp, S_IRUGO);
29MODULE_PARM_DESC(g_net_dev, "The device(s) to bind to; "
30 "'*' means all, '' (empty string; default) means none.");
31
32/*
33 * Context: process
34 */
35static int __init ozwpan_init(void)
36{
37 int err;
38
39 err = oz_cdev_register();
40 if (err)
41 return err;
42 err = oz_protocol_init(g_net_dev);
43 if (err)
44 goto err_protocol;
45 oz_app_enable(OZ_APPID_USB, 1);
46 oz_apps_init();
47 return 0;
48
49err_protocol:
50 oz_cdev_deregister();
51 return err;
52}
53
54/*
55 * Context: process
56 */
57static void __exit ozwpan_exit(void)
58{
59 oz_protocol_term();
60 oz_apps_term();
61 oz_cdev_deregister();
62}
63
64module_init(ozwpan_init);
65module_exit(ozwpan_exit);
66
67MODULE_AUTHOR("Chris Kelly");
68MODULE_DESCRIPTION("Ozmo Devices USB over WiFi hcd driver");
69MODULE_VERSION("1.0.13");
70MODULE_LICENSE("GPL");
71
diff --git a/drivers/staging/ozwpan/ozpd.c b/drivers/staging/ozwpan/ozpd.c
deleted file mode 100644
index 021d74a132dd..000000000000
--- a/drivers/staging/ozwpan/ozpd.c
+++ /dev/null
@@ -1,886 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
5 */
6
7#include <linux/module.h>
8#include <linux/timer.h>
9#include <linux/sched.h>
10#include <linux/netdevice.h>
11#include <linux/etherdevice.h>
12#include <linux/errno.h>
13#include "ozdbg.h"
14#include "ozprotocol.h"
15#include "ozeltbuf.h"
16#include "ozpd.h"
17#include "ozproto.h"
18#include "ozcdev.h"
19#include "ozusbsvc.h"
20#include <asm/unaligned.h>
21#include <linux/uaccess.h>
22#include <net/psnap.h>
23
24static struct oz_tx_frame *oz_tx_frame_alloc(struct oz_pd *pd);
25static void oz_tx_frame_free(struct oz_pd *pd, struct oz_tx_frame *f);
26static void oz_tx_isoc_free(struct oz_pd *pd, struct oz_tx_frame *f);
27static struct sk_buff *oz_build_frame(struct oz_pd *pd, struct oz_tx_frame *f);
28static int oz_send_isoc_frame(struct oz_pd *pd);
29static void oz_retire_frame(struct oz_pd *pd, struct oz_tx_frame *f);
30static void oz_isoc_stream_free(struct oz_isoc_stream *st);
31static int oz_send_next_queued_frame(struct oz_pd *pd, int more_data);
32static void oz_isoc_destructor(struct sk_buff *skb);
33
34/*
35 * Counts the uncompleted isoc frames submitted to netcard.
36 */
37static atomic_t g_submitted_isoc = ATOMIC_INIT(0);
38
39/* Application handler functions.
40 */
41static const struct oz_app_if g_app_if[OZ_NB_APPS] = {
42 [OZ_APPID_USB] = {
43 .init = oz_usb_init,
44 .term = oz_usb_term,
45 .start = oz_usb_start,
46 .stop = oz_usb_stop,
47 .rx = oz_usb_rx,
48 .heartbeat = oz_usb_heartbeat,
49 .farewell = oz_usb_farewell,
50 },
51 [OZ_APPID_SERIAL] = {
52 .init = oz_cdev_init,
53 .term = oz_cdev_term,
54 .start = oz_cdev_start,
55 .stop = oz_cdev_stop,
56 .rx = oz_cdev_rx,
57 },
58};
59
60
61/*
62 * Context: softirq or process
63 */
64void oz_pd_set_state(struct oz_pd *pd, unsigned state)
65{
66 pd->state = state;
67 switch (state) {
68 case OZ_PD_S_IDLE:
69 oz_pd_dbg(pd, ON, "PD State: OZ_PD_S_IDLE\n");
70 break;
71 case OZ_PD_S_CONNECTED:
72 oz_pd_dbg(pd, ON, "PD State: OZ_PD_S_CONNECTED\n");
73 break;
74 case OZ_PD_S_STOPPED:
75 oz_pd_dbg(pd, ON, "PD State: OZ_PD_S_STOPPED\n");
76 break;
77 case OZ_PD_S_SLEEP:
78 oz_pd_dbg(pd, ON, "PD State: OZ_PD_S_SLEEP\n");
79 break;
80 }
81}
82
83/*
84 * Context: softirq or process
85 */
86void oz_pd_get(struct oz_pd *pd)
87{
88 atomic_inc(&pd->ref_count);
89}
90
91/*
92 * Context: softirq or process
93 */
94void oz_pd_put(struct oz_pd *pd)
95{
96 if (atomic_dec_and_test(&pd->ref_count))
97 oz_pd_destroy(pd);
98}
99
100/*
101 * Context: softirq-serialized
102 */
103struct oz_pd *oz_pd_alloc(const u8 *mac_addr)
104{
105 struct oz_pd *pd;
106 int i;
107
108 pd = kzalloc(sizeof(struct oz_pd), GFP_ATOMIC);
109 if (!pd)
110 return NULL;
111
112 atomic_set(&pd->ref_count, 2);
113 for (i = 0; i < OZ_NB_APPS; i++)
114 spin_lock_init(&pd->app_lock[i]);
115 pd->last_rx_pkt_num = 0xffffffff;
116 oz_pd_set_state(pd, OZ_PD_S_IDLE);
117 pd->max_tx_size = OZ_MAX_TX_SIZE;
118 ether_addr_copy(pd->mac_addr, mac_addr);
119 oz_elt_buf_init(&pd->elt_buff);
120 spin_lock_init(&pd->tx_frame_lock);
121 INIT_LIST_HEAD(&pd->tx_queue);
122 INIT_LIST_HEAD(&pd->farewell_list);
123 pd->last_sent_frame = &pd->tx_queue;
124 spin_lock_init(&pd->stream_lock);
125 INIT_LIST_HEAD(&pd->stream_list);
126 tasklet_init(&pd->heartbeat_tasklet, oz_pd_heartbeat_handler,
127 (unsigned long)pd);
128 tasklet_init(&pd->timeout_tasklet, oz_pd_timeout_handler,
129 (unsigned long)pd);
130 hrtimer_init(&pd->heartbeat, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
131 hrtimer_init(&pd->timeout, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
132 pd->heartbeat.function = oz_pd_heartbeat_event;
133 pd->timeout.function = oz_pd_timeout_event;
134
135 return pd;
136}
137
138/*
139 * Context: softirq or process
140 */
141static void oz_pd_free(struct work_struct *work)
142{
143 struct list_head *e, *n;
144 struct oz_pd *pd;
145
146 oz_pd_dbg(pd, ON, "Destroying PD\n");
147 pd = container_of(work, struct oz_pd, workitem);
148 /*Disable timer tasklets*/
149 tasklet_kill(&pd->heartbeat_tasklet);
150 tasklet_kill(&pd->timeout_tasklet);
151
152 /* Free streams, queued tx frames and farewells. */
153
154 list_for_each_safe(e, n, &pd->stream_list)
155 oz_isoc_stream_free(list_entry(e, struct oz_isoc_stream, link));
156
157 list_for_each_safe(e, n, &pd->tx_queue) {
158 struct oz_tx_frame *f = list_entry(e, struct oz_tx_frame, link);
159
160 if (f->skb != NULL)
161 kfree_skb(f->skb);
162 oz_retire_frame(pd, f);
163 }
164
165 oz_elt_buf_term(&pd->elt_buff);
166
167 list_for_each_safe(e, n, &pd->farewell_list)
168 kfree(list_entry(e, struct oz_farewell, link));
169
170 if (pd->net_dev)
171 dev_put(pd->net_dev);
172 kfree(pd);
173}
174
175/*
176 * Context: softirq or Process
177 */
178void oz_pd_destroy(struct oz_pd *pd)
179{
180 if (hrtimer_active(&pd->timeout))
181 hrtimer_cancel(&pd->timeout);
182 if (hrtimer_active(&pd->heartbeat))
183 hrtimer_cancel(&pd->heartbeat);
184
185 INIT_WORK(&pd->workitem, oz_pd_free);
186 if (!schedule_work(&pd->workitem))
187 oz_pd_dbg(pd, ON, "failed to schedule workitem\n");
188}
189
190/*
191 * Context: softirq-serialized
192 */
193int oz_services_start(struct oz_pd *pd, u16 apps, int resume)
194{
195 int i, rc = 0;
196
197 oz_pd_dbg(pd, ON, "%s: (0x%x) resume(%d)\n", __func__, apps, resume);
198 for (i = 0; i < OZ_NB_APPS; i++) {
199 if (g_app_if[i].start && (apps & (1 << i))) {
200 if (g_app_if[i].start(pd, resume)) {
201 rc = -1;
202 oz_pd_dbg(pd, ON,
203 "Unable to start service %d\n", i);
204 break;
205 }
206 spin_lock_bh(&g_polling_lock);
207 pd->total_apps |= (1 << i);
208 if (resume)
209 pd->paused_apps &= ~(1 << i);
210 spin_unlock_bh(&g_polling_lock);
211 }
212 }
213 return rc;
214}
215
216/*
217 * Context: softirq or process
218 */
219void oz_services_stop(struct oz_pd *pd, u16 apps, int pause)
220{
221 int i;
222
223 oz_pd_dbg(pd, ON, "%s: (0x%x) pause(%d)\n", __func__, apps, pause);
224 for (i = 0; i < OZ_NB_APPS; i++) {
225 if (g_app_if[i].stop && (apps & (1 << i))) {
226 spin_lock_bh(&g_polling_lock);
227 if (pause) {
228 pd->paused_apps |= (1 << i);
229 } else {
230 pd->total_apps &= ~(1 << i);
231 pd->paused_apps &= ~(1 << i);
232 }
233 spin_unlock_bh(&g_polling_lock);
234 g_app_if[i].stop(pd, pause);
235 }
236 }
237}
238
239/*
240 * Context: softirq
241 */
242void oz_pd_heartbeat(struct oz_pd *pd, u16 apps)
243{
244 int i, more = 0;
245
246 for (i = 0; i < OZ_NB_APPS; i++) {
247 if (g_app_if[i].heartbeat && (apps & (1 << i))) {
248 if (g_app_if[i].heartbeat(pd))
249 more = 1;
250 }
251 }
252 if ((!more) && (hrtimer_active(&pd->heartbeat)))
253 hrtimer_cancel(&pd->heartbeat);
254 if (pd->mode & OZ_F_ISOC_ANYTIME) {
255 int count = 8;
256
257 while (count-- && (oz_send_isoc_frame(pd) >= 0))
258 ;
259 }
260}
261
262/*
263 * Context: softirq or process
264 */
265void oz_pd_stop(struct oz_pd *pd)
266{
267 u16 stop_apps;
268
269 oz_dbg(ON, "oz_pd_stop() State = 0x%x\n", pd->state);
270 oz_pd_indicate_farewells(pd);
271 spin_lock_bh(&g_polling_lock);
272 stop_apps = pd->total_apps;
273 pd->total_apps = 0;
274 pd->paused_apps = 0;
275 spin_unlock_bh(&g_polling_lock);
276 oz_services_stop(pd, stop_apps, 0);
277 spin_lock_bh(&g_polling_lock);
278 oz_pd_set_state(pd, OZ_PD_S_STOPPED);
279 /* Remove from PD list.*/
280 list_del(&pd->link);
281 spin_unlock_bh(&g_polling_lock);
282 oz_dbg(ON, "pd ref count = %d\n", atomic_read(&pd->ref_count));
283 oz_pd_put(pd);
284}
285
286/*
287 * Context: softirq
288 */
289int oz_pd_sleep(struct oz_pd *pd)
290{
291 int do_stop = 0;
292 u16 stop_apps;
293
294 spin_lock_bh(&g_polling_lock);
295 if (pd->state & (OZ_PD_S_SLEEP | OZ_PD_S_STOPPED)) {
296 spin_unlock_bh(&g_polling_lock);
297 return 0;
298 }
299 if (pd->keep_alive && pd->session_id)
300 oz_pd_set_state(pd, OZ_PD_S_SLEEP);
301 else
302 do_stop = 1;
303
304 stop_apps = pd->total_apps;
305 spin_unlock_bh(&g_polling_lock);
306 if (do_stop) {
307 oz_pd_stop(pd);
308 } else {
309 oz_services_stop(pd, stop_apps, 1);
310 oz_timer_add(pd, OZ_TIMER_STOP, pd->keep_alive);
311 }
312 return do_stop;
313}
314
315/*
316 * Context: softirq
317 */
318static struct oz_tx_frame *oz_tx_frame_alloc(struct oz_pd *pd)
319{
320 struct oz_tx_frame *f;
321
322 f = kmem_cache_alloc(oz_tx_frame_cache, GFP_ATOMIC);
323 if (f) {
324 f->total_size = sizeof(struct oz_hdr);
325 INIT_LIST_HEAD(&f->link);
326 INIT_LIST_HEAD(&f->elt_list);
327 }
328 return f;
329}
330
331/*
332 * Context: softirq or process
333 */
334static void oz_tx_isoc_free(struct oz_pd *pd, struct oz_tx_frame *f)
335{
336 pd->nb_queued_isoc_frames--;
337 list_del_init(&f->link);
338
339 kmem_cache_free(oz_tx_frame_cache, f);
340
341 oz_dbg(TX_FRAMES, "Releasing ISOC Frame isoc_nb= %d\n",
342 pd->nb_queued_isoc_frames);
343}
344
345/*
346 * Context: softirq or process
347 */
348static void oz_tx_frame_free(struct oz_pd *pd, struct oz_tx_frame *f)
349{
350 kmem_cache_free(oz_tx_frame_cache, f);
351}
352
353/*
354 * Context: softirq-serialized
355 */
356static void oz_set_more_bit(struct sk_buff *skb)
357{
358 struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb);
359
360 oz_hdr->control |= OZ_F_MORE_DATA;
361}
362
363/*
364 * Context: softirq-serialized
365 */
366static void oz_set_last_pkt_nb(struct oz_pd *pd, struct sk_buff *skb)
367{
368 struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb);
369
370 oz_hdr->last_pkt_num = pd->trigger_pkt_num & OZ_LAST_PN_MASK;
371}
372
373/*
374 * Context: softirq
375 */
376int oz_prepare_frame(struct oz_pd *pd, int empty)
377{
378 struct oz_tx_frame *f;
379
380 if ((pd->mode & OZ_MODE_MASK) != OZ_MODE_TRIGGERED)
381 return -1;
382 if (pd->nb_queued_frames >= OZ_MAX_QUEUED_FRAMES)
383 return -1;
384 if (!empty && !oz_are_elts_available(&pd->elt_buff))
385 return -1;
386 f = oz_tx_frame_alloc(pd);
387 if (f == NULL)
388 return -1;
389 f->skb = NULL;
390 f->hdr.control =
391 (OZ_PROTOCOL_VERSION<<OZ_VERSION_SHIFT) | OZ_F_ACK_REQUESTED;
392 ++pd->last_tx_pkt_num;
393 put_unaligned(cpu_to_le32(pd->last_tx_pkt_num), &f->hdr.pkt_num);
394 if (empty == 0) {
395 oz_select_elts_for_tx(&pd->elt_buff, 0, &f->total_size,
396 pd->max_tx_size, &f->elt_list);
397 }
398 spin_lock(&pd->tx_frame_lock);
399 list_add_tail(&f->link, &pd->tx_queue);
400 pd->nb_queued_frames++;
401 spin_unlock(&pd->tx_frame_lock);
402 return 0;
403}
404
405/*
406 * Context: softirq-serialized
407 */
408static struct sk_buff *oz_build_frame(struct oz_pd *pd, struct oz_tx_frame *f)
409{
410 struct sk_buff *skb;
411 struct net_device *dev = pd->net_dev;
412 struct oz_hdr *oz_hdr;
413 struct oz_elt *elt;
414 struct oz_elt_info *ei;
415
416 /* Allocate skb with enough space for the lower layers as well
417 * as the space we need.
418 */
419 skb = alloc_skb(f->total_size + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC);
420 if (skb == NULL)
421 return NULL;
422 /* Reserve the head room for lower layers.
423 */
424 skb_reserve(skb, LL_RESERVED_SPACE(dev));
425 skb_reset_network_header(skb);
426 skb->dev = dev;
427 skb->protocol = htons(OZ_ETHERTYPE);
428 if (dev_hard_header(skb, dev, OZ_ETHERTYPE, pd->mac_addr,
429 dev->dev_addr, skb->len) < 0)
430 goto fail;
431 /* Push the tail to the end of the area we are going to copy to.
432 */
433 oz_hdr = (struct oz_hdr *)skb_put(skb, f->total_size);
434 f->hdr.last_pkt_num = pd->trigger_pkt_num & OZ_LAST_PN_MASK;
435 memcpy(oz_hdr, &f->hdr, sizeof(struct oz_hdr));
436 /* Copy the elements into the frame body.
437 */
438 elt = (struct oz_elt *)(oz_hdr+1);
439 list_for_each_entry(ei, &f->elt_list, link) {
440 memcpy(elt, ei->data, ei->length);
441 elt = oz_next_elt(elt);
442 }
443 return skb;
444fail:
445 kfree_skb(skb);
446 return NULL;
447}
448
449/*
450 * Context: softirq or process
451 */
452static void oz_retire_frame(struct oz_pd *pd, struct oz_tx_frame *f)
453{
454 struct oz_elt_info *ei, *n;
455
456 list_for_each_entry_safe(ei, n, &f->elt_list, link) {
457 list_del_init(&ei->link);
458 if (ei->callback)
459 ei->callback(pd, ei->context);
460 spin_lock_bh(&pd->elt_buff.lock);
461 oz_elt_info_free(&pd->elt_buff, ei);
462 spin_unlock_bh(&pd->elt_buff.lock);
463 }
464 oz_tx_frame_free(pd, f);
465}
466
467/*
468 * Context: softirq-serialized
469 */
470static int oz_send_next_queued_frame(struct oz_pd *pd, int more_data)
471{
472 struct sk_buff *skb;
473 struct oz_tx_frame *f;
474 struct list_head *e;
475
476 spin_lock(&pd->tx_frame_lock);
477 e = pd->last_sent_frame->next;
478 if (e == &pd->tx_queue) {
479 spin_unlock(&pd->tx_frame_lock);
480 return -1;
481 }
482 f = list_entry(e, struct oz_tx_frame, link);
483
484 if (f->skb != NULL) {
485 skb = f->skb;
486 oz_tx_isoc_free(pd, f);
487 spin_unlock(&pd->tx_frame_lock);
488 if (more_data)
489 oz_set_more_bit(skb);
490 oz_set_last_pkt_nb(pd, skb);
491 if ((int)atomic_read(&g_submitted_isoc) <
492 OZ_MAX_SUBMITTED_ISOC) {
493 if (dev_queue_xmit(skb) < 0) {
494 oz_dbg(TX_FRAMES, "Dropping ISOC Frame\n");
495 return -1;
496 }
497 atomic_inc(&g_submitted_isoc);
498 oz_dbg(TX_FRAMES, "Sending ISOC Frame, nb_isoc= %d\n",
499 pd->nb_queued_isoc_frames);
500 return 0;
501 }
502 kfree_skb(skb);
503 oz_dbg(TX_FRAMES, "Dropping ISOC Frame>\n");
504 return -1;
505 }
506
507 pd->last_sent_frame = e;
508 skb = oz_build_frame(pd, f);
509 spin_unlock(&pd->tx_frame_lock);
510 if (!skb)
511 return -1;
512 if (more_data)
513 oz_set_more_bit(skb);
514 oz_dbg(TX_FRAMES, "TX frame PN=0x%x\n", f->hdr.pkt_num);
515 if (dev_queue_xmit(skb) < 0)
516 return -1;
517
518 return 0;
519}
520
521/*
522 * Context: softirq-serialized
523 */
524void oz_send_queued_frames(struct oz_pd *pd, int backlog)
525{
526 while (oz_prepare_frame(pd, 0) >= 0)
527 backlog++;
528
529 switch (pd->mode & (OZ_F_ISOC_NO_ELTS | OZ_F_ISOC_ANYTIME)) {
530
531 case OZ_F_ISOC_NO_ELTS: {
532 backlog += pd->nb_queued_isoc_frames;
533 if (backlog <= 0)
534 goto out;
535 if (backlog > OZ_MAX_SUBMITTED_ISOC)
536 backlog = OZ_MAX_SUBMITTED_ISOC;
537 break;
538 }
539 case OZ_NO_ELTS_ANYTIME: {
540 if ((backlog <= 0) && (pd->isoc_sent == 0))
541 goto out;
542 break;
543 }
544 default: {
545 if (backlog <= 0)
546 goto out;
547 break;
548 }
549 }
550 while (backlog--) {
551 if (oz_send_next_queued_frame(pd, backlog) < 0)
552 break;
553 }
554 return;
555
556out: oz_prepare_frame(pd, 1);
557 oz_send_next_queued_frame(pd, 0);
558}
559
560/*
561 * Context: softirq
562 */
563static int oz_send_isoc_frame(struct oz_pd *pd)
564{
565 struct sk_buff *skb;
566 struct net_device *dev = pd->net_dev;
567 struct oz_hdr *oz_hdr;
568 struct oz_elt *elt;
569 struct oz_elt_info *ei;
570 LIST_HEAD(list);
571 int total_size = sizeof(struct oz_hdr);
572
573 oz_select_elts_for_tx(&pd->elt_buff, 1, &total_size,
574 pd->max_tx_size, &list);
575 if (list_empty(&list))
576 return 0;
577 skb = alloc_skb(total_size + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC);
578 if (skb == NULL) {
579 oz_dbg(ON, "Cannot alloc skb\n");
580 oz_elt_info_free_chain(&pd->elt_buff, &list);
581 return -1;
582 }
583 skb_reserve(skb, LL_RESERVED_SPACE(dev));
584 skb_reset_network_header(skb);
585 skb->dev = dev;
586 skb->protocol = htons(OZ_ETHERTYPE);
587 if (dev_hard_header(skb, dev, OZ_ETHERTYPE, pd->mac_addr,
588 dev->dev_addr, skb->len) < 0) {
589 kfree_skb(skb);
590 return -1;
591 }
592 oz_hdr = (struct oz_hdr *)skb_put(skb, total_size);
593 oz_hdr->control = (OZ_PROTOCOL_VERSION<<OZ_VERSION_SHIFT) | OZ_F_ISOC;
594 oz_hdr->last_pkt_num = pd->trigger_pkt_num & OZ_LAST_PN_MASK;
595 elt = (struct oz_elt *)(oz_hdr+1);
596
597 list_for_each_entry(ei, &list, link) {
598 memcpy(elt, ei->data, ei->length);
599 elt = oz_next_elt(elt);
600 }
601 dev_queue_xmit(skb);
602 oz_elt_info_free_chain(&pd->elt_buff, &list);
603 return 0;
604}
605
606/*
607 * Context: softirq-serialized
608 */
609void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn)
610{
611 struct oz_tx_frame *f, *tmp = NULL;
612 u8 diff;
613 u32 pkt_num;
614
615 LIST_HEAD(list);
616
617 spin_lock(&pd->tx_frame_lock);
618 list_for_each_entry(f, &pd->tx_queue, link) {
619 pkt_num = le32_to_cpu(get_unaligned(&f->hdr.pkt_num));
620 diff = (lpn - (pkt_num & OZ_LAST_PN_MASK)) & OZ_LAST_PN_MASK;
621 if ((diff > OZ_LAST_PN_HALF_CYCLE) || (pkt_num == 0))
622 break;
623 oz_dbg(TX_FRAMES, "Releasing pkt_num= %u, nb= %d\n",
624 pkt_num, pd->nb_queued_frames);
625 tmp = f;
626 pd->nb_queued_frames--;
627 }
628 if (tmp)
629 list_cut_position(&list, &pd->tx_queue, &tmp->link);
630 pd->last_sent_frame = &pd->tx_queue;
631 spin_unlock(&pd->tx_frame_lock);
632
633 list_for_each_entry_safe(f, tmp, &list, link)
634 oz_retire_frame(pd, f);
635}
636
637/*
638 * Precondition: stream_lock must be held.
639 * Context: softirq
640 */
641static struct oz_isoc_stream *pd_stream_find(struct oz_pd *pd, u8 ep_num)
642{
643 struct oz_isoc_stream *st;
644
645 list_for_each_entry(st, &pd->stream_list, link) {
646 if (st->ep_num == ep_num)
647 return st;
648 }
649 return NULL;
650}
651
652/*
653 * Context: softirq
654 */
655int oz_isoc_stream_create(struct oz_pd *pd, u8 ep_num)
656{
657 struct oz_isoc_stream *st;
658
659 st = kzalloc(sizeof(struct oz_isoc_stream), GFP_ATOMIC);
660 if (!st)
661 return -ENOMEM;
662 st->ep_num = ep_num;
663 spin_lock_bh(&pd->stream_lock);
664 if (!pd_stream_find(pd, ep_num)) {
665 list_add(&st->link, &pd->stream_list);
666 st = NULL;
667 }
668 spin_unlock_bh(&pd->stream_lock);
669 kfree(st);
670 return 0;
671}
672
673/*
674 * Context: softirq or process
675 */
676static void oz_isoc_stream_free(struct oz_isoc_stream *st)
677{
678 kfree_skb(st->skb);
679 kfree(st);
680}
681
682/*
683 * Context: softirq
684 */
685int oz_isoc_stream_delete(struct oz_pd *pd, u8 ep_num)
686{
687 struct oz_isoc_stream *st;
688
689 spin_lock_bh(&pd->stream_lock);
690 st = pd_stream_find(pd, ep_num);
691 if (st)
692 list_del(&st->link);
693 spin_unlock_bh(&pd->stream_lock);
694 if (st)
695 oz_isoc_stream_free(st);
696 return 0;
697}
698
699/*
700 * Context: any
701 */
702static void oz_isoc_destructor(struct sk_buff *skb)
703{
704 atomic_dec(&g_submitted_isoc);
705}
706
707/*
708 * Context: softirq
709 */
710int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, const u8 *data, int len)
711{
712 struct net_device *dev = pd->net_dev;
713 struct oz_isoc_stream *st;
714 u8 nb_units = 0;
715 struct sk_buff *skb = NULL;
716 struct oz_hdr *oz_hdr = NULL;
717 int size = 0;
718
719 spin_lock_bh(&pd->stream_lock);
720 st = pd_stream_find(pd, ep_num);
721 if (st) {
722 skb = st->skb;
723 st->skb = NULL;
724 nb_units = st->nb_units;
725 st->nb_units = 0;
726 oz_hdr = st->oz_hdr;
727 size = st->size;
728 }
729 spin_unlock_bh(&pd->stream_lock);
730 if (!st)
731 return 0;
732 if (!skb) {
733 /* Allocate enough space for max size frame. */
734 skb = alloc_skb(pd->max_tx_size + OZ_ALLOCATED_SPACE(dev),
735 GFP_ATOMIC);
736 if (skb == NULL)
737 return 0;
738 /* Reserve the head room for lower layers. */
739 skb_reserve(skb, LL_RESERVED_SPACE(dev));
740 skb_reset_network_header(skb);
741 skb->dev = dev;
742 skb->protocol = htons(OZ_ETHERTYPE);
743 /* For audio packet set priority to AC_VO */
744 skb->priority = 0x7;
745 size = sizeof(struct oz_hdr) + sizeof(struct oz_isoc_large);
746 oz_hdr = (struct oz_hdr *)skb_put(skb, size);
747 }
748 memcpy(skb_put(skb, len), data, len);
749 size += len;
750 if (++nb_units < pd->ms_per_isoc) {
751 spin_lock_bh(&pd->stream_lock);
752 st->skb = skb;
753 st->nb_units = nb_units;
754 st->oz_hdr = oz_hdr;
755 st->size = size;
756 spin_unlock_bh(&pd->stream_lock);
757 } else {
758 struct oz_hdr oz;
759 struct oz_isoc_large iso;
760
761 spin_lock_bh(&pd->stream_lock);
762 iso.frame_number = st->frame_num;
763 st->frame_num += nb_units;
764 spin_unlock_bh(&pd->stream_lock);
765 oz.control =
766 (OZ_PROTOCOL_VERSION<<OZ_VERSION_SHIFT) | OZ_F_ISOC;
767 oz.last_pkt_num = pd->trigger_pkt_num & OZ_LAST_PN_MASK;
768 oz.pkt_num = 0;
769 iso.endpoint = ep_num;
770 iso.format = OZ_DATA_F_ISOC_LARGE;
771 iso.ms_data = nb_units;
772 memcpy(oz_hdr, &oz, sizeof(oz));
773 memcpy(oz_hdr+1, &iso, sizeof(iso));
774 if (dev_hard_header(skb, dev, OZ_ETHERTYPE, pd->mac_addr,
775 dev->dev_addr, skb->len) < 0)
776 goto out;
777
778 skb->destructor = oz_isoc_destructor;
779 /*Queue for Xmit if mode is not ANYTIME*/
780 if (!(pd->mode & OZ_F_ISOC_ANYTIME)) {
781 struct oz_tx_frame *isoc_unit = NULL;
782 int nb = pd->nb_queued_isoc_frames;
783
784 if (nb >= pd->isoc_latency) {
785 struct oz_tx_frame *f;
786
787 oz_dbg(TX_FRAMES, "Dropping ISOC Unit nb= %d\n",
788 nb);
789 spin_lock(&pd->tx_frame_lock);
790 list_for_each_entry(f, &pd->tx_queue, link) {
791 if (f->skb != NULL) {
792 oz_tx_isoc_free(pd, f);
793 break;
794 }
795 }
796 spin_unlock(&pd->tx_frame_lock);
797 }
798 isoc_unit = oz_tx_frame_alloc(pd);
799 if (isoc_unit == NULL)
800 goto out;
801 isoc_unit->hdr = oz;
802 isoc_unit->skb = skb;
803 spin_lock_bh(&pd->tx_frame_lock);
804 list_add_tail(&isoc_unit->link, &pd->tx_queue);
805 pd->nb_queued_isoc_frames++;
806 spin_unlock_bh(&pd->tx_frame_lock);
807 oz_dbg(TX_FRAMES,
808 "Added ISOC Frame to Tx Queue isoc_nb= %d, nb= %d\n",
809 pd->nb_queued_isoc_frames, pd->nb_queued_frames);
810 return 0;
811 }
812
813 /*In ANYTIME mode Xmit unit immediately*/
814 if (atomic_read(&g_submitted_isoc) < OZ_MAX_SUBMITTED_ISOC) {
815 atomic_inc(&g_submitted_isoc);
816 if (dev_queue_xmit(skb) < 0)
817 return -1;
818 return 0;
819 }
820
821out: kfree_skb(skb);
822 return -1;
823
824 }
825 return 0;
826}
827
828/*
829 * Context: process
830 */
831void oz_apps_init(void)
832{
833 int i;
834
835 for (i = 0; i < OZ_NB_APPS; i++) {
836 if (g_app_if[i].init)
837 g_app_if[i].init();
838 }
839}
840
841/*
842 * Context: process
843 */
844void oz_apps_term(void)
845{
846 int i;
847
848 /* Terminate all the apps. */
849 for (i = 0; i < OZ_NB_APPS; i++) {
850 if (g_app_if[i].term)
851 g_app_if[i].term();
852 }
853}
854
855/*
856 * Context: softirq-serialized
857 */
858void oz_handle_app_elt(struct oz_pd *pd, u8 app_id, struct oz_elt *elt)
859{
860 if (app_id < OZ_NB_APPS && g_app_if[app_id].rx)
861 g_app_if[app_id].rx(pd, elt);
862}
863
864/*
865 * Context: softirq or process
866 */
867void oz_pd_indicate_farewells(struct oz_pd *pd)
868{
869 struct oz_farewell *f;
870 const struct oz_app_if *ai = &g_app_if[OZ_APPID_USB];
871
872 while (1) {
873 spin_lock_bh(&g_polling_lock);
874 if (list_empty(&pd->farewell_list)) {
875 spin_unlock_bh(&g_polling_lock);
876 break;
877 }
878 f = list_first_entry(&pd->farewell_list,
879 struct oz_farewell, link);
880 list_del(&f->link);
881 spin_unlock_bh(&g_polling_lock);
882 if (ai->farewell)
883 ai->farewell(pd, f->ep_num, f->report, f->len);
884 kfree(f);
885 }
886}
diff --git a/drivers/staging/ozwpan/ozpd.h b/drivers/staging/ozwpan/ozpd.h
deleted file mode 100644
index 212fab0d807a..000000000000
--- a/drivers/staging/ozwpan/ozpd.h
+++ /dev/null
@@ -1,134 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
5 */
6#ifndef _OZPD_H_
7#define _OZPD_H_
8
9#include <linux/interrupt.h>
10#include "ozeltbuf.h"
11
12/* PD state
13 */
14#define OZ_PD_S_IDLE 0x1
15#define OZ_PD_S_CONNECTED 0x2
16#define OZ_PD_S_SLEEP 0x4
17#define OZ_PD_S_STOPPED 0x8
18
19/* Timer event types.
20 */
21#define OZ_TIMER_TOUT 1
22#define OZ_TIMER_HEARTBEAT 2
23#define OZ_TIMER_STOP 3
24
25/*
26 *External spinlock variable
27 */
28extern spinlock_t g_polling_lock;
29
30/* Data structure that hold information on a frame for transmisson. This is
31 * built when the frame is first transmitted and is used to rebuild the frame
32 * if a re-transmission is required.
33 */
34struct oz_tx_frame {
35 struct list_head link;
36 struct list_head elt_list;
37 struct oz_hdr hdr;
38 struct sk_buff *skb;
39 int total_size;
40};
41
42struct oz_isoc_stream {
43 struct list_head link;
44 u8 ep_num;
45 u8 frame_num;
46 u8 nb_units;
47 int size;
48 struct sk_buff *skb;
49 struct oz_hdr *oz_hdr;
50};
51
52struct oz_farewell {
53 struct list_head link;
54 u8 ep_num;
55 u8 index;
56 u8 len;
57 u8 report[0];
58};
59
60/* Data structure that holds information on a specific peripheral device (PD).
61 */
62struct oz_pd {
63 struct list_head link;
64 atomic_t ref_count;
65 u8 mac_addr[ETH_ALEN];
66 unsigned state;
67 unsigned state_flags;
68 unsigned send_flags;
69 u16 total_apps;
70 u16 paused_apps;
71 u8 session_id;
72 u8 param_rsp_status;
73 u8 pd_info;
74 u8 isoc_sent;
75 u32 last_rx_pkt_num;
76 u32 last_tx_pkt_num;
77 struct timespec last_rx_timestamp;
78 u32 trigger_pkt_num;
79 unsigned long pulse_time;
80 unsigned long pulse_period;
81 unsigned long presleep;
82 unsigned long keep_alive;
83 struct oz_elt_buf elt_buff;
84 void *app_ctx[OZ_NB_APPS];
85 spinlock_t app_lock[OZ_NB_APPS];
86 int max_tx_size;
87 u8 mode;
88 u8 ms_per_isoc;
89 unsigned isoc_latency;
90 unsigned max_stream_buffering;
91 int nb_queued_frames;
92 int nb_queued_isoc_frames;
93 spinlock_t tx_frame_lock;
94 struct list_head *last_sent_frame;
95 struct list_head tx_queue;
96 struct list_head farewell_list;
97 spinlock_t stream_lock;
98 struct list_head stream_list;
99 struct net_device *net_dev;
100 struct hrtimer heartbeat;
101 struct hrtimer timeout;
102 u8 timeout_type;
103 struct tasklet_struct heartbeat_tasklet;
104 struct tasklet_struct timeout_tasklet;
105 struct work_struct workitem;
106};
107
108#define OZ_MAX_QUEUED_FRAMES 4
109
110struct oz_pd *oz_pd_alloc(const u8 *mac_addr);
111void oz_pd_destroy(struct oz_pd *pd);
112void oz_pd_get(struct oz_pd *pd);
113void oz_pd_put(struct oz_pd *pd);
114void oz_pd_set_state(struct oz_pd *pd, unsigned state);
115void oz_pd_indicate_farewells(struct oz_pd *pd);
116int oz_pd_sleep(struct oz_pd *pd);
117void oz_pd_stop(struct oz_pd *pd);
118void oz_pd_heartbeat(struct oz_pd *pd, u16 apps);
119int oz_services_start(struct oz_pd *pd, u16 apps, int resume);
120void oz_services_stop(struct oz_pd *pd, u16 apps, int pause);
121int oz_prepare_frame(struct oz_pd *pd, int empty);
122void oz_send_queued_frames(struct oz_pd *pd, int backlog);
123void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn);
124int oz_isoc_stream_create(struct oz_pd *pd, u8 ep_num);
125int oz_isoc_stream_delete(struct oz_pd *pd, u8 ep_num);
126int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, const u8 *data, int len);
127void oz_handle_app_elt(struct oz_pd *pd, u8 app_id, struct oz_elt *elt);
128void oz_apps_init(void);
129void oz_apps_term(void);
130
131extern struct kmem_cache *oz_elt_info_cache;
132extern struct kmem_cache *oz_tx_frame_cache;
133
134#endif /* Sentry */
diff --git a/drivers/staging/ozwpan/ozproto.c b/drivers/staging/ozwpan/ozproto.c
deleted file mode 100644
index 1ba24a2aef83..000000000000
--- a/drivers/staging/ozwpan/ozproto.c
+++ /dev/null
@@ -1,813 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
5 */
6
7#include <linux/module.h>
8#include <linux/timer.h>
9#include <linux/sched.h>
10#include <linux/netdevice.h>
11#include <linux/etherdevice.h>
12#include <linux/errno.h>
13#include <linux/ieee80211.h>
14#include <linux/slab.h>
15#include "ozdbg.h"
16#include "ozprotocol.h"
17#include "ozeltbuf.h"
18#include "ozpd.h"
19#include "ozproto.h"
20#include "ozusbsvc.h"
21
22#include "ozappif.h"
23#include <asm/unaligned.h>
24#include <linux/uaccess.h>
25#include <net/psnap.h>
26
27#define OZ_CF_CONN_SUCCESS 1
28#define OZ_CF_CONN_FAILURE 2
29
30#define OZ_DO_STOP 1
31#define OZ_DO_SLEEP 2
32
33struct oz_binding {
34 struct packet_type ptype;
35 char name[OZ_MAX_BINDING_LEN];
36 struct list_head link;
37};
38
39/*
40 * External variable
41 */
42
43DEFINE_SPINLOCK(g_polling_lock);
44/*
45 * Static external variables.
46 */
47static LIST_HEAD(g_pd_list);
48static LIST_HEAD(g_binding);
49static DEFINE_SPINLOCK(g_binding_lock);
50static struct sk_buff_head g_rx_queue;
51static u8 g_session_id;
52static u16 g_apps = 0x1;
53static int g_processing_rx;
54
55struct kmem_cache *oz_elt_info_cache;
56struct kmem_cache *oz_tx_frame_cache;
57
58/*
59 * Context: softirq-serialized
60 */
61static u8 oz_get_new_session_id(u8 exclude)
62{
63 if (++g_session_id == 0)
64 g_session_id = 1;
65 if (g_session_id == exclude) {
66 if (++g_session_id == 0)
67 g_session_id = 1;
68 }
69 return g_session_id;
70}
71
72/*
73 * Context: softirq-serialized
74 */
75static void oz_send_conn_rsp(struct oz_pd *pd, u8 status)
76{
77 struct sk_buff *skb;
78 struct net_device *dev = pd->net_dev;
79 struct oz_hdr *oz_hdr;
80 struct oz_elt *elt;
81 struct oz_elt_connect_rsp *body;
82
83 int sz = sizeof(struct oz_hdr) + sizeof(struct oz_elt) +
84 sizeof(struct oz_elt_connect_rsp);
85 skb = alloc_skb(sz + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC);
86 if (skb == NULL)
87 return;
88 skb_reserve(skb, LL_RESERVED_SPACE(dev));
89 skb_reset_network_header(skb);
90 oz_hdr = (struct oz_hdr *)skb_put(skb, sz);
91 elt = (struct oz_elt *)(oz_hdr+1);
92 body = (struct oz_elt_connect_rsp *)(elt+1);
93 skb->dev = dev;
94 skb->protocol = htons(OZ_ETHERTYPE);
95 /* Fill in device header */
96 if (dev_hard_header(skb, dev, OZ_ETHERTYPE, pd->mac_addr,
97 dev->dev_addr, skb->len) < 0) {
98 kfree_skb(skb);
99 return;
100 }
101 oz_hdr->control = OZ_PROTOCOL_VERSION<<OZ_VERSION_SHIFT;
102 oz_hdr->last_pkt_num = 0;
103 put_unaligned(0, &oz_hdr->pkt_num);
104 elt->type = OZ_ELT_CONNECT_RSP;
105 elt->length = sizeof(struct oz_elt_connect_rsp);
106 memset(body, 0, sizeof(struct oz_elt_connect_rsp));
107 body->status = status;
108 if (status == 0) {
109 body->mode = pd->mode;
110 body->session_id = pd->session_id;
111 put_unaligned(cpu_to_le16(pd->total_apps), &body->apps);
112 }
113 oz_dbg(ON, "TX: OZ_ELT_CONNECT_RSP %d", status);
114 dev_queue_xmit(skb);
115}
116
117/*
118 * Context: softirq-serialized
119 */
120static void pd_set_keepalive(struct oz_pd *pd, u8 kalive)
121{
122 unsigned long keep_alive = kalive & OZ_KALIVE_VALUE_MASK;
123
124 switch (kalive & OZ_KALIVE_TYPE_MASK) {
125 case OZ_KALIVE_SPECIAL:
126 pd->keep_alive = keep_alive * 1000*60*60*24*20;
127 break;
128 case OZ_KALIVE_SECS:
129 pd->keep_alive = keep_alive*1000;
130 break;
131 case OZ_KALIVE_MINS:
132 pd->keep_alive = keep_alive*1000*60;
133 break;
134 case OZ_KALIVE_HOURS:
135 pd->keep_alive = keep_alive*1000*60*60;
136 break;
137 default:
138 pd->keep_alive = 0;
139 }
140 oz_dbg(ON, "Keepalive = %lu mSec\n", pd->keep_alive);
141}
142
143/*
144 * Context: softirq-serialized
145 */
146static void pd_set_presleep(struct oz_pd *pd, u8 presleep, u8 start_timer)
147{
148 if (presleep)
149 pd->presleep = presleep*100;
150 else
151 pd->presleep = OZ_PRESLEEP_TOUT;
152 if (start_timer) {
153 spin_unlock(&g_polling_lock);
154 oz_timer_add(pd, OZ_TIMER_TOUT, pd->presleep);
155 spin_lock(&g_polling_lock);
156 }
157 oz_dbg(ON, "Presleep time = %lu mSec\n", pd->presleep);
158}
159
160/*
161 * Context: softirq-serialized
162 */
163static struct oz_pd *oz_connect_req(struct oz_pd *cur_pd, struct oz_elt *elt,
164 const u8 *pd_addr, struct net_device *net_dev)
165{
166 struct oz_pd *pd;
167 struct oz_elt_connect_req *body =
168 (struct oz_elt_connect_req *)(elt+1);
169 u8 rsp_status = OZ_STATUS_SUCCESS;
170 u8 stop_needed = 0;
171 u16 new_apps = g_apps;
172 struct net_device *old_net_dev = NULL;
173 struct oz_pd *free_pd = NULL;
174
175 if (cur_pd) {
176 pd = cur_pd;
177 spin_lock_bh(&g_polling_lock);
178 } else {
179 struct oz_pd *pd2 = NULL;
180 struct list_head *e;
181
182 pd = oz_pd_alloc(pd_addr);
183 if (pd == NULL)
184 return NULL;
185 getnstimeofday(&pd->last_rx_timestamp);
186 spin_lock_bh(&g_polling_lock);
187 list_for_each(e, &g_pd_list) {
188 pd2 = list_entry(e, struct oz_pd, link);
189 if (ether_addr_equal(pd2->mac_addr, pd_addr)) {
190 free_pd = pd;
191 pd = pd2;
192 break;
193 }
194 }
195 if (pd != pd2)
196 list_add_tail(&pd->link, &g_pd_list);
197 }
198 if (pd == NULL) {
199 spin_unlock_bh(&g_polling_lock);
200 return NULL;
201 }
202 if (pd->net_dev != net_dev) {
203 old_net_dev = pd->net_dev;
204 dev_hold(net_dev);
205 pd->net_dev = net_dev;
206 }
207 oz_dbg(ON, "Host vendor: %d\n", body->host_vendor);
208 pd->max_tx_size = OZ_MAX_TX_SIZE;
209 pd->mode = body->mode;
210 pd->pd_info = body->pd_info;
211 if (pd->mode & OZ_F_ISOC_NO_ELTS) {
212 pd->ms_per_isoc = body->ms_per_isoc;
213 if (!pd->ms_per_isoc)
214 pd->ms_per_isoc = 4;
215
216 switch (body->ms_isoc_latency & OZ_LATENCY_MASK) {
217 case OZ_ONE_MS_LATENCY:
218 pd->isoc_latency = (body->ms_isoc_latency &
219 ~OZ_LATENCY_MASK) / pd->ms_per_isoc;
220 break;
221 case OZ_TEN_MS_LATENCY:
222 pd->isoc_latency = ((body->ms_isoc_latency &
223 ~OZ_LATENCY_MASK) * 10) / pd->ms_per_isoc;
224 break;
225 default:
226 pd->isoc_latency = OZ_MAX_TX_QUEUE_ISOC;
227 }
228 }
229 if (body->max_len_div16)
230 pd->max_tx_size = ((u16)body->max_len_div16)<<4;
231 oz_dbg(ON, "Max frame:%u Ms per isoc:%u\n",
232 pd->max_tx_size, pd->ms_per_isoc);
233 pd->max_stream_buffering = 3*1024;
234 pd->pulse_period = OZ_QUANTUM;
235 pd_set_presleep(pd, body->presleep, 0);
236 pd_set_keepalive(pd, body->keep_alive);
237
238 new_apps &= le16_to_cpu(get_unaligned(&body->apps));
239 if ((new_apps & 0x1) && (body->session_id)) {
240 if (pd->session_id) {
241 if (pd->session_id != body->session_id) {
242 rsp_status = OZ_STATUS_SESSION_MISMATCH;
243 goto done;
244 }
245 } else {
246 new_apps &= ~0x1; /* Resume not permitted */
247 pd->session_id =
248 oz_get_new_session_id(body->session_id);
249 }
250 } else {
251 if (pd->session_id && !body->session_id) {
252 rsp_status = OZ_STATUS_SESSION_TEARDOWN;
253 stop_needed = 1;
254 } else {
255 new_apps &= ~0x1; /* Resume not permitted */
256 pd->session_id =
257 oz_get_new_session_id(body->session_id);
258 }
259 }
260done:
261 if (rsp_status == OZ_STATUS_SUCCESS) {
262 u16 start_apps = new_apps & ~pd->total_apps & ~0x1;
263 u16 stop_apps = pd->total_apps & ~new_apps & ~0x1;
264 u16 resume_apps = new_apps & pd->paused_apps & ~0x1;
265
266 spin_unlock_bh(&g_polling_lock);
267 oz_pd_set_state(pd, OZ_PD_S_CONNECTED);
268 oz_dbg(ON, "new_apps=0x%x total_apps=0x%x paused_apps=0x%x\n",
269 new_apps, pd->total_apps, pd->paused_apps);
270 if (start_apps) {
271 if (oz_services_start(pd, start_apps, 0))
272 rsp_status = OZ_STATUS_TOO_MANY_PDS;
273 }
274 if (resume_apps)
275 if (oz_services_start(pd, resume_apps, 1))
276 rsp_status = OZ_STATUS_TOO_MANY_PDS;
277 if (stop_apps)
278 oz_services_stop(pd, stop_apps, 0);
279 oz_pd_request_heartbeat(pd);
280 } else {
281 spin_unlock_bh(&g_polling_lock);
282 }
283 oz_send_conn_rsp(pd, rsp_status);
284 if (rsp_status != OZ_STATUS_SUCCESS) {
285 if (stop_needed)
286 oz_pd_stop(pd);
287 oz_pd_put(pd);
288 pd = NULL;
289 }
290 if (old_net_dev)
291 dev_put(old_net_dev);
292 if (free_pd)
293 oz_pd_destroy(free_pd);
294 return pd;
295}
296
297/*
298 * Context: softirq-serialized
299 */
300static void oz_add_farewell(struct oz_pd *pd, u8 ep_num, u8 index,
301 const u8 *report, u8 len)
302{
303 struct oz_farewell *f;
304 struct oz_farewell *f2;
305 int found = 0;
306
307 f = kmalloc(sizeof(struct oz_farewell) + len, GFP_ATOMIC);
308 if (!f)
309 return;
310 f->ep_num = ep_num;
311 f->index = index;
312 f->len = len;
313 memcpy(f->report, report, len);
314 oz_dbg(ON, "RX: Adding farewell report\n");
315 spin_lock(&g_polling_lock);
316 list_for_each_entry(f2, &pd->farewell_list, link) {
317 if ((f2->ep_num == ep_num) && (f2->index == index)) {
318 found = 1;
319 list_del(&f2->link);
320 break;
321 }
322 }
323 list_add_tail(&f->link, &pd->farewell_list);
324 spin_unlock(&g_polling_lock);
325 if (found)
326 kfree(f2);
327}
328
329/*
330 * Context: softirq-serialized
331 */
332static void oz_rx_frame(struct sk_buff *skb)
333{
334 u8 *mac_hdr;
335 u8 *src_addr;
336 struct oz_elt *elt;
337 int length;
338 struct oz_pd *pd = NULL;
339 struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb);
340 struct timespec current_time;
341 int dup = 0;
342 u32 pkt_num;
343
344 oz_dbg(RX_FRAMES, "RX frame PN=0x%x LPN=0x%x control=0x%x\n",
345 oz_hdr->pkt_num, oz_hdr->last_pkt_num, oz_hdr->control);
346 mac_hdr = skb_mac_header(skb);
347 src_addr = &mac_hdr[ETH_ALEN];
348 length = skb->len;
349
350 /* Check the version field */
351 if (oz_get_prot_ver(oz_hdr->control) != OZ_PROTOCOL_VERSION) {
352 oz_dbg(ON, "Incorrect protocol version: %d\n",
353 oz_get_prot_ver(oz_hdr->control));
354 goto done;
355 }
356
357 pkt_num = le32_to_cpu(get_unaligned(&oz_hdr->pkt_num));
358
359 pd = oz_pd_find(src_addr);
360 if (pd) {
361 if (!(pd->state & OZ_PD_S_CONNECTED))
362 oz_pd_set_state(pd, OZ_PD_S_CONNECTED);
363 getnstimeofday(&current_time);
364 if ((current_time.tv_sec != pd->last_rx_timestamp.tv_sec) ||
365 (pd->presleep < MSEC_PER_SEC)) {
366 oz_timer_add(pd, OZ_TIMER_TOUT, pd->presleep);
367 pd->last_rx_timestamp = current_time;
368 }
369 if (pkt_num != pd->last_rx_pkt_num) {
370 pd->last_rx_pkt_num = pkt_num;
371 } else {
372 dup = 1;
373 oz_dbg(ON, "Duplicate frame\n");
374 }
375 }
376
377 if (pd && !dup && ((pd->mode & OZ_MODE_MASK) == OZ_MODE_TRIGGERED)) {
378 oz_dbg(RX_FRAMES, "Received TRIGGER Frame\n");
379 pd->last_sent_frame = &pd->tx_queue;
380 if (oz_hdr->control & OZ_F_ACK) {
381 /* Retire completed frames */
382 oz_retire_tx_frames(pd, oz_hdr->last_pkt_num);
383 }
384 if ((oz_hdr->control & OZ_F_ACK_REQUESTED) &&
385 (pd->state == OZ_PD_S_CONNECTED)) {
386 int backlog = pd->nb_queued_frames;
387
388 pd->trigger_pkt_num = pkt_num;
389 /* Send queued frames */
390 oz_send_queued_frames(pd, backlog);
391 }
392 }
393
394 length -= sizeof(struct oz_hdr);
395 elt = (struct oz_elt *)((u8 *)oz_hdr + sizeof(struct oz_hdr));
396
397 while (length >= sizeof(struct oz_elt)) {
398 length -= sizeof(struct oz_elt) + elt->length;
399 if (length < 0)
400 break;
401 switch (elt->type) {
402 case OZ_ELT_CONNECT_REQ:
403 oz_dbg(ON, "RX: OZ_ELT_CONNECT_REQ\n");
404 pd = oz_connect_req(pd, elt, src_addr, skb->dev);
405 break;
406 case OZ_ELT_DISCONNECT:
407 oz_dbg(ON, "RX: OZ_ELT_DISCONNECT\n");
408 if (pd)
409 oz_pd_sleep(pd);
410 break;
411 case OZ_ELT_UPDATE_PARAM_REQ: {
412 struct oz_elt_update_param *body =
413 (struct oz_elt_update_param *)(elt + 1);
414 oz_dbg(ON, "RX: OZ_ELT_UPDATE_PARAM_REQ\n");
415 if (pd && (pd->state & OZ_PD_S_CONNECTED)) {
416 spin_lock(&g_polling_lock);
417 pd_set_keepalive(pd, body->keepalive);
418 pd_set_presleep(pd, body->presleep, 1);
419 spin_unlock(&g_polling_lock);
420 }
421 }
422 break;
423 case OZ_ELT_FAREWELL_REQ: {
424 struct oz_elt_farewell *body =
425 (struct oz_elt_farewell *)(elt + 1);
426 oz_dbg(ON, "RX: OZ_ELT_FAREWELL_REQ\n");
427 oz_add_farewell(pd, body->ep_num,
428 body->index, body->report,
429 elt->length + 1 - sizeof(*body));
430 }
431 break;
432 case OZ_ELT_APP_DATA:
433 if (pd && (pd->state & OZ_PD_S_CONNECTED)) {
434 struct oz_app_hdr *app_hdr =
435 (struct oz_app_hdr *)(elt+1);
436 if (dup)
437 break;
438 oz_handle_app_elt(pd, app_hdr->app_id, elt);
439 }
440 break;
441 default:
442 oz_dbg(ON, "RX: Unknown elt %02x\n", elt->type);
443 }
444 elt = oz_next_elt(elt);
445 }
446done:
447 if (pd)
448 oz_pd_put(pd);
449 consume_skb(skb);
450}
451
452/*
453 * Context: process
454 */
455void oz_protocol_term(void)
456{
457 struct oz_binding *b, *t;
458
459 /* Walk the list of bindings and remove each one.
460 */
461 spin_lock_bh(&g_binding_lock);
462 list_for_each_entry_safe(b, t, &g_binding, link) {
463 list_del(&b->link);
464 spin_unlock_bh(&g_binding_lock);
465 dev_remove_pack(&b->ptype);
466 if (b->ptype.dev)
467 dev_put(b->ptype.dev);
468 kfree(b);
469 spin_lock_bh(&g_binding_lock);
470 }
471 spin_unlock_bh(&g_binding_lock);
472 /* Walk the list of PDs and stop each one. This causes the PD to be
473 * removed from the list so we can just pull each one from the head
474 * of the list.
475 */
476 spin_lock_bh(&g_polling_lock);
477 while (!list_empty(&g_pd_list)) {
478 struct oz_pd *pd =
479 list_first_entry(&g_pd_list, struct oz_pd, link);
480 oz_pd_get(pd);
481 spin_unlock_bh(&g_polling_lock);
482 oz_pd_stop(pd);
483 oz_pd_put(pd);
484 spin_lock_bh(&g_polling_lock);
485 }
486 spin_unlock_bh(&g_polling_lock);
487 oz_dbg(ON, "Protocol stopped\n");
488
489 kmem_cache_destroy(oz_tx_frame_cache);
490 kmem_cache_destroy(oz_elt_info_cache);
491}
492
493/*
494 * Context: softirq
495 */
496void oz_pd_heartbeat_handler(unsigned long data)
497{
498 struct oz_pd *pd = (struct oz_pd *)data;
499 u16 apps = 0;
500
501 spin_lock_bh(&g_polling_lock);
502 if (pd->state & OZ_PD_S_CONNECTED)
503 apps = pd->total_apps;
504 spin_unlock_bh(&g_polling_lock);
505 if (apps)
506 oz_pd_heartbeat(pd, apps);
507 oz_pd_put(pd);
508}
509
510/*
511 * Context: softirq
512 */
513void oz_pd_timeout_handler(unsigned long data)
514{
515 int type;
516 struct oz_pd *pd = (struct oz_pd *)data;
517
518 spin_lock_bh(&g_polling_lock);
519 type = pd->timeout_type;
520 spin_unlock_bh(&g_polling_lock);
521 switch (type) {
522 case OZ_TIMER_TOUT:
523 oz_pd_sleep(pd);
524 break;
525 case OZ_TIMER_STOP:
526 oz_pd_stop(pd);
527 break;
528 }
529 oz_pd_put(pd);
530}
531
532/*
533 * Context: Interrupt
534 */
535enum hrtimer_restart oz_pd_heartbeat_event(struct hrtimer *timer)
536{
537 struct oz_pd *pd;
538
539 pd = container_of(timer, struct oz_pd, heartbeat);
540 hrtimer_forward_now(timer, ktime_set(pd->pulse_period /
541 MSEC_PER_SEC, (pd->pulse_period % MSEC_PER_SEC) * NSEC_PER_MSEC));
542 oz_pd_get(pd);
543 tasklet_schedule(&pd->heartbeat_tasklet);
544 return HRTIMER_RESTART;
545}
546
547/*
548 * Context: Interrupt
549 */
550enum hrtimer_restart oz_pd_timeout_event(struct hrtimer *timer)
551{
552 struct oz_pd *pd;
553
554 pd = container_of(timer, struct oz_pd, timeout);
555 oz_pd_get(pd);
556 tasklet_schedule(&pd->timeout_tasklet);
557 return HRTIMER_NORESTART;
558}
559
560/*
561 * Context: softirq or process
562 */
563void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time)
564{
565 spin_lock_bh(&g_polling_lock);
566 switch (type) {
567 case OZ_TIMER_TOUT:
568 case OZ_TIMER_STOP:
569 if (hrtimer_active(&pd->timeout)) {
570 hrtimer_set_expires(&pd->timeout, ktime_set(due_time /
571 MSEC_PER_SEC, (due_time % MSEC_PER_SEC) *
572 NSEC_PER_MSEC));
573 hrtimer_start_expires(&pd->timeout, HRTIMER_MODE_REL);
574 } else {
575 hrtimer_start(&pd->timeout, ktime_set(due_time /
576 MSEC_PER_SEC, (due_time % MSEC_PER_SEC) *
577 NSEC_PER_MSEC), HRTIMER_MODE_REL);
578 }
579 pd->timeout_type = type;
580 break;
581 case OZ_TIMER_HEARTBEAT:
582 if (!hrtimer_active(&pd->heartbeat))
583 hrtimer_start(&pd->heartbeat, ktime_set(due_time /
584 MSEC_PER_SEC, (due_time % MSEC_PER_SEC) *
585 NSEC_PER_MSEC), HRTIMER_MODE_REL);
586 break;
587 }
588 spin_unlock_bh(&g_polling_lock);
589}
590
591/*
592 * Context: softirq or process
593 */
594void oz_pd_request_heartbeat(struct oz_pd *pd)
595{
596 oz_timer_add(pd, OZ_TIMER_HEARTBEAT, pd->pulse_period > 0 ?
597 pd->pulse_period : OZ_QUANTUM);
598}
599
600/*
601 * Context: softirq or process
602 */
603struct oz_pd *oz_pd_find(const u8 *mac_addr)
604{
605 struct oz_pd *pd;
606
607 spin_lock_bh(&g_polling_lock);
608 list_for_each_entry(pd, &g_pd_list, link) {
609 if (ether_addr_equal(pd->mac_addr, mac_addr)) {
610 oz_pd_get(pd);
611 spin_unlock_bh(&g_polling_lock);
612 return pd;
613 }
614 }
615 spin_unlock_bh(&g_polling_lock);
616 return NULL;
617}
618
619/*
620 * Context: process
621 */
622void oz_app_enable(int app_id, int enable)
623{
624 if (app_id < OZ_NB_APPS) {
625 spin_lock_bh(&g_polling_lock);
626 if (enable)
627 g_apps |= (1<<app_id);
628 else
629 g_apps &= ~(1<<app_id);
630 spin_unlock_bh(&g_polling_lock);
631 }
632}
633
634/*
635 * Context: softirq
636 */
637static int oz_pkt_recv(struct sk_buff *skb, struct net_device *dev,
638 struct packet_type *pt, struct net_device *orig_dev)
639{
640 skb = skb_share_check(skb, GFP_ATOMIC);
641 if (skb == NULL)
642 return 0;
643 spin_lock_bh(&g_rx_queue.lock);
644 if (g_processing_rx) {
645 /* We already hold the lock so use __ variant.
646 */
647 __skb_queue_head(&g_rx_queue, skb);
648 spin_unlock_bh(&g_rx_queue.lock);
649 } else {
650 g_processing_rx = 1;
651 do {
652
653 spin_unlock_bh(&g_rx_queue.lock);
654 oz_rx_frame(skb);
655 spin_lock_bh(&g_rx_queue.lock);
656 if (skb_queue_empty(&g_rx_queue)) {
657 g_processing_rx = 0;
658 spin_unlock_bh(&g_rx_queue.lock);
659 break;
660 }
661 /* We already hold the lock so use __ variant.
662 */
663 skb = __skb_dequeue(&g_rx_queue);
664 } while (1);
665 }
666 return 0;
667}
668
669/*
670 * Context: process
671 */
672void oz_binding_add(const char *net_dev)
673{
674 struct oz_binding *binding;
675
676 binding = kzalloc(sizeof(struct oz_binding), GFP_KERNEL);
677 if (!binding)
678 return;
679
680 binding->ptype.type = htons(OZ_ETHERTYPE);
681 binding->ptype.func = oz_pkt_recv;
682 if (net_dev && *net_dev) {
683 memcpy(binding->name, net_dev, OZ_MAX_BINDING_LEN);
684 oz_dbg(ON, "Adding binding: %s\n", net_dev);
685 binding->ptype.dev = dev_get_by_name(&init_net, net_dev);
686 if (binding->ptype.dev == NULL) {
687 oz_dbg(ON, "Netdev %s not found\n", net_dev);
688 kfree(binding);
689 return;
690 }
691 }
692 dev_add_pack(&binding->ptype);
693 spin_lock_bh(&g_binding_lock);
694 list_add_tail(&binding->link, &g_binding);
695 spin_unlock_bh(&g_binding_lock);
696}
697
698/*
699 * Context: process
700 */
701static void pd_stop_all_for_device(struct net_device *net_dev)
702{
703 LIST_HEAD(h);
704 struct oz_pd *pd;
705 struct oz_pd *n;
706
707 spin_lock_bh(&g_polling_lock);
708 list_for_each_entry_safe(pd, n, &g_pd_list, link) {
709 if (pd->net_dev == net_dev) {
710 list_move(&pd->link, &h);
711 oz_pd_get(pd);
712 }
713 }
714 spin_unlock_bh(&g_polling_lock);
715 while (!list_empty(&h)) {
716 pd = list_first_entry(&h, struct oz_pd, link);
717 oz_pd_stop(pd);
718 oz_pd_put(pd);
719 }
720}
721
722/*
723 * Context: process
724 */
725void oz_binding_remove(const char *net_dev)
726{
727 struct oz_binding *binding;
728 int found = 0;
729
730 oz_dbg(ON, "Removing binding: %s\n", net_dev);
731 spin_lock_bh(&g_binding_lock);
732 list_for_each_entry(binding, &g_binding, link) {
733 if (strncmp(binding->name, net_dev, OZ_MAX_BINDING_LEN) == 0) {
734 oz_dbg(ON, "Binding '%s' found\n", net_dev);
735 found = 1;
736 break;
737 }
738 }
739 spin_unlock_bh(&g_binding_lock);
740 if (found) {
741 dev_remove_pack(&binding->ptype);
742 if (binding->ptype.dev) {
743 dev_put(binding->ptype.dev);
744 pd_stop_all_for_device(binding->ptype.dev);
745 }
746 list_del(&binding->link);
747 kfree(binding);
748 }
749}
750
751/*
752 * Context: process
753 */
754static char *oz_get_next_device_name(char *s, char *dname, int max_size)
755{
756 while (*s == ',')
757 s++;
758 while (*s && (*s != ',') && max_size > 1) {
759 *dname++ = *s++;
760 max_size--;
761 }
762 *dname = 0;
763 return s;
764}
765
766/*
767 * Context: process
768 */
769int oz_protocol_init(char *devs)
770{
771 oz_elt_info_cache = KMEM_CACHE(oz_elt_info, 0);
772 if (!oz_elt_info_cache)
773 return -ENOMEM;
774
775 oz_tx_frame_cache = KMEM_CACHE(oz_tx_frame, 0);
776 if (!oz_tx_frame_cache) {
777 kmem_cache_destroy(oz_elt_info_cache);
778 return -ENOMEM;
779 }
780
781 skb_queue_head_init(&g_rx_queue);
782 if (devs[0] == '*') {
783 oz_binding_add(NULL);
784 } else {
785 char d[32];
786
787 while (*devs) {
788 devs = oz_get_next_device_name(devs, d, sizeof(d));
789 if (d[0])
790 oz_binding_add(d);
791 }
792 }
793 return 0;
794}
795
796/*
797 * Context: process
798 */
799int oz_get_pd_list(struct oz_mac_addr *addr, int max_count)
800{
801 struct oz_pd *pd;
802 int count = 0;
803
804 spin_lock_bh(&g_polling_lock);
805 list_for_each_entry(pd, &g_pd_list, link) {
806 if (count >= max_count)
807 break;
808 ether_addr_copy((u8 *)&addr[count++], pd->mac_addr);
809 }
810 spin_unlock_bh(&g_polling_lock);
811 return count;
812}
813
diff --git a/drivers/staging/ozwpan/ozproto.h b/drivers/staging/ozwpan/ozproto.h
deleted file mode 100644
index 30c2db91c000..000000000000
--- a/drivers/staging/ozwpan/ozproto.h
+++ /dev/null
@@ -1,62 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
5 */
6#ifndef _OZPROTO_H
7#define _OZPROTO_H
8
9#include <asm/byteorder.h>
10#include "ozdbg.h"
11#include "ozappif.h"
12
13#define OZ_ALLOCATED_SPACE(__x) (LL_RESERVED_SPACE(__x)+(__x)->needed_tailroom)
14
15/* Quantum in MS */
16#define OZ_QUANTUM 8
17/* Default timeouts.
18 */
19#define OZ_PRESLEEP_TOUT 11
20
21/* Maximun sizes of tx frames. */
22#define OZ_MAX_TX_SIZE 760
23
24/* Maximum number of uncompleted isoc frames that can be pending in network. */
25#define OZ_MAX_SUBMITTED_ISOC 16
26
27/* Maximum number of uncompleted isoc frames that can be pending in Tx Queue. */
28#define OZ_MAX_TX_QUEUE_ISOC 32
29
30/* Application handler functions.
31 */
32struct oz_app_if {
33 int (*init)(void);
34 void (*term)(void);
35 int (*start)(struct oz_pd *pd, int resume);
36 void (*stop)(struct oz_pd *pd, int pause);
37 void (*rx)(struct oz_pd *pd, struct oz_elt *elt);
38 int (*heartbeat)(struct oz_pd *pd);
39 void (*farewell)(struct oz_pd *pd, u8 ep_num, u8 *data, u8 len);
40};
41
42int oz_protocol_init(char *devs);
43void oz_protocol_term(void);
44int oz_get_pd_list(struct oz_mac_addr *addr, int max_count);
45void oz_app_enable(int app_id, int enable);
46struct oz_pd *oz_pd_find(const u8 *mac_addr);
47void oz_binding_add(const char *net_dev);
48void oz_binding_remove(const char *net_dev);
49void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time);
50void oz_timer_delete(struct oz_pd *pd, int type);
51void oz_pd_request_heartbeat(struct oz_pd *pd);
52void oz_pd_heartbeat_handler(unsigned long data);
53void oz_pd_timeout_handler(unsigned long data);
54enum hrtimer_restart oz_pd_heartbeat_event(struct hrtimer *timer);
55enum hrtimer_restart oz_pd_timeout_event(struct hrtimer *timer);
56int oz_get_pd_status_list(char *pd_list, int max_count);
57int oz_get_binding_list(char *buf, int max_if);
58
59extern struct kmem_cache *oz_elt_info_cache;
60extern struct kmem_cache *oz_tx_frame_cache;
61
62#endif /* _OZPROTO_H */
diff --git a/drivers/staging/ozwpan/ozprotocol.h b/drivers/staging/ozwpan/ozprotocol.h
deleted file mode 100644
index 4642072596da..000000000000
--- a/drivers/staging/ozwpan/ozprotocol.h
+++ /dev/null
@@ -1,375 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
5 */
6#ifndef _OZPROTOCOL_H
7#define _OZPROTOCOL_H
8
9#define PACKED __packed
10
11#define OZ_ETHERTYPE 0x892e
12
13/* Status codes
14 */
15#define OZ_STATUS_SUCCESS 0
16#define OZ_STATUS_INVALID_PARAM 1
17#define OZ_STATUS_TOO_MANY_PDS 2
18#define OZ_STATUS_NOT_ALLOWED 4
19#define OZ_STATUS_SESSION_MISMATCH 5
20#define OZ_STATUS_SESSION_TEARDOWN 6
21
22/* This is the generic element header.
23 Every element starts with this.
24 */
25struct oz_elt {
26 u8 type;
27 u8 length;
28} PACKED;
29
30#define oz_next_elt(__elt) \
31 (struct oz_elt *)((u8 *)((__elt) + 1) + (__elt)->length)
32
33/* Protocol element IDs.
34 */
35#define OZ_ELT_CONNECT_REQ 0x06
36#define OZ_ELT_CONNECT_RSP 0x07
37#define OZ_ELT_DISCONNECT 0x08
38#define OZ_ELT_UPDATE_PARAM_REQ 0x11
39#define OZ_ELT_FAREWELL_REQ 0x12
40#define OZ_ELT_APP_DATA 0x31
41
42/* This is the Ozmo header which is the first Ozmo specific part
43 * of a frame and comes after the MAC header.
44 */
45struct oz_hdr {
46 u8 control;
47 u8 last_pkt_num;
48 u32 pkt_num;
49} PACKED;
50
51#define OZ_PROTOCOL_VERSION 0x1
52/* Bits in the control field. */
53#define OZ_VERSION_MASK 0xc
54#define OZ_VERSION_SHIFT 2
55#define OZ_F_ACK 0x10
56#define OZ_F_ISOC 0x20
57#define OZ_F_MORE_DATA 0x40
58#define OZ_F_ACK_REQUESTED 0x80
59
60#define oz_get_prot_ver(__x) (((__x) & OZ_VERSION_MASK) >> OZ_VERSION_SHIFT)
61
62/* Used to select the bits of packet number to put in the last_pkt_num.
63 */
64#define OZ_LAST_PN_MASK 0x00ff
65
66#define OZ_LAST_PN_HALF_CYCLE 127
67
68#define OZ_LATENCY_MASK 0xc0
69#define OZ_ONE_MS_LATENCY 0x40
70#define OZ_TEN_MS_LATENCY 0x80
71
72/* Connect request data structure.
73 */
74struct oz_elt_connect_req {
75 u8 mode;
76 u8 resv1[16];
77 u8 pd_info;
78 u8 session_id;
79 u8 presleep;
80 u8 ms_isoc_latency;
81 u8 host_vendor;
82 u8 keep_alive;
83 u16 apps;
84 u8 max_len_div16;
85 u8 ms_per_isoc;
86 u8 resv3[2];
87} PACKED;
88
89/* mode field bits.
90 */
91#define OZ_MODE_POLLED 0x0
92#define OZ_MODE_TRIGGERED 0x1
93#define OZ_MODE_MASK 0xf
94#define OZ_F_ISOC_NO_ELTS 0x40
95#define OZ_F_ISOC_ANYTIME 0x80
96#define OZ_NO_ELTS_ANYTIME 0xc0
97
98/* Keep alive field.
99 */
100#define OZ_KALIVE_TYPE_MASK 0xc0
101#define OZ_KALIVE_VALUE_MASK 0x3f
102#define OZ_KALIVE_SPECIAL 0x00
103#define OZ_KALIVE_SECS 0x40
104#define OZ_KALIVE_MINS 0x80
105#define OZ_KALIVE_HOURS 0xc0
106
107/* Connect response data structure.
108 */
109struct oz_elt_connect_rsp {
110 u8 mode;
111 u8 status;
112 u8 resv1[3];
113 u8 session_id;
114 u16 apps;
115 u32 resv2;
116} PACKED;
117
118struct oz_elt_farewell {
119 u8 ep_num;
120 u8 index;
121 u8 report[1];
122} PACKED;
123
124struct oz_elt_update_param {
125 u8 resv1[16];
126 u8 presleep;
127 u8 resv2;
128 u8 host_vendor;
129 u8 keepalive;
130} PACKED;
131
132/* Header common to all application elements.
133 */
134struct oz_app_hdr {
135 u8 app_id;
136 u8 elt_seq_num;
137} PACKED;
138
139/* Values for app_id.
140 */
141#define OZ_APPID_USB 0x1
142#define OZ_APPID_SERIAL 0x4
143#define OZ_APPID_MAX OZ_APPID_SERIAL
144#define OZ_NB_APPS (OZ_APPID_MAX+1)
145
146/* USB header common to all elements for the USB application.
147 * This header extends the oz_app_hdr and comes directly after
148 * the element header in a USB application.
149 */
150struct oz_usb_hdr {
151 u8 app_id;
152 u8 elt_seq_num;
153 u8 type;
154} PACKED;
155
156
157
158/* USB requests element subtypes (type field of hs_usb_hdr).
159 */
160#define OZ_GET_DESC_REQ 1
161#define OZ_GET_DESC_RSP 2
162#define OZ_SET_CONFIG_REQ 3
163#define OZ_SET_CONFIG_RSP 4
164#define OZ_SET_INTERFACE_REQ 5
165#define OZ_SET_INTERFACE_RSP 6
166#define OZ_VENDOR_CLASS_REQ 7
167#define OZ_VENDOR_CLASS_RSP 8
168#define OZ_GET_STATUS_REQ 9
169#define OZ_GET_STATUS_RSP 10
170#define OZ_CLEAR_FEATURE_REQ 11
171#define OZ_CLEAR_FEATURE_RSP 12
172#define OZ_SET_FEATURE_REQ 13
173#define OZ_SET_FEATURE_RSP 14
174#define OZ_GET_CONFIGURATION_REQ 15
175#define OZ_GET_CONFIGURATION_RSP 16
176#define OZ_GET_INTERFACE_REQ 17
177#define OZ_GET_INTERFACE_RSP 18
178#define OZ_SYNCH_FRAME_REQ 19
179#define OZ_SYNCH_FRAME_RSP 20
180#define OZ_USB_ENDPOINT_DATA 23
181
182#define OZ_REQD_D2H 0x80
183
184struct oz_get_desc_req {
185 u8 app_id;
186 u8 elt_seq_num;
187 u8 type;
188 u8 req_id;
189 u16 offset;
190 u16 size;
191 u8 req_type;
192 u8 desc_type;
193 __le16 w_index;
194 u8 index;
195} PACKED;
196
197/* Values for desc_type field.
198*/
199#define OZ_DESC_DEVICE 0x01
200#define OZ_DESC_CONFIG 0x02
201#define OZ_DESC_STRING 0x03
202
203/* Values for req_type field.
204 */
205#define OZ_RECP_MASK 0x1F
206#define OZ_RECP_DEVICE 0x00
207#define OZ_RECP_INTERFACE 0x01
208#define OZ_RECP_ENDPOINT 0x02
209
210#define OZ_REQT_MASK 0x60
211#define OZ_REQT_STD 0x00
212#define OZ_REQT_CLASS 0x20
213#define OZ_REQT_VENDOR 0x40
214
215struct oz_get_desc_rsp {
216 u8 app_id;
217 u8 elt_seq_num;
218 u8 type;
219 u8 req_id;
220 __le16 offset;
221 __le16 total_size;
222 u8 rcode;
223 u8 data[1];
224} PACKED;
225
226struct oz_feature_req {
227 u8 app_id;
228 u8 elt_seq_num;
229 u8 type;
230 u8 req_id;
231 u8 recipient;
232 u8 index;
233 u16 feature;
234} PACKED;
235
236struct oz_feature_rsp {
237 u8 app_id;
238 u8 elt_seq_num;
239 u8 type;
240 u8 req_id;
241 u8 rcode;
242} PACKED;
243
244struct oz_set_config_req {
245 u8 app_id;
246 u8 elt_seq_num;
247 u8 type;
248 u8 req_id;
249 u8 index;
250} PACKED;
251
252struct oz_set_config_rsp {
253 u8 app_id;
254 u8 elt_seq_num;
255 u8 type;
256 u8 req_id;
257 u8 rcode;
258} PACKED;
259
260struct oz_set_interface_req {
261 u8 app_id;
262 u8 elt_seq_num;
263 u8 type;
264 u8 req_id;
265 u8 index;
266 u8 alternative;
267} PACKED;
268
269struct oz_set_interface_rsp {
270 u8 app_id;
271 u8 elt_seq_num;
272 u8 type;
273 u8 req_id;
274 u8 rcode;
275} PACKED;
276
277struct oz_get_interface_req {
278 u8 app_id;
279 u8 elt_seq_num;
280 u8 type;
281 u8 req_id;
282 u8 index;
283} PACKED;
284
285struct oz_get_interface_rsp {
286 u8 app_id;
287 u8 elt_seq_num;
288 u8 type;
289 u8 req_id;
290 u8 rcode;
291 u8 alternative;
292} PACKED;
293
294struct oz_vendor_class_req {
295 u8 app_id;
296 u8 elt_seq_num;
297 u8 type;
298 u8 req_id;
299 u8 req_type;
300 u8 request;
301 u16 value;
302 u16 index;
303 u8 data[1];
304} PACKED;
305
306struct oz_vendor_class_rsp {
307 u8 app_id;
308 u8 elt_seq_num;
309 u8 type;
310 u8 req_id;
311 u8 rcode;
312 u8 data[1];
313} PACKED;
314
315struct oz_data {
316 u8 app_id;
317 u8 elt_seq_num;
318 u8 type;
319 u8 endpoint;
320 u8 format;
321} PACKED;
322
323struct oz_isoc_fixed {
324 u8 app_id;
325 u8 elt_seq_num;
326 u8 type;
327 u8 endpoint;
328 u8 format;
329 u8 unit_size;
330 u8 frame_number;
331 u8 data[1];
332} PACKED;
333
334struct oz_multiple_fixed {
335 u8 app_id;
336 u8 elt_seq_num;
337 u8 type;
338 u8 endpoint;
339 u8 format;
340 u8 unit_size;
341 u8 data[1];
342} PACKED;
343
344struct oz_fragmented {
345 u8 app_id;
346 u8 elt_seq_num;
347 u8 type;
348 u8 endpoint;
349 u8 format;
350 u16 total_size;
351 u16 offset;
352 u8 data[1];
353} PACKED;
354
355/* Note: the following does not get packaged in an element in the same way
356 * that other data formats are packaged. Instead the data is put in a frame
357 * directly after the oz_header and is the only permitted data in such a
358 * frame. The length of the data is directly determined from the frame size.
359 */
360struct oz_isoc_large {
361 u8 endpoint;
362 u8 format;
363 u8 ms_data;
364 u8 frame_number;
365} PACKED;
366
367#define OZ_DATA_F_TYPE_MASK 0xF
368#define OZ_DATA_F_MULTIPLE_FIXED 0x1
369#define OZ_DATA_F_MULTIPLE_VAR 0x2
370#define OZ_DATA_F_ISOC_FIXED 0x3
371#define OZ_DATA_F_ISOC_VAR 0x4
372#define OZ_DATA_F_FRAGMENTED 0x5
373#define OZ_DATA_F_ISOC_LARGE 0x7
374
375#endif /* _OZPROTOCOL_H */
diff --git a/drivers/staging/ozwpan/ozurbparanoia.c b/drivers/staging/ozwpan/ozurbparanoia.c
deleted file mode 100644
index cf6278a198a8..000000000000
--- a/drivers/staging/ozwpan/ozurbparanoia.c
+++ /dev/null
@@ -1,54 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
5 */
6#include <linux/usb.h>
7#include "ozdbg.h"
8
9#ifdef WANT_URB_PARANOIA
10
11#include "ozurbparanoia.h"
12
13#define OZ_MAX_URBS 1000
14struct urb *g_urb_memory[OZ_MAX_URBS];
15int g_nb_urbs;
16DEFINE_SPINLOCK(g_urb_mem_lock);
17
18void oz_remember_urb(struct urb *urb)
19{
20 unsigned long irq_state;
21
22 spin_lock_irqsave(&g_urb_mem_lock, irq_state);
23 if (g_nb_urbs < OZ_MAX_URBS) {
24 g_urb_memory[g_nb_urbs++] = urb;
25 oz_dbg(ON, "urb up = %d %p\n", g_nb_urbs, urb);
26 } else {
27 oz_dbg(ON, "ERROR urb buffer full\n");
28 }
29 spin_unlock_irqrestore(&g_urb_mem_lock, irq_state);
30}
31
32/*
33 */
34int oz_forget_urb(struct urb *urb)
35{
36 unsigned long irq_state;
37 int i;
38 int rc = -1;
39
40 spin_lock_irqsave(&g_urb_mem_lock, irq_state);
41 for (i = 0; i < g_nb_urbs; i++) {
42 if (g_urb_memory[i] == urb) {
43 rc = 0;
44 if (--g_nb_urbs > i)
45 memcpy(&g_urb_memory[i], &g_urb_memory[i+1],
46 (g_nb_urbs - i) * sizeof(struct urb *));
47 oz_dbg(ON, "urb down = %d %p\n", g_nb_urbs, urb);
48 }
49 }
50 spin_unlock_irqrestore(&g_urb_mem_lock, irq_state);
51 return rc;
52}
53#endif /* #ifdef WANT_URB_PARANOIA */
54
diff --git a/drivers/staging/ozwpan/ozurbparanoia.h b/drivers/staging/ozwpan/ozurbparanoia.h
deleted file mode 100644
index 5080ea76f507..000000000000
--- a/drivers/staging/ozwpan/ozurbparanoia.h
+++ /dev/null
@@ -1,19 +0,0 @@
1#ifndef _OZURBPARANOIA_H
2#define _OZURBPARANOIA_H
3/* -----------------------------------------------------------------------------
4 * Released under the GNU General Public License Version 2 (GPLv2).
5 * Copyright (c) 2011 Ozmo Inc
6 * -----------------------------------------------------------------------------
7 */
8
9#ifdef WANT_URB_PARANOIA
10void oz_remember_urb(struct urb *urb);
11int oz_forget_urb(struct urb *urb);
12#else
13static inline void oz_remember_urb(struct urb *urb) {}
14static inline int oz_forget_urb(struct urb *urb) { return 0; }
15#endif /* WANT_URB_PARANOIA */
16
17
18#endif /* _OZURBPARANOIA_H */
19
diff --git a/drivers/staging/ozwpan/ozusbif.h b/drivers/staging/ozwpan/ozusbif.h
deleted file mode 100644
index d2a6085345be..000000000000
--- a/drivers/staging/ozwpan/ozusbif.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
5 */
6#ifndef _OZUSBIF_H
7#define _OZUSBIF_H
8
9#include <linux/usb.h>
10
11/* Reference counting functions.
12 */
13void oz_usb_get(void *hpd);
14void oz_usb_put(void *hpd);
15
16/* Stream functions.
17 */
18int oz_usb_stream_create(void *hpd, u8 ep_num);
19int oz_usb_stream_delete(void *hpd, u8 ep_num);
20
21/* Request functions.
22 */
23int oz_usb_control_req(void *hpd, u8 req_id, struct usb_ctrlrequest *setup,
24 const u8 *data, int data_len);
25int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type,
26 u8 index, __le16 windex, int offset, int len);
27int oz_usb_send_isoc(void *hpd, u8 ep_num, struct urb *urb);
28void oz_usb_request_heartbeat(void *hpd);
29
30/* Confirmation functions.
31 */
32void oz_hcd_get_desc_cnf(void *hport, u8 req_id, u8 status,
33 const u8 *desc, u8 length, u16 offset, u16 total_size);
34void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode,
35 const u8 *data, int data_len);
36
37/* Indication functions.
38 */
39void oz_hcd_data_ind(void *hport, u8 endpoint, const u8 *data, int data_len);
40
41int oz_hcd_heartbeat(void *hport);
42
43#endif /* _OZUSBIF_H */
diff --git a/drivers/staging/ozwpan/ozusbsvc.c b/drivers/staging/ozwpan/ozusbsvc.c
deleted file mode 100644
index bf15dc301cb5..000000000000
--- a/drivers/staging/ozwpan/ozusbsvc.c
+++ /dev/null
@@ -1,263 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 *
5 * This file provides protocol independent part of the implementation of the USB
6 * service for a PD.
7 * The implementation of this service is split into two parts the first of which
8 * is protocol independent and the second contains protocol specific details.
9 * This split is to allow alternative protocols to be defined.
10 * The implementation of this service uses ozhcd.c to implement a USB HCD.
11 * -----------------------------------------------------------------------------
12 */
13
14#include <linux/module.h>
15#include <linux/timer.h>
16#include <linux/sched.h>
17#include <linux/netdevice.h>
18#include <linux/errno.h>
19#include <linux/input.h>
20#include <asm/unaligned.h>
21#include "ozdbg.h"
22#include "ozprotocol.h"
23#include "ozeltbuf.h"
24#include "ozpd.h"
25#include "ozproto.h"
26#include "ozusbif.h"
27#include "ozhcd.h"
28#include "ozusbsvc.h"
29
30/*
31 * This is called once when the driver is loaded to initialise the USB service.
32 * Context: process
33 */
34int oz_usb_init(void)
35{
36 return oz_hcd_init();
37}
38
39/*
40 * This is called once when the driver is unloaded to terminate the USB service.
41 * Context: process
42 */
43void oz_usb_term(void)
44{
45 oz_hcd_term();
46}
47
48/*
49 * This is called when the USB service is started or resumed for a PD.
50 * Context: softirq
51 */
52int oz_usb_start(struct oz_pd *pd, int resume)
53{
54 int rc = 0;
55 struct oz_usb_ctx *usb_ctx;
56 struct oz_usb_ctx *old_ctx;
57
58 if (resume) {
59 oz_dbg(ON, "USB service resumed\n");
60 return 0;
61 }
62 oz_dbg(ON, "USB service started\n");
63 /* Create a USB context in case we need one. If we find the PD already
64 * has a USB context then we will destroy it.
65 */
66 usb_ctx = kzalloc(sizeof(struct oz_usb_ctx), GFP_ATOMIC);
67 if (usb_ctx == NULL)
68 return -ENOMEM;
69 atomic_set(&usb_ctx->ref_count, 1);
70 usb_ctx->pd = pd;
71 usb_ctx->stopped = 0;
72 /* Install the USB context if the PD doesn't already have one.
73 * If it does already have one then destroy the one we have just
74 * created.
75 */
76 spin_lock_bh(&pd->app_lock[OZ_APPID_USB]);
77 old_ctx = pd->app_ctx[OZ_APPID_USB];
78 if (old_ctx == NULL)
79 pd->app_ctx[OZ_APPID_USB] = usb_ctx;
80 oz_usb_get(pd->app_ctx[OZ_APPID_USB]);
81 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB]);
82 if (old_ctx) {
83 oz_dbg(ON, "Already have USB context\n");
84 kfree(usb_ctx);
85 usb_ctx = old_ctx;
86 } else if (usb_ctx) {
87 /* Take a reference to the PD. This will be released when
88 * the USB context is destroyed.
89 */
90 oz_pd_get(pd);
91 }
92 /* If we already had a USB context and had obtained a port from
93 * the USB HCD then just reset the port. If we didn't have a port
94 * then report the arrival to the USB HCD so we get one.
95 */
96 if (usb_ctx->hport) {
97 oz_hcd_pd_reset(usb_ctx, usb_ctx->hport);
98 } else {
99 usb_ctx->hport = oz_hcd_pd_arrived(usb_ctx);
100 if (usb_ctx->hport == NULL) {
101 oz_dbg(ON, "USB hub returned null port\n");
102 spin_lock_bh(&pd->app_lock[OZ_APPID_USB]);
103 pd->app_ctx[OZ_APPID_USB] = NULL;
104 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB]);
105 oz_usb_put(usb_ctx);
106 rc = -1;
107 }
108 }
109 oz_usb_put(usb_ctx);
110 return rc;
111}
112
113/*
114 * This is called when the USB service is stopped or paused for a PD.
115 * Context: softirq or process
116 */
117void oz_usb_stop(struct oz_pd *pd, int pause)
118{
119 struct oz_usb_ctx *usb_ctx;
120
121 if (pause) {
122 oz_dbg(ON, "USB service paused\n");
123 return;
124 }
125 spin_lock_bh(&pd->app_lock[OZ_APPID_USB]);
126 usb_ctx = (struct oz_usb_ctx *) pd->app_ctx[OZ_APPID_USB];
127 pd->app_ctx[OZ_APPID_USB] = NULL;
128 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB]);
129 if (usb_ctx) {
130 struct timespec ts, now;
131
132 getnstimeofday(&ts);
133 oz_dbg(ON, "USB service stopping...\n");
134 usb_ctx->stopped = 1;
135 /* At this point the reference count on the usb context should
136 * be 2 - one from when we created it and one from the hcd
137 * which claims a reference. Since stopped = 1 no one else
138 * should get in but someone may already be in. So wait
139 * until they leave but timeout after 1 second.
140 */
141 while ((atomic_read(&usb_ctx->ref_count) > 2)) {
142 getnstimeofday(&now);
143 /*Approx 1 Sec. this is not perfect calculation*/
144 if (now.tv_sec != ts.tv_sec)
145 break;
146 }
147 oz_dbg(ON, "USB service stopped\n");
148 oz_hcd_pd_departed(usb_ctx->hport);
149 /* Release the reference taken in oz_usb_start.
150 */
151 oz_usb_put(usb_ctx);
152 }
153}
154
155/*
156 * This increments the reference count of the context area for a specific PD.
157 * This ensures this context area does not disappear while still in use.
158 * Context: softirq
159 */
160void oz_usb_get(void *hpd)
161{
162 struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd;
163
164 atomic_inc(&usb_ctx->ref_count);
165}
166
167/*
168 * This decrements the reference count of the context area for a specific PD
169 * and destroys the context area if the reference count becomes zero.
170 * Context: irq or process
171 */
172void oz_usb_put(void *hpd)
173{
174 struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd;
175
176 if (atomic_dec_and_test(&usb_ctx->ref_count)) {
177 oz_dbg(ON, "Dealloc USB context\n");
178 oz_pd_put(usb_ctx->pd);
179 kfree(usb_ctx);
180 }
181}
182
183/*
184 * Context: softirq
185 */
186int oz_usb_heartbeat(struct oz_pd *pd)
187{
188 struct oz_usb_ctx *usb_ctx;
189 int rc = 0;
190
191 spin_lock_bh(&pd->app_lock[OZ_APPID_USB]);
192 usb_ctx = (struct oz_usb_ctx *) pd->app_ctx[OZ_APPID_USB];
193 if (usb_ctx)
194 oz_usb_get(usb_ctx);
195 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB]);
196 if (usb_ctx == NULL)
197 return rc;
198 if (usb_ctx->stopped)
199 goto done;
200 if (usb_ctx->hport)
201 if (oz_hcd_heartbeat(usb_ctx->hport))
202 rc = 1;
203done:
204 oz_usb_put(usb_ctx);
205 return rc;
206}
207
208/*
209 * Context: softirq
210 */
211int oz_usb_stream_create(void *hpd, u8 ep_num)
212{
213 struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd;
214 struct oz_pd *pd = usb_ctx->pd;
215
216 oz_dbg(ON, "%s: (0x%x)\n", __func__, ep_num);
217 if (pd->mode & OZ_F_ISOC_NO_ELTS) {
218 oz_isoc_stream_create(pd, ep_num);
219 } else {
220 oz_pd_get(pd);
221 if (oz_elt_stream_create(&pd->elt_buff, ep_num,
222 4*pd->max_tx_size)) {
223 oz_pd_put(pd);
224 return -1;
225 }
226 }
227 return 0;
228}
229
230/*
231 * Context: softirq
232 */
233int oz_usb_stream_delete(void *hpd, u8 ep_num)
234{
235 struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd;
236
237 if (usb_ctx) {
238 struct oz_pd *pd = usb_ctx->pd;
239
240 if (pd) {
241 oz_dbg(ON, "%s: (0x%x)\n", __func__, ep_num);
242 if (pd->mode & OZ_F_ISOC_NO_ELTS) {
243 oz_isoc_stream_delete(pd, ep_num);
244 } else {
245 if (oz_elt_stream_delete(&pd->elt_buff, ep_num))
246 return -1;
247 oz_pd_put(pd);
248 }
249 }
250 }
251 return 0;
252}
253
254/*
255 * Context: softirq or process
256 */
257void oz_usb_request_heartbeat(void *hpd)
258{
259 struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd;
260
261 if (usb_ctx && usb_ctx->pd)
262 oz_pd_request_heartbeat(usb_ctx->pd);
263}
diff --git a/drivers/staging/ozwpan/ozusbsvc.h b/drivers/staging/ozwpan/ozusbsvc.h
deleted file mode 100644
index 58e05a59be31..000000000000
--- a/drivers/staging/ozwpan/ozusbsvc.h
+++ /dev/null
@@ -1,32 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
5 */
6#ifndef _OZUSBSVC_H
7#define _OZUSBSVC_H
8
9/*------------------------------------------------------------------------------
10 * Per PD context info stored in application context area of PD.
11 * This object is reference counted to ensure it doesn't disappear while
12 * still in use.
13 */
14struct oz_usb_ctx {
15 atomic_t ref_count;
16 u8 tx_seq_num;
17 u8 rx_seq_num;
18 struct oz_pd *pd;
19 void *hport;
20 int stopped;
21};
22
23int oz_usb_init(void);
24void oz_usb_term(void);
25int oz_usb_start(struct oz_pd *pd, int resume);
26void oz_usb_stop(struct oz_pd *pd, int pause);
27void oz_usb_rx(struct oz_pd *pd, struct oz_elt *elt);
28int oz_usb_heartbeat(struct oz_pd *pd);
29void oz_usb_farewell(struct oz_pd *pd, u8 ep_num, u8 *data, u8 len);
30
31#endif /* _OZUSBSVC_H */
32
diff --git a/drivers/staging/ozwpan/ozusbsvc1.c b/drivers/staging/ozwpan/ozusbsvc1.c
deleted file mode 100644
index 301fee8625ed..000000000000
--- a/drivers/staging/ozwpan/ozusbsvc1.c
+++ /dev/null
@@ -1,471 +0,0 @@
1/* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 *
5 * This file implements the protocol specific parts of the USB service for a PD.
6 * -----------------------------------------------------------------------------
7 */
8#include <linux/module.h>
9#include <linux/timer.h>
10#include <linux/sched.h>
11#include <linux/netdevice.h>
12#include <linux/errno.h>
13#include <linux/input.h>
14#include <asm/unaligned.h>
15#include "ozdbg.h"
16#include "ozprotocol.h"
17#include "ozeltbuf.h"
18#include "ozpd.h"
19#include "ozproto.h"
20#include "ozusbif.h"
21#include "ozhcd.h"
22#include "ozusbsvc.h"
23
24#define MAX_ISOC_FIXED_DATA (253-sizeof(struct oz_isoc_fixed))
25
26/*
27 * Context: softirq
28 */
29static int oz_usb_submit_elt(struct oz_elt_buf *eb, struct oz_elt_info *ei,
30 struct oz_usb_ctx *usb_ctx, u8 strid, u8 isoc)
31{
32 int ret;
33 struct oz_elt *elt = (struct oz_elt *)ei->data;
34 struct oz_app_hdr *app_hdr = (struct oz_app_hdr *)(elt+1);
35
36 elt->type = OZ_ELT_APP_DATA;
37 ei->app_id = OZ_APPID_USB;
38 ei->length = elt->length + sizeof(struct oz_elt);
39 app_hdr->app_id = OZ_APPID_USB;
40 spin_lock_bh(&eb->lock);
41 if (isoc == 0) {
42 app_hdr->elt_seq_num = usb_ctx->tx_seq_num++;
43 if (usb_ctx->tx_seq_num == 0)
44 usb_ctx->tx_seq_num = 1;
45 }
46 ret = oz_queue_elt_info(eb, isoc, strid, ei);
47 if (ret)
48 oz_elt_info_free(eb, ei);
49 spin_unlock_bh(&eb->lock);
50 return ret;
51}
52
53/*
54 * Context: softirq
55 */
56int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type,
57 u8 index, __le16 windex, int offset, int len)
58{
59 struct oz_usb_ctx *usb_ctx = hpd;
60 struct oz_pd *pd = usb_ctx->pd;
61 struct oz_elt *elt;
62 struct oz_get_desc_req *body;
63 struct oz_elt_buf *eb = &pd->elt_buff;
64 struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff);
65
66 oz_dbg(ON, " req_type = 0x%x\n", req_type);
67 oz_dbg(ON, " desc_type = 0x%x\n", desc_type);
68 oz_dbg(ON, " index = 0x%x\n", index);
69 oz_dbg(ON, " windex = 0x%x\n", windex);
70 oz_dbg(ON, " offset = 0x%x\n", offset);
71 oz_dbg(ON, " len = 0x%x\n", len);
72 if (len > 200)
73 len = 200;
74 if (ei == NULL)
75 return -1;
76 elt = (struct oz_elt *)ei->data;
77 elt->length = sizeof(struct oz_get_desc_req);
78 body = (struct oz_get_desc_req *)(elt+1);
79 body->type = OZ_GET_DESC_REQ;
80 body->req_id = req_id;
81 put_unaligned(cpu_to_le16(offset), &body->offset);
82 put_unaligned(cpu_to_le16(len), &body->size);
83 body->req_type = req_type;
84 body->desc_type = desc_type;
85 body->w_index = windex;
86 body->index = index;
87 return oz_usb_submit_elt(eb, ei, usb_ctx, 0, 0);
88}
89
90/*
91 * Context: tasklet
92 */
93static int oz_usb_set_config_req(void *hpd, u8 req_id, u8 index)
94{
95 struct oz_usb_ctx *usb_ctx = hpd;
96 struct oz_pd *pd = usb_ctx->pd;
97 struct oz_elt *elt;
98 struct oz_elt_buf *eb = &pd->elt_buff;
99 struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff);
100 struct oz_set_config_req *body;
101
102 if (ei == NULL)
103 return -1;
104 elt = (struct oz_elt *)ei->data;
105 elt->length = sizeof(struct oz_set_config_req);
106 body = (struct oz_set_config_req *)(elt+1);
107 body->type = OZ_SET_CONFIG_REQ;
108 body->req_id = req_id;
109 body->index = index;
110 return oz_usb_submit_elt(eb, ei, usb_ctx, 0, 0);
111}
112
113/*
114 * Context: tasklet
115 */
116static int oz_usb_set_interface_req(void *hpd, u8 req_id, u8 index, u8 alt)
117{
118 struct oz_usb_ctx *usb_ctx = hpd;
119 struct oz_pd *pd = usb_ctx->pd;
120 struct oz_elt *elt;
121 struct oz_elt_buf *eb = &pd->elt_buff;
122 struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff);
123 struct oz_set_interface_req *body;
124
125 if (ei == NULL)
126 return -1;
127 elt = (struct oz_elt *)ei->data;
128 elt->length = sizeof(struct oz_set_interface_req);
129 body = (struct oz_set_interface_req *)(elt+1);
130 body->type = OZ_SET_INTERFACE_REQ;
131 body->req_id = req_id;
132 body->index = index;
133 body->alternative = alt;
134 return oz_usb_submit_elt(eb, ei, usb_ctx, 0, 0);
135}
136
137/*
138 * Context: tasklet
139 */
140static int oz_usb_set_clear_feature_req(void *hpd, u8 req_id, u8 type,
141 u8 recipient, u8 index, __le16 feature)
142{
143 struct oz_usb_ctx *usb_ctx = hpd;
144 struct oz_pd *pd = usb_ctx->pd;
145 struct oz_elt *elt;
146 struct oz_elt_buf *eb = &pd->elt_buff;
147 struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff);
148 struct oz_feature_req *body;
149
150 if (ei == NULL)
151 return -1;
152 elt = (struct oz_elt *)ei->data;
153 elt->length = sizeof(struct oz_feature_req);
154 body = (struct oz_feature_req *)(elt+1);
155 body->type = type;
156 body->req_id = req_id;
157 body->recipient = recipient;
158 body->index = index;
159 put_unaligned(feature, &body->feature);
160 return oz_usb_submit_elt(eb, ei, usb_ctx, 0, 0);
161}
162
163/*
164 * Context: tasklet
165 */
166static int oz_usb_vendor_class_req(void *hpd, u8 req_id, u8 req_type,
167 u8 request, __le16 value, __le16 index, const u8 *data, int data_len)
168{
169 struct oz_usb_ctx *usb_ctx = hpd;
170 struct oz_pd *pd = usb_ctx->pd;
171 struct oz_elt *elt;
172 struct oz_elt_buf *eb = &pd->elt_buff;
173 struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff);
174 struct oz_vendor_class_req *body;
175
176 if (ei == NULL)
177 return -1;
178 elt = (struct oz_elt *)ei->data;
179 elt->length = sizeof(struct oz_vendor_class_req) - 1 + data_len;
180 body = (struct oz_vendor_class_req *)(elt+1);
181 body->type = OZ_VENDOR_CLASS_REQ;
182 body->req_id = req_id;
183 body->req_type = req_type;
184 body->request = request;
185 put_unaligned(value, &body->value);
186 put_unaligned(index, &body->index);
187 if (data_len)
188 memcpy(body->data, data, data_len);
189 return oz_usb_submit_elt(eb, ei, usb_ctx, 0, 0);
190}
191
192/*
193 * Context: tasklet
194 */
195int oz_usb_control_req(void *hpd, u8 req_id, struct usb_ctrlrequest *setup,
196 const u8 *data, int data_len)
197{
198 unsigned wvalue = le16_to_cpu(setup->wValue);
199 unsigned windex = le16_to_cpu(setup->wIndex);
200 unsigned wlength = le16_to_cpu(setup->wLength);
201 int rc = 0;
202
203 if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
204 switch (setup->bRequest) {
205 case USB_REQ_GET_DESCRIPTOR:
206 rc = oz_usb_get_desc_req(hpd, req_id,
207 setup->bRequestType, (u8)(wvalue>>8),
208 (u8)wvalue, setup->wIndex, 0, wlength);
209 break;
210 case USB_REQ_SET_CONFIGURATION:
211 rc = oz_usb_set_config_req(hpd, req_id, (u8)wvalue);
212 break;
213 case USB_REQ_SET_INTERFACE: {
214 u8 if_num = (u8)windex;
215 u8 alt = (u8)wvalue;
216
217 rc = oz_usb_set_interface_req(hpd, req_id,
218 if_num, alt);
219 }
220 break;
221 case USB_REQ_SET_FEATURE:
222 rc = oz_usb_set_clear_feature_req(hpd, req_id,
223 OZ_SET_FEATURE_REQ,
224 setup->bRequestType & 0xf, (u8)windex,
225 setup->wValue);
226 break;
227 case USB_REQ_CLEAR_FEATURE:
228 rc = oz_usb_set_clear_feature_req(hpd, req_id,
229 OZ_CLEAR_FEATURE_REQ,
230 setup->bRequestType & 0xf,
231 (u8)windex, setup->wValue);
232 break;
233 }
234 } else {
235 rc = oz_usb_vendor_class_req(hpd, req_id, setup->bRequestType,
236 setup->bRequest, setup->wValue, setup->wIndex,
237 data, data_len);
238 }
239 return rc;
240}
241
242/*
243 * Context: softirq
244 */
245int oz_usb_send_isoc(void *hpd, u8 ep_num, struct urb *urb)
246{
247 struct oz_usb_ctx *usb_ctx = hpd;
248 struct oz_pd *pd = usb_ctx->pd;
249 struct oz_elt_buf *eb;
250 int i;
251 int hdr_size;
252 u8 *data;
253 struct usb_iso_packet_descriptor *desc;
254
255 if (pd->mode & OZ_F_ISOC_NO_ELTS) {
256 for (i = 0; i < urb->number_of_packets; i++) {
257 u8 *data;
258
259 desc = &urb->iso_frame_desc[i];
260 data = ((u8 *)urb->transfer_buffer)+desc->offset;
261 oz_send_isoc_unit(pd, ep_num, data, desc->length);
262 }
263 return 0;
264 }
265
266 hdr_size = sizeof(struct oz_isoc_fixed) - 1;
267 eb = &pd->elt_buff;
268 i = 0;
269 while (i < urb->number_of_packets) {
270 struct oz_elt_info *ei = oz_elt_info_alloc(eb);
271 struct oz_elt *elt;
272 struct oz_isoc_fixed *body;
273 int unit_count;
274 int unit_size;
275 int rem;
276
277 if (ei == NULL)
278 return -1;
279 rem = MAX_ISOC_FIXED_DATA;
280 elt = (struct oz_elt *)ei->data;
281 body = (struct oz_isoc_fixed *)(elt + 1);
282 body->type = OZ_USB_ENDPOINT_DATA;
283 body->endpoint = ep_num;
284 body->format = OZ_DATA_F_ISOC_FIXED;
285 unit_size = urb->iso_frame_desc[i].length;
286 body->unit_size = (u8)unit_size;
287 data = ((u8 *)(elt+1)) + hdr_size;
288 unit_count = 0;
289 while (i < urb->number_of_packets) {
290 desc = &urb->iso_frame_desc[i];
291 if ((unit_size == desc->length) &&
292 (desc->length <= rem)) {
293 memcpy(data, ((u8 *)urb->transfer_buffer) +
294 desc->offset, unit_size);
295 data += unit_size;
296 rem -= unit_size;
297 unit_count++;
298 desc->status = 0;
299 desc->actual_length = desc->length;
300 i++;
301 } else {
302 break;
303 }
304 }
305 elt->length = hdr_size + MAX_ISOC_FIXED_DATA - rem;
306 /* Store the number of units in body->frame_number for the
307 * moment. This field will be correctly determined before
308 * the element is sent. */
309 body->frame_number = (u8)unit_count;
310 oz_usb_submit_elt(eb, ei, usb_ctx, ep_num,
311 pd->mode & OZ_F_ISOC_ANYTIME);
312 }
313 return 0;
314}
315
316/*
317 * Context: softirq-serialized
318 */
319static void oz_usb_handle_ep_data(struct oz_usb_ctx *usb_ctx,
320 struct oz_usb_hdr *usb_hdr, int len)
321{
322 struct oz_data *data_hdr = (struct oz_data *)usb_hdr;
323
324 switch (data_hdr->format) {
325 case OZ_DATA_F_MULTIPLE_FIXED: {
326 struct oz_multiple_fixed *body =
327 (struct oz_multiple_fixed *)data_hdr;
328 u8 *data = body->data;
329 unsigned int n;
330 if (!body->unit_size ||
331 len < sizeof(struct oz_multiple_fixed) - 1)
332 break;
333 n = (len - (sizeof(struct oz_multiple_fixed) - 1))
334 / body->unit_size;
335 while (n--) {
336 oz_hcd_data_ind(usb_ctx->hport, body->endpoint,
337 data, body->unit_size);
338 data += body->unit_size;
339 }
340 }
341 break;
342 case OZ_DATA_F_ISOC_FIXED: {
343 struct oz_isoc_fixed *body =
344 (struct oz_isoc_fixed *)data_hdr;
345 int data_len;
346 int unit_size = body->unit_size;
347 u8 *data = body->data;
348 int count;
349 int i;
350
351 if (len < sizeof(struct oz_isoc_fixed) - 1)
352 break;
353 data_len = len - (sizeof(struct oz_isoc_fixed) - 1);
354
355 if (!unit_size)
356 break;
357 count = data_len/unit_size;
358 for (i = 0; i < count; i++) {
359 oz_hcd_data_ind(usb_ctx->hport,
360 body->endpoint, data, unit_size);
361 data += unit_size;
362 }
363 }
364 break;
365 }
366
367}
368
369/*
370 * This is called when the PD has received a USB element. The type of element
371 * is determined and is then passed to an appropriate handler function.
372 * Context: softirq-serialized
373 */
374void oz_usb_rx(struct oz_pd *pd, struct oz_elt *elt)
375{
376 struct oz_usb_hdr *usb_hdr = (struct oz_usb_hdr *)(elt + 1);
377 struct oz_usb_ctx *usb_ctx;
378
379 spin_lock_bh(&pd->app_lock[OZ_APPID_USB]);
380 usb_ctx = (struct oz_usb_ctx *)pd->app_ctx[OZ_APPID_USB];
381 if (usb_ctx)
382 oz_usb_get(usb_ctx);
383 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB]);
384 if (usb_ctx == NULL)
385 return; /* Context has gone so nothing to do. */
386 if (usb_ctx->stopped)
387 goto done;
388 /* If sequence number is non-zero then check it is not a duplicate.
389 * Zero sequence numbers are always accepted.
390 */
391 if (usb_hdr->elt_seq_num != 0) {
392 if (((usb_ctx->rx_seq_num - usb_hdr->elt_seq_num) & 0x80) == 0)
393 /* Reject duplicate element. */
394 goto done;
395 }
396 usb_ctx->rx_seq_num = usb_hdr->elt_seq_num;
397 switch (usb_hdr->type) {
398 case OZ_GET_DESC_RSP: {
399 struct oz_get_desc_rsp *body =
400 (struct oz_get_desc_rsp *)usb_hdr;
401 u16 offs, total_size;
402 u8 data_len;
403
404 if (elt->length < sizeof(struct oz_get_desc_rsp) - 1)
405 break;
406 data_len = elt->length -
407 (sizeof(struct oz_get_desc_rsp) - 1);
408 offs = le16_to_cpu(get_unaligned(&body->offset));
409 total_size =
410 le16_to_cpu(get_unaligned(&body->total_size));
411 oz_dbg(ON, "USB_REQ_GET_DESCRIPTOR - cnf\n");
412 oz_hcd_get_desc_cnf(usb_ctx->hport, body->req_id,
413 body->rcode, body->data,
414 data_len, offs, total_size);
415 }
416 break;
417 case OZ_SET_CONFIG_RSP: {
418 struct oz_set_config_rsp *body =
419 (struct oz_set_config_rsp *)usb_hdr;
420 oz_hcd_control_cnf(usb_ctx->hport, body->req_id,
421 body->rcode, NULL, 0);
422 }
423 break;
424 case OZ_SET_INTERFACE_RSP: {
425 struct oz_set_interface_rsp *body =
426 (struct oz_set_interface_rsp *)usb_hdr;
427 oz_hcd_control_cnf(usb_ctx->hport,
428 body->req_id, body->rcode, NULL, 0);
429 }
430 break;
431 case OZ_VENDOR_CLASS_RSP: {
432 struct oz_vendor_class_rsp *body =
433 (struct oz_vendor_class_rsp *)usb_hdr;
434
435 if (elt->length <
436 sizeof(struct oz_vendor_class_rsp) - 1)
437 break;
438
439 oz_hcd_control_cnf(usb_ctx->hport, body->req_id,
440 body->rcode, body->data, elt->length-
441 sizeof(struct oz_vendor_class_rsp)+1);
442 }
443 break;
444 case OZ_USB_ENDPOINT_DATA:
445 oz_usb_handle_ep_data(usb_ctx, usb_hdr, elt->length);
446 break;
447 }
448done:
449 oz_usb_put(usb_ctx);
450}
451
452/*
453 * Context: softirq, process
454 */
455void oz_usb_farewell(struct oz_pd *pd, u8 ep_num, u8 *data, u8 len)
456{
457 struct oz_usb_ctx *usb_ctx;
458
459 spin_lock_bh(&pd->app_lock[OZ_APPID_USB]);
460 usb_ctx = (struct oz_usb_ctx *)pd->app_ctx[OZ_APPID_USB];
461 if (usb_ctx)
462 oz_usb_get(usb_ctx);
463 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB]);
464 if (usb_ctx == NULL)
465 return; /* Context has gone so nothing to do. */
466 if (!usb_ctx->stopped) {
467 oz_dbg(ON, "Farewell indicated ep = 0x%x\n", ep_num);
468 oz_hcd_data_ind(usb_ctx->hport, ep_num, data, len);
469 }
470 oz_usb_put(usb_ctx);
471}
diff --git a/drivers/staging/panel/panel.c b/drivers/staging/panel/panel.c
index bda208da514e..3e9ee7ee6be2 100644
--- a/drivers/staging/panel/panel.c
+++ b/drivers/staging/panel/panel.c
@@ -781,14 +781,18 @@ static void long_sleep(int ms)
781 schedule_timeout_interruptible(msecs_to_jiffies(ms)); 781 schedule_timeout_interruptible(msecs_to_jiffies(ms));
782} 782}
783 783
784/* send a serial byte to the LCD panel. The caller is responsible for locking 784/*
785 if needed. */ 785 * send a serial byte to the LCD panel. The caller is responsible for locking
786 * if needed.
787 */
786static void lcd_send_serial(int byte) 788static void lcd_send_serial(int byte)
787{ 789{
788 int bit; 790 int bit;
789 791
790 /* the data bit is set on D0, and the clock on STROBE. 792 /*
791 * LCD reads D0 on STROBE's rising edge. */ 793 * the data bit is set on D0, and the clock on STROBE.
794 * LCD reads D0 on STROBE's rising edge.
795 */
792 for (bit = 0; bit < 8; bit++) { 796 for (bit = 0; bit < 8; bit++) {
793 bits.cl = BIT_CLR; /* CLK low */ 797 bits.cl = BIT_CLR; /* CLK low */
794 panel_set_bits(); 798 panel_set_bits();
diff --git a/drivers/staging/rtl8188eu/core/rtw_ap.c b/drivers/staging/rtl8188eu/core/rtw_ap.c
index 581af88e3024..5c45f8a8c2cf 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ap.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ap.c
@@ -379,7 +379,8 @@ void expire_timeout_chk(struct adapter *padapter)
379 if (pmlmeext->active_keep_alive_check) { 379 if (pmlmeext->active_keep_alive_check) {
380 int stainfo_offset; 380 int stainfo_offset;
381 381
382 stainfo_offset = rtw_stainfo_offset(pstapriv, psta); 382 stainfo_offset =
383 rtw_stainfo_offset(pstapriv, psta);
383 if (stainfo_offset_valid(stainfo_offset)) 384 if (stainfo_offset_valid(stainfo_offset))
384 chk_alive_list[chk_alive_num++] = stainfo_offset; 385 chk_alive_list[chk_alive_num++] = stainfo_offset;
385 continue; 386 continue;
@@ -1584,7 +1585,7 @@ void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta)
1584 } 1585 }
1585 } 1586 }
1586 1587
1587 if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT)) { 1588 if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)) {
1588 if (!psta->no_short_slot_time_set) { 1589 if (!psta->no_short_slot_time_set) {
1589 psta->no_short_slot_time_set = 1; 1590 psta->no_short_slot_time_set = 1;
1590 1591
diff --git a/drivers/staging/rtl8188eu/core/rtw_debug.c b/drivers/staging/rtl8188eu/core/rtw_debug.c
index bc3fe10ff247..993c7db87a1a 100644
--- a/drivers/staging/rtl8188eu/core/rtw_debug.c
+++ b/drivers/staging/rtl8188eu/core/rtw_debug.c
@@ -219,6 +219,7 @@ int proc_get_ht_option(char *page, char **start,
219 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 219 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
220 220
221 int len = 0; 221 int len = 0;
222
222 len += snprintf(page + len, count - len, "ht_option=%d\n", pmlmepriv->htpriv.ht_option); 223 len += snprintf(page + len, count - len, "ht_option=%d\n", pmlmepriv->htpriv.ht_option);
223 *eof = 1; 224 *eof = 1;
224 return len; 225 return len;
@@ -588,6 +589,7 @@ int proc_set_rx_signal(struct file *file, const char __user *buffer,
588 589
589 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) { 590 if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
590 int num = sscanf(tmp, "%u %u", &is_signal_dbg, &signal_strength); 591 int num = sscanf(tmp, "%u %u", &is_signal_dbg, &signal_strength);
592
591 is_signal_dbg = is_signal_dbg == 0 ? 0 : 1; 593 is_signal_dbg = is_signal_dbg == 0 ? 0 : 1;
592 if (is_signal_dbg && num != 2) 594 if (is_signal_dbg && num != 2)
593 return count; 595 return count;
@@ -917,7 +919,7 @@ int proc_get_best_channel(char *page, char **start,
917 /* 5G */ 919 /* 5G */
918 if (pmlmeext->channel_set[i].ChannelNum >= 36 && 920 if (pmlmeext->channel_set[i].ChannelNum >= 36 &&
919 pmlmeext->channel_set[i].ChannelNum < 140) { 921 pmlmeext->channel_set[i].ChannelNum < 140) {
920 /* Find primary channel */ 922 /* Find primary channel */
921 if (((pmlmeext->channel_set[i].ChannelNum - 36) % 8 == 0) && 923 if (((pmlmeext->channel_set[i].ChannelNum - 36) % 8 == 0) &&
922 (pmlmeext->channel_set[i].rx_count < pmlmeext->channel_set[index_5G].rx_count)) { 924 (pmlmeext->channel_set[i].rx_count < pmlmeext->channel_set[index_5G].rx_count)) {
923 index_5G = i; 925 index_5G = i;
@@ -927,7 +929,7 @@ int proc_get_best_channel(char *page, char **start,
927 929
928 if (pmlmeext->channel_set[i].ChannelNum >= 149 && 930 if (pmlmeext->channel_set[i].ChannelNum >= 149 &&
929 pmlmeext->channel_set[i].ChannelNum < 165) { 931 pmlmeext->channel_set[i].ChannelNum < 165) {
930 /* find primary channel */ 932 /* find primary channel */
931 if (((pmlmeext->channel_set[i].ChannelNum - 149) % 8 == 0) && 933 if (((pmlmeext->channel_set[i].ChannelNum - 149) % 8 == 0) &&
932 (pmlmeext->channel_set[i].rx_count < pmlmeext->channel_set[index_5G].rx_count)) { 934 (pmlmeext->channel_set[i].rx_count < pmlmeext->channel_set[index_5G].rx_count)) {
933 index_5G = i; 935 index_5G = i;
diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c b/drivers/staging/rtl8188eu/core/rtw_efuse.c
index dbaba2c6cce5..7b99ea91a9e6 100644
--- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
+++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
@@ -551,7 +551,7 @@ int Efuse_PgPacketRead(struct adapter *pAdapter, u8 offset, u8 *data)
551 bContinual = false; 551 bContinual = false;
552 } 552 }
553 } else if (ReadState & PG_STATE_DATA) { 553 } else if (ReadState & PG_STATE_DATA) {
554 /* Data section Read ------------- */ 554 /* Data section Read ------------- */
555 efuse_WordEnableDataRead(hworden, tmpdata, data); 555 efuse_WordEnableDataRead(hworden, tmpdata, data);
556 efuse_addr = efuse_addr + (word_cnts*2)+1; 556 efuse_addr = efuse_addr + (word_cnts*2)+1;
557 ReadState = PG_STATE_HEADER; 557 ReadState = PG_STATE_HEADER;
diff --git a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
index 11b780d6c4ab..c3c582881a09 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
@@ -19,6 +19,8 @@
19 ******************************************************************************/ 19 ******************************************************************************/
20#define _IEEE80211_C 20#define _IEEE80211_C
21 21
22#include <linux/ieee80211.h>
23
22#include <drv_types.h> 24#include <drv_types.h>
23#include <osdep_intf.h> 25#include <osdep_intf.h>
24#include <ieee80211.h> 26#include <ieee80211.h>
@@ -1042,7 +1044,7 @@ enum parse_res rtw_ieee802_11_parse_elems(u8 *start, uint len,
1042 elems->timeout_int = pos; 1044 elems->timeout_int = pos;
1043 elems->timeout_int_len = elen; 1045 elems->timeout_int_len = elen;
1044 break; 1046 break;
1045 case WLAN_EID_HT_CAP: 1047 case WLAN_EID_HT_CAPABILITY:
1046 elems->ht_capabilities = pos; 1048 elems->ht_capabilities = pos;
1047 elems->ht_capabilities_len = elen; 1049 elems->ht_capabilities_len = elen;
1048 break; 1050 break;
diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
index 8c05cb021c46..22f5b45f5f7f 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
@@ -183,7 +183,7 @@ u8 rtw_set_802_11_bssid(struct adapter *padapter, u8 *bssid)
183 if (check_fwstate(pmlmepriv, _FW_LINKED) == true) 183 if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
184 rtw_indicate_disconnect(padapter); 184 rtw_indicate_disconnect(padapter);
185 185
186 rtw_free_assoc_resources(padapter, 1); 186 rtw_free_assoc_resources(padapter);
187 187
188 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) { 188 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) {
189 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE); 189 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
@@ -271,7 +271,7 @@ u8 rtw_set_802_11_ssid(struct adapter *padapter, struct ndis_802_11_ssid *ssid)
271 if (check_fwstate(pmlmepriv, _FW_LINKED) == true) 271 if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
272 rtw_indicate_disconnect(padapter); 272 rtw_indicate_disconnect(padapter);
273 273
274 rtw_free_assoc_resources(padapter, 1); 274 rtw_free_assoc_resources(padapter);
275 275
276 if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) { 276 if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) {
277 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE); 277 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
@@ -293,7 +293,7 @@ u8 rtw_set_802_11_ssid(struct adapter *padapter, struct ndis_802_11_ssid *ssid)
293 if (check_fwstate(pmlmepriv, _FW_LINKED) == true) 293 if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
294 rtw_indicate_disconnect(padapter); 294 rtw_indicate_disconnect(padapter);
295 295
296 rtw_free_assoc_resources(padapter, 1); 296 rtw_free_assoc_resources(padapter);
297 297
298 if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) { 298 if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) {
299 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE); 299 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
@@ -366,7 +366,7 @@ u8 rtw_set_802_11_infrastructure_mode(struct adapter *padapter,
366 366
367 if ((check_fwstate(pmlmepriv, _FW_LINKED)) || 367 if ((check_fwstate(pmlmepriv, _FW_LINKED)) ||
368 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))) 368 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)))
369 rtw_free_assoc_resources(padapter, 1); 369 rtw_free_assoc_resources(padapter);
370 370
371 if ((*pold_state == Ndis802_11Infrastructure) || (*pold_state == Ndis802_11IBSS)) { 371 if ((*pold_state == Ndis802_11Infrastructure) || (*pold_state == Ndis802_11IBSS)) {
372 if (check_fwstate(pmlmepriv, _FW_LINKED) == true) 372 if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
@@ -415,7 +415,7 @@ u8 rtw_set_802_11_disassociate(struct adapter *padapter)
415 415
416 rtw_disassoc_cmd(padapter, 0, true); 416 rtw_disassoc_cmd(padapter, 0, true);
417 rtw_indicate_disconnect(padapter); 417 rtw_indicate_disconnect(padapter);
418 rtw_free_assoc_resources(padapter, 1); 418 rtw_free_assoc_resources(padapter);
419 rtw_pwr_wakeup(padapter); 419 rtw_pwr_wakeup(padapter);
420 } 420 }
421 421
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c b/drivers/staging/rtl8188eu/core/rtw_mlme.c
index 05584515c5b4..2b917a18e228 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
@@ -19,6 +19,7 @@
19 ******************************************************************************/ 19 ******************************************************************************/
20#define _RTW_MLME_C_ 20#define _RTW_MLME_C_
21 21
22#include <linux/ieee80211.h>
22 23
23#include <osdep_service.h> 24#include <osdep_service.h>
24#include <drv_types.h> 25#include <drv_types.h>
@@ -160,7 +161,7 @@ exit:
160 return pnetwork; 161 return pnetwork;
161} 162}
162 163
163static void _rtw_free_network(struct mlme_priv *pmlmepriv , struct wlan_network *pnetwork, u8 isfreeall) 164static void _rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 isfreeall)
164{ 165{
165 u32 curr_time, delta_time; 166 u32 curr_time, delta_time;
166 u32 lifetime = SCANQUEUE_LIFETIME; 167 u32 lifetime = SCANQUEUE_LIFETIME;
@@ -352,8 +353,8 @@ int is_same_network(struct wlan_bssid_ex *src, struct wlan_bssid_ex *dst)
352 ((!memcmp(src->Ssid.Ssid, dst->Ssid.Ssid, src->Ssid.SsidLength)) == true) && 353 ((!memcmp(src->Ssid.Ssid, dst->Ssid.Ssid, src->Ssid.SsidLength)) == true) &&
353 ((s_cap & WLAN_CAPABILITY_IBSS) == 354 ((s_cap & WLAN_CAPABILITY_IBSS) ==
354 (d_cap & WLAN_CAPABILITY_IBSS)) && 355 (d_cap & WLAN_CAPABILITY_IBSS)) &&
355 ((s_cap & WLAN_CAPABILITY_BSS) == 356 ((s_cap & WLAN_CAPABILITY_ESS) ==
356 (d_cap & WLAN_CAPABILITY_BSS))); 357 (d_cap & WLAN_CAPABILITY_ESS)));
357} 358}
358 359
359struct wlan_network *rtw_get_oldest_wlan_network(struct __queue *scanned_queue) 360struct wlan_network *rtw_get_oldest_wlan_network(struct __queue *scanned_queue)
@@ -581,7 +582,7 @@ static int rtw_is_desired_network(struct adapter *adapter, struct wlan_network *
581} 582}
582 583
583/* TODO: Perry: For Power Management */ 584/* TODO: Perry: For Power Management */
584void rtw_atimdone_event_callback(struct adapter *adapter , u8 *pbuf) 585void rtw_atimdone_event_callback(struct adapter *adapter, u8 *pbuf)
585{ 586{
586 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("receive atimdone_evet\n")); 587 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("receive atimdone_evet\n"));
587 return; 588 return;
@@ -614,7 +615,7 @@ void rtw_survey_event_callback(struct adapter *adapter, u8 *pbuf)
614 spin_lock_bh(&(pmlmepriv->scanned_queue.lock)); 615 spin_lock_bh(&(pmlmepriv->scanned_queue.lock));
615 ibss_wlan = rtw_find_network(&pmlmepriv->scanned_queue, pnetwork->MacAddress); 616 ibss_wlan = rtw_find_network(&pmlmepriv->scanned_queue, pnetwork->MacAddress);
616 if (ibss_wlan) { 617 if (ibss_wlan) {
617 memcpy(ibss_wlan->network.IEs , pnetwork->IEs, 8); 618 memcpy(ibss_wlan->network.IEs, pnetwork->IEs, 8);
618 spin_unlock_bh(&pmlmepriv->scanned_queue.lock); 619 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
619 goto exit; 620 goto exit;
620 } 621 }
@@ -692,8 +693,8 @@ void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf)
692 pmlmepriv->to_join = false; 693 pmlmepriv->to_join = false;
693 s_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv); 694 s_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv);
694 if (_SUCCESS == s_ret) { 695 if (_SUCCESS == s_ret) {
695 mod_timer(&pmlmepriv->assoc_timer, 696 mod_timer(&pmlmepriv->assoc_timer,
696 jiffies + msecs_to_jiffies(MAX_JOIN_TIMEOUT)); 697 jiffies + msecs_to_jiffies(MAX_JOIN_TIMEOUT));
697 } else if (s_ret == 2) { /* there is no need to wait for join */ 698 } else if (s_ret == 2) { /* there is no need to wait for join */
698 _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING); 699 _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
699 rtw_indicate_connect(adapter); 700 rtw_indicate_connect(adapter);
@@ -703,7 +704,7 @@ void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf)
703 if (--pmlmepriv->to_roaming == 0 || 704 if (--pmlmepriv->to_roaming == 0 ||
704 _SUCCESS != rtw_sitesurvey_cmd(adapter, &pmlmepriv->assoc_ssid, 1, NULL, 0)) { 705 _SUCCESS != rtw_sitesurvey_cmd(adapter, &pmlmepriv->assoc_ssid, 1, NULL, 0)) {
705 pmlmepriv->to_roaming = 0; 706 pmlmepriv->to_roaming = 0;
706 rtw_free_assoc_resources(adapter, 1); 707 rtw_free_assoc_resources(adapter);
707 rtw_indicate_disconnect(adapter); 708 rtw_indicate_disconnect(adapter);
708 } else { 709 } else {
709 pmlmepriv->to_join = true; 710 pmlmepriv->to_join = true;
@@ -757,7 +758,19 @@ static void free_scanqueue(struct mlme_priv *pmlmepriv)
757/* 758/*
758*rtw_free_assoc_resources: the caller has to lock pmlmepriv->lock 759*rtw_free_assoc_resources: the caller has to lock pmlmepriv->lock
759*/ 760*/
760void rtw_free_assoc_resources(struct adapter *adapter, int lock_scanned_queue) 761void rtw_free_assoc_resources(struct adapter *adapter)
762{
763 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
764
765 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
766 rtw_free_assoc_resources_locked(adapter);
767 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
768}
769
770/*
771*rtw_free_assoc_resources_locked: the caller has to lock pmlmepriv->lock
772*/
773void rtw_free_assoc_resources_locked(struct adapter *adapter)
761{ 774{
762 struct wlan_network *pwlan = NULL; 775 struct wlan_network *pwlan = NULL;
763 struct mlme_priv *pmlmepriv = &adapter->mlmepriv; 776 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
@@ -792,8 +805,6 @@ void rtw_free_assoc_resources(struct adapter *adapter, int lock_scanned_queue)
792 rtw_init_bcmc_stainfo(adapter); 805 rtw_init_bcmc_stainfo(adapter);
793 } 806 }
794 807
795 if (lock_scanned_queue)
796 spin_lock_bh(&(pmlmepriv->scanned_queue.lock));
797 808
798 pwlan = rtw_find_network(&pmlmepriv->scanned_queue, tgt_network->network.MacAddress); 809 pwlan = rtw_find_network(&pmlmepriv->scanned_queue, tgt_network->network.MacAddress);
799 if (pwlan) 810 if (pwlan)
@@ -804,8 +815,6 @@ void rtw_free_assoc_resources(struct adapter *adapter, int lock_scanned_queue)
804 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) && (adapter->stapriv.asoc_sta_count == 1))) 815 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) && (adapter->stapriv.asoc_sta_count == 1)))
805 rtw_free_network_nolock(pmlmepriv, pwlan); 816 rtw_free_network_nolock(pmlmepriv, pwlan);
806 817
807 if (lock_scanned_queue)
808 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
809 pmlmepriv->key_mask = 0; 818 pmlmepriv->key_mask = 0;
810} 819}
811 820
@@ -1301,7 +1310,7 @@ void rtw_stadel_event_callback(struct adapter *adapter, u8 *pbuf)
1301 1310
1302 rtw_free_uc_swdec_pending_queue(adapter); 1311 rtw_free_uc_swdec_pending_queue(adapter);
1303 1312
1304 rtw_free_assoc_resources(adapter, 1); 1313 rtw_free_assoc_resources(adapter);
1305 rtw_indicate_disconnect(adapter); 1314 rtw_indicate_disconnect(adapter);
1306 spin_lock_bh(&(pmlmepriv->scanned_queue.lock)); 1315 spin_lock_bh(&(pmlmepriv->scanned_queue.lock));
1307 /* remove the network entry in scanned_queue */ 1316 /* remove the network entry in scanned_queue */
@@ -1382,7 +1391,7 @@ void _rtw_join_timeout_handler (unsigned long data)
1382 DBG_88E("%s try another roaming\n", __func__); 1391 DBG_88E("%s try another roaming\n", __func__);
1383 do_join_r = rtw_do_join(adapter); 1392 do_join_r = rtw_do_join(adapter);
1384 if (_SUCCESS != do_join_r) { 1393 if (_SUCCESS != do_join_r) {
1385 DBG_88E("%s roaming do_join return %d\n", __func__ , do_join_r); 1394 DBG_88E("%s roaming do_join return %d\n", __func__, do_join_r);
1386 continue; 1395 continue;
1387 } 1396 }
1388 break; 1397 break;
@@ -1556,7 +1565,7 @@ int rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv)
1556 1565
1557 rtw_disassoc_cmd(adapter, 0, true); 1566 rtw_disassoc_cmd(adapter, 0, true);
1558 rtw_indicate_disconnect(adapter); 1567 rtw_indicate_disconnect(adapter);
1559 rtw_free_assoc_resources(adapter, 0); 1568 rtw_free_assoc_resources_locked(adapter);
1560 } 1569 }
1561 1570
1562 rtw_hal_get_def_var(adapter, HAL_DEF_IS_SUPPORT_ANT_DIV, &(supp_ant_div)); 1571 rtw_hal_get_def_var(adapter, HAL_DEF_IS_SUPPORT_ANT_DIV, &(supp_ant_div));
@@ -1997,7 +2006,7 @@ unsigned int rtw_restructure_ht_ie(struct adapter *padapter, u8 *in_ie, u8 *out_
1997 p = rtw_get_ie(in_ie+12, _HT_ADD_INFO_IE_, &ielen, in_len-12); 2006 p = rtw_get_ie(in_ie+12, _HT_ADD_INFO_IE_, &ielen, in_len-12);
1998 if (p && (ielen == sizeof(struct ieee80211_ht_addt_info))) { 2007 if (p && (ielen == sizeof(struct ieee80211_ht_addt_info))) {
1999 out_len = *pout_len; 2008 out_len = *pout_len;
2000 rtw_set_ie(out_ie+out_len, _HT_ADD_INFO_IE_, ielen, p+2 , pout_len); 2009 rtw_set_ie(out_ie+out_len, _HT_ADD_INFO_IE_, ielen, p+2, pout_len);
2001 } 2010 }
2002 } 2011 }
2003 return phtpriv->ht_option; 2012 return phtpriv->ht_option;
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
index a0b8f665fa2f..935b48eef8b1 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
@@ -1096,7 +1096,7 @@ static void issue_assocreq(struct adapter *padapter)
1096 1096
1097 /* Check if the AP's supported rates are also supported by STA. */ 1097 /* Check if the AP's supported rates are also supported by STA. */
1098 for (j = 0; j < sta_bssrate_len; j++) { 1098 for (j = 0; j < sta_bssrate_len; j++) {
1099 /* Avoid the proprietary data rate (22Mbps) of Handlink WSG-4000 AP */ 1099 /* Avoid the proprietary data rate (22Mbps) of Handlink WSG-4000 AP */
1100 if ((pmlmeinfo->network.SupportedRates[i]|IEEE80211_BASIC_RATE_MASK) 1100 if ((pmlmeinfo->network.SupportedRates[i]|IEEE80211_BASIC_RATE_MASK)
1101 == (sta_bssrate[j]|IEEE80211_BASIC_RATE_MASK)) 1101 == (sta_bssrate[j]|IEEE80211_BASIC_RATE_MASK))
1102 break; 1102 break;
@@ -2932,7 +2932,7 @@ static unsigned int OnAuthClient(struct adapter *padapter,
2932 2932
2933 if (seq == 2) { 2933 if (seq == 2) {
2934 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared) { 2934 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared) {
2935 /* legendary shared system */ 2935 /* legendary shared system */
2936 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _AUTH_IE_OFFSET_, _CHLGETXT_IE_, (int *)&len, 2936 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _AUTH_IE_OFFSET_, _CHLGETXT_IE_, (int *)&len,
2937 pkt_len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_); 2937 pkt_len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_);
2938 2938
@@ -3367,7 +3367,7 @@ static unsigned int OnAssocReq(struct adapter *padapter,
3367 spin_unlock_bh(&pstapriv->asoc_list_lock); 3367 spin_unlock_bh(&pstapriv->asoc_list_lock);
3368 3368
3369 /* now the station is qualified to join our BSS... */ 3369 /* now the station is qualified to join our BSS... */
3370 if (pstat && (pstat->state & WIFI_FW_ASSOC_SUCCESS) && (_STATS_SUCCESSFUL_ == status)) { 3370 if ((pstat->state & WIFI_FW_ASSOC_SUCCESS) && (_STATS_SUCCESSFUL_ == status)) {
3371 /* 1 bss_cap_update & sta_info_update */ 3371 /* 1 bss_cap_update & sta_info_update */
3372 bss_cap_update_on_sta_join(padapter, pstat); 3372 bss_cap_update_on_sta_join(padapter, pstat);
3373 sta_info_update(padapter, pstat); 3373 sta_info_update(padapter, pstat);
@@ -4155,8 +4155,8 @@ static void _mgt_dispatcher(struct adapter *padapter, struct mlme_handler *ptabl
4155 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 4155 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
4156 u8 *pframe = precv_frame->rx_data; 4156 u8 *pframe = precv_frame->rx_data;
4157 4157
4158 if (ptable->func) { 4158 if (ptable->func) {
4159 /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */ 4159 /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */
4160 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN) && 4160 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN) &&
4161 memcmp(GetAddr1Ptr(pframe), bc_addr, ETH_ALEN)) 4161 memcmp(GetAddr1Ptr(pframe), bc_addr, ETH_ALEN))
4162 return; 4162 return;
diff --git a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
index ec0a8a4cdc6e..9765946466ab 100644
--- a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
+++ b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
@@ -70,7 +70,7 @@ static int rtw_hw_suspend(struct adapter *padapter)
70 } 70 }
71 } 71 }
72 /* s2-3. */ 72 /* s2-3. */
73 rtw_free_assoc_resources(padapter, 1); 73 rtw_free_assoc_resources(padapter);
74 74
75 /* s2-4. */ 75 /* s2-4. */
76 rtw_free_network_queue(padapter, true); 76 rtw_free_network_queue(padapter, true);
@@ -549,12 +549,6 @@ void rtw_init_pwrctrl_priv(struct adapter *padapter)
549 (unsigned long)padapter); 549 (unsigned long)padapter);
550} 550}
551 551
552inline void rtw_set_ips_deny(struct adapter *padapter, u32 ms)
553{
554 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
555 pwrpriv->ips_deny_time = jiffies + msecs_to_jiffies(ms);
556}
557
558/* 552/*
559* rtw_pwr_wakeup - Wake the NIC up from: 1)IPS. 2)USB autosuspend 553* rtw_pwr_wakeup - Wake the NIC up from: 1)IPS. 2)USB autosuspend
560* @adapter: pointer to struct adapter structure 554* @adapter: pointer to struct adapter structure
diff --git a/drivers/staging/rtl8188eu/core/rtw_recv.c b/drivers/staging/rtl8188eu/core/rtw_recv.c
index 8501eb898824..44eeb03213e6 100644
--- a/drivers/staging/rtl8188eu/core/rtw_recv.c
+++ b/drivers/staging/rtl8188eu/core/rtw_recv.c
@@ -74,10 +74,8 @@ int _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter)
74 74
75 precvpriv->pallocated_frame_buf = vzalloc(NR_RECVFRAME * sizeof(struct recv_frame) + RXFRAME_ALIGN_SZ); 75 precvpriv->pallocated_frame_buf = vzalloc(NR_RECVFRAME * sizeof(struct recv_frame) + RXFRAME_ALIGN_SZ);
76 76
77 if (precvpriv->pallocated_frame_buf == NULL) { 77 if (!precvpriv->pallocated_frame_buf)
78 res = _FAIL; 78 return _FAIL;
79 goto exit;
80 }
81 79
82 precvpriv->precv_frame_buf = (u8 *)N_BYTE_ALIGMENT((size_t)(precvpriv->pallocated_frame_buf), RXFRAME_ALIGN_SZ); 80 precvpriv->precv_frame_buf = (u8 *)N_BYTE_ALIGMENT((size_t)(precvpriv->pallocated_frame_buf), RXFRAME_ALIGN_SZ);
83 81
@@ -89,7 +87,7 @@ int _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter)
89 list_add_tail(&(precvframe->list), 87 list_add_tail(&(precvframe->list),
90 &(precvpriv->free_recv_queue.queue)); 88 &(precvpriv->free_recv_queue.queue));
91 89
92 res = rtw_os_recv_resource_alloc(padapter, precvframe); 90 rtw_os_recv_resource_alloc(precvframe);
93 91
94 precvframe->len = 0; 92 precvframe->len = 0;
95 93
@@ -107,8 +105,6 @@ int _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter)
107 precvpriv->signal_stat_sampling_interval = 1000; /* ms */ 105 precvpriv->signal_stat_sampling_interval = 1000; /* ms */
108 106
109 rtw_set_signal_stat_timer(precvpriv); 107 rtw_set_signal_stat_timer(precvpriv);
110exit:
111
112 108
113 return res; 109 return res;
114} 110}
@@ -117,7 +113,6 @@ void _rtw_free_recv_priv(struct recv_priv *precvpriv)
117{ 113{
118 struct adapter *padapter = precvpriv->adapter; 114 struct adapter *padapter = precvpriv->adapter;
119 115
120
121 rtw_free_uc_swdec_pending_queue(padapter); 116 rtw_free_uc_swdec_pending_queue(padapter);
122 117
123 if (precvpriv->pallocated_frame_buf) { 118 if (precvpriv->pallocated_frame_buf) {
@@ -153,7 +148,6 @@ struct recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue)
153 } 148 }
154 } 149 }
155 150
156
157 return (struct recv_frame *)hdr; 151 return (struct recv_frame *)hdr;
158} 152}
159 153
@@ -170,14 +164,6 @@ struct recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue)
170 return precvframe; 164 return precvframe;
171} 165}
172 166
173void rtw_init_recvframe(struct recv_frame *precvframe, struct recv_priv *precvpriv)
174{
175 /* Perry: This can be removed */
176 INIT_LIST_HEAD(&precvframe->list);
177
178 precvframe->len = 0;
179}
180
181int rtw_free_recvframe(struct recv_frame *precvframe, 167int rtw_free_recvframe(struct recv_frame *precvframe,
182 struct __queue *pfree_recv_queue) 168 struct __queue *pfree_recv_queue)
183{ 169{
@@ -208,7 +194,6 @@ int rtw_free_recvframe(struct recv_frame *precvframe,
208 194
209 spin_unlock_bh(&pfree_recv_queue->lock); 195 spin_unlock_bh(&pfree_recv_queue->lock);
210 196
211
212 return _SUCCESS; 197 return _SUCCESS;
213} 198}
214 199
@@ -217,7 +202,6 @@ int _rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
217 struct adapter *padapter = precvframe->adapter; 202 struct adapter *padapter = precvframe->adapter;
218 struct recv_priv *precvpriv = &padapter->recvpriv; 203 struct recv_priv *precvpriv = &padapter->recvpriv;
219 204
220
221 list_del_init(&(precvframe->list)); 205 list_del_init(&(precvframe->list));
222 list_add_tail(&(precvframe->list), get_list_head(queue)); 206 list_add_tail(&(precvframe->list), get_list_head(queue));
223 207
@@ -226,7 +210,6 @@ int _rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
226 precvpriv->free_recvframe_cnt++; 210 precvpriv->free_recvframe_cnt++;
227 } 211 }
228 212
229
230 return _SUCCESS; 213 return _SUCCESS;
231} 214}
232 215
@@ -421,7 +404,6 @@ static int recvframe_chkmic(struct adapter *adapter,
421 404
422exit: 405exit:
423 406
424
425 return res; 407 return res;
426} 408}
427 409
@@ -483,7 +465,6 @@ static struct recv_frame *decryptor(struct adapter *padapter,
483 return_packet = NULL; 465 return_packet = NULL;
484 } 466 }
485 467
486
487 return return_packet; 468 return return_packet;
488} 469}
489 470
@@ -502,7 +483,6 @@ static struct recv_frame *portctrl(struct adapter *adapter,
502 struct rx_pkt_attrib *pattrib; 483 struct rx_pkt_attrib *pattrib;
503 __be16 be_tmp; 484 __be16 be_tmp;
504 485
505
506 pstapriv = &adapter->stapriv; 486 pstapriv = &adapter->stapriv;
507 487
508 auth_alg = adapter->securitypriv.dot11AuthAlgrthm; 488 auth_alg = adapter->securitypriv.dot11AuthAlgrthm;
@@ -561,7 +541,6 @@ static struct recv_frame *portctrl(struct adapter *adapter,
561 prtnframe = precv_frame; 541 prtnframe = precv_frame;
562 } 542 }
563 543
564
565 return prtnframe; 544 return prtnframe;
566} 545}
567 546
@@ -573,7 +552,6 @@ static int recv_decache(struct recv_frame *precv_frame, u8 bretry,
573 u16 seq_ctrl = ((precv_frame->attrib.seq_num&0xffff) << 4) | 552 u16 seq_ctrl = ((precv_frame->attrib.seq_num&0xffff) << 4) |
574 (precv_frame->attrib.frag_num & 0xf); 553 (precv_frame->attrib.frag_num & 0xf);
575 554
576
577 if (tid > 15) { 555 if (tid > 15) {
578 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_decache, (tid>15)! seq_ctrl=0x%x, tid=0x%x\n", seq_ctrl, tid)); 556 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_decache, (tid>15)! seq_ctrl=0x%x, tid=0x%x\n", seq_ctrl, tid));
579 557
@@ -590,7 +568,6 @@ static int recv_decache(struct recv_frame *precv_frame, u8 bretry,
590 568
591 prxcache->tid_rxseq[tid] = seq_ctrl; 569 prxcache->tid_rxseq[tid] = seq_ctrl;
592 570
593
594 return _SUCCESS; 571 return _SUCCESS;
595} 572}
596 573
@@ -727,7 +704,6 @@ int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame,
727 u8 *sta_addr = NULL; 704 u8 *sta_addr = NULL;
728 int bmcast = IS_MCAST(pattrib->dst); 705 int bmcast = IS_MCAST(pattrib->dst);
729 706
730
731 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) || 707 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) ||
732 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) { 708 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) {
733 /* filter packets that SA is myself or multicast or broadcast */ 709 /* filter packets that SA is myself or multicast or broadcast */
@@ -815,7 +791,6 @@ static int ap2sta_data_frame(
815 u8 *myhwaddr = myid(&adapter->eeprompriv); 791 u8 *myhwaddr = myid(&adapter->eeprompriv);
816 int bmcast = IS_MCAST(pattrib->dst); 792 int bmcast = IS_MCAST(pattrib->dst);
817 793
818
819 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) && 794 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) &&
820 (check_fwstate(pmlmepriv, _FW_LINKED) == true || 795 (check_fwstate(pmlmepriv, _FW_LINKED) == true ||
821 check_fwstate(pmlmepriv, _FW_UNDER_LINKING))) { 796 check_fwstate(pmlmepriv, _FW_UNDER_LINKING))) {
@@ -907,7 +882,6 @@ static int ap2sta_data_frame(
907 882
908exit: 883exit:
909 884
910
911 return ret; 885 return ret;
912} 886}
913 887
@@ -922,7 +896,6 @@ static int sta2ap_data_frame(struct adapter *adapter,
922 unsigned char *mybssid = get_bssid(pmlmepriv); 896 unsigned char *mybssid = get_bssid(pmlmepriv);
923 int ret = _SUCCESS; 897 int ret = _SUCCESS;
924 898
925
926 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) { 899 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
927 /* For AP mode, RA = BSSID, TX = STA(SRC_ADDR), A3 = DST_ADDR */ 900 /* For AP mode, RA = BSSID, TX = STA(SRC_ADDR), A3 = DST_ADDR */
928 if (memcmp(pattrib->bssid, mybssid, ETH_ALEN)) { 901 if (memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
@@ -967,7 +940,6 @@ static int sta2ap_data_frame(struct adapter *adapter,
967 940
968exit: 941exit:
969 942
970
971 return ret; 943 return ret;
972} 944}
973 945
@@ -1149,7 +1121,6 @@ static int validate_recv_data_frame(struct adapter *adapter,
1149 struct security_priv *psecuritypriv = &adapter->securitypriv; 1121 struct security_priv *psecuritypriv = &adapter->securitypriv;
1150 int ret = _SUCCESS; 1122 int ret = _SUCCESS;
1151 1123
1152
1153 bretry = GetRetry(ptr); 1124 bretry = GetRetry(ptr);
1154 pda = get_da(ptr); 1125 pda = get_da(ptr);
1155 psa = get_sa(ptr); 1126 psa = get_sa(ptr);
@@ -1253,7 +1224,6 @@ static int validate_recv_data_frame(struct adapter *adapter,
1253 1224
1254exit: 1225exit:
1255 1226
1256
1257 return ret; 1227 return ret;
1258} 1228}
1259 1229
@@ -1273,7 +1243,6 @@ static int validate_recv_frame(struct adapter *adapter,
1273 u8 ver = (unsigned char)(*ptr)&0x3; 1243 u8 ver = (unsigned char)(*ptr)&0x3;
1274 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv; 1244 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
1275 1245
1276
1277 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) { 1246 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
1278 int ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, rtw_get_oper_ch(adapter)); 1247 int ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, rtw_get_oper_ch(adapter));
1279 if (ch_set_idx >= 0) 1248 if (ch_set_idx >= 0)
@@ -1362,7 +1331,6 @@ static int validate_recv_frame(struct adapter *adapter,
1362 1331
1363exit: 1332exit:
1364 1333
1365
1366 return retval; 1334 return retval;
1367} 1335}
1368 1336
@@ -1445,7 +1413,6 @@ static struct recv_frame *recvframe_defrag(struct adapter *adapter,
1445 struct recv_frame *prframe, *pnextrframe; 1413 struct recv_frame *prframe, *pnextrframe;
1446 struct __queue *pfree_recv_queue; 1414 struct __queue *pfree_recv_queue;
1447 1415
1448
1449 curfragnum = 0; 1416 curfragnum = 0;
1450 pfree_recv_queue = &adapter->recvpriv.free_recv_queue; 1417 pfree_recv_queue = &adapter->recvpriv.free_recv_queue;
1451 1418
@@ -1510,7 +1477,6 @@ static struct recv_frame *recvframe_defrag(struct adapter *adapter,
1510 1477
1511 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Performance defrag!!!!!\n")); 1478 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Performance defrag!!!!!\n"));
1512 1479
1513
1514 return prframe; 1480 return prframe;
1515} 1481}
1516 1482
@@ -1528,7 +1494,6 @@ struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
1528 struct recv_frame *prtnframe = NULL; 1494 struct recv_frame *prtnframe = NULL;
1529 struct __queue *pfree_recv_queue, *pdefrag_q; 1495 struct __queue *pfree_recv_queue, *pdefrag_q;
1530 1496
1531
1532 pstapriv = &padapter->stapriv; 1497 pstapriv = &padapter->stapriv;
1533 1498
1534 pfhdr = precv_frame; 1499 pfhdr = precv_frame;
@@ -1612,7 +1577,6 @@ struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
1612 } 1577 }
1613 } 1578 }
1614 1579
1615
1616 return prtnframe; 1580 return prtnframe;
1617} 1581}
1618 1582
@@ -2116,7 +2080,6 @@ s32 rtw_recv_entry(struct recv_frame *precvframe)
2116 struct recv_priv *precvpriv; 2080 struct recv_priv *precvpriv;
2117 s32 ret = _SUCCESS; 2081 s32 ret = _SUCCESS;
2118 2082
2119
2120 padapter = precvframe->adapter; 2083 padapter = precvframe->adapter;
2121 2084
2122 precvpriv = &padapter->recvpriv; 2085 precvpriv = &padapter->recvpriv;
@@ -2129,7 +2092,6 @@ s32 rtw_recv_entry(struct recv_frame *precvframe)
2129 2092
2130 precvpriv->rx_pkts++; 2093 precvpriv->rx_pkts++;
2131 2094
2132
2133 return ret; 2095 return ret;
2134 2096
2135_recv_entry_drop: 2097_recv_entry_drop:
diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c b/drivers/staging/rtl8188eu/core/rtw_security.c
index d870a5ce8585..22839d57dc8c 100644
--- a/drivers/staging/rtl8188eu/core/rtw_security.c
+++ b/drivers/staging/rtl8188eu/core/rtw_security.c
@@ -1330,7 +1330,7 @@ static int aes_decipher(u8 *key, uint hdrlen,
1330 bitwise_xor(aes_out, &pframe[payload_index], chain_buffer); 1330 bitwise_xor(aes_out, &pframe[payload_index], chain_buffer);
1331 1331
1332 for (j = 0; j < 16; j++) 1332 for (j = 0; j < 16; j++)
1333 pframe[payload_index++] = chain_buffer[j]; 1333 pframe[payload_index++] = chain_buffer[j];
1334 } 1334 }
1335 1335
1336 if (payload_remainder > 0) { /* If there is a short final block, then pad it,*/ 1336 if (payload_remainder > 0) { /* If there is a short final block, then pad it,*/
diff --git a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
index 32300df7b996..077b39a41c60 100644
--- a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
+++ b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
@@ -19,6 +19,8 @@
19 ******************************************************************************/ 19 ******************************************************************************/
20#define _RTW_WLAN_UTIL_C_ 20#define _RTW_WLAN_UTIL_C_
21 21
22#include <linux/ieee80211.h>
23
22#include <osdep_service.h> 24#include <osdep_service.h>
23#include <drv_types.h> 25#include <drv_types.h>
24#include <wifi.h> 26#include <wifi.h>
diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index fda169d37771..5dc0b90e8ab5 100644
--- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
+++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
@@ -868,7 +868,7 @@ s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr
868 /* check if enable ampdu */ 868 /* check if enable ampdu */
869 if (pattrib->ht_en && psta->htpriv.ampdu_enable) { 869 if (pattrib->ht_en && psta->htpriv.ampdu_enable) {
870 if (psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority)) 870 if (psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority))
871 pattrib->ampdu_en = true; 871 pattrib->ampdu_en = true;
872 } 872 }
873 873
874 /* re-check if enable ampdu by BA_starting_seqctrl */ 874 /* re-check if enable ampdu by BA_starting_seqctrl */
@@ -1026,22 +1026,22 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct
1026 /* adding icv, if necessary... */ 1026 /* adding icv, if necessary... */
1027 if (pattrib->iv_len) { 1027 if (pattrib->iv_len) {
1028 switch (pattrib->encrypt) { 1028 switch (pattrib->encrypt) {
1029 case _WEP40_: 1029 case _WEP40_:
1030 case _WEP104_: 1030 case _WEP104_:
1031 WEP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx); 1031 WEP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
1032 break; 1032 break;
1033 case _TKIP_: 1033 case _TKIP_:
1034 if (bmcst) 1034 if (bmcst)
1035 TKIP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx); 1035 TKIP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
1036 else 1036 else
1037 TKIP_IV(pattrib->iv, psta->dot11txpn, 0); 1037 TKIP_IV(pattrib->iv, psta->dot11txpn, 0);
1038 break; 1038 break;
1039 case _AES_: 1039 case _AES_:
1040 if (bmcst) 1040 if (bmcst)
1041 AES_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx); 1041 AES_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
1042 else 1042 else
1043 AES_IV(pattrib->iv, psta->dot11txpn, 0); 1043 AES_IV(pattrib->iv, psta->dot11txpn, 0);
1044 break; 1044 break;
1045 } 1045 }
1046 1046
1047 memcpy(pframe, pattrib->iv, pattrib->iv_len); 1047 memcpy(pframe, pattrib->iv, pattrib->iv_len);
@@ -1769,7 +1769,7 @@ int xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_fra
1769 int bmcst = IS_MCAST(pattrib->ra); 1769 int bmcst = IS_MCAST(pattrib->ra);
1770 1770
1771 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == false) 1771 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == false)
1772 return ret; 1772 return ret;
1773 1773
1774 if (pattrib->psta) 1774 if (pattrib->psta)
1775 psta = pattrib->psta; 1775 psta = pattrib->psta;
diff --git a/drivers/staging/rtl8188eu/hal/Hal8188ERateAdaptive.c b/drivers/staging/rtl8188eu/hal/Hal8188ERateAdaptive.c
index 15a176596305..2633a13b4e58 100644
--- a/drivers/staging/rtl8188eu/hal/Hal8188ERateAdaptive.c
+++ b/drivers/staging/rtl8188eu/hal/Hal8188ERateAdaptive.c
@@ -659,11 +659,11 @@ void ODM_RA_UpdateRateInfo_8188E(struct odm_dm_struct *dm_odm, u8 macid, u8 Rate
659{ 659{
660 struct odm_ra_info *pRaInfo = NULL; 660 struct odm_ra_info *pRaInfo = NULL;
661 661
662 if ((NULL == dm_odm) || (macid >= ASSOCIATE_ENTRY_NUM))
663 return;
662 ODM_RT_TRACE(dm_odm, ODM_COMP_RATE_ADAPTIVE, ODM_DBG_LOUD, 664 ODM_RT_TRACE(dm_odm, ODM_COMP_RATE_ADAPTIVE, ODM_DBG_LOUD,
663 ("macid =%d RateID = 0x%x RateMask = 0x%x SGIEnable =%d\n", 665 ("macid =%d RateID = 0x%x RateMask = 0x%x SGIEnable =%d\n",
664 macid, RateID, RateMask, SGIEnable)); 666 macid, RateID, RateMask, SGIEnable));
665 if ((NULL == dm_odm) || (macid >= ASSOCIATE_ENTRY_NUM))
666 return;
667 667
668 pRaInfo = &(dm_odm->RAInfo[macid]); 668 pRaInfo = &(dm_odm->RAInfo[macid]);
669 pRaInfo->RateID = RateID; 669 pRaInfo->RateID = RateID;
@@ -676,10 +676,10 @@ void ODM_RA_SetRSSI_8188E(struct odm_dm_struct *dm_odm, u8 macid, u8 Rssi)
676{ 676{
677 struct odm_ra_info *pRaInfo = NULL; 677 struct odm_ra_info *pRaInfo = NULL;
678 678
679 ODM_RT_TRACE(dm_odm, ODM_COMP_RATE_ADAPTIVE, ODM_DBG_TRACE,
680 (" macid =%d Rssi =%d\n", macid, Rssi));
681 if ((NULL == dm_odm) || (macid >= ASSOCIATE_ENTRY_NUM)) 679 if ((NULL == dm_odm) || (macid >= ASSOCIATE_ENTRY_NUM))
682 return; 680 return;
681 ODM_RT_TRACE(dm_odm, ODM_COMP_RATE_ADAPTIVE, ODM_DBG_TRACE,
682 (" macid =%d Rssi =%d\n", macid, Rssi));
683 683
684 pRaInfo = &(dm_odm->RAInfo[macid]); 684 pRaInfo = &(dm_odm->RAInfo[macid]);
685 pRaInfo->RssiStaRA = Rssi; 685 pRaInfo->RssiStaRA = Rssi;
diff --git a/drivers/staging/rtl8188eu/hal/bb_cfg.c b/drivers/staging/rtl8188eu/hal/bb_cfg.c
index 8eb2b39a0b67..9c7e626aa703 100644
--- a/drivers/staging/rtl8188eu/hal/bb_cfg.c
+++ b/drivers/staging/rtl8188eu/hal/bb_cfg.c
@@ -24,9 +24,9 @@
24 24
25#define read_next_pair(array, v1, v2, i) \ 25#define read_next_pair(array, v1, v2, i) \
26 do { \ 26 do { \
27 i += 2; \ 27 i += 2; \
28 v1 = array[i]; \ 28 v1 = array[i]; \
29 v2 = array[i+1]; \ 29 v2 = array[i+1]; \
30 } while (0) 30 } while (0)
31 31
32 32
diff --git a/drivers/staging/rtl8188eu/hal/hal_com.c b/drivers/staging/rtl8188eu/hal/hal_com.c
index 170e3de5eab4..38e9fdc312d3 100644
--- a/drivers/staging/rtl8188eu/hal/hal_com.c
+++ b/drivers/staging/rtl8188eu/hal/hal_com.c
@@ -31,18 +31,7 @@ void dump_chip_info(struct HAL_VERSION chip_vers)
31 uint cnt = 0; 31 uint cnt = 0;
32 char buf[128]; 32 char buf[128];
33 33
34 if (IS_81XXC(chip_vers)) { 34 cnt += sprintf((buf+cnt), "Chip Version Info: CHIP_8188E_");
35 cnt += sprintf((buf+cnt), "Chip Version Info: %s_",
36 IS_92C_SERIAL(chip_vers) ?
37 "CHIP_8192C" : "CHIP_8188C");
38 } else if (IS_92D(chip_vers)) {
39 cnt += sprintf((buf+cnt), "Chip Version Info: CHIP_8192D_");
40 } else if (IS_8723_SERIES(chip_vers)) {
41 cnt += sprintf((buf+cnt), "Chip Version Info: CHIP_8723A_");
42 } else if (IS_8188E(chip_vers)) {
43 cnt += sprintf((buf+cnt), "Chip Version Info: CHIP_8188E_");
44 }
45
46 cnt += sprintf((buf+cnt), "%s_", IS_NORMAL_CHIP(chip_vers) ? 35 cnt += sprintf((buf+cnt), "%s_", IS_NORMAL_CHIP(chip_vers) ?
47 "Normal_Chip" : "Test_Chip"); 36 "Normal_Chip" : "Test_Chip");
48 cnt += sprintf((buf+cnt), "%s_", IS_CHIP_VENDOR_TSMC(chip_vers) ? 37 cnt += sprintf((buf+cnt), "%s_", IS_CHIP_VENDOR_TSMC(chip_vers) ?
@@ -60,18 +49,8 @@ void dump_chip_info(struct HAL_VERSION chip_vers)
60 else 49 else
61 cnt += sprintf((buf+cnt), "UNKNOWN_CUT(%d)_", 50 cnt += sprintf((buf+cnt), "UNKNOWN_CUT(%d)_",
62 chip_vers.CUTVersion); 51 chip_vers.CUTVersion);
63 52 cnt += sprintf((buf+cnt), "1T1R_");
64 if (IS_1T1R(chip_vers)) 53 cnt += sprintf((buf+cnt), "RomVer(0)\n");
65 cnt += sprintf((buf+cnt), "1T1R_");
66 else if (IS_1T2R(chip_vers))
67 cnt += sprintf((buf+cnt), "1T2R_");
68 else if (IS_2T2R(chip_vers))
69 cnt += sprintf((buf+cnt), "2T2R_");
70 else
71 cnt += sprintf((buf+cnt), "UNKNOWN_RFTYPE(%d)_",
72 chip_vers.RFType);
73
74 cnt += sprintf((buf+cnt), "RomVer(%d)\n", chip_vers.ROMVer);
75 54
76 pr_info("%s", buf); 55 pr_info("%s", buf);
77} 56}
diff --git a/drivers/staging/rtl8188eu/hal/hal_intf.c b/drivers/staging/rtl8188eu/hal/hal_intf.c
index 5edb5c41c8e7..85c17ef942f3 100644
--- a/drivers/staging/rtl8188eu/hal/hal_intf.c
+++ b/drivers/staging/rtl8188eu/hal/hal_intf.c
@@ -131,14 +131,6 @@ void rtw_hal_get_hwreg(struct adapter *adapt, u8 variable, u8 *val)
131 adapt->HalFunc.GetHwRegHandler(adapt, variable, val); 131 adapt->HalFunc.GetHwRegHandler(adapt, variable, val);
132} 132}
133 133
134u8 rtw_hal_set_def_var(struct adapter *adapt, enum hal_def_variable var,
135 void *val)
136{
137 if (adapt->HalFunc.SetHalDefVarHandler)
138 return adapt->HalFunc.SetHalDefVarHandler(adapt, var, val);
139 return _FAIL;
140}
141
142u8 rtw_hal_get_def_var(struct adapter *adapt, 134u8 rtw_hal_get_def_var(struct adapter *adapt,
143 enum hal_def_variable var, void *val) 135 enum hal_def_variable var, void *val)
144{ 136{
@@ -156,22 +148,6 @@ void rtw_hal_set_odm_var(struct adapter *adapt,
156 val1, set); 148 val1, set);
157} 149}
158 150
159void rtw_hal_enable_interrupt(struct adapter *adapt)
160{
161 if (adapt->HalFunc.enable_interrupt)
162 adapt->HalFunc.enable_interrupt(adapt);
163 else
164 DBG_88E("%s: HalFunc.enable_interrupt is NULL!\n", __func__);
165}
166
167void rtw_hal_disable_interrupt(struct adapter *adapt)
168{
169 if (adapt->HalFunc.disable_interrupt)
170 adapt->HalFunc.disable_interrupt(adapt);
171 else
172 DBG_88E("%s: HalFunc.disable_interrupt is NULL!\n", __func__);
173}
174
175u32 rtw_hal_inirp_init(struct adapter *adapt) 151u32 rtw_hal_inirp_init(struct adapter *adapt)
176{ 152{
177 u32 rst = _FAIL; 153 u32 rst = _FAIL;
@@ -269,14 +245,6 @@ u32 rtw_hal_read_rfreg(struct adapter *adapt, enum rf_radio_path rfpath,
269 return data; 245 return data;
270} 246}
271 247
272void rtw_hal_write_rfreg(struct adapter *adapt, enum rf_radio_path rfpath,
273 u32 regaddr, u32 bitmask, u32 data)
274{
275 if (adapt->HalFunc.write_rfreg)
276 adapt->HalFunc.write_rfreg(adapt, rfpath, regaddr,
277 bitmask, data);
278}
279
280void rtw_hal_set_bwmode(struct adapter *adapt, 248void rtw_hal_set_bwmode(struct adapter *adapt,
281 enum ht_channel_width bandwidth, u8 offset) 249 enum ht_channel_width bandwidth, u8 offset)
282{ 250{
diff --git a/drivers/staging/rtl8188eu/hal/odm.c b/drivers/staging/rtl8188eu/hal/odm.c
index 28b5e7bd4fc0..710fdc3449f8 100644
--- a/drivers/staging/rtl8188eu/hal/odm.c
+++ b/drivers/staging/rtl8188eu/hal/odm.c
@@ -1170,13 +1170,10 @@ void odm_RSSIMonitorCheckCE(struct odm_dm_struct *pDM_Odm)
1170 } 1170 }
1171 1171
1172 for (i = 0; i < sta_cnt; i++) { 1172 for (i = 0; i < sta_cnt; i++) {
1173 if (PWDB_rssi[i] != (0)) { 1173 if (PWDB_rssi[i] != 0) {
1174 if (pHalData->fw_ractrl) { 1174 ODM_RA_SetRSSI_8188E(&pHalData->odmpriv,
1175 /* Report every sta's RSSI to FW */ 1175 PWDB_rssi[i] & 0xFF,
1176 } else { 1176 (PWDB_rssi[i] >> 16) & 0xFF);
1177 ODM_RA_SetRSSI_8188E(
1178 &(pHalData->odmpriv), (PWDB_rssi[i]&0xFF), (u8)((PWDB_rssi[i]>>16) & 0xFF));
1179 }
1180 } 1177 }
1181 } 1178 }
1182 1179
diff --git a/drivers/staging/rtl8188eu/hal/rf.c b/drivers/staging/rtl8188eu/hal/rf.c
index 097092772a86..38845d17d593 100644
--- a/drivers/staging/rtl8188eu/hal/rf.c
+++ b/drivers/staging/rtl8188eu/hal/rf.c
@@ -102,7 +102,7 @@ void rtl88eu_phy_rf6052_set_cck_txpower(struct adapter *adapt, u8 *powerlevel)
102 } 102 }
103 } 103 }
104 rtl88eu_dm_txpower_track_adjust(&hal_data->odmpriv, 1, &direction, 104 rtl88eu_dm_txpower_track_adjust(&hal_data->odmpriv, 1, &direction,
105 &pwrtrac_value); 105 &pwrtrac_value);
106 106
107 if (direction == 1) { 107 if (direction == 1) {
108 /* Increase TX power */ 108 /* Increase TX power */
diff --git a/drivers/staging/rtl8188eu/hal/rf_cfg.c b/drivers/staging/rtl8188eu/hal/rf_cfg.c
index 455ecdc8d9fa..954cade478db 100644
--- a/drivers/staging/rtl8188eu/hal/rf_cfg.c
+++ b/drivers/staging/rtl8188eu/hal/rf_cfg.c
@@ -295,7 +295,7 @@ static bool rf6052_conf_para(struct adapter *adapt)
295 break; 295 break;
296 } 296 }
297 297
298 if (rtstatus != true) 298 if (!rtstatus)
299 return false; 299 return false;
300 } 300 }
301 301
diff --git a/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c b/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c
index 86347f2ccdfd..0a62bfa210fe 100644
--- a/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c
+++ b/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c
@@ -127,27 +127,6 @@ exit:
127 return ret; 127 return ret;
128} 128}
129 129
130u8 rtl8188e_set_raid_cmd(struct adapter *adapt, u32 mask)
131{
132 u8 buf[3];
133 u8 res = _SUCCESS;
134 struct hal_data_8188e *haldata = GET_HAL_DATA(adapt);
135
136 if (haldata->fw_ractrl) {
137
138 memset(buf, 0, 3);
139 put_unaligned_le32(mask, buf);
140
141 FillH2CCmd_88E(adapt, H2C_DM_MACID_CFG, 3, buf);
142 } else {
143 DBG_88E("==>%s fw dont support RA\n", __func__);
144 res = _FAIL;
145 }
146
147
148 return res;
149}
150
151/* bitmap[0:27] = tx_rate_bitmap */ 130/* bitmap[0:27] = tx_rate_bitmap */
152/* bitmap[28:31]= Rate Adaptive id */ 131/* bitmap[28:31]= Rate Adaptive id */
153/* arg[0:4] = macid */ 132/* arg[0:4] = macid */
diff --git a/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c b/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c
index 7904d2260f2c..a6295ca6a73e 100644
--- a/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c
+++ b/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c
@@ -128,7 +128,7 @@ static void rtl8188e_free_hal_data(struct adapter *padapter)
128 padapter->HalData = NULL; 128 padapter->HalData = NULL;
129} 129}
130 130
131static struct HAL_VERSION ReadChipVersion8188E(struct adapter *padapter) 131static void ReadChipVersion8188E(struct adapter *padapter)
132{ 132{
133 u32 value32; 133 u32 value32;
134 struct HAL_VERSION ChipVersion; 134 struct HAL_VERSION ChipVersion;
@@ -137,41 +137,17 @@ static struct HAL_VERSION ReadChipVersion8188E(struct adapter *padapter)
137 pHalData = GET_HAL_DATA(padapter); 137 pHalData = GET_HAL_DATA(padapter);
138 138
139 value32 = usb_read32(padapter, REG_SYS_CFG); 139 value32 = usb_read32(padapter, REG_SYS_CFG);
140 ChipVersion.ICType = CHIP_8188E;
141 ChipVersion.ChipType = ((value32 & RTL_ID) ? TEST_CHIP : NORMAL_CHIP); 140 ChipVersion.ChipType = ((value32 & RTL_ID) ? TEST_CHIP : NORMAL_CHIP);
142
143 ChipVersion.RFType = RF_TYPE_1T1R;
144 ChipVersion.VendorType = ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : CHIP_VENDOR_TSMC); 141 ChipVersion.VendorType = ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : CHIP_VENDOR_TSMC);
145 ChipVersion.CUTVersion = (value32 & CHIP_VER_RTL_MASK)>>CHIP_VER_RTL_SHIFT; /* IC version (CUT) */ 142 ChipVersion.CUTVersion = (value32 & CHIP_VER_RTL_MASK)>>CHIP_VER_RTL_SHIFT; /* IC version (CUT) */
146 143
147 /* For regulator mode. by tynli. 2011.01.14 */
148 pHalData->RegulatorMode = ((value32 & TRP_BT_EN) ? RT_LDO_REGULATOR : RT_SWITCHING_REGULATOR);
149
150 ChipVersion.ROMVer = 0; /* ROM code version. */
151
152 dump_chip_info(ChipVersion); 144 dump_chip_info(ChipVersion);
153 145
154 pHalData->VersionID = ChipVersion; 146 pHalData->VersionID = ChipVersion;
155 147 pHalData->rf_type = RF_1T1R;
156 if (IS_1T2R(ChipVersion)) { 148 pHalData->NumTotalRFPath = 1;
157 pHalData->rf_type = RF_1T2R;
158 pHalData->NumTotalRFPath = 2;
159 } else if (IS_2T2R(ChipVersion)) {
160 pHalData->rf_type = RF_2T2R;
161 pHalData->NumTotalRFPath = 2;
162 } else{
163 pHalData->rf_type = RF_1T1R;
164 pHalData->NumTotalRFPath = 1;
165 }
166 149
167 MSG_88E("RF_Type is %x!!\n", pHalData->rf_type); 150 MSG_88E("RF_Type is %x!!\n", pHalData->rf_type);
168
169 return ChipVersion;
170}
171
172static void rtl8188e_read_chip_version(struct adapter *padapter)
173{
174 ReadChipVersion8188E(padapter);
175} 151}
176 152
177static void rtl8188e_SetHalODMVar(struct adapter *Adapter, enum hal_odm_variable eVariable, void *pValue1, bool bSet) 153static void rtl8188e_SetHalODMVar(struct adapter *Adapter, enum hal_odm_variable eVariable, void *pValue1, bool bSet)
@@ -220,7 +196,7 @@ void rtl8188e_set_hal_ops(struct hal_ops *pHalFunc)
220 196
221 pHalFunc->dm_init = &rtl8188e_init_dm_priv; 197 pHalFunc->dm_init = &rtl8188e_init_dm_priv;
222 198
223 pHalFunc->read_chip_version = &rtl8188e_read_chip_version; 199 pHalFunc->read_chip_version = &ReadChipVersion8188E;
224 200
225 pHalFunc->set_bwmode_handler = &phy_set_bw_mode; 201 pHalFunc->set_bwmode_handler = &phy_set_bw_mode;
226 pHalFunc->set_channel_handler = &phy_sw_chnl; 202 pHalFunc->set_channel_handler = &phy_sw_chnl;
@@ -232,7 +208,6 @@ void rtl8188e_set_hal_ops(struct hal_ops *pHalFunc)
232 pHalFunc->AntDivBeforeLinkHandler = &AntDivBeforeLink8188E; 208 pHalFunc->AntDivBeforeLinkHandler = &AntDivBeforeLink8188E;
233 pHalFunc->AntDivCompareHandler = &AntDivCompare8188E; 209 pHalFunc->AntDivCompareHandler = &AntDivCompare8188E;
234 pHalFunc->read_rfreg = &phy_query_rf_reg; 210 pHalFunc->read_rfreg = &phy_query_rf_reg;
235 pHalFunc->write_rfreg = &phy_set_rf_reg;
236 211
237 pHalFunc->sreset_init_value = &sreset_init_value; 212 pHalFunc->sreset_init_value = &sreset_init_value;
238 pHalFunc->sreset_get_wifi_status = &sreset_get_wifi_status; 213 pHalFunc->sreset_get_wifi_status = &sreset_get_wifi_status;
diff --git a/drivers/staging/rtl8188eu/hal/usb_halinit.c b/drivers/staging/rtl8188eu/hal/usb_halinit.c
index 872622214264..1ef878fd997b 100644
--- a/drivers/staging/rtl8188eu/hal/usb_halinit.c
+++ b/drivers/staging/rtl8188eu/hal/usb_halinit.c
@@ -743,19 +743,16 @@ static u32 rtl8188eu_hal_init(struct adapter *Adapter)
743 if (Adapter->registrypriv.mp_mode == 1) { 743 if (Adapter->registrypriv.mp_mode == 1) {
744 _InitRxSetting(Adapter); 744 _InitRxSetting(Adapter);
745 Adapter->bFWReady = false; 745 Adapter->bFWReady = false;
746 haldata->fw_ractrl = false;
747 } else { 746 } else {
748 status = rtl88eu_download_fw(Adapter); 747 status = rtl88eu_download_fw(Adapter);
749 748
750 if (status) { 749 if (status) {
751 DBG_88E("%s: Download Firmware failed!!\n", __func__); 750 DBG_88E("%s: Download Firmware failed!!\n", __func__);
752 Adapter->bFWReady = false; 751 Adapter->bFWReady = false;
753 haldata->fw_ractrl = false;
754 return status; 752 return status;
755 } else { 753 } else {
756 RT_TRACE(_module_hci_hal_init_c_, _drv_info_, ("Initializeadapt8192CSdio(): Download Firmware Success!!\n")); 754 RT_TRACE(_module_hci_hal_init_c_, _drv_info_, ("Initializeadapt8192CSdio(): Download Firmware Success!!\n"));
757 Adapter->bFWReady = true; 755 Adapter->bFWReady = true;
758 haldata->fw_ractrl = false;
759 } 756 }
760 } 757 }
761 rtl8188e_InitializeFirmwareVars(Adapter); 758 rtl8188e_InitializeFirmwareVars(Adapter);
@@ -1703,7 +1700,7 @@ static void SetHwReg8188EU(struct adapter *Adapter, u8 variable, u8 *val)
1703 1700
1704 /* Forece leave RF low power mode for 1T1R to prevent conficting setting in Fw power */ 1701 /* Forece leave RF low power mode for 1T1R to prevent conficting setting in Fw power */
1705 /* saving sequence. 2010.06.07. Added by tynli. Suggested by SD3 yschang. */ 1702 /* saving sequence. 2010.06.07. Added by tynli. Suggested by SD3 yschang. */
1706 if ((psmode != PS_MODE_ACTIVE) && (!IS_92C_SERIAL(haldata->VersionID))) 1703 if (psmode != PS_MODE_ACTIVE)
1707 ODM_RF_Saving(podmpriv, true); 1704 ODM_RF_Saving(podmpriv, true);
1708 rtl8188e_set_FwPwrMode_cmd(Adapter, psmode); 1705 rtl8188e_set_FwPwrMode_cmd(Adapter, psmode);
1709 } 1706 }
@@ -1961,75 +1958,6 @@ GetHalDefVar8188EUsb(
1961 return bResult; 1958 return bResult;
1962} 1959}
1963 1960
1964/* */
1965/* Description: */
1966/* Change default setting of specified variable. */
1967/* */
1968static u8 SetHalDefVar8188EUsb(struct adapter *Adapter, enum hal_def_variable eVariable, void *pValue)
1969{
1970 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
1971 u8 bResult = _SUCCESS;
1972
1973 switch (eVariable) {
1974 case HAL_DEF_DBG_DM_FUNC:
1975 {
1976 u8 dm_func = *((u8 *)pValue);
1977 struct odm_dm_struct *podmpriv = &haldata->odmpriv;
1978
1979 if (dm_func == 0) { /* disable all dynamic func */
1980 podmpriv->SupportAbility = DYNAMIC_FUNC_DISABLE;
1981 DBG_88E("==> Disable all dynamic function...\n");
1982 } else if (dm_func == 1) {/* disable DIG */
1983 podmpriv->SupportAbility &= (~DYNAMIC_BB_DIG);
1984 DBG_88E("==> Disable DIG...\n");
1985 } else if (dm_func == 2) {/* disable High power */
1986 podmpriv->SupportAbility &= (~DYNAMIC_BB_DYNAMIC_TXPWR);
1987 } else if (dm_func == 3) {/* disable tx power tracking */
1988 podmpriv->SupportAbility &= (~DYNAMIC_RF_CALIBRATION);
1989 DBG_88E("==> Disable tx power tracking...\n");
1990 } else if (dm_func == 5) {/* disable antenna diversity */
1991 podmpriv->SupportAbility &= (~DYNAMIC_BB_ANT_DIV);
1992 } else if (dm_func == 6) {/* turn on all dynamic func */
1993 if (!(podmpriv->SupportAbility & DYNAMIC_BB_DIG)) {
1994 struct rtw_dig *pDigTable = &podmpriv->DM_DigTable;
1995 pDigTable->CurIGValue = usb_read8(Adapter, 0xc50);
1996 }
1997 podmpriv->SupportAbility = DYNAMIC_ALL_FUNC_ENABLE;
1998 DBG_88E("==> Turn on all dynamic function...\n");
1999 }
2000 }
2001 break;
2002 case HAL_DEF_DBG_DUMP_RXPKT:
2003 haldata->bDumpRxPkt = *((u8 *)pValue);
2004 break;
2005 case HAL_DEF_DBG_DUMP_TXPKT:
2006 haldata->bDumpTxPkt = *((u8 *)pValue);
2007 break;
2008 case HW_DEF_FA_CNT_DUMP:
2009 {
2010 u8 bRSSIDump = *((u8 *)pValue);
2011 struct odm_dm_struct *dm_ocm = &(haldata->odmpriv);
2012 if (bRSSIDump)
2013 dm_ocm->DebugComponents = ODM_COMP_DIG|ODM_COMP_FA_CNT;
2014 else
2015 dm_ocm->DebugComponents = 0;
2016 }
2017 break;
2018 case HW_DEF_ODM_DBG_FLAG:
2019 {
2020 u64 DebugComponents = *((u64 *)pValue);
2021 struct odm_dm_struct *dm_ocm = &(haldata->odmpriv);
2022 dm_ocm->DebugComponents = DebugComponents;
2023 }
2024 break;
2025 default:
2026 bResult = _FAIL;
2027 break;
2028 }
2029
2030 return bResult;
2031}
2032
2033static void UpdateHalRAMask8188EUsb(struct adapter *adapt, u32 mac_id, u8 rssi_level) 1961static void UpdateHalRAMask8188EUsb(struct adapter *adapt, u32 mac_id, u8 rssi_level)
2034{ 1962{
2035 u8 init_rate = 0; 1963 u8 init_rate = 0;
@@ -2085,28 +2013,9 @@ static void UpdateHalRAMask8188EUsb(struct adapter *adapt, u32 mac_id, u8 rssi_l
2085 2013
2086 init_rate = get_highest_rate_idx(mask)&0x3f; 2014 init_rate = get_highest_rate_idx(mask)&0x3f;
2087 2015
2088 if (haldata->fw_ractrl) { 2016 ODM_RA_UpdateRateInfo_8188E(&haldata->odmpriv, mac_id,
2089 u8 arg; 2017 raid, mask, shortGIrate);
2090
2091 arg = mac_id & 0x1f;/* MACID */
2092 arg |= BIT(7);
2093 if (shortGIrate)
2094 arg |= BIT(5);
2095 mask |= ((raid << 28) & 0xf0000000);
2096 DBG_88E("update raid entry, mask=0x%x, arg=0x%x\n", mask, arg);
2097 psta->ra_mask = mask;
2098 mask |= ((raid << 28) & 0xf0000000);
2099 2018
2100 /* to do ,for 8188E-SMIC */
2101 rtl8188e_set_raid_cmd(adapt, mask);
2102 } else {
2103 ODM_RA_UpdateRateInfo_8188E(&(haldata->odmpriv),
2104 mac_id,
2105 raid,
2106 mask,
2107 shortGIrate
2108 );
2109 }
2110 /* set ra_id */ 2019 /* set ra_id */
2111 psta->raid = raid; 2020 psta->raid = raid;
2112 psta->init_rate = init_rate; 2021 psta->init_rate = init_rate;
@@ -2156,7 +2065,6 @@ static void rtl8188eu_init_default_value(struct adapter *adapt)
2156 pwrctrlpriv = &adapt->pwrctrlpriv; 2065 pwrctrlpriv = &adapt->pwrctrlpriv;
2157 2066
2158 /* init default value */ 2067 /* init default value */
2159 haldata->fw_ractrl = false;
2160 if (!pwrctrlpriv->bkeepfwalive) 2068 if (!pwrctrlpriv->bkeepfwalive)
2161 haldata->LastHMEBoxNum = 0; 2069 haldata->LastHMEBoxNum = 0;
2162 2070
@@ -2200,7 +2108,6 @@ void rtl8188eu_set_hal_ops(struct adapter *adapt)
2200 halfunc->SetHwRegHandler = &SetHwReg8188EU; 2108 halfunc->SetHwRegHandler = &SetHwReg8188EU;
2201 halfunc->GetHwRegHandler = &GetHwReg8188EU; 2109 halfunc->GetHwRegHandler = &GetHwReg8188EU;
2202 halfunc->GetHalDefVarHandler = &GetHalDefVar8188EUsb; 2110 halfunc->GetHalDefVarHandler = &GetHalDefVar8188EUsb;
2203 halfunc->SetHalDefVarHandler = &SetHalDefVar8188EUsb;
2204 2111
2205 halfunc->UpdateRAMaskHandler = &UpdateHalRAMask8188EUsb; 2112 halfunc->UpdateRAMaskHandler = &UpdateHalRAMask8188EUsb;
2206 halfunc->SetBeaconRelatedRegistersHandler = &SetBeaconRelatedRegisters8188EUsb; 2113 halfunc->SetBeaconRelatedRegistersHandler = &SetBeaconRelatedRegisters8188EUsb;
diff --git a/drivers/staging/rtl8188eu/include/HalVerDef.h b/drivers/staging/rtl8188eu/include/HalVerDef.h
index 97047cf06780..56b4ff08e509 100644
--- a/drivers/staging/rtl8188eu/include/HalVerDef.h
+++ b/drivers/staging/rtl8188eu/include/HalVerDef.h
@@ -20,20 +20,6 @@
20#ifndef __HAL_VERSION_DEF_H__ 20#ifndef __HAL_VERSION_DEF_H__
21#define __HAL_VERSION_DEF_H__ 21#define __HAL_VERSION_DEF_H__
22 22
23enum HAL_IC_TYPE {
24 CHIP_8192S = 0,
25 CHIP_8188C = 1,
26 CHIP_8192C = 2,
27 CHIP_8192D = 3,
28 CHIP_8723A = 4,
29 CHIP_8188E = 5,
30 CHIP_8881A = 6,
31 CHIP_8812A = 7,
32 CHIP_8821A = 8,
33 CHIP_8723B = 9,
34 CHIP_8192E = 10,
35};
36
37enum HAL_CHIP_TYPE { 23enum HAL_CHIP_TYPE {
38 TEST_CHIP = 0, 24 TEST_CHIP = 0,
39 NORMAL_CHIP = 1, 25 NORMAL_CHIP = 1,
@@ -55,48 +41,20 @@ enum HAL_VENDOR {
55 CHIP_VENDOR_UMC = 1, 41 CHIP_VENDOR_UMC = 1,
56}; 42};
57 43
58enum HAL_RF_TYPE {
59 RF_TYPE_1T1R = 0,
60 RF_TYPE_1T2R = 1,
61 RF_TYPE_2T2R = 2,
62 RF_TYPE_2T3R = 3,
63 RF_TYPE_2T4R = 4,
64 RF_TYPE_3T3R = 5,
65 RF_TYPE_3T4R = 6,
66 RF_TYPE_4T4R = 7,
67};
68
69struct HAL_VERSION { 44struct HAL_VERSION {
70 enum HAL_IC_TYPE ICType;
71 enum HAL_CHIP_TYPE ChipType; 45 enum HAL_CHIP_TYPE ChipType;
72 enum HAL_CUT_VERSION CUTVersion; 46 enum HAL_CUT_VERSION CUTVersion;
73 enum HAL_VENDOR VendorType; 47 enum HAL_VENDOR VendorType;
74 enum HAL_RF_TYPE RFType;
75 u8 ROMVer;
76}; 48};
77 49
78/* Get element */ 50/* Get element */
79#define GET_CVID_IC_TYPE(version) (((version).ICType))
80#define GET_CVID_CHIP_TYPE(version) (((version).ChipType)) 51#define GET_CVID_CHIP_TYPE(version) (((version).ChipType))
81#define GET_CVID_RF_TYPE(version) (((version).RFType))
82#define GET_CVID_MANUFACTUER(version) (((version).VendorType)) 52#define GET_CVID_MANUFACTUER(version) (((version).VendorType))
83#define GET_CVID_CUT_VERSION(version) (((version).CUTVersion)) 53#define GET_CVID_CUT_VERSION(version) (((version).CUTVersion))
84#define GET_CVID_ROM_VERSION(version) (((version).ROMVer) & ROM_VERSION_MASK)
85 54
86/* Common Macro. -- */ 55/* Common Macro. -- */
87/* HAL_VERSION VersionID */ 56/* HAL_VERSION VersionID */
88 57
89/* HAL_IC_TYPE_E */
90#define IS_81XXC(version) \
91 (((GET_CVID_IC_TYPE(version) == CHIP_8192C) || \
92 (GET_CVID_IC_TYPE(version) == CHIP_8188C)) ? true : false)
93#define IS_8723_SERIES(version) \
94 ((GET_CVID_IC_TYPE(version) == CHIP_8723A) ? true : false)
95#define IS_92D(version) \
96 ((GET_CVID_IC_TYPE(version) == CHIP_8192D) ? true : false)
97#define IS_8188E(version) \
98 ((GET_CVID_IC_TYPE(version) == CHIP_8188E) ? true : false)
99
100/* HAL_CHIP_TYPE_E */ 58/* HAL_CHIP_TYPE_E */
101#define IS_TEST_CHIP(version) \ 59#define IS_TEST_CHIP(version) \
102 ((GET_CVID_CHIP_TYPE(version) == TEST_CHIP) ? true : false) 60 ((GET_CVID_CHIP_TYPE(version) == TEST_CHIP) ? true : false)
@@ -122,46 +80,4 @@ struct HAL_VERSION {
122#define IS_CHIP_VENDOR_UMC(version) \ 80#define IS_CHIP_VENDOR_UMC(version) \
123 ((GET_CVID_MANUFACTUER(version) == CHIP_VENDOR_UMC) ? true : false) 81 ((GET_CVID_MANUFACTUER(version) == CHIP_VENDOR_UMC) ? true : false)
124 82
125/* HAL_RF_TYPE_E */
126#define IS_1T1R(version) \
127 ((GET_CVID_RF_TYPE(version) == RF_TYPE_1T1R) ? true : false)
128#define IS_1T2R(version) \
129 ((GET_CVID_RF_TYPE(version) == RF_TYPE_1T2R) ? true : false)
130#define IS_2T2R(version) \
131 ((GET_CVID_RF_TYPE(version) == RF_TYPE_2T2R) ? true : false)
132
133/* Chip version Macro. -- */
134#define IS_81XXC_TEST_CHIP(version) \
135 ((IS_81XXC(version) && (!IS_NORMAL_CHIP(version))) ? true : false)
136
137#define IS_92C_SERIAL(version) \
138 ((IS_81XXC(version) && IS_2T2R(version)) ? true : false)
139#define IS_81xxC_VENDOR_UMC_A_CUT(version) \
140 (IS_81XXC(version) ? (IS_CHIP_VENDOR_UMC(version) ? \
141 (IS_A_CUT(version) ? true : false) : false) : false)
142#define IS_81xxC_VENDOR_UMC_B_CUT(version) \
143 (IS_81XXC(version) ? (IS_CHIP_VENDOR_UMC(version) ? \
144 (IS_B_CUT(version) ? true : false) : false) : false)
145#define IS_81xxC_VENDOR_UMC_C_CUT(version) \
146 (IS_81XXC(version) ? (IS_CHIP_VENDOR_UMC(version) ? \
147 (IS_C_CUT(version) ? true : false) : false) : false)
148
149#define IS_NORMAL_CHIP92D(version) \
150 ((IS_92D(version)) ? \
151 ((GET_CVID_CHIP_TYPE(version) == NORMAL_CHIP) ? true : false) : false)
152
153#define IS_92D_SINGLEPHY(version) \
154 ((IS_92D(version)) ? (IS_2T2R(version) ? true : false) : false)
155#define IS_92D_C_CUT(version) \
156 ((IS_92D(version)) ? (IS_C_CUT(version) ? true : false) : false)
157#define IS_92D_D_CUT(version) \
158 ((IS_92D(version)) ? (IS_D_CUT(version) ? true : false) : false)
159#define IS_92D_E_CUT(version) \
160 ((IS_92D(version)) ? (IS_E_CUT(version) ? true : false) : false)
161
162#define IS_8723A_A_CUT(version) \
163 ((IS_8723_SERIES(version)) ? (IS_A_CUT(version) ? true : false) : false)
164#define IS_8723A_B_CUT(version) \
165 ((IS_8723_SERIES(version)) ? (IS_B_CUT(version) ? true : false) : false)
166
167#endif 83#endif
diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
index 3b476d80f64d..e73c6341248e 100644
--- a/drivers/staging/rtl8188eu/include/hal_intf.h
+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
@@ -171,8 +171,6 @@ struct hal_ops {
171 171
172 void (*read_adapter_info)(struct adapter *padapter); 172 void (*read_adapter_info)(struct adapter *padapter);
173 173
174 void (*enable_interrupt)(struct adapter *padapter);
175 void (*disable_interrupt)(struct adapter *padapter);
176 s32 (*interrupt_handler)(struct adapter *padapter); 174 s32 (*interrupt_handler)(struct adapter *padapter);
177 175
178 void (*set_bwmode_handler)(struct adapter *padapter, 176 void (*set_bwmode_handler)(struct adapter *padapter,
@@ -190,9 +188,6 @@ struct hal_ops {
190 u8 (*GetHalDefVarHandler)(struct adapter *padapter, 188 u8 (*GetHalDefVarHandler)(struct adapter *padapter,
191 enum hal_def_variable eVariable, 189 enum hal_def_variable eVariable,
192 void *pValue); 190 void *pValue);
193 u8 (*SetHalDefVarHandler)(struct adapter *padapter,
194 enum hal_def_variable eVariable,
195 void *pValue);
196 191
197 void (*SetHalODMVarHandler)(struct adapter *padapter, 192 void (*SetHalODMVarHandler)(struct adapter *padapter,
198 enum hal_odm_variable eVariable, 193 enum hal_odm_variable eVariable,
@@ -216,9 +211,6 @@ struct hal_ops {
216 u32 (*read_rfreg)(struct adapter *padapter, 211 u32 (*read_rfreg)(struct adapter *padapter,
217 enum rf_radio_path eRFPath, u32 RegAddr, 212 enum rf_radio_path eRFPath, u32 RegAddr,
218 u32 BitMask); 213 u32 BitMask);
219 void (*write_rfreg)(struct adapter *padapter,
220 enum rf_radio_path eRFPath, u32 RegAddr,
221 u32 BitMask, u32 Data);
222 214
223 void (*sreset_init_value)(struct adapter *padapter); 215 void (*sreset_init_value)(struct adapter *padapter);
224 u8 (*sreset_get_wifi_status)(struct adapter *padapter); 216 u8 (*sreset_get_wifi_status)(struct adapter *padapter);
@@ -267,8 +259,6 @@ void rtw_hal_chip_configure(struct adapter *padapter);
267void rtw_hal_read_chip_info(struct adapter *padapter); 259void rtw_hal_read_chip_info(struct adapter *padapter);
268void rtw_hal_read_chip_version(struct adapter *padapter); 260void rtw_hal_read_chip_version(struct adapter *padapter);
269 261
270u8 rtw_hal_set_def_var(struct adapter *padapter,
271 enum hal_def_variable eVariable, void *pValue);
272u8 rtw_hal_get_def_var(struct adapter *padapter, 262u8 rtw_hal_get_def_var(struct adapter *padapter,
273 enum hal_def_variable eVariable, void *pValue); 263 enum hal_def_variable eVariable, void *pValue);
274 264
@@ -276,9 +266,6 @@ void rtw_hal_set_odm_var(struct adapter *padapter,
276 enum hal_odm_variable eVariable, void *pValue1, 266 enum hal_odm_variable eVariable, void *pValue1,
277 bool bSet); 267 bool bSet);
278 268
279void rtw_hal_enable_interrupt(struct adapter *padapter);
280void rtw_hal_disable_interrupt(struct adapter *padapter);
281
282u32 rtw_hal_inirp_init(struct adapter *padapter); 269u32 rtw_hal_inirp_init(struct adapter *padapter);
283u32 rtw_hal_inirp_deinit(struct adapter *padapter); 270u32 rtw_hal_inirp_deinit(struct adapter *padapter);
284 271
@@ -300,9 +287,6 @@ void rtw_hal_bcn_related_reg_setting(struct adapter *padapter);
300 287
301u32 rtw_hal_read_rfreg(struct adapter *padapter, enum rf_radio_path eRFPath, 288u32 rtw_hal_read_rfreg(struct adapter *padapter, enum rf_radio_path eRFPath,
302 u32 RegAddr, u32 BitMask); 289 u32 RegAddr, u32 BitMask);
303void rtw_hal_write_rfreg(struct adapter *padapter,
304 enum rf_radio_path eRFPath, u32 RegAddr,
305 u32 BitMask, u32 Data);
306 290
307void rtw_hal_set_bwmode(struct adapter *padapter, 291void rtw_hal_set_bwmode(struct adapter *padapter,
308 enum ht_channel_width Bandwidth, u8 Offset); 292 enum ht_channel_width Bandwidth, u8 Offset);
diff --git a/drivers/staging/rtl8188eu/include/ieee80211.h b/drivers/staging/rtl8188eu/include/ieee80211.h
index b129ad148b47..6400f75707bd 100644
--- a/drivers/staging/rtl8188eu/include/ieee80211.h
+++ b/drivers/staging/rtl8188eu/include/ieee80211.h
@@ -477,63 +477,9 @@ struct ieee80211_snap_hdr {
477#define WLAN_GET_SEQ_FRAG(seq) ((seq) & RTW_IEEE80211_SCTL_FRAG) 477#define WLAN_GET_SEQ_FRAG(seq) ((seq) & RTW_IEEE80211_SCTL_FRAG)
478#define WLAN_GET_SEQ_SEQ(seq) ((seq) & RTW_IEEE80211_SCTL_SEQ) 478#define WLAN_GET_SEQ_SEQ(seq) ((seq) & RTW_IEEE80211_SCTL_SEQ)
479 479
480/* Authentication algorithms */
481#define WLAN_AUTH_OPEN 0
482#define WLAN_AUTH_SHARED_KEY 1
483
484#define WLAN_AUTH_CHALLENGE_LEN 128
485
486#define WLAN_CAPABILITY_BSS (1<<0)
487#define WLAN_CAPABILITY_IBSS (1<<1)
488#define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
489#define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
490#define WLAN_CAPABILITY_PRIVACY (1<<4)
491#define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
492#define WLAN_CAPABILITY_PBCC (1<<6)
493#define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
494#define WLAN_CAPABILITY_SHORT_SLOT (1<<10)
495
496/* Non standard? Not in <linux/ieee80211.h> */ 480/* Non standard? Not in <linux/ieee80211.h> */
497#define WLAN_REASON_EXPIRATION_CHK 65535 481#define WLAN_REASON_EXPIRATION_CHK 65535
498 482
499/* Information Element IDs */
500#define WLAN_EID_SSID 0
501#define WLAN_EID_SUPP_RATES 1
502#define WLAN_EID_FH_PARAMS 2
503#define WLAN_EID_DS_PARAMS 3
504#define WLAN_EID_CF_PARAMS 4
505#define WLAN_EID_TIM 5
506#define WLAN_EID_IBSS_PARAMS 6
507#define WLAN_EID_CHALLENGE 16
508/* EIDs defined by IEEE 802.11h - START */
509#define WLAN_EID_PWR_CONSTRAINT 32
510#define WLAN_EID_PWR_CAPABILITY 33
511#define WLAN_EID_TPC_REQUEST 34
512#define WLAN_EID_TPC_REPORT 35
513#define WLAN_EID_SUPPORTED_CHANNELS 36
514#define WLAN_EID_CHANNEL_SWITCH 37
515#define WLAN_EID_MEASURE_REQUEST 38
516#define WLAN_EID_MEASURE_REPORT 39
517#define WLAN_EID_QUITE 40
518#define WLAN_EID_IBSS_DFS 41
519/* EIDs defined by IEEE 802.11h - END */
520#define WLAN_EID_ERP_INFO 42
521#define WLAN_EID_HT_CAP 45
522#define WLAN_EID_RSN 48
523#define WLAN_EID_EXT_SUPP_RATES 50
524#define WLAN_EID_MOBILITY_DOMAIN 54
525#define WLAN_EID_FAST_BSS_TRANSITION 55
526#define WLAN_EID_TIMEOUT_INTERVAL 56
527#define WLAN_EID_RIC_DATA 57
528#define WLAN_EID_HT_OPERATION 61
529#define WLAN_EID_SECONDARY_CHANNEL_OFFSET 62
530#define WLAN_EID_20_40_BSS_COEXISTENCE 72
531#define WLAN_EID_20_40_BSS_INTOLERANT 73
532#define WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS 74
533#define WLAN_EID_MMIE 76
534#define WLAN_EID_VENDOR_SPECIFIC 221
535#define WLAN_EID_GENERIC (WLAN_EID_VENDOR_SPECIFIC)
536
537#define IEEE80211_MGMT_HDR_LEN 24 483#define IEEE80211_MGMT_HDR_LEN 24
538#define IEEE80211_DATA_HDR3_LEN 24 484#define IEEE80211_DATA_HDR3_LEN 24
539#define IEEE80211_DATA_HDR4_LEN 30 485#define IEEE80211_DATA_HDR4_LEN 30
diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h b/drivers/staging/rtl8188eu/include/osdep_service.h
index 00472e0c00a0..cf9ca685eb77 100644
--- a/drivers/staging/rtl8188eu/include/osdep_service.h
+++ b/drivers/staging/rtl8188eu/include/osdep_service.h
@@ -123,7 +123,7 @@ static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)
123#define BIT35 0x0800000000 123#define BIT35 0x0800000000
124#define BIT36 0x1000000000 124#define BIT36 0x1000000000
125 125
126extern int RTW_STATUS_CODE(int error_code); 126int RTW_STATUS_CODE(int error_code);
127 127
128#define rtw_update_mem_stat(flag, sz) do {} while (0) 128#define rtw_update_mem_stat(flag, sz) do {} while (0)
129u8 *_rtw_malloc(u32 sz); 129u8 *_rtw_malloc(u32 sz);
diff --git a/drivers/staging/rtl8188eu/include/recv_osdep.h b/drivers/staging/rtl8188eu/include/recv_osdep.h
index 0809963ce6aa..fdeb603b6cc1 100644
--- a/drivers/staging/rtl8188eu/include/recv_osdep.h
+++ b/drivers/staging/rtl8188eu/include/recv_osdep.h
@@ -38,8 +38,7 @@ void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup);
38int rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter); 38int rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter);
39void rtw_free_recv_priv(struct recv_priv *precvpriv); 39void rtw_free_recv_priv(struct recv_priv *precvpriv);
40 40
41int rtw_os_recv_resource_alloc(struct adapter *adapt, 41void rtw_os_recv_resource_alloc(struct recv_frame *recvfr);
42 struct recv_frame *recvfr);
43 42
44int rtw_os_recvbuf_resource_alloc(struct adapter *adapt, struct recv_buf *buf); 43int rtw_os_recvbuf_resource_alloc(struct adapter *adapt, struct recv_buf *buf);
45 44
diff --git a/drivers/staging/rtl8188eu/include/rtl8188e_cmd.h b/drivers/staging/rtl8188eu/include/rtl8188e_cmd.h
index 42b1f22424eb..f813ce0563f8 100644
--- a/drivers/staging/rtl8188eu/include/rtl8188e_cmd.h
+++ b/drivers/staging/rtl8188eu/include/rtl8188e_cmd.h
@@ -107,7 +107,6 @@ struct P2P_PS_CTWPeriod_t {
107/* host message to firmware cmd */ 107/* host message to firmware cmd */
108void rtl8188e_set_FwPwrMode_cmd(struct adapter *padapter, u8 Mode); 108void rtl8188e_set_FwPwrMode_cmd(struct adapter *padapter, u8 Mode);
109void rtl8188e_set_FwJoinBssReport_cmd(struct adapter *padapter, u8 mstatus); 109void rtl8188e_set_FwJoinBssReport_cmd(struct adapter *padapter, u8 mstatus);
110u8 rtl8188e_set_raid_cmd(struct adapter *padapter, u32 mask);
111void rtl8188e_Add_RateATid(struct adapter *padapter, u32 bitmap, u8 arg, 110void rtl8188e_Add_RateATid(struct adapter *padapter, u32 bitmap, u8 arg,
112 u8 rssi_level); 111 u8 rssi_level);
113 112
diff --git a/drivers/staging/rtl8188eu/include/rtl8188e_hal.h b/drivers/staging/rtl8188eu/include/rtl8188e_hal.h
index 7d8e022925e0..cbad364f189c 100644
--- a/drivers/staging/rtl8188eu/include/rtl8188e_hal.h
+++ b/drivers/staging/rtl8188eu/include/rtl8188e_hal.h
@@ -188,15 +188,8 @@ struct txpowerinfo24g {
188 188
189#define EFUSE_PROTECT_BYTES_BANK 16 189#define EFUSE_PROTECT_BYTES_BANK 16
190 190
191/* For RTL8723 regulator mode. */
192enum rt_regulator_mode {
193 RT_SWITCHING_REGULATOR = 0,
194 RT_LDO_REGULATOR = 1,
195};
196
197struct hal_data_8188e { 191struct hal_data_8188e {
198 struct HAL_VERSION VersionID; 192 struct HAL_VERSION VersionID;
199 enum rt_regulator_mode RegulatorMode; /* switching regulator or LDO */
200 u16 CustomerID; 193 u16 CustomerID;
201 u8 *pfirmware; 194 u8 *pfirmware;
202 u32 fwsize; 195 u32 fwsize;
@@ -301,7 +294,6 @@ struct hal_data_8188e {
301 /* for host message to fw */ 294 /* for host message to fw */
302 u8 LastHMEBoxNum; 295 u8 LastHMEBoxNum;
303 296
304 u8 fw_ractrl;
305 u8 RegTxPause; 297 u8 RegTxPause;
306 /* Beacon function related global variable. */ 298 /* Beacon function related global variable. */
307 u32 RegBcnCtrlVal; 299 u32 RegBcnCtrlVal;
diff --git a/drivers/staging/rtl8188eu/include/rtw_mlme.h b/drivers/staging/rtl8188eu/include/rtw_mlme.h
index 8c7e8a36aa13..4c992573e3ca 100644
--- a/drivers/staging/rtl8188eu/include/rtw_mlme.h
+++ b/drivers/staging/rtl8188eu/include/rtw_mlme.h
@@ -535,7 +535,8 @@ void rtw_generate_random_ibss(u8 *pibss);
535struct wlan_network *rtw_find_network(struct __queue *scanned_queue, u8 *addr); 535struct wlan_network *rtw_find_network(struct __queue *scanned_queue, u8 *addr);
536struct wlan_network *rtw_get_oldest_wlan_network(struct __queue *scanned_queue); 536struct wlan_network *rtw_get_oldest_wlan_network(struct __queue *scanned_queue);
537 537
538void rtw_free_assoc_resources(struct adapter *adapter, int lock_scanned_queue); 538void rtw_free_assoc_resources(struct adapter *adapter);
539void rtw_free_assoc_resources_locked(struct adapter *adapter);
539void rtw_indicate_disconnect(struct adapter *adapter); 540void rtw_indicate_disconnect(struct adapter *adapter);
540void rtw_indicate_connect(struct adapter *adapter); 541void rtw_indicate_connect(struct adapter *adapter);
541void rtw_indicate_scan_done(struct adapter *padapter, bool aborted); 542void rtw_indicate_scan_done(struct adapter *padapter, bool aborted);
diff --git a/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h b/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
index 2417809f3aef..9093a5f94d32 100644
--- a/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
+++ b/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
@@ -457,9 +457,9 @@ struct mlme_ext_priv {
457int init_mlme_ext_priv(struct adapter *adapter); 457int init_mlme_ext_priv(struct adapter *adapter);
458int init_hw_mlme_ext(struct adapter *padapter); 458int init_hw_mlme_ext(struct adapter *padapter);
459void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext); 459void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext);
460extern void init_mlme_ext_timer(struct adapter *padapter); 460void init_mlme_ext_timer(struct adapter *padapter);
461extern void init_addba_retry_timer(struct adapter *adapt, struct sta_info *sta); 461void init_addba_retry_timer(struct adapter *adapt, struct sta_info *sta);
462extern struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv); 462struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv);
463 463
464unsigned char networktype_to_raid(unsigned char network_type); 464unsigned char networktype_to_raid(unsigned char network_type);
465u8 judge_network_type(struct adapter *padapter, unsigned char *rate, int len); 465u8 judge_network_type(struct adapter *padapter, unsigned char *rate, int len);
@@ -554,7 +554,7 @@ void report_add_sta_event(struct adapter *padapter, unsigned char *addr,
554 int cam_idx); 554 int cam_idx);
555 555
556void beacon_timing_control(struct adapter *padapter); 556void beacon_timing_control(struct adapter *padapter);
557extern u8 set_tx_beacon_cmd(struct adapter *padapter); 557u8 set_tx_beacon_cmd(struct adapter *padapter);
558unsigned int setup_beacon_frame(struct adapter *padapter, 558unsigned int setup_beacon_frame(struct adapter *padapter,
559 unsigned char *beacon_frame); 559 unsigned char *beacon_frame);
560void update_mgnt_tx_rate(struct adapter *padapter, u8 rate); 560void update_mgnt_tx_rate(struct adapter *padapter, u8 rate);
diff --git a/drivers/staging/rtl8188eu/include/rtw_pwrctrl.h b/drivers/staging/rtl8188eu/include/rtw_pwrctrl.h
index aa1fd87c47fb..a493d4c37ef1 100644
--- a/drivers/staging/rtl8188eu/include/rtw_pwrctrl.h
+++ b/drivers/staging/rtl8188eu/include/rtw_pwrctrl.h
@@ -257,7 +257,6 @@ s32 LPS_RF_ON_check(struct adapter *adapter, u32 delay_ms);
257void LPS_Enter(struct adapter *adapter); 257void LPS_Enter(struct adapter *adapter);
258void LPS_Leave(struct adapter *adapter); 258void LPS_Leave(struct adapter *adapter);
259 259
260void rtw_set_ips_deny(struct adapter *adapter, u32 ms);
261int _rtw_pwr_wakeup(struct adapter *adapter, u32 ips_defer_ms, 260int _rtw_pwr_wakeup(struct adapter *adapter, u32 ips_defer_ms,
262 const char *caller); 261 const char *caller);
263#define rtw_pwr_wakeup(adapter) \ 262#define rtw_pwr_wakeup(adapter) \
diff --git a/drivers/staging/rtl8188eu/include/sta_info.h b/drivers/staging/rtl8188eu/include/sta_info.h
index 9612490539b3..d4e78326fc8d 100644
--- a/drivers/staging/rtl8188eu/include/sta_info.h
+++ b/drivers/staging/rtl8188eu/include/sta_info.h
@@ -113,7 +113,6 @@ struct sta_info {
113 113
114 u8 raid; 114 u8 raid;
115 u8 init_rate; 115 u8 init_rate;
116 u32 ra_mask;
117 u8 wireless_mode; /* NETWORK_TYPE */ 116 u8 wireless_mode; /* NETWORK_TYPE */
118 struct stainfo_stats sta_stats; 117 struct stainfo_stats sta_stats;
119 118
@@ -351,19 +350,19 @@ static inline u32 wifi_mac_hash(u8 *mac)
351 return x; 350 return x;
352} 351}
353 352
354extern u32 _rtw_init_sta_priv(struct sta_priv *pstapriv); 353u32 _rtw_init_sta_priv(struct sta_priv *pstapriv);
355extern u32 _rtw_free_sta_priv(struct sta_priv *pstapriv); 354u32 _rtw_free_sta_priv(struct sta_priv *pstapriv);
356 355
357#define stainfo_offset_valid(offset) (offset < NUM_STA && offset >= 0) 356#define stainfo_offset_valid(offset) (offset < NUM_STA && offset >= 0)
358int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta); 357int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta);
359struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int off); 358struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int off);
360 359
361extern struct sta_info *rtw_alloc_stainfo(struct sta_priv *stapriv, u8 *hwaddr); 360struct sta_info *rtw_alloc_stainfo(struct sta_priv *stapriv, u8 *hwaddr);
362extern u32 rtw_free_stainfo(struct adapter *adapt, struct sta_info *psta); 361u32 rtw_free_stainfo(struct adapter *adapt, struct sta_info *psta);
363extern void rtw_free_all_stainfo(struct adapter *adapt); 362void rtw_free_all_stainfo(struct adapter *adapt);
364extern struct sta_info *rtw_get_stainfo(struct sta_priv *stapriv, u8 *hwaddr); 363struct sta_info *rtw_get_stainfo(struct sta_priv *stapriv, u8 *hwaddr);
365extern u32 rtw_init_bcmc_stainfo(struct adapter *adapt); 364u32 rtw_init_bcmc_stainfo(struct adapter *adapt);
366extern struct sta_info *rtw_get_bcmc_stainfo(struct adapter *padapter); 365struct sta_info *rtw_get_bcmc_stainfo(struct adapter *padapter);
367extern u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr); 366u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr);
368 367
369#endif /* _STA_INFO_H_ */ 368#endif /* _STA_INFO_H_ */
diff --git a/drivers/staging/rtl8188eu/include/wifi.h b/drivers/staging/rtl8188eu/include/wifi.h
index a08a2e045e59..dba8af1ec41e 100644
--- a/drivers/staging/rtl8188eu/include/wifi.h
+++ b/drivers/staging/rtl8188eu/include/wifi.h
@@ -649,13 +649,6 @@ enum ht_cap_ampdu_factor {
649#define IEEE80211_MAX_AMPDU_BUF 0x40 649#define IEEE80211_MAX_AMPDU_BUF 0x40
650 650
651 651
652/* Spatial Multiplexing Power Save Modes */
653#define WLAN_HT_CAP_SM_PS_STATIC 0
654#define WLAN_HT_CAP_SM_PS_DYNAMIC 1
655#define WLAN_HT_CAP_SM_PS_INVALID 2
656#define WLAN_HT_CAP_SM_PS_DISABLED 3
657
658
659#define OP_MODE_PURE 0 652#define OP_MODE_PURE 0
660#define OP_MODE_MAY_BE_LEGACY_STAS 1 653#define OP_MODE_MAY_BE_LEGACY_STAS 1
661#define OP_MODE_20MHZ_HT_STA_ASSOCED 2 654#define OP_MODE_20MHZ_HT_STA_ASSOCED 2
diff --git a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
index 38dba1435c1e..969574926e21 100644
--- a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
@@ -179,8 +179,8 @@ static char *translate_scan(struct adapter *padapter,
179 179
180 cap = le16_to_cpu(le_tmp); 180 cap = le16_to_cpu(le_tmp);
181 181
182 if (cap & (WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_BSS)) { 182 if (!WLAN_CAPABILITY_IS_STA_BSS(cap)) {
183 if (cap & WLAN_CAPABILITY_BSS) 183 if (cap & WLAN_CAPABILITY_ESS)
184 iwe.u.mode = IW_MODE_MASTER; 184 iwe.u.mode = IW_MODE_MASTER;
185 else 185 else
186 iwe.u.mode = IW_MODE_ADHOC; 186 iwe.u.mode = IW_MODE_ADHOC;
@@ -1871,7 +1871,7 @@ static int rtw_wx_set_auth(struct net_device *dev,
1871 rtw_disassoc_cmd(padapter, 500, false); 1871 rtw_disassoc_cmd(padapter, 500, false);
1872 DBG_88E("%s...call rtw_indicate_disconnect\n ", __func__); 1872 DBG_88E("%s...call rtw_indicate_disconnect\n ", __func__);
1873 rtw_indicate_disconnect(padapter); 1873 rtw_indicate_disconnect(padapter);
1874 rtw_free_assoc_resources(padapter, 1); 1874 rtw_free_assoc_resources(padapter);
1875 } 1875 }
1876 ret = wpa_set_auth_algs(dev, (u32)param->value); 1876 ret = wpa_set_auth_algs(dev, (u32)param->value);
1877 break; 1877 break;
@@ -2485,16 +2485,13 @@ static int rtw_set_beacon(struct net_device *dev, struct ieee_param *param, int
2485 2485
2486static int rtw_hostapd_sta_flush(struct net_device *dev) 2486static int rtw_hostapd_sta_flush(struct net_device *dev)
2487{ 2487{
2488 int ret = 0;
2489 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 2488 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2490 2489
2491 DBG_88E("%s\n", __func__); 2490 DBG_88E("%s\n", __func__);
2492 2491
2493 flush_all_cam_entry(padapter); /* clear CAM */ 2492 flush_all_cam_entry(padapter); /* clear CAM */
2494 2493
2495 ret = rtw_sta_flush(padapter); 2494 return rtw_sta_flush(padapter);
2496
2497 return ret;
2498} 2495}
2499 2496
2500static int rtw_add_sta(struct net_device *dev, struct ieee_param *param) 2497static int rtw_add_sta(struct net_device *dev, struct ieee_param *param)
@@ -2666,7 +2663,8 @@ static int rtw_get_sta_wpaie(struct net_device *dev, struct ieee_param *param)
2666 2663
2667 psta = rtw_get_stainfo(pstapriv, param->sta_addr); 2664 psta = rtw_get_stainfo(pstapriv, param->sta_addr);
2668 if (psta) { 2665 if (psta) {
2669 if ((psta->wpa_ie[0] == WLAN_EID_RSN) || (psta->wpa_ie[0] == WLAN_EID_GENERIC)) { 2666 if (psta->wpa_ie[0] == WLAN_EID_RSN ||
2667 psta->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
2670 int wpa_ie_len; 2668 int wpa_ie_len;
2671 int copy_len; 2669 int copy_len;
2672 2670
@@ -2809,7 +2807,6 @@ static int rtw_set_hidden_ssid(struct net_device *dev, struct ieee_param *param,
2809 2807
2810static int rtw_ioctl_acl_remove_sta(struct net_device *dev, struct ieee_param *param, int len) 2808static int rtw_ioctl_acl_remove_sta(struct net_device *dev, struct ieee_param *param, int len)
2811{ 2809{
2812 int ret = 0;
2813 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 2810 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2814 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 2811 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2815 2812
@@ -2820,13 +2817,11 @@ static int rtw_ioctl_acl_remove_sta(struct net_device *dev, struct ieee_param *p
2820 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && 2817 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
2821 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) 2818 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
2822 return -EINVAL; 2819 return -EINVAL;
2823 ret = rtw_acl_remove_sta(padapter, param->sta_addr); 2820 return rtw_acl_remove_sta(padapter, param->sta_addr);
2824 return ret;
2825} 2821}
2826 2822
2827static int rtw_ioctl_acl_add_sta(struct net_device *dev, struct ieee_param *param, int len) 2823static int rtw_ioctl_acl_add_sta(struct net_device *dev, struct ieee_param *param, int len)
2828{ 2824{
2829 int ret = 0;
2830 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 2825 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2831 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 2826 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2832 2827
@@ -2837,8 +2832,7 @@ static int rtw_ioctl_acl_add_sta(struct net_device *dev, struct ieee_param *para
2837 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && 2832 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
2838 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) 2833 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
2839 return -EINVAL; 2834 return -EINVAL;
2840 ret = rtw_acl_add_sta(padapter, param->sta_addr); 2835 return rtw_acl_add_sta(padapter, param->sta_addr);
2841 return ret;
2842} 2836}
2843 2837
2844static int rtw_ioctl_set_macaddr_acl(struct net_device *dev, struct ieee_param *param, int len) 2838static int rtw_ioctl_set_macaddr_acl(struct net_device *dev, struct ieee_param *param, int len)
diff --git a/drivers/staging/rtl8188eu/os_dep/os_intfs.c b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
index a14e79f31abf..2361bce480c3 100644
--- a/drivers/staging/rtl8188eu/os_dep/os_intfs.c
+++ b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
@@ -1175,7 +1175,7 @@ static int netdev_close(struct net_device *pnetdev)
1175 /* s2-2. indicate disconnect to os */ 1175 /* s2-2. indicate disconnect to os */
1176 rtw_indicate_disconnect(padapter); 1176 rtw_indicate_disconnect(padapter);
1177 /* s2-3. */ 1177 /* s2-3. */
1178 rtw_free_assoc_resources(padapter, 1); 1178 rtw_free_assoc_resources(padapter);
1179 /* s2-4. */ 1179 /* s2-4. */
1180 rtw_free_network_queue(padapter, true); 1180 rtw_free_network_queue(padapter, true);
1181 /* Close LED */ 1181 /* Close LED */
diff --git a/drivers/staging/rtl8188eu/os_dep/recv_linux.c b/drivers/staging/rtl8188eu/os_dep/recv_linux.c
index 05701328dce4..3ebb8b206e46 100644
--- a/drivers/staging/rtl8188eu/os_dep/recv_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/recv_linux.c
@@ -17,8 +17,6 @@
17 * 17 *
18 * 18 *
19 ******************************************************************************/ 19 ******************************************************************************/
20#define _RECV_OSDEP_C_
21
22#include <osdep_service.h> 20#include <osdep_service.h>
23#include <drv_types.h> 21#include <drv_types.h>
24 22
@@ -29,26 +27,22 @@
29#include <usb_ops_linux.h> 27#include <usb_ops_linux.h>
30 28
31/* alloc os related resource in struct recv_frame */ 29/* alloc os related resource in struct recv_frame */
32int rtw_os_recv_resource_alloc(struct adapter *padapter, 30void rtw_os_recv_resource_alloc(struct recv_frame *precvframe)
33 struct recv_frame *precvframe)
34{ 31{
35 precvframe->pkt_newalloc = NULL; 32 precvframe->pkt_newalloc = NULL;
36 precvframe->pkt = NULL; 33 precvframe->pkt = NULL;
37 return _SUCCESS;
38} 34}
39 35
40/* alloc os related resource in struct recv_buf */ 36/* alloc os related resource in struct recv_buf */
41int rtw_os_recvbuf_resource_alloc(struct adapter *padapter, 37int rtw_os_recvbuf_resource_alloc(struct adapter *padapter,
42 struct recv_buf *precvbuf) 38 struct recv_buf *precvbuf)
43{ 39{
44 int res = _SUCCESS;
45
46 precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL);
47 if (precvbuf->purb == NULL)
48 res = _FAIL;
49 precvbuf->pskb = NULL; 40 precvbuf->pskb = NULL;
50 precvbuf->reuse = false; 41 precvbuf->reuse = false;
51 return res; 42 precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL);
43 if (!precvbuf->purb)
44 return _FAIL;
45 return _SUCCESS;
52} 46}
53 47
54void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup) 48void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup)
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index d0d4335b444c..33bfe054f867 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -17,8 +17,8 @@
17 * 17 *
18 * 18 *
19 ******************************************************************************/ 19 ******************************************************************************/
20#define _HCI_INTF_C_
21 20
21#define pr_fmt(fmt) "R8188EU: " fmt
22#include <osdep_service.h> 22#include <osdep_service.h>
23#include <drv_types.h> 23#include <drv_types.h>
24#include <recv_osdep.h> 24#include <recv_osdep.h>
@@ -55,7 +55,6 @@ MODULE_DEVICE_TABLE(usb, rtw_usb_id_tbl);
55static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf) 55static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf)
56{ 56{
57 int i; 57 int i;
58 int status = _FAIL;
59 struct dvobj_priv *pdvobjpriv; 58 struct dvobj_priv *pdvobjpriv;
60 struct usb_host_config *phost_conf; 59 struct usb_host_config *phost_conf;
61 struct usb_config_descriptor *pconf_desc; 60 struct usb_config_descriptor *pconf_desc;
@@ -64,10 +63,9 @@ static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf)
64 struct usb_endpoint_descriptor *pendp_desc; 63 struct usb_endpoint_descriptor *pendp_desc;
65 struct usb_device *pusbd; 64 struct usb_device *pusbd;
66 65
67
68 pdvobjpriv = kzalloc(sizeof(*pdvobjpriv), GFP_KERNEL); 66 pdvobjpriv = kzalloc(sizeof(*pdvobjpriv), GFP_KERNEL);
69 if (pdvobjpriv == NULL) 67 if (pdvobjpriv == NULL)
70 goto exit; 68 return NULL;
71 69
72 pdvobjpriv->pusbintf = usb_intf; 70 pdvobjpriv->pusbintf = usb_intf;
73 pusbd = interface_to_usbdev(usb_intf); 71 pusbd = interface_to_usbdev(usb_intf);
@@ -115,20 +113,13 @@ static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf)
115 mutex_init(&pdvobjpriv->usb_vendor_req_mutex); 113 mutex_init(&pdvobjpriv->usb_vendor_req_mutex);
116 pdvobjpriv->usb_vendor_req_buf = kzalloc(MAX_USB_IO_CTL_SIZE, GFP_KERNEL); 114 pdvobjpriv->usb_vendor_req_buf = kzalloc(MAX_USB_IO_CTL_SIZE, GFP_KERNEL);
117 115
118 if (!pdvobjpriv->usb_vendor_req_buf) 116 if (!pdvobjpriv->usb_vendor_req_buf) {
119 goto free_dvobj;
120
121 usb_get_dev(pusbd);
122
123 status = _SUCCESS;
124
125free_dvobj:
126 if (status != _SUCCESS && pdvobjpriv) {
127 usb_set_intfdata(usb_intf, NULL); 117 usb_set_intfdata(usb_intf, NULL);
128 kfree(pdvobjpriv); 118 kfree(pdvobjpriv);
129 pdvobjpriv = NULL; 119 return NULL;
130 } 120 }
131exit: 121 usb_get_dev(pusbd);
122
132 return pdvobjpriv; 123 return pdvobjpriv;
133} 124}
134 125
@@ -136,7 +127,6 @@ static void usb_dvobj_deinit(struct usb_interface *usb_intf)
136{ 127{
137 struct dvobj_priv *dvobj = usb_get_intfdata(usb_intf); 128 struct dvobj_priv *dvobj = usb_get_intfdata(usb_intf);
138 129
139
140 usb_set_intfdata(usb_intf, NULL); 130 usb_set_intfdata(usb_intf, NULL);
141 if (dvobj) { 131 if (dvobj) {
142 /* Modify condition for 92DU DMDP 2010.11.18, by Thomas */ 132 /* Modify condition for 92DU DMDP 2010.11.18, by Thomas */
@@ -150,7 +140,7 @@ static void usb_dvobj_deinit(struct usb_interface *usb_intf)
150 * on sitesurvey for the first time when 140 * on sitesurvey for the first time when
151 * device is up . Reset usb port for sitesurvey 141 * device is up . Reset usb port for sitesurvey
152 * fail issue. */ 142 * fail issue. */
153 DBG_88E("usb attached..., try to reset usb device\n"); 143 pr_debug("usb attached..., try to reset usb device\n");
154 usb_reset_device(interface_to_usbdev(usb_intf)); 144 usb_reset_device(interface_to_usbdev(usb_intf));
155 } 145 }
156 } 146 }
@@ -201,7 +191,7 @@ static void rtw_dev_unload(struct adapter *padapter)
201 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_dev_unload\n")); 191 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_dev_unload\n"));
202 192
203 if (padapter->bup) { 193 if (padapter->bup) {
204 DBG_88E("===> rtw_dev_unload\n"); 194 pr_debug("===> rtw_dev_unload\n");
205 padapter->bDriverStopped = true; 195 padapter->bDriverStopped = true;
206 if (padapter->xmitpriv.ack_tx) 196 if (padapter->xmitpriv.ack_tx)
207 rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_DRV_STOP); 197 rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_DRV_STOP);
@@ -224,7 +214,7 @@ static void rtw_dev_unload(struct adapter *padapter)
224 ("r871x_dev_unload():padapter->bup == false\n")); 214 ("r871x_dev_unload():padapter->bup == false\n"));
225 } 215 }
226 216
227 DBG_88E("<=== rtw_dev_unload\n"); 217 pr_debug("<=== rtw_dev_unload\n");
228 218
229 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-rtw_dev_unload\n")); 219 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-rtw_dev_unload\n"));
230} 220}
@@ -236,16 +226,13 @@ static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
236 struct net_device *pnetdev = padapter->pnetdev; 226 struct net_device *pnetdev = padapter->pnetdev;
237 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 227 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
238 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv; 228 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
239
240 int ret = 0;
241 u32 start_time = jiffies; 229 u32 start_time = jiffies;
242 230
243 231 pr_debug("==> %s (%s:%d)\n", __func__, current->comm, current->pid);
244 DBG_88E("==> %s (%s:%d)\n", __func__, current->comm, current->pid);
245 232
246 if ((!padapter->bup) || (padapter->bDriverStopped) || 233 if ((!padapter->bup) || (padapter->bDriverStopped) ||
247 (padapter->bSurpriseRemoved)) { 234 (padapter->bSurpriseRemoved)) {
248 DBG_88E("padapter->bup=%d bDriverStopped=%d bSurpriseRemoved = %d\n", 235 pr_debug("padapter->bup=%d bDriverStopped=%d bSurpriseRemoved = %d\n",
249 padapter->bup, padapter->bDriverStopped, 236 padapter->bup, padapter->bDriverStopped,
250 padapter->bSurpriseRemoved); 237 padapter->bSurpriseRemoved);
251 goto exit; 238 goto exit;
@@ -267,7 +254,7 @@ static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
267 254
268 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) && 255 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) &&
269 check_fwstate(pmlmepriv, _FW_LINKED)) { 256 check_fwstate(pmlmepriv, _FW_LINKED)) {
270 DBG_88E("%s:%d %s(%pM), length:%d assoc_ssid.length:%d\n", 257 pr_debug("%s:%d %s(%pM), length:%d assoc_ssid.length:%d\n",
271 __func__, __LINE__, 258 __func__, __LINE__,
272 pmlmepriv->cur_network.network.Ssid.Ssid, 259 pmlmepriv->cur_network.network.Ssid.Ssid,
273 pmlmepriv->cur_network.network.MacAddress, 260 pmlmepriv->cur_network.network.MacAddress,
@@ -279,7 +266,7 @@ static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
279 /* s2-2. indicate disconnect to os */ 266 /* s2-2. indicate disconnect to os */
280 rtw_indicate_disconnect(padapter); 267 rtw_indicate_disconnect(padapter);
281 /* s2-3. */ 268 /* s2-3. */
282 rtw_free_assoc_resources(padapter, 1); 269 rtw_free_assoc_resources(padapter);
283 /* s2-4. */ 270 /* s2-4. */
284 rtw_free_network_queue(padapter, true); 271 rtw_free_network_queue(padapter, true);
285 272
@@ -293,10 +280,10 @@ static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
293 rtw_indicate_disconnect(padapter); 280 rtw_indicate_disconnect(padapter);
294 281
295exit: 282exit:
296 DBG_88E("<=== %s return %d.............. in %dms\n", __func__ 283 pr_debug("<=== %s .............. in %dms\n", __func__,
297 , ret, rtw_get_passing_time_ms(start_time)); 284 rtw_get_passing_time_ms(start_time));
298 285
299 return ret; 286 return 0;
300} 287}
301 288
302static int rtw_resume_process(struct adapter *padapter) 289static int rtw_resume_process(struct adapter *padapter)
@@ -306,7 +293,7 @@ static int rtw_resume_process(struct adapter *padapter)
306 int ret = -1; 293 int ret = -1;
307 u32 start_time = jiffies; 294 u32 start_time = jiffies;
308 295
309 DBG_88E("==> %s (%s:%d)\n", __func__, current->comm, current->pid); 296 pr_debug("==> %s (%s:%d)\n", __func__, current->comm, current->pid);
310 297
311 if (padapter) { 298 if (padapter) {
312 pnetdev = padapter->pnetdev; 299 pnetdev = padapter->pnetdev;
@@ -319,7 +306,7 @@ static int rtw_resume_process(struct adapter *padapter)
319 rtw_reset_drv_sw(padapter); 306 rtw_reset_drv_sw(padapter);
320 pwrpriv->bkeepfwalive = false; 307 pwrpriv->bkeepfwalive = false;
321 308
322 DBG_88E("bkeepfwalive(%x)\n", pwrpriv->bkeepfwalive); 309 pr_debug("bkeepfwalive(%x)\n", pwrpriv->bkeepfwalive);
323 if (pm_netdev_open(pnetdev, true) != 0) 310 if (pm_netdev_open(pnetdev, true) != 0)
324 goto exit; 311 goto exit;
325 312
@@ -334,10 +321,9 @@ static int rtw_resume_process(struct adapter *padapter)
334exit: 321exit:
335 if (pwrpriv) 322 if (pwrpriv)
336 pwrpriv->bInSuspend = false; 323 pwrpriv->bInSuspend = false;
337 DBG_88E("<=== %s return %d.............. in %dms\n", __func__, 324 pr_debug("<=== %s return %d.............. in %dms\n", __func__,
338 ret, rtw_get_passing_time_ms(start_time)); 325 ret, rtw_get_passing_time_ms(start_time));
339 326
340
341 return ret; 327 return ret;
342} 328}
343 329
@@ -407,8 +393,8 @@ static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
407 dvobj->pusbdev->do_remote_wakeup = 1; 393 dvobj->pusbdev->do_remote_wakeup = 1;
408 pusb_intf->needs_remote_wakeup = 1; 394 pusb_intf->needs_remote_wakeup = 1;
409 device_init_wakeup(&pusb_intf->dev, 1); 395 device_init_wakeup(&pusb_intf->dev, 1);
410 DBG_88E("\n padapter->pwrctrlpriv.bSupportRemoteWakeup~~~~~~\n"); 396 pr_debug("\n padapter->pwrctrlpriv.bSupportRemoteWakeup~~~~~~\n");
411 DBG_88E("\n padapter->pwrctrlpriv.bSupportRemoteWakeup~~~[%d]~~~\n", 397 pr_debug("\n padapter->pwrctrlpriv.bSupportRemoteWakeup~~~[%d]~~~\n",
412 device_may_wakeup(&pusb_intf->dev)); 398 device_may_wakeup(&pusb_intf->dev));
413 } 399 }
414#endif 400#endif
@@ -416,13 +402,13 @@ static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
416 /* 2012-07-11 Move here to prevent the 8723AS-VAU BT auto 402 /* 2012-07-11 Move here to prevent the 8723AS-VAU BT auto
417 * suspend influence */ 403 * suspend influence */
418 if (usb_autopm_get_interface(pusb_intf) < 0) 404 if (usb_autopm_get_interface(pusb_intf) < 0)
419 DBG_88E("can't get autopm:\n"); 405 pr_debug("can't get autopm:\n");
420 406
421 /* alloc dev name after read efuse. */ 407 /* alloc dev name after read efuse. */
422 rtw_init_netdev_name(pnetdev, padapter->registrypriv.ifname); 408 rtw_init_netdev_name(pnetdev, padapter->registrypriv.ifname);
423 rtw_macaddr_cfg(padapter->eeprompriv.mac_addr); 409 rtw_macaddr_cfg(padapter->eeprompriv.mac_addr);
424 memcpy(pnetdev->dev_addr, padapter->eeprompriv.mac_addr, ETH_ALEN); 410 memcpy(pnetdev->dev_addr, padapter->eeprompriv.mac_addr, ETH_ALEN);
425 DBG_88E("MAC Address from pnetdev->dev_addr = %pM\n", 411 pr_debug("MAC Address from pnetdev->dev_addr = %pM\n",
426 pnetdev->dev_addr); 412 pnetdev->dev_addr);
427 413
428 /* step 6. Tell the network stack we exist */ 414 /* step 6. Tell the network stack we exist */
@@ -431,7 +417,7 @@ static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
431 goto free_hal_data; 417 goto free_hal_data;
432 } 418 }
433 419
434 DBG_88E("bDriverStopped:%d, bSurpriseRemoved:%d, bup:%d, hw_init_completed:%d\n" 420 pr_debug("bDriverStopped:%d, bSurpriseRemoved:%d, bup:%d, hw_init_completed:%d\n"
435 , padapter->bDriverStopped 421 , padapter->bDriverStopped
436 , padapter->bSurpriseRemoved 422 , padapter->bSurpriseRemoved
437 , padapter->bup 423 , padapter->bup
@@ -475,7 +461,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
475 rtw_cancel_all_timer(if1); 461 rtw_cancel_all_timer(if1);
476 462
477 rtw_dev_unload(if1); 463 rtw_dev_unload(if1);
478 DBG_88E("+r871xu_dev_remove, hw_init_completed=%d\n", 464 pr_debug("+r871xu_dev_remove, hw_init_completed=%d\n",
479 if1->hw_init_completed); 465 if1->hw_init_completed);
480 rtw_free_drv_sw(if1); 466 rtw_free_drv_sw(if1);
481 if (pnetdev) 467 if (pnetdev)
@@ -485,7 +471,6 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
485static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid) 471static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
486{ 472{
487 struct adapter *if1 = NULL; 473 struct adapter *if1 = NULL;
488 int status = _FAIL;
489 struct dvobj_priv *dvobj; 474 struct dvobj_priv *dvobj;
490 475
491 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_drv_init\n")); 476 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_drv_init\n"));
@@ -500,19 +485,18 @@ static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device
500 485
501 if1 = rtw_usb_if1_init(dvobj, pusb_intf, pdid); 486 if1 = rtw_usb_if1_init(dvobj, pusb_intf, pdid);
502 if (if1 == NULL) { 487 if (if1 == NULL) {
503 DBG_88E("rtw_init_primarystruct adapter Failed!\n"); 488 pr_debug("rtw_init_primarystruct adapter Failed!\n");
504 goto free_dvobj; 489 goto free_dvobj;
505 } 490 }
506 491
507 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-871x_drv - drv_init, success!\n")); 492 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-871x_drv - drv_init, success!\n"));
508 493
509 status = _SUCCESS; 494 return 0;
510 495
511free_dvobj: 496free_dvobj:
512 if (status != _SUCCESS) 497 usb_dvobj_deinit(pusb_intf);
513 usb_dvobj_deinit(pusb_intf);
514exit: 498exit:
515 return status == _SUCCESS ? 0 : -ENODEV; 499 return -ENODEV;
516} 500}
517 501
518/* 502/*
@@ -524,8 +508,7 @@ static void rtw_dev_remove(struct usb_interface *pusb_intf)
524 struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf); 508 struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
525 struct adapter *padapter = dvobj->if1; 509 struct adapter *padapter = dvobj->if1;
526 510
527 511 pr_debug("+rtw_dev_remove\n");
528 DBG_88E("+rtw_dev_remove\n");
529 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+dev_remove()\n")); 512 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+dev_remove()\n"));
530 513
531 if (!pusb_intf->unregistering) 514 if (!pusb_intf->unregistering)
@@ -541,7 +524,7 @@ static void rtw_dev_remove(struct usb_interface *pusb_intf)
541 usb_dvobj_deinit(pusb_intf); 524 usb_dvobj_deinit(pusb_intf);
542 525
543 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-dev_remove()\n")); 526 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-dev_remove()\n"));
544 DBG_88E("-r871xu_dev_remove, done\n"); 527 pr_debug("-r871xu_dev_remove, done\n");
545} 528}
546 529
547static struct usb_driver rtl8188e_usb_drv = { 530static struct usb_driver rtl8188e_usb_drv = {
diff --git a/drivers/staging/rtl8192e/dot11d.c b/drivers/staging/rtl8192e/dot11d.c
index ef9da863c335..fcf9b3bcf76a 100644
--- a/drivers/staging/rtl8192e/dot11d.c
+++ b/drivers/staging/rtl8192e/dot11d.c
@@ -160,21 +160,6 @@ void Dot11d_UpdateCountryIe(struct rtllib_device *dev, u8 *pTaddr,
160 pDot11dInfo->State = DOT11D_STATE_LEARNED; 160 pDot11dInfo->State = DOT11D_STATE_LEARNED;
161} 161}
162 162
163u8 DOT11D_GetMaxTxPwrInDbm(struct rtllib_device *dev, u8 Channel)
164{
165 struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev);
166 u8 MaxTxPwrInDbm = 255;
167
168 if (MAX_CHANNEL_NUMBER < Channel) {
169 netdev_info(dev->dev, "DOT11D_GetMaxTxPwrInDbm(): Invalid Channel\n");
170 return MaxTxPwrInDbm;
171 }
172 if (pDot11dInfo->channel_map[Channel])
173 MaxTxPwrInDbm = pDot11dInfo->MaxTxPwrDbmList[Channel];
174
175 return MaxTxPwrInDbm;
176}
177
178void DOT11D_ScanComplete(struct rtllib_device *dev) 163void DOT11D_ScanComplete(struct rtllib_device *dev)
179{ 164{
180 struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev); 165 struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev);
@@ -190,27 +175,3 @@ void DOT11D_ScanComplete(struct rtllib_device *dev)
190 break; 175 break;
191 } 176 }
192} 177}
193
194int ToLegalChannel(struct rtllib_device *dev, u8 channel)
195{
196 struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev);
197 u8 default_chn = 0;
198 u32 i;
199
200 for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) {
201 if (pDot11dInfo->channel_map[i] > 0) {
202 default_chn = i;
203 break;
204 }
205 }
206
207 if (MAX_CHANNEL_NUMBER < channel) {
208 netdev_err(dev->dev, "%s(): Invalid Channel\n", __func__);
209 return default_chn;
210 }
211
212 if (pDot11dInfo->channel_map[channel] > 0)
213 return channel;
214
215 return default_chn;
216}
diff --git a/drivers/staging/rtl8192e/dot11d.h b/drivers/staging/rtl8192e/dot11d.h
index 69e0f8f7e3f8..129ebed2e3cc 100644
--- a/drivers/staging/rtl8192e/dot11d.h
+++ b/drivers/staging/rtl8192e/dot11d.h
@@ -79,7 +79,6 @@ static inline void cpMacAddr(unsigned char *des, unsigned char *src)
79#define UPDATE_CIE_SRC(__pIeeeDev, __pTa) \ 79#define UPDATE_CIE_SRC(__pIeeeDev, __pTa) \
80 cpMacAddr(GET_DOT11D_INFO(__pIeeeDev)->CountryIeSrcAddr, __pTa) 80 cpMacAddr(GET_DOT11D_INFO(__pIeeeDev)->CountryIeSrcAddr, __pTa)
81 81
82#define CIE_WATCHDOG_TH 1
83#define GET_CIE_WATCHDOG(__pIeeeDev) \ 82#define GET_CIE_WATCHDOG(__pIeeeDev) \
84 (GET_DOT11D_INFO(__pIeeeDev)->CountryIeWatchdog) 83 (GET_DOT11D_INFO(__pIeeeDev)->CountryIeWatchdog)
85static inline void RESET_CIE_WATCHDOG(struct rtllib_device *__pIeeeDev) 84static inline void RESET_CIE_WATCHDOG(struct rtllib_device *__pIeeeDev)
@@ -88,16 +87,11 @@ static inline void RESET_CIE_WATCHDOG(struct rtllib_device *__pIeeeDev)
88} 87}
89#define UPDATE_CIE_WATCHDOG(__pIeeeDev) (++GET_CIE_WATCHDOG(__pIeeeDev)) 88#define UPDATE_CIE_WATCHDOG(__pIeeeDev) (++GET_CIE_WATCHDOG(__pIeeeDev))
90 89
91#define IS_DOT11D_STATE_DONE(__pIeeeDev) \
92 (GET_DOT11D_INFO(__pIeeeDev)->State == DOT11D_STATE_DONE)
93
94void dot11d_init(struct rtllib_device *dev); 90void dot11d_init(struct rtllib_device *dev);
95void Dot11d_Channelmap(u8 channel_plan, struct rtllib_device *ieee); 91void Dot11d_Channelmap(u8 channel_plan, struct rtllib_device *ieee);
96void Dot11d_Reset(struct rtllib_device *dev); 92void Dot11d_Reset(struct rtllib_device *dev);
97void Dot11d_UpdateCountryIe(struct rtllib_device *dev, u8 *pTaddr, 93void Dot11d_UpdateCountryIe(struct rtllib_device *dev, u8 *pTaddr,
98 u16 CoutryIeLen, u8 *pCoutryIe); 94 u16 CoutryIeLen, u8 *pCoutryIe);
99u8 DOT11D_GetMaxTxPwrInDbm(struct rtllib_device *dev, u8 Channel);
100void DOT11D_ScanComplete(struct rtllib_device *dev); 95void DOT11D_ScanComplete(struct rtllib_device *dev);
101int ToLegalChannel(struct rtllib_device *dev, u8 channel);
102 96
103#endif 97#endif
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8190P_def.h b/drivers/staging/rtl8192e/rtl8192e/r8190P_def.h
index d0b08301b88f..dba4584c7006 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8190P_def.h
+++ b/drivers/staging/rtl8192e/rtl8192e/r8190P_def.h
@@ -26,8 +26,6 @@
26#define MAX_SILENT_RESET_RX_SLOT_NUM 10 26#define MAX_SILENT_RESET_RX_SLOT_NUM 10
27 27
28#define RX_MPDU_QUEUE 0 28#define RX_MPDU_QUEUE 0
29#define RX_CMD_QUEUE 1
30
31 29
32enum rtl819x_loopback { 30enum rtl819x_loopback {
33 RTL819X_NO_LOOPBACK = 0, 31 RTL819X_NO_LOOPBACK = 0,
@@ -36,11 +34,6 @@ enum rtl819x_loopback {
36 RTL819X_CCK_LOOPBACK = 3, 34 RTL819X_CCK_LOOPBACK = 3,
37}; 35};
38 36
39
40#define RESET_DELAY_8185 20
41
42#define RT_IBSS_INT_MASKS (IMR_BcnInt | IMR_BcnInt | IMR_TBDOK | IMR_TBDER)
43
44#define DESC90_RATE1M 0x00 37#define DESC90_RATE1M 0x00
45#define DESC90_RATE2M 0x01 38#define DESC90_RATE2M 0x01
46#define DESC90_RATE5_5M 0x02 39#define DESC90_RATE5_5M 0x02
@@ -74,17 +67,6 @@ enum rtl819x_loopback {
74#define SHORT_SLOT_TIME 9 67#define SHORT_SLOT_TIME 9
75#define NON_SHORT_SLOT_TIME 20 68#define NON_SHORT_SLOT_TIME 20
76 69
77
78#define MAX_LINES_HWCONFIG_TXT 1000
79#define MAX_BYTES_LINE_HWCONFIG_TXT 128
80
81#define SW_THREE_WIRE 0
82#define HW_THREE_WIRE 2
83
84#define BT_DEMO_BOARD 0
85#define BT_QA_BOARD 1
86#define BT_FPGA 2
87
88#define RX_SMOOTH 20 70#define RX_SMOOTH 20
89 71
90#define QSLT_BK 0x1 72#define QSLT_BK 0x1
@@ -96,25 +78,14 @@ enum rtl819x_loopback {
96#define QSLT_MGNT 0x12 78#define QSLT_MGNT 0x12
97#define QSLT_CMD 0x13 79#define QSLT_CMD 0x13
98 80
99#define NUM_OF_FIRMWARE_QUEUE 10
100#define NUM_OF_PAGES_IN_FW 0x100
101#define NUM_OF_PAGE_IN_FW_QUEUE_BK 0x007 81#define NUM_OF_PAGE_IN_FW_QUEUE_BK 0x007
102#define NUM_OF_PAGE_IN_FW_QUEUE_BE 0x0aa 82#define NUM_OF_PAGE_IN_FW_QUEUE_BE 0x0aa
103#define NUM_OF_PAGE_IN_FW_QUEUE_VI 0x024 83#define NUM_OF_PAGE_IN_FW_QUEUE_VI 0x024
104#define NUM_OF_PAGE_IN_FW_QUEUE_VO 0x007 84#define NUM_OF_PAGE_IN_FW_QUEUE_VO 0x007
105#define NUM_OF_PAGE_IN_FW_QUEUE_HCCA 0
106#define NUM_OF_PAGE_IN_FW_QUEUE_CMD 0x2
107#define NUM_OF_PAGE_IN_FW_QUEUE_MGNT 0x10 85#define NUM_OF_PAGE_IN_FW_QUEUE_MGNT 0x10
108#define NUM_OF_PAGE_IN_FW_QUEUE_HIGH 0
109#define NUM_OF_PAGE_IN_FW_QUEUE_BCN 0x4 86#define NUM_OF_PAGE_IN_FW_QUEUE_BCN 0x4
110#define NUM_OF_PAGE_IN_FW_QUEUE_PUB 0xd 87#define NUM_OF_PAGE_IN_FW_QUEUE_PUB 0xd
111 88
112#define NUM_OF_PAGE_IN_FW_QUEUE_BK_DTM 0x026
113#define NUM_OF_PAGE_IN_FW_QUEUE_BE_DTM 0x048
114#define NUM_OF_PAGE_IN_FW_QUEUE_VI_DTM 0x048
115#define NUM_OF_PAGE_IN_FW_QUEUE_VO_DTM 0x026
116#define NUM_OF_PAGE_IN_FW_QUEUE_PUB_DTM 0x00
117
118#define APPLIED_RESERVED_QUEUE_IN_FW 0x80000000 89#define APPLIED_RESERVED_QUEUE_IN_FW 0x80000000
119#define RSVD_FW_QUEUE_PAGE_BK_SHIFT 0x00 90#define RSVD_FW_QUEUE_PAGE_BK_SHIFT 0x00
120#define RSVD_FW_QUEUE_PAGE_BE_SHIFT 0x08 91#define RSVD_FW_QUEUE_PAGE_BE_SHIFT 0x08
@@ -197,23 +168,6 @@ struct tx_fwinfo_8190pci {
197 168
198}; 169};
199 170
200
201#define TX_DESC_SIZE 32
202
203#define TX_DESC_CMD_SIZE 32
204
205
206#define TX_STATUS_DESC_SIZE 32
207
208#define TX_FWINFO_SIZE 8
209
210
211#define RX_DESC_SIZE 16
212
213#define RX_STATUS_DESC_SIZE 16
214
215#define RX_DRIVER_INFO_SIZE 8
216
217struct log_int_8190 { 171struct log_int_8190 {
218 u32 nIMR_COMDOK; 172 u32 nIMR_COMDOK;
219 u32 nIMR_MGNTDOK; 173 u32 nIMR_MGNTDOK;
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8190P_rtl8256.c b/drivers/staging/rtl8192e/rtl8192e/r8190P_rtl8256.c
index facc6f1f302b..c8f25ade2535 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8190P_rtl8256.c
+++ b/drivers/staging/rtl8192e/rtl8192e/r8190P_rtl8256.c
@@ -22,55 +22,38 @@
22#include "r8192E_phy.h" 22#include "r8192E_phy.h"
23#include "r8190P_rtl8256.h" 23#include "r8190P_rtl8256.h"
24 24
25void PHY_SetRF8256Bandwidth(struct net_device *dev, 25void rtl92e_set_bandwidth(struct net_device *dev,
26 enum ht_channel_width Bandwidth) 26 enum ht_channel_width Bandwidth)
27{ 27{
28 u8 eRFPath; 28 u8 eRFPath;
29 struct r8192_priv *priv = rtllib_priv(dev); 29 struct r8192_priv *priv = rtllib_priv(dev);
30 30
31 if (priv->card_8192_version != VERSION_8190_BD &&
32 priv->card_8192_version != VERSION_8190_BE) {
33 netdev_warn(dev, "%s(): Unknown HW version.\n", __func__);
34 return;
35 }
36
31 for (eRFPath = 0; eRFPath < priv->NumTotalRFPath; eRFPath++) { 37 for (eRFPath = 0; eRFPath < priv->NumTotalRFPath; eRFPath++) {
32 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath)) 38 if (!rtl92e_is_legal_rf_path(dev, eRFPath))
33 continue; 39 continue;
34 40
35 switch (Bandwidth) { 41 switch (Bandwidth) {
36 case HT_CHANNEL_WIDTH_20: 42 case HT_CHANNEL_WIDTH_20:
37 if (priv->card_8192_version == VERSION_8190_BD || 43 rtl92e_set_rf_reg(dev, (enum rf90_radio_path)eRFPath,
38 priv->card_8192_version == VERSION_8190_BE) { 44 0x0b, bMask12Bits, 0x100);
39 rtl8192_phy_SetRFReg(dev, 45 rtl92e_set_rf_reg(dev, (enum rf90_radio_path)eRFPath,
40 (enum rf90_radio_path)eRFPath, 46 0x2c, bMask12Bits, 0x3d7);
41 0x0b, bMask12Bits, 0x100); 47 rtl92e_set_rf_reg(dev, (enum rf90_radio_path)eRFPath,
42 rtl8192_phy_SetRFReg(dev, 48 0x0e, bMask12Bits, 0x021);
43 (enum rf90_radio_path)eRFPath,
44 0x2c, bMask12Bits, 0x3d7);
45 rtl8192_phy_SetRFReg(dev,
46 (enum rf90_radio_path)eRFPath,
47 0x0e, bMask12Bits, 0x021);
48
49 } else {
50 netdev_warn(dev, "%s(): Unknown HW version.\n",
51 __func__);
52 }
53
54 break; 49 break;
55 case HT_CHANNEL_WIDTH_20_40: 50 case HT_CHANNEL_WIDTH_20_40:
56 if (priv->card_8192_version == VERSION_8190_BD || 51 rtl92e_set_rf_reg(dev, (enum rf90_radio_path)eRFPath,
57 priv->card_8192_version == VERSION_8190_BE) { 52 0x0b, bMask12Bits, 0x300);
58 rtl8192_phy_SetRFReg(dev, 53 rtl92e_set_rf_reg(dev, (enum rf90_radio_path)eRFPath,
59 (enum rf90_radio_path)eRFPath, 54 0x2c, bMask12Bits, 0x3ff);
60 0x0b, bMask12Bits, 0x300); 55 rtl92e_set_rf_reg(dev, (enum rf90_radio_path)eRFPath,
61 rtl8192_phy_SetRFReg(dev, 56 0x0e, bMask12Bits, 0x0e1);
62 (enum rf90_radio_path)eRFPath,
63 0x2c, bMask12Bits, 0x3ff);
64 rtl8192_phy_SetRFReg(dev,
65 (enum rf90_radio_path)eRFPath,
66 0x0e, bMask12Bits, 0x0e1);
67
68 } else {
69 netdev_warn(dev, "%s(): Unknown HW version.\n",
70 __func__);
71 }
72
73
74 break; 57 break;
75 default: 58 default:
76 netdev_err(dev, "%s(): Unknown bandwidth: %#X\n", 59 netdev_err(dev, "%s(): Unknown bandwidth: %#X\n",
@@ -81,15 +64,7 @@ void PHY_SetRF8256Bandwidth(struct net_device *dev,
81 } 64 }
82} 65}
83 66
84bool PHY_RF8256_Config(struct net_device *dev) 67bool rtl92e_config_rf(struct net_device *dev)
85{
86 struct r8192_priv *priv = rtllib_priv(dev);
87
88 priv->NumTotalRFPath = RTL819X_TOTAL_RF_PATH;
89 return phy_RF8256_Config_ParaFile(dev);
90}
91
92bool phy_RF8256_Config_ParaFile(struct net_device *dev)
93{ 68{
94 u32 u4RegValue = 0; 69 u32 u4RegValue = 0;
95 u8 eRFPath; 70 u8 eRFPath;
@@ -102,9 +77,11 @@ bool phy_RF8256_Config_ParaFile(struct net_device *dev)
102 u8 ConstRetryTimes = 5, RetryTimes = 5; 77 u8 ConstRetryTimes = 5, RetryTimes = 5;
103 u8 ret = 0; 78 u8 ret = 0;
104 79
80 priv->NumTotalRFPath = RTL819X_TOTAL_RF_PATH;
81
105 for (eRFPath = (enum rf90_radio_path)RF90_PATH_A; 82 for (eRFPath = (enum rf90_radio_path)RF90_PATH_A;
106 eRFPath < priv->NumTotalRFPath; eRFPath++) { 83 eRFPath < priv->NumTotalRFPath; eRFPath++) {
107 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath)) 84 if (!rtl92e_is_legal_rf_path(dev, eRFPath))
108 continue; 85 continue;
109 86
110 pPhyReg = &priv->PHYRegDef[eRFPath]; 87 pPhyReg = &priv->PHYRegDef[eRFPath];
@@ -113,114 +90,63 @@ bool phy_RF8256_Config_ParaFile(struct net_device *dev)
113 switch (eRFPath) { 90 switch (eRFPath) {
114 case RF90_PATH_A: 91 case RF90_PATH_A:
115 case RF90_PATH_C: 92 case RF90_PATH_C:
116 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, 93 u4RegValue = rtl92e_get_bb_reg(dev, pPhyReg->rfintfs,
117 bRFSI_RFENV); 94 bRFSI_RFENV);
118 break; 95 break;
119 case RF90_PATH_B: 96 case RF90_PATH_B:
120 case RF90_PATH_D: 97 case RF90_PATH_D:
121 u4RegValue = rtl8192_QueryBBReg(dev, pPhyReg->rfintfs, 98 u4RegValue = rtl92e_get_bb_reg(dev, pPhyReg->rfintfs,
122 bRFSI_RFENV<<16); 99 bRFSI_RFENV<<16);
123 break; 100 break;
124 } 101 }
125 102
126 rtl8192_setBBreg(dev, pPhyReg->rfintfe, bRFSI_RFENV<<16, 0x1); 103 rtl92e_set_bb_reg(dev, pPhyReg->rfintfe, bRFSI_RFENV<<16, 0x1);
127 104
128 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1); 105 rtl92e_set_bb_reg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1);
129 106
130 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, 107 rtl92e_set_bb_reg(dev, pPhyReg->rfHSSIPara2,
131 b3WireAddressLength, 0x0); 108 b3WireAddressLength, 0x0);
132 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, 109 rtl92e_set_bb_reg(dev, pPhyReg->rfHSSIPara2,
133 b3WireDataLength, 0x0); 110 b3WireDataLength, 0x0);
134 111
135 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path) eRFPath, 0x0, 112 rtl92e_set_rf_reg(dev, (enum rf90_radio_path)eRFPath, 0x0,
136 bMask12Bits, 0xbf); 113 bMask12Bits, 0xbf);
137 114
138 rtStatus = rtl8192_phy_checkBBAndRF(dev, HW90_BLOCK_RF, 115 rtStatus = rtl92e_check_bb_and_rf(dev, HW90_BLOCK_RF,
139 (enum rf90_radio_path)eRFPath); 116 (enum rf90_radio_path)eRFPath);
140 if (!rtStatus) { 117 if (!rtStatus) {
141 netdev_err(dev, "%s(): Failed to check RF Path %d.\n", 118 netdev_err(dev, "%s(): Failed to check RF Path %d.\n",
142 __func__, eRFPath); 119 __func__, eRFPath);
143 goto phy_RF8256_Config_ParaFile_Fail; 120 goto fail;
144 } 121 }
145 122
146 RetryTimes = ConstRetryTimes; 123 RetryTimes = ConstRetryTimes;
147 RF3_Final_Value = 0; 124 RF3_Final_Value = 0;
148 switch (eRFPath) { 125 while (RF3_Final_Value != RegValueToBeCheck &&
149 case RF90_PATH_A: 126 RetryTimes != 0) {
150 while (RF3_Final_Value != RegValueToBeCheck && 127 ret = rtl92e_config_rf_path(dev,
151 RetryTimes != 0) {
152 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev,
153 (enum rf90_radio_path)eRFPath);
154 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev,
155 (enum rf90_radio_path)eRFPath,
156 RegOffSetToBeCheck,
157 bMask12Bits);
158 RT_TRACE(COMP_RF,
159 "RF %d %d register final value: %x\n",
160 eRFPath, RegOffSetToBeCheck,
161 RF3_Final_Value);
162 RetryTimes--;
163 }
164 break;
165 case RF90_PATH_B:
166 while (RF3_Final_Value != RegValueToBeCheck &&
167 RetryTimes != 0) {
168 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev,
169 (enum rf90_radio_path)eRFPath);
170 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev,
171 (enum rf90_radio_path)eRFPath,
172 RegOffSetToBeCheck,
173 bMask12Bits);
174 RT_TRACE(COMP_RF,
175 "RF %d %d register final value: %x\n",
176 eRFPath, RegOffSetToBeCheck,
177 RF3_Final_Value);
178 RetryTimes--;
179 }
180 break;
181 case RF90_PATH_C:
182 while (RF3_Final_Value != RegValueToBeCheck &&
183 RetryTimes != 0) {
184 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev,
185 (enum rf90_radio_path)eRFPath); 128 (enum rf90_radio_path)eRFPath);
186 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev, 129 RF3_Final_Value = rtl92e_get_rf_reg(dev,
187 (enum rf90_radio_path)eRFPath, 130 (enum rf90_radio_path)eRFPath,
188 RegOffSetToBeCheck, 131 RegOffSetToBeCheck,
189 bMask12Bits); 132 bMask12Bits);
190 RT_TRACE(COMP_RF, 133 RT_TRACE(COMP_RF,
191 "RF %d %d register final value: %x\n", 134 "RF %d %d register final value: %x\n",
192 eRFPath, RegOffSetToBeCheck, 135 eRFPath, RegOffSetToBeCheck,
193 RF3_Final_Value); 136 RF3_Final_Value);
194 RetryTimes--; 137 RetryTimes--;
195 }
196 break;
197 case RF90_PATH_D:
198 while (RF3_Final_Value != RegValueToBeCheck &&
199 RetryTimes != 0) {
200 ret = rtl8192_phy_ConfigRFWithHeaderFile(dev,
201 (enum rf90_radio_path)eRFPath);
202 RF3_Final_Value = rtl8192_phy_QueryRFReg(dev,
203 (enum rf90_radio_path)eRFPath,
204 RegOffSetToBeCheck, bMask12Bits);
205 RT_TRACE(COMP_RF,
206 "RF %d %d register final value: %x\n",
207 eRFPath, RegOffSetToBeCheck,
208 RF3_Final_Value);
209 RetryTimes--;
210 }
211 break;
212 } 138 }
213 139
214 switch (eRFPath) { 140 switch (eRFPath) {
215 case RF90_PATH_A: 141 case RF90_PATH_A:
216 case RF90_PATH_C: 142 case RF90_PATH_C:
217 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV, 143 rtl92e_set_bb_reg(dev, pPhyReg->rfintfs, bRFSI_RFENV,
218 u4RegValue); 144 u4RegValue);
219 break; 145 break;
220 case RF90_PATH_B: 146 case RF90_PATH_B:
221 case RF90_PATH_D: 147 case RF90_PATH_D:
222 rtl8192_setBBreg(dev, pPhyReg->rfintfs, bRFSI_RFENV<<16, 148 rtl92e_set_bb_reg(dev, pPhyReg->rfintfs,
223 u4RegValue); 149 bRFSI_RFENV<<16, u4RegValue);
224 break; 150 break;
225 } 151 }
226 152
@@ -228,7 +154,7 @@ bool phy_RF8256_Config_ParaFile(struct net_device *dev)
228 netdev_err(dev, 154 netdev_err(dev,
229 "%s(): Failed to initialize RF Path %d.\n", 155 "%s(): Failed to initialize RF Path %d.\n",
230 __func__, eRFPath); 156 __func__, eRFPath);
231 goto phy_RF8256_Config_ParaFile_Fail; 157 goto fail;
232 } 158 }
233 159
234 } 160 }
@@ -236,11 +162,11 @@ bool phy_RF8256_Config_ParaFile(struct net_device *dev)
236 RT_TRACE(COMP_PHY, "PHY Initialization Success\n"); 162 RT_TRACE(COMP_PHY, "PHY Initialization Success\n");
237 return true; 163 return true;
238 164
239phy_RF8256_Config_ParaFile_Fail: 165fail:
240 return false; 166 return false;
241} 167}
242 168
243void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel) 169void rtl92e_set_cck_tx_power(struct net_device *dev, u8 powerlevel)
244{ 170{
245 u32 TxAGC = 0; 171 u32 TxAGC = 0;
246 struct r8192_priv *priv = rtllib_priv(dev); 172 struct r8192_priv *priv = rtllib_priv(dev);
@@ -254,11 +180,11 @@ void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel)
254 } 180 }
255 if (TxAGC > 0x24) 181 if (TxAGC > 0x24)
256 TxAGC = 0x24; 182 TxAGC = 0x24;
257 rtl8192_setBBreg(dev, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC); 183 rtl92e_set_bb_reg(dev, rTxAGC_CCK_Mcs32, bTxAGCRateCCK, TxAGC);
258} 184}
259 185
260 186
261void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel) 187void rtl92e_set_ofdm_tx_power(struct net_device *dev, u8 powerlevel)
262{ 188{
263 struct r8192_priv *priv = rtllib_priv(dev); 189 struct r8192_priv *priv = rtllib_priv(dev);
264 u32 writeVal, powerBase0, powerBase1, writeVal_tmp; 190 u32 writeVal, powerBase0, powerBase1, writeVal_tmp;
@@ -300,7 +226,7 @@ void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel)
300 else 226 else
301 writeVal = (byte3 << 24) | (byte2 << 16) | 227 writeVal = (byte3 << 24) | (byte2 << 16) |
302 (byte1 << 8) | byte0; 228 (byte1 << 8) | byte0;
303 rtl8192_setBBreg(dev, RegOffset[index], 0x7f7f7f7f, writeVal); 229 rtl92e_set_bb_reg(dev, RegOffset[index], 0x7f7f7f7f, writeVal);
304 } 230 }
305 231
306} 232}
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8190P_rtl8256.h b/drivers/staging/rtl8192e/rtl8192e/r8190P_rtl8256.h
index 64e831d2f4e5..3e4363f41728 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8190P_rtl8256.h
+++ b/drivers/staging/rtl8192e/rtl8192e/r8190P_rtl8256.h
@@ -21,11 +21,10 @@
21#define RTL8225H 21#define RTL8225H
22 22
23#define RTL819X_TOTAL_RF_PATH 2 23#define RTL819X_TOTAL_RF_PATH 2
24extern void PHY_SetRF8256Bandwidth(struct net_device *dev, 24void rtl92e_set_bandwidth(struct net_device *dev,
25 enum ht_channel_width Bandwidth); 25 enum ht_channel_width Bandwidth);
26extern bool PHY_RF8256_Config(struct net_device *dev); 26bool rtl92e_config_rf(struct net_device *dev);
27extern bool phy_RF8256_Config_ParaFile(struct net_device *dev); 27void rtl92e_set_cck_tx_power(struct net_device *dev, u8 powerlevel);
28extern void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel); 28void rtl92e_set_ofdm_tx_power(struct net_device *dev, u8 powerlevel);
29extern void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel);
30 29
31#endif 30#endif
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.c
index ebd08a16685e..9ddabf59784c 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.c
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.c
@@ -21,11 +21,8 @@
21#include "r8192E_hw.h" 21#include "r8192E_hw.h"
22#include "r8192E_cmdpkt.h" 22#include "r8192E_cmdpkt.h"
23 23
24bool cmpk_message_handle_tx( 24bool rtl92e_send_cmd_pkt(struct net_device *dev, u8 *code_virtual_address,
25 struct net_device *dev, 25 u32 packettype, u32 buffer_len)
26 u8 *code_virtual_address,
27 u32 packettype,
28 u32 buffer_len)
29{ 26{
30 27
31 bool rt_status = true; 28 bool rt_status = true;
@@ -41,7 +38,7 @@ bool cmpk_message_handle_tx(
41 struct tx_fwinfo_8190pci *pTxFwInfo = NULL; 38 struct tx_fwinfo_8190pci *pTxFwInfo = NULL;
42 39
43 RT_TRACE(COMP_CMDPKT, "%s(),buffer_len is %d\n", __func__, buffer_len); 40 RT_TRACE(COMP_CMDPKT, "%s(),buffer_len is %d\n", __func__, buffer_len);
44 firmware_init_param(dev); 41 rtl92e_init_fw_param(dev);
45 frag_threshold = pfirmware->cmdpacket_frag_thresold; 42 frag_threshold = pfirmware->cmdpacket_frag_thresold;
46 43
47 do { 44 do {
@@ -84,7 +81,7 @@ bool cmpk_message_handle_tx(
84 81
85 } while (frag_offset < buffer_len); 82 } while (frag_offset < buffer_len);
86 83
87 write_nic_byte(dev, TPPoll, TPPoll_CQ); 84 rtl92e_writeb(dev, TPPoll, TPPoll_CQ);
88Failed: 85Failed:
89 return rt_status; 86 return rt_status;
90} 87}
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.h b/drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.h
index f714d5100059..2a8b165cb8e1 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.h
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.h
@@ -19,7 +19,6 @@
19#ifndef R819XUSB_CMDPKT_H 19#ifndef R819XUSB_CMDPKT_H
20#define R819XUSB_CMDPKT_H 20#define R819XUSB_CMDPKT_H
21 21
22extern bool cmpk_message_handle_tx(struct net_device *dev, 22bool rtl92e_send_cmd_pkt(struct net_device *dev, u8 *codevirtualaddress,
23 u8 *codevirtualaddress, u32 packettype, 23 u32 packettype, u32 buffer_len);
24 u32 buffer_len);
25#endif 24#endif
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c
index f6661bbae7a8..c28cabc23fc0 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c
@@ -33,7 +33,7 @@
33static int WDCAPARA_ADD[] = {EDCAPARA_BE, EDCAPARA_BK, EDCAPARA_VI, 33static int WDCAPARA_ADD[] = {EDCAPARA_BE, EDCAPARA_BK, EDCAPARA_VI,
34 EDCAPARA_VO}; 34 EDCAPARA_VO};
35 35
36void rtl8192e_start_beacon(struct net_device *dev) 36void rtl92e_start_beacon(struct net_device *dev)
37{ 37{
38 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 38 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
39 struct rtllib_network *net = &priv->rtllib->current_network; 39 struct rtllib_network *net = &priv->rtllib->current_network;
@@ -41,21 +41,20 @@ void rtl8192e_start_beacon(struct net_device *dev)
41 u16 BcnCW = 6; 41 u16 BcnCW = 6;
42 u16 BcnIFS = 0xf; 42 u16 BcnIFS = 0xf;
43 43
44 DMESG("Enabling beacon TX"); 44 rtl92e_irq_disable(dev);
45 rtl8192_irq_disable(dev);
46 45
47 write_nic_word(dev, ATIMWND, 2); 46 rtl92e_writew(dev, ATIMWND, 2);
48 47
49 write_nic_word(dev, BCN_INTERVAL, net->beacon_interval); 48 rtl92e_writew(dev, BCN_INTERVAL, net->beacon_interval);
50 write_nic_word(dev, BCN_DRV_EARLY_INT, 10); 49 rtl92e_writew(dev, BCN_DRV_EARLY_INT, 10);
51 write_nic_word(dev, BCN_DMATIME, 256); 50 rtl92e_writew(dev, BCN_DMATIME, 256);
52 51
53 write_nic_byte(dev, BCN_ERR_THRESH, 100); 52 rtl92e_writeb(dev, BCN_ERR_THRESH, 100);
54 53
55 BcnTimeCfg |= BcnCW<<BCN_TCFG_CW_SHIFT; 54 BcnTimeCfg |= BcnCW<<BCN_TCFG_CW_SHIFT;
56 BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS; 55 BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS;
57 write_nic_word(dev, BCN_TCFG, BcnTimeCfg); 56 rtl92e_writew(dev, BCN_TCFG, BcnTimeCfg);
58 rtl8192_irq_enable(dev); 57 rtl92e_irq_enable(dev);
59} 58}
60 59
61static void rtl8192e_update_msr(struct net_device *dev) 60static void rtl8192e_update_msr(struct net_device *dev)
@@ -64,7 +63,7 @@ static void rtl8192e_update_msr(struct net_device *dev)
64 u8 msr; 63 u8 msr;
65 enum led_ctl_mode LedAction = LED_CTL_NO_LINK; 64 enum led_ctl_mode LedAction = LED_CTL_NO_LINK;
66 65
67 msr = read_nic_byte(dev, MSR); 66 msr = rtl92e_readb(dev, MSR);
68 msr &= ~MSR_LINK_MASK; 67 msr &= ~MSR_LINK_MASK;
69 68
70 switch (priv->rtllib->iw_mode) { 69 switch (priv->rtllib->iw_mode) {
@@ -91,26 +90,26 @@ static void rtl8192e_update_msr(struct net_device *dev)
91 break; 90 break;
92 } 91 }
93 92
94 write_nic_byte(dev, MSR, msr); 93 rtl92e_writeb(dev, MSR, msr);
95 if (priv->rtllib->LedControlHandler) 94 if (priv->rtllib->LedControlHandler)
96 priv->rtllib->LedControlHandler(dev, LedAction); 95 priv->rtllib->LedControlHandler(dev, LedAction);
97} 96}
98 97
99void rtl8192e_SetHwReg(struct net_device *dev, u8 variable, u8 *val) 98void rtl92e_set_reg(struct net_device *dev, u8 variable, u8 *val)
100{ 99{
101 struct r8192_priv *priv = rtllib_priv(dev); 100 struct r8192_priv *priv = rtllib_priv(dev);
102 101
103 switch (variable) { 102 switch (variable) {
104 case HW_VAR_BSSID: 103 case HW_VAR_BSSID:
105 write_nic_dword(dev, BSSIDR, ((u32 *)(val))[0]); 104 rtl92e_writel(dev, BSSIDR, ((u32 *)(val))[0]);
106 write_nic_word(dev, BSSIDR+2, ((u16 *)(val+2))[0]); 105 rtl92e_writew(dev, BSSIDR+2, ((u16 *)(val+2))[0]);
107 break; 106 break;
108 107
109 case HW_VAR_MEDIA_STATUS: 108 case HW_VAR_MEDIA_STATUS:
110 { 109 {
111 enum rt_op_mode OpMode = *((enum rt_op_mode *)(val)); 110 enum rt_op_mode OpMode = *((enum rt_op_mode *)(val));
112 enum led_ctl_mode LedAction = LED_CTL_NO_LINK; 111 enum led_ctl_mode LedAction = LED_CTL_NO_LINK;
113 u8 btMsr = read_nic_byte(dev, MSR); 112 u8 btMsr = rtl92e_readb(dev, MSR);
114 113
115 btMsr &= 0xfc; 114 btMsr &= 0xfc;
116 115
@@ -134,7 +133,7 @@ void rtl8192e_SetHwReg(struct net_device *dev, u8 variable, u8 *val)
134 break; 133 break;
135 } 134 }
136 135
137 write_nic_byte(dev, MSR, btMsr); 136 rtl92e_writeb(dev, MSR, btMsr);
138 137
139 } 138 }
140 break; 139 break;
@@ -144,7 +143,7 @@ void rtl8192e_SetHwReg(struct net_device *dev, u8 variable, u8 *val)
144 u32 RegRCR, Type; 143 u32 RegRCR, Type;
145 144
146 Type = ((u8 *)(val))[0]; 145 Type = ((u8 *)(val))[0];
147 RegRCR = read_nic_dword(dev, RCR); 146 RegRCR = rtl92e_readl(dev, RCR);
148 priv->ReceiveConfig = RegRCR; 147 priv->ReceiveConfig = RegRCR;
149 148
150 if (Type == true) 149 if (Type == true)
@@ -152,7 +151,7 @@ void rtl8192e_SetHwReg(struct net_device *dev, u8 variable, u8 *val)
152 else if (Type == false) 151 else if (Type == false)
153 RegRCR &= (~RCR_CBSSID); 152 RegRCR &= (~RCR_CBSSID);
154 153
155 write_nic_dword(dev, RCR, RegRCR); 154 rtl92e_writel(dev, RCR, RegRCR);
156 priv->ReceiveConfig = RegRCR; 155 priv->ReceiveConfig = RegRCR;
157 156
158 } 157 }
@@ -161,7 +160,7 @@ void rtl8192e_SetHwReg(struct net_device *dev, u8 variable, u8 *val)
161 case HW_VAR_SLOT_TIME: 160 case HW_VAR_SLOT_TIME:
162 161
163 priv->slot_time = val[0]; 162 priv->slot_time = val[0];
164 write_nic_byte(dev, SLOT_TIME, val[0]); 163 rtl92e_writeb(dev, SLOT_TIME, val[0]);
165 164
166 break; 165 break;
167 166
@@ -173,12 +172,12 @@ void rtl8192e_SetHwReg(struct net_device *dev, u8 variable, u8 *val)
173 regTmp = priv->basic_rate; 172 regTmp = priv->basic_rate;
174 if (priv->short_preamble) 173 if (priv->short_preamble)
175 regTmp |= BRSR_AckShortPmb; 174 regTmp |= BRSR_AckShortPmb;
176 write_nic_dword(dev, RRSR, regTmp); 175 rtl92e_writel(dev, RRSR, regTmp);
177 break; 176 break;
178 } 177 }
179 178
180 case HW_VAR_CPU_RST: 179 case HW_VAR_CPU_RST:
181 write_nic_dword(dev, CPU_GEN, ((u32 *)(val))[0]); 180 rtl92e_writel(dev, CPU_GEN, ((u32 *)(val))[0]);
182 break; 181 break;
183 182
184 case HW_VAR_AC_PARAM: 183 case HW_VAR_AC_PARAM:
@@ -194,7 +193,7 @@ void rtl8192e_SetHwReg(struct net_device *dev, u8 variable, u8 *val)
194 u1bAIFS = qop->aifs[pAcParam] * 193 u1bAIFS = qop->aifs[pAcParam] *
195 ((mode&(IEEE_G|IEEE_N_24G)) ? 9 : 20) + aSifsTime; 194 ((mode&(IEEE_G|IEEE_N_24G)) ? 9 : 20) + aSifsTime;
196 195
197 dm_init_edca_turbo(dev); 196 rtl92e_dm_init_edca_turbo(dev);
198 197
199 u4bAcParam = (le16_to_cpu(qop->tx_op_limit[pAcParam]) << 198 u4bAcParam = (le16_to_cpu(qop->tx_op_limit[pAcParam]) <<
200 AC_PARAM_TXOP_LIMIT_OFFSET) | 199 AC_PARAM_TXOP_LIMIT_OFFSET) |
@@ -208,19 +207,19 @@ void rtl8192e_SetHwReg(struct net_device *dev, u8 variable, u8 *val)
208 __func__, eACI, u4bAcParam); 207 __func__, eACI, u4bAcParam);
209 switch (eACI) { 208 switch (eACI) {
210 case AC1_BK: 209 case AC1_BK:
211 write_nic_dword(dev, EDCAPARA_BK, u4bAcParam); 210 rtl92e_writel(dev, EDCAPARA_BK, u4bAcParam);
212 break; 211 break;
213 212
214 case AC0_BE: 213 case AC0_BE:
215 write_nic_dword(dev, EDCAPARA_BE, u4bAcParam); 214 rtl92e_writel(dev, EDCAPARA_BE, u4bAcParam);
216 break; 215 break;
217 216
218 case AC2_VI: 217 case AC2_VI:
219 write_nic_dword(dev, EDCAPARA_VI, u4bAcParam); 218 rtl92e_writel(dev, EDCAPARA_VI, u4bAcParam);
220 break; 219 break;
221 220
222 case AC3_VO: 221 case AC3_VO:
223 write_nic_dword(dev, EDCAPARA_VO, u4bAcParam); 222 rtl92e_writel(dev, EDCAPARA_VO, u4bAcParam);
224 break; 223 break;
225 224
226 default: 225 default:
@@ -242,7 +241,7 @@ void rtl8192e_SetHwReg(struct net_device *dev, u8 variable, u8 *val)
242 union aci_aifsn *pAciAifsn = (union aci_aifsn *) & 241 union aci_aifsn *pAciAifsn = (union aci_aifsn *) &
243 (qos_parameters->aifs[0]); 242 (qos_parameters->aifs[0]);
244 u8 acm = pAciAifsn->f.acm; 243 u8 acm = pAciAifsn->f.acm;
245 u8 AcmCtrl = read_nic_byte(dev, AcmHwCtrl); 244 u8 AcmCtrl = rtl92e_readb(dev, AcmHwCtrl);
246 245
247 RT_TRACE(COMP_DBG, "===========>%s():HW_VAR_ACM_CTRL:%x\n", 246 RT_TRACE(COMP_DBG, "===========>%s():HW_VAR_ACM_CTRL:%x\n",
248 __func__, eACI); 247 __func__, eACI);
@@ -290,20 +289,20 @@ void rtl8192e_SetHwReg(struct net_device *dev, u8 variable, u8 *val)
290 RT_TRACE(COMP_QOS, 289 RT_TRACE(COMP_QOS,
291 "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n", 290 "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
292 AcmCtrl); 291 AcmCtrl);
293 write_nic_byte(dev, AcmHwCtrl, AcmCtrl); 292 rtl92e_writeb(dev, AcmHwCtrl, AcmCtrl);
294 break; 293 break;
295 } 294 }
296 295
297 case HW_VAR_SIFS: 296 case HW_VAR_SIFS:
298 write_nic_byte(dev, SIFS, val[0]); 297 rtl92e_writeb(dev, SIFS, val[0]);
299 write_nic_byte(dev, SIFS+1, val[0]); 298 rtl92e_writeb(dev, SIFS+1, val[0]);
300 break; 299 break;
301 300
302 case HW_VAR_RF_TIMING: 301 case HW_VAR_RF_TIMING:
303 { 302 {
304 u8 Rf_Timing = *((u8 *)val); 303 u8 Rf_Timing = *((u8 *)val);
305 304
306 write_nic_byte(dev, rFPGA0_RFTiming1, Rf_Timing); 305 rtl92e_writeb(dev, rFPGA0_RFTiming1, Rf_Timing);
307 break; 306 break;
308 } 307 }
309 308
@@ -324,7 +323,7 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
324 323
325 RT_TRACE(COMP_INIT, "====> rtl8192_read_eeprom_info\n"); 324 RT_TRACE(COMP_INIT, "====> rtl8192_read_eeprom_info\n");
326 325
327 EEPROMId = eprom_read(dev, 0); 326 EEPROMId = rtl92e_eeprom_read(dev, 0);
328 if (EEPROMId != RTL8190_EEPROM_ID) { 327 if (EEPROMId != RTL8190_EEPROM_ID) {
329 netdev_err(dev, "%s(): Invalid EEPROM ID: %x\n", __func__, 328 netdev_err(dev, "%s(): Invalid EEPROM ID: %x\n", __func__,
330 EEPROMId); 329 EEPROMId);
@@ -334,12 +333,14 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
334 } 333 }
335 334
336 if (!priv->AutoloadFailFlag) { 335 if (!priv->AutoloadFailFlag) {
337 priv->eeprom_vid = eprom_read(dev, EEPROM_VID >> 1); 336 priv->eeprom_vid = rtl92e_eeprom_read(dev, EEPROM_VID >> 1);
338 priv->eeprom_did = eprom_read(dev, EEPROM_DID >> 1); 337 priv->eeprom_did = rtl92e_eeprom_read(dev, EEPROM_DID >> 1);
339 338
340 usValue = eprom_read(dev, (u16)(EEPROM_Customer_ID>>1)) >> 8; 339 usValue = rtl92e_eeprom_read(dev,
340 (u16)(EEPROM_Customer_ID>>1)) >> 8;
341 priv->eeprom_CustomerID = (u8)(usValue & 0xff); 341 priv->eeprom_CustomerID = (u8)(usValue & 0xff);
342 usValue = eprom_read(dev, EEPROM_ICVersion_ChannelPlan>>1); 342 usValue = rtl92e_eeprom_read(dev,
343 EEPROM_ICVersion_ChannelPlan>>1);
343 priv->eeprom_ChannelPlan = usValue&0xff; 344 priv->eeprom_ChannelPlan = usValue&0xff;
344 IC_Version = (usValue & 0xff00)>>8; 345 IC_Version = (usValue & 0xff00)>>8;
345 346
@@ -377,7 +378,7 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
377 378
378 if (!priv->AutoloadFailFlag) { 379 if (!priv->AutoloadFailFlag) {
379 for (i = 0; i < 6; i += 2) { 380 for (i = 0; i < 6; i += 2) {
380 usValue = eprom_read(dev, 381 usValue = rtl92e_eeprom_read(dev,
381 (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1)); 382 (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1));
382 *(u16 *)(&dev->dev_addr[i]) = usValue; 383 *(u16 *)(&dev->dev_addr[i]) = usValue;
383 } 384 }
@@ -397,8 +398,8 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
397 398
398 if (priv->card_8192_version > VERSION_8190_BD) { 399 if (priv->card_8192_version > VERSION_8190_BD) {
399 if (!priv->AutoloadFailFlag) { 400 if (!priv->AutoloadFailFlag) {
400 tempval = (eprom_read(dev, (EEPROM_RFInd_PowerDiff >> 401 tempval = (rtl92e_eeprom_read(dev,
401 1))) & 0xff; 402 (EEPROM_RFInd_PowerDiff >> 1))) & 0xff;
402 priv->EEPROMLegacyHTTxPowerDiff = tempval & 0xf; 403 priv->EEPROMLegacyHTTxPowerDiff = tempval & 0xf;
403 404
404 if (tempval&0x80) 405 if (tempval&0x80)
@@ -412,7 +413,7 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
412 priv->EEPROMLegacyHTTxPowerDiff); 413 priv->EEPROMLegacyHTTxPowerDiff);
413 414
414 if (!priv->AutoloadFailFlag) 415 if (!priv->AutoloadFailFlag)
415 priv->EEPROMThermalMeter = (u8)(((eprom_read(dev, 416 priv->EEPROMThermalMeter = (u8)(((rtl92e_eeprom_read(dev,
416 (EEPROM_ThermalMeter>>1))) & 417 (EEPROM_ThermalMeter>>1))) &
417 0xff00)>>8); 418 0xff00)>>8);
418 else 419 else
@@ -423,7 +424,7 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
423 424
424 if (priv->epromtype == EEPROM_93C46) { 425 if (priv->epromtype == EEPROM_93C46) {
425 if (!priv->AutoloadFailFlag) { 426 if (!priv->AutoloadFailFlag) {
426 usValue = eprom_read(dev, 427 usValue = rtl92e_eeprom_read(dev,
427 EEPROM_TxPwDiff_CrystalCap >> 1); 428 EEPROM_TxPwDiff_CrystalCap >> 1);
428 priv->EEPROMAntPwDiff = (usValue&0x0fff); 429 priv->EEPROMAntPwDiff = (usValue&0x0fff);
429 priv->EEPROMCrystalCap = (u8)((usValue & 0xf000) 430 priv->EEPROMCrystalCap = (u8)((usValue & 0xf000)
@@ -441,7 +442,7 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
441 442
442 for (i = 0; i < 14; i += 2) { 443 for (i = 0; i < 14; i += 2) {
443 if (!priv->AutoloadFailFlag) 444 if (!priv->AutoloadFailFlag)
444 usValue = eprom_read(dev, 445 usValue = rtl92e_eeprom_read(dev,
445 (u16)((EEPROM_TxPwIndex_CCK + 446 (u16)((EEPROM_TxPwIndex_CCK +
446 i) >> 1)); 447 i) >> 1));
447 else 448 else
@@ -457,7 +458,7 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
457 } 458 }
458 for (i = 0; i < 14; i += 2) { 459 for (i = 0; i < 14; i += 2) {
459 if (!priv->AutoloadFailFlag) 460 if (!priv->AutoloadFailFlag)
460 usValue = eprom_read(dev, 461 usValue = rtl92e_eeprom_read(dev,
461 (u16)((EEPROM_TxPwIndex_OFDM_24G 462 (u16)((EEPROM_TxPwIndex_OFDM_24G
462 + i) >> 1)); 463 + i) >> 1));
463 else 464 else
@@ -561,7 +562,7 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
561 RT_TRACE(COMP_INIT, "\n2T4R config\n"); 562 RT_TRACE(COMP_INIT, "\n2T4R config\n");
562 } 563 }
563 564
564 init_rate_adaptive(dev); 565 rtl92e_init_adaptive_rate(dev);
565 566
566 priv->rf_chip = RF_8256; 567 priv->rf_chip = RF_8256;
567 568
@@ -626,13 +627,13 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
626 RT_TRACE(COMP_TRACE, "<==== ReadAdapterInfo\n"); 627 RT_TRACE(COMP_TRACE, "<==== ReadAdapterInfo\n");
627} 628}
628 629
629void rtl8192_get_eeprom_size(struct net_device *dev) 630void rtl92e_get_eeprom_size(struct net_device *dev)
630{ 631{
631 u16 curCR; 632 u16 curCR;
632 struct r8192_priv *priv = rtllib_priv(dev); 633 struct r8192_priv *priv = rtllib_priv(dev);
633 634
634 RT_TRACE(COMP_INIT, "===========>%s()\n", __func__); 635 RT_TRACE(COMP_INIT, "===========>%s()\n", __func__);
635 curCR = read_nic_dword(dev, EPROM_CMD); 636 curCR = rtl92e_readl(dev, EPROM_CMD);
636 RT_TRACE(COMP_INIT, "read from Reg Cmd9346CR(%x):%x\n", EPROM_CMD, 637 RT_TRACE(COMP_INIT, "read from Reg Cmd9346CR(%x):%x\n", EPROM_CMD,
637 curCR); 638 curCR);
638 priv->epromtype = (curCR & EPROM_CMD_9356SEL) ? EEPROM_93C56 : 639 priv->epromtype = (curCR & EPROM_CMD_9356SEL) ? EEPROM_93C56 :
@@ -684,26 +685,26 @@ static void rtl8192_hwconfig(struct net_device *dev)
684 break; 685 break;
685 } 686 }
686 687
687 write_nic_byte(dev, BW_OPMODE, regBwOpMode); 688 rtl92e_writeb(dev, BW_OPMODE, regBwOpMode);
688 { 689 {
689 u32 ratr_value = 0; 690 u32 ratr_value = 0;
690 691
691 ratr_value = regRATR; 692 ratr_value = regRATR;
692 if (priv->rf_type == RF_1T2R) 693 if (priv->rf_type == RF_1T2R)
693 ratr_value &= ~(RATE_ALL_OFDM_2SS); 694 ratr_value &= ~(RATE_ALL_OFDM_2SS);
694 write_nic_dword(dev, RATR0, ratr_value); 695 rtl92e_writel(dev, RATR0, ratr_value);
695 write_nic_byte(dev, UFWP, 1); 696 rtl92e_writeb(dev, UFWP, 1);
696 } 697 }
697 regTmp = read_nic_byte(dev, 0x313); 698 regTmp = rtl92e_readb(dev, 0x313);
698 regRRSR = ((regTmp) << 24) | (regRRSR & 0x00ffffff); 699 regRRSR = ((regTmp) << 24) | (regRRSR & 0x00ffffff);
699 write_nic_dword(dev, RRSR, regRRSR); 700 rtl92e_writel(dev, RRSR, regRRSR);
700 701
701 write_nic_word(dev, RETRY_LIMIT, 702 rtl92e_writew(dev, RETRY_LIMIT,
702 priv->ShortRetryLimit << RETRY_LIMIT_SHORT_SHIFT | 703 priv->ShortRetryLimit << RETRY_LIMIT_SHORT_SHIFT |
703 priv->LongRetryLimit << RETRY_LIMIT_LONG_SHIFT); 704 priv->LongRetryLimit << RETRY_LIMIT_LONG_SHIFT);
704} 705}
705 706
706bool rtl8192_adapter_start(struct net_device *dev) 707bool rtl92e_start_adapter(struct net_device *dev)
707{ 708{
708 struct r8192_priv *priv = rtllib_priv(dev); 709 struct r8192_priv *priv = rtllib_priv(dev);
709 u32 ulRegRead; 710 u32 ulRegRead;
@@ -719,10 +720,10 @@ bool rtl8192_adapter_start(struct net_device *dev)
719 priv->being_init_adapter = true; 720 priv->being_init_adapter = true;
720 721
721start: 722start:
722 rtl8192_pci_resetdescring(dev); 723 rtl92e_reset_desc_ring(dev);
723 priv->Rf_Mode = RF_OP_By_SW_3wire; 724 priv->Rf_Mode = RF_OP_By_SW_3wire;
724 if (priv->ResetProgress == RESET_TYPE_NORESET) { 725 if (priv->ResetProgress == RESET_TYPE_NORESET) {
725 write_nic_byte(dev, ANAPAR, 0x37); 726 rtl92e_writeb(dev, ANAPAR, 0x37);
726 mdelay(500); 727 mdelay(500);
727 } 728 }
728 priv->pFirmware->firmware_status = FW_STATUS_0_INIT; 729 priv->pFirmware->firmware_status = FW_STATUS_0_INIT;
@@ -730,7 +731,7 @@ start:
730 if (priv->RegRfOff) 731 if (priv->RegRfOff)
731 priv->rtllib->eRFPowerState = eRfOff; 732 priv->rtllib->eRFPowerState = eRfOff;
732 733
733 ulRegRead = read_nic_dword(dev, CPU_GEN); 734 ulRegRead = rtl92e_readl(dev, CPU_GEN);
734 if (priv->pFirmware->firmware_status == FW_STATUS_0_INIT) 735 if (priv->pFirmware->firmware_status == FW_STATUS_0_INIT)
735 ulRegRead |= CPU_GEN_SYSTEM_RESET; 736 ulRegRead |= CPU_GEN_SYSTEM_RESET;
736 else if (priv->pFirmware->firmware_status == FW_STATUS_5_READY) 737 else if (priv->pFirmware->firmware_status == FW_STATUS_5_READY)
@@ -739,19 +740,19 @@ start:
739 netdev_err(dev, "%s(): undefined firmware state: %d.\n", 740 netdev_err(dev, "%s(): undefined firmware state: %d.\n",
740 __func__, priv->pFirmware->firmware_status); 741 __func__, priv->pFirmware->firmware_status);
741 742
742 write_nic_dword(dev, CPU_GEN, ulRegRead); 743 rtl92e_writel(dev, CPU_GEN, ulRegRead);
743 744
744 ICVersion = read_nic_byte(dev, IC_VERRSION); 745 ICVersion = rtl92e_readb(dev, IC_VERRSION);
745 if (ICVersion >= 0x4) { 746 if (ICVersion >= 0x4) {
746 SwitchingRegulatorOutput = read_nic_byte(dev, SWREGULATOR); 747 SwitchingRegulatorOutput = rtl92e_readb(dev, SWREGULATOR);
747 if (SwitchingRegulatorOutput != 0xb8) { 748 if (SwitchingRegulatorOutput != 0xb8) {
748 write_nic_byte(dev, SWREGULATOR, 0xa8); 749 rtl92e_writeb(dev, SWREGULATOR, 0xa8);
749 mdelay(1); 750 mdelay(1);
750 write_nic_byte(dev, SWREGULATOR, 0xb8); 751 rtl92e_writeb(dev, SWREGULATOR, 0xb8);
751 } 752 }
752 } 753 }
753 RT_TRACE(COMP_INIT, "BB Config Start!\n"); 754 RT_TRACE(COMP_INIT, "BB Config Start!\n");
754 rtStatus = rtl8192_BBConfig(dev); 755 rtStatus = rtl92e_config_bb(dev);
755 if (!rtStatus) { 756 if (!rtStatus) {
756 netdev_warn(dev, "%s(): Failed to configure BB\n", __func__); 757 netdev_warn(dev, "%s(): Failed to configure BB\n", __func__);
757 return rtStatus; 758 return rtStatus;
@@ -760,7 +761,7 @@ start:
760 761
761 priv->LoopbackMode = RTL819X_NO_LOOPBACK; 762 priv->LoopbackMode = RTL819X_NO_LOOPBACK;
762 if (priv->ResetProgress == RESET_TYPE_NORESET) { 763 if (priv->ResetProgress == RESET_TYPE_NORESET) {
763 ulRegRead = read_nic_dword(dev, CPU_GEN); 764 ulRegRead = rtl92e_readl(dev, CPU_GEN);
764 if (priv->LoopbackMode == RTL819X_NO_LOOPBACK) 765 if (priv->LoopbackMode == RTL819X_NO_LOOPBACK)
765 ulRegRead = ((ulRegRead & CPU_GEN_NO_LOOPBACK_MSK) | 766 ulRegRead = ((ulRegRead & CPU_GEN_NO_LOOPBACK_MSK) |
766 CPU_GEN_NO_LOOPBACK_SET); 767 CPU_GEN_NO_LOOPBACK_SET);
@@ -770,73 +771,73 @@ start:
770 netdev_err(dev, "%s: Invalid loopback mode setting.\n", 771 netdev_err(dev, "%s: Invalid loopback mode setting.\n",
771 __func__); 772 __func__);
772 773
773 write_nic_dword(dev, CPU_GEN, ulRegRead); 774 rtl92e_writel(dev, CPU_GEN, ulRegRead);
774 775
775 udelay(500); 776 udelay(500);
776 } 777 }
777 rtl8192_hwconfig(dev); 778 rtl8192_hwconfig(dev);
778 write_nic_byte(dev, CMDR, CR_RE | CR_TE); 779 rtl92e_writeb(dev, CMDR, CR_RE | CR_TE);
779 780
780 write_nic_byte(dev, PCIF, ((MXDMA2_NoLimit<<MXDMA2_RX_SHIFT) | 781 rtl92e_writeb(dev, PCIF, ((MXDMA2_NoLimit<<MXDMA2_RX_SHIFT) |
781 (MXDMA2_NoLimit<<MXDMA2_TX_SHIFT))); 782 (MXDMA2_NoLimit<<MXDMA2_TX_SHIFT)));
782 write_nic_dword(dev, MAC0, ((u32 *)dev->dev_addr)[0]); 783 rtl92e_writel(dev, MAC0, ((u32 *)dev->dev_addr)[0]);
783 write_nic_word(dev, MAC4, ((u16 *)(dev->dev_addr + 4))[0]); 784 rtl92e_writew(dev, MAC4, ((u16 *)(dev->dev_addr + 4))[0]);
784 write_nic_dword(dev, RCR, priv->ReceiveConfig); 785 rtl92e_writel(dev, RCR, priv->ReceiveConfig);
785 786
786 write_nic_dword(dev, RQPN1, NUM_OF_PAGE_IN_FW_QUEUE_BK << 787 rtl92e_writel(dev, RQPN1, NUM_OF_PAGE_IN_FW_QUEUE_BK <<
787 RSVD_FW_QUEUE_PAGE_BK_SHIFT | 788 RSVD_FW_QUEUE_PAGE_BK_SHIFT |
788 NUM_OF_PAGE_IN_FW_QUEUE_BE << 789 NUM_OF_PAGE_IN_FW_QUEUE_BE <<
789 RSVD_FW_QUEUE_PAGE_BE_SHIFT | 790 RSVD_FW_QUEUE_PAGE_BE_SHIFT |
790 NUM_OF_PAGE_IN_FW_QUEUE_VI << 791 NUM_OF_PAGE_IN_FW_QUEUE_VI <<
791 RSVD_FW_QUEUE_PAGE_VI_SHIFT | 792 RSVD_FW_QUEUE_PAGE_VI_SHIFT |
792 NUM_OF_PAGE_IN_FW_QUEUE_VO << 793 NUM_OF_PAGE_IN_FW_QUEUE_VO <<
793 RSVD_FW_QUEUE_PAGE_VO_SHIFT); 794 RSVD_FW_QUEUE_PAGE_VO_SHIFT);
794 write_nic_dword(dev, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << 795 rtl92e_writel(dev, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT <<
795 RSVD_FW_QUEUE_PAGE_MGNT_SHIFT); 796 RSVD_FW_QUEUE_PAGE_MGNT_SHIFT);
796 write_nic_dword(dev, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW | 797 rtl92e_writel(dev, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW |
797 NUM_OF_PAGE_IN_FW_QUEUE_BCN << 798 NUM_OF_PAGE_IN_FW_QUEUE_BCN <<
798 RSVD_FW_QUEUE_PAGE_BCN_SHIFT| 799 RSVD_FW_QUEUE_PAGE_BCN_SHIFT|
799 NUM_OF_PAGE_IN_FW_QUEUE_PUB << 800 NUM_OF_PAGE_IN_FW_QUEUE_PUB <<
800 RSVD_FW_QUEUE_PAGE_PUB_SHIFT); 801 RSVD_FW_QUEUE_PAGE_PUB_SHIFT);
801 802
802 rtl8192_tx_enable(dev); 803 rtl92e_tx_enable(dev);
803 rtl8192_rx_enable(dev); 804 rtl92e_rx_enable(dev);
804 ulRegRead = (0xFFF00000 & read_nic_dword(dev, RRSR)) | 805 ulRegRead = (0xFFF00000 & rtl92e_readl(dev, RRSR)) |
805 RATE_ALL_OFDM_AG | RATE_ALL_CCK; 806 RATE_ALL_OFDM_AG | RATE_ALL_CCK;
806 write_nic_dword(dev, RRSR, ulRegRead); 807 rtl92e_writel(dev, RRSR, ulRegRead);
807 write_nic_dword(dev, RATR0+4*7, (RATE_ALL_OFDM_AG | RATE_ALL_CCK)); 808 rtl92e_writel(dev, RATR0+4*7, (RATE_ALL_OFDM_AG | RATE_ALL_CCK));
808 809
809 write_nic_byte(dev, ACK_TIMEOUT, 0x30); 810 rtl92e_writeb(dev, ACK_TIMEOUT, 0x30);
810 811
811 if (priv->ResetProgress == RESET_TYPE_NORESET) 812 if (priv->ResetProgress == RESET_TYPE_NORESET)
812 rtl8192_SetWirelessMode(dev, priv->rtllib->mode); 813 rtl92e_set_wireless_mode(dev, priv->rtllib->mode);
813 CamResetAllEntry(dev); 814 rtl92e_cam_reset(dev);
814 { 815 {
815 u8 SECR_value = 0x0; 816 u8 SECR_value = 0x0;
816 817
817 SECR_value |= SCR_TxEncEnable; 818 SECR_value |= SCR_TxEncEnable;
818 SECR_value |= SCR_RxDecEnable; 819 SECR_value |= SCR_RxDecEnable;
819 SECR_value |= SCR_NoSKMC; 820 SECR_value |= SCR_NoSKMC;
820 write_nic_byte(dev, SECR, SECR_value); 821 rtl92e_writeb(dev, SECR, SECR_value);
821 } 822 }
822 write_nic_word(dev, ATIMWND, 2); 823 rtl92e_writew(dev, ATIMWND, 2);
823 write_nic_word(dev, BCN_INTERVAL, 100); 824 rtl92e_writew(dev, BCN_INTERVAL, 100);
824 { 825 {
825 int i; 826 int i;
826 827
827 for (i = 0; i < QOS_QUEUE_NUM; i++) 828 for (i = 0; i < QOS_QUEUE_NUM; i++)
828 write_nic_dword(dev, WDCAPARA_ADD[i], 0x005e4332); 829 rtl92e_writel(dev, WDCAPARA_ADD[i], 0x005e4332);
829 } 830 }
830 write_nic_byte(dev, 0xbe, 0xc0); 831 rtl92e_writeb(dev, 0xbe, 0xc0);
831 832
832 rtl8192_phy_configmac(dev); 833 rtl92e_config_mac(dev);
833 834
834 if (priv->card_8192_version > (u8) VERSION_8190_BD) { 835 if (priv->card_8192_version > (u8) VERSION_8190_BD) {
835 rtl8192_phy_getTxPower(dev); 836 rtl92e_get_tx_power(dev);
836 rtl8192_phy_setTxPower(dev, priv->chan); 837 rtl92e_set_tx_power(dev, priv->chan);
837 } 838 }
838 839
839 tmpvalue = read_nic_byte(dev, IC_VERRSION); 840 tmpvalue = rtl92e_readb(dev, IC_VERRSION);
840 priv->IC_Cut = tmpvalue; 841 priv->IC_Cut = tmpvalue;
841 RT_TRACE(COMP_INIT, "priv->IC_Cut= 0x%x\n", priv->IC_Cut); 842 RT_TRACE(COMP_INIT, "priv->IC_Cut= 0x%x\n", priv->IC_Cut);
842 if (priv->IC_Cut >= IC_VersionCut_D) { 843 if (priv->IC_Cut >= IC_VersionCut_D) {
@@ -851,7 +852,7 @@ start:
851 } 852 }
852 853
853 RT_TRACE(COMP_INIT, "Load Firmware!\n"); 854 RT_TRACE(COMP_INIT, "Load Firmware!\n");
854 bfirmwareok = init_firmware(dev); 855 bfirmwareok = rtl92e_init_fw(dev);
855 if (!bfirmwareok) { 856 if (!bfirmwareok) {
856 if (retry_times < 10) { 857 if (retry_times < 10) {
857 retry_times++; 858 retry_times++;
@@ -864,37 +865,34 @@ start:
864 RT_TRACE(COMP_INIT, "Load Firmware finished!\n"); 865 RT_TRACE(COMP_INIT, "Load Firmware finished!\n");
865 if (priv->ResetProgress == RESET_TYPE_NORESET) { 866 if (priv->ResetProgress == RESET_TYPE_NORESET) {
866 RT_TRACE(COMP_INIT, "RF Config Started!\n"); 867 RT_TRACE(COMP_INIT, "RF Config Started!\n");
867 rtStatus = rtl8192_phy_RFConfig(dev); 868 rtStatus = rtl92e_config_phy(dev);
868 if (!rtStatus) { 869 if (!rtStatus) {
869 netdev_info(dev, "RF Config failed\n"); 870 netdev_info(dev, "RF Config failed\n");
870 return rtStatus; 871 return rtStatus;
871 } 872 }
872 RT_TRACE(COMP_INIT, "RF Config Finished!\n"); 873 RT_TRACE(COMP_INIT, "RF Config Finished!\n");
873 } 874 }
874 rtl8192_phy_updateInitGain(dev);
875 875
876 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn, 0x1); 876 rtl92e_set_bb_reg(dev, rFPGA0_RFMOD, bCCKEn, 0x1);
877 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bOFDMEn, 0x1); 877 rtl92e_set_bb_reg(dev, rFPGA0_RFMOD, bOFDMEn, 0x1);
878 878
879 write_nic_byte(dev, 0x87, 0x0); 879 rtl92e_writeb(dev, 0x87, 0x0);
880 880
881 if (priv->RegRfOff) { 881 if (priv->RegRfOff) {
882 RT_TRACE((COMP_INIT | COMP_RF | COMP_POWER), 882 RT_TRACE((COMP_INIT | COMP_RF | COMP_POWER),
883 "%s(): Turn off RF for RegRfOff ----------\n", 883 "%s(): Turn off RF for RegRfOff ----------\n",
884 __func__); 884 __func__);
885 MgntActSet_RF_State(dev, eRfOff, RF_CHANGE_BY_SW, true); 885 rtl92e_set_rf_state(dev, eRfOff, RF_CHANGE_BY_SW);
886 } else if (priv->rtllib->RfOffReason > RF_CHANGE_BY_PS) { 886 } else if (priv->rtllib->RfOffReason > RF_CHANGE_BY_PS) {
887 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), 887 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER),
888 "%s(): Turn off RF for RfOffReason(%d) ----------\n", 888 "%s(): Turn off RF for RfOffReason(%d) ----------\n",
889 __func__, priv->rtllib->RfOffReason); 889 __func__, priv->rtllib->RfOffReason);
890 MgntActSet_RF_State(dev, eRfOff, priv->rtllib->RfOffReason, 890 rtl92e_set_rf_state(dev, eRfOff, priv->rtllib->RfOffReason);
891 true);
892 } else if (priv->rtllib->RfOffReason >= RF_CHANGE_BY_IPS) { 891 } else if (priv->rtllib->RfOffReason >= RF_CHANGE_BY_IPS) {
893 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), 892 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER),
894 "%s(): Turn off RF for RfOffReason(%d) ----------\n", 893 "%s(): Turn off RF for RfOffReason(%d) ----------\n",
895 __func__, priv->rtllib->RfOffReason); 894 __func__, priv->rtllib->RfOffReason);
896 MgntActSet_RF_State(dev, eRfOff, priv->rtllib->RfOffReason, 895 rtl92e_set_rf_state(dev, eRfOff, priv->rtllib->RfOffReason);
897 true);
898 } else { 896 } else {
899 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): RF-ON\n", 897 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): RF-ON\n",
900 __func__); 898 __func__);
@@ -908,13 +906,13 @@ start:
908 priv->Rf_Mode = RF_OP_By_SW_3wire; 906 priv->Rf_Mode = RF_OP_By_SW_3wire;
909 907
910 if (priv->ResetProgress == RESET_TYPE_NORESET) { 908 if (priv->ResetProgress == RESET_TYPE_NORESET) {
911 dm_initialize_txpower_tracking(dev); 909 rtl92e_dm_init_txpower_tracking(dev);
912 910
913 if (priv->IC_Cut >= IC_VersionCut_D) { 911 if (priv->IC_Cut >= IC_VersionCut_D) {
914 tmpRegA = rtl8192_QueryBBReg(dev, 912 tmpRegA = rtl92e_get_bb_reg(dev, rOFDM0_XATxIQImbalance,
915 rOFDM0_XATxIQImbalance, bMaskDWord); 913 bMaskDWord);
916 tmpRegC = rtl8192_QueryBBReg(dev, 914 tmpRegC = rtl92e_get_bb_reg(dev, rOFDM0_XCTxIQImbalance,
917 rOFDM0_XCTxIQImbalance, bMaskDWord); 915 bMaskDWord);
918 for (i = 0; i < TxBBGainTableLength; i++) { 916 for (i = 0; i < TxBBGainTableLength; i++) {
919 if (tmpRegA == dm_tx_bb_gain[i]) { 917 if (tmpRegA == dm_tx_bb_gain[i]) {
920 priv->rfa_txpowertrackingindex = (u8)i; 918 priv->rfa_txpowertrackingindex = (u8)i;
@@ -926,8 +924,8 @@ start:
926 } 924 }
927 } 925 }
928 926
929 TempCCk = rtl8192_QueryBBReg(dev, 927 TempCCk = rtl92e_get_bb_reg(dev, rCCK0_TxFilter1,
930 rCCK0_TxFilter1, bMaskByte2); 928 bMaskByte2);
931 929
932 for (i = 0; i < CCKTxBBGainTableLength; i++) { 930 for (i = 0; i < CCKTxBBGainTableLength; i++) {
933 if (TempCCk == dm_cck_tx_bb_gain[i][0]) { 931 if (TempCCk == dm_cck_tx_bb_gain[i][0]) {
@@ -954,7 +952,7 @@ start:
954 priv->btxpower_tracking = false; 952 priv->btxpower_tracking = false;
955 } 953 }
956 } 954 }
957 rtl8192_irq_enable(dev); 955 rtl92e_irq_enable(dev);
958end: 956end:
959 priv->being_init_adapter = false; 957 priv->being_init_adapter = false;
960 return rtStatus; 958 return rtStatus;
@@ -969,27 +967,27 @@ static void rtl8192_net_update(struct net_device *dev)
969 u16 rate_config = 0; 967 u16 rate_config = 0;
970 968
971 net = &priv->rtllib->current_network; 969 net = &priv->rtllib->current_network;
972 rtl8192_config_rate(dev, &rate_config); 970 rtl92e_config_rate(dev, &rate_config);
973 priv->dot11CurrentPreambleMode = PREAMBLE_AUTO; 971 priv->dot11CurrentPreambleMode = PREAMBLE_AUTO;
974 priv->basic_rate = rate_config &= 0x15f; 972 priv->basic_rate = rate_config &= 0x15f;
975 write_nic_dword(dev, BSSIDR, ((u32 *)net->bssid)[0]); 973 rtl92e_writel(dev, BSSIDR, ((u32 *)net->bssid)[0]);
976 write_nic_word(dev, BSSIDR+4, ((u16 *)net->bssid)[2]); 974 rtl92e_writew(dev, BSSIDR+4, ((u16 *)net->bssid)[2]);
977 975
978 if (priv->rtllib->iw_mode == IW_MODE_ADHOC) { 976 if (priv->rtllib->iw_mode == IW_MODE_ADHOC) {
979 write_nic_word(dev, ATIMWND, 2); 977 rtl92e_writew(dev, ATIMWND, 2);
980 write_nic_word(dev, BCN_DMATIME, 256); 978 rtl92e_writew(dev, BCN_DMATIME, 256);
981 write_nic_word(dev, BCN_INTERVAL, net->beacon_interval); 979 rtl92e_writew(dev, BCN_INTERVAL, net->beacon_interval);
982 write_nic_word(dev, BCN_DRV_EARLY_INT, 10); 980 rtl92e_writew(dev, BCN_DRV_EARLY_INT, 10);
983 write_nic_byte(dev, BCN_ERR_THRESH, 100); 981 rtl92e_writeb(dev, BCN_ERR_THRESH, 100);
984 982
985 BcnTimeCfg |= (BcnCW<<BCN_TCFG_CW_SHIFT); 983 BcnTimeCfg |= (BcnCW<<BCN_TCFG_CW_SHIFT);
986 BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS; 984 BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS;
987 985
988 write_nic_word(dev, BCN_TCFG, BcnTimeCfg); 986 rtl92e_writew(dev, BCN_TCFG, BcnTimeCfg);
989 } 987 }
990} 988}
991 989
992void rtl8192_link_change(struct net_device *dev) 990void rtl92e_link_change(struct net_device *dev)
993{ 991{
994 struct r8192_priv *priv = rtllib_priv(dev); 992 struct r8192_priv *priv = rtllib_priv(dev);
995 struct rtllib_device *ieee = priv->rtllib; 993 struct rtllib_device *ieee = priv->rtllib;
@@ -1002,16 +1000,16 @@ void rtl8192_link_change(struct net_device *dev)
1002 priv->ops->update_ratr_table(dev); 1000 priv->ops->update_ratr_table(dev);
1003 if ((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || 1001 if ((KEY_TYPE_WEP40 == ieee->pairwise_key_type) ||
1004 (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) 1002 (KEY_TYPE_WEP104 == ieee->pairwise_key_type))
1005 EnableHWSecurityConfig8192(dev); 1003 rtl92e_enable_hw_security_config(dev);
1006 } else { 1004 } else {
1007 write_nic_byte(dev, 0x173, 0); 1005 rtl92e_writeb(dev, 0x173, 0);
1008 } 1006 }
1009 rtl8192e_update_msr(dev); 1007 rtl8192e_update_msr(dev);
1010 1008
1011 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) { 1009 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) {
1012 u32 reg = 0; 1010 u32 reg = 0;
1013 1011
1014 reg = read_nic_dword(dev, RCR); 1012 reg = rtl92e_readl(dev, RCR);
1015 if (priv->rtllib->state == RTLLIB_LINKED) { 1013 if (priv->rtllib->state == RTLLIB_LINKED) {
1016 if (ieee->IntelPromiscuousModeInfo.bPromiscuousOn) 1014 if (ieee->IntelPromiscuousModeInfo.bPromiscuousOn)
1017 ; 1015 ;
@@ -1020,12 +1018,12 @@ void rtl8192_link_change(struct net_device *dev)
1020 } else 1018 } else
1021 priv->ReceiveConfig = reg &= ~RCR_CBSSID; 1019 priv->ReceiveConfig = reg &= ~RCR_CBSSID;
1022 1020
1023 write_nic_dword(dev, RCR, reg); 1021 rtl92e_writel(dev, RCR, reg);
1024 } 1022 }
1025} 1023}
1026 1024
1027void rtl8192_AllowAllDestAddr(struct net_device *dev, 1025void rtl92e_set_monitor_mode(struct net_device *dev, bool bAllowAllDA,
1028 bool bAllowAllDA, bool WriteIntoReg) 1026 bool WriteIntoReg)
1029{ 1027{
1030 struct r8192_priv *priv = rtllib_priv(dev); 1028 struct r8192_priv *priv = rtllib_priv(dev);
1031 1029
@@ -1035,7 +1033,7 @@ void rtl8192_AllowAllDestAddr(struct net_device *dev,
1035 priv->ReceiveConfig &= ~RCR_AAP; 1033 priv->ReceiveConfig &= ~RCR_AAP;
1036 1034
1037 if (WriteIntoReg) 1035 if (WriteIntoReg)
1038 write_nic_dword(dev, RCR, priv->ReceiveConfig); 1036 rtl92e_writel(dev, RCR, priv->ReceiveConfig);
1039} 1037}
1040 1038
1041static u8 MRateToHwRate8190Pci(u8 rate) 1039static u8 MRateToHwRate8190Pci(u8 rate)
@@ -1177,8 +1175,20 @@ static u8 rtl8192_MapHwQueueToFirmwareQueue(struct net_device *dev, u8 QueueID,
1177 return QueueSelect; 1175 return QueueSelect;
1178} 1176}
1179 1177
1180void rtl8192_tx_fill_desc(struct net_device *dev, struct tx_desc *pdesc, 1178static u8 rtl8192_QueryIsShort(u8 TxHT, u8 TxRate, struct cb_desc *tcb_desc)
1181 struct cb_desc *cb_desc, struct sk_buff *skb) 1179{
1180 u8 tmp_Short;
1181
1182 tmp_Short = (TxHT == 1) ? ((tcb_desc->bUseShortGI) ? 1 : 0) :
1183 ((tcb_desc->bUseShortPreamble) ? 1 : 0);
1184 if (TxHT == 1 && TxRate != DESC90_RATEMCS15)
1185 tmp_Short = 0;
1186
1187 return tmp_Short;
1188}
1189
1190void rtl92e_fill_tx_desc(struct net_device *dev, struct tx_desc *pdesc,
1191 struct cb_desc *cb_desc, struct sk_buff *skb)
1182{ 1192{
1183 struct r8192_priv *priv = rtllib_priv(dev); 1193 struct r8192_priv *priv = rtllib_priv(dev);
1184 dma_addr_t mapping = pci_map_single(priv->pdev, skb->data, skb->len, 1194 dma_addr_t mapping = pci_map_single(priv->pdev, skb->data, skb->len,
@@ -1286,9 +1296,8 @@ void rtl8192_tx_fill_desc(struct net_device *dev, struct tx_desc *pdesc,
1286 pdesc->TxBuffAddr = mapping; 1296 pdesc->TxBuffAddr = mapping;
1287} 1297}
1288 1298
1289void rtl8192_tx_fill_cmd_desc(struct net_device *dev, 1299void rtl92e_fill_tx_cmd_desc(struct net_device *dev, struct tx_desc_cmd *entry,
1290 struct tx_desc_cmd *entry, 1300 struct cb_desc *cb_desc, struct sk_buff *skb)
1291 struct cb_desc *cb_desc, struct sk_buff *skb)
1292{ 1301{
1293 struct r8192_priv *priv = rtllib_priv(dev); 1302 struct r8192_priv *priv = rtllib_priv(dev);
1294 dma_addr_t mapping = pci_map_single(priv->pdev, skb->data, skb->len, 1303 dma_addr_t mapping = pci_map_single(priv->pdev, skb->data, skb->len,
@@ -1506,8 +1515,9 @@ static void rtl8192_query_rxphystatus(
1506 pstats->bPacketBeacon = precord_stats->bPacketBeacon = bPacketBeacon; 1515 pstats->bPacketBeacon = precord_stats->bPacketBeacon = bPacketBeacon;
1507 pstats->bToSelfBA = precord_stats->bToSelfBA = bToSelfBA; 1516 pstats->bToSelfBA = precord_stats->bToSelfBA = bToSelfBA;
1508 if (check_reg824 == 0) { 1517 if (check_reg824 == 0) {
1509 reg824_bit9 = rtl8192_QueryBBReg(priv->rtllib->dev, 1518 reg824_bit9 = rtl92e_get_bb_reg(priv->rtllib->dev,
1510 rFPGA0_XA_HSSIParameter2, 0x200); 1519 rFPGA0_XA_HSSIParameter2,
1520 0x200);
1511 check_reg824 = 1; 1521 check_reg824 = 1;
1512 } 1522 }
1513 1523
@@ -1575,7 +1585,7 @@ static void rtl8192_query_rxphystatus(
1575 } 1585 }
1576 } 1586 }
1577 1587
1578 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all); 1588 pwdb_all = rtl92e_rx_db_to_percent(rx_pwr_all);
1579 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all; 1589 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
1580 pstats->RecvSignalPower = rx_pwr_all; 1590 pstats->RecvSignalPower = rx_pwr_all;
1581 1591
@@ -1615,7 +1625,7 @@ static void rtl8192_query_rxphystatus(
1615 rx_snrX /= 2; 1625 rx_snrX /= 2;
1616 priv->stats.rxSNRdB[i] = (long)rx_snrX; 1626 priv->stats.rxSNRdB[i] = (long)rx_snrX;
1617 1627
1618 RSSI = rtl819x_query_rxpwrpercentage(rx_pwr[i]); 1628 RSSI = rtl92e_rx_db_to_percent(rx_pwr[i]);
1619 if (priv->brfpath_rxenable[i]) 1629 if (priv->brfpath_rxenable[i])
1620 total_rssi += RSSI; 1630 total_rssi += RSSI;
1621 1631
@@ -1628,7 +1638,7 @@ static void rtl8192_query_rxphystatus(
1628 1638
1629 1639
1630 rx_pwr_all = (((pofdm_buf->pwdb_all) >> 1) & 0x7f) - 106; 1640 rx_pwr_all = (((pofdm_buf->pwdb_all) >> 1) & 0x7f) - 106;
1631 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all); 1641 pwdb_all = rtl92e_rx_db_to_percent(rx_pwr_all);
1632 1642
1633 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all; 1643 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
1634 pstats->RxPower = precord_stats->RxPower = rx_pwr_all; 1644 pstats->RxPower = precord_stats->RxPower = rx_pwr_all;
@@ -1645,7 +1655,7 @@ static void rtl8192_query_rxphystatus(
1645 1655
1646 rx_evmX /= 2; 1656 rx_evmX /= 2;
1647 1657
1648 evm = rtl819x_evm_dbtopercentage(rx_evmX); 1658 evm = rtl92e_evm_db_to_percent(rx_evmX);
1649 if (bpacket_match_bssid) { 1659 if (bpacket_match_bssid) {
1650 if (i == 0) { 1660 if (i == 0) {
1651 pstats->SignalQuality = (u8)(evm & 1661 pstats->SignalQuality = (u8)(evm &
@@ -1721,8 +1731,8 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
1721 slide_rssi_index = 0; 1731 slide_rssi_index = 0;
1722 1732
1723 tmp_val = priv->stats.slide_rssi_total/slide_rssi_statistics; 1733 tmp_val = priv->stats.slide_rssi_total/slide_rssi_statistics;
1724 priv->stats.signal_strength = rtl819x_translate_todbm(priv, 1734 priv->stats.signal_strength = rtl92e_translate_to_dbm(priv,
1725 (u8)tmp_val); 1735 (u8)tmp_val);
1726 curr_st->rssi = priv->stats.signal_strength; 1736 curr_st->rssi = priv->stats.signal_strength;
1727 if (!prev_st->bPacketMatchBSSID) { 1737 if (!prev_st->bPacketMatchBSSID) {
1728 if (!prev_st->bToSelfBA) 1738 if (!prev_st->bToSelfBA)
@@ -1732,13 +1742,10 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
1732 if (!bcheck) 1742 if (!bcheck)
1733 return; 1743 return;
1734 1744
1735 rtl819x_process_cck_rxpathsel(priv, prev_st);
1736
1737 priv->stats.num_process_phyinfo++; 1745 priv->stats.num_process_phyinfo++;
1738 if (!prev_st->bIsCCK && prev_st->bPacketToSelf) { 1746 if (!prev_st->bIsCCK && prev_st->bPacketToSelf) {
1739 for (rfpath = RF90_PATH_A; rfpath < RF90_PATH_C; rfpath++) { 1747 for (rfpath = RF90_PATH_A; rfpath < RF90_PATH_C; rfpath++) {
1740 if (!rtl8192_phy_CheckIsLegalRFPath(priv->rtllib->dev, 1748 if (!rtl92e_is_legal_rf_path(priv->rtllib->dev, rfpath))
1741 rfpath))
1742 continue; 1749 continue;
1743 RT_TRACE(COMP_DBG, 1750 RT_TRACE(COMP_DBG,
1744 "Jacken -> pPreviousstats->RxMIMOSignalStrength[rfpath] = %d\n", 1751 "Jacken -> pPreviousstats->RxMIMOSignalStrength[rfpath] = %d\n",
@@ -1813,7 +1820,7 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
1813 (RX_SMOOTH-1)) + 1820 (RX_SMOOTH-1)) +
1814 (prev_st->RxPWDBAll)) / (RX_SMOOTH); 1821 (prev_st->RxPWDBAll)) / (RX_SMOOTH);
1815 } 1822 }
1816 rtl819x_update_rxsignalstatistics8190pci(priv, prev_st); 1823 rtl92e_update_rx_statistics(priv, prev_st);
1817 } 1824 }
1818 1825
1819 if (prev_st->SignalQuality != 0) { 1826 if (prev_st->SignalQuality != 0) {
@@ -1900,7 +1907,7 @@ static void rtl8192_TranslateRxSignalStuff(struct net_device *dev,
1900 rtl8192_query_rxphystatus(priv, pstats, pdesc, pdrvinfo, 1907 rtl8192_query_rxphystatus(priv, pstats, pdesc, pdrvinfo,
1901 &previous_stats, bpacket_match_bssid, 1908 &previous_stats, bpacket_match_bssid,
1902 bpacket_toself, bPacketBeacon, bToSelfBA); 1909 bpacket_toself, bPacketBeacon, bToSelfBA);
1903 rtl8192_record_rxdesc_forlateruse(pstats, &previous_stats); 1910 rtl92e_copy_mpdu_stats(pstats, &previous_stats);
1904} 1911}
1905 1912
1906static void rtl8192_UpdateReceivedRateHistogramStatistics( 1913static void rtl8192_UpdateReceivedRateHistogramStatistics(
@@ -2016,10 +2023,8 @@ static void rtl8192_UpdateReceivedRateHistogramStatistics(
2016 priv->stats.received_rate_histogram[rcvType][rateIndex]++; 2023 priv->stats.received_rate_histogram[rcvType][rateIndex]++;
2017} 2024}
2018 2025
2019bool rtl8192_rx_query_status_desc(struct net_device *dev, 2026bool rtl92e_get_rx_stats(struct net_device *dev, struct rtllib_rx_stats *stats,
2020 struct rtllib_rx_stats *stats, 2027 struct rx_desc *pdesc, struct sk_buff *skb)
2021 struct rx_desc *pdesc,
2022 struct sk_buff *skb)
2023{ 2028{
2024 struct r8192_priv *priv = rtllib_priv(dev); 2029 struct r8192_priv *priv = rtllib_priv(dev);
2025 struct rx_fwinfo *pDrvInfo = NULL; 2030 struct rx_fwinfo *pDrvInfo = NULL;
@@ -2063,9 +2068,9 @@ bool rtl8192_rx_query_status_desc(struct net_device *dev,
2063 (pDrvInfo->FirstAGGR == 1); 2068 (pDrvInfo->FirstAGGR == 1);
2064 2069
2065 stats->TimeStampLow = pDrvInfo->TSFL; 2070 stats->TimeStampLow = pDrvInfo->TSFL;
2066 stats->TimeStampHigh = read_nic_dword(dev, TSFR+4); 2071 stats->TimeStampHigh = rtl92e_readl(dev, TSFR+4);
2067 2072
2068 rtl819x_UpdateRxPktTimeStamp(dev, stats); 2073 rtl92e_update_rx_pkt_timestamp(dev, stats);
2069 2074
2070 if ((stats->RxBufShift + stats->RxDrvInfoSize) > 0) 2075 if ((stats->RxBufShift + stats->RxDrvInfoSize) > 0)
2071 stats->bShift = 1; 2076 stats->bShift = 1;
@@ -2089,7 +2094,7 @@ bool rtl8192_rx_query_status_desc(struct net_device *dev,
2089 return true; 2094 return true;
2090} 2095}
2091 2096
2092void rtl8192_halt_adapter(struct net_device *dev, bool reset) 2097void rtl92e_stop_adapter(struct net_device *dev, bool reset)
2093{ 2098{
2094 struct r8192_priv *priv = rtllib_priv(dev); 2099 struct r8192_priv *priv = rtllib_priv(dev);
2095 int i; 2100 int i;
@@ -2102,7 +2107,7 @@ void rtl8192_halt_adapter(struct net_device *dev, bool reset)
2102 2107
2103 if (!priv->rtllib->bSupportRemoteWakeUp) { 2108 if (!priv->rtllib->bSupportRemoteWakeUp) {
2104 u1bTmp = 0x0; 2109 u1bTmp = 0x0;
2105 write_nic_byte(dev, CMDR, u1bTmp); 2110 rtl92e_writeb(dev, CMDR, u1bTmp);
2106 } 2111 }
2107 2112
2108 mdelay(20); 2113 mdelay(20);
@@ -2113,18 +2118,18 @@ void rtl8192_halt_adapter(struct net_device *dev, bool reset)
2113 priv->bHwRfOffAction = 2; 2118 priv->bHwRfOffAction = 2;
2114 2119
2115 if (!priv->rtllib->bSupportRemoteWakeUp) { 2120 if (!priv->rtllib->bSupportRemoteWakeUp) {
2116 PHY_SetRtl8192eRfOff(dev); 2121 rtl92e_set_rf_off(dev);
2117 ulRegRead = read_nic_dword(dev, CPU_GEN); 2122 ulRegRead = rtl92e_readl(dev, CPU_GEN);
2118 ulRegRead |= CPU_GEN_SYSTEM_RESET; 2123 ulRegRead |= CPU_GEN_SYSTEM_RESET;
2119 write_nic_dword(dev, CPU_GEN, ulRegRead); 2124 rtl92e_writel(dev, CPU_GEN, ulRegRead);
2120 } else { 2125 } else {
2121 write_nic_dword(dev, WFCRC0, 0xffffffff); 2126 rtl92e_writel(dev, WFCRC0, 0xffffffff);
2122 write_nic_dword(dev, WFCRC1, 0xffffffff); 2127 rtl92e_writel(dev, WFCRC1, 0xffffffff);
2123 write_nic_dword(dev, WFCRC2, 0xffffffff); 2128 rtl92e_writel(dev, WFCRC2, 0xffffffff);
2124 2129
2125 2130
2126 write_nic_byte(dev, PMR, 0x5); 2131 rtl92e_writeb(dev, PMR, 0x5);
2127 write_nic_byte(dev, MacBlkCtrl, 0xa); 2132 rtl92e_writeb(dev, MacBlkCtrl, 0xa);
2128 } 2133 }
2129 } 2134 }
2130 2135
@@ -2136,7 +2141,7 @@ void rtl8192_halt_adapter(struct net_device *dev, bool reset)
2136 skb_queue_purge(&priv->skb_queue); 2141 skb_queue_purge(&priv->skb_queue);
2137} 2142}
2138 2143
2139void rtl8192_update_ratr_table(struct net_device *dev) 2144void rtl92e_update_ratr_table(struct net_device *dev)
2140{ 2145{
2141 struct r8192_priv *priv = rtllib_priv(dev); 2146 struct r8192_priv *priv = rtllib_priv(dev);
2142 struct rtllib_device *ieee = priv->rtllib; 2147 struct rtllib_device *ieee = priv->rtllib;
@@ -2145,7 +2150,7 @@ void rtl8192_update_ratr_table(struct net_device *dev)
2145 u16 rate_config = 0; 2150 u16 rate_config = 0;
2146 u8 rate_index = 0; 2151 u8 rate_index = 0;
2147 2152
2148 rtl8192_config_rate(dev, &rate_config); 2153 rtl92e_config_rate(dev, &rate_config);
2149 ratr_value = rate_config | *pMcsRate << 12; 2154 ratr_value = rate_config | *pMcsRate << 12;
2150 switch (ieee->mode) { 2155 switch (ieee->mode) {
2151 case IEEE_A: 2156 case IEEE_A:
@@ -2179,12 +2184,12 @@ void rtl8192_update_ratr_table(struct net_device *dev)
2179 else if (!ieee->pHTInfo->bCurTxBW40MHz && 2184 else if (!ieee->pHTInfo->bCurTxBW40MHz &&
2180 ieee->pHTInfo->bCurShortGI20MHz) 2185 ieee->pHTInfo->bCurShortGI20MHz)
2181 ratr_value |= 0x80000000; 2186 ratr_value |= 0x80000000;
2182 write_nic_dword(dev, RATR0+rate_index*4, ratr_value); 2187 rtl92e_writel(dev, RATR0+rate_index*4, ratr_value);
2183 write_nic_byte(dev, UFWP, 1); 2188 rtl92e_writeb(dev, UFWP, 1);
2184} 2189}
2185 2190
2186void 2191void
2187rtl8192_InitializeVariables(struct net_device *dev) 2192rtl92e_init_variables(struct net_device *dev)
2188{ 2193{
2189 struct r8192_priv *priv = rtllib_priv(dev); 2194 struct r8192_priv *priv = rtllib_priv(dev);
2190 2195
@@ -2218,66 +2223,65 @@ rtl8192_InitializeVariables(struct net_device *dev)
2218 priv->bfirst_after_down = false; 2223 priv->bfirst_after_down = false;
2219} 2224}
2220 2225
2221void rtl8192_EnableInterrupt(struct net_device *dev) 2226void rtl92e_enable_irq(struct net_device *dev)
2222{ 2227{
2223 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 2228 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2224 2229
2225 priv->irq_enabled = 1; 2230 priv->irq_enabled = 1;
2226 2231
2227 write_nic_dword(dev, INTA_MASK, priv->irq_mask[0]); 2232 rtl92e_writel(dev, INTA_MASK, priv->irq_mask[0]);
2228 2233
2229} 2234}
2230 2235
2231void rtl8192_DisableInterrupt(struct net_device *dev) 2236void rtl92e_disable_irq(struct net_device *dev)
2232{ 2237{
2233 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 2238 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2234 2239
2235 write_nic_dword(dev, INTA_MASK, 0); 2240 rtl92e_writel(dev, INTA_MASK, 0);
2236 2241
2237 priv->irq_enabled = 0; 2242 priv->irq_enabled = 0;
2238} 2243}
2239 2244
2240void rtl8192_ClearInterrupt(struct net_device *dev) 2245void rtl92e_clear_irq(struct net_device *dev)
2241{ 2246{
2242 u32 tmp = 0; 2247 u32 tmp = 0;
2243 2248
2244 tmp = read_nic_dword(dev, ISR); 2249 tmp = rtl92e_readl(dev, ISR);
2245 write_nic_dword(dev, ISR, tmp); 2250 rtl92e_writel(dev, ISR, tmp);
2246} 2251}
2247 2252
2248 2253
2249void rtl8192_enable_rx(struct net_device *dev) 2254void rtl92e_enable_rx(struct net_device *dev)
2250{ 2255{
2251 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 2256 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2252 2257
2253 write_nic_dword(dev, RDQDA, priv->rx_ring_dma[RX_MPDU_QUEUE]); 2258 rtl92e_writel(dev, RDQDA, priv->rx_ring_dma[RX_MPDU_QUEUE]);
2254} 2259}
2255 2260
2256static const u32 TX_DESC_BASE[] = { 2261static const u32 TX_DESC_BASE[] = {
2257 BKQDA, BEQDA, VIQDA, VOQDA, HCCAQDA, CQDA, MQDA, HQDA, BQDA 2262 BKQDA, BEQDA, VIQDA, VOQDA, HCCAQDA, CQDA, MQDA, HQDA, BQDA
2258}; 2263};
2259 2264
2260void rtl8192_enable_tx(struct net_device *dev) 2265void rtl92e_enable_tx(struct net_device *dev)
2261{ 2266{
2262 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 2267 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2263 u32 i; 2268 u32 i;
2264 2269
2265 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) 2270 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
2266 write_nic_dword(dev, TX_DESC_BASE[i], priv->tx_ring[i].dma); 2271 rtl92e_writel(dev, TX_DESC_BASE[i], priv->tx_ring[i].dma);
2267} 2272}
2268 2273
2269 2274
2270void rtl8192_interrupt_recognized(struct net_device *dev, u32 *p_inta, 2275void rtl92e_ack_irq(struct net_device *dev, u32 *p_inta, u32 *p_intb)
2271 u32 *p_intb)
2272{ 2276{
2273 *p_inta = read_nic_dword(dev, ISR); 2277 *p_inta = rtl92e_readl(dev, ISR);
2274 write_nic_dword(dev, ISR, *p_inta); 2278 rtl92e_writel(dev, ISR, *p_inta);
2275} 2279}
2276 2280
2277bool rtl8192_HalRxCheckStuck(struct net_device *dev) 2281bool rtl92e_is_rx_stuck(struct net_device *dev)
2278{ 2282{
2279 struct r8192_priv *priv = rtllib_priv(dev); 2283 struct r8192_priv *priv = rtllib_priv(dev);
2280 u16 RegRxCounter = read_nic_word(dev, 0x130); 2284 u16 RegRxCounter = rtl92e_readw(dev, 0x130);
2281 bool bStuck = false; 2285 bool bStuck = false;
2282 static u8 rx_chk_cnt; 2286 static u8 rx_chk_cnt;
2283 u32 SlotIndex = 0, TotalRxStuckCount = 0; 2287 u32 SlotIndex = 0, TotalRxStuckCount = 0;
@@ -2338,11 +2342,11 @@ bool rtl8192_HalRxCheckStuck(struct net_device *dev)
2338 return bStuck; 2342 return bStuck;
2339} 2343}
2340 2344
2341bool rtl8192_HalTxCheckStuck(struct net_device *dev) 2345bool rtl92e_is_tx_stuck(struct net_device *dev)
2342{ 2346{
2343 struct r8192_priv *priv = rtllib_priv(dev); 2347 struct r8192_priv *priv = rtllib_priv(dev);
2344 bool bStuck = false; 2348 bool bStuck = false;
2345 u16 RegTxCounter = read_nic_word(dev, 0x128); 2349 u16 RegTxCounter = rtl92e_readw(dev, 0x128);
2346 2350
2347 RT_TRACE(COMP_RESET, "%s():RegTxCounter is %d,TxCounter is %d\n", 2351 RT_TRACE(COMP_RESET, "%s():RegTxCounter is %d,TxCounter is %d\n",
2348 __func__, RegTxCounter, priv->TxCounter); 2352 __func__, RegTxCounter, priv->TxCounter);
@@ -2355,7 +2359,7 @@ bool rtl8192_HalTxCheckStuck(struct net_device *dev)
2355 return bStuck; 2359 return bStuck;
2356} 2360}
2357 2361
2358bool rtl8192_GetNmodeSupportBySecCfg(struct net_device *dev) 2362bool rtl92e_get_nmode_support_by_sec(struct net_device *dev)
2359{ 2363{
2360 struct r8192_priv *priv = rtllib_priv(dev); 2364 struct r8192_priv *priv = rtllib_priv(dev);
2361 struct rtllib_device *ieee = priv->rtllib; 2365 struct rtllib_device *ieee = priv->rtllib;
@@ -2369,34 +2373,10 @@ bool rtl8192_GetNmodeSupportBySecCfg(struct net_device *dev)
2369 } 2373 }
2370} 2374}
2371 2375
2372bool rtl8192_GetHalfNmodeSupportByAPs(struct net_device *dev) 2376bool rtl92e_is_halfn_supported_by_ap(struct net_device *dev)
2373{ 2377{
2374 bool Reval;
2375 struct r8192_priv *priv = rtllib_priv(dev); 2378 struct r8192_priv *priv = rtllib_priv(dev);
2376 struct rtllib_device *ieee = priv->rtllib; 2379 struct rtllib_device *ieee = priv->rtllib;
2377 2380
2378 if (ieee->bHalfWirelessN24GMode == true) 2381 return ieee->bHalfWirelessN24GMode;
2379 Reval = true;
2380 else
2381 Reval = false;
2382
2383 return Reval;
2384}
2385
2386u8 rtl8192_QueryIsShort(u8 TxHT, u8 TxRate, struct cb_desc *tcb_desc)
2387{
2388 u8 tmp_Short;
2389
2390 tmp_Short = (TxHT == 1) ? ((tcb_desc->bUseShortGI) ? 1 : 0) :
2391 ((tcb_desc->bUseShortPreamble) ? 1 : 0);
2392 if (TxHT == 1 && TxRate != DESC90_RATEMCS15)
2393 tmp_Short = 0;
2394
2395 return tmp_Short;
2396}
2397
2398void ActUpdateChannelAccessSetting(struct net_device *dev,
2399 enum wireless_mode WirelessMode,
2400 struct channel_access_setting *ChnlAccessSetting)
2401{
2402} 2382}
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.h b/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.h
index dbe0e1c87056..6bd6b3a4fcea 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.h
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.h
@@ -27,36 +27,30 @@
27 27
28#include "r8190P_def.h" 28#include "r8190P_def.h"
29 29
30u8 rtl8192_QueryIsShort(u8 TxHT, u8 TxRate, struct cb_desc *tcb_desc); 30bool rtl92e_is_halfn_supported_by_ap(struct net_device *dev);
31bool rtl8192_GetHalfNmodeSupportByAPs(struct net_device *dev); 31bool rtl92e_get_nmode_support_by_sec(struct net_device *dev);
32bool rtl8192_GetNmodeSupportBySecCfg(struct net_device *dev); 32bool rtl92e_is_tx_stuck(struct net_device *dev);
33bool rtl8192_HalTxCheckStuck(struct net_device *dev); 33bool rtl92e_is_rx_stuck(struct net_device *dev);
34bool rtl8192_HalRxCheckStuck(struct net_device *dev); 34void rtl92e_ack_irq(struct net_device *dev, u32 *p_inta, u32 *p_intb);
35void rtl8192_interrupt_recognized(struct net_device *dev, u32 *p_inta, 35void rtl92e_enable_rx(struct net_device *dev);
36 u32 *p_intb); 36void rtl92e_enable_tx(struct net_device *dev);
37void rtl8192_enable_rx(struct net_device *dev); 37void rtl92e_enable_irq(struct net_device *dev);
38void rtl8192_enable_tx(struct net_device *dev); 38void rtl92e_disable_irq(struct net_device *dev);
39void rtl8192_EnableInterrupt(struct net_device *dev); 39void rtl92e_clear_irq(struct net_device *dev);
40void rtl8192_DisableInterrupt(struct net_device *dev); 40void rtl92e_init_variables(struct net_device *dev);
41void rtl8192_ClearInterrupt(struct net_device *dev); 41void rtl92e_start_beacon(struct net_device *dev);
42void rtl8192_InitializeVariables(struct net_device *dev); 42void rtl92e_set_reg(struct net_device *dev, u8 variable, u8 *val);
43void rtl8192e_start_beacon(struct net_device *dev); 43void rtl92e_get_eeprom_size(struct net_device *dev);
44void rtl8192e_SetHwReg(struct net_device *dev, u8 variable, u8 *val); 44bool rtl92e_start_adapter(struct net_device *dev);
45void rtl8192_get_eeprom_size(struct net_device *dev); 45void rtl92e_link_change(struct net_device *dev);
46bool rtl8192_adapter_start(struct net_device *dev); 46void rtl92e_set_monitor_mode(struct net_device *dev, bool bAllowAllDA,
47void rtl8192_link_change(struct net_device *dev); 47 bool WriteIntoReg);
48void rtl8192_AllowAllDestAddr(struct net_device *dev, bool bAllowAllDA, 48void rtl92e_fill_tx_desc(struct net_device *dev, struct tx_desc *pdesc,
49 bool WriteIntoReg); 49 struct cb_desc *cb_desc, struct sk_buff *skb);
50void rtl8192_tx_fill_desc(struct net_device *dev, struct tx_desc *pdesc, 50void rtl92e_fill_tx_cmd_desc(struct net_device *dev, struct tx_desc_cmd *entry,
51 struct cb_desc *cb_desc, 51 struct cb_desc *cb_desc, struct sk_buff *skb);
52 struct sk_buff *skb); 52bool rtl92e_get_rx_stats(struct net_device *dev, struct rtllib_rx_stats *stats,
53void rtl8192_tx_fill_cmd_desc(struct net_device *dev, 53 struct rx_desc *pdesc, struct sk_buff *skb);
54 struct tx_desc_cmd *entry, 54void rtl92e_stop_adapter(struct net_device *dev, bool reset);
55 struct cb_desc *cb_desc, struct sk_buff *skb); 55void rtl92e_update_ratr_table(struct net_device *dev);
56bool rtl8192_rx_query_status_desc(struct net_device *dev,
57 struct rtllib_rx_stats *stats,
58 struct rx_desc *pdesc,
59 struct sk_buff *skb);
60void rtl8192_halt_adapter(struct net_device *dev, bool reset);
61void rtl8192_update_ratr_table(struct net_device *dev);
62#endif 56#endif
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c
index 17d2a1540cc8..5c527c419bc9 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c
@@ -23,7 +23,7 @@
23#include "r8192E_firmware.h" 23#include "r8192E_firmware.h"
24#include <linux/firmware.h> 24#include <linux/firmware.h>
25 25
26void firmware_init_param(struct net_device *dev) 26void rtl92e_init_fw_param(struct net_device *dev)
27{ 27{
28 struct r8192_priv *priv = rtllib_priv(dev); 28 struct r8192_priv *priv = rtllib_priv(dev);
29 struct rt_firmware *pfirmware = priv->pFirmware; 29 struct rt_firmware *pfirmware = priv->pFirmware;
@@ -46,7 +46,7 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
46 struct cb_desc *tcb_desc; 46 struct cb_desc *tcb_desc;
47 u8 bLastIniPkt; 47 u8 bLastIniPkt;
48 48
49 firmware_init_param(dev); 49 rtl92e_init_fw_param(dev);
50 frag_threshold = pfirmware->cmdpacket_frag_thresold; 50 frag_threshold = pfirmware->cmdpacket_frag_thresold;
51 do { 51 do {
52 if ((buffer_len - frag_offset) > frag_threshold) { 52 if ((buffer_len - frag_offset) > frag_threshold) {
@@ -96,7 +96,7 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
96 96
97 } while (frag_offset < buffer_len); 97 } while (frag_offset < buffer_len);
98 98
99 write_nic_byte(dev, TPPoll, TPPoll_CQ); 99 rtl92e_writeb(dev, TPPoll, TPPoll_CQ);
100 100
101 return true; 101 return true;
102} 102}
@@ -109,7 +109,7 @@ static bool CPUcheck_maincodeok_turnonCPU(struct net_device *dev)
109 109
110 timeout = jiffies + msecs_to_jiffies(200); 110 timeout = jiffies + msecs_to_jiffies(200);
111 while (time_before(jiffies, timeout)) { 111 while (time_before(jiffies, timeout)) {
112 CPU_status = read_nic_dword(dev, CPU_GEN); 112 CPU_status = rtl92e_readl(dev, CPU_GEN);
113 if (CPU_status & CPU_GEN_PUT_CODE_OK) 113 if (CPU_status & CPU_GEN_PUT_CODE_OK)
114 break; 114 break;
115 mdelay(2); 115 mdelay(2);
@@ -122,14 +122,14 @@ static bool CPUcheck_maincodeok_turnonCPU(struct net_device *dev)
122 RT_TRACE(COMP_FIRMWARE, "Download Firmware: Put code ok!\n"); 122 RT_TRACE(COMP_FIRMWARE, "Download Firmware: Put code ok!\n");
123 } 123 }
124 124
125 CPU_status = read_nic_dword(dev, CPU_GEN); 125 CPU_status = rtl92e_readl(dev, CPU_GEN);
126 write_nic_byte(dev, CPU_GEN, 126 rtl92e_writeb(dev, CPU_GEN,
127 (u8)((CPU_status|CPU_GEN_PWR_STB_CPU)&0xff)); 127 (u8)((CPU_status|CPU_GEN_PWR_STB_CPU)&0xff));
128 mdelay(1); 128 mdelay(1);
129 129
130 timeout = jiffies + msecs_to_jiffies(200); 130 timeout = jiffies + msecs_to_jiffies(200);
131 while (time_before(jiffies, timeout)) { 131 while (time_before(jiffies, timeout)) {
132 CPU_status = read_nic_dword(dev, CPU_GEN); 132 CPU_status = rtl92e_readl(dev, CPU_GEN);
133 if (CPU_status&CPU_GEN_BOOT_RDY) 133 if (CPU_status&CPU_GEN_BOOT_RDY)
134 break; 134 break;
135 mdelay(2); 135 mdelay(2);
@@ -158,7 +158,7 @@ static bool CPUcheck_firmware_ready(struct net_device *dev)
158 158
159 timeout = jiffies + msecs_to_jiffies(20); 159 timeout = jiffies + msecs_to_jiffies(20);
160 while (time_before(jiffies, timeout)) { 160 while (time_before(jiffies, timeout)) {
161 CPU_status = read_nic_dword(dev, CPU_GEN); 161 CPU_status = rtl92e_readl(dev, CPU_GEN);
162 if (CPU_status&CPU_GEN_FIRM_RDY) 162 if (CPU_status&CPU_GEN_FIRM_RDY)
163 break; 163 break;
164 mdelay(2); 164 mdelay(2);
@@ -223,7 +223,7 @@ static bool firmware_check_ready(struct net_device *dev,
223 return rt_status; 223 return rt_status;
224} 224}
225 225
226bool init_firmware(struct net_device *dev) 226bool rtl92e_init_fw(struct net_device *dev)
227{ 227{
228 struct r8192_priv *priv = rtllib_priv(dev); 228 struct r8192_priv *priv = rtllib_priv(dev);
229 bool rt_status = true; 229 bool rt_status = true;
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.h b/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.h
index d79e54203199..fa760f7ac145 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.h
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.h
@@ -19,8 +19,6 @@
19#ifndef __INC_FIRMWARE_H 19#ifndef __INC_FIRMWARE_H
20#define __INC_FIRMWARE_H 20#define __INC_FIRMWARE_H
21 21
22#define RTL8190_CPU_START_OFFSET 0x80
23
24#define GET_COMMAND_PACKET_FRAG_THRESHOLD(v) (4*(v/4) - 8) 22#define GET_COMMAND_PACKET_FRAG_THRESHOLD(v) (4*(v/4) - 8)
25 23
26#define RTL8192E_BOOT_IMG_FW "RTL8192E/boot.img" 24#define RTL8192E_BOOT_IMG_FW "RTL8192E/boot.img"
@@ -61,7 +59,7 @@ struct rt_firmware {
61 u16 firmware_buf_size[MAX_FW_INIT_STEP]; 59 u16 firmware_buf_size[MAX_FW_INIT_STEP];
62}; 60};
63 61
64bool init_firmware(struct net_device *dev); 62bool rtl92e_init_fw(struct net_device *dev);
65extern void firmware_init_param(struct net_device *dev); 63void rtl92e_init_fw_param(struct net_device *dev);
66 64
67#endif 65#endif
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_hw.h b/drivers/staging/rtl8192e/rtl8192e/r8192E_hw.h
index 43c3fb859d10..c81832dcf181 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_hw.h
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_hw.h
@@ -119,10 +119,10 @@ enum _RTL8192Pci_HW {
119#define EPROM_CMD_NORMAL 0 119#define EPROM_CMD_NORMAL 0
120#define EPROM_CMD_LOAD 1 120#define EPROM_CMD_LOAD 1
121#define EPROM_CMD_PROGRAM 2 121#define EPROM_CMD_PROGRAM 2
122#define EPROM_CS_SHIFT 3 122#define EPROM_CS_BIT 3
123#define EPROM_CK_SHIFT 2 123#define EPROM_CK_BIT 2
124#define EPROM_W_SHIFT 1 124#define EPROM_W_BIT 1
125#define EPROM_R_SHIFT 0 125#define EPROM_R_BIT 0
126 126
127 AFR = 0x010, 127 AFR = 0x010,
128#define AFR_CardBEn (1<<0) 128#define AFR_CardBEn (1<<0)
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c
index fba7654160e8..3a15a0f5b479 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c
@@ -64,7 +64,7 @@ static u32 rtl8192_CalculateBitShift(u32 dwBitMask)
64 return i; 64 return i;
65} 65}
66 66
67u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device *dev, u32 eRFPath) 67u8 rtl92e_is_legal_rf_path(struct net_device *dev, u32 eRFPath)
68{ 68{
69 u8 ret = 1; 69 u8 ret = 1;
70 struct r8192_priv *priv = rtllib_priv(dev); 70 struct r8192_priv *priv = rtllib_priv(dev);
@@ -80,27 +80,27 @@ u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device *dev, u32 eRFPath)
80 return ret; 80 return ret;
81} 81}
82 82
83void rtl8192_setBBreg(struct net_device *dev, u32 dwRegAddr, u32 dwBitMask, 83void rtl92e_set_bb_reg(struct net_device *dev, u32 dwRegAddr, u32 dwBitMask,
84 u32 dwData) 84 u32 dwData)
85{ 85{
86 86
87 u32 OriginalValue, BitShift, NewValue; 87 u32 OriginalValue, BitShift, NewValue;
88 88
89 if (dwBitMask != bMaskDWord) { 89 if (dwBitMask != bMaskDWord) {
90 OriginalValue = read_nic_dword(dev, dwRegAddr); 90 OriginalValue = rtl92e_readl(dev, dwRegAddr);
91 BitShift = rtl8192_CalculateBitShift(dwBitMask); 91 BitShift = rtl8192_CalculateBitShift(dwBitMask);
92 NewValue = (((OriginalValue) & (~dwBitMask)) | 92 NewValue = (((OriginalValue) & (~dwBitMask)) |
93 (dwData << BitShift)); 93 (dwData << BitShift));
94 write_nic_dword(dev, dwRegAddr, NewValue); 94 rtl92e_writel(dev, dwRegAddr, NewValue);
95 } else 95 } else
96 write_nic_dword(dev, dwRegAddr, dwData); 96 rtl92e_writel(dev, dwRegAddr, dwData);
97} 97}
98 98
99u32 rtl8192_QueryBBReg(struct net_device *dev, u32 dwRegAddr, u32 dwBitMask) 99u32 rtl92e_get_bb_reg(struct net_device *dev, u32 dwRegAddr, u32 dwBitMask)
100{ 100{
101 u32 Ret = 0, OriginalValue, BitShift; 101 u32 Ret = 0, OriginalValue, BitShift;
102 102
103 OriginalValue = read_nic_dword(dev, dwRegAddr); 103 OriginalValue = rtl92e_readl(dev, dwRegAddr);
104 BitShift = rtl8192_CalculateBitShift(dwBitMask); 104 BitShift = rtl8192_CalculateBitShift(dwBitMask);
105 Ret = (OriginalValue & dwBitMask) >> BitShift; 105 Ret = (OriginalValue & dwBitMask) >> BitShift;
106 106
@@ -117,19 +117,19 @@ static u32 rtl8192_phy_RFSerialRead(struct net_device *dev,
117 Offset &= 0x3f; 117 Offset &= 0x3f;
118 118
119 if (priv->rf_chip == RF_8256) { 119 if (priv->rf_chip == RF_8256) {
120 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0x0); 120 rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter4, 0xf00, 0x0);
121 if (Offset >= 31) { 121 if (Offset >= 31) {
122 priv->RfReg0Value[eRFPath] |= 0x140; 122 priv->RfReg0Value[eRFPath] |= 0x140;
123 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, 123 rtl92e_set_bb_reg(dev, pPhyReg->rf3wireOffset,
124 bMaskDWord, 124 bMaskDWord,
125 (priv->RfReg0Value[eRFPath]<<16)); 125 (priv->RfReg0Value[eRFPath]<<16));
126 NewOffset = Offset - 30; 126 NewOffset = Offset - 30;
127 } else if (Offset >= 16) { 127 } else if (Offset >= 16) {
128 priv->RfReg0Value[eRFPath] |= 0x100; 128 priv->RfReg0Value[eRFPath] |= 0x100;
129 priv->RfReg0Value[eRFPath] &= (~0x40); 129 priv->RfReg0Value[eRFPath] &= (~0x40);
130 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, 130 rtl92e_set_bb_reg(dev, pPhyReg->rf3wireOffset,
131 bMaskDWord, 131 bMaskDWord,
132 (priv->RfReg0Value[eRFPath]<<16)); 132 (priv->RfReg0Value[eRFPath]<<16));
133 133
134 NewOffset = Offset - 15; 134 NewOffset = Offset - 15;
135 } else 135 } else
@@ -139,23 +139,23 @@ static u32 rtl8192_phy_RFSerialRead(struct net_device *dev,
139 "check RF type here, need to be 8256\n"); 139 "check RF type here, need to be 8256\n");
140 NewOffset = Offset; 140 NewOffset = Offset;
141 } 141 }
142 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadAddress, 142 rtl92e_set_bb_reg(dev, pPhyReg->rfHSSIPara2, bLSSIReadAddress,
143 NewOffset); 143 NewOffset);
144 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x0); 144 rtl92e_set_bb_reg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x0);
145 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x1); 145 rtl92e_set_bb_reg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x1);
146 146
147 mdelay(1); 147 mdelay(1);
148 148
149 ret = rtl8192_QueryBBReg(dev, pPhyReg->rfLSSIReadBack, 149 ret = rtl92e_get_bb_reg(dev, pPhyReg->rfLSSIReadBack,
150 bLSSIReadBackData); 150 bLSSIReadBackData);
151 151
152 if (priv->rf_chip == RF_8256) { 152 if (priv->rf_chip == RF_8256) {
153 priv->RfReg0Value[eRFPath] &= 0xebf; 153 priv->RfReg0Value[eRFPath] &= 0xebf;
154 154
155 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, 155 rtl92e_set_bb_reg(dev, pPhyReg->rf3wireOffset, bMaskDWord,
156 (priv->RfReg0Value[eRFPath] << 16)); 156 (priv->RfReg0Value[eRFPath] << 16));
157 157
158 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300, 0x3); 158 rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter4, 0x300, 0x3);
159 } 159 }
160 160
161 161
@@ -173,20 +173,20 @@ static void rtl8192_phy_RFSerialWrite(struct net_device *dev,
173 173
174 Offset &= 0x3f; 174 Offset &= 0x3f;
175 if (priv->rf_chip == RF_8256) { 175 if (priv->rf_chip == RF_8256) {
176 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00, 0x0); 176 rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter4, 0xf00, 0x0);
177 177
178 if (Offset >= 31) { 178 if (Offset >= 31) {
179 priv->RfReg0Value[eRFPath] |= 0x140; 179 priv->RfReg0Value[eRFPath] |= 0x140;
180 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, 180 rtl92e_set_bb_reg(dev, pPhyReg->rf3wireOffset,
181 bMaskDWord, 181 bMaskDWord,
182 (priv->RfReg0Value[eRFPath] << 16)); 182 (priv->RfReg0Value[eRFPath] << 16));
183 NewOffset = Offset - 30; 183 NewOffset = Offset - 30;
184 } else if (Offset >= 16) { 184 } else if (Offset >= 16) {
185 priv->RfReg0Value[eRFPath] |= 0x100; 185 priv->RfReg0Value[eRFPath] |= 0x100;
186 priv->RfReg0Value[eRFPath] &= (~0x40); 186 priv->RfReg0Value[eRFPath] &= (~0x40);
187 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, 187 rtl92e_set_bb_reg(dev, pPhyReg->rf3wireOffset,
188 bMaskDWord, 188 bMaskDWord,
189 (priv->RfReg0Value[eRFPath] << 16)); 189 (priv->RfReg0Value[eRFPath] << 16));
190 NewOffset = Offset - 15; 190 NewOffset = Offset - 15;
191 } else 191 } else
192 NewOffset = Offset; 192 NewOffset = Offset;
@@ -198,7 +198,7 @@ static void rtl8192_phy_RFSerialWrite(struct net_device *dev,
198 198
199 DataAndAddr = (Data<<16) | (NewOffset&0x3f); 199 DataAndAddr = (Data<<16) | (NewOffset&0x3f);
200 200
201 rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, DataAndAddr); 201 rtl92e_set_bb_reg(dev, pPhyReg->rf3wireOffset, bMaskDWord, DataAndAddr);
202 202
203 if (Offset == 0x0) 203 if (Offset == 0x0)
204 priv->RfReg0Value[eRFPath] = Data; 204 priv->RfReg0Value[eRFPath] = Data;
@@ -206,23 +206,21 @@ static void rtl8192_phy_RFSerialWrite(struct net_device *dev,
206 if (priv->rf_chip == RF_8256) { 206 if (priv->rf_chip == RF_8256) {
207 if (Offset != 0) { 207 if (Offset != 0) {
208 priv->RfReg0Value[eRFPath] &= 0xebf; 208 priv->RfReg0Value[eRFPath] &= 0xebf;
209 rtl8192_setBBreg( 209 rtl92e_set_bb_reg(dev, pPhyReg->rf3wireOffset,
210 dev, 210 bMaskDWord,
211 pPhyReg->rf3wireOffset, 211 (priv->RfReg0Value[eRFPath] << 16));
212 bMaskDWord,
213 (priv->RfReg0Value[eRFPath] << 16));
214 } 212 }
215 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300, 0x3); 213 rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter4, 0x300, 0x3);
216 } 214 }
217} 215}
218 216
219void rtl8192_phy_SetRFReg(struct net_device *dev, enum rf90_radio_path eRFPath, 217void rtl92e_set_rf_reg(struct net_device *dev, enum rf90_radio_path eRFPath,
220 u32 RegAddr, u32 BitMask, u32 Data) 218 u32 RegAddr, u32 BitMask, u32 Data)
221{ 219{
222 struct r8192_priv *priv = rtllib_priv(dev); 220 struct r8192_priv *priv = rtllib_priv(dev);
223 u32 Original_Value, BitShift, New_Value; 221 u32 Original_Value, BitShift, New_Value;
224 222
225 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath)) 223 if (!rtl92e_is_legal_rf_path(dev, eRFPath))
226 return; 224 return;
227 if (priv->rtllib->eRFPowerState != eRfOn && !priv->being_init_adapter) 225 if (priv->rtllib->eRFPowerState != eRfOn && !priv->being_init_adapter)
228 return; 226 return;
@@ -256,13 +254,13 @@ void rtl8192_phy_SetRFReg(struct net_device *dev, enum rf90_radio_path eRFPath,
256 } 254 }
257} 255}
258 256
259u32 rtl8192_phy_QueryRFReg(struct net_device *dev, enum rf90_radio_path eRFPath, 257u32 rtl92e_get_rf_reg(struct net_device *dev, enum rf90_radio_path eRFPath,
260 u32 RegAddr, u32 BitMask) 258 u32 RegAddr, u32 BitMask)
261{ 259{
262 u32 Original_Value, Readback_Value, BitShift; 260 u32 Original_Value, Readback_Value, BitShift;
263 struct r8192_priv *priv = rtllib_priv(dev); 261 struct r8192_priv *priv = rtllib_priv(dev);
264 262
265 if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath)) 263 if (!rtl92e_is_legal_rf_path(dev, eRFPath))
266 return 0; 264 return 0;
267 if (priv->rtllib->eRFPowerState != eRfOn && !priv->being_init_adapter) 265 if (priv->rtllib->eRFPowerState != eRfOn && !priv->being_init_adapter)
268 return 0; 266 return 0;
@@ -289,20 +287,20 @@ static u32 phy_FwRFSerialRead(struct net_device *dev,
289 Data |= ((Offset & 0xFF) << 12); 287 Data |= ((Offset & 0xFF) << 12);
290 Data |= ((eRFPath & 0x3) << 20); 288 Data |= ((eRFPath & 0x3) << 20);
291 Data |= 0x80000000; 289 Data |= 0x80000000;
292 while (read_nic_dword(dev, QPNR)&0x80000000) { 290 while (rtl92e_readl(dev, QPNR) & 0x80000000) {
293 if (time++ < 100) 291 if (time++ < 100)
294 udelay(10); 292 udelay(10);
295 else 293 else
296 break; 294 break;
297 } 295 }
298 write_nic_dword(dev, QPNR, Data); 296 rtl92e_writel(dev, QPNR, Data);
299 while (read_nic_dword(dev, QPNR) & 0x80000000) { 297 while (rtl92e_readl(dev, QPNR) & 0x80000000) {
300 if (time++ < 100) 298 if (time++ < 100)
301 udelay(10); 299 udelay(10);
302 else 300 else
303 return 0; 301 return 0;
304 } 302 }
305 return read_nic_dword(dev, RF_DATA); 303 return rtl92e_readl(dev, RF_DATA);
306 304
307} 305}
308 306
@@ -317,18 +315,18 @@ static void phy_FwRFSerialWrite(struct net_device *dev,
317 Data |= 0x400000; 315 Data |= 0x400000;
318 Data |= 0x80000000; 316 Data |= 0x80000000;
319 317
320 while (read_nic_dword(dev, QPNR) & 0x80000000) { 318 while (rtl92e_readl(dev, QPNR) & 0x80000000) {
321 if (time++ < 100) 319 if (time++ < 100)
322 udelay(10); 320 udelay(10);
323 else 321 else
324 break; 322 break;
325 } 323 }
326 write_nic_dword(dev, QPNR, Data); 324 rtl92e_writel(dev, QPNR, Data);
327 325
328} 326}
329 327
330 328
331void rtl8192_phy_configmac(struct net_device *dev) 329void rtl92e_config_mac(struct net_device *dev)
332{ 330{
333 u32 dwArrayLen = 0, i = 0; 331 u32 dwArrayLen = 0, i = 0;
334 u32 *pdwArray = NULL; 332 u32 *pdwArray = NULL;
@@ -350,14 +348,14 @@ void rtl8192_phy_configmac(struct net_device *dev)
350 pdwArray[i], pdwArray[i+1], pdwArray[i+2]); 348 pdwArray[i], pdwArray[i+1], pdwArray[i+2]);
351 if (pdwArray[i] == 0x318) 349 if (pdwArray[i] == 0x318)
352 pdwArray[i+2] = 0x00000800; 350 pdwArray[i+2] = 0x00000800;
353 rtl8192_setBBreg(dev, pdwArray[i], pdwArray[i+1], 351 rtl92e_set_bb_reg(dev, pdwArray[i], pdwArray[i+1],
354 pdwArray[i+2]); 352 pdwArray[i+2]);
355 } 353 }
356 return; 354 return;
357 355
358} 356}
359 357
360void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType) 358static void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType)
361{ 359{
362 int i; 360 int i;
363 u32 *Rtl819XPHY_REGArray_Table = NULL; 361 u32 *Rtl819XPHY_REGArray_Table = NULL;
@@ -377,9 +375,9 @@ void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType)
377 375
378 if (ConfigType == BaseBand_Config_PHY_REG) { 376 if (ConfigType == BaseBand_Config_PHY_REG) {
379 for (i = 0; i < PHY_REGArrayLen; i += 2) { 377 for (i = 0; i < PHY_REGArrayLen; i += 2) {
380 rtl8192_setBBreg(dev, Rtl819XPHY_REGArray_Table[i], 378 rtl92e_set_bb_reg(dev, Rtl819XPHY_REGArray_Table[i],
381 bMaskDWord, 379 bMaskDWord,
382 Rtl819XPHY_REGArray_Table[i+1]); 380 Rtl819XPHY_REGArray_Table[i+1]);
383 RT_TRACE(COMP_DBG, 381 RT_TRACE(COMP_DBG,
384 "i: %x, The Rtl819xUsbPHY_REGArray[0] is %x Rtl819xUsbPHY_REGArray[1] is %x\n", 382 "i: %x, The Rtl819xUsbPHY_REGArray[0] is %x Rtl819xUsbPHY_REGArray[1] is %x\n",
385 i, Rtl819XPHY_REGArray_Table[i], 383 i, Rtl819XPHY_REGArray_Table[i],
@@ -387,9 +385,9 @@ void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType)
387 } 385 }
388 } else if (ConfigType == BaseBand_Config_AGC_TAB) { 386 } else if (ConfigType == BaseBand_Config_AGC_TAB) {
389 for (i = 0; i < AGCTAB_ArrayLen; i += 2) { 387 for (i = 0; i < AGCTAB_ArrayLen; i += 2) {
390 rtl8192_setBBreg(dev, Rtl819XAGCTAB_Array_Table[i], 388 rtl92e_set_bb_reg(dev, Rtl819XAGCTAB_Array_Table[i],
391 bMaskDWord, 389 bMaskDWord,
392 Rtl819XAGCTAB_Array_Table[i+1]); 390 Rtl819XAGCTAB_Array_Table[i+1]);
393 RT_TRACE(COMP_DBG, 391 RT_TRACE(COMP_DBG,
394 "i:%x, The rtl819XAGCTAB_Array[0] is %x rtl819XAGCTAB_Array[1] is %x\n", 392 "i:%x, The rtl819XAGCTAB_Array[0] is %x rtl819XAGCTAB_Array[1] is %x\n",
395 i, Rtl819XAGCTAB_Array_Table[i], 393 i, Rtl819XAGCTAB_Array_Table[i],
@@ -489,9 +487,8 @@ static void rtl8192_InitBBRFRegDef(struct net_device *dev)
489 487
490} 488}
491 489
492bool rtl8192_phy_checkBBAndRF(struct net_device *dev, 490bool rtl92e_check_bb_and_rf(struct net_device *dev, enum hw90_block CheckBlock,
493 enum hw90_block CheckBlock, 491 enum rf90_radio_path eRFPath)
494 enum rf90_radio_path eRFPath)
495{ 492{
496 bool ret = true; 493 bool ret = true;
497 u32 i, CheckTimes = 4, dwRegRead = 0; 494 u32 i, CheckTimes = 4, dwRegRead = 0;
@@ -515,20 +512,20 @@ bool rtl8192_phy_checkBBAndRF(struct net_device *dev,
515 switch (CheckBlock) { 512 switch (CheckBlock) {
516 case HW90_BLOCK_PHY0: 513 case HW90_BLOCK_PHY0:
517 case HW90_BLOCK_PHY1: 514 case HW90_BLOCK_PHY1:
518 write_nic_dword(dev, WriteAddr[CheckBlock], 515 rtl92e_writel(dev, WriteAddr[CheckBlock],
519 WriteData[i]); 516 WriteData[i]);
520 dwRegRead = read_nic_dword(dev, WriteAddr[CheckBlock]); 517 dwRegRead = rtl92e_readl(dev, WriteAddr[CheckBlock]);
521 break; 518 break;
522 519
523 case HW90_BLOCK_RF: 520 case HW90_BLOCK_RF:
524 WriteData[i] &= 0xfff; 521 WriteData[i] &= 0xfff;
525 rtl8192_phy_SetRFReg(dev, eRFPath, 522 rtl92e_set_rf_reg(dev, eRFPath,
526 WriteAddr[HW90_BLOCK_RF], 523 WriteAddr[HW90_BLOCK_RF],
527 bMask12Bits, WriteData[i]); 524 bMask12Bits, WriteData[i]);
528 mdelay(10); 525 mdelay(10);
529 dwRegRead = rtl8192_phy_QueryRFReg(dev, eRFPath, 526 dwRegRead = rtl92e_get_rf_reg(dev, eRFPath,
530 WriteAddr[HW90_BLOCK_RF], 527 WriteAddr[HW90_BLOCK_RF],
531 bMaskDWord); 528 bMaskDWord);
532 mdelay(10); 529 mdelay(10);
533 break; 530 break;
534 531
@@ -555,29 +552,29 @@ static bool rtl8192_BB_Config_ParaFile(struct net_device *dev)
555 u8 bRegValue = 0, eCheckItem = 0; 552 u8 bRegValue = 0, eCheckItem = 0;
556 u32 dwRegValue = 0; 553 u32 dwRegValue = 0;
557 554
558 bRegValue = read_nic_byte(dev, BB_GLOBAL_RESET); 555 bRegValue = rtl92e_readb(dev, BB_GLOBAL_RESET);
559 write_nic_byte(dev, BB_GLOBAL_RESET, (bRegValue|BB_GLOBAL_RESET_BIT)); 556 rtl92e_writeb(dev, BB_GLOBAL_RESET, (bRegValue|BB_GLOBAL_RESET_BIT));
560 557
561 dwRegValue = read_nic_dword(dev, CPU_GEN); 558 dwRegValue = rtl92e_readl(dev, CPU_GEN);
562 write_nic_dword(dev, CPU_GEN, (dwRegValue&(~CPU_GEN_BB_RST))); 559 rtl92e_writel(dev, CPU_GEN, (dwRegValue&(~CPU_GEN_BB_RST)));
563 560
564 for (eCheckItem = (enum hw90_block)HW90_BLOCK_PHY0; 561 for (eCheckItem = (enum hw90_block)HW90_BLOCK_PHY0;
565 eCheckItem <= HW90_BLOCK_PHY1; eCheckItem++) { 562 eCheckItem <= HW90_BLOCK_PHY1; eCheckItem++) {
566 rtStatus = rtl8192_phy_checkBBAndRF(dev, 563 rtStatus = rtl92e_check_bb_and_rf(dev,
567 (enum hw90_block)eCheckItem, 564 (enum hw90_block)eCheckItem,
568 (enum rf90_radio_path)0); 565 (enum rf90_radio_path)0);
569 if (!rtStatus) { 566 if (!rtStatus) {
570 RT_TRACE((COMP_ERR | COMP_PHY), 567 RT_TRACE((COMP_ERR | COMP_PHY),
571 "PHY_RF8256_Config():Check PHY%d Fail!!\n", 568 "rtl92e_config_rf():Check PHY%d Fail!!\n",
572 eCheckItem-1); 569 eCheckItem-1);
573 return rtStatus; 570 return rtStatus;
574 } 571 }
575 } 572 }
576 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn|bOFDMEn, 0x0); 573 rtl92e_set_bb_reg(dev, rFPGA0_RFMOD, bCCKEn|bOFDMEn, 0x0);
577 rtl8192_phyConfigBB(dev, BaseBand_Config_PHY_REG); 574 rtl8192_phyConfigBB(dev, BaseBand_Config_PHY_REG);
578 575
579 dwRegValue = read_nic_dword(dev, CPU_GEN); 576 dwRegValue = rtl92e_readl(dev, CPU_GEN);
580 write_nic_dword(dev, CPU_GEN, (dwRegValue|CPU_GEN_BB_RST)); 577 rtl92e_writel(dev, CPU_GEN, (dwRegValue|CPU_GEN_BB_RST));
581 578
582 rtl8192_phyConfigBB(dev, BaseBand_Config_AGC_TAB); 579 rtl8192_phyConfigBB(dev, BaseBand_Config_AGC_TAB);
583 580
@@ -588,57 +585,57 @@ static bool rtl8192_BB_Config_ParaFile(struct net_device *dev)
588 priv->AntennaTxPwDiff[0]); 585 priv->AntennaTxPwDiff[0]);
589 else 586 else
590 dwRegValue = 0x0; 587 dwRegValue = 0x0;
591 rtl8192_setBBreg(dev, rFPGA0_TxGainStage, 588 rtl92e_set_bb_reg(dev, rFPGA0_TxGainStage,
592 (bXBTxAGC|bXCTxAGC|bXDTxAGC), dwRegValue); 589 (bXBTxAGC|bXCTxAGC|bXDTxAGC), dwRegValue);
593 590
594 591
595 dwRegValue = priv->CrystalCap; 592 dwRegValue = priv->CrystalCap;
596 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, bXtalCap92x, 593 rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter1, bXtalCap92x,
597 dwRegValue); 594 dwRegValue);
598 } 595 }
599 596
600 return rtStatus; 597 return rtStatus;
601} 598}
602bool rtl8192_BBConfig(struct net_device *dev) 599bool rtl92e_config_bb(struct net_device *dev)
603{ 600{
604 rtl8192_InitBBRFRegDef(dev); 601 rtl8192_InitBBRFRegDef(dev);
605 return rtl8192_BB_Config_ParaFile(dev); 602 return rtl8192_BB_Config_ParaFile(dev);
606} 603}
607 604
608void rtl8192_phy_getTxPower(struct net_device *dev) 605void rtl92e_get_tx_power(struct net_device *dev)
609{ 606{
610 struct r8192_priv *priv = rtllib_priv(dev); 607 struct r8192_priv *priv = rtllib_priv(dev);
611 608
612 priv->MCSTxPowerLevelOriginalOffset[0] = 609 priv->MCSTxPowerLevelOriginalOffset[0] =
613 read_nic_dword(dev, rTxAGC_Rate18_06); 610 rtl92e_readl(dev, rTxAGC_Rate18_06);
614 priv->MCSTxPowerLevelOriginalOffset[1] = 611 priv->MCSTxPowerLevelOriginalOffset[1] =
615 read_nic_dword(dev, rTxAGC_Rate54_24); 612 rtl92e_readl(dev, rTxAGC_Rate54_24);
616 priv->MCSTxPowerLevelOriginalOffset[2] = 613 priv->MCSTxPowerLevelOriginalOffset[2] =
617 read_nic_dword(dev, rTxAGC_Mcs03_Mcs00); 614 rtl92e_readl(dev, rTxAGC_Mcs03_Mcs00);
618 priv->MCSTxPowerLevelOriginalOffset[3] = 615 priv->MCSTxPowerLevelOriginalOffset[3] =
619 read_nic_dword(dev, rTxAGC_Mcs07_Mcs04); 616 rtl92e_readl(dev, rTxAGC_Mcs07_Mcs04);
620 priv->MCSTxPowerLevelOriginalOffset[4] = 617 priv->MCSTxPowerLevelOriginalOffset[4] =
621 read_nic_dword(dev, rTxAGC_Mcs11_Mcs08); 618 rtl92e_readl(dev, rTxAGC_Mcs11_Mcs08);
622 priv->MCSTxPowerLevelOriginalOffset[5] = 619 priv->MCSTxPowerLevelOriginalOffset[5] =
623 read_nic_dword(dev, rTxAGC_Mcs15_Mcs12); 620 rtl92e_readl(dev, rTxAGC_Mcs15_Mcs12);
624 621
625 priv->DefaultInitialGain[0] = read_nic_byte(dev, rOFDM0_XAAGCCore1); 622 priv->DefaultInitialGain[0] = rtl92e_readb(dev, rOFDM0_XAAGCCore1);
626 priv->DefaultInitialGain[1] = read_nic_byte(dev, rOFDM0_XBAGCCore1); 623 priv->DefaultInitialGain[1] = rtl92e_readb(dev, rOFDM0_XBAGCCore1);
627 priv->DefaultInitialGain[2] = read_nic_byte(dev, rOFDM0_XCAGCCore1); 624 priv->DefaultInitialGain[2] = rtl92e_readb(dev, rOFDM0_XCAGCCore1);
628 priv->DefaultInitialGain[3] = read_nic_byte(dev, rOFDM0_XDAGCCore1); 625 priv->DefaultInitialGain[3] = rtl92e_readb(dev, rOFDM0_XDAGCCore1);
629 RT_TRACE(COMP_INIT, 626 RT_TRACE(COMP_INIT,
630 "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x)\n", 627 "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x)\n",
631 priv->DefaultInitialGain[0], priv->DefaultInitialGain[1], 628 priv->DefaultInitialGain[0], priv->DefaultInitialGain[1],
632 priv->DefaultInitialGain[2], priv->DefaultInitialGain[3]); 629 priv->DefaultInitialGain[2], priv->DefaultInitialGain[3]);
633 630
634 priv->framesync = read_nic_byte(dev, rOFDM0_RxDetector3); 631 priv->framesync = rtl92e_readb(dev, rOFDM0_RxDetector3);
635 priv->framesyncC34 = read_nic_dword(dev, rOFDM0_RxDetector2); 632 priv->framesyncC34 = rtl92e_readl(dev, rOFDM0_RxDetector2);
636 RT_TRACE(COMP_INIT, "Default framesync (0x%x) = 0x%x\n", 633 RT_TRACE(COMP_INIT, "Default framesync (0x%x) = 0x%x\n",
637 rOFDM0_RxDetector3, priv->framesync); 634 rOFDM0_RxDetector3, priv->framesync);
638 priv->SifsTime = read_nic_word(dev, SIFS); 635 priv->SifsTime = rtl92e_readw(dev, SIFS);
639} 636}
640 637
641void rtl8192_phy_setTxPower(struct net_device *dev, u8 channel) 638void rtl92e_set_tx_power(struct net_device *dev, u8 channel)
642{ 639{
643 struct r8192_priv *priv = rtllib_priv(dev); 640 struct r8192_priv *priv = rtllib_priv(dev);
644 u8 powerlevel = 0, powerlevelOFDM24G = 0; 641 u8 powerlevel = 0, powerlevelOFDM24G = 0;
@@ -671,16 +668,17 @@ void rtl8192_phy_setTxPower(struct net_device *dev, u8 channel)
671 priv->AntennaTxPwDiff[1]<<4 | 668 priv->AntennaTxPwDiff[1]<<4 |
672 priv->AntennaTxPwDiff[0]); 669 priv->AntennaTxPwDiff[0]);
673 670
674 rtl8192_setBBreg(dev, rFPGA0_TxGainStage, 671 rtl92e_set_bb_reg(dev, rFPGA0_TxGainStage,
675 (bXBTxAGC|bXCTxAGC|bXDTxAGC), u4RegValue); 672 (bXBTxAGC|bXCTxAGC|bXDTxAGC),
673 u4RegValue);
676 } 674 }
677 } 675 }
678 switch (priv->rf_chip) { 676 switch (priv->rf_chip) {
679 case RF_8225: 677 case RF_8225:
680 break; 678 break;
681 case RF_8256: 679 case RF_8256:
682 PHY_SetRF8256CCKTxPower(dev, powerlevel); 680 rtl92e_set_cck_tx_power(dev, powerlevel);
683 PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G); 681 rtl92e_set_ofdm_tx_power(dev, powerlevelOFDM24G);
684 break; 682 break;
685 case RF_8258: 683 case RF_8258:
686 break; 684 break;
@@ -690,7 +688,7 @@ void rtl8192_phy_setTxPower(struct net_device *dev, u8 channel)
690 } 688 }
691} 689}
692 690
693bool rtl8192_phy_RFConfig(struct net_device *dev) 691bool rtl92e_config_phy(struct net_device *dev)
694{ 692{
695 struct r8192_priv *priv = rtllib_priv(dev); 693 struct r8192_priv *priv = rtllib_priv(dev);
696 bool rtStatus = true; 694 bool rtStatus = true;
@@ -699,7 +697,7 @@ bool rtl8192_phy_RFConfig(struct net_device *dev)
699 case RF_8225: 697 case RF_8225:
700 break; 698 break;
701 case RF_8256: 699 case RF_8256:
702 rtStatus = PHY_RF8256_Config(dev); 700 rtStatus = rtl92e_config_rf(dev);
703 break; 701 break;
704 702
705 case RF_8258: 703 case RF_8258:
@@ -714,12 +712,7 @@ bool rtl8192_phy_RFConfig(struct net_device *dev)
714 return rtStatus; 712 return rtStatus;
715} 713}
716 714
717void rtl8192_phy_updateInitGain(struct net_device *dev) 715u8 rtl92e_config_rf_path(struct net_device *dev, enum rf90_radio_path eRFPath)
718{
719}
720
721u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device *dev,
722 enum rf90_radio_path eRFPath)
723{ 716{
724 717
725 int i; 718 int i;
@@ -731,10 +724,9 @@ u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device *dev,
731 msleep(100); 724 msleep(100);
732 continue; 725 continue;
733 } 726 }
734 rtl8192_phy_SetRFReg(dev, eRFPath, 727 rtl92e_set_rf_reg(dev, eRFPath, Rtl819XRadioA_Array[i],
735 Rtl819XRadioA_Array[i], 728 bMask12Bits,
736 bMask12Bits, 729 Rtl819XRadioA_Array[i+1]);
737 Rtl819XRadioA_Array[i+1]);
738 730
739 } 731 }
740 break; 732 break;
@@ -744,10 +736,9 @@ u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device *dev,
744 msleep(100); 736 msleep(100);
745 continue; 737 continue;
746 } 738 }
747 rtl8192_phy_SetRFReg(dev, eRFPath, 739 rtl92e_set_rf_reg(dev, eRFPath, Rtl819XRadioB_Array[i],
748 Rtl819XRadioB_Array[i], 740 bMask12Bits,
749 bMask12Bits, 741 Rtl819XRadioB_Array[i+1]);
750 Rtl819XRadioB_Array[i+1]);
751 742
752 } 743 }
753 break; 744 break;
@@ -757,10 +748,9 @@ u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device *dev,
757 msleep(100); 748 msleep(100);
758 continue; 749 continue;
759 } 750 }
760 rtl8192_phy_SetRFReg(dev, eRFPath, 751 rtl92e_set_rf_reg(dev, eRFPath, Rtl819XRadioC_Array[i],
761 Rtl819XRadioC_Array[i], 752 bMask12Bits,
762 bMask12Bits, 753 Rtl819XRadioC_Array[i+1]);
763 Rtl819XRadioC_Array[i+1]);
764 754
765 } 755 }
766 break; 756 break;
@@ -770,9 +760,9 @@ u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device *dev,
770 msleep(100); 760 msleep(100);
771 continue; 761 continue;
772 } 762 }
773 rtl8192_phy_SetRFReg(dev, eRFPath, 763 rtl92e_set_rf_reg(dev, eRFPath, Rtl819XRadioD_Array[i],
774 Rtl819XRadioD_Array[i], bMask12Bits, 764 bMask12Bits,
775 Rtl819XRadioD_Array[i+1]); 765 Rtl819XRadioD_Array[i+1]);
776 766
777 } 767 }
778 break; 768 break;
@@ -794,8 +784,8 @@ static void rtl8192_SetTxPowerLevel(struct net_device *dev, u8 channel)
794 break; 784 break;
795 785
796 case RF_8256: 786 case RF_8256:
797 PHY_SetRF8256CCKTxPower(dev, powerlevel); 787 rtl92e_set_cck_tx_power(dev, powerlevel);
798 PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G); 788 rtl92e_set_ofdm_tx_power(dev, powerlevelOFDM24G);
799 break; 789 break;
800 790
801 case RF_8258: 791 case RF_8258:
@@ -941,21 +931,21 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel,
941 rtl8192_SetTxPowerLevel(dev, channel); 931 rtl8192_SetTxPowerLevel(dev, channel);
942 break; 932 break;
943 case CmdID_WritePortUlong: 933 case CmdID_WritePortUlong:
944 write_nic_dword(dev, CurrentCmd->Para1, 934 rtl92e_writel(dev, CurrentCmd->Para1,
945 CurrentCmd->Para2); 935 CurrentCmd->Para2);
946 break; 936 break;
947 case CmdID_WritePortUshort: 937 case CmdID_WritePortUshort:
948 write_nic_word(dev, CurrentCmd->Para1, 938 rtl92e_writew(dev, CurrentCmd->Para1,
949 (u16)CurrentCmd->Para2); 939 (u16)CurrentCmd->Para2);
950 break; 940 break;
951 case CmdID_WritePortUchar: 941 case CmdID_WritePortUchar:
952 write_nic_byte(dev, CurrentCmd->Para1, 942 rtl92e_writeb(dev, CurrentCmd->Para1,
953 (u8)CurrentCmd->Para2); 943 (u8)CurrentCmd->Para2);
954 break; 944 break;
955 case CmdID_RF_WriteReg: 945 case CmdID_RF_WriteReg:
956 for (eRFPath = 0; eRFPath < 946 for (eRFPath = 0; eRFPath <
957 priv->NumTotalRFPath; eRFPath++) 947 priv->NumTotalRFPath; eRFPath++)
958 rtl8192_phy_SetRFReg(dev, 948 rtl92e_set_rf_reg(dev,
959 (enum rf90_radio_path)eRFPath, 949 (enum rf90_radio_path)eRFPath,
960 CurrentCmd->Para1, bMask12Bits, 950 CurrentCmd->Para1, bMask12Bits,
961 CurrentCmd->Para2<<7); 951 CurrentCmd->Para2<<7);
@@ -986,7 +976,7 @@ static void rtl8192_phy_FinishSwChnlNow(struct net_device *dev, u8 channel)
986 break; 976 break;
987 } 977 }
988} 978}
989void rtl8192_SwChnl_WorkItem(struct net_device *dev) 979static void rtl8192_SwChnl_WorkItem(struct net_device *dev)
990{ 980{
991 981
992 struct r8192_priv *priv = rtllib_priv(dev); 982 struct r8192_priv *priv = rtllib_priv(dev);
@@ -1001,7 +991,7 @@ void rtl8192_SwChnl_WorkItem(struct net_device *dev)
1001 RT_TRACE(COMP_TRACE, "<== SwChnlCallback819xUsbWorkItem()\n"); 991 RT_TRACE(COMP_TRACE, "<== SwChnlCallback819xUsbWorkItem()\n");
1002} 992}
1003 993
1004u8 rtl8192_phy_SwChnl(struct net_device *dev, u8 channel) 994u8 rtl92e_set_channel(struct net_device *dev, u8 channel)
1005{ 995{
1006 struct r8192_priv *priv = rtllib_priv(dev); 996 struct r8192_priv *priv = rtllib_priv(dev);
1007 997
@@ -1082,13 +1072,13 @@ static void CCK_Tx_Power_Track_BW_Switch_TSSI(struct net_device *dev)
1082 if (priv->rtllib->current_network.channel == 14 && 1072 if (priv->rtllib->current_network.channel == 14 &&
1083 !priv->bcck_in_ch14) { 1073 !priv->bcck_in_ch14) {
1084 priv->bcck_in_ch14 = true; 1074 priv->bcck_in_ch14 = true;
1085 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14); 1075 rtl92e_dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1086 } else if (priv->rtllib->current_network.channel != 1076 } else if (priv->rtllib->current_network.channel !=
1087 14 && priv->bcck_in_ch14) { 1077 14 && priv->bcck_in_ch14) {
1088 priv->bcck_in_ch14 = false; 1078 priv->bcck_in_ch14 = false;
1089 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14); 1079 rtl92e_dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1090 } else { 1080 } else {
1091 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14); 1081 rtl92e_dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1092 } 1082 }
1093 break; 1083 break;
1094 1084
@@ -1110,13 +1100,13 @@ static void CCK_Tx_Power_Track_BW_Switch_TSSI(struct net_device *dev)
1110 if (priv->rtllib->current_network.channel == 14 && 1100 if (priv->rtllib->current_network.channel == 14 &&
1111 !priv->bcck_in_ch14) { 1101 !priv->bcck_in_ch14) {
1112 priv->bcck_in_ch14 = true; 1102 priv->bcck_in_ch14 = true;
1113 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14); 1103 rtl92e_dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1114 } else if (priv->rtllib->current_network.channel != 14 1104 } else if (priv->rtllib->current_network.channel != 14
1115 && priv->bcck_in_ch14) { 1105 && priv->bcck_in_ch14) {
1116 priv->bcck_in_ch14 = false; 1106 priv->bcck_in_ch14 = false;
1117 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14); 1107 rtl92e_dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1118 } else { 1108 } else {
1119 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14); 1109 rtl92e_dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1120 } 1110 }
1121 break; 1111 break;
1122 } 1112 }
@@ -1150,7 +1140,7 @@ static void CCK_Tx_Power_Track_BW_Switch_ThermalMeter(struct net_device *dev)
1150 priv->CCK_index); 1140 priv->CCK_index);
1151 break; 1141 break;
1152 } 1142 }
1153 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14); 1143 rtl92e_dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1154} 1144}
1155 1145
1156static void CCK_Tx_Power_Track_BW_Switch(struct net_device *dev) 1146static void CCK_Tx_Power_Track_BW_Switch(struct net_device *dev)
@@ -1163,7 +1153,7 @@ static void CCK_Tx_Power_Track_BW_Switch(struct net_device *dev)
1163 CCK_Tx_Power_Track_BW_Switch_ThermalMeter(dev); 1153 CCK_Tx_Power_Track_BW_Switch_ThermalMeter(dev);
1164} 1154}
1165 1155
1166void rtl8192_SetBWModeWorkItem(struct net_device *dev) 1156static void rtl8192_SetBWModeWorkItem(struct net_device *dev)
1167{ 1157{
1168 1158
1169 struct r8192_priv *priv = rtllib_priv(dev); 1159 struct r8192_priv *priv = rtllib_priv(dev);
@@ -1183,17 +1173,17 @@ void rtl8192_SetBWModeWorkItem(struct net_device *dev)
1183 netdev_err(dev, "%s(): Driver is not initialized\n", __func__); 1173 netdev_err(dev, "%s(): Driver is not initialized\n", __func__);
1184 return; 1174 return;
1185 } 1175 }
1186 regBwOpMode = read_nic_byte(dev, BW_OPMODE); 1176 regBwOpMode = rtl92e_readb(dev, BW_OPMODE);
1187 1177
1188 switch (priv->CurrentChannelBW) { 1178 switch (priv->CurrentChannelBW) {
1189 case HT_CHANNEL_WIDTH_20: 1179 case HT_CHANNEL_WIDTH_20:
1190 regBwOpMode |= BW_OPMODE_20MHZ; 1180 regBwOpMode |= BW_OPMODE_20MHZ;
1191 write_nic_byte(dev, BW_OPMODE, regBwOpMode); 1181 rtl92e_writeb(dev, BW_OPMODE, regBwOpMode);
1192 break; 1182 break;
1193 1183
1194 case HT_CHANNEL_WIDTH_20_40: 1184 case HT_CHANNEL_WIDTH_20_40:
1195 regBwOpMode &= ~BW_OPMODE_20MHZ; 1185 regBwOpMode &= ~BW_OPMODE_20MHZ;
1196 write_nic_byte(dev, BW_OPMODE, regBwOpMode); 1186 rtl92e_writeb(dev, BW_OPMODE, regBwOpMode);
1197 break; 1187 break;
1198 1188
1199 default: 1189 default:
@@ -1204,38 +1194,38 @@ void rtl8192_SetBWModeWorkItem(struct net_device *dev)
1204 1194
1205 switch (priv->CurrentChannelBW) { 1195 switch (priv->CurrentChannelBW) {
1206 case HT_CHANNEL_WIDTH_20: 1196 case HT_CHANNEL_WIDTH_20:
1207 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0); 1197 rtl92e_set_bb_reg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
1208 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0); 1198 rtl92e_set_bb_reg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
1209 1199
1210 if (!priv->btxpower_tracking) { 1200 if (!priv->btxpower_tracking) {
1211 write_nic_dword(dev, rCCK0_TxFilter1, 0x1a1b0000); 1201 rtl92e_writel(dev, rCCK0_TxFilter1, 0x1a1b0000);
1212 write_nic_dword(dev, rCCK0_TxFilter2, 0x090e1317); 1202 rtl92e_writel(dev, rCCK0_TxFilter2, 0x090e1317);
1213 write_nic_dword(dev, rCCK0_DebugPort, 0x00000204); 1203 rtl92e_writel(dev, rCCK0_DebugPort, 0x00000204);
1214 } else { 1204 } else {
1215 CCK_Tx_Power_Track_BW_Switch(dev); 1205 CCK_Tx_Power_Track_BW_Switch(dev);
1216 } 1206 }
1217 1207
1218 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 1); 1208 rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter1, 0x00100000, 1);
1219 1209
1220 break; 1210 break;
1221 case HT_CHANNEL_WIDTH_20_40: 1211 case HT_CHANNEL_WIDTH_20_40:
1222 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1); 1212 rtl92e_set_bb_reg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
1223 rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1); 1213 rtl92e_set_bb_reg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
1224 1214
1225 if (!priv->btxpower_tracking) { 1215 if (!priv->btxpower_tracking) {
1226 write_nic_dword(dev, rCCK0_TxFilter1, 0x35360000); 1216 rtl92e_writel(dev, rCCK0_TxFilter1, 0x35360000);
1227 write_nic_dword(dev, rCCK0_TxFilter2, 0x121c252e); 1217 rtl92e_writel(dev, rCCK0_TxFilter2, 0x121c252e);
1228 write_nic_dword(dev, rCCK0_DebugPort, 0x00000409); 1218 rtl92e_writel(dev, rCCK0_DebugPort, 0x00000409);
1229 } else { 1219 } else {
1230 CCK_Tx_Power_Track_BW_Switch(dev); 1220 CCK_Tx_Power_Track_BW_Switch(dev);
1231 } 1221 }
1232 1222
1233 rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, 1223 rtl92e_set_bb_reg(dev, rCCK0_System, bCCKSideBand,
1234 (priv->nCur40MhzPrimeSC>>1)); 1224 (priv->nCur40MhzPrimeSC>>1));
1235 rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, 1225 rtl92e_set_bb_reg(dev, rOFDM1_LSTF, 0xC00,
1236 priv->nCur40MhzPrimeSC); 1226 priv->nCur40MhzPrimeSC);
1237 1227
1238 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 0); 1228 rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter1, 0x00100000, 0);
1239 break; 1229 break;
1240 default: 1230 default:
1241 netdev_err(dev, "%s(): unknown Bandwidth: %#X\n", __func__, 1231 netdev_err(dev, "%s(): unknown Bandwidth: %#X\n", __func__,
@@ -1249,7 +1239,7 @@ void rtl8192_SetBWModeWorkItem(struct net_device *dev)
1249 break; 1239 break;
1250 1240
1251 case RF_8256: 1241 case RF_8256:
1252 PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW); 1242 rtl92e_set_bandwidth(dev, priv->CurrentChannelBW);
1253 break; 1243 break;
1254 1244
1255 case RF_8258: 1245 case RF_8258:
@@ -1270,8 +1260,8 @@ void rtl8192_SetBWModeWorkItem(struct net_device *dev)
1270 RT_TRACE(COMP_SWBW, "<==SetBWMode819xUsb()"); 1260 RT_TRACE(COMP_SWBW, "<==SetBWMode819xUsb()");
1271} 1261}
1272 1262
1273void rtl8192_SetBWMode(struct net_device *dev, enum ht_channel_width Bandwidth, 1263void rtl92e_set_bw_mode(struct net_device *dev, enum ht_channel_width Bandwidth,
1274 enum ht_extchnl_offset Offset) 1264 enum ht_extchnl_offset Offset)
1275{ 1265{
1276 struct r8192_priv *priv = rtllib_priv(dev); 1266 struct r8192_priv *priv = rtllib_priv(dev);
1277 1267
@@ -1295,7 +1285,7 @@ void rtl8192_SetBWMode(struct net_device *dev, enum ht_channel_width Bandwidth,
1295 1285
1296} 1286}
1297 1287
1298void InitialGain819xPci(struct net_device *dev, u8 Operation) 1288void rtl92e_init_gain(struct net_device *dev, u8 Operation)
1299{ 1289{
1300#define SCAN_RX_INITIAL_GAIN 0x17 1290#define SCAN_RX_INITIAL_GAIN 0x17
1301#define POWER_DETECTION_TH 0x08 1291#define POWER_DETECTION_TH 0x08
@@ -1312,21 +1302,21 @@ void InitialGain819xPci(struct net_device *dev, u8 Operation)
1312 BitMask = bMaskByte0; 1302 BitMask = bMaskByte0;
1313 if (dm_digtable.dig_algorithm == 1303 if (dm_digtable.dig_algorithm ==
1314 DIG_ALGO_BY_FALSE_ALARM) 1304 DIG_ALGO_BY_FALSE_ALARM)
1315 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); 1305 rtl92e_set_bb_reg(dev, UFWP, bMaskByte1, 0x8);
1316 priv->initgain_backup.xaagccore1 = 1306 priv->initgain_backup.xaagccore1 =
1317 (u8)rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, 1307 (u8)rtl92e_get_bb_reg(dev, rOFDM0_XAAGCCore1,
1318 BitMask); 1308 BitMask);
1319 priv->initgain_backup.xbagccore1 = 1309 priv->initgain_backup.xbagccore1 =
1320 (u8)rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, 1310 (u8)rtl92e_get_bb_reg(dev, rOFDM0_XBAGCCore1,
1321 BitMask); 1311 BitMask);
1322 priv->initgain_backup.xcagccore1 = 1312 priv->initgain_backup.xcagccore1 =
1323 (u8)rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, 1313 (u8)rtl92e_get_bb_reg(dev, rOFDM0_XCAGCCore1,
1324 BitMask); 1314 BitMask);
1325 priv->initgain_backup.xdagccore1 = 1315 priv->initgain_backup.xdagccore1 =
1326 (u8)rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, 1316 (u8)rtl92e_get_bb_reg(dev, rOFDM0_XDAGCCore1,
1327 BitMask); 1317 BitMask);
1328 BitMask = bMaskByte2; 1318 BitMask = bMaskByte2;
1329 priv->initgain_backup.cca = (u8)rtl8192_QueryBBReg(dev, 1319 priv->initgain_backup.cca = (u8)rtl92e_get_bb_reg(dev,
1330 rCCK0_CCA, BitMask); 1320 rCCK0_CCA, BitMask);
1331 1321
1332 RT_TRACE(COMP_SCAN, 1322 RT_TRACE(COMP_SCAN,
@@ -1347,13 +1337,13 @@ void InitialGain819xPci(struct net_device *dev, u8 Operation)
1347 1337
1348 RT_TRACE(COMP_SCAN, "Write scan initial gain = 0x%x\n", 1338 RT_TRACE(COMP_SCAN, "Write scan initial gain = 0x%x\n",
1349 initial_gain); 1339 initial_gain);
1350 write_nic_byte(dev, rOFDM0_XAAGCCore1, initial_gain); 1340 rtl92e_writeb(dev, rOFDM0_XAAGCCore1, initial_gain);
1351 write_nic_byte(dev, rOFDM0_XBAGCCore1, initial_gain); 1341 rtl92e_writeb(dev, rOFDM0_XBAGCCore1, initial_gain);
1352 write_nic_byte(dev, rOFDM0_XCAGCCore1, initial_gain); 1342 rtl92e_writeb(dev, rOFDM0_XCAGCCore1, initial_gain);
1353 write_nic_byte(dev, rOFDM0_XDAGCCore1, initial_gain); 1343 rtl92e_writeb(dev, rOFDM0_XDAGCCore1, initial_gain);
1354 RT_TRACE(COMP_SCAN, "Write scan 0xa0a = 0x%x\n", 1344 RT_TRACE(COMP_SCAN, "Write scan 0xa0a = 0x%x\n",
1355 POWER_DETECTION_TH); 1345 POWER_DETECTION_TH);
1356 write_nic_byte(dev, 0xa0a, POWER_DETECTION_TH); 1346 rtl92e_writeb(dev, 0xa0a, POWER_DETECTION_TH);
1357 break; 1347 break;
1358 case IG_Restore: 1348 case IG_Restore:
1359 RT_TRACE(COMP_SCAN, 1349 RT_TRACE(COMP_SCAN,
@@ -1361,18 +1351,18 @@ void InitialGain819xPci(struct net_device *dev, u8 Operation)
1361 BitMask = 0x7f; 1351 BitMask = 0x7f;
1362 if (dm_digtable.dig_algorithm == 1352 if (dm_digtable.dig_algorithm ==
1363 DIG_ALGO_BY_FALSE_ALARM) 1353 DIG_ALGO_BY_FALSE_ALARM)
1364 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); 1354 rtl92e_set_bb_reg(dev, UFWP, bMaskByte1, 0x8);
1365 1355
1366 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, BitMask, 1356 rtl92e_set_bb_reg(dev, rOFDM0_XAAGCCore1, BitMask,
1367 (u32)priv->initgain_backup.xaagccore1); 1357 (u32)priv->initgain_backup.xaagccore1);
1368 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, BitMask, 1358 rtl92e_set_bb_reg(dev, rOFDM0_XBAGCCore1, BitMask,
1369 (u32)priv->initgain_backup.xbagccore1); 1359 (u32)priv->initgain_backup.xbagccore1);
1370 rtl8192_setBBreg(dev, rOFDM0_XCAGCCore1, BitMask, 1360 rtl92e_set_bb_reg(dev, rOFDM0_XCAGCCore1, BitMask,
1371 (u32)priv->initgain_backup.xcagccore1); 1361 (u32)priv->initgain_backup.xcagccore1);
1372 rtl8192_setBBreg(dev, rOFDM0_XDAGCCore1, BitMask, 1362 rtl92e_set_bb_reg(dev, rOFDM0_XDAGCCore1, BitMask,
1373 (u32)priv->initgain_backup.xdagccore1); 1363 (u32)priv->initgain_backup.xdagccore1);
1374 BitMask = bMaskByte2; 1364 BitMask = bMaskByte2;
1375 rtl8192_setBBreg(dev, rCCK0_CCA, BitMask, 1365 rtl92e_set_bb_reg(dev, rCCK0_CCA, BitMask,
1376 (u32)priv->initgain_backup.cca); 1366 (u32)priv->initgain_backup.cca);
1377 1367
1378 RT_TRACE(COMP_SCAN, 1368 RT_TRACE(COMP_SCAN,
@@ -1391,12 +1381,12 @@ void InitialGain819xPci(struct net_device *dev, u8 Operation)
1391 "Scan BBInitialGainRestore 0xa0a is %x\n", 1381 "Scan BBInitialGainRestore 0xa0a is %x\n",
1392 priv->initgain_backup.cca); 1382 priv->initgain_backup.cca);
1393 1383
1394 rtl8192_phy_setTxPower(dev, 1384 rtl92e_set_tx_power(dev,
1395 priv->rtllib->current_network.channel); 1385 priv->rtllib->current_network.channel);
1396 1386
1397 if (dm_digtable.dig_algorithm == 1387 if (dm_digtable.dig_algorithm ==
1398 DIG_ALGO_BY_FALSE_ALARM) 1388 DIG_ALGO_BY_FALSE_ALARM)
1399 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); 1389 rtl92e_set_bb_reg(dev, UFWP, bMaskByte1, 0x1);
1400 break; 1390 break;
1401 default: 1391 default:
1402 RT_TRACE(COMP_SCAN, "Unknown IG Operation.\n"); 1392 RT_TRACE(COMP_SCAN, "Unknown IG Operation.\n");
@@ -1405,17 +1395,17 @@ void InitialGain819xPci(struct net_device *dev, u8 Operation)
1405 } 1395 }
1406} 1396}
1407 1397
1408void PHY_SetRtl8192eRfOff(struct net_device *dev) 1398void rtl92e_set_rf_off(struct net_device *dev)
1409{ 1399{
1410 1400
1411 rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT4, 0x0); 1401 rtl92e_set_bb_reg(dev, rFPGA0_XA_RFInterfaceOE, BIT4, 0x0);
1412 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300, 0x0); 1402 rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter4, 0x300, 0x0);
1413 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x18, 0x0); 1403 rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter1, 0x18, 0x0);
1414 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0xf, 0x0); 1404 rtl92e_set_bb_reg(dev, rOFDM0_TRxPathEnable, 0xf, 0x0);
1415 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x0); 1405 rtl92e_set_bb_reg(dev, rOFDM1_TRxPathEnable, 0xf, 0x0);
1416 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60, 0x0); 1406 rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter1, 0x60, 0x0);
1417 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x4, 0x0); 1407 rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter1, 0x4, 0x0);
1418 write_nic_byte(dev, ANAPAR_FOR_8192PciE, 0x07); 1408 rtl92e_writeb(dev, ANAPAR_FOR_8192PciE, 0x07);
1419 1409
1420} 1410}
1421 1411
@@ -1447,7 +1437,7 @@ static bool SetRFPowerState8190(struct net_device *dev,
1447 do { 1437 do {
1448 InitilizeCount--; 1438 InitilizeCount--;
1449 priv->RegRfOff = false; 1439 priv->RegRfOff = false;
1450 rtstatus = NicIFEnableNIC(dev); 1440 rtstatus = rtl92e_enable_nic(dev);
1451 } while (!rtstatus && (InitilizeCount > 0)); 1441 } while (!rtstatus && (InitilizeCount > 0));
1452 1442
1453 if (!rtstatus) { 1443 if (!rtstatus) {
@@ -1461,24 +1451,24 @@ static bool SetRFPowerState8190(struct net_device *dev,
1461 RT_CLEAR_PS_LEVEL(pPSC, 1451 RT_CLEAR_PS_LEVEL(pPSC,
1462 RT_RF_OFF_LEVL_HALT_NIC); 1452 RT_RF_OFF_LEVL_HALT_NIC);
1463 } else { 1453 } else {
1464 write_nic_byte(dev, ANAPAR, 0x37); 1454 rtl92e_writeb(dev, ANAPAR, 0x37);
1465 mdelay(1); 1455 mdelay(1);
1466 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 1456 rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter1,
1467 0x4, 0x1); 1457 0x4, 0x1);
1468 priv->bHwRfOffAction = 0; 1458 priv->bHwRfOffAction = 0;
1469 1459
1470 rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, 1460 rtl92e_set_bb_reg(dev, rFPGA0_XA_RFInterfaceOE,
1471 BIT4, 0x1); 1461 BIT4, 0x1);
1472 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 1462 rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter4,
1473 0x300, 0x3); 1463 0x300, 0x3);
1474 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 1464 rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter1,
1475 0x18, 0x3); 1465 0x18, 0x3);
1476 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0x3, 1466 rtl92e_set_bb_reg(dev, rOFDM0_TRxPathEnable,
1477 0x3); 1467 0x3, 0x3);
1478 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0x3, 1468 rtl92e_set_bb_reg(dev, rOFDM1_TRxPathEnable,
1479 0x3); 1469 0x3, 0x3);
1480 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 1470 rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter1,
1481 0x60, 0x3); 1471 0x60, 0x3);
1482 1472
1483 } 1473 }
1484 1474
@@ -1511,7 +1501,7 @@ static bool SetRFPowerState8190(struct net_device *dev,
1511 break; 1501 break;
1512 } 1502 }
1513 } 1503 }
1514 PHY_SetRtl8192eRfOff(dev); 1504 rtl92e_set_rf_off(dev);
1515 break; 1505 break;
1516 1506
1517 case eRfOff: 1507 case eRfOff:
@@ -1543,11 +1533,11 @@ static bool SetRFPowerState8190(struct net_device *dev,
1543 1533
1544 if (pPSC->RegRfPsLevel & RT_RF_OFF_LEVL_HALT_NIC && 1534 if (pPSC->RegRfPsLevel & RT_RF_OFF_LEVL_HALT_NIC &&
1545 !RT_IN_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC)) { 1535 !RT_IN_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC)) {
1546 NicIFDisableNIC(dev); 1536 rtl92e_disable_nic(dev);
1547 RT_SET_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC); 1537 RT_SET_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
1548 } else if (!(pPSC->RegRfPsLevel & 1538 } else if (!(pPSC->RegRfPsLevel &
1549 RT_RF_OFF_LEVL_HALT_NIC)) { 1539 RT_RF_OFF_LEVL_HALT_NIC)) {
1550 PHY_SetRtl8192eRfOff(dev); 1540 rtl92e_set_rf_off(dev);
1551 } 1541 }
1552 1542
1553 break; 1543 break;
@@ -1586,32 +1576,34 @@ static bool SetRFPowerState8190(struct net_device *dev,
1586 return bResult; 1576 return bResult;
1587} 1577}
1588 1578
1589bool SetRFPowerState(struct net_device *dev, 1579bool rtl92e_set_rf_power_state(struct net_device *dev,
1590 enum rt_rf_power_state eRFPowerState) 1580 enum rt_rf_power_state eRFPowerState)
1591{ 1581{
1592 struct r8192_priv *priv = rtllib_priv(dev); 1582 struct r8192_priv *priv = rtllib_priv(dev);
1593 1583
1594 bool bResult = false; 1584 bool bResult = false;
1595 1585
1596 RT_TRACE(COMP_PS, "---------> SetRFPowerState(): eRFPowerState(%d)\n", 1586 RT_TRACE(COMP_PS,
1587 "---------> rtl92e_set_rf_power_state(): eRFPowerState(%d)\n",
1597 eRFPowerState); 1588 eRFPowerState);
1598 if (eRFPowerState == priv->rtllib->eRFPowerState && 1589 if (eRFPowerState == priv->rtllib->eRFPowerState &&
1599 priv->bHwRfOffAction == 0) { 1590 priv->bHwRfOffAction == 0) {
1600 RT_TRACE(COMP_PS, 1591 RT_TRACE(COMP_PS,
1601 "<--------- SetRFPowerState(): discard the request for eRFPowerState(%d) is the same.\n", 1592 "<--------- rtl92e_set_rf_power_state(): discard the request for eRFPowerState(%d) is the same.\n",
1602 eRFPowerState); 1593 eRFPowerState);
1603 return bResult; 1594 return bResult;
1604 } 1595 }
1605 1596
1606 bResult = SetRFPowerState8190(dev, eRFPowerState); 1597 bResult = SetRFPowerState8190(dev, eRFPowerState);
1607 1598
1608 RT_TRACE(COMP_PS, "<--------- SetRFPowerState(): bResult(%d)\n", 1599 RT_TRACE(COMP_PS,
1600 "<--------- rtl92e_set_rf_power_state(): bResult(%d)\n",
1609 bResult); 1601 bResult);
1610 1602
1611 return bResult; 1603 return bResult;
1612} 1604}
1613 1605
1614void PHY_ScanOperationBackup8192(struct net_device *dev, u8 Operation) 1606void rtl92e_scan_op_backup(struct net_device *dev, u8 Operation)
1615{ 1607{
1616 struct r8192_priv *priv = rtllib_priv(dev); 1608 struct r8192_priv *priv = rtllib_priv(dev);
1617 1609
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.h b/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.h
index 18bc58240fbe..96015d342009 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.h
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.h
@@ -67,48 +67,36 @@ enum rf90_radio_path {
67#define bMaskLWord 0x0000ffff 67#define bMaskLWord 0x0000ffff
68#define bMaskDWord 0xffffffff 68#define bMaskDWord 0xffffffff
69 69
70extern u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device *dev, 70u8 rtl92e_is_legal_rf_path(struct net_device *dev, u32 eRFPath);
71 u32 eRFPath); 71void rtl92e_set_bb_reg(struct net_device *dev, u32 dwRegAddr,
72extern void rtl8192_setBBreg(struct net_device *dev, u32 dwRegAddr, 72 u32 dwBitMask, u32 dwData);
73 u32 dwBitMask, u32 dwData); 73u32 rtl92e_get_bb_reg(struct net_device *dev, u32 dwRegAddr, u32 dwBitMask);
74extern u32 rtl8192_QueryBBReg(struct net_device *dev, u32 dwRegAddr, 74void rtl92e_set_rf_reg(struct net_device *dev, enum rf90_radio_path eRFPath,
75 u32 dwBitMask); 75 u32 RegAddr, u32 BitMask, u32 Data);
76extern void rtl8192_phy_SetRFReg(struct net_device *dev, 76u32 rtl92e_get_rf_reg(struct net_device *dev, enum rf90_radio_path eRFPath,
77 enum rf90_radio_path eRFPath, 77 u32 RegAddr, u32 BitMask);
78 u32 RegAddr, u32 BitMask, u32 Data); 78void rtl92e_config_mac(struct net_device *dev);
79extern u32 rtl8192_phy_QueryRFReg(struct net_device *dev, 79bool rtl92e_check_bb_and_rf(struct net_device *dev,
80 enum rf90_radio_path eRFPath, 80 enum hw90_block CheckBlock,
81 u32 RegAddr, u32 BitMask); 81 enum rf90_radio_path eRFPath);
82extern void rtl8192_phy_configmac(struct net_device *dev); 82bool rtl92e_config_bb(struct net_device *dev);
83extern void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType); 83void rtl92e_get_tx_power(struct net_device *dev);
84extern bool rtl8192_phy_checkBBAndRF(struct net_device *dev, 84void rtl92e_set_tx_power(struct net_device *dev, u8 channel);
85 enum hw90_block CheckBlock, 85bool rtl92e_config_phy(struct net_device *dev);
86 enum rf90_radio_path eRFPath); 86u8 rtl92e_config_rf_path(struct net_device *dev, enum rf90_radio_path eRFPath);
87extern bool rtl8192_BBConfig(struct net_device *dev);
88extern void rtl8192_phy_getTxPower(struct net_device *dev);
89extern void rtl8192_phy_setTxPower(struct net_device *dev, u8 channel);
90extern bool rtl8192_phy_RFConfig(struct net_device *dev);
91extern void rtl8192_phy_updateInitGain(struct net_device *dev);
92extern u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device *dev,
93 enum rf90_radio_path eRFPath);
94 87
95extern u8 rtl8192_phy_SwChnl(struct net_device *dev, u8 channel); 88u8 rtl92e_set_channel(struct net_device *dev, u8 channel);
96extern void rtl8192_SetBWMode(struct net_device *dev, 89void rtl92e_set_bw_mode(struct net_device *dev,
97 enum ht_channel_width Bandwidth, 90 enum ht_channel_width Bandwidth,
98 enum ht_extchnl_offset Offset); 91 enum ht_extchnl_offset Offset);
99extern void rtl8192_SwChnl_WorkItem(struct net_device *dev); 92void rtl92e_init_gain(struct net_device *dev, u8 Operation);
100extern void rtl8192_SetBWModeWorkItem(struct net_device *dev);
101extern void InitialGain819xPci(struct net_device *dev, u8 Operation);
102 93
103extern void PHY_SetRtl8192eRfOff(struct net_device *dev); 94void rtl92e_set_rf_off(struct net_device *dev);
104 95
105bool 96bool rtl92e_set_rf_power_state(struct net_device *dev,
106SetRFPowerState( 97 enum rt_rf_power_state eRFPowerState);
107 struct net_device *dev, 98#define PHY_SetRFPowerState rtl92e_set_rf_power_state
108 enum rt_rf_power_state eRFPowerState
109 );
110#define PHY_SetRFPowerState SetRFPowerState
111 99
112extern void PHY_ScanOperationBackup8192(struct net_device *dev, u8 Operation); 100void rtl92e_scan_op_backup(struct net_device *dev, u8 Operation);
113 101
114#endif 102#endif
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c b/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c
index f246222e5fc9..29dd93ac5e93 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c
@@ -28,15 +28,15 @@
28#include "r8190P_rtl8256.h" /* RTL8225 Radio frontend */ 28#include "r8190P_rtl8256.h" /* RTL8225 Radio frontend */
29#include "r8192E_cmdpkt.h" 29#include "r8192E_cmdpkt.h"
30 30
31void CamResetAllEntry(struct net_device *dev) 31void rtl92e_cam_reset(struct net_device *dev)
32{ 32{
33 u32 ulcommand = 0; 33 u32 ulcommand = 0;
34 34
35 ulcommand |= BIT31|BIT30; 35 ulcommand |= BIT31|BIT30;
36 write_nic_dword(dev, RWCAM, ulcommand); 36 rtl92e_writel(dev, RWCAM, ulcommand);
37} 37}
38 38
39void EnableHWSecurityConfig8192(struct net_device *dev) 39void rtl92e_enable_hw_security_config(struct net_device *dev)
40{ 40{
41 u8 SECR_value = 0x0; 41 u8 SECR_value = 0x0;
42 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 42 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
@@ -65,11 +65,12 @@ void EnableHWSecurityConfig8192(struct net_device *dev)
65 RT_TRACE(COMP_SEC, "%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n", 65 RT_TRACE(COMP_SEC, "%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n",
66 __func__, ieee->hwsec_active, ieee->pairwise_key_type, 66 __func__, ieee->hwsec_active, ieee->pairwise_key_type,
67 SECR_value); 67 SECR_value);
68 write_nic_byte(dev, SECR, SECR_value); 68 rtl92e_writeb(dev, SECR, SECR_value);
69} 69}
70 70
71void set_swcam(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType, 71void rtl92e_set_swcam(struct net_device *dev, u8 EntryNo, u8 KeyIndex,
72 const u8 *MacAddr, u8 DefaultKey, u32 *KeyContent, u8 is_mesh) 72 u16 KeyType, const u8 *MacAddr, u8 DefaultKey,
73 u32 *KeyContent, u8 is_mesh)
73{ 74{
74 struct r8192_priv *priv = rtllib_priv(dev); 75 struct r8192_priv *priv = rtllib_priv(dev);
75 struct rtllib_device *ieee = priv->rtllib; 76 struct rtllib_device *ieee = priv->rtllib;
@@ -77,6 +78,10 @@ void set_swcam(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
77 RT_TRACE(COMP_DBG, 78 RT_TRACE(COMP_DBG,
78 "===========>%s():EntryNo is %d,KeyIndex is %d,KeyType is %d,is_mesh is %d\n", 79 "===========>%s():EntryNo is %d,KeyIndex is %d,KeyType is %d,is_mesh is %d\n",
79 __func__, EntryNo, KeyIndex, KeyType, is_mesh); 80 __func__, EntryNo, KeyIndex, KeyType, is_mesh);
81
82 if (EntryNo >= TOTAL_CAM_ENTRY)
83 return;
84
80 if (!is_mesh) { 85 if (!is_mesh) {
81 ieee->swcamtable[EntryNo].bused = true; 86 ieee->swcamtable[EntryNo].bused = true;
82 ieee->swcamtable[EntryNo].key_index = KeyIndex; 87 ieee->swcamtable[EntryNo].key_index = KeyIndex;
@@ -87,8 +92,9 @@ void set_swcam(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
87 } 92 }
88} 93}
89 94
90void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType, 95void rtl92e_set_key(struct net_device *dev, u8 EntryNo, u8 KeyIndex,
91 const u8 *MacAddr, u8 DefaultKey, u32 *KeyContent) 96 u16 KeyType, const u8 *MacAddr, u8 DefaultKey,
97 u32 *KeyContent)
92{ 98{
93 u32 TargetCommand = 0; 99 u32 TargetCommand = 0;
94 u32 TargetContent = 0; 100 u32 TargetContent = 0;
@@ -106,16 +112,18 @@ void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
106 return; 112 return;
107 } 113 }
108 down(&priv->rtllib->ips_sem); 114 down(&priv->rtllib->ips_sem);
109 IPSLeave(dev); 115 rtl92e_ips_leave(dev);
110 up(&priv->rtllib->ips_sem); 116 up(&priv->rtllib->ips_sem);
111 } 117 }
112 } 118 }
113 priv->rtllib->is_set_key = true; 119 priv->rtllib->is_set_key = true;
114 if (EntryNo >= TOTAL_CAM_ENTRY) 120 if (EntryNo >= TOTAL_CAM_ENTRY) {
115 netdev_info(dev, "%s(): Invalid CAM entry\n", __func__); 121 netdev_info(dev, "%s(): Invalid CAM entry\n", __func__);
122 return;
123 }
116 124
117 RT_TRACE(COMP_SEC, 125 RT_TRACE(COMP_SEC,
118 "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d,KeyType:%d, MacAddr %pM\n", 126 "====>to rtl92e_set_key(), dev:%p, EntryNo:%d, KeyIndex:%d,KeyType:%d, MacAddr %pM\n",
119 dev, EntryNo, KeyIndex, KeyType, MacAddr); 127 dev, EntryNo, KeyIndex, KeyType, MacAddr);
120 128
121 if (DefaultKey) 129 if (DefaultKey)
@@ -133,20 +141,20 @@ void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
133 (u32)(*(MacAddr+1)) << 24 | 141 (u32)(*(MacAddr+1)) << 24 |
134 (u32)usConfig; 142 (u32)usConfig;
135 143
136 write_nic_dword(dev, WCAMI, TargetContent); 144 rtl92e_writel(dev, WCAMI, TargetContent);
137 write_nic_dword(dev, RWCAM, TargetCommand); 145 rtl92e_writel(dev, RWCAM, TargetCommand);
138 } else if (i == 1) { 146 } else if (i == 1) {
139 TargetContent = (u32)(*(MacAddr+2)) | 147 TargetContent = (u32)(*(MacAddr+2)) |
140 (u32)(*(MacAddr+3)) << 8 | 148 (u32)(*(MacAddr+3)) << 8 |
141 (u32)(*(MacAddr+4)) << 16 | 149 (u32)(*(MacAddr+4)) << 16 |
142 (u32)(*(MacAddr+5)) << 24; 150 (u32)(*(MacAddr+5)) << 24;
143 write_nic_dword(dev, WCAMI, TargetContent); 151 rtl92e_writel(dev, WCAMI, TargetContent);
144 write_nic_dword(dev, RWCAM, TargetCommand); 152 rtl92e_writel(dev, RWCAM, TargetCommand);
145 } else { 153 } else {
146 if (KeyContent != NULL) { 154 if (KeyContent != NULL) {
147 write_nic_dword(dev, WCAMI, 155 rtl92e_writel(dev, WCAMI,
148 (u32)(*(KeyContent+i-2))); 156 (u32)(*(KeyContent+i-2)));
149 write_nic_dword(dev, RWCAM, TargetCommand); 157 rtl92e_writel(dev, RWCAM, TargetCommand);
150 udelay(100); 158 udelay(100);
151 } 159 }
152 } 160 }
@@ -154,7 +162,7 @@ void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
154 RT_TRACE(COMP_SEC, "=========>after set key, usconfig:%x\n", usConfig); 162 RT_TRACE(COMP_SEC, "=========>after set key, usconfig:%x\n", usConfig);
155} 163}
156 164
157void CamRestoreAllEntry(struct net_device *dev) 165void rtl92e_cam_restore(struct net_device *dev)
158{ 166{
159 u8 EntryId = 0; 167 u8 EntryId = 0;
160 struct r8192_priv *priv = rtllib_priv(dev); 168 struct r8192_priv *priv = rtllib_priv(dev);
@@ -170,7 +178,7 @@ void CamRestoreAllEntry(struct net_device *dev)
170 0xff, 0xff, 0xff, 0xff, 0xff, 0xff 178 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
171 }; 179 };
172 180
173 RT_TRACE(COMP_SEC, "CamRestoreAllEntry:\n"); 181 RT_TRACE(COMP_SEC, "rtl92e_cam_restore:\n");
174 182
175 183
176 if ((priv->rtllib->pairwise_key_type == KEY_TYPE_WEP40) || 184 if ((priv->rtllib->pairwise_key_type == KEY_TYPE_WEP40) ||
@@ -179,36 +187,41 @@ void CamRestoreAllEntry(struct net_device *dev)
179 for (EntryId = 0; EntryId < 4; EntryId++) { 187 for (EntryId = 0; EntryId < 4; EntryId++) {
180 MacAddr = CAM_CONST_ADDR[EntryId]; 188 MacAddr = CAM_CONST_ADDR[EntryId];
181 if (priv->rtllib->swcamtable[EntryId].bused) { 189 if (priv->rtllib->swcamtable[EntryId].bused) {
182 setKey(dev, EntryId, EntryId, 190 rtl92e_set_key(dev, EntryId, EntryId,
183 priv->rtllib->pairwise_key_type, MacAddr, 191 priv->rtllib->pairwise_key_type,
184 0, (u32 *)(&priv->rtllib->swcamtable 192 MacAddr, 0,
185 [EntryId].key_buf[0])); 193 (u32 *)(&priv->rtllib->swcamtable
194 [EntryId].key_buf[0]));
186 } 195 }
187 } 196 }
188 197
189 } else if (priv->rtllib->pairwise_key_type == KEY_TYPE_TKIP) { 198 } else if (priv->rtllib->pairwise_key_type == KEY_TYPE_TKIP) {
190 if (priv->rtllib->iw_mode == IW_MODE_ADHOC) { 199 if (priv->rtllib->iw_mode == IW_MODE_ADHOC) {
191 setKey(dev, 4, 0, priv->rtllib->pairwise_key_type, 200 rtl92e_set_key(dev, 4, 0,
192 (u8 *)dev->dev_addr, 0, 201 priv->rtllib->pairwise_key_type,
193 (u32 *)(&priv->rtllib->swcamtable[4].key_buf[0])); 202 (u8 *)dev->dev_addr, 0,
203 (u32 *)(&priv->rtllib->swcamtable[4].
204 key_buf[0]));
194 } else { 205 } else {
195 setKey(dev, 4, 0, priv->rtllib->pairwise_key_type, 206 rtl92e_set_key(dev, 4, 0,
196 MacAddr, 0, 207 priv->rtllib->pairwise_key_type,
197 (u32 *)(&priv->rtllib->swcamtable[4].key_buf[0])); 208 MacAddr, 0,
209 (u32 *)(&priv->rtllib->swcamtable[4].
210 key_buf[0]));
198 } 211 }
199 212
200 } else if (priv->rtllib->pairwise_key_type == KEY_TYPE_CCMP) { 213 } else if (priv->rtllib->pairwise_key_type == KEY_TYPE_CCMP) {
201 if (priv->rtllib->iw_mode == IW_MODE_ADHOC) { 214 if (priv->rtllib->iw_mode == IW_MODE_ADHOC) {
202 setKey(dev, 4, 0, 215 rtl92e_set_key(dev, 4, 0,
203 priv->rtllib->pairwise_key_type, 216 priv->rtllib->pairwise_key_type,
204 (u8 *)dev->dev_addr, 0, 217 (u8 *)dev->dev_addr, 0,
205 (u32 *)(&priv->rtllib->swcamtable[4]. 218 (u32 *)(&priv->rtllib->swcamtable[4].
206 key_buf[0])); 219 key_buf[0]));
207 } else { 220 } else {
208 setKey(dev, 4, 0, 221 rtl92e_set_key(dev, 4, 0,
209 priv->rtllib->pairwise_key_type, MacAddr, 222 priv->rtllib->pairwise_key_type, MacAddr,
210 0, (u32 *)(&priv->rtllib->swcamtable[4]. 223 0, (u32 *)(&priv->rtllib->swcamtable[4].
211 key_buf[0])); 224 key_buf[0]));
212 } 225 }
213 } 226 }
214 227
@@ -216,20 +229,18 @@ void CamRestoreAllEntry(struct net_device *dev)
216 MacAddr = CAM_CONST_BROAD; 229 MacAddr = CAM_CONST_BROAD;
217 for (EntryId = 1; EntryId < 4; EntryId++) { 230 for (EntryId = 1; EntryId < 4; EntryId++) {
218 if (priv->rtllib->swcamtable[EntryId].bused) { 231 if (priv->rtllib->swcamtable[EntryId].bused) {
219 setKey(dev, EntryId, EntryId, 232 rtl92e_set_key(dev, EntryId, EntryId,
220 priv->rtllib->group_key_type, 233 priv->rtllib->group_key_type,
221 MacAddr, 0, 234 MacAddr, 0,
222 (u32 *)(&priv->rtllib->swcamtable[EntryId].key_buf[0]) 235 (u32 *)(&priv->rtllib->swcamtable[EntryId].key_buf[0]));
223 );
224 } 236 }
225 } 237 }
226 if (priv->rtllib->iw_mode == IW_MODE_ADHOC) { 238 if (priv->rtllib->iw_mode == IW_MODE_ADHOC) {
227 if (priv->rtllib->swcamtable[0].bused) { 239 if (priv->rtllib->swcamtable[0].bused) {
228 setKey(dev, 0, 0, 240 rtl92e_set_key(dev, 0, 0,
229 priv->rtllib->group_key_type, 241 priv->rtllib->group_key_type,
230 CAM_CONST_ADDR[0], 0, 242 CAM_CONST_ADDR[0], 0,
231 (u32 *)(&priv->rtllib->swcamtable[0].key_buf[0]) 243 (u32 *)(&priv->rtllib->swcamtable[0].key_buf[0]));
232 );
233 } else { 244 } else {
234 netdev_warn(dev, 245 netdev_warn(dev,
235 "%s(): ADHOC TKIP: missing key entry.\n", 246 "%s(): ADHOC TKIP: missing key entry.\n",
@@ -241,19 +252,19 @@ void CamRestoreAllEntry(struct net_device *dev)
241 MacAddr = CAM_CONST_BROAD; 252 MacAddr = CAM_CONST_BROAD;
242 for (EntryId = 1; EntryId < 4; EntryId++) { 253 for (EntryId = 1; EntryId < 4; EntryId++) {
243 if (priv->rtllib->swcamtable[EntryId].bused) { 254 if (priv->rtllib->swcamtable[EntryId].bused) {
244 setKey(dev, EntryId, EntryId, 255 rtl92e_set_key(dev, EntryId, EntryId,
245 priv->rtllib->group_key_type, 256 priv->rtllib->group_key_type,
246 MacAddr, 0, 257 MacAddr, 0,
247 (u32 *)(&priv->rtllib->swcamtable[EntryId].key_buf[0])); 258 (u32 *)(&priv->rtllib->swcamtable[EntryId].key_buf[0]));
248 } 259 }
249 } 260 }
250 261
251 if (priv->rtllib->iw_mode == IW_MODE_ADHOC) { 262 if (priv->rtllib->iw_mode == IW_MODE_ADHOC) {
252 if (priv->rtllib->swcamtable[0].bused) { 263 if (priv->rtllib->swcamtable[0].bused) {
253 setKey(dev, 0, 0, 264 rtl92e_set_key(dev, 0, 0,
254 priv->rtllib->group_key_type, 265 priv->rtllib->group_key_type,
255 CAM_CONST_ADDR[0], 0, 266 CAM_CONST_ADDR[0], 0,
256 (u32 *)(&priv->rtllib->swcamtable[0].key_buf[0])); 267 (u32 *)(&priv->rtllib->swcamtable[0].key_buf[0]));
257 } else { 268 } else {
258 netdev_warn(dev, 269 netdev_warn(dev,
259 "%s(): ADHOC CCMP: missing key entry.\n", 270 "%s(): ADHOC CCMP: missing key entry.\n",
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_cam.h b/drivers/staging/rtl8192e/rtl8192e/rtl_cam.h
index f23ab46c77e7..9ef8b36fc6b5 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_cam.h
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_cam.h
@@ -28,12 +28,14 @@
28#include <linux/types.h> 28#include <linux/types.h>
29struct net_device; 29struct net_device;
30 30
31void CamResetAllEntry(struct net_device *dev); 31void rtl92e_cam_reset(struct net_device *dev);
32void EnableHWSecurityConfig8192(struct net_device *dev); 32void rtl92e_enable_hw_security_config(struct net_device *dev);
33void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType, 33void rtl92e_set_key(struct net_device *dev, u8 EntryNo, u8 KeyIndex,
34 const u8 *MacAddr, u8 DefaultKey, u32 *KeyContent); 34 u16 KeyType, const u8 *MacAddr, u8 DefaultKey,
35void set_swcam(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType, 35 u32 *KeyContent);
36 const u8 *MacAddr, u8 DefaultKey, u32 *KeyContent, u8 is_mesh); 36void rtl92e_set_swcam(struct net_device *dev, u8 EntryNo, u8 KeyIndex,
37void CamRestoreAllEntry(struct net_device *dev); 37 u16 KeyType, const u8 *MacAddr, u8 DefaultKey,
38 u32 *KeyContent, u8 is_mesh);
39void rtl92e_cam_restore(struct net_device *dev);
38 40
39#endif 41#endif
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
index c6cdb43b864c..d6b46dfd01e1 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
@@ -22,25 +22,6 @@
22 * Contact Information: 22 * Contact Information:
23 * wlanfae <wlanfae@realtek.com> 23 * wlanfae <wlanfae@realtek.com>
24******************************************************************************/ 24******************************************************************************/
25#undef RX_DONT_PASS_UL
26#undef DEBUG_EPROM
27#undef DEBUG_RX_VERBOSE
28#undef DUMMY_RX
29#undef DEBUG_ZERO_RX
30#undef DEBUG_RX_SKB
31#undef DEBUG_TX_FRAG
32#undef DEBUG_RX_FRAG
33#undef DEBUG_TX_FILLDESC
34#undef DEBUG_TX
35#undef DEBUG_IRQ
36#undef DEBUG_RX
37#undef DEBUG_RXALLOC
38#undef DEBUG_REGISTERS
39#undef DEBUG_RING
40#undef DEBUG_IRQ_TASKLET
41#undef DEBUG_TX_ALLOC
42#undef DEBUG_TX_DESC
43
44#include <linux/uaccess.h> 25#include <linux/uaccess.h>
45#include <linux/pci.h> 26#include <linux/pci.h>
46#include <linux/vmalloc.h> 27#include <linux/vmalloc.h>
@@ -63,24 +44,24 @@ static char *ifname = "wlan%d";
63 44
64static struct rtl819x_ops rtl819xp_ops = { 45static struct rtl819x_ops rtl819xp_ops = {
65 .nic_type = NIC_8192E, 46 .nic_type = NIC_8192E,
66 .get_eeprom_size = rtl8192_get_eeprom_size, 47 .get_eeprom_size = rtl92e_get_eeprom_size,
67 .init_adapter_variable = rtl8192_InitializeVariables, 48 .init_adapter_variable = rtl92e_init_variables,
68 .initialize_adapter = rtl8192_adapter_start, 49 .initialize_adapter = rtl92e_start_adapter,
69 .link_change = rtl8192_link_change, 50 .link_change = rtl92e_link_change,
70 .tx_fill_descriptor = rtl8192_tx_fill_desc, 51 .tx_fill_descriptor = rtl92e_fill_tx_desc,
71 .tx_fill_cmd_descriptor = rtl8192_tx_fill_cmd_desc, 52 .tx_fill_cmd_descriptor = rtl92e_fill_tx_cmd_desc,
72 .rx_query_status_descriptor = rtl8192_rx_query_status_desc, 53 .rx_query_status_descriptor = rtl92e_get_rx_stats,
73 .rx_command_packet_handler = NULL, 54 .rx_command_packet_handler = NULL,
74 .stop_adapter = rtl8192_halt_adapter, 55 .stop_adapter = rtl92e_stop_adapter,
75 .update_ratr_table = rtl8192_update_ratr_table, 56 .update_ratr_table = rtl92e_update_ratr_table,
76 .irq_enable = rtl8192_EnableInterrupt, 57 .irq_enable = rtl92e_enable_irq,
77 .irq_disable = rtl8192_DisableInterrupt, 58 .irq_disable = rtl92e_disable_irq,
78 .irq_clear = rtl8192_ClearInterrupt, 59 .irq_clear = rtl92e_clear_irq,
79 .rx_enable = rtl8192_enable_rx, 60 .rx_enable = rtl92e_enable_rx,
80 .tx_enable = rtl8192_enable_tx, 61 .tx_enable = rtl92e_enable_tx,
81 .interrupt_recognized = rtl8192_interrupt_recognized, 62 .interrupt_recognized = rtl92e_ack_irq,
82 .TxCheckStuckHandler = rtl8192_HalTxCheckStuck, 63 .TxCheckStuckHandler = rtl92e_is_tx_stuck,
83 .RxCheckStuckHandler = rtl8192_HalRxCheckStuck, 64 .RxCheckStuckHandler = rtl92e_is_rx_stuck,
84}; 65};
85 66
86static struct pci_device_id rtl8192_pci_id_tbl[] = { 67static struct pci_device_id rtl8192_pci_id_tbl[] = {
@@ -102,202 +83,61 @@ static struct pci_driver rtl8192_pci_driver = {
102 .id_table = rtl8192_pci_id_tbl, /* PCI_ID table */ 83 .id_table = rtl8192_pci_id_tbl, /* PCI_ID table */
103 .probe = rtl8192_pci_probe, /* probe fn */ 84 .probe = rtl8192_pci_probe, /* probe fn */
104 .remove = rtl8192_pci_disconnect, /* remove fn */ 85 .remove = rtl8192_pci_disconnect, /* remove fn */
105 .suspend = rtl8192E_suspend, /* PM suspend fn */ 86 .suspend = rtl92e_suspend, /* PM suspend fn */
106 .resume = rtl8192E_resume, /* PM resume fn */ 87 .resume = rtl92e_resume, /* PM resume fn */
107}; 88};
108 89
90static short rtl8192_is_tx_queue_empty(struct net_device *dev);
91static void rtl819x_watchdog_wqcallback(void *data);
92static void watch_dog_timer_callback(unsigned long data);
93static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
94 int rate);
95static int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev);
96static void rtl8192_tx_cmd(struct net_device *dev, struct sk_buff *skb);
97static short rtl8192_tx(struct net_device *dev, struct sk_buff *skb);
98static short rtl8192_pci_initdescring(struct net_device *dev);
99static void rtl8192_irq_tx_tasklet(struct r8192_priv *priv);
100static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv);
101static void rtl8192_cancel_deferred_work(struct r8192_priv *priv);
102static int _rtl8192_up(struct net_device *dev, bool is_silent_reset);
103static int rtl8192_up(struct net_device *dev);
104static int rtl8192_down(struct net_device *dev, bool shutdownrf);
105static void rtl8192_restart(void *data);
106
109/**************************************************************************** 107/****************************************************************************
110 -----------------------------IO STUFF------------------------- 108 -----------------------------IO STUFF-------------------------
111*****************************************************************************/ 109*****************************************************************************/
112static bool PlatformIOCheckPageLegalAndGetRegMask(u32 u4bPage, u8 *pu1bPageMask)
113{
114 bool bReturn = false;
115
116 *pu1bPageMask = 0xfe;
117
118 switch (u4bPage) {
119 case 1: case 2: case 3: case 4:
120 case 8: case 9: case 10: case 12: case 13:
121 bReturn = true;
122 *pu1bPageMask = 0xf0;
123 break;
124
125 default:
126 bReturn = false;
127 break;
128 }
129
130 return bReturn;
131}
132
133void write_nic_io_byte(struct net_device *dev, int x, u8 y)
134{
135 u32 u4bPage = x >> 8;
136 u8 u1PageMask = 0;
137 bool bIsLegalPage = false;
138
139 if (u4bPage == 0) {
140 outb(y&0xff, dev->base_addr + x);
141
142 } else {
143 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
144 &u1PageMask);
145 if (bIsLegalPage) {
146 u8 u1bPsr = read_nic_io_byte(dev, PSR);
147
148 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
149 (u8)u4bPage));
150 write_nic_io_byte(dev, (x & 0xff), y);
151 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
152 }
153 }
154}
155
156void write_nic_io_word(struct net_device *dev, int x, u16 y)
157{
158 u32 u4bPage = x >> 8;
159 u8 u1PageMask = 0;
160 bool bIsLegalPage = false;
161
162 if (u4bPage == 0) {
163 outw(y, dev->base_addr + x);
164 } else {
165 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
166 &u1PageMask);
167 if (bIsLegalPage) {
168 u8 u1bPsr = read_nic_io_byte(dev, PSR);
169
170 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
171 (u8)u4bPage));
172 write_nic_io_word(dev, (x & 0xff), y);
173 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
174
175 }
176 }
177}
178
179void write_nic_io_dword(struct net_device *dev, int x, u32 y)
180{
181 u32 u4bPage = x >> 8;
182 u8 u1PageMask = 0;
183 bool bIsLegalPage = false;
184
185 if (u4bPage == 0) {
186 outl(y, dev->base_addr + x);
187 } else {
188 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
189 &u1PageMask);
190 if (bIsLegalPage) {
191 u8 u1bPsr = read_nic_io_byte(dev, PSR);
192
193 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
194 (u8)u4bPage));
195 write_nic_io_dword(dev, (x & 0xff), y);
196 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
197 }
198 }
199}
200
201u8 read_nic_io_byte(struct net_device *dev, int x)
202{
203 u32 u4bPage = x >> 8;
204 u8 u1PageMask = 0;
205 bool bIsLegalPage = false;
206 u8 Data = 0;
207
208 if (u4bPage == 0)
209 return 0xff&inb(dev->base_addr + x);
210
211 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
212 &u1PageMask);
213 if (bIsLegalPage) {
214 u8 u1bPsr = read_nic_io_byte(dev, PSR);
215
216 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
217 (u8)u4bPage));
218 Data = read_nic_io_byte(dev, (x & 0xff));
219 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
220 }
221
222 return Data;
223}
224
225u16 read_nic_io_word(struct net_device *dev, int x)
226{
227 u32 u4bPage = x >> 8;
228 u8 u1PageMask = 0;
229 bool bIsLegalPage = false;
230 u16 Data = 0;
231
232 if (u4bPage == 0)
233 return inw(dev->base_addr + x);
234 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
235 &u1PageMask);
236 if (bIsLegalPage) {
237 u8 u1bPsr = read_nic_io_byte(dev, PSR);
238
239 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
240 (u8)u4bPage));
241 Data = read_nic_io_word(dev, (x & 0xff));
242 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
243 }
244
245 return Data;
246}
247 110
248u32 read_nic_io_dword(struct net_device *dev, int x) 111u8 rtl92e_readb(struct net_device *dev, int x)
249{
250 u32 u4bPage = x >> 8;
251 u8 u1PageMask = 0;
252 bool bIsLegalPage = false;
253 u32 Data = 0;
254
255 if (u4bPage == 0)
256 return inl(dev->base_addr + x);
257 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
258 &u1PageMask);
259 if (bIsLegalPage) {
260 u8 u1bPsr = read_nic_io_byte(dev, PSR);
261
262 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
263 (u8)u4bPage));
264 Data = read_nic_io_dword(dev, (x & 0xff));
265 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
266 }
267
268 return Data;
269}
270
271u8 read_nic_byte(struct net_device *dev, int x)
272{ 112{
273 return 0xff & readb((u8 __iomem *)dev->mem_start + x); 113 return 0xff & readb((u8 __iomem *)dev->mem_start + x);
274} 114}
275 115
276u32 read_nic_dword(struct net_device *dev, int x) 116u32 rtl92e_readl(struct net_device *dev, int x)
277{ 117{
278 return readl((u8 __iomem *)dev->mem_start + x); 118 return readl((u8 __iomem *)dev->mem_start + x);
279} 119}
280 120
281u16 read_nic_word(struct net_device *dev, int x) 121u16 rtl92e_readw(struct net_device *dev, int x)
282{ 122{
283 return readw((u8 __iomem *)dev->mem_start + x); 123 return readw((u8 __iomem *)dev->mem_start + x);
284} 124}
285 125
286void write_nic_byte(struct net_device *dev, int x, u8 y) 126void rtl92e_writeb(struct net_device *dev, int x, u8 y)
287{ 127{
288 writeb(y, (u8 __iomem *)dev->mem_start + x); 128 writeb(y, (u8 __iomem *)dev->mem_start + x);
289 129
290 udelay(20); 130 udelay(20);
291} 131}
292 132
293void write_nic_dword(struct net_device *dev, int x, u32 y) 133void rtl92e_writel(struct net_device *dev, int x, u32 y)
294{ 134{
295 writel(y, (u8 __iomem *)dev->mem_start + x); 135 writel(y, (u8 __iomem *)dev->mem_start + x);
296 136
297 udelay(20); 137 udelay(20);
298} 138}
299 139
300void write_nic_word(struct net_device *dev, int x, u16 y) 140void rtl92e_writew(struct net_device *dev, int x, u16 y)
301{ 141{
302 writew(y, (u8 __iomem *)dev->mem_start + x); 142 writew(y, (u8 __iomem *)dev->mem_start + x);
303 143
@@ -307,10 +147,9 @@ void write_nic_word(struct net_device *dev, int x, u16 y)
307/**************************************************************************** 147/****************************************************************************
308 -----------------------------GENERAL FUNCTION------------------------- 148 -----------------------------GENERAL FUNCTION-------------------------
309*****************************************************************************/ 149*****************************************************************************/
310bool MgntActSet_RF_State(struct net_device *dev, 150bool rtl92e_set_rf_state(struct net_device *dev,
311 enum rt_rf_power_state StateToSet, 151 enum rt_rf_power_state StateToSet,
312 RT_RF_CHANGE_SOURCE ChangeSource, 152 RT_RF_CHANGE_SOURCE ChangeSource)
313 bool ProtectOrNot)
314{ 153{
315 struct r8192_priv *priv = rtllib_priv(dev); 154 struct r8192_priv *priv = rtllib_priv(dev);
316 struct rtllib_device *ieee = priv->rtllib; 155 struct rtllib_device *ieee = priv->rtllib;
@@ -321,39 +160,34 @@ bool MgntActSet_RF_State(struct net_device *dev,
321 unsigned long flag; 160 unsigned long flag;
322 161
323 RT_TRACE((COMP_PS | COMP_RF), 162 RT_TRACE((COMP_PS | COMP_RF),
324 "===>MgntActSet_RF_State(): StateToSet(%d)\n", StateToSet); 163 "===>rtl92e_set_rf_state(): StateToSet(%d)\n", StateToSet);
325
326 ProtectOrNot = false;
327 164
165 while (true) {
166 spin_lock_irqsave(&priv->rf_ps_lock, flag);
167 if (priv->RFChangeInProgress) {
168 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
169 RT_TRACE((COMP_PS | COMP_RF),
170 "rtl92e_set_rf_state(): RF Change in progress! Wait to set..StateToSet(%d).\n",
171 StateToSet);
328 172
329 if (!ProtectOrNot) { 173 while (priv->RFChangeInProgress) {
330 while (true) { 174 RFWaitCounter++;
331 spin_lock_irqsave(&priv->rf_ps_lock, flag);
332 if (priv->RFChangeInProgress) {
333 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
334 RT_TRACE((COMP_PS | COMP_RF), 175 RT_TRACE((COMP_PS | COMP_RF),
335 "MgntActSet_RF_State(): RF Change in progress! Wait to set..StateToSet(%d).\n", 176 "rtl92e_set_rf_state(): Wait 1 ms (%d times)...\n",
336 StateToSet); 177 RFWaitCounter);
337 178 mdelay(1);
338 while (priv->RFChangeInProgress) { 179
339 RFWaitCounter++; 180 if (RFWaitCounter > 100) {
340 RT_TRACE((COMP_PS | COMP_RF), 181 netdev_warn(dev,
341 "MgntActSet_RF_State(): Wait 1 ms (%d times)...\n", 182 "%s(): Timeout waiting for RF change.\n",
342 RFWaitCounter); 183 __func__);
343 mdelay(1); 184 return false;
344
345 if (RFWaitCounter > 100) {
346 netdev_warn(dev,
347 "%s(): Timeout waiting for RF change.\n",
348 __func__);
349 return false;
350 }
351 } 185 }
352 } else {
353 priv->RFChangeInProgress = true;
354 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
355 break;
356 } 186 }
187 } else {
188 priv->RFChangeInProgress = true;
189 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
190 break;
357 } 191 }
358 } 192 }
359 193
@@ -376,7 +210,7 @@ bool MgntActSet_RF_State(struct net_device *dev,
376 bConnectBySSID = true; 210 bConnectBySSID = true;
377 } else { 211 } else {
378 RT_TRACE((COMP_PS | COMP_RF), 212 RT_TRACE((COMP_PS | COMP_RF),
379 "MgntActSet_RF_State - eRfon reject pMgntInfo->RfOffReason= 0x%x, ChangeSource=0x%X\n", 213 "rtl92e_set_rf_state - eRfon reject pMgntInfo->RfOffReason= 0x%x, ChangeSource=0x%X\n",
380 priv->rtllib->RfOffReason, ChangeSource); 214 priv->rtllib->RfOffReason, ChangeSource);
381 } 215 }
382 216
@@ -413,7 +247,7 @@ bool MgntActSet_RF_State(struct net_device *dev,
413 247
414 if (bActionAllowed) { 248 if (bActionAllowed) {
415 RT_TRACE((COMP_PS | COMP_RF), 249 RT_TRACE((COMP_PS | COMP_RF),
416 "MgntActSet_RF_State(): Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n", 250 "rtl92e_set_rf_state(): Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n",
417 StateToSet, priv->rtllib->RfOffReason); 251 StateToSet, priv->rtllib->RfOffReason);
418 PHY_SetRFPowerState(dev, StateToSet); 252 PHY_SetRFPowerState(dev, StateToSet);
419 if (StateToSet == eRfOn) { 253 if (StateToSet == eRfOn) {
@@ -426,17 +260,15 @@ bool MgntActSet_RF_State(struct net_device *dev,
426 } 260 }
427 } else { 261 } else {
428 RT_TRACE((COMP_PS | COMP_RF), 262 RT_TRACE((COMP_PS | COMP_RF),
429 "MgntActSet_RF_State(): Action is rejected.... StateToSet(%d), ChangeSource(%#X), RfOffReason(%#X)\n", 263 "rtl92e_set_rf_state(): Action is rejected.... StateToSet(%d), ChangeSource(%#X), RfOffReason(%#X)\n",
430 StateToSet, ChangeSource, priv->rtllib->RfOffReason); 264 StateToSet, ChangeSource, priv->rtllib->RfOffReason);
431 } 265 }
432 266
433 if (!ProtectOrNot) { 267 spin_lock_irqsave(&priv->rf_ps_lock, flag);
434 spin_lock_irqsave(&priv->rf_ps_lock, flag); 268 priv->RFChangeInProgress = false;
435 priv->RFChangeInProgress = false; 269 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
436 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
437 }
438 270
439 RT_TRACE((COMP_PS | COMP_RF), "<===MgntActSet_RF_State()\n"); 271 RT_TRACE((COMP_PS | COMP_RF), "<===rtl92e_set_rf_state()\n");
440 return bActionAllowed; 272 return bActionAllowed;
441} 273}
442 274
@@ -450,7 +282,7 @@ static short rtl8192_check_nic_enough_desc(struct net_device *dev, int prio)
450 return 0; 282 return 0;
451} 283}
452 284
453void rtl8192_tx_timeout(struct net_device *dev) 285static void rtl8192_tx_timeout(struct net_device *dev)
454{ 286{
455 struct r8192_priv *priv = rtllib_priv(dev); 287 struct r8192_priv *priv = rtllib_priv(dev);
456 288
@@ -458,7 +290,7 @@ void rtl8192_tx_timeout(struct net_device *dev)
458 netdev_info(dev, "TXTIMEOUT"); 290 netdev_info(dev, "TXTIMEOUT");
459} 291}
460 292
461void rtl8192_irq_enable(struct net_device *dev) 293void rtl92e_irq_enable(struct net_device *dev)
462{ 294{
463 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 295 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
464 296
@@ -467,7 +299,7 @@ void rtl8192_irq_enable(struct net_device *dev)
467 priv->ops->irq_enable(dev); 299 priv->ops->irq_enable(dev);
468} 300}
469 301
470void rtl8192_irq_disable(struct net_device *dev) 302void rtl92e_irq_disable(struct net_device *dev)
471{ 303{
472 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 304 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
473 305
@@ -476,7 +308,7 @@ void rtl8192_irq_disable(struct net_device *dev)
476 priv->irq_enabled = 0; 308 priv->irq_enabled = 0;
477} 309}
478 310
479void rtl8192_set_chan(struct net_device *dev, short ch) 311static void rtl8192_set_chan(struct net_device *dev, short ch)
480{ 312{
481 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 313 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
482 314
@@ -490,7 +322,7 @@ void rtl8192_set_chan(struct net_device *dev, short ch)
490 priv->rf_set_chan(dev, priv->chan); 322 priv->rf_set_chan(dev, priv->chan);
491} 323}
492 324
493void rtl8192_update_cap(struct net_device *dev, u16 cap) 325static void rtl8192_update_cap(struct net_device *dev, u16 cap)
494{ 326{
495 struct r8192_priv *priv = rtllib_priv(dev); 327 struct r8192_priv *priv = rtllib_priv(dev);
496 struct rtllib_network *net = &priv->rtllib->current_network; 328 struct rtllib_network *net = &priv->rtllib->current_network;
@@ -683,7 +515,7 @@ static int rtl8192_qos_association_resp(struct r8192_priv *priv,
683 RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __func__, 515 RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __func__,
684 network->flags, priv->rtllib->current_network.qos_data.active); 516 network->flags, priv->rtllib->current_network.qos_data.active);
685 if (set_qos_param == 1) { 517 if (set_qos_param == 1) {
686 dm_init_edca_turbo(priv->rtllib->dev); 518 rtl92e_dm_init_edca_turbo(priv->rtllib->dev);
687 queue_work_rsl(priv->priv_wq, &priv->qos_activate); 519 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
688 } 520 }
689 return 0; 521 return 0;
@@ -733,7 +565,7 @@ static void rtl8192_stop_beacon(struct net_device *dev)
733{ 565{
734} 566}
735 567
736void rtl8192_config_rate(struct net_device *dev, u16 *rate_config) 568void rtl92e_config_rate(struct net_device *dev, u16 *rate_config)
737{ 569{
738 struct r8192_priv *priv = rtllib_priv(dev); 570 struct r8192_priv *priv = rtllib_priv(dev);
739 struct rtllib_network *net; 571 struct rtllib_network *net;
@@ -864,7 +696,7 @@ static u8 rtl8192_getSupportedWireleeMode(struct net_device *dev)
864 return ret; 696 return ret;
865} 697}
866 698
867void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode) 699void rtl92e_set_wireless_mode(struct net_device *dev, u8 wireless_mode)
868{ 700{
869 struct r8192_priv *priv = rtllib_priv(dev); 701 struct r8192_priv *priv = rtllib_priv(dev);
870 u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev); 702 u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
@@ -895,9 +727,6 @@ void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
895 727
896 priv->rtllib->mode = wireless_mode; 728 priv->rtllib->mode = wireless_mode;
897 729
898 ActUpdateChannelAccessSetting(dev, wireless_mode,
899 &priv->ChannelAccessSetting);
900
901 if ((wireless_mode == WIRELESS_MODE_N_24G) || 730 if ((wireless_mode == WIRELESS_MODE_N_24G) ||
902 (wireless_mode == WIRELESS_MODE_N_5G)) { 731 (wireless_mode == WIRELESS_MODE_N_5G)) {
903 priv->rtllib->pHTInfo->bEnableHT = 1; 732 priv->rtllib->pHTInfo->bEnableHT = 1;
@@ -941,7 +770,7 @@ static int _rtl8192_sta_up(struct net_device *dev, bool is_silent_reset)
941 priv->bfirst_init = false; 770 priv->bfirst_init = false;
942 771
943 if (priv->polling_timer_on == 0) 772 if (priv->polling_timer_on == 0)
944 check_rfctrl_gpio_timer((unsigned long)dev); 773 rtl92e_check_rfctrl_gpio_timer((unsigned long)dev);
945 774
946 if (priv->rtllib->state != RTLLIB_LINKED) 775 if (priv->rtllib->state != RTLLIB_LINKED)
947 rtllib_softmac_start_protocol(priv->rtllib, 0); 776 rtllib_softmac_start_protocol(priv->rtllib, 0);
@@ -969,7 +798,7 @@ static int rtl8192_sta_down(struct net_device *dev, bool shutdownrf)
969 priv->rtllib->rtllib_ips_leave(dev); 798 priv->rtllib->rtllib_ips_leave(dev);
970 799
971 if (priv->rtllib->state == RTLLIB_LINKED) 800 if (priv->rtllib->state == RTLLIB_LINKED)
972 LeisurePSLeave(dev); 801 rtl92e_leisure_ps_leave(dev);
973 802
974 priv->bDriverIsGoingToUnload = true; 803 priv->bDriverIsGoingToUnload = true;
975 priv->up = 0; 804 priv->up = 0;
@@ -982,9 +811,9 @@ static int rtl8192_sta_down(struct net_device *dev, bool shutdownrf)
982 priv->rtllib->wpa_ie_len = 0; 811 priv->rtllib->wpa_ie_len = 0;
983 kfree(priv->rtllib->wpa_ie); 812 kfree(priv->rtllib->wpa_ie);
984 priv->rtllib->wpa_ie = NULL; 813 priv->rtllib->wpa_ie = NULL;
985 CamResetAllEntry(dev); 814 rtl92e_cam_reset(dev);
986 memset(priv->rtllib->swcamtable, 0, sizeof(struct sw_cam_table) * 32); 815 memset(priv->rtllib->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
987 rtl8192_irq_disable(dev); 816 rtl92e_irq_disable(dev);
988 817
989 del_timer_sync(&priv->watch_dog_timer); 818 del_timer_sync(&priv->watch_dog_timer);
990 rtl8192_cancel_deferred_work(priv); 819 rtl8192_cancel_deferred_work(priv);
@@ -1027,38 +856,36 @@ static void rtl8192_init_priv_handler(struct net_device *dev)
1027 priv->rtllib->set_chan = rtl8192_set_chan; 856 priv->rtllib->set_chan = rtl8192_set_chan;
1028 priv->rtllib->link_change = priv->ops->link_change; 857 priv->rtllib->link_change = priv->ops->link_change;
1029 priv->rtllib->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit; 858 priv->rtllib->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit;
1030 priv->rtllib->data_hard_stop = rtl8192_data_hard_stop;
1031 priv->rtllib->data_hard_resume = rtl8192_data_hard_resume;
1032 priv->rtllib->check_nic_enough_desc = rtl8192_check_nic_enough_desc; 859 priv->rtllib->check_nic_enough_desc = rtl8192_check_nic_enough_desc;
1033 priv->rtllib->handle_assoc_response = rtl8192_handle_assoc_response; 860 priv->rtllib->handle_assoc_response = rtl8192_handle_assoc_response;
1034 priv->rtllib->handle_beacon = rtl8192_handle_beacon; 861 priv->rtllib->handle_beacon = rtl8192_handle_beacon;
1035 priv->rtllib->SetWirelessMode = rtl8192_SetWirelessMode; 862 priv->rtllib->SetWirelessMode = rtl92e_set_wireless_mode;
1036 priv->rtllib->LeisurePSLeave = LeisurePSLeave; 863 priv->rtllib->LeisurePSLeave = rtl92e_leisure_ps_leave;
1037 priv->rtllib->SetBWModeHandler = rtl8192_SetBWMode; 864 priv->rtllib->SetBWModeHandler = rtl92e_set_bw_mode;
1038 priv->rf_set_chan = rtl8192_phy_SwChnl; 865 priv->rf_set_chan = rtl92e_set_channel;
1039 866
1040 priv->rtllib->start_send_beacons = rtl8192e_start_beacon; 867 priv->rtllib->start_send_beacons = rtl92e_start_beacon;
1041 priv->rtllib->stop_send_beacons = rtl8192_stop_beacon; 868 priv->rtllib->stop_send_beacons = rtl8192_stop_beacon;
1042 869
1043 priv->rtllib->sta_wake_up = rtl8192_hw_wakeup; 870 priv->rtllib->sta_wake_up = rtl92e_hw_wakeup;
1044 priv->rtllib->enter_sleep_state = rtl8192_hw_to_sleep; 871 priv->rtllib->enter_sleep_state = rtl92e_enter_sleep;
1045 priv->rtllib->ps_is_queue_empty = rtl8192_is_tx_queue_empty; 872 priv->rtllib->ps_is_queue_empty = rtl8192_is_tx_queue_empty;
1046 873
1047 priv->rtllib->GetNmodeSupportBySecCfg = rtl8192_GetNmodeSupportBySecCfg; 874 priv->rtllib->GetNmodeSupportBySecCfg = rtl92e_get_nmode_support_by_sec;
1048 priv->rtllib->GetHalfNmodeSupportByAPsHandler = 875 priv->rtllib->GetHalfNmodeSupportByAPsHandler =
1049 rtl8192_GetHalfNmodeSupportByAPs; 876 rtl92e_is_halfn_supported_by_ap;
1050 877
1051 priv->rtllib->SetHwRegHandler = rtl8192e_SetHwReg; 878 priv->rtllib->SetHwRegHandler = rtl92e_set_reg;
1052 priv->rtllib->AllowAllDestAddrHandler = rtl8192_AllowAllDestAddr; 879 priv->rtllib->AllowAllDestAddrHandler = rtl92e_set_monitor_mode;
1053 priv->rtllib->SetFwCmdHandler = NULL; 880 priv->rtllib->SetFwCmdHandler = NULL;
1054 priv->rtllib->InitialGainHandler = InitialGain819xPci; 881 priv->rtllib->InitialGainHandler = rtl92e_init_gain;
1055 priv->rtllib->rtllib_ips_leave_wq = rtllib_ips_leave_wq; 882 priv->rtllib->rtllib_ips_leave_wq = rtl92e_rtllib_ips_leave_wq;
1056 priv->rtllib->rtllib_ips_leave = rtllib_ips_leave; 883 priv->rtllib->rtllib_ips_leave = rtl92e_rtllib_ips_leave;
1057 884
1058 priv->rtllib->LedControlHandler = NULL; 885 priv->rtllib->LedControlHandler = NULL;
1059 priv->rtllib->UpdateBeaconInterruptHandler = NULL; 886 priv->rtllib->UpdateBeaconInterruptHandler = NULL;
1060 887
1061 priv->rtllib->ScanOperationBackupHandler = PHY_ScanOperationBackup8192; 888 priv->rtllib->ScanOperationBackupHandler = rtl92e_scan_op_backup;
1062} 889}
1063 890
1064static void rtl8192_init_priv_constant(struct net_device *dev) 891static void rtl8192_init_priv_constant(struct net_device *dev)
@@ -1181,20 +1008,21 @@ static void rtl8192_init_priv_task(struct net_device *dev)
1181 1008
1182 priv->priv_wq = create_workqueue(DRV_NAME); 1009 priv->priv_wq = create_workqueue(DRV_NAME);
1183 INIT_WORK_RSL(&priv->reset_wq, (void *)rtl8192_restart, dev); 1010 INIT_WORK_RSL(&priv->reset_wq, (void *)rtl8192_restart, dev);
1184 INIT_WORK_RSL(&priv->rtllib->ips_leave_wq, (void *)IPSLeave_wq, dev); 1011 INIT_WORK_RSL(&priv->rtllib->ips_leave_wq, (void *)rtl92e_ips_leave_wq,
1012 dev);
1185 INIT_DELAYED_WORK_RSL(&priv->watch_dog_wq, 1013 INIT_DELAYED_WORK_RSL(&priv->watch_dog_wq,
1186 (void *)rtl819x_watchdog_wqcallback, dev); 1014 (void *)rtl819x_watchdog_wqcallback, dev);
1187 INIT_DELAYED_WORK_RSL(&priv->txpower_tracking_wq, 1015 INIT_DELAYED_WORK_RSL(&priv->txpower_tracking_wq,
1188 (void *)dm_txpower_trackingcallback, dev); 1016 (void *)rtl92e_dm_txpower_tracking_wq, dev);
1189 INIT_DELAYED_WORK_RSL(&priv->rfpath_check_wq, 1017 INIT_DELAYED_WORK_RSL(&priv->rfpath_check_wq,
1190 (void *)dm_rf_pathcheck_workitemcallback, dev); 1018 (void *)rtl92e_dm_rf_pathcheck_wq, dev);
1191 INIT_DELAYED_WORK_RSL(&priv->update_beacon_wq, 1019 INIT_DELAYED_WORK_RSL(&priv->update_beacon_wq,
1192 (void *)rtl8192_update_beacon, dev); 1020 (void *)rtl8192_update_beacon, dev);
1193 INIT_WORK_RSL(&priv->qos_activate, (void *)rtl8192_qos_activate, dev); 1021 INIT_WORK_RSL(&priv->qos_activate, (void *)rtl8192_qos_activate, dev);
1194 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_wakeup_wq, 1022 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_wakeup_wq,
1195 (void *) rtl8192_hw_wakeup_wq, dev); 1023 (void *) rtl92e_hw_wakeup_wq, dev);
1196 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_sleep_wq, 1024 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_sleep_wq,
1197 (void *) rtl8192_hw_sleep_wq, dev); 1025 (void *) rtl92e_hw_sleep_wq, dev);
1198 tasklet_init(&priv->irq_rx_tasklet, 1026 tasklet_init(&priv->irq_rx_tasklet,
1199 (void(*)(unsigned long))rtl8192_irq_rx_tasklet, 1027 (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
1200 (unsigned long)priv); 1028 (unsigned long)priv);
@@ -1250,17 +1078,17 @@ static short rtl8192_init(struct net_device *dev)
1250 priv->ops->init_adapter_variable(dev); 1078 priv->ops->init_adapter_variable(dev);
1251 rtl8192_get_channel_map(dev); 1079 rtl8192_get_channel_map(dev);
1252 1080
1253 init_hal_dm(dev); 1081 rtl92e_dm_init(dev);
1254 1082
1255 setup_timer(&priv->watch_dog_timer, 1083 setup_timer(&priv->watch_dog_timer,
1256 watch_dog_timer_callback, 1084 watch_dog_timer_callback,
1257 (unsigned long) dev); 1085 (unsigned long) dev);
1258 1086
1259 setup_timer(&priv->gpio_polling_timer, 1087 setup_timer(&priv->gpio_polling_timer,
1260 check_rfctrl_gpio_timer, 1088 rtl92e_check_rfctrl_gpio_timer,
1261 (unsigned long)dev); 1089 (unsigned long)dev);
1262 1090
1263 rtl8192_irq_disable(dev); 1091 rtl92e_irq_disable(dev);
1264 if (request_irq(dev->irq, rtl8192_interrupt, IRQF_SHARED, 1092 if (request_irq(dev->irq, rtl8192_interrupt, IRQF_SHARED,
1265 dev->name, dev)) { 1093 dev->name, dev)) {
1266 netdev_err(dev, "Error allocating IRQ %d", dev->irq); 1094 netdev_err(dev, "Error allocating IRQ %d", dev->irq);
@@ -1282,7 +1110,7 @@ static short rtl8192_init(struct net_device *dev)
1282/*************************************************************************** 1110/***************************************************************************
1283 -------------------------------WATCHDOG STUFF--------------------------- 1111 -------------------------------WATCHDOG STUFF---------------------------
1284***************************************************************************/ 1112***************************************************************************/
1285short rtl8192_is_tx_queue_empty(struct net_device *dev) 1113static short rtl8192_is_tx_queue_empty(struct net_device *dev)
1286{ 1114{
1287 int i = 0; 1115 int i = 0;
1288 struct r8192_priv *priv = rtllib_priv(dev); 1116 struct r8192_priv *priv = rtllib_priv(dev);
@@ -1439,7 +1267,7 @@ RESET_START:
1439 down(&priv->wx_sem); 1267 down(&priv->wx_sem);
1440 1268
1441 if (priv->rtllib->state == RTLLIB_LINKED) 1269 if (priv->rtllib->state == RTLLIB_LINKED)
1442 LeisurePSLeave(dev); 1270 rtl92e_leisure_ps_leave(dev);
1443 1271
1444 if (priv->up) { 1272 if (priv->up) {
1445 netdev_info(dev, "%s():the driver is not up.\n", 1273 netdev_info(dev, "%s():the driver is not up.\n",
@@ -1459,10 +1287,10 @@ RESET_START:
1459 if (!netif_queue_stopped(dev)) 1287 if (!netif_queue_stopped(dev))
1460 netif_stop_queue(dev); 1288 netif_stop_queue(dev);
1461 1289
1462 rtl8192_irq_disable(dev); 1290 rtl92e_irq_disable(dev);
1463 del_timer_sync(&priv->watch_dog_timer); 1291 del_timer_sync(&priv->watch_dog_timer);
1464 rtl8192_cancel_deferred_work(priv); 1292 rtl8192_cancel_deferred_work(priv);
1465 deinit_hal_dm(dev); 1293 rtl92e_dm_deinit(dev);
1466 rtllib_stop_scan_syncro(ieee); 1294 rtllib_stop_scan_syncro(ieee);
1467 1295
1468 if (ieee->state == RTLLIB_LINKED) { 1296 if (ieee->state == RTLLIB_LINKED) {
@@ -1479,7 +1307,7 @@ RESET_START:
1479 rtllib_softmac_stop_protocol(priv->rtllib, 0, true); 1307 rtllib_softmac_stop_protocol(priv->rtllib, 0, true);
1480 } 1308 }
1481 1309
1482 dm_backup_dynamic_mechanism_state(dev); 1310 rtl92e_dm_backup_state(dev);
1483 1311
1484 up(&priv->wx_sem); 1312 up(&priv->wx_sem);
1485 RT_TRACE(COMP_RESET, 1313 RT_TRACE(COMP_RESET,
@@ -1508,7 +1336,7 @@ RESET_START:
1508 priv->RFChangeInProgress = false; 1336 priv->RFChangeInProgress = false;
1509 spin_unlock_irqrestore(&priv->rf_ps_lock, flag); 1337 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1510 1338
1511 EnableHWSecurityConfig8192(dev); 1339 rtl92e_enable_hw_security_config(dev);
1512 1340
1513 if (ieee->state == RTLLIB_LINKED && ieee->iw_mode == 1341 if (ieee->state == RTLLIB_LINKED && ieee->iw_mode ==
1514 IW_MODE_INFRA) { 1342 IW_MODE_INFRA) {
@@ -1527,15 +1355,13 @@ RESET_START:
1527 1355
1528 rtllib_start_send_beacons(ieee); 1356 rtllib_start_send_beacons(ieee);
1529 1357
1530 if (ieee->data_hard_resume)
1531 ieee->data_hard_resume(ieee->dev);
1532 netif_carrier_on(ieee->dev); 1358 netif_carrier_on(ieee->dev);
1533 } else if (ieee->iw_mode == IW_MODE_MESH) { 1359 } else if (ieee->iw_mode == IW_MODE_MESH) {
1534 rtl819x_silentreset_mesh_bk(dev, IsPortal); 1360 rtl819x_silentreset_mesh_bk(dev, IsPortal);
1535 } 1361 }
1536 1362
1537 CamRestoreAllEntry(dev); 1363 rtl92e_cam_restore(dev);
1538 dm_restore_dynamic_mechanism_state(dev); 1364 rtl92e_dm_restore_state(dev);
1539END: 1365END:
1540 priv->ResetProgress = RESET_TYPE_NORESET; 1366 priv->ResetProgress = RESET_TYPE_NORESET;
1541 priv->reset_count++; 1367 priv->reset_count++;
@@ -1543,7 +1369,7 @@ END:
1543 priv->bForcedSilentReset = false; 1369 priv->bForcedSilentReset = false;
1544 priv->bResetInProgress = false; 1370 priv->bResetInProgress = false;
1545 1371
1546 write_nic_byte(dev, UFWP, 1); 1372 rtl92e_writeb(dev, UFWP, 1);
1547 RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n", 1373 RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n",
1548 priv->reset_count); 1374 priv->reset_count);
1549 } 1375 }
@@ -1570,8 +1396,7 @@ static void rtl819x_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum,
1570 } 1396 }
1571} 1397}
1572 1398
1573 1399static void rtl819x_watchdog_wqcallback(void *data)
1574void rtl819x_watchdog_wqcallback(void *data)
1575{ 1400{
1576 struct r8192_priv *priv = container_of_dwork_rsl(data, 1401 struct r8192_priv *priv = container_of_dwork_rsl(data,
1577 struct r8192_priv, watch_dog_wq); 1402 struct r8192_priv, watch_dog_wq);
@@ -1597,7 +1422,7 @@ void rtl819x_watchdog_wqcallback(void *data)
1597 priv->rtllib->CntAfterLink = 0; 1422 priv->rtllib->CntAfterLink = 0;
1598 } 1423 }
1599 1424
1600 hal_dm_watchdog(dev); 1425 rtl92e_dm_watchdog(dev);
1601 1426
1602 if (rtllib_act_scanning(priv->rtllib, false) == false) { 1427 if (rtllib_act_scanning(priv->rtllib, false) == false) {
1603 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state == 1428 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state ==
@@ -1608,8 +1433,8 @@ void rtl819x_watchdog_wqcallback(void *data)
1608 IPS_CALLBACK_NONE) && 1433 IPS_CALLBACK_NONE) &&
1609 (!ieee->bNetPromiscuousMode)) { 1434 (!ieee->bNetPromiscuousMode)) {
1610 RT_TRACE(COMP_PS, 1435 RT_TRACE(COMP_PS,
1611 "====================>haha: IPSEnter()\n"); 1436 "====================>haha: rtl92e_ips_enter()\n");
1612 IPSEnter(dev); 1437 rtl92e_ips_enter(dev);
1613 } 1438 }
1614 } 1439 }
1615 } 1440 }
@@ -1640,13 +1465,13 @@ void rtl819x_watchdog_wqcallback(void *data)
1640 bEnterPS = false; 1465 bEnterPS = false;
1641 1466
1642 if (bEnterPS) 1467 if (bEnterPS)
1643 LeisurePSEnter(dev); 1468 rtl92e_leisure_ps_enter(dev);
1644 else 1469 else
1645 LeisurePSLeave(dev); 1470 rtl92e_leisure_ps_leave(dev);
1646 1471
1647 } else { 1472 } else {
1648 RT_TRACE(COMP_LPS, "====>no link LPS leave\n"); 1473 RT_TRACE(COMP_LPS, "====>no link LPS leave\n");
1649 LeisurePSLeave(dev); 1474 rtl92e_leisure_ps_leave(dev);
1650 } 1475 }
1651 1476
1652 ieee->LinkDetectInfo.NumRxOkInPeriod = 0; 1477 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
@@ -1725,7 +1550,7 @@ void rtl819x_watchdog_wqcallback(void *data)
1725 RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n"); 1550 RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
1726} 1551}
1727 1552
1728void watch_dog_timer_callback(unsigned long data) 1553static void watch_dog_timer_callback(unsigned long data)
1729{ 1554{
1730 struct r8192_priv *priv = rtllib_priv((struct net_device *)data); 1555 struct r8192_priv *priv = rtllib_priv((struct net_device *)data);
1731 1556
@@ -1737,14 +1562,14 @@ void watch_dog_timer_callback(unsigned long data)
1737/**************************************************************************** 1562/****************************************************************************
1738 ---------------------------- NIC TX/RX STUFF--------------------------- 1563 ---------------------------- NIC TX/RX STUFF---------------------------
1739*****************************************************************************/ 1564*****************************************************************************/
1740void rtl8192_rx_enable(struct net_device *dev) 1565void rtl92e_rx_enable(struct net_device *dev)
1741{ 1566{
1742 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 1567 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1743 1568
1744 priv->ops->rx_enable(dev); 1569 priv->ops->rx_enable(dev);
1745} 1570}
1746 1571
1747void rtl8192_tx_enable(struct net_device *dev) 1572void rtl92e_tx_enable(struct net_device *dev)
1748{ 1573{
1749 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 1574 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1750 1575
@@ -1802,16 +1627,7 @@ static void rtl8192_free_tx_ring(struct net_device *dev, unsigned int prio)
1802 ring->desc = NULL; 1627 ring->desc = NULL;
1803} 1628}
1804 1629
1805void rtl8192_data_hard_stop(struct net_device *dev) 1630static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
1806{
1807}
1808
1809
1810void rtl8192_data_hard_resume(struct net_device *dev)
1811{
1812}
1813
1814void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
1815 int rate) 1631 int rate)
1816{ 1632{
1817 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 1633 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
@@ -1826,8 +1642,8 @@ void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
1826 return; 1642 return;
1827 } 1643 }
1828 1644
1829 if (queue_index != TXCMD_QUEUE) 1645 if (queue_index == TXCMD_QUEUE)
1830 netdev_warn(dev, "%s(): queue index != TXCMD_QUEUE\n", 1646 netdev_warn(dev, "%s(): queue index == TXCMD_QUEUE\n",
1831 __func__); 1647 __func__);
1832 1648
1833 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev)); 1649 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
@@ -1843,7 +1659,7 @@ void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
1843 } 1659 }
1844} 1660}
1845 1661
1846int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) 1662static int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1847{ 1663{
1848 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 1664 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1849 int ret; 1665 int ret;
@@ -1902,7 +1718,7 @@ static void rtl8192_tx_isr(struct net_device *dev, int prio)
1902 tasklet_schedule(&priv->irq_tx_tasklet); 1718 tasklet_schedule(&priv->irq_tx_tasklet);
1903} 1719}
1904 1720
1905void rtl8192_tx_cmd(struct net_device *dev, struct sk_buff *skb) 1721static void rtl8192_tx_cmd(struct net_device *dev, struct sk_buff *skb)
1906{ 1722{
1907 struct r8192_priv *priv = rtllib_priv(dev); 1723 struct r8192_priv *priv = rtllib_priv(dev);
1908 struct rtl8192_tx_ring *ring; 1724 struct rtl8192_tx_ring *ring;
@@ -1925,7 +1741,7 @@ void rtl8192_tx_cmd(struct net_device *dev, struct sk_buff *skb)
1925 spin_unlock_irqrestore(&priv->irq_th_lock, flags); 1741 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
1926} 1742}
1927 1743
1928short rtl8192_tx(struct net_device *dev, struct sk_buff *skb) 1744static short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
1929{ 1745{
1930 struct r8192_priv *priv = rtllib_priv(dev); 1746 struct r8192_priv *priv = rtllib_priv(dev);
1931 struct rtl8192_tx_ring *ring; 1747 struct rtl8192_tx_ring *ring;
@@ -1997,7 +1813,7 @@ short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
1997 spin_unlock_irqrestore(&priv->irq_th_lock, flags); 1813 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
1998 dev->trans_start = jiffies; 1814 dev->trans_start = jiffies;
1999 1815
2000 write_nic_word(dev, TPPoll, 0x01 << tcb_desc->queue_index); 1816 rtl92e_writew(dev, TPPoll, 0x01 << tcb_desc->queue_index);
2001 return 0; 1817 return 0;
2002} 1818}
2003 1819
@@ -2077,8 +1893,7 @@ static int rtl8192_alloc_tx_desc_ring(struct net_device *dev,
2077 return 0; 1893 return 0;
2078} 1894}
2079 1895
2080 1896static short rtl8192_pci_initdescring(struct net_device *dev)
2081short rtl8192_pci_initdescring(struct net_device *dev)
2082{ 1897{
2083 u32 ret; 1898 u32 ret;
2084 int i; 1899 int i;
@@ -2104,7 +1919,7 @@ err_free_rings:
2104 return 1; 1919 return 1;
2105} 1920}
2106 1921
2107void rtl8192_pci_resetdescring(struct net_device *dev) 1922void rtl92e_reset_desc_ring(struct net_device *dev)
2108{ 1923{
2109 struct r8192_priv *priv = rtllib_priv(dev); 1924 struct r8192_priv *priv = rtllib_priv(dev);
2110 int i, rx_queue_idx; 1925 int i, rx_queue_idx;
@@ -2144,8 +1959,8 @@ void rtl8192_pci_resetdescring(struct net_device *dev)
2144 spin_unlock_irqrestore(&priv->irq_th_lock, flags); 1959 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2145} 1960}
2146 1961
2147void rtl819x_UpdateRxPktTimeStamp(struct net_device *dev, 1962void rtl92e_update_rx_pkt_timestamp(struct net_device *dev,
2148 struct rtllib_rx_stats *stats) 1963 struct rtllib_rx_stats *stats)
2149{ 1964{
2150 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 1965 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2151 1966
@@ -2155,7 +1970,7 @@ void rtl819x_UpdateRxPktTimeStamp(struct net_device *dev,
2155 priv->LastRxDescTSF = stats->mac_time; 1970 priv->LastRxDescTSF = stats->mac_time;
2156} 1971}
2157 1972
2158long rtl819x_translate_todbm(struct r8192_priv *priv, u8 signal_strength_index) 1973long rtl92e_translate_to_dbm(struct r8192_priv *priv, u8 signal_strength_index)
2159{ 1974{
2160 long signal_power; 1975 long signal_power;
2161 1976
@@ -2166,11 +1981,8 @@ long rtl819x_translate_todbm(struct r8192_priv *priv, u8 signal_strength_index)
2166} 1981}
2167 1982
2168 1983
2169void 1984void rtl92e_update_rx_statistics(struct r8192_priv *priv,
2170rtl819x_update_rxsignalstatistics8190pci( 1985 struct rtllib_rx_stats *pprevious_stats)
2171 struct r8192_priv *priv,
2172 struct rtllib_rx_stats *pprevious_stats
2173 )
2174{ 1986{
2175 int weighting = 0; 1987 int weighting = 0;
2176 1988
@@ -2189,13 +2001,7 @@ rtl819x_update_rxsignalstatistics8190pci(
2189 weighting) / 6; 2001 weighting) / 6;
2190} 2002}
2191 2003
2192void rtl819x_process_cck_rxpathsel(struct r8192_priv *priv, 2004u8 rtl92e_rx_db_to_percent(char antpower)
2193 struct rtllib_rx_stats *pprevious_stats)
2194{
2195}
2196
2197
2198u8 rtl819x_query_rxpwrpercentage(char antpower)
2199{ 2005{
2200 if ((antpower <= -100) || (antpower >= 20)) 2006 if ((antpower <= -100) || (antpower >= 20))
2201 return 0; 2007 return 0;
@@ -2206,10 +2012,7 @@ u8 rtl819x_query_rxpwrpercentage(char antpower)
2206 2012
2207} /* QueryRxPwrPercentage */ 2013} /* QueryRxPwrPercentage */
2208 2014
2209u8 2015u8 rtl92e_evm_db_to_percent(char value)
2210rtl819x_evm_dbtopercentage(
2211 char value
2212 )
2213{ 2016{
2214 char ret_val; 2017 char ret_val;
2215 2018
@@ -2226,11 +2029,8 @@ rtl819x_evm_dbtopercentage(
2226 return ret_val; 2029 return ret_val;
2227} 2030}
2228 2031
2229void 2032void rtl92e_copy_mpdu_stats(struct rtllib_rx_stats *psrc_stats,
2230rtl8192_record_rxdesc_forlateruse( 2033 struct rtllib_rx_stats *ptarget_stats)
2231 struct rtllib_rx_stats *psrc_stats,
2232 struct rtllib_rx_stats *ptarget_stats
2233)
2234{ 2034{
2235 ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU; 2035 ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
2236 ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU; 2036 ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
@@ -2344,11 +2144,6 @@ done:
2344 2144
2345} 2145}
2346 2146
2347static void rtl8192_rx_cmd(struct net_device *dev)
2348{
2349}
2350
2351
2352static void rtl8192_tx_resume(struct net_device *dev) 2147static void rtl8192_tx_resume(struct net_device *dev)
2353{ 2148{
2354 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 2149 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
@@ -2366,26 +2161,23 @@ static void rtl8192_tx_resume(struct net_device *dev)
2366 } 2161 }
2367} 2162}
2368 2163
2369void rtl8192_irq_tx_tasklet(struct r8192_priv *priv) 2164static void rtl8192_irq_tx_tasklet(struct r8192_priv *priv)
2370{ 2165{
2371 rtl8192_tx_resume(priv->rtllib->dev); 2166 rtl8192_tx_resume(priv->rtllib->dev);
2372} 2167}
2373 2168
2374void rtl8192_irq_rx_tasklet(struct r8192_priv *priv) 2169static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
2375{ 2170{
2376 rtl8192_rx_normal(priv->rtllib->dev); 2171 rtl8192_rx_normal(priv->rtllib->dev);
2377 2172
2378 if (MAX_RX_QUEUE > 1) 2173 rtl92e_writel(priv->rtllib->dev, INTA_MASK,
2379 rtl8192_rx_cmd(priv->rtllib->dev); 2174 rtl92e_readl(priv->rtllib->dev, INTA_MASK) | IMR_RDU);
2380
2381 write_nic_dword(priv->rtllib->dev, INTA_MASK,
2382 read_nic_dword(priv->rtllib->dev, INTA_MASK) | IMR_RDU);
2383} 2175}
2384 2176
2385/**************************************************************************** 2177/****************************************************************************
2386 ---------------------------- NIC START/CLOSE STUFF--------------------------- 2178 ---------------------------- NIC START/CLOSE STUFF---------------------------
2387*****************************************************************************/ 2179*****************************************************************************/
2388void rtl8192_cancel_deferred_work(struct r8192_priv *priv) 2180static void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
2389{ 2181{
2390 cancel_delayed_work(&priv->watch_dog_wq); 2182 cancel_delayed_work(&priv->watch_dog_wq);
2391 cancel_delayed_work(&priv->update_beacon_wq); 2183 cancel_delayed_work(&priv->update_beacon_wq);
@@ -2394,14 +2186,13 @@ void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
2394 cancel_work_sync(&priv->qos_activate); 2186 cancel_work_sync(&priv->qos_activate);
2395} 2187}
2396 2188
2397int _rtl8192_up(struct net_device *dev, bool is_silent_reset) 2189static int _rtl8192_up(struct net_device *dev, bool is_silent_reset)
2398{ 2190{
2399 if (_rtl8192_sta_up(dev, is_silent_reset) == -1) 2191 if (_rtl8192_sta_up(dev, is_silent_reset) == -1)
2400 return -1; 2192 return -1;
2401 return 0; 2193 return 0;
2402} 2194}
2403 2195
2404
2405static int rtl8192_open(struct net_device *dev) 2196static int rtl8192_open(struct net_device *dev)
2406{ 2197{
2407 struct r8192_priv *priv = rtllib_priv(dev); 2198 struct r8192_priv *priv = rtllib_priv(dev);
@@ -2414,8 +2205,7 @@ static int rtl8192_open(struct net_device *dev)
2414 2205
2415} 2206}
2416 2207
2417 2208static int rtl8192_up(struct net_device *dev)
2418int rtl8192_up(struct net_device *dev)
2419{ 2209{
2420 struct r8192_priv *priv = rtllib_priv(dev); 2210 struct r8192_priv *priv = rtllib_priv(dev);
2421 2211
@@ -2445,7 +2235,7 @@ static int rtl8192_close(struct net_device *dev)
2445 2235
2446} 2236}
2447 2237
2448int rtl8192_down(struct net_device *dev, bool shutdownrf) 2238static int rtl8192_down(struct net_device *dev, bool shutdownrf)
2449{ 2239{
2450 if (rtl8192_sta_down(dev, shutdownrf) == -1) 2240 if (rtl8192_sta_down(dev, shutdownrf) == -1)
2451 return -1; 2241 return -1;
@@ -2453,19 +2243,19 @@ int rtl8192_down(struct net_device *dev, bool shutdownrf)
2453 return 0; 2243 return 0;
2454} 2244}
2455 2245
2456void rtl8192_commit(struct net_device *dev) 2246void rtl92e_commit(struct net_device *dev)
2457{ 2247{
2458 struct r8192_priv *priv = rtllib_priv(dev); 2248 struct r8192_priv *priv = rtllib_priv(dev);
2459 2249
2460 if (priv->up == 0) 2250 if (priv->up == 0)
2461 return; 2251 return;
2462 rtllib_softmac_stop_protocol(priv->rtllib, 0, true); 2252 rtllib_softmac_stop_protocol(priv->rtllib, 0, true);
2463 rtl8192_irq_disable(dev); 2253 rtl92e_irq_disable(dev);
2464 priv->ops->stop_adapter(dev, true); 2254 priv->ops->stop_adapter(dev, true);
2465 _rtl8192_up(dev, false); 2255 _rtl8192_up(dev, false);
2466} 2256}
2467 2257
2468void rtl8192_restart(void *data) 2258static void rtl8192_restart(void *data)
2469{ 2259{
2470 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv, 2260 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
2471 reset_wq); 2261 reset_wq);
@@ -2473,7 +2263,7 @@ void rtl8192_restart(void *data)
2473 2263
2474 down(&priv->wx_sem); 2264 down(&priv->wx_sem);
2475 2265
2476 rtl8192_commit(dev); 2266 rtl92e_commit(dev);
2477 2267
2478 up(&priv->wx_sem); 2268 up(&priv->wx_sem);
2479} 2269}
@@ -2552,30 +2342,34 @@ static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2552 if (is_zero_ether_addr(ieee->ap_mac_addr)) 2342 if (is_zero_ether_addr(ieee->ap_mac_addr))
2553 ieee->iw_mode = IW_MODE_ADHOC; 2343 ieee->iw_mode = IW_MODE_ADHOC;
2554 memcpy((u8 *)key, ipw->u.crypt.key, 16); 2344 memcpy((u8 *)key, ipw->u.crypt.key, 16);
2555 EnableHWSecurityConfig8192(dev); 2345 rtl92e_enable_hw_security_config(dev);
2556 set_swcam(dev, 4, ipw->u.crypt.idx, 2346 rtl92e_set_swcam(dev, 4,
2557 ieee->pairwise_key_type, 2347 ipw->u.crypt.idx,
2558 (u8 *)ieee->ap_mac_addr, 2348 ieee->pairwise_key_type,
2559 0, key, 0); 2349 (u8 *)ieee->ap_mac_addr,
2560 setKey(dev, 4, ipw->u.crypt.idx, 2350 0, key, 0);
2561 ieee->pairwise_key_type, 2351 rtl92e_set_key(dev, 4, ipw->u.crypt.idx,
2562 (u8 *)ieee->ap_mac_addr, 0, key);
2563 if (ieee->iw_mode == IW_MODE_ADHOC) {
2564 set_swcam(dev, ipw->u.crypt.idx,
2565 ipw->u.crypt.idx,
2566 ieee->pairwise_key_type,
2567 (u8 *)ieee->ap_mac_addr,
2568 0, key, 0);
2569 setKey(dev, ipw->u.crypt.idx,
2570 ipw->u.crypt.idx,
2571 ieee->pairwise_key_type, 2352 ieee->pairwise_key_type,
2572 (u8 *)ieee->ap_mac_addr, 2353 (u8 *)ieee->ap_mac_addr,
2573 0, key); 2354 0, key);
2355 if (ieee->iw_mode == IW_MODE_ADHOC) {
2356 rtl92e_set_swcam(dev,
2357 ipw->u.crypt.idx,
2358 ipw->u.crypt.idx,
2359 ieee->pairwise_key_type,
2360 (u8 *)ieee->ap_mac_addr,
2361 0, key, 0);
2362 rtl92e_set_key(dev,
2363 ipw->u.crypt.idx,
2364 ipw->u.crypt.idx,
2365 ieee->pairwise_key_type,
2366 (u8 *)ieee->ap_mac_addr,
2367 0, key);
2574 } 2368 }
2575 } 2369 }
2576 if ((ieee->pairwise_key_type == KEY_TYPE_CCMP) 2370 if ((ieee->pairwise_key_type == KEY_TYPE_CCMP)
2577 && ieee->pHTInfo->bCurrentHTSupport) { 2371 && ieee->pHTInfo->bCurrentHTSupport) {
2578 write_nic_byte(dev, 0x173, 1); 2372 rtl92e_writeb(dev, 0x173, 1);
2579 } 2373 }
2580 2374
2581 } else { 2375 } else {
@@ -2595,14 +2389,15 @@ static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2595 ieee->group_key_type = KEY_TYPE_NA; 2389 ieee->group_key_type = KEY_TYPE_NA;
2596 2390
2597 if (ieee->group_key_type) { 2391 if (ieee->group_key_type) {
2598 set_swcam(dev, ipw->u.crypt.idx, 2392 rtl92e_set_swcam(dev, ipw->u.crypt.idx,
2599 ipw->u.crypt.idx, 2393 ipw->u.crypt.idx,
2600 ieee->group_key_type, 2394 ieee->group_key_type,
2601 broadcast_addr, 0, key, 0); 2395 broadcast_addr, 0, key,
2602 setKey(dev, ipw->u.crypt.idx, 2396 0);
2603 ipw->u.crypt.idx, 2397 rtl92e_set_key(dev, ipw->u.crypt.idx,
2604 ieee->group_key_type, 2398 ipw->u.crypt.idx,
2605 broadcast_addr, 0, key); 2399 ieee->group_key_type,
2400 broadcast_addr, 0, key);
2606 } 2401 }
2607 } 2402 }
2608 } 2403 }
@@ -2707,8 +2502,8 @@ static irqreturn_t rtl8192_interrupt(int irq, void *netdev)
2707 if (inta & IMR_RDU) { 2502 if (inta & IMR_RDU) {
2708 RT_TRACE(COMP_INTR, "rx descriptor unavailable!\n"); 2503 RT_TRACE(COMP_INTR, "rx descriptor unavailable!\n");
2709 priv->stats.rxrdu++; 2504 priv->stats.rxrdu++;
2710 write_nic_dword(dev, INTA_MASK, 2505 rtl92e_writel(dev, INTA_MASK,
2711 read_nic_dword(dev, INTA_MASK) & ~IMR_RDU); 2506 rtl92e_readl(dev, INTA_MASK) & ~IMR_RDU);
2712 tasklet_schedule(&priv->irq_rx_tasklet); 2507 tasklet_schedule(&priv->irq_rx_tasklet);
2713 } 2508 }
2714 2509
@@ -2782,7 +2577,6 @@ static int rtl8192_pci_probe(struct pci_dev *pdev,
2782 struct rtl819x_ops *ops = (struct rtl819x_ops *)(id->driver_data); 2577 struct rtl819x_ops *ops = (struct rtl819x_ops *)(id->driver_data);
2783 unsigned long pmem_start, pmem_len, pmem_flags; 2578 unsigned long pmem_start, pmem_len, pmem_flags;
2784 int err = -ENOMEM; 2579 int err = -ENOMEM;
2785 bool bdma64 = false;
2786 u8 revision_id; 2580 u8 revision_id;
2787 2581
2788 RT_TRACE(COMP_INIT, "Configuring chip resources"); 2582 RT_TRACE(COMP_INIT, "Configuring chip resources");
@@ -2806,8 +2600,6 @@ static int rtl8192_pci_probe(struct pci_dev *pdev,
2806 goto err_pci_disable; 2600 goto err_pci_disable;
2807 2601
2808 err = -ENODEV; 2602 err = -ENODEV;
2809 if (bdma64)
2810 dev->features |= NETIF_F_HIGHDMA;
2811 2603
2812 pci_set_drvdata(pdev, dev); 2604 pci_set_drvdata(pdev, dev);
2813 SET_NETDEV_DEV(dev, &pdev->dev); 2605 SET_NETDEV_DEV(dev, &pdev->dev);
@@ -2850,12 +2642,12 @@ static int rtl8192_pci_probe(struct pci_dev *pdev,
2850 pci_read_config_byte(pdev, 0x08, &revision_id); 2642 pci_read_config_byte(pdev, 0x08, &revision_id);
2851 /* If the revisionid is 0x10, the device uses rtl8192se. */ 2643 /* If the revisionid is 0x10, the device uses rtl8192se. */
2852 if (pdev->device == 0x8192 && revision_id == 0x10) 2644 if (pdev->device == 0x8192 && revision_id == 0x10)
2853 goto err_rel_mem; 2645 goto err_unmap;
2854 2646
2855 priv->ops = ops; 2647 priv->ops = ops;
2856 2648
2857 if (rtl8192_pci_findadapter(pdev, dev) == false) 2649 if (rtl92e_check_adapter(pdev, dev) == false)
2858 goto err_rel_mem; 2650 goto err_unmap;
2859 2651
2860 dev->irq = pdev->irq; 2652 dev->irq = pdev->irq;
2861 priv->irq = 0; 2653 priv->irq = 0;
@@ -2888,7 +2680,7 @@ static int rtl8192_pci_probe(struct pci_dev *pdev,
2888 RT_TRACE(COMP_INIT, "dev name: %s\n", dev->name); 2680 RT_TRACE(COMP_INIT, "dev name: %s\n", dev->name);
2889 2681
2890 if (priv->polling_timer_on == 0) 2682 if (priv->polling_timer_on == 0)
2891 check_rfctrl_gpio_timer((unsigned long)dev); 2683 rtl92e_check_rfctrl_gpio_timer((unsigned long)dev);
2892 2684
2893 RT_TRACE(COMP_INIT, "Driver probe completed\n"); 2685 RT_TRACE(COMP_INIT, "Driver probe completed\n");
2894 return 0; 2686 return 0;
@@ -2896,12 +2688,12 @@ static int rtl8192_pci_probe(struct pci_dev *pdev,
2896err_free_irq: 2688err_free_irq:
2897 free_irq(dev->irq, dev); 2689 free_irq(dev->irq, dev);
2898 priv->irq = 0; 2690 priv->irq = 0;
2691err_unmap:
2692 iounmap((void __iomem *)ioaddr);
2899err_rel_mem: 2693err_rel_mem:
2900 release_mem_region(pmem_start, pmem_len); 2694 release_mem_region(pmem_start, pmem_len);
2901err_rel_rtllib: 2695err_rel_rtllib:
2902 free_rtllib(dev); 2696 free_rtllib(dev);
2903
2904 DMESG("wlan driver load failed\n");
2905err_pci_disable: 2697err_pci_disable:
2906 pci_disable_device(pdev); 2698 pci_disable_device(pdev);
2907 return err; 2699 return err;
@@ -2922,7 +2714,7 @@ static void rtl8192_pci_disconnect(struct pci_dev *pdev)
2922 cancel_delayed_work(&priv->gpio_change_rf_wq); 2714 cancel_delayed_work(&priv->gpio_change_rf_wq);
2923 priv->polling_timer_on = 0; 2715 priv->polling_timer_on = 0;
2924 rtl8192_down(dev, true); 2716 rtl8192_down(dev, true);
2925 deinit_hal_dm(dev); 2717 rtl92e_dm_deinit(dev);
2926 if (priv->pFirmware) { 2718 if (priv->pFirmware) {
2927 vfree(priv->pFirmware); 2719 vfree(priv->pFirmware);
2928 priv->pFirmware = NULL; 2720 priv->pFirmware = NULL;
@@ -2952,7 +2744,7 @@ static void rtl8192_pci_disconnect(struct pci_dev *pdev)
2952 RT_TRACE(COMP_DOWN, "wlan driver removed\n"); 2744 RT_TRACE(COMP_DOWN, "wlan driver removed\n");
2953} 2745}
2954 2746
2955bool NicIFEnableNIC(struct net_device *dev) 2747bool rtl92e_enable_nic(struct net_device *dev)
2956{ 2748{
2957 bool init_status = true; 2749 bool init_status = true;
2958 struct r8192_priv *priv = rtllib_priv(dev); 2750 struct r8192_priv *priv = rtllib_priv(dev);
@@ -2977,12 +2769,12 @@ bool NicIFEnableNIC(struct net_device *dev)
2977 RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC); 2769 RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
2978 priv->bfirst_init = false; 2770 priv->bfirst_init = false;
2979 2771
2980 rtl8192_irq_enable(dev); 2772 rtl92e_irq_enable(dev);
2981 priv->bdisable_nic = false; 2773 priv->bdisable_nic = false;
2982 RT_TRACE(COMP_PS, "<===========%s()\n", __func__); 2774 RT_TRACE(COMP_PS, "<===========%s()\n", __func__);
2983 return init_status; 2775 return init_status;
2984} 2776}
2985bool NicIFDisableNIC(struct net_device *dev) 2777bool rtl92e_disable_nic(struct net_device *dev)
2986{ 2778{
2987 struct r8192_priv *priv = rtllib_priv(dev); 2779 struct r8192_priv *priv = rtllib_priv(dev);
2988 u8 tmp_state = 0; 2780 u8 tmp_state = 0;
@@ -2993,7 +2785,7 @@ bool NicIFDisableNIC(struct net_device *dev)
2993 rtllib_softmac_stop_protocol(priv->rtllib, 0, false); 2785 rtllib_softmac_stop_protocol(priv->rtllib, 0, false);
2994 priv->rtllib->state = tmp_state; 2786 priv->rtllib->state = tmp_state;
2995 rtl8192_cancel_deferred_work(priv); 2787 rtl8192_cancel_deferred_work(priv);
2996 rtl8192_irq_disable(dev); 2788 rtl92e_irq_disable(dev);
2997 2789
2998 priv->ops->stop_adapter(dev, false); 2790 priv->ops->stop_adapter(dev, false);
2999 RT_TRACE(COMP_PS, "<=========%s()\n", __func__); 2791 RT_TRACE(COMP_PS, "<=========%s()\n", __func__);
@@ -3007,7 +2799,6 @@ static int __init rtl8192_pci_module_init(void)
3007 pr_info("Copyright (c) 2007-2008, Realsil Wlan Driver\n"); 2799 pr_info("Copyright (c) 2007-2008, Realsil Wlan Driver\n");
3008 2800
3009 if (0 != pci_register_driver(&rtl8192_pci_driver)) { 2801 if (0 != pci_register_driver(&rtl8192_pci_driver)) {
3010 DMESG("No device found");
3011 /*pci_unregister_driver (&rtl8192_pci_driver);*/ 2802 /*pci_unregister_driver (&rtl8192_pci_driver);*/
3012 return -ENODEV; 2803 return -ENODEV;
3013 } 2804 }
@@ -3021,7 +2812,7 @@ static void __exit rtl8192_pci_module_exit(void)
3021 RT_TRACE(COMP_DOWN, "Exiting"); 2812 RT_TRACE(COMP_DOWN, "Exiting");
3022} 2813}
3023 2814
3024void check_rfctrl_gpio_timer(unsigned long data) 2815void rtl92e_check_rfctrl_gpio_timer(unsigned long data)
3025{ 2816{
3026 struct r8192_priv *priv = rtllib_priv((struct net_device *)data); 2817 struct r8192_priv *priv = rtllib_priv((struct net_device *)data);
3027 2818
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_core.h b/drivers/staging/rtl8192e/rtl8192e/rtl_core.h
index 776d950655cb..cd948bb13840 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_core.h
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_core.h
@@ -578,84 +578,44 @@ struct r8192_priv {
578 578
579extern const struct ethtool_ops rtl819x_ethtool_ops; 579extern const struct ethtool_ops rtl819x_ethtool_ops;
580 580
581void rtl8192_tx_cmd(struct net_device *dev, struct sk_buff *skb); 581u8 rtl92e_readb(struct net_device *dev, int x);
582short rtl8192_tx(struct net_device *dev, struct sk_buff *skb); 582u32 rtl92e_readl(struct net_device *dev, int x);
583 583u16 rtl92e_readw(struct net_device *dev, int x);
584u8 read_nic_io_byte(struct net_device *dev, int x); 584void rtl92e_writeb(struct net_device *dev, int x, u8 y);
585u32 read_nic_io_dword(struct net_device *dev, int x); 585void rtl92e_writew(struct net_device *dev, int x, u16 y);
586u16 read_nic_io_word(struct net_device *dev, int x); 586void rtl92e_writel(struct net_device *dev, int x, u32 y);
587void write_nic_io_byte(struct net_device *dev, int x, u8 y);
588void write_nic_io_word(struct net_device *dev, int x, u16 y);
589void write_nic_io_dword(struct net_device *dev, int x, u32 y);
590
591u8 read_nic_byte(struct net_device *dev, int x);
592u32 read_nic_dword(struct net_device *dev, int x);
593u16 read_nic_word(struct net_device *dev, int x);
594void write_nic_byte(struct net_device *dev, int x, u8 y);
595void write_nic_word(struct net_device *dev, int x, u16 y);
596void write_nic_dword(struct net_device *dev, int x, u32 y);
597 587
598void force_pci_posting(struct net_device *dev); 588void force_pci_posting(struct net_device *dev);
599 589
600void rtl8192_rx_enable(struct net_device *); 590void rtl92e_rx_enable(struct net_device *);
601void rtl8192_tx_enable(struct net_device *); 591void rtl92e_tx_enable(struct net_device *);
602 592
603int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev); 593void rtl92e_hw_sleep_wq(void *data);
604void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, 594void rtl92e_commit(struct net_device *dev);
605 int rate); 595
606void rtl8192_data_hard_stop(struct net_device *dev); 596void rtl92e_check_rfctrl_gpio_timer(unsigned long data);
607void rtl8192_data_hard_resume(struct net_device *dev); 597
608void rtl8192_restart(void *data); 598void rtl92e_hw_wakeup_wq(void *data);
609void rtl819x_watchdog_wqcallback(void *data);
610void rtl8192_hw_sleep_wq(void *data);
611void watch_dog_timer_callback(unsigned long data);
612void rtl8192_irq_rx_tasklet(struct r8192_priv *priv);
613void rtl8192_irq_tx_tasklet(struct r8192_priv *priv);
614int rtl8192_down(struct net_device *dev, bool shutdownrf);
615int rtl8192_up(struct net_device *dev);
616void rtl8192_commit(struct net_device *dev);
617void rtl8192_set_chan(struct net_device *dev, short ch);
618
619void check_rfctrl_gpio_timer(unsigned long data);
620
621void rtl8192_hw_wakeup_wq(void *data);
622short rtl8192_pci_initdescring(struct net_device *dev);
623
624void rtl8192_cancel_deferred_work(struct r8192_priv *priv);
625
626int _rtl8192_up(struct net_device *dev, bool is_silent_reset);
627
628short rtl8192_is_tx_queue_empty(struct net_device *dev);
629void rtl8192_irq_disable(struct net_device *dev);
630
631void rtl8192_tx_timeout(struct net_device *dev);
632void rtl8192_pci_resetdescring(struct net_device *dev);
633void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode);
634void rtl8192_irq_enable(struct net_device *dev);
635void rtl8192_config_rate(struct net_device *dev, u16 *rate_config);
636void rtl8192_update_cap(struct net_device *dev, u16 cap);
637void rtl8192_irq_disable(struct net_device *dev);
638
639void rtl819x_UpdateRxPktTimeStamp(struct net_device *dev,
640 struct rtllib_rx_stats *stats);
641long rtl819x_translate_todbm(struct r8192_priv *priv, u8 signal_strength_index);
642void rtl819x_update_rxsignalstatistics8190pci(struct r8192_priv *priv,
643 struct rtllib_rx_stats *pprevious_stats);
644u8 rtl819x_evm_dbtopercentage(char value);
645void rtl819x_process_cck_rxpathsel(struct r8192_priv *priv,
646 struct rtllib_rx_stats *pprevious_stats);
647u8 rtl819x_query_rxpwrpercentage(char antpower);
648void rtl8192_record_rxdesc_forlateruse(struct rtllib_rx_stats *psrc_stats,
649 struct rtllib_rx_stats *ptarget_stats);
650bool NicIFEnableNIC(struct net_device *dev);
651bool NicIFDisableNIC(struct net_device *dev);
652
653bool MgntActSet_RF_State(struct net_device *dev,
654 enum rt_rf_power_state StateToSet,
655 RT_RF_CHANGE_SOURCE ChangeSource,
656 bool ProtectOrNot);
657void ActUpdateChannelAccessSetting(struct net_device *dev,
658 enum wireless_mode WirelessMode,
659 struct channel_access_setting *ChnlAccessSetting);
660 599
600void rtl92e_reset_desc_ring(struct net_device *dev);
601void rtl92e_set_wireless_mode(struct net_device *dev, u8 wireless_mode);
602void rtl92e_irq_enable(struct net_device *dev);
603void rtl92e_config_rate(struct net_device *dev, u16 *rate_config);
604void rtl92e_irq_disable(struct net_device *dev);
605
606void rtl92e_update_rx_pkt_timestamp(struct net_device *dev,
607 struct rtllib_rx_stats *stats);
608long rtl92e_translate_to_dbm(struct r8192_priv *priv, u8 signal_strength_index);
609void rtl92e_update_rx_statistics(struct r8192_priv *priv,
610 struct rtllib_rx_stats *pprevious_stats);
611u8 rtl92e_evm_db_to_percent(char value);
612u8 rtl92e_rx_db_to_percent(char antpower);
613void rtl92e_copy_mpdu_stats(struct rtllib_rx_stats *psrc_stats,
614 struct rtllib_rx_stats *ptarget_stats);
615bool rtl92e_enable_nic(struct net_device *dev);
616bool rtl92e_disable_nic(struct net_device *dev);
617
618bool rtl92e_set_rf_state(struct net_device *dev,
619 enum rt_rf_power_state StateToSet,
620 RT_RF_CHANGE_SOURCE ChangeSource);
661#endif 621#endif
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
index 3de7cc549794..1a0c690bfa07 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
@@ -58,9 +58,6 @@ static u32 edca_setting_UL[HT_IOT_PEER_MAX] = {
58 0x5e4332 58 0x5e4332
59}; 59};
60 60
61#define RTK_UL_EDCA 0xa44f
62#define RTK_DL_EDCA 0x5e4322
63
64const u32 dm_tx_bb_gain[TxBBGainTableLength] = { 61const u32 dm_tx_bb_gain[TxBBGainTableLength] = {
65 0x7f8001fe, /* 12 dB */ 62 0x7f8001fe, /* 12 dB */
66 0x788001e2, /* 11 dB */ 63 0x788001e2, /* 11 dB */
@@ -213,6 +210,9 @@ static void dm_deInit_fsync(struct net_device *dev);
213 210
214static void dm_check_txrateandretrycount(struct net_device *dev); 211static void dm_check_txrateandretrycount(struct net_device *dev);
215static void dm_check_ac_dc_power(struct net_device *dev); 212static void dm_check_ac_dc_power(struct net_device *dev);
213static void dm_check_fsync(struct net_device *dev);
214static void dm_CheckRfCtrlGPIO(void *data);
215static void dm_fsync_timer_callback(unsigned long data);
216 216
217/*---------------------Define local function prototype-----------------------*/ 217/*---------------------Define local function prototype-----------------------*/
218 218
@@ -224,7 +224,7 @@ static void dm_send_rssi_tofw(struct net_device *dev);
224static void dm_ctstoself(struct net_device *dev); 224static void dm_ctstoself(struct net_device *dev);
225/*---------------------------Define function prototype------------------------*/ 225/*---------------------------Define function prototype------------------------*/
226 226
227void init_hal_dm(struct net_device *dev) 227void rtl92e_dm_init(struct net_device *dev)
228{ 228{
229 struct r8192_priv *priv = rtllib_priv(dev); 229 struct r8192_priv *priv = rtllib_priv(dev);
230 230
@@ -234,10 +234,10 @@ void init_hal_dm(struct net_device *dev)
234 234
235 dm_init_dynamic_txpower(dev); 235 dm_init_dynamic_txpower(dev);
236 236
237 init_rate_adaptive(dev); 237 rtl92e_init_adaptive_rate(dev);
238 238
239 dm_dig_init(dev); 239 dm_dig_init(dev);
240 dm_init_edca_turbo(dev); 240 rtl92e_dm_init_edca_turbo(dev);
241 dm_init_bandwidth_autoswitch(dev); 241 dm_init_bandwidth_autoswitch(dev);
242 dm_init_fsync(dev); 242 dm_init_fsync(dev);
243 dm_init_rxpath_selection(dev); 243 dm_init_rxpath_selection(dev);
@@ -249,14 +249,14 @@ void init_hal_dm(struct net_device *dev)
249 (void *)dm_CheckRfCtrlGPIO, dev); 249 (void *)dm_CheckRfCtrlGPIO, dev);
250} 250}
251 251
252void deinit_hal_dm(struct net_device *dev) 252void rtl92e_dm_deinit(struct net_device *dev)
253{ 253{
254 254
255 dm_deInit_fsync(dev); 255 dm_deInit_fsync(dev);
256 256
257} 257}
258 258
259void hal_dm_watchdog(struct net_device *dev) 259void rtl92e_dm_watchdog(struct net_device *dev)
260{ 260{
261 struct r8192_priv *priv = rtllib_priv(dev); 261 struct r8192_priv *priv = rtllib_priv(dev);
262 262
@@ -307,7 +307,7 @@ static void dm_check_ac_dc_power(struct net_device *dev)
307}; 307};
308 308
309 309
310void init_rate_adaptive(struct net_device *dev) 310void rtl92e_init_adaptive_rate(struct net_device *dev)
311{ 311{
312 312
313 struct r8192_priv *priv = rtllib_priv(dev); 313 struct r8192_priv *priv = rtllib_priv(dev);
@@ -444,7 +444,7 @@ static void dm_check_rate_adaptive(struct net_device *dev)
444 if (priv->rtllib->GetHalfNmodeSupportByAPsHandler(dev)) 444 if (priv->rtllib->GetHalfNmodeSupportByAPsHandler(dev))
445 targetRATR &= 0xf00fffff; 445 targetRATR &= 0xf00fffff;
446 446
447 currentRATR = read_nic_dword(dev, RATR0); 447 currentRATR = rtl92e_readl(dev, RATR0);
448 if (targetRATR != currentRATR) { 448 if (targetRATR != currentRATR) {
449 u32 ratr_value; 449 u32 ratr_value;
450 450
@@ -454,8 +454,8 @@ static void dm_check_rate_adaptive(struct net_device *dev)
454 currentRATR, targetRATR); 454 currentRATR, targetRATR);
455 if (priv->rf_type == RF_1T2R) 455 if (priv->rf_type == RF_1T2R)
456 ratr_value &= ~(RATE_ALL_OFDM_2SS); 456 ratr_value &= ~(RATE_ALL_OFDM_2SS);
457 write_nic_dword(dev, RATR0, ratr_value); 457 rtl92e_writel(dev, RATR0, ratr_value);
458 write_nic_byte(dev, UFWP, 1); 458 rtl92e_writeb(dev, UFWP, 1);
459 459
460 pra->last_ratr = targetRATR; 460 pra->last_ratr = targetRATR;
461 } 461 }
@@ -561,40 +561,40 @@ static void dm_tx_update_tssi_weak_signal(struct net_device *dev, u8 RF_Type)
561 p->rfa_txpowertrackingindex--; 561 p->rfa_txpowertrackingindex--;
562 if (p->rfa_txpowertrackingindex_real > 4) { 562 if (p->rfa_txpowertrackingindex_real > 4) {
563 p->rfa_txpowertrackingindex_real--; 563 p->rfa_txpowertrackingindex_real--;
564 rtl8192_setBBreg(dev, rOFDM0_XATxIQImbalance, 564 rtl92e_set_bb_reg(dev, rOFDM0_XATxIQImbalance,
565 bMaskDWord, 565 bMaskDWord,
566 dm_tx_bb_gain[p->rfa_txpowertrackingindex_real]); 566 dm_tx_bb_gain[p->rfa_txpowertrackingindex_real]);
567 } 567 }
568 568
569 p->rfc_txpowertrackingindex--; 569 p->rfc_txpowertrackingindex--;
570 if (p->rfc_txpowertrackingindex_real > 4) { 570 if (p->rfc_txpowertrackingindex_real > 4) {
571 p->rfc_txpowertrackingindex_real--; 571 p->rfc_txpowertrackingindex_real--;
572 rtl8192_setBBreg(dev, 572 rtl92e_set_bb_reg(dev,
573 rOFDM0_XCTxIQImbalance, 573 rOFDM0_XCTxIQImbalance,
574 bMaskDWord, 574 bMaskDWord,
575 dm_tx_bb_gain[p->rfc_txpowertrackingindex_real]); 575 dm_tx_bb_gain[p->rfc_txpowertrackingindex_real]);
576 } 576 }
577 } else { 577 } else {
578 rtl8192_setBBreg(dev, rOFDM0_XATxIQImbalance, 578 rtl92e_set_bb_reg(dev, rOFDM0_XATxIQImbalance,
579 bMaskDWord, 579 bMaskDWord,
580 dm_tx_bb_gain[4]); 580 dm_tx_bb_gain[4]);
581 rtl8192_setBBreg(dev, 581 rtl92e_set_bb_reg(dev,
582 rOFDM0_XCTxIQImbalance, 582 rOFDM0_XCTxIQImbalance,
583 bMaskDWord, dm_tx_bb_gain[4]); 583 bMaskDWord, dm_tx_bb_gain[4]);
584 } 584 }
585 } else { 585 } else {
586 if (p->rfa_txpowertrackingindex > 0) { 586 if (p->rfa_txpowertrackingindex > 0) {
587 p->rfa_txpowertrackingindex--; 587 p->rfa_txpowertrackingindex--;
588 if (p->rfa_txpowertrackingindex_real > 4) { 588 if (p->rfa_txpowertrackingindex_real > 4) {
589 p->rfa_txpowertrackingindex_real--; 589 p->rfa_txpowertrackingindex_real--;
590 rtl8192_setBBreg(dev, 590 rtl92e_set_bb_reg(dev,
591 rOFDM0_XATxIQImbalance, 591 rOFDM0_XATxIQImbalance,
592 bMaskDWord, 592 bMaskDWord,
593 dm_tx_bb_gain[p->rfa_txpowertrackingindex_real]); 593 dm_tx_bb_gain[p->rfa_txpowertrackingindex_real]);
594 } 594 }
595 } else { 595 } else {
596 rtl8192_setBBreg(dev, rOFDM0_XATxIQImbalance, 596 rtl92e_set_bb_reg(dev, rOFDM0_XATxIQImbalance,
597 bMaskDWord, dm_tx_bb_gain[4]); 597 bMaskDWord, dm_tx_bb_gain[4]);
598 } 598 }
599 } 599 }
600} 600}
@@ -608,36 +608,33 @@ static void dm_tx_update_tssi_strong_signal(struct net_device *dev, u8 RF_Type)
608 (p->rfc_txpowertrackingindex < TxBBGainTableLength - 1)) { 608 (p->rfc_txpowertrackingindex < TxBBGainTableLength - 1)) {
609 p->rfa_txpowertrackingindex++; 609 p->rfa_txpowertrackingindex++;
610 p->rfa_txpowertrackingindex_real++; 610 p->rfa_txpowertrackingindex_real++;
611 rtl8192_setBBreg(dev, 611 rtl92e_set_bb_reg(dev, rOFDM0_XATxIQImbalance,
612 rOFDM0_XATxIQImbalance, 612 bMaskDWord,
613 bMaskDWord, 613 dm_tx_bb_gain[p->rfa_txpowertrackingindex_real]);
614 dm_tx_bb_gain[p->rfa_txpowertrackingindex_real]);
615 p->rfc_txpowertrackingindex++; 614 p->rfc_txpowertrackingindex++;
616 p->rfc_txpowertrackingindex_real++; 615 p->rfc_txpowertrackingindex_real++;
617 rtl8192_setBBreg(dev, 616 rtl92e_set_bb_reg(dev, rOFDM0_XCTxIQImbalance,
618 rOFDM0_XCTxIQImbalance, 617 bMaskDWord,
619 bMaskDWord, 618 dm_tx_bb_gain[p->rfc_txpowertrackingindex_real]);
620 dm_tx_bb_gain[p->rfc_txpowertrackingindex_real]);
621 } else { 619 } else {
622 rtl8192_setBBreg(dev, 620 rtl92e_set_bb_reg(dev, rOFDM0_XATxIQImbalance,
623 rOFDM0_XATxIQImbalance, 621 bMaskDWord,
624 bMaskDWord, 622 dm_tx_bb_gain[TxBBGainTableLength - 1]);
625 dm_tx_bb_gain[TxBBGainTableLength - 1]); 623 rtl92e_set_bb_reg(dev, rOFDM0_XCTxIQImbalance,
626 rtl8192_setBBreg(dev, rOFDM0_XCTxIQImbalance, 624 bMaskDWord,
627 bMaskDWord, 625 dm_tx_bb_gain[TxBBGainTableLength - 1]);
628 dm_tx_bb_gain[TxBBGainTableLength - 1]);
629 } 626 }
630 } else { 627 } else {
631 if (p->rfa_txpowertrackingindex < (TxBBGainTableLength - 1)) { 628 if (p->rfa_txpowertrackingindex < (TxBBGainTableLength - 1)) {
632 p->rfa_txpowertrackingindex++; 629 p->rfa_txpowertrackingindex++;
633 p->rfa_txpowertrackingindex_real++; 630 p->rfa_txpowertrackingindex_real++;
634 rtl8192_setBBreg(dev, rOFDM0_XATxIQImbalance, 631 rtl92e_set_bb_reg(dev, rOFDM0_XATxIQImbalance,
635 bMaskDWord, 632 bMaskDWord,
636 dm_tx_bb_gain[p->rfa_txpowertrackingindex_real]); 633 dm_tx_bb_gain[p->rfa_txpowertrackingindex_real]);
637 } else { 634 } else {
638 rtl8192_setBBreg(dev, rOFDM0_XATxIQImbalance, 635 rtl92e_set_bb_reg(dev, rOFDM0_XATxIQImbalance,
639 bMaskDWord, 636 bMaskDWord,
640 dm_tx_bb_gain[TxBBGainTableLength - 1]); 637 dm_tx_bb_gain[TxBBGainTableLength - 1]);
641 } 638 }
642 } 639 }
643} 640}
@@ -656,8 +653,8 @@ static void dm_TXPowerTrackingCallback_TSSI(struct net_device *dev)
656 u32 delta = 0; 653 u32 delta = 0;
657 654
658 RT_TRACE(COMP_POWER_TRACKING, "%s()\n", __func__); 655 RT_TRACE(COMP_POWER_TRACKING, "%s()\n", __func__);
659 write_nic_byte(dev, Pw_Track_Flag, 0); 656 rtl92e_writeb(dev, Pw_Track_Flag, 0);
660 write_nic_byte(dev, FW_Busy_Flag, 0); 657 rtl92e_writeb(dev, FW_Busy_Flag, 0);
661 priv->rtllib->bdynamic_txpower_enable = false; 658 priv->rtllib->bdynamic_txpower_enable = false;
662 bHighpowerstate = priv->bDynamicTxHighPower; 659 bHighpowerstate = priv->bDynamicTxHighPower;
663 660
@@ -674,12 +671,11 @@ static void dm_TXPowerTrackingCallback_TSSI(struct net_device *dev)
674 tx_cmd.Op = TXCMD_SET_TX_PWR_TRACKING; 671 tx_cmd.Op = TXCMD_SET_TX_PWR_TRACKING;
675 tx_cmd.Length = 4; 672 tx_cmd.Length = 4;
676 tx_cmd.Value = Value; 673 tx_cmd.Value = Value;
677 cmpk_message_handle_tx(dev, (u8 *)&tx_cmd, 674 rtl92e_send_cmd_pkt(dev, (u8 *)&tx_cmd, DESC_PACKET_TYPE_INIT,
678 DESC_PACKET_TYPE_INIT, 675 sizeof(struct dcmd_txcmd));
679 sizeof(struct dcmd_txcmd));
680 mdelay(1); 676 mdelay(1);
681 for (i = 0; i <= 30; i++) { 677 for (i = 0; i <= 30; i++) {
682 Pwr_Flag = read_nic_byte(dev, Pw_Track_Flag); 678 Pwr_Flag = rtl92e_readb(dev, Pw_Track_Flag);
683 679
684 if (Pwr_Flag == 0) { 680 if (Pwr_Flag == 0) {
685 mdelay(1); 681 mdelay(1);
@@ -687,35 +683,35 @@ static void dm_TXPowerTrackingCallback_TSSI(struct net_device *dev)
687 if (priv->bResetInProgress) { 683 if (priv->bResetInProgress) {
688 RT_TRACE(COMP_POWER_TRACKING, 684 RT_TRACE(COMP_POWER_TRACKING,
689 "we are in silent reset progress, so return\n"); 685 "we are in silent reset progress, so return\n");
690 write_nic_byte(dev, Pw_Track_Flag, 0); 686 rtl92e_writeb(dev, Pw_Track_Flag, 0);
691 write_nic_byte(dev, FW_Busy_Flag, 0); 687 rtl92e_writeb(dev, FW_Busy_Flag, 0);
692 return; 688 return;
693 } 689 }
694 if (priv->rtllib->eRFPowerState != eRfOn) { 690 if (priv->rtllib->eRFPowerState != eRfOn) {
695 RT_TRACE(COMP_POWER_TRACKING, 691 RT_TRACE(COMP_POWER_TRACKING,
696 "we are in power save, so return\n"); 692 "we are in power save, so return\n");
697 write_nic_byte(dev, Pw_Track_Flag, 0); 693 rtl92e_writeb(dev, Pw_Track_Flag, 0);
698 write_nic_byte(dev, FW_Busy_Flag, 0); 694 rtl92e_writeb(dev, FW_Busy_Flag, 0);
699 return; 695 return;
700 } 696 }
701 697
702 continue; 698 continue;
703 } 699 }
704 700
705 Avg_TSSI_Meas = read_nic_word(dev, Tssi_Mea_Value); 701 Avg_TSSI_Meas = rtl92e_readw(dev, Tssi_Mea_Value);
706 702
707 if (Avg_TSSI_Meas == 0) { 703 if (Avg_TSSI_Meas == 0) {
708 write_nic_byte(dev, Pw_Track_Flag, 0); 704 rtl92e_writeb(dev, Pw_Track_Flag, 0);
709 write_nic_byte(dev, FW_Busy_Flag, 0); 705 rtl92e_writeb(dev, FW_Busy_Flag, 0);
710 return; 706 return;
711 } 707 }
712 708
713 for (k = 0; k < 5; k++) { 709 for (k = 0; k < 5; k++) {
714 if (k != 4) 710 if (k != 4)
715 tmp_report[k] = read_nic_byte(dev, 711 tmp_report[k] = rtl92e_readb(dev,
716 Tssi_Report_Value1+k); 712 Tssi_Report_Value1+k);
717 else 713 else
718 tmp_report[k] = read_nic_byte(dev, 714 tmp_report[k] = rtl92e_readb(dev,
719 Tssi_Report_Value2); 715 Tssi_Report_Value2);
720 716
721 RT_TRACE(COMP_POWER_TRACKING, 717 RT_TRACE(COMP_POWER_TRACKING,
@@ -729,7 +725,7 @@ static void dm_TXPowerTrackingCallback_TSSI(struct net_device *dev)
729 } 725 }
730 726
731 if (viviflag) { 727 if (viviflag) {
732 write_nic_byte(dev, Pw_Track_Flag, 0); 728 rtl92e_writeb(dev, Pw_Track_Flag, 0);
733 viviflag = false; 729 viviflag = false;
734 RT_TRACE(COMP_POWER_TRACKING, 730 RT_TRACE(COMP_POWER_TRACKING,
735 "we filted this data\n"); 731 "we filted this data\n");
@@ -756,8 +752,8 @@ static void dm_TXPowerTrackingCallback_TSSI(struct net_device *dev)
756 752
757 if (delta <= E_FOR_TX_POWER_TRACK) { 753 if (delta <= E_FOR_TX_POWER_TRACK) {
758 priv->rtllib->bdynamic_txpower_enable = true; 754 priv->rtllib->bdynamic_txpower_enable = true;
759 write_nic_byte(dev, Pw_Track_Flag, 0); 755 rtl92e_writeb(dev, Pw_Track_Flag, 0);
760 write_nic_byte(dev, FW_Busy_Flag, 0); 756 rtl92e_writeb(dev, FW_Busy_Flag, 0);
761 RT_TRACE(COMP_POWER_TRACKING, 757 RT_TRACE(COMP_POWER_TRACKING,
762 "tx power track is done\n"); 758 "tx power track is done\n");
763 RT_TRACE(COMP_POWER_TRACKING, 759 RT_TRACE(COMP_POWER_TRACKING,
@@ -806,12 +802,12 @@ static void dm_TXPowerTrackingCallback_TSSI(struct net_device *dev)
806 if (priv->rtllib->current_network.channel == 14 && 802 if (priv->rtllib->current_network.channel == 14 &&
807 !priv->bcck_in_ch14) { 803 !priv->bcck_in_ch14) {
808 priv->bcck_in_ch14 = true; 804 priv->bcck_in_ch14 = true;
809 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14); 805 rtl92e_dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
810 } else if (priv->rtllib->current_network.channel != 14 && priv->bcck_in_ch14) { 806 } else if (priv->rtllib->current_network.channel != 14 && priv->bcck_in_ch14) {
811 priv->bcck_in_ch14 = false; 807 priv->bcck_in_ch14 = false;
812 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14); 808 rtl92e_dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
813 } else 809 } else
814 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14); 810 rtl92e_dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
815 } 811 }
816 RT_TRACE(COMP_POWER_TRACKING, 812 RT_TRACE(COMP_POWER_TRACKING,
817 "priv->rfa_txpowertrackingindex = %d\n", 813 "priv->rfa_txpowertrackingindex = %d\n",
@@ -829,23 +825,23 @@ static void dm_TXPowerTrackingCallback_TSSI(struct net_device *dev)
829 if (priv->CCKPresentAttentuation_difference <= -12 || 825 if (priv->CCKPresentAttentuation_difference <= -12 ||
830 priv->CCKPresentAttentuation_difference >= 24) { 826 priv->CCKPresentAttentuation_difference >= 24) {
831 priv->rtllib->bdynamic_txpower_enable = true; 827 priv->rtllib->bdynamic_txpower_enable = true;
832 write_nic_byte(dev, Pw_Track_Flag, 0); 828 rtl92e_writeb(dev, Pw_Track_Flag, 0);
833 write_nic_byte(dev, FW_Busy_Flag, 0); 829 rtl92e_writeb(dev, FW_Busy_Flag, 0);
834 RT_TRACE(COMP_POWER_TRACKING, 830 RT_TRACE(COMP_POWER_TRACKING,
835 "tx power track--->limited\n"); 831 "tx power track--->limited\n");
836 return; 832 return;
837 } 833 }
838 834
839 write_nic_byte(dev, Pw_Track_Flag, 0); 835 rtl92e_writeb(dev, Pw_Track_Flag, 0);
840 Avg_TSSI_Meas_from_driver = 0; 836 Avg_TSSI_Meas_from_driver = 0;
841 for (k = 0; k < 5; k++) 837 for (k = 0; k < 5; k++)
842 tmp_report[k] = 0; 838 tmp_report[k] = 0;
843 break; 839 break;
844 } 840 }
845 write_nic_byte(dev, FW_Busy_Flag, 0); 841 rtl92e_writeb(dev, FW_Busy_Flag, 0);
846 } 842 }
847 priv->rtllib->bdynamic_txpower_enable = true; 843 priv->rtllib->bdynamic_txpower_enable = true;
848 write_nic_byte(dev, Pw_Track_Flag, 0); 844 rtl92e_writeb(dev, Pw_Track_Flag, 0);
849} 845}
850 846
851static void dm_TXPowerTrackingCallback_ThermalMeter(struct net_device *dev) 847static void dm_TXPowerTrackingCallback_ThermalMeter(struct net_device *dev)
@@ -857,8 +853,8 @@ static void dm_TXPowerTrackingCallback_ThermalMeter(struct net_device *dev)
857 int i = 0, CCKSwingNeedUpdate = 0; 853 int i = 0, CCKSwingNeedUpdate = 0;
858 854
859 if (!priv->btxpower_trackingInit) { 855 if (!priv->btxpower_trackingInit) {
860 tmpRegA = rtl8192_QueryBBReg(dev, rOFDM0_XATxIQImbalance, 856 tmpRegA = rtl92e_get_bb_reg(dev, rOFDM0_XATxIQImbalance,
861 bMaskDWord); 857 bMaskDWord);
862 for (i = 0; i < OFDM_Table_Length; i++) { 858 for (i = 0; i < OFDM_Table_Length; i++) {
863 if (tmpRegA == OFDMSwingTable[i]) { 859 if (tmpRegA == OFDMSwingTable[i]) {
864 priv->OFDM_index[0] = (u8)i; 860 priv->OFDM_index[0] = (u8)i;
@@ -869,7 +865,7 @@ static void dm_TXPowerTrackingCallback_ThermalMeter(struct net_device *dev)
869 } 865 }
870 } 866 }
871 867
872 TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2); 868 TempCCk = rtl92e_get_bb_reg(dev, rCCK0_TxFilter1, bMaskByte2);
873 for (i = 0; i < CCK_Table_length; i++) { 869 for (i = 0; i < CCK_Table_length; i++) {
874 if (TempCCk == (u32)CCKSwingTable_Ch1_Ch13[i][0]) { 870 if (TempCCk == (u32)CCKSwingTable_Ch1_Ch13[i][0]) {
875 priv->CCK_index = (u8) i; 871 priv->CCK_index = (u8) i;
@@ -884,7 +880,7 @@ static void dm_TXPowerTrackingCallback_ThermalMeter(struct net_device *dev)
884 return; 880 return;
885 } 881 }
886 882
887 tmpRegA = rtl8192_phy_QueryRFReg(dev, RF90_PATH_A, 0x12, 0x078); 883 tmpRegA = rtl92e_get_rf_reg(dev, RF90_PATH_A, 0x12, 0x078);
888 RT_TRACE(COMP_POWER_TRACKING, "Readback ThermalMeterA = %d\n", tmpRegA); 884 RT_TRACE(COMP_POWER_TRACKING, "Readback ThermalMeterA = %d\n", tmpRegA);
889 if (tmpRegA < 3 || tmpRegA > 13) 885 if (tmpRegA < 3 || tmpRegA > 13)
890 return; 886 return;
@@ -939,11 +935,11 @@ static void dm_TXPowerTrackingCallback_ThermalMeter(struct net_device *dev)
939 } 935 }
940 936
941 if (CCKSwingNeedUpdate) 937 if (CCKSwingNeedUpdate)
942 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14); 938 rtl92e_dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
943 if (priv->OFDM_index[0] != tmpOFDMindex) { 939 if (priv->OFDM_index[0] != tmpOFDMindex) {
944 priv->OFDM_index[0] = tmpOFDMindex; 940 priv->OFDM_index[0] = tmpOFDMindex;
945 rtl8192_setBBreg(dev, rOFDM0_XATxIQImbalance, bMaskDWord, 941 rtl92e_set_bb_reg(dev, rOFDM0_XATxIQImbalance, bMaskDWord,
946 OFDMSwingTable[priv->OFDM_index[0]]); 942 OFDMSwingTable[priv->OFDM_index[0]]);
947 RT_TRACE(COMP_POWER_TRACKING, "Update OFDMSwing[%d] = 0x%x\n", 943 RT_TRACE(COMP_POWER_TRACKING, "Update OFDMSwing[%d] = 0x%x\n",
948 priv->OFDM_index[0], 944 priv->OFDM_index[0],
949 OFDMSwingTable[priv->OFDM_index[0]]); 945 OFDMSwingTable[priv->OFDM_index[0]]);
@@ -951,7 +947,7 @@ static void dm_TXPowerTrackingCallback_ThermalMeter(struct net_device *dev)
951 priv->txpower_count = 0; 947 priv->txpower_count = 0;
952} 948}
953 949
954void dm_txpower_trackingcallback(void *data) 950void rtl92e_dm_txpower_tracking_wq(void *data)
955{ 951{
956 struct r8192_priv *priv = container_of_dwork_rsl(data, 952 struct r8192_priv *priv = container_of_dwork_rsl(data,
957 struct r8192_priv, txpower_tracking_wq); 953 struct r8192_priv, txpower_tracking_wq);
@@ -989,7 +985,7 @@ static void dm_InitializeTXPowerTracking_ThermalMeter(struct net_device *dev)
989 priv->btxpower_tracking); 985 priv->btxpower_tracking);
990} 986}
991 987
992void dm_initialize_txpower_tracking(struct net_device *dev) 988void rtl92e_dm_init_txpower_tracking(struct net_device *dev)
993{ 989{
994 struct r8192_priv *priv = rtllib_priv(dev); 990 struct r8192_priv *priv = rtllib_priv(dev);
995 991
@@ -1005,7 +1001,7 @@ static void dm_CheckTXPowerTracking_TSSI(struct net_device *dev)
1005 static u32 tx_power_track_counter; 1001 static u32 tx_power_track_counter;
1006 1002
1007 RT_TRACE(COMP_POWER_TRACKING, "%s()\n", __func__); 1003 RT_TRACE(COMP_POWER_TRACKING, "%s()\n", __func__);
1008 if (read_nic_byte(dev, 0x11e) == 1) 1004 if (rtl92e_readb(dev, 0x11e) == 1)
1009 return; 1005 return;
1010 if (!priv->btxpower_tracking) 1006 if (!priv->btxpower_tracking)
1011 return; 1007 return;
@@ -1039,10 +1035,10 @@ static void dm_CheckTXPowerTracking_ThermalMeter(struct net_device *dev)
1039 1035
1040 if (!TM_Trigger) { 1036 if (!TM_Trigger) {
1041 { 1037 {
1042 rtl8192_phy_SetRFReg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4d); 1038 rtl92e_set_rf_reg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4d);
1043 rtl8192_phy_SetRFReg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4f); 1039 rtl92e_set_rf_reg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4f);
1044 rtl8192_phy_SetRFReg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4d); 1040 rtl92e_set_rf_reg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4d);
1045 rtl8192_phy_SetRFReg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4f); 1041 rtl92e_set_rf_reg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4f);
1046 } 1042 }
1047 TM_Trigger = 1; 1043 TM_Trigger = 1;
1048 return; 1044 return;
@@ -1074,30 +1070,30 @@ static void dm_CCKTxPowerAdjust_TSSI(struct net_device *dev, bool bInCH14)
1074 TempVal = (u32)(dm_cck_tx_bb_gain[attenuation][0] + 1070 TempVal = (u32)(dm_cck_tx_bb_gain[attenuation][0] +
1075 (dm_cck_tx_bb_gain[attenuation][1] << 8)); 1071 (dm_cck_tx_bb_gain[attenuation][1] << 8));
1076 1072
1077 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal); 1073 rtl92e_set_bb_reg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
1078 TempVal = (u32)((dm_cck_tx_bb_gain[attenuation][2]) + 1074 TempVal = (u32)((dm_cck_tx_bb_gain[attenuation][2]) +
1079 (dm_cck_tx_bb_gain[attenuation][3] << 8) + 1075 (dm_cck_tx_bb_gain[attenuation][3] << 8) +
1080 (dm_cck_tx_bb_gain[attenuation][4] << 16)+ 1076 (dm_cck_tx_bb_gain[attenuation][4] << 16)+
1081 (dm_cck_tx_bb_gain[attenuation][5] << 24)); 1077 (dm_cck_tx_bb_gain[attenuation][5] << 24));
1082 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal); 1078 rtl92e_set_bb_reg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
1083 TempVal = (u32)(dm_cck_tx_bb_gain[attenuation][6] + 1079 TempVal = (u32)(dm_cck_tx_bb_gain[attenuation][6] +
1084 (dm_cck_tx_bb_gain[attenuation][7] << 8)); 1080 (dm_cck_tx_bb_gain[attenuation][7] << 8));
1085 1081
1086 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal); 1082 rtl92e_set_bb_reg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
1087 } else { 1083 } else {
1088 TempVal = (u32)((dm_cck_tx_bb_gain_ch14[attenuation][0]) + 1084 TempVal = (u32)((dm_cck_tx_bb_gain_ch14[attenuation][0]) +
1089 (dm_cck_tx_bb_gain_ch14[attenuation][1] << 8)); 1085 (dm_cck_tx_bb_gain_ch14[attenuation][1] << 8));
1090 1086
1091 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal); 1087 rtl92e_set_bb_reg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
1092 TempVal = (u32)((dm_cck_tx_bb_gain_ch14[attenuation][2]) + 1088 TempVal = (u32)((dm_cck_tx_bb_gain_ch14[attenuation][2]) +
1093 (dm_cck_tx_bb_gain_ch14[attenuation][3] << 8) + 1089 (dm_cck_tx_bb_gain_ch14[attenuation][3] << 8) +
1094 (dm_cck_tx_bb_gain_ch14[attenuation][4] << 16)+ 1090 (dm_cck_tx_bb_gain_ch14[attenuation][4] << 16)+
1095 (dm_cck_tx_bb_gain_ch14[attenuation][5] << 24)); 1091 (dm_cck_tx_bb_gain_ch14[attenuation][5] << 24));
1096 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal); 1092 rtl92e_set_bb_reg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
1097 TempVal = (u32)((dm_cck_tx_bb_gain_ch14[attenuation][6]) + 1093 TempVal = (u32)((dm_cck_tx_bb_gain_ch14[attenuation][6]) +
1098 (dm_cck_tx_bb_gain_ch14[attenuation][7] << 8)); 1094 (dm_cck_tx_bb_gain_ch14[attenuation][7] << 8));
1099 1095
1100 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal); 1096 rtl92e_set_bb_reg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
1101 } 1097 }
1102} 1098}
1103 1099
@@ -1111,7 +1107,7 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev,
1111 if (!bInCH14) { 1107 if (!bInCH14) {
1112 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][0] + 1108 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][0] +
1113 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][1] << 8); 1109 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][1] << 8);
1114 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal); 1110 rtl92e_set_bb_reg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
1115 RT_TRACE(COMP_POWER_TRACKING, 1111 RT_TRACE(COMP_POWER_TRACKING,
1116 "CCK not chnl 14, reg 0x%x = 0x%x\n", rCCK0_TxFilter1, 1112 "CCK not chnl 14, reg 0x%x = 0x%x\n", rCCK0_TxFilter1,
1117 TempVal); 1113 TempVal);
@@ -1119,14 +1115,14 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev,
1119 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][3] << 8) + 1115 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][3] << 8) +
1120 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][4] << 16)+ 1116 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][4] << 16)+
1121 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][5] << 24); 1117 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][5] << 24);
1122 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal); 1118 rtl92e_set_bb_reg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
1123 RT_TRACE(COMP_POWER_TRACKING, 1119 RT_TRACE(COMP_POWER_TRACKING,
1124 "CCK not chnl 14, reg 0x%x = 0x%x\n", rCCK0_TxFilter2, 1120 "CCK not chnl 14, reg 0x%x = 0x%x\n", rCCK0_TxFilter2,
1125 TempVal); 1121 TempVal);
1126 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][6] + 1122 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][6] +
1127 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][7] << 8); 1123 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][7] << 8);
1128 1124
1129 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal); 1125 rtl92e_set_bb_reg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
1130 RT_TRACE(COMP_POWER_TRACKING, 1126 RT_TRACE(COMP_POWER_TRACKING,
1131 "CCK not chnl 14, reg 0x%x = 0x%x\n", rCCK0_DebugPort, 1127 "CCK not chnl 14, reg 0x%x = 0x%x\n", rCCK0_DebugPort,
1132 TempVal); 1128 TempVal);
@@ -1134,26 +1130,26 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev,
1134 TempVal = CCKSwingTable_Ch14[priv->CCK_index][0] + 1130 TempVal = CCKSwingTable_Ch14[priv->CCK_index][0] +
1135 (CCKSwingTable_Ch14[priv->CCK_index][1] << 8); 1131 (CCKSwingTable_Ch14[priv->CCK_index][1] << 8);
1136 1132
1137 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal); 1133 rtl92e_set_bb_reg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
1138 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n", 1134 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n",
1139 rCCK0_TxFilter1, TempVal); 1135 rCCK0_TxFilter1, TempVal);
1140 TempVal = CCKSwingTable_Ch14[priv->CCK_index][2] + 1136 TempVal = CCKSwingTable_Ch14[priv->CCK_index][2] +
1141 (CCKSwingTable_Ch14[priv->CCK_index][3] << 8) + 1137 (CCKSwingTable_Ch14[priv->CCK_index][3] << 8) +
1142 (CCKSwingTable_Ch14[priv->CCK_index][4] << 16)+ 1138 (CCKSwingTable_Ch14[priv->CCK_index][4] << 16)+
1143 (CCKSwingTable_Ch14[priv->CCK_index][5] << 24); 1139 (CCKSwingTable_Ch14[priv->CCK_index][5] << 24);
1144 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal); 1140 rtl92e_set_bb_reg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
1145 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n", 1141 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n",
1146 rCCK0_TxFilter2, TempVal); 1142 rCCK0_TxFilter2, TempVal);
1147 TempVal = CCKSwingTable_Ch14[priv->CCK_index][6] + 1143 TempVal = CCKSwingTable_Ch14[priv->CCK_index][6] +
1148 (CCKSwingTable_Ch14[priv->CCK_index][7]<<8); 1144 (CCKSwingTable_Ch14[priv->CCK_index][7]<<8);
1149 1145
1150 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal); 1146 rtl92e_set_bb_reg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
1151 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n", 1147 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n",
1152 rCCK0_DebugPort, TempVal); 1148 rCCK0_DebugPort, TempVal);
1153 } 1149 }
1154} 1150}
1155 1151
1156void dm_cck_txpower_adjust(struct net_device *dev, bool binch14) 1152void rtl92e_dm_cck_txpower_adjust(struct net_device *dev, bool binch14)
1157{ 1153{
1158 struct r8192_priv *priv = rtllib_priv(dev); 1154 struct r8192_priv *priv = rtllib_priv(dev);
1159 1155
@@ -1168,8 +1164,8 @@ static void dm_txpower_reset_recovery(struct net_device *dev)
1168 struct r8192_priv *priv = rtllib_priv(dev); 1164 struct r8192_priv *priv = rtllib_priv(dev);
1169 1165
1170 RT_TRACE(COMP_POWER_TRACKING, "Start Reset Recovery ==>\n"); 1166 RT_TRACE(COMP_POWER_TRACKING, "Start Reset Recovery ==>\n");
1171 rtl8192_setBBreg(dev, rOFDM0_XATxIQImbalance, bMaskDWord, 1167 rtl92e_set_bb_reg(dev, rOFDM0_XATxIQImbalance, bMaskDWord,
1172 dm_tx_bb_gain[priv->rfa_txpowertrackingindex]); 1168 dm_tx_bb_gain[priv->rfa_txpowertrackingindex]);
1173 RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery: Fill in 0xc80 is %08x\n", 1169 RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery: Fill in 0xc80 is %08x\n",
1174 dm_tx_bb_gain[priv->rfa_txpowertrackingindex]); 1170 dm_tx_bb_gain[priv->rfa_txpowertrackingindex]);
1175 RT_TRACE(COMP_POWER_TRACKING, 1171 RT_TRACE(COMP_POWER_TRACKING,
@@ -1181,10 +1177,10 @@ static void dm_txpower_reset_recovery(struct net_device *dev)
1181 RT_TRACE(COMP_POWER_TRACKING, 1177 RT_TRACE(COMP_POWER_TRACKING,
1182 "Reset Recovery: CCK Attenuation is %d dB\n", 1178 "Reset Recovery: CCK Attenuation is %d dB\n",
1183 priv->CCKPresentAttentuation); 1179 priv->CCKPresentAttentuation);
1184 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14); 1180 rtl92e_dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
1185 1181
1186 rtl8192_setBBreg(dev, rOFDM0_XCTxIQImbalance, bMaskDWord, 1182 rtl92e_set_bb_reg(dev, rOFDM0_XCTxIQImbalance, bMaskDWord,
1187 dm_tx_bb_gain[priv->rfc_txpowertrackingindex]); 1183 dm_tx_bb_gain[priv->rfc_txpowertrackingindex]);
1188 RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery: Fill in 0xc90 is %08x\n", 1184 RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery: Fill in 0xc90 is %08x\n",
1189 dm_tx_bb_gain[priv->rfc_txpowertrackingindex]); 1185 dm_tx_bb_gain[priv->rfc_txpowertrackingindex]);
1190 RT_TRACE(COMP_POWER_TRACKING, 1186 RT_TRACE(COMP_POWER_TRACKING,
@@ -1195,7 +1191,7 @@ static void dm_txpower_reset_recovery(struct net_device *dev)
1195 dm_tx_bb_gain_idx_to_amplify(priv->rfc_txpowertrackingindex)); 1191 dm_tx_bb_gain_idx_to_amplify(priv->rfc_txpowertrackingindex));
1196} 1192}
1197 1193
1198void dm_restore_dynamic_mechanism_state(struct net_device *dev) 1194void rtl92e_dm_restore_state(struct net_device *dev)
1199{ 1195{
1200 struct r8192_priv *priv = rtllib_priv(dev); 1196 struct r8192_priv *priv = rtllib_priv(dev);
1201 u32 reg_ratr = priv->rate_adaptive.last_ratr; 1197 u32 reg_ratr = priv->rate_adaptive.last_ratr;
@@ -1203,7 +1199,7 @@ void dm_restore_dynamic_mechanism_state(struct net_device *dev)
1203 1199
1204 if (!priv->up) { 1200 if (!priv->up) {
1205 RT_TRACE(COMP_RATE, 1201 RT_TRACE(COMP_RATE,
1206 "<---- dm_restore_dynamic_mechanism_state(): driver is going to unload\n"); 1202 "<---- rtl92e_dm_restore_state(): driver is going to unload\n");
1207 return; 1203 return;
1208 } 1204 }
1209 1205
@@ -1215,8 +1211,8 @@ void dm_restore_dynamic_mechanism_state(struct net_device *dev)
1215 ratr_value = reg_ratr; 1211 ratr_value = reg_ratr;
1216 if (priv->rf_type == RF_1T2R) 1212 if (priv->rf_type == RF_1T2R)
1217 ratr_value &= ~(RATE_ALL_OFDM_2SS); 1213 ratr_value &= ~(RATE_ALL_OFDM_2SS);
1218 write_nic_dword(dev, RATR0, ratr_value); 1214 rtl92e_writel(dev, RATR0, ratr_value);
1219 write_nic_byte(dev, UFWP, 1); 1215 rtl92e_writeb(dev, UFWP, 1);
1220 if (priv->btxpower_trackingInit && priv->btxpower_tracking) 1216 if (priv->btxpower_trackingInit && priv->btxpower_tracking)
1221 dm_txpower_reset_recovery(dev); 1217 dm_txpower_reset_recovery(dev);
1222 1218
@@ -1232,18 +1228,18 @@ static void dm_bb_initialgain_restore(struct net_device *dev)
1232 if (dm_digtable.dig_algorithm == DIG_ALGO_BY_RSSI) 1228 if (dm_digtable.dig_algorithm == DIG_ALGO_BY_RSSI)
1233 return; 1229 return;
1234 1230
1235 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); 1231 rtl92e_set_bb_reg(dev, UFWP, bMaskByte1, 0x8);
1236 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, bit_mask, 1232 rtl92e_set_bb_reg(dev, rOFDM0_XAAGCCore1, bit_mask,
1237 (u32)priv->initgain_backup.xaagccore1); 1233 (u32)priv->initgain_backup.xaagccore1);
1238 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, bit_mask, 1234 rtl92e_set_bb_reg(dev, rOFDM0_XBAGCCore1, bit_mask,
1239 (u32)priv->initgain_backup.xbagccore1); 1235 (u32)priv->initgain_backup.xbagccore1);
1240 rtl8192_setBBreg(dev, rOFDM0_XCAGCCore1, bit_mask, 1236 rtl92e_set_bb_reg(dev, rOFDM0_XCAGCCore1, bit_mask,
1241 (u32)priv->initgain_backup.xcagccore1); 1237 (u32)priv->initgain_backup.xcagccore1);
1242 rtl8192_setBBreg(dev, rOFDM0_XDAGCCore1, bit_mask, 1238 rtl92e_set_bb_reg(dev, rOFDM0_XDAGCCore1, bit_mask,
1243 (u32)priv->initgain_backup.xdagccore1); 1239 (u32)priv->initgain_backup.xdagccore1);
1244 bit_mask = bMaskByte2; 1240 bit_mask = bMaskByte2;
1245 rtl8192_setBBreg(dev, rCCK0_CCA, bit_mask, 1241 rtl92e_set_bb_reg(dev, rCCK0_CCA, bit_mask,
1246 (u32)priv->initgain_backup.cca); 1242 (u32)priv->initgain_backup.cca);
1247 1243
1248 RT_TRACE(COMP_DIG, "dm_BBInitialGainRestore 0xc50 is %x\n", 1244 RT_TRACE(COMP_DIG, "dm_BBInitialGainRestore 0xc50 is %x\n",
1249 priv->initgain_backup.xaagccore1); 1245 priv->initgain_backup.xaagccore1);
@@ -1255,12 +1251,12 @@ static void dm_bb_initialgain_restore(struct net_device *dev)
1255 priv->initgain_backup.xdagccore1); 1251 priv->initgain_backup.xdagccore1);
1256 RT_TRACE(COMP_DIG, "dm_BBInitialGainRestore 0xa0a is %x\n", 1252 RT_TRACE(COMP_DIG, "dm_BBInitialGainRestore 0xa0a is %x\n",
1257 priv->initgain_backup.cca); 1253 priv->initgain_backup.cca);
1258 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); 1254 rtl92e_set_bb_reg(dev, UFWP, bMaskByte1, 0x1);
1259 1255
1260} 1256}
1261 1257
1262 1258
1263void dm_backup_dynamic_mechanism_state(struct net_device *dev) 1259void rtl92e_dm_backup_state(struct net_device *dev)
1264{ 1260{
1265 struct r8192_priv *priv = rtllib_priv(dev); 1261 struct r8192_priv *priv = rtllib_priv(dev);
1266 1262
@@ -1279,13 +1275,13 @@ static void dm_bb_initialgain_backup(struct net_device *dev)
1279 if (dm_digtable.dig_algorithm == DIG_ALGO_BY_RSSI) 1275 if (dm_digtable.dig_algorithm == DIG_ALGO_BY_RSSI)
1280 return; 1276 return;
1281 1277
1282 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); 1278 rtl92e_set_bb_reg(dev, UFWP, bMaskByte1, 0x8);
1283 priv->initgain_backup.xaagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, bit_mask); 1279 priv->initgain_backup.xaagccore1 = (u8)rtl92e_get_bb_reg(dev, rOFDM0_XAAGCCore1, bit_mask);
1284 priv->initgain_backup.xbagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, bit_mask); 1280 priv->initgain_backup.xbagccore1 = (u8)rtl92e_get_bb_reg(dev, rOFDM0_XBAGCCore1, bit_mask);
1285 priv->initgain_backup.xcagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, bit_mask); 1281 priv->initgain_backup.xcagccore1 = (u8)rtl92e_get_bb_reg(dev, rOFDM0_XCAGCCore1, bit_mask);
1286 priv->initgain_backup.xdagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, bit_mask); 1282 priv->initgain_backup.xdagccore1 = (u8)rtl92e_get_bb_reg(dev, rOFDM0_XDAGCCore1, bit_mask);
1287 bit_mask = bMaskByte2; 1283 bit_mask = bMaskByte2;
1288 priv->initgain_backup.cca = (u8)rtl8192_QueryBBReg(dev, rCCK0_CCA, bit_mask); 1284 priv->initgain_backup.cca = (u8)rtl92e_get_bb_reg(dev, rCCK0_CCA, bit_mask);
1289 1285
1290 RT_TRACE(COMP_DIG, "BBInitialGainBackup 0xc50 is %x\n", 1286 RT_TRACE(COMP_DIG, "BBInitialGainBackup 0xc50 is %x\n",
1291 priv->initgain_backup.xaagccore1); 1287 priv->initgain_backup.xaagccore1);
@@ -1376,7 +1372,7 @@ static void dm_ctrl_initgain_byrssi_by_driverrssi(
1376 fw_dig = 0; 1372 fw_dig = 0;
1377 if (fw_dig <= 3) { 1373 if (fw_dig <= 3) {
1378 for (i = 0; i < 3; i++) 1374 for (i = 0; i < 3; i++)
1379 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); 1375 rtl92e_set_bb_reg(dev, UFWP, bMaskByte1, 0x8);
1380 fw_dig++; 1376 fw_dig++;
1381 dm_digtable.dig_state = DM_STA_DIG_OFF; 1377 dm_digtable.dig_state = DM_STA_DIG_OFF;
1382 } 1378 }
@@ -1410,7 +1406,7 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
1410 if (dm_digtable.dig_algorithm_switch) { 1406 if (dm_digtable.dig_algorithm_switch) {
1411 dm_digtable.dig_state = DM_STA_DIG_MAX; 1407 dm_digtable.dig_state = DM_STA_DIG_MAX;
1412 for (i = 0; i < 3; i++) 1408 for (i = 0; i < 3; i++)
1413 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); 1409 rtl92e_set_bb_reg(dev, UFWP, bMaskByte1, 0x1);
1414 dm_digtable.dig_algorithm_switch = 0; 1410 dm_digtable.dig_algorithm_switch = 0;
1415 } 1411 }
1416 1412
@@ -1429,19 +1425,19 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
1429 dm_digtable.dig_highpwr_state = DM_STA_DIG_MAX; 1425 dm_digtable.dig_highpwr_state = DM_STA_DIG_MAX;
1430 dm_digtable.dig_state = DM_STA_DIG_OFF; 1426 dm_digtable.dig_state = DM_STA_DIG_OFF;
1431 1427
1432 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); 1428 rtl92e_set_bb_reg(dev, UFWP, bMaskByte1, 0x8);
1433 1429
1434 write_nic_byte(dev, rOFDM0_XAAGCCore1, 0x17); 1430 rtl92e_writeb(dev, rOFDM0_XAAGCCore1, 0x17);
1435 write_nic_byte(dev, rOFDM0_XBAGCCore1, 0x17); 1431 rtl92e_writeb(dev, rOFDM0_XBAGCCore1, 0x17);
1436 write_nic_byte(dev, rOFDM0_XCAGCCore1, 0x17); 1432 rtl92e_writeb(dev, rOFDM0_XCAGCCore1, 0x17);
1437 write_nic_byte(dev, rOFDM0_XDAGCCore1, 0x17); 1433 rtl92e_writeb(dev, rOFDM0_XDAGCCore1, 0x17);
1438 1434
1439 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) 1435 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
1440 write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x00); 1436 rtl92e_writeb(dev, (rOFDM0_XATxAFE+3), 0x00);
1441 else 1437 else
1442 write_nic_byte(dev, rOFDM0_RxDetector1, 0x42); 1438 rtl92e_writeb(dev, rOFDM0_RxDetector1, 0x42);
1443 1439
1444 write_nic_byte(dev, 0xa0a, 0x08); 1440 rtl92e_writeb(dev, 0xa0a, 0x08);
1445 1441
1446 return; 1442 return;
1447 } 1443 }
@@ -1462,25 +1458,25 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
1462 dm_digtable.dig_state = DM_STA_DIG_ON; 1458 dm_digtable.dig_state = DM_STA_DIG_ON;
1463 1459
1464 if (reset_flag == 1) { 1460 if (reset_flag == 1) {
1465 write_nic_byte(dev, rOFDM0_XAAGCCore1, 0x2c); 1461 rtl92e_writeb(dev, rOFDM0_XAAGCCore1, 0x2c);
1466 write_nic_byte(dev, rOFDM0_XBAGCCore1, 0x2c); 1462 rtl92e_writeb(dev, rOFDM0_XBAGCCore1, 0x2c);
1467 write_nic_byte(dev, rOFDM0_XCAGCCore1, 0x2c); 1463 rtl92e_writeb(dev, rOFDM0_XCAGCCore1, 0x2c);
1468 write_nic_byte(dev, rOFDM0_XDAGCCore1, 0x2c); 1464 rtl92e_writeb(dev, rOFDM0_XDAGCCore1, 0x2c);
1469 } else { 1465 } else {
1470 write_nic_byte(dev, rOFDM0_XAAGCCore1, 0x20); 1466 rtl92e_writeb(dev, rOFDM0_XAAGCCore1, 0x20);
1471 write_nic_byte(dev, rOFDM0_XBAGCCore1, 0x20); 1467 rtl92e_writeb(dev, rOFDM0_XBAGCCore1, 0x20);
1472 write_nic_byte(dev, rOFDM0_XCAGCCore1, 0x20); 1468 rtl92e_writeb(dev, rOFDM0_XCAGCCore1, 0x20);
1473 write_nic_byte(dev, rOFDM0_XDAGCCore1, 0x20); 1469 rtl92e_writeb(dev, rOFDM0_XDAGCCore1, 0x20);
1474 } 1470 }
1475 1471
1476 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) 1472 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
1477 write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x20); 1473 rtl92e_writeb(dev, (rOFDM0_XATxAFE+3), 0x20);
1478 else 1474 else
1479 write_nic_byte(dev, rOFDM0_RxDetector1, 0x44); 1475 rtl92e_writeb(dev, rOFDM0_RxDetector1, 0x44);
1480 1476
1481 write_nic_byte(dev, 0xa0a, 0xcd); 1477 rtl92e_writeb(dev, 0xa0a, 0xcd);
1482 1478
1483 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); 1479 rtl92e_set_bb_reg(dev, UFWP, bMaskByte1, 0x1);
1484 } 1480 }
1485 dm_ctrl_initgain_byrssi_highpwr(dev); 1481 dm_ctrl_initgain_byrssi_highpwr(dev);
1486} 1482}
@@ -1505,9 +1501,9 @@ static void dm_ctrl_initgain_byrssi_highpwr(struct net_device *dev)
1505 dm_digtable.dig_highpwr_state = DM_STA_DIG_ON; 1501 dm_digtable.dig_highpwr_state = DM_STA_DIG_ON;
1506 1502
1507 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) 1503 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
1508 write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x10); 1504 rtl92e_writeb(dev, (rOFDM0_XATxAFE+3), 0x10);
1509 else 1505 else
1510 write_nic_byte(dev, rOFDM0_RxDetector1, 0x43); 1506 rtl92e_writeb(dev, rOFDM0_RxDetector1, 0x43);
1511 } else { 1507 } else {
1512 if (dm_digtable.dig_highpwr_state == DM_STA_DIG_OFF && 1508 if (dm_digtable.dig_highpwr_state == DM_STA_DIG_OFF &&
1513 (priv->reset_count == reset_cnt_highpwr)) 1509 (priv->reset_count == reset_cnt_highpwr))
@@ -1519,9 +1515,9 @@ static void dm_ctrl_initgain_byrssi_highpwr(struct net_device *dev)
1519 (priv->undecorated_smoothed_pwdb >= 1515 (priv->undecorated_smoothed_pwdb >=
1520 dm_digtable.rssi_high_thresh)) { 1516 dm_digtable.rssi_high_thresh)) {
1521 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) 1517 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
1522 write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x20); 1518 rtl92e_writeb(dev, (rOFDM0_XATxAFE+3), 0x20);
1523 else 1519 else
1524 write_nic_byte(dev, rOFDM0_RxDetector1, 0x44); 1520 rtl92e_writeb(dev, rOFDM0_RxDetector1, 0x44);
1525 } 1521 }
1526 } 1522 }
1527 reset_cnt_highpwr = priv->reset_count; 1523 reset_cnt_highpwr = priv->reset_count;
@@ -1568,16 +1564,16 @@ static void dm_initial_gain(struct net_device *dev)
1568 reset_cnt = priv->reset_count; 1564 reset_cnt = priv->reset_count;
1569 } 1565 }
1570 1566
1571 if (dm_digtable.pre_ig_value != read_nic_byte(dev, rOFDM0_XAAGCCore1)) 1567 if (dm_digtable.pre_ig_value != rtl92e_readb(dev, rOFDM0_XAAGCCore1))
1572 force_write = 1; 1568 force_write = 1;
1573 1569
1574 if ((dm_digtable.pre_ig_value != dm_digtable.cur_ig_value) 1570 if ((dm_digtable.pre_ig_value != dm_digtable.cur_ig_value)
1575 || !initialized || force_write) { 1571 || !initialized || force_write) {
1576 initial_gain = (u8)dm_digtable.cur_ig_value; 1572 initial_gain = (u8)dm_digtable.cur_ig_value;
1577 write_nic_byte(dev, rOFDM0_XAAGCCore1, initial_gain); 1573 rtl92e_writeb(dev, rOFDM0_XAAGCCore1, initial_gain);
1578 write_nic_byte(dev, rOFDM0_XBAGCCore1, initial_gain); 1574 rtl92e_writeb(dev, rOFDM0_XBAGCCore1, initial_gain);
1579 write_nic_byte(dev, rOFDM0_XCAGCCore1, initial_gain); 1575 rtl92e_writeb(dev, rOFDM0_XCAGCCore1, initial_gain);
1580 write_nic_byte(dev, rOFDM0_XDAGCCore1, initial_gain); 1576 rtl92e_writeb(dev, rOFDM0_XDAGCCore1, initial_gain);
1581 dm_digtable.pre_ig_value = dm_digtable.cur_ig_value; 1577 dm_digtable.pre_ig_value = dm_digtable.cur_ig_value;
1582 initialized = 1; 1578 initialized = 1;
1583 force_write = 0; 1579 force_write = 0;
@@ -1630,20 +1626,20 @@ static void dm_pd_th(struct net_device *dev)
1630 (initialized <= 3) || force_write) { 1626 (initialized <= 3) || force_write) {
1631 if (dm_digtable.curpd_thstate == DIG_PD_AT_LOW_POWER) { 1627 if (dm_digtable.curpd_thstate == DIG_PD_AT_LOW_POWER) {
1632 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) 1628 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
1633 write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x00); 1629 rtl92e_writeb(dev, (rOFDM0_XATxAFE+3), 0x00);
1634 else 1630 else
1635 write_nic_byte(dev, rOFDM0_RxDetector1, 0x42); 1631 rtl92e_writeb(dev, rOFDM0_RxDetector1, 0x42);
1636 } else if (dm_digtable.curpd_thstate == 1632 } else if (dm_digtable.curpd_thstate ==
1637 DIG_PD_AT_NORMAL_POWER) { 1633 DIG_PD_AT_NORMAL_POWER) {
1638 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) 1634 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
1639 write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x20); 1635 rtl92e_writeb(dev, (rOFDM0_XATxAFE+3), 0x20);
1640 else 1636 else
1641 write_nic_byte(dev, rOFDM0_RxDetector1, 0x44); 1637 rtl92e_writeb(dev, rOFDM0_RxDetector1, 0x44);
1642 } else if (dm_digtable.curpd_thstate == DIG_PD_AT_HIGH_POWER) { 1638 } else if (dm_digtable.curpd_thstate == DIG_PD_AT_HIGH_POWER) {
1643 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) 1639 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
1644 write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x10); 1640 rtl92e_writeb(dev, (rOFDM0_XATxAFE+3), 0x10);
1645 else 1641 else
1646 write_nic_byte(dev, rOFDM0_RxDetector1, 0x43); 1642 rtl92e_writeb(dev, rOFDM0_RxDetector1, 0x43);
1647 } 1643 }
1648 dm_digtable.prepd_thstate = dm_digtable.curpd_thstate; 1644 dm_digtable.prepd_thstate = dm_digtable.curpd_thstate;
1649 if (initialized <= 3) 1645 if (initialized <= 3)
@@ -1687,16 +1683,16 @@ static void dm_cs_ratio(struct net_device *dev)
1687 if ((dm_digtable.precs_ratio_state != dm_digtable.curcs_ratio_state) || 1683 if ((dm_digtable.precs_ratio_state != dm_digtable.curcs_ratio_state) ||
1688 !initialized || force_write) { 1684 !initialized || force_write) {
1689 if (dm_digtable.curcs_ratio_state == DIG_CS_RATIO_LOWER) 1685 if (dm_digtable.curcs_ratio_state == DIG_CS_RATIO_LOWER)
1690 write_nic_byte(dev, 0xa0a, 0x08); 1686 rtl92e_writeb(dev, 0xa0a, 0x08);
1691 else if (dm_digtable.curcs_ratio_state == DIG_CS_RATIO_HIGHER) 1687 else if (dm_digtable.curcs_ratio_state == DIG_CS_RATIO_HIGHER)
1692 write_nic_byte(dev, 0xa0a, 0xcd); 1688 rtl92e_writeb(dev, 0xa0a, 0xcd);
1693 dm_digtable.precs_ratio_state = dm_digtable.curcs_ratio_state; 1689 dm_digtable.precs_ratio_state = dm_digtable.curcs_ratio_state;
1694 initialized = 1; 1690 initialized = 1;
1695 force_write = 0; 1691 force_write = 0;
1696 } 1692 }
1697} 1693}
1698 1694
1699void dm_init_edca_turbo(struct net_device *dev) 1695void rtl92e_dm_init_edca_turbo(struct net_device *dev)
1700{ 1696{
1701 struct r8192_priv *priv = rtllib_priv(dev); 1697 struct r8192_priv *priv = rtllib_priv(dev);
1702 1698
@@ -1745,21 +1741,19 @@ static void dm_check_edca_turbo(struct net_device *dev)
1745 if (curTxOkCnt > 4*curRxOkCnt) { 1741 if (curTxOkCnt > 4*curRxOkCnt) {
1746 if (priv->bis_cur_rdlstate || 1742 if (priv->bis_cur_rdlstate ||
1747 !priv->bcurrent_turbo_EDCA) { 1743 !priv->bcurrent_turbo_EDCA) {
1748 write_nic_dword(dev, EDCAPARA_BE, 1744 rtl92e_writel(dev, EDCAPARA_BE,
1749 edca_setting_UL[pHTInfo->IOTPeer]); 1745 edca_setting_UL[pHTInfo->IOTPeer]);
1750 priv->bis_cur_rdlstate = false; 1746 priv->bis_cur_rdlstate = false;
1751 } 1747 }
1752 } else { 1748 } else {
1753 if (!priv->bis_cur_rdlstate || 1749 if (!priv->bis_cur_rdlstate ||
1754 !priv->bcurrent_turbo_EDCA) { 1750 !priv->bcurrent_turbo_EDCA) {
1755 if (priv->rtllib->mode == WIRELESS_MODE_G) 1751 if (priv->rtllib->mode == WIRELESS_MODE_G)
1756 write_nic_dword(dev, 1752 rtl92e_writel(dev, EDCAPARA_BE,
1757 EDCAPARA_BE, 1753 edca_setting_DL_GMode[pHTInfo->IOTPeer]);
1758 edca_setting_DL_GMode[pHTInfo->IOTPeer]);
1759 else 1754 else
1760 write_nic_dword(dev, 1755 rtl92e_writel(dev, EDCAPARA_BE,
1761 EDCAPARA_BE, 1756 edca_setting_DL[pHTInfo->IOTPeer]);
1762 edca_setting_DL[pHTInfo->IOTPeer]);
1763 priv->bis_cur_rdlstate = true; 1757 priv->bis_cur_rdlstate = true;
1764 } 1758 }
1765 } 1759 }
@@ -1769,20 +1763,18 @@ static void dm_check_edca_turbo(struct net_device *dev)
1769 if (!priv->bis_cur_rdlstate || 1763 if (!priv->bis_cur_rdlstate ||
1770 !priv->bcurrent_turbo_EDCA) { 1764 !priv->bcurrent_turbo_EDCA) {
1771 if (priv->rtllib->mode == WIRELESS_MODE_G) 1765 if (priv->rtllib->mode == WIRELESS_MODE_G)
1772 write_nic_dword(dev, 1766 rtl92e_writel(dev, EDCAPARA_BE,
1773 EDCAPARA_BE, 1767 edca_setting_DL_GMode[pHTInfo->IOTPeer]);
1774 edca_setting_DL_GMode[pHTInfo->IOTPeer]);
1775 else 1768 else
1776 write_nic_dword(dev, 1769 rtl92e_writel(dev, EDCAPARA_BE,
1777 EDCAPARA_BE, 1770 edca_setting_DL[pHTInfo->IOTPeer]);
1778 edca_setting_DL[pHTInfo->IOTPeer]);
1779 priv->bis_cur_rdlstate = true; 1771 priv->bis_cur_rdlstate = true;
1780 } 1772 }
1781 } else { 1773 } else {
1782 if (priv->bis_cur_rdlstate || 1774 if (priv->bis_cur_rdlstate ||
1783 !priv->bcurrent_turbo_EDCA) { 1775 !priv->bcurrent_turbo_EDCA) {
1784 write_nic_dword(dev, EDCAPARA_BE, 1776 rtl92e_writel(dev, EDCAPARA_BE,
1785 edca_setting_UL[pHTInfo->IOTPeer]); 1777 edca_setting_UL[pHTInfo->IOTPeer]);
1786 priv->bis_cur_rdlstate = false; 1778 priv->bis_cur_rdlstate = false;
1787 } 1779 }
1788 1780
@@ -1854,7 +1846,7 @@ static void dm_check_pbc_gpio(struct net_device *dev)
1854{ 1846{
1855} 1847}
1856 1848
1857void dm_CheckRfCtrlGPIO(void *data) 1849static void dm_CheckRfCtrlGPIO(void *data)
1858{ 1850{
1859 struct r8192_priv *priv = container_of_dwork_rsl(data, 1851 struct r8192_priv *priv = container_of_dwork_rsl(data,
1860 struct r8192_priv, gpio_change_rf_wq); 1852 struct r8192_priv, gpio_change_rf_wq);
@@ -1877,7 +1869,7 @@ void dm_CheckRfCtrlGPIO(void *data)
1877 return; 1869 return;
1878 } 1870 }
1879 1871
1880 tmp1byte = read_nic_byte(dev, GPI); 1872 tmp1byte = rtl92e_readb(dev, GPI);
1881 1873
1882 eRfPowerStateToSet = (tmp1byte&BIT1) ? eRfOn : eRfOff; 1874 eRfPowerStateToSet = (tmp1byte&BIT1) ? eRfOn : eRfOff;
1883 1875
@@ -1896,8 +1888,7 @@ void dm_CheckRfCtrlGPIO(void *data)
1896 if (bActuallySet) { 1888 if (bActuallySet) {
1897 mdelay(1000); 1889 mdelay(1000);
1898 priv->bHwRfOffAction = 1; 1890 priv->bHwRfOffAction = 1;
1899 MgntActSet_RF_State(dev, eRfPowerStateToSet, RF_CHANGE_BY_HW, 1891 rtl92e_set_rf_state(dev, eRfPowerStateToSet, RF_CHANGE_BY_HW);
1900 true);
1901 if (priv->bHwRadioOff) 1892 if (priv->bHwRadioOff)
1902 argv[1] = "RFOFF"; 1893 argv[1] = "RFOFF";
1903 else 1894 else
@@ -1909,7 +1900,7 @@ void dm_CheckRfCtrlGPIO(void *data)
1909 } 1900 }
1910} 1901}
1911 1902
1912void dm_rf_pathcheck_workitemcallback(void *data) 1903void rtl92e_dm_rf_pathcheck_wq(void *data)
1913{ 1904{
1914 struct r8192_priv *priv = container_of_dwork_rsl(data, 1905 struct r8192_priv *priv = container_of_dwork_rsl(data,
1915 struct r8192_priv, 1906 struct r8192_priv,
@@ -1917,7 +1908,7 @@ void dm_rf_pathcheck_workitemcallback(void *data)
1917 struct net_device *dev = priv->rtllib->dev; 1908 struct net_device *dev = priv->rtllib->dev;
1918 u8 rfpath = 0, i; 1909 u8 rfpath = 0, i;
1919 1910
1920 rfpath = read_nic_byte(dev, 0xc04); 1911 rfpath = rtl92e_readb(dev, 0xc04);
1921 1912
1922 for (i = 0; i < RF90_PATH_MAX; i++) { 1913 for (i = 0; i < RF90_PATH_MAX; i++) {
1923 if (rfpath & (0x01<<i)) 1914 if (rfpath & (0x01<<i))
@@ -1974,12 +1965,12 @@ static void dm_rxpath_sel_byrssi(struct net_device *dev)
1974 return; 1965 return;
1975 1966
1976 if (!cck_Rx_Path_initialized) { 1967 if (!cck_Rx_Path_initialized) {
1977 DM_RxPathSelTable.cck_Rx_path = (read_nic_byte(dev, 0xa07)&0xf); 1968 DM_RxPathSelTable.cck_Rx_path = (rtl92e_readb(dev, 0xa07)&0xf);
1978 cck_Rx_Path_initialized = 1; 1969 cck_Rx_Path_initialized = 1;
1979 } 1970 }
1980 1971
1981 DM_RxPathSelTable.disabledRF = 0xf; 1972 DM_RxPathSelTable.disabledRF = 0xf;
1982 DM_RxPathSelTable.disabledRF &= ~(read_nic_byte(dev, 0xc04)); 1973 DM_RxPathSelTable.disabledRF &= ~(rtl92e_readb(dev, 0xc04));
1983 1974
1984 if (priv->rtllib->mode == WIRELESS_MODE_B) 1975 if (priv->rtllib->mode == WIRELESS_MODE_B)
1985 DM_RxPathSelTable.cck_method = CCK_Rx_Version_2; 1976 DM_RxPathSelTable.cck_method = CCK_Rx_Version_2;
@@ -2116,10 +2107,10 @@ static void dm_rxpath_sel_byrssi(struct net_device *dev)
2116 DM_RxPathSelTable.diff_TH) { 2107 DM_RxPathSelTable.diff_TH) {
2117 DM_RxPathSelTable.rf_enable_rssi_th[min_rssi_index] = 2108 DM_RxPathSelTable.rf_enable_rssi_th[min_rssi_index] =
2118 tmp_max_rssi+5; 2109 tmp_max_rssi+5;
2119 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 2110 rtl92e_set_bb_reg(dev, rOFDM0_TRxPathEnable,
2120 0x1<<min_rssi_index, 0x0); 2111 0x1<<min_rssi_index, 0x0);
2121 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 2112 rtl92e_set_bb_reg(dev, rOFDM1_TRxPathEnable,
2122 0x1<<min_rssi_index, 0x0); 2113 0x1<<min_rssi_index, 0x0);
2123 disabled_rf_cnt++; 2114 disabled_rf_cnt++;
2124 } 2115 }
2125 if (DM_RxPathSelTable.cck_method == CCK_Rx_Version_1) { 2116 if (DM_RxPathSelTable.cck_method == CCK_Rx_Version_1) {
@@ -2133,8 +2124,8 @@ static void dm_rxpath_sel_byrssi(struct net_device *dev)
2133 if (update_cck_rx_path) { 2124 if (update_cck_rx_path) {
2134 DM_RxPathSelTable.cck_Rx_path = (cck_default_Rx<<2) | 2125 DM_RxPathSelTable.cck_Rx_path = (cck_default_Rx<<2) |
2135 (cck_optional_Rx); 2126 (cck_optional_Rx);
2136 rtl8192_setBBreg(dev, rCCK0_AFESetting, 0x0f000000, 2127 rtl92e_set_bb_reg(dev, rCCK0_AFESetting, 0x0f000000,
2137 DM_RxPathSelTable.cck_Rx_path); 2128 DM_RxPathSelTable.cck_Rx_path);
2138 } 2129 }
2139 2130
2140 if (DM_RxPathSelTable.disabledRF) { 2131 if (DM_RxPathSelTable.disabledRF) {
@@ -2142,12 +2133,12 @@ static void dm_rxpath_sel_byrssi(struct net_device *dev)
2142 if ((DM_RxPathSelTable.disabledRF>>i) & 0x1) { 2133 if ((DM_RxPathSelTable.disabledRF>>i) & 0x1) {
2143 if (tmp_max_rssi >= 2134 if (tmp_max_rssi >=
2144 DM_RxPathSelTable.rf_enable_rssi_th[i]) { 2135 DM_RxPathSelTable.rf_enable_rssi_th[i]) {
2145 rtl8192_setBBreg(dev, 2136 rtl92e_set_bb_reg(dev,
2146 rOFDM0_TRxPathEnable, 0x1 << i, 2137 rOFDM0_TRxPathEnable,
2147 0x1); 2138 0x1 << i, 0x1);
2148 rtl8192_setBBreg(dev, 2139 rtl92e_set_bb_reg(dev,
2149 rOFDM1_TRxPathEnable, 2140 rOFDM1_TRxPathEnable,
2150 0x1 << i, 0x1); 2141 0x1 << i, 0x1);
2151 DM_RxPathSelTable.rf_enable_rssi_th[i] 2142 DM_RxPathSelTable.rf_enable_rssi_th[i]
2152 = 100; 2143 = 100;
2153 disabled_rf_cnt--; 2144 disabled_rf_cnt--;
@@ -2191,7 +2182,7 @@ static void dm_deInit_fsync(struct net_device *dev)
2191 del_timer_sync(&priv->fsync_timer); 2182 del_timer_sync(&priv->fsync_timer);
2192} 2183}
2193 2184
2194void dm_fsync_timer_callback(unsigned long data) 2185static void dm_fsync_timer_callback(unsigned long data)
2195{ 2186{
2196 struct net_device *dev = (struct net_device *)data; 2187 struct net_device *dev = (struct net_device *)data;
2197 struct r8192_priv *priv = rtllib_priv((struct net_device *)data); 2188 struct r8192_priv *priv = rtllib_priv((struct net_device *)data);
@@ -2252,18 +2243,18 @@ void dm_fsync_timer_callback(unsigned long data)
2252 bDoubleTimeInterval = true; 2243 bDoubleTimeInterval = true;
2253 priv->bswitch_fsync = !priv->bswitch_fsync; 2244 priv->bswitch_fsync = !priv->bswitch_fsync;
2254 if (priv->bswitch_fsync) { 2245 if (priv->bswitch_fsync) {
2255 write_nic_byte(dev, 0xC36, 0x1c); 2246 rtl92e_writeb(dev, 0xC36, 0x1c);
2256 write_nic_byte(dev, 0xC3e, 0x90); 2247 rtl92e_writeb(dev, 0xC3e, 0x90);
2257 } else { 2248 } else {
2258 write_nic_byte(dev, 0xC36, 0x5c); 2249 rtl92e_writeb(dev, 0xC36, 0x5c);
2259 write_nic_byte(dev, 0xC3e, 0x96); 2250 rtl92e_writeb(dev, 0xC3e, 0x96);
2260 } 2251 }
2261 } else if (priv->undecorated_smoothed_pwdb <= 2252 } else if (priv->undecorated_smoothed_pwdb <=
2262 priv->rtllib->fsync_rssi_threshold) { 2253 priv->rtllib->fsync_rssi_threshold) {
2263 if (priv->bswitch_fsync) { 2254 if (priv->bswitch_fsync) {
2264 priv->bswitch_fsync = false; 2255 priv->bswitch_fsync = false;
2265 write_nic_byte(dev, 0xC36, 0x5c); 2256 rtl92e_writeb(dev, 0xC36, 0x5c);
2266 write_nic_byte(dev, 0xC3e, 0x96); 2257 rtl92e_writeb(dev, 0xC3e, 0x96);
2267 } 2258 }
2268 } 2259 }
2269 if (bDoubleTimeInterval) { 2260 if (bDoubleTimeInterval) {
@@ -2283,11 +2274,11 @@ void dm_fsync_timer_callback(unsigned long data)
2283 } else { 2274 } else {
2284 if (priv->bswitch_fsync) { 2275 if (priv->bswitch_fsync) {
2285 priv->bswitch_fsync = false; 2276 priv->bswitch_fsync = false;
2286 write_nic_byte(dev, 0xC36, 0x5c); 2277 rtl92e_writeb(dev, 0xC36, 0x5c);
2287 write_nic_byte(dev, 0xC3e, 0x96); 2278 rtl92e_writeb(dev, 0xC3e, 0x96);
2288 } 2279 }
2289 priv->ContinueDiffCount = 0; 2280 priv->ContinueDiffCount = 0;
2290 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd); 2281 rtl92e_writel(dev, rOFDM0_RxDetector2, 0x465c52cd);
2291 } 2282 }
2292 RT_TRACE(COMP_HALDM, "ContinueDiffCount %d\n", priv->ContinueDiffCount); 2283 RT_TRACE(COMP_HALDM, "ContinueDiffCount %d\n", priv->ContinueDiffCount);
2293 RT_TRACE(COMP_HALDM, 2284 RT_TRACE(COMP_HALDM,
@@ -2302,10 +2293,10 @@ static void dm_StartHWFsync(struct net_device *dev)
2302 struct r8192_priv *priv = rtllib_priv(dev); 2293 struct r8192_priv *priv = rtllib_priv(dev);
2303 2294
2304 RT_TRACE(COMP_HALDM, "%s\n", __func__); 2295 RT_TRACE(COMP_HALDM, "%s\n", __func__);
2305 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c12cf); 2296 rtl92e_writel(dev, rOFDM0_RxDetector2, 0x465c12cf);
2306 priv->rtllib->SetHwRegHandler(dev, HW_VAR_RF_TIMING, 2297 priv->rtllib->SetHwRegHandler(dev, HW_VAR_RF_TIMING,
2307 (u8 *)(&rf_timing)); 2298 (u8 *)(&rf_timing));
2308 write_nic_byte(dev, 0xc3b, 0x41); 2299 rtl92e_writeb(dev, 0xc3b, 0x41);
2309} 2300}
2310 2301
2311static void dm_EndHWFsync(struct net_device *dev) 2302static void dm_EndHWFsync(struct net_device *dev)
@@ -2314,10 +2305,10 @@ static void dm_EndHWFsync(struct net_device *dev)
2314 struct r8192_priv *priv = rtllib_priv(dev); 2305 struct r8192_priv *priv = rtllib_priv(dev);
2315 2306
2316 RT_TRACE(COMP_HALDM, "%s\n", __func__); 2307 RT_TRACE(COMP_HALDM, "%s\n", __func__);
2317 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd); 2308 rtl92e_writel(dev, rOFDM0_RxDetector2, 0x465c52cd);
2318 priv->rtllib->SetHwRegHandler(dev, HW_VAR_RF_TIMING, (u8 *) 2309 priv->rtllib->SetHwRegHandler(dev, HW_VAR_RF_TIMING, (u8 *)
2319 (&rf_timing)); 2310 (&rf_timing));
2320 write_nic_byte(dev, 0xc3b, 0x49); 2311 rtl92e_writeb(dev, 0xc3b, 0x49);
2321} 2312}
2322 2313
2323static void dm_EndSWFsync(struct net_device *dev) 2314static void dm_EndSWFsync(struct net_device *dev)
@@ -2330,13 +2321,13 @@ static void dm_EndSWFsync(struct net_device *dev)
2330 if (priv->bswitch_fsync) { 2321 if (priv->bswitch_fsync) {
2331 priv->bswitch_fsync = false; 2322 priv->bswitch_fsync = false;
2332 2323
2333 write_nic_byte(dev, 0xC36, 0x5c); 2324 rtl92e_writeb(dev, 0xC36, 0x5c);
2334 2325
2335 write_nic_byte(dev, 0xC3e, 0x96); 2326 rtl92e_writeb(dev, 0xC3e, 0x96);
2336 } 2327 }
2337 2328
2338 priv->ContinueDiffCount = 0; 2329 priv->ContinueDiffCount = 0;
2339 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd); 2330 rtl92e_writel(dev, rOFDM0_RxDetector2, 0x465c52cd);
2340} 2331}
2341 2332
2342static void dm_StartSWFsync(struct net_device *dev) 2333static void dm_StartSWFsync(struct net_device *dev)
@@ -2371,11 +2362,11 @@ static void dm_StartSWFsync(struct net_device *dev)
2371 msecs_to_jiffies(priv->rtllib->fsync_time_interval); 2362 msecs_to_jiffies(priv->rtllib->fsync_time_interval);
2372 add_timer(&priv->fsync_timer); 2363 add_timer(&priv->fsync_timer);
2373 2364
2374 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c12cd); 2365 rtl92e_writel(dev, rOFDM0_RxDetector2, 0x465c12cd);
2375 2366
2376} 2367}
2377 2368
2378void dm_check_fsync(struct net_device *dev) 2369static void dm_check_fsync(struct net_device *dev)
2379{ 2370{
2380#define RegC38_Default 0 2371#define RegC38_Default 0
2381#define RegC38_NonFsync_Other_AP 1 2372#define RegC38_NonFsync_Other_AP 1
@@ -2431,7 +2422,7 @@ void dm_check_fsync(struct net_device *dev)
2431 } 2422 }
2432 if (priv->framesyncMonitor) { 2423 if (priv->framesyncMonitor) {
2433 if (reg_c38_State != RegC38_Fsync_AP_BCM) { 2424 if (reg_c38_State != RegC38_Fsync_AP_BCM) {
2434 write_nic_byte(dev, rOFDM0_RxDetector3, 0x95); 2425 rtl92e_writeb(dev, rOFDM0_RxDetector3, 0x95);
2435 2426
2436 reg_c38_State = RegC38_Fsync_AP_BCM; 2427 reg_c38_State = RegC38_Fsync_AP_BCM;
2437 } 2428 }
@@ -2457,7 +2448,7 @@ void dm_check_fsync(struct net_device *dev)
2457 RegC38_TH) { 2448 RegC38_TH) {
2458 if (reg_c38_State != 2449 if (reg_c38_State !=
2459 RegC38_NonFsync_Other_AP) { 2450 RegC38_NonFsync_Other_AP) {
2460 write_nic_byte(dev, 2451 rtl92e_writeb(dev,
2461 rOFDM0_RxDetector3, 2452 rOFDM0_RxDetector3,
2462 0x90); 2453 0x90);
2463 2454
@@ -2467,7 +2458,7 @@ void dm_check_fsync(struct net_device *dev)
2467 } else if (priv->undecorated_smoothed_pwdb >= 2458 } else if (priv->undecorated_smoothed_pwdb >=
2468 (RegC38_TH+5)) { 2459 (RegC38_TH+5)) {
2469 if (reg_c38_State) { 2460 if (reg_c38_State) {
2470 write_nic_byte(dev, 2461 rtl92e_writeb(dev,
2471 rOFDM0_RxDetector3, 2462 rOFDM0_RxDetector3,
2472 priv->framesync); 2463 priv->framesync);
2473 reg_c38_State = RegC38_Default; 2464 reg_c38_State = RegC38_Default;
@@ -2475,8 +2466,8 @@ void dm_check_fsync(struct net_device *dev)
2475 } 2466 }
2476 } else { 2467 } else {
2477 if (reg_c38_State) { 2468 if (reg_c38_State) {
2478 write_nic_byte(dev, rOFDM0_RxDetector3, 2469 rtl92e_writeb(dev, rOFDM0_RxDetector3,
2479 priv->framesync); 2470 priv->framesync);
2480 reg_c38_State = RegC38_Default; 2471 reg_c38_State = RegC38_Default;
2481 } 2472 }
2482 } 2473 }
@@ -2484,14 +2475,14 @@ void dm_check_fsync(struct net_device *dev)
2484 } 2475 }
2485 if (priv->framesyncMonitor) { 2476 if (priv->framesyncMonitor) {
2486 if (priv->reset_count != reset_cnt) { 2477 if (priv->reset_count != reset_cnt) {
2487 write_nic_byte(dev, rOFDM0_RxDetector3, 2478 rtl92e_writeb(dev, rOFDM0_RxDetector3,
2488 priv->framesync); 2479 priv->framesync);
2489 reg_c38_State = RegC38_Default; 2480 reg_c38_State = RegC38_Default;
2490 reset_cnt = priv->reset_count; 2481 reset_cnt = priv->reset_count;
2491 } 2482 }
2492 } else { 2483 } else {
2493 if (reg_c38_State) { 2484 if (reg_c38_State) {
2494 write_nic_byte(dev, rOFDM0_RxDetector3, 2485 rtl92e_writeb(dev, rOFDM0_RxDetector3,
2495 priv->framesync); 2486 priv->framesync);
2496 reg_c38_State = RegC38_Default; 2487 reg_c38_State = RegC38_Default;
2497 } 2488 }
@@ -2556,8 +2547,7 @@ static void dm_dynamic_txpower(struct net_device *dev)
2556 RT_TRACE(COMP_TXAGC, "SetTxPowerLevel8190() channel = %d\n", 2547 RT_TRACE(COMP_TXAGC, "SetTxPowerLevel8190() channel = %d\n",
2557 priv->rtllib->current_network.channel); 2548 priv->rtllib->current_network.channel);
2558 2549
2559 rtl8192_phy_setTxPower(dev, 2550 rtl92e_set_tx_power(dev, priv->rtllib->current_network.channel);
2560 priv->rtllib->current_network.channel);
2561 } 2551 }
2562 priv->bLastDTPFlag_High = priv->bDynamicTxHighPower; 2552 priv->bLastDTPFlag_High = priv->bDynamicTxHighPower;
2563 priv->bLastDTPFlag_Low = priv->bDynamicTxLowPower; 2553 priv->bLastDTPFlag_Low = priv->bDynamicTxLowPower;
@@ -2569,13 +2559,13 @@ static void dm_check_txrateandretrycount(struct net_device *dev)
2569 struct r8192_priv *priv = rtllib_priv(dev); 2559 struct r8192_priv *priv = rtllib_priv(dev);
2570 struct rtllib_device *ieee = priv->rtllib; 2560 struct rtllib_device *ieee = priv->rtllib;
2571 2561
2572 ieee->softmac_stats.CurrentShowTxate = read_nic_byte(dev, 2562 ieee->softmac_stats.CurrentShowTxate = rtl92e_readb(dev,
2573 Current_Tx_Rate_Reg); 2563 Current_Tx_Rate_Reg);
2574 2564
2575 ieee->softmac_stats.last_packet_rate = read_nic_byte(dev, 2565 ieee->softmac_stats.last_packet_rate = rtl92e_readb(dev,
2576 Initial_Tx_Rate_Reg); 2566 Initial_Tx_Rate_Reg);
2577 2567
2578 ieee->softmac_stats.txretrycount = read_nic_dword(dev, 2568 ieee->softmac_stats.txretrycount = rtl92e_readl(dev,
2579 Tx_Retry_Count_Reg); 2569 Tx_Retry_Count_Reg);
2580} 2570}
2581 2571
@@ -2583,5 +2573,5 @@ static void dm_send_rssi_tofw(struct net_device *dev)
2583{ 2573{
2584 struct r8192_priv *priv = rtllib_priv(dev); 2574 struct r8192_priv *priv = rtllib_priv(dev);
2585 2575
2586 write_nic_byte(dev, DRIVER_RSSI, (u8)priv->undecorated_smoothed_pwdb); 2576 rtl92e_writeb(dev, DRIVER_RSSI, (u8)priv->undecorated_smoothed_pwdb);
2587} 2577}
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.h b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.h
index b037451c3ada..097f0dc2056d 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.h
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.h
@@ -27,26 +27,17 @@
27#define DM_DIG_THRESH_HIGH 40 27#define DM_DIG_THRESH_HIGH 40
28#define DM_DIG_THRESH_LOW 35 28#define DM_DIG_THRESH_LOW 35
29 29
30#define DM_FALSEALARM_THRESH_LOW 40
31#define DM_FALSEALARM_THRESH_HIGH 1000
32
33#define DM_DIG_HIGH_PWR_THRESH_HIGH 75 30#define DM_DIG_HIGH_PWR_THRESH_HIGH 75
34#define DM_DIG_HIGH_PWR_THRESH_LOW 70 31#define DM_DIG_HIGH_PWR_THRESH_LOW 70
35 32
36#define BW_AUTO_SWITCH_HIGH_LOW 25 33#define BW_AUTO_SWITCH_HIGH_LOW 25
37#define BW_AUTO_SWITCH_LOW_HIGH 30 34#define BW_AUTO_SWITCH_LOW_HIGH 30
38 35
39#define DM_check_fsync_time_interval 500
40
41
42#define DM_DIG_BACKOFF 12 36#define DM_DIG_BACKOFF 12
43#define DM_DIG_MAX 0x36 37#define DM_DIG_MAX 0x36
44#define DM_DIG_MIN 0x1c 38#define DM_DIG_MIN 0x1c
45#define DM_DIG_MIN_Netcore 0x12 39#define DM_DIG_MIN_Netcore 0x12
46 40
47#define DM_DIG_BACKOFF_MAX 12
48#define DM_DIG_BACKOFF_MIN -4
49
50#define RxPathSelection_SS_TH_low 30 41#define RxPathSelection_SS_TH_low 30
51#define RxPathSelection_diff_TH 18 42#define RxPathSelection_diff_TH 18
52 43
@@ -55,8 +46,6 @@
55#define RateAdaptiveTH_Low_40M 10 46#define RateAdaptiveTH_Low_40M 10
56#define VeryLowRSSI 15 47#define VeryLowRSSI 15
57 48
58#define CTSToSelfTHVal 35
59
60#define WAIotTHVal 25 49#define WAIotTHVal 25
61 50
62#define E_FOR_TX_POWER_TRACK 300 51#define E_FOR_TX_POWER_TRACK 300
@@ -70,14 +59,6 @@
70#define Tx_Retry_Count_Reg 0x1ac 59#define Tx_Retry_Count_Reg 0x1ac
71#define RegC38_TH 20 60#define RegC38_TH 20
72 61
73#define TX_POWER_NEAR_FIELD_THRESH_LVL2 74
74#define TX_POWER_NEAR_FIELD_THRESH_LVL1 67
75
76#define TxHighPwrLevel_Normal 0
77#define TxHighPwrLevel_Level1 1
78#define TxHighPwrLevel_Level2 2
79
80#define DM_Type_ByFW 0
81#define DM_Type_ByDriver 1 62#define DM_Type_ByDriver 1
82 63
83/*--------------------------Define Parameters-------------------------------*/ 64/*--------------------------Define Parameters-------------------------------*/
@@ -207,23 +188,20 @@ extern const u8 dm_cck_tx_bb_gain_ch14[CCKTxBBGainTableLength][8];
207/*--------------------------Exported Function prototype---------------------*/ 188/*--------------------------Exported Function prototype---------------------*/
208/*--------------------------Exported Function prototype---------------------*/ 189/*--------------------------Exported Function prototype---------------------*/
209 190
210extern void init_hal_dm(struct net_device *dev); 191void rtl92e_dm_init(struct net_device *dev);
211extern void deinit_hal_dm(struct net_device *dev); 192void rtl92e_dm_deinit(struct net_device *dev);
212 193
213extern void hal_dm_watchdog(struct net_device *dev); 194void rtl92e_dm_watchdog(struct net_device *dev);
214 195
215 196
216extern void init_rate_adaptive(struct net_device *dev); 197void rtl92e_init_adaptive_rate(struct net_device *dev);
217extern void dm_txpower_trackingcallback(void *data); 198void rtl92e_dm_txpower_tracking_wq(void *data);
218 199
219extern void dm_cck_txpower_adjust(struct net_device *dev, bool binch14); 200void rtl92e_dm_cck_txpower_adjust(struct net_device *dev, bool binch14);
220 201
221extern void dm_restore_dynamic_mechanism_state(struct net_device *dev); 202void rtl92e_dm_restore_state(struct net_device *dev);
222extern void dm_backup_dynamic_mechanism_state(struct net_device *dev); 203void rtl92e_dm_backup_state(struct net_device *dev);
223extern void dm_init_edca_turbo(struct net_device *dev); 204void rtl92e_dm_init_edca_turbo(struct net_device *dev);
224extern void dm_rf_pathcheck_workitemcallback(void *data); 205void rtl92e_dm_rf_pathcheck_wq(void *data);
225extern void dm_fsync_timer_callback(unsigned long data); 206void rtl92e_dm_init_txpower_tracking(struct net_device *dev);
226extern void dm_check_fsync(struct net_device *dev);
227extern void dm_initialize_txpower_tracking(struct net_device *dev);
228extern void dm_CheckRfCtrlGPIO(void *data);
229#endif /*__R8192UDM_H__ */ 207#endif /*__R8192UDM_H__ */
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_eeprom.c b/drivers/staging/rtl8192e/rtl8192e/rtl_eeprom.c
index a6778e0853c7..039ccfd41230 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_eeprom.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_eeprom.c
@@ -25,115 +25,75 @@
25#include "rtl_core.h" 25#include "rtl_core.h"
26#include "rtl_eeprom.h" 26#include "rtl_eeprom.h"
27 27
28static void eprom_cs(struct net_device *dev, short bit) 28static void _rtl92e_gpio_write_bit(struct net_device *dev, int no, bool val)
29{ 29{
30 if (bit) 30 u8 reg = rtl92e_readb(dev, EPROM_CMD);
31 write_nic_byte(dev, EPROM_CMD, 31
32 (1 << EPROM_CS_SHIFT) | 32 if (val)
33 read_nic_byte(dev, EPROM_CMD)); 33 reg |= 1 << no;
34 else 34 else
35 write_nic_byte(dev, EPROM_CMD, read_nic_byte(dev, EPROM_CMD) 35 reg &= ~(1 << no);
36 & ~(1<<EPROM_CS_SHIFT));
37 36
37 rtl92e_writeb(dev, EPROM_CMD, reg);
38 udelay(EPROM_DELAY); 38 udelay(EPROM_DELAY);
39} 39}
40 40
41 41static bool _rtl92e_gpio_get_bit(struct net_device *dev, int no)
42static void eprom_ck_cycle(struct net_device *dev)
43{ 42{
44 write_nic_byte(dev, EPROM_CMD, 43 u8 reg = rtl92e_readb(dev, EPROM_CMD);
45 (1<<EPROM_CK_SHIFT) | read_nic_byte(dev, EPROM_CMD));
46 udelay(EPROM_DELAY);
47 write_nic_byte(dev, EPROM_CMD,
48 read_nic_byte(dev, EPROM_CMD) & ~(1<<EPROM_CK_SHIFT));
49 udelay(EPROM_DELAY);
50}
51 44
45 return (reg >> no) & 0x1;
46}
52 47
53static void eprom_w(struct net_device *dev, short bit) 48static void _rtl92e_eeprom_ck_cycle(struct net_device *dev)
54{ 49{
55 if (bit) 50 _rtl92e_gpio_write_bit(dev, EPROM_CK_BIT, 1);
56 write_nic_byte(dev, EPROM_CMD, (1<<EPROM_W_SHIFT) | 51 _rtl92e_gpio_write_bit(dev, EPROM_CK_BIT, 0);
57 read_nic_byte(dev, EPROM_CMD));
58 else
59 write_nic_byte(dev, EPROM_CMD, read_nic_byte(dev, EPROM_CMD)
60 & ~(1<<EPROM_W_SHIFT));
61
62 udelay(EPROM_DELAY);
63} 52}
64 53
65 54static u16 _rtl92e_eeprom_xfer(struct net_device *dev, u16 data, int tx_len)
66static short eprom_r(struct net_device *dev)
67{ 55{
68 short bit; 56 u16 ret = 0;
57 int rx_len = 16;
69 58
70 bit = (read_nic_byte(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT)); 59 _rtl92e_gpio_write_bit(dev, EPROM_CS_BIT, 1);
71 udelay(EPROM_DELAY); 60 _rtl92e_eeprom_ck_cycle(dev);
72 61
73 if (bit) 62 while (tx_len--) {
74 return 1; 63 _rtl92e_gpio_write_bit(dev, EPROM_W_BIT,
75 return 0; 64 (data >> tx_len) & 0x1);
76} 65 _rtl92e_eeprom_ck_cycle(dev);
66 }
77 67
78static void eprom_send_bits_string(struct net_device *dev, short b[], int len) 68 _rtl92e_gpio_write_bit(dev, EPROM_W_BIT, 0);
79{
80 int i;
81 69
82 for (i = 0; i < len; i++) { 70 while (rx_len--) {
83 eprom_w(dev, b[i]); 71 _rtl92e_eeprom_ck_cycle(dev);
84 eprom_ck_cycle(dev); 72 ret |= _rtl92e_gpio_get_bit(dev, EPROM_R_BIT) << rx_len;
85 } 73 }
74
75 _rtl92e_gpio_write_bit(dev, EPROM_CS_BIT, 0);
76 _rtl92e_eeprom_ck_cycle(dev);
77
78 return ret;
86} 79}
87 80
88u32 eprom_read(struct net_device *dev, u32 addr) 81u32 rtl92e_eeprom_read(struct net_device *dev, u32 addr)
89{ 82{
90 struct r8192_priv *priv = rtllib_priv(dev); 83 struct r8192_priv *priv = rtllib_priv(dev);
91 short read_cmd[] = {1, 1, 0}; 84 u32 ret = 0;
92 short addr_str[8];
93 int i;
94 int addr_len;
95 u32 ret;
96
97 ret = 0;
98 write_nic_byte(dev, EPROM_CMD,
99 (EPROM_CMD_PROGRAM << EPROM_CMD_OPERATING_MODE_SHIFT));
100 udelay(EPROM_DELAY);
101 85
102 if (priv->epromtype == EEPROM_93C56) { 86 rtl92e_writeb(dev, EPROM_CMD,
103 addr_str[7] = addr & 1; 87 (EPROM_CMD_PROGRAM << EPROM_CMD_OPERATING_MODE_SHIFT));
104 addr_str[6] = addr & (1<<1); 88 udelay(EPROM_DELAY);
105 addr_str[5] = addr & (1<<2);
106 addr_str[4] = addr & (1<<3);
107 addr_str[3] = addr & (1<<4);
108 addr_str[2] = addr & (1<<5);
109 addr_str[1] = addr & (1<<6);
110 addr_str[0] = addr & (1<<7);
111 addr_len = 8;
112 } else {
113 addr_str[5] = addr & 1;
114 addr_str[4] = addr & (1<<1);
115 addr_str[3] = addr & (1<<2);
116 addr_str[2] = addr & (1<<3);
117 addr_str[1] = addr & (1<<4);
118 addr_str[0] = addr & (1<<5);
119 addr_len = 6;
120 }
121 eprom_cs(dev, 1);
122 eprom_ck_cycle(dev);
123 eprom_send_bits_string(dev, read_cmd, 3);
124 eprom_send_bits_string(dev, addr_str, addr_len);
125
126 eprom_w(dev, 0);
127
128 for (i = 0; i < 16; i++) {
129 eprom_ck_cycle(dev);
130 ret |= (eprom_r(dev)<<(15-i));
131 }
132 89
133 eprom_cs(dev, 0); 90 /* EEPROM is configured as x16 */
134 eprom_ck_cycle(dev); 91 if (priv->epromtype == EEPROM_93C56)
92 ret = _rtl92e_eeprom_xfer(dev, (addr & 0xFF) | (0x6 << 8), 11);
93 else
94 ret = _rtl92e_eeprom_xfer(dev, (addr & 0x3F) | (0x6 << 6), 9);
135 95
136 write_nic_byte(dev, EPROM_CMD, 96 rtl92e_writeb(dev, EPROM_CMD,
137 (EPROM_CMD_NORMAL<<EPROM_CMD_OPERATING_MODE_SHIFT)); 97 (EPROM_CMD_NORMAL<<EPROM_CMD_OPERATING_MODE_SHIFT));
138 return ret; 98 return ret;
139} 99}
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_eeprom.h b/drivers/staging/rtl8192e/rtl8192e/rtl_eeprom.h
index adea2b4c7a44..8d23aea5fb4f 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_eeprom.h
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_eeprom.h
@@ -26,4 +26,4 @@
26 26
27#define EPROM_DELAY 10 27#define EPROM_DELAY 10
28 28
29u32 eprom_read(struct net_device *dev, u32 addr); 29u32 rtl92e_eeprom_read(struct net_device *dev, u32 addr);
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_pci.c b/drivers/staging/rtl8192e/rtl8192e/rtl_pci.c
index 6bbd1c626e24..9fcb099e6edd 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_pci.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_pci.c
@@ -45,7 +45,7 @@ static void rtl8192_parse_pci_configuration(struct pci_dev *pdev,
45 pci_write_config_byte(pdev, 0x70f, tmp); 45 pci_write_config_byte(pdev, 0x70f, tmp);
46} 46}
47 47
48bool rtl8192_pci_findadapter(struct pci_dev *pdev, struct net_device *dev) 48bool rtl92e_check_adapter(struct pci_dev *pdev, struct net_device *dev)
49{ 49{
50 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 50 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
51 u16 VenderID; 51 u16 VenderID;
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_pci.h b/drivers/staging/rtl8192e/rtl8192e/rtl_pci.h
index e8d5527a5f04..6246841bde15 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_pci.h
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_pci.h
@@ -29,6 +29,6 @@
29#include <linux/pci.h> 29#include <linux/pci.h>
30 30
31struct net_device; 31struct net_device;
32bool rtl8192_pci_findadapter(struct pci_dev *pdev, struct net_device *dev); 32bool rtl92e_check_adapter(struct pci_dev *pdev, struct net_device *dev);
33 33
34#endif 34#endif
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_pm.c b/drivers/staging/rtl8192e/rtl8192e/rtl_pm.c
index e4908672421c..b0268fdc100f 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_pm.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_pm.c
@@ -23,7 +23,7 @@
23#include "rtl_pm.h" 23#include "rtl_pm.h"
24 24
25 25
26int rtl8192E_suspend(struct pci_dev *pdev, pm_message_t state) 26int rtl92e_suspend(struct pci_dev *pdev, pm_message_t state)
27{ 27{
28 struct net_device *dev = pci_get_drvdata(pdev); 28 struct net_device *dev = pci_get_drvdata(pdev);
29 struct r8192_priv *priv = rtllib_priv(dev); 29 struct r8192_priv *priv = rtllib_priv(dev);
@@ -45,16 +45,16 @@ int rtl8192E_suspend(struct pci_dev *pdev, pm_message_t state)
45 netif_device_detach(dev); 45 netif_device_detach(dev);
46 46
47 if (!priv->rtllib->bSupportRemoteWakeUp) { 47 if (!priv->rtllib->bSupportRemoteWakeUp) {
48 MgntActSet_RF_State(dev, eRfOff, RF_CHANGE_BY_INIT, true); 48 rtl92e_set_rf_state(dev, eRfOff, RF_CHANGE_BY_INIT);
49 ulRegRead = read_nic_dword(dev, CPU_GEN); 49 ulRegRead = rtl92e_readl(dev, CPU_GEN);
50 ulRegRead |= CPU_GEN_SYSTEM_RESET; 50 ulRegRead |= CPU_GEN_SYSTEM_RESET;
51 write_nic_dword(dev, CPU_GEN, ulRegRead); 51 rtl92e_writel(dev, CPU_GEN, ulRegRead);
52 } else { 52 } else {
53 write_nic_dword(dev, WFCRC0, 0xffffffff); 53 rtl92e_writel(dev, WFCRC0, 0xffffffff);
54 write_nic_dword(dev, WFCRC1, 0xffffffff); 54 rtl92e_writel(dev, WFCRC1, 0xffffffff);
55 write_nic_dword(dev, WFCRC2, 0xffffffff); 55 rtl92e_writel(dev, WFCRC2, 0xffffffff);
56 write_nic_byte(dev, PMR, 0x5); 56 rtl92e_writeb(dev, PMR, 0x5);
57 write_nic_byte(dev, MacBlkCtrl, 0xa); 57 rtl92e_writeb(dev, MacBlkCtrl, 0xa);
58 } 58 }
59out_pci_suspend: 59out_pci_suspend:
60 netdev_info(dev, "WOL is %s\n", priv->rtllib->bSupportRemoteWakeUp ? 60 netdev_info(dev, "WOL is %s\n", priv->rtllib->bSupportRemoteWakeUp ?
@@ -70,7 +70,7 @@ out_pci_suspend:
70 return 0; 70 return 0;
71} 71}
72 72
73int rtl8192E_resume(struct pci_dev *pdev) 73int rtl92e_resume(struct pci_dev *pdev)
74{ 74{
75 struct net_device *dev = pci_get_drvdata(pdev); 75 struct net_device *dev = pci_get_drvdata(pdev);
76 struct r8192_priv *priv = rtllib_priv(dev); 76 struct r8192_priv *priv = rtllib_priv(dev);
@@ -95,7 +95,7 @@ int rtl8192E_resume(struct pci_dev *pdev)
95 pci_enable_wake(pdev, PCI_D0, 0); 95 pci_enable_wake(pdev, PCI_D0, 0);
96 96
97 if (priv->polling_timer_on == 0) 97 if (priv->polling_timer_on == 0)
98 check_rfctrl_gpio_timer((unsigned long)dev); 98 rtl92e_check_rfctrl_gpio_timer((unsigned long)dev);
99 99
100 if (!netif_running(dev)) { 100 if (!netif_running(dev)) {
101 netdev_info(dev, 101 netdev_info(dev,
@@ -108,7 +108,7 @@ int rtl8192E_resume(struct pci_dev *pdev)
108 dev->netdev_ops->ndo_open(dev); 108 dev->netdev_ops->ndo_open(dev);
109 109
110 if (!priv->rtllib->bSupportRemoteWakeUp) 110 if (!priv->rtllib->bSupportRemoteWakeUp)
111 MgntActSet_RF_State(dev, eRfOn, RF_CHANGE_BY_INIT, true); 111 rtl92e_set_rf_state(dev, eRfOn, RF_CHANGE_BY_INIT);
112 112
113out: 113out:
114 RT_TRACE(COMP_POWER, "<================r8192E resume call.\n"); 114 RT_TRACE(COMP_POWER, "<================r8192E resume call.\n");
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_pm.h b/drivers/staging/rtl8192e/rtl8192e/rtl_pm.h
index 7bfe44817f23..cdc45f7fb339 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_pm.h
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_pm.h
@@ -23,7 +23,7 @@
23#include <linux/types.h> 23#include <linux/types.h>
24#include <linux/pci.h> 24#include <linux/pci.h>
25 25
26int rtl8192E_suspend(struct pci_dev *dev, pm_message_t state); 26int rtl92e_suspend(struct pci_dev *dev, pm_message_t state);
27int rtl8192E_resume(struct pci_dev *dev); 27int rtl92e_resume(struct pci_dev *dev);
28 28
29#endif 29#endif
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_ps.c b/drivers/staging/rtl8192e/rtl8192e/rtl_ps.c
index 404cb83153d9..f09560d60dc4 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_ps.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_ps.c
@@ -45,10 +45,10 @@ static void rtl8192_hw_sleep_down(struct net_device *dev)
45 spin_unlock_irqrestore(&priv->rf_ps_lock, flags); 45 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
46 RT_TRACE(COMP_DBG, "%s()============>come to sleep down\n", __func__); 46 RT_TRACE(COMP_DBG, "%s()============>come to sleep down\n", __func__);
47 47
48 MgntActSet_RF_State(dev, eRfSleep, RF_CHANGE_BY_PS, false); 48 rtl92e_set_rf_state(dev, eRfSleep, RF_CHANGE_BY_PS);
49} 49}
50 50
51void rtl8192_hw_sleep_wq(void *data) 51void rtl92e_hw_sleep_wq(void *data)
52{ 52{
53 struct rtllib_device *ieee = container_of_dwork_rsl(data, 53 struct rtllib_device *ieee = container_of_dwork_rsl(data,
54 struct rtllib_device, hw_sleep_wq); 54 struct rtllib_device, hw_sleep_wq);
@@ -57,7 +57,7 @@ void rtl8192_hw_sleep_wq(void *data)
57 rtl8192_hw_sleep_down(dev); 57 rtl8192_hw_sleep_down(dev);
58} 58}
59 59
60void rtl8192_hw_wakeup(struct net_device *dev) 60void rtl92e_hw_wakeup(struct net_device *dev)
61{ 61{
62 struct r8192_priv *priv = rtllib_priv(dev); 62 struct r8192_priv *priv = rtllib_priv(dev);
63 unsigned long flags = 0; 63 unsigned long flags = 0;
@@ -66,7 +66,7 @@ void rtl8192_hw_wakeup(struct net_device *dev)
66 if (priv->RFChangeInProgress) { 66 if (priv->RFChangeInProgress) {
67 spin_unlock_irqrestore(&priv->rf_ps_lock, flags); 67 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
68 RT_TRACE(COMP_DBG, 68 RT_TRACE(COMP_DBG,
69 "rtl8192_hw_wakeup(): RF Change in progress!\n"); 69 "rtl92e_hw_wakeup(): RF Change in progress!\n");
70 queue_delayed_work_rsl(priv->rtllib->wq, 70 queue_delayed_work_rsl(priv->rtllib->wq,
71 &priv->rtllib->hw_wakeup_wq, 71 &priv->rtllib->hw_wakeup_wq,
72 msecs_to_jiffies(10)); 72 msecs_to_jiffies(10));
@@ -74,21 +74,21 @@ void rtl8192_hw_wakeup(struct net_device *dev)
74 } 74 }
75 spin_unlock_irqrestore(&priv->rf_ps_lock, flags); 75 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
76 RT_TRACE(COMP_PS, "%s()============>come to wake up\n", __func__); 76 RT_TRACE(COMP_PS, "%s()============>come to wake up\n", __func__);
77 MgntActSet_RF_State(dev, eRfOn, RF_CHANGE_BY_PS, false); 77 rtl92e_set_rf_state(dev, eRfOn, RF_CHANGE_BY_PS);
78} 78}
79 79
80void rtl8192_hw_wakeup_wq(void *data) 80void rtl92e_hw_wakeup_wq(void *data)
81{ 81{
82 struct rtllib_device *ieee = container_of_dwork_rsl(data, 82 struct rtllib_device *ieee = container_of_dwork_rsl(data,
83 struct rtllib_device, hw_wakeup_wq); 83 struct rtllib_device, hw_wakeup_wq);
84 struct net_device *dev = ieee->dev; 84 struct net_device *dev = ieee->dev;
85 85
86 rtl8192_hw_wakeup(dev); 86 rtl92e_hw_wakeup(dev);
87} 87}
88 88
89#define MIN_SLEEP_TIME 50 89#define MIN_SLEEP_TIME 50
90#define MAX_SLEEP_TIME 10000 90#define MAX_SLEEP_TIME 10000
91void rtl8192_hw_to_sleep(struct net_device *dev, u64 time) 91void rtl92e_enter_sleep(struct net_device *dev, u64 time)
92{ 92{
93 struct r8192_priv *priv = rtllib_priv(dev); 93 struct r8192_priv *priv = rtllib_priv(dev);
94 94
@@ -133,14 +133,13 @@ static void InactivePsWorkItemCallback(struct net_device *dev)
133 133
134 RT_TRACE(COMP_PS, "InactivePsWorkItemCallback(): Set RF to %s.\n", 134 RT_TRACE(COMP_PS, "InactivePsWorkItemCallback(): Set RF to %s.\n",
135 pPSC->eInactivePowerState == eRfOff ? "OFF" : "ON"); 135 pPSC->eInactivePowerState == eRfOff ? "OFF" : "ON");
136 MgntActSet_RF_State(dev, pPSC->eInactivePowerState, RF_CHANGE_BY_IPS, 136 rtl92e_set_rf_state(dev, pPSC->eInactivePowerState, RF_CHANGE_BY_IPS);
137 false);
138 137
139 pPSC->bSwRfProcessing = false; 138 pPSC->bSwRfProcessing = false;
140 RT_TRACE(COMP_PS, "InactivePsWorkItemCallback() <---------\n"); 139 RT_TRACE(COMP_PS, "InactivePsWorkItemCallback() <---------\n");
141} 140}
142 141
143void IPSEnter(struct net_device *dev) 142void rtl92e_ips_enter(struct net_device *dev)
144{ 143{
145 struct r8192_priv *priv = rtllib_priv(dev); 144 struct r8192_priv *priv = rtllib_priv(dev);
146 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *) 145 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
@@ -152,7 +151,7 @@ void IPSEnter(struct net_device *dev)
152 if (rtState == eRfOn && !pPSC->bSwRfProcessing && 151 if (rtState == eRfOn && !pPSC->bSwRfProcessing &&
153 (priv->rtllib->state != RTLLIB_LINKED) && 152 (priv->rtllib->state != RTLLIB_LINKED) &&
154 (priv->rtllib->iw_mode != IW_MODE_MASTER)) { 153 (priv->rtllib->iw_mode != IW_MODE_MASTER)) {
155 RT_TRACE(COMP_PS, "IPSEnter(): Turn off RF.\n"); 154 RT_TRACE(COMP_PS, "rtl92e_ips_enter(): Turn off RF.\n");
156 pPSC->eInactivePowerState = eRfOff; 155 pPSC->eInactivePowerState = eRfOff;
157 priv->isRFOff = true; 156 priv->isRFOff = true;
158 priv->bInPowerSaveMode = true; 157 priv->bInPowerSaveMode = true;
@@ -161,7 +160,7 @@ void IPSEnter(struct net_device *dev)
161 } 160 }
162} 161}
163 162
164void IPSLeave(struct net_device *dev) 163void rtl92e_ips_leave(struct net_device *dev)
165{ 164{
166 struct r8192_priv *priv = rtllib_priv(dev); 165 struct r8192_priv *priv = rtllib_priv(dev);
167 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *) 166 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
@@ -172,7 +171,7 @@ void IPSLeave(struct net_device *dev)
172 rtState = priv->rtllib->eRFPowerState; 171 rtState = priv->rtllib->eRFPowerState;
173 if (rtState != eRfOn && !pPSC->bSwRfProcessing && 172 if (rtState != eRfOn && !pPSC->bSwRfProcessing &&
174 priv->rtllib->RfOffReason <= RF_CHANGE_BY_IPS) { 173 priv->rtllib->RfOffReason <= RF_CHANGE_BY_IPS) {
175 RT_TRACE(COMP_PS, "IPSLeave(): Turn on RF.\n"); 174 RT_TRACE(COMP_PS, "rtl92e_ips_leave(): Turn on RF.\n");
176 pPSC->eInactivePowerState = eRfOn; 175 pPSC->eInactivePowerState = eRfOn;
177 priv->bInPowerSaveMode = false; 176 priv->bInPowerSaveMode = false;
178 InactivePsWorkItemCallback(dev); 177 InactivePsWorkItemCallback(dev);
@@ -180,7 +179,7 @@ void IPSLeave(struct net_device *dev)
180 } 179 }
181} 180}
182 181
183void IPSLeave_wq(void *data) 182void rtl92e_ips_leave_wq(void *data)
184{ 183{
185 struct rtllib_device *ieee = container_of_work_rsl(data, 184 struct rtllib_device *ieee = container_of_work_rsl(data,
186 struct rtllib_device, ips_leave_wq); 185 struct rtllib_device, ips_leave_wq);
@@ -188,11 +187,11 @@ void IPSLeave_wq(void *data)
188 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 187 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
189 188
190 down(&priv->rtllib->ips_sem); 189 down(&priv->rtllib->ips_sem);
191 IPSLeave(dev); 190 rtl92e_ips_leave(dev);
192 up(&priv->rtllib->ips_sem); 191 up(&priv->rtllib->ips_sem);
193} 192}
194 193
195void rtllib_ips_leave_wq(struct net_device *dev) 194void rtl92e_rtllib_ips_leave_wq(struct net_device *dev)
196{ 195{
197 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 196 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
198 enum rt_rf_power_state rtState; 197 enum rt_rf_power_state rtState;
@@ -206,7 +205,7 @@ void rtllib_ips_leave_wq(struct net_device *dev)
206 __func__); 205 __func__);
207 return; 206 return;
208 } 207 }
209 netdev_info(dev, "=========>%s(): IPSLeave\n", 208 netdev_info(dev, "=========>%s(): rtl92e_ips_leave\n",
210 __func__); 209 __func__);
211 queue_work_rsl(priv->rtllib->wq, 210 queue_work_rsl(priv->rtllib->wq,
212 &priv->rtllib->ips_leave_wq); 211 &priv->rtllib->ips_leave_wq);
@@ -214,12 +213,12 @@ void rtllib_ips_leave_wq(struct net_device *dev)
214 } 213 }
215} 214}
216 215
217void rtllib_ips_leave(struct net_device *dev) 216void rtl92e_rtllib_ips_leave(struct net_device *dev)
218{ 217{
219 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev); 218 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
220 219
221 down(&priv->rtllib->ips_sem); 220 down(&priv->rtllib->ips_sem);
222 IPSLeave(dev); 221 rtl92e_ips_leave(dev);
223 up(&priv->rtllib->ips_sem); 222 up(&priv->rtllib->ips_sem);
224} 223}
225 224
@@ -238,7 +237,7 @@ static bool MgntActSet_802_11_PowerSaveMode(struct net_device *dev,
238 rtPsMode == RTLLIB_PS_DISABLED) { 237 rtPsMode == RTLLIB_PS_DISABLED) {
239 unsigned long flags; 238 unsigned long flags;
240 239
241 rtl8192_hw_wakeup(dev); 240 rtl92e_hw_wakeup(dev);
242 priv->rtllib->sta_sleep = LPS_IS_WAKE; 241 priv->rtllib->sta_sleep = LPS_IS_WAKE;
243 242
244 spin_lock_irqsave(&(priv->rtllib->mgmt_tx_lock), flags); 243 spin_lock_irqsave(&(priv->rtllib->mgmt_tx_lock), flags);
@@ -251,13 +250,13 @@ static bool MgntActSet_802_11_PowerSaveMode(struct net_device *dev,
251 return true; 250 return true;
252} 251}
253 252
254void LeisurePSEnter(struct net_device *dev) 253void rtl92e_leisure_ps_enter(struct net_device *dev)
255{ 254{
256 struct r8192_priv *priv = rtllib_priv(dev); 255 struct r8192_priv *priv = rtllib_priv(dev);
257 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *) 256 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
258 &(priv->rtllib->PowerSaveControl); 257 &(priv->rtllib->PowerSaveControl);
259 258
260 RT_TRACE(COMP_PS, "LeisurePSEnter()...\n"); 259 RT_TRACE(COMP_PS, "rtl92e_leisure_ps_enter()...\n");
261 RT_TRACE(COMP_PS, 260 RT_TRACE(COMP_PS,
262 "pPSC->bLeisurePs = %d, ieee->ps = %d,pPSC->LpsIdleCount is %d,RT_CHECK_FOR_HANG_PERIOD is %d\n", 261 "pPSC->bLeisurePs = %d, ieee->ps = %d,pPSC->LpsIdleCount is %d,RT_CHECK_FOR_HANG_PERIOD is %d\n",
263 pPSC->bLeisurePs, priv->rtllib->ps, pPSC->LpsIdleCount, 262 pPSC->bLeisurePs, priv->rtllib->ps, pPSC->LpsIdleCount,
@@ -275,7 +274,7 @@ void LeisurePSEnter(struct net_device *dev)
275 if (priv->rtllib->ps == RTLLIB_PS_DISABLED) { 274 if (priv->rtllib->ps == RTLLIB_PS_DISABLED) {
276 275
277 RT_TRACE(COMP_LPS, 276 RT_TRACE(COMP_LPS,
278 "LeisurePSEnter(): Enter 802.11 power save mode...\n"); 277 "rtl92e_leisure_ps_enter(): Enter 802.11 power save mode...\n");
279 278
280 if (!pPSC->bFwCtrlLPS) { 279 if (!pPSC->bFwCtrlLPS) {
281 if (priv->rtllib->SetFwCmdHandler) 280 if (priv->rtllib->SetFwCmdHandler)
@@ -291,21 +290,21 @@ void LeisurePSEnter(struct net_device *dev)
291 } 290 }
292} 291}
293 292
294void LeisurePSLeave(struct net_device *dev) 293void rtl92e_leisure_ps_leave(struct net_device *dev)
295{ 294{
296 struct r8192_priv *priv = rtllib_priv(dev); 295 struct r8192_priv *priv = rtllib_priv(dev);
297 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *) 296 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
298 &(priv->rtllib->PowerSaveControl); 297 &(priv->rtllib->PowerSaveControl);
299 298
300 299
301 RT_TRACE(COMP_PS, "LeisurePSLeave()...\n"); 300 RT_TRACE(COMP_PS, "rtl92e_leisure_ps_leave()...\n");
302 RT_TRACE(COMP_PS, "pPSC->bLeisurePs = %d, ieee->ps = %d\n", 301 RT_TRACE(COMP_PS, "pPSC->bLeisurePs = %d, ieee->ps = %d\n",
303 pPSC->bLeisurePs, priv->rtllib->ps); 302 pPSC->bLeisurePs, priv->rtllib->ps);
304 303
305 if (pPSC->bLeisurePs) { 304 if (pPSC->bLeisurePs) {
306 if (priv->rtllib->ps != RTLLIB_PS_DISABLED) { 305 if (priv->rtllib->ps != RTLLIB_PS_DISABLED) {
307 RT_TRACE(COMP_LPS, 306 RT_TRACE(COMP_LPS,
308 "LeisurePSLeave(): Busy Traffic , Leave 802.11 power save..\n"); 307 "rtl92e_leisure_ps_leave(): Busy Traffic , Leave 802.11 power save..\n");
309 MgntActSet_802_11_PowerSaveMode(dev, 308 MgntActSet_802_11_PowerSaveMode(dev,
310 RTLLIB_PS_DISABLED); 309 RTLLIB_PS_DISABLED);
311 310
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_ps.h b/drivers/staging/rtl8192e/rtl8192e/rtl_ps.h
index 962f2e5b8bf8..35fc9e2a3365 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_ps.h
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_ps.h
@@ -30,18 +30,17 @@
30struct net_device; 30struct net_device;
31 31
32#define RT_CHECK_FOR_HANG_PERIOD 2 32#define RT_CHECK_FOR_HANG_PERIOD 2
33#define INIT_DEFAULT_CHAN 1
34 33
35void rtl8192_hw_wakeup(struct net_device *dev); 34void rtl92e_hw_wakeup(struct net_device *dev);
36void rtl8192_hw_to_sleep(struct net_device *dev, u64 time); 35void rtl92e_enter_sleep(struct net_device *dev, u64 time);
37void rtllib_ips_leave_wq(struct net_device *dev); 36void rtl92e_rtllib_ips_leave_wq(struct net_device *dev);
38void rtllib_ips_leave(struct net_device *dev); 37void rtl92e_rtllib_ips_leave(struct net_device *dev);
39void IPSLeave_wq(void *data); 38void rtl92e_ips_leave_wq(void *data);
40 39
41void IPSEnter(struct net_device *dev); 40void rtl92e_ips_enter(struct net_device *dev);
42void IPSLeave(struct net_device *dev); 41void rtl92e_ips_leave(struct net_device *dev);
43 42
44void LeisurePSEnter(struct net_device *dev); 43void rtl92e_leisure_ps_enter(struct net_device *dev);
45void LeisurePSLeave(struct net_device *dev); 44void rtl92e_leisure_ps_leave(struct net_device *dev);
46 45
47#endif 46#endif
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_wx.c b/drivers/staging/rtl8192e/rtl8192e/rtl_wx.c
index f5e4961677d2..7e3ca7ef997b 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_wx.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_wx.c
@@ -192,7 +192,7 @@ static int r8192_wx_adapter_power_status(struct net_device *dev,
192 pPSC->bLeisurePs = true; 192 pPSC->bLeisurePs = true;
193 } else { 193 } else {
194 if (priv->rtllib->state == RTLLIB_LINKED) 194 if (priv->rtllib->state == RTLLIB_LINKED)
195 LeisurePSLeave(dev); 195 rtl92e_leisure_ps_leave(dev);
196 196
197 priv->ps_force = true; 197 priv->ps_force = true;
198 pPSC->bLeisurePs = false; 198 pPSC->bLeisurePs = false;
@@ -282,10 +282,11 @@ static int r8192_wx_set_mode(struct net_device *dev, struct iw_request_info *a,
282 up(&priv->wx_sem); 282 up(&priv->wx_sem);
283 return -1; 283 return -1;
284 } 284 }
285 netdev_info(dev, "=========>%s(): IPSLeave\n", 285 netdev_info(dev,
286 "=========>%s(): rtl92e_ips_leave\n",
286 __func__); 287 __func__);
287 down(&priv->rtllib->ips_sem); 288 down(&priv->rtllib->ips_sem);
288 IPSLeave(dev); 289 rtl92e_ips_leave(dev);
289 up(&priv->rtllib->ips_sem); 290 up(&priv->rtllib->ips_sem);
290 } 291 }
291 } 292 }
@@ -442,10 +443,11 @@ static int r8192_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
442 up(&priv->wx_sem); 443 up(&priv->wx_sem);
443 return -1; 444 return -1;
444 } 445 }
445 RT_TRACE(COMP_PS, "=========>%s(): IPSLeave\n", 446 RT_TRACE(COMP_PS,
447 "=========>%s(): rtl92e_ips_leave\n",
446 __func__); 448 __func__);
447 down(&priv->rtllib->ips_sem); 449 down(&priv->rtllib->ips_sem);
448 IPSLeave(dev); 450 rtl92e_ips_leave(dev);
449 up(&priv->rtllib->ips_sem); 451 up(&priv->rtllib->ips_sem);
450 } 452 }
451 } 453 }
@@ -700,7 +702,7 @@ static int r8192_wx_set_enc(struct net_device *dev,
700 702
701 priv->rtllib->wx_set_enc = 1; 703 priv->rtllib->wx_set_enc = 1;
702 down(&priv->rtllib->ips_sem); 704 down(&priv->rtllib->ips_sem);
703 IPSLeave(dev); 705 rtl92e_ips_leave(dev);
704 up(&priv->rtllib->ips_sem); 706 up(&priv->rtllib->ips_sem);
705 down(&priv->wx_sem); 707 down(&priv->wx_sem);
706 708
@@ -711,7 +713,7 @@ static int r8192_wx_set_enc(struct net_device *dev,
711 713
712 if (wrqu->encoding.flags & IW_ENCODE_DISABLED) { 714 if (wrqu->encoding.flags & IW_ENCODE_DISABLED) {
713 ieee->pairwise_key_type = ieee->group_key_type = KEY_TYPE_NA; 715 ieee->pairwise_key_type = ieee->group_key_type = KEY_TYPE_NA;
714 CamResetAllEntry(dev); 716 rtl92e_cam_reset(dev);
715 memset(priv->rtllib->swcamtable, 0, 717 memset(priv->rtllib->swcamtable, 0,
716 sizeof(struct sw_cam_table) * 32); 718 sizeof(struct sw_cam_table) * 32);
717 goto end_hw_sec; 719 goto end_hw_sec;
@@ -729,9 +731,6 @@ static int r8192_wx_set_enc(struct net_device *dev,
729 hwkey[i] |= (key[4 * i + 3] & mask) << 24; 731 hwkey[i] |= (key[4 * i + 3] & mask) << 24;
730 } 732 }
731 733
732 #define CONF_WEP40 0x4
733 #define CONF_WEP104 0x14
734
735 switch (wrqu->encoding.flags & IW_ENCODE_INDEX) { 734 switch (wrqu->encoding.flags & IW_ENCODE_INDEX) {
736 case 0: 735 case 0:
737 key_idx = ieee->crypt_info.tx_keyidx; 736 key_idx = ieee->crypt_info.tx_keyidx;
@@ -753,16 +752,16 @@ static int r8192_wx_set_enc(struct net_device *dev,
753 } 752 }
754 if (wrqu->encoding.length == 0x5) { 753 if (wrqu->encoding.length == 0x5) {
755 ieee->pairwise_key_type = KEY_TYPE_WEP40; 754 ieee->pairwise_key_type = KEY_TYPE_WEP40;
756 EnableHWSecurityConfig8192(dev); 755 rtl92e_enable_hw_security_config(dev);
757 } 756 }
758 757
759 else if (wrqu->encoding.length == 0xd) { 758 else if (wrqu->encoding.length == 0xd) {
760 ieee->pairwise_key_type = KEY_TYPE_WEP104; 759 ieee->pairwise_key_type = KEY_TYPE_WEP104;
761 EnableHWSecurityConfig8192(dev); 760 rtl92e_enable_hw_security_config(dev);
762 setKey(dev, key_idx, key_idx, KEY_TYPE_WEP104, 761 rtl92e_set_key(dev, key_idx, key_idx, KEY_TYPE_WEP104,
763 zero_addr[key_idx], 0, hwkey); 762 zero_addr[key_idx], 0, hwkey);
764 set_swcam(dev, key_idx, key_idx, KEY_TYPE_WEP104, 763 rtl92e_set_swcam(dev, key_idx, key_idx, KEY_TYPE_WEP104,
765 zero_addr[key_idx], 0, hwkey, 0); 764 zero_addr[key_idx], 0, hwkey, 0);
766 } else { 765 } else {
767 netdev_info(dev, 766 netdev_info(dev,
768 "wrong type in WEP, not WEP40 and WEP104\n"); 767 "wrong type in WEP, not WEP40 and WEP104\n");
@@ -821,17 +820,13 @@ static int r8192_wx_set_retry(struct net_device *dev,
821 } 820 }
822 if (wrqu->retry.flags & IW_RETRY_MAX) { 821 if (wrqu->retry.flags & IW_RETRY_MAX) {
823 priv->retry_rts = wrqu->retry.value; 822 priv->retry_rts = wrqu->retry.value;
824 DMESG("Setting retry for RTS/CTS data to %d",
825 wrqu->retry.value);
826 823
827 } else { 824 } else {
828 priv->retry_data = wrqu->retry.value; 825 priv->retry_data = wrqu->retry.value;
829 DMESG("Setting retry for non RTS/CTS data to %d",
830 wrqu->retry.value);
831 } 826 }
832 827
833 828
834 rtl8192_commit(dev); 829 rtl92e_commit(dev);
835exit: 830exit:
836 up(&priv->wx_sem); 831 up(&priv->wx_sem);
837 832
@@ -917,7 +912,7 @@ static int r8192_wx_set_enc_ext(struct net_device *dev,
917 912
918 priv->rtllib->wx_set_enc = 1; 913 priv->rtllib->wx_set_enc = 1;
919 down(&priv->rtllib->ips_sem); 914 down(&priv->rtllib->ips_sem);
920 IPSLeave(dev); 915 rtl92e_ips_leave(dev);
921 up(&priv->rtllib->ips_sem); 916 up(&priv->rtllib->ips_sem);
922 917
923 ret = rtllib_wx_set_encode_ext(ieee, info, wrqu, extra); 918 ret = rtllib_wx_set_encode_ext(ieee, info, wrqu, extra);
@@ -933,7 +928,7 @@ static int r8192_wx_set_enc_ext(struct net_device *dev,
933 ext->alg == IW_ENCODE_ALG_NONE) { 928 ext->alg == IW_ENCODE_ALG_NONE) {
934 ieee->pairwise_key_type = ieee->group_key_type 929 ieee->pairwise_key_type = ieee->group_key_type
935 = KEY_TYPE_NA; 930 = KEY_TYPE_NA;
936 CamResetAllEntry(dev); 931 rtl92e_cam_reset(dev);
937 memset(priv->rtllib->swcamtable, 0, 932 memset(priv->rtllib->swcamtable, 0,
938 sizeof(struct sw_cam_table) * 32); 933 sizeof(struct sw_cam_table) * 32);
939 goto end_hw_sec; 934 goto end_hw_sec;
@@ -950,28 +945,29 @@ static int r8192_wx_set_enc_ext(struct net_device *dev,
950 if ((ext->key_len == 13) && (alg == KEY_TYPE_WEP40)) 945 if ((ext->key_len == 13) && (alg == KEY_TYPE_WEP40))
951 alg = KEY_TYPE_WEP104; 946 alg = KEY_TYPE_WEP104;
952 ieee->pairwise_key_type = alg; 947 ieee->pairwise_key_type = alg;
953 EnableHWSecurityConfig8192(dev); 948 rtl92e_enable_hw_security_config(dev);
954 } 949 }
955 memcpy((u8 *)key, ext->key, 16); 950 memcpy((u8 *)key, ext->key, 16);
956 951
957 if ((alg & KEY_TYPE_WEP40) && (ieee->auth_mode != 2)) { 952 if ((alg & KEY_TYPE_WEP40) && (ieee->auth_mode != 2)) {
958 if (ext->key_len == 13) 953 if (ext->key_len == 13)
959 ieee->pairwise_key_type = alg = KEY_TYPE_WEP104; 954 ieee->pairwise_key_type = alg = KEY_TYPE_WEP104;
960 setKey(dev, idx, idx, alg, zero, 0, key); 955 rtl92e_set_key(dev, idx, idx, alg, zero, 0, key);
961 set_swcam(dev, idx, idx, alg, zero, 0, key, 0); 956 rtl92e_set_swcam(dev, idx, idx, alg, zero, 0, key, 0);
962 } else if (group) { 957 } else if (group) {
963 ieee->group_key_type = alg; 958 ieee->group_key_type = alg;
964 setKey(dev, idx, idx, alg, broadcast_addr, 0, key); 959 rtl92e_set_key(dev, idx, idx, alg, broadcast_addr, 0,
965 set_swcam(dev, idx, idx, alg, broadcast_addr, 0, 960 key);
966 key, 0); 961 rtl92e_set_swcam(dev, idx, idx, alg, broadcast_addr, 0,
962 key, 0);
967 } else { 963 } else {
968 if ((ieee->pairwise_key_type == KEY_TYPE_CCMP) && 964 if ((ieee->pairwise_key_type == KEY_TYPE_CCMP) &&
969 ieee->pHTInfo->bCurrentHTSupport) 965 ieee->pHTInfo->bCurrentHTSupport)
970 write_nic_byte(dev, 0x173, 1); 966 rtl92e_writeb(dev, 0x173, 1);
971 setKey(dev, 4, idx, alg, (u8 *)ieee->ap_mac_addr, 967 rtl92e_set_key(dev, 4, idx, alg,
972 0, key); 968 (u8 *)ieee->ap_mac_addr, 0, key);
973 set_swcam(dev, 4, idx, alg, (u8 *)ieee->ap_mac_addr, 969 rtl92e_set_swcam(dev, 4, idx, alg,
974 0, key, 0); 970 (u8 *)ieee->ap_mac_addr, 0, key, 0);
975 } 971 }
976 972
977 973
@@ -1119,41 +1115,41 @@ static int r8192_wx_get_PromiscuousMode(struct net_device *dev,
1119} 1115}
1120 1116
1121 1117
1122#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] 1118#define IW_IOCTL(x) ((x) - SIOCSIWCOMMIT)
1123static iw_handler r8192_wx_handlers[] = { 1119static iw_handler r8192_wx_handlers[] = {
1124 IW_IOCTL(SIOCGIWNAME) = r8192_wx_get_name, 1120 [IW_IOCTL(SIOCGIWNAME)] = r8192_wx_get_name,
1125 IW_IOCTL(SIOCSIWFREQ) = r8192_wx_set_freq, 1121 [IW_IOCTL(SIOCSIWFREQ)] = r8192_wx_set_freq,
1126 IW_IOCTL(SIOCGIWFREQ) = r8192_wx_get_freq, 1122 [IW_IOCTL(SIOCGIWFREQ)] = r8192_wx_get_freq,
1127 IW_IOCTL(SIOCSIWMODE) = r8192_wx_set_mode, 1123 [IW_IOCTL(SIOCSIWMODE)] = r8192_wx_set_mode,
1128 IW_IOCTL(SIOCGIWMODE) = r8192_wx_get_mode, 1124 [IW_IOCTL(SIOCGIWMODE)] = r8192_wx_get_mode,
1129 IW_IOCTL(SIOCSIWSENS) = r8192_wx_set_sens, 1125 [IW_IOCTL(SIOCSIWSENS)] = r8192_wx_set_sens,
1130 IW_IOCTL(SIOCGIWSENS) = r8192_wx_get_sens, 1126 [IW_IOCTL(SIOCGIWSENS)] = r8192_wx_get_sens,
1131 IW_IOCTL(SIOCGIWRANGE) = rtl8192_wx_get_range, 1127 [IW_IOCTL(SIOCGIWRANGE)] = rtl8192_wx_get_range,
1132 IW_IOCTL(SIOCSIWAP) = r8192_wx_set_wap, 1128 [IW_IOCTL(SIOCSIWAP)] = r8192_wx_set_wap,
1133 IW_IOCTL(SIOCGIWAP) = r8192_wx_get_wap, 1129 [IW_IOCTL(SIOCGIWAP)] = r8192_wx_get_wap,
1134 IW_IOCTL(SIOCSIWSCAN) = r8192_wx_set_scan, 1130 [IW_IOCTL(SIOCSIWSCAN)] = r8192_wx_set_scan,
1135 IW_IOCTL(SIOCGIWSCAN) = r8192_wx_get_scan, 1131 [IW_IOCTL(SIOCGIWSCAN)] = r8192_wx_get_scan,
1136 IW_IOCTL(SIOCSIWESSID) = r8192_wx_set_essid, 1132 [IW_IOCTL(SIOCSIWESSID)] = r8192_wx_set_essid,
1137 IW_IOCTL(SIOCGIWESSID) = r8192_wx_get_essid, 1133 [IW_IOCTL(SIOCGIWESSID)] = r8192_wx_get_essid,
1138 IW_IOCTL(SIOCSIWNICKN) = r8192_wx_set_nick, 1134 [IW_IOCTL(SIOCSIWNICKN)] = r8192_wx_set_nick,
1139 IW_IOCTL(SIOCGIWNICKN) = r8192_wx_get_nick, 1135 [IW_IOCTL(SIOCGIWNICKN)] = r8192_wx_get_nick,
1140 IW_IOCTL(SIOCSIWRATE) = r8192_wx_set_rate, 1136 [IW_IOCTL(SIOCSIWRATE)] = r8192_wx_set_rate,
1141 IW_IOCTL(SIOCGIWRATE) = r8192_wx_get_rate, 1137 [IW_IOCTL(SIOCGIWRATE)] = r8192_wx_get_rate,
1142 IW_IOCTL(SIOCSIWRTS) = r8192_wx_set_rts, 1138 [IW_IOCTL(SIOCSIWRTS)] = r8192_wx_set_rts,
1143 IW_IOCTL(SIOCGIWRTS) = r8192_wx_get_rts, 1139 [IW_IOCTL(SIOCGIWRTS)] = r8192_wx_get_rts,
1144 IW_IOCTL(SIOCSIWFRAG) = r8192_wx_set_frag, 1140 [IW_IOCTL(SIOCSIWFRAG)] = r8192_wx_set_frag,
1145 IW_IOCTL(SIOCGIWFRAG) = r8192_wx_get_frag, 1141 [IW_IOCTL(SIOCGIWFRAG)] = r8192_wx_get_frag,
1146 IW_IOCTL(SIOCSIWRETRY) = r8192_wx_set_retry, 1142 [IW_IOCTL(SIOCSIWRETRY)] = r8192_wx_set_retry,
1147 IW_IOCTL(SIOCGIWRETRY) = r8192_wx_get_retry, 1143 [IW_IOCTL(SIOCGIWRETRY)] = r8192_wx_get_retry,
1148 IW_IOCTL(SIOCSIWENCODE) = r8192_wx_set_enc, 1144 [IW_IOCTL(SIOCSIWENCODE)] = r8192_wx_set_enc,
1149 IW_IOCTL(SIOCGIWENCODE) = r8192_wx_get_enc, 1145 [IW_IOCTL(SIOCGIWENCODE)] = r8192_wx_get_enc,
1150 IW_IOCTL(SIOCSIWPOWER) = r8192_wx_set_power, 1146 [IW_IOCTL(SIOCSIWPOWER)] = r8192_wx_set_power,
1151 IW_IOCTL(SIOCGIWPOWER) = r8192_wx_get_power, 1147 [IW_IOCTL(SIOCGIWPOWER)] = r8192_wx_get_power,
1152 IW_IOCTL(SIOCSIWGENIE) = r8192_wx_set_gen_ie, 1148 [IW_IOCTL(SIOCSIWGENIE)] = r8192_wx_set_gen_ie,
1153 IW_IOCTL(SIOCGIWGENIE) = r8192_wx_get_gen_ie, 1149 [IW_IOCTL(SIOCGIWGENIE)] = r8192_wx_get_gen_ie,
1154 IW_IOCTL(SIOCSIWMLME) = r8192_wx_set_mlme, 1150 [IW_IOCTL(SIOCSIWMLME)] = r8192_wx_set_mlme,
1155 IW_IOCTL(SIOCSIWAUTH) = r8192_wx_set_auth, 1151 [IW_IOCTL(SIOCSIWAUTH)] = r8192_wx_set_auth,
1156 IW_IOCTL(SIOCSIWENCODEEXT) = r8192_wx_set_enc_ext, 1152 [IW_IOCTL(SIOCSIWENCODEEXT)] = r8192_wx_set_enc_ext,
1157}; 1153};
1158 1154
1159/* the following rule need to be following, 1155/* the following rule need to be following,
diff --git a/drivers/staging/rtl8192e/rtl819x_BA.h b/drivers/staging/rtl8192e/rtl819x_BA.h
index 613e14c12df3..894666465152 100644
--- a/drivers/staging/rtl8192e/rtl819x_BA.h
+++ b/drivers/staging/rtl8192e/rtl819x_BA.h
@@ -19,11 +19,7 @@
19#ifndef _BATYPE_H_ 19#ifndef _BATYPE_H_
20#define _BATYPE_H_ 20#define _BATYPE_H_
21 21
22#define TOTAL_TXBA_NUM 16
23#define TOTAL_RXBA_NUM 16
24
25#define BA_SETUP_TIMEOUT 200 22#define BA_SETUP_TIMEOUT 200
26#define BA_INACT_TIMEOUT 60000
27 23
28#define BA_POLICY_DELAYED 0 24#define BA_POLICY_DELAYED 0
29#define BA_POLICY_IMMEDIATE 1 25#define BA_POLICY_IMMEDIATE 1
@@ -32,7 +28,6 @@
32#define ADDBA_STATUS_REFUSED 37 28#define ADDBA_STATUS_REFUSED 37
33#define ADDBA_STATUS_INVALID_PARAM 38 29#define ADDBA_STATUS_INVALID_PARAM 38
34 30
35#define DELBA_REASON_QSTA_LEAVING 36
36#define DELBA_REASON_END_BA 37 31#define DELBA_REASON_END_BA 37
37#define DELBA_REASON_UNKNOWN_BA 38 32#define DELBA_REASON_UNKNOWN_BA 38
38#define DELBA_REASON_TIMEOUT 39 33#define DELBA_REASON_TIMEOUT 39
diff --git a/drivers/staging/rtl8192e/rtl819x_BAProc.c b/drivers/staging/rtl8192e/rtl819x_BAProc.c
index 60f536c295ab..78ede4a817fc 100644
--- a/drivers/staging/rtl8192e/rtl819x_BAProc.c
+++ b/drivers/staging/rtl8192e/rtl819x_BAProc.c
@@ -428,7 +428,6 @@ int rtllib_rx_DELBA(struct rtllib_device *ieee, struct sk_buff *skb)
428{ 428{
429 struct rtllib_hdr_3addr *delba = NULL; 429 struct rtllib_hdr_3addr *delba = NULL;
430 union delba_param_set *pDelBaParamSet = NULL; 430 union delba_param_set *pDelBaParamSet = NULL;
431 u16 *pReasonCode = NULL;
432 u8 *dst = NULL; 431 u8 *dst = NULL;
433 432
434 if (skb->len < sizeof(struct rtllib_hdr_3addr) + 6) { 433 if (skb->len < sizeof(struct rtllib_hdr_3addr) + 6) {
@@ -453,9 +452,7 @@ int rtllib_rx_DELBA(struct rtllib_device *ieee, struct sk_buff *skb)
453#endif 452#endif
454 delba = (struct rtllib_hdr_3addr *)skb->data; 453 delba = (struct rtllib_hdr_3addr *)skb->data;
455 dst = (u8 *)(&delba->addr2[0]); 454 dst = (u8 *)(&delba->addr2[0]);
456 delba += sizeof(struct rtllib_hdr_3addr); 455 pDelBaParamSet = (union delba_param_set *)&delba->payload[2];
457 pDelBaParamSet = (union delba_param_set *)(delba+2);
458 pReasonCode = (u16 *)(delba+4);
459 456
460 if (pDelBaParamSet->field.Initiator == 1) { 457 if (pDelBaParamSet->field.Initiator == 1) {
461 struct rx_ts_record *pRxTs; 458 struct rx_ts_record *pRxTs;
diff --git a/drivers/staging/rtl8192e/rtl819x_HT.h b/drivers/staging/rtl8192e/rtl819x_HT.h
index 0c263d9f7246..51711dcdc8ef 100644
--- a/drivers/staging/rtl8192e/rtl819x_HT.h
+++ b/drivers/staging/rtl8192e/rtl819x_HT.h
@@ -20,8 +20,6 @@
20#define _RTL819XU_HTTYPE_H_ 20#define _RTL819XU_HTTYPE_H_
21 21
22#define MIMO_PS_STATIC 0 22#define MIMO_PS_STATIC 0
23#define MIMO_PS_DYNAMIC 1
24#define MIMO_PS_NOLIMIT 3
25 23
26#define sHTCLng 4 24#define sHTCLng 4
27 25
diff --git a/drivers/staging/rtl8192e/rtl819x_HTProc.c b/drivers/staging/rtl8192e/rtl819x_HTProc.c
index b5c3647b0f80..555745b2a75e 100644
--- a/drivers/staging/rtl8192e/rtl819x_HTProc.c
+++ b/drivers/staging/rtl8192e/rtl819x_HTProc.c
@@ -117,7 +117,7 @@ void HTUpdateDefaultSetting(struct rtllib_device *ieee)
117 pHTInfo->RxReorderPendingTime = 30; 117 pHTInfo->RxReorderPendingTime = 30;
118} 118}
119 119
120u16 HTMcsToDataRate(struct rtllib_device *ieee, u8 nMcsRate) 120static u16 HTMcsToDataRate(struct rtllib_device *ieee, u8 nMcsRate)
121{ 121{
122 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; 122 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
123 123
@@ -502,7 +502,8 @@ u8 HTGetHighestMCSRate(struct rtllib_device *ieee, u8 *pMCSRateSet,
502 return mcsRate | 0x80; 502 return mcsRate | 0x80;
503} 503}
504 504
505u8 HTFilterMCSRate(struct rtllib_device *ieee, u8 *pSupportMCS, u8 *pOperateMCS) 505static u8 HTFilterMCSRate(struct rtllib_device *ieee, u8 *pSupportMCS,
506 u8 *pOperateMCS)
506{ 507{
507 508
508 u8 i; 509 u8 i;
diff --git a/drivers/staging/rtl8192e/rtl819x_Qos.h b/drivers/staging/rtl8192e/rtl819x_Qos.h
index 3aa35ced2b8b..fcc8fabbebb7 100644
--- a/drivers/staging/rtl8192e/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192e/rtl819x_Qos.h
@@ -96,11 +96,6 @@ struct octet_string {
96 u16 Length; 96 u16 Length;
97}; 97};
98 98
99enum ack_policy {
100 eAckPlc0_ACK = 0x00,
101 eAckPlc1_NoACK = 0x01,
102};
103
104#define AC0_BE 0 99#define AC0_BE 0
105#define AC1_BK 1 100#define AC1_BK 1
106#define AC2_VI 2 101#define AC2_VI 2
diff --git a/drivers/staging/rtl8192e/rtl819x_TS.h b/drivers/staging/rtl8192e/rtl819x_TS.h
index b8fed556928c..a93348c37f17 100644
--- a/drivers/staging/rtl8192e/rtl819x_TS.h
+++ b/drivers/staging/rtl8192e/rtl819x_TS.h
@@ -19,8 +19,6 @@
19#ifndef _TSTYPE_H_ 19#ifndef _TSTYPE_H_
20#define _TSTYPE_H_ 20#define _TSTYPE_H_
21#include "rtl819x_Qos.h" 21#include "rtl819x_Qos.h"
22#define TS_SETUP_TIMEOUT 60
23#define TS_INACT_TIMEOUT 60
24#define TS_ADDBA_DELAY 60 22#define TS_ADDBA_DELAY 60
25 23
26#define TOTAL_TS_NUM 16 24#define TOTAL_TS_NUM 16
diff --git a/drivers/staging/rtl8192e/rtl819x_TSProc.c b/drivers/staging/rtl8192e/rtl819x_TSProc.c
index 05aea4321b9d..7087959443cb 100644
--- a/drivers/staging/rtl8192e/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192e/rtl819x_TSProc.c
@@ -113,7 +113,7 @@ static void TsAddBaProcess(unsigned long data)
113 113
114static void ResetTsCommonInfo(struct ts_common_info *pTsCommonInfo) 114static void ResetTsCommonInfo(struct ts_common_info *pTsCommonInfo)
115{ 115{
116 memset(pTsCommonInfo->Addr, 0, 6); 116 eth_zero_addr(pTsCommonInfo->Addr);
117 memset(&pTsCommonInfo->TSpec, 0, sizeof(union tspec_body)); 117 memset(&pTsCommonInfo->TSpec, 0, sizeof(union tspec_body));
118 memset(&pTsCommonInfo->TClass, 0, sizeof(union qos_tclas)*TCLAS_NUM); 118 memset(&pTsCommonInfo->TClass, 0, sizeof(union qos_tclas)*TCLAS_NUM);
119 pTsCommonInfo->TClasProc = 0; 119 pTsCommonInfo->TClasProc = 0;
diff --git a/drivers/staging/rtl8192e/rtllib.h b/drivers/staging/rtl8192e/rtllib.h
index fd38c6dd146b..563ac12f0b2c 100644
--- a/drivers/staging/rtl8192e/rtllib.h
+++ b/drivers/staging/rtl8192e/rtllib.h
@@ -84,9 +84,6 @@
84#define iwe_stream_add_point_rsl(info, start, stop, iwe, p) \ 84#define iwe_stream_add_point_rsl(info, start, stop, iwe, p) \
85 iwe_stream_add_point(info, start, stop, iwe, p) 85 iwe_stream_add_point(info, start, stop, iwe, p)
86 86
87#define usb_alloc_urb_rsl(x, y) usb_alloc_urb(x, y)
88#define usb_submit_urb_rsl(x, y) usb_submit_urb(x, y)
89
90static inline void *netdev_priv_rsl(struct net_device *dev) 87static inline void *netdev_priv_rsl(struct net_device *dev)
91{ 88{
92 return netdev_priv(dev); 89 return netdev_priv(dev);
@@ -110,27 +107,14 @@ static inline void *netdev_priv_rsl(struct net_device *dev)
110#define HIGH_QUEUE 7 107#define HIGH_QUEUE 7
111#define BEACON_QUEUE 8 108#define BEACON_QUEUE 8
112 109
113#define LOW_QUEUE BE_QUEUE
114#define NORMAL_QUEUE MGNT_QUEUE
115
116#ifndef IW_MODE_MESH 110#ifndef IW_MODE_MESH
117#define IW_MODE_MESH 7 111#define IW_MODE_MESH 7
118#endif 112#endif
119#define AMSDU_SUBHEADER_LEN 14
120#define SWRF_TIMEOUT 50
121 113
122#define IE_CISCO_FLAG_POSITION 0x08 114#define IE_CISCO_FLAG_POSITION 0x08
123#define SUPPORT_CKIP_MIC 0x08 115#define SUPPORT_CKIP_MIC 0x08
124#define SUPPORT_CKIP_PK 0x10 116#define SUPPORT_CKIP_PK 0x10
125#define RT_RF_OFF_LEVL_ASPM BIT0
126#define RT_RF_OFF_LEVL_CLK_REQ BIT1
127#define RT_RF_OFF_LEVL_PCI_D3 BIT2
128#define RT_RF_OFF_LEVL_HALT_NIC BIT3 117#define RT_RF_OFF_LEVL_HALT_NIC BIT3
129#define RT_RF_OFF_LEVL_FREE_FW BIT4
130#define RT_RF_OFF_LEVL_FW_32K BIT5
131#define RT_RF_PS_LEVEL_ALWAYS_ASPM BIT6
132#define RT_RF_LPS_DISALBE_2R BIT30
133#define RT_RF_LPS_LEVEL_ASPM BIT31
134#define RT_IN_PS_LEVEL(pPSC, _PS_FLAG) \ 118#define RT_IN_PS_LEVEL(pPSC, _PS_FLAG) \
135 ((pPSC->CurPsLevel & _PS_FLAG) ? true : false) 119 ((pPSC->CurPsLevel & _PS_FLAG) ? true : false)
136#define RT_CLEAR_PS_LEVEL(pPSC, _PS_FLAG) \ 120#define RT_CLEAR_PS_LEVEL(pPSC, _PS_FLAG) \
@@ -244,22 +228,6 @@ struct sw_chnl_cmd {
244#define MGN_MCS13 0x8d 228#define MGN_MCS13 0x8d
245#define MGN_MCS14 0x8e 229#define MGN_MCS14 0x8e
246#define MGN_MCS15 0x8f 230#define MGN_MCS15 0x8f
247#define MGN_MCS0_SG 0x90
248#define MGN_MCS1_SG 0x91
249#define MGN_MCS2_SG 0x92
250#define MGN_MCS3_SG 0x93
251#define MGN_MCS4_SG 0x94
252#define MGN_MCS5_SG 0x95
253#define MGN_MCS6_SG 0x96
254#define MGN_MCS7_SG 0x97
255#define MGN_MCS8_SG 0x98
256#define MGN_MCS9_SG 0x99
257#define MGN_MCS10_SG 0x9a
258#define MGN_MCS11_SG 0x9b
259#define MGN_MCS12_SG 0x9c
260#define MGN_MCS13_SG 0x9d
261#define MGN_MCS14_SG 0x9e
262#define MGN_MCS15_SG 0x9f
263 231
264enum hw_variables { 232enum hw_variables {
265 HW_VAR_ETHER_ADDR, 233 HW_VAR_ETHER_ADDR,
@@ -722,42 +690,13 @@ struct rtllib_frag_entry {
722 u8 dst_addr[ETH_ALEN]; 690 u8 dst_addr[ETH_ALEN];
723}; 691};
724 692
725struct rtllib_stats {
726 unsigned int tx_unicast_frames;
727 unsigned int tx_multicast_frames;
728 unsigned int tx_fragments;
729 unsigned int tx_unicast_octets;
730 unsigned int tx_multicast_octets;
731 unsigned int tx_deferred_transmissions;
732 unsigned int tx_single_retry_frames;
733 unsigned int tx_multiple_retry_frames;
734 unsigned int tx_retry_limit_exceeded;
735 unsigned int tx_discards;
736 unsigned int rx_unicast_frames;
737 unsigned int rx_multicast_frames;
738 unsigned int rx_fragments;
739 unsigned int rx_unicast_octets;
740 unsigned int rx_multicast_octets;
741 unsigned int rx_fcs_errors;
742 unsigned int rx_discards_no_buffer;
743 unsigned int tx_discards_wrong_sa;
744 unsigned int rx_discards_undecryptable;
745 unsigned int rx_message_in_msg_fragments;
746 unsigned int rx_message_in_bad_msg_fragments;
747};
748
749struct rtllib_device; 693struct rtllib_device;
750 694
751#define SEC_KEY_1 (1<<0)
752#define SEC_KEY_2 (1<<1)
753#define SEC_KEY_3 (1<<2)
754#define SEC_KEY_4 (1<<3)
755#define SEC_ACTIVE_KEY (1<<4) 695#define SEC_ACTIVE_KEY (1<<4)
756#define SEC_AUTH_MODE (1<<5) 696#define SEC_AUTH_MODE (1<<5)
757#define SEC_UNICAST_GROUP (1<<6) 697#define SEC_UNICAST_GROUP (1<<6)
758#define SEC_LEVEL (1<<7) 698#define SEC_LEVEL (1<<7)
759#define SEC_ENABLED (1<<8) 699#define SEC_ENABLED (1<<8)
760#define SEC_ENCRYPT (1<<9)
761 700
762#define SEC_LEVEL_0 0 /* None */ 701#define SEC_LEVEL_0 0 /* None */
763#define SEC_LEVEL_1 1 /* WEP 40 and 104 bit */ 702#define SEC_LEVEL_1 1 /* WEP 40 and 104 bit */
@@ -772,7 +711,6 @@ struct rtllib_device;
772 711
773#define WEP_KEY_LEN 13 712#define WEP_KEY_LEN 13
774#define SCM_KEY_LEN 32 713#define SCM_KEY_LEN 32
775#define SCM_TEMPORAL_KEY_LENGTH 16
776 714
777struct rtllib_security { 715struct rtllib_security {
778 u16 active_key:2, 716 u16 active_key:2,
@@ -1187,8 +1125,6 @@ enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame};
1187#define WME_AC_BE 0x01 1125#define WME_AC_BE 0x01
1188#define WME_AC_VI 0x02 1126#define WME_AC_VI 0x02
1189#define WME_AC_VO 0x03 1127#define WME_AC_VO 0x03
1190#define WME_ACI_MASK 0x03
1191#define WME_AIFSN_MASK 0x03
1192#define WME_AC_PRAM_LEN 16 1128#define WME_AC_PRAM_LEN 16
1193 1129
1194#define MAX_RECEIVE_BUFFER_SIZE 9100 1130#define MAX_RECEIVE_BUFFER_SIZE 9100
@@ -1204,12 +1140,6 @@ enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame};
1204#define ETHERNET_HEADER_SIZE 14 /* length of two Ethernet address 1140#define ETHERNET_HEADER_SIZE 14 /* length of two Ethernet address
1205 * plus ether type*/ 1141 * plus ether type*/
1206 1142
1207struct ether_header {
1208 u8 ether_dhost[ETHER_ADDR_LEN];
1209 u8 ether_shost[ETHER_ADDR_LEN];
1210 u16 ether_type;
1211} __packed;
1212
1213enum erp_t { 1143enum erp_t {
1214 ERP_NonERPpresent = 0x01, 1144 ERP_NonERPpresent = 0x01,
1215 ERP_UseProtection = 0x02, 1145 ERP_UseProtection = 0x02,
@@ -1591,7 +1521,6 @@ struct rtllib_device {
1591 1521
1592 /* Bookkeeping structures */ 1522 /* Bookkeeping structures */
1593 struct net_device_stats stats; 1523 struct net_device_stats stats;
1594 struct rtllib_stats ieee_stats;
1595 struct rtllib_softmac_stats softmac_stats; 1524 struct rtllib_softmac_stats softmac_stats;
1596 1525
1597 /* Probe / Beacon management */ 1526 /* Probe / Beacon management */
@@ -1673,7 +1602,6 @@ struct rtllib_device {
1673 int short_slot; 1602 int short_slot;
1674 int mode; /* A, B, G */ 1603 int mode; /* A, B, G */
1675 int modulation; /* CCK, OFDM */ 1604 int modulation; /* CCK, OFDM */
1676 int freq_band; /* 2.4Ghz, 5.2Ghz, Mixed */
1677 1605
1678 /* used for forcing the ibss workqueue to terminate 1606 /* used for forcing the ibss workqueue to terminate
1679 * without wait for the syncro scan to terminate 1607 * without wait for the syncro scan to terminate
@@ -2056,244 +1984,199 @@ static inline int rtllib_is_cck_rate(u8 rate)
2056 1984
2057 1985
2058/* rtllib.c */ 1986/* rtllib.c */
2059extern void free_rtllib(struct net_device *dev); 1987void free_rtllib(struct net_device *dev);
2060extern struct net_device *alloc_rtllib(int sizeof_priv); 1988struct net_device *alloc_rtllib(int sizeof_priv);
2061 1989
2062/* rtllib_tx.c */ 1990/* rtllib_tx.c */
2063 1991
2064extern int rtllib_encrypt_fragment( 1992int rtllib_encrypt_fragment(
2065 struct rtllib_device *ieee, 1993 struct rtllib_device *ieee,
2066 struct sk_buff *frag, 1994 struct sk_buff *frag,
2067 int hdr_len); 1995 int hdr_len);
2068 1996
2069extern int rtllib_xmit(struct sk_buff *skb, struct net_device *dev); 1997int rtllib_xmit(struct sk_buff *skb, struct net_device *dev);
2070extern int rtllib_xmit_inter(struct sk_buff *skb, struct net_device *dev); 1998void rtllib_txb_free(struct rtllib_txb *);
2071extern void rtllib_txb_free(struct rtllib_txb *);
2072 1999
2073/* rtllib_rx.c */ 2000/* rtllib_rx.c */
2074extern int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb, 2001int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
2075 struct rtllib_rx_stats *rx_stats); 2002 struct rtllib_rx_stats *rx_stats);
2076extern void rtllib_rx_mgt(struct rtllib_device *ieee, 2003void rtllib_rx_probe_rq(struct rtllib_device *ieee,
2077 struct sk_buff *skb, 2004 struct sk_buff *skb);
2078 struct rtllib_rx_stats *stats); 2005int rtllib_legal_channel(struct rtllib_device *rtllib, u8 channel);
2079extern void rtllib_rx_probe_rq(struct rtllib_device *ieee,
2080 struct sk_buff *skb);
2081extern int rtllib_legal_channel(struct rtllib_device *rtllib, u8 channel);
2082 2006
2083/* rtllib_wx.c */ 2007/* rtllib_wx.c */
2084extern int rtllib_wx_get_scan(struct rtllib_device *ieee, 2008int rtllib_wx_get_scan(struct rtllib_device *ieee,
2085 struct iw_request_info *info, 2009 struct iw_request_info *info,
2086 union iwreq_data *wrqu, char *key); 2010 union iwreq_data *wrqu, char *key);
2087extern int rtllib_wx_set_encode(struct rtllib_device *ieee, 2011int rtllib_wx_set_encode(struct rtllib_device *ieee,
2088 struct iw_request_info *info, 2012 struct iw_request_info *info,
2089 union iwreq_data *wrqu, char *key); 2013 union iwreq_data *wrqu, char *key);
2090extern int rtllib_wx_get_encode(struct rtllib_device *ieee, 2014int rtllib_wx_get_encode(struct rtllib_device *ieee,
2091 struct iw_request_info *info, 2015 struct iw_request_info *info,
2092 union iwreq_data *wrqu, char *key); 2016 union iwreq_data *wrqu, char *key);
2093extern int rtllib_wx_set_encode_ext(struct rtllib_device *ieee, 2017int rtllib_wx_set_encode_ext(struct rtllib_device *ieee,
2094 struct iw_request_info *info, 2018 struct iw_request_info *info,
2095 union iwreq_data *wrqu, char *extra); 2019 union iwreq_data *wrqu, char *extra);
2096extern int rtllib_wx_set_auth(struct rtllib_device *ieee, 2020int rtllib_wx_set_auth(struct rtllib_device *ieee,
2097 struct iw_request_info *info, 2021 struct iw_request_info *info,
2098 struct iw_param *data, char *extra); 2022 struct iw_param *data, char *extra);
2099extern int rtllib_wx_set_mlme(struct rtllib_device *ieee, 2023int rtllib_wx_set_mlme(struct rtllib_device *ieee,
2100 struct iw_request_info *info, 2024 struct iw_request_info *info,
2101 union iwreq_data *wrqu, char *extra); 2025 union iwreq_data *wrqu, char *extra);
2102extern int rtllib_wx_set_gen_ie(struct rtllib_device *ieee, u8 *ie, size_t len); 2026int rtllib_wx_set_gen_ie(struct rtllib_device *ieee, u8 *ie, size_t len);
2103 2027
2104/* rtllib_softmac.c */ 2028/* rtllib_softmac.c */
2105extern short rtllib_is_54g(struct rtllib_network *net); 2029int rtllib_rx_frame_softmac(struct rtllib_device *ieee, struct sk_buff *skb,
2106extern int rtllib_rx_frame_softmac(struct rtllib_device *ieee, 2030 struct rtllib_rx_stats *rx_stats, u16 type,
2107 struct sk_buff *skb, 2031 u16 stype);
2108 struct rtllib_rx_stats *rx_stats, u16 type, 2032void rtllib_softmac_new_net(struct rtllib_device *ieee,
2109 u16 stype); 2033 struct rtllib_network *net);
2110extern void rtllib_softmac_new_net(struct rtllib_device *ieee,
2111 struct rtllib_network *net);
2112 2034
2113void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn); 2035void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn);
2114extern void rtllib_softmac_xmit(struct rtllib_txb *txb, 2036void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee);
2115 struct rtllib_device *ieee); 2037
2116 2038void rtllib_stop_send_beacons(struct rtllib_device *ieee);
2117extern void rtllib_stop_send_beacons(struct rtllib_device *ieee); 2039void notify_wx_assoc_event(struct rtllib_device *ieee);
2118extern void notify_wx_assoc_event(struct rtllib_device *ieee); 2040void rtllib_start_ibss(struct rtllib_device *ieee);
2119extern void rtllib_softmac_check_all_nets(struct rtllib_device *ieee); 2041void rtllib_softmac_init(struct rtllib_device *ieee);
2120extern void rtllib_start_bss(struct rtllib_device *ieee); 2042void rtllib_softmac_free(struct rtllib_device *ieee);
2121extern void rtllib_start_master_bss(struct rtllib_device *ieee); 2043void rtllib_disassociate(struct rtllib_device *ieee);
2122extern void rtllib_start_ibss(struct rtllib_device *ieee); 2044void rtllib_stop_scan(struct rtllib_device *ieee);
2123extern void rtllib_softmac_init(struct rtllib_device *ieee); 2045bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan);
2124extern void rtllib_softmac_free(struct rtllib_device *ieee); 2046void rtllib_stop_scan_syncro(struct rtllib_device *ieee);
2125extern void rtllib_associate_abort(struct rtllib_device *ieee); 2047void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh);
2126extern void rtllib_disassociate(struct rtllib_device *ieee); 2048void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr);
2127extern void rtllib_stop_scan(struct rtllib_device *ieee); 2049void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee);
2128extern bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan); 2050void rtllib_start_protocol(struct rtllib_device *ieee);
2129extern void rtllib_stop_scan_syncro(struct rtllib_device *ieee); 2051void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown);
2130extern void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh); 2052
2131extern void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, 2053void rtllib_EnableNetMonitorMode(struct net_device *dev, bool bInitState);
2132 short pwr); 2054void rtllib_DisableNetMonitorMode(struct net_device *dev, bool bInitState);
2133extern void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl); 2055void rtllib_EnableIntelPromiscuousMode(struct net_device *dev, bool bInitState);
2134extern void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee); 2056void rtllib_DisableIntelPromiscuousMode(struct net_device *dev,
2135extern void rtllib_start_protocol(struct rtllib_device *ieee);
2136extern void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown);
2137
2138extern void rtllib_EnableNetMonitorMode(struct net_device *dev,
2139 bool bInitState); 2057 bool bInitState);
2140extern void rtllib_DisableNetMonitorMode(struct net_device *dev, 2058void rtllib_softmac_stop_protocol(struct rtllib_device *ieee,
2141 bool bInitState); 2059 u8 mesh_flag, u8 shutdown);
2142extern void rtllib_EnableIntelPromiscuousMode(struct net_device *dev, 2060void rtllib_softmac_start_protocol(struct rtllib_device *ieee, u8 mesh_flag);
2143 bool bInitState); 2061
2144extern void rtllib_DisableIntelPromiscuousMode(struct net_device *dev, 2062void rtllib_reset_queue(struct rtllib_device *ieee);
2145 bool bInitState); 2063void rtllib_wake_all_queues(struct rtllib_device *ieee);
2146extern void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh); 2064void rtllib_stop_all_queues(struct rtllib_device *ieee);
2147 2065struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee);
2148extern void rtllib_softmac_stop_protocol(struct rtllib_device *ieee, 2066void rtllib_start_send_beacons(struct rtllib_device *ieee);
2149 u8 mesh_flag, u8 shutdown); 2067void rtllib_stop_send_beacons(struct rtllib_device *ieee);
2150extern void rtllib_softmac_start_protocol(struct rtllib_device *ieee, 2068int rtllib_wpa_supplicant_ioctl(struct rtllib_device *ieee,
2151 u8 mesh_flag); 2069 struct iw_point *p, u8 is_mesh);
2152 2070
2153extern void rtllib_reset_queue(struct rtllib_device *ieee); 2071void notify_wx_assoc_event(struct rtllib_device *ieee);
2154extern void rtllib_wake_all_queues(struct rtllib_device *ieee); 2072void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success);
2155extern void rtllib_stop_all_queues(struct rtllib_device *ieee); 2073
2156extern struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee); 2074void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee);
2157extern void rtllib_start_send_beacons(struct rtllib_device *ieee); 2075u8 rtllib_ap_sec_type(struct rtllib_device *ieee);
2158extern void rtllib_stop_send_beacons(struct rtllib_device *ieee);
2159extern int rtllib_wpa_supplicant_ioctl(struct rtllib_device *ieee,
2160 struct iw_point *p, u8 is_mesh);
2161
2162extern void notify_wx_assoc_event(struct rtllib_device *ieee);
2163extern void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success);
2164
2165extern void softmac_mgmt_xmit(struct sk_buff *skb,
2166 struct rtllib_device *ieee);
2167extern u16 rtllib_query_seqnum(struct rtllib_device *ieee,
2168 struct sk_buff *skb, u8 *dst);
2169extern u8 rtllib_ap_sec_type(struct rtllib_device *ieee);
2170 2076
2171/* rtllib_softmac_wx.c */ 2077/* rtllib_softmac_wx.c */
2172 2078
2173extern int rtllib_wx_get_wap(struct rtllib_device *ieee, 2079int rtllib_wx_get_wap(struct rtllib_device *ieee, struct iw_request_info *info,
2174 struct iw_request_info *info, 2080 union iwreq_data *wrqu, char *ext);
2175 union iwreq_data *wrqu, char *ext);
2176 2081
2177extern int rtllib_wx_set_wap(struct rtllib_device *ieee, 2082int rtllib_wx_set_wap(struct rtllib_device *ieee, struct iw_request_info *info,
2178 struct iw_request_info *info, 2083 union iwreq_data *awrq, char *extra);
2179 union iwreq_data *awrq,
2180 char *extra);
2181 2084
2182extern int rtllib_wx_get_essid(struct rtllib_device *ieee, 2085int rtllib_wx_get_essid(struct rtllib_device *ieee, struct iw_request_info *a,
2183 struct iw_request_info *a, 2086 union iwreq_data *wrqu, char *b);
2184 union iwreq_data *wrqu, char *b);
2185 2087
2186extern int rtllib_wx_set_rate(struct rtllib_device *ieee, 2088int rtllib_wx_set_rate(struct rtllib_device *ieee, struct iw_request_info *info,
2187 struct iw_request_info *info, 2089 union iwreq_data *wrqu, char *extra);
2188 union iwreq_data *wrqu, char *extra);
2189 2090
2190extern int rtllib_wx_get_rate(struct rtllib_device *ieee, 2091int rtllib_wx_get_rate(struct rtllib_device *ieee, struct iw_request_info *info,
2191 struct iw_request_info *info, 2092 union iwreq_data *wrqu, char *extra);
2192 union iwreq_data *wrqu, char *extra);
2193 2093
2194extern int rtllib_wx_set_mode(struct rtllib_device *ieee, 2094int rtllib_wx_set_mode(struct rtllib_device *ieee, struct iw_request_info *a,
2195 struct iw_request_info *a, 2095 union iwreq_data *wrqu, char *b);
2196 union iwreq_data *wrqu, char *b);
2197 2096
2198extern int rtllib_wx_set_scan(struct rtllib_device *ieee, 2097int rtllib_wx_set_scan(struct rtllib_device *ieee, struct iw_request_info *a,
2199 struct iw_request_info *a, 2098 union iwreq_data *wrqu, char *b);
2200 union iwreq_data *wrqu, char *b);
2201 2099
2202extern int rtllib_wx_set_essid(struct rtllib_device *ieee, 2100int rtllib_wx_set_essid(struct rtllib_device *ieee, struct iw_request_info *a,
2203 struct iw_request_info *a, 2101 union iwreq_data *wrqu, char *extra);
2204 union iwreq_data *wrqu, char *extra);
2205 2102
2206extern int rtllib_wx_get_mode(struct rtllib_device *ieee, 2103int rtllib_wx_get_mode(struct rtllib_device *ieee, struct iw_request_info *a,
2207 struct iw_request_info *a, 2104 union iwreq_data *wrqu, char *b);
2208 union iwreq_data *wrqu, char *b);
2209 2105
2210extern int rtllib_wx_set_freq(struct rtllib_device *ieee, 2106int rtllib_wx_set_freq(struct rtllib_device *ieee, struct iw_request_info *a,
2211 struct iw_request_info *a, 2107 union iwreq_data *wrqu, char *b);
2212 union iwreq_data *wrqu, char *b);
2213 2108
2214extern int rtllib_wx_get_freq(struct rtllib_device *ieee, 2109int rtllib_wx_get_freq(struct rtllib_device *ieee, struct iw_request_info *a,
2215 struct iw_request_info *a, 2110 union iwreq_data *wrqu, char *b);
2216 union iwreq_data *wrqu, char *b); 2111void rtllib_wx_sync_scan_wq(void *data);
2217extern void rtllib_wx_sync_scan_wq(void *data);
2218 2112
2219extern int rtllib_wx_set_rawtx(struct rtllib_device *ieee, 2113int rtllib_wx_set_rawtx(struct rtllib_device *ieee,
2220 struct iw_request_info *info, 2114 struct iw_request_info *info,
2221 union iwreq_data *wrqu, char *extra); 2115 union iwreq_data *wrqu, char *extra);
2222 2116
2223extern int rtllib_wx_get_name(struct rtllib_device *ieee, 2117int rtllib_wx_get_name(struct rtllib_device *ieee, struct iw_request_info *info,
2224 struct iw_request_info *info, 2118 union iwreq_data *wrqu, char *extra);
2225 union iwreq_data *wrqu, char *extra);
2226 2119
2227extern int rtllib_wx_set_power(struct rtllib_device *ieee, 2120int rtllib_wx_set_power(struct rtllib_device *ieee,
2228 struct iw_request_info *info, 2121 struct iw_request_info *info,
2229 union iwreq_data *wrqu, char *extra); 2122 union iwreq_data *wrqu, char *extra);
2230 2123
2231extern int rtllib_wx_get_power(struct rtllib_device *ieee, 2124int rtllib_wx_get_power(struct rtllib_device *ieee,
2232 struct iw_request_info *info, 2125 struct iw_request_info *info,
2233 union iwreq_data *wrqu, char *extra); 2126 union iwreq_data *wrqu, char *extra);
2234 2127
2235extern int rtllib_wx_set_rts(struct rtllib_device *ieee, 2128int rtllib_wx_set_rts(struct rtllib_device *ieee, struct iw_request_info *info,
2236 struct iw_request_info *info, 2129 union iwreq_data *wrqu, char *extra);
2237 union iwreq_data *wrqu, char *extra);
2238 2130
2239extern int rtllib_wx_get_rts(struct rtllib_device *ieee, 2131int rtllib_wx_get_rts(struct rtllib_device *ieee, struct iw_request_info *info,
2240 struct iw_request_info *info, 2132 union iwreq_data *wrqu, char *extra);
2241 union iwreq_data *wrqu, char *extra);
2242#define MAX_RECEIVE_BUFFER_SIZE 9100 2133#define MAX_RECEIVE_BUFFER_SIZE 9100
2243 2134
2244void HTSetConnectBwMode(struct rtllib_device *ieee, 2135void HTSetConnectBwMode(struct rtllib_device *ieee,
2245 enum ht_channel_width Bandwidth, 2136 enum ht_channel_width Bandwidth,
2246 enum ht_extchnl_offset Offset); 2137 enum ht_extchnl_offset Offset);
2247extern void HTUpdateDefaultSetting(struct rtllib_device *ieee); 2138void HTUpdateDefaultSetting(struct rtllib_device *ieee);
2248extern void HTConstructCapabilityElement(struct rtllib_device *ieee, 2139void HTConstructCapabilityElement(struct rtllib_device *ieee,
2249 u8 *posHTCap, u8 *len, 2140 u8 *posHTCap, u8 *len,
2250 u8 isEncrypt, bool bAssoc); 2141 u8 isEncrypt, bool bAssoc);
2251extern void HTConstructInfoElement(struct rtllib_device *ieee, 2142void HTConstructInfoElement(struct rtllib_device *ieee,
2252 u8 *posHTInfo, u8 *len, u8 isEncrypt); 2143 u8 *posHTInfo, u8 *len, u8 isEncrypt);
2253extern void HTConstructRT2RTAggElement(struct rtllib_device *ieee, 2144void HTConstructRT2RTAggElement(struct rtllib_device *ieee,
2254 u8 *posRT2RTAgg, u8 *len); 2145 u8 *posRT2RTAgg, u8 *len);
2255extern void HTOnAssocRsp(struct rtllib_device *ieee); 2146void HTOnAssocRsp(struct rtllib_device *ieee);
2256extern void HTInitializeHTInfo(struct rtllib_device *ieee); 2147void HTInitializeHTInfo(struct rtllib_device *ieee);
2257extern void HTInitializeBssDesc(struct bss_ht *pBssHT); 2148void HTInitializeBssDesc(struct bss_ht *pBssHT);
2258extern void HTResetSelfAndSavePeerSetting(struct rtllib_device *ieee, 2149void HTResetSelfAndSavePeerSetting(struct rtllib_device *ieee,
2259 struct rtllib_network *pNetwork); 2150 struct rtllib_network *pNetwork);
2260extern void HT_update_self_and_peer_setting(struct rtllib_device *ieee, 2151void HT_update_self_and_peer_setting(struct rtllib_device *ieee,
2261 struct rtllib_network *pNetwork); 2152 struct rtllib_network *pNetwork);
2262extern u8 HTGetHighestMCSRate(struct rtllib_device *ieee, u8 *pMCSRateSet, 2153u8 HTGetHighestMCSRate(struct rtllib_device *ieee, u8 *pMCSRateSet,
2263 u8 *pMCSFilter); 2154 u8 *pMCSFilter);
2264extern u8 MCS_FILTER_ALL[]; 2155extern u8 MCS_FILTER_ALL[];
2265extern u16 MCS_DATA_RATE[2][2][77]; 2156extern u16 MCS_DATA_RATE[2][2][77];
2266extern u8 HTCCheck(struct rtllib_device *ieee, u8 *pFrame); 2157u8 HTCCheck(struct rtllib_device *ieee, u8 *pFrame);
2267extern void HTResetIOTSetting(struct rt_hi_throughput *pHTInfo); 2158void HTResetIOTSetting(struct rt_hi_throughput *pHTInfo);
2268extern bool IsHTHalfNmodeAPs(struct rtllib_device *ieee); 2159bool IsHTHalfNmodeAPs(struct rtllib_device *ieee);
2269extern u16 HTMcsToDataRate(struct rtllib_device *ieee, u8 nMcsRate); 2160u16 TxCountToDataRate(struct rtllib_device *ieee, u8 nDataRate);
2270extern u16 TxCountToDataRate(struct rtllib_device *ieee, u8 nDataRate); 2161int rtllib_rx_ADDBAReq(struct rtllib_device *ieee, struct sk_buff *skb);
2271extern int rtllib_rx_ADDBAReq(struct rtllib_device *ieee, struct sk_buff *skb); 2162int rtllib_rx_ADDBARsp(struct rtllib_device *ieee, struct sk_buff *skb);
2272extern int rtllib_rx_ADDBARsp(struct rtllib_device *ieee, struct sk_buff *skb); 2163int rtllib_rx_DELBA(struct rtllib_device *ieee, struct sk_buff *skb);
2273extern int rtllib_rx_DELBA(struct rtllib_device *ieee, struct sk_buff *skb); 2164void TsInitAddBA(struct rtllib_device *ieee, struct tx_ts_record *pTS,
2274extern void TsInitAddBA(struct rtllib_device *ieee, struct tx_ts_record *pTS, 2165 u8 Policy, u8 bOverwritePending);
2275 u8 Policy, u8 bOverwritePending); 2166void TsInitDelBA(struct rtllib_device *ieee,
2276extern void TsInitDelBA(struct rtllib_device *ieee, 2167 struct ts_common_info *pTsCommonInfo,
2277 struct ts_common_info *pTsCommonInfo, 2168 enum tr_select TxRxSelect);
2278 enum tr_select TxRxSelect); 2169void BaSetupTimeOut(unsigned long data);
2279extern void BaSetupTimeOut(unsigned long data); 2170void TxBaInactTimeout(unsigned long data);
2280extern void TxBaInactTimeout(unsigned long data); 2171void RxBaInactTimeout(unsigned long data);
2281extern void RxBaInactTimeout(unsigned long data); 2172void ResetBaEntry(struct ba_record *pBA);
2282extern void ResetBaEntry(struct ba_record *pBA); 2173bool GetTs(struct rtllib_device *ieee, struct ts_common_info **ppTS, u8 *Addr,
2283extern bool GetTs( 2174 u8 TID, enum tr_select TxRxSelect, bool bAddNewTs);
2284 struct rtllib_device *ieee, 2175void TSInitialize(struct rtllib_device *ieee);
2285 struct ts_common_info **ppTS, 2176void TsStartAddBaProcess(struct rtllib_device *ieee,
2286 u8 *Addr, 2177 struct tx_ts_record *pTxTS);
2287 u8 TID, 2178void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr);
2288 enum tr_select TxRxSelect, 2179void RemoveAllTS(struct rtllib_device *ieee);
2289 bool bAddNewTs
2290);
2291extern void TSInitialize(struct rtllib_device *ieee);
2292extern void TsStartAddBaProcess(struct rtllib_device *ieee,
2293 struct tx_ts_record *pTxTS);
2294extern void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr);
2295extern void RemoveAllTS(struct rtllib_device *ieee);
2296void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh);
2297 2180
2298extern const long rtllib_wlan_frequencies[]; 2181extern const long rtllib_wlan_frequencies[];
2299 2182
@@ -2317,23 +2200,19 @@ bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn);
2317/* For the function is more related to hardware setting, it's better to use the 2200/* For the function is more related to hardware setting, it's better to use the
2318 * ieee handler to refer to it. 2201 * ieee handler to refer to it.
2319 */ 2202 */
2320extern void rtllib_update_active_chan_map(struct rtllib_device *ieee); 2203void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee,
2321extern void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee, 2204 struct rx_ts_record *pTS);
2322 struct rx_ts_record *pTS); 2205int rtllib_parse_info_param(struct rtllib_device *ieee,
2323extern int rtllib_parse_info_param(struct rtllib_device *ieee, 2206 struct rtllib_info_element *info_element,
2324 struct rtllib_info_element *info_element, 2207 u16 length,
2325 u16 length, 2208 struct rtllib_network *network,
2326 struct rtllib_network *network, 2209 struct rtllib_rx_stats *stats);
2327 struct rtllib_rx_stats *stats);
2328 2210
2329void rtllib_indicate_packets(struct rtllib_device *ieee, 2211void rtllib_indicate_packets(struct rtllib_device *ieee,
2330 struct rtllib_rxb **prxbIndicateArray, u8 index); 2212 struct rtllib_rxb **prxbIndicateArray, u8 index);
2331extern u8 HTFilterMCSRate(struct rtllib_device *ieee, u8 *pSupportMCS, 2213void HTUseDefaultSetting(struct rtllib_device *ieee);
2332 u8 *pOperateMCS);
2333extern void HTUseDefaultSetting(struct rtllib_device *ieee);
2334#define RT_ASOC_RETRY_LIMIT 5 2214#define RT_ASOC_RETRY_LIMIT 5
2335u8 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee); 2215u8 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee);
2336extern void rtllib_TURBO_Info(struct rtllib_device *ieee, u8 **tag_p);
2337#define SEM_DOWN_IEEE_WX(psem) down(psem) 2216#define SEM_DOWN_IEEE_WX(psem) down(psem)
2338#define SEM_UP_IEEE_WX(psem) up(psem) 2217#define SEM_UP_IEEE_WX(psem) up(psem)
2339 2218
diff --git a/drivers/staging/rtl8192e/rtllib_debug.h b/drivers/staging/rtl8192e/rtllib_debug.h
index 42e88d69ae63..17c276d71058 100644
--- a/drivers/staging/rtl8192e/rtllib_debug.h
+++ b/drivers/staging/rtl8192e/rtllib_debug.h
@@ -30,8 +30,6 @@
30#define DRV_NAME "rtllib_92e" 30#define DRV_NAME "rtllib_92e"
31#endif 31#endif
32 32
33#define DMESG(x, a...)
34
35extern u32 rt_global_debug_component; 33extern u32 rt_global_debug_component;
36 34
37/* These are the defines for rt_global_debug_component */ 35/* These are the defines for rt_global_debug_component */
@@ -40,10 +38,7 @@ enum RTL_DEBUG {
40 COMP_DBG = (1 << 1), 38 COMP_DBG = (1 << 1),
41 COMP_INIT = (1 << 2), 39 COMP_INIT = (1 << 2),
42 COMP_RECV = (1 << 3), 40 COMP_RECV = (1 << 3),
43 COMP_SEND = (1 << 4),
44 COMP_CMD = (1 << 5),
45 COMP_POWER = (1 << 6), 41 COMP_POWER = (1 << 6),
46 COMP_EPROM = (1 << 7),
47 COMP_SWBW = (1 << 8), 42 COMP_SWBW = (1 << 8),
48 COMP_SEC = (1 << 9), 43 COMP_SEC = (1 << 9),
49 COMP_LPS = (1 << 10), 44 COMP_LPS = (1 << 10),
@@ -58,15 +53,12 @@ enum RTL_DEBUG {
58 COMP_CH = (1 << 19), 53 COMP_CH = (1 << 19),
59 COMP_RF = (1 << 20), 54 COMP_RF = (1 << 20),
60 COMP_FIRMWARE = (1 << 21), 55 COMP_FIRMWARE = (1 << 21),
61 COMP_HT = (1 << 22),
62 COMP_RESET = (1 << 23), 56 COMP_RESET = (1 << 23),
63 COMP_CMDPKT = (1 << 24), 57 COMP_CMDPKT = (1 << 24),
64 COMP_SCAN = (1 << 25), 58 COMP_SCAN = (1 << 25),
65 COMP_PS = (1 << 26), 59 COMP_PS = (1 << 26),
66 COMP_DOWN = (1 << 27), 60 COMP_DOWN = (1 << 27),
67 COMP_INTR = (1 << 28), 61 COMP_INTR = (1 << 28),
68 COMP_LED = (1 << 29),
69 COMP_MLME = (1 << 30),
70 COMP_ERR = (1 << 31) 62 COMP_ERR = (1 << 31)
71}; 63};
72 64
diff --git a/drivers/staging/rtl8192e/rtllib_rx.c b/drivers/staging/rtl8192e/rtllib_rx.c
index da862c3da4ce..09f0820fb340 100644
--- a/drivers/staging/rtl8192e/rtllib_rx.c
+++ b/drivers/staging/rtl8192e/rtllib_rx.c
@@ -44,6 +44,9 @@
44#include "rtllib.h" 44#include "rtllib.h"
45#include "dot11d.h" 45#include "dot11d.h"
46 46
47static void rtllib_rx_mgt(struct rtllib_device *ieee, struct sk_buff *skb,
48 struct rtllib_rx_stats *stats);
49
47static inline void rtllib_monitor_rx(struct rtllib_device *ieee, 50static inline void rtllib_monitor_rx(struct rtllib_device *ieee,
48 struct sk_buff *skb, 51 struct sk_buff *skb,
49 struct rtllib_rx_stats *rx_status, 52 struct rtllib_rx_stats *rx_status,
@@ -317,7 +320,6 @@ rtllib_rx_frame_decrypt(struct rtllib_device *ieee, struct sk_buff *skb,
317 netdev_dbg(ieee->dev, 320 netdev_dbg(ieee->dev,
318 "Decryption failed ICV mismatch (key %d)\n", 321 "Decryption failed ICV mismatch (key %d)\n",
319 skb->data[hdrlen + 3] >> 6); 322 skb->data[hdrlen + 3] >> 6);
320 ieee->ieee_stats.rx_discards_undecryptable++;
321 return -1; 323 return -1;
322 } 324 }
323 325
@@ -1077,7 +1079,6 @@ static int rtllib_rx_get_crypt(struct rtllib_device *ieee, struct sk_buff *skb,
1077 netdev_dbg(ieee->dev, 1079 netdev_dbg(ieee->dev,
1078 "Decryption failed (not set) (SA= %pM)\n", 1080 "Decryption failed (not set) (SA= %pM)\n",
1079 hdr->addr2); 1081 hdr->addr2);
1080 ieee->ieee_stats.rx_discards_undecryptable++;
1081 return -1; 1082 return -1;
1082 } 1083 }
1083 } 1084 }
@@ -1743,37 +1744,61 @@ static int rtllib_parse_qos_info_param_IE(struct rtllib_device *ieee,
1743 return rc; 1744 return rc;
1744} 1745}
1745 1746
1746#define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
1747
1748static const char *get_info_element_string(u16 id) 1747static const char *get_info_element_string(u16 id)
1749{ 1748{
1750 switch (id) { 1749 switch (id) {
1751 MFIE_STRING(SSID); 1750 case MFIE_TYPE_SSID:
1752 MFIE_STRING(RATES); 1751 return "SSID";
1753 MFIE_STRING(FH_SET); 1752 case MFIE_TYPE_RATES:
1754 MFIE_STRING(DS_SET); 1753 return "RATES";
1755 MFIE_STRING(CF_SET); 1754 case MFIE_TYPE_FH_SET:
1756 MFIE_STRING(TIM); 1755 return "FH_SET";
1757 MFIE_STRING(IBSS_SET); 1756 case MFIE_TYPE_DS_SET:
1758 MFIE_STRING(COUNTRY); 1757 return "DS_SET";
1759 MFIE_STRING(HOP_PARAMS); 1758 case MFIE_TYPE_CF_SET:
1760 MFIE_STRING(HOP_TABLE); 1759 return "CF_SET";
1761 MFIE_STRING(REQUEST); 1760 case MFIE_TYPE_TIM:
1762 MFIE_STRING(CHALLENGE); 1761 return "TIM";
1763 MFIE_STRING(POWER_CONSTRAINT); 1762 case MFIE_TYPE_IBSS_SET:
1764 MFIE_STRING(POWER_CAPABILITY); 1763 return "IBSS_SET";
1765 MFIE_STRING(TPC_REQUEST); 1764 case MFIE_TYPE_COUNTRY:
1766 MFIE_STRING(TPC_REPORT); 1765 return "COUNTRY";
1767 MFIE_STRING(SUPP_CHANNELS); 1766 case MFIE_TYPE_HOP_PARAMS:
1768 MFIE_STRING(CSA); 1767 return "HOP_PARAMS";
1769 MFIE_STRING(MEASURE_REQUEST); 1768 case MFIE_TYPE_HOP_TABLE:
1770 MFIE_STRING(MEASURE_REPORT); 1769 return "HOP_TABLE";
1771 MFIE_STRING(QUIET); 1770 case MFIE_TYPE_REQUEST:
1772 MFIE_STRING(IBSS_DFS); 1771 return "REQUEST";
1773 MFIE_STRING(RSN); 1772 case MFIE_TYPE_CHALLENGE:
1774 MFIE_STRING(RATES_EX); 1773 return "CHALLENGE";
1775 MFIE_STRING(GENERIC); 1774 case MFIE_TYPE_POWER_CONSTRAINT:
1776 MFIE_STRING(QOS_PARAMETER); 1775 return "POWER_CONSTRAINT";
1776 case MFIE_TYPE_POWER_CAPABILITY:
1777 return "POWER_CAPABILITY";
1778 case MFIE_TYPE_TPC_REQUEST:
1779 return "TPC_REQUEST";
1780 case MFIE_TYPE_TPC_REPORT:
1781 return "TPC_REPORT";
1782 case MFIE_TYPE_SUPP_CHANNELS:
1783 return "SUPP_CHANNELS";
1784 case MFIE_TYPE_CSA:
1785 return "CSA";
1786 case MFIE_TYPE_MEASURE_REQUEST:
1787 return "MEASURE_REQUEST";
1788 case MFIE_TYPE_MEASURE_REPORT:
1789 return "MEASURE_REPORT";
1790 case MFIE_TYPE_QUIET:
1791 return "QUIET";
1792 case MFIE_TYPE_IBSS_DFS:
1793 return "IBSS_DFS";
1794 case MFIE_TYPE_RSN:
1795 return "RSN";
1796 case MFIE_TYPE_RATES_EX:
1797 return "RATES_EX";
1798 case MFIE_TYPE_GENERIC:
1799 return "GENERIC";
1800 case MFIE_TYPE_QOS_PARAMETER:
1801 return "QOS_PARAMETER";
1777 default: 1802 default:
1778 return "UNKNOWN"; 1803 return "UNKNOWN";
1779 } 1804 }
@@ -2717,9 +2742,9 @@ free_network:
2717 kfree(network); 2742 kfree(network);
2718} 2743}
2719 2744
2720void rtllib_rx_mgt(struct rtllib_device *ieee, 2745static void rtllib_rx_mgt(struct rtllib_device *ieee,
2721 struct sk_buff *skb, 2746 struct sk_buff *skb,
2722 struct rtllib_rx_stats *stats) 2747 struct rtllib_rx_stats *stats)
2723{ 2748{
2724 struct rtllib_hdr_4addr *header = (struct rtllib_hdr_4addr *)skb->data; 2749 struct rtllib_hdr_4addr *header = (struct rtllib_hdr_4addr *)skb->data;
2725 2750
diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
index d320c31732f2..1503cbb3574e 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -23,7 +23,10 @@
23#include <linux/ieee80211.h> 23#include <linux/ieee80211.h>
24#include "dot11d.h" 24#include "dot11d.h"
25 25
26short rtllib_is_54g(struct rtllib_network *net) 26static void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl);
27
28
29static short rtllib_is_54g(struct rtllib_network *net)
27{ 30{
28 return (net->rates_ex_len > 0) || (net->rates_len > 4); 31 return (net->rates_ex_len > 0) || (net->rates_len > 4);
29} 32}
@@ -107,7 +110,7 @@ static void rtllib_WMM_Info(struct rtllib_device *ieee, u8 **tag_p)
107 *tag_p = tag; 110 *tag_p = tag;
108} 111}
109 112
110void rtllib_TURBO_Info(struct rtllib_device *ieee, u8 **tag_p) 113static void rtllib_TURBO_Info(struct rtllib_device *ieee, u8 **tag_p)
111{ 114{
112 u8 *tag = *tag_p; 115 u8 *tag = *tag_p;
113 116
@@ -369,7 +372,7 @@ static inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee)
369 return skb; 372 return skb;
370} 373}
371 374
372struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee); 375static struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee);
373 376
374static void rtllib_send_beacon(struct rtllib_device *ieee) 377static void rtllib_send_beacon(struct rtllib_device *ieee)
375{ 378{
@@ -483,7 +486,7 @@ static void rtllib_send_probe(struct rtllib_device *ieee, u8 is_mesh)
483} 486}
484 487
485 488
486void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh) 489static void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh)
487{ 490{
488 if (ieee->active_scan && (ieee->softmac_features & 491 if (ieee->active_scan && (ieee->softmac_features &
489 IEEE_SOFTMAC_PROBERQ)) { 492 IEEE_SOFTMAC_PROBERQ)) {
@@ -492,7 +495,7 @@ void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh)
492 } 495 }
493} 496}
494 497
495void rtllib_update_active_chan_map(struct rtllib_device *ieee) 498static void rtllib_update_active_chan_map(struct rtllib_device *ieee)
496{ 499{
497 memcpy(ieee->active_channel_map, GET_DOT11D_INFO(ieee)->channel_map, 500 memcpy(ieee->active_channel_map, GET_DOT11D_INFO(ieee)->channel_map,
498 MAX_CHANNEL_NUMBER+1); 501 MAX_CHANNEL_NUMBER+1);
@@ -501,7 +504,7 @@ void rtllib_update_active_chan_map(struct rtllib_device *ieee)
501/* this performs syncro scan blocking the caller until all channels 504/* this performs syncro scan blocking the caller until all channels
502 * in the allowed channel map has been checked. 505 * in the allowed channel map has been checked.
503 */ 506 */
504void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh) 507static void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
505{ 508{
506 union iwreq_data wrqu; 509 union iwreq_data wrqu;
507 short ch = 0; 510 short ch = 0;
@@ -1401,7 +1404,7 @@ inline struct sk_buff *rtllib_association_req(struct rtllib_network *beacon,
1401 return skb; 1404 return skb;
1402} 1405}
1403 1406
1404void rtllib_associate_abort(struct rtllib_device *ieee) 1407static void rtllib_associate_abort(struct rtllib_device *ieee)
1405{ 1408{
1406 unsigned long flags; 1409 unsigned long flags;
1407 1410
@@ -1511,7 +1514,6 @@ static void rtllib_associate_step2(struct rtllib_device *ieee)
1511 } 1514 }
1512} 1515}
1513 1516
1514#define CANCELLED 2
1515static void rtllib_associate_complete_wq(void *data) 1517static void rtllib_associate_complete_wq(void *data)
1516{ 1518{
1517 struct rtllib_device *ieee = (struct rtllib_device *) 1519 struct rtllib_device *ieee = (struct rtllib_device *)
@@ -1753,7 +1755,7 @@ inline void rtllib_softmac_new_net(struct rtllib_device *ieee,
1753 } 1755 }
1754} 1756}
1755 1757
1756void rtllib_softmac_check_all_nets(struct rtllib_device *ieee) 1758static void rtllib_softmac_check_all_nets(struct rtllib_device *ieee)
1757{ 1759{
1758 unsigned long flags; 1760 unsigned long flags;
1759 struct rtllib_network *target; 1761 struct rtllib_network *target;
@@ -2109,7 +2111,7 @@ out:
2109 2111
2110} 2112}
2111 2113
2112void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl) 2114static void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl)
2113{ 2115{
2114 if (ieee->sta_sleep == LPS_IS_WAKE) { 2116 if (ieee->sta_sleep == LPS_IS_WAKE) {
2115 if (nl) { 2117 if (nl) {
@@ -2545,7 +2547,7 @@ inline void rtllib_randomize_cell(struct rtllib_device *ieee)
2545} 2547}
2546 2548
2547/* called in user context only */ 2549/* called in user context only */
2548void rtllib_start_master_bss(struct rtllib_device *ieee) 2550static void rtllib_start_master_bss(struct rtllib_device *ieee)
2549{ 2551{
2550 ieee->assoc_id = 1; 2552 ieee->assoc_id = 1;
2551 2553
@@ -2720,7 +2722,7 @@ inline void rtllib_start_ibss(struct rtllib_device *ieee)
2720} 2722}
2721 2723
2722/* this is called only in user context, with wx_sem held */ 2724/* this is called only in user context, with wx_sem held */
2723void rtllib_start_bss(struct rtllib_device *ieee) 2725static void rtllib_start_bss(struct rtllib_device *ieee)
2724{ 2726{
2725 unsigned long flags; 2727 unsigned long flags;
2726 2728
@@ -2817,7 +2819,7 @@ exit:
2817 up(&ieee->wx_sem); 2819 up(&ieee->wx_sem);
2818} 2820}
2819 2821
2820struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee) 2822static struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee)
2821{ 2823{
2822 const u8 broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 2824 const u8 broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2823 2825
@@ -3084,7 +3086,7 @@ static int rtllib_wpa_enable(struct rtllib_device *ieee, int value)
3084 */ 3086 */
3085 netdev_info(ieee->dev, "%s WPA\n", value ? "enabling" : "disabling"); 3087 netdev_info(ieee->dev, "%s WPA\n", value ? "enabling" : "disabling");
3086 ieee->wpa_enabled = value; 3088 ieee->wpa_enabled = value;
3087 memset(ieee->ap_mac_addr, 0, 6); 3089 eth_zero_addr(ieee->ap_mac_addr);
3088 return 0; 3090 return 0;
3089} 3091}
3090 3092
diff --git a/drivers/staging/rtl8192e/rtllib_tx.c b/drivers/staging/rtl8192e/rtllib_tx.c
index e99ea5e67ef9..b992e4612fd8 100644
--- a/drivers/staging/rtl8192e/rtllib_tx.c
+++ b/drivers/staging/rtl8192e/rtllib_tx.c
@@ -151,7 +151,7 @@
151static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 }; 151static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
152static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 }; 152static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
153 153
154inline int rtllib_put_snap(u8 *data, u16 h_proto) 154static int rtllib_put_snap(u8 *data, u16 h_proto)
155{ 155{
156 struct rtllib_snap_hdr *snap; 156 struct rtllib_snap_hdr *snap;
157 u8 *oui; 157 u8 *oui;
@@ -205,7 +205,6 @@ int rtllib_encrypt_fragment(struct rtllib_device *ieee, struct sk_buff *frag,
205 if (res < 0) { 205 if (res < 0) {
206 netdev_info(ieee->dev, "%s: Encryption failed: len=%d.\n", 206 netdev_info(ieee->dev, "%s: Encryption failed: len=%d.\n",
207 ieee->dev->name, frag->len); 207 ieee->dev->name, frag->len);
208 ieee->ieee_stats.tx_discards++;
209 return -1; 208 return -1;
210 } 209 }
211 210
@@ -515,8 +514,8 @@ static void rtllib_txrate_selectmode(struct rtllib_device *ieee,
515 } 514 }
516} 515}
517 516
518u16 rtllib_query_seqnum(struct rtllib_device *ieee, struct sk_buff *skb, 517static u16 rtllib_query_seqnum(struct rtllib_device *ieee, struct sk_buff *skb,
519 u8 *dst) 518 u8 *dst)
520{ 519{
521 u16 seqnum = 0; 520 u16 seqnum = 0;
522 521
@@ -566,7 +565,7 @@ static u8 rtllib_current_rate(struct rtllib_device *ieee)
566 return ieee->rate & 0x7F; 565 return ieee->rate & 0x7F;
567} 566}
568 567
569int rtllib_xmit_inter(struct sk_buff *skb, struct net_device *dev) 568static int rtllib_xmit_inter(struct sk_buff *skb, struct net_device *dev)
570{ 569{
571 struct rtllib_device *ieee = (struct rtllib_device *) 570 struct rtllib_device *ieee = (struct rtllib_device *)
572 netdev_priv_rsl(dev); 571 netdev_priv_rsl(dev);
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
index 23af2aad458e..d481a26c25ae 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
@@ -2169,98 +2169,99 @@ static inline int ieee80211_is_cck_rate(u8 rate)
2169 2169
2170 2170
2171/* ieee80211.c */ 2171/* ieee80211.c */
2172extern void free_ieee80211(struct net_device *dev); 2172void free_ieee80211(struct net_device *dev);
2173extern struct net_device *alloc_ieee80211(int sizeof_priv); 2173struct net_device *alloc_ieee80211(int sizeof_priv);
2174 2174
2175extern int ieee80211_set_encryption(struct ieee80211_device *ieee); 2175int ieee80211_set_encryption(struct ieee80211_device *ieee);
2176 2176
2177/* ieee80211_tx.c */ 2177/* ieee80211_tx.c */
2178 2178
2179extern int ieee80211_encrypt_fragment( 2179int ieee80211_encrypt_fragment(struct ieee80211_device *ieee,
2180 struct ieee80211_device *ieee, 2180 struct sk_buff *frag, int hdr_len);
2181 struct sk_buff *frag,
2182 int hdr_len);
2183 2181
2184extern int ieee80211_xmit(struct sk_buff *skb, 2182int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev);
2185 struct net_device *dev); 2183void ieee80211_txb_free(struct ieee80211_txb *);
2186extern void ieee80211_txb_free(struct ieee80211_txb *);
2187 2184
2188 2185
2189/* ieee80211_rx.c */ 2186/* ieee80211_rx.c */
2190extern int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb, 2187int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
2191 struct ieee80211_rx_stats *rx_stats); 2188 struct ieee80211_rx_stats *rx_stats);
2192extern void ieee80211_rx_mgt(struct ieee80211_device *ieee, 2189void ieee80211_rx_mgt(struct ieee80211_device *ieee,
2193 struct rtl_80211_hdr_4addr *header, 2190 struct rtl_80211_hdr_4addr *header,
2194 struct ieee80211_rx_stats *stats); 2191 struct ieee80211_rx_stats *stats);
2195 2192
2196/* ieee80211_wx.c */ 2193/* ieee80211_wx.c */
2197extern int ieee80211_wx_get_scan(struct ieee80211_device *ieee, 2194int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
2198 struct iw_request_info *info, 2195 struct iw_request_info *info,
2199 union iwreq_data *wrqu, char *key); 2196 union iwreq_data *wrqu, char *key);
2200extern int ieee80211_wx_set_encode(struct ieee80211_device *ieee, 2197int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
2201 struct iw_request_info *info,
2202 union iwreq_data *wrqu, char *key);
2203extern int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
2204 struct iw_request_info *info,
2205 union iwreq_data *wrqu, char *key);
2206extern int ieee80211_wx_get_encode_ext(struct ieee80211_device *ieee,
2207 struct iw_request_info *info, 2198 struct iw_request_info *info,
2208 union iwreq_data *wrqu, char *extra); 2199 union iwreq_data *wrqu, char *key);
2209extern int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee, 2200int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
2210 struct iw_request_info *info, 2201 struct iw_request_info *info,
2211 union iwreq_data *wrqu, char *extra); 2202 union iwreq_data *wrqu, char *key);
2212extern int ieee80211_wx_set_auth(struct ieee80211_device *ieee, 2203int ieee80211_wx_get_encode_ext(struct ieee80211_device *ieee,
2213 struct iw_request_info *info, 2204 struct iw_request_info *info,
2214 struct iw_param *data, char *extra); 2205 union iwreq_data *wrqu, char *extra);
2215extern int ieee80211_wx_set_mlme(struct ieee80211_device *ieee, 2206int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
2216 struct iw_request_info *info, 2207 struct iw_request_info *info,
2217 union iwreq_data *wrqu, char *extra); 2208 union iwreq_data *wrqu, char *extra);
2218extern int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len); 2209int ieee80211_wx_set_auth(struct ieee80211_device *ieee,
2210 struct iw_request_info *info,
2211 struct iw_param *data, char *extra);
2212int ieee80211_wx_set_mlme(struct ieee80211_device *ieee,
2213 struct iw_request_info *info,
2214 union iwreq_data *wrqu, char *extra);
2215int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len);
2219 2216
2220/* ieee80211_softmac.c */ 2217/* ieee80211_softmac.c */
2221extern short ieee80211_is_54g(const struct ieee80211_network *net); 2218short ieee80211_is_54g(const struct ieee80211_network *net);
2222extern short ieee80211_is_shortslot(const struct ieee80211_network *net); 2219short ieee80211_is_shortslot(const struct ieee80211_network *net);
2223extern int ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb, 2220int ieee80211_rx_frame_softmac(struct ieee80211_device *ieee,
2224 struct ieee80211_rx_stats *rx_stats, u16 type, 2221 struct sk_buff *skb,
2225 u16 stype); 2222 struct ieee80211_rx_stats *rx_stats,
2226extern void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee80211_network *net); 2223 u16 type, u16 stype);
2224void ieee80211_softmac_new_net(struct ieee80211_device *ieee,
2225 struct ieee80211_network *net);
2227 2226
2228void SendDisassociation(struct ieee80211_device *ieee, u8 *asSta, u8 asRsn); 2227void SendDisassociation(struct ieee80211_device *ieee, u8 *asSta, u8 asRsn);
2229extern void ieee80211_softmac_xmit(struct ieee80211_txb *txb, struct ieee80211_device *ieee); 2228void ieee80211_softmac_xmit(struct ieee80211_txb *txb,
2230 2229 struct ieee80211_device *ieee);
2231extern void ieee80211_stop_send_beacons(struct ieee80211_device *ieee); 2230
2232extern void notify_wx_assoc_event(struct ieee80211_device *ieee); 2231void ieee80211_stop_send_beacons(struct ieee80211_device *ieee);
2233extern void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee); 2232void notify_wx_assoc_event(struct ieee80211_device *ieee);
2234extern void ieee80211_start_bss(struct ieee80211_device *ieee); 2233void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee);
2235extern void ieee80211_start_master_bss(struct ieee80211_device *ieee); 2234void ieee80211_start_bss(struct ieee80211_device *ieee);
2236extern void ieee80211_start_ibss(struct ieee80211_device *ieee); 2235void ieee80211_start_master_bss(struct ieee80211_device *ieee);
2237extern void ieee80211_softmac_init(struct ieee80211_device *ieee); 2236void ieee80211_start_ibss(struct ieee80211_device *ieee);
2238extern void ieee80211_softmac_free(struct ieee80211_device *ieee); 2237void ieee80211_softmac_init(struct ieee80211_device *ieee);
2239extern void ieee80211_associate_abort(struct ieee80211_device *ieee); 2238void ieee80211_softmac_free(struct ieee80211_device *ieee);
2240extern void ieee80211_disassociate(struct ieee80211_device *ieee); 2239void ieee80211_associate_abort(struct ieee80211_device *ieee);
2241extern void ieee80211_stop_scan(struct ieee80211_device *ieee); 2240void ieee80211_disassociate(struct ieee80211_device *ieee);
2242extern void ieee80211_start_scan_syncro(struct ieee80211_device *ieee); 2241void ieee80211_stop_scan(struct ieee80211_device *ieee);
2243extern void ieee80211_check_all_nets(struct ieee80211_device *ieee); 2242void ieee80211_start_scan_syncro(struct ieee80211_device *ieee);
2244extern void ieee80211_start_protocol(struct ieee80211_device *ieee); 2243void ieee80211_check_all_nets(struct ieee80211_device *ieee);
2245extern void ieee80211_stop_protocol(struct ieee80211_device *ieee); 2244void ieee80211_start_protocol(struct ieee80211_device *ieee);
2246extern void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee); 2245void ieee80211_stop_protocol(struct ieee80211_device *ieee);
2247extern void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee); 2246void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee);
2248extern void ieee80211_reset_queue(struct ieee80211_device *ieee); 2247void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee);
2249extern void ieee80211_wake_queue(struct ieee80211_device *ieee); 2248void ieee80211_reset_queue(struct ieee80211_device *ieee);
2250extern void ieee80211_stop_queue(struct ieee80211_device *ieee); 2249void ieee80211_wake_queue(struct ieee80211_device *ieee);
2251extern struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee); 2250void ieee80211_stop_queue(struct ieee80211_device *ieee);
2252extern void ieee80211_start_send_beacons(struct ieee80211_device *ieee); 2251struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee);
2253extern void ieee80211_stop_send_beacons(struct ieee80211_device *ieee); 2252void ieee80211_start_send_beacons(struct ieee80211_device *ieee);
2254extern int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, struct iw_point *p); 2253void ieee80211_stop_send_beacons(struct ieee80211_device *ieee);
2255extern void notify_wx_assoc_event(struct ieee80211_device *ieee); 2254int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee,
2256extern void ieee80211_ps_tx_ack(struct ieee80211_device *ieee, short success); 2255 struct iw_point *p);
2257 2256void notify_wx_assoc_event(struct ieee80211_device *ieee);
2258extern void softmac_mgmt_xmit(struct sk_buff *skb, struct ieee80211_device *ieee); 2257void ieee80211_ps_tx_ack(struct ieee80211_device *ieee, short success);
2258
2259void softmac_mgmt_xmit(struct sk_buff *skb, struct ieee80211_device *ieee);
2259 2260
2260/* ieee80211_crypt_ccmp&tkip&wep.c */ 2261/* ieee80211_crypt_ccmp&tkip&wep.c */
2261extern void ieee80211_tkip_null(void); 2262void ieee80211_tkip_null(void);
2262extern void ieee80211_wep_null(void); 2263void ieee80211_wep_null(void);
2263extern void ieee80211_ccmp_null(void); 2264void ieee80211_ccmp_null(void);
2264 2265
2265int ieee80211_crypto_init(void); 2266int ieee80211_crypto_init(void);
2266void ieee80211_crypto_deinit(void); 2267void ieee80211_crypto_deinit(void);
@@ -2273,116 +2274,128 @@ void ieee80211_crypto_wep_exit(void);
2273 2274
2274/* ieee80211_softmac_wx.c */ 2275/* ieee80211_softmac_wx.c */
2275 2276
2276extern int ieee80211_wx_get_wap(struct ieee80211_device *ieee, 2277int ieee80211_wx_get_wap(struct ieee80211_device *ieee,
2277 struct iw_request_info *info, 2278 struct iw_request_info *info,
2278 union iwreq_data *wrqu, char *ext); 2279 union iwreq_data *wrqu, char *ext);
2279 2280
2280extern int ieee80211_wx_set_wap(struct ieee80211_device *ieee, 2281int ieee80211_wx_set_wap(struct ieee80211_device *ieee,
2281 struct iw_request_info *info, 2282 struct iw_request_info *info,
2282 union iwreq_data *awrq, 2283 union iwreq_data *awrq,
2283 char *extra); 2284 char *extra);
2284 2285
2285extern int ieee80211_wx_get_essid(struct ieee80211_device *ieee, struct iw_request_info *a,union iwreq_data *wrqu,char *b); 2286int ieee80211_wx_get_essid(struct ieee80211_device *ieee,
2287 struct iw_request_info *a,
2288 union iwreq_data *wrqu, char *b);
2286 2289
2287extern int ieee80211_wx_set_rate(struct ieee80211_device *ieee, 2290int ieee80211_wx_set_rate(struct ieee80211_device *ieee,
2288 struct iw_request_info *info, 2291 struct iw_request_info *info,
2289 union iwreq_data *wrqu, char *extra); 2292 union iwreq_data *wrqu, char *extra);
2290 2293
2291extern int ieee80211_wx_get_rate(struct ieee80211_device *ieee, 2294int ieee80211_wx_get_rate(struct ieee80211_device *ieee,
2292 struct iw_request_info *info, 2295 struct iw_request_info *info,
2293 union iwreq_data *wrqu, char *extra); 2296 union iwreq_data *wrqu, char *extra);
2294 2297
2295extern int ieee80211_wx_set_mode(struct ieee80211_device *ieee, struct iw_request_info *a, 2298int ieee80211_wx_set_mode(struct ieee80211_device *ieee,
2296 union iwreq_data *wrqu, char *b); 2299 struct iw_request_info *a,
2300 union iwreq_data *wrqu, char *b);
2297 2301
2298extern int ieee80211_wx_set_scan(struct ieee80211_device *ieee, struct iw_request_info *a, 2302int ieee80211_wx_set_scan(struct ieee80211_device *ieee,
2299 union iwreq_data *wrqu, char *b); 2303 struct iw_request_info *a,
2304 union iwreq_data *wrqu, char *b);
2300 2305
2301extern int ieee80211_wx_set_essid(struct ieee80211_device *ieee, 2306int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
2302 struct iw_request_info *a, 2307 struct iw_request_info *a,
2303 union iwreq_data *wrqu, char *extra); 2308 union iwreq_data *wrqu, char *extra);
2304 2309
2305extern int ieee80211_wx_get_mode(struct ieee80211_device *ieee, struct iw_request_info *a, 2310int ieee80211_wx_get_mode(struct ieee80211_device *ieee,
2306 union iwreq_data *wrqu, char *b); 2311 struct iw_request_info *a,
2312 union iwreq_data *wrqu, char *b);
2307 2313
2308extern int ieee80211_wx_set_freq(struct ieee80211_device *ieee, struct iw_request_info *a, 2314int ieee80211_wx_set_freq(struct ieee80211_device *ieee,
2309 union iwreq_data *wrqu, char *b); 2315 struct iw_request_info *a,
2316 union iwreq_data *wrqu, char *b);
2310 2317
2311extern int ieee80211_wx_get_freq(struct ieee80211_device *ieee, struct iw_request_info *a, 2318int ieee80211_wx_get_freq(struct ieee80211_device *ieee,
2312 union iwreq_data *wrqu, char *b); 2319 struct iw_request_info *a,
2320 union iwreq_data *wrqu, char *b);
2313 2321
2314/* ieee80211_module.c */ 2322/* ieee80211_module.c */
2315extern int ieee80211_debug_init(void); 2323int ieee80211_debug_init(void);
2316extern void ieee80211_debug_exit(void); 2324void ieee80211_debug_exit(void);
2317 2325
2318//extern void ieee80211_wx_sync_scan_wq(struct ieee80211_device *ieee); 2326//extern void ieee80211_wx_sync_scan_wq(struct ieee80211_device *ieee);
2319extern void ieee80211_wx_sync_scan_wq(struct work_struct *work); 2327void ieee80211_wx_sync_scan_wq(struct work_struct *work);
2320 2328
2321 2329
2322extern int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee, 2330int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
2323 struct iw_request_info *info, 2331 struct iw_request_info *info,
2324 union iwreq_data *wrqu, char *extra); 2332 union iwreq_data *wrqu, char *extra);
2325 2333
2326extern int ieee80211_wx_get_name(struct ieee80211_device *ieee, 2334int ieee80211_wx_get_name(struct ieee80211_device *ieee,
2327 struct iw_request_info *info, 2335 struct iw_request_info *info,
2328 union iwreq_data *wrqu, char *extra); 2336 union iwreq_data *wrqu, char *extra);
2329 2337
2330extern int ieee80211_wx_set_power(struct ieee80211_device *ieee, 2338int ieee80211_wx_set_power(struct ieee80211_device *ieee,
2331 struct iw_request_info *info, 2339 struct iw_request_info *info,
2332 union iwreq_data *wrqu, char *extra); 2340 union iwreq_data *wrqu, char *extra);
2333 2341
2334extern int ieee80211_wx_get_power(struct ieee80211_device *ieee, 2342int ieee80211_wx_get_power(struct ieee80211_device *ieee,
2335 struct iw_request_info *info, 2343 struct iw_request_info *info,
2336 union iwreq_data *wrqu, char *extra); 2344 union iwreq_data *wrqu, char *extra);
2337 2345
2338extern int ieee80211_wx_set_rts(struct ieee80211_device *ieee, 2346int ieee80211_wx_set_rts(struct ieee80211_device *ieee,
2339 struct iw_request_info *info, 2347 struct iw_request_info *info,
2340 union iwreq_data *wrqu, char *extra); 2348 union iwreq_data *wrqu, char *extra);
2341 2349
2342extern int ieee80211_wx_get_rts(struct ieee80211_device *ieee, 2350int ieee80211_wx_get_rts(struct ieee80211_device *ieee,
2343 struct iw_request_info *info, 2351 struct iw_request_info *info,
2344 union iwreq_data *wrqu, char *extra); 2352 union iwreq_data *wrqu, char *extra);
2345//HT 2353//HT
2346#define MAX_RECEIVE_BUFFER_SIZE 9100 // 2354#define MAX_RECEIVE_BUFFER_SIZE 9100 //
2347extern void HTDebugHTCapability(u8 *CapIE, u8 *TitleString ); 2355void HTDebugHTCapability(u8 *CapIE, u8 *TitleString);
2348extern void HTDebugHTInfo(u8 *InfoIE, u8 *TitleString); 2356void HTDebugHTInfo(u8 *InfoIE, u8 *TitleString);
2349 2357
2350void HTSetConnectBwMode(struct ieee80211_device *ieee, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET Offset); 2358void HTSetConnectBwMode(struct ieee80211_device *ieee,
2351extern void HTUpdateDefaultSetting(struct ieee80211_device *ieee); 2359 HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET Offset);
2352extern void HTConstructCapabilityElement(struct ieee80211_device *ieee, u8 *posHTCap, u8 *len, u8 isEncrypt); 2360void HTUpdateDefaultSetting(struct ieee80211_device *ieee);
2353extern void HTConstructInfoElement(struct ieee80211_device *ieee, u8 *posHTInfo, u8 *len, u8 isEncrypt); 2361void HTConstructCapabilityElement(struct ieee80211_device *ieee, u8 *posHTCap,
2354extern void HTConstructRT2RTAggElement(struct ieee80211_device *ieee, u8 *posRT2RTAgg, u8 *len); 2362 u8 *len, u8 isEncrypt);
2355extern void HTOnAssocRsp(struct ieee80211_device *ieee); 2363void HTConstructInfoElement(struct ieee80211_device *ieee, u8 *posHTInfo,
2356extern void HTInitializeHTInfo(struct ieee80211_device *ieee); 2364 u8 *len, u8 isEncrypt);
2357extern void HTInitializeBssDesc(PBSS_HT pBssHT); 2365void HTConstructRT2RTAggElement(struct ieee80211_device *ieee, u8 *posRT2RTAgg,
2358extern void HTResetSelfAndSavePeerSetting(struct ieee80211_device *ieee, struct ieee80211_network *pNetwork); 2366 u8 *len);
2359extern void HTUpdateSelfAndPeerSetting(struct ieee80211_device *ieee, struct ieee80211_network *pNetwork); 2367void HTOnAssocRsp(struct ieee80211_device *ieee);
2360extern u8 HTGetHighestMCSRate(struct ieee80211_device *ieee, u8 *pMCSRateSet, u8 *pMCSFilter); 2368void HTInitializeHTInfo(struct ieee80211_device *ieee);
2369void HTInitializeBssDesc(PBSS_HT pBssHT);
2370void HTResetSelfAndSavePeerSetting(struct ieee80211_device *ieee,
2371 struct ieee80211_network *pNetwork);
2372void HTUpdateSelfAndPeerSetting(struct ieee80211_device *ieee,
2373 struct ieee80211_network *pNetwork);
2374u8 HTGetHighestMCSRate(struct ieee80211_device *ieee,
2375 u8 *pMCSRateSet, u8 *pMCSFilter);
2361extern u8 MCS_FILTER_ALL[]; 2376extern u8 MCS_FILTER_ALL[];
2362extern u16 MCS_DATA_RATE[2][2][77] ; 2377extern u16 MCS_DATA_RATE[2][2][77] ;
2363extern u8 HTCCheck(struct ieee80211_device *ieee, u8 *pFrame); 2378u8 HTCCheck(struct ieee80211_device *ieee, u8 *pFrame);
2364//extern void HTSetConnectBwModeCallback(unsigned long data); 2379//extern void HTSetConnectBwModeCallback(unsigned long data);
2365extern void HTResetIOTSetting(PRT_HIGH_THROUGHPUT pHTInfo); 2380void HTResetIOTSetting(PRT_HIGH_THROUGHPUT pHTInfo);
2366extern bool IsHTHalfNmodeAPs(struct ieee80211_device *ieee); 2381bool IsHTHalfNmodeAPs(struct ieee80211_device *ieee);
2367extern u16 HTHalfMcsToDataRate(struct ieee80211_device *ieee, u8 nMcsRate); 2382u16 HTHalfMcsToDataRate(struct ieee80211_device *ieee, u8 nMcsRate);
2368extern u16 HTMcsToDataRate(struct ieee80211_device *ieee, u8 nMcsRate); 2383u16 HTMcsToDataRate(struct ieee80211_device *ieee, u8 nMcsRate);
2369extern u16 TxCountToDataRate(struct ieee80211_device *ieee, u8 nDataRate); 2384u16 TxCountToDataRate(struct ieee80211_device *ieee, u8 nDataRate);
2370//function in BAPROC.c 2385//function in BAPROC.c
2371extern int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, 2386int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb);
2372 struct sk_buff *skb); 2387int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb);
2373extern int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, 2388int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb);
2374 struct sk_buff *skb); 2389void TsInitAddBA(struct ieee80211_device *ieee, PTX_TS_RECORD pTS,
2375extern int ieee80211_rx_DELBA(struct ieee80211_device *ieee,struct sk_buff *skb); 2390 u8 Policy, u8 bOverwritePending);
2376extern void TsInitAddBA(struct ieee80211_device *ieee, PTX_TS_RECORD pTS, 2391void TsInitDelBA(struct ieee80211_device *ieee,
2377 u8 Policy, u8 bOverwritePending); 2392 PTS_COMMON_INFO pTsCommonInfo, TR_SELECT TxRxSelect);
2378extern void TsInitDelBA(struct ieee80211_device *ieee, 2393void BaSetupTimeOut(unsigned long data);
2379 PTS_COMMON_INFO pTsCommonInfo, TR_SELECT TxRxSelect); 2394void TxBaInactTimeout(unsigned long data);
2380extern void BaSetupTimeOut(unsigned long data); 2395void RxBaInactTimeout(unsigned long data);
2381extern void TxBaInactTimeout(unsigned long data); 2396void ResetBaEntry(PBA_RECORD pBA);
2382extern void RxBaInactTimeout(unsigned long data);
2383extern void ResetBaEntry(PBA_RECORD pBA);
2384//function in TS.c 2397//function in TS.c
2385extern bool GetTs( 2398bool GetTs(
2386 struct ieee80211_device *ieee, 2399 struct ieee80211_device *ieee,
2387 PTS_COMMON_INFO *ppTS, 2400 PTS_COMMON_INFO *ppTS,
2388 u8 *Addr, 2401 u8 *Addr,
@@ -2390,10 +2403,10 @@ extern bool GetTs(
2390 TR_SELECT TxRxSelect, //Rx:1, Tx:0 2403 TR_SELECT TxRxSelect, //Rx:1, Tx:0
2391 bool bAddNewTs 2404 bool bAddNewTs
2392 ); 2405 );
2393extern void TSInitialize(struct ieee80211_device *ieee); 2406void TSInitialize(struct ieee80211_device *ieee);
2394extern void TsStartAddBaProcess(struct ieee80211_device *ieee, PTX_TS_RECORD pTxTS); 2407void TsStartAddBaProcess(struct ieee80211_device *ieee, PTX_TS_RECORD pTxTS);
2395extern void RemovePeerTS(struct ieee80211_device *ieee, u8 *Addr); 2408void RemovePeerTS(struct ieee80211_device *ieee, u8 *Addr);
2396extern void RemoveAllTS(struct ieee80211_device *ieee); 2409void RemoveAllTS(struct ieee80211_device *ieee);
2397void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee); 2410void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee);
2398 2411
2399extern const long ieee80211_wlan_frequencies[]; 2412extern const long ieee80211_wlan_frequencies[];
@@ -2423,14 +2436,16 @@ static inline const char *escape_essid(const char *essid, u8 essid_len) {
2423/* For the function is more related to hardware setting, it's better to use the 2436/* For the function is more related to hardware setting, it's better to use the
2424 * ieee handler to refer to it. 2437 * ieee handler to refer to it.
2425 */ 2438 */
2426extern short check_nic_enough_desc(struct net_device *dev, int queue_index); 2439short check_nic_enough_desc(struct net_device *dev, int queue_index);
2427extern int ieee80211_data_xmit(struct sk_buff *skb, struct net_device *dev); 2440int ieee80211_data_xmit(struct sk_buff *skb, struct net_device *dev);
2428extern int ieee80211_parse_info_param(struct ieee80211_device *ieee, 2441int ieee80211_parse_info_param(struct ieee80211_device *ieee,
2429 struct ieee80211_info_element *info_element, 2442 struct ieee80211_info_element *info_element,
2430 u16 length, 2443 u16 length,
2431 struct ieee80211_network *network, 2444 struct ieee80211_network *network,
2432 struct ieee80211_rx_stats *stats); 2445 struct ieee80211_rx_stats *stats);
2433 2446
2434void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb **prxbIndicateArray,u8 index); 2447void ieee80211_indicate_packets(struct ieee80211_device *ieee,
2448 struct ieee80211_rxb **prxbIndicateArray,
2449 u8 index);
2435#define RT_ASOC_RETRY_LIMIT 5 2450#define RT_ASOC_RETRY_LIMIT 5
2436#endif /* IEEE80211_H */ 2451#endif /* IEEE80211_H */
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
index b374088c5ff8..0aa9021cb95e 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
@@ -1014,7 +1014,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1014 goto rx_dropped; 1014 goto rx_dropped;
1015 1015
1016 // if QoS enabled, should check the sequence for each of the AC 1016 // if QoS enabled, should check the sequence for each of the AC
1017 if( (ieee->pHTInfo->bCurRxReorderEnable == false) || !ieee->current_network.qos_data.active|| !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)){ 1017 if ((!ieee->pHTInfo->bCurRxReorderEnable) || !ieee->current_network.qos_data.active|| !IsDataFrame(skb->data) || IsLegacyDataFrame(skb->data)) {
1018 if (is_duplicate_packet(ieee, hdr)) 1018 if (is_duplicate_packet(ieee, hdr))
1019 goto rx_dropped; 1019 goto rx_dropped;
1020 1020
@@ -1307,7 +1307,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1307 } 1307 }
1308 1308
1309//added by amy for reorder 1309//added by amy for reorder
1310 if(ieee->pHTInfo->bCurRxReorderEnable == false ||pTS == NULL){ 1310 if (!ieee->pHTInfo->bCurRxReorderEnable || pTS == NULL){
1311//added by amy for reorder 1311//added by amy for reorder
1312 for(i = 0; i<rxb->nr_subframes; i++) { 1312 for(i = 0; i<rxb->nr_subframes; i++) {
1313 struct sk_buff *sub_skb = rxb->subframes[i]; 1313 struct sk_buff *sub_skb = rxb->subframes[i];
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index 1b11acb96233..39e9892c3fa6 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -1177,7 +1177,7 @@ inline struct sk_buff *ieee80211_association_req(struct ieee80211_network *beaco
1177 tag = skb_put(skb, ht_cap_len); 1177 tag = skb_put(skb, ht_cap_len);
1178 *tag++ = MFIE_TYPE_HT_CAP; 1178 *tag++ = MFIE_TYPE_HT_CAP;
1179 *tag++ = ht_cap_len - 2; 1179 *tag++ = ht_cap_len - 2;
1180 memcpy(tag, ht_cap_buf,ht_cap_len -2); 1180 memcpy(tag, ht_cap_buf, ht_cap_len - 2);
1181 tag += ht_cap_len -2; 1181 tag += ht_cap_len -2;
1182 } 1182 }
1183 } 1183 }
@@ -1214,7 +1214,7 @@ inline struct sk_buff *ieee80211_association_req(struct ieee80211_network *beaco
1214 tag = skb_put(skb, realtek_ie_len); 1214 tag = skb_put(skb, realtek_ie_len);
1215 *tag++ = MFIE_TYPE_GENERIC; 1215 *tag++ = MFIE_TYPE_GENERIC;
1216 *tag++ = realtek_ie_len - 2; 1216 *tag++ = realtek_ie_len - 2;
1217 memcpy(tag, realtek_ie_buf,realtek_ie_len -2 ); 1217 memcpy(tag, realtek_ie_buf, realtek_ie_len - 2);
1218 } 1218 }
1219 } 1219 }
1220// printk("<=====%s(), %p, %p\n", __func__, ieee->dev, ieee->dev->dev_addr); 1220// printk("<=====%s(), %p, %p\n", __func__, ieee->dev, ieee->dev->dev_addr);
@@ -1964,7 +1964,7 @@ static void ieee80211_check_auth_response(struct ieee80211_device *ieee,
1964 } 1964 }
1965 1965
1966 if (ieee->current_network.mode == IEEE_N_24G && 1966 if (ieee->current_network.mode == IEEE_N_24G &&
1967 bHalfSupportNmode == true) { 1967 bHalfSupportNmode) {
1968 netdev_dbg(ieee->dev, "enter half N mode\n"); 1968 netdev_dbg(ieee->dev, "enter half N mode\n");
1969 ieee->bHalfWirelessN24GMode = true; 1969 ieee->bHalfWirelessN24GMode = true;
1970 } else 1970 } else
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
index 714fbcace72b..3e502520648e 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
@@ -391,7 +391,7 @@ int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
391 union iwreq_data *wrqu, char *extra) 391 union iwreq_data *wrqu, char *extra)
392{ 392{
393 393
394 int ret=0,len; 394 int ret = 0, len;
395 short proto_started; 395 short proto_started;
396 unsigned long flags; 396 unsigned long flags;
397 397
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
index 5353a45ffdff..fff8d583c62f 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
@@ -336,12 +336,12 @@ static void ieee80211_tx_query_agg_cap(struct ieee80211_device *ieee,
336 printk("===>can't get TS\n"); 336 printk("===>can't get TS\n");
337 return; 337 return;
338 } 338 }
339 if (pTxTs->TxAdmittedBARecord.bValid == false) 339 if (!pTxTs->TxAdmittedBARecord.bValid)
340 { 340 {
341 TsStartAddBaProcess(ieee, pTxTs); 341 TsStartAddBaProcess(ieee, pTxTs);
342 goto FORCED_AGG_SETTING; 342 goto FORCED_AGG_SETTING;
343 } 343 }
344 else if (pTxTs->bUsingBa == false) 344 else if (!pTxTs->bUsingBa)
345 { 345 {
346 if (SN_LESS(pTxTs->TxAdmittedBARecord.BaStartSeqCtrl.field.SeqNum, (pTxTs->TxCurSeq+1)%4096)) 346 if (SN_LESS(pTxTs->TxAdmittedBARecord.BaStartSeqCtrl.field.SeqNum, (pTxTs->TxCurSeq+1)%4096))
347 pTxTs->bUsingBa = true; 347 pTxTs->bUsingBa = true;
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
index 9ff8e056ab7f..3bde744604c2 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
@@ -364,8 +364,8 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb)
364 printk("====================>rx ADDBAREQ from :%pM\n", dst); 364 printk("====================>rx ADDBAREQ from :%pM\n", dst);
365//some other capability is not ready now. 365//some other capability is not ready now.
366 if ((ieee->current_network.qos_data.active == 0) || 366 if ((ieee->current_network.qos_data.active == 0) ||
367 (ieee->pHTInfo->bCurrentHTSupport == false)) //|| 367 (!ieee->pHTInfo->bCurrentHTSupport)) //||
368 // (ieee->pStaQos->bEnableRxImmBA == false) ) 368 // (!ieee->pStaQos->bEnableRxImmBA) )
369 { 369 {
370 rc = ADDBA_STATUS_REFUSED; 370 rc = ADDBA_STATUS_REFUSED;
371 IEEE80211_DEBUG(IEEE80211_DL_ERR, "Failed to reply on ADDBA_REQ as some capability is not ready(%d, %d)\n", ieee->current_network.qos_data.active, ieee->pHTInfo->bCurrentHTSupport); 371 IEEE80211_DEBUG(IEEE80211_DL_ERR, "Failed to reply on ADDBA_REQ as some capability is not ready(%d, %d)\n", ieee->current_network.qos_data.active, ieee->pHTInfo->bCurrentHTSupport);
@@ -462,8 +462,8 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
462 // Check the capability 462 // Check the capability
463 // Since we can always receive A-MPDU, we just check if it is under HT mode. 463 // Since we can always receive A-MPDU, we just check if it is under HT mode.
464 if (ieee->current_network.qos_data.active == 0 || 464 if (ieee->current_network.qos_data.active == 0 ||
465 ieee->pHTInfo->bCurrentHTSupport == false || 465 !ieee->pHTInfo->bCurrentHTSupport ||
466 ieee->pHTInfo->bCurrentAMPDUEnable == false) { 466 !ieee->pHTInfo->bCurrentAMPDUEnable) {
467 IEEE80211_DEBUG(IEEE80211_DL_ERR, "reject to ADDBA_RSP as some capability is not ready(%d, %d, %d)\n",ieee->current_network.qos_data.active, ieee->pHTInfo->bCurrentHTSupport, ieee->pHTInfo->bCurrentAMPDUEnable); 467 IEEE80211_DEBUG(IEEE80211_DL_ERR, "reject to ADDBA_RSP as some capability is not ready(%d, %d, %d)\n",ieee->current_network.qos_data.active, ieee->pHTInfo->bCurrentHTSupport, ieee->pHTInfo->bCurrentAMPDUEnable);
468 ReasonCode = DELBA_REASON_UNKNOWN_BA; 468 ReasonCode = DELBA_REASON_UNKNOWN_BA;
469 goto OnADDBARsp_Reject; 469 goto OnADDBARsp_Reject;
@@ -502,7 +502,7 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
502 IEEE80211_DEBUG(IEEE80211_DL_BA, "OnADDBARsp(): Recv ADDBA Rsp. Drop because already admit it! \n"); 502 IEEE80211_DEBUG(IEEE80211_DL_BA, "OnADDBARsp(): Recv ADDBA Rsp. Drop because already admit it! \n");
503 return -1; 503 return -1;
504 } 504 }
505 else if((pPendingBA->bValid == false) ||(*pDialogToken != pPendingBA->DialogToken)) 505 else if((!pPendingBA->bValid) ||(*pDialogToken != pPendingBA->DialogToken))
506 { 506 {
507 IEEE80211_DEBUG(IEEE80211_DL_ERR, "OnADDBARsp(): Recv ADDBA Rsp. BA invalid, DELBA! \n"); 507 IEEE80211_DEBUG(IEEE80211_DL_ERR, "OnADDBARsp(): Recv ADDBA Rsp. BA invalid, DELBA! \n");
508 ReasonCode = DELBA_REASON_UNKNOWN_BA; 508 ReasonCode = DELBA_REASON_UNKNOWN_BA;
@@ -571,7 +571,6 @@ int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb)
571{ 571{
572 struct rtl_80211_hdr_3addr *delba = NULL; 572 struct rtl_80211_hdr_3addr *delba = NULL;
573 PDELBA_PARAM_SET pDelBaParamSet = NULL; 573 PDELBA_PARAM_SET pDelBaParamSet = NULL;
574 u16 *pReasonCode = NULL;
575 u8 *dst = NULL; 574 u8 *dst = NULL;
576 575
577 if (skb->len < sizeof(struct rtl_80211_hdr_3addr) + 6) { 576 if (skb->len < sizeof(struct rtl_80211_hdr_3addr) + 6) {
@@ -583,7 +582,7 @@ int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb)
583 } 582 }
584 583
585 if (ieee->current_network.qos_data.active == 0 || 584 if (ieee->current_network.qos_data.active == 0 ||
586 ieee->pHTInfo->bCurrentHTSupport == false ) 585 !ieee->pHTInfo->bCurrentHTSupport)
587 { 586 {
588 IEEE80211_DEBUG(IEEE80211_DL_ERR, "received DELBA while QOS or HT is not supported(%d, %d)\n",ieee->current_network.qos_data.active, ieee->pHTInfo->bCurrentHTSupport); 587 IEEE80211_DEBUG(IEEE80211_DL_ERR, "received DELBA while QOS or HT is not supported(%d, %d)\n",ieee->current_network.qos_data.active, ieee->pHTInfo->bCurrentHTSupport);
589 return -1; 588 return -1;
@@ -592,9 +591,7 @@ int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb)
592 IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len); 591 IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len);
593 delba = (struct rtl_80211_hdr_3addr *)skb->data; 592 delba = (struct rtl_80211_hdr_3addr *)skb->data;
594 dst = (u8 *)(&delba->addr2[0]); 593 dst = (u8 *)(&delba->addr2[0]);
595 delba += sizeof(struct rtl_80211_hdr_3addr); 594 pDelBaParamSet = (PDELBA_PARAM_SET)&delba->payload[2];
596 pDelBaParamSet = (PDELBA_PARAM_SET)(delba+2);
597 pReasonCode = (u16 *)(delba+4);
598 595
599 if(pDelBaParamSet->field.Initiator == 1) 596 if(pDelBaParamSet->field.Initiator == 1)
600 { 597 {
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
index c2588f80625b..c27397b14adb 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
@@ -224,9 +224,9 @@ static bool IsHTHalfNmode40Bandwidth(struct ieee80211_device *ieee)
224 bool retValue = false; 224 bool retValue = false;
225 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 225 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
226 226
227 if(pHTInfo->bCurrentHTSupport == false ) // wireless is n mode 227 if(!pHTInfo->bCurrentHTSupport) // wireless is n mode
228 retValue = false; 228 retValue = false;
229 else if(pHTInfo->bRegBW40MHz == false) // station supports 40 bw 229 else if(!pHTInfo->bRegBW40MHz) // station supports 40 bw
230 retValue = false; 230 retValue = false;
231 else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode 231 else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode
232 retValue = false; 232 retValue = false;
@@ -243,7 +243,7 @@ static bool IsHTHalfNmodeSGI(struct ieee80211_device *ieee, bool is40MHz)
243 bool retValue = false; 243 bool retValue = false;
244 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 244 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
245 245
246 if(pHTInfo->bCurrentHTSupport == false ) // wireless is n mode 246 if(!pHTInfo->bCurrentHTSupport) // wireless is n mode
247 retValue = false; 247 retValue = false;
248 else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode 248 else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode
249 retValue = false; 249 retValue = false;
@@ -675,7 +675,7 @@ void HTConstructInfoElement(struct ieee80211_device *ieee, u8 *posHTInfo, u8 *le
675 if ( (ieee->iw_mode == IW_MODE_ADHOC) || (ieee->iw_mode == IW_MODE_MASTER)) //ap mode is not currently supported 675 if ( (ieee->iw_mode == IW_MODE_ADHOC) || (ieee->iw_mode == IW_MODE_MASTER)) //ap mode is not currently supported
676 { 676 {
677 pHTInfoEle->ControlChl = ieee->current_network.channel; 677 pHTInfoEle->ControlChl = ieee->current_network.channel;
678 pHTInfoEle->ExtChlOffset = ((pHT->bRegBW40MHz == false)?HT_EXTCHNL_OFFSET_NO_EXT: 678 pHTInfoEle->ExtChlOffset = ((!pHT->bRegBW40MHz)?HT_EXTCHNL_OFFSET_NO_EXT:
679 (ieee->current_network.channel<=6)? 679 (ieee->current_network.channel<=6)?
680 HT_EXTCHNL_OFFSET_UPPER:HT_EXTCHNL_OFFSET_LOWER); 680 HT_EXTCHNL_OFFSET_UPPER:HT_EXTCHNL_OFFSET_LOWER);
681 pHTInfoEle->RecommemdedTxWidth = pHT->bRegBW40MHz; 681 pHTInfoEle->RecommemdedTxWidth = pHT->bRegBW40MHz;
@@ -945,7 +945,7 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
945 static u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; // For 11n EWC definition, 2007.07.17, by Emily 945 static u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; // For 11n EWC definition, 2007.07.17, by Emily
946 static u8 EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34}; // For 11n EWC definition, 2007.07.17, by Emily 946 static u8 EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34}; // For 11n EWC definition, 2007.07.17, by Emily
947 947
948 if (pHTInfo->bCurrentHTSupport == false) { 948 if (!pHTInfo->bCurrentHTSupport) {
949 IEEE80211_DEBUG(IEEE80211_DL_ERR, "<=== HTOnAssocRsp(): HT_DISABLE\n"); 949 IEEE80211_DEBUG(IEEE80211_DL_ERR, "<=== HTOnAssocRsp(): HT_DISABLE\n");
950 return; 950 return;
951 } 951 }
@@ -956,7 +956,7 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
956// HTDebugHTCapability(pHTInfo->PeerHTCapBuf,"HTOnAssocRsp_wq"); 956// HTDebugHTCapability(pHTInfo->PeerHTCapBuf,"HTOnAssocRsp_wq");
957// HTDebugHTInfo(pHTInfo->PeerHTInfoBuf,"HTOnAssocRsp_wq"); 957// HTDebugHTInfo(pHTInfo->PeerHTInfoBuf,"HTOnAssocRsp_wq");
958 // 958 //
959 if(!memcmp(pHTInfo->PeerHTCapBuf,EWC11NHTCap, sizeof(EWC11NHTCap))) 959 if (!memcmp(pHTInfo->PeerHTCapBuf, EWC11NHTCap, sizeof(EWC11NHTCap)))
960 pPeerHTCap = (PHT_CAPABILITY_ELE)(&pHTInfo->PeerHTCapBuf[4]); 960 pPeerHTCap = (PHT_CAPABILITY_ELE)(&pHTInfo->PeerHTCapBuf[4]);
961 else 961 else
962 pPeerHTCap = (PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf); 962 pPeerHTCap = (PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf);
@@ -976,7 +976,7 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
976 // 976 //
977 HTSetConnectBwMode(ieee, (HT_CHANNEL_WIDTH)(pPeerHTCap->ChlWidth), (HT_EXTCHNL_OFFSET)(pPeerHTInfo->ExtChlOffset)); 977 HTSetConnectBwMode(ieee, (HT_CHANNEL_WIDTH)(pPeerHTCap->ChlWidth), (HT_EXTCHNL_OFFSET)(pPeerHTInfo->ExtChlOffset));
978 978
979// if(pHTInfo->bCurBW40MHz == true) 979// if (pHTInfo->bCurBW40MHz)
980 pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1)?true:false); 980 pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1)?true:false);
981 981
982 // 982 //
@@ -1341,7 +1341,7 @@ void HTSetConnectBwMode(struct ieee80211_device *ieee, HT_CHANNEL_WIDTH Bandwidt
1341 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 1341 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1342// u32 flags = 0; 1342// u32 flags = 0;
1343 1343
1344 if(pHTInfo->bRegBW40MHz == false) 1344 if(!pHTInfo->bRegBW40MHz)
1345 return; 1345 return;
1346 1346
1347 1347
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
index ea92fdebe5a7..f33c74342cf3 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
@@ -112,7 +112,7 @@ static void TsAddBaProcess(unsigned long data)
112 112
113static void ResetTsCommonInfo(PTS_COMMON_INFO pTsCommonInfo) 113static void ResetTsCommonInfo(PTS_COMMON_INFO pTsCommonInfo)
114{ 114{
115 memset(pTsCommonInfo->Addr, 0, 6); 115 eth_zero_addr(pTsCommonInfo->Addr);
116 memset(&pTsCommonInfo->TSpec, 0, sizeof(TSPEC_BODY)); 116 memset(&pTsCommonInfo->TSpec, 0, sizeof(TSPEC_BODY));
117 memset(&pTsCommonInfo->TClass, 0, sizeof(QOS_TCLAS)*TCLAS_NUM); 117 memset(&pTsCommonInfo->TClass, 0, sizeof(QOS_TCLAS)*TCLAS_NUM);
118 pTsCommonInfo->TClasProc = 0; 118 pTsCommonInfo->TClasProc = 0;
@@ -584,7 +584,7 @@ void RemoveAllTS(struct ieee80211_device *ieee)
584 584
585void TsStartAddBaProcess(struct ieee80211_device *ieee, PTX_TS_RECORD pTxTS) 585void TsStartAddBaProcess(struct ieee80211_device *ieee, PTX_TS_RECORD pTxTS)
586{ 586{
587 if(pTxTS->bAddBaReqInProgress == false) 587 if(!pTxTS->bAddBaReqInProgress)
588 { 588 {
589 pTxTS->bAddBaReqInProgress = true; 589 pTxTS->bAddBaReqInProgress = true;
590 if(pTxTS->bAddBaReqDelayed) 590 if(pTxTS->bAddBaReqDelayed)
diff --git a/drivers/staging/rtl8192u/r8190_rtl8256.h b/drivers/staging/rtl8192u/r8190_rtl8256.h
index 6e5662f7951c..1ba4f83b520e 100644
--- a/drivers/staging/rtl8192u/r8190_rtl8256.h
+++ b/drivers/staging/rtl8192u/r8190_rtl8256.h
@@ -14,11 +14,10 @@
14#define RTL8225H 14#define RTL8225H
15 15
16#define RTL819X_TOTAL_RF_PATH 2 /* for 8192U */ 16#define RTL819X_TOTAL_RF_PATH 2 /* for 8192U */
17extern void PHY_SetRF8256Bandwidth(struct net_device *dev, 17void PHY_SetRF8256Bandwidth(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth);
18 HT_CHANNEL_WIDTH Bandwidth); 18void PHY_RF8256_Config(struct net_device *dev);
19extern void PHY_RF8256_Config(struct net_device *dev); 19void phy_RF8256_Config_ParaFile(struct net_device *dev);
20extern void phy_RF8256_Config_ParaFile(struct net_device *dev); 20void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel);
21extern void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel); 21void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel);
22extern void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel);
23 22
24#endif 23#endif
diff --git a/drivers/staging/rtl8192u/r8192U.h b/drivers/staging/rtl8192u/r8192U.h
index 6c2e438c9af4..785fd027a00d 100644
--- a/drivers/staging/rtl8192u/r8192U.h
+++ b/drivers/staging/rtl8192u/r8192U.h
@@ -1187,7 +1187,7 @@ void write_phy_cck(struct net_device *dev, u8 adr, u32 data);
1187void write_phy_ofdm(struct net_device *dev, u8 adr, u32 data); 1187void write_phy_ofdm(struct net_device *dev, u8 adr, u32 data);
1188void rtl8185_tx_antenna(struct net_device *dev, u8 ant); 1188void rtl8185_tx_antenna(struct net_device *dev, u8 ant);
1189void rtl8192_set_rxconf(struct net_device *dev); 1189void rtl8192_set_rxconf(struct net_device *dev);
1190extern void rtl819xusb_beacon_tx(struct net_device *dev, u16 tx_rate); 1190void rtl819xusb_beacon_tx(struct net_device *dev, u16 tx_rate);
1191 1191
1192void EnableHWSecurityConfig8192(struct net_device *dev); 1192void EnableHWSecurityConfig8192(struct net_device *dev);
1193void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType, u8 *MacAddr, u8 DefaultKey, u32 *KeyContent); 1193void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType, u8 *MacAddr, u8 DefaultKey, u32 *KeyContent);
diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index b852396d21e6..6f6fe38081bc 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -2043,16 +2043,9 @@ static bool GetNmodeSupportBySecCfg8192(struct net_device *dev)
2043 2043
2044static bool GetHalfNmodeSupportByAPs819xUsb(struct net_device *dev) 2044static bool GetHalfNmodeSupportByAPs819xUsb(struct net_device *dev)
2045{ 2045{
2046 bool Reval;
2047 struct r8192_priv *priv = ieee80211_priv(dev); 2046 struct r8192_priv *priv = ieee80211_priv(dev);
2048 struct ieee80211_device *ieee = priv->ieee80211;
2049
2050 if (ieee->bHalfWirelessN24GMode == true)
2051 Reval = true;
2052 else
2053 Reval = false;
2054 2047
2055 return Reval; 2048 return priv->ieee80211->bHalfWirelessN24GMode;
2056} 2049}
2057 2050
2058static void rtl8192_refresh_supportrate(struct r8192_priv *priv) 2051static void rtl8192_refresh_supportrate(struct r8192_priv *priv)
@@ -2762,7 +2755,7 @@ static bool rtl8192_adapter_start(struct net_device *dev)
2762 // 2755 //
2763#ifdef TO_DO_LIST 2756#ifdef TO_DO_LIST
2764 if (Adapter->ResetProgress == RESET_TYPE_NORESET) { 2757 if (Adapter->ResetProgress == RESET_TYPE_NORESET) {
2765 if (pMgntInfo->RegRfOff == true) { /* User disable RF via registry. */ 2758 if (pMgntInfo->RegRfOff) { /* User disable RF via registry. */
2766 RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): Turn off RF for RegRfOff ----------\n")); 2759 RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): Turn off RF for RegRfOff ----------\n"));
2767 MgntActSet_RF_State(Adapter, eRfOff, RF_CHANGE_BY_SW); 2760 MgntActSet_RF_State(Adapter, eRfOff, RF_CHANGE_BY_SW);
2768 // Those actions will be discard in MgntActSet_RF_State because of the same state 2761 // Those actions will be discard in MgntActSet_RF_State because of the same state
@@ -4406,7 +4399,8 @@ static void query_rxdesc_status(struct sk_buff *skb,
4406 /* RTL8190 set this bit to indicate that Hw does not decrypt packet */ 4399 /* RTL8190 set this bit to indicate that Hw does not decrypt packet */
4407 stats->Decrypted = !desc->SWDec; 4400 stats->Decrypted = !desc->SWDec;
4408 4401
4409 if ((priv->ieee80211->pHTInfo->bCurrentHTSupport == true) && (priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP)) 4402 if ((priv->ieee80211->pHTInfo->bCurrentHTSupport) &&
4403 (priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP))
4410 stats->bHwError = false; 4404 stats->bHwError = false;
4411 else 4405 else
4412 stats->bHwError = stats->bCRC|stats->bICV; 4406 stats->bHwError = stats->bCRC|stats->bICV;
diff --git a/drivers/staging/rtl8192u/r8192U_dm.c b/drivers/staging/rtl8192u/r8192U_dm.c
index 7ca5d8fbc57f..5277f2eec033 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -438,7 +438,7 @@ static void dm_bandwidth_autoswitch(struct net_device *dev)
438 438
439 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 || !priv->ieee80211->bandwidth_auto_switch.bautoswitch_enable) 439 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 || !priv->ieee80211->bandwidth_auto_switch.bautoswitch_enable)
440 return; 440 return;
441 if (priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz == false) { /* If send packets in 40 Mhz in 20/40 */ 441 if (!priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz) { /* If send packets in 40 Mhz in 20/40 */
442 if (priv->undecorated_smoothed_pwdb <= priv->ieee80211->bandwidth_auto_switch.threshold_40Mhzto20Mhz) 442 if (priv->undecorated_smoothed_pwdb <= priv->ieee80211->bandwidth_auto_switch.threshold_40Mhzto20Mhz)
443 priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz = true; 443 priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz = true;
444 } else { /* in force send packets in 20 Mhz in 20/40 */ 444 } else { /* in force send packets in 20 Mhz in 20/40 */
@@ -1731,7 +1731,7 @@ static void dm_dig_init(struct net_device *dev)
1731 *---------------------------------------------------------------------------*/ 1731 *---------------------------------------------------------------------------*/
1732static void dm_ctrl_initgain_byrssi(struct net_device *dev) 1732static void dm_ctrl_initgain_byrssi(struct net_device *dev)
1733{ 1733{
1734 if (dm_digtable.dig_enable_flag == false) 1734 if (!dm_digtable.dig_enable_flag)
1735 return; 1735 return;
1736 1736
1737 if (dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM) 1737 if (dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
@@ -1750,7 +1750,7 @@ static void dm_ctrl_initgain_byrssi_by_driverrssi(
1750 u8 i; 1750 u8 i;
1751 static u8 fw_dig; 1751 static u8 fw_dig;
1752 1752
1753 if (dm_digtable.dig_enable_flag == false) 1753 if (!dm_digtable.dig_enable_flag)
1754 return; 1754 return;
1755 1755
1756 /*DbgPrint("Dig by Sw Rssi\n");*/ 1756 /*DbgPrint("Dig by Sw Rssi\n");*/
@@ -1792,7 +1792,7 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
1792 static u32 reset_cnt; 1792 static u32 reset_cnt;
1793 u8 i; 1793 u8 i;
1794 1794
1795 if (dm_digtable.dig_enable_flag == false) 1795 if (!dm_digtable.dig_enable_flag)
1796 return; 1796 return;
1797 1797
1798 if (dm_digtable.dig_algorithm_switch) { 1798 if (dm_digtable.dig_algorithm_switch) {
diff --git a/drivers/staging/rtl8192u/r8192U_dm.h b/drivers/staging/rtl8192u/r8192U_dm.h
index 6cd32eb44085..2d0232fb3f9b 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.h
+++ b/drivers/staging/rtl8192u/r8192U_dm.h
@@ -212,24 +212,24 @@ extern struct dynamic_rx_path_sel DM_RxPathSelTable;
212 212
213 213
214/*--------------------------Exported Function prototype---------------------*/ 214/*--------------------------Exported Function prototype---------------------*/
215extern void init_hal_dm(struct net_device *dev); 215void init_hal_dm(struct net_device *dev);
216extern void deinit_hal_dm(struct net_device *dev); 216void deinit_hal_dm(struct net_device *dev);
217extern void hal_dm_watchdog(struct net_device *dev); 217void hal_dm_watchdog(struct net_device *dev);
218extern void init_rate_adaptive(struct net_device *dev); 218void init_rate_adaptive(struct net_device *dev);
219extern void dm_txpower_trackingcallback(struct work_struct *work); 219void dm_txpower_trackingcallback(struct work_struct *work);
220extern void dm_restore_dynamic_mechanism_state(struct net_device *dev); 220void dm_restore_dynamic_mechanism_state(struct net_device *dev);
221extern void dm_backup_dynamic_mechanism_state(struct net_device *dev); 221void dm_backup_dynamic_mechanism_state(struct net_device *dev);
222extern void dm_change_dynamic_initgain_thresh(struct net_device *dev, 222void dm_change_dynamic_initgain_thresh(struct net_device *dev,
223 u32 dm_type, u32 dm_value); 223 u32 dm_type, u32 dm_value);
224extern void dm_force_tx_fw_info(struct net_device *dev, 224void dm_force_tx_fw_info(struct net_device *dev,
225 u32 force_type, u32 force_value); 225 u32 force_type, u32 force_value);
226extern void dm_init_edca_turbo(struct net_device *dev); 226void dm_init_edca_turbo(struct net_device *dev);
227extern void dm_rf_operation_test_callback(unsigned long data); 227void dm_rf_operation_test_callback(unsigned long data);
228extern void dm_rf_pathcheck_workitemcallback(struct work_struct *work); 228void dm_rf_pathcheck_workitemcallback(struct work_struct *work);
229extern void dm_fsync_timer_callback(unsigned long data); 229void dm_fsync_timer_callback(unsigned long data);
230extern void dm_cck_txpower_adjust(struct net_device *dev, bool binch14); 230void dm_cck_txpower_adjust(struct net_device *dev, bool binch14);
231extern void dm_shadow_init(struct net_device *dev); 231void dm_shadow_init(struct net_device *dev);
232extern void dm_initialize_txpower_tracking(struct net_device *dev); 232void dm_initialize_txpower_tracking(struct net_device *dev);
233/*--------------------------Exported Function prototype---------------------*/ 233/*--------------------------Exported Function prototype---------------------*/
234 234
235 235
diff --git a/drivers/staging/rtl8192u/r8192U_wx.h b/drivers/staging/rtl8192u/r8192U_wx.h
index d6a2d9756531..fb5f808433d1 100644
--- a/drivers/staging/rtl8192u/r8192U_wx.h
+++ b/drivers/staging/rtl8192u/r8192U_wx.h
@@ -19,6 +19,6 @@
19 19
20extern struct iw_handler_def r8192_wx_handlers_def; 20extern struct iw_handler_def r8192_wx_handlers_def;
21/* Enable the rtl819x_core.c to share this function, david 2008.9.22 */ 21/* Enable the rtl819x_core.c to share this function, david 2008.9.22 */
22extern struct iw_statistics *r8192_get_wireless_stats(struct net_device *dev); 22struct iw_statistics *r8192_get_wireless_stats(struct net_device *dev);
23 23
24#endif 24#endif
diff --git a/drivers/staging/rtl8192u/r819xU_cmdpkt.h b/drivers/staging/rtl8192u/r819xU_cmdpkt.h
index 52cd437ef7bb..cc8029a15df4 100644
--- a/drivers/staging/rtl8192u/r819xU_cmdpkt.h
+++ b/drivers/staging/rtl8192u/r819xU_cmdpkt.h
@@ -182,10 +182,10 @@ typedef enum _rt_status {
182 RT_STATUS_RESOURCE 182 RT_STATUS_RESOURCE
183} rt_status, *prt_status; 183} rt_status, *prt_status;
184 184
185extern u32 cmpk_message_handle_rx(struct net_device *dev, 185u32 cmpk_message_handle_rx(struct net_device *dev,
186 struct ieee80211_rx_stats *pstats); 186 struct ieee80211_rx_stats *pstats);
187extern rt_status SendTxCommandPacket(struct net_device *dev, 187rt_status SendTxCommandPacket(struct net_device *dev,
188 void *pData, u32 DataLen); 188 void *pData, u32 DataLen);
189 189
190 190
191#endif 191#endif
diff --git a/drivers/staging/rtl8192u/r819xU_firmware.c b/drivers/staging/rtl8192u/r819xU_firmware.c
index d27b1e24ca4a..08302dfb0d90 100644
--- a/drivers/staging/rtl8192u/r819xU_firmware.c
+++ b/drivers/staging/rtl8192u/r819xU_firmware.c
@@ -66,7 +66,7 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
66 skb = dev_alloc_skb(USB_HWDESC_HEADER_LEN + frag_length + 4); 66 skb = dev_alloc_skb(USB_HWDESC_HEADER_LEN + frag_length + 4);
67 if (!skb) 67 if (!skb)
68 return false; 68 return false;
69 memcpy((unsigned char *)(skb->cb),&dev,sizeof(dev)); 69 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
70 tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 70 tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
71 tcb_desc->queue_index = TXCMD_QUEUE; 71 tcb_desc->queue_index = TXCMD_QUEUE;
72 tcb_desc->bCmdOrInit = DESC_PACKET_TYPE_INIT; 72 tcb_desc->bCmdOrInit = DESC_PACKET_TYPE_INIT;
@@ -91,7 +91,7 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
91 if (!priv->ieee80211->check_nic_enough_desc(dev, index) || 91 if (!priv->ieee80211->check_nic_enough_desc(dev, index) ||
92 (!skb_queue_empty(&priv->ieee80211->skb_waitQ[index])) || 92 (!skb_queue_empty(&priv->ieee80211->skb_waitQ[index])) ||
93 (priv->ieee80211->queue_stop)) { 93 (priv->ieee80211->queue_stop)) {
94 RT_TRACE(COMP_FIRMWARE,"=====================================================> tx full!\n"); 94 RT_TRACE(COMP_FIRMWARE, "=====================================================> tx full!\n");
95 skb_queue_tail(&priv->ieee80211->skb_waitQ[tcb_desc->queue_index], skb); 95 skb_queue_tail(&priv->ieee80211->skb_waitQ[tcb_desc->queue_index], skb);
96 } else { 96 } else {
97 priv->ieee80211->softmac_hard_start_xmit(skb, dev); 97 priv->ieee80211->softmac_hard_start_xmit(skb, dev);
@@ -144,7 +144,8 @@ static bool CPUcheck_maincodeok_turnonCPU(struct net_device *dev)
144 144
145 /* Turn On CPU */ 145 /* Turn On CPU */
146 read_nic_dword(dev, CPU_GEN, &CPU_status); 146 read_nic_dword(dev, CPU_GEN, &CPU_status);
147 write_nic_byte(dev, CPU_GEN, (u8)((CPU_status|CPU_GEN_PWR_STB_CPU)&0xff)); 147 write_nic_byte(dev, CPU_GEN,
148 (u8)((CPU_status | CPU_GEN_PWR_STB_CPU) & 0xff));
148 mdelay(1000); 149 mdelay(1000);
149 150
150 /* Check whether CPU boot OK */ 151 /* Check whether CPU boot OK */
@@ -242,7 +243,7 @@ bool init_firmware(struct net_device *dev)
242 * or read image file from array. Default load from IMG file 243 * or read image file from array. Default load from IMG file
243 */ 244 */
244 if (rst_opt == OPT_SYSTEM_RESET) { 245 if (rst_opt == OPT_SYSTEM_RESET) {
245 rc = request_firmware(&fw_entry, fw_name[init_step],&priv->udev->dev); 246 rc = request_firmware(&fw_entry, fw_name[init_step], &priv->udev->dev);
246 if (rc < 0) { 247 if (rc < 0) {
247 RT_TRACE(COMP_ERR, "request firmware fail!\n"); 248 RT_TRACE(COMP_ERR, "request firmware fail!\n");
248 goto download_firmware_fail; 249 goto download_firmware_fail;
@@ -254,12 +255,12 @@ bool init_firmware(struct net_device *dev)
254 } 255 }
255 256
256 if (init_step != FW_INIT_STEP1_MAIN) { 257 if (init_step != FW_INIT_STEP1_MAIN) {
257 memcpy(pfirmware->firmware_buf,fw_entry->data,fw_entry->size); 258 memcpy(pfirmware->firmware_buf, fw_entry->data, fw_entry->size);
258 mapped_file = pfirmware->firmware_buf; 259 mapped_file = pfirmware->firmware_buf;
259 file_length = fw_entry->size; 260 file_length = fw_entry->size;
260 } else { 261 } else {
261 memset(pfirmware->firmware_buf, 0, 128); 262 memset(pfirmware->firmware_buf, 0, 128);
262 memcpy(&pfirmware->firmware_buf[128],fw_entry->data,fw_entry->size); 263 memcpy(&pfirmware->firmware_buf[128], fw_entry->data, fw_entry->size);
263 mapped_file = pfirmware->firmware_buf; 264 mapped_file = pfirmware->firmware_buf;
264 file_length = fw_entry->size + 128; 265 file_length = fw_entry->size + 128;
265 } 266 }
@@ -319,7 +320,7 @@ bool init_firmware(struct net_device *dev)
319 320
320 rt_status = CPUcheck_firmware_ready(dev); 321 rt_status = CPUcheck_firmware_ready(dev);
321 if (!rt_status) { 322 if (!rt_status) {
322 RT_TRACE(COMP_ERR, "CPUcheck_firmware_ready fail(%d)!\n",rt_status); 323 RT_TRACE(COMP_ERR, "CPUcheck_firmware_ready fail(%d)!\n", rt_status);
323 goto download_firmware_fail; 324 goto download_firmware_fail;
324 } 325 }
325 326
diff --git a/drivers/staging/rtl8192u/r819xU_phy.h b/drivers/staging/rtl8192u/r819xU_phy.h
index 66cbe3f9cafd..e672126330f3 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.h
+++ b/drivers/staging/rtl8192u/r819xU_phy.h
@@ -57,36 +57,35 @@ typedef enum _RF90_RADIO_PATH {
57#define bMaskLWord 0x0000ffff 57#define bMaskLWord 0x0000ffff
58#define bMaskDWord 0xffffffff 58#define bMaskDWord 0xffffffff
59 59
60extern u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device *dev, u32 eRFPath); 60u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device *dev, u32 eRFPath);
61extern void rtl8192_setBBreg(struct net_device *dev, u32 reg_addr, 61void rtl8192_setBBreg(struct net_device *dev, u32 reg_addr,
62 u32 bitmask, u32 data); 62 u32 bitmask, u32 data);
63extern u32 rtl8192_QueryBBReg(struct net_device *dev, u32 reg_addr, 63u32 rtl8192_QueryBBReg(struct net_device *dev, u32 reg_addr, u32 bitmask);
64 u32 bitmask); 64void rtl8192_phy_SetRFReg(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
65extern void rtl8192_phy_SetRFReg(struct net_device *dev, 65 u32 reg_addr, u32 bitmask, u32 data);
66 RF90_RADIO_PATH_E eRFPath, u32 reg_addr, u32 bitmask, u32 data); 66u32 rtl8192_phy_QueryRFReg(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
67extern u32 rtl8192_phy_QueryRFReg(struct net_device *dev, 67 u32 reg_addr, u32 bitmask);
68 RF90_RADIO_PATH_E eRFPath, u32 reg_addr, u32 bitmask); 68void rtl8192_phy_configmac(struct net_device *dev);
69extern void rtl8192_phy_configmac(struct net_device *dev); 69void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType);
70extern void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType); 70u8 rtl8192_phy_checkBBAndRF(struct net_device *dev,
71extern u8 rtl8192_phy_checkBBAndRF(struct net_device *dev, 71 HW90_BLOCK_E CheckBlock, RF90_RADIO_PATH_E eRFPath);
72 HW90_BLOCK_E CheckBlock, RF90_RADIO_PATH_E eRFPath); 72void rtl8192_BBConfig(struct net_device *dev);
73extern void rtl8192_BBConfig(struct net_device *dev); 73void rtl8192_phy_getTxPower(struct net_device *dev);
74extern void rtl8192_phy_getTxPower(struct net_device *dev); 74void rtl8192_phy_setTxPower(struct net_device *dev, u8 channel);
75extern void rtl8192_phy_setTxPower(struct net_device *dev, u8 channel); 75void rtl8192_phy_RFConfig(struct net_device *dev);
76extern void rtl8192_phy_RFConfig(struct net_device *dev); 76void rtl8192_phy_updateInitGain(struct net_device *dev);
77extern void rtl8192_phy_updateInitGain(struct net_device *dev); 77u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device *dev,
78extern u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device *dev, 78 RF90_RADIO_PATH_E eRFPath);
79 RF90_RADIO_PATH_E eRFPath);
80 79
81extern u8 rtl8192_phy_SwChnl(struct net_device *dev, u8 channel); 80u8 rtl8192_phy_SwChnl(struct net_device *dev, u8 channel);
82extern void rtl8192_SetBWMode(struct net_device *dev, 81void rtl8192_SetBWMode(struct net_device *dev, HT_CHANNEL_WIDTH bandwidth,
83 HT_CHANNEL_WIDTH bandwidth, HT_EXTCHNL_OFFSET offset); 82 HT_EXTCHNL_OFFSET offset);
84extern void rtl8192_SwChnl_WorkItem(struct net_device *dev); 83void rtl8192_SwChnl_WorkItem(struct net_device *dev);
85void rtl8192_SetBWModeWorkItem(struct net_device *dev); 84void rtl8192_SetBWModeWorkItem(struct net_device *dev);
86extern bool rtl8192_SetRFPowerState(struct net_device *dev, 85bool rtl8192_SetRFPowerState(struct net_device *dev,
87 RT_RF_POWER_STATE eRFPowerState); 86 RT_RF_POWER_STATE eRFPowerState);
88extern void InitialGain819xUsb(struct net_device *dev, u8 Operation); 87void InitialGain819xUsb(struct net_device *dev, u8 Operation);
89 88
90extern void InitialGainOperateWorkItemCallBack(struct work_struct *work); 89void InitialGainOperateWorkItemCallBack(struct work_struct *work);
91 90
92#endif 91#endif
diff --git a/drivers/staging/rtl8712/ieee80211.c b/drivers/staging/rtl8712/ieee80211.c
index 57868085ce58..c5527c1ccaa6 100644
--- a/drivers/staging/rtl8712/ieee80211.c
+++ b/drivers/staging/rtl8712/ieee80211.c
@@ -134,22 +134,20 @@ u8 *r8712_get_ie(u8 *pbuf, sint index, sint *len, sint limit)
134 return NULL; 134 return NULL;
135} 135}
136 136
137static void set_supported_rate(u8 *SupportedRates, uint mode) 137static void set_supported_rate(u8 *rates, uint mode)
138{ 138{
139 memset(SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX); 139 memset(rates, 0, NDIS_802_11_LENGTH_RATES_EX);
140 switch (mode) { 140 switch (mode) {
141 case WIRELESS_11B: 141 case WIRELESS_11B:
142 memcpy(SupportedRates, WIFI_CCKRATES, 142 memcpy(rates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
143 IEEE80211_CCK_RATE_LEN);
144 break; 143 break;
145 case WIRELESS_11G: 144 case WIRELESS_11G:
146 case WIRELESS_11A: 145 case WIRELESS_11A:
147 memcpy(SupportedRates, WIFI_OFDMRATES, 146 memcpy(rates, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
148 IEEE80211_NUM_OFDM_RATESLEN);
149 break; 147 break;
150 case WIRELESS_11BG: 148 case WIRELESS_11BG:
151 memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN); 149 memcpy(rates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
152 memcpy(SupportedRates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES, 150 memcpy(rates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES,
153 IEEE80211_NUM_OFDM_RATESLEN); 151 IEEE80211_NUM_OFDM_RATESLEN);
154 break; 152 break;
155 } 153 }
@@ -195,17 +193,16 @@ int r8712_generate_ie(struct registry_priv *pregistrypriv)
195 ie = r8712_set_ie(ie, _SSID_IE_, pdev_network->Ssid.SsidLength, 193 ie = r8712_set_ie(ie, _SSID_IE_, pdev_network->Ssid.SsidLength,
196 pdev_network->Ssid.Ssid, &sz); 194 pdev_network->Ssid.Ssid, &sz);
197 /*supported rates*/ 195 /*supported rates*/
198 set_supported_rate(pdev_network->SupportedRates, 196 set_supported_rate(pdev_network->rates, pregistrypriv->wireless_mode);
199 pregistrypriv->wireless_mode); 197 rateLen = r8712_get_rateset_len(pdev_network->rates);
200 rateLen = r8712_get_rateset_len(pdev_network->SupportedRates);
201 if (rateLen > 8) { 198 if (rateLen > 8) {
202 ie = r8712_set_ie(ie, _SUPPORTEDRATES_IE_, 8, 199 ie = r8712_set_ie(ie, _SUPPORTEDRATES_IE_, 8,
203 pdev_network->SupportedRates, &sz); 200 pdev_network->rates, &sz);
204 ie = r8712_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), 201 ie = r8712_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8),
205 (pdev_network->SupportedRates + 8), &sz); 202 (pdev_network->rates + 8), &sz);
206 } else 203 } else
207 ie = r8712_set_ie(ie, _SUPPORTEDRATES_IE_, 204 ie = r8712_set_ie(ie, _SUPPORTEDRATES_IE_,
208 rateLen, pdev_network->SupportedRates, &sz); 205 rateLen, pdev_network->rates, &sz);
209 /*DS parameter set*/ 206 /*DS parameter set*/
210 ie = r8712_set_ie(ie, _DSSET_IE_, 1, 207 ie = r8712_set_ie(ie, _DSSET_IE_, 1,
211 (u8 *)&(pdev_network->Configuration.DSConfig), &sz); 208 (u8 *)&(pdev_network->Configuration.DSConfig), &sz);
diff --git a/drivers/staging/rtl8712/rtl8712_recv.c b/drivers/staging/rtl8712/rtl8712_recv.c
index fcb8c61b2884..4fa2540a6c34 100644
--- a/drivers/staging/rtl8712/rtl8712_recv.c
+++ b/drivers/staging/rtl8712/rtl8712_recv.c
@@ -58,8 +58,8 @@ int r8712_init_recv_priv(struct recv_priv *precvpriv, struct _adapter *padapter)
58 58
59 /*init recv_buf*/ 59 /*init recv_buf*/
60 _init_queue(&precvpriv->free_recv_buf_queue); 60 _init_queue(&precvpriv->free_recv_buf_queue);
61 precvpriv->pallocated_recv_buf = kzalloc(NR_RECVBUFF * sizeof(struct recv_buf) + 4, 61 precvpriv->pallocated_recv_buf =
62 GFP_ATOMIC); 62 kzalloc(NR_RECVBUFF * sizeof(struct recv_buf) + 4, GFP_ATOMIC);
63 if (precvpriv->pallocated_recv_buf == NULL) 63 if (precvpriv->pallocated_recv_buf == NULL)
64 return _FAIL; 64 return _FAIL;
65 precvpriv->precv_buf = precvpriv->pallocated_recv_buf + 4 - 65 precvpriv->precv_buf = precvpriv->pallocated_recv_buf + 4 -
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.c b/drivers/staging/rtl8712/rtl871x_cmd.c
index e35854d28f90..ef7182961002 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.c
+++ b/drivers/staging/rtl8712/rtl871x_cmd.c
@@ -456,9 +456,7 @@ u8 r8712_createbss_cmd(struct _adapter *padapter)
456 INIT_LIST_HEAD(&pcmd->list); 456 INIT_LIST_HEAD(&pcmd->list);
457 pcmd->cmdcode = _CreateBss_CMD_; 457 pcmd->cmdcode = _CreateBss_CMD_;
458 pcmd->parmbuf = (unsigned char *)pdev_network; 458 pcmd->parmbuf = (unsigned char *)pdev_network;
459 pcmd->cmdsz = r8712_get_ndis_wlan_bssid_ex_sz(( 459 pcmd->cmdsz = r8712_get_wlan_bssid_ex_sz(pdev_network);
460 struct ndis_wlan_bssid_ex *)
461 pdev_network);
462 pcmd->rsp = NULL; 460 pcmd->rsp = NULL;
463 pcmd->rspsz = 0; 461 pcmd->rspsz = 0;
464 /* notes: translate IELength & Length after assign to cmdsz; */ 462 /* notes: translate IELength & Length after assign to cmdsz; */
@@ -471,8 +469,7 @@ u8 r8712_createbss_cmd(struct _adapter *padapter)
471 469
472u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork) 470u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork)
473{ 471{
474 uint t_len = 0; 472 struct wlan_bssid_ex *psecnetwork;
475 struct ndis_wlan_bssid_ex *psecnetwork;
476 struct cmd_obj *pcmd; 473 struct cmd_obj *pcmd;
477 struct cmd_priv *pcmdpriv = &padapter->cmdpriv; 474 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
478 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 475 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
@@ -486,14 +483,6 @@ u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork)
486 pcmd = kmalloc(sizeof(*pcmd), GFP_ATOMIC); 483 pcmd = kmalloc(sizeof(*pcmd), GFP_ATOMIC);
487 if (pcmd == NULL) 484 if (pcmd == NULL)
488 return _FAIL; 485 return _FAIL;
489 t_len = sizeof(u32) + 6 * sizeof(unsigned char) + 2 +
490 sizeof(struct ndis_802_11_ssid) + sizeof(u32) +
491 sizeof(s32) +
492 sizeof(enum NDIS_802_11_NETWORK_TYPE) +
493 sizeof(struct NDIS_802_11_CONFIGURATION) +
494 sizeof(enum NDIS_802_11_NETWORK_INFRASTRUCTURE) +
495 sizeof(NDIS_802_11_RATES_EX) +
496 sizeof(u32) + MAX_IE_SZ;
497 486
498 /* for hidden ap to set fw_state here */ 487 /* for hidden ap to set fw_state here */
499 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_ADHOC_STATE) != 488 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_ADHOC_STATE) !=
@@ -511,12 +500,12 @@ u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork)
511 break; 500 break;
512 } 501 }
513 } 502 }
514 psecnetwork = (struct ndis_wlan_bssid_ex *)&psecuritypriv->sec_bss; 503 psecnetwork = &psecuritypriv->sec_bss;
515 if (psecnetwork == NULL) { 504 if (psecnetwork == NULL) {
516 kfree(pcmd); 505 kfree(pcmd);
517 return _FAIL; 506 return _FAIL;
518 } 507 }
519 memcpy(psecnetwork, &pnetwork->network, t_len); 508 memcpy(psecnetwork, &pnetwork->network, sizeof(*psecnetwork));
520 psecuritypriv->authenticator_ie[0] = (unsigned char) 509 psecuritypriv->authenticator_ie[0] = (unsigned char)
521 psecnetwork->IELength; 510 psecnetwork->IELength;
522 if ((psecnetwork->IELength-12) < (256 - 1)) 511 if ((psecnetwork->IELength-12) < (256 - 1))
@@ -575,7 +564,7 @@ u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork)
575 memcpy(&psecuritypriv->supplicant_ie[1], &psecnetwork->IEs[0], 564 memcpy(&psecuritypriv->supplicant_ie[1], &psecnetwork->IEs[0],
576 255); 565 255);
577 /* get cmdsz before endian conversion */ 566 /* get cmdsz before endian conversion */
578 pcmd->cmdsz = r8712_get_ndis_wlan_bssid_ex_sz(psecnetwork); 567 pcmd->cmdsz = r8712_get_wlan_bssid_ex_sz(psecnetwork);
579#ifdef __BIG_ENDIAN 568#ifdef __BIG_ENDIAN
580 /* wlan_network endian conversion */ 569 /* wlan_network endian conversion */
581 psecnetwork->Length = cpu_to_le32(psecnetwork->Length); 570 psecnetwork->Length = cpu_to_le32(psecnetwork->Length);
@@ -903,8 +892,7 @@ void r8712_createbss_cmd_callback(struct _adapter *padapter,
903 struct sta_info *psta = NULL; 892 struct sta_info *psta = NULL;
904 struct wlan_network *pwlan = NULL; 893 struct wlan_network *pwlan = NULL;
905 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 894 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
906 struct ndis_wlan_bssid_ex *pnetwork = (struct ndis_wlan_bssid_ex *) 895 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)pcmd->parmbuf;
907 pcmd->parmbuf;
908 struct wlan_network *tgt_network = &(pmlmepriv->cur_network); 896 struct wlan_network *tgt_network = &(pmlmepriv->cur_network);
909 897
910 if (pcmd->res != H2C_SUCCESS) 898 if (pcmd->res != H2C_SUCCESS)
@@ -958,11 +946,11 @@ void r8712_createbss_cmd_callback(struct _adapter *padapter,
958 } else 946 } else
959 list_add_tail(&(pwlan->list), 947 list_add_tail(&(pwlan->list),
960 &pmlmepriv->scanned_queue.queue); 948 &pmlmepriv->scanned_queue.queue);
961 pnetwork->Length = r8712_get_ndis_wlan_bssid_ex_sz(pnetwork); 949 pnetwork->Length = r8712_get_wlan_bssid_ex_sz(pnetwork);
962 memcpy(&(pwlan->network), pnetwork, pnetwork->Length); 950 memcpy(&(pwlan->network), pnetwork, pnetwork->Length);
963 pwlan->fixed = true; 951 pwlan->fixed = true;
964 memcpy(&tgt_network->network, pnetwork, 952 memcpy(&tgt_network->network, pnetwork,
965 (r8712_get_ndis_wlan_bssid_ex_sz(pnetwork))); 953 (r8712_get_wlan_bssid_ex_sz(pnetwork)));
966 if (pmlmepriv->fw_state & _FW_UNDER_LINKING) 954 if (pmlmepriv->fw_state & _FW_UNDER_LINKING)
967 pmlmepriv->fw_state ^= _FW_UNDER_LINKING; 955 pmlmepriv->fw_state ^= _FW_UNDER_LINKING;
968 /* we will set _FW_LINKED when there is one more sat to 956 /* we will set _FW_LINKED when there is one more sat to
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.h b/drivers/staging/rtl8712/rtl871x_cmd.h
index cb8225b94cf1..818cd8807a38 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.h
+++ b/drivers/staging/rtl8712/rtl871x_cmd.h
@@ -123,15 +123,6 @@ struct usb_suspend_parm {
123}; 123};
124 124
125/* 125/*
126 * Caller Mode: Infra, Ad-Hoc
127 * Notes: To join the specified bss
128 * Command Event Mode
129 */
130struct joinbss_parm {
131 struct ndis_wlan_bssid_ex network;
132};
133
134/*
135 * Caller Mode: Infra, Ad-HoC(C) 126 * Caller Mode: Infra, Ad-HoC(C)
136 * Notes: To disconnect the current associated BSS 127 * Notes: To disconnect the current associated BSS
137 * Command Mode 128 * Command Mode
@@ -141,15 +132,6 @@ struct disconnect_parm {
141}; 132};
142 133
143/* 134/*
144 * Caller Mode: AP, Ad-HoC(M)
145 * Notes: To create a BSS
146 * Command Mode
147 */
148struct createbss_parm {
149 struct ndis_wlan_bssid_ex network;
150};
151
152/*
153 * Caller Mode: AP, Ad-HoC, Infra 135 * Caller Mode: AP, Ad-HoC, Infra
154 * Notes: To set the NIC mode of RTL8711 136 * Notes: To set the NIC mode of RTL8711
155 * Command Mode 137 * Command Mode
diff --git a/drivers/staging/rtl8712/rtl871x_event.h b/drivers/staging/rtl8712/rtl871x_event.h
index e03ee90d2870..697c8d735150 100644
--- a/drivers/staging/rtl8712/rtl871x_event.h
+++ b/drivers/staging/rtl8712/rtl871x_event.h
@@ -36,7 +36,7 @@
36 * Used to report a bss has been scanned 36 * Used to report a bss has been scanned
37*/ 37*/
38struct survey_event { 38struct survey_event {
39 struct ndis_wlan_bssid_ex bss; 39 struct wlan_bssid_ex bss;
40}; 40};
41 41
42/* 42/*
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl.h b/drivers/staging/rtl8712/rtl871x_ioctl.h
index 8e6ef5d49fbf..c9218be5bb4f 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl.h
+++ b/drivers/staging/rtl8712/rtl871x_ioctl.h
@@ -76,22 +76,18 @@ uint oid_null_function(struct oid_par_priv *poid_par_priv);
76 76
77extern struct iw_handler_def r871x_handlers_def; 77extern struct iw_handler_def r871x_handlers_def;
78 78
79extern uint drv_query_info( 79uint drv_query_info(struct net_device *MiniportAdapterContext,
80 struct net_device *MiniportAdapterContext, 80 uint Oid,
81 uint Oid, 81 void *InformationBuffer,
82 void *InformationBuffer, 82 u32 InformationBufferLength,
83 u32 InformationBufferLength, 83 u32 *BytesWritten,
84 u32 *BytesWritten, 84 u32 *BytesNeeded);
85 u32 *BytesNeeded
86);
87 85
88extern uint drv_set_info( 86uint drv_set_info(struct net_device *MiniportAdapterContext,
89 struct net_device *MiniportAdapterContext, 87 uint Oid,
90 uint Oid, 88 void *InformationBuffer,
91 void *InformationBuffer, 89 u32 InformationBufferLength,
92 u32 InformationBufferLength, 90 u32 *BytesRead,
93 u32 *BytesRead, 91 u32 *BytesNeeded);
94 u32 *BytesNeeded
95);
96 92
97#endif 93#endif
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index 3388f971fb48..143be0fdc578 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -203,14 +203,12 @@ static inline char *translate_scan(struct _adapter *padapter,
203 } 203 }
204 /* Add the protocol name */ 204 /* Add the protocol name */
205 iwe.cmd = SIOCGIWNAME; 205 iwe.cmd = SIOCGIWNAME;
206 if ((r8712_is_cckratesonly_included((u8 *)&pnetwork->network. 206 if (r8712_is_cckratesonly_included(pnetwork->network.rates)) {
207 SupportedRates)) == true) {
208 if (ht_cap == true) 207 if (ht_cap == true)
209 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bn"); 208 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bn");
210 else 209 else
211 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11b"); 210 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11b");
212 } else if ((r8712_is_cckrates_included((u8 *)&pnetwork->network. 211 } else if (r8712_is_cckrates_included(pnetwork->network.rates)) {
213 SupportedRates)) == true) {
214 if (ht_cap == true) 212 if (ht_cap == true)
215 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bgn"); 213 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bgn");
216 else 214 else
@@ -270,9 +268,9 @@ static inline char *translate_scan(struct _adapter *padapter,
270 iwe.u.bitrate.disabled = 0; 268 iwe.u.bitrate.disabled = 0;
271 iwe.u.bitrate.value = 0; 269 iwe.u.bitrate.value = 0;
272 i = 0; 270 i = 0;
273 while (pnetwork->network.SupportedRates[i] != 0) { 271 while (pnetwork->network.rates[i] != 0) {
274 /* Bit rate given in 500 kb/s units */ 272 /* Bit rate given in 500 kb/s units */
275 iwe.u.bitrate.value = (pnetwork->network.SupportedRates[i++] & 273 iwe.u.bitrate.value = (pnetwork->network.rates[i++] &
276 0x7F) * 500000; 274 0x7F) * 500000;
277 current_val = iwe_stream_add_value(info, start, current_val, 275 current_val = iwe_stream_add_value(info, start, current_val,
278 stop, &iwe, IW_EV_PARAM_LEN); 276 stop, &iwe, IW_EV_PARAM_LEN);
@@ -634,8 +632,8 @@ static int r8711_wx_get_name(struct net_device *dev,
634 char *p; 632 char *p;
635 u8 ht_cap = false; 633 u8 ht_cap = false;
636 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 634 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
637 struct ndis_wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; 635 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
638 NDIS_802_11_RATES_EX *prates = NULL; 636 u8 *prates;
639 637
640 if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE) == 638 if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE) ==
641 true) { 639 true) {
@@ -644,15 +642,15 @@ static int r8711_wx_get_name(struct net_device *dev,
644 &ht_ielen, pcur_bss->IELength - 12); 642 &ht_ielen, pcur_bss->IELength - 12);
645 if (p && ht_ielen > 0) 643 if (p && ht_ielen > 0)
646 ht_cap = true; 644 ht_cap = true;
647 prates = &pcur_bss->SupportedRates; 645 prates = pcur_bss->rates;
648 if (r8712_is_cckratesonly_included((u8 *)prates) == true) { 646 if (r8712_is_cckratesonly_included(prates) == true) {
649 if (ht_cap == true) 647 if (ht_cap == true)
650 snprintf(wrqu->name, IFNAMSIZ, 648 snprintf(wrqu->name, IFNAMSIZ,
651 "IEEE 802.11bn"); 649 "IEEE 802.11bn");
652 else 650 else
653 snprintf(wrqu->name, IFNAMSIZ, 651 snprintf(wrqu->name, IFNAMSIZ,
654 "IEEE 802.11b"); 652 "IEEE 802.11b");
655 } else if ((r8712_is_cckrates_included((u8 *)prates)) == true) { 653 } else if ((r8712_is_cckrates_included(prates)) == true) {
656 if (ht_cap == true) 654 if (ht_cap == true)
657 snprintf(wrqu->name, IFNAMSIZ, 655 snprintf(wrqu->name, IFNAMSIZ,
658 "IEEE 802.11bgn"); 656 "IEEE 802.11bgn");
@@ -723,7 +721,7 @@ static int r8711_wx_get_freq(struct net_device *dev,
723{ 721{
724 struct _adapter *padapter = netdev_priv(dev); 722 struct _adapter *padapter = netdev_priv(dev);
725 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 723 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
726 struct ndis_wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; 724 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
727 725
728 if (check_fwstate(pmlmepriv, _FW_LINKED) == true) { 726 if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
729 wrqu->freq.m = ieee80211_wlan_frequencies[ 727 wrqu->freq.m = ieee80211_wlan_frequencies[
@@ -1111,7 +1109,7 @@ static int r8711_wx_get_wap(struct net_device *dev,
1111{ 1109{
1112 struct _adapter *padapter = netdev_priv(dev); 1110 struct _adapter *padapter = netdev_priv(dev);
1113 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 1111 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1114 struct ndis_wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; 1112 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
1115 1113
1116 wrqu->ap_addr.sa_family = ARPHRD_ETHER; 1114 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1117 if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE | 1115 if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE |
@@ -1327,7 +1325,7 @@ static int r8711_wx_get_essid(struct net_device *dev,
1327{ 1325{
1328 struct _adapter *padapter = netdev_priv(dev); 1326 struct _adapter *padapter = netdev_priv(dev);
1329 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 1327 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1330 struct ndis_wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; 1328 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
1331 u32 len, ret = 0; 1329 u32 len, ret = 0;
1332 1330
1333 if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE)) { 1331 if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE)) {
@@ -1419,7 +1417,7 @@ static int r8711_wx_get_rate(struct net_device *dev,
1419{ 1417{
1420 struct _adapter *padapter = netdev_priv(dev); 1418 struct _adapter *padapter = netdev_priv(dev);
1421 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 1419 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1422 struct ndis_wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; 1420 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
1423 struct ieee80211_ht_cap *pht_capie; 1421 struct ieee80211_ht_cap *pht_capie;
1424 unsigned char rf_type = padapter->registrypriv.rf_config; 1422 unsigned char rf_type = padapter->registrypriv.rf_config;
1425 int i; 1423 int i;
@@ -1444,9 +1442,9 @@ static int r8711_wx_get_rate(struct net_device *dev,
1444 (IEEE80211_HT_CAP_SGI_20 | 1442 (IEEE80211_HT_CAP_SGI_20 |
1445 IEEE80211_HT_CAP_SGI_40)) ? 1 : 0; 1443 IEEE80211_HT_CAP_SGI_40)) ? 1 : 0;
1446 } 1444 }
1447 while ((pcur_bss->SupportedRates[i] != 0) && 1445 while ((pcur_bss->rates[i] != 0) &&
1448 (pcur_bss->SupportedRates[i] != 0xFF)) { 1446 (pcur_bss->rates[i] != 0xFF)) {
1449 rate = pcur_bss->SupportedRates[i] & 0x7F; 1447 rate = pcur_bss->rates[i] & 0x7F;
1450 if (rate > max_rate) 1448 if (rate > max_rate)
1451 max_rate = rate; 1449 max_rate = rate;
1452 wrqu->bitrate.fixed = 0; /* no auto select */ 1450 wrqu->bitrate.fixed = 0; /* no auto select */
diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c b/drivers/staging/rtl8712/rtl871x_mlme.c
index c044b0e55ba9..fc5dbea08cb4 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.c
+++ b/drivers/staging/rtl8712/rtl871x_mlme.c
@@ -208,19 +208,9 @@ void r8712_generate_random_ibss(u8 *pibss)
208 pibss[5] = (u8)((curtime>>16) & 0xff); 208 pibss[5] = (u8)((curtime>>16) & 0xff);
209} 209}
210 210
211uint r8712_get_ndis_wlan_bssid_ex_sz(struct ndis_wlan_bssid_ex *bss) 211uint r8712_get_wlan_bssid_ex_sz(struct wlan_bssid_ex *bss)
212{ 212{
213 uint t_len; 213 return sizeof(*bss) + bss->IELength - MAX_IE_SZ;
214
215 t_len = sizeof(u32) + 6 * sizeof(unsigned long) + 2 +
216 sizeof(struct ndis_802_11_ssid) + sizeof(u32) +
217 sizeof(s32) +
218 sizeof(enum NDIS_802_11_NETWORK_TYPE) +
219 sizeof(struct NDIS_802_11_CONFIGURATION) +
220 sizeof(enum NDIS_802_11_NETWORK_INFRASTRUCTURE) +
221 sizeof(NDIS_802_11_RATES_EX) +
222 sizeof(u32) + bss->IELength;
223 return t_len;
224} 214}
225 215
226u8 *r8712_get_capability_from_ie(u8 *ie) 216u8 *r8712_get_capability_from_ie(u8 *ie)
@@ -286,8 +276,8 @@ int r8712_is_same_ibss(struct _adapter *adapter, struct wlan_network *pnetwork)
286 276
287} 277}
288 278
289static int is_same_network(struct ndis_wlan_bssid_ex *src, 279static int is_same_network(struct wlan_bssid_ex *src,
290 struct ndis_wlan_bssid_ex *dst) 280 struct wlan_bssid_ex *dst)
291{ 281{
292 u16 s_cap, d_cap; 282 u16 s_cap, d_cap;
293 283
@@ -332,8 +322,8 @@ struct wlan_network *r8712_get_oldest_wlan_network(
332 return oldest; 322 return oldest;
333} 323}
334 324
335static void update_network(struct ndis_wlan_bssid_ex *dst, 325static void update_network(struct wlan_bssid_ex *dst,
336 struct ndis_wlan_bssid_ex *src, 326 struct wlan_bssid_ex *src,
337 struct _adapter *padapter) 327 struct _adapter *padapter)
338{ 328{
339 u32 last_evm = 0, tmpVal; 329 u32 last_evm = 0, tmpVal;
@@ -366,11 +356,11 @@ static void update_network(struct ndis_wlan_bssid_ex *dst,
366 src->Rssi = padapter->recvpriv.signal; 356 src->Rssi = padapter->recvpriv.signal;
367 } else 357 } else
368 src->Rssi = (src->Rssi + dst->Rssi) / 2; 358 src->Rssi = (src->Rssi + dst->Rssi) / 2;
369 memcpy((u8 *)dst, (u8 *)src, r8712_get_ndis_wlan_bssid_ex_sz(src)); 359 memcpy((u8 *)dst, (u8 *)src, r8712_get_wlan_bssid_ex_sz(src));
370} 360}
371 361
372static void update_current_network(struct _adapter *adapter, 362static void update_current_network(struct _adapter *adapter,
373 struct ndis_wlan_bssid_ex *pnetwork) 363 struct wlan_bssid_ex *pnetwork)
374{ 364{
375 struct mlme_priv *pmlmepriv = &adapter->mlmepriv; 365 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
376 366
@@ -388,7 +378,7 @@ static void update_current_network(struct _adapter *adapter,
388Caller must hold pmlmepriv->lock first. 378Caller must hold pmlmepriv->lock first.
389*/ 379*/
390static void update_scanned_network(struct _adapter *adapter, 380static void update_scanned_network(struct _adapter *adapter,
391 struct ndis_wlan_bssid_ex *target) 381 struct wlan_bssid_ex *target)
392{ 382{
393 struct list_head *plist, *phead; 383 struct list_head *plist, *phead;
394 384
@@ -426,7 +416,7 @@ static void update_scanned_network(struct _adapter *adapter,
426 target->Rssi = (pnetwork->network.Rssi + 416 target->Rssi = (pnetwork->network.Rssi +
427 target->Rssi) / 2; 417 target->Rssi) / 2;
428 memcpy(&pnetwork->network, target, 418 memcpy(&pnetwork->network, target,
429 r8712_get_ndis_wlan_bssid_ex_sz(target)); 419 r8712_get_wlan_bssid_ex_sz(target));
430 pnetwork->last_scanned = jiffies; 420 pnetwork->last_scanned = jiffies;
431 } else { 421 } else {
432 /* Otherwise just pull from the free list */ 422 /* Otherwise just pull from the free list */
@@ -434,7 +424,7 @@ static void update_scanned_network(struct _adapter *adapter,
434 pnetwork = alloc_network(pmlmepriv); 424 pnetwork = alloc_network(pmlmepriv);
435 if (pnetwork == NULL) 425 if (pnetwork == NULL)
436 return; 426 return;
437 bssid_ex_sz = r8712_get_ndis_wlan_bssid_ex_sz(target); 427 bssid_ex_sz = r8712_get_wlan_bssid_ex_sz(target);
438 target->Length = bssid_ex_sz; 428 target->Length = bssid_ex_sz;
439 memcpy(&pnetwork->network, target, bssid_ex_sz); 429 memcpy(&pnetwork->network, target, bssid_ex_sz);
440 list_add_tail(&pnetwork->list, &queue->queue); 430 list_add_tail(&pnetwork->list, &queue->queue);
@@ -451,7 +441,7 @@ static void update_scanned_network(struct _adapter *adapter,
451} 441}
452 442
453static void rtl8711_add_network(struct _adapter *adapter, 443static void rtl8711_add_network(struct _adapter *adapter,
454 struct ndis_wlan_bssid_ex *pnetwork) 444 struct wlan_bssid_ex *pnetwork)
455{ 445{
456 unsigned long irqL; 446 unsigned long irqL;
457 struct mlme_priv *pmlmepriv = &(((struct _adapter *)adapter)->mlmepriv); 447 struct mlme_priv *pmlmepriv = &(((struct _adapter *)adapter)->mlmepriv);
@@ -507,10 +497,10 @@ void r8712_survey_event_callback(struct _adapter *adapter, u8 *pbuf)
507{ 497{
508 unsigned long flags; 498 unsigned long flags;
509 u32 len; 499 u32 len;
510 struct ndis_wlan_bssid_ex *pnetwork; 500 struct wlan_bssid_ex *pnetwork;
511 struct mlme_priv *pmlmepriv = &adapter->mlmepriv; 501 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
512 502
513 pnetwork = (struct ndis_wlan_bssid_ex *)pbuf; 503 pnetwork = (struct wlan_bssid_ex *)pbuf;
514#ifdef __BIG_ENDIAN 504#ifdef __BIG_ENDIAN
515 /* endian_convert */ 505 /* endian_convert */
516 pnetwork->Length = le32_to_cpu(pnetwork->Length); 506 pnetwork->Length = le32_to_cpu(pnetwork->Length);
@@ -538,7 +528,7 @@ void r8712_survey_event_callback(struct _adapter *adapter, u8 *pbuf)
538 le32_to_cpu(pnetwork->InfrastructureMode); 528 le32_to_cpu(pnetwork->InfrastructureMode);
539 pnetwork->IELength = le32_to_cpu(pnetwork->IELength); 529 pnetwork->IELength = le32_to_cpu(pnetwork->IELength);
540#endif 530#endif
541 len = r8712_get_ndis_wlan_bssid_ex_sz(pnetwork); 531 len = r8712_get_wlan_bssid_ex_sz(pnetwork);
542 if (len > sizeof(struct wlan_bssid_ex)) 532 if (len > sizeof(struct wlan_bssid_ex))
543 return; 533 return;
544 spin_lock_irqsave(&pmlmepriv->lock2, flags); 534 spin_lock_irqsave(&pmlmepriv->lock2, flags);
@@ -769,7 +759,7 @@ void r8712_joinbss_event_callback(struct _adapter *adapter, u8 *pbuf)
769 the_same_macaddr = !memcmp(pnetwork->network.MacAddress, 759 the_same_macaddr = !memcmp(pnetwork->network.MacAddress,
770 cur_network->network.MacAddress, ETH_ALEN); 760 cur_network->network.MacAddress, ETH_ALEN);
771 pnetwork->network.Length = 761 pnetwork->network.Length =
772 r8712_get_ndis_wlan_bssid_ex_sz(&pnetwork->network); 762 r8712_get_wlan_bssid_ex_sz(&pnetwork->network);
773 spin_lock_irqsave(&pmlmepriv->lock, irqL); 763 spin_lock_irqsave(&pmlmepriv->lock, irqL);
774 if (pnetwork->network.Length > sizeof(struct wlan_bssid_ex)) 764 if (pnetwork->network.Length > sizeof(struct wlan_bssid_ex))
775 goto ignore_joinbss_callback; 765 goto ignore_joinbss_callback;
@@ -1001,7 +991,7 @@ void r8712_stadel_event_callback(struct _adapter *adapter, u8 *pbuf)
1001 pdev_network = &(adapter->registrypriv.dev_network); 991 pdev_network = &(adapter->registrypriv.dev_network);
1002 pibss = adapter->registrypriv.dev_network.MacAddress; 992 pibss = adapter->registrypriv.dev_network.MacAddress;
1003 memcpy(pdev_network, &tgt_network->network, 993 memcpy(pdev_network, &tgt_network->network,
1004 r8712_get_ndis_wlan_bssid_ex_sz(&tgt_network-> 994 r8712_get_wlan_bssid_ex_sz(&tgt_network->
1005 network)); 995 network));
1006 memcpy(&pdev_network->Ssid, 996 memcpy(&pdev_network->Ssid,
1007 &pmlmepriv->assoc_ssid, 997 &pmlmepriv->assoc_ssid,
@@ -1668,8 +1658,7 @@ void r8712_update_registrypriv_dev_network(struct _adapter *adapter)
1668 */ 1658 */
1669 sz = r8712_generate_ie(pregistrypriv); 1659 sz = r8712_generate_ie(pregistrypriv);
1670 pdev_network->IELength = sz; 1660 pdev_network->IELength = sz;
1671 pdev_network->Length = r8712_get_ndis_wlan_bssid_ex_sz( 1661 pdev_network->Length = r8712_get_wlan_bssid_ex_sz(pdev_network);
1672 (struct ndis_wlan_bssid_ex *)pdev_network);
1673} 1662}
1674 1663
1675/*the function is at passive_level*/ 1664/*the function is at passive_level*/
diff --git a/drivers/staging/rtl8712/rtl871x_mlme.h b/drivers/staging/rtl8712/rtl871x_mlme.h
index 42bd0bf8a816..08d6c986c11e 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.h
+++ b/drivers/staging/rtl8712/rtl871x_mlme.h
@@ -202,7 +202,7 @@ sint r8712_set_key(struct _adapter *adapter,
202 struct security_priv *psecuritypriv, sint keyid); 202 struct security_priv *psecuritypriv, sint keyid);
203sint r8712_set_auth(struct _adapter *adapter, 203sint r8712_set_auth(struct _adapter *adapter,
204 struct security_priv *psecuritypriv); 204 struct security_priv *psecuritypriv);
205uint r8712_get_ndis_wlan_bssid_ex_sz(struct ndis_wlan_bssid_ex *bss); 205uint r8712_get_wlan_bssid_ex_sz(struct wlan_bssid_ex *bss);
206void r8712_generate_random_ibss(u8 *pibss); 206void r8712_generate_random_ibss(u8 *pibss);
207u8 *r8712_get_capability_from_ie(u8 *ie); 207u8 *r8712_get_capability_from_ie(u8 *ie);
208struct wlan_network *r8712_get_oldest_wlan_network( 208struct wlan_network *r8712_get_oldest_wlan_network(
diff --git a/drivers/staging/rtl8712/rtl871x_mp_ioctl.c b/drivers/staging/rtl8712/rtl871x_mp_ioctl.c
index 0b5461208eb9..77f01bf1ca3c 100644
--- a/drivers/staging/rtl8712/rtl871x_mp_ioctl.c
+++ b/drivers/staging/rtl8712/rtl871x_mp_ioctl.c
@@ -160,13 +160,13 @@ static int mp_start_test(struct _adapter *padapter)
160 struct mp_priv *pmppriv = &padapter->mppriv; 160 struct mp_priv *pmppriv = &padapter->mppriv;
161 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 161 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
162 struct wlan_network *tgt_network = &pmlmepriv->cur_network; 162 struct wlan_network *tgt_network = &pmlmepriv->cur_network;
163 struct ndis_wlan_bssid_ex bssid; 163 struct wlan_bssid_ex bssid;
164 struct sta_info *psta; 164 struct sta_info *psta;
165 unsigned long length; 165 unsigned long length;
166 unsigned long irqL; 166 unsigned long irqL;
167 int res = _SUCCESS; 167 int res = _SUCCESS;
168 168
169 /* 3 1. initialize a new struct ndis_wlan_bssid_ex */ 169 /* 3 1. initialize a new struct wlan_bssid_ex */
170 memcpy(bssid.MacAddress, pmppriv->network_macaddr, ETH_ALEN); 170 memcpy(bssid.MacAddress, pmppriv->network_macaddr, ETH_ALEN);
171 bssid.Ssid.SsidLength = 16; 171 bssid.Ssid.SsidLength = 16;
172 memcpy(bssid.Ssid.Ssid, (unsigned char *)"mp_pseudo_adhoc", 172 memcpy(bssid.Ssid.Ssid, (unsigned char *)"mp_pseudo_adhoc",
@@ -174,7 +174,7 @@ static int mp_start_test(struct _adapter *padapter)
174 bssid.InfrastructureMode = Ndis802_11IBSS; 174 bssid.InfrastructureMode = Ndis802_11IBSS;
175 bssid.NetworkTypeInUse = Ndis802_11DS; 175 bssid.NetworkTypeInUse = Ndis802_11DS;
176 bssid.IELength = 0; 176 bssid.IELength = 0;
177 length = r8712_get_ndis_wlan_bssid_ex_sz(&bssid); 177 length = r8712_get_wlan_bssid_ex_sz(&bssid);
178 if (length % 4) { 178 if (length % 4) {
179 /*round up to multiple of 4 bytes.*/ 179 /*round up to multiple of 4 bytes.*/
180 bssid.Length = ((length >> 2) + 1) << 2; 180 bssid.Length = ((length >> 2) + 1) << 2;
diff --git a/drivers/staging/rtl8712/rtl871x_security.c b/drivers/staging/rtl8712/rtl871x_security.c
index bcd1a5128868..862792826dc5 100644
--- a/drivers/staging/rtl8712/rtl871x_security.c
+++ b/drivers/staging/rtl8712/rtl871x_security.c
@@ -124,28 +124,25 @@ static u8 crc32_reverseBit(u8 data)
124 124
125static void crc32_init(void) 125static void crc32_init(void)
126{ 126{
127 sint i, j;
128 u32 c;
129 u8 *p = (u8 *)&c, *p1;
130 u8 k;
131
127 if (bcrc32initialized == 1) 132 if (bcrc32initialized == 1)
128 return; 133 return;
129 else { 134
130 sint i, j; 135 for (i = 0; i < 256; ++i) {
131 u32 c; 136 k = crc32_reverseBit((u8)i);
132 u8 *p = (u8 *)&c, *p1; 137 for (c = ((u32)k) << 24, j = 8; j > 0; --j)
133 u8 k; 138 c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1);
134 139 p1 = (u8 *)&crc32_table[i];
135 c = 0x12340000; 140 p1[0] = crc32_reverseBit(p[3]);
136 for (i = 0; i < 256; ++i) { 141 p1[1] = crc32_reverseBit(p[2]);
137 k = crc32_reverseBit((u8)i); 142 p1[2] = crc32_reverseBit(p[1]);
138 for (c = ((u32)k) << 24, j = 8; j > 0; --j) 143 p1[3] = crc32_reverseBit(p[0]);
139 c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY :
140 (c << 1);
141 p1 = (u8 *)&crc32_table[i];
142 p1[0] = crc32_reverseBit(p[3]);
143 p1[1] = crc32_reverseBit(p[2]);
144 p1[2] = crc32_reverseBit(p[1]);
145 p1[3] = crc32_reverseBit(p[0]);
146 }
147 bcrc32initialized = 1;
148 } 144 }
145 bcrc32initialized = 1;
149} 146}
150 147
151static u32 getcrc32(u8 *buf, u32 len) 148static u32 getcrc32(u8 *buf, u32 len)
diff --git a/drivers/staging/rtl8712/wlan_bssdef.h b/drivers/staging/rtl8712/wlan_bssdef.h
index 2ea8a3d6b705..fda5707c4acd 100644
--- a/drivers/staging/rtl8712/wlan_bssdef.h
+++ b/drivers/staging/rtl8712/wlan_bssdef.h
@@ -32,11 +32,6 @@
32#define NDIS_802_11_LENGTH_RATES 8 32#define NDIS_802_11_LENGTH_RATES 8
33#define NDIS_802_11_LENGTH_RATES_EX 16 33#define NDIS_802_11_LENGTH_RATES_EX 16
34 34
35/* Set of 8 data rates*/
36typedef unsigned char NDIS_802_11_RATES[NDIS_802_11_LENGTH_RATES];
37/* Set of 16 data rates */
38typedef unsigned char NDIS_802_11_RATES_EX[NDIS_802_11_LENGTH_RATES_EX];
39
40struct ndis_802_11_ssid { 35struct ndis_802_11_ssid {
41 u32 SsidLength; 36 u32 SsidLength;
42 u8 Ssid[32]; 37 u8 Ssid[32];
@@ -83,18 +78,7 @@ struct NDIS_802_11_FIXED_IEs {
83 u16 Capabilities; 78 u16 Capabilities;
84}; 79};
85 80
86/* 81struct wlan_bssid_ex {
87 * Length is the 4 bytes multiples of the sume of
88 * 6 * sizeof (unsigned char) + 2 + sizeof (ndis_802_11_ssid) + sizeof (u32)
89 * + sizeof (s32) + sizeof (NDIS_802_11_NETWORK_TYPE)
90 * + sizeof (struct NDIS_802_11_CONFIGURATION)
91 * + sizeof (NDIS_802_11_RATES_EX) + IELength
92
93 * Except the IELength, all other fields are fixed length. Therefore, we can
94 * define a macro to present the partial sum.
95 */
96
97struct ndis_wlan_bssid_ex {
98 u32 Length; 82 u32 Length;
99 unsigned char MacAddress[6]; 83 unsigned char MacAddress[6];
100 u8 Reserved[2]; 84 u8 Reserved[2];
@@ -104,7 +88,8 @@ struct ndis_wlan_bssid_ex {
104 enum NDIS_802_11_NETWORK_TYPE NetworkTypeInUse; 88 enum NDIS_802_11_NETWORK_TYPE NetworkTypeInUse;
105 struct NDIS_802_11_CONFIGURATION Configuration; 89 struct NDIS_802_11_CONFIGURATION Configuration;
106 enum NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode; 90 enum NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode;
107 NDIS_802_11_RATES_EX SupportedRates; 91 u8 rates[NDIS_802_11_LENGTH_RATES_EX];
92 /* number of content bytes in EIs, which varies */
108 u32 IELength; 93 u32 IELength;
109 /*(timestamp, beacon interval, and capability information) */ 94 /*(timestamp, beacon interval, and capability information) */
110 u8 IEs[MAX_IE_SZ]; 95 u8 IEs[MAX_IE_SZ];
@@ -213,7 +198,7 @@ struct wlan_network {
213 unsigned int last_scanned; /*timestamp for the network */ 198 unsigned int last_scanned; /*timestamp for the network */
214 int aid; /*will only be valid when a BSS is joined. */ 199 int aid; /*will only be valid when a BSS is joined. */
215 int join_res; 200 int join_res;
216 struct ndis_wlan_bssid_ex network; /*must be the last item */ 201 struct wlan_bssid_ex network; /*must be the last item */
217}; 202};
218 203
219enum VRTL_CARRIER_SENSE { 204enum VRTL_CARRIER_SENSE {
@@ -244,24 +229,5 @@ enum UAPSD_MAX_SP {
244#define NUM_PRE_AUTH_KEY 16 229#define NUM_PRE_AUTH_KEY 16
245#define NUM_PMKID_CACHE NUM_PRE_AUTH_KEY 230#define NUM_PMKID_CACHE NUM_PRE_AUTH_KEY
246 231
247/*
248 * WPA2
249 */
250struct wlan_bssid_ex {
251 u32 Length;
252 unsigned char MacAddress[6];
253 u8 Reserved[2];
254 struct ndis_802_11_ssid Ssid;
255 u32 Privacy;
256 s32 Rssi;
257 enum NDIS_802_11_NETWORK_TYPE NetworkTypeInUse;
258 struct NDIS_802_11_CONFIGURATION Configuration;
259 enum NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode;
260 NDIS_802_11_RATES_EX SupportedRates;
261 u32 IELength;
262 u8 IEs[MAX_IE_SZ]; /* (timestamp, beacon interval, and capability
263 * information) */
264};
265
266#endif /* #ifndef WLAN_BSSDEF_H_ */ 232#endif /* #ifndef WLAN_BSSDEF_H_ */
267 233
diff --git a/drivers/staging/rtl8723au/core/rtw_recv.c b/drivers/staging/rtl8723au/core/rtw_recv.c
index 274a4b65c022..ad0549c66529 100644
--- a/drivers/staging/rtl8723au/core/rtw_recv.c
+++ b/drivers/staging/rtl8723au/core/rtw_recv.c
@@ -1554,8 +1554,7 @@ static int wlanhdr_to_ethhdr (struct recv_frame *precvframe)
1554 ether_addr_copy(ptr + ETH_ALEN, pattrib->src); 1554 ether_addr_copy(ptr + ETH_ALEN, pattrib->src);
1555 1555
1556 if (!bsnaphdr) { 1556 if (!bsnaphdr) {
1557 len = htons(len); 1557 put_unaligned_be16(len, ptr + 12);
1558 memcpy(ptr + 12, &len, 2);
1559 } 1558 }
1560 1559
1561 1560
diff --git a/drivers/staging/rtl8723au/core/rtw_security.c b/drivers/staging/rtl8723au/core/rtw_security.c
index af53c92fc3a2..3d40bab1d9c8 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -148,7 +148,7 @@ void rtw_wep_encrypt23a(struct rtw_adapter *padapter,
148 struct xmit_frame *pxmitframe) 148 struct xmit_frame *pxmitframe)
149{ 149{
150 /* exclude ICV */ 150 /* exclude ICV */
151 unsigned char crc[4]; 151 __le32 crc;
152 struct arc4context mycontext; 152 struct arc4context mycontext;
153 int curfragnum, length, index; 153 int curfragnum, length, index;
154 u32 keylength; 154 u32 keylength;
@@ -186,18 +186,20 @@ void rtw_wep_encrypt23a(struct rtw_adapter *padapter,
186 length = pattrib->last_txcmdsz - pattrib->hdrlen - 186 length = pattrib->last_txcmdsz - pattrib->hdrlen -
187 pattrib->iv_len - pattrib->icv_len; 187 pattrib->iv_len - pattrib->icv_len;
188 188
189 *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length)); 189 crc = cpu_to_le32(getcrc32(payload, length));
190 190
191 arcfour_init(&mycontext, wepkey, 3 + keylength); 191 arcfour_init(&mycontext, wepkey, 3 + keylength);
192 arcfour_encrypt(&mycontext, payload, payload, length); 192 arcfour_encrypt(&mycontext, payload, payload, length);
193 arcfour_encrypt(&mycontext, payload + length, crc, 4); 193 arcfour_encrypt(&mycontext, payload + length,
194 (char *)&crc, 4);
194 } else { 195 } else {
195 length = pxmitpriv->frag_len - pattrib->hdrlen - 196 length = pxmitpriv->frag_len - pattrib->hdrlen -
196 pattrib->iv_len - pattrib->icv_len; 197 pattrib->iv_len - pattrib->icv_len;
197 *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length)); 198 crc = cpu_to_le32(getcrc32(payload, length));
198 arcfour_init(&mycontext, wepkey, 3 + keylength); 199 arcfour_init(&mycontext, wepkey, 3 + keylength);
199 arcfour_encrypt(&mycontext, payload, payload, length); 200 arcfour_encrypt(&mycontext, payload, payload, length);
200 arcfour_encrypt(&mycontext, payload + length, crc, 4); 201 arcfour_encrypt(&mycontext, payload + length,
202 (char *)&crc, 4);
201 203
202 pframe += pxmitpriv->frag_len; 204 pframe += pxmitpriv->frag_len;
203 pframe = PTR_ALIGN(pframe, 4); 205 pframe = PTR_ALIGN(pframe, 4);
@@ -602,7 +604,7 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
602 u32 pnh; 604 u32 pnh;
603 u8 rc4key[16]; 605 u8 rc4key[16];
604 u8 ttkey[16]; 606 u8 ttkey[16];
605 u8 crc[4]; 607 __le32 crc;
606 u8 hw_hdr_offset = 0; 608 u8 hw_hdr_offset = 0;
607 struct arc4context mycontext; 609 struct arc4context mycontext;
608 int curfragnum, length; 610 int curfragnum, length;
@@ -679,11 +681,12 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
679 "pattrib->iv_len =%x, pattrib->icv_len =%x\n", 681 "pattrib->iv_len =%x, pattrib->icv_len =%x\n",
680 pattrib->iv_len, 682 pattrib->iv_len,
681 pattrib->icv_len); 683 pattrib->icv_len);
682 *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length)); 684 crc = cpu_to_le32(getcrc32(payload, length));
683 685
684 arcfour_init(&mycontext, rc4key, 16); 686 arcfour_init(&mycontext, rc4key, 16);
685 arcfour_encrypt(&mycontext, payload, payload, length); 687 arcfour_encrypt(&mycontext, payload, payload, length);
686 arcfour_encrypt(&mycontext, payload + length, crc, 4); 688 arcfour_encrypt(&mycontext, payload + length,
689 (char *)&crc, 4);
687 690
688 } else { 691 } else {
689 length = (pxmitpriv->frag_len - 692 length = (pxmitpriv->frag_len -
@@ -691,10 +694,11 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
691 pattrib->iv_len - 694 pattrib->iv_len -
692 pattrib->icv_len); 695 pattrib->icv_len);
693 696
694 *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length)); 697 crc = cpu_to_le32(getcrc32(payload, length));
695 arcfour_init(&mycontext, rc4key, 16); 698 arcfour_init(&mycontext, rc4key, 16);
696 arcfour_encrypt(&mycontext, payload, payload, length); 699 arcfour_encrypt(&mycontext, payload, payload, length);
697 arcfour_encrypt(&mycontext, payload + length, crc, 4); 700 arcfour_encrypt(&mycontext, payload + length,
701 (char *)&crc, 4);
698 702
699 pframe += pxmitpriv->frag_len; 703 pframe += pxmitpriv->frag_len;
700 pframe = PTR_ALIGN(pframe, 4); 704 pframe = PTR_ALIGN(pframe, 4);
diff --git a/drivers/staging/rtl8723au/hal/odm.c b/drivers/staging/rtl8723au/hal/odm.c
index f354f5e11a30..6b9dbeffafcb 100644
--- a/drivers/staging/rtl8723au/hal/odm.c
+++ b/drivers/staging/rtl8723au/hal/odm.c
@@ -985,7 +985,7 @@ void ODM_RF_Saving23a(struct dm_odm_t *pDM_Odm, u8 bForceInNormal)
985 val32 = rtl8723au_read32(adapter, 0x874); 985 val32 = rtl8723au_read32(adapter, 0x874);
986 val32 |= pDM_PSTable->Reg874; 986 val32 |= pDM_PSTable->Reg874;
987 rtl8723au_write32(adapter, 0x874, val32); 987 rtl8723au_write32(adapter, 0x874, val32);
988 988
989 val32 = rtl8723au_read32(adapter, 0xc70); 989 val32 = rtl8723au_read32(adapter, 0xc70);
990 val32 |= pDM_PSTable->RegC70; 990 val32 |= pDM_PSTable->RegC70;
991 rtl8723au_write32(adapter, 0xc70, val32); 991 rtl8723au_write32(adapter, 0xc70, val32);
diff --git a/drivers/staging/rtl8723au/hal/odm_RegConfig8723A.c b/drivers/staging/rtl8723au/hal/odm_RegConfig8723A.c
index 342dec3e939f..a63c6cb88bc9 100644
--- a/drivers/staging/rtl8723au/hal/odm_RegConfig8723A.c
+++ b/drivers/staging/rtl8723au/hal/odm_RegConfig8723A.c
@@ -21,7 +21,7 @@ odm_ConfigRFReg_8723A(
21 struct dm_odm_t *pDM_Odm, 21 struct dm_odm_t *pDM_Odm,
22 u32 Addr, 22 u32 Addr,
23 u32 Data, 23 u32 Data,
24 enum RF_RADIO_PATH RF_PATH, 24 enum RF_RADIO_PATH RF_PATH,
25 u32 RegAddr 25 u32 RegAddr
26 ) 26 )
27{ 27{
diff --git a/drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c b/drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c
index cb5076abda8b..cf2388f4f6e7 100644
--- a/drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c
+++ b/drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c
@@ -1838,7 +1838,7 @@ Hal_EfuseParseThermalMeter_8723A(struct rtw_adapter *padapter,
1838 1838
1839static void rtl8723a_cal_txdesc_chksum(struct tx_desc *ptxdesc) 1839static void rtl8723a_cal_txdesc_chksum(struct tx_desc *ptxdesc)
1840{ 1840{
1841 u16 *usPtr = (u16 *) ptxdesc; 1841 __le16 *usPtr = (__le16 *)ptxdesc;
1842 u32 count = 16; /* (32 bytes / 2 bytes per XOR) => 16 times */ 1842 u32 count = 16; /* (32 bytes / 2 bytes per XOR) => 16 times */
1843 u32 index; 1843 u32 index;
1844 u16 checksum = 0; 1844 u16 checksum = 0;
@@ -1847,7 +1847,7 @@ static void rtl8723a_cal_txdesc_chksum(struct tx_desc *ptxdesc)
1847 ptxdesc->txdw7 &= cpu_to_le32(0xffff0000); 1847 ptxdesc->txdw7 &= cpu_to_le32(0xffff0000);
1848 1848
1849 for (index = 0; index < count; index++) 1849 for (index = 0; index < count; index++)
1850 checksum ^= le16_to_cpu(*(usPtr + index)); 1850 checksum ^= le16_to_cpu(usPtr[index]);
1851 1851
1852 ptxdesc->txdw7 |= cpu_to_le32(checksum & 0x0000ffff); 1852 ptxdesc->txdw7 |= cpu_to_le32(checksum & 0x0000ffff);
1853} 1853}
diff --git a/drivers/staging/rts5208/ms.c b/drivers/staging/rts5208/ms.c
index ee818b0dc401..cdaa1aba50ed 100644
--- a/drivers/staging/rts5208/ms.c
+++ b/drivers/staging/rts5208/ms.c
@@ -1121,11 +1121,10 @@ static int ms_read_attribute_info(struct rtsx_chip *chip)
1121 1121
1122#ifdef SUPPORT_MSXC 1122#ifdef SUPPORT_MSXC
1123 if ((buf[cur_addr_off + 8] == 0x10) || 1123 if ((buf[cur_addr_off + 8] == 0x10) ||
1124 (buf[cur_addr_off + 8] == 0x13)) 1124 (buf[cur_addr_off + 8] == 0x13)) {
1125#else 1125#else
1126 if (buf[cur_addr_off + 8] == 0x10) 1126 if (buf[cur_addr_off + 8] == 0x10) {
1127#endif 1127#endif
1128 {
1129 sys_info_addr = ((u32)buf[cur_addr_off + 0] << 24) | 1128 sys_info_addr = ((u32)buf[cur_addr_off + 0] << 24) |
1130 ((u32)buf[cur_addr_off + 1] << 16) | 1129 ((u32)buf[cur_addr_off + 1] << 16) |
1131 ((u32)buf[cur_addr_off + 2] << 8) | 1130 ((u32)buf[cur_addr_off + 2] << 8) |
diff --git a/drivers/staging/rts5208/sd.c b/drivers/staging/rts5208/sd.c
index a8d657bb5c1b..d6c498209b2c 100644
--- a/drivers/staging/rts5208/sd.c
+++ b/drivers/staging/rts5208/sd.c
@@ -246,11 +246,10 @@ RTY_SEND_CMD:
246 } 246 }
247 } 247 }
248#ifdef SUPPORT_SD_LOCK 248#ifdef SUPPORT_SD_LOCK
249 if (ptr[1] & 0x7D) 249 if (ptr[1] & 0x7D) {
250#else 250#else
251 if (ptr[1] & 0x7F) 251 if (ptr[1] & 0x7F) {
252#endif 252#endif
253 {
254 dev_dbg(rtsx_dev(chip), "ptr[1]: 0x%02x\n", 253 dev_dbg(rtsx_dev(chip), "ptr[1]: 0x%02x\n",
255 ptr[1]); 254 ptr[1]);
256 rtsx_trace(chip); 255 rtsx_trace(chip);
@@ -3520,12 +3519,11 @@ int reset_sd_card(struct rtsx_chip *chip)
3520 if (chip->sd_io) { 3519 if (chip->sd_io) {
3521 rtsx_trace(chip); 3520 rtsx_trace(chip);
3522 return STATUS_FAIL; 3521 return STATUS_FAIL;
3523 } else { 3522 }
3524 retval = reset_mmc(chip); 3523 retval = reset_mmc(chip);
3525 if (retval != STATUS_SUCCESS) { 3524 if (retval != STATUS_SUCCESS) {
3526 rtsx_trace(chip); 3525 rtsx_trace(chip);
3527 return STATUS_FAIL; 3526 return STATUS_FAIL;
3528 }
3529 } 3527 }
3530 } 3528 }
3531 } 3529 }
@@ -4149,11 +4147,10 @@ RTY_SEND_CMD:
4149 } 4147 }
4150 } 4148 }
4151#ifdef SUPPORT_SD_LOCK 4149#ifdef SUPPORT_SD_LOCK
4152 if (ptr[1] & 0x7D) 4150 if (ptr[1] & 0x7D) {
4153#else 4151#else
4154 if (ptr[1] & 0x7F) 4152 if (ptr[1] & 0x7F) {
4155#endif 4153#endif
4156 {
4157 rtsx_trace(chip); 4154 rtsx_trace(chip);
4158 return STATUS_FAIL; 4155 return STATUS_FAIL;
4159 } 4156 }
diff --git a/drivers/staging/slicoss/slicoss.c b/drivers/staging/slicoss/slicoss.c
index a609f3e67256..858597087ba7 100644
--- a/drivers/staging/slicoss/slicoss.c
+++ b/drivers/staging/slicoss/slicoss.c
@@ -2329,6 +2329,7 @@ static int slic_if_init(struct adapter *adapter, unsigned long *flags)
2329 2329
2330 if (!adapter->isp_initialized) { 2330 if (!adapter->isp_initialized) {
2331 unsigned long flags; 2331 unsigned long flags;
2332
2332 pshmem = (struct slic_shmem *)(unsigned long) 2333 pshmem = (struct slic_shmem *)(unsigned long)
2333 adapter->phys_shmem; 2334 adapter->phys_shmem;
2334 2335
diff --git a/drivers/staging/sm750fb/ddk750_chip.c b/drivers/staging/sm750fb/ddk750_chip.c
index f4975d2d97ad..5e6798ea9468 100644
--- a/drivers/staging/sm750fb/ddk750_chip.c
+++ b/drivers/staging/sm750fb/ddk750_chip.c
@@ -268,7 +268,7 @@ int ddk750_initHw(initchip_param_t *pInitParam)
268#endif 268#endif
269 269
270 270
271 if (pInitParam->powerMode != 0 ) 271 if (pInitParam->powerMode != 0)
272 pInitParam->powerMode = 0; 272 pInitParam->powerMode = 0;
273 setPowerMode(pInitParam->powerMode); 273 setPowerMode(pInitParam->powerMode);
274 274
@@ -464,17 +464,18 @@ unsigned int calcPllValue(unsigned int request_orig, pll_value_t *pll)
464 RN = N * request; 464 RN = N * request;
465 quo = RN / input; 465 quo = RN / input;
466 rem = RN % input;/* rem always small than 14318181 */ 466 rem = RN % input;/* rem always small than 14318181 */
467 fl_quo = (rem * 10000 /input); 467 fl_quo = (rem * 10000 / input);
468 468
469 for (d = xcnt - 1; d >= 0; d--) { 469 for (d = xcnt - 1; d >= 0; d--) {
470 X = xparm[d].value; 470 X = xparm[d].value;
471 M = quo*X; 471 M = quo*X;
472 M += fl_quo * X / 10000; 472 M += fl_quo * X / 10000;
473 /* round step */ 473 /* round step */
474 M += (fl_quo*X % 10000)>5000?1:0; 474 M += (fl_quo*X % 10000) > 5000?1:0;
475 if (M < 256 && M > 0) { 475 if (M < 256 && M > 0) {
476 unsigned int diff; 476 unsigned int diff;
477 tmpClock = pll->inputFreq *M / N / X; 477
478 tmpClock = pll->inputFreq * M / N / X;
478 diff = absDiff(tmpClock, request_orig); 479 diff = absDiff(tmpClock, request_orig);
479 if (diff < miniDiff) { 480 if (diff < miniDiff) {
480 pll->M = M; 481 pll->M = M;
@@ -599,9 +600,9 @@ unsigned int formatPllReg(pll_value_t *pPLL)
599 On returning a 32 bit number, the value can be applied to any PLL in the calling function. 600 On returning a 32 bit number, the value can be applied to any PLL in the calling function.
600 */ 601 */
601 ulPllReg = 602 ulPllReg =
602 FIELD_SET( 0, PANEL_PLL_CTRL, BYPASS, OFF) 603 FIELD_SET(0, PANEL_PLL_CTRL, BYPASS, OFF)
603 | FIELD_SET( 0, PANEL_PLL_CTRL, POWER, ON) 604 | FIELD_SET(0, PANEL_PLL_CTRL, POWER, ON)
604 | FIELD_SET( 0, PANEL_PLL_CTRL, INPUT, OSC) 605 | FIELD_SET(0, PANEL_PLL_CTRL, INPUT, OSC)
605#ifndef VALIDATION_CHIP 606#ifndef VALIDATION_CHIP
606 | FIELD_VALUE(0, PANEL_PLL_CTRL, POD, pPLL->POD) 607 | FIELD_VALUE(0, PANEL_PLL_CTRL, POD, pPLL->POD)
607#endif 608#endif
diff --git a/drivers/staging/sm750fb/ddk750_chip.h b/drivers/staging/sm750fb/ddk750_chip.h
index 4e030e820cf3..6ff043608fe9 100644
--- a/drivers/staging/sm750fb/ddk750_chip.h
+++ b/drivers/staging/sm750fb/ddk750_chip.h
@@ -8,8 +8,7 @@
8#include <linux/io.h> 8#include <linux/io.h>
9 9
10/* This is all the chips recognized by this library */ 10/* This is all the chips recognized by this library */
11typedef enum _logical_chip_type_t 11typedef enum _logical_chip_type_t {
12{
13 SM_UNKNOWN, 12 SM_UNKNOWN,
14 SM718, 13 SM718,
15 SM750, 14 SM750,
@@ -18,8 +17,7 @@ typedef enum _logical_chip_type_t
18logical_chip_type_t; 17logical_chip_type_t;
19 18
20 19
21typedef enum _clock_type_t 20typedef enum _clock_type_t {
22{
23 MXCLK_PLL, 21 MXCLK_PLL,
24 PRIMARY_PLL, 22 PRIMARY_PLL,
25 SECONDARY_PLL, 23 SECONDARY_PLL,
@@ -28,8 +26,7 @@ typedef enum _clock_type_t
28} 26}
29clock_type_t; 27clock_type_t;
30 28
31typedef struct _pll_value_t 29typedef struct _pll_value_t {
32{
33 clock_type_t clockType; 30 clock_type_t clockType;
34 unsigned long inputFreq; /* Input clock frequency to the PLL */ 31 unsigned long inputFreq; /* Input clock frequency to the PLL */
35 32
@@ -42,8 +39,7 @@ typedef struct _pll_value_t
42pll_value_t; 39pll_value_t;
43 40
44/* input struct to initChipParam() function */ 41/* input struct to initChipParam() function */
45typedef struct _initchip_param_t 42typedef struct _initchip_param_t {
46{
47 unsigned short powerMode; /* Use power mode 0 or 1 */ 43 unsigned short powerMode; /* Use power mode 0 or 1 */
48 unsigned short chipClock; /** 44 unsigned short chipClock; /**
49 * Speed of main chip clock in MHz unit 45 * Speed of main chip clock in MHz unit
diff --git a/drivers/staging/sm750fb/ddk750_display.c b/drivers/staging/sm750fb/ddk750_display.c
index a3e672056ef8..8348113482d9 100644
--- a/drivers/staging/sm750fb/ddk750_display.c
+++ b/drivers/staging/sm750fb/ddk750_display.c
@@ -15,16 +15,14 @@ static void setDisplayControl(int ctrl, int dispState)
15 cnt = 0; 15 cnt = 0;
16 16
17 /* Set the primary display control */ 17 /* Set the primary display control */
18 if (!ctrl) 18 if (!ctrl) {
19 {
20 ulDisplayCtrlReg = PEEK32(PANEL_DISPLAY_CTRL); 19 ulDisplayCtrlReg = PEEK32(PANEL_DISPLAY_CTRL);
21 /* Turn on/off the Panel display control */ 20 /* Turn on/off the Panel display control */
22 if (dispState) 21 if (dispState) {
23 {
24 /* Timing should be enabled first before enabling the plane 22 /* Timing should be enabled first before enabling the plane
25 * because changing at the same time does not guarantee that 23 * because changing at the same time does not guarantee that
26 * the plane will also enabled or disabled. 24 * the plane will also enabled or disabled.
27 */ 25 */
28 ulDisplayCtrlReg = FIELD_SET(ulDisplayCtrlReg, 26 ulDisplayCtrlReg = FIELD_SET(ulDisplayCtrlReg,
29 PANEL_DISPLAY_CTRL, TIMING, ENABLE); 27 PANEL_DISPLAY_CTRL, TIMING, ENABLE);
30 POKE32(PANEL_DISPLAY_CTRL, ulDisplayCtrlReg); 28 POKE32(PANEL_DISPLAY_CTRL, ulDisplayCtrlReg);
@@ -45,16 +43,13 @@ static void setDisplayControl(int ctrl, int dispState)
45 * until a few delay. Need to write 43 * until a few delay. Need to write
46 * and read it a couple times 44 * and read it a couple times
47 */ 45 */
48 do 46 do {
49 {
50 cnt++; 47 cnt++;
51 POKE32(PANEL_DISPLAY_CTRL, ulDisplayCtrlReg); 48 POKE32(PANEL_DISPLAY_CTRL, ulDisplayCtrlReg);
52 } while((PEEK32(PANEL_DISPLAY_CTRL) & ~ulReservedBits) != 49 } while ((PEEK32(PANEL_DISPLAY_CTRL) & ~ulReservedBits) !=
53 (ulDisplayCtrlReg & ~ulReservedBits)); 50 (ulDisplayCtrlReg & ~ulReservedBits));
54 printk("Set Panel Plane enbit:after tried %d times\n", cnt); 51 printk("Set Panel Plane enbit:after tried %d times\n", cnt);
55 } 52 } else {
56 else
57 {
58 /* When turning off, there is no rule on the programming 53 /* When turning off, there is no rule on the programming
59 * sequence since whenever the clock is off, then it does not 54 * sequence since whenever the clock is off, then it does not
60 * matter whether the plane is enabled or disabled. 55 * matter whether the plane is enabled or disabled.
@@ -71,14 +66,11 @@ static void setDisplayControl(int ctrl, int dispState)
71 POKE32(PANEL_DISPLAY_CTRL, ulDisplayCtrlReg); 66 POKE32(PANEL_DISPLAY_CTRL, ulDisplayCtrlReg);
72 } 67 }
73 68
74 } 69 } else {
75 /* Set the secondary display control */ 70 /* Set the secondary display control */
76 else
77 {
78 ulDisplayCtrlReg = PEEK32(CRT_DISPLAY_CTRL); 71 ulDisplayCtrlReg = PEEK32(CRT_DISPLAY_CTRL);
79 72
80 if (dispState) 73 if (dispState) {
81 {
82 /* Timing should be enabled first before enabling the plane because changing at the 74 /* Timing should be enabled first before enabling the plane because changing at the
83 same time does not guarantee that the plane will also enabled or disabled. 75 same time does not guarantee that the plane will also enabled or disabled.
84 */ 76 */
@@ -100,16 +92,13 @@ static void setDisplayControl(int ctrl, int dispState)
100 FIELD_SET(0, CRT_DISPLAY_CTRL, RESERVED_3_MASK, ENABLE) | 92 FIELD_SET(0, CRT_DISPLAY_CTRL, RESERVED_3_MASK, ENABLE) |
101 FIELD_SET(0, CRT_DISPLAY_CTRL, RESERVED_4_MASK, ENABLE); 93 FIELD_SET(0, CRT_DISPLAY_CTRL, RESERVED_4_MASK, ENABLE);
102 94
103 do 95 do {
104 {
105 cnt++; 96 cnt++;
106 POKE32(CRT_DISPLAY_CTRL, ulDisplayCtrlReg); 97 POKE32(CRT_DISPLAY_CTRL, ulDisplayCtrlReg);
107 } while((PEEK32(CRT_DISPLAY_CTRL) & ~ulReservedBits) != 98 } while ((PEEK32(CRT_DISPLAY_CTRL) & ~ulReservedBits) !=
108 (ulDisplayCtrlReg & ~ulReservedBits)); 99 (ulDisplayCtrlReg & ~ulReservedBits));
109 printk("Set Crt Plane enbit:after tried %d times\n", cnt); 100 printk("Set Crt Plane enbit:after tried %d times\n", cnt);
110 } 101 } else {
111 else
112 {
113 /* When turning off, there is no rule on the programming 102 /* When turning off, there is no rule on the programming
114 * sequence since whenever the clock is off, then it does not 103 * sequence since whenever the clock is off, then it does not
115 * matter whether the plane is enabled or disabled. 104 * matter whether the plane is enabled or disabled.
@@ -132,71 +121,60 @@ static void setDisplayControl(int ctrl, int dispState)
132static void waitNextVerticalSync(int ctrl, int delay) 121static void waitNextVerticalSync(int ctrl, int delay)
133{ 122{
134 unsigned int status; 123 unsigned int status;
135 if(!ctrl){ 124
125 if (!ctrl) {
136 /* primary controller */ 126 /* primary controller */
137 127
138 /* Do not wait when the Primary PLL is off or display control is already off. 128 /* Do not wait when the Primary PLL is off or display control is already off.
139 This will prevent the software to wait forever. */ 129 This will prevent the software to wait forever. */
140 if ((FIELD_GET(PEEK32(PANEL_PLL_CTRL), PANEL_PLL_CTRL, POWER) == 130 if ((FIELD_GET(PEEK32(PANEL_PLL_CTRL), PANEL_PLL_CTRL, POWER) ==
141 PANEL_PLL_CTRL_POWER_OFF) || 131 PANEL_PLL_CTRL_POWER_OFF) ||
142 (FIELD_GET(PEEK32(PANEL_DISPLAY_CTRL), PANEL_DISPLAY_CTRL, TIMING) == 132 (FIELD_GET(PEEK32(PANEL_DISPLAY_CTRL), PANEL_DISPLAY_CTRL, TIMING) ==
143 PANEL_DISPLAY_CTRL_TIMING_DISABLE)) 133 PANEL_DISPLAY_CTRL_TIMING_DISABLE)) {
144 {
145 return; 134 return;
146 } 135 }
147 136
148 while (delay-- > 0) 137 while (delay-- > 0) {
149 { 138 /* Wait for end of vsync. */
150 /* Wait for end of vsync. */ 139 do {
151 do 140 status = FIELD_GET(PEEK32(SYSTEM_CTRL),
152 { 141 SYSTEM_CTRL,
153 status = FIELD_GET(PEEK32(SYSTEM_CTRL), 142 PANEL_VSYNC);
154 SYSTEM_CTRL, 143 } while (status == SYSTEM_CTRL_PANEL_VSYNC_ACTIVE);
155 PANEL_VSYNC); 144
156 } 145 /* Wait for start of vsync. */
157 while (status == SYSTEM_CTRL_PANEL_VSYNC_ACTIVE); 146 do {
158 147 status = FIELD_GET(PEEK32(SYSTEM_CTRL),
159 /* Wait for start of vsync. */ 148 SYSTEM_CTRL,
160 do 149 PANEL_VSYNC);
161 { 150 } while (status == SYSTEM_CTRL_PANEL_VSYNC_INACTIVE);
162 status = FIELD_GET(PEEK32(SYSTEM_CTRL), 151 }
163 SYSTEM_CTRL, 152
164 PANEL_VSYNC); 153 } else {
165 }
166 while (status == SYSTEM_CTRL_PANEL_VSYNC_INACTIVE);
167 }
168
169 }else{
170 154
171 /* Do not wait when the Primary PLL is off or display control is already off. 155 /* Do not wait when the Primary PLL is off or display control is already off.
172 This will prevent the software to wait forever. */ 156 This will prevent the software to wait forever. */
173 if ((FIELD_GET(PEEK32(CRT_PLL_CTRL), CRT_PLL_CTRL, POWER) == 157 if ((FIELD_GET(PEEK32(CRT_PLL_CTRL), CRT_PLL_CTRL, POWER) ==
174 CRT_PLL_CTRL_POWER_OFF) || 158 CRT_PLL_CTRL_POWER_OFF) ||
175 (FIELD_GET(PEEK32(CRT_DISPLAY_CTRL), CRT_DISPLAY_CTRL, TIMING) == 159 (FIELD_GET(PEEK32(CRT_DISPLAY_CTRL), CRT_DISPLAY_CTRL, TIMING) ==
176 CRT_DISPLAY_CTRL_TIMING_DISABLE)) 160 CRT_DISPLAY_CTRL_TIMING_DISABLE)) {
177 {
178 return; 161 return;
179 } 162 }
180 163
181 while (delay-- > 0) 164 while (delay-- > 0) {
182 {
183 /* Wait for end of vsync. */ 165 /* Wait for end of vsync. */
184 do 166 do {
185 {
186 status = FIELD_GET(PEEK32(SYSTEM_CTRL), 167 status = FIELD_GET(PEEK32(SYSTEM_CTRL),
187 SYSTEM_CTRL, 168 SYSTEM_CTRL,
188 CRT_VSYNC); 169 CRT_VSYNC);
189 } 170 } while (status == SYSTEM_CTRL_CRT_VSYNC_ACTIVE);
190 while (status == SYSTEM_CTRL_CRT_VSYNC_ACTIVE);
191 171
192 /* Wait for start of vsync. */ 172 /* Wait for start of vsync. */
193 do 173 do {
194 {
195 status = FIELD_GET(PEEK32(SYSTEM_CTRL), 174 status = FIELD_GET(PEEK32(SYSTEM_CTRL),
196 SYSTEM_CTRL, 175 SYSTEM_CTRL,
197 CRT_VSYNC); 176 CRT_VSYNC);
198 } 177 } while (status == SYSTEM_CTRL_CRT_VSYNC_INACTIVE);
199 while (status == SYSTEM_CTRL_CRT_VSYNC_INACTIVE);
200 } 178 }
201 } 179 }
202} 180}
@@ -233,14 +211,15 @@ static void swPanelPowerSequence(int disp, int delay)
233void ddk750_setLogicalDispOut(disp_output_t output) 211void ddk750_setLogicalDispOut(disp_output_t output)
234{ 212{
235 unsigned int reg; 213 unsigned int reg;
236 if(output & PNL_2_USAGE){ 214
215 if (output & PNL_2_USAGE) {
237 /* set panel path controller select */ 216 /* set panel path controller select */
238 reg = PEEK32(PANEL_DISPLAY_CTRL); 217 reg = PEEK32(PANEL_DISPLAY_CTRL);
239 reg = FIELD_VALUE(reg, PANEL_DISPLAY_CTRL, SELECT, (output & PNL_2_MASK)>>PNL_2_OFFSET); 218 reg = FIELD_VALUE(reg, PANEL_DISPLAY_CTRL, SELECT, (output & PNL_2_MASK)>>PNL_2_OFFSET);
240 POKE32(PANEL_DISPLAY_CTRL, reg); 219 POKE32(PANEL_DISPLAY_CTRL, reg);
241 } 220 }
242 221
243 if(output & CRT_2_USAGE){ 222 if (output & CRT_2_USAGE) {
244 /* set crt path controller select */ 223 /* set crt path controller select */
245 reg = PEEK32(CRT_DISPLAY_CTRL); 224 reg = PEEK32(CRT_DISPLAY_CTRL);
246 reg = FIELD_VALUE(reg, CRT_DISPLAY_CTRL, SELECT, (output & CRT_2_MASK)>>CRT_2_OFFSET); 225 reg = FIELD_VALUE(reg, CRT_DISPLAY_CTRL, SELECT, (output & CRT_2_MASK)>>CRT_2_OFFSET);
@@ -250,58 +229,57 @@ void ddk750_setLogicalDispOut(disp_output_t output)
250 229
251 } 230 }
252 231
253 if(output & PRI_TP_USAGE){ 232 if (output & PRI_TP_USAGE) {
254 /* set primary timing and plane en_bit */ 233 /* set primary timing and plane en_bit */
255 setDisplayControl(0, (output&PRI_TP_MASK)>>PRI_TP_OFFSET); 234 setDisplayControl(0, (output&PRI_TP_MASK)>>PRI_TP_OFFSET);
256 } 235 }
257 236
258 if(output & SEC_TP_USAGE){ 237 if (output & SEC_TP_USAGE) {
259 /* set secondary timing and plane en_bit*/ 238 /* set secondary timing and plane en_bit*/
260 setDisplayControl(1, (output&SEC_TP_MASK)>>SEC_TP_OFFSET); 239 setDisplayControl(1, (output&SEC_TP_MASK)>>SEC_TP_OFFSET);
261 } 240 }
262 241
263 if(output & PNL_SEQ_USAGE){ 242 if (output & PNL_SEQ_USAGE) {
264 /* set panel sequence */ 243 /* set panel sequence */
265 swPanelPowerSequence((output&PNL_SEQ_MASK)>>PNL_SEQ_OFFSET, 4); 244 swPanelPowerSequence((output&PNL_SEQ_MASK)>>PNL_SEQ_OFFSET, 4);
266 } 245 }
267 246
268 if(output & DAC_USAGE) 247 if (output & DAC_USAGE)
269 setDAC((output & DAC_MASK)>>DAC_OFFSET); 248 setDAC((output & DAC_MASK)>>DAC_OFFSET);
270 249
271 if(output & DPMS_USAGE) 250 if (output & DPMS_USAGE)
272 ddk750_setDPMS((output & DPMS_MASK) >> DPMS_OFFSET); 251 ddk750_setDPMS((output & DPMS_MASK) >> DPMS_OFFSET);
273} 252}
274 253
275 254
276int ddk750_initDVIDisp(void) 255int ddk750_initDVIDisp(void)
277{ 256{
278 /* Initialize DVI. If the dviInit fail and the VendorID or the DeviceID are 257 /* Initialize DVI. If the dviInit fail and the VendorID or the DeviceID are
279 not zeroed, then set the failure flag. If it is zeroe, it might mean 258 not zeroed, then set the failure flag. If it is zeroe, it might mean
280 that the system is in Dual CRT Monitor configuration. */ 259 that the system is in Dual CRT Monitor configuration. */
281 260
282 /* De-skew enabled with default 111b value. 261 /* De-skew enabled with default 111b value.
283 This will fix some artifacts problem in some mode on board 2.2. 262 This will fix some artifacts problem in some mode on board 2.2.
284 Somehow this fix does not affect board 2.1. 263 Somehow this fix does not affect board 2.1.
285 */ 264 */
286 if ((dviInit(1, /* Select Rising Edge */ 265 if ((dviInit(1, /* Select Rising Edge */
287 1, /* Select 24-bit bus */ 266 1, /* Select 24-bit bus */
288 0, /* Select Single Edge clock */ 267 0, /* Select Single Edge clock */
289 1, /* Enable HSync as is */ 268 1, /* Enable HSync as is */
290 1, /* Enable VSync as is */ 269 1, /* Enable VSync as is */
291 1, /* Enable De-skew */ 270 1, /* Enable De-skew */
292 7, /* Set the de-skew setting to maximum setup */ 271 7, /* Set the de-skew setting to maximum setup */
293 1, /* Enable continuous Sync */ 272 1, /* Enable continuous Sync */
294 1, /* Enable PLL Filter */ 273 1, /* Enable PLL Filter */
295 4 /* Use the recommended value for PLL Filter value */ 274 4 /* Use the recommended value for PLL Filter value */
296 ) != 0) && (dviGetVendorID() != 0x0000) && (dviGetDeviceID() != 0x0000)) 275 ) != 0) && (dviGetVendorID() != 0x0000) && (dviGetDeviceID() != 0x0000)) {
297 { 276 return (-1);
298 return (-1); 277 }
299 } 278
300 279 /* TODO: Initialize other display component */
301 /* TODO: Initialize other display component */ 280
302 281 /* Success */
303 /* Success */ 282 return 0;
304 return 0;
305 283
306} 284}
307 285
diff --git a/drivers/staging/sm750fb/ddk750_display.h b/drivers/staging/sm750fb/ddk750_display.h
index ae0f84c68de5..abccf84a8c9a 100644
--- a/drivers/staging/sm750fb/ddk750_display.h
+++ b/drivers/staging/sm750fb/ddk750_display.h
@@ -8,7 +8,7 @@
8#define PNL_2_OFFSET 0 8#define PNL_2_OFFSET 0
9#define PNL_2_MASK (3 << PNL_2_OFFSET) 9#define PNL_2_MASK (3 << PNL_2_OFFSET)
10#define PNL_2_USAGE (PNL_2_MASK << 16) 10#define PNL_2_USAGE (PNL_2_MASK << 16)
11#define PNL_2_PRI ((0 << PNL_2_OFFSET)|PNL_2_USAGE) 11#define PNL_2_PRI ((0 << PNL_2_OFFSET)|PNL_2_USAGE)
12#define PNL_2_SEC ((2 << PNL_2_OFFSET)|PNL_2_USAGE) 12#define PNL_2_SEC ((2 << PNL_2_OFFSET)|PNL_2_USAGE)
13 13
14 14
@@ -46,7 +46,7 @@
46 0: both off 46 0: both off
47*/ 47*/
48#define SEC_TP_OFFSET 5 48#define SEC_TP_OFFSET 5
49#define SEC_TP_MASK (1<< SEC_TP_OFFSET) 49#define SEC_TP_MASK (1 << SEC_TP_OFFSET)
50#define SEC_TP_USAGE (SEC_TP_MASK << 16) 50#define SEC_TP_USAGE (SEC_TP_MASK << 16)
51#define SEC_TP_ON ((0x1 << SEC_TP_OFFSET)|SEC_TP_USAGE) 51#define SEC_TP_ON ((0x1 << SEC_TP_OFFSET)|SEC_TP_USAGE)
52#define SEC_TP_OFF ((0x0 << SEC_TP_OFFSET)|SEC_TP_USAGE) 52#define SEC_TP_OFF ((0x0 << SEC_TP_OFFSET)|SEC_TP_USAGE)
@@ -67,7 +67,7 @@
67#define DAC_OFFSET 7 67#define DAC_OFFSET 7
68#define DAC_MASK (1 << DAC_OFFSET) 68#define DAC_MASK (1 << DAC_OFFSET)
69#define DAC_USAGE (DAC_MASK << 16) 69#define DAC_USAGE (DAC_MASK << 16)
70#define DAC_ON ((0x0<< DAC_OFFSET)|DAC_USAGE) 70#define DAC_ON ((0x0 << DAC_OFFSET)|DAC_USAGE)
71#define DAC_OFF ((0x1 << DAC_OFFSET)|DAC_USAGE) 71#define DAC_OFF ((0x1 << DAC_OFFSET)|DAC_USAGE)
72 72
73/* DPMS only affect D-SUB head 73/* DPMS only affect D-SUB head
@@ -86,8 +86,7 @@
86 CRT means crt path DSUB 86 CRT means crt path DSUB
87*/ 87*/
88#if 0 88#if 0
89typedef enum _disp_output_t 89typedef enum _disp_output_t {
90{
91 NO_DISPLAY = DPMS_OFF, 90 NO_DISPLAY = DPMS_OFF,
92 91
93 LCD1_PRI = PNL_2_PRI|PRI_TP_ON|PNL_SEQ_ON|DPMS_OFF|DAC_ON, 92 LCD1_PRI = PNL_2_PRI|PRI_TP_ON|PNL_SEQ_ON|DPMS_OFF|DAC_ON,
@@ -129,7 +128,7 @@ typedef enum _disp_output_t
129} 128}
130disp_output_t; 129disp_output_t;
131#else 130#else
132typedef enum _disp_output_t{ 131typedef enum _disp_output_t {
133 do_LCD1_PRI = PNL_2_PRI|PRI_TP_ON|PNL_SEQ_ON|DAC_ON, 132 do_LCD1_PRI = PNL_2_PRI|PRI_TP_ON|PNL_SEQ_ON|DAC_ON,
134 do_LCD1_SEC = PNL_2_SEC|SEC_TP_ON|PNL_SEQ_ON|DAC_ON, 133 do_LCD1_SEC = PNL_2_SEC|SEC_TP_ON|PNL_SEQ_ON|DAC_ON,
135#if 0 134#if 0
diff --git a/drivers/staging/sm750fb/ddk750_dvi.c b/drivers/staging/sm750fb/ddk750_dvi.c
index b2bf7e66d5cb..a7a23514ac39 100644
--- a/drivers/staging/sm750fb/ddk750_dvi.c
+++ b/drivers/staging/sm750fb/ddk750_dvi.c
@@ -1,4 +1,4 @@
1#define USE_DVICHIP 1#define USE_DVICHIP
2#ifdef USE_DVICHIP 2#ifdef USE_DVICHIP
3#include "ddk750_help.h" 3#include "ddk750_help.h"
4#include "ddk750_reg.h" 4#include "ddk750_reg.h"
@@ -9,47 +9,46 @@
9/* This global variable contains all the supported driver and its corresponding 9/* This global variable contains all the supported driver and its corresponding
10 function API. Please set the function pointer to NULL whenever the function 10 function API. Please set the function pointer to NULL whenever the function
11 is not supported. */ 11 is not supported. */
12static dvi_ctrl_device_t g_dcftSupportedDviController[] = 12static dvi_ctrl_device_t g_dcftSupportedDviController[] = {
13{
14#ifdef DVI_CTRL_SII164 13#ifdef DVI_CTRL_SII164
15 { 14 {
16 .pfnInit = sii164InitChip, 15 .pfnInit = sii164InitChip,
17 .pfnGetVendorId = sii164GetVendorID, 16 .pfnGetVendorId = sii164GetVendorID,
18 .pfnGetDeviceId = sii164GetDeviceID, 17 .pfnGetDeviceId = sii164GetDeviceID,
19#ifdef SII164_FULL_FUNCTIONS 18#ifdef SII164_FULL_FUNCTIONS
20 .pfnResetChip = sii164ResetChip, 19 .pfnResetChip = sii164ResetChip,
21 .pfnGetChipString = sii164GetChipString, 20 .pfnGetChipString = sii164GetChipString,
22 .pfnSetPower = sii164SetPower, 21 .pfnSetPower = sii164SetPower,
23 .pfnEnableHotPlugDetection = sii164EnableHotPlugDetection, 22 .pfnEnableHotPlugDetection = sii164EnableHotPlugDetection,
24 .pfnIsConnected = sii164IsConnected, 23 .pfnIsConnected = sii164IsConnected,
25 .pfnCheckInterrupt = sii164CheckInterrupt, 24 .pfnCheckInterrupt = sii164CheckInterrupt,
26 .pfnClearInterrupt = sii164ClearInterrupt, 25 .pfnClearInterrupt = sii164ClearInterrupt,
27#endif 26#endif
28 }, 27 },
29#endif 28#endif
30}; 29};
31 30
32 31
33int dviInit( 32int dviInit(
34 unsigned char edgeSelect, 33 unsigned char edgeSelect,
35 unsigned char busSelect, 34 unsigned char busSelect,
36 unsigned char dualEdgeClkSelect, 35 unsigned char dualEdgeClkSelect,
37 unsigned char hsyncEnable, 36 unsigned char hsyncEnable,
38 unsigned char vsyncEnable, 37 unsigned char vsyncEnable,
39 unsigned char deskewEnable, 38 unsigned char deskewEnable,
40 unsigned char deskewSetting, 39 unsigned char deskewSetting,
41 unsigned char continuousSyncEnable, 40 unsigned char continuousSyncEnable,
42 unsigned char pllFilterEnable, 41 unsigned char pllFilterEnable,
43 unsigned char pllFilterValue 42 unsigned char pllFilterValue
44 ) 43 )
45{ 44{
46 dvi_ctrl_device_t *pCurrentDviCtrl; 45 dvi_ctrl_device_t *pCurrentDviCtrl;
46
47 pCurrentDviCtrl = g_dcftSupportedDviController; 47 pCurrentDviCtrl = g_dcftSupportedDviController;
48 if(pCurrentDviCtrl->pfnInit != NULL) 48 if (pCurrentDviCtrl->pfnInit != NULL) {
49 {
50 return pCurrentDviCtrl->pfnInit(edgeSelect, busSelect, dualEdgeClkSelect, hsyncEnable, 49 return pCurrentDviCtrl->pfnInit(edgeSelect, busSelect, dualEdgeClkSelect, hsyncEnable,
51 vsyncEnable, deskewEnable, deskewSetting, continuousSyncEnable, 50 vsyncEnable, deskewEnable, deskewSetting, continuousSyncEnable,
52 pllFilterEnable, pllFilterValue); 51 pllFilterEnable, pllFilterValue);
53 } 52 }
54 return -1; /* error */ 53 return -1; /* error */
55} 54}
@@ -64,13 +63,13 @@ int dviInit(
64 */ 63 */
65unsigned short dviGetVendorID(void) 64unsigned short dviGetVendorID(void)
66{ 65{
67 dvi_ctrl_device_t *pCurrentDviCtrl; 66 dvi_ctrl_device_t *pCurrentDviCtrl;
68 67
69 pCurrentDviCtrl = g_dcftSupportedDviController; 68 pCurrentDviCtrl = g_dcftSupportedDviController;
70 if (pCurrentDviCtrl != (dvi_ctrl_device_t *)0) 69 if (pCurrentDviCtrl != (dvi_ctrl_device_t *)0)
71 return pCurrentDviCtrl->pfnGetVendorId(); 70 return pCurrentDviCtrl->pfnGetVendorId();
72 71
73 return 0x0000; 72 return 0x0000;
74} 73}
75 74
76 75
@@ -83,13 +82,13 @@ unsigned short dviGetVendorID(void)
83 */ 82 */
84unsigned short dviGetDeviceID(void) 83unsigned short dviGetDeviceID(void)
85{ 84{
86 dvi_ctrl_device_t *pCurrentDviCtrl; 85 dvi_ctrl_device_t *pCurrentDviCtrl;
87 86
88 pCurrentDviCtrl = g_dcftSupportedDviController; 87 pCurrentDviCtrl = g_dcftSupportedDviController;
89 if (pCurrentDviCtrl != (dvi_ctrl_device_t *)0) 88 if (pCurrentDviCtrl != (dvi_ctrl_device_t *)0)
90 return pCurrentDviCtrl->pfnGetDeviceId(); 89 return pCurrentDviCtrl->pfnGetDeviceId();
91 90
92 return 0x0000; 91 return 0x0000;
93} 92}
94 93
95#endif 94#endif
diff --git a/drivers/staging/sm750fb/ddk750_dvi.h b/drivers/staging/sm750fb/ddk750_dvi.h
index 83bbd6d62061..e1d4c9a2d50a 100644
--- a/drivers/staging/sm750fb/ddk750_dvi.h
+++ b/drivers/staging/sm750fb/ddk750_dvi.h
@@ -26,8 +26,7 @@ typedef unsigned char (*PFN_DVICTRL_CHECKINTERRUPT)(void);
26typedef void (*PFN_DVICTRL_CLEARINTERRUPT)(void); 26typedef void (*PFN_DVICTRL_CLEARINTERRUPT)(void);
27 27
28/* Structure to hold all the function pointer to the DVI Controller. */ 28/* Structure to hold all the function pointer to the DVI Controller. */
29typedef struct _dvi_ctrl_device_t 29typedef struct _dvi_ctrl_device_t {
30{
31 PFN_DVICTRL_INIT pfnInit; 30 PFN_DVICTRL_INIT pfnInit;
32 PFN_DVICTRL_RESETCHIP pfnResetChip; 31 PFN_DVICTRL_RESETCHIP pfnResetChip;
33 PFN_DVICTRL_GETCHIPSTRING pfnGetChipString; 32 PFN_DVICTRL_GETCHIPSTRING pfnGetChipString;
diff --git a/drivers/staging/sm750fb/ddk750_help.c b/drivers/staging/sm750fb/ddk750_help.c
index 1adcafcc5133..9637dd30d037 100644
--- a/drivers/staging/sm750fb/ddk750_help.c
+++ b/drivers/staging/sm750fb/ddk750_help.c
@@ -1,8 +1,8 @@
1#include "ddk750_help.h" 1#include "ddk750_help.h"
2 2
3void __iomem *mmio750 = NULL; 3void __iomem *mmio750;
4char revId750 = 0; 4char revId750;
5unsigned short devId750 = 0; 5unsigned short devId750;
6 6
7/* after driver mapped io registers, use this function first */ 7/* after driver mapped io registers, use this function first */
8void ddk750_set_mmio(void __iomem *addr, unsigned short devId, char revId) 8void ddk750_set_mmio(void __iomem *addr, unsigned short devId, char revId)
@@ -10,7 +10,7 @@ void ddk750_set_mmio(void __iomem *addr, unsigned short devId, char revId)
10 mmio750 = addr; 10 mmio750 = addr;
11 devId750 = devId; 11 devId750 = devId;
12 revId750 = revId; 12 revId750 = revId;
13 if(revId == 0xfe) 13 if (revId == 0xfe)
14 printk("found sm750le\n"); 14 printk("found sm750le\n");
15} 15}
16 16
diff --git a/drivers/staging/sm750fb/ddk750_help.h b/drivers/staging/sm750fb/ddk750_help.h
index 4285b056585a..3b06aed431bd 100644
--- a/drivers/staging/sm750fb/ddk750_help.h
+++ b/drivers/staging/sm750fb/ddk750_help.h
@@ -12,8 +12,8 @@
12#if 0 12#if 0
13/* if 718 big endian turned on,be aware that don't use this driver for general use,only for ppc big-endian */ 13/* if 718 big endian turned on,be aware that don't use this driver for general use,only for ppc big-endian */
14#warning "big endian on target cpu and enable nature big endian support of 718 capability !" 14#warning "big endian on target cpu and enable nature big endian support of 718 capability !"
15#define PEEK32(addr) __raw_readl(mmio750 + addr) 15#define PEEK32(addr) __raw_readl(mmio750 + addr)
16#define POKE32(addr, data) __raw_writel(data, mmio750 + addr) 16#define POKE32(addr, data) __raw_writel(data, mmio750 + addr)
17#else /* software control endianness */ 17#else /* software control endianness */
18#define PEEK32(addr) readl(addr + mmio750) 18#define PEEK32(addr) readl(addr + mmio750)
19#define POKE32(addr, data) writel(data, addr + mmio750) 19#define POKE32(addr, data) writel(data, addr + mmio750)
diff --git a/drivers/staging/sm750fb/ddk750_hwi2c.c b/drivers/staging/sm750fb/ddk750_hwi2c.c
index 7826376ed705..5ddac430aea2 100644
--- a/drivers/staging/sm750fb/ddk750_hwi2c.c
+++ b/drivers/staging/sm750fb/ddk750_hwi2c.c
@@ -10,70 +10,70 @@
10 10
11 11
12int hwI2CInit( 12int hwI2CInit(
13 unsigned char busSpeedMode 13unsigned char busSpeedMode
14) 14)
15{ 15{
16 unsigned int value; 16 unsigned int value;
17 17
18 /* Enable GPIO 30 & 31 as IIC clock & data */ 18 /* Enable GPIO 30 & 31 as IIC clock & data */
19 value = PEEK32(GPIO_MUX); 19 value = PEEK32(GPIO_MUX);
20 20
21 value = FIELD_SET(value, GPIO_MUX, 30, I2C) | 21 value = FIELD_SET(value, GPIO_MUX, 30, I2C) |
22 FIELD_SET(0, GPIO_MUX, 31, I2C); 22 FIELD_SET(0, GPIO_MUX, 31, I2C);
23 POKE32(GPIO_MUX, value); 23 POKE32(GPIO_MUX, value);
24 24
25 /* Enable Hardware I2C power. 25 /* Enable Hardware I2C power.
26 TODO: Check if we need to enable GPIO power? 26 TODO: Check if we need to enable GPIO power?
27 */ 27 */
28 enableI2C(1); 28 enableI2C(1);
29 29
30 /* Enable the I2C Controller and set the bus speed mode */ 30 /* Enable the I2C Controller and set the bus speed mode */
31 value = PEEK32(I2C_CTRL); 31 value = PEEK32(I2C_CTRL);
32 if (busSpeedMode == 0) 32 if (busSpeedMode == 0)
33 value = FIELD_SET(value, I2C_CTRL, MODE, STANDARD); 33 value = FIELD_SET(value, I2C_CTRL, MODE, STANDARD);
34 else 34 else
35 value = FIELD_SET(value, I2C_CTRL, MODE, FAST); 35 value = FIELD_SET(value, I2C_CTRL, MODE, FAST);
36 value = FIELD_SET(value, I2C_CTRL, EN, ENABLE); 36 value = FIELD_SET(value, I2C_CTRL, EN, ENABLE);
37 POKE32(I2C_CTRL, value); 37 POKE32(I2C_CTRL, value);
38 38
39 return 0; 39 return 0;
40} 40}
41 41
42 42
43void hwI2CClose(void) 43void hwI2CClose(void)
44{ 44{
45 unsigned int value; 45 unsigned int value;
46 46
47 /* Disable I2C controller */ 47 /* Disable I2C controller */
48 value = PEEK32(I2C_CTRL); 48 value = PEEK32(I2C_CTRL);
49 value = FIELD_SET(value, I2C_CTRL, EN, DISABLE); 49 value = FIELD_SET(value, I2C_CTRL, EN, DISABLE);
50 POKE32(I2C_CTRL, value); 50 POKE32(I2C_CTRL, value);
51 51
52 /* Disable I2C Power */ 52 /* Disable I2C Power */
53 enableI2C(0); 53 enableI2C(0);
54 54
55 /* Set GPIO 30 & 31 back as GPIO pins */ 55 /* Set GPIO 30 & 31 back as GPIO pins */
56 value = PEEK32(GPIO_MUX); 56 value = PEEK32(GPIO_MUX);
57 value = FIELD_SET(value, GPIO_MUX, 30, GPIO); 57 value = FIELD_SET(value, GPIO_MUX, 30, GPIO);
58 value = FIELD_SET(value, GPIO_MUX, 31, GPIO); 58 value = FIELD_SET(value, GPIO_MUX, 31, GPIO);
59 POKE32(GPIO_MUX, value); 59 POKE32(GPIO_MUX, value);
60} 60}
61 61
62 62
63static long hwI2CWaitTXDone(void) 63static long hwI2CWaitTXDone(void)
64{ 64{
65 unsigned int timeout; 65 unsigned int timeout;
66 66
67 /* Wait until the transfer is completed. */ 67 /* Wait until the transfer is completed. */
68 timeout = HWI2C_WAIT_TIMEOUT; 68 timeout = HWI2C_WAIT_TIMEOUT;
69 while ((FIELD_GET(PEEK32(I2C_STATUS), I2C_STATUS, TX) != I2C_STATUS_TX_COMPLETED) && 69 while ((FIELD_GET(PEEK32(I2C_STATUS), I2C_STATUS, TX) != I2C_STATUS_TX_COMPLETED) &&
70 (timeout != 0)) 70 (timeout != 0))
71 timeout--; 71 timeout--;
72 72
73 if (timeout == 0) 73 if (timeout == 0)
74 return (-1); 74 return (-1);
75 75
76 return 0; 76 return 0;
77} 77}
78 78
79 79
@@ -91,53 +91,52 @@ static long hwI2CWaitTXDone(void)
91 * Total number of bytes those are actually written. 91 * Total number of bytes those are actually written.
92 */ 92 */
93static unsigned int hwI2CWriteData( 93static unsigned int hwI2CWriteData(
94 unsigned char deviceAddress, 94 unsigned char deviceAddress,
95 unsigned int length, 95 unsigned int length,
96 unsigned char *pBuffer 96 unsigned char *pBuffer
97) 97)
98{ 98{
99 unsigned char count, i; 99 unsigned char count, i;
100 unsigned int totalBytes = 0; 100 unsigned int totalBytes = 0;
101 101
102 /* Set the Device Address */ 102 /* Set the Device Address */
103 POKE32(I2C_SLAVE_ADDRESS, deviceAddress & ~0x01); 103 POKE32(I2C_SLAVE_ADDRESS, deviceAddress & ~0x01);
104 104
105 /* Write data. 105 /* Write data.
106 * Note: 106 * Note:
107 * Only 16 byte can be accessed per i2c start instruction. 107 * Only 16 byte can be accessed per i2c start instruction.
108 */ 108 */
109 do 109 do {
110 { 110 /* Reset I2C by writing 0 to I2C_RESET register to clear the previous status. */
111 /* Reset I2C by writing 0 to I2C_RESET register to clear the previous status. */ 111 POKE32(I2C_RESET, 0);
112 POKE32(I2C_RESET, 0);
113 112
114 /* Set the number of bytes to be written */ 113 /* Set the number of bytes to be written */
115 if (length < MAX_HWI2C_FIFO) 114 if (length < MAX_HWI2C_FIFO)
116 count = length - 1; 115 count = length - 1;
117 else 116 else
118 count = MAX_HWI2C_FIFO - 1; 117 count = MAX_HWI2C_FIFO - 1;
119 POKE32(I2C_BYTE_COUNT, count); 118 POKE32(I2C_BYTE_COUNT, count);
120 119
121 /* Move the data to the I2C data register */ 120 /* Move the data to the I2C data register */
122 for (i = 0; i <= count; i++) 121 for (i = 0; i <= count; i++)
123 POKE32(I2C_DATA0 + i, *pBuffer++); 122 POKE32(I2C_DATA0 + i, *pBuffer++);
124 123
125 /* Start the I2C */ 124 /* Start the I2C */
126 POKE32(I2C_CTRL, FIELD_SET(PEEK32(I2C_CTRL), I2C_CTRL, CTRL, START)); 125 POKE32(I2C_CTRL, FIELD_SET(PEEK32(I2C_CTRL), I2C_CTRL, CTRL, START));
127 126
128 /* Wait until the transfer is completed. */ 127 /* Wait until the transfer is completed. */
129 if (hwI2CWaitTXDone() != 0) 128 if (hwI2CWaitTXDone() != 0)
130 break; 129 break;
131 130
132 /* Substract length */ 131 /* Substract length */
133 length -= (count + 1); 132 length -= (count + 1);
134 133
135 /* Total byte written */ 134 /* Total byte written */
136 totalBytes += (count + 1); 135 totalBytes += (count + 1);
137 136
138 } while (length > 0); 137 } while (length > 0);
139 138
140 return totalBytes; 139 return totalBytes;
141} 140}
142 141
143 142
@@ -158,53 +157,52 @@ static unsigned int hwI2CWriteData(
158 * Total number of actual bytes read from the slave device 157 * Total number of actual bytes read from the slave device
159 */ 158 */
160static unsigned int hwI2CReadData( 159static unsigned int hwI2CReadData(
161 unsigned char deviceAddress, 160 unsigned char deviceAddress,
162 unsigned int length, 161 unsigned int length,
163 unsigned char *pBuffer 162 unsigned char *pBuffer
164) 163)
165{ 164{
166 unsigned char count, i; 165 unsigned char count, i;
167 unsigned int totalBytes = 0; 166 unsigned int totalBytes = 0;
168 167
169 /* Set the Device Address */ 168 /* Set the Device Address */
170 POKE32(I2C_SLAVE_ADDRESS, deviceAddress | 0x01); 169 POKE32(I2C_SLAVE_ADDRESS, deviceAddress | 0x01);
171 170
172 /* Read data and save them to the buffer. 171 /* Read data and save them to the buffer.
173 * Note: 172 * Note:
174 * Only 16 byte can be accessed per i2c start instruction. 173 * Only 16 byte can be accessed per i2c start instruction.
175 */ 174 */
176 do 175 do {
177 { 176 /* Reset I2C by writing 0 to I2C_RESET register to clear all the status. */
178 /* Reset I2C by writing 0 to I2C_RESET register to clear all the status. */ 177 POKE32(I2C_RESET, 0);
179 POKE32(I2C_RESET, 0);
180 178
181 /* Set the number of bytes to be read */ 179 /* Set the number of bytes to be read */
182 if (length <= MAX_HWI2C_FIFO) 180 if (length <= MAX_HWI2C_FIFO)
183 count = length - 1; 181 count = length - 1;
184 else 182 else
185 count = MAX_HWI2C_FIFO - 1; 183 count = MAX_HWI2C_FIFO - 1;
186 POKE32(I2C_BYTE_COUNT, count); 184 POKE32(I2C_BYTE_COUNT, count);
187 185
188 /* Start the I2C */ 186 /* Start the I2C */
189 POKE32(I2C_CTRL, FIELD_SET(PEEK32(I2C_CTRL), I2C_CTRL, CTRL, START)); 187 POKE32(I2C_CTRL, FIELD_SET(PEEK32(I2C_CTRL), I2C_CTRL, CTRL, START));
190 188
191 /* Wait until transaction done. */ 189 /* Wait until transaction done. */
192 if (hwI2CWaitTXDone() != 0) 190 if (hwI2CWaitTXDone() != 0)
193 break; 191 break;
194 192
195 /* Save the data to the given buffer */ 193 /* Save the data to the given buffer */
196 for (i = 0; i <= count; i++) 194 for (i = 0; i <= count; i++)
197 *pBuffer++ = PEEK32(I2C_DATA0 + i); 195 *pBuffer++ = PEEK32(I2C_DATA0 + i);
198 196
199 /* Substract length by 16 */ 197 /* Substract length by 16 */
200 length -= (count + 1); 198 length -= (count + 1);
201 199
202 /* Number of bytes read. */ 200 /* Number of bytes read. */
203 totalBytes += (count + 1); 201 totalBytes += (count + 1);
204 202
205 } while (length > 0); 203 } while (length > 0);
206 204
207 return totalBytes; 205 return totalBytes;
208} 206}
209 207
210 208
@@ -222,16 +220,16 @@ static unsigned int hwI2CReadData(
222 * Register value 220 * Register value
223 */ 221 */
224unsigned char hwI2CReadReg( 222unsigned char hwI2CReadReg(
225 unsigned char deviceAddress, 223 unsigned char deviceAddress,
226 unsigned char registerIndex 224 unsigned char registerIndex
227) 225)
228{ 226{
229 unsigned char value = (0xFF); 227 unsigned char value = (0xFF);
230 228
231 if (hwI2CWriteData(deviceAddress, 1, &registerIndex) == 1) 229 if (hwI2CWriteData(deviceAddress, 1, &registerIndex) == 1)
232 hwI2CReadData(deviceAddress, 1, &value); 230 hwI2CReadData(deviceAddress, 1, &value);
233 231
234 return value; 232 return value;
235} 233}
236 234
237 235
@@ -252,19 +250,19 @@ unsigned char hwI2CReadReg(
252 * -1 - Fail 250 * -1 - Fail
253 */ 251 */
254int hwI2CWriteReg( 252int hwI2CWriteReg(
255 unsigned char deviceAddress, 253 unsigned char deviceAddress,
256 unsigned char registerIndex, 254 unsigned char registerIndex,
257 unsigned char data 255 unsigned char data
258) 256)
259{ 257{
260 unsigned char value[2]; 258 unsigned char value[2];
261 259
262 value[0] = registerIndex; 260 value[0] = registerIndex;
263 value[1] = data; 261 value[1] = data;
264 if (hwI2CWriteData(deviceAddress, 2, value) == 2) 262 if (hwI2CWriteData(deviceAddress, 2, value) == 2)
265 return 0; 263 return 0;
266 264
267 return (-1); 265 return (-1);
268} 266}
269 267
270 268
diff --git a/drivers/staging/sm750fb/ddk750_mode.c b/drivers/staging/sm750fb/ddk750_mode.c
index 74313ff84e45..2399b175ade0 100644
--- a/drivers/staging/sm750fb/ddk750_mode.c
+++ b/drivers/staging/sm750fb/ddk750_mode.c
@@ -20,54 +20,54 @@ static unsigned long displayControlAdjust_SM750LE(mode_parameter_t *pModeParam,
20 x = pModeParam->horizontal_display_end; 20 x = pModeParam->horizontal_display_end;
21 y = pModeParam->vertical_display_end; 21 y = pModeParam->vertical_display_end;
22 22
23 /* SM750LE has to set up the top-left and bottom-right 23 /* SM750LE has to set up the top-left and bottom-right
24 registers as well. 24 registers as well.
25 Note that normal SM750/SM718 only use those two register for 25 Note that normal SM750/SM718 only use those two register for
26 auto-centering mode. 26 auto-centering mode.
27 */ 27 */
28 POKE32(CRT_AUTO_CENTERING_TL, 28 POKE32(CRT_AUTO_CENTERING_TL,
29 FIELD_VALUE(0, CRT_AUTO_CENTERING_TL, TOP, 0) 29 FIELD_VALUE(0, CRT_AUTO_CENTERING_TL, TOP, 0)
30 | FIELD_VALUE(0, CRT_AUTO_CENTERING_TL, LEFT, 0)); 30 | FIELD_VALUE(0, CRT_AUTO_CENTERING_TL, LEFT, 0));
31 31
32 POKE32(CRT_AUTO_CENTERING_BR, 32 POKE32(CRT_AUTO_CENTERING_BR,
33 FIELD_VALUE(0, CRT_AUTO_CENTERING_BR, BOTTOM, y-1) 33 FIELD_VALUE(0, CRT_AUTO_CENTERING_BR, BOTTOM, y-1)
34 | FIELD_VALUE(0, CRT_AUTO_CENTERING_BR, RIGHT, x-1)); 34 | FIELD_VALUE(0, CRT_AUTO_CENTERING_BR, RIGHT, x-1));
35 35
36 /* Assume common fields in dispControl have been properly set before 36 /* Assume common fields in dispControl have been properly set before
37 calling this function. 37 calling this function.
38 This function only sets the extra fields in dispControl. 38 This function only sets the extra fields in dispControl.
39 */ 39 */
40 40
41 /* Clear bit 29:27 of display control register */ 41 /* Clear bit 29:27 of display control register */
42 dispControl &= FIELD_CLEAR(CRT_DISPLAY_CTRL, CLK); 42 dispControl &= FIELD_CLEAR(CRT_DISPLAY_CTRL, CLK);
43 43
44 /* Set bit 29:27 of display control register for the right clock */ 44 /* Set bit 29:27 of display control register for the right clock */
45 /* Note that SM750LE only need to supported 7 resoluitons. */ 45 /* Note that SM750LE only need to supported 7 resoluitons. */
46 if ( x == 800 && y == 600 ) 46 if (x == 800 && y == 600)
47 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL41); 47 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL41);
48 else if (x == 1024 && y == 768) 48 else if (x == 1024 && y == 768)
49 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL65); 49 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL65);
50 else if (x == 1152 && y == 864) 50 else if (x == 1152 && y == 864)
51 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL80); 51 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL80);
52 else if (x == 1280 && y == 768) 52 else if (x == 1280 && y == 768)
53 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL80); 53 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL80);
54 else if (x == 1280 && y == 720) 54 else if (x == 1280 && y == 720)
55 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL74); 55 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL74);
56 else if (x == 1280 && y == 960) 56 else if (x == 1280 && y == 960)
57 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL108); 57 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL108);
58 else if (x == 1280 && y == 1024) 58 else if (x == 1280 && y == 1024)
59 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL108); 59 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL108);
60 else /* default to VGA clock */ 60 else /* default to VGA clock */
61 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL25); 61 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLK, PLL25);
62 62
63 /* Set bit 25:24 of display controller */ 63 /* Set bit 25:24 of display controller */
64 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CRTSELECT, CRT); 64 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CRTSELECT, CRT);
65 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, RGBBIT, 24BIT); 65 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, RGBBIT, 24BIT);
66 66
67 /* Set bit 14 of display controller */ 67 /* Set bit 14 of display controller */
68 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLOCK_PHASE, ACTIVE_LOW); 68 dispControl = FIELD_SET(dispControl, CRT_DISPLAY_CTRL, CLOCK_PHASE, ACTIVE_LOW);
69 69
70 POKE32(CRT_DISPLAY_CTRL, dispControl); 70 POKE32(CRT_DISPLAY_CTRL, dispControl);
71 71
72 return dispControl; 72 return dispControl;
73} 73}
@@ -80,25 +80,25 @@ static int programModeRegisters(mode_parameter_t *pModeParam, pll_value_t *pll)
80 int ret = 0; 80 int ret = 0;
81 int cnt = 0; 81 int cnt = 0;
82 unsigned int ulTmpValue, ulReg; 82 unsigned int ulTmpValue, ulReg;
83 if(pll->clockType == SECONDARY_PLL) 83
84 { 84 if (pll->clockType == SECONDARY_PLL) {
85 /* programe secondary pixel clock */ 85 /* programe secondary pixel clock */
86 POKE32(CRT_PLL_CTRL, formatPllReg(pll)); 86 POKE32(CRT_PLL_CTRL, formatPllReg(pll));
87 POKE32(CRT_HORIZONTAL_TOTAL, 87 POKE32(CRT_HORIZONTAL_TOTAL,
88 FIELD_VALUE(0, CRT_HORIZONTAL_TOTAL, TOTAL, pModeParam->horizontal_total - 1) 88 FIELD_VALUE(0, CRT_HORIZONTAL_TOTAL, TOTAL, pModeParam->horizontal_total - 1)
89 | FIELD_VALUE(0, CRT_HORIZONTAL_TOTAL, DISPLAY_END, pModeParam->horizontal_display_end - 1)); 89 | FIELD_VALUE(0, CRT_HORIZONTAL_TOTAL, DISPLAY_END, pModeParam->horizontal_display_end - 1));
90 90
91 POKE32(CRT_HORIZONTAL_SYNC, 91 POKE32(CRT_HORIZONTAL_SYNC,
92 FIELD_VALUE(0, CRT_HORIZONTAL_SYNC, WIDTH, pModeParam->horizontal_sync_width) 92 FIELD_VALUE(0, CRT_HORIZONTAL_SYNC, WIDTH, pModeParam->horizontal_sync_width)
93 | FIELD_VALUE(0, CRT_HORIZONTAL_SYNC, START, pModeParam->horizontal_sync_start - 1)); 93 | FIELD_VALUE(0, CRT_HORIZONTAL_SYNC, START, pModeParam->horizontal_sync_start - 1));
94 94
95 POKE32(CRT_VERTICAL_TOTAL, 95 POKE32(CRT_VERTICAL_TOTAL,
96 FIELD_VALUE(0, CRT_VERTICAL_TOTAL, TOTAL, pModeParam->vertical_total - 1) 96 FIELD_VALUE(0, CRT_VERTICAL_TOTAL, TOTAL, pModeParam->vertical_total - 1)
97 | FIELD_VALUE(0, CRT_VERTICAL_TOTAL, DISPLAY_END, pModeParam->vertical_display_end - 1)); 97 | FIELD_VALUE(0, CRT_VERTICAL_TOTAL, DISPLAY_END, pModeParam->vertical_display_end - 1));
98 98
99 POKE32(CRT_VERTICAL_SYNC, 99 POKE32(CRT_VERTICAL_SYNC,
100 FIELD_VALUE(0, CRT_VERTICAL_SYNC, HEIGHT, pModeParam->vertical_sync_height) 100 FIELD_VALUE(0, CRT_VERTICAL_SYNC, HEIGHT, pModeParam->vertical_sync_height)
101 | FIELD_VALUE(0, CRT_VERTICAL_SYNC, START, pModeParam->vertical_sync_start - 1)); 101 | FIELD_VALUE(0, CRT_VERTICAL_SYNC, START, pModeParam->vertical_sync_start - 1));
102 102
103 103
104 ulTmpValue = FIELD_VALUE(0, CRT_DISPLAY_CTRL, VSYNC_PHASE, pModeParam->vertical_sync_polarity)| 104 ulTmpValue = FIELD_VALUE(0, CRT_DISPLAY_CTRL, VSYNC_PHASE, pModeParam->vertical_sync_polarity)|
@@ -107,9 +107,9 @@ static int programModeRegisters(mode_parameter_t *pModeParam, pll_value_t *pll)
107 FIELD_SET(0, CRT_DISPLAY_CTRL, PLANE, ENABLE); 107 FIELD_SET(0, CRT_DISPLAY_CTRL, PLANE, ENABLE);
108 108
109 109
110 if(getChipType() == SM750LE){ 110 if (getChipType() == SM750LE) {
111 displayControlAdjust_SM750LE(pModeParam, ulTmpValue); 111 displayControlAdjust_SM750LE(pModeParam, ulTmpValue);
112 }else{ 112 } else {
113 ulReg = PEEK32(CRT_DISPLAY_CTRL) 113 ulReg = PEEK32(CRT_DISPLAY_CTRL)
114 & FIELD_CLEAR(CRT_DISPLAY_CTRL, VSYNC_PHASE) 114 & FIELD_CLEAR(CRT_DISPLAY_CTRL, VSYNC_PHASE)
115 & FIELD_CLEAR(CRT_DISPLAY_CTRL, HSYNC_PHASE) 115 & FIELD_CLEAR(CRT_DISPLAY_CTRL, HSYNC_PHASE)
@@ -119,45 +119,44 @@ static int programModeRegisters(mode_parameter_t *pModeParam, pll_value_t *pll)
119 POKE32(CRT_DISPLAY_CTRL, ulTmpValue|ulReg); 119 POKE32(CRT_DISPLAY_CTRL, ulTmpValue|ulReg);
120 } 120 }
121 121
122 } 122 } else if (pll->clockType == PRIMARY_PLL) {
123 else if(pll->clockType == PRIMARY_PLL)
124 {
125 unsigned int ulReservedBits; 123 unsigned int ulReservedBits;
124
126 POKE32(PANEL_PLL_CTRL, formatPllReg(pll)); 125 POKE32(PANEL_PLL_CTRL, formatPllReg(pll));
127 126
128 POKE32(PANEL_HORIZONTAL_TOTAL, 127 POKE32(PANEL_HORIZONTAL_TOTAL,
129 FIELD_VALUE(0, PANEL_HORIZONTAL_TOTAL, TOTAL, pModeParam->horizontal_total - 1) 128 FIELD_VALUE(0, PANEL_HORIZONTAL_TOTAL, TOTAL, pModeParam->horizontal_total - 1)
130 | FIELD_VALUE(0, PANEL_HORIZONTAL_TOTAL, DISPLAY_END, pModeParam->horizontal_display_end - 1)); 129 | FIELD_VALUE(0, PANEL_HORIZONTAL_TOTAL, DISPLAY_END, pModeParam->horizontal_display_end - 1));
131 130
132 POKE32(PANEL_HORIZONTAL_SYNC, 131 POKE32(PANEL_HORIZONTAL_SYNC,
133 FIELD_VALUE(0, PANEL_HORIZONTAL_SYNC, WIDTH, pModeParam->horizontal_sync_width) 132 FIELD_VALUE(0, PANEL_HORIZONTAL_SYNC, WIDTH, pModeParam->horizontal_sync_width)
134 | FIELD_VALUE(0, PANEL_HORIZONTAL_SYNC, START, pModeParam->horizontal_sync_start - 1)); 133 | FIELD_VALUE(0, PANEL_HORIZONTAL_SYNC, START, pModeParam->horizontal_sync_start - 1));
135 134
136 POKE32(PANEL_VERTICAL_TOTAL, 135 POKE32(PANEL_VERTICAL_TOTAL,
137 FIELD_VALUE(0, PANEL_VERTICAL_TOTAL, TOTAL, pModeParam->vertical_total - 1) 136 FIELD_VALUE(0, PANEL_VERTICAL_TOTAL, TOTAL, pModeParam->vertical_total - 1)
138 | FIELD_VALUE(0, PANEL_VERTICAL_TOTAL, DISPLAY_END, pModeParam->vertical_display_end - 1)); 137 | FIELD_VALUE(0, PANEL_VERTICAL_TOTAL, DISPLAY_END, pModeParam->vertical_display_end - 1));
139 138
140 POKE32(PANEL_VERTICAL_SYNC, 139 POKE32(PANEL_VERTICAL_SYNC,
141 FIELD_VALUE(0, PANEL_VERTICAL_SYNC, HEIGHT, pModeParam->vertical_sync_height) 140 FIELD_VALUE(0, PANEL_VERTICAL_SYNC, HEIGHT, pModeParam->vertical_sync_height)
142 | FIELD_VALUE(0, PANEL_VERTICAL_SYNC, START, pModeParam->vertical_sync_start - 1)); 141 | FIELD_VALUE(0, PANEL_VERTICAL_SYNC, START, pModeParam->vertical_sync_start - 1));
143 142
144 ulTmpValue = FIELD_VALUE(0, PANEL_DISPLAY_CTRL, VSYNC_PHASE, pModeParam->vertical_sync_polarity)| 143 ulTmpValue = FIELD_VALUE(0, PANEL_DISPLAY_CTRL, VSYNC_PHASE, pModeParam->vertical_sync_polarity)|
145 FIELD_VALUE(0, PANEL_DISPLAY_CTRL, HSYNC_PHASE, pModeParam->horizontal_sync_polarity)| 144 FIELD_VALUE(0, PANEL_DISPLAY_CTRL, HSYNC_PHASE, pModeParam->horizontal_sync_polarity)|
146 FIELD_VALUE(0, PANEL_DISPLAY_CTRL, CLOCK_PHASE, pModeParam->clock_phase_polarity)| 145 FIELD_VALUE(0, PANEL_DISPLAY_CTRL, CLOCK_PHASE, pModeParam->clock_phase_polarity)|
147 FIELD_SET(0, PANEL_DISPLAY_CTRL, TIMING, ENABLE)| 146 FIELD_SET(0, PANEL_DISPLAY_CTRL, TIMING, ENABLE)|
148 FIELD_SET(0, PANEL_DISPLAY_CTRL, PLANE, ENABLE); 147 FIELD_SET(0, PANEL_DISPLAY_CTRL, PLANE, ENABLE);
149 148
150 ulReservedBits = FIELD_SET(0, PANEL_DISPLAY_CTRL, RESERVED_1_MASK, ENABLE) | 149 ulReservedBits = FIELD_SET(0, PANEL_DISPLAY_CTRL, RESERVED_1_MASK, ENABLE) |
151 FIELD_SET(0, PANEL_DISPLAY_CTRL, RESERVED_2_MASK, ENABLE) | 150 FIELD_SET(0, PANEL_DISPLAY_CTRL, RESERVED_2_MASK, ENABLE) |
152 FIELD_SET(0, PANEL_DISPLAY_CTRL, RESERVED_3_MASK, ENABLE)| 151 FIELD_SET(0, PANEL_DISPLAY_CTRL, RESERVED_3_MASK, ENABLE)|
153 FIELD_SET(0, PANEL_DISPLAY_CTRL, VSYNC, ACTIVE_LOW); 152 FIELD_SET(0, PANEL_DISPLAY_CTRL, VSYNC, ACTIVE_LOW);
154 153
155 ulReg = (PEEK32(PANEL_DISPLAY_CTRL) & ~ulReservedBits) 154 ulReg = (PEEK32(PANEL_DISPLAY_CTRL) & ~ulReservedBits)
156 & FIELD_CLEAR(PANEL_DISPLAY_CTRL, CLOCK_PHASE) 155 & FIELD_CLEAR(PANEL_DISPLAY_CTRL, CLOCK_PHASE)
157 & FIELD_CLEAR(PANEL_DISPLAY_CTRL, VSYNC_PHASE) 156 & FIELD_CLEAR(PANEL_DISPLAY_CTRL, VSYNC_PHASE)
158 & FIELD_CLEAR(PANEL_DISPLAY_CTRL, HSYNC_PHASE) 157 & FIELD_CLEAR(PANEL_DISPLAY_CTRL, HSYNC_PHASE)
159 & FIELD_CLEAR(PANEL_DISPLAY_CTRL, TIMING) 158 & FIELD_CLEAR(PANEL_DISPLAY_CTRL, TIMING)
160 & FIELD_CLEAR(PANEL_DISPLAY_CTRL, PLANE); 159 & FIELD_CLEAR(PANEL_DISPLAY_CTRL, PLANE);
161 160
162 161
163 /* May a hardware bug or just my test chip (not confirmed). 162 /* May a hardware bug or just my test chip (not confirmed).
@@ -170,16 +169,14 @@ static int programModeRegisters(mode_parameter_t *pModeParam, pll_value_t *pll)
170 169
171 POKE32(PANEL_DISPLAY_CTRL, ulTmpValue|ulReg); 170 POKE32(PANEL_DISPLAY_CTRL, ulTmpValue|ulReg);
172#if 1 171#if 1
173 while((PEEK32(PANEL_DISPLAY_CTRL) & ~ulReservedBits) != (ulTmpValue|ulReg)) 172 while ((PEEK32(PANEL_DISPLAY_CTRL) & ~ulReservedBits) != (ulTmpValue|ulReg)) {
174 {
175 cnt++; 173 cnt++;
176 if(cnt > 1000) 174 if (cnt > 1000)
177 break; 175 break;
178 POKE32(PANEL_DISPLAY_CTRL, ulTmpValue|ulReg); 176 POKE32(PANEL_DISPLAY_CTRL, ulTmpValue|ulReg);
179 } 177 }
180#endif 178#endif
181 } 179 } else {
182 else{
183 ret = -1; 180 ret = -1;
184 } 181 }
185 return ret; 182 return ret;
@@ -189,11 +186,12 @@ int ddk750_setModeTiming(mode_parameter_t *parm, clock_type_t clock)
189{ 186{
190 pll_value_t pll; 187 pll_value_t pll;
191 unsigned int uiActualPixelClk; 188 unsigned int uiActualPixelClk;
189
192 pll.inputFreq = DEFAULT_INPUT_CLOCK; 190 pll.inputFreq = DEFAULT_INPUT_CLOCK;
193 pll.clockType = clock; 191 pll.clockType = clock;
194 192
195 uiActualPixelClk = calcPllValue(parm->pixel_clock, &pll); 193 uiActualPixelClk = calcPllValue(parm->pixel_clock, &pll);
196 if(getChipType() == SM750LE){ 194 if (getChipType() == SM750LE) {
197 /* set graphic mode via IO method */ 195 /* set graphic mode via IO method */
198 outb_p(0x88, 0x3d4); 196 outb_p(0x88, 0x3d4);
199 outb_p(0x06, 0x3d5); 197 outb_p(0x06, 0x3d5);
diff --git a/drivers/staging/sm750fb/ddk750_mode.h b/drivers/staging/sm750fb/ddk750_mode.h
index 4e8fab3f17e4..e846dc2c3d5c 100644
--- a/drivers/staging/sm750fb/ddk750_mode.h
+++ b/drivers/staging/sm750fb/ddk750_mode.h
@@ -3,37 +3,35 @@
3 3
4#include "ddk750_chip.h" 4#include "ddk750_chip.h"
5 5
6typedef enum _spolarity_t 6typedef enum _spolarity_t {
7{ 7 POS = 0, /* positive */
8 POS = 0, /* positive */ 8 NEG, /* negative */
9 NEG, /* negative */
10} 9}
11spolarity_t; 10spolarity_t;
12 11
13 12
14typedef struct _mode_parameter_t 13typedef struct _mode_parameter_t {
15{ 14 /* Horizontal timing. */
16 /* Horizontal timing. */ 15 unsigned long horizontal_total;
17 unsigned long horizontal_total; 16 unsigned long horizontal_display_end;
18 unsigned long horizontal_display_end; 17 unsigned long horizontal_sync_start;
19 unsigned long horizontal_sync_start; 18 unsigned long horizontal_sync_width;
20 unsigned long horizontal_sync_width; 19 spolarity_t horizontal_sync_polarity;
21 spolarity_t horizontal_sync_polarity; 20
22 21 /* Vertical timing. */
23 /* Vertical timing. */ 22 unsigned long vertical_total;
24 unsigned long vertical_total; 23 unsigned long vertical_display_end;
25 unsigned long vertical_display_end; 24 unsigned long vertical_sync_start;
26 unsigned long vertical_sync_start; 25 unsigned long vertical_sync_height;
27 unsigned long vertical_sync_height; 26 spolarity_t vertical_sync_polarity;
28 spolarity_t vertical_sync_polarity; 27
29 28 /* Refresh timing. */
30 /* Refresh timing. */ 29 unsigned long pixel_clock;
31 unsigned long pixel_clock; 30 unsigned long horizontal_frequency;
32 unsigned long horizontal_frequency; 31 unsigned long vertical_frequency;
33 unsigned long vertical_frequency; 32
34 33 /* Clock Phase. This clock phase only applies to Panel. */
35 /* Clock Phase. This clock phase only applies to Panel. */ 34 spolarity_t clock_phase_polarity;
36 spolarity_t clock_phase_polarity;
37} 35}
38mode_parameter_t; 36mode_parameter_t;
39 37
diff --git a/drivers/staging/sm750fb/ddk750_power.c b/drivers/staging/sm750fb/ddk750_power.c
index 1e5f398aed10..e580dab2b625 100644
--- a/drivers/staging/sm750fb/ddk750_power.c
+++ b/drivers/staging/sm750fb/ddk750_power.c
@@ -5,21 +5,23 @@
5void ddk750_setDPMS(DPMS_t state) 5void ddk750_setDPMS(DPMS_t state)
6{ 6{
7 unsigned int value; 7 unsigned int value;
8 if(getChipType() == SM750LE){ 8
9 if (getChipType() == SM750LE) {
9 value = PEEK32(CRT_DISPLAY_CTRL); 10 value = PEEK32(CRT_DISPLAY_CTRL);
10 POKE32(CRT_DISPLAY_CTRL, FIELD_VALUE(value, CRT_DISPLAY_CTRL, DPMS, state)); 11 POKE32(CRT_DISPLAY_CTRL, FIELD_VALUE(value, CRT_DISPLAY_CTRL,
11 }else{ 12 DPMS, state));
13 } else {
12 value = PEEK32(SYSTEM_CTRL); 14 value = PEEK32(SYSTEM_CTRL);
13 value= FIELD_VALUE(value, SYSTEM_CTRL, DPMS, state); 15 value = FIELD_VALUE(value, SYSTEM_CTRL, DPMS, state);
14 POKE32(SYSTEM_CTRL, value); 16 POKE32(SYSTEM_CTRL, value);
15 } 17 }
16} 18}
17 19
18unsigned int getPowerMode(void) 20unsigned int getPowerMode(void)
19{ 21{
20 if(getChipType() == SM750LE) 22 if (getChipType() == SM750LE)
21 return 0; 23 return 0;
22 return (FIELD_GET(PEEK32(POWER_MODE_CTRL), POWER_MODE_CTRL, MODE)); 24 return FIELD_GET(PEEK32(POWER_MODE_CTRL), POWER_MODE_CTRL, MODE);
23} 25}
24 26
25 27
@@ -29,76 +31,74 @@ unsigned int getPowerMode(void)
29 */ 31 */
30void setPowerMode(unsigned int powerMode) 32void setPowerMode(unsigned int powerMode)
31{ 33{
32 unsigned int control_value = 0; 34 unsigned int control_value = 0;
33 35
34 control_value = PEEK32(POWER_MODE_CTRL); 36 control_value = PEEK32(POWER_MODE_CTRL);
35 37
36 if(getChipType() == SM750LE) 38 if (getChipType() == SM750LE)
37 return; 39 return;
38 40
39 switch (powerMode) 41 switch (powerMode) {
40 { 42 case POWER_MODE_CTRL_MODE_MODE0:
41 case POWER_MODE_CTRL_MODE_MODE0: 43 control_value = FIELD_SET(control_value, POWER_MODE_CTRL, MODE,
42 control_value = FIELD_SET(control_value, POWER_MODE_CTRL, MODE, MODE0); 44 MODE0);
43 break; 45 break;
44 46
45 case POWER_MODE_CTRL_MODE_MODE1: 47 case POWER_MODE_CTRL_MODE_MODE1:
46 control_value = FIELD_SET(control_value, POWER_MODE_CTRL, MODE, MODE1); 48 control_value = FIELD_SET(control_value, POWER_MODE_CTRL, MODE,
47 break; 49 MODE1);
50 break;
48 51
49 case POWER_MODE_CTRL_MODE_SLEEP: 52 case POWER_MODE_CTRL_MODE_SLEEP:
50 control_value = FIELD_SET(control_value, POWER_MODE_CTRL, MODE, SLEEP); 53 control_value = FIELD_SET(control_value, POWER_MODE_CTRL, MODE,
51 break; 54 SLEEP);
55 break;
52 56
53 default: 57 default:
54 break; 58 break;
55 } 59 }
56 60
57 /* Set up other fields in Power Control Register */ 61 /* Set up other fields in Power Control Register */
58 if (powerMode == POWER_MODE_CTRL_MODE_SLEEP) 62 if (powerMode == POWER_MODE_CTRL_MODE_SLEEP) {
59 { 63 control_value =
60 control_value =
61#ifdef VALIDATION_CHIP 64#ifdef VALIDATION_CHIP
62 FIELD_SET( control_value, POWER_MODE_CTRL, 336CLK, OFF) | 65 FIELD_SET(control_value, POWER_MODE_CTRL, 336CLK, OFF) |
63#endif 66#endif
64 FIELD_SET( control_value, POWER_MODE_CTRL, OSC_INPUT, OFF); 67 FIELD_SET(control_value, POWER_MODE_CTRL, OSC_INPUT, OFF);
65 } 68 } else {
66 else 69 control_value =
67 {
68 control_value =
69#ifdef VALIDATION_CHIP 70#ifdef VALIDATION_CHIP
70 FIELD_SET( control_value, POWER_MODE_CTRL, 336CLK, ON) | 71 FIELD_SET(control_value, POWER_MODE_CTRL, 336CLK, ON) |
71#endif 72#endif
72 FIELD_SET( control_value, POWER_MODE_CTRL, OSC_INPUT, ON); 73 FIELD_SET(control_value, POWER_MODE_CTRL, OSC_INPUT, ON);
73 } 74 }
74 75
75 /* Program new power mode. */ 76 /* Program new power mode. */
76 POKE32(POWER_MODE_CTRL, control_value); 77 POKE32(POWER_MODE_CTRL, control_value);
77} 78}
78 79
79void setCurrentGate(unsigned int gate) 80void setCurrentGate(unsigned int gate)
80{ 81{
81 unsigned int gate_reg; 82 unsigned int gate_reg;
82 unsigned int mode; 83 unsigned int mode;
83 84
84 /* Get current power mode. */ 85 /* Get current power mode. */
85 mode = getPowerMode(); 86 mode = getPowerMode();
86 87
87 switch (mode) 88 switch (mode) {
88 { 89 case POWER_MODE_CTRL_MODE_MODE0:
89 case POWER_MODE_CTRL_MODE_MODE0: 90 gate_reg = MODE0_GATE;
90 gate_reg = MODE0_GATE; 91 break;
91 break; 92
92 93 case POWER_MODE_CTRL_MODE_MODE1:
93 case POWER_MODE_CTRL_MODE_MODE1: 94 gate_reg = MODE1_GATE;
94 gate_reg = MODE1_GATE; 95 break;
95 break; 96
96 97 default:
97 default: 98 gate_reg = MODE0_GATE;
98 gate_reg = MODE0_GATE; 99 break;
99 break; 100 }
100 } 101 POKE32(gate_reg, gate);
101 POKE32(gate_reg, gate);
102} 102}
103 103
104 104
@@ -108,21 +108,18 @@ void setCurrentGate(unsigned int gate)
108 */ 108 */
109void enable2DEngine(unsigned int enable) 109void enable2DEngine(unsigned int enable)
110{ 110{
111 uint32_t gate; 111 uint32_t gate;
112 112
113 gate = PEEK32(CURRENT_GATE); 113 gate = PEEK32(CURRENT_GATE);
114 if (enable) 114 if (enable) {
115 { 115 gate = FIELD_SET(gate, CURRENT_GATE, DE, ON);
116 gate = FIELD_SET(gate, CURRENT_GATE, DE, ON); 116 gate = FIELD_SET(gate, CURRENT_GATE, CSC, ON);
117 gate = FIELD_SET(gate, CURRENT_GATE, CSC, ON); 117 } else {
118 } 118 gate = FIELD_SET(gate, CURRENT_GATE, DE, OFF);
119 else 119 gate = FIELD_SET(gate, CURRENT_GATE, CSC, OFF);
120 { 120 }
121 gate = FIELD_SET(gate, CURRENT_GATE, DE, OFF); 121
122 gate = FIELD_SET(gate, CURRENT_GATE, CSC, OFF); 122 setCurrentGate(gate);
123 }
124
125 setCurrentGate(gate);
126} 123}
127 124
128 125
@@ -131,58 +128,56 @@ void enable2DEngine(unsigned int enable)
131 */ 128 */
132void enableZVPort(unsigned int enable) 129void enableZVPort(unsigned int enable)
133{ 130{
134 uint32_t gate; 131 uint32_t gate;
135 132
136 /* Enable ZV Port Gate */ 133 /* Enable ZV Port Gate */
137 gate = PEEK32(CURRENT_GATE); 134 gate = PEEK32(CURRENT_GATE);
138 if (enable) 135 if (enable) {
139 { 136 gate = FIELD_SET(gate, CURRENT_GATE, ZVPORT, ON);
140 gate = FIELD_SET(gate, CURRENT_GATE, ZVPORT, ON);
141#if 1 137#if 1
142 /* Using Software I2C */ 138 /* Using Software I2C */
143 gate = FIELD_SET(gate, CURRENT_GATE, GPIO, ON); 139 gate = FIELD_SET(gate, CURRENT_GATE, GPIO, ON);
144#else 140#else
145 /* Using Hardware I2C */ 141 /* Using Hardware I2C */
146 gate = FIELD_SET(gate, CURRENT_GATE, I2C, ON); 142 gate = FIELD_SET(gate, CURRENT_GATE, I2C, ON);
147#endif 143#endif
148 } 144 } else {
149 else 145 /* Disable ZV Port Gate. There is no way to know whether the
150 { 146 GPIO pins are being used or not. Therefore, do not disable the
151 /* Disable ZV Port Gate. There is no way to know whether the GPIO pins are being used 147 GPIO gate. */
152 or not. Therefore, do not disable the GPIO gate. */ 148 gate = FIELD_SET(gate, CURRENT_GATE, ZVPORT, OFF);
153 gate = FIELD_SET(gate, CURRENT_GATE, ZVPORT, OFF); 149 }
154 } 150
155 151 setCurrentGate(gate);
156 setCurrentGate(gate);
157} 152}
158 153
159 154
160void enableSSP(unsigned int enable) 155void enableSSP(unsigned int enable)
161{ 156{
162 uint32_t gate; 157 uint32_t gate;
163 158
164 /* Enable SSP Gate */ 159 /* Enable SSP Gate */
165 gate = PEEK32(CURRENT_GATE); 160 gate = PEEK32(CURRENT_GATE);
166 if (enable) 161 if (enable)
167 gate = FIELD_SET(gate, CURRENT_GATE, SSP, ON); 162 gate = FIELD_SET(gate, CURRENT_GATE, SSP, ON);
168 else 163 else
169 gate = FIELD_SET(gate, CURRENT_GATE, SSP, OFF); 164 gate = FIELD_SET(gate, CURRENT_GATE, SSP, OFF);
170 165
171 setCurrentGate(gate); 166 setCurrentGate(gate);
172} 167}
173 168
174void enableDMA(unsigned int enable) 169void enableDMA(unsigned int enable)
175{ 170{
176 uint32_t gate; 171 uint32_t gate;
177 172
178 /* Enable DMA Gate */ 173 /* Enable DMA Gate */
179 gate = PEEK32(CURRENT_GATE); 174 gate = PEEK32(CURRENT_GATE);
180 if (enable) 175 if (enable)
181 gate = FIELD_SET(gate, CURRENT_GATE, DMA, ON); 176 gate = FIELD_SET(gate, CURRENT_GATE, DMA, ON);
182 else 177 else
183 gate = FIELD_SET(gate, CURRENT_GATE, DMA, OFF); 178 gate = FIELD_SET(gate, CURRENT_GATE, DMA, OFF);
184 179
185 setCurrentGate(gate); 180 setCurrentGate(gate);
186} 181}
187 182
188/* 183/*
@@ -190,16 +185,16 @@ void enableDMA(unsigned int enable)
190 */ 185 */
191void enableGPIO(unsigned int enable) 186void enableGPIO(unsigned int enable)
192{ 187{
193 uint32_t gate; 188 uint32_t gate;
194 189
195 /* Enable GPIO Gate */ 190 /* Enable GPIO Gate */
196 gate = PEEK32(CURRENT_GATE); 191 gate = PEEK32(CURRENT_GATE);
197 if (enable) 192 if (enable)
198 gate = FIELD_SET(gate, CURRENT_GATE, GPIO, ON); 193 gate = FIELD_SET(gate, CURRENT_GATE, GPIO, ON);
199 else 194 else
200 gate = FIELD_SET(gate, CURRENT_GATE, GPIO, OFF); 195 gate = FIELD_SET(gate, CURRENT_GATE, GPIO, OFF);
201 196
202 setCurrentGate(gate); 197 setCurrentGate(gate);
203} 198}
204 199
205/* 200/*
@@ -207,16 +202,16 @@ void enableGPIO(unsigned int enable)
207 */ 202 */
208void enablePWM(unsigned int enable) 203void enablePWM(unsigned int enable)
209{ 204{
210 uint32_t gate; 205 uint32_t gate;
211 206
212 /* Enable PWM Gate */ 207 /* Enable PWM Gate */
213 gate = PEEK32(CURRENT_GATE); 208 gate = PEEK32(CURRENT_GATE);
214 if (enable) 209 if (enable)
215 gate = FIELD_SET(gate, CURRENT_GATE, PWM, ON); 210 gate = FIELD_SET(gate, CURRENT_GATE, PWM, ON);
216 else 211 else
217 gate = FIELD_SET(gate, CURRENT_GATE, PWM, OFF); 212 gate = FIELD_SET(gate, CURRENT_GATE, PWM, OFF);
218 213
219 setCurrentGate(gate); 214 setCurrentGate(gate);
220} 215}
221 216
222/* 217/*
@@ -224,16 +219,16 @@ void enablePWM(unsigned int enable)
224 */ 219 */
225void enableI2C(unsigned int enable) 220void enableI2C(unsigned int enable)
226{ 221{
227 uint32_t gate; 222 uint32_t gate;
228 223
229 /* Enable I2C Gate */ 224 /* Enable I2C Gate */
230 gate = PEEK32(CURRENT_GATE); 225 gate = PEEK32(CURRENT_GATE);
231 if (enable) 226 if (enable)
232 gate = FIELD_SET(gate, CURRENT_GATE, I2C, ON); 227 gate = FIELD_SET(gate, CURRENT_GATE, I2C, ON);
233 else 228 else
234 gate = FIELD_SET(gate, CURRENT_GATE, I2C, OFF); 229 gate = FIELD_SET(gate, CURRENT_GATE, I2C, OFF);
235 230
236 setCurrentGate(gate); 231 setCurrentGate(gate);
237} 232}
238 233
239 234
diff --git a/drivers/staging/sm750fb/ddk750_power.h b/drivers/staging/sm750fb/ddk750_power.h
index 4e00955a07dd..b7cf6b281fb6 100644
--- a/drivers/staging/sm750fb/ddk750_power.h
+++ b/drivers/staging/sm750fb/ddk750_power.h
@@ -1,12 +1,11 @@
1#ifndef DDK750_POWER_H__ 1#ifndef DDK750_POWER_H__
2#define DDK750_POWER_H__ 2#define DDK750_POWER_H__
3 3
4typedef enum _DPMS_t 4typedef enum _DPMS_t {
5{ 5 crtDPMS_ON = 0x0,
6 crtDPMS_ON = 0x0, 6 crtDPMS_STANDBY = 0x1,
7 crtDPMS_STANDBY = 0x1, 7 crtDPMS_SUSPEND = 0x2,
8 crtDPMS_SUSPEND = 0x2, 8 crtDPMS_OFF = 0x3,
9 crtDPMS_OFF = 0x3,
10} 9}
11DPMS_t; 10DPMS_t;
12 11
diff --git a/drivers/staging/sm750fb/ddk750_reg.h b/drivers/staging/sm750fb/ddk750_reg.h
index 1a40dc2a2f75..2995625c3d62 100644
--- a/drivers/staging/sm750fb/ddk750_reg.h
+++ b/drivers/staging/sm750fb/ddk750_reg.h
@@ -1640,9 +1640,9 @@
1640/* CRT Graphics Control */ 1640/* CRT Graphics Control */
1641 1641
1642#define CRT_DISPLAY_CTRL 0x080200 1642#define CRT_DISPLAY_CTRL 0x080200
1643#define CRT_DISPLAY_CTRL_RESERVED_1_MASK 31:27 1643#define CRT_DISPLAY_CTRL_RESERVED_1_MASK 31:27
1644#define CRT_DISPLAY_CTRL_RESERVED_1_MASK_DISABLE 0 1644#define CRT_DISPLAY_CTRL_RESERVED_1_MASK_DISABLE 0
1645#define CRT_DISPLAY_CTRL_RESERVED_1_MASK_ENABLE 0x1F 1645#define CRT_DISPLAY_CTRL_RESERVED_1_MASK_ENABLE 0x1F
1646 1646
1647/* SM750LE definition */ 1647/* SM750LE definition */
1648#define CRT_DISPLAY_CTRL_DPMS 31:30 1648#define CRT_DISPLAY_CTRL_DPMS 31:30
@@ -1664,9 +1664,9 @@
1664#define CRT_DISPLAY_CTRL_SHIFT_VGA_DAC_ENABLE 0 1664#define CRT_DISPLAY_CTRL_SHIFT_VGA_DAC_ENABLE 0
1665 1665
1666 1666
1667#define CRT_DISPLAY_CTRL_RESERVED_2_MASK 25:24 1667#define CRT_DISPLAY_CTRL_RESERVED_2_MASK 25:24
1668#define CRT_DISPLAY_CTRL_RESERVED_2_MASK_ENABLE 3 1668#define CRT_DISPLAY_CTRL_RESERVED_2_MASK_ENABLE 3
1669#define CRT_DISPLAY_CTRL_RESERVED_2_MASK_DISABLE 0 1669#define CRT_DISPLAY_CTRL_RESERVED_2_MASK_DISABLE 0
1670 1670
1671/* SM750LE definition */ 1671/* SM750LE definition */
1672#define CRT_DISPLAY_CTRL_CRTSELECT 25:25 1672#define CRT_DISPLAY_CTRL_CRTSELECT 25:25
@@ -1677,11 +1677,11 @@
1677#define CRT_DISPLAY_CTRL_RGBBIT_12BIT 1 1677#define CRT_DISPLAY_CTRL_RGBBIT_12BIT 1
1678 1678
1679 1679
1680#define CRT_DISPLAY_CTRL_RESERVED_3_MASK 15:15 1680#define CRT_DISPLAY_CTRL_RESERVED_3_MASK 15:15
1681#define CRT_DISPLAY_CTRL_RESERVED_3_MASK_DISABLE 0 1681#define CRT_DISPLAY_CTRL_RESERVED_3_MASK_DISABLE 0
1682#define CRT_DISPLAY_CTRL_RESERVED_3_MASK_ENABLE 1 1682#define CRT_DISPLAY_CTRL_RESERVED_3_MASK_ENABLE 1
1683 1683
1684#define CRT_DISPLAY_CTRL_RESERVED_4_MASK 9:9 1684#define CRT_DISPLAY_CTRL_RESERVED_4_MASK 9:9
1685#define CRT_DISPLAY_CTRL_RESERVED_4_MASK_DISABLE 0 1685#define CRT_DISPLAY_CTRL_RESERVED_4_MASK_DISABLE 0
1686#define CRT_DISPLAY_CTRL_RESERVED_4_MASK_ENABLE 1 1686#define CRT_DISPLAY_CTRL_RESERVED_4_MASK_ENABLE 1
1687 1687
@@ -1882,7 +1882,7 @@
1882#endif 1882#endif
1883 1883
1884/* sm750le new register to control panel output */ 1884/* sm750le new register to control panel output */
1885#define DISPLAY_CONTROL_750LE 0x80288 1885#define DISPLAY_CONTROL_750LE 0x80288
1886/* Palette RAM */ 1886/* Palette RAM */
1887 1887
1888/* Panel Palette register starts at 0x080400 ~ 0x0807FC */ 1888/* Panel Palette register starts at 0x080400 ~ 0x0807FC */
diff --git a/drivers/staging/sm750fb/ddk750_sii164.c b/drivers/staging/sm750fb/ddk750_sii164.c
index b6395b87fc21..0bdf3db11df0 100644
--- a/drivers/staging/sm750fb/ddk750_sii164.c
+++ b/drivers/staging/sm750fb/ddk750_sii164.c
@@ -36,12 +36,12 @@ static char *gDviCtrlChipName = "Silicon Image SiI 164";
36 */ 36 */
37unsigned short sii164GetVendorID(void) 37unsigned short sii164GetVendorID(void)
38{ 38{
39 unsigned short vendorID; 39 unsigned short vendorID;
40 40
41 vendorID = ((unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_VENDOR_ID_HIGH) << 8) | 41 vendorID = ((unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_VENDOR_ID_HIGH) << 8) |
42 (unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_VENDOR_ID_LOW); 42 (unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_VENDOR_ID_LOW);
43 43
44 return vendorID; 44 return vendorID;
45} 45}
46 46
47/* 47/*
@@ -53,12 +53,12 @@ unsigned short sii164GetVendorID(void)
53 */ 53 */
54unsigned short sii164GetDeviceID(void) 54unsigned short sii164GetDeviceID(void)
55{ 55{
56 unsigned short deviceID; 56 unsigned short deviceID;
57 57
58 deviceID = ((unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_DEVICE_ID_HIGH) << 8) | 58 deviceID = ((unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_DEVICE_ID_HIGH) << 8) |
59 (unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_DEVICE_ID_LOW); 59 (unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_DEVICE_ID_LOW);
60 60
61 return deviceID; 61 return deviceID;
62} 62}
63 63
64 64
@@ -113,132 +113,130 @@ unsigned short sii164GetDeviceID(void)
113 * -1 - Fail. 113 * -1 - Fail.
114 */ 114 */
115long sii164InitChip( 115long sii164InitChip(
116 unsigned char edgeSelect, 116 unsigned char edgeSelect,
117 unsigned char busSelect, 117 unsigned char busSelect,
118 unsigned char dualEdgeClkSelect, 118 unsigned char dualEdgeClkSelect,
119 unsigned char hsyncEnable, 119 unsigned char hsyncEnable,
120 unsigned char vsyncEnable, 120 unsigned char vsyncEnable,
121 unsigned char deskewEnable, 121 unsigned char deskewEnable,
122 unsigned char deskewSetting, 122 unsigned char deskewSetting,
123 unsigned char continuousSyncEnable, 123 unsigned char continuousSyncEnable,
124 unsigned char pllFilterEnable, 124 unsigned char pllFilterEnable,
125 unsigned char pllFilterValue 125 unsigned char pllFilterValue
126) 126)
127{ 127{
128 unsigned char config; 128 unsigned char config;
129 129
130 /* Initialize the i2c bus */ 130 /* Initialize the i2c bus */
131#ifdef USE_HW_I2C 131#ifdef USE_HW_I2C
132 /* Use fast mode. */ 132 /* Use fast mode. */
133 hwI2CInit(1); 133 hwI2CInit(1);
134#else 134#else
135 swI2CInit(DEFAULT_I2C_SCL, DEFAULT_I2C_SDA); 135 swI2CInit(DEFAULT_I2C_SCL, DEFAULT_I2C_SDA);
136#endif 136#endif
137 137
138 /* Check if SII164 Chip exists */ 138 /* Check if SII164 Chip exists */
139 if ((sii164GetVendorID() == SII164_VENDOR_ID) && (sii164GetDeviceID() == SII164_DEVICE_ID)) 139 if ((sii164GetVendorID() == SII164_VENDOR_ID) && (sii164GetDeviceID() == SII164_DEVICE_ID)) {
140 { 140 /*
141 /* 141 * Initialize SII164 controller chip.
142 * Initialize SII164 controller chip. 142 */
143 */ 143
144 144 /* Select the edge */
145 /* Select the edge */ 145 if (edgeSelect == 0)
146 if (edgeSelect == 0) 146 config = SII164_CONFIGURATION_LATCH_FALLING;
147 config = SII164_CONFIGURATION_LATCH_FALLING; 147 else
148 else 148 config = SII164_CONFIGURATION_LATCH_RISING;
149 config = SII164_CONFIGURATION_LATCH_RISING; 149
150 150 /* Select bus wide */
151 /* Select bus wide */ 151 if (busSelect == 0)
152 if (busSelect == 0) 152 config |= SII164_CONFIGURATION_BUS_12BITS;
153 config |= SII164_CONFIGURATION_BUS_12BITS; 153 else
154 else 154 config |= SII164_CONFIGURATION_BUS_24BITS;
155 config |= SII164_CONFIGURATION_BUS_24BITS; 155
156 156 /* Select Dual/Single Edge Clock */
157 /* Select Dual/Single Edge Clock */ 157 if (dualEdgeClkSelect == 0)
158 if (dualEdgeClkSelect == 0) 158 config |= SII164_CONFIGURATION_CLOCK_SINGLE;
159 config |= SII164_CONFIGURATION_CLOCK_SINGLE; 159 else
160 else 160 config |= SII164_CONFIGURATION_CLOCK_DUAL;
161 config |= SII164_CONFIGURATION_CLOCK_DUAL; 161
162 162 /* Select HSync Enable */
163 /* Select HSync Enable */ 163 if (hsyncEnable == 0)
164 if (hsyncEnable == 0) 164 config |= SII164_CONFIGURATION_HSYNC_FORCE_LOW;
165 config |= SII164_CONFIGURATION_HSYNC_FORCE_LOW; 165 else
166 else 166 config |= SII164_CONFIGURATION_HSYNC_AS_IS;
167 config |= SII164_CONFIGURATION_HSYNC_AS_IS; 167
168 168 /* Select VSync Enable */
169 /* Select VSync Enable */ 169 if (vsyncEnable == 0)
170 if (vsyncEnable == 0) 170 config |= SII164_CONFIGURATION_VSYNC_FORCE_LOW;
171 config |= SII164_CONFIGURATION_VSYNC_FORCE_LOW; 171 else
172 else 172 config |= SII164_CONFIGURATION_VSYNC_AS_IS;
173 config |= SII164_CONFIGURATION_VSYNC_AS_IS; 173
174 174 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config);
175 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config); 175
176 176 /* De-skew enabled with default 111b value.
177 /* De-skew enabled with default 111b value. 177 This will fix some artifacts problem in some mode on board 2.2.
178 This will fix some artifacts problem in some mode on board 2.2. 178 Somehow this fix does not affect board 2.1.
179 Somehow this fix does not affect board 2.1. 179 */
180 */ 180 if (deskewEnable == 0)
181 if (deskewEnable == 0) 181 config = SII164_DESKEW_DISABLE;
182 config = SII164_DESKEW_DISABLE; 182 else
183 else 183 config = SII164_DESKEW_ENABLE;
184 config = SII164_DESKEW_ENABLE; 184
185 185 switch (deskewSetting) {
186 switch (deskewSetting) 186 case 0:
187 { 187 config |= SII164_DESKEW_1_STEP;
188 case 0: 188 break;
189 config |= SII164_DESKEW_1_STEP; 189 case 1:
190 break; 190 config |= SII164_DESKEW_2_STEP;
191 case 1: 191 break;
192 config |= SII164_DESKEW_2_STEP; 192 case 2:
193 break; 193 config |= SII164_DESKEW_3_STEP;
194 case 2: 194 break;
195 config |= SII164_DESKEW_3_STEP; 195 case 3:
196 break; 196 config |= SII164_DESKEW_4_STEP;
197 case 3: 197 break;
198 config |= SII164_DESKEW_4_STEP; 198 case 4:
199 break; 199 config |= SII164_DESKEW_5_STEP;
200 case 4: 200 break;
201 config |= SII164_DESKEW_5_STEP; 201 case 5:
202 break; 202 config |= SII164_DESKEW_6_STEP;
203 case 5: 203 break;
204 config |= SII164_DESKEW_6_STEP; 204 case 6:
205 break; 205 config |= SII164_DESKEW_7_STEP;
206 case 6: 206 break;
207 config |= SII164_DESKEW_7_STEP; 207 case 7:
208 break; 208 config |= SII164_DESKEW_8_STEP;
209 case 7: 209 break;
210 config |= SII164_DESKEW_8_STEP; 210 }
211 break; 211 i2cWriteReg(SII164_I2C_ADDRESS, SII164_DESKEW, config);
212 } 212
213 i2cWriteReg(SII164_I2C_ADDRESS, SII164_DESKEW, config); 213 /* Enable/Disable Continuous Sync. */
214 214 if (continuousSyncEnable == 0)
215 /* Enable/Disable Continuous Sync. */ 215 config = SII164_PLL_FILTER_SYNC_CONTINUOUS_DISABLE;
216 if (continuousSyncEnable == 0) 216 else
217 config = SII164_PLL_FILTER_SYNC_CONTINUOUS_DISABLE; 217 config = SII164_PLL_FILTER_SYNC_CONTINUOUS_ENABLE;
218 else 218
219 config = SII164_PLL_FILTER_SYNC_CONTINUOUS_ENABLE; 219 /* Enable/Disable PLL Filter */
220 220 if (pllFilterEnable == 0)
221 /* Enable/Disable PLL Filter */ 221 config |= SII164_PLL_FILTER_DISABLE;
222 if (pllFilterEnable == 0) 222 else
223 config |= SII164_PLL_FILTER_DISABLE; 223 config |= SII164_PLL_FILTER_ENABLE;
224 else 224
225 config |= SII164_PLL_FILTER_ENABLE; 225 /* Set the PLL Filter value */
226 226 config |= ((pllFilterValue & 0x07) << 1);
227 /* Set the PLL Filter value */ 227
228 config |= ((pllFilterValue & 0x07) << 1); 228 i2cWriteReg(SII164_I2C_ADDRESS, SII164_PLL, config);
229 229
230 i2cWriteReg(SII164_I2C_ADDRESS, SII164_PLL, config); 230 /* Recover from Power Down and enable output. */
231 231 config = i2cReadReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION);
232 /* Recover from Power Down and enable output. */ 232 config |= SII164_CONFIGURATION_POWER_NORMAL;
233 config = i2cReadReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION); 233 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config);
234 config |= SII164_CONFIGURATION_POWER_NORMAL; 234
235 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config); 235 return 0;
236 236 }
237 return 0; 237
238 } 238 /* Return -1 if initialization fails. */
239 239 return (-1);
240 /* Return -1 if initialization fails. */
241 return (-1);
242} 240}
243 241
244 242
@@ -255,9 +253,9 @@ long sii164InitChip(
255 */ 253 */
256void sii164ResetChip(void) 254void sii164ResetChip(void)
257{ 255{
258 /* Power down */ 256 /* Power down */
259 sii164SetPower(0); 257 sii164SetPower(0);
260 sii164SetPower(1); 258 sii164SetPower(1);
261} 259}
262 260
263 261
@@ -268,7 +266,7 @@ void sii164ResetChip(void)
268 */ 266 */
269char *sii164GetChipString(void) 267char *sii164GetChipString(void)
270{ 268{
271 return gDviCtrlChipName; 269 return gDviCtrlChipName;
272} 270}
273 271
274 272
@@ -280,26 +278,23 @@ char *sii164GetChipString(void)
280 * powerUp - Flag to set the power down or up 278 * powerUp - Flag to set the power down or up
281 */ 279 */
282void sii164SetPower( 280void sii164SetPower(
283 unsigned char powerUp 281 unsigned char powerUp
284) 282)
285{ 283{
286 unsigned char config; 284 unsigned char config;
287 285
288 config = i2cReadReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION); 286 config = i2cReadReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION);
289 if (powerUp == 1) 287 if (powerUp == 1) {
290 { 288 /* Power up the chip */
291 /* Power up the chip */ 289 config &= ~SII164_CONFIGURATION_POWER_MASK;
292 config &= ~SII164_CONFIGURATION_POWER_MASK; 290 config |= SII164_CONFIGURATION_POWER_NORMAL;
293 config |= SII164_CONFIGURATION_POWER_NORMAL; 291 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config);
294 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config); 292 } else {
295 } 293 /* Power down the chip */
296 else 294 config &= ~SII164_CONFIGURATION_POWER_MASK;
297 { 295 config |= SII164_CONFIGURATION_POWER_DOWN;
298 /* Power down the chip */ 296 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config);
299 config &= ~SII164_CONFIGURATION_POWER_MASK; 297 }
300 config |= SII164_CONFIGURATION_POWER_DOWN;
301 i2cWriteReg(SII164_I2C_ADDRESS, SII164_CONFIGURATION, config);
302 }
303} 298}
304 299
305 300
@@ -308,31 +303,30 @@ void sii164SetPower(
308 * This function selects the mode of the hot plug detection. 303 * This function selects the mode of the hot plug detection.
309 */ 304 */
310static void sii164SelectHotPlugDetectionMode( 305static void sii164SelectHotPlugDetectionMode(
311 sii164_hot_plug_mode_t hotPlugMode 306 sii164_hot_plug_mode_t hotPlugMode
312) 307)
313{ 308{
314 unsigned char detectReg; 309 unsigned char detectReg;
315 310
316 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT) & ~SII164_DETECT_MONITOR_SENSE_OUTPUT_FLAG; 311 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT) & ~SII164_DETECT_MONITOR_SENSE_OUTPUT_FLAG;
317 switch (hotPlugMode) 312 switch (hotPlugMode) {
318 { 313 case SII164_HOTPLUG_DISABLE:
319 case SII164_HOTPLUG_DISABLE: 314 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_HIGH;
320 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_HIGH; 315 break;
321 break; 316 case SII164_HOTPLUG_USE_MDI:
322 case SII164_HOTPLUG_USE_MDI: 317 detectReg &= ~SII164_DETECT_INTERRUPT_MASK;
323 detectReg &= ~SII164_DETECT_INTERRUPT_MASK; 318 detectReg |= SII164_DETECT_INTERRUPT_BY_HTPLG_PIN;
324 detectReg |= SII164_DETECT_INTERRUPT_BY_HTPLG_PIN; 319 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_MDI;
325 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_MDI; 320 break;
326 break; 321 case SII164_HOTPLUG_USE_RSEN:
327 case SII164_HOTPLUG_USE_RSEN: 322 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_RSEN;
328 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_RSEN; 323 break;
329 break; 324 case SII164_HOTPLUG_USE_HTPLG:
330 case SII164_HOTPLUG_USE_HTPLG: 325 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_HTPLG;
331 detectReg |= SII164_DETECT_MONITOR_SENSE_OUTPUT_HTPLG; 326 break;
332 break; 327 }
333 } 328
334 329 i2cWriteReg(SII164_I2C_ADDRESS, SII164_DETECT, detectReg);
335 i2cWriteReg(SII164_I2C_ADDRESS, SII164_DETECT, detectReg);
336} 330}
337 331
338/* 332/*
@@ -342,18 +336,19 @@ static void sii164SelectHotPlugDetectionMode(
342 * enableHotPlug - Enable (=1) / disable (=0) Hot Plug detection 336 * enableHotPlug - Enable (=1) / disable (=0) Hot Plug detection
343 */ 337 */
344void sii164EnableHotPlugDetection( 338void sii164EnableHotPlugDetection(
345 unsigned char enableHotPlug 339 unsigned char enableHotPlug
346) 340)
347{ 341{
348 unsigned char detectReg; 342 unsigned char detectReg;
349 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT); 343
350 344 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT);
351 /* Depending on each DVI controller, need to enable the hot plug based on each 345
352 individual chip design. */ 346 /* Depending on each DVI controller, need to enable the hot plug based on each
353 if (enableHotPlug != 0) 347 individual chip design. */
354 sii164SelectHotPlugDetectionMode(SII164_HOTPLUG_USE_MDI); 348 if (enableHotPlug != 0)
355 else 349 sii164SelectHotPlugDetectionMode(SII164_HOTPLUG_USE_MDI);
356 sii164SelectHotPlugDetectionMode(SII164_HOTPLUG_DISABLE); 350 else
351 sii164SelectHotPlugDetectionMode(SII164_HOTPLUG_DISABLE);
357} 352}
358 353
359/* 354/*
@@ -366,13 +361,13 @@ void sii164EnableHotPlugDetection(
366 */ 361 */
367unsigned char sii164IsConnected(void) 362unsigned char sii164IsConnected(void)
368{ 363{
369 unsigned char hotPlugValue; 364 unsigned char hotPlugValue;
370 365
371 hotPlugValue = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT) & SII164_DETECT_HOT_PLUG_STATUS_MASK; 366 hotPlugValue = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT) & SII164_DETECT_HOT_PLUG_STATUS_MASK;
372 if (hotPlugValue == SII164_DETECT_HOT_PLUG_STATUS_ON) 367 if (hotPlugValue == SII164_DETECT_HOT_PLUG_STATUS_ON)
373 return 1; 368 return 1;
374 else 369 else
375 return 0; 370 return 0;
376} 371}
377 372
378/* 373/*
@@ -385,13 +380,13 @@ unsigned char sii164IsConnected(void)
385 */ 380 */
386unsigned char sii164CheckInterrupt(void) 381unsigned char sii164CheckInterrupt(void)
387{ 382{
388 unsigned char detectReg; 383 unsigned char detectReg;
389 384
390 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT) & SII164_DETECT_MONITOR_STATE_MASK; 385 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT) & SII164_DETECT_MONITOR_STATE_MASK;
391 if (detectReg == SII164_DETECT_MONITOR_STATE_CHANGE) 386 if (detectReg == SII164_DETECT_MONITOR_STATE_CHANGE)
392 return 1; 387 return 1;
393 else 388 else
394 return 0; 389 return 0;
395} 390}
396 391
397/* 392/*
@@ -400,11 +395,11 @@ unsigned char sii164CheckInterrupt(void)
400 */ 395 */
401void sii164ClearInterrupt(void) 396void sii164ClearInterrupt(void)
402{ 397{
403 unsigned char detectReg; 398 unsigned char detectReg;
404 399
405 /* Clear the MDI interrupt */ 400 /* Clear the MDI interrupt */
406 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT); 401 detectReg = i2cReadReg(SII164_I2C_ADDRESS, SII164_DETECT);
407 i2cWriteReg(SII164_I2C_ADDRESS, SII164_DETECT, detectReg | SII164_DETECT_MONITOR_STATE_CLEAR); 402 i2cWriteReg(SII164_I2C_ADDRESS, SII164_DETECT, detectReg | SII164_DETECT_MONITOR_STATE_CLEAR);
408} 403}
409 404
410#endif 405#endif
diff --git a/drivers/staging/sm750fb/ddk750_sii164.h b/drivers/staging/sm750fb/ddk750_sii164.h
index 2b4c7d3381df..f2610c90eeb4 100644
--- a/drivers/staging/sm750fb/ddk750_sii164.h
+++ b/drivers/staging/sm750fb/ddk750_sii164.h
@@ -4,27 +4,26 @@
4#define USE_DVICHIP 4#define USE_DVICHIP
5 5
6/* Hot Plug detection mode structure */ 6/* Hot Plug detection mode structure */
7typedef enum _sii164_hot_plug_mode_t 7typedef enum _sii164_hot_plug_mode_t {
8{ 8 SII164_HOTPLUG_DISABLE = 0, /* Disable Hot Plug output bit (always high). */
9 SII164_HOTPLUG_DISABLE = 0, /* Disable Hot Plug output bit (always high). */ 9 SII164_HOTPLUG_USE_MDI, /* Use Monitor Detect Interrupt bit. */
10 SII164_HOTPLUG_USE_MDI, /* Use Monitor Detect Interrupt bit. */ 10 SII164_HOTPLUG_USE_RSEN, /* Use Receiver Sense detect bit. */
11 SII164_HOTPLUG_USE_RSEN, /* Use Receiver Sense detect bit. */ 11 SII164_HOTPLUG_USE_HTPLG /* Use Hot Plug detect bit. */
12 SII164_HOTPLUG_USE_HTPLG /* Use Hot Plug detect bit. */
13} sii164_hot_plug_mode_t; 12} sii164_hot_plug_mode_t;
14 13
15 14
16/* Silicon Image SiI164 chip prototype */ 15/* Silicon Image SiI164 chip prototype */
17long sii164InitChip( 16long sii164InitChip(
18 unsigned char edgeSelect, 17 unsigned char edgeSelect,
19 unsigned char busSelect, 18 unsigned char busSelect,
20 unsigned char dualEdgeClkSelect, 19 unsigned char dualEdgeClkSelect,
21 unsigned char hsyncEnable, 20 unsigned char hsyncEnable,
22 unsigned char vsyncEnable, 21 unsigned char vsyncEnable,
23 unsigned char deskewEnable, 22 unsigned char deskewEnable,
24 unsigned char deskewSetting, 23 unsigned char deskewSetting,
25 unsigned char continuousSyncEnable, 24 unsigned char continuousSyncEnable,
26 unsigned char pllFilterEnable, 25 unsigned char pllFilterEnable,
27 unsigned char pllFilterValue 26 unsigned char pllFilterValue
28); 27);
29 28
30unsigned short sii164GetVendorID(void); 29unsigned short sii164GetVendorID(void);
diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c
index 8e201f19cc0d..07f8afd2defe 100644
--- a/drivers/staging/sm750fb/sm750.c
+++ b/drivers/staging/sm750fb/sm750.c
@@ -24,8 +24,7 @@
24 24
25#include "modedb.h" 25#include "modedb.h"
26 26
27int smi_indent = 0; 27int smi_indent;
28
29 28
30/* 29/*
31 * #ifdef __BIG_ENDIAN 30 * #ifdef __BIG_ENDIAN
@@ -40,17 +39,15 @@ typedef void (*PROC_SPEC_SETUP)(struct lynx_share*, char *);
40typedef int (*PROC_SPEC_MAP)(struct lynx_share*, struct pci_dev*); 39typedef int (*PROC_SPEC_MAP)(struct lynx_share*, struct pci_dev*);
41typedef int (*PROC_SPEC_INITHW)(struct lynx_share*, struct pci_dev*); 40typedef int (*PROC_SPEC_INITHW)(struct lynx_share*, struct pci_dev*);
42 41
43
44/* common var for all device */ 42/* common var for all device */
45static int g_hwcursor = 1; 43static int g_hwcursor = 1;
46static int g_noaccel; 44static int g_noaccel;
47static int g_nomtrr; 45static int g_nomtrr;
48static const char *g_fbmode[] = {NULL, NULL}; 46static const char *g_fbmode[] = {NULL, NULL};
49static const char *g_def_fbmode = "800x600-16@60"; 47static const char *g_def_fbmode = "800x600-16@60";
50static char *g_settings = NULL; 48static char *g_settings;
51static int g_dualview; 49static int g_dualview;
52static char *g_option = NULL; 50static char *g_option;
53
54 51
55static const struct fb_videomode lynx750_ext[] = { 52static const struct fb_videomode lynx750_ext[] = {
56 /* 1024x600-60 VESA [1.71:1] */ 53 /* 1024x600-60 VESA [1.71:1] */
@@ -115,8 +112,6 @@ static const struct fb_videomode lynx750_ext[] = {
115}; 112};
116 113
117 114
118
119
120/* no hardware cursor supported under version 2.6.10, kernel bug */ 115/* no hardware cursor supported under version 2.6.10, kernel bug */
121static int lynxfb_ops_cursor(struct fb_info *info, struct fb_cursor *fbcursor) 116static int lynxfb_ops_cursor(struct fb_info *info, struct fb_cursor *fbcursor)
122{ 117{
@@ -149,18 +144,17 @@ static int lynxfb_ops_cursor(struct fb_info *info, struct fb_cursor *fbcursor)
149 /* get the 16bit color of kernel means */ 144 /* get the 16bit color of kernel means */
150 u16 fg, bg; 145 u16 fg, bg;
151 146
152 fg = ((info->cmap.red[fbcursor->image.fg_color] & 0xf800))| 147 fg = ((info->cmap.red[fbcursor->image.fg_color] & 0xf800)) |
153 ((info->cmap.green[fbcursor->image.fg_color] & 0xfc00) >> 5)| 148 ((info->cmap.green[fbcursor->image.fg_color] & 0xfc00) >> 5) |
154 ((info->cmap.blue[fbcursor->image.fg_color] & 0xf800) >> 11); 149 ((info->cmap.blue[fbcursor->image.fg_color] & 0xf800) >> 11);
155 150
156 bg = ((info->cmap.red[fbcursor->image.bg_color] & 0xf800))| 151 bg = ((info->cmap.red[fbcursor->image.bg_color] & 0xf800)) |
157 ((info->cmap.green[fbcursor->image.bg_color] & 0xfc00) >> 5)| 152 ((info->cmap.green[fbcursor->image.bg_color] & 0xfc00) >> 5) |
158 ((info->cmap.blue[fbcursor->image.bg_color] & 0xf800) >> 11); 153 ((info->cmap.blue[fbcursor->image.bg_color] & 0xf800) >> 11);
159 154
160 cursor->setColor(cursor, fg, bg); 155 cursor->setColor(cursor, fg, bg);
161 } 156 }
162 157
163
164 if (fbcursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) { 158 if (fbcursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
165 cursor->setData(cursor, 159 cursor->setData(cursor,
166 fbcursor->rop, 160 fbcursor->rop,
@@ -188,14 +182,17 @@ static void lynxfb_ops_fillrect(struct fb_info *info,
188 par = info->par; 182 par = info->par;
189 share = par->share; 183 share = par->share;
190 184
191 /* each time 2d function begin to work,below three variable always need 185 /*
192 * be set, seems we can put them together in some place */ 186 * each time 2d function begin to work,below three variable always need
187 * be set, seems we can put them together in some place
188 */
193 base = par->crtc.oScreen; 189 base = par->crtc.oScreen;
194 pitch = info->fix.line_length; 190 pitch = info->fix.line_length;
195 Bpp = info->var.bits_per_pixel >> 3; 191 Bpp = info->var.bits_per_pixel >> 3;
196 192
197 color = (Bpp == 1)?region->color:((u32 *)info->pseudo_palette)[region->color]; 193 color = (Bpp == 1) ? region->color :
198 rop = (region->rop != ROP_COPY) ? HW_ROP2_XOR:HW_ROP2_COPY; 194 ((u32 *)info->pseudo_palette)[region->color];
195 rop = (region->rop != ROP_COPY) ? HW_ROP2_XOR : HW_ROP2_COPY;
199 196
200 /* 197 /*
201 * If not use spin_lock,system will die if user load driver 198 * If not use spin_lock,system will die if user load driver
@@ -223,8 +220,10 @@ static void lynxfb_ops_copyarea(struct fb_info *info,
223 par = info->par; 220 par = info->par;
224 share = par->share; 221 share = par->share;
225 222
226 /* each time 2d function begin to work,below three variable always need 223 /*
227 * be set, seems we can put them together in some place */ 224 * each time 2d function begin to work,below three variable always need
225 * be set, seems we can put them together in some place
226 */
228 base = par->crtc.oScreen; 227 base = par->crtc.oScreen;
229 pitch = info->fix.line_length; 228 pitch = info->fix.line_length;
230 Bpp = info->var.bits_per_pixel >> 3; 229 Bpp = info->var.bits_per_pixel >> 3;
@@ -254,28 +253,29 @@ static void lynxfb_ops_imageblit(struct fb_info *info,
254 253
255 par = info->par; 254 par = info->par;
256 share = par->share; 255 share = par->share;
257 /* each time 2d function begin to work,below three variable always need 256 /*
258 * be set, seems we can put them together in some place */ 257 * each time 2d function begin to work,below three variable always need
258 * be set, seems we can put them together in some place
259 */
259 base = par->crtc.oScreen; 260 base = par->crtc.oScreen;
260 pitch = info->fix.line_length; 261 pitch = info->fix.line_length;
261 Bpp = info->var.bits_per_pixel >> 3; 262 Bpp = info->var.bits_per_pixel >> 3;
262 263
263 if (image->depth == 1) {
264 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
265 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
266 fgcol = ((u32 *)info->pseudo_palette)[image->fg_color];
267 bgcol = ((u32 *)info->pseudo_palette)[image->bg_color];
268 } else {
269 fgcol = image->fg_color;
270 bgcol = image->bg_color;
271 }
272 goto _do_work;
273 }
274 /* TODO: Implement hardware acceleration for image->depth > 1 */ 264 /* TODO: Implement hardware acceleration for image->depth > 1 */
275 cfb_imageblit(info, image); 265 if (image->depth != 1) {
276 return; 266 cfb_imageblit(info, image);
267 return;
268 }
269
270 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
271 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
272 fgcol = ((u32 *)info->pseudo_palette)[image->fg_color];
273 bgcol = ((u32 *)info->pseudo_palette)[image->bg_color];
274 } else {
275 fgcol = image->fg_color;
276 bgcol = image->bg_color;
277 }
277 278
278_do_work:
279 /* 279 /*
280 * If not use spin_lock, system will die if user load driver 280 * If not use spin_lock, system will die if user load driver
281 * and immediately unload driver frequently (dual) 281 * and immediately unload driver frequently (dual)
@@ -284,7 +284,7 @@ _do_work:
284 spin_lock(&share->slock); 284 spin_lock(&share->slock);
285 285
286 share->accel.de_imageblit(&share->accel, 286 share->accel.de_imageblit(&share->accel,
287 image->data, image->width>>3, 0, 287 image->data, image->width >> 3, 0,
288 base, pitch, Bpp, 288 base, pitch, Bpp,
289 image->dx, image->dy, 289 image->dx, image->dy,
290 image->width, image->height, 290 image->width, image->height,
@@ -298,18 +298,13 @@ static int lynxfb_ops_pan_display(struct fb_var_screeninfo *var,
298{ 298{
299 struct lynxfb_par *par; 299 struct lynxfb_par *par;
300 struct lynxfb_crtc *crtc; 300 struct lynxfb_crtc *crtc;
301 int ret;
302
303 301
304 if (!info) 302 if (!info)
305 return -EINVAL; 303 return -EINVAL;
306 304
307 ret = 0;
308 par = info->par; 305 par = info->par;
309 crtc = &par->crtc; 306 crtc = &par->crtc;
310 ret = crtc->proc_panDisplay(crtc, var, info); 307 return crtc->proc_panDisplay(crtc, var, info);
311
312 return ret;
313} 308}
314 309
315static int lynxfb_ops_set_par(struct fb_info *info) 310static int lynxfb_ops_set_par(struct fb_info *info)
@@ -340,9 +335,10 @@ static int lynxfb_ops_set_par(struct fb_info *info)
340 fix->line_length = line_length; 335 fix->line_length = line_length;
341 pr_info("fix->line_length = %d\n", fix->line_length); 336 pr_info("fix->line_length = %d\n", fix->line_length);
342 337
343 /* var->red,green,blue,transp are need to be set by driver 338 /*
339 * var->red,green,blue,transp are need to be set by driver
344 * and these data should be set before setcolreg routine 340 * and these data should be set before setcolreg routine
345 * */ 341 */
346 342
347 switch (var->bits_per_pixel) { 343 switch (var->bits_per_pixel) {
348 case 8: 344 case 8:
@@ -466,7 +462,6 @@ static int lynxfb_resume(struct pci_dev *pdev)
466 462
467 int ret; 463 int ret;
468 464
469
470 ret = 0; 465 ret = 0;
471 share = pci_get_drvdata(pdev); 466 share = pci_get_drvdata(pdev);
472 467
@@ -478,7 +473,6 @@ static int lynxfb_resume(struct pci_dev *pdev)
478 return ret; 473 return ret;
479 } 474 }
480 475
481
482 if (pdev->dev.power.power_state.event != PM_EVENT_FREEZE) { 476 if (pdev->dev.power.power_state.event != PM_EVENT_FREEZE) {
483 pci_restore_state(pdev); 477 pci_restore_state(pdev);
484 ret = pci_enable_device(pdev); 478 ret = pci_enable_device(pdev);
@@ -493,7 +487,6 @@ static int lynxfb_resume(struct pci_dev *pdev)
493 487
494 hw_sm750_inithw(share, pdev); 488 hw_sm750_inithw(share, pdev);
495 489
496
497 info = share->fbinfo[0]; 490 info = share->fbinfo[0];
498 491
499 if (info) { 492 if (info) {
@@ -518,7 +511,6 @@ static int lynxfb_resume(struct pci_dev *pdev)
518 fb_set_suspend(info, 0); 511 fb_set_suspend(info, 0);
519 } 512 }
520 513
521
522 console_unlock(); 514 console_unlock();
523 return ret; 515 return ret;
524} 516}
@@ -534,7 +526,6 @@ static int lynxfb_ops_check_var(struct fb_var_screeninfo *var,
534 int ret; 526 int ret;
535 resource_size_t request; 527 resource_size_t request;
536 528
537
538 par = info->par; 529 par = info->par;
539 crtc = &par->crtc; 530 crtc = &par->crtc;
540 output = &par->output; 531 output = &par->output;
@@ -546,7 +537,6 @@ static int lynxfb_ops_check_var(struct fb_var_screeninfo *var,
546 var->yres, 537 var->yres,
547 var->bits_per_pixel); 538 var->bits_per_pixel);
548 539
549
550 switch (var->bits_per_pixel) { 540 switch (var->bits_per_pixel) {
551 case 8: 541 case 8:
552 case 16: 542 case 16:
@@ -617,7 +607,6 @@ exit:
617 return ret; 607 return ret;
618} 608}
619 609
620
621static int lynxfb_ops_setcolreg(unsigned regno, 610static int lynxfb_ops_setcolreg(unsigned regno,
622 unsigned red, 611 unsigned red,
623 unsigned green, 612 unsigned green,
@@ -652,7 +641,6 @@ static int lynxfb_ops_setcolreg(unsigned regno,
652 goto exit; 641 goto exit;
653 } 642 }
654 643
655
656 if (info->fix.visual == FB_VISUAL_TRUECOLOR && regno < 256) { 644 if (info->fix.visual == FB_VISUAL_TRUECOLOR && regno < 256) {
657 u32 val; 645 u32 val;
658 646
@@ -699,7 +687,8 @@ static int sm750fb_set_drv(struct lynxfb_par *par)
699 output = &par->output; 687 output = &par->output;
700 crtc = &par->crtc; 688 crtc = &par->crtc;
701 689
702 crtc->vidmem_size = (share->dual)?share->vidmem_size>>1:share->vidmem_size; 690 crtc->vidmem_size = (share->dual) ? share->vidmem_size >> 1 :
691 share->vidmem_size;
703 /* setup crtc and output member */ 692 /* setup crtc and output member */
704 spec_share->hwCursor = g_hwcursor; 693 spec_share->hwCursor = g_hwcursor;
705 694
@@ -716,10 +705,12 @@ static int sm750fb_set_drv(struct lynxfb_par *par)
716 output->proc_setMode = hw_sm750_output_setMode; 705 output->proc_setMode = hw_sm750_output_setMode;
717 output->proc_checkMode = hw_sm750_output_checkMode; 706 output->proc_checkMode = hw_sm750_output_checkMode;
718 707
719 output->proc_setBLANK = (share->revid == SM750LE_REVISION_ID)?hw_sm750le_setBLANK:hw_sm750_setBLANK; 708 output->proc_setBLANK = (share->revid == SM750LE_REVISION_ID) ?
709 hw_sm750le_setBLANK : hw_sm750_setBLANK;
720 output->clear = hw_sm750_output_clear; 710 output->clear = hw_sm750_output_clear;
721 /* chip specific phase */ 711 /* chip specific phase */
722 share->accel.de_wait = (share->revid == SM750LE_REVISION_ID)?hw_sm750le_deWait : hw_sm750_deWait; 712 share->accel.de_wait = (share->revid == SM750LE_REVISION_ID) ?
713 hw_sm750le_deWait : hw_sm750_deWait;
723 switch (spec_share->state.dataflow) { 714 switch (spec_share->state.dataflow) {
724 case sm750_simul_pri: 715 case sm750_simul_pri:
725 output->paths = sm750_pnc; 716 output->paths = sm750_pnc;
@@ -782,7 +773,6 @@ static struct fb_ops lynxfb_ops = {
782 .fb_cursor = lynxfb_ops_cursor, 773 .fb_cursor = lynxfb_ops_cursor,
783}; 774};
784 775
785
786static int lynxfb_set_fbinfo(struct fb_info *info, int index) 776static int lynxfb_set_fbinfo(struct fb_info *info, int index)
787{ 777{
788 int i; 778 int i;
@@ -803,7 +793,6 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
803 "kernel HELPERS prepared vesa_modes", 793 "kernel HELPERS prepared vesa_modes",
804 }; 794 };
805 795
806
807 static const char *fixId[2] = { 796 static const char *fixId[2] = {
808 "sm750_fb1", "sm750_fb2", 797 "sm750_fb1", "sm750_fb2",
809 }; 798 };
@@ -824,15 +813,16 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
824 sm750fb_set_drv(par); 813 sm750fb_set_drv(par);
825 lynxfb_ops.fb_pan_display = lynxfb_ops_pan_display; 814 lynxfb_ops.fb_pan_display = lynxfb_ops_pan_display;
826 815
827 816 /*
828 /* set current cursor variable and proc pointer, 817 * set current cursor variable and proc pointer,
829 * must be set after crtc member initialized */ 818 * must be set after crtc member initialized
819 */
830 crtc->cursor.offset = crtc->oScreen + crtc->vidmem_size - 1024; 820 crtc->cursor.offset = crtc->oScreen + crtc->vidmem_size - 1024;
831 crtc->cursor.mmio = share->pvReg + 0x800f0 + (int)crtc->channel * 0x140; 821 crtc->cursor.mmio = share->pvReg + 0x800f0 + (int)crtc->channel * 0x140;
832 822
833 pr_info("crtc->cursor.mmio = %p\n", crtc->cursor.mmio); 823 pr_info("crtc->cursor.mmio = %p\n", crtc->cursor.mmio);
834 crtc->cursor.maxH = crtc->cursor.maxW = 64; 824 crtc->cursor.maxH = crtc->cursor.maxW = 64;
835 crtc->cursor.size = crtc->cursor.maxH*crtc->cursor.maxW*2/8; 825 crtc->cursor.size = crtc->cursor.maxH * crtc->cursor.maxW * 2 / 8;
836 crtc->cursor.disable = hw_cursor_disable; 826 crtc->cursor.disable = hw_cursor_disable;
837 crtc->cursor.enable = hw_cursor_enable; 827 crtc->cursor.enable = hw_cursor_enable;
838 crtc->cursor.setColor = hw_cursor_setColor; 828 crtc->cursor.setColor = hw_cursor_setColor;
@@ -841,7 +831,6 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
841 crtc->cursor.setData = hw_cursor_setData; 831 crtc->cursor.setData = hw_cursor_setData;
842 crtc->cursor.vstart = share->pvMem + crtc->cursor.offset; 832 crtc->cursor.vstart = share->pvMem + crtc->cursor.offset;
843 833
844
845 crtc->cursor.share = share; 834 crtc->cursor.share = share;
846 memset_io(crtc->cursor.vstart, 0, crtc->cursor.size); 835 memset_io(crtc->cursor.vstart, 0, crtc->cursor.size);
847 if (!g_hwcursor) { 836 if (!g_hwcursor) {
@@ -849,7 +838,6 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
849 crtc->cursor.disable(&crtc->cursor); 838 crtc->cursor.disable(&crtc->cursor);
850 } 839 }
851 840
852
853 /* set info->fbops, must be set before fb_find_mode */ 841 /* set info->fbops, must be set before fb_find_mode */
854 if (!share->accel_off) { 842 if (!share->accel_off) {
855 /* use 2d acceleration */ 843 /* use 2d acceleration */
@@ -865,7 +853,6 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
865 g_fbmode[index] = g_fbmode[0]; 853 g_fbmode[index] = g_fbmode[0];
866 } 854 }
867 855
868
869 for (i = 0; i < 3; i++) { 856 for (i = 0; i < 3; i++) {
870 857
871 ret = fb_find_mode(var, info, g_fbmode[index], 858 ret = fb_find_mode(var, info, g_fbmode[index],
@@ -917,13 +904,13 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
917 904
918 /* set info */ 905 /* set info */
919 line_length = PADDING(crtc->line_pad, 906 line_length = PADDING(crtc->line_pad,
920 (var->xres_virtual * var->bits_per_pixel/8)); 907 (var->xres_virtual * var->bits_per_pixel / 8));
921 908
922 info->pseudo_palette = &par->pseudo_palette[0]; 909 info->pseudo_palette = &par->pseudo_palette[0];
923 info->screen_base = crtc->vScreen; 910 info->screen_base = crtc->vScreen;
924 pr_debug("screen_base vaddr = %p\n", info->screen_base); 911 pr_debug("screen_base vaddr = %p\n", info->screen_base);
925 info->screen_size = line_length * var->yres_virtual; 912 info->screen_size = line_length * var->yres_virtual;
926 info->flags = FBINFO_FLAG_DEFAULT|0; 913 info->flags = FBINFO_FLAG_DEFAULT | 0;
927 914
928 /* set info->fix */ 915 /* set info->fix */
929 fix->type = FB_TYPE_PACKED_PIXELS; 916 fix->type = FB_TYPE_PACKED_PIXELS;
@@ -935,15 +922,15 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
935 922
936 strlcpy(fix->id, fixId[index], sizeof(fix->id)); 923 strlcpy(fix->id, fixId[index], sizeof(fix->id));
937 924
938
939 fix->smem_start = crtc->oScreen + share->vidmem_start; 925 fix->smem_start = crtc->oScreen + share->vidmem_start;
940 pr_info("fix->smem_start = %lx\n", fix->smem_start); 926 pr_info("fix->smem_start = %lx\n", fix->smem_start);
941 /* according to mmap experiment from user space application, 927 /*
928 * according to mmap experiment from user space application,
942 * fix->mmio_len should not larger than virtual size 929 * fix->mmio_len should not larger than virtual size
943 * (xres_virtual x yres_virtual x ByPP) 930 * (xres_virtual x yres_virtual x ByPP)
944 * Below line maybe buggy when user mmap fb dev node and write 931 * Below line maybe buggy when user mmap fb dev node and write
945 * data into the bound over virtual size 932 * data into the bound over virtual size
946 * */ 933 */
947 fix->smem_len = crtc->vidmem_size; 934 fix->smem_len = crtc->vidmem_size;
948 pr_info("fix->smem_len = %x\n", fix->smem_len); 935 pr_info("fix->smem_len = %x\n", fix->smem_len);
949 info->screen_size = fix->smem_len; 936 info->screen_size = fix->smem_len;
@@ -967,7 +954,7 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
967 var->accel_flags = 0; 954 var->accel_flags = 0;
968 var->vmode = FB_VMODE_NONINTERLACED; 955 var->vmode = FB_VMODE_NONINTERLACED;
969 956
970 pr_debug("#1 show info->cmap : \nstart=%d,len=%d,red=%p,green=%p,blue=%p,transp=%p\n", 957 pr_debug("#1 show info->cmap :\nstart=%d,len=%d,red=%p,green=%p,blue=%p,transp=%p\n",
971 info->cmap.start, info->cmap.len, 958 info->cmap.start, info->cmap.len,
972 info->cmap.red, info->cmap.green, info->cmap.blue, 959 info->cmap.red, info->cmap.green, info->cmap.blue,
973 info->cmap.transp); 960 info->cmap.transp);
@@ -998,7 +985,6 @@ static void sm750fb_setup(struct lynx_share *share, char *src)
998#endif 985#endif
999 int swap; 986 int swap;
1000 987
1001
1002 spec_share = container_of(share, struct sm750_share, share); 988 spec_share = container_of(share, struct sm750_share, share);
1003#ifdef CAP_EXPENSIION 989#ifdef CAP_EXPENSIION
1004 exp_res = NULL; 990 exp_res = NULL;
@@ -1096,15 +1082,16 @@ static int lynxfb_pci_probe(struct pci_dev *pdev,
1096 size_t spec_offset = 0; 1082 size_t spec_offset = 0;
1097 int fbidx; 1083 int fbidx;
1098 1084
1099
1100 /* enable device */ 1085 /* enable device */
1101 if (pci_enable_device(pdev)) { 1086 if (pci_enable_device(pdev)) {
1102 pr_err("can not enable device.\n"); 1087 pr_err("can not enable device.\n");
1103 goto err_enable; 1088 goto err_enable;
1104 } 1089 }
1105 1090
1106 /* though offset of share in sm750_share is 0, 1091 /*
1107 * we use this marcro as the same */ 1092 * though offset of share in sm750_share is 0,
1093 * we use this marcro as the same
1094 */
1108 spec_offset = offsetof(struct sm750_share, share); 1095 spec_offset = offsetof(struct sm750_share, share);
1109 1096
1110 spec_share = kzalloc(sizeof(*spec_share), GFP_KERNEL); 1097 spec_share = kzalloc(sizeof(*spec_share), GFP_KERNEL);
@@ -1128,10 +1115,12 @@ static int lynxfb_pci_probe(struct pci_dev *pdev,
1128 spin_lock_init(&share->slock); 1115 spin_lock_init(&share->slock);
1129 1116
1130 if (!share->accel_off) { 1117 if (!share->accel_off) {
1131 /* hook deInit and 2d routines, notes that below hw_xxx 1118 /*
1119 * hook deInit and 2d routines, notes that below hw_xxx
1132 * routine can work on most of lynx chips 1120 * routine can work on most of lynx chips
1133 * if some chip need specific function, 1121 * if some chip need specific function,
1134 * please hook it in smXXX_set_drv routine */ 1122 * please hook it in smXXX_set_drv routine
1123 */
1135 share->accel.de_init = hw_de_init; 1124 share->accel.de_init = hw_de_init;
1136 share->accel.de_fillrect = hw_fillrect; 1125 share->accel.de_fillrect = hw_fillrect;
1137 share->accel.de_copyarea = hw_copyarea; 1126 share->accel.de_copyarea = hw_copyarea;
@@ -1268,7 +1257,6 @@ static int __init lynxfb_setup(char *options)
1268 int len; 1257 int len;
1269 char *opt, *tmp; 1258 char *opt, *tmp;
1270 1259
1271
1272 if (!options || !*options) { 1260 if (!options || !*options) {
1273 pr_warn("no options.\n"); 1261 pr_warn("no options.\n");
1274 return 0; 1262 return 0;
@@ -1283,14 +1271,15 @@ static int __init lynxfb_setup(char *options)
1283 1271
1284 tmp = g_settings; 1272 tmp = g_settings;
1285 1273
1286 /* Notes: 1274 /*
1287 char * strsep(char **s,const char * ct); 1275 * Notes:
1288 @s: the string to be searched 1276 * char * strsep(char **s,const char * ct);
1289 @ct :the characters to search for 1277 * @s: the string to be searched
1290 1278 * @ct :the characters to search for
1291 strsep() updates @options to pointer after the first found token 1279 *
1292 it also returns the pointer ahead the token. 1280 * strsep() updates @options to pointer after the first found token
1293 */ 1281 * it also returns the pointer ahead the token.
1282 */
1294 while ((opt = strsep(&options, ":")) != NULL) { 1283 while ((opt = strsep(&options, ":")) != NULL) {
1295 /* options that mean for any lynx chips are configured here */ 1284 /* options that mean for any lynx chips are configured here */
1296 if (!strncmp(opt, "noaccel", strlen("noaccel"))) 1285 if (!strncmp(opt, "noaccel", strlen("noaccel")))
@@ -1332,7 +1321,6 @@ static struct pci_driver lynxfb_driver = {
1332#endif 1321#endif
1333}; 1322};
1334 1323
1335
1336static int __init lynxfb_init(void) 1324static int __init lynxfb_init(void)
1337{ 1325{
1338 char *option; 1326 char *option;
diff --git a/drivers/staging/sm750fb/sm750.h b/drivers/staging/sm750fb/sm750.h
index cc80580bc823..5bc445571b48 100644
--- a/drivers/staging/sm750fb/sm750.h
+++ b/drivers/staging/sm750fb/sm750.h
@@ -5,20 +5,20 @@
5 5
6#define FB_ACCEL_SMI 0xab 6#define FB_ACCEL_SMI 0xab
7/* please use revision id to distinguish sm750le and sm750*/ 7/* please use revision id to distinguish sm750le and sm750*/
8#define SPC_SM750 0 8#define SPC_SM750 0
9 9
10#define MB(x) ((x)<<20) 10#define MB(x) ((x)<<20)
11#define MHZ(x) ((x) * 1000000) 11#define MHZ(x) ((x) * 1000000)
12/* align should be 2,4,8,16 */ 12/* align should be 2,4,8,16 */
13#define PADDING(align, data) (((data)+(align)-1)&(~((align) -1))) 13#define PADDING(align, data) (((data)+(align)-1)&(~((align) - 1)))
14extern int smi_indent; 14extern int smi_indent;
15 15
16 16
17struct lynx_accel{ 17struct lynx_accel {
18 /* base virtual address of DPR registers */ 18 /* base virtual address of DPR registers */
19 volatile unsigned char __iomem * dprBase; 19 volatile unsigned char __iomem *dprBase;
20 /* base virtual address of de data port */ 20 /* base virtual address of de data port */
21 volatile unsigned char __iomem * dpPortBase; 21 volatile unsigned char __iomem *dpPortBase;
22 22
23 /* function fointers */ 23 /* function fointers */
24 void (*de_init)(struct lynx_accel *); 24 void (*de_init)(struct lynx_accel *);
@@ -38,10 +38,10 @@ struct lynx_accel{
38 38
39}; 39};
40 40
41/* lynx_share stands for a presentation of two frame buffer 41/* lynx_share stands for a presentation of two frame buffer
42 that use one smi adaptor , it is similar to a basic class of C++ 42 that use one smi adaptor , it is similar to a basic class of C++
43*/ 43*/
44struct lynx_share{ 44struct lynx_share {
45 /* common members */ 45 /* common members */
46 u16 devid; 46 u16 devid;
47 u8 revid; 47 u8 revid;
@@ -53,7 +53,7 @@ struct lynx_share{
53 int mtrr_off; 53 int mtrr_off;
54 struct{ 54 struct{
55 int vram; 55 int vram;
56 }mtrr; 56 } mtrr;
57 /* all smi graphic adaptor got below attributes */ 57 /* all smi graphic adaptor got below attributes */
58 unsigned long vidmem_start; 58 unsigned long vidmem_start;
59 unsigned long vidreg_start; 59 unsigned long vidreg_start;
@@ -64,11 +64,11 @@ struct lynx_share{
64 /* locks*/ 64 /* locks*/
65 spinlock_t slock; 65 spinlock_t slock;
66 /* function pointers */ 66 /* function pointers */
67 void (*suspend)(struct lynx_share*); 67 void (*suspend)(struct lynx_share *);
68 void (*resume)(struct lynx_share*); 68 void (*resume)(struct lynx_share *);
69}; 69};
70 70
71struct lynx_cursor{ 71struct lynx_cursor {
72 /* cursor width ,height and size */ 72 /* cursor width ,height and size */
73 int w; 73 int w;
74 int h; 74 int h;
@@ -80,7 +80,7 @@ struct lynx_cursor{
80 char __iomem *vstart; 80 char __iomem *vstart;
81 int offset; 81 int offset;
82 /* mmio addr of hw cursor */ 82 /* mmio addr of hw cursor */
83 volatile char __iomem * mmio; 83 volatile char __iomem *mmio;
84 /* the lynx_share of this adaptor */ 84 /* the lynx_share of this adaptor */
85 struct lynx_share *share; 85 struct lynx_share *share;
86 /* proc_routines */ 86 /* proc_routines */
@@ -92,7 +92,7 @@ struct lynx_cursor{
92 void (*setData)(struct lynx_cursor *, u16, const u8*, const u8*); 92 void (*setData)(struct lynx_cursor *, u16, const u8*, const u8*);
93}; 93};
94 94
95struct lynxfb_crtc{ 95struct lynxfb_crtc {
96 unsigned char __iomem *vCursor; /* virtual address of cursor */ 96 unsigned char __iomem *vCursor; /* virtual address of cursor */
97 unsigned char __iomem *vScreen; /* virtual address of on_screen */ 97 unsigned char __iomem *vScreen; /* virtual address of on_screen */
98 int oCursor; /* cursor address offset in vidmem */ 98 int oCursor; /* cursor address offset in vidmem */
@@ -108,14 +108,14 @@ struct lynxfb_crtc{
108 108
109 void *priv; 109 void *priv;
110 110
111 int(*proc_setMode)(struct lynxfb_crtc*, 111 int (*proc_setMode)(struct lynxfb_crtc*,
112 struct fb_var_screeninfo*, 112 struct fb_var_screeninfo*,
113 struct fb_fix_screeninfo*); 113 struct fb_fix_screeninfo*);
114 114
115 int(*proc_checkMode)(struct lynxfb_crtc*, struct fb_var_screeninfo*); 115 int (*proc_checkMode)(struct lynxfb_crtc*, struct fb_var_screeninfo*);
116 int(*proc_setColReg)(struct lynxfb_crtc*, ushort, ushort, ushort, ushort); 116 int (*proc_setColReg)(struct lynxfb_crtc*, ushort, ushort, ushort, ushort);
117 void (*clear)(struct lynxfb_crtc*); 117 void (*clear)(struct lynxfb_crtc *);
118 /* pan display */ 118 /* pan display */
119 int (*proc_panDisplay)(struct lynxfb_crtc *, 119 int (*proc_panDisplay)(struct lynxfb_crtc *,
120 const struct fb_var_screeninfo *, 120 const struct fb_var_screeninfo *,
121 const struct fb_info *); 121 const struct fb_info *);
@@ -123,33 +123,33 @@ struct lynxfb_crtc{
123 struct lynx_cursor cursor; 123 struct lynx_cursor cursor;
124}; 124};
125 125
126struct lynxfb_output{ 126struct lynxfb_output {
127 int dpms; 127 int dpms;
128 int paths; 128 int paths;
129 /* which paths(s) this output stands for,for sm750: 129 /* which paths(s) this output stands for,for sm750:
130 paths=1:means output for panel paths 130 paths=1:means output for panel paths
131 paths=2:means output for crt paths 131 paths=2:means output for crt paths
132 paths=3:means output for both panel and crt paths 132 paths=3:means output for both panel and crt paths
133 */ 133 */
134 134
135 int *channel; 135 int *channel;
136 /* which channel these outputs linked with,for sm750: 136 /* which channel these outputs linked with,for sm750:
137 *channel=0 means primary channel 137 *channel=0 means primary channel
138 *channel=1 means secondary channel 138 *channel=1 means secondary channel
139 output->channel ==> &crtc->channel 139 output->channel ==> &crtc->channel
140 */ 140 */
141 void *priv; 141 void *priv;
142 142
143 int(*proc_setMode)(struct lynxfb_output*, 143 int (*proc_setMode)(struct lynxfb_output*,
144 struct fb_var_screeninfo*, 144 struct fb_var_screeninfo*,
145 struct fb_fix_screeninfo*); 145 struct fb_fix_screeninfo*);
146 146
147 int(*proc_checkMode)(struct lynxfb_output*, struct fb_var_screeninfo*); 147 int (*proc_checkMode)(struct lynxfb_output*, struct fb_var_screeninfo*);
148 int(*proc_setBLANK)(struct lynxfb_output*, int); 148 int (*proc_setBLANK)(struct lynxfb_output*, int);
149 void (*clear)(struct lynxfb_output*); 149 void (*clear)(struct lynxfb_output *);
150}; 150};
151 151
152struct lynxfb_par{ 152struct lynxfb_par {
153 /* either 0 or 1 for dual head adaptor,0 is the older one registered */ 153 /* either 0 or 1 for dual head adaptor,0 is the older one registered */
154 int index; 154 int index;
155 unsigned int pseudo_palette[256]; 155 unsigned int pseudo_palette[256];
@@ -165,14 +165,14 @@ struct lynxfb_par{
165 165
166 166
167#define PS_TO_HZ(ps) \ 167#define PS_TO_HZ(ps) \
168 ({ \ 168 ({ \
169 unsigned long long hz = 1000*1000*1000*1000ULL; \ 169 unsigned long long hz = 1000*1000*1000*1000ULL; \
170 do_div(hz, ps); \ 170 do_div(hz, ps); \
171 (unsigned long)hz;}) 171 (unsigned long)hz; })
172 172
173static inline unsigned long ps_to_hz(unsigned int psvalue) 173static inline unsigned long ps_to_hz(unsigned int psvalue)
174{ 174{
175 unsigned long long numerator=1000*1000*1000*1000ULL; 175 unsigned long long numerator = 1000*1000*1000*1000ULL;
176 /* 10^12 / picosecond period gives frequency in Hz */ 176 /* 10^12 / picosecond period gives frequency in Hz */
177 do_div(numerator, psvalue); 177 do_div(numerator, psvalue);
178 return (unsigned long)numerator; 178 return (unsigned long)numerator;
diff --git a/drivers/staging/sm750fb/sm750_accel.c b/drivers/staging/sm750fb/sm750_accel.c
index 6eee4cd582d1..1dd06a2e4ede 100644
--- a/drivers/staging/sm750fb/sm750_accel.c
+++ b/drivers/staging/sm750fb/sm750_accel.c
@@ -37,7 +37,7 @@ void hw_de_init(struct lynx_accel *accel)
37{ 37{
38 /* setup 2d engine registers */ 38 /* setup 2d engine registers */
39 u32 reg, clr; 39 u32 reg, clr;
40 40
41 write_dpr(accel, DE_MASKS, 0xFFFFFFFF); 41 write_dpr(accel, DE_MASKS, 0xFFFFFFFF);
42 42
43 /* dpr1c */ 43 /* dpr1c */
@@ -82,7 +82,7 @@ void hw_de_init(struct lynx_accel *accel)
82void hw_set2dformat(struct lynx_accel *accel, int fmt) 82void hw_set2dformat(struct lynx_accel *accel, int fmt)
83{ 83{
84 u32 reg; 84 u32 reg;
85 85
86 /* fmt=0,1,2 for 8,16,32,bpp on sm718/750/502 */ 86 /* fmt=0,1,2 for 8,16,32,bpp on sm718/750/502 */
87 reg = read_dpr(accel, DE_STRETCH_FORMAT); 87 reg = read_dpr(accel, DE_STRETCH_FORMAT);
88 reg = FIELD_VALUE(reg, DE_STRETCH_FORMAT, PIXEL_FORMAT, fmt); 88 reg = FIELD_VALUE(reg, DE_STRETCH_FORMAT, PIXEL_FORMAT, fmt);
@@ -96,11 +96,10 @@ int hw_fillrect(struct lynx_accel *accel,
96{ 96{
97 u32 deCtrl; 97 u32 deCtrl;
98 98
99 if(accel->de_wait() != 0) 99 if (accel->de_wait() != 0) {
100 {
101 /* int time wait and always busy,seems hardware 100 /* int time wait and always busy,seems hardware
102 * got something error */ 101 * got something error */
103 pr_debug("%s:De engine always bussy\n", __func__); 102 pr_debug("De engine always busy\n");
104 return -1; 103 return -1;
105 } 104 }
106 105
@@ -151,112 +150,102 @@ unsigned int width,
151unsigned int height, /* width and height of rectangle in pixel value */ 150unsigned int height, /* width and height of rectangle in pixel value */
152unsigned int rop2) /* ROP value */ 151unsigned int rop2) /* ROP value */
153{ 152{
154 unsigned int nDirection, de_ctrl; 153 unsigned int nDirection, de_ctrl;
155 int opSign; 154 int opSign;
156 nDirection = LEFT_TO_RIGHT; 155
156 nDirection = LEFT_TO_RIGHT;
157 /* Direction of ROP2 operation: 1 = Left to Right, (-1) = Right to Left */ 157 /* Direction of ROP2 operation: 1 = Left to Right, (-1) = Right to Left */
158 opSign = 1; 158 opSign = 1;
159 de_ctrl = 0; 159 de_ctrl = 0;
160 160
161 /* If source and destination are the same surface, need to check for overlay cases */ 161 /* If source and destination are the same surface, need to check for overlay cases */
162 if (sBase == dBase && sPitch == dPitch) 162 if (sBase == dBase && sPitch == dPitch) {
163 { 163 /* Determine direction of operation */
164 /* Determine direction of operation */ 164 if (sy < dy) {
165 if (sy < dy) 165 /* +----------+
166 { 166 |S |
167 /* +----------+ 167 | +----------+
168 |S | 168 | | | |
169 | +----------+ 169 | | | |
170 | | | | 170 +---|------+ |
171 | | | | 171 | D|
172 +---|------+ | 172 +----------+ */
173 | D| 173
174 +----------+ */ 174 nDirection = BOTTOM_TO_TOP;
175 175 } else if (sy > dy) {
176 nDirection = BOTTOM_TO_TOP; 176 /* +----------+
177 } 177 |D |
178 else if (sy > dy) 178 | +----------+
179 { 179 | | | |
180 /* +----------+ 180 | | | |
181 |D | 181 +---|------+ |
182 | +----------+ 182 | S|
183 | | | | 183 +----------+ */
184 | | | | 184
185 +---|------+ | 185 nDirection = TOP_TO_BOTTOM;
186 | S| 186 } else {
187 +----------+ */ 187 /* sy == dy */
188 188
189 nDirection = TOP_TO_BOTTOM; 189 if (sx <= dx) {
190 } 190 /* +------+---+------+
191 else 191 |S | | D|
192 { 192 | | | |
193 /* sy == dy */ 193 | | | |
194 194 | | | |
195 if (sx <= dx) 195 +------+---+------+ */
196 { 196
197 /* +------+---+------+ 197 nDirection = RIGHT_TO_LEFT;
198 |S | | D| 198 } else {
199 | | | | 199 /* sx > dx */
200 | | | | 200
201 | | | | 201 /* +------+---+------+
202 +------+---+------+ */ 202 |D | | S|
203 203 | | | |
204 nDirection = RIGHT_TO_LEFT; 204 | | | |
205 } 205 | | | |
206 else 206 +------+---+------+ */
207 { 207
208 /* sx > dx */ 208 nDirection = LEFT_TO_RIGHT;
209 209 }
210 /* +------+---+------+ 210 }
211 |D | | S| 211 }
212 | | | |
213 | | | |
214 | | | |
215 +------+---+------+ */
216
217 nDirection = LEFT_TO_RIGHT;
218 }
219 }
220 }
221
222 if ((nDirection == BOTTOM_TO_TOP) || (nDirection == RIGHT_TO_LEFT))
223 {
224 sx += width - 1;
225 sy += height - 1;
226 dx += width - 1;
227 dy += height - 1;
228 opSign = (-1);
229 }
230
231 /* Note:
232 DE_FOREGROUND are DE_BACKGROUND are don't care.
233 DE_COLOR_COMPARE and DE_COLOR_COMPARE_MAKS are set by set deSetTransparency().
234 */
235 212
236 /* 2D Source Base. 213 if ((nDirection == BOTTOM_TO_TOP) || (nDirection == RIGHT_TO_LEFT)) {
237 It is an address offset (128 bit aligned) from the beginning of frame buffer. 214 sx += width - 1;
238 */ 215 sy += height - 1;
239 write_dpr(accel, DE_WINDOW_SOURCE_BASE, sBase); /* dpr40 */ 216 dx += width - 1;
217 dy += height - 1;
218 opSign = (-1);
219 }
240 220
241 /* 2D Destination Base. 221 /* Note:
242 It is an address offset (128 bit aligned) from the beginning of frame buffer. 222 DE_FOREGROUND are DE_BACKGROUND are don't care.
243 */ 223 DE_COLOR_COMPARE and DE_COLOR_COMPARE_MAKS are set by set deSetTransparency().
244 write_dpr(accel, DE_WINDOW_DESTINATION_BASE, dBase); /* dpr44 */ 224 */
225
226 /* 2D Source Base.
227 It is an address offset (128 bit aligned) from the beginning of frame buffer.
228 */
229 write_dpr(accel, DE_WINDOW_SOURCE_BASE, sBase); /* dpr40 */
230
231 /* 2D Destination Base.
232 It is an address offset (128 bit aligned) from the beginning of frame buffer.
233 */
234 write_dpr(accel, DE_WINDOW_DESTINATION_BASE, dBase); /* dpr44 */
245 235
246#if 0 236#if 0
247 /* Program pitch (distance between the 1st points of two adjacent lines). 237 /* Program pitch (distance between the 1st points of two adjacent lines).
248 Note that input pitch is BYTE value, but the 2D Pitch register uses 238 Note that input pitch is BYTE value, but the 2D Pitch register uses
249 pixel values. Need Byte to pixel conversion. 239 pixel values. Need Byte to pixel conversion.
250 */ 240 */
251 if(Bpp == 3){ 241 if (Bpp == 3) {
252 sx *= 3; 242 sx *= 3;
253 dx *= 3; 243 dx *= 3;
254 width *= 3; 244 width *= 3;
255 write_dpr(accel, DE_PITCH, 245 write_dpr(accel, DE_PITCH,
256 FIELD_VALUE(0, DE_PITCH, DESTINATION, dPitch) | 246 FIELD_VALUE(0, DE_PITCH, DESTINATION, dPitch) |
257 FIELD_VALUE(0, DE_PITCH, SOURCE, sPitch)); /* dpr10 */ 247 FIELD_VALUE(0, DE_PITCH, SOURCE, sPitch)); /* dpr10 */
258 } 248 } else
259 else
260#endif 249#endif
261 { 250 {
262 write_dpr(accel, DE_PITCH, 251 write_dpr(accel, DE_PITCH,
@@ -267,54 +256,53 @@ unsigned int rop2) /* ROP value */
267 /* Screen Window width in Pixels. 256 /* Screen Window width in Pixels.
268 2D engine uses this value to calculate the linear address in frame buffer for a given point. 257 2D engine uses this value to calculate the linear address in frame buffer for a given point.
269 */ 258 */
270 write_dpr(accel, DE_WINDOW_WIDTH, 259 write_dpr(accel, DE_WINDOW_WIDTH,
271 FIELD_VALUE(0, DE_WINDOW_WIDTH, DESTINATION, (dPitch/Bpp)) | 260 FIELD_VALUE(0, DE_WINDOW_WIDTH, DESTINATION, (dPitch/Bpp)) |
272 FIELD_VALUE(0, DE_WINDOW_WIDTH, SOURCE, (sPitch/Bpp))); /* dpr3c */ 261 FIELD_VALUE(0, DE_WINDOW_WIDTH, SOURCE, (sPitch/Bpp))); /* dpr3c */
273 262
274 if (accel->de_wait() != 0){ 263 if (accel->de_wait() != 0)
275 return -1; 264 return -1;
265
266 {
267
268 write_dpr(accel, DE_SOURCE,
269 FIELD_SET(0, DE_SOURCE, WRAP, DISABLE) |
270 FIELD_VALUE(0, DE_SOURCE, X_K1, sx) |
271 FIELD_VALUE(0, DE_SOURCE, Y_K2, sy)); /* dpr0 */
272 write_dpr(accel, DE_DESTINATION,
273 FIELD_SET(0, DE_DESTINATION, WRAP, DISABLE) |
274 FIELD_VALUE(0, DE_DESTINATION, X, dx) |
275 FIELD_VALUE(0, DE_DESTINATION, Y, dy)); /* dpr04 */
276 write_dpr(accel, DE_DIMENSION,
277 FIELD_VALUE(0, DE_DIMENSION, X, width) |
278 FIELD_VALUE(0, DE_DIMENSION, Y_ET, height)); /* dpr08 */
279
280 de_ctrl = FIELD_VALUE(0, DE_CONTROL, ROP, rop2) |
281 FIELD_SET(0, DE_CONTROL, ROP_SELECT, ROP2) |
282 FIELD_SET(0, DE_CONTROL, COMMAND, BITBLT) |
283 ((nDirection == RIGHT_TO_LEFT) ?
284 FIELD_SET(0, DE_CONTROL, DIRECTION, RIGHT_TO_LEFT)
285 : FIELD_SET(0, DE_CONTROL, DIRECTION, LEFT_TO_RIGHT)) |
286 FIELD_SET(0, DE_CONTROL, STATUS, START);
287 write_dpr(accel, DE_CONTROL, de_ctrl); /* dpr0c */
288
276 } 289 }
277 290
278 { 291 return 0;
279
280 write_dpr(accel, DE_SOURCE,
281 FIELD_SET (0, DE_SOURCE, WRAP, DISABLE) |
282 FIELD_VALUE(0, DE_SOURCE, X_K1, sx) |
283 FIELD_VALUE(0, DE_SOURCE, Y_K2, sy)); /* dpr0 */
284 write_dpr(accel, DE_DESTINATION,
285 FIELD_SET (0, DE_DESTINATION, WRAP, DISABLE) |
286 FIELD_VALUE(0, DE_DESTINATION, X, dx) |
287 FIELD_VALUE(0, DE_DESTINATION, Y, dy)); /* dpr04 */
288 write_dpr(accel, DE_DIMENSION,
289 FIELD_VALUE(0, DE_DIMENSION, X, width) |
290 FIELD_VALUE(0, DE_DIMENSION, Y_ET, height)); /* dpr08 */
291
292 de_ctrl =
293 FIELD_VALUE(0, DE_CONTROL, ROP, rop2) |
294 FIELD_SET(0, DE_CONTROL, ROP_SELECT, ROP2) |
295 FIELD_SET(0, DE_CONTROL, COMMAND, BITBLT) |
296 ((nDirection == RIGHT_TO_LEFT) ?
297 FIELD_SET(0, DE_CONTROL, DIRECTION, RIGHT_TO_LEFT)
298 : FIELD_SET(0, DE_CONTROL, DIRECTION, LEFT_TO_RIGHT)) |
299 FIELD_SET(0, DE_CONTROL, STATUS, START);
300 write_dpr(accel, DE_CONTROL, de_ctrl); /* dpr0c */
301 }
302
303 return 0;
304} 292}
305 293
306static unsigned int deGetTransparency(struct lynx_accel *accel) 294static unsigned int deGetTransparency(struct lynx_accel *accel)
307{ 295{
308 unsigned int de_ctrl; 296 unsigned int de_ctrl;
309 297
310 de_ctrl = read_dpr(accel, DE_CONTROL); 298 de_ctrl = read_dpr(accel, DE_CONTROL);
311 299
312 de_ctrl &= 300 de_ctrl &=
313 FIELD_MASK(DE_CONTROL_TRANSPARENCY_MATCH) | 301 FIELD_MASK(DE_CONTROL_TRANSPARENCY_MATCH) |
314 FIELD_MASK(DE_CONTROL_TRANSPARENCY_SELECT)| 302 FIELD_MASK(DE_CONTROL_TRANSPARENCY_SELECT)|
315 FIELD_MASK(DE_CONTROL_TRANSPARENCY); 303 FIELD_MASK(DE_CONTROL_TRANSPARENCY);
316 304
317 return de_ctrl; 305 return de_ctrl;
318} 306}
319 307
320int hw_imageblit(struct lynx_accel *accel, 308int hw_imageblit(struct lynx_accel *accel,
@@ -332,38 +320,36 @@ int hw_imageblit(struct lynx_accel *accel,
332 u32 bColor, /* Background color (corresponding to a 0 in the monochrome data */ 320 u32 bColor, /* Background color (corresponding to a 0 in the monochrome data */
333 u32 rop2) /* ROP value */ 321 u32 rop2) /* ROP value */
334{ 322{
335 unsigned int ulBytesPerScan; 323 unsigned int ulBytesPerScan;
336 unsigned int ul4BytesPerScan; 324 unsigned int ul4BytesPerScan;
337 unsigned int ulBytesRemain; 325 unsigned int ulBytesRemain;
338 unsigned int de_ctrl = 0; 326 unsigned int de_ctrl = 0;
339 unsigned char ajRemain[4]; 327 unsigned char ajRemain[4];
340 int i, j; 328 int i, j;
341 329
342 startBit &= 7; /* Just make sure the start bit is within legal range */ 330 startBit &= 7; /* Just make sure the start bit is within legal range */
343 ulBytesPerScan = (width + startBit + 7) / 8; 331 ulBytesPerScan = (width + startBit + 7) / 8;
344 ul4BytesPerScan = ulBytesPerScan & ~3; 332 ul4BytesPerScan = ulBytesPerScan & ~3;
345 ulBytesRemain = ulBytesPerScan & 3; 333 ulBytesRemain = ulBytesPerScan & 3;
346 334
347 if(accel->de_wait() != 0) 335 if (accel->de_wait() != 0)
348 { 336 return -1;
349 return -1;
350 }
351
352 /* 2D Source Base.
353 Use 0 for HOST Blt.
354 */
355 write_dpr(accel, DE_WINDOW_SOURCE_BASE, 0);
356 337
357 /* 2D Destination Base. 338 /* 2D Source Base.
358 It is an address offset (128 bit aligned) from the beginning of frame buffer. 339 Use 0 for HOST Blt.
359 */ 340 */
360 write_dpr(accel, DE_WINDOW_DESTINATION_BASE, dBase); 341 write_dpr(accel, DE_WINDOW_SOURCE_BASE, 0);
342
343 /* 2D Destination Base.
344 It is an address offset (128 bit aligned) from the beginning of frame buffer.
345 */
346 write_dpr(accel, DE_WINDOW_DESTINATION_BASE, dBase);
361#if 0 347#if 0
362 /* Program pitch (distance between the 1st points of two adjacent lines). 348 /* Program pitch (distance between the 1st points of two adjacent lines).
363 Note that input pitch is BYTE value, but the 2D Pitch register uses 349 Note that input pitch is BYTE value, but the 2D Pitch register uses
364 pixel values. Need Byte to pixel conversion. 350 pixel values. Need Byte to pixel conversion.
365 */ 351 */
366 if(bytePerPixel == 3 ){ 352 if (bytePerPixel == 3) {
367 dx *= 3; 353 dx *= 3;
368 width *= 3; 354 width *= 3;
369 startBit *= 3; 355 startBit *= 3;
@@ -371,8 +357,7 @@ int hw_imageblit(struct lynx_accel *accel,
371 FIELD_VALUE(0, DE_PITCH, DESTINATION, dPitch) | 357 FIELD_VALUE(0, DE_PITCH, DESTINATION, dPitch) |
372 FIELD_VALUE(0, DE_PITCH, SOURCE, dPitch)); /* dpr10 */ 358 FIELD_VALUE(0, DE_PITCH, SOURCE, dPitch)); /* dpr10 */
373 359
374 } 360 } else
375 else
376#endif 361#endif
377 { 362 {
378 write_dpr(accel, DE_PITCH, 363 write_dpr(accel, DE_PITCH,
@@ -380,30 +365,30 @@ int hw_imageblit(struct lynx_accel *accel,
380 FIELD_VALUE(0, DE_PITCH, SOURCE, dPitch/bytePerPixel)); /* dpr10 */ 365 FIELD_VALUE(0, DE_PITCH, SOURCE, dPitch/bytePerPixel)); /* dpr10 */
381 } 366 }
382 367
383 /* Screen Window width in Pixels. 368 /* Screen Window width in Pixels.
384 2D engine uses this value to calculate the linear address in frame buffer for a given point. 369 2D engine uses this value to calculate the linear address in frame buffer for a given point.
385 */ 370 */
386 write_dpr(accel, DE_WINDOW_WIDTH, 371 write_dpr(accel, DE_WINDOW_WIDTH,
387 FIELD_VALUE(0, DE_WINDOW_WIDTH, DESTINATION, (dPitch/bytePerPixel)) | 372 FIELD_VALUE(0, DE_WINDOW_WIDTH, DESTINATION, (dPitch/bytePerPixel)) |
388 FIELD_VALUE(0, DE_WINDOW_WIDTH, SOURCE, (dPitch/bytePerPixel))); 373 FIELD_VALUE(0, DE_WINDOW_WIDTH, SOURCE, (dPitch/bytePerPixel)));
389 374
390 /* Note: For 2D Source in Host Write, only X_K1_MONO field is needed, and Y_K2 field is not used. 375 /* Note: For 2D Source in Host Write, only X_K1_MONO field is needed, and Y_K2 field is not used.
391 For mono bitmap, use startBit for X_K1. */ 376 For mono bitmap, use startBit for X_K1. */
392 write_dpr(accel, DE_SOURCE, 377 write_dpr(accel, DE_SOURCE,
393 FIELD_SET (0, DE_SOURCE, WRAP, DISABLE) | 378 FIELD_SET(0, DE_SOURCE, WRAP, DISABLE) |
394 FIELD_VALUE(0, DE_SOURCE, X_K1_MONO, startBit)); /* dpr00 */ 379 FIELD_VALUE(0, DE_SOURCE, X_K1_MONO, startBit)); /* dpr00 */
395 380
396 write_dpr(accel, DE_DESTINATION, 381 write_dpr(accel, DE_DESTINATION,
397 FIELD_SET (0, DE_DESTINATION, WRAP, DISABLE) | 382 FIELD_SET(0, DE_DESTINATION, WRAP, DISABLE) |
398 FIELD_VALUE(0, DE_DESTINATION, X, dx) | 383 FIELD_VALUE(0, DE_DESTINATION, X, dx) |
399 FIELD_VALUE(0, DE_DESTINATION, Y, dy)); /* dpr04 */ 384 FIELD_VALUE(0, DE_DESTINATION, Y, dy)); /* dpr04 */
400 385
401 write_dpr(accel, DE_DIMENSION, 386 write_dpr(accel, DE_DIMENSION,
402 FIELD_VALUE(0, DE_DIMENSION, X, width) | 387 FIELD_VALUE(0, DE_DIMENSION, X, width) |
403 FIELD_VALUE(0, DE_DIMENSION, Y_ET, height)); /* dpr08 */ 388 FIELD_VALUE(0, DE_DIMENSION, Y_ET, height)); /* dpr08 */
404 389
405 write_dpr(accel, DE_FOREGROUND, fColor); 390 write_dpr(accel, DE_FOREGROUND, fColor);
406 write_dpr(accel, DE_BACKGROUND, bColor); 391 write_dpr(accel, DE_BACKGROUND, bColor);
407 392
408 de_ctrl = FIELD_VALUE(0, DE_CONTROL, ROP, rop2) | 393 de_ctrl = FIELD_VALUE(0, DE_CONTROL, ROP, rop2) |
409 FIELD_SET(0, DE_CONTROL, ROP_SELECT, ROP2) | 394 FIELD_SET(0, DE_CONTROL, ROP_SELECT, ROP2) |
@@ -413,24 +398,20 @@ int hw_imageblit(struct lynx_accel *accel,
413 398
414 write_dpr(accel, DE_CONTROL, de_ctrl | deGetTransparency(accel)); 399 write_dpr(accel, DE_CONTROL, de_ctrl | deGetTransparency(accel));
415 400
416 /* Write MONO data (line by line) to 2D Engine data port */ 401 /* Write MONO data (line by line) to 2D Engine data port */
417 for (i=0; i<height; i++) 402 for (i = 0; i < height; i++) {
418 { 403 /* For each line, send the data in chunks of 4 bytes */
419 /* For each line, send the data in chunks of 4 bytes */ 404 for (j = 0; j < (ul4BytesPerScan/4); j++)
420 for (j=0; j<(ul4BytesPerScan/4); j++) 405 write_dpPort(accel, *(unsigned int *)(pSrcbuf + (j * 4)));
421 { 406
422 write_dpPort(accel, *(unsigned int *)(pSrcbuf + (j * 4))); 407 if (ulBytesRemain) {
423 } 408 memcpy(ajRemain, pSrcbuf+ul4BytesPerScan, ulBytesRemain);
424 409 write_dpPort(accel, *(unsigned int *)ajRemain);
425 if (ulBytesRemain) 410 }
426 { 411
427 memcpy(ajRemain, pSrcbuf+ul4BytesPerScan, ulBytesRemain); 412 pSrcbuf += srcDelta;
428 write_dpPort(accel, *(unsigned int *)ajRemain); 413 }
429 } 414
430 415 return 0;
431 pSrcbuf += srcDelta;
432 }
433
434 return 0;
435} 416}
436 417
diff --git a/drivers/staging/sm750fb/sm750_accel.h b/drivers/staging/sm750fb/sm750_accel.h
index d3d256c21206..f252e47d5ee9 100644
--- a/drivers/staging/sm750fb/sm750_accel.h
+++ b/drivers/staging/sm750fb/sm750_accel.h
@@ -7,7 +7,7 @@
7/* notes: below address are the offset value from de_base_address (0x100000)*/ 7/* notes: below address are the offset value from de_base_address (0x100000)*/
8 8
9/* for sm718/750/502 de_base is at mmreg_1mb*/ 9/* for sm718/750/502 de_base is at mmreg_1mb*/
10#define DE_BASE_ADDR_TYPE1 0x100000 10#define DE_BASE_ADDR_TYPE1 0x100000
11/* for sm712,de_base is at mmreg_32kb */ 11/* for sm712,de_base is at mmreg_32kb */
12#define DE_BASE_ADDR_TYPE2 0x8000 12#define DE_BASE_ADDR_TYPE2 0x8000
13/* for sm722,de_base is at mmreg_0 */ 13/* for sm722,de_base is at mmreg_0 */
@@ -26,7 +26,7 @@
26#define DE_SOURCE_WRAP_ENABLE 1 26#define DE_SOURCE_WRAP_ENABLE 1
27#define DE_SOURCE_X_K1 29:16 27#define DE_SOURCE_X_K1 29:16
28#define DE_SOURCE_Y_K2 15:0 28#define DE_SOURCE_Y_K2 15:0
29#define DE_SOURCE_X_K1_MONO 20:16 29#define DE_SOURCE_X_K1_MONO 20:16
30 30
31#define DE_DESTINATION 0x4 31#define DE_DESTINATION 0x4
32#define DE_DESTINATION_WRAP 31:31 32#define DE_DESTINATION_WRAP 31:31
diff --git a/drivers/staging/sm750fb/sm750_cursor.c b/drivers/staging/sm750fb/sm750_cursor.c
index 405e24b6768f..a94a4bbff450 100644
--- a/drivers/staging/sm750fb/sm750_cursor.c
+++ b/drivers/staging/sm750fb/sm750_cursor.c
@@ -61,6 +61,7 @@ writel((data), cursor->mmio + (addr))
61void hw_cursor_enable(struct lynx_cursor *cursor) 61void hw_cursor_enable(struct lynx_cursor *cursor)
62{ 62{
63 u32 reg; 63 u32 reg;
64
64 reg = FIELD_VALUE(0, HWC_ADDRESS, ADDRESS, cursor->offset)| 65 reg = FIELD_VALUE(0, HWC_ADDRESS, ADDRESS, cursor->offset)|
65 FIELD_SET(0, HWC_ADDRESS, EXT, LOCAL)| 66 FIELD_SET(0, HWC_ADDRESS, EXT, LOCAL)|
66 FIELD_SET(0, HWC_ADDRESS, ENABLE, ENABLE); 67 FIELD_SET(0, HWC_ADDRESS, ENABLE, ENABLE);
@@ -81,6 +82,7 @@ void hw_cursor_setPos(struct lynx_cursor *cursor,
81 int x, int y) 82 int x, int y)
82{ 83{
83 u32 reg; 84 u32 reg;
85
84 reg = FIELD_VALUE(0, HWC_LOCATION, Y, y)| 86 reg = FIELD_VALUE(0, HWC_LOCATION, Y, y)|
85 FIELD_VALUE(0, HWC_LOCATION, X, x); 87 FIELD_VALUE(0, HWC_LOCATION, X, x);
86 POKE32(HWC_LOCATION, reg); 88 POKE32(HWC_LOCATION, reg);
@@ -93,7 +95,7 @@ void hw_cursor_setColor(struct lynx_cursor *cursor,
93} 95}
94 96
95void hw_cursor_setData(struct lynx_cursor *cursor, 97void hw_cursor_setData(struct lynx_cursor *cursor,
96 u16 rop, const u8* pcol, const u8* pmsk) 98 u16 rop, const u8 *pcol, const u8 *pmsk)
97{ 99{
98 int i, j, count, pitch, offset; 100 int i, j, count, pitch, offset;
99 u8 color, mask, opr; 101 u8 color, mask, opr;
@@ -122,8 +124,7 @@ void hw_cursor_setData(struct lynx_cursor *cursor,
122 odd=0; 124 odd=0;
123*/ 125*/
124 126
125 for(i=0;i<count;i++) 127 for (i = 0; i < count; i++) {
126 {
127 color = *pcol++; 128 color = *pcol++;
128 mask = *pmsk++; 129 mask = *pmsk++;
129 data = 0; 130 data = 0;
@@ -132,26 +133,25 @@ void hw_cursor_setData(struct lynx_cursor *cursor,
132 * but method 2 shows no lag 133 * but method 2 shows no lag
133 * and method 1 seems a bit wrong*/ 134 * and method 1 seems a bit wrong*/
134#if 0 135#if 0
135 if(rop == ROP_XOR) 136 if (rop == ROP_XOR)
136 opr = mask ^ color; 137 opr = mask ^ color;
137 else 138 else
138 opr = mask & color; 139 opr = mask & color;
139 140
140 for(j=0;j<8;j++) 141 for (j = 0; j < 8; j++) {
141 {
142 142
143 if(opr & (0x80 >> j)) 143 if (opr & (0x80 >> j)) {
144 { /* use fg color,id = 2 */ 144 /* use fg color,id = 2 */
145 data |= 2 << (j*2); 145 data |= 2 << (j*2);
146 }else{ 146 } else {
147 /* use bg color,id = 1 */ 147 /* use bg color,id = 1 */
148 data |= 1 << (j*2); 148 data |= 1 << (j*2);
149 } 149 }
150 } 150 }
151#else 151#else
152 for(j=0;j<8;j++){ 152 for (j = 0; j < 8; j++) {
153 if(mask & (0x80>>j)){ 153 if (mask & (0x80>>j)) {
154 if(rop == ROP_XOR) 154 if (rop == ROP_XOR)
155 opr = mask ^ color; 155 opr = mask ^ color;
156 else 156 else
157 opr = mask & color; 157 opr = mask & color;
@@ -165,15 +165,15 @@ void hw_cursor_setData(struct lynx_cursor *cursor,
165 165
166 /* assume pitch is 1,2,4,8,...*/ 166 /* assume pitch is 1,2,4,8,...*/
167#if 0 167#if 0
168 if(!((i+1)&(pitch-1))) /* below line equal to is line */ 168 if (!((i+1)&(pitch-1))) /* below line equal to is line */
169#else 169#else
170 if((i+1) % pitch == 0) 170 if ((i+1) % pitch == 0)
171#endif 171#endif
172 { 172 {
173 /* need a return */ 173 /* need a return */
174 pstart += offset; 174 pstart += offset;
175 pbuffer = pstart; 175 pbuffer = pstart;
176 }else{ 176 } else {
177 pbuffer += sizeof(u16); 177 pbuffer += sizeof(u16);
178 } 178 }
179 179
@@ -184,7 +184,7 @@ void hw_cursor_setData(struct lynx_cursor *cursor,
184 184
185 185
186void hw_cursor_setData2(struct lynx_cursor *cursor, 186void hw_cursor_setData2(struct lynx_cursor *cursor,
187 u16 rop, const u8* pcol, const u8* pmsk) 187 u16 rop, const u8 *pcol, const u8 *pmsk)
188{ 188{
189 int i, j, count, pitch, offset; 189 int i, j, count, pitch, offset;
190 u8 color, mask; 190 u8 color, mask;
@@ -204,45 +204,42 @@ void hw_cursor_setData2(struct lynx_cursor *cursor,
204 pstart = cursor->vstart; 204 pstart = cursor->vstart;
205 pbuffer = pstart; 205 pbuffer = pstart;
206 206
207 for(i=0;i<count;i++) 207 for (i = 0; i < count; i++) {
208 {
209 color = *pcol++; 208 color = *pcol++;
210 mask = *pmsk++; 209 mask = *pmsk++;
211 data = 0; 210 data = 0;
212 211
213 /* either method below works well, but method 2 shows no lag */ 212 /* either method below works well, but method 2 shows no lag */
214#if 0 213#if 0
215 if(rop == ROP_XOR) 214 if (rop == ROP_XOR)
216 opr = mask ^ color; 215 opr = mask ^ color;
217 else 216 else
218 opr = mask & color; 217 opr = mask & color;
219 218
220 for(j=0;j<8;j++) 219 for (j = 0; j < 8; j++) {
221 {
222 220
223 if(opr & (0x80 >> j)) 221 if (opr & (0x80 >> j)) {
224 { /* use fg color,id = 2 */ 222 /* use fg color,id = 2 */
225 data |= 2 << (j*2); 223 data |= 2 << (j*2);
226 }else{ 224 } else {
227 /* use bg color,id = 1 */ 225 /* use bg color,id = 1 */
228 data |= 1 << (j*2); 226 data |= 1 << (j*2);
229 } 227 }
230 } 228 }
231#else 229#else
232 for(j=0;j<8;j++){ 230 for (j = 0; j < 8; j++) {
233 if(mask & (1<<j)) 231 if (mask & (1<<j))
234 data |= ((color & (1<<j))?1:2)<<(j*2); 232 data |= ((color & (1<<j))?1:2)<<(j*2);
235 } 233 }
236#endif 234#endif
237 iowrite16(data, pbuffer); 235 iowrite16(data, pbuffer);
238 236
239 /* assume pitch is 1,2,4,8,...*/ 237 /* assume pitch is 1,2,4,8,...*/
240 if(!(i&(pitch-1))) 238 if (!(i&(pitch-1))) {
241 {
242 /* need a return */ 239 /* need a return */
243 pstart += offset; 240 pstart += offset;
244 pbuffer = pstart; 241 pbuffer = pstart;
245 }else{ 242 } else {
246 pbuffer += sizeof(u16); 243 pbuffer += sizeof(u16);
247 } 244 }
248 245
diff --git a/drivers/staging/sm750fb/sm750_cursor.h b/drivers/staging/sm750fb/sm750_cursor.h
index e1716a600239..6c4fc9b73489 100644
--- a/drivers/staging/sm750fb/sm750_cursor.h
+++ b/drivers/staging/sm750fb/sm750_cursor.h
@@ -11,7 +11,7 @@ void hw_cursor_setPos(struct lynx_cursor *cursor,
11void hw_cursor_setColor(struct lynx_cursor *cursor, 11void hw_cursor_setColor(struct lynx_cursor *cursor,
12 u32 fg, u32 bg); 12 u32 fg, u32 bg);
13void hw_cursor_setData(struct lynx_cursor *cursor, 13void hw_cursor_setData(struct lynx_cursor *cursor,
14 u16 rop, const u8* data, const u8* mask); 14 u16 rop, const u8 *data, const u8 *mask);
15void hw_cursor_setData2(struct lynx_cursor *cursor, 15void hw_cursor_setData2(struct lynx_cursor *cursor,
16 u16 rop, const u8* data, const u8* mask); 16 u16 rop, const u8 *data, const u8 *mask);
17#endif 17#endif
diff --git a/drivers/staging/sm750fb/sm750_help.h b/drivers/staging/sm750fb/sm750_help.h
index 05777f72c166..8dc6bd22f5db 100644
--- a/drivers/staging/sm750fb/sm750_help.h
+++ b/drivers/staging/sm750fb/sm750_help.h
@@ -11,9 +11,9 @@
11#define GET_FIELD(d, f) (((d) >> _LSB(f)) & RAW_MASK(f)) 11#define GET_FIELD(d, f) (((d) >> _LSB(f)) & RAW_MASK(f))
12#define TEST_FIELD(d, f, v) (GET_FIELD(d, f) == f ## _ ## v) 12#define TEST_FIELD(d, f, v) (GET_FIELD(d, f) == f ## _ ## v)
13#define SET_FIELD(d, f, v) (((d) & ~GET_MASK(f)) | \ 13#define SET_FIELD(d, f, v) (((d) & ~GET_MASK(f)) | \
14 (((f ## _ ## v) & RAW_MASK(f)) << _LSB(f))) 14 (((f ## _ ## v) & RAW_MASK(f)) << _LSB(f)))
15#define SET_FIELDV(d, f, v) (((d) & ~GET_MASK(f)) | \ 15#define SET_FIELDV(d, f, v) (((d) & ~GET_MASK(f)) | \
16 (((v) & RAW_MASK(f)) << _LSB(f))) 16 (((v) & RAW_MASK(f)) << _LSB(f)))
17 17
18/* Internal macros */ 18/* Internal macros */
19#define _F_START(f) (0 ? f) 19#define _F_START(f) (0 ? f)
@@ -26,24 +26,24 @@
26/* Global macros */ 26/* Global macros */
27#define FIELD_GET(x, reg, field) \ 27#define FIELD_GET(x, reg, field) \
28( \ 28( \
29 _F_NORMALIZE((x), reg ## _ ## field) \ 29 _F_NORMALIZE((x), reg ## _ ## field) \
30) 30)
31 31
32#define FIELD_SET(x, reg, field, value) \ 32#define FIELD_SET(x, reg, field, value) \
33( \ 33( \
34 (x & ~_F_MASK(reg ## _ ## field)) \ 34 (x & ~_F_MASK(reg ## _ ## field)) \
35 | _F_DENORMALIZE(reg ## _ ## field ## _ ## value, reg ## _ ## field) \ 35 | _F_DENORMALIZE(reg ## _ ## field ## _ ## value, reg ## _ ## field) \
36) 36)
37 37
38#define FIELD_VALUE(x, reg, field, value) \ 38#define FIELD_VALUE(x, reg, field, value) \
39( \ 39( \
40 (x & ~_F_MASK(reg ## _ ## field)) \ 40 (x & ~_F_MASK(reg ## _ ## field)) \
41 | _F_DENORMALIZE(value, reg ## _ ## field) \ 41 | _F_DENORMALIZE(value, reg ## _ ## field) \
42) 42)
43 43
44#define FIELD_CLEAR(reg, field) \ 44#define FIELD_CLEAR(reg, field) \
45( \ 45( \
46 ~ _F_MASK(reg ## _ ## field) \ 46 ~ _F_MASK(reg ## _ ## field) \
47) 47)
48 48
49/* Field Macros */ 49/* Field Macros */
@@ -55,25 +55,25 @@
55#define FIELD_DENORMALIZE(field, value) (((value) << FIELD_START(field)) & FIELD_MASK(field)) 55#define FIELD_DENORMALIZE(field, value) (((value) << FIELD_START(field)) & FIELD_MASK(field))
56 56
57#define FIELD_INIT(reg, field, value) FIELD_DENORMALIZE(reg ## _ ## field, \ 57#define FIELD_INIT(reg, field, value) FIELD_DENORMALIZE(reg ## _ ## field, \
58 reg ## _ ## field ## _ ## value) 58 reg ## _ ## field ## _ ## value)
59#define FIELD_INIT_VAL(reg, field, value) \ 59#define FIELD_INIT_VAL(reg, field, value) \
60 (FIELD_DENORMALIZE(reg ## _ ## field, value)) 60 (FIELD_DENORMALIZE(reg ## _ ## field, value))
61#define FIELD_VAL_SET(x, r, f, v) x = x & ~FIELD_MASK(r ## _ ## f) \ 61#define FIELD_VAL_SET(x, r, f, v) x = x & ~FIELD_MASK(r ## _ ## f) \
62 | FIELD_DENORMALIZE(r ## _ ## f, r ## _ ## f ## _ ## v) 62 | FIELD_DENORMALIZE(r ## _ ## f, r ## _ ## f ## _ ## v)
63 63
64#define RGB(r, g, b) \ 64#define RGB(r, g, b) \
65( \ 65( \
66 (unsigned long) (((r) << 16) | ((g) << 8) | (b)) \ 66 (unsigned long) (((r) << 16) | ((g) << 8) | (b)) \
67) 67)
68 68
69#define RGB16(r, g, b) \ 69#define RGB16(r, g, b) \
70( \ 70( \
71 (unsigned short) ((((r) & 0xF8) << 8) | (((g) & 0xFC) << 3) | (((b) & 0xF8) >> 3)) \ 71 (unsigned short) ((((r) & 0xF8) << 8) | (((g) & 0xFC) << 3) | (((b) & 0xF8) >> 3)) \
72) 72)
73 73
74static inline unsigned int absDiff(unsigned int a, unsigned int b) 74static inline unsigned int absDiff(unsigned int a, unsigned int b)
75{ 75{
76 if(a<b) 76 if (a < b)
77 return b-a; 77 return b-a;
78 else 78 else
79 return a-b; 79 return a-b;
diff --git a/drivers/staging/sm750fb/sm750_hw.c b/drivers/staging/sm750fb/sm750_hw.c
index 84381bc414e7..7317ba9b7fe5 100644
--- a/drivers/staging/sm750fb/sm750_hw.c
+++ b/drivers/staging/sm750fb/sm750_hw.c
@@ -24,11 +24,11 @@
24#include "ddk750.h" 24#include "ddk750.h"
25#include "sm750_accel.h" 25#include "sm750_accel.h"
26 26
27int hw_sm750_map(struct lynx_share* share, struct pci_dev* pdev) 27int hw_sm750_map(struct lynx_share *share, struct pci_dev *pdev)
28{ 28{
29 int ret; 29 int ret;
30 struct sm750_share *spec_share; 30 struct sm750_share *spec_share;
31 31
32 32
33 spec_share = container_of(share, struct sm750_share, share); 33 spec_share = container_of(share, struct sm750_share, share);
34 ret = 0; 34 ret = 0;
@@ -43,24 +43,23 @@ int hw_sm750_map(struct lynx_share* share, struct pci_dev* pdev)
43 * in lynxfb_remove, or memory will not be mapped again 43 * in lynxfb_remove, or memory will not be mapped again
44 * successfully 44 * successfully
45 * */ 45 * */
46 46 ret = pci_request_region(pdev, 1, "sm750fb");
47 if((ret = pci_request_region(pdev, 1, "sm750fb"))) 47 if (ret) {
48 {
49 pr_err("Can not request PCI regions.\n"); 48 pr_err("Can not request PCI regions.\n");
50 goto exit; 49 goto exit;
51 } 50 }
52 51
53 /* now map mmio and vidmem*/ 52 /* now map mmio and vidmem*/
54 share->pvReg = ioremap_nocache(share->vidreg_start, share->vidreg_size); 53 share->pvReg = ioremap_nocache(share->vidreg_start, share->vidreg_size);
55 if(!share->pvReg){ 54 if (!share->pvReg) {
56 pr_err("mmio failed\n"); 55 pr_err("mmio failed\n");
57 ret = -EFAULT; 56 ret = -EFAULT;
58 goto exit; 57 goto exit;
59 }else{ 58 } else {
60 pr_info("mmio virtual addr = %p\n", share->pvReg); 59 pr_info("mmio virtual addr = %p\n", share->pvReg);
61 } 60 }
62 61
63 62
64 share->accel.dprBase = share->pvReg + DE_BASE_ADDR_TYPE1; 63 share->accel.dprBase = share->pvReg + DE_BASE_ADDR_TYPE1;
65 share->accel.dpPortBase = share->pvReg + DE_PORT_ADDR_TYPE1; 64 share->accel.dpPortBase = share->pvReg + DE_PORT_ADDR_TYPE1;
66 65
@@ -78,8 +77,8 @@ int hw_sm750_map(struct lynx_share* share, struct pci_dev* pdev)
78 77
79 /* reserve the vidmem space of smi adaptor */ 78 /* reserve the vidmem space of smi adaptor */
80#if 0 79#if 0
81 if((ret = pci_request_region(pdev, 0, _moduleName_))) 80 ret = pci_request_region(pdev, 0, _moduleName_);
82 { 81 if (ret) {
83 pr_err("Can not request PCI regions.\n"); 82 pr_err("Can not request PCI regions.\n");
84 goto exit; 83 goto exit;
85 } 84 }
@@ -87,11 +86,11 @@ int hw_sm750_map(struct lynx_share* share, struct pci_dev* pdev)
87 86
88 share->pvMem = ioremap_wc(share->vidmem_start, share->vidmem_size); 87 share->pvMem = ioremap_wc(share->vidmem_start, share->vidmem_size);
89 88
90 if(!share->pvMem){ 89 if (!share->pvMem) {
91 pr_err("Map video memory failed\n"); 90 pr_err("Map video memory failed\n");
92 ret = -EFAULT; 91 ret = -EFAULT;
93 goto exit; 92 goto exit;
94 }else{ 93 } else {
95 pr_info("video memory vaddr = %p\n", share->pvMem); 94 pr_info("video memory vaddr = %p\n", share->pvMem);
96 } 95 }
97exit: 96exit:
@@ -104,22 +103,22 @@ int hw_sm750_inithw(struct lynx_share *share, struct pci_dev *pdev)
104{ 103{
105 struct sm750_share *spec_share; 104 struct sm750_share *spec_share;
106 struct init_status *parm; 105 struct init_status *parm;
107 106
108 spec_share = container_of(share, struct sm750_share, share); 107 spec_share = container_of(share, struct sm750_share, share);
109 parm = &spec_share->state.initParm; 108 parm = &spec_share->state.initParm;
110 if(parm->chip_clk == 0) 109 if (parm->chip_clk == 0)
111 parm->chip_clk = (getChipType() == SM750LE)? 110 parm->chip_clk = (getChipType() == SM750LE) ?
112 DEFAULT_SM750LE_CHIP_CLOCK : 111 DEFAULT_SM750LE_CHIP_CLOCK :
113 DEFAULT_SM750_CHIP_CLOCK; 112 DEFAULT_SM750_CHIP_CLOCK;
114 113
115 if(parm->mem_clk == 0) 114 if (parm->mem_clk == 0)
116 parm->mem_clk = parm->chip_clk; 115 parm->mem_clk = parm->chip_clk;
117 if(parm->master_clk == 0) 116 if (parm->master_clk == 0)
118 parm->master_clk = parm->chip_clk/3; 117 parm->master_clk = parm->chip_clk/3;
119 118
120 ddk750_initHw((initchip_param_t *)&spec_share->state.initParm); 119 ddk750_initHw((initchip_param_t *)&spec_share->state.initParm);
121 /* for sm718,open pci burst */ 120 /* for sm718,open pci burst */
122 if(share->devid == 0x718){ 121 if (share->devid == 0x718) {
123 POKE32(SYSTEM_CTRL, 122 POKE32(SYSTEM_CTRL,
124 FIELD_SET(PEEK32(SYSTEM_CTRL), SYSTEM_CTRL, PCI_BURST, ON)); 123 FIELD_SET(PEEK32(SYSTEM_CTRL), SYSTEM_CTRL, PCI_BURST, ON));
125 } 124 }
@@ -130,10 +129,9 @@ int hw_sm750_inithw(struct lynx_share *share, struct pci_dev *pdev)
130 ddk750_initDVIDisp(); 129 ddk750_initDVIDisp();
131#endif 130#endif
132 131
133 if(getChipType() != SM750LE) 132 if (getChipType() != SM750LE) {
134 {
135 /* does user need CRT ?*/ 133 /* does user need CRT ?*/
136 if(spec_share->state.nocrt){ 134 if (spec_share->state.nocrt) {
137 POKE32(MISC_CTRL, 135 POKE32(MISC_CTRL,
138 FIELD_SET(PEEK32(MISC_CTRL), 136 FIELD_SET(PEEK32(MISC_CTRL),
139 MISC_CTRL, 137 MISC_CTRL,
@@ -143,7 +141,7 @@ int hw_sm750_inithw(struct lynx_share *share, struct pci_dev *pdev)
143 FIELD_SET(PEEK32(SYSTEM_CTRL), 141 FIELD_SET(PEEK32(SYSTEM_CTRL),
144 SYSTEM_CTRL, 142 SYSTEM_CTRL,
145 DPMS, VNHN)); 143 DPMS, VNHN));
146 }else{ 144 } else {
147 POKE32(MISC_CTRL, 145 POKE32(MISC_CTRL,
148 FIELD_SET(PEEK32(MISC_CTRL), 146 FIELD_SET(PEEK32(MISC_CTRL),
149 MISC_CTRL, 147 MISC_CTRL,
@@ -155,45 +153,43 @@ int hw_sm750_inithw(struct lynx_share *share, struct pci_dev *pdev)
155 DPMS, VPHP)); 153 DPMS, VPHP));
156 } 154 }
157 155
158 switch (spec_share->state.pnltype){ 156 switch (spec_share->state.pnltype) {
159 case sm750_doubleTFT: 157 case sm750_doubleTFT:
160 case sm750_24TFT: 158 case sm750_24TFT:
161 case sm750_dualTFT: 159 case sm750_dualTFT:
162 POKE32(PANEL_DISPLAY_CTRL, 160 POKE32(PANEL_DISPLAY_CTRL,
163 FIELD_VALUE(PEEK32(PANEL_DISPLAY_CTRL), 161 FIELD_VALUE(PEEK32(PANEL_DISPLAY_CTRL),
164 PANEL_DISPLAY_CTRL, 162 PANEL_DISPLAY_CTRL,
165 TFT_DISP, 163 TFT_DISP,
166 spec_share->state.pnltype)); 164 spec_share->state.pnltype));
167 break; 165 break;
168 } 166 }
169 }else{ 167 } else {
170 /* for 750LE ,no DVI chip initilization makes Monitor no signal */ 168 /* for 750LE ,no DVI chip initilization makes Monitor no signal */
171 /* Set up GPIO for software I2C to program DVI chip in the 169 /* Set up GPIO for software I2C to program DVI chip in the
172 Xilinx SP605 board, in order to have video signal. 170 Xilinx SP605 board, in order to have video signal.
173 */ 171 */
174 swI2CInit(0, 1); 172 swI2CInit(0, 1);
175 173
176 174
177 /* Customer may NOT use CH7301 DVI chip, which has to be 175 /* Customer may NOT use CH7301 DVI chip, which has to be
178 initialized differently. 176 initialized differently.
179 */ 177 */
180 if (swI2CReadReg(0xec, 0x4a) == 0x95) 178 if (swI2CReadReg(0xec, 0x4a) == 0x95) {
181 { 179 /* The following register values for CH7301 are from
182 /* The following register values for CH7301 are from 180 Chrontel app note and our experiment.
183 Chrontel app note and our experiment. 181 */
184 */
185 pr_info("yes,CH7301 DVI chip found\n"); 182 pr_info("yes,CH7301 DVI chip found\n");
186 swI2CWriteReg(0xec, 0x1d, 0x16); 183 swI2CWriteReg(0xec, 0x1d, 0x16);
187 swI2CWriteReg(0xec, 0x21, 0x9); 184 swI2CWriteReg(0xec, 0x21, 0x9);
188 swI2CWriteReg(0xec, 0x49, 0xC0); 185 swI2CWriteReg(0xec, 0x49, 0xC0);
189 pr_info("okay,CH7301 DVI chip setup done\n"); 186 pr_info("okay,CH7301 DVI chip setup done\n");
190 } 187 }
191 } 188 }
192 189
193 /* init 2d engine */ 190 /* init 2d engine */
194 if(!share->accel_off){ 191 if (!share->accel_off)
195 hw_sm750_initAccel(share); 192 hw_sm750_initAccel(share);
196 }
197 193
198 return 0; 194 return 0;
199} 195}
@@ -202,86 +198,87 @@ int hw_sm750_inithw(struct lynx_share *share, struct pci_dev *pdev)
202resource_size_t hw_sm750_getVMSize(struct lynx_share *share) 198resource_size_t hw_sm750_getVMSize(struct lynx_share *share)
203{ 199{
204 resource_size_t ret; 200 resource_size_t ret;
205 201
206 ret = ddk750_getVMSize(); 202 ret = ddk750_getVMSize();
207 return ret; 203 return ret;
208} 204}
209 205
210 206
211 207
212int hw_sm750_output_checkMode(struct lynxfb_output* output, struct fb_var_screeninfo* var) 208int hw_sm750_output_checkMode(struct lynxfb_output *output, struct fb_var_screeninfo *var)
213{ 209{
214 210
215 return 0; 211 return 0;
216} 212}
217 213
218 214
219int hw_sm750_output_setMode(struct lynxfb_output* output, 215int hw_sm750_output_setMode(struct lynxfb_output *output,
220 struct fb_var_screeninfo* var, struct fb_fix_screeninfo* fix) 216 struct fb_var_screeninfo *var, struct fb_fix_screeninfo *fix)
221{ 217{
222 int ret; 218 int ret;
223 disp_output_t dispSet; 219 disp_output_t dispSet;
224 int channel; 220 int channel;
225 221
226 ret = 0; 222 ret = 0;
227 dispSet = 0; 223 dispSet = 0;
228 channel = *output->channel; 224 channel = *output->channel;
229 225
230 226
231 if(getChipType() != SM750LE){ 227 if (getChipType() != SM750LE) {
232 if(channel == sm750_primary){ 228 if (channel == sm750_primary) {
233 pr_info("primary channel\n"); 229 pr_info("primary channel\n");
234 if(output->paths & sm750_panel) 230 if (output->paths & sm750_panel)
235 dispSet |= do_LCD1_PRI; 231 dispSet |= do_LCD1_PRI;
236 if(output->paths & sm750_crt) 232 if (output->paths & sm750_crt)
237 dispSet |= do_CRT_PRI; 233 dispSet |= do_CRT_PRI;
238 234
239 }else{ 235 } else {
240 pr_info("secondary channel\n"); 236 pr_info("secondary channel\n");
241 if(output->paths & sm750_panel) 237 if (output->paths & sm750_panel)
242 dispSet |= do_LCD1_SEC; 238 dispSet |= do_LCD1_SEC;
243 if(output->paths & sm750_crt) 239 if (output->paths & sm750_crt)
244 dispSet |= do_CRT_SEC; 240 dispSet |= do_CRT_SEC;
245 241
246 } 242 }
247 ddk750_setLogicalDispOut(dispSet); 243 ddk750_setLogicalDispOut(dispSet);
248 }else{ 244 } else {
249 /* just open DISPLAY_CONTROL_750LE register bit 3:0*/ 245 /* just open DISPLAY_CONTROL_750LE register bit 3:0*/
250 u32 reg; 246 u32 reg;
247
251 reg = PEEK32(DISPLAY_CONTROL_750LE); 248 reg = PEEK32(DISPLAY_CONTROL_750LE);
252 reg |= 0xf; 249 reg |= 0xf;
253 POKE32(DISPLAY_CONTROL_750LE, reg); 250 POKE32(DISPLAY_CONTROL_750LE, reg);
254 } 251 }
255 252
256 pr_info("ddk setlogicdispout done \n"); 253 pr_info("ddk setlogicdispout done\n");
257 return ret; 254 return ret;
258} 255}
259 256
260void hw_sm750_output_clear(struct lynxfb_output* output) 257void hw_sm750_output_clear(struct lynxfb_output *output)
261{ 258{
262 259
263 return; 260 return;
264} 261}
265 262
266int hw_sm750_crtc_checkMode(struct lynxfb_crtc* crtc, struct fb_var_screeninfo* var) 263int hw_sm750_crtc_checkMode(struct lynxfb_crtc *crtc, struct fb_var_screeninfo *var)
267{ 264{
268 struct lynx_share *share; 265 struct lynx_share *share;
269 266
270 267
271 share = container_of(crtc, struct lynxfb_par, crtc)->share; 268 share = container_of(crtc, struct lynxfb_par, crtc)->share;
272 269
273 switch (var->bits_per_pixel){ 270 switch (var->bits_per_pixel) {
274 case 8: 271 case 8:
275 case 16: 272 case 16:
276 break; 273 break;
277 case 32: 274 case 32:
278 if (share->revid == SM750LE_REVISION_ID) { 275 if (share->revid == SM750LE_REVISION_ID) {
279 pr_debug("750le do not support 32bpp\n"); 276 pr_debug("750le do not support 32bpp\n");
280 return -EINVAL;
281 }
282 break;
283 default:
284 return -EINVAL; 277 return -EINVAL;
278 }
279 break;
280 default:
281 return -EINVAL;
285 282
286 } 283 }
287 284
@@ -292,9 +289,9 @@ int hw_sm750_crtc_checkMode(struct lynxfb_crtc* crtc, struct fb_var_screeninfo*
292/* 289/*
293 set the controller's mode for @crtc charged with @var and @fix parameters 290 set the controller's mode for @crtc charged with @var and @fix parameters
294*/ 291*/
295int hw_sm750_crtc_setMode(struct lynxfb_crtc* crtc, 292int hw_sm750_crtc_setMode(struct lynxfb_crtc *crtc,
296 struct fb_var_screeninfo* var, 293 struct fb_var_screeninfo *var,
297 struct fb_fix_screeninfo* fix) 294 struct fb_fix_screeninfo *fix)
298{ 295{
299 int ret, fmt; 296 int ret, fmt;
300 u32 reg; 297 u32 reg;
@@ -303,24 +300,24 @@ int hw_sm750_crtc_setMode(struct lynxfb_crtc* crtc,
303 struct lynx_share *share; 300 struct lynx_share *share;
304 struct lynxfb_par *par; 301 struct lynxfb_par *par;
305 302
306 303
307 ret = 0; 304 ret = 0;
308 par = container_of(crtc, struct lynxfb_par, crtc); 305 par = container_of(crtc, struct lynxfb_par, crtc);
309 share = par->share; 306 share = par->share;
310#if 1 307#if 1
311 if(!share->accel_off){ 308 if (!share->accel_off) {
312 /* set 2d engine pixel format according to mode bpp */ 309 /* set 2d engine pixel format according to mode bpp */
313 switch(var->bits_per_pixel){ 310 switch (var->bits_per_pixel) {
314 case 8: 311 case 8:
315 fmt = 0; 312 fmt = 0;
316 break; 313 break;
317 case 16: 314 case 16:
318 fmt = 1; 315 fmt = 1;
319 break; 316 break;
320 case 32: 317 case 32:
321 default: 318 default:
322 fmt = 2; 319 fmt = 2;
323 break; 320 break;
324 } 321 }
325 hw_set2dformat(&share->accel, fmt); 322 hw_set2dformat(&share->accel, fmt);
326 } 323 }
@@ -330,7 +327,7 @@ int hw_sm750_crtc_setMode(struct lynxfb_crtc* crtc,
330 modparm.pixel_clock = ps_to_hz(var->pixclock); 327 modparm.pixel_clock = ps_to_hz(var->pixclock);
331 modparm.vertical_sync_polarity = (var->sync & FB_SYNC_HOR_HIGH_ACT) ? POS:NEG; 328 modparm.vertical_sync_polarity = (var->sync & FB_SYNC_HOR_HIGH_ACT) ? POS:NEG;
332 modparm.horizontal_sync_polarity = (var->sync & FB_SYNC_VERT_HIGH_ACT) ? POS:NEG; 329 modparm.horizontal_sync_polarity = (var->sync & FB_SYNC_VERT_HIGH_ACT) ? POS:NEG;
333 modparm.clock_phase_polarity = (var->sync& FB_SYNC_COMP_HIGH_ACT) ? POS:NEG; 330 modparm.clock_phase_polarity = (var->sync & FB_SYNC_COMP_HIGH_ACT) ? POS:NEG;
334 modparm.horizontal_display_end = var->xres; 331 modparm.horizontal_display_end = var->xres;
335 modparm.horizontal_sync_width = var->hsync_len; 332 modparm.horizontal_sync_width = var->hsync_len;
336 modparm.horizontal_sync_start = var->xres + var->right_margin; 333 modparm.horizontal_sync_start = var->xres + var->right_margin;
@@ -341,19 +338,19 @@ int hw_sm750_crtc_setMode(struct lynxfb_crtc* crtc,
341 modparm.vertical_total = var->yres + var->upper_margin + var->lower_margin + var->vsync_len; 338 modparm.vertical_total = var->yres + var->upper_margin + var->lower_margin + var->vsync_len;
342 339
343 /* choose pll */ 340 /* choose pll */
344 if(crtc->channel != sm750_secondary) 341 if (crtc->channel != sm750_secondary)
345 clock = PRIMARY_PLL; 342 clock = PRIMARY_PLL;
346 else 343 else
347 clock = SECONDARY_PLL; 344 clock = SECONDARY_PLL;
348 345
349 pr_debug("Request pixel clock = %lu\n", modparm.pixel_clock); 346 pr_debug("Request pixel clock = %lu\n", modparm.pixel_clock);
350 ret = ddk750_setModeTiming(&modparm, clock); 347 ret = ddk750_setModeTiming(&modparm, clock);
351 if(ret){ 348 if (ret) {
352 pr_err("Set mode timing failed\n"); 349 pr_err("Set mode timing failed\n");
353 goto exit; 350 goto exit;
354 } 351 }
355 352
356 if(crtc->channel != sm750_secondary){ 353 if (crtc->channel != sm750_secondary) {
357 /* set pitch, offset ,width,start address ,etc... */ 354 /* set pitch, offset ,width,start address ,etc... */
358 POKE32(PANEL_FB_ADDRESS, 355 POKE32(PANEL_FB_ADDRESS,
359 FIELD_SET(0, PANEL_FB_ADDRESS, STATUS, CURRENT)| 356 FIELD_SET(0, PANEL_FB_ADDRESS, STATUS, CURRENT)|
@@ -369,7 +366,7 @@ int hw_sm750_crtc_setMode(struct lynxfb_crtc* crtc,
369 FIELD_VALUE(0, PANEL_FB_WIDTH, OFFSET, fix->line_length)); 366 FIELD_VALUE(0, PANEL_FB_WIDTH, OFFSET, fix->line_length));
370 367
371 POKE32(PANEL_WINDOW_WIDTH, 368 POKE32(PANEL_WINDOW_WIDTH,
372 FIELD_VALUE(0, PANEL_WINDOW_WIDTH, WIDTH, var->xres -1)| 369 FIELD_VALUE(0, PANEL_WINDOW_WIDTH, WIDTH, var->xres - 1)|
373 FIELD_VALUE(0, PANEL_WINDOW_WIDTH, X, var->xoffset)); 370 FIELD_VALUE(0, PANEL_WINDOW_WIDTH, X, var->xoffset));
374 371
375 POKE32(PANEL_WINDOW_HEIGHT, 372 POKE32(PANEL_WINDOW_HEIGHT,
@@ -389,7 +386,7 @@ int hw_sm750_crtc_setMode(struct lynxfb_crtc* crtc,
389 PANEL_DISPLAY_CTRL, FORMAT, 386 PANEL_DISPLAY_CTRL, FORMAT,
390 (var->bits_per_pixel >> 4) 387 (var->bits_per_pixel >> 4)
391 )); 388 ));
392 }else{ 389 } else {
393 /* not implemented now */ 390 /* not implemented now */
394 POKE32(CRT_FB_ADDRESS, crtc->oScreen); 391 POKE32(CRT_FB_ADDRESS, crtc->oScreen);
395 reg = var->xres * (var->bits_per_pixel >> 3); 392 reg = var->xres * (var->bits_per_pixel >> 3);
@@ -412,138 +409,137 @@ exit:
412 return ret; 409 return ret;
413} 410}
414 411
415void hw_sm750_crtc_clear(struct lynxfb_crtc* crtc) 412void hw_sm750_crtc_clear(struct lynxfb_crtc *crtc)
416{ 413{
417 414
418 return; 415 return;
419} 416}
420 417
421int hw_sm750_setColReg(struct lynxfb_crtc* crtc, ushort index, 418int hw_sm750_setColReg(struct lynxfb_crtc *crtc, ushort index,
422 ushort red, ushort green, ushort blue) 419 ushort red, ushort green, ushort blue)
423{ 420{
424 static unsigned int add[]={PANEL_PALETTE_RAM, CRT_PALETTE_RAM}; 421 static unsigned int add[] = {PANEL_PALETTE_RAM, CRT_PALETTE_RAM};
422
425 POKE32(add[crtc->channel] + index*4, (red<<16)|(green<<8)|blue); 423 POKE32(add[crtc->channel] + index*4, (red<<16)|(green<<8)|blue);
426 return 0; 424 return 0;
427} 425}
428 426
429int hw_sm750le_setBLANK(struct lynxfb_output * output, int blank){ 427int hw_sm750le_setBLANK(struct lynxfb_output *output, int blank)
428{
430 int dpms, crtdb; 429 int dpms, crtdb;
431 430
432 switch(blank) 431 switch (blank) {
433 {
434#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10) 432#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
435 case FB_BLANK_UNBLANK: 433 case FB_BLANK_UNBLANK:
436#else 434#else
437 case VESA_NO_BLANKING: 435 case VESA_NO_BLANKING:
438#endif 436#endif
439 dpms = CRT_DISPLAY_CTRL_DPMS_0; 437 dpms = CRT_DISPLAY_CTRL_DPMS_0;
440 crtdb = CRT_DISPLAY_CTRL_BLANK_OFF; 438 crtdb = CRT_DISPLAY_CTRL_BLANK_OFF;
441 break; 439 break;
442#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10) 440#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
443 case FB_BLANK_NORMAL: 441 case FB_BLANK_NORMAL:
444 dpms = CRT_DISPLAY_CTRL_DPMS_0; 442 dpms = CRT_DISPLAY_CTRL_DPMS_0;
445 crtdb = CRT_DISPLAY_CTRL_BLANK_ON; 443 crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
446 break; 444 break;
447#endif 445#endif
448#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10) 446#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
449 case FB_BLANK_VSYNC_SUSPEND: 447 case FB_BLANK_VSYNC_SUSPEND:
450#else 448#else
451 case VESA_VSYNC_SUSPEND: 449 case VESA_VSYNC_SUSPEND:
452#endif 450#endif
453 dpms = CRT_DISPLAY_CTRL_DPMS_2; 451 dpms = CRT_DISPLAY_CTRL_DPMS_2;
454 crtdb = CRT_DISPLAY_CTRL_BLANK_ON; 452 crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
455 break; 453 break;
456#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10) 454#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
457 case FB_BLANK_HSYNC_SUSPEND: 455 case FB_BLANK_HSYNC_SUSPEND:
458#else 456#else
459 case VESA_HSYNC_SUSPEND: 457 case VESA_HSYNC_SUSPEND:
460#endif 458#endif
461 dpms = CRT_DISPLAY_CTRL_DPMS_1; 459 dpms = CRT_DISPLAY_CTRL_DPMS_1;
462 crtdb = CRT_DISPLAY_CTRL_BLANK_ON; 460 crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
463 break; 461 break;
464#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10) 462#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
465 case FB_BLANK_POWERDOWN: 463 case FB_BLANK_POWERDOWN:
466#else 464#else
467 case VESA_POWERDOWN: 465 case VESA_POWERDOWN:
468#endif 466#endif
469 dpms = CRT_DISPLAY_CTRL_DPMS_3; 467 dpms = CRT_DISPLAY_CTRL_DPMS_3;
470 crtdb = CRT_DISPLAY_CTRL_BLANK_ON; 468 crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
471 break; 469 break;
472 default: 470 default:
473 return -EINVAL; 471 return -EINVAL;
474 } 472 }
475 473
476 if(output->paths & sm750_crt){ 474 if (output->paths & sm750_crt) {
477 POKE32(CRT_DISPLAY_CTRL, FIELD_VALUE(PEEK32(CRT_DISPLAY_CTRL), CRT_DISPLAY_CTRL, DPMS, dpms)); 475 POKE32(CRT_DISPLAY_CTRL, FIELD_VALUE(PEEK32(CRT_DISPLAY_CTRL), CRT_DISPLAY_CTRL, DPMS, dpms));
478 POKE32(CRT_DISPLAY_CTRL, FIELD_VALUE(PEEK32(CRT_DISPLAY_CTRL), CRT_DISPLAY_CTRL, BLANK, crtdb)); 476 POKE32(CRT_DISPLAY_CTRL, FIELD_VALUE(PEEK32(CRT_DISPLAY_CTRL), CRT_DISPLAY_CTRL, BLANK, crtdb));
479 } 477 }
480 return 0; 478 return 0;
481} 479}
482 480
483int hw_sm750_setBLANK(struct lynxfb_output* output, int blank) 481int hw_sm750_setBLANK(struct lynxfb_output *output, int blank)
484{ 482{
485 unsigned int dpms, pps, crtdb; 483 unsigned int dpms, pps, crtdb;
486 484
487 dpms = pps = crtdb = 0; 485 dpms = pps = crtdb = 0;
488 486
489 switch (blank) 487 switch (blank) {
490 {
491#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10) 488#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
492 case FB_BLANK_UNBLANK: 489 case FB_BLANK_UNBLANK:
493#else 490#else
494 case VESA_NO_BLANKING: 491 case VESA_NO_BLANKING:
495#endif 492#endif
496 pr_info("flag = FB_BLANK_UNBLANK \n"); 493 pr_info("flag = FB_BLANK_UNBLANK\n");
497 dpms = SYSTEM_CTRL_DPMS_VPHP; 494 dpms = SYSTEM_CTRL_DPMS_VPHP;
498 pps = PANEL_DISPLAY_CTRL_DATA_ENABLE; 495 pps = PANEL_DISPLAY_CTRL_DATA_ENABLE;
499 crtdb = CRT_DISPLAY_CTRL_BLANK_OFF; 496 crtdb = CRT_DISPLAY_CTRL_BLANK_OFF;
500 break; 497 break;
501#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10) 498#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
502 case FB_BLANK_NORMAL: 499 case FB_BLANK_NORMAL:
503 pr_info("flag = FB_BLANK_NORMAL \n"); 500 pr_info("flag = FB_BLANK_NORMAL\n");
504 dpms = SYSTEM_CTRL_DPMS_VPHP; 501 dpms = SYSTEM_CTRL_DPMS_VPHP;
505 pps = PANEL_DISPLAY_CTRL_DATA_DISABLE; 502 pps = PANEL_DISPLAY_CTRL_DATA_DISABLE;
506 crtdb = CRT_DISPLAY_CTRL_BLANK_ON; 503 crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
507 break; 504 break;
508#endif 505#endif
509#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10) 506#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
510 case FB_BLANK_VSYNC_SUSPEND: 507 case FB_BLANK_VSYNC_SUSPEND:
511#else 508#else
512 case VESA_VSYNC_SUSPEND: 509 case VESA_VSYNC_SUSPEND:
513#endif 510#endif
514 dpms = SYSTEM_CTRL_DPMS_VNHP; 511 dpms = SYSTEM_CTRL_DPMS_VNHP;
515 pps = PANEL_DISPLAY_CTRL_DATA_DISABLE; 512 pps = PANEL_DISPLAY_CTRL_DATA_DISABLE;
516 crtdb = CRT_DISPLAY_CTRL_BLANK_ON; 513 crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
517 break; 514 break;
518#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10) 515#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
519 case FB_BLANK_HSYNC_SUSPEND: 516 case FB_BLANK_HSYNC_SUSPEND:
520#else 517#else
521 case VESA_HSYNC_SUSPEND: 518 case VESA_HSYNC_SUSPEND:
522#endif 519#endif
523 dpms = SYSTEM_CTRL_DPMS_VPHN; 520 dpms = SYSTEM_CTRL_DPMS_VPHN;
524 pps = PANEL_DISPLAY_CTRL_DATA_DISABLE; 521 pps = PANEL_DISPLAY_CTRL_DATA_DISABLE;
525 crtdb = CRT_DISPLAY_CTRL_BLANK_ON; 522 crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
526 break; 523 break;
527#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10) 524#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
528 case FB_BLANK_POWERDOWN: 525 case FB_BLANK_POWERDOWN:
529#else 526#else
530 case VESA_POWERDOWN: 527 case VESA_POWERDOWN:
531#endif 528#endif
532 dpms = SYSTEM_CTRL_DPMS_VNHN; 529 dpms = SYSTEM_CTRL_DPMS_VNHN;
533 pps = PANEL_DISPLAY_CTRL_DATA_DISABLE; 530 pps = PANEL_DISPLAY_CTRL_DATA_DISABLE;
534 crtdb = CRT_DISPLAY_CTRL_BLANK_ON; 531 crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
535 break; 532 break;
536 } 533 }
537 534
538 if(output->paths & sm750_crt){ 535 if (output->paths & sm750_crt) {
539 536
540 POKE32(SYSTEM_CTRL, FIELD_VALUE(PEEK32(SYSTEM_CTRL), SYSTEM_CTRL, DPMS, dpms)); 537 POKE32(SYSTEM_CTRL, FIELD_VALUE(PEEK32(SYSTEM_CTRL), SYSTEM_CTRL, DPMS, dpms));
541 POKE32(CRT_DISPLAY_CTRL, FIELD_VALUE(PEEK32(CRT_DISPLAY_CTRL), CRT_DISPLAY_CTRL, BLANK, crtdb)); 538 POKE32(CRT_DISPLAY_CTRL, FIELD_VALUE(PEEK32(CRT_DISPLAY_CTRL), CRT_DISPLAY_CTRL, BLANK, crtdb));
542 } 539 }
543 540
544 if(output->paths & sm750_panel){ 541 if (output->paths & sm750_panel)
545 POKE32(PANEL_DISPLAY_CTRL, FIELD_VALUE(PEEK32(PANEL_DISPLAY_CTRL), PANEL_DISPLAY_CTRL, DATA, pps)); 542 POKE32(PANEL_DISPLAY_CTRL, FIELD_VALUE(PEEK32(PANEL_DISPLAY_CTRL), PANEL_DISPLAY_CTRL, DATA, pps));
546 }
547 543
548 return 0; 544 return 0;
549} 545}
@@ -552,9 +548,10 @@ int hw_sm750_setBLANK(struct lynxfb_output* output, int blank)
552void hw_sm750_initAccel(struct lynx_share *share) 548void hw_sm750_initAccel(struct lynx_share *share)
553{ 549{
554 u32 reg; 550 u32 reg;
551
555 enable2DEngine(1); 552 enable2DEngine(1);
556 553
557 if(getChipType() == SM750LE){ 554 if (getChipType() == SM750LE) {
558 reg = PEEK32(DE_STATE1); 555 reg = PEEK32(DE_STATE1);
559 reg = FIELD_SET(reg, DE_STATE1, DE_ABORT, ON); 556 reg = FIELD_SET(reg, DE_STATE1, DE_ABORT, ON);
560 POKE32(DE_STATE1, reg); 557 POKE32(DE_STATE1, reg);
@@ -563,7 +560,7 @@ void hw_sm750_initAccel(struct lynx_share *share)
563 reg = FIELD_SET(reg, DE_STATE1, DE_ABORT, OFF); 560 reg = FIELD_SET(reg, DE_STATE1, DE_ABORT, OFF);
564 POKE32(DE_STATE1, reg); 561 POKE32(DE_STATE1, reg);
565 562
566 }else{ 563 } else {
567 /* engine reset */ 564 /* engine reset */
568 reg = PEEK32(SYSTEM_CTRL); 565 reg = PEEK32(SYSTEM_CTRL);
569 reg = FIELD_SET(reg, SYSTEM_CTRL, DE_ABORT, ON); 566 reg = FIELD_SET(reg, SYSTEM_CTRL, DE_ABORT, ON);
@@ -580,13 +577,14 @@ void hw_sm750_initAccel(struct lynx_share *share)
580 577
581int hw_sm750le_deWait(void) 578int hw_sm750le_deWait(void)
582{ 579{
583 int i=0x10000000; 580 int i = 0x10000000;
584 while(i--){ 581
582 while (i--) {
585 unsigned int dwVal = PEEK32(DE_STATE2); 583 unsigned int dwVal = PEEK32(DE_STATE2);
586 if((FIELD_GET(dwVal, DE_STATE2, DE_STATUS) == DE_STATE2_DE_STATUS_IDLE) && 584
585 if ((FIELD_GET(dwVal, DE_STATE2, DE_STATUS) == DE_STATE2_DE_STATUS_IDLE) &&
587 (FIELD_GET(dwVal, DE_STATE2, DE_FIFO) == DE_STATE2_DE_FIFO_EMPTY) && 586 (FIELD_GET(dwVal, DE_STATE2, DE_FIFO) == DE_STATE2_DE_FIFO_EMPTY) &&
588 (FIELD_GET(dwVal, DE_STATE2, DE_MEM_FIFO) == DE_STATE2_DE_MEM_FIFO_EMPTY)) 587 (FIELD_GET(dwVal, DE_STATE2, DE_MEM_FIFO) == DE_STATE2_DE_MEM_FIFO_EMPTY)) {
589 {
590 return 0; 588 return 0;
591 } 589 }
592 } 590 }
@@ -597,13 +595,14 @@ int hw_sm750le_deWait(void)
597 595
598int hw_sm750_deWait(void) 596int hw_sm750_deWait(void)
599{ 597{
600 int i=0x10000000; 598 int i = 0x10000000;
601 while(i--){ 599
600 while (i--) {
602 unsigned int dwVal = PEEK32(SYSTEM_CTRL); 601 unsigned int dwVal = PEEK32(SYSTEM_CTRL);
603 if((FIELD_GET(dwVal, SYSTEM_CTRL, DE_STATUS) == SYSTEM_CTRL_DE_STATUS_IDLE) && 602
603 if ((FIELD_GET(dwVal, SYSTEM_CTRL, DE_STATUS) == SYSTEM_CTRL_DE_STATUS_IDLE) &&
604 (FIELD_GET(dwVal, SYSTEM_CTRL, DE_FIFO) == SYSTEM_CTRL_DE_FIFO_EMPTY) && 604 (FIELD_GET(dwVal, SYSTEM_CTRL, DE_FIFO) == SYSTEM_CTRL_DE_FIFO_EMPTY) &&
605 (FIELD_GET(dwVal, SYSTEM_CTRL, DE_MEM_FIFO) == SYSTEM_CTRL_DE_MEM_FIFO_EMPTY)) 605 (FIELD_GET(dwVal, SYSTEM_CTRL, DE_MEM_FIFO) == SYSTEM_CTRL_DE_MEM_FIFO_EMPTY)) {
606 {
607 return 0; 606 return 0;
608 } 607 }
609 } 608 }
@@ -612,28 +611,27 @@ int hw_sm750_deWait(void)
612} 611}
613 612
614int hw_sm750_pan_display(struct lynxfb_crtc *crtc, 613int hw_sm750_pan_display(struct lynxfb_crtc *crtc,
615 const struct fb_var_screeninfo *var, 614 const struct fb_var_screeninfo *var,
616 const struct fb_info *info) 615 const struct fb_info *info)
617{ 616{
618 uint32_t total; 617 uint32_t total;
619 /* check params */ 618 /* check params */
620 if ((var->xoffset + var->xres > var->xres_virtual) || 619 if ((var->xoffset + var->xres > var->xres_virtual) ||
621 (var->yoffset + var->yres > var->yres_virtual)) { 620 (var->yoffset + var->yres > var->yres_virtual)) {
622 return -EINVAL; 621 return -EINVAL;
623 } 622 }
624
625 total = var->yoffset * info->fix.line_length +
626 ((var->xoffset * var->bits_per_pixel) >> 3);
627 total += crtc->oScreen;
628 if (crtc->channel == sm750_primary) {
629 POKE32(PANEL_FB_ADDRESS,
630 FIELD_VALUE(PEEK32(PANEL_FB_ADDRESS),
631 PANEL_FB_ADDRESS, ADDRESS, total));
632 } else {
633 POKE32(CRT_FB_ADDRESS,
634 FIELD_VALUE(PEEK32(CRT_FB_ADDRESS),
635 CRT_FB_ADDRESS, ADDRESS, total));
636 }
637 return 0;
638}
639 623
624 total = var->yoffset * info->fix.line_length +
625 ((var->xoffset * var->bits_per_pixel) >> 3);
626 total += crtc->oScreen;
627 if (crtc->channel == sm750_primary) {
628 POKE32(PANEL_FB_ADDRESS,
629 FIELD_VALUE(PEEK32(PANEL_FB_ADDRESS),
630 PANEL_FB_ADDRESS, ADDRESS, total));
631 } else {
632 POKE32(CRT_FB_ADDRESS,
633 FIELD_VALUE(PEEK32(CRT_FB_ADDRESS),
634 CRT_FB_ADDRESS, ADDRESS, total));
635 }
636 return 0;
637}
diff --git a/drivers/staging/sm750fb/sm750_hw.h b/drivers/staging/sm750fb/sm750_hw.h
index 93288b3a99d8..3781a1a11c68 100644
--- a/drivers/staging/sm750fb/sm750_hw.h
+++ b/drivers/staging/sm750fb/sm750_hw.h
@@ -2,14 +2,14 @@
2#define LYNX_HW750_H__ 2#define LYNX_HW750_H__
3 3
4 4
5#define DEFAULT_SM750_CHIP_CLOCK 290 5#define DEFAULT_SM750_CHIP_CLOCK 290
6#define DEFAULT_SM750LE_CHIP_CLOCK 333 6#define DEFAULT_SM750LE_CHIP_CLOCK 333
7#ifndef SM750LE_REVISION_ID 7#ifndef SM750LE_REVISION_ID
8#define SM750LE_REVISION_ID (unsigned char)0xfe 8#define SM750LE_REVISION_ID (unsigned char)0xfe
9#endif 9#endif
10 10
11 11
12enum sm750_pnltype{ 12enum sm750_pnltype {
13 13
14 sm750_24TFT = 0,/* 24bit tft */ 14 sm750_24TFT = 0,/* 24bit tft */
15 15
@@ -19,30 +19,30 @@ enum sm750_pnltype{
19}; 19};
20 20
21/* vga channel is not concerned */ 21/* vga channel is not concerned */
22enum sm750_dataflow{ 22enum sm750_dataflow {
23 sm750_simul_pri,/* primary => all head */ 23 sm750_simul_pri,/* primary => all head */
24 24
25 sm750_simul_sec,/* secondary => all head */ 25 sm750_simul_sec,/* secondary => all head */
26 26
27 sm750_dual_normal,/* primary => panel head and secondary => crt */ 27 sm750_dual_normal,/* primary => panel head and secondary => crt */
28 28
29 sm750_dual_swap,/* primary => crt head and secondary => panel */ 29 sm750_dual_swap,/* primary => crt head and secondary => panel */
30}; 30};
31 31
32 32
33enum sm750_channel{ 33enum sm750_channel {
34 sm750_primary = 0, 34 sm750_primary = 0,
35 /* enum value equal to the register filed data */ 35 /* enum value equal to the register filed data */
36 sm750_secondary = 1, 36 sm750_secondary = 1,
37}; 37};
38 38
39enum sm750_path{ 39enum sm750_path {
40 sm750_panel = 1, 40 sm750_panel = 1,
41 sm750_crt = 2, 41 sm750_crt = 2,
42 sm750_pnc = 3,/* panel and crt */ 42 sm750_pnc = 3,/* panel and crt */
43}; 43};
44 44
45struct init_status{ 45struct init_status {
46 ushort powerMode; 46 ushort powerMode;
47 /* below three clocks are in unit of MHZ*/ 47 /* below three clocks are in unit of MHZ*/
48 ushort chip_clk; 48 ushort chip_clk;
@@ -52,7 +52,7 @@ struct init_status{
52 ushort resetMemory; 52 ushort resetMemory;
53}; 53};
54 54
55struct sm750_state{ 55struct sm750_state {
56 struct init_status initParm; 56 struct init_status initParm;
57 enum sm750_pnltype pnltype; 57 enum sm750_pnltype pnltype;
58 enum sm750_dataflow dataflow; 58 enum sm750_dataflow dataflow;
@@ -61,24 +61,24 @@ struct sm750_state{
61 int yLCD; 61 int yLCD;
62}; 62};
63 63
64/* sm750_share stands for a presentation of two frame buffer 64/* sm750_share stands for a presentation of two frame buffer
65 that use one sm750 adaptor, it is similar to the super class of lynx_share 65 that use one sm750 adaptor, it is similar to the super class of lynx_share
66 in C++ 66 in C++
67*/ 67 */
68 68
69struct sm750_share{ 69struct sm750_share {
70 /* it's better to put lynx_share struct to the first place of sm750_share */ 70 /* it's better to put lynx_share struct to the first place of sm750_share */
71 struct lynx_share share; 71 struct lynx_share share;
72 struct sm750_state state; 72 struct sm750_state state;
73 int hwCursor; 73 int hwCursor;
74 /* 0: no hardware cursor 74 /* 0: no hardware cursor
75 1: primary crtc hw cursor enabled, 75 1: primary crtc hw cursor enabled,
76 2: secondary crtc hw cursor enabled 76 2: secondary crtc hw cursor enabled
77 3: both ctrc hw cursor enabled 77 3: both ctrc hw cursor enabled
78 */ 78 */
79}; 79};
80 80
81int hw_sm750_map(struct lynx_share* share, struct pci_dev* pdev); 81int hw_sm750_map(struct lynx_share *share, struct pci_dev *pdev);
82int hw_sm750_inithw(struct lynx_share*, struct pci_dev *); 82int hw_sm750_inithw(struct lynx_share*, struct pci_dev *);
83void hw_sm750_initAccel(struct lynx_share *); 83void hw_sm750_initAccel(struct lynx_share *);
84int hw_sm750_deWait(void); 84int hw_sm750_deWait(void);
@@ -92,10 +92,10 @@ int hw_sm750_crtc_setMode(struct lynxfb_crtc*, struct fb_var_screeninfo*, struct
92int hw_sm750_setColReg(struct lynxfb_crtc*, ushort, ushort, ushort, ushort); 92int hw_sm750_setColReg(struct lynxfb_crtc*, ushort, ushort, ushort, ushort);
93int hw_sm750_setBLANK(struct lynxfb_output*, int); 93int hw_sm750_setBLANK(struct lynxfb_output*, int);
94int hw_sm750le_setBLANK(struct lynxfb_output*, int); 94int hw_sm750le_setBLANK(struct lynxfb_output*, int);
95void hw_sm750_crtc_clear(struct lynxfb_crtc*); 95void hw_sm750_crtc_clear(struct lynxfb_crtc *);
96void hw_sm750_output_clear(struct lynxfb_output*); 96void hw_sm750_output_clear(struct lynxfb_output *);
97int hw_sm750_pan_display(struct lynxfb_crtc *crtc, 97int hw_sm750_pan_display(struct lynxfb_crtc *crtc,
98 const struct fb_var_screeninfo *var, 98 const struct fb_var_screeninfo *var,
99 const struct fb_info *info); 99 const struct fb_info *info);
100 100
101#endif 101#endif
diff --git a/drivers/staging/sm7xxfb/Kconfig b/drivers/staging/sm7xxfb/Kconfig
deleted file mode 100644
index e2922ae3a3ee..000000000000
--- a/drivers/staging/sm7xxfb/Kconfig
+++ /dev/null
@@ -1,13 +0,0 @@
1config FB_SM7XX
2 tristate "Silicon Motion SM7XX framebuffer support"
3 depends on FB && PCI
4 select FB_CFB_FILLRECT
5 select FB_CFB_COPYAREA
6 select FB_CFB_IMAGEBLIT
7 help
8 Frame buffer driver for the Silicon Motion SM710, SM712, SM721
9 and SM722 chips.
10
11 This driver is also available as a module. The module will be
12 called sm7xxfb. If you want to compile it as a module, say M
13 here and read <file:Documentation/kbuild/modules.txt>.
diff --git a/drivers/staging/sm7xxfb/Makefile b/drivers/staging/sm7xxfb/Makefile
deleted file mode 100644
index 48f471cf9f36..000000000000
--- a/drivers/staging/sm7xxfb/Makefile
+++ /dev/null
@@ -1 +0,0 @@
1obj-$(CONFIG_FB_SM7XX) += sm7xxfb.o
diff --git a/drivers/staging/sm7xxfb/TODO b/drivers/staging/sm7xxfb/TODO
deleted file mode 100644
index 7cb0b242f204..000000000000
--- a/drivers/staging/sm7xxfb/TODO
+++ /dev/null
@@ -1,12 +0,0 @@
1TODO:
2- Dual head support
3- 2D acceleration support
4- use kernel coding style
5- refine the code and remove unused code
6- move it to drivers/video/fbdev/sm7xxfb.c
7
8Please send any patches to
9 Greg Kroah-Hartman <greg@kroah.com>
10 Sudip Mukherjee <sudipm.mukherjee@gmail.com>
11 Teddy Wang <teddy.wang@siliconmotion.com>
12 Sudip Mukherjee <sudip@vectorindia.org>
diff --git a/drivers/staging/speakup/buffers.c b/drivers/staging/speakup/buffers.c
index d45c8afb041d..d4d45989b605 100644
--- a/drivers/staging/speakup/buffers.c
+++ b/drivers/staging/speakup/buffers.c
@@ -63,7 +63,8 @@ void synth_buffer_add(char ch)
63{ 63{
64 if (!synth->alive) { 64 if (!synth->alive) {
65 /* This makes sure that we won't stop TTYs if there is no synth 65 /* This makes sure that we won't stop TTYs if there is no synth
66 * to restart them */ 66 * to restart them
67 */
67 return; 68 return;
68 } 69 }
69 if (synth_buffer_free() <= 100) { 70 if (synth_buffer_free() <= 100) {
diff --git a/drivers/staging/speakup/i18n.c b/drivers/staging/speakup/i18n.c
index 9ea16c5b4d6c..f061747546a6 100644
--- a/drivers/staging/speakup/i18n.c
+++ b/drivers/staging/speakup/i18n.c
@@ -1,5 +1,6 @@
1/* Internationalization implementation. Includes definitions of English 1/* Internationalization implementation. Includes definitions of English
2 * string arrays, and the i18n pointer. */ 2 * string arrays, and the i18n pointer.
3 */
3 4
4#include <linux/slab.h> /* For kmalloc. */ 5#include <linux/slab.h> /* For kmalloc. */
5#include <linux/ctype.h> 6#include <linux/ctype.h>
diff --git a/drivers/staging/speakup/i18n.h b/drivers/staging/speakup/i18n.h
index 326d086f9d5a..8fcce566653f 100644
--- a/drivers/staging/speakup/i18n.h
+++ b/drivers/staging/speakup/i18n.h
@@ -224,11 +224,11 @@ struct msg_group_t {
224 enum msg_index_t end; 224 enum msg_index_t end;
225}; 225};
226 226
227extern char *spk_msg_get(enum msg_index_t index); 227char *spk_msg_get(enum msg_index_t index);
228extern ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length); 228ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length);
229extern struct msg_group_t *spk_find_msg_group(const char *group_name); 229struct msg_group_t *spk_find_msg_group(const char *group_name);
230extern void spk_reset_msg_group(struct msg_group_t *group); 230void spk_reset_msg_group(struct msg_group_t *group);
231extern void spk_initialize_msgs(void); 231void spk_initialize_msgs(void);
232extern void spk_free_user_msgs(void); 232void spk_free_user_msgs(void);
233 233
234#endif 234#endif
diff --git a/drivers/staging/speakup/keyhelp.c b/drivers/staging/speakup/keyhelp.c
index 94756742136f..02d5c706aee7 100644
--- a/drivers/staging/speakup/keyhelp.c
+++ b/drivers/staging/speakup/keyhelp.c
@@ -165,7 +165,7 @@ int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key)
165 synth_printf("\n"); 165 synth_printf("\n");
166 return 1; 166 return 1;
167 } 167 }
168 cur_item = letter_offsets[ch-'a']; 168 cur_item = letter_offsets[ch-'a'];
169 } else if (type == KT_CUR) { 169 } else if (type == KT_CUR) {
170 if (ch == 0 170 if (ch == 0
171 && (MSG_FUNCNAMES_START + cur_item + 1) <= 171 && (MSG_FUNCNAMES_START + cur_item + 1) <=
diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c
index 0211df60004a..958add4839bc 100644
--- a/drivers/staging/speakup/kobjects.c
+++ b/drivers/staging/speakup/kobjects.c
@@ -240,7 +240,8 @@ static ssize_t keymap_show(struct kobject *kobj, struct kobj_attribute *attr,
240 cp += sprintf(cp, "%d, %d, %d,\n", KEY_MAP_VER, num_keys, nstates); 240 cp += sprintf(cp, "%d, %d, %d,\n", KEY_MAP_VER, num_keys, nstates);
241 cp1 += 2; /* now pointing at shift states */ 241 cp1 += 2; /* now pointing at shift states */
242 /* dump num_keys+1 as first row is shift states + flags, 242 /* dump num_keys+1 as first row is shift states + flags,
243 * each subsequent row is key + states */ 243 * each subsequent row is key + states
244 */
244 for (n = 0; n <= num_keys; n++) { 245 for (n = 0; n <= num_keys; n++) {
245 for (i = 0; i <= nstates; i++) { 246 for (i = 0; i <= nstates; i++) {
246 ch = *cp1++; 247 ch = *cp1++;
diff --git a/drivers/staging/speakup/main.c b/drivers/staging/speakup/main.c
index 6c4f9a1ed07f..63c59bc89b04 100644
--- a/drivers/staging/speakup/main.c
+++ b/drivers/staging/speakup/main.c
@@ -128,7 +128,8 @@ static char *phonetic[] = {
128 128
129/* array of 256 char pointers (one for each character description) 129/* array of 256 char pointers (one for each character description)
130 * initialized to default_chars and user selectable via 130 * initialized to default_chars and user selectable via
131 * /proc/speakup/characters */ 131 * /proc/speakup/characters
132 */
132char *spk_characters[256]; 133char *spk_characters[256];
133 134
134char *spk_default_chars[256] = { 135char *spk_default_chars[256] = {
@@ -194,7 +195,8 @@ char *spk_default_chars[256] = {
194 195
195/* array of 256 u_short (one for each character) 196/* array of 256 u_short (one for each character)
196 * initialized to default_chartab and user selectable via 197 * initialized to default_chartab and user selectable via
197 * /sys/module/speakup/parameters/chartab */ 198 * /sys/module/speakup/parameters/chartab
199 */
198u_short spk_chartab[256]; 200u_short spk_chartab[256];
199 201
200static u_short default_chartab[256] = { 202static u_short default_chartab[256] = {
@@ -540,7 +542,8 @@ static void say_next_char(struct vc_data *vc)
540 * see if there is a word starting on the next position to the right 542 * see if there is a word starting on the next position to the right
541 * and return that word if it exists. If it does not exist it will 543 * and return that word if it exists. If it does not exist it will
542 * move left to the beginning of any previous word on the line or the 544 * move left to the beginning of any previous word on the line or the
543 * beginning off the line whichever comes first.. */ 545 * beginning off the line whichever comes first..
546 */
544 547
545static u_long get_word(struct vc_data *vc) 548static u_long get_word(struct vc_data *vc)
546{ 549{
@@ -1113,7 +1116,8 @@ static void spkup_write(const char *in_buf, int count)
1113 * suppress multiple to get rid of long pauses and 1116 * suppress multiple to get rid of long pauses and
1114 * clear repeat count 1117 * clear repeat count
1115 * so if someone has 1118 * so if someone has
1116 * repeats on you don't get nothing repeated count */ 1119 * repeats on you don't get nothing repeated count
1120 */
1117 if (ch != old_ch) 1121 if (ch != old_ch)
1118 synth_printf("%c", ch); 1122 synth_printf("%c", ch);
1119 else 1123 else
@@ -1509,7 +1513,8 @@ static void do_handle_cursor(struct vc_data *vc, u_char value, char up_flag)
1509 if (spk_no_intr) 1513 if (spk_no_intr)
1510 spk_do_flush(); 1514 spk_do_flush();
1511/* the key press flushes if !no_inter but we want to flush on cursor 1515/* the key press flushes if !no_inter but we want to flush on cursor
1512 * moves regardless of no_inter state */ 1516 * moves regardless of no_inter state
1517 */
1513 is_cursor = value + 1; 1518 is_cursor = value + 1;
1514 old_cursor_pos = vc->vc_pos; 1519 old_cursor_pos = vc->vc_pos;
1515 old_cursor_x = vc->vc_x; 1520 old_cursor_x = vc->vc_x;
diff --git a/drivers/staging/speakup/selection.c b/drivers/staging/speakup/selection.c
index a0315701c7d9..98af3b1f2d2a 100644
--- a/drivers/staging/speakup/selection.c
+++ b/drivers/staging/speakup/selection.c
@@ -114,7 +114,8 @@ int speakup_set_selection(struct tty_struct *tty)
114 obp = bp; 114 obp = bp;
115 if (!((i + 2) % vc->vc_size_row)) { 115 if (!((i + 2) % vc->vc_size_row)) {
116 /* strip trailing blanks from line and add newline, 116 /* strip trailing blanks from line and add newline,
117 unless non-space at end of line. */ 117 * unless non-space at end of line.
118 */
118 if (obp != bp) { 119 if (obp != bp) {
119 bp = obp; 120 bp = obp;
120 *bp++ = '\r'; 121 *bp++ = '\r';
diff --git a/drivers/staging/speakup/serialio.c b/drivers/staging/speakup/serialio.c
index 1d9d51bdf517..66ac999a0323 100644
--- a/drivers/staging/speakup/serialio.c
+++ b/drivers/staging/speakup/serialio.c
@@ -51,7 +51,8 @@ const struct old_serial_port *spk_serial_init(int index)
51 } 51 }
52 52
53 /* Disable UART interrupts, set DTR and RTS high 53 /* Disable UART interrupts, set DTR and RTS high
54 * and set speed. */ 54 * and set speed.
55 */
55 outb(cval | UART_LCR_DLAB, ser->port + UART_LCR); /* set DLAB */ 56 outb(cval | UART_LCR_DLAB, ser->port + UART_LCR); /* set DLAB */
56 outb(quot & 0xff, ser->port + UART_DLL); /* LS of divisor */ 57 outb(quot & 0xff, ser->port + UART_DLL); /* LS of divisor */
57 outb(quot >> 8, ser->port + UART_DLM); /* MS of divisor */ 58 outb(quot >> 8, ser->port + UART_DLM); /* MS of divisor */
@@ -145,7 +146,8 @@ int spk_wait_for_xmitr(void)
145 synth->alive = 0; 146 synth->alive = 0;
146 /* No synth any more, so nobody will restart TTYs, and we thus 147 /* No synth any more, so nobody will restart TTYs, and we thus
147 * need to do it ourselves. Now that there is no synth we can 148 * need to do it ourselves. Now that there is no synth we can
148 * let application flood anyway */ 149 * let application flood anyway
150 */
149 speakup_start_ttys(); 151 speakup_start_ttys();
150 timeouts = 0; 152 timeouts = 0;
151 return 0; 153 return 0;
@@ -163,7 +165,8 @@ int spk_wait_for_xmitr(void)
163 /* CTS */ 165 /* CTS */
164 if (--tmout == 0) { 166 if (--tmout == 0) {
165 /* pr_warn("%s: timed out (cts)\n", 167 /* pr_warn("%s: timed out (cts)\n",
166 * synth->long_name); */ 168 * synth->long_name);
169 */
167 timeouts++; 170 timeouts++;
168 return 0; 171 return 0;
169 } 172 }
@@ -217,4 +220,3 @@ void spk_serial_release(void)
217 speakup_info.port_tts = 0; 220 speakup_info.port_tts = 0;
218} 221}
219EXPORT_SYMBOL_GPL(spk_serial_release); 222EXPORT_SYMBOL_GPL(spk_serial_release);
220
diff --git a/drivers/staging/speakup/speakup.h b/drivers/staging/speakup/speakup.h
index a7f4962427f3..df74c912da72 100644
--- a/drivers/staging/speakup/speakup.h
+++ b/drivers/staging/speakup/speakup.h
@@ -42,46 +42,44 @@
42#define IS_CHAR(x, type) (spk_chartab[((u_char)x)]&type) 42#define IS_CHAR(x, type) (spk_chartab[((u_char)x)]&type)
43#define IS_TYPE(x, type) ((spk_chartab[((u_char)x)]&type) == type) 43#define IS_TYPE(x, type) ((spk_chartab[((u_char)x)]&type) == type)
44 44
45extern int speakup_thread(void *data); 45int speakup_thread(void *data);
46extern void spk_reset_default_chars(void); 46void spk_reset_default_chars(void);
47extern void spk_reset_default_chartab(void); 47void spk_reset_default_chartab(void);
48extern void synth_start(void); 48void synth_start(void);
49void synth_insert_next_index(int sent_num); 49void synth_insert_next_index(int sent_num);
50void spk_reset_index_count(int sc); 50void spk_reset_index_count(int sc);
51void spk_get_index_count(int *linecount, int *sentcount); 51void spk_get_index_count(int *linecount, int *sentcount);
52extern int spk_set_key_info(const u_char *key_info, u_char *k_buffer); 52int spk_set_key_info(const u_char *key_info, u_char *k_buffer);
53extern char *spk_strlwr(char *s); 53char *spk_strlwr(char *s);
54extern char *spk_s2uchar(char *start, char *dest); 54char *spk_s2uchar(char *start, char *dest);
55extern int speakup_kobj_init(void); 55int speakup_kobj_init(void);
56extern void speakup_kobj_exit(void); 56void speakup_kobj_exit(void);
57extern int spk_chartab_get_value(char *keyword); 57int spk_chartab_get_value(char *keyword);
58extern void speakup_register_var(struct var_t *var); 58void speakup_register_var(struct var_t *var);
59extern void speakup_unregister_var(enum var_id_t var_id); 59void speakup_unregister_var(enum var_id_t var_id);
60extern struct st_var_header *spk_get_var_header(enum var_id_t var_id); 60struct st_var_header *spk_get_var_header(enum var_id_t var_id);
61extern struct st_var_header *spk_var_header_by_name(const char *name); 61struct st_var_header *spk_var_header_by_name(const char *name);
62extern struct punc_var_t *spk_get_punc_var(enum var_id_t var_id); 62struct punc_var_t *spk_get_punc_var(enum var_id_t var_id);
63extern int spk_set_num_var(int val, struct st_var_header *var, int how); 63int spk_set_num_var(int val, struct st_var_header *var, int how);
64extern int spk_set_string_var(const char *page, struct st_var_header *var, 64int spk_set_string_var(const char *page, struct st_var_header *var, int len);
65 int len); 65int spk_set_mask_bits(const char *input, const int which, const int how);
66extern int spk_set_mask_bits(const char *input, const int which, const int how);
67extern special_func spk_special_handler; 66extern special_func spk_special_handler;
68extern int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, 67int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key);
69 u_short key); 68int synth_init(char *name);
70extern int synth_init(char *name); 69void synth_release(void);
71extern void synth_release(void);
72 70
73extern void spk_do_flush(void); 71void spk_do_flush(void);
74extern void speakup_start_ttys(void); 72void speakup_start_ttys(void);
75extern void synth_buffer_add(char ch); 73void synth_buffer_add(char ch);
76extern void synth_buffer_clear(void); 74void synth_buffer_clear(void);
77extern void speakup_clear_selection(void); 75void speakup_clear_selection(void);
78extern int speakup_set_selection(struct tty_struct *tty); 76int speakup_set_selection(struct tty_struct *tty);
79extern int speakup_paste_selection(struct tty_struct *tty); 77int speakup_paste_selection(struct tty_struct *tty);
80extern void speakup_cancel_paste(void); 78void speakup_cancel_paste(void);
81extern void speakup_register_devsynth(void); 79void speakup_register_devsynth(void);
82extern void speakup_unregister_devsynth(void); 80void speakup_unregister_devsynth(void);
83extern void synth_write(const char *buf, size_t count); 81void synth_write(const char *buf, size_t count);
84extern int synth_supports_indexing(void); 82int synth_supports_indexing(void);
85 83
86extern struct vc_data *spk_sel_cons; 84extern struct vc_data *spk_sel_cons;
87extern unsigned short spk_xs, spk_ys, spk_xe, spk_ye; /* our region points */ 85extern unsigned short spk_xs, spk_ys, spk_xe, spk_ye; /* our region points */
diff --git a/drivers/staging/speakup/speakup_acnt.h b/drivers/staging/speakup/speakup_acnt.h
index 6376fca9e0e1..107ec1155f51 100644
--- a/drivers/staging/speakup/speakup_acnt.h
+++ b/drivers/staging/speakup/speakup_acnt.h
@@ -6,10 +6,12 @@
6 6
7 /* Port Status Flags */ 7 /* Port Status Flags */
8#define SYNTH_READABLE 0x01 /* mask for bit which is nonzero if a 8#define SYNTH_READABLE 0x01 /* mask for bit which is nonzero if a
9 byte can be read from the data port */ 9 * byte can be read from the data port
10 */
10#define SYNTH_WRITABLE 0x02 /* mask for RDY bit, which when set to 11#define SYNTH_WRITABLE 0x02 /* mask for RDY bit, which when set to
11 1, indicates the data port is ready 12 * 1, indicates the data port is ready
12 to accept a byte of data. */ 13 * to accept a byte of data.
14 */
13#define SYNTH_QUIET 'S' /* synth is not speaking */ 15#define SYNTH_QUIET 'S' /* synth is not speaking */
14#define SYNTH_FULL 'F' /* synth is full. */ 16#define SYNTH_FULL 'F' /* synth is full. */
15#define SYNTH_ALMOST_EMPTY 'M' /* synth has less than 2 seconds of text left */ 17#define SYNTH_ALMOST_EMPTY 'M' /* synth has less than 2 seconds of text left */
diff --git a/drivers/staging/speakup/speakup_decpc.c b/drivers/staging/speakup/speakup_decpc.c
index 437e13a85943..4893fef3f894 100644
--- a/drivers/staging/speakup/speakup_decpc.c
+++ b/drivers/staging/speakup/speakup_decpc.c
@@ -88,8 +88,9 @@
88#define CTRL_last_index 0x0b00 /* get last index spoken */ 88#define CTRL_last_index 0x0b00 /* get last index spoken */
89#define CTRL_io_priority 0x0c00 /* change i/o priority */ 89#define CTRL_io_priority 0x0c00 /* change i/o priority */
90#define CTRL_free_mem 0x0d00 /* get free paragraphs on module */ 90#define CTRL_free_mem 0x0d00 /* get free paragraphs on module */
91#define CTRL_get_lang 0x0e00 /* return bit mask of loaded 91#define CTRL_get_lang 0x0e00 /* return bit mask of loaded
92 * languages */ 92 * languages
93 */
93#define CMD_test 0x2000 /* self-test request */ 94#define CMD_test 0x2000 /* self-test request */
94#define TEST_mask 0x0F00 /* isolate test field */ 95#define TEST_mask 0x0F00 /* isolate test field */
95#define TEST_null 0x0000 /* no test requested */ 96#define TEST_null 0x0000 /* no test requested */
@@ -500,4 +501,3 @@ MODULE_AUTHOR("David Borowski");
500MODULE_DESCRIPTION("Speakup support for DECtalk PC synthesizers"); 501MODULE_DESCRIPTION("Speakup support for DECtalk PC synthesizers");
501MODULE_LICENSE("GPL"); 502MODULE_LICENSE("GPL");
502MODULE_VERSION(DRV_VERSION); 503MODULE_VERSION(DRV_VERSION);
503
diff --git a/drivers/staging/speakup/speakup_dtlk.h b/drivers/staging/speakup/speakup_dtlk.h
index d951d18c5792..46d885fcfb20 100644
--- a/drivers/staging/speakup/speakup_dtlk.h
+++ b/drivers/staging/speakup/speakup_dtlk.h
@@ -4,31 +4,37 @@
4#define SYNTH_CLEAR 0x18 /* stops speech */ 4#define SYNTH_CLEAR 0x18 /* stops speech */
5 /* TTS Port Status Flags */ 5 /* TTS Port Status Flags */
6#define TTS_READABLE 0x80 /* mask for bit which is nonzero if a 6#define TTS_READABLE 0x80 /* mask for bit which is nonzero if a
7 byte can be read from the TTS port */ 7 * byte can be read from the TTS port
8 */
8#define TTS_SPEAKING 0x40 /* mask for SYNC bit, which is nonzero 9#define TTS_SPEAKING 0x40 /* mask for SYNC bit, which is nonzero
9 while DoubleTalk is producing 10 * while DoubleTalk is producing
10 output with TTS, PCM or CVSD 11 * output with TTS, PCM or CVSD
11 synthesizers or tone generators 12 * synthesizers or tone generators
12 (that is, all but LPC) */ 13 * (that is, all but LPC)
14 */
13#define TTS_SPEAKING2 0x20 /* mask for SYNC2 bit, 15#define TTS_SPEAKING2 0x20 /* mask for SYNC2 bit,
14 which falls to zero up to 0.4 sec 16 * which falls to zero up to 0.4 sec
15 before speech stops */ 17 * before speech stops
18 */
16#define TTS_WRITABLE 0x10 /* mask for RDY bit, which when set to 19#define TTS_WRITABLE 0x10 /* mask for RDY bit, which when set to
17 1, indicates the TTS port is ready 20 * 1, indicates the TTS port is ready
18 to accept a byte of data. The RDY 21 * to accept a byte of data. The RDY
19 bit goes zero 2-3 usec after 22 * bit goes zero 2-3 usec after
20 writing, and goes 1 again 180-190 23 * writing, and goes 1 again 180-190
21 usec later. */ 24 * usec later.
25 */
22#define TTS_ALMOST_FULL 0x08 /* mask for AF bit: When set to 1, 26#define TTS_ALMOST_FULL 0x08 /* mask for AF bit: When set to 1,
23 indicates that less than 300 bytes 27 * indicates that less than 300 bytes
24 are available in the TTS input 28 * are available in the TTS input
25 buffer. AF is always 0 in the PCM, 29 * buffer. AF is always 0 in the PCM,
26 TGN and CVSD modes. */ 30 * TGN and CVSD modes.
31 */
27#define TTS_ALMOST_EMPTY 0x04 /* mask for AE bit: When set to 1, 32#define TTS_ALMOST_EMPTY 0x04 /* mask for AE bit: When set to 1,
28 indicates that less than 300 bytes 33 * indicates that less than 300 bytes
29 are remaining in DoubleTalk's input 34 * are remaining in DoubleTalk's input
30 (TTS or PCM) buffer. AE is always 1 35 * (TTS or PCM) buffer. AE is always 1
31 in the TGN and CVSD modes. */ 36 * in the TGN and CVSD modes.
37 */
32 38
33 /* data returned by Interrogate command */ 39 /* data returned by Interrogate command */
34struct synth_settings { 40struct synth_settings {
@@ -45,10 +51,12 @@ struct synth_settings {
45 u_char ext_dict_loaded; /* 1=exception dictionary loaded */ 51 u_char ext_dict_loaded; /* 1=exception dictionary loaded */
46 u_char ext_dict_status; /* 1=exception dictionary enabled */ 52 u_char ext_dict_status; /* 1=exception dictionary enabled */
47 u_char free_ram; /* # pages (truncated) remaining for 53 u_char free_ram; /* # pages (truncated) remaining for
48 * text buffer */ 54 * text buffer
55 */
49 u_char articulation; /* nA; 0-9 */ 56 u_char articulation; /* nA; 0-9 */
50 u_char reverb; /* nR; 0-9 */ 57 u_char reverb; /* nR; 0-9 */
51 u_char eob; /* 7Fh value indicating end of 58 u_char eob; /* 7Fh value indicating end of
52 * parameter block */ 59 * parameter block
60 */
53 u_char has_indexing; /* nonzero if indexing is implemented */ 61 u_char has_indexing; /* nonzero if indexing is implemented */
54}; 62};
diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
index fb31bb95d83a..366358b600a1 100644
--- a/drivers/staging/speakup/speakup_soft.c
+++ b/drivers/staging/speakup/speakup_soft.c
@@ -356,4 +356,3 @@ MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
356MODULE_DESCRIPTION("Speakup userspace software synthesizer support"); 356MODULE_DESCRIPTION("Speakup userspace software synthesizer support");
357MODULE_LICENSE("GPL"); 357MODULE_LICENSE("GPL");
358MODULE_VERSION(DRV_VERSION); 358MODULE_VERSION(DRV_VERSION);
359
diff --git a/drivers/staging/speakup/thread.c b/drivers/staging/speakup/thread.c
index d95efb702fe4..90c383ee7c3f 100644
--- a/drivers/staging/speakup/thread.c
+++ b/drivers/staging/speakup/thread.c
@@ -48,7 +48,8 @@ int speakup_thread(void *data)
48 kd_mksound(our_sound.freq, our_sound.jiffies); 48 kd_mksound(our_sound.freq, our_sound.jiffies);
49 if (synth && synth->catch_up && synth->alive) { 49 if (synth && synth->catch_up && synth->alive) {
50 /* It is up to the callee to take the lock, so that it 50 /* It is up to the callee to take the lock, so that it
51 * can sleep whenever it likes */ 51 * can sleep whenever it likes
52 */
52 synth->catch_up(synth); 53 synth->catch_up(synth);
53 } 54 }
54 55
diff --git a/drivers/staging/speakup/varhandlers.c b/drivers/staging/speakup/varhandlers.c
index 1b0d1c08741f..75bf40c14c79 100644
--- a/drivers/staging/speakup/varhandlers.c
+++ b/drivers/staging/speakup/varhandlers.c
@@ -269,7 +269,8 @@ int spk_set_string_var(const char *page, struct st_var_header *var, int len)
269/* spk_set_mask_bits sets or clears the punc/delim/repeat bits, 269/* spk_set_mask_bits sets or clears the punc/delim/repeat bits,
270 * if input is null uses the defaults. 270 * if input is null uses the defaults.
271 * values for how: 0 clears bits of chars supplied, 271 * values for how: 0 clears bits of chars supplied,
272 * 1 clears allk, 2 sets bits for chars */ 272 * 1 clears allk, 2 sets bits for chars
273 */
273int spk_set_mask_bits(const char *input, const int which, const int how) 274int spk_set_mask_bits(const char *input, const int which, const int how)
274{ 275{
275 u_char *cp; 276 u_char *cp;
diff --git a/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c b/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c
index 0f524bb7b41d..1f9ba8beb061 100644
--- a/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c
+++ b/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c
@@ -1126,7 +1126,6 @@ MODULE_DEVICE_TABLE(i2c, synaptics_rmi4_id_table);
1126static struct i2c_driver synaptics_rmi4_driver = { 1126static struct i2c_driver synaptics_rmi4_driver = {
1127 .driver = { 1127 .driver = {
1128 .name = DRIVER_NAME, 1128 .name = DRIVER_NAME,
1129 .owner = THIS_MODULE,
1130 .pm = &synaptics_rmi4_dev_pm_ops, 1129 .pm = &synaptics_rmi4_dev_pm_ops,
1131 }, 1130 },
1132 .probe = synaptics_rmi4_probe, 1131 .probe = synaptics_rmi4_probe,
diff --git a/drivers/staging/unisys/Kconfig b/drivers/staging/unisys/Kconfig
index 778f9d05f98a..624abe66c20c 100644
--- a/drivers/staging/unisys/Kconfig
+++ b/drivers/staging/unisys/Kconfig
@@ -3,7 +3,7 @@
3# 3#
4menuconfig UNISYSSPAR 4menuconfig UNISYSSPAR
5 bool "Unisys SPAR driver support" 5 bool "Unisys SPAR driver support"
6 depends on X86_64 6 depends on X86_64 && !UML
7 select PCI 7 select PCI
8 select ACPI 8 select ACPI
9 ---help--- 9 ---help---
diff --git a/drivers/staging/unisys/include/channel_guid.h b/drivers/staging/unisys/include/channel_guid.h
index 706363fc3e9a..17cb499cb53c 100644
--- a/drivers/staging/unisys/include/channel_guid.h
+++ b/drivers/staging/unisys/include/channel_guid.h
@@ -17,35 +17,31 @@
17 * CHANNEL Guids 17 * CHANNEL Guids
18 */ 18 */
19 19
20/* Used in IOChannel 20/* {414815ed-c58c-11da-95a9-00e08161165f} */
21 * {414815ed-c58c-11da-95a9-00e08161165f}
22 */
23#define SPAR_VHBA_CHANNEL_PROTOCOL_UUID \ 21#define SPAR_VHBA_CHANNEL_PROTOCOL_UUID \
24 UUID_LE(0x414815ed, 0xc58c, 0x11da, \ 22 UUID_LE(0x414815ed, 0xc58c, 0x11da, \
25 0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f) 23 0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f)
26static const uuid_le spar_vhba_channel_protocol_uuid = 24static const uuid_le spar_vhba_channel_protocol_uuid =
27 SPAR_VHBA_CHANNEL_PROTOCOL_UUID; 25 SPAR_VHBA_CHANNEL_PROTOCOL_UUID;
26#define SPAR_VHBA_CHANNEL_PROTOCOL_UUID_STR \
27 "414815ed-c58c-11da-95a9-00e08161165f"
28 28
29/* Used in IOChannel 29/* {8cd5994d-c58e-11da-95a9-00e08161165f} */
30 * {8cd5994d-c58e-11da-95a9-00e08161165f}
31 */
32#define SPAR_VNIC_CHANNEL_PROTOCOL_UUID \ 30#define SPAR_VNIC_CHANNEL_PROTOCOL_UUID \
33 UUID_LE(0x8cd5994d, 0xc58e, 0x11da, \ 31 UUID_LE(0x8cd5994d, 0xc58e, 0x11da, \
34 0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f) 32 0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f)
35static const uuid_le spar_vnic_channel_protocol_uuid = 33static const uuid_le spar_vnic_channel_protocol_uuid =
36 SPAR_VNIC_CHANNEL_PROTOCOL_UUID; 34 SPAR_VNIC_CHANNEL_PROTOCOL_UUID;
35#define SPAR_VNIC_CHANNEL_PROTOCOL_UUID_STR \
36 "8cd5994d-c58e-11da-95a9-00e08161165f"
37 37
38/* Used in IOChannel 38/* {72120008-4AAB-11DC-8530-444553544200} */
39 * {72120008-4AAB-11DC-8530-444553544200}
40 */
41#define SPAR_SIOVM_UUID \ 39#define SPAR_SIOVM_UUID \
42 UUID_LE(0x72120008, 0x4AAB, 0x11DC, \ 40 UUID_LE(0x72120008, 0x4AAB, 0x11DC, \
43 0x85, 0x30, 0x44, 0x45, 0x53, 0x54, 0x42, 0x00) 41 0x85, 0x30, 0x44, 0x45, 0x53, 0x54, 0x42, 0x00)
44static const uuid_le spar_siovm_uuid = SPAR_SIOVM_UUID; 42static const uuid_le spar_siovm_uuid = SPAR_SIOVM_UUID;
45 43
46/* Used in visornoop/visornoop_main.c 44/* {5b52c5ac-e5f5-4d42-8dff-429eaecd221f} */
47 * {5b52c5ac-e5f5-4d42-8dff-429eaecd221f}
48 */
49#define SPAR_CONTROLDIRECTOR_CHANNEL_PROTOCOL_UUID \ 45#define SPAR_CONTROLDIRECTOR_CHANNEL_PROTOCOL_UUID \
50 UUID_LE(0x5b52c5ac, 0xe5f5, 0x4d42, \ 46 UUID_LE(0x5b52c5ac, 0xe5f5, 0x4d42, \
51 0x8d, 0xff, 0x42, 0x9e, 0xae, 0xcd, 0x22, 0x1f) 47 0x8d, 0xff, 0x42, 0x9e, 0xae, 0xcd, 0x22, 0x1f)
@@ -53,9 +49,7 @@ static const uuid_le spar_siovm_uuid = SPAR_SIOVM_UUID;
53static const uuid_le spar_controldirector_channel_protocol_uuid = 49static const uuid_le spar_controldirector_channel_protocol_uuid =
54 SPAR_CONTROLDIRECTOR_CHANNEL_PROTOCOL_UUID; 50 SPAR_CONTROLDIRECTOR_CHANNEL_PROTOCOL_UUID;
55 51
56/* Used in visorchipset/visorchipset_main.c 52/* {b4e79625-aede-4eAA-9e11-D3eddcd4504c} */
57 * {B4E79625-AEDE-4EAA-9E11-D3EDDCD4504C}
58 */
59#define SPAR_DIAG_POOL_CHANNEL_PROTOCOL_UUID \ 53#define SPAR_DIAG_POOL_CHANNEL_PROTOCOL_UUID \
60 UUID_LE(0xb4e79625, 0xaede, 0x4eaa, \ 54 UUID_LE(0xb4e79625, 0xaede, 0x4eaa, \
61 0x9e, 0x11, 0xd3, 0xed, 0xdc, 0xd4, 0x50, 0x4c) 55 0x9e, 0x11, 0xd3, 0xed, 0xdc, 0xd4, 0x50, 0x4c)
diff --git a/drivers/staging/unisys/include/visorbus.h b/drivers/staging/unisys/include/visorbus.h
index e4a21e42e868..9235536fa75f 100644
--- a/drivers/staging/unisys/include/visorbus.h
+++ b/drivers/staging/unisys/include/visorbus.h
@@ -113,7 +113,8 @@ struct visor_driver {
113 struct driver_attribute version_attr; 113 struct driver_attribute version_attr;
114}; 114};
115 115
116#define to_visor_driver(x) container_of(x, struct visor_driver, driver) 116#define to_visor_driver(x) ((x) ? \
117 (container_of(x, struct visor_driver, driver)) : (NULL))
117 118
118/** A device type for things "plugged" into the visorbus bus */ 119/** A device type for things "plugged" into the visorbus bus */
119 120
@@ -200,6 +201,8 @@ bool visorchannel_signalremove(struct visorchannel *channel, u32 queue,
200 void *msg); 201 void *msg);
201bool visorchannel_signalinsert(struct visorchannel *channel, u32 queue, 202bool visorchannel_signalinsert(struct visorchannel *channel, u32 queue,
202 void *msg); 203 void *msg);
204bool visorchannel_signalempty(struct visorchannel *channel, u32 queue);
205
203int visorchannel_signalqueue_slots_avail(struct visorchannel *channel, 206int visorchannel_signalqueue_slots_avail(struct visorchannel *channel,
204 u32 queue); 207 u32 queue);
205int visorchannel_signalqueue_max_slots(struct visorchannel *channel, u32 queue); 208int visorchannel_signalqueue_max_slots(struct visorchannel *channel, u32 queue);
diff --git a/drivers/staging/unisys/visorbus/controlvmchannel.h b/drivers/staging/unisys/visorbus/controlvmchannel.h
index a50d9cf4bed7..ec25366b127c 100644
--- a/drivers/staging/unisys/visorbus/controlvmchannel.h
+++ b/drivers/staging/unisys/visorbus/controlvmchannel.h
@@ -1,10 +1,9 @@
1/* Copyright (C) 2010 - 2013 UNISYS CORPORATION 1/* Copyright (C) 2010 - 2015 UNISYS CORPORATION
2 * All rights reserved. 2 * All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify it
5 * it under the terms of the GNU General Public License as published by 5 * under the terms and conditions of the GNU General Public License,
6 * the Free Software Foundation; either version 2 of the License, or (at 6 * version 2, as published by the Free Software Foundation.
7 * your option) any later version.
8 * 7 *
9 * This program is distributed in the hope that it will be useful, but 8 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of 9 * WITHOUT ANY WARRANTY; without even the implied warranty of
diff --git a/drivers/staging/unisys/visorbus/controlvmcompletionstatus.h b/drivers/staging/unisys/visorbus/controlvmcompletionstatus.h
index f74f5d8c2820..3c97ebac4f32 100644
--- a/drivers/staging/unisys/visorbus/controlvmcompletionstatus.h
+++ b/drivers/staging/unisys/visorbus/controlvmcompletionstatus.h
@@ -1,12 +1,11 @@
1/* controlvmcompletionstatus.c 1/* controlvmcompletionstatus.c
2 * 2 *
3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION 3 * Copyright (C) 2010 - 2015 UNISYS CORPORATION
4 * All Rights Reserved. 4 * All Rights Reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify it
7 * it under the terms of the GNU General Public License as published by 7 * under the terms and conditions of the GNU General Public License,
8 * the Free Software Foundation; either version 2 of the License, or (at 8 * version 2, as published by the Free Software Foundation.
9 * your option) any later version.
10 * 9 *
11 * This program is distributed in the hope that it will be useful, but 10 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * WITHOUT ANY WARRANTY; without even the implied warranty of
diff --git a/drivers/staging/unisys/visorbus/iovmcall_gnuc.h b/drivers/staging/unisys/visorbus/iovmcall_gnuc.h
index 57dd93e0cc83..b08b6ecc8d31 100644
--- a/drivers/staging/unisys/visorbus/iovmcall_gnuc.h
+++ b/drivers/staging/unisys/visorbus/iovmcall_gnuc.h
@@ -1,10 +1,9 @@
1/* Copyright (C) 2010 - 2013 UNISYS CORPORATION 1/* Copyright (C) 2010 - 2015 UNISYS CORPORATION
2 * All rights reserved. 2 * All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify it
5 * it under the terms of the GNU General Public License as published by 5 * under the terms and conditions of the GNU General Public License,
6 * the Free Software Foundation; either version 2 of the License, or (at 6 * version 2, as published by the Free Software Foundation.
7 * your option) any later version.
8 * 7 *
9 * This program is distributed in the hope that it will be useful, but 8 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of 9 * WITHOUT ANY WARRANTY; without even the implied warranty of
diff --git a/drivers/staging/unisys/visorbus/periodic_work.c b/drivers/staging/unisys/visorbus/periodic_work.c
index 5e56088cf855..a3631c3591f6 100644
--- a/drivers/staging/unisys/visorbus/periodic_work.c
+++ b/drivers/staging/unisys/visorbus/periodic_work.c
@@ -1,12 +1,11 @@
1/* periodic_work.c 1/* periodic_work.c
2 * 2 *
3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION 3 * Copyright (C) 2010 - 2015 UNISYS CORPORATION
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify it
7 * it under the terms of the GNU General Public License as published by 7 * under the terms and conditions of the GNU General Public License,
8 * the Free Software Foundation; either version 2 of the License, or (at 8 * version 2, as published by the Free Software Foundation.
9 * your option) any later version.
10 * 9 *
11 * This program is distributed in the hope that it will be useful, but 10 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * WITHOUT ANY WARRANTY; without even the implied warranty of
diff --git a/drivers/staging/unisys/visorbus/vbuschannel.h b/drivers/staging/unisys/visorbus/vbuschannel.h
index 5ed83a3f1428..80e64477e547 100644
--- a/drivers/staging/unisys/visorbus/vbuschannel.h
+++ b/drivers/staging/unisys/visorbus/vbuschannel.h
@@ -1,10 +1,9 @@
1/* Copyright (C) 2010 - 2013 UNISYS CORPORATION 1/* Copyright (C) 2010 - 2015 UNISYS CORPORATION
2 * All rights reserved. 2 * All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify it
5 * it under the terms of the GNU General Public License as published by 5 * under the terms and conditions of the GNU General Public License,
6 * the Free Software Foundation; either version 2 of the License, or (at 6 * version 2, as published by the Free Software Foundation.
7 * your option) any later version.
8 * 7 *
9 * This program is distributed in the hope that it will be useful, but 8 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of 9 * WITHOUT ANY WARRANTY; without even the implied warranty of
diff --git a/drivers/staging/unisys/visorbus/vbusdeviceinfo.h b/drivers/staging/unisys/visorbus/vbusdeviceinfo.h
index 9b6d3e69355c..f59fd8a523c4 100644
--- a/drivers/staging/unisys/visorbus/vbusdeviceinfo.h
+++ b/drivers/staging/unisys/visorbus/vbusdeviceinfo.h
@@ -1,10 +1,9 @@
1/* Copyright (C) 2010 - 2013 UNISYS CORPORATION 1/* Copyright (C) 2010 - 2015 UNISYS CORPORATION
2 * All rights reserved. 2 * All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify it
5 * it under the terms of the GNU General Public License as published by 5 * under the terms and conditions of the GNU General Public License,
6 * the Free Software Foundation; either version 2 of the License, or (at 6 * version 2, as published by the Free Software Foundation.
7 * your option) any later version.
8 * 7 *
9 * This program is distributed in the hope that it will be useful, but 8 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of 9 * WITHOUT ANY WARRANTY; without even the implied warranty of
diff --git a/drivers/staging/unisys/visorbus/visorbus_main.c b/drivers/staging/unisys/visorbus/visorbus_main.c
index 6db47196c189..2309f5f2b238 100644
--- a/drivers/staging/unisys/visorbus/visorbus_main.c
+++ b/drivers/staging/unisys/visorbus/visorbus_main.c
@@ -1,12 +1,11 @@
1/* visorbus_main.c 1/* visorbus_main.c
2 * 2 *
3 * Copyright � 2010 - 2013 UNISYS CORPORATION 3 * Copyright � 2010 - 2015 UNISYS CORPORATION
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify it
7 * it under the terms of the GNU General Public License as published by 7 * under the terms and conditions of the GNU General Public License,
8 * the Free Software Foundation; either version 2 of the License, or (at 8 * version 2, as published by the Free Software Foundation.
9 * your option) any later version.
10 * 9 *
11 * This program is distributed in the hope that it will be useful, but 10 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -70,6 +69,38 @@ static const struct attribute_group *visorbus_bus_groups[] = {
70 NULL, 69 NULL,
71}; 70};
72 71
72/*
73 * DEVICE type attributes
74 *
75 * The modalias file will contain the guid of the device.
76 */
77static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
78 char *buf)
79{
80 struct visor_device *vdev;
81 uuid_le guid;
82
83 vdev = to_visor_device(dev);
84 guid = visorchannel_get_uuid(vdev->visorchannel);
85 return snprintf(buf, PAGE_SIZE, "visorbus:%pUl\n", &guid);
86}
87static DEVICE_ATTR_RO(modalias);
88
89static struct attribute *visorbus_dev_attrs[] = {
90 &dev_attr_modalias.attr,
91 NULL,
92};
93
94/* sysfs example for bridge-only sysfs files using device_type's */
95static const struct attribute_group visorbus_dev_group = {
96 .attrs = visorbus_dev_attrs,
97};
98
99static const struct attribute_group *visorbus_dev_groups[] = {
100 &visorbus_dev_group,
101 NULL,
102};
103
73/** This describes the TYPE of bus. 104/** This describes the TYPE of bus.
74 * (Don't confuse this with an INSTANCE of the bus.) 105 * (Don't confuse this with an INSTANCE of the bus.)
75 */ 106 */
@@ -77,6 +108,7 @@ struct bus_type visorbus_type = {
77 .name = "visorbus", 108 .name = "visorbus",
78 .match = visorbus_match, 109 .match = visorbus_match,
79 .uevent = visorbus_uevent, 110 .uevent = visorbus_uevent,
111 .dev_groups = visorbus_dev_groups,
80 .bus_groups = visorbus_bus_groups, 112 .bus_groups = visorbus_bus_groups,
81}; 113};
82 114
@@ -129,7 +161,13 @@ static LIST_HEAD(list_all_device_instances);
129static int 161static int
130visorbus_uevent(struct device *xdev, struct kobj_uevent_env *env) 162visorbus_uevent(struct device *xdev, struct kobj_uevent_env *env)
131{ 163{
132 if (add_uevent_var(env, "VERSION=%s", VERSION)) 164 struct visor_device *dev;
165 uuid_le guid;
166
167 dev = to_visor_device(xdev);
168 guid = visorchannel_get_uuid(dev->visorchannel);
169
170 if (add_uevent_var(env, "MODALIAS=visorbus:%pUl", &guid))
133 return -ENOMEM; 171 return -ENOMEM;
134 return 0; 172 return 0;
135} 173}
@@ -218,9 +256,9 @@ visorbus_release_device(struct device *xdev)
218struct devmajorminor_attribute { 256struct devmajorminor_attribute {
219 struct attribute attr; 257 struct attribute attr;
220 int slot; 258 int slot;
221 ssize_t (*show)(struct visor_device *, int slot, char *buf); 259 ssize_t (*show)(struct visor_device *, int slot, char *buf);
222 ssize_t (*store)(struct visor_device *, int slot, const char *buf, 260 ssize_t (*store)(struct visor_device *, int slot, const char *buf,
223 size_t count); 261 size_t count);
224}; 262};
225 263
226static ssize_t DEVMAJORMINOR_ATTR(struct visor_device *dev, int slot, char *buf) 264static ssize_t DEVMAJORMINOR_ATTR(struct visor_device *dev, int slot, char *buf)
@@ -281,12 +319,11 @@ devmajorminor_create_file(struct visor_device *dev, const char *name,
281 rc = -ENOMEM; 319 rc = -ENOMEM;
282 goto away; 320 goto away;
283 } 321 }
284 myattr = kmalloc(sizeof(*myattr), GFP_KERNEL); 322 myattr = kzalloc(sizeof(*myattr), GFP_KERNEL);
285 if (!myattr) { 323 if (!myattr) {
286 rc = -ENOMEM; 324 rc = -ENOMEM;
287 goto away; 325 goto away;
288 } 326 }
289 memset(myattr, 0, sizeof(struct devmajorminor_attribute));
290 myattr->show = DEVMAJORMINOR_ATTR; 327 myattr->show = DEVMAJORMINOR_ATTR;
291 myattr->store = NULL; 328 myattr->store = NULL;
292 myattr->slot = slot; 329 myattr->slot = slot;
@@ -471,6 +508,7 @@ static struct attribute *channel_attrs[] = {
471 &dev_attr_typeguid.attr, 508 &dev_attr_typeguid.attr,
472 &dev_attr_zoneguid.attr, 509 &dev_attr_zoneguid.attr,
473 &dev_attr_typename.attr, 510 &dev_attr_typename.attr,
511 NULL
474}; 512};
475 513
476static struct attribute_group channel_attr_grp = { 514static struct attribute_group channel_attr_grp = {
@@ -478,7 +516,7 @@ static struct attribute_group channel_attr_grp = {
478 .attrs = channel_attrs, 516 .attrs = channel_attrs,
479}; 517};
480 518
481static const struct attribute_group *visorbus_dev_groups[] = { 519static const struct attribute_group *visorbus_channel_groups[] = {
482 &channel_attr_grp, 520 &channel_attr_grp,
483 NULL 521 NULL
484}; 522};
@@ -678,7 +716,7 @@ unregister_driver_attributes(struct visor_driver *drv)
678static void 716static void
679dev_periodic_work(void *xdev) 717dev_periodic_work(void *xdev)
680{ 718{
681 struct visor_device *dev = (struct visor_device *)xdev; 719 struct visor_device *dev = xdev;
682 struct visor_driver *drv = to_visor_driver(dev->device.driver); 720 struct visor_driver *drv = to_visor_driver(dev->device.driver);
683 721
684 down(&dev->visordriver_callback_lock); 722 down(&dev->visordriver_callback_lock);
@@ -937,7 +975,7 @@ create_visor_device(struct visor_device *dev)
937 975
938 sema_init(&dev->visordriver_callback_lock, 1); /* unlocked */ 976 sema_init(&dev->visordriver_callback_lock, 1); /* unlocked */
939 dev->device.bus = &visorbus_type; 977 dev->device.bus = &visorbus_type;
940 dev->device.groups = visorbus_dev_groups; 978 dev->device.groups = visorbus_channel_groups;
941 device_initialize(&dev->device); 979 device_initialize(&dev->device);
942 dev->device.release = visorbus_release_device; 980 dev->device.release = visorbus_release_device;
943 /* keep a reference just for us (now 2) */ 981 /* keep a reference just for us (now 2) */
@@ -1043,10 +1081,10 @@ write_vbus_chp_info(struct visorchannel *chan,
1043 int off = sizeof(struct channel_header) + hdr_info->chp_info_offset; 1081 int off = sizeof(struct channel_header) + hdr_info->chp_info_offset;
1044 1082
1045 if (hdr_info->chp_info_offset == 0) 1083 if (hdr_info->chp_info_offset == 0)
1046 return -1; 1084 return -1;
1047 1085
1048 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0) 1086 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0)
1049 return -1; 1087 return -1;
1050 return 0; 1088 return 0;
1051} 1089}
1052 1090
@@ -1061,10 +1099,10 @@ write_vbus_bus_info(struct visorchannel *chan,
1061 int off = sizeof(struct channel_header) + hdr_info->bus_info_offset; 1099 int off = sizeof(struct channel_header) + hdr_info->bus_info_offset;
1062 1100
1063 if (hdr_info->bus_info_offset == 0) 1101 if (hdr_info->bus_info_offset == 0)
1064 return -1; 1102 return -1;
1065 1103
1066 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0) 1104 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0)
1067 return -1; 1105 return -1;
1068 return 0; 1106 return 0;
1069} 1107}
1070 1108
@@ -1081,10 +1119,10 @@ write_vbus_dev_info(struct visorchannel *chan,
1081 (hdr_info->device_info_struct_bytes * devix); 1119 (hdr_info->device_info_struct_bytes * devix);
1082 1120
1083 if (hdr_info->dev_info_offset == 0) 1121 if (hdr_info->dev_info_offset == 0)
1084 return -1; 1122 return -1;
1085 1123
1086 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0) 1124 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0)
1087 return -1; 1125 return -1;
1088 return 0; 1126 return 0;
1089} 1127}
1090 1128
@@ -1106,7 +1144,7 @@ fix_vbus_dev_info(struct visor_device *visordev)
1106 struct spar_vbus_headerinfo *hdr_info; 1144 struct spar_vbus_headerinfo *hdr_info;
1107 1145
1108 if (!visordev->device.driver) 1146 if (!visordev->device.driver)
1109 return; 1147 return;
1110 1148
1111 hdr_info = (struct spar_vbus_headerinfo *)visordev->vbus_hdr_info; 1149 hdr_info = (struct spar_vbus_headerinfo *)visordev->vbus_hdr_info;
1112 if (!hdr_info) 1150 if (!hdr_info)
@@ -1319,11 +1357,11 @@ static void
1319pause_state_change_complete(struct visor_device *dev, int status) 1357pause_state_change_complete(struct visor_device *dev, int status)
1320{ 1358{
1321 if (!dev->pausing) 1359 if (!dev->pausing)
1322 return; 1360 return;
1323 1361
1324 dev->pausing = false; 1362 dev->pausing = false;
1325 if (!chipset_responders.device_pause) /* this can never happen! */ 1363 if (!chipset_responders.device_pause) /* this can never happen! */
1326 return; 1364 return;
1327 1365
1328 /* Notify the chipset driver that the pause is complete, which 1366 /* Notify the chipset driver that the pause is complete, which
1329 * will presumably want to send some sort of response to the 1367 * will presumably want to send some sort of response to the
@@ -1339,11 +1377,11 @@ static void
1339resume_state_change_complete(struct visor_device *dev, int status) 1377resume_state_change_complete(struct visor_device *dev, int status)
1340{ 1378{
1341 if (!dev->resuming) 1379 if (!dev->resuming)
1342 return; 1380 return;
1343 1381
1344 dev->resuming = false; 1382 dev->resuming = false;
1345 if (!chipset_responders.device_resume) /* this can never happen! */ 1383 if (!chipset_responders.device_resume) /* this can never happen! */
1346 return; 1384 return;
1347 1385
1348 /* Notify the chipset driver that the resume is complete, 1386 /* Notify the chipset driver that the resume is complete,
1349 * which will presumably want to send some sort of response to 1387 * which will presumably want to send some sort of response to
@@ -1367,14 +1405,14 @@ initiate_chipset_device_pause_resume(struct visor_device *dev, bool is_pause)
1367 else 1405 else
1368 notify_func = chipset_responders.device_resume; 1406 notify_func = chipset_responders.device_resume;
1369 if (!notify_func) 1407 if (!notify_func)
1370 goto away; 1408 goto away;
1371 1409
1372 drv = to_visor_driver(dev->device.driver); 1410 drv = to_visor_driver(dev->device.driver);
1373 if (!drv) 1411 if (!drv)
1374 goto away; 1412 goto away;
1375 1413
1376 if (dev->pausing || dev->resuming) 1414 if (dev->pausing || dev->resuming)
1377 goto away; 1415 goto away;
1378 1416
1379 /* Note that even though both drv->pause() and drv->resume 1417 /* Note that even though both drv->pause() and drv->resume
1380 * specify a callback function, it is NOT necessary for us to 1418 * specify a callback function, it is NOT necessary for us to
@@ -1385,7 +1423,7 @@ initiate_chipset_device_pause_resume(struct visor_device *dev, bool is_pause)
1385 */ 1423 */
1386 if (is_pause) { 1424 if (is_pause) {
1387 if (!drv->pause) 1425 if (!drv->pause)
1388 goto away; 1426 goto away;
1389 1427
1390 dev->pausing = true; 1428 dev->pausing = true;
1391 x = drv->pause(dev, pause_state_change_complete); 1429 x = drv->pause(dev, pause_state_change_complete);
@@ -1397,7 +1435,7 @@ initiate_chipset_device_pause_resume(struct visor_device *dev, bool is_pause)
1397 * would never even get here in that case. */ 1435 * would never even get here in that case. */
1398 fix_vbus_dev_info(dev); 1436 fix_vbus_dev_info(dev);
1399 if (!drv->resume) 1437 if (!drv->resume)
1400 goto away; 1438 goto away;
1401 1439
1402 dev->resuming = true; 1440 dev->resuming = true;
1403 x = drv->resume(dev, resume_state_change_complete); 1441 x = drv->resume(dev, resume_state_change_complete);
@@ -1413,7 +1451,7 @@ initiate_chipset_device_pause_resume(struct visor_device *dev, bool is_pause)
1413away: 1451away:
1414 if (rc < 0) { 1452 if (rc < 0) {
1415 if (notify_func) 1453 if (notify_func)
1416 (*notify_func)(dev, rc); 1454 (*notify_func)(dev, rc);
1417 } 1455 }
1418} 1456}
1419 1457
@@ -1469,8 +1507,8 @@ visorbus_init(void)
1469 1507
1470away: 1508away:
1471 if (rc) 1509 if (rc)
1472 POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, rc, 1510 POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, rc,
1473 POSTCODE_SEVERITY_ERR); 1511 POSTCODE_SEVERITY_ERR);
1474 return rc; 1512 return rc;
1475} 1513}
1476 1514
@@ -1495,9 +1533,8 @@ visorbus_exit(void)
1495 1533
1496 list_for_each_safe(listentry, listtmp, &list_all_bus_instances) { 1534 list_for_each_safe(listentry, listtmp, &list_all_bus_instances) {
1497 struct visor_device *dev = list_entry(listentry, 1535 struct visor_device *dev = list_entry(listentry,
1498 struct 1536 struct visor_device,
1499 visor_device, 1537 list_all);
1500 list_all);
1501 remove_bus_instance(dev); 1538 remove_bus_instance(dev);
1502 } 1539 }
1503 remove_bus_type(); 1540 remove_bus_type();
diff --git a/drivers/staging/unisys/visorbus/visorbus_private.h b/drivers/staging/unisys/visorbus/visorbus_private.h
index 2f12483e38ab..39edd2018453 100644
--- a/drivers/staging/unisys/visorbus/visorbus_private.h
+++ b/drivers/staging/unisys/visorbus/visorbus_private.h
@@ -1,12 +1,11 @@
1/* visorchipset.h 1/* visorchipset.h
2 * 2 *
3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION 3 * Copyright (C) 2010 - 2015 UNISYS CORPORATION
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify it
7 * it under the terms of the GNU General Public License as published by 7 * under the terms and conditions of the GNU General Public License,
8 * the Free Software Foundation; either version 2 of the License, or (at 8 * version 2, as published by the Free Software Foundation.
9 * your option) any later version.
10 * 9 *
11 * This program is distributed in the hope that it will be useful, but 10 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * WITHOUT ANY WARRANTY; without even the implied warranty of
diff --git a/drivers/staging/unisys/visorbus/visorchannel.c b/drivers/staging/unisys/visorbus/visorchannel.c
index 20b63496e9f2..6da7e49a6627 100644
--- a/drivers/staging/unisys/visorbus/visorchannel.c
+++ b/drivers/staging/unisys/visorbus/visorchannel.c
@@ -1,12 +1,11 @@
1/* visorchannel_funcs.c 1/* visorchannel_funcs.c
2 * 2 *
3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION 3 * Copyright (C) 2010 - 2015 UNISYS CORPORATION
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify it
7 * it under the terms of the GNU General Public License as published by 7 * under the terms and conditions of the GNU General Public License,
8 * the Free Software Foundation; either version 2 of the License, or (at 8 * version 2, as published by the Free Software Foundation.
9 * your option) any later version.
10 * 9 *
11 * This program is distributed in the hope that it will be useful, but 10 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -259,7 +258,8 @@ visorchannel_write(struct visorchannel *channel, ulong offset,
259 258
260 if (offset < chdr_size) { 259 if (offset < chdr_size) {
261 copy_size = min(chdr_size - offset, nbytes); 260 copy_size = min(chdr_size - offset, nbytes);
262 memcpy(&channel->chan_hdr + offset, local, copy_size); 261 memcpy(((char *)(&channel->chan_hdr)) + offset,
262 local, copy_size);
263 } 263 }
264 264
265 memcpy_toio(channel->mapped + offset, local, nbytes); 265 memcpy_toio(channel->mapped + offset, local, nbytes);
@@ -416,11 +416,12 @@ bool
416visorchannel_signalremove(struct visorchannel *channel, u32 queue, void *msg) 416visorchannel_signalremove(struct visorchannel *channel, u32 queue, void *msg)
417{ 417{
418 bool rc; 418 bool rc;
419 unsigned long flags;
419 420
420 if (channel->needs_lock) { 421 if (channel->needs_lock) {
421 spin_lock(&channel->remove_lock); 422 spin_lock_irqsave(&channel->remove_lock, flags);
422 rc = signalremove_inner(channel, queue, msg); 423 rc = signalremove_inner(channel, queue, msg);
423 spin_unlock(&channel->remove_lock); 424 spin_unlock_irqrestore(&channel->remove_lock, flags);
424 } else { 425 } else {
425 rc = signalremove_inner(channel, queue, msg); 426 rc = signalremove_inner(channel, queue, msg);
426 } 427 }
@@ -429,6 +430,27 @@ visorchannel_signalremove(struct visorchannel *channel, u32 queue, void *msg)
429} 430}
430EXPORT_SYMBOL_GPL(visorchannel_signalremove); 431EXPORT_SYMBOL_GPL(visorchannel_signalremove);
431 432
433bool
434visorchannel_signalempty(struct visorchannel *channel, u32 queue)
435{
436 unsigned long flags = 0;
437 struct signal_queue_header sig_hdr;
438 bool rc = false;
439
440 if (channel->needs_lock)
441 spin_lock_irqsave(&channel->remove_lock, flags);
442
443 if (!sig_read_header(channel, queue, &sig_hdr))
444 rc = true;
445 if (sig_hdr.head == sig_hdr.tail)
446 rc = true;
447 if (channel->needs_lock)
448 spin_unlock_irqrestore(&channel->remove_lock, flags);
449
450 return rc;
451}
452EXPORT_SYMBOL_GPL(visorchannel_signalempty);
453
432static bool 454static bool
433signalinsert_inner(struct visorchannel *channel, u32 queue, void *msg) 455signalinsert_inner(struct visorchannel *channel, u32 queue, void *msg)
434{ 456{
@@ -470,11 +492,12 @@ bool
470visorchannel_signalinsert(struct visorchannel *channel, u32 queue, void *msg) 492visorchannel_signalinsert(struct visorchannel *channel, u32 queue, void *msg)
471{ 493{
472 bool rc; 494 bool rc;
495 unsigned long flags;
473 496
474 if (channel->needs_lock) { 497 if (channel->needs_lock) {
475 spin_lock(&channel->insert_lock); 498 spin_lock_irqsave(&channel->insert_lock, flags);
476 rc = signalinsert_inner(channel, queue, msg); 499 rc = signalinsert_inner(channel, queue, msg);
477 spin_unlock(&channel->insert_lock); 500 spin_unlock_irqrestore(&channel->insert_lock, flags);
478 } else { 501 } else {
479 rc = signalinsert_inner(channel, queue, msg); 502 rc = signalinsert_inner(channel, queue, msg);
480 } 503 }
diff --git a/drivers/staging/unisys/visorbus/visorchipset.c b/drivers/staging/unisys/visorbus/visorchipset.c
index bb8087e70127..4b76cb441ed4 100644
--- a/drivers/staging/unisys/visorbus/visorchipset.c
+++ b/drivers/staging/unisys/visorbus/visorchipset.c
@@ -1,12 +1,11 @@
1/* visorchipset_main.c 1/* visorchipset_main.c
2 * 2 *
3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION 3 * Copyright (C) 2010 - 2015 UNISYS CORPORATION
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify it
7 * it under the terms of the GNU General Public License as published by 7 * under the terms and conditions of the GNU General Public License,
8 * the Free Software Foundation; either version 2 of the License, or (at 8 * version 2, as published by the Free Software Foundation.
9 * your option) any later version.
10 * 9 *
11 * This program is distributed in the hope that it will be useful, but 10 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -1247,10 +1246,11 @@ my_device_create(struct controlvm_message *inmsg)
1247 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, dev_no, bus_no, 1246 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, dev_no, bus_no,
1248 POSTCODE_SEVERITY_INFO); 1247 POSTCODE_SEVERITY_INFO);
1249 1248
1250 visorchannel = visorchannel_create(cmd->create_device.channel_addr, 1249 visorchannel =
1251 cmd->create_device.channel_bytes, 1250 visorchannel_create_with_lock(cmd->create_device.channel_addr,
1252 GFP_KERNEL, 1251 cmd->create_device.channel_bytes,
1253 cmd->create_device.data_type_uuid); 1252 GFP_KERNEL,
1253 cmd->create_device.data_type_uuid);
1254 1254
1255 if (!visorchannel) { 1255 if (!visorchannel) {
1256 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, 1256 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
@@ -2047,6 +2047,7 @@ device_create_response(struct visor_device *dev_info, int response)
2047 response); 2047 response);
2048 2048
2049 kfree(dev_info->pending_msg_hdr); 2049 kfree(dev_info->pending_msg_hdr);
2050 dev_info->pending_msg_hdr = NULL;
2050} 2051}
2051 2052
2052static void 2053static void
@@ -2381,6 +2382,9 @@ static struct acpi_driver unisys_acpi_driver = {
2381 .remove = visorchipset_exit, 2382 .remove = visorchipset_exit,
2382 }, 2383 },
2383}; 2384};
2385
2386MODULE_DEVICE_TABLE(acpi, unisys_device_ids);
2387
2384static __init uint32_t visorutil_spar_detect(void) 2388static __init uint32_t visorutil_spar_detect(void)
2385{ 2389{
2386 unsigned int eax, ebx, ecx, edx; 2390 unsigned int eax, ebx, ecx, edx;
diff --git a/drivers/staging/unisys/visorbus/vmcallinterface.h b/drivers/staging/unisys/visorbus/vmcallinterface.h
index 7a53df00726a..7abd27a618f8 100644
--- a/drivers/staging/unisys/visorbus/vmcallinterface.h
+++ b/drivers/staging/unisys/visorbus/vmcallinterface.h
@@ -1,10 +1,9 @@
1/* Copyright (C) 2010 - 2013 UNISYS CORPORATION 1/* Copyright (C) 2010 - 2015 UNISYS CORPORATION
2 * All rights reserved. 2 * All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify it
5 * it under the terms of the GNU General Public License as published by 5 * under the terms and conditions of the GNU General Public License,
6 * the Free Software Foundation; either version 2 of the License, or (at 6 * version 2, as published by the Free Software Foundation.
7 * your option) any later version.
8 * 7 *
9 * This program is distributed in the hope that it will be useful, but 8 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of 9 * WITHOUT ANY WARRANTY; without even the implied warranty of
diff --git a/drivers/staging/unisys/visornic/visornic_main.c b/drivers/staging/unisys/visornic/visornic_main.c
index 710074437737..8c9da7ea7845 100644
--- a/drivers/staging/unisys/visornic/visornic_main.c
+++ b/drivers/staging/unisys/visornic/visornic_main.c
@@ -1,10 +1,9 @@
1/* Copyright (c) 2012 - 2015 UNISYS CORPORATION 1/* Copyright (c) 2012 - 2015 UNISYS CORPORATION
2 * All rights reserved. 2 * All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify it
5 * it under the terms of the GNU General Public License as published by 5 * under the terms and conditions of the GNU General Public License,
6 * the Free Software Foundation; either version 2 of the License, or (at 6 * version 2, as published by the Free Software Foundation.
7 * your option) any later version.
8 * 7 *
9 * This program is distributed in the hope that it will be useful, but 8 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of 9 * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,15 +19,16 @@
20 */ 19 */
21 20
22#include <linux/debugfs.h> 21#include <linux/debugfs.h>
23#include <linux/netdevice.h>
24#include <linux/etherdevice.h> 22#include <linux/etherdevice.h>
25#include <linux/skbuff.h> 23#include <linux/netdevice.h>
26#include <linux/kthread.h> 24#include <linux/kthread.h>
25#include <linux/skbuff.h>
26#include <linux/rtnetlink.h>
27 27
28#include "visorbus.h" 28#include "visorbus.h"
29#include "iochannel.h" 29#include "iochannel.h"
30 30
31#define VISORNIC_INFINITE_RESPONSE_WAIT 0 31#define VISORNIC_INFINITE_RSP_WAIT 0
32#define VISORNICSOPENMAX 32 32#define VISORNICSOPENMAX 32
33#define MAXDEVICES 16384 33#define MAXDEVICES 16384
34 34
@@ -61,7 +61,6 @@ static const struct file_operations debugfs_enable_ints_fops = {
61 .write = enable_ints_write, 61 .write = enable_ints_write,
62}; 62};
63 63
64static struct workqueue_struct *visornic_serverdown_workqueue;
65static struct workqueue_struct *visornic_timeout_reset_workqueue; 64static struct workqueue_struct *visornic_timeout_reset_workqueue;
66 65
67/* GUIDS for director channel type supported by this driver. */ 66/* GUIDS for director channel type supported by this driver. */
@@ -72,6 +71,15 @@ static struct visor_channeltype_descriptor visornic_channel_types[] = {
72 { SPAR_VNIC_CHANNEL_PROTOCOL_UUID, "ultravnic" }, 71 { SPAR_VNIC_CHANNEL_PROTOCOL_UUID, "ultravnic" },
73 { NULL_UUID_LE, NULL } 72 { NULL_UUID_LE, NULL }
74}; 73};
74MODULE_DEVICE_TABLE(visorbus, visornic_channel_types);
75/*
76 * FIXME XXX: This next line of code must be fixed and removed before
77 * acceptance into the 'normal' part of the kernel. It is only here as a place
78 * holder to get module autoloading functionality working for visorbus. Code
79 * must be added to scripts/mode/file2alias.c, etc., to get this working
80 * properly.
81 */
82MODULE_ALIAS("visorbus:" SPAR_VNIC_CHANNEL_PROTOCOL_UUID_STR);
75 83
76/* This is used to tell the visor bus driver which types of visor devices 84/* This is used to tell the visor bus driver which types of visor devices
77 * we support, and what functions to call when a visor device that we support 85 * we support, and what functions to call when a visor device that we support
@@ -90,12 +98,6 @@ static struct visor_driver visornic_driver = {
90 .channel_interrupt = NULL, 98 .channel_interrupt = NULL,
91}; 99};
92 100
93struct visor_thread_info {
94 struct task_struct *task;
95 struct completion has_stopped;
96 int id;
97};
98
99struct chanstat { 101struct chanstat {
100 unsigned long got_rcv; 102 unsigned long got_rcv;
101 unsigned long got_enbdisack; 103 unsigned long got_enbdisack;
@@ -104,6 +106,7 @@ struct chanstat {
104 unsigned long sent_enbdis; 106 unsigned long sent_enbdis;
105 unsigned long sent_promisc; 107 unsigned long sent_promisc;
106 unsigned long sent_post; 108 unsigned long sent_post;
109 unsigned long sent_post_failed;
107 unsigned long sent_xmit; 110 unsigned long sent_xmit;
108 unsigned long reject_count; 111 unsigned long reject_count;
109 unsigned long extra_rcvbufs_sent; 112 unsigned long extra_rcvbufs_sent;
@@ -111,7 +114,6 @@ struct chanstat {
111 114
112struct visornic_devdata { 115struct visornic_devdata {
113 int devnum; 116 int devnum;
114 int thread_wait_ms;
115 unsigned short enabled; /* 0 disabled 1 enabled to receive */ 117 unsigned short enabled; /* 0 disabled 1 enabled to receive */
116 unsigned short enab_dis_acked; /* NET_RCV_ENABLE/DISABLE acked by 118 unsigned short enab_dis_acked; /* NET_RCV_ENABLE/DISABLE acked by
117 * IOPART 119 * IOPART
@@ -119,7 +121,6 @@ struct visornic_devdata {
119 struct visor_device *dev; 121 struct visor_device *dev;
120 char name[99]; 122 char name[99];
121 struct list_head list_all; /* < link within list_all_devices list */ 123 struct list_head list_all; /* < link within list_all_devices list */
122 struct kref kref;
123 struct net_device *netdev; 124 struct net_device *netdev;
124 struct net_device_stats net_stats; 125 struct net_device_stats net_stats;
125 atomic_t interrupt_rcvd; 126 atomic_t interrupt_rcvd;
@@ -137,20 +138,21 @@ struct visornic_devdata {
137 atomic_t num_rcvbuf_in_iovm; 138 atomic_t num_rcvbuf_in_iovm;
138 unsigned long alloc_failed_in_if_needed_cnt; 139 unsigned long alloc_failed_in_if_needed_cnt;
139 unsigned long alloc_failed_in_repost_rtn_cnt; 140 unsigned long alloc_failed_in_repost_rtn_cnt;
140 int max_outstanding_net_xmits; /* absolute max number of outstanding 141 unsigned long max_outstanding_net_xmits; /* absolute max number of
141 * xmits - should never hit this 142 * outstanding xmits - should
142 */ 143 * never hit this
143 int upper_threshold_net_xmits; /* high water mark for calling 144 */
144 * netif_stop_queue() 145 unsigned long upper_threshold_net_xmits; /* high water mark for
145 */ 146 * calling netif_stop_queue()
146 int lower_threshold_net_xmits; /* high water mark for calling 147 */
147 * netif_wake_queue() 148 unsigned long lower_threshold_net_xmits; /* high water mark for calling
148 */ 149 * netif_wake_queue()
150 */
149 struct sk_buff_head xmitbufhead; /* xmitbufhead is the head of the 151 struct sk_buff_head xmitbufhead; /* xmitbufhead is the head of the
150 * xmit buffer list that have been 152 * xmit buffer list that have been
151 * sent to the IOPART end 153 * sent to the IOPART end
152 */ 154 */
153 struct work_struct serverdown_completion; 155 visorbus_state_complete_func server_down_complete_func;
154 struct work_struct timeout_reset; 156 struct work_struct timeout_reset;
155 struct uiscmdrsp *cmdrsp_rcv; /* cmdrsp_rcv is used for 157 struct uiscmdrsp *cmdrsp_rcv; /* cmdrsp_rcv is used for
156 * posting/unposting rcv buffers 158 * posting/unposting rcv buffers
@@ -161,8 +163,8 @@ struct visornic_devdata {
161 */ 163 */
162 bool server_down; /* IOPART is down */ 164 bool server_down; /* IOPART is down */
163 bool server_change_state; /* Processing SERVER_CHANGESTATE msg */ 165 bool server_change_state; /* Processing SERVER_CHANGESTATE msg */
166 bool going_away; /* device is being torn down */
164 struct dentry *eth_debugfs_dir; 167 struct dentry *eth_debugfs_dir;
165 struct visor_thread_info threadinfo;
166 u64 interrupts_rcvd; 168 u64 interrupts_rcvd;
167 u64 interrupts_notme; 169 u64 interrupts_notme;
168 u64 interrupts_disabled; 170 u64 interrupts_disabled;
@@ -194,16 +196,19 @@ struct visornic_devdata {
194 196
195 int queuefullmsg_logged; 197 int queuefullmsg_logged;
196 struct chanstat chstat; 198 struct chanstat chstat;
199 struct timer_list irq_poll_timer;
200 struct napi_struct napi;
201 struct uiscmdrsp cmdrsp[SIZEOF_CMDRSP];
197}; 202};
198 203
199/* array of open devices maintained by open() and close() */
200static struct net_device *num_visornic_open[VISORNICSOPENMAX];
201 204
202/* List of all visornic_devdata structs, 205/* List of all visornic_devdata structs,
203 * linked via the list_all member 206 * linked via the list_all member
204 */ 207 */
205static LIST_HEAD(list_all_devices); 208static LIST_HEAD(list_all_devices);
206static DEFINE_SPINLOCK(lock_all_devices); 209static DEFINE_SPINLOCK(lock_all_devices);
210static int visornic_poll(struct napi_struct *napi, int budget);
211static void poll_for_irq(unsigned long v);
207 212
208/** 213/**
209 * visor_copy_fragsinfo_from_skb( 214 * visor_copy_fragsinfo_from_skb(
@@ -223,9 +228,25 @@ visor_copy_fragsinfo_from_skb(struct sk_buff *skb, unsigned int firstfraglen,
223 struct phys_info frags[]) 228 struct phys_info frags[])
224{ 229{
225 unsigned int count = 0, ii, size, offset = 0, numfrags; 230 unsigned int count = 0, ii, size, offset = 0, numfrags;
231 unsigned int total_count;
226 232
227 numfrags = skb_shinfo(skb)->nr_frags; 233 numfrags = skb_shinfo(skb)->nr_frags;
228 234
235 /*
236 * Compute the number of fragments this skb has, and if its more than
237 * frag array can hold, linearize the skb
238 */
239 total_count = numfrags + (firstfraglen / PI_PAGE_SIZE);
240 if (firstfraglen % PI_PAGE_SIZE)
241 total_count++;
242
243 if (total_count > frags_max) {
244 if (skb_linearize(skb))
245 return -EINVAL;
246 numfrags = skb_shinfo(skb)->nr_frags;
247 firstfraglen = 0;
248 }
249
229 while (firstfraglen) { 250 while (firstfraglen) {
230 if (count == frags_max) 251 if (count == frags_max)
231 return -EINVAL; 252 return -EINVAL;
@@ -256,8 +277,16 @@ visor_copy_fragsinfo_from_skb(struct sk_buff *skb, unsigned int firstfraglen,
256 page_offset, 277 page_offset,
257 skb_shinfo(skb)->frags[ii]. 278 skb_shinfo(skb)->frags[ii].
258 size, count, frags_max, frags); 279 size, count, frags_max, frags);
259 if (!count) 280 /*
260 return -EIO; 281 * add_physinfo_entries only returns
282 * zero if the frags array is out of room
283 * That should never happen because we
284 * fail above, if count+numfrags > frags_max.
285 * Given that theres no recovery mechanism from putting
286 * half a packet in the I/O channel, panic here as this
287 * should never happen
288 */
289 BUG_ON(!count);
261 } 290 }
262 } 291 }
263 if (skb_shinfo(skb)->frag_list) { 292 if (skb_shinfo(skb)->frag_list) {
@@ -279,222 +308,15 @@ visor_copy_fragsinfo_from_skb(struct sk_buff *skb, unsigned int firstfraglen,
279 return count; 308 return count;
280} 309}
281 310
282/**
283 * visort_thread_start - starts thread for the device
284 * @thrinfo: The thread to start
285 * @threadfn: Function the thread starts
286 * @thrcontext: Context to pass to the thread, i.e. devdata
287 * @name: string describing name of thread
288 *
289 * Starts a thread for the device, currently only thread is
290 * process_incoming_rsps
291 * Returns 0 on success;
292 */
293static int visor_thread_start(struct visor_thread_info *thrinfo,
294 int (*threadfn)(void *),
295 void *thrcontext, char *name)
296{
297 /* used to stop the thread */
298 init_completion(&thrinfo->has_stopped);
299 thrinfo->task = kthread_run(threadfn, thrcontext, name);
300 if (IS_ERR(thrinfo->task)) {
301 thrinfo->id = 0;
302 return -EINVAL;
303 }
304 thrinfo->id = thrinfo->task->pid;
305 return 0;
306}
307
308/**
309 * visor_thread_stop - stop a thread for the device
310 * @thrinfo: The thread to stop
311 *
312 * Stop the thread and wait for completion for a minute
313 * Returns void.
314 */
315static void visor_thread_stop(struct visor_thread_info *thrinfo)
316{
317 if (!thrinfo->id)
318 return; /* thread not running */
319
320 kthread_stop(thrinfo->task);
321 /* give up if the thread has NOT died in 1 minute */
322 if (wait_for_completion_timeout(&thrinfo->has_stopped, 60 * HZ))
323 thrinfo->id = 0;
324}
325
326/* DebugFS code */
327static ssize_t info_debugfs_read(struct file *file, char __user *buf,
328 size_t len, loff_t *offset)
329{
330 int i;
331 ssize_t bytes_read = 0;
332 int str_pos = 0;
333 struct visornic_devdata *devdata;
334 char *vbuf;
335
336 if (len > MAX_BUF)
337 len = MAX_BUF;
338 vbuf = kzalloc(len, GFP_KERNEL);
339 if (!vbuf)
340 return -ENOMEM;
341
342 /* for each vnic channel
343 * dump out channel specific data
344 */
345 for (i = 0; i < VISORNICSOPENMAX; i++) {
346 if (!num_visornic_open[i])
347 continue;
348
349 devdata = netdev_priv(num_visornic_open[i]);
350 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
351 "Vnic i = %d\n", i);
352 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
353 "netdev = %s (0x%p), MAC Addr %pM\n",
354 num_visornic_open[i]->name,
355 num_visornic_open[i],
356 num_visornic_open[i]->dev_addr);
357 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
358 "VisorNic Dev Info = 0x%p\n", devdata);
359 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
360 " num_rcv_bufs = %d\n",
361 devdata->num_rcv_bufs);
362 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
363 " max_oustanding_next_xmits = %d\n",
364 devdata->max_outstanding_net_xmits);
365 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
366 " upper_threshold_net_xmits = %d\n",
367 devdata->upper_threshold_net_xmits);
368 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
369 " lower_threshold_net_xmits = %d\n",
370 devdata->lower_threshold_net_xmits);
371 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
372 " queuefullmsg_logged = %d\n",
373 devdata->queuefullmsg_logged);
374 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
375 " chstat.got_rcv = %lu\n",
376 devdata->chstat.got_rcv);
377 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
378 " chstat.got_enbdisack = %lu\n",
379 devdata->chstat.got_enbdisack);
380 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
381 " chstat.got_xmit_done = %lu\n",
382 devdata->chstat.got_xmit_done);
383 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
384 " chstat.xmit_fail = %lu\n",
385 devdata->chstat.xmit_fail);
386 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
387 " chstat.sent_enbdis = %lu\n",
388 devdata->chstat.sent_enbdis);
389 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
390 " chstat.sent_promisc = %lu\n",
391 devdata->chstat.sent_promisc);
392 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
393 " chstat.sent_post = %lu\n",
394 devdata->chstat.sent_post);
395 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
396 " chstat.sent_xmit = %lu\n",
397 devdata->chstat.sent_xmit);
398 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
399 " chstat.reject_count = %lu\n",
400 devdata->chstat.reject_count);
401 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
402 " chstat.extra_rcvbufs_sent = %lu\n",
403 devdata->chstat.extra_rcvbufs_sent);
404 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
405 " n_rcv0 = %lu\n", devdata->n_rcv0);
406 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
407 " n_rcv1 = %lu\n", devdata->n_rcv1);
408 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
409 " n_rcv2 = %lu\n", devdata->n_rcv2);
410 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
411 " n_rcvx = %lu\n", devdata->n_rcvx);
412 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
413 " num_rcvbuf_in_iovm = %d\n",
414 atomic_read(&devdata->num_rcvbuf_in_iovm));
415 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
416 " alloc_failed_in_if_needed_cnt = %lu\n",
417 devdata->alloc_failed_in_if_needed_cnt);
418 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
419 " alloc_failed_in_repost_rtn_cnt = %lu\n",
420 devdata->alloc_failed_in_repost_rtn_cnt);
421 /* str_pos += scnprintf(vbuf + str_pos, len - str_pos,
422 * " inner_loop_limit_reached_cnt = %lu\n",
423 * devdata->inner_loop_limit_reached_cnt);
424 */
425 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
426 " found_repost_rcvbuf_cnt = %lu\n",
427 devdata->found_repost_rcvbuf_cnt);
428 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
429 " repost_found_skb_cnt = %lu\n",
430 devdata->repost_found_skb_cnt);
431 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
432 " n_repost_deficit = %lu\n",
433 devdata->n_repost_deficit);
434 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
435 " bad_rcv_buf = %lu\n",
436 devdata->bad_rcv_buf);
437 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
438 " n_rcv_packets_not_accepted = %lu\n",
439 devdata->n_rcv_packets_not_accepted);
440 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
441 " interrupts_rcvd = %llu\n",
442 devdata->interrupts_rcvd);
443 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
444 " interrupts_notme = %llu\n",
445 devdata->interrupts_notme);
446 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
447 " interrupts_disabled = %llu\n",
448 devdata->interrupts_disabled);
449 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
450 " busy_cnt = %llu\n",
451 devdata->busy_cnt);
452 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
453 " flow_control_upper_hits = %llu\n",
454 devdata->flow_control_upper_hits);
455 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
456 " flow_control_lower_hits = %llu\n",
457 devdata->flow_control_lower_hits);
458 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
459 " thread_wait_ms = %d\n",
460 devdata->thread_wait_ms);
461 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
462 " netif_queue = %s\n",
463 netif_queue_stopped(devdata->netdev) ?
464 "stopped" : "running");
465 }
466 bytes_read = simple_read_from_buffer(buf, len, offset, vbuf, str_pos);
467 kfree(vbuf);
468 return bytes_read;
469}
470
471static ssize_t enable_ints_write(struct file *file, 311static ssize_t enable_ints_write(struct file *file,
472 const char __user *buffer, 312 const char __user *buffer,
473 size_t count, loff_t *ppos) 313 size_t count, loff_t *ppos)
474{ 314{
475 char buf[4]; 315 /*
476 int i, new_value; 316 * Don't want to break ABI here by having a debugfs
477 struct visornic_devdata *devdata; 317 * file that no longer exists or is writable, so
478 318 * lets just make this a vestigual function
479 if (count >= ARRAY_SIZE(buf)) 319 */
480 return -EINVAL;
481
482 buf[count] = '\0';
483 if (copy_from_user(buf, buffer, count))
484 return -EFAULT;
485
486 i = kstrtoint(buf, 10, &new_value);
487 if (i != 0)
488 return -EFAULT;
489
490 /* set all counts to new_value usually 0 */
491 for (i = 0; i < VISORNICSOPENMAX; i++) {
492 if (num_visornic_open[i]) {
493 devdata = netdev_priv(num_visornic_open[i]);
494 /* TODO update features bit in channel */
495 }
496 }
497
498 return count; 320 return count;
499} 321}
500 322
@@ -509,44 +331,29 @@ static ssize_t enable_ints_write(struct file *file,
509 * Returns void. 331 * Returns void.
510 */ 332 */
511static void 333static void
512visornic_serverdown_complete(struct work_struct *work) 334visornic_serverdown_complete(struct visornic_devdata *devdata)
513{ 335{
514 struct visornic_devdata *devdata;
515 struct net_device *netdev; 336 struct net_device *netdev;
516 unsigned long flags;
517 int i = 0, count = 0;
518 337
519 devdata = container_of(work, struct visornic_devdata,
520 serverdown_completion);
521 netdev = devdata->netdev; 338 netdev = devdata->netdev;
522 339
523 /* Stop using datachan */ 340 /* Stop polling for interrupts */
524 visor_thread_stop(&devdata->threadinfo); 341 del_timer_sync(&devdata->irq_poll_timer);
525
526 /* Inform Linux that the link is down */
527 netif_carrier_off(netdev);
528 netif_stop_queue(netdev);
529 342
530 /* Free the skb for XMITs that haven't been serviced by the server 343 rtnl_lock();
531 * We shouldn't have to inform Linux about these IOs because they 344 dev_close(netdev);
532 * are "lost in the ethernet" 345 rtnl_unlock();
533 */
534 skb_queue_purge(&devdata->xmitbufhead);
535 346
536 spin_lock_irqsave(&devdata->priv_lock, flags);
537 /* free rcv buffers */
538 for (i = 0; i < devdata->num_rcv_bufs; i++) {
539 if (devdata->rcvbuf[i]) {
540 kfree_skb(devdata->rcvbuf[i]);
541 devdata->rcvbuf[i] = NULL;
542 count++;
543 }
544 }
545 atomic_set(&devdata->num_rcvbuf_in_iovm, 0); 347 atomic_set(&devdata->num_rcvbuf_in_iovm, 0);
546 spin_unlock_irqrestore(&devdata->priv_lock, flags); 348 devdata->chstat.sent_xmit = 0;
349 devdata->chstat.got_xmit_done = 0;
350
351 if (devdata->server_down_complete_func)
352 (*devdata->server_down_complete_func)(devdata->dev, 0);
547 353
548 devdata->server_down = true; 354 devdata->server_down = true;
549 devdata->server_change_state = false; 355 devdata->server_change_state = false;
356 devdata->server_down_complete_func = NULL;
550} 357}
551 358
552/** 359/**
@@ -558,15 +365,31 @@ visornic_serverdown_complete(struct work_struct *work)
558 * Returns 0 if we scheduled the work, -EINVAL on error. 365 * Returns 0 if we scheduled the work, -EINVAL on error.
559 */ 366 */
560static int 367static int
561visornic_serverdown(struct visornic_devdata *devdata) 368visornic_serverdown(struct visornic_devdata *devdata,
369 visorbus_state_complete_func complete_func)
562{ 370{
371 unsigned long flags;
372
373 spin_lock_irqsave(&devdata->priv_lock, flags);
563 if (!devdata->server_down && !devdata->server_change_state) { 374 if (!devdata->server_down && !devdata->server_change_state) {
375 if (devdata->going_away) {
376 spin_unlock_irqrestore(&devdata->priv_lock, flags);
377 dev_dbg(&devdata->dev->device,
378 "%s aborting because device removal pending\n",
379 __func__);
380 return -ENODEV;
381 }
564 devdata->server_change_state = true; 382 devdata->server_change_state = true;
565 queue_work(visornic_serverdown_workqueue, 383 devdata->server_down_complete_func = complete_func;
566 &devdata->serverdown_completion); 384 spin_unlock_irqrestore(&devdata->priv_lock, flags);
385 visornic_serverdown_complete(devdata);
567 } else if (devdata->server_change_state) { 386 } else if (devdata->server_change_state) {
387 dev_dbg(&devdata->dev->device, "%s changing state\n",
388 __func__);
389 spin_unlock_irqrestore(&devdata->priv_lock, flags);
568 return -EINVAL; 390 return -EINVAL;
569 } 391 } else
392 spin_unlock_irqrestore(&devdata->priv_lock, flags);
570 return 0; 393 return 0;
571} 394}
572 395
@@ -625,11 +448,14 @@ post_skb(struct uiscmdrsp *cmdrsp,
625 if ((cmdrsp->net.rcvpost.frag.pi_off + skb->len) <= PI_PAGE_SIZE) { 448 if ((cmdrsp->net.rcvpost.frag.pi_off + skb->len) <= PI_PAGE_SIZE) {
626 cmdrsp->net.type = NET_RCV_POST; 449 cmdrsp->net.type = NET_RCV_POST;
627 cmdrsp->cmdtype = CMD_NET_TYPE; 450 cmdrsp->cmdtype = CMD_NET_TYPE;
628 visorchannel_signalinsert(devdata->dev->visorchannel, 451 if (visorchannel_signalinsert(devdata->dev->visorchannel,
629 IOCHAN_TO_IOPART, 452 IOCHAN_TO_IOPART,
630 cmdrsp); 453 cmdrsp)) {
631 atomic_inc(&devdata->num_rcvbuf_in_iovm); 454 atomic_inc(&devdata->num_rcvbuf_in_iovm);
632 devdata->chstat.sent_post++; 455 devdata->chstat.sent_post++;
456 } else {
457 devdata->chstat.sent_post_failed++;
458 }
633 } 459 }
634} 460}
635 461
@@ -651,10 +477,10 @@ send_enbdis(struct net_device *netdev, int state,
651 devdata->cmdrsp_rcv->net.enbdis.context = netdev; 477 devdata->cmdrsp_rcv->net.enbdis.context = netdev;
652 devdata->cmdrsp_rcv->net.type = NET_RCV_ENBDIS; 478 devdata->cmdrsp_rcv->net.type = NET_RCV_ENBDIS;
653 devdata->cmdrsp_rcv->cmdtype = CMD_NET_TYPE; 479 devdata->cmdrsp_rcv->cmdtype = CMD_NET_TYPE;
654 visorchannel_signalinsert(devdata->dev->visorchannel, 480 if (visorchannel_signalinsert(devdata->dev->visorchannel,
655 IOCHAN_TO_IOPART, 481 IOCHAN_TO_IOPART,
656 devdata->cmdrsp_rcv); 482 devdata->cmdrsp_rcv))
657 devdata->chstat.sent_enbdis++; 483 devdata->chstat.sent_enbdis++;
658} 484}
659 485
660/** 486/**
@@ -676,9 +502,6 @@ visornic_disable_with_timeout(struct net_device *netdev, const int timeout)
676 unsigned long flags; 502 unsigned long flags;
677 int wait = 0; 503 int wait = 0;
678 504
679 /* stop the transmit queue so nothing more can be transmitted */
680 netif_stop_queue(netdev);
681
682 /* send a msg telling the other end we are stopping incoming pkts */ 505 /* send a msg telling the other end we are stopping incoming pkts */
683 spin_lock_irqsave(&devdata->priv_lock, flags); 506 spin_lock_irqsave(&devdata->priv_lock, flags);
684 devdata->enabled = 0; 507 devdata->enabled = 0;
@@ -695,12 +518,14 @@ visornic_disable_with_timeout(struct net_device *netdev, const int timeout)
695 * when it gets a disable. 518 * when it gets a disable.
696 */ 519 */
697 spin_lock_irqsave(&devdata->priv_lock, flags); 520 spin_lock_irqsave(&devdata->priv_lock, flags);
698 while ((timeout == VISORNIC_INFINITE_RESPONSE_WAIT) || 521 while ((timeout == VISORNIC_INFINITE_RSP_WAIT) ||
699 (wait < timeout)) { 522 (wait < timeout)) {
700 if (devdata->enab_dis_acked) 523 if (devdata->enab_dis_acked)
701 break; 524 break;
702 if (devdata->server_down || devdata->server_change_state) { 525 if (devdata->server_down || devdata->server_change_state) {
703 spin_unlock_irqrestore(&devdata->priv_lock, flags); 526 spin_unlock_irqrestore(&devdata->priv_lock, flags);
527 dev_dbg(&netdev->dev, "%s server went away\n",
528 __func__);
704 return -EIO; 529 return -EIO;
705 } 530 }
706 set_current_state(TASK_INTERRUPTIBLE); 531 set_current_state(TASK_INTERRUPTIBLE);
@@ -722,10 +547,16 @@ visornic_disable_with_timeout(struct net_device *netdev, const int timeout)
722 break; 547 break;
723 } 548 }
724 } 549 }
725
726 /* we've set enabled to 0, so we can give up the lock. */ 550 /* we've set enabled to 0, so we can give up the lock. */
727 spin_unlock_irqrestore(&devdata->priv_lock, flags); 551 spin_unlock_irqrestore(&devdata->priv_lock, flags);
728 552
553 /* stop the transmit queue so nothing more can be transmitted */
554 netif_stop_queue(netdev);
555
556 napi_disable(&devdata->napi);
557
558 skb_queue_purge(&devdata->xmitbufhead);
559
729 /* Free rcv buffers - other end has automatically unposed them on 560 /* Free rcv buffers - other end has automatically unposed them on
730 * disable 561 * disable
731 */ 562 */
@@ -736,13 +567,6 @@ visornic_disable_with_timeout(struct net_device *netdev, const int timeout)
736 } 567 }
737 } 568 }
738 569
739 /* remove references from array */
740 for (i = 0; i < VISORNICSOPENMAX; i++)
741 if (num_visornic_open[i] == netdev) {
742 num_visornic_open[i] = NULL;
743 break;
744 }
745
746 return 0; 570 return 0;
747} 571}
748 572
@@ -814,11 +638,15 @@ visornic_enable_with_timeout(struct net_device *netdev, const int timeout)
814 * gets a disable. 638 * gets a disable.
815 */ 639 */
816 i = init_rcv_bufs(netdev, devdata); 640 i = init_rcv_bufs(netdev, devdata);
817 if (i < 0) 641 if (i < 0) {
642 dev_err(&netdev->dev,
643 "%s failed to init rcv bufs (%d)\n", __func__, i);
818 return i; 644 return i;
645 }
819 646
820 spin_lock_irqsave(&devdata->priv_lock, flags); 647 spin_lock_irqsave(&devdata->priv_lock, flags);
821 devdata->enabled = 1; 648 devdata->enabled = 1;
649 devdata->enab_dis_acked = 0;
822 650
823 /* now we're ready, let's send an ENB to uisnic but until we get 651 /* now we're ready, let's send an ENB to uisnic but until we get
824 * an ACK back from uisnic, we'll drop the packets 652 * an ACK back from uisnic, we'll drop the packets
@@ -829,15 +657,18 @@ visornic_enable_with_timeout(struct net_device *netdev, const int timeout)
829 /* send enable and wait for ack -- don't hold lock when sending enable 657 /* send enable and wait for ack -- don't hold lock when sending enable
830 * because if the queue is full, insert might sleep. 658 * because if the queue is full, insert might sleep.
831 */ 659 */
660 napi_enable(&devdata->napi);
832 send_enbdis(netdev, 1, devdata); 661 send_enbdis(netdev, 1, devdata);
833 662
834 spin_lock_irqsave(&devdata->priv_lock, flags); 663 spin_lock_irqsave(&devdata->priv_lock, flags);
835 while ((timeout == VISORNIC_INFINITE_RESPONSE_WAIT) || 664 while ((timeout == VISORNIC_INFINITE_RSP_WAIT) ||
836 (wait < timeout)) { 665 (wait < timeout)) {
837 if (devdata->enab_dis_acked) 666 if (devdata->enab_dis_acked)
838 break; 667 break;
839 if (devdata->server_down || devdata->server_change_state) { 668 if (devdata->server_down || devdata->server_change_state) {
840 spin_unlock_irqrestore(&devdata->priv_lock, flags); 669 spin_unlock_irqrestore(&devdata->priv_lock, flags);
670 dev_dbg(&netdev->dev, "%s server went away\n",
671 __func__);
841 return -EIO; 672 return -EIO;
842 } 673 }
843 set_current_state(TASK_INTERRUPTIBLE); 674 set_current_state(TASK_INTERRUPTIBLE);
@@ -848,19 +679,13 @@ visornic_enable_with_timeout(struct net_device *netdev, const int timeout)
848 679
849 spin_unlock_irqrestore(&devdata->priv_lock, flags); 680 spin_unlock_irqrestore(&devdata->priv_lock, flags);
850 681
851 if (!devdata->enab_dis_acked) 682 if (!devdata->enab_dis_acked) {
683 dev_err(&netdev->dev, "%s missing ACK\n", __func__);
852 return -EIO; 684 return -EIO;
853
854 /* find an open slot in the array to save off VisorNic references
855 * for debug
856 */
857 for (i = 0; i < VISORNICSOPENMAX; i++) {
858 if (!num_visornic_open[i]) {
859 num_visornic_open[i] = netdev;
860 break;
861 }
862 } 685 }
863 686
687 netif_start_queue(netdev);
688
864 return 0; 689 return 0;
865} 690}
866 691
@@ -882,20 +707,29 @@ visornic_timeout_reset(struct work_struct *work)
882 devdata = container_of(work, struct visornic_devdata, timeout_reset); 707 devdata = container_of(work, struct visornic_devdata, timeout_reset);
883 netdev = devdata->netdev; 708 netdev = devdata->netdev;
884 709
885 netif_stop_queue(netdev); 710 rtnl_lock();
886 response = visornic_disable_with_timeout(netdev, 100); 711 if (!netif_running(netdev)) {
712 rtnl_unlock();
713 return;
714 }
715
716 response = visornic_disable_with_timeout(netdev,
717 VISORNIC_INFINITE_RSP_WAIT);
887 if (response) 718 if (response)
888 goto call_serverdown; 719 goto call_serverdown;
889 720
890 response = visornic_enable_with_timeout(netdev, 100); 721 response = visornic_enable_with_timeout(netdev,
722 VISORNIC_INFINITE_RSP_WAIT);
891 if (response) 723 if (response)
892 goto call_serverdown; 724 goto call_serverdown;
893 netif_wake_queue(netdev); 725
726 rtnl_unlock();
894 727
895 return; 728 return;
896 729
897call_serverdown: 730call_serverdown:
898 visornic_serverdown(devdata); 731 visornic_serverdown(devdata, NULL);
732 rtnl_unlock();
899} 733}
900 734
901/** 735/**
@@ -908,12 +742,7 @@ call_serverdown:
908static int 742static int
909visornic_open(struct net_device *netdev) 743visornic_open(struct net_device *netdev)
910{ 744{
911 visornic_enable_with_timeout(netdev, VISORNIC_INFINITE_RESPONSE_WAIT); 745 visornic_enable_with_timeout(netdev, VISORNIC_INFINITE_RSP_WAIT);
912
913 /* start the interface's transmit queue, allowing it to accept
914 * packets for transmission
915 */
916 netif_start_queue(netdev);
917 746
918 return 0; 747 return 0;
919} 748}
@@ -928,13 +757,59 @@ visornic_open(struct net_device *netdev)
928static int 757static int
929visornic_close(struct net_device *netdev) 758visornic_close(struct net_device *netdev)
930{ 759{
931 netif_stop_queue(netdev); 760 visornic_disable_with_timeout(netdev, VISORNIC_INFINITE_RSP_WAIT);
932 visornic_disable_with_timeout(netdev, VISORNIC_INFINITE_RESPONSE_WAIT);
933 761
934 return 0; 762 return 0;
935} 763}
936 764
937/** 765/**
766 * devdata_xmits_outstanding - compute outstanding xmits
767 * @devdata: visornic_devdata for device
768 *
769 * Return value is the number of outstanding xmits.
770 */
771static unsigned long devdata_xmits_outstanding(struct visornic_devdata *devdata)
772{
773 if (devdata->chstat.sent_xmit >= devdata->chstat.got_xmit_done)
774 return devdata->chstat.sent_xmit -
775 devdata->chstat.got_xmit_done;
776 else
777 return (ULONG_MAX - devdata->chstat.got_xmit_done
778 + devdata->chstat.sent_xmit + 1);
779}
780
781/**
782 * vnic_hit_high_watermark
783 * @devdata: indicates visornic device we are checking
784 * @high_watermark: max num of unacked xmits we will tolerate,
785 * before we will start throttling
786 *
787 * Returns true iff the number of unacked xmits sent to
788 * the IO partition is >= high_watermark.
789 */
790static inline bool vnic_hit_high_watermark(struct visornic_devdata *devdata,
791 ulong high_watermark)
792{
793 return (devdata_xmits_outstanding(devdata) >= high_watermark);
794}
795
796/**
797 * vnic_hit_low_watermark
798 * @devdata: indicates visornic device we are checking
799 * @low_watermark: we will wait until the num of unacked xmits
800 * drops to this value or lower before we start
801 * transmitting again
802 *
803 * Returns true iff the number of unacked xmits sent to
804 * the IO partition is <= low_watermark.
805 */
806static inline bool vnic_hit_low_watermark(struct visornic_devdata *devdata,
807 ulong low_watermark)
808{
809 return (devdata_xmits_outstanding(devdata) <= low_watermark);
810}
811
812/**
938 * visornic_xmit - send a packet to the IO Partition 813 * visornic_xmit - send a packet to the IO Partition
939 * @skb: Packet to be sent 814 * @skb: Packet to be sent
940 * @netdev: net device the packet is being sent from 815 * @netdev: net device the packet is being sent from
@@ -944,7 +819,7 @@ visornic_close(struct net_device *netdev)
944 * function is protected from concurrent calls by a spinlock xmit_lock 819 * function is protected from concurrent calls by a spinlock xmit_lock
945 * in the net_device struct, but as soon as the function returns it 820 * in the net_device struct, but as soon as the function returns it
946 * can be called again. 821 * can be called again.
947 * Returns NETDEV_TX_OK for success, NETDEV_TX_BUSY for error. 822 * Returns NETDEV_TX_OK.
948 */ 823 */
949static int 824static int
950visornic_xmit(struct sk_buff *skb, struct net_device *netdev) 825visornic_xmit(struct sk_buff *skb, struct net_device *netdev)
@@ -961,7 +836,10 @@ visornic_xmit(struct sk_buff *skb, struct net_device *netdev)
961 devdata->server_change_state) { 836 devdata->server_change_state) {
962 spin_unlock_irqrestore(&devdata->priv_lock, flags); 837 spin_unlock_irqrestore(&devdata->priv_lock, flags);
963 devdata->busy_cnt++; 838 devdata->busy_cnt++;
964 return NETDEV_TX_BUSY; 839 dev_dbg(&netdev->dev,
840 "%s busy - queue stopped\n", __func__);
841 kfree_skb(skb);
842 return NETDEV_TX_OK;
965 } 843 }
966 844
967 /* sk_buff struct is used to host network data throughout all the 845 /* sk_buff struct is used to host network data throughout all the
@@ -979,7 +857,11 @@ visornic_xmit(struct sk_buff *skb, struct net_device *netdev)
979 if (firstfraglen < ETH_HEADER_SIZE) { 857 if (firstfraglen < ETH_HEADER_SIZE) {
980 spin_unlock_irqrestore(&devdata->priv_lock, flags); 858 spin_unlock_irqrestore(&devdata->priv_lock, flags);
981 devdata->busy_cnt++; 859 devdata->busy_cnt++;
982 return NETDEV_TX_BUSY; 860 dev_err(&netdev->dev,
861 "%s busy - first frag too small (%d)\n",
862 __func__, firstfraglen);
863 kfree_skb(skb);
864 return NETDEV_TX_OK;
983 } 865 }
984 866
985 if ((len < ETH_MIN_PACKET_SIZE) && 867 if ((len < ETH_MIN_PACKET_SIZE) &&
@@ -1002,13 +884,8 @@ visornic_xmit(struct sk_buff *skb, struct net_device *netdev)
1002 /* save the pointer to skb -- we'll need it for completion */ 884 /* save the pointer to skb -- we'll need it for completion */
1003 cmdrsp->net.buf = skb; 885 cmdrsp->net.buf = skb;
1004 886
1005 if (((devdata->chstat.sent_xmit >= devdata->chstat.got_xmit_done) && 887 if (vnic_hit_high_watermark(devdata,
1006 (devdata->chstat.sent_xmit - devdata->chstat.got_xmit_done >= 888 devdata->max_outstanding_net_xmits)) {
1007 devdata->max_outstanding_net_xmits)) ||
1008 ((devdata->chstat.sent_xmit < devdata->chstat.got_xmit_done) &&
1009 (ULONG_MAX - devdata->chstat.got_xmit_done +
1010 devdata->chstat.sent_xmit >=
1011 devdata->max_outstanding_net_xmits))) {
1012 /* too many NET_XMITs queued over to IOVM - need to wait 889 /* too many NET_XMITs queued over to IOVM - need to wait
1013 */ 890 */
1014 devdata->chstat.reject_count++; 891 devdata->chstat.reject_count++;
@@ -1018,7 +895,11 @@ visornic_xmit(struct sk_buff *skb, struct net_device *netdev)
1018 netif_stop_queue(netdev); 895 netif_stop_queue(netdev);
1019 spin_unlock_irqrestore(&devdata->priv_lock, flags); 896 spin_unlock_irqrestore(&devdata->priv_lock, flags);
1020 devdata->busy_cnt++; 897 devdata->busy_cnt++;
1021 return NETDEV_TX_BUSY; 898 dev_dbg(&netdev->dev,
899 "%s busy - waiting for iovm to catch up\n",
900 __func__);
901 kfree_skb(skb);
902 return NETDEV_TX_OK;
1022 } 903 }
1023 if (devdata->queuefullmsg_logged) 904 if (devdata->queuefullmsg_logged)
1024 devdata->queuefullmsg_logged = 0; 905 devdata->queuefullmsg_logged = 0;
@@ -1055,10 +936,13 @@ visornic_xmit(struct sk_buff *skb, struct net_device *netdev)
1055 visor_copy_fragsinfo_from_skb(skb, firstfraglen, 936 visor_copy_fragsinfo_from_skb(skb, firstfraglen,
1056 MAX_PHYS_INFO, 937 MAX_PHYS_INFO,
1057 cmdrsp->net.xmt.frags); 938 cmdrsp->net.xmt.frags);
1058 if (cmdrsp->net.xmt.num_frags == -1) { 939 if (cmdrsp->net.xmt.num_frags < 0) {
1059 spin_unlock_irqrestore(&devdata->priv_lock, flags); 940 spin_unlock_irqrestore(&devdata->priv_lock, flags);
1060 devdata->busy_cnt++; 941 devdata->busy_cnt++;
1061 return NETDEV_TX_BUSY; 942 dev_err(&netdev->dev,
943 "%s busy - copy frags failed\n", __func__);
944 kfree_skb(skb);
945 return NETDEV_TX_OK;
1062 } 946 }
1063 947
1064 if (!visorchannel_signalinsert(devdata->dev->visorchannel, 948 if (!visorchannel_signalinsert(devdata->dev->visorchannel,
@@ -1066,18 +950,15 @@ visornic_xmit(struct sk_buff *skb, struct net_device *netdev)
1066 netif_stop_queue(netdev); 950 netif_stop_queue(netdev);
1067 spin_unlock_irqrestore(&devdata->priv_lock, flags); 951 spin_unlock_irqrestore(&devdata->priv_lock, flags);
1068 devdata->busy_cnt++; 952 devdata->busy_cnt++;
1069 return NETDEV_TX_BUSY; 953 dev_dbg(&netdev->dev,
954 "%s busy - signalinsert failed\n", __func__);
955 kfree_skb(skb);
956 return NETDEV_TX_OK;
1070 } 957 }
1071 958
1072 /* Track the skbs that have been sent to the IOVM for XMIT */ 959 /* Track the skbs that have been sent to the IOVM for XMIT */
1073 skb_queue_head(&devdata->xmitbufhead, skb); 960 skb_queue_head(&devdata->xmitbufhead, skb);
1074 961
1075 /* set the last transmission start time
1076 * linux doc says: Do not forget to update netdev->trans_start to
1077 * jiffies after each new tx packet is given to the hardware.
1078 */
1079 netdev->trans_start = jiffies;
1080
1081 /* update xmt stats */ 962 /* update xmt stats */
1082 devdata->net_stats.tx_packets++; 963 devdata->net_stats.tx_packets++;
1083 devdata->net_stats.tx_bytes += skb->len; 964 devdata->net_stats.tx_bytes += skb->len;
@@ -1086,18 +967,16 @@ visornic_xmit(struct sk_buff *skb, struct net_device *netdev)
1086 /* check to see if we have hit the high watermark for 967 /* check to see if we have hit the high watermark for
1087 * netif_stop_queue() 968 * netif_stop_queue()
1088 */ 969 */
1089 if (((devdata->chstat.sent_xmit >= devdata->chstat.got_xmit_done) && 970 if (vnic_hit_high_watermark(devdata,
1090 (devdata->chstat.sent_xmit - devdata->chstat.got_xmit_done >= 971 devdata->upper_threshold_net_xmits)) {
1091 devdata->upper_threshold_net_xmits)) ||
1092 ((devdata->chstat.sent_xmit < devdata->chstat.got_xmit_done) &&
1093 (ULONG_MAX - devdata->chstat.got_xmit_done +
1094 devdata->chstat.sent_xmit >=
1095 devdata->upper_threshold_net_xmits))) {
1096 /* too many NET_XMITs queued over to IOVM - need to wait */ 972 /* too many NET_XMITs queued over to IOVM - need to wait */
1097 netif_stop_queue(netdev); /* calling stop queue - call 973 netif_stop_queue(netdev); /* calling stop queue - call
1098 * netif_wake_queue() after lower 974 * netif_wake_queue() after lower
1099 * threshold 975 * threshold
1100 */ 976 */
977 dev_dbg(&netdev->dev,
978 "%s busy - invoking iovm flow control\n",
979 __func__);
1101 devdata->flow_control_upper_hits++; 980 devdata->flow_control_upper_hits++;
1102 } 981 }
1103 spin_unlock_irqrestore(&devdata->priv_lock, flags); 982 spin_unlock_irqrestore(&devdata->priv_lock, flags);
@@ -1121,21 +1000,6 @@ visornic_get_stats(struct net_device *netdev)
1121} 1000}
1122 1001
1123/** 1002/**
1124 * visornic_ioctl - ioctl function for netdevice.
1125 * @netdev: netdevice
1126 * @ifr: ignored
1127 * @cmd: ignored
1128 *
1129 * Currently not supported.
1130 * Returns EOPNOTSUPP
1131 */
1132static int
1133visornic_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
1134{
1135 return -EOPNOTSUPP;
1136}
1137
1138/**
1139 * visornic_change_mtu - changes mtu of device. 1003 * visornic_change_mtu - changes mtu of device.
1140 * @netdev: netdevice 1004 * @netdev: netdevice
1141 * @new_mtu: value of new mtu 1005 * @new_mtu: value of new mtu
@@ -1201,15 +1065,24 @@ visornic_xmit_timeout(struct net_device *netdev)
1201 unsigned long flags; 1065 unsigned long flags;
1202 1066
1203 spin_lock_irqsave(&devdata->priv_lock, flags); 1067 spin_lock_irqsave(&devdata->priv_lock, flags);
1068 if (devdata->going_away) {
1069 spin_unlock_irqrestore(&devdata->priv_lock, flags);
1070 dev_dbg(&devdata->dev->device,
1071 "%s aborting because device removal pending\n",
1072 __func__);
1073 return;
1074 }
1075
1204 /* Ensure that a ServerDown message hasn't been received */ 1076 /* Ensure that a ServerDown message hasn't been received */
1205 if (!devdata->enabled || 1077 if (!devdata->enabled ||
1206 (devdata->server_down && !devdata->server_change_state)) { 1078 (devdata->server_down && !devdata->server_change_state)) {
1079 dev_dbg(&netdev->dev, "%s no processing\n",
1080 __func__);
1207 spin_unlock_irqrestore(&devdata->priv_lock, flags); 1081 spin_unlock_irqrestore(&devdata->priv_lock, flags);
1208 return; 1082 return;
1209 } 1083 }
1210 spin_unlock_irqrestore(&devdata->priv_lock, flags);
1211
1212 queue_work(visornic_timeout_reset_workqueue, &devdata->timeout_reset); 1084 queue_work(visornic_timeout_reset_workqueue, &devdata->timeout_reset);
1085 spin_unlock_irqrestore(&devdata->priv_lock, flags);
1213} 1086}
1214 1087
1215/** 1088/**
@@ -1281,7 +1154,6 @@ repost_return(struct uiscmdrsp *cmdrsp, struct visornic_devdata *devdata,
1281 devdata->bad_rcv_buf++; 1154 devdata->bad_rcv_buf++;
1282 } 1155 }
1283 } 1156 }
1284 atomic_dec(&devdata->usage);
1285 return status; 1157 return status;
1286} 1158}
1287 1159
@@ -1293,18 +1165,16 @@ repost_return(struct uiscmdrsp *cmdrsp, struct visornic_devdata *devdata,
1293 * it up the stack. 1165 * it up the stack.
1294 * Returns void 1166 * Returns void
1295 */ 1167 */
1296static void 1168static int
1297visornic_rx(struct uiscmdrsp *cmdrsp) 1169visornic_rx(struct uiscmdrsp *cmdrsp)
1298{ 1170{
1299 struct visornic_devdata *devdata; 1171 struct visornic_devdata *devdata;
1300 struct sk_buff *skb, *prev, *curr; 1172 struct sk_buff *skb, *prev, *curr;
1301 struct net_device *netdev; 1173 struct net_device *netdev;
1302 int cc, currsize, off, status; 1174 int cc, currsize, off;
1303 struct ethhdr *eth; 1175 struct ethhdr *eth;
1304 unsigned long flags; 1176 unsigned long flags;
1305#ifdef DEBUG 1177 int rx_count = 0;
1306 struct phys_info testfrags[MAX_PHYS_INFO];
1307#endif
1308 1178
1309 /* post new rcv buf to the other end using the cmdrsp we have at hand 1179 /* post new rcv buf to the other end using the cmdrsp we have at hand
1310 * post it without holding lock - but we'll use the signal lock to 1180 * post it without holding lock - but we'll use the signal lock to
@@ -1314,18 +1184,6 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1314 skb = cmdrsp->net.buf; 1184 skb = cmdrsp->net.buf;
1315 netdev = skb->dev; 1185 netdev = skb->dev;
1316 1186
1317 if (!netdev) {
1318 /* We must have previously downed this network device and
1319 * this skb and device is no longer valid. This also means
1320 * the skb reference was removed from devdata->rcvbuf so no
1321 * need to search for it.
1322 * All we can do is free the skb and return.
1323 * Note: We crash if we try to log this here.
1324 */
1325 kfree_skb(skb);
1326 return;
1327 }
1328
1329 devdata = netdev_priv(netdev); 1187 devdata = netdev_priv(netdev);
1330 1188
1331 spin_lock_irqsave(&devdata->priv_lock, flags); 1189 spin_lock_irqsave(&devdata->priv_lock, flags);
@@ -1335,10 +1193,6 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1335 devdata->net_stats.rx_packets++; 1193 devdata->net_stats.rx_packets++;
1336 devdata->net_stats.rx_bytes = skb->len; 1194 devdata->net_stats.rx_bytes = skb->len;
1337 1195
1338 atomic_inc(&devdata->usage); /* don't want a close to happen before
1339 * we're done here
1340 */
1341
1342 /* set length to how much was ACTUALLY received - 1196 /* set length to how much was ACTUALLY received -
1343 * NOTE: rcv_done_len includes actual length of data rcvd 1197 * NOTE: rcv_done_len includes actual length of data rcvd
1344 * including ethhdr 1198 * including ethhdr
@@ -1352,7 +1206,7 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1352 */ 1206 */
1353 spin_unlock_irqrestore(&devdata->priv_lock, flags); 1207 spin_unlock_irqrestore(&devdata->priv_lock, flags);
1354 repost_return(cmdrsp, devdata, skb, netdev); 1208 repost_return(cmdrsp, devdata, skb, netdev);
1355 return; 1209 return rx_count;
1356 } 1210 }
1357 1211
1358 spin_unlock_irqrestore(&devdata->priv_lock, flags); 1212 spin_unlock_irqrestore(&devdata->priv_lock, flags);
@@ -1371,7 +1225,7 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1371 if (repost_return(cmdrsp, devdata, skb, netdev) < 0) 1225 if (repost_return(cmdrsp, devdata, skb, netdev) < 0)
1372 dev_err(&devdata->netdev->dev, 1226 dev_err(&devdata->netdev->dev,
1373 "repost_return failed"); 1227 "repost_return failed");
1374 return; 1228 return rx_count;
1375 } 1229 }
1376 /* length rcvd is greater than firstfrag in this skb rcv buf */ 1230 /* length rcvd is greater than firstfrag in this skb rcv buf */
1377 skb->tail += RCVPOST_BUF_SIZE; /* amount in skb->data */ 1231 skb->tail += RCVPOST_BUF_SIZE; /* amount in skb->data */
@@ -1386,7 +1240,7 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1386 if (repost_return(cmdrsp, devdata, skb, netdev) < 0) 1240 if (repost_return(cmdrsp, devdata, skb, netdev) < 0)
1387 dev_err(&devdata->netdev->dev, 1241 dev_err(&devdata->netdev->dev,
1388 "repost_return failed"); 1242 "repost_return failed");
1389 return; 1243 return rx_count;
1390 } 1244 }
1391 skb->tail += skb->len; 1245 skb->tail += skb->len;
1392 skb->data_len = 0; /* nothing rcvd in frag_list */ 1246 skb->data_len = 0; /* nothing rcvd in frag_list */
@@ -1405,7 +1259,7 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1405 if (cmdrsp->net.rcv.rcvbuf[0] != skb) { 1259 if (cmdrsp->net.rcv.rcvbuf[0] != skb) {
1406 if (repost_return(cmdrsp, devdata, skb, netdev) < 0) 1260 if (repost_return(cmdrsp, devdata, skb, netdev) < 0)
1407 dev_err(&devdata->netdev->dev, "repost_return failed"); 1261 dev_err(&devdata->netdev->dev, "repost_return failed");
1408 return; 1262 return rx_count;
1409 } 1263 }
1410 1264
1411 if (cmdrsp->net.rcv.numrcvbufs > 1) { 1265 if (cmdrsp->net.rcv.numrcvbufs > 1) {
@@ -1431,29 +1285,12 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1431 curr->data_len = 0; 1285 curr->data_len = 0;
1432 off += currsize; 1286 off += currsize;
1433 } 1287 }
1434#ifdef DEBUG
1435 /* assert skb->len == off */ 1288 /* assert skb->len == off */
1436 if (skb->len != off) { 1289 if (skb->len != off) {
1437 dev_err(&devdata->netdev->dev, 1290 netdev_err(devdata->netdev,
1438 "%s something wrong; skb->len:%d != off:%d\n", 1291 "something wrong; skb->len:%d != off:%d\n",
1439 netdev->name, skb->len, off); 1292 skb->len, off);
1440 }
1441 /* test code */
1442 cc = util_copy_fragsinfo_from_skb("rcvchaintest", skb,
1443 RCVPOST_BUF_SIZE,
1444 MAX_PHYS_INFO, testfrags);
1445 if (cc != cmdrsp->net.rcv.numrcvbufs) {
1446 dev_err(&devdata->netdev->dev,
1447 "**** %s Something wrong; rcvd chain length %d different from one we calculated %d\n",
1448 netdev->name, cmdrsp->net.rcv.numrcvbufs, cc);
1449 }
1450 for (i = 0; i < cc; i++) {
1451 dev_inf(&devdata->netdev->dev,
1452 "test:RCVPOST_BUF_SIZE:%d[%d] pfn:%llu off:0x%x len:%d\n",
1453 RCVPOST_BUF_SIZE, i, testfrags[i].pi_pfn,
1454 testfrags[i].pi_off, testfrags[i].pi_len);
1455 } 1293 }
1456#endif
1457 } 1294 }
1458 1295
1459 /* set up packet's protocl type using ethernet header - this 1296 /* set up packet's protocl type using ethernet header - this
@@ -1505,10 +1342,11 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1505 /* drop packet - don't forward it up to OS */ 1342 /* drop packet - don't forward it up to OS */
1506 devdata->n_rcv_packets_not_accepted++; 1343 devdata->n_rcv_packets_not_accepted++;
1507 repost_return(cmdrsp, devdata, skb, netdev); 1344 repost_return(cmdrsp, devdata, skb, netdev);
1508 return; 1345 return rx_count;
1509 } while (0); 1346 } while (0);
1510 1347
1511 status = netif_rx(skb); 1348 rx_count++;
1349 netif_receive_skb(skb);
1512 /* netif_rx returns various values, but "in practice most drivers 1350 /* netif_rx returns various values, but "in practice most drivers
1513 * ignore the return value 1351 * ignore the return value
1514 */ 1352 */
@@ -1520,6 +1358,7 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1520 * new rcv buffer. 1358 * new rcv buffer.
1521 */ 1359 */
1522 repost_return(cmdrsp, devdata, skb, netdev); 1360 repost_return(cmdrsp, devdata, skb, netdev);
1361 return rx_count;
1523} 1362}
1524 1363
1525/** 1364/**
@@ -1545,14 +1384,11 @@ devdata_initialize(struct visornic_devdata *devdata, struct visor_device *dev)
1545 spin_unlock(&dev_num_pool_lock); 1384 spin_unlock(&dev_num_pool_lock);
1546 if (devnum == MAXDEVICES) 1385 if (devnum == MAXDEVICES)
1547 devnum = -1; 1386 devnum = -1;
1548 if (devnum < 0) { 1387 if (devnum < 0)
1549 kfree(devdata);
1550 return NULL; 1388 return NULL;
1551 }
1552 devdata->devnum = devnum; 1389 devdata->devnum = devnum;
1553 devdata->dev = dev; 1390 devdata->dev = dev;
1554 strncpy(devdata->name, dev_name(&dev->device), sizeof(devdata->name)); 1391 strncpy(devdata->name, dev_name(&dev->device), sizeof(devdata->name));
1555 kref_init(&devdata->kref);
1556 spin_lock(&lock_all_devices); 1392 spin_lock(&lock_all_devices);
1557 list_add_tail(&devdata->list_all, &list_all_devices); 1393 list_add_tail(&devdata->list_all, &list_all_devices);
1558 spin_unlock(&lock_all_devices); 1394 spin_unlock(&lock_all_devices);
@@ -1560,24 +1396,23 @@ devdata_initialize(struct visornic_devdata *devdata, struct visor_device *dev)
1560} 1396}
1561 1397
1562/** 1398/**
1563 * devdata_release - Frees up a devdata 1399 * devdata_release - Frees up references in devdata
1564 * @mykref: kref to the devdata 1400 * @devdata: struct to clean up
1565 * 1401 *
1566 * Frees up a devdata. 1402 * Frees up references in devdata.
1567 * Returns void 1403 * Returns void
1568 */ 1404 */
1569static void devdata_release(struct kref *mykref) 1405static void devdata_release(struct visornic_devdata *devdata)
1570{ 1406{
1571 struct visornic_devdata *devdata =
1572 container_of(mykref, struct visornic_devdata, kref);
1573
1574 spin_lock(&dev_num_pool_lock); 1407 spin_lock(&dev_num_pool_lock);
1575 clear_bit(devdata->devnum, dev_num_pool); 1408 clear_bit(devdata->devnum, dev_num_pool);
1576 spin_unlock(&dev_num_pool_lock); 1409 spin_unlock(&dev_num_pool_lock);
1577 spin_lock(&lock_all_devices); 1410 spin_lock(&lock_all_devices);
1578 list_del(&devdata->list_all); 1411 list_del(&devdata->list_all);
1579 spin_unlock(&lock_all_devices); 1412 spin_unlock(&lock_all_devices);
1580 kfree(devdata); 1413 kfree(devdata->rcvbuf);
1414 kfree(devdata->cmdrsp_rcv);
1415 kfree(devdata->xmit_cmdrsp);
1581} 1416}
1582 1417
1583static const struct net_device_ops visornic_dev_ops = { 1418static const struct net_device_ops visornic_dev_ops = {
@@ -1585,12 +1420,163 @@ static const struct net_device_ops visornic_dev_ops = {
1585 .ndo_stop = visornic_close, 1420 .ndo_stop = visornic_close,
1586 .ndo_start_xmit = visornic_xmit, 1421 .ndo_start_xmit = visornic_xmit,
1587 .ndo_get_stats = visornic_get_stats, 1422 .ndo_get_stats = visornic_get_stats,
1588 .ndo_do_ioctl = visornic_ioctl,
1589 .ndo_change_mtu = visornic_change_mtu, 1423 .ndo_change_mtu = visornic_change_mtu,
1590 .ndo_tx_timeout = visornic_xmit_timeout, 1424 .ndo_tx_timeout = visornic_xmit_timeout,
1591 .ndo_set_rx_mode = visornic_set_multi, 1425 .ndo_set_rx_mode = visornic_set_multi,
1592}; 1426};
1593 1427
1428/* DebugFS code */
1429static ssize_t info_debugfs_read(struct file *file, char __user *buf,
1430 size_t len, loff_t *offset)
1431{
1432 ssize_t bytes_read = 0;
1433 int str_pos = 0;
1434 struct visornic_devdata *devdata;
1435 struct net_device *dev;
1436 char *vbuf;
1437
1438 if (len > MAX_BUF)
1439 len = MAX_BUF;
1440 vbuf = kzalloc(len, GFP_KERNEL);
1441 if (!vbuf)
1442 return -ENOMEM;
1443
1444 /* for each vnic channel
1445 * dump out channel specific data
1446 */
1447 rcu_read_lock();
1448 for_each_netdev_rcu(current->nsproxy->net_ns, dev) {
1449 /*
1450 * Only consider netdevs that are visornic, and are open
1451 */
1452 if ((dev->netdev_ops != &visornic_dev_ops) ||
1453 (!netif_queue_stopped(dev)))
1454 continue;
1455
1456 devdata = netdev_priv(dev);
1457 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1458 "netdev = %s (0x%p), MAC Addr %pM\n",
1459 dev->name,
1460 dev,
1461 dev->dev_addr);
1462 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1463 "VisorNic Dev Info = 0x%p\n", devdata);
1464 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1465 " num_rcv_bufs = %d\n",
1466 devdata->num_rcv_bufs);
1467 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1468 " max_oustanding_next_xmits = %lu\n",
1469 devdata->max_outstanding_net_xmits);
1470 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1471 " upper_threshold_net_xmits = %lu\n",
1472 devdata->upper_threshold_net_xmits);
1473 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1474 " lower_threshold_net_xmits = %lu\n",
1475 devdata->lower_threshold_net_xmits);
1476 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1477 " queuefullmsg_logged = %d\n",
1478 devdata->queuefullmsg_logged);
1479 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1480 " chstat.got_rcv = %lu\n",
1481 devdata->chstat.got_rcv);
1482 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1483 " chstat.got_enbdisack = %lu\n",
1484 devdata->chstat.got_enbdisack);
1485 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1486 " chstat.got_xmit_done = %lu\n",
1487 devdata->chstat.got_xmit_done);
1488 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1489 " chstat.xmit_fail = %lu\n",
1490 devdata->chstat.xmit_fail);
1491 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1492 " chstat.sent_enbdis = %lu\n",
1493 devdata->chstat.sent_enbdis);
1494 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1495 " chstat.sent_promisc = %lu\n",
1496 devdata->chstat.sent_promisc);
1497 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1498 " chstat.sent_post = %lu\n",
1499 devdata->chstat.sent_post);
1500 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1501 " chstat.sent_post_failed = %lu\n",
1502 devdata->chstat.sent_post_failed);
1503 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1504 " chstat.sent_xmit = %lu\n",
1505 devdata->chstat.sent_xmit);
1506 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1507 " chstat.reject_count = %lu\n",
1508 devdata->chstat.reject_count);
1509 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1510 " chstat.extra_rcvbufs_sent = %lu\n",
1511 devdata->chstat.extra_rcvbufs_sent);
1512 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1513 " n_rcv0 = %lu\n", devdata->n_rcv0);
1514 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1515 " n_rcv1 = %lu\n", devdata->n_rcv1);
1516 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1517 " n_rcv2 = %lu\n", devdata->n_rcv2);
1518 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1519 " n_rcvx = %lu\n", devdata->n_rcvx);
1520 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1521 " num_rcvbuf_in_iovm = %d\n",
1522 atomic_read(&devdata->num_rcvbuf_in_iovm));
1523 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1524 " alloc_failed_in_if_needed_cnt = %lu\n",
1525 devdata->alloc_failed_in_if_needed_cnt);
1526 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1527 " alloc_failed_in_repost_rtn_cnt = %lu\n",
1528 devdata->alloc_failed_in_repost_rtn_cnt);
1529 /* str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1530 * " inner_loop_limit_reached_cnt = %lu\n",
1531 * devdata->inner_loop_limit_reached_cnt);
1532 */
1533 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1534 " found_repost_rcvbuf_cnt = %lu\n",
1535 devdata->found_repost_rcvbuf_cnt);
1536 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1537 " repost_found_skb_cnt = %lu\n",
1538 devdata->repost_found_skb_cnt);
1539 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1540 " n_repost_deficit = %lu\n",
1541 devdata->n_repost_deficit);
1542 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1543 " bad_rcv_buf = %lu\n",
1544 devdata->bad_rcv_buf);
1545 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1546 " n_rcv_packets_not_accepted = %lu\n",
1547 devdata->n_rcv_packets_not_accepted);
1548 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1549 " interrupts_rcvd = %llu\n",
1550 devdata->interrupts_rcvd);
1551 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1552 " interrupts_notme = %llu\n",
1553 devdata->interrupts_notme);
1554 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1555 " interrupts_disabled = %llu\n",
1556 devdata->interrupts_disabled);
1557 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1558 " busy_cnt = %llu\n",
1559 devdata->busy_cnt);
1560 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1561 " flow_control_upper_hits = %llu\n",
1562 devdata->flow_control_upper_hits);
1563 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1564 " flow_control_lower_hits = %llu\n",
1565 devdata->flow_control_lower_hits);
1566 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1567 " netif_queue = %s\n",
1568 netif_queue_stopped(devdata->netdev) ?
1569 "stopped" : "running");
1570 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1571 " xmits_outstanding = %lu\n",
1572 devdata_xmits_outstanding(devdata));
1573 }
1574 rcu_read_unlock();
1575 bytes_read = simple_read_from_buffer(buf, len, offset, vbuf, str_pos);
1576 kfree(vbuf);
1577 return bytes_read;
1578}
1579
1594/** 1580/**
1595 * send_rcv_posts_if_needed 1581 * send_rcv_posts_if_needed
1596 * @devdata: visornic device 1582 * @devdata: visornic device
@@ -1644,15 +1630,15 @@ send_rcv_posts_if_needed(struct visornic_devdata *devdata)
1644 * Returns when response queue is empty or when the threadd stops. 1630 * Returns when response queue is empty or when the threadd stops.
1645 */ 1631 */
1646static void 1632static void
1647drain_queue(struct uiscmdrsp *cmdrsp, struct visornic_devdata *devdata) 1633service_resp_queue(struct uiscmdrsp *cmdrsp, struct visornic_devdata *devdata,
1634 int *rx_work_done)
1648{ 1635{
1649 unsigned long flags; 1636 unsigned long flags;
1650 struct net_device *netdev; 1637 struct net_device *netdev;
1651 1638
1652 /* drain queue */ 1639 /* TODO: CLIENT ACQUIRE -- Don't really need this at the
1653 while (1) { 1640 * moment */
1654 /* TODO: CLIENT ACQUIRE -- Don't really need this at the 1641 for (;;) {
1655 * moment */
1656 if (!visorchannel_signalremove(devdata->dev->visorchannel, 1642 if (!visorchannel_signalremove(devdata->dev->visorchannel,
1657 IOCHAN_FROM_IOPART, 1643 IOCHAN_FROM_IOPART,
1658 cmdrsp)) 1644 cmdrsp))
@@ -1662,7 +1648,7 @@ drain_queue(struct uiscmdrsp *cmdrsp, struct visornic_devdata *devdata)
1662 case NET_RCV: 1648 case NET_RCV:
1663 devdata->chstat.got_rcv++; 1649 devdata->chstat.got_rcv++;
1664 /* process incoming packet */ 1650 /* process incoming packet */
1665 visornic_rx(cmdrsp); 1651 *rx_work_done += visornic_rx(cmdrsp);
1666 break; 1652 break;
1667 case NET_XMIT_DONE: 1653 case NET_XMIT_DONE:
1668 spin_lock_irqsave(&devdata->priv_lock, flags); 1654 spin_lock_irqsave(&devdata->priv_lock, flags);
@@ -1678,16 +1664,8 @@ drain_queue(struct uiscmdrsp *cmdrsp, struct visornic_devdata *devdata)
1678 * the lower watermark for 1664 * the lower watermark for
1679 * netif_wake_queue() 1665 * netif_wake_queue()
1680 */ 1666 */
1681 if (((devdata->chstat.sent_xmit >= 1667 if (vnic_hit_low_watermark(devdata,
1682 devdata->chstat.got_xmit_done) && 1668 devdata->lower_threshold_net_xmits)) {
1683 (devdata->chstat.sent_xmit -
1684 devdata->chstat.got_xmit_done <=
1685 devdata->lower_threshold_net_xmits)) ||
1686 ((devdata->chstat.sent_xmit <
1687 devdata->chstat.got_xmit_done) &&
1688 (ULONG_MAX - devdata->chstat.got_xmit_done
1689 + devdata->chstat.sent_xmit <=
1690 devdata->lower_threshold_net_xmits))) {
1691 /* enough NET_XMITs completed 1669 /* enough NET_XMITs completed
1692 * so can restart netif queue 1670 * so can restart netif queue
1693 */ 1671 */
@@ -1738,50 +1716,51 @@ drain_queue(struct uiscmdrsp *cmdrsp, struct visornic_devdata *devdata)
1738 break; 1716 break;
1739 } 1717 }
1740 /* cmdrsp is now available for reuse */ 1718 /* cmdrsp is now available for reuse */
1741
1742 if (kthread_should_stop())
1743 break;
1744 } 1719 }
1745} 1720}
1746 1721
1722static int visornic_poll(struct napi_struct *napi, int budget)
1723{
1724 struct visornic_devdata *devdata = container_of(napi,
1725 struct visornic_devdata,
1726 napi);
1727 int rx_count = 0;
1728
1729 send_rcv_posts_if_needed(devdata);
1730 service_resp_queue(devdata->cmdrsp, devdata, &rx_count);
1731
1732 /*
1733 * If there aren't any more packets to receive
1734 * stop the poll
1735 */
1736 if (rx_count < budget)
1737 napi_complete(napi);
1738
1739 return rx_count;
1740}
1741
1747/** 1742/**
1748 * process_incoming_rsps - Checks the status of the response queue. 1743 * poll_for_irq - Checks the status of the response queue.
1749 * @v: void pointer to the visronic devdata 1744 * @v: void pointer to the visronic devdata
1750 * 1745 *
1751 * Main function of the vnic_incoming thread. Peridocially check the 1746 * Main function of the vnic_incoming thread. Peridocially check the
1752 * response queue and drain it if needed. 1747 * response queue and drain it if needed.
1753 * Returns when thread has stopped. 1748 * Returns when thread has stopped.
1754 */ 1749 */
1755static int 1750static void
1756process_incoming_rsps(void *v) 1751poll_for_irq(unsigned long v)
1757{ 1752{
1758 struct visornic_devdata *devdata = v; 1753 struct visornic_devdata *devdata = (struct visornic_devdata *)v;
1759 struct uiscmdrsp *cmdrsp = NULL;
1760 const int SZ = SIZEOF_CMDRSP;
1761 1754
1762 cmdrsp = kmalloc(SZ, GFP_ATOMIC); 1755 if (!visorchannel_signalempty(
1763 if (!cmdrsp) 1756 devdata->dev->visorchannel,
1764 complete_and_exit(&devdata->threadinfo.has_stopped, 0); 1757 IOCHAN_FROM_IOPART))
1758 napi_schedule(&devdata->napi);
1765 1759
1766 while (1) { 1760 atomic_set(&devdata->interrupt_rcvd, 0);
1767 wait_event_interruptible_timeout(
1768 devdata->rsp_queue, (atomic_read(
1769 &devdata->interrupt_rcvd) == 1),
1770 msecs_to_jiffies(devdata->thread_wait_ms));
1771 1761
1772 /* periodically check to see if there are any rcf bufs which 1762 mod_timer(&devdata->irq_poll_timer, msecs_to_jiffies(2));
1773 * need to get sent to the IOSP. This can only happen if
1774 * we run out of memory when trying to allocate skbs.
1775 */
1776 atomic_set(&devdata->interrupt_rcvd, 0);
1777 send_rcv_posts_if_needed(devdata);
1778 drain_queue(cmdrsp, devdata);
1779 if (kthread_should_stop())
1780 break;
1781 }
1782 1763
1783 kfree(cmdrsp);
1784 complete_and_exit(&devdata->threadinfo.has_stopped, 0);
1785} 1764}
1786 1765
1787/** 1766/**
@@ -1801,12 +1780,15 @@ static int visornic_probe(struct visor_device *dev)
1801 u64 features; 1780 u64 features;
1802 1781
1803 netdev = alloc_etherdev(sizeof(struct visornic_devdata)); 1782 netdev = alloc_etherdev(sizeof(struct visornic_devdata));
1804 if (!netdev) 1783 if (!netdev) {
1784 dev_err(&dev->device,
1785 "%s alloc_etherdev failed\n", __func__);
1805 return -ENOMEM; 1786 return -ENOMEM;
1787 }
1806 1788
1807 netdev->netdev_ops = &visornic_dev_ops; 1789 netdev->netdev_ops = &visornic_dev_ops;
1808 netdev->watchdog_timeo = (5 * HZ); 1790 netdev->watchdog_timeo = (5 * HZ);
1809 netdev->dev.parent = &dev->device; 1791 SET_NETDEV_DEV(netdev, &dev->device);
1810 1792
1811 /* Get MAC adddress from channel and read it into the device. */ 1793 /* Get MAC adddress from channel and read it into the device. */
1812 netdev->addr_len = ETH_ALEN; 1794 netdev->addr_len = ETH_ALEN;
@@ -1814,16 +1796,23 @@ static int visornic_probe(struct visor_device *dev)
1814 vnic.macaddr); 1796 vnic.macaddr);
1815 err = visorbus_read_channel(dev, channel_offset, netdev->dev_addr, 1797 err = visorbus_read_channel(dev, channel_offset, netdev->dev_addr,
1816 ETH_ALEN); 1798 ETH_ALEN);
1817 if (err < 0) 1799 if (err < 0) {
1800 dev_err(&dev->device,
1801 "%s failed to get mac addr from chan (%d)\n",
1802 __func__, err);
1818 goto cleanup_netdev; 1803 goto cleanup_netdev;
1804 }
1819 1805
1820 devdata = devdata_initialize(netdev_priv(netdev), dev); 1806 devdata = devdata_initialize(netdev_priv(netdev), dev);
1821 if (!devdata) { 1807 if (!devdata) {
1808 dev_err(&dev->device,
1809 "%s devdata_initialize failed\n", __func__);
1822 err = -ENOMEM; 1810 err = -ENOMEM;
1823 goto cleanup_netdev; 1811 goto cleanup_netdev;
1824 } 1812 }
1825 1813
1826 devdata->netdev = netdev; 1814 devdata->netdev = netdev;
1815 dev_set_drvdata(&dev->device, devdata);
1827 init_waitqueue_head(&devdata->rsp_queue); 1816 init_waitqueue_head(&devdata->rsp_queue);
1828 spin_lock_init(&devdata->priv_lock); 1817 spin_lock_init(&devdata->priv_lock);
1829 devdata->enabled = 0; /* not yet */ 1818 devdata->enabled = 0; /* not yet */
@@ -1834,10 +1823,14 @@ static int visornic_probe(struct visor_device *dev)
1834 vnic.num_rcv_bufs); 1823 vnic.num_rcv_bufs);
1835 err = visorbus_read_channel(dev, channel_offset, 1824 err = visorbus_read_channel(dev, channel_offset,
1836 &devdata->num_rcv_bufs, 4); 1825 &devdata->num_rcv_bufs, 4);
1837 if (err) 1826 if (err) {
1827 dev_err(&dev->device,
1828 "%s failed to get #rcv bufs from chan (%d)\n",
1829 __func__, err);
1838 goto cleanup_netdev; 1830 goto cleanup_netdev;
1831 }
1839 1832
1840 devdata->rcvbuf = kmalloc(sizeof(struct sk_buff *) * 1833 devdata->rcvbuf = kzalloc(sizeof(struct sk_buff *) *
1841 devdata->num_rcv_bufs, GFP_KERNEL); 1834 devdata->num_rcv_bufs, GFP_KERNEL);
1842 if (!devdata->rcvbuf) { 1835 if (!devdata->rcvbuf) {
1843 err = -ENOMEM; 1836 err = -ENOMEM;
@@ -1846,12 +1839,15 @@ static int visornic_probe(struct visor_device *dev)
1846 1839
1847 /* set the net_xmit outstanding threshold */ 1840 /* set the net_xmit outstanding threshold */
1848 /* always leave two slots open but you should have 3 at a minimum */ 1841 /* always leave two slots open but you should have 3 at a minimum */
1842 /* note that max_outstanding_net_xmits must be > 0 */
1849 devdata->max_outstanding_net_xmits = 1843 devdata->max_outstanding_net_xmits =
1850 max(3, ((devdata->num_rcv_bufs / 3) - 2)); 1844 max_t(unsigned long, 3, ((devdata->num_rcv_bufs / 3) - 2));
1851 devdata->upper_threshold_net_xmits = 1845 devdata->upper_threshold_net_xmits =
1852 max(2, devdata->max_outstanding_net_xmits - 1); 1846 max_t(unsigned long,
1847 2, (devdata->max_outstanding_net_xmits - 1));
1853 devdata->lower_threshold_net_xmits = 1848 devdata->lower_threshold_net_xmits =
1854 max(1, devdata->max_outstanding_net_xmits / 2); 1849 max_t(unsigned long,
1850 1, (devdata->max_outstanding_net_xmits / 2));
1855 1851
1856 skb_queue_head_init(&devdata->xmitbufhead); 1852 skb_queue_head_init(&devdata->xmitbufhead);
1857 1853
@@ -1866,8 +1862,6 @@ static int visornic_probe(struct visor_device *dev)
1866 err = -ENOMEM; 1862 err = -ENOMEM;
1867 goto cleanup_xmit_cmdrsp; 1863 goto cleanup_xmit_cmdrsp;
1868 } 1864 }
1869 INIT_WORK(&devdata->serverdown_completion,
1870 visornic_serverdown_complete);
1871 INIT_WORK(&devdata->timeout_reset, visornic_timeout_reset); 1865 INIT_WORK(&devdata->timeout_reset, visornic_timeout_reset);
1872 devdata->server_down = false; 1866 devdata->server_down = false;
1873 devdata->server_change_state = false; 1867 devdata->server_change_state = false;
@@ -1876,42 +1870,70 @@ static int visornic_probe(struct visor_device *dev)
1876 channel_offset = offsetof(struct spar_io_channel_protocol, 1870 channel_offset = offsetof(struct spar_io_channel_protocol,
1877 vnic.mtu); 1871 vnic.mtu);
1878 err = visorbus_read_channel(dev, channel_offset, &netdev->mtu, 4); 1872 err = visorbus_read_channel(dev, channel_offset, &netdev->mtu, 4);
1879 if (err) 1873 if (err) {
1874 dev_err(&dev->device,
1875 "%s failed to get mtu from chan (%d)\n",
1876 __func__, err);
1880 goto cleanup_xmit_cmdrsp; 1877 goto cleanup_xmit_cmdrsp;
1878 }
1881 1879
1882 /* TODO: Setup Interrupt information */ 1880 /* TODO: Setup Interrupt information */
1883 /* Let's start our threads to get responses */ 1881 /* Let's start our threads to get responses */
1882 netif_napi_add(netdev, &devdata->napi, visornic_poll, 64);
1883
1884 setup_timer(&devdata->irq_poll_timer, poll_for_irq,
1885 (unsigned long)devdata);
1886 /*
1887 * Note: This time has to start running before the while
1888 * loop below because the napi routine is responsible for
1889 * setting enab_dis_acked
1890 */
1891 mod_timer(&devdata->irq_poll_timer, msecs_to_jiffies(2));
1892
1884 channel_offset = offsetof(struct spar_io_channel_protocol, 1893 channel_offset = offsetof(struct spar_io_channel_protocol,
1885 channel_header.features); 1894 channel_header.features);
1886 err = visorbus_read_channel(dev, channel_offset, &features, 8); 1895 err = visorbus_read_channel(dev, channel_offset, &features, 8);
1887 if (err) 1896 if (err) {
1888 goto cleanup_xmit_cmdrsp; 1897 dev_err(&dev->device,
1898 "%s failed to get features from chan (%d)\n",
1899 __func__, err);
1900 goto cleanup_napi_add;
1901 }
1889 1902
1890 features |= ULTRA_IO_CHANNEL_IS_POLLING; 1903 features |= ULTRA_IO_CHANNEL_IS_POLLING;
1891 err = visorbus_write_channel(dev, channel_offset, &features, 8); 1904 err = visorbus_write_channel(dev, channel_offset, &features, 8);
1892 if (err) 1905 if (err) {
1893 goto cleanup_xmit_cmdrsp; 1906 dev_err(&dev->device,
1894 1907 "%s failed to set features in chan (%d)\n",
1895 devdata->thread_wait_ms = 2; 1908 __func__, err);
1896 visor_thread_start(&devdata->threadinfo, process_incoming_rsps, 1909 goto cleanup_napi_add;
1897 devdata, "vnic_incoming"); 1910 }
1898 1911
1899 err = register_netdev(netdev); 1912 err = register_netdev(netdev);
1900 if (err) 1913 if (err) {
1901 goto cleanup_thread_stop; 1914 dev_err(&dev->device,
1915 "%s register_netdev failed (%d)\n", __func__, err);
1916 goto cleanup_napi_add;
1917 }
1902 1918
1903 /* create debgug/sysfs directories */ 1919 /* create debgug/sysfs directories */
1904 devdata->eth_debugfs_dir = debugfs_create_dir(netdev->name, 1920 devdata->eth_debugfs_dir = debugfs_create_dir(netdev->name,
1905 visornic_debugfs_dir); 1921 visornic_debugfs_dir);
1906 if (!devdata->eth_debugfs_dir) { 1922 if (!devdata->eth_debugfs_dir) {
1923 dev_err(&dev->device,
1924 "%s debugfs_create_dir %s failed\n",
1925 __func__, netdev->name);
1907 err = -ENOMEM; 1926 err = -ENOMEM;
1908 goto cleanup_thread_stop; 1927 goto cleanup_xmit_cmdrsp;
1909 } 1928 }
1910 1929
1930 dev_info(&dev->device, "%s success netdev=%s\n",
1931 __func__, netdev->name);
1911 return 0; 1932 return 0;
1912 1933
1913cleanup_thread_stop: 1934cleanup_napi_add:
1914 visor_thread_stop(&devdata->threadinfo); 1935 del_timer_sync(&devdata->irq_poll_timer);
1936 netif_napi_del(&devdata->napi);
1915 1937
1916cleanup_xmit_cmdrsp: 1938cleanup_xmit_cmdrsp:
1917 kfree(devdata->xmit_cmdrsp); 1939 kfree(devdata->xmit_cmdrsp);
@@ -1954,12 +1976,41 @@ static void host_side_disappeared(struct visornic_devdata *devdata)
1954static void visornic_remove(struct visor_device *dev) 1976static void visornic_remove(struct visor_device *dev)
1955{ 1977{
1956 struct visornic_devdata *devdata = dev_get_drvdata(&dev->device); 1978 struct visornic_devdata *devdata = dev_get_drvdata(&dev->device);
1979 struct net_device *netdev;
1980 unsigned long flags;
1957 1981
1958 if (!devdata) 1982 if (!devdata) {
1983 dev_err(&dev->device, "%s no devdata\n", __func__);
1984 return;
1985 }
1986 spin_lock_irqsave(&devdata->priv_lock, flags);
1987 if (devdata->going_away) {
1988 spin_unlock_irqrestore(&devdata->priv_lock, flags);
1989 dev_err(&dev->device, "%s already being removed\n", __func__);
1959 return; 1990 return;
1991 }
1992 devdata->going_away = true;
1993 spin_unlock_irqrestore(&devdata->priv_lock, flags);
1994 netdev = devdata->netdev;
1995 if (!netdev) {
1996 dev_err(&dev->device, "%s not net device\n", __func__);
1997 return;
1998 }
1999
2000 /* going_away prevents new items being added to the workqueues */
2001 flush_workqueue(visornic_timeout_reset_workqueue);
2002
2003 debugfs_remove_recursive(devdata->eth_debugfs_dir);
2004
2005 unregister_netdev(netdev); /* this will call visornic_close() */
2006
2007 del_timer_sync(&devdata->irq_poll_timer);
2008 netif_napi_del(&devdata->napi);
2009
1960 dev_set_drvdata(&dev->device, NULL); 2010 dev_set_drvdata(&dev->device, NULL);
1961 host_side_disappeared(devdata); 2011 host_side_disappeared(devdata);
1962 kref_put(&devdata->kref, devdata_release); 2012 devdata_release(devdata);
2013 free_netdev(netdev);
1963} 2014}
1964 2015
1965/** 2016/**
@@ -1980,8 +2031,7 @@ static int visornic_pause(struct visor_device *dev,
1980{ 2031{
1981 struct visornic_devdata *devdata = dev_get_drvdata(&dev->device); 2032 struct visornic_devdata *devdata = dev_get_drvdata(&dev->device);
1982 2033
1983 visornic_serverdown(devdata); 2034 visornic_serverdown(devdata, complete_func);
1984 complete_func(dev, 0);
1985 return 0; 2035 return 0;
1986} 2036}
1987 2037
@@ -2003,37 +2053,40 @@ static int visornic_resume(struct visor_device *dev,
2003 unsigned long flags; 2053 unsigned long flags;
2004 2054
2005 devdata = dev_get_drvdata(&dev->device); 2055 devdata = dev_get_drvdata(&dev->device);
2006 if (!devdata) 2056 if (!devdata) {
2057 dev_err(&dev->device, "%s no devdata\n", __func__);
2007 return -EINVAL; 2058 return -EINVAL;
2059 }
2008 2060
2009 netdev = devdata->netdev; 2061 netdev = devdata->netdev;
2010 2062
2011 if (devdata->server_down && !devdata->server_change_state) { 2063 spin_lock_irqsave(&devdata->priv_lock, flags);
2012 devdata->server_change_state = true; 2064 if (devdata->server_change_state) {
2013 /* Must transition channel to ATTACHED state BEFORE
2014 * we can start using the device again.
2015 * TODO: State transitions
2016 */
2017 visor_thread_start(&devdata->threadinfo, process_incoming_rsps,
2018 devdata, "vnic_incoming");
2019 init_rcv_bufs(netdev, devdata);
2020 spin_lock_irqsave(&devdata->priv_lock, flags);
2021 devdata->enabled = 1;
2022
2023 /* Now we're ready, let's send an ENB to uisnic but until
2024 * we get an ACK back from uisnic, we'll drop the packets
2025 */
2026 devdata->enab_dis_acked = 0;
2027 spin_unlock_irqrestore(&devdata->priv_lock, flags); 2065 spin_unlock_irqrestore(&devdata->priv_lock, flags);
2028 2066 dev_err(&dev->device, "%s server already changing state\n",
2029 /* send enable and wait for ack - don't hold lock when 2067 __func__);
2030 * sending enable because if the queue if sull, insert 2068 return -EINVAL;
2031 * might sleep. 2069 }
2032 */ 2070 if (!devdata->server_down) {
2033 send_enbdis(netdev, 1, devdata); 2071 spin_unlock_irqrestore(&devdata->priv_lock, flags);
2034 } else if (devdata->server_change_state) { 2072 dev_err(&dev->device, "%s server not down\n", __func__);
2035 return -EIO; 2073 complete_func(dev, 0);
2074 return 0;
2036 } 2075 }
2076 devdata->server_change_state = true;
2077 spin_unlock_irqrestore(&devdata->priv_lock, flags);
2078
2079 /* Must transition channel to ATTACHED state BEFORE
2080 * we can start using the device again.
2081 * TODO: State transitions
2082 */
2083 mod_timer(&devdata->irq_poll_timer, msecs_to_jiffies(2));
2084
2085 init_rcv_bufs(netdev, devdata);
2086
2087 rtnl_lock();
2088 dev_open(netdev);
2089 rtnl_unlock();
2037 2090
2038 complete_func(dev, 0); 2091 complete_func(dev, 0);
2039 return 0; 2092 return 0;
@@ -2051,18 +2104,6 @@ static int visornic_init(void)
2051 struct dentry *ret; 2104 struct dentry *ret;
2052 int err = -ENOMEM; 2105 int err = -ENOMEM;
2053 2106
2054 /* create workqueue for serverdown completion */
2055 visornic_serverdown_workqueue =
2056 create_singlethread_workqueue("visornic_serverdown");
2057 if (!visornic_serverdown_workqueue)
2058 return -ENOMEM;
2059
2060 /* create workqueue for tx timeout reset */
2061 visornic_timeout_reset_workqueue =
2062 create_singlethread_workqueue("visornic_timeout_reset");
2063 if (!visornic_timeout_reset_workqueue)
2064 return -ENOMEM;
2065
2066 visornic_debugfs_dir = debugfs_create_dir("visornic", NULL); 2107 visornic_debugfs_dir = debugfs_create_dir("visornic", NULL);
2067 if (!visornic_debugfs_dir) 2108 if (!visornic_debugfs_dir)
2068 return err; 2109 return err;
@@ -2076,12 +2117,6 @@ static int visornic_init(void)
2076 if (!ret) 2117 if (!ret)
2077 goto cleanup_debugfs; 2118 goto cleanup_debugfs;
2078 2119
2079 /* create workqueue for serverdown completion */
2080 visornic_serverdown_workqueue =
2081 create_singlethread_workqueue("visornic_serverdown");
2082 if (!visornic_serverdown_workqueue)
2083 goto cleanup_debugfs;
2084
2085 /* create workqueue for tx timeout reset */ 2120 /* create workqueue for tx timeout reset */
2086 visornic_timeout_reset_workqueue = 2121 visornic_timeout_reset_workqueue =
2087 create_singlethread_workqueue("visornic_timeout_reset"); 2122 create_singlethread_workqueue("visornic_timeout_reset");
@@ -2097,8 +2132,6 @@ static int visornic_init(void)
2097 return 0; 2132 return 0;
2098 2133
2099cleanup_workqueue: 2134cleanup_workqueue:
2100 flush_workqueue(visornic_serverdown_workqueue);
2101 destroy_workqueue(visornic_serverdown_workqueue);
2102 if (visornic_timeout_reset_workqueue) { 2135 if (visornic_timeout_reset_workqueue) {
2103 flush_workqueue(visornic_timeout_reset_workqueue); 2136 flush_workqueue(visornic_timeout_reset_workqueue);
2104 destroy_workqueue(visornic_timeout_reset_workqueue); 2137 destroy_workqueue(visornic_timeout_reset_workqueue);
@@ -2116,17 +2149,14 @@ cleanup_debugfs:
2116 */ 2149 */
2117static void visornic_cleanup(void) 2150static void visornic_cleanup(void)
2118{ 2151{
2119 if (visornic_serverdown_workqueue) { 2152 visorbus_unregister_visor_driver(&visornic_driver);
2120 flush_workqueue(visornic_serverdown_workqueue); 2153
2121 destroy_workqueue(visornic_serverdown_workqueue);
2122 }
2123 if (visornic_timeout_reset_workqueue) { 2154 if (visornic_timeout_reset_workqueue) {
2124 flush_workqueue(visornic_timeout_reset_workqueue); 2155 flush_workqueue(visornic_timeout_reset_workqueue);
2125 destroy_workqueue(visornic_timeout_reset_workqueue); 2156 destroy_workqueue(visornic_timeout_reset_workqueue);
2126 } 2157 }
2127 debugfs_remove_recursive(visornic_debugfs_dir); 2158 debugfs_remove_recursive(visornic_debugfs_dir);
2128 2159
2129 visorbus_unregister_visor_driver(&visornic_driver);
2130 kfree(dev_num_pool); 2160 kfree(dev_num_pool);
2131 dev_num_pool = NULL; 2161 dev_num_pool = NULL;
2132} 2162}
diff --git a/drivers/staging/vme/devices/vme_pio2_core.c b/drivers/staging/vme/devices/vme_pio2_core.c
index eabbcc710a20..35c6ce5047de 100644
--- a/drivers/staging/vme/devices/vme_pio2_core.c
+++ b/drivers/staging/vme/devices/vme_pio2_core.c
@@ -24,7 +24,6 @@
24 24
25#include "vme_pio2.h" 25#include "vme_pio2.h"
26 26
27
28static const char driver_name[] = "pio2"; 27static const char driver_name[] = "pio2";
29 28
30static int bus[PIO2_CARDS_MAX]; 29static int bus[PIO2_CARDS_MAX];
@@ -118,7 +117,6 @@ static void pio2_int(int level, int vector, void *ptr)
118 } 117 }
119} 118}
120 119
121
122/* 120/*
123 * We return whether this has been successful - this is used in the probe to 121 * We return whether this has been successful - this is used in the probe to
124 * ensure we have a valid card. 122 * ensure we have a valid card.
@@ -158,7 +156,6 @@ static struct vme_driver pio2_driver = {
158 .remove = pio2_remove, 156 .remove = pio2_remove,
159}; 157};
160 158
161
162static int __init pio2_init(void) 159static int __init pio2_init(void)
163{ 160{
164 if (bus_num == 0) { 161 if (bus_num == 0) {
@@ -178,7 +175,6 @@ static int __init pio2_init(void)
178 175
179static int pio2_match(struct vme_dev *vdev) 176static int pio2_match(struct vme_dev *vdev)
180{ 177{
181
182 if (vdev->num >= bus_num) { 178 if (vdev->num >= bus_num) {
183 dev_err(&vdev->dev, 179 dev_err(&vdev->dev,
184 "The enumeration of the VMEbus to which the board is connected must be specified\n"); 180 "The enumeration of the VMEbus to which the board is connected must be specified\n");
@@ -220,7 +216,7 @@ static int pio2_probe(struct vme_dev *vdev)
220 int vec; 216 int vec;
221 217
222 card = kzalloc(sizeof(struct pio2_card), GFP_KERNEL); 218 card = kzalloc(sizeof(struct pio2_card), GFP_KERNEL);
223 if (card == NULL) { 219 if (!card) {
224 retval = -ENOMEM; 220 retval = -ENOMEM;
225 goto err_struct; 221 goto err_struct;
226 } 222 }
@@ -234,7 +230,6 @@ static int pio2_probe(struct vme_dev *vdev)
234 card->vdev = vdev; 230 card->vdev = vdev;
235 231
236 for (i = 0; i < PIO2_VARIANT_LENGTH; i++) { 232 for (i = 0; i < PIO2_VARIANT_LENGTH; i++) {
237
238 if (isdigit(card->variant[i]) == 0) { 233 if (isdigit(card->variant[i]) == 0) {
239 dev_err(&card->vdev->dev, "Variant invalid\n"); 234 dev_err(&card->vdev->dev, "Variant invalid\n");
240 retval = -EINVAL; 235 retval = -EINVAL;
@@ -264,29 +259,29 @@ static int pio2_probe(struct vme_dev *vdev)
264 for (i = 1; i < PIO2_VARIANT_LENGTH; i++) { 259 for (i = 1; i < PIO2_VARIANT_LENGTH; i++) {
265 switch (card->variant[i]) { 260 switch (card->variant[i]) {
266 case '0': 261 case '0':
267 card->bank[i-1].config = NOFIT; 262 card->bank[i - 1].config = NOFIT;
268 break; 263 break;
269 case '1': 264 case '1':
270 case '2': 265 case '2':
271 case '3': 266 case '3':
272 case '4': 267 case '4':
273 card->bank[i-1].config = INPUT; 268 card->bank[i - 1].config = INPUT;
274 break; 269 break;
275 case '5': 270 case '5':
276 card->bank[i-1].config = OUTPUT; 271 card->bank[i - 1].config = OUTPUT;
277 break; 272 break;
278 case '6': 273 case '6':
279 case '7': 274 case '7':
280 case '8': 275 case '8':
281 case '9': 276 case '9':
282 card->bank[i-1].config = BOTH; 277 card->bank[i - 1].config = BOTH;
283 break; 278 break;
284 } 279 }
285 } 280 }
286 281
287 /* Get a master window and position over regs */ 282 /* Get a master window and position over regs */
288 card->window = vme_master_request(vdev, VME_A24, VME_SCT, VME_D16); 283 card->window = vme_master_request(vdev, VME_A24, VME_SCT, VME_D16);
289 if (card->window == NULL) { 284 if (!card->window) {
290 dev_err(&card->vdev->dev, 285 dev_err(&card->vdev->dev,
291 "Unable to assign VME master resource\n"); 286 "Unable to assign VME master resource\n");
292 retval = -EIO; 287 retval = -EIO;
@@ -481,7 +476,6 @@ static void __exit pio2_exit(void)
481 vme_unregister_driver(&pio2_driver); 476 vme_unregister_driver(&pio2_driver);
482} 477}
483 478
484
485/* These are required for each board */ 479/* These are required for each board */
486MODULE_PARM_DESC(bus, "Enumeration of VMEbus to which the board is connected"); 480MODULE_PARM_DESC(bus, "Enumeration of VMEbus to which the board is connected");
487module_param_array(bus, int, &bus_num, S_IRUGO); 481module_param_array(bus, int, &bus_num, S_IRUGO);
diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c
index 9cca97af3044..8e61a3b3e7e4 100644
--- a/drivers/staging/vme/devices/vme_user.c
+++ b/drivers/staging/vme/devices/vme_user.c
@@ -101,13 +101,13 @@ struct image_desc {
101 struct vme_resource *resource; /* VME resource */ 101 struct vme_resource *resource; /* VME resource */
102 int mmap_count; /* Number of current mmap's */ 102 int mmap_count; /* Number of current mmap's */
103}; 103};
104
104static struct image_desc image[VME_DEVS]; 105static struct image_desc image[VME_DEVS];
105 106
106static struct cdev *vme_user_cdev; /* Character device */ 107static struct cdev *vme_user_cdev; /* Character device */
107static struct class *vme_user_sysfs_class; /* Sysfs class */ 108static struct class *vme_user_sysfs_class; /* Sysfs class */
108static struct vme_dev *vme_user_bridge; /* Pointer to user device */ 109static struct vme_dev *vme_user_bridge; /* Pointer to user device */
109 110
110
111static const int type[VME_DEVS] = { MASTER_MINOR, MASTER_MINOR, 111static const int type[VME_DEVS] = { MASTER_MINOR, MASTER_MINOR,
112 MASTER_MINOR, MASTER_MINOR, 112 MASTER_MINOR, MASTER_MINOR,
113 SLAVE_MINOR, SLAVE_MINOR, 113 SLAVE_MINOR, SLAVE_MINOR,
@@ -120,125 +120,68 @@ struct vme_user_vma_priv {
120 atomic_t refcnt; 120 atomic_t refcnt;
121}; 121};
122 122
123
124/*
125 * We are going ot alloc a page during init per window for small transfers.
126 * Small transfers will go VME -> buffer -> user space. Larger (more than a
127 * page) transfers will lock the user space buffer into memory and then
128 * transfer the data directly into the user space buffers.
129 */
130static ssize_t resource_to_user(int minor, char __user *buf, size_t count, 123static ssize_t resource_to_user(int minor, char __user *buf, size_t count,
131 loff_t *ppos) 124 loff_t *ppos)
132{ 125{
133 ssize_t retval;
134 ssize_t copied = 0; 126 ssize_t copied = 0;
135 127
136 if (count <= image[minor].size_buf) { 128 if (count > image[minor].size_buf)
137 /* We copy to kernel buffer */ 129 count = image[minor].size_buf;
138 copied = vme_master_read(image[minor].resource,
139 image[minor].kern_buf, count, *ppos);
140 if (copied < 0)
141 return (int)copied;
142
143 retval = __copy_to_user(buf, image[minor].kern_buf,
144 (unsigned long)copied);
145 if (retval != 0) {
146 copied = (copied - retval);
147 pr_info("User copy failed\n");
148 return -EINVAL;
149 }
150 130
151 } else { 131 copied = vme_master_read(image[minor].resource, image[minor].kern_buf,
152 /* XXX Need to write this */ 132 count, *ppos);
153 pr_info("Currently don't support large transfers\n"); 133 if (copied < 0)
154 /* Map in pages from userspace */ 134 return (int)copied;
155 135
156 /* Call vme_master_read to do the transfer */ 136 if (__copy_to_user(buf, image[minor].kern_buf, (unsigned long)copied))
157 return -EINVAL; 137 return -EFAULT;
158 }
159 138
160 return copied; 139 return copied;
161} 140}
162 141
163/*
164 * We are going to alloc a page during init per window for small transfers.
165 * Small transfers will go user space -> buffer -> VME. Larger (more than a
166 * page) transfers will lock the user space buffer into memory and then
167 * transfer the data directly from the user space buffers out to VME.
168 */
169static ssize_t resource_from_user(unsigned int minor, const char __user *buf, 142static ssize_t resource_from_user(unsigned int minor, const char __user *buf,
170 size_t count, loff_t *ppos) 143 size_t count, loff_t *ppos)
171{ 144{
172 ssize_t retval; 145 if (count > image[minor].size_buf)
173 ssize_t copied = 0; 146 count = image[minor].size_buf;
174 147
175 if (count <= image[minor].size_buf) { 148 if (__copy_from_user(image[minor].kern_buf, buf, (unsigned long)count))
176 retval = __copy_from_user(image[minor].kern_buf, buf, 149 return -EFAULT;
177 (unsigned long)count);
178 if (retval != 0)
179 copied = (copied - retval);
180 else
181 copied = count;
182
183 copied = vme_master_write(image[minor].resource,
184 image[minor].kern_buf, copied, *ppos);
185 } else {
186 /* XXX Need to write this */
187 pr_info("Currently don't support large transfers\n");
188 /* Map in pages from userspace */
189
190 /* Call vme_master_write to do the transfer */
191 return -EINVAL;
192 }
193 150
194 return copied; 151 return vme_master_write(image[minor].resource, image[minor].kern_buf,
152 count, *ppos);
195} 153}
196 154
197static ssize_t buffer_to_user(unsigned int minor, char __user *buf, 155static ssize_t buffer_to_user(unsigned int minor, char __user *buf,
198 size_t count, loff_t *ppos) 156 size_t count, loff_t *ppos)
199{ 157{
200 void *image_ptr; 158 void *image_ptr;
201 ssize_t retval;
202 159
203 image_ptr = image[minor].kern_buf + *ppos; 160 image_ptr = image[minor].kern_buf + *ppos;
161 if (__copy_to_user(buf, image_ptr, (unsigned long)count))
162 return -EFAULT;
204 163
205 retval = __copy_to_user(buf, image_ptr, (unsigned long)count); 164 return count;
206 if (retval != 0) {
207 retval = (count - retval);
208 pr_warn("Partial copy to userspace\n");
209 } else
210 retval = count;
211
212 /* Return number of bytes successfully read */
213 return retval;
214} 165}
215 166
216static ssize_t buffer_from_user(unsigned int minor, const char __user *buf, 167static ssize_t buffer_from_user(unsigned int minor, const char __user *buf,
217 size_t count, loff_t *ppos) 168 size_t count, loff_t *ppos)
218{ 169{
219 void *image_ptr; 170 void *image_ptr;
220 size_t retval;
221 171
222 image_ptr = image[minor].kern_buf + *ppos; 172 image_ptr = image[minor].kern_buf + *ppos;
173 if (__copy_from_user(image_ptr, buf, (unsigned long)count))
174 return -EFAULT;
223 175
224 retval = __copy_from_user(image_ptr, buf, (unsigned long)count); 176 return count;
225 if (retval != 0) {
226 retval = (count - retval);
227 pr_warn("Partial copy to userspace\n");
228 } else
229 retval = count;
230
231 /* Return number of bytes successfully read */
232 return retval;
233} 177}
234 178
235static ssize_t vme_user_read(struct file *file, char __user *buf, size_t count, 179static ssize_t vme_user_read(struct file *file, char __user *buf, size_t count,
236 loff_t *ppos) 180 loff_t *ppos)
237{ 181{
238 unsigned int minor = MINOR(file_inode(file)->i_rdev); 182 unsigned int minor = MINOR(file_inode(file)->i_rdev);
239 ssize_t retval; 183 ssize_t retval;
240 size_t image_size; 184 size_t image_size;
241 size_t okcount;
242 185
243 if (minor == CONTROL_MINOR) 186 if (minor == CONTROL_MINOR)
244 return 0; 187 return 0;
@@ -256,16 +199,14 @@ static ssize_t vme_user_read(struct file *file, char __user *buf, size_t count,
256 199
257 /* Ensure not reading past end of the image */ 200 /* Ensure not reading past end of the image */
258 if (*ppos + count > image_size) 201 if (*ppos + count > image_size)
259 okcount = image_size - *ppos; 202 count = image_size - *ppos;
260 else
261 okcount = count;
262 203
263 switch (type[minor]) { 204 switch (type[minor]) {
264 case MASTER_MINOR: 205 case MASTER_MINOR:
265 retval = resource_to_user(minor, buf, okcount, ppos); 206 retval = resource_to_user(minor, buf, count, ppos);
266 break; 207 break;
267 case SLAVE_MINOR: 208 case SLAVE_MINOR:
268 retval = buffer_to_user(minor, buf, okcount, ppos); 209 retval = buffer_to_user(minor, buf, count, ppos);
269 break; 210 break;
270 default: 211 default:
271 retval = -EINVAL; 212 retval = -EINVAL;
@@ -279,12 +220,11 @@ static ssize_t vme_user_read(struct file *file, char __user *buf, size_t count,
279} 220}
280 221
281static ssize_t vme_user_write(struct file *file, const char __user *buf, 222static ssize_t vme_user_write(struct file *file, const char __user *buf,
282 size_t count, loff_t *ppos) 223 size_t count, loff_t *ppos)
283{ 224{
284 unsigned int minor = MINOR(file_inode(file)->i_rdev); 225 unsigned int minor = MINOR(file_inode(file)->i_rdev);
285 ssize_t retval; 226 ssize_t retval;
286 size_t image_size; 227 size_t image_size;
287 size_t okcount;
288 228
289 if (minor == CONTROL_MINOR) 229 if (minor == CONTROL_MINOR)
290 return 0; 230 return 0;
@@ -301,16 +241,14 @@ static ssize_t vme_user_write(struct file *file, const char __user *buf,
301 241
302 /* Ensure not reading past end of the image */ 242 /* Ensure not reading past end of the image */
303 if (*ppos + count > image_size) 243 if (*ppos + count > image_size)
304 okcount = image_size - *ppos; 244 count = image_size - *ppos;
305 else
306 okcount = count;
307 245
308 switch (type[minor]) { 246 switch (type[minor]) {
309 case MASTER_MINOR: 247 case MASTER_MINOR:
310 retval = resource_from_user(minor, buf, okcount, ppos); 248 retval = resource_from_user(minor, buf, count, ppos);
311 break; 249 break;
312 case SLAVE_MINOR: 250 case SLAVE_MINOR:
313 retval = buffer_from_user(minor, buf, okcount, ppos); 251 retval = buffer_from_user(minor, buf, count, ppos);
314 break; 252 break;
315 default: 253 default:
316 retval = -EINVAL; 254 retval = -EINVAL;
@@ -354,7 +292,7 @@ static loff_t vme_user_llseek(struct file *file, loff_t off, int whence)
354 * already been defined. 292 * already been defined.
355 */ 293 */
356static int vme_user_ioctl(struct inode *inode, struct file *file, 294static int vme_user_ioctl(struct inode *inode, struct file *file,
357 unsigned int cmd, unsigned long arg) 295 unsigned int cmd, unsigned long arg)
358{ 296{
359 struct vme_master master; 297 struct vme_master master;
360 struct vme_slave slave; 298 struct vme_slave slave;
@@ -390,12 +328,13 @@ static int vme_user_ioctl(struct inode *inode, struct file *file,
390 * to userspace as they are 328 * to userspace as they are
391 */ 329 */
392 retval = vme_master_get(image[minor].resource, 330 retval = vme_master_get(image[minor].resource,
393 &master.enable, &master.vme_addr, 331 &master.enable,
394 &master.size, &master.aspace, 332 &master.vme_addr,
395 &master.cycle, &master.dwidth); 333 &master.size, &master.aspace,
334 &master.cycle, &master.dwidth);
396 335
397 copied = copy_to_user(argp, &master, 336 copied = copy_to_user(argp, &master,
398 sizeof(struct vme_master)); 337 sizeof(struct vme_master));
399 if (copied != 0) { 338 if (copied != 0) {
400 pr_warn("Partial copy to userspace\n"); 339 pr_warn("Partial copy to userspace\n");
401 return -EFAULT; 340 return -EFAULT;
@@ -435,12 +374,12 @@ static int vme_user_ioctl(struct inode *inode, struct file *file,
435 * to userspace as they are 374 * to userspace as they are
436 */ 375 */
437 retval = vme_slave_get(image[minor].resource, 376 retval = vme_slave_get(image[minor].resource,
438 &slave.enable, &slave.vme_addr, 377 &slave.enable, &slave.vme_addr,
439 &slave.size, &pci_addr, &slave.aspace, 378 &slave.size, &pci_addr,
440 &slave.cycle); 379 &slave.aspace, &slave.cycle);
441 380
442 copied = copy_to_user(argp, &slave, 381 copied = copy_to_user(argp, &slave,
443 sizeof(struct vme_slave)); 382 sizeof(struct vme_slave));
444 if (copied != 0) { 383 if (copied != 0) {
445 pr_warn("Partial copy to userspace\n"); 384 pr_warn("Partial copy to userspace\n");
446 return -EFAULT; 385 return -EFAULT;
@@ -526,8 +465,8 @@ static int vme_user_master_mmap(unsigned int minor, struct vm_area_struct *vma)
526 return err; 465 return err;
527 } 466 }
528 467
529 vma_priv = kmalloc(sizeof(struct vme_user_vma_priv), GFP_KERNEL); 468 vma_priv = kmalloc(sizeof(*vma_priv), GFP_KERNEL);
530 if (vma_priv == NULL) { 469 if (!vma_priv) {
531 mutex_unlock(&image[minor].mutex); 470 mutex_unlock(&image[minor].mutex);
532 return -ENOMEM; 471 return -ENOMEM;
533 } 472 }
@@ -588,7 +527,7 @@ static int vme_user_probe(struct vme_dev *vdev)
588 char *name; 527 char *name;
589 528
590 /* Save pointer to the bridge device */ 529 /* Save pointer to the bridge device */
591 if (vme_user_bridge != NULL) { 530 if (vme_user_bridge) {
592 dev_err(&vdev->dev, "Driver can only be loaded for 1 device\n"); 531 dev_err(&vdev->dev, "Driver can only be loaded for 1 device\n");
593 err = -EINVAL; 532 err = -EINVAL;
594 goto err_dev; 533 goto err_dev;
@@ -606,7 +545,7 @@ static int vme_user_probe(struct vme_dev *vdev)
606 545
607 /* Assign major and minor numbers for the driver */ 546 /* Assign major and minor numbers for the driver */
608 err = register_chrdev_region(MKDEV(VME_MAJOR, 0), VME_DEVS, 547 err = register_chrdev_region(MKDEV(VME_MAJOR, 0), VME_DEVS,
609 driver_name); 548 driver_name);
610 if (err) { 549 if (err) {
611 dev_warn(&vdev->dev, "Error getting Major Number %d for driver.\n", 550 dev_warn(&vdev->dev, "Error getting Major Number %d for driver.\n",
612 VME_MAJOR); 551 VME_MAJOR);
@@ -622,10 +561,8 @@ static int vme_user_probe(struct vme_dev *vdev)
622 vme_user_cdev->ops = &vme_user_fops; 561 vme_user_cdev->ops = &vme_user_fops;
623 vme_user_cdev->owner = THIS_MODULE; 562 vme_user_cdev->owner = THIS_MODULE;
624 err = cdev_add(vme_user_cdev, MKDEV(VME_MAJOR, 0), VME_DEVS); 563 err = cdev_add(vme_user_cdev, MKDEV(VME_MAJOR, 0), VME_DEVS);
625 if (err) { 564 if (err)
626 dev_warn(&vdev->dev, "cdev_all failed\n");
627 goto err_char; 565 goto err_char;
628 }
629 566
630 /* Request slave resources and allocate buffers (128kB wide) */ 567 /* Request slave resources and allocate buffers (128kB wide) */
631 for (i = SLAVE_MINOR; i < (SLAVE_MAX + 1); i++) { 568 for (i = SLAVE_MINOR; i < (SLAVE_MAX + 1); i++) {
@@ -636,7 +573,7 @@ static int vme_user_probe(struct vme_dev *vdev)
636 */ 573 */
637 image[i].resource = vme_slave_request(vme_user_bridge, 574 image[i].resource = vme_slave_request(vme_user_bridge,
638 VME_A24, VME_SCT); 575 VME_A24, VME_SCT);
639 if (image[i].resource == NULL) { 576 if (!image[i].resource) {
640 dev_warn(&vdev->dev, 577 dev_warn(&vdev->dev,
641 "Unable to allocate slave resource\n"); 578 "Unable to allocate slave resource\n");
642 err = -ENOMEM; 579 err = -ENOMEM;
@@ -645,7 +582,7 @@ static int vme_user_probe(struct vme_dev *vdev)
645 image[i].size_buf = PCI_BUF_SIZE; 582 image[i].size_buf = PCI_BUF_SIZE;
646 image[i].kern_buf = vme_alloc_consistent(image[i].resource, 583 image[i].kern_buf = vme_alloc_consistent(image[i].resource,
647 image[i].size_buf, &image[i].pci_buf); 584 image[i].size_buf, &image[i].pci_buf);
648 if (image[i].kern_buf == NULL) { 585 if (!image[i].kern_buf) {
649 dev_warn(&vdev->dev, 586 dev_warn(&vdev->dev,
650 "Unable to allocate memory for buffer\n"); 587 "Unable to allocate memory for buffer\n");
651 image[i].pci_buf = 0; 588 image[i].pci_buf = 0;
@@ -663,7 +600,7 @@ static int vme_user_probe(struct vme_dev *vdev)
663 /* XXX Need to properly request attributes */ 600 /* XXX Need to properly request attributes */
664 image[i].resource = vme_master_request(vme_user_bridge, 601 image[i].resource = vme_master_request(vme_user_bridge,
665 VME_A32, VME_SCT, VME_D32); 602 VME_A32, VME_SCT, VME_D32);
666 if (image[i].resource == NULL) { 603 if (!image[i].resource) {
667 dev_warn(&vdev->dev, 604 dev_warn(&vdev->dev,
668 "Unable to allocate master resource\n"); 605 "Unable to allocate master resource\n");
669 err = -ENOMEM; 606 err = -ENOMEM;
@@ -671,7 +608,7 @@ static int vme_user_probe(struct vme_dev *vdev)
671 } 608 }
672 image[i].size_buf = PCI_BUF_SIZE; 609 image[i].size_buf = PCI_BUF_SIZE;
673 image[i].kern_buf = kmalloc(image[i].size_buf, GFP_KERNEL); 610 image[i].kern_buf = kmalloc(image[i].size_buf, GFP_KERNEL);
674 if (image[i].kern_buf == NULL) { 611 if (!image[i].kern_buf) {
675 err = -ENOMEM; 612 err = -ENOMEM;
676 vme_master_free(image[i].resource); 613 vme_master_free(image[i].resource);
677 goto err_master; 614 goto err_master;
@@ -835,7 +772,6 @@ static void __exit vme_user_exit(void)
835 vme_unregister_driver(&vme_user_driver); 772 vme_unregister_driver(&vme_user_driver);
836} 773}
837 774
838
839MODULE_PARM_DESC(bus, "Enumeration of VMEbus to which the driver is connected"); 775MODULE_PARM_DESC(bus, "Enumeration of VMEbus to which the driver is connected");
840module_param_array(bus, int, &bus_num, 0); 776module_param_array(bus, int, &bus_num, 0);
841 777
diff --git a/drivers/staging/vt6655/baseband.c b/drivers/staging/vt6655/baseband.c
index b0ea38f1911c..9e61f2df3a00 100644
--- a/drivers/staging/vt6655/baseband.c
+++ b/drivers/staging/vt6655/baseband.c
@@ -1728,10 +1728,8 @@ BBuGetFrameTime(
1728 unsigned int uRateIdx = (unsigned int) wRate; 1728 unsigned int uRateIdx = (unsigned int) wRate;
1729 unsigned int uRate = 0; 1729 unsigned int uRate = 0;
1730 1730
1731 if (uRateIdx > RATE_54M) { 1731 if (uRateIdx > RATE_54M)
1732 ASSERT(0);
1733 return 0; 1732 return 0;
1734 }
1735 1733
1736 uRate = (unsigned int)awcFrameTime[uRateIdx]; 1734 uRate = (unsigned int)awcFrameTime[uRateIdx];
1737 1735
@@ -1945,7 +1943,6 @@ bool BBbReadEmbedded(struct vnt_private *priv,
1945 VNSvInPortB(dwIoBase + MAC_REG_BBREGDATA, pbyData); 1943 VNSvInPortB(dwIoBase + MAC_REG_BBREGDATA, pbyData);
1946 1944
1947 if (ww == W_MAX_TIMEOUT) { 1945 if (ww == W_MAX_TIMEOUT) {
1948 DBG_PORT80(0x30);
1949 pr_debug(" DBG_PORT80(0x30)\n"); 1946 pr_debug(" DBG_PORT80(0x30)\n");
1950 return false; 1947 return false;
1951 } 1948 }
@@ -1988,7 +1985,6 @@ bool BBbWriteEmbedded(struct vnt_private *priv,
1988 } 1985 }
1989 1986
1990 if (ww == W_MAX_TIMEOUT) { 1987 if (ww == W_MAX_TIMEOUT) {
1991 DBG_PORT80(0x31);
1992 pr_debug(" DBG_PORT80(0x31)\n"); 1988 pr_debug(" DBG_PORT80(0x31)\n");
1993 return false; 1989 return false;
1994 } 1990 }
diff --git a/drivers/staging/vt6655/card.c b/drivers/staging/vt6655/card.c
index e00c0605d154..c7b75dfc2d5f 100644
--- a/drivers/staging/vt6655/card.c
+++ b/drivers/staging/vt6655/card.c
@@ -514,7 +514,7 @@ CARDvSafeResetTx(
514) 514)
515{ 515{
516 unsigned int uu; 516 unsigned int uu;
517 PSTxDesc pCurrTD; 517 struct vnt_tx_desc *pCurrTD;
518 518
519 /* initialize TD index */ 519 /* initialize TD index */
520 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]); 520 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
@@ -525,12 +525,12 @@ CARDvSafeResetTx(
525 525
526 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) { 526 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
527 pCurrTD = &(pDevice->apTD0Rings[uu]); 527 pCurrTD = &(pDevice->apTD0Rings[uu]);
528 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST; 528 pCurrTD->td0.owner = OWNED_BY_HOST;
529 /* init all Tx Packet pointer to NULL */ 529 /* init all Tx Packet pointer to NULL */
530 } 530 }
531 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) { 531 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
532 pCurrTD = &(pDevice->apTD1Rings[uu]); 532 pCurrTD = &(pDevice->apTD1Rings[uu]);
533 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST; 533 pCurrTD->td0.owner = OWNED_BY_HOST;
534 /* init all Tx Packet pointer to NULL */ 534 /* init all Tx Packet pointer to NULL */
535 } 535 }
536 536
@@ -573,17 +573,17 @@ CARDvSafeResetRx(
573 /* init state, all RD is chip's */ 573 /* init state, all RD is chip's */
574 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) { 574 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
575 pDesc = &(pDevice->aRD0Ring[uu]); 575 pDesc = &(pDevice->aRD0Ring[uu]);
576 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz); 576 pDesc->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
577 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC; 577 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
578 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz); 578 pDesc->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
579 } 579 }
580 580
581 /* init state, all RD is chip's */ 581 /* init state, all RD is chip's */
582 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) { 582 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
583 pDesc = &(pDevice->aRD1Ring[uu]); 583 pDesc = &(pDevice->aRD1Ring[uu]);
584 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz); 584 pDesc->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
585 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC; 585 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
586 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz); 586 pDesc->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
587 } 587 }
588 588
589 /* set perPkt mode */ 589 /* set perPkt mode */
@@ -847,7 +847,6 @@ void CARDvSetLoopbackMode(struct vnt_private *priv, unsigned short wLoopbackMode
847 case CARD_LB_PHY: 847 case CARD_LB_PHY:
848 break; 848 break;
849 default: 849 default:
850 ASSERT(false);
851 break; 850 break;
852 } 851 }
853 /* set MAC loopback */ 852 /* set MAC loopback */
diff --git a/drivers/staging/vt6655/desc.h b/drivers/staging/vt6655/desc.h
index 758eeb2afd51..3c9007e34c0f 100644
--- a/drivers/staging/vt6655/desc.h
+++ b/drivers/staging/vt6655/desc.h
@@ -170,13 +170,12 @@
170typedef struct tagDEVICE_RD_INFO { 170typedef struct tagDEVICE_RD_INFO {
171 struct sk_buff *skb; 171 struct sk_buff *skb;
172 dma_addr_t skb_dma; 172 dma_addr_t skb_dma;
173 dma_addr_t curr_desc;
174} DEVICE_RD_INFO, *PDEVICE_RD_INFO; 173} DEVICE_RD_INFO, *PDEVICE_RD_INFO;
175 174
176#ifdef __BIG_ENDIAN 175#ifdef __BIG_ENDIAN
177 176
178typedef struct tagRDES0 { 177typedef struct tagRDES0 {
179 volatile unsigned short wResCount; 178 volatile __le16 wResCount;
180 union { 179 union {
181 volatile u16 f15Reserved; 180 volatile u16 f15Reserved;
182 struct { 181 struct {
@@ -191,7 +190,7 @@ SRDES0, *PSRDES0;
191#else 190#else
192 191
193typedef struct tagRDES0 { 192typedef struct tagRDES0 {
194 unsigned short wResCount; 193 __le16 wResCount;
195 unsigned short f15Reserved:15; 194 unsigned short f15Reserved:15;
196 unsigned short f1Owner:1; 195 unsigned short f1Owner:1;
197} __attribute__ ((__packed__)) 196} __attribute__ ((__packed__))
@@ -200,7 +199,7 @@ SRDES0;
200#endif 199#endif
201 200
202typedef struct tagRDES1 { 201typedef struct tagRDES1 {
203 unsigned short wReqCount; 202 __le16 wReqCount;
204 unsigned short wReserved; 203 unsigned short wReserved;
205} __attribute__ ((__packed__)) 204} __attribute__ ((__packed__))
206SRDES1; 205SRDES1;
@@ -209,93 +208,56 @@ SRDES1;
209typedef struct tagSRxDesc { 208typedef struct tagSRxDesc {
210 volatile SRDES0 m_rd0RD0; 209 volatile SRDES0 m_rd0RD0;
211 volatile SRDES1 m_rd1RD1; 210 volatile SRDES1 m_rd1RD1;
212 volatile u32 buff_addr; 211 volatile __le32 buff_addr;
213 volatile u32 next_desc; 212 volatile __le32 next_desc;
214 struct tagSRxDesc *next __aligned(8); 213 struct tagSRxDesc *next __aligned(8);
215 volatile PDEVICE_RD_INFO pRDInfo __aligned(8); 214 volatile PDEVICE_RD_INFO pRDInfo __aligned(8);
216} __attribute__ ((__packed__)) 215} __attribute__ ((__packed__))
217SRxDesc, *PSRxDesc; 216SRxDesc, *PSRxDesc;
218typedef const SRxDesc *PCSRxDesc; 217typedef const SRxDesc *PCSRxDesc;
219 218
219struct vnt_tdes0 {
220 volatile u8 tsr0;
221 volatile u8 tsr1;
220#ifdef __BIG_ENDIAN 222#ifdef __BIG_ENDIAN
221
222typedef struct tagTDES0 {
223 volatile unsigned char byTSR0;
224 volatile unsigned char byTSR1;
225 union { 223 union {
226 volatile u16 f15Txtime; 224 volatile u16 f15_txtime;
227 struct { 225 struct {
228 volatile u8 f8Reserved1; 226 volatile u8 f8_reserved;
229 volatile u8 f1Owner:1; 227 volatile u8 owner:1;
230 volatile u8 f7Reserved:7; 228 volatile u8 f7_reserved:7;
231 } __attribute__ ((__packed__)); 229 } __packed;
232 } __attribute__ ((__packed__)); 230 } __packed;
233} __attribute__ ((__packed__))
234STDES0, PSTDES0;
235
236#else 231#else
237 232 volatile u16 f15_txtime:15;
238typedef struct tagTDES0 { 233 volatile u16 owner:1;
239 volatile unsigned char byTSR0;
240 volatile unsigned char byTSR1;
241 volatile unsigned short f15Txtime:15;
242 volatile unsigned short f1Owner:1;
243} __attribute__ ((__packed__))
244STDES0;
245
246#endif 234#endif
235} __packed;
247 236
248typedef struct tagTDES1 { 237struct vnt_tdes1 {
249 volatile unsigned short wReqCount; 238 volatile __le16 req_count;
250 volatile unsigned char byTCR; 239 volatile u8 tcr;
251 volatile unsigned char byReserved; 240 volatile u8 reserved;
252} __attribute__ ((__packed__)) 241} __packed;
253STDES1;
254 242
255typedef struct tagDEVICE_TD_INFO { 243struct vnt_td_info {
256 void *mic_hdr; 244 void *mic_hdr;
257 struct sk_buff *skb; 245 struct sk_buff *skb;
258 unsigned char *buf; 246 unsigned char *buf;
259 dma_addr_t skb_dma; 247 dma_addr_t buf_dma;
260 dma_addr_t buf_dma; 248 u16 req_count;
261 dma_addr_t curr_desc; 249 u8 flags;
262 unsigned long dwReqCount; 250};
263 unsigned long dwHeaderLength;
264 unsigned char byFlags;
265} DEVICE_TD_INFO, *PDEVICE_TD_INFO;
266 251
267/* transmit descriptor */ 252/* transmit descriptor */
268typedef struct tagSTxDesc { 253struct vnt_tx_desc {
269 volatile STDES0 m_td0TD0; 254 volatile struct vnt_tdes0 td0;
270 volatile STDES1 m_td1TD1; 255 volatile struct vnt_tdes1 td1;
271 volatile u32 buff_addr; 256 volatile __le32 buff_addr;
272 volatile u32 next_desc; 257 volatile __le32 next_desc;
273 struct tagSTxDesc *next __aligned(8); 258 struct vnt_tx_desc *next __aligned(8);
274 volatile PDEVICE_TD_INFO pTDInfo __aligned(8); 259 struct vnt_td_info *td_info __aligned(8);
275} __attribute__ ((__packed__)) 260} __packed;
276STxDesc, *PSTxDesc;
277typedef const STxDesc *PCSTxDesc;
278
279typedef struct tagSTxSyncDesc {
280 volatile STDES0 m_td0TD0;
281 volatile STDES1 m_td1TD1;
282 volatile u32 buff_addr; /* pointer to logical buffer */
283 volatile u32 next_desc; /* pointer to next logical descriptor */
284 volatile unsigned short m_wFIFOCtl;
285 volatile unsigned short m_wTimeStamp;
286 struct tagSTxSyncDesc *next __aligned(8);
287 volatile PDEVICE_TD_INFO pTDInfo __aligned(8);
288} __attribute__ ((__packed__))
289STxSyncDesc, *PSTxSyncDesc;
290typedef const STxSyncDesc *PCSTxSyncDesc;
291
292/* RsvTime buffer header */
293typedef struct tagSRrvTime_atim {
294 unsigned short wCTSTxRrvTime_ba;
295 unsigned short wTxRrvTime_a;
296} __attribute__ ((__packed__))
297SRrvTime_atim, *PSRrvTime_atim;
298typedef const SRrvTime_atim *PCSRrvTime_atim;
299 261
300/* Length, Service, and Signal fields of Phy for Tx */ 262/* Length, Service, and Signal fields of Phy for Tx */
301struct vnt_phy_field { 263struct vnt_phy_field {
@@ -310,42 +272,4 @@ union vnt_phy_field_swap {
310 u32 field_write; 272 u32 field_write;
311}; 273};
312 274
313/* Tx FIFO header */
314typedef struct tagSTxBufHead {
315 u32 adwTxKey[4];
316 unsigned short wFIFOCtl;
317 unsigned short wTimeStamp;
318 unsigned short wFragCtl;
319 unsigned char byTxPower;
320 unsigned char wReserved;
321} __attribute__ ((__packed__))
322STxBufHead, *PSTxBufHead;
323typedef const STxBufHead *PCSTxBufHead;
324
325typedef struct tagSBEACONCtl {
326 u32 BufReady:1;
327 u32 TSF:15;
328 u32 BufLen:11;
329 u32 Reserved:5;
330} __attribute__ ((__packed__))
331SBEACONCtl;
332
333typedef struct tagSSecretKey {
334 u32 dwLowDword;
335 unsigned char byHighByte;
336} __attribute__ ((__packed__))
337SSecretKey;
338
339typedef struct tagSKeyEntry {
340 unsigned char abyAddrHi[2];
341 unsigned short wKCTL;
342 unsigned char abyAddrLo[4];
343 u32 dwKey0[4];
344 u32 dwKey1[4];
345 u32 dwKey2[4];
346 u32 dwKey3[4];
347 u32 dwKey4[4];
348} __attribute__ ((__packed__))
349SKeyEntry;
350
351#endif /* __DESC_H__ */ 275#endif /* __DESC_H__ */
diff --git a/drivers/staging/vt6655/device.h b/drivers/staging/vt6655/device.h
index 5cf1b337cba7..c9fa6ef42d34 100644
--- a/drivers/staging/vt6655/device.h
+++ b/drivers/staging/vt6655/device.h
@@ -252,11 +252,11 @@ struct vnt_private {
252 int nTxQueues; 252 int nTxQueues;
253 volatile int iTDUsed[TYPE_MAXTD]; 253 volatile int iTDUsed[TYPE_MAXTD];
254 254
255 volatile PSTxDesc apCurrTD[TYPE_MAXTD]; 255 struct vnt_tx_desc *apCurrTD[TYPE_MAXTD];
256 volatile PSTxDesc apTailTD[TYPE_MAXTD]; 256 struct vnt_tx_desc *apTailTD[TYPE_MAXTD];
257 257
258 volatile PSTxDesc apTD0Rings; 258 struct vnt_tx_desc *apTD0Rings;
259 volatile PSTxDesc apTD1Rings; 259 struct vnt_tx_desc *apTD1Rings;
260 260
261 volatile PSRxDesc aRD0Ring; 261 volatile PSRxDesc aRD0Ring;
262 volatile PSRxDesc aRD1Ring; 262 volatile PSRxDesc aRD1Ring;
@@ -403,6 +403,7 @@ struct vnt_private {
403 unsigned char abyEEPROM[EEP_MAX_CONTEXT_SIZE]; /* unsigned long alignment */ 403 unsigned char abyEEPROM[EEP_MAX_CONTEXT_SIZE]; /* unsigned long alignment */
404 404
405 unsigned short wBeaconInterval; 405 unsigned short wBeaconInterval;
406 u16 wake_up_count;
406 407
407 struct work_struct interrupt_work; 408 struct work_struct interrupt_work;
408 409
@@ -414,8 +415,8 @@ static inline PDEVICE_RD_INFO alloc_rd_info(void)
414 return kzalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC); 415 return kzalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC);
415} 416}
416 417
417static inline PDEVICE_TD_INFO alloc_td_info(void) 418static inline struct vnt_td_info *alloc_td_info(void)
418{ 419{
419 return kzalloc(sizeof(DEVICE_TD_INFO), GFP_ATOMIC); 420 return kzalloc(sizeof(struct vnt_td_info), GFP_ATOMIC);
420} 421}
421#endif 422#endif
diff --git a/drivers/staging/vt6655/device_cfg.h b/drivers/staging/vt6655/device_cfg.h
index a4a8a8489e0b..b4c9547d3138 100644
--- a/drivers/staging/vt6655/device_cfg.h
+++ b/drivers/staging/vt6655/device_cfg.h
@@ -69,19 +69,4 @@ typedef enum _chip_type {
69 VT3253 = 1 69 VT3253 = 1
70} CHIP_TYPE, *PCHIP_TYPE; 70} CHIP_TYPE, *PCHIP_TYPE;
71 71
72#ifdef VIAWET_DEBUG
73#define ASSERT(x) \
74do { \
75 if (!(x)) { \
76 pr_err("assertion %s failed: file %s line %d\n", \
77 #x, __func__, __LINE__); \
78 *(int *)0 = 0; \
79 } \
80} while (0)
81#define DBG_PORT80(value) outb(value, 0x80)
82#else
83#define ASSERT(x)
84#define DBG_PORT80(value)
85#endif
86
87#endif 72#endif
diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c
index 69bdc8f29b59..0d8f123c57fe 100644
--- a/drivers/staging/vt6655/device_main.c
+++ b/drivers/staging/vt6655/device_main.c
@@ -157,7 +157,7 @@ static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx);
157static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx); 157static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx);
158static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pDesc); 158static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pDesc);
159static void device_init_registers(struct vnt_private *pDevice); 159static void device_init_registers(struct vnt_private *pDevice);
160static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc); 160static void device_free_tx_buf(struct vnt_private *, struct vnt_tx_desc *);
161static void device_free_td0_ring(struct vnt_private *pDevice); 161static void device_free_td0_ring(struct vnt_private *pDevice);
162static void device_free_td1_ring(struct vnt_private *pDevice); 162static void device_free_td1_ring(struct vnt_private *pDevice);
163static void device_free_rd0_ring(struct vnt_private *pDevice); 163static void device_free_rd0_ring(struct vnt_private *pDevice);
@@ -522,8 +522,8 @@ static bool device_init_rings(struct vnt_private *pDevice)
522 vir_pool = dma_zalloc_coherent(&pDevice->pcid->dev, 522 vir_pool = dma_zalloc_coherent(&pDevice->pcid->dev,
523 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) + 523 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
524 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) + 524 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
525 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) + 525 pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc) +
526 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc), 526 pDevice->sOpts.nTxDescs[1] * sizeof(struct vnt_tx_desc),
527 &pDevice->pool_dma, GFP_ATOMIC); 527 &pDevice->pool_dma, GFP_ATOMIC);
528 if (vir_pool == NULL) { 528 if (vir_pool == NULL) {
529 dev_err(&pDevice->pcid->dev, "allocate desc dma memory failed\n"); 529 dev_err(&pDevice->pcid->dev, "allocate desc dma memory failed\n");
@@ -551,8 +551,8 @@ static bool device_init_rings(struct vnt_private *pDevice)
551 dma_free_coherent(&pDevice->pcid->dev, 551 dma_free_coherent(&pDevice->pcid->dev,
552 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) + 552 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
553 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) + 553 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
554 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) + 554 pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc) +
555 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc), 555 pDevice->sOpts.nTxDescs[1] * sizeof(struct vnt_tx_desc),
556 vir_pool, pDevice->pool_dma 556 vir_pool, pDevice->pool_dma
557 ); 557 );
558 return false; 558 return false;
@@ -562,7 +562,7 @@ static bool device_init_rings(struct vnt_private *pDevice)
562 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc); 562 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
563 563
564 pDevice->td1_pool_dma = pDevice->td0_pool_dma + 564 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
565 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc); 565 pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc);
566 566
567 /* vir_pool: pvoid type */ 567 /* vir_pool: pvoid type */
568 pDevice->apTD0Rings = vir_pool 568 pDevice->apTD0Rings = vir_pool
@@ -572,7 +572,7 @@ static bool device_init_rings(struct vnt_private *pDevice)
572 pDevice->apTD1Rings = vir_pool 572 pDevice->apTD1Rings = vir_pool
573 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) 573 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
574 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) 574 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
575 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc); 575 + pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc);
576 576
577 pDevice->tx1_bufs = pDevice->tx0_bufs + 577 pDevice->tx1_bufs = pDevice->tx0_bufs +
578 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ; 578 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
@@ -597,8 +597,8 @@ static void device_free_rings(struct vnt_private *pDevice)
597 dma_free_coherent(&pDevice->pcid->dev, 597 dma_free_coherent(&pDevice->pcid->dev,
598 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) + 598 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
599 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) + 599 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
600 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) + 600 pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc) +
601 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc) 601 pDevice->sOpts.nTxDescs[1] * sizeof(struct vnt_tx_desc)
602 , 602 ,
603 pDevice->aRD0Ring, pDevice->pool_dma 603 pDevice->aRD0Ring, pDevice->pool_dma
604 ); 604 );
@@ -623,12 +623,11 @@ static void device_init_rd0_ring(struct vnt_private *pDevice)
623 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) { 623 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
624 pDesc = &(pDevice->aRD0Ring[i]); 624 pDesc = &(pDevice->aRD0Ring[i]);
625 pDesc->pRDInfo = alloc_rd_info(); 625 pDesc->pRDInfo = alloc_rd_info();
626 ASSERT(pDesc->pRDInfo); 626
627 if (!device_alloc_rx_buf(pDevice, pDesc)) 627 if (!device_alloc_rx_buf(pDevice, pDesc))
628 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n"); 628 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
629 629
630 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]); 630 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
631 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
632 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc)); 631 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
633 } 632 }
634 633
@@ -647,12 +646,11 @@ static void device_init_rd1_ring(struct vnt_private *pDevice)
647 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) { 646 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
648 pDesc = &(pDevice->aRD1Ring[i]); 647 pDesc = &(pDevice->aRD1Ring[i]);
649 pDesc->pRDInfo = alloc_rd_info(); 648 pDesc->pRDInfo = alloc_rd_info();
650 ASSERT(pDesc->pRDInfo); 649
651 if (!device_alloc_rx_buf(pDevice, pDesc)) 650 if (!device_alloc_rx_buf(pDevice, pDesc))
652 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n"); 651 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
653 652
654 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]); 653 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
655 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
656 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc)); 654 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
657 } 655 }
658 656
@@ -699,20 +697,20 @@ static void device_init_td0_ring(struct vnt_private *pDevice)
699{ 697{
700 int i; 698 int i;
701 dma_addr_t curr; 699 dma_addr_t curr;
702 PSTxDesc pDesc; 700 struct vnt_tx_desc *pDesc;
703 701
704 curr = pDevice->td0_pool_dma; 702 curr = pDevice->td0_pool_dma;
705 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) { 703 for (i = 0; i < pDevice->sOpts.nTxDescs[0];
704 i++, curr += sizeof(struct vnt_tx_desc)) {
706 pDesc = &(pDevice->apTD0Rings[i]); 705 pDesc = &(pDevice->apTD0Rings[i]);
707 pDesc->pTDInfo = alloc_td_info(); 706 pDesc->td_info = alloc_td_info();
708 ASSERT(pDesc->pTDInfo); 707
709 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) { 708 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
710 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ; 709 pDesc->td_info->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
711 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ; 710 pDesc->td_info->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
712 } 711 }
713 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]); 712 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
714 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr); 713 pDesc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_tx_desc));
715 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
716 } 714 }
717 715
718 if (i > 0) 716 if (i > 0)
@@ -724,21 +722,21 @@ static void device_init_td1_ring(struct vnt_private *pDevice)
724{ 722{
725 int i; 723 int i;
726 dma_addr_t curr; 724 dma_addr_t curr;
727 PSTxDesc pDesc; 725 struct vnt_tx_desc *pDesc;
728 726
729 /* Init the TD ring entries */ 727 /* Init the TD ring entries */
730 curr = pDevice->td1_pool_dma; 728 curr = pDevice->td1_pool_dma;
731 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr += sizeof(STxDesc)) { 729 for (i = 0; i < pDevice->sOpts.nTxDescs[1];
730 i++, curr += sizeof(struct vnt_tx_desc)) {
732 pDesc = &(pDevice->apTD1Rings[i]); 731 pDesc = &(pDevice->apTD1Rings[i]);
733 pDesc->pTDInfo = alloc_td_info(); 732 pDesc->td_info = alloc_td_info();
734 ASSERT(pDesc->pTDInfo); 733
735 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) { 734 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
736 pDesc->pTDInfo->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ; 735 pDesc->td_info->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
737 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ; 736 pDesc->td_info->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
738 } 737 }
739 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]); 738 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
740 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr); 739 pDesc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_tx_desc));
741 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
742 } 740 }
743 741
744 if (i > 0) 742 if (i > 0)
@@ -751,17 +749,11 @@ static void device_free_td0_ring(struct vnt_private *pDevice)
751 int i; 749 int i;
752 750
753 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) { 751 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
754 PSTxDesc pDesc = &(pDevice->apTD0Rings[i]); 752 struct vnt_tx_desc *pDesc = &pDevice->apTD0Rings[i];
755 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo; 753 struct vnt_td_info *pTDInfo = pDesc->td_info;
756 754
757 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) 755 dev_kfree_skb(pTDInfo->skb);
758 dma_unmap_single(&pDevice->pcid->dev, pTDInfo->skb_dma, 756 kfree(pDesc->td_info);
759 pTDInfo->skb->len, DMA_TO_DEVICE);
760
761 if (pTDInfo->skb)
762 dev_kfree_skb(pTDInfo->skb);
763
764 kfree(pDesc->pTDInfo);
765 } 757 }
766} 758}
767 759
@@ -770,17 +762,11 @@ static void device_free_td1_ring(struct vnt_private *pDevice)
770 int i; 762 int i;
771 763
772 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) { 764 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
773 PSTxDesc pDesc = &(pDevice->apTD1Rings[i]); 765 struct vnt_tx_desc *pDesc = &pDevice->apTD1Rings[i];
774 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo; 766 struct vnt_td_info *pTDInfo = pDesc->td_info;
775
776 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
777 dma_unmap_single(&pDevice->pcid->dev, pTDInfo->skb_dma,
778 pTDInfo->skb->len, DMA_TO_DEVICE);
779
780 if (pTDInfo->skb)
781 dev_kfree_skb(pTDInfo->skb);
782 767
783 kfree(pDesc->pTDInfo); 768 dev_kfree_skb(pTDInfo->skb);
769 kfree(pDesc->td_info);
784 } 770 }
785} 771}
786 772
@@ -822,7 +808,6 @@ static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pRD)
822 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); 808 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
823 if (pRDInfo->skb == NULL) 809 if (pRDInfo->skb == NULL)
824 return false; 810 return false;
825 ASSERT(pRDInfo->skb);
826 811
827 pRDInfo->skb_dma = 812 pRDInfo->skb_dma =
828 dma_map_single(&pDevice->pcid->dev, 813 dma_map_single(&pDevice->pcid->dev,
@@ -856,7 +841,7 @@ static const u8 fallback_rate1[5][5] = {
856}; 841};
857 842
858static int vnt_int_report_rate(struct vnt_private *priv, 843static int vnt_int_report_rate(struct vnt_private *priv,
859 PDEVICE_TD_INFO context, u8 tsr0, u8 tsr1) 844 struct vnt_td_info *context, u8 tsr0, u8 tsr1)
860{ 845{
861 struct vnt_tx_fifo_head *fifo_head; 846 struct vnt_tx_fifo_head *fifo_head;
862 struct ieee80211_tx_info *info; 847 struct ieee80211_tx_info *info;
@@ -917,23 +902,23 @@ static int vnt_int_report_rate(struct vnt_private *priv,
917 902
918static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx) 903static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
919{ 904{
920 PSTxDesc pTD; 905 struct vnt_tx_desc *pTD;
921 int works = 0; 906 int works = 0;
922 unsigned char byTsr0; 907 unsigned char byTsr0;
923 unsigned char byTsr1; 908 unsigned char byTsr1;
924 909
925 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) { 910 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
926 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC) 911 if (pTD->td0.owner == OWNED_BY_NIC)
927 break; 912 break;
928 if (works++ > 15) 913 if (works++ > 15)
929 break; 914 break;
930 915
931 byTsr0 = pTD->m_td0TD0.byTSR0; 916 byTsr0 = pTD->td0.tsr0;
932 byTsr1 = pTD->m_td0TD0.byTSR1; 917 byTsr1 = pTD->td0.tsr1;
933 918
934 /* Only the status of first TD in the chain is correct */ 919 /* Only the status of first TD in the chain is correct */
935 if (pTD->m_td1TD1.byTCR & TCR_STP) { 920 if (pTD->td1.tcr & TCR_STP) {
936 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) { 921 if ((pTD->td_info->flags & TD_FLAGS_NETIF_SKB) != 0) {
937 if (!(byTsr1 & TSR1_TERR)) { 922 if (!(byTsr1 & TSR1_TERR)) {
938 if (byTsr0 != 0) { 923 if (byTsr0 != 0) {
939 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n", 924 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n",
@@ -947,13 +932,13 @@ static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
947 } 932 }
948 933
949 if (byTsr1 & TSR1_TERR) { 934 if (byTsr1 & TSR1_TERR) {
950 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) { 935 if ((pTD->td_info->flags & TD_FLAGS_PRIV_SKB) != 0) {
951 pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n", 936 pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n",
952 (int)uIdx, byTsr1, byTsr0); 937 (int)uIdx, byTsr1, byTsr0);
953 } 938 }
954 } 939 }
955 940
956 vnt_int_report_rate(pDevice, pTD->pTDInfo, byTsr0, byTsr1); 941 vnt_int_report_rate(pDevice, pTD->td_info, byTsr0, byTsr1);
957 942
958 device_free_tx_buf(pDevice, pTD); 943 device_free_tx_buf(pDevice, pTD);
959 pDevice->iTDUsed[uIdx]--; 944 pDevice->iTDUsed[uIdx]--;
@@ -975,23 +960,17 @@ static void device_error(struct vnt_private *pDevice, unsigned short status)
975 } 960 }
976} 961}
977 962
978static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc) 963static void device_free_tx_buf(struct vnt_private *pDevice,
964 struct vnt_tx_desc *pDesc)
979{ 965{
980 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo; 966 struct vnt_td_info *pTDInfo = pDesc->td_info;
981 struct sk_buff *skb = pTDInfo->skb; 967 struct sk_buff *skb = pTDInfo->skb;
982 968
983 /* pre-allocated buf_dma can't be unmapped. */
984 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
985 dma_unmap_single(&pDevice->pcid->dev, pTDInfo->skb_dma,
986 skb->len, DMA_TO_DEVICE);
987 }
988
989 if (skb) 969 if (skb)
990 ieee80211_tx_status_irqsafe(pDevice->hw, skb); 970 ieee80211_tx_status_irqsafe(pDevice->hw, skb);
991 971
992 pTDInfo->skb_dma = 0;
993 pTDInfo->skb = NULL; 972 pTDInfo->skb = NULL;
994 pTDInfo->byFlags = 0; 973 pTDInfo->flags = 0;
995} 974}
996 975
997static void vnt_check_bb_vga(struct vnt_private *priv) 976static void vnt_check_bb_vga(struct vnt_private *priv)
@@ -1180,7 +1159,7 @@ static irqreturn_t vnt_interrupt(int irq, void *arg)
1180static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb) 1159static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
1181{ 1160{
1182 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 1161 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1183 PSTxDesc head_td; 1162 struct vnt_tx_desc *head_td;
1184 u32 dma_idx; 1163 u32 dma_idx;
1185 unsigned long flags; 1164 unsigned long flags;
1186 1165
@@ -1198,12 +1177,12 @@ static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
1198 1177
1199 head_td = priv->apCurrTD[dma_idx]; 1178 head_td = priv->apCurrTD[dma_idx];
1200 1179
1201 head_td->m_td1TD1.byTCR = 0; 1180 head_td->td1.tcr = 0;
1202 1181
1203 head_td->pTDInfo->skb = skb; 1182 head_td->td_info->skb = skb;
1204 1183
1205 if (dma_idx == TYPE_AC0DMA) 1184 if (dma_idx == TYPE_AC0DMA)
1206 head_td->pTDInfo->byFlags = TD_FLAGS_NETIF_SKB; 1185 head_td->td_info->flags = TD_FLAGS_NETIF_SKB;
1207 1186
1208 priv->apCurrTD[dma_idx] = head_td->next; 1187 priv->apCurrTD[dma_idx] = head_td->next;
1209 1188
@@ -1211,26 +1190,22 @@ static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
1211 1190
1212 vnt_generate_fifo_header(priv, dma_idx, head_td, skb); 1191 vnt_generate_fifo_header(priv, dma_idx, head_td, skb);
1213 1192
1214 if (MACbIsRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
1215 MACbPSWakeup(priv->PortOffset);
1216
1217 spin_lock_irqsave(&priv->lock, flags); 1193 spin_lock_irqsave(&priv->lock, flags);
1218 1194
1219 priv->bPWBitOn = false; 1195 priv->bPWBitOn = false;
1220 1196
1221 /* Set TSR1 & ReqCount in TxDescHead */ 1197 /* Set TSR1 & ReqCount in TxDescHead */
1222 head_td->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU); 1198 head_td->td1.tcr |= (TCR_STP | TCR_EDP | EDMSDU);
1223 head_td->m_td1TD1.wReqCount = 1199 head_td->td1.req_count = cpu_to_le16(head_td->td_info->req_count);
1224 cpu_to_le16((u16)head_td->pTDInfo->dwReqCount);
1225 1200
1226 head_td->buff_addr = cpu_to_le32(head_td->pTDInfo->skb_dma); 1201 head_td->buff_addr = cpu_to_le32(head_td->td_info->buf_dma);
1227 1202
1228 /* Poll Transmit the adapter */ 1203 /* Poll Transmit the adapter */
1229 wmb(); 1204 wmb();
1230 head_td->m_td0TD0.f1Owner = OWNED_BY_NIC; 1205 head_td->td0.owner = OWNED_BY_NIC;
1231 wmb(); /* second memory barrier */ 1206 wmb(); /* second memory barrier */
1232 1207
1233 if (head_td->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) 1208 if (head_td->td_info->flags & TD_FLAGS_NETIF_SKB)
1234 MACvTransmitAC0(priv->PortOffset); 1209 MACvTransmitAC0(priv->PortOffset);
1235 else 1210 else
1236 MACvTransmit0(priv->PortOffset); 1211 MACvTransmit0(priv->PortOffset);
@@ -1775,6 +1750,12 @@ vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
1775 return -ENODEV; 1750 return -ENODEV;
1776 } 1751 }
1777 1752
1753 if (dma_set_mask(&pcid->dev, DMA_BIT_MASK(32))) {
1754 dev_err(&pcid->dev, ": Failed to set dma 32 bit mask\n");
1755 device_free_info(priv);
1756 return -ENODEV;
1757 }
1758
1778 INIT_WORK(&priv->interrupt_work, vnt_interrupt_work); 1759 INIT_WORK(&priv->interrupt_work, vnt_interrupt_work);
1779 1760
1780 /* do reset */ 1761 /* do reset */
@@ -1812,6 +1793,7 @@ vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
1812 ieee80211_hw_set(priv->hw, SIGNAL_DBM); 1793 ieee80211_hw_set(priv->hw, SIGNAL_DBM);
1813 ieee80211_hw_set(priv->hw, RX_INCLUDES_FCS); 1794 ieee80211_hw_set(priv->hw, RX_INCLUDES_FCS);
1814 ieee80211_hw_set(priv->hw, REPORTS_TX_ACK_STATUS); 1795 ieee80211_hw_set(priv->hw, REPORTS_TX_ACK_STATUS);
1796 ieee80211_hw_set(priv->hw, SUPPORTS_PS);
1815 1797
1816 priv->hw->max_signal = 100; 1798 priv->hw->max_signal = 100;
1817 1799
diff --git a/drivers/staging/vt6655/dpc.c b/drivers/staging/vt6655/dpc.c
index b25ee962558d..e14eed160a19 100644
--- a/drivers/staging/vt6655/dpc.c
+++ b/drivers/staging/vt6655/dpc.c
@@ -144,7 +144,7 @@ bool vnt_receive_frame(struct vnt_private *priv, PSRxDesc curr_rd)
144 priv->rx_buf_sz, DMA_FROM_DEVICE); 144 priv->rx_buf_sz, DMA_FROM_DEVICE);
145 145
146 frame_size = le16_to_cpu(curr_rd->m_rd1RD1.wReqCount) 146 frame_size = le16_to_cpu(curr_rd->m_rd1RD1.wReqCount)
147 - cpu_to_le16(curr_rd->m_rd0RD0.wResCount); 147 - le16_to_cpu(curr_rd->m_rd0RD0.wResCount);
148 148
149 if ((frame_size > 2364) || (frame_size < 33)) { 149 if ((frame_size > 2364) || (frame_size < 33)) {
150 /* Frame Size error drop this packet.*/ 150 /* Frame Size error drop this packet.*/
diff --git a/drivers/staging/vt6655/mac.c b/drivers/staging/vt6655/mac.c
index aed530f022b8..3dfd333475c0 100644
--- a/drivers/staging/vt6655/mac.c
+++ b/drivers/staging/vt6655/mac.c
@@ -186,7 +186,6 @@ void MACvSetLoopbackMode(void __iomem *dwIoBase, unsigned char byLoopbackMode)
186{ 186{
187 unsigned char byOrgValue; 187 unsigned char byOrgValue;
188 188
189 ASSERT(byLoopbackMode < 3);
190 byLoopbackMode <<= 6; 189 byLoopbackMode <<= 6;
191 /* set TCR */ 190 /* set TCR */
192 VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue); 191 VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue);
@@ -374,7 +373,6 @@ bool MACbSafeRxOff(void __iomem *dwIoBase)
374 break; 373 break;
375 } 374 }
376 if (ww == W_MAX_TIMEOUT) { 375 if (ww == W_MAX_TIMEOUT) {
377 DBG_PORT80(0x10);
378 pr_debug(" DBG_PORT80(0x10)\n"); 376 pr_debug(" DBG_PORT80(0x10)\n");
379 return false; 377 return false;
380 } 378 }
@@ -384,7 +382,6 @@ bool MACbSafeRxOff(void __iomem *dwIoBase)
384 break; 382 break;
385 } 383 }
386 if (ww == W_MAX_TIMEOUT) { 384 if (ww == W_MAX_TIMEOUT) {
387 DBG_PORT80(0x11);
388 pr_debug(" DBG_PORT80(0x11)\n"); 385 pr_debug(" DBG_PORT80(0x11)\n");
389 return false; 386 return false;
390 } 387 }
@@ -398,7 +395,6 @@ bool MACbSafeRxOff(void __iomem *dwIoBase)
398 break; 395 break;
399 } 396 }
400 if (ww == W_MAX_TIMEOUT) { 397 if (ww == W_MAX_TIMEOUT) {
401 DBG_PORT80(0x12);
402 pr_debug(" DBG_PORT80(0x12)\n"); 398 pr_debug(" DBG_PORT80(0x12)\n");
403 return false; 399 return false;
404 } 400 }
@@ -436,7 +432,6 @@ bool MACbSafeTxOff(void __iomem *dwIoBase)
436 break; 432 break;
437 } 433 }
438 if (ww == W_MAX_TIMEOUT) { 434 if (ww == W_MAX_TIMEOUT) {
439 DBG_PORT80(0x20);
440 pr_debug(" DBG_PORT80(0x20)\n"); 435 pr_debug(" DBG_PORT80(0x20)\n");
441 return false; 436 return false;
442 } 437 }
@@ -446,7 +441,6 @@ bool MACbSafeTxOff(void __iomem *dwIoBase)
446 break; 441 break;
447 } 442 }
448 if (ww == W_MAX_TIMEOUT) { 443 if (ww == W_MAX_TIMEOUT) {
449 DBG_PORT80(0x21);
450 pr_debug(" DBG_PORT80(0x21)\n"); 444 pr_debug(" DBG_PORT80(0x21)\n");
451 return false; 445 return false;
452 } 446 }
@@ -461,7 +455,6 @@ bool MACbSafeTxOff(void __iomem *dwIoBase)
461 break; 455 break;
462 } 456 }
463 if (ww == W_MAX_TIMEOUT) { 457 if (ww == W_MAX_TIMEOUT) {
464 DBG_PORT80(0x24);
465 pr_debug(" DBG_PORT80(0x24)\n"); 458 pr_debug(" DBG_PORT80(0x24)\n");
466 return false; 459 return false;
467 } 460 }
@@ -486,13 +479,11 @@ bool MACbSafeStop(void __iomem *dwIoBase)
486 MACvRegBitsOff(dwIoBase, MAC_REG_TCR, TCR_AUTOBCNTX); 479 MACvRegBitsOff(dwIoBase, MAC_REG_TCR, TCR_AUTOBCNTX);
487 480
488 if (!MACbSafeRxOff(dwIoBase)) { 481 if (!MACbSafeRxOff(dwIoBase)) {
489 DBG_PORT80(0xA1);
490 pr_debug(" MACbSafeRxOff == false)\n"); 482 pr_debug(" MACbSafeRxOff == false)\n");
491 MACbSafeSoftwareReset(dwIoBase); 483 MACbSafeSoftwareReset(dwIoBase);
492 return false; 484 return false;
493 } 485 }
494 if (!MACbSafeTxOff(dwIoBase)) { 486 if (!MACbSafeTxOff(dwIoBase)) {
495 DBG_PORT80(0xA2);
496 pr_debug(" MACbSafeTxOff == false)\n"); 487 pr_debug(" MACbSafeTxOff == false)\n");
497 MACbSafeSoftwareReset(dwIoBase); 488 MACbSafeSoftwareReset(dwIoBase);
498 return false; 489 return false;
@@ -590,9 +581,6 @@ void MACvSetCurrRx0DescAddr(void __iomem *dwIoBase, unsigned long dwCurrDescAddr
590 break; 581 break;
591 } 582 }
592 583
593 if (ww == W_MAX_TIMEOUT)
594 DBG_PORT80(0x13);
595
596 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, dwCurrDescAddr); 584 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, dwCurrDescAddr);
597 if (byOrgDMACtl & DMACTL_RUN) 585 if (byOrgDMACtl & DMACTL_RUN)
598 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_RUN); 586 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_RUN);
@@ -627,8 +615,6 @@ void MACvSetCurrRx1DescAddr(void __iomem *dwIoBase, unsigned long dwCurrDescAddr
627 if (!(byData & DMACTL_RUN)) 615 if (!(byData & DMACTL_RUN))
628 break; 616 break;
629 } 617 }
630 if (ww == W_MAX_TIMEOUT)
631 DBG_PORT80(0x14);
632 618
633 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, dwCurrDescAddr); 619 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, dwCurrDescAddr);
634 if (byOrgDMACtl & DMACTL_RUN) 620 if (byOrgDMACtl & DMACTL_RUN)
@@ -666,8 +652,6 @@ void MACvSetCurrTx0DescAddrEx(void __iomem *dwIoBase,
666 if (!(byData & DMACTL_RUN)) 652 if (!(byData & DMACTL_RUN))
667 break; 653 break;
668 } 654 }
669 if (ww == W_MAX_TIMEOUT)
670 DBG_PORT80(0x25);
671 655
672 VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, dwCurrDescAddr); 656 VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, dwCurrDescAddr);
673 if (byOrgDMACtl & DMACTL_RUN) 657 if (byOrgDMACtl & DMACTL_RUN)
@@ -706,7 +690,6 @@ void MACvSetCurrAC0DescAddrEx(void __iomem *dwIoBase,
706 break; 690 break;
707 } 691 }
708 if (ww == W_MAX_TIMEOUT) { 692 if (ww == W_MAX_TIMEOUT) {
709 DBG_PORT80(0x26);
710 pr_debug(" DBG_PORT80(0x26)\n"); 693 pr_debug(" DBG_PORT80(0x26)\n");
711 } 694 }
712 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, dwCurrDescAddr); 695 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, dwCurrDescAddr);
@@ -807,7 +790,6 @@ bool MACbPSWakeup(void __iomem *dwIoBase)
807 break; 790 break;
808 } 791 }
809 if (ww == W_MAX_TIMEOUT) { 792 if (ww == W_MAX_TIMEOUT) {
810 DBG_PORT80(0x36);
811 pr_debug(" DBG_PORT80(0x33)\n"); 793 pr_debug(" DBG_PORT80(0x33)\n");
812 return false; 794 return false;
813 } 795 }
diff --git a/drivers/staging/vt6655/power.c b/drivers/staging/vt6655/power.c
index be3c4e949b6a..06e6b9d871c4 100644
--- a/drivers/staging/vt6655/power.c
+++ b/drivers/staging/vt6655/power.c
@@ -157,10 +157,18 @@ PSbIsNextTBTTWakeUp(
157 struct ieee80211_conf *conf = &hw->conf; 157 struct ieee80211_conf *conf = &hw->conf;
158 bool bWakeUp = false; 158 bool bWakeUp = false;
159 159
160 if (conf->listen_interval == 1) { 160 if (conf->listen_interval > 1) {
161 /* Turn on wake up to listen next beacon */ 161 if (!pDevice->wake_up_count)
162 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN); 162 pDevice->wake_up_count = conf->listen_interval;
163 bWakeUp = true; 163
164 --pDevice->wake_up_count;
165
166 if (pDevice->wake_up_count == 1) {
167 /* Turn on wake up to listen next beacon */
168 MACvRegBitsOn(pDevice->PortOffset,
169 MAC_REG_PSCTL, PSCTL_LNBCN);
170 bWakeUp = true;
171 }
164 } 172 }
165 173
166 return bWakeUp; 174 return bWakeUp;
diff --git a/drivers/staging/vt6655/rf.c b/drivers/staging/vt6655/rf.c
index 7626f635f160..c537321444be 100644
--- a/drivers/staging/vt6655/rf.c
+++ b/drivers/staging/vt6655/rf.c
@@ -39,66 +39,66 @@
39#include "rf.h" 39#include "rf.h"
40#include "baseband.h" 40#include "baseband.h"
41 41
42#define BY_AL2230_REG_LEN 23 //24bit 42#define BY_AL2230_REG_LEN 23 /* 24bit */
43#define CB_AL2230_INIT_SEQ 15 43#define CB_AL2230_INIT_SEQ 15
44#define SWITCH_CHANNEL_DELAY_AL2230 200 //us 44#define SWITCH_CHANNEL_DELAY_AL2230 200 /* us */
45#define AL2230_PWR_IDX_LEN 64 45#define AL2230_PWR_IDX_LEN 64
46 46
47#define BY_AL7230_REG_LEN 23 //24bit 47#define BY_AL7230_REG_LEN 23 /* 24bit */
48#define CB_AL7230_INIT_SEQ 16 48#define CB_AL7230_INIT_SEQ 16
49#define SWITCH_CHANNEL_DELAY_AL7230 200 //us 49#define SWITCH_CHANNEL_DELAY_AL7230 200 /* us */
50#define AL7230_PWR_IDX_LEN 64 50#define AL7230_PWR_IDX_LEN 64
51 51
52static const unsigned long dwAL2230InitTable[CB_AL2230_INIT_SEQ] = { 52static const unsigned long dwAL2230InitTable[CB_AL2230_INIT_SEQ] = {
53 0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // 53 0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
54 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // 54 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
55 0x01A00200+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // 55 0x01A00200+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
56 0x00FFF300+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // 56 0x00FFF300+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
57 0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // 57 0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
58 0x0F4DC500+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // 58 0x0F4DC500+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
59 0x0805B600+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // 59 0x0805B600+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
60 0x0146C700+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // 60 0x0146C700+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
61 0x00068800+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // 61 0x00068800+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
62 0x0403B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // 62 0x0403B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
63 0x00DBBA00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // 63 0x00DBBA00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
64 0x00099B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // 64 0x00099B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
65 0x0BDFFC00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, 65 0x0BDFFC00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
66 0x00000D00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, 66 0x00000D00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
67 0x00580F00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW 67 0x00580F00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW
68}; 68};
69 69
70static const unsigned long dwAL2230ChannelTable0[CB_MAX_CHANNEL] = { 70static const unsigned long dwAL2230ChannelTable0[CB_MAX_CHANNEL] = {
71 0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz 71 0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 1, Tf = 2412MHz */
72 0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz 72 0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 2, Tf = 2417MHz */
73 0x03E79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz 73 0x03E79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 3, Tf = 2422MHz */
74 0x03E79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 4, Tf = 2427MHz 74 0x03E79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 4, Tf = 2427MHz */
75 0x03F7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 5, Tf = 2432MHz 75 0x03F7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 5, Tf = 2432MHz */
76 0x03F7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 6, Tf = 2437MHz 76 0x03F7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 6, Tf = 2437MHz */
77 0x03E7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 2442MHz 77 0x03E7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 7, Tf = 2442MHz */
78 0x03E7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 2447MHz 78 0x03E7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 8, Tf = 2447MHz */
79 0x03F7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 2452MHz 79 0x03F7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 9, Tf = 2452MHz */
80 0x03F7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz 80 0x03F7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 10, Tf = 2457MHz */
81 0x03E7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz 81 0x03E7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 11, Tf = 2462MHz */
82 0x03E7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz 82 0x03E7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 12, Tf = 2467MHz */
83 0x03F7C000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz 83 0x03F7C000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 13, Tf = 2472MHz */
84 0x03E7C000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW // channel = 14, Tf = 2412M 84 0x03E7C000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW /* channel = 14, Tf = 2412M */
85}; 85};
86 86
87static const unsigned long dwAL2230ChannelTable1[CB_MAX_CHANNEL] = { 87static const unsigned long dwAL2230ChannelTable1[CB_MAX_CHANNEL] = {
88 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz 88 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 1, Tf = 2412MHz */
89 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz 89 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 2, Tf = 2417MHz */
90 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz 90 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 3, Tf = 2422MHz */
91 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 4, Tf = 2427MHz 91 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 4, Tf = 2427MHz */
92 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 5, Tf = 2432MHz 92 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 5, Tf = 2432MHz */
93 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 6, Tf = 2437MHz 93 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 6, Tf = 2437MHz */
94 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 2442MHz 94 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 7, Tf = 2442MHz */
95 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 2447MHz 95 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 8, Tf = 2447MHz */
96 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 2452MHz 96 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 9, Tf = 2452MHz */
97 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz 97 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 10, Tf = 2457MHz */
98 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz 98 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 11, Tf = 2462MHz */
99 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz 99 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 12, Tf = 2467MHz */
100 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz 100 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 13, Tf = 2472MHz */
101 0x06666100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW // channel = 14, Tf = 2412M 101 0x06666100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW /* channel = 14, Tf = 2412M */
102}; 102};
103 103
104static unsigned long dwAL2230PowerTable[AL2230_PWR_IDX_LEN] = { 104static unsigned long dwAL2230PowerTable[AL2230_PWR_IDX_LEN] = {
@@ -168,240 +168,240 @@ static unsigned long dwAL2230PowerTable[AL2230_PWR_IDX_LEN] = {
168 0x0407F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW 168 0x0407F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW
169}; 169};
170 170
171// 40MHz reference frequency 171/* 40MHz reference frequency
172// Need to Pull PLLON(PE3) low when writing channel registers through 3-wire. 172 * Need to Pull PLLON(PE3) low when writing channel registers through 3-wire.*/
173static const unsigned long dwAL7230InitTable[CB_AL7230_INIT_SEQ] = { 173static const unsigned long dwAL7230InitTable[CB_AL7230_INIT_SEQ] = {
174 0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel1 // Need modify for 11a 174 0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Channel1 // Need modify for 11a */
175 0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel1 // Need modify for 11a 175 0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Channel1 // Need modify for 11a */
176 0x841FF200+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 451FE2 176 0x841FF200+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Need modify for 11a: 451FE2 */
177 0x3FDFA300+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 5FDFA3 177 0x3FDFA300+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Need modify for 11a: 5FDFA3 */
178 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // 11b/g // Need modify for 11a 178 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* 11b/g // Need modify for 11a */
179 // RoberYu:20050113, Rev0.47 Regsiter Setting Guide 179 /* RoberYu:20050113, Rev0.47 Regsiter Setting Guide */
180 0x802B5500+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 8D1B55 180 0x802B5500+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Need modify for 11a: 8D1B55 */
181 0x56AF3600+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, 181 0x56AF3600+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
182 0xCE020700+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 860207 182 0xCE020700+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Need modify for 11a: 860207 */
183 0x6EBC0800+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, 183 0x6EBC0800+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
184 0x221BB900+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, 184 0x221BB900+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
185 0xE0000A00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: E0600A 185 0xE0000A00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Need modify for 11a: E0600A */
186 0x08031B00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // init 0x080B1B00 => 0x080F1B00 for 3 wire control TxGain(D10) 186 0x08031B00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* init 0x080B1B00 => 0x080F1B00 for 3 wire control TxGain(D10) */
187 // RoberYu:20050113, Rev0.47 Regsiter Setting Guide 187 /* RoberYu:20050113, Rev0.47 Regsiter Setting Guide */
188 0x000A3C00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 00143C 188 0x000A3C00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Need modify for 11a: 00143C */
189 0xFFFFFD00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, 189 0xFFFFFD00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
190 0x00000E00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, 190 0x00000E00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
191 0x1ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW // Need modify for 11a: 12BACF 191 0x1ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW /* Need modify for 11a: 12BACF */
192}; 192};
193 193
194static const unsigned long dwAL7230InitTableAMode[CB_AL7230_INIT_SEQ] = { 194static const unsigned long dwAL7230InitTableAMode[CB_AL7230_INIT_SEQ] = {
195 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel184 // Need modify for 11b/g 195 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Channel184 // Need modify for 11b/g */
196 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel184 // Need modify for 11b/g 196 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Channel184 // Need modify for 11b/g */
197 0x451FE200+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g 197 0x451FE200+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Need modify for 11b/g */
198 0x5FDFA300+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g 198 0x5FDFA300+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Need modify for 11b/g */
199 0x67F78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // 11a // Need modify for 11b/g 199 0x67F78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* 11a // Need modify for 11b/g */
200 0x853F5500+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g, RoberYu:20050113 200 0x853F5500+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Need modify for 11b/g, RoberYu:20050113 */
201 0x56AF3600+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, 201 0x56AF3600+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
202 0xCE020700+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g 202 0xCE020700+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Need modify for 11b/g */
203 0x6EBC0800+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, 203 0x6EBC0800+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
204 0x221BB900+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, 204 0x221BB900+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
205 0xE0600A00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g 205 0xE0600A00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Need modify for 11b/g */
206 0x08031B00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // init 0x080B1B00 => 0x080F1B00 for 3 wire control TxGain(D10) 206 0x08031B00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* init 0x080B1B00 => 0x080F1B00 for 3 wire control TxGain(D10) */
207 0x00147C00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g 207 0x00147C00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* Need modify for 11b/g */
208 0xFFFFFD00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, 208 0xFFFFFD00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
209 0x00000E00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, 209 0x00000E00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
210 0x12BACF00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW // Need modify for 11b/g 210 0x12BACF00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW /* Need modify for 11b/g */
211}; 211};
212 212
213static const unsigned long dwAL7230ChannelTable0[CB_MAX_CHANNEL] = { 213static const unsigned long dwAL7230ChannelTable0[CB_MAX_CHANNEL] = {
214 0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz 214 0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 1, Tf = 2412MHz */
215 0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz 215 0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 2, Tf = 2417MHz */
216 0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz 216 0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 3, Tf = 2422MHz */
217 0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 4, Tf = 2427MHz 217 0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 4, Tf = 2427MHz */
218 0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 5, Tf = 2432MHz 218 0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 5, Tf = 2432MHz */
219 0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 6, Tf = 2437MHz 219 0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 6, Tf = 2437MHz */
220 0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 2442MHz 220 0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 7, Tf = 2442MHz */
221 0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 2447MHz //RobertYu: 20050218, update for APNode 0.49 221 0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 8, Tf = 2447MHz //RobertYu: 20050218, update for APNode 0.49 */
222 0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 2452MHz //RobertYu: 20050218, update for APNode 0.49 222 0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 9, Tf = 2452MHz //RobertYu: 20050218, update for APNode 0.49 */
223 0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz //RobertYu: 20050218, update for APNode 0.49 223 0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 10, Tf = 2457MHz //RobertYu: 20050218, update for APNode 0.49 */
224 0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz //RobertYu: 20050218, update for APNode 0.49 224 0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 11, Tf = 2462MHz //RobertYu: 20050218, update for APNode 0.49 */
225 0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz //RobertYu: 20050218, update for APNode 0.49 225 0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 12, Tf = 2467MHz //RobertYu: 20050218, update for APNode 0.49 */
226 0x0037C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz //RobertYu: 20050218, update for APNode 0.49 226 0x0037C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 13, Tf = 2472MHz //RobertYu: 20050218, update for APNode 0.49 */
227 0x0037C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 14, Tf = 2484MHz 227 0x0037C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 14, Tf = 2484MHz */
228 228
229 // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22) 229 /* 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22) */
230 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 183, Tf = 4915MHz (15) 230 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 183, Tf = 4915MHz (15) */
231 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 184, Tf = 4920MHz (16) 231 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 184, Tf = 4920MHz (16) */
232 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 185, Tf = 4925MHz (17) 232 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 185, Tf = 4925MHz (17) */
233 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 187, Tf = 4935MHz (18) 233 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 187, Tf = 4935MHz (18) */
234 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 188, Tf = 4940MHz (19) 234 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 188, Tf = 4940MHz (19) */
235 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 189, Tf = 4945MHz (20) 235 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 189, Tf = 4945MHz (20) */
236 0x0FF53000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 192, Tf = 4960MHz (21) 236 0x0FF53000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 192, Tf = 4960MHz (21) */
237 0x0FF53000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 196, Tf = 4980MHz (22) 237 0x0FF53000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 196, Tf = 4980MHz (22) */
238 238
239 // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64, 239 /* 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
240 // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56) 240 * 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56) */
241 241
242 0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 5035MHz (23) 242 0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 7, Tf = 5035MHz (23) */
243 0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 5040MHz (24) 243 0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 8, Tf = 5040MHz (24) */
244 0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 5045MHz (25) 244 0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 9, Tf = 5045MHz (25) */
245 0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 5055MHz (26) 245 0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 11, Tf = 5055MHz (26) */
246 0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 5060MHz (27) 246 0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 12, Tf = 5060MHz (27) */
247 0x0FF55000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 16, Tf = 5080MHz (28) 247 0x0FF55000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 16, Tf = 5080MHz (28) */
248 0x0FF56000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 34, Tf = 5170MHz (29) 248 0x0FF56000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 34, Tf = 5170MHz (29) */
249 0x0FF56000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 36, Tf = 5180MHz (30) 249 0x0FF56000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 36, Tf = 5180MHz (30) */
250 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 38, Tf = 5190MHz (31) //RobertYu: 20050218, update for APNode 0.49 250 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 38, Tf = 5190MHz (31) //RobertYu: 20050218, update for APNode 0.49 */
251 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 40, Tf = 5200MHz (32) 251 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 40, Tf = 5200MHz (32) */
252 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 42, Tf = 5210MHz (33) 252 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 42, Tf = 5210MHz (33) */
253 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 44, Tf = 5220MHz (34) 253 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 44, Tf = 5220MHz (34) */
254 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 46, Tf = 5230MHz (35) 254 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 46, Tf = 5230MHz (35) */
255 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 48, Tf = 5240MHz (36) 255 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 48, Tf = 5240MHz (36) */
256 0x0FF58000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 52, Tf = 5260MHz (37) 256 0x0FF58000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 52, Tf = 5260MHz (37) */
257 0x0FF58000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 56, Tf = 5280MHz (38) 257 0x0FF58000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 56, Tf = 5280MHz (38) */
258 0x0FF58000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 60, Tf = 5300MHz (39) 258 0x0FF58000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 60, Tf = 5300MHz (39) */
259 0x0FF59000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 64, Tf = 5320MHz (40) 259 0x0FF59000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 64, Tf = 5320MHz (40) */
260 260
261 0x0FF5C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 100, Tf = 5500MHz (41) 261 0x0FF5C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 100, Tf = 5500MHz (41) */
262 0x0FF5C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 104, Tf = 5520MHz (42) 262 0x0FF5C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 104, Tf = 5520MHz (42) */
263 0x0FF5C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 108, Tf = 5540MHz (43) 263 0x0FF5C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 108, Tf = 5540MHz (43) */
264 0x0FF5D000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 112, Tf = 5560MHz (44) 264 0x0FF5D000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 112, Tf = 5560MHz (44) */
265 0x0FF5D000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 116, Tf = 5580MHz (45) 265 0x0FF5D000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 116, Tf = 5580MHz (45) */
266 0x0FF5D000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 120, Tf = 5600MHz (46) 266 0x0FF5D000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 120, Tf = 5600MHz (46) */
267 0x0FF5E000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 124, Tf = 5620MHz (47) 267 0x0FF5E000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 124, Tf = 5620MHz (47) */
268 0x0FF5E000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 128, Tf = 5640MHz (48) 268 0x0FF5E000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 128, Tf = 5640MHz (48) */
269 0x0FF5E000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 132, Tf = 5660MHz (49) 269 0x0FF5E000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 132, Tf = 5660MHz (49) */
270 0x0FF5F000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 136, Tf = 5680MHz (50) 270 0x0FF5F000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 136, Tf = 5680MHz (50) */
271 0x0FF5F000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 140, Tf = 5700MHz (51) 271 0x0FF5F000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 140, Tf = 5700MHz (51) */
272 0x0FF60000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 149, Tf = 5745MHz (52) 272 0x0FF60000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 149, Tf = 5745MHz (52) */
273 0x0FF60000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 153, Tf = 5765MHz (53) 273 0x0FF60000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 153, Tf = 5765MHz (53) */
274 0x0FF60000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 157, Tf = 5785MHz (54) 274 0x0FF60000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 157, Tf = 5785MHz (54) */
275 0x0FF61000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 161, Tf = 5805MHz (55) 275 0x0FF61000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 161, Tf = 5805MHz (55) */
276 0x0FF61000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW // channel = 165, Tf = 5825MHz (56) 276 0x0FF61000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW /* channel = 165, Tf = 5825MHz (56) */
277}; 277};
278 278
279static const unsigned long dwAL7230ChannelTable1[CB_MAX_CHANNEL] = { 279static const unsigned long dwAL7230ChannelTable1[CB_MAX_CHANNEL] = {
280 0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz 280 0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 1, Tf = 2412MHz */
281 0x1B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz 281 0x1B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 2, Tf = 2417MHz */
282 0x03333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz 282 0x03333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 3, Tf = 2422MHz */
283 0x0B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 4, Tf = 2427MHz 283 0x0B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 4, Tf = 2427MHz */
284 0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 5, Tf = 2432MHz 284 0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 5, Tf = 2432MHz */
285 0x1B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 6, Tf = 2437MHz 285 0x1B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 6, Tf = 2437MHz */
286 0x03333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 2442MHz 286 0x03333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 7, Tf = 2442MHz */
287 0x0B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 2447MHz 287 0x0B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 8, Tf = 2447MHz */
288 0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 2452MHz 288 0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 9, Tf = 2452MHz */
289 0x1B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz 289 0x1B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 10, Tf = 2457MHz */
290 0x03333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz 290 0x03333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 11, Tf = 2462MHz */
291 0x0B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz 291 0x0B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 12, Tf = 2467MHz */
292 0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz 292 0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 13, Tf = 2472MHz */
293 0x06666100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 14, Tf = 2484MHz 293 0x06666100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 14, Tf = 2484MHz */
294 294
295 // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22) 295 /* 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22) */
296 0x1D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 183, Tf = 4915MHz (15) 296 0x1D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 183, Tf = 4915MHz (15) */
297 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 184, Tf = 4920MHz (16) 297 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 184, Tf = 4920MHz (16) */
298 0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 185, Tf = 4925MHz (17) 298 0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 185, Tf = 4925MHz (17) */
299 0x08000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 187, Tf = 4935MHz (18) 299 0x08000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 187, Tf = 4935MHz (18) */
300 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 188, Tf = 4940MHz (19) 300 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 188, Tf = 4940MHz (19) */
301 0x0D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 189, Tf = 4945MHz (20) 301 0x0D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 189, Tf = 4945MHz (20) */
302 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 192, Tf = 4960MHz (21) 302 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 192, Tf = 4960MHz (21) */
303 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 196, Tf = 4980MHz (22) 303 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 196, Tf = 4980MHz (22) */
304 304
305 // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64, 305 /* 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
306 // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56) 306 * 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56) */
307 0x1D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 5035MHz (23) 307 0x1D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 7, Tf = 5035MHz (23) */
308 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 5040MHz (24) 308 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 8, Tf = 5040MHz (24) */
309 0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 5045MHz (25) 309 0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 9, Tf = 5045MHz (25) */
310 0x08000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 5055MHz (26) 310 0x08000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 11, Tf = 5055MHz (26) */
311 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 5060MHz (27) 311 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 12, Tf = 5060MHz (27) */
312 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 16, Tf = 5080MHz (28) 312 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 16, Tf = 5080MHz (28) */
313 0x05555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 34, Tf = 5170MHz (29) 313 0x05555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 34, Tf = 5170MHz (29) */
314 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 36, Tf = 5180MHz (30) 314 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 36, Tf = 5180MHz (30) */
315 0x10000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 38, Tf = 5190MHz (31) 315 0x10000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 38, Tf = 5190MHz (31) */
316 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 40, Tf = 5200MHz (32) 316 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 40, Tf = 5200MHz (32) */
317 0x1AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 42, Tf = 5210MHz (33) 317 0x1AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 42, Tf = 5210MHz (33) */
318 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 44, Tf = 5220MHz (34) 318 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 44, Tf = 5220MHz (34) */
319 0x05555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 46, Tf = 5230MHz (35) 319 0x05555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 46, Tf = 5230MHz (35) */
320 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 48, Tf = 5240MHz (36) 320 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 48, Tf = 5240MHz (36) */
321 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 52, Tf = 5260MHz (37) 321 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 52, Tf = 5260MHz (37) */
322 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 56, Tf = 5280MHz (38) 322 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 56, Tf = 5280MHz (38) */
323 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 60, Tf = 5300MHz (39) 323 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 60, Tf = 5300MHz (39) */
324 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 64, Tf = 5320MHz (40) 324 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 64, Tf = 5320MHz (40) */
325 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 100, Tf = 5500MHz (41) 325 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 100, Tf = 5500MHz (41) */
326 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 104, Tf = 5520MHz (42) 326 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 104, Tf = 5520MHz (42) */
327 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 108, Tf = 5540MHz (43) 327 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 108, Tf = 5540MHz (43) */
328 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 112, Tf = 5560MHz (44) 328 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 112, Tf = 5560MHz (44) */
329 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 116, Tf = 5580MHz (45) 329 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 116, Tf = 5580MHz (45) */
330 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 120, Tf = 5600MHz (46) 330 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 120, Tf = 5600MHz (46) */
331 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 124, Tf = 5620MHz (47) 331 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 124, Tf = 5620MHz (47) */
332 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 128, Tf = 5640MHz (48) 332 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 128, Tf = 5640MHz (48) */
333 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 132, Tf = 5660MHz (49) 333 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 132, Tf = 5660MHz (49) */
334 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 136, Tf = 5680MHz (50) 334 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 136, Tf = 5680MHz (50) */
335 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 140, Tf = 5700MHz (51) 335 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 140, Tf = 5700MHz (51) */
336 0x18000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 149, Tf = 5745MHz (52) 336 0x18000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 149, Tf = 5745MHz (52) */
337 0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 153, Tf = 5765MHz (53) 337 0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 153, Tf = 5765MHz (53) */
338 0x0D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 157, Tf = 5785MHz (54) 338 0x0D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 157, Tf = 5785MHz (54) */
339 0x18000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 161, Tf = 5805MHz (55) 339 0x18000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 161, Tf = 5805MHz (55) */
340 0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW // channel = 165, Tf = 5825MHz (56) 340 0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW /* channel = 165, Tf = 5825MHz (56) */
341}; 341};
342 342
343static const unsigned long dwAL7230ChannelTable2[CB_MAX_CHANNEL] = { 343static const unsigned long dwAL7230ChannelTable2[CB_MAX_CHANNEL] = {
344 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz 344 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 1, Tf = 2412MHz */
345 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz 345 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 2, Tf = 2417MHz */
346 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz 346 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 3, Tf = 2422MHz */
347 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 4, Tf = 2427MHz 347 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 4, Tf = 2427MHz */
348 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 5, Tf = 2432MHz 348 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 5, Tf = 2432MHz */
349 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 6, Tf = 2437MHz 349 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 6, Tf = 2437MHz */
350 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 2442MHz 350 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 7, Tf = 2442MHz */
351 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 2447MHz 351 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 8, Tf = 2447MHz */
352 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 2452MHz 352 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 9, Tf = 2452MHz */
353 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz 353 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 10, Tf = 2457MHz */
354 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz 354 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 11, Tf = 2462MHz */
355 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz 355 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 12, Tf = 2467MHz */
356 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz 356 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 13, Tf = 2472MHz */
357 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 14, Tf = 2484MHz 357 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 14, Tf = 2484MHz */
358 358
359 // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22) 359 /* 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22) */
360 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 183, Tf = 4915MHz (15) 360 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 183, Tf = 4915MHz (15) */
361 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 184, Tf = 4920MHz (16) 361 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 184, Tf = 4920MHz (16) */
362 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 185, Tf = 4925MHz (17) 362 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 185, Tf = 4925MHz (17) */
363 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 187, Tf = 4935MHz (18) 363 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 187, Tf = 4935MHz (18) */
364 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 188, Tf = 4940MHz (19) 364 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 188, Tf = 4940MHz (19) */
365 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 189, Tf = 4945MHz (20) 365 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 189, Tf = 4945MHz (20) */
366 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 192, Tf = 4960MHz (21) 366 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 192, Tf = 4960MHz (21) */
367 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 196, Tf = 4980MHz (22) 367 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 196, Tf = 4980MHz (22) */
368 368
369 // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64, 369 /* 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
370 // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56) 370 * 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56) */
371 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 5035MHz (23) 371 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 7, Tf = 5035MHz (23) */
372 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 5040MHz (24) 372 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 8, Tf = 5040MHz (24) */
373 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 5045MHz (25) 373 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 9, Tf = 5045MHz (25) */
374 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 5055MHz (26) 374 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 11, Tf = 5055MHz (26) */
375 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 5060MHz (27) 375 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 12, Tf = 5060MHz (27) */
376 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 16, Tf = 5080MHz (28) 376 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 16, Tf = 5080MHz (28) */
377 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 34, Tf = 5170MHz (29) 377 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 34, Tf = 5170MHz (29) */
378 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 36, Tf = 5180MHz (30) 378 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 36, Tf = 5180MHz (30) */
379 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 38, Tf = 5190MHz (31) 379 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 38, Tf = 5190MHz (31) */
380 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 40, Tf = 5200MHz (32) 380 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 40, Tf = 5200MHz (32) */
381 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 42, Tf = 5210MHz (33) 381 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 42, Tf = 5210MHz (33) */
382 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 44, Tf = 5220MHz (34) 382 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 44, Tf = 5220MHz (34) */
383 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 46, Tf = 5230MHz (35) 383 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 46, Tf = 5230MHz (35) */
384 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 48, Tf = 5240MHz (36) 384 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 48, Tf = 5240MHz (36) */
385 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 52, Tf = 5260MHz (37) 385 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 52, Tf = 5260MHz (37) */
386 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 56, Tf = 5280MHz (38) 386 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 56, Tf = 5280MHz (38) */
387 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 60, Tf = 5300MHz (39) 387 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 60, Tf = 5300MHz (39) */
388 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 64, Tf = 5320MHz (40) 388 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 64, Tf = 5320MHz (40) */
389 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 100, Tf = 5500MHz (41) 389 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 100, Tf = 5500MHz (41) */
390 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 104, Tf = 5520MHz (42) 390 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 104, Tf = 5520MHz (42) */
391 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 108, Tf = 5540MHz (43) 391 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 108, Tf = 5540MHz (43) */
392 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 112, Tf = 5560MHz (44) 392 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 112, Tf = 5560MHz (44) */
393 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 116, Tf = 5580MHz (45) 393 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 116, Tf = 5580MHz (45) */
394 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 120, Tf = 5600MHz (46) 394 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 120, Tf = 5600MHz (46) */
395 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 124, Tf = 5620MHz (47) 395 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 124, Tf = 5620MHz (47) */
396 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 128, Tf = 5640MHz (48) 396 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 128, Tf = 5640MHz (48) */
397 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 132, Tf = 5660MHz (49) 397 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 132, Tf = 5660MHz (49) */
398 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 136, Tf = 5680MHz (50) 398 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 136, Tf = 5680MHz (50) */
399 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 140, Tf = 5700MHz (51) 399 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 140, Tf = 5700MHz (51) */
400 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 149, Tf = 5745MHz (52) 400 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 149, Tf = 5745MHz (52) */
401 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 153, Tf = 5765MHz (53) 401 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 153, Tf = 5765MHz (53) */
402 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 157, Tf = 5785MHz (54) 402 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 157, Tf = 5785MHz (54) */
403 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 161, Tf = 5805MHz (55) 403 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, /* channel = 161, Tf = 5805MHz (55) */
404 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW // channel = 165, Tf = 5825MHz (56) 404 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW /* channel = 165, Tf = 5825MHz (56) */
405}; 405};
406 406
407/* 407/*
@@ -438,13 +438,13 @@ static bool s_bAL7230Init(struct vnt_private *priv)
438 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3); 438 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
439 439
440 /* Calibration */ 440 /* Calibration */
441 MACvTimer0MicroSDelay(dwIoBase, 150);//150us 441 MACvTimer0MicroSDelay(dwIoBase, 150);/* 150us */
442 /* TXDCOC:active, RCK:disable */ 442 /* TXDCOC:active, RCK:disable */
443 bResult &= IFRFbWriteEmbedded(priv, (0x9ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW)); 443 bResult &= IFRFbWriteEmbedded(priv, (0x9ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW));
444 MACvTimer0MicroSDelay(dwIoBase, 30);//30us 444 MACvTimer0MicroSDelay(dwIoBase, 30);/* 30us */
445 /* TXDCOC:disable, RCK:active */ 445 /* TXDCOC:disable, RCK:active */
446 bResult &= IFRFbWriteEmbedded(priv, (0x3ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW)); 446 bResult &= IFRFbWriteEmbedded(priv, (0x3ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW));
447 MACvTimer0MicroSDelay(dwIoBase, 30);//30us 447 MACvTimer0MicroSDelay(dwIoBase, 30);/* 30us */
448 /* TXDCOC:disable, RCK:disable */ 448 /* TXDCOC:disable, RCK:disable */
449 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTable[CB_AL7230_INIT_SEQ-1]); 449 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTable[CB_AL7230_INIT_SEQ-1]);
450 450
@@ -457,7 +457,7 @@ static bool s_bAL7230Init(struct vnt_private *priv)
457 457
458 /* PE1: TX_ON, PE2: RX_ON, PE3: PLLON */ 458 /* PE1: TX_ON, PE2: RX_ON, PE3: PLLON */
459 /* 3-wire control for power saving mode */ 459 /* 3-wire control for power saving mode */
460 VNSvOutPortB(dwIoBase + MAC_REG_PSPWRSIG, (PSSIG_WPE3 | PSSIG_WPE2)); //1100 0000 460 VNSvOutPortB(dwIoBase + MAC_REG_PSPWRSIG, (PSSIG_WPE3 | PSSIG_WPE2)); /* 1100 0000 */
461 461
462 return bResult; 462 return bResult;
463} 463}
@@ -557,16 +557,16 @@ static bool RFbAL2230Init(struct vnt_private *priv)
557 557
558 for (ii = 0; ii < CB_AL2230_INIT_SEQ; ii++) 558 for (ii = 0; ii < CB_AL2230_INIT_SEQ; ii++)
559 bResult &= IFRFbWriteEmbedded(priv, dwAL2230InitTable[ii]); 559 bResult &= IFRFbWriteEmbedded(priv, dwAL2230InitTable[ii]);
560 MACvTimer0MicroSDelay(dwIoBase, 30); //delay 30 us 560 MACvTimer0MicroSDelay(dwIoBase, 30); /* delay 30 us */
561 561
562 /* PLL On */ 562 /* PLL On */
563 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3); 563 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
564 564
565 MACvTimer0MicroSDelay(dwIoBase, 150);//150us 565 MACvTimer0MicroSDelay(dwIoBase, 150);/* 150us */
566 bResult &= IFRFbWriteEmbedded(priv, (0x00d80f00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW)); 566 bResult &= IFRFbWriteEmbedded(priv, (0x00d80f00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW));
567 MACvTimer0MicroSDelay(dwIoBase, 30);//30us 567 MACvTimer0MicroSDelay(dwIoBase, 30);/* 30us */
568 bResult &= IFRFbWriteEmbedded(priv, (0x00780f00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW)); 568 bResult &= IFRFbWriteEmbedded(priv, (0x00780f00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW));
569 MACvTimer0MicroSDelay(dwIoBase, 30);//30us 569 MACvTimer0MicroSDelay(dwIoBase, 30);/* 30us */
570 bResult &= IFRFbWriteEmbedded(priv, dwAL2230InitTable[CB_AL2230_INIT_SEQ-1]); 570 bResult &= IFRFbWriteEmbedded(priv, dwAL2230InitTable[CB_AL2230_INIT_SEQ-1]);
571 571
572 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE3 | 572 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE3 |
@@ -575,7 +575,7 @@ static bool RFbAL2230Init(struct vnt_private *priv)
575 SOFTPWRCTL_TXPEINV)); 575 SOFTPWRCTL_TXPEINV));
576 576
577 /* 3-wire control for power saving mode */ 577 /* 3-wire control for power saving mode */
578 VNSvOutPortB(dwIoBase + MAC_REG_PSPWRSIG, (PSSIG_WPE3 | PSSIG_WPE2)); //1100 0000 578 VNSvOutPortB(dwIoBase + MAC_REG_PSPWRSIG, (PSSIG_WPE3 | PSSIG_WPE2)); /* 1100 0000 */
579 579
580 return bResult; 580 return bResult;
581} 581}
@@ -661,11 +661,11 @@ bool RFbSelectChannel(struct vnt_private *priv, unsigned char byRFType,
661 case RF_AL2230S: 661 case RF_AL2230S:
662 bResult = RFbAL2230SelectChannel(priv, byChannel); 662 bResult = RFbAL2230SelectChannel(priv, byChannel);
663 break; 663 break;
664 //{{ RobertYu: 20050104 664 /*{{ RobertYu: 20050104 */
665 case RF_AIROHA7230: 665 case RF_AIROHA7230:
666 bResult = s_bAL7230SelectChannel(priv, byChannel); 666 bResult = s_bAL7230SelectChannel(priv, byChannel);
667 break; 667 break;
668 //}} RobertYu 668 /*}} RobertYu */
669 case RF_NOTHING: 669 case RF_NOTHING:
670 bResult = true; 670 bResult = true;
671 break; 671 break;
diff --git a/drivers/staging/vt6655/rf.h b/drivers/staging/vt6655/rf.h
index 2ea21e2b00f2..b5fc3eed06fb 100644
--- a/drivers/staging/vt6655/rf.h
+++ b/drivers/staging/vt6655/rf.h
@@ -33,18 +33,18 @@
33#include "device.h" 33#include "device.h"
34 34
35/*--------------------- Export Definitions -------------------------*/ 35/*--------------------- Export Definitions -------------------------*/
36// 36/*
37// Baseband RF pair definition in eeprom (Bits 6..0) 37 * Baseband RF pair definition in eeprom (Bits 6..0)
38// 38*/
39#define RF_RFMD2959 0x01 39#define RF_RFMD2959 0x01
40#define RF_MAXIMAG 0x02 40#define RF_MAXIMAG 0x02
41#define RF_AIROHA 0x03 41#define RF_AIROHA 0x03
42 42
43#define RF_UW2451 0x05 43#define RF_UW2451 0x05
44#define RF_MAXIMG 0x06 44#define RF_MAXIMG 0x06
45#define RF_MAXIM2829 0x07 // RobertYu: 20041118 45#define RF_MAXIM2829 0x07 /* RobertYu: 20041118 */
46#define RF_UW2452 0x08 // RobertYu: 20041210 46#define RF_UW2452 0x08 /* RobertYu: 20041210 */
47#define RF_AIROHA7230 0x0a // RobertYu: 20050104 47#define RF_AIROHA7230 0x0a /* RobertYu: 20050104 */
48#define RF_UW2453 0x0b 48#define RF_UW2453 0x0b
49 49
50#define RF_VT3226 0x09 50#define RF_VT3226 0x09
@@ -63,9 +63,9 @@
63#define ZONE_MKK 6 63#define ZONE_MKK 6
64#define ZONE_ISRAEL 7 64#define ZONE_ISRAEL 7
65 65
66//[20050104] CB_MAXIM2829_CHANNEL_5G_HIGH, CB_UW2452_CHANNEL_5G_HIGH: 40==>41 66/* [20050104] CB_MAXIM2829_CHANNEL_5G_HIGH, CB_UW2452_CHANNEL_5G_HIGH: 40==>41 */
67#define CB_MAXIM2829_CHANNEL_5G_HIGH 41 //Index41: channel = 100, Tf = 5500MHz, set the (A3:A0=0101) D6=1 67#define CB_MAXIM2829_CHANNEL_5G_HIGH 41 /* Index41: channel = 100, Tf = 5500MHz, set the (A3:A0=0101) D6=1 */
68#define CB_UW2452_CHANNEL_5G_HIGH 41 //[20041210] Index41: channel = 100, Tf = 5500MHz, change VCO2->VCO3 68#define CB_UW2452_CHANNEL_5G_HIGH 41 /* [20041210] Index41: channel = 100, Tf = 5500MHz, change VCO2->VCO3 */
69 69
70/*--------------------- Export Classes ----------------------------*/ 70/*--------------------- Export Classes ----------------------------*/
71 71
@@ -93,8 +93,8 @@ RFvRSSITodBm(
93 long *pldBm 93 long *pldBm
94); 94);
95 95
96//{{ RobertYu: 20050104 96/* {{ RobertYu: 20050104 */
97bool RFbAL7230SelectChannelPostProcess(struct vnt_private *, u16, u16); 97bool RFbAL7230SelectChannelPostProcess(struct vnt_private *, u16, u16);
98//}} RobertYu 98/* }} RobertYu */
99 99
100#endif // __RF_H__ 100#endif /* __RF_H__ */
diff --git a/drivers/staging/vt6655/rxtx.c b/drivers/staging/vt6655/rxtx.c
index 534338c46619..5875d655dd55 100644
--- a/drivers/staging/vt6655/rxtx.c
+++ b/drivers/staging/vt6655/rxtx.c
@@ -130,7 +130,7 @@ s_vGenerateTxParameter(
130static unsigned int 130static unsigned int
131s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType, 131s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
132 unsigned char *pbyTxBufferAddr, 132 unsigned char *pbyTxBufferAddr,
133 unsigned int uDMAIdx, PSTxDesc pHeadTD, 133 unsigned int uDMAIdx, struct vnt_tx_desc *pHeadTD,
134 unsigned int uNodeIndex); 134 unsigned int uNodeIndex);
135 135
136static 136static
@@ -387,7 +387,6 @@ s_uGetDataDuration(
387 break; 387 break;
388 } 388 }
389 389
390 ASSERT(false);
391 return 0; 390 return 0;
392} 391}
393 392
@@ -1028,10 +1027,10 @@ s_vGenerateTxParameter(
1028static unsigned int 1027static unsigned int
1029s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType, 1028s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
1030 unsigned char *pbyTxBufferAddr, 1029 unsigned char *pbyTxBufferAddr,
1031 unsigned int uDMAIdx, PSTxDesc pHeadTD, 1030 unsigned int uDMAIdx, struct vnt_tx_desc *pHeadTD,
1032 unsigned int is_pspoll) 1031 unsigned int is_pspoll)
1033{ 1032{
1034 PDEVICE_TD_INFO td_info = pHeadTD->pTDInfo; 1033 struct vnt_td_info *td_info = pHeadTD->td_info;
1035 struct sk_buff *skb = td_info->skb; 1034 struct sk_buff *skb = td_info->skb;
1036 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1035 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1037 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 1036 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
@@ -1048,7 +1047,7 @@ s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
1048 unsigned int cbReqCount = 0; 1047 unsigned int cbReqCount = 0;
1049 bool bNeedACK = (bool)(fifo_ctl & FIFOCTL_NEEDACK); 1048 bool bNeedACK = (bool)(fifo_ctl & FIFOCTL_NEEDACK);
1050 bool bRTS = (bool)(fifo_ctl & FIFOCTL_RTS); 1049 bool bRTS = (bool)(fifo_ctl & FIFOCTL_RTS);
1051 PSTxDesc ptdCurr; 1050 struct vnt_tx_desc *ptdCurr;
1052 unsigned int cbHeaderLength = 0; 1051 unsigned int cbHeaderLength = 0;
1053 void *pvRrvTime; 1052 void *pvRrvTime;
1054 struct vnt_mic_hdr *pMICHDR; 1053 struct vnt_mic_hdr *pMICHDR;
@@ -1089,7 +1088,7 @@ s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
1089 1088
1090 1089
1091 /* Set RrvTime/RTS/CTS Buffer */ 1090 /* Set RrvTime/RTS/CTS Buffer */
1092 wTxBufSize = sizeof(STxBufHead); 1091 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1093 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {/* 802.11g packet */ 1092 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {/* 802.11g packet */
1094 1093
1095 if (byFBOption == AUTO_FB_NONE) { 1094 if (byFBOption == AUTO_FB_NONE) {
@@ -1193,17 +1192,15 @@ s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
1193 hdr->duration_id = uDuration; 1192 hdr->duration_id = uDuration;
1194 1193
1195 cbReqCount = cbHeaderLength + uPadding + skb->len; 1194 cbReqCount = cbHeaderLength + uPadding + skb->len;
1196 pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf; 1195 pbyBuffer = (unsigned char *)pHeadTD->td_info->buf;
1197 uLength = cbHeaderLength + uPadding; 1196 uLength = cbHeaderLength + uPadding;
1198 1197
1199 /* Copy the Packet into a tx Buffer */ 1198 /* Copy the Packet into a tx Buffer */
1200 memcpy((pbyBuffer + uLength), skb->data, skb->len); 1199 memcpy((pbyBuffer + uLength), skb->data, skb->len);
1201 1200
1202 ptdCurr = (PSTxDesc)pHeadTD; 1201 ptdCurr = pHeadTD;
1203 1202
1204 ptdCurr->pTDInfo->dwReqCount = cbReqCount; 1203 ptdCurr->td_info->req_count = (u16)cbReqCount;
1205 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1206 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1207 1204
1208 return cbHeaderLength; 1205 return cbHeaderLength;
1209} 1206}
@@ -1276,9 +1273,9 @@ static void vnt_fill_txkey(struct ieee80211_hdr *hdr, u8 *key_buffer,
1276} 1273}
1277 1274
1278int vnt_generate_fifo_header(struct vnt_private *priv, u32 dma_idx, 1275int vnt_generate_fifo_header(struct vnt_private *priv, u32 dma_idx,
1279 PSTxDesc head_td, struct sk_buff *skb) 1276 struct vnt_tx_desc *head_td, struct sk_buff *skb)
1280{ 1277{
1281 PDEVICE_TD_INFO td_info = head_td->pTDInfo; 1278 struct vnt_td_info *td_info = head_td->td_info;
1282 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1279 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1283 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0]; 1280 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
1284 struct ieee80211_rate *rate; 1281 struct ieee80211_rate *rate;
diff --git a/drivers/staging/vt6655/rxtx.h b/drivers/staging/vt6655/rxtx.h
index b9bd1639b13e..1e30ecb5c63c 100644
--- a/drivers/staging/vt6655/rxtx.h
+++ b/drivers/staging/vt6655/rxtx.h
@@ -192,9 +192,9 @@ struct vnt_tx_short_buf_head {
192} __packed; 192} __packed;
193 193
194int vnt_generate_fifo_header(struct vnt_private *, u32, 194int vnt_generate_fifo_header(struct vnt_private *, u32,
195 PSTxDesc head_td, struct sk_buff *); 195 struct vnt_tx_desc *head_td, struct sk_buff *);
196int vnt_beacon_make(struct vnt_private *, struct ieee80211_vif *); 196int vnt_beacon_make(struct vnt_private *, struct ieee80211_vif *);
197int vnt_beacon_enable(struct vnt_private *, struct ieee80211_vif *, 197int vnt_beacon_enable(struct vnt_private *, struct ieee80211_vif *,
198 struct ieee80211_bss_conf *); 198 struct ieee80211_bss_conf *);
199 199
200#endif // __RXTX_H__ 200#endif /* __RXTX_H__ */
diff --git a/drivers/staging/vt6655/upc.h b/drivers/staging/vt6655/upc.h
index cc63dc8d47f7..85fe0464cfb3 100644
--- a/drivers/staging/vt6655/upc.h
+++ b/drivers/staging/vt6655/upc.h
@@ -37,35 +37,23 @@
37/* For memory mapped IO */ 37/* For memory mapped IO */
38 38
39 39
40#define VNSvInPortB(dwIOAddress, pbyData) \ 40#define VNSvInPortB(dwIOAddress, pbyData) \
41do { \ 41 (*(pbyData) = ioread8(dwIOAddress))
42 *(pbyData) = ioread8(dwIOAddress); \
43} while (0)
44 42
45#define VNSvInPortW(dwIOAddress, pwData) \ 43#define VNSvInPortW(dwIOAddress, pwData) \
46do { \ 44 (*(pwData) = ioread16(dwIOAddress))
47 *(pwData) = ioread16(dwIOAddress); \
48} while (0)
49 45
50#define VNSvInPortD(dwIOAddress, pdwData) \ 46#define VNSvInPortD(dwIOAddress, pdwData) \
51do { \ 47 (*(pdwData) = ioread32(dwIOAddress))
52 *(pdwData) = ioread32(dwIOAddress); \
53} while (0)
54 48
55#define VNSvOutPortB(dwIOAddress, byData) \ 49#define VNSvOutPortB(dwIOAddress, byData) \
56do { \ 50 iowrite8((u8)(byData), dwIOAddress)
57 iowrite8((u8)byData, dwIOAddress); \
58} while (0)
59 51
60#define VNSvOutPortW(dwIOAddress, wData) \ 52#define VNSvOutPortW(dwIOAddress, wData) \
61do { \ 53 iowrite16((u16)(wData), dwIOAddress)
62 iowrite16((u16)wData, dwIOAddress); \
63} while (0)
64 54
65#define VNSvOutPortD(dwIOAddress, dwData) \ 55#define VNSvOutPortD(dwIOAddress, dwData) \
66do { \ 56 iowrite32((u32)(dwData), dwIOAddress)
67 iowrite32((u32)dwData, dwIOAddress); \
68} while (0)
69 57
70#define PCAvDelayByIO(uDelayUnit) \ 58#define PCAvDelayByIO(uDelayUnit) \
71do { \ 59do { \
diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c
index 8116791f4f06..da075f485298 100644
--- a/drivers/staging/vt6656/rxtx.c
+++ b/drivers/staging/vt6656/rxtx.c
@@ -45,8 +45,11 @@
45#include "usbpipe.h" 45#include "usbpipe.h"
46 46
47static const u16 vnt_time_stampoff[2][MAX_RATE] = { 47static const u16 vnt_time_stampoff[2][MAX_RATE] = {
48 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23},/* Long Preamble */ 48 /* Long Preamble */
49 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23},/* Short Preamble */ 49 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23},
50
51 /* Short Preamble */
52 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23},
50}; 53};
51 54
52static const u16 vnt_fb_opt0[2][5] = { 55static const u16 vnt_fb_opt0[2][5] = {
diff --git a/drivers/staging/wilc1000/Kconfig b/drivers/staging/wilc1000/Kconfig
index 062d9c5ca4bd..51bbf468fe45 100644
--- a/drivers/staging/wilc1000/Kconfig
+++ b/drivers/staging/wilc1000/Kconfig
@@ -37,17 +37,26 @@ choice
37 bool "SDIO support" 37 bool "SDIO support"
38 depends on MMC 38 depends on MMC
39 ---help--- 39 ---help---
40 This module adds support for the SDIO interface 40 This module adds support for the SDIO interface of adapters using
41 of adapters using WILC chipset. Select this if 41 WILC1000 chipset. The Atmel WILC1000 SDIO is a full speed interface.
42 your platform is using the SDIO bus. 42 It meets SDIO card specification version 2.0. The interface supports
43 the 1-bit/4-bit SD transfer mode at the clock range of 0-50 MHz.
44 The host can use this interface to read and write from any register
45 within the chip as well as configure the WILC1000 for data DMA.
46 To use this interface, pin9 (SDIO_SPI_CFG) must be grounded. Select
47 this if your platform is using the SDIO bus.
43 48
44 config WILC1000_SPI 49 config WILC1000_SPI
45 depends on SPI 50 depends on SPI
46 bool "SPI support" 51 bool "SPI support"
47 ---help--- 52 ---help---
48 This module adds support for the SPI interface 53 This module adds support for the SPI interface of adapters using
49 of adapters using WILC chipset. Select this if 54 WILC1000 chipset. The Atmel WILC1000 has a Serial Peripheral
50 your platform is using the SPI bus. 55 Interface (SPI) that operates as a SPI slave. This SPI interface can
56 be used for control and for serial I/O of 802.11 data. The SPI is a
57 full-duplex slave synchronous serial interface that is available
58 immediately following reset when pin 9 (SDIO_SPI_CFG) is tied to
59 VDDIO. Select this if your platform is using the SPI bus.
51endchoice 60endchoice
52 61
53config WILC1000_HW_OOB_INTR 62config WILC1000_HW_OOB_INTR
@@ -55,5 +64,8 @@ config WILC1000_HW_OOB_INTR
55 depends on WILC1000 && WILC1000_SDIO 64 depends on WILC1000 && WILC1000_SDIO
56 default n 65 default n
57 ---help--- 66 ---help---
58 If your platform don't recognize SDIO IRQ, connect chipset external IRQ pin 67 This option enables out-of-band interrupt support for the WILC1000
59 and check this option. Or, Use this to get all interrupts including SDIO interrupts. 68 chipset. This OOB interrupt is intended to provide a faster interrupt
69 mechanism for SDIO host controllers that don't support SDIO interrupt.
70 Select this option If the SDIO host controller in your platform
71 doesn't support SDIO time devision interrupt.
diff --git a/drivers/staging/wilc1000/Makefile b/drivers/staging/wilc1000/Makefile
index a78c4d529a58..6be8a920706a 100644
--- a/drivers/staging/wilc1000/Makefile
+++ b/drivers/staging/wilc1000/Makefile
@@ -25,10 +25,10 @@ ccflags-$(CONFIG_WILC1000_PREALLOCATE_AT_LOADING_DRIVER) += -DMEMORY_STATIC \
25ccflags-$(CONFIG_WILC1000_DYNAMICALLY_ALLOCATE_MEMROY) += -DWILC_NORMAL_ALLOC 25ccflags-$(CONFIG_WILC1000_DYNAMICALLY_ALLOCATE_MEMROY) += -DWILC_NORMAL_ALLOC
26 26
27 27
28wilc1000-objs := wilc_wfi_netdevice.o wilc_wfi_cfgoperations.o linux_wlan.o linux_mon.o \ 28wilc1000-objs := wilc_wfi_cfgoperations.o linux_wlan.o linux_mon.o \
29 wilc_memory.o wilc_msgqueue.o wilc_sleep.o wilc_strutils.o \ 29 wilc_memory.o wilc_msgqueue.o \
30 wilc_timer.o coreconfigurator.o host_interface.o \ 30 coreconfigurator.o host_interface.o \
31 fifo_buffer.o wilc_sdio.o wilc_spi.o wilc_wlan_cfg.o wilc_debugfs.o 31 wilc_sdio.o wilc_spi.o wilc_wlan_cfg.o wilc_debugfs.o
32 32
33wilc1000-$(CONFIG_WILC1000_SDIO) += linux_wlan_sdio.o 33wilc1000-$(CONFIG_WILC1000_SDIO) += linux_wlan_sdio.o
34wilc1000-$(CONFIG_WILC1000_SPI) += linux_wlan_spi.o 34wilc1000-$(CONFIG_WILC1000_SPI) += linux_wlan_spi.o
diff --git a/drivers/staging/wilc1000/coreconfigsimulator.h b/drivers/staging/wilc1000/coreconfigsimulator.h
deleted file mode 100644
index 5e01f8e4a41d..000000000000
--- a/drivers/staging/wilc1000/coreconfigsimulator.h
+++ /dev/null
@@ -1,17 +0,0 @@
1
2/*!
3 * @file coreconfigsimulator.h
4 * @brief
5 * @author
6 * @sa coreconfigsimulator.c
7 * @date 1 Mar 2012
8 * @version 1.0
9 */
10
11#ifndef CORECONFIGSIMULATOR_H
12#define CORECONFIGSIMULATOR_H
13
14extern s32 CoreConfigSimulatorInit(void);
15extern s32 CoreConfigSimulatorDeInit(void);
16
17#endif
diff --git a/drivers/staging/wilc1000/coreconfigurator.c b/drivers/staging/wilc1000/coreconfigurator.c
index ed6ac45c0385..16a0abc970c0 100644
--- a/drivers/staging/wilc1000/coreconfigurator.c
+++ b/drivers/staging/wilc1000/coreconfigurator.c
@@ -167,7 +167,6 @@ extern void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length);
167static struct semaphore SemHandleSendPkt; 167static struct semaphore SemHandleSendPkt;
168static struct semaphore SemHandlePktResp; 168static struct semaphore SemHandlePktResp;
169 169
170static s8 *gps8ConfigPacket;
171 170
172static tstrConfigPktInfo gstrConfigPktInfo; 171static tstrConfigPktInfo gstrConfigPktInfo;
173 172
@@ -544,21 +543,21 @@ INLINE u8 get_from_ds(u8 *header)
544/* header and updates the MAC Address in the allocated 'addr' variable. */ 543/* header and updates the MAC Address in the allocated 'addr' variable. */
545INLINE void get_address1(u8 *pu8msa, u8 *addr) 544INLINE void get_address1(u8 *pu8msa, u8 *addr)
546{ 545{
547 WILC_memcpy(addr, pu8msa + 4, 6); 546 memcpy(addr, pu8msa + 4, 6);
548} 547}
549 548
550/* This function extracts the MAC Address in 'address2' field of the MAC */ 549/* This function extracts the MAC Address in 'address2' field of the MAC */
551/* header and updates the MAC Address in the allocated 'addr' variable. */ 550/* header and updates the MAC Address in the allocated 'addr' variable. */
552INLINE void get_address2(u8 *pu8msa, u8 *addr) 551INLINE void get_address2(u8 *pu8msa, u8 *addr)
553{ 552{
554 WILC_memcpy(addr, pu8msa + 10, 6); 553 memcpy(addr, pu8msa + 10, 6);
555} 554}
556 555
557/* This function extracts the MAC Address in 'address3' field of the MAC */ 556/* This function extracts the MAC Address in 'address3' field of the MAC */
558/* header and updates the MAC Address in the allocated 'addr' variable. */ 557/* header and updates the MAC Address in the allocated 'addr' variable. */
559INLINE void get_address3(u8 *pu8msa, u8 *addr) 558INLINE void get_address3(u8 *pu8msa, u8 *addr)
560{ 559{
561 WILC_memcpy(addr, pu8msa + 16, 6); 560 memcpy(addr, pu8msa + 16, 6);
562} 561}
563 562
564/* This function extracts the BSSID from the incoming WLAN packet based on */ 563/* This function extracts the BSSID from the incoming WLAN packet based on */
@@ -605,7 +604,7 @@ INLINE u16 get_cap_info(u8 *data)
605{ 604{
606 u16 cap_info = 0; 605 u16 cap_info = 0;
607 u16 index = MAC_HDR_LEN; 606 u16 index = MAC_HDR_LEN;
608 tenuFrmSubtype st = BEACON; 607 tenuFrmSubtype st;
609 608
610 st = get_sub_type(data); 609 st = get_sub_type(data);
611 610
@@ -674,17 +673,8 @@ s32 CoreConfiguratorInit(void)
674 sema_init(&SemHandleSendPkt, 1); 673 sema_init(&SemHandleSendPkt, 1);
675 sema_init(&SemHandlePktResp, 0); 674 sema_init(&SemHandlePktResp, 0);
676 675
677 gps8ConfigPacket = (s8 *)WILC_MALLOC(MAX_PACKET_BUFF_SIZE);
678 if (gps8ConfigPacket == NULL) {
679 PRINT_ER("failed in gps8ConfigPacket allocation\n");
680 s32Error = WILC_NO_MEM;
681 goto _fail_;
682 }
683
684 WILC_memset((void *)gps8ConfigPacket, 0, MAX_PACKET_BUFF_SIZE);
685 676
686 WILC_memset((void *)(&gstrConfigPktInfo), 0, sizeof(tstrConfigPktInfo)); 677 memset((void *)(&gstrConfigPktInfo), 0, sizeof(tstrConfigPktInfo));
687_fail_:
688 return s32Error; 678 return s32Error;
689} 679}
690 680
@@ -706,11 +696,10 @@ u8 *get_tim_elm(u8 *pu8msa, u16 u16RxLen, u16 u16TagParamOffset)
706 696
707 /* Search for the TIM Element Field and return if the element is found */ 697 /* Search for the TIM Element Field and return if the element is found */
708 while (u16index < (u16RxLen - FCS_LEN)) { 698 while (u16index < (u16RxLen - FCS_LEN)) {
709 if (pu8msa[u16index] == ITIM) { 699 if (pu8msa[u16index] == ITIM)
710 return &pu8msa[u16index]; 700 return &pu8msa[u16index];
711 } else { 701 else
712 u16index += (IE_HDR_LEN + pu8msa[u16index + 1]); 702 u16index += (IE_HDR_LEN + pu8msa[u16index + 1]);
713 }
714 } 703 }
715 704
716 return 0; 705 return 0;
@@ -811,8 +800,11 @@ s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
811 u32 u32Tsf_Lo; 800 u32 u32Tsf_Lo;
812 u32 u32Tsf_Hi; 801 u32 u32Tsf_Hi;
813 802
814 pstrNetworkInfo = (tstrNetworkInfo *)WILC_MALLOC(sizeof(tstrNetworkInfo)); 803 pstrNetworkInfo = kmalloc(sizeof(tstrNetworkInfo), GFP_KERNEL);
815 WILC_memset((void *)(pstrNetworkInfo), 0, sizeof(tstrNetworkInfo)); 804 if (!pstrNetworkInfo)
805 return -ENOMEM;
806
807 memset((void *)(pstrNetworkInfo), 0, sizeof(tstrNetworkInfo));
816 808
817 pstrNetworkInfo->s8rssi = pu8WidVal[0]; 809 pstrNetworkInfo->s8rssi = pu8WidVal[0];
818 810
@@ -855,17 +847,19 @@ s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
855 847
856 /* Get DTIM Period */ 848 /* Get DTIM Period */
857 pu8TimElm = get_tim_elm(pu8msa, (u16RxLen + FCS_LEN), u8index); 849 pu8TimElm = get_tim_elm(pu8msa, (u16RxLen + FCS_LEN), u8index);
858 if (pu8TimElm != 0) { 850 if (pu8TimElm != 0)
859 pstrNetworkInfo->u8DtimPeriod = pu8TimElm[3]; 851 pstrNetworkInfo->u8DtimPeriod = pu8TimElm[3];
860 }
861 pu8IEs = &pu8msa[MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN]; 852 pu8IEs = &pu8msa[MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN];
862 u16IEsLen = u16RxLen - (MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN); 853 u16IEsLen = u16RxLen - (MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN);
863 854
864 if (u16IEsLen > 0) { 855 if (u16IEsLen > 0) {
865 pstrNetworkInfo->pu8IEs = (u8 *)WILC_MALLOC(u16IEsLen); 856 pstrNetworkInfo->pu8IEs = kmalloc(u16IEsLen, GFP_KERNEL);
866 WILC_memset((void *)(pstrNetworkInfo->pu8IEs), 0, u16IEsLen); 857 if (!pstrNetworkInfo->pu8IEs)
858 return -ENOMEM;
867 859
868 WILC_memcpy(pstrNetworkInfo->pu8IEs, pu8IEs, u16IEsLen); 860 memset((void *)(pstrNetworkInfo->pu8IEs), 0, u16IEsLen);
861
862 memcpy(pstrNetworkInfo->pu8IEs, pu8IEs, u16IEsLen);
869 } 863 }
870 pstrNetworkInfo->u16IEsLen = u16IEsLen; 864 pstrNetworkInfo->u16IEsLen = u16IEsLen;
871 865
@@ -893,13 +887,13 @@ s32 DeallocateNetworkInfo(tstrNetworkInfo *pstrNetworkInfo)
893 887
894 if (pstrNetworkInfo != NULL) { 888 if (pstrNetworkInfo != NULL) {
895 if (pstrNetworkInfo->pu8IEs != NULL) { 889 if (pstrNetworkInfo->pu8IEs != NULL) {
896 WILC_FREE(pstrNetworkInfo->pu8IEs); 890 kfree(pstrNetworkInfo->pu8IEs);
897 pstrNetworkInfo->pu8IEs = NULL; 891 pstrNetworkInfo->pu8IEs = NULL;
898 } else { 892 } else {
899 s32Error = WILC_FAIL; 893 s32Error = WILC_FAIL;
900 } 894 }
901 895
902 WILC_FREE(pstrNetworkInfo); 896 kfree(pstrNetworkInfo);
903 pstrNetworkInfo = NULL; 897 pstrNetworkInfo = NULL;
904 898
905 } else { 899 } else {
@@ -929,8 +923,11 @@ s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
929 u8 *pu8IEs = 0; 923 u8 *pu8IEs = 0;
930 u16 u16IEsLen = 0; 924 u16 u16IEsLen = 0;
931 925
932 pstrConnectRespInfo = (tstrConnectRespInfo *)WILC_MALLOC(sizeof(tstrConnectRespInfo)); 926 pstrConnectRespInfo = kmalloc(sizeof(tstrConnectRespInfo), GFP_KERNEL);
933 WILC_memset((void *)(pstrConnectRespInfo), 0, sizeof(tstrConnectRespInfo)); 927 if (!pstrConnectRespInfo)
928 return -ENOMEM;
929
930 memset((void *)(pstrConnectRespInfo), 0, sizeof(tstrConnectRespInfo));
934 931
935 /* u16AssocRespLen = pu8Buffer[0]; */ 932 /* u16AssocRespLen = pu8Buffer[0]; */
936 u16AssocRespLen = (u16)u32BufferLen; 933 u16AssocRespLen = (u16)u32BufferLen;
@@ -949,10 +946,13 @@ s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
949 pu8IEs = &pu8Buffer[CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN]; 946 pu8IEs = &pu8Buffer[CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN];
950 u16IEsLen = u16AssocRespLen - (CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN); 947 u16IEsLen = u16AssocRespLen - (CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN);
951 948
952 pstrConnectRespInfo->pu8RespIEs = (u8 *)WILC_MALLOC(u16IEsLen); 949 pstrConnectRespInfo->pu8RespIEs = kmalloc(u16IEsLen, GFP_KERNEL);
953 WILC_memset((void *)(pstrConnectRespInfo->pu8RespIEs), 0, u16IEsLen); 950 if (!pstrConnectRespInfo->pu8RespIEs)
951 return -ENOMEM;
954 952
955 WILC_memcpy(pstrConnectRespInfo->pu8RespIEs, pu8IEs, u16IEsLen); 953 memset((void *)(pstrConnectRespInfo->pu8RespIEs), 0, u16IEsLen);
954
955 memcpy(pstrConnectRespInfo->pu8RespIEs, pu8IEs, u16IEsLen);
956 pstrConnectRespInfo->u16RespIEsLen = u16IEsLen; 956 pstrConnectRespInfo->u16RespIEsLen = u16IEsLen;
957 } 957 }
958 958
@@ -978,13 +978,13 @@ s32 DeallocateAssocRespInfo(tstrConnectRespInfo *pstrConnectRespInfo)
978 978
979 if (pstrConnectRespInfo != NULL) { 979 if (pstrConnectRespInfo != NULL) {
980 if (pstrConnectRespInfo->pu8RespIEs != NULL) { 980 if (pstrConnectRespInfo->pu8RespIEs != NULL) {
981 WILC_FREE(pstrConnectRespInfo->pu8RespIEs); 981 kfree(pstrConnectRespInfo->pu8RespIEs);
982 pstrConnectRespInfo->pu8RespIEs = NULL; 982 pstrConnectRespInfo->pu8RespIEs = NULL;
983 } else { 983 } else {
984 s32Error = WILC_FAIL; 984 s32Error = WILC_FAIL;
985 } 985 }
986 986
987 WILC_FREE(pstrConnectRespInfo); 987 kfree(pstrConnectRespInfo);
988 pstrConnectRespInfo = NULL; 988 pstrConnectRespInfo = NULL;
989 989
990 } else { 990 } else {
@@ -1018,13 +1018,12 @@ s32 ParseSurveyResults(u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZ
1018 } 1018 }
1019 } 1019 }
1020 1020
1021 pstrSurveyResults = (wid_site_survey_reslts_s *)WILC_MALLOC(u32SurveyResultsCount * sizeof(wid_site_survey_reslts_s)); 1021 pstrSurveyResults = kmalloc_array(u32SurveyResultsCount,
1022 if (pstrSurveyResults == NULL) { 1022 sizeof(wid_site_survey_reslts_s), GFP_KERNEL);
1023 u32SurveyResultsCount = 0; 1023 if (!pstrSurveyResults)
1024 WILC_ERRORREPORT(s32Error, WILC_NO_MEM); 1024 return -ENOMEM;
1025 }
1026 1025
1027 WILC_memset((void *)(pstrSurveyResults), 0, u32SurveyResultsCount * sizeof(wid_site_survey_reslts_s)); 1026 memset((void *)(pstrSurveyResults), 0, u32SurveyResultsCount * sizeof(wid_site_survey_reslts_s));
1028 1027
1029 u32SurveyResultsCount = 0; 1028 u32SurveyResultsCount = 0;
1030 1029
@@ -1039,7 +1038,7 @@ s32 ParseSurveyResults(u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZ
1039 pu8BufferPtr += 2; 1038 pu8BufferPtr += 2;
1040 1039
1041 for (j = 0; j < u32SurveyBytesLength; j += SURVEY_RESULT_LENGTH) { 1040 for (j = 0; j < u32SurveyBytesLength; j += SURVEY_RESULT_LENGTH) {
1042 WILC_memcpy(&pstrSurveyResults[u32SurveyResultsCount], pu8BufferPtr, SURVEY_RESULT_LENGTH); 1041 memcpy(&pstrSurveyResults[u32SurveyResultsCount], pu8BufferPtr, SURVEY_RESULT_LENGTH);
1043 pu8BufferPtr += SURVEY_RESULT_LENGTH; 1042 pu8BufferPtr += SURVEY_RESULT_LENGTH;
1044 u32SurveyResultsCount++; 1043 u32SurveyResultsCount++;
1045 } 1044 }
@@ -1058,7 +1057,7 @@ s32 DeallocateSurveyResults(wid_site_survey_reslts_s *pstrSurveyResults)
1058 s32 s32Error = WILC_SUCCESS; 1057 s32 s32Error = WILC_SUCCESS;
1059 1058
1060 if (pstrSurveyResults != NULL) { 1059 if (pstrSurveyResults != NULL) {
1061 WILC_FREE(pstrSurveyResults); 1060 kfree(pstrSurveyResults);
1062 } 1061 }
1063 1062
1064 return s32Error; 1063 return s32Error;
@@ -1334,7 +1333,6 @@ void ProcessStrWid(char *pcPacket, s32 *ps32PktLen,
1334 1333
1335 if (g_oper_mode == SET_CFG) { 1334 if (g_oper_mode == SET_CFG) {
1336 /* Message Length */ 1335 /* Message Length */
1337 /* u16MsgLen = WILC_strlen(pu8val); */
1338 u16MsgLen = (u16)s32ValueSize; 1336 u16MsgLen = (u16)s32ValueSize;
1339 1337
1340 /* Length */ 1338 /* Length */
@@ -1441,8 +1439,6 @@ void ProcessAdrWid(char *pcPacket, s32 *ps32PktLen,
1441void ProcessBinWid(char *pcPacket, s32 *ps32PktLen, 1439void ProcessBinWid(char *pcPacket, s32 *ps32PktLen,
1442 tstrWID *pstrWID, u8 *pu8val, s32 s32ValueSize) 1440 tstrWID *pstrWID, u8 *pu8val, s32 s32ValueSize)
1443{ 1441{
1444 /* WILC_ERROR("processing Binary WIDs is not supported\n"); */
1445
1446 u16 u16MsgLen = 0; 1442 u16 u16MsgLen = 0;
1447 u16 idx = 0; 1443 u16 idx = 0;
1448 s32 s32PktLen = *ps32PktLen; 1444 s32 s32PktLen = *ps32PktLen;
@@ -1528,11 +1524,10 @@ s32 further_process_response(u8 *resp,
1528 u8 cfg_str[256] = {0}; 1524 u8 cfg_str[256] = {0};
1529 tenuWIDtype enuWIDtype = WID_UNDEF; 1525 tenuWIDtype enuWIDtype = WID_UNDEF;
1530 1526
1531 if (process_wid_num) { 1527 if (process_wid_num)
1532 enuWIDtype = get_wid_type(g_wid_num); 1528 enuWIDtype = get_wid_type(g_wid_num);
1533 } else { 1529 else
1534 enuWIDtype = gastrWIDs[cnt].enuWIDtype; 1530 enuWIDtype = gastrWIDs[cnt].enuWIDtype;
1535 }
1536 1531
1537 1532
1538 switch (enuWIDtype) { 1533 switch (enuWIDtype) {
@@ -1566,18 +1561,10 @@ s32 further_process_response(u8 *resp,
1566 } 1561 }
1567 1562
1568 case WID_STR: 1563 case WID_STR:
1569 WILC_memcpy(cfg_str, resp + idx, cfg_len); 1564 memcpy(cfg_str, resp + idx, cfg_len);
1570 /* cfg_str[cfg_len] = '\0'; //mostafa: no need currently for NULL termination */ 1565 /* cfg_str[cfg_len] = '\0'; //mostafa: no need currently for NULL termination */
1571 if (process_wid_num) {
1572 /*fprintf(out_file,"0x%4.4x = %s\n",g_wid_num,
1573 * cfg_str);*/
1574 } else {
1575 /*fprintf(out_file,"%s = %s\n",gastrWIDs[cnt].cfg_switch,
1576 * cfg_str);*/
1577 }
1578
1579 if (pstrWIDresult->s32ValueSize >= cfg_len) { 1566 if (pstrWIDresult->s32ValueSize >= cfg_len) {
1580 WILC_memcpy(pstrWIDresult->ps8WidVal, cfg_str, cfg_len); /* mostafa: no need currently for the extra NULL byte */ 1567 memcpy(pstrWIDresult->ps8WidVal, cfg_str, cfg_len); /* mostafa: no need currently for the extra NULL byte */
1581 pstrWIDresult->s32ValueSize = cfg_len; 1568 pstrWIDresult->s32ValueSize = cfg_len;
1582 } else { 1569 } else {
1583 PRINT_ER("allocated WID buffer length is smaller than the received WID Length\n"); 1570 PRINT_ER("allocated WID buffer length is smaller than the received WID Length\n");
@@ -1589,15 +1576,8 @@ s32 further_process_response(u8 *resp,
1589 case WID_ADR: 1576 case WID_ADR:
1590 create_mac_addr(cfg_str, resp + idx); 1577 create_mac_addr(cfg_str, resp + idx);
1591 1578
1592 WILC_strncpy(pstrWIDresult->ps8WidVal, cfg_str, WILC_strlen(cfg_str)); 1579 strncpy(pstrWIDresult->ps8WidVal, cfg_str, strlen(cfg_str));
1593 pstrWIDresult->ps8WidVal[WILC_strlen(cfg_str)] = '\0'; 1580 pstrWIDresult->ps8WidVal[strlen(cfg_str)] = '\0';
1594 if (process_wid_num) {
1595 /*fprintf(out_file,"0x%4.4x = %s\n",g_wid_num,
1596 * cfg_str);*/
1597 } else {
1598 /*fprintf(out_file,"%s = %s\n",gastrWIDs[cnt].cfg_switch,
1599 * cfg_str);*/
1600 }
1601 break; 1581 break;
1602 1582
1603 case WID_IP: 1583 case WID_IP:
@@ -1606,18 +1586,11 @@ s32 further_process_response(u8 *resp,
1606 MAKE_WORD16(resp[idx + 2], resp[idx + 3]) 1586 MAKE_WORD16(resp[idx + 2], resp[idx + 3])
1607 ); 1587 );
1608 conv_int_to_ip(cfg_str, cfg_int); 1588 conv_int_to_ip(cfg_str, cfg_int);
1609 if (process_wid_num) {
1610 /*fprintf(out_file,"0x%4.4x = %s\n",g_wid_num,
1611 * cfg_str);*/
1612 } else {
1613 /*fprintf(out_file,"%s = %s\n",gastrWIDs[cnt].cfg_switch,
1614 * cfg_str);*/
1615 }
1616 break; 1589 break;
1617 1590
1618 case WID_BIN_DATA: 1591 case WID_BIN_DATA:
1619 if (pstrWIDresult->s32ValueSize >= cfg_len) { 1592 if (pstrWIDresult->s32ValueSize >= cfg_len) {
1620 WILC_memcpy(pstrWIDresult->ps8WidVal, resp + idx, cfg_len); 1593 memcpy(pstrWIDresult->ps8WidVal, resp + idx, cfg_len);
1621 pstrWIDresult->s32ValueSize = cfg_len; 1594 pstrWIDresult->s32ValueSize = cfg_len;
1622 } else { 1595 } else {
1623 PRINT_ER("Allocated WID buffer length is smaller than the received WID Length Err(%d)\n", retval); 1596 PRINT_ER("Allocated WID buffer length is smaller than the received WID Length Err(%d)\n", retval);
@@ -1739,7 +1712,6 @@ s32 ParseResponse(u8 *resp, tstrWID *pstrWIDcfgResult)
1739s32 ParseWriteResponse(u8 *pu8RespBuffer) 1712s32 ParseWriteResponse(u8 *pu8RespBuffer)
1740{ 1713{
1741 s32 s32Error = WILC_FAIL; 1714 s32 s32Error = WILC_FAIL;
1742 u16 u16RespLen = 0;
1743 u16 u16WIDtype = (u16)WID_NIL; 1715 u16 u16WIDtype = (u16)WID_NIL;
1744 1716
1745 /* Check whether the received frame is a valid response */ 1717 /* Check whether the received frame is a valid response */
@@ -1748,9 +1720,6 @@ s32 ParseWriteResponse(u8 *pu8RespBuffer)
1748 return WILC_FAIL; 1720 return WILC_FAIL;
1749 } 1721 }
1750 1722
1751 /* Extract Response Length */
1752 u16RespLen = MAKE_WORD16(pu8RespBuffer[2], pu8RespBuffer[3]);
1753
1754 u16WIDtype = MAKE_WORD16(pu8RespBuffer[4], pu8RespBuffer[5]); 1723 u16WIDtype = MAKE_WORD16(pu8RespBuffer[4], pu8RespBuffer[5]);
1755 1724
1756 /* Check for WID_STATUS ID and then check the length and status value */ 1725 /* Check for WID_STATUS ID and then check the length and status value */
@@ -1898,104 +1867,21 @@ s32 ConfigWaitResponse(char *pcRespBuffer, s32 s32MaxRespBuffLen, s32 *ps32Bytes
1898 *ps32BytesRead = gstrConfigPktInfo.s32BytesRead; 1867 *ps32BytesRead = gstrConfigPktInfo.s32BytesRead;
1899 } 1868 }
1900 1869
1901 WILC_memset((void *)(&gstrConfigPktInfo), 0, sizeof(tstrConfigPktInfo)); 1870 memset((void *)(&gstrConfigPktInfo), 0, sizeof(tstrConfigPktInfo));
1902 1871
1903 return s32Error; 1872 return s32Error;
1904} 1873}
1905 1874
1906/**
1907 * @brief sends certain Configuration Packet based on the input WIDs pstrWIDs
1908 * and retrieves the packet response pu8RxResp
1909 * @details
1910 * @param[in] pstrWIDs WIDs to be sent in the configuration packet
1911 * @param[in] u32WIDsCount number of WIDs to be sent in the configuration packet
1912 * @param[out] pu8RxResp The received Packet Response
1913 * @param[out] ps32RxRespLen Length of the received Packet Response
1914 * @return Error code indicating success/failure
1915 * @note
1916 * @author mabubakr
1917 * @date 1 Mar 2012
1918 * @version 1.0
1919 */
1920#ifdef SIMULATION
1921s32 SendConfigPkt(u8 u8Mode, tstrWID *pstrWIDs,
1922 u32 u32WIDsCount, bool bRespRequired, u32 drvHandler)
1923{
1924 s32 s32Error = WILC_SUCCESS;
1925 s32 err = WILC_SUCCESS;
1926 s32 s32ConfigPacketLen = 0;
1927 s32 s32RcvdRespLen = 0;
1928
1929 down(&SemHandleSendPkt);
1930
1931 /*set the packet mode*/
1932 g_oper_mode = u8Mode;
1933
1934 WILC_memset((void *)gps8ConfigPacket, 0, MAX_PACKET_BUFF_SIZE);
1935
1936 if (CreateConfigPacket(gps8ConfigPacket, &s32ConfigPacketLen, pstrWIDs, u32WIDsCount) != WILC_SUCCESS) {
1937 s32Error = WILC_FAIL;
1938 goto End_ConfigPkt;
1939 }
1940 /*bug 3878*/
1941 gstrConfigPktInfo.pcRespBuffer = gps8ConfigPacket;
1942 gstrConfigPktInfo.s32MaxRespBuffLen = MAX_PACKET_BUFF_SIZE;
1943 PRINT_INFO(CORECONFIG_DBG, "GLOBAL =bRespRequired =%d\n", bRespRequired);
1944 gstrConfigPktInfo.bRespRequired = bRespRequired;
1945
1946 s32Error = SendRawPacket(gps8ConfigPacket, s32ConfigPacketLen);
1947 if (s32Error != WILC_SUCCESS) {
1948 goto End_ConfigPkt;
1949 }
1950
1951 WILC_memset((void *)gps8ConfigPacket, 0, MAX_PACKET_BUFF_SIZE);
1952
1953 ConfigWaitResponse(gps8ConfigPacket, MAX_PACKET_BUFF_SIZE, &s32RcvdRespLen, bRespRequired);
1954
1955
1956 if (bRespRequired) {
1957 /* If the operating Mode is GET, then we expect a response frame from */
1958 /* the driver. Hence start listening to the port for response */
1959 if (g_oper_mode == GET_CFG) {
1960 #if 1
1961 err = ParseResponse(gps8ConfigPacket, pstrWIDs);
1962 if (err != 0) {
1963 s32Error = WILC_FAIL;
1964 goto End_ConfigPkt;
1965 } else {
1966 s32Error = WILC_SUCCESS;
1967 }
1968 #endif
1969 } else {
1970 err = ParseWriteResponse(gps8ConfigPacket);
1971 if (err != WRITE_RESP_SUCCESS) {
1972 s32Error = WILC_FAIL;
1973 goto End_ConfigPkt;
1974 } else {
1975 s32Error = WILC_SUCCESS;
1976 }
1977 }
1978
1979
1980 }
1981
1982
1983End_ConfigPkt:
1984 up(&SemHandleSendPkt);
1985
1986 return s32Error;
1987}
1988#endif
1989s32 ConfigProvideResponse(char *pcRespBuffer, s32 s32RespLen) 1875s32 ConfigProvideResponse(char *pcRespBuffer, s32 s32RespLen)
1990{ 1876{
1991 s32 s32Error = WILC_SUCCESS; 1877 s32 s32Error = WILC_SUCCESS;
1992 1878
1993 if (gstrConfigPktInfo.bRespRequired) { 1879 if (gstrConfigPktInfo.bRespRequired) {
1994 if (s32RespLen <= gstrConfigPktInfo.s32MaxRespBuffLen) { 1880 if (s32RespLen <= gstrConfigPktInfo.s32MaxRespBuffLen) {
1995 WILC_memcpy(gstrConfigPktInfo.pcRespBuffer, pcRespBuffer, s32RespLen); 1881 memcpy(gstrConfigPktInfo.pcRespBuffer, pcRespBuffer, s32RespLen);
1996 gstrConfigPktInfo.s32BytesRead = s32RespLen; 1882 gstrConfigPktInfo.s32BytesRead = s32RespLen;
1997 } else { 1883 } else {
1998 WILC_memcpy(gstrConfigPktInfo.pcRespBuffer, pcRespBuffer, gstrConfigPktInfo.s32MaxRespBuffLen); 1884 memcpy(gstrConfigPktInfo.pcRespBuffer, pcRespBuffer, gstrConfigPktInfo.s32MaxRespBuffLen);
1999 gstrConfigPktInfo.s32BytesRead = gstrConfigPktInfo.s32MaxRespBuffLen; 1885 gstrConfigPktInfo.s32BytesRead = gstrConfigPktInfo.s32MaxRespBuffLen;
2000 PRINT_ER("BusProvideResponse() Response greater than the prepared Buffer Size\n"); 1886 PRINT_ER("BusProvideResponse() Response greater than the prepared Buffer Size\n");
2001 } 1887 }
@@ -2069,17 +1955,10 @@ s32 CoreConfiguratorDeInit(void)
2069 1955
2070 PRINT_D(CORECONFIG_DBG, "CoreConfiguratorDeInit()\n"); 1956 PRINT_D(CORECONFIG_DBG, "CoreConfiguratorDeInit()\n");
2071 1957
2072 if (gps8ConfigPacket != NULL) {
2073
2074 WILC_FREE(gps8ConfigPacket);
2075 gps8ConfigPacket = NULL;
2076 }
2077 1958
2078 return s32Error; 1959 return s32Error;
2079} 1960}
2080 1961
2081
2082#ifndef SIMULATION
2083/*Using the global handle of the driver*/ 1962/*Using the global handle of the driver*/
2084extern wilc_wlan_oup_t *gpstrWlanOps; 1963extern wilc_wlan_oup_t *gpstrWlanOps;
2085/** 1964/**
@@ -2129,7 +2008,6 @@ s32 SendConfigPkt(u8 u8Mode, tstrWID *pstrWIDs,
2129 /** 2008 /**
2130 * get the value 2009 * get the value
2131 **/ 2010 **/
2132 /* WILC_Sleep(1000); */
2133 counter = 0; 2011 counter = 0;
2134 for (counter = 0; counter < u32WIDsCount; counter++) { 2012 for (counter = 0; counter < u32WIDsCount; counter++) {
2135 pstrWIDs[counter].s32ValueSize = gpstrWlanOps->wlan_cfg_get_value( 2013 pstrWIDs[counter].s32ValueSize = gpstrWlanOps->wlan_cfg_get_value(
@@ -2153,4 +2031,3 @@ s32 SendConfigPkt(u8 u8Mode, tstrWID *pstrWIDs,
2153 2031
2154 return ret; 2032 return ret;
2155} 2033}
2156#endif
diff --git a/drivers/staging/wilc1000/coreconfigurator.h b/drivers/staging/wilc1000/coreconfigurator.h
index 9059c8df7ce5..3af193543cdb 100644
--- a/drivers/staging/wilc1000/coreconfigurator.h
+++ b/drivers/staging/wilc1000/coreconfigurator.h
@@ -8,7 +8,6 @@
8 * @version 1.0 8 * @version 1.0
9 */ 9 */
10 10
11
12#ifndef CORECONFIGURATOR_H 11#ifndef CORECONFIGURATOR_H
13#define CORECONFIGURATOR_H 12#define CORECONFIGURATOR_H
14 13
@@ -42,7 +41,6 @@ extern u16 g_num_total_switches;
42#define AID_LEN 2 41#define AID_LEN 2
43#define IE_HDR_LEN 2 42#define IE_HDR_LEN 2
44 43
45
46/* Operating Mode: SET */ 44/* Operating Mode: SET */
47#define SET_CFG 0 45#define SET_CFG 0
48/* Operating Mode: GET */ 46/* Operating Mode: GET */
@@ -59,15 +57,12 @@ extern u16 g_num_total_switches;
59#define MAC_CONNECTED 1 57#define MAC_CONNECTED 1
60#define MAC_DISCONNECTED 0 58#define MAC_DISCONNECTED 0
61 59
62
63
64/*****************************************************************************/ 60/*****************************************************************************/
65/* Function Macros */ 61/* Function Macros */
66/*****************************************************************************/ 62/*****************************************************************************/
67#define MAKE_WORD16(lsb, msb) ((((u16)(msb) << 8) & 0xFF00) | (lsb)) 63#define MAKE_WORD16(lsb, msb) ((((u16)(msb) << 8) & 0xFF00) | (lsb))
68#define MAKE_WORD32(lsw, msw) ((((u32)(msw) << 16) & 0xFFFF0000) | (lsw)) 64#define MAKE_WORD32(lsw, msw) ((((u32)(msw) << 16) & 0xFFFF0000) | (lsw))
69 65
70
71/*****************************************************************************/ 66/*****************************************************************************/
72/* Type Definitions */ 67/* Type Definitions */
73/*****************************************************************************/ 68/*****************************************************************************/
@@ -140,7 +135,6 @@ typedef struct {
140 u16 u16RespIEsLen; 135 u16 u16RespIEsLen;
141} tstrConnectRespInfo; 136} tstrConnectRespInfo;
142 137
143
144typedef struct { 138typedef struct {
145 u8 au8bssid[6]; 139 u8 au8bssid[6];
146 u8 *pu8ReqIEs; 140 u8 *pu8ReqIEs;
@@ -150,8 +144,6 @@ typedef struct {
150 u16 u16ConnectStatus; 144 u16 u16ConnectStatus;
151} tstrConnectInfo; 145} tstrConnectInfo;
152 146
153
154
155typedef struct { 147typedef struct {
156 u16 u16reason; 148 u16 u16reason;
157 u8 *ie; 149 u8 *ie;
@@ -171,26 +163,27 @@ typedef struct wid_site_survey_reslts {
171} wid_site_survey_reslts_s; 163} wid_site_survey_reslts_s;
172#endif 164#endif
173 165
174extern s32 CoreConfiguratorInit(void); 166s32 CoreConfiguratorInit(void);
175extern s32 CoreConfiguratorDeInit(void); 167s32 CoreConfiguratorDeInit(void);
176 168
177extern s32 SendConfigPkt(u8 u8Mode, tstrWID *pstrWIDs, 169s32 SendConfigPkt(u8 u8Mode, tstrWID *pstrWIDs,
178 u32 u32WIDsCount, bool bRespRequired, u32 drvHandler); 170 u32 u32WIDsCount, bool bRespRequired, u32 drvHandler);
179extern s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo); 171s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo);
180extern s32 DeallocateNetworkInfo(tstrNetworkInfo *pstrNetworkInfo); 172s32 DeallocateNetworkInfo(tstrNetworkInfo *pstrNetworkInfo);
181 173
182extern s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen, 174s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
183 tstrConnectRespInfo **ppstrConnectRespInfo); 175 tstrConnectRespInfo **ppstrConnectRespInfo);
184extern s32 DeallocateAssocRespInfo(tstrConnectRespInfo *pstrConnectRespInfo); 176s32 DeallocateAssocRespInfo(tstrConnectRespInfo *pstrConnectRespInfo);
185 177
186#ifndef CONNECT_DIRECT 178#ifndef CONNECT_DIRECT
187extern s32 ParseSurveyResults(u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZE], 179s32 ParseSurveyResults(u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZE],
188 wid_site_survey_reslts_s **ppstrSurveyResults, u32 *pu32SurveyResultsCount); 180 wid_site_survey_reslts_s **ppstrSurveyResults,
189extern s32 DeallocateSurveyResults(wid_site_survey_reslts_s *pstrSurveyResults); 181 u32 *pu32SurveyResultsCount);
182s32 DeallocateSurveyResults(wid_site_survey_reslts_s *pstrSurveyResults);
190#endif 183#endif
191 184
192extern s32 SendRawPacket(s8 *pspacket, s32 s32PacketLen); 185s32 SendRawPacket(s8 *pspacket, s32 s32PacketLen);
193extern void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length); 186void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length);
194void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length); 187void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length);
195void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length); 188void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length);
196 189
diff --git a/drivers/staging/wilc1000/fifo_buffer.c b/drivers/staging/wilc1000/fifo_buffer.c
deleted file mode 100644
index b6c07cfc43d2..000000000000
--- a/drivers/staging/wilc1000/fifo_buffer.c
+++ /dev/null
@@ -1,133 +0,0 @@
1
2
3#include "fifo_buffer.h"
4
5
6
7u32 FIFO_InitBuffer(tHANDLE *hBuffer, u32 u32BufferLength)
8{
9 u32 u32Error = 0;
10 tstrFifoHandler *pstrFifoHandler = WILC_MALLOC (sizeof (tstrFifoHandler));
11 if (pstrFifoHandler) {
12 WILC_memset (pstrFifoHandler, 0, sizeof (tstrFifoHandler));
13 pstrFifoHandler->pu8Buffer = WILC_MALLOC (u32BufferLength);
14 if (pstrFifoHandler->pu8Buffer) {
15 pstrFifoHandler->u32BufferLength = u32BufferLength;
16 WILC_memset (pstrFifoHandler->pu8Buffer, 0, u32BufferLength);
17 /* create semaphore */
18 sema_init(&pstrFifoHandler->SemBuffer, 1);
19 *hBuffer = pstrFifoHandler;
20 } else {
21 *hBuffer = NULL;
22 u32Error = 1;
23 }
24 } else {
25 u32Error = 1;
26 }
27 return u32Error;
28}
29u32 FIFO_DeInit(tHANDLE hFifo)
30{
31 u32 u32Error = 0;
32 tstrFifoHandler *pstrFifoHandler = (tstrFifoHandler *) hFifo;
33 if (pstrFifoHandler) {
34 if (pstrFifoHandler->pu8Buffer) {
35 WILC_FREE (pstrFifoHandler->pu8Buffer);
36 } else {
37 u32Error = 1;
38 }
39
40 WILC_FREE (pstrFifoHandler);
41 } else {
42 u32Error = 1;
43 }
44 return u32Error;
45}
46
47u32 FIFO_ReadBytes(tHANDLE hFifo, u8 *pu8Buffer, u32 u32BytesToRead, u32 *pu32BytesRead)
48{
49 u32 u32Error = 0;
50 tstrFifoHandler *pstrFifoHandler = (tstrFifoHandler *) hFifo;
51 if (pstrFifoHandler && pu32BytesRead) {
52 if (pstrFifoHandler->u32TotalBytes) {
53 down(&pstrFifoHandler->SemBuffer);
54
55 if (u32BytesToRead > pstrFifoHandler->u32TotalBytes) {
56 *pu32BytesRead = pstrFifoHandler->u32TotalBytes;
57 } else {
58 *pu32BytesRead = u32BytesToRead;
59 }
60 if ((pstrFifoHandler->u32ReadOffset + u32BytesToRead) <= pstrFifoHandler->u32BufferLength) {
61 WILC_memcpy(pu8Buffer, pstrFifoHandler->pu8Buffer + pstrFifoHandler->u32ReadOffset,
62 *pu32BytesRead);
63 /* update read offset and total bytes */
64 pstrFifoHandler->u32ReadOffset += u32BytesToRead;
65 pstrFifoHandler->u32TotalBytes -= u32BytesToRead;
66
67 } else {
68 u32 u32FirstPart =
69 pstrFifoHandler->u32BufferLength - pstrFifoHandler->u32ReadOffset;
70 WILC_memcpy(pu8Buffer, pstrFifoHandler->pu8Buffer + pstrFifoHandler->u32ReadOffset,
71 u32FirstPart);
72 WILC_memcpy(pu8Buffer + u32FirstPart, pstrFifoHandler->pu8Buffer,
73 u32BytesToRead - u32FirstPart);
74 /* update read offset and total bytes */
75 pstrFifoHandler->u32ReadOffset = u32BytesToRead - u32FirstPart;
76 pstrFifoHandler->u32TotalBytes -= u32BytesToRead;
77 }
78 up(&pstrFifoHandler->SemBuffer);
79 } else {
80 u32Error = 1;
81 }
82 } else {
83 u32Error = 1;
84 }
85 return u32Error;
86}
87
88u32 FIFO_WriteBytes(tHANDLE hFifo, u8 *pu8Buffer, u32 u32BytesToWrite, bool bForceOverWrite)
89{
90 u32 u32Error = 0;
91 tstrFifoHandler *pstrFifoHandler = (tstrFifoHandler *) hFifo;
92 if (pstrFifoHandler) {
93 if (u32BytesToWrite < pstrFifoHandler->u32BufferLength) {
94 if ((pstrFifoHandler->u32TotalBytes + u32BytesToWrite) <= pstrFifoHandler->u32BufferLength ||
95 bForceOverWrite) {
96 down(&pstrFifoHandler->SemBuffer);
97 if ((pstrFifoHandler->u32WriteOffset + u32BytesToWrite) <= pstrFifoHandler->u32BufferLength) {
98 WILC_memcpy(pstrFifoHandler->pu8Buffer + pstrFifoHandler->u32WriteOffset, pu8Buffer,
99 u32BytesToWrite);
100 /* update read offset and total bytes */
101 pstrFifoHandler->u32WriteOffset += u32BytesToWrite;
102 pstrFifoHandler->u32TotalBytes += u32BytesToWrite;
103
104 } else {
105 u32 u32FirstPart =
106 pstrFifoHandler->u32BufferLength - pstrFifoHandler->u32WriteOffset;
107 WILC_memcpy(pstrFifoHandler->pu8Buffer + pstrFifoHandler->u32WriteOffset, pu8Buffer,
108 u32FirstPart);
109 WILC_memcpy(pstrFifoHandler->pu8Buffer, pu8Buffer + u32FirstPart,
110 u32BytesToWrite - u32FirstPart);
111 /* update read offset and total bytes */
112 pstrFifoHandler->u32WriteOffset = u32BytesToWrite - u32FirstPart;
113 pstrFifoHandler->u32TotalBytes += u32BytesToWrite;
114 }
115 /* if data overwriten */
116 if (pstrFifoHandler->u32TotalBytes > pstrFifoHandler->u32BufferLength) {
117 /* adjust read offset to the oldest data available */
118 pstrFifoHandler->u32ReadOffset = pstrFifoHandler->u32WriteOffset;
119 /* data availabe is the buffer length */
120 pstrFifoHandler->u32TotalBytes = pstrFifoHandler->u32BufferLength;
121 }
122 up(&pstrFifoHandler->SemBuffer);
123 } else {
124 u32Error = 1;
125 }
126 } else {
127 u32Error = 1;
128 }
129 } else {
130 u32Error = 1;
131 }
132 return u32Error;
133}
diff --git a/drivers/staging/wilc1000/fifo_buffer.h b/drivers/staging/wilc1000/fifo_buffer.h
deleted file mode 100644
index 7b76998e4238..000000000000
--- a/drivers/staging/wilc1000/fifo_buffer.h
+++ /dev/null
@@ -1,26 +0,0 @@
1
2#include <linux/types.h>
3#include <linux/semaphore.h>
4#include "wilc_memory.h"
5#include "wilc_strutils.h"
6
7
8#define tHANDLE void *
9
10typedef struct {
11 u8 *pu8Buffer;
12 u32 u32BufferLength;
13 u32 u32WriteOffset;
14 u32 u32ReadOffset;
15 u32 u32TotalBytes;
16 struct semaphore SemBuffer;
17} tstrFifoHandler;
18
19
20extern u32 FIFO_InitBuffer(tHANDLE *hBuffer,
21 u32 u32BufferLength);
22extern u32 FIFO_DeInit(tHANDLE hFifo);
23extern u32 FIFO_ReadBytes(tHANDLE hFifo, u8 *pu8Buffer,
24 u32 u32BytesToRead, u32 *pu32BytesRead);
25extern u32 FIFO_WriteBytes(tHANDLE hFifo, u8 *pu8Buffer,
26 u32 u32BytesToWrite, bool bForceOverWrite);
diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 6b10bbbe6ab2..66fa677015db 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -6,10 +6,9 @@ extern s32 TransportDeInit(void);
6extern u8 connecting; 6extern u8 connecting;
7 7
8#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 8#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
9extern WILC_TimerHandle hDuringIpTimer; 9extern struct timer_list hDuringIpTimer;
10#endif 10#endif
11 11
12extern bool bEnablePS;
13/*BugID_5137*/ 12/*BugID_5137*/
14extern u8 g_wilc_initialized; 13extern u8 g_wilc_initialized;
15/*****************************************************************************/ 14/*****************************************************************************/
@@ -467,7 +466,7 @@ typedef union _tuniHostIFmsgBody {
467typedef struct _tstrHostIFmsg { 466typedef struct _tstrHostIFmsg {
468 u16 u16MsgId; /*!< Message ID */ 467 u16 u16MsgId; /*!< Message ID */
469 tuniHostIFmsgBody uniHostIFmsgBody; /*!< Message body */ 468 tuniHostIFmsgBody uniHostIFmsgBody; /*!< Message body */
470 void *drvHandler; 469 tstrWILC_WFIDrv *drvHandler;
471} tstrHostIFmsg; 470} tstrHostIFmsg;
472 471
473#ifdef CONNECT_DIRECT 472#ifdef CONNECT_DIRECT
@@ -534,8 +533,8 @@ typedef enum {
534/*****************************************************************************/ 533/*****************************************************************************/
535 534
536 535
537tstrWILC_WFIDrv *terminated_handle = NULL; 536tstrWILC_WFIDrv *terminated_handle;
538tstrWILC_WFIDrv *gWFiDrvHandle = NULL; 537tstrWILC_WFIDrv *gWFiDrvHandle;
539#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 538#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
540bool g_obtainingIP = false; 539bool g_obtainingIP = false;
541#endif 540#endif
@@ -547,7 +546,7 @@ static struct semaphore hSemHostIFthrdEnd;
547struct semaphore hSemDeinitDrvHandle; 546struct semaphore hSemDeinitDrvHandle;
548static struct semaphore hWaitResponse; 547static struct semaphore hWaitResponse;
549struct semaphore hSemHostIntDeinit; 548struct semaphore hSemHostIntDeinit;
550WILC_TimerHandle g_hPeriodicRSSI; 549struct timer_list g_hPeriodicRSSI;
551 550
552 551
553 552
@@ -570,9 +569,7 @@ static u8 gs8GetIP[2][4];
570static u32 gu32InactiveTime; 569static u32 gu32InactiveTime;
571static u8 gu8DelBcn; 570static u8 gu8DelBcn;
572#endif 571#endif
573#ifndef SIMULATION
574static u32 gu32WidConnRstHack; 572static u32 gu32WidConnRstHack;
575#endif
576 573
577/*BugID_5137*/ 574/*BugID_5137*/
578u8 *gu8FlushedJoinReq; 575u8 *gu8FlushedJoinReq;
@@ -604,7 +601,7 @@ extern int linux_wlan_get_num_conn_ifcs(void);
604 * @date 601 * @date
605 * @version 1.0 602 * @version 1.0
606 */ 603 */
607static s32 Handle_SetChannel(void *drvHandler, tstrHostIFSetChan *pstrHostIFSetChan) 604static s32 Handle_SetChannel(tstrWILC_WFIDrv *drvHandler, tstrHostIFSetChan *pstrHostIFSetChan)
608{ 605{
609 606
610 s32 s32Error = WILC_SUCCESS; 607 s32 s32Error = WILC_SUCCESS;
@@ -659,9 +656,8 @@ static s32 Handle_SetWfiDrvHandler(tstrHostIfSetDrvHandler *pstrHostIfSetDrvHand
659 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); 656 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
660 657
661 658
662 if ((pstrHostIfSetDrvHandler->u32Address) == (u32)NULL) { 659 if ((pstrHostIfSetDrvHandler->u32Address) == (u32)NULL)
663 up(&hSemDeinitDrvHandle); 660 up(&hSemDeinitDrvHandle);
664 }
665 661
666 662
667 if (s32Error) { 663 if (s32Error) {
@@ -685,7 +681,7 @@ static s32 Handle_SetWfiDrvHandler(tstrHostIfSetDrvHandler *pstrHostIfSetDrvHand
685 * @date 681 * @date
686 * @version 1.0 682 * @version 1.0
687 */ 683 */
688static s32 Handle_SetOperationMode(void *drvHandler, tstrHostIfSetOperationMode *pstrHostIfSetOperationMode) 684static s32 Handle_SetOperationMode(tstrWILC_WFIDrv *drvHandler, tstrHostIfSetOperationMode *pstrHostIfSetOperationMode)
689{ 685{
690 686
691 s32 s32Error = WILC_SUCCESS; 687 s32 s32Error = WILC_SUCCESS;
@@ -700,14 +696,13 @@ static s32 Handle_SetOperationMode(void *drvHandler, tstrHostIfSetOperationMode
700 strWID.s32ValueSize = sizeof(u32); 696 strWID.s32ValueSize = sizeof(u32);
701 697
702 /*Sending Cfg*/ 698 /*Sending Cfg*/
703 PRINT_INFO(HOSTINF_DBG, "pstrWFIDrv= %p \n", pstrWFIDrv); 699 PRINT_INFO(HOSTINF_DBG, "pstrWFIDrv= %p\n", pstrWFIDrv);
704 700
705 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); 701 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
706 702
707 703
708 if ((pstrHostIfSetOperationMode->u32Mode) == (u32)NULL) { 704 if ((pstrHostIfSetOperationMode->u32Mode) == (u32)NULL)
709 up(&hSemDeinitDrvHandle); 705 up(&hSemDeinitDrvHandle);
710 }
711 706
712 707
713 if (s32Error) { 708 if (s32Error) {
@@ -731,7 +726,7 @@ static s32 Handle_SetOperationMode(void *drvHandler, tstrHostIfSetOperationMode
731 * @date 726 * @date
732 * @version 1.0 727 * @version 1.0
733 */ 728 */
734s32 Handle_set_IPAddress(void *drvHandler, u8 *pu8IPAddr, u8 idx) 729s32 Handle_set_IPAddress(tstrWILC_WFIDrv *drvHandler, u8 *pu8IPAddr, u8 idx)
735{ 730{
736 731
737 s32 s32Error = WILC_SUCCESS; 732 s32 s32Error = WILC_SUCCESS;
@@ -742,9 +737,9 @@ s32 Handle_set_IPAddress(void *drvHandler, u8 *pu8IPAddr, u8 idx)
742 if (pu8IPAddr[0] < 192) 737 if (pu8IPAddr[0] < 192)
743 pu8IPAddr[0] = 0; 738 pu8IPAddr[0] = 0;
744 739
745 PRINT_INFO(HOSTINF_DBG, "Indx = %d, Handling set IP = %d.%d.%d.%d \n", idx, pu8IPAddr[0], pu8IPAddr[1], pu8IPAddr[2], pu8IPAddr[3]); 740 PRINT_INFO(HOSTINF_DBG, "Indx = %d, Handling set IP = %pI4\n", idx, pu8IPAddr);
746 741
747 WILC_memcpy(gs8SetIP[idx], pu8IPAddr, IP_ALEN); 742 memcpy(gs8SetIP[idx], pu8IPAddr, IP_ALEN);
748 743
749 /*prepare configuration packet*/ 744 /*prepare configuration packet*/
750 strWID.u16WIDid = (u16)WID_IP_ADDRESS; 745 strWID.u16WIDid = (u16)WID_IP_ADDRESS;
@@ -756,7 +751,7 @@ s32 Handle_set_IPAddress(void *drvHandler, u8 *pu8IPAddr, u8 idx)
756 751
757 752
758 753
759 host_int_get_ipaddress((WILC_WFIDrvHandle)drvHandler, firmwareIPAddress, idx); 754 host_int_get_ipaddress(drvHandler, firmwareIPAddress, idx);
760 755
761 if (s32Error) { 756 if (s32Error) {
762 PRINT_D(HOSTINF_DBG, "Failed to set IP address\n"); 757 PRINT_D(HOSTINF_DBG, "Failed to set IP address\n");
@@ -783,7 +778,7 @@ s32 Handle_set_IPAddress(void *drvHandler, u8 *pu8IPAddr, u8 idx)
783 * @date 778 * @date
784 * @version 1.0 779 * @version 1.0
785 */ 780 */
786s32 Handle_get_IPAddress(void *drvHandler, u8 *pu8IPAddr, u8 idx) 781s32 Handle_get_IPAddress(tstrWILC_WFIDrv *drvHandler, u8 *pu8IPAddr, u8 idx)
787{ 782{
788 783
789 s32 s32Error = WILC_SUCCESS; 784 s32 s32Error = WILC_SUCCESS;
@@ -793,27 +788,27 @@ s32 Handle_get_IPAddress(void *drvHandler, u8 *pu8IPAddr, u8 idx)
793 /*prepare configuration packet*/ 788 /*prepare configuration packet*/
794 strWID.u16WIDid = (u16)WID_IP_ADDRESS; 789 strWID.u16WIDid = (u16)WID_IP_ADDRESS;
795 strWID.enuWIDtype = WID_STR; 790 strWID.enuWIDtype = WID_STR;
796 strWID.ps8WidVal = (u8 *)WILC_MALLOC(IP_ALEN); 791 strWID.ps8WidVal = WILC_MALLOC(IP_ALEN);
797 strWID.s32ValueSize = IP_ALEN; 792 strWID.s32ValueSize = IP_ALEN;
798 793
799 s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); 794 s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
800 795
801 PRINT_INFO(HOSTINF_DBG, "%d.%d.%d.%d\n", (u8)(strWID.ps8WidVal[0]), (u8)(strWID.ps8WidVal[1]), (u8)(strWID.ps8WidVal[2]), (u8)(strWID.ps8WidVal[3])); 796 PRINT_INFO(HOSTINF_DBG, "%pI4\n", strWID.ps8WidVal);
802 797
803 WILC_memcpy(gs8GetIP[idx], strWID.ps8WidVal, IP_ALEN); 798 memcpy(gs8GetIP[idx], strWID.ps8WidVal, IP_ALEN);
804 799
805 /*get the value by searching the local copy*/ 800 /*get the value by searching the local copy*/
806 WILC_FREE(strWID.ps8WidVal); 801 kfree(strWID.ps8WidVal);
807 802
808 if (WILC_memcmp(gs8GetIP[idx], gs8SetIP[idx], IP_ALEN) != 0) 803 if (memcmp(gs8GetIP[idx], gs8SetIP[idx], IP_ALEN) != 0)
809 host_int_setup_ipaddress((WILC_WFIDrvHandle)pstrWFIDrv, gs8SetIP[idx], idx); 804 host_int_setup_ipaddress(pstrWFIDrv, gs8SetIP[idx], idx);
810 805
811 if (s32Error != WILC_SUCCESS) { 806 if (s32Error != WILC_SUCCESS) {
812 PRINT_ER("Failed to get IP address\n"); 807 PRINT_ER("Failed to get IP address\n");
813 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE); 808 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
814 } else { 809 } else {
815 PRINT_INFO(HOSTINF_DBG, "IP address retrieved:: u8IfIdx = %d \n", idx); 810 PRINT_INFO(HOSTINF_DBG, "IP address retrieved:: u8IfIdx = %d\n", idx);
816 PRINT_INFO(HOSTINF_DBG, "%d.%d.%d.%d\n", gs8GetIP[idx][0], gs8GetIP[idx][1], gs8GetIP[idx][2], gs8GetIP[idx][3]); 811 PRINT_INFO(HOSTINF_DBG, "%pI4\n", gs8GetIP[idx]);
817 PRINT_INFO(HOSTINF_DBG, "\n"); 812 PRINT_INFO(HOSTINF_DBG, "\n");
818 } 813 }
819 814
@@ -836,18 +831,19 @@ s32 Handle_get_IPAddress(void *drvHandler, u8 *pu8IPAddr, u8 idx)
836 * @date November 2013 831 * @date November 2013
837 * @version 7.0 832 * @version 7.0
838 */ 833 */
839static s32 Handle_SetMacAddress(void *drvHandler, tstrHostIfSetMacAddress *pstrHostIfSetMacAddress) 834static s32 Handle_SetMacAddress(tstrWILC_WFIDrv *drvHandler, tstrHostIfSetMacAddress *pstrHostIfSetMacAddress)
840{ 835{
841 836
842 s32 s32Error = WILC_SUCCESS; 837 s32 s32Error = WILC_SUCCESS;
843 tstrWID strWID; 838 tstrWID strWID;
844 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler; 839 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
845 u8 *mac_buf = (u8 *)WILC_MALLOC(ETH_ALEN); 840 u8 *mac_buf = WILC_MALLOC(ETH_ALEN);
841
846 if (mac_buf == NULL) { 842 if (mac_buf == NULL) {
847 PRINT_ER("No buffer to send mac address\n"); 843 PRINT_ER("No buffer to send mac address\n");
848 return WILC_FAIL; 844 return WILC_FAIL;
849 } 845 }
850 WILC_memcpy(mac_buf, pstrHostIfSetMacAddress->u8MacAddress, ETH_ALEN); 846 memcpy(mac_buf, pstrHostIfSetMacAddress->u8MacAddress, ETH_ALEN);
851 847
852 /*prepare configuration packet*/ 848 /*prepare configuration packet*/
853 strWID.u16WIDid = (u16)WID_MAC_ADDR; 849 strWID.u16WIDid = (u16)WID_MAC_ADDR;
@@ -866,7 +862,7 @@ static s32 Handle_SetMacAddress(void *drvHandler, tstrHostIfSetMacAddress *pstrH
866 { 862 {
867 863
868 } 864 }
869 WILC_FREE(mac_buf); 865 kfree(mac_buf);
870 return s32Error; 866 return s32Error;
871} 867}
872 868
@@ -881,7 +877,7 @@ static s32 Handle_SetMacAddress(void *drvHandler, tstrHostIfSetMacAddress *pstrH
881 * @date JAN 2013 877 * @date JAN 2013
882 * @version 8.0 878 * @version 8.0
883 */ 879 */
884static s32 Handle_GetMacAddress(void *drvHandler, tstrHostIfGetMacAddress *pstrHostIfGetMacAddress) 880static s32 Handle_GetMacAddress(tstrWILC_WFIDrv *drvHandler, tstrHostIfGetMacAddress *pstrHostIfGetMacAddress)
885{ 881{
886 882
887 s32 s32Error = WILC_SUCCESS; 883 s32 s32Error = WILC_SUCCESS;
@@ -918,7 +914,7 @@ static s32 Handle_GetMacAddress(void *drvHandler, tstrHostIfGetMacAddress *pstrH
918 * @date 914 * @date
919 * @version 1.0 915 * @version 1.0
920 */ 916 */
921static s32 Handle_CfgParam(void *drvHandler, tstrHostIFCfgParamAttr *strHostIFCfgParamAttr) 917static s32 Handle_CfgParam(tstrWILC_WFIDrv *drvHandler, tstrHostIFCfgParamAttr *strHostIFCfgParamAttr)
922{ 918{
923 s32 s32Error = WILC_SUCCESS; 919 s32 s32Error = WILC_SUCCESS;
924 tstrWID strWIDList[32]; 920 tstrWID strWIDList[32];
@@ -1204,10 +1200,9 @@ static s32 Handle_CfgParam(void *drvHandler, tstrHostIFCfgParamAttr *strHostIFCf
1204 } 1200 }
1205 s32Error = SendConfigPkt(SET_CFG, strWIDList, u8WidCnt, false, (u32)pstrWFIDrv); 1201 s32Error = SendConfigPkt(SET_CFG, strWIDList, u8WidCnt, false, (u32)pstrWFIDrv);
1206 1202
1207 if (s32Error) { 1203 if (s32Error)
1208 PRINT_ER("Error in setting CFG params\n"); 1204 PRINT_ER("Error in setting CFG params\n");
1209 1205
1210 }
1211 WILC_CATCH(s32Error) 1206 WILC_CATCH(s32Error)
1212 { 1207 {
1213 } 1208 }
@@ -1228,6 +1223,7 @@ static s32 Handle_CfgParam(void *drvHandler, tstrHostIFCfgParamAttr *strHostIFCf
1228static s32 Handle_wait_msg_q_empty(void) 1223static s32 Handle_wait_msg_q_empty(void)
1229{ 1224{
1230 s32 s32Error = WILC_SUCCESS; 1225 s32 s32Error = WILC_SUCCESS;
1226
1231 g_wilc_initialized = 0; 1227 g_wilc_initialized = 0;
1232 up(&hWaitResponse); 1228 up(&hWaitResponse);
1233 return s32Error; 1229 return s32Error;
@@ -1242,7 +1238,7 @@ static s32 Handle_wait_msg_q_empty(void)
1242 * @date 1238 * @date
1243 * @version 1.0 1239 * @version 1.0
1244 */ 1240 */
1245static s32 Handle_Scan(void *drvHandler, tstrHostIFscanAttr *pstrHostIFscanAttr) 1241static s32 Handle_Scan(tstrWILC_WFIDrv *drvHandler, tstrHostIFscanAttr *pstrHostIFscanAttr)
1246{ 1242{
1247 s32 s32Error = WILC_SUCCESS; 1243 s32 s32Error = WILC_SUCCESS;
1248 tstrWID strWIDList[5]; 1244 tstrWID strWIDList[5];
@@ -1254,7 +1250,7 @@ static s32 Handle_Scan(void *drvHandler, tstrHostIFscanAttr *pstrHostIFscanAttr)
1254 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler; 1250 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler;
1255 1251
1256 PRINT_D(HOSTINF_DBG, "Setting SCAN params\n"); 1252 PRINT_D(HOSTINF_DBG, "Setting SCAN params\n");
1257 PRINT_D(HOSTINF_DBG, "Scanning: In [%d] state \n", pstrWFIDrv->enuHostIFstate); 1253 PRINT_D(HOSTINF_DBG, "Scanning: In [%d] state\n", pstrWFIDrv->enuHostIFstate);
1258 1254
1259 pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult = pstrHostIFscanAttr->pfScanResult; 1255 pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult = pstrHostIFscanAttr->pfScanResult;
1260 pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid = pstrHostIFscanAttr->pvUserArg; 1256 pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid = pstrHostIFscanAttr->pvUserArg;
@@ -1284,9 +1280,8 @@ static s32 Handle_Scan(void *drvHandler, tstrHostIFscanAttr *pstrHostIFscanAttr)
1284 strWIDList[u32WidsCount].u16WIDid = (u16)WID_SSID_PROBE_REQ; 1280 strWIDList[u32WidsCount].u16WIDid = (u16)WID_SSID_PROBE_REQ;
1285 strWIDList[u32WidsCount].enuWIDtype = WID_STR; 1281 strWIDList[u32WidsCount].enuWIDtype = WID_STR;
1286 1282
1287 for (i = 0; i < pstrHostIFscanAttr->strHiddenNetwork.u8ssidnum; i++) { 1283 for (i = 0; i < pstrHostIFscanAttr->strHiddenNetwork.u8ssidnum; i++)
1288 valuesize += ((pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen) + 1); 1284 valuesize += ((pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen) + 1);
1289 }
1290 pu8HdnNtwrksWidVal = WILC_MALLOC(valuesize + 1); 1285 pu8HdnNtwrksWidVal = WILC_MALLOC(valuesize + 1);
1291 strWIDList[u32WidsCount].ps8WidVal = pu8HdnNtwrksWidVal; 1286 strWIDList[u32WidsCount].ps8WidVal = pu8HdnNtwrksWidVal;
1292 if (strWIDList[u32WidsCount].ps8WidVal != NULL) { 1287 if (strWIDList[u32WidsCount].ps8WidVal != NULL) {
@@ -1298,7 +1293,7 @@ static s32 Handle_Scan(void *drvHandler, tstrHostIFscanAttr *pstrHostIFscanAttr)
1298 1293
1299 for (i = 0; i < pstrHostIFscanAttr->strHiddenNetwork.u8ssidnum; i++) { 1294 for (i = 0; i < pstrHostIFscanAttr->strHiddenNetwork.u8ssidnum; i++) {
1300 *pu8Buffer++ = pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen; 1295 *pu8Buffer++ = pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen;
1301 WILC_memcpy(pu8Buffer, pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen); 1296 memcpy(pu8Buffer, pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen);
1302 pu8Buffer += pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen; 1297 pu8Buffer += pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen;
1303 } 1298 }
1304 1299
@@ -1336,9 +1331,8 @@ static s32 Handle_Scan(void *drvHandler, tstrHostIFscanAttr *pstrHostIFscanAttr)
1336 int i; 1331 int i;
1337 1332
1338 for (i = 0; i < pstrHostIFscanAttr->u8ChnlListLen; i++) { 1333 for (i = 0; i < pstrHostIFscanAttr->u8ChnlListLen; i++) {
1339 if (pstrHostIFscanAttr->pu8ChnlFreqList[i] > 0) { 1334 if (pstrHostIFscanAttr->pu8ChnlFreqList[i] > 0)
1340 pstrHostIFscanAttr->pu8ChnlFreqList[i] = pstrHostIFscanAttr->pu8ChnlFreqList[i] - 1; 1335 pstrHostIFscanAttr->pu8ChnlFreqList[i] = pstrHostIFscanAttr->pu8ChnlFreqList[i] - 1;
1341 }
1342 } 1336 }
1343 } 1337 }
1344 1338
@@ -1356,11 +1350,10 @@ static s32 Handle_Scan(void *drvHandler, tstrHostIFscanAttr *pstrHostIFscanAttr)
1356 /*keep the state as is , no need to change it*/ 1350 /*keep the state as is , no need to change it*/
1357 /* gWFiDrvHandle->enuHostIFstate = HOST_IF_SCANNING; */ 1351 /* gWFiDrvHandle->enuHostIFstate = HOST_IF_SCANNING; */
1358 1352
1359 if (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTED) { 1353 if (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTED)
1360 gbScanWhileConnected = true; 1354 gbScanWhileConnected = true;
1361 } else if (pstrWFIDrv->enuHostIFstate == HOST_IF_IDLE) { 1355 else if (pstrWFIDrv->enuHostIFstate == HOST_IF_IDLE)
1362 gbScanWhileConnected = false; 1356 gbScanWhileConnected = false;
1363 }
1364 1357
1365 s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, (u32)pstrWFIDrv); 1358 s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, (u32)pstrWFIDrv);
1366 1359
@@ -1373,36 +1366,35 @@ static s32 Handle_Scan(void *drvHandler, tstrHostIFscanAttr *pstrHostIFscanAttr)
1373 1366
1374 WILC_CATCH(s32Error) 1367 WILC_CATCH(s32Error)
1375 { 1368 {
1376 WILC_TimerStop(&(pstrWFIDrv->hScanTimer), NULL); 1369 del_timer(&pstrWFIDrv->hScanTimer);
1377 /*if there is an ongoing scan request*/ 1370 /*if there is an ongoing scan request*/
1378 Handle_ScanDone(drvHandler, SCAN_EVENT_ABORTED); 1371 Handle_ScanDone(drvHandler, SCAN_EVENT_ABORTED);
1379 } 1372 }
1380 1373
1381 /* Deallocate pstrHostIFscanAttr->u8ChnlListLen which was prevoisuly allocated by the sending thread */ 1374 /* Deallocate pstrHostIFscanAttr->u8ChnlListLen which was prevoisuly allocated by the sending thread */
1382 if (pstrHostIFscanAttr->pu8ChnlFreqList != NULL) { 1375 if (pstrHostIFscanAttr->pu8ChnlFreqList != NULL) {
1383 WILC_FREE(pstrHostIFscanAttr->pu8ChnlFreqList); 1376 kfree(pstrHostIFscanAttr->pu8ChnlFreqList);
1384 pstrHostIFscanAttr->pu8ChnlFreqList = NULL; 1377 pstrHostIFscanAttr->pu8ChnlFreqList = NULL;
1385 } 1378 }
1386 1379
1387 /* Deallocate pstrHostIFscanAttr->pu8IEs which was previously allocated by the sending thread */ 1380 /* Deallocate pstrHostIFscanAttr->pu8IEs which was previously allocated by the sending thread */
1388 if (pstrHostIFscanAttr->pu8IEs != NULL) { 1381 if (pstrHostIFscanAttr->pu8IEs != NULL) {
1389 WILC_FREE(pstrHostIFscanAttr->pu8IEs); 1382 kfree(pstrHostIFscanAttr->pu8IEs);
1390 pstrHostIFscanAttr->pu8IEs = NULL; 1383 pstrHostIFscanAttr->pu8IEs = NULL;
1391 } 1384 }
1392 if (pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo != NULL) { 1385 if (pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo != NULL) {
1393 WILC_FREE(pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo); 1386 kfree(pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo);
1394 pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo = NULL; 1387 pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo = NULL;
1395 } 1388 }
1396 1389
1397 /* Deallocate pstrHostIFscanAttr->u8ChnlListLen which was prevoisuly allocated by the sending thread */ 1390 /* Deallocate pstrHostIFscanAttr->u8ChnlListLen which was prevoisuly allocated by the sending thread */
1398 if (pstrHostIFscanAttr->pu8ChnlFreqList != NULL) { 1391 if (pstrHostIFscanAttr->pu8ChnlFreqList != NULL) {
1399 WILC_FREE(pstrHostIFscanAttr->pu8ChnlFreqList); 1392 kfree(pstrHostIFscanAttr->pu8ChnlFreqList);
1400 pstrHostIFscanAttr->pu8ChnlFreqList = NULL; 1393 pstrHostIFscanAttr->pu8ChnlFreqList = NULL;
1401 } 1394 }
1402 1395
1403 if (pu8HdnNtwrksWidVal != NULL) { 1396 if (pu8HdnNtwrksWidVal != NULL)
1404 WILC_FREE(pu8HdnNtwrksWidVal); 1397 kfree(pu8HdnNtwrksWidVal);
1405 }
1406 1398
1407 return s32Error; 1399 return s32Error;
1408} 1400}
@@ -1416,7 +1408,7 @@ static s32 Handle_Scan(void *drvHandler, tstrHostIFscanAttr *pstrHostIFscanAttr)
1416 * @date 1408 * @date
1417 * @version 1.0 1409 * @version 1.0
1418 */ 1410 */
1419static s32 Handle_ScanDone(void *drvHandler, tenuScanEvent enuEvent) 1411static s32 Handle_ScanDone(tstrWILC_WFIDrv *drvHandler, tenuScanEvent enuEvent)
1420{ 1412{
1421 s32 s32Error = WILC_SUCCESS; 1413 s32 s32Error = WILC_SUCCESS;
1422 1414
@@ -1476,7 +1468,7 @@ static s32 Handle_ScanDone(void *drvHandler, tenuScanEvent enuEvent)
1476 * @version 1.0 1468 * @version 1.0
1477 */ 1469 */
1478u8 u8ConnectedSSID[6] = {0}; 1470u8 u8ConnectedSSID[6] = {0};
1479static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFconnectAttr) 1471static s32 Handle_Connect(tstrWILC_WFIDrv *drvHandler, tstrHostIFconnectAttr *pstrHostIFconnectAttr)
1480{ 1472{
1481 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler; 1473 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler;
1482 s32 s32Error = WILC_SUCCESS; 1474 s32 s32Error = WILC_SUCCESS;
@@ -1500,12 +1492,12 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1500 PRINT_D(GENERIC_DBG, "Handling connect request\n"); 1492 PRINT_D(GENERIC_DBG, "Handling connect request\n");
1501 1493
1502 #ifndef CONNECT_DIRECT 1494 #ifndef CONNECT_DIRECT
1503 WILC_memset(gapu8RcvdSurveyResults[0], 0, MAX_SURVEY_RESULT_FRAG_SIZE); 1495 memset(gapu8RcvdSurveyResults[0], 0, MAX_SURVEY_RESULT_FRAG_SIZE);
1504 WILC_memset(gapu8RcvdSurveyResults[1], 0, MAX_SURVEY_RESULT_FRAG_SIZE); 1496 memset(gapu8RcvdSurveyResults[1], 0, MAX_SURVEY_RESULT_FRAG_SIZE);
1505 1497
1506 1498
1507 PRINT_D(HOSTINF_DBG, "Getting site survey results\n"); 1499 PRINT_D(HOSTINF_DBG, "Getting site survey results\n");
1508 s32Err = host_int_get_site_survey_results((WILC_WFIDrvHandle)pstrWFIDrv, 1500 s32Err = host_int_get_site_survey_results(pstrWFIDrv,
1509 gapu8RcvdSurveyResults, 1501 gapu8RcvdSurveyResults,
1510 MAX_SURVEY_RESULT_FRAG_SIZE); 1502 MAX_SURVEY_RESULT_FRAG_SIZE);
1511 if (s32Err) { 1503 if (s32Err) {
@@ -1521,19 +1513,19 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1521 /* use the parsed info in pstrSurveyResults, then deallocate it */ 1513 /* use the parsed info in pstrSurveyResults, then deallocate it */
1522 PRINT_D(HOSTINF_DBG, "Copying site survey results in global structure, then deallocate\n"); 1514 PRINT_D(HOSTINF_DBG, "Copying site survey results in global structure, then deallocate\n");
1523 for (i = 0; i < pstrWFIDrv->u32SurveyResultsCount; i++) { 1515 for (i = 0; i < pstrWFIDrv->u32SurveyResultsCount; i++) {
1524 WILC_memcpy(&pstrWFIDrv->astrSurveyResults[i], &pstrSurveyResults[i], 1516 memcpy(&pstrWFIDrv->astrSurveyResults[i], &pstrSurveyResults[i],
1525 sizeof(wid_site_survey_reslts_s)); 1517 sizeof(wid_site_survey_reslts_s));
1526 } 1518 }
1527 1519
1528 DeallocateSurveyResults(pstrSurveyResults); 1520 DeallocateSurveyResults(pstrSurveyResults);
1529 } else { 1521 } else {
1530 WILC_ERRORREPORT(s32Error, WILC_FAIL); 1522 WILC_ERRORREPORT(s32Error, WILC_FAIL);
1531 PRINT_ER("ParseSurveyResults() Error(%d) \n", s32Err); 1523 PRINT_ER("ParseSurveyResults() Error(%d)\n", s32Err);
1532 } 1524 }
1533 1525
1534 1526
1535 for (i = 0; i < pstrWFIDrv->u32SurveyResultsCount; i++) { 1527 for (i = 0; i < pstrWFIDrv->u32SurveyResultsCount; i++) {
1536 if (WILC_memcmp(pstrWFIDrv->astrSurveyResults[i].SSID, 1528 if (memcmp(pstrWFIDrv->astrSurveyResults[i].SSID,
1537 pstrHostIFconnectAttr->pu8ssid, 1529 pstrHostIFconnectAttr->pu8ssid,
1538 pstrHostIFconnectAttr->ssidLen) == 0) { 1530 pstrHostIFconnectAttr->ssidLen) == 0) {
1539 PRINT_INFO(HOSTINF_DBG, "Network with required SSID is found %s\n", pstrHostIFconnectAttr->pu8ssid); 1531 PRINT_INFO(HOSTINF_DBG, "Network with required SSID is found %s\n", pstrHostIFconnectAttr->pu8ssid);
@@ -1546,7 +1538,7 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1546 /* BSSID is also passed from the user, so decision of matching 1538 /* BSSID is also passed from the user, so decision of matching
1547 * should consider also this passed BSSID */ 1539 * should consider also this passed BSSID */
1548 1540
1549 if (WILC_memcmp(pstrWFIDrv->astrSurveyResults[i].BSSID, 1541 if (memcmp(pstrWFIDrv->astrSurveyResults[i].BSSID,
1550 pstrHostIFconnectAttr->pu8bssid, 1542 pstrHostIFconnectAttr->pu8bssid,
1551 6) == 0) { 1543 6) == 0) {
1552 PRINT_INFO(HOSTINF_DBG, "BSSID is passed from the user and matched\n"); 1544 PRINT_INFO(HOSTINF_DBG, "BSSID is passed from the user and matched\n");
@@ -1559,29 +1551,29 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1559 if (i < pstrWFIDrv->u32SurveyResultsCount) { 1551 if (i < pstrWFIDrv->u32SurveyResultsCount) {
1560 u8bssDscListIndex = i; 1552 u8bssDscListIndex = i;
1561 1553
1562 PRINT_INFO(HOSTINF_DBG, "Connecting to network of Bss Idx %d and SSID %s and channel %d \n", 1554 PRINT_INFO(HOSTINF_DBG, "Connecting to network of Bss Idx%d and SSID %s and channel%d\n",
1563 u8bssDscListIndex, pstrWFIDrv->astrSurveyResults[u8bssDscListIndex].SSID, 1555 u8bssDscListIndex, pstrWFIDrv->astrSurveyResults[u8bssDscListIndex].SSID,
1564 pstrWFIDrv->astrSurveyResults[u8bssDscListIndex].Channel); 1556 pstrWFIDrv->astrSurveyResults[u8bssDscListIndex].Channel);
1565 1557
1566 PRINT_INFO(HOSTINF_DBG, "Saving connection parameters in global structure\n"); 1558 PRINT_INFO(HOSTINF_DBG, "Saving connection parameters in global structure\n");
1567 1559
1568 if (pstrHostIFconnectAttr->pu8bssid != NULL) { 1560 if (pstrHostIFconnectAttr->pu8bssid != NULL) {
1569 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = (u8 *)WILC_MALLOC(6); 1561 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = WILC_MALLOC(6);
1570 WILC_memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, pstrHostIFconnectAttr->pu8bssid, 6); 1562 memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, pstrHostIFconnectAttr->pu8bssid, 6);
1571 } 1563 }
1572 1564
1573 pstrWFIDrv->strWILC_UsrConnReq.ssidLen = pstrHostIFconnectAttr->ssidLen; 1565 pstrWFIDrv->strWILC_UsrConnReq.ssidLen = pstrHostIFconnectAttr->ssidLen;
1574 if (pstrHostIFconnectAttr->pu8ssid != NULL) { 1566 if (pstrHostIFconnectAttr->pu8ssid != NULL) {
1575 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = (u8 *)WILC_MALLOC(pstrHostIFconnectAttr->ssidLen + 1); 1567 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = WILC_MALLOC(pstrHostIFconnectAttr->ssidLen + 1);
1576 WILC_memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid, pstrHostIFconnectAttr->pu8ssid, 1568 memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid, pstrHostIFconnectAttr->pu8ssid,
1577 pstrHostIFconnectAttr->ssidLen); 1569 pstrHostIFconnectAttr->ssidLen);
1578 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid[pstrHostIFconnectAttr->ssidLen] = '\0'; 1570 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid[pstrHostIFconnectAttr->ssidLen] = '\0';
1579 } 1571 }
1580 1572
1581 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = pstrHostIFconnectAttr->IEsLen; 1573 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = pstrHostIFconnectAttr->IEsLen;
1582 if (pstrHostIFconnectAttr->pu8IEs != NULL) { 1574 if (pstrHostIFconnectAttr->pu8IEs != NULL) {
1583 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = (u8 *)WILC_MALLOC(pstrHostIFconnectAttr->IEsLen); 1575 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = WILC_MALLOC(pstrHostIFconnectAttr->IEsLen);
1584 WILC_memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs, pstrHostIFconnectAttr->pu8IEs, 1576 memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs, pstrHostIFconnectAttr->pu8IEs,
1585 pstrHostIFconnectAttr->IEsLen); 1577 pstrHostIFconnectAttr->IEsLen);
1586 } 1578 }
1587 1579
@@ -1630,14 +1622,12 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1630 strWIDList[u32WidsCount].ps8WidVal = (s8 *)&u8bssDscListIndex; 1622 strWIDList[u32WidsCount].ps8WidVal = (s8 *)&u8bssDscListIndex;
1631 u32WidsCount++; 1623 u32WidsCount++;
1632 1624
1633 #ifndef SIMULATION
1634 /* A temporary workaround to avoid handling the misleading MAC_DISCONNECTED raised from the 1625 /* A temporary workaround to avoid handling the misleading MAC_DISCONNECTED raised from the
1635 * firmware at chip reset when processing the WIDs of the Connect Request. 1626 * firmware at chip reset when processing the WIDs of the Connect Request.
1636 * (This workaround should be removed in the future when the Chip reset of the Connect WIDs is disabled) */ 1627 * (This workaround should be removed in the future when the Chip reset of the Connect WIDs is disabled) */
1637 /* ////////////////////// */ 1628 /* ////////////////////// */
1638 gu32WidConnRstHack = 0; 1629 gu32WidConnRstHack = 0;
1639 /* ////////////////////// */ 1630 /* ////////////////////// */
1640 #endif
1641 1631
1642 s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, (u32)pstrWFIDrv); 1632 s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, (u32)pstrWFIDrv);
1643 if (s32Error) { 1633 if (s32Error) {
@@ -1656,7 +1646,7 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1656 1646
1657 /* if we try to connect to an already connected AP then discard the request */ 1647 /* if we try to connect to an already connected AP then discard the request */
1658 1648
1659 if (WILC_memcmp(pstrHostIFconnectAttr->pu8bssid, u8ConnectedSSID, ETH_ALEN) == 0) { 1649 if (memcmp(pstrHostIFconnectAttr->pu8bssid, u8ConnectedSSID, ETH_ALEN) == 0) {
1660 1650
1661 s32Error = WILC_SUCCESS; 1651 s32Error = WILC_SUCCESS;
1662 PRINT_ER("Trying to connect to an already connected AP, Discard connect request\n"); 1652 PRINT_ER("Trying to connect to an already connected AP, Discard connect request\n");
@@ -1675,22 +1665,22 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1675 #endif /*WILC_PARSE_SCAN_IN_HOST*/ 1665 #endif /*WILC_PARSE_SCAN_IN_HOST*/
1676 1666
1677 if (pstrHostIFconnectAttr->pu8bssid != NULL) { 1667 if (pstrHostIFconnectAttr->pu8bssid != NULL) {
1678 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = (u8 *)WILC_MALLOC(6); 1668 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = WILC_MALLOC(6);
1679 WILC_memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, pstrHostIFconnectAttr->pu8bssid, 6); 1669 memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, pstrHostIFconnectAttr->pu8bssid, 6);
1680 } 1670 }
1681 1671
1682 pstrWFIDrv->strWILC_UsrConnReq.ssidLen = pstrHostIFconnectAttr->ssidLen; 1672 pstrWFIDrv->strWILC_UsrConnReq.ssidLen = pstrHostIFconnectAttr->ssidLen;
1683 if (pstrHostIFconnectAttr->pu8ssid != NULL) { 1673 if (pstrHostIFconnectAttr->pu8ssid != NULL) {
1684 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = (u8 *)WILC_MALLOC(pstrHostIFconnectAttr->ssidLen + 1); 1674 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = WILC_MALLOC(pstrHostIFconnectAttr->ssidLen + 1);
1685 WILC_memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid, pstrHostIFconnectAttr->pu8ssid, 1675 memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid, pstrHostIFconnectAttr->pu8ssid,
1686 pstrHostIFconnectAttr->ssidLen); 1676 pstrHostIFconnectAttr->ssidLen);
1687 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid[pstrHostIFconnectAttr->ssidLen] = '\0'; 1677 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid[pstrHostIFconnectAttr->ssidLen] = '\0';
1688 } 1678 }
1689 1679
1690 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = pstrHostIFconnectAttr->IEsLen; 1680 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = pstrHostIFconnectAttr->IEsLen;
1691 if (pstrHostIFconnectAttr->pu8IEs != NULL) { 1681 if (pstrHostIFconnectAttr->pu8IEs != NULL) {
1692 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = (u8 *)WILC_MALLOC(pstrHostIFconnectAttr->IEsLen); 1682 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = WILC_MALLOC(pstrHostIFconnectAttr->IEsLen);
1693 WILC_memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs, pstrHostIFconnectAttr->pu8IEs, 1683 memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs, pstrHostIFconnectAttr->pu8IEs,
1694 pstrHostIFconnectAttr->IEsLen); 1684 pstrHostIFconnectAttr->IEsLen);
1695 } 1685 }
1696 1686
@@ -1728,7 +1718,7 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1728 u32WidsCount++; 1718 u32WidsCount++;
1729 1719
1730 /*BugID_5137*/ 1720 /*BugID_5137*/
1731 if (WILC_memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) { 1721 if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) {
1732 1722
1733 gu32FlushedInfoElemAsocSize = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen; 1723 gu32FlushedInfoElemAsocSize = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen;
1734 gu8FlushedInfoElemAsoc = WILC_MALLOC(gu32FlushedInfoElemAsocSize); 1724 gu8FlushedInfoElemAsoc = WILC_MALLOC(gu32FlushedInfoElemAsocSize);
@@ -1743,7 +1733,7 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1743 u32WidsCount++; 1733 u32WidsCount++;
1744 1734
1745 /*BugID_5137*/ 1735 /*BugID_5137*/
1746 if (WILC_memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) 1736 if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7))
1747 gu8Flushed11iMode = pstrWFIDrv->strWILC_UsrConnReq.u8security; 1737 gu8Flushed11iMode = pstrWFIDrv->strWILC_UsrConnReq.u8security;
1748 1738
1749 PRINT_INFO(HOSTINF_DBG, "Encrypt Mode = %x\n", pstrWFIDrv->strWILC_UsrConnReq.u8security); 1739 PRINT_INFO(HOSTINF_DBG, "Encrypt Mode = %x\n", pstrWFIDrv->strWILC_UsrConnReq.u8security);
@@ -1756,7 +1746,7 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1756 u32WidsCount++; 1746 u32WidsCount++;
1757 1747
1758 /*BugID_5137*/ 1748 /*BugID_5137*/
1759 if (WILC_memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) 1749 if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7))
1760 gu8FlushedAuthType = (u8)pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type; 1750 gu8FlushedAuthType = (u8)pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type;
1761 1751
1762 PRINT_INFO(HOSTINF_DBG, "Authentication Type = %x\n", pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type); 1752 PRINT_INFO(HOSTINF_DBG, "Authentication Type = %x\n", pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type);
@@ -1778,14 +1768,13 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1778 strWIDList[u32WidsCount].s32ValueSize = MAX_SSID_LEN + 7; 1768 strWIDList[u32WidsCount].s32ValueSize = MAX_SSID_LEN + 7;
1779 strWIDList[u32WidsCount].ps8WidVal = WILC_MALLOC(strWIDList[u32WidsCount].s32ValueSize); 1769 strWIDList[u32WidsCount].ps8WidVal = WILC_MALLOC(strWIDList[u32WidsCount].s32ValueSize);
1780 1770
1781 if (strWIDList[u32WidsCount].ps8WidVal == NULL) { 1771 if (strWIDList[u32WidsCount].ps8WidVal == NULL)
1782 WILC_ERRORREPORT(s32Error, WILC_NO_MEM); 1772 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
1783 }
1784 1773
1785 pu8CurrByte = strWIDList[u32WidsCount].ps8WidVal; 1774 pu8CurrByte = strWIDList[u32WidsCount].ps8WidVal;
1786 1775
1787 if (pstrHostIFconnectAttr->pu8ssid != NULL) { 1776 if (pstrHostIFconnectAttr->pu8ssid != NULL) {
1788 WILC_memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8ssid, pstrHostIFconnectAttr->ssidLen); 1777 memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8ssid, pstrHostIFconnectAttr->ssidLen);
1789 pu8CurrByte[pstrHostIFconnectAttr->ssidLen] = '\0'; 1778 pu8CurrByte[pstrHostIFconnectAttr->ssidLen] = '\0';
1790 } 1779 }
1791 pu8CurrByte += MAX_SSID_LEN; 1780 pu8CurrByte += MAX_SSID_LEN;
@@ -1795,9 +1784,8 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1795 PRINT_ER("Channel out of range\n"); 1784 PRINT_ER("Channel out of range\n");
1796 *(pu8CurrByte++) = 0xFF; 1785 *(pu8CurrByte++) = 0xFF;
1797 } 1786 }
1798 if (pstrHostIFconnectAttr->pu8bssid != NULL) { 1787 if (pstrHostIFconnectAttr->pu8bssid != NULL)
1799 WILC_memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8bssid, 6); 1788 memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8bssid, 6);
1800 }
1801 pu8CurrByte += 6; 1789 pu8CurrByte += 6;
1802 1790
1803 /* keep the buffer at the start of the allocated pointer to use it with the free*/ 1791 /* keep the buffer at the start of the allocated pointer to use it with the free*/
@@ -1813,19 +1801,18 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1813 strWIDList[u32WidsCount].ps8WidVal = WILC_MALLOC(strWIDList[u32WidsCount].s32ValueSize); 1801 strWIDList[u32WidsCount].ps8WidVal = WILC_MALLOC(strWIDList[u32WidsCount].s32ValueSize);
1814 1802
1815 /*BugID_5137*/ 1803 /*BugID_5137*/
1816 if (WILC_memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) { 1804 if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) {
1817 gu32FlushedJoinReqSize = strWIDList[u32WidsCount].s32ValueSize; 1805 gu32FlushedJoinReqSize = strWIDList[u32WidsCount].s32ValueSize;
1818 gu8FlushedJoinReq = WILC_MALLOC(gu32FlushedJoinReqSize); 1806 gu8FlushedJoinReq = WILC_MALLOC(gu32FlushedJoinReqSize);
1819 } 1807 }
1820 if (strWIDList[u32WidsCount].ps8WidVal == NULL) { 1808 if (strWIDList[u32WidsCount].ps8WidVal == NULL)
1821 WILC_ERRORREPORT(s32Error, WILC_NO_MEM); 1809 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
1822 }
1823 1810
1824 pu8CurrByte = strWIDList[u32WidsCount].ps8WidVal; 1811 pu8CurrByte = strWIDList[u32WidsCount].ps8WidVal;
1825 1812
1826 1813
1827 if (pstrHostIFconnectAttr->pu8ssid != NULL) { 1814 if (pstrHostIFconnectAttr->pu8ssid != NULL) {
1828 WILC_memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8ssid, pstrHostIFconnectAttr->ssidLen); 1815 memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8ssid, pstrHostIFconnectAttr->ssidLen);
1829 pu8CurrByte[pstrHostIFconnectAttr->ssidLen] = '\0'; 1816 pu8CurrByte[pstrHostIFconnectAttr->ssidLen] = '\0';
1830 } 1817 }
1831 pu8CurrByte += MAX_SSID_LEN; 1818 pu8CurrByte += MAX_SSID_LEN;
@@ -1845,15 +1832,13 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1845 PRINT_D(HOSTINF_DBG, "* Cap Info %0x*\n", (*(pu8CurrByte - 2) | ((*(pu8CurrByte - 1)) << 8))); 1832 PRINT_D(HOSTINF_DBG, "* Cap Info %0x*\n", (*(pu8CurrByte - 2) | ((*(pu8CurrByte - 1)) << 8)));
1846 1833
1847 /* sa*/ 1834 /* sa*/
1848 if (pstrHostIFconnectAttr->pu8bssid != NULL) { 1835 if (pstrHostIFconnectAttr->pu8bssid != NULL)
1849 WILC_memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8bssid, 6); 1836 memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8bssid, 6);
1850 }
1851 pu8CurrByte += 6; 1837 pu8CurrByte += 6;
1852 1838
1853 /* bssid*/ 1839 /* bssid*/
1854 if (pstrHostIFconnectAttr->pu8bssid != NULL) { 1840 if (pstrHostIFconnectAttr->pu8bssid != NULL)
1855 WILC_memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8bssid, 6); 1841 memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8bssid, 6);
1856 }
1857 pu8CurrByte += 6; 1842 pu8CurrByte += 6;
1858 1843
1859 /* Beacon Period*/ 1844 /* Beacon Period*/
@@ -1864,7 +1849,7 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1864 *(pu8CurrByte++) = ptstrJoinBssParam->dtim_period; 1849 *(pu8CurrByte++) = ptstrJoinBssParam->dtim_period;
1865 PRINT_D(HOSTINF_DBG, "* DTIM Period %d*\n", (*(pu8CurrByte - 1))); 1850 PRINT_D(HOSTINF_DBG, "* DTIM Period %d*\n", (*(pu8CurrByte - 1)));
1866 /* Supported rates*/ 1851 /* Supported rates*/
1867 WILC_memcpy(pu8CurrByte, ptstrJoinBssParam->supp_rates, MAX_RATES_SUPPORTED + 1); 1852 memcpy(pu8CurrByte, ptstrJoinBssParam->supp_rates, MAX_RATES_SUPPORTED + 1);
1868 pu8CurrByte += (MAX_RATES_SUPPORTED + 1); 1853 pu8CurrByte += (MAX_RATES_SUPPORTED + 1);
1869 1854
1870 /* wmm cap*/ 1855 /* wmm cap*/
@@ -1888,15 +1873,15 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1888 *(pu8CurrByte++) = ptstrJoinBssParam->mode_802_11i; 1873 *(pu8CurrByte++) = ptstrJoinBssParam->mode_802_11i;
1889 PRINT_D(HOSTINF_DBG, "* mode_802_11i %d*\n", (*(pu8CurrByte - 1))); 1874 PRINT_D(HOSTINF_DBG, "* mode_802_11i %d*\n", (*(pu8CurrByte - 1)));
1890 /* rsn pcip policy*/ 1875 /* rsn pcip policy*/
1891 WILC_memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_pcip_policy, sizeof(ptstrJoinBssParam->rsn_pcip_policy)); 1876 memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_pcip_policy, sizeof(ptstrJoinBssParam->rsn_pcip_policy));
1892 pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_pcip_policy); 1877 pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_pcip_policy);
1893 1878
1894 /* rsn auth policy*/ 1879 /* rsn auth policy*/
1895 WILC_memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_auth_policy, sizeof(ptstrJoinBssParam->rsn_auth_policy)); 1880 memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_auth_policy, sizeof(ptstrJoinBssParam->rsn_auth_policy));
1896 pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_auth_policy); 1881 pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_auth_policy);
1897 1882
1898 /* rsn auth policy*/ 1883 /* rsn auth policy*/
1899 WILC_memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_cap, sizeof(ptstrJoinBssParam->rsn_cap)); 1884 memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_cap, sizeof(ptstrJoinBssParam->rsn_cap));
1900 pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_cap); 1885 pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_cap);
1901 1886
1902 /*BugID_5137*/ 1887 /*BugID_5137*/
@@ -1921,15 +1906,15 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1921 1906
1922 *(pu8CurrByte++) = ptstrJoinBssParam->u8Count; 1907 *(pu8CurrByte++) = ptstrJoinBssParam->u8Count;
1923 1908
1924 WILC_memcpy(pu8CurrByte, ptstrJoinBssParam->au8Duration, sizeof(ptstrJoinBssParam->au8Duration)); 1909 memcpy(pu8CurrByte, ptstrJoinBssParam->au8Duration, sizeof(ptstrJoinBssParam->au8Duration));
1925 1910
1926 pu8CurrByte += sizeof(ptstrJoinBssParam->au8Duration); 1911 pu8CurrByte += sizeof(ptstrJoinBssParam->au8Duration);
1927 1912
1928 WILC_memcpy(pu8CurrByte, ptstrJoinBssParam->au8Interval, sizeof(ptstrJoinBssParam->au8Interval)); 1913 memcpy(pu8CurrByte, ptstrJoinBssParam->au8Interval, sizeof(ptstrJoinBssParam->au8Interval));
1929 1914
1930 pu8CurrByte += sizeof(ptstrJoinBssParam->au8Interval); 1915 pu8CurrByte += sizeof(ptstrJoinBssParam->au8Interval);
1931 1916
1932 WILC_memcpy(pu8CurrByte, ptstrJoinBssParam->au8StartTime, sizeof(ptstrJoinBssParam->au8StartTime)); 1917 memcpy(pu8CurrByte, ptstrJoinBssParam->au8StartTime, sizeof(ptstrJoinBssParam->au8StartTime));
1933 1918
1934 pu8CurrByte += sizeof(ptstrJoinBssParam->au8StartTime); 1919 pu8CurrByte += sizeof(ptstrJoinBssParam->au8StartTime);
1935 1920
@@ -1945,17 +1930,15 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1945 #endif /* #ifdef WILC_PARSE_SCAN_IN_HOST*/ 1930 #endif /* #ifdef WILC_PARSE_SCAN_IN_HOST*/
1946 u32WidsCount++; 1931 u32WidsCount++;
1947 1932
1948 #ifndef SIMULATION
1949 /* A temporary workaround to avoid handling the misleading MAC_DISCONNECTED raised from the 1933 /* A temporary workaround to avoid handling the misleading MAC_DISCONNECTED raised from the
1950 * firmware at chip reset when processing the WIDs of the Connect Request. 1934 * firmware at chip reset when processing the WIDs of the Connect Request.
1951 * (This workaround should be removed in the future when the Chip reset of the Connect WIDs is disabled) */ 1935 * (This workaround should be removed in the future when the Chip reset of the Connect WIDs is disabled) */
1952 /* ////////////////////// */ 1936 /* ////////////////////// */
1953 gu32WidConnRstHack = 0; 1937 gu32WidConnRstHack = 0;
1954 /* ////////////////////// */ 1938 /* ////////////////////// */
1955 #endif
1956 1939
1957 /*BugID_5137*/ 1940 /*BugID_5137*/
1958 if (WILC_memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) { 1941 if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) {
1959 memcpy(gu8FlushedJoinReq, pu8CurrByte, gu32FlushedJoinReqSize); 1942 memcpy(gu8FlushedJoinReq, pu8CurrByte, gu32FlushedJoinReqSize);
1960 gu8FlushedJoinReqDrvHandler = (u32)pstrWFIDrv; 1943 gu8FlushedJoinReqDrvHandler = (u32)pstrWFIDrv;
1961 } 1944 }
@@ -1963,7 +1946,7 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1963 PRINT_D(GENERIC_DBG, "send HOST_IF_WAITING_CONN_RESP\n"); 1946 PRINT_D(GENERIC_DBG, "send HOST_IF_WAITING_CONN_RESP\n");
1964 1947
1965 if (pstrHostIFconnectAttr->pu8bssid != NULL) { 1948 if (pstrHostIFconnectAttr->pu8bssid != NULL) {
1966 WILC_memcpy(u8ConnectedSSID, pstrHostIFconnectAttr->pu8bssid, ETH_ALEN); 1949 memcpy(u8ConnectedSSID, pstrHostIFconnectAttr->pu8bssid, ETH_ALEN);
1967 1950
1968 PRINT_D(GENERIC_DBG, "save Bssid = %x:%x:%x:%x:%x:%x\n", (pstrHostIFconnectAttr->pu8bssid[0]), (pstrHostIFconnectAttr->pu8bssid[1]), (pstrHostIFconnectAttr->pu8bssid[2]), (pstrHostIFconnectAttr->pu8bssid[3]), (pstrHostIFconnectAttr->pu8bssid[4]), (pstrHostIFconnectAttr->pu8bssid[5])); 1951 PRINT_D(GENERIC_DBG, "save Bssid = %x:%x:%x:%x:%x:%x\n", (pstrHostIFconnectAttr->pu8bssid[0]), (pstrHostIFconnectAttr->pu8bssid[1]), (pstrHostIFconnectAttr->pu8bssid[2]), (pstrHostIFconnectAttr->pu8bssid[3]), (pstrHostIFconnectAttr->pu8bssid[4]), (pstrHostIFconnectAttr->pu8bssid[5]));
1969 PRINT_D(GENERIC_DBG, "save bssid = %x:%x:%x:%x:%x:%x\n", (u8ConnectedSSID[0]), (u8ConnectedSSID[1]), (u8ConnectedSSID[2]), (u8ConnectedSSID[3]), (u8ConnectedSSID[4]), (u8ConnectedSSID[5])); 1952 PRINT_D(GENERIC_DBG, "save bssid = %x:%x:%x:%x:%x:%x\n", (u8ConnectedSSID[0]), (u8ConnectedSSID[1]), (u8ConnectedSSID[2]), (u8ConnectedSSID[3]), (u8ConnectedSSID[4]), (u8ConnectedSSID[5]));
@@ -1983,21 +1966,20 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
1983 { 1966 {
1984 tstrConnectInfo strConnectInfo; 1967 tstrConnectInfo strConnectInfo;
1985 1968
1986 WILC_TimerStop(&(pstrWFIDrv->hConnectTimer), NULL); 1969 del_timer(&pstrWFIDrv->hConnectTimer);
1987 1970
1988 PRINT_D(HOSTINF_DBG, "could not start connecting to the required network\n"); 1971 PRINT_D(HOSTINF_DBG, "could not start connecting to the required network\n");
1989 1972
1990 WILC_memset(&strConnectInfo, 0, sizeof(tstrConnectInfo)); 1973 memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
1991 1974
1992 if (pstrHostIFconnectAttr->pfConnectResult != NULL) { 1975 if (pstrHostIFconnectAttr->pfConnectResult != NULL) {
1993 if (pstrHostIFconnectAttr->pu8bssid != NULL) { 1976 if (pstrHostIFconnectAttr->pu8bssid != NULL)
1994 WILC_memcpy(strConnectInfo.au8bssid, pstrHostIFconnectAttr->pu8bssid, 6); 1977 memcpy(strConnectInfo.au8bssid, pstrHostIFconnectAttr->pu8bssid, 6);
1995 }
1996 1978
1997 if (pstrHostIFconnectAttr->pu8IEs != NULL) { 1979 if (pstrHostIFconnectAttr->pu8IEs != NULL) {
1998 strConnectInfo.ReqIEsLen = pstrHostIFconnectAttr->IEsLen; 1980 strConnectInfo.ReqIEsLen = pstrHostIFconnectAttr->IEsLen;
1999 strConnectInfo.pu8ReqIEs = (u8 *)WILC_MALLOC(pstrHostIFconnectAttr->IEsLen); 1981 strConnectInfo.pu8ReqIEs = WILC_MALLOC(pstrHostIFconnectAttr->IEsLen);
2000 WILC_memcpy(strConnectInfo.pu8ReqIEs, 1982 memcpy(strConnectInfo.pu8ReqIEs,
2001 pstrHostIFconnectAttr->pu8IEs, 1983 pstrHostIFconnectAttr->pu8IEs,
2002 pstrHostIFconnectAttr->IEsLen); 1984 pstrHostIFconnectAttr->IEsLen);
2003 } 1985 }
@@ -2011,37 +1993,36 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
2011 pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE; 1993 pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
2012 /* Deallocation */ 1994 /* Deallocation */
2013 if (strConnectInfo.pu8ReqIEs != NULL) { 1995 if (strConnectInfo.pu8ReqIEs != NULL) {
2014 WILC_FREE(strConnectInfo.pu8ReqIEs); 1996 kfree(strConnectInfo.pu8ReqIEs);
2015 strConnectInfo.pu8ReqIEs = NULL; 1997 strConnectInfo.pu8ReqIEs = NULL;
2016 } 1998 }
2017 1999
2018 } else { 2000 } else {
2019 PRINT_ER("Connect callback function pointer is NULL \n"); 2001 PRINT_ER("Connect callback function pointer is NULL\n");
2020 } 2002 }
2021 } 2003 }
2022 2004
2023 PRINT_D(HOSTINF_DBG, "Deallocating connection parameters\n"); 2005 PRINT_D(HOSTINF_DBG, "Deallocating connection parameters\n");
2024 /* Deallocate pstrHostIFconnectAttr->pu8bssid which was prevoisuly allocated by the sending thread */ 2006 /* Deallocate pstrHostIFconnectAttr->pu8bssid which was prevoisuly allocated by the sending thread */
2025 if (pstrHostIFconnectAttr->pu8bssid != NULL) { 2007 if (pstrHostIFconnectAttr->pu8bssid != NULL) {
2026 WILC_FREE(pstrHostIFconnectAttr->pu8bssid); 2008 kfree(pstrHostIFconnectAttr->pu8bssid);
2027 pstrHostIFconnectAttr->pu8bssid = NULL; 2009 pstrHostIFconnectAttr->pu8bssid = NULL;
2028 } 2010 }
2029 2011
2030 /* Deallocate pstrHostIFconnectAttr->pu8ssid which was prevoisuly allocated by the sending thread */ 2012 /* Deallocate pstrHostIFconnectAttr->pu8ssid which was prevoisuly allocated by the sending thread */
2031 if (pstrHostIFconnectAttr->pu8ssid != NULL) { 2013 if (pstrHostIFconnectAttr->pu8ssid != NULL) {
2032 WILC_FREE(pstrHostIFconnectAttr->pu8ssid); 2014 kfree(pstrHostIFconnectAttr->pu8ssid);
2033 pstrHostIFconnectAttr->pu8ssid = NULL; 2015 pstrHostIFconnectAttr->pu8ssid = NULL;
2034 } 2016 }
2035 2017
2036 /* Deallocate pstrHostIFconnectAttr->pu8IEs which was prevoisuly allocated by the sending thread */ 2018 /* Deallocate pstrHostIFconnectAttr->pu8IEs which was prevoisuly allocated by the sending thread */
2037 if (pstrHostIFconnectAttr->pu8IEs != NULL) { 2019 if (pstrHostIFconnectAttr->pu8IEs != NULL) {
2038 WILC_FREE(pstrHostIFconnectAttr->pu8IEs); 2020 kfree(pstrHostIFconnectAttr->pu8IEs);
2039 pstrHostIFconnectAttr->pu8IEs = NULL; 2021 pstrHostIFconnectAttr->pu8IEs = NULL;
2040 } 2022 }
2041 2023
2042 if (pu8CurrByte != NULL) { 2024 if (pu8CurrByte != NULL)
2043 WILC_FREE(pu8CurrByte); 2025 kfree(pu8CurrByte);
2044 }
2045 return s32Error; 2026 return s32Error;
2046} 2027}
2047 2028
@@ -2056,7 +2037,7 @@ static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFcon
2056 * @version 8.0 2037 * @version 8.0
2057 */ 2038 */
2058 2039
2059static s32 Handle_FlushConnect(void *drvHandler) 2040static s32 Handle_FlushConnect(tstrWILC_WFIDrv *drvHandler)
2060{ 2041{
2061 s32 s32Error = WILC_SUCCESS; 2042 s32 s32Error = WILC_SUCCESS;
2062 tstrWID strWIDList[5]; 2043 tstrWID strWIDList[5];
@@ -2123,7 +2104,7 @@ static s32 Handle_FlushConnect(void *drvHandler)
2123 * @date 2104 * @date
2124 * @version 1.0 2105 * @version 1.0
2125 */ 2106 */
2126static s32 Handle_ConnectTimeout(void *drvHandler) 2107static s32 Handle_ConnectTimeout(tstrWILC_WFIDrv *drvHandler)
2127{ 2108{
2128 s32 s32Error = WILC_SUCCESS; 2109 s32 s32Error = WILC_SUCCESS;
2129 tstrConnectInfo strConnectInfo; 2110 tstrConnectInfo strConnectInfo;
@@ -2141,7 +2122,7 @@ static s32 Handle_ConnectTimeout(void *drvHandler)
2141 gbScanWhileConnected = false; 2122 gbScanWhileConnected = false;
2142 2123
2143 2124
2144 WILC_memset(&strConnectInfo, 0, sizeof(tstrConnectInfo)); 2125 memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
2145 2126
2146 2127
2147 /* First, we will notify the upper layer with the Connection failure {through the Connect Callback function}, 2128 /* First, we will notify the upper layer with the Connection failure {through the Connect Callback function},
@@ -2149,14 +2130,14 @@ static s32 Handle_ConnectTimeout(void *drvHandler)
2149 * WID_DISCONNECT} */ 2130 * WID_DISCONNECT} */
2150 if (pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult != NULL) { 2131 if (pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult != NULL) {
2151 if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) { 2132 if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
2152 WILC_memcpy(strConnectInfo.au8bssid, 2133 memcpy(strConnectInfo.au8bssid,
2153 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, 6); 2134 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, 6);
2154 } 2135 }
2155 2136
2156 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) { 2137 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
2157 strConnectInfo.ReqIEsLen = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen; 2138 strConnectInfo.ReqIEsLen = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen;
2158 strConnectInfo.pu8ReqIEs = (u8 *)WILC_MALLOC(pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen); 2139 strConnectInfo.pu8ReqIEs = WILC_MALLOC(pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen);
2159 WILC_memcpy(strConnectInfo.pu8ReqIEs, 2140 memcpy(strConnectInfo.pu8ReqIEs,
2160 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs, 2141 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs,
2161 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen); 2142 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen);
2162 } 2143 }
@@ -2169,11 +2150,11 @@ static s32 Handle_ConnectTimeout(void *drvHandler)
2169 2150
2170 /* Deallocation of strConnectInfo.pu8ReqIEs */ 2151 /* Deallocation of strConnectInfo.pu8ReqIEs */
2171 if (strConnectInfo.pu8ReqIEs != NULL) { 2152 if (strConnectInfo.pu8ReqIEs != NULL) {
2172 WILC_FREE(strConnectInfo.pu8ReqIEs); 2153 kfree(strConnectInfo.pu8ReqIEs);
2173 strConnectInfo.pu8ReqIEs = NULL; 2154 strConnectInfo.pu8ReqIEs = NULL;
2174 } 2155 }
2175 } else { 2156 } else {
2176 PRINT_ER("Connect callback function pointer is NULL \n"); 2157 PRINT_ER("Connect callback function pointer is NULL\n");
2177 } 2158 }
2178 2159
2179 /* Here we will notify our firmware also with the Connection failure {through sending to it Cfg packet carrying 2160 /* Here we will notify our firmware also with the Connection failure {through sending to it Cfg packet carrying
@@ -2186,37 +2167,36 @@ static s32 Handle_ConnectTimeout(void *drvHandler)
2186 PRINT_D(HOSTINF_DBG, "Sending disconnect request\n"); 2167 PRINT_D(HOSTINF_DBG, "Sending disconnect request\n");
2187 2168
2188 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv); 2169 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
2189 if (s32Error) { 2170 if (s32Error)
2190 PRINT_ER("Failed to send dissconect config packet\n"); 2171 PRINT_ER("Failed to send dissconect config packet\n");
2191 }
2192 2172
2193 /* Deallocation of the Saved Connect Request in the global Handle */ 2173 /* Deallocation of the Saved Connect Request in the global Handle */
2194 pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0; 2174 pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0;
2195 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) { 2175 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) {
2196 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid); 2176 kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid);
2197 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL; 2177 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL;
2198 } 2178 }
2199 2179
2200 if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) { 2180 if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
2201 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid); 2181 kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid);
2202 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL; 2182 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL;
2203 } 2183 }
2204 2184
2205 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0; 2185 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
2206 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) { 2186 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
2207 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs); 2187 kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs);
2208 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL; 2188 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL;
2209 } 2189 }
2210 2190
2211 WILC_memset(u8ConnectedSSID, 0, ETH_ALEN); 2191 memset(u8ConnectedSSID, 0, ETH_ALEN);
2212 /*BugID_5213*/ 2192 /*BugID_5213*/
2213 /*Freeing flushed join request params on connect timeout*/ 2193 /*Freeing flushed join request params on connect timeout*/
2214 if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) { 2194 if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
2215 WILC_FREE(gu8FlushedJoinReq); 2195 kfree(gu8FlushedJoinReq);
2216 gu8FlushedJoinReq = NULL; 2196 gu8FlushedJoinReq = NULL;
2217 } 2197 }
2218 if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) { 2198 if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
2219 WILC_FREE(gu8FlushedInfoElemAsoc); 2199 kfree(gu8FlushedInfoElemAsoc);
2220 gu8FlushedInfoElemAsoc = NULL; 2200 gu8FlushedInfoElemAsoc = NULL;
2221 } 2201 }
2222 2202
@@ -2232,7 +2212,7 @@ static s32 Handle_ConnectTimeout(void *drvHandler)
2232 * @date 2212 * @date
2233 * @version 1.0 2213 * @version 1.0
2234 */ 2214 */
2235static s32 Handle_RcvdNtwrkInfo(void *drvHandler, tstrRcvdNetworkInfo *pstrRcvdNetworkInfo) 2215static s32 Handle_RcvdNtwrkInfo(tstrWILC_WFIDrv *drvHandler, tstrRcvdNetworkInfo *pstrRcvdNetworkInfo)
2236{ 2216{
2237 u32 i; 2217 u32 i;
2238 bool bNewNtwrkFound; 2218 bool bNewNtwrkFound;
@@ -2264,7 +2244,7 @@ static s32 Handle_RcvdNtwrkInfo(void *drvHandler, tstrRcvdNetworkInfo *pstrRcvdN
2264 2244
2265 if ((pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].au8bssid != NULL) && 2245 if ((pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].au8bssid != NULL) &&
2266 (pstrNetworkInfo->au8bssid != NULL)) { 2246 (pstrNetworkInfo->au8bssid != NULL)) {
2267 if (WILC_memcmp(pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].au8bssid, 2247 if (memcmp(pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].au8bssid,
2268 pstrNetworkInfo->au8bssid, 6) == 0) { 2248 pstrNetworkInfo->au8bssid, 6) == 0) {
2269 if (pstrNetworkInfo->s8rssi <= pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].s8rssi) { 2249 if (pstrNetworkInfo->s8rssi <= pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].s8rssi) {
2270 /*we have already found this network with better rssi, so keep the old cached one and don't 2250 /*we have already found this network with better rssi, so keep the old cached one and don't
@@ -2294,7 +2274,7 @@ static s32 Handle_RcvdNtwrkInfo(void *drvHandler, tstrRcvdNetworkInfo *pstrRcvdN
2294 2274
2295 if ((pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount].au8bssid != NULL) 2275 if ((pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount].au8bssid != NULL)
2296 && (pstrNetworkInfo->au8bssid != NULL)) { 2276 && (pstrNetworkInfo->au8bssid != NULL)) {
2297 WILC_memcpy(pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount].au8bssid, 2277 memcpy(pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount].au8bssid,
2298 pstrNetworkInfo->au8bssid, 6); 2278 pstrNetworkInfo->au8bssid, 6);
2299 2279
2300 pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount++; 2280 pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount++;
@@ -2313,7 +2293,7 @@ static s32 Handle_RcvdNtwrkInfo(void *drvHandler, tstrRcvdNetworkInfo *pstrRcvdN
2313 2293
2314 } 2294 }
2315 } else { 2295 } else {
2316 PRINT_WRN(HOSTINF_DBG, "Discovered networks exceeded max. limit \n"); 2296 PRINT_WRN(HOSTINF_DBG, "Discovered networks exceeded max. limit\n");
2317 } 2297 }
2318 } else { 2298 } else {
2319 pstrNetworkInfo->bNewNetwork = false; 2299 pstrNetworkInfo->bNewNetwork = false;
@@ -2332,7 +2312,7 @@ static s32 Handle_RcvdNtwrkInfo(void *drvHandler, tstrRcvdNetworkInfo *pstrRcvdN
2332done: 2312done:
2333 /* Deallocate pstrRcvdNetworkInfo->pu8Buffer which was prevoisuly allocated by the sending thread */ 2313 /* Deallocate pstrRcvdNetworkInfo->pu8Buffer which was prevoisuly allocated by the sending thread */
2334 if (pstrRcvdNetworkInfo->pu8Buffer != NULL) { 2314 if (pstrRcvdNetworkInfo->pu8Buffer != NULL) {
2335 WILC_FREE(pstrRcvdNetworkInfo->pu8Buffer); 2315 kfree(pstrRcvdNetworkInfo->pu8Buffer);
2336 pstrRcvdNetworkInfo->pu8Buffer = NULL; 2316 pstrRcvdNetworkInfo->pu8Buffer = NULL;
2337 } 2317 }
2338 2318
@@ -2354,7 +2334,7 @@ done:
2354 * @date 2334 * @date
2355 * @version 1.0 2335 * @version 1.0
2356 */ 2336 */
2357static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pstrRcvdGnrlAsyncInfo) 2337static s32 Handle_RcvdGnrlAsyncInfo(tstrWILC_WFIDrv *drvHandler, tstrRcvdGnrlAsyncInfo *pstrRcvdGnrlAsyncInfo)
2358{ 2338{
2359 /* TODO: mostafa: till now, this function just handles only the received mac status msg, */ 2339 /* TODO: mostafa: till now, this function just handles only the received mac status msg, */
2360 /* which carries only 1 WID which have WID ID = WID_STATUS */ 2340 /* which carries only 1 WID which have WID ID = WID_STATUS */
@@ -2371,9 +2351,9 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2371 tstrDisconnectNotifInfo strDisconnectNotifInfo; 2351 tstrDisconnectNotifInfo strDisconnectNotifInfo;
2372 s32 s32Err = WILC_SUCCESS; 2352 s32 s32Err = WILC_SUCCESS;
2373 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler; 2353 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler;
2374 if (pstrWFIDrv == NULL) { 2354
2355 if (pstrWFIDrv == NULL)
2375 PRINT_ER("Driver handler is NULL\n"); 2356 PRINT_ER("Driver handler is NULL\n");
2376 }
2377 PRINT_D(GENERIC_DBG, "Current State = %d,Received state = %d\n", pstrWFIDrv->enuHostIFstate, 2357 PRINT_D(GENERIC_DBG, "Current State = %d,Received state = %d\n", pstrWFIDrv->enuHostIFstate,
2378 pstrRcvdGnrlAsyncInfo->pu8Buffer[7]); 2358 pstrRcvdGnrlAsyncInfo->pu8Buffer[7]);
2379 2359
@@ -2417,12 +2397,12 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2417 2397
2418 PRINT_D(HOSTINF_DBG, "Recieved MAC status = %d with Reason = %d , Code = %d\n", u8MacStatus, u8MacStatusReasonCode, u8MacStatusAdditionalInfo); 2398 PRINT_D(HOSTINF_DBG, "Recieved MAC status = %d with Reason = %d , Code = %d\n", u8MacStatus, u8MacStatusReasonCode, u8MacStatusAdditionalInfo);
2419 2399
2420 WILC_memset(&strConnectInfo, 0, sizeof(tstrConnectInfo)); 2400 memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
2421 2401
2422 if (u8MacStatus == MAC_CONNECTED) { 2402 if (u8MacStatus == MAC_CONNECTED) {
2423 WILC_memset(gapu8RcvdAssocResp, 0, MAX_ASSOC_RESP_FRAME_SIZE); 2403 memset(gapu8RcvdAssocResp, 0, MAX_ASSOC_RESP_FRAME_SIZE);
2424 2404
2425 host_int_get_assoc_res_info((WILC_WFIDrvHandle)pstrWFIDrv, 2405 host_int_get_assoc_res_info(pstrWFIDrv,
2426 gapu8RcvdAssocResp, 2406 gapu8RcvdAssocResp,
2427 MAX_ASSOC_RESP_FRAME_SIZE, 2407 MAX_ASSOC_RESP_FRAME_SIZE,
2428 &u32RcvdAssocRespInfoLen); 2408 &u32RcvdAssocRespInfoLen);
@@ -2435,7 +2415,7 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2435 s32Err = ParseAssocRespInfo(gapu8RcvdAssocResp, u32RcvdAssocRespInfoLen, 2415 s32Err = ParseAssocRespInfo(gapu8RcvdAssocResp, u32RcvdAssocRespInfoLen,
2436 &pstrConnectRespInfo); 2416 &pstrConnectRespInfo);
2437 if (s32Err) { 2417 if (s32Err) {
2438 PRINT_ER("ParseAssocRespInfo() returned error %d \n", s32Err); 2418 PRINT_ER("ParseAssocRespInfo() returned error %d\n", s32Err);
2439 } else { 2419 } else {
2440 /* use the necessary parsed Info from the Received Association Response */ 2420 /* use the necessary parsed Info from the Received Association Response */
2441 strConnectInfo.u16ConnectStatus = pstrConnectRespInfo->u16ConnectStatus; 2421 strConnectInfo.u16ConnectStatus = pstrConnectRespInfo->u16ConnectStatus;
@@ -2446,8 +2426,8 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2446 strConnectInfo.u16RespIEsLen = pstrConnectRespInfo->u16RespIEsLen; 2426 strConnectInfo.u16RespIEsLen = pstrConnectRespInfo->u16RespIEsLen;
2447 2427
2448 2428
2449 strConnectInfo.pu8RespIEs = (u8 *)WILC_MALLOC(pstrConnectRespInfo->u16RespIEsLen); 2429 strConnectInfo.pu8RespIEs = WILC_MALLOC(pstrConnectRespInfo->u16RespIEsLen);
2450 WILC_memcpy(strConnectInfo.pu8RespIEs, pstrConnectRespInfo->pu8RespIEs, 2430 memcpy(strConnectInfo.pu8RespIEs, pstrConnectRespInfo->pu8RespIEs,
2451 pstrConnectRespInfo->u16RespIEsLen); 2431 pstrConnectRespInfo->u16RespIEsLen);
2452 } 2432 }
2453 } 2433 }
@@ -2466,23 +2446,23 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2466 * So check first the matching between the received mac status and the received status code in Asoc Resp */ 2446 * So check first the matching between the received mac status and the received status code in Asoc Resp */
2467 if ((u8MacStatus == MAC_CONNECTED) && 2447 if ((u8MacStatus == MAC_CONNECTED) &&
2468 (strConnectInfo.u16ConnectStatus != SUCCESSFUL_STATUSCODE)) { 2448 (strConnectInfo.u16ConnectStatus != SUCCESSFUL_STATUSCODE)) {
2469 PRINT_ER("Received MAC status is MAC_CONNECTED while the received status code in Asoc Resp is not SUCCESSFUL_STATUSCODE \n"); 2449 PRINT_ER("Received MAC status is MAC_CONNECTED while the received status code in Asoc Resp is not SUCCESSFUL_STATUSCODE\n");
2470 WILC_memset(u8ConnectedSSID, 0, ETH_ALEN); 2450 memset(u8ConnectedSSID, 0, ETH_ALEN);
2471 2451
2472 } else if (u8MacStatus == MAC_DISCONNECTED) { 2452 } else if (u8MacStatus == MAC_DISCONNECTED) {
2473 PRINT_ER("Received MAC status is MAC_DISCONNECTED\n"); 2453 PRINT_ER("Received MAC status is MAC_DISCONNECTED\n");
2474 WILC_memset(u8ConnectedSSID, 0, ETH_ALEN); 2454 memset(u8ConnectedSSID, 0, ETH_ALEN);
2475 } 2455 }
2476 2456
2477 /* TODO: mostafa: correct BSSID should be retrieved from actual BSSID received from AP */ 2457 /* TODO: mostafa: correct BSSID should be retrieved from actual BSSID received from AP */
2478 /* through a structure of type tstrConnectRespInfo */ 2458 /* through a structure of type tstrConnectRespInfo */
2479 if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) { 2459 if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
2480 PRINT_D(HOSTINF_DBG, "Retrieving actual BSSID from AP\n"); 2460 PRINT_D(HOSTINF_DBG, "Retrieving actual BSSID from AP\n");
2481 WILC_memcpy(strConnectInfo.au8bssid, pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, 6); 2461 memcpy(strConnectInfo.au8bssid, pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, 6);
2482 2462
2483 if ((u8MacStatus == MAC_CONNECTED) && 2463 if ((u8MacStatus == MAC_CONNECTED) &&
2484 (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) { 2464 (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
2485 WILC_memcpy(pstrWFIDrv->au8AssociatedBSSID, 2465 memcpy(pstrWFIDrv->au8AssociatedBSSID,
2486 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, ETH_ALEN); 2466 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, ETH_ALEN);
2487 } 2467 }
2488 } 2468 }
@@ -2490,14 +2470,14 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2490 2470
2491 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) { 2471 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
2492 strConnectInfo.ReqIEsLen = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen; 2472 strConnectInfo.ReqIEsLen = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen;
2493 strConnectInfo.pu8ReqIEs = (u8 *)WILC_MALLOC(pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen); 2473 strConnectInfo.pu8ReqIEs = WILC_MALLOC(pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen);
2494 WILC_memcpy(strConnectInfo.pu8ReqIEs, 2474 memcpy(strConnectInfo.pu8ReqIEs,
2495 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs, 2475 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs,
2496 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen); 2476 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen);
2497 } 2477 }
2498 2478
2499 2479
2500 WILC_TimerStop(&(pstrWFIDrv->hConnectTimer), NULL); 2480 del_timer(&pstrWFIDrv->hConnectTimer);
2501 pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP, 2481 pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
2502 &strConnectInfo, 2482 &strConnectInfo,
2503 u8MacStatus, 2483 u8MacStatus,
@@ -2512,7 +2492,7 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2512 (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) { 2492 (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
2513 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 2493 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2514 2494
2515 host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 0, 0); 2495 host_int_set_power_mgmt(pstrWFIDrv, 0, 0);
2516 #endif 2496 #endif
2517 2497
2518 PRINT_D(HOSTINF_DBG, "MAC status : CONNECTED and Connect Status : Successful\n"); 2498 PRINT_D(HOSTINF_DBG, "MAC status : CONNECTED and Connect Status : Successful\n");
@@ -2521,7 +2501,8 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2521 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 2501 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2522 PRINT_D(GENERIC_DBG, "Obtaining an IP, Disable Scan\n"); 2502 PRINT_D(GENERIC_DBG, "Obtaining an IP, Disable Scan\n");
2523 g_obtainingIP = true; 2503 g_obtainingIP = true;
2524 WILC_TimerStart(&hDuringIpTimer, 10000, NULL, NULL); 2504 mod_timer(&hDuringIpTimer,
2505 jiffies + msecs_to_jiffies(10000));
2525 #endif 2506 #endif
2526 2507
2527 #ifdef WILC_PARSE_SCAN_IN_HOST 2508 #ifdef WILC_PARSE_SCAN_IN_HOST
@@ -2540,30 +2521,30 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2540 2521
2541 /* Deallocation */ 2522 /* Deallocation */
2542 if (strConnectInfo.pu8RespIEs != NULL) { 2523 if (strConnectInfo.pu8RespIEs != NULL) {
2543 WILC_FREE(strConnectInfo.pu8RespIEs); 2524 kfree(strConnectInfo.pu8RespIEs);
2544 strConnectInfo.pu8RespIEs = NULL; 2525 strConnectInfo.pu8RespIEs = NULL;
2545 } 2526 }
2546 2527
2547 if (strConnectInfo.pu8ReqIEs != NULL) { 2528 if (strConnectInfo.pu8ReqIEs != NULL) {
2548 WILC_FREE(strConnectInfo.pu8ReqIEs); 2529 kfree(strConnectInfo.pu8ReqIEs);
2549 strConnectInfo.pu8ReqIEs = NULL; 2530 strConnectInfo.pu8ReqIEs = NULL;
2550 } 2531 }
2551 2532
2552 2533
2553 pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0; 2534 pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0;
2554 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) { 2535 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) {
2555 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid); 2536 kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid);
2556 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL; 2537 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL;
2557 } 2538 }
2558 2539
2559 if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) { 2540 if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
2560 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid); 2541 kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid);
2561 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL; 2542 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL;
2562 } 2543 }
2563 2544
2564 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0; 2545 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
2565 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) { 2546 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
2566 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs); 2547 kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs);
2567 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL; 2548 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL;
2568 } 2549 }
2569 2550
@@ -2572,11 +2553,11 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2572 /* Disassociation or Deauthentication frame has been received */ 2553 /* Disassociation or Deauthentication frame has been received */
2573 PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW\n"); 2554 PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW\n");
2574 2555
2575 WILC_memset(&strDisconnectNotifInfo, 0, sizeof(tstrDisconnectNotifInfo)); 2556 memset(&strDisconnectNotifInfo, 0, sizeof(tstrDisconnectNotifInfo));
2576 2557
2577 if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) { 2558 if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
2578 PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running OBSS Scan >> \n\n"); 2559 PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running OBSS Scan >>\n\n");
2579 WILC_TimerStop(&(pstrWFIDrv->hScanTimer), NULL); 2560 del_timer(&pstrWFIDrv->hScanTimer);
2580 Handle_ScanDone((void *)pstrWFIDrv, SCAN_EVENT_ABORTED); 2561 Handle_ScanDone((void *)pstrWFIDrv, SCAN_EVENT_ABORTED);
2581 } 2562 }
2582 2563
@@ -2588,7 +2569,7 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2588 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 2569 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2589 2570
2590 g_obtainingIP = false; 2571 g_obtainingIP = false;
2591 host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 0, 0); 2572 host_int_set_power_mgmt(pstrWFIDrv, 0, 0);
2592 #endif 2573 #endif
2593 2574
2594 pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF, 2575 pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF,
@@ -2598,10 +2579,10 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2598 pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid); 2579 pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid);
2599 2580
2600 } else { 2581 } else {
2601 PRINT_ER("Connect result callback function is NULL \n"); 2582 PRINT_ER("Connect result callback function is NULL\n");
2602 } 2583 }
2603 2584
2604 WILC_memset(pstrWFIDrv->au8AssociatedBSSID, 0, ETH_ALEN); 2585 memset(pstrWFIDrv->au8AssociatedBSSID, 0, ETH_ALEN);
2605 2586
2606 2587
2607 /* Deallocation */ 2588 /* Deallocation */
@@ -2611,25 +2592,25 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2611 /* 2592 /*
2612 * if(strDisconnectNotifInfo.ie != NULL) 2593 * if(strDisconnectNotifInfo.ie != NULL)
2613 * { 2594 * {
2614 * WILC_FREE(strDisconnectNotifInfo.ie); 2595 * kfree(strDisconnectNotifInfo.ie);
2615 * strDisconnectNotifInfo.ie = NULL; 2596 * strDisconnectNotifInfo.ie = NULL;
2616 * } 2597 * }
2617 */ 2598 */
2618 2599
2619 pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0; 2600 pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0;
2620 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) { 2601 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) {
2621 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid); 2602 kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid);
2622 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL; 2603 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL;
2623 } 2604 }
2624 2605
2625 if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) { 2606 if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
2626 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid); 2607 kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid);
2627 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL; 2608 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL;
2628 } 2609 }
2629 2610
2630 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0; 2611 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
2631 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) { 2612 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
2632 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs); 2613 kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs);
2633 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL; 2614 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL;
2634 } 2615 }
2635 2616
@@ -2637,11 +2618,11 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2637 /*Freeing flushed join request params on receiving*/ 2618 /*Freeing flushed join request params on receiving*/
2638 /*MAC_DISCONNECTED while connected*/ 2619 /*MAC_DISCONNECTED while connected*/
2639 if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) { 2620 if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
2640 WILC_FREE(gu8FlushedJoinReq); 2621 kfree(gu8FlushedJoinReq);
2641 gu8FlushedJoinReq = NULL; 2622 gu8FlushedJoinReq = NULL;
2642 } 2623 }
2643 if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) { 2624 if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
2644 WILC_FREE(gu8FlushedInfoElemAsoc); 2625 kfree(gu8FlushedInfoElemAsoc);
2645 gu8FlushedInfoElemAsoc = NULL; 2626 gu8FlushedInfoElemAsoc = NULL;
2646 } 2627 }
2647 2628
@@ -2651,13 +2632,12 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2651 } else if ((u8MacStatus == MAC_DISCONNECTED) && 2632 } else if ((u8MacStatus == MAC_DISCONNECTED) &&
2652 (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult != NULL)) { 2633 (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult != NULL)) {
2653 PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW while scanning\n"); 2634 PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW while scanning\n");
2654 PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running Scan >> \n\n"); 2635 PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running Scan >>\n\n");
2655 /*Abort the running scan*/ 2636 /*Abort the running scan*/
2656 WILC_TimerStop(&(pstrWFIDrv->hScanTimer), NULL); 2637 del_timer(&pstrWFIDrv->hScanTimer);
2657 if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) { 2638 if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult)
2658 Handle_ScanDone((void *)pstrWFIDrv, SCAN_EVENT_ABORTED); 2639 Handle_ScanDone(pstrWFIDrv, SCAN_EVENT_ABORTED);
2659 2640
2660 }
2661 } 2641 }
2662 2642
2663 } 2643 }
@@ -2669,7 +2649,7 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2669 2649
2670 /* Deallocate pstrRcvdGnrlAsyncInfo->pu8Buffer which was prevoisuly allocated by the sending thread */ 2650 /* Deallocate pstrRcvdGnrlAsyncInfo->pu8Buffer which was prevoisuly allocated by the sending thread */
2671 if (pstrRcvdGnrlAsyncInfo->pu8Buffer != NULL) { 2651 if (pstrRcvdGnrlAsyncInfo->pu8Buffer != NULL) {
2672 WILC_FREE(pstrRcvdGnrlAsyncInfo->pu8Buffer); 2652 kfree(pstrRcvdGnrlAsyncInfo->pu8Buffer);
2673 pstrRcvdGnrlAsyncInfo->pu8Buffer = NULL; 2653 pstrRcvdGnrlAsyncInfo->pu8Buffer = NULL;
2674 } 2654 }
2675 2655
@@ -2685,7 +2665,7 @@ static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pst
2685 * @date 2665 * @date
2686 * @version 1.0 2666 * @version 1.0
2687 */ 2667 */
2688static int Handle_Key(void *drvHandler, tstrHostIFkeyAttr *pstrHostIFkeyAttr) 2668static int Handle_Key(tstrWILC_WFIDrv *drvHandler, tstrHostIFkeyAttr *pstrHostIFkeyAttr)
2689{ 2669{
2690 s32 s32Error = WILC_SUCCESS; 2670 s32 s32Error = WILC_SUCCESS;
2691 tstrWID strWID; 2671 tstrWID strWID;
@@ -2726,7 +2706,7 @@ static int Handle_Key(void *drvHandler, tstrHostIFkeyAttr *pstrHostIFkeyAttr)
2726 strWIDList[2].s32ValueSize = sizeof(char); 2706 strWIDList[2].s32ValueSize = sizeof(char);
2727 2707
2728 2708
2729 pu8keybuf = (u8 *)WILC_MALLOC(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen); 2709 pu8keybuf = WILC_MALLOC(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen);
2730 2710
2731 2711
2732 if (pu8keybuf == NULL) { 2712 if (pu8keybuf == NULL) {
@@ -2734,11 +2714,11 @@ static int Handle_Key(void *drvHandler, tstrHostIFkeyAttr *pstrHostIFkeyAttr)
2734 return -1; 2714 return -1;
2735 } 2715 }
2736 2716
2737 WILC_memcpy(pu8keybuf, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey, 2717 memcpy(pu8keybuf, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey,
2738 pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen); 2718 pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen);
2739 2719
2740 2720
2741 WILC_FREE(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey); 2721 kfree(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey);
2742 2722
2743 strWIDList[3].u16WIDid = (u16)WID_WEP_KEY_VALUE; 2723 strWIDList[3].u16WIDid = (u16)WID_WEP_KEY_VALUE;
2744 strWIDList[3].enuWIDtype = WID_STR; 2724 strWIDList[3].enuWIDtype = WID_STR;
@@ -2747,7 +2727,7 @@ static int Handle_Key(void *drvHandler, tstrHostIFkeyAttr *pstrHostIFkeyAttr)
2747 2727
2748 2728
2749 s32Error = SendConfigPkt(SET_CFG, strWIDList, 4, true, (u32)pstrWFIDrv); 2729 s32Error = SendConfigPkt(SET_CFG, strWIDList, 4, true, (u32)pstrWFIDrv);
2750 WILC_FREE(pu8keybuf); 2730 kfree(pu8keybuf);
2751 2731
2752 2732
2753 } 2733 }
@@ -2755,19 +2735,19 @@ static int Handle_Key(void *drvHandler, tstrHostIFkeyAttr *pstrHostIFkeyAttr)
2755 2735
2756 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY) { 2736 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY) {
2757 PRINT_D(HOSTINF_DBG, "Handling WEP key\n"); 2737 PRINT_D(HOSTINF_DBG, "Handling WEP key\n");
2758 pu8keybuf = (u8 *)WILC_MALLOC(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen + 2); 2738 pu8keybuf = WILC_MALLOC(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen + 2);
2759 if (pu8keybuf == NULL) { 2739 if (pu8keybuf == NULL) {
2760 PRINT_ER("No buffer to send Key\n"); 2740 PRINT_ER("No buffer to send Key\n");
2761 return -1; 2741 return -1;
2762 } 2742 }
2763 pu8keybuf[0] = pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx; 2743 pu8keybuf[0] = pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx;
2764 2744
2765 WILC_memcpy(pu8keybuf + 1, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen, 1); 2745 memcpy(pu8keybuf + 1, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen, 1);
2766 2746
2767 WILC_memcpy(pu8keybuf + 2, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey, 2747 memcpy(pu8keybuf + 2, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey,
2768 pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen); 2748 pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen);
2769 2749
2770 WILC_FREE(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey); 2750 kfree(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey);
2771 2751
2772 strWID.u16WIDid = (u16)WID_ADD_WEP_KEY; 2752 strWID.u16WIDid = (u16)WID_ADD_WEP_KEY;
2773 strWID.enuWIDtype = WID_STR; 2753 strWID.enuWIDtype = WID_STR;
@@ -2775,7 +2755,7 @@ static int Handle_Key(void *drvHandler, tstrHostIFkeyAttr *pstrHostIFkeyAttr)
2775 strWID.s32ValueSize = pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen + 2; 2755 strWID.s32ValueSize = pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen + 2;
2776 2756
2777 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); 2757 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
2778 WILC_FREE(pu8keybuf); 2758 kfree(pu8keybuf);
2779 } else if (pstrHostIFkeyAttr->u8KeyAction & REMOVEKEY) { 2759 } else if (pstrHostIFkeyAttr->u8KeyAction & REMOVEKEY) {
2780 2760
2781 PRINT_D(HOSTINF_DBG, "Removing key\n"); 2761 PRINT_D(HOSTINF_DBG, "Removing key\n");
@@ -2803,14 +2783,14 @@ static int Handle_Key(void *drvHandler, tstrHostIFkeyAttr *pstrHostIFkeyAttr)
2803 case WPARxGtk: 2783 case WPARxGtk:
2804 #ifdef WILC_AP_EXTERNAL_MLME 2784 #ifdef WILC_AP_EXTERNAL_MLME
2805 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY_AP) { 2785 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY_AP) {
2806 pu8keybuf = (u8 *)WILC_MALLOC(RX_MIC_KEY_MSG_LEN); 2786 pu8keybuf = WILC_MALLOC(RX_MIC_KEY_MSG_LEN);
2807 if (pu8keybuf == NULL) { 2787 if (pu8keybuf == NULL) {
2808 PRINT_ER("No buffer to send RxGTK Key\n"); 2788 PRINT_ER("No buffer to send RxGTK Key\n");
2809 ret = -1; 2789 ret = -1;
2810 goto _WPARxGtk_end_case_; 2790 goto _WPARxGtk_end_case_;
2811 } 2791 }
2812 2792
2813 WILC_memset(pu8keybuf, 0, RX_MIC_KEY_MSG_LEN); 2793 memset(pu8keybuf, 0, RX_MIC_KEY_MSG_LEN);
2814 2794
2815 2795
2816 /*|----------------------------------------------------------------------------| 2796 /*|----------------------------------------------------------------------------|
@@ -2821,14 +2801,14 @@ static int Handle_Key(void *drvHandler, tstrHostIFkeyAttr *pstrHostIFkeyAttr)
2821 2801
2822 2802
2823 if (pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq != NULL) 2803 if (pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq != NULL)
2824 WILC_memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq, 8); 2804 memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq, 8);
2825 2805
2826 2806
2827 WILC_memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx, 1); 2807 memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx, 1);
2828 2808
2829 WILC_memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1); 2809 memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1);
2830 2810
2831 WILC_memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key, 2811 memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
2832 pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen); 2812 pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen);
2833 /* pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Ciphermode = 0X51; */ 2813 /* pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Ciphermode = 0X51; */
2834 strWIDList[0].u16WIDid = (u16)WID_11I_MODE; 2814 strWIDList[0].u16WIDid = (u16)WID_11I_MODE;
@@ -2843,7 +2823,7 @@ static int Handle_Key(void *drvHandler, tstrHostIFkeyAttr *pstrHostIFkeyAttr)
2843 2823
2844 s32Error = SendConfigPkt(SET_CFG, strWIDList, 2, true, (u32)pstrWFIDrv); 2824 s32Error = SendConfigPkt(SET_CFG, strWIDList, 2, true, (u32)pstrWFIDrv);
2845 2825
2846 WILC_FREE(pu8keybuf); 2826 kfree(pu8keybuf);
2847 2827
2848 /* ////////////////////////// */ 2828 /* ////////////////////////// */
2849 up(&(pstrWFIDrv->hSemTestKeyBlock)); 2829 up(&(pstrWFIDrv->hSemTestKeyBlock));
@@ -2854,14 +2834,14 @@ static int Handle_Key(void *drvHandler, tstrHostIFkeyAttr *pstrHostIFkeyAttr)
2854 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY) { 2834 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY) {
2855 PRINT_D(HOSTINF_DBG, "Handling group key(Rx) function\n"); 2835 PRINT_D(HOSTINF_DBG, "Handling group key(Rx) function\n");
2856 2836
2857 pu8keybuf = (u8 *)WILC_MALLOC(RX_MIC_KEY_MSG_LEN); 2837 pu8keybuf = WILC_MALLOC(RX_MIC_KEY_MSG_LEN);
2858 if (pu8keybuf == NULL) { 2838 if (pu8keybuf == NULL) {
2859 PRINT_ER("No buffer to send RxGTK Key\n"); 2839 PRINT_ER("No buffer to send RxGTK Key\n");
2860 ret = -1; 2840 ret = -1;
2861 goto _WPARxGtk_end_case_; 2841 goto _WPARxGtk_end_case_;
2862 } 2842 }
2863 2843
2864 WILC_memset(pu8keybuf, 0, RX_MIC_KEY_MSG_LEN); 2844 memset(pu8keybuf, 0, RX_MIC_KEY_MSG_LEN);
2865 2845
2866 2846
2867 /*|----------------------------------------------------------------------------| 2847 /*|----------------------------------------------------------------------------|
@@ -2869,18 +2849,17 @@ static int Handle_Key(void *drvHandler, tstrHostIFkeyAttr *pstrHostIFkeyAttr)
2869 * |------------|---------|-------|------------|---------------|----------------| 2849 * |------------|---------|-------|------------|---------------|----------------|
2870 | 6 bytes | 8 byte |1 byte | 1 byte | 16 bytes | 8 bytes |*/ 2850 | 6 bytes | 8 byte |1 byte | 1 byte | 16 bytes | 8 bytes |*/
2871 2851
2872 if (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTED) { 2852 if (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTED)
2873 WILC_memcpy(pu8keybuf, pstrWFIDrv->au8AssociatedBSSID, ETH_ALEN); 2853 memcpy(pu8keybuf, pstrWFIDrv->au8AssociatedBSSID, ETH_ALEN);
2874 } else { 2854 else
2875 PRINT_ER("Couldn't handle WPARxGtk while enuHostIFstate is not HOST_IF_CONNECTED \n"); 2855 PRINT_ER("Couldn't handle WPARxGtk while enuHostIFstate is not HOST_IF_CONNECTED\n");
2876 }
2877 2856
2878 WILC_memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq, 8); 2857 memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq, 8);
2879 2858
2880 WILC_memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx, 1); 2859 memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx, 1);
2881 2860
2882 WILC_memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1); 2861 memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1);
2883 WILC_memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key, 2862 memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
2884 pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen); 2863 pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen);
2885 2864
2886 strWID.u16WIDid = (u16)WID_ADD_RX_GTK; 2865 strWID.u16WIDid = (u16)WID_ADD_RX_GTK;
@@ -2890,15 +2869,15 @@ static int Handle_Key(void *drvHandler, tstrHostIFkeyAttr *pstrHostIFkeyAttr)
2890 2869
2891 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); 2870 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
2892 2871
2893 WILC_FREE(pu8keybuf); 2872 kfree(pu8keybuf);
2894 2873
2895 /* ////////////////////////// */ 2874 /* ////////////////////////// */
2896 up(&(pstrWFIDrv->hSemTestKeyBlock)); 2875 up(&(pstrWFIDrv->hSemTestKeyBlock));
2897 /* ///////////////////////// */ 2876 /* ///////////////////////// */
2898 } 2877 }
2899_WPARxGtk_end_case_: 2878_WPARxGtk_end_case_:
2900 WILC_FREE(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key); 2879 kfree(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key);
2901 WILC_FREE(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq); 2880 kfree(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq);
2902 if (ret == -1) 2881 if (ret == -1)
2903 return ret; 2882 return ret;
2904 2883
@@ -2909,7 +2888,7 @@ _WPARxGtk_end_case_:
2909 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY_AP) { 2888 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY_AP) {
2910 2889
2911 2890
2912 pu8keybuf = (u8 *)WILC_MALLOC(PTK_KEY_MSG_LEN + 1); 2891 pu8keybuf = WILC_MALLOC(PTK_KEY_MSG_LEN + 1);
2913 2892
2914 2893
2915 2894
@@ -2926,12 +2905,12 @@ _WPARxGtk_end_case_:
2926 | 6 bytes | 1 byte | 1byte | 16 bytes | 8 bytes | 8 bytes | 2905 | 6 bytes | 1 byte | 1byte | 16 bytes | 8 bytes | 8 bytes |
2927 |-----------------------------------------------------------------------------|*/ 2906 |-----------------------------------------------------------------------------|*/
2928 2907
2929 WILC_memcpy(pu8keybuf, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8macaddr, 6); /*1 bytes Key Length */ 2908 memcpy(pu8keybuf, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8macaddr, 6); /*1 bytes Key Length */
2930 2909
2931 WILC_memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx, 1); 2910 memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx, 1);
2932 WILC_memcpy(pu8keybuf + 7, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1); 2911 memcpy(pu8keybuf + 7, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1);
2933 /*16 byte TK*/ 2912 /*16 byte TK*/
2934 WILC_memcpy(pu8keybuf + 8, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key, 2913 memcpy(pu8keybuf + 8, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
2935 pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen); 2914 pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen);
2936 2915
2937 2916
@@ -2946,7 +2925,7 @@ _WPARxGtk_end_case_:
2946 strWIDList[1].s32ValueSize = PTK_KEY_MSG_LEN + 1; 2925 strWIDList[1].s32ValueSize = PTK_KEY_MSG_LEN + 1;
2947 2926
2948 s32Error = SendConfigPkt(SET_CFG, strWIDList, 2, true, (u32)pstrWFIDrv); 2927 s32Error = SendConfigPkt(SET_CFG, strWIDList, 2, true, (u32)pstrWFIDrv);
2949 WILC_FREE(pu8keybuf); 2928 kfree(pu8keybuf);
2950 2929
2951 /* ////////////////////////// */ 2930 /* ////////////////////////// */
2952 up(&(pstrWFIDrv->hSemTestKeyBlock)); 2931 up(&(pstrWFIDrv->hSemTestKeyBlock));
@@ -2956,7 +2935,7 @@ _WPARxGtk_end_case_:
2956 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY) { 2935 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY) {
2957 2936
2958 2937
2959 pu8keybuf = (u8 *)WILC_MALLOC(PTK_KEY_MSG_LEN); 2938 pu8keybuf = WILC_MALLOC(PTK_KEY_MSG_LEN);
2960 2939
2961 2940
2962 2941
@@ -2973,11 +2952,11 @@ _WPARxGtk_end_case_:
2973 | 6 bytes | 1byte | 16 bytes | 8 bytes | 8 bytes | 2952 | 6 bytes | 1byte | 16 bytes | 8 bytes | 8 bytes |
2974 |-----------------------------------------------------------------------------|*/ 2953 |-----------------------------------------------------------------------------|*/
2975 2954
2976 WILC_memcpy(pu8keybuf, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8macaddr, 6); /*1 bytes Key Length */ 2955 memcpy(pu8keybuf, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8macaddr, 6); /*1 bytes Key Length */
2977 2956
2978 WILC_memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1); 2957 memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1);
2979 /*16 byte TK*/ 2958 /*16 byte TK*/
2980 WILC_memcpy(pu8keybuf + 7, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key, 2959 memcpy(pu8keybuf + 7, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
2981 pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen); 2960 pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen);
2982 2961
2983 2962
@@ -2987,7 +2966,7 @@ _WPARxGtk_end_case_:
2987 strWID.s32ValueSize = PTK_KEY_MSG_LEN; 2966 strWID.s32ValueSize = PTK_KEY_MSG_LEN;
2988 2967
2989 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); 2968 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
2990 WILC_FREE(pu8keybuf); 2969 kfree(pu8keybuf);
2991 2970
2992 /* ////////////////////////// */ 2971 /* ////////////////////////// */
2993 up(&(pstrWFIDrv->hSemTestKeyBlock)); 2972 up(&(pstrWFIDrv->hSemTestKeyBlock));
@@ -2995,7 +2974,7 @@ _WPARxGtk_end_case_:
2995 } 2974 }
2996 2975
2997_WPAPtk_end_case_: 2976_WPAPtk_end_case_:
2998 WILC_FREE(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key); 2977 kfree(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key);
2999 if (ret == -1) 2978 if (ret == -1)
3000 return ret; 2979 return ret;
3001 2980
@@ -3006,7 +2985,7 @@ _WPAPtk_end_case_:
3006 2985
3007 PRINT_D(HOSTINF_DBG, "Handling PMKSA key\n"); 2986 PRINT_D(HOSTINF_DBG, "Handling PMKSA key\n");
3008 2987
3009 pu8keybuf = (u8 *)WILC_MALLOC((pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.numpmkid * PMKSA_KEY_LEN) + 1); 2988 pu8keybuf = WILC_MALLOC((pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.numpmkid * PMKSA_KEY_LEN) + 1);
3010 if (pu8keybuf == NULL) { 2989 if (pu8keybuf == NULL) {
3011 PRINT_ER("No buffer to send PMKSA Key\n"); 2990 PRINT_ER("No buffer to send PMKSA Key\n");
3012 return -1; 2991 return -1;
@@ -3016,8 +2995,8 @@ _WPAPtk_end_case_:
3016 2995
3017 for (i = 0; i < pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.numpmkid; i++) { 2996 for (i = 0; i < pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.numpmkid; i++) {
3018 2997
3019 WILC_memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + 1), pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].bssid, ETH_ALEN); 2998 memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + 1), pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].bssid, ETH_ALEN);
3020 WILC_memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + ETH_ALEN + 1), pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].pmkid, PMKID_LEN); 2999 memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + ETH_ALEN + 1), pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].pmkid, PMKID_LEN);
3021 } 3000 }
3022 3001
3023 strWID.u16WIDid = (u16)WID_PMKID_INFO; 3002 strWID.u16WIDid = (u16)WID_PMKID_INFO;
@@ -3027,7 +3006,7 @@ _WPAPtk_end_case_:
3027 3006
3028 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); 3007 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
3029 3008
3030 WILC_FREE(pu8keybuf); 3009 kfree(pu8keybuf);
3031 break; 3010 break;
3032 } 3011 }
3033 3012
@@ -3048,7 +3027,7 @@ _WPAPtk_end_case_:
3048 * @date 3027 * @date
3049 * @version 1.0 3028 * @version 1.0
3050 */ 3029 */
3051static void Handle_Disconnect(void *drvHandler) 3030static void Handle_Disconnect(tstrWILC_WFIDrv *drvHandler)
3052{ 3031{
3053 tstrWID strWID; 3032 tstrWID strWID;
3054 3033
@@ -3069,10 +3048,10 @@ static void Handle_Disconnect(void *drvHandler)
3069 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 3048 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
3070 3049
3071 g_obtainingIP = false; 3050 g_obtainingIP = false;
3072 host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 0, 0); 3051 host_int_set_power_mgmt(pstrWFIDrv, 0, 0);
3073 #endif 3052 #endif
3074 3053
3075 WILC_memset(u8ConnectedSSID, 0, ETH_ALEN); 3054 memset(u8ConnectedSSID, 0, ETH_ALEN);
3076 3055
3077 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv); 3056 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
3078 3057
@@ -3082,14 +3061,14 @@ static void Handle_Disconnect(void *drvHandler)
3082 } else { 3061 } else {
3083 tstrDisconnectNotifInfo strDisconnectNotifInfo; 3062 tstrDisconnectNotifInfo strDisconnectNotifInfo;
3084 3063
3085 WILC_memset(&strDisconnectNotifInfo, 0, sizeof(tstrDisconnectNotifInfo)); 3064 memset(&strDisconnectNotifInfo, 0, sizeof(tstrDisconnectNotifInfo));
3086 3065
3087 strDisconnectNotifInfo.u16reason = 0; 3066 strDisconnectNotifInfo.u16reason = 0;
3088 strDisconnectNotifInfo.ie = NULL; 3067 strDisconnectNotifInfo.ie = NULL;
3089 strDisconnectNotifInfo.ie_len = 0; 3068 strDisconnectNotifInfo.ie_len = 0;
3090 3069
3091 if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) { 3070 if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
3092 WILC_TimerStop(&(pstrWFIDrv->hScanTimer), NULL); 3071 del_timer(&pstrWFIDrv->hScanTimer);
3093 pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_ABORTED, NULL, 3072 pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_ABORTED, NULL,
3094 pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid, NULL); 3073 pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
3095 3074
@@ -3102,48 +3081,48 @@ static void Handle_Disconnect(void *drvHandler)
3102 /*Stop connect timer, if connection in progress*/ 3081 /*Stop connect timer, if connection in progress*/
3103 if (pstrWFIDrv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) { 3082 if (pstrWFIDrv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
3104 PRINT_D(HOSTINF_DBG, "Upper layer requested termination of connection\n"); 3083 PRINT_D(HOSTINF_DBG, "Upper layer requested termination of connection\n");
3105 WILC_TimerStop(&(pstrWFIDrv->hConnectTimer), NULL); 3084 del_timer(&pstrWFIDrv->hConnectTimer);
3106 } 3085 }
3107 3086
3108 pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF, NULL, 3087 pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF, NULL,
3109 0, &strDisconnectNotifInfo, pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid); 3088 0, &strDisconnectNotifInfo, pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid);
3110 } else { 3089 } else {
3111 PRINT_ER("strWILC_UsrConnReq.pfUserConnectResult = NULL \n"); 3090 PRINT_ER("strWILC_UsrConnReq.pfUserConnectResult = NULL\n");
3112 } 3091 }
3113 3092
3114 gbScanWhileConnected = false; 3093 gbScanWhileConnected = false;
3115 3094
3116 pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE; 3095 pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
3117 3096
3118 WILC_memset(pstrWFIDrv->au8AssociatedBSSID, 0, ETH_ALEN); 3097 memset(pstrWFIDrv->au8AssociatedBSSID, 0, ETH_ALEN);
3119 3098
3120 3099
3121 /* Deallocation */ 3100 /* Deallocation */
3122 pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0; 3101 pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0;
3123 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) { 3102 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) {
3124 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid); 3103 kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid);
3125 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL; 3104 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL;
3126 } 3105 }
3127 3106
3128 if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) { 3107 if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
3129 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid); 3108 kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid);
3130 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL; 3109 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL;
3131 } 3110 }
3132 3111
3133 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0; 3112 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
3134 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) { 3113 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
3135 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs); 3114 kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs);
3136 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL; 3115 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL;
3137 } 3116 }
3138 3117
3139 3118
3140 /*BugID_5137*/ 3119 /*BugID_5137*/
3141 if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) { 3120 if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
3142 WILC_FREE(gu8FlushedJoinReq); 3121 kfree(gu8FlushedJoinReq);
3143 gu8FlushedJoinReq = NULL; 3122 gu8FlushedJoinReq = NULL;
3144 } 3123 }
3145 if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) { 3124 if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
3146 WILC_FREE(gu8FlushedInfoElemAsoc); 3125 kfree(gu8FlushedInfoElemAsoc);
3147 gu8FlushedInfoElemAsoc = NULL; 3126 gu8FlushedInfoElemAsoc = NULL;
3148 } 3127 }
3149 3128
@@ -3161,7 +3140,7 @@ static void Handle_Disconnect(void *drvHandler)
3161} 3140}
3162 3141
3163 3142
3164void resolve_disconnect_aberration(void *drvHandler) 3143void resolve_disconnect_aberration(tstrWILC_WFIDrv *drvHandler)
3165{ 3144{
3166 tstrWILC_WFIDrv *pstrWFIDrv; 3145 tstrWILC_WFIDrv *pstrWFIDrv;
3167 3146
@@ -3170,10 +3149,10 @@ void resolve_disconnect_aberration(void *drvHandler)
3170 return; 3149 return;
3171 if ((pstrWFIDrv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) || (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTING)) { 3150 if ((pstrWFIDrv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) || (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTING)) {
3172 PRINT_D(HOSTINF_DBG, "\n\n<< correcting Supplicant state machine >>\n\n"); 3151 PRINT_D(HOSTINF_DBG, "\n\n<< correcting Supplicant state machine >>\n\n");
3173 host_int_disconnect((WILC_WFIDrvHandle)pstrWFIDrv, 1); 3152 host_int_disconnect(pstrWFIDrv, 1);
3174 } 3153 }
3175} 3154}
3176static s32 Switch_Log_Terminal(void *drvHandler) 3155static s32 Switch_Log_Terminal(tstrWILC_WFIDrv *drvHandler)
3177{ 3156{
3178 3157
3179 3158
@@ -3194,7 +3173,7 @@ static s32 Switch_Log_Terminal(void *drvHandler)
3194 PRINT_D(HOSTINF_DBG, "Failed to switch log terminal\n"); 3173 PRINT_D(HOSTINF_DBG, "Failed to switch log terminal\n");
3195 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE); 3174 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
3196 } else { 3175 } else {
3197 PRINT_INFO(HOSTINF_DBG, "MAC address set :: \n"); 3176 PRINT_INFO(HOSTINF_DBG, "MAC address set ::\n");
3198 3177
3199 3178
3200 } 3179 }
@@ -3217,13 +3196,14 @@ static s32 Switch_Log_Terminal(void *drvHandler)
3217 * @date 3196 * @date
3218 * @version 1.0 3197 * @version 1.0
3219 */ 3198 */
3220static s32 Handle_GetChnl(void *drvHandler) 3199static s32 Handle_GetChnl(tstrWILC_WFIDrv *drvHandler)
3221{ 3200{
3222 3201
3223 s32 s32Error = WILC_SUCCESS; 3202 s32 s32Error = WILC_SUCCESS;
3224 tstrWID strWID; 3203 tstrWID strWID;
3225 /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */ 3204 /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
3226 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler; 3205 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3206
3227 strWID.u16WIDid = (u16)WID_CURRENT_CHANNEL; 3207 strWID.u16WIDid = (u16)WID_CURRENT_CHANNEL;
3228 strWID.enuWIDtype = WID_CHAR; 3208 strWID.enuWIDtype = WID_CHAR;
3229 strWID.ps8WidVal = (s8 *)&gu8Chnl; 3209 strWID.ps8WidVal = (s8 *)&gu8Chnl;
@@ -3261,7 +3241,7 @@ static s32 Handle_GetChnl(void *drvHandler)
3261 * @date 3241 * @date
3262 * @version 1.0 3242 * @version 1.0
3263 */ 3243 */
3264static void Handle_GetRssi(void *drvHandler) 3244static void Handle_GetRssi(tstrWILC_WFIDrv *drvHandler)
3265{ 3245{
3266 s32 s32Error = WILC_SUCCESS; 3246 s32 s32Error = WILC_SUCCESS;
3267 tstrWID strWID; 3247 tstrWID strWID;
@@ -3291,7 +3271,7 @@ static void Handle_GetRssi(void *drvHandler)
3291} 3271}
3292 3272
3293 3273
3294static void Handle_GetLinkspeed(void *drvHandler) 3274static void Handle_GetLinkspeed(tstrWILC_WFIDrv *drvHandler)
3295{ 3275{
3296 s32 s32Error = WILC_SUCCESS; 3276 s32 s32Error = WILC_SUCCESS;
3297 tstrWID strWID; 3277 tstrWID strWID;
@@ -3321,7 +3301,7 @@ static void Handle_GetLinkspeed(void *drvHandler)
3321 3301
3322} 3302}
3323 3303
3324s32 Handle_GetStatistics(void *drvHandler, tstrStatistics *pstrStatistics) 3304s32 Handle_GetStatistics(tstrWILC_WFIDrv *drvHandler, tstrStatistics *pstrStatistics)
3325{ 3305{
3326 tstrWID strWIDList[5]; 3306 tstrWID strWIDList[5];
3327 uint32_t u32WidsCount = 0, s32Error = 0; 3307 uint32_t u32WidsCount = 0, s32Error = 0;
@@ -3382,7 +3362,7 @@ s32 Handle_GetStatistics(void *drvHandler, tstrStatistics *pstrStatistics)
3382 * @date 3362 * @date
3383 * @version 1.0 3363 * @version 1.0
3384 */ 3364 */
3385static s32 Handle_Get_InActiveTime(void *drvHandler, tstrHostIfStaInactiveT *strHostIfStaInactiveT) 3365static s32 Handle_Get_InActiveTime(tstrWILC_WFIDrv *drvHandler, tstrHostIfStaInactiveT *strHostIfStaInactiveT)
3386{ 3366{
3387 3367
3388 s32 s32Error = WILC_SUCCESS; 3368 s32 s32Error = WILC_SUCCESS;
@@ -3394,11 +3374,11 @@ static s32 Handle_Get_InActiveTime(void *drvHandler, tstrHostIfStaInactiveT *str
3394 strWID.u16WIDid = (u16)WID_SET_STA_MAC_INACTIVE_TIME; 3374 strWID.u16WIDid = (u16)WID_SET_STA_MAC_INACTIVE_TIME;
3395 strWID.enuWIDtype = WID_STR; 3375 strWID.enuWIDtype = WID_STR;
3396 strWID.s32ValueSize = ETH_ALEN; 3376 strWID.s32ValueSize = ETH_ALEN;
3397 strWID.ps8WidVal = (u8 *)WILC_MALLOC(strWID.s32ValueSize); 3377 strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
3398 3378
3399 3379
3400 stamac = strWID.ps8WidVal; 3380 stamac = strWID.ps8WidVal;
3401 WILC_memcpy(stamac, strHostIfStaInactiveT->mac, ETH_ALEN); 3381 memcpy(stamac, strHostIfStaInactiveT->mac, ETH_ALEN);
3402 3382
3403 3383
3404 PRINT_D(CFG80211_DBG, "SETING STA inactive time\n"); 3384 PRINT_D(CFG80211_DBG, "SETING STA inactive time\n");
@@ -3451,21 +3431,21 @@ static s32 Handle_Get_InActiveTime(void *drvHandler, tstrHostIfStaInactiveT *str
3451 * @date 3431 * @date
3452 * @version 1.0 3432 * @version 1.0
3453 */ 3433 */
3454static void Handle_AddBeacon(void *drvHandler, tstrHostIFSetBeacon *pstrSetBeaconParam) 3434static void Handle_AddBeacon(tstrWILC_WFIDrv *drvHandler, tstrHostIFSetBeacon *pstrSetBeaconParam)
3455{ 3435{
3456 s32 s32Error = WILC_SUCCESS; 3436 s32 s32Error = WILC_SUCCESS;
3457 tstrWID strWID; 3437 tstrWID strWID;
3458 u8 *pu8CurrByte; 3438 u8 *pu8CurrByte;
3459 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler; 3439 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3440
3460 PRINT_D(HOSTINF_DBG, "Adding BEACON\n"); 3441 PRINT_D(HOSTINF_DBG, "Adding BEACON\n");
3461 3442
3462 strWID.u16WIDid = (u16)WID_ADD_BEACON; 3443 strWID.u16WIDid = (u16)WID_ADD_BEACON;
3463 strWID.enuWIDtype = WID_BIN; 3444 strWID.enuWIDtype = WID_BIN;
3464 strWID.s32ValueSize = pstrSetBeaconParam->u32HeadLen + pstrSetBeaconParam->u32TailLen + 16; 3445 strWID.s32ValueSize = pstrSetBeaconParam->u32HeadLen + pstrSetBeaconParam->u32TailLen + 16;
3465 strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize); 3446 strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
3466 if (strWID.ps8WidVal == NULL) { 3447 if (strWID.ps8WidVal == NULL)
3467 WILC_ERRORREPORT(s32Error, WILC_NO_MEM); 3448 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3468 }
3469 3449
3470 pu8CurrByte = strWID.ps8WidVal; 3450 pu8CurrByte = strWID.ps8WidVal;
3471 *pu8CurrByte++ = (pstrSetBeaconParam->u32Interval & 0xFF); 3451 *pu8CurrByte++ = (pstrSetBeaconParam->u32Interval & 0xFF);
@@ -3508,9 +3488,9 @@ static void Handle_AddBeacon(void *drvHandler, tstrHostIFSetBeacon *pstrSetBeaco
3508 WILC_CATCH(s32Error) 3488 WILC_CATCH(s32Error)
3509 { 3489 {
3510 } 3490 }
3511 WILC_FREE_IF_TRUE(strWID.ps8WidVal); 3491 kfree(strWID.ps8WidVal);
3512 WILC_FREE_IF_TRUE(pstrSetBeaconParam->pu8Head); 3492 kfree(pstrSetBeaconParam->pu8Head);
3513 WILC_FREE_IF_TRUE(pstrSetBeaconParam->pu8Tail); 3493 kfree(pstrSetBeaconParam->pu8Tail);
3514} 3494}
3515 3495
3516 3496
@@ -3523,20 +3503,20 @@ static void Handle_AddBeacon(void *drvHandler, tstrHostIFSetBeacon *pstrSetBeaco
3523 * @date 3503 * @date
3524 * @version 1.0 3504 * @version 1.0
3525 */ 3505 */
3526static void Handle_DelBeacon(void *drvHandler, tstrHostIFDelBeacon *pstrDelBeacon) 3506static void Handle_DelBeacon(tstrWILC_WFIDrv *drvHandler, tstrHostIFDelBeacon *pstrDelBeacon)
3527{ 3507{
3528 s32 s32Error = WILC_SUCCESS; 3508 s32 s32Error = WILC_SUCCESS;
3529 tstrWID strWID; 3509 tstrWID strWID;
3530 u8 *pu8CurrByte; 3510 u8 *pu8CurrByte;
3531 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler; 3511 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3512
3532 strWID.u16WIDid = (u16)WID_DEL_BEACON; 3513 strWID.u16WIDid = (u16)WID_DEL_BEACON;
3533 strWID.enuWIDtype = WID_CHAR; 3514 strWID.enuWIDtype = WID_CHAR;
3534 strWID.s32ValueSize = sizeof(char); 3515 strWID.s32ValueSize = sizeof(char);
3535 strWID.ps8WidVal = &gu8DelBcn; 3516 strWID.ps8WidVal = &gu8DelBcn;
3536 3517
3537 if (strWID.ps8WidVal == NULL) { 3518 if (strWID.ps8WidVal == NULL)
3538 WILC_ERRORREPORT(s32Error, WILC_NO_MEM); 3519 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3539 }
3540 3520
3541 pu8CurrByte = strWID.ps8WidVal; 3521 pu8CurrByte = strWID.ps8WidVal;
3542 3522
@@ -3573,16 +3553,15 @@ static u32 WILC_HostIf_PackStaParam(u8 *pu8Buffer, tstrWILC_AddStaParam *pstrSta
3573 pu8CurrByte = pu8Buffer; 3553 pu8CurrByte = pu8Buffer;
3574 3554
3575 PRINT_D(HOSTINF_DBG, "Packing STA params\n"); 3555 PRINT_D(HOSTINF_DBG, "Packing STA params\n");
3576 WILC_memcpy(pu8CurrByte, pstrStationParam->au8BSSID, ETH_ALEN); 3556 memcpy(pu8CurrByte, pstrStationParam->au8BSSID, ETH_ALEN);
3577 pu8CurrByte += ETH_ALEN; 3557 pu8CurrByte += ETH_ALEN;
3578 3558
3579 *pu8CurrByte++ = pstrStationParam->u16AssocID & 0xFF; 3559 *pu8CurrByte++ = pstrStationParam->u16AssocID & 0xFF;
3580 *pu8CurrByte++ = (pstrStationParam->u16AssocID >> 8) & 0xFF; 3560 *pu8CurrByte++ = (pstrStationParam->u16AssocID >> 8) & 0xFF;
3581 3561
3582 *pu8CurrByte++ = pstrStationParam->u8NumRates; 3562 *pu8CurrByte++ = pstrStationParam->u8NumRates;
3583 if (pstrStationParam->u8NumRates > 0) { 3563 if (pstrStationParam->u8NumRates > 0)
3584 WILC_memcpy(pu8CurrByte, pstrStationParam->pu8Rates, pstrStationParam->u8NumRates); 3564 memcpy(pu8CurrByte, pstrStationParam->pu8Rates, pstrStationParam->u8NumRates);
3585 }
3586 pu8CurrByte += pstrStationParam->u8NumRates; 3565 pu8CurrByte += pstrStationParam->u8NumRates;
3587 3566
3588 *pu8CurrByte++ = pstrStationParam->bIsHTSupported; 3567 *pu8CurrByte++ = pstrStationParam->bIsHTSupported;
@@ -3590,7 +3569,7 @@ static u32 WILC_HostIf_PackStaParam(u8 *pu8Buffer, tstrWILC_AddStaParam *pstrSta
3590 *pu8CurrByte++ = (pstrStationParam->u16HTCapInfo >> 8) & 0xFF; 3569 *pu8CurrByte++ = (pstrStationParam->u16HTCapInfo >> 8) & 0xFF;
3591 3570
3592 *pu8CurrByte++ = pstrStationParam->u8AmpduParams; 3571 *pu8CurrByte++ = pstrStationParam->u8AmpduParams;
3593 WILC_memcpy(pu8CurrByte, pstrStationParam->au8SuppMCsSet, WILC_SUPP_MCS_SET_SIZE); 3572 memcpy(pu8CurrByte, pstrStationParam->au8SuppMCsSet, WILC_SUPP_MCS_SET_SIZE);
3594 pu8CurrByte += WILC_SUPP_MCS_SET_SIZE; 3573 pu8CurrByte += WILC_SUPP_MCS_SET_SIZE;
3595 3574
3596 *pu8CurrByte++ = pstrStationParam->u16HTExtParams & 0xFF; 3575 *pu8CurrByte++ = pstrStationParam->u16HTExtParams & 0xFF;
@@ -3621,21 +3600,21 @@ static u32 WILC_HostIf_PackStaParam(u8 *pu8Buffer, tstrWILC_AddStaParam *pstrSta
3621 * @date 3600 * @date
3622 * @version 1.0 3601 * @version 1.0
3623 */ 3602 */
3624static void Handle_AddStation(void *drvHandler, tstrWILC_AddStaParam *pstrStationParam) 3603static void Handle_AddStation(tstrWILC_WFIDrv *drvHandler, tstrWILC_AddStaParam *pstrStationParam)
3625{ 3604{
3626 s32 s32Error = WILC_SUCCESS; 3605 s32 s32Error = WILC_SUCCESS;
3627 tstrWID strWID; 3606 tstrWID strWID;
3628 u8 *pu8CurrByte; 3607 u8 *pu8CurrByte;
3629 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler; 3608 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3609
3630 PRINT_D(HOSTINF_DBG, "Handling add station\n"); 3610 PRINT_D(HOSTINF_DBG, "Handling add station\n");
3631 strWID.u16WIDid = (u16)WID_ADD_STA; 3611 strWID.u16WIDid = (u16)WID_ADD_STA;
3632 strWID.enuWIDtype = WID_BIN; 3612 strWID.enuWIDtype = WID_BIN;
3633 strWID.s32ValueSize = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates; 3613 strWID.s32ValueSize = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates;
3634 3614
3635 strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize); 3615 strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
3636 if (strWID.ps8WidVal == NULL) { 3616 if (strWID.ps8WidVal == NULL)
3637 WILC_ERRORREPORT(s32Error, WILC_NO_MEM); 3617 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3638 }
3639 3618
3640 pu8CurrByte = strWID.ps8WidVal; 3619 pu8CurrByte = strWID.ps8WidVal;
3641 pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam); 3620 pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
@@ -3651,8 +3630,8 @@ static void Handle_AddStation(void *drvHandler, tstrWILC_AddStaParam *pstrStatio
3651 WILC_CATCH(s32Error) 3630 WILC_CATCH(s32Error)
3652 { 3631 {
3653 } 3632 }
3654 WILC_FREE_IF_TRUE(pstrStationParam->pu8Rates); 3633 kfree(pstrStationParam->pu8Rates);
3655 WILC_FREE_IF_TRUE(strWID.ps8WidVal); 3634 kfree(strWID.ps8WidVal);
3656} 3635}
3657 3636
3658/** 3637/**
@@ -3664,24 +3643,25 @@ static void Handle_AddStation(void *drvHandler, tstrWILC_AddStaParam *pstrStatio
3664 * @date 3643 * @date
3665 * @version 1.0 3644 * @version 1.0
3666 */ 3645 */
3667static void Handle_DelAllSta(void *drvHandler, tstrHostIFDelAllSta *pstrDelAllStaParam) 3646static void Handle_DelAllSta(tstrWILC_WFIDrv *drvHandler, tstrHostIFDelAllSta *pstrDelAllStaParam)
3668{ 3647{
3669 s32 s32Error = WILC_SUCCESS; 3648 s32 s32Error = WILC_SUCCESS;
3649
3670 tstrWID strWID; 3650 tstrWID strWID;
3671 u8 *pu8CurrByte; 3651 u8 *pu8CurrByte;
3672 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler; 3652 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3673 u8 i; 3653 u8 i;
3674 u8 au8Zero_Buff[6] = {0}; 3654 u8 au8Zero_Buff[6] = {0};
3655
3675 strWID.u16WIDid = (u16)WID_DEL_ALL_STA; 3656 strWID.u16WIDid = (u16)WID_DEL_ALL_STA;
3676 strWID.enuWIDtype = WID_STR; 3657 strWID.enuWIDtype = WID_STR;
3677 strWID.s32ValueSize = (pstrDelAllStaParam->u8Num_AssocSta * ETH_ALEN) + 1; 3658 strWID.s32ValueSize = (pstrDelAllStaParam->u8Num_AssocSta * ETH_ALEN) + 1;
3678 3659
3679 PRINT_D(HOSTINF_DBG, "Handling delete station \n"); 3660 PRINT_D(HOSTINF_DBG, "Handling delete station\n");
3680 3661
3681 strWID.ps8WidVal = WILC_MALLOC((pstrDelAllStaParam->u8Num_AssocSta * ETH_ALEN) + 1); 3662 strWID.ps8WidVal = WILC_MALLOC((pstrDelAllStaParam->u8Num_AssocSta * ETH_ALEN) + 1);
3682 if (strWID.ps8WidVal == NULL) { 3663 if (strWID.ps8WidVal == NULL)
3683 WILC_ERRORREPORT(s32Error, WILC_NO_MEM); 3664 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3684 }
3685 3665
3686 pu8CurrByte = strWID.ps8WidVal; 3666 pu8CurrByte = strWID.ps8WidVal;
3687 3667
@@ -3689,7 +3669,7 @@ static void Handle_DelAllSta(void *drvHandler, tstrHostIFDelAllSta *pstrDelAllSt
3689 3669
3690 for (i = 0; i < MAX_NUM_STA; i++) { 3670 for (i = 0; i < MAX_NUM_STA; i++) {
3691 if (memcmp(pstrDelAllStaParam->au8Sta_DelAllSta[i], au8Zero_Buff, ETH_ALEN)) 3671 if (memcmp(pstrDelAllStaParam->au8Sta_DelAllSta[i], au8Zero_Buff, ETH_ALEN))
3692 WILC_memcpy(pu8CurrByte, pstrDelAllStaParam->au8Sta_DelAllSta[i], ETH_ALEN); 3672 memcpy(pu8CurrByte, pstrDelAllStaParam->au8Sta_DelAllSta[i], ETH_ALEN);
3693 else 3673 else
3694 continue; 3674 continue;
3695 3675
@@ -3700,14 +3680,14 @@ static void Handle_DelAllSta(void *drvHandler, tstrHostIFDelAllSta *pstrDelAllSt
3700 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); 3680 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
3701 if (s32Error) { 3681 if (s32Error) {
3702 3682
3703 PRINT_ER("Failed to send add station config packe\n"); 3683 PRINT_ER("Failed to send add station config packet\n");
3704 WILC_ERRORREPORT(s32Error, WILC_FAIL); 3684 WILC_ERRORREPORT(s32Error, WILC_FAIL);
3705 } 3685 }
3706 3686
3707 WILC_CATCH(s32Error) 3687 WILC_CATCH(s32Error)
3708 { 3688 {
3709 } 3689 }
3710 WILC_FREE_IF_TRUE(strWID.ps8WidVal); 3690 kfree(strWID.ps8WidVal);
3711 3691
3712 up(&hWaitResponse); 3692 up(&hWaitResponse);
3713} 3693}
@@ -3722,7 +3702,7 @@ static void Handle_DelAllSta(void *drvHandler, tstrHostIFDelAllSta *pstrDelAllSt
3722 * @date 3702 * @date
3723 * @version 1.0 3703 * @version 1.0
3724 */ 3704 */
3725static void Handle_DelStation(void *drvHandler, tstrHostIFDelSta *pstrDelStaParam) 3705static void Handle_DelStation(tstrWILC_WFIDrv *drvHandler, tstrHostIFDelSta *pstrDelStaParam)
3726{ 3706{
3727 s32 s32Error = WILC_SUCCESS; 3707 s32 s32Error = WILC_SUCCESS;
3728 tstrWID strWID; 3708 tstrWID strWID;
@@ -3733,29 +3713,28 @@ static void Handle_DelStation(void *drvHandler, tstrHostIFDelSta *pstrDelStaPara
3733 strWID.enuWIDtype = WID_BIN; 3713 strWID.enuWIDtype = WID_BIN;
3734 strWID.s32ValueSize = ETH_ALEN; 3714 strWID.s32ValueSize = ETH_ALEN;
3735 3715
3736 PRINT_D(HOSTINF_DBG, "Handling delete station \n"); 3716 PRINT_D(HOSTINF_DBG, "Handling delete station\n");
3737 3717
3738 strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize); 3718 strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
3739 if (strWID.ps8WidVal == NULL) { 3719 if (strWID.ps8WidVal == NULL)
3740 WILC_ERRORREPORT(s32Error, WILC_NO_MEM); 3720 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3741 }
3742 3721
3743 pu8CurrByte = strWID.ps8WidVal; 3722 pu8CurrByte = strWID.ps8WidVal;
3744 3723
3745 WILC_memcpy(pu8CurrByte, pstrDelStaParam->au8MacAddr, ETH_ALEN); 3724 memcpy(pu8CurrByte, pstrDelStaParam->au8MacAddr, ETH_ALEN);
3746 3725
3747 /*Sending Cfg*/ 3726 /*Sending Cfg*/
3748 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv); 3727 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
3749 if (s32Error) { 3728 if (s32Error) {
3750 3729
3751 PRINT_ER("Failed to send add station config packe\n"); 3730 PRINT_ER("Failed to send add station config packet\n");
3752 WILC_ERRORREPORT(s32Error, WILC_FAIL); 3731 WILC_ERRORREPORT(s32Error, WILC_FAIL);
3753 } 3732 }
3754 3733
3755 WILC_CATCH(s32Error) 3734 WILC_CATCH(s32Error)
3756 { 3735 {
3757 } 3736 }
3758 WILC_FREE_IF_TRUE(strWID.ps8WidVal); 3737 kfree(strWID.ps8WidVal);
3759} 3738}
3760 3739
3761 3740
@@ -3768,7 +3747,7 @@ static void Handle_DelStation(void *drvHandler, tstrHostIFDelSta *pstrDelStaPara
3768 * @date 3747 * @date
3769 * @version 1.0 3748 * @version 1.0
3770 */ 3749 */
3771static void Handle_EditStation(void *drvHandler, tstrWILC_AddStaParam *pstrStationParam) 3750static void Handle_EditStation(tstrWILC_WFIDrv *drvHandler, tstrWILC_AddStaParam *pstrStationParam)
3772{ 3751{
3773 s32 s32Error = WILC_SUCCESS; 3752 s32 s32Error = WILC_SUCCESS;
3774 tstrWID strWID; 3753 tstrWID strWID;
@@ -3781,9 +3760,8 @@ static void Handle_EditStation(void *drvHandler, tstrWILC_AddStaParam *pstrStati
3781 3760
3782 PRINT_D(HOSTINF_DBG, "Handling edit station\n"); 3761 PRINT_D(HOSTINF_DBG, "Handling edit station\n");
3783 strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize); 3762 strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
3784 if (strWID.ps8WidVal == NULL) { 3763 if (strWID.ps8WidVal == NULL)
3785 WILC_ERRORREPORT(s32Error, WILC_NO_MEM); 3764 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3786 }
3787 3765
3788 pu8CurrByte = strWID.ps8WidVal; 3766 pu8CurrByte = strWID.ps8WidVal;
3789 pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam); 3767 pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
@@ -3799,8 +3777,8 @@ static void Handle_EditStation(void *drvHandler, tstrWILC_AddStaParam *pstrStati
3799 WILC_CATCH(s32Error) 3777 WILC_CATCH(s32Error)
3800 { 3778 {
3801 } 3779 }
3802 WILC_FREE_IF_TRUE(pstrStationParam->pu8Rates); 3780 kfree(pstrStationParam->pu8Rates);
3803 WILC_FREE_IF_TRUE(strWID.ps8WidVal); 3781 kfree(strWID.ps8WidVal);
3804} 3782}
3805#endif /*WILC_AP_EXTERNAL_MLME*/ 3783#endif /*WILC_AP_EXTERNAL_MLME*/
3806 3784
@@ -3814,7 +3792,7 @@ static void Handle_EditStation(void *drvHandler, tstrWILC_AddStaParam *pstrStati
3814 * @date 3792 * @date
3815 * @version 1.0 3793 * @version 1.0
3816 */ 3794 */
3817static int Handle_RemainOnChan(void *drvHandler, tstrHostIfRemainOnChan *pstrHostIfRemainOnChan) 3795static int Handle_RemainOnChan(tstrWILC_WFIDrv *drvHandler, tstrHostIfRemainOnChan *pstrHostIfRemainOnChan)
3818{ 3796{
3819 s32 s32Error = WILC_SUCCESS; 3797 s32 s32Error = WILC_SUCCESS;
3820 u8 u8remain_on_chan_flag; 3798 u8 u8remain_on_chan_flag;
@@ -3856,30 +3834,30 @@ static int Handle_RemainOnChan(void *drvHandler, tstrHostIfRemainOnChan *pstrHos
3856 strWID.u16WIDid = (u16)WID_REMAIN_ON_CHAN; 3834 strWID.u16WIDid = (u16)WID_REMAIN_ON_CHAN;
3857 strWID.enuWIDtype = WID_STR; 3835 strWID.enuWIDtype = WID_STR;
3858 strWID.s32ValueSize = 2; 3836 strWID.s32ValueSize = 2;
3859 strWID.ps8WidVal = (s8 *)WILC_MALLOC(strWID.s32ValueSize); 3837 strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
3860 3838
3861 if (strWID.ps8WidVal == NULL) { 3839 if (strWID.ps8WidVal == NULL)
3862 WILC_ERRORREPORT(s32Error, WILC_NO_MEM); 3840 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3863 }
3864 3841
3865 strWID.ps8WidVal[0] = u8remain_on_chan_flag; 3842 strWID.ps8WidVal[0] = u8remain_on_chan_flag;
3866 strWID.ps8WidVal[1] = (s8)pstrHostIfRemainOnChan->u16Channel; 3843 strWID.ps8WidVal[1] = (s8)pstrHostIfRemainOnChan->u16Channel;
3867 3844
3868 /*Sending Cfg*/ 3845 /*Sending Cfg*/
3869 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); 3846 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
3870 if (s32Error != WILC_SUCCESS) { 3847 if (s32Error != WILC_SUCCESS)
3871 PRINT_ER("Failed to set remain on channel\n"); 3848 PRINT_ER("Failed to set remain on channel\n");
3872 }
3873 3849
3874 WILC_CATCH(-1) 3850 WILC_CATCH(-1)
3875 { 3851 {
3876 P2P_LISTEN_STATE = 1; 3852 P2P_LISTEN_STATE = 1;
3877 WILC_TimerStart(&(pstrWFIDrv->hRemainOnChannel), pstrHostIfRemainOnChan->u32duration, (void *)pstrWFIDrv, NULL); 3853 pstrWFIDrv->hRemainOnChannel.data = (unsigned long)pstrWFIDrv;
3854 mod_timer(&pstrWFIDrv->hRemainOnChannel,
3855 jiffies +
3856 msecs_to_jiffies(pstrHostIfRemainOnChan->u32duration));
3878 3857
3879 /*Calling CFG ready_on_channel*/ 3858 /*Calling CFG ready_on_channel*/
3880 if (pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanReady) { 3859 if (pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanReady)
3881 pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanReady(pstrWFIDrv->strHostIfRemainOnChan.pVoid); 3860 pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanReady(pstrWFIDrv->strHostIfRemainOnChan.pVoid);
3882 }
3883 3861
3884 if (pstrWFIDrv->u8RemainOnChan_pendingreq) 3862 if (pstrWFIDrv->u8RemainOnChan_pendingreq)
3885 pstrWFIDrv->u8RemainOnChan_pendingreq = 0; 3863 pstrWFIDrv->u8RemainOnChan_pendingreq = 0;
@@ -3896,7 +3874,7 @@ static int Handle_RemainOnChan(void *drvHandler, tstrHostIfRemainOnChan *pstrHos
3896 * @date 3874 * @date
3897 * @version 1.0 3875 * @version 1.0
3898 */ 3876 */
3899static int Handle_RegisterFrame(void *drvHandler, tstrHostIfRegisterFrame *pstrHostIfRegisterFrame) 3877static int Handle_RegisterFrame(tstrWILC_WFIDrv *drvHandler, tstrHostIfRegisterFrame *pstrHostIfRegisterFrame)
3900{ 3878{
3901 s32 s32Error = WILC_SUCCESS; 3879 s32 s32Error = WILC_SUCCESS;
3902 tstrWID strWID; 3880 tstrWID strWID;
@@ -3909,15 +3887,14 @@ static int Handle_RegisterFrame(void *drvHandler, tstrHostIfRegisterFrame *pstrH
3909 strWID.u16WIDid = (u16)WID_REGISTER_FRAME; 3887 strWID.u16WIDid = (u16)WID_REGISTER_FRAME;
3910 strWID.enuWIDtype = WID_STR; 3888 strWID.enuWIDtype = WID_STR;
3911 strWID.ps8WidVal = WILC_MALLOC(sizeof(u16) + 2); 3889 strWID.ps8WidVal = WILC_MALLOC(sizeof(u16) + 2);
3912 if (strWID.ps8WidVal == NULL) { 3890 if (strWID.ps8WidVal == NULL)
3913 WILC_ERRORREPORT(s32Error, WILC_NO_MEM); 3891 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3914 }
3915 3892
3916 pu8CurrByte = strWID.ps8WidVal; 3893 pu8CurrByte = strWID.ps8WidVal;
3917 3894
3918 *pu8CurrByte++ = pstrHostIfRegisterFrame->bReg; 3895 *pu8CurrByte++ = pstrHostIfRegisterFrame->bReg;
3919 *pu8CurrByte++ = pstrHostIfRegisterFrame->u8Regid; 3896 *pu8CurrByte++ = pstrHostIfRegisterFrame->u8Regid;
3920 WILC_memcpy(pu8CurrByte, &(pstrHostIfRegisterFrame->u16FrameType), sizeof(u16)); 3897 memcpy(pu8CurrByte, &(pstrHostIfRegisterFrame->u16FrameType), sizeof(u16));
3921 3898
3922 3899
3923 strWID.s32ValueSize = sizeof(u16) + 2; 3900 strWID.s32ValueSize = sizeof(u16) + 2;
@@ -3949,7 +3926,7 @@ static int Handle_RegisterFrame(void *drvHandler, tstrHostIfRegisterFrame *pstrH
3949 * @version 1.0 3926 * @version 1.0
3950 */ 3927 */
3951#define FALSE_FRMWR_CHANNEL 100 3928#define FALSE_FRMWR_CHANNEL 100
3952static u32 Handle_ListenStateExpired(void *drvHandler, tstrHostIfRemainOnChan *pstrHostIfRemainOnChan) 3929static u32 Handle_ListenStateExpired(tstrWILC_WFIDrv *drvHandler, tstrHostIfRemainOnChan *pstrHostIfRemainOnChan)
3953{ 3930{
3954 u8 u8remain_on_chan_flag; 3931 u8 u8remain_on_chan_flag;
3955 tstrWID strWID; 3932 tstrWID strWID;
@@ -3968,9 +3945,8 @@ static u32 Handle_ListenStateExpired(void *drvHandler, tstrHostIfRemainOnChan *p
3968 strWID.s32ValueSize = 2; 3945 strWID.s32ValueSize = 2;
3969 strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize); 3946 strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
3970 3947
3971 if (strWID.ps8WidVal == NULL) { 3948 if (strWID.ps8WidVal == NULL)
3972 PRINT_ER("Failed to allocate memory\n"); 3949 PRINT_ER("Failed to allocate memory\n");
3973 }
3974 3950
3975 strWID.ps8WidVal[0] = u8remain_on_chan_flag; 3951 strWID.ps8WidVal[0] = u8remain_on_chan_flag;
3976 strWID.ps8WidVal[1] = FALSE_FRMWR_CHANNEL; 3952 strWID.ps8WidVal[1] = FALSE_FRMWR_CHANNEL;
@@ -4006,25 +3982,24 @@ _done_:
4006 * @date 3982 * @date
4007 * @version 1.0 3983 * @version 1.0
4008 */ 3984 */
4009static void ListenTimerCB(void *pvArg) 3985static void ListenTimerCB(unsigned long arg)
4010{ 3986{
4011 s32 s32Error = WILC_SUCCESS; 3987 s32 s32Error = WILC_SUCCESS;
4012 tstrHostIFmsg strHostIFmsg; 3988 tstrHostIFmsg strHostIFmsg;
4013 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)pvArg; 3989 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)arg;
4014 /*Stopping remain-on-channel timer*/ 3990 /*Stopping remain-on-channel timer*/
4015 WILC_TimerStop(&(pstrWFIDrv->hRemainOnChannel), NULL); 3991 del_timer(&pstrWFIDrv->hRemainOnChannel);
4016 3992
4017 /* prepare the Timer Callback message */ 3993 /* prepare the Timer Callback message */
4018 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 3994 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4019 strHostIFmsg.u16MsgId = HOST_IF_MSG_LISTEN_TIMER_FIRED; 3995 strHostIFmsg.u16MsgId = HOST_IF_MSG_LISTEN_TIMER_FIRED;
4020 strHostIFmsg.drvHandler = pstrWFIDrv; 3996 strHostIFmsg.drvHandler = pstrWFIDrv;
4021 strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u32ListenSessionID = pstrWFIDrv->strHostIfRemainOnChan.u32ListenSessionID; 3997 strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u32ListenSessionID = pstrWFIDrv->strHostIfRemainOnChan.u32ListenSessionID;
4022 3998
4023 /* send the message */ 3999 /* send the message */
4024 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 4000 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
4025 if (s32Error) { 4001 if (s32Error)
4026 WILC_ERRORREPORT(s32Error, s32Error); 4002 WILC_ERRORREPORT(s32Error, s32Error);
4027 }
4028 WILC_CATCH(s32Error) 4003 WILC_CATCH(s32Error)
4029 { 4004 {
4030 4005
@@ -4042,19 +4017,19 @@ static void ListenTimerCB(void *pvArg)
4042 * @date 4017 * @date
4043 * @version 1.0 4018 * @version 1.0
4044 */ 4019 */
4045static void Handle_PowerManagement(void *drvHandler, tstrHostIfPowerMgmtParam *strPowerMgmtParam) 4020static void Handle_PowerManagement(tstrWILC_WFIDrv *drvHandler, tstrHostIfPowerMgmtParam *strPowerMgmtParam)
4046{ 4021{
4047 s32 s32Error = WILC_SUCCESS; 4022 s32 s32Error = WILC_SUCCESS;
4048 tstrWID strWID; 4023 tstrWID strWID;
4049 s8 s8PowerMode; 4024 s8 s8PowerMode;
4050 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler; 4025 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
4026
4051 strWID.u16WIDid = (u16)WID_POWER_MANAGEMENT; 4027 strWID.u16WIDid = (u16)WID_POWER_MANAGEMENT;
4052 4028
4053 if (strPowerMgmtParam->bIsEnabled == true) { 4029 if (strPowerMgmtParam->bIsEnabled == true)
4054 s8PowerMode = MIN_FAST_PS; 4030 s8PowerMode = MIN_FAST_PS;
4055 } else { 4031 else
4056 s8PowerMode = NO_POWERSAVE; 4032 s8PowerMode = NO_POWERSAVE;
4057 }
4058 PRINT_D(HOSTINF_DBG, "Handling power mgmt to %d\n", s8PowerMode); 4033 PRINT_D(HOSTINF_DBG, "Handling power mgmt to %d\n", s8PowerMode);
4059 strWID.ps8WidVal = &s8PowerMode; 4034 strWID.ps8WidVal = &s8PowerMode;
4060 strWID.s32ValueSize = sizeof(char); 4035 strWID.s32ValueSize = sizeof(char);
@@ -4083,7 +4058,7 @@ static void Handle_PowerManagement(void *drvHandler, tstrHostIfPowerMgmtParam *s
4083 * @date 4058 * @date
4084 * @version 1.0 4059 * @version 1.0
4085 */ 4060 */
4086static void Handle_SetMulticastFilter(void *drvHandler, tstrHostIFSetMulti *strHostIfSetMulti) 4061static void Handle_SetMulticastFilter(tstrWILC_WFIDrv *drvHandler, tstrHostIFSetMulti *strHostIfSetMulti)
4087{ 4062{
4088 s32 s32Error = WILC_SUCCESS; 4063 s32 s32Error = WILC_SUCCESS;
4089 tstrWID strWID; 4064 tstrWID strWID;
@@ -4095,9 +4070,8 @@ static void Handle_SetMulticastFilter(void *drvHandler, tstrHostIFSetMulti *strH
4095 strWID.enuWIDtype = WID_BIN; 4070 strWID.enuWIDtype = WID_BIN;
4096 strWID.s32ValueSize = sizeof(tstrHostIFSetMulti) + ((strHostIfSetMulti->u32count) * ETH_ALEN); 4071 strWID.s32ValueSize = sizeof(tstrHostIFSetMulti) + ((strHostIfSetMulti->u32count) * ETH_ALEN);
4097 strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize); 4072 strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
4098 if (strWID.ps8WidVal == NULL) { 4073 if (strWID.ps8WidVal == NULL)
4099 WILC_ERRORREPORT(s32Error, WILC_NO_MEM); 4074 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
4100 }
4101 4075
4102 pu8CurrByte = strWID.ps8WidVal; 4076 pu8CurrByte = strWID.ps8WidVal;
4103 *pu8CurrByte++ = (strHostIfSetMulti->bIsEnabled & 0xFF); 4077 *pu8CurrByte++ = (strHostIfSetMulti->bIsEnabled & 0xFF);
@@ -4123,7 +4097,7 @@ static void Handle_SetMulticastFilter(void *drvHandler, tstrHostIFSetMulti *strH
4123 WILC_CATCH(s32Error) 4097 WILC_CATCH(s32Error)
4124 { 4098 {
4125 } 4099 }
4126 WILC_FREE_IF_TRUE(strWID.ps8WidVal); 4100 kfree(strWID.ps8WidVal);
4127 4101
4128} 4102}
4129 4103
@@ -4138,7 +4112,7 @@ static void Handle_SetMulticastFilter(void *drvHandler, tstrHostIFSetMulti *strH
4138 * @date Feb. 2014 4112 * @date Feb. 2014
4139 * @version 9.0 4113 * @version 9.0
4140 */ 4114 */
4141static s32 Handle_AddBASession(void *drvHandler, tstrHostIfBASessionInfo *strHostIfBASessionInfo) 4115static s32 Handle_AddBASession(tstrWILC_WFIDrv *drvHandler, tstrHostIfBASessionInfo *strHostIfBASessionInfo)
4142{ 4116{
4143 s32 s32Error = WILC_SUCCESS; 4117 s32 s32Error = WILC_SUCCESS;
4144 tstrWID strWID; 4118 tstrWID strWID;
@@ -4146,7 +4120,7 @@ static s32 Handle_AddBASession(void *drvHandler, tstrHostIfBASessionInfo *strHos
4146 char *ptr = NULL; 4120 char *ptr = NULL;
4147 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler; 4121 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
4148 4122
4149 PRINT_D(HOSTINF_DBG, "Opening Block Ack session with\nBSSID = %.2x:%.2x:%.2x \nTID=%d \nBufferSize == %d \nSessionTimeOut = %d\n", 4123 PRINT_D(HOSTINF_DBG, "Opening Block Ack session with\nBSSID = %.2x:%.2x:%.2x\nTID=%d\nBufferSize == %d\nSessionTimeOut = %d\n",
4150 strHostIfBASessionInfo->au8Bssid[0], 4124 strHostIfBASessionInfo->au8Bssid[0],
4151 strHostIfBASessionInfo->au8Bssid[1], 4125 strHostIfBASessionInfo->au8Bssid[1],
4152 strHostIfBASessionInfo->au8Bssid[2], 4126 strHostIfBASessionInfo->au8Bssid[2],
@@ -4156,14 +4130,14 @@ static s32 Handle_AddBASession(void *drvHandler, tstrHostIfBASessionInfo *strHos
4156 4130
4157 strWID.u16WIDid = (u16)WID_11E_P_ACTION_REQ; 4131 strWID.u16WIDid = (u16)WID_11E_P_ACTION_REQ;
4158 strWID.enuWIDtype = WID_STR; 4132 strWID.enuWIDtype = WID_STR;
4159 strWID.ps8WidVal = (u8 *)WILC_MALLOC(BLOCK_ACK_REQ_SIZE); 4133 strWID.ps8WidVal = WILC_MALLOC(BLOCK_ACK_REQ_SIZE);
4160 strWID.s32ValueSize = BLOCK_ACK_REQ_SIZE; 4134 strWID.s32ValueSize = BLOCK_ACK_REQ_SIZE;
4161 ptr = strWID.ps8WidVal; 4135 ptr = strWID.ps8WidVal;
4162 /* *ptr++ = 0x14; */ 4136 /* *ptr++ = 0x14; */
4163 *ptr++ = 0x14; 4137 *ptr++ = 0x14;
4164 *ptr++ = 0x3; 4138 *ptr++ = 0x3;
4165 *ptr++ = 0x0; 4139 *ptr++ = 0x0;
4166 WILC_memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN); 4140 memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
4167 ptr += ETH_ALEN; 4141 ptr += ETH_ALEN;
4168 *ptr++ = strHostIfBASessionInfo->u8Ted; 4142 *ptr++ = strHostIfBASessionInfo->u8Ted;
4169 /* BA Policy*/ 4143 /* BA Policy*/
@@ -4195,7 +4169,7 @@ static s32 Handle_AddBASession(void *drvHandler, tstrHostIfBASessionInfo *strHos
4195 *ptr++ = 15; 4169 *ptr++ = 15;
4196 *ptr++ = 7; 4170 *ptr++ = 7;
4197 *ptr++ = 0x2; 4171 *ptr++ = 0x2;
4198 WILC_memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN); 4172 memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
4199 ptr += ETH_ALEN; 4173 ptr += ETH_ALEN;
4200 /* TID*/ 4174 /* TID*/
4201 *ptr++ = strHostIfBASessionInfo->u8Ted; 4175 *ptr++ = strHostIfBASessionInfo->u8Ted;
@@ -4209,7 +4183,7 @@ static s32 Handle_AddBASession(void *drvHandler, tstrHostIfBASessionInfo *strHos
4209 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); 4183 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
4210 4184
4211 if (strWID.ps8WidVal != NULL) 4185 if (strWID.ps8WidVal != NULL)
4212 WILC_FREE(strWID.ps8WidVal); 4186 kfree(strWID.ps8WidVal);
4213 4187
4214 return s32Error; 4188 return s32Error;
4215 4189
@@ -4226,14 +4200,14 @@ static s32 Handle_AddBASession(void *drvHandler, tstrHostIfBASessionInfo *strHos
4226 * @date Feb. 2013 4200 * @date Feb. 2013
4227 * @version 9.0 4201 * @version 9.0
4228 */ 4202 */
4229static s32 Handle_DelBASession(void *drvHandler, tstrHostIfBASessionInfo *strHostIfBASessionInfo) 4203static s32 Handle_DelBASession(tstrWILC_WFIDrv *drvHandler, tstrHostIfBASessionInfo *strHostIfBASessionInfo)
4230{ 4204{
4231 s32 s32Error = WILC_SUCCESS; 4205 s32 s32Error = WILC_SUCCESS;
4232 tstrWID strWID; 4206 tstrWID strWID;
4233 char *ptr = NULL; 4207 char *ptr = NULL;
4234 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler; 4208 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
4235 4209
4236 PRINT_D(GENERIC_DBG, "Delete Block Ack session with\nBSSID = %.2x:%.2x:%.2x \nTID=%d\n", 4210 PRINT_D(GENERIC_DBG, "Delete Block Ack session with\nBSSID = %.2x:%.2x:%.2x\nTID=%d\n",
4237 strHostIfBASessionInfo->au8Bssid[0], 4211 strHostIfBASessionInfo->au8Bssid[0],
4238 strHostIfBASessionInfo->au8Bssid[1], 4212 strHostIfBASessionInfo->au8Bssid[1],
4239 strHostIfBASessionInfo->au8Bssid[2], 4213 strHostIfBASessionInfo->au8Bssid[2],
@@ -4241,14 +4215,14 @@ static s32 Handle_DelBASession(void *drvHandler, tstrHostIfBASessionInfo *strHos
4241 4215
4242 strWID.u16WIDid = (u16)WID_11E_P_ACTION_REQ; 4216 strWID.u16WIDid = (u16)WID_11E_P_ACTION_REQ;
4243 strWID.enuWIDtype = WID_STR; 4217 strWID.enuWIDtype = WID_STR;
4244 strWID.ps8WidVal = (u8 *)WILC_MALLOC(BLOCK_ACK_REQ_SIZE); 4218 strWID.ps8WidVal = WILC_MALLOC(BLOCK_ACK_REQ_SIZE);
4245 strWID.s32ValueSize = BLOCK_ACK_REQ_SIZE; 4219 strWID.s32ValueSize = BLOCK_ACK_REQ_SIZE;
4246 ptr = strWID.ps8WidVal; 4220 ptr = strWID.ps8WidVal;
4247 /* *ptr++ = 0x14; */ 4221 /* *ptr++ = 0x14; */
4248 *ptr++ = 0x14; 4222 *ptr++ = 0x14;
4249 *ptr++ = 0x3; 4223 *ptr++ = 0x3;
4250 *ptr++ = 0x2; 4224 *ptr++ = 0x2;
4251 WILC_memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN); 4225 memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
4252 ptr += ETH_ALEN; 4226 ptr += ETH_ALEN;
4253 *ptr++ = strHostIfBASessionInfo->u8Ted; 4227 *ptr++ = strHostIfBASessionInfo->u8Ted;
4254 /* BA direction = recipent*/ 4228 /* BA direction = recipent*/
@@ -4269,7 +4243,7 @@ static s32 Handle_DelBASession(void *drvHandler, tstrHostIfBASessionInfo *strHos
4269 *ptr++ = 15; 4243 *ptr++ = 15;
4270 *ptr++ = 7; 4244 *ptr++ = 7;
4271 *ptr++ = 0x3; 4245 *ptr++ = 0x3;
4272 WILC_memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN); 4246 memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
4273 ptr += ETH_ALEN; 4247 ptr += ETH_ALEN;
4274 /* TID*/ 4248 /* TID*/
4275 *ptr++ = strHostIfBASessionInfo->u8Ted; 4249 *ptr++ = strHostIfBASessionInfo->u8Ted;
@@ -4277,7 +4251,7 @@ static s32 Handle_DelBASession(void *drvHandler, tstrHostIfBASessionInfo *strHos
4277 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); 4251 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
4278 4252
4279 if (strWID.ps8WidVal != NULL) 4253 if (strWID.ps8WidVal != NULL)
4280 WILC_FREE(strWID.ps8WidVal); 4254 kfree(strWID.ps8WidVal);
4281 4255
4282 /*BugID_5222*/ 4256 /*BugID_5222*/
4283 up(&hWaitResponse); 4257 up(&hWaitResponse);
@@ -4296,14 +4270,14 @@ static s32 Handle_DelBASession(void *drvHandler, tstrHostIfBASessionInfo *strHos
4296 * @date Feb. 2013 4270 * @date Feb. 2013
4297 * @version 9.0 4271 * @version 9.0
4298 */ 4272 */
4299static s32 Handle_DelAllRxBASessions(void *drvHandler, tstrHostIfBASessionInfo *strHostIfBASessionInfo) 4273static s32 Handle_DelAllRxBASessions(tstrWILC_WFIDrv *drvHandler, tstrHostIfBASessionInfo *strHostIfBASessionInfo)
4300{ 4274{
4301 s32 s32Error = WILC_SUCCESS; 4275 s32 s32Error = WILC_SUCCESS;
4302 tstrWID strWID; 4276 tstrWID strWID;
4303 char *ptr = NULL; 4277 char *ptr = NULL;
4304 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler; 4278 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
4305 4279
4306 PRINT_D(GENERIC_DBG, "Delete Block Ack session with\nBSSID = %.2x:%.2x:%.2x \nTID=%d\n", 4280 PRINT_D(GENERIC_DBG, "Delete Block Ack session with\nBSSID = %.2x:%.2x:%.2x\nTID=%d\n",
4307 strHostIfBASessionInfo->au8Bssid[0], 4281 strHostIfBASessionInfo->au8Bssid[0],
4308 strHostIfBASessionInfo->au8Bssid[1], 4282 strHostIfBASessionInfo->au8Bssid[1],
4309 strHostIfBASessionInfo->au8Bssid[2], 4283 strHostIfBASessionInfo->au8Bssid[2],
@@ -4311,13 +4285,13 @@ static s32 Handle_DelAllRxBASessions(void *drvHandler, tstrHostIfBASessionInfo *
4311 4285
4312 strWID.u16WIDid = (u16)WID_DEL_ALL_RX_BA; 4286 strWID.u16WIDid = (u16)WID_DEL_ALL_RX_BA;
4313 strWID.enuWIDtype = WID_STR; 4287 strWID.enuWIDtype = WID_STR;
4314 strWID.ps8WidVal = (u8 *)WILC_MALLOC(BLOCK_ACK_REQ_SIZE); 4288 strWID.ps8WidVal = WILC_MALLOC(BLOCK_ACK_REQ_SIZE);
4315 strWID.s32ValueSize = BLOCK_ACK_REQ_SIZE; 4289 strWID.s32ValueSize = BLOCK_ACK_REQ_SIZE;
4316 ptr = strWID.ps8WidVal; 4290 ptr = strWID.ps8WidVal;
4317 *ptr++ = 0x14; 4291 *ptr++ = 0x14;
4318 *ptr++ = 0x3; 4292 *ptr++ = 0x3;
4319 *ptr++ = 0x2; 4293 *ptr++ = 0x2;
4320 WILC_memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN); 4294 memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
4321 ptr += ETH_ALEN; 4295 ptr += ETH_ALEN;
4322 *ptr++ = strHostIfBASessionInfo->u8Ted; 4296 *ptr++ = strHostIfBASessionInfo->u8Ted;
4323 /* BA direction = recipent*/ 4297 /* BA direction = recipent*/
@@ -4331,7 +4305,7 @@ static s32 Handle_DelAllRxBASessions(void *drvHandler, tstrHostIfBASessionInfo *
4331 4305
4332 4306
4333 if (strWID.ps8WidVal != NULL) 4307 if (strWID.ps8WidVal != NULL)
4334 WILC_FREE(strWID.ps8WidVal); 4308 kfree(strWID.ps8WidVal);
4335 4309
4336 /*BugID_5222*/ 4310 /*BugID_5222*/
4337 up(&hWaitResponse); 4311 up(&hWaitResponse);
@@ -4355,10 +4329,10 @@ static int hostIFthread(void *pvArg)
4355 tstrHostIFmsg strHostIFmsg; 4329 tstrHostIFmsg strHostIFmsg;
4356 tstrWILC_WFIDrv *pstrWFIDrv; 4330 tstrWILC_WFIDrv *pstrWFIDrv;
4357 4331
4358 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 4332 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4359 4333
4360 while (1) { 4334 while (1) {
4361 WILC_MsgQueueRecv(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), &u32Ret, NULL); 4335 WILC_MsgQueueRecv(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), &u32Ret);
4362 pstrWFIDrv = (tstrWILC_WFIDrv *)strHostIFmsg.drvHandler; 4336 pstrWFIDrv = (tstrWILC_WFIDrv *)strHostIFmsg.drvHandler;
4363 if (strHostIFmsg.u16MsgId == HOST_IF_MSG_EXIT) { 4337 if (strHostIFmsg.u16MsgId == HOST_IF_MSG_EXIT) {
4364 PRINT_D(GENERIC_DBG, "THREAD: Exiting HostIfThread\n"); 4338 PRINT_D(GENERIC_DBG, "THREAD: Exiting HostIfThread\n");
@@ -4369,15 +4343,15 @@ static int hostIFthread(void *pvArg)
4369 /*Re-Queue HIF message*/ 4343 /*Re-Queue HIF message*/
4370 if ((!g_wilc_initialized)) { 4344 if ((!g_wilc_initialized)) {
4371 PRINT_D(GENERIC_DBG, "--WAIT--"); 4345 PRINT_D(GENERIC_DBG, "--WAIT--");
4372 WILC_Sleep(200); 4346 usleep_range(200 * 1000, 200 * 1000);
4373 WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 4347 WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
4374 continue; 4348 continue;
4375 } 4349 }
4376 4350
4377 if (strHostIFmsg.u16MsgId == HOST_IF_MSG_CONNECT && pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult != NULL) { 4351 if (strHostIFmsg.u16MsgId == HOST_IF_MSG_CONNECT && pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult != NULL) {
4378 PRINT_D(HOSTINF_DBG, "Requeue connect request till scan done received\n"); 4352 PRINT_D(HOSTINF_DBG, "Requeue connect request till scan done received\n");
4379 WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 4353 WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
4380 WILC_Sleep(2); 4354 usleep_range(2 * 1000, 2 * 1000);
4381 continue; 4355 continue;
4382 } 4356 }
4383 4357
@@ -4425,14 +4399,13 @@ static int hostIFthread(void *pvArg)
4425 break; 4399 break;
4426 4400
4427 case HOST_IF_MSG_RCVD_SCAN_COMPLETE: 4401 case HOST_IF_MSG_RCVD_SCAN_COMPLETE:
4428 WILC_TimerStop(&(pstrWFIDrv->hScanTimer), NULL); 4402 del_timer(&pstrWFIDrv->hScanTimer);
4429 PRINT_D(HOSTINF_DBG, "scan completed successfully\n"); 4403 PRINT_D(HOSTINF_DBG, "scan completed successfully\n");
4430 4404
4431 /*BugID_5213*/ 4405 /*BugID_5213*/
4432 /*Allow chip sleep, only if both interfaces are not connected*/ 4406 /*Allow chip sleep, only if both interfaces are not connected*/
4433 if (!linux_wlan_get_num_conn_ifcs()) { 4407 if (!linux_wlan_get_num_conn_ifcs())
4434 chip_sleep_manually(INFINITE_SLEEP_TIME); 4408 chip_sleep_manually(INFINITE_SLEEP_TIME);
4435 }
4436 4409
4437 Handle_ScanDone(strHostIFmsg.drvHandler, SCAN_EVENT_DONE); 4410 Handle_ScanDone(strHostIFmsg.drvHandler, SCAN_EVENT_DONE);
4438 4411
@@ -4492,7 +4465,7 @@ static int hostIFthread(void *pvArg)
4492 break; 4465 break;
4493 4466
4494 case HOST_IF_MSG_CONNECT_TIMER_FIRED: 4467 case HOST_IF_MSG_CONNECT_TIMER_FIRED:
4495 PRINT_D(HOSTINF_DBG, "Connect Timeout \n"); 4468 PRINT_D(HOSTINF_DBG, "Connect Timeout\n");
4496 Handle_ConnectTimeout(strHostIFmsg.drvHandler); 4469 Handle_ConnectTimeout(strHostIFmsg.drvHandler);
4497 break; 4470 break;
4498 4471
@@ -4563,7 +4536,7 @@ static int hostIFthread(void *pvArg)
4563 break; 4536 break;
4564 4537
4565 default: 4538 default:
4566 PRINT_ER("[Host Interface] undefined Received Msg ID \n"); 4539 PRINT_ER("[Host Interface] undefined Received Msg ID\n");
4567 break; 4540 break;
4568 } 4541 }
4569 } 4542 }
@@ -4573,30 +4546,32 @@ static int hostIFthread(void *pvArg)
4573 return 0; 4546 return 0;
4574} 4547}
4575 4548
4576static void TimerCB_Scan(void *pvArg) 4549static void TimerCB_Scan(unsigned long arg)
4577{ 4550{
4551 void *pvArg = (void *)arg;
4578 tstrHostIFmsg strHostIFmsg; 4552 tstrHostIFmsg strHostIFmsg;
4579 4553
4580 /* prepare the Timer Callback message */ 4554 /* prepare the Timer Callback message */
4581 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 4555 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4582 strHostIFmsg.drvHandler = pvArg; 4556 strHostIFmsg.drvHandler = pvArg;
4583 strHostIFmsg.u16MsgId = HOST_IF_MSG_SCAN_TIMER_FIRED; 4557 strHostIFmsg.u16MsgId = HOST_IF_MSG_SCAN_TIMER_FIRED;
4584 4558
4585 /* send the message */ 4559 /* send the message */
4586 WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 4560 WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
4587} 4561}
4588 4562
4589static void TimerCB_Connect(void *pvArg) 4563static void TimerCB_Connect(unsigned long arg)
4590{ 4564{
4565 void *pvArg = (void *)arg;
4591 tstrHostIFmsg strHostIFmsg; 4566 tstrHostIFmsg strHostIFmsg;
4592 4567
4593 /* prepare the Timer Callback message */ 4568 /* prepare the Timer Callback message */
4594 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 4569 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4595 strHostIFmsg.drvHandler = pvArg; 4570 strHostIFmsg.drvHandler = pvArg;
4596 strHostIFmsg.u16MsgId = HOST_IF_MSG_CONNECT_TIMER_FIRED; 4571 strHostIFmsg.u16MsgId = HOST_IF_MSG_CONNECT_TIMER_FIRED;
4597 4572
4598 /* send the message */ 4573 /* send the message */
4599 WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 4574 WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
4600} 4575}
4601 4576
4602 4577
@@ -4613,7 +4588,7 @@ static void TimerCB_Connect(void *pvArg)
4613 * @version 1.0 4588 * @version 1.0
4614 */ 4589 */
4615/* Check implementation in core adding 9 bytes to the input! */ 4590/* Check implementation in core adding 9 bytes to the input! */
4616s32 host_int_remove_key(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8StaAddress) 4591s32 host_int_remove_key(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8StaAddress)
4617{ 4592{
4618 s32 s32Error = WILC_SUCCESS; 4593 s32 s32Error = WILC_SUCCESS;
4619 tstrWID strWID; 4594 tstrWID strWID;
@@ -4642,19 +4617,18 @@ s32 host_int_remove_key(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8StaAddress)
4642 * @date 8 March 2012 4617 * @date 8 March 2012
4643 * @version 1.0 4618 * @version 1.0
4644 */ 4619 */
4645s32 host_int_remove_wep_key(WILC_WFIDrvHandle hWFIDrv, u8 u8keyIdx) 4620s32 host_int_remove_wep_key(tstrWILC_WFIDrv *hWFIDrv, u8 u8keyIdx)
4646{ 4621{
4647 s32 s32Error = WILC_SUCCESS; 4622 s32 s32Error = WILC_SUCCESS;
4648 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 4623 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
4649 tstrHostIFmsg strHostIFmsg; 4624 tstrHostIFmsg strHostIFmsg;
4650 4625
4651 4626
4652 if (pstrWFIDrv == NULL) { 4627 if (pstrWFIDrv == NULL)
4653 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 4628 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
4654 }
4655 4629
4656 /* prepare the Remove Wep Key Message */ 4630 /* prepare the Remove Wep Key Message */
4657 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 4631 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4658 4632
4659 4633
4660 strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY; 4634 strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
@@ -4668,9 +4642,9 @@ s32 host_int_remove_wep_key(WILC_WFIDrvHandle hWFIDrv, u8 u8keyIdx)
4668 uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx = u8keyIdx; 4642 uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx = u8keyIdx;
4669 4643
4670 /* send the message */ 4644 /* send the message */
4671 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 4645 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
4672 if (s32Error) 4646 if (s32Error)
4673 PRINT_ER("Error in sending message queue : Request to remove WEP key \n"); 4647 PRINT_ER("Error in sending message queue : Request to remove WEP key\n");
4674 down(&(pstrWFIDrv->hSemTestKeyBlock)); 4648 down(&(pstrWFIDrv->hSemTestKeyBlock));
4675 4649
4676 WILC_CATCH(s32Error) 4650 WILC_CATCH(s32Error)
@@ -4692,19 +4666,18 @@ s32 host_int_remove_wep_key(WILC_WFIDrvHandle hWFIDrv, u8 u8keyIdx)
4692 * @date 8 March 2012 4666 * @date 8 March 2012
4693 * @version 1.0 4667 * @version 1.0
4694 */ 4668 */
4695s32 host_int_set_WEPDefaultKeyID(WILC_WFIDrvHandle hWFIDrv, u8 u8Index) 4669s32 host_int_set_WEPDefaultKeyID(tstrWILC_WFIDrv *hWFIDrv, u8 u8Index)
4696{ 4670{
4697 s32 s32Error = WILC_SUCCESS; 4671 s32 s32Error = WILC_SUCCESS;
4698 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 4672 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
4699 tstrHostIFmsg strHostIFmsg; 4673 tstrHostIFmsg strHostIFmsg;
4700 4674
4701 4675
4702 if (pstrWFIDrv == NULL) { 4676 if (pstrWFIDrv == NULL)
4703 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 4677 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
4704 }
4705 4678
4706 /* prepare the Key Message */ 4679 /* prepare the Key Message */
4707 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 4680 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4708 4681
4709 4682
4710 strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY; 4683 strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
@@ -4717,7 +4690,7 @@ s32 host_int_set_WEPDefaultKeyID(WILC_WFIDrvHandle hWFIDrv, u8 u8Index)
4717 uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx = u8Index; 4690 uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx = u8Index;
4718 4691
4719 /* send the message */ 4692 /* send the message */
4720 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 4693 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
4721 if (s32Error) 4694 if (s32Error)
4722 PRINT_ER("Error in sending message queue : Default key index\n"); 4695 PRINT_ER("Error in sending message queue : Default key index\n");
4723 down(&(pstrWFIDrv->hSemTestKeyBlock)); 4696 down(&(pstrWFIDrv->hSemTestKeyBlock));
@@ -4749,20 +4722,19 @@ s32 host_int_set_WEPDefaultKeyID(WILC_WFIDrvHandle hWFIDrv, u8 u8Index)
4749 * @date 8 March 2012 4722 * @date 8 March 2012
4750 * @version 1.0 4723 * @version 1.0
4751 */ 4724 */
4752s32 host_int_add_wep_key_bss_sta(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8WepKey, u8 u8WepKeylen, u8 u8Keyidx) 4725s32 host_int_add_wep_key_bss_sta(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8WepKey, u8 u8WepKeylen, u8 u8Keyidx)
4753{ 4726{
4754 4727
4755 s32 s32Error = WILC_SUCCESS; 4728 s32 s32Error = WILC_SUCCESS;
4756 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 4729 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
4757 tstrHostIFmsg strHostIFmsg; 4730 tstrHostIFmsg strHostIFmsg;
4758 4731
4759 if (pstrWFIDrv == NULL) { 4732 if (pstrWFIDrv == NULL)
4760 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 4733 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
4761 4734
4762 }
4763 4735
4764 /* prepare the Key Message */ 4736 /* prepare the Key Message */
4765 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 4737 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4766 4738
4767 4739
4768 strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY; 4740 strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
@@ -4772,9 +4744,9 @@ s32 host_int_add_wep_key_bss_sta(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8WepKey,
4772 4744
4773 4745
4774 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr. 4746 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4775 uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey = (u8 *)WILC_MALLOC(u8WepKeylen); 4747 uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey = WILC_MALLOC(u8WepKeylen);
4776 4748
4777 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey, 4749 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey,
4778 pu8WepKey, u8WepKeylen); 4750 pu8WepKey, u8WepKeylen);
4779 4751
4780 4752
@@ -4785,7 +4757,7 @@ s32 host_int_add_wep_key_bss_sta(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8WepKey,
4785 uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx = u8Keyidx; 4757 uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx = u8Keyidx;
4786 4758
4787 /* send the message */ 4759 /* send the message */
4788 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 4760 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
4789 if (s32Error) 4761 if (s32Error)
4790 PRINT_ER("Error in sending message queue :WEP Key\n"); 4762 PRINT_ER("Error in sending message queue :WEP Key\n");
4791 down(&(pstrWFIDrv->hSemTestKeyBlock)); 4763 down(&(pstrWFIDrv->hSemTestKeyBlock));
@@ -4815,7 +4787,7 @@ s32 host_int_add_wep_key_bss_sta(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8WepKey,
4815 * @date 28 FEB 2013 4787 * @date 28 FEB 2013
4816 * @version 1.0 4788 * @version 1.0
4817 */ 4789 */
4818s32 host_int_add_wep_key_bss_ap(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8WepKey, u8 u8WepKeylen, u8 u8Keyidx, u8 u8mode, AUTHTYPE_T tenuAuth_type) 4790s32 host_int_add_wep_key_bss_ap(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8WepKey, u8 u8WepKeylen, u8 u8Keyidx, u8 u8mode, AUTHTYPE_T tenuAuth_type)
4819{ 4791{
4820 4792
4821 s32 s32Error = WILC_SUCCESS; 4793 s32 s32Error = WILC_SUCCESS;
@@ -4823,13 +4795,12 @@ s32 host_int_add_wep_key_bss_ap(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8WepKey,
4823 tstrHostIFmsg strHostIFmsg; 4795 tstrHostIFmsg strHostIFmsg;
4824 u8 i; 4796 u8 i;
4825 4797
4826 if (pstrWFIDrv == NULL) { 4798 if (pstrWFIDrv == NULL)
4827 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 4799 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
4828 4800
4829 }
4830 4801
4831 /* prepare the Key Message */ 4802 /* prepare the Key Message */
4832 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 4803 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4833 4804
4834 if (INFO) { 4805 if (INFO) {
4835 for (i = 0; i < u8WepKeylen; i++) 4806 for (i = 0; i < u8WepKeylen; i++)
@@ -4842,10 +4813,10 @@ s32 host_int_add_wep_key_bss_ap(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8WepKey,
4842 4813
4843 4814
4844 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr. 4815 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4845 uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey = (u8 *)WILC_MALLOC((u8WepKeylen)); 4816 uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey = WILC_MALLOC((u8WepKeylen));
4846 4817
4847 4818
4848 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey, 4819 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey,
4849 pu8WepKey, (u8WepKeylen)); 4820 pu8WepKey, (u8WepKeylen));
4850 4821
4851 4822
@@ -4861,7 +4832,7 @@ s32 host_int_add_wep_key_bss_ap(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8WepKey,
4861 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr. 4832 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4862 uniHostIFkeyAttr.strHostIFwepAttr.tenuAuth_type = tenuAuth_type; 4833 uniHostIFkeyAttr.strHostIFwepAttr.tenuAuth_type = tenuAuth_type;
4863 /* send the message */ 4834 /* send the message */
4864 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 4835 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
4865 4836
4866 if (s32Error) 4837 if (s32Error)
4867 PRINT_ER("Error in sending message queue :WEP Key\n"); 4838 PRINT_ER("Error in sending message queue :WEP Key\n");
@@ -4891,7 +4862,7 @@ s32 host_int_add_wep_key_bss_ap(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8WepKey,
4891 * @date 8 March 2012 4862 * @date 8 March 2012
4892 * @version 1.0 4863 * @version 1.0
4893 */ 4864 */
4894s32 host_int_add_ptk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen, 4865s32 host_int_add_ptk(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen,
4895 const u8 *mac_addr, const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode, u8 u8Idx) 4866 const u8 *mac_addr, const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode, u8 u8Idx)
4896{ 4867{
4897 s32 s32Error = WILC_SUCCESS; 4868 s32 s32Error = WILC_SUCCESS;
@@ -4899,18 +4870,16 @@ s32 host_int_add_ptk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen
4899 tstrHostIFmsg strHostIFmsg; 4870 tstrHostIFmsg strHostIFmsg;
4900 u8 u8KeyLen = u8PtkKeylen; 4871 u8 u8KeyLen = u8PtkKeylen;
4901 u32 i; 4872 u32 i;
4902 if (pstrWFIDrv == NULL) { 4873
4874 if (pstrWFIDrv == NULL)
4903 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 4875 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
4904 } 4876 if (pu8RxMic != NULL)
4905 if (pu8RxMic != NULL) {
4906 u8KeyLen += RX_MIC_KEY_LEN; 4877 u8KeyLen += RX_MIC_KEY_LEN;
4907 } 4878 if (pu8TxMic != NULL)
4908 if (pu8TxMic != NULL) {
4909 u8KeyLen += TX_MIC_KEY_LEN; 4879 u8KeyLen += TX_MIC_KEY_LEN;
4910 }
4911 4880
4912 /* prepare the Key Message */ 4881 /* prepare the Key Message */
4913 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 4882 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4914 4883
4915 4884
4916 strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY; 4885 strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
@@ -4927,15 +4896,15 @@ s32 host_int_add_ptk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen
4927 4896
4928 4897
4929 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr. 4898 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4930 uniHostIFkeyAttr.strHostIFwpaAttr.pu8key = (u8 *)WILC_MALLOC(u8PtkKeylen); 4899 uniHostIFkeyAttr.strHostIFwpaAttr.pu8key = WILC_MALLOC(u8PtkKeylen);
4931 4900
4932 4901
4933 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key, 4902 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
4934 pu8Ptk, u8PtkKeylen); 4903 pu8Ptk, u8PtkKeylen);
4935 4904
4936 if (pu8RxMic != NULL) { 4905 if (pu8RxMic != NULL) {
4937 4906
4938 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 16, 4907 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 16,
4939 pu8RxMic, RX_MIC_KEY_LEN); 4908 pu8RxMic, RX_MIC_KEY_LEN);
4940 if (INFO) { 4909 if (INFO) {
4941 for (i = 0; i < RX_MIC_KEY_LEN; i++) 4910 for (i = 0; i < RX_MIC_KEY_LEN; i++)
@@ -4944,7 +4913,7 @@ s32 host_int_add_ptk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen
4944 } 4913 }
4945 if (pu8TxMic != NULL) { 4914 if (pu8TxMic != NULL) {
4946 4915
4947 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 24, 4916 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 24,
4948 pu8TxMic, TX_MIC_KEY_LEN); 4917 pu8TxMic, TX_MIC_KEY_LEN);
4949 if (INFO) { 4918 if (INFO) {
4950 for (i = 0; i < TX_MIC_KEY_LEN; i++) 4919 for (i = 0; i < TX_MIC_KEY_LEN; i++)
@@ -4962,14 +4931,13 @@ s32 host_int_add_ptk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen
4962 strHostIFmsg.drvHandler = hWFIDrv; 4931 strHostIFmsg.drvHandler = hWFIDrv;
4963 4932
4964 /* send the message */ 4933 /* send the message */
4965 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 4934 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
4966 4935
4967 if (s32Error) 4936 if (s32Error)
4968 PRINT_ER("Error in sending message queue: PTK Key\n"); 4937 PRINT_ER("Error in sending message queue: PTK Key\n");
4969 4938
4970 /* ////////////// */ 4939 /* ////////////// */
4971 down(&(pstrWFIDrv->hSemTestKeyBlock)); 4940 down(&(pstrWFIDrv->hSemTestKeyBlock));
4972 /* WILC_Sleep(100); */
4973 /* /////// */ 4941 /* /////// */
4974 4942
4975 WILC_CATCH(s32Error) 4943 WILC_CATCH(s32Error)
@@ -4993,7 +4961,7 @@ s32 host_int_add_ptk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen
4993 * @date 8 March 2012 4961 * @date 8 March 2012
4994 * @version 1.0 4962 * @version 1.0
4995 */ 4963 */
4996s32 host_int_add_rx_gtk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8RxGtk, u8 u8GtkKeylen, 4964s32 host_int_add_rx_gtk(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8RxGtk, u8 u8GtkKeylen,
4997 u8 u8KeyIdx, u32 u32KeyRSClen, const u8 *KeyRSC, 4965 u8 u8KeyIdx, u32 u32KeyRSClen, const u8 *KeyRSC,
4998 const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode) 4966 const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode)
4999{ 4967{
@@ -5002,24 +4970,21 @@ s32 host_int_add_rx_gtk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8RxGtk, u8 u8GtkK
5002 tstrHostIFmsg strHostIFmsg; 4970 tstrHostIFmsg strHostIFmsg;
5003 u8 u8KeyLen = u8GtkKeylen; 4971 u8 u8KeyLen = u8GtkKeylen;
5004 4972
5005 if (pstrWFIDrv == NULL) { 4973 if (pstrWFIDrv == NULL)
5006 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 4974 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5007 }
5008 /* prepare the Key Message */ 4975 /* prepare the Key Message */
5009 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 4976 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5010 4977
5011 4978
5012 if (pu8RxMic != NULL) { 4979 if (pu8RxMic != NULL)
5013 u8KeyLen += RX_MIC_KEY_LEN; 4980 u8KeyLen += RX_MIC_KEY_LEN;
5014 } 4981 if (pu8TxMic != NULL)
5015 if (pu8TxMic != NULL) {
5016 u8KeyLen += TX_MIC_KEY_LEN; 4982 u8KeyLen += TX_MIC_KEY_LEN;
5017 }
5018 if (KeyRSC != NULL) { 4983 if (KeyRSC != NULL) {
5019 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr. 4984 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
5020 uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq = (u8 *)WILC_MALLOC(u32KeyRSClen); 4985 uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq = WILC_MALLOC(u32KeyRSClen);
5021 4986
5022 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq, 4987 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq,
5023 KeyRSC, u32KeyRSClen); 4988 KeyRSC, u32KeyRSClen);
5024 } 4989 }
5025 4990
@@ -5039,20 +5004,20 @@ s32 host_int_add_rx_gtk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8RxGtk, u8 u8GtkK
5039 5004
5040 5005
5041 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr. 5006 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
5042 uniHostIFkeyAttr.strHostIFwpaAttr.pu8key = (u8 *)WILC_MALLOC(u8KeyLen); 5007 uniHostIFkeyAttr.strHostIFwpaAttr.pu8key = WILC_MALLOC(u8KeyLen);
5043 5008
5044 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key, 5009 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
5045 pu8RxGtk, u8GtkKeylen); 5010 pu8RxGtk, u8GtkKeylen);
5046 5011
5047 if (pu8RxMic != NULL) { 5012 if (pu8RxMic != NULL) {
5048 5013
5049 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 16, 5014 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 16,
5050 pu8RxMic, RX_MIC_KEY_LEN); 5015 pu8RxMic, RX_MIC_KEY_LEN);
5051 5016
5052 } 5017 }
5053 if (pu8TxMic != NULL) { 5018 if (pu8TxMic != NULL) {
5054 5019
5055 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 24, 5020 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 24,
5056 pu8TxMic, TX_MIC_KEY_LEN); 5021 pu8TxMic, TX_MIC_KEY_LEN);
5057 5022
5058 } 5023 }
@@ -5068,12 +5033,11 @@ s32 host_int_add_rx_gtk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8RxGtk, u8 u8GtkK
5068 5033
5069 5034
5070 /* send the message */ 5035 /* send the message */
5071 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 5036 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
5072 if (s32Error) 5037 if (s32Error)
5073 PRINT_ER("Error in sending message queue: RX GTK\n"); 5038 PRINT_ER("Error in sending message queue: RX GTK\n");
5074 /* ////////////// */ 5039 /* ////////////// */
5075 down(&(pstrWFIDrv->hSemTestKeyBlock)); 5040 down(&(pstrWFIDrv->hSemTestKeyBlock));
5076 /* WILC_Sleep(100); */
5077 /* /////// */ 5041 /* /////// */
5078 5042
5079 WILC_CATCH(s32Error) 5043 WILC_CATCH(s32Error)
@@ -5103,7 +5067,7 @@ s32 host_int_add_rx_gtk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8RxGtk, u8 u8GtkK
5103 * @date 8 March 2012 5067 * @date 8 March 2012
5104 * @version 1.0 5068 * @version 1.0
5105 */ 5069 */
5106s32 host_int_set_pmkid_info(WILC_WFIDrvHandle hWFIDrv, tstrHostIFpmkidAttr *pu8PmkidInfoArray) 5070s32 host_int_set_pmkid_info(tstrWILC_WFIDrv *hWFIDrv, tstrHostIFpmkidAttr *pu8PmkidInfoArray)
5107{ 5071{
5108 s32 s32Error = WILC_SUCCESS; 5072 s32 s32Error = WILC_SUCCESS;
5109 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 5073 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
@@ -5111,12 +5075,11 @@ s32 host_int_set_pmkid_info(WILC_WFIDrvHandle hWFIDrv, tstrHostIFpmkidAttr *pu8P
5111 u32 i; 5075 u32 i;
5112 5076
5113 5077
5114 if (pstrWFIDrv == NULL) { 5078 if (pstrWFIDrv == NULL)
5115 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 5079 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5116 }
5117 5080
5118 /* prepare the Key Message */ 5081 /* prepare the Key Message */
5119 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 5082 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5120 5083
5121 strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY; 5084 strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
5122 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = PMKSA; 5085 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = PMKSA;
@@ -5125,15 +5088,15 @@ s32 host_int_set_pmkid_info(WILC_WFIDrvHandle hWFIDrv, tstrHostIFpmkidAttr *pu8P
5125 5088
5126 for (i = 0; i < pu8PmkidInfoArray->numpmkid; i++) { 5089 for (i = 0; i < pu8PmkidInfoArray->numpmkid; i++) {
5127 5090
5128 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].bssid, &pu8PmkidInfoArray->pmkidlist[i].bssid, 5091 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].bssid, &pu8PmkidInfoArray->pmkidlist[i].bssid,
5129 ETH_ALEN); 5092 ETH_ALEN);
5130 5093
5131 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].pmkid, &pu8PmkidInfoArray->pmkidlist[i].pmkid, 5094 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].pmkid, &pu8PmkidInfoArray->pmkidlist[i].pmkid,
5132 PMKID_LEN); 5095 PMKID_LEN);
5133 } 5096 }
5134 5097
5135 /* send the message */ 5098 /* send the message */
5136 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 5099 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
5137 if (s32Error) 5100 if (s32Error)
5138 PRINT_ER(" Error in sending messagequeue: PMKID Info\n"); 5101 PRINT_ER(" Error in sending messagequeue: PMKID Info\n");
5139 5102
@@ -5166,7 +5129,7 @@ s32 host_int_set_pmkid_info(WILC_WFIDrvHandle hWFIDrv, tstrHostIFpmkidAttr *pu8P
5166 * @date 8 March 2012 5129 * @date 8 March 2012
5167 * @version 1.0 5130 * @version 1.0
5168 */ 5131 */
5169s32 host_int_get_pmkid_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8PmkidInfoArray, 5132s32 host_int_get_pmkid_info(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8PmkidInfoArray,
5170 u32 u32PmkidInfoLen) 5133 u32 u32PmkidInfoLen)
5171{ 5134{
5172 s32 s32Error = WILC_SUCCESS; 5135 s32 s32Error = WILC_SUCCESS;
@@ -5195,14 +5158,12 @@ s32 host_int_get_pmkid_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8PmkidInfoArray,
5195 * @date 8 March 2012 5158 * @date 8 March 2012
5196 * @version 1.0 5159 * @version 1.0
5197 */ 5160 */
5198s32 host_int_set_RSNAConfigPSKPassPhrase(WILC_WFIDrvHandle hWFIDrv, u8 *pu8PassPhrase, 5161s32 host_int_set_RSNAConfigPSKPassPhrase(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8PassPhrase,
5199 u8 u8Psklength) 5162 u8 u8Psklength)
5200{ 5163{
5201 s32 s32Error = WILC_SUCCESS; 5164 s32 s32Error = WILC_SUCCESS;
5202 tstrWID strWID; 5165 tstrWID strWID;
5203 /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
5204 5166
5205 /* u8 u8Psklength = WILC_strlen(pu8PassPhrase); */
5206 /*validating psk length*/ 5167 /*validating psk length*/
5207 if ((u8Psklength > 7) && (u8Psklength < 65)) { 5168 if ((u8Psklength > 7) && (u8Psklength < 65)) {
5208 strWID.u16WIDid = (u16)WID_11I_PSK; 5169 strWID.u16WIDid = (u16)WID_11I_PSK;
@@ -5224,20 +5185,20 @@ s32 host_int_set_RSNAConfigPSKPassPhrase(WILC_WFIDrvHandle hWFIDrv, u8 *pu8PassP
5224 * @date 19 April 2012 5185 * @date 19 April 2012
5225 * @version 1.0 5186 * @version 1.0
5226 */ 5187 */
5227s32 host_int_get_MacAddress(WILC_WFIDrvHandle hWFIDrv, u8 *pu8MacAddress) 5188s32 host_int_get_MacAddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8MacAddress)
5228{ 5189{
5229 s32 s32Error = WILC_SUCCESS; 5190 s32 s32Error = WILC_SUCCESS;
5230 tstrHostIFmsg strHostIFmsg; 5191 tstrHostIFmsg strHostIFmsg;
5231 5192
5232 5193
5233 /* prepare the Message */ 5194 /* prepare the Message */
5234 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 5195 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5235 5196
5236 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_MAC_ADDRESS; 5197 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_MAC_ADDRESS;
5237 strHostIFmsg.uniHostIFmsgBody.strHostIfGetMacAddress.u8MacAddress = pu8MacAddress; 5198 strHostIFmsg.uniHostIFmsgBody.strHostIfGetMacAddress.u8MacAddress = pu8MacAddress;
5238 strHostIFmsg.drvHandler = hWFIDrv; 5199 strHostIFmsg.drvHandler = hWFIDrv;
5239 /* send the message */ 5200 /* send the message */
5240 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 5201 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
5241 if (s32Error) { 5202 if (s32Error) {
5242 PRINT_ER("Failed to send get mac address\n"); 5203 PRINT_ER("Failed to send get mac address\n");
5243 return WILC_FAIL; 5204 return WILC_FAIL;
@@ -5258,7 +5219,7 @@ s32 host_int_get_MacAddress(WILC_WFIDrvHandle hWFIDrv, u8 *pu8MacAddress)
5258 * @date 16 July 2012 5219 * @date 16 July 2012
5259 * @version 1.0 5220 * @version 1.0
5260 */ 5221 */
5261s32 host_int_set_MacAddress(WILC_WFIDrvHandle hWFIDrv, u8 *pu8MacAddress) 5222s32 host_int_set_MacAddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8MacAddress)
5262{ 5223{
5263 s32 s32Error = WILC_SUCCESS; 5224 s32 s32Error = WILC_SUCCESS;
5264 tstrHostIFmsg strHostIFmsg; 5225 tstrHostIFmsg strHostIFmsg;
@@ -5266,12 +5227,12 @@ s32 host_int_set_MacAddress(WILC_WFIDrvHandle hWFIDrv, u8 *pu8MacAddress)
5266 PRINT_D(GENERIC_DBG, "mac addr = %x:%x:%x\n", pu8MacAddress[0], pu8MacAddress[1], pu8MacAddress[2]); 5227 PRINT_D(GENERIC_DBG, "mac addr = %x:%x:%x\n", pu8MacAddress[0], pu8MacAddress[1], pu8MacAddress[2]);
5267 5228
5268 /* prepare setting mac address message */ 5229 /* prepare setting mac address message */
5269 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 5230 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5270 strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_MAC_ADDRESS; 5231 strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_MAC_ADDRESS;
5271 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIfSetMacAddress.u8MacAddress, pu8MacAddress, ETH_ALEN); 5232 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIfSetMacAddress.u8MacAddress, pu8MacAddress, ETH_ALEN);
5272 strHostIFmsg.drvHandler = hWFIDrv; 5233 strHostIFmsg.drvHandler = hWFIDrv;
5273 5234
5274 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 5235 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
5275 if (s32Error) { 5236 if (s32Error) {
5276 PRINT_ER("Failed to send message queue: Set mac address\n"); 5237 PRINT_ER("Failed to send message queue: Set mac address\n");
5277 WILC_ERRORREPORT(s32Error, s32Error); 5238 WILC_ERRORREPORT(s32Error, s32Error);
@@ -5299,7 +5260,7 @@ s32 host_int_set_MacAddress(WILC_WFIDrvHandle hWFIDrv, u8 *pu8MacAddress)
5299 * @date 8 March 2012 5260 * @date 8 March 2012
5300 * @version 1.0 5261 * @version 1.0
5301 */ 5262 */
5302s32 host_int_get_RSNAConfigPSKPassPhrase(WILC_WFIDrvHandle hWFIDrv, 5263s32 host_int_get_RSNAConfigPSKPassPhrase(tstrWILC_WFIDrv *hWFIDrv,
5303 u8 *pu8PassPhrase, u8 u8Psklength) 5264 u8 *pu8PassPhrase, u8 u8Psklength)
5304{ 5265{
5305 s32 s32Error = WILC_SUCCESS; 5266 s32 s32Error = WILC_SUCCESS;
@@ -5346,7 +5307,7 @@ s32 host_int_get_RSNAConfigPSKPassPhrase(WILC_WFIDrvHandle hWFIDrv,
5346 * @version 1.0 5307 * @version 1.0
5347 */ 5308 */
5348#ifndef CONNECT_DIRECT 5309#ifndef CONNECT_DIRECT
5349s32 host_int_get_site_survey_results(WILC_WFIDrvHandle hWFIDrv, 5310s32 host_int_get_site_survey_results(tstrWILC_WFIDrv *hWFIDrv,
5350 u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZE], 5311 u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZE],
5351 u32 u32MaxSiteSrvyFragLen) 5312 u32 u32MaxSiteSrvyFragLen)
5352{ 5313{
@@ -5396,7 +5357,7 @@ s32 host_int_get_site_survey_results(WILC_WFIDrvHandle hWFIDrv,
5396 * @date 8 March 2012 5357 * @date 8 March 2012
5397 * @version 1.0 5358 * @version 1.0
5398 */ 5359 */
5399s32 host_int_set_start_scan_req(WILC_WFIDrvHandle hWFIDrv, u8 scanSource) 5360s32 host_int_set_start_scan_req(tstrWILC_WFIDrv *hWFIDrv, u8 scanSource)
5400{ 5361{
5401 s32 s32Error = WILC_SUCCESS; 5362 s32 s32Error = WILC_SUCCESS;
5402 tstrWID strWID; 5363 tstrWID strWID;
@@ -5426,7 +5387,7 @@ s32 host_int_set_start_scan_req(WILC_WFIDrvHandle hWFIDrv, u8 scanSource)
5426 * @version 1.0 5387 * @version 1.0
5427 */ 5388 */
5428 5389
5429s32 host_int_get_start_scan_req(WILC_WFIDrvHandle hWFIDrv, u8 *pu8ScanSource) 5390s32 host_int_get_start_scan_req(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8ScanSource)
5430{ 5391{
5431 s32 s32Error = WILC_SUCCESS; 5392 s32 s32Error = WILC_SUCCESS;
5432 tstrWID strWID; 5393 tstrWID strWID;
@@ -5451,7 +5412,7 @@ s32 host_int_get_start_scan_req(WILC_WFIDrvHandle hWFIDrv, u8 *pu8ScanSource)
5451 * @date 8 March 2012 5412 * @date 8 March 2012
5452 * @version 1.0 5413 * @version 1.0
5453 */ 5414 */
5454s32 host_int_set_join_req(WILC_WFIDrvHandle hWFIDrv, u8 *pu8bssid, 5415s32 host_int_set_join_req(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8bssid,
5455 const u8 *pu8ssid, size_t ssidLen, 5416 const u8 *pu8ssid, size_t ssidLen,
5456 const u8 *pu8IEs, size_t IEsLen, 5417 const u8 *pu8IEs, size_t IEsLen,
5457 tWILCpfConnectResult pfConnectResult, void *pvUserArg, 5418 tWILCpfConnectResult pfConnectResult, void *pvUserArg,
@@ -5464,9 +5425,8 @@ s32 host_int_set_join_req(WILC_WFIDrvHandle hWFIDrv, u8 *pu8bssid,
5464 tstrHostIFmsg strHostIFmsg; 5425 tstrHostIFmsg strHostIFmsg;
5465 tenuScanConnTimer enuScanConnTimer; 5426 tenuScanConnTimer enuScanConnTimer;
5466 5427
5467 if (pstrWFIDrv == NULL || pfConnectResult == NULL) { 5428 if (pstrWFIDrv == NULL || pfConnectResult == NULL)
5468 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 5429 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5469 }
5470 5430
5471 if (hWFIDrv == NULL) { 5431 if (hWFIDrv == NULL) {
5472 PRINT_ER("Driver not initialized: gWFiDrvHandle = NULL\n"); 5432 PRINT_ER("Driver not initialized: gWFiDrvHandle = NULL\n");
@@ -5486,7 +5446,7 @@ s32 host_int_set_join_req(WILC_WFIDrvHandle hWFIDrv, u8 *pu8bssid,
5486 * } 5446 * }
5487 */ 5447 */
5488 /* prepare the Connect Message */ 5448 /* prepare the Connect Message */
5489 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 5449 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5490 5450
5491 strHostIFmsg.u16MsgId = HOST_IF_MSG_CONNECT; 5451 strHostIFmsg.u16MsgId = HOST_IF_MSG_CONNECT;
5492 5452
@@ -5499,39 +5459,41 @@ s32 host_int_set_join_req(WILC_WFIDrvHandle hWFIDrv, u8 *pu8bssid,
5499 strHostIFmsg.drvHandler = hWFIDrv; 5459 strHostIFmsg.drvHandler = hWFIDrv;
5500 5460
5501 if (pu8bssid != NULL) { 5461 if (pu8bssid != NULL) {
5502 strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8bssid = (u8 *)WILC_MALLOC(6); /* will be deallocated by the receiving thread */ 5462 strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8bssid = WILC_MALLOC(6); /* will be deallocated by the receiving thread */
5503 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8bssid, 5463 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8bssid,
5504 pu8bssid, 6); 5464 pu8bssid, 6);
5505 } 5465 }
5506 5466
5507 if (pu8ssid != NULL) { 5467 if (pu8ssid != NULL) {
5508 strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.ssidLen = ssidLen; 5468 strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.ssidLen = ssidLen;
5509 strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8ssid = (u8 *)WILC_MALLOC(ssidLen); /* will be deallocated by the receiving thread */ 5469 strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8ssid = WILC_MALLOC(ssidLen); /* will be deallocated by the receiving thread */
5510 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8ssid, 5470 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8ssid,
5511 5471
5512 pu8ssid, ssidLen); 5472 pu8ssid, ssidLen);
5513 } 5473 }
5514 5474
5515 if (pu8IEs != NULL) { 5475 if (pu8IEs != NULL) {
5516 strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.IEsLen = IEsLen; 5476 strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.IEsLen = IEsLen;
5517 strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8IEs = (u8 *)WILC_MALLOC(IEsLen); /* will be deallocated by the receiving thread */ 5477 strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8IEs = WILC_MALLOC(IEsLen); /* will be deallocated by the receiving thread */
5518 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8IEs, 5478 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8IEs,
5519 pu8IEs, IEsLen); 5479 pu8IEs, IEsLen);
5520 } 5480 }
5521 if (pstrWFIDrv->enuHostIFstate < HOST_IF_CONNECTING) { 5481 if (pstrWFIDrv->enuHostIFstate < HOST_IF_CONNECTING)
5522 pstrWFIDrv->enuHostIFstate = HOST_IF_CONNECTING; 5482 pstrWFIDrv->enuHostIFstate = HOST_IF_CONNECTING;
5523 } else 5483 else
5524 PRINT_D(GENERIC_DBG, "Don't set state to 'connecting' as state is %d\n", pstrWFIDrv->enuHostIFstate); 5484 PRINT_D(GENERIC_DBG, "Don't set state to 'connecting' as state is %d\n", pstrWFIDrv->enuHostIFstate);
5525 5485
5526 /* send the message */ 5486 /* send the message */
5527 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 5487 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
5528 if (s32Error) { 5488 if (s32Error) {
5529 PRINT_ER("Failed to send message queue: Set join request\n"); 5489 PRINT_ER("Failed to send message queue: Set join request\n");
5530 WILC_ERRORREPORT(s32Error, WILC_FAIL); 5490 WILC_ERRORREPORT(s32Error, WILC_FAIL);
5531 } 5491 }
5532 5492
5533 enuScanConnTimer = CONNECT_TIMER; 5493 enuScanConnTimer = CONNECT_TIMER;
5534 WILC_TimerStart(&(pstrWFIDrv->hConnectTimer), HOST_IF_CONNECT_TIMEOUT, (void *) hWFIDrv, NULL); 5494 pstrWFIDrv->hConnectTimer.data = (unsigned long)hWFIDrv;
5495 mod_timer(&pstrWFIDrv->hConnectTimer,
5496 jiffies + msecs_to_jiffies(HOST_IF_CONNECT_TIMEOUT));
5535 5497
5536 WILC_CATCH(s32Error) 5498 WILC_CATCH(s32Error)
5537 { 5499 {
@@ -5553,7 +5515,7 @@ s32 host_int_set_join_req(WILC_WFIDrvHandle hWFIDrv, u8 *pu8bssid,
5553 * @version 8.0 5515 * @version 8.0
5554 */ 5516 */
5555 5517
5556s32 host_int_flush_join_req(WILC_WFIDrvHandle hWFIDrv) 5518s32 host_int_flush_join_req(tstrWILC_WFIDrv *hWFIDrv)
5557{ 5519{
5558 s32 s32Error = WILC_SUCCESS; 5520 s32 s32Error = WILC_SUCCESS;
5559 tstrHostIFmsg strHostIFmsg; 5521 tstrHostIFmsg strHostIFmsg;
@@ -5564,16 +5526,15 @@ s32 host_int_flush_join_req(WILC_WFIDrvHandle hWFIDrv)
5564 } 5526 }
5565 5527
5566 5528
5567 if (hWFIDrv == NULL) { 5529 if (hWFIDrv == NULL)
5568 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 5530 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5569 }
5570 5531
5571 5532
5572 strHostIFmsg.u16MsgId = HOST_IF_MSG_FLUSH_CONNECT; 5533 strHostIFmsg.u16MsgId = HOST_IF_MSG_FLUSH_CONNECT;
5573 strHostIFmsg.drvHandler = hWFIDrv; 5534 strHostIFmsg.drvHandler = hWFIDrv;
5574 5535
5575 /* send the message */ 5536 /* send the message */
5576 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 5537 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
5577 if (s32Error) { 5538 if (s32Error) {
5578 PRINT_ER("Failed to send message queue: Flush join request\n"); 5539 PRINT_ER("Failed to send message queue: Flush join request\n");
5579 WILC_ERRORREPORT(s32Error, WILC_FAIL); 5540 WILC_ERRORREPORT(s32Error, WILC_FAIL);
@@ -5597,14 +5558,14 @@ s32 host_int_flush_join_req(WILC_WFIDrvHandle hWFIDrv)
5597 * @date 8 March 2012 5558 * @date 8 March 2012
5598 * @version 1.0 5559 * @version 1.0
5599 */ 5560 */
5600s32 host_int_disconnect(WILC_WFIDrvHandle hWFIDrv, u16 u16ReasonCode) 5561s32 host_int_disconnect(tstrWILC_WFIDrv *hWFIDrv, u16 u16ReasonCode)
5601{ 5562{
5602 s32 s32Error = WILC_SUCCESS; 5563 s32 s32Error = WILC_SUCCESS;
5603 tstrHostIFmsg strHostIFmsg; 5564 tstrHostIFmsg strHostIFmsg;
5604 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 5565 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
5605 5566
5606 if (pstrWFIDrv == NULL) { 5567 if (pstrWFIDrv == NULL) {
5607 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL \n"); 5568 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL\n");
5608 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 5569 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5609 } 5570 }
5610 5571
@@ -5614,13 +5575,13 @@ s32 host_int_disconnect(WILC_WFIDrvHandle hWFIDrv, u16 u16ReasonCode)
5614 } 5575 }
5615 5576
5616 /* prepare the Disconnect Message */ 5577 /* prepare the Disconnect Message */
5617 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 5578 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5618 5579
5619 strHostIFmsg.u16MsgId = HOST_IF_MSG_DISCONNECT; 5580 strHostIFmsg.u16MsgId = HOST_IF_MSG_DISCONNECT;
5620 strHostIFmsg.drvHandler = hWFIDrv; 5581 strHostIFmsg.drvHandler = hWFIDrv;
5621 5582
5622 /* send the message */ 5583 /* send the message */
5623 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 5584 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
5624 if (s32Error) 5585 if (s32Error)
5625 PRINT_ER("Failed to send message queue: disconnect\n"); 5586 PRINT_ER("Failed to send message queue: disconnect\n");
5626 /* ////////////// */ 5587 /* ////////////// */
@@ -5646,7 +5607,7 @@ s32 host_int_disconnect(WILC_WFIDrvHandle hWFIDrv, u16 u16ReasonCode)
5646 * @date 8 March 2012 5607 * @date 8 March 2012
5647 * @version 1.0 5608 * @version 1.0
5648 */ 5609 */
5649s32 host_int_disconnect_station(WILC_WFIDrvHandle hWFIDrv, u8 assoc_id) 5610s32 host_int_disconnect_station(tstrWILC_WFIDrv *hWFIDrv, u8 assoc_id)
5650{ 5611{
5651 s32 s32Error = WILC_SUCCESS; 5612 s32 s32Error = WILC_SUCCESS;
5652 tstrWID strWID; 5613 tstrWID strWID;
@@ -5686,7 +5647,7 @@ s32 host_int_disconnect_station(WILC_WFIDrvHandle hWFIDrv, u8 assoc_id)
5686 * @version 1.0 5647 * @version 1.0
5687 */ 5648 */
5688 5649
5689s32 host_int_get_assoc_req_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8AssocReqInfo, 5650s32 host_int_get_assoc_req_info(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8AssocReqInfo,
5690 u32 u32AssocReqInfoLen) 5651 u32 u32AssocReqInfoLen)
5691{ 5652{
5692 s32 s32Error = WILC_SUCCESS; 5653 s32 s32Error = WILC_SUCCESS;
@@ -5713,7 +5674,7 @@ s32 host_int_get_assoc_req_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8AssocReqInfo,
5713 * @date 8 March 2012 5674 * @date 8 March 2012
5714 * @version 1.0 5675 * @version 1.0
5715 */ 5676 */
5716s32 host_int_get_assoc_res_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8AssocRespInfo, 5677s32 host_int_get_assoc_res_info(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8AssocRespInfo,
5717 u32 u32MaxAssocRespInfoLen, u32 *pu32RcvdAssocRespInfoLen) 5678 u32 u32MaxAssocRespInfoLen, u32 *pu32RcvdAssocRespInfoLen)
5718{ 5679{
5719 s32 s32Error = WILC_SUCCESS; 5680 s32 s32Error = WILC_SUCCESS;
@@ -5721,7 +5682,7 @@ s32 host_int_get_assoc_res_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8AssocRespInfo,
5721 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 5682 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
5722 5683
5723 if (pstrWFIDrv == NULL) { 5684 if (pstrWFIDrv == NULL) {
5724 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL \n"); 5685 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL\n");
5725 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 5686 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5726 } 5687 }
5727 5688
@@ -5763,7 +5724,7 @@ s32 host_int_get_assoc_res_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8AssocRespInfo,
5763 * @date 8 March 2012 5724 * @date 8 March 2012
5764 * @version 1.0 5725 * @version 1.0
5765 */ 5726 */
5766s32 host_int_get_rx_power_level(WILC_WFIDrvHandle hWFIDrv, u8 *pu8RxPowerLevel, 5727s32 host_int_get_rx_power_level(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8RxPowerLevel,
5767 u32 u32RxPowerLevelLen) 5728 u32 u32RxPowerLevelLen)
5768{ 5729{
5769 s32 s32Error = WILC_SUCCESS; 5730 s32 s32Error = WILC_SUCCESS;
@@ -5794,26 +5755,24 @@ s32 host_int_get_rx_power_level(WILC_WFIDrvHandle hWFIDrv, u8 *pu8RxPowerLevel,
5794 * @date 8 March 2012 5755 * @date 8 March 2012
5795 * @version 1.0 5756 * @version 1.0
5796 */ 5757 */
5797s32 host_int_set_mac_chnl_num(WILC_WFIDrvHandle hWFIDrv, u8 u8ChNum) 5758s32 host_int_set_mac_chnl_num(tstrWILC_WFIDrv *hWFIDrv, u8 u8ChNum)
5798{ 5759{
5799 s32 s32Error = WILC_SUCCESS; 5760 s32 s32Error = WILC_SUCCESS;
5800 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 5761 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
5801 tstrHostIFmsg strHostIFmsg; 5762 tstrHostIFmsg strHostIFmsg;
5802 5763
5803 if (pstrWFIDrv == NULL) { 5764 if (pstrWFIDrv == NULL)
5804 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 5765 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5805 }
5806 5766
5807 /* prepare the set channel message */ 5767 /* prepare the set channel message */
5808 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 5768 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5809 strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_CHANNEL; 5769 strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_CHANNEL;
5810 strHostIFmsg.uniHostIFmsgBody.strHostIFSetChan.u8SetChan = u8ChNum; 5770 strHostIFmsg.uniHostIFmsgBody.strHostIFSetChan.u8SetChan = u8ChNum;
5811 strHostIFmsg.drvHandler = hWFIDrv; 5771 strHostIFmsg.drvHandler = hWFIDrv;
5812 5772
5813 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 5773 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
5814 if (s32Error) { 5774 if (s32Error)
5815 WILC_ERRORREPORT(s32Error, s32Error); 5775 WILC_ERRORREPORT(s32Error, s32Error);
5816 }
5817 WILC_CATCH(s32Error) 5776 WILC_CATCH(s32Error)
5818 { 5777 {
5819 5778
@@ -5831,12 +5790,11 @@ s32 host_int_wait_msg_queue_idle(void)
5831 5790
5832 /* prepare the set driver handler message */ 5791 /* prepare the set driver handler message */
5833 5792
5834 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 5793 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5835 strHostIFmsg.u16MsgId = HOST_IF_MSG_Q_IDLE; 5794 strHostIFmsg.u16MsgId = HOST_IF_MSG_Q_IDLE;
5836 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 5795 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
5837 if (s32Error) { 5796 if (s32Error)
5838 WILC_ERRORREPORT(s32Error, s32Error); 5797 WILC_ERRORREPORT(s32Error, s32Error);
5839 }
5840 WILC_CATCH(s32Error) 5798 WILC_CATCH(s32Error)
5841 { 5799 {
5842 5800
@@ -5849,7 +5807,7 @@ s32 host_int_wait_msg_queue_idle(void)
5849 5807
5850} 5808}
5851 5809
5852s32 host_int_set_wfi_drv_handler(u32 u32address) 5810s32 host_int_set_wfi_drv_handler(tstrWILC_WFIDrv *u32address)
5853{ 5811{
5854 s32 s32Error = WILC_SUCCESS; 5812 s32 s32Error = WILC_SUCCESS;
5855 5813
@@ -5858,15 +5816,14 @@ s32 host_int_set_wfi_drv_handler(u32 u32address)
5858 5816
5859 /* prepare the set driver handler message */ 5817 /* prepare the set driver handler message */
5860 5818
5861 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 5819 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5862 strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_WFIDRV_HANDLER; 5820 strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_WFIDRV_HANDLER;
5863 strHostIFmsg.uniHostIFmsgBody.strHostIfSetDrvHandler.u32Address = u32address; 5821 strHostIFmsg.uniHostIFmsgBody.strHostIfSetDrvHandler.u32Address = u32address;
5864 /* strHostIFmsg.drvHandler=hWFIDrv; */ 5822 /* strHostIFmsg.drvHandler=hWFIDrv; */
5865 5823
5866 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 5824 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
5867 if (s32Error) { 5825 if (s32Error)
5868 WILC_ERRORREPORT(s32Error, s32Error); 5826 WILC_ERRORREPORT(s32Error, s32Error);
5869 }
5870 WILC_CATCH(s32Error) 5827 WILC_CATCH(s32Error)
5871 { 5828 {
5872 5829
@@ -5877,7 +5834,7 @@ s32 host_int_set_wfi_drv_handler(u32 u32address)
5877 5834
5878 5835
5879 5836
5880s32 host_int_set_operation_mode(WILC_WFIDrvHandle hWFIDrv, u32 u32mode) 5837s32 host_int_set_operation_mode(tstrWILC_WFIDrv *hWFIDrv, u32 u32mode)
5881{ 5838{
5882 s32 s32Error = WILC_SUCCESS; 5839 s32 s32Error = WILC_SUCCESS;
5883 5840
@@ -5886,15 +5843,14 @@ s32 host_int_set_operation_mode(WILC_WFIDrvHandle hWFIDrv, u32 u32mode)
5886 5843
5887 /* prepare the set driver handler message */ 5844 /* prepare the set driver handler message */
5888 5845
5889 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 5846 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5890 strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_OPERATION_MODE; 5847 strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_OPERATION_MODE;
5891 strHostIFmsg.uniHostIFmsgBody.strHostIfSetOperationMode.u32Mode = u32mode; 5848 strHostIFmsg.uniHostIFmsgBody.strHostIfSetOperationMode.u32Mode = u32mode;
5892 strHostIFmsg.drvHandler = hWFIDrv; 5849 strHostIFmsg.drvHandler = hWFIDrv;
5893 5850
5894 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 5851 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
5895 if (s32Error) { 5852 if (s32Error)
5896 WILC_ERRORREPORT(s32Error, s32Error); 5853 WILC_ERRORREPORT(s32Error, s32Error);
5897 }
5898 WILC_CATCH(s32Error) 5854 WILC_CATCH(s32Error)
5899 { 5855 {
5900 5856
@@ -5918,25 +5874,25 @@ s32 host_int_set_operation_mode(WILC_WFIDrvHandle hWFIDrv, u32 u32mode)
5918 * @date 8 March 2012 5874 * @date 8 March 2012
5919 * @version 1.0 5875 * @version 1.0
5920 */ 5876 */
5921s32 host_int_get_host_chnl_num(WILC_WFIDrvHandle hWFIDrv, u8 *pu8ChNo) 5877s32 host_int_get_host_chnl_num(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8ChNo)
5922{ 5878{
5923 s32 s32Error = WILC_SUCCESS; 5879 s32 s32Error = WILC_SUCCESS;
5924 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 5880 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
5925 tstrHostIFmsg strHostIFmsg; 5881 tstrHostIFmsg strHostIFmsg;
5926 5882
5927 if (pstrWFIDrv == NULL) { 5883 if (pstrWFIDrv == NULL) {
5928 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL \n"); 5884 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL\n");
5929 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 5885 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5930 } 5886 }
5931 5887
5932 /* prepare the Get Channel Message */ 5888 /* prepare the Get Channel Message */
5933 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 5889 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5934 5890
5935 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_CHNL; 5891 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_CHNL;
5936 strHostIFmsg.drvHandler = hWFIDrv; 5892 strHostIFmsg.drvHandler = hWFIDrv;
5937 5893
5938 /* send the message */ 5894 /* send the message */
5939 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 5895 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
5940 if (s32Error) 5896 if (s32Error)
5941 PRINT_ER("Failed to send get host channel param's message queue "); 5897 PRINT_ER("Failed to send get host channel param's message queue ");
5942 down(&(pstrWFIDrv->hSemGetCHNL)); 5898 down(&(pstrWFIDrv->hSemGetCHNL));
@@ -5964,7 +5920,7 @@ s32 host_int_get_host_chnl_num(WILC_WFIDrvHandle hWFIDrv, u8 *pu8ChNo)
5964 * @date 8 March 2012 5920 * @date 8 March 2012
5965 * @version 1.0 5921 * @version 1.0
5966 */ 5922 */
5967s32 host_int_test_set_int_wid(WILC_WFIDrvHandle hWFIDrv, u32 u32TestMemAddr) 5923s32 host_int_test_set_int_wid(tstrWILC_WFIDrv *hWFIDrv, u32 u32TestMemAddr)
5968{ 5924{
5969 s32 s32Error = WILC_SUCCESS; 5925 s32 s32Error = WILC_SUCCESS;
5970 tstrWID strWID; 5926 tstrWID strWID;
@@ -5972,7 +5928,7 @@ s32 host_int_test_set_int_wid(WILC_WFIDrvHandle hWFIDrv, u32 u32TestMemAddr)
5972 5928
5973 5929
5974 if (pstrWFIDrv == NULL) { 5930 if (pstrWFIDrv == NULL) {
5975 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL \n"); 5931 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL\n");
5976 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 5932 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5977 } 5933 }
5978 5934
@@ -6011,28 +5967,28 @@ s32 host_int_test_set_int_wid(WILC_WFIDrvHandle hWFIDrv, u32 u32TestMemAddr)
6011 * @date 5967 * @date
6012 * @version 1.0 5968 * @version 1.0
6013 */ 5969 */
6014s32 host_int_get_inactive_time(WILC_WFIDrvHandle hWFIDrv, const u8 *mac, u32 *pu32InactiveTime) 5970s32 host_int_get_inactive_time(tstrWILC_WFIDrv *hWFIDrv, const u8 *mac, u32 *pu32InactiveTime)
6015{ 5971{
6016 s32 s32Error = WILC_SUCCESS; 5972 s32 s32Error = WILC_SUCCESS;
6017 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 5973 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
6018 tstrHostIFmsg strHostIFmsg; 5974 tstrHostIFmsg strHostIFmsg;
6019 5975
6020 if (pstrWFIDrv == NULL) { 5976 if (pstrWFIDrv == NULL) {
6021 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL \n"); 5977 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL\n");
6022 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 5978 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
6023 } 5979 }
6024 5980
6025 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 5981 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6026 5982
6027 5983
6028 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIfStaInactiveT.mac, 5984 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIfStaInactiveT.mac,
6029 mac, ETH_ALEN); 5985 mac, ETH_ALEN);
6030 5986
6031 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_INACTIVETIME; 5987 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_INACTIVETIME;
6032 strHostIFmsg.drvHandler = hWFIDrv; 5988 strHostIFmsg.drvHandler = hWFIDrv;
6033 5989
6034 /* send the message */ 5990 /* send the message */
6035 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 5991 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
6036 if (s32Error) 5992 if (s32Error)
6037 PRINT_ER("Failed to send get host channel param's message queue "); 5993 PRINT_ER("Failed to send get host channel param's message queue ");
6038 5994
@@ -6057,7 +6013,7 @@ s32 host_int_get_inactive_time(WILC_WFIDrvHandle hWFIDrv, const u8 *mac, u32 *pu
6057 * @date 8 March 2012 6013 * @date 8 March 2012
6058 * @version 1.0 6014 * @version 1.0
6059 */ 6015 */
6060s32 host_int_test_get_int_wid(WILC_WFIDrvHandle hWFIDrv, u32 *pu32TestMemAddr) 6016s32 host_int_test_get_int_wid(tstrWILC_WFIDrv *hWFIDrv, u32 *pu32TestMemAddr)
6061{ 6017{
6062 6018
6063 s32 s32Error = WILC_SUCCESS; 6019 s32 s32Error = WILC_SUCCESS;
@@ -6066,7 +6022,7 @@ s32 host_int_test_get_int_wid(WILC_WFIDrvHandle hWFIDrv, u32 *pu32TestMemAddr)
6066 6022
6067 6023
6068 if (pstrWFIDrv == NULL) { 6024 if (pstrWFIDrv == NULL) {
6069 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL \n"); 6025 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL\n");
6070 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 6026 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
6071 } 6027 }
6072 6028
@@ -6106,7 +6062,7 @@ s32 host_int_test_get_int_wid(WILC_WFIDrvHandle hWFIDrv, u32 *pu32TestMemAddr)
6106 * @date 8 March 2012 6062 * @date 8 March 2012
6107 * @version 1.0 6063 * @version 1.0
6108 */ 6064 */
6109s32 host_int_get_rssi(WILC_WFIDrvHandle hWFIDrv, s8 *ps8Rssi) 6065s32 host_int_get_rssi(tstrWILC_WFIDrv *hWFIDrv, s8 *ps8Rssi)
6110{ 6066{
6111 s32 s32Error = WILC_SUCCESS; 6067 s32 s32Error = WILC_SUCCESS;
6112 tstrHostIFmsg strHostIFmsg; 6068 tstrHostIFmsg strHostIFmsg;
@@ -6114,13 +6070,13 @@ s32 host_int_get_rssi(WILC_WFIDrvHandle hWFIDrv, s8 *ps8Rssi)
6114 6070
6115 6071
6116 /* prepare the Get RSSI Message */ 6072 /* prepare the Get RSSI Message */
6117 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 6073 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6118 6074
6119 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_RSSI; 6075 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_RSSI;
6120 strHostIFmsg.drvHandler = hWFIDrv; 6076 strHostIFmsg.drvHandler = hWFIDrv;
6121 6077
6122 /* send the message */ 6078 /* send the message */
6123 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 6079 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
6124 if (s32Error) { 6080 if (s32Error) {
6125 PRINT_ER("Failed to send get host channel param's message queue "); 6081 PRINT_ER("Failed to send get host channel param's message queue ");
6126 return WILC_FAIL; 6082 return WILC_FAIL;
@@ -6141,7 +6097,7 @@ s32 host_int_get_rssi(WILC_WFIDrvHandle hWFIDrv, s8 *ps8Rssi)
6141 return s32Error; 6097 return s32Error;
6142} 6098}
6143 6099
6144s32 host_int_get_link_speed(WILC_WFIDrvHandle hWFIDrv, s8 *ps8lnkspd) 6100s32 host_int_get_link_speed(tstrWILC_WFIDrv *hWFIDrv, s8 *ps8lnkspd)
6145{ 6101{
6146 tstrHostIFmsg strHostIFmsg; 6102 tstrHostIFmsg strHostIFmsg;
6147 s32 s32Error = WILC_SUCCESS; 6103 s32 s32Error = WILC_SUCCESS;
@@ -6151,13 +6107,13 @@ s32 host_int_get_link_speed(WILC_WFIDrvHandle hWFIDrv, s8 *ps8lnkspd)
6151 6107
6152 6108
6153 /* prepare the Get LINKSPEED Message */ 6109 /* prepare the Get LINKSPEED Message */
6154 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 6110 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6155 6111
6156 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_LINKSPEED; 6112 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_LINKSPEED;
6157 strHostIFmsg.drvHandler = hWFIDrv; 6113 strHostIFmsg.drvHandler = hWFIDrv;
6158 6114
6159 /* send the message */ 6115 /* send the message */
6160 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 6116 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
6161 if (s32Error) { 6117 if (s32Error) {
6162 PRINT_ER("Failed to send GET_LINKSPEED to message queue "); 6118 PRINT_ER("Failed to send GET_LINKSPEED to message queue ");
6163 return WILC_FAIL; 6119 return WILC_FAIL;
@@ -6178,20 +6134,20 @@ s32 host_int_get_link_speed(WILC_WFIDrvHandle hWFIDrv, s8 *ps8lnkspd)
6178 return s32Error; 6134 return s32Error;
6179} 6135}
6180 6136
6181s32 host_int_get_statistics(WILC_WFIDrvHandle hWFIDrv, tstrStatistics *pstrStatistics) 6137s32 host_int_get_statistics(tstrWILC_WFIDrv *hWFIDrv, tstrStatistics *pstrStatistics)
6182{ 6138{
6183 s32 s32Error = WILC_SUCCESS; 6139 s32 s32Error = WILC_SUCCESS;
6184 tstrHostIFmsg strHostIFmsg; 6140 tstrHostIFmsg strHostIFmsg;
6185 6141
6186 6142
6187 /* prepare the Get RSSI Message */ 6143 /* prepare the Get RSSI Message */
6188 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 6144 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6189 6145
6190 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_STATISTICS; 6146 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_STATISTICS;
6191 strHostIFmsg.uniHostIFmsgBody.pUserData = (char *)pstrStatistics; 6147 strHostIFmsg.uniHostIFmsgBody.pUserData = (char *)pstrStatistics;
6192 strHostIFmsg.drvHandler = hWFIDrv; 6148 strHostIFmsg.drvHandler = hWFIDrv;
6193 /* send the message */ 6149 /* send the message */
6194 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 6150 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
6195 if (s32Error) { 6151 if (s32Error) {
6196 PRINT_ER("Failed to send get host channel param's message queue "); 6152 PRINT_ER("Failed to send get host channel param's message queue ");
6197 return WILC_FAIL; 6153 return WILC_FAIL;
@@ -6218,7 +6174,7 @@ s32 host_int_get_statistics(WILC_WFIDrvHandle hWFIDrv, tstrStatistics *pstrStati
6218 * @date 8 March 2012 6174 * @date 8 March 2012
6219 * @version 1.0 6175 * @version 1.0
6220 */ 6176 */
6221s32 host_int_scan(WILC_WFIDrvHandle hWFIDrv, u8 u8ScanSource, 6177s32 host_int_scan(tstrWILC_WFIDrv *hWFIDrv, u8 u8ScanSource,
6222 u8 u8ScanType, u8 *pu8ChnlFreqList, 6178 u8 u8ScanType, u8 *pu8ChnlFreqList,
6223 u8 u8ChnlListLen, const u8 *pu8IEs, 6179 u8 u8ChnlListLen, const u8 *pu8IEs,
6224 size_t IEsLen, tWILCpfScanResult ScanResult, 6180 size_t IEsLen, tWILCpfScanResult ScanResult,
@@ -6229,13 +6185,12 @@ s32 host_int_scan(WILC_WFIDrvHandle hWFIDrv, u8 u8ScanSource,
6229 tstrHostIFmsg strHostIFmsg; 6185 tstrHostIFmsg strHostIFmsg;
6230 tenuScanConnTimer enuScanConnTimer; 6186 tenuScanConnTimer enuScanConnTimer;
6231 6187
6232 if (pstrWFIDrv == NULL || ScanResult == NULL) { 6188 if (pstrWFIDrv == NULL || ScanResult == NULL)
6233 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 6189 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
6234 }
6235 6190
6236 6191
6237 /* prepare the Scan Message */ 6192 /* prepare the Scan Message */
6238 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 6193 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6239 6194
6240 strHostIFmsg.u16MsgId = HOST_IF_MSG_SCAN; 6195 strHostIFmsg.u16MsgId = HOST_IF_MSG_SCAN;
6241 6196
@@ -6253,17 +6208,17 @@ s32 host_int_scan(WILC_WFIDrvHandle hWFIDrv, u8 u8ScanSource,
6253 strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pvUserArg = pvUserArg; 6208 strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pvUserArg = pvUserArg;
6254 6209
6255 strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.u8ChnlListLen = u8ChnlListLen; 6210 strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.u8ChnlListLen = u8ChnlListLen;
6256 strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8ChnlFreqList = (u8 *)WILC_MALLOC(u8ChnlListLen); /* will be deallocated by the receiving thread */ 6211 strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8ChnlFreqList = WILC_MALLOC(u8ChnlListLen); /* will be deallocated by the receiving thread */
6257 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8ChnlFreqList, 6212 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8ChnlFreqList,
6258 pu8ChnlFreqList, u8ChnlListLen); 6213 pu8ChnlFreqList, u8ChnlListLen);
6259 6214
6260 strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.IEsLen = IEsLen; 6215 strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.IEsLen = IEsLen;
6261 strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8IEs = (u8 *)WILC_MALLOC(IEsLen); /* will be deallocated by the receiving thread */ 6216 strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8IEs = WILC_MALLOC(IEsLen); /* will be deallocated by the receiving thread */
6262 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8IEs, 6217 memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8IEs,
6263 pu8IEs, IEsLen); 6218 pu8IEs, IEsLen);
6264 6219
6265 /* send the message */ 6220 /* send the message */
6266 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 6221 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
6267 if (s32Error) { 6222 if (s32Error) {
6268 PRINT_ER("Error in sending message queue scanning parameters: Error(%d)\n", s32Error); 6223 PRINT_ER("Error in sending message queue scanning parameters: Error(%d)\n", s32Error);
6269 WILC_ERRORREPORT(s32Error, WILC_FAIL); 6224 WILC_ERRORREPORT(s32Error, WILC_FAIL);
@@ -6271,8 +6226,9 @@ s32 host_int_scan(WILC_WFIDrvHandle hWFIDrv, u8 u8ScanSource,
6271 6226
6272 enuScanConnTimer = SCAN_TIMER; 6227 enuScanConnTimer = SCAN_TIMER;
6273 PRINT_D(HOSTINF_DBG, ">> Starting the SCAN timer\n"); 6228 PRINT_D(HOSTINF_DBG, ">> Starting the SCAN timer\n");
6274 WILC_TimerStart(&(pstrWFIDrv->hScanTimer), HOST_IF_SCAN_TIMEOUT, (void *) hWFIDrv, NULL); 6229 pstrWFIDrv->hScanTimer.data = (unsigned long)hWFIDrv;
6275 6230 mod_timer(&pstrWFIDrv->hScanTimer,
6231 jiffies + msecs_to_jiffies(HOST_IF_SCAN_TIMEOUT));
6276 6232
6277 WILC_CATCH(s32Error) 6233 WILC_CATCH(s32Error)
6278 { 6234 {
@@ -6292,7 +6248,7 @@ s32 host_int_scan(WILC_WFIDrvHandle hWFIDrv, u8 u8ScanSource,
6292 * @date 8 March 2012 6248 * @date 8 March 2012
6293 * @version 1.0 6249 * @version 1.0
6294 */ 6250 */
6295s32 hif_set_cfg(WILC_WFIDrvHandle hWFIDrv, tstrCfgParamVal *pstrCfgParamVal) 6251s32 hif_set_cfg(tstrWILC_WFIDrv *hWFIDrv, tstrCfgParamVal *pstrCfgParamVal)
6296{ 6252{
6297 6253
6298 s32 s32Error = WILC_SUCCESS; 6254 s32 s32Error = WILC_SUCCESS;
@@ -6301,16 +6257,15 @@ s32 hif_set_cfg(WILC_WFIDrvHandle hWFIDrv, tstrCfgParamVal *pstrCfgParamVal)
6301 tstrHostIFmsg strHostIFmsg; 6257 tstrHostIFmsg strHostIFmsg;
6302 6258
6303 6259
6304 if (pstrWFIDrv == NULL) { 6260 if (pstrWFIDrv == NULL)
6305 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 6261 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
6306 }
6307 /* prepare the WiphyParams Message */ 6262 /* prepare the WiphyParams Message */
6308 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 6263 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6309 strHostIFmsg.u16MsgId = HOST_IF_MSG_CFG_PARAMS; 6264 strHostIFmsg.u16MsgId = HOST_IF_MSG_CFG_PARAMS;
6310 strHostIFmsg.uniHostIFmsgBody.strHostIFCfgParamAttr.pstrCfgParamVal = *pstrCfgParamVal; 6265 strHostIFmsg.uniHostIFmsgBody.strHostIFCfgParamAttr.pstrCfgParamVal = *pstrCfgParamVal;
6311 strHostIFmsg.drvHandler = hWFIDrv; 6266 strHostIFmsg.drvHandler = hWFIDrv;
6312 6267
6313 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 6268 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
6314 6269
6315 WILC_CATCH(s32Error) 6270 WILC_CATCH(s32Error)
6316 { 6271 {
@@ -6334,7 +6289,7 @@ s32 hif_set_cfg(WILC_WFIDrvHandle hWFIDrv, tstrCfgParamVal *pstrCfgParamVal)
6334 * @date 8 March 2012 6289 * @date 8 March 2012
6335 * @version 1.0 6290 * @version 1.0
6336 */ 6291 */
6337s32 hif_get_cfg(WILC_WFIDrvHandle hWFIDrv, u16 u16WID, u16 *pu16WID_Value) 6292s32 hif_get_cfg(tstrWILC_WFIDrv *hWFIDrv, u16 u16WID, u16 *pu16WID_Value)
6338{ 6293{
6339 s32 s32Error = WILC_SUCCESS; 6294 s32 s32Error = WILC_SUCCESS;
6340 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 6295 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
@@ -6342,7 +6297,7 @@ s32 hif_get_cfg(WILC_WFIDrvHandle hWFIDrv, u16 u16WID, u16 *pu16WID_Value)
6342 down(&(pstrWFIDrv->gtOsCfgValuesSem)); 6297 down(&(pstrWFIDrv->gtOsCfgValuesSem));
6343 6298
6344 if (pstrWFIDrv == NULL) { 6299 if (pstrWFIDrv == NULL) {
6345 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL \n"); 6300 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL\n");
6346 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 6301 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
6347 } 6302 }
6348 PRINT_D(HOSTINF_DBG, "Getting configuration parameters\n"); 6303 PRINT_D(HOSTINF_DBG, "Getting configuration parameters\n");
@@ -6469,9 +6424,10 @@ void host_int_send_join_leave_info_to_host
6469 * @version 1.0 6424 * @version 1.0
6470 */ 6425 */
6471 6426
6472void GetPeriodicRSSI(void *pvArg) 6427static void GetPeriodicRSSI(unsigned long arg)
6473{ 6428{
6474 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)pvArg; 6429 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)arg;
6430
6475 if (pstrWFIDrv == NULL) { 6431 if (pstrWFIDrv == NULL) {
6476 PRINT_ER("Driver handler is NULL\n"); 6432 PRINT_ER("Driver handler is NULL\n");
6477 return; 6433 return;
@@ -6482,19 +6438,20 @@ void GetPeriodicRSSI(void *pvArg)
6482 tstrHostIFmsg strHostIFmsg; 6438 tstrHostIFmsg strHostIFmsg;
6483 6439
6484 /* prepare the Get RSSI Message */ 6440 /* prepare the Get RSSI Message */
6485 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 6441 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6486 6442
6487 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_RSSI; 6443 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_RSSI;
6488 strHostIFmsg.drvHandler = pstrWFIDrv; 6444 strHostIFmsg.drvHandler = pstrWFIDrv;
6489 6445
6490 /* send the message */ 6446 /* send the message */
6491 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 6447 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
6492 if (s32Error) { 6448 if (s32Error) {
6493 PRINT_ER("Failed to send get host channel param's message queue "); 6449 PRINT_ER("Failed to send get host channel param's message queue ");
6494 return; 6450 return;
6495 } 6451 }
6496 } 6452 }
6497 WILC_TimerStart(&(g_hPeriodicRSSI), 5000, (void *)pstrWFIDrv, NULL); 6453 g_hPeriodicRSSI.data = (unsigned long)pstrWFIDrv;
6454 mod_timer(&g_hPeriodicRSSI, jiffies + msecs_to_jiffies(5000));
6498} 6455}
6499 6456
6500 6457
@@ -6515,7 +6472,7 @@ static u32 u32Intialized;
6515static u32 msgQ_created; 6472static u32 msgQ_created;
6516static u32 clients_count; 6473static u32 clients_count;
6517 6474
6518s32 host_int_init(WILC_WFIDrvHandle *phWFIDrv) 6475s32 host_int_init(tstrWILC_WFIDrv **phWFIDrv)
6519{ 6476{
6520 s32 s32Error = WILC_SUCCESS; 6477 s32 s32Error = WILC_SUCCESS;
6521 tstrWILC_WFIDrv *pstrWFIDrv; 6478 tstrWILC_WFIDrv *pstrWFIDrv;
@@ -6535,16 +6492,16 @@ s32 host_int_init(WILC_WFIDrvHandle *phWFIDrv)
6535 6492
6536 6493
6537 /*Allocate host interface private structure*/ 6494 /*Allocate host interface private structure*/
6538 pstrWFIDrv = (tstrWILC_WFIDrv *)WILC_MALLOC(sizeof(tstrWILC_WFIDrv)); 6495 pstrWFIDrv = WILC_MALLOC(sizeof(tstrWILC_WFIDrv));
6539 if (pstrWFIDrv == NULL) { 6496 if (pstrWFIDrv == NULL) {
6540 /* WILC_ERRORREPORT(s32Error,WILC_NO_MEM); */ 6497 /* WILC_ERRORREPORT(s32Error,WILC_NO_MEM); */
6541 s32Error = WILC_NO_MEM; 6498 s32Error = WILC_NO_MEM;
6542 PRINT_ER("Failed to allocate memory\n"); 6499 PRINT_ER("Failed to allocate memory\n");
6543 goto _fail_timer_2; 6500 goto _fail_timer_2;
6544 } 6501 }
6545 WILC_memset(pstrWFIDrv, 0, sizeof(tstrWILC_WFIDrv)); 6502 memset(pstrWFIDrv, 0, sizeof(tstrWILC_WFIDrv));
6546 /*return driver handle to user*/ 6503 /*return driver handle to user*/
6547 *phWFIDrv = (WILC_WFIDrvHandle)pstrWFIDrv; 6504 *phWFIDrv = pstrWFIDrv;
6548 /*save into globl handle*/ 6505 /*save into globl handle*/
6549 6506
6550 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 6507 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
@@ -6575,9 +6532,7 @@ s32 host_int_init(WILC_WFIDrvHandle *phWFIDrv)
6575 PRINT_D(HOSTINF_DBG, "INIT: CLIENT COUNT %d\n", clients_count); 6532 PRINT_D(HOSTINF_DBG, "INIT: CLIENT COUNT %d\n", clients_count);
6576 6533
6577 if (clients_count == 0) { 6534 if (clients_count == 0) {
6578 6535 s32Error = WILC_MsgQueueCreate(&gMsgQHostIF);
6579 s32Error = WILC_MsgQueueCreate(&gMsgQHostIF, NULL);
6580
6581 6536
6582 if (s32Error < 0) { 6537 if (s32Error < 0) {
6583 PRINT_ER("Failed to creat MQ\n"); 6538 PRINT_ER("Failed to creat MQ\n");
@@ -6590,47 +6545,24 @@ s32 host_int_init(WILC_WFIDrvHandle *phWFIDrv)
6590 s32Error = WILC_FAIL; 6545 s32Error = WILC_FAIL;
6591 goto _fail_mq_; 6546 goto _fail_mq_;
6592 } 6547 }
6593 s32Error = WILC_TimerCreate(&(g_hPeriodicRSSI), GetPeriodicRSSI, NULL); 6548 setup_timer(&g_hPeriodicRSSI, GetPeriodicRSSI,
6594 if (s32Error < 0) { 6549 (unsigned long)pstrWFIDrv);
6595 PRINT_ER("Failed to creat Timer\n"); 6550 mod_timer(&g_hPeriodicRSSI, jiffies + msecs_to_jiffies(5000));
6596 goto _fail_timer_1;
6597 }
6598 WILC_TimerStart(&(g_hPeriodicRSSI), 5000, (void *)pstrWFIDrv, NULL);
6599
6600 } 6551 }
6601 6552
6602 6553
6603 s32Error = WILC_TimerCreate(&(pstrWFIDrv->hScanTimer), TimerCB_Scan, NULL); 6554 setup_timer(&pstrWFIDrv->hScanTimer, TimerCB_Scan, 0);
6604 if (s32Error < 0) {
6605 PRINT_ER("Failed to creat Timer\n");
6606 goto _fail_thread_;
6607 }
6608
6609 s32Error = WILC_TimerCreate(&(pstrWFIDrv->hConnectTimer), TimerCB_Connect, NULL);
6610 if (s32Error < 0) {
6611 PRINT_ER("Failed to creat Timer\n");
6612 goto _fail_timer_1;
6613 }
6614 6555
6556 setup_timer(&pstrWFIDrv->hConnectTimer, TimerCB_Connect, 0);
6615 6557
6616 #ifdef WILC_P2P 6558 #ifdef WILC_P2P
6617 /*Remain on channel timer*/ 6559 /*Remain on channel timer*/
6618 s32Error = WILC_TimerCreate(&(pstrWFIDrv->hRemainOnChannel), ListenTimerCB, NULL); 6560 setup_timer(&pstrWFIDrv->hRemainOnChannel, ListenTimerCB, 0);
6619 if (s32Error < 0) {
6620 PRINT_ER("Failed to creat Remain-on-channel Timer\n");
6621 goto _fail_timer_3;
6622 }
6623 #endif 6561 #endif
6624 6562
6625 sema_init(&(pstrWFIDrv->gtOsCfgValuesSem), 1); 6563 sema_init(&(pstrWFIDrv->gtOsCfgValuesSem), 1);
6626 down(&(pstrWFIDrv->gtOsCfgValuesSem)); 6564 down(&(pstrWFIDrv->gtOsCfgValuesSem));
6627 6565
6628
6629
6630#ifdef SIMULATION
6631 TransportInit();
6632#endif
6633
6634 pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE; 6566 pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
6635 /* gWFiDrvHandle->bPendingConnRequest = false; */ 6567 /* gWFiDrvHandle->bPendingConnRequest = false; */
6636 6568
@@ -6666,11 +6598,6 @@ s32 host_int_init(WILC_WFIDrvHandle *phWFIDrv)
6666 goto _fail_mem_; 6598 goto _fail_mem_;
6667 } 6599 }
6668 6600
6669#ifdef SIMULATION
6670 /*Initialize Simulaor*/
6671 CoreConfigSimulatorInit();
6672#endif
6673
6674 u32Intialized = 1; 6601 u32Intialized = 1;
6675 clients_count++; /* increase number of created entities */ 6602 clients_count++; /* increase number of created entities */
6676 6603
@@ -6679,20 +6606,17 @@ s32 host_int_init(WILC_WFIDrvHandle *phWFIDrv)
6679 6606
6680_fail_mem_: 6607_fail_mem_:
6681 if (pstrWFIDrv != NULL) 6608 if (pstrWFIDrv != NULL)
6682 WILC_FREE(pstrWFIDrv); 6609 kfree(pstrWFIDrv);
6683#ifdef WILC_P2P 6610#ifdef WILC_P2P
6684_fail_timer_3: 6611 del_timer_sync(&pstrWFIDrv->hRemainOnChannel);
6685 WILC_TimerDestroy(&(pstrWFIDrv->hRemainOnChannel), NULL);
6686#endif 6612#endif
6687_fail_timer_2: 6613_fail_timer_2:
6688 up(&(pstrWFIDrv->gtOsCfgValuesSem)); 6614 up(&(pstrWFIDrv->gtOsCfgValuesSem));
6689 WILC_TimerDestroy(&(pstrWFIDrv->hConnectTimer), NULL); 6615 del_timer_sync(&pstrWFIDrv->hConnectTimer);
6690_fail_timer_1: 6616 del_timer_sync(&pstrWFIDrv->hScanTimer);
6691 WILC_TimerDestroy(&(pstrWFIDrv->hScanTimer), NULL);
6692_fail_thread_:
6693 kthread_stop(HostIFthreadHandler); 6617 kthread_stop(HostIFthreadHandler);
6694_fail_mq_: 6618_fail_mq_:
6695 WILC_MsgQueueDestroy(&gMsgQHostIF, NULL); 6619 WILC_MsgQueueDestroy(&gMsgQHostIF);
6696_fail_: 6620_fail_:
6697 return s32Error; 6621 return s32Error;
6698 6622
@@ -6708,7 +6632,7 @@ _fail_:
6708 * @version 1.0 6632 * @version 1.0
6709 */ 6633 */
6710 6634
6711s32 host_int_deinit(WILC_WFIDrvHandle hWFIDrv) 6635s32 host_int_deinit(tstrWILC_WFIDrv *hWFIDrv)
6712{ 6636{
6713 s32 s32Error = WILC_SUCCESS; 6637 s32 s32Error = WILC_SUCCESS;
6714 tstrHostIFmsg strHostIFmsg; 6638 tstrHostIFmsg strHostIFmsg;
@@ -6737,28 +6661,28 @@ s32 host_int_deinit(WILC_WFIDrvHandle hWFIDrv)
6737 /*BugID_5348*/ 6661 /*BugID_5348*/
6738 /*Destroy all timers before acquiring hSemDeinitDrvHandle*/ 6662 /*Destroy all timers before acquiring hSemDeinitDrvHandle*/
6739 /*to guarantee handling all messages befor proceeding*/ 6663 /*to guarantee handling all messages befor proceeding*/
6740 if (WILC_TimerDestroy(&(pstrWFIDrv->hScanTimer), NULL)) { 6664 if (del_timer_sync(&pstrWFIDrv->hScanTimer)) {
6741 PRINT_D(HOSTINF_DBG, ">> Scan timer is active \n"); 6665 PRINT_D(HOSTINF_DBG, ">> Scan timer is active\n");
6742 /* msleep(HOST_IF_SCAN_TIMEOUT+1000); */ 6666 /* msleep(HOST_IF_SCAN_TIMEOUT+1000); */
6743 } 6667 }
6744 6668
6745 if (WILC_TimerDestroy(&(pstrWFIDrv->hConnectTimer), NULL)) { 6669 if (del_timer_sync(&pstrWFIDrv->hConnectTimer)) {
6746 PRINT_D(HOSTINF_DBG, ">> Connect timer is active \n"); 6670 PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
6747 /* msleep(HOST_IF_CONNECT_TIMEOUT+1000); */ 6671 /* msleep(HOST_IF_CONNECT_TIMEOUT+1000); */
6748 } 6672 }
6749 6673
6750 6674
6751 if (WILC_TimerDestroy(&(g_hPeriodicRSSI), NULL)) { 6675 if (del_timer_sync(&g_hPeriodicRSSI)) {
6752 PRINT_D(HOSTINF_DBG, ">> Connect timer is active \n"); 6676 PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
6753 /* msleep(HOST_IF_CONNECT_TIMEOUT+1000); */ 6677 /* msleep(HOST_IF_CONNECT_TIMEOUT+1000); */
6754 } 6678 }
6755 6679
6756 #ifdef WILC_P2P 6680 #ifdef WILC_P2P
6757 /*Destroy Remain-onchannel Timer*/ 6681 /*Destroy Remain-onchannel Timer*/
6758 WILC_TimerDestroy(&(pstrWFIDrv->hRemainOnChannel), NULL); 6682 del_timer_sync(&pstrWFIDrv->hRemainOnChannel);
6759 #endif 6683 #endif
6760 6684
6761 host_int_set_wfi_drv_handler((u32)NULL); 6685 host_int_set_wfi_drv_handler(NULL);
6762 down(&hSemDeinitDrvHandle); 6686 down(&hSemDeinitDrvHandle);
6763 6687
6764 6688
@@ -6770,39 +6694,30 @@ s32 host_int_deinit(WILC_WFIDrvHandle hWFIDrv)
6770 pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult = NULL; 6694 pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult = NULL;
6771 } 6695 }
6772 /*deinit configurator and simulator*/ 6696 /*deinit configurator and simulator*/
6773#ifdef SIMULATION
6774 CoreConfigSimulatorDeInit();
6775#endif
6776 CoreConfiguratorDeInit(); 6697 CoreConfiguratorDeInit();
6777#ifdef SIMULATION
6778 TransportDeInit();
6779#endif
6780 6698
6781 pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE; 6699 pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
6782 6700
6783 gbScanWhileConnected = false; 6701 gbScanWhileConnected = false;
6784 6702
6785 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 6703 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6786 6704
6787 if (clients_count == 1) { 6705 if (clients_count == 1) {
6788 if (WILC_TimerDestroy(&g_hPeriodicRSSI, NULL)) { 6706 if (del_timer_sync(&g_hPeriodicRSSI)) {
6789 PRINT_D(HOSTINF_DBG, ">> Connect timer is active \n"); 6707 PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
6790 /* msleep(HOST_IF_CONNECT_TIMEOUT+1000); */ 6708 /* msleep(HOST_IF_CONNECT_TIMEOUT+1000); */
6791 } 6709 }
6792 strHostIFmsg.u16MsgId = HOST_IF_MSG_EXIT; 6710 strHostIFmsg.u16MsgId = HOST_IF_MSG_EXIT;
6793 strHostIFmsg.drvHandler = hWFIDrv; 6711 strHostIFmsg.drvHandler = hWFIDrv;
6794 6712
6795 6713
6796 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 6714 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
6797 if (s32Error != WILC_SUCCESS) { 6715 if (s32Error != WILC_SUCCESS)
6798 PRINT_ER("Error in sending deinit's message queue message function: Error(%d)\n", s32Error); 6716 PRINT_ER("Error in sending deinit's message queue message function: Error(%d)\n", s32Error);
6799 }
6800 6717
6801 down(&hSemHostIFthrdEnd); 6718 down(&hSemHostIFthrdEnd);
6802 6719
6803 6720 WILC_MsgQueueDestroy(&gMsgQHostIF);
6804
6805 WILC_MsgQueueDestroy(&gMsgQHostIF, NULL);
6806 msgQ_created = 0; 6721 msgQ_created = 0;
6807 } 6722 }
6808 6723
@@ -6812,7 +6727,7 @@ s32 host_int_deinit(WILC_WFIDrvHandle hWFIDrv)
6812 u32Intialized = 0; 6727 u32Intialized = 0;
6813 /* gWFiDrvHandle = NULL; */ 6728 /* gWFiDrvHandle = NULL; */
6814 if (pstrWFIDrv != NULL) { 6729 if (pstrWFIDrv != NULL) {
6815 WILC_FREE(pstrWFIDrv); 6730 kfree(pstrWFIDrv);
6816 /* pstrWFIDrv=NULL; */ 6731 /* pstrWFIDrv=NULL; */
6817 6732
6818 } 6733 }
@@ -6854,24 +6769,20 @@ void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length)
6854 } 6769 }
6855 6770
6856 /* prepare the Asynchronous Network Info message */ 6771 /* prepare the Asynchronous Network Info message */
6857 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 6772 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6858 6773
6859 strHostIFmsg.u16MsgId = HOST_IF_MSG_RCVD_NTWRK_INFO; 6774 strHostIFmsg.u16MsgId = HOST_IF_MSG_RCVD_NTWRK_INFO;
6860 strHostIFmsg.drvHandler = pstrWFIDrv; 6775 strHostIFmsg.drvHandler = pstrWFIDrv;
6861 6776
6862 strHostIFmsg.uniHostIFmsgBody.strRcvdNetworkInfo.u32Length = u32Length; 6777 strHostIFmsg.uniHostIFmsgBody.strRcvdNetworkInfo.u32Length = u32Length;
6863 strHostIFmsg.uniHostIFmsgBody.strRcvdNetworkInfo.pu8Buffer = (u8 *)WILC_MALLOC(u32Length); /* will be deallocated by the receiving thread */ 6778 strHostIFmsg.uniHostIFmsgBody.strRcvdNetworkInfo.pu8Buffer = WILC_MALLOC(u32Length); /* will be deallocated by the receiving thread */
6864 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strRcvdNetworkInfo.pu8Buffer, 6779 memcpy(strHostIFmsg.uniHostIFmsgBody.strRcvdNetworkInfo.pu8Buffer,
6865 pu8Buffer, u32Length); 6780 pu8Buffer, u32Length);
6866 6781
6867 /* send the message */ 6782 /* send the message */
6868 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 6783 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
6869 if (s32Error) { 6784 if (s32Error)
6870 PRINT_ER("Error in sending network info message queue message parameters: Error(%d)\n", s32Error); 6785 PRINT_ER("Error in sending network info message queue message parameters: Error(%d)\n", s32Error);
6871 }
6872
6873
6874 return;
6875} 6786}
6876 6787
6877/** 6788/**
@@ -6897,7 +6808,7 @@ void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length)
6897 6808
6898 drvHandler = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24)); 6809 drvHandler = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
6899 pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler; 6810 pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
6900 PRINT_D(HOSTINF_DBG, "General asynchronous info packet received \n"); 6811 PRINT_D(HOSTINF_DBG, "General asynchronous info packet received\n");
6901 6812
6902 6813
6903 if (pstrWFIDrv == NULL || pstrWFIDrv == terminated_handle) { 6814 if (pstrWFIDrv == NULL || pstrWFIDrv == terminated_handle) {
@@ -6916,7 +6827,7 @@ void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length)
6916 } 6827 }
6917 6828
6918 /* prepare the General Asynchronous Info message */ 6829 /* prepare the General Asynchronous Info message */
6919 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 6830 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6920 6831
6921 6832
6922 strHostIFmsg.u16MsgId = HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO; 6833 strHostIFmsg.u16MsgId = HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO;
@@ -6924,19 +6835,17 @@ void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length)
6924 6835
6925 6836
6926 strHostIFmsg.uniHostIFmsgBody.strRcvdGnrlAsyncInfo.u32Length = u32Length; 6837 strHostIFmsg.uniHostIFmsgBody.strRcvdGnrlAsyncInfo.u32Length = u32Length;
6927 strHostIFmsg.uniHostIFmsgBody.strRcvdGnrlAsyncInfo.pu8Buffer = (u8 *)WILC_MALLOC(u32Length); /* will be deallocated by the receiving thread */ 6838 strHostIFmsg.uniHostIFmsgBody.strRcvdGnrlAsyncInfo.pu8Buffer = WILC_MALLOC(u32Length); /* will be deallocated by the receiving thread */
6928 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strRcvdGnrlAsyncInfo.pu8Buffer, 6839 memcpy(strHostIFmsg.uniHostIFmsgBody.strRcvdGnrlAsyncInfo.pu8Buffer,
6929 pu8Buffer, u32Length); 6840 pu8Buffer, u32Length);
6930 6841
6931 /* send the message */ 6842 /* send the message */
6932 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 6843 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
6933 if (s32Error) { 6844 if (s32Error)
6934 PRINT_ER("Error in sending message queue asynchronous message info: Error(%d)\n", s32Error); 6845 PRINT_ER("Error in sending message queue asynchronous message info: Error(%d)\n", s32Error);
6935 }
6936 6846
6937 /*BugID_5348*/ 6847 /*BugID_5348*/
6938 up(&hSemHostIntDeinit); 6848 up(&hSemHostIntDeinit);
6939 return;
6940} 6849}
6941 6850
6942/** 6851/**
@@ -6954,20 +6863,20 @@ void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length)
6954 tstrHostIFmsg strHostIFmsg; 6863 tstrHostIFmsg strHostIFmsg;
6955 u32 drvHandler; 6864 u32 drvHandler;
6956 tstrWILC_WFIDrv *pstrWFIDrv = NULL; 6865 tstrWILC_WFIDrv *pstrWFIDrv = NULL;
6866
6957 drvHandler = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24)); 6867 drvHandler = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
6958 pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler; 6868 pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
6959 6869
6960 6870
6961 PRINT_D(GENERIC_DBG, "Scan notification received %p\n", pstrWFIDrv); 6871 PRINT_D(GENERIC_DBG, "Scan notification received %p\n", pstrWFIDrv);
6962 6872
6963 if (pstrWFIDrv == NULL || pstrWFIDrv == terminated_handle) { 6873 if (pstrWFIDrv == NULL || pstrWFIDrv == terminated_handle)
6964 return; 6874 return;
6965 }
6966 6875
6967 /*if there is an ongoing scan request*/ 6876 /*if there is an ongoing scan request*/
6968 if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) { 6877 if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
6969 /* prepare theScan Done message */ 6878 /* prepare theScan Done message */
6970 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 6879 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6971 6880
6972 strHostIFmsg.u16MsgId = HOST_IF_MSG_RCVD_SCAN_COMPLETE; 6881 strHostIFmsg.u16MsgId = HOST_IF_MSG_RCVD_SCAN_COMPLETE;
6973 strHostIFmsg.drvHandler = pstrWFIDrv; 6882 strHostIFmsg.drvHandler = pstrWFIDrv;
@@ -6978,14 +6887,13 @@ void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length)
6978 6887
6979 /*strHostIFmsg.uniHostIFmsgBody.strScanComplete.u32Length = u32Length; 6888 /*strHostIFmsg.uniHostIFmsgBody.strScanComplete.u32Length = u32Length;
6980 * strHostIFmsg.uniHostIFmsgBody.strScanComplete.pu8Buffer = (u8*)WILC_MALLOC(u32Length); 6889 * strHostIFmsg.uniHostIFmsgBody.strScanComplete.pu8Buffer = (u8*)WILC_MALLOC(u32Length);
6981 * WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strScanComplete.pu8Buffer, 6890 * memcpy(strHostIFmsg.uniHostIFmsgBody.strScanComplete.pu8Buffer,
6982 * pu8Buffer, u32Length); */ 6891 * pu8Buffer, u32Length); */
6983 6892
6984 /* send the message */ 6893 /* send the message */
6985 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 6894 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
6986 if (s32Error) { 6895 if (s32Error)
6987 PRINT_ER("Error in sending message queue scan complete parameters: Error(%d)\n", s32Error); 6896 PRINT_ER("Error in sending message queue scan complete parameters: Error(%d)\n", s32Error);
6988 }
6989 } 6897 }
6990 6898
6991 6899
@@ -7008,18 +6916,17 @@ void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length)
7008 * @date 6916 * @date
7009 * @version 1.0 6917 * @version 1.0
7010 */ 6918 */
7011s32 host_int_remain_on_channel(WILC_WFIDrvHandle hWFIDrv, u32 u32SessionID, u32 u32duration, u16 chan, tWILCpfRemainOnChanExpired RemainOnChanExpired, tWILCpfRemainOnChanReady RemainOnChanReady, void *pvUserArg) 6919s32 host_int_remain_on_channel(tstrWILC_WFIDrv *hWFIDrv, u32 u32SessionID, u32 u32duration, u16 chan, tWILCpfRemainOnChanExpired RemainOnChanExpired, tWILCpfRemainOnChanReady RemainOnChanReady, void *pvUserArg)
7012{ 6920{
7013 s32 s32Error = WILC_SUCCESS; 6921 s32 s32Error = WILC_SUCCESS;
7014 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 6922 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7015 tstrHostIFmsg strHostIFmsg; 6923 tstrHostIFmsg strHostIFmsg;
7016 6924
7017 if (pstrWFIDrv == NULL) { 6925 if (pstrWFIDrv == NULL)
7018 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 6926 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7019 }
7020 6927
7021 /* prepare the remainonchan Message */ 6928 /* prepare the remainonchan Message */
7022 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 6929 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7023 6930
7024 /* prepare the WiphyParams Message */ 6931 /* prepare the WiphyParams Message */
7025 strHostIFmsg.u16MsgId = HOST_IF_MSG_REMAIN_ON_CHAN; 6932 strHostIFmsg.u16MsgId = HOST_IF_MSG_REMAIN_ON_CHAN;
@@ -7031,10 +6938,9 @@ s32 host_int_remain_on_channel(WILC_WFIDrvHandle hWFIDrv, u32 u32SessionID, u32
7031 strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u32ListenSessionID = u32SessionID; 6938 strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u32ListenSessionID = u32SessionID;
7032 strHostIFmsg.drvHandler = hWFIDrv; 6939 strHostIFmsg.drvHandler = hWFIDrv;
7033 6940
7034 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 6941 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7035 if (s32Error) { 6942 if (s32Error)
7036 WILC_ERRORREPORT(s32Error, s32Error); 6943 WILC_ERRORREPORT(s32Error, s32Error);
7037 }
7038 WILC_CATCH(s32Error) 6944 WILC_CATCH(s32Error)
7039 { 6945 {
7040 6946
@@ -7057,29 +6963,27 @@ s32 host_int_remain_on_channel(WILC_WFIDrvHandle hWFIDrv, u32 u32SessionID, u32
7057 * @date 6963 * @date
7058 * @version 1.0 6964 * @version 1.0
7059 */ 6965 */
7060s32 host_int_ListenStateExpired(WILC_WFIDrvHandle hWFIDrv, u32 u32SessionID) 6966s32 host_int_ListenStateExpired(tstrWILC_WFIDrv *hWFIDrv, u32 u32SessionID)
7061{ 6967{
7062 s32 s32Error = WILC_SUCCESS; 6968 s32 s32Error = WILC_SUCCESS;
7063 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 6969 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7064 tstrHostIFmsg strHostIFmsg; 6970 tstrHostIFmsg strHostIFmsg;
7065 6971
7066 if (pstrWFIDrv == NULL) { 6972 if (pstrWFIDrv == NULL)
7067 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 6973 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7068 }
7069 6974
7070 /*Stopping remain-on-channel timer*/ 6975 /*Stopping remain-on-channel timer*/
7071 WILC_TimerStop(&(pstrWFIDrv->hRemainOnChannel), NULL); 6976 del_timer(&pstrWFIDrv->hRemainOnChannel);
7072 6977
7073 /* prepare the timer fire Message */ 6978 /* prepare the timer fire Message */
7074 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 6979 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7075 strHostIFmsg.u16MsgId = HOST_IF_MSG_LISTEN_TIMER_FIRED; 6980 strHostIFmsg.u16MsgId = HOST_IF_MSG_LISTEN_TIMER_FIRED;
7076 strHostIFmsg.drvHandler = hWFIDrv; 6981 strHostIFmsg.drvHandler = hWFIDrv;
7077 strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u32ListenSessionID = u32SessionID; 6982 strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u32ListenSessionID = u32SessionID;
7078 6983
7079 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 6984 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7080 if (s32Error) { 6985 if (s32Error)
7081 WILC_ERRORREPORT(s32Error, s32Error); 6986 WILC_ERRORREPORT(s32Error, s32Error);
7082 }
7083 WILC_CATCH(s32Error) 6987 WILC_CATCH(s32Error)
7084 { 6988 {
7085 6989
@@ -7095,17 +6999,16 @@ s32 host_int_ListenStateExpired(WILC_WFIDrvHandle hWFIDrv, u32 u32SessionID)
7095 * @author 6999 * @author
7096 * @date 7000 * @date
7097 * @version 1.0*/ 7001 * @version 1.0*/
7098s32 host_int_frame_register(WILC_WFIDrvHandle hWFIDrv, u16 u16FrameType, bool bReg) 7002s32 host_int_frame_register(tstrWILC_WFIDrv *hWFIDrv, u16 u16FrameType, bool bReg)
7099{ 7003{
7100 s32 s32Error = WILC_SUCCESS; 7004 s32 s32Error = WILC_SUCCESS;
7101 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 7005 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7102 tstrHostIFmsg strHostIFmsg; 7006 tstrHostIFmsg strHostIFmsg;
7103 7007
7104 if (pstrWFIDrv == NULL) { 7008 if (pstrWFIDrv == NULL)
7105 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 7009 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7106 }
7107 7010
7108 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 7011 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7109 7012
7110 /* prepare the WiphyParams Message */ 7013 /* prepare the WiphyParams Message */
7111 strHostIFmsg.u16MsgId = HOST_IF_MSG_REGISTER_FRAME; 7014 strHostIFmsg.u16MsgId = HOST_IF_MSG_REGISTER_FRAME;
@@ -7128,10 +7031,9 @@ s32 host_int_frame_register(WILC_WFIDrvHandle hWFIDrv, u16 u16FrameType, bool bR
7128 strHostIFmsg.uniHostIFmsgBody.strHostIfRegisterFrame.bReg = bReg; 7031 strHostIFmsg.uniHostIFmsgBody.strHostIfRegisterFrame.bReg = bReg;
7129 strHostIFmsg.drvHandler = hWFIDrv; 7032 strHostIFmsg.drvHandler = hWFIDrv;
7130 7033
7131 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 7034 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7132 if (s32Error) { 7035 if (s32Error)
7133 WILC_ERRORREPORT(s32Error, s32Error); 7036 WILC_ERRORREPORT(s32Error, s32Error);
7134 }
7135 WILC_CATCH(s32Error) 7037 WILC_CATCH(s32Error)
7136 { 7038 {
7137 7039
@@ -7155,7 +7057,7 @@ s32 host_int_frame_register(WILC_WFIDrvHandle hWFIDrv, u16 u16FrameType, bool bR
7155 * @date 7057 * @date
7156 * @version 1.0 7058 * @version 1.0
7157 */ 7059 */
7158s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval, 7060s32 host_int_add_beacon(tstrWILC_WFIDrv *hWFIDrv, u32 u32Interval,
7159 u32 u32DTIMPeriod, 7061 u32 u32DTIMPeriod,
7160 u32 u32HeadLen, u8 *pu8Head, 7062 u32 u32HeadLen, u8 *pu8Head,
7161 u32 u32TailLen, u8 *pu8Tail) 7063 u32 u32TailLen, u8 *pu8Tail)
@@ -7165,11 +7067,10 @@ s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval,
7165 tstrHostIFmsg strHostIFmsg; 7067 tstrHostIFmsg strHostIFmsg;
7166 tstrHostIFSetBeacon *pstrSetBeaconParam = &strHostIFmsg.uniHostIFmsgBody.strHostIFSetBeacon; 7068 tstrHostIFSetBeacon *pstrSetBeaconParam = &strHostIFmsg.uniHostIFmsgBody.strHostIFSetBeacon;
7167 7069
7168 if (pstrWFIDrv == NULL) { 7070 if (pstrWFIDrv == NULL)
7169 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 7071 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7170 }
7171 7072
7172 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 7073 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7173 7074
7174 PRINT_D(HOSTINF_DBG, "Setting adding beacon message queue params\n"); 7075 PRINT_D(HOSTINF_DBG, "Setting adding beacon message queue params\n");
7175 7076
@@ -7180,38 +7081,33 @@ s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval,
7180 pstrSetBeaconParam->u32Interval = u32Interval; 7081 pstrSetBeaconParam->u32Interval = u32Interval;
7181 pstrSetBeaconParam->u32DTIMPeriod = u32DTIMPeriod; 7082 pstrSetBeaconParam->u32DTIMPeriod = u32DTIMPeriod;
7182 pstrSetBeaconParam->u32HeadLen = u32HeadLen; 7083 pstrSetBeaconParam->u32HeadLen = u32HeadLen;
7183 pstrSetBeaconParam->pu8Head = (u8 *)WILC_MALLOC(u32HeadLen); 7084 pstrSetBeaconParam->pu8Head = WILC_MALLOC(u32HeadLen);
7184 if (pstrSetBeaconParam->pu8Head == NULL) { 7085 if (pstrSetBeaconParam->pu8Head == NULL)
7185 WILC_ERRORREPORT(s32Error, WILC_NO_MEM); 7086 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
7186 } 7087 memcpy(pstrSetBeaconParam->pu8Head, pu8Head, u32HeadLen);
7187 WILC_memcpy(pstrSetBeaconParam->pu8Head, pu8Head, u32HeadLen);
7188 pstrSetBeaconParam->u32TailLen = u32TailLen; 7088 pstrSetBeaconParam->u32TailLen = u32TailLen;
7189 7089
7190 /* Bug 4599 : if tail length = 0 skip allocating & copying */ 7090 /* Bug 4599 : if tail length = 0 skip allocating & copying */
7191 if (u32TailLen > 0) { 7091 if (u32TailLen > 0) {
7192 pstrSetBeaconParam->pu8Tail = (u8 *)WILC_MALLOC(u32TailLen); 7092 pstrSetBeaconParam->pu8Tail = WILC_MALLOC(u32TailLen);
7193 if (pstrSetBeaconParam->pu8Tail == NULL) { 7093 if (pstrSetBeaconParam->pu8Tail == NULL)
7194 WILC_ERRORREPORT(s32Error, WILC_NO_MEM); 7094 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
7195 } 7095 memcpy(pstrSetBeaconParam->pu8Tail, pu8Tail, u32TailLen);
7196 WILC_memcpy(pstrSetBeaconParam->pu8Tail, pu8Tail, u32TailLen);
7197 } else { 7096 } else {
7198 pstrSetBeaconParam->pu8Tail = NULL; 7097 pstrSetBeaconParam->pu8Tail = NULL;
7199 } 7098 }
7200 7099
7201 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 7100 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7202 if (s32Error) { 7101 if (s32Error)
7203 WILC_ERRORREPORT(s32Error, s32Error); 7102 WILC_ERRORREPORT(s32Error, s32Error);
7204 }
7205 7103
7206 WILC_CATCH(s32Error) 7104 WILC_CATCH(s32Error)
7207 { 7105 {
7208 if (pstrSetBeaconParam->pu8Head != NULL) { 7106 if (pstrSetBeaconParam->pu8Head != NULL)
7209 WILC_FREE(pstrSetBeaconParam->pu8Head); 7107 kfree(pstrSetBeaconParam->pu8Head);
7210 }
7211 7108
7212 if (pstrSetBeaconParam->pu8Tail != NULL) { 7109 if (pstrSetBeaconParam->pu8Tail != NULL)
7213 WILC_FREE(pstrSetBeaconParam->pu8Tail); 7110 kfree(pstrSetBeaconParam->pu8Tail);
7214 }
7215 } 7111 }
7216 7112
7217 return s32Error; 7113 return s32Error;
@@ -7228,22 +7124,21 @@ s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval,
7228 * @date 7124 * @date
7229 * @version 1.0 7125 * @version 1.0
7230 */ 7126 */
7231s32 host_int_del_beacon(WILC_WFIDrvHandle hWFIDrv) 7127s32 host_int_del_beacon(tstrWILC_WFIDrv *hWFIDrv)
7232{ 7128{
7233 s32 s32Error = WILC_SUCCESS; 7129 s32 s32Error = WILC_SUCCESS;
7234 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 7130 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7235 tstrHostIFmsg strHostIFmsg; 7131 tstrHostIFmsg strHostIFmsg;
7236 7132
7237 if (pstrWFIDrv == NULL) { 7133 if (pstrWFIDrv == NULL)
7238 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 7134 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7239 }
7240 7135
7241 /* prepare the WiphyParams Message */ 7136 /* prepare the WiphyParams Message */
7242 strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_BEACON; 7137 strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_BEACON;
7243 strHostIFmsg.drvHandler = hWFIDrv; 7138 strHostIFmsg.drvHandler = hWFIDrv;
7244 PRINT_D(HOSTINF_DBG, "Setting deleting beacon message queue params\n"); 7139 PRINT_D(HOSTINF_DBG, "Setting deleting beacon message queue params\n");
7245 7140
7246 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 7141 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7247 WILC_ERRORCHECK(s32Error); 7142 WILC_ERRORCHECK(s32Error);
7248 7143
7249 WILC_CATCH(s32Error) 7144 WILC_CATCH(s32Error)
@@ -7262,7 +7157,7 @@ s32 host_int_del_beacon(WILC_WFIDrvHandle hWFIDrv)
7262 * @date 7157 * @date
7263 * @version 1.0 7158 * @version 1.0
7264 */ 7159 */
7265s32 host_int_add_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam *pstrStaParams) 7160s32 host_int_add_station(tstrWILC_WFIDrv *hWFIDrv, tstrWILC_AddStaParam *pstrStaParams)
7266{ 7161{
7267 s32 s32Error = WILC_SUCCESS; 7162 s32 s32Error = WILC_SUCCESS;
7268 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 7163 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
@@ -7270,11 +7165,10 @@ s32 host_int_add_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam *pstrSt
7270 tstrWILC_AddStaParam *pstrAddStationMsg = &strHostIFmsg.uniHostIFmsgBody.strAddStaParam; 7165 tstrWILC_AddStaParam *pstrAddStationMsg = &strHostIFmsg.uniHostIFmsgBody.strAddStaParam;
7271 7166
7272 7167
7273 if (pstrWFIDrv == NULL) { 7168 if (pstrWFIDrv == NULL)
7274 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 7169 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7275 }
7276 7170
7277 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 7171 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7278 7172
7279 PRINT_D(HOSTINF_DBG, "Setting adding station message queue params\n"); 7173 PRINT_D(HOSTINF_DBG, "Setting adding station message queue params\n");
7280 7174
@@ -7283,20 +7177,20 @@ s32 host_int_add_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam *pstrSt
7283 strHostIFmsg.u16MsgId = HOST_IF_MSG_ADD_STATION; 7177 strHostIFmsg.u16MsgId = HOST_IF_MSG_ADD_STATION;
7284 strHostIFmsg.drvHandler = hWFIDrv; 7178 strHostIFmsg.drvHandler = hWFIDrv;
7285 7179
7286 WILC_memcpy(pstrAddStationMsg, pstrStaParams, sizeof(tstrWILC_AddStaParam)); 7180 memcpy(pstrAddStationMsg, pstrStaParams, sizeof(tstrWILC_AddStaParam));
7287 if (pstrAddStationMsg->u8NumRates > 0) { 7181 if (pstrAddStationMsg->u8NumRates > 0) {
7288 u8 *rates = WILC_MALLOC(pstrAddStationMsg->u8NumRates); 7182 u8 *rates = WILC_MALLOC(pstrAddStationMsg->u8NumRates);
7183
7289 WILC_NULLCHECK(s32Error, rates); 7184 WILC_NULLCHECK(s32Error, rates);
7290 7185
7291 WILC_memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates); 7186 memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates);
7292 pstrAddStationMsg->pu8Rates = rates; 7187 pstrAddStationMsg->pu8Rates = rates;
7293 } 7188 }
7294 7189
7295 7190
7296 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 7191 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7297 if (s32Error) { 7192 if (s32Error)
7298 WILC_ERRORREPORT(s32Error, s32Error); 7193 WILC_ERRORREPORT(s32Error, s32Error);
7299 }
7300 7194
7301 WILC_CATCH(s32Error) 7195 WILC_CATCH(s32Error)
7302 { 7196 {
@@ -7313,18 +7207,17 @@ s32 host_int_add_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam *pstrSt
7313 * @date 7207 * @date
7314 * @version 1.0 7208 * @version 1.0
7315 */ 7209 */
7316s32 host_int_del_station(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8MacAddr) 7210s32 host_int_del_station(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8MacAddr)
7317{ 7211{
7318 s32 s32Error = WILC_SUCCESS; 7212 s32 s32Error = WILC_SUCCESS;
7319 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 7213 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7320 tstrHostIFmsg strHostIFmsg; 7214 tstrHostIFmsg strHostIFmsg;
7321 tstrHostIFDelSta *pstrDelStationMsg = &strHostIFmsg.uniHostIFmsgBody.strDelStaParam; 7215 tstrHostIFDelSta *pstrDelStationMsg = &strHostIFmsg.uniHostIFmsgBody.strDelStaParam;
7322 7216
7323 if (pstrWFIDrv == NULL) { 7217 if (pstrWFIDrv == NULL)
7324 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 7218 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7325 }
7326 7219
7327 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 7220 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7328 7221
7329 PRINT_D(HOSTINF_DBG, "Setting deleting station message queue params\n"); 7222 PRINT_D(HOSTINF_DBG, "Setting deleting station message queue params\n");
7330 7223
@@ -7336,14 +7229,13 @@ s32 host_int_del_station(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8MacAddr)
7336 7229
7337 /*BugID_4795: Handling situation of deleting all stations*/ 7230 /*BugID_4795: Handling situation of deleting all stations*/
7338 if (pu8MacAddr == NULL) 7231 if (pu8MacAddr == NULL)
7339 WILC_memset(pstrDelStationMsg->au8MacAddr, 255, ETH_ALEN); 7232 memset(pstrDelStationMsg->au8MacAddr, 255, ETH_ALEN);
7340 else 7233 else
7341 WILC_memcpy(pstrDelStationMsg->au8MacAddr, pu8MacAddr, ETH_ALEN); 7234 memcpy(pstrDelStationMsg->au8MacAddr, pu8MacAddr, ETH_ALEN);
7342 7235
7343 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 7236 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7344 if (s32Error) { 7237 if (s32Error)
7345 WILC_ERRORREPORT(s32Error, s32Error); 7238 WILC_ERRORREPORT(s32Error, s32Error);
7346 }
7347 7239
7348 WILC_CATCH(s32Error) 7240 WILC_CATCH(s32Error)
7349 { 7241 {
@@ -7359,7 +7251,7 @@ s32 host_int_del_station(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8MacAddr)
7359 * @date 7251 * @date
7360 * @version 1.0 7252 * @version 1.0
7361 */ 7253 */
7362s32 host_int_del_allstation(WILC_WFIDrvHandle hWFIDrv, u8 pu8MacAddr[][ETH_ALEN]) 7254s32 host_int_del_allstation(tstrWILC_WFIDrv *hWFIDrv, u8 pu8MacAddr[][ETH_ALEN])
7363{ 7255{
7364 s32 s32Error = WILC_SUCCESS; 7256 s32 s32Error = WILC_SUCCESS;
7365 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 7257 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
@@ -7370,11 +7262,10 @@ s32 host_int_del_allstation(WILC_WFIDrvHandle hWFIDrv, u8 pu8MacAddr[][ETH_ALEN]
7370 u8 u8AssocNumb = 0; 7262 u8 u8AssocNumb = 0;
7371 7263
7372 7264
7373 if (pstrWFIDrv == NULL) { 7265 if (pstrWFIDrv == NULL)
7374 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 7266 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7375 }
7376 7267
7377 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 7268 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7378 7269
7379 PRINT_D(HOSTINF_DBG, "Setting deauthenticating station message queue params\n"); 7270 PRINT_D(HOSTINF_DBG, "Setting deauthenticating station message queue params\n");
7380 7271
@@ -7385,7 +7276,7 @@ s32 host_int_del_allstation(WILC_WFIDrvHandle hWFIDrv, u8 pu8MacAddr[][ETH_ALEN]
7385 /* Handling situation of deauthenticing all associated stations*/ 7276 /* Handling situation of deauthenticing all associated stations*/
7386 for (i = 0; i < MAX_NUM_STA; i++) { 7277 for (i = 0; i < MAX_NUM_STA; i++) {
7387 if (memcmp(pu8MacAddr[i], au8Zero_Buff, ETH_ALEN)) { 7278 if (memcmp(pu8MacAddr[i], au8Zero_Buff, ETH_ALEN)) {
7388 WILC_memcpy(pstrDelAllStationMsg->au8Sta_DelAllSta[i], pu8MacAddr[i], ETH_ALEN); 7279 memcpy(pstrDelAllStationMsg->au8Sta_DelAllSta[i], pu8MacAddr[i], ETH_ALEN);
7389 PRINT_D(CFG80211_DBG, "BSSID = %x%x%x%x%x%x\n", pstrDelAllStationMsg->au8Sta_DelAllSta[i][0], pstrDelAllStationMsg->au8Sta_DelAllSta[i][1], pstrDelAllStationMsg->au8Sta_DelAllSta[i][2], pstrDelAllStationMsg->au8Sta_DelAllSta[i][3], pstrDelAllStationMsg->au8Sta_DelAllSta[i][4], 7280 PRINT_D(CFG80211_DBG, "BSSID = %x%x%x%x%x%x\n", pstrDelAllStationMsg->au8Sta_DelAllSta[i][0], pstrDelAllStationMsg->au8Sta_DelAllSta[i][1], pstrDelAllStationMsg->au8Sta_DelAllSta[i][2], pstrDelAllStationMsg->au8Sta_DelAllSta[i][3], pstrDelAllStationMsg->au8Sta_DelAllSta[i][4],
7390 pstrDelAllStationMsg->au8Sta_DelAllSta[i][5]); 7281 pstrDelAllStationMsg->au8Sta_DelAllSta[i][5]);
7391 u8AssocNumb++; 7282 u8AssocNumb++;
@@ -7397,13 +7288,12 @@ s32 host_int_del_allstation(WILC_WFIDrvHandle hWFIDrv, u8 pu8MacAddr[][ETH_ALEN]
7397 } 7288 }
7398 7289
7399 pstrDelAllStationMsg->u8Num_AssocSta = u8AssocNumb; 7290 pstrDelAllStationMsg->u8Num_AssocSta = u8AssocNumb;
7400 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 7291 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7401 7292
7402 7293
7403 if (s32Error) { 7294 if (s32Error)
7404 WILC_ERRORREPORT(s32Error, s32Error); 7295 WILC_ERRORREPORT(s32Error, s32Error);
7405 7296
7406 }
7407 WILC_CATCH(s32Error) 7297 WILC_CATCH(s32Error)
7408 { 7298 {
7409 7299
@@ -7423,38 +7313,37 @@ s32 host_int_del_allstation(WILC_WFIDrvHandle hWFIDrv, u8 pu8MacAddr[][ETH_ALEN]
7423 * @date 7313 * @date
7424 * @version 1.0 7314 * @version 1.0
7425 */ 7315 */
7426s32 host_int_edit_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam *pstrStaParams) 7316s32 host_int_edit_station(tstrWILC_WFIDrv *hWFIDrv, tstrWILC_AddStaParam *pstrStaParams)
7427{ 7317{
7428 s32 s32Error = WILC_SUCCESS; 7318 s32 s32Error = WILC_SUCCESS;
7429 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 7319 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7430 tstrHostIFmsg strHostIFmsg; 7320 tstrHostIFmsg strHostIFmsg;
7431 tstrWILC_AddStaParam *pstrAddStationMsg = &strHostIFmsg.uniHostIFmsgBody.strAddStaParam; 7321 tstrWILC_AddStaParam *pstrAddStationMsg = &strHostIFmsg.uniHostIFmsgBody.strAddStaParam;
7432 7322
7433 if (pstrWFIDrv == NULL) { 7323 if (pstrWFIDrv == NULL)
7434 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 7324 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7435 }
7436 7325
7437 PRINT_D(HOSTINF_DBG, "Setting editing station message queue params\n"); 7326 PRINT_D(HOSTINF_DBG, "Setting editing station message queue params\n");
7438 7327
7439 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 7328 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7440 7329
7441 7330
7442 /* prepare the WiphyParams Message */ 7331 /* prepare the WiphyParams Message */
7443 strHostIFmsg.u16MsgId = HOST_IF_MSG_EDIT_STATION; 7332 strHostIFmsg.u16MsgId = HOST_IF_MSG_EDIT_STATION;
7444 strHostIFmsg.drvHandler = hWFIDrv; 7333 strHostIFmsg.drvHandler = hWFIDrv;
7445 7334
7446 WILC_memcpy(pstrAddStationMsg, pstrStaParams, sizeof(tstrWILC_AddStaParam)); 7335 memcpy(pstrAddStationMsg, pstrStaParams, sizeof(tstrWILC_AddStaParam));
7447 if (pstrAddStationMsg->u8NumRates > 0) { 7336 if (pstrAddStationMsg->u8NumRates > 0) {
7448 u8 *rates = WILC_MALLOC(pstrAddStationMsg->u8NumRates); 7337 u8 *rates = WILC_MALLOC(pstrAddStationMsg->u8NumRates);
7338
7449 WILC_NULLCHECK(s32Error, rates); 7339 WILC_NULLCHECK(s32Error, rates);
7450 WILC_memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates); 7340 memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates);
7451 pstrAddStationMsg->pu8Rates = rates; 7341 pstrAddStationMsg->pu8Rates = rates;
7452 } 7342 }
7453 7343
7454 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 7344 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7455 if (s32Error) { 7345 if (s32Error)
7456 WILC_ERRORREPORT(s32Error, s32Error); 7346 WILC_ERRORREPORT(s32Error, s32Error);
7457 }
7458 WILC_CATCH(s32Error) 7347 WILC_CATCH(s32Error)
7459 { 7348 {
7460 } 7349 }
@@ -7463,22 +7352,21 @@ s32 host_int_edit_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam *pstrS
7463#endif /*WILC_AP_EXTERNAL_MLME*/ 7352#endif /*WILC_AP_EXTERNAL_MLME*/
7464uint32_t wilc_get_chipid(uint8_t); 7353uint32_t wilc_get_chipid(uint8_t);
7465 7354
7466s32 host_int_set_power_mgmt(WILC_WFIDrvHandle hWFIDrv, bool bIsEnabled, u32 u32Timeout) 7355s32 host_int_set_power_mgmt(tstrWILC_WFIDrv *hWFIDrv, bool bIsEnabled, u32 u32Timeout)
7467{ 7356{
7468 s32 s32Error = WILC_SUCCESS; 7357 s32 s32Error = WILC_SUCCESS;
7469 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 7358 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7470 tstrHostIFmsg strHostIFmsg; 7359 tstrHostIFmsg strHostIFmsg;
7471 tstrHostIfPowerMgmtParam *pstrPowerMgmtParam = &strHostIFmsg.uniHostIFmsgBody.strPowerMgmtparam; 7360 tstrHostIfPowerMgmtParam *pstrPowerMgmtParam = &strHostIFmsg.uniHostIFmsgBody.strPowerMgmtparam;
7472 7361
7473 PRINT_INFO(HOSTINF_DBG, "\n\n>> Setting PS to %d << \n\n", bIsEnabled); 7362 PRINT_INFO(HOSTINF_DBG, "\n\n>> Setting PS to %d <<\n\n", bIsEnabled);
7474 7363
7475 if (pstrWFIDrv == NULL) { 7364 if (pstrWFIDrv == NULL)
7476 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 7365 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7477 }
7478 7366
7479 PRINT_D(HOSTINF_DBG, "Setting Power management message queue params\n"); 7367 PRINT_D(HOSTINF_DBG, "Setting Power management message queue params\n");
7480 7368
7481 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 7369 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7482 7370
7483 7371
7484 /* prepare the WiphyParams Message */ 7372 /* prepare the WiphyParams Message */
@@ -7489,17 +7377,16 @@ s32 host_int_set_power_mgmt(WILC_WFIDrvHandle hWFIDrv, bool bIsEnabled, u32 u32T
7489 pstrPowerMgmtParam->u32Timeout = u32Timeout; 7377 pstrPowerMgmtParam->u32Timeout = u32Timeout;
7490 7378
7491 7379
7492 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 7380 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7493 if (s32Error) { 7381 if (s32Error)
7494 WILC_ERRORREPORT(s32Error, s32Error); 7382 WILC_ERRORREPORT(s32Error, s32Error);
7495 }
7496 WILC_CATCH(s32Error) 7383 WILC_CATCH(s32Error)
7497 { 7384 {
7498 } 7385 }
7499 return s32Error; 7386 return s32Error;
7500} 7387}
7501 7388
7502s32 host_int_setup_multicast_filter(WILC_WFIDrvHandle hWFIDrv, bool bIsEnabled, u32 u32count) 7389s32 host_int_setup_multicast_filter(tstrWILC_WFIDrv *hWFIDrv, bool bIsEnabled, u32 u32count)
7503{ 7390{
7504 s32 s32Error = WILC_SUCCESS; 7391 s32 s32Error = WILC_SUCCESS;
7505 7392
@@ -7508,13 +7395,12 @@ s32 host_int_setup_multicast_filter(WILC_WFIDrvHandle hWFIDrv, bool bIsEnabled,
7508 tstrHostIFSetMulti *pstrMulticastFilterParam = &strHostIFmsg.uniHostIFmsgBody.strHostIfSetMulti; 7395 tstrHostIFSetMulti *pstrMulticastFilterParam = &strHostIFmsg.uniHostIFmsgBody.strHostIfSetMulti;
7509 7396
7510 7397
7511 if (pstrWFIDrv == NULL) { 7398 if (pstrWFIDrv == NULL)
7512 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 7399 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7513 }
7514 7400
7515 PRINT_D(HOSTINF_DBG, "Setting Multicast Filter params\n"); 7401 PRINT_D(HOSTINF_DBG, "Setting Multicast Filter params\n");
7516 7402
7517 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 7403 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7518 7404
7519 7405
7520 /* prepare the WiphyParams Message */ 7406 /* prepare the WiphyParams Message */
@@ -7524,10 +7410,9 @@ s32 host_int_setup_multicast_filter(WILC_WFIDrvHandle hWFIDrv, bool bIsEnabled,
7524 pstrMulticastFilterParam->bIsEnabled = bIsEnabled; 7410 pstrMulticastFilterParam->bIsEnabled = bIsEnabled;
7525 pstrMulticastFilterParam->u32count = u32count; 7411 pstrMulticastFilterParam->u32count = u32count;
7526 7412
7527 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 7413 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7528 if (s32Error) { 7414 if (s32Error)
7529 WILC_ERRORREPORT(s32Error, s32Error); 7415 WILC_ERRORREPORT(s32Error, s32Error);
7530 }
7531 WILC_CATCH(s32Error) 7416 WILC_CATCH(s32Error)
7532 { 7417 {
7533 } 7418 }
@@ -7568,17 +7453,17 @@ static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo)
7568 7453
7569 pNewJoinBssParam = WILC_MALLOC(sizeof(tstrJoinBssParam)); 7454 pNewJoinBssParam = WILC_MALLOC(sizeof(tstrJoinBssParam));
7570 if (pNewJoinBssParam != NULL) { 7455 if (pNewJoinBssParam != NULL) {
7571 WILC_memset(pNewJoinBssParam, 0, sizeof(tstrJoinBssParam)); 7456 memset(pNewJoinBssParam, 0, sizeof(tstrJoinBssParam));
7572 pNewJoinBssParam->dtim_period = ptstrNetworkInfo->u8DtimPeriod; 7457 pNewJoinBssParam->dtim_period = ptstrNetworkInfo->u8DtimPeriod;
7573 pNewJoinBssParam->beacon_period = ptstrNetworkInfo->u16BeaconPeriod; 7458 pNewJoinBssParam->beacon_period = ptstrNetworkInfo->u16BeaconPeriod;
7574 pNewJoinBssParam->cap_info = ptstrNetworkInfo->u16CapInfo; 7459 pNewJoinBssParam->cap_info = ptstrNetworkInfo->u16CapInfo;
7575 WILC_memcpy(pNewJoinBssParam->au8bssid, ptstrNetworkInfo->au8bssid, 6); 7460 memcpy(pNewJoinBssParam->au8bssid, ptstrNetworkInfo->au8bssid, 6);
7576 /*for(i=0; i<6;i++) 7461 /*for(i=0; i<6;i++)
7577 * PRINT_D(HOSTINF_DBG,"%c",pNewJoinBssParam->au8bssid[i]);*/ 7462 * PRINT_D(HOSTINF_DBG,"%c",pNewJoinBssParam->au8bssid[i]);*/
7578 WILC_memcpy((u8 *)pNewJoinBssParam->ssid, ptstrNetworkInfo->au8ssid, ptstrNetworkInfo->u8SsidLen + 1); 7463 memcpy((u8 *)pNewJoinBssParam->ssid, ptstrNetworkInfo->au8ssid, ptstrNetworkInfo->u8SsidLen + 1);
7579 pNewJoinBssParam->ssidLen = ptstrNetworkInfo->u8SsidLen; 7464 pNewJoinBssParam->ssidLen = ptstrNetworkInfo->u8SsidLen;
7580 WILC_memset(pNewJoinBssParam->rsn_pcip_policy, 0xFF, 3); 7465 memset(pNewJoinBssParam->rsn_pcip_policy, 0xFF, 3);
7581 WILC_memset(pNewJoinBssParam->rsn_auth_policy, 0xFF, 3); 7466 memset(pNewJoinBssParam->rsn_auth_policy, 0xFF, 3);
7582 /*for(i=0; i<pNewJoinBssParam->ssidLen;i++) 7467 /*for(i=0; i<pNewJoinBssParam->ssidLen;i++)
7583 * PRINT_D(HOSTINF_DBG,"%c",pNewJoinBssParam->ssid[i]);*/ 7468 * PRINT_D(HOSTINF_DBG,"%c",pNewJoinBssParam->ssid[i]);*/
7584 7469
@@ -7633,9 +7518,8 @@ static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo)
7633 pNewJoinBssParam->wmm_cap = true; 7518 pNewJoinBssParam->wmm_cap = true;
7634 7519
7635 /* Check if Bit 7 is set indicating U-APSD capability */ 7520 /* Check if Bit 7 is set indicating U-APSD capability */
7636 if (pu8IEs[index + 8] & (1 << 7)) { 7521 if (pu8IEs[index + 8] & (1 << 7))
7637 pNewJoinBssParam->uapsd_cap = true; 7522 pNewJoinBssParam->uapsd_cap = true;
7638 }
7639 index += pu8IEs[index + 1] + 2; 7523 index += pu8IEs[index + 1] + 2;
7640 continue; 7524 continue;
7641 } 7525 }
@@ -7645,6 +7529,7 @@ static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo)
7645 (pu8IEs[index + 4] == 0x9a) && /* OUI */ 7529 (pu8IEs[index + 4] == 0x9a) && /* OUI */
7646 (pu8IEs[index + 5] == 0x09) && (pu8IEs[index + 6] == 0x0c)) { /* OUI Type */ 7530 (pu8IEs[index + 5] == 0x09) && (pu8IEs[index + 6] == 0x0c)) { /* OUI Type */
7647 u16 u16P2P_count; 7531 u16 u16P2P_count;
7532
7648 pNewJoinBssParam->tsf = ptstrNetworkInfo->u32Tsf; 7533 pNewJoinBssParam->tsf = ptstrNetworkInfo->u32Tsf;
7649 pNewJoinBssParam->u8NoaEnbaled = 1; 7534 pNewJoinBssParam->u8NoaEnbaled = 1;
7650 pNewJoinBssParam->u8Index = pu8IEs[index + 9]; 7535 pNewJoinBssParam->u8Index = pu8IEs[index + 9];
@@ -7656,20 +7541,20 @@ static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo)
7656 } else 7541 } else
7657 pNewJoinBssParam->u8OppEnable = 0; 7542 pNewJoinBssParam->u8OppEnable = 0;
7658 /* HOSTINF_DBG */ 7543 /* HOSTINF_DBG */
7659 PRINT_D(GENERIC_DBG, "P2P Dump \n"); 7544 PRINT_D(GENERIC_DBG, "P2P Dump\n");
7660 for (i = 0; i < pu8IEs[index + 7]; i++) 7545 for (i = 0; i < pu8IEs[index + 7]; i++)
7661 PRINT_D(GENERIC_DBG, " %x \n", pu8IEs[index + 9 + i]); 7546 PRINT_D(GENERIC_DBG, " %x\n", pu8IEs[index + 9 + i]);
7662 7547
7663 pNewJoinBssParam->u8Count = pu8IEs[index + 11]; 7548 pNewJoinBssParam->u8Count = pu8IEs[index + 11];
7664 u16P2P_count = index + 12; 7549 u16P2P_count = index + 12;
7665 7550
7666 WILC_memcpy(pNewJoinBssParam->au8Duration, pu8IEs + u16P2P_count, 4); 7551 memcpy(pNewJoinBssParam->au8Duration, pu8IEs + u16P2P_count, 4);
7667 u16P2P_count += 4; 7552 u16P2P_count += 4;
7668 7553
7669 WILC_memcpy(pNewJoinBssParam->au8Interval, pu8IEs + u16P2P_count, 4); 7554 memcpy(pNewJoinBssParam->au8Interval, pu8IEs + u16P2P_count, 4);
7670 u16P2P_count += 4; 7555 u16P2P_count += 4;
7671 7556
7672 WILC_memcpy(pNewJoinBssParam->au8StartTime, pu8IEs + u16P2P_count, 4); 7557 memcpy(pNewJoinBssParam->au8StartTime, pu8IEs + u16P2P_count, 4);
7673 7558
7674 index += pu8IEs[index + 1] + 2; 7559 index += pu8IEs[index + 1] + 2;
7675 continue; 7560 continue;
@@ -7698,7 +7583,7 @@ static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo)
7698 rsnIndex += 7; /* skipping id, length, version(2B) and first 3 bytes of gcipher */ 7583 rsnIndex += 7; /* skipping id, length, version(2B) and first 3 bytes of gcipher */
7699 pNewJoinBssParam->rsn_grp_policy = pu8IEs[rsnIndex]; 7584 pNewJoinBssParam->rsn_grp_policy = pu8IEs[rsnIndex];
7700 rsnIndex++; 7585 rsnIndex++;
7701 /* PRINT_D(HOSTINF_DBG,"Group Policy: %0x \n",pNewJoinBssParam->rsn_grp_policy); */ 7586 /* PRINT_D(HOSTINF_DBG,"Group Policy: %0x\n",pNewJoinBssParam->rsn_grp_policy); */
7702 /* initialize policies with invalid values */ 7587 /* initialize policies with invalid values */
7703 7588
7704 jumpOffset = pu8IEs[rsnIndex] * 4; /* total no.of bytes of pcipher field (count*4) */ 7589 jumpOffset = pu8IEs[rsnIndex] * 4; /* total no.of bytes of pcipher field (count*4) */
@@ -7709,7 +7594,7 @@ static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo)
7709 pcipherCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex]; 7594 pcipherCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
7710 rsnIndex += 2; /* jump 2 bytes of pcipher count */ 7595 rsnIndex += 2; /* jump 2 bytes of pcipher count */
7711 7596
7712 /* PRINT_D(HOSTINF_DBG,"\npcipher:%d \n",pcipherCount); */ 7597 /* PRINT_D(HOSTINF_DBG,"\npcipher:%d\n",pcipherCount); */
7713 for (i = pcipherTotalCount, j = 0; i < pcipherCount + pcipherTotalCount && i < 3; i++, j++) { 7598 for (i = pcipherTotalCount, j = 0; i < pcipherCount + pcipherTotalCount && i < 3; i++, j++) {
7714 /* each count corresponds to 4 bytes, only last byte is saved */ 7599 /* each count corresponds to 4 bytes, only last byte is saved */
7715 pNewJoinBssParam->rsn_pcip_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1]; 7600 pNewJoinBssParam->rsn_pcip_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
@@ -7755,7 +7640,7 @@ static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo)
7755void host_int_freeJoinParams(void *pJoinParams) 7640void host_int_freeJoinParams(void *pJoinParams)
7756{ 7641{
7757 if ((tstrJoinBssParam *)pJoinParams != NULL) 7642 if ((tstrJoinBssParam *)pJoinParams != NULL)
7758 WILC_FREE((tstrJoinBssParam *)pJoinParams); 7643 kfree((tstrJoinBssParam *)pJoinParams);
7759 else 7644 else
7760 PRINT_ER("Unable to FREE null pointer\n"); 7645 PRINT_ER("Unable to FREE null pointer\n");
7761} 7646}
@@ -7771,7 +7656,7 @@ void host_int_freeJoinParams(void *pJoinParams)
7771 * @date 7656 * @date
7772 * @version 1.0**/ 7657 * @version 1.0**/
7773 7658
7774static int host_int_addBASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char TID, short int BufferSize, 7659static int host_int_addBASession(tstrWILC_WFIDrv *hWFIDrv, char *pBSSID, char TID, short int BufferSize,
7775 short int SessionTimeout, void *drvHandler) 7660 short int SessionTimeout, void *drvHandler)
7776{ 7661{
7777 s32 s32Error = WILC_SUCCESS; 7662 s32 s32Error = WILC_SUCCESS;
@@ -7779,11 +7664,10 @@ static int host_int_addBASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char T
7779 tstrHostIFmsg strHostIFmsg; 7664 tstrHostIFmsg strHostIFmsg;
7780 tstrHostIfBASessionInfo *pBASessionInfo = &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo; 7665 tstrHostIfBASessionInfo *pBASessionInfo = &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo;
7781 7666
7782 if (pstrWFIDrv == NULL) { 7667 if (pstrWFIDrv == NULL)
7783 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 7668 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7784 }
7785 7669
7786 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 7670 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7787 7671
7788 /* prepare the WiphyParams Message */ 7672 /* prepare the WiphyParams Message */
7789 strHostIFmsg.u16MsgId = HOST_IF_MSG_ADD_BA_SESSION; 7673 strHostIFmsg.u16MsgId = HOST_IF_MSG_ADD_BA_SESSION;
@@ -7794,10 +7678,9 @@ static int host_int_addBASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char T
7794 pBASessionInfo->u16SessionTimeout = SessionTimeout; 7678 pBASessionInfo->u16SessionTimeout = SessionTimeout;
7795 strHostIFmsg.drvHandler = hWFIDrv; 7679 strHostIFmsg.drvHandler = hWFIDrv;
7796 7680
7797 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 7681 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7798 if (s32Error) { 7682 if (s32Error)
7799 WILC_ERRORREPORT(s32Error, s32Error); 7683 WILC_ERRORREPORT(s32Error, s32Error);
7800 }
7801 WILC_CATCH(s32Error) 7684 WILC_CATCH(s32Error)
7802 { 7685 {
7803 7686
@@ -7807,18 +7690,17 @@ static int host_int_addBASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char T
7807} 7690}
7808 7691
7809 7692
7810s32 host_int_delBASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char TID) 7693s32 host_int_delBASession(tstrWILC_WFIDrv *hWFIDrv, char *pBSSID, char TID)
7811{ 7694{
7812 s32 s32Error = WILC_SUCCESS; 7695 s32 s32Error = WILC_SUCCESS;
7813 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 7696 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7814 tstrHostIFmsg strHostIFmsg; 7697 tstrHostIFmsg strHostIFmsg;
7815 tstrHostIfBASessionInfo *pBASessionInfo = &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo; 7698 tstrHostIfBASessionInfo *pBASessionInfo = &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo;
7816 7699
7817 if (pstrWFIDrv == NULL) { 7700 if (pstrWFIDrv == NULL)
7818 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 7701 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7819 }
7820 7702
7821 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 7703 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7822 7704
7823 /* prepare the WiphyParams Message */ 7705 /* prepare the WiphyParams Message */
7824 strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_BA_SESSION; 7706 strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_BA_SESSION;
@@ -7827,10 +7709,9 @@ s32 host_int_delBASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char TID)
7827 pBASessionInfo->u8Ted = TID; 7709 pBASessionInfo->u8Ted = TID;
7828 strHostIFmsg.drvHandler = hWFIDrv; 7710 strHostIFmsg.drvHandler = hWFIDrv;
7829 7711
7830 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 7712 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7831 if (s32Error) { 7713 if (s32Error)
7832 WILC_ERRORREPORT(s32Error, s32Error); 7714 WILC_ERRORREPORT(s32Error, s32Error);
7833 }
7834 WILC_CATCH(s32Error) 7715 WILC_CATCH(s32Error)
7835 { 7716 {
7836 7717
@@ -7842,18 +7723,17 @@ s32 host_int_delBASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char TID)
7842 return s32Error; 7723 return s32Error;
7843} 7724}
7844 7725
7845s32 host_int_del_All_Rx_BASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char TID) 7726s32 host_int_del_All_Rx_BASession(tstrWILC_WFIDrv *hWFIDrv, char *pBSSID, char TID)
7846{ 7727{
7847 s32 s32Error = WILC_SUCCESS; 7728 s32 s32Error = WILC_SUCCESS;
7848 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 7729 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7849 tstrHostIFmsg strHostIFmsg; 7730 tstrHostIFmsg strHostIFmsg;
7850 tstrHostIfBASessionInfo *pBASessionInfo = &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo; 7731 tstrHostIfBASessionInfo *pBASessionInfo = &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo;
7851 7732
7852 if (pstrWFIDrv == NULL) { 7733 if (pstrWFIDrv == NULL)
7853 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 7734 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7854 }
7855 7735
7856 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 7736 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7857 7737
7858 /* prepare the WiphyParams Message */ 7738 /* prepare the WiphyParams Message */
7859 strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS; 7739 strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS;
@@ -7862,10 +7742,9 @@ s32 host_int_del_All_Rx_BASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char
7862 pBASessionInfo->u8Ted = TID; 7742 pBASessionInfo->u8Ted = TID;
7863 strHostIFmsg.drvHandler = hWFIDrv; 7743 strHostIFmsg.drvHandler = hWFIDrv;
7864 7744
7865 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 7745 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7866 if (s32Error) { 7746 if (s32Error)
7867 WILC_ERRORREPORT(s32Error, s32Error); 7747 WILC_ERRORREPORT(s32Error, s32Error);
7868 }
7869 WILC_CATCH(s32Error) 7748 WILC_CATCH(s32Error)
7870 { 7749 {
7871 7750
@@ -7885,7 +7764,7 @@ s32 host_int_del_All_Rx_BASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char
7885 * @author Abdelrahman Sobhy 7764 * @author Abdelrahman Sobhy
7886 * @date 7765 * @date
7887 * @version 1.0*/ 7766 * @version 1.0*/
7888s32 host_int_setup_ipaddress(WILC_WFIDrvHandle hWFIDrv, u8 *u16ipadd, u8 idx) 7767s32 host_int_setup_ipaddress(tstrWILC_WFIDrv *hWFIDrv, u8 *u16ipadd, u8 idx)
7889{ 7768{
7890 s32 s32Error = WILC_SUCCESS; 7769 s32 s32Error = WILC_SUCCESS;
7891 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 7770 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
@@ -7894,11 +7773,10 @@ s32 host_int_setup_ipaddress(WILC_WFIDrvHandle hWFIDrv, u8 *u16ipadd, u8 idx)
7894 /* TODO: Enable This feature on softap firmware */ 7773 /* TODO: Enable This feature on softap firmware */
7895 return 0; 7774 return 0;
7896 7775
7897 if (pstrWFIDrv == NULL) { 7776 if (pstrWFIDrv == NULL)
7898 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 7777 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7899 }
7900 7778
7901 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 7779 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7902 7780
7903 /* prepare the WiphyParams Message */ 7781 /* prepare the WiphyParams Message */
7904 strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_IPADDRESS; 7782 strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_IPADDRESS;
@@ -7907,10 +7785,9 @@ s32 host_int_setup_ipaddress(WILC_WFIDrvHandle hWFIDrv, u8 *u16ipadd, u8 idx)
7907 strHostIFmsg.drvHandler = hWFIDrv; 7785 strHostIFmsg.drvHandler = hWFIDrv;
7908 strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.idx = idx; 7786 strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.idx = idx;
7909 7787
7910 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 7788 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7911 if (s32Error) { 7789 if (s32Error)
7912 WILC_ERRORREPORT(s32Error, s32Error); 7790 WILC_ERRORREPORT(s32Error, s32Error);
7913 }
7914 WILC_CATCH(s32Error) 7791 WILC_CATCH(s32Error)
7915 { 7792 {
7916 7793
@@ -7929,29 +7806,27 @@ s32 host_int_setup_ipaddress(WILC_WFIDrvHandle hWFIDrv, u8 *u16ipadd, u8 idx)
7929 * @author Abdelrahman Sobhy 7806 * @author Abdelrahman Sobhy
7930 * @date 7807 * @date
7931 * @version 1.0*/ 7808 * @version 1.0*/
7932s32 host_int_get_ipaddress(WILC_WFIDrvHandle hWFIDrv, u8 *u16ipadd, u8 idx) 7809s32 host_int_get_ipaddress(tstrWILC_WFIDrv *hWFIDrv, u8 *u16ipadd, u8 idx)
7933{ 7810{
7934 s32 s32Error = WILC_SUCCESS; 7811 s32 s32Error = WILC_SUCCESS;
7935 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; 7812 tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7936 tstrHostIFmsg strHostIFmsg; 7813 tstrHostIFmsg strHostIFmsg;
7937 7814
7938 if (pstrWFIDrv == NULL) { 7815 if (pstrWFIDrv == NULL)
7939 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT); 7816 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7940 }
7941 7817
7942 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg)); 7818 memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7943 7819
7944 /* prepare the WiphyParams Message */ 7820 /* prepare the WiphyParams Message */
7945 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_IPADDRESS; 7821 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_IPADDRESS;
7946 7822
7947 strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.au8IPAddr = u16ipadd; 7823 strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.au8IPAddr = u16ipadd;
7948 strHostIFmsg.drvHandler=hWFIDrv; 7824 strHostIFmsg.drvHandler = hWFIDrv;
7949 strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.idx= idx; 7825 strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.idx = idx;
7950 7826
7951 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL); 7827 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
7952 if (s32Error) { 7828 if (s32Error)
7953 WILC_ERRORREPORT(s32Error, s32Error); 7829 WILC_ERRORREPORT(s32Error, s32Error);
7954 }
7955 WILC_CATCH(s32Error) 7830 WILC_CATCH(s32Error)
7956 { 7831 {
7957 7832
diff --git a/drivers/staging/wilc1000/host_interface.h b/drivers/staging/wilc1000/host_interface.h
index 38db740745cd..e66dee9af5da 100644
--- a/drivers/staging/wilc1000/host_interface.h
+++ b/drivers/staging/wilc1000/host_interface.h
@@ -11,7 +11,6 @@
11#define HOST_INT_H 11#define HOST_INT_H
12 12
13#include "coreconfigurator.h" 13#include "coreconfigurator.h"
14#include "coreconfigsimulator.h"
15/*****************************************************************************/ 14/*****************************************************************************/
16/* Macros */ 15/* Macros */
17/*****************************************************************************/ 16/*****************************************************************************/
@@ -368,10 +367,10 @@ typedef struct {
368 struct semaphore hSemGetCHNL; 367 struct semaphore hSemGetCHNL;
369 struct semaphore hSemInactiveTime; 368 struct semaphore hSemInactiveTime;
370/* timer handlers */ 369/* timer handlers */
371 WILC_TimerHandle hScanTimer; 370 struct timer_list hScanTimer;
372 WILC_TimerHandle hConnectTimer; 371 struct timer_list hConnectTimer;
373 #ifdef WILC_P2P 372 #ifdef WILC_P2P
374 WILC_TimerHandle hRemainOnChannel; 373 struct timer_list hRemainOnChannel;
375 #endif 374 #endif
376 375
377 bool IFC_UP; 376 bool IFC_UP;
@@ -433,7 +432,7 @@ typedef struct {
433 * @date 8 March 2012 432 * @date 8 March 2012
434 * @version 1.0 433 * @version 1.0
435 */ 434 */
436s32 host_int_remove_key(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8StaAddress); 435s32 host_int_remove_key(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8StaAddress);
437/** 436/**
438 * @brief removes WEP key 437 * @brief removes WEP key
439 * @details valid only in BSS STA mode if External Supplicant support is enabled. 438 * @details valid only in BSS STA mode if External Supplicant support is enabled.
@@ -448,7 +447,7 @@ s32 host_int_remove_key(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8StaAddress);
448 * @date 8 March 2012 447 * @date 8 March 2012
449 * @version 1.0 448 * @version 1.0
450 */ 449 */
451s32 host_int_remove_wep_key(WILC_WFIDrvHandle hWFIDrv, u8 u8Index); 450s32 host_int_remove_wep_key(tstrWILC_WFIDrv *hWFIDrv, u8 u8Index);
452/** 451/**
453 * @brief sets WEP deafault key 452 * @brief sets WEP deafault key
454 * @details Sets the index of the WEP encryption key in use, 453 * @details Sets the index of the WEP encryption key in use,
@@ -461,7 +460,7 @@ s32 host_int_remove_wep_key(WILC_WFIDrvHandle hWFIDrv, u8 u8Index);
461 * @date 8 March 2012 460 * @date 8 March 2012
462 * @version 1.0 461 * @version 1.0
463 */ 462 */
464s32 host_int_set_WEPDefaultKeyID(WILC_WFIDrvHandle hWFIDrv, u8 u8Index); 463s32 host_int_set_WEPDefaultKeyID(tstrWILC_WFIDrv *hWFIDrv, u8 u8Index);
465 464
466/** 465/**
467 * @brief sets WEP deafault key 466 * @brief sets WEP deafault key
@@ -482,7 +481,7 @@ s32 host_int_set_WEPDefaultKeyID(WILC_WFIDrvHandle hWFIDrv, u8 u8Index);
482 * @date 8 March 2012 481 * @date 8 March 2012
483 * @version 1.0 482 * @version 1.0
484 */ 483 */
485s32 host_int_add_wep_key_bss_sta(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8WepKey, u8 u8WepKeylen, u8 u8Keyidx); 484s32 host_int_add_wep_key_bss_sta(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8WepKey, u8 u8WepKeylen, u8 u8Keyidx);
486/** 485/**
487 * @brief host_int_add_wep_key_bss_ap 486 * @brief host_int_add_wep_key_bss_ap
488 * @details valid only in AP mode if External Supplicant support is enabled. 487 * @details valid only in AP mode if External Supplicant support is enabled.
@@ -497,7 +496,7 @@ s32 host_int_add_wep_key_bss_sta(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8WepKey,
497 * @date 28 Feb 2013 496 * @date 28 Feb 2013
498 * @version 1.0 497 * @version 1.0
499 */ 498 */
500s32 host_int_add_wep_key_bss_ap(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8WepKey, u8 u8WepKeylen, u8 u8Keyidx, u8 u8mode, AUTHTYPE_T tenuAuth_type); 499s32 host_int_add_wep_key_bss_ap(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8WepKey, u8 u8WepKeylen, u8 u8Keyidx, u8 u8mode, AUTHTYPE_T tenuAuth_type);
501 500
502/** 501/**
503 * @brief adds ptk Key 502 * @brief adds ptk Key
@@ -515,7 +514,7 @@ s32 host_int_add_wep_key_bss_ap(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8WepKey,
515 * @date 8 March 2012 514 * @date 8 March 2012
516 * @version 1.0 515 * @version 1.0
517 */ 516 */
518s32 host_int_add_ptk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen, 517s32 host_int_add_ptk(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen,
519 const u8 *mac_addr, const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode, u8 u8Idx); 518 const u8 *mac_addr, const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode, u8 u8Idx);
520 519
521/** 520/**
@@ -530,7 +529,7 @@ s32 host_int_add_ptk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen
530 * @date 15 April 2013 529 * @date 15 April 2013
531 * @version 1.0 530 * @version 1.0
532 */ 531 */
533s32 host_int_get_inactive_time(WILC_WFIDrvHandle hWFIDrv, const u8 *mac, u32 *pu32InactiveTime); 532s32 host_int_get_inactive_time(tstrWILC_WFIDrv *hWFIDrv, const u8 *mac, u32 *pu32InactiveTime);
534 533
535/** 534/**
536 * @brief adds Rx GTk Key 535 * @brief adds Rx GTk Key
@@ -548,7 +547,7 @@ s32 host_int_get_inactive_time(WILC_WFIDrvHandle hWFIDrv, const u8 *mac, u32 *pu
548 * @date 8 March 2012 547 * @date 8 March 2012
549 * @version 1.0 548 * @version 1.0
550 */ 549 */
551s32 host_int_add_rx_gtk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8RxGtk, u8 u8GtkKeylen, 550s32 host_int_add_rx_gtk(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8RxGtk, u8 u8GtkKeylen,
552 u8 u8KeyIdx, u32 u32KeyRSClen, const u8 *KeyRSC, 551 u8 u8KeyIdx, u32 u32KeyRSClen, const u8 *KeyRSC,
553 const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode); 552 const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode);
554 553
@@ -569,7 +568,7 @@ s32 host_int_add_rx_gtk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8RxGtk, u8 u8GtkK
569 * @date 8 March 2012 568 * @date 8 March 2012
570 * @version 1.0 569 * @version 1.0
571 */ 570 */
572s32 host_int_add_tx_gtk(WILC_WFIDrvHandle hWFIDrv, u8 u8KeyLen, u8 *pu8TxGtk, u8 u8KeyIdx); 571s32 host_int_add_tx_gtk(tstrWILC_WFIDrv *hWFIDrv, u8 u8KeyLen, u8 *pu8TxGtk, u8 u8KeyIdx);
573 572
574/** 573/**
575 * @brief caches the pmkid 574 * @brief caches the pmkid
@@ -592,7 +591,7 @@ s32 host_int_add_tx_gtk(WILC_WFIDrvHandle hWFIDrv, u8 u8KeyLen, u8 *pu8TxGtk, u8
592 * @version 1.0 591 * @version 1.0
593 */ 592 */
594 593
595s32 host_int_set_pmkid_info(WILC_WFIDrvHandle hWFIDrv, tstrHostIFpmkidAttr *pu8PmkidInfoArray); 594s32 host_int_set_pmkid_info(tstrWILC_WFIDrv *hWFIDrv, tstrHostIFpmkidAttr *pu8PmkidInfoArray);
596/** 595/**
597 * @brief gets the cached the pmkid info 596 * @brief gets the cached the pmkid info
598 * @details valid only in BSS STA mode if External Supplicant 597 * @details valid only in BSS STA mode if External Supplicant
@@ -616,7 +615,7 @@ s32 host_int_set_pmkid_info(WILC_WFIDrvHandle hWFIDrv, tstrHostIFpmkidAttr *pu8P
616 * @version 1.0 615 * @version 1.0
617 */ 616 */
618 617
619s32 host_int_get_pmkid_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8PmkidInfoArray, 618s32 host_int_get_pmkid_info(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8PmkidInfoArray,
620 u32 u32PmkidInfoLen); 619 u32 u32PmkidInfoLen);
621 620
622/** 621/**
@@ -633,7 +632,7 @@ s32 host_int_get_pmkid_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8PmkidInfoArray,
633 * @date 8 March 2012 632 * @date 8 March 2012
634 * @version 1.0 633 * @version 1.0
635 */ 634 */
636s32 host_int_set_RSNAConfigPSKPassPhrase(WILC_WFIDrvHandle hWFIDrv, u8 *pu8PassPhrase, 635s32 host_int_set_RSNAConfigPSKPassPhrase(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8PassPhrase,
637 u8 u8Psklength); 636 u8 u8Psklength);
638/** 637/**
639 * @brief gets the pass phrase 638 * @brief gets the pass phrase
@@ -649,7 +648,7 @@ s32 host_int_set_RSNAConfigPSKPassPhrase(WILC_WFIDrvHandle hWFIDrv, u8 *pu8PassP
649 * @date 8 March 2012 648 * @date 8 March 2012
650 * @version 1.0 649 * @version 1.0
651 */ 650 */
652s32 host_int_get_RSNAConfigPSKPassPhrase(WILC_WFIDrvHandle hWFIDrv, 651s32 host_int_get_RSNAConfigPSKPassPhrase(tstrWILC_WFIDrv *hWFIDrv,
653 u8 *pu8PassPhrase, u8 u8Psklength); 652 u8 *pu8PassPhrase, u8 u8Psklength);
654 653
655/** 654/**
@@ -663,7 +662,7 @@ s32 host_int_get_RSNAConfigPSKPassPhrase(WILC_WFIDrvHandle hWFIDrv,
663 * @date 19 April 2012 662 * @date 19 April 2012
664 * @version 1.0 663 * @version 1.0
665 */ 664 */
666s32 host_int_get_MacAddress(WILC_WFIDrvHandle hWFIDrv, u8 *pu8MacAddress); 665s32 host_int_get_MacAddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8MacAddress);
667 666
668/** 667/**
669 * @brief sets mac address 668 * @brief sets mac address
@@ -676,7 +675,7 @@ s32 host_int_get_MacAddress(WILC_WFIDrvHandle hWFIDrv, u8 *pu8MacAddress);
676 * @date 16 July 2012 675 * @date 16 July 2012
677 * @version 1.0 676 * @version 1.0
678 */ 677 */
679s32 host_int_set_MacAddress(WILC_WFIDrvHandle hWFIDrv, u8 *pu8MacAddress); 678s32 host_int_set_MacAddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8MacAddress);
680 679
681/** 680/**
682 * @brief wait until msg q is empty 681 * @brief wait until msg q is empty
@@ -721,7 +720,7 @@ s32 host_int_wait_msg_queue_idle(void);
721 * @version 1.0 720 * @version 1.0
722 */ 721 */
723#ifndef CONNECT_DIRECT 722#ifndef CONNECT_DIRECT
724s32 host_int_get_site_survey_results(WILC_WFIDrvHandle hWFIDrv, 723s32 host_int_get_site_survey_results(tstrWILC_WFIDrv *hWFIDrv,
725 u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZE], 724 u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZE],
726 u32 u32MaxSiteSrvyFragLen); 725 u32 u32MaxSiteSrvyFragLen);
727#endif 726#endif
@@ -742,7 +741,7 @@ s32 host_int_get_site_survey_results(WILC_WFIDrvHandle hWFIDrv,
742 * @version 1.0 741 * @version 1.0
743 */ 742 */
744 743
745s32 host_int_set_start_scan_req(WILC_WFIDrvHandle hWFIDrv, u8 scanSource); 744s32 host_int_set_start_scan_req(tstrWILC_WFIDrv *hWFIDrv, u8 scanSource);
746/** 745/**
747 * @brief gets scan source of the last scan 746 * @brief gets scan source of the last scan
748 * @details 747 * @details
@@ -758,7 +757,7 @@ s32 host_int_set_start_scan_req(WILC_WFIDrvHandle hWFIDrv, u8 scanSource);
758 * @date 8 March 2012 757 * @date 8 March 2012
759 * @version 1.0 758 * @version 1.0
760 */ 759 */
761s32 host_int_get_start_scan_req(WILC_WFIDrvHandle hWFIDrv, u8 *pu8ScanSource); 760s32 host_int_get_start_scan_req(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8ScanSource);
762 761
763/** 762/**
764 * @brief sets a join request 763 * @brief sets a join request
@@ -772,7 +771,7 @@ s32 host_int_get_start_scan_req(WILC_WFIDrvHandle hWFIDrv, u8 *pu8ScanSource);
772 * @version 1.0 771 * @version 1.0
773 */ 772 */
774 773
775s32 host_int_set_join_req(WILC_WFIDrvHandle hWFIDrv, u8 *pu8bssid, 774s32 host_int_set_join_req(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8bssid,
776 const u8 *pu8ssid, size_t ssidLen, 775 const u8 *pu8ssid, size_t ssidLen,
777 const u8 *pu8IEs, size_t IEsLen, 776 const u8 *pu8IEs, size_t IEsLen,
778 tWILCpfConnectResult pfConnectResult, void *pvUserArg, 777 tWILCpfConnectResult pfConnectResult, void *pvUserArg,
@@ -792,7 +791,7 @@ s32 host_int_set_join_req(WILC_WFIDrvHandle hWFIDrv, u8 *pu8bssid,
792 * @version 8.0 791 * @version 8.0
793 */ 792 */
794 793
795s32 host_int_flush_join_req(WILC_WFIDrvHandle hWFIDrv); 794s32 host_int_flush_join_req(tstrWILC_WFIDrv *hWFIDrv);
796 795
797 796
798/** 797/**
@@ -806,7 +805,7 @@ s32 host_int_flush_join_req(WILC_WFIDrvHandle hWFIDrv);
806 * @date 8 March 2012 805 * @date 8 March 2012
807 * @version 1.0 806 * @version 1.0
808 */ 807 */
809s32 host_int_disconnect(WILC_WFIDrvHandle hWFIDrv, u16 u16ReasonCode); 808s32 host_int_disconnect(tstrWILC_WFIDrv *hWFIDrv, u16 u16ReasonCode);
810 809
811/** 810/**
812 * @brief disconnects a sta 811 * @brief disconnects a sta
@@ -819,7 +818,7 @@ s32 host_int_disconnect(WILC_WFIDrvHandle hWFIDrv, u16 u16ReasonCode);
819 * @date 8 March 2012 818 * @date 8 March 2012
820 * @version 1.0 819 * @version 1.0
821 */ 820 */
822s32 host_int_disconnect_station(WILC_WFIDrvHandle hWFIDrv, u8 assoc_id); 821s32 host_int_disconnect_station(tstrWILC_WFIDrv *hWFIDrv, u8 assoc_id);
823/** 822/**
824 * @brief gets a Association request info 823 * @brief gets a Association request info
825 * @details 824 * @details
@@ -846,7 +845,7 @@ s32 host_int_disconnect_station(WILC_WFIDrvHandle hWFIDrv, u8 assoc_id);
846 * @version 1.0 845 * @version 1.0
847 */ 846 */
848 847
849s32 host_int_get_assoc_req_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8AssocReqInfo, 848s32 host_int_get_assoc_req_info(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8AssocReqInfo,
850 u32 u32AssocReqInfoLen); 849 u32 u32AssocReqInfoLen);
851/** 850/**
852 * @brief gets a Association Response info 851 * @brief gets a Association Response info
@@ -860,7 +859,7 @@ s32 host_int_get_assoc_req_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8AssocReqInfo,
860 * @version 1.0 859 * @version 1.0
861 */ 860 */
862 861
863s32 host_int_get_assoc_res_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8AssocRespInfo, 862s32 host_int_get_assoc_res_info(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8AssocRespInfo,
864 u32 u32MaxAssocRespInfoLen, u32 *pu32RcvdAssocRespInfoLen); 863 u32 u32MaxAssocRespInfoLen, u32 *pu32RcvdAssocRespInfoLen);
865/** 864/**
866 * @brief gets a Association Response info 865 * @brief gets a Association Response info
@@ -877,7 +876,7 @@ s32 host_int_get_assoc_res_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8AssocRespInfo,
877 * @date 8 March 2012 876 * @date 8 March 2012
878 * @version 1.0 877 * @version 1.0
879 */ 878 */
880s32 host_int_get_rx_power_level(WILC_WFIDrvHandle hWFIDrv, u8 *pu8RxPowerLevel, 879s32 host_int_get_rx_power_level(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8RxPowerLevel,
881 u32 u32RxPowerLevelLen); 880 u32 u32RxPowerLevelLen);
882 881
883/** 882/**
@@ -895,7 +894,7 @@ s32 host_int_get_rx_power_level(WILC_WFIDrvHandle hWFIDrv, u8 *pu8RxPowerLevel,
895 * @date 8 March 2012 894 * @date 8 March 2012
896 * @version 1.0 895 * @version 1.0
897 */ 896 */
898s32 host_int_set_mac_chnl_num(WILC_WFIDrvHandle hWFIDrv, u8 u8ChNum); 897s32 host_int_set_mac_chnl_num(tstrWILC_WFIDrv *hWFIDrv, u8 u8ChNum);
899 898
900/** 899/**
901 * @brief gets the current channel index 900 * @brief gets the current channel index
@@ -912,7 +911,7 @@ s32 host_int_set_mac_chnl_num(WILC_WFIDrvHandle hWFIDrv, u8 u8ChNum);
912 * @date 8 March 2012 911 * @date 8 March 2012
913 * @version 1.0 912 * @version 1.0
914 */ 913 */
915s32 host_int_get_host_chnl_num(WILC_WFIDrvHandle hWFIDrv, u8 *pu8ChNo); 914s32 host_int_get_host_chnl_num(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8ChNo);
916/** 915/**
917 * @brief gets the sta rssi 916 * @brief gets the sta rssi
918 * @details gets the currently maintained RSSI value for the station. 917 * @details gets the currently maintained RSSI value for the station.
@@ -926,8 +925,8 @@ s32 host_int_get_host_chnl_num(WILC_WFIDrvHandle hWFIDrv, u8 *pu8ChNo);
926 * @date 8 March 2012 925 * @date 8 March 2012
927 * @version 1.0 926 * @version 1.0
928 */ 927 */
929s32 host_int_get_rssi(WILC_WFIDrvHandle hWFIDrv, s8 *ps8Rssi); 928s32 host_int_get_rssi(tstrWILC_WFIDrv *hWFIDrv, s8 *ps8Rssi);
930s32 host_int_get_link_speed(WILC_WFIDrvHandle hWFIDrv, s8 *ps8lnkspd); 929s32 host_int_get_link_speed(tstrWILC_WFIDrv *hWFIDrv, s8 *ps8lnkspd);
931/** 930/**
932 * @brief scans a set of channels 931 * @brief scans a set of channels
933 * @details 932 * @details
@@ -945,7 +944,7 @@ s32 host_int_get_link_speed(WILC_WFIDrvHandle hWFIDrv, s8 *ps8lnkspd);
945 * @date 8 March 2012 944 * @date 8 March 2012
946 * @version 1.0 945 * @version 1.0
947 */ 946 */
948s32 host_int_scan(WILC_WFIDrvHandle hWFIDrv, u8 u8ScanSource, 947s32 host_int_scan(tstrWILC_WFIDrv *hWFIDrv, u8 u8ScanSource,
949 u8 u8ScanType, u8 *pu8ChnlFreqList, 948 u8 u8ScanType, u8 *pu8ChnlFreqList,
950 u8 u8ChnlListLen, const u8 *pu8IEs, 949 u8 u8ChnlListLen, const u8 *pu8IEs,
951 size_t IEsLen, tWILCpfScanResult ScanResult, 950 size_t IEsLen, tWILCpfScanResult ScanResult,
@@ -961,7 +960,7 @@ s32 host_int_scan(WILC_WFIDrvHandle hWFIDrv, u8 u8ScanSource,
961 * @date 8 March 2012 960 * @date 8 March 2012
962 * @version 1.0 961 * @version 1.0
963 */ 962 */
964s32 hif_set_cfg(WILC_WFIDrvHandle hWFIDrv, tstrCfgParamVal *pstrCfgParamVal); 963s32 hif_set_cfg(tstrWILC_WFIDrv *hWFIDrv, tstrCfgParamVal *pstrCfgParamVal);
965 964
966/** 965/**
967 * @brief gets configuration wids values 966 * @brief gets configuration wids values
@@ -975,7 +974,7 @@ s32 hif_set_cfg(WILC_WFIDrvHandle hWFIDrv, tstrCfgParamVal *pstrCfgParamVal);
975 * @date 8 March 2012 974 * @date 8 March 2012
976 * @version 1.0 975 * @version 1.0
977 */ 976 */
978s32 hif_get_cfg(WILC_WFIDrvHandle hWFIDrv, u16 u16WID, u16 *pu16WID_Value); 977s32 hif_get_cfg(tstrWILC_WFIDrv *hWFIDrv, u16 u16WID, u16 *pu16WID_Value);
979/*****************************************************************************/ 978/*****************************************************************************/
980/* Notification Functions */ 979/* Notification Functions */
981/*****************************************************************************/ 980/*****************************************************************************/
@@ -1022,7 +1021,7 @@ void host_int_send_network_info_to_host
1022 * @date 8 March 2012 1021 * @date 8 March 2012
1023 * @version 1.0 1022 * @version 1.0
1024 */ 1023 */
1025s32 host_int_init(WILC_WFIDrvHandle *phWFIDrv); 1024s32 host_int_init(tstrWILC_WFIDrv **phWFIDrv);
1026 1025
1027/** 1026/**
1028 * @brief host interface initialization function 1027 * @brief host interface initialization function
@@ -1033,7 +1032,7 @@ s32 host_int_init(WILC_WFIDrvHandle *phWFIDrv);
1033 * @date 8 March 2012 1032 * @date 8 March 2012
1034 * @version 1.0 1033 * @version 1.0
1035 */ 1034 */
1036s32 host_int_deinit(WILC_WFIDrvHandle hWFIDrv); 1035s32 host_int_deinit(tstrWILC_WFIDrv *hWFIDrv);
1037 1036
1038 1037
1039/*! 1038/*!
@@ -1058,7 +1057,7 @@ s32 host_int_deinit(WILC_WFIDrvHandle hWFIDrv);
1058 * @version 1.0 Description 1057 * @version 1.0 Description
1059 * 1058 *
1060 */ 1059 */
1061s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval, 1060s32 host_int_add_beacon(tstrWILC_WFIDrv *hWFIDrv, u32 u32Interval,
1062 u32 u32DTIMPeriod, 1061 u32 u32DTIMPeriod,
1063 u32 u32HeadLen, u8 *pu8Head, 1062 u32 u32HeadLen, u8 *pu8Head,
1064 u32 u32TailLen, u8 *pu8tail); 1063 u32 u32TailLen, u8 *pu8tail);
@@ -1076,7 +1075,7 @@ s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval,
1076 * @date 10 Julys 2012 1075 * @date 10 Julys 2012
1077 * @version 1.0 Description 1076 * @version 1.0 Description
1078 */ 1077 */
1079s32 host_int_del_beacon(WILC_WFIDrvHandle hWFIDrv); 1078s32 host_int_del_beacon(tstrWILC_WFIDrv *hWFIDrv);
1080 1079
1081/*! 1080/*!
1082 * @fn s32 host_int_add_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam strStaParams) 1081 * @fn s32 host_int_add_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam strStaParams)
@@ -1091,7 +1090,7 @@ s32 host_int_del_beacon(WILC_WFIDrvHandle hWFIDrv);
1091 * @date 12 July 2012 1090 * @date 12 July 2012
1092 * @version 1.0 Description 1091 * @version 1.0 Description
1093 */ 1092 */
1094s32 host_int_add_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam *pstrStaParams); 1093s32 host_int_add_station(tstrWILC_WFIDrv *hWFIDrv, tstrWILC_AddStaParam *pstrStaParams);
1095 1094
1096/*! 1095/*!
1097 * @fn s32 host_int_del_allstation(WILC_WFIDrvHandle hWFIDrv, const u8* pu8MacAddr) 1096 * @fn s32 host_int_del_allstation(WILC_WFIDrvHandle hWFIDrv, const u8* pu8MacAddr)
@@ -1106,7 +1105,7 @@ s32 host_int_add_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam *pstrSt
1106 * @date 09 April 2014 1105 * @date 09 April 2014
1107 * @version 1.0 Description 1106 * @version 1.0 Description
1108 */ 1107 */
1109s32 host_int_del_allstation(WILC_WFIDrvHandle hWFIDrv, u8 pu8MacAddr[][ETH_ALEN]); 1108s32 host_int_del_allstation(tstrWILC_WFIDrv *hWFIDrv, u8 pu8MacAddr[][ETH_ALEN]);
1110 1109
1111/*! 1110/*!
1112 * @fn s32 host_int_del_station(WILC_WFIDrvHandle hWFIDrv, u8* pu8MacAddr) 1111 * @fn s32 host_int_del_station(WILC_WFIDrvHandle hWFIDrv, u8* pu8MacAddr)
@@ -1121,7 +1120,7 @@ s32 host_int_del_allstation(WILC_WFIDrvHandle hWFIDrv, u8 pu8MacAddr[][ETH_ALEN]
1121 * @date 15 July 2012 1120 * @date 15 July 2012
1122 * @version 1.0 Description 1121 * @version 1.0 Description
1123 */ 1122 */
1124s32 host_int_del_station(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8MacAddr); 1123s32 host_int_del_station(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8MacAddr);
1125 1124
1126/*! 1125/*!
1127 * @fn s32 host_int_edit_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam strStaParams) 1126 * @fn s32 host_int_edit_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam strStaParams)
@@ -1136,7 +1135,7 @@ s32 host_int_del_station(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8MacAddr);
1136 * @date 15 July 2012 1135 * @date 15 July 2012
1137 * @version 1.0 Description 1136 * @version 1.0 Description
1138 */ 1137 */
1139s32 host_int_edit_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam *pstrStaParams); 1138s32 host_int_edit_station(tstrWILC_WFIDrv *hWFIDrv, tstrWILC_AddStaParam *pstrStaParams);
1140 1139
1141/*! 1140/*!
1142 * @fn s32 host_int_set_power_mgmt(WILC_WFIDrvHandle hWFIDrv, bool bIsEnabled, u32 u32Timeout) 1141 * @fn s32 host_int_set_power_mgmt(WILC_WFIDrvHandle hWFIDrv, bool bIsEnabled, u32 u32Timeout)
@@ -1153,7 +1152,7 @@ s32 host_int_edit_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam *pstrS
1153 * @date 24 November 2012 1152 * @date 24 November 2012
1154 * @version 1.0 Description 1153 * @version 1.0 Description
1155 */ 1154 */
1156s32 host_int_set_power_mgmt(WILC_WFIDrvHandle hWFIDrv, bool bIsEnabled, u32 u32Timeout); 1155s32 host_int_set_power_mgmt(tstrWILC_WFIDrv *hWFIDrv, bool bIsEnabled, u32 u32Timeout);
1157/* @param[in,out] hWFIDrv handle to the wifi driver 1156/* @param[in,out] hWFIDrv handle to the wifi driver
1158 * @param[in] bIsEnabled TRUE if enabled, FALSE otherwise 1157 * @param[in] bIsEnabled TRUE if enabled, FALSE otherwise
1159 * @param[in] u8count count of mac address entries in the filter table 1158 * @param[in] u8count count of mac address entries in the filter table
@@ -1165,7 +1164,7 @@ s32 host_int_set_power_mgmt(WILC_WFIDrvHandle hWFIDrv, bool bIsEnabled, u32 u32T
1165 * @date 24 November 2012 1164 * @date 24 November 2012
1166 * @version 1.0 Description 1165 * @version 1.0 Description
1167 */ 1166 */
1168s32 host_int_setup_multicast_filter(WILC_WFIDrvHandle hWFIDrv, bool bIsEnabled, u32 u32count); 1167s32 host_int_setup_multicast_filter(tstrWILC_WFIDrv *hWFIDrv, bool bIsEnabled, u32 u32count);
1169/** 1168/**
1170 * @brief host_int_setup_ipaddress 1169 * @brief host_int_setup_ipaddress
1171 * @details set IP address on firmware 1170 * @details set IP address on firmware
@@ -1175,7 +1174,7 @@ s32 host_int_setup_multicast_filter(WILC_WFIDrvHandle hWFIDrv, bool bIsEnabled,
1175 * @date 1174 * @date
1176 * @version 1.0 1175 * @version 1.0
1177 */ 1176 */
1178s32 host_int_setup_ipaddress(WILC_WFIDrvHandle hWFIDrv, u8 *pu8IPAddr, u8 idx); 1177s32 host_int_setup_ipaddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8IPAddr, u8 idx);
1179 1178
1180 1179
1181/** 1180/**
@@ -1187,7 +1186,7 @@ s32 host_int_setup_ipaddress(WILC_WFIDrvHandle hWFIDrv, u8 *pu8IPAddr, u8 idx);
1187 * @date 1186 * @date
1188 * @version 1.0 1187 * @version 1.0
1189 */ 1188 */
1190s32 host_int_delBASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char TID); 1189s32 host_int_delBASession(tstrWILC_WFIDrv *hWFIDrv, char *pBSSID, char TID);
1191 1190
1192/** 1191/**
1193 * @brief host_int_delBASession 1192 * @brief host_int_delBASession
@@ -1198,7 +1197,7 @@ s32 host_int_delBASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char TID);
1198 * @date 1197 * @date
1199 * @version 1.0 1198 * @version 1.0
1200 */ 1199 */
1201s32 host_int_del_All_Rx_BASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char TID); 1200s32 host_int_del_All_Rx_BASession(tstrWILC_WFIDrv *hWFIDrv, char *pBSSID, char TID);
1202 1201
1203 1202
1204/** 1203/**
@@ -1210,7 +1209,7 @@ s32 host_int_del_All_Rx_BASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char
1210 * @date 1209 * @date
1211 * @version 1.0 1210 * @version 1.0
1212 */ 1211 */
1213s32 host_int_get_ipaddress(WILC_WFIDrvHandle hWFIDrv, u8 *pu8IPAddr, u8 idx); 1212s32 host_int_get_ipaddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8IPAddr, u8 idx);
1214 1213
1215#ifdef WILC_P2P 1214#ifdef WILC_P2P
1216/** 1215/**
@@ -1222,7 +1221,7 @@ s32 host_int_get_ipaddress(WILC_WFIDrvHandle hWFIDrv, u8 *pu8IPAddr, u8 idx);
1222 * @date 1221 * @date
1223 * @version 1.0 1222 * @version 1.0
1224 */ 1223 */
1225s32 host_int_remain_on_channel(WILC_WFIDrvHandle hWFIDrv, u32 u32SessionID, u32 u32duration, u16 chan, tWILCpfRemainOnChanExpired RemainOnChanExpired, tWILCpfRemainOnChanReady RemainOnChanReady, void *pvUserArg); 1224s32 host_int_remain_on_channel(tstrWILC_WFIDrv *hWFIDrv, u32 u32SessionID, u32 u32duration, u16 chan, tWILCpfRemainOnChanExpired RemainOnChanExpired, tWILCpfRemainOnChanReady RemainOnChanReady, void *pvUserArg);
1226 1225
1227/** 1226/**
1228 * @brief host_int_ListenStateExpired 1227 * @brief host_int_ListenStateExpired
@@ -1238,7 +1237,7 @@ s32 host_int_remain_on_channel(WILC_WFIDrvHandle hWFIDrv, u32 u32SessionID, u32
1238 * @date 1237 * @date
1239 * @version 1.0 1238 * @version 1.0
1240 */ 1239 */
1241s32 host_int_ListenStateExpired(WILC_WFIDrvHandle hWFIDrv, u32 u32SessionID); 1240s32 host_int_ListenStateExpired(tstrWILC_WFIDrv *hWFIDrv, u32 u32SessionID);
1242 1241
1243/** 1242/**
1244 * @brief host_int_frame_register 1243 * @brief host_int_frame_register
@@ -1249,7 +1248,7 @@ s32 host_int_ListenStateExpired(WILC_WFIDrvHandle hWFIDrv, u32 u32SessionID);
1249 * @date 1248 * @date
1250 * @version 1.0 1249 * @version 1.0
1251 */ 1250 */
1252s32 host_int_frame_register(WILC_WFIDrvHandle hWFIDrv, u16 u16FrameType, bool bReg); 1251s32 host_int_frame_register(tstrWILC_WFIDrv *hWFIDrv, u16 u16FrameType, bool bReg);
1253#endif 1252#endif
1254/** 1253/**
1255 * @brief host_int_set_wfi_drv_handler 1254 * @brief host_int_set_wfi_drv_handler
@@ -1260,18 +1259,18 @@ s32 host_int_frame_register(WILC_WFIDrvHandle hWFIDrv, u16 u16FrameType, bool bR
1260 * @date 1259 * @date
1261 * @version 1.0 1260 * @version 1.0
1262 */ 1261 */
1263s32 host_int_set_wfi_drv_handler(u32 u32address); 1262s32 host_int_set_wfi_drv_handler(tstrWILC_WFIDrv *u32address);
1264s32 host_int_set_operation_mode(WILC_WFIDrvHandle hWFIDrv, u32 u32mode); 1263s32 host_int_set_operation_mode(tstrWILC_WFIDrv *hWFIDrv, u32 u32mode);
1265 1264
1266static s32 Handle_ScanDone(void *drvHandler, tenuScanEvent enuEvent); 1265static s32 Handle_ScanDone(tstrWILC_WFIDrv *drvHandler, tenuScanEvent enuEvent);
1267 1266
1268static int host_int_addBASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char TID, short int BufferSize, 1267static int host_int_addBASession(tstrWILC_WFIDrv *hWFIDrv, char *pBSSID, char TID, short int BufferSize,
1269 short int SessionTimeout, void *drvHandler); 1268 short int SessionTimeout, void *drvHandler);
1270 1269
1271 1270
1272void host_int_freeJoinParams(void *pJoinParams); 1271void host_int_freeJoinParams(void *pJoinParams);
1273 1272
1274s32 host_int_get_statistics(WILC_WFIDrvHandle hWFIDrv, tstrStatistics *pstrStatistics); 1273s32 host_int_get_statistics(tstrWILC_WFIDrv *hWFIDrv, tstrStatistics *pstrStatistics);
1275 1274
1276/*****************************************************************************/ 1275/*****************************************************************************/
1277/* */ 1276/* */
diff --git a/drivers/staging/wilc1000/linux_mon.c b/drivers/staging/wilc1000/linux_mon.c
index f5296f53a3d2..123468a9582f 100644
--- a/drivers/staging/wilc1000/linux_mon.c
+++ b/drivers/staging/wilc1000/linux_mon.c
@@ -6,20 +6,15 @@
6 * @date 01 MAR 2012 6 * @date 01 MAR 2012
7 * @version 1.0 7 * @version 1.0
8 */ 8 */
9
10#ifndef SIMULATION
11#include "wilc_wfi_cfgoperations.h" 9#include "wilc_wfi_cfgoperations.h"
12#include "linux_wlan_common.h" 10#include "linux_wlan_common.h"
13#include "wilc_wlan_if.h" 11#include "wilc_wlan_if.h"
14#include "wilc_wlan.h" 12#include "wilc_wlan.h"
15#endif 13
16#ifdef WILC_FULLY_HOSTING_AP 14#ifdef WILC_FULLY_HOSTING_AP
17#include "wilc_host_ap.h" 15#include "wilc_host_ap.h"
18#endif 16#endif
19#ifdef WILC_AP_EXTERNAL_MLME 17#ifdef WILC_AP_EXTERNAL_MLME
20#ifdef SIMULATION
21#include "wilc_wfi_cfgoperations.h"
22#endif
23 18
24struct wilc_wfi_radiotap_hdr { 19struct wilc_wfi_radiotap_hdr {
25 struct ieee80211_radiotap_header hdr; 20 struct ieee80211_radiotap_header hdr;
@@ -39,9 +34,7 @@ extern linux_wlan_t *g_linux_wlan;
39 34
40static struct net_device *wilc_wfi_mon; /* global monitor netdev */ 35static struct net_device *wilc_wfi_mon; /* global monitor netdev */
41 36
42#ifdef SIMULATION 37#if USE_WIRELESS
43extern int WILC_WFI_Tx(struct sk_buff *skb, struct net_device *dev);
44#elif USE_WIRELESS
45extern int mac_xmit(struct sk_buff *skb, struct net_device *dev); 38extern int mac_xmit(struct sk_buff *skb, struct net_device *dev);
46#endif 39#endif
47 40
@@ -237,14 +230,12 @@ static void mgmt_tx_complete(void *priv, int status)
237} 230}
238static int mon_mgmt_tx(struct net_device *dev, const u8 *buf, size_t len) 231static int mon_mgmt_tx(struct net_device *dev, const u8 *buf, size_t len)
239{ 232{
240 linux_wlan_t *nic;
241 struct tx_complete_mon_data *mgmt_tx = NULL; 233 struct tx_complete_mon_data *mgmt_tx = NULL;
242 234
243 if (dev == NULL) { 235 if (dev == NULL) {
244 PRINT_D(HOSTAPD_DBG, "ERROR: dev == NULL\n"); 236 PRINT_D(HOSTAPD_DBG, "ERROR: dev == NULL\n");
245 return WILC_FAIL; 237 return WILC_FAIL;
246 } 238 }
247 nic = netdev_priv(dev);
248 239
249 netif_stop_queue(dev); 240 netif_stop_queue(dev);
250 mgmt_tx = kmalloc(sizeof(struct tx_complete_mon_data), GFP_ATOMIC); 241 mgmt_tx = kmalloc(sizeof(struct tx_complete_mon_data), GFP_ATOMIC);
@@ -298,7 +289,6 @@ static int mon_mgmt_tx(struct net_device *dev, const u8 *buf, size_t len)
298static netdev_tx_t WILC_WFI_mon_xmit(struct sk_buff *skb, 289static netdev_tx_t WILC_WFI_mon_xmit(struct sk_buff *skb,
299 struct net_device *dev) 290 struct net_device *dev)
300{ 291{
301 struct ieee80211_radiotap_header *rtap_hdr;
302 u32 rtap_len, i, ret = 0; 292 u32 rtap_len, i, ret = 0;
303 struct WILC_WFI_mon_priv *mon_priv; 293 struct WILC_WFI_mon_priv *mon_priv;
304 294
@@ -318,7 +308,6 @@ static netdev_tx_t WILC_WFI_mon_xmit(struct sk_buff *skb,
318 return WILC_FAIL; 308 return WILC_FAIL;
319 } 309 }
320 310
321 rtap_hdr = (struct ieee80211_radiotap_header *)skb->data;
322 311
323 rtap_len = ieee80211_get_radiotap_len(skb->data); 312 rtap_len = ieee80211_get_radiotap_len(skb->data);
324 if (skb->len < rtap_len) { 313 if (skb->len < rtap_len) {
@@ -378,9 +367,7 @@ static netdev_tx_t WILC_WFI_mon_xmit(struct sk_buff *skb,
378 PRINT_INFO(HOSTAPD_DBG, "SKB netdevice name = %s\n", skb->dev->name); 367 PRINT_INFO(HOSTAPD_DBG, "SKB netdevice name = %s\n", skb->dev->name);
379 PRINT_INFO(HOSTAPD_DBG, "MONITOR real dev name = %s\n", mon_priv->real_ndev->name); 368 PRINT_INFO(HOSTAPD_DBG, "MONITOR real dev name = %s\n", mon_priv->real_ndev->name);
380 369
381 #ifdef SIMULATION 370 #if USE_WIRELESS
382 ret = WILC_WFI_Tx(skb, mon_priv->real_ndev);
383 #elif USE_WIRELESS
384 /* Identify if Ethernet or MAC header (data or mgmt) */ 371 /* Identify if Ethernet or MAC header (data or mgmt) */
385 memcpy(srcAdd, &skb->data[10], 6); 372 memcpy(srcAdd, &skb->data[10], 6);
386 memcpy(bssid, &skb->data[16], 6); 373 memcpy(bssid, &skb->data[16], 6);
@@ -495,7 +482,7 @@ static void WILC_WFI_mon_setup(struct net_device *dev)
495 ether_setup(dev); 482 ether_setup(dev);
496 dev->tx_queue_len = 0; 483 dev->tx_queue_len = 0;
497 dev->type = ARPHRD_IEEE80211_RADIOTAP; 484 dev->type = ARPHRD_IEEE80211_RADIOTAP;
498 memset(dev->dev_addr, 0, ETH_ALEN); 485 eth_zero_addr(dev->dev_addr);
499 486
500 #ifdef USE_WIRELESS 487 #ifdef USE_WIRELESS
501 { 488 {
@@ -571,7 +558,7 @@ struct net_device *WILC_WFI_init_mon_interface(const char *name, struct net_devi
571 * @date 12 JUL 2012 558 * @date 12 JUL 2012
572 * @version 1.0 559 * @version 1.0
573 */ 560 */
574int WILC_WFI_deinit_mon_interface() 561int WILC_WFI_deinit_mon_interface(void)
575{ 562{
576 bool rollback_lock = false; 563 bool rollback_lock = false;
577 564
diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index b352c504a77d..b3cc9f5c7937 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -1,4 +1,3 @@
1#ifndef SIMULATION
2#include "wilc_wfi_cfgoperations.h" 1#include "wilc_wfi_cfgoperations.h"
3#include "linux_wlan_common.h" 2#include "linux_wlan_common.h"
4#include "wilc_wlan_if.h" 3#include "wilc_wlan_if.h"
@@ -72,7 +71,7 @@ extern void resolve_disconnect_aberration(void *drvHandler);
72extern u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN]; 71extern u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
73void wilc1000_wlan_deinit(linux_wlan_t *nic); 72void wilc1000_wlan_deinit(linux_wlan_t *nic);
74#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 73#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
75extern WILC_TimerHandle hDuringIpTimer; 74extern struct timer_list hDuringIpTimer;
76#endif 75#endif
77 76
78static int linux_wlan_device_power(int on_off) 77static int linux_wlan_device_power(int on_off)
@@ -103,7 +102,6 @@ static int linux_wlan_device_detection(int on_off)
103 return 0; 102 return 0;
104} 103}
105 104
106
107#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 105#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
108static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr); 106static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr);
109 107
@@ -116,7 +114,6 @@ static struct notifier_block g_dev_notifier = {
116 if (g_linux_wlan->oup.wlan_cleanup != NULL) \ 114 if (g_linux_wlan->oup.wlan_cleanup != NULL) \
117 g_linux_wlan->oup.wlan_cleanup(); } 115 g_linux_wlan->oup.wlan_cleanup(); }
118 116
119
120#ifndef STA_FIRMWARE 117#ifndef STA_FIRMWARE
121#define STA_FIRMWARE "wifi_firmware.bin" 118#define STA_FIRMWARE "wifi_firmware.bin"
122#endif 119#endif
@@ -129,15 +126,12 @@ static struct notifier_block g_dev_notifier = {
129#define P2P_CONCURRENCY_FIRMWARE "wifi_firmware_p2p_concurrency.bin" 126#define P2P_CONCURRENCY_FIRMWARE "wifi_firmware_p2p_concurrency.bin"
130#endif 127#endif
131 128
132
133
134typedef struct android_wifi_priv_cmd { 129typedef struct android_wifi_priv_cmd {
135 char *buf; 130 char *buf;
136 int used_len; 131 int used_len;
137 int total_len; 132 int total_len;
138} android_wifi_priv_cmd; 133} android_wifi_priv_cmd;
139 134
140
141#define IRQ_WAIT 1 135#define IRQ_WAIT 1
142#define IRQ_NO_WAIT 0 136#define IRQ_NO_WAIT 0
143/* 137/*
@@ -158,7 +152,6 @@ void linux_wlan_unlock(void *vp);
158extern void WILC_WFI_monitor_rx(uint8_t *buff, uint32_t size); 152extern void WILC_WFI_monitor_rx(uint8_t *buff, uint32_t size);
159extern void WILC_WFI_p2p_rx(struct net_device *dev, uint8_t *buff, uint32_t size); 153extern void WILC_WFI_p2p_rx(struct net_device *dev, uint8_t *buff, uint32_t size);
160 154
161
162static void *internal_alloc(uint32_t size, uint32_t flag); 155static void *internal_alloc(uint32_t size, uint32_t flag);
163static void linux_wlan_tx_complete(void *priv, int status); 156static void linux_wlan_tx_complete(void *priv, int status);
164void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset); 157void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset);
@@ -170,8 +163,6 @@ static struct net_device_stats *mac_stats(struct net_device *dev);
170static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd); 163static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd);
171static void wilc_set_multicast_list(struct net_device *dev); 164static void wilc_set_multicast_list(struct net_device *dev);
172 165
173
174
175/* 166/*
176 * for now - in frmw_to_linux there should be private data to be passed to it 167 * for now - in frmw_to_linux there should be private data to be passed to it
177 * and this data should be pointer to net device 168 * and this data should be pointer to net device
@@ -200,22 +191,18 @@ volatile int WatchDogdebuggerCounter;
200char DebugBuffer[DEGUG_BUFFER_LENGTH + 20] = {0}; 191char DebugBuffer[DEGUG_BUFFER_LENGTH + 20] = {0};
201static char *ps8current = DebugBuffer; 192static char *ps8current = DebugBuffer;
202 193
203
204
205void printk_later(const char *format, ...) 194void printk_later(const char *format, ...)
206{ 195{
207 va_list args; 196 va_list args;
208 va_start (args, format); 197 va_start(args, format);
209 ps8current += vsprintf (ps8current, format, args); 198 ps8current += vsprintf(ps8current, format, args);
210 va_end (args); 199 va_end(args);
211 if ((ps8current - DebugBuffer) > DEGUG_BUFFER_LENGTH) { 200 if ((ps8current - DebugBuffer) > DEGUG_BUFFER_LENGTH)
212 ps8current = DebugBuffer; 201 ps8current = DebugBuffer;
213 }
214 202
215} 203}
216 204
217 205void dump_logs(void)
218void dump_logs()
219{ 206{
220 if (DebugBuffer[0]) { 207 if (DebugBuffer[0]) {
221 DebugBuffer[DEGUG_BUFFER_LENGTH] = 0; 208 DebugBuffer[DEGUG_BUFFER_LENGTH] = 0;
@@ -229,7 +216,7 @@ void dump_logs()
229 } 216 }
230} 217}
231 218
232void Reset_WatchDogdebugger() 219void Reset_WatchDogdebugger(void)
233{ 220{
234 WatchDogdebuggerCounter = 0; 221 WatchDogdebuggerCounter = 0;
235} 222}
@@ -246,11 +233,8 @@ static int DebuggingThreadTask(void *vp)
246 WatchDogdebuggerCounter = 0; 233 WatchDogdebuggerCounter = 0;
247 } 234 }
248} 235}
249
250
251#endif 236#endif
252 237
253
254#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 238#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
255static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr) 239static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr)
256{ 240{
@@ -298,25 +282,22 @@ static int dev_state_ev_handler(struct notifier_block *this, unsigned long event
298 282
299 PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Obtained ===============\n\n"); 283 PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Obtained ===============\n\n");
300 284
301
302 /*If we are in station mode or client mode*/ 285 /*If we are in station mode or client mode*/
303 if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) { 286 if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) {
304 pstrWFIDrv->IFC_UP = 1; 287 pstrWFIDrv->IFC_UP = 1;
305 g_obtainingIP = false; 288 g_obtainingIP = false;
306 WILC_TimerStop(&hDuringIpTimer, NULL); 289 del_timer(&hDuringIpTimer);
307 PRINT_D(GENERIC_DBG, "IP obtained , enable scan\n"); 290 PRINT_D(GENERIC_DBG, "IP obtained , enable scan\n");
308 } 291 }
309 292
310
311
312 if (bEnablePS) 293 if (bEnablePS)
313 host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 1, 0); 294 host_int_set_power_mgmt(pstrWFIDrv, 1, 0);
314 295
315 PRINT_D(GENERIC_DBG, "[%s] Up IP\n", dev_iface->ifa_label); 296 PRINT_D(GENERIC_DBG, "[%s] Up IP\n", dev_iface->ifa_label);
316 297
317 pIP_Add_buff = (char *) (&(dev_iface->ifa_address)); 298 pIP_Add_buff = (char *) (&(dev_iface->ifa_address));
318 PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d \n", pIP_Add_buff[0], pIP_Add_buff[1], pIP_Add_buff[2], pIP_Add_buff[3]); 299 PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d\n", pIP_Add_buff[0], pIP_Add_buff[1], pIP_Add_buff[2], pIP_Add_buff[3]);
319 host_int_setup_ipaddress((WILC_WFIDrvHandle)pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx); 300 host_int_setup_ipaddress(pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx);
320 301
321 break; 302 break;
322 303
@@ -330,17 +311,16 @@ static int dev_state_ev_handler(struct notifier_block *this, unsigned long event
330 } 311 }
331 312
332 if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0) 313 if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
333 host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 0, 0); 314 host_int_set_power_mgmt(pstrWFIDrv, 0, 0);
334 315
335 resolve_disconnect_aberration(pstrWFIDrv); 316 resolve_disconnect_aberration(pstrWFIDrv);
336 317
337
338 PRINT_D(GENERIC_DBG, "[%s] Down IP\n", dev_iface->ifa_label); 318 PRINT_D(GENERIC_DBG, "[%s] Down IP\n", dev_iface->ifa_label);
339 319
340 pIP_Add_buff = null_ip; 320 pIP_Add_buff = null_ip;
341 PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d \n", pIP_Add_buff[0], pIP_Add_buff[1], pIP_Add_buff[2], pIP_Add_buff[3]); 321 PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d\n", pIP_Add_buff[0], pIP_Add_buff[1], pIP_Add_buff[2], pIP_Add_buff[3]);
342 322
343 host_int_setup_ipaddress((WILC_WFIDrvHandle)pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx); 323 host_int_setup_ipaddress(pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx);
344 324
345 break; 325 break;
346 326
@@ -387,8 +367,6 @@ void linux_wlan_disable_irq(int wait)
387#if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO) 367#if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
388static irqreturn_t isr_uh_routine(int irq, void *user_data) 368static irqreturn_t isr_uh_routine(int irq, void *user_data)
389{ 369{
390
391
392 int_rcvdU++; 370 int_rcvdU++;
393#if (RX_BH_TYPE != RX_BH_THREADED_IRQ) 371#if (RX_BH_TYPE != RX_BH_THREADED_IRQ)
394 linux_wlan_disable_irq(IRQ_NO_WAIT); 372 linux_wlan_disable_irq(IRQ_NO_WAIT);
@@ -440,19 +418,14 @@ static void isr_bh_routine(struct work_struct *work)
440 #else 418 #else
441 return; 419 return;
442 #endif 420 #endif
443
444
445
446 } 421 }
447 422
448 int_rcvdB++; 423 int_rcvdB++;
449 PRINT_D(INT_DBG, "Interrupt received BH\n"); 424 PRINT_D(INT_DBG, "Interrupt received BH\n");
450 if (g_linux_wlan->oup.wlan_handle_rx_isr != 0) { 425 if (g_linux_wlan->oup.wlan_handle_rx_isr != 0)
451 g_linux_wlan->oup.wlan_handle_rx_isr(); 426 g_linux_wlan->oup.wlan_handle_rx_isr();
452 } else { 427 else
453 PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n"); 428 PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n");
454 }
455
456 429
457#if (RX_BH_TYPE == RX_BH_THREADED_IRQ) 430#if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
458 return IRQ_HANDLED; 431 return IRQ_HANDLED;
@@ -476,18 +449,16 @@ static int isr_bh_routine(void *vp)
476 } 449 }
477 int_rcvdB++; 450 int_rcvdB++;
478 PRINT_D(INT_DBG, "Interrupt received BH\n"); 451 PRINT_D(INT_DBG, "Interrupt received BH\n");
479 if (g_linux_wlan->oup.wlan_handle_rx_isr != 0) { 452 if (g_linux_wlan->oup.wlan_handle_rx_isr != 0)
480 g_linux_wlan->oup.wlan_handle_rx_isr(); 453 g_linux_wlan->oup.wlan_handle_rx_isr();
481 } else { 454 else
482 PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n"); 455 PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n");
483 }
484 } 456 }
485 457
486 return 0; 458 return 0;
487} 459}
488#endif 460#endif
489 461
490
491#if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO) 462#if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
492static int init_irq(linux_wlan_t *p_nic) 463static int init_irq(linux_wlan_t *p_nic)
493{ 464{
@@ -504,9 +475,9 @@ static int init_irq(linux_wlan_t *p_nic)
504 * 475 *
505 * ex) nic->dev_irq_num = gpio_to_irq(GPIO_NUM); 476 * ex) nic->dev_irq_num = gpio_to_irq(GPIO_NUM);
506 */ 477 */
507#elif defined (NM73131_0_BOARD) 478#elif defined(NM73131_0_BOARD)
508 nic->dev_irq_num = IRQ_WILC1000; 479 nic->dev_irq_num = IRQ_WILC1000;
509#elif defined (PANDA_BOARD) 480#elif defined(PANDA_BOARD)
510 gpio_export(GPIO_NUM, 1); 481 gpio_export(GPIO_NUM, 1);
511 nic->dev_irq_num = OMAP_GPIO_IRQ(GPIO_NUM); 482 nic->dev_irq_num = OMAP_GPIO_IRQ(GPIO_NUM);
512 irq_set_irq_type(nic->dev_irq_num, IRQ_TYPE_LEVEL_LOW); 483 irq_set_irq_type(nic->dev_irq_num, IRQ_TYPE_LEVEL_LOW);
@@ -518,7 +489,6 @@ static int init_irq(linux_wlan_t *p_nic)
518 PRINT_ER("could not obtain gpio for WILC_INTR\n"); 489 PRINT_ER("could not obtain gpio for WILC_INTR\n");
519 } 490 }
520 491
521
522#if (RX_BH_TYPE == RX_BH_THREADED_IRQ) 492#if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
523 if ((ret != -1) && (request_threaded_irq(nic->dev_irq_num, isr_uh_routine, isr_bh_routine, 493 if ((ret != -1) && (request_threaded_irq(nic->dev_irq_num, isr_uh_routine, isr_bh_routine,
524 IRQF_TRIGGER_LOW | IRQF_ONESHOT, /*Without IRQF_ONESHOT the uh will remain kicked in and dont gave a chance to bh*/ 494 IRQF_TRIGGER_LOW | IRQF_ONESHOT, /*Without IRQF_ONESHOT the uh will remain kicked in and dont gave a chance to bh*/
@@ -554,7 +524,6 @@ static void deinit_irq(linux_wlan_t *nic)
554#endif 524#endif
555} 525}
556 526
557
558/* 527/*
559 * OS functions 528 * OS functions
560 */ 529 */
@@ -601,7 +570,6 @@ void linux_wlan_free(void *vp)
601 } 570 }
602} 571}
603 572
604
605static void *internal_alloc(uint32_t size, uint32_t flag) 573static void *internal_alloc(uint32_t size, uint32_t flag)
606{ 574{
607 char *pntr = NULL; 575 char *pntr = NULL;
@@ -610,7 +578,6 @@ static void *internal_alloc(uint32_t size, uint32_t flag)
610 return (void *)pntr; 578 return (void *)pntr;
611} 579}
612 580
613
614static void linux_wlan_init_lock(char *lockName, void *plock, int count) 581static void linux_wlan_init_lock(char *lockName, void *plock, int count)
615{ 582{
616 sema_init((struct semaphore *)plock, count); 583 sema_init((struct semaphore *)plock, count);
@@ -638,25 +605,22 @@ static int linux_wlan_lock_timeout(void *vp, u32 timeout)
638{ 605{
639 int error = -1; 606 int error = -1;
640 PRINT_D(LOCK_DBG, "Locking %p\n", vp); 607 PRINT_D(LOCK_DBG, "Locking %p\n", vp);
641 if (vp != NULL) { 608 if (vp != NULL)
642 error = down_timeout((struct semaphore *)vp, msecs_to_jiffies(timeout)); 609 error = down_timeout((struct semaphore *)vp, msecs_to_jiffies(timeout));
643 } else { 610 else
644 PRINT_ER("Failed, mutex is NULL\n"); 611 PRINT_ER("Failed, mutex is NULL\n");
645 }
646 return error; 612 return error;
647} 613}
648 614
649void linux_wlan_unlock(void *vp) 615void linux_wlan_unlock(void *vp)
650{ 616{
651 PRINT_D(LOCK_DBG, "Unlocking %p\n", vp); 617 PRINT_D(LOCK_DBG, "Unlocking %p\n", vp);
652 if (vp != NULL) { 618 if (vp != NULL)
653 up((struct semaphore *)vp); 619 up((struct semaphore *)vp);
654 } else { 620 else
655 PRINT_ER("Failed, mutex is NULL\n"); 621 PRINT_ER("Failed, mutex is NULL\n");
656 }
657} 622}
658 623
659
660static void linux_wlan_init_mutex(char *lockName, void *plock, int count) 624static void linux_wlan_init_mutex(char *lockName, void *plock, int count)
661{ 625{
662 mutex_init((struct mutex *)plock); 626 mutex_init((struct mutex *)plock);
@@ -702,7 +666,6 @@ static void linux_wlan_unlock_mutex(void *vp)
702 } 666 }
703} 667}
704 668
705
706/*Added by Amr - BugID_4720*/ 669/*Added by Amr - BugID_4720*/
707static void linux_wlan_init_spin_lock(char *lockName, void *plock, int count) 670static void linux_wlan_init_spin_lock(char *lockName, void *plock, int count)
708{ 671{
@@ -780,9 +743,8 @@ struct net_device *GetIfHandler(uint8_t *pMacHeader)
780 } 743 }
781 } 744 }
782 PRINT_INFO(INIT_DBG, "Invalide handle\n"); 745 PRINT_INFO(INIT_DBG, "Invalide handle\n");
783 for (i = 0; i < 25; i++) { 746 for (i = 0; i < 25; i++)
784 PRINT_D(INIT_DBG, "%02x ", pMacHeader[i]); 747 PRINT_D(INIT_DBG, "%02x ", pMacHeader[i]);
785 }
786 Bssid = pMacHeader + 18; 748 Bssid = pMacHeader + 18;
787 Bssid1 = pMacHeader + 12; 749 Bssid1 = pMacHeader + 12;
788 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) { 750 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
@@ -822,9 +784,8 @@ int linux_wlan_get_num_conn_ifcs(void)
822 uint8_t ret_val = 0; 784 uint8_t ret_val = 0;
823 785
824 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) { 786 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
825 if (memcmp(g_linux_wlan->strInterfaceInfo[i].aBSSID, null_bssid, 6)) { 787 if (memcmp(g_linux_wlan->strInterfaceInfo[i].aBSSID, null_bssid, 6))
826 ret_val++; 788 ret_val++;
827 }
828 } 789 }
829 return ret_val; 790 return ret_val;
830} 791}
@@ -868,7 +829,6 @@ static int linux_wlan_txq_task(void *vp)
868#define TX_BACKOFF_WEIGHT_MIN (0) 829#define TX_BACKOFF_WEIGHT_MIN (0)
869#define TX_BACKOFF_WEIGHT_UNIT_MS (10) 830#define TX_BACKOFF_WEIGHT_UNIT_MS (10)
870 int backoff_weight = TX_BACKOFF_WEIGHT_MIN; 831 int backoff_weight = TX_BACKOFF_WEIGHT_MIN;
871 signed long timeout;
872#endif 832#endif
873 833
874 /* inform wilc1000_wlan_init that TXQ task is started. */ 834 /* inform wilc1000_wlan_init that TXQ task is started. */
@@ -906,7 +866,6 @@ static int linux_wlan_txq_task(void *vp)
906 } 866 }
907 867
908 if (ret == WILC_TX_ERR_NO_BUF) { /* failed to allocate buffers in chip. */ 868 if (ret == WILC_TX_ERR_NO_BUF) { /* failed to allocate buffers in chip. */
909 timeout = msecs_to_jiffies(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight);
910 do { 869 do {
911 /* Back off from sending packets for some time. */ 870 /* Back off from sending packets for some time. */
912 /* schedule_timeout will allow RX task to run and free buffers.*/ 871 /* schedule_timeout will allow RX task to run and free buffers.*/
@@ -915,15 +874,13 @@ static int linux_wlan_txq_task(void *vp)
915 msleep(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight); 874 msleep(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight);
916 } while (/*timeout*/ 0); 875 } while (/*timeout*/ 0);
917 backoff_weight += TX_BACKOFF_WEIGHT_INCR_STEP; 876 backoff_weight += TX_BACKOFF_WEIGHT_INCR_STEP;
918 if (backoff_weight > TX_BACKOFF_WEIGHT_MAX) { 877 if (backoff_weight > TX_BACKOFF_WEIGHT_MAX)
919 backoff_weight = TX_BACKOFF_WEIGHT_MAX; 878 backoff_weight = TX_BACKOFF_WEIGHT_MAX;
920 }
921 } else { 879 } else {
922 if (backoff_weight > TX_BACKOFF_WEIGHT_MIN) { 880 if (backoff_weight > TX_BACKOFF_WEIGHT_MIN) {
923 backoff_weight -= TX_BACKOFF_WEIGHT_DECR_STEP; 881 backoff_weight -= TX_BACKOFF_WEIGHT_DECR_STEP;
924 if (backoff_weight < TX_BACKOFF_WEIGHT_MIN) { 882 if (backoff_weight < TX_BACKOFF_WEIGHT_MIN)
925 backoff_weight = TX_BACKOFF_WEIGHT_MIN; 883 backoff_weight = TX_BACKOFF_WEIGHT_MIN;
926 }
927 } 884 }
928 } 885 }
929 /*TODO: drop packets after a certain time/number of retry count. */ 886 /*TODO: drop packets after a certain time/number of retry count. */
@@ -946,7 +903,6 @@ int linux_wlan_get_firmware(perInterface_wlan_t *p_nic)
946 const struct firmware *wilc_firmware; 903 const struct firmware *wilc_firmware;
947 char *firmware; 904 char *firmware;
948 905
949
950 if (nic->iftype == AP_MODE) 906 if (nic->iftype == AP_MODE)
951 firmware = AP_FIRMWARE; 907 firmware = AP_FIRMWARE;
952 else if (nic->iftype == STATION_MODE) 908 else if (nic->iftype == STATION_MODE)
@@ -958,8 +914,6 @@ int linux_wlan_get_firmware(perInterface_wlan_t *p_nic)
958 firmware = P2P_CONCURRENCY_FIRMWARE; 914 firmware = P2P_CONCURRENCY_FIRMWARE;
959 } 915 }
960 916
961
962
963 if (nic == NULL) { 917 if (nic == NULL) {
964 PRINT_ER("NIC is NULL\n"); 918 PRINT_ER("NIC is NULL\n");
965 goto _fail_; 919 goto _fail_;
@@ -970,7 +924,6 @@ int linux_wlan_get_firmware(perInterface_wlan_t *p_nic)
970 goto _fail_; 924 goto _fail_;
971 } 925 }
972 926
973
974 /* the firmare should be located in /lib/firmware in 927 /* the firmare should be located in /lib/firmware in
975 * root file system with the name specified above */ 928 * root file system with the name specified above */
976 929
@@ -1054,9 +1007,8 @@ static int linux_wlan_firmware_download(linux_wlan_t *p_nic)
1054 **/ 1007 **/
1055 PRINT_D(INIT_DBG, "Downloading Firmware ...\n"); 1008 PRINT_D(INIT_DBG, "Downloading Firmware ...\n");
1056 ret = g_linux_wlan->oup.wlan_firmware_download(g_linux_wlan->wilc_firmware->data, g_linux_wlan->wilc_firmware->size); 1009 ret = g_linux_wlan->oup.wlan_firmware_download(g_linux_wlan->wilc_firmware->data, g_linux_wlan->wilc_firmware->size);
1057 if (ret < 0) { 1010 if (ret < 0)
1058 goto _FAIL_; 1011 goto _FAIL_;
1059 }
1060 1012
1061 /* Freeing FW buffer */ 1013 /* Freeing FW buffer */
1062 PRINT_D(INIT_DBG, "Freeing FW buffer ...\n"); 1014 PRINT_D(INIT_DBG, "Freeing FW buffer ...\n");
@@ -1064,13 +1016,12 @@ static int linux_wlan_firmware_download(linux_wlan_t *p_nic)
1064 release_firmware(g_linux_wlan->wilc_firmware); 1016 release_firmware(g_linux_wlan->wilc_firmware);
1065 g_linux_wlan->wilc_firmware = NULL; 1017 g_linux_wlan->wilc_firmware = NULL;
1066 1018
1067 PRINT_D(INIT_DBG, "Download Succeeded \n"); 1019 PRINT_D(INIT_DBG, "Download Succeeded\n");
1068 1020
1069_FAIL_: 1021_FAIL_:
1070 return ret; 1022 return ret;
1071} 1023}
1072 1024
1073
1074/* startup configuration - could be changed later using iconfig*/ 1025/* startup configuration - could be changed later using iconfig*/
1075static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_nic) 1026static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_nic)
1076{ 1027{
@@ -1096,7 +1047,6 @@ static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_n
1096 PRINT_D(INIT_DBG, "MAC address is : %02x-%02x-%02x-%02x-%02x-%02x\n", mac_add[0], mac_add[1], mac_add[2], mac_add[3], mac_add[4], mac_add[5]); 1047 PRINT_D(INIT_DBG, "MAC address is : %02x-%02x-%02x-%02x-%02x-%02x\n", mac_add[0], mac_add[1], mac_add[2], mac_add[3], mac_add[4], mac_add[5]);
1097 wilc_get_chipid(0); 1048 wilc_get_chipid(0);
1098 1049
1099
1100 if (g_linux_wlan->oup.wlan_cfg_set == NULL) { 1050 if (g_linux_wlan->oup.wlan_cfg_set == NULL) {
1101 PRINT_D(INIT_DBG, "Null p[ointer\n"); 1051 PRINT_D(INIT_DBG, "Null p[ointer\n");
1102 goto _fail_; 1052 goto _fail_;
@@ -1116,7 +1066,6 @@ static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_n
1116 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BSS_TYPE, c_val, 1, 0, 0)) 1066 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BSS_TYPE, c_val, 1, 0, 0))
1117 goto _fail_; 1067 goto _fail_;
1118 1068
1119
1120 /* c_val[0] = RATE_AUTO; / * bug 4275: Enable autorate and limit it to 24Mbps * / */ 1069 /* c_val[0] = RATE_AUTO; / * bug 4275: Enable autorate and limit it to 24Mbps * / */
1121 c_val[0] = RATE_AUTO; 1070 c_val[0] = RATE_AUTO;
1122 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0)) 1071 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0))
@@ -1351,7 +1300,6 @@ _fail_:
1351 return -1; 1300 return -1;
1352} 1301}
1353 1302
1354
1355/**************************/ 1303/**************************/
1356void wilc1000_wlan_deinit(linux_wlan_t *nic) 1304void wilc1000_wlan_deinit(linux_wlan_t *nic)
1357{ 1305{
@@ -1385,16 +1333,12 @@ void wilc1000_wlan_deinit(linux_wlan_t *nic)
1385 #endif 1333 #endif
1386 #endif 1334 #endif
1387 1335
1388
1389 /* not sure if the following unlocks are needed or not*/ 1336 /* not sure if the following unlocks are needed or not*/
1390 if (&g_linux_wlan->rxq_event != NULL) { 1337 if (&g_linux_wlan->rxq_event != NULL)
1391 linux_wlan_unlock(&g_linux_wlan->rxq_event); 1338 linux_wlan_unlock(&g_linux_wlan->rxq_event);
1392 }
1393 1339
1394 if (&g_linux_wlan->txq_event != NULL) { 1340 if (&g_linux_wlan->txq_event != NULL)
1395 linux_wlan_unlock(&g_linux_wlan->txq_event); 1341 linux_wlan_unlock(&g_linux_wlan->txq_event);
1396 }
1397
1398 1342
1399 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE) 1343 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
1400 /*Removing the work struct from the linux kernel workqueue*/ 1344 /*Removing the work struct from the linux kernel workqueue*/
@@ -1412,7 +1356,6 @@ void wilc1000_wlan_deinit(linux_wlan_t *nic)
1412 PRINT_D(INIT_DBG, "Deinitializing IRQ\n"); 1356 PRINT_D(INIT_DBG, "Deinitializing IRQ\n");
1413 deinit_irq(g_linux_wlan); 1357 deinit_irq(g_linux_wlan);
1414 1358
1415
1416 if (&g_linux_wlan->oup != NULL) { 1359 if (&g_linux_wlan->oup != NULL) {
1417 if (g_linux_wlan->oup.wlan_stop != NULL) 1360 if (g_linux_wlan->oup.wlan_stop != NULL)
1418 g_linux_wlan->oup.wlan_stop(); 1361 g_linux_wlan->oup.wlan_stop();
@@ -1442,7 +1385,6 @@ void wilc1000_wlan_deinit(linux_wlan_t *nic)
1442 } else { 1385 } else {
1443 PRINT_D(INIT_DBG, "wilc1000 is not initialized\n"); 1386 PRINT_D(INIT_DBG, "wilc1000 is not initialized\n");
1444 } 1387 }
1445 return;
1446} 1388}
1447 1389
1448int wlan_init_locks(linux_wlan_t *p_nic) 1390int wlan_init_locks(linux_wlan_t *p_nic)
@@ -1536,7 +1478,7 @@ void linux_to_wlan(wilc_wlan_inp_t *nwi, linux_wlan_t *nic)
1536 1478
1537 nwi->os_context.txq_wait_event = (void *)&g_linux_wlan->txq_event; 1479 nwi->os_context.txq_wait_event = (void *)&g_linux_wlan->txq_event;
1538 1480
1539#if defined (MEMORY_STATIC) 1481#if defined(MEMORY_STATIC)
1540 nwi->os_context.rx_buffer_size = LINUX_RX_SIZE; 1482 nwi->os_context.rx_buffer_size = LINUX_RX_SIZE;
1541#endif 1483#endif
1542 nwi->os_context.rxq_critical_section = (void *)&g_linux_wlan->rxq_cs; 1484 nwi->os_context.rxq_critical_section = (void *)&g_linux_wlan->rxq_cs;
@@ -1673,17 +1615,14 @@ static void wlan_deinitialize_threads(linux_wlan_t *nic)
1673 if (&g_linux_wlan->rxq_event != NULL) 1615 if (&g_linux_wlan->rxq_event != NULL)
1674 linux_wlan_unlock(&g_linux_wlan->rxq_event); 1616 linux_wlan_unlock(&g_linux_wlan->rxq_event);
1675 1617
1676
1677 if (g_linux_wlan->rxq_thread != NULL) { 1618 if (g_linux_wlan->rxq_thread != NULL) {
1678 kthread_stop(g_linux_wlan->rxq_thread); 1619 kthread_stop(g_linux_wlan->rxq_thread);
1679 g_linux_wlan->rxq_thread = NULL; 1620 g_linux_wlan->rxq_thread = NULL;
1680 } 1621 }
1681 1622
1682
1683 if (&g_linux_wlan->txq_event != NULL) 1623 if (&g_linux_wlan->txq_event != NULL)
1684 linux_wlan_unlock(&g_linux_wlan->txq_event); 1624 linux_wlan_unlock(&g_linux_wlan->txq_event);
1685 1625
1686
1687 if (g_linux_wlan->txq_thread != NULL) { 1626 if (g_linux_wlan->txq_thread != NULL) {
1688 kthread_stop(g_linux_wlan->txq_thread); 1627 kthread_stop(g_linux_wlan->txq_thread);
1689 g_linux_wlan->txq_thread = NULL; 1628 g_linux_wlan->txq_thread = NULL;
@@ -1747,14 +1686,12 @@ static int linux_wlan_read_mac_addr(void *vp)
1747 } 1686 }
1748 } 1687 }
1749 1688
1750 if (index == array_size) { 1689 if (index == array_size)
1751 PRINT_ER("random MAC\n"); 1690 PRINT_ER("random MAC\n");
1752 }
1753 1691
1754exit: 1692exit:
1755 if (fp && !IS_ERR(fp)) { 1693 if (fp && !IS_ERR(fp))
1756 filp_close(fp, NULL); 1694 filp_close(fp, NULL);
1757 }
1758 1695
1759 set_fs(old_fs); 1696 set_fs(old_fs);
1760 1697
@@ -1786,9 +1723,8 @@ uint8_t wilc1000_prepare_11b_core(wilc_wlan_inp_t *nwi, wilc_wlan_oup_t *nwo, li
1786 1723
1787 sdio_register_driver(&wilc_bus); 1724 sdio_register_driver(&wilc_bus);
1788 1725
1789 while (!probe) { 1726 while (!probe)
1790 msleep(100); 1727 msleep(100);
1791 }
1792 probe = 0; 1728 probe = 0;
1793 g_linux_wlan->wilc_sdio_func = local_sdio_func; 1729 g_linux_wlan->wilc_sdio_func = local_sdio_func;
1794 linux_to_wlan(nwi, nic); 1730 linux_to_wlan(nwi, nic);
@@ -1820,9 +1756,8 @@ int repeat_power_cycle(perInterface_wlan_t *nic)
1820 sdio_register_driver(&wilc_bus); 1756 sdio_register_driver(&wilc_bus);
1821 1757
1822 /* msleep(1000); */ 1758 /* msleep(1000); */
1823 while (!probe) { 1759 while (!probe)
1824 msleep(100); 1760 msleep(100);
1825 }
1826 probe = 0; 1761 probe = 0;
1827 g_linux_wlan->wilc_sdio_func = local_sdio_func; 1762 g_linux_wlan->wilc_sdio_func = local_sdio_func;
1828 linux_to_wlan(&nwi, g_linux_wlan); 1763 linux_to_wlan(&nwi, g_linux_wlan);
@@ -1834,7 +1769,7 @@ int repeat_power_cycle(perInterface_wlan_t *nic)
1834 #endif 1769 #endif
1835 1770
1836 if (linux_wlan_get_firmware(nic)) { 1771 if (linux_wlan_get_firmware(nic)) {
1837 PRINT_ER("Can't get firmware \n"); 1772 PRINT_ER("Can't get firmware\n");
1838 ret = -1; 1773 ret = -1;
1839 goto __fail__; 1774 goto __fail__;
1840 } 1775 }
@@ -1847,9 +1782,8 @@ int repeat_power_cycle(perInterface_wlan_t *nic)
1847 } 1782 }
1848 /* Start firmware*/ 1783 /* Start firmware*/
1849 ret = linux_wlan_start_firmware(nic); 1784 ret = linux_wlan_start_firmware(nic);
1850 if (ret < 0) { 1785 if (ret < 0)
1851 PRINT_ER("Failed to start firmware\n"); 1786 PRINT_ER("Failed to start firmware\n");
1852 }
1853__fail__: 1787__fail__:
1854 return ret; 1788 return ret;
1855} 1789}
@@ -1871,9 +1805,8 @@ int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
1871 1805
1872#ifdef STATIC_MACADDRESS 1806#ifdef STATIC_MACADDRESS
1873 wilc_mac_thread = kthread_run(linux_wlan_read_mac_addr, NULL, "wilc_mac_thread"); 1807 wilc_mac_thread = kthread_run(linux_wlan_read_mac_addr, NULL, "wilc_mac_thread");
1874 if (wilc_mac_thread < 0) { 1808 if (wilc_mac_thread < 0)
1875 PRINT_ER("couldn't create Mac addr thread\n"); 1809 PRINT_ER("couldn't create Mac addr thread\n");
1876 }
1877#endif 1810#endif
1878 1811
1879 linux_to_wlan(&nwi, g_linux_wlan); 1812 linux_to_wlan(&nwi, g_linux_wlan);
@@ -1889,7 +1822,6 @@ int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
1889 /*Save the oup structre into global pointer*/ 1822 /*Save the oup structre into global pointer*/
1890 gpstrWlanOps = &g_linux_wlan->oup; 1823 gpstrWlanOps = &g_linux_wlan->oup;
1891 1824
1892
1893 ret = wlan_initialize_threads(nic); 1825 ret = wlan_initialize_threads(nic);
1894 if (ret < 0) { 1826 if (ret < 0) {
1895 PRINT_ER("Initializing Threads FAILED\n"); 1827 PRINT_ER("Initializing Threads FAILED\n");
@@ -1922,12 +1854,11 @@ int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
1922#endif 1854#endif
1923 1855
1924 if (linux_wlan_get_firmware(nic)) { 1856 if (linux_wlan_get_firmware(nic)) {
1925 PRINT_ER("Can't get firmware \n"); 1857 PRINT_ER("Can't get firmware\n");
1926 ret = -EIO; 1858 ret = -EIO;
1927 goto _fail_irq_enable_; 1859 goto _fail_irq_enable_;
1928 } 1860 }
1929 1861
1930
1931 /*Download firmware*/ 1862 /*Download firmware*/
1932 ret = linux_wlan_firmware_download(g_linux_wlan); 1863 ret = linux_wlan_firmware_download(g_linux_wlan);
1933 if (ret < 0) { 1864 if (ret < 0) {
@@ -1967,7 +1898,6 @@ int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
1967 g_linux_wlan->wilc1000_initialized = 1; 1898 g_linux_wlan->wilc1000_initialized = 1;
1968 return 0; /*success*/ 1899 return 0; /*success*/
1969 1900
1970
1971_fail_fw_start_: 1901_fail_fw_start_:
1972 if (&g_linux_wlan->oup != NULL) { 1902 if (&g_linux_wlan->oup != NULL) {
1973 if (g_linux_wlan->oup.wlan_stop != NULL) 1903 if (g_linux_wlan->oup.wlan_stop != NULL)
@@ -1996,12 +1926,11 @@ _fail_locks_:
1996 return ret; 1926 return ret;
1997} 1927}
1998 1928
1999
2000/* 1929/*
2001 * - this function will be called automatically by OS when module inserted. 1930 * - this function will be called automatically by OS when module inserted.
2002 */ 1931 */
2003 1932
2004#if !defined (NM73131_0_BOARD) 1933#if !defined(NM73131_0_BOARD)
2005int mac_init_fn(struct net_device *ndev) 1934int mac_init_fn(struct net_device *ndev)
2006{ 1935{
2007 1936
@@ -2028,12 +1957,11 @@ int mac_init_fn(struct net_device *ndev)
2028} 1957}
2029#endif 1958#endif
2030 1959
2031
2032void WILC_WFI_frame_register(struct wiphy *wiphy, struct net_device *dev, 1960void WILC_WFI_frame_register(struct wiphy *wiphy, struct net_device *dev,
2033 u16 frame_type, bool reg); 1961 u16 frame_type, bool reg);
2034 1962
2035/* This fn is called, when this device is setup using ifconfig */ 1963/* This fn is called, when this device is setup using ifconfig */
2036#if !defined (NM73131_0_BOARD) 1964#if !defined(NM73131_0_BOARD)
2037int mac_open(struct net_device *ndev) 1965int mac_open(struct net_device *ndev)
2038{ 1966{
2039 perInterface_wlan_t *nic; 1967 perInterface_wlan_t *nic;
@@ -2078,7 +2006,7 @@ int mac_open(struct net_device *ndev)
2078 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) { 2006 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
2079 if (ndev == g_linux_wlan->strInterfaceInfo[i].wilc_netdev) { 2007 if (ndev == g_linux_wlan->strInterfaceInfo[i].wilc_netdev) {
2080 memcpy(g_linux_wlan->strInterfaceInfo[i].aSrcAddress, mac_add, ETH_ALEN); 2008 memcpy(g_linux_wlan->strInterfaceInfo[i].aSrcAddress, mac_add, ETH_ALEN);
2081 g_linux_wlan->strInterfaceInfo[i].drvHandler = (u32)priv->hWILCWFIDrv; 2009 g_linux_wlan->strInterfaceInfo[i].drvHandler = priv->hWILCWFIDrv;
2082 break; 2010 break;
2083 } 2011 }
2084 } 2012 }
@@ -2092,7 +2020,6 @@ int mac_open(struct net_device *ndev)
2092 goto _err_; 2020 goto _err_;
2093 } 2021 }
2094 2022
2095
2096 WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev, 2023 WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev,
2097 nic->g_struct_frame_reg[0].frame_type, nic->g_struct_frame_reg[0].reg); 2024 nic->g_struct_frame_reg[0].frame_type, nic->g_struct_frame_reg[0].reg);
2098 WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev, 2025 WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev,
@@ -2131,7 +2058,6 @@ struct net_device_stats *mac_stats(struct net_device *dev)
2131{ 2058{
2132 perInterface_wlan_t *nic = netdev_priv(dev); 2059 perInterface_wlan_t *nic = netdev_priv(dev);
2133 2060
2134
2135 return &nic->netstats; 2061 return &nic->netstats;
2136} 2062}
2137 2063
@@ -2146,17 +2072,16 @@ static void wilc_set_multicast_list(struct net_device *dev)
2146 priv = wiphy_priv(dev->ieee80211_ptr->wiphy); 2072 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
2147 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv; 2073 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
2148 2074
2149
2150 if (!dev) 2075 if (!dev)
2151 return; 2076 return;
2152 2077
2153 PRINT_D(INIT_DBG, "Setting Multicast List with count = %d. \n", dev->mc.count); 2078 PRINT_D(INIT_DBG, "Setting Multicast List with count = %d.\n", dev->mc.count);
2154 2079
2155 if (dev->flags & IFF_PROMISC) { 2080 if (dev->flags & IFF_PROMISC) {
2156 /* Normally, we should configure the chip to retrive all packets 2081 /* Normally, we should configure the chip to retrive all packets
2157 * but we don't wanna support this right now */ 2082 * but we don't wanna support this right now */
2158 /* TODO: add promiscuous mode support */ 2083 /* TODO: add promiscuous mode support */
2159 PRINT_D(INIT_DBG, "Set promiscuous mode ON, retrive all packets \n"); 2084 PRINT_D(INIT_DBG, "Set promiscuous mode ON, retrive all packets\n");
2160 return; 2085 return;
2161 } 2086 }
2162 2087
@@ -2165,27 +2090,27 @@ static void wilc_set_multicast_list(struct net_device *dev)
2165 if ((dev->flags & IFF_ALLMULTI) || (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) { 2090 if ((dev->flags & IFF_ALLMULTI) || (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) {
2166 PRINT_D(INIT_DBG, "Disable multicast filter, retrive all multicast packets\n"); 2091 PRINT_D(INIT_DBG, "Disable multicast filter, retrive all multicast packets\n");
2167 /* get all multicast packets */ 2092 /* get all multicast packets */
2168 host_int_setup_multicast_filter((WILC_WFIDrvHandle)pstrWFIDrv, false, 0); 2093 host_int_setup_multicast_filter(pstrWFIDrv, false, 0);
2169 return; 2094 return;
2170 } 2095 }
2171 2096
2172 /* No multicast? Just get our own stuff */ 2097 /* No multicast? Just get our own stuff */
2173 if ((dev->mc.count) == 0) { 2098 if ((dev->mc.count) == 0) {
2174 PRINT_D(INIT_DBG, "Enable multicast filter, retrive directed packets only.\n"); 2099 PRINT_D(INIT_DBG, "Enable multicast filter, retrive directed packets only.\n");
2175 host_int_setup_multicast_filter((WILC_WFIDrvHandle)pstrWFIDrv, true, 0); 2100 host_int_setup_multicast_filter(pstrWFIDrv, true, 0);
2176 return; 2101 return;
2177 } 2102 }
2178 2103
2179 /* Store all of the multicast addresses in the hardware filter */ 2104 /* Store all of the multicast addresses in the hardware filter */
2180 netdev_for_each_mc_addr(ha, dev) 2105 netdev_for_each_mc_addr(ha, dev)
2181 { 2106 {
2182 WILC_memcpy(gau8MulticastMacAddrList[i], ha->addr, ETH_ALEN); 2107 memcpy(gau8MulticastMacAddrList[i], ha->addr, ETH_ALEN);
2183 PRINT_D(INIT_DBG, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i, 2108 PRINT_D(INIT_DBG, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i,
2184 gau8MulticastMacAddrList[i][0], gau8MulticastMacAddrList[i][1], gau8MulticastMacAddrList[i][2], gau8MulticastMacAddrList[i][3], gau8MulticastMacAddrList[i][4], gau8MulticastMacAddrList[i][5]); 2109 gau8MulticastMacAddrList[i][0], gau8MulticastMacAddrList[i][1], gau8MulticastMacAddrList[i][2], gau8MulticastMacAddrList[i][3], gau8MulticastMacAddrList[i][4], gau8MulticastMacAddrList[i][5]);
2185 i++; 2110 i++;
2186 } 2111 }
2187 2112
2188 host_int_setup_multicast_filter((WILC_WFIDrvHandle)pstrWFIDrv, true, (dev->mc.count)); 2113 host_int_setup_multicast_filter(pstrWFIDrv, true, (dev->mc.count));
2189 2114
2190 return; 2115 return;
2191 2116
@@ -2195,11 +2120,10 @@ static void linux_wlan_tx_complete(void *priv, int status)
2195{ 2120{
2196 2121
2197 struct tx_complete_data *pv_data = (struct tx_complete_data *)priv; 2122 struct tx_complete_data *pv_data = (struct tx_complete_data *)priv;
2198 if (status == 1) { 2123 if (status == 1)
2199 PRINT_D(TX_DBG, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb); 2124 PRINT_D(TX_DBG, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
2200 } else { 2125 else
2201 PRINT_D(TX_DBG, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb); 2126 PRINT_D(TX_DBG, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
2202 }
2203 /* Free the SK Buffer, its work is done */ 2127 /* Free the SK Buffer, its work is done */
2204 dev_kfree_skb(pv_data->skb); 2128 dev_kfree_skb(pv_data->skb);
2205 linux_wlan_free(pv_data); 2129 linux_wlan_free(pv_data);
@@ -2215,7 +2139,7 @@ int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
2215 struct ethhdr *eth_h; 2139 struct ethhdr *eth_h;
2216 nic = netdev_priv(ndev); 2140 nic = netdev_priv(ndev);
2217 2141
2218 PRINT_D(INT_DBG, "\n========\n IntUH: %d - IntBH: %d - IntCld: %d \n========\n", int_rcvdU, int_rcvdB, int_clrd); 2142 PRINT_D(INT_DBG, "\n========\n IntUH: %d - IntBH: %d - IntCld: %d\n========\n", int_rcvdU, int_rcvdB, int_clrd);
2219 PRINT_D(TX_DBG, "Sending packet just received from TCP/IP\n"); 2143 PRINT_D(TX_DBG, "Sending packet just received from TCP/IP\n");
2220 2144
2221 /* Stop the network interface queue */ 2145 /* Stop the network interface queue */
@@ -2237,18 +2161,16 @@ int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
2237 tx_data->skb = skb; 2161 tx_data->skb = skb;
2238 2162
2239 eth_h = (struct ethhdr *)(skb->data); 2163 eth_h = (struct ethhdr *)(skb->data);
2240 if (eth_h->h_proto == 0x8e88) { 2164 if (eth_h->h_proto == 0x8e88)
2241 PRINT_D(INIT_DBG, "EAPOL transmitted\n"); 2165 PRINT_D(INIT_DBG, "EAPOL transmitted\n");
2242 }
2243 2166
2244 /*get source and dest ip addresses*/ 2167 /*get source and dest ip addresses*/
2245 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr)); 2168 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
2246 2169
2247 pu8UdpBuffer = (char *)ih + sizeof(struct iphdr); 2170 pu8UdpBuffer = (char *)ih + sizeof(struct iphdr);
2248 if ((pu8UdpBuffer[1] == 68 && pu8UdpBuffer[3] == 67) || (pu8UdpBuffer[1] == 67 && pu8UdpBuffer[3] == 68)) { 2171 if ((pu8UdpBuffer[1] == 68 && pu8UdpBuffer[3] == 67) || (pu8UdpBuffer[1] == 67 && pu8UdpBuffer[3] == 68))
2249 PRINT_D(GENERIC_DBG, "DHCP Message transmitted, type:%x %x %x\n", pu8UdpBuffer[248], pu8UdpBuffer[249], pu8UdpBuffer[250]); 2172 PRINT_D(GENERIC_DBG, "DHCP Message transmitted, type:%x %x %x\n", pu8UdpBuffer[248], pu8UdpBuffer[249], pu8UdpBuffer[250]);
2250 2173
2251 }
2252 PRINT_D(TX_DBG, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data->size, tx_data->buff, tx_data->skb); 2174 PRINT_D(TX_DBG, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data->size, tx_data->buff, tx_data->skb);
2253 2175
2254 /* Send packet to MAC HW - for now the tx_complete function will be just status 2176 /* Send packet to MAC HW - for now the tx_complete function will be just status
@@ -2269,7 +2191,6 @@ int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
2269 QueueCount = WILC_Xmit_data((void *)tx_data, HOST_TO_WLAN); 2191 QueueCount = WILC_Xmit_data((void *)tx_data, HOST_TO_WLAN);
2270 #endif /* WILC_FULLY_HOSTING_AP */ 2192 #endif /* WILC_FULLY_HOSTING_AP */
2271 2193
2272
2273 if (QueueCount > FLOW_CONTROL_UPPER_THRESHOLD) { 2194 if (QueueCount > FLOW_CONTROL_UPPER_THRESHOLD) {
2274 netif_stop_queue(g_linux_wlan->strInterfaceInfo[0].wilc_netdev); 2195 netif_stop_queue(g_linux_wlan->strInterfaceInfo[0].wilc_netdev);
2275 netif_stop_queue(g_linux_wlan->strInterfaceInfo[1].wilc_netdev); 2196 netif_stop_queue(g_linux_wlan->strInterfaceInfo[1].wilc_netdev);
@@ -2278,7 +2199,6 @@ int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
2278 return 0; 2199 return 0;
2279} 2200}
2280 2201
2281
2282int mac_close(struct net_device *ndev) 2202int mac_close(struct net_device *ndev)
2283{ 2203{
2284 struct WILC_WFI_priv *priv; 2204 struct WILC_WFI_priv *priv;
@@ -2301,8 +2221,6 @@ int mac_close(struct net_device *ndev)
2301 2221
2302 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv; 2222 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
2303 2223
2304
2305
2306 PRINT_D(GENERIC_DBG, "Mac close\n"); 2224 PRINT_D(GENERIC_DBG, "Mac close\n");
2307 2225
2308 if (g_linux_wlan == NULL) { 2226 if (g_linux_wlan == NULL) {
@@ -2348,7 +2266,6 @@ int mac_close(struct net_device *ndev)
2348 return 0; 2266 return 0;
2349} 2267}
2350 2268
2351
2352int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) 2269int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
2353{ 2270{
2354 2271
@@ -2359,8 +2276,6 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
2359 struct WILC_WFI_priv *priv; 2276 struct WILC_WFI_priv *priv;
2360 s32 s32Error = WILC_SUCCESS; 2277 s32 s32Error = WILC_SUCCESS;
2361 2278
2362
2363
2364 /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */ 2279 /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */
2365 #ifdef USE_WIRELESS 2280 #ifdef USE_WIRELESS
2366 nic = netdev_priv(ndev); 2281 nic = netdev_priv(ndev);
@@ -2422,9 +2337,7 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
2422 2337
2423done: 2338done:
2424 2339
2425 if (buff != NULL) { 2340 kfree(buff);
2426 kfree(buff);
2427 }
2428 2341
2429 return s32Error; 2342 return s32Error;
2430} 2343}
@@ -2455,7 +2368,6 @@ void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset)
2455 frame_len = size; 2368 frame_len = size;
2456 buff_to_send = buff; 2369 buff_to_send = buff;
2457 2370
2458
2459 /* Need to send the packet up to the host, allocate a skb buffer */ 2371 /* Need to send the packet up to the host, allocate a skb buffer */
2460 skb = dev_alloc_skb(frame_len); 2372 skb = dev_alloc_skb(frame_len);
2461 if (skb == NULL) { 2373 if (skb == NULL) {
@@ -2465,14 +2377,12 @@ void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset)
2465 2377
2466 skb_reserve(skb, (unsigned int)skb->data & 0x3); 2378 skb_reserve(skb, (unsigned int)skb->data & 0x3);
2467 2379
2468 if (g_linux_wlan == NULL || wilc_netdev == NULL) { 2380 if (g_linux_wlan == NULL || wilc_netdev == NULL)
2469 PRINT_ER("wilc_netdev in g_linux_wlan is NULL"); 2381 PRINT_ER("wilc_netdev in g_linux_wlan is NULL");
2470 }
2471 skb->dev = wilc_netdev; 2382 skb->dev = wilc_netdev;
2472 2383
2473 if (skb->dev == NULL) { 2384 if (skb->dev == NULL)
2474 PRINT_ER("skb->dev is NULL\n"); 2385 PRINT_ER("skb->dev is NULL\n");
2475 }
2476 2386
2477 /* 2387 /*
2478 * for(i=0;i<40;i++) 2388 * for(i=0;i<40;i++)
@@ -2502,9 +2412,8 @@ void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset)
2502 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr)); 2412 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
2503 2413
2504 pu8UdpBuffer = (char *)ih + sizeof(struct iphdr); 2414 pu8UdpBuffer = (char *)ih + sizeof(struct iphdr);
2505 if (buff_to_send[35] == 67 && buff_to_send[37] == 68) { 2415 if (buff_to_send[35] == 67 && buff_to_send[37] == 68)
2506 PRINT_D(RX_DBG, "DHCP Message received\n"); 2416 PRINT_D(RX_DBG, "DHCP Message received\n");
2507 }
2508 if (buff_to_send[12] == 0x88 && buff_to_send[13] == 0x8e) 2417 if (buff_to_send[12] == 0x88 && buff_to_send[13] == 0x8e)
2509 PRINT_D(GENERIC_DBG, "eapol received\n"); 2418 PRINT_D(GENERIC_DBG, "eapol received\n");
2510 #endif 2419 #endif
@@ -2516,9 +2425,8 @@ void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset)
2516 PRINT_D(RX_DBG, "netif_rx ret value is: %d\n", stats); 2425 PRINT_D(RX_DBG, "netif_rx ret value is: %d\n", stats);
2517 } 2426 }
2518 #ifndef TCP_ENHANCEMENTS 2427 #ifndef TCP_ENHANCEMENTS
2519 else { 2428 else
2520 PRINT_ER("Discard sending packet with len = %d\n", size); 2429 PRINT_ER("Discard sending packet with len = %d\n", size);
2521 }
2522 #endif 2430 #endif
2523} 2431}
2524 2432
@@ -2541,9 +2449,8 @@ void WILC_WFI_mgmt_rx(uint8_t *buff, uint32_t size)
2541 #ifdef WILC_P2P 2449 #ifdef WILC_P2P
2542 nic = netdev_priv(g_linux_wlan->strInterfaceInfo[1].wilc_netdev); /* p2p0 */ 2450 nic = netdev_priv(g_linux_wlan->strInterfaceInfo[1].wilc_netdev); /* p2p0 */
2543 if ((buff[0] == nic->g_struct_frame_reg[0].frame_type && nic->g_struct_frame_reg[0].reg) || 2451 if ((buff[0] == nic->g_struct_frame_reg[0].frame_type && nic->g_struct_frame_reg[0].reg) ||
2544 (buff[0] == nic->g_struct_frame_reg[1].frame_type && nic->g_struct_frame_reg[1].reg)) { 2452 (buff[0] == nic->g_struct_frame_reg[1].frame_type && nic->g_struct_frame_reg[1].reg))
2545 WILC_WFI_p2p_rx(g_linux_wlan->strInterfaceInfo[1].wilc_netdev, buff, size); 2453 WILC_WFI_p2p_rx(g_linux_wlan->strInterfaceInfo[1].wilc_netdev, buff, size);
2546 }
2547 #endif 2454 #endif
2548} 2455}
2549 2456
@@ -2557,7 +2464,7 @@ int wilc_netdev_init(void)
2557 linux_wlan_init_lock("close_exit_sync", &close_exit_sync, 0); 2464 linux_wlan_init_lock("close_exit_sync", &close_exit_sync, 0);
2558 2465
2559 /*create the common structure*/ 2466 /*create the common structure*/
2560 g_linux_wlan = (linux_wlan_t *)WILC_MALLOC(sizeof(linux_wlan_t)); 2467 g_linux_wlan = WILC_MALLOC(sizeof(linux_wlan_t));
2561 memset(g_linux_wlan, 0, sizeof(linux_wlan_t)); 2468 memset(g_linux_wlan, 0, sizeof(linux_wlan_t));
2562 2469
2563 /*Reset interrupt count debug*/ 2470 /*Reset interrupt count debug*/
@@ -2625,7 +2532,6 @@ int wilc_netdev_init(void)
2625 } 2532 }
2626 #endif 2533 #endif
2627 2534
2628
2629 if (register_netdev(ndev)) { 2535 if (register_netdev(ndev)) {
2630 PRINT_ER("Device couldn't be registered - %s\n", ndev->name); 2536 PRINT_ER("Device couldn't be registered - %s\n", ndev->name);
2631 return -1; /* ERROR */ 2537 return -1; /* ERROR */
@@ -2638,7 +2544,7 @@ int wilc_netdev_init(void)
2638 2544
2639 #ifndef WILC_SDIO 2545 #ifndef WILC_SDIO
2640 if (!linux_spi_init(&g_linux_wlan->wilc_spidev)) { 2546 if (!linux_spi_init(&g_linux_wlan->wilc_spidev)) {
2641 PRINT_ER("Can't initialize SPI \n"); 2547 PRINT_ER("Can't initialize SPI\n");
2642 return -1; /* ERROR */ 2548 return -1; /* ERROR */
2643 } 2549 }
2644 g_linux_wlan->wilc_spidev = wilc_spi_dev; 2550 g_linux_wlan->wilc_spidev = wilc_spi_dev;
@@ -2649,13 +2555,10 @@ int wilc_netdev_init(void)
2649 return 0; 2555 return 0;
2650} 2556}
2651 2557
2652
2653/*The 1st function called after module inserted*/ 2558/*The 1st function called after module inserted*/
2654static int __init init_wilc_driver(void) 2559static int __init init_wilc_driver(void)
2655{ 2560{
2656 2561#if defined(WILC_DEBUGFS)
2657
2658#if defined (WILC_DEBUGFS)
2659 if (wilc_debugfs_init() < 0) { 2562 if (wilc_debugfs_init() < 0) {
2660 PRINT_D(GENERIC_DBG, "fail to create debugfs for wilc driver\n"); 2563 PRINT_D(GENERIC_DBG, "fail to create debugfs for wilc driver\n");
2661 return -1; 2564 return -1;
@@ -2674,17 +2577,15 @@ static int __init init_wilc_driver(void)
2674 int ret; 2577 int ret;
2675 2578
2676 ret = sdio_register_driver(&wilc_bus); 2579 ret = sdio_register_driver(&wilc_bus);
2677 if (ret < 0) { 2580 if (ret < 0)
2678 PRINT_D(INIT_DBG, "init_wilc_driver: Failed register sdio driver\n"); 2581 PRINT_D(INIT_DBG, "init_wilc_driver: Failed register sdio driver\n");
2679 }
2680 2582
2681 return ret; 2583 return ret;
2682 } 2584 }
2683#else 2585#else
2684 PRINT_D(INIT_DBG, "Initializing netdev\n"); 2586 PRINT_D(INIT_DBG, "Initializing netdev\n");
2685 if (wilc_netdev_init()) { 2587 if (wilc_netdev_init())
2686 PRINT_ER("Couldn't initialize netdev\n"); 2588 PRINT_ER("Couldn't initialize netdev\n");
2687 }
2688 return 0; 2589 return 0;
2689#endif 2590#endif
2690} 2591}
@@ -2702,18 +2603,15 @@ static void __exit exit_wilc_driver(void)
2702 unregister_inetaddr_notifier(&g_dev_notifier); 2603 unregister_inetaddr_notifier(&g_dev_notifier);
2703 #endif 2604 #endif
2704 2605
2705 for (i = 0; i < NUM_CONCURRENT_IFC; i++) { 2606 for (i = 0; i < NUM_CONCURRENT_IFC; i++)
2706 nic[i] = netdev_priv(g_linux_wlan->strInterfaceInfo[i].wilc_netdev); 2607 nic[i] = netdev_priv(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2707 }
2708 } 2608 }
2709 2609
2710
2711 if ((g_linux_wlan != NULL) && g_linux_wlan->wilc_firmware != NULL) { 2610 if ((g_linux_wlan != NULL) && g_linux_wlan->wilc_firmware != NULL) {
2712 release_firmware(g_linux_wlan->wilc_firmware); 2611 release_firmware(g_linux_wlan->wilc_firmware);
2713 g_linux_wlan->wilc_firmware = NULL; 2612 g_linux_wlan->wilc_firmware = NULL;
2714 } 2613 }
2715 2614
2716
2717 if ((g_linux_wlan != NULL) && (((g_linux_wlan->strInterfaceInfo[0].wilc_netdev) != NULL) 2615 if ((g_linux_wlan != NULL) && (((g_linux_wlan->strInterfaceInfo[0].wilc_netdev) != NULL)
2718 || ((g_linux_wlan->strInterfaceInfo[1].wilc_netdev) != NULL))) { 2616 || ((g_linux_wlan->strInterfaceInfo[1].wilc_netdev) != NULL))) {
2719 PRINT_D(INIT_DBG, "Waiting for mac_close ....\n"); 2617 PRINT_D(INIT_DBG, "Waiting for mac_close ....\n");
@@ -2723,17 +2621,15 @@ static void __exit exit_wilc_driver(void)
2723 else 2621 else
2724 PRINT_D(INIT_DBG, "mac_closed\n"); 2622 PRINT_D(INIT_DBG, "mac_closed\n");
2725 2623
2726
2727 for (i = 0; i < NUM_CONCURRENT_IFC; i++) { 2624 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2728 /* close all opened interfaces */ 2625 /* close all opened interfaces */
2729 if (g_linux_wlan->strInterfaceInfo[i].wilc_netdev != NULL) { 2626 if (g_linux_wlan->strInterfaceInfo[i].wilc_netdev != NULL) {
2730 if (nic[i]->mac_opened) { 2627 if (nic[i]->mac_opened)
2731 mac_close(g_linux_wlan->strInterfaceInfo[i].wilc_netdev); 2628 mac_close(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2732 }
2733 } 2629 }
2734 } 2630 }
2735 for (i = 0; i < NUM_CONCURRENT_IFC; i++) { 2631 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2736 PRINT_D(INIT_DBG, "Unregistering netdev %p \n", g_linux_wlan->strInterfaceInfo[i].wilc_netdev); 2632 PRINT_D(INIT_DBG, "Unregistering netdev %p\n", g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2737 unregister_netdev(g_linux_wlan->strInterfaceInfo[i].wilc_netdev); 2633 unregister_netdev(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2738 #ifdef USE_WIRELESS 2634 #ifdef USE_WIRELESS
2739 PRINT_D(INIT_DBG, "Freeing Wiphy...\n"); 2635 PRINT_D(INIT_DBG, "Freeing Wiphy...\n");
@@ -2744,7 +2640,6 @@ static void __exit exit_wilc_driver(void)
2744 } 2640 }
2745 } 2641 }
2746 2642
2747
2748#ifdef USE_WIRELESS 2643#ifdef USE_WIRELESS
2749#ifdef WILC_AP_EXTERNAL_MLME 2644#ifdef WILC_AP_EXTERNAL_MLME
2750 /* Bug 4600 : WILC_WFI_deinit_mon_interface was already called at mac_close */ 2645 /* Bug 4600 : WILC_WFI_deinit_mon_interface was already called at mac_close */
@@ -2764,12 +2659,12 @@ static void __exit exit_wilc_driver(void)
2764 2659
2765 linux_wlan_deinit_lock(&close_exit_sync); 2660 linux_wlan_deinit_lock(&close_exit_sync);
2766 if (g_linux_wlan != NULL) { 2661 if (g_linux_wlan != NULL) {
2767 WILC_FREE(g_linux_wlan); 2662 kfree(g_linux_wlan);
2768 g_linux_wlan = NULL; 2663 g_linux_wlan = NULL;
2769 } 2664 }
2770 printk("Module_exit Done.\n"); 2665 printk("Module_exit Done.\n");
2771 2666
2772#if defined (WILC_DEBUGFS) 2667#if defined(WILC_DEBUGFS)
2773 wilc_debugfs_remove(); 2668 wilc_debugfs_remove();
2774#endif 2669#endif
2775 2670
@@ -2780,4 +2675,3 @@ static void __exit exit_wilc_driver(void)
2780module_exit(exit_wilc_driver); 2675module_exit(exit_wilc_driver);
2781 2676
2782MODULE_LICENSE("GPL"); 2677MODULE_LICENSE("GPL");
2783#endif
diff --git a/drivers/staging/wilc1000/linux_wlan_common.h b/drivers/staging/wilc1000/linux_wlan_common.h
index 2476bfda1b46..e6ebf3e89129 100644
--- a/drivers/staging/wilc1000/linux_wlan_common.h
+++ b/drivers/staging/wilc1000/linux_wlan_common.h
@@ -39,8 +39,8 @@ enum debug_region {
39#define FIRM_DBG (1 << Firmware_debug) 39#define FIRM_DBG (1 << Firmware_debug)
40 40
41#if defined (WILC_DEBUGFS) 41#if defined (WILC_DEBUGFS)
42extern int wilc_debugfs_init(void); 42int wilc_debugfs_init(void);
43extern void wilc_debugfs_remove(void); 43void wilc_debugfs_remove(void);
44 44
45extern atomic_t REGION; 45extern atomic_t REGION;
46extern atomic_t DEBUG_LEVEL; 46extern atomic_t DEBUG_LEVEL;
diff --git a/drivers/staging/wilc1000/linux_wlan_sdio.c b/drivers/staging/wilc1000/linux_wlan_sdio.c
index 858e3a191bce..37f31f4558b5 100644
--- a/drivers/staging/wilc1000/linux_wlan_sdio.c
+++ b/drivers/staging/wilc1000/linux_wlan_sdio.c
@@ -31,7 +31,6 @@
31struct sdio_func *local_sdio_func; 31struct sdio_func *local_sdio_func;
32extern linux_wlan_t *g_linux_wlan; 32extern linux_wlan_t *g_linux_wlan;
33extern int wilc_netdev_init(void); 33extern int wilc_netdev_init(void);
34extern int sdio_clear_int(void);
35extern void wilc_handle_isr(void); 34extern void wilc_handle_isr(void);
36 35
37static unsigned int sdio_default_speed; 36static unsigned int sdio_default_speed;
diff --git a/drivers/staging/wilc1000/wilc_debugfs.c b/drivers/staging/wilc1000/wilc_debugfs.c
index c328208cda29..ae111862e7a9 100644
--- a/drivers/staging/wilc1000/wilc_debugfs.c
+++ b/drivers/staging/wilc1000/wilc_debugfs.c
@@ -48,38 +48,28 @@ static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf, si
48 return simple_read_from_buffer(userbuf, count, ppos, buf, res); 48 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
49} 49}
50 50
51static ssize_t wilc_debug_level_write(struct file *filp, const char *buf, size_t count, loff_t *ppos) 51static ssize_t wilc_debug_level_write(struct file *filp, const char __user *buf,
52 size_t count, loff_t *ppos)
52{ 53{
53 char buffer[128] = {};
54 int flag = 0; 54 int flag = 0;
55 int ret;
55 56
56 if (count > sizeof(buffer)) 57 ret = kstrtouint_from_user(buf, count, 16, &flag);
57 return -EINVAL; 58 if (ret)
58 59 return ret;
59 if (copy_from_user(buffer, buf, count)) {
60 return -EFAULT;
61 }
62
63 flag = buffer[0] - '0';
64
65 if (flag > 0) {
66 flag = DEBUG | ERR;
67 } else if (flag < 0) {
68 flag = 100;
69 }
70 60
71 if (flag > DBG_LEVEL_ALL) { 61 if (flag > DBG_LEVEL_ALL) {
72 printk("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n", __func__, flag, atomic_read(&DEBUG_LEVEL)); 62 printk("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n", __func__, flag, atomic_read(&DEBUG_LEVEL));
73 return -EFAULT; 63 return -EINVAL;
74 } 64 }
75 65
76 atomic_set(&DEBUG_LEVEL, (int)flag); 66 atomic_set(&DEBUG_LEVEL, (int)flag);
77 67
78 if (flag == 0) { 68 if (flag == 0)
79 printk("Debug-level disabled\n"); 69 printk("Debug-level disabled\n");
80 } else { 70 else
81 printk("Debug-level enabled\n"); 71 printk("Debug-level enabled\n");
82 } 72
83 return count; 73 return count;
84} 74}
85 75
diff --git a/drivers/staging/wilc1000/wilc_exported_buf.c b/drivers/staging/wilc1000/wilc_exported_buf.c
index 529457816f65..c3f6a0a1c9ad 100644
--- a/drivers/staging/wilc1000/wilc_exported_buf.c
+++ b/drivers/staging/wilc1000/wilc_exported_buf.c
@@ -8,9 +8,6 @@
8#define LINUX_TX_SIZE (64 * 1024) 8#define LINUX_TX_SIZE (64 * 1024)
9#define WILC1000_FW_SIZE (4 * 1024) 9#define WILC1000_FW_SIZE (4 * 1024)
10 10
11#define DECLARE_WILC_BUFFER(name) \
12 void *exported_ ## name = NULL;
13
14#define MALLOC_WILC_BUFFER(name, size) \ 11#define MALLOC_WILC_BUFFER(name, size) \
15 exported_ ## name = kmalloc(size, GFP_KERNEL); \ 12 exported_ ## name = kmalloc(size, GFP_KERNEL); \
16 if (!exported_ ## name) { \ 13 if (!exported_ ## name) { \
@@ -24,9 +21,9 @@
24/* 21/*
25 * Add necessary buffer pointers 22 * Add necessary buffer pointers
26 */ 23 */
27DECLARE_WILC_BUFFER(g_tx_buf) 24void *exported_g_tx_buf;
28DECLARE_WILC_BUFFER(g_rx_buf) 25void *exported_g_rx_buf;
29DECLARE_WILC_BUFFER(g_fw_buf) 26void *exported_g_fw_buf;
30 27
31void *get_tx_buffer(void) 28void *get_tx_buffer(void)
32{ 29{
@@ -65,12 +62,10 @@ static void __exit wilc_module_deinit(void)
65 FREE_WILC_BUFFER(g_tx_buf) 62 FREE_WILC_BUFFER(g_tx_buf)
66 FREE_WILC_BUFFER(g_rx_buf) 63 FREE_WILC_BUFFER(g_rx_buf)
67 FREE_WILC_BUFFER(g_fw_buf) 64 FREE_WILC_BUFFER(g_fw_buf)
68
69 return;
70} 65}
71 66
72MODULE_LICENSE("Dual BSD/GPL"); 67MODULE_LICENSE("Dual BSD/GPL");
73MODULE_AUTHOR("Tony Cho"); 68MODULE_AUTHOR("Tony Cho");
74MODULE_DESCRIPTION("WILC1xxx Memory Manager"); 69MODULE_DESCRIPTION("WILC1xxx Memory Manager");
75pure_initcall(wilc_module_init); 70pure_initcall(wilc_module_init);
76module_exit(wilc_module_deinit); \ No newline at end of file 71module_exit(wilc_module_deinit);
diff --git a/drivers/staging/wilc1000/wilc_log.h b/drivers/staging/wilc1000/wilc_log.h
deleted file mode 100644
index 2269ebdec129..000000000000
--- a/drivers/staging/wilc1000/wilc_log.h
+++ /dev/null
@@ -1,47 +0,0 @@
1#ifndef __WILC_LOG_H__
2#define __WILC_LOG_H__
3
4/* Errors will always get printed */
5#define WILC_ERROR(...) do { WILC_PRINTF("(ERR)(%s:%d) ", __WILC_FUNCTION__, __WILC_LINE__); \
6 WILC_PRINTF(__VA_ARGS__); \
7 } while (0)
8
9/* Wraning only printed if verbosity is 1 or more */
10#if (WILC_LOG_VERBOSITY_LEVEL > 0)
11#define WILC_WARN(...) do { WILC_PRINTF("(WRN)"); \
12 WILC_PRINTF(__VA_ARGS__); \
13 } while (0)
14#else
15#define WILC_WARN(...) (0)
16#endif
17
18/* Info only printed if verbosity is 2 or more */
19#if (WILC_LOG_VERBOSITY_LEVEL > 1)
20#define WILC_INFO(...) do { WILC_PRINTF("(INF)"); \
21 WILC_PRINTF(__VA_ARGS__); \
22 } while (0)
23#else
24#define WILC_INFO(...) (0)
25#endif
26
27/* Debug is only printed if verbosity is 3 or more */
28#if (WILC_LOG_VERBOSITY_LEVEL > 2)
29#define WILC_DBG(...) do { WILC_PRINTF("(DBG)(%s:%d) ", __WILC_FUNCTION__, __WILC_LINE__); \
30 WILC_PRINTF(__VA_ARGS__); \
31 } while (0)
32
33#else
34#define WILC_DBG(...) (0)
35#endif
36
37/* Function In/Out is only printed if verbosity is 4 or more */
38#if (WILC_LOG_VERBOSITY_LEVEL > 3)
39#define WILC_FN_IN do { WILC_PRINTF("(FIN) (%s:%d) \n", __WILC_FUNCTION__, __WILC_LINE__); } while (0)
40#define WILC_FN_OUT(ret) do { WILC_PRINTF("(FOUT) (%s:%d) %d.\n", __WILC_FUNCTION__, __WILC_LINE__, (ret)); } while (0)
41#else
42#define WILC_FN_IN (0)
43#define WILC_FN_OUT(ret) (0)
44#endif
45
46
47#endif \ No newline at end of file
diff --git a/drivers/staging/wilc1000/wilc_memory.c b/drivers/staging/wilc1000/wilc_memory.c
index c70707fefb66..e90a95705a7d 100644
--- a/drivers/staging/wilc1000/wilc_memory.c
+++ b/drivers/staging/wilc1000/wilc_memory.c
@@ -9,50 +9,8 @@
9void *WILC_MemoryAlloc(u32 u32Size, tstrWILC_MemoryAttrs *strAttrs, 9void *WILC_MemoryAlloc(u32 u32Size, tstrWILC_MemoryAttrs *strAttrs,
10 char *pcFileName, u32 u32LineNo) 10 char *pcFileName, u32 u32LineNo)
11{ 11{
12 if (u32Size > 0) { 12 if (u32Size > 0)
13 return kmalloc(u32Size, GFP_ATOMIC); 13 return kmalloc(u32Size, GFP_ATOMIC);
14 } else { 14 else
15 return NULL; 15 return NULL;
16 }
17}
18
19/*!
20 * @author syounan
21 * @date 18 Aug 2010
22 * @version 1.0
23 */
24void *WILC_MemoryCalloc(u32 u32Size, tstrWILC_MemoryAttrs *strAttrs,
25 char *pcFileName, u32 u32LineNo)
26{
27 return kcalloc(u32Size, 1, GFP_KERNEL);
28}
29
30/*!
31 * @author syounan
32 * @date 18 Aug 2010
33 * @version 1.0
34 */
35void *WILC_MemoryRealloc(void *pvOldBlock, u32 u32NewSize,
36 tstrWILC_MemoryAttrs *strAttrs, char *pcFileName, u32 u32LineNo)
37{
38 if (u32NewSize == 0) {
39 kfree(pvOldBlock);
40 return NULL;
41 } else if (pvOldBlock == NULL) {
42 return kmalloc(u32NewSize, GFP_KERNEL);
43 } else {
44 return krealloc(pvOldBlock, u32NewSize, GFP_KERNEL);
45 }
46
47}
48
49/*!
50 * @author syounan
51 * @date 18 Aug 2010
52 * @version 1.0
53 */
54void WILC_MemoryFree(const void *pvBlock, tstrWILC_MemoryAttrs *strAttrs,
55 char *pcFileName, u32 u32LineNo)
56{
57 kfree(pvBlock);
58} 16}
diff --git a/drivers/staging/wilc1000/wilc_memory.h b/drivers/staging/wilc1000/wilc_memory.h
index 372d7053e873..f19cec11a69a 100644
--- a/drivers/staging/wilc1000/wilc_memory.h
+++ b/drivers/staging/wilc1000/wilc_memory.h
@@ -38,8 +38,6 @@ typedef struct {
38 * @sa sttrWILC_MemoryAttrs 38 * @sa sttrWILC_MemoryAttrs
39 * @sa WILC_MALLOC 39 * @sa WILC_MALLOC
40 * @sa WILC_MALLOC_EX 40 * @sa WILC_MALLOC_EX
41 * @sa WILC_NEW
42 * @sa WILC_NEW_EX
43 * @author syounan 41 * @author syounan
44 * @date 16 Aug 2010 42 * @date 16 Aug 2010
45 * @version 1.0 43 * @version 1.0
@@ -48,140 +46,12 @@ void *WILC_MemoryAlloc(u32 u32Size, tstrWILC_MemoryAttrs *strAttrs,
48 char *pcFileName, u32 u32LineNo); 46 char *pcFileName, u32 u32LineNo);
49 47
50/*! 48/*!
51 * @brief Allocates a given size of bytes and zero filling it
52 * @param[in] u32Size size of memory in bytes to be allocated
53 * @param[in] strAttrs Optional attributes, NULL for default
54 * if not NULL, pAllocationPool should point to the pool to use for
55 * this allocation. if NULL memory will be allocated directly from
56 * the system
57 * @param[in] pcFileName file name of the calling code for debugging
58 * @param[in] u32LineNo line number of the calling code for debugging
59 * @return The new allocated block, NULL if allocation fails
60 * @note It is recommended to use of of the wrapper macros instead of
61 * calling this function directly
62 * @sa sttrWILC_MemoryAttrs
63 * @sa WILC_CALLOC
64 * @sa WILC_CALLOC_EX
65 * @sa WILC_NEW_0
66 * @sa WILC_NEW_0_EX
67 * @author syounan
68 * @date 16 Aug 2010
69 * @version 1.0
70 */
71void *WILC_MemoryCalloc(u32 u32Size, tstrWILC_MemoryAttrs *strAttrs,
72 char *pcFileName, u32 u32LineNo);
73
74/*!
75 * @brief Reallocates a given block to a new size
76 * @param[in] pvOldBlock the old memory block, if NULL then this function
77 * behaves as a new allocation function
78 * @param[in] u32NewSize size of the new memory block in bytes, if zero then
79 * this function behaves as a free function
80 * @param[in] strAttrs Optional attributes, NULL for default
81 * if pAllocationPool!=NULL and pvOldBlock==NULL, pAllocationPool
82 * should point to the pool to use for this allocation.
83 * if pAllocationPool==NULL and pvOldBlock==NULL memory will be
84 * allocated directly from the system
85 * if and pvOldBlock!=NULL, pAllocationPool will not be inspected
86 * and reallocation is done from the same pool as the original block
87 * @param[in] pcFileName file name of the calling code for debugging
88 * @param[in] u32LineNo line number of the calling code for debugging
89 * @return The new allocated block, possibly same as pvOldBlock
90 * @note It is recommended to use of of the wrapper macros instead of
91 * calling this function directly
92 * @sa sttrWILC_MemoryAttrs
93 * @sa WILC_REALLOC
94 * @sa WILC_REALLOC_EX
95 * @author syounan
96 * @date 16 Aug 2010
97 * @version 1.0
98 */
99void *WILC_MemoryRealloc(void *pvOldBlock, u32 u32NewSize,
100 tstrWILC_MemoryAttrs *strAttrs, char *pcFileName, u32 u32LineNo);
101
102/*!
103 * @brief Frees given block
104 * @param[in] pvBlock the memory block to be freed
105 * @param[in] strAttrs Optional attributes, NULL for default
106 * @param[in] pcFileName file name of the calling code for debugging
107 * @param[in] u32LineNo line number of the calling code for debugging
108 * @note It is recommended to use of of the wrapper macros instead of
109 * calling this function directly
110 * @sa sttrWILC_MemoryAttrs
111 * @sa WILC_FREE
112 * @sa WILC_FREE_EX
113 * @sa WILC_FREE_SET_NULL
114 * @sa WILC_FREE_IF_TRUE
115 * @author syounan
116 * @date 16 Aug 2010
117 * @version 1.0
118 */
119void WILC_MemoryFree(const void *pvBlock, tstrWILC_MemoryAttrs *strAttrs,
120 char *pcFileName, u32 u32LineNo);
121
122/*!
123 * @brief standrad malloc wrapper with custom attributes 49 * @brief standrad malloc wrapper with custom attributes
124 */ 50 */
125 #define WILC_MALLOC_EX(__size__, __attrs__) \ 51 #define WILC_MALLOC_EX(__size__, __attrs__) \
126 (WILC_MemoryAlloc( \ 52 (WILC_MemoryAlloc( \
127 (__size__), __attrs__, NULL, 0)) 53 (__size__), __attrs__, NULL, 0))
128 54
129/*!
130 * @brief standrad calloc wrapper with custom attributes
131 */
132 #define WILC_CALLOC_EX(__size__, __attrs__) \
133 (WILC_MemoryCalloc( \
134 (__size__), __attrs__, NULL, 0))
135
136/*!
137 * @brief standrad realloc wrapper with custom attributes
138 */
139 #define WILC_REALLOC_EX(__ptr__, __new_size__, __attrs__) \
140 (WILC_MemoryRealloc( \
141 (__ptr__), (__new_size__), __attrs__, NULL, 0))
142/*!
143 * @brief standrad free wrapper with custom attributes
144 */
145 #define WILC_FREE_EX(__ptr__, __attrs__) \
146 (WILC_MemoryFree( \
147 (__ptr__), __attrs__, NULL, 0))
148
149/*!
150 * @brief Allocates a block (with custom attributes) of given type and number of
151 * elements
152 */
153#define WILC_NEW_EX(__struct_type__, __n_structs__, __attrs__) \
154 ((__struct_type__ *)WILC_MALLOC_EX( \
155 sizeof(__struct_type__) * (u32)(__n_structs__), __attrs__))
156
157/*!
158 * @brief Allocates a block (with custom attributes) of given type and number of
159 * elements and Zero-fills it
160 */
161#define WILC_NEW_0_EX(__struct_type__, __n_structs__, __attrs__) \
162 ((__struct_type__ *)WILC_CALLOC_EX( \
163 sizeof(__struct_type__) * (u32)(__n_structs__), __attrs__))
164
165/*!
166 * @brief Frees a block (with custom attributes), also setting the original pointer
167 * to NULL
168 */
169#define WILC_FREE_SET_NULL_EX(__ptr__, __attrs__) do { \
170 if (__ptr__ != NULL) { \
171 WILC_FREE_EX(__ptr__, __attrs__); \
172 __ptr__ = NULL; \
173 } \
174} while (0)
175
176/*!
177 * @brief Frees a block (with custom attributes) if the pointer expression evaluates
178 * to true
179 */
180#define WILC_FREE_IF_TRUE_EX(__ptr__, __attrs__) do { \
181 if (__ptr__ != NULL) { \
182 WILC_FREE_EX(__ptr__, __attrs__); \
183 } \
184} while (0)
185 55
186/*! 56/*!
187 * @brief standrad malloc wrapper with default attributes 57 * @brief standrad malloc wrapper with default attributes
@@ -189,51 +59,8 @@ void WILC_MemoryFree(const void *pvBlock, tstrWILC_MemoryAttrs *strAttrs,
189#define WILC_MALLOC(__size__) \ 59#define WILC_MALLOC(__size__) \
190 WILC_MALLOC_EX(__size__, NULL) 60 WILC_MALLOC_EX(__size__, NULL)
191 61
192/*!
193 * @brief standrad calloc wrapper with default attributes
194 */
195#define WILC_CALLOC(__size__) \
196 WILC_CALLOC_EX(__size__, NULL)
197
198/*!
199 * @brief standrad realloc wrapper with default attributes
200 */
201#define WILC_REALLOC(__ptr__, __new_size__) \
202 WILC_REALLOC_EX(__ptr__, __new_size__, NULL)
203 62
204/*!
205 * @brief standrad free wrapper with default attributes
206 */
207#define WILC_FREE(__ptr__) \
208 WILC_FREE_EX(__ptr__, NULL)
209 63
210/*!
211 * @brief Allocates a block (with default attributes) of given type and number of
212 * elements
213 */
214#define WILC_NEW(__struct_type__, __n_structs__) \
215 WILC_NEW_EX(__struct_type__, __n_structs__, NULL)
216
217/*!
218 * @brief Allocates a block (with default attributes) of given type and number of
219 * elements and Zero-fills it
220 */
221#define WILC_NEW_0(__struct_type__, __n_structs__) \
222 WILC_NEW_O_EX(__struct_type__, __n_structs__, NULL)
223
224/*!
225 * @brief Frees a block (with default attributes), also setting the original pointer
226 * to NULL
227 */
228#define WILC_FREE_SET_NULL(__ptr__) \
229 WILC_FREE_SET_NULL_EX(__ptr__, NULL)
230
231/*!
232 * @brief Frees a block (with default attributes) if the pointer expression evaluates
233 * to true
234 */
235#define WILC_FREE_IF_TRUE(__ptr__) \
236 WILC_FREE_IF_TRUE_EX(__ptr__, NULL)
237 64
238 65
239#endif 66#endif
diff --git a/drivers/staging/wilc1000/wilc_msgqueue.c b/drivers/staging/wilc1000/wilc_msgqueue.c
index 16bcef4b5c00..70e4fa6a07a6 100644
--- a/drivers/staging/wilc1000/wilc_msgqueue.c
+++ b/drivers/staging/wilc1000/wilc_msgqueue.c
@@ -8,8 +8,7 @@
8 * @note copied from FLO glue implementatuion 8 * @note copied from FLO glue implementatuion
9 * @version 1.0 9 * @version 1.0
10 */ 10 */
11WILC_ErrNo WILC_MsgQueueCreate(WILC_MsgQueueHandle *pHandle, 11WILC_ErrNo WILC_MsgQueueCreate(WILC_MsgQueueHandle *pHandle)
12 tstrWILC_MsgQueueAttrs *pstrAttrs)
13{ 12{
14 spin_lock_init(&pHandle->strCriticalSection); 13 spin_lock_init(&pHandle->strCriticalSection);
15 sema_init(&pHandle->hSem, 0); 14 sema_init(&pHandle->hSem, 0);
@@ -25,8 +24,7 @@ WILC_ErrNo WILC_MsgQueueCreate(WILC_MsgQueueHandle *pHandle,
25 * @note copied from FLO glue implementatuion 24 * @note copied from FLO glue implementatuion
26 * @version 1.0 25 * @version 1.0
27 */ 26 */
28WILC_ErrNo WILC_MsgQueueDestroy(WILC_MsgQueueHandle *pHandle, 27WILC_ErrNo WILC_MsgQueueDestroy(WILC_MsgQueueHandle *pHandle)
29 tstrWILC_MsgQueueAttrs *pstrAttrs)
30{ 28{
31 29
32 pHandle->bExiting = true; 30 pHandle->bExiting = true;
@@ -39,7 +37,7 @@ WILC_ErrNo WILC_MsgQueueDestroy(WILC_MsgQueueHandle *pHandle,
39 37
40 while (pHandle->pstrMessageList != NULL) { 38 while (pHandle->pstrMessageList != NULL) {
41 Message *pstrMessge = pHandle->pstrMessageList->pstrNext; 39 Message *pstrMessge = pHandle->pstrMessageList->pstrNext;
42 WILC_FREE(pHandle->pstrMessageList); 40 kfree(pHandle->pstrMessageList);
43 pHandle->pstrMessageList = pstrMessge; 41 pHandle->pstrMessageList = pstrMessge;
44 } 42 }
45 43
@@ -53,8 +51,7 @@ WILC_ErrNo WILC_MsgQueueDestroy(WILC_MsgQueueHandle *pHandle,
53 * @version 1.0 51 * @version 1.0
54 */ 52 */
55WILC_ErrNo WILC_MsgQueueSend(WILC_MsgQueueHandle *pHandle, 53WILC_ErrNo WILC_MsgQueueSend(WILC_MsgQueueHandle *pHandle,
56 const void *pvSendBuffer, u32 u32SendBufferSize, 54 const void *pvSendBuffer, u32 u32SendBufferSize)
57 tstrWILC_MsgQueueAttrs *pstrAttrs)
58{ 55{
59 WILC_ErrNo s32RetStatus = WILC_SUCCESS; 56 WILC_ErrNo s32RetStatus = WILC_SUCCESS;
60 unsigned long flags; 57 unsigned long flags;
@@ -71,13 +68,13 @@ WILC_ErrNo WILC_MsgQueueSend(WILC_MsgQueueHandle *pHandle,
71 spin_lock_irqsave(&pHandle->strCriticalSection, flags); 68 spin_lock_irqsave(&pHandle->strCriticalSection, flags);
72 69
73 /* construct a new message */ 70 /* construct a new message */
74 pstrMessage = WILC_NEW(Message, 1); 71 pstrMessage = kmalloc(sizeof(Message), GFP_ATOMIC);
75 WILC_NULLCHECK(s32RetStatus, pstrMessage); 72 WILC_NULLCHECK(s32RetStatus, pstrMessage);
76 pstrMessage->u32Length = u32SendBufferSize; 73 pstrMessage->u32Length = u32SendBufferSize;
77 pstrMessage->pstrNext = NULL; 74 pstrMessage->pstrNext = NULL;
78 pstrMessage->pvBuffer = WILC_MALLOC(u32SendBufferSize); 75 pstrMessage->pvBuffer = WILC_MALLOC(u32SendBufferSize);
79 WILC_NULLCHECK(s32RetStatus, pstrMessage->pvBuffer); 76 WILC_NULLCHECK(s32RetStatus, pstrMessage->pvBuffer);
80 WILC_memcpy(pstrMessage->pvBuffer, pvSendBuffer, u32SendBufferSize); 77 memcpy(pstrMessage->pvBuffer, pvSendBuffer, u32SendBufferSize);
81 78
82 79
83 /* add it to the message queue */ 80 /* add it to the message queue */
@@ -100,9 +97,9 @@ WILC_ErrNo WILC_MsgQueueSend(WILC_MsgQueueHandle *pHandle,
100 /* error occured, free any allocations */ 97 /* error occured, free any allocations */
101 if (pstrMessage != NULL) { 98 if (pstrMessage != NULL) {
102 if (pstrMessage->pvBuffer != NULL) { 99 if (pstrMessage->pvBuffer != NULL) {
103 WILC_FREE(pstrMessage->pvBuffer); 100 kfree(pstrMessage->pvBuffer);
104 } 101 }
105 WILC_FREE(pstrMessage); 102 kfree(pstrMessage);
106 } 103 }
107 } 104 }
108 105
@@ -119,8 +116,7 @@ WILC_ErrNo WILC_MsgQueueSend(WILC_MsgQueueHandle *pHandle,
119 */ 116 */
120WILC_ErrNo WILC_MsgQueueRecv(WILC_MsgQueueHandle *pHandle, 117WILC_ErrNo WILC_MsgQueueRecv(WILC_MsgQueueHandle *pHandle,
121 void *pvRecvBuffer, u32 u32RecvBufferSize, 118 void *pvRecvBuffer, u32 u32RecvBufferSize,
122 u32 *pu32ReceivedLength, 119 u32 *pu32ReceivedLength)
123 tstrWILC_MsgQueueAttrs *pstrAttrs)
124{ 120{
125 121
126 Message *pstrMessage; 122 Message *pstrMessage;
@@ -170,13 +166,13 @@ WILC_ErrNo WILC_MsgQueueRecv(WILC_MsgQueueHandle *pHandle,
170 166
171 /* consume the message */ 167 /* consume the message */
172 pHandle->u32ReceiversCount--; 168 pHandle->u32ReceiversCount--;
173 WILC_memcpy(pvRecvBuffer, pstrMessage->pvBuffer, pstrMessage->u32Length); 169 memcpy(pvRecvBuffer, pstrMessage->pvBuffer, pstrMessage->u32Length);
174 *pu32ReceivedLength = pstrMessage->u32Length; 170 *pu32ReceivedLength = pstrMessage->u32Length;
175 171
176 pHandle->pstrMessageList = pstrMessage->pstrNext; 172 pHandle->pstrMessageList = pstrMessage->pstrNext;
177 173
178 WILC_FREE(pstrMessage->pvBuffer); 174 kfree(pstrMessage->pvBuffer);
179 WILC_FREE(pstrMessage); 175 kfree(pstrMessage);
180 176
181 spin_unlock_irqrestore(&pHandle->strCriticalSection, flags); 177 spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
182 178
diff --git a/drivers/staging/wilc1000/wilc_msgqueue.h b/drivers/staging/wilc1000/wilc_msgqueue.h
index 35b10019eebd..ef1d2fa20c50 100644
--- a/drivers/staging/wilc1000/wilc_msgqueue.h
+++ b/drivers/staging/wilc1000/wilc_msgqueue.h
@@ -13,20 +13,6 @@
13#include "wilc_platform.h" 13#include "wilc_platform.h"
14#include "wilc_errorsupport.h" 14#include "wilc_errorsupport.h"
15#include "wilc_memory.h" 15#include "wilc_memory.h"
16#include "wilc_strutils.h"
17
18/*!
19 * @struct tstrWILC_MsgQueueAttrs
20 * @brief Message Queue API options
21 * @author syounan
22 * @date 30 Aug 2010
23 * @version 1.0
24 */
25typedef struct {
26 /* a dummy member to avoid compiler errors*/
27 u8 dummy;
28
29} tstrWILC_MsgQueueAttrs;
30 16
31/*! 17/*!
32 * @brief Creates a new Message queue 18 * @brief Creates a new Message queue
@@ -37,14 +23,11 @@ typedef struct {
37 * @param[in,out] pHandle handle to the message queue object 23 * @param[in,out] pHandle handle to the message queue object
38 * @param[in] pstrAttrs Optional attributes, NULL for default 24 * @param[in] pstrAttrs Optional attributes, NULL for default
39 * @return Error code indicating sucess/failure 25 * @return Error code indicating sucess/failure
40 * @sa tstrWILC_MsgQueueAttrs
41 * @author syounan 26 * @author syounan
42 * @date 30 Aug 2010 27 * @date 30 Aug 2010
43 * @version 1.0 28 * @version 1.0
44 */ 29 */
45WILC_ErrNo WILC_MsgQueueCreate(WILC_MsgQueueHandle *pHandle, 30WILC_ErrNo WILC_MsgQueueCreate(WILC_MsgQueueHandle *pHandle);
46 tstrWILC_MsgQueueAttrs *pstrAttrs);
47
48 31
49/*! 32/*!
50 * @brief Sends a message 33 * @brief Sends a message
@@ -57,15 +40,12 @@ WILC_ErrNo WILC_MsgQueueCreate(WILC_MsgQueueHandle *pHandle,
57 * @param[in] u32SendBufferSize the size of the data to send 40 * @param[in] u32SendBufferSize the size of the data to send
58 * @param[in] pstrAttrs Optional attributes, NULL for default 41 * @param[in] pstrAttrs Optional attributes, NULL for default
59 * @return Error code indicating sucess/failure 42 * @return Error code indicating sucess/failure
60 * @sa tstrWILC_MsgQueueAttrs
61 * @author syounan 43 * @author syounan
62 * @date 30 Aug 2010 44 * @date 30 Aug 2010
63 * @version 1.0 45 * @version 1.0
64 */ 46 */
65WILC_ErrNo WILC_MsgQueueSend(WILC_MsgQueueHandle *pHandle, 47WILC_ErrNo WILC_MsgQueueSend(WILC_MsgQueueHandle *pHandle,
66 const void *pvSendBuffer, u32 u32SendBufferSize, 48 const void *pvSendBuffer, u32 u32SendBufferSize);
67 tstrWILC_MsgQueueAttrs *pstrAttrs);
68
69 49
70/*! 50/*!
71 * @brief Receives a message 51 * @brief Receives a message
@@ -79,30 +59,23 @@ WILC_ErrNo WILC_MsgQueueSend(WILC_MsgQueueHandle *pHandle,
79 * @param[out] pu32ReceivedLength the length of received data 59 * @param[out] pu32ReceivedLength the length of received data
80 * @param[in] pstrAttrs Optional attributes, NULL for default 60 * @param[in] pstrAttrs Optional attributes, NULL for default
81 * @return Error code indicating sucess/failure 61 * @return Error code indicating sucess/failure
82 * @sa tstrWILC_MsgQueueAttrs
83 * @author syounan 62 * @author syounan
84 * @date 30 Aug 2010 63 * @date 30 Aug 2010
85 * @version 1.0 64 * @version 1.0
86 */ 65 */
87WILC_ErrNo WILC_MsgQueueRecv(WILC_MsgQueueHandle *pHandle, 66WILC_ErrNo WILC_MsgQueueRecv(WILC_MsgQueueHandle *pHandle,
88 void *pvRecvBuffer, u32 u32RecvBufferSize, 67 void *pvRecvBuffer, u32 u32RecvBufferSize,
89 u32 *pu32ReceivedLength, 68 u32 *pu32ReceivedLength);
90 tstrWILC_MsgQueueAttrs *pstrAttrs);
91
92 69
93/*! 70/*!
94 * @brief Destroys an existing Message queue 71 * @brief Destroys an existing Message queue
95 * @param[in] pHandle handle to the message queue object 72 * @param[in] pHandle handle to the message queue object
96 * @param[in] pstrAttrs Optional attributes, NULL for default 73 * @param[in] pstrAttrs Optional attributes, NULL for default
97 * @return Error code indicating sucess/failure 74 * @return Error code indicating sucess/failure
98 * @sa tstrWILC_MsgQueueAttrs
99 * @author syounan 75 * @author syounan
100 * @date 30 Aug 2010 76 * @date 30 Aug 2010
101 * @version 1.0 77 * @version 1.0
102 */ 78 */
103WILC_ErrNo WILC_MsgQueueDestroy(WILC_MsgQueueHandle *pHandle, 79WILC_ErrNo WILC_MsgQueueDestroy(WILC_MsgQueueHandle *pHandle);
104 tstrWILC_MsgQueueAttrs *pstrAttrs);
105
106
107 80
108#endif 81#endif
diff --git a/drivers/staging/wilc1000/wilc_osconfig.h b/drivers/staging/wilc1000/wilc_osconfig.h
deleted file mode 100644
index f9c25140393e..000000000000
--- a/drivers/staging/wilc1000/wilc_osconfig.h
+++ /dev/null
@@ -1,9 +0,0 @@
1/* Logs options */
2#define WILC_LOGS_NOTHING 0
3#define WILC_LOGS_WARN 1
4#define WILC_LOGS_WARN_INFO 2
5#define WILC_LOGS_WARN_INFO_DBG 3
6#define WILC_LOGS_WARN_INFO_DBG_FN 4
7#define WILC_LOGS_ALL 5
8
9#define WILC_LOG_VERBOSITY_LEVEL WILC_LOGS_ALL
diff --git a/drivers/staging/wilc1000/wilc_oswrapper.h b/drivers/staging/wilc1000/wilc_oswrapper.h
index e97aa96006e0..cb483253e788 100644
--- a/drivers/staging/wilc1000/wilc_oswrapper.h
+++ b/drivers/staging/wilc1000/wilc_oswrapper.h
@@ -14,26 +14,14 @@
14#define WILC_OSW_INTERFACE_VER 2 14#define WILC_OSW_INTERFACE_VER 2
15 15
16/* Os Configuration File */ 16/* Os Configuration File */
17#include "wilc_osconfig.h"
18#include "wilc_platform.h" 17#include "wilc_platform.h"
19 18
20/* Logging Functions */
21#include "wilc_log.h"
22
23/* Error reporting and handling support */ 19/* Error reporting and handling support */
24#include "wilc_errorsupport.h" 20#include "wilc_errorsupport.h"
25 21
26/* Sleep support */
27#include "wilc_sleep.h"
28
29/* Timer support */
30#include "wilc_timer.h"
31
32/* Memory support */ 22/* Memory support */
33#include "wilc_memory.h" 23#include "wilc_memory.h"
34 24
35/* String Utilities */
36#include "wilc_strutils.h"
37 25
38/* Message Queue */ 26/* Message Queue */
39#include "wilc_msgqueue.h" 27#include "wilc_msgqueue.h"
diff --git a/drivers/staging/wilc1000/wilc_platform.h b/drivers/staging/wilc1000/wilc_platform.h
index d03532cc3af2..1e56973f2f93 100644
--- a/drivers/staging/wilc1000/wilc_platform.h
+++ b/drivers/staging/wilc1000/wilc_platform.h
@@ -1,5 +1,5 @@
1#ifndef __WILC_platfrom_H__ 1#ifndef __WILC_platform_H__
2#define __WILC_platfrom_H__ 2#define __WILC_platform_H__
3 3
4#include <linux/kthread.h> 4#include <linux/kthread.h>
5#include <linux/semaphore.h> 5#include <linux/semaphore.h>
@@ -16,10 +16,6 @@
16 * OS specific types 16 * OS specific types
17 *******************************************************************/ 17 *******************************************************************/
18 18
19typedef struct timer_list WILC_TimerHandle;
20
21
22
23/* Message Queue type is a structure */ 19/* Message Queue type is a structure */
24typedef struct __Message_struct { 20typedef struct __Message_struct {
25 void *pvBuffer; 21 void *pvBuffer;
diff --git a/drivers/staging/wilc1000/wilc_sdio.c b/drivers/staging/wilc1000/wilc_sdio.c
index 897e47e317ff..5a18148a593e 100644
--- a/drivers/staging/wilc1000/wilc_sdio.c
+++ b/drivers/staging/wilc1000/wilc_sdio.c
@@ -10,17 +10,7 @@
10#include "wilc_wlan_if.h" 10#include "wilc_wlan_if.h"
11#include "wilc_wlan.h" 11#include "wilc_wlan.h"
12 12
13 13#define WILC_SDIO_BLOCK_SIZE 512
14#ifdef WILC1000_SINGLE_TRANSFER
15#define WILC_SDIO_BLOCK_SIZE 256
16#else
17 #if defined(PLAT_AML8726_M3) /* johnny */
18 #define WILC_SDIO_BLOCK_SIZE 512
19 #define MAX_SEG_SIZE (1 << 12) /* 4096 */
20 #else
21 #define WILC_SDIO_BLOCK_SIZE 512
22 #endif
23#endif
24 14
25typedef struct { 15typedef struct {
26 void *os_context; 16 void *os_context;
@@ -90,7 +80,6 @@ static int sdio_set_func0_csa_address_byte0(uint32_t adr)
90{ 80{
91 sdio_cmd52_t cmd; 81 sdio_cmd52_t cmd;
92 82
93
94 /** 83 /**
95 * Review: BIG ENDIAN 84 * Review: BIG ENDIAN
96 **/ 85 **/
@@ -108,6 +97,7 @@ static int sdio_set_func0_csa_address_byte0(uint32_t adr)
108_fail_: 97_fail_:
109 return 0; 98 return 0;
110} 99}
100
111static int sdio_set_func0_block_size(uint32_t block_size) 101static int sdio_set_func0_block_size(uint32_t block_size)
112{ 102{
113 sdio_cmd52_t cmd; 103 sdio_cmd52_t cmd;
@@ -170,6 +160,7 @@ static int sdio_clear_int(void)
170#ifndef WILC_SDIO_IRQ_GPIO 160#ifndef WILC_SDIO_IRQ_GPIO
171 /* uint32_t sts; */ 161 /* uint32_t sts; */
172 sdio_cmd52_t cmd; 162 sdio_cmd52_t cmd;
163
173 cmd.read_write = 0; 164 cmd.read_write = 0;
174 cmd.function = 1; 165 cmd.function = 1;
175 cmd.raw = 0; 166 cmd.raw = 0;
@@ -181,6 +172,7 @@ static int sdio_clear_int(void)
181 return cmd.data; 172 return cmd.data;
182#else 173#else
183 uint32_t reg; 174 uint32_t reg;
175
184 if (!sdio_read_reg(WILC_HOST_RX_CTRL_0, &reg)) { 176 if (!sdio_read_reg(WILC_HOST_RX_CTRL_0, &reg)) {
185 g_sdio.dPrint(N_ERR, "[wilc spi]: Failed read reg (%08x)...\n", WILC_HOST_RX_CTRL_0); 177 g_sdio.dPrint(N_ERR, "[wilc spi]: Failed read reg (%08x)...\n", WILC_HOST_RX_CTRL_0);
186 return 0; 178 return 0;
@@ -197,6 +189,7 @@ uint32_t sdio_xfer_cnt(void)
197{ 189{
198 uint32_t cnt = 0; 190 uint32_t cnt = 0;
199 sdio_cmd52_t cmd; 191 sdio_cmd52_t cmd;
192
200 cmd.read_write = 0; 193 cmd.read_write = 0;
201 cmd.function = 1; 194 cmd.function = 1;
202 cmd.raw = 0; 195 cmd.raw = 0;
@@ -222,8 +215,6 @@ uint32_t sdio_xfer_cnt(void)
222 cnt |= (cmd.data << 16); 215 cnt |= (cmd.data << 16);
223 216
224 return cnt; 217 return cnt;
225
226
227} 218}
228 219
229/******************************************** 220/********************************************
@@ -263,6 +254,7 @@ static int sdio_write_reg(uint32_t addr, uint32_t data)
263 254
264 if ((addr >= 0xf0) && (addr <= 0xff)) { 255 if ((addr >= 0xf0) && (addr <= 0xff)) {
265 sdio_cmd52_t cmd; 256 sdio_cmd52_t cmd;
257
266 cmd.read_write = 1; 258 cmd.read_write = 1;
267 cmd.function = 0; 259 cmd.function = 0;
268 cmd.raw = 0; 260 cmd.raw = 0;
@@ -325,16 +317,6 @@ static int sdio_write(uint32_t addr, uint8_t *buf, uint32_t size)
325 cmd.function = 0; 317 cmd.function = 0;
326 cmd.address = 0x10f; 318 cmd.address = 0x10f;
327 } else { 319 } else {
328#ifdef WILC1000_SINGLE_TRANSFER
329 /**
330 * has to be block aligned...
331 **/
332 nleft = size % block_size;
333 if (nleft > 0) {
334 size += block_size;
335 size &= ~(block_size - 1);
336 }
337#else
338 /** 320 /**
339 * has to be word aligned... 321 * has to be word aligned...
340 **/ 322 **/
@@ -342,7 +324,6 @@ static int sdio_write(uint32_t addr, uint8_t *buf, uint32_t size)
342 size += 4; 324 size += 4;
343 size &= ~0x3; 325 size &= ~0x3;
344 } 326 }
345#endif
346 327
347 /** 328 /**
348 * func 1 access 329 * func 1 access
@@ -355,89 +336,6 @@ static int sdio_write(uint32_t addr, uint8_t *buf, uint32_t size)
355 nleft = size % block_size; 336 nleft = size % block_size;
356 337
357 if (nblk > 0) { 338 if (nblk > 0) {
358
359#if defined(PLAT_AML8726_M3_BACKUP) /* johnny */
360 int i;
361
362 for (i = 0; i < nblk; i++) {
363 cmd.block_mode = 0; /* 1; */
364 cmd.increment = 1;
365 cmd.count = block_size; /* nblk; */
366 cmd.buffer = buf;
367 cmd.block_size = block_size;
368 if (addr > 0) {
369 if (!sdio_set_func0_csa_address(addr))
370 goto _fail_;
371 }
372 if (!g_sdio.sdio_cmd53(&cmd)) {
373 g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd53 [%x], block send...\n", addr);
374 goto _fail_;
375 }
376
377 if (addr > 0)
378 addr += block_size; /* addr += nblk*block_size; */
379
380 buf += block_size; /* buf += nblk*block_size; */
381 }
382
383#elif defined(PLAT_AML8726_M3) /* johnny */
384
385 int i;
386 int rest;
387 int seg_cnt;
388
389 seg_cnt = (nblk * block_size) / MAX_SEG_SIZE;
390 rest = (nblk * block_size) & (MAX_SEG_SIZE - 1);
391
392 for (i = 0; i < seg_cnt; i++) {
393 cmd.block_mode = 1;
394 cmd.increment = 1;
395 cmd.count = MAX_SEG_SIZE / block_size;
396 cmd.buffer = buf;
397 cmd.block_size = block_size;
398
399 if (addr > 0) {
400 if (!sdio_set_func0_csa_address(addr))
401 goto _fail_;
402 }
403 if (!g_sdio.sdio_cmd53(&cmd)) {
404 g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd53 [%x], block send...\n", addr);
405 goto _fail_;
406 }
407
408 if (addr > 0)
409 addr += MAX_SEG_SIZE;
410
411 buf += MAX_SEG_SIZE;
412
413 }
414
415
416 if (rest > 0) {
417 cmd.block_mode = 1;
418 cmd.increment = 1;
419 cmd.count = rest / block_size;
420 cmd.buffer = buf;
421 cmd.block_size = block_size; /* johnny : prevent it from setting unexpected value */
422
423 if (addr > 0) {
424 if (!sdio_set_func0_csa_address(addr))
425 goto _fail_;
426 }
427 if (!g_sdio.sdio_cmd53(&cmd)) {
428 g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd53 [%x], bytes send...\n", addr);
429 goto _fail_;
430 }
431
432 if (addr > 0)
433 addr += rest;
434
435 buf += rest;
436
437 }
438
439#else
440
441 cmd.block_mode = 1; 339 cmd.block_mode = 1;
442 cmd.increment = 1; 340 cmd.increment = 1;
443 cmd.count = nblk; 341 cmd.count = nblk;
@@ -454,11 +352,8 @@ static int sdio_write(uint32_t addr, uint8_t *buf, uint32_t size)
454 if (addr > 0) 352 if (addr > 0)
455 addr += nblk * block_size; 353 addr += nblk * block_size;
456 buf += nblk * block_size; 354 buf += nblk * block_size;
457
458#endif /* platform */
459 } 355 }
460 356
461
462 if (nleft > 0) { 357 if (nleft > 0) {
463 cmd.block_mode = 0; 358 cmd.block_mode = 0;
464 cmd.increment = 1; 359 cmd.increment = 1;
@@ -488,6 +383,7 @@ static int sdio_read_reg(uint32_t addr, uint32_t *data)
488{ 383{
489 if ((addr >= 0xf0) && (addr <= 0xff)) { 384 if ((addr >= 0xf0) && (addr <= 0xff)) {
490 sdio_cmd52_t cmd; 385 sdio_cmd52_t cmd;
386
491 cmd.read_write = 0; 387 cmd.read_write = 0;
492 cmd.function = 0; 388 cmd.function = 0;
493 cmd.raw = 0; 389 cmd.raw = 0;
@@ -552,16 +448,6 @@ static int sdio_read(uint32_t addr, uint8_t *buf, uint32_t size)
552 cmd.function = 0; 448 cmd.function = 0;
553 cmd.address = 0x10f; 449 cmd.address = 0x10f;
554 } else { 450 } else {
555#ifdef WILC1000_SINGLE_TRANSFER
556 /**
557 * has to be block aligned...
558 **/
559 nleft = size % block_size;
560 if (nleft > 0) {
561 size += block_size;
562 size &= ~(block_size - 1);
563 }
564#else
565 /** 451 /**
566 * has to be word aligned... 452 * has to be word aligned...
567 **/ 453 **/
@@ -569,7 +455,6 @@ static int sdio_read(uint32_t addr, uint8_t *buf, uint32_t size)
569 size += 4; 455 size += 4;
570 size &= ~0x3; 456 size &= ~0x3;
571 } 457 }
572#endif
573 458
574 /** 459 /**
575 * func 1 access 460 * func 1 access
@@ -582,89 +467,6 @@ static int sdio_read(uint32_t addr, uint8_t *buf, uint32_t size)
582 nleft = size % block_size; 467 nleft = size % block_size;
583 468
584 if (nblk > 0) { 469 if (nblk > 0) {
585
586#if defined(PLAT_AML8726_M3_BACKUP) /* johnny */
587
588 int i;
589
590 for (i = 0; i < nblk; i++) {
591 cmd.block_mode = 0; /* 1; */
592 cmd.increment = 1;
593 cmd.count = block_size; /* nblk; */
594 cmd.buffer = buf;
595 cmd.block_size = block_size;
596 if (addr > 0) {
597 if (!sdio_set_func0_csa_address(addr))
598 goto _fail_;
599 }
600 if (!g_sdio.sdio_cmd53(&cmd)) {
601 g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd53 [%x], block read...\n", addr);
602 goto _fail_;
603 }
604 if (addr > 0)
605 addr += block_size; /* addr += nblk*block_size; */
606 buf += block_size; /* buf += nblk*block_size; */
607 }
608
609#elif defined(PLAT_AML8726_M3) /* johnny */
610
611 int i;
612 int rest;
613 int seg_cnt;
614
615 seg_cnt = (nblk * block_size) / MAX_SEG_SIZE;
616 rest = (nblk * block_size) & (MAX_SEG_SIZE - 1);
617
618 for (i = 0; i < seg_cnt; i++) {
619 cmd.block_mode = 1;
620 cmd.increment = 1;
621 cmd.count = MAX_SEG_SIZE / block_size;
622 cmd.buffer = buf;
623 cmd.block_size = block_size;
624
625
626 if (addr > 0) {
627 if (!sdio_set_func0_csa_address(addr))
628 goto _fail_;
629 }
630 if (!g_sdio.sdio_cmd53(&cmd)) {
631 g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd53 [%x], block read...\n", addr);
632 goto _fail_;
633 }
634
635 if (addr > 0)
636 addr += MAX_SEG_SIZE;
637
638 buf += MAX_SEG_SIZE;
639
640 }
641
642
643 if (rest > 0) {
644 cmd.block_mode = 1;
645 cmd.increment = 1;
646 cmd.count = rest / block_size;
647 cmd.buffer = buf;
648 cmd.block_size = block_size; /* johnny : prevent it from setting unexpected value */
649
650 if (addr > 0) {
651 if (!sdio_set_func0_csa_address(addr))
652 goto _fail_;
653 }
654 if (!g_sdio.sdio_cmd53(&cmd)) {
655 g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd53 [%x], block read...\n", addr);
656 goto _fail_;
657 }
658
659 if (addr > 0)
660 addr += rest;
661
662 buf += rest;
663
664 }
665
666#else
667
668 cmd.block_mode = 1; 470 cmd.block_mode = 1;
669 cmd.increment = 1; 471 cmd.increment = 1;
670 cmd.count = nblk; 472 cmd.count = nblk;
@@ -681,8 +483,6 @@ static int sdio_read(uint32_t addr, uint8_t *buf, uint32_t size)
681 if (addr > 0) 483 if (addr > 0)
682 addr += nblk * block_size; 484 addr += nblk * block_size;
683 buf += nblk * block_size; 485 buf += nblk * block_size;
684
685#endif /* platform */
686 } /* if (nblk > 0) */ 486 } /* if (nblk > 0) */
687 487
688 if (nleft > 0) { 488 if (nleft > 0) {
@@ -784,6 +584,7 @@ static int sdio_init(wilc_wlan_inp_t *inp, wilc_debug_func func)
784 sdio_cmd52_t cmd; 584 sdio_cmd52_t cmd;
785 int loop; 585 int loop;
786 uint32_t chipid; 586 uint32_t chipid;
587
787 memset(&g_sdio, 0, sizeof(wilc_sdio_t)); 588 memset(&g_sdio, 0, sizeof(wilc_sdio_t));
788 589
789 g_sdio.dPrint = func; 590 g_sdio.dPrint = func;
@@ -891,14 +692,12 @@ static int sdio_init(wilc_wlan_inp_t *inp, wilc_debug_func func)
891 goto _fail_; 692 goto _fail_;
892 } 693 }
893 g_sdio.dPrint(N_ERR, "[wilc sdio]: chipid (%08x)\n", chipid); 694 g_sdio.dPrint(N_ERR, "[wilc sdio]: chipid (%08x)\n", chipid);
894 if ((chipid & 0xfff) > 0x2a0) { 695 if ((chipid & 0xfff) > 0x2a0)
895 g_sdio.has_thrpt_enh3 = 1; 696 g_sdio.has_thrpt_enh3 = 1;
896 } else { 697 else
897 g_sdio.has_thrpt_enh3 = 0; 698 g_sdio.has_thrpt_enh3 = 0;
898 }
899 g_sdio.dPrint(N_ERR, "[wilc sdio]: has_thrpt_enh3 = %d...\n", g_sdio.has_thrpt_enh3); 699 g_sdio.dPrint(N_ERR, "[wilc sdio]: has_thrpt_enh3 = %d...\n", g_sdio.has_thrpt_enh3);
900 700
901
902 return 1; 701 return 1;
903 702
904_fail_: 703_fail_:
@@ -925,23 +724,21 @@ static int sdio_read_size(uint32_t *size)
925 /** 724 /**
926 * Read DMA count in words 725 * Read DMA count in words
927 **/ 726 **/
928 { 727 cmd.read_write = 0;
929 cmd.read_write = 0; 728 cmd.function = 0;
930 cmd.function = 0; 729 cmd.raw = 0;
931 cmd.raw = 0; 730 cmd.address = 0xf2;
932 cmd.address = 0xf2; 731 cmd.data = 0;
933 cmd.data = 0; 732 g_sdio.sdio_cmd52(&cmd);
934 g_sdio.sdio_cmd52(&cmd); 733 tmp = cmd.data;
935 tmp = cmd.data;
936 734
937 /* cmd.read_write = 0; */ 735 /* cmd.read_write = 0; */
938 /* cmd.function = 0; */ 736 /* cmd.function = 0; */
939 /* cmd.raw = 0; */ 737 /* cmd.raw = 0; */
940 cmd.address = 0xf3; 738 cmd.address = 0xf3;
941 cmd.data = 0; 739 cmd.data = 0;
942 g_sdio.sdio_cmd52(&cmd); 740 g_sdio.sdio_cmd52(&cmd);
943 tmp |= (cmd.data << 8); 741 tmp |= (cmd.data << 8);
944 }
945 742
946 *size = tmp; 743 *size = tmp;
947 return 1; 744 return 1;
@@ -966,26 +763,21 @@ static int sdio_read_int(uint32_t *int_status)
966 cmd.data = 0; 763 cmd.data = 0;
967 g_sdio.sdio_cmd52(&cmd); 764 g_sdio.sdio_cmd52(&cmd);
968 765
969 if (cmd.data & (1 << 0)) { 766 if (cmd.data & (1 << 0))
970 tmp |= INT_0; 767 tmp |= INT_0;
971 } 768 if (cmd.data & (1 << 2))
972 if (cmd.data & (1 << 2)) {
973 tmp |= INT_1; 769 tmp |= INT_1;
974 } 770 if (cmd.data & (1 << 3))
975 if (cmd.data & (1 << 3)) {
976 tmp |= INT_2; 771 tmp |= INT_2;
977 } 772 if (cmd.data & (1 << 4))
978 if (cmd.data & (1 << 4)) {
979 tmp |= INT_3; 773 tmp |= INT_3;
980 } 774 if (cmd.data & (1 << 5))
981 if (cmd.data & (1 << 5)) {
982 tmp |= INT_4; 775 tmp |= INT_4;
983 } 776 if (cmd.data & (1 << 6))
984 if (cmd.data & (1 << 6)) {
985 tmp |= INT_5; 777 tmp |= INT_5;
986 }
987 { 778 {
988 int i; 779 int i;
780
989 for (i = g_sdio.nint; i < MAX_NUM_INT; i++) { 781 for (i = g_sdio.nint; i < MAX_NUM_INT; i++) {
990 if ((tmp >> (IRG_FLAGS_OFFSET + i)) & 0x1) { 782 if ((tmp >> (IRG_FLAGS_OFFSET + i)) & 0x1) {
991 g_sdio.dPrint(N_ERR, "[wilc sdio]: Unexpected interrupt (1) : tmp=%x, data=%x\n", tmp, cmd.data); 783 g_sdio.dPrint(N_ERR, "[wilc sdio]: Unexpected interrupt (1) : tmp=%x, data=%x\n", tmp, cmd.data);
@@ -1024,6 +816,7 @@ static int sdio_clear_int_ext(uint32_t val)
1024#ifdef WILC_SDIO_IRQ_GPIO 816#ifdef WILC_SDIO_IRQ_GPIO
1025 { 817 {
1026 uint32_t flags; 818 uint32_t flags;
819
1027 flags = val & ((1 << MAX_NUN_INT_THRPT_ENH2) - 1); 820 flags = val & ((1 << MAX_NUN_INT_THRPT_ENH2) - 1);
1028 reg = flags; 821 reg = flags;
1029 } 822 }
@@ -1041,6 +834,7 @@ static int sdio_clear_int_ext(uint32_t val)
1041 reg |= (1 << 7); 834 reg |= (1 << 7);
1042 if (reg) { 835 if (reg) {
1043 sdio_cmd52_t cmd; 836 sdio_cmd52_t cmd;
837
1044 cmd.read_write = 1; 838 cmd.read_write = 1;
1045 cmd.function = 0; 839 cmd.function = 0;
1046 cmd.raw = 0; 840 cmd.raw = 0;
@@ -1060,6 +854,7 @@ static int sdio_clear_int_ext(uint32_t val)
1060 /* see below. has_thrpt_enh2 uses register 0xf8 to clear interrupts. */ 854 /* see below. has_thrpt_enh2 uses register 0xf8 to clear interrupts. */
1061 /* Cannot clear multiple interrupts. Must clear each interrupt individually */ 855 /* Cannot clear multiple interrupts. Must clear each interrupt individually */
1062 uint32_t flags; 856 uint32_t flags;
857
1063 flags = val & ((1 << MAX_NUM_INT) - 1); 858 flags = val & ((1 << MAX_NUM_INT) - 1);
1064 if (flags) { 859 if (flags) {
1065 int i; 860 int i;
@@ -1068,6 +863,7 @@ static int sdio_clear_int_ext(uint32_t val)
1068 for (i = 0; i < g_sdio.nint; i++) { 863 for (i = 0; i < g_sdio.nint; i++) {
1069 if (flags & 1) { 864 if (flags & 1) {
1070 sdio_cmd52_t cmd; 865 sdio_cmd52_t cmd;
866
1071 cmd.read_write = 1; 867 cmd.read_write = 1;
1072 cmd.function = 0; 868 cmd.function = 0;
1073 cmd.raw = 0; 869 cmd.raw = 0;
@@ -1085,9 +881,8 @@ static int sdio_clear_int_ext(uint32_t val)
1085 break; 881 break;
1086 flags >>= 1; 882 flags >>= 1;
1087 } 883 }
1088 if (!ret) { 884 if (!ret)
1089 goto _fail_; 885 goto _fail_;
1090 }
1091 for (i = g_sdio.nint; i < MAX_NUM_INT; i++) { 886 for (i = g_sdio.nint; i < MAX_NUM_INT; i++) {
1092 if (flags & 1) 887 if (flags & 1)
1093 g_sdio.dPrint(N_ERR, "[wilc sdio]: Unexpected interrupt cleared %d...\n", i); 888 g_sdio.dPrint(N_ERR, "[wilc sdio]: Unexpected interrupt cleared %d...\n", i);
@@ -1097,7 +892,6 @@ static int sdio_clear_int_ext(uint32_t val)
1097 } 892 }
1098#endif /* WILC_SDIO_IRQ_GPIO */ 893#endif /* WILC_SDIO_IRQ_GPIO */
1099 894
1100
1101 { 895 {
1102 uint32_t vmm_ctl; 896 uint32_t vmm_ctl;
1103 897
@@ -1138,7 +932,6 @@ static int sdio_sync_ext(int nint /* how mant interrupts to enable. */)
1138{ 932{
1139 uint32_t reg; 933 uint32_t reg;
1140 934
1141
1142 if (nint > MAX_NUM_INT) { 935 if (nint > MAX_NUM_INT) {
1143 g_sdio.dPrint(N_ERR, "[wilc sdio]: Too many interupts (%d)...\n", nint); 936 g_sdio.dPrint(N_ERR, "[wilc sdio]: Too many interupts (%d)...\n", nint);
1144 return 0; 937 return 0;
@@ -1148,7 +941,6 @@ static int sdio_sync_ext(int nint /* how mant interrupts to enable. */)
1148 return 0; 941 return 0;
1149 } 942 }
1150 943
1151
1152 g_sdio.nint = nint; 944 g_sdio.nint = nint;
1153 945
1154 /** 946 /**
@@ -1170,7 +962,6 @@ static int sdio_sync_ext(int nint /* how mant interrupts to enable. */)
1170 uint32_t reg; 962 uint32_t reg;
1171 int ret, i; 963 int ret, i;
1172 964
1173
1174 /** 965 /**
1175 * interrupt pin mux select 966 * interrupt pin mux select
1176 **/ 967 **/
@@ -1195,9 +986,8 @@ static int sdio_sync_ext(int nint /* how mant interrupts to enable. */)
1195 return 0; 986 return 0;
1196 } 987 }
1197 988
1198 for (i = 0; (i < 5) && (nint > 0); i++, nint--) { 989 for (i = 0; (i < 5) && (nint > 0); i++, nint--)
1199 reg |= (1 << (27 + i)); 990 reg |= (1 << (27 + i));
1200 }
1201 ret = sdio_write_reg(WILC_INTR_ENABLE, reg); 991 ret = sdio_write_reg(WILC_INTR_ENABLE, reg);
1202 if (!ret) { 992 if (!ret) {
1203 g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed write reg (%08x)...\n", WILC_INTR_ENABLE); 993 g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed write reg (%08x)...\n", WILC_INTR_ENABLE);
@@ -1210,9 +1000,8 @@ static int sdio_sync_ext(int nint /* how mant interrupts to enable. */)
1210 return 0; 1000 return 0;
1211 } 1001 }
1212 1002
1213 for (i = 0; (i < 3) && (nint > 0); i++, nint--) { 1003 for (i = 0; (i < 3) && (nint > 0); i++, nint--)
1214 reg |= (1 << i); 1004 reg |= (1 << i);
1215 }
1216 1005
1217 ret = sdio_read_reg(WILC_INTR2_ENABLE, &reg); 1006 ret = sdio_read_reg(WILC_INTR2_ENABLE, &reg);
1218 if (!ret) { 1007 if (!ret) {
@@ -1225,7 +1014,6 @@ static int sdio_sync_ext(int nint /* how mant interrupts to enable. */)
1225 return 1; 1014 return 1;
1226} 1015}
1227 1016
1228
1229/******************************************** 1017/********************************************
1230 * 1018 *
1231 * Global sdio HIF function table 1019 * Global sdio HIF function table
diff --git a/drivers/staging/wilc1000/wilc_sleep.c b/drivers/staging/wilc1000/wilc_sleep.c
deleted file mode 100644
index adab3cac64f9..000000000000
--- a/drivers/staging/wilc1000/wilc_sleep.c
+++ /dev/null
@@ -1,18 +0,0 @@
1
2#include "wilc_sleep.h"
3
4/*
5 * @author mdaftedar
6 * @date 10 Aug 2010
7 * @version 1.0
8 */
9void WILC_Sleep(u32 u32TimeMilliSec)
10{
11 if (u32TimeMilliSec <= 4000000) {
12 u32 u32Temp = u32TimeMilliSec * 1000;
13 usleep_range(u32Temp, u32Temp);
14 } else {
15 msleep(u32TimeMilliSec);
16 }
17
18}
diff --git a/drivers/staging/wilc1000/wilc_sleep.h b/drivers/staging/wilc1000/wilc_sleep.h
deleted file mode 100644
index cf9047f707a7..000000000000
--- a/drivers/staging/wilc1000/wilc_sleep.h
+++ /dev/null
@@ -1,20 +0,0 @@
1#ifndef __WILC_SLEEP_H__
2#define __WILC_SLEEP_H__
3
4#include <linux/types.h>
5#include <linux/delay.h>
6
7/*!
8 * @brief forces the current thread to sleep until the given time has elapsed
9 * @param[in] u32TimeMilliSec Time to sleep in Milli seconds
10 * @sa WILC_SleepMicrosec
11 * @author syounan
12 * @date 10 Aug 2010
13 * @version 1.0
14 * @note This function offers a relatively innacurate and low resolution
15 * sleep, for accurate high resolution sleep use u32TimeMicoSec
16 */
17/* TODO: remove and open-code in callers */
18void WILC_Sleep(u32 u32TimeMilliSec);
19
20#endif
diff --git a/drivers/staging/wilc1000/wilc_spi.c b/drivers/staging/wilc1000/wilc_spi.c
index abea5df656d7..1bf7d314ae34 100644
--- a/drivers/staging/wilc1000/wilc_spi.c
+++ b/drivers/staging/wilc1000/wilc_spi.c
@@ -374,11 +374,10 @@ static int spi_cmd_complete(uint8_t cmd, uint32_t adr, uint8_t *b, uint32_t sz,
374 return result; 374 return result;
375 } 375 }
376 376
377 if (!g_spi.crc_off) { 377 if (!g_spi.crc_off)
378 wb[len - 1] = (crc7(0x7f, (const uint8_t *)&wb[0], len - 1)) << 1; 378 wb[len - 1] = (crc7(0x7f, (const uint8_t *)&wb[0], len - 1)) << 1;
379 } else { 379 else
380 len -= 1; 380 len -= 1;
381 }
382 381
383#define NUM_SKIP_BYTES (1) 382#define NUM_SKIP_BYTES (1)
384#define NUM_RSP_BYTES (2) 383#define NUM_RSP_BYTES (2)
@@ -522,11 +521,10 @@ static int spi_cmd_complete(uint8_t cmd, uint32_t adr, uint8_t *b, uint32_t sz,
522 if (sz > 0) { 521 if (sz > 0) {
523 int nbytes; 522 int nbytes;
524 523
525 if (sz <= (DATA_PKT_SZ - ix)) { 524 if (sz <= (DATA_PKT_SZ - ix))
526 nbytes = sz; 525 nbytes = sz;
527 } else { 526 else
528 nbytes = DATA_PKT_SZ - ix; 527 nbytes = DATA_PKT_SZ - ix;
529 }
530 528
531 /** 529 /**
532 * Read bytes 530 * Read bytes
@@ -557,11 +555,10 @@ static int spi_cmd_complete(uint8_t cmd, uint32_t adr, uint8_t *b, uint32_t sz,
557 while (sz > 0) { 555 while (sz > 0) {
558 int nbytes; 556 int nbytes;
559 557
560 if (sz <= DATA_PKT_SZ) { 558 if (sz <= DATA_PKT_SZ)
561 nbytes = sz; 559 nbytes = sz;
562 } else { 560 else
563 nbytes = DATA_PKT_SZ; 561 nbytes = DATA_PKT_SZ;
564 }
565 562
566 /** 563 /**
567 * read data response only on the next DMA cycles not 564 * read data response only on the next DMA cycles not
diff --git a/drivers/staging/wilc1000/wilc_strutils.c b/drivers/staging/wilc1000/wilc_strutils.c
deleted file mode 100644
index e0145953ceef..000000000000
--- a/drivers/staging/wilc1000/wilc_strutils.c
+++ /dev/null
@@ -1,80 +0,0 @@
1
2#define _CRT_SECURE_NO_DEPRECATE
3
4#include "wilc_strutils.h"
5
6
7/*!
8 * @author syounan
9 * @date 18 Aug 2010
10 * @version 1.0
11 */
12s32 WILC_memcmp(const void *pvArg1, const void *pvArg2, u32 u32Count)
13{
14 return memcmp(pvArg1, pvArg2, u32Count);
15}
16
17
18/*!
19 * @author syounan
20 * @date 18 Aug 2010
21 * @version 1.0
22 */
23void WILC_memcpy_INTERNAL(void *pvTarget, const void *pvSource, u32 u32Count)
24{
25 memcpy(pvTarget, pvSource, u32Count);
26}
27
28/*!
29 * @author syounan
30 * @date 18 Aug 2010
31 * @version 1.0
32 */
33void *WILC_memset(void *pvTarget, u8 u8SetValue, u32 u32Count)
34{
35 return memset(pvTarget, u8SetValue, u32Count);
36}
37
38/*!
39 * @author syounan
40 * @date 18 Aug 2010
41 * @version 1.0
42 */
43char *WILC_strncpy(char *pcTarget, const char *pcSource,
44 u32 u32Count)
45{
46 return strncpy(pcTarget, pcSource, u32Count);
47}
48
49s32 WILC_strncmp(const char *pcStr1, const char *pcStr2,
50 u32 u32Count)
51{
52 s32 s32Result;
53
54 if (pcStr1 == NULL && pcStr2 == NULL) {
55 s32Result = 0;
56 } else if (pcStr1 == NULL) {
57 s32Result = -1;
58 } else if (pcStr2 == NULL) {
59 s32Result = 1;
60 } else {
61 s32Result = strncmp(pcStr1, pcStr2, u32Count);
62 if (s32Result < 0) {
63 s32Result = -1;
64 } else if (s32Result > 0) {
65 s32Result = 1;
66 }
67 }
68
69 return s32Result;
70}
71
72/*!
73 * @author syounan
74 * @date 18 Aug 2010
75 * @version 1.0
76 */
77u32 WILC_strlen(const char *pcStr)
78{
79 return (u32)strlen(pcStr);
80}
diff --git a/drivers/staging/wilc1000/wilc_strutils.h b/drivers/staging/wilc1000/wilc_strutils.h
deleted file mode 100644
index d1445575a25e..000000000000
--- a/drivers/staging/wilc1000/wilc_strutils.h
+++ /dev/null
@@ -1,134 +0,0 @@
1#ifndef __WILC_STRUTILS_H__
2#define __WILC_STRUTILS_H__
3
4/*!
5 * @file wilc_strutils.h
6 * @brief Basic string utilities
7 * @author syounan
8 * @sa wilc_oswrapper.h top level OS wrapper file
9 * @date 16 Aug 2010
10 * @version 1.0
11 */
12
13#include <linux/types.h>
14#include <linux/string.h>
15#include "wilc_errorsupport.h"
16
17/*!
18 * @brief Compares two memory buffers
19 * @param[in] pvArg1 pointer to the first memory location
20 * @param[in] pvArg2 pointer to the second memory location
21 * @param[in] u32Count the size of the memory buffers
22 * @return 0 if the 2 buffers are equal, 1 if pvArg1 is bigger than pvArg2,
23 * -1 if pvArg1 smaller than pvArg2
24 * @note this function repeats the functionality of standard memcmp
25 * @author syounan
26 * @date 18 Aug 2010
27 * @version 1.0
28 */
29s32 WILC_memcmp(const void *pvArg1, const void *pvArg2, u32 u32Count);
30
31/*!
32 * @brief Internal implementation for memory copy
33 * @param[in] pvTarget the target buffer to which the data is copied into
34 * @param[in] pvSource pointer to the second memory location
35 * @param[in] u32Count the size of the data to copy
36 * @note this function should not be used directly, use WILC_memcpy instead
37 * @author syounan
38 * @date 18 Aug 2010
39 * @version 1.0
40 */
41void WILC_memcpy_INTERNAL(void *pvTarget, const void *pvSource, u32 u32Count);
42
43/*!
44 * @brief Copies the contents of a memory buffer into another
45 * @param[in] pvTarget the target buffer to which the data is copied into
46 * @param[in] pvSource pointer to the second memory location
47 * @param[in] u32Count the size of the data to copy
48 * @return WILC_SUCCESS if copy is successfully handeled
49 * WILC_FAIL if copy failed
50 * @note this function repeats the functionality of standard memcpy,
51 * however memcpy is undefined if the two buffers overlap but this
52 * implementation will check for overlap and report error
53 * @author syounan
54 * @date 18 Aug 2010
55 * @version 1.0
56 */
57static WILC_ErrNo WILC_memcpy(void *pvTarget, const void *pvSource, u32 u32Count)
58{
59 if (
60 (((u8 *)pvTarget <= (u8 *)pvSource)
61 && (((u8 *)pvTarget + u32Count) > (u8 *)pvSource))
62
63 || (((u8 *)pvSource <= (u8 *)pvTarget)
64 && (((u8 *)pvSource + u32Count) > (u8 *)pvTarget))
65 ) {
66 /* ovelapped memory, return Error */
67 return WILC_FAIL;
68 } else {
69 WILC_memcpy_INTERNAL(pvTarget, pvSource, u32Count);
70 return WILC_SUCCESS;
71 }
72}
73
74/*!
75 * @brief Sets the contents of a memory buffer with the given value
76 * @param[in] pvTarget the target buffer which contsnts will be set
77 * @param[in] u8SetValue the value to be used
78 * @param[in] u32Count the size of the memory buffer
79 * @return value of pvTarget
80 * @note this function repeats the functionality of standard memset
81 * @author syounan
82 * @date 18 Aug 2010
83 * @version 1.0
84 */
85void *WILC_memset(void *pvTarget, u8 u8SetValue, u32 u32Count);
86
87/*!
88 * @brief copies the contents of source string into the target string
89 * @param[in] pcTarget the target string buffer
90 * @param[in] pcSource the source string the will be copied
91 * @param[in] u32Count copying will proceed until a null character in pcSource
92 * is encountered or u32Count of bytes copied
93 * @return value of pcTarget
94 * @note this function repeats the functionality of standard strncpy
95 * @author syounan
96 * @date 18 Aug 2010
97 * @version 1.0
98 */
99char *WILC_strncpy(char *pcTarget, const char *pcSource,
100 u32 u32Count);
101
102/*!
103 * @brief Compares two strings up to u32Count characters
104 * @details Compares 2 strings reporting which is bigger, NULL is considered
105 * the smallest string, then a zero length string then all other
106 * strings depending on thier ascii characters order with small case
107 * converted to uppder case
108 * @param[in] pcStr1 the first string, NULL is valid and considered smaller
109 * than any other non-NULL string (incliding zero lenght strings)
110 * @param[in] pcStr2 the second string, NULL is valid and considered smaller
111 * than any other non-NULL string (incliding zero lenght strings)
112 * @param[in] u32Count copying will proceed until a null character in pcStr1 or
113 * pcStr2 is encountered or u32Count of bytes copied
114 * @return 0 if the 2 strings are equal, 1 if pcStr1 is bigger than pcStr2,
115 * -1 if pcStr1 smaller than pcStr2
116 * @author aabozaeid
117 * @date 7 Dec 2010
118 * @version 1.0
119 */
120s32 WILC_strncmp(const char *pcStr1, const char *pcStr2,
121 u32 u32Count);
122
123/*!
124 * @brief gets the length of a string
125 * @param[in] pcStr the string
126 * @return the length
127 * @note this function repeats the functionality of standard strlen
128 * @author syounan
129 * @date 18 Aug 2010
130 * @version 1.0
131 */
132u32 WILC_strlen(const char *pcStr);
133
134#endif
diff --git a/drivers/staging/wilc1000/wilc_timer.c b/drivers/staging/wilc1000/wilc_timer.c
deleted file mode 100644
index dc71157f9c3e..000000000000
--- a/drivers/staging/wilc1000/wilc_timer.c
+++ /dev/null
@@ -1,45 +0,0 @@
1
2#include "wilc_timer.h"
3
4WILC_ErrNo WILC_TimerCreate(WILC_TimerHandle *pHandle,
5 tpfWILC_TimerFunction pfCallback, tstrWILC_TimerAttrs *pstrAttrs)
6{
7 WILC_ErrNo s32RetStatus = WILC_SUCCESS;
8 setup_timer(pHandle, (void(*)(unsigned long))pfCallback, 0);
9
10 return s32RetStatus;
11}
12
13WILC_ErrNo WILC_TimerDestroy(WILC_TimerHandle *pHandle,
14 tstrWILC_TimerAttrs *pstrAttrs)
15{
16 WILC_ErrNo s32RetStatus = WILC_FAIL;
17 if (pHandle != NULL) {
18 s32RetStatus = del_timer_sync(pHandle);
19 pHandle = NULL;
20 }
21
22 return s32RetStatus;
23}
24
25
26WILC_ErrNo WILC_TimerStart(WILC_TimerHandle *pHandle, u32 u32Timeout,
27 void *pvArg, tstrWILC_TimerAttrs *pstrAttrs)
28{
29 WILC_ErrNo s32RetStatus = WILC_FAIL;
30 if (pHandle != NULL) {
31 pHandle->data = (unsigned long)pvArg;
32 s32RetStatus = mod_timer(pHandle, (jiffies + msecs_to_jiffies(u32Timeout)));
33 }
34 return s32RetStatus;
35}
36
37WILC_ErrNo WILC_TimerStop(WILC_TimerHandle *pHandle,
38 tstrWILC_TimerAttrs *pstrAttrs)
39{
40 WILC_ErrNo s32RetStatus = WILC_FAIL;
41 if (pHandle != NULL)
42 s32RetStatus = del_timer(pHandle);
43
44 return s32RetStatus;
45}
diff --git a/drivers/staging/wilc1000/wilc_timer.h b/drivers/staging/wilc1000/wilc_timer.h
deleted file mode 100644
index 931269db3194..000000000000
--- a/drivers/staging/wilc1000/wilc_timer.h
+++ /dev/null
@@ -1,129 +0,0 @@
1#ifndef __WILC_TIMER_H__
2#define __WILC_TIMER_H__
3
4/*!
5 * @file wilc_timer.h
6 * @brief Timer (One Shot and Periodic) OS wrapper functionality
7 * @author syounan
8 * @sa wilc_oswrapper.h top level OS wrapper file
9 * @date 16 Aug 2010
10 * @version 1.0
11 */
12
13#include "wilc_platform.h"
14#include "wilc_errorsupport.h"
15
16typedef void (*tpfWILC_TimerFunction)(void *);
17
18/*!
19 * @struct tstrWILC_TimerAttrs
20 * @brief Timer API options
21 * @author syounan
22 * @date 16 Aug 2010
23 * @version 1.0
24 */
25typedef struct {
26 /* a dummy member to avoid compiler errors*/
27 u8 dummy;
28} tstrWILC_TimerAttrs;
29
30/*!
31 * @brief Creates a new timer
32 * @details Timers are a useful utility to execute some callback function
33 * in the future.
34 * A timer object has 3 states : IDLE, PENDING and EXECUTING
35 * IDLE : initial timer state after creation, no execution for the
36 * callback function is planned
37 * PENDING : a request to execute the callback function is made
38 * using WILC_TimerStart.
39 * EXECUTING : the timer has expired and its callback is now
40 * executing, when execution is done the timer returns to PENDING
41 * if the feature CONFIG_WILC_TIMER_PERIODIC is enabled and
42 * the flag tstrWILC_TimerAttrs.bPeriodicTimer is set. otherwise the
43 * timer will return to IDLE
44 * @param[out] pHandle handle to the newly created timer object
45 * @param[in] pfEntry pointer to the callback function to be called when the
46 * timer expires
47 * the underlaying OS may put many restrictions on what can be
48 * called inside a timer's callback, as a general rule no blocking
49 * operations (IO or semaphore Acquision) should be perfomred
50 * It is recommended that the callback will be as short as possible
51 * and only flags other threads to do the actual work
52 * also it should be noted that the underlaying OS maynot give any
53 * guarentees on which contect this callback will execute in
54 * @param[in] pstrAttrs Optional attributes, NULL for default
55 * @return Error code indicating sucess/failure
56 * @sa WILC_TimerAttrs
57 * @author syounan
58 * @date 16 Aug 2010
59 * @version 1.0
60 */
61WILC_ErrNo WILC_TimerCreate(WILC_TimerHandle *pHandle,
62 tpfWILC_TimerFunction pfCallback, tstrWILC_TimerAttrs *pstrAttrs);
63
64
65/*!
66 * @brief Destroys a given timer
67 * @details This will destroy a given timer freeing any resources used by it
68 * if the timer was PENDING Then must be cancelled as well(i.e.
69 * goes to IDLE, same effect as calling WILC_TimerCancel first)
70 * if the timer was EXECUTING then the callback will be allowed to
71 * finish first then all resources are freed
72 * @param[in] pHandle handle to the timer object
73 * @param[in] pstrAttrs Optional attributes, NULL for default
74 * @return Error code indicating sucess/failure
75 * @sa WILC_TimerAttrs
76 * @author syounan
77 * @date 16 Aug 2010
78 * @version 1.0
79 */
80WILC_ErrNo WILC_TimerDestroy(WILC_TimerHandle *pHandle,
81 tstrWILC_TimerAttrs *pstrAttrs);
82
83/*!
84 * @brief Starts a given timer
85 * @details This function will move the timer to the PENDING state until the
86 * given time expires (in msec) then the callback function will be
87 * executed (timer in EXECUTING state) after execution is dene the
88 * timer either goes to IDLE (if bPeriodicTimer==false) or
89 * PENDING with same timeout value (if bPeriodicTimer==true)
90 * @param[in] pHandle handle to the timer object
91 * @param[in] u32Timeout timeout value in msec after witch the callback
92 * function will be executed. Timeout value of 0 is not allowed for
93 * periodic timers
94 * @param[in] pstrAttrs Optional attributes, NULL for default,
95 * set bPeriodicTimer to run this timer as a periodic timer
96 * @return Error code indicating sucess/failure
97 * @sa WILC_TimerAttrs
98 * @author syounan
99 * @date 16 Aug 2010
100 * @version 1.0
101 */
102WILC_ErrNo WILC_TimerStart(WILC_TimerHandle *pHandle, u32 u32Timeout, void *pvArg,
103 tstrWILC_TimerAttrs *pstrAttrs);
104
105
106/*!
107 * @brief Stops a given timer
108 * @details This function will move the timer to the IDLE state cancelling
109 * any sheduled callback execution.
110 * if this function is called on a timer already in the IDLE state
111 * it will have no effect.
112 * if this function is called on a timer in EXECUTING state
113 * (callback has already started) it will wait until executing is
114 * done then move the timer to the IDLE state (which is trivial
115 * work if the timer is non periodic)
116 * @param[in] pHandle handle to the timer object
117 * @param[in] pstrAttrs Optional attributes, NULL for default,
118 * @return Error code indicating sucess/failure
119 * @sa WILC_TimerAttrs
120 * @author syounan
121 * @date 16 Aug 2010
122 * @version 1.0
123 */
124WILC_ErrNo WILC_TimerStop(WILC_TimerHandle *pHandle,
125 tstrWILC_TimerAttrs *pstrAttrs);
126
127
128
129#endif
diff --git a/drivers/staging/wilc1000/wilc_type.h b/drivers/staging/wilc1000/wilc_type.h
deleted file mode 100644
index 5f36e7f92cd1..000000000000
--- a/drivers/staging/wilc1000/wilc_type.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/* ////////////////////////////////////////////////////////////////////////// */
2/* */
3/* Copyright (c) Atmel Corporation. All rights reserved. */
4/* */
5/* Module Name: wilc_type.h */
6/* */
7/* */
8/* //////////////////////////////////////////////////////////////////////////// */
9#ifndef WILC_TYPE_H
10#define WILC_TYPE_H
11
12/********************************************
13 *
14 * Type Defines
15 *
16 ********************************************/
17#ifdef WIN32
18typedef char int8_t;
19typedef short int16_t;
20typedef long int32_t;
21typedef unsigned char uint8_t;
22typedef unsigned short uint16_t;
23typedef unsigned long uint32_t;
24#else
25#ifdef _linux_
26/*typedef unsigned char uint8_t;
27 * typedef unsigned short uint16_t;
28 * typedef unsigned long uint32_t;*/
29#include <stdint.h>
30#else
31#include "wilc_oswrapper.h"
32#endif
33#endif
34#endif
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 92064db9eb05..a6edc973f636 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -22,7 +22,6 @@
22#define IS_MGMT_STATUS_SUCCES 0x040 22#define IS_MGMT_STATUS_SUCCES 0x040
23#define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff) 23#define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
24 24
25extern void linux_wlan_free(void *vp);
26extern int linux_wlan_get_firmware(perInterface_wlan_t *p_nic); 25extern int linux_wlan_get_firmware(perInterface_wlan_t *p_nic);
27extern void linux_wlan_unlock(void *vp); 26extern void linux_wlan_unlock(void *vp);
28extern u16 Set_machw_change_vir_if(bool bValue); 27extern u16 Set_machw_change_vir_if(bool bValue);
@@ -33,9 +32,9 @@ extern int mac_close(struct net_device *ndev);
33tstrNetworkInfo astrLastScannedNtwrksShadow[MAX_NUM_SCANNED_NETWORKS_SHADOW]; 32tstrNetworkInfo astrLastScannedNtwrksShadow[MAX_NUM_SCANNED_NETWORKS_SHADOW];
34u32 u32LastScannedNtwrksCountShadow; 33u32 u32LastScannedNtwrksCountShadow;
35#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 34#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
36WILC_TimerHandle hDuringIpTimer; 35struct timer_list hDuringIpTimer;
37#endif 36#endif
38WILC_TimerHandle hAgingTimer; 37struct timer_list hAgingTimer;
39static u8 op_ifcs; 38static u8 op_ifcs;
40extern u8 u8ConnectedSSID[6]; 39extern u8 u8ConnectedSSID[6];
41 40
@@ -112,7 +111,7 @@ u8 u8P2P_oui[] = {0x50, 0x6f, 0x9A, 0x09};
112u8 u8P2Plocalrandom = 0x01; 111u8 u8P2Plocalrandom = 0x01;
113u8 u8P2Precvrandom = 0x00; 112u8 u8P2Precvrandom = 0x00;
114u8 u8P2P_vendorspec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03}; 113u8 u8P2P_vendorspec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03};
115bool bWilc_ie = false; 114bool bWilc_ie;
116#endif 115#endif
117 116
118static struct ieee80211_supported_band WILC_WFI_band_2ghz = { 117static struct ieee80211_supported_band WILC_WFI_band_2ghz = {
@@ -135,25 +134,23 @@ struct add_key_params g_add_ptk_key_params;
135struct wilc_wfi_key g_key_ptk_params; 134struct wilc_wfi_key g_key_ptk_params;
136struct wilc_wfi_wep_key g_key_wep_params; 135struct wilc_wfi_wep_key g_key_wep_params;
137u8 g_flushing_in_progress; 136u8 g_flushing_in_progress;
138bool g_ptk_keys_saved = false; 137bool g_ptk_keys_saved;
139bool g_gtk_keys_saved = false; 138bool g_gtk_keys_saved;
140bool g_wep_keys_saved = false; 139bool g_wep_keys_saved;
141 140
142#define AGING_TIME (9 * 1000) 141#define AGING_TIME (9 * 1000)
143#define duringIP_TIME 15000 142#define duringIP_TIME 15000
144 143
145void clear_shadow_scan(void *pUserVoid) 144void clear_shadow_scan(void *pUserVoid)
146{ 145{
147 struct WILC_WFI_priv *priv;
148 int i; 146 int i;
149 priv = (struct WILC_WFI_priv *)pUserVoid;
150 if (op_ifcs == 0) { 147 if (op_ifcs == 0) {
151 WILC_TimerDestroy(&hAgingTimer, NULL); 148 del_timer_sync(&hAgingTimer);
152 PRINT_INFO(CORECONFIG_DBG, "destroy aging timer\n"); 149 PRINT_INFO(CORECONFIG_DBG, "destroy aging timer\n");
153 150
154 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) { 151 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
155 if (astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs != NULL) { 152 if (astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs != NULL) {
156 WILC_FREE(astrLastScannedNtwrksShadow[i].pu8IEs); 153 kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
157 astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs = NULL; 154 astrLastScannedNtwrksShadow[u32LastScannedNtwrksCountShadow].pu8IEs = NULL;
158 } 155 }
159 156
@@ -204,7 +201,7 @@ void refresh_scan(void *pUserVoid, uint8_t all, bool bDirectScan)
204 channel = ieee80211_get_channel(wiphy, s32Freq); 201 channel = ieee80211_get_channel(wiphy, s32Freq);
205 202
206 rssi = get_rssi_avg(pstrNetworkInfo); 203 rssi = get_rssi_avg(pstrNetworkInfo);
207 if (WILC_memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7) || bDirectScan) { 204 if (memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7) || bDirectScan) {
208 bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo, 205 bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo,
209 pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs, 206 pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs,
210 (size_t)pstrNetworkInfo->u16IEsLen, (((s32)rssi) * 100), GFP_KERNEL); 207 (size_t)pstrNetworkInfo->u16IEsLen, (((s32)rssi) * 100), GFP_KERNEL);
@@ -219,9 +216,7 @@ void refresh_scan(void *pUserVoid, uint8_t all, bool bDirectScan)
219 216
220void reset_shadow_found(void *pUserVoid) 217void reset_shadow_found(void *pUserVoid)
221{ 218{
222 struct WILC_WFI_priv *priv;
223 int i; 219 int i;
224 priv = (struct WILC_WFI_priv *)pUserVoid;
225 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) { 220 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
226 astrLastScannedNtwrksShadow[i].u8Found = 0; 221 astrLastScannedNtwrksShadow[i].u8Found = 0;
227 222
@@ -230,28 +225,24 @@ void reset_shadow_found(void *pUserVoid)
230 225
231void update_scan_time(void *pUserVoid) 226void update_scan_time(void *pUserVoid)
232{ 227{
233 struct WILC_WFI_priv *priv;
234 int i; 228 int i;
235 priv = (struct WILC_WFI_priv *)pUserVoid;
236 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) { 229 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
237 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies; 230 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies;
238 } 231 }
239} 232}
240 233
241void remove_network_from_shadow(void *pUserVoid) 234static void remove_network_from_shadow(unsigned long arg)
242{ 235{
243 struct WILC_WFI_priv *priv;
244 unsigned long now = jiffies; 236 unsigned long now = jiffies;
245 int i, j; 237 int i, j;
246 238
247 priv = (struct WILC_WFI_priv *)pUserVoid;
248 239
249 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) { 240 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
250 if (time_after(now, astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan + (unsigned long)(SCAN_RESULT_EXPIRE))) { 241 if (time_after(now, astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan + (unsigned long)(SCAN_RESULT_EXPIRE))) {
251 PRINT_D(CFG80211_DBG, "Network expired in ScanShadow: %s \n", astrLastScannedNtwrksShadow[i].au8ssid); 242 PRINT_D(CFG80211_DBG, "Network expired in ScanShadow: %s\n", astrLastScannedNtwrksShadow[i].au8ssid);
252 243
253 if (astrLastScannedNtwrksShadow[i].pu8IEs != NULL) { 244 if (astrLastScannedNtwrksShadow[i].pu8IEs != NULL) {
254 WILC_FREE(astrLastScannedNtwrksShadow[i].pu8IEs); 245 kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
255 astrLastScannedNtwrksShadow[i].pu8IEs = NULL; 246 astrLastScannedNtwrksShadow[i].pu8IEs = NULL;
256 } 247 }
257 248
@@ -265,14 +256,16 @@ void remove_network_from_shadow(void *pUserVoid)
265 } 256 }
266 257
267 PRINT_D(CFG80211_DBG, "Number of cached networks: %d\n", u32LastScannedNtwrksCountShadow); 258 PRINT_D(CFG80211_DBG, "Number of cached networks: %d\n", u32LastScannedNtwrksCountShadow);
268 if (u32LastScannedNtwrksCountShadow != 0) 259 if (u32LastScannedNtwrksCountShadow != 0) {
269 WILC_TimerStart(&(hAgingTimer), AGING_TIME, pUserVoid, NULL); 260 hAgingTimer.data = arg;
270 else 261 mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME));
262 } else {
271 PRINT_D(CFG80211_DBG, "No need to restart Aging timer\n"); 263 PRINT_D(CFG80211_DBG, "No need to restart Aging timer\n");
264 }
272} 265}
273 266
274#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 267#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
275void clear_duringIP(void *pUserVoid) 268static void clear_duringIP(unsigned long arg)
276{ 269{
277 PRINT_D(GENERIC_DBG, "GO:IP Obtained , enable scan\n"); 270 PRINT_D(GENERIC_DBG, "GO:IP Obtained , enable scan\n");
278 g_obtainingIP = false; 271 g_obtainingIP = false;
@@ -281,19 +274,18 @@ void clear_duringIP(void *pUserVoid)
281 274
282int8_t is_network_in_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid) 275int8_t is_network_in_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid)
283{ 276{
284 struct WILC_WFI_priv *priv;
285 int8_t state = -1; 277 int8_t state = -1;
286 int i; 278 int i;
287 279
288 priv = (struct WILC_WFI_priv *)pUserVoid;
289 if (u32LastScannedNtwrksCountShadow == 0) { 280 if (u32LastScannedNtwrksCountShadow == 0) {
290 PRINT_D(CFG80211_DBG, "Starting Aging timer\n"); 281 PRINT_D(CFG80211_DBG, "Starting Aging timer\n");
291 WILC_TimerStart(&(hAgingTimer), AGING_TIME, pUserVoid, NULL); 282 hAgingTimer.data = (unsigned long)pUserVoid;
283 mod_timer(&hAgingTimer, jiffies + msecs_to_jiffies(AGING_TIME));
292 state = -1; 284 state = -1;
293 } else { 285 } else {
294 /* Linear search for now */ 286 /* Linear search for now */
295 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) { 287 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
296 if (WILC_memcmp(astrLastScannedNtwrksShadow[i].au8bssid, 288 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
297 pstrNetworkInfo->au8bssid, 6) == 0) { 289 pstrNetworkInfo->au8bssid, 6) == 0) {
298 state = i; 290 state = i;
299 break; 291 break;
@@ -305,11 +297,9 @@ int8_t is_network_in_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid)
305 297
306void add_network_to_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams) 298void add_network_to_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
307{ 299{
308 struct WILC_WFI_priv *priv;
309 int8_t ap_found = is_network_in_shadow(pstrNetworkInfo, pUserVoid); 300 int8_t ap_found = is_network_in_shadow(pstrNetworkInfo, pUserVoid);
310 uint32_t ap_index = 0; 301 uint32_t ap_index = 0;
311 uint8_t rssi_index = 0; 302 uint8_t rssi_index = 0;
312 priv = (struct WILC_WFI_priv *)pUserVoid;
313 303
314 if (u32LastScannedNtwrksCountShadow >= MAX_NUM_SCANNED_NETWORKS_SHADOW) { 304 if (u32LastScannedNtwrksCountShadow >= MAX_NUM_SCANNED_NETWORKS_SHADOW) {
315 PRINT_D(CFG80211_DBG, "Shadow network reached its maximum limit\n"); 305 PRINT_D(CFG80211_DBG, "Shadow network reached its maximum limit\n");
@@ -334,10 +324,10 @@ void add_network_to_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, vo
334 astrLastScannedNtwrksShadow[ap_index].u16CapInfo = pstrNetworkInfo->u16CapInfo; 324 astrLastScannedNtwrksShadow[ap_index].u16CapInfo = pstrNetworkInfo->u16CapInfo;
335 325
336 astrLastScannedNtwrksShadow[ap_index].u8SsidLen = pstrNetworkInfo->u8SsidLen; 326 astrLastScannedNtwrksShadow[ap_index].u8SsidLen = pstrNetworkInfo->u8SsidLen;
337 WILC_memcpy(astrLastScannedNtwrksShadow[ap_index].au8ssid, 327 memcpy(astrLastScannedNtwrksShadow[ap_index].au8ssid,
338 pstrNetworkInfo->au8ssid, pstrNetworkInfo->u8SsidLen); 328 pstrNetworkInfo->au8ssid, pstrNetworkInfo->u8SsidLen);
339 329
340 WILC_memcpy(astrLastScannedNtwrksShadow[ap_index].au8bssid, 330 memcpy(astrLastScannedNtwrksShadow[ap_index].au8bssid,
341 pstrNetworkInfo->au8bssid, ETH_ALEN); 331 pstrNetworkInfo->au8bssid, ETH_ALEN);
342 332
343 astrLastScannedNtwrksShadow[ap_index].u16BeaconPeriod = pstrNetworkInfo->u16BeaconPeriod; 333 astrLastScannedNtwrksShadow[ap_index].u16BeaconPeriod = pstrNetworkInfo->u16BeaconPeriod;
@@ -347,10 +337,10 @@ void add_network_to_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, vo
347 astrLastScannedNtwrksShadow[ap_index].u16IEsLen = pstrNetworkInfo->u16IEsLen; 337 astrLastScannedNtwrksShadow[ap_index].u16IEsLen = pstrNetworkInfo->u16IEsLen;
348 astrLastScannedNtwrksShadow[ap_index].u64Tsf = pstrNetworkInfo->u64Tsf; 338 astrLastScannedNtwrksShadow[ap_index].u64Tsf = pstrNetworkInfo->u64Tsf;
349 if (ap_found != -1) 339 if (ap_found != -1)
350 WILC_FREE(astrLastScannedNtwrksShadow[ap_index].pu8IEs); 340 kfree(astrLastScannedNtwrksShadow[ap_index].pu8IEs);
351 astrLastScannedNtwrksShadow[ap_index].pu8IEs = 341 astrLastScannedNtwrksShadow[ap_index].pu8IEs =
352 (u8 *)WILC_MALLOC(pstrNetworkInfo->u16IEsLen); /* will be deallocated by the WILC_WFI_CfgScan() function */ 342 WILC_MALLOC(pstrNetworkInfo->u16IEsLen); /* will be deallocated by the WILC_WFI_CfgScan() function */
353 WILC_memcpy(astrLastScannedNtwrksShadow[ap_index].pu8IEs, 343 memcpy(astrLastScannedNtwrksShadow[ap_index].pu8IEs,
354 pstrNetworkInfo->pu8IEs, pstrNetworkInfo->u16IEsLen); 344 pstrNetworkInfo->pu8IEs, pstrNetworkInfo->u16IEsLen);
355 345
356 astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScan = jiffies; 346 astrLastScannedNtwrksShadow[ap_index].u32TimeRcvdInScan = jiffies;
@@ -406,7 +396,7 @@ static void CfgScanResult(tenuScanEvent enuScanEvent, tstrNetworkInfo *pstrNetwo
406 WILC_NULLCHECK(s32Error, channel); 396 WILC_NULLCHECK(s32Error, channel);
407 397
408 PRINT_INFO(CFG80211_DBG, "Network Info:: CHANNEL Frequency: %d, RSSI: %d, CapabilityInfo: %d," 398 PRINT_INFO(CFG80211_DBG, "Network Info:: CHANNEL Frequency: %d, RSSI: %d, CapabilityInfo: %d,"
409 "BeaconPeriod: %d \n", channel->center_freq, (((s32)pstrNetworkInfo->s8rssi) * 100), 399 "BeaconPeriod: %d\n", channel->center_freq, (((s32)pstrNetworkInfo->s8rssi) * 100),
410 pstrNetworkInfo->u16CapInfo, pstrNetworkInfo->u16BeaconPeriod); 400 pstrNetworkInfo->u16CapInfo, pstrNetworkInfo->u16BeaconPeriod);
411 401
412 if (pstrNetworkInfo->bNewNetwork == true) { 402 if (pstrNetworkInfo->bNewNetwork == true) {
@@ -426,7 +416,7 @@ static void CfgScanResult(tenuScanEvent enuScanEvent, tstrNetworkInfo *pstrNetwo
426 416
427 /*P2P peers are sent to WPA supplicant and added to shadow table*/ 417 /*P2P peers are sent to WPA supplicant and added to shadow table*/
428 418
429 if (!(WILC_memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7))) { 419 if (!(memcmp("DIRECT-", pstrNetworkInfo->au8ssid, 7))) {
430 bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo, 420 bss = cfg80211_inform_bss(wiphy, channel, CFG80211_BSS_FTYPE_UNKNOWN, pstrNetworkInfo->au8bssid, pstrNetworkInfo->u64Tsf, pstrNetworkInfo->u16CapInfo,
431 pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs, 421 pstrNetworkInfo->u16BeaconPeriod, (const u8 *)pstrNetworkInfo->pu8IEs,
432 (size_t)pstrNetworkInfo->u16IEsLen, (((s32)pstrNetworkInfo->s8rssi) * 100), GFP_KERNEL); 422 (size_t)pstrNetworkInfo->u16IEsLen, (((s32)pstrNetworkInfo->s8rssi) * 100), GFP_KERNEL);
@@ -441,8 +431,8 @@ static void CfgScanResult(tenuScanEvent enuScanEvent, tstrNetworkInfo *pstrNetwo
441 u32 i; 431 u32 i;
442 /* So this network is discovered before, we'll just update its RSSI */ 432 /* So this network is discovered before, we'll just update its RSSI */
443 for (i = 0; i < priv->u32RcvdChCount; i++) { 433 for (i = 0; i < priv->u32RcvdChCount; i++) {
444 if (WILC_memcmp(astrLastScannedNtwrksShadow[i].au8bssid, pstrNetworkInfo->au8bssid, 6) == 0) { 434 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid, pstrNetworkInfo->au8bssid, 6) == 0) {
445 PRINT_D(CFG80211_DBG, "Update RSSI of %s \n", astrLastScannedNtwrksShadow[i].au8ssid); 435 PRINT_D(CFG80211_DBG, "Update RSSI of %s\n", astrLastScannedNtwrksShadow[i].au8ssid);
446 436
447 astrLastScannedNtwrksShadow[i].s8rssi = pstrNetworkInfo->s8rssi; 437 astrLastScannedNtwrksShadow[i].s8rssi = pstrNetworkInfo->s8rssi;
448 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies; 438 astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies;
@@ -452,15 +442,14 @@ static void CfgScanResult(tenuScanEvent enuScanEvent, tstrNetworkInfo *pstrNetwo
452 } 442 }
453 } 443 }
454 } else if (enuScanEvent == SCAN_EVENT_DONE) { 444 } else if (enuScanEvent == SCAN_EVENT_DONE) {
455 PRINT_D(CFG80211_DBG, "Scan Done[%p] \n", priv->dev); 445 PRINT_D(CFG80211_DBG, "Scan Done[%p]\n", priv->dev);
456 PRINT_D(CFG80211_DBG, "Refreshing Scan ... \n"); 446 PRINT_D(CFG80211_DBG, "Refreshing Scan ...\n");
457 refresh_scan(priv, 1, false); 447 refresh_scan(priv, 1, false);
458 448
459 if (priv->u32RcvdChCount > 0) { 449 if (priv->u32RcvdChCount > 0)
460 PRINT_D(CFG80211_DBG, "%d Network(s) found \n", priv->u32RcvdChCount); 450 PRINT_D(CFG80211_DBG, "%d Network(s) found\n", priv->u32RcvdChCount);
461 } else { 451 else
462 PRINT_D(CFG80211_DBG, "No networks found \n"); 452 PRINT_D(CFG80211_DBG, "No networks found\n");
463 }
464 453
465 down(&(priv->hSemScanReq)); 454 down(&(priv->hSemScanReq));
466 455
@@ -477,7 +466,7 @@ static void CfgScanResult(tenuScanEvent enuScanEvent, tstrNetworkInfo *pstrNetwo
477 else if (enuScanEvent == SCAN_EVENT_ABORTED) { 466 else if (enuScanEvent == SCAN_EVENT_ABORTED) {
478 down(&(priv->hSemScanReq)); 467 down(&(priv->hSemScanReq));
479 468
480 PRINT_D(CFG80211_DBG, "Scan Aborted \n"); 469 PRINT_D(CFG80211_DBG, "Scan Aborted\n");
481 if (priv->pstrScanReq != NULL) { 470 if (priv->pstrScanReq != NULL) {
482 471
483 update_scan_time(priv); 472 update_scan_time(priv);
@@ -515,7 +504,7 @@ int WILC_WFI_Set_PMKSA(u8 *bssid, struct WILC_WFI_priv *priv)
515 504
516 for (i = 0; i < priv->pmkid_list.numpmkid; i++) { 505 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
517 506
518 if (!WILC_memcmp(bssid, priv->pmkid_list.pmkidlist[i].bssid, 507 if (!memcmp(bssid, priv->pmkid_list.pmkidlist[i].bssid,
519 ETH_ALEN)) { 508 ETH_ALEN)) {
520 PRINT_D(CFG80211_DBG, "PMKID successful comparison"); 509 PRINT_D(CFG80211_DBG, "PMKID successful comparison");
521 510
@@ -586,7 +575,7 @@ static void CfgConnectResult(tenuConnDisconnEvent enuConnDisconnEvent,
586 * = SUCCESSFUL_STATUSCODE, while mac status is MAC_DISCONNECTED (which means something wrong happened) */ 575 * = SUCCESSFUL_STATUSCODE, while mac status is MAC_DISCONNECTED (which means something wrong happened) */
587 u16ConnectStatus = WLAN_STATUS_UNSPECIFIED_FAILURE; 576 u16ConnectStatus = WLAN_STATUS_UNSPECIFIED_FAILURE;
588 linux_wlan_set_bssid(priv->dev, NullBssid); 577 linux_wlan_set_bssid(priv->dev, NullBssid);
589 WILC_memset(u8ConnectedSSID, 0, ETH_ALEN); 578 memset(u8ConnectedSSID, 0, ETH_ALEN);
590 579
591 /*BugID_5457*/ 580 /*BugID_5457*/
592 /*Invalidate u8WLANChannel value on wlan0 disconnect*/ 581 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
@@ -595,7 +584,7 @@ static void CfgConnectResult(tenuConnDisconnEvent enuConnDisconnEvent,
595 u8WLANChannel = INVALID_CHANNEL; 584 u8WLANChannel = INVALID_CHANNEL;
596 #endif 585 #endif
597 586
598 PRINT_ER("Unspecified failure: Connection status %d : MAC status = %d \n", u16ConnectStatus, u8MacStatus); 587 PRINT_ER("Unspecified failure: Connection status %d : MAC status = %d\n", u16ConnectStatus, u8MacStatus);
599 } 588 }
600 589
601 if (u16ConnectStatus == WLAN_STATUS_SUCCESS) { 590 if (u16ConnectStatus == WLAN_STATUS_SUCCESS) {
@@ -604,14 +593,14 @@ static void CfgConnectResult(tenuConnDisconnEvent enuConnDisconnEvent,
604 593
605 PRINT_INFO(CFG80211_DBG, "Connection Successful:: BSSID: %x%x%x%x%x%x\n", pstrConnectInfo->au8bssid[0], 594 PRINT_INFO(CFG80211_DBG, "Connection Successful:: BSSID: %x%x%x%x%x%x\n", pstrConnectInfo->au8bssid[0],
606 pstrConnectInfo->au8bssid[1], pstrConnectInfo->au8bssid[2], pstrConnectInfo->au8bssid[3], pstrConnectInfo->au8bssid[4], pstrConnectInfo->au8bssid[5]); 595 pstrConnectInfo->au8bssid[1], pstrConnectInfo->au8bssid[2], pstrConnectInfo->au8bssid[3], pstrConnectInfo->au8bssid[4], pstrConnectInfo->au8bssid[5]);
607 WILC_memcpy(priv->au8AssociatedBss, pstrConnectInfo->au8bssid, ETH_ALEN); 596 memcpy(priv->au8AssociatedBss, pstrConnectInfo->au8bssid, ETH_ALEN);
608 597
609 /* BugID_4209: if this network has expired in the scan results in the above nl80211 layer, refresh them here by calling 598 /* BugID_4209: if this network has expired in the scan results in the above nl80211 layer, refresh them here by calling
610 * cfg80211_inform_bss() with the last Scan results before calling cfg80211_connect_result() to avoid 599 * cfg80211_inform_bss() with the last Scan results before calling cfg80211_connect_result() to avoid
611 * Linux kernel warning generated at the nl80211 layer */ 600 * Linux kernel warning generated at the nl80211 layer */
612 601
613 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) { 602 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
614 if (WILC_memcmp(astrLastScannedNtwrksShadow[i].au8bssid, 603 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
615 pstrConnectInfo->au8bssid, ETH_ALEN) == 0) { 604 pstrConnectInfo->au8bssid, ETH_ALEN) == 0) {
616 unsigned long now = jiffies; 605 unsigned long now = jiffies;
617 606
@@ -652,9 +641,9 @@ static void CfgConnectResult(tenuConnDisconnEvent enuConnDisconnEvent,
652 u8P2Plocalrandom = 0x01; 641 u8P2Plocalrandom = 0x01;
653 u8P2Precvrandom = 0x00; 642 u8P2Precvrandom = 0x00;
654 bWilc_ie = false; 643 bWilc_ie = false;
655 WILC_memset(priv->au8AssociatedBss, 0, ETH_ALEN); 644 memset(priv->au8AssociatedBss, 0, ETH_ALEN);
656 linux_wlan_set_bssid(priv->dev, NullBssid); 645 linux_wlan_set_bssid(priv->dev, NullBssid);
657 WILC_memset(u8ConnectedSSID, 0, ETH_ALEN); 646 memset(u8ConnectedSSID, 0, ETH_ALEN);
658 647
659 /*BugID_5457*/ 648 /*BugID_5457*/
660 /*Invalidate u8WLANChannel value on wlan0 disconnect*/ 649 /*Invalidate u8WLANChannel value on wlan0 disconnect*/
@@ -675,7 +664,8 @@ static void CfgConnectResult(tenuConnDisconnEvent enuConnDisconnEvent,
675 pstrDisconnectNotifInfo->u16reason = 1; 664 pstrDisconnectNotifInfo->u16reason = 1;
676 } 665 }
677 cfg80211_disconnected(dev, pstrDisconnectNotifInfo->u16reason, pstrDisconnectNotifInfo->ie, 666 cfg80211_disconnected(dev, pstrDisconnectNotifInfo->u16reason, pstrDisconnectNotifInfo->ie,
678 pstrDisconnectNotifInfo->ie_len, GFP_KERNEL); 667 pstrDisconnectNotifInfo->ie_len, false,
668 GFP_KERNEL);
679 669
680 } 670 }
681 671
@@ -747,7 +737,7 @@ static int WILC_WFI_CfgScan(struct wiphy *wiphy, struct cfg80211_scan_request *r
747 737
748 priv->u32RcvdChCount = 0; 738 priv->u32RcvdChCount = 0;
749 739
750 host_int_set_wfi_drv_handler((u32)priv->hWILCWFIDrv); 740 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
751 741
752 742
753 reset_shadow_found(priv); 743 reset_shadow_found(priv);
@@ -777,20 +767,20 @@ static int WILC_WFI_CfgScan(struct wiphy *wiphy, struct cfg80211_scan_request *r
777 767
778 if (request->ssids[i].ssid != NULL && request->ssids[i].ssid_len != 0) { 768 if (request->ssids[i].ssid != NULL && request->ssids[i].ssid_len != 0) {
779 strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid = WILC_MALLOC(request->ssids[i].ssid_len); 769 strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid = WILC_MALLOC(request->ssids[i].ssid_len);
780 WILC_memcpy(strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, request->ssids[i].ssid, request->ssids[i].ssid_len); 770 memcpy(strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, request->ssids[i].ssid, request->ssids[i].ssid_len);
781 strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen = request->ssids[i].ssid_len; 771 strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen = request->ssids[i].ssid_len;
782 } else { 772 } else {
783 PRINT_D(CFG80211_DBG, "Received one NULL SSID \n"); 773 PRINT_D(CFG80211_DBG, "Received one NULL SSID\n");
784 strHiddenNetwork.u8ssidnum -= 1; 774 strHiddenNetwork.u8ssidnum -= 1;
785 } 775 }
786 } 776 }
787 PRINT_D(CFG80211_DBG, "Trigger Scan Request \n"); 777 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
788 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN, 778 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
789 au8ScanChanList, request->n_channels, 779 au8ScanChanList, request->n_channels,
790 (const u8 *)request->ie, request->ie_len, 780 (const u8 *)request->ie, request->ie_len,
791 CfgScanResult, (void *)priv, &strHiddenNetwork); 781 CfgScanResult, (void *)priv, &strHiddenNetwork);
792 } else { 782 } else {
793 PRINT_D(CFG80211_DBG, "Trigger Scan Request \n"); 783 PRINT_D(CFG80211_DBG, "Trigger Scan Request\n");
794 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN, 784 s32Error = host_int_scan(priv->hWILCWFIDrv, USER_SCAN, ACTIVE_SCAN,
795 au8ScanChanList, request->n_channels, 785 au8ScanChanList, request->n_channels,
796 (const u8 *)request->ie, request->ie_len, 786 (const u8 *)request->ie, request->ie_len,
@@ -799,7 +789,7 @@ static int WILC_WFI_CfgScan(struct wiphy *wiphy, struct cfg80211_scan_request *r
799 789
800 } else { 790 } else {
801 PRINT_ER("Requested num of scanned channels is greater than the max, supported" 791 PRINT_ER("Requested num of scanned channels is greater than the max, supported"
802 " channels \n"); 792 " channels\n");
803 } 793 }
804 794
805 if (s32Error != WILC_SUCCESS) { 795 if (s32Error != WILC_SUCCESS) {
@@ -842,21 +832,21 @@ static int WILC_WFI_CfgConnect(struct wiphy *wiphy, struct net_device *dev,
842 priv = wiphy_priv(wiphy); 832 priv = wiphy_priv(wiphy);
843 pstrWFIDrv = (tstrWILC_WFIDrv *)(priv->hWILCWFIDrv); 833 pstrWFIDrv = (tstrWILC_WFIDrv *)(priv->hWILCWFIDrv);
844 834
845 host_int_set_wfi_drv_handler((u32)priv->hWILCWFIDrv); 835 host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
846 836
847 PRINT_D(CFG80211_DBG, "Connecting to SSID [%s] on netdev [%p] host if [%p]\n", sme->ssid, dev, priv->hWILCWFIDrv); 837 PRINT_D(CFG80211_DBG, "Connecting to SSID [%s] on netdev [%p] host if [%p]\n", sme->ssid, dev, priv->hWILCWFIDrv);
848 #ifdef WILC_P2P 838 #ifdef WILC_P2P
849 if (!(WILC_strncmp(sme->ssid, "DIRECT-", 7))) { 839 if (!(strncmp(sme->ssid, "DIRECT-", 7))) {
850 PRINT_D(CFG80211_DBG, "Connected to Direct network,OBSS disabled\n"); 840 PRINT_D(CFG80211_DBG, "Connected to Direct network,OBSS disabled\n");
851 pstrWFIDrv->u8P2PConnect = 1; 841 pstrWFIDrv->u8P2PConnect = 1;
852 } else 842 } else
853 pstrWFIDrv->u8P2PConnect = 0; 843 pstrWFIDrv->u8P2PConnect = 0;
854 #endif 844 #endif
855 PRINT_INFO(CFG80211_DBG, "Required SSID = %s\n , AuthType = %d \n", sme->ssid, sme->auth_type); 845 PRINT_INFO(CFG80211_DBG, "Required SSID = %s\n , AuthType = %d\n", sme->ssid, sme->auth_type);
856 846
857 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) { 847 for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
858 if ((sme->ssid_len == astrLastScannedNtwrksShadow[i].u8SsidLen) && 848 if ((sme->ssid_len == astrLastScannedNtwrksShadow[i].u8SsidLen) &&
859 WILC_memcmp(astrLastScannedNtwrksShadow[i].au8ssid, 849 memcmp(astrLastScannedNtwrksShadow[i].au8ssid,
860 sme->ssid, 850 sme->ssid,
861 sme->ssid_len) == 0) { 851 sme->ssid_len) == 0) {
862 PRINT_INFO(CFG80211_DBG, "Network with required SSID is found %s\n", sme->ssid); 852 PRINT_INFO(CFG80211_DBG, "Network with required SSID is found %s\n", sme->ssid);
@@ -868,7 +858,7 @@ static int WILC_WFI_CfgConnect(struct wiphy *wiphy, struct net_device *dev,
868 } else { 858 } else {
869 /* BSSID is also passed from the user, so decision of matching 859 /* BSSID is also passed from the user, so decision of matching
870 * should consider also this passed BSSID */ 860 * should consider also this passed BSSID */
871 if (WILC_memcmp(astrLastScannedNtwrksShadow[i].au8bssid, 861 if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
872 sme->bssid, 862 sme->bssid,
873 ETH_ALEN) == 0) { 863 ETH_ALEN) == 0) {
874 PRINT_INFO(CFG80211_DBG, "BSSID is passed from the user and matched\n"); 864 PRINT_INFO(CFG80211_DBG, "BSSID is passed from the user and matched\n");
@@ -898,8 +888,8 @@ static int WILC_WFI_CfgConnect(struct wiphy *wiphy, struct net_device *dev,
898 } 888 }
899 889
900 priv->WILC_WFI_wep_default = 0; 890 priv->WILC_WFI_wep_default = 0;
901 WILC_memset(priv->WILC_WFI_wep_key, 0, sizeof(priv->WILC_WFI_wep_key)); 891 memset(priv->WILC_WFI_wep_key, 0, sizeof(priv->WILC_WFI_wep_key));
902 WILC_memset(priv->WILC_WFI_wep_key_len, 0, sizeof(priv->WILC_WFI_wep_key_len)); 892 memset(priv->WILC_WFI_wep_key_len, 0, sizeof(priv->WILC_WFI_wep_key_len));
903 893
904 PRINT_INFO(CFG80211_DBG, "sme->crypto.wpa_versions=%x\n", sme->crypto.wpa_versions); 894 PRINT_INFO(CFG80211_DBG, "sme->crypto.wpa_versions=%x\n", sme->crypto.wpa_versions);
905 PRINT_INFO(CFG80211_DBG, "sme->crypto.cipher_group=%x\n", sme->crypto.cipher_group); 895 PRINT_INFO(CFG80211_DBG, "sme->crypto.cipher_group=%x\n", sme->crypto.cipher_group);
@@ -928,7 +918,7 @@ static int WILC_WFI_CfgConnect(struct wiphy *wiphy, struct net_device *dev,
928 } 918 }
929 priv->WILC_WFI_wep_default = sme->key_idx; 919 priv->WILC_WFI_wep_default = sme->key_idx;
930 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len; 920 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
931 WILC_memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len); 921 memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
932 922
933 /*BugID_5137*/ 923 /*BugID_5137*/
934 g_key_wep_params.key_len = sme->key_len; 924 g_key_wep_params.key_len = sme->key_len;
@@ -946,7 +936,7 @@ static int WILC_WFI_CfgConnect(struct wiphy *wiphy, struct net_device *dev,
946 936
947 priv->WILC_WFI_wep_default = sme->key_idx; 937 priv->WILC_WFI_wep_default = sme->key_idx;
948 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len; 938 priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
949 WILC_memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len); 939 memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
950 940
951 /*BugID_5137*/ 941 /*BugID_5137*/
952 g_key_wep_params.key_len = sme->key_len; 942 g_key_wep_params.key_len = sme->key_len;
@@ -1057,7 +1047,7 @@ static int WILC_WFI_CfgConnect(struct wiphy *wiphy, struct net_device *dev,
1057 tenuAuth_type, pstrNetworkInfo->u8channel, 1047 tenuAuth_type, pstrNetworkInfo->u8channel,
1058 pstrNetworkInfo->pJoinParams); 1048 pstrNetworkInfo->pJoinParams);
1059 if (s32Error != WILC_SUCCESS) { 1049 if (s32Error != WILC_SUCCESS) {
1060 PRINT_ER("host_int_set_join_req(): Error(%d) \n", s32Error); 1050 PRINT_ER("host_int_set_join_req(): Error(%d)\n", s32Error);
1061 s32Error = -ENOENT; 1051 s32Error = -ENOENT;
1062 goto done; 1052 goto done;
1063 } 1053 }
@@ -1162,7 +1152,7 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
1162 1152
1163 priv->WILC_WFI_wep_default = key_index; 1153 priv->WILC_WFI_wep_default = key_index;
1164 priv->WILC_WFI_wep_key_len[key_index] = params->key_len; 1154 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
1165 WILC_memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len); 1155 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
1166 1156
1167 PRINT_D(CFG80211_DBG, "Adding AP WEP Default key Idx = %d\n", key_index); 1157 PRINT_D(CFG80211_DBG, "Adding AP WEP Default key Idx = %d\n", key_index);
1168 PRINT_D(CFG80211_DBG, "Adding AP WEP Key len= %d\n", params->key_len); 1158 PRINT_D(CFG80211_DBG, "Adding AP WEP Key len= %d\n", params->key_len);
@@ -1181,10 +1171,10 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
1181 break; 1171 break;
1182 } 1172 }
1183 #endif 1173 #endif
1184 if (WILC_memcmp(params->key, priv->WILC_WFI_wep_key[key_index], params->key_len)) { 1174 if (memcmp(params->key, priv->WILC_WFI_wep_key[key_index], params->key_len)) {
1185 priv->WILC_WFI_wep_default = key_index; 1175 priv->WILC_WFI_wep_default = key_index;
1186 priv->WILC_WFI_wep_key_len[key_index] = params->key_len; 1176 priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
1187 WILC_memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len); 1177 memcpy(priv->WILC_WFI_wep_key[key_index], params->key, params->key_len);
1188 1178
1189 PRINT_D(CFG80211_DBG, "Adding WEP Default key Idx = %d\n", key_index); 1179 PRINT_D(CFG80211_DBG, "Adding WEP Default key Idx = %d\n", key_index);
1190 PRINT_D(CFG80211_DBG, "Adding WEP Key length = %d\n", params->key_len); 1180 PRINT_D(CFG80211_DBG, "Adding WEP Key length = %d\n", params->key_len);
@@ -1203,21 +1193,20 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
1203 if (priv->wdev->iftype == NL80211_IFTYPE_AP || priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) { 1193 if (priv->wdev->iftype == NL80211_IFTYPE_AP || priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) {
1204 1194
1205 if (priv->wilc_gtk[key_index] == NULL) { 1195 if (priv->wilc_gtk[key_index] == NULL) {
1206 priv->wilc_gtk[key_index] = (struct wilc_wfi_key *)WILC_MALLOC(sizeof(struct wilc_wfi_key)); 1196 priv->wilc_gtk[key_index] = WILC_MALLOC(sizeof(struct wilc_wfi_key));
1207 priv->wilc_gtk[key_index]->key = NULL; 1197 priv->wilc_gtk[key_index]->key = NULL;
1208 priv->wilc_gtk[key_index]->seq = NULL; 1198 priv->wilc_gtk[key_index]->seq = NULL;
1209 1199
1210 } 1200 }
1211 if (priv->wilc_ptk[key_index] == NULL) { 1201 if (priv->wilc_ptk[key_index] == NULL) {
1212 priv->wilc_ptk[key_index] = (struct wilc_wfi_key *)WILC_MALLOC(sizeof(struct wilc_wfi_key)); 1202 priv->wilc_ptk[key_index] = WILC_MALLOC(sizeof(struct wilc_wfi_key));
1213 priv->wilc_ptk[key_index]->key = NULL; 1203 priv->wilc_ptk[key_index]->key = NULL;
1214 priv->wilc_ptk[key_index]->seq = NULL; 1204 priv->wilc_ptk[key_index]->seq = NULL;
1215 } 1205 }
1216 1206
1217 1207
1218 1208
1219 if (!pairwise) 1209 if (!pairwise) {
1220 {
1221 if (params->cipher == WLAN_CIPHER_SUITE_TKIP) 1210 if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1222 u8gmode = ENCRYPT_ENABLED | WPA | TKIP; 1211 u8gmode = ENCRYPT_ENABLED | WPA | TKIP;
1223 else 1212 else
@@ -1233,18 +1222,18 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
1233 } 1222 }
1234 /* if there has been previous allocation for the same index through its key, free that memory and allocate again*/ 1223 /* if there has been previous allocation for the same index through its key, free that memory and allocate again*/
1235 if (priv->wilc_gtk[key_index]->key) 1224 if (priv->wilc_gtk[key_index]->key)
1236 WILC_FREE(priv->wilc_gtk[key_index]->key); 1225 kfree(priv->wilc_gtk[key_index]->key);
1237 1226
1238 priv->wilc_gtk[key_index]->key = (u8 *)WILC_MALLOC(params->key_len); 1227 priv->wilc_gtk[key_index]->key = WILC_MALLOC(params->key_len);
1239 WILC_memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len); 1228 memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len);
1240 1229
1241 /* if there has been previous allocation for the same index through its seq, free that memory and allocate again*/ 1230 /* if there has been previous allocation for the same index through its seq, free that memory and allocate again*/
1242 if (priv->wilc_gtk[key_index]->seq) 1231 if (priv->wilc_gtk[key_index]->seq)
1243 WILC_FREE(priv->wilc_gtk[key_index]->seq); 1232 kfree(priv->wilc_gtk[key_index]->seq);
1244 1233
1245 if ((params->seq_len) > 0) { 1234 if ((params->seq_len) > 0) {
1246 priv->wilc_gtk[key_index]->seq = (u8 *)WILC_MALLOC(params->seq_len); 1235 priv->wilc_gtk[key_index]->seq = WILC_MALLOC(params->seq_len);
1247 WILC_memcpy(priv->wilc_gtk[key_index]->seq, params->seq, params->seq_len); 1236 memcpy(priv->wilc_gtk[key_index]->seq, params->seq, params->seq_len);
1248 } 1237 }
1249 1238
1250 priv->wilc_gtk[key_index]->cipher = params->cipher; 1239 priv->wilc_gtk[key_index]->cipher = params->cipher;
@@ -1279,15 +1268,15 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
1279 } 1268 }
1280 1269
1281 if (priv->wilc_ptk[key_index]->key) 1270 if (priv->wilc_ptk[key_index]->key)
1282 WILC_FREE(priv->wilc_ptk[key_index]->key); 1271 kfree(priv->wilc_ptk[key_index]->key);
1283 1272
1284 priv->wilc_ptk[key_index]->key = (u8 *)WILC_MALLOC(params->key_len); 1273 priv->wilc_ptk[key_index]->key = WILC_MALLOC(params->key_len);
1285 1274
1286 if (priv->wilc_ptk[key_index]->seq) 1275 if (priv->wilc_ptk[key_index]->seq)
1287 WILC_FREE(priv->wilc_ptk[key_index]->seq); 1276 kfree(priv->wilc_ptk[key_index]->seq);
1288 1277
1289 if ((params->seq_len) > 0) 1278 if ((params->seq_len) > 0)
1290 priv->wilc_ptk[key_index]->seq = (u8 *)WILC_MALLOC(params->seq_len); 1279 priv->wilc_ptk[key_index]->seq = WILC_MALLOC(params->seq_len);
1291 1280
1292 if (INFO) { 1281 if (INFO) {
1293 for (i = 0; i < params->key_len; i++) 1282 for (i = 0; i < params->key_len; i++)
@@ -1297,10 +1286,10 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
1297 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]); 1286 PRINT_INFO(CFG80211_DBG, "Adding group seq value[%d] = %x\n", i, params->seq[i]);
1298 } 1287 }
1299 1288
1300 WILC_memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len); 1289 memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
1301 1290
1302 if ((params->seq_len) > 0) 1291 if ((params->seq_len) > 0)
1303 WILC_memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len); 1292 memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len);
1304 1293
1305 priv->wilc_ptk[key_index]->cipher = params->cipher; 1294 priv->wilc_ptk[key_index]->cipher = params->cipher;
1306 priv->wilc_ptk[key_index]->key_len = params->key_len; 1295 priv->wilc_ptk[key_index]->key_len = params->key_len;
@@ -1315,8 +1304,7 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
1315 1304
1316 { 1305 {
1317 u8mode = 0; 1306 u8mode = 0;
1318 if (!pairwise) 1307 if (!pairwise) {
1319 {
1320 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) { 1308 if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) {
1321 /* swap the tx mic by rx mic */ 1309 /* swap the tx mic by rx mic */
1322 pu8RxMic = params->key + 24; 1310 pu8RxMic = params->key + 24;
@@ -1437,7 +1425,7 @@ static int WILC_WFI_del_key(struct wiphy *wiphy, struct net_device *netdev,
1437 1425
1438 /*Delete saved WEP keys params, if any*/ 1426 /*Delete saved WEP keys params, if any*/
1439 if (g_key_wep_params.key != NULL) { 1427 if (g_key_wep_params.key != NULL) {
1440 WILC_FREE(g_key_wep_params.key); 1428 kfree(g_key_wep_params.key);
1441 g_key_wep_params.key = NULL; 1429 g_key_wep_params.key = NULL;
1442 } 1430 }
1443 1431
@@ -1448,16 +1436,16 @@ static int WILC_WFI_del_key(struct wiphy *wiphy, struct net_device *netdev,
1448 1436
1449 if (priv->wilc_gtk[key_index]->key != NULL) { 1437 if (priv->wilc_gtk[key_index]->key != NULL) {
1450 1438
1451 WILC_FREE(priv->wilc_gtk[key_index]->key); 1439 kfree(priv->wilc_gtk[key_index]->key);
1452 priv->wilc_gtk[key_index]->key = NULL; 1440 priv->wilc_gtk[key_index]->key = NULL;
1453 } 1441 }
1454 if (priv->wilc_gtk[key_index]->seq) { 1442 if (priv->wilc_gtk[key_index]->seq) {
1455 1443
1456 WILC_FREE(priv->wilc_gtk[key_index]->seq); 1444 kfree(priv->wilc_gtk[key_index]->seq);
1457 priv->wilc_gtk[key_index]->seq = NULL; 1445 priv->wilc_gtk[key_index]->seq = NULL;
1458 } 1446 }
1459 1447
1460 WILC_FREE(priv->wilc_gtk[key_index]); 1448 kfree(priv->wilc_gtk[key_index]);
1461 priv->wilc_gtk[key_index] = NULL; 1449 priv->wilc_gtk[key_index] = NULL;
1462 1450
1463 } 1451 }
@@ -1466,35 +1454,35 @@ static int WILC_WFI_del_key(struct wiphy *wiphy, struct net_device *netdev,
1466 1454
1467 if (priv->wilc_ptk[key_index]->key) { 1455 if (priv->wilc_ptk[key_index]->key) {
1468 1456
1469 WILC_FREE(priv->wilc_ptk[key_index]->key); 1457 kfree(priv->wilc_ptk[key_index]->key);
1470 priv->wilc_ptk[key_index]->key = NULL; 1458 priv->wilc_ptk[key_index]->key = NULL;
1471 } 1459 }
1472 if (priv->wilc_ptk[key_index]->seq) { 1460 if (priv->wilc_ptk[key_index]->seq) {
1473 1461
1474 WILC_FREE(priv->wilc_ptk[key_index]->seq); 1462 kfree(priv->wilc_ptk[key_index]->seq);
1475 priv->wilc_ptk[key_index]->seq = NULL; 1463 priv->wilc_ptk[key_index]->seq = NULL;
1476 } 1464 }
1477 WILC_FREE(priv->wilc_ptk[key_index]); 1465 kfree(priv->wilc_ptk[key_index]);
1478 priv->wilc_ptk[key_index] = NULL; 1466 priv->wilc_ptk[key_index] = NULL;
1479 } 1467 }
1480 #endif 1468 #endif
1481 1469
1482 /*Delete saved PTK and GTK keys params, if any*/ 1470 /*Delete saved PTK and GTK keys params, if any*/
1483 if (g_key_ptk_params.key != NULL) { 1471 if (g_key_ptk_params.key != NULL) {
1484 WILC_FREE(g_key_ptk_params.key); 1472 kfree(g_key_ptk_params.key);
1485 g_key_ptk_params.key = NULL; 1473 g_key_ptk_params.key = NULL;
1486 } 1474 }
1487 if (g_key_ptk_params.seq != NULL) { 1475 if (g_key_ptk_params.seq != NULL) {
1488 WILC_FREE(g_key_ptk_params.seq); 1476 kfree(g_key_ptk_params.seq);
1489 g_key_ptk_params.seq = NULL; 1477 g_key_ptk_params.seq = NULL;
1490 } 1478 }
1491 1479
1492 if (g_key_gtk_params.key != NULL) { 1480 if (g_key_gtk_params.key != NULL) {
1493 WILC_FREE(g_key_gtk_params.key); 1481 kfree(g_key_gtk_params.key);
1494 g_key_gtk_params.key = NULL; 1482 g_key_gtk_params.key = NULL;
1495 } 1483 }
1496 if (g_key_gtk_params.seq != NULL) { 1484 if (g_key_gtk_params.seq != NULL) {
1497 WILC_FREE(g_key_gtk_params.seq); 1485 kfree(g_key_gtk_params.seq);
1498 g_key_gtk_params.seq = NULL; 1486 g_key_gtk_params.seq = NULL;
1499 } 1487 }
1500 1488
@@ -1503,7 +1491,7 @@ static int WILC_WFI_del_key(struct wiphy *wiphy, struct net_device *netdev,
1503 } 1491 }
1504 1492
1505 if (key_index >= 0 && key_index <= 3) { 1493 if (key_index >= 0 && key_index <= 3) {
1506 WILC_memset(priv->WILC_WFI_wep_key[key_index], 0, priv->WILC_WFI_wep_key_len[key_index]); 1494 memset(priv->WILC_WFI_wep_key[key_index], 0, priv->WILC_WFI_wep_key_len[key_index]);
1507 priv->WILC_WFI_wep_key_len[key_index] = 0; 1495 priv->WILC_WFI_wep_key_len[key_index] = 0;
1508 1496
1509 PRINT_D(CFG80211_DBG, "Removing WEP key with index = %d\n", key_index); 1497 PRINT_D(CFG80211_DBG, "Removing WEP key with index = %d\n", key_index);
@@ -1588,7 +1576,7 @@ static int WILC_WFI_set_default_key(struct wiphy *wiphy, struct net_device *netd
1588 1576
1589 priv = wiphy_priv(wiphy); 1577 priv = wiphy_priv(wiphy);
1590 1578
1591 PRINT_D(CFG80211_DBG, "Setting default key with idx = %d \n", key_index); 1579 PRINT_D(CFG80211_DBG, "Setting default key with idx = %d\n", key_index);
1592 1580
1593 if (key_index != priv->WILC_WFI_wep_default) { 1581 if (key_index != priv->WILC_WFI_wep_default) {
1594 1582
@@ -1633,7 +1621,6 @@ static int WILC_WFI_dump_survey(struct wiphy *wiphy, struct net_device *netdev,
1633 * @version 1.0 1621 * @version 1.0
1634 */ 1622 */
1635 1623
1636extern uint32_t Statisitcs_totalAcks, Statisitcs_DroppedAcks;
1637static int WILC_WFI_get_station(struct wiphy *wiphy, struct net_device *dev, 1624static int WILC_WFI_get_station(struct wiphy *wiphy, struct net_device *dev,
1638 const u8 *mac, struct station_info *sinfo) 1625 const u8 *mac, struct station_info *sinfo)
1639{ 1626{
@@ -1689,7 +1676,7 @@ static int WILC_WFI_get_station(struct wiphy *wiphy, struct net_device *dev,
1689 * kernel version 3.0.0 1676 * kernel version 3.0.0
1690 */ 1677 */
1691 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) | 1678 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) |
1692 BIT( NL80211_STA_INFO_RX_PACKETS) | 1679 BIT(NL80211_STA_INFO_RX_PACKETS) |
1693 BIT(NL80211_STA_INFO_TX_PACKETS) | 1680 BIT(NL80211_STA_INFO_TX_PACKETS) |
1694 BIT(NL80211_STA_INFO_TX_FAILED) | 1681 BIT(NL80211_STA_INFO_TX_FAILED) |
1695 BIT(NL80211_STA_INFO_TX_BITRATE); 1682 BIT(NL80211_STA_INFO_TX_BITRATE);
@@ -1701,11 +1688,10 @@ static int WILC_WFI_get_station(struct wiphy *wiphy, struct net_device *dev,
1701 sinfo->txrate.legacy = strStatistics.u8LinkSpeed * 10; 1688 sinfo->txrate.legacy = strStatistics.u8LinkSpeed * 10;
1702 1689
1703#ifdef TCP_ENHANCEMENTS 1690#ifdef TCP_ENHANCEMENTS
1704 if ((strStatistics.u8LinkSpeed > TCP_ACK_FILTER_LINK_SPEED_THRESH) && (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED)) { 1691 if ((strStatistics.u8LinkSpeed > TCP_ACK_FILTER_LINK_SPEED_THRESH) && (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED))
1705 Enable_TCP_ACK_Filter(true); 1692 Enable_TCP_ACK_Filter(true);
1706 } else if (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED) { 1693 else if (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED)
1707 Enable_TCP_ACK_Filter(false); 1694 Enable_TCP_ACK_Filter(false);
1708 }
1709#endif 1695#endif
1710 1696
1711 PRINT_D(CORECONFIG_DBG, "*** stats[%d][%d][%d][%d][%d]\n", sinfo->signal, sinfo->rx_packets, sinfo->tx_packets, 1697 PRINT_D(CORECONFIG_DBG, "*** stats[%d][%d][%d][%d][%d]\n", sinfo->signal, sinfo->rx_packets, sinfo->tx_packets,
@@ -1826,7 +1812,7 @@ static int WILC_WFI_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1826 priv = wiphy_priv(wiphy); 1812 priv = wiphy_priv(wiphy);
1827 1813
1828 pstrCfgParamVal.u32SetCfgFlag = 0; 1814 pstrCfgParamVal.u32SetCfgFlag = 0;
1829 PRINT_D(CFG80211_DBG, "Setting Wiphy params \n"); 1815 PRINT_D(CFG80211_DBG, "Setting Wiphy params\n");
1830 1816
1831 if (changed & WIPHY_PARAM_RETRY_SHORT) { 1817 if (changed & WIPHY_PARAM_RETRY_SHORT) {
1832 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_SHORT %d\n", 1818 PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_SHORT %d\n",
@@ -1909,7 +1895,7 @@ static int WILC_WFI_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1909 1895
1910 1896
1911 for (i = 0; i < priv->pmkid_list.numpmkid; i++) { 1897 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
1912 if (!WILC_memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid, 1898 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
1913 ETH_ALEN)) { 1899 ETH_ALEN)) {
1914 /*If bssid already exists and pmkid value needs to reset*/ 1900 /*If bssid already exists and pmkid value needs to reset*/
1915 flag = PMKID_FOUND; 1901 flag = PMKID_FOUND;
@@ -1919,9 +1905,9 @@ static int WILC_WFI_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1919 } 1905 }
1920 if (i < WILC_MAX_NUM_PMKIDS) { 1906 if (i < WILC_MAX_NUM_PMKIDS) {
1921 PRINT_D(CFG80211_DBG, "Setting PMKID in private structure\n"); 1907 PRINT_D(CFG80211_DBG, "Setting PMKID in private structure\n");
1922 WILC_memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid, 1908 memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
1923 ETH_ALEN); 1909 ETH_ALEN);
1924 WILC_memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid, 1910 memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
1925 PMKID_LEN); 1911 PMKID_LEN);
1926 if (!(flag == PMKID_FOUND)) 1912 if (!(flag == PMKID_FOUND))
1927 priv->pmkid_list.numpmkid++; 1913 priv->pmkid_list.numpmkid++;
@@ -1959,11 +1945,11 @@ static int WILC_WFI_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1959 PRINT_D(CFG80211_DBG, "Deleting PMKSA keys\n"); 1945 PRINT_D(CFG80211_DBG, "Deleting PMKSA keys\n");
1960 1946
1961 for (i = 0; i < priv->pmkid_list.numpmkid; i++) { 1947 for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
1962 if (!WILC_memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid, 1948 if (!memcmp(pmksa->bssid, priv->pmkid_list.pmkidlist[i].bssid,
1963 ETH_ALEN)) { 1949 ETH_ALEN)) {
1964 /*If bssid is found, reset the values*/ 1950 /*If bssid is found, reset the values*/
1965 PRINT_D(CFG80211_DBG, "Reseting PMKID values\n"); 1951 PRINT_D(CFG80211_DBG, "Reseting PMKID values\n");
1966 WILC_memset(&priv->pmkid_list.pmkidlist[i], 0, sizeof(tstrHostIFpmkid)); 1952 memset(&priv->pmkid_list.pmkidlist[i], 0, sizeof(tstrHostIFpmkid));
1967 flag = PMKID_FOUND; 1953 flag = PMKID_FOUND;
1968 break; 1954 break;
1969 } 1955 }
@@ -1971,10 +1957,10 @@ static int WILC_WFI_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1971 1957
1972 if (i < priv->pmkid_list.numpmkid && priv->pmkid_list.numpmkid > 0) { 1958 if (i < priv->pmkid_list.numpmkid && priv->pmkid_list.numpmkid > 0) {
1973 for (; i < (priv->pmkid_list.numpmkid - 1); i++) { 1959 for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
1974 WILC_memcpy(priv->pmkid_list.pmkidlist[i].bssid, 1960 memcpy(priv->pmkid_list.pmkidlist[i].bssid,
1975 priv->pmkid_list.pmkidlist[i + 1].bssid, 1961 priv->pmkid_list.pmkidlist[i + 1].bssid,
1976 ETH_ALEN); 1962 ETH_ALEN);
1977 WILC_memcpy(priv->pmkid_list.pmkidlist[i].pmkid, 1963 memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
1978 priv->pmkid_list.pmkidlist[i].pmkid, 1964 priv->pmkid_list.pmkidlist[i].pmkid,
1979 PMKID_LEN); 1965 PMKID_LEN);
1980 } 1966 }
@@ -2002,7 +1988,7 @@ static int WILC_WFI_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
2002 PRINT_D(CFG80211_DBG, "Flushing PMKID key values\n"); 1988 PRINT_D(CFG80211_DBG, "Flushing PMKID key values\n");
2003 1989
2004 /*Get cashed Pmkids and set all with zeros*/ 1990 /*Get cashed Pmkids and set all with zeros*/
2005 WILC_memset(&priv->pmkid_list, 0, sizeof(tstrHostIFpmkidAttr)); 1991 memset(&priv->pmkid_list, 0, sizeof(tstrHostIFpmkidAttr));
2006 1992
2007 return 0; 1993 return 0;
2008} 1994}
@@ -2074,11 +2060,10 @@ void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len)
2074 } 2060 }
2075 #endif /* USE_SUPPLICANT_GO_INTENT */ 2061 #endif /* USE_SUPPLICANT_GO_INTENT */
2076 2062
2077 if (buf[index] == CHANLIST_ATTR_ID) { 2063 if (buf[index] == CHANLIST_ATTR_ID)
2078 channel_list_attr_index = index; 2064 channel_list_attr_index = index;
2079 } else if (buf[index] == OPERCHAN_ATTR_ID) { 2065 else if (buf[index] == OPERCHAN_ATTR_ID)
2080 op_channel_attr_index = index; 2066 op_channel_attr_index = index;
2081 }
2082 index += buf[index + 1] + 3; /* ID,Length byte */ 2067 index += buf[index + 1] + 3; /* ID,Length byte */
2083 } 2068 }
2084 2069
@@ -2160,11 +2145,10 @@ void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype)
2160 } 2145 }
2161 #endif 2146 #endif
2162 2147
2163 if (buf[index] == CHANLIST_ATTR_ID) { 2148 if (buf[index] == CHANLIST_ATTR_ID)
2164 channel_list_attr_index = index; 2149 channel_list_attr_index = index;
2165 } else if (buf[index] == OPERCHAN_ATTR_ID) { 2150 else if (buf[index] == OPERCHAN_ATTR_ID)
2166 op_channel_attr_index = index; 2151 op_channel_attr_index = index;
2167 }
2168 index += buf[index + 1] + 3; /* ID,Length byte */ 2152 index += buf[index + 1] + 3; /* ID,Length byte */
2169 } 2153 }
2170 2154
@@ -2218,7 +2202,7 @@ void WILC_WFI_p2p_rx (struct net_device *dev, uint8_t *buff, uint32_t size)
2218 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv; 2202 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
2219 2203
2220 /* Get WILC header */ 2204 /* Get WILC header */
2221 WILC_memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET); 2205 memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET);
2222 2206
2223 /* The packet offset field conain info about what type of managment frame */ 2207 /* The packet offset field conain info about what type of managment frame */
2224 /* we are dealing with and ack status */ 2208 /* we are dealing with and ack status */
@@ -2270,11 +2254,11 @@ void WILC_WFI_p2p_rx (struct net_device *dev, uint8_t *buff, uint32_t size)
2270 case PUBLIC_ACT_VENDORSPEC: 2254 case PUBLIC_ACT_VENDORSPEC:
2271 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame 2255 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
2272 * based on the standard its should have the p2p_oui attribute with the following values 50 6f 9A 09*/ 2256 * based on the standard its should have the p2p_oui attribute with the following values 50 6f 9A 09*/
2273 if (!WILC_memcmp(u8P2P_oui, &buff[ACTION_SUBTYPE_ID + 1], 4)) { 2257 if (!memcmp(u8P2P_oui, &buff[ACTION_SUBTYPE_ID + 1], 4)) {
2274 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) { 2258 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
2275 if (!bWilc_ie) { 2259 if (!bWilc_ie) {
2276 for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) { 2260 for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) {
2277 if (!WILC_memcmp(u8P2P_vendorspec, &buff[i], 6)) { 2261 if (!memcmp(u8P2P_vendorspec, &buff[i], 6)) {
2278 u8P2Precvrandom = buff[i + 6]; 2262 u8P2Precvrandom = buff[i + 6];
2279 bWilc_ie = true; 2263 bWilc_ie = true;
2280 PRINT_D(GENERIC_DBG, "WILC Vendor specific IE:%02x\n", u8P2Precvrandom); 2264 PRINT_D(GENERIC_DBG, "WILC Vendor specific IE:%02x\n", u8P2Precvrandom);
@@ -2287,7 +2271,7 @@ void WILC_WFI_p2p_rx (struct net_device *dev, uint8_t *buff, uint32_t size)
2287 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP 2271 if ((buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP
2288 || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) { 2272 || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buff[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)) {
2289 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < size; i++) { 2273 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < size; i++) {
2290 if (buff[i] == P2PELEM_ATTR_ID && !(WILC_memcmp(u8P2P_oui, &buff[i + 2], 4))) { 2274 if (buff[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buff[i + 2], 4))) {
2291 WILC_WFI_CfgParseRxAction(&buff[i + 6], size - (i + 6)); 2275 WILC_WFI_CfgParseRxAction(&buff[i + 6], size - (i + 6));
2292 break; 2276 break;
2293 } 2277 }
@@ -2351,7 +2335,7 @@ static void WILC_WFI_RemainOnChannelReady(void *pUserVoid)
2351 struct WILC_WFI_priv *priv; 2335 struct WILC_WFI_priv *priv;
2352 priv = (struct WILC_WFI_priv *)pUserVoid; 2336 priv = (struct WILC_WFI_priv *)pUserVoid;
2353 2337
2354 PRINT_D(HOSTINF_DBG, "Remain on channel ready \n"); 2338 PRINT_D(HOSTINF_DBG, "Remain on channel ready\n");
2355 2339
2356 priv->bInP2PlistenState = true; 2340 priv->bInP2PlistenState = true;
2357 2341
@@ -2379,7 +2363,7 @@ static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID)
2379 2363
2380 /*BugID_5477*/ 2364 /*BugID_5477*/
2381 if (u32SessionID == priv->strRemainOnChanParams.u32ListenSessionID) { 2365 if (u32SessionID == priv->strRemainOnChanParams.u32ListenSessionID) {
2382 PRINT_D(GENERIC_DBG, "Remain on channel expired \n"); 2366 PRINT_D(GENERIC_DBG, "Remain on channel expired\n");
2383 2367
2384 priv->bInP2PlistenState = false; 2368 priv->bInP2PlistenState = false;
2385 2369
@@ -2485,7 +2469,7 @@ static int WILC_WFI_cancel_remain_on_channel(struct wiphy *wiphy,
2485 */ 2469 */
2486void WILC_WFI_add_wilcvendorspec(u8 *buff) 2470void WILC_WFI_add_wilcvendorspec(u8 *buff)
2487{ 2471{
2488 WILC_memcpy(buff, u8P2P_vendorspec, sizeof(u8P2P_vendorspec)); 2472 memcpy(buff, u8P2P_vendorspec, sizeof(u8P2P_vendorspec));
2489} 2473}
2490/** 2474/**
2491 * @brief WILC_WFI_mgmt_tx_frame 2475 * @brief WILC_WFI_mgmt_tx_frame
@@ -2528,17 +2512,17 @@ int WILC_WFI_mgmt_tx(struct wiphy *wiphy,
2528 if (ieee80211_is_mgmt(mgmt->frame_control)) { 2512 if (ieee80211_is_mgmt(mgmt->frame_control)) {
2529 2513
2530 /*mgmt frame allocation*/ 2514 /*mgmt frame allocation*/
2531 mgmt_tx = (struct p2p_mgmt_data *)WILC_MALLOC(sizeof(struct p2p_mgmt_data)); 2515 mgmt_tx = WILC_MALLOC(sizeof(struct p2p_mgmt_data));
2532 if (mgmt_tx == NULL) { 2516 if (mgmt_tx == NULL) {
2533 PRINT_ER("Failed to allocate memory for mgmt_tx structure\n"); 2517 PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
2534 return WILC_FAIL; 2518 return WILC_FAIL;
2535 } 2519 }
2536 mgmt_tx->buff = (char *)WILC_MALLOC(buf_len); 2520 mgmt_tx->buff = WILC_MALLOC(buf_len);
2537 if (mgmt_tx->buff == NULL) { 2521 if (mgmt_tx->buff == NULL) {
2538 PRINT_ER("Failed to allocate memory for mgmt_tx buff\n"); 2522 PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
2539 return WILC_FAIL; 2523 return WILC_FAIL;
2540 } 2524 }
2541 WILC_memcpy(mgmt_tx->buff, buf, len); 2525 memcpy(mgmt_tx->buff, buf, len);
2542 mgmt_tx->size = len; 2526 mgmt_tx->size = len;
2543 2527
2544 2528
@@ -2583,7 +2567,7 @@ int WILC_WFI_mgmt_tx(struct wiphy *wiphy,
2583 { 2567 {
2584 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame 2568 /*Now we have a public action vendor specific action frame, check if its a p2p public action frame
2585 * based on the standard its should have the p2p_oui attribute with the following values 50 6f 9A 09*/ 2569 * based on the standard its should have the p2p_oui attribute with the following values 50 6f 9A 09*/
2586 if (!WILC_memcmp(u8P2P_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) { 2570 if (!memcmp(u8P2P_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) {
2587 /*For the connection of two WILC's connection generate a rand number to determine who will be a GO*/ 2571 /*For the connection of two WILC's connection generate a rand number to determine who will be a GO*/
2588 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) { 2572 if ((buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == GO_NEG_RSP)) {
2589 if (u8P2Plocalrandom == 1 && u8P2Precvrandom < u8P2Plocalrandom) { 2573 if (u8P2Plocalrandom == 1 && u8P2Precvrandom < u8P2Plocalrandom) {
@@ -2600,7 +2584,7 @@ int WILC_WFI_mgmt_tx(struct wiphy *wiphy,
2600 2584
2601 /*Search for the p2p information information element , after the Public action subtype theres a byte for teh dialog token, skip that*/ 2585 /*Search for the p2p information information element , after the Public action subtype theres a byte for teh dialog token, skip that*/
2602 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) { 2586 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) {
2603 if (buf[i] == P2PELEM_ATTR_ID && !(WILC_memcmp(u8P2P_oui, &buf[i + 2], 4))) { 2587 if (buf[i] == P2PELEM_ATTR_ID && !(memcmp(u8P2P_oui, &buf[i + 2], 4))) {
2604 if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP) 2588 if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)
2605 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), true, nic->iftype); 2589 WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), true, nic->iftype);
2606 2590
@@ -2862,7 +2846,7 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
2862 2846
2863 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 2847 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2864 g_obtainingIP = false; 2848 g_obtainingIP = false;
2865 WILC_TimerStop(&hDuringIpTimer, NULL); 2849 del_timer(&hDuringIpTimer);
2866 PRINT_D(GENERIC_DBG, "Changing virtual interface, enable scan\n"); 2850 PRINT_D(GENERIC_DBG, "Changing virtual interface, enable scan\n");
2867 #endif 2851 #endif
2868 /*BugID_5137*/ 2852 /*BugID_5137*/
@@ -2886,7 +2870,6 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
2886 2870
2887 /*Remove the enteries of the previously connected clients*/ 2871 /*Remove the enteries of the previously connected clients*/
2888 memset(priv->assoc_stainfo.au8Sta_AssociatedBss, 0, MAX_NUM_STA * ETH_ALEN); 2872 memset(priv->assoc_stainfo.au8Sta_AssociatedBss, 0, MAX_NUM_STA * ETH_ALEN);
2889 #ifndef SIMULATION
2890 #ifdef WILC_P2P 2873 #ifdef WILC_P2P
2891 interface_type = nic->iftype; 2874 interface_type = nic->iftype;
2892 nic->iftype = STATION_MODE; 2875 nic->iftype = STATION_MODE;
@@ -2907,15 +2890,15 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
2907 2890
2908 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/ 2891 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
2909 host_int_set_wfi_drv_handler(g_linux_wlan->strInterfaceInfo[0].drvHandler); 2892 host_int_set_wfi_drv_handler(g_linux_wlan->strInterfaceInfo[0].drvHandler);
2910 host_int_set_MacAddress((WILC_WFIDrvHandle)(g_linux_wlan->strInterfaceInfo[0].drvHandler), 2893 host_int_set_MacAddress(g_linux_wlan->strInterfaceInfo[0].drvHandler,
2911 g_linux_wlan->strInterfaceInfo[0].aSrcAddress); 2894 g_linux_wlan->strInterfaceInfo[0].aSrcAddress);
2912 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE); 2895 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
2913 2896
2914 /*Add saved WEP keys, if any*/ 2897 /*Add saved WEP keys, if any*/
2915 if (g_wep_keys_saved) { 2898 if (g_wep_keys_saved) {
2916 host_int_set_WEPDefaultKeyID((WILC_WFIDrvHandle)(g_linux_wlan->strInterfaceInfo[0].drvHandler), 2899 host_int_set_WEPDefaultKeyID(g_linux_wlan->strInterfaceInfo[0].drvHandler,
2917 g_key_wep_params.key_idx); 2900 g_key_wep_params.key_idx);
2918 host_int_add_wep_key_bss_sta((WILC_WFIDrvHandle)(g_linux_wlan->strInterfaceInfo[0].drvHandler), 2901 host_int_add_wep_key_bss_sta(g_linux_wlan->strInterfaceInfo[0].drvHandler,
2919 g_key_wep_params.key, 2902 g_key_wep_params.key,
2920 g_key_wep_params.key_len, 2903 g_key_wep_params.key_len,
2921 g_key_wep_params.key_idx); 2904 g_key_wep_params.key_idx);
@@ -2964,7 +2947,6 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
2964 host_int_set_power_mgmt(priv->hWILCWFIDrv, 1, 0); 2947 host_int_set_power_mgmt(priv->hWILCWFIDrv, 1, 0);
2965 } 2948 }
2966 #endif 2949 #endif
2967 #endif
2968 break; 2950 break;
2969 2951
2970 case NL80211_IFTYPE_P2P_CLIENT: 2952 case NL80211_IFTYPE_P2P_CLIENT:
@@ -2979,7 +2961,6 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
2979 priv->wdev->iftype = type; 2961 priv->wdev->iftype = type;
2980 nic->monitor_flag = 0; 2962 nic->monitor_flag = 0;
2981 2963
2982 #ifndef SIMULATION
2983 #ifdef WILC_P2P 2964 #ifdef WILC_P2P
2984 2965
2985 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n"); 2966 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
@@ -2995,15 +2976,15 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
2995 g_wilc_initialized = 1; 2976 g_wilc_initialized = 1;
2996 2977
2997 host_int_set_wfi_drv_handler(g_linux_wlan->strInterfaceInfo[0].drvHandler); 2978 host_int_set_wfi_drv_handler(g_linux_wlan->strInterfaceInfo[0].drvHandler);
2998 host_int_set_MacAddress((WILC_WFIDrvHandle)(g_linux_wlan->strInterfaceInfo[0].drvHandler), 2979 host_int_set_MacAddress(g_linux_wlan->strInterfaceInfo[0].drvHandler,
2999 g_linux_wlan->strInterfaceInfo[0].aSrcAddress); 2980 g_linux_wlan->strInterfaceInfo[0].aSrcAddress);
3000 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE); 2981 host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
3001 2982
3002 /*Add saved WEP keys, if any*/ 2983 /*Add saved WEP keys, if any*/
3003 if (g_wep_keys_saved) { 2984 if (g_wep_keys_saved) {
3004 host_int_set_WEPDefaultKeyID((WILC_WFIDrvHandle)(g_linux_wlan->strInterfaceInfo[0].drvHandler), 2985 host_int_set_WEPDefaultKeyID(g_linux_wlan->strInterfaceInfo[0].drvHandler,
3005 g_key_wep_params.key_idx); 2986 g_key_wep_params.key_idx);
3006 host_int_add_wep_key_bss_sta((WILC_WFIDrvHandle)(g_linux_wlan->strInterfaceInfo[0].drvHandler), 2987 host_int_add_wep_key_bss_sta(g_linux_wlan->strInterfaceInfo[0].drvHandler,
3007 g_key_wep_params.key, 2988 g_key_wep_params.key,
3008 g_key_wep_params.key_len, 2989 g_key_wep_params.key_len,
3009 g_key_wep_params.key_idx); 2990 g_key_wep_params.key_idx);
@@ -3053,7 +3034,6 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
3053 } 3034 }
3054 } 3035 }
3055 #endif 3036 #endif
3056 #endif
3057 break; 3037 break;
3058 3038
3059 case NL80211_IFTYPE_AP: 3039 case NL80211_IFTYPE_AP:
@@ -3064,7 +3044,6 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
3064 nic->iftype = AP_MODE; 3044 nic->iftype = AP_MODE;
3065 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv); 3045 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
3066 3046
3067 #ifndef SIMULATION
3068 PRINT_D(HOSTAPD_DBG, "Downloading AP firmware\n"); 3047 PRINT_D(HOSTAPD_DBG, "Downloading AP firmware\n");
3069 linux_wlan_get_firmware(nic); 3048 linux_wlan_get_firmware(nic);
3070 #ifdef WILC_P2P 3049 #ifdef WILC_P2P
@@ -3086,7 +3065,6 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
3086 } 3065 }
3087 } 3066 }
3088 #endif 3067 #endif
3089 #endif
3090 break; 3068 break;
3091 3069
3092 case NL80211_IFTYPE_P2P_GO: 3070 case NL80211_IFTYPE_P2P_GO:
@@ -3094,7 +3072,7 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
3094 3072
3095 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 3073 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
3096 g_obtainingIP = true; 3074 g_obtainingIP = true;
3097 WILC_TimerStart(&hDuringIpTimer, duringIP_TIME, NULL, NULL); 3075 mod_timer(&hDuringIpTimer, jiffies + msecs_to_jiffies(duringIP_TIME));
3098 #endif 3076 #endif
3099 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0); 3077 host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
3100 /*BugID_5222*/ 3078 /*BugID_5222*/
@@ -3110,7 +3088,6 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
3110 3088
3111 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv); 3089 PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
3112 3090
3113 #ifndef SIMULATION
3114 #ifdef WILC_P2P 3091 #ifdef WILC_P2P
3115 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n"); 3092 PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
3116 3093
@@ -3127,15 +3104,15 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
3127 3104
3128 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/ 3105 /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
3129 host_int_set_wfi_drv_handler(g_linux_wlan->strInterfaceInfo[0].drvHandler); 3106 host_int_set_wfi_drv_handler(g_linux_wlan->strInterfaceInfo[0].drvHandler);
3130 host_int_set_MacAddress((WILC_WFIDrvHandle)(g_linux_wlan->strInterfaceInfo[0].drvHandler), 3107 host_int_set_MacAddress(g_linux_wlan->strInterfaceInfo[0].drvHandler,
3131 g_linux_wlan->strInterfaceInfo[0].aSrcAddress); 3108 g_linux_wlan->strInterfaceInfo[0].aSrcAddress);
3132 host_int_set_operation_mode(priv->hWILCWFIDrv, AP_MODE); 3109 host_int_set_operation_mode(priv->hWILCWFIDrv, AP_MODE);
3133 3110
3134 /*Add saved WEP keys, if any*/ 3111 /*Add saved WEP keys, if any*/
3135 if (g_wep_keys_saved) { 3112 if (g_wep_keys_saved) {
3136 host_int_set_WEPDefaultKeyID((WILC_WFIDrvHandle)(g_linux_wlan->strInterfaceInfo[0].drvHandler), 3113 host_int_set_WEPDefaultKeyID(g_linux_wlan->strInterfaceInfo[0].drvHandler,
3137 g_key_wep_params.key_idx); 3114 g_key_wep_params.key_idx);
3138 host_int_add_wep_key_bss_sta((WILC_WFIDrvHandle)(g_linux_wlan->strInterfaceInfo[0].drvHandler), 3115 host_int_add_wep_key_bss_sta(g_linux_wlan->strInterfaceInfo[0].drvHandler,
3139 g_key_wep_params.key, 3116 g_key_wep_params.key,
3140 g_key_wep_params.key_len, 3117 g_key_wep_params.key_len,
3141 g_key_wep_params.key_idx); 3118 g_key_wep_params.key_idx);
@@ -3185,7 +3162,6 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
3185 } 3162 }
3186 } 3163 }
3187 #endif 3164 #endif
3188 #endif
3189 break; 3165 break;
3190 3166
3191 default: 3167 default:
@@ -3234,7 +3210,7 @@ static int WILC_WFI_start_ap(struct wiphy *wiphy, struct net_device *dev,
3234 priv = wiphy_priv(wiphy); 3210 priv = wiphy_priv(wiphy);
3235 PRINT_D(HOSTAPD_DBG, "Starting ap\n"); 3211 PRINT_D(HOSTAPD_DBG, "Starting ap\n");
3236 3212
3237 PRINT_D(HOSTAPD_DBG, "Interval = %d \n DTIM period = %d\n Head length = %zu Tail length = %zu\n", 3213 PRINT_D(HOSTAPD_DBG, "Interval = %d\n DTIM period = %d\n Head length = %zu Tail length = %zu\n",
3238 settings->beacon_interval, settings->dtim_period, beacon->head_len, beacon->tail_len); 3214 settings->beacon_interval, settings->dtim_period, beacon->head_len, beacon->tail_len);
3239 3215
3240 s32Error = WILC_WFI_CfgSetChannel(wiphy, &settings->chandef); 3216 s32Error = WILC_WFI_CfgSetChannel(wiphy, &settings->chandef);
@@ -3353,7 +3329,7 @@ static int WILC_WFI_add_station(struct wiphy *wiphy, struct net_device *dev,
3353{ 3329{
3354 s32 s32Error = WILC_SUCCESS; 3330 s32 s32Error = WILC_SUCCESS;
3355 struct WILC_WFI_priv *priv; 3331 struct WILC_WFI_priv *priv;
3356 tstrWILC_AddStaParam strStaParams = {{0}}; 3332 tstrWILC_AddStaParam strStaParams = { {0} };
3357 perInterface_wlan_t *nic; 3333 perInterface_wlan_t *nic;
3358 3334
3359 3335
@@ -3365,8 +3341,8 @@ static int WILC_WFI_add_station(struct wiphy *wiphy, struct net_device *dev,
3365 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) { 3341 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3366 #ifndef WILC_FULLY_HOSTING_AP 3342 #ifndef WILC_FULLY_HOSTING_AP
3367 3343
3368 WILC_memcpy(strStaParams.au8BSSID, mac, ETH_ALEN); 3344 memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
3369 WILC_memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN); 3345 memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN);
3370 strStaParams.u16AssocID = params->aid; 3346 strStaParams.u16AssocID = params->aid;
3371 strStaParams.u8NumRates = params->supported_rates_len; 3347 strStaParams.u8NumRates = params->supported_rates_len;
3372 strStaParams.pu8Rates = params->supported_rates; 3348 strStaParams.pu8Rates = params->supported_rates;
@@ -3384,7 +3360,7 @@ static int WILC_WFI_add_station(struct wiphy *wiphy, struct net_device *dev,
3384 strStaParams.bIsHTSupported = true; 3360 strStaParams.bIsHTSupported = true;
3385 strStaParams.u16HTCapInfo = params->ht_capa->cap_info; 3361 strStaParams.u16HTCapInfo = params->ht_capa->cap_info;
3386 strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info; 3362 strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info;
3387 WILC_memcpy(strStaParams.au8SuppMCsSet, &params->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE); 3363 memcpy(strStaParams.au8SuppMCsSet, &params->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE);
3388 strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info; 3364 strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info;
3389 strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info; 3365 strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info;
3390 strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info; 3366 strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info;
@@ -3407,7 +3383,7 @@ static int WILC_WFI_add_station(struct wiphy *wiphy, struct net_device *dev,
3407 3383
3408 #else 3384 #else
3409 PRINT_D(CFG80211_DBG, "Adding station parameters %d\n", params->aid); 3385 PRINT_D(CFG80211_DBG, "Adding station parameters %d\n", params->aid);
3410 WILC_memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN); 3386 memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN);
3411 3387
3412 PRINT_D(CFG80211_DBG, "BSSID = %x%x%x%x%x%x\n", priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][0], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][1], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][2], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][3], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][4], 3388 PRINT_D(CFG80211_DBG, "BSSID = %x%x%x%x%x%x\n", priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][0], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][1], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][2], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][3], priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][4],
3413 priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][5]); 3389 priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][5]);
@@ -3450,7 +3426,7 @@ static int WILC_WFI_del_station(struct wiphy *wiphy, struct net_device *dev,
3450 3426
3451 3427
3452 if (mac == NULL) { 3428 if (mac == NULL) {
3453 PRINT_D(HOSTAPD_DBG, "All associated stations \n"); 3429 PRINT_D(HOSTAPD_DBG, "All associated stations\n");
3454 s32Error = host_int_del_allstation(priv->hWILCWFIDrv, priv->assoc_stainfo.au8Sta_AssociatedBss); 3430 s32Error = host_int_del_allstation(priv->hWILCWFIDrv, priv->assoc_stainfo.au8Sta_AssociatedBss);
3455 } else { 3431 } else {
3456 PRINT_D(HOSTAPD_DBG, "With mac address: %x%x%x%x%x%x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 3432 PRINT_D(HOSTAPD_DBG, "With mac address: %x%x%x%x%x%x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
@@ -3484,7 +3460,7 @@ static int WILC_WFI_change_station(struct wiphy *wiphy, struct net_device *dev,
3484{ 3460{
3485 s32 s32Error = WILC_SUCCESS; 3461 s32 s32Error = WILC_SUCCESS;
3486 struct WILC_WFI_priv *priv; 3462 struct WILC_WFI_priv *priv;
3487 tstrWILC_AddStaParam strStaParams = {{0}}; 3463 tstrWILC_AddStaParam strStaParams = { {0} };
3488 perInterface_wlan_t *nic; 3464 perInterface_wlan_t *nic;
3489 3465
3490 3466
@@ -3498,7 +3474,7 @@ static int WILC_WFI_change_station(struct wiphy *wiphy, struct net_device *dev,
3498 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) { 3474 if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
3499 #ifndef WILC_FULLY_HOSTING_AP 3475 #ifndef WILC_FULLY_HOSTING_AP
3500 3476
3501 WILC_memcpy(strStaParams.au8BSSID, mac, ETH_ALEN); 3477 memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
3502 strStaParams.u16AssocID = params->aid; 3478 strStaParams.u16AssocID = params->aid;
3503 strStaParams.u8NumRates = params->supported_rates_len; 3479 strStaParams.u8NumRates = params->supported_rates_len;
3504 strStaParams.pu8Rates = params->supported_rates; 3480 strStaParams.pu8Rates = params->supported_rates;
@@ -3514,7 +3490,7 @@ static int WILC_WFI_change_station(struct wiphy *wiphy, struct net_device *dev,
3514 strStaParams.bIsHTSupported = true; 3490 strStaParams.bIsHTSupported = true;
3515 strStaParams.u16HTCapInfo = params->ht_capa->cap_info; 3491 strStaParams.u16HTCapInfo = params->ht_capa->cap_info;
3516 strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info; 3492 strStaParams.u8AmpduParams = params->ht_capa->ampdu_params_info;
3517 WILC_memcpy(strStaParams.au8SuppMCsSet, &params->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE); 3493 memcpy(strStaParams.au8SuppMCsSet, &params->ht_capa->mcs, WILC_SUPP_MCS_SET_SIZE);
3518 strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info; 3494 strStaParams.u16HTExtParams = params->ht_capa->extended_ht_cap_info;
3519 strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info; 3495 strStaParams.u32TxBeamformingCap = params->ht_capa->tx_BF_cap_info;
3520 strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info; 3496 strStaParams.u8ASELCap = params->ht_capa->antenna_selection_info;
@@ -3581,13 +3557,8 @@ struct wireless_dev *WILC_WFI_add_virt_intf(struct wiphy *wiphy, const char *nam
3581 new_ifc = WILC_WFI_init_mon_interface(name, nic->wilc_netdev); 3557 new_ifc = WILC_WFI_init_mon_interface(name, nic->wilc_netdev);
3582 if (new_ifc != NULL) { 3558 if (new_ifc != NULL) {
3583 PRINT_D(HOSTAPD_DBG, "Setting monitor flag in private structure\n"); 3559 PRINT_D(HOSTAPD_DBG, "Setting monitor flag in private structure\n");
3584 #ifdef SIMULATION
3585 priv = netdev_priv(priv->wdev->netdev);
3586 priv->monitor_flag = 1;
3587 #else
3588 nic = netdev_priv(priv->wdev->netdev); 3560 nic = netdev_priv(priv->wdev->netdev);
3589 nic->monitor_flag = 1; 3561 nic->monitor_flag = 1;
3590 #endif
3591 } else 3562 } else
3592 PRINT_ER("Error in initializing monitor interface\n "); 3563 PRINT_ER("Error in initializing monitor interface\n ");
3593 } 3564 }
@@ -3856,9 +3827,9 @@ int WILC_WFI_InitHostInt(struct net_device *net)
3856 PRINT_D(INIT_DBG, "Host[%p][%p]\n", net, net->ieee80211_ptr); 3827 PRINT_D(INIT_DBG, "Host[%p][%p]\n", net, net->ieee80211_ptr);
3857 priv = wdev_priv(net->ieee80211_ptr); 3828 priv = wdev_priv(net->ieee80211_ptr);
3858 if (op_ifcs == 0) { 3829 if (op_ifcs == 0) {
3859 s32Error = WILC_TimerCreate(&(hAgingTimer), remove_network_from_shadow, NULL); 3830 setup_timer(&hAgingTimer, remove_network_from_shadow, 0);
3860 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 3831 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
3861 s32Error = WILC_TimerCreate(&(hDuringIpTimer), clear_duringIP, NULL); 3832 setup_timer(&hDuringIpTimer, clear_duringIP, 0);
3862 #endif 3833 #endif
3863 } 3834 }
3864 op_ifcs++; 3835 op_ifcs++;
@@ -3908,7 +3879,7 @@ int WILC_WFI_DeInitHostInt(struct net_device *net)
3908 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP 3879 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
3909 if (op_ifcs == 0) { 3880 if (op_ifcs == 0) {
3910 PRINT_D(CORECONFIG_DBG, "destroy during ip\n"); 3881 PRINT_D(CORECONFIG_DBG, "destroy during ip\n");
3911 WILC_TimerDestroy(&hDuringIpTimer, NULL); 3882 del_timer_sync(&hDuringIpTimer);
3912 } 3883 }
3913 #endif 3884 #endif
3914 3885
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h
index c25350cb58c8..97b663b7fd14 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h
@@ -123,7 +123,7 @@ struct net_device *WILC_WFI_init_mon_interface(const char *name, struct net_devi
123#ifdef TCP_ENHANCEMENTS 123#ifdef TCP_ENHANCEMENTS
124#define TCP_ACK_FILTER_LINK_SPEED_THRESH 54 124#define TCP_ACK_FILTER_LINK_SPEED_THRESH 54
125#define DEFAULT_LINK_SPEED 72 125#define DEFAULT_LINK_SPEED 72
126extern void Enable_TCP_ACK_Filter(bool value); 126void Enable_TCP_ACK_Filter(bool value);
127#endif 127#endif
128 128
129#endif 129#endif
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.c b/drivers/staging/wilc1000/wilc_wfi_netdevice.c
deleted file mode 100644
index ab66ce4bd790..000000000000
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.c
+++ /dev/null
@@ -1,951 +0,0 @@
1/*!
2 * @file wilc_wfi_netdevice.c
3 * @brief File Operations OS wrapper functionality
4 * @author mdaftedar
5 * @sa wilc_wfi_netdevice.h
6 * @date 01 MAR 2012
7 * @version 1.0
8 */
9
10#ifdef SIMULATION
11
12#include "wilc_wfi_cfgoperations.h"
13#include "host_interface.h"
14
15
16MODULE_AUTHOR("Mai Daftedar");
17MODULE_LICENSE("Dual BSD/GPL");
18
19
20struct net_device *WILC_WFI_devs[2];
21
22/*
23 * Transmitter lockup simulation, normally disabled.
24 */
25static int lockup;
26module_param(lockup, int, 0);
27
28static int timeout = WILC_WFI_TIMEOUT;
29module_param(timeout, int, 0);
30
31/*
32 * Do we run in NAPI mode?
33 */
34static int use_napi ;
35module_param(use_napi, int, 0);
36
37
38/*
39 * A structure representing an in-flight packet.
40 */
41struct WILC_WFI_packet {
42 struct WILC_WFI_packet *next;
43 struct net_device *dev;
44 int datalen;
45 u8 data[ETH_DATA_LEN];
46};
47
48
49
50int pool_size = 8;
51module_param(pool_size, int, 0);
52
53
54static void WILC_WFI_TxTimeout(struct net_device *dev);
55static void (*WILC_WFI_Interrupt)(int, void *, struct pt_regs *);
56
57/**
58 * @brief WILC_WFI_SetupPool
59 * @details Set up a device's packet pool.
60 * @param[in] struct net_device *dev : Network Device Pointer
61 * @return NONE
62 * @author mdaftedar
63 * @date 01 MAR 2012
64 * @version 1.0
65 */
66void WILC_WFI_SetupPool(struct net_device *dev)
67{
68 struct WILC_WFI_priv *priv = netdev_priv(dev);
69 int i;
70 struct WILC_WFI_packet *pkt;
71
72 priv->ppool = NULL;
73 for (i = 0; i < pool_size; i++) {
74 pkt = kmalloc (sizeof (struct WILC_WFI_packet), GFP_KERNEL);
75 if (pkt == NULL) {
76 PRINT_D(RX_DBG, "Ran out of memory allocating packet pool\n");
77 return;
78 }
79 pkt->dev = dev;
80 pkt->next = priv->ppool;
81 priv->ppool = pkt;
82 }
83}
84
85/**
86 * @brief WILC_WFI_TearDownPool
87 * @details Internal cleanup function that's called after the network device
88 * driver is unregistered
89 * @param[in] struct net_device *dev : Network Device Driver
90 * @return NONE
91 * @author mdaftedar
92 * @date 01 MAR 2012
93 * @version 1.0
94 */
95void WILC_WFI_TearDownPool(struct net_device *dev)
96{
97 struct WILC_WFI_priv *priv = netdev_priv(dev);
98 struct WILC_WFI_packet *pkt;
99
100 while ((pkt = priv->ppool)) {
101 priv->ppool = pkt->next;
102 kfree (pkt);
103 /* FIXME - in-flight packets ? */
104 }
105}
106
107/**
108 * @brief WILC_WFI_GetTxBuffer
109 * @details Buffer/pool management
110 * @param[in] net_device *dev : Network Device Driver Structure
111 * @return struct WILC_WFI_packet
112 * @author mdaftedar
113 * @date 01 MAR 2012
114 * @version 1.0
115 */
116struct WILC_WFI_packet *WILC_WFI_GetTxBuffer(struct net_device *dev)
117{
118 struct WILC_WFI_priv *priv = netdev_priv(dev);
119 unsigned long flags;
120 struct WILC_WFI_packet *pkt;
121
122 spin_lock_irqsave(&priv->lock, flags);
123 pkt = priv->ppool;
124 priv->ppool = pkt->next;
125 if (priv->ppool == NULL) {
126 PRINT_INFO(RX_DBG, "Pool empty\n");
127 netif_stop_queue(dev);
128 }
129 spin_unlock_irqrestore(&priv->lock, flags);
130 return pkt;
131}
132/**
133 * @brief WILC_WFI_ReleaseBuffer
134 * @details Buffer/pool management
135 * @param[in] WILC_WFI_packet *pkt : Structure holding in-flight packet
136 * @return NONE
137 * @author mdaftedar
138 * @date 01 MAR 2012
139 * @version 1.0
140 */
141void WILC_WFI_ReleaseBuffer(struct WILC_WFI_packet *pkt)
142{
143 unsigned long flags;
144 struct WILC_WFI_priv *priv = netdev_priv(pkt->dev);
145
146 spin_lock_irqsave(&priv->lock, flags);
147 pkt->next = priv->ppool;
148 priv->ppool = pkt;
149 spin_unlock_irqrestore(&priv->lock, flags);
150 if (netif_queue_stopped(pkt->dev) && pkt->next == NULL)
151 netif_wake_queue(pkt->dev);
152}
153
154/**
155 * @brief WILC_WFI_EnqueueBuf
156 * @details Enqueuing packets in an RX buffer queue
157 * @param[in] WILC_WFI_packet *pkt : Structure holding in-flight packet
158 * @param[in] net_device *dev : Network Device Driver Structure
159 * @return NONE
160 * @author mdaftedar
161 * @date 01 MAR 2012
162 * @version 1.0
163 */
164void WILC_WFI_EnqueueBuf(struct net_device *dev, struct WILC_WFI_packet *pkt)
165{
166 unsigned long flags;
167 struct WILC_WFI_priv *priv = netdev_priv(dev);
168
169 spin_lock_irqsave(&priv->lock, flags);
170 pkt->next = priv->rx_queue; /* FIXME - misorders packets */
171 priv->rx_queue = pkt;
172 spin_unlock_irqrestore(&priv->lock, flags);
173}
174
175/**
176 * @brief WILC_WFI_DequeueBuf
177 * @details Dequeuing packets from the RX buffer queue
178 * @param[in] net_device *dev : Network Device Driver Structure
179 * @return WILC_WFI_packet *pkt : Structure holding in-flight pac
180 * @author mdaftedar
181 * @date 01 MAR 2012
182 * @version 1.0
183 */
184struct WILC_WFI_packet *WILC_WFI_DequeueBuf(struct net_device *dev)
185{
186 struct WILC_WFI_priv *priv = netdev_priv(dev);
187 struct WILC_WFI_packet *pkt;
188 unsigned long flags;
189
190 spin_lock_irqsave(&priv->lock, flags);
191 pkt = priv->rx_queue;
192 if (pkt != NULL)
193 priv->rx_queue = pkt->next;
194 spin_unlock_irqrestore(&priv->lock, flags);
195 return pkt;
196}
197/**
198 * @brief WILC_WFI_RxInts
199 * @details Enable and disable receive interrupts.
200 * @param[in] net_device *dev : Network Device Driver Structure
201 * @param[in] enable : Enable/Disable flag
202 * @return NONE
203 * @author mdaftedar
204 * @date 01 MAR 2012
205 * @version 1.0
206 */
207static void WILC_WFI_RxInts(struct net_device *dev, int enable)
208{
209 struct WILC_WFI_priv *priv = netdev_priv(dev);
210 priv->rx_int_enabled = enable;
211}
212
213/**
214 * @brief WILC_WFI_Open
215 * @details Open Network Device Driver, called when the network
216 * interface is opened. It starts the interface's transmit queue.
217 * @param[in] net_device *dev : Network Device Driver Structure
218 * @param[in] enable : Enable/Disable flag
219 * @return int : Returns 0 upon success.
220 * @author mdaftedar
221 * @date 01 MAR 2012
222 * @version 1.0
223 */
224int WILC_WFI_Open(struct net_device *dev)
225{
226 /* request_region(), request_irq(), .... (like fops->open) */
227 /*
228 * Assign the hardware address of the board: use "\0SNULx", where
229 * x is 0 or 1. The first byte is '\0' to avoid being a multicast
230 * address (the first byte of multicast addrs is odd).
231 */
232 memcpy(dev->dev_addr, "\0WLAN0", ETH_ALEN);
233 if (dev == WILC_WFI_devs[1])
234 dev->dev_addr[ETH_ALEN - 1]++; /* \0SNUL1 */
235
236 WILC_WFI_InitHostInt(dev);
237 netif_start_queue(dev);
238 return 0;
239}
240/**
241 * @brief WILC_WFI_Release
242 * @details Release Network Device Driver, called when the network
243 * interface is stopped or brought down. This function marks
244 * the network driver as not being able to transmit
245 * @param[in] net_device *dev : Network Device Driver Structure
246 * @return int : Return 0 on Success.
247 * @author mdaftedar
248 * @date 01 MAR 2012
249 * @version 1.0
250 */
251int WILC_WFI_Release(struct net_device *dev)
252{
253 /* release ports, irq and such -- like fops->close */
254
255 netif_stop_queue(dev); /* can't transmit any more */
256
257 return 0;
258}
259/**
260 * @brief WILC_WFI_Config
261 * @details Configuration changes (passed on by ifconfig)
262 * @param[in] net_device *dev : Network Device Driver Structure
263 * @param[in] struct ifmap *map : Contains the ioctl implementation for the
264 * network driver.
265 * @return int : Return 0 on Success.
266 * @author mdaftedar
267 * @date 01 MAR 2012
268 * @version 1.0
269 */
270int WILC_WFI_Config(struct net_device *dev, struct ifmap *map)
271{
272 if (dev->flags & IFF_UP) /* can't act on a running interface */
273 return -EBUSY;
274
275 /* Don't allow changing the I/O address */
276 if (map->base_addr != dev->base_addr) {
277 PRINT_D(RX_DBG, KERN_WARNING "WILC_WFI: Can't change I/O address\n");
278 return -EOPNOTSUPP;
279 }
280
281 /* Allow changing the IRQ */
282 if (map->irq != dev->irq) {
283 dev->irq = map->irq;
284 /* request_irq() is delayed to open-time */
285 }
286
287 /* ignore other fields */
288 return 0;
289}
290/**
291 * @brief WILC_WFI_Rx
292 * @details Receive a packet: retrieve, encapsulate and pass over to upper
293 * levels
294 * @param[in] net_device *dev : Network Device Driver Structure
295 * @param[in] WILC_WFI_packet :
296 * @return NONE
297 * @author mdaftedar
298 * @date 01 MAR 2012
299 * @version 1.0
300 */
301void WILC_WFI_Rx(struct net_device *dev, struct WILC_WFI_packet *pkt)
302{
303 int i;
304 struct sk_buff *skb;
305 struct WILC_WFI_priv *priv = netdev_priv(dev);
306 s8 rssi;
307 /*
308 * The packet has been retrieved from the transmission
309 * medium. Build an skb around it, so upper layers can handle it
310 */
311
312
313 skb = dev_alloc_skb(pkt->datalen + 2);
314 if (!skb) {
315 if (printk_ratelimit())
316 PRINT_D(RX_DBG, "WILC_WFI rx: low on mem - packet dropped\n");
317 priv->stats.rx_dropped++;
318 goto out;
319 }
320 skb_reserve(skb, 2); /* align IP on 16B boundary */
321 memcpy(skb_put(skb, pkt->datalen), pkt->data, pkt->datalen);
322
323 if (priv->monitor_flag) {
324 PRINT_INFO(RX_DBG, "In monitor device name %s\n", dev->name);
325 priv = wiphy_priv(priv->dev->ieee80211_ptr->wiphy);
326 PRINT_D(RX_DBG, "VALUE PASSED IN OF HRWD %p\n", priv->hWILCWFIDrv);
327 /* host_int_get_rssi(priv->hWILCWFIDrv, &(rssi)); */
328 if (INFO) {
329 for (i = 14; i < skb->len; i++)
330 PRINT_INFO(RX_DBG, "RXdata[%d] %02x\n", i, skb->data[i]);
331 }
332 WILC_WFI_monitor_rx(dev, skb);
333 return;
334 }
335out:
336 return;
337}
338
339/**
340 * @brief WILC_WFI_Poll
341 * @details The poll implementation
342 * @param[in] struct napi_struct *napi :
343 * @param[in] int budget :
344 * @return int : Return 0 on Success.
345 * @author mdaftedar
346 * @date 01 MAR 2012
347 * @version 1.0
348 */
349static int WILC_WFI_Poll(struct napi_struct *napi, int budget)
350{
351 int npackets = 0;
352 struct sk_buff *skb;
353 struct WILC_WFI_priv *priv = container_of(napi, struct WILC_WFI_priv, napi);
354 struct net_device *dev = priv->dev;
355 struct WILC_WFI_packet *pkt;
356
357 while (npackets < budget && priv->rx_queue) {
358 pkt = WILC_WFI_DequeueBuf(dev);
359 skb = dev_alloc_skb(pkt->datalen + 2);
360 if (!skb) {
361 if (printk_ratelimit())
362 PRINT_D(RX_DBG, "WILC_WFI: packet dropped\n");
363 priv->stats.rx_dropped++;
364 WILC_WFI_ReleaseBuffer(pkt);
365 continue;
366 }
367 skb_reserve(skb, 2); /* align IP on 16B boundary */
368 memcpy(skb_put(skb, pkt->datalen), pkt->data, pkt->datalen);
369 skb->dev = dev;
370 skb->protocol = eth_type_trans(skb, dev);
371 skb->ip_summed = CHECKSUM_UNNECESSARY; /* don't check it */
372 netif_receive_skb(skb);
373 /* Maintain stats */
374 npackets++;
375 WILC_WFI_update_stats(priv->dev->ieee80211_ptr->wiphy, pkt->datalen, WILC_WFI_RX_PKT);
376 WILC_WFI_ReleaseBuffer(pkt);
377 }
378 /* If we processed all packets, we're done; tell the kernel and re-enable ints */
379 if (npackets < budget) {
380 napi_complete(napi);
381 WILC_WFI_RxInts(dev, 1);
382 }
383 return npackets;
384}
385
386/**
387 * @brief WILC_WFI_Poll
388 * @details The typical interrupt entry point
389 * @param[in] struct napi_struct *napi :
390 * @param[in] int budget :
391 * @return int : Return 0 on Success.
392 * @author mdaftedar
393 * @date 01 MAR 2012
394 * @version 1.0
395 */
396static void WILC_WFI_RegularInterrupt(int irq, void *dev_id, struct pt_regs *regs)
397{
398 int statusword;
399 struct WILC_WFI_priv *priv;
400 struct WILC_WFI_packet *pkt = NULL;
401 /*
402 * As usual, check the "device" pointer to be sure it is
403 * really interrupting.
404 * Then assign "struct device *dev"
405 */
406 struct net_device *dev = (struct net_device *)dev_id;
407 /* ... and check with hw if it's really ours */
408
409 /* paranoid */
410 if (!dev)
411 return;
412
413 /* Lock the device */
414 priv = netdev_priv(dev);
415 spin_lock(&priv->lock);
416
417 /* retrieve statusword: real netdevices use I/O instructions */
418 statusword = priv->status;
419 priv->status = 0;
420 if (statusword & WILC_WFI_RX_INTR) {
421 /* send it to WILC_WFI_rx for handling */
422 pkt = priv->rx_queue;
423 if (pkt) {
424 priv->rx_queue = pkt->next;
425 WILC_WFI_Rx(dev, pkt);
426 }
427 }
428 if (statusword & WILC_WFI_TX_INTR) {
429 /* a transmission is over: free the skb */
430 WILC_WFI_update_stats(priv->dev->ieee80211_ptr->wiphy, priv->tx_packetlen, WILC_WFI_TX_PKT);
431 dev_kfree_skb(priv->skb);
432 }
433
434 /* Unlock the device and we are done */
435 spin_unlock(&priv->lock);
436 if (pkt)
437 WILC_WFI_ReleaseBuffer(pkt); /* Do this outside the lock! */
438 return;
439}
440/**
441 * @brief WILC_WFI_NapiInterrupt
442 * @details A NAPI interrupt handler
443 * @param[in] irq:
444 * @param[in] dev_id:
445 * @param[in] pt_regs:
446 * @return NONE
447 * @author mdaftedar
448 * @date 01 MAR 2012
449 * @version 1.0
450 */
451static void WILC_WFI_NapiInterrupt(int irq, void *dev_id, struct pt_regs *regs)
452{
453 int statusword;
454 struct WILC_WFI_priv *priv;
455
456 /*
457 * As usual, check the "device" pointer for shared handlers.
458 * Then assign "struct device *dev"
459 */
460 struct net_device *dev = (struct net_device *)dev_id;
461 /* ... and check with hw if it's really ours */
462
463 /* paranoid */
464 if (!dev)
465 return;
466
467 /* Lock the device */
468 priv = netdev_priv(dev);
469 spin_lock(&priv->lock);
470
471 /* retrieve statusword: real netdevices use I/O instructions */
472 statusword = priv->status;
473 priv->status = 0;
474 if (statusword & WILC_WFI_RX_INTR) {
475 WILC_WFI_RxInts(dev, 0); /* Disable further interrupts */
476 napi_schedule(&priv->napi);
477 }
478 if (statusword & WILC_WFI_TX_INTR) {
479 /* a transmission is over: free the skb */
480
481 WILC_WFI_update_stats(priv->dev->ieee80211_ptr->wiphy, priv->tx_packetlen, WILC_WFI_TX_PKT);
482 dev_kfree_skb(priv->skb);
483 }
484
485 /* Unlock the device and we are done */
486 spin_unlock(&priv->lock);
487 return;
488}
489
490/**
491 * @brief MI_WFI_HwTx
492 * @details Transmit a packet (low level interface)
493 * @param[in] buf:
494 * @param[in] len:
495 * @param[in] net_device *dev:
496 * @return NONE
497 * @author mdaftedar
498 * @date 01 MAR 2012
499 * @version 1.0
500 */
501void WILC_WFI_HwTx(char *buf, int len, struct net_device *dev)
502{
503 /*
504 * This function deals with hw details. This interface loops
505 * back the packet to the other WILC_WFI interface (if any).
506 * In other words, this function implements the WILC_WFI behaviour,
507 * while all other procedures are rather device-independent
508 */
509 struct iphdr *ih;
510 struct net_device *dest;
511 struct WILC_WFI_priv *priv;
512 u32 *saddr, *daddr;
513 struct WILC_WFI_packet *tx_buffer;
514
515
516 /* I am paranoid. Ain't I? */
517 if (len < sizeof(struct ethhdr) + sizeof(struct iphdr)) {
518 PRINT_D(RX_DBG, "WILC_WFI: Hmm... packet too short (%i octets)\n",
519 len);
520 return;
521 }
522
523 if (0) { /* enable this conditional to look at the data */
524 int i;
525 PRINT_D(RX_DBG, "len is %i", len);
526 for (i = 14; i < len; i++)
527 PRINT_D(RX_DBG, "TXdata[%d] %02x\n", i, buf[i] & 0xff);
528 /* PRINT_D(RX_DBG, "\n"); */
529 }
530 /*
531 * Ethhdr is 14 bytes, but the kernel arranges for iphdr
532 * to be aligned (i.e., ethhdr is unaligned)
533 */
534 ih = (struct iphdr *)(buf + sizeof(struct ethhdr));
535 saddr = &ih->saddr;
536 daddr = &ih->daddr;
537
538 ((u8 *)saddr)[2] ^= 1; /* change the third octet (class C) */
539 ((u8 *)daddr)[2] ^= 1;
540
541 ih->check = 0; /* and rebuild the checksum (ip needs it) */
542 ih->check = ip_fast_csum((unsigned char *)ih, ih->ihl);
543
544
545 if (dev == WILC_WFI_devs[0])
546 PRINT_D(RX_DBG, "%08x:%05i --> %08x:%05i\n",
547 ntohl(ih->saddr), ntohs(((struct tcphdr *)(ih + 1))->source),
548 ntohl(ih->daddr), ntohs(((struct tcphdr *)(ih + 1))->dest));
549 else
550 PRINT_D(RX_DBG, "%08x:%05i <-- %08x:%05i\n",
551 ntohl(ih->daddr), ntohs(((struct tcphdr *)(ih + 1))->dest),
552 ntohl(ih->saddr), ntohs(((struct tcphdr *)(ih + 1))->source));
553
554 /*
555 * Ok, now the packet is ready for transmission: first simulate a
556 * receive interrupt on the twin device, then a
557 * transmission-done on the transmitting device
558 */
559 dest = WILC_WFI_devs[dev == WILC_WFI_devs[0] ? 1 : 0];
560 priv = netdev_priv(dest);
561
562 tx_buffer = WILC_WFI_GetTxBuffer(dev);
563 tx_buffer->datalen = len;
564 memcpy(tx_buffer->data, buf, len);
565 WILC_WFI_EnqueueBuf(dest, tx_buffer);
566 if (priv->rx_int_enabled) {
567 priv->status |= WILC_WFI_RX_INTR;
568 WILC_WFI_Interrupt(0, dest, NULL);
569 }
570
571 priv = netdev_priv(dev);
572 priv->tx_packetlen = len;
573 priv->tx_packetdata = buf;
574 priv->status |= WILC_WFI_TX_INTR;
575 if (lockup && ((priv->stats.tx_packets + 1) % lockup) == 0) {
576 /* Simulate a dropped transmit interrupt */
577 netif_stop_queue(dev);
578 PRINT_D(RX_DBG, "Simulate lockup at %ld, txp %ld\n", jiffies,
579 (unsigned long) priv->stats.tx_packets);
580 } else
581 WILC_WFI_Interrupt(0, dev, NULL);
582
583}
584
585/**
586 * @brief WILC_WFI_Tx
587 * @details Transmit a packet (called by the kernel)
588 * @param[in] sk_buff *skb:
589 * @param[in] net_device *dev:
590 * @return NONE
591 * @author mdaftedar
592 * @date 01 MAR 2012
593 * @version 1.0
594 */
595int WILC_WFI_Tx(struct sk_buff *skb, struct net_device *dev)
596{
597 int len;
598 char *data, shortpkt[ETH_ZLEN];
599 struct WILC_WFI_priv *priv = netdev_priv(dev);
600
601 /* priv = wiphy_priv(priv->dev->ieee80211_ptr->wiphy); */
602
603 /* if(priv->monitor_flag) */
604 /* mac80211_hwsim_monitor_rx(skb); */
605
606
607 data = skb->data;
608 len = skb->len;
609
610 if (len < ETH_ZLEN) {
611 memset(shortpkt, 0, ETH_ZLEN);
612 memcpy(shortpkt, skb->data, skb->len);
613 len = ETH_ZLEN;
614 data = shortpkt;
615 }
616 dev->trans_start = jiffies; /* save the timestamp */
617
618 /* Remember the skb, so we can free it at interrupt time */
619 priv->skb = skb;
620
621 /* actual deliver of data is device-specific, and not shown here */
622 WILC_WFI_HwTx(data, len, dev);
623
624 return 0; /* Our simple device can not fail */
625}
626
627/**
628 * @brief WILC_WFI_TxTimeout
629 * @details Deal with a transmit timeout.
630 * @param[in] net_device *dev:
631 * @return NONE
632 * @author mdaftedar
633 * @date 01 MAR 2012
634 * @version 1.0
635 */
636void WILC_WFI_TxTimeout(struct net_device *dev)
637{
638 struct WILC_WFI_priv *priv = netdev_priv(dev);
639
640 PRINT_D(RX_DBG, "Transmit timeout at %ld, latency %ld\n", jiffies,
641 jiffies - dev->trans_start);
642 /* Simulate a transmission interrupt to get things moving */
643 priv->status = WILC_WFI_TX_INTR;
644 WILC_WFI_Interrupt(0, dev, NULL);
645 priv->stats.tx_errors++;
646 netif_wake_queue(dev);
647 return;
648}
649
650/**
651 * @brief WILC_WFI_Ioctl
652 * @details Ioctl commands
653 * @param[in] net_device *dev:
654 * @param[in] ifreq *rq
655 * @param[in] cmd:
656 * @return int : Return 0 on Success
657 * @author mdaftedar
658 * @date 01 MAR 2012
659 * @version 1.0
660 */
661int WILC_WFI_Ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
662{
663 PRINT_D(RX_DBG, "ioctl\n");
664 return 0;
665}
666
667/**
668 * @brief WILC_WFI_Stat
669 * @details Return statistics to the caller
670 * @param[in] net_device *dev:
671 * @return WILC_WFI_Stats : Return net_device_stats stucture with the
672 * network device driver private data contents.
673 * @author mdaftedar
674 * @date 01 MAR 2012
675 * @version 1.0
676 */
677struct net_device_stats *WILC_WFI_Stats(struct net_device *dev)
678{
679 struct WILC_WFI_priv *priv = netdev_priv(dev);
680 return &priv->stats;
681}
682
683/**
684 * @brief WILC_WFI_RebuildHeader
685 * @details This function is called to fill up an eth header, since arp is not
686 * available on the interface
687 * @param[in] sk_buff *skb:
688 * @return int : Return 0 on Success
689 * @author mdaftedar
690 * @date 01 MAR 2012
691 * @version 1.0
692 */
693int WILC_WFI_RebuildHeader(struct sk_buff *skb)
694{
695 struct ethhdr *eth = (struct ethhdr *) skb->data;
696 struct net_device *dev = skb->dev;
697
698 memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
699 memcpy(eth->h_dest, dev->dev_addr, dev->addr_len);
700 eth->h_dest[ETH_ALEN - 1] ^= 0x01; /* dest is us xor 1 */
701 return 0;
702}
703/**
704 * @brief WILC_WFI_RebuildHeader
705 * @details This function is called to fill up an eth header, since arp is not
706 * available on the interface
707 * @param[in] sk_buff *skb:
708 * @param[in] struct net_device *dev:
709 * @param[in] unsigned short type:
710 * @param[in] const void *saddr,
711 * @param[in] const void *daddr:
712 * @param[in] unsigned int len
713 * @return int : Return 0 on Success
714 * @author mdaftedar
715 * @date 01 MAR 2012
716 * @version 1.0
717 */
718int WILC_WFI_Header(struct sk_buff *skb, struct net_device *dev,
719 unsigned short type, const void *daddr, const void *saddr,
720 unsigned int len)
721{
722 struct ethhdr *eth = (struct ethhdr *)skb_push(skb, ETH_HLEN);
723
724 eth->h_proto = htons(type);
725 memcpy(eth->h_source, saddr ? saddr : dev->dev_addr, dev->addr_len);
726 memcpy(eth->h_dest, daddr ? daddr : dev->dev_addr, dev->addr_len);
727 eth->h_dest[ETH_ALEN - 1] ^= 0x01; /* dest is us xor 1 */
728 return dev->hard_header_len;
729}
730
731/**
732 * @brief WILC_WFI_ChangeMtu
733 * @details The "change_mtu" method is usually not needed.
734 * If you need it, it must be like this.
735 * @param[in] net_device *dev : Network Device Driver Structure
736 * @param[in] new_mtu :
737 * @return int : Returns 0 on Success.
738 * @author mdaftedar
739 * @date 01 MAR 2012
740 * @version 1.0
741 */
742int WILC_WFI_ChangeMtu(struct net_device *dev, int new_mtu)
743{
744 unsigned long flags;
745 struct WILC_WFI_priv *priv = netdev_priv(dev);
746 spinlock_t *lock = &priv->lock;
747
748 /* check ranges */
749 if ((new_mtu < 68) || (new_mtu > 1500))
750 return -EINVAL;
751 /*
752 * Do anything you need, and the accept the value
753 */
754 spin_lock_irqsave(lock, flags);
755 dev->mtu = new_mtu;
756 spin_unlock_irqrestore(lock, flags);
757 return 0; /* success */
758}
759
760static const struct header_ops WILC_WFI_header_ops = {
761 .create = WILC_WFI_Header,
762 .rebuild = WILC_WFI_RebuildHeader,
763 .cache = NULL, /* disable caching */
764};
765
766
767static const struct net_device_ops WILC_WFI_netdev_ops = {
768 .ndo_open = WILC_WFI_Open,
769 .ndo_stop = WILC_WFI_Release,
770 .ndo_set_config = WILC_WFI_Config,
771 .ndo_start_xmit = WILC_WFI_Tx,
772 .ndo_do_ioctl = WILC_WFI_Ioctl,
773 .ndo_get_stats = WILC_WFI_Stats,
774 .ndo_change_mtu = WILC_WFI_ChangeMtu,
775 .ndo_tx_timeout = WILC_WFI_TxTimeout,
776};
777
778/**
779 * @brief WILC_WFI_Init
780 * @details The init function (sometimes called probe).
781 * It is invoked by register_netdev()
782 * @param[in] net_device *dev:
783 * @return NONE
784 * @author mdaftedar
785 * @date 01 MAR 2012
786 * @version 1.0
787 */
788void WILC_WFI_Init(struct net_device *dev)
789{
790 struct WILC_WFI_priv *priv;
791
792
793 /*
794 * Then, assign other fields in dev, using ether_setup() and some
795 * hand assignments
796 */
797 ether_setup(dev); /* assign some of the fields */
798 /* 1- Allocate space */
799
800 dev->netdev_ops = &WILC_WFI_netdev_ops;
801 dev->header_ops = &WILC_WFI_header_ops;
802 dev->watchdog_timeo = timeout;
803 /* keep the default flags, just add NOARP */
804 dev->flags |= IFF_NOARP;
805 dev->features |= NETIF_F_NO_CSUM;
806 /*
807 * Then, initialize the priv field. This encloses the statistics
808 * and a few private fields.
809 */
810 priv = netdev_priv(dev);
811 memset(priv, 0, sizeof(struct WILC_WFI_priv));
812 priv->dev = dev;
813 netif_napi_add(dev, &priv->napi, WILC_WFI_Poll, 2);
814 /* The last parameter above is the NAPI "weight". */
815 spin_lock_init(&priv->lock);
816 WILC_WFI_RxInts(dev, 1); /* enable receive interrupts */
817 WILC_WFI_SetupPool(dev);
818}
819
820/**
821 * @brief WILC_WFI_Stat
822 * @details Return statistics to the caller
823 * @param[in] net_device *dev:
824 * @return WILC_WFI_Stats : Return net_device_stats stucture with the
825 * network device driver private data contents.
826 * @author mdaftedar
827 * @date 01 MAR 2012
828 * @version 1.0
829 */
830
831void WILC_WFI_Cleanup(void)
832{
833 int i;
834 struct WILC_WFI_priv *priv[2];
835
836 /*if(hwsim_mon!=NULL)
837 * {
838 * PRINT_D(RX_DBG, "Freeing monitor interface\n");
839 * unregister_netdev(hwsim_mon);
840 * free_netdev(hwsim_mon);
841 * }*/
842 for (i = 0; i < 2; i++) {
843 priv[i] = netdev_priv(WILC_WFI_devs[i]);
844
845 if (WILC_WFI_devs[i]) {
846 PRINT_D(RX_DBG, "Unregistering\n");
847 unregister_netdev(WILC_WFI_devs[i]);
848 WILC_WFI_TearDownPool(WILC_WFI_devs[i]);
849 free_netdev(WILC_WFI_devs[i]);
850 PRINT_D(RX_DBG, "[NETDEV]Stopping interface\n");
851 WILC_WFI_DeInitHostInt(WILC_WFI_devs[i]);
852 WILC_WFI_WiphyFree(WILC_WFI_devs[i]);
853 }
854
855 }
856 /* unregister_netdev(hwsim_mon); */
857 WILC_WFI_deinit_mon_interface();
858 return;
859}
860
861
862void StartConfigSim(void);
863
864
865
866
867
868
869
870/**
871 * @brief WILC_WFI_Stat
872 * @details Return statistics to the caller
873 * @param[in] net_device *dev:
874 * @return WILC_WFI_Stats : Return net_device_stats stucture with the
875 * network device driver private data contents.
876 * @author mdaftedar
877 * @date 01 MAR 2012
878 * @version 1.0
879 */
880int WILC_WFI_InitModule(void)
881{
882
883 int result, i, ret = -ENOMEM;
884 struct WILC_WFI_priv *priv[2], *netpriv;
885 struct wireless_dev *wdev;
886 WILC_WFI_Interrupt = use_napi ? WILC_WFI_NapiInterrupt : WILC_WFI_RegularInterrupt;
887 char buf[IFNAMSIZ];
888
889 for (i = 0; i < 2; i++) {
890
891 /* Allocate the net devices */
892 WILC_WFI_devs[i] = alloc_netdev(sizeof(struct WILC_WFI_priv), "wlan%d",
893 WILC_WFI_Init);
894 if (WILC_WFI_devs[i] == NULL)
895 goto out;
896 /* priv[i] = netdev_priv(WILC_WFI_devs[i]); */
897
898 wdev = WILC_WFI_WiphyRegister(WILC_WFI_devs[i]);
899 WILC_WFI_devs[i]->ieee80211_ptr = wdev;
900 netpriv = netdev_priv(WILC_WFI_devs[i]);
901 netpriv->dev->ieee80211_ptr = wdev;
902 netpriv->dev->ml_priv = netpriv;
903 wdev->netdev = netpriv->dev;
904
905 /*Registering the net device*/
906 result = register_netdev(WILC_WFI_devs[i]);
907 if (result)
908 PRINT_D(RX_DBG, "WILC_WFI: error %i registering device \"%s\"\n",
909 result, WILC_WFI_devs[i]->name);
910 else
911 ret = 0;
912 }
913
914
915 /*init atmel driver */
916 priv[0] = netdev_priv(WILC_WFI_devs[0]);
917 priv[1] = netdev_priv(WILC_WFI_devs[1]);
918
919 if (priv[1]->dev->ieee80211_ptr->wiphy->interface_modes && BIT(NL80211_IFTYPE_MONITOR)) {
920 /* snprintf(buf, IFNAMSIZ, "mon.%s", priv[1]->dev->name); */
921 /* WILC_WFI_init_mon_interface(); */
922 /* priv[1]->monitor_flag = 1; */
923
924 }
925 priv[0]->bCfgScanning = false;
926 priv[0]->u32RcvdChCount = 0;
927
928 WILC_memset(priv[0]->au8AssociatedBss, 0xFF, ETH_ALEN);
929
930
931 /* ret = host_int_init(&priv[0]->hWILCWFIDrv); */
932 /*copy handle to the other driver*/
933 /* priv[1]->hWILCWFIDrv = priv[0]->hWILCWFIDrv; */
934 if (ret) {
935 PRINT_ER("Error Init Driver\n");
936 }
937
938
939out:
940 if (ret)
941 WILC_WFI_Cleanup();
942 return ret;
943
944
945}
946
947
948module_init(WILC_WFI_InitModule);
949module_exit(WILC_WFI_Cleanup);
950
951#endif
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index d413fa3861c0..77f320d125e8 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -77,12 +77,12 @@ struct WILC_WFI_stats {
77#define num_reg_frame 2 77#define num_reg_frame 2
78/* 78/*
79 * If you use RX_BH_WORK_QUEUE on LPC3131: You may lose the first interrupt on 79 * If you use RX_BH_WORK_QUEUE on LPC3131: You may lose the first interrupt on
80 * LPC3131 which is important to get the MAC start status when you are blocked inside 80 * LPC3131 which is important to get the MAC start status when you are blocked
81 * linux_wlan_firmware_download() which blocks mac_open(). 81 * inside linux_wlan_firmware_download() which blocks mac_open().
82 */ 82 */
83#if defined (NM73131_0_BOARD) 83#if defined(NM73131_0_BOARD)
84 #define RX_BH_TYPE RX_BH_KTHREAD 84 #define RX_BH_TYPE RX_BH_KTHREAD
85#elif defined (PANDA_BOARD) 85#elif defined(PANDA_BOARD)
86 #define RX_BH_TYPE RX_BH_THREADED_IRQ 86 #define RX_BH_TYPE RX_BH_THREADED_IRQ
87#else 87#else
88 #define RX_BH_TYPE RX_BH_KTHREAD 88 #define RX_BH_TYPE RX_BH_KTHREAD
@@ -95,6 +95,7 @@ struct wilc_wfi_key {
95 int seq_len; 95 int seq_len;
96 u32 cipher; 96 u32 cipher;
97}; 97};
98
98struct wilc_wfi_wep_key { 99struct wilc_wfi_wep_key {
99 u8 *key; 100 u8 *key;
100 u8 key_len; 101 u8 key_len;
@@ -143,14 +144,15 @@ struct WILC_WFI_priv {
143 spinlock_t lock; 144 spinlock_t lock;
144 struct net_device *dev; 145 struct net_device *dev;
145 struct napi_struct napi; 146 struct napi_struct napi;
146 WILC_WFIDrvHandle hWILCWFIDrv; 147 tstrWILC_WFIDrv *hWILCWFIDrv;
147 WILC_WFIDrvHandle hWILCWFIDrv_2; 148 WILC_WFIDrvHandle hWILCWFIDrv_2;
148 tstrHostIFpmkidAttr pmkid_list; 149 tstrHostIFpmkidAttr pmkid_list;
149 struct WILC_WFI_stats netstats; 150 struct WILC_WFI_stats netstats;
150 u8 WILC_WFI_wep_default; 151 u8 WILC_WFI_wep_default;
151 u8 WILC_WFI_wep_key[4][WLAN_KEY_LEN_WEP104]; 152 u8 WILC_WFI_wep_key[4][WLAN_KEY_LEN_WEP104];
152 u8 WILC_WFI_wep_key_len[4]; 153 u8 WILC_WFI_wep_key_len[4];
153 struct net_device *real_ndev; /* The real interface that the monitor is on */ 154 /* The real interface that the monitor is on */
155 struct net_device *real_ndev;
154 struct wilc_wfi_key *wilc_gtk[MAX_NUM_STA]; 156 struct wilc_wfi_key *wilc_gtk[MAX_NUM_STA];
155 struct wilc_wfi_key *wilc_ptk[MAX_NUM_STA]; 157 struct wilc_wfi_key *wilc_ptk[MAX_NUM_STA];
156 u8 wilc_groupkey; 158 u8 wilc_groupkey;
@@ -174,7 +176,7 @@ typedef struct {
174typedef struct { 176typedef struct {
175 uint8_t aSrcAddress[ETH_ALEN]; 177 uint8_t aSrcAddress[ETH_ALEN];
176 uint8_t aBSSID[ETH_ALEN]; 178 uint8_t aBSSID[ETH_ALEN];
177 uint32_t drvHandler; 179 tstrWILC_WFIDrv *drvHandler;
178 struct net_device *wilc_netdev; 180 struct net_device *wilc_netdev;
179} tstrInterfaceInfo; 181} tstrInterfaceInfo;
180typedef struct { 182typedef struct {
diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c
index 3af91f770485..7c53a2bd0381 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -16,7 +16,6 @@
16 * Global 16 * Global
17 * 17 *
18 ********************************************/ 18 ********************************************/
19extern unsigned int int_clrd;
20extern wilc_hif_func_t hif_sdio; 19extern wilc_hif_func_t hif_sdio;
21extern wilc_hif_func_t hif_spi; 20extern wilc_hif_func_t hif_spi;
22extern wilc_cfg_func_t mac_cfg; 21extern wilc_cfg_func_t mac_cfg;
@@ -24,8 +23,6 @@ extern wilc_cfg_func_t mac_cfg;
24extern u8 g_wilc_initialized; /* AMR : 0422 RK3026 Crash issue */ 23extern u8 g_wilc_initialized; /* AMR : 0422 RK3026 Crash issue */
25#endif 24#endif
26extern void WILC_WFI_mgmt_rx(uint8_t *buff, uint32_t size); 25extern void WILC_WFI_mgmt_rx(uint8_t *buff, uint32_t size);
27extern void frmw_to_linux(uint8_t *buff, uint32_t size);
28int sdio_xfer_cnt(void);
29uint32_t wilc_get_chipid(uint8_t update); 26uint32_t wilc_get_chipid(uint8_t update);
30u16 Set_machw_change_vir_if(bool bValue); 27u16 Set_machw_change_vir_if(bool bValue);
31 28
@@ -118,18 +115,15 @@ static void wilc_debug(uint32_t flag, char *fmt, ...)
118{ 115{
119 char buf[256]; 116 char buf[256];
120 va_list args; 117 va_list args;
121 int len;
122 118
123 if (flag & dbgflag) { 119 if (flag & dbgflag) {
124 va_start(args, fmt); 120 va_start(args, fmt);
125 len = vsprintf(buf, fmt, args); 121 vsprintf(buf, fmt, args);
126 va_end(args); 122 va_end(args);
127 123
128 if (g_wlan.os_func.os_debug) 124 if (g_wlan.os_func.os_debug)
129 g_wlan.os_func.os_debug(buf); 125 g_wlan.os_func.os_debug(buf);
130 } 126 }
131
132 return;
133} 127}
134 128
135static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP; 129static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
@@ -292,13 +286,13 @@ uint32_t Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
292 286
293#ifdef TCP_ACK_FILTER 287#ifdef TCP_ACK_FILTER
294struct Ack_session_info; 288struct Ack_session_info;
295typedef struct Ack_session_info { 289struct Ack_session_info {
296 uint32_t Ack_seq_num; 290 uint32_t Ack_seq_num;
297 uint32_t Bigger_Ack_num; 291 uint32_t Bigger_Ack_num;
298 uint16_t src_port; 292 uint16_t src_port;
299 uint16_t dst_port; 293 uint16_t dst_port;
300 uint16_t status; 294 uint16_t status;
301} Ack_session_info_t; 295};
302 296
303typedef struct { 297typedef struct {
304 uint32_t ack_num; 298 uint32_t ack_num;
@@ -319,7 +313,7 @@ struct Ack_session_info *Alloc_head;
319 313
320#define MAX_TCP_SESSION 25 314#define MAX_TCP_SESSION 25
321#define MAX_PENDING_ACKS 256 315#define MAX_PENDING_ACKS 256
322Ack_session_info_t Acks_keep_track_info[2 * MAX_TCP_SESSION]; 316struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
323Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS]; 317Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
324 318
325uint32_t PendingAcks_arrBase; 319uint32_t PendingAcks_arrBase;
@@ -451,7 +445,7 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(void)
451 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) { 445 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
452 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) { 446 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
453 struct txq_entry_t *tqe; 447 struct txq_entry_t *tqe;
454 PRINT_D(TCP_ENH, "DROP ACK: %u \n", Pending_Acks_info[i].ack_num); 448 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
455 tqe = Pending_Acks_info[i].txqe; 449 tqe = Pending_Acks_info[i].txqe;
456 if (tqe) { 450 if (tqe) {
457 wilc_wlan_txq_remove(tqe); 451 wilc_wlan_txq_remove(tqe);
@@ -467,11 +461,10 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(void)
467 Pending_Acks = 0; 461 Pending_Acks = 0;
468 Opened_TCP_session = 0; 462 Opened_TCP_session = 0;
469 463
470 if (PendingAcks_arrBase == 0) { 464 if (PendingAcks_arrBase == 0)
471 PendingAcks_arrBase = MAX_TCP_SESSION; 465 PendingAcks_arrBase = MAX_TCP_SESSION;
472 } else { 466 else
473 PendingAcks_arrBase = 0; 467 PendingAcks_arrBase = 0;
474 }
475 468
476 469
477 p->os_func.os_spin_unlock(p->txq_spinlock, &p->txq_spinlock_flags); 470 p->os_func.os_spin_unlock(p->txq_spinlock, &p->txq_spinlock_flags);
@@ -735,7 +728,7 @@ INLINE void chip_wakeup(void)
735 728
736 do { 729 do {
737 /* Wait for the chip to stabilize*/ 730 /* Wait for the chip to stabilize*/
738 WILC_Sleep(2); 731 usleep_range(2 * 1000, 2 * 1000);
739 /* Make sure chip is awake. This is an extra step that can be removed */ 732 /* Make sure chip is awake. This is an extra step that can be removed */
740 /* later to avoid the bus access overhead */ 733 /* later to avoid the bus access overhead */
741 if ((wilc_get_chipid(true) == 0)) { 734 if ((wilc_get_chipid(true) == 0)) {
@@ -758,7 +751,7 @@ INLINE void chip_wakeup(void)
758 /* If still off, redo the wake up sequence */ 751 /* If still off, redo the wake up sequence */
759 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) { 752 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
760 /* Wait for the chip to stabilize*/ 753 /* Wait for the chip to stabilize*/
761 WILC_Sleep(2); 754 usleep_range(2 * 1000, 2 * 1000);
762 755
763 /* Make sure chip is awake. This is an extra step that can be removed */ 756 /* Make sure chip is awake. This is an extra step that can be removed */
764 /* later to avoid the bus access overhead */ 757 /* later to avoid the bus access overhead */
@@ -996,7 +989,7 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
996 /** 989 /**
997 * wait for vmm table is ready 990 * wait for vmm table is ready
998 **/ 991 **/
999 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait... \n"); 992 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
1000 release_bus(RELEASE_ALLOW_SLEEP); 993 release_bus(RELEASE_ALLOW_SLEEP);
1001 p->os_func.os_sleep(3); /* wait 3 ms */ 994 p->os_func.os_sleep(3); /* wait 3 ms */
1002 acquire_bus(ACQUIRE_AND_WAKEUP); 995 acquire_bus(ACQUIRE_AND_WAKEUP);
@@ -1063,7 +1056,7 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
1063 } 1056 }
1064 1057
1065 if (entries == 0) { 1058 if (entries == 0) {
1066 PRINT_WRN(GENERIC_DBG, "[wilc txq]: no more buffer in the chip (reg: %08x), retry later [[ %d, %x ]] \n", reg, i, vmm_table[i - 1]); 1059 PRINT_WRN(GENERIC_DBG, "[wilc txq]: no more buffer in the chip (reg: %08x), retry later [[ %d, %x ]]\n", reg, i, vmm_table[i - 1]);
1067 1060
1068 /* undo the transaction. */ 1061 /* undo the transaction. */
1069 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg); 1062 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, &reg);
@@ -1114,11 +1107,10 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
1114 /*Bug3959: transmitting mgmt frames received from host*/ 1107 /*Bug3959: transmitting mgmt frames received from host*/
1115 /*setting bit 30 in the host header to indicate mgmt frame*/ 1108 /*setting bit 30 in the host header to indicate mgmt frame*/
1116#ifdef WILC_AP_EXTERNAL_MLME 1109#ifdef WILC_AP_EXTERNAL_MLME
1117 if (tqe->type == WILC_MGMT_PKT) { 1110 if (tqe->type == WILC_MGMT_PKT)
1118 header |= (1 << 30); 1111 header |= (1 << 30);
1119 } else { 1112 else
1120 header &= ~(1 << 30); 1113 header &= ~(1 << 30);
1121 }
1122#endif 1114#endif
1123 1115
1124#ifdef BIG_ENDIAN 1116#ifdef BIG_ENDIAN
@@ -1213,7 +1205,7 @@ static void wilc_wlan_handle_rxq(void)
1213 1205
1214 do { 1206 do {
1215 if (p->quit) { 1207 if (p->quit) {
1216 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function \n"); 1208 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
1217 p->os_func.os_signal(p->cfg_wait); 1209 p->os_func.os_signal(p->cfg_wait);
1218 break; 1210 break;
1219 } 1211 }
@@ -1330,8 +1322,7 @@ static void wilc_wlan_handle_rxq(void)
1330 } while (1); 1322 } while (1);
1331 1323
1332 p->rxq_exit = 1; 1324 p->rxq_exit = 1;
1333 PRINT_D(RX_DBG, "THREAD: Exiting RX thread \n"); 1325 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
1334 return;
1335} 1326}
1336 1327
1337/******************************************** 1328/********************************************
@@ -1414,7 +1405,7 @@ static void wilc_wlan_handle_isr_ext(uint32_t int_status)
1414 buffer = p->os_func.os_malloc(size); 1405 buffer = p->os_func.os_malloc(size);
1415 if (buffer == NULL) { 1406 if (buffer == NULL) {
1416 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size); 1407 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
1417 WILC_Sleep(100); 1408 usleep_range(100 * 1000, 100 * 1000);
1418 goto _end_; 1409 goto _end_;
1419 } 1410 }
1420#endif 1411#endif
@@ -1545,11 +1536,10 @@ static int wilc_wlan_firmware_download(const uint8_t *buffer, uint32_t buffer_si
1545 acquire_bus(ACQUIRE_ONLY); 1536 acquire_bus(ACQUIRE_ONLY);
1546 offset += 8; 1537 offset += 8;
1547 while (((int)size) && (offset < buffer_size)) { 1538 while (((int)size) && (offset < buffer_size)) {
1548 if (size <= blksz) { 1539 if (size <= blksz)
1549 size2 = size; 1540 size2 = size;
1550 } else { 1541 else
1551 size2 = blksz; 1542 size2 = blksz;
1552 }
1553 /* Copy firmware into a DMA coherent buffer */ 1543 /* Copy firmware into a DMA coherent buffer */
1554 memcpy(dma_buffer, &buffer[offset], size2); 1544 memcpy(dma_buffer, &buffer[offset], size2);
1555 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2); 1545 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
@@ -1782,7 +1772,7 @@ static int wilc_wlan_stop(void)
1782/******************************************************************************/ 1772/******************************************************************************/
1783 reg = ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 8) | (1 << 9) | (1 << 26) | (1 << 29) | (1 << 30) | (1 << 31)); /**/ 1773 reg = ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 8) | (1 << 9) | (1 << 26) | (1 << 29) | (1 << 30) | (1 << 31)); /**/
1784 /**/ 1774 /**/
1785 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/ 1775 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
1786 reg = ~(1 << 10); /**/ 1776 reg = ~(1 << 10); /**/
1787 /**/ 1777 /**/
1788 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/ 1778 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
@@ -2306,11 +2296,10 @@ u16 Set_machw_change_vir_if(bool bValue)
2306 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n"); 2296 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
2307 } 2297 }
2308 2298
2309 if (bValue) { 2299 if (bValue)
2310 reg |= (BIT31); 2300 reg |= (BIT31);
2311 } else { 2301 else
2312 reg &= ~(BIT31); 2302 reg &= ~(BIT31);
2313 }
2314 2303
2315 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg); 2304 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2316 2305
diff --git a/drivers/staging/wilc1000/wilc_wlan.h b/drivers/staging/wilc1000/wilc_wlan.h
index 0ba7ec69e2b4..244f7108ae92 100644
--- a/drivers/staging/wilc1000/wilc_wlan.h
+++ b/drivers/staging/wilc1000/wilc_wlan.h
@@ -1,7 +1,7 @@
1#ifndef WILC_WLAN_H 1#ifndef WILC_WLAN_H
2#define WILC_WLAN_H 2#define WILC_WLAN_H
3 3
4#include "wilc_type.h" 4#include "wilc_oswrapper.h"
5 5
6 6
7#define ISWILC1000(id) (((id & 0xfffff000) == 0x100000) ? 1 : 0) 7#define ISWILC1000(id) (((id & 0xfffff000) == 0x100000) ? 1 : 0)
diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.c b/drivers/staging/wilc1000/wilc_wlan_cfg.c
index 3cffe55b3a93..e2842d37b078 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.c
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.c
@@ -363,8 +363,6 @@ static void wilc_wlan_parse_response_frame(uint8_t *info, int size)
363 size -= (2 + len); 363 size -= (2 + len);
364 info += (2 + len); 364 info += (2 + len);
365 } 365 }
366
367 return;
368} 366}
369 367
370static int wilc_wlan_parse_info_frame(uint8_t *info, int size) 368static int wilc_wlan_parse_info_frame(uint8_t *info, int size)
@@ -513,7 +511,6 @@ static int wilc_wlan_cfg_indicate_rx(uint8_t *frame, int size, wilc_cfg_rsp_t *r
513 int ret = 1; 511 int ret = 1;
514 uint8_t msg_type; 512 uint8_t msg_type;
515 uint8_t msg_id; 513 uint8_t msg_id;
516 uint16_t msg_len;
517 #ifdef WILC_FULLY_HOSTING_AP 514 #ifdef WILC_FULLY_HOSTING_AP
518 u32 *ptru32Frame; 515 u32 *ptru32Frame;
519 bool bStatus = frame[2]; 516 bool bStatus = frame[2];
@@ -528,11 +525,6 @@ static int wilc_wlan_cfg_indicate_rx(uint8_t *frame, int size, wilc_cfg_rsp_t *r
528 525
529 msg_type = frame[0]; 526 msg_type = frame[0];
530 msg_id = frame[1]; /* seq no */ 527 msg_id = frame[1]; /* seq no */
531#ifdef BIG_ENDIAN
532 msg_len = (frame[2] << 8) | frame[3];
533#else
534 msg_len = (frame[3] << 8) | frame[2];
535#endif
536 frame += 4; 528 frame += 4;
537 size -= 4; 529 size -= 4;
538 530
@@ -557,7 +549,7 @@ static int wilc_wlan_cfg_indicate_rx(uint8_t *frame, int size, wilc_cfg_rsp_t *r
557 549
558 case 'L': 550 case 'L':
559#ifndef SWITCH_LOG_TERMINAL 551#ifndef SWITCH_LOG_TERMINAL
560 PRINT_ER("Unexpected firmware log message received \n"); 552 PRINT_ER("Unexpected firmware log message received\n");
561#else 553#else
562 PRINT_D(FIRM_DBG, "\nFIRMWARE LOGS :\n<<\n%s\n>>\n", frame); 554 PRINT_D(FIRM_DBG, "\nFIRMWARE LOGS :\n<<\n%s\n>>\n", frame);
563 break; 555 break;
@@ -572,18 +564,18 @@ static int wilc_wlan_cfg_indicate_rx(uint8_t *frame, int size, wilc_cfg_rsp_t *r
572#endif 564#endif
573/*bug3819:*/ 565/*bug3819:*/
574 case 'S': 566 case 'S':
575 PRINT_INFO(RX_DBG, "Scan Notification Received \n"); 567 PRINT_INFO(RX_DBG, "Scan Notification Received\n");
576 host_int_ScanCompleteReceived(frame - 4, size + 4); 568 host_int_ScanCompleteReceived(frame - 4, size + 4);
577 break; 569 break;
578 570
579#ifdef WILC_FULLY_HOSTING_AP 571#ifdef WILC_FULLY_HOSTING_AP
580 case 'T': 572 case 'T':
581 PRINT_INFO(RX_DBG, "TBTT Notification Received \n"); 573 PRINT_INFO(RX_DBG, "TBTT Notification Received\n");
582 process_tbtt_isr(); 574 process_tbtt_isr();
583 break; 575 break;
584 576
585 case 'A': 577 case 'A':
586 PRINT_INFO(RX_DBG, "HOSTAPD ACK Notification Received \n"); 578 PRINT_INFO(RX_DBG, "HOSTAPD ACK Notification Received\n");
587 WILC_mgm_HOSTAPD_ACK(ptru32Frame, bStatus); 579 WILC_mgm_HOSTAPD_ACK(ptru32Frame, bStatus);
588 break; 580 break;
589#endif 581#endif
diff --git a/drivers/staging/wilc1000/wilc_wlan_if.h b/drivers/staging/wilc1000/wilc_wlan_if.h
index 8ed51e385118..5cf74e4c4a70 100644
--- a/drivers/staging/wilc1000/wilc_wlan_if.h
+++ b/drivers/staging/wilc1000/wilc_wlan_if.h
@@ -20,7 +20,7 @@
20/* #define USE_OLD_SPI_SW */ 20/* #define USE_OLD_SPI_SW */
21 21
22 22
23#include "wilc_type.h" 23#include "wilc_oswrapper.h"
24#include "linux_wlan_common.h" 24#include "linux_wlan_common.h"
25 25
26 26
@@ -43,8 +43,8 @@
43 ********************************************/ 43 ********************************************/
44 44
45#define HIF_SDIO (0) 45#define HIF_SDIO (0)
46#define HIF_SPI (1 << 0) 46#define HIF_SPI BIT(0)
47#define HIF_SDIO_GPIO_IRQ (1 << 2) 47#define HIF_SDIO_GPIO_IRQ BIT(2)
48 48
49 49
50/******************************************** 50/********************************************
diff --git a/drivers/staging/xgifb/Makefile b/drivers/staging/xgifb/Makefile
index 55e519905346..964a843c4521 100644
--- a/drivers/staging/xgifb/Makefile
+++ b/drivers/staging/xgifb/Makefile
@@ -1,4 +1,4 @@
1obj-$(CONFIG_FB_XGI) += xgifb.o 1obj-$(CONFIG_FB_XGI) += xgifb.o
2 2
3xgifb-y := XGI_main_26.o vb_init.o vb_setmode.o vb_util.o 3xgifb-y := XGI_main_26.o vb_init.o vb_setmode.o
4 4
diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c
index 943d463cf193..5a6251a45112 100644
--- a/drivers/staging/xgifb/XGI_main_26.c
+++ b/drivers/staging/xgifb/XGI_main_26.c
@@ -18,8 +18,8 @@
18#define Index_CR_GPIO_Reg1 0x48 18#define Index_CR_GPIO_Reg1 0x48
19#define Index_CR_GPIO_Reg3 0x4a 19#define Index_CR_GPIO_Reg3 0x4a
20 20
21#define GPIOG_EN (1<<6) 21#define GPIOG_EN BIT(6)
22#define GPIOG_READ (1<<1) 22#define GPIOG_READ BIT(1)
23 23
24static char *forcecrt2type; 24static char *forcecrt2type;
25static char *mode; 25static char *mode;
@@ -29,7 +29,7 @@ static unsigned int refresh_rate;
29/* -------------------- Macro definitions ---------------------------- */ 29/* -------------------- Macro definitions ---------------------------- */
30 30
31#ifdef DEBUG 31#ifdef DEBUG
32static void dumpVGAReg(void) 32static void dumpVGAReg(struct xgifb_video_info *xgifb_info)
33{ 33{
34 u8 i, reg; 34 u8 i, reg;
35 35
@@ -48,7 +48,7 @@ static void dumpVGAReg(void)
48 } 48 }
49} 49}
50#else 50#else
51static inline void dumpVGAReg(void) 51static inline void dumpVGAReg(struct xgifb_video_info *xgifb_info)
52{ 52{
53} 53}
54#endif 54#endif
@@ -1073,7 +1073,7 @@ static int XGIfb_do_set_var(struct fb_var_screeninfo *var, int isactive,
1073 } 1073 }
1074 XGIfb_bpp_to_var(xgifb_info, var); /*update ARGB info*/ 1074 XGIfb_bpp_to_var(xgifb_info, var); /*update ARGB info*/
1075 1075
1076 dumpVGAReg(); 1076 dumpVGAReg(xgifb_info);
1077 return 0; 1077 return 0;
1078} 1078}
1079 1079
@@ -2019,7 +2019,7 @@ static int xgifb_probe(struct pci_dev *pdev,
2019 goto error_mtrr; 2019 goto error_mtrr;
2020 } 2020 }
2021 2021
2022 dumpVGAReg(); 2022 dumpVGAReg(xgifb_info);
2023 2023
2024 return 0; 2024 return 0;
2025 2025
diff --git a/drivers/staging/xgifb/vb_init.h b/drivers/staging/xgifb/vb_init.h
index 24573026a7c0..500cabe41a3c 100644
--- a/drivers/staging/xgifb/vb_init.h
+++ b/drivers/staging/xgifb/vb_init.h
@@ -1,6 +1,6 @@
1#ifndef _VBINIT_ 1#ifndef _VBINIT_
2#define _VBINIT_ 2#define _VBINIT_
3extern unsigned char XGIInitNew(struct pci_dev *pdev); 3unsigned char XGIInitNew(struct pci_dev *pdev);
4extern void XGIRegInit(struct vb_device_info *, unsigned long); 4void XGIRegInit(struct vb_device_info *, unsigned long);
5#endif 5#endif
6 6
diff --git a/drivers/staging/xgifb/vb_setmode.h b/drivers/staging/xgifb/vb_setmode.h
index 5301bec6440d..6f082a7a5a4a 100644
--- a/drivers/staging/xgifb/vb_setmode.h
+++ b/drivers/staging/xgifb/vb_setmode.h
@@ -1,23 +1,23 @@
1#ifndef _VBSETMODE_ 1#ifndef _VBSETMODE_
2#define _VBSETMODE_ 2#define _VBSETMODE_
3 3
4extern void InitTo330Pointer(unsigned char, struct vb_device_info *); 4void InitTo330Pointer(unsigned char, struct vb_device_info *);
5extern void XGI_UnLockCRT2(struct vb_device_info *); 5void XGI_UnLockCRT2(struct vb_device_info *);
6extern void XGI_LockCRT2(struct vb_device_info *); 6void XGI_LockCRT2(struct vb_device_info *);
7extern void XGI_DisplayOff(struct xgifb_video_info *, 7void XGI_DisplayOff(struct xgifb_video_info *,
8 struct xgi_hw_device_info *, 8 struct xgi_hw_device_info *,
9 struct vb_device_info *); 9 struct vb_device_info *);
10extern void XGI_GetVBType(struct vb_device_info *); 10void XGI_GetVBType(struct vb_device_info *);
11extern void XGI_SenseCRT1(struct vb_device_info *); 11void XGI_SenseCRT1(struct vb_device_info *);
12extern unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info, 12unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
13 struct xgi_hw_device_info *HwDeviceExtension, 13 struct xgi_hw_device_info *HwDeviceExtension,
14 unsigned short ModeNo); 14 unsigned short ModeNo);
15 15
16extern unsigned char XGI_SearchModeID(unsigned short ModeNo, 16unsigned char XGI_SearchModeID(unsigned short ModeNo,
17 unsigned short *ModeIdIndex); 17 unsigned short *ModeIdIndex);
18extern unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE, 18unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
19 unsigned short ModeNo, 19 unsigned short ModeNo,
20 unsigned short ModeIdIndex, 20 unsigned short ModeIdIndex,
21 struct vb_device_info *); 21 struct vb_device_info *);
22 22
23#endif 23#endif
diff --git a/drivers/staging/xgifb/vb_util.c b/drivers/staging/xgifb/vb_util.c
deleted file mode 100644
index be3437ca339e..000000000000
--- a/drivers/staging/xgifb/vb_util.c
+++ /dev/null
@@ -1,42 +0,0 @@
1#include "vgatypes.h"
2#include "vb_util.h"
3
4void xgifb_reg_set(unsigned long port, u8 index, u8 data)
5{
6 outb(index, port);
7 outb(data, port + 1);
8}
9
10u8 xgifb_reg_get(unsigned long port, u8 index)
11{
12 outb(index, port);
13 return inb(port + 1);
14}
15
16void xgifb_reg_and_or(unsigned long port, u8 index,
17 unsigned data_and, unsigned data_or)
18{
19 u8 temp;
20
21 temp = xgifb_reg_get(port, index); /* XGINew_Part1Port index 02 */
22 temp = (temp & data_and) | data_or;
23 xgifb_reg_set(port, index, temp);
24}
25
26void xgifb_reg_and(unsigned long port, u8 index, unsigned data_and)
27{
28 u8 temp;
29
30 temp = xgifb_reg_get(port, index); /* XGINew_Part1Port index 02 */
31 temp &= data_and;
32 xgifb_reg_set(port, index, temp);
33}
34
35void xgifb_reg_or(unsigned long port, u8 index, unsigned data_or)
36{
37 u8 temp;
38
39 temp = xgifb_reg_get(port, index); /* XGINew_Part1Port index 02 */
40 temp |= data_or;
41 xgifb_reg_set(port, index, temp);
42}
diff --git a/drivers/staging/xgifb/vb_util.h b/drivers/staging/xgifb/vb_util.h
index 9161de1d37dd..7bd395fb31b2 100644
--- a/drivers/staging/xgifb/vb_util.h
+++ b/drivers/staging/xgifb/vb_util.h
@@ -1,9 +1,43 @@
1#ifndef _VBUTIL_ 1#ifndef _VBUTIL_
2#define _VBUTIL_ 2#define _VBUTIL_
3extern void xgifb_reg_set(unsigned long, u8, u8); 3static inline void xgifb_reg_set(unsigned long port, u8 index, u8 data)
4extern u8 xgifb_reg_get(unsigned long, u8); 4{
5extern void xgifb_reg_or(unsigned long, u8, unsigned); 5 outb(index, port);
6extern void xgifb_reg_and(unsigned long, u8, unsigned); 6 outb(data, port + 1);
7extern void xgifb_reg_and_or(unsigned long, u8, unsigned, unsigned); 7}
8
9static inline u8 xgifb_reg_get(unsigned long port, u8 index)
10{
11 outb(index, port);
12 return inb(port + 1);
13}
14
15static inline void xgifb_reg_and_or(unsigned long port, u8 index,
16 unsigned data_and, unsigned data_or)
17{
18 u8 temp;
19
20 temp = xgifb_reg_get(port, index);
21 temp = (temp & data_and) | data_or;
22 xgifb_reg_set(port, index, temp);
23}
24
25static inline void xgifb_reg_and(unsigned long port, u8 index, unsigned data_and)
26{
27 u8 temp;
28
29 temp = xgifb_reg_get(port, index);
30 temp &= data_and;
31 xgifb_reg_set(port, index, temp);
32}
33
34static inline void xgifb_reg_or(unsigned long port, u8 index, unsigned data_or)
35{
36 u8 temp;
37
38 temp = xgifb_reg_get(port, index);
39 temp |= data_or;
40 xgifb_reg_set(port, index, temp);
41}
8#endif 42#endif
9 43
diff --git a/drivers/video/fbdev/Kconfig b/drivers/video/fbdev/Kconfig
index f888561568d9..811acfc6048e 100644
--- a/drivers/video/fbdev/Kconfig
+++ b/drivers/video/fbdev/Kconfig
@@ -2475,3 +2475,17 @@ config FB_SSD1307
2475 help 2475 help
2476 This driver implements support for the Solomon SSD1307 2476 This driver implements support for the Solomon SSD1307
2477 OLED controller over I2C. 2477 OLED controller over I2C.
2478
2479config FB_SM712
2480 tristate "Silicon Motion SM712 framebuffer support"
2481 depends on FB && PCI
2482 select FB_CFB_FILLRECT
2483 select FB_CFB_COPYAREA
2484 select FB_CFB_IMAGEBLIT
2485 help
2486 Frame buffer driver for the Silicon Motion SM710, SM712, SM721
2487 and SM722 chips.
2488
2489 This driver is also available as a module. The module will be
2490 called sm712fb. If you want to compile it as a module, say M
2491 here and read <file:Documentation/kbuild/modules.txt>.
diff --git a/drivers/video/fbdev/Makefile b/drivers/video/fbdev/Makefile
index cecea5063a80..50ed1b4fc2bf 100644
--- a/drivers/video/fbdev/Makefile
+++ b/drivers/video/fbdev/Makefile
@@ -131,6 +131,7 @@ obj-$(CONFIG_FB_JZ4740) += jz4740_fb.o
131obj-$(CONFIG_FB_PUV3_UNIGFX) += fb-puv3.o 131obj-$(CONFIG_FB_PUV3_UNIGFX) += fb-puv3.o
132obj-$(CONFIG_FB_HYPERV) += hyperv_fb.o 132obj-$(CONFIG_FB_HYPERV) += hyperv_fb.o
133obj-$(CONFIG_FB_OPENCORES) += ocfb.o 133obj-$(CONFIG_FB_OPENCORES) += ocfb.o
134obj-$(CONFIG_FB_SM712) += sm712fb.o
134 135
135# Platform or fallback drivers go here 136# Platform or fallback drivers go here
136obj-$(CONFIG_FB_UVESA) += uvesafb.o 137obj-$(CONFIG_FB_UVESA) += uvesafb.o
diff --git a/drivers/staging/sm7xxfb/sm7xx.h b/drivers/video/fbdev/sm712.h
index 4bed0946c1b1..aad1cc4be34a 100644
--- a/drivers/staging/sm7xxfb/sm7xx.h
+++ b/drivers/video/fbdev/sm712.h
@@ -13,8 +13,6 @@
13 * more details. 13 * more details.
14 */ 14 */
15 15
16#define NR_PALETTE 256
17
18#define FB_ACCEL_SMI_LYNX 88 16#define FB_ACCEL_SMI_LYNX 88
19 17
20#define SCREEN_X_RES 1024 18#define SCREEN_X_RES 1024
@@ -31,12 +29,8 @@
31 29
32extern void __iomem *smtc_regbaseaddress; 30extern void __iomem *smtc_regbaseaddress;
33#define smtc_mmiowb(dat, reg) writeb(dat, smtc_regbaseaddress + reg) 31#define smtc_mmiowb(dat, reg) writeb(dat, smtc_regbaseaddress + reg)
34#define smtc_mmioww(dat, reg) writew(dat, smtc_regbaseaddress + reg)
35#define smtc_mmiowl(dat, reg) writel(dat, smtc_regbaseaddress + reg)
36 32
37#define smtc_mmiorb(reg) readb(smtc_regbaseaddress + reg) 33#define smtc_mmiorb(reg) readb(smtc_regbaseaddress + reg)
38#define smtc_mmiorw(reg) readw(smtc_regbaseaddress + reg)
39#define smtc_mmiorl(reg) readl(smtc_regbaseaddress + reg)
40 34
41#define SIZE_SR00_SR04 (0x04 - 0x00 + 1) 35#define SIZE_SR00_SR04 (0x04 - 0x00 + 1)
42#define SIZE_SR10_SR24 (0x24 - 0x10 + 1) 36#define SIZE_SR10_SR24 (0x24 - 0x10 + 1)
@@ -48,8 +42,6 @@ extern void __iomem *smtc_regbaseaddress;
48#define SIZE_CR00_CR18 (0x18 - 0x00 + 1) 42#define SIZE_CR00_CR18 (0x18 - 0x00 + 1)
49#define SIZE_CR30_CR4D (0x4D - 0x30 + 1) 43#define SIZE_CR30_CR4D (0x4D - 0x30 + 1)
50#define SIZE_CR90_CRA7 (0xA7 - 0x90 + 1) 44#define SIZE_CR90_CRA7 (0xA7 - 0x90 + 1)
51#define SIZE_VPR (0x6C + 1)
52#define SIZE_DPR (0x44 + 1)
53 45
54static inline void smtc_crtcw(int reg, int val) 46static inline void smtc_crtcw(int reg, int val)
55{ 47{
@@ -57,24 +49,12 @@ static inline void smtc_crtcw(int reg, int val)
57 smtc_mmiowb(val, 0x3d5); 49 smtc_mmiowb(val, 0x3d5);
58} 50}
59 51
60static inline unsigned int smtc_crtcr(int reg)
61{
62 smtc_mmiowb(reg, 0x3d4);
63 return smtc_mmiorb(0x3d5);
64}
65
66static inline void smtc_grphw(int reg, int val) 52static inline void smtc_grphw(int reg, int val)
67{ 53{
68 smtc_mmiowb(reg, 0x3ce); 54 smtc_mmiowb(reg, 0x3ce);
69 smtc_mmiowb(val, 0x3cf); 55 smtc_mmiowb(val, 0x3cf);
70} 56}
71 57
72static inline unsigned int smtc_grphr(int reg)
73{
74 smtc_mmiowb(reg, 0x3ce);
75 return smtc_mmiorb(0x3cf);
76}
77
78static inline void smtc_attrw(int reg, int val) 58static inline void smtc_attrw(int reg, int val)
79{ 59{
80 smtc_mmiorb(0x3da); 60 smtc_mmiorb(0x3da);
@@ -115,3 +95,22 @@ struct modeinit {
115 unsigned char init_cr30_cr4d[SIZE_CR30_CR4D]; 95 unsigned char init_cr30_cr4d[SIZE_CR30_CR4D];
116 unsigned char init_cr90_cra7[SIZE_CR90_CRA7]; 96 unsigned char init_cr90_cra7[SIZE_CR90_CRA7];
117}; 97};
98
99#ifdef __BIG_ENDIAN
100#define pal_rgb(r, g, b, val) (((r & 0xf800) >> 8) | \
101 ((g & 0xe000) >> 13) | \
102 ((g & 0x1c00) << 3) | \
103 ((b & 0xf800) >> 3))
104#define big_addr 0x800000
105#define mmio_addr 0x00800000
106#define seqw17() smtc_seqw(0x17, 0x30)
107#define big_pixel_depth(p, d) {if (p == 24) {p = 32; d = 32; } }
108#define big_swap(p) ((p & 0xff00ff00 >> 8) | (p & 0x00ff00ff << 8))
109#else
110#define pal_rgb(r, g, b, val) val
111#define big_addr 0
112#define mmio_addr 0x00c00000
113#define seqw17() do { } while (0)
114#define big_pixel_depth(p, d) do { } while (0)
115#define big_swap(p) p
116#endif
diff --git a/drivers/staging/sm7xxfb/sm7xxfb.c b/drivers/video/fbdev/sm712fb.c
index 2ff4fe73d148..629bfa2d2f51 100644
--- a/drivers/staging/sm7xxfb/sm7xxfb.c
+++ b/drivers/video/fbdev/sm712fb.c
@@ -32,7 +32,7 @@
32#include <linux/pm.h> 32#include <linux/pm.h>
33#endif 33#endif
34 34
35#include "sm7xx.h" 35#include "sm712.h"
36 36
37/* 37/*
38* Private structure 38* Private structure
@@ -923,25 +923,14 @@ static int smtc_setcolreg(unsigned regno, unsigned red, unsigned green,
923 val = chan_to_field(red, &sfb->fb->var.red); 923 val = chan_to_field(red, &sfb->fb->var.red);
924 val |= chan_to_field(green, &sfb->fb->var.green); 924 val |= chan_to_field(green, &sfb->fb->var.green);
925 val |= chan_to_field(blue, &sfb->fb->var.blue); 925 val |= chan_to_field(blue, &sfb->fb->var.blue);
926#ifdef __BIG_ENDIAN 926 pal[regno] = pal_rgb(red, green, blue, val);
927 pal[regno] = ((red & 0xf800) >> 8) |
928 ((green & 0xe000) >> 13) |
929 ((green & 0x1c00) << 3) |
930 ((blue & 0xf800) >> 3);
931#else
932 pal[regno] = val;
933#endif
934 } else { 927 } else {
935 u32 *pal = sfb->fb->pseudo_palette; 928 u32 *pal = sfb->fb->pseudo_palette;
936 929
937 val = chan_to_field(red, &sfb->fb->var.red); 930 val = chan_to_field(red, &sfb->fb->var.red);
938 val |= chan_to_field(green, &sfb->fb->var.green); 931 val |= chan_to_field(green, &sfb->fb->var.green);
939 val |= chan_to_field(blue, &sfb->fb->var.blue); 932 val |= chan_to_field(blue, &sfb->fb->var.blue);
940#ifdef __BIG_ENDIAN 933 pal[regno] = big_swap(val);
941 val = (val & 0xff00ff00 >> 8) |
942 (val & 0x00ff00ff << 8);
943#endif
944 pal[regno] = val;
945 } 934 }
946 break; 935 break;
947 936
@@ -957,7 +946,6 @@ static int smtc_setcolreg(unsigned regno, unsigned red, unsigned green,
957 return 0; 946 return 0;
958} 947}
959 948
960#ifdef __BIG_ENDIAN
961static ssize_t smtcfb_read(struct fb_info *info, char __user *buf, 949static ssize_t smtcfb_read(struct fb_info *info, char __user *buf,
962 size_t count, loff_t *ppos) 950 size_t count, loff_t *ppos)
963{ 951{
@@ -1002,8 +990,7 @@ static ssize_t smtcfb_read(struct fb_info *info, char __user *buf,
1002 dst = buffer; 990 dst = buffer;
1003 for (i = c >> 2; i--;) { 991 for (i = c >> 2; i--;) {
1004 *dst = fb_readl(src++); 992 *dst = fb_readl(src++);
1005 *dst = (*dst & 0xff00ff00 >> 8) | 993 *dst = big_swap(*dst);
1006 (*dst & 0x00ff00ff << 8);
1007 dst++; 994 dst++;
1008 } 995 }
1009 if (c & 3) { 996 if (c & 3) {
@@ -1091,8 +1078,7 @@ static ssize_t smtcfb_write(struct fb_info *info, const char __user *buf,
1091 } 1078 }
1092 1079
1093 for (i = c >> 2; i--;) { 1080 for (i = c >> 2; i--;) {
1094 fb_writel((*src & 0xff00ff00 >> 8) | 1081 fb_writel(big_swap(*src), dst++);
1095 (*src & 0x00ff00ff << 8), dst++);
1096 src++; 1082 src++;
1097 } 1083 }
1098 if (c & 3) { 1084 if (c & 3) {
@@ -1120,7 +1106,6 @@ static ssize_t smtcfb_write(struct fb_info *info, const char __user *buf,
1120 1106
1121 return (cnt) ? cnt : err; 1107 return (cnt) ? cnt : err;
1122} 1108}
1123#endif /* ! __BIG_ENDIAN */
1124 1109
1125static void sm7xx_set_timing(struct smtcfb_info *sfb) 1110static void sm7xx_set_timing(struct smtcfb_info *sfb)
1126{ 1111{
@@ -1316,10 +1301,8 @@ static struct fb_ops smtcfb_ops = {
1316 .fb_fillrect = cfb_fillrect, 1301 .fb_fillrect = cfb_fillrect,
1317 .fb_imageblit = cfb_imageblit, 1302 .fb_imageblit = cfb_imageblit,
1318 .fb_copyarea = cfb_copyarea, 1303 .fb_copyarea = cfb_copyarea,
1319#ifdef __BIG_ENDIAN
1320 .fb_read = smtcfb_read, 1304 .fb_read = smtcfb_read,
1321 .fb_write = smtcfb_write, 1305 .fb_write = smtcfb_write,
1322#endif
1323}; 1306};
1324 1307
1325/* 1308/*
@@ -1341,10 +1324,8 @@ static int smtc_map_smem(struct smtcfb_info *sfb,
1341{ 1324{
1342 sfb->fb->fix.smem_start = pci_resource_start(pdev, 0); 1325 sfb->fb->fix.smem_start = pci_resource_start(pdev, 0);
1343 1326
1344#ifdef __BIG_ENDIAN
1345 if (sfb->fb->var.bits_per_pixel == 32) 1327 if (sfb->fb->var.bits_per_pixel == 32)
1346 sfb->fb->fix.smem_start += 0x800000; 1328 sfb->fb->fix.smem_start += big_addr;
1347#endif
1348 1329
1349 sfb->fb->fix.smem_len = smem_len; 1330 sfb->fb->fix.smem_len = smem_len;
1350 1331
@@ -1437,10 +1418,7 @@ static int smtcfb_pci_probe(struct pci_dev *pdev,
1437 sfb->fb->var.bits_per_pixel = SCREEN_BPP; 1418 sfb->fb->var.bits_per_pixel = SCREEN_BPP;
1438 } 1419 }
1439 1420
1440#ifdef __BIG_ENDIAN 1421 big_pixel_depth(sfb->fb->var.bits_per_pixel, smtc_scr_info.lfb_depth);
1441 if (sfb->fb->var.bits_per_pixel == 24)
1442 sfb->fb->var.bits_per_pixel = (smtc_scr_info.lfb_depth = 32);
1443#endif
1444 /* Map address and memory detection */ 1422 /* Map address and memory detection */
1445 mmio_base = pci_resource_start(pdev, 0); 1423 mmio_base = pci_resource_start(pdev, 0);
1446 pci_read_config_byte(pdev, PCI_REVISION_ID, &sfb->chip_rev_id); 1424 pci_read_config_byte(pdev, PCI_REVISION_ID, &sfb->chip_rev_id);
@@ -1451,28 +1429,23 @@ static int smtcfb_pci_probe(struct pci_dev *pdev,
1451 sfb->fb->fix.mmio_start = mmio_base + 0x00400000; 1429 sfb->fb->fix.mmio_start = mmio_base + 0x00400000;
1452 sfb->fb->fix.mmio_len = 0x00400000; 1430 sfb->fb->fix.mmio_len = 0x00400000;
1453 smem_size = SM712_VIDEOMEMORYSIZE; 1431 smem_size = SM712_VIDEOMEMORYSIZE;
1454#ifdef __BIG_ENDIAN 1432 sfb->lfb = ioremap(mmio_base, mmio_addr);
1455 sfb->lfb = ioremap(mmio_base, 0x00c00000); 1433 if (!sfb->lfb) {
1456#else 1434 dev_err(&pdev->dev,
1457 sfb->lfb = ioremap(mmio_base, 0x00800000); 1435 "%s: unable to map memory mapped IO!\n",
1458#endif 1436 sfb->fb->fix.id);
1437 err = -ENOMEM;
1438 goto failed_fb;
1439 }
1440
1459 sfb->mmio = (smtc_regbaseaddress = 1441 sfb->mmio = (smtc_regbaseaddress =
1460 sfb->lfb + 0x00700000); 1442 sfb->lfb + 0x00700000);
1461 sfb->dp_regs = sfb->lfb + 0x00408000; 1443 sfb->dp_regs = sfb->lfb + 0x00408000;
1462 sfb->vp_regs = sfb->lfb + 0x0040c000; 1444 sfb->vp_regs = sfb->lfb + 0x0040c000;
1463#ifdef __BIG_ENDIAN
1464 if (sfb->fb->var.bits_per_pixel == 32) { 1445 if (sfb->fb->var.bits_per_pixel == 32) {
1465 sfb->lfb += 0x800000; 1446 sfb->lfb += big_addr;
1466 dev_info(&pdev->dev, "sfb->lfb=%p\n", sfb->lfb); 1447 dev_info(&pdev->dev, "sfb->lfb=%p\n", sfb->lfb);
1467 } 1448 }
1468#endif
1469 if (!smtc_regbaseaddress) {
1470 dev_err(&pdev->dev,
1471 "%s: unable to map memory mapped IO!\n",
1472 sfb->fb->fix.id);
1473 err = -ENOMEM;
1474 goto failed_fb;
1475 }
1476 1449
1477 /* set MCLK = 14.31818 * (0x16 / 0x2) */ 1450 /* set MCLK = 14.31818 * (0x16 / 0x2) */
1478 smtc_seqw(0x6a, 0x16); 1451 smtc_seqw(0x6a, 0x16);
@@ -1481,10 +1454,8 @@ static int smtcfb_pci_probe(struct pci_dev *pdev,
1481 /* enable PCI burst */ 1454 /* enable PCI burst */
1482 smtc_seqw(0x17, 0x20); 1455 smtc_seqw(0x17, 0x20);
1483 /* enable word swap */ 1456 /* enable word swap */
1484#ifdef __BIG_ENDIAN
1485 if (sfb->fb->var.bits_per_pixel == 32) 1457 if (sfb->fb->var.bits_per_pixel == 32)
1486 smtc_seqw(0x17, 0x30); 1458 seqw17();
1487#endif
1488 break; 1459 break;
1489 case 0x720: 1460 case 0x720:
1490 sfb->fb->fix.mmio_start = mmio_base; 1461 sfb->fb->fix.mmio_start = mmio_base;
@@ -1616,10 +1587,8 @@ static int smtcfb_pci_resume(struct device *device)
1616 smtc_seqw(0x62, 0x3e); 1587 smtc_seqw(0x62, 0x3e);
1617 /* enable PCI burst */ 1588 /* enable PCI burst */
1618 smtc_seqw(0x17, 0x20); 1589 smtc_seqw(0x17, 0x20);
1619#ifdef __BIG_ENDIAN
1620 if (sfb->fb->var.bits_per_pixel == 32) 1590 if (sfb->fb->var.bits_per_pixel == 32)
1621 smtc_seqw(0x17, 0x30); 1591 seqw17();
1622#endif
1623 break; 1592 break;
1624 case 0x720: 1593 case 0x720:
1625 smtc_seqw(0x62, 0xff); 1594 smtc_seqw(0x62, 0xff);
@@ -1659,14 +1628,12 @@ static struct pci_driver smtcfb_driver = {
1659 1628
1660static int __init sm712fb_init(void) 1629static int __init sm712fb_init(void)
1661{ 1630{
1662#ifndef MODULE
1663 char *option = NULL; 1631 char *option = NULL;
1664 1632
1665 if (fb_get_options("sm712fb", &option)) 1633 if (fb_get_options("sm712fb", &option))
1666 return -ENODEV; 1634 return -ENODEV;
1667 if (option && *option) 1635 if (option && *option)
1668 mode_option = option; 1636 mode_option = option;
1669#endif
1670 sm7xx_vga_setup(mode_option); 1637 sm7xx_vga_setup(mode_option);
1671 1638
1672 return pci_register_driver(&smtcfb_driver); 1639 return pci_register_driver(&smtcfb_driver);
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
index 2c476acb87d9..3c17cd7fdf06 100644
--- a/include/linux/iio/common/st_sensors.h
+++ b/include/linux/iio/common/st_sensors.h
@@ -166,6 +166,7 @@ struct st_sensor_transfer_function {
166/** 166/**
167 * struct st_sensor_settings - ST specific sensor settings 167 * struct st_sensor_settings - ST specific sensor settings
168 * @wai: Contents of WhoAmI register. 168 * @wai: Contents of WhoAmI register.
169 * @wai_addr: The address of WhoAmI register.
169 * @sensors_supported: List of supported sensors by struct itself. 170 * @sensors_supported: List of supported sensors by struct itself.
170 * @ch: IIO channels for the sensor. 171 * @ch: IIO channels for the sensor.
171 * @odr: Output data rate register and ODR list available. 172 * @odr: Output data rate register and ODR list available.
@@ -179,6 +180,7 @@ struct st_sensor_transfer_function {
179 */ 180 */
180struct st_sensor_settings { 181struct st_sensor_settings {
181 u8 wai; 182 u8 wai;
183 u8 wai_addr;
182 char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME]; 184 char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME];
183 struct iio_chan_spec *ch; 185 struct iio_chan_spec *ch;
184 int num_ch; 186 int num_ch;
diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h
index 26fb8f6342bb..fad58671c49e 100644
--- a/include/linux/iio/consumer.h
+++ b/include/linux/iio/consumer.h
@@ -100,7 +100,7 @@ void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff);
100 100
101/** 101/**
102 * iio_channel_cb_get_channels() - get access to the underlying channels. 102 * iio_channel_cb_get_channels() - get access to the underlying channels.
103 * @cb_buff: The callback buffer from whom we want the channel 103 * @cb_buffer: The callback buffer from whom we want the channel
104 * information. 104 * information.
105 * 105 *
106 * This function allows one to obtain information about the channels. 106 * This function allows one to obtain information about the channels.
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index f79148261d16..7bb7f673cb3f 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -645,6 +645,15 @@ int iio_str_to_fixpoint(const char *str, int fract_mult, int *integer,
645#define IIO_DEGREE_TO_RAD(deg) (((deg) * 314159ULL + 9000000ULL) / 18000000ULL) 645#define IIO_DEGREE_TO_RAD(deg) (((deg) * 314159ULL + 9000000ULL) / 18000000ULL)
646 646
647/** 647/**
648 * IIO_RAD_TO_DEGREE() - Convert rad to degree
649 * @rad: A value in rad
650 *
651 * Returns the given value converted from rad to degree
652 */
653#define IIO_RAD_TO_DEGREE(rad) \
654 (((rad) * 18000000ULL + 314159ULL / 2) / 314159ULL)
655
656/**
648 * IIO_G_TO_M_S_2() - Convert g to meter / second**2 657 * IIO_G_TO_M_S_2() - Convert g to meter / second**2
649 * @g: A value in g 658 * @g: A value in g
650 * 659 *
@@ -652,4 +661,12 @@ int iio_str_to_fixpoint(const char *str, int fract_mult, int *integer,
652 */ 661 */
653#define IIO_G_TO_M_S_2(g) ((g) * 980665ULL / 100000ULL) 662#define IIO_G_TO_M_S_2(g) ((g) * 980665ULL / 100000ULL)
654 663
664/**
665 * IIO_M_S_2_TO_G() - Convert meter / second**2 to g
666 * @ms2: A value in meter / second**2
667 *
668 * Returns the given value converted from meter / second**2 to g
669 */
670#define IIO_M_S_2_TO_G(ms2) (((ms2) * 100000ULL + 980665ULL / 2) / 980665ULL)
671
655#endif /* _INDUSTRIAL_IO_H_ */ 672#endif /* _INDUSTRIAL_IO_H_ */
diff --git a/include/linux/iio/sysfs.h b/include/linux/iio/sysfs.h
index 8a1d18640ab9..9cd8f747212f 100644
--- a/include/linux/iio/sysfs.h
+++ b/include/linux/iio/sysfs.h
@@ -18,7 +18,8 @@ struct iio_chan_spec;
18 * struct iio_dev_attr - iio specific device attribute 18 * struct iio_dev_attr - iio specific device attribute
19 * @dev_attr: underlying device attribute 19 * @dev_attr: underlying device attribute
20 * @address: associated register address 20 * @address: associated register address
21 * @l: list head for maintaining list of dynamically created attrs. 21 * @l: list head for maintaining list of dynamically created attrs
22 * @c: specification for the underlying channel
22 */ 23 */
23struct iio_dev_attr { 24struct iio_dev_attr {
24 struct device_attribute dev_attr; 25 struct device_attribute dev_attr;
diff --git a/include/linux/iio/trigger.h b/include/linux/iio/trigger.h
index fa76c79a52a1..1c9e028e0d4a 100644
--- a/include/linux/iio/trigger.h
+++ b/include/linux/iio/trigger.h
@@ -18,6 +18,9 @@ struct iio_subirq {
18 bool enabled; 18 bool enabled;
19}; 19};
20 20
21struct iio_dev;
22struct iio_trigger;
23
21/** 24/**
22 * struct iio_trigger_ops - operations structure for an iio_trigger. 25 * struct iio_trigger_ops - operations structure for an iio_trigger.
23 * @owner: used to monitor usage count of the trigger. 26 * @owner: used to monitor usage count of the trigger.
diff --git a/include/linux/iio/triggered_buffer.h b/include/linux/iio/triggered_buffer.h
index c378ebec605e..f72f70d5a97b 100644
--- a/include/linux/iio/triggered_buffer.h
+++ b/include/linux/iio/triggered_buffer.h
@@ -7,8 +7,8 @@ struct iio_dev;
7struct iio_buffer_setup_ops; 7struct iio_buffer_setup_ops;
8 8
9int iio_triggered_buffer_setup(struct iio_dev *indio_dev, 9int iio_triggered_buffer_setup(struct iio_dev *indio_dev,
10 irqreturn_t (*pollfunc_bh)(int irq, void *p), 10 irqreturn_t (*h)(int irq, void *p),
11 irqreturn_t (*pollfunc_th)(int irq, void *p), 11 irqreturn_t (*thread)(int irq, void *p),
12 const struct iio_buffer_setup_ops *setup_ops); 12 const struct iio_buffer_setup_ops *setup_ops);
13void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev); 13void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev);
14 14
diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
index 4eebb6616e5c..9f7b85bf6ada 100644
--- a/tools/iio/generic_buffer.c
+++ b/tools/iio/generic_buffer.c
@@ -51,14 +51,33 @@ int size_from_channelarray(struct iio_channel_info *channels, int num_channels)
51 if (bytes % channels[i].bytes == 0) 51 if (bytes % channels[i].bytes == 0)
52 channels[i].location = bytes; 52 channels[i].location = bytes;
53 else 53 else
54 channels[i].location = bytes - bytes%channels[i].bytes 54 channels[i].location = bytes - bytes % channels[i].bytes
55 + channels[i].bytes; 55 + channels[i].bytes;
56
56 bytes = channels[i].location + channels[i].bytes; 57 bytes = channels[i].location + channels[i].bytes;
57 i++; 58 i++;
58 } 59 }
60
59 return bytes; 61 return bytes;
60} 62}
61 63
64void print1byte(uint8_t input, struct iio_channel_info *info)
65{
66 /*
67 * Shift before conversion to avoid sign extension
68 * of left aligned data
69 */
70 input >>= info->shift;
71 input &= info->mask;
72 if (info->is_signed) {
73 int8_t val = (int8_t)(input << (8 - info->bits_used)) >>
74 (8 - info->bits_used);
75 printf("%05f ", ((float)val + info->offset) * info->scale);
76 } else {
77 printf("%05f ", ((float)input + info->offset) * info->scale);
78 }
79}
80
62void print2byte(uint16_t input, struct iio_channel_info *info) 81void print2byte(uint16_t input, struct iio_channel_info *info)
63{ 82{
64 /* First swap if incorrect endian */ 83 /* First swap if incorrect endian */
@@ -136,9 +155,9 @@ void print8byte(uint64_t input, struct iio_channel_info *info)
136/** 155/**
137 * process_scan() - print out the values in SI units 156 * process_scan() - print out the values in SI units
138 * @data: pointer to the start of the scan 157 * @data: pointer to the start of the scan
139 * @channels: information about the channels. Note 158 * @channels: information about the channels.
140 * size_from_channelarray must have been called first to fill the 159 * Note: size_from_channelarray must have been called first
141 * location offsets. 160 * to fill the location offsets.
142 * @num_channels: number of channels 161 * @num_channels: number of channels
143 **/ 162 **/
144void process_scan(char *data, 163void process_scan(char *data,
@@ -150,6 +169,10 @@ void process_scan(char *data,
150 for (k = 0; k < num_channels; k++) 169 for (k = 0; k < num_channels; k++)
151 switch (channels[k].bytes) { 170 switch (channels[k].bytes) {
152 /* only a few cases implemented so far */ 171 /* only a few cases implemented so far */
172 case 1:
173 print1byte(*(uint8_t *)(data + channels[k].location),
174 &channels[k]);
175 break;
153 case 2: 176 case 2:
154 print2byte(*(uint16_t *)(data + channels[k].location), 177 print2byte(*(uint16_t *)(data + channels[k].location),
155 &channels[k]); 178 &channels[k]);
@@ -170,15 +193,15 @@ void process_scan(char *data,
170 193
171void print_usage(void) 194void print_usage(void)
172{ 195{
173 printf("Usage: generic_buffer [options]...\n" 196 fprintf(stderr, "Usage: generic_buffer [options]...\n"
174 "Capture, convert and output data from IIO device buffer\n" 197 "Capture, convert and output data from IIO device buffer\n"
175 " -c <n> Do n conversions\n" 198 " -c <n> Do n conversions\n"
176 " -e Disable wait for event (new data)\n" 199 " -e Disable wait for event (new data)\n"
177 " -g Use trigger-less mode\n" 200 " -g Use trigger-less mode\n"
178 " -l <n> Set buffer length to n samples\n" 201 " -l <n> Set buffer length to n samples\n"
179 " -n <name> Set device name (mandatory)\n" 202 " -n <name> Set device name (mandatory)\n"
180 " -t <name> Set trigger name\n" 203 " -t <name> Set trigger name\n"
181 " -w <n> Set delay between reads in us (event-less mode)\n"); 204 " -w <n> Set delay between reads in us (event-less mode)\n");
182} 205}
183 206
184int main(int argc, char **argv) 207int main(int argc, char **argv)
@@ -213,6 +236,7 @@ int main(int argc, char **argv)
213 num_loops = strtoul(optarg, &dummy, 10); 236 num_loops = strtoul(optarg, &dummy, 10);
214 if (errno) 237 if (errno)
215 return -errno; 238 return -errno;
239
216 break; 240 break;
217 case 'e': 241 case 'e':
218 noevents = 1; 242 noevents = 1;
@@ -225,6 +249,7 @@ int main(int argc, char **argv)
225 buf_len = strtoul(optarg, &dummy, 10); 249 buf_len = strtoul(optarg, &dummy, 10);
226 if (errno) 250 if (errno)
227 return -errno; 251 return -errno;
252
228 break; 253 break;
229 case 'n': 254 case 'n':
230 device_name = optarg; 255 device_name = optarg;
@@ -245,8 +270,8 @@ int main(int argc, char **argv)
245 } 270 }
246 } 271 }
247 272
248 if (device_name == NULL) { 273 if (!device_name) {
249 printf("Device name not set\n"); 274 fprintf(stderr, "Device name not set\n");
250 print_usage(); 275 print_usage();
251 return -1; 276 return -1;
252 } 277 }
@@ -254,9 +279,10 @@ int main(int argc, char **argv)
254 /* Find the device requested */ 279 /* Find the device requested */
255 dev_num = find_type_by_name(device_name, "iio:device"); 280 dev_num = find_type_by_name(device_name, "iio:device");
256 if (dev_num < 0) { 281 if (dev_num < 0) {
257 printf("Failed to find the %s\n", device_name); 282 fprintf(stderr, "Failed to find the %s\n", device_name);
258 return dev_num; 283 return dev_num;
259 } 284 }
285
260 printf("iio device number being used is %d\n", dev_num); 286 printf("iio device number being used is %d\n", dev_num);
261 287
262 ret = asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num); 288 ret = asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num);
@@ -264,7 +290,7 @@ int main(int argc, char **argv)
264 return -ENOMEM; 290 return -ENOMEM;
265 291
266 if (!notrigger) { 292 if (!notrigger) {
267 if (trigger_name == NULL) { 293 if (!trigger_name) {
268 /* 294 /*
269 * Build the trigger name. If it is device associated 295 * Build the trigger name. If it is device associated
270 * its name is <device_name>_dev[n] where n matches 296 * its name is <device_name>_dev[n] where n matches
@@ -281,13 +307,16 @@ int main(int argc, char **argv)
281 /* Verify the trigger exists */ 307 /* Verify the trigger exists */
282 trig_num = find_type_by_name(trigger_name, "trigger"); 308 trig_num = find_type_by_name(trigger_name, "trigger");
283 if (trig_num < 0) { 309 if (trig_num < 0) {
284 printf("Failed to find the trigger %s\n", trigger_name); 310 fprintf(stderr, "Failed to find the trigger %s\n",
311 trigger_name);
285 ret = trig_num; 312 ret = trig_num;
286 goto error_free_triggername; 313 goto error_free_triggername;
287 } 314 }
315
288 printf("iio trigger number being used is %d\n", trig_num); 316 printf("iio trigger number being used is %d\n", trig_num);
289 } else 317 } else {
290 printf("trigger-less mode selected\n"); 318 printf("trigger-less mode selected\n");
319 }
291 320
292 /* 321 /*
293 * Parse the files in scan_elements to identify what channels are 322 * Parse the files in scan_elements to identify what channels are
@@ -295,8 +324,8 @@ int main(int argc, char **argv)
295 */ 324 */
296 ret = build_channel_array(dev_dir_name, &channels, &num_channels); 325 ret = build_channel_array(dev_dir_name, &channels, &num_channels);
297 if (ret) { 326 if (ret) {
298 printf("Problem reading scan element information\n"); 327 fprintf(stderr, "Problem reading scan element information\n"
299 printf("diag %s\n", dev_dir_name); 328 "diag %s\n", dev_dir_name);
300 goto error_free_triggername; 329 goto error_free_triggername;
301 } 330 }
302 331
@@ -314,13 +343,16 @@ int main(int argc, char **argv)
314 343
315 if (!notrigger) { 344 if (!notrigger) {
316 printf("%s %s\n", dev_dir_name, trigger_name); 345 printf("%s %s\n", dev_dir_name, trigger_name);
317 /* Set the device trigger to be the data ready trigger found 346 /*
318 * above */ 347 * Set the device trigger to be the data ready trigger found
348 * above
349 */
319 ret = write_sysfs_string_and_verify("trigger/current_trigger", 350 ret = write_sysfs_string_and_verify("trigger/current_trigger",
320 dev_dir_name, 351 dev_dir_name,
321 trigger_name); 352 trigger_name);
322 if (ret < 0) { 353 if (ret < 0) {
323 printf("Failed to write current_trigger file\n"); 354 fprintf(stderr,
355 "Failed to write current_trigger file\n");
324 goto error_free_buf_dir_name; 356 goto error_free_buf_dir_name;
325 } 357 }
326 } 358 }
@@ -332,10 +364,14 @@ int main(int argc, char **argv)
332 364
333 /* Enable the buffer */ 365 /* Enable the buffer */
334 ret = write_sysfs_int("enable", buf_dir_name, 1); 366 ret = write_sysfs_int("enable", buf_dir_name, 1);
335 if (ret < 0) 367 if (ret < 0) {
368 fprintf(stderr,
369 "Failed to enable buffer: %s\n", strerror(-ret));
336 goto error_free_buf_dir_name; 370 goto error_free_buf_dir_name;
371 }
372
337 scan_size = size_from_channelarray(channels, num_channels); 373 scan_size = size_from_channelarray(channels, num_channels);
338 data = malloc(scan_size*buf_len); 374 data = malloc(scan_size * buf_len);
339 if (!data) { 375 if (!data) {
340 ret = -ENOMEM; 376 ret = -ENOMEM;
341 goto error_free_buf_dir_name; 377 goto error_free_buf_dir_name;
@@ -349,13 +385,12 @@ int main(int argc, char **argv)
349 385
350 /* Attempt to open non blocking the access dev */ 386 /* Attempt to open non blocking the access dev */
351 fp = open(buffer_access, O_RDONLY | O_NONBLOCK); 387 fp = open(buffer_access, O_RDONLY | O_NONBLOCK);
352 if (fp == -1) { /* If it isn't there make the node */ 388 if (fp == -1) { /* TODO: If it isn't there make the node */
353 ret = -errno; 389 ret = -errno;
354 printf("Failed to open %s\n", buffer_access); 390 fprintf(stderr, "Failed to open %s\n", buffer_access);
355 goto error_free_buffer_access; 391 goto error_free_buffer_access;
356 } 392 }
357 393
358 /* Wait for events 10 times */
359 for (j = 0; j < num_loops; j++) { 394 for (j = 0; j < num_loops; j++) {
360 if (!noevents) { 395 if (!noevents) {
361 struct pollfd pfd = { 396 struct pollfd pfd = {
@@ -372,25 +407,22 @@ int main(int argc, char **argv)
372 } 407 }
373 408
374 toread = buf_len; 409 toread = buf_len;
375
376 } else { 410 } else {
377 usleep(timedelay); 411 usleep(timedelay);
378 toread = 64; 412 toread = 64;
379 } 413 }
380 414
381 read_size = read(fp, 415 read_size = read(fp, data, toread * scan_size);
382 data,
383 toread*scan_size);
384 if (read_size < 0) { 416 if (read_size < 0) {
385 if (errno == EAGAIN) { 417 if (errno == EAGAIN) {
386 printf("nothing available\n"); 418 fprintf(stderr, "nothing available\n");
387 continue; 419 continue;
388 } else 420 } else {
389 break; 421 break;
422 }
390 } 423 }
391 for (i = 0; i < read_size/scan_size; i++) 424 for (i = 0; i < read_size / scan_size; i++)
392 process_scan(data + scan_size*i, 425 process_scan(data + scan_size * i, channels,
393 channels,
394 num_channels); 426 num_channels);
395 } 427 }
396 428
@@ -404,11 +436,13 @@ int main(int argc, char **argv)
404 ret = write_sysfs_string("trigger/current_trigger", 436 ret = write_sysfs_string("trigger/current_trigger",
405 dev_dir_name, "NULL"); 437 dev_dir_name, "NULL");
406 if (ret < 0) 438 if (ret < 0)
407 printf("Failed to write to %s\n", dev_dir_name); 439 fprintf(stderr, "Failed to write to %s\n",
440 dev_dir_name);
408 441
409error_close_buffer_access: 442error_close_buffer_access:
410 if (close(fp) == -1) 443 if (close(fp) == -1)
411 perror("Failed to close buffer"); 444 perror("Failed to close buffer");
445
412error_free_buffer_access: 446error_free_buffer_access:
413 free(buffer_access); 447 free(buffer_access);
414error_free_data: 448error_free_data:
@@ -424,6 +458,7 @@ error_free_channels:
424error_free_triggername: 458error_free_triggername:
425 if (datardytrigger) 459 if (datardytrigger)
426 free(trigger_name); 460 free(trigger_name);
461
427error_free_dev_dir_name: 462error_free_dev_dir_name:
428 free(dev_dir_name); 463 free(dev_dir_name);
429 464
diff --git a/tools/iio/iio_event_monitor.c b/tools/iio/iio_event_monitor.c
index 016760e769c0..cd3fd41b481d 100644
--- a/tools/iio/iio_event_monitor.c
+++ b/tools/iio/iio_event_monitor.c
@@ -13,7 +13,6 @@
13 * 13 *
14 * Usage: 14 * Usage:
15 * iio_event_monitor <device_name> 15 * iio_event_monitor <device_name>
16 *
17 */ 16 */
18 17
19#include <unistd.h> 18#include <unistd.h>
@@ -51,6 +50,9 @@ static const char * const iio_chan_type_name_spec[] = {
51 [IIO_HUMIDITYRELATIVE] = "humidityrelative", 50 [IIO_HUMIDITYRELATIVE] = "humidityrelative",
52 [IIO_ACTIVITY] = "activity", 51 [IIO_ACTIVITY] = "activity",
53 [IIO_STEPS] = "steps", 52 [IIO_STEPS] = "steps",
53 [IIO_ENERGY] = "energy",
54 [IIO_DISTANCE] = "distance",
55 [IIO_VELOCITY] = "velocity",
54}; 56};
55 57
56static const char * const iio_ev_type_text[] = { 58static const char * const iio_ev_type_text[] = {
@@ -99,6 +101,7 @@ static const char * const iio_modifier_names[] = {
99 [IIO_MOD_JOGGING] = "jogging", 101 [IIO_MOD_JOGGING] = "jogging",
100 [IIO_MOD_WALKING] = "walking", 102 [IIO_MOD_WALKING] = "walking",
101 [IIO_MOD_STILL] = "still", 103 [IIO_MOD_STILL] = "still",
104 [IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z] = "sqrt(x^2+y^2+z^2)",
102}; 105};
103 106
104static bool event_is_known(struct iio_event_data *event) 107static bool event_is_known(struct iio_event_data *event)
@@ -130,6 +133,9 @@ static bool event_is_known(struct iio_event_data *event)
130 case IIO_HUMIDITYRELATIVE: 133 case IIO_HUMIDITYRELATIVE:
131 case IIO_ACTIVITY: 134 case IIO_ACTIVITY:
132 case IIO_STEPS: 135 case IIO_STEPS:
136 case IIO_ENERGY:
137 case IIO_DISTANCE:
138 case IIO_VELOCITY:
133 break; 139 break;
134 default: 140 default:
135 return false; 141 return false;
@@ -167,6 +173,7 @@ static bool event_is_known(struct iio_event_data *event)
167 case IIO_MOD_JOGGING: 173 case IIO_MOD_JOGGING:
168 case IIO_MOD_WALKING: 174 case IIO_MOD_WALKING:
169 case IIO_MOD_STILL: 175 case IIO_MOD_STILL:
176 case IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z:
170 break; 177 break;
171 default: 178 default:
172 return false; 179 return false;
@@ -208,8 +215,9 @@ static void print_event(struct iio_event_data *event)
208 bool diff = IIO_EVENT_CODE_EXTRACT_DIFF(event->id); 215 bool diff = IIO_EVENT_CODE_EXTRACT_DIFF(event->id);
209 216
210 if (!event_is_known(event)) { 217 if (!event_is_known(event)) {
211 printf("Unknown event: time: %lld, id: %llx\n", 218 fprintf(stderr, "Unknown event: time: %lld, id: %llx\n",
212 event->timestamp, event->id); 219 event->timestamp, event->id);
220
213 return; 221 return;
214 } 222 }
215 223
@@ -229,6 +237,7 @@ static void print_event(struct iio_event_data *event)
229 237
230 if (dir != IIO_EV_DIR_NONE) 238 if (dir != IIO_EV_DIR_NONE)
231 printf(", direction: %s", iio_ev_dir_text[dir]); 239 printf(", direction: %s", iio_ev_dir_text[dir]);
240
232 printf("\n"); 241 printf("\n");
233} 242}
234 243
@@ -242,7 +251,7 @@ int main(int argc, char **argv)
242 int fd, event_fd; 251 int fd, event_fd;
243 252
244 if (argc <= 1) { 253 if (argc <= 1) {
245 printf("Usage: %s <device_name>\n", argv[0]); 254 fprintf(stderr, "Usage: %s <device_name>\n", argv[0]);
246 return -1; 255 return -1;
247 } 256 }
248 257
@@ -251,14 +260,15 @@ int main(int argc, char **argv)
251 dev_num = find_type_by_name(device_name, "iio:device"); 260 dev_num = find_type_by_name(device_name, "iio:device");
252 if (dev_num >= 0) { 261 if (dev_num >= 0) {
253 printf("Found IIO device with name %s with device number %d\n", 262 printf("Found IIO device with name %s with device number %d\n",
254 device_name, dev_num); 263 device_name, dev_num);
255 ret = asprintf(&chrdev_name, "/dev/iio:device%d", dev_num); 264 ret = asprintf(&chrdev_name, "/dev/iio:device%d", dev_num);
256 if (ret < 0) { 265 if (ret < 0)
257 return -ENOMEM; 266 return -ENOMEM;
258 }
259 } else { 267 } else {
260 /* If we can't find a IIO device by name assume device_name is a 268 /*
261 IIO chrdev */ 269 * If we can't find an IIO device by name assume device_name is
270 * an IIO chrdev
271 */
262 chrdev_name = strdup(device_name); 272 chrdev_name = strdup(device_name);
263 if (!chrdev_name) 273 if (!chrdev_name)
264 return -ENOMEM; 274 return -ENOMEM;
@@ -267,14 +277,14 @@ int main(int argc, char **argv)
267 fd = open(chrdev_name, 0); 277 fd = open(chrdev_name, 0);
268 if (fd == -1) { 278 if (fd == -1) {
269 ret = -errno; 279 ret = -errno;
270 fprintf(stdout, "Failed to open %s\n", chrdev_name); 280 fprintf(stderr, "Failed to open %s\n", chrdev_name);
271 goto error_free_chrdev_name; 281 goto error_free_chrdev_name;
272 } 282 }
273 283
274 ret = ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd); 284 ret = ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd);
275 if (ret == -1 || event_fd == -1) { 285 if (ret == -1 || event_fd == -1) {
276 ret = -errno; 286 ret = -errno;
277 fprintf(stdout, "Failed to retrieve event fd\n"); 287 fprintf(stderr, "Failed to retrieve event fd\n");
278 if (close(fd) == -1) 288 if (close(fd) == -1)
279 perror("Failed to close character device file"); 289 perror("Failed to close character device file");
280 290
@@ -290,7 +300,7 @@ int main(int argc, char **argv)
290 ret = read(event_fd, &event, sizeof(event)); 300 ret = read(event_fd, &event, sizeof(event));
291 if (ret == -1) { 301 if (ret == -1) {
292 if (errno == EAGAIN) { 302 if (errno == EAGAIN) {
293 printf("nothing available\n"); 303 fprintf(stderr, "nothing available\n");
294 continue; 304 continue;
295 } else { 305 } else {
296 ret = -errno; 306 ret = -errno;
@@ -299,6 +309,12 @@ int main(int argc, char **argv)
299 } 309 }
300 } 310 }
301 311
312 if (ret != sizeof(event)) {
313 fprintf(stderr, "Reading event failed!\n");
314 ret = -EIO;
315 break;
316 }
317
302 print_event(&event); 318 print_event(&event);
303 } 319 }
304 320
diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
index ec9ab7f9ae4c..5eb6793f3972 100644
--- a/tools/iio/iio_utils.c
+++ b/tools/iio/iio_utils.c
@@ -6,9 +6,6 @@
6 * under the terms of the GNU General Public License version 2 as published by 6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation. 7 * the Free Software Foundation.
8 */ 8 */
9#ifndef _IIO_UTILS_H
10#define _IIO_UTILS_H
11
12#include <string.h> 9#include <string.h>
13#include <stdlib.h> 10#include <stdlib.h>
14#include <stdio.h> 11#include <stdio.h>
@@ -32,15 +29,14 @@ static char * const iio_direction[] = {
32 * 29 *
33 * Returns 0 on success, or a negative error code if string extraction failed. 30 * Returns 0 on success, or a negative error code if string extraction failed.
34 **/ 31 **/
35int iioutils_break_up_name(const char *full_name, 32int iioutils_break_up_name(const char *full_name, char **generic_name)
36 char **generic_name)
37{ 33{
38 char *current; 34 char *current;
39 char *w, *r; 35 char *w, *r;
40 char *working, *prefix = ""; 36 char *working, *prefix = "";
41 int i, ret; 37 int i, ret;
42 38
43 for (i = 0; i < sizeof(iio_direction) / sizeof(iio_direction[0]); i++) 39 for (i = 0; i < ARRAY_SIZE(iio_direction); i++)
44 if (!strncmp(full_name, iio_direction[i], 40 if (!strncmp(full_name, iio_direction[i],
45 strlen(iio_direction[i]))) { 41 strlen(iio_direction[i]))) {
46 prefix = iio_direction[i]; 42 prefix = iio_direction[i];
@@ -65,6 +61,7 @@ int iioutils_break_up_name(const char *full_name,
65 *w = *r; 61 *w = *r;
66 w++; 62 w++;
67 } 63 }
64
68 r++; 65 r++;
69 } 66 }
70 *w = '\0'; 67 *w = '\0';
@@ -88,15 +85,10 @@ int iioutils_break_up_name(const char *full_name,
88 * 85 *
89 * Returns a value >= 0 on success, otherwise a negative error code. 86 * Returns a value >= 0 on success, otherwise a negative error code.
90 **/ 87 **/
91int iioutils_get_type(unsigned *is_signed, 88int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
92 unsigned *bytes, 89 unsigned *shift, uint64_t *mask, unsigned *be,
93 unsigned *bits_used, 90 const char *device_dir, const char *name,
94 unsigned *shift, 91 const char *generic_name)
95 uint64_t *mask,
96 unsigned *be,
97 const char *device_dir,
98 const char *name,
99 const char *generic_name)
100{ 92{
101 FILE *sysfsfp; 93 FILE *sysfsfp;
102 int ret; 94 int ret;
@@ -122,12 +114,13 @@ int iioutils_get_type(unsigned *is_signed,
122 } 114 }
123 115
124 dp = opendir(scan_el_dir); 116 dp = opendir(scan_el_dir);
125 if (dp == NULL) { 117 if (!dp) {
126 ret = -errno; 118 ret = -errno;
127 goto error_free_builtname_generic; 119 goto error_free_builtname_generic;
128 } 120 }
121
129 ret = -ENOENT; 122 ret = -ENOENT;
130 while (ent = readdir(dp), ent != NULL) 123 while (ent = readdir(dp), ent)
131 /* 124 /*
132 * Do we allow devices to override a generic name with 125 * Do we allow devices to override a generic name with
133 * a specific one? 126 * a specific one?
@@ -140,10 +133,12 @@ int iioutils_get_type(unsigned *is_signed,
140 ret = -ENOMEM; 133 ret = -ENOMEM;
141 goto error_closedir; 134 goto error_closedir;
142 } 135 }
136
143 sysfsfp = fopen(filename, "r"); 137 sysfsfp = fopen(filename, "r");
144 if (sysfsfp == NULL) { 138 if (!sysfsfp) {
145 ret = -errno; 139 ret = -errno;
146 printf("failed to open %s\n", filename); 140 fprintf(stderr, "failed to open %s\n",
141 filename);
147 goto error_free_filename; 142 goto error_free_filename;
148 } 143 }
149 144
@@ -155,31 +150,36 @@ int iioutils_get_type(unsigned *is_signed,
155 &padint, shift); 150 &padint, shift);
156 if (ret < 0) { 151 if (ret < 0) {
157 ret = -errno; 152 ret = -errno;
158 printf("failed to pass scan type description\n"); 153 fprintf(stderr,
154 "failed to pass scan type description\n");
159 goto error_close_sysfsfp; 155 goto error_close_sysfsfp;
160 } else if (ret != 5) { 156 } else if (ret != 5) {
161 ret = -EIO; 157 ret = -EIO;
162 printf("scan type description didn't match\n"); 158 fprintf(stderr,
159 "scan type description didn't match\n");
163 goto error_close_sysfsfp; 160 goto error_close_sysfsfp;
164 } 161 }
162
165 *be = (endianchar == 'b'); 163 *be = (endianchar == 'b');
166 *bytes = padint / 8; 164 *bytes = padint / 8;
167 if (*bits_used == 64) 165 if (*bits_used == 64)
168 *mask = ~0; 166 *mask = ~0;
169 else 167 else
170 *mask = (1 << *bits_used) - 1; 168 *mask = (1ULL << *bits_used) - 1;
169
171 *is_signed = (signchar == 's'); 170 *is_signed = (signchar == 's');
172 if (fclose(sysfsfp)) { 171 if (fclose(sysfsfp)) {
173 ret = -errno; 172 ret = -errno;
174 printf("Failed to close %s\n", filename); 173 fprintf(stderr, "Failed to close %s\n",
174 filename);
175 goto error_free_filename; 175 goto error_free_filename;
176 } 176 }
177 177
178 sysfsfp = 0; 178 sysfsfp = 0;
179 free(filename); 179 free(filename);
180
181 filename = 0; 180 filename = 0;
182 } 181 }
182
183error_close_sysfsfp: 183error_close_sysfsfp:
184 if (sysfsfp) 184 if (sysfsfp)
185 if (fclose(sysfsfp)) 185 if (fclose(sysfsfp))
@@ -188,6 +188,7 @@ error_close_sysfsfp:
188error_free_filename: 188error_free_filename:
189 if (filename) 189 if (filename)
190 free(filename); 190 free(filename);
191
191error_closedir: 192error_closedir:
192 if (closedir(dp) == -1) 193 if (closedir(dp) == -1)
193 perror("iioutils_get_type(): Failed to close directory"); 194 perror("iioutils_get_type(): Failed to close directory");
@@ -212,11 +213,9 @@ error_free_scan_el_dir:
212 * 213 *
213 * Returns a value >= 0 on success, otherwise a negative error code. 214 * Returns a value >= 0 on success, otherwise a negative error code.
214 **/ 215 **/
215int iioutils_get_param_float(float *output, 216int iioutils_get_param_float(float *output, const char *param_name,
216 const char *param_name, 217 const char *device_dir, const char *name,
217 const char *device_dir, 218 const char *generic_name)
218 const char *name,
219 const char *generic_name)
220{ 219{
221 FILE *sysfsfp; 220 FILE *sysfsfp;
222 int ret; 221 int ret;
@@ -235,13 +234,15 @@ int iioutils_get_param_float(float *output,
235 ret = -ENOMEM; 234 ret = -ENOMEM;
236 goto error_free_builtname; 235 goto error_free_builtname;
237 } 236 }
237
238 dp = opendir(device_dir); 238 dp = opendir(device_dir);
239 if (dp == NULL) { 239 if (!dp) {
240 ret = -errno; 240 ret = -errno;
241 goto error_free_builtname_generic; 241 goto error_free_builtname_generic;
242 } 242 }
243
243 ret = -ENOENT; 244 ret = -ENOENT;
244 while (ent = readdir(dp), ent != NULL) 245 while (ent = readdir(dp), ent)
245 if ((strcmp(builtname, ent->d_name) == 0) || 246 if ((strcmp(builtname, ent->d_name) == 0) ||
246 (strcmp(builtname_generic, ent->d_name) == 0)) { 247 (strcmp(builtname_generic, ent->d_name) == 0)) {
247 ret = asprintf(&filename, 248 ret = asprintf(&filename,
@@ -250,11 +251,13 @@ int iioutils_get_param_float(float *output,
250 ret = -ENOMEM; 251 ret = -ENOMEM;
251 goto error_closedir; 252 goto error_closedir;
252 } 253 }
254
253 sysfsfp = fopen(filename, "r"); 255 sysfsfp = fopen(filename, "r");
254 if (!sysfsfp) { 256 if (!sysfsfp) {
255 ret = -errno; 257 ret = -errno;
256 goto error_free_filename; 258 goto error_free_filename;
257 } 259 }
260
258 errno = 0; 261 errno = 0;
259 if (fscanf(sysfsfp, "%f", output) != 1) 262 if (fscanf(sysfsfp, "%f", output) != 1)
260 ret = errno ? -errno : -ENODATA; 263 ret = errno ? -errno : -ENODATA;
@@ -264,6 +267,7 @@ int iioutils_get_param_float(float *output,
264error_free_filename: 267error_free_filename:
265 if (filename) 268 if (filename)
266 free(filename); 269 free(filename);
270
267error_closedir: 271error_closedir:
268 if (closedir(dp) == -1) 272 if (closedir(dp) == -1)
269 perror("iioutils_get_param_float(): Failed to close directory"); 273 perror("iioutils_get_param_float(): Failed to close directory");
@@ -282,19 +286,17 @@ error_free_builtname:
282 * @cnt: the amount of array elements 286 * @cnt: the amount of array elements
283 **/ 287 **/
284 288
285void bsort_channel_array_by_index(struct iio_channel_info **ci_array, 289void bsort_channel_array_by_index(struct iio_channel_info *ci_array, int cnt)
286 int cnt)
287{ 290{
288
289 struct iio_channel_info temp; 291 struct iio_channel_info temp;
290 int x, y; 292 int x, y;
291 293
292 for (x = 0; x < cnt; x++) 294 for (x = 0; x < cnt; x++)
293 for (y = 0; y < (cnt - 1); y++) 295 for (y = 0; y < (cnt - 1); y++)
294 if ((*ci_array)[y].index > (*ci_array)[y+1].index) { 296 if (ci_array[y].index > ci_array[y + 1].index) {
295 temp = (*ci_array)[y + 1]; 297 temp = ci_array[y + 1];
296 (*ci_array)[y + 1] = (*ci_array)[y]; 298 ci_array[y + 1] = ci_array[y];
297 (*ci_array)[y] = temp; 299 ci_array[y] = temp;
298 } 300 }
299} 301}
300 302
@@ -307,8 +309,7 @@ void bsort_channel_array_by_index(struct iio_channel_info **ci_array,
307 * Returns 0 on success, otherwise a negative error code. 309 * Returns 0 on success, otherwise a negative error code.
308 **/ 310 **/
309int build_channel_array(const char *device_dir, 311int build_channel_array(const char *device_dir,
310 struct iio_channel_info **ci_array, 312 struct iio_channel_info **ci_array, int *counter)
311 int *counter)
312{ 313{
313 DIR *dp; 314 DIR *dp;
314 FILE *sysfsfp; 315 FILE *sysfsfp;
@@ -325,11 +326,12 @@ int build_channel_array(const char *device_dir,
325 return -ENOMEM; 326 return -ENOMEM;
326 327
327 dp = opendir(scan_el_dir); 328 dp = opendir(scan_el_dir);
328 if (dp == NULL) { 329 if (!dp) {
329 ret = -errno; 330 ret = -errno;
330 goto error_free_name; 331 goto error_free_name;
331 } 332 }
332 while (ent = readdir(dp), ent != NULL) 333
334 while (ent = readdir(dp), ent)
333 if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), 335 if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"),
334 "_en") == 0) { 336 "_en") == 0) {
335 ret = asprintf(&filename, 337 ret = asprintf(&filename,
@@ -338,12 +340,14 @@ int build_channel_array(const char *device_dir,
338 ret = -ENOMEM; 340 ret = -ENOMEM;
339 goto error_close_dir; 341 goto error_close_dir;
340 } 342 }
343
341 sysfsfp = fopen(filename, "r"); 344 sysfsfp = fopen(filename, "r");
342 if (sysfsfp == NULL) { 345 if (!sysfsfp) {
343 ret = -errno; 346 ret = -errno;
344 free(filename); 347 free(filename);
345 goto error_close_dir; 348 goto error_close_dir;
346 } 349 }
350
347 errno = 0; 351 errno = 0;
348 if (fscanf(sysfsfp, "%i", &ret) != 1) { 352 if (fscanf(sysfsfp, "%i", &ret) != 1) {
349 ret = errno ? -errno : -ENODATA; 353 ret = errno ? -errno : -ENODATA;
@@ -353,9 +357,9 @@ int build_channel_array(const char *device_dir,
353 free(filename); 357 free(filename);
354 goto error_close_dir; 358 goto error_close_dir;
355 } 359 }
356
357 if (ret == 1) 360 if (ret == 1)
358 (*counter)++; 361 (*counter)++;
362
359 if (fclose(sysfsfp)) { 363 if (fclose(sysfsfp)) {
360 ret = -errno; 364 ret = -errno;
361 free(filename); 365 free(filename);
@@ -364,13 +368,15 @@ int build_channel_array(const char *device_dir,
364 368
365 free(filename); 369 free(filename);
366 } 370 }
371
367 *ci_array = malloc(sizeof(**ci_array) * (*counter)); 372 *ci_array = malloc(sizeof(**ci_array) * (*counter));
368 if (*ci_array == NULL) { 373 if (!*ci_array) {
369 ret = -ENOMEM; 374 ret = -ENOMEM;
370 goto error_close_dir; 375 goto error_close_dir;
371 } 376 }
377
372 seekdir(dp, 0); 378 seekdir(dp, 0);
373 while (ent = readdir(dp), ent != NULL) { 379 while (ent = readdir(dp), ent) {
374 if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), 380 if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"),
375 "_en") == 0) { 381 "_en") == 0) {
376 int current_enabled = 0; 382 int current_enabled = 0;
@@ -384,13 +390,15 @@ int build_channel_array(const char *device_dir,
384 count--; 390 count--;
385 goto error_cleanup_array; 391 goto error_cleanup_array;
386 } 392 }
393
387 sysfsfp = fopen(filename, "r"); 394 sysfsfp = fopen(filename, "r");
388 if (sysfsfp == NULL) { 395 if (!sysfsfp) {
389 ret = -errno; 396 ret = -errno;
390 free(filename); 397 free(filename);
391 count--; 398 count--;
392 goto error_cleanup_array; 399 goto error_cleanup_array;
393 } 400 }
401
394 errno = 0; 402 errno = 0;
395 if (fscanf(sysfsfp, "%i", &current_enabled) != 1) { 403 if (fscanf(sysfsfp, "%i", &current_enabled) != 1) {
396 ret = errno ? -errno : -ENODATA; 404 ret = errno ? -errno : -ENODATA;
@@ -417,12 +425,13 @@ int build_channel_array(const char *device_dir,
417 current->name = strndup(ent->d_name, 425 current->name = strndup(ent->d_name,
418 strlen(ent->d_name) - 426 strlen(ent->d_name) -
419 strlen("_en")); 427 strlen("_en"));
420 if (current->name == NULL) { 428 if (!current->name) {
421 free(filename); 429 free(filename);
422 ret = -ENOMEM; 430 ret = -ENOMEM;
423 count--; 431 count--;
424 goto error_cleanup_array; 432 goto error_cleanup_array;
425 } 433 }
434
426 /* Get the generic and specific name elements */ 435 /* Get the generic and specific name elements */
427 ret = iioutils_break_up_name(current->name, 436 ret = iioutils_break_up_name(current->name,
428 &current->generic_name); 437 &current->generic_name);
@@ -432,6 +441,7 @@ int build_channel_array(const char *device_dir,
432 count--; 441 count--;
433 goto error_cleanup_array; 442 goto error_cleanup_array;
434 } 443 }
444
435 ret = asprintf(&filename, 445 ret = asprintf(&filename,
436 "%s/%s_index", 446 "%s/%s_index",
437 scan_el_dir, 447 scan_el_dir,
@@ -441,10 +451,12 @@ int build_channel_array(const char *device_dir,
441 ret = -ENOMEM; 451 ret = -ENOMEM;
442 goto error_cleanup_array; 452 goto error_cleanup_array;
443 } 453 }
454
444 sysfsfp = fopen(filename, "r"); 455 sysfsfp = fopen(filename, "r");
445 if (sysfsfp == NULL) { 456 if (!sysfsfp) {
446 ret = -errno; 457 ret = -errno;
447 printf("failed to open %s\n", filename); 458 fprintf(stderr, "failed to open %s\n",
459 filename);
448 free(filename); 460 free(filename);
449 goto error_cleanup_array; 461 goto error_cleanup_array;
450 } 462 }
@@ -472,15 +484,17 @@ int build_channel_array(const char *device_dir,
472 device_dir, 484 device_dir,
473 current->name, 485 current->name,
474 current->generic_name); 486 current->generic_name);
475 if (ret < 0) 487 if ((ret < 0) && (ret != -ENOENT))
476 goto error_cleanup_array; 488 goto error_cleanup_array;
489
477 ret = iioutils_get_param_float(&current->offset, 490 ret = iioutils_get_param_float(&current->offset,
478 "offset", 491 "offset",
479 device_dir, 492 device_dir,
480 current->name, 493 current->name,
481 current->generic_name); 494 current->generic_name);
482 if (ret < 0) 495 if ((ret < 0) && (ret != -ENOENT))
483 goto error_cleanup_array; 496 goto error_cleanup_array;
497
484 ret = iioutils_get_type(&current->is_signed, 498 ret = iioutils_get_type(&current->is_signed,
485 &current->bytes, 499 &current->bytes,
486 &current->bits_used, 500 &current->bits_used,
@@ -502,7 +516,7 @@ int build_channel_array(const char *device_dir,
502 516
503 free(scan_el_dir); 517 free(scan_el_dir);
504 /* reorder so that the array is in index order */ 518 /* reorder so that the array is in index order */
505 bsort_channel_array_by_index(ci_array, *counter); 519 bsort_channel_array_by_index(*ci_array, *counter);
506 520
507 return 0; 521 return 0;
508 522
@@ -512,6 +526,8 @@ error_cleanup_array:
512 free((*ci_array)[i].generic_name); 526 free((*ci_array)[i].generic_name);
513 } 527 }
514 free(*ci_array); 528 free(*ci_array);
529 *ci_array = NULL;
530 *counter = 0;
515error_close_dir: 531error_close_dir:
516 if (dp) 532 if (dp)
517 if (closedir(dp) == -1) 533 if (closedir(dp) == -1)
@@ -523,7 +539,7 @@ error_free_name:
523 return ret; 539 return ret;
524} 540}
525 541
526int calc_digits(int num) 542static int calc_digits(int num)
527{ 543{
528 int count = 0; 544 int count = 0;
529 545
@@ -549,44 +565,43 @@ int find_type_by_name(const char *name, const char *type)
549 const struct dirent *ent; 565 const struct dirent *ent;
550 int number, numstrlen, ret; 566 int number, numstrlen, ret;
551 567
552 FILE *nameFile; 568 FILE *namefp;
553 DIR *dp; 569 DIR *dp;
554 char thisname[IIO_MAX_NAME_LENGTH]; 570 char thisname[IIO_MAX_NAME_LENGTH];
555 char *filename; 571 char *filename;
556 572
557 dp = opendir(iio_dir); 573 dp = opendir(iio_dir);
558 if (dp == NULL) { 574 if (!dp) {
559 printf("No industrialio devices available\n"); 575 fprintf(stderr, "No industrialio devices available\n");
560 return -ENODEV; 576 return -ENODEV;
561 } 577 }
562 578
563 while (ent = readdir(dp), ent != NULL) { 579 while (ent = readdir(dp), ent) {
564 if (strcmp(ent->d_name, ".") != 0 && 580 if (strcmp(ent->d_name, ".") != 0 &&
565 strcmp(ent->d_name, "..") != 0 && 581 strcmp(ent->d_name, "..") != 0 &&
566 strlen(ent->d_name) > strlen(type) && 582 strlen(ent->d_name) > strlen(type) &&
567 strncmp(ent->d_name, type, strlen(type)) == 0) { 583 strncmp(ent->d_name, type, strlen(type)) == 0) {
568 errno = 0; 584 errno = 0;
569 ret = sscanf(ent->d_name + strlen(type), "%d", &number); 585 ret = sscanf(ent->d_name + strlen(type), "%d", &number);
570 if (ret < 0) { 586 if (ret < 0) {
571 ret = -errno; 587 ret = -errno;
572 printf("failed to read element number\n"); 588 fprintf(stderr,
589 "failed to read element number\n");
573 goto error_close_dir; 590 goto error_close_dir;
574 } else if (ret != 1) { 591 } else if (ret != 1) {
575 ret = -EIO; 592 ret = -EIO;
576 printf("failed to match element number\n"); 593 fprintf(stderr,
594 "failed to match element number\n");
577 goto error_close_dir; 595 goto error_close_dir;
578 } 596 }
579 597
580 numstrlen = calc_digits(number); 598 numstrlen = calc_digits(number);
581 /* verify the next character is not a colon */ 599 /* verify the next character is not a colon */
582 if (strncmp(ent->d_name + strlen(type) + numstrlen, 600 if (strncmp(ent->d_name + strlen(type) + numstrlen,
583 ":", 601 ":", 1) != 0) {
584 1) != 0) { 602 filename = malloc(strlen(iio_dir) + strlen(type)
585 filename = malloc(strlen(iio_dir) 603 + numstrlen + 6);
586 + strlen(type) 604 if (!filename) {
587 + numstrlen
588 + 6);
589 if (filename == NULL) {
590 ret = -ENOMEM; 605 ret = -ENOMEM;
591 goto error_close_dir; 606 goto error_close_dir;
592 } 607 }
@@ -598,19 +613,20 @@ int find_type_by_name(const char *name, const char *type)
598 goto error_close_dir; 613 goto error_close_dir;
599 } 614 }
600 615
601 nameFile = fopen(filename, "r"); 616 namefp = fopen(filename, "r");
602 if (!nameFile) { 617 if (!namefp) {
603 free(filename); 618 free(filename);
604 continue; 619 continue;
605 } 620 }
621
606 free(filename); 622 free(filename);
607 errno = 0; 623 errno = 0;
608 if (fscanf(nameFile, "%s", thisname) != 1) { 624 if (fscanf(namefp, "%s", thisname) != 1) {
609 ret = errno ? -errno : -ENODATA; 625 ret = errno ? -errno : -ENODATA;
610 goto error_close_dir; 626 goto error_close_dir;
611 } 627 }
612 628
613 if (fclose(nameFile)) { 629 if (fclose(namefp)) {
614 ret = -errno; 630 ret = -errno;
615 goto error_close_dir; 631 goto error_close_dir;
616 } 632 }
@@ -618,6 +634,7 @@ int find_type_by_name(const char *name, const char *type)
618 if (strcmp(name, thisname) == 0) { 634 if (strcmp(name, thisname) == 0) {
619 if (closedir(dp) == -1) 635 if (closedir(dp) == -1)
620 return -errno; 636 return -errno;
637
621 return number; 638 return number;
622 } 639 }
623 } 640 }
@@ -631,6 +648,7 @@ int find_type_by_name(const char *name, const char *type)
631error_close_dir: 648error_close_dir:
632 if (closedir(dp) == -1) 649 if (closedir(dp) == -1)
633 perror("find_type_by_name(): Failed to close directory"); 650 perror("find_type_by_name(): Failed to close directory");
651
634 return ret; 652 return ret;
635} 653}
636 654
@@ -642,18 +660,20 @@ static int _write_sysfs_int(const char *filename, const char *basedir, int val,
642 int test; 660 int test;
643 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 661 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
644 662
645 if (temp == NULL) 663 if (!temp)
646 return -ENOMEM; 664 return -ENOMEM;
665
647 ret = sprintf(temp, "%s/%s", basedir, filename); 666 ret = sprintf(temp, "%s/%s", basedir, filename);
648 if (ret < 0) 667 if (ret < 0)
649 goto error_free; 668 goto error_free;
650 669
651 sysfsfp = fopen(temp, "w"); 670 sysfsfp = fopen(temp, "w");
652 if (sysfsfp == NULL) { 671 if (!sysfsfp) {
653 ret = -errno; 672 ret = -errno;
654 printf("failed to open %s\n", temp); 673 fprintf(stderr, "failed to open %s\n", temp);
655 goto error_free; 674 goto error_free;
656 } 675 }
676
657 ret = fprintf(sysfsfp, "%d", val); 677 ret = fprintf(sysfsfp, "%d", val);
658 if (ret < 0) { 678 if (ret < 0) {
659 if (fclose(sysfsfp)) 679 if (fclose(sysfsfp))
@@ -669,11 +689,12 @@ static int _write_sysfs_int(const char *filename, const char *basedir, int val,
669 689
670 if (verify) { 690 if (verify) {
671 sysfsfp = fopen(temp, "r"); 691 sysfsfp = fopen(temp, "r");
672 if (sysfsfp == NULL) { 692 if (!sysfsfp) {
673 ret = -errno; 693 ret = -errno;
674 printf("failed to open %s\n", temp); 694 fprintf(stderr, "failed to open %s\n", temp);
675 goto error_free; 695 goto error_free;
676 } 696 }
697
677 if (fscanf(sysfsfp, "%d", &test) != 1) { 698 if (fscanf(sysfsfp, "%d", &test) != 1) {
678 ret = errno ? -errno : -ENODATA; 699 ret = errno ? -errno : -ENODATA;
679 if (fclose(sysfsfp)) 700 if (fclose(sysfsfp))
@@ -688,13 +709,13 @@ static int _write_sysfs_int(const char *filename, const char *basedir, int val,
688 } 709 }
689 710
690 if (test != val) { 711 if (test != val) {
691 printf("Possible failure in int write %d to %s%s\n", 712 fprintf(stderr,
692 val, 713 "Possible failure in int write %d to %s/%s\n",
693 basedir, 714 val, basedir, filename);
694 filename);
695 ret = -1; 715 ret = -1;
696 } 716 }
697 } 717 }
718
698error_free: 719error_free:
699 free(temp); 720 free(temp);
700 return ret; 721 return ret;
@@ -735,20 +756,22 @@ static int _write_sysfs_string(const char *filename, const char *basedir,
735 FILE *sysfsfp; 756 FILE *sysfsfp;
736 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 757 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
737 758
738 if (temp == NULL) { 759 if (!temp) {
739 printf("Memory allocation failed\n"); 760 fprintf(stderr, "Memory allocation failed\n");
740 return -ENOMEM; 761 return -ENOMEM;
741 } 762 }
763
742 ret = sprintf(temp, "%s/%s", basedir, filename); 764 ret = sprintf(temp, "%s/%s", basedir, filename);
743 if (ret < 0) 765 if (ret < 0)
744 goto error_free; 766 goto error_free;
745 767
746 sysfsfp = fopen(temp, "w"); 768 sysfsfp = fopen(temp, "w");
747 if (sysfsfp == NULL) { 769 if (!sysfsfp) {
748 ret = -errno; 770 ret = -errno;
749 printf("Could not open %s\n", temp); 771 fprintf(stderr, "Could not open %s\n", temp);
750 goto error_free; 772 goto error_free;
751 } 773 }
774
752 ret = fprintf(sysfsfp, "%s", val); 775 ret = fprintf(sysfsfp, "%s", val);
753 if (ret < 0) { 776 if (ret < 0) {
754 if (fclose(sysfsfp)) 777 if (fclose(sysfsfp))
@@ -764,11 +787,12 @@ static int _write_sysfs_string(const char *filename, const char *basedir,
764 787
765 if (verify) { 788 if (verify) {
766 sysfsfp = fopen(temp, "r"); 789 sysfsfp = fopen(temp, "r");
767 if (sysfsfp == NULL) { 790 if (!sysfsfp) {
768 ret = -errno; 791 ret = -errno;
769 printf("could not open file to verify\n"); 792 fprintf(stderr, "Could not open file to verify\n");
770 goto error_free; 793 goto error_free;
771 } 794 }
795
772 if (fscanf(sysfsfp, "%s", temp) != 1) { 796 if (fscanf(sysfsfp, "%s", temp) != 1) {
773 ret = errno ? -errno : -ENODATA; 797 ret = errno ? -errno : -ENODATA;
774 if (fclose(sysfsfp)) 798 if (fclose(sysfsfp))
@@ -783,16 +807,14 @@ static int _write_sysfs_string(const char *filename, const char *basedir,
783 } 807 }
784 808
785 if (strcmp(temp, val) != 0) { 809 if (strcmp(temp, val) != 0) {
786 printf("Possible failure in string write of %s " 810 fprintf(stderr,
787 "Should be %s " 811 "Possible failure in string write of %s "
788 "written to %s\%s\n", 812 "Should be %s written to %s/%s\n", temp, val,
789 temp, 813 basedir, filename);
790 val,
791 basedir,
792 filename);
793 ret = -1; 814 ret = -1;
794 } 815 }
795 } 816 }
817
796error_free: 818error_free:
797 free(temp); 819 free(temp);
798 820
@@ -841,19 +863,21 @@ int read_sysfs_posint(const char *filename, const char *basedir)
841 FILE *sysfsfp; 863 FILE *sysfsfp;
842 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 864 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
843 865
844 if (temp == NULL) { 866 if (!temp) {
845 printf("Memory allocation failed"); 867 fprintf(stderr, "Memory allocation failed");
846 return -ENOMEM; 868 return -ENOMEM;
847 } 869 }
870
848 ret = sprintf(temp, "%s/%s", basedir, filename); 871 ret = sprintf(temp, "%s/%s", basedir, filename);
849 if (ret < 0) 872 if (ret < 0)
850 goto error_free; 873 goto error_free;
851 874
852 sysfsfp = fopen(temp, "r"); 875 sysfsfp = fopen(temp, "r");
853 if (sysfsfp == NULL) { 876 if (!sysfsfp) {
854 ret = -errno; 877 ret = -errno;
855 goto error_free; 878 goto error_free;
856 } 879 }
880
857 errno = 0; 881 errno = 0;
858 if (fscanf(sysfsfp, "%d\n", &ret) != 1) { 882 if (fscanf(sysfsfp, "%d\n", &ret) != 1) {
859 ret = errno ? -errno : -ENODATA; 883 ret = errno ? -errno : -ENODATA;
@@ -868,6 +892,7 @@ int read_sysfs_posint(const char *filename, const char *basedir)
868 892
869error_free: 893error_free:
870 free(temp); 894 free(temp);
895
871 return ret; 896 return ret;
872} 897}
873 898
@@ -885,19 +910,21 @@ int read_sysfs_float(const char *filename, const char *basedir, float *val)
885 FILE *sysfsfp; 910 FILE *sysfsfp;
886 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 911 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
887 912
888 if (temp == NULL) { 913 if (!temp) {
889 printf("Memory allocation failed"); 914 fprintf(stderr, "Memory allocation failed");
890 return -ENOMEM; 915 return -ENOMEM;
891 } 916 }
917
892 ret = sprintf(temp, "%s/%s", basedir, filename); 918 ret = sprintf(temp, "%s/%s", basedir, filename);
893 if (ret < 0) 919 if (ret < 0)
894 goto error_free; 920 goto error_free;
895 921
896 sysfsfp = fopen(temp, "r"); 922 sysfsfp = fopen(temp, "r");
897 if (sysfsfp == NULL) { 923 if (!sysfsfp) {
898 ret = -errno; 924 ret = -errno;
899 goto error_free; 925 goto error_free;
900 } 926 }
927
901 errno = 0; 928 errno = 0;
902 if (fscanf(sysfsfp, "%f\n", val) != 1) { 929 if (fscanf(sysfsfp, "%f\n", val) != 1) {
903 ret = errno ? -errno : -ENODATA; 930 ret = errno ? -errno : -ENODATA;
@@ -912,6 +939,7 @@ int read_sysfs_float(const char *filename, const char *basedir, float *val)
912 939
913error_free: 940error_free:
914 free(temp); 941 free(temp);
942
915 return ret; 943 return ret;
916} 944}
917 945
@@ -929,19 +957,21 @@ int read_sysfs_string(const char *filename, const char *basedir, char *str)
929 FILE *sysfsfp; 957 FILE *sysfsfp;
930 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 958 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
931 959
932 if (temp == NULL) { 960 if (!temp) {
933 printf("Memory allocation failed"); 961 fprintf(stderr, "Memory allocation failed");
934 return -ENOMEM; 962 return -ENOMEM;
935 } 963 }
964
936 ret = sprintf(temp, "%s/%s", basedir, filename); 965 ret = sprintf(temp, "%s/%s", basedir, filename);
937 if (ret < 0) 966 if (ret < 0)
938 goto error_free; 967 goto error_free;
939 968
940 sysfsfp = fopen(temp, "r"); 969 sysfsfp = fopen(temp, "r");
941 if (sysfsfp == NULL) { 970 if (!sysfsfp) {
942 ret = -errno; 971 ret = -errno;
943 goto error_free; 972 goto error_free;
944 } 973 }
974
945 errno = 0; 975 errno = 0;
946 if (fscanf(sysfsfp, "%s\n", str) != 1) { 976 if (fscanf(sysfsfp, "%s\n", str) != 1) {
947 ret = errno ? -errno : -ENODATA; 977 ret = errno ? -errno : -ENODATA;
@@ -956,7 +986,6 @@ int read_sysfs_string(const char *filename, const char *basedir, char *str)
956 986
957error_free: 987error_free:
958 free(temp); 988 free(temp);
989
959 return ret; 990 return ret;
960} 991}
961
962#endif /* _IIO_UTILS_H */
diff --git a/tools/iio/iio_utils.h b/tools/iio/iio_utils.h
index 379eed9deaea..e3503bfe538b 100644
--- a/tools/iio/iio_utils.h
+++ b/tools/iio/iio_utils.h
@@ -18,6 +18,8 @@
18#define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements" 18#define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements"
19#define FORMAT_TYPE_FILE "%s_type" 19#define FORMAT_TYPE_FILE "%s_type"
20 20
21#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
22
21extern const char *iio_dir; 23extern const char *iio_dir;
22 24
23/** 25/**
@@ -51,17 +53,16 @@ struct iio_channel_info {
51}; 53};
52 54
53int iioutils_break_up_name(const char *full_name, char **generic_name); 55int iioutils_break_up_name(const char *full_name, char **generic_name);
54int iioutils_get_type(unsigned *is_signed, unsigned *bytes, 56int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
55 unsigned *bits_used, unsigned *shift, 57 unsigned *shift, uint64_t *mask, unsigned *be,
56 uint64_t *mask, unsigned *be, 58 const char *device_dir, const char *name,
57 const char *device_dir, const char *name, 59 const char *generic_name);
58 const char *generic_name);
59int iioutils_get_param_float(float *output, const char *param_name, 60int iioutils_get_param_float(float *output, const char *param_name,
60 const char *device_dir, const char *name, 61 const char *device_dir, const char *name,
61 const char *generic_name); 62 const char *generic_name);
62void bsort_channel_array_by_index(struct iio_channel_info **ci_array, int cnt); 63void bsort_channel_array_by_index(struct iio_channel_info *ci_array, int cnt);
63int build_channel_array(const char *device_dir, 64int build_channel_array(const char *device_dir,
64 struct iio_channel_info **ci_array, int *counter); 65 struct iio_channel_info **ci_array, int *counter);
65int find_type_by_name(const char *name, const char *type); 66int find_type_by_name(const char *name, const char *type);
66int write_sysfs_int(const char *filename, const char *basedir, int val); 67int write_sysfs_int(const char *filename, const char *basedir, int val);
67int write_sysfs_int_and_verify(const char *filename, const char *basedir, 68int write_sysfs_int_and_verify(const char *filename, const char *basedir,
diff --git a/tools/iio/lsiio.c b/tools/iio/lsiio.c
index b59ee1733924..3d650e668252 100644
--- a/tools/iio/lsiio.c
+++ b/tools/iio/lsiio.c
@@ -20,7 +20,6 @@
20#include <sys/dir.h> 20#include <sys/dir.h>
21#include "iio_utils.h" 21#include "iio_utils.h"
22 22
23
24static enum verbosity { 23static enum verbosity {
25 VERBLEVEL_DEFAULT, /* 0 gives lspci behaviour */ 24 VERBLEVEL_DEFAULT, /* 0 gives lspci behaviour */
26 VERBLEVEL_SENSORS, /* 1 lists sensors */ 25 VERBLEVEL_SENSORS, /* 1 lists sensors */
@@ -29,17 +28,16 @@ static enum verbosity {
29const char *type_device = "iio:device"; 28const char *type_device = "iio:device";
30const char *type_trigger = "trigger"; 29const char *type_trigger = "trigger";
31 30
32
33static inline int check_prefix(const char *str, const char *prefix) 31static inline int check_prefix(const char *str, const char *prefix)
34{ 32{
35 return strlen(str) > strlen(prefix) && 33 return strlen(str) > strlen(prefix) &&
36 strncmp(str, prefix, strlen(prefix)) == 0; 34 strncmp(str, prefix, strlen(prefix)) == 0;
37} 35}
38 36
39static inline int check_postfix(const char *str, const char *postfix) 37static inline int check_postfix(const char *str, const char *postfix)
40{ 38{
41 return strlen(str) > strlen(postfix) && 39 return strlen(str) > strlen(postfix) &&
42 strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; 40 strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
43} 41}
44 42
45static int dump_channels(const char *dev_dir_name) 43static int dump_channels(const char *dev_dir_name)
@@ -48,13 +46,13 @@ static int dump_channels(const char *dev_dir_name)
48 const struct dirent *ent; 46 const struct dirent *ent;
49 47
50 dp = opendir(dev_dir_name); 48 dp = opendir(dev_dir_name);
51 if (dp == NULL) 49 if (!dp)
52 return -errno; 50 return -errno;
53 while (ent = readdir(dp), ent != NULL) 51
52 while (ent = readdir(dp), ent)
54 if (check_prefix(ent->d_name, "in_") && 53 if (check_prefix(ent->d_name, "in_") &&
55 check_postfix(ent->d_name, "_raw")) { 54 check_postfix(ent->d_name, "_raw"))
56 printf(" %-10s\n", ent->d_name); 55 printf(" %-10s\n", ent->d_name);
57 }
58 56
59 return (closedir(dp) == -1) ? -errno : 0; 57 return (closedir(dp) == -1) ? -errno : 0;
60} 58}
@@ -63,20 +61,22 @@ static int dump_one_device(const char *dev_dir_name)
63{ 61{
64 char name[IIO_MAX_NAME_LENGTH]; 62 char name[IIO_MAX_NAME_LENGTH];
65 int dev_idx; 63 int dev_idx;
66 int retval; 64 int ret;
67 65
68 retval = sscanf(dev_dir_name + strlen(iio_dir) + strlen(type_device), 66 ret = sscanf(dev_dir_name + strlen(iio_dir) + strlen(type_device), "%i",
69 "%i", &dev_idx); 67 &dev_idx);
70 if (retval != 1) 68 if (ret != 1)
71 return -EINVAL; 69 return -EINVAL;
72 retval = read_sysfs_string("name", dev_dir_name, name); 70
73 if (retval) 71 ret = read_sysfs_string("name", dev_dir_name, name);
74 return retval; 72 if (ret < 0)
73 return ret;
75 74
76 printf("Device %03d: %s\n", dev_idx, name); 75 printf("Device %03d: %s\n", dev_idx, name);
77 76
78 if (verblevel >= VERBLEVEL_SENSORS) 77 if (verblevel >= VERBLEVEL_SENSORS)
79 return dump_channels(dev_dir_name); 78 return dump_channels(dev_dir_name);
79
80 return 0; 80 return 0;
81} 81}
82 82
@@ -84,17 +84,19 @@ static int dump_one_trigger(const char *dev_dir_name)
84{ 84{
85 char name[IIO_MAX_NAME_LENGTH]; 85 char name[IIO_MAX_NAME_LENGTH];
86 int dev_idx; 86 int dev_idx;
87 int retval; 87 int ret;
88 88
89 retval = sscanf(dev_dir_name + strlen(iio_dir) + strlen(type_trigger), 89 ret = sscanf(dev_dir_name + strlen(iio_dir) + strlen(type_trigger),
90 "%i", &dev_idx); 90 "%i", &dev_idx);
91 if (retval != 1) 91 if (ret != 1)
92 return -EINVAL; 92 return -EINVAL;
93 retval = read_sysfs_string("name", dev_dir_name, name); 93
94 if (retval) 94 ret = read_sysfs_string("name", dev_dir_name, name);
95 return retval; 95 if (ret < 0)
96 return ret;
96 97
97 printf("Trigger %03d: %s\n", dev_idx, name); 98 printf("Trigger %03d: %s\n", dev_idx, name);
99
98 return 0; 100 return 0;
99} 101}
100 102
@@ -105,12 +107,12 @@ static int dump_devices(void)
105 DIR *dp; 107 DIR *dp;
106 108
107 dp = opendir(iio_dir); 109 dp = opendir(iio_dir);
108 if (dp == NULL) { 110 if (!dp) {
109 printf("No industrial I/O devices available\n"); 111 fprintf(stderr, "No industrial I/O devices available\n");
110 return -ENODEV; 112 return -ENODEV;
111 } 113 }
112 114
113 while (ent = readdir(dp), ent != NULL) { 115 while (ent = readdir(dp), ent) {
114 if (check_prefix(ent->d_name, type_device)) { 116 if (check_prefix(ent->d_name, type_device)) {
115 char *dev_dir_name; 117 char *dev_dir_name;
116 118
@@ -132,7 +134,7 @@ static int dump_devices(void)
132 } 134 }
133 } 135 }
134 rewinddir(dp); 136 rewinddir(dp);
135 while (ent = readdir(dp), ent != NULL) { 137 while (ent = readdir(dp), ent) {
136 if (check_prefix(ent->d_name, type_trigger)) { 138 if (check_prefix(ent->d_name, type_trigger)) {
137 char *dev_dir_name; 139 char *dev_dir_name;
138 140
@@ -151,6 +153,7 @@ static int dump_devices(void)
151 free(dev_dir_name); 153 free(dev_dir_name);
152 } 154 }
153 } 155 }
156
154 return (closedir(dp) == -1) ? -errno : 0; 157 return (closedir(dp) == -1) ? -errno : 0;
155 158
156error_close_dir: 159error_close_dir: